
; Listings17m.s = LiquidSimulatorOK.s

****************************************************************************
	SECTION	exe000000,CODE
Start:
	MOVE.W	#$3E8,MAXDROPS
	CLR.W	NOOFDROPS
	CLR.B	MOVING
	MOVE.W	#$1F4,COLOURFLAG
	MOVE.L	#$5000,D0
	MOVE.L	#$10002,D1
	MOVEA.L	4,A6
	JSR	-$C6(A6)
	MOVE.L	D0,FIRSTBPL
	beq.w	QUIT
	MOVE.W	D0,B1L
	SWAP	D0
	MOVE.W	D0,B1H
	SWAP	D0
	ADDI.L	#$2800,D0
	MOVE.W	D0,B2L
	SWAP	D0
	MOVE.W	D0,B2H
	MOVE.L	FIRSTBPL,D0
	ADDI.L	#$3C,D0
	MOVE.L	D0,BPLORIG
	MOVE.W	MAXDROPS,D0
	MULU.W	#6,D0
	MOVEQ	#0,D1
	JSR	-$C6(A6)
	MOVE.L	D0,FIRSTDROP
	beq.w	QUIT1
	JSR	-$84(A6)
	bsr.w	MAINPROGRAM
	MOVEA.L	4,A6
	JSR	-$8A(A6)
	MOVE.W	MAXDROPS,D0
	MULU.W	#6,D0
	MOVEA.L	FIRSTDROP,A1
	JSR	-$D2(A6)
	LEA	GFXLIB(PC),A1
	MOVEQ	#0,D0
	JSR	-$228(A6)
	MOVEA.L	D0,A1
	MOVE.L	$26(A1),$80(A5)
	MOVE.W	#0,$88(A5)
	MOVE.W	#0,$1FC(A5)
	JSR	-$19E(A6)
QUIT1:
	MOVEA.L	FIRSTBPL,A1
	MOVE.L	#$5000,D0
	JMP	-$D2(A6)

MAINPROGRAM:
	LEA	$DFF000,A5
	MOVE.L	#POINTER,D0
	MOVE.W	D0,S0L
	SWAP	D0
	MOVE.W	D0,S0H
	CLR.L	MOUSEX
	MOVE.W	10,OLD0DAT
	bsr.w	VWAIT
	MOVE.L	#COPPER,$80(A5)
	MOVE.W	#0,$88(A5)
	MOVE.W	#$26C,$184(A5)
	MOVE.W	#$C41,$186(A5)
	MOVE.B	#1,DELFLAG
	CLR.B	UDFLAG
	CLR.B	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#1,D1
	CMP.W	#$FF,D1
	beq.w	WAIT
	bsr.w	PLOT
lbC000262:
	MOVE.W	MOUSEX,D0
	MOVE.W	MOUSEY,D1
	bsr.w	PLOT
	bra.w	WAIT

lbC000276:
	TST.B	MOVING
	beq.w	WAIT
	bra.w	MOVEWATER

QUIT:
	MOVE.L	lbL00063A,$68
	RTS

FREEZE:
	TST.W	NOOFDROPS
	beq.w	WAIT
	CLR.B	MOVING
	MOVE.W	#$CCF,$184(A5)
	MOVE.W	#$C68,$186(A5)
	bra.w	WAIT

THAW:
	MOVE.W	NOOFDROPS,D0
	beq.w	WAIT
	MOVE.B	#1,MOVING
	MOVE.W	#$26C,$184(A5)
	MOVE.W	#$C41,$186(A5)
	bra.w	WAIT

RESET:
	MOVE.W	NOOFDROPS,D0
	beq.w	WAIT
	MOVEA.L	FIRSTDROP,A4
lbC0002E0:
	MOVEA.L	(A4),A0
	MOVE.B	4(A4),D1
	ADDQ.L	#6,A4
	BTST	D1,$2800(A0)
	BEQ.S	lbC0002F4
	BCLR	D1,(A0)
	BCLR	D1,$2800(A0)
lbC0002F4:
	SUBQ.W	#1,D0
	BNE.S	lbC0002E0
	CLR.B	MOVING
	CLR.W	NOOFDROPS
	MOVE.W	#$1F4,COLOURFLAG
	bra.w	WAIT

WIPE:
	MOVEA.L	FIRSTBPL,A0
	MOVE.W	#$13FF,D0
lbC00031A:
	CLR.L	(A0)+
	DBRA	D0,lbC00031A
REDRAW:
	MOVE.W	NOOFDROPS,D0
	beq.w	DRAWBORDER
	MOVEA.L	FIRSTDROP,A4
lbC000330:
	MOVEA.L	(A4)+,A0
	MOVE.B	(A4)+,D1
	BSET	D1,$2800(A0)
	BTST	#0,(A4)+
	BEQ.S	lbC000342
	BSET	D1,(A0)
	BRA.S	lbC000344

lbC000342:
	BCLR	D1,(A0)
lbC000344:
	SUBQ.W	#1,D0
	BNE.S	lbC000330
	bra.w	DRAWBORDER

INVERT:
	CMPI.B	#$D1,$BFEC01
	BEQ.S	INVERT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G
	EORI.W	#$4E,SPRCOL
	BRA.S	GOTKEY

TESTUD:
	CMP.B	#$64,D0
	BLO.S	TESTLR
	CMP.B	#$68,D0
	BHS.S	GOTKEY
	ANDI.B	#1,D0
	MOVE.B	D0,UDFLAG
	BRA.S	GOTKEY

TESTLR:
	CMP.B	#$60,D0
	BLO.S	GOTKEY
	ANDI.B	#1,D0
	MOVE.B	D0,LRFLAG
GOTKEY:
	MOVE.L	(SP)+,D0
OLD2:
	dc.w	$4EF9
lbL00063A:
	dc.l	0
FIRSTBPL:
	dc.l	0
BPLORIG:
	dc.l	0
FIRSTDROP:
	dc.l	0
MAXDROPS:
	dc.w	0
NOOFDROPS:
	dc.w	0
MOUSEX:
	dcb.b	$2,0
MOUSEY:
	dc.w	0
OLD0DAT:
	dc.w	0
COLOURFLAG:
	dc.w	0
MOVING:
	dc.b	0
UDFLAG:
	dc.b	0
LRFLAG:
	dc.b	0
DELFLAG:
	dc.b	0
GFXLIB:
	dc.b	'graphics.library',0,0

	SECTION	exe00066C,CODE_C
COPPER:
	dc.l	$1002200,$1020000,$1040010,$1080000,$10A0000
	dc.l	$8E2C81,$902CC1,$920038,$9400D0
	dc.w	$E2
B1L:
	dc.w	0,$E0
B1H:
	dc.w	0,$E6
B2L:
	dc.w	0,$E4
B2H:
	dc.w	0,$122
S0L:
	dc.w	0,$120
S0H:
	dc.w	0,$126,0,$124,0,$12A,0,$128,0,$12E,0,$12C,0,$132
	dc.w	0,$130,0,$136,0,$134,0,$13A,0,$138,0,$13E,0,$13C
	dc.w	0,$180,0,$182,$EA4,$1A0,0,$1A2
SPRCOL:
	dc.w	$4E,$1A4,$3B,$1A6,$47D,$106,$C00,$1FC,0,$FFFF
	dc.w	$FFFE
POINTER:
	dc.l	0,$8000C000,$C000B000,$70004E00,$7E0041E0
	dc.l	$3F802040,$3F002080,$3F002080,$1F801040,$1FC01630
	dc.l	$19F0190C,$10F01088,$E00090,$400060,$400040,0
	end
