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

add score(初步)

This commit is contained in:
fumiama
2021-03-31 23:29:04 +08:00
parent 7415d0774d
commit 52ac9f147b
9 changed files with 180 additions and 49 deletions

View File

@@ -2,36 +2,46 @@
.require "platform/c64_0.oph"
.require "platform/c64kernal.oph"
.alias go_u #1 ; 上
.alias go_d #2 ; 下
.alias go_l #4 ;
.alias go_r #8 ;
.alias cblk $bf
.alias go_u $55 ;
.alias go_d $5f ;
.alias go_l $1d ; 左
.alias go_r $32 ; 右
.alias st_g $a0 ; 开始/暂停
.alias ed_g $20 ; 结束
.data zp
.space d 1 ; 方向 值定义如上
.space c 1 ; 长度 最大255 最小0
.space d 1 ; 方向 值定义如上
.space c 1 ; 🐍长度 最大255 最小0
.space s 2 ; 得分 小端序
.text
main:
.scope
lda #147 ;清屏
jsr chrout
rts
`init
rts
.scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; getdir 返回一个方向到d
; init 初始化界面、变量
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
getdir:
.macro
jsr chrin
sta d
.macro init
lda #147 ;清屏
jsr chrout
lda #$aa
; sta s
sta s + 1
jsr printscore
.macend
.require "printscore.asm"
.require "print16.asm"
.require "print.asm"
.checkpc $A000 ; text段边界
.data zp ; 零页段边界
.data zp ; 零页段边界
.checkpc $80
.data
.checkpc $D000 ; data段边界

31
print.asm Normal file
View File

@@ -0,0 +1,31 @@
.macro print
pha
tya
pha
lda #<_1 ; 取参数的低八位
ldy #>_1 ; 取参数的高八位
jsr printstr
pla
tay
pla
.macend
; 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
ldy #$00
_lp:
lda (_ptr),y
beq _done
jsr chrout
iny
bne _lp
_done:
rts
.scend

73
print16.asm Normal file
View File

@@ -0,0 +1,73 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; print16 从内存打印16位int(十进制5位),空位补0
; 以BE方式存储以便打印
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.macro print16
.data zp
.space _num 6
.text
pha
txa
pha
lda #0
ldx #6
* dex
sta _num, x
bne -
`splitbyte _1, 4
`splitbyte _1 + 1, 2
`carry
`print _num
pla
tax
pla
rts
mod10:
lda _num, y
ldx #$ff
* inx
clc
sbc #10
bcc -
clc
adc #$3a
sta _num, y
txa
dey
adc _num, y
sta _num, y
rts
.macend
.macro splitbyte
lda _1
jsr printbyte
sta _num + _2
lsr
lsr
lsr
lsr
sta _num + _2 - 1
lda #$0f
ora _num + _2
sta _num + _2
.macend
.macro carry
tya
pha
ldy #4
* jsr mod10
; dey
bne -
pla
tay
.macend
.require "printbyte.asm"

17
printbyte.asm Normal file
View File

@@ -0,0 +1,17 @@
.data zp
.space _na 1 ; a的临时存放处
.text
printbyte:
sta _na
txa
pha
ldx #8 ; 打印8bit
* lda #$30 ; a = '0'
asl _na ; 左移一位溢出到c
adc #0 ; a = a + c + 0
jsr chrout ; putchar(a)
dex ; x--
bne - ; if(x != 0) goto 上个星号
pla
tax
rts

View File

@@ -2,11 +2,6 @@
.require "platform/c64header.oph"
.require "platform/c64kernal.oph"
.data
.org $C000
.space _na 1 ; a的临时存放处
.text
main:
* jsr getin
beq skip
@@ -20,17 +15,4 @@ skip:
end:
rts
printbyte:
sta _na
txa
pha
ldx #8 ; 打印8bit
* lda #$30 ; a = '0'
asl _na ; 左移一位溢出到c
adc #0 ; a = a + c + 0
jsr chrout ; putchar(a)
dex ; x--
bne - ; if(x != 0) goto 上个星号
pla
tax
rts
.require "printbyte.asm"

Binary file not shown.

20
printscore.asm Normal file
View File

@@ -0,0 +1,20 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; printscore 打印分数
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
printscore:
.scope
lda #cblk
ldx #15
* jsr chrout
dex
bne -
`print score_str
`print16 s
ldx #15
* jsr chrout
dex
bne -
rts
.scend
score_str: .byte "SCORE",0

BIN
snake.prg

Binary file not shown.

View File

@@ -1,22 +1,20 @@
# Snake Fumiama
# C64
#Recalbox's Pad-to-Keyboard configuration
#Xenon 1 (1983)(IJK Software Ltd).tap
#ORIC ATMOS
# Moves
0:right = down ;; a droite
0:left = left ;; a gauche
0:j1right = down ;; a droite
0:j1left = left ;; a gauche
0:right = down
0:left = left
0:j1right = down
0:j1left = left
0:up = U
0:j1up = U
# Actions
0:b = up ;; DISENGAGE
0:a = space ;; tire
0:a = space
# Menu
0:l1 = esc ;; retour menu
0:l2 = V ;; reglage volume
0:select = I ;; instruction
0:r1 = S ;; niveau de jeu
0:l1 = esc
0:l2 = V
0:select = I
0:r1 = S