c64-basic/ripple-chamber/ripple-chamber.asm

440 lines
14 KiB
NASM

!cpu 6510
; Original multicolor pixel tiles. No ROM/PETSCII glyphs in the running scene.
; Screen buffers at $0400/$0c00, custom charset at $2000.
*=$0801
!word basic_end,10
!byte $9e
!text "4096"
!byte 0
basic_end: !word 0
*=$1000
start:
ldx #6
save_vic:
lda $d020,x
sta old_colors,x
dex
bpl save_vic
lda $d018
sta old_layout
lda $d016
sta old_scroll
lda $dd00
sta old_bank
lda $d015
sta old_sprites
lda #0
sta $d020
sta $d021
lda #147
jsr $ffd2
lda #<splash
sta $fb
lda #>splash
sta $fc
print:
ldy #0
lda ($fb),y
beq wait_space
jsr $ffd2
inc $fb
bne print
inc $fc
jmp print
wait_space:
jsr $ffe4
cmp #32
bne wait_space
lda old_bank
ora #3
sta $dd00
lda #0
sta $d015
lda #$18
sta $d016
lda #$18
sta $d018
lda #6
sta $d022
lda #14
sta $d023
ldx #0
color_loop:
lda #10
sta $d800,x
sta $d900,x
sta $da00,x
sta $db00,x
inx
bne color_loop
jsr render
jsr flip
loop:
jsr $ffe4
cmp #81
bne not_quit
jmp exit
not_quit:
cmp #32
bne not_pause
lda paused
eor #1
sta paused
not_pause:
cmp #67
bne not_color
inc palette
lda palette
and #3
tax
lda color_a,x
sta $d022
lda color_b,x
sta $d023
not_color:
cmp #49
bne not_one
lda #1
sta speed
not_one:
cmp #50
bne not_two
lda #2
sta speed
not_two:
cmp #51
bne not_three
lda #3
sta speed
not_three:
lda paused
bne loop
lda phase
clc
adc speed
and #31
sta phase
jsr render
jsr flip
jmp loop
; Build all 1000 cells off screen. Fixed color RAM avoids visible color tearing.
render:
lda #<field
sta $fb
lda #>field
sta $fc
lda #0
sta $fd
lda back_hi
sta $fe
ldx #4
ldy #0
render_cell:
lda ($fb),y
sta cell
and #31
clc
adc phase
and #31
sta value
lda cell
and #$e0
ora value
sta ($fd),y
iny
bne check_end
inc $fc
inc $fe
dex
check_end:
cpx #1
bne render_cell
cpy #232
bne render_cell
rts
flip:
; Flip only in the lower border, on both PAL and NTSC.
lda #250
wait_enter:
cmp $d012
bne wait_enter
lda back_hi
cmp #12
beq show_second
lda #$18
sta $d018
lda #12
sta back_hi
rts
show_second:
lda #$38
sta $d018
lda #4
sta back_hi
rts
exit:
lda old_bank
sta $dd00
lda old_layout
sta $d018
lda old_scroll
sta $d016
lda old_sprites
sta $d015
ldx #6
restore_colors:
lda old_colors,x
sta $d020,x
dex
bpl restore_colors
lda #147
jsr $ffd2
rts
phase: !byte 0
speed: !byte 1
paused: !byte 0
palette: !byte 0
back_hi: !byte 12
cell: !byte 0
value: !byte 0
old_layout: !byte 0
old_scroll: !byte 0
old_bank: !byte 0
old_sprites: !byte 0
old_colors: !fill 7,0
color_a: !byte 6,2,9,11
color_b: !byte 14,8,7,3
splash:
!byte 13,13,13,154
!text " RIPPLE CHAMBER"
!byte 13,13,5
!text " TWO WAVES MEET IN A ROOM OF LIGHT"
!byte 13,13,13,153
!text " CONTROLS"
!byte 13,13,158
!text " 1-3"
!byte 5
!text " SPEED "
!byte 158
!text "C"
!byte 5
!text " PALETTE"
!byte 13,158
!text " SPACE"
!byte 5
!text " PAUSE "
!byte 158
!text "Q"
!byte 5
!text " QUIT"
!byte 13,13,13,5
!text " HTTPS://C64.P20.DEV"
!byte 13,13,152
!text " RELEASED 29 OCTOBER 2026"
!byte 13,13,13,158
!text " PRESS SPACE TO START"
!byte 0
*=$2000
; 8 directions x 32 phases x 8 bytes, 4 multicolor pixels per row.
charset:
!byte 85,85,85,85,85,85,85,85,90,90,90,90,90,90,90,90
!byte 106,106,106,106,106,106,106,106,170,170,170,170,170,170,170,170
!byte 171,171,171,171,171,171,171,171,175,175,175,175,175,175,175,175
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,250,250,250,250,250,250,250,250
!byte 234,234,234,234,234,234,234,234,170,170,170,170,170,170,170,170
!byte 169,169,169,169,169,169,169,169,165,165,165,165,165,165,165,165
!byte 85,85,85,85,85,85,85,85,84,84,84,84,84,84,84,84
!byte 80,80,80,80,80,80,80,80,64,64,64,64,64,64,64,64
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1
!byte 5,5,5,5,5,5,5,5,21,21,21,21,21,21,21,21
!byte 21,21,85,85,86,86,90,90,85,85,86,86,90,90,106,106
!byte 86,90,90,106,106,170,170,170,90,106,106,170,170,171,171,175
!byte 170,170,170,171,171,175,175,191,171,171,175,175,191,191,255,255
!byte 175,175,191,191,255,255,255,255,191,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254
!byte 255,255,255,255,254,254,250,250,255,255,254,254,250,250,234,234
!byte 254,250,250,234,234,170,170,170,250,234,234,170,170,169,169,165
!byte 170,170,170,169,169,165,165,149,169,169,165,165,149,149,85,85
!byte 165,165,149,149,85,85,84,84,149,85,85,85,84,84,80,80
!byte 85,84,84,80,80,64,64,0,84,80,80,64,64,0,0,0
!byte 64,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,1,1,0,0,0,1,1,5,5,21
!byte 0,1,1,5,5,21,21,85,5,5,21,21,85,85,85,86
!byte 85,85,85,85,85,85,85,170,85,85,85,85,85,170,170,170
!byte 85,85,170,170,170,170,170,170,170,170,170,170,170,170,170,170
!byte 170,170,170,170,170,170,255,255,170,170,170,255,255,255,255,255
!byte 170,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,170,255,255,255,255,255,170,170,170
!byte 255,255,170,170,170,170,170,170,170,170,170,170,170,170,170,170
!byte 170,170,170,170,170,170,85,85,170,170,170,85,85,85,85,85
!byte 170,85,85,85,85,85,85,85,85,85,85,85,85,85,85,0
!byte 85,85,85,85,0,0,0,0,85,85,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,85
!byte 0,0,0,0,85,85,85,85,0,85,85,85,85,85,85,85
!byte 84,84,85,85,149,149,165,165,85,85,149,149,165,165,169,169
!byte 149,165,165,169,169,170,170,170,165,169,169,170,170,234,234,250
!byte 170,170,170,234,234,250,250,254,234,234,250,250,254,254,255,255
!byte 250,250,254,254,255,255,255,255,254,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,191
!byte 255,255,255,255,191,191,175,175,255,255,191,191,175,175,171,171
!byte 191,175,175,171,171,170,170,170,175,171,171,170,170,106,106,90
!byte 170,170,170,106,106,90,90,86,106,106,90,90,86,86,85,85
!byte 90,90,86,86,85,85,21,21,86,85,85,85,21,21,5,5
!byte 85,21,21,5,5,1,1,0,21,5,5,1,1,0,0,0
!byte 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,64,64,0,0,0,64,64,80,80,84
!byte 0,64,64,80,80,84,84,85,80,80,84,84,85,85,85,149
!byte 85,85,85,85,85,85,85,85,165,165,165,165,165,165,165,165
!byte 169,169,169,169,169,169,169,169,170,170,170,170,170,170,170,170
!byte 234,234,234,234,234,234,234,234,250,250,250,250,250,250,250,250
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,175,175,175,175,175,175,175,175
!byte 171,171,171,171,171,171,171,171,170,170,170,170,170,170,170,170
!byte 106,106,106,106,106,106,106,106,90,90,90,90,90,90,90,90
!byte 85,85,85,85,85,85,85,85,21,21,21,21,21,21,21,21
!byte 5,5,5,5,5,5,5,5,1,1,1,1,1,1,1,1
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,64,64,64,64,64,64,64,64
!byte 80,80,80,80,80,80,80,80,84,84,84,84,84,84,84,84
!byte 165,165,149,149,85,85,84,84,169,169,165,165,149,149,85,85
!byte 170,170,170,169,169,165,165,149,250,234,234,170,170,169,169,165
!byte 254,250,250,234,234,170,170,170,255,255,254,254,250,250,234,234
!byte 255,255,255,255,254,254,250,250,255,255,255,255,255,255,255,254
!byte 255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255
!byte 175,175,191,191,255,255,255,255,171,171,175,175,191,191,255,255
!byte 170,170,170,171,171,175,175,191,90,106,106,170,170,171,171,175
!byte 86,90,90,106,106,170,170,170,85,85,86,86,90,90,106,106
!byte 21,21,85,85,86,86,90,90,5,5,21,21,85,85,85,86
!byte 0,1,1,5,5,21,21,85,0,0,0,1,1,5,5,21
!byte 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 64,64,0,0,0,0,0,0,84,80,80,64,64,0,0,0
!byte 85,84,84,80,80,64,64,0,149,85,85,85,84,84,80,80
!byte 170,85,85,85,85,85,85,85,170,170,170,85,85,85,85,85
!byte 170,170,170,170,170,170,85,85,170,170,170,170,170,170,170,170
!byte 255,255,170,170,170,170,170,170,255,255,255,255,255,170,170,170
!byte 255,255,255,255,255,255,255,170,255,255,255,255,255,255,255,255
!byte 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
!byte 170,255,255,255,255,255,255,255,170,170,170,255,255,255,255,255
!byte 170,170,170,170,170,170,255,255,170,170,170,170,170,170,170,170
!byte 85,85,170,170,170,170,170,170,85,85,85,85,85,170,170,170
!byte 85,85,85,85,85,85,85,170,0,85,85,85,85,85,85,85
!byte 0,0,0,0,85,85,85,85,0,0,0,0,0,0,85,85
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,85,85,0,0,0,0,0,0
!byte 85,85,85,85,0,0,0,0,85,85,85,85,85,85,85,0
!byte 90,90,86,86,85,85,21,21,106,106,90,90,86,86,85,85
!byte 170,170,170,106,106,90,90,86,175,171,171,170,170,106,106,90
!byte 191,175,175,171,171,170,170,170,255,255,191,191,175,175,171,171
!byte 255,255,255,255,191,191,175,175,255,255,255,255,255,255,255,191
!byte 255,255,255,255,255,255,255,255,254,255,255,255,255,255,255,255
!byte 250,250,254,254,255,255,255,255,234,234,250,250,254,254,255,255
!byte 170,170,170,234,234,250,250,254,165,169,169,170,170,234,234,250
!byte 149,165,165,169,169,170,170,170,85,85,149,149,165,165,169,169
!byte 84,84,85,85,149,149,165,165,80,80,84,84,85,85,85,149
!byte 0,64,64,80,80,84,84,85,0,0,0,64,64,80,80,84
!byte 0,0,0,0,0,0,64,64,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!byte 1,1,0,0,0,0,0,0,21,5,5,1,1,0,0,0
!byte 85,21,21,5,5,1,1,0,86,85,85,85,21,21,5,5
*=$3000
; Elliptical distance field and local gradient direction, generated offline.
field:
!byte 183,181,180,178,176,175,173,172,171,170,168,167,167,198,197,197
!byte 196,196,196,196,196,196,196,196,197,197,198,231,231,232,234,235
!byte 236,237,239,240,242,244,245,247,182,180,178,176,175,173,172,170
!byte 169,168,166,165,165,196,195,194,194,194,193,193,193,193,194,194
!byte 194,195,196,229,229,230,232,233,234,236,237,239,240,242,244,246
!byte 180,178,177,175,173,171,170,168,167,166,165,163,163,162,193,192
!byte 192,192,223,223,223,223,192,192,192,193,226,227,227,229,230,231
!byte 232,234,235,237,239,241,242,244,179,177,175,173,172,170,168,167
!byte 165,164,163,162,161,160,223,222,222,222,221,221,221,221,222,222
!byte 222,223,224,225,226,227,228,229,231,232,234,236,237,239,241,243
!byte 178,176,174,172,170,168,167,165,163,162,161,160,191,190,221,220
!byte 220,220,219,219,219,219,220,220,220,221,254,255,224,225,226,227
!byte 229,231,232,234,236,238,240,242,177,175,173,171,169,167,165,163
!byte 162,160,191,190,189,188,219,219,218,218,218,218,218,218,218,218
!byte 219,219,252,253,254,255,224,226,227,229,231,233,235,237,239,241
!byte 144,174,172,170,168,166,164,162,160,191,189,188,187,186,217,217
!byte 216,216,216,216,216,216,216,216,217,217,250,251,252,253,255,224
!byte 226,228,230,232,234,236,238,16,143,141,139,169,166,164,162,161
!byte 191,189,188,186,185,184,216,215,215,215,214,214,214,214,215,215
!byte 215,216,248,249,250,252,253,255,225,226,228,230,233,11,13,15
!byte 142,140,138,136,133,163,161,191,189,188,186,185,184,183,214,214
!byte 213,213,213,213,213,213,213,213,214,214,247,248,249,250,252,253
!byte 255,225,227,5,8,10,12,14,142,139,137,135,133,131,128,190
!byte 188,186,185,183,182,181,213,212,212,212,212,212,212,212,212,212
!byte 212,213,245,246,247,249,250,252,254,0,3,5,7,9,11,14
!byte 141,139,137,134,132,130,128,157,155,185,183,182,181,180,212,211
!byte 211,211,211,211,211,211,211,211,211,212,244,245,246,247,249,27
!byte 29,0,2,4,6,9,11,13,141,139,136,134,132,129,159,157
!byte 155,152,150,180,179,211,211,211,211,211,211,211,211,211,211,211
!byte 211,211,211,243,244,22,24,27,29,31,1,4,6,8,11,13
!byte 141,139,136,134,132,129,159,157,154,152,150,148,18,18,18,18
!byte 18,18,18,18,18,18,18,18,18,18,18,18,20,22,24,26
!byte 29,31,1,4,6,8,11,13,141,139,136,134,132,129,159,157
!byte 155,152,150,116,115,83,83,83,83,83,83,83,83,83,83,83
!byte 83,83,83,51,52,22,24,27,29,31,1,4,6,8,11,13
!byte 141,139,137,134,132,130,128,157,155,121,119,118,117,116,84,83
!byte 83,83,83,83,83,83,83,83,83,84,52,53,54,55,57,27
!byte 29,0,2,4,6,9,11,13,142,139,137,135,133,131,128,126
!byte 124,122,121,119,118,117,85,84,84,84,84,84,84,84,84,84
!byte 84,85,53,54,55,57,58,60,62,0,3,5,7,9,11,14
!byte 142,140,138,136,133,99,97,127,125,124,122,121,120,119,86,86
!byte 85,85,85,85,85,85,85,85,86,86,55,56,57,58,60,61
!byte 63,33,35,5,8,10,12,14,143,141,139,105,102,100,98,97
!byte 127,125,124,122,121,120,88,87,87,87,86,86,86,86,87,87
!byte 87,88,56,57,58,60,61,63,33,34,36,38,41,11,13,15
!byte 144,110,108,106,104,102,100,98,96,127,125,124,123,122,89,89
!byte 88,88,88,88,88,88,88,88,89,89,58,59,60,61,63,32
!byte 34,36,38,40,42,44,46,16,113,111,109,107,105,103,101,99
!byte 98,96,127,126,125,124,91,91,90,90,90,90,90,90,90,90
!byte 91,91,60,61,62,63,32,34,35,37,39,41,43,45,47,49
!byte 114,112,110,108,106,104,103,101,99,98,97,96,127,126,93,92
!byte 92,92,91,91,91,91,92,92,92,93,62,63,32,33,34,35
!byte 37,39,40,42,44,46,48,50,115,113,111,109,108,106,104,103
!byte 101,100,99,98,97,96,95,94,94,94,93,93,93,93,94,94
!byte 94,95,32,33,34,35,36,37,39,40,42,44,45,47,49,51
!byte 116,114,113,111,109,107,106,104,103,102,101,99,99,98,65,64
!byte 64,64,95,95,95,95,64,64,64,65,34,35,35,37,38,39
!byte 40,42,43,45,47,49,50,52,118,116,114,112,111,109,108,106
!byte 105,104,102,101,101,68,67,66,66,66,65,65,65,65,66,66
!byte 66,67,68,37,37,38,40,41,42,44,45,47,48,50,52,54
!byte 119,117,116,114,112,111,109,108,107,106,104,103,103,70,69,69
!byte 68,68,68,68,68,68,68,68,69,69,70,39,39,40,42,43
!byte 44,45,47,48,50,52,53,55