Added techniques of good software engineering - well, use of costants instead of magic numbers for statuses, sort of enum
This commit is contained in:
parent
be1c1f57f5
commit
e177fdcd86
71
snake.asm
71
snake.asm
@ -15,6 +15,13 @@ printIntroString = $a3
|
|||||||
; Pointer to screen position where to print intro string ($fb-$fc)
|
; Pointer to screen position where to print intro string ($fb-$fc)
|
||||||
introScreenStart = $fb
|
introScreenStart = $fb
|
||||||
|
|
||||||
|
; Status of the game (costants pre-processor defined)
|
||||||
|
ST_INTRO0 = 0
|
||||||
|
ST_INTRO1 = 1
|
||||||
|
ST_PLAY = 2
|
||||||
|
ST_OUTRO = 3
|
||||||
|
ST_END = 4
|
||||||
|
|
||||||
org $801
|
org $801
|
||||||
. = $801 ; 10 SYS9216 ($2400) BASIC autostart
|
. = $801 ; 10 SYS9216 ($2400) BASIC autostart
|
||||||
BYTE #$0b,#$08,#$0a,#$00,#$9e,#$39,#$32,#$31,#$36,#$00,#$00,#$00
|
BYTE #$0b,#$08,#$0a,#$00,#$9e,#$39,#$32,#$31,#$36,#$00,#$00,#$00
|
||||||
@ -62,11 +69,6 @@ random:
|
|||||||
BYTE
|
BYTE
|
||||||
|
|
||||||
; Status
|
; Status
|
||||||
; 0 fist time intro playing
|
|
||||||
; 1 init (title) screen
|
|
||||||
; 2 game running
|
|
||||||
; 3 outro
|
|
||||||
; 4 end
|
|
||||||
status:
|
status:
|
||||||
BYTE
|
BYTE
|
||||||
|
|
||||||
@ -170,7 +172,7 @@ start:
|
|||||||
jsr sidtune
|
jsr sidtune
|
||||||
|
|
||||||
; Set status as first-time intro playing
|
; Set status as first-time intro playing
|
||||||
lda #0
|
lda #ST_INTRO0
|
||||||
sta status
|
sta status
|
||||||
|
|
||||||
; Enable interrupts
|
; Enable interrupts
|
||||||
@ -192,18 +194,18 @@ intro0end:
|
|||||||
; Set init variables of the game
|
; Set init variables of the game
|
||||||
jsr fullreset
|
jsr fullreset
|
||||||
; Set status as game playing
|
; Set status as game playing
|
||||||
lda #2
|
lda #ST_PLAY
|
||||||
sta status
|
sta status
|
||||||
|
|
||||||
endless:
|
endless:
|
||||||
; Loop waiting for gameover
|
; Loop waiting for gameover
|
||||||
lda status
|
lda status
|
||||||
cmp #4 ; is status equal to 4 (gameover) ?
|
cmp #ST_END ; is status equal to end ?
|
||||||
bne endless ; if not, just wait looping here, else...
|
bne endless ; if not, just wait looping here, else...
|
||||||
|
|
||||||
jsr introreset ; reset variables for intro
|
jsr introreset ; reset variables for intro
|
||||||
lda #0
|
lda #ST_INTRO0
|
||||||
sta status ; put machine into 0 status (play intro)
|
sta status ; put machine into play intro status
|
||||||
jmp intro0running ; and go there waiting for keypress
|
jmp intro0running ; and go there waiting for keypress
|
||||||
|
|
||||||
; Full game reset
|
; Full game reset
|
||||||
@ -327,32 +329,27 @@ irq:
|
|||||||
tya
|
tya
|
||||||
pha
|
pha
|
||||||
|
|
||||||
; Check status
|
; Check status and call appropriate sub-routine
|
||||||
; Sort of switch-case
|
; Sort of switch-case
|
||||||
; 0 intro running
|
|
||||||
; 1 for future use
|
|
||||||
; 2 actual game running
|
|
||||||
; 3 after-game outro
|
|
||||||
; 4 gameover
|
|
||||||
lda status
|
lda status
|
||||||
cmp #0
|
cmp #ST_INTRO0
|
||||||
bne checkStatus1
|
bne checkStatus1
|
||||||
jsr status0
|
jsr statusIntro0
|
||||||
jmp checkEndStatus
|
jmp checkEndStatus
|
||||||
checkStatus1:
|
checkStatus1:
|
||||||
cmp #1
|
cmp #ST_INTRO1
|
||||||
bne checkStatus2
|
bne checkStatus2
|
||||||
jsr status1
|
jsr statusIntro1
|
||||||
jmp checkEndStatus
|
jmp checkEndStatus
|
||||||
checkStatus2
|
checkStatus2
|
||||||
cmp #2
|
cmp #ST_PLAY
|
||||||
bne checkStatus3
|
bne checkStatus3
|
||||||
jsr status2
|
jsr statusPlay
|
||||||
jmp checkEndStatus
|
jmp checkEndStatus
|
||||||
checkStatus3
|
checkStatus3
|
||||||
cmp #3
|
cmp #ST_OUTRO
|
||||||
bne checkEndStatus
|
bne checkEndStatus
|
||||||
jsr status3
|
jsr statusOutro
|
||||||
jmp checkEndStatus
|
jmp checkEndStatus
|
||||||
checkEndStatus:
|
checkEndStatus:
|
||||||
|
|
||||||
@ -374,10 +371,10 @@ checkEndStatus:
|
|||||||
; Go to original system routine
|
; Go to original system routine
|
||||||
jmp $ea31
|
jmp $ea31
|
||||||
|
|
||||||
; Currently status0 is the same as status1
|
; Currently statusIntro0 is the same as statusIntro1
|
||||||
; status1 has just been reserved for future use
|
; statusIntro1 has just been reserved for future use
|
||||||
status0:
|
statusIntro0:
|
||||||
status1:
|
statusIntro1:
|
||||||
; Decrement interrupt divider for the intro
|
; Decrement interrupt divider for the intro
|
||||||
ldx introCounter
|
ldx introCounter
|
||||||
dex
|
dex
|
||||||
@ -453,7 +450,7 @@ status1okset:
|
|||||||
; For now, just return.
|
; For now, just return.
|
||||||
rts
|
rts
|
||||||
|
|
||||||
status2: ; do Game
|
statusPlay: ; do Game
|
||||||
; Check counter
|
; Check counter
|
||||||
ldx irqn
|
ldx irqn
|
||||||
dex
|
dex
|
||||||
@ -719,26 +716,26 @@ gameover:
|
|||||||
sta printStatusString + 1
|
sta printStatusString + 1
|
||||||
jsr printStatus
|
jsr printStatus
|
||||||
|
|
||||||
; Set gameover status
|
; Set gameover and outro status
|
||||||
; this way, the loop out of this interrupt, will know that we
|
|
||||||
; finished, and play the intro again
|
|
||||||
lda #$ff
|
lda #$ff
|
||||||
sta outroDelay
|
sta outroDelay
|
||||||
lda #3
|
lda #ST_OUTRO
|
||||||
sta status
|
sta status
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; Decrement outroDelay, just to let player see her/his end screen
|
; Decrement outroDelay, just to let player see her/his end screen
|
||||||
; with score
|
; with score
|
||||||
status3:
|
statusOutro:
|
||||||
ldy outroDelay ; load outroDelay and decrement
|
ldy outroDelay ; load outroDelay and decrement
|
||||||
dey
|
dey
|
||||||
sty outroDelay
|
sty outroDelay
|
||||||
cpy #0
|
cpy #0
|
||||||
beq status3end
|
beq statusOutroEnd
|
||||||
rts
|
rts
|
||||||
status3end:
|
statusOutroEnd:
|
||||||
lda #4 ; go to end status
|
; Set status as ST_END: this way, the loop out of this interrupt,
|
||||||
|
; will know that we finished, and will play the intro again
|
||||||
|
lda #ST_END
|
||||||
sta status
|
sta status
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user