# Mermaids of Atlantis (U) - routine descriptions. # # Name description. Used by the routine-header tool; the routines # that are not listed here get a description built from their name. # ---- fixed bank (file $6000-$7FFF, CPU $E000-$FFFF) ---- Reset Power-on entry: sets up the stack, clears the PPU and starts the bank switch. SelectChrBanks Picks the CHR banks for the stage that is about to be drawn. StartGame Switches to the first PRG bank and hands over to the game code. WritePrgBankReg Writes the MMC3 PRG bank register at $4100. DelayOuterLoop Outer half of the power-on delay loop. DelayInnerLoop Inner half of the power-on delay loop. WaitForBankSwitch Waits for the bank switch counter to run out. StartBankSwitchDelay Starts the bank switch delay counter. SwitchPrgBank Writes A to the MMC3 PRG bank register with the mode bits forced on. SwitchPrgBankKeepA Writes X to the MMC3 PRG bank register and keeps A. # ---- bank 0 (file $0000-$1FFF, CPU $8000-$9FFF) ---- BankedCall Switches the PRG bank and dispatches to the handler the caller named. SelectPrgBankByIndex Switches the PRG bank to the one in X. InitializeGame Resets the CPU, the PPU and the work RAM, then idles for the NMI. WaitForVBlank Spins until the PPU signals the start of vertical blank. ClearRamLoop Clears the work RAM one 224 byte page at a time. ClearRamPageDone Moves on to the next page of the RAM clear. InitGameVariables Sets the sound, scroll and sprite registers up. IdleWaitLoop The loop the game sits in between two NMI handlers. NmiHandler The frame handler: redraws the screen, reads the pad and runs the game. UploadOam Copies the sprite shadow into the OAM through the DMA register. RunGameLogic Runs the game logic for the current mode. ReadControllers Strobes the controller ports and reads both of them. ReadControllerBits Shifts one controller byte into the button bit mask. DispatchByJumpTable Jumps to the handler whose address follows the call. ClearOamShadow Fills the sprite shadow at $0200 with the "empty" value $F8. UpdateNametable Rewrites the nametable entries that changed. UpdateSprites Walks the sixteen sprite slots and redraws the active ones. UpdateActorSprites Walks the actor slots and redraws their sprites. StartVramWrite Sets the PPU address for the next VRAM write. WriteVramTiles Writes the tile data to VRAM. TickAnimationCounter Advances the animation counter once per frame. ApplyGraphicsMode Switches the PPU to the graphics mode the level asks for. AnimatePalette Cycles the palette entries of the animated tiles. InitLevelState Sets up the state of a new level. CopyStackPage Copies the stack page so the game can use it as scratch RAM. ReadPlayerInput Turns the raw button bits into the player's movement. BuildOamBuffer Fills the sprite shadow from the actor and bubble tables. ClearSpriteSlots Empties the sixteen sprite slots. TickLevelTimer Counts the level timer and resets it when it runs out. LoadSpriteTable Copies a sprite table out of the fixed bank. SetGraphicsMode Switches the PPU between the background and the overlay. UpdateGameState Runs the mode machine: title, demo, play and game over. ResetLevelTimers Clears the level timers when a new level starts. SetTablePointer Points the data pointer at a table in RAM. # ---- bank 1 (file $2000-$3FFF, CPU $A000-$BFFF) ---- ClearBubbleSlots Empties the bubble slots. ClearActorSlots Empties the actor slots. ClearActorTable Empties the actor table in RAM. SoundTimerTick Counts the sound effect timer down. PlaySoundEffect Starts a sound effect from the sound table. LoadActorTemplate Copies an actor template out of the table. CopyActorToSpriteTable Copies an actor into the sprite table. UpdatePlayerState Updates the player state for the current frame. HandleDemoMode Runs the attract mode when no credit is left. HandlePlayerInput Turns the button bits into the player's actions. CountPlayerFrames Counts the frames the player state has been in. MovePlayer Moves the player by one step. ApplyPlayerDirection Turns the direction bits into a movement delta. ComputePlayerPosition Computes the player's position from the tile map. StorePlayerSprite Stores the player's sprite in the sprite table. BuildBubbleTable Builds the table of the bubbles on the screen. UpdateBubbles Updates every bubble on the screen. PlayBubbleSound Plays the sound of a bubble that burst. SpawnBubble Puts a new bubble on the screen. DrawBubble Draws one bubble. DispatchBubbleHandler Jumps to the handler the bubble table names. ResetLevel Resets the level and the player. ClearSpriteTable Empties the sprite table in RAM. # ---- bank 2 (file $4000-$5FFF, CPU $C000-$DFFF) ---- ClearNametableRam Clears the nametable RAM the game writes to. PlayStageMusic Runs the stage script: the music, the waves and the timer. DispatchLevelScript Jumps to the level script step the game is on. ResetPpuAndLoadTiles Turns the PPU off and loads the tile set. SetVramPointer Points the VRAM pointer at the tile set. ClearSpriteEntry Clears one entry of the sprite table. TickStageDelay Counts the delay between two stage script steps. UpdateStageMode Updates the mode the stage script is in. DisablePpuRendering Turns the PPU off. SetPlayerActive Marks the player as active. CheckPlayerActive Tests whether the player is still in play. TickSoundOnEvenFrame Updates the sound on every second frame. UpdateSoundEngine Updates the sound engine. CheckActorCount Tests how many actors are on the screen. TickActorsOnEvenFrame Updates the actors on every second frame. InitPlayerPosition Places the player at the start of the level. TickTimerOnEvenFrame Updates the level timer on every second frame. ResetScrollOnEvenFrame Resets the scroll on every second frame. InitBubbleState Sets the bubble state up for a new wave. UpdateBubbleFrame Updates the bubbles once per frame. TickHudOnEvenFrame Updates the score display on every second frame. TickSpritesOnEvenFrame Updates the sprite table on every second frame. SetSoundChannels Turns the APU channels on. # ---- the second half of the image (banks 4-7) ---- Bank4_CallBankedHandler Switches the PRG bank and dispatches to the handler the caller named. Bank4_StartVramWrite Sets the PPU address for the next VRAM write. Bank4_UpdateNametable Rewrites the nametable entries that changed. Bank5_UpdateSound Updates the sound engine of the second half. Bank5_ReadSoundTable Reads the sound table of the second half. Bank5_SetSoundMode Turns the sound channels on in the second half. Bank7_SwitchPrgBank The copy of the bank switch the last bank of the image carries.