From be94eef97211553f9aa85de93a7172e1ab178798 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Wed, 15 Jul 2026 22:29:08 +0200 Subject: [PATCH] colorized --- README.md | 3 ++ common.asm | 121 ++++++++++++++++++++++++++++++++++++++++++++--------- defs.asm | 18 ++++++++ main.asm | 22 +++++++--- over.asm | 21 ++++++++-- play.asm | 13 ++++++ title.asm | 18 +++++--- 7 files changed, 181 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 3c9976f..fe63eb4 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,9 @@ in the original. - PAL frame loop synced by polling the raster beam (no interrupts), one state update per frame — title, play and game over are `updvec` states. +- The background is raster-split at the horizon: sky above, grass below. + The road is a grey wedge of inverse-space characters between painted + white edge lines, with trees along both shoulders. - The player is hardware sprite 0; up to seven rabbits live on sprites 1–7. Rabbits follow the road's perspective: a linear y ramp and a t² horizontal fan-out, both precomputed into tables at assembly time diff --git a/common.asm b/common.asm index 1a781f7..70c56c9 100644 --- a/common.asm +++ b/common.asm @@ -46,47 +46,126 @@ pt_loop: bne pt_loop rts -; ---- the road: two diagonals from the horizon apex down to -; the screen corners, plus a tree on the left shoulder ---- -draw_road: - ldx #0 -dr_loop: - txa - clc - adc #6 ; road runs from char row 6 to row 24 - tay - lda mul40lo,y +; ---- set scrlo/hi + collo/hi to the start of char row X ---- +row_ptr: + lda mul40lo,x sta scrlo - lda mul40hi,y + sta collo + lda mul40hi,x clc adc #>SCREEN sta scrhi + clc + adc #$d4 ; COLRAM - SCREEN high byte distance + sta colhi + rts + +; ---- the road: grey surface between two painted edge lines, +; from the horizon apex down to the screen corners, then the +; trees along both shoulders ---- +draw_road: + ldx #0 +dr_loop: stx drtmp + txa + clc + adc #6 ; road runs from char row 6 to row 24 + tax + jsr row_ptr lda #19 ; left edge: one column left per row sec sbc drtmp tay + sty drleft lda #$4e ; '/' diagonal sta (scrlo),y + lda #COL_EDGE + sta (collo),y lda #20 ; right edge: one column right per row clc adc drtmp tay lda #$4d ; '\' diagonal sta (scrlo),y + lda #COL_EDGE + sta (collo),y + dey ; fill the surface between the edges +dr_fill: + cpy drleft + beq dr_rowdone + lda #$a0 ; inverse space: solid block + sta (scrlo),y + lda #COL_ROAD + sta (collo),y + dey + jmp dr_fill +dr_rowdone: + ldx drtmp inx cpx #19 bne dr_loop - ; tree on the left shoulder - lda #$51 ; ball - sta SCREEN+10*40+3 - sta SCREEN+11*40+2 - sta SCREEN+11*40+3 - sta SCREEN+11*40+4 - lda #$5d ; trunk - sta SCREEN+12*40+3 +; falls through: the roadside trees +draw_trees: + lda #0 + sta ttidx +dt_loop: + ldx ttidx + lda tree_tbl,x + sta trow + lda tree_tbl+1,x + sta tcol + jsr draw_tree + inc ttidx + inc ttidx + lda ttidx + cmp #NTREES*2 + bne dt_loop rts +; ---- one tree: crown of balls on trow, top ball above, +; trunk below (trow/tcol = middle row, left column) ---- +draw_tree: + ldx trow + dex + jsr row_ptr + ldy tcol + iny + jsr tree_ball + ldx trow + jsr row_ptr + ldy tcol + jsr tree_ball + iny + jsr tree_ball + iny + jsr tree_ball + ldx trow + inx + jsr row_ptr + ldy tcol + iny + lda #$5d ; trunk + sta (scrlo),y + lda #BROWN + sta (collo),y + rts + +tree_ball: + lda #$51 ; foliage ball + sta (scrlo),y + lda #LGREEN + sta (collo),y + rts + +NTREES = 6 +tree_tbl: ; middle row, left column - far trees sit + !byte 9, 4 ; higher and closer to the road + !byte 14, 6 + !byte 19, 3 + !byte 8, 31 + !byte 12, 34 + !byte 17, 36 + ; ---- input ---- ; read joystick port 2 merged with the a/d keys, @@ -488,6 +567,10 @@ rowidx: !byte 0 bitcnt: !byte 0 curbits: !byte 0 drtmp: !byte 0 ; draw_road internals +drleft: !byte 0 +ttidx: !byte 0 ; draw_trees internals +trow: !byte 0 +tcol: !byte 0 rslot: !byte 0 ; rab_pos internals rt: !byte 0 rlane: !byte 0 diff --git a/defs.asm b/defs.asm index 7fbf802..7c06d1b 100644 --- a/defs.asm +++ b/defs.asm @@ -28,8 +28,25 @@ SPR_COL = $d027 ; sprite 0 color, +1 = sprite 1, ... ; ---- colors ---- BLACK = 0 WHITE = 1 +RED = 2 +CYAN = 3 +GREEN = 5 +BLUE = 6 +YELLOW = 7 +ORANGE = 8 +BROWN = 9 +DGREY = 11 +MGREY = 12 +LGREEN = 13 +LBLUE = 14 LGREY = 15 +; ---- scene palette ---- +COL_SKY = LBLUE ; background above the horizon +COL_GRASS = GREEN ; background below it +COL_ROAD = MGREY ; road surface (inverse-space fill) +COL_EDGE = WHITE ; painted road edge lines + ; ---- joystick port 2 bits (after read_joy, active high) ---- JOY_LEFT = 4 JOY_RIGHT = 8 @@ -46,6 +63,7 @@ T_EXP = 192 ; ... and where the sprite gets double-sized REP_HOLD = 12 ; frames before a held direction auto-repeats REP_PERIOD = 6 ; frames between auto-repeat steps RAS_SYNC = 251 ; raster line polled for the frame sync +RAS_SPLIT = 97 ; horizon line: sky/grass background split ; ---- zero page pointers (same slots as the c64-demo) ---- txtlo = $f5 ; text pointer for the print routines (2 bytes) diff --git a/main.asm b/main.asm index 7a8e3bd..866a811 100644 --- a/main.asm +++ b/main.asm @@ -37,19 +37,21 @@ start: sei ; no KERNAL IRQ - raster polling must not jitter - ; LCD look: black bezel border, pale screen, black artwork + ; sunny scene: black frame, sky above the horizon split lda #BLACK sta BORDER - lda #LGREY + lda #COL_SKY sta BG - ; sprites: all black, hires, in front of the characters + ; sprites: red scooter, white rabbits, hires, in front + lda #RED + sta SPR_COL ldx #7 sprcol: - lda #BLACK + lda #WHITE sta SPR_COL,x dex - bpl sprcol + bne sprcol lda #0 sta SPR_EN sta SPR_MC @@ -72,9 +74,17 @@ sprcol: ; ============================================================ main: jsr wait_frame + lda #COL_SKY ; repaint the sky while the beam is off screen + sta BG inc framectr jsr rand8 ; stir the RNG once per frame - jsr call_update + jsr call_update ; finishes long before the horizon line +wait_grass: + lda RASTER ; split the background at the horizon: + cmp #RAS_SPLIT ; sky above, grass below + bne wait_grass + lda #COL_GRASS + sta BG jmp main call_update: diff --git a/over.asm b/over.asm index 5f182aa..42116a6 100644 --- a/over.asm +++ b/over.asm @@ -26,18 +26,27 @@ oi_row: lda mul40hi,y adc #>SCREEN sta scrhi + sta colhi ; color RAM pointer for the same cells + lda scrlo + sta collo + lda colhi + clc + adc #$d4 + sta colhi ldy #BOXW-1 oi_col: jsr box_char sta (scrlo),y + lda #WHITE + sta (collo),y dey bpl oi_col inx cpx #5 bne oi_row - +prtext BOXROW+1, 15, BLACK, txt_over, 9 - +prtext BOXROW+2, 15, BLACK, txt_score, 5 + +prtext BOXROW+1, 15, WHITE, txt_over, 9 + +prtext BOXROW+2, 15, WHITE, txt_score, 5 ; final score digits next to the label lda sc_d0 @@ -49,6 +58,10 @@ oi_col: lda sc_d2 ora #48 sta SCREEN+(BOXROW+2)*40+23 + lda #YELLOW + sta COLRAM+(BOXROW+2)*40+21 + sta COLRAM+(BOXROW+2)*40+22 + sta COLRAM+(BOXROW+2)*40+23 +setupd over_update rts @@ -100,10 +113,10 @@ over_update: lda framectr and #32 bne ou_hide - +prtext BOXROW+3, 14, BLACK, txt_retry, 12 + +prtext BOXROW+3, 14, YELLOW, txt_retry, 12 jmp ou_start ou_hide: - +prtext BOXROW+3, 14, BLACK, txt_blank, 12 + +prtext BOXROW+3, 14, YELLOW, txt_blank, 12 ou_start: jsr start_edge beq ou_done diff --git a/play.asm b/play.asm index 1b2e38f..c500144 100644 --- a/play.asm +++ b/play.asm @@ -35,6 +35,17 @@ pi_clr: lda #2 ; start in the middle lane sta player_lane + ; sprite colors back to red scooter + white rabbits + ; (the title borrows sprites 1-4 as red scooters) + ldx #7 +pi_col: + lda #WHITE + sta SPR_COL,x + dex + bne pi_col + lda #RED + sta SPR_COL + ; player sprite: scooter, fixed row, rabbits come per frame lda #SPRP_SCOOT sta SPRPTR @@ -266,6 +277,8 @@ add_miss: ldy miss ; Y: the rabbit loop still needs X lda #24 ; 'x' sta SCREEN+34,y ; marks land on columns 35-37 + lda #RED + sta COLRAM+34,y lda #12 sta flash rts diff --git a/title.asm b/title.asm index a2f3c81..f53ef9c 100644 --- a/title.asm +++ b/title.asm @@ -8,11 +8,17 @@ title_init: jsr clear_screen jsr draw_road - +prbig 1, 8, BLACK, txt_rabbit, 6 - +prtext 6, 16, BLACK, txt_scooter, 7 - +prtext 17, 4, BLACK, txt_info, 31 + +prbig 1, 8, RED, txt_rabbit, 6 + +prtext 6, 16, WHITE, txt_scooter, 7 + +prtext 17, 4, WHITE, txt_info, 31 - ; one parked scooter per lane on sprites 0-4 + ; one parked scooter per lane on sprites 0-4, all in red + ldx #4 +ti_col: + lda #RED + sta SPR_COL,x + dex + bne ti_col ldx #4 ti_scoot: txa @@ -80,10 +86,10 @@ tu_pos: lda framectr and #32 bne tu_hide - +prtext 15, 10, BLACK, txt_press, 19 + +prtext 15, 10, YELLOW, txt_press, 19 jmp tu_start tu_hide: - +prtext 15, 10, BLACK, txt_blank, 19 + +prtext 15, 10, YELLOW, txt_blank, 19 tu_start: jsr start_edge beq tu_done