1
0
mirror of https://github.com/fumiama/c64-snake.git synced 2026-06-05 00:32:39 +08:00

扩展data段,完成食物生成

This commit is contained in:
fumiama
2021-04-04 23:05:36 +08:00
parent 743e7c939d
commit 16b49bd98d
8 changed files with 104 additions and 17 deletions

View File

@@ -3,5 +3,87 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
addfood:
.scope
.data
.space seed 6
.text
lda #<field
sta _ptr
lda #>field
sta _ptr + 1
`propagate seed, $c3
`propagate seed+1, $9e
`propagate seed+2, $26
`propagate seed, seed+1
`propagate seed+1, seed+2
`propagate seed+2, seed+3
lda seed + 5
ldx seed + 4
sta seed + 4
lda seed + 3
stx seed + 3
ldx seed + 2
sta seed + 2
lda seed + 1
stx seed + 1
ldx seed
sta seed
stx seed + 5
lda seed
tay
lda seed + 1
and #$03
beq +
clc
adc _ptr + 1
sta _ptr + 1
* cmp #$03
bne +
tya
cmp #$c0
bmi +
sbc #$c0
tay
* lda (_ptr), y
iny
cmp #csnk
beq -
cmp #cblk
beq -
lda #csnk
dey
sta (_ptr), y
rts
.scend
.scend
srand: ; 做随机种子的初始化
.scope
jsr rdtim
sta seed + 5
stx seed + 3
sty seed + 1
rts
.scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; propagate 进位
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.macro propagate
lda _1
clc
adc _2
bcc _end
inc _1 + 1
bne _end
inc _1 + 2
bne _end
inc _1 + 3
bne _end
inc _1 + 4
bne _end
inc _1 + 5
_end:
sta _1
.macend

View File

@@ -1,7 +1,7 @@
; DELAY routine. Takes values from the Accumulator and pauses
; for that many jiffies (1/60th of a second).
.scope
.data zp
.data
.space _tmp 1
.space _target 1
.text

View File

@@ -17,10 +17,11 @@
.space d 1 ; 方向 值定义如上
.space c 1 ; 🐍长度 最大255 最小0
.space s 2 ; 得分 小端序
.space _ptr 2 ; 通用指针
.alias title $0400
.alias field $0428 ; 蛇所在屏幕内存区
.data
.org $0400
.space title 40
.space field 960 ; 蛇所在屏幕内存区
.org $c000
.text

View File

@@ -5,6 +5,9 @@
main:
.scope
.data
.space lopcnt 1 ; 循环次数计数
.text
`init
jsr getchar ; 等待输入任意字符开始游戏
jsr erasehint ; 游戏开始,清空提示
@@ -21,7 +24,7 @@ main:
jsr append
* jsr calcscore ; 计算得分
jsr printscore ; 打印分数
lda #60
lda #32
jsr delay ; 延时期间最后一个按键位于d
lda d
beq ++
@@ -29,7 +32,13 @@ main:
bne +
rts
* sta d
* jsr addfood
* inc lopcnt
lda lopcnt
cmp #16
bmi -----
lda #0
sta lopcnt
jsr addfood
jmp -----
.scend
@@ -51,6 +60,7 @@ main:
jsr printhint ; 打印开始提示
lda #go_d ; 初始化方向为下
sta d
jsr srand ; 初始化随机数种子
.macend
.require "printscore.asm"
@@ -66,8 +76,8 @@ main:
.require "calcscore.asm"
.require "print.asm"
.checkpc $A000 ; text段边界
.checkpc $a000 ; text段边界
.data zp ; 零页段边界
.checkpc $80
.data
.checkpc $0800 ; data段边界
.checkpc $d000 ; data段边界

View File

@@ -13,9 +13,6 @@
; PRINTSTR routine. Accumulator stores the low byte of the address,
; X register stores the high byte.
.scope
.data zp
.space _ptr 2
.text
printstr:
sta _ptr
sty _ptr+1

View File

@@ -4,7 +4,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print16:
.scope
.data zp
.data
.space _num 4
.space _num_dec 6
.text

View File

@@ -3,9 +3,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
printfield:
.scope
.data zp
.space _ptr 2
.text
ldx #23 ; i代表行数不含边框
lda #<field ; 取地址低8位
sta _ptr

BIN
snake.prg

Binary file not shown.