	SECTION dex,CODE
	LEA arraylabcoordinates,A0
	MOVE.L A0,mainvarcoordinates
	MOVE.L 4,A6            ; init + open libs
	LEA dosname,A1
	MOVEQ #33,D0           ; we need atleast kick 1.2
	JSR -552(A6)           ; open dos.library
	MOVE.L D0,mainvardosbase
	BEQ backwherewecamefrom
	MOVE.L A6,A5
	MOVE.L D0,A6           ; get std output
	JSR -60(A6)
	MOVE.L A5,A6
	MOVE.L D0,mainvarstdout
	LEA graphicsname,A1
	MOVEQ #33,D0           ; we need atleast kick 1.2
	JSR -552(A6)           ; open graphics.library
	MOVE.L D0,mainvargraphicsbase
	BEQ backwherewecamefrom
	LEA intuitionname,A1
	MOVEQ #33,D0           ; we need atleast kick 1.2
	JSR -552(A6)           ; open intuition.library
	MOVE.L D0,mainvarintuitionbase
	BEQ backwherewecamefrom
	MOVE.L A7,savestack    ; save stack
	BSR proglabmain        ; get going ...
leaveprog:
	MOVE.L savestack,A7    ; close down
	MOVE.L 4,A6
	MOVE.L mainvardosbase,A1
	JSR -414(a6)           ; close dos.library
	MOVE.L mainvargraphicsbase,A1
	JSR -414(a6)           ; close graphics.library
	MOVE.L mainvarintuitionbase,A1
	JSR -414(a6)           ; close intuition.library
backwherewecamefrom:
	RTS
	savestack: DC.L 0
rdfdump:
	MOVE.B  D0,(A3)+
	ADDQ.L  #1,rdflenght
	RTS
rdflenght:
	DC.L 0
printf:
	MOVE.L  D1,A0
	LEA     rdfdump(pc),A2
	MOVE.L  4,A6
	MOVE.L  276(A6),A3
	MOVE.L  58(A3),A3
	MOVE.L  A3,A4
	CLR.L   rdflenght
	JSR     -522(A6)
	MOVE.L  mainvarstdout(pc),D1
	MOVE.L  A4,D2
	MOVE.L  rdflenght(pc),D3
	MOVE.L  mainvardosbase(pc),a6
	JSR     -48(a6)
	RTS

proglabinit:		; PROC init()
	BSR proglabmakedata		; VOID makedata()
	MOVEQ #90,D0		; VOID view(90,13)
	MOVE.W D0,viewvarx
	MOVEQ #13,D0
	MOVE.W D0,viewvary
	BSR proglabview
	MOVEQ #0,D0		; screenadr1 := screen(screenx,screeny,2,0,' ')
	MOVE.W mainvarscreenx(pc),D0
	MOVE.W D0,proglabns+4
	MOVEQ #0,D0
	MOVE.W mainvarscreeny(pc),D0
	MOVE.W D0,proglabns+6
	MOVEQ #2,D0
	MOVE.W D0,proglabns+8
	MOVEQ #0,D0
	MOVE.W D0,proglabns+12
	LEA directtextlab0(pc),A0
	MOVE.L A0,D0
	MOVE.L D0,proglabns+20
	BSR proglabscreen
	MOVE.L D0,mainvarscreenadr1
	MOVE.L mainvarscreenadr1(pc),D0		; rast1 := screenadr1+84
	ADD.L #84,D0
	MOVE.L D0,mainvarrast1
	MOVE.L mainvarscreenadr1(pc),D0		; VOID setcolours(screenadr1)
	MOVE.L D0,setcoloursvarrastport
	BSR proglabsetcolours
	MOVEQ #0,D0		; screenadr2 := screen(screenx,screeny,2,0,' ')
	MOVE.W mainvarscreenx(pc),D0
	MOVE.W D0,proglabns+4
	MOVEQ #0,D0
	MOVE.W mainvarscreeny(pc),D0
	MOVE.W D0,proglabns+6
	MOVEQ #2,D0
	MOVE.W D0,proglabns+8
	MOVEQ #0,D0
	MOVE.W D0,proglabns+12
	LEA directtextlab1(pc),A0
	MOVE.L A0,D0
	MOVE.L D0,proglabns+20
	BSR proglabscreen
	MOVE.L D0,mainvarscreenadr2
	MOVE.L mainvarscreenadr2(pc),D0		; rast2 := screenadr2+84
	ADD.L #84,D0
	MOVE.L D0,mainvarrast2
	MOVE.L mainvarscreenadr2(pc),D0		; VOID setcolours(screenadr2)
	MOVE.L D0,setcoloursvarrastport
	BSR proglabsetcolours
	MOVE.L mainvarscreenadr1(pc),D0		; ENDPROC screenadr1*screenadr2
	MULS mainvarscreenadr2+2(pc),D0
	RTS
proglabmain:		; PROC main()
	BSR proglabinit		; suxxes := init()
	MOVE.L D0,mainvarsuxxes
	MOVE.L mainvarsuxxes(pc),D0		; IF suxxes=0
	CMP.L #0,D0
	BNE endcmplabel0
	MOVEM.L D2/D3,-(A7)
	LEA directtextlab2(pc),A0
	MOVE.L A0,D0
	MOVE.L D0,D1
	MOVE.L A7,A1
	BSR printf
	LEA 0(A7),A7
	MOVEM.L (A7)+,D2/D3
	BRA endendcmplabel0		; ELSE
endcmplabel0:
mouselab2:		; MOUSE
	MOVEQ #0,D0		; FOR frame,maxframe,0,-1
	MOVE.W mainvarmaxframe(pc),D0
	ADDQ.W #1,D0
	MOVE.W D0,mainvarframe
forlabel3:
	SUBQ.W #1,mainvarframe
	MOVE.L mainvarrast1(pc),D0		; rast := rast1
	MOVE.L D0,mainvarrast
	MOVE.L mainvarscreenadr1(pc),D0		; screen := screenadr1
	MOVE.L D0,mainvarscreen
	MOVE.L mainvaractual(pc),D0		; IF actual=1
	CMP.L #1,D0
	BNE endcmplabel4
	MOVE.L mainvarrast2(pc),D0		; rast := rast2
	MOVE.L D0,mainvarrast
	MOVE.L mainvarscreenadr2(pc),D0		; screen := screenadr2
	MOVE.L D0,mainvarscreen
endcmplabel4:		; ENDIF
endendcmplabel1:
	MOVE.L mainvarrast(pc),D0		; VOID SetRast(rast,0)
	MOVE.L D0,A1
	MOVEQ #0,D0
	MOVE.L mainvargraphicsbase,A6
	JSR -234(A6)
	MOVEQ #1,D4		; colour := 1
	MOVEQ #0,D3		; frameoffset := maxline*frame*8+coordinates
	MOVE.W mainvarmaxline(pc),D3
	MULS mainvarframe(pc),D3
	ASL.L #3,D3
	ADD.L mainvarcoordinates(pc),D3
	MOVEQ #0,D7		; DOWN line,maxline
	MOVE.W mainvarmaxline(pc),D7
	SUBQ #1,D7
countlabel5:
	MOVEQ #0,D2		; lineoffset := line*8+frameoffset
	MOVE.W D7,D2
	ASL.L #3,D2
	ADD.L D3,D2
	MOVE.L mainvarrast(pc),D0		; VOID SetAPen(rast,colour)
	MOVE.L D0,A1
	MOVE.L D4,D0
	MOVE.L mainvargraphicsbase,A6
	JSR -342(A6)
	MOVE.L D2,D0		; x := MINT(lineoffset)
	MOVE.L D0,A0
	MOVE.W (A0),D0
	MOVE.W D0,D6
	MOVE.L D2,D0		; y := MINT(lineoffset+2)
	ADDQ.L #2,D0
	MOVE.L D0,A0
	MOVE.W (A0),D0
	MOVE.W D0,D5
	MOVE.L mainvarrast(pc),D0		; VOID Move(rast,x,y)
	MOVE.L D0,A1
	MOVEQ #0,D0
	MOVE.W D6,D0
	MOVEQ #0,D1
	MOVE.W D5,D1
	MOVE.L mainvargraphicsbase,A6
	JSR -240(A6)
	MOVE.L D2,D0		; x := MINT(lineoffset+4)
	ADDQ.L #4,D0
	MOVE.L D0,A0
	MOVE.W (A0),D0
	MOVE.W D0,D6
	MOVE.L D2,D0		; y := MINT(lineoffset+6)
	ADDQ.L #6,D0
	MOVE.L D0,A0
	MOVE.W (A0),D0
	MOVE.W D0,D5
	MOVE.L mainvarrast(pc),D0		; VOID Draw(rast,x,y)
	MOVE.L D0,A1
	MOVEQ #0,D0
	MOVE.W D6,D0
	MOVEQ #0,D1
	MOVE.W D5,D1
	MOVE.L mainvargraphicsbase,A6
	JSR -246(A6)
	ADDQ.L #1,D4		; INC 1,colour
	MOVE.L D4,D0		; IF colour>3
	CMP.L #3,D0
	BLE endcmplabel6
	MOVEQ #1,D4		; colour := 1
endcmplabel6:		; ENDIF
endendcmplabel2:
	DBRA D7,countlabel5		; ENDDOWN
	SUB.L #$10000,D7
	BCC countlabel5
	BTST #6,$bfe001		; JUMPMOUSE exit
	BEQ proglabexit
	MOVE.L mainvarscreen(pc),D0		; VOID ScreenToFront(screen)
	MOVE.L D0,A0
	MOVE.L mainvarintuitionbase,A6
	JSR -252(A6)
	MOVEQ #32,D0		; DMACON := 32
	MOVE.W D0,$DFF096
	MOVEQ #1,D0		; actual := 1-actual
	SUB.L mainvaractual(pc),D0
	MOVE.L D0,mainvaractual
	MOVE.L #0,D0		; ENDFOR
	CMP.W mainvarframe,D0
	BLT forlabel3
	BTST #6,$bfe001		; ENDMOUSE
	BNE mouselab2
endcmplabel1:		; ENDIF
endendcmplabel0:
proglabexit:		; exit:
	BSR proglabcleanup		; VOID cleanup()
	MOVEQ #0,D0		; ENDPROC
	RTS
proglabcleanup:		; PROC cleanup()
	MOVE.L mainvarscreenadr1(pc),D0		; IF screenadr1?0
	CMP.L #0,D0
	BEQ endcmplabel7
	MOVE.L mainvarscreenadr1(pc),D0		; VOID CloseScreen(screenadr1)
	MOVE.L D0,A0
	MOVE.L mainvarintuitionbase,A6
	JSR -66(A6)
endcmplabel7:		; ENDIF
endendcmplabel3:
	MOVE.L mainvarscreenadr2(pc),D0		; IF screenadr2?0
	CMP.L #0,D0
	BEQ endcmplabel8
	MOVE.L mainvarscreenadr2(pc),D0		; VOID CloseScreen(screenadr2)
	MOVE.L D0,A0
	MOVE.L mainvarintuitionbase,A6
	JSR -66(A6)
endcmplabel8:		; ENDIF
endendcmplabel4:
	MOVE.L #129,D0		; VOID view(129,44)
	MOVE.W D0,viewvarx
	MOVEQ #44,D0
	MOVE.W D0,viewvary
	BSR proglabview
	MOVEQ #0,D0		; ENDPROC
	RTS
proglabmakedata:		; PROC makedata()
	LEA proglabvectordata,A0		; adr := {vectordata}
	MOVE.L A0,D7
	MOVEQ #0,D5		; dummy := 0
	MOVEQ #0,D6		; FOR count,0,5199
	SUBQ.L #1,D6
forlabel9:
	ADDQ.L #1,D6
	MOVE.L D7,D0		; dummy := MCHAR(adr+count)
	ADD.L D6,D0
	MOVE.L D0,A0
	MOVE.B (A0),D0
	MOVE.W D0,D5
	MOVE.L #255,D0		; AND 255,dummy
	AND.W D0,D5
	MOVE.L D6,D0		; MINT count*2+coordinates,dummy*2
	ASL.L #1,D0
	ADD.L mainvarcoordinates(pc),D0
	MOVE.L D0,A1
	MOVEQ #0,D0
	MOVE.W D5,D0
	ASL.L #1,D0
	MOVE.W D0,(A1)
	MOVE.L #5199,D0		; ENDFOR
	CMP.L D6,D0
	BGT forlabel9
	MOVEQ #0,D0		; ENDPROC
	RTS
proglabview:		; PROC view( x, y)
	MOVE.L mainvarintuitionbase,A6		; viewadr := ViewAddress()
	JSR -294(A6)
	MOVE.L D0,viewvarviewadr
	MOVE.L viewvarviewadr(pc),D0		; MINT viewadr+14, x
	ADD.L #14,D0
	MOVE.L D0,A1
	MOVEQ #0,D0
	MOVE.W viewvarx(pc),D0
	MOVE.W D0,(A1)
	MOVE.L viewvarviewadr(pc),D0		; MINT viewadr+12, y
	ADD.L #12,D0
	MOVE.L D0,A1
	MOVEQ #0,D0
	MOVE.W viewvary(pc),D0
	MOVE.W D0,(A1)
	MOVE.L mainvarintuitionbase,A6		; VOID RemakeDisplay()
	JSR -384(A6)
	MOVEQ #0,D0		; ENDPROC
	RTS
proglabsetcolours:		; PROC setcolours( rastport)
	MOVE.L setcoloursvarrastport(pc),D0		; viewadr := rastport+44
	ADD.L #44,D0
	MOVE.L D0,setcoloursvarviewadr
	MOVE.L setcoloursvarviewadr(pc),D0		; VOID SetRGB4(viewadr,0,0,0,0)
	MOVE.L D0,A0
	MOVEQ #0,D0
	MOVEQ #0,D1
	MOVEQ #0,D2
	MOVEQ #0,D3
	MOVE.L mainvargraphicsbase,A6
	JSR -288(A6)
	MOVE.L setcoloursvarviewadr(pc),D0		; VOID SetRGB4(viewadr,1,5,5,15)
	MOVE.L D0,A0
	MOVEQ #1,D0
	MOVEQ #5,D1
	MOVEQ #5,D2
	MOVEQ #15,D3
	MOVE.L mainvargraphicsbase,A6
	JSR -288(A6)
	MOVE.L setcoloursvarviewadr(pc),D0		; VOID SetRGB4(viewadr,2,15,5,5)
	MOVE.L D0,A0
	MOVEQ #2,D0
	MOVEQ #15,D1
	MOVEQ #5,D2
	MOVEQ #5,D3
	MOVE.L mainvargraphicsbase,A6
	JSR -288(A6)
	MOVE.L setcoloursvarviewadr(pc),D0		; VOID SetRGB4(viewadr,3,15,15,5)
	MOVE.L D0,A0
	MOVEQ #3,D0
	MOVEQ #15,D1
	MOVEQ #15,D2
	MOVEQ #5,D3
	MOVE.L mainvargraphicsbase,A6
	JSR -288(A6)
	MOVEQ #0,D0		; ENDPROC
	RTS
proglabscreen:		; PROC screen( width, height, depth, mode, title)
	LEA proglabns,A0		; return := OpenScreen({ns})
	MOVE.L A0,D0
	MOVE.L D0,A0
	MOVE.L mainvarintuitionbase,A6
	JSR -198(A6)
	MOVE.L D0,D7
	MOVE.L D7,D0		; ENDPROC return
	RTS

mainvarscreenx: DC.W 400		; screenx=400:INT,screeny=320:INT,maxframe=49:INT,maxline=26:INT
mainvarscreeny: DC.W 320
mainvarmaxframe: DC.W 49
mainvarmaxline: DC.W 26
mainvarcoordinates: DC.L 0		; coordinates=10400:ARRAY,screenadr1:LONG,screenadr2:LONG
mainvarscreenadr1: DC.L 0
mainvarscreenadr2: DC.L 0
mainvarrast1: DC.L 0		; rast1:LONG,rast2:LONG,out:LONG
mainvarrast2: DC.L 0
mainvarout: DC.L 0
mainvarframe: DC.W 0		; frame:INT,line:REGINT,actual=0:LONG,rast:LONG,screen:LONG
mainvaractual: DC.L 0
mainvarrast: DC.L 0
mainvarscreen: DC.L 0
mainvarsuxxes: DC.L 0
viewvarx: DC.W 0		; x:INT,y:INT,viewadr:LONG
viewvary: DC.W 0
viewvarviewadr: DC.L 0
setcoloursvarrastport: DC.L 0		; rastport:LONG,viewadr:LONG
setcoloursvarviewadr: DC.L 0
directtextlab0:
	DC.B " ",0
	EVEN
directtextlab1:
	DC.B " ",0
	EVEN
mainvarstdout: DC.L 0		; WRITE 'Could not open screens!\n'
directtextlab2:
	DC.B "Could not open screens!",10,13,0
	EVEN
proglabvectordata:		; STRUCT vectordata
	INCBIN "dex:vector/TDEX.BIN"		; INCLUDE dex:vector/TDEX.BIN
	EVEN
proglabvectordataend:		; ENDSTRUCT
proglabns:		; STRUCT ns
	DC.W 0,0,320,256,2,515,0,1		; INT  0,0,320,256,2,$203,0,1
	DC.L 0,0,0,0		; LONG 0,0,0,0
proglabnsend:		; ENDSTRUCT
dosname: DC.B "dos.library",0
	EVEN
mainvardosbase: DC.L 0
graphicsname: DC.B "graphics.library",0
	EVEN
mainvargraphicsbase: DC.L 0
intuitionname: DC.B "intuition.library",0
	EVEN
mainvarintuitionbase: DC.L 0
	SECTION DexBSSHunk,BSS
arraylabcoordinates:
	DS.B 10400
	EVEN


	END

