diff --git a/main.asm b/main.asm index d19a166..5b2985a 100644 --- a/main.asm +++ b/main.asm @@ -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段边界 \ No newline at end of file diff --git a/print.asm b/print.asm new file mode 100644 index 0000000..e8df889 --- /dev/null +++ b/print.asm @@ -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 \ No newline at end of file diff --git a/print16.asm b/print16.asm new file mode 100644 index 0000000..b8d4747 --- /dev/null +++ b/print16.asm @@ -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" \ No newline at end of file diff --git a/printbyte.asm b/printbyte.asm new file mode 100644 index 0000000..30ebd2e --- /dev/null +++ b/printbyte.asm @@ -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 \ No newline at end of file diff --git a/printinput.asm b/printinput.asm index 3fabc98..30266ac 100644 --- a/printinput.asm +++ b/printinput.asm @@ -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 \ No newline at end of file +.require "printbyte.asm" \ No newline at end of file diff --git a/printinput.prg b/printinput.prg index 2dd683f..b90fd02 100644 Binary files a/printinput.prg and b/printinput.prg differ diff --git a/printscore.asm b/printscore.asm new file mode 100644 index 0000000..3e670df --- /dev/null +++ b/printscore.asm @@ -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 \ No newline at end of file diff --git a/snake.prg b/snake.prg index ce37aa2..428e6bb 100644 Binary files a/snake.prg and b/snake.prg differ diff --git a/snake.prg.p2k.cfg b/snake.prg.p2k.cfg index 6b6a633..b3890d4 100644 --- a/snake.prg.p2k.cfg +++ b/snake.prg.p2k.cfg @@ -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 \ No newline at end of file +0:l1 = esc +0:l2 = V +0:select = I +0:r1 = S \ No newline at end of file