From 52ac9f147b63e16bc06b4be0a13b3a96bf242b89 Mon Sep 17 00:00:00 2001 From: fumiama Date: Wed, 31 Mar 2021 23:29:04 +0800 Subject: [PATCH] =?UTF-8?q?add=20score(=E5=88=9D=E6=AD=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.asm | 42 ++++++++++++++++---------- print.asm | 31 ++++++++++++++++++++ print16.asm | 73 ++++++++++++++++++++++++++++++++++++++++++++++ printbyte.asm | 17 +++++++++++ printinput.asm | 20 +------------ printinput.prg | Bin 58 -> 56 bytes printscore.asm | 20 +++++++++++++ snake.prg | Bin 80 -> 276 bytes snake.prg.p2k.cfg | 26 ++++++++--------- 9 files changed, 180 insertions(+), 49 deletions(-) create mode 100644 print.asm create mode 100644 print16.asm create mode 100644 printbyte.asm create mode 100644 printscore.asm 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 2dd683ff6dddd2d177501adf7da591d7f1e817dd..b90fd02803828adc3c528c1bff8ce3b248fbb3ea 100644 GIT binary patch delta 26 icmcDrn4m1$%FyMph-0Mz8$%|8!lnPGE_}&Yl>h*8>k4%M delta 28 kcmcDpnxHJ+%W$B}V-d$n13rcWnG6b-{-3(=Ib&4<0Fu}Y1^@s6 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 ce37aa2667052689dc371d65c1558baf21752d85..428e6bb03828a1f486bc44d85f3e04fd19e6b3b6 100644 GIT binary patch delta 204 zcmWHT!Zg9Ze&woGR)sK*gq8aj@he>Vf9k?7j~N~--!9-#;NZ+yk>Szhv65jC+o`#^ z92b5qWl{Ld(Obyj1q8hX94q;G3qjnatRUfhh;SZAI3L8F;jw^4;S|S(-x(`FM&`nd z%vhC?urrrq(f=0`FS*<%{F2DDnwiVd)lr$t0i+XP&PWJ$_78GpXl3j2Sj4f?fQ>Da c0qnjn8LJXn*;_akFl=Q1zy=gLap7A609pA}O#lD@ delta 7 OcmbQj6fnV`F#!MxJ_08I 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