;Clowns (Midway, 1978) - hardware map, RAM variables and equates for
;clowns_program_rom.asm (MAME 'clowns', rev. 2).
;No original source is known: all names were given for this disassembly.
;Hardware notes follow the MAME driver mw8080bw.cpp.
;Generated by disasm/emit_defines.py; every symbol the program listing uses is here.

;----------------------------------[ Memory map ]----------------------------------
.alias ProgramRom       $00      ;Through $17FF. Six 1K ROMs H G F E D C (clowns_program_rom.asm).
.alias WorkRam          $2000    ;Through $23FF. Variables; the 8080 stack grows down from $2400.
.alias VideoRam         $2400    ;Through $3FFF. 256 x 224 bitmap, 32 bytes per line, bit 0 = leftmost pixel. Address = $2400 + 32*Y + X/8.
.alias EmptyRomSpace    $4000    ;Through $5FFF. The board's second ROM area, not fitted on Clowns: writes are ignored. A splatted clown sinking below line 223 is drawn into it.
.alias RamMirror        $6000    ;Through $7FFF. $2000-$3FFF again (only 15 address bits are decoded). Not used.

;----------------------------------[ Input ports ]----------------------------------
;8080 I/O space (IN). Port numbers repeat every 4.
.alias INP_PADDLE       $00      ;IN0. Paddle position 0-255 of the player selected by OUT_MISC bit 1.
.alias INP_SWITCH       $01      ;IN1, active low. b4 2-player start, b5 1-player start, b6 coin.
.alias INP_DIP          $02      ;IN2. b0-b1 coinage (0 1C/1P, 1 1C/2P, 2 2C/2P, 3 2C/1P), b2-b3 bonus game (0 none, 9000, 11000, 13000), b4 balloon resets (0 each row, 1 all rows), b5 extra jump at 3000/4000, b6 jumps 3/4, b7 self test.
.alias INP_SHIFT        $03      ;MB14241 shifter result: the last two bytes written, shifted by the count.

;----------------------------------[ Output ports ]----------------------------------
;8080 I/O space (OUT).
.alias OUT_SHIFT_AMT    $01      ;MB14241 shift count (low 3 bits = X position within the byte).
.alias OUT_SHIFT_DATA   $02      ;MB14241 shift data.
.alias OUT_MISC         $03      ;b0 coin counter, b1 paddle select (1 = player 2). Shadow in OUT3_SHADOW.
.alias OUT_WATCHDOG     $04      ;Any write clears the watchdog.
.alias OUT_TONE_LO      $05      ;Tone generator: b0 tone enable, b1-b5 low five bits of the period.
.alias OUT_TONE_HI      $06      ;Tone generator: b0-b5 high six bits of the period.
.alias OUT_SOUND        $07      ;b0 pop (bottom row), b1 pop (middle row), b2 pop (top row), b3 sound enable, b4 springboard hit, b5 miss (rising edge).

;----------------------------------[ Work RAM: script, scores, timers ]----------------------------------
.alias SCRIPT_PTR       $2000    ;2 bytes. Game script program counter (the interpreter is MainLoop).
.alias SECOND_PRESCALE  $2002    ;Counts 30 odd frames down to one TMR_TIMEOUT tick (about a second).
.alias TIMEOUT_PTR      $2003    ;2 bytes. Script address taken when TMR_TIMEOUT runs out (script TIMEOUT command).
.alias GAME_ACTIVE      $2005    ;0 = attract mode, 1 = a game is being played.
.alias COIN_SW_PREV     $2006    ;Last coin switch state ($40 = down) for edge detection.
.alias RNG_SEED         $2007    ;8-bit shift-register random number.
.alias COINS            $2009    ;Coins inserted and not yet spent.
.alias COINS_PER_GAME   $200A    ;Coins the current game cost; a bonus game adds this many back to COINS.
.alias SCRIPT_HOLD      $200B    ;Non-zero: an expired TMR_SCRIPT does not step the script past its WAIT.
.alias TIMEOUT_HOLD     $200C    ;Non-zero: an expired TMR_TIMEOUT does not jump to TIMEOUT_PTR.
.alias FRAME_CTR        $200D    ;Incremented each frame; bit 0 picks seesaw frame (even) or balloon frame (odd).
.alias P1_SCORE         $200E    ;2 bytes. Player 1 score, BCD, high byte first. Shown with a fixed 0 appended (tens of points).
.alias JUMPS_LEFT       $2010    ;Jumps (lives) left, shown after JUMPS.
.alias P2_SCORE         $2011    ;2 bytes. Player 2 score, same format as P1_SCORE.
.alias PADDLE_POS       $2013    ;Wanted seesaw X: the paddle (read at vblank when PADDLE_ENABLE) or the attract autopilot.
.alias OUT3_SHADOW      $2014    ;Copy of OUT_MISC: b0 coin counter, b1 paddle select.
.alias HI_SCORE         $2015    ;2 bytes. High score, BCD, high byte first. Below $2040, so it survives the script CLEAR.
.alias REFILL_PENDING   $2017    ;Non-zero while a cleared row waits to be refilled: the row's Y (each-row mode) or 1 (all rows).
.alias REFILL_ROW_PTR   $2018    ;2 bytes. Balloon row (or first row) that TMR_REFILL will refill.
.alias NEXT_PLAYER      $201A    ;Player for the next turn; ClearRamTop copies it to PLAYER.
.alias NEXT_JUMPS_LEFT  $201B    ;Jumps left for the next turn; ClearRamTop copies it to JUMPS_LEFT.
.alias SPEED_LEVEL      $201C    ;0-4. Launch speed is SPEED_LEVEL+5; goes up every third launch.
.alias TUNE_TEMPO       $201D    ;Frames per beat of the tune being played.
.alias TUNE_TICKS       $201E    ;Frames left in the current beat.
.alias TUNE_BEATS       $201F    ;Beats left in the current note.
.alias TUNE_GAP         $2020    ;Frames of silence owed before the next note.
.alias TUNE_ON          $2021    ;Non-zero: PlayTune runs.
.alias TUNE_PTR         $2022    ;2 bytes. Next byte of the tune.
.alias JUMPS_AGAIN      $2024    ;Non-zero: the player earned an extra jump; the turn does not pass and no jump is used.
.alias PREV_BONUS_GAME  $2025    ;BONUS_GAME of the game that just ended; a game played on a bonus cannot win another.
.alias TMR_TIMEOUT      $2028    ;Slow timer (seconds). Expiry -> EVT_TIMEOUT b0 -> script jumps to TIMEOUT_PTR.
.alias TMR_SCRIPT       $2029    ;30 Hz timers $2029-$2030 (TickTimers). This one: script DELAY; expiry steps past the WAIT.
.alias TMR_SOUND_OFF    $202A    ;Expiry ends the pop / hit / miss sound (OUT_SOUND = $08).
.alias TMR_WALK         $202B    ;Expiry advances the walk animation of the clown being served.
.alias TMR_SERVE_JUMP   $202C    ;Expiry makes the served clown jump off its ledge.
.alias TMR_GRAVITY      $202D    ;Expiry adds 1 to the flyer's Y velocity; reloaded from GRAVITY_PERIOD.
.alias TMR_SPLAT        $202E    ;Expiry steps the splat animation.
.alias TMR_HIT_LOCKOUT  $202F    ;While running, sprite contact is ignored (after a launch or a pop). No expiry action.
.alias TMR_REFILL       $2030    ;Expiry refills the cleared balloon row(s).
.alias TMR_COIN_CTR     $2031    ;30 Hz timers $2031-$2033. This one: expiry ends the coin counter pulse.
.alias TMR_TUMBLE       $2032    ;Paces the flyer's tumble frames. No expiry action; polled by AnimateFlyer.
.alias TMR_FREEZE       $2033    ;Expiry ends the bonus freeze and erases the BONUS message.

;----------------------------------[ Work RAM: balloon rows ]----------------------------------
.alias P1_ROW_TOP       $2040    ;36 bytes. Balloon rows: 12 balloons x (state b7 = present, X, Y). Player 1 top row (Y $24, 100 points).
.alias P2_ROW_TOP       $2064    ;36 bytes. Player 2 top row. Every player 2 row is P2_OFFSET above player 1's.
.alias P1_ROW_MID       $2088    ;36 bytes. Player 1 middle row (Y $38, 50 points).
.alias P2_ROW_MID       $20AC    ;36 bytes. Player 2 middle row.
.alias P1_ROW_BOT       $20D0    ;36 bytes. Player 1 bottom row (Y $4E, 20 points).
.alias P2_ROW_BOT       $20F4    ;36 bytes. Player 2 bottom row.

;----------------------------------[ Work RAM: seesaw, players, clown objects ]----------------------------------
.alias SEESAW_STATE     $2118    ;b7 on screen, b6 tipping, b5 right end down (clown waits on the right), b0-b3 picture 0-4.
.alias SEESAW_DRAWN_X   $2119    ;X the seesaw was last drawn at (erased from here next time).
.alias P1_EXTRA_JUMP    $211B    ;Non-zero once player 1 has been given the extra jump.
.alias P2_EXTRA_JUMP    $211C    ;Same for player 2.
.alias PLAYER           $211D    ;$00 = player 1, $FF = player 2.
.alias TWO_PLAYERS      $211E    ;Non-zero in a two-player game.
.alias BONUS_GAME       $211F    ;Non-zero once the bonus game has been awarded in this game.
.alias CLOWN_A          $2180    ;64 bytes. Clown object (see the CL_ offsets).
.alias CLOWN_B          $21C0    ;64 bytes. Second clown object.

;----------------------------------[ Work RAM: text buffer and game state ]----------------------------------
.alias TEXT_BUF         $2200    ;15 bytes. Characters of the score line: player 1 score (5), jumps left (1), player 2 score (5).
.alias BONUS_BUF        $220F    ;5 bytes. Characters of the row bonus value.
.alias EVT_TIMEOUT      $2219    ;b0 set by the interrupt when TMR_TIMEOUT ran out; taken by CheckTimeout.
.alias EVT_TIMERS       $221A    ;Expiry bits for $2029-$2030 (b7 = $2029 ... b0 = $2030); taken by RunTimerEvents.
.alias EVT_TIMERS2      $221B    ;Expiry bits for $2031-$2033 (b2 = $2031 ... b0 = $2033); taken by RunTimerEvents2.
.alias SEESAW_X         $221D    ;Seesaw X: PADDLE_POS limited to $D7.
.alias SERVE_REQUEST    $221E    ;Non-zero: ServeClown sets up both clowns for a new jump.
.alias SERVING          $221F    ;Non-zero while the served clown walks on its ledge (no gravity, no tumbling).
.alias WALK_PHASE       $2220    ;0-3, steps the walk picture +1 +1 -1 -1.
.alias GRAVITY_PERIOD   $2221    ;TMR_GRAVITY reload: 5 in attract, 4 at the start of a jump, up to 8.
.alias GRAVITY_STEP_CTR $2222    ;Every 2nd launch raises GRAVITY_PERIOD.
.alias SPLAT_CTR        $2223    ;Splat pictures left.
.alias FLYER_PTR        $2224    ;2 bytes. Clown object in the air (or being served).
.alias RIDER_PTR        $2226    ;2 bytes. Clown object standing on the seesaw.
.alias ERASE_MODE       $2228    ;OR-ed into the flyer's state when it is drawn: $40 put the saved background back, $20 blank the box.
.alias HIT_ROW          $2229    ;Row of the balloon just popped: 0 bottom, 1 middle, 2 top.
.alias START1_DOWN      $222A    ;$20 while the 1-player start button is down.
.alias START2_DOWN      $222B    ;$10 while the 2-player start button is down.
.alias PLAYFIELD_ON     $222C    ;Non-zero: the floor and the four ledges are redrawn every main loop pass.
.alias PADDLE_ENABLE    $222D    ;Non-zero: the vblank interrupt copies the paddle to PADDLE_POS.
.alias AUTOPILOT        $222E    ;Non-zero: attract mode steers the seesaw under the flyer.
.alias DIGIT_INDEX      $2230    ;Which character of TEXT_BUF DrawNextDigit shows next.
.alias FLYER_HIGH       $2231    ;Non-zero when the flyer is above Y $50: it is then updated at mid-screen, else at vblank.
.alias FREEZE           $2232    ;Non-zero: flyer and balloons stand still (bonus message).
.alias FREEZE_REQ       $2233    ;Copied to FREEZE after the flyer's next update.
.alias CONTACT_ROW      $2234    ;Set by the interrupt: 1 + sprite row where the flyer first touched something; cleared by HandleContact.
.alias BALLOON_PHASE    $2235    ;0-5, which entry of BalloonTasks runs this odd frame.
.alias SPEED_STEP_CTR   $2236    ;Every 3rd launch raises SPEED_LEVEL.
.alias REBOUND_STEP_CTR $2237    ;Every 4th launch raises REBOUND_SPEED.
.alias REBOUND_SPEED    $2238    ;0-4. Downward speed given to a flyer that pops a balloon on the way up.

;----------------------------------[ Constants ]----------------------------------
;Clown object
.alias CL_STATE         $00      ;b7 in use, b6 put back the saved background before the next draw, b5 blank the old box, b4 slow (moves every 4th update), b3 splatted, b0-b2 slow tick.
.alias CL_FRAME         $01      ;Picture number, index into ClownPictures.
.alias CL_XVEL          $02      ;Added to X at every update.
.alias CL_X             $03      ;X, 0-$F1.
.alias CL_YVEL          $04      ;Added to Y at every update.
.alias CL_Y             $05      ;Y of the top of the picture.
.alias CL_SCREEN        $06      ;Video RAM address the picture was drawn at (2 bytes).
.alias CL_ROWS          $08      ;Rows drawn.
.alias CL_WIDTH         $09      ;Screen bytes per row: picture bytes + 1 for the shift (3 for the flyer, 2 for the rider).
.alias CL_SAVED         $0A      ;Background bytes saved while drawing, CL_WIDTH per row.
;Balloons
.alias P2_OFFSET        $24      ;Player 2's balloon row = player 1's + $24 (12 balloons x 3 bytes).
