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

很多改进

This commit is contained in:
fumiama
2021-04-13 23:29:01 +08:00
parent 44c4e25be1
commit 43aa9250b1
7 changed files with 71 additions and 128 deletions

View File

@@ -48,14 +48,9 @@ addfood:
tay tay
* lda (_ptr), y * lda (_ptr), y
iny iny
cmp #csnk cmp #csps
beq - bne -
cmp #cblk
beq -
cmp #crnd
beq -
lda #crnd lda #crnd
dey
sta (_ptr), y sta (_ptr), y
rts rts
.scend .scend

View File

@@ -16,7 +16,7 @@
.data zp .data zp
.space d 1 ; 方向 值定义如上 .space d 1 ; 方向 值定义如上
.space c 1 ; 🐍长度 最大255 最小0 .space prev_d 1 ; 前一个方向
.space s 2 ; 得分 小端序 .space s 2 ; 得分 小端序
.space _ptr 2 ; 通用指针 .space _ptr 2 ; 通用指针
.space eat 1 ; 吃到食物标记 .space eat 1 ; 吃到食物标记

View File

@@ -13,7 +13,7 @@ printfail:
`print failhint `print failhint
rts rts
erasehint: erasehint:
ldy #25 ldy #22
lda #csps lda #csps
* sta [title+20*40+8-1], y * sta [title+20*40+8-1], y
dey dey

150
judge.asm
View File

@@ -24,75 +24,13 @@
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
judgeout: judgeout:
.scope `judgeof cblk
lda d bcs +
;;方向向上 cmp #csnk
cmp #go_u bne +
beq _gup sec
;;方向向下 * rts
cmp #go_d
beq _gdown
;;方向向左
cmp #go_l
beq _gleft
;;方向向右
cmp #go_r
beq _gright
jmp _End1 ;什么都没有撞
;是否撞墙;是否考虑溢出情况;撞墙撞自己要不要分开写?
_gup: ;地址-40?实现:/减法/地址跳跃
lda shead
sec
sbc #40
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
lda (_ptr),y
cmp #cblk
beq _End2
jmp _selfx
_gdown: ldy #40 ;地址+40,好像有问题,这个(shead)是蛇头地址的地址了 拟修改:lda (取低位用啥来着)(shead),sec, adc #40,
lda (shead),y
cmp #cblk
beq _End2
jmp _selfx
_gleft:
lda shead
sec
sbc #1
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
lda (_ptr),y
cmp #cblk
beq _End2
jmp _selfx
_gright:ldy #1 ;地址+1好像有问题这个(shead) 拟修改:lda (取低位用啥来着)(shead),sec,adc #
lda (shead),y
cmp #cblk
beq _End2
_selfx: cmp #csnk
beq _End2
;蛇没死
_End1: clc
rts
;蛇死了
_End2: sec
rts
.scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; judgefood 判断是否吃到食物 ; judgefood 判断是否吃到食物
; 是->sec 即进位标志置1 ; 是->sec 即进位标志置1
@@ -104,8 +42,17 @@ _End2: sec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
judgefood: judgefood:
.scope `judgeof crnd
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; judgeof 两个判断的宏
; 是->sec 即进位标志置1
; 否->clc 即进位标志置0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.macro judgeof
lda d lda d
ldy #0
;;方向向上 ;;方向向上
cmp #go_u cmp #go_u
beq _gup beq _gup
@@ -121,54 +68,43 @@ judgefood:
jmp _End1 ;输入了一个无效字符,,,,,? jmp _End1 ;输入了一个无效字符,,,,,?
;是否撞墙;是否考虑溢出情况-不用;撞墙撞自己要不要分开写? ;是否撞墙;是否考虑溢出情况-不用;撞墙撞自己要不要分开写?
_gup: _gup:
lda shead `_m_ptr_minus 40
sec
sbc #40
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
lda (_ptr),y lda (_ptr),y
jmp _compare
cmp #crnd _gdown:
beq _End2 ldy #40 ;地址+40
bne _End1
_gdown: ldy #40 ;地址+40
lda (shead),y lda (shead),y
cmp #crnd jmp _compare
beq _End2
bne _End1
_gleft: _gleft:
`_m_ptr_minus 1
lda shead
sec
sbc #1
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
lda (_ptr),y lda (_ptr),y
jmp _compare
cmp #crnd _gright:
beq _End2 ldy #1 ;地址+1
bne _End1
_gright:ldy #1 ;地址+1
lda (shead),y lda (shead),y
cmp #crnd
_compare:
cmp #_1
beq _End2 beq _End2
;没吃到 ;没吃到 默认情况
_End1: clc _End1: clc
rts jmp _end
;吃到了 ;吃到了
_End2: sec _End2: sec
rts _end:
.macend
.macro _m_ptr_minus
.scend lda shead
sec
sbc #_1
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
.macend

View File

@@ -19,20 +19,27 @@ main:
sta eat sta eat
jsr judgefood ; 判断是否吃到食物 jsr judgefood ; 判断是否吃到食物
bcc + bcc +
inc c ; 蛇长加一
lda #1 lda #1
sta eat sta eat
jsr addfood jsr addfood
* jsr move ; 蛇移动一格 * jsr move ; 蛇移动一格
jsr calcscore ; 计算得分 jsr calcscore ; 计算得分
jsr printscore ; 打印分数 jsr printscore ; 打印分数
lda d
sta prev_d ; 备份前一个按键
lda #32 lda #32
jsr delay ; 延时期间最后一个按键位于d jsr delay ; 延时期间最后一个按键位于d
lda d lda d
cmp #ed_g cmp #ed_g
bne + beq _end
cmp #st_g
bne ---
jsr getchar
lda prev_d
sta d ; 恢复按键
jmp ---
_end:
rts rts
* jmp ----
.scend .scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -47,8 +54,6 @@ main:
sta s + 1 ; 初始化分数为0 sta s + 1 ; 初始化分数为0
jsr printscore ; 打印分数 jsr printscore ; 打印分数
jsr move_init jsr move_init
lda #2
sta c ; 初始化蛇长为1
jsr printfield ; 打印蛇,包括边框 jsr printfield ; 打印蛇,包括边框
jsr printhint ; 打印开始提示 jsr printhint ; 打印开始提示
lda #go_d ; 初始化方向为下 lda #go_d ; 初始化方向为下

View File

@@ -5,10 +5,13 @@ printfield:
.scope .scope
ldx #23 ; i代表行数不含边框 ldx #23 ; i代表行数不含边框
lda #<field ; 取地址低8位 lda #<field ; 取地址低8位
clc
adc #1
sta _ptr sta _ptr
lda #>field ; 取地址高8位 lda #>field ; 取地址高8位
sta _ptr + 1 sta _ptr + 1
ldy #0 jsr _print_blk_line
;ldy #0 ; 此时y一定为0
* lda #cblk * lda #cblk
sta (_ptr), y ; 打印左边框 sta (_ptr), y ; 打印左边框
lda #39 lda #39
@@ -19,12 +22,7 @@ printfield:
jsr _addptr jsr _addptr
dex dex
bne - bne -
lda #cblk jsr _print_blk_line
ldy #40
dec _ptr
* sta (_ptr), y ; 打印底边
dey
bne -
rts rts
_addptr: _addptr:
@@ -34,4 +32,13 @@ _addptr:
inc _ptr + 1 inc _ptr + 1
* sta _ptr * sta _ptr
rts rts
_print_blk_line:
lda #cblk
ldy #40
dec _ptr
* sta (_ptr), y ; 打印底边
dey
bne -
rts
.scend .scend

BIN
snake.prg

Binary file not shown.