; SPDX-License-Identifier: MIT ; Big Top Bounce: an original paddle game for the Atari 2600. ; Copyright (c) 2026 alewman (see LICENSE). ; ; Assembled with ca65/ld65 (cc65 V2.18 - Git 5552824, as the binaries report; ; installed in a directory misnamed cc65-2.19). 16K F6 cartridge: ; bank 0 ($D000 link) game logic, sound, tables the logic uses ; bank 1 ($F000 link) the play kernel (HUD and the three floors) and its graphics ; bank 2 ($B000 link) the title kernel and its graphics ; bank 3 ($9000 link) unused ; Every bank ends with the same stubs (bank switching, vectors). ; Build flags: -D PAL50 (312-line PAL), -D PAL60 (262 lines, PAL colours), neither = NTSC. .setcpu "6502" .include "vcs.inc" ; --------------------------------------------------------------------------- ; Video timing. NTSC and PAL60: 3 VSYNC + 33 VBLANK + 196 kernel (4 set-up lines ; with VBLANK on, then 192 visible) + 30 overscan = 262 lines. PAL50 adds 25 lines ; of VBLANK and 25 of overscan: 312. The waits poll TIMINT D7 (set when the ; counter passes zero), so a late finish costs one line, which the line check ; catches, instead of a missed zero. MEASURED with tools/harness (`run`, every ; frame's line count): with the NTSC values the timer expiry can move from about ; 20 cycles earlier to 38 later (VBLANK) and 38 either way (overscan) before a ; frame changes length; the delays put the expiry in the middle of its line. ; PAL50 adds 1900 cycles to each section (25 lines). .ifndef VBTIM ; (-D overrides, for tuning) .ifdef PAL50 VBTIM = 67 VBDELAY = 62 OSTIM = 63 OSDELAY = 50 .else VBTIM = 38 VBDELAY = 18 OSTIM = 34 OSDELAY = 6 .endif .endif .include "colours.inc" .include "gen/chars.inc" ; --------------------------------------------------------------------------- ; Play-field geometry (see docs/design.md). HUDH = 22 ; HUD lines (score, status, set-up) PLAYH = 170 ; play-area lines; kernel line counter Y = PLAYH - line BH = 4 ; ball height in lines (2 colour clocks wide) XMIN = 16 ; ball's left edge range inside the walls XMAX = 142 BATTOP = 160 ; play line of the bat's top edge CEIL = 10 ; top floor: the roof's lower edge RELEASE_Y = 111 ; Y of line 59, where the paddle capacitor is released PADINIT = 112 ; Horizontal positions (MEASURED on our board by the first session's harness ; `calib` command, which was lost in a reboot; the bot's pixel probes re-check ; the bat, ball, clown, bumpers and balloon rows against RAM, see docs/design.md). PosObj puts a player at x - POS_KP + ... : callers pass ; x - POS_K so the object lands on x. POS_KP = 4 ; players through PosObj POS_KB = 2 ; the ball through PosObj SCORE_SLEEP = 37 ; HUD/title text: RESP0 written on cycle SCORE_SLEEP+2 SCORE_HM0 = $00 SCORE_HM1 = $10 BUMP_SLEEP = 34 ; middle floor bumpers (x = 44) BUMP_HM = $40 CTRL_REF = $15 ; reflect, PF above players, ball 2 clocks CTRL_NONREF = $14 ; Speed as power (2026-11-23; provisional, docs/design.md). Speed steps 0-7 (7 is ; the cap, the velocity table's last step). -D overrides, for tuning. .ifndef PUNCH_SPEED PUNCH_SPEED = 5 ; from this step the ball punches through balloons .endif .ifndef BUMP_MAX BUMP_MAX = 3 ; a bumper's speed-up stops at this step (kicks go higher) .endif ; game states ST_TITLE = 0 ST_SERVE = 1 ST_PLAY = 2 ST_LOST = 3 ST_OVER = 4 ; --------------------------------------------------------------------------- ; RAM ($80-$FF). The play kernel's temporaries share `dp` with the score ; pointers: they are written only after the score has been drawn. .segment "ZEROPAGE" frame: .res 1 rngLo: .res 1 rngHi: .res 1 gameState: .res 1 stateTimer: .res 1 gameNum: .res 1 ; 0-3 (shown as 1-4) twoPlayer: .res 1 ; 0 or 1 curPlayer: .res 1 ; 0 or 1 swOld: .res 1 ; SWCHB last frame btnOld: .res 1 ; paddle button last frame (1 = pressed) pStart: ; ---- the active player's block ---- score: .res 3 ; BCD, score+0 most significant balls: .res 1 ; balls left, including the one in play level: .res 1 cleared: .res 1 ; floors cleared this level (bits 0-2) bricks: .res 6 ; bottom floor, one byte per row (bit c = column c) balloons: .res 3 ; top floor rows: bits 0-2 P0 copies, bits 3-5 P1 copies drops: .res 1 ; middle floor drop targets pEnd: PBLK = pEnd - pStart stash: .res PBLK ; the other player's block ballXL: .res 1 ballX: .res 1 ballYL: .res 1 ballY: .res 1 vxL: .res 1 vxH: .res 1 vyL: .res 1 vyH: .res 1 floor: .res 1 ; 0 bottom, 1 middle, 2 top speed: .res 1 ; 0-7 cool: .res 1 ; collision cool-down frames batX: .res 1 padY: .res 1 kick: .res 1 ; kick timer batW: .res 1 ; 16 or 24 rowX: .res 3 ; balloon rows' x rowDirs: .res 1 ; bit r set: row r slides left balT: .res 1 ; fours of frames until the next empty balloon row drifts in (0 idle) dropT: .res 1 ; fours of frames until the drop targets are back (0 idle) multK: .res 1 ; this ball's score multiplier: (multiplier - 1) * 6, 0..24 clownX: .res 1 clownDir: .res 1 clownHit: .res 1 ; tumble timer flash: .res 1 ; bumper flash timer sfxPtr0: .res 2 sfxCnt0: .res 1 sfxPtr1: .res 2 sfxCnt1: .res 1 msgT: .res 1 ; message frames left msgIdx: .res 1 ; message offset in Messages kernelMode: .res 1 ; 0 play, 1 title ballK: .res 1 ; PLAYH-BH+1 - ballY: ball shows where Y-ballK < BH ballK2: .res 1 ; ballK+2 batCoarse: .res 1 batFine: .res 1 batPtr: .res 2 batCol: .res 1 pipsPF: .res 1 floorPF: .res 3 scoreCol: .res 1 clownTop: .res 1 ; clown frame's last table index bumpCol: .res 1 ballXpos: .res 1 ; ball x for the positioning routine clownXpos: .res 1 titleX: .res 1 ; title balloons' x dropPF: .res 5 ; middle floor drop-target row: PF1 L, PF2 L, PF0 R, PF1 R, PF2 R dp: .res 12 ; score digit pointers / kernel temporaries tmp: .res 1 row: .res 1 t0: .res 1 t1: .res 1 t2: .res 1 t3: .res 1 ; kernel temporaries inside dp (used after the score is drawn) tE1 = dp+0 tE2 = dp+1 v1L = dp+2 ; brick rows v2L = dp+3 v0R = dp+4 v1R = dp+5 v2R = dp+6 bc0 = dp+2 ; balloon rows bc1 = dp+3 bf0 = dp+4 bf1 = dp+5 bn0 = dp+6 bn1 = dp+7 bsum = dp+8 bcol = dp+9 ; the next balloon row's colour (HITCOL) ; --------------------------------------------------------------------------- ; Macros ; SLEEP n: burn n cycles (n >= 2) without touching registers or flags ; (BIT on a RAM byte changes flags; it is used only for odd counts and the ; macro is never placed between a compare and its branch). .macro SLEEP n .if n = 1 .error "SLEEP 1" .endif .if (n .mod 2) = 1 bit $80 .repeat (n-3)/2 nop .endrepeat .else .repeat n/2 nop .endrepeat .endif .endmacro ; GUARD n: if the next n bytes would cross a page, jump to the next page ; (3 cycles, placed where the line has room). Keeps timed loops' branches from ; taking the extra page-crossing cycle; the loops also assert it. .macro GUARD n .if (<*) + (n) > 256 jmp :+ .res (256 - <*) & $FF, $EA : .endif .endmacro ; KEXIT stub: the kernels' common exit, after their last visible line: ends that ; line, blanks, and returns to bank 0 at the same cycle from every kernel (the ; overscan timer starts from there). .macro KEXIT stub sta WSYNC lda #$82 sta VBLANK lda #0 sta ENABL sta GRP0 sta GRP1 sta PF0 sta PF1 sta PF2 sta COLUBK jmp stub .endmacro ; BALL: 16 cycles. ENABL for the current line from the line counter Y. .macro BALL tya sec sbc ballK cmp #BH lda #$FF adc #0 sta ENABL .endmacro ; BALLAT kv, dest: 16 cycles. ENABL value for a later line (kv = ballK2). .macro BALLAT kv, dest tya sec sbc kv cmp #BH lda #$FF adc #0 sta dest .endmacro ; BALLAT1 dest: 16 cycles. ENABL value for the next line: Y - ballK - 1, the 1 ; from the borrow of a clear carry (saves a RAM byte; same cycles as BALLAT). .macro BALLAT1 dest tya clc sbc ballK cmp #BH lda #$FF adc #0 sta dest .endmacro ; PADDLE9: 9 cycles on either path. While INPT0 D7 is still low (capacitor not ; yet charged, DOC: SPG "Dumped Input Ports"), remember this line's Y in padY. ; The $2C byte is BIT absolute: on the charged path it swallows `sty padY`. .macro PADDLE9 .local skip bit INPT0 bpl skip .byte $2C skip: sty padY .assert >(skip-1) = >skip, error, "PADDLE9 branch crosses a page" .endmacro .include "bands.inc" .include "play_low.s" .include "play_top.s" .include "title.s" .include "logic.s" .include "stubs.s"