;Atari 2600 Initialization Code - C02 Assembly Language File

PLR0X  EQU $80
PLR1X  EQU $81
MSL0X  EQU $82
MSL1X  EQU $83
BALLX  EQU $84

OBJTY  EQU $85
PLR0Y  EQU $85
PLR1Y  EQU $86
MSL1HT EQU $87
MSL1Y  EQU $88
BALLY  EQU $89

PLR0LO EQU $8A
PLR0HI EQU $8B
PLR1LO EQU $8C
PLR1HI EQU $8D

PLR0HT EQU $8E
PLR1HT EQU $8F
MSL0HT EQU $90
MSL0Y  EQU $91
BALLHT EQU $92


SCORE EQU $93 ; $93-$95
SCOREPOINTERS EQU $96 ; $96-$9B EQU 6 BYTES
TEMP1 EQU $9C ;USED BY KERNEL
TEMP2 EQU $9D ;CAN BE USED IN PROGRAM TOO, BUT
TEMP3 EQU $9E ;ARE OBLITERATED WHEN DRAWSCREEN IS CALLED.
TEMP4 EQU $9F
TEMP5 EQU $A0
TEMP6 EQU $A1

RAND EQU $A2
SCORECOLOR EQU $A3

VAR0  EQU $A4
VAR1  EQU $A5
VAR2  EQU $A6
VAR3  EQU $A7
VAR4  EQU $A8
VAR5  EQU $A9
VAR6  EQU $AA
VAR7  EQU $AB
VAR8  EQU $AC
VAR9  EQU $AD
VAR10 EQU $AE
VAR11 EQU $AF
VAR12 EQU $B0
VAR13 EQU $B1
VAR14 EQU $B2
VAR15 EQU $B3
VAR16 EQU $B4
VAR17 EQU $B5
VAR18 EQU $B6
VAR19 EQU $B7
VAR20 EQU $B8
VAR21 EQU $B9
VAR22 EQU $BA
VAR23 EQU $BB
VAR24 EQU $BC
VAR25 EQU $BD
VAR26 EQU $BE
VAR27 EQU $BF
VAR28 EQU $C0
VAR29 EQU $C1
VAR30 EQU $C2
VAR31 EQU $C3
VAR32 EQU $C4
VAR33 EQU $C5
VAR34 EQU $C6
VAR35 EQU $C7
VAR36 EQU $C8
VAR37 EQU $C9
VAR38 EQU $CA
VAR39 EQU $CB
VAR40 EQU $CC
VAR41 EQU $CD
VAR42 EQU $CE
VAR43 EQU $CF
VAR44 EQU $D0
VAR45 EQU $D1
VAR46 EQU $D2
VAR47 EQU $D3

TEMP7 EQU $D4 ; THIS IS USED TO AID IN BANKSWITCHING

PLAYFIELDPOS EQU $D5

A EQU $D6
B EQU $D7
C EQU $D8
D EQU $D9
E EQU $DA
F EQU $DB
G EQU $DC
H EQU $DD
I EQU $DE
J EQU $DF
K EQU $E0
L EQU $E1
M EQU $E2
N EQU $E3
O EQU $E4
P EQU $E5
Q EQU $E6
R EQU $E7
S EQU $E8
T EQU $E9
U EQU $EA
V EQU $EB
W EQU $EC
X  EQU $ED
Y  EQU $EE
Z EQU $EF

; AVAILABLE FOR OTHER USES, OR IF UNUSED, PROVIDE MORE STACK SPACE

AUX1 EQU $F0
AUX2 EQU $F1
AUX3 EQU $F2
AUX4 EQU $F3
AUX5 EQU $F4
AUX6 EQU $F5

; PLAYFIELD COLOR/HT POINTERS
PFCOLORTABLE EQU $F0 ; AND $D5
PFHTTABLE EQU $F0 ; AND $D5
; THE ABOVE POINTERS ARE THE SAME BECAUSE IF COLOR AND HT ARE BOTH USED TOGETHER,
; THEY MUST USED ABSOLUTE INDEXED AND CANNOT USE POINTERS

LIFEPOINTER EQU $F2 ; POINTER TO "LIVES" SHAPE
; UPPER 3 BITS OF $F2 CONTAIN THE NUMBER OF LIVES
LIFECOLOR EQU $F4
LIVES EQU $F3 ; # LIVES >> 5
STATUSBARLENGTH EQU $F5 ; ONLY USES UPPER 5 BITS; OTHER BITS FREE

PFSCORE1 EQU $F2 ; OPTIONAL PLAYFIELD BYTES IN SCORE
PFSCORE2 EQU $F3
PFSCORECOLOR EQU $F4

STACK1 EQU $F6
STACK2 EQU $F7
STACK3 EQU $F8
STACK4 EQU $F9


START:  SEI         ;Disable Interrupts
        CLD         ;Disable Decimal Modes
        LDY #0      ;Set Y-Index to $00
        LDA $D0     ;If Location $D0
        CMP #$2C    ;  Does Not Contain $2C
        BNE IS2600  ;And
        LDA $D1     ;  Location $D1 
        CMP #$A9    ;  Does Not Contain $D1
        BNE IS2600  ;Then
        DEY         ;  Set Y-Index to $FF
IS2600: LDX #0      ;Initialize X-Index
        TXA         ;Initialize Accumulator
CLRMEM: INX         ;
        TXS         ;
        PHA
        BNE CLRMEM
        STY TEMP1
        IFCONST PFROWHT
        LDA PFROWHT
        ELSE
        IFCONST PFRES
        LDA #(96/PFRES)
        ELSE
        LDA #8
        ENDIF
        ENDIF
        STA PLAYFIELDPOS
        LDX #5
INITSCORE
        LDA #<SCORETABLE
        STA SCOREPOINTERS,X 
        DEX
        BPL INITSCORE
        LDA #1
        STA CTRLPF
        ORA INTIM
        STA RAND

        IFCONST MULTISPRITE
          JSR MULTISPRITE_SETUP
        ENDIF

        IFNCONST BANKSWITCH
          JMP GAME
        ELSE
          LDA #>(GAME-1)
          PHA
          LDA #<(GAME-1)
          PHA
          PHA
          PHA
          LDX #1
          JMP BS_JSR
        ENDIF
