;
;	Disassembled by:
;		DASMx object code disassembler
;		(c) Copyright 1996-1999   Conquest Consultants
;		Version 1.30 (Oct  6 1999)
;
;       File:           circus.bin
;	CPU:		Signetics 2650 (2650 family)

;$VER: 1.0 (1.9.2006)
;Disassembled by Amigan Software in December 2002, February-March 2006,
; June 2006 and September 2006.
;Please inform us of any errors found...
;URL:   http://www.deadwoodinc.net/amigan/
;EMail: jrj76@optusnet.com.au

;2650 Equates-------------------------------------------------------------
z     equ  0
eq    equ  z
p     equ  1
gt    equ  p
n     equ  2
lt    equ  n
un    equ  3
;Hardware Equates/Memory Map----------------------------------------------
;                $0000..$0FFF can be ROM (first 4K of cartridge)
;                $1000..$17FF are unmapped
;                $1800..$18CF are upper screen display
;                $18D0..$18EF are user RAM
SPRITE0Y      equ 18F0h
SPRITE0X      equ 18F1h
SPRITE1Y      equ 18F2h
SPRITE1X      equ 18F3h
SPRITE2Y      equ 18F4h
SPRITE2X      equ 18F5h
SPRITE3Y      equ 18F6h
SPRITE3X      equ 18F7h
;                $18F8..$18FB are user RAM
VSCROLL       equ 18FCh ;crtc vertical position register
PITCH         equ 18FDh ;also other uses
VOLUME        equ 18FEh ;also other uses
CHARLINE      equ 18FFh ;current character line
P1LEFTKEYS    equ 1900h
P1MIDDLEKEYS  equ 1901h
P1RIGHTKEYS   equ 1902h
P1PALLADIUM   equ 1903h
P2LEFTKEYS    equ 1904h
P2MIDDLEKEYS  equ 1905h
P2RIGHTKEYS   equ 1906h
P2PALLADIUM   equ 1907h
CONSOLE       equ 1908h
;$1909..$197F are unmapped
;$1980..$19BF are user-defined characters
;$19C0..$19F7 are unmapped
RESOLUTION    equ 19F8h ;also other uses
BGCOLOUR      equ 19F9h ;also other uses
SPRITES23CTRL equ 19FAh
SPRITES01CTRL equ 19FBh
BGCOLLIDE     equ 19FCh
SPRITECOLLIDE equ 19FDh
P2PADDLE      equ 19FEh
P1PADDLE      equ 19FFh
;                $1A00..$1ACF are lower screen display
;                $1AD0..$1AFF are user RAM
;                $1B00..$1FFF are unmapped
;                $2000..$7FFF can be ROM (last 24K of cartridge)
;Variable Equates---------------------------------------------------------
;$18E6..$18E7 is a pointer
SOUNDVAR      equ 18D0h
;$18D1: unused
OFFSET        equ 18D2h
ROW1OFFSET  equ $18D3
ROW2OFFSET  equ $18D4
ROW3OFFSET  equ $18D5
ROW4OFFSET  equ $18D6
;$18E0..$18E1 is a pointer - the screen location of platform #1
;$18E2..$18E3 is a pointer - the screen location of platform #2
SPRITECOLCOPY equ 18EAh
FLAGS         equ 18DFh
PLAYERS       equ 1AE4h      ;'1' or '2'
;$1AE6..$1AE7 is a pointer, containing either $F07 or $EFA. It is set at
; initialization time and never changes.
; Offsets used with it are 0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12.
;$1AEA is always 0 or 3
;-------------------------------------------------------------------------
        org     $0000
;
	eorz	r0
        lpsu                 ;clear the Program Status Word
	lpsl
        ppsu    60h          ;set Program Status Byte Upper to %01100000
                             ;SP:  0   (Stack Pointer)     bits 0..2
                             ;II:  On  (Interrupt Inhibit) bit  5
                             ;F:   On  (Flag)              bit  6
                             ;S:   Off (Sense)             bit  7
        ppsl    02h          ;set Program Status Byte Lower to %00000010
                             ;C:   Off     (Carry)             bit  0
                             ;COM: Logical (Compare)           bit  1
                             ;OVF: Off     (Overflow)          bit  2
                             ;WC:  Off     (With Carry)        bit  3
                             ;RS:  Off     (Register Select)   bit  4
                             ;IDC: Off     (Inter Digit Carry) bit  5
                             ;CC:  Off     (Condition Code)    bits 6..7
        stra,r0 VSCROLL      ;VSCROLL = r0 [0];
        bsta,un WAITVBL
        eorz    r0           ;r0 = 0; // useless, r0 is already 0!
        strz    r1           ;r1 = r0 [0];
L000F:
;clear $1800..$1AFF
        stra,r0 17FFh,r1
        stra,r0 19FFh,r1
        stra,r0 18FFh,r1
	bdrr,r1	L000F
;end of loop
        lodi,r0 0E6h
        stra,r0 VSCROLL
        bsta,un WAITVBL
	eorz	r0
L0023:
;waits for the 'Sense input' (vertical blanking interval) to start
        tpsu    $80          ;test high bit of upper status byte      ;3,2
                             ;sets CC to 0 if all tested bits are set, 1 otherwise
        bcfr,eq L0023        ;if CC != 0 (ie. not doing VBL), retry   ;3,2
L0027:

;this took 6 cycles for the above two instructions
;the counter goes up by 1 for every 9 CPU cycles
;measures the length (ie. speed) of the vertical blanking interval!
;maybe this is to determine whether it is a PAL or NTSC system.
;this goes until the end of the vertical blanking interval
        addi,r0 $01          ;increment counter                       ;2,2
        tpsu    $80                                                   ;3,2
        bctr,eq L0027                                                 ;3,2
;end of loop

        comi,r0 $45          ;compare counter against $45 [69]
        bctr,gt L003D        ;if (>) goto L003D;

;if vertical blank takes <= 621 CPU cycles (ie. <= 207 for each of the
;3 "invisible" rastlines), we go into "green mode", otherwise we use
;"black mode".

;if r0 <= $45 [69] then *($1AE6..$1AE7) = $0F07; // "green mode"
        lodi,r0 $0F
        stra,r0 $1AE6
        lodi,r0 $07
        stra,r0 $1AE7
        bctr,un L0047        ;skip next section
L003D:
;else *($1AE6..$1AE7) = $0EFA; // "black mode"
        lodi,r0 $0E
        stra,r0 $1AE6
        lodi,r0 $FA
        stra,r0 $1AE7
;end if

L0047:
;set pointers to screen memory
        lodi,r0 $18
        stra,r0 18E0h
        stra,r0 18E2h        ;*(18E0) = *(18E2) = $18; (user RAM)
	bsta,un	L08C3
        lodi,r0 $03

        stra,r0 $1AEA        ;*($1AEA) = r0 [3];                        ;3

        lodi,r1 $09

        loda,r0 *$1AE6,r1    ;r0 = *(*($1AE6) + r1 [9]);

        stra,r0 BGCOLOUR

        lodi,r0 036h         ;r0 = %00110110;

        stra,r0 SPRITES01CTRL
        stra,r0 SPRITES23CTRL
        lodi,r0 $40
        stra,r0 RESOLUTION   ;RESOLUTION = r0 [$%01000000]; // set 26 row mode
        lodi,r1 008h
L006E:
        loda,r0 0DFFh,r1
        stra,r0 199Fh,r1
	bdrr,r1	L006E

        lodi,r1 018h         ;r1 = 24; // loop iterator
;copy left mover into sprite #0, seesaws into sprites #1 and #2
L0078:
        loda,r0 0E1Fh,r1     ;r0 = *(E1F + r1);
        stra,r0 197Fh,r1     ;*(197F + r1) = r0; // sprites #0..#2
        bdrr,r1 L0078        ;if (--r1 != 0) goto L0078;
;end of loop

        loda,r0 FLAGS        ;r0 = FLAGS;
;clear bit 0
        andi,r0 0FEh         ;r0 &= %11111110;
        stra,r0 FLAGS        ;FLAGS = r0;

;SPRITE0Y = SPRITE1Y = SPRITE2Y = r0 = *(*($1AE6..$1AE7));
        lodi,r1 000h
        loda,r0 *$1AE6,r1    ;r0 = *(*($1AE6) + r1 [0]); // useless! why not
;       loda,r0 *$1AE6       ;r0 = *(*($1AE6));          // instead?
        stra,r0 SPRITE0Y
        stra,r0 SPRITE1Y
        stra,r0 SPRITE2Y

        lodi,r0 067h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
        lodi,r1 005h
        loda,r0 *$1AE6,r1
        stra,r0 SPRITE3Y     ;SPRITE3Y = *(*(1AE6) + r1 [5]);
        lodi,r0 02Ch         ;r0 = $2C;
        stra,r0 SPRITE3X     ;SPRITE3X = r0 [$2C];
        bsta,un L0C9B        ;gosub L0C9B;

        lodi,r1 001h         ;r1 = 1;
        loda,r0 *1AE6h,r1    ;r0 = *(*(1AE6) + r1 [1]);
        stra,r0 1AE8h        ;*(1AE8) = r0;

        lodi,r1 002h         ;r1 = 2;
        loda,r0 *1AE6h,r1    ;r0 = *(*(1AE6) + r1 [2]);
        stra,r0 1AE9h        ;*(1AE9) = r0;

        lodi,r0 0C3h         ;r0 = $C3;

        stra,r0 *1AE8h       ;*(*(1AE8)) = r0 [$C3];
        loda,r1 1AE9h        ;r1 = *(1AE9);
        addi,r1 0Fh          ;r1 += 15;
        stra,r1 1AE9h        ;*(1AE9) = r1;
        stra,r0 *1AE8h
        lodi,r0 $20
        stra,r0 ROW1OFFSET
        lodi,r0 $20
        stra,r0 ROW2OFFSET
        lodi,r0 $60
        stra,r0 ROW3OFFSET
        lodi,r0 $60
        stra,r0 ROW4OFFSET
	bsta,un	L07BC
        lodi,r0 001h         ;r0 = 1;
        stra,r0 PLAYERS      ;PLAYERS = r0 [1];
L00EC:
        bsta,un WAITVBL      ;gosub L0B73;
        loda,r0 CONSOLE      ;r0 = CONSOLE;
        andi,r0 007h         ;r0 &= %00000111;
        comi,r0 002h         ;compare r0 against %00000010 (OPTION bit)
        bcfr,eq L0113        ;if (!=) goto L0113;
;OPTION has been pressed
        loda,r0 FLAGS        ;r0 = FLAGS;
        andi,r0 010h         ;r0 &= %00010000;
        bcta,eq L01AF        ;if (==) goto L01AF;

;PLAYERS--;
        loda,r0 PLAYERS      ;r0 = PLAYERS;
        subi,r0 01h          ;r0--;
        stra,r0 PLAYERS      ;PLAYERS = r0;

;FLAGS &= %11101111;
        loda,r0 FLAGS        ;r0 = FLAGS;
        andi,r0 0EFh         ;r0 &= %11101111; // clear bit 4
        stra,r0 FLAGS        ;FLAGS = r0;

        bcta,un L01AF        ;goto L01AF;
L0113:
        loda,r0 CONSOLE      ;r0 = CONSOLE;
        andi,r0 007h         ;r0 &= %0000111;
        comi,r0 004h         ;compare r0 against %00000100 (DIFFICULTY bit)
        bcfr,eq L0139        ;if (!=) goto L0139;

;DIFFICULTY has been pressed
;if bit 4 of FLAGS is set, goto L01AF
        loda,r0 FLAGS        ;r0 = FLAGS;                               ;3
        andi,r0 010h         ;r0 &= %00010000; // extract bit 4         ;2
        bcfa,eq L01AF        ;if (!=) goto L01AF;

;PLAYERS--;
        loda,r0 PLAYERS      ;r0 = PLAYERS; // user RAM
        subi,r0 01h          ;r0--;
        stra,r0 PLAYERS      ;PLAYERS = r0; // user RAM

;FLAGS |= %00010000;
        loda,r0 FLAGS        ;r0 = FLAGS;
        andi,r0 0EFh         ;r0 &= %11101111; // clear bit 4
        eori,r0 010h         ;Exclusive OR r0 with %00010000 // set bit 4 (inefficient!)
        stra,r0 FLAGS        ;FLAGS = r0;

        bcta,un L01AF        ;goto L01AF;
;
L0139:
        loda,r0 CONSOLE      ;r0 = CONSOLE;
        andi,r0 007h         ;r0 &= 00000111;
        comi,r0 001h         ;compare r0 against %00000001 (START bit)
        bctr,eq L0145        ;if (==) goto L0145;
        bcfa,eq L0158        ;if (!=) goto L0158; // inefficient!
L0145:
;START has been pressed
;begin game
        loda,r0 FLAGS        ;r0 = FLAGS;
;clear bit 7 (demo flag)
        andi,r0 07Fh         ;r0 &= %01111111;
        stra,r0 FLAGS        ;FLAGS = r0;

        eorz    r0           ;r0 = 0;
L014E:
;clear (' ' character) top line of screen
        lodi,r1 010h         ;loop iterator
L0150:
        stra,r0 17FFh,r1
	bdrr,r1	L0150
;end of loop

        bcta,un RUNGAME      ;goto RUNGAME;
L0158:
        loda,r1 1AEBh        ;get variable
        addi,r1 01h          ;increment by one
        stra,r1 1AEBh        ;update variable
;print "PLAYER GAME" on top line
        lodi,r1 010h         ;r1 = 16; // loop iterator
L0162:
        loda,r0 0E57h,r1
        stra,r0 17FFh,r1     ;*(17FF + r1) = *(E57 + r1);
	bdrr,r1	L0162
;end of loop

        loda,r0 FLAGS  
        andi,r0 010h
        bctr,eq L0178        ;if bit 4 of FLAGS is set, jump 

        lodi,r0 0D2h         ;set players to $D2

        stra,r0 1800h        ;show players
	bctr,un	L017D
;
L0178:

        lodi,r0 0D1h         ;set players to $D1

        stra,r0 1800h        ;show players
L017D:
        loda,r0 PLAYERS      ;r0 = PLAYERS;
        andi,r0 00Fh         ;extract lower nybble

        eori,r0 0D0h         ;Exclusive OR r0 with %11010000

;flip bits 7, 6 and 4
;bits 7..6 are colour, bits 5..0 are character
        stra,r0 180Eh        ;put on screen at (14,0)
        lodi,r0 00Fh         ;loop iterator
L0189:
        bsta,un WAITVBL      ;branch to subroutine 15 times
	bdrr,r0	L0189
;end of loop
        loda,r0 1AE5h
        addi,r0 01h
        stra,r0 1AE5h
        comi,r0 046h

        bcta,lt L00EC

	eorz	r0
        stra,r0 1AE5h

        loda,r0 FLAGS        ;r0 = FLAGS;
        andi,r0 07Fh         ;r0 &= %01111111;
;set bit 7 (demo flag)
        eori,r0 080h         ;Exclusive OR r0 with %10000000 // inefficient!
        stra,r0 FLAGS        ;FLAGS = r0;

	bcta,un	L014E
;
        db      01Fh, 000h, 0ECh
;
L01AF:
        loda,r0 PLAYERS      ;r0 = PLAYERS;
        addi,r0 01h          ;r0++;
        stra,r0 PLAYERS      ;PLAYERS = r0;
        comi,r0 008h         ;compare r0 against 8
        bcfa,gt L01C1        ;if (!(>)) goto L01C1;
        lodi,r0 001h         ;r0 = 1;
        stra,r0 PLAYERS      ;PLAYERS = r0;
L01C1:
        eorz    r0           ;r0 = 0;
        stra,r0 1AE5h        ;*(1AE5) = r0 [0];
        bcta,un L0158        ;goto L0158;
;Code Section-------------------------------------------------------------
RUNGAME:
        bsta,un WAITVBL
        bsta,un L07BC

        loda,r0 FLAGS  
        andi,r0 010h
	bcfr,eq	L01F1

	eorz	r0
        stra,r0 1AE5h

        lodi,r0 0D5h         ;set p1 lives to $D5

        stra,r0 1800h        ;show p1 lives

        lodi,r0 0D0h

        stra,r0 1805h
        stra,r0 1806h
        stra,r0 1807h
        stra,r0 1808h
        stra,r0 1809h

	bctr,un	L01FB
;
L01F1:
        lodi,r1 010h
L01F3:
        loda,r0 0E37h,r1
        stra,r0 17FFh,r1
	bdrr,r1	L01F3
L01FB:
        loda,r1 PLAYERS
        loda,r0 0EE9h,r1
	strz	r2
        loda,r0 0EF1h,r1
	strz	r3
        loda,r0 FLAGS        ;r0 = FLAGS;
;clear bits 5 and 2
        andi,r0 0DBh         ;r0 &= %11011011;
        eorz    r2
        stra,r0 FLAGS  

        stra,r3 1898h
        stra,r3 189Ch
	bcta,un	L02C5
;
L0218:
	eorz	r0
        stra,r0 1AE5h

        loda,r0 FLAGS  
        andi,r0 010h
	bcta,eq	L02C5

        loda,r0 FLAGS  
        andi,r0 002h
	bcta,eq	L0279
        lodi,r0 01Ah
        stra,r0 1ADEh
        lodi,r0 0D5h
        stra,r0 1ADFh
	bsta,un	L0893
        lodi,r0 01Ah
        stra,r0 1ADEh
        lodi,r0 0CFh
        stra,r0 1ADFh
	bsta,un	L0825

        loda,r0 FLAGS  
        andi,r0 0FDh
        stra,r0 FLAGS  

        lodi,r3 0006h

        lodi,r2 0D0h

L0252:
        loda,r0 0EE3h,r3
        stra,r0 18E1h
	bsta,un	L07F8
	bdrr,r3	L0252
        lodi,r3 0006h

        lodi,r2 090h

L0261:
        loda,r0 0EDDh,r3
        stra,r0 18E1h
	bsta,un	L07F8
	bdrr,r3	L0261

        lodi,r0 018h
        stra,r0 1AE2h
        lodi,r0 0FFh
        stra,r0 1AE3h
	bcta,un	L02C5
;
L0279:
        lodi,r0 01Ah
        stra,r0 1ADEh
        lodi,r0 0CFh
        stra,r0 1ADFh
	bsta,un	L0893
        lodi,r0 01Ah
        stra,r0 1ADEh
        lodi,r0 0D5h
        stra,r0 1ADFh
	bsta,un	L0825

        loda,r0 FLAGS  
        andi,r0 0FDh
        eori,r0 002h
        stra,r0 FLAGS  

        lodi,r3 0006h

        lodi,r2 0D0h

L02A1:
        loda,r0 0EDDh,r3
        stra,r0 18E1h
	bsta,un	L07F8
	bdrr,r3	L02A1

        lodi,r3 0006h

        lodi,r2 090h

L02B0:
        loda,r0 0EE3h,r3
        stra,r0 18E1h
	bsta,un	L07F8
	bdrr,r3	L02B0
        lodi,r0 019h
        stra,r0 1AE2h
        lodi,r0 003h
        stra,r0 1AE3h
L02C5:
;check whether game over
        loda,r0 1800h        ;get p1 lives
        andi,r0 00Fh         ;ignore colour nybble
        loda,r2 1802h        ;get p2 lives
        andi,r2 00Fh         ;ignore colour nybble
        addz    r2           ;add lives together, store answer in r0
        bcfa,eq L0367        ;if (!=) goto L0367;
        lodi,r1 010h         ;loop iterator
L02D5:
;print "GAME  OVER"
        loda,r0 0F13h,r1
        stra,r0 1A1Fh,r1
	bdrr,r1	L02D5
;end of loop

        loda,r0 FLAGS  
        andi,r0 010h
	bctr,eq	L02F3

        lodi,r3 0006h

        lodi,r2 0D0h

L02E8:
        loda,r0 0EDDh,r3
        stra,r0 18E1h
	bsta,un	L07F8
	bdrr,r3	L02E8
L02F3:
        bsta,un WAITVBL

        loda,r0 FLAGS  
        andi,r0 010h
        bcfa,eq L0327

        lodi,r1 000h
L0300:
        loda,r0 1806h,r1
        andi,r0 00Fh
	strz	r2
        loda,r0 180Ch,r1
        andi,r0 00Fh
	comz	r2
	bcta,gt	L0327
	bctr,lt	L0319
        addi,r1 01h
        comi,r1 004h
	bcfr,gt	L0300
	bctr,un	L0327
;
L0319:
        lodi,r1 005h
L031B:
        loda,r0 1804h,r1
        andi,r0 00Fh

        eori,r0 090h         ;Exclusive OR r0 with %10010000

        stra,r0 180Ah,r1
	bdrr,r1	L031B
L0327:
        loda,r0 CONSOLE      ;r0 = CONSOLE;
        andi,r0 007h         ;r0 &= %00000111;
        comi,r0 001h         ;compare r0 against %00000001 (START bit)
        bcfa,eq L033F        ;if (!=) goto L033F;
;START has been pressed

        loda,r0 FLAGS        ;r0 = *(18DF);
;clear bit 7 (demo flag)
        andi,r0 07Fh         ;r0 &= %01111111;
        stra,r0 FLAGS        ;*(18DF) = r0;

        bsta,un NEWGAME      ;gosub NEWGAME;
        bcta,un RUNGAME      ;goto RUNGAME;
;
L033F:
        lodi,r1 00Fh         ;r1 = 15; // loop iterator
L0341:
        bsta,un WAITVBL      ;gosub WAITVBL;
        bdrr,r1 L0341        ;if (--r1 != 0) goto L0341;
;end of loop

        loda,r0 1AE5h
        addi,r0 01h
        stra,r0 1AE5h
        comi,r0 046h

        bcta,lt L02F3

;now we want to begin the demo
        loda,r0 FLAGS        ;r0 = FLAGS;
        andi,r0 07Fh         ;r0 &= %01111111;
;set bit 7 (demo flag)
        eori,r0 080h         ;Exclusive OR with %10000000 // inefficient!
        stra,r0 FLAGS        ;FLAGS = r0;

        eorz    r0           ;r0 = 0;
        stra,r0 1AE5h        ;*(1AE5) = r0 [0];
        bsta,un NEWGAME      ;gosub NEWGAME;
        bcta,un RUNGAME      ;goto RUNGAME;
;
L0367:
        loda,r0 FLAGS  
        andi,r0 001h
	bcfr,eq	L037D

        lodi,r1 005h
        loda,r0 *$1AE6,r1
        stra,r0 SPRITE3Y     ;r0 = *(*(1AE6) + r1 [5]);
        lodi,r0 02Ch
        stra,r0 SPRITE3X
	bctr,un	L038A
;
L037D:
        lodi,r1 005h
        loda,r0 *$1AE6,r1
        stra,r0 SPRITE3Y     ;SPRITE3Y = *(*(1AE6) + r1 [5]);
        lodi,r0 0A3h
        stra,r0 SPRITE3X
L038A:
        bsta,un L0C9B        ;gosub L0C9B;

        lodi,r1 004h         ;r1 = 4; // loop iterator
L038F:
        loda,r0 *1AE2h,r1    ;r0 = *(*(1AE2) + r1);
        andi,r0 00Fh         ;r0 &= %00001111;
        bcfr,eq L03A3        ;if (!=) goto L03A3;
        bdrr,r1 L038F        ;if (--r1 != 0) goto L038F;
;end of loop

        loda,r0 FLAGS        ;r0 = FLAGS;
;extract bit 7 (demo flag)
        andi,r0 080h         ;r0 &= %10000000;
        bcfa,eq L03A3        ;if (!=) goto L03A3;

        bcta,un L038A        ;goto L038A;
;
L03A3:

        loda,r0 FLAGS  
        andi,r0 0F7h
        stra,r0 FLAGS  

;*($1AEA) = SPRITE3X = r0 = 3;
        lodi,r0 $03          ;r0 = 3;
        stra,r0 $1AEA        ;*($1AEA) = r0 [3];
        loda,r0 SPRITE3X     ;SPRITE3X = r0 [3];

;if acrobat's x-position > 40, goto L03BA
        comi,r0 040h
	bctr,gt	L03BA
	bcta,un	L03BD
L03BA:
	bcta,un	L03C4
;
L03BD:
        lodi,r3 001h
        stra,r3 18D9h
	bctr,un	L03C9
;Code Section-------------------------------------------------------------
L03C4:
        lodi,r3 0FFh         ;r3 = $FF;
        stra,r3 18D9h        ;*(18D9) = r3 [$FF];
L03C9:
        bsta,un L0C9B        ;gosub L0C9B;
        bsta,un CHECKLIMITS  ;gosub CHECKLIMITS;
        comi,r0 05Fh         ;compare r0 against $5F
        bcta,lt L0408        ;if (<) goto L0408;
        comi,r0 07Fh         ;compare r0 against $7F
        bcta,lt L0417        ;if (<) goto L0417;
        comi,r0 08Bh         ;compare r0 against $8B
        bcta,lt L0426        ;if (<) goto L0426;
        comi,r0 093h         ;compare r0 against $93
        bcta,lt L0444        ;if (<) goto L0444;
        comi,r0 097h         ;compare r0 against $97
        bcta,lt L0435        ;if (<) goto L0435;
        loda,r0 18D9h        ;r0 = *(18D9);
        comi,r0 001h         ;compare r0 against 1
        bcta,eq L0453        ;if (==) goto L0453;
        bcta,un L045A        ;goto L045A;
;
L03F3:
;r1 is 0..4
;r0 = *(EA5 + r1);
        loda,r0 0EA5h,r1     ;r0 = *(EA5 + r1);
        stra,r0 18DBh        ;*(18DB) = r0;
        loda,r0 18D9h        ;r0 = *(18D9);
        stra,r0 18DAh        ;*(18DA) = r0;
        bsta,un L0D3E        ;gosub L0D3E;
        bsta,un L0D85        ;gosub L0D85;
        bcta,un L03C9        ;goto L03C9;
;
L0408:
        lodi,r1 004h         ;r1 = 4;
        lodi,r0 067h         ;r0 = $67;
        stra,r0 18E9h        ;*(18E9) = r0 [$67];
        lodi,r0 00Eh         ;r0 = 14;
        stra,r0 18E8h        ;*(18E8) = r0 [14];
        bcta,un L03F3        ;goto L03F3;
;
L0417:
        lodi,r1 003h
        lodi,r0 06Fh
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L03F3
;
L0426:
        lodi,r1 002h
        lodi,r0 077h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L03F3
;
L0435:
        lodi,r1 000h         ;r1 = 0;
        lodi,r0 087h         ;r0 = $87;
        stra,r0 18E9h        ;*(18E9) = r0 [$87];
        lodi,r0 00Eh         ;r0 = 14;
        stra,r0 18E8h        ;*(18E8) = r0 [14];
        bcta,un L03F3        ;goto L03F3;
;
L0444:
        lodi,r1 001h
        lodi,r0 07Fh
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L03F3
;
L0453:
        lodi,r3 001h
        stra,r3 18D9h
	bctr,un	L045F
;
L045A:
        lodi,r3 0FFh
        stra,r3 18D9h
L045F:
	bsta,un	L0C9B
        bsta,un CHECKLIMITS
        lodi,r1 006h
        coma,r0 *$1AE6,r1
	bcta,lt	L04A4
        comi,r0 05Fh
	bcta,lt	L04AF
        comi,r0 07Fh
	bcta,lt	L04BE
        comi,r0 08Bh
	bcta,lt	L04CD
        comi,r0 093h
	bcta,lt	L04DC
        comi,r0 097h
	bcta,lt	L04EB
        lodi,r0 097h
        stra,r0 SPRITE3Y     ;SPRITE3Y = $97;
        lodi,r1 000h
        lodi,r2 001h
L048F:
        loda,r0 0EA0h,r1
        stra,r0 18DBh
        loda,r0 18D9h
        stra,r0 18DAh
	bsta,un	L0D3E
	bsta,un	L0D85
	bcta,un	L045F
;
L04A4:
        lodi,r1 004h         ;r1 = 4;
        bsta,un CHECKSPRITEHIT ;gosub CHECKSPRITEHIT;
        bcfa,eq L06AE        ;if (!=) goto L06AE;
;if (SPRITECOLCOPY == $FF)
        bcta,un L0579        ;goto L0579;
;
L04AF:
        lodi,r1 004h
        lodi,r0 067h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L048F
;
L04BE:
        lodi,r1 003h
        lodi,r0 06Fh
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L048F
;
L04CD:
        lodi,r1 002h
        lodi,r0 077h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L048F
;
L04DC:
        lodi,r1 001h
        lodi,r0 07Fh
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L048F
;
L04EB:
        lodi,r1 000h
        lodi,r0 087h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	bcta,un	L048F
;
L04FA:
	bsta,un	L0C9B
        bsta,un CHECKLIMITS
        lodi,r1 006h
        coma,r0 *$1AE6,r1
	bcta,lt	L06A6
        comi,r0 0AFh
	bcta,lt	L05B4
        comi,r0 0BFh
	bcfa,gt	L05E3
        comi,r0 0C7h
	bcfa,gt	L0606
        comi,r0 0CFh
	bcfa,gt	L0638
        comi,r0 0D7h
	bcfa,gt	L065B
        comi,r0 0DFh
	bcfa,gt	L068D
        loda,r0 18DBh
	bsta,un	L0D38
        stra,r0 18DBh
        lodi,r0 0DAh
        stra,r0 SPRITE3Y     ;SPRITE3Y = $DA;
L0534:
	bsta,un	L0D3E
	bsta,un	L0D85
	bcta,un	L04FA
;Code Section-------------------------------------------------------------
BOUNCELEFTWALL:
        lodi,r1 005h         ;r1 = 5;
        loda,r0 *$1AE6,r1    ;r0 = *(*(1AE6) + r1 [5]);
        stra,r0 SPRITE3Y     ;SPRITE3Y = r0;
        lodi,r0 02Ch         ;r0 = $2C;
        stra,r0 SPRITE3X     ;SPRITE3X = r0 [$2C];
        bcta,un L055A        ;goto L055A;
;Code Section-------------------------------------------------------------
BOUNCERIGHTWALL:
        lodi,r1 005h         ;r1 = 5;
        loda,r0 *$1AE6,r1    ;r0 = *(*(1AE6) + r1 [5]);
        stra,r0 SPRITE3Y     ;SPRITE3Y = r0;
        lodi,r0 0A3h         ;r0 = $A3;
        stra,r0 SPRITE3X     ;SPRITE3X = r0 [$A3];
;Code Section-------------------------------------------------------------
L055A:
        loda,r0 VOLUME       ;r0 = VOLUME;
        andi,r0 0E0h         ;r0 &= %11100000;
;flip bits 0..3
        eori,r0 00Fh         ;Exclusive OR r0 with %00001111
        stra,r0 VOLUME       ;VOLUME = r0;
        lodi,r0 0C7h         ;r0 = $C7;
        stra,r0 18DDh        ;*(18DD) = r0 [$C7];
        lodi,r0 00Eh         ;r0 = 14;
        stra,r0 18DCh        ;*(18DC) = r0 [14];
        loda,r0 SPRITE3X     ;r0 = SPRITE3X;
        comi,r0 040h         ;compare r0 against %01000000
        bcta,lt L03BD        ;if (<) goto L03BD;
        bcta,un L03C4        ;goto L03C4;
;Code Section-------------------------------------------------------------
L0579:
        loda,r0 SPRITE3X     ;get sprite 3 x-pos, put into r0
        comi,r0 033h         ;compare r0 against $33
        bcta,lt L0594        ;if (<) goto L0594;
        comi,r0 0A4h         ;compare r0 against $A4
        bcta,gt L05A4        ;if (>) goto L05A6;
;if sprite 3 x-position is $33..$A4
CALLSPLAT:
        bsta,un SPLAT
        lodi,r0 000h         ;r0 = 0;
        stra,r0 $1AEA        ;*($1AEA) = r0 [0];
        bsta,un L0902
	bcta,un	L0218
;
L0594:
        lodi,r1 005h
        loda,r0 *$1AE6,r1
        stra,r0 SPRITE3Y     ;SPRITE3Y = *(*(1AE6) + r1 [5]);
        lodi,r0 02Ch
        stra,r0 SPRITE3X
	bcta,un	L03BD
;
L05A4:
        lodi,r1 005h
        loda,r0 *$1AE6,r1
        stra,r0 SPRITE3Y     ;SPRITE3Y = *(*(1AE6) + r1 [5]);
        lodi,r0 0A3h
        stra,r0 SPRITE3X
	bcta,un	L03C4
;
L05B4:
        lodi,r0 067h
        stra,r0 18E9h        ;*(18E9) = $67;
        lodi,r0 00Eh
        stra,r0 18E8h        ;*(18E8) = $E;
        bsta,un CHECKBGHIT   ;background collision check
        bcfr,eq L05C6        ;change direction
	bcta,un	L0534
;
L05C6:
        loda,r0 18DBh        ;r0 = *(18DB); // user RAM
        bctr,gt L05D2        ;if (>) goto L05D2;
        lodi,r0 0AFh
        stra,r0 SPRITE3Y     ;SPRITE3Y = $AF;
        bctr,un L05D7        ;goto L0537;
;
L05D2:
        lodi,r0 09Dh
        stra,r0 SPRITE3Y     ;SPRITE3Y = $9D;
L05D7:
        loda,r0 18DBh        ;r0 = *(18D8); // user RAM
        bsta,un L0D38        ;gosub L0D38;
        stra,r0 18DBh        ;*(18D8) = r0; // user RAM
        bcta,un L0534        ;goto L0534;
;
L05E3:
        lodi,r0 07Fh
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
        loda,r1 ROW3OFFSET
        lodi,r0 060h
        stra,r0 18E1h
	bsta,un	L0A42
        stra,r3 OFFSET
        lodi,r3 001h
        bsta,un CHECKBGHIT    ;background collision check
        bcfa,eq BALLOONBOUNCE
	bcta,un	L0534
;
L0606:
        loda,r1 ROW3OFFSET
        lodi,r0 060h
        stra,r0 18E1h
	bsta,un	L0A42
        stra,r3 OFFSET
        loda,r0 1860h,r3
	bcta,eq	L061F
        lodi,r3 001h
	bcta,un	L062F
;
L061F:
        loda,r1 ROW2OFFSET
        lodi,r0 $40
        stra,r0 $18E1          ;*(18E1) = r0 [$40];
        bsta,un L0A42
        stra,r3 OFFSET
        lodi,r3 002h
L062F:
        bsta,un CHECKBGHIT     ;background collision check
        bcfa,eq BALLOONBOUNCE
	bcta,un	L0534
;
L0638:
        lodi,r0 087h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
        loda,r1 ROW2OFFSET
        lodi,r0 040h
        stra,r0 18E1h
	bsta,un	L0A42
        stra,r3 OFFSET
        lodi,r3 002h
        bsta,un CHECKBGHIT     ;background collision check
        bcfa,eq BALLOONBOUNCE
	bcta,un	L0534
;
L065B:
        loda,r1 ROW2OFFSET
        lodi,r0 040h
        stra,r0 18E1h
	bsta,un	L0A42
        stra,r3 OFFSET
        loda,r0 1840h,r3
	bcta,eq	L0674
        lodi,r3 002h
	bcta,un	L0684
;
L0674:
        loda,r1 ROW1OFFSET
        lodi,r0 020h
        stra,r0 18E1h
	bsta,un	L0A42
        stra,r3 OFFSET
        lodi,r3 004h
L0684:
        bsta,un CHECKBGHIT     ;background collision check
        bcfa,eq BALLOONBOUNCE
	bcta,un	L0534
;
L068D:
        loda,r1 ROW1OFFSET
        lodi,r0 020h
        stra,r0 18E1h
	bsta,un	L0A42
        stra,r3 OFFSET
        lodi,r3 004h
        bsta,un CHECKBGHIT    ;background collision check
        bcfa,eq BALLOONBOUNCE
	bcta,un	L0534
;
L06A6:
        bsta,un CHECKSPRITEHIT;gosub CHECKSPRITEHIT;
        bcfr,eq L06AE         ;if (!=) goto L06AE;
        bcta,un L0579         ;goto L0579;
;Code Section-------------------------------------------------------------
L06AE:
        bsta,un WAITVBL       ;gosub WAITVBL;
        bsta,un L0AFC         ;gosub L0AFC;
        bsta,un WAITLINES     ;gosub WAITLINES;
        loda,r0 SPRITECOLCOPY ;r0 = SPRITECOLCOPY;

        loda,r2 FLAGS         ;put FLAGS into r2
        andi,r2 $01           ;r2 &= %00000001;
        bcfa,eq L0718         ;if (!=) goto L0718;

        andi,r0 $04           ;r0 &= %00000100;

        bcta,eq CALLSPLAT     ;if (==) goto CALLSPLAT;

L06C7:
        loda,r0 18DBh         ;r0 = *(18DB);
        bsta,un L0D38         ;gosub L0D38;
        stra,r0 18DBh         ;*(18DB) = r0;

        loda,r0 18DAh         ;r0 = *(18DA);
        bctr,gt L06DB         ;if (>) goto L06DB;
        bsta,un L0D38         ;gosub L0D38;
        stra,r0 18DAh         ;*(18DA) = r0;
L06DB:
        loda,r0 SPRITE0X      ;r0 = SPRITE0X;
        stra,r0 SPRITE3X      ;SPRITE3X = r0;
        loda,r0 SPRITE0Y      ;r0 = SPRITE0Y;
        addi,r0 10h           ;r0 += 16;
        stra,r0 SPRITE3Y      ;SPRITE3Y = r0;
        bsta,un L08ED         ;gosub L08ED;

;wait for start of vertical blank
L06EC:
        tpsu    80h           ;test mask %10000000 of PSU (Sense bit)
        bcfr,eq L06EC         ;if (!=) goto L06EC;
;end of loop

        lodi,r1 018h          ;r1 = 24; // loop iterator
;copy seesaws into sprites #0 and #1, right mover into sprite #2
L06F2:
        loda,r0 0E07h,r1      ;r0 = *(E07 + r1);
        stra,r0 197Fh,r1      ;*(197F + r1) = r0; // sprites #0..#2
        bdrr,r1 L06F2         ;if (--r1 != 0) goto L06F2;
;end of loop

;wait for start of vertical blank
L06FA:
        tpsu    80h           ;test mask %10000000 of PSU
        bctr,eq L06FA         ;if (==) goto L06FA;
;end of loop

        bsta,un L0AFC         ;gosub L0AFC;
        bsta,un WAITLINES     ;gosub WAITLINES;
        loda,r0 FLAGS         ;r0 = FLAGS;
        lodi,r1 001h          ;r1 = %00000001;
;flip bit 0
        eorz    r1            ;r0 |= r1 [%00000001];
        stra,r0 FLAGS         ;FLAGS = r0;
        loda,r0 SPRITECOLCOPY ;r0 = SPRITECOLCOPY;

        andi,r0 010h          ;r0 &= %00010000; // test bit 4

        bcfa,eq L076E         ;if (!=) goto L076E;
        bcta,un L03BD         ;goto L03BD;
;Code Section-------------------------------------------------------------
L0718:
        andi,r0 020h         ;r0 &= %00100000; // test bit 5

        bcta,eq CALLSPLAT    ;if (==) goto CALLSPLAT;

L072D:
        loda,r0 18DBh        ;r0 = *(18DB);
        bsta,un L0D38        ;gosub L0D38;
        stra,r0 18DBh        ;*(18DB) = r0;
        loda,r0 18DAh        ;r0 = *(18DA);
        bctr,lt L0731        ;if (<) goto L0731;
        bsta,un L0D38        ;gosub L0D38;
        stra,r0 18DAh        ;*(18DA) = r0;
L0731:
        loda,r0 SPRITE2X     ;r0 = SPRITE2X;     
        stra,r0 SPRITE3X     ;SPRITE3X = r0;
        loda,r0 SPRITE2Y     ;r0 = SPRITE2Y;
        addi,r0 10h          ;r0 += 16;
        stra,r0 SPRITE3Y     ;SPRITE3Y = r0;
        bsta,un L08ED        ;gosub L08ED;

;wait for start of vertical blank
L0742:
        tpsu    80h          ;test mask %10000000 of PSU (Sense bit)
        bcfr,eq L0742        ;if (!=) goto L0742;
;end of loop

        lodi,r1 018h         ;r1 = 24; // loop iterator
;copy left mover into sprite #0, seesaws into sprites #1 and #2
L0748:
        loda,r0 0E1Fh,r1     ;r0 = *(E1F + r1);
        stra,r0 197Fh,r1     ;*(197F + r1) = r0; // sprites #0..#2
        bdrr,r1 L0748        ;if (--r1 != 0) goto L0748;
;end of loop

;wait for end of vertical blank
L0750:
        tpsu    80h          ;test mask %10000000 of PSU (Sense bit)
        bctr,eq L0750        ;if (==) goto L0750;
;end of loop

        bsta,un L0AFC        ;gosub L0AFC;
        bsta,un WAITLINES    ;gosub WAITLINES;

        loda,r0 FLAGS        ;r0 = FLAGS;
        lodi,r1 0FEh         ;r1 = %11111110;
        andz    r1           ;r0 &= r1 [%11111110];
        stra,r0 FLAGS        ;FLAGS = r0;

        loda,r0 SPRITECOLCOPY;r0 = SPRITECOLCOPY;
;test for collision between sprites 1 and 3
        andi,r0 010h         ;r0 &= %00010000; // test bit 4
        bcfa,eq L077E        ;if (!=) goto L077E;
        bcta,un L03C4        ;goto L03C4;
;Code Section-------------------------------------------------------------
L076E:
        lodi,r1 $07
        loda,r0 *$1AE6,r1
        stra,r0 18DBh
        lodi,r0 001h
        stra,r0 18DAh
	bcta,un	L04FA
;
L077E:
        lodi,r1 $07
        loda,r0 *$1AE6,r1
        stra,r0 18DBh
        lodi,r0 0FFh
        stra,r0 18DAh
	bcta,un	L04FA
;Subroutine---------------------------------------------------------------
NEWGAME:
        lodi,r1 010h         ;r1 = 16; // loop iterator
        eorz    r0           ;r0 = 0;
;clear lower screen from $1A20..$1A2F (row 2)
L0791:
        stra,r0 1A1Fh,r1     ;*(1A1F + r1) = r0 [0];
        bdrr,r1 L0791        ;if (--r1 != 0) goto L0791;
;end of loop

        lodi,r0 003h         ;r0 = 3;
        stra,r0 $1AEA        ;*($1AEA) = r0 [3];
        retc,un              ;return;
;Subroutine---------------------------------------------------------------
CHECKLIMITS:
;sprite #3 is acrobat
        loda,r0 SPRITE3X      ;r0 = SPRITE3X;
        comi,r0 02Bh          ;compare r0 against $2B
        bcta,lt BOUNCELEFTWALL;if (<) goto BOUNCELEFTWALL;
        comi,r0 0A4h          ;compare r0 against $A4
        bcta,gt BOUNCERIGHTWALL;if (>) goto BOUNCERIGHTWALL;
        bsta,un L0D5B         ;gosub L0D5B;
        bsta,un PLAYNOTE      ;gosub PLAYNOTE;
        loda,r0 SPRITE3Y      ;SPRITE3Y = r0;
        retc,un               ;return;
;Subroutine---------------------------------------------------------------
WAITVBL:
;Wait for Sense bit to go off then on (remember that TPSU inverts)
        tpsu    80h
        bcfr,eq WAITVBL
WAITVBL_1:
        tpsu    80h
        bctr,eq WAITVBL_1
	retc,un
;-------------------------------------------------------------------------
L07BC:
        lodi,r0 010h
        stra,r0 18E4h
        stra,r0 18E5h
        stra,r0 18E6h
        lodi,r0 067h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
        lodi,r1 00Ch
        lodi,r0 0FFh
L07D5:
        stra,r0 1ACFh,r1
	bdrr,r1	L07D5
        lodi,r0 018h
        stra,r0 1AE2h
        lodi,r0 0FFh
        stra,r0 1AE3h

        loda,r0 FLAGS  
        andi,r0 0FDh
        stra,r0 FLAGS  

	bsta,un	L08C3
        lodi,r1 010h
	eorz	r0
L07F2:
        stra,r0 188Fh,r1
	bdrr,r1	L07F2
	retc,un
;
L07F8:
        loda,r0 *18E0h
        andi,r0 00Fh
	eorz	r2
        stra,r0 *18E0h
	retc,un
;
L0802:
        lodi,r1 000h
L0804:
        loda,r0 *1ADEh
        andi,r0 001h
	bctr,eq	L0817
	lodz	r3
        stra,r0 *18E0h,r1
        loda,r2 *1AE0h
        addi,r2 01h
        stra,r2 *1AE0h
L0817:
        loda,r0 *1ADEh
	rrr,r0
        stra,r0 *1ADEh
        addi,r1 01h
        comi,r1 008h
	bctr,lt	L0804
	retc,un
;
L0825:
        lodi,r1 050h
	eorz	r0
L0828:
        stra,r0 181Fh,r1
	bdrr,r1	L0828
        stra,r0 18E4h
        stra,r0 18E5h
        stra,r0 18E6h
        lodi,r0 018h
        stra,r0 1AE0h
        lodi,r0 006h
        stra,r0 1ADDh
L0840:
        loda,r1 1ADDh
        loda,r0 0ECBh,r1
        stra,r0 18E1h
        loda,r0 1ADFh
        addi,r0 01h
        stra,r0 1ADFh
        loda,r0 0ED1h,r1
        stra,r0 1AE1h
        loda,r0 0ED7h,r1
	strz	r3
	bsta,un	L0802
        loda,r0 1ADDh
        subi,r0 01h
        stra,r0 1ADDh
	bcfr,eq	L0840
	retc,un
;
L0869:
        lodi,r1 007h
L086B:
        loda,r0 *18E0h,r1
        comi,r0 000h
	bctr,eq	L087A
        loda,r2 *1ADEh
        addi,r2 01h
        stra,r2 *1ADEh
L087A:
        loda,r2 *1ADEh
	rrl,r2
        stra,r2 *1ADEh
	bdrr,r1	L086B
        loda,r0 *18E0h
        comi,r0 000h
	bctr,eq	L0892
        loda,r2 *1ADEh
        addi,r2 01h
        stra,r2 *1ADEh
L0892:
	retc,un
;
L0893:
	eorz	r0
        lodi,r1 001h
L0896:
        stra,r0 *1ADEh,r1
        addi,r1 01h
        comi,r1 007h
	bctr,lt	L0896
        lodi,r0 006h
        stra,r0 1ADDh
L08A4:
        loda,r1 1ADDh
        loda,r0 0ECBh,r1
        stra,r0 18E1h
        loda,r2 1ADFh
        addi,r2 01h
        stra,r2 1ADFh
	bsta,un	L0869
        loda,r0 1ADDh
        subi,r0 01h
        stra,r0 1ADDh
	bcfr,eq	L08A4
	retc,un
;
L08C3:

        lodi,r0 07Ch

        lodi,r1 01Fh
        stra,r1 18E1h
	bsta,un	L0D53

        lodi,r0 0FCh

        lodi,r1 03Fh
        stra,r1 18E1h
	bsta,un	L0D53

        lodi,r0 0BCh

        lodi,r1 05Fh
        stra,r1 18E1h
	bsta,un	L0D53
        lodi,r0 010h
        stra,r0 18E4h
        stra,r0 18E5h
        stra,r0 18E6h
	retc,un
;
L08ED:
        loda,r0 VOLUME
        andi,r0 0E0h
        eori,r0 00Fh
        stra,r0 VOLUME
        lodi,r0 0AEh
        stra,r0 18DDh
        lodi,r0 00Eh
        stra,r0 18DCh
	retc,un
;
L0902:
        lodi,r1 $08
        loda,r0 *$1AE6,r1
        stra,r0 SPRITE3Y
        loda,r0 VOLUME
        andi,r0 0E0h
        eori,r0 00Fh
        stra,r0 VOLUME
        lodi,r0 0B3h
        stra,r0 18DDh
        lodi,r0 00Eh
        stra,r0 18DCh
        lodi,r0 004h
        stra,r0 18D8h
L0923:
        lodi,r0 08Fh
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
        lodi,r1 008h
        stra,r1 OFFSET
L0932:
	bsta,un	L0C9B
        bsta,un PLAYNOTE
        loda,r1 OFFSET
        subi,r1 01h
        stra,r1 OFFSET
	bcfr,eq	L0932
        lodi,r0 097h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
        lodi,r1 008h
        stra,r1 OFFSET
L0951:
	bsta,un	L0C9B
        bsta,un PLAYNOTE
        loda,r1 OFFSET
        subi,r1 01h
        stra,r1 OFFSET
	bcfr,eq	L0951
        loda,r0 18D8h
        subi,r0 01h
        stra,r0 18D8h
	bcfa,eq	L0923
        lodi,r0 067h
        stra,r0 18E9h
        lodi,r0 00Eh
        stra,r0 18E8h
	retc,un
;Code Section-------------------------------------------------------------
;acrobat-balloon bounce routine
BALLOONBOUNCE:
        stra,r3 18EBh       ;*(18EB) = r3; // user RAM
        lodi,r0 018h        ;r0 = $18;
        stra,r0 18E0h       ;*(18E0) = r0 [$18]; // user RAM
        eorz    r0          ;r0 = 0;
        loda,r1 OFFSET      ;r1 = OFFSET;
        stra,r0 *18E0h,r1   ;*(*(18E0) + r1) = 0; // both user RAM
        loda,r0 18E1h       ;r0 = *(18E1);
        stra,r0 18ECh       ;*(18EC) = r0; // user RAM
        bsta,un L0C9B       ;gosub L0C9B;
        bsta,un L099B       ;gosub L099B;
        bsta,un L0AB0       ;gosub L0AB0;
        bsta,un L0D3E       ;gosub L0D3E;

        bcta,un L04FA       ;goto L04FA;
;Subroutine---------------------------------------------------------------
L099B:
        loda,r0 18ECh
        comi,r0 020h
	bctr,eq	L09AB
        comi,r0 040h
	bctr,eq	L09AE
        comi,r0 060h
	bctr,eq	L09B1
	retc,un
;
L09AB:
	bsta,un	L0A75
L09AE:
	bsta,un	L0A75
L09B1:
	bsta,un	L0A75
	eorz	r0
        stra,r0 18EDh
        lodi,r3 003h
        stra,r3 18EFh
L09BD:
	eorz	r0
        stra,r0 18EEh
        loda,r3 18EFh
        loda,r0 0F23h,r3
        stra,r0 18E1h
        lodi,r2 000h
L09CC:
        loda,r0 *18E0h,r2
	bctr,eq	L09D9
        loda,r0 18EEh
        addi,r0 01h
        stra,r0 18EEh
L09D9:
        addi,r2 01h
        comi,r2 010h
	bcfr,eq	L09CC
        loda,r0 18EEh
	bctr,eq	L09F1
L09E4:
        loda,r0 18EFh
        subi,r0 01h
        stra,r0 18EFh
        comi,r0 000h
	bcfr,eq	L09BD
	retc,un
;
L09F1:
        loda,r0 FLAGS  
        andi,r0 020h
	bcfr,eq	L0A03

        loda,r3 18EFh
        loda,r0 0F26h,r3
	bsta,un	L0AD5
	bctr,un	L09E4
;
L0A03:
        loda,r0 18EDh
        addi,r0 01h
        stra,r0 18EDh
        comi,r0 003h
	bcfr,eq	L09E4
	bsta,un	L08C3
        lodi,r1 00Ch
L0A14:
	bsta,un	L0A75
	bdrr,r1	L0A14
	bctr,un	L09E4
;Subroutine---------------------------------------------------------------
PLAYNOTE:
        loda,r0 VOLUME       ;r0 = VOLUME;
        andi,r0 008h         ;r0 &= %00001000;
        bctr,eq PLAYNOTE_2   ;if (==) goto PLAYNOTE_2;
        loda,r1 SOUNDVAR     ;r1 = SOUNDVAR;
        loda,r0 *18DCh,r1    ;r0 = *(*(18DC) + r1);
        bctr,eq PLAYNOTE_1   ;if (==) goto PLAYNOTE_1;  
        andi,r0 07Fh         ;r0 &= %01111111;
        stra,r0 PITCH        ;PITCH = r0;
        addi,r1 01h          ;r1++;
        stra,r1 SOUNDVAR     ;SOUNDVAR = r1;
        retc,un              ;return;
PLAYNOTE_1:
        loda,r0 VOLUME       ;r0 = VOLUME;
        andi,r0 0E7h         ;r0 &= %01110111;
        stra,r0 VOLUME       ;VOLUME = r0;
        eorz    r0           ;r0 = 0;
        stra,r0 SOUNDVAR     ;SOUNDVAR = r0 [0];
PLAYNOTE_2:
        retc,un              ;return;
;Subroutine---------------------------------------------------------------
L0A42:
	rrl,r1
	rrl,r1
	rrl,r1
        andi,r1 007h
        loda,r0 SPRITE3X
	subz	r1
        subi,r0 2Bh
        tpsl    01h
	bctr,eq	L0A52
	eorz	r0
L0A52:
	rrr,r0
	rrr,r0
	rrr,r0
	strz	r2
        andi,r0 01Fh
	strz	r3
        comi,r3 00Fh
	retc,eq
        andi,r2 0E0h
        comi,r2 060h
	bcfr,gt	L0A6C
        addi,r3 01h
        loda,r0 *18E0h,r3
	bcfr,eq	L0A6B
        subi,r3 01h
L0A6B:
	retc,un
;
L0A6C:
        loda,r0 *18E0h,r3
	bcfr,eq	L0A6B
        addi,r3 01h
	bctr,un	L0A6B
;
L0A75:
        loda,r0 FLAGS  
        andi,r0 002h
	bctr,eq	L0A83

        lodi,r0 00Fh
        stra,r0 18E3h
	bctr,un	L0A88
;
L0A83:
        lodi,r0 009h
        stra,r0 18E3h
L0A88:
        lodi,r2 005h
        lodi,r3 005h
L0A8C:
        loda,r0 *18E2h
        addi,r0 06h
	addz	r2
        andi,r0 0CFh
        eori,r0 010h
        tpsl    20h
	bctr,eq	L0AA0
        subi,r0 06h
        stra,r0 *18E2h
	retc,un
;
L0AA0:
        stra,r0 *18E2h
        loda,r0 18E3h
        subi,r0 01h
        stra,r0 18E3h
        lodi,r2 001h
	bdrr,r3	L0A8C
	retc,un
;
L0AB0:
        loda,r0 FLAGS  
        andi,r0 004h
	bcfr,eq	L0AC0

        loda,r0 18DBh
	bsta,un	L0D38
        stra,r0 18DBh
L0AC0:
        loda,r0 VOLUME
        andi,r0 0E0h
        eori,r0 00Fh
        stra,r0 VOLUME
        lodi,r0 0AAh
        stra,r0 18DDh
        lodi,r0 00Eh
        stra,r0 18DCh
	retc,un
;
L0AD5:
        lodi,r1 000h
L0AD7:
        stra,r0 *18E0h,r1
        addi,r1 01h
        comi,r1 010h
	bcfr,eq	L0AD7
        lodi,r1 004h
L0AE2:
	bsta,un	L0A75
	bdrr,r1	L0AE2
        loda,r0 VOLUME
        andi,r0 0E0h
        eori,r0 00Fh
        stra,r0 VOLUME
        lodi,r0 0C2h
        stra,r0 18DDh
        lodi,r0 00Eh
        stra,r0 18DCh
	retc,un
;Subroutine---------------------------------------------------------------
L0AFC:

;ROW1OFFSET -= 32; // move 1st row left
        loda,r0 ROW1OFFSET ;r0 = ROW1OFFSET;
        subi,r0 $20          ;r0 -= 32;
        stra,r0 ROW1OFFSET ;ROW1OFFSET = r0;

;ROW2OFFSET += 32; // move 2nd row right
        loda,r0 ROW2OFFSET ;r0 = ROW2OFFSET;
        addi,r0 $20          ;r0 += 32;
        stra,r0 ROW2OFFSET ;ROW2OFFSET = r0;

;ROW3OFFSET -= 32; // move 3rd row left
        loda,r0 ROW3OFFSET ;r0 = ROW3OFFSET;
        subi,r0 $20          ;r0 -= 32;
        stra,r0 ROW3OFFSET ;ROW3OFFSET = r0;

;ROW4OFFSET += 32; // move 4th row right
        loda,r0 ROW4OFFSET   ;r0 = ROW4OFFSET;
        addi,r0 $20          ;r0 += 32;
        stra,r0 ROW4OFFSET   ;ROW4OFFSET = r0;

        loda,r0 ROW1OFFSET   ;r0 = ROW1OFFSET;
;explicitly compare against $E0
        comi,r0 0E0h         ;compare r0 against $E0
        bcta,eq ROW1         ;if (==) goto ROW1;

        loda,r0 ROW2OFFSET   ;r0 = ROW2OFFSET;
;implicitly compare against 0
        bcta,eq ROW2         ;if (==) goto ROW2;

        loda,r0 ROW3OFFSET   ;r0 = ROW3OFFSET;
;explicitly compare against $E0
        comi,r0 0E0h         ;compare r0 against $E0
        bcta,eq ROW3         ;if (==) goto ROW3;

        loda,r0 ROW4OFFSET   ;r0 = ROW4OFFSET;
;implicitly compare against 0
        bcta,eq ROW4         ;if (==) goto ROW4;
        retc,un              ;return;
;Subroutine---------------------------------------------------------------
;This is a slave subroutine of ROW2 and ROW4.

SCROLLRIGHT:
        lodi,r1 00Fh         ;r1 = 15; // loop iterator
        loda,r0 *18E0h,r1    ;r0 = *(*(18E0) + r1);
        stra,r0 18D7h        ;*(18D7) = r0;
SCROLLRIGHT_1:
        loda,r0 *18E2h,r1    ;r0 = *(*(18E2) + r1);
        stra,r0 *18E0h,r1    ;*(*(18E0) + r1) = r0;
        bdrr,r1 SCROLLRIGHT_1;if (--r1 != 0) goto SCROLLRIGHT_1
;end of loop

        loda,r0 18D7h        ;r0 = *(18D7);
        stra,r0 *18E0h       ;*(*(18E0)) = r0;
        retc,un              ;return;
;Subroutine---------------------------------------------------------------
SCROLLLEFT:
;This is a slave subroutine of ROW1 and ROW3.

;*($18D7) = *(*($18E0..$18E1));
        loda,r0 *$18E0       ;r0 = *(*($18E0..$18E1)); // user RAM
        stra,r0 $18D7        ;*(18D7) = r0;

        lodi,r1 $01          ;loop iterator (goes from 1..15)
SCROLLLEFT_1:
        loda,r0 *$18E0,r1    ;r0 = *(*($18E0..$18E1) + r1); // user RAM
        stra,r0 *$18E2,r1    ;*(*($18E2..$18E3) + r1) = r0;
        addi,r1 $01          ;r1++;
        comi,r1 $10          ;compare r1 against 16
        bcfr,eq SCROLLLEFT_1 ;if (!=) goto SCROLLLEFT_1
;end of loop

        lodi,r1 $0F          ;r1 = 15;
        loda,r0 $18D7        ;*($18D7) = r0;
        stra,r0 *$18E0,r1    ;*(*($18E0..$18E1) + 1) = r0;
        retc,un              ;return;
;Subroutine---------------------------------------------------------------
;This is a slave subroutine of ROW1, ROW2, ROW3 and ROW4.
L0B6D:
        stra,r0 $18E1        ;*($18E1) = r0;
        subi,r0 $01          ;r0--;
        stra,r0 $18E3        ;*($18E3) = r0;
        retc,un              ;return;
;Subroutine---------------------------------------------------------------
ROW1:
        lodi,r0 $20
        bsta,un L0B6D
        bsta,un SCROLLLEFT
	retc,un
;Subroutine---------------------------------------------------------------
ROW2:
        lodi,r0 $40
	bsta,un	L0B6D
        bsta,un SCROLLRIGHT
	retc,un
;Subroutine---------------------------------------------------------------
ROW3:
        lodi,r0 $60
	bsta,un	L0B6D
        bsta,un SCROLLLEFT
	retc,un
;Subroutine---------------------------------------------------------------
ROW4:
        lodi,r0 $90
	bsta,un	L0B6D
        bsta,un SCROLLRIGHT
	retc,un
;Subroutine---------------------------------------------------------------
L0B9A:                                                                    	strz	r3
        loda,r0 SPRITE3Y
        lodi,r2 $0A
        coma,r0 *$1AE6,r2
	bctr,gt	L0BBD
        lodi,r2 $0B
        coma,r0 *$1AE6,r2
	bctr,lt	L0BBD
	bsta,un	L0BE4
        loda,r1 1AEBh
        andi,r1 01Fh
        comi,r1 00Fh
	bctr,eq	L0BBA
        andi,r1 003h
L0BBA:
	lodz	r3
	addz	r1
	retc,un
;
L0BBD:
	lodz	r3
	retc,un
;
L0BBF:
	strz	r3
        loda,r0 SPRITE3Y
        lodi,r2 $0A
        coma,r0 *1AE6h,r2
	bctr,gt	L0BE2
        lodi,r2 $0B
        coma,r0 *1AE6h,r2
	bctr,lt	L0BE2
	bsta,un	L0BE4
        loda,r1 1AEBh
        andi,r1 01Fh
        comi,r1 00Fh
	bctr,eq	L0BDF
        andi,r1 003h
L0BDF:
	lodz	r3
	subz	r1
	retc,un
;
L0BE2:
	lodz	r3
	retc,un
;
L0BE4:
        loda,r0 1AEBh
        comi,r0 000h
	bcfr,eq	L0BED
        lodi,r0 0AAh
L0BED:
	strz	r1
	rrl,r1
	eorz	r1
	rrl,r0
        andi,r0 001h
        andi,r1 0FEh
	eorz	r1
        stra,r0 1AEBh
	retc,un
;Subroutine---------------------------------------------------------------
HANDLEINPUT:
;r0 has P1PADDLE
;r1 has P2PADDLE
        loda,r3 FLAGS                ;r3 = FLAGS;
        andi,r3 080h                 ;r3 &= %10000000;
        bctr,eq L0C27                ;if (==) goto L0C27;

        strz    r3                   ;r3 = r0;
        lodi,r2 $0B                  ;r2 = 11;
        loda,r0 SPRITE3Y             ;r0 = SPRITE3Y;
        coma,r0 *$1AE6,r2            ;compare r0 against *(*(1AE6) + r2 [11])
        retc,lt                      ;if (<) return;
        lodz    r3                   ;r0 = r3;

        loda,r3 FLAGS                ;r3 = FLAGS;
        andi,r3 001h                 ;r3 &= %00000001;
        bcfr,eq L0C1D                ;if (!=) goto L0C1D;

        loda,r0 SPRITE3X             ;r0 = SPRITE3X;
        subi,r0 08h                  ;r0 -= 8;
        bsta,un L0B9A                ;gosub L0B9A;
        bctr,un L0C34                ;goto L0C34;
L0C1D:
        loda,r0 SPRITE3X
        addi,r0 08h
	bsta,un	L0BBF
	bctr,un	L0C34
L0C27:
        loda,r2 FLAGS                ;r2 = FLAGS;
;extract bit 1
        andi,r2 002h                 ;r2 &= %00000010;
        bctr,eq L0C2F                ;if (==) goto L0C2F;

        lodz    r1                   ;r0 = r1;
L0C2F:
        rrr,r0                       ;rotate r0 to the right once
        andi,r0 07Fh                 ;r0 &= %01111111;
        addi,r0 2Ch                  ;r0 += $2C;
L0C34:
        comi,r0 03Bh                 ;compare r0 against $3B
        bctr,lt L0C4A                ;if (<) goto L0C4A;
        comi,r0 093h                 ;compare r0 against $93
        bctr,gt L0C51                ;if (>) goto L0C51;
L0C3C:

        stra,r0 SPRITE1X                                                ;3

        addi,r0 08h
        stra,r0 SPRITE2X
        subi,r0 10h
        stra,r0 SPRITE0X
	retc,un
L0C4A:

        lodi,r0 03Bh                                                    ;2
        bsta,un L0C58                                                   ;3

	bctr,un	L0C3C
L0C51:

        lodi,r0 093h                                                    ;2
        bsta,un L0C58                                                   ;3

	bctr,un	L0C3C
L0C58:
        loda,r3 FLAGS        ;r3 = FLAGS;
        andi,r3 080h         ;r3 &= %10000000;
        retc,eq              ;if (==) return;

        strz    r3           ;r3 = r0;
        loda,r0 SPRITE3Y     ;r0 = SPRITE3Y;
        lodi,r2 $0C          ;r2 = 12;
        coma,r0 *$1AE6,r2    ;compare r0 against *(*($1AE6) + r2 [12])
        bctr,gt L0C70        ;if (>) goto L0C70;
        lodi,r2 $0A          ;r2 = 10;
        coma,r0 *$1AE6,r2    ;compare r0 against *(*($1AE6) + r2 [10])
        bctr,gt L0C72        ;if (>) goto L0C72;
L0C70:
        lodz    r3           ;r0 = r3;
        retc,un              ;return;
L0C72:
        loda,r0 SPRITE3X
        comi,r0 030h
	retc,lt
        comi,r0 0A5h
	retc,gt
	bsta,un	L0BE4
	lodz	r3
        loda,r3 1AEBh
        andi,r3 003h
        comi,r3 002h
	retc,gt

        loda,r3 FLAGS        ;r3 = FLAGS;
        andi,r3 0BFh         ;r3 &= %10111111;
;set bit 6
        eori,r3 040h         ;Exclusive OR r3 with %01000000 // inefficient!
        stra,r3 FLAGS        ;FLAGS = r3;

        retc,un              ;return;
;Subroutine---------------------------------------------------------------
SETHSCROLL:
;highest 3 bits of r0 are the desired horizontal scroll
;caller is responsible for actually setting VOLUME according to returned r0
        andi,r0 $E0          ;r0 &= %11100000; // get HSCROLL bits
        loda,r1 VOLUME       ;r1 = VOLUME;
        andi,r1 $1F          ;r1 &= %00011111; // clear HSCROLL bits
        eorz    r1           ;r0 ^= r1; // effectively the same as r0 |= r1 in this case
	retc,un
;Subroutine---------------------------------------------------------------
L0C9B:
        tpsu    80h
        bcfr,eq L0C9B
        loda,r0 P1PADDLE
        loda,r1 P2PADDLE
        bsta,un HANDLEINPUT
        lodi,r1 008h
L0CAA:
        loda,r0 *18E8h,r1
        stra,r0 1997h,r1
	bdrr,r1	L0CAA
L0CB2:
        tpsu    80h
	bctr,eq	L0CB2
	bsta,un	L0AFC
        bsta,un WAITLINES
	retc,un
;Subroutine---------------------------------------------------------------
WAITLINES:
        loda,r0 CHARLINE        ;current character line
        andi,r0 00Fh

        comi,r0 00Fh

        bcfr,eq WAITLINES
;we just waited for DMA to become $FF

;HSCROLL = 0;
	eorz	r0
        bsta,un SETHSCROLL
        stra,r0 VOLUME

WAITLINE1:
;wait for line 1 or 14
        loda,r0 CHARLINE
        andi,r0 00Fh
        comi,r0 001h
        bcfr,eq WAITLINE1
;we just waited for DMA to become $F1

;HSCROLL = ROW1OFFSET; // 1st row of balloons
        loda,r0 ROW1OFFSET
        bsta,un SETHSCROLL
        stra,r0 VOLUME

L0CDF:
;wait for line 3 or 16
        loda,r0 CHARLINE
        andi,r0 00Fh
        comi,r0 003h
	bcfr,eq	L0CDF
;we just waited for DMA to become $F3

;HSCROLL = ROW2OFFSET; // 2nd row of balloons
        loda,r0 ROW2OFFSET
        bsta,un SETHSCROLL
        stra,r0 VOLUME

L0CF1:
;wait for line 5 or 18
        loda,r0 CHARLINE
        andi,r0 00Fh
        comi,r0 005h
	bcfr,eq	L0CF1
;we just waited for DMA to become $F5

;HSCROLL = ROW3OFFSET; // 3rd row of balloons
        loda,r0 ROW3OFFSET
        bsta,un SETHSCROLL
        stra,r0 VOLUME

L0D03:
;wait for line 8 or 21
        loda,r0 CHARLINE
        andi,r0 00Fh
        comi,r0 008h
	bcfr,eq	L0D03
;we just waited for DMA to become $F8

;HSCROLL = ROW4OFFSET; // movable deflectors
        loda,r0 ROW4OFFSET
        bsta,un SETHSCROLL
        stra,r0 VOLUME

L0D15:
;wait for line 9 or 22
        loda,r0 CHARLINE
        andi,r0 00Fh
        comi,r0 009h
	bcfr,eq	L0D15
;we just waited for DMA to become $F9

;HSCROLL = 0;
	eorz	r0
        bsta,un SETHSCROLL
        stra,r0 VOLUME

	retc,un
;Subroutine---------------------------------------------------------------
CHECKSPRITEHIT:

;wait for vertical blank
        loda,r0 CHARLINE
        andi,r0 00Fh
        comi,r0 00Dh
        bcfr,eq CHECKSPRITEHIT ;if (!=) goto CHECKSPRITEHIT;
;end of loop
;we have just waited for DMA to become $FD

        loda,r0 SPRITECOLLIDE;r0 = SPRITECOLLIDE;
        stra,r0 SPRITECOLCOPY;SPRITECOLCOPY = r0;
        comi,r0 0FFh         ;compare r0 against $FF;
        retc,un              ;return;
;Subroutine---------------------------------------------------------------
;this is used to affect *(18DA) and *(18DB)
;it flips r0 then adds one to it
;r0 = 255 - r0 + 1;
L0D38:
        lodi,r1 0FFh          ;r1 = $FF;
        eorz    r1            ;Exclusive OR r0 with r1 (ie. flip all bits of r0)
        addi,r0 01h           ;r0++;
        retc,un
;-------------------------------------------------------------------------
L0D3E:
        loda,r0 SPRITE3Y
        loda,r1 18DBh
	addz	r1
        stra,r0 SPRITE3Y
        loda,r0 SPRITE3X
        loda,r1 18DAh
	addz	r1
        stra,r0 SPRITE3X
	retc,un
;
L0D53:
        lodi,r1 010h
L0D55:
        stra,r0 *18E0h,r1
	bdrr,r1	L0D55
	retc,un
;
L0D5B:
        lodi,r1 004h
L0D5D:
        loda,r0 *1AE2h,r1
        andi,r0 00Fh
	bcfr,eq	L0D72
	bdrr,r1	L0D5D

        loda,r0 FLAGS  
        andi,r0 0F7h
        lodi,r1 008h
	eorz	r1
        stra,r0 FLAGS  

	retc,un
;
L0D72:
        loda,r0 FLAGS  
        andi,r0 008h
	bcfr,eq	L0D7A

	retc,un
;
L0D7A:
        loda,r0 FLAGS  
        andi,r0 0BFh
        eori,r0 040h
        stra,r0 FLAGS  

	retc,un
;Subroutine---------------------------------------------------------------
L0D85:
        loda,r0 FLAGS        ;r0 = FLAGS;

        andi,r0 040h         ;r0 &= %01000000;
        bcfr,eq L0D8D        ;if (!=) goto L0D8D;
        retc,un              ;return;

;wait for start of vertical blank
L0D8D:
        tpsu    80h          ;test mask %10000000 of PSU (Sense bit)
        bcfr,eq L0D8D        ;if (!=) goto L0D8D;
;end of loop

        loda,r0 FLAGS        ;r0 = FLAGS;
        andi,r0 001h         ;r0 &= %00000001;
        bctr,eq L0DAC        ;if (==) goto L0DAC;

        lodi,r1 018h         ;r1 = 24; // loop iterator
;copy left mover into sprite #0, seesaws into sprites #1 and #2
L0D9A:
        loda,r0 0E1Fh,r1     ;r0 = *(E1F + r1);
        stra,r0 197Fh,r1     ;*(197F + r1) = r0; // sprites #0..#2
        bdrr,r1 L0D9A        ;if (--r1 != 0) goto L0D9A;
;end of loop

        loda,r0 FLAGS        ;r0 = FLAGS;
;clear bit 0
        andi,r0 0FEh         ;r0 &= %11111110;
        stra,r0 FLAGS        ;r0 = FLAGS;
        bctr,un L0DBF        ;goto L0DBF;

L0DAC:
        lodi,r1 018h         ;r1 = 24; // loop iterator
;copy seesaws into sprites #0 and #1, right mover into sprite #2
L0DAE:
        loda,r0 0E07h,r1     ;r0 = *(E07 + r1);
        stra,r0 197Fh,r1     ;*(197F + r1) = r0; // sprites #0..#2
        bdrr,r1 L0DAE        ;if (--r1 != 0) goto L0DAE;
;end of loop

        loda,r0 FLAGS        ;r0 = FLAGS;
        lodi,r1 001h         ;r1 = 1;
;flip bit 0
        eorz    r1           ;Exclusive OR r0 with r1 [1]
        stra,r0 FLAGS        ;FLAGS = r0;

;wait for start of vertical blank
L0DBF:
        tpsu    80h          ;test mask %10000000 of PSU (Sense bit)
        bctr,eq L0DBF        ;if (==) goto L0DBF;
;end of loop

        bsta,un L0AFC        ;gosub L0AFC;
        bsta,un WAITLINES    ;gosub WAITLINES;
        bsta,un L0D3E        ;gosub L0D3E;

        loda,r0 FLAGS        ;r0 = FLAGS;
;clear bits 3 and 6
        andi,r0 0B7h         ;r0 &= %10110111;
        stra,r0 FLAGS        ;FLAGS = r0;

        retc,un              ;return;
;Subroutine---------------------------------------------------------------
SPLAT:
        loda,r0 FLAGS         ;get current player
        andi,r0 002h         ;if it is not player 2
        bctr,eq L0DE6        ;then kill player 1 instead

        loda,r0 1802h        ;get p2 lives
        subi,r0 01h          ;decrement by one
        stra,r0 1802h        ;show p2 lives
        bctr,un L0DEE        ;skip forwards
L0DE6:
        loda,r0 1800h        ;get p1 lives
        subi,r0 01h          ;decrement by one
        stra,r0 1800h        ;show p1 lives
L0DEE:
        andi,r0 00Fh         ;ignore colours, return character in r0
        retc,un              ;return;
;-------------------------------------------------------------------------
CHECKBGHIT:
;wait for vertical blank
        loda,r0 CHARLINE

        andi,r0 00Fh
        comi,r0 00Dh
        bcfr,eq CHECKBGHIT   ;background collision check
;end of loop
;we have just waited for DMA to become $FD

        loda,r0 BGCOLLIDE

        comi,r0 0FFh

X0DFF:
	retc,un
;-------------------------------------------------------------------------
        db      018h ;...##...
        db      03Ch ;..####..
        db      07Eh ;.######.
        db      07Eh ;.######.
        db      07Eh ;.######.
        db      07Eh ;.######.
        db      03Ch ;..####..
X0E07:
        db      018h ;...##...

        db      000h ;........
        db      000h ;........
        db      000h ;........
        db      0FCh ;######..
        db      007h ;.....###
        db      000h ;........
        db      000h ;........
        db      000h ;........

        db      000h ;........
        db      000h ;........
        db      000h ;........
        db      000h ;........
        db      0C0h ;##......
        db      07Eh ;.######.
        db      003h ;......##
        db      000h ;........

        db      008h ;....#... mover on right
        db      01Ch ;...###..
        db      02Ah ;..#.#.#.
        db      02Ah ;..#.#.#.
        db      014h ;...#.#..
        db      014h ;...#.#..
        db      0F4h ;####.#..
X0E1F:
        db      03Fh ;..######

        db      010h ;...#.... mover on left
        db      038h ;..###...
        db      054h ;.#.#.#..
        db      054h ;.#.#.#..
        db      028h ;..#.#...
        db      028h ;..#.#...
        db      02Fh ;..#.####
        db      0FCh ;######..

        db      000h ;........
        db      000h ;........
        db      000h ;........
        db      000h ;........
        db      003h ;......##
        db      07Eh ;.######.
        db      0C0h ;##......
        db      000h ;........

        db      000h ;........
        db      000h ;........
        db      000h ;........
        db      03Fh ;..######
        db      0E0h ;###.....
        db      000h ;........
        db      000h ;........
X0E37:
        db      000h ;........

        db      0D5h ;"5"

        db      000h

        db      095h ;"5"

        db      000h, 000h

        db      0D0h, 0D0h, 0D0h, 0D0h, 0D0h ;"00000"

        db      000h

        db      090h, 090h, 090h, 090h, 090h ;"00000"

        db      000h, 000h

        db      0ECh, 0DEh, 0E5h, 0DEh, 0DCh, 0EDh ;"SELECT"

        db      000h                               ;" "

        db      0E0h, 0DAh, 0E6h, 0DEh, 0ECh       ;"GAMES"

        db      000h
X0E57:
        db      000h, 000h, 000h

        db      0E9h, 0E5h, 0DAh, 0F2h, 0DEh, 0EBh ;"PLAYER"

        db      000h                               ;" "

        db      0E0h, 0DAh, 0E6h, 0DEh             ;"GAME"

        db      000h, 000h
        db      000h, 000h, 010h, 038h
        db      054h, 054h, 028h, 028h
        db      028h, 048h, 03Ch, 00Bh
        db      008h, 014h, 022h, 022h
        db      000h, 009h, 01Eh, 068h
        db      008h, 014h, 022h, 012h
        db      000h, 048h, 03Ch, 00Bh
        db      008h, 014h, 022h, 024h
        db      000h, 049h, 03Eh, 008h
        db      008h, 014h, 022h, 022h
        db      000h, 000h, 000h, 000h
        db      010h, 008h, 044h, 032h
        db      03Ch, 000h, 000h, 000h
        db      002h, 012h, 052h, 032h
        db      03Ch
X0EA0:
        db      0FFh, 0FEh, 0FDh, 0FCh, 0FBh
X0EA5:
        db      001h, 002h, 003h, 004h, 005h

        db      030h, 010h, 005h
        db      000h, 015h, 012h, 008h
        db      005h, 000h, 011h, 020h
        db      030h, 031h, 020h, 020h
        db      030h, 030h, 040h, 020h
        db      010h, 008h, 007h, 006h
        db      000h, 015h, 010h, 007h
        db      004h, 000h, 020h, 016h
        db      003h, 002h
X0ECB:
        db      000h, 068h, 060h, 048h
        db      040h, 028h
X0ED1:
        db      020h, 0E6h, 0E6h, 0E5h
        db      0E5h, 0E4h
X0ED7:
        db      0E4h, 0BCh, 0BCh, 0FCh
        db      0FCh, 07Ch
X0EDD:
        db      07Ch, 002h, 00Bh, 00Ch
        db      00Dh, 00Eh
X0EE3:
        db      00Fh, 000h, 005h, 006h
        db      007h, 008h
X0EE9:
        db      009h, 004h, 024h, 000h
        db      020h, 004h, 024h, 000h
X0EF1:
        db      020h
        db      000h, 000h, 0000, 000h

        db      0C4h, 0C4h, 0C4h, 0C4h

;"black mode"
;$EFA: // for slow-VBL machines (ie. $46 or more iterations during VBL)
        db      $27                    ;*(*($1AE6 +  0)) SPRITE0Y, SPRITE1Y, SPRITE2Y
        db      $1A                    ;*(*($1AE6 +  1)) $1AE8
        db      $C0                    ;*(*($1AE6 +  2)) $1AE9
        db      $00, $00
        db      $2F                    ;*(*($1AE6 +  5)) SPRITE3Y
        db      $2D                    ;*(*($1AE6 +  6)) compares SPRITE3Y against this
        db      $07                    ;*(*($1AE6 +  7)) $18DB
        db      $26                    ;*(*($1AE6 +  8)) SPRITE3Y
        db      $C8 ;%1,1,001,000      ;*(*($1AE6 +  9)) BGCOLOUR (black)
        db      $2E                    ;*(*($1AE6 + 10)) compares SPRITE3Y against this
        db      $27                    ;*(*($1AE6 + 11)) compares SPRITE3Y against this
        db      $35                    ;*(*($1AE6 + 12)) compares SPRITE3Y against this

;"green mode"
;$F07: // for fast-VBL machines (ie. $45 or less iterations during VBL)
        db      $2F                    ;*(*($1AE6 +  0)) SPRITE0Y, SPRITE1Y, SPRITE2Y
        db      $1A                    ;*(*($1AE6 +  1)) $1AE8
        db      $B0                    ;*(*($1AE6 +  2)) $1AE9
        db      $00, $00
        db      $37                    ;*(*($1AE6 +  5)) SPRITE3Y
        db      $35                    ;*(*($1AE6 +  6)) compares SPRITE3Y against this
        db      $05                    ;*(*($1AE6 +  7)) $18DB
        db      $2E                    ;*(*($1AE6 +  8)) SPRITE3Y
        db      $CC ;%1,1,001,100      ;*(*($1AE6 +  9)) BGCOLOUR (green)
        db      $36                    ;*(*($1AE6 + 10)) compares SPRITE3Y against this
        db      $2F                    ;*(*($1AE6 + 11)) compares SPRITE3Y against this
X0F13:
        db      $3D                    ;*(*($1AE6 + 12)) compares SPRITE3Y against this

        db      000h, 000h, 000h

        db      0E0h, 0DAh, 0E6h, 0DEh ;"GAME"

        db      000h, 000h             ;"  "

        db      0E8h, 0EFh, 0DEh, 0EBh ;"OVER"

        db      000h, 000h
X0F23:
        db      000h, 020h, 040h
X0F26:
        db      060h, 07Ch, 0FCh, 0BCh
        db      000h, 000h, 000h, 000h
        db      000h, 000h, 041h, 030h
        db      00Dh, 053h, 031h, 031h
        db      042h, 030h, 039h, 044h
        db      038h, 036h, 033h, 037h
        db      033h, 036h, 033h, 046h
        db      034h, 046h, 032h, 046h
        db      032h, 046h, 030h, 046h
        db      030h, 046h, 030h, 037h
        db      037h, 037h, 037h, 039h
        db      037h, 037h, 037h, 039h
        db      037h, 042h, 037h, 044h
        db      046h, 045h, 046h, 046h
        db      037h, 046h, 042h, 046h
        db      044h, 046h, 045h, 046h
        db      037h, 046h, 035h, 046h
        db      033h, 033h, 045h, 00Dh
        db      053h, 031h, 031h, 042h
        db      030h, 039h, 046h, 030h
        db      046h, 031h, 046h, 036h
        db      046h, 034h, 046h, 032h
        db      046h, 030h, 046h, 037h
        db      046h, 042h, 046h, 044h
        db      046h, 045h, 033h, 043h
        db      032h, 038h, 035h, 030h
        db      030h, 030h, 030h, 034h
        db      030h, 035h, 030h, 037h
        db      033h, 030h, 034h, 030h
        db      035h, 030h, 036h, 030h
        db      030h, 030h, 030h, 030h
        db      035h, 035h, 041h, 041h
        db      035h, 045h, 00Dh, 053h
        db      031h, 031h, 042h, 030h
        db      041h, 030h, 038h, 030h
        db      031h, 030h, 032h, 030h
        db      034h, 030h, 038h, 031h
        db      030h, 032h, 030h, 034h
        db      030h, 038h, 030h, 030h
        db      030h, 030h, 031h, 030h
        db      032h, 030h, 034h, 030h
        db      038h, 033h, 032h, 033h
        db      034h, 033h, 036h, 035h
        db      031h, 036h, 031h, 037h
        db      031h, 038h, 031h, 039h
        db      031h, 036h, 032h, 037h
        db      032h, 038h, 032h, 039h
        db      044h, 00Dh, 053h, 031h
        db      031h, 042h, 030h, 041h
        db      032h, 030h, 039h, 032h
        db      035h, 033h, 036h, 033h
        db      037h, 033h, 038h, 033h
        db      039h, 033h
        db      035h, 036h, 036h, 036h
        db      037h, 036h, 038h, 036h

        end

Movement limits are $3B + moveamount, and $93 - moveamount

Clearly CHARLINE really does become $FF at some point, because the game
waits explicitly for it to do so.

1st row: purple (moves left)
2nd row: white (moves right)
3rd row: cyan (moves left)
4th row: moving deflectors (moves right)

0 = 0      5    00000
1 = 1ST
2 = 1ST    ****************
3 = 2ND
4 = 2ND    ****************
5 = 3RD
6 = 3RD    ****************
7 = 3RD
8 = 4TH    --  --  --  --
9..25 = 0
