From 16b49bd98d2c13c5f3f3918c0cc84edaa46943a0 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 4 Apr 2021 23:05:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A9=E5=B1=95data=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=A3=9F=E7=89=A9=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addfood.asm | 84 ++++++++++++++++++++++++++++++++++++++++++++++++- delay.asm | 2 +- head.asm | 9 +++--- main.asm | 18 ++++++++--- print.asm | 3 -- print16.asm | 2 +- printfield.asm | 3 -- snake.prg | Bin 739 -> 1122 bytes 8 files changed, 104 insertions(+), 17 deletions(-) diff --git a/addfood.asm b/addfood.asm index 6ef1d3a..d361361 100644 --- a/addfood.asm +++ b/addfood.asm @@ -3,5 +3,87 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;; addfood: .scope +.data +.space seed 6 +.text + lda #field + sta _ptr + 1 + + `propagate seed, $c3 + `propagate seed+1, $9e + `propagate seed+2, $26 + `propagate seed, seed+1 + `propagate seed+1, seed+2 + `propagate seed+2, seed+3 + + lda seed + 5 + ldx seed + 4 + sta seed + 4 + lda seed + 3 + stx seed + 3 + ldx seed + 2 + sta seed + 2 + lda seed + 1 + stx seed + 1 + ldx seed + sta seed + stx seed + 5 + + lda seed + tay + lda seed + 1 + and #$03 + beq + + clc + adc _ptr + 1 + sta _ptr + 1 +* cmp #$03 + bne + + tya + cmp #$c0 + bmi + + sbc #$c0 + tay +* lda (_ptr), y + iny + cmp #csnk + beq - + cmp #cblk + beq - + lda #csnk + dey + sta (_ptr), y rts -.scend \ No newline at end of file +.scend + +srand: ; 做随机种子的初始化 +.scope + jsr rdtim + sta seed + 5 + stx seed + 3 + sty seed + 1 + rts +.scend + +;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; propagate 进位 +;;;;;;;;;;;;;;;;;;;;;;;;;;;; +.macro propagate + lda _1 + clc + adc _2 + bcc _end + inc _1 + 1 + bne _end + inc _1 + 2 + bne _end + inc _1 + 3 + bne _end + inc _1 + 4 + bne _end + inc _1 + 5 +_end: + sta _1 +.macend \ No newline at end of file diff --git a/delay.asm b/delay.asm index c51ee64..a573d9a 100644 --- a/delay.asm +++ b/delay.asm @@ -1,7 +1,7 @@ ; DELAY routine. Takes values from the Accumulator and pauses ; for that many jiffies (1/60th of a second). .scope -.data zp +.data .space _tmp 1 .space _target 1 .text diff --git a/head.asm b/head.asm index 19bca85..2b5f825 100644 --- a/head.asm +++ b/head.asm @@ -17,10 +17,11 @@ .space d 1 ; 方向 值定义如上 .space c 1 ; 🐍长度 最大255 最小0 .space s 2 ; 得分 小端序 +.space _ptr 2 ; 通用指针 + +.alias title $0400 +.alias field $0428 ; 蛇所在屏幕内存区 .data -.org $0400 -.space title 40 -.space field 960 ; 蛇所在屏幕内存区 - +.org $c000 .text \ No newline at end of file diff --git a/main.asm b/main.asm index 7c5eafa..26a9e29 100644 --- a/main.asm +++ b/main.asm @@ -5,6 +5,9 @@ main: .scope +.data +.space lopcnt 1 ; 循环次数计数 +.text `init jsr getchar ; 等待输入任意字符开始游戏 jsr erasehint ; 游戏开始,清空提示 @@ -21,7 +24,7 @@ main: jsr append * jsr calcscore ; 计算得分 jsr printscore ; 打印分数 - lda #60 + lda #32 jsr delay ; 延时期间最后一个按键位于d lda d beq ++ @@ -29,7 +32,13 @@ main: bne + rts * sta d -* jsr addfood +* inc lopcnt + lda lopcnt + cmp #16 + bmi ----- + lda #0 + sta lopcnt + jsr addfood jmp ----- .scend @@ -51,6 +60,7 @@ main: jsr printhint ; 打印开始提示 lda #go_d ; 初始化方向为下 sta d + jsr srand ; 初始化随机数种子 .macend .require "printscore.asm" @@ -66,8 +76,8 @@ main: .require "calcscore.asm" .require "print.asm" -.checkpc $A000 ; text段边界 +.checkpc $a000 ; text段边界 .data zp ; 零页段边界 .checkpc $80 .data -.checkpc $0800 ; data段边界 \ No newline at end of file +.checkpc $d000 ; data段边界 \ No newline at end of file diff --git a/print.asm b/print.asm index 93db005..a18fdd3 100644 --- a/print.asm +++ b/print.asm @@ -13,9 +13,6 @@ ; 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 diff --git a/print16.asm b/print16.asm index 9da3aeb..af2cd39 100644 --- a/print16.asm +++ b/print16.asm @@ -4,7 +4,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; print16: .scope -.data zp +.data .space _num 4 .space _num_dec 6 .text diff --git a/printfield.asm b/printfield.asm index 92b4e7b..5e2b8a8 100644 --- a/printfield.asm +++ b/printfield.asm @@ -3,9 +3,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; printfield: .scope -.data zp -.space _ptr 2 -.text ldx #23 ; i代表行数,不含边框 lda #{R7loS!_ zp=DVpbc6&1MMT731T_U=^&p<4h!jPP3sUic#(z>P2wDdg=KsF$|Nh6Ynv-!nGPAw7 zV;dnPCO646S$LCtp4A3^xHQz*KIe?QF9HLB@1Yh?+|?GYX!A zFSBP|NkS7pi`{Z$BtBZ9!H#-t%#+nnXB&O?-eWgBHsl9vzu$1!jE4vh*a5#`uzsH% z^i?8bTl`r)wcAG%jfZ-NK$Ac_UwkBqAizF)L#Le}CJ|w2SB}OxtUI54El-u@tH@zT z{MuZNy>V7>Ufp%LQX=K?vLrE`HUYJ>rZ8bY9$|pYZ8ZVISxe~4n5HltFq|rXW~W?s z-etF4W_hs{k@34Gw7tgK@<6H#&KfXnKy4t`GhTQRTgbb`UbIx3Q%zYBEH_oVR^!cH zw)@t*CN<%}xNw2D48TDp4eBm5GG&<$>JA`TLsDug_=VaaY(yO#;VEzFt7KV!%aVFf zw^zI<2#Q`ddfnkIZ51!~uU=+Qrz>6-2n)Sv&nsRp`$Hd`JqN zEF{@ZA0$pE2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