1
0
mirror of https://github.com/fumiama/c64-snake.git synced 2026-06-30 08:50:34 +08:00

框架构建完成

This commit is contained in:
fumiama
2021-04-03 19:34:32 +08:00
parent c21a2a1efb
commit f716081ad7
17 changed files with 241 additions and 109 deletions

7
addfood.asm Normal file
View File

@@ -0,0 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; addfood 随机生成食物
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
addfood:
.scope
rts
.scend

9
append.asm Normal file
View File

@@ -0,0 +1,9 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; append 增加蛇长
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
append:
.scope
inc c ; 蛇长加一
; 其他代码
rts
.scend

8
calcscore.asm Normal file
View File

@@ -0,0 +1,8 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; calcscore 计算分数存储到s
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
calcscore:
.scope
inc s
rts
.scend

23
delay.asm Normal file
View File

@@ -0,0 +1,23 @@
; DELAY routine. Takes values from the Accumulator and pauses
; for that many jiffies (1/60th of a second).
.scope
.data zp
.space _tmp 1
.space _target 1
.text
delay: sta _tmp ; save argument (rdtim destroys it)
jsr rdtim
clc
adc _tmp ; add current time to get target
sta _target
* jsr rdtim
cmp _target
php
jsr getin
beq +
sta d
* plp
bmi -- ; Buzz until target reached
rts
.scend

4
getchar.asm Normal file
View File

@@ -0,0 +1,4 @@
getchar:
* jsr getin
beq -
rts

View File

@@ -2,12 +2,16 @@
.alias csnk $a0 ; 像素 .alias csnk $a0 ; 像素
.alias csps $20 ; 空白 .alias csps $20 ; 空白
.alias go_u $55 ; 上 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.alias go_d $5f ; 下 ; 按钮配置调试时使用WASD控制
.alias go_l $1d ; 左 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.alias go_r $32 ; 右
.alias st_g $a0 ; 开始/暂停 .alias go_u 'W ;$55 ; 上
.alias ed_g $20 ; 结束 .alias go_d 'S ;$5f ; 下
.alias go_l 'A ;$1d ; 左
.alias go_r 'D ;$32 ; 右
.alias st_g 'P ;$a0 ; 开始/暂停
.alias ed_g 'Q ;$20 ; 结束
.data zp .data zp
.space d 1 ; 方向 值定义如上 .space d 1 ; 方向 值定义如上

24
hint.asm Normal file
View File

@@ -0,0 +1,24 @@
printhint:
clc
ldx #20 ; 光标来到正确位置
ldy #8
jsr plot
`print starthint
rts
printfail:
clc
ldx #20 ; 光标来到正确位置
ldy #8
jsr plot
`print failhint
rts
erasehint:
ldy #25
lda #csps
* sta [title+20*40+8-1], y
dey
bne -
rts
starthint: .byte "PRESS ANY KEY TO START", 0
failhint: .byte "FAILED:PRESS TO RETURN", 0

19
judge.asm Normal file
View File

@@ -0,0 +1,19 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; judgeout 判断是否出界/撞到自身
; 是->sec 即进位标志置1
; 否->clc 即进位标志置0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
judgeout:
.scope
rts
.scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; judgefood 判断是否吃到食物
; 是->sec 即进位标志置1
; 否->clc 即进位标志置0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
judgefood:
.scope
rts
.scend

View File

@@ -6,8 +6,31 @@
main: main:
.scope .scope
`init `init
jsr getchar ; 等待输入任意字符开始游戏
jsr erasehint ; 游戏开始,清空提示
* jsr move ; 蛇移动一格
clc
jsr judgeout ; 判断是否出界
bcc +
jsr printfail
jsr getchar
rts rts
clc
* jsr judgefood ; 判断是否吃到食物
bcc +
jsr append
* jsr calcscore ; 计算得分
jsr printscore ; 打印分数
lda #60
jsr delay ; 延时期间最后一个按键位于d
lda d
beq ++
cmp #ed_g
bne +
rts
* sta d
* jsr addfood
jmp -----
.scend .scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -21,15 +44,26 @@ main:
lda #$00 lda #$00
sta s + 1 ; 初始化分数为0 sta s + 1 ; 初始化分数为0
jsr printscore ; 打印分数 jsr printscore ; 打印分数
lda #1 lda #csnk
sta field + 11*38 + 19 ; 初始化蛇位置 sta field + 11*40 + 19 ; 初始化蛇位置
sta c ; 初始化蛇长为1 sta c ; 初始化蛇长为1
jsr printfield ; 打印蛇,包括边框 jsr printfield ; 打印蛇,包括边框
jsr printhint ; 打印开始提示
lda #go_d ; 初始化方向为下
sta d
.macend .macend
.require "printscore.asm" .require "printscore.asm"
.require "print16.asm" .require "print16.asm"
.require "printfield.asm" .require "printfield.asm"
.require "hint.asm"
.require "getchar.asm"
.require "addfood.asm"
.require "append.asm"
.require "delay.asm"
.require "judge.asm"
.require "move.asm"
.require "calcscore.asm"
.require "print.asm" .require "print.asm"
.checkpc $A000 ; text段边界 .checkpc $A000 ; text段边界

7
move.asm Normal file
View File

@@ -0,0 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; move 根据d中的值实现蛇的移动
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move:
.scope
rts
.scend

View File

@@ -33,7 +33,6 @@ print16:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mod_4: ; 高字节低4位若大于10则向高位进1 mod_4: ; 高字节低4位若大于10则向高位进1
;jsr chrin
lda _num + 3 lda _num + 3
cmp #10 cmp #10
bcc + bcc +
@@ -41,10 +40,8 @@ mod_4: ; 高字节低4位若大于10则向高位进1
tax tax
lda #1 lda #1
sta _num_dec + 3 ; 进位 sta _num_dec + 3 ; 进位
;jsr chrin
txa txa
* sta _num_dec + 4 * sta _num_dec + 4
;jsr chrin
rts rts
mod_3: ; 高字节高4位的值相当于个位加6十位加1 mod_3: ; 高字节高4位的值相当于个位加6十位加1
@@ -101,23 +98,19 @@ mod_1: ; 低字节低4位的值相当于个位加6十位加9百位加
pla pla
_skip: _skip:
sta _num_dec + _1 sta _num_dec + _1
;jsr chrin
.macend .macend
.macro splitbyte .macro splitbyte
lda _1 lda _1
sta _num + _2 sta _num + _2
;jsr printbyte
lsr lsr
lsr lsr
lsr lsr
lsr lsr
sta _num + _2 - 1 sta _num + _2 - 1
;jsr printbyte
lda #$0f lda #$0f
and _num + _2 and _num + _2
sta _num + _2 sta _num + _2
;jsr printbyte
.macend .macend
.macro carry .macro carry
@@ -163,5 +156,3 @@ _up:
pla pla
tay tay
.macend .macend
; .require "printbyte.asm"

View File

@@ -28,8 +28,6 @@ printfield:
* sta (_ptr), y ; 打印底边 * sta (_ptr), y ; 打印底边
dey dey
bne - bne -
ldx #0
jsr plot
rts rts
_addptr: _addptr:

View File

@@ -3,6 +3,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
printscore: printscore:
.scope .scope
clc
ldx #0 ; 光标回到原点
ldy #0
jsr plot
lda #cblk lda #cblk
ldx #15 ldx #15
* jsr chrout * jsr chrout

BIN
snake.prg

Binary file not shown.