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-03 01:08:30 +08:00
parent 78f9c020d5
commit 1bf85109ea
3 changed files with 102 additions and 39 deletions

View File

@@ -5,7 +5,7 @@
print16: print16:
.scope .scope
.data zp .data zp
.space _num 6 .space _num 4
.space _num_dec 6 .space _num_dec 6
.text .text
pha pha
@@ -13,14 +13,13 @@ print16:
pha pha
lda #0 lda #0
ldx #6 ldx #10
* dex * dex
sta _num, x sta _num - 1, x
sta _num_dec, x
bne - bne -
`splitbyte s, 4 `splitbyte s, 3
`splitbyte s + 1, 2 `splitbyte s + 1, 1
`carry `carry
`print _num_dec `print _num_dec
@@ -29,43 +28,75 @@ print16:
pla pla
rts rts
_store: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
adc _num_dec, y ; mod函数处理的数据为打印方便均使用大端序存储
sta _num_dec, y ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;jsr printbyte
rts
_store2: mod_4: ; 高字节低4位若大于10则向高位进1
adc _num_dec, y lda _num + 3
sta _num_dec, y cmp #10
;jsr printbyte bcc +
dey sbc #10 ; 此时c为1
tax
lda #1 lda #1
sta _num_dec, y sta _num_dec + 3 ; 进位
txa
* sta _num_dec + 4
rts rts
mod_4: `mod10 4, $26 mod_3: ; 高字节高4位的值相当于个位加6十位加1
ldx _num + 2
bne + ; 如果为0直接返回
rts
* lda #6
`carry10 4
lda #1
`carry10 3
dex
bne -
rts
mod_3: `mod10 3, $2c mod_2: ; 低字节低4位的值相当于个位加6十位加5百位加2
ldx _num + 1
bne + ; 如果为0直接返回
rts
* lda #6
`carry10 4
lda #5
`carry10 3
lda #2
`carry10 2
dex
bne -
rts
mod_2: `mod10 2, $28 mod_1: ; 低字节低4位的值相当于个位加6十位加9百位加0千位加4
ldx _num
bne + ; 如果为0直接返回
rts
* lda #6
`carry10 4
lda #9
`carry10 3
lda #4
`carry10 1
dex
bne -
rts
mod_1: `mod10 1, $2a
.scend .scend
.macro mod10 .macro carry10
ldy #_1
lda _num, y
;jsr printbyte
cmp #10
clc clc
bmi _s adc _num_dec + _1
adc #_2 bcc _skip
jsr _store2 pha
rts adc _num_dec + _1 - 1
_s: adc #$30 sta _num_dec + _1 - 1
jsr _store pla
rts _skip:
sta _num_dec + _1
;jsr printbyte
.macend .macend
.macro splitbyte .macro splitbyte
@@ -88,15 +119,45 @@ _s: adc #$30
tya tya
pha pha
sed ; 设置为bcd加减法
jsr mod_4 jsr mod_4
jsr mod_3 jsr mod_3
jsr mod_2 jsr mod_2
jsr mod_1 jsr mod_1 ; 此时结果中有些位可能大于10需要进行进位处理
lda #$30 ldx #4
clc _loop:
adc _num_dec lda _num_dec, x
sta _num_dec ldy #0 ; y记录进位数
cmp #10
bcc _skip ; 小于10不进位
pha
ora #$f0
ror
ror
ror
ror
tay
pla
ora #$0f
sta _num_dec, x
tya
dex
adc _num_dec, x
sta _num_dec, x
inx
_skip:
dex
bne _loop
cld ; 退出bcd模式
lda #$30 ; 转化为可显示字符
ldx #5
_up:
adc _num_dec - 1, x
sta _num_dec - 1, x
dex
bne _up
pla pla
tay tay
.macend .macend

View File

@@ -2,6 +2,7 @@
.space _na 1 ; a的临时存放处 .space _na 1 ; a的临时存放处
.text .text
printbyte: printbyte:
php
pha pha
sta _na sta _na
txa txa
@@ -18,4 +19,5 @@ printbyte:
pla pla
tax tax
pla pla
plp
rts rts

BIN
snake.prg

Binary file not shown.