Tabs to space, official vim adoption
This commit is contained in:
parent
bb86656068
commit
fcc479eaed
226
snake.asm
226
snake.asm
@ -4,15 +4,15 @@
|
|||||||
; Code yet to be developed, example to use:
|
; Code yet to be developed, example to use:
|
||||||
; ----------------------------------------------------------------------
|
; ----------------------------------------------------------------------
|
||||||
#if SYSTEM = 64
|
#if SYSTEM = 64
|
||||||
; Commodore64 specific code
|
; Commodore64 specific code
|
||||||
#else
|
#else
|
||||||
; Commodore16 specific code
|
; Commodore16 specific code
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
; Zero page utilities
|
; Zero page utilities
|
||||||
; ----------------------------------------------------------------------
|
; ----------------------------------------------------------------------
|
||||||
SEG.U zeropage
|
SEG.U zeropage
|
||||||
org $02
|
org $02
|
||||||
; Where is the snake head in video memory? Do math to calculate address
|
; Where is the snake head in video memory? Do math to calculate address
|
||||||
; using pointer at tileMem,tileMem+1
|
; using pointer at tileMem,tileMem+1
|
||||||
tileMem DS 2
|
tileMem DS 2
|
||||||
@ -26,11 +26,11 @@ printIntroString DS 2
|
|||||||
introScreenStart DS 2
|
introScreenStart DS 2
|
||||||
|
|
||||||
#if DEBUG = 1
|
#if DEBUG = 1
|
||||||
; Locations $90-$FF in zeropage are used by kernal
|
; Locations $90-$FF in zeropage are used by kernal
|
||||||
ECHO "End of zeropage variables. Space left: ",($90 - .)
|
ECHO "End of zeropage variables. Space left: ",($90 - .)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SEG program
|
SEG program
|
||||||
org $801
|
org $801
|
||||||
. = $801 ; 10 SYS10240 ($2800) BASIC autostart
|
. = $801 ; 10 SYS10240 ($2800) BASIC autostart
|
||||||
BYTE #$0b,#$08,#$0a,#$00,#$9e,#$31,#$30,#$32,#$34,#$30,#$00,#$00,#$00
|
BYTE #$0b,#$08,#$0a,#$00,#$9e,#$31,#$30,#$32,#$34,#$30,#$00,#$00,#$00
|
||||||
@ -40,7 +40,7 @@ introScreenStart DS 2
|
|||||||
; Number of interrupt
|
; Number of interrupt
|
||||||
; Used as counter to be decremented to do some things less frequently
|
; Used as counter to be decremented to do some things less frequently
|
||||||
irqn:
|
irqn:
|
||||||
BYTE
|
BYTE
|
||||||
|
|
||||||
; Direction of the snake (2,4,6,8 as down,left,right,up)
|
; Direction of the snake (2,4,6,8 as down,left,right,up)
|
||||||
; 5 means `pause`
|
; 5 means `pause`
|
||||||
@ -87,10 +87,10 @@ introXinc:
|
|||||||
outroDelay
|
outroDelay
|
||||||
BYTE #$ff
|
BYTE #$ff
|
||||||
|
|
||||||
INCLUDE "cost.asm"
|
INCLUDE "cost.asm"
|
||||||
|
|
||||||
#if DEBUG = 1
|
#if DEBUG = 1
|
||||||
ECHO "End of Data. Space left: ",($e00 - .)
|
ECHO "End of Data. Space left: ",($e00 - .)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
; List
|
; List
|
||||||
@ -106,13 +106,13 @@ listY:
|
|||||||
sidtune:
|
sidtune:
|
||||||
INCBIN "amour.sid"
|
INCBIN "amour.sid"
|
||||||
#if DEBUG = 1
|
#if DEBUG = 1
|
||||||
ECHO "End of SIDtune. Space left: ",($2000 - .)
|
ECHO "End of SIDtune. Space left: ",($2000 - .)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
. = $2000
|
. = $2000
|
||||||
; This binary data that defines the font is exactly 2kB long ($800)
|
; This binary data that defines the font is exactly 2kB long ($800)
|
||||||
tggsFont:
|
tggsFont:
|
||||||
INCBIN "tggs.font"
|
INCBIN "tggs.font"
|
||||||
|
|
||||||
; ENTRY OF PROGRAM
|
; ENTRY OF PROGRAM
|
||||||
; ----------------------------------------------------------------------
|
; ----------------------------------------------------------------------
|
||||||
@ -136,8 +136,8 @@ start:
|
|||||||
sta $d01a
|
sta $d01a
|
||||||
|
|
||||||
; Store in $314 address of our custom interrupt handler
|
; Store in $314 address of our custom interrupt handler
|
||||||
ldx #<irq ; least significant byte
|
ldx #<irq ; least significant byte
|
||||||
ldy #>irq ; most significant byte
|
ldy #>irq ; most significant byte
|
||||||
stx $314
|
stx $314
|
||||||
sty $315
|
sty $315
|
||||||
|
|
||||||
@ -154,17 +154,17 @@ start:
|
|||||||
lda #0
|
lda #0
|
||||||
jsr sidtune
|
jsr sidtune
|
||||||
|
|
||||||
; Initialize MultiColor mode
|
; Initialize MultiColor mode
|
||||||
jsr multicolorInit
|
jsr multicolorInit
|
||||||
|
|
||||||
; Zero-fill zeropage variables
|
; Zero-fill zeropage variables
|
||||||
lda #$0
|
lda #$0
|
||||||
ldx #$90
|
ldx #$90
|
||||||
zeroFillZeroPage:
|
zeroFillZeroPage:
|
||||||
dex
|
dex
|
||||||
sta $0,x
|
sta $0,x
|
||||||
cpx #$2
|
cpx #$2
|
||||||
bne zeroFillZeroPage
|
bne zeroFillZeroPage
|
||||||
|
|
||||||
; Set status as first-time intro playing
|
; Set status as first-time intro playing
|
||||||
lda #ST_INTRO0
|
lda #ST_INTRO0
|
||||||
@ -186,9 +186,9 @@ intro0running: ; Cycle here until SPACE or `Q` is pressed
|
|||||||
|
|
||||||
; Intro is finished, now it's time to start the proper game
|
; Intro is finished, now it's time to start the proper game
|
||||||
intro0end:
|
intro0end:
|
||||||
; Pause everything in interrupt
|
; Pause everything in interrupt
|
||||||
lda #ST_PAUSE
|
lda #ST_PAUSE
|
||||||
sta status
|
sta status
|
||||||
; 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
|
||||||
@ -209,14 +209,14 @@ endless:
|
|||||||
; Full game reset
|
; Full game reset
|
||||||
; ----------------------------------------------------------------------
|
; ----------------------------------------------------------------------
|
||||||
fullreset:
|
fullreset:
|
||||||
; Turn MultiColor mode on
|
; Turn MultiColor mode on
|
||||||
jsr multicolorOn
|
jsr multicolorOn
|
||||||
|
|
||||||
; Clear screen
|
; Clear screen
|
||||||
ldx #$00
|
ldx #$00
|
||||||
lda #$20
|
lda #$20
|
||||||
fullresetCLS:
|
fullresetCLS:
|
||||||
dex
|
dex
|
||||||
sta $400,x
|
sta $400,x
|
||||||
sta $500,x
|
sta $500,x
|
||||||
sta $600,x
|
sta $600,x
|
||||||
@ -238,12 +238,12 @@ upperbarLoop:
|
|||||||
cpx #$ff
|
cpx #$ff
|
||||||
bne upperbarLoop
|
bne upperbarLoop
|
||||||
|
|
||||||
; Set upper bar text
|
; Set upper bar text
|
||||||
lda #<scoreString
|
lda #<scoreString
|
||||||
sta printStatusString
|
sta printStatusString
|
||||||
lda #>scoreString
|
lda #>scoreString
|
||||||
sta printStatusString + 1
|
sta printStatusString + 1
|
||||||
jsr printStatus
|
jsr printStatus
|
||||||
|
|
||||||
; Init game variables
|
; Init game variables
|
||||||
lda #FOOD_TILE
|
lda #FOOD_TILE
|
||||||
@ -252,7 +252,7 @@ upperbarLoop:
|
|||||||
sta irqn ; Initialize interrupt divider
|
sta irqn ; Initialize interrupt divider
|
||||||
lda #6
|
lda #6
|
||||||
sta direction ; Snake must go right
|
sta direction ; Snake must go right
|
||||||
; Note: these values depends on following list initialization
|
; Note: these values depends on following list initialization
|
||||||
lda #19
|
lda #19
|
||||||
sta snakeX ; Snake is at screen center width...
|
sta snakeX ; Snake is at screen center width...
|
||||||
lda #12
|
lda #12
|
||||||
@ -262,23 +262,23 @@ upperbarLoop:
|
|||||||
lda #5
|
lda #5
|
||||||
sta length ; Length of the list
|
sta length ; Length of the list
|
||||||
|
|
||||||
; Clear snake lists X and Y
|
; Clear snake lists X and Y
|
||||||
ldx #$00
|
ldx #$00
|
||||||
clearListLoop:
|
clearListLoop:
|
||||||
dex
|
dex
|
||||||
lda #19
|
lda #19
|
||||||
sta listX,x
|
sta listX,x
|
||||||
lda #12
|
lda #12
|
||||||
sta listY,x
|
sta listY,x
|
||||||
cpx #$00
|
cpx #$00
|
||||||
bne clearListLoop
|
bne clearListLoop
|
||||||
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; Intro reset
|
; Intro reset
|
||||||
; ----------------------------------------------------------------------
|
; ----------------------------------------------------------------------
|
||||||
introreset:
|
introreset:
|
||||||
jsr multicolorOff
|
jsr multicolorOff
|
||||||
|
|
||||||
; Clear screen
|
; Clear screen
|
||||||
ldx #$ff
|
ldx #$ff
|
||||||
@ -347,9 +347,9 @@ irq:
|
|||||||
pha
|
pha
|
||||||
|
|
||||||
#if DEBUG = 1
|
#if DEBUG = 1
|
||||||
; Change background to visually see the ISR timing
|
; Change background to visually see the ISR timing
|
||||||
lda #2
|
lda #2
|
||||||
sta $d020
|
sta $d020
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
; Check status and call appropriate sub-routine
|
; Check status and call appropriate sub-routine
|
||||||
@ -376,20 +376,26 @@ checkStatus3
|
|||||||
jmp checkEndStatus
|
jmp checkEndStatus
|
||||||
checkEndStatus:
|
checkEndStatus:
|
||||||
|
|
||||||
|
#if DEBUG = 1
|
||||||
|
; Change background to show how much time does music take for each interrupt
|
||||||
|
lda #1
|
||||||
|
sta $d020
|
||||||
|
#endif
|
||||||
|
|
||||||
; Play music
|
; Play music
|
||||||
jsr sidtune + 3
|
jsr sidtune + 3
|
||||||
jsr sidtune + 3
|
jsr sidtune + 3
|
||||||
jsr sidtune + 3
|
jsr sidtune + 3
|
||||||
jsr sidtune + 3
|
jsr sidtune + 3
|
||||||
jsr sidtune + 3
|
jsr sidtune + 3
|
||||||
|
|
||||||
; Increase random value
|
; Increase random value
|
||||||
inc random
|
inc random
|
||||||
|
|
||||||
#if DEBUG = 1
|
#if DEBUG = 1
|
||||||
; Change background back again to visally see ISR timing
|
; Change background back again to visally see ISR timing
|
||||||
lda #11
|
lda #11
|
||||||
sta $d020
|
sta $d020
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
; Restore registers from stack
|
; Restore registers from stack
|
||||||
@ -548,60 +554,60 @@ keybCheckP:
|
|||||||
jmp keybEndCheck
|
jmp keybEndCheck
|
||||||
keybEndCheck:
|
keybEndCheck:
|
||||||
|
|
||||||
; Get joystick status and decide snake direction
|
; Get joystick status and decide snake direction
|
||||||
; Joystick register bits 4:0 => Fire,Right,Left,Down,Up
|
; Joystick register bits 4:0 => Fire,Right,Left,Down,Up
|
||||||
; 0 = Pressed; 1 = Idle
|
; 0 = Pressed; 1 = Idle
|
||||||
lda $dc00 ; CIA joystick port 2 register
|
lda $dc00 ; CIA joystick port 2 register
|
||||||
ror ; rotate bit and put bit#0 in CF
|
ror ; rotate bit and put bit#0 in CF
|
||||||
tax ; store byte value for next key check
|
tax ; store byte value for next key check
|
||||||
bcs joyCheckDown ; if CF = 1, then key was not depressed, so skip and check next...
|
bcs joyCheckDown ; if CF = 1, then key was not depressed, so skip and check next...
|
||||||
; ... else key was depressed!
|
; ... else key was depressed!
|
||||||
lda direction ; check for not overlapping direction (turn over yourself)
|
lda direction ; check for not overlapping direction (turn over yourself)
|
||||||
cmp #2
|
cmp #2
|
||||||
beq joyEndCheck
|
beq joyEndCheck
|
||||||
lda #8
|
lda #8
|
||||||
sta direction
|
sta direction
|
||||||
jmp joyEndCheck
|
jmp joyEndCheck
|
||||||
joyCheckDown:
|
joyCheckDown:
|
||||||
txa
|
txa
|
||||||
ror
|
ror
|
||||||
tax
|
tax
|
||||||
bcs joyCheckLeft
|
bcs joyCheckLeft
|
||||||
lda direction
|
lda direction
|
||||||
cmp #8
|
cmp #8
|
||||||
beq joyEndCheck
|
beq joyEndCheck
|
||||||
lda #2
|
lda #2
|
||||||
sta direction
|
sta direction
|
||||||
jmp joyEndCheck
|
jmp joyEndCheck
|
||||||
joyCheckLeft:
|
joyCheckLeft:
|
||||||
txa
|
txa
|
||||||
ror
|
ror
|
||||||
tax
|
tax
|
||||||
bcs joyCheckRight
|
bcs joyCheckRight
|
||||||
lda direction
|
lda direction
|
||||||
cmp #6
|
cmp #6
|
||||||
beq joyEndCheck
|
beq joyEndCheck
|
||||||
lda #4
|
lda #4
|
||||||
sta direction
|
sta direction
|
||||||
jmp joyEndCheck
|
jmp joyEndCheck
|
||||||
joyCheckRight:
|
joyCheckRight:
|
||||||
txa
|
txa
|
||||||
ror
|
ror
|
||||||
tax
|
tax
|
||||||
bcs joyCheckFire
|
bcs joyCheckFire
|
||||||
lda direction
|
lda direction
|
||||||
cmp #4
|
cmp #4
|
||||||
beq joyEndCheck
|
beq joyEndCheck
|
||||||
lda #6
|
lda #6
|
||||||
sta direction
|
sta direction
|
||||||
jmp joyEndCheck
|
jmp joyEndCheck
|
||||||
joyCheckFire: ; `Fire` joystick key used to pause game
|
joyCheckFire: ; `Fire` joystick key used to pause game
|
||||||
txa
|
txa
|
||||||
ror
|
ror
|
||||||
tax
|
tax
|
||||||
bcs joyEndCheck
|
bcs joyEndCheck
|
||||||
lda #5
|
lda #5
|
||||||
sta direction
|
sta direction
|
||||||
joyEndCheck:
|
joyEndCheck:
|
||||||
|
|
||||||
; Get direction and move head accordingly
|
; Get direction and move head accordingly
|
||||||
@ -962,10 +968,10 @@ printIntroEnd:
|
|||||||
|
|
||||||
; Include
|
; Include
|
||||||
; ______________________________________________________________________
|
; ______________________________________________________________________
|
||||||
INCLUDE "multicolor.asm"
|
INCLUDE "multicolor.asm"
|
||||||
|
|
||||||
#if DEBUG = 1
|
#if DEBUG = 1
|
||||||
ECHO "Program ends at: ",.
|
ECHO "Program ends at: ",.
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
; coded during december 2017
|
; coded during december 2017
|
||||||
@ -973,3 +979,5 @@ printIntroEnd:
|
|||||||
; this software is free software and is distributed
|
; this software is free software and is distributed
|
||||||
; under the terms of GNU GPL v3 license
|
; under the terms of GNU GPL v3 license
|
||||||
;
|
;
|
||||||
|
|
||||||
|
; vim: set expandtab tabstop=4 shiftwidth=4:
|
||||||
|
Loading…
Reference in New Issue
Block a user