| @@ -88,7 +88,7 @@ c64 mon "r" "m .label .label+8" # talk to a run started with -Monito | |||||
| | `skirmish-game/` | Tactical game in ca65 assembly | `c64 test skirmish-game` | | | `skirmish-game/` | Tactical game in ca65 assembly | `c64 test skirmish-game` | | ||||
| | `samples/kernal-os-skeleton/` | Kernal-resident OS shell (+ `vim.asm` via `build_vim.bat`) | `c64 test samples/kernal-os-skeleton` | | | `samples/kernal-os-skeleton/` | Kernal-resident OS shell (+ `vim.asm` via `build_vim.bat`) | `c64 test samples/kernal-os-skeleton` | | ||||
| | `samples/cc65-mouse-driver-demo/` | cc65 1351 mouse driver demo | `c64 test samples/cc65-mouse-driver-demo` | | | `samples/cc65-mouse-driver-demo/` | cc65 1351 mouse driver demo | `c64 test samples/cc65-mouse-driver-demo` | | ||||
| | `vim/` | vi clone: Power C on the C64, cc65 port for the C128 (`vim128.c`) | see `vim/NOTES.md` | | |||||
| | `vim/` | vi clone: ca65 assembly on the C64 (`src/vim.s`), plus the older Power C build and a cc65 C128 port (`vim128.c`) | `pwsh vim/test/test-vim.ps1`; see `vim/NOTES.md` | | |||||
| | `newLang/` | Nova128: an OO language and on-machine compiler for the C128 | see `newLang/AGENTS.md` | | | `newLang/` | Nova128: an OO language and on-machine compiler for the C128 | see `newLang/AGENTS.md` | | ||||
| ## Platform summary | ## Platform summary | ||||
| @@ -0,0 +1,52 @@ | |||||
| # BLAST RUNNER | |||||
| An auto-scrolling run-and-gun for the Commodore 64, written in 6502 assembly (ca65/ld65). | |||||
| The city scrolls on its own. Jump the pits, use the platforms, and shoot the soldiers and bomb-dropping drones. | |||||
| ## Controls | |||||
| | Key | Joystick (port 2) | Action | | |||||
| |-----|-------------------|--------| | |||||
| | SPACE | Up | Jump (hold for a higher jump) | | |||||
| | CTRL | Fire | Shoot (hold for auto-fire) | | |||||
| | A / D | Left / Right | Move left / right on screen | | |||||
| SPACE also starts the game and restarts it after game over. | |||||
| ## Scoring | |||||
| | Target | Points | | |||||
| |--------|--------| | |||||
| | Soldier | 100 | | |||||
| | Drone | 250 | | |||||
| | Shooting down an enemy bullet or bomb | 10 | | |||||
| | Distance | 10 every 4 columns | | |||||
| You start with 3 lives. After a respawn you are invulnerable for 3 seconds, and falling into a pit bounces you back out during that time. | |||||
| The game gets harder as you go: enemies come more often, drones become more common, and pits get wider. | |||||
| ## Build and run | |||||
| ``` | |||||
| build.bat :: runs gfx.py, then assembles blastrun.prg | |||||
| build.bat -run :: build, then launch in VICE x64sc | |||||
| run.bat :: launch (builds first if needed) | |||||
| ``` | |||||
| Python, `ca65`, and `ld65` must be on `PATH`. `run.bat` expects VICE 3.10 at | |||||
| `C:\Program Files\GTK3VICE-3.10-win64\bin\x64sc.exe`. | |||||
| ## Graphics | |||||
| All sprites and custom characters are ASCII art in `gfx.py`. Edit them there and rebuild. `gfx.inc` is generated, so don't edit it by hand. | |||||
| ## Test builds | |||||
| | Define | Effect | | |||||
| |--------|--------| | |||||
| | `-D AUTOTEST` | Starts on its own, holds fire, hops now and then, and shows player Y and the on-ground flag in the HUD | | |||||
| | `-D INVINCIBLE` | Enemies can't hurt you and pits bounce you out | | |||||
| Example: `ca65 -D AUTOTEST -D INVINCIBLE blastrun.asm -o t.o && ld65 t.o -C blastrun.cfg -o test.prg` | |||||
| Screenshot without a window: `x64sc -autostart test.prg -warp -limitcycles 20000000 -exitscreenshot shot.png` | |||||
| @@ -0,0 +1,15 @@ | |||||
| MEMORY { | |||||
| ZP: start = $0002, size = $008E, type = rw, file = ""; | |||||
| LOADADDR: start = $07FF, size = $0002, file = %O; | |||||
| MAIN: start = $0801, size = $17FF, file = %O, fill = yes; | |||||
| SPR: start = $2000, size = $0400, file = %O; | |||||
| BSS: start = $3000, size = $1000, file = ""; | |||||
| } | |||||
| SEGMENTS { | |||||
| ZEROPAGE: load = ZP, type = zp; | |||||
| LOADADDR: load = LOADADDR, type = ro; | |||||
| CODE: load = MAIN, type = rw; | |||||
| RODATA: load = MAIN, type = ro; | |||||
| SPRITES: load = SPR, type = ro; | |||||
| BSS: load = BSS, type = bss; | |||||
| } | |||||
| @@ -0,0 +1,36 @@ | |||||
| Modules list: | |||||
| ------------- | |||||
| blastrun.o: | |||||
| CODE Offs=000000 Size=001024 Align=00001 Fill=0000 | |||||
| RODATA Offs=000000 Size=00026A Align=00001 Fill=0000 | |||||
| BSS Offs=000000 Size=00008D Align=00001 Fill=0000 | |||||
| ZEROPAGE Offs=000000 Size=00003C Align=00001 Fill=0000 | |||||
| SPRITES Offs=000000 Size=000380 Align=00001 Fill=0000 | |||||
| LOADADDR Offs=000000 Size=000002 Align=00001 Fill=0000 | |||||
| Segment list: | |||||
| ------------- | |||||
| Name Start End Size Align | |||||
| ---------------------------------------------------- | |||||
| ZEROPAGE 000002 00003D 00003C 00001 | |||||
| LOADADDR 0007FF 000800 000002 00001 | |||||
| CODE 000801 001824 001024 00001 | |||||
| RODATA 001825 001A8E 00026A 00001 | |||||
| SPRITES 002000 00237F 000380 00001 | |||||
| BSS 003000 00308C 00008D 00001 | |||||
| Exports list by name: | |||||
| --------------------- | |||||
| Exports list by value: | |||||
| ---------------------- | |||||
| Imports list: | |||||
| ------------- | |||||
| @@ -0,0 +1,9 @@ | |||||
| @echo off | |||||
| REM Build BLAST RUNNER: python gfx.py, then ca65/ld65. Pass -run to launch it in VICE. | |||||
| setlocal | |||||
| cd /d "%~dp0" | |||||
| python gfx.py || exit /b 1 | |||||
| ca65 blastrun.asm -o blastrun.o || exit /b 1 | |||||
| ld65 blastrun.o -C blastrun.cfg -o blastrun.prg -m blastrun.map || exit /b 1 | |||||
| echo Built blastrun.prg | |||||
| if "%1"=="-run" call run.bat | |||||
| @@ -0,0 +1,133 @@ | |||||
| ; Generated by gfx.py - do not edit, edit gfx.py instead | |||||
| ; sprite pointers | |||||
| SP_PRUN_A = $80 | |||||
| SP_PRUN_B = $81 | |||||
| SP_PRUN_C = $82 | |||||
| SP_PJUMP = $83 | |||||
| SP_SOLD_A = $84 | |||||
| SP_SOLD_B = $85 | |||||
| SP_DRONE_A = $86 | |||||
| SP_DRONE_B = $87 | |||||
| SP_EXPL_1 = $88 | |||||
| SP_EXPL_2 = $89 | |||||
| SP_EXPL_3 = $8A | |||||
| SP_PBUL = $8B | |||||
| SP_ESHOT = $8C | |||||
| SP_BOMB = $8D | |||||
| ; character codes | |||||
| CH_STAR1 = $40 | |||||
| CH_STAR2 = $41 | |||||
| CH_BTOP = $42 | |||||
| CH_BLDA = $43 | |||||
| CH_BLDB = $44 | |||||
| CH_D1 = $45 | |||||
| CH_D2 = $46 | |||||
| CH_DL = $47 | |||||
| CH_DR = $48 | |||||
| CH_G1 = $50 | |||||
| CH_G2 = $51 | |||||
| CH_GL = $52 | |||||
| CH_GR = $53 | |||||
| CH_PLL = $54 | |||||
| CH_PLM = $55 | |||||
| CH_PLR = $56 | |||||
| CH_SOLID = $50 | |||||
| CUSTOM_FIRST = $40 | |||||
| .segment "RODATA" | |||||
| custom_chars: | |||||
| .byte $00,$00,$30,$00,$00,$00,$00,$00,$00,$03,$00,$00,$00,$C0,$00,$00 | |||||
| .byte $00,$AA,$AA,$BA,$AA,$AE,$AA,$AA,$AA,$BA,$BA,$AA,$AA,$AE,$AE,$AA | |||||
| .byte $AA,$AA,$AA,$AA,$AA,$AE,$AE,$AA,$55,$65,$55,$56,$55,$55,$95,$55 | |||||
| .byte $55,$55,$59,$55,$95,$55,$55,$59,$95,$99,$95,$95,$96,$95,$95,$95 | |||||
| .byte $56,$66,$56,$56,$96,$56,$56,$56,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $33,$FF,$DF,$55,$65,$55,$59,$55,$CC,$FF,$F7,$55,$56,$55,$95,$55 | |||||
| .byte $0F,$3F,$B7,$95,$99,$95,$95,$95,$F0,$FC,$DE,$56,$66,$56,$56,$56 | |||||
| .byte $3F,$95,$99,$95,$2A,$00,$00,$00,$FF,$55,$65,$55,$AA,$00,$00,$00 | |||||
| .byte $FC,$56,$66,$56,$A8,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| custom_chars_end: | |||||
| sintab: | |||||
| .byte $0C,$0E,$11,$13,$14,$16,$17,$18,$18,$18,$17,$16,$14,$13,$11,$0E | |||||
| .byte $0C,$0A,$07,$05,$04,$02,$01,$00,$00,$00,$01,$02,$04,$05,$07,$0A | |||||
| .segment "SPRITES" | |||||
| spr_prun_a: | |||||
| .byte $00,$55,$00,$01,$AA,$50,$06,$AA,$A4,$05,$7F,$50,$01,$F7,$40,$01 | |||||
| .byte $FF,$40,$00,$55,$00,$06,$AA,$95,$1A,$A9,$55,$1A,$AA,$90,$1A,$AA | |||||
| .byte $40,$06,$A9,$00,$05,$55,$00,$06,$AA,$40,$06,$91,$90,$1A,$40,$64 | |||||
| .byte $19,$00,$64,$64,$00,$19,$64,$00,$19,$7D,$00,$7D,$55,$00,$55,$00 | |||||
| spr_prun_b: | |||||
| .byte $00,$55,$00,$01,$AA,$50,$06,$AA,$A4,$05,$7F,$50,$01,$F7,$40,$01 | |||||
| .byte $FF,$40,$00,$55,$00,$06,$AA,$95,$1A,$A9,$55,$1A,$AA,$90,$1A,$AA | |||||
| .byte $40,$06,$A9,$00,$05,$55,$00,$06,$AA,$40,$01,$A9,$00,$01,$A9,$00 | |||||
| .byte $01,$A4,$00,$01,$A4,$00,$01,$A4,$00,$01,$FD,$00,$01,$55,$00,$00 | |||||
| spr_prun_c: | |||||
| .byte $00,$55,$00,$01,$AA,$50,$06,$AA,$A4,$05,$7F,$50,$01,$F7,$40,$01 | |||||
| .byte $FF,$40,$00,$55,$00,$06,$AA,$95,$1A,$A9,$55,$1A,$AA,$90,$1A,$AA | |||||
| .byte $40,$06,$A9,$00,$05,$55,$00,$06,$AA,$40,$06,$96,$40,$06,$46,$40 | |||||
| .byte $19,$06,$40,$19,$01,$90,$64,$01,$90,$7D,$01,$F4,$55,$01,$54,$00 | |||||
| spr_pjump: | |||||
| .byte $00,$55,$00,$01,$AA,$50,$06,$AA,$A4,$05,$7F,$50,$01,$F7,$40,$01 | |||||
| .byte $FF,$40,$00,$55,$00,$06,$AA,$95,$1A,$A9,$55,$1A,$AA,$90,$1A,$AA | |||||
| .byte $40,$06,$A9,$00,$05,$55,$00,$06,$AA,$50,$06,$AA,$A4,$06,$41,$A4 | |||||
| .byte $19,$00,$7D,$1F,$40,$55,$15,$40,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_sold_a: | |||||
| .byte $00,$55,$00,$05,$AA,$40,$1A,$AA,$90,$05,$FD,$50,$01,$DF,$40,$01 | |||||
| .byte $FF,$40,$00,$55,$00,$56,$AA,$90,$55,$6A,$A4,$06,$AA,$A4,$01,$AA | |||||
| .byte $A4,$00,$6A,$90,$00,$55,$50,$01,$AA,$90,$06,$46,$90,$19,$01,$A4 | |||||
| .byte $19,$00,$64,$64,$00,$19,$64,$00,$19,$7D,$00,$7D,$55,$00,$55,$00 | |||||
| spr_sold_b: | |||||
| .byte $00,$55,$00,$05,$AA,$40,$1A,$AA,$90,$05,$FD,$50,$01,$DF,$40,$01 | |||||
| .byte $FF,$40,$00,$55,$00,$56,$AA,$90,$55,$6A,$A4,$06,$AA,$A4,$01,$AA | |||||
| .byte $A4,$00,$6A,$90,$00,$55,$50,$01,$AA,$90,$01,$96,$90,$01,$91,$90 | |||||
| .byte $01,$90,$64,$06,$40,$64,$06,$40,$19,$1F,$40,$7D,$15,$40,$55,$00 | |||||
| spr_drone_a: | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$55,$41,$55,$00,$14,$00,$00 | |||||
| .byte $55,$00,$01,$AA,$40,$06,$FA,$90,$55,$55,$55,$79,$E7,$9D,$55,$55 | |||||
| .byte $55,$06,$AA,$90,$01,$55,$40,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_drone_b: | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$05,$41,$50,$00,$14,$00,$00 | |||||
| .byte $55,$00,$01,$AA,$40,$06,$FA,$90,$55,$55,$55,$67,$9E,$79,$55,$55 | |||||
| .byte $55,$06,$AA,$90,$01,$55,$40,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_expl_1: | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$28,$00,$00,$BE,$00,$02,$FF | |||||
| .byte $80,$02,$FF,$80,$00,$BE,$00,$00,$28,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_expl_2: | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $20,$00,$08,$28,$20,$02,$BE,$80,$0B,$FF,$E0,$2F,$D7,$F8,$AF,$55 | |||||
| .byte $FA,$2F,$55,$F8,$0B,$D7,$E0,$02,$BE,$80,$08,$28,$20,$00,$08,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_expl_3: | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$08,$00,$08,$00,$00,$00,$00 | |||||
| .byte $41,$00,$20,$00,$00,$01,$41,$40,$04,$00,$10,$10,$28,$04,$80,$82 | |||||
| .byte $02,$10,$28,$04,$04,$00,$10,$01,$41,$40,$00,$00,$00,$20,$00,$08 | |||||
| .byte $00,$00,$00,$00,$20,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_pbul: | |||||
| .byte $7F,$00,$00,$FF,$00,$00,$7F,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_eshot: | |||||
| .byte $60,$00,$00,$F0,$00,$00,$60,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| spr_bomb: | |||||
| .byte $90,$00,$00,$60,$00,$00,$F0,$00,$00,$F0,$00,$00,$60,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| @@ -0,0 +1,311 @@ | |||||
| """Generate gfx.inc (sprites, custom characters, tables) for BLAST RUNNER. | |||||
| Edit the ASCII art below and run: python gfx.py | |||||
| build.bat runs this automatically. | |||||
| Multicolor sprite pixels (12 wide, each pixel is 2 screen pixels): | |||||
| . transparent k $D025 (black) c sprite colour w $D026 (pink) | |||||
| Hires sprite pixels (24 wide): | |||||
| . transparent # sprite colour | |||||
| Multicolor character pixels (4 wide): | |||||
| . $D021 sky b $D022 brown k $D023 dark grey c colour RAM | |||||
| """ | |||||
| import math | |||||
| import os | |||||
| # --------------------------------------------------------------- sprites | |||||
| PLAYER_BODY = [ | |||||
| "....kkkk....", | |||||
| "...kcccckk..", | |||||
| "..kccccccck.", | |||||
| "..kkkwwwkk..", | |||||
| "...kwwkwk...", | |||||
| "...kwwwwk...", | |||||
| "....kkkk....", | |||||
| "..kcccccckkk", | |||||
| ".kccccckkkkk", | |||||
| ".kccccccck..", | |||||
| ".kcccccck...", | |||||
| "..kcccck....", | |||||
| "..kkkkkk....", | |||||
| ] | |||||
| LEGS_A = [ | |||||
| "..kccccck...", | |||||
| "..kcck.kck..", | |||||
| ".kcck...kck.", | |||||
| ".kck....kck.", | |||||
| "kck......kck", | |||||
| "kck......kck", | |||||
| "kwwk....kwwk", | |||||
| "kkkk....kkkk", | |||||
| ] | |||||
| LEGS_B = [ | |||||
| "..kccccck...", | |||||
| "...kccck....", | |||||
| "...kccck....", | |||||
| "...kcck.....", | |||||
| "...kcck.....", | |||||
| "...kcck.....", | |||||
| "...kwwwk....", | |||||
| "...kkkkk....", | |||||
| ] | |||||
| LEGS_C = [ | |||||
| "..kccccck...", | |||||
| "..kcckkck...", | |||||
| "..kck.kck...", | |||||
| ".kck..kck...", | |||||
| ".kck...kck..", | |||||
| "kck....kck..", | |||||
| "kwwk...kwwk.", | |||||
| "kkkk...kkkk.", | |||||
| ] | |||||
| LEGS_JUMP = [ | |||||
| "..kccccckk..", | |||||
| "..kccccccck.", | |||||
| "..kck..kcck.", | |||||
| ".kck....kwwk", | |||||
| ".kwwk...kkkk", | |||||
| ".kkkk.......", | |||||
| "............", | |||||
| "............", | |||||
| ] | |||||
| DRONE_A = [""] * 3 + [ | |||||
| "kkkkk..kkkkk", | |||||
| ".....kk.....", | |||||
| "....kkkk....", | |||||
| "...kcccck...", | |||||
| "..kcwwccck..", | |||||
| "kkkkkkkkkkkk", | |||||
| "kwckwckwckwk", | |||||
| "kkkkkkkkkkkk", | |||||
| "..kcccccck..", | |||||
| "...kkkkkk...", | |||||
| ] | |||||
| DRONE_B = [""] * 3 + [ | |||||
| "..kkk..kkk..", | |||||
| ".....kk.....", | |||||
| "....kkkk....", | |||||
| "...kcccck...", | |||||
| "..kcwwccck..", | |||||
| "kkkkkkkkkkkk", | |||||
| "kckwckwckwck", | |||||
| "kkkkkkkkkkkk", | |||||
| "..kcccccck..", | |||||
| "...kkkkkk...", | |||||
| ] | |||||
| EXPL_1 = [""] * 8 + [ | |||||
| ".....cc.....", | |||||
| "....cwwc....", | |||||
| "...cwwwwc...", | |||||
| "...cwwwwc...", | |||||
| "....cwwc....", | |||||
| ".....cc.....", | |||||
| ] | |||||
| EXPL_2 = [""] * 5 + [ | |||||
| ".....c......", | |||||
| "..c..cc..c..", | |||||
| "...ccwwcc...", | |||||
| "..cwwwwwwc..", | |||||
| ".cwwwkkwwwc.", | |||||
| "ccwwkkkkwwcc", | |||||
| ".cwwkkkkwwc.", | |||||
| "..cwwkkwwc..", | |||||
| "...ccwwcc...", | |||||
| "..c..cc..c..", | |||||
| "......c.....", | |||||
| ] | |||||
| EXPL_3 = [""] * 3 + [ | |||||
| "..c.......c.", | |||||
| "............", | |||||
| "....k..k....", | |||||
| ".c..........", | |||||
| "...kk..kk...", | |||||
| "..k......k..", | |||||
| ".k...cc...k.", | |||||
| "c...c..c...c", | |||||
| ".k...cc...k.", | |||||
| "..k......k..", | |||||
| "...kk..kk...", | |||||
| "............", | |||||
| ".c........c.", | |||||
| "............", | |||||
| ".....c......", | |||||
| ] | |||||
| PBUL = [ | |||||
| ".#######", | |||||
| "########", | |||||
| ".#######", | |||||
| ] | |||||
| ESHOT = [ | |||||
| ".##.", | |||||
| "####", | |||||
| ".##.", | |||||
| ] | |||||
| BOMB = [ | |||||
| "#..#", | |||||
| ".##.", | |||||
| "####", | |||||
| "####", | |||||
| ".##.", | |||||
| ] | |||||
| def mirror(rows): | |||||
| return [r[::-1] for r in rows] | |||||
| PLAYER = { | |||||
| "PRUN_A": PLAYER_BODY + LEGS_A, | |||||
| "PRUN_B": PLAYER_BODY + LEGS_B, | |||||
| "PRUN_C": PLAYER_BODY + LEGS_C, | |||||
| "PJUMP": PLAYER_BODY + LEGS_JUMP, | |||||
| } | |||||
| # (name, kind, rows) in sprite-block order starting at block $80 ($2000) | |||||
| SPRITES = [ | |||||
| ("PRUN_A", "mc", PLAYER["PRUN_A"]), | |||||
| ("PRUN_B", "mc", PLAYER["PRUN_B"]), | |||||
| ("PRUN_C", "mc", PLAYER["PRUN_C"]), | |||||
| ("PJUMP", "mc", PLAYER["PJUMP"]), | |||||
| ("SOLD_A", "mc", mirror(PLAYER["PRUN_A"])), | |||||
| ("SOLD_B", "mc", mirror(PLAYER["PRUN_C"])), | |||||
| ("DRONE_A", "mc", DRONE_A), | |||||
| ("DRONE_B", "mc", DRONE_B), | |||||
| ("EXPL_1", "mc", EXPL_1), | |||||
| ("EXPL_2", "mc", EXPL_2), | |||||
| ("EXPL_3", "mc", EXPL_3), | |||||
| ("PBUL", "hi", PBUL), | |||||
| ("ESHOT", "hi", ESHOT), | |||||
| ("BOMB", "hi", BOMB), | |||||
| ] | |||||
| SPRITE_BASE_BLOCK = 0x80 | |||||
| # --------------------------------------------------------------- characters | |||||
| CHARS = { | |||||
| # decoration (not solid) | |||||
| 0x40: ("STAR1", ["....", "....", ".c..", "....", "....", "....", "....", "...."]), | |||||
| 0x41: ("STAR2", ["....", "...c", "....", "....", "....", "c...", "....", "...."]), | |||||
| 0x42: ("BTOP", ["....", "kkkk", "kkkk", "kckk", "kkkk", "kkck", "kkkk", "kkkk"]), | |||||
| 0x43: ("BLDA", ["kkkk", "kckk", "kckk", "kkkk", "kkkk", "kkck", "kkck", "kkkk"]), | |||||
| 0x44: ("BLDB", ["kkkk", "kkkk", "kkkk", "kkkk", "kkkk", "kkck", "kkck", "kkkk"]), | |||||
| 0x45: ("D1", ["bbbb", "bkbb", "bbbb", "bbbk", "bbbb", "bbbb", "kbbb", "bbbb"]), | |||||
| 0x46: ("D2", ["bbbb", "bbbb", "bbkb", "bbbb", "kbbb", "bbbb", "bbbb", "bbkb"]), | |||||
| 0x47: ("DL", ["kbbb", "kbkb", "kbbb", "kbbb", "kbbk", "kbbb", "kbbb", "kbbb"]), | |||||
| 0x48: ("DR", ["bbbk", "bkbk", "bbbk", "bbbk", "kbbk", "bbbk", "bbbk", "bbbk"]), | |||||
| # solid from above: code >= CH_SOLID | |||||
| 0x50: ("G1", [".c.c", "cccc", "cbcc", "bbbb", "bkbb", "bbbb", "bbkb", "bbbb"]), | |||||
| 0x51: ("G2", ["c.c.", "cccc", "ccbc", "bbbb", "bbbk", "bbbb", "kbbb", "bbbb"]), | |||||
| 0x52: ("GL", ["..cc", ".ccc", "kcbc", "kbbb", "kbkb", "kbbb", "kbbb", "kbbb"]), | |||||
| 0x53: ("GR", ["cc..", "ccc.", "cbck", "bbbk", "bkbk", "bbbk", "bbbk", "bbbk"]), | |||||
| 0x54: ("PLL", [".ccc", "kbbb", "kbkb", "kbbb", ".kkk", "....", "....", "...."]), | |||||
| 0x55: ("PLM", ["cccc", "bbbb", "bkbb", "bbbb", "kkkk", "....", "....", "...."]), | |||||
| 0x56: ("PLR", ["ccc.", "bbbk", "bkbk", "bbbk", "kkk.", "....", "....", "...."]), | |||||
| } | |||||
| CHAR_FIRST, CHAR_LAST = 0x40, 0x5F | |||||
| CH_SOLID = 0x50 | |||||
| # --------------------------------------------------------------- encoders | |||||
| MC_SPR = {".": 0, "k": 1, "c": 2, "w": 3} | |||||
| MC_CHR = {".": 0, "b": 1, "k": 2, "c": 3} | |||||
| def pad_rows(name, rows, width): | |||||
| if len(rows) > 21: | |||||
| raise SystemExit(f"{name}: {len(rows)} rows (max 21)") | |||||
| out = [] | |||||
| for i, r in enumerate(rows): | |||||
| if len(r) > width: | |||||
| raise SystemExit(f"{name} row {i}: {len(r)} > {width} pixels") | |||||
| out.append(r.ljust(width, ".")) | |||||
| return out + ["." * width] * (21 - len(out)) | |||||
| def encode_mc_sprite(name, rows): | |||||
| data = [] | |||||
| for r in pad_rows(name, rows, 12): | |||||
| bits = 0 | |||||
| for ch in r: | |||||
| bits = (bits << 2) | MC_SPR[ch] | |||||
| data += [(bits >> 16) & 255, (bits >> 8) & 255, bits & 255] | |||||
| return data + [0] | |||||
| def encode_hi_sprite(name, rows): | |||||
| data = [] | |||||
| for r in pad_rows(name, rows, 24): | |||||
| bits = 0 | |||||
| for ch in r: | |||||
| bits = (bits << 1) | (1 if ch == "#" else 0) | |||||
| data += [(bits >> 16) & 255, (bits >> 8) & 255, bits & 255] | |||||
| return data + [0] | |||||
| def encode_char(name, rows): | |||||
| if len(rows) != 8: | |||||
| raise SystemExit(f"char {name}: needs 8 rows") | |||||
| out = [] | |||||
| for i, r in enumerate(rows): | |||||
| if len(r) != 4: | |||||
| raise SystemExit(f"char {name} row {i}: needs 4 pixels") | |||||
| b = 0 | |||||
| for ch in r: | |||||
| b = (b << 2) | MC_CHR[ch] | |||||
| out.append(b) | |||||
| return out | |||||
| def hexbytes(data): | |||||
| lines = [] | |||||
| for i in range(0, len(data), 16): | |||||
| lines.append(" .byte " + ",".join(f"${b:02X}" for b in data[i:i + 16])) | |||||
| return lines | |||||
| def main(): | |||||
| here = os.path.dirname(os.path.abspath(__file__)) | |||||
| out = ["; Generated by gfx.py - do not edit, edit gfx.py instead", ""] | |||||
| out.append("; sprite pointers") | |||||
| for i, (name, _, _) in enumerate(SPRITES): | |||||
| out.append(f"SP_{name:<8} = ${SPRITE_BASE_BLOCK + i:02X}") | |||||
| out.append("") | |||||
| out.append("; character codes") | |||||
| for code, (name, _) in sorted(CHARS.items()): | |||||
| out.append(f"CH_{name:<8} = ${code:02X}") | |||||
| out.append(f"CH_SOLID = ${CH_SOLID:02X}") | |||||
| out.append(f"CUSTOM_FIRST = ${CHAR_FIRST:02X}") | |||||
| out.append("") | |||||
| out.append('.segment "RODATA"') | |||||
| out.append("custom_chars:") | |||||
| data = [] | |||||
| for code in range(CHAR_FIRST, CHAR_LAST + 1): | |||||
| if code in CHARS: | |||||
| data += encode_char(*CHARS[code]) | |||||
| else: | |||||
| data += [0] * 8 | |||||
| out += hexbytes(data) | |||||
| out.append("custom_chars_end:") | |||||
| out.append("") | |||||
| # drone bob: 32 steps, 0..24 | |||||
| sine = [round(12 + 12 * math.sin(2 * math.pi * i / 32)) for i in range(32)] | |||||
| out.append("sintab:") | |||||
| out += hexbytes(sine) | |||||
| out.append("") | |||||
| out.append('.segment "SPRITES"') | |||||
| for name, kind, rows in SPRITES: | |||||
| enc = encode_mc_sprite if kind == "mc" else encode_hi_sprite | |||||
| out.append(f"spr_{name.lower()}:") | |||||
| out += hexbytes(enc(name, rows)) | |||||
| out.append("") | |||||
| with open(os.path.join(here, "gfx.inc"), "w", newline="\n") as f: | |||||
| f.write("\n".join(out)) | |||||
| print(f"gfx.inc: {len(SPRITES)} sprites, {len(CHARS)} chars") | |||||
| if __name__ == "__main__": | |||||
| main() | |||||
| @@ -0,0 +1,5 @@ | |||||
| @echo off | |||||
| setlocal | |||||
| set "VICE_EXE=C:\Program Files\GTK3VICE-3.10-win64\bin\x64sc.exe" | |||||
| if not exist "%~dp0blastrun.prg" call "%~dp0build.bat" || exit /b 1 | |||||
| "%VICE_EXE%" -autostart "%~dp0blastrun.prg" -autostartprgmode 1 | |||||
| @@ -0,0 +1,49 @@ | |||||
| # BUZZ RUN | |||||
| A one-button flying game for the Commodore 64, written in 6502 assembly (ca65/ld65). | |||||
| Steer a bumblebee through the gaps in an endless row of hedge pillars. | |||||
| ## Controls | |||||
| | Input | Action | | |||||
| |-------|--------| | |||||
| | Fire (joystick port 1 or 2) or SPACE | Flap / start / retry | | |||||
| ## Build and run | |||||
| ``` | |||||
| build.bat :: assembles buzzrun.prg | |||||
| build.bat -run :: build, then launch in VICE x64sc | |||||
| run.bat :: launch (builds first if needed) | |||||
| ``` | |||||
| `ca65`/`ld65` must be on `PATH`. `run.bat` expects VICE 3.10 at | |||||
| `C:\Program Files\GTK3VICE-3.10-win64\bin\x64sc.exe`. | |||||
| ## Test builds | |||||
| | Define | Effect | | |||||
| |--------|--------| | |||||
| | `-D AUTOTEST` | Starts immediately and flaps automatically (for screenshots in VICE) | | |||||
| | `-D INVINCIBLE` | Ignores pillar collisions | | |||||
| Example: `ca65 -D AUTOTEST -D INVINCIBLE buzzrun.asm -o t.o && ld65 t.o -C buzzrun.cfg -o test.prg` | |||||
| ## How it works | |||||
| - **Display:** multicolor text mode in 38-column mode. The pillars and ground use custom characters; the ROM font is copied to `$3000` and the custom characters are placed over codes `$40`–`$4C`. | |||||
| - **Scrolling:** the playfield moves 1 pixel per frame using `$D016` fine scroll. Every 8 pixels, rows 1–24 are copied one column left, starting in the lower border. The copy runs top to bottom ahead of the raster beam, so the screen doesn't tear. New world columns are drawn into the hidden column 39. | |||||
| - **Raster IRQs:** line 251 resets the scroll for the HUD row, updates the sprite, and signals the main loop. Line 58 applies the playfield fine scroll. | |||||
| - **Collision:** the sprite-to-background register `$D01F` detects hits at pixel level. The light-green highlight pixels (`%01`) don't count as hits, which makes the edges slightly forgiving. | |||||
| - **Scoring:** after each coarse scroll, if a pillar's right-edge character is in column 7 of row 1, the bee has passed it. | |||||
| - **Random gaps:** an 8-bit Galois LFSR, seeded from the frame counter when the player presses fire. | |||||
| - **Sound:** SID voice 1 plays the flap chirp and the crash noise. Voice 2 plays the score ding. | |||||
| ## Memory map | |||||
| | Range | Use | | |||||
| |-------|-----| | |||||
| | `$0002`–`$001D` | Zero-page variables | | |||||
| | `$0801`–`$0FFF` | Program (BASIC `SYS 2061` stub) | | |||||
| | `$2000`–`$207F` | Bee sprite frames (copied at start-up) | | |||||
| | `$3000`–`$37FF` | Character set | | |||||
| @@ -0,0 +1,8 @@ | |||||
| @echo off | |||||
| REM Build BUZZ RUN with ca65/ld65. Pass -run to launch it in VICE. | |||||
| setlocal | |||||
| cd /d "%~dp0" | |||||
| ca65 buzzrun.asm -o buzzrun.o || exit /b 1 | |||||
| ld65 buzzrun.o -C buzzrun.cfg -o buzzrun.prg -m buzzrun.map || exit /b 1 | |||||
| echo Built buzzrun.prg | |||||
| if "%1"=="-run" call run.bat | |||||
| @@ -0,0 +1,916 @@ | |||||
| ; =========================================================================== | |||||
| ; BUZZ RUN - a one-button flying game for the Commodore 64 | |||||
| ; Guide a bumblebee through the gaps in an endless row of hedge pillars. | |||||
| ; | |||||
| ; Controls: FIRE (joystick port 1 or 2) or SPACE to flap. | |||||
| ; Build : ca65 buzzrun.asm -o buzzrun.o && ld65 buzzrun.o -C buzzrun.cfg -o buzzrun.prg | |||||
| ; | |||||
| ; Technique notes | |||||
| ; - Multicolor text mode, 38-column mode, hardware X fine scroll ($D016). | |||||
| ; - Two raster IRQs: line 251 (score row unscrolled, frame tick, sprite | |||||
| ; update) and line 58 (apply fine scroll to the playfield). | |||||
| ; - Coarse scroll copies rows top-to-bottom starting in the lower border, | |||||
| ; staying ahead of the beam, so there is no tearing. | |||||
| ; - Sprite/background collision register $D01F gives pixel-exact hits. | |||||
| ; - Gap heights come from an 8-bit LFSR seeded by the frame counter | |||||
| ; at the moment the player presses fire. | |||||
| ; =========================================================================== | |||||
| ; ---------------------------------------------------------------- hardware | |||||
| SCREEN = $0400 | |||||
| COLRAM = $D800 | |||||
| CHARSET = $3000 | |||||
| SPRDATA = $2000 ; sprite block $80 | |||||
| SPRPTR = SCREEN + $03F8 | |||||
| VIC_SPR0X = $D000 | |||||
| VIC_SPR0Y = $D001 | |||||
| VIC_SPRXHI = $D010 | |||||
| VIC_CTRL1 = $D011 | |||||
| VIC_RASTER = $D012 | |||||
| VIC_SPREN = $D015 | |||||
| VIC_CTRL2 = $D016 | |||||
| VIC_MEM = $D018 | |||||
| VIC_IRQ = $D019 | |||||
| VIC_IRQEN = $D01A | |||||
| VIC_SPRMC = $D01C | |||||
| VIC_SBCOLL = $D01F | |||||
| VIC_BORDER = $D020 | |||||
| VIC_BG0 = $D021 | |||||
| VIC_BG1 = $D022 | |||||
| VIC_BG2 = $D023 | |||||
| VIC_SPRMC0 = $D025 | |||||
| VIC_SPRMC1 = $D026 | |||||
| VIC_SPR0COL = $D027 | |||||
| SID = $D400 | |||||
| CIA1_PRA = $DC00 | |||||
| CIA1_PRB = $DC01 | |||||
| CIA1_ICR = $DC0D | |||||
| CIA2_ICR = $DD0D | |||||
| IRQVEC = $0314 | |||||
| KERNAL_IRQ_EXIT = $EA81 | |||||
| ; ---------------------------------------------------------------- tuning | |||||
| BEE_X = 88 ; sprite X register (fixed) | |||||
| Y_CEIL = 56 ; topmost sprite Y (art starts 3 lines down) | |||||
| Y_FLOOR = 221 ; art bottom sits on the grass | |||||
| Y_START = 110 | |||||
| GRAV = $0016 ; 8.8 px/frame^2 (~0.086) | |||||
| FLAP_VEL = $FE4D ; -1.7 px/frame (~18 px rise incl. apex hang) | |||||
| MAX_FALL = $0240 ; +2.25 px/frame | |||||
| GRAV_HANG = $000C ; gravity near the top of the arc (~0.05) | |||||
| HANG_WINDOW = $0080 ; "near the top" = |vel| < 0.5 px/frame | |||||
| .assert GRAV < $100 && GRAV_HANG < $100 && HANG_WINDOW < $100, error, "physics assumes 8-bit gravity/window" | |||||
| TITLE_BOB_Y = 120 | |||||
| GAP = 6 ; gap height in rows | |||||
| PERIOD = 14 ; columns from one pillar to the next | |||||
| SCORE_COL = 7 ; screen column checked for "pillar passed" | |||||
| ; game states | |||||
| ST_TITLE = 0 | |||||
| ST_PLAY = 1 | |||||
| ST_DEAD = 2 | |||||
| ; custom character codes (multicolor) | |||||
| CH_SKY = $20 | |||||
| CH_BL = $40 ; pillar body left / mid / right | |||||
| CH_BM = $41 | |||||
| CH_BR = $42 | |||||
| CH_CBL = $43 ; cap at bottom end of upper pillar | |||||
| CH_CBM = $44 | |||||
| CH_CBR = $45 | |||||
| CH_CTL = $46 ; cap at top end of lower pillar | |||||
| CH_CTM = $47 | |||||
| CH_CTR = $48 | |||||
| CH_G1 = $49 ; grass row | |||||
| CH_G2 = $4A | |||||
| CH_D1 = $4B ; dirt row | |||||
| CH_D2 = $4C | |||||
| ; ---------------------------------------------------------------- macros | |||||
| .macro SET_PTRS row, col, str | |||||
| lda #<(SCREEN+(row)*40+(col)) | |||||
| sta ptr | |||||
| lda #>(SCREEN+(row)*40+(col)) | |||||
| sta ptr+1 | |||||
| lda #<str | |||||
| sta ptr2 | |||||
| lda #>str | |||||
| sta ptr2+1 | |||||
| .endmacro | |||||
| .macro PRINT_AT row, col, str | |||||
| SET_PTRS row, col, str | |||||
| jsr print_hires | |||||
| .endmacro | |||||
| ; ---------------------------------------------------------------- zero page | |||||
| .segment "ZEROPAGE" | |||||
| ptr: .res 2 | |||||
| ptr2: .res 2 | |||||
| state: .res 1 | |||||
| frame_flag: .res 1 | |||||
| fine: .res 1 | |||||
| fine_cur: .res 1 ; read by the line-58 IRQ | |||||
| spr_y: .res 1 ; written to VIC by the IRQ | |||||
| spr_ptr: .res 1 | |||||
| ypos: .res 2 ; lo = fraction, hi = pixel | |||||
| vel: .res 2 | |||||
| fire_prev: .res 1 | |||||
| anim: .res 1 | |||||
| colphase: .res 1 | |||||
| colparity: .res 1 | |||||
| gap_top: .res 1 | |||||
| score_lo: .res 1 ; BCD, two lower digits | |||||
| score_hi: .res 1 ; BCD, hundreds digit | |||||
| best_lo: .res 1 | |||||
| best_hi: .res 1 | |||||
| timer: .res 1 | |||||
| sfx1_t: .res 1 | |||||
| sfx1_f: .res 1 | |||||
| tmp: .res 1 | |||||
| seed: .res 1 | |||||
| ; ---------------------------------------------------------------- BASIC stub | |||||
| .segment "LOADADDR" | |||||
| .word $0801 | |||||
| .segment "CODE" | |||||
| basic: .word basic_end, 10 ; 10 SYS 2061 | |||||
| .byte $9E, "2061", 0 | |||||
| basic_end: | |||||
| .word 0 | |||||
| ; =========================================================================== | |||||
| start: | |||||
| sei | |||||
| cld | |||||
| lda #$7F ; CIA interrupts off (no KERNAL keyscan) | |||||
| sta CIA1_ICR | |||||
| sta CIA2_ICR | |||||
| lda CIA1_ICR | |||||
| lda CIA2_ICR | |||||
| jsr copy_charset | |||||
| jsr copy_sprites | |||||
| jsr init_sid | |||||
| ; --- VIC setup | |||||
| lda #14 | |||||
| sta VIC_BORDER | |||||
| sta VIC_BG0 | |||||
| lda #13 ; %01 multicolor: light green | |||||
| sta VIC_BG1 | |||||
| lda #0 ; %10 multicolor: black outline | |||||
| sta VIC_BG2 | |||||
| lda #$1C ; screen $0400, charset $3000 | |||||
| sta VIC_MEM | |||||
| lda #$1B | |||||
| sta VIC_CTRL1 | |||||
| lda #$10 ; multicolor, 38 columns, xscroll 0 | |||||
| sta VIC_CTRL2 | |||||
| lda #BEE_X | |||||
| sta VIC_SPR0X | |||||
| lda #0 | |||||
| sta VIC_SPRXHI | |||||
| lda #1 | |||||
| sta VIC_SPREN | |||||
| sta VIC_SPRMC | |||||
| lda #0 | |||||
| sta VIC_SPRMC0 ; black | |||||
| lda #1 | |||||
| sta VIC_SPRMC1 ; white | |||||
| lda #7 | |||||
| sta VIC_SPR0COL ; yellow | |||||
| lda #0 | |||||
| sta best_lo | |||||
| sta best_hi | |||||
| sta frame_flag | |||||
| lda #$10 | |||||
| sta fire_prev ; require a fresh press | |||||
| ; --- raster IRQ | |||||
| lda #<irq_bottom | |||||
| sta IRQVEC | |||||
| lda #>irq_bottom | |||||
| sta IRQVEC+1 | |||||
| lda #251 | |||||
| sta VIC_RASTER | |||||
| lda #1 | |||||
| sta VIC_IRQEN | |||||
| lda #$FF | |||||
| sta VIC_IRQ | |||||
| jsr new_game | |||||
| cli | |||||
| ; =========================================================================== | |||||
| main_loop: | |||||
| lda frame_flag | |||||
| beq main_loop | |||||
| lda #0 | |||||
| sta frame_flag | |||||
| ; ---- scrolling (only while playing) | |||||
| lda state | |||||
| cmp #ST_PLAY | |||||
| bne @no_scroll | |||||
| dec fine | |||||
| bpl @fine_only | |||||
| lda #7 | |||||
| sta fine | |||||
| sta fine_cur ; must be set before raster line 58 | |||||
| jsr shift_screen | |||||
| jsr new_column | |||||
| jsr check_score | |||||
| jmp @no_scroll | |||||
| @fine_only: | |||||
| lda fine | |||||
| sta fine_cur | |||||
| @no_scroll: | |||||
| jsr read_fire ; A = 1 on a fresh press | |||||
| sta tmp | |||||
| .ifdef AUTOTEST ; test build: autostart + autopilot | |||||
| lda state | |||||
| cmp #ST_PLAY | |||||
| bne :+ | |||||
| lda #0 | |||||
| sta tmp | |||||
| lda ypos+1 | |||||
| cmp #140 | |||||
| bcc :+ | |||||
| lda vel+1 | |||||
| bmi :+ | |||||
| inc tmp | |||||
| : lda state | |||||
| bne :+ | |||||
| inc tmp | |||||
| : | |||||
| .endif | |||||
| lda state | |||||
| cmp #ST_TITLE | |||||
| beq do_title | |||||
| cmp #ST_PLAY | |||||
| beq do_play | |||||
| jmp do_dead | |||||
| ; ---------------------------------------------------------------- TITLE | |||||
| do_title: | |||||
| lda tmp | |||||
| beq @idle | |||||
| ; start the game | |||||
| jsr clear_playfield | |||||
| lda #ST_PLAY | |||||
| sta state | |||||
| lda anim ; seed the RNG from player timing | |||||
| ora #1 | |||||
| sta seed | |||||
| lda VIC_SBCOLL ; discard stale collisions | |||||
| jsr flap | |||||
| jmp frame_end | |||||
| @idle: | |||||
| jsr physics | |||||
| lda ypos+1 | |||||
| cmp #TITLE_BOB_Y | |||||
| bcc @noflap | |||||
| lda #<FLAP_VEL | |||||
| sta vel | |||||
| lda #>FLAP_VEL | |||||
| sta vel+1 | |||||
| @noflap: | |||||
| jmp frame_end | |||||
| ; ---------------------------------------------------------------- PLAY | |||||
| do_play: | |||||
| lda tmp | |||||
| beq @nofl | |||||
| jsr flap | |||||
| @nofl: | |||||
| jsr physics | |||||
| ; ceiling | |||||
| lda ypos+1 | |||||
| cmp #Y_CEIL | |||||
| bcs @below_ceil | |||||
| lda #Y_CEIL | |||||
| sta ypos+1 | |||||
| lda #0 | |||||
| sta ypos | |||||
| sta vel | |||||
| sta vel+1 | |||||
| @below_ceil: | |||||
| ; floor or pillar hit? | |||||
| lda ypos+1 | |||||
| cmp #Y_FLOOR | |||||
| bcs @die | |||||
| lda VIC_SBCOLL | |||||
| .ifdef INVINCIBLE | |||||
| lda #0 | |||||
| .endif | |||||
| and #1 | |||||
| beq frame_end | |||||
| @die: | |||||
| jsr kill_bee | |||||
| jmp frame_end | |||||
| ; ---------------------------------------------------------------- DEAD | |||||
| do_dead: | |||||
| jsr physics | |||||
| lda ypos+1 | |||||
| cmp #Y_FLOOR | |||||
| bcc @air | |||||
| lda #Y_FLOOR | |||||
| sta ypos+1 | |||||
| lda #0 | |||||
| sta ypos | |||||
| sta vel | |||||
| sta vel+1 | |||||
| @air: | |||||
| lda timer | |||||
| beq @ready | |||||
| dec timer | |||||
| bne @wait | |||||
| ; timer just expired: show game over | |||||
| PRINT_AT 9, 15, msg_over | |||||
| PRINT_AT 12, 10, msg_again | |||||
| @wait: | |||||
| jmp frame_end_noanim | |||||
| @ready: | |||||
| lda tmp | |||||
| beq @wait | |||||
| jsr new_game | |||||
| jmp frame_end | |||||
| ; ---------------------------------------------------------------- frame end | |||||
| frame_end: | |||||
| inc anim ; wing buzz | |||||
| lda anim | |||||
| lsr | |||||
| lsr | |||||
| and #1 | |||||
| ora #(SPRDATA/64) | |||||
| sta spr_ptr | |||||
| frame_end_noanim: | |||||
| lda ypos+1 | |||||
| sta spr_y | |||||
| jsr update_sfx | |||||
| jmp main_loop | |||||
| ; =========================================================================== | |||||
| ; Game helpers | |||||
| ; =========================================================================== | |||||
| new_game: | |||||
| lda #ST_TITLE | |||||
| sta state | |||||
| lda #0 | |||||
| sta score_lo | |||||
| sta score_hi | |||||
| sta fine | |||||
| sta fine_cur | |||||
| sta colphase | |||||
| sta ypos | |||||
| sta vel | |||||
| sta vel+1 | |||||
| lda #Y_START | |||||
| sta ypos+1 | |||||
| sta spr_y | |||||
| lda #(SPRDATA/64) | |||||
| sta spr_ptr | |||||
| jsr clear_playfield | |||||
| jsr draw_hud | |||||
| PRINT_AT 7, 19, msg_title | |||||
| PRINT_AT 10, 14, msg_sub | |||||
| PRINT_AT 13, 14, msg_ctrl | |||||
| rts | |||||
| flap: | |||||
| lda #<FLAP_VEL | |||||
| sta vel | |||||
| lda #>FLAP_VEL | |||||
| sta vel+1 | |||||
| ; flap sound: rising triangle chirp on voice 1 | |||||
| lda #$00 | |||||
| sta SID+4 | |||||
| lda #$06 | |||||
| sta SID+5 | |||||
| lda #$00 | |||||
| sta SID+6 | |||||
| lda #$14 | |||||
| sta sfx1_f | |||||
| sta SID+1 | |||||
| lda #$11 | |||||
| sta SID+4 | |||||
| lda #6 | |||||
| sta sfx1_t | |||||
| rts | |||||
| kill_bee: | |||||
| lda #ST_DEAD | |||||
| sta state | |||||
| lda #50 | |||||
| sta timer | |||||
| lda #0 | |||||
| sta sfx1_t | |||||
| sta vel | |||||
| sta vel+1 | |||||
| ; crunch: noise burst on voice 1 | |||||
| lda #$80 | |||||
| sta SID+4 | |||||
| lda #$0A | |||||
| sta SID+5 | |||||
| lda #$00 | |||||
| sta SID+6 | |||||
| lda #$08 | |||||
| sta SID+1 | |||||
| lda #$81 | |||||
| sta SID+4 | |||||
| ; new best? | |||||
| lda score_hi | |||||
| cmp best_hi | |||||
| bcc @done | |||||
| bne @newbest | |||||
| lda score_lo | |||||
| cmp best_lo | |||||
| bcc @done | |||||
| beq @done | |||||
| @newbest: | |||||
| lda score_lo | |||||
| sta best_lo | |||||
| lda score_hi | |||||
| sta best_hi | |||||
| jsr draw_hud | |||||
| @done: | |||||
| rts | |||||
| ; vel += GRAV (clamped), ypos += vel | |||||
| physics: | |||||
| ; apex hang: weaker gravity while |vel| is small (top of the arc) | |||||
| ldx #<GRAV | |||||
| clc | |||||
| lda vel | |||||
| adc #<HANG_WINDOW | |||||
| lda vel+1 | |||||
| adc #0 | |||||
| bne :+ ; vel outside [-HANG_WINDOW, HANG_WINDOW) | |||||
| ldx #<GRAV_HANG | |||||
| : txa | |||||
| clc | |||||
| adc vel | |||||
| sta vel | |||||
| lda vel+1 | |||||
| adc #0 ; both gravities are < 1.0 px/frame^2 | |||||
| sta vel+1 | |||||
| bmi @noclamp ; rising | |||||
| cmp #>MAX_FALL | |||||
| bcc @noclamp | |||||
| lda #<MAX_FALL | |||||
| sta vel | |||||
| lda #>MAX_FALL | |||||
| sta vel+1 | |||||
| @noclamp: | |||||
| clc | |||||
| lda ypos | |||||
| adc vel | |||||
| sta ypos | |||||
| lda ypos+1 | |||||
| adc vel+1 | |||||
| sta ypos+1 | |||||
| rts | |||||
| ; returns A=1 on a fresh press of fire (joy 1/2) or space | |||||
| read_fire: | |||||
| lda #$7F ; select keyboard column with SPACE | |||||
| sta CIA1_PRA | |||||
| lda CIA1_PRA ; joystick 2 | |||||
| and CIA1_PRB ; joystick 1 fire / space | |||||
| and #$10 | |||||
| eor #$10 ; $10 = pressed | |||||
| tax | |||||
| ldy fire_prev | |||||
| stx fire_prev | |||||
| cpx #$10 | |||||
| bne @none | |||||
| cpy #$10 | |||||
| beq @none | |||||
| lda #1 | |||||
| rts | |||||
| @none: | |||||
| lda #0 | |||||
| rts | |||||
| ; after a coarse scroll: did a pillar's right edge just pass the bee? | |||||
| check_score: | |||||
| lda SCREEN+40+SCORE_COL | |||||
| cmp #CH_BR | |||||
| bne @no | |||||
| sed | |||||
| clc | |||||
| lda score_lo | |||||
| adc #1 | |||||
| sta score_lo | |||||
| lda score_hi | |||||
| adc #0 | |||||
| and #$0F | |||||
| sta score_hi | |||||
| cld | |||||
| jsr draw_hud | |||||
| ; ding on voice 2 | |||||
| lda #$10 | |||||
| sta SID+7+4 | |||||
| lda #$09 | |||||
| sta SID+7+5 | |||||
| lda #$00 | |||||
| sta SID+7+6 | |||||
| lda #$00 | |||||
| sta SID+7+0 | |||||
| lda #$38 | |||||
| sta SID+7+1 | |||||
| lda #$11 | |||||
| sta SID+7+4 | |||||
| @no: | |||||
| rts | |||||
| update_sfx: | |||||
| lda sfx1_t | |||||
| beq @off | |||||
| dec sfx1_t | |||||
| bne @sweep | |||||
| lda #$10 ; gate off | |||||
| sta SID+4 | |||||
| rts | |||||
| @sweep: | |||||
| lda sfx1_f | |||||
| clc | |||||
| adc #$06 | |||||
| sta sfx1_f | |||||
| sta SID+1 | |||||
| @off: | |||||
| rts | |||||
| ; =========================================================================== | |||||
| ; Screen | |||||
| ; =========================================================================== | |||||
| ; coarse scroll: rows 1..24, columns 0..38 <- 1..39 (top to bottom) | |||||
| shift_screen: | |||||
| .repeat 24, R | |||||
| ldx #0 | |||||
| : lda SCREEN+(R+1)*40+1,x | |||||
| sta SCREEN+(R+1)*40,x | |||||
| inx | |||||
| cpx #39 | |||||
| bne :- | |||||
| .endrepeat | |||||
| rts | |||||
| ; fill column 39 of the playfield with the next slice of the world | |||||
| new_column: | |||||
| lda colphase | |||||
| bne @not_new | |||||
| ; a new pillar starts: choose the gap | |||||
| : jsr rand | |||||
| and #$0F | |||||
| cmp #12 | |||||
| bcs :- | |||||
| clc | |||||
| adc #3 ; gap_top = 3..14 | |||||
| sta gap_top | |||||
| @not_new: | |||||
| ldx colphase | |||||
| cpx #3 | |||||
| bcs @sky ; phases 3.. are open sky | |||||
| ; pillar column x (0=left,1=mid,2=right) | |||||
| lda #<(SCREEN+40+39) | |||||
| sta ptr | |||||
| lda #>(SCREEN+40+39) | |||||
| sta ptr+1 | |||||
| ldy #1 ; Y = screen row | |||||
| @row: | |||||
| tya | |||||
| sec | |||||
| sbc gap_top ; row - gap_top | |||||
| cmp #$FF | |||||
| beq @capb ; row = gap_top-1 | |||||
| cmp #GAP | |||||
| beq @capt ; row = gap_top+GAP | |||||
| bcc @gap ; gap_top <= row < gap_top+GAP | |||||
| lda body_chars,x | |||||
| bne @put | |||||
| @capb: lda capb_chars,x | |||||
| bne @put | |||||
| @capt: lda capt_chars,x | |||||
| bne @put | |||||
| @gap: lda #CH_SKY | |||||
| @put: sty tmp | |||||
| ldy #0 | |||||
| sta (ptr),y | |||||
| ldy tmp | |||||
| jsr ptr_next_row | |||||
| iny | |||||
| cpy #23 | |||||
| bne @row | |||||
| jmp @ground | |||||
| @sky: lda #CH_SKY | |||||
| sta SCREEN+40+39 | |||||
| sta SCREEN+40+39+40*1 | |||||
| sta SCREEN+40+39+40*2 | |||||
| sta SCREEN+40+39+40*3 | |||||
| sta SCREEN+40+39+40*4 | |||||
| sta SCREEN+40+39+40*5 | |||||
| sta SCREEN+40+39+40*6 | |||||
| sta SCREEN+40+39+40*7 | |||||
| sta SCREEN+40+39+40*8 | |||||
| sta SCREEN+40+39+40*9 | |||||
| sta SCREEN+40+39+40*10 | |||||
| sta SCREEN+40+39+40*11 | |||||
| sta SCREEN+40+39+40*12 | |||||
| sta SCREEN+40+39+40*13 | |||||
| sta SCREEN+40+39+40*14 | |||||
| sta SCREEN+40+39+40*15 | |||||
| sta SCREEN+40+39+40*16 | |||||
| sta SCREEN+40+39+40*17 | |||||
| sta SCREEN+40+39+40*18 | |||||
| sta SCREEN+40+39+40*19 | |||||
| sta SCREEN+40+39+40*20 | |||||
| sta SCREEN+40+39+40*21 | |||||
| @ground: | |||||
| lda colparity | |||||
| eor #1 | |||||
| sta colparity | |||||
| tax | |||||
| lda grass_chars,x | |||||
| sta SCREEN+23*40+39 | |||||
| lda dirt_chars,x | |||||
| sta SCREEN+24*40+39 | |||||
| inc colphase | |||||
| lda colphase | |||||
| cmp #PERIOD | |||||
| bcc :+ | |||||
| lda #0 | |||||
| sta colphase | |||||
| : rts | |||||
| ; 8-bit Galois LFSR, period 255 (seed must be non-zero) | |||||
| rand: | |||||
| lda seed | |||||
| asl | |||||
| bcc :+ | |||||
| eor #$1D | |||||
| : sta seed | |||||
| rts | |||||
| ptr_next_row: | |||||
| lda ptr | |||||
| clc | |||||
| adc #40 | |||||
| sta ptr | |||||
| bcc :+ | |||||
| inc ptr+1 | |||||
| : rts | |||||
| ; clear rows 1..22 to sky, draw ground, reset colors | |||||
| clear_playfield: | |||||
| ldx #0 | |||||
| @c: lda #CH_SKY | |||||
| sta SCREEN+40,x | |||||
| sta SCREEN+40+220,x | |||||
| sta SCREEN+40+440,x | |||||
| sta SCREEN+40+660,x ; rows 1..22 = 880 bytes, 4 x 220 | |||||
| lda #13 ; multicolor + green | |||||
| sta COLRAM+40,x | |||||
| sta COLRAM+40+220,x | |||||
| sta COLRAM+40+440,x | |||||
| sta COLRAM+40+660,x | |||||
| inx | |||||
| cpx #220 | |||||
| bne @c | |||||
| ldx #39 | |||||
| @g: txa | |||||
| and #1 | |||||
| tay | |||||
| lda grass_chars,y | |||||
| sta SCREEN+23*40,x | |||||
| lda dirt_chars,y | |||||
| sta SCREEN+24*40,x | |||||
| lda #15 ; multicolor + yellow | |||||
| sta COLRAM+23*40,x | |||||
| sta COLRAM+24*40,x | |||||
| lda #1 ; HUD row: hi-res white | |||||
| sta COLRAM,x | |||||
| dex | |||||
| bpl @g | |||||
| lda #1 | |||||
| sta colparity | |||||
| rts | |||||
| draw_hud: | |||||
| ldx #39 | |||||
| lda #CH_SKY | |||||
| : sta SCREEN,x | |||||
| dex | |||||
| bpl :- | |||||
| SET_PTRS 0, 1, msg_score | |||||
| jsr print_str | |||||
| SET_PTRS 0, 29, msg_best | |||||
| jsr print_str | |||||
| ; score digits at col 7 | |||||
| ldx #7 | |||||
| lda score_hi | |||||
| ldy score_lo | |||||
| jsr put_bcd3 | |||||
| ldx #34 | |||||
| lda best_hi | |||||
| ldy best_lo | |||||
| jsr put_bcd3 | |||||
| rts | |||||
| ; A = hundreds digit, Y = BCD tens/ones, X = column on row 0 | |||||
| put_bcd3: | |||||
| ora #'0' | |||||
| sta SCREEN,x | |||||
| tya | |||||
| lsr | |||||
| lsr | |||||
| lsr | |||||
| lsr | |||||
| ora #'0' | |||||
| sta SCREEN+1,x | |||||
| tya | |||||
| and #$0F | |||||
| ora #'0' | |||||
| sta SCREEN+2,x | |||||
| rts | |||||
| ; copy ASCII string at (ptr2) to (ptr) as screen codes; returns Y = length | |||||
| print_str: | |||||
| ldy #0 | |||||
| @l: lda (ptr2),y | |||||
| beq @d | |||||
| and #$3F | |||||
| sta (ptr),y | |||||
| iny | |||||
| bne @l | |||||
| @d: rts | |||||
| ; as print_str, then colour the cells yellow (hi-res, so text is readable | |||||
| ; inside the multicolor playfield) | |||||
| print_hires: | |||||
| jsr print_str | |||||
| lda ptr+1 | |||||
| pha | |||||
| clc | |||||
| adc #>(COLRAM-SCREEN) | |||||
| sta ptr+1 | |||||
| lda #7 | |||||
| @c: dey | |||||
| bmi @x | |||||
| sta (ptr),y | |||||
| jmp @c | |||||
| @x: pla | |||||
| sta ptr+1 | |||||
| rts | |||||
| ; =========================================================================== | |||||
| ; Init | |||||
| ; =========================================================================== | |||||
| copy_charset: | |||||
| lda #$33 ; char ROM visible at $D000 | |||||
| sta $01 | |||||
| ldx #0 | |||||
| : lda $D000,x | |||||
| sta CHARSET,x | |||||
| lda $D100,x | |||||
| sta CHARSET+$100,x | |||||
| lda $D200,x | |||||
| sta CHARSET+$200,x | |||||
| lda $D300,x | |||||
| sta CHARSET+$300,x | |||||
| inx | |||||
| bne :- | |||||
| lda #$37 | |||||
| sta $01 | |||||
| ldx #(custom_chars_end-custom_chars-1) | |||||
| : lda custom_chars,x | |||||
| sta CHARSET+CH_BL*8,x | |||||
| dex | |||||
| bpl :- | |||||
| rts | |||||
| copy_sprites: | |||||
| ldx #127 | |||||
| : lda bee_f1,x | |||||
| sta SPRDATA,x | |||||
| dex | |||||
| bpl :- | |||||
| rts | |||||
| init_sid: | |||||
| ldx #$18 | |||||
| lda #0 | |||||
| : sta SID,x | |||||
| dex | |||||
| bpl :- | |||||
| lda #$0F ; volume 15 | |||||
| sta SID+$18 | |||||
| rts | |||||
| ; =========================================================================== | |||||
| ; IRQs | |||||
| ; =========================================================================== | |||||
| irq_bottom: | |||||
| lda #$FF | |||||
| sta VIC_IRQ | |||||
| lda #$10 ; HUD row: no fine scroll | |||||
| sta VIC_CTRL2 | |||||
| lda spr_y | |||||
| sta VIC_SPR0Y | |||||
| lda spr_ptr | |||||
| sta SPRPTR | |||||
| inc frame_flag | |||||
| lda #<irq_top | |||||
| sta IRQVEC | |||||
| lda #>irq_top | |||||
| sta IRQVEC+1 | |||||
| lda #58 | |||||
| sta VIC_RASTER | |||||
| jmp KERNAL_IRQ_EXIT | |||||
| irq_top: | |||||
| lda #$FF | |||||
| sta VIC_IRQ | |||||
| lda fine_cur | |||||
| ora #$10 | |||||
| sta VIC_CTRL2 | |||||
| lda #<irq_bottom | |||||
| sta IRQVEC | |||||
| lda #>irq_bottom | |||||
| sta IRQVEC+1 | |||||
| lda #251 | |||||
| sta VIC_RASTER | |||||
| jmp KERNAL_IRQ_EXIT | |||||
| ; =========================================================================== | |||||
| ; Data | |||||
| ; =========================================================================== | |||||
| body_chars: .byte CH_BL, CH_BM, CH_BR | |||||
| capb_chars: .byte CH_CBL, CH_CBM, CH_CBR | |||||
| capt_chars: .byte CH_CTL, CH_CTM, CH_CTR | |||||
| grass_chars: .byte CH_G1, CH_G2 | |||||
| dirt_chars: .byte CH_D1, CH_D2 | |||||
| msg_score: .byte "SCORE", 0 | |||||
| msg_best: .byte "BEST", 0 | |||||
| msg_title: .byte "BUZZ RUN", 0 | |||||
| msg_sub: .byte "FLAP PAST THE HEDGES", 0 | |||||
| msg_ctrl: .byte "FIRE OR SPACE", 0 | |||||
| msg_over: .byte "GAME OVER", 0 | |||||
| msg_again: .byte "PRESS FIRE TO RETRY", 0 | |||||
| ; multicolor chars: %00 sky, %01 light green, %10 black, %11 colour RAM | |||||
| custom_chars: | |||||
| ; body L/M/R (inset one pixel on each side, narrower than the caps) | |||||
| .byte $27,$27,$27,$27,$27,$27,$27,$27 | |||||
| .byte $FF,$DF,$FF,$FF,$FF,$DF,$FF,$FF | |||||
| .byte $FA,$F8,$FA,$F8,$FA,$F8,$FA,$F8 | |||||
| ; cap at bottom of upper pillar L/M/R | |||||
| .byte $95,$95,$95,$95,$95,$95,$AA,$00 | |||||
| .byte $7F,$7F,$7F,$7F,$7F,$7F,$AA,$00 | |||||
| .byte $FE,$FE,$FE,$FE,$FE,$FE,$AA,$00 | |||||
| ; cap at top of lower pillar L/M/R | |||||
| .byte $00,$AA,$95,$95,$95,$95,$95,$95 | |||||
| .byte $00,$AA,$7F,$7F,$7F,$7F,$7F,$7F | |||||
| .byte $00,$AA,$FE,$FE,$FE,$FE,$FE,$FE | |||||
| ; grass 1/2 | |||||
| .byte $55,$55,$65,$AA,$FF,$FB,$FF,$BF | |||||
| .byte $55,$55,$56,$AA,$FF,$BF,$FF,$FB | |||||
| ; dirt 1/2 | |||||
| .byte $FF,$EF,$FF,$FE,$FF,$BF,$FF,$FF | |||||
| .byte $FF,$FF,$FB,$FF,$EF,$FF,$FF,$FE | |||||
| custom_chars_end: | |||||
| ; multicolor sprite: %01 black, %10 yellow, %11 white | |||||
| bee_f1: | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F3,$C0,$03,$FF,$F0,$03 | |||||
| .byte $FF,$F0,$00,$FF,$C0,$06,$9A,$50,$1A,$69,$A4,$6A,$69,$9D,$6A,$69 | |||||
| .byte $A9,$1A,$69,$A4,$06,$9A,$50,$01,$04,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| bee_f2: | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$06,$9A,$50,$FF,$F9,$A4,$FF,$FD,$9D,$3F,$F9 | |||||
| .byte $A9,$1F,$E9,$A4,$06,$9A,$50,$01,$04,$00,$00,$00,$00,$00,$00,$00 | |||||
| .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |||||
| code_end: | |||||
| .assert code_end <= SPRDATA, error, "program overlaps sprite data at $2000" | |||||
| @@ -0,0 +1,10 @@ | |||||
| MEMORY { | |||||
| ZP: start = $0002, size = $008E, type = rw, file = ""; | |||||
| LOADADDR: start = $07FF, size = $0002, file = %O; | |||||
| MAIN: start = $0801, size = $17FF, file = %O; | |||||
| } | |||||
| SEGMENTS { | |||||
| ZEROPAGE: load = ZP, type = zp; | |||||
| LOADADDR: load = LOADADDR, type = ro; | |||||
| CODE: load = MAIN, type = rw; | |||||
| } | |||||
| @@ -0,0 +1,30 @@ | |||||
| Modules list: | |||||
| ------------- | |||||
| buzzrun.o: | |||||
| CODE Offs=000000 Size=0007B7 Align=00001 Fill=0000 | |||||
| ZEROPAGE Offs=000000 Size=00001C Align=00001 Fill=0000 | |||||
| LOADADDR Offs=000000 Size=000002 Align=00001 Fill=0000 | |||||
| Segment list: | |||||
| ------------- | |||||
| Name Start End Size Align | |||||
| ---------------------------------------------------- | |||||
| ZEROPAGE 000002 00001D 00001C 00001 | |||||
| LOADADDR 0007FF 000800 000002 00001 | |||||
| CODE 000801 000FB7 0007B7 00001 | |||||
| Exports list by name: | |||||
| --------------------- | |||||
| Exports list by value: | |||||
| ---------------------- | |||||
| Imports list: | |||||
| ------------- | |||||
| @@ -0,0 +1,5 @@ | |||||
| @echo off | |||||
| setlocal | |||||
| set "VICE_EXE=C:\Program Files\GTK3VICE-3.10-win64\bin\x64sc.exe" | |||||
| if not exist "%~dp0buzzrun.prg" call "%~dp0build.bat" || exit /b 1 | |||||
| "%VICE_EXE%" -autostart "%~dp0buzzrun.prg" -autostartprgmode 1 | |||||
Powered by TurnKey Linux.