2020-09-15 12:57:10 +00:00
|
|
|
#if VERBOSE = 1
|
|
|
|
LASTINIT SET .
|
|
|
|
#endif
|
|
|
|
|
2018-09-22 08:58:10 +00:00
|
|
|
; ENTRY OF PROGRAM
|
|
|
|
; ----------------------------------------------------------------------
|
|
|
|
start:
|
|
|
|
; Clear screen, initialize keyboard, restore interrupts
|
|
|
|
jsr $ff81
|
|
|
|
|
|
|
|
; Disable all interrupts
|
|
|
|
sei
|
|
|
|
|
2020-04-01 23:13:10 +00:00
|
|
|
; Turn off CIA interrupts and (possibly) flush the pending queue
|
2018-09-22 08:58:10 +00:00
|
|
|
ldy #$7f
|
|
|
|
sty $dc0d
|
|
|
|
sty $dd0d
|
|
|
|
lda $dc0d
|
|
|
|
lda $dd0d
|
|
|
|
|
|
|
|
; Set Interrupt Request Mask as we want IRQ by raster beam
|
|
|
|
lda #$1
|
|
|
|
sta $d01a
|
|
|
|
|
|
|
|
; Store in $314 address of our custom interrupt handler
|
|
|
|
ldx #<irq ; least significant byte
|
|
|
|
ldy #>irq ; most significant byte
|
|
|
|
stx $314
|
|
|
|
sty $315
|
|
|
|
|
|
|
|
; Set raster beam to trigger interrupt at row zero
|
|
|
|
lda #$00
|
|
|
|
sta $d012
|
|
|
|
|
|
|
|
; Bit#0 of $d011 is used as bit#9 of $d012, and must be zero
|
|
|
|
lda $d011
|
|
|
|
and #$7f
|
|
|
|
sta $d011
|
|
|
|
|
|
|
|
; Initialize player for first song
|
|
|
|
lda #0
|
|
|
|
jsr sidtune
|
|
|
|
|
|
|
|
; Initialize MultiColor mode
|
|
|
|
jsr multicolorInit
|
|
|
|
|
|
|
|
; Zero-fill zeropage variables
|
|
|
|
lda #$0
|
|
|
|
ldx #$90
|
|
|
|
zeroFillZeroPage:
|
|
|
|
dex
|
|
|
|
sta $0,x
|
|
|
|
cpx #$2
|
|
|
|
bne zeroFillZeroPage
|
|
|
|
|
|
|
|
; Set status as first-time intro playing
|
|
|
|
lda #ST_INTRO0
|
|
|
|
sta status
|
|
|
|
|
|
|
|
; Enable interrupts
|
|
|
|
cli
|
|
|
|
|
|
|
|
; Reset screen (and other parameters) to play intro
|
|
|
|
jsr introreset
|
|
|
|
|
2021-04-13 21:19:47 +00:00
|
|
|
menu SUBROUTINE
|
|
|
|
.menu: ; Cycle here until SPACE or `Q` is pressed
|
2018-09-22 08:58:10 +00:00
|
|
|
jsr $ffe4 ; GETIN
|
|
|
|
cmp #$20 ; Is it SPACE?
|
2021-04-13 21:19:47 +00:00
|
|
|
beq .intro0end ; if yes, go to intro0end and start game (see)
|
|
|
|
#if DEBUG = 1
|
|
|
|
cmp #$41 ; Is it A?
|
|
|
|
beq .printCounter ; if yes, print current counter
|
|
|
|
#endif
|
2018-09-22 08:58:10 +00:00
|
|
|
cmp #$51 ; Is it Q?
|
2021-04-13 22:30:42 +00:00
|
|
|
bne .menu ; If not, keep looping here,
|
2018-09-22 08:58:10 +00:00
|
|
|
jmp $fce2 ; else, reset the computer
|
|
|
|
|
2021-04-13 21:19:47 +00:00
|
|
|
#if DEBUG = 1
|
|
|
|
.printCounter
|
|
|
|
lda counter + 1
|
|
|
|
ldy #2
|
|
|
|
jsr printByte
|
|
|
|
lda counter
|
|
|
|
ldy #4
|
|
|
|
jsr printByte
|
|
|
|
jmp .menu
|
|
|
|
#endif
|
|
|
|
|
2018-09-22 08:58:10 +00:00
|
|
|
; Intro is finished, now it's time to start the proper game
|
2021-04-13 21:19:47 +00:00
|
|
|
.intro0end:
|
2020-04-08 08:54:54 +00:00
|
|
|
; Set current level pointer to list start
|
|
|
|
lda #<levelsList
|
|
|
|
sta levelPointer
|
|
|
|
lda #>levelsList
|
|
|
|
sta levelPointer + 1
|
|
|
|
|
|
|
|
; clear score
|
|
|
|
lda #$00
|
|
|
|
sta score
|
|
|
|
sta score + 1
|
|
|
|
|
|
|
|
; Set init variables of the level
|
|
|
|
jsr levelresetvar
|
2018-09-22 08:58:10 +00:00
|
|
|
|
2020-04-02 14:17:48 +00:00
|
|
|
; Set status as level select
|
|
|
|
; (then it will enter in status play)
|
2020-04-08 07:15:25 +00:00
|
|
|
lda #ST_LEVEL_TITLE
|
2018-09-22 08:58:10 +00:00
|
|
|
sta status
|
|
|
|
|
2021-04-13 21:19:47 +00:00
|
|
|
.endless:
|
2018-09-22 08:58:10 +00:00
|
|
|
; Loop waiting for gameover
|
|
|
|
lda status
|
|
|
|
cmp #ST_END ; is status equal to end ?
|
2021-04-13 21:19:47 +00:00
|
|
|
bne .endless ; if not, just wait looping here, else...
|
2018-09-22 08:58:10 +00:00
|
|
|
|
2021-04-13 21:19:47 +00:00
|
|
|
jsr clearScreen
|
|
|
|
|
|
|
|
lda #ST_MENURESET
|
|
|
|
sta status ; put machine into menu status
|
|
|
|
jmp .menu ; and go there waiting for keypress
|
2018-09-22 08:58:10 +00:00
|
|
|
|
|
|
|
; Interrupt Handler
|
|
|
|
; ----------------------------------------------------------------------
|
2021-04-13 21:19:47 +00:00
|
|
|
irq SUBROUTINE
|
2018-09-22 08:58:10 +00:00
|
|
|
; Things that must be done every interrupt (50Hz)
|
|
|
|
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
; Acknoweledge IRQ
|
|
|
|
dec $d019
|
|
|
|
|
|
|
|
; Save registers in stack
|
|
|
|
pha
|
|
|
|
txa
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
pha
|
|
|
|
|
2021-04-13 21:19:47 +00:00
|
|
|
#if DEBUG = 1
|
|
|
|
; Change background to show how much time does music take for each interrupt
|
|
|
|
lda #1
|
|
|
|
sta $d020
|
|
|
|
#endif
|
|
|
|
|
|
|
|
; if interrupt raster line is not 0, then someone is doing some magic elsewhere
|
|
|
|
lda $d012
|
|
|
|
;bne .noPlay
|
|
|
|
; Play music first -> no skew if computations are slow
|
|
|
|
jsr sidtune + 3
|
|
|
|
.noPlay:
|
|
|
|
|
2018-09-22 08:58:10 +00:00
|
|
|
#if DEBUG = 1
|
|
|
|
; Change background to visually see the ISR timing
|
|
|
|
lda #2
|
|
|
|
sta $d020
|
|
|
|
#endif
|
|
|
|
|
2021-04-13 21:19:47 +00:00
|
|
|
inc counter
|
|
|
|
bne .noIncCounter
|
|
|
|
inc counter + 1
|
|
|
|
.noIncCounter
|
|
|
|
|
2018-09-22 08:58:10 +00:00
|
|
|
; Check status and call appropriate sub-routine
|
|
|
|
; Sort of switch-case
|
|
|
|
lda status
|
2021-04-13 21:19:47 +00:00
|
|
|
checkStatusIntro0:
|
2018-09-22 08:58:10 +00:00
|
|
|
cmp #ST_INTRO0
|
2020-04-02 14:17:48 +00:00
|
|
|
bne checkStatusIntro1
|
2018-09-22 08:58:10 +00:00
|
|
|
jsr statusIntro0
|
|
|
|
jmp checkEndStatus
|
2020-04-02 14:17:48 +00:00
|
|
|
checkStatusIntro1:
|
2018-09-22 08:58:10 +00:00
|
|
|
cmp #ST_INTRO1
|
2021-04-13 21:19:47 +00:00
|
|
|
bne checkStatusIntro2
|
2018-09-22 08:58:10 +00:00
|
|
|
jsr statusIntro1
|
|
|
|
jmp checkEndStatus
|
2021-04-13 21:19:47 +00:00
|
|
|
checkStatusIntro2:
|
|
|
|
cmp #ST_INTRO2
|
|
|
|
bne checkStatusIntro3
|
|
|
|
jsr statusIntro2
|
|
|
|
jmp checkEndStatus
|
|
|
|
checkStatusIntro3:
|
|
|
|
cmp #ST_INTRO3
|
|
|
|
bne checkStatusIntro4
|
|
|
|
jsr statusIntro3
|
|
|
|
jmp checkEndStatus
|
|
|
|
checkStatusIntro4:
|
|
|
|
cmp #ST_INTRO4
|
2021-04-13 22:30:42 +00:00
|
|
|
bne checkStatusIntro5
|
2021-04-13 21:19:47 +00:00
|
|
|
jsr statusIntro4
|
|
|
|
jmp checkEndStatus
|
2021-04-13 22:30:42 +00:00
|
|
|
checkStatusIntro5:
|
|
|
|
cmp #ST_INTRO5
|
|
|
|
bne checkStatusIntro6
|
|
|
|
jsr statusIntro5
|
|
|
|
jmp checkEndStatus
|
|
|
|
checkStatusIntro6:
|
|
|
|
cmp #ST_INTRO6
|
|
|
|
bne checkStatusIntro7
|
|
|
|
jsr statusIntro6
|
|
|
|
jmp checkEndStatus
|
|
|
|
checkStatusIntro7:
|
|
|
|
cmp #ST_INTRO7
|
|
|
|
bne checkStatusIntro8
|
|
|
|
jsr statusIntro7
|
|
|
|
jmp checkEndStatus
|
|
|
|
checkStatusIntro8:
|
|
|
|
cmp #ST_INTRO8
|
|
|
|
bne checkStatusMenuReset
|
|
|
|
jsr statusIntro8
|
|
|
|
jmp checkEndStatus
|
2021-04-13 21:19:47 +00:00
|
|
|
checkStatusMenuReset:
|
|
|
|
cmp #ST_MENURESET
|
|
|
|
bne checkStatusMenu
|
|
|
|
jsr statusMenuReset
|
|
|
|
jmp checkEndStatus
|
|
|
|
checkStatusMenu:
|
|
|
|
cmp #ST_MENU
|
|
|
|
bne checkStatusPlay
|
|
|
|
jsr statusMenu
|
|
|
|
jmp checkEndStatus
|
2020-04-02 14:17:48 +00:00
|
|
|
checkStatusPlay:
|
2018-09-22 08:58:10 +00:00
|
|
|
cmp #ST_PLAY
|
2020-04-08 07:15:25 +00:00
|
|
|
bne checkStatusDelay
|
2018-09-22 08:58:10 +00:00
|
|
|
jsr statusPlay
|
|
|
|
jmp checkEndStatus
|
2020-04-08 07:15:25 +00:00
|
|
|
checkStatusDelay:
|
|
|
|
cmp #ST_DELAY
|
|
|
|
bne checkStatusLevelTitle
|
|
|
|
jsr statusDelay
|
|
|
|
jmp checkEndStatus
|
|
|
|
checkStatusLevelTitle:
|
|
|
|
cmp #ST_LEVEL_TITLE
|
|
|
|
bne checkStatusLevelLoad
|
|
|
|
jsr statusLevelTitle
|
2018-09-22 08:58:10 +00:00
|
|
|
jmp checkEndStatus
|
2020-04-08 07:15:25 +00:00
|
|
|
checkStatusLevelLoad:
|
|
|
|
cmp #ST_LEVEL_LOAD
|
2020-04-02 14:17:48 +00:00
|
|
|
bne checkEndStatus
|
2020-04-08 07:15:25 +00:00
|
|
|
jsr statusLevelLoad
|
2020-04-02 14:17:48 +00:00
|
|
|
jmp checkEndStatus
|
2018-09-22 08:58:10 +00:00
|
|
|
checkEndStatus:
|
|
|
|
|
|
|
|
; Increase random value
|
|
|
|
inc random
|
|
|
|
|
|
|
|
#if DEBUG = 1
|
|
|
|
; Change background back again to visally see ISR timing
|
|
|
|
lda #11
|
|
|
|
sta $d020
|
|
|
|
#endif
|
|
|
|
|
|
|
|
; Restore registers from stack
|
|
|
|
pla
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
|
|
|
|
; Go to original system routine
|
|
|
|
jmp $ea31
|
|
|
|
|
2020-09-15 12:57:10 +00:00
|
|
|
#if VERBOSE = 1
|
|
|
|
ECHO "program.asm @ ",LASTINIT,"len:",(. - LASTINIT)
|
2021-04-12 21:28:34 +00:00
|
|
|
#endif
|