diff --git a/src/enemy_types.h b/src/enemy_types.h index a73bbf4..de423d7 100644 --- a/src/enemy_types.h +++ b/src/enemy_types.h @@ -1010,17 +1010,6 @@ uint8 pad1[0x7800 - 0xFB8]; uint16 fzr_var_1E; uint16 fzr_var_1F; }Enemy_FireZoomer; -typedef struct Enemy_Fireflea { -EnemyBase base; -uint16 firefl_var_A; -uint16 firefl_var_B; -uint16 firefl_var_C; -uint16 firefl_var_D; -uint16 firefl_var_E; -uint16 firefl_var_F; -uint16 firefl_parameter_1; -uint16 firefl_parameter_2; -}Enemy_Fireflea; typedef struct Enemy_Flies { EnemyBase base; uint16 flies_var_A; @@ -3993,7 +3982,6 @@ struct Enemy_FakeKraid; static inline Enemy_FakeKraid *Get_FakeKraid(int o) { re struct Enemy_FireFlea; static inline Enemy_FireFlea *Get_FireFlea(int o) { return (Enemy_FireFlea *)(g_ram + 0xF78 + o); } struct Enemy_FireGeyser; static inline Enemy_FireGeyser *Get_FireGeyser(int o) { return (Enemy_FireGeyser *)(g_ram + 0xF78 + o); } struct Enemy_FireZoomer; static inline Enemy_FireZoomer *Get_FireZoomer(int o) { return (Enemy_FireZoomer *)(g_ram + 0xF78 + o); } -struct Enemy_Fireflea; static inline Enemy_Fireflea *Get_Fireflea(int o) { return (Enemy_Fireflea *)(g_ram + 0xF78 + o); } struct Enemy_Flies; static inline Enemy_Flies *Get_Flies(int o) { return (Enemy_Flies *)(g_ram + 0xF78 + o); } struct Enemy_Fune; static inline Enemy_Fune *Get_Fune(int o) { return (Enemy_Fune *)(g_ram + 0xF78 + o); } struct Enemy_Gripper; static inline Enemy_Gripper *Get_Gripper(int o) { return (Enemy_Gripper *)(g_ram + 0xF78 + o); } diff --git a/src/funcs.h b/src/funcs.h index 921735a..2d38c3c 100644 --- a/src/funcs.h +++ b/src/funcs.h @@ -21,8 +21,7 @@ uint8 ProcessTimer_InitialDelay(void); uint8 ProcessTimer_MotherBrainStart(void); uint8 ProcessTimer_MovementDelayed(void); uint8 ProcessTimer_MovingIntoPlace(void); -uint8 j_ProcessTimer_Decrement(void); -void APU_UploadBank(void); +void APU_UploadBank(uint32 addr); void AddGrappleToHudTilemap(void); void AddMissilesToHudTilemap(void); void AddPowerBombsToHudTilemap(void); @@ -51,10 +50,10 @@ void DoorTransitionScrollingSetup_Down(void); void DoorTransitionScrollingSetup_Left(void); void DoorTransitionScrollingSetup_Right(void); void DoorTransitionScrollingSetup_Up(void); -void DrawThreeHudDigits(LongPtr r0, uint16 a, uint16 k); +void DrawThreeHudDigits(uint32 addr, uint16 a, uint16 k); void DrawTimer(void); void DrawTimerSpritemap(uint16 a, uint16 j); -void DrawTwoHudDigits(LongPtr r0, uint16 a, uint16 k); +void DrawTwoHudDigits(uint32 addr, uint16 a, uint16 k); void DrawTwoTimerDigits(uint16 a, uint16 k); void EnableIrqInterrupts(void); void EnableIrqInterruptsNow(void); @@ -94,7 +93,7 @@ void Irq_DoorTransitionVramUpdate(void); void WaitForIrqDoorTransitionVramUpdate(void); void LoadFromLoadStation(void); void LoadMirrorOfExploredMapTiles(void); -void Multiply16x16(uint16 a, uint16 j); +uint32 Multiply16x16(uint16 a, uint16 j); void NMI_ProcessMode7Queue(void); void NMI_ProcessMode7QueueInner(const uint8 *p); void NMI_ProcessVramReadQueue(void); @@ -176,9 +175,9 @@ void ClearMenuTilemap(void); void ConfigureWindow1ForExpandingSquare(void); void DebugGameOverMenu(void); void DrawAreaSelectMapLabels(void); -void DrawBeamGrappleSpritemap(uint16 a); -void DrawEnemyProjectileSpritemapWithBaseTile(uint8 db, uint16 j); -void DrawEnemyProjectileSpritemapWithBaseTileOffscreen(uint8 db, uint16 j); +void DrawBeamGrappleSpritemap(uint16 a, uint16 x_r20, uint16 y_r18); +void DrawEnemyProjectileSpritemapWithBaseTile(uint8 db, uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r26, uint16 chr_r28); +void DrawEnemyProjectileSpritemapWithBaseTileOffscreen(uint8 db, uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r26, uint16 chr_r28); void DrawFileCopyClearConfirmation(void); void DrawFileCopyConfirmationSaveFileInfo(void); void DrawFileCopySaveFileInfo(void); @@ -190,14 +189,14 @@ void DrawFileSelectSamusHelmets(void); void DrawFileSelectSlotSamusHelmet(uint16 k); void DrawFileSelectionHealth(uint16 a, uint16 k); void DrawFileSelectionTime(uint16 a, uint16 k); -void DrawMenuSpritemap(uint16 a, uint16 k, uint16 j); -void DrawProjectileSpritemap(uint16 k); +void DrawMenuSpritemap(uint16 a, uint16 k, uint16 j, uint16 chr_r3); +void DrawProjectileSpritemap(uint16 k, uint16 x_r20, uint16 y_r18); void DrawSamusSpritemap(uint16 a, uint16 k, uint16 j); -void DrawSpritemap(uint8 db, uint16 j); -void DrawSpritemapOffScreen(uint16 j); -void DrawSpritemapWithBaseTile(uint8 db, uint16 j); -void DrawSpritemapWithBaseTile2(uint8 db, uint16 j); -void DrawSpritemapWithBaseTileOffscreen(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y); +void DrawSpritemap(uint8 db, uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r22); +void DrawSpritemapOffScreen(uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r22); +void DrawSpritemapWithBaseTile(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y, uint16 r3, uint16 r0); +void DrawSpritemapWithBaseTile2(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y, uint16 r3, uint16 r0); +void DrawSpritemapWithBaseTileOffscreen(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y, uint16 r3, uint16 r0); void FileSelectClearRestOfMenuTilemapRow(uint16 k); void FileSelectMap(void); void FileSelectMap_0(void); @@ -269,7 +268,6 @@ void InitFileSelectMenuFileClear(void); void LoadActiveAreaMapForegroundColors(uint16 k); void LoadAreaMapForegroundColors(uint16 j); void LoadAreaSelectBackgroundTilemap(uint16 j); -void LoadDebugGameOverMenuTilemaps(void); void LoadFileSelectPalettes(void); void LoadInactiveAreaMapForegroundColors(uint16 k); void LoadInitialMenuTiles(void); @@ -288,9 +286,9 @@ void SetFileCopyMenuSelectionMissilePosition(void); void SetInitialFileCopyMenuSelection(void); void SetupInitialExpandingSquareHDMA(void); void SetupRoomSelectMapExpandingSquareTransHDMA(void); -void SwitchActiveFileSelectMapArea(void); +void SwitchActiveFileSelectMapArea(uint16 R28); void UnpackMapFromSave(void); -void DrawGrappleOrProjectileSpritemap(const uint8 *pp); +void DrawGrappleOrProjectileSpritemap(const uint8 *pp, uint16 x_r20, uint16 y_r18); void sub_819591(void); void sub_81A3D1(uint16 k); void sub_81AEC8(void); @@ -300,10 +298,6 @@ void SoftReset(void); uint16 CalculateNthTransitionColorComponentFromXtoY(uint16 a, uint16 k, uint16 j); uint16 CalculateNthTransitionColorFromXtoY(uint16 a, uint16 k, uint16 j); uint16 CheckIfMapPositionIsExplored(uint16 k, uint16 j); -uint16 DetermineBottommostMapColumn(void); -uint16 DetermineLeftmostMapColumn(void); -uint16 DetermineRightmostMapColumn(void); -uint16 DetermineTopmostMapColumn(void); uint16 EquipmentScreenCategory_Boots_MoveUpInBoots(uint16 k); uint16 EquipmentScreenMoveLowerOnSuitsMisc(uint16 k); uint16 EquipmentScreenMoveToBottomOfBeams(uint16 k); @@ -317,7 +311,6 @@ uint16 LoadLibraryBackgroundFunc_A_ClearBG2Tilemap(uint16 j); uint16 LoadLibraryBackgroundFunc_C_ClearKraidLayer2(uint16 j); uint16 LoadLibraryBackgroundFunc_E_DoorDependentTransferToVram(uint16 j); uint16 MapScrolling_GetSpeedIndex(void); -uint16 MultiplyBy8(uint16 k); uint16 OptionsInstr_8C64(uint16 k, uint16 j); uint16 OptionsInstr_8C79(uint16 k, uint16 j); uint16 OptionsInstr_8C89(uint16 k, uint16 j); @@ -363,7 +356,7 @@ void ClearSamusBeamTiles(void); void ContinueInitGameplayResume(void); void ContinueInitPauseMenu(void); void CopyToVramAtNextInterrupt(const void* p); -void Copy_R22_Bytes(uint16 k); +void Copy_R22_Bytes(uint16 k, int r22); void CreatePlmsExecuteDoorAsmRoomSetup(void); void DeleteAllOptionsMenuObjects_(void); void DemoRoom_ChargeBeamRoomScroll21(void); @@ -389,13 +382,13 @@ void DrawBorderAroundDataClearMode(void); void DrawBorderAroundDataCopyMode(void); void DrawBorderAroundSamusData(void); void DrawBossMapIcons(uint16 a, uint16 k); -void DrawDebugElevatorMapIcons(uint16 a, uint16 k); -void DrawDebugSaveMapIcons(uint16 a, uint16 k); +void DrawDebugElevatorMapIcons(uint16 a, uint16 k, uint16 r3); +void DrawDebugSaveMapIcons(uint16 a, uint16 k, uint16 r3); void DrawFileCopyArrow(void); void DrawFileSelectMapIcons(void); void DrawLrHighlight(void); void DrawMapIcons(void); -void DrawMapIconsOfType(uint16 a); +void DrawMapIconsOfType(uint16 a, uint16 r34, uint16 r36, uint16 r3); void DrawMapScrollArrowAndCheckToScroll(uint8 db, uint16 k); void DrawMenuSelectionMissile(void); void DrawOptionsMenuSpritemaps(void); @@ -403,13 +396,13 @@ void DrawPauseMenuDuringFadeIn(void); void DrawPauseMenuDuringFadeout(void); void DrawPauseScreenSpriteAnim(uint16 a, uint16 k, uint16 j); void DrawRoomSelectMap(void); -void DrawRoomSelectMapAreaLabel(void); -void DrawSaveStationMapIcon(uint16 a, uint16 k); -void DrawSimpleMapIcons(uint16 a, uint16 k); +void DrawRoomSelectMapAreaLabel(LongPtr r0); +void DrawSaveStationMapIcon(uint16 a, uint16 k, uint16 r3); +void DrawSimpleMapIcons(uint16 a, uint16 k, uint16 r3); void EnsureSamusDrawnEachFrame(void); void EquipmentScreenCategory_Boots(void); void EquipmentScreenCategory_Boots_MoveResponse(void); -void EquipmentScreenCategory_ButtonResponse(void); +void EquipmentScreenCategory_ButtonResponse(uint16 r24); void EquipmentScreenCategory_Suit(void); void EquipmentScreenCategory_Suit_MoveResponse(void); void EquipmentScreenCategory_Tanks(void); @@ -417,10 +410,10 @@ void EquipmentScreenCategory_Tanks_0(void); void EquipmentScreenCategory_Tanks_1(void); void EquipmentScreenCategory_Weapons(void); void EquipmentScreenCategory_Weapons_MoveButtons(void); -void EquipmentScreenCategory_Weapons_PlazmaSpazerCheck(void); +void EquipmentScreenCategory_Weapons_PlazmaSpazerCheck(uint16 R36); void EquipmentScreenDisplayReserveTankAmount(void); void EquipmentScreenDisplayReserveTankAmount_(void); -void EquipmentScreenDisplayReserves_PaletteSetup(void); +uint16 EquipmentScreenDisplayReserves_PaletteSetup(void); void EquipmentScreenDrawItemSelector(void); void EquipmentScreenEnergyArrowGlow_Off(void); void EquipmentScreenEnergyArrowGlow_On(void); @@ -432,9 +425,9 @@ void EquipmentScreenHandleDpad(void); void EquipmentScreenHudReserveAutoTilemap_Off(void); void EquipmentScreenHudReserveAutoTilemap_On_BUGGY(void); void EquipmentScreenMain(void); -void EquipmentScreenMoveToBeams(uint16 k); -void EquipmentScreenMoveToHighJumpOrLowerInBoots(uint16 k); -void EquipmentScreenMoveToScrewOrHigherOnSuits(uint16 k); +void EquipmentScreenMoveToBeams(uint16 k, uint16 r18); +void EquipmentScreenMoveToHighJumpOrLowerInBoots(uint16 k, uint16 r18); +void EquipmentScreenMoveToScrewOrHigherOnSuits(uint16 k, uint16 r18); void EquipmentScreenSetupReserveMode(void); void EquipmentScreenTransferBG1Tilemap(void); void FinishProcessingGameOverBabyMetroidAsm(void); @@ -510,10 +503,8 @@ CoroutineRet InitAndLoadGameData_Async(void); void InitCpuForGameplay(void); void InitIoForGameplay(void); void InitPpuForGameplay(void); -void JmpFuncA(uint16 a); void LoaadDesinationRoomCreBitset(void); void LoadCRETilesTilesetTilesAndPalette(void); -void LoadCRETilesTilesetTilesAndPalette_(void); void LoadColorsForSpritesBeamsAndEnemies(void); void LoadControllerOptionsFromControllerBindings(void); void LoadDemoRoomData(void); @@ -536,7 +527,6 @@ void LoadRoomHeader(void); void LoadRoomMusic(void); void LoadStateHeader(void); void LoadStdBG3andSpriteTilesClearTilemaps(void); -void MainGameLoopStarter(void); void MainPauseRoutine(void); void MapScreenDrawSamusPositionIndicator(void); void MapScrolling(void); @@ -579,7 +569,6 @@ void ResetSoundQueues(void); void RestoreBG2TilemapFromPauseScreen(void); void RestoreSomeGfxStateForPause(void); void SaveMapExploredifElevator(void); -void SetPaletteOfR22TilemapBytesToR18(void); void SetPauseScreenButtonLabelPalettes(void); void SetPauseScreenButtonLabelPalettes_0(void); void SetPauseScreenButtonLabelPalettes_1(void); @@ -621,220 +610,11 @@ void sub_82F404(uint16 k); void sub_82F419(uint16 j); // Bank 84 -const uint8 *PlmInstr_ABD6(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ActivateEnergyStation(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ActivateMapStation(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ActivateMissileStation(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ActivateSaveStationAndGotoIfNo(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Call(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_CallFunction(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ClearChargeBeamCounter(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ClearMusicQueueAndQueueTrack(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ClearPreInstr(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ClearTrigger(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_CollectAmmoMissileTank(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_CollectAmmoPowerBombTank(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_CollectAmmoSuperMissileTank(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_CollectHealthEnergyTank(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_CollectHealthReserveTank(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_CopyFromRamToVram(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DamageDraygonTurret(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DamageDraygonTurret2(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DamageDraygonTurretFacingDownLeft(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DamageDraygonTurretFacingDownRight(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DamageDraygonTurretFacingUpLeft(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DamageDraygonTurretFacingUpRight(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DealDamage_2(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DecrementAndBranchNonzero(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Delete(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DiagonalEarthquake(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DisableSamusControls(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DisplayGameSavedMessageBox(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Draw0x38FramesOfLeftTreadmill(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Draw0x38FramesOfRightTreadmill(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DrawItemFrame0(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DrawItemFrame1(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DrawItemFrame_Common(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DrawPlmBlock(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_DrawPlmBlock_(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_E63B(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_EnableMovementAndSetSaveStationUsed(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_EnableSamusControls(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_EnableWaterPhysics(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_FxBaseYPos_0x2D2(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GiveInvincibility(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Goto(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfBossBitSet(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfChozoSet(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfDoorBitSet(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfEventSet(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfItemBitSet(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfMissilesFull(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfRoomArgLess(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfSamusHealthFull(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_GotoIfSamusNear(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_IncrementArgumentAndJGE(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_IncrementDoorHitCounterAndJGE(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_JumpIfSamusHasNoBombs(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_LoadItemPlmGfx(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_MovePlmDownOneBlock(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_MovePlmDownOneBlock_0(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_MovePlmRight4Blocks(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_MoveUpAndMakeBlueDoorFacingLeft(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_MoveUpAndMakeBlueDoorFacingRight(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_PickupBeamAndShowMessage(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_PickupEquipmentAddGrappleShowMessage(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_PickupEquipmentAddXrayShowMessage(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_PickupEquipmentAndShowMessage(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_PlaceSamusOnSaveStation(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_PreInstr(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ProcessAirScrollUpdate(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ProcessSolidScrollUpdate(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueMusic(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx1_Max1(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx1_Max15(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx1_Max3(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx1_Max6(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx1_Max9(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx2_Max1(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx2_Max15(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx2_Max3(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx2_Max6(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx2_Max9(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx3_Max1(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx3_Max15(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx3_Max6(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx3_Max9(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSfx_Max3(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_QueueSong1MusicTrack(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Return(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Scroll_0_1_Blue(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetBTS(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetBtsTo1(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetCrittersEscapedEvent(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetEvent(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetGreyDoorPreInstr(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetItemBit(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetLinkReg(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetRoomChozoBit(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SetTimer(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_ShootEyeDoorProjectileWithProjectileArg(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Sleep(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_Spawn10shardsAnd6n00bs(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SpawnEnemyProjectile(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SpawnEyeDoorSmokeProjectile(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SpawnEyeDoorSweatEnemyProjectile(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SpawnFourMotherBrainGlass(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SpawnN00bTubeCrackEnemyProjectile(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SpawnTorizoStatueBreaking(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_SpawnTwoEyeDoorSmoke(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_TransferWreckedShipChozoSpikesToSlopes(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_TransferWreckedShipSlopesToChozoSpikes(const uint8 *plmp, uint16 k); -const uint8 *PlmInstr_WakeEnemyProjectileAtPlmPos(const uint8 *plmp, uint16 k); uint16 SetBtsTo0x10AdvanceRow(uint16 k); uint16 SetBtsTo0x10AdvanceRowUp(uint16 k); uint8 ActivateStationIfSamusCannonLinedUp(uint16 a, uint16 j); -uint8 PlmSetup_B638_Rightwards_Extension(uint16 j); -uint8 PlmSetup_B63F_Leftwards_Extension(uint16 j); -uint8 PlmSetup_B643_Downwards_Extension(uint16 j); -uint8 PlmSetup_B647_Upwards_Extension(uint16 j); -uint8 PlmSetup_B6D3_MapStation(uint16 j); -uint8 PlmSetup_B6E3_EnergyStationRightAccess(uint16 j); -uint8 PlmSetup_B6E7_EnergyStationLeftAccess(uint16 j); -uint8 PlmSetup_B6EF_MissileStationRightAccess(uint16 j); -uint8 PlmSetup_B6F3_MissileStationLeftAccess(uint16 j); -uint8 PlmSetup_B6FF_ScrollBlockTouch(uint16 j); -uint8 PlmSetup_B703_ScrollPLM(uint16 j); -uint8 PlmSetup_B707_SolidScrollPLM(uint16 j); -uint8 PlmSetup_B70F_IcePhysics(uint16 j); -uint8 PlmSetup_B71F_SubmergingQuicksand(uint16 j); -uint8 PlmSetup_B723_SandfallsSlow(uint16 j); -uint8 PlmSetup_B727_SandFallsFast(uint16 j); -uint8 PlmSetup_B737_SubmergingQuicksand(uint16 j); -uint8 PlmSetup_B73B_B73F_SandFalls(uint16 j); -uint8 PlmSetup_B767_ClearShitroidInvisibleWall(uint16 j); -uint8 PlmSetup_B76B_SaveStationTrigger(uint16 j); -uint8 PlmSetup_B76F_SaveStation(uint16 j); -uint8 PlmSetup_B7EB_EnableSoundsIn32Frames(uint16 j); -uint8 PlmSetup_B974(uint16 j); -uint8 PlmSetup_B9C1_CrittersEscapeBlock(uint16 j); -uint8 PlmSetup_B9ED_CrittersEscapeBlock(uint16 j); -uint8 PlmSetup_BB30_CrateriaMainstreetEscape(uint16 j); -uint8 PlmSetup_BTS_Brinstar_0x80_Floorplant(uint16 j); -uint8 PlmSetup_BTS_Brinstar_0x81_Ceilingplant(uint16 j); -uint8 PlmSetup_Bts47_MapStationRightAccess(uint16 j); -uint8 PlmSetup_Bts4_MapStationLeftAccess(uint16 j); -uint8 PlmSetup_C73A_UpwardsGateShootblock(uint16 j); -uint8 PlmSetup_C794_GreyDoor(uint16 j); -uint8 PlmSetup_C806_LeftGreenGateTrigger(uint16 j); -uint8 PlmSetup_C80A_RightGreenGateTrigger(uint16 j); -uint8 PlmSetup_C80E_LeftRedGateTrigger(uint16 j); -uint8 PlmSetup_C812_RightRedGateTrigger(uint16 j); -uint8 PlmSetup_C816_LeftBlueGateTrigger(uint16 j); -uint8 PlmSetup_C81A_RightBlueGateTrigger(uint16 j); -uint8 PlmSetup_C81E_LeftYellowGateTrigger(uint16 j); -uint8 PlmSetup_C822_RightYellowGateTrigger(uint16 j); -uint8 PlmSetup_C826_DownwardsOpenGate(uint16 j); -uint8 PlmSetup_C82A_DownwardsClosedGate(uint16 j); -uint8 PlmSetup_C82E_UpwardsOpenGate(uint16 j); -uint8 PlmSetup_C832_UpwardsClosedGate(uint16 j); -uint8 PlmSetup_C836_DownwardsGateShootblock(uint16 j); -uint8 PlmSetup_ClearShitroidInvisibleWall(uint16 j); -uint8 PlmSetup_CrumbleBotwoonWall(uint16 j); -uint8 PlmSetup_D028_D02C_Unused(uint16 j); -uint8 PlmSetup_D08C_CrumbleBlock(uint16 j); -uint8 PlmSetup_D08C_SuperMissileBlockRespawning(uint16 j); -uint8 PlmSetup_D094_EnemyBreakableBlock(uint16 j); -uint8 UNUSED_sub_84B3E3(uint16 j); -uint8 PlmSetup_D0D8_ClearVflag(uint16 j); -uint8 PlmSetup_D0D8_SetVFlag(uint16 j); -uint8 PlmSetup_D0DC_BreakableGrappleBlock(uint16 j); -uint8 PlmSetup_D0E8_GiveSamusDamage(uint16 j); -uint8 PlmSetup_D113_LowerNorfairChozoRoomPlug(uint16 j); -uint8 PlmSetup_D127(uint16 j); -uint8 PlmSetup_D138(uint16 j); -uint8 PlmSetup_D6DA_LowerNorfairChozoHandTrigger(uint16 j); -uint8 PlmSetup_D6F2_WreckedShipChozoHandTrigger(uint16 j); -uint8 PlmSetup_D700_MakePlmAirBlock_Unused(uint16 j); -uint8 PlmSetup_D704_AlteranateLowerNorfairChozoHand_Unused(uint16 j); -uint8 PlmSetup_D708_LowerNorfairChozoBlockUnused(uint16 j); -uint8 PlmSetup_D70C_NoobTube(uint16 j); -uint8 PlmSetup_DeactivatePlm(uint16 j); -uint8 PlmSetup_DeletePlmIfAreaTorizoDead(uint16 j); -uint8 PlmSetup_Door_Blue(uint16 j); -uint8 PlmSetup_Door_Colored(uint16 j); -uint8 PlmSetup_Door_Strange(uint16 j); -uint8 PlmSetup_DraygonCannon(uint16 j); -uint8 PlmSetup_DraygonCannonFacingDiagonalLeft(uint16 j); -uint8 PlmSetup_DraygonCannonFacingDiagonalRight(uint16 j); -uint8 PlmSetup_DraygonCannonFacingLeft(uint16 j); -uint8 PlmSetup_DraygonCannonFacingRight(uint16 j); -uint8 PlmSetup_EyeDoor(uint16 j); -uint8 PlmSetup_EyeDoorEye(uint16 j); -uint8 PlmSetup_MakeBllockChozoHandTrigger(uint16 j); -uint8 PlmSetup_MotherBrainGlass(uint16 j); -uint8 PlmSetup_MotherBrainRoomEscapeDoor(uint16 j); -uint8 PlmSetup_PlmB6DF_EnergyStation(uint16 j); -uint8 PlmSetup_PlmB6EB_EnergyStation(uint16 j); -uint8 PlmSetup_QuicksandSurface(uint16 j); -uint8 PlmSetup_QuicksandSurfaceB(uint16 j); -uint8 PlmSetup_QuicksandSurfaceB_0(uint16 j); -uint8 PlmSetup_QuicksandSurfaceB_1(uint16 j); -uint8 PlmSetup_QuicksandSurfaceB_2(uint16 j); -uint8 PlmSetup_RespawningBombBlock(uint16 j); -uint8 PlmSetup_RespawningBombBlock2(uint16 j); -uint8 PlmSetup_RespawningCrumbleBlock(uint16 j); -uint8 PlmSetup_RespawningPowerBombBlock(uint16 j); -uint8 PlmSetup_RespawningShotBlock(uint16 j); -uint8 PlmSetup_RespawningSpeedBoostBlock(uint16 j); -uint8 PlmSetup_ReturnCarryClear(uint16 j); -uint8 PlmSetup_ReturnCarrySet(uint16 j); -uint8 PlmSetup_SetMetroidRequiredClearState(uint16 j); -uint8 PlmSetup_SetrupWreckedShipEntrance(uint16 j); -uint8 PlmSetup_ShaktoolsRoom(uint16 j); -uint8 PlmSetup_SpeedBoosterEscape(uint16 j); uint8 SpawnPLM(uint16 a); -uint8 WakePlmIfSamusIsBelowAndRightOfTarget(uint16 k); +uint8 WakePlmIfSamusIsBelowAndRightOfTarget(uint16 k, uint16 x_r18, uint16 y_r20); uint8 sub_84B9F1(uint16 j); uint8 sub_84C63F(uint16 j); uint8 sub_84C647(uint16 j); @@ -853,7 +633,6 @@ uint8 sub_84EE89(uint16 j, uint16 a); uint8 sub_84EE8E(uint16 j); uint8 sub_84EEAB(uint16 j); void CalculatePlmBlockCoords(uint16 k); -void CalculatePlmDrawTilemapVramDst(uint16 k); void ClearPLMs(void); void ClearSoundsWhenGoingThroughDoor(void); void DeletePlm(uint16 j); @@ -862,45 +641,8 @@ void DrawPlm(uint16 k); void EnablePLMs(void); void LoadRoomPlmGfx(void); void LoadXrayBlocks(void); -void PartiallyQueueVramForSingleScreenPlm(uint16 a, uint16 k); void PlaySpinJumpSoundIfSpinJumping(void); CoroutineRet PlmHandler_Async(void); -void PlmPreInstr_AdvanceLavaSamusMovesLeft(uint16 k); -void PlmPreInstr_B7EB_DecTimerEnableSoundsDeletePlm(uint16 k); -void PlmPreInstr_DeletePlmAndSpawnTriggerIfBlockDestroyed(uint16 k); -void PlmPreInstr_Empty2(void); -void PlmPreInstr_EscapeRoomBeforeOldTourianEscapeShaft(uint16 k); -void PlmPreInstr_GoToLinkInstrIfShot(uint16 k); -void PlmPreInstr_GoToLinkInstrIfShotWithAnyMissile(uint16 k); -void PlmPreInstr_GoToLinkInstrIfShotWithPowerBomb(uint16 k); -void PlmPreInstr_GoToLinkInstrIfShotWithSuperMissile(uint16 k); -void PlmPreInstr_GoToLinkInstruction(uint16 k); -void PlmPreInstr_GotoLinkIfBoss1Dead(uint16 k); -void PlmPreInstr_GotoLinkIfCrittersEscaped(uint16 k); -void PlmPreInstr_GotoLinkIfEnemyDeathQuotaOk(uint16 k); -void PlmPreInstr_GotoLinkIfMiniBossDead(uint16 k); -void PlmPreInstr_GotoLinkIfShotWithSuperMissile(uint16 k); -void PlmPreInstr_GotoLinkIfTorizoDead(uint16 k); -void PlmPreInstr_GotoLinkIfTourianStatueFinishedProcessing(uint16 k); -void PlmPreInstr_GotoLinkIfTriggered(uint16 k); -void PlmPreInstr_IncrementRoomArgIfShotBySuperMissile(uint16 k); -void PlmPreInstr_OldTourianEscapeShaftEscape(uint16 k); -void PlmPreInstr_PlayDudSound(uint16 k); -void PlmPreInstr_PositionSamusAndInvincible(uint16 k); -void PlmPreInstr_SetMetroidsClearState_Ev0x10(uint16 k); -void PlmPreInstr_SetMetroidsClearState_Ev0x11(uint16 k); -void PlmPreInstr_SetMetroidsClearState_Ev0x12(uint16 k); -void PlmPreInstr_SetMetroidsClearState_Ev0x13(uint16 k); -void PlmPreInstr_ShaktoolsRoom(uint16 k); -void PlmPreInstr_WakeAndLavaIfBoosterCollected(uint16 k); -void PlmPreInstr_WakeIfTriggered(uint16 k); -void PlmPreInstr_WakeOnKeyPress(uint16 k); -void PlmPreInstr_WakePLMAndStartFxMotionSamusFarLeft(uint16 k); -void PlmPreInstr_WakePlmIfRoomArgumentDoorIsSet(uint16 k); -void PlmPreInstr_WakePlmIfSamusHasBombs(uint16 k); -void PlmPreInstr_WakePlmIfTriggered(uint16 k); -void PlmPreInstr_WakePlmIfTriggeredOrSamusAbovePlm(uint16 k); -void PlmPreInstr_WakePlmIfTriggeredOrSamusBelowPlm(uint16 k); void PlmSetup_QuicksandSurface_0(uint16 j); void PlmSetup_QuicksandSurface_1(uint16 j); void PlmSetup_QuicksandSurface_2(uint16 j); @@ -909,7 +651,14 @@ void SetBts0x10FiveStepsDown(uint16 j); void SetBts0x10FiveStepsUp(uint16 j); void SetGoldenTorizoPalette(uint16 a); void SkipDebugDrawInstructionsForScrollPlms(uint16 j); -void SpawnHardcodedPlm(const void* p); + +typedef struct SpawnHardcodedPlmArgs { + uint8 field_0; + uint8 field_1; + VoidP field_2; +} SpawnHardcodedPlmArgs; + +void SpawnHardcodedPlm(SpawnHardcodedPlmArgs p); void SpawnMotherBrainGlassShatteringShard(uint16 a); void SpawnRoomPLM(uint16 k); void WriteLevelDataBlockTypeAndBts(uint16 k, uint16 a); @@ -920,397 +669,45 @@ void sub_84D7EF(uint16 k); int DisplayMessageBox_Poll(uint16 a); void DisplayMessageBox(uint16 a); CoroutineRet DisplayMessageBox_Async(uint16 a); -uint16 WriteMessageTilemap(void); -void ClearMessageBoxBg3Tilemap(void); -CoroutineRet CloseMessageBox_Async(void); -void DrawRunButtonAndSetupPpuForLargeMessageBox(void); -void DrawShootButtonAndSetupPpuForLargeMessageBox(void); -void DrawSpecialButtonAndSetupPpuForLargeMessageBox(uint16 a); -CoroutineRet HandleMessageBoxInteraction_Async(void); -void InitializeMessageBox(void); -void InitializePpuForMessageBoxes(void); -CoroutineRet OpenMessageBox_Async(void); -void PlaySavingSoundEffect(void); -void RestorePpuForMessageBox(void); -void SetupMessageBoxBg3YscrollHdma(void); -void SetupPpuForActiveMessageBox(void); -void SetupPpuForLargeMessageBox(void); -void SetupPpuForSmallMessageBox(void); -void ToggleSaveConfirmationSelection(void); -void WriteLargeMessageBoxTilemap(void); -void MsgBoxMakeHdmaTable(void); -void WriteSmallMessageBoxTilemap(void); // Bank 86 -uint16 CheckIfEnemyProjectileIsOffScreen(uint16 k); -uint16 EprojInstr_SetPreInstrA(uint16 k, uint16 j); -uint16 EprojInstr_868D55(uint16 k, uint16 j); -uint16 EprojInstr_868D99(uint16 k, uint16 j); -uint16 EprojInstr_9270(uint16 k, uint16 j); -uint16 EprojInstr_95BA(uint16 k, uint16 j); -uint16 EprojInstr_95ED(uint16 k, uint16 j); -uint16 EprojInstr_9620(uint16 k, uint16 j); -uint16 EprojInstr_980E(uint16 k, uint16 j); -uint16 EprojInstr_A3BE(uint16 k, uint16 j); -uint16 EprojInstr_Add12ToY(uint16 k, uint16 j); -uint16 EprojInstr_AddToYpos(uint16 k, uint16 j); -uint16 EprojInstr_AssignNewN00bTubeShardVelocity(uint16 k, uint16 j); -uint16 EprojInstr_BB24(uint16 k, uint16 j); -uint16 EprojInstr_CalculateDirectionTowardsSamus(uint16 k, uint16 j); -uint16 EprojInstr_CallFunc(uint16 k, uint16 j); -uint16 EprojInstr_CallFuncWithParam(uint16 k, uint16 j); -uint16 EprojInstr_ClearPreInstr(uint16 k, uint16 j); -uint16 EprojInstr_ClearProjectileProperties(uint16 k, uint16 j); -uint16 EprojInstr_D15C(uint16 k, uint16 j); -uint16 EprojInstr_D1B6(uint16 k, uint16 j); -uint16 EprojInstr_D1C7(uint16 k, uint16 j); -uint16 EprojInstr_D1CE(uint16 k, uint16 j); -uint16 EprojInstr_D62A(uint16 k, uint16 j); -uint16 EprojInstr_DC5A(uint16 k, uint16 j); -uint16 EprojInstr_DFEA(uint16 k, uint16 j); -uint16 EprojInstr_DecTimerAndGotoIfNonZero(uint16 k, uint16 j); -uint16 EprojInstr_DecTimerAndGotoRelIfNonZero(uint16 k, uint16 j); -uint16 EprojInstr_Delete(uint16 k, uint16 j); -uint16 EprojInstr_DisableCollisionWithSamus(uint16 k, uint16 j); -uint16 EprojInstr_DisableCollisionWithSamusProj(uint16 k, uint16 j); -uint16 EprojInstr_DisableCollisionsWithSamus(uint16 k, uint16 j); -uint16 EprojInstr_ECE3(uint16 k, uint16 j); -uint16 EprojInstr_ED17(uint16 k, uint16 j); -uint16 EprojInstr_EEAF(uint16 k, uint16 j); -uint16 EprojInstr_Earthquake(uint16 k, uint16 j); -uint16 EprojInstr_EnableCollisionWithSamus(uint16 k, uint16 j); -uint16 EprojInstr_EnableCollisionWithSamusProj(uint16 k, uint16 j); -uint16 EprojInstr_Goto(uint16 k, uint16 j); -uint16 EprojInstr_GotoDependingOnXDirection(uint16 k, uint16 j); -uint16 EprojInstr_GotoIfFunc1(uint16 k, uint16 j); -uint16 EprojInstr_GotoRel(uint16 k, uint16 j); -uint16 EprojInstr_GotoWithProbability25(uint16 k, uint16 j); -uint16 EprojInstr_HandleRespawningEnemy(uint16 k, uint16 j); -uint16 EprojInstr_MotherBrainPurpleBreathIsActive(uint16 k, uint16 j); -uint16 EprojInstr_MoveRandomlyWithinRadius(uint16 k, uint16 j); -uint16 EprojInstr_MoveY_Minus4(uint16 k, uint16 j); -uint16 EprojInstr_QueueMusic(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx1_Max1(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx1_Max15(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx1_Max3(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx1_Max6(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx1_Max9(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_24(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_9(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_B(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_Max1(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_Max15(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_Max3(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_Max6(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx2_Max9(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx3_Max1(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx3_Max15(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx3_Max3(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx3_Max6(uint16 k, uint16 j); -uint16 EprojInstr_QueueSfx3_Max9(uint16 k, uint16 j); -uint16 EprojInstr_ResetXYpos1(uint16 k, uint16 j); -uint16 EprojInstr_ResetXYpos2(uint16 k, uint16 j); -uint16 EprojInstr_SetHighPriority(uint16 k, uint16 j); -uint16 EprojInstr_SetLowPriority(uint16 k, uint16 j); -uint16 EprojInstr_SetN00bTubeShardX(uint16 k, uint16 j); -uint16 EprojInstr_SetPreInstrAndRun(uint16 k, uint16 j); -uint16 EprojInstr_SetPreInstr_(uint16 k, uint16 j); -uint16 EprojInstr_SetProjectileProperties(uint16 k, uint16 j); -uint16 EprojInstr_SetTimer(uint16 k, uint16 j); -uint16 EprojInstr_SetToDieOnContact(uint16 k, uint16 j); -uint16 EprojInstr_SetToNotDieOnContact(uint16 k, uint16 j); -uint16 EprojInstr_SetXvelRandom(uint16 k, uint16 j); -uint16 EprojInstr_SetXyRadius(uint16 k, uint16 j); -uint16 EprojInstr_SetXyRadiusZero(uint16 k, uint16 j); -uint16 EprojInstr_SetYVel(uint16 k, uint16 j); -uint16 EprojInstr_Sleep(uint16 k, uint16 j); -uint16 EprojInstr_SpawnEnemyDrops(uint16 k, uint16 j); -uint16 EprojInstr_SpawnEnemyDrops_0(uint16 k, uint16 j); -uint16 EprojInstr_SpawnSporesEproj(uint16 k, uint16 j); -uint16 EprojInstr_SpawnTourianStatueUnlockingParticle(uint16 k, uint16 j); -uint16 EprojInstr_SpawnTourianStatueUnlockingParticleTail(uint16 k, uint16 j); -uint16 EprojInstr_SwitchJump(uint16 k, uint16 j); -uint16 EprojInstr_UserPalette0(uint16 k, uint16 j); -uint16 EprojInstr_WriteColorsToPalette(uint16 k, uint16 j); +extern Rect16U eproj_spawn_rect; +extern uint16 eproj_spawn_r22; +extern Point16U eproj_spawn_pt; +extern uint16 eproj_spawn_varE24; + +uint16 Math_MultByCos(uint16 a, uint16 r18); +uint16 Math_MultBySin(uint16 a, uint16 r18); +uint16 Math_MultBySinCos(uint16 r38, uint16 a); + uint16 EprojPreInstrHelper_DBF2_Func2(uint16 k); uint16 EprojPreInstrHelper_SpikeShootingPlantSpikes_Func2(uint16 k); uint16 EprojPreInstr_NorfairLavaquakeRocks_Inner2(uint16 k); uint16 Eproj_FuncE722(uint16 k); -uint16 Eproj_PhantomFireballs_Func2(uint16 k); -uint16 Math_MultByCos(uint16 a); -uint16 Math_MultBySin(uint16 a); -uint16 Math_MultBySinCos(uint16 a); -uint16 MoveEprojWithVelocity(uint16 k); -uint16 MoveEprojWithVelocityX(uint16 k); -uint16 MoveEprojWithVelocityY(uint16 k); +uint16 Eproj_PhantomFireballs_Func2(uint16 k, uint16 r24); uint16 RandomDropRoutine(uint16 k); -uint16 sub_86B13E(uint16 k, uint16 j); -uint16 sub_86B183(uint16 k, uint16 j); +const uint8 *sub_86B13E(uint16 k, const uint8 *epjp); uint16 sub_86DFA0(uint16 k); uint16 sub_86E0B0(uint16 k); uint16 sub_86EC18(uint16 k); uint8 CheckForBlueRingCollisionWithRoom(uint16 k); uint8 CheckForCollisionWithShitroid_DoubleRet(uint16 k); -uint8 EnemyProjectileBlockCollisition_CheckHorizontal(uint16 k); -uint8 EnemyProjectileBlockCollisition_CheckVertical(uint16 k); uint8 EnemyProjectileBlockCollisition_Horiz(uint16 k); uint8 EnemyProjectileBlockCollisition_Vertical(uint16 k); -uint8 EprojColl_8506(void); -uint8 EprojColl_858E(void); -uint8 EprojColl_85AD(void); -uint8 EprojColl_85C2(uint16 a, uint16 k); -uint8 EprojColl_8676(uint16 a, uint16 k, uint16 j); uint8 EprojColl_873D(void); -uint8 EprojColl_874E(void); -uint8 EprojColl_ClearCarry(void); -uint8 EprojColl_SetCarry(void); -uint8 EprojColl_Unknown8536(void); -uint8 Eproj_CheckForBombCollisionWithRect(void); -uint8 Eproj_CheckForCollisionWithSamus(uint16 k); -uint8 Eproj_CheckForEnemyCollisionWithRect(uint16 k); uint8 Eproj_MotherBrainRoomTurretBullets_CheckIfTurretOnScreen(uint16 k); uint8 MotherBrainBomb_Bomb_CollDetect_DoubleRet(uint16 k); uint8 MoveMotherBrainBomb(uint16 k, uint16 a); void BlueRingContactExplosion(uint16 k); void ClearEnemyProjectiles(void); void DisableEnemyProjectiles(void); -void DrawEnemyProjectiles(uint16 k); +void DrawEnemyProjectiles(uint16 k, Point16U pt); void DrawHighPriorityEnemyProjectiles(void); void DrawLowPriorityEnemyProjectiles(void); void EnableEnemyProjectiles(void); -uint16 EprojInstr_SetPreInstrB(uint16 k, uint16 j); -uint16 EprojInstr_SpawnEnemyDropsWithDraygonsEyeDrops(uint16 k, uint16 j); -void EnemyProj_Init_0x8aaf(uint16 j); -void EnemyProj_Init_0x8bc2_SkreeDownRight(uint16 j); -void EnemyProj_Init_0x8bd0_SkreeUpRight(uint16 j); -void EnemyProj_Init_0x8bde_SkreeDownLeft(uint16 j); -void EnemyProj_Init_0x8bec_SkreeUpLeft(uint16 j); -void EnemyProj_PreInit_0x8aaf(uint16 k); -void EnemyProj_PreInstr_SkreeParticle(uint16 k); -void EprojIni_TourianStatueUnlockingParticleTail(uint16 j); -void EprojInit_8E6C(uint16 j); -void EprojInit_9634(uint16 j); -void EprojInit_9642_RidleysFireball(uint16 j); -void EprojInit_9660_FireballExplosion(uint16 j); -void EprojInit_966C(uint16 j); -void EprojInit_967A(uint16 j); -void EprojInit_9688(uint16 j); -void EprojInit_9696(uint16 j); -void EprojInit_9734_CeresFallingDebris(uint16 j); -void EprojInit_A379(uint16 j); -void EprojInit_A977(uint16 j); -void EprojInit_AB07(uint16 j); -void EprojInit_BDA2(uint16 j); -void EprojInit_BombTorizoDeathExplosion(uint16 j); -void EprojInit_BombTorizoExplosiveSwipe(uint16 j); -void EprojInit_BombTorizoLowHealthDrool(uint16 j); -void EprojInit_BombTorizoLowHealthExplode(uint16 j); -void EprojInit_BombTorizoLowHealthInitialDrool(uint16 j); -void EprojInit_BombTorizoStatueBreaking(uint16 j); -void EprojInit_BombTorizosChozoOrbs(uint16 j); -void EprojInit_BotwoonsBody(uint16 j); -void EprojInit_BotwoonsSpit(uint16 j); -void EprojInit_CeresElevatorPad(uint16 j); -void EprojInit_CeresElevatorPlatform(uint16 j); -void EprojInit_ClosedDownwardsShotGate(uint16 j); -void EprojInit_ClosedUpwardsShotGate(uint16 j); -void EprojInit_Common(uint16 j, uint16 k, uint16 a); -void EprojInit_CrocomireBridgeCrumbling(uint16 j); -void EprojInit_CrocomireProjectile(uint16 j); -void EprojInit_CrocomireSpikeWallPieces(uint16 j); -void EprojInit_DBF2(uint16 j); -void EprojInit_DraygonsGunk(uint16 j); -void EprojInit_DraygonsWallTurretProjs(uint16 j); -void EprojInit_EnemyDeathExplosion(uint16 j); -void EprojInit_EyeDoorProjectile(uint16 j); -void EprojInit_EyeDoorSmoke(uint16 j); -void EprojInit_EyeDoorSweat(uint16 j); -void EprojInit_F337(uint16 j); -void EprojInit_GoldenTorizoEgg(uint16 j); -void EprojInit_GoldenTorizoEyeBeam(uint16 j); -void EprojInit_GoldenTorizoSuperMissile(uint16 j); -void EprojInit_GoldenTorizosChozoOrbs(uint16 j); -void EprojInit_KagosBugs(uint16 j); -void EprojInit_KiHunterAcidSpitCommon(uint16 k, uint16 j); -void EprojInit_KiHunterAcidSpitLeft(uint16 j); -void EprojInit_KiHunterAcidSpitRight(uint16 j); -void EprojInit_LavaSeahorseFireball(uint16 j); -void EprojInit_LavaThrownByLavaman(uint16 j); -void EprojInit_MaridiaFloatersSpikes(uint16 j); -void EprojInit_MiniKraidSpikes(uint16 j, uint16 a); -void EprojInit_MiniKraidSpikesLeft(uint16 j); -void EprojInit_MiniKraidSpikesRight(uint16 j); -void EprojInit_MiniKraidSpit(uint16 j); -void EprojInit_MotherBrainBomb(uint16 j); -void EprojInit_MotherBrainDeathBeemFired(uint16 j); -void EprojInit_MotherBrainEscapeDoorParticles(uint16 j); -void EprojInit_MotherBrainGlassShatteringShard(uint16 j); -void EprojInit_MotherBrainGlassShatteringSparkle(uint16 j); -void EprojInit_MotherBrainPurpleBreathBig(uint16 j); -void EprojInit_MotherBrainPurpleBreathSmall(uint16 j); -void EprojInit_MotherBrainRainbowBeam(uint16 j); -void EprojInit_MotherBrainRoomTurretBullets(uint16 j); -void EprojInit_MotherBrainRoomTurrets(uint16 j); -void EprojInit_MotherBrainTubeFalling(uint16 j); -void EprojInit_MotherBrainsDeathExplosion(uint16 j); -void EprojInit_MotherBrainsDrool(uint16 j); -void EprojInit_MotherBrainsDrool_Falling(uint16 k); -void EprojInit_MotherBrainsRainbowBeamExplosion(uint16 j); -void EprojInit_N00bTubeCrack(uint16 j); -void EprojInit_N00bTubeReleasedAirBubbles(uint16 j); -void EprojInit_N00bTubeShards(uint16 j); -void EprojInit_NamiFuneFireball(uint16 j); -void EprojInit_NamiFuneFireball_MoveX1(uint16 k); -void EprojInit_NamiFuneFireball_MoveX2(uint16 k); -void EprojInit_NorfairLavaquakeRocks(uint16 j); -void EprojInit_NuclearWaffleBody(uint16 j); -void EprojInit_PhantoonDestroyableFireballs(uint16 j); -void EprojInit_PhantoonStartingFireballs(uint16 j); -void EprojInit_PirateClaw(uint16 j); -void EprojInit_PirateMotherBrainLaser(uint16 j); -void EprojInit_RocksFallingKraidCeiling(uint16 j); -void EprojInit_RocksKraidSpits(uint16 j); -void EprojInit_RocksWhenKraidRises(uint16 j); -void EprojInit_SaveStationElectricity(uint16 j); -void EprojInit_ShaktoolAttackFrontCircle(uint16 k); -void EprojInit_ShaktoolAttackMiddleBackCircle(uint16 j); -void EprojInit_Sparks(uint16 j); -void EprojInit_SpawnedGate_Common(uint16 j, uint16 a); -void EprojInit_SpawnedShotGate(uint16 j); -void EprojInit_SporeSpawnStalk(uint16 j); -void EprojInit_SporeSpawners(uint16 j); -void EprojInit_Spores(uint16 j); -void EprojInit_TimeBombSetJapaneseText(uint16 j); -void EprojInit_TorizoLandingDustCloudLeftFoot(uint16 j); -void EprojInit_TorizoSonicBoom(uint16 j); -void EprojInit_TourianEscapeShaftFakeWallExplode(uint16 j); -void EprojInit_TourianLandingDustCloudsRightFoot(uint16 j); -void EprojInit_TourianStatueBaseDecoration(uint16 j); -void EprojInit_TourianStatueDustClouds(uint16 j); -void EprojInit_TourianStatueEyeGlow(uint16 j); -void EprojInit_TourianStatuePhantoon(uint16 j); -void EprojInit_TourianStatueRidley(uint16 j); -void EprojInit_TourianStatueSoul(uint16 j); -void EprojInit_TourianStatueUnlockingParticle(uint16 j); -void EprojInit_TourianStatueUnlockingParticleWaterSplash(uint16 j); -void EprojInit_WalkingLavaSeahorseFireball(uint16 j); -void EprojInit_WreckedShipChozoSpikeFootsteps(uint16 j); -void EprojInit_WreckedShipRobotLaserCommon(uint16 k, uint16 j); -void EprojInit_WreckedShipRobotLaserDown(uint16 j); -void EprojInit_WreckedShipRobotLaserHorizontal(uint16 j); -void EprojInit_WreckedShipRobotLaserUp(uint16 j); -void EprojInit_YappingMawsBody(uint16 j); -void EprojInst_DustCloudOrExplosion(uint16 j); -void EprojPowerBombCollision(uint16 k); -void EprojPreInit_MiniKraidSpit(uint16 k); -void EprojPreInit_MotherBrainsDeathExplosion_0(uint16 k); -void EprojPreInstrHelper_SpikeShootingPlantSpikes_Func1(uint16 k); -void EprojPreInstr_8DCA(uint16 k); -void EprojPreInstr_8E6C(uint16 k); -void EprojPreInstr_9634(uint16 k); -void EprojPreInstr_9642_RidleysFireball(uint16 k); -void EprojPreInstr_966C(uint16 k); -void EprojPreInstr_9688(uint16 k); -void EprojPreInstr_96A4(uint16 k); -void EprojPreInstr_96C0(uint16 k); -void EprojPreInstr_96CE(uint16 k); -void EprojPreInstr_9734_CeresFallingDebris(uint16 k); -void EprojPreInstr_A977(uint16 k); -void EprojPreInstr_AB07(uint16 k); -void EprojPreInstr_B237(uint16 k); -void EprojPreInstr_BA42(uint16 k); -void EprojPreInstr_BE12(uint16 k); -void EprojPreInstr_BombTorizosChozoOrbs(uint16 k); -void EprojPreInstr_BotwoonsBody(uint16 k); -void EprojPreInstr_BotwoonsSpit(uint16 k); -void EprojPreInstr_C84D(uint16 k); -void EprojPreInstr_CeresElevatorPad(uint16 k); -void EprojPreInstr_CeresElevatorPlatform(uint16 k); -void EprojPreInstr_CrocomireBridgeCrumbling(uint16 k); -void EprojPreInstr_CrocomireProjectile(uint16 k); -void EprojPreInstr_CrocomireSpikeWallPieces(uint16 k); -void EprojPreInstr_D0EC(uint16 k); -void EprojPreInstr_D128(uint16 k); -void EprojPreInstr_DBF2(uint16 k); -void EprojPreInstr_DBF2_Func1(uint16 k); -void EprojPreInstr_DBF2_MoveX1(uint16 k); -void EprojPreInstr_DBF2_MoveX2(uint16 k); -void EprojPreInstr_DraygonsGunk_8E0F(uint16 k); -void EprojPreInstr_DraygonsTurret_8DFF(uint16 k); -void EprojPreInstr_DustCloudOrExplosion(uint16 k); -void EprojPreInstr_E605(uint16 k); -void EprojPreInstr_Empty(uint16 k); -void EprojPreInstr_Empty2(uint16 k); -void EprojPreInstr_EyeDoorProjectile(uint16 k); -void EprojPreInstr_EyeDoorSweat(uint16 k); -void EprojPreInstr_GoldenTorizoEgg(uint16 k); -void EprojPreInstr_GoldenTorizoEyeBeam(uint16 k); -void EprojPreInstr_GoldenTorizoSuperMissile(uint16 k); -void EprojPreInstr_GoldenTorizosChozoOrbs(uint16 k); -void EprojPreInstr_KagosBugs(uint16 k); -void EprojPreInstr_KagosBugs_Func1(uint16 k); -void EprojPreInstr_KagosBugs_Func2(uint16 k); -void EprojPreInstr_KraidRocks(uint16 k); -void EprojPreInstr_MaridiaFloatersSpikes(uint16 k); -void EprojPreInstr_MiniKraidSpikes(uint16 k); -void EprojPreInstr_MotherBrainBomb(uint16 k); -void EprojPreInstr_MotherBrainGlassShatteringShard(uint16 k); -void EprojPreInstr_MotherBrainRainbowBeam(uint16 k); -void EprojPreInstr_MotherBrainRoomTurretBullets(uint16 k); -void EprojPreInstr_MotherBrainRoomTurrets(uint16 k); -void EprojPreInstr_MotherBrainTubeFalling(uint16 k); -void EprojPreInstr_MotherBrainsExplodedDoorParticles(uint16 k); -void EprojPreInstr_MotherBrainsRainbowBeamExplosion(uint16 k); -void EprojPreInstr_N00bTubeShards(uint16 k); -void EprojPreInstr_NamiFuneFireball(uint16 k); -void EprojPreInstr_NorfairLavaquakeRocks(uint16 k); -void EprojPreInstr_NorfairLavaquakeRocks_Inner(uint16 k); -void EprojPreInstr_PhantoonDestroyableFireballs(uint16 k); -void EprojPreInstr_PhantoonDestroyableFireballs_2(uint16 k); -void EprojPreInstr_PhantoonDestroyableFireballs_3(uint16 k); -void EprojPreInstr_PhantoonStartingFireballs(uint16 k); -void EprojPreInstr_PhantoonStartingFireballs2(uint16 k); -void EprojPreInstr_PhantoonStartingFireballs3(uint16 k); -void EprojPreInstr_PhantoonStartingFireballsB(uint16 k); -void EprojPreInstr_PhantoonStartingFireballsB_2(uint16 k); -void EprojPreInstr_Pickup(uint16 k); -void EprojPreInstr_PirateClawThrownLeft(uint16 k); -void EprojPreInstr_PirateClawThrownRight(uint16 k); -void EprojPreInstr_PirateMotherBrainLaser_MoveLeft(uint16 k); -void EprojPreInstr_PirateMotherBrainLaser_MoveRight(uint16 k); -void EprojPreInstr_PrePhantomRoom(uint16 j); -void EprojPreInstr_RocksFallingKraidCeiling(uint16 k); -void EprojPreInstr_Sparks(uint16 k); -void EprojPreInstr_SpikeShootingPlantSpikes(uint16 k); -void EprojPreInstr_SpikeShootingPlantSpikes_0_MoveX1(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_1_MoveY1(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_2_MoveX2(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_4_MoveY2(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_6_MoveX1Y1(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_7_MoveX2Y1(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_8_MoveX1Y2(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_9_MoveX2Y2(uint16 j); -void EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(uint16 k); -void EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(uint16 k); -void EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(uint16 k); -void EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(uint16 k); -void EprojPreInstr_SporeSpawners(uint16 k); -void EprojPreInstr_Spores(uint16 k); -void EprojPreInstr_TimeBombSetJapaneseText(uint16 k); -void EprojPreInstr_TorizoSonicBoom(uint16 k); -void EprojPreInstr_TourianStatueSoul(uint16 k); -void EprojPreInstr_TourianStatueStuff(uint16 k); -void EprojPreInstr_TourianStatueUnlockingParticle(uint16 k); -void EprojPreInstr_TourianStatueUnlockingParticleWaterSplash(uint16 k); -void EprojPreInstr_WalkingLavaSeahorseFireball(uint16 k); -void EprojPreInstr_WreckedShipRobotLaser(uint16 k); -void EprojPreInstr_nullsub_297(void); -void EprojPreInstr_nullsub_83(void); -void EprojPreInstr_nullsub_98(void); -void EprojPreInstr_nullsub_99(void); + void EprojRunAll(void); -void EprojRunOne(uint16 k); -void Eproj_AngleToSamus(uint16 j); +void Eproj_AngleToSamus(uint16 j, uint16 r18, uint16 r20); void Eproj_BotwonsBodyFunction_Dying(uint16 k); void Eproj_BotwonsBodyFunction_Dying2(uint16 k); void Eproj_BotwonsBodyFunction_DyingFalling(uint16 k); @@ -1320,8 +717,6 @@ void Eproj_BotwoonsBody_Main(uint16 k); void Eproj_DeleteIfYposOutside(uint16 k); void Eproj_Earthqhake5(uint16 k); void Eproj_FuncE73E_MoveXY(uint16 k); -void Eproj_InitForCollDetect(uint16 k); -void Eproj_InitXYVelRandom(uint16 j, uint16 k); void Eproj_LavaThrownByLavaman_MoveX1(uint16 k); void Eproj_LavaThrownByLavaman_MoveX2(uint16 k); void Eproj_MotherBrainRoomTurretBullets_Func2(uint16 k); @@ -1331,18 +726,17 @@ void Eproj_NamiFuneFireball_After(uint16 k); void Eproj_NorfairLavaquakeRocks_Func1(uint16 k); void Eproj_NorfairLavaquakeRocks_Func2(uint16 k); void Eproj_NorfairLavaquakeRocks_Func3(uint16 k); -void Eproj_PhantomFireballs_Func1(uint16 j, uint16 a); +Point16U Eproj_PhantomFireballs_Func1(uint16 j, uint16 a); void Eproj_Pickup_BigHealth(void); void Eproj_Pickup_Missiles(void); void Eproj_Pickup_PowerBombs(void); void Eproj_Pickup_SmallHealth(void); void Eproj_Pickup_SuperMissiles(void); -uint16 EprojInstr_SetVelTowardsSamus1(uint16 k, uint16 j); -uint16 EprojInstr_SetVelTowardsSamus2(uint16 k, uint16 j); +const uint8 *EprojInstr_SetVelTowardsSamus1(uint16 k, const uint8 *epjp); +const uint8 *EprojInstr_SetVelTowardsSamus2(uint16 k, const uint8 *epjp); void Eproj_SetXvelRandom(uint16 k); void Eproj_SetYvelRandom(uint16 k); -void GetValuesForScreenShaking(void); -void Math_Mult16U(void); +Point16U GetValuesForScreenShaking(void); void MotherBrainTubeFallingFunc_Falling(uint16 k); void MotherBrainTubeFallingFunc_GenerateExplosion(uint16 k); void QueueSmallExplosionSfx(void); @@ -1352,32 +746,6 @@ void SetAreaDependentEprojPropertiesEx(uint16 k, uint16 j); void SpawnEnemyProjectileWithGfx(uint16 a, uint16 k, uint16 j); void SpawnEnemyProjectileWithRoomGfx(uint16 j, uint16 a); void SpawnMotherBrainDeathBeam(uint16 k); -void sub_8690B3(uint16 k); -void sub_869DA5(uint16 k); -void sub_86A301(uint16 j); -void sub_86A887(uint16 k); -void sub_86A91A(uint16 v0); -void sub_86B0B9(uint16 k); -void sub_86B0DD(uint16 k); -void sub_86B279(uint16 k, uint16 a); -void sub_86B535(uint16 k); -void sub_86BB30(uint16 j); -void sub_86C320(uint16 k); -void sub_86C42E(uint16 k); -void sub_86C605(uint16 j); -void sub_86CFD5(uint16 k); -void sub_86CFE6(uint16 k); -void sub_86CFF8(uint16 k); -void sub_86D7BF(uint16 k); -void sub_86D7DE(uint16 k); -void sub_86D83D(uint16 k); -void sub_86D89F(uint16 k); -void sub_86D8DF(uint16 k); -void sub_86D992(uint16 k); -void sub_86DCC3(uint16 j); -void sub_86E049(uint16 k); -void sub_86E0A4(uint16 k); -void sub_86EC0C(uint16 k); // Bank 87 uint16 AnimtilesInstr_Clear3PaletteColors(uint16 k, uint16 j); @@ -1415,60 +783,9 @@ void SpawnAnimtiles(uint16 j); uint16 CalculatePowerBombHdmaScaled_LeftOfScreen(uint16 k, uint16 j, uint8 multval); uint16 CalculatePowerBombHdmaScaled_OnScreen(uint16 k, uint16 j, uint8 multval); uint16 CalculatePowerBombHdmaScaled_RightOfScreen(uint16 k, uint16 j, uint8 multval); -const uint8 *HdmaobjInsr_ConfigTitleSequenceGradientHDMA(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_1938_RandomNumber(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_B3A9(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_CallFarFunc(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_ClearPreInstr(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_DecrementAndGoto(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_DecrementAndGotoRel(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_Delete(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_E4BD(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_EC9F_ClearVars(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_Goto(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_GotoIfEventHappened(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_GotoRel(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_InitMorphBallEyeBeamHdma(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetFlagB(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetFlagB_Copy(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetFlagB_Copy2(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetFlagB_Copy3(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetHdmaControl(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetHdmaTableBank(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetHdmaTablePtr(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetHdmaTarget(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetIndirectHdmaDataBank(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetPreInstr(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetTimer(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_SetVideoMode1(uint16 k, const uint8 *hdp); -const uint8 *HdmaobjInstr_Sleep(uint16 k, const uint8 *hdp); -uint16 LayerBlendFunc_10(uint16 j); -uint16 LayerBlendFunc_14(uint16 j); -uint16 LayerBlendFunc_16(uint16 j); -uint16 LayerBlendFunc_18(uint16 j); -uint16 LayerBlendFunc_1A(uint16 j); -uint16 LayerBlendFunc_1C(uint16 j); -uint16 LayerBlendFunc_24(uint16 j); -uint16 LayerBlendFunc_26(uint16 j); -uint16 LayerBlendFunc_28(uint16 j); -uint16 LayerBlendFunc_2A(uint16 j); -uint16 LayerBlendFunc_2C(uint16 j); -uint16 LayerBlendFunc_2E(uint16 j); -uint16 LayerBlendFunc_32(uint16 j); -uint16 LayerBlendFunc_34(uint16 j); -uint16 LayerBlendFunc_4_PhantoonIntro(uint16 j); -uint16 LayerBlendFunc_6(uint16 j); -uint16 LayerBlendFunc_8(uint16 j); -uint16 LayerBlendFunc_A(uint16 j); -uint16 LayerBlendFunc_C(uint16 j); uint16 MotherBrainRisingHdmaObject(void); -uint16 SetupSomeHdmaTablesBG3(void); uint16 SpawnHdmaObject(uint8 db, const void* p); -uint16 SpawnHdmaObjectInner(uint16 k, uint16 *p); uint16 SpawnMotherBrainRainbowBeamHdma(void); -uint16 nullsub_10(uint16 j); -uint16 nullsub_11(uint16 j); -uint16 nullsub_9(uint16 j); uint8 AdvanceSuitPickupColorMathSubscreenToWhite(void); uint8 AdvanceSuitPickupColorMathToBlue(void); uint8 AdvanceSuitPickupColorMathToOrange(void); @@ -1529,63 +846,9 @@ void HandleMovingXrayUpDown(void); void Handle_LavaAcidBG2YScroll_Func1(uint16 k); void Handle_LavaAcidBG2YScroll_Func2(uint16 k); void Handle_LavaAcidBG2YScroll_Func3(uint16 k); -void HdmaFunc_A786(uint16 k); +uint16 HdmaFunc_A786(uint16 k, uint16 r18, uint16 r20, uint16 r22); void HdmaObjectHandler(void); void HdmaobjInstructionHandler(uint8 k); -void HdmaobjPreInstr_BG3Xscroll(uint16 k); -void HdmaobjPreInstr_Backdrop_TitleSequenceGradient(uint16 k); -void HdmaobjPreInstr_BombTorizoHazeColorMathBgColor(uint16 k); -void HdmaobjPreInstr_CheckLotsOfEventsHappened(uint16 k); -void HdmaobjPreInstr_ColorMathControlB_TitleGradient(uint16 k); -void HdmaobjPreInstr_CrystalFlash_CustomLayerBlend(uint16 k); -void HdmaobjPreInstr_CrystalFlash_Stage1_Explosion(uint16 k); -void HdmaobjPreInstr_CrystalFlash_Stage2_AfterGlow(uint16 k); -void HdmaobjPreInstr_DC23(uint16 k); -void HdmaobjPreInstr_DC69(uint16 k); -void HdmaobjPreInstr_DCBA(uint16 k); -void HdmaobjPreInstr_DF94(uint16 k); -void HdmaobjPreInstr_E449(uint16 k); -void HdmaobjPreInstr_E567(uint16 k); -void HdmaobjPreInstr_E7BC(uint16 k); -void HdmaobjPreInstr_E9E6(uint16 k); -void HdmaobjPreInstr_EA3C(uint16 k); -void HdmaobjPreInstr_EACB(uint16 k); -void HdmaobjPreInstr_ECB6(uint16 k); -void HdmaobjPreInstr_FirefleaBG3XScroll(uint16 k); -void HdmaobjPreInstr_FogBG3Scroll(uint16 k); -void HdmaobjPreInstr_FxType22_BG3Yscroll(uint16 k); -void HdmaobjPreInstr_GravitySuitPickup(uint16 k); -void HdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyAlive(uint16 k); -void HdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyDead(uint16 k); -void HdmaobjPreInstr_HazeColorMathSubscreen_FadedIn(uint16 k); -void HdmaobjPreInstr_HazeColorMathSubscreen_FadingIn(uint16 k); -void HdmaobjPreInstr_HazeColorMathSubscreen_FadingOut(uint16 k); -void HdmaobjPreInstr_IntroCutsceneCrossfade(uint16 k); -void HdmaobjPreInstr_LavaAcidBG2YScroll(uint16 k); -void HdmaobjPreInstr_LavaAcidBG3YScroll(uint16 k); -void HdmaobjPreInstr_PowerBombExplode_ExplosionWhite(uint16 k); -void HdmaobjPreInstr_PowerBombExplode_ExplosionYellow(uint16 k); -void HdmaobjPreInstr_PowerBombExplode_PreExplosionWhite(uint16 k); -void HdmaobjPreInstr_PowerBombExplode_PreExplosionYellow(uint16 k); -void HdmaobjPreInstr_PowerBombExplode_SetWindowConf(uint16 k); -void HdmaobjPreInstr_PowerBombExplode_Stage5_Afterglow(uint16 k); -void HdmaobjPreInstr_RainBg3Scroll(uint16 k); -void HdmaobjPreInstr_SkyLandBG2Xscroll(uint16 k); -void HdmaobjPreInstr_SkyLandBG2Xscroll2(uint16 k); -void HdmaobjPreInstr_SkyLandBG2XscrollInner(uint16 k); -void HdmaobjPreInstr_SporesBG3Xscroll(uint16 k); -void HdmaobjPreInstr_VariaSuitPickup(uint16 k); -void HdmaobjPreInstr_WaterBG2XScroll(uint16 k); -void HdmaobjPreInstr_WaterBG2XScroll_Func1(uint16 k); -void HdmaobjPreInstr_WaterBG2XScroll_Func2(uint16 k); -void HdmaobjPreInstr_WaterBG3XScroll(uint16 k); -void HdmaobjPreInstr_Xray(uint16 k); -void HdmaobjPreInstr_XrayFunc0_NoBeam(uint16 k); -void HdmaobjPreInstr_XrayFunc1_BeamWidening(uint16 k); -void HdmaobjPreInstr_XrayFunc2_FullBeam(uint16 k); -void HdmaobjPreInstr_XrayFunc3_DeactivateBeam(uint16 k); -void HdmaobjPreInstr_XrayFunc4_DeactivateBeam(uint16 k); -void HdmaobjPreInstr_XrayFunc5_DeactivateBeam(uint16 k); void Hdmaobj_CleanUpTryCrystalFlash(uint16 k); void Hdmaobj_ExplodeWhite(void); void Hdmaobj_ExplodeYellow(void); @@ -1594,15 +857,11 @@ void Hdmaobj_PreExplodeYellow(void); void InitializeLayerBlending(void); void InitializeRainbowBeam(void); void InitializeSpecialEffectsForNewRoom(void); -void LayerBlendPowerBombFunc_0(void); -void LayerBlendPowerBombFunc_4(void); -void LayerBlendPowerBombFunc_6(void); void LayerBlendingHandler(void); void MoveXrayDown(void); void MoveXrayUp(void); -void PauseHook_Empty(void); void RoomCode_ScrollingSkyLand(void); -void RoomMainAsm_ScrollingSky(void); +void RoomMainAsm_ScrollingSky(LongPtr ptr); void RoomMainAsm_ScrollingSkyOcean(void); void RoomSetupAsm_ScrollingSkyOcean(void); void SpawnBG3ScrollHdmaObject(void); @@ -1617,13 +876,12 @@ void WaitUntilEndOfVblankAndClearHdma(void); void sub_8882AC(void); void sub_88D916(void); -void sub_88DA9F(uint16 k); void sub_88DBCB(uint16 k); void sub_88DE18(uint16 k, uint16 a); void sub_88DF34(void); void sub_88DF3D(void); void sub_88DF46(void); -void sub_88E487(uint16 a); +void sub_88E487(uint16 a, uint16 r22); void sub_88E7ED(void); void sub_88E987(uint16 k); @@ -1634,88 +892,8 @@ void RoomCode_CeresElevatorShaft(void); // Bank 8B uint16 CalcItemPercentageCount(uint16 k, uint16 j); -uint16 CalcSinMult(uint16 k); -uint16 CinematicBgInstr_Delete(uint16 k, uint16 j); -uint16 CinematicBgInstr_Func16(uint16 k, uint16 j); -uint16 CinematicBgInstr_Func17(uint16 k, uint16 j); -uint16 CinematicBgInstr_Goto(uint16 k, uint16 j); -uint16 CinematicBgInstr_HandleCreateJpnText_Page1(uint16 k, uint16 j); -uint16 CinematicBgInstr_HandleCreateJpnText_Page2(uint16 k, uint16 j); -uint16 CinematicBgInstr_HandleCreateJpnText_Page3(uint16 k, uint16 j); -uint16 CinematicBgInstr_HandleCreateJpnText_Page4(uint16 k, uint16 j); -uint16 CinematicBgInstr_HandleCreateJpnText_Page5(uint16 k, uint16 j); -uint16 CinematicBgInstr_SetSomeStuffForSpriteObject_14(uint16 k, uint16 j); -uint16 CinematicBgInstr_SpawnMarkerWaitInput_Page1(uint16 k, uint16 j); -uint16 CinematicBgInstr_SpawnMarkerWaitInput_Page2(uint16 k, uint16 j); -uint16 CinematicBgInstr_SpawnMarkerWaitInput_Page3(uint16 k, uint16 j); -uint16 CinematicBgInstr_SpawnMarkerWaitInput_Page4(uint16 k, uint16 j); -uint16 CinematicBgInstr_SpawnMarkerWaitInput_Page5(uint16 k, uint16 j); -uint16 CinematicCommonInstr_Func69(uint16 k, uint16 j); -uint16 CinematicCommonInstr_Func70(uint16 k, uint16 j); -uint16 CinematicFunction_Intro_Func146(uint16 k, uint16 j); -uint16 CinematicFunction_Intro_Func147(uint16 k, uint16 j); -uint16 CinematicFunction_Intro_Func219(uint16 k, uint16 j); -uint16 CinematicGetTilemapOffsetForTile(void); -uint16 CinematicSetPal1(uint16 k, uint16 j); -uint16 CinematicSetPal2(uint16 k, uint16 j); -uint16 CinematicSetPal3(uint16 k, uint16 j); -uint16 CinematicSetPal4(uint16 k, uint16 j); -uint16 CinematicSprInstr_9CE1(uint16 k, uint16 j); -uint16 CinematicSprInstr_9D5D(uint16 k, uint16 j); -uint16 CinematicSprInstr_9DD6(uint16 k, uint16 j); -uint16 CinematicSprInstr_9F19(uint16 k, uint16 j); -uint16 CinematicSprInstr_C9A5(uint16 k, uint16 j); -uint16 CinematicSprInstr_C9AF(uint16 k, uint16 j); -uint16 CinematicSprInstr_C9BD(uint16 k, uint16 j); -uint16 CinematicSprInstr_C9C7(uint16 k, uint16 j); -uint16 CinematicSprInstr_CallFunc(uint16 k, uint16 j); -uint16 CinematicSprInstr_CallFuncWithArg(uint16 k, uint16 j); -uint16 CinematicSprInstr_ClearPreInstr(uint16 k, uint16 j); -uint16 CinematicSprInstr_DecTimerGoto(uint16 k, uint16 j); -uint16 CinematicSprInstr_DecTimerGotoRel(uint16 k, uint16 j); -uint16 CinematicSprInstr_Delete(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func181(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func182(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func183(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func185(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func186(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func187(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func190(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func192(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func193(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func194(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func195(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func196(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func197(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func198(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func208(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func211(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func213(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func214(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func217(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func218(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func43(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func8(uint16 k, uint16 j); -uint16 CinematicSprInstr_Func9(uint16 k, uint16 j); -uint16 CinematicSprInstr_Goto(uint16 k, uint16 j); -uint16 CinematicSprInstr_GotoRel(uint16 k, uint16 j); -uint16 CinematicSprInstr_SetPreInstr(uint16 k, uint16 j); -uint16 CinematicSprInstr_SetTimer(uint16 k, uint16 j); -uint16 CinematicSprInstr_Sleep(uint16 k, uint16 j); -uint16 CinematicSprInstr_SpawnCeresExplosions1(uint16 k, uint16 j); -uint16 CinematicSprInstr_SpawnCeresExplosions3(uint16 k, uint16 j); -uint16 CinematicSprInstr_SpawnIntroRinkas01(uint16 k, uint16 j); -uint16 CinematicSprInstr_SpawnIntroRinkas23(uint16 k, uint16 j); -uint16 CinematicSprInstr_SpawnMetroidEggParticles(uint16 k, uint16 j); -uint16 CinematicSprInstr_StartIntroPage2(uint16 k, uint16 j); -uint16 CinematicSprInstr_StartIntroPage3(uint16 k, uint16 j); -uint16 CinematicSprInstr_StartIntroPage4(uint16 k, uint16 j); -uint16 CinematicSprInstr_StartIntroPage5(uint16 k, uint16 j); -uint16 CinematicSprInstr_sub_8B9EF0(uint16 k, uint16 j); -uint16 IntroObject_DecTimerGoto(uint16 k, uint16 j); -uint16 IntroObject_Delete(uint16 k, uint16 j); -uint16 IntroObject_Goto(uint16 k, uint16 j); -uint16 IntroObject_SetTimer(uint16 k, uint16 j); +uint16 CalcSinMult(uint16 k, uint16 r24); +uint16 CinematicGetTilemapOffsetForTile(uint16 r18); uint16 Mode7Instr_ClearPreInstr(uint16 k, uint16 j); uint16 Mode7Instr_DecTimerAndGoto(uint16 k, uint16 j); uint16 Mode7Instr_Delete(uint16 k, uint16 j); @@ -1732,243 +910,11 @@ uint8 AdvanceSlowScreenFadeOut(void); uint8 SpawnCimenaticSpriteObjectInner(uint16 k, uint16 j); uint8 SpawnCinematicBgObject(uint16 j, uint16 a); uint8 SpawnCinematicSpriteObject(uint16 j, uint16 a); -uint8 SpawnCinematicSpriteObjectToR18(uint16 j, uint16 a); +uint8 SpawnCinematicSpriteObjectToR18(uint16 j, uint16 r18); uint8 SpawnMode7Object(uint16 j, uint16 a); void AddNintentoLogoToOam(void); -void CalcCeresSteamPos_Mode7(void); -void CalcExplosion_Mode7(uint16 k); -void CalcSinCos(uint16 a, uint16 j); -void CinematicBgPreInstr_SamusBlink(uint16 k); -void CinematicFunc_Func1(void); -void CinematicFunc_Func10(void); -void CinematicFunc_Func2(void); -void CinematicFunc_Func4(void); -void CinematicFunc_Func5(void); -void CinematicFunc_Func7(void); -void CinematicFunc_Func9(void); -void CinematicFunc_Intro_FadeOut(void); -void CinematicFunc_Intro_QueueGalaxyIsAtPeace(void); -void CinematicFunc_Intro_SetupTextPage2(void); -void CinematicFunc_Intro_WaitFadeinShowText(void); -void CinematicFunc_Intro_WaitForFadeOut(void); -void CinematicFunc_Intro_WaitForFadeinSleep(void); -void CinematicFunc_Intro_WaitForQueueWait4secs(void); -void CinematicFunc_Nothing(void); -void CinematicFunctionBlackoutFromCeres(void); -void CinematicFunctionEscapeFromCebes(void); -void CinematicFunctionNone(void); -void CinematicFunctionOpening(void); -void CinematicFunction_F0B8(uint16 j); -void CinematicFunction_Intro_DrawInitJpn(void); -void CinematicFunction_Intro_FadeIn(void); -void CinematicFunction_Intro_Fadestuff(void); -void CinematicFunction_Intro_Fadestuff2(void); -void CinematicFunction_Intro_Func100(uint16 j); -void CinematicFunction_Intro_Func101(uint16 j); -void CinematicFunction_Intro_Func102(uint16 j); -void CinematicFunction_Intro_Func104(uint16 j); -void CinematicFunction_Intro_Func105(void); -void CinematicFunction_Intro_Func106(void); -void CinematicFunction_Intro_Func107(void); -void CinematicFunction_Intro_Func108(void); -void CinematicFunction_Intro_Func109(void); -void CinematicFunction_Intro_Func11(void); -void CinematicFunction_Intro_Func110(void); -void CinematicFunction_Intro_Func111(void); -void CinematicFunction_Intro_Func112(void); -void CinematicFunction_Intro_Func113(void); -void CinematicFunction_Intro_Func114(void); -void CinematicFunction_Intro_Func115(void); -void CinematicFunction_Intro_Func116(void); -void CinematicFunction_Intro_Func117(void); -void CinematicFunction_Intro_Func118(void); -void CinematicFunction_Intro_Func119(void); -void CinematicFunction_Intro_Func12(void); -void CinematicFunction_Intro_Func120(void); -void CinematicFunction_Intro_Func121(void); -void CinematicFunction_Intro_Func122(void); -void CinematicFunction_Intro_Func123(void); -void CinematicFunction_Intro_Func124(void); -void CinematicFunction_Intro_Func125(void); -void CinematicFunction_Intro_Func126(void); -void CinematicFunction_Intro_Func127(void); -void CinematicFunction_Intro_Func128(uint16 a); -void CinematicFunction_Intro_Func129(void); -void CinematicFunction_Intro_Func13(void); -void CinematicFunction_Intro_Func130(void); -void CinematicFunction_Intro_Func131(void); -void CinematicFunction_Intro_Func132(void); -void CinematicFunction_Intro_Func134(void); -void CinematicFunction_Intro_Func135(void); -void CinematicFunction_Intro_Func136(void); -void CinematicFunction_Intro_Func137(void); -void CinematicFunction_Intro_Func138(void); -void CinematicFunction_Intro_Func139(void); -void CinematicFunction_Intro_Func140(void); -void CinematicFunction_Intro_Func141(void); -void CinematicFunction_Intro_Func142(void); -void CinematicFunction_Intro_Func143(void); -void CinematicFunction_Intro_Func144(void); -void CinematicFunction_Intro_Func145(void); -void CinematicFunction_Intro_Func148(void); -void CinematicFunction_Intro_Func149(void); -void CinematicFunction_Intro_Func15(void); -void CinematicFunction_Intro_Func150(uint16 j); -void CinematicFunction_Intro_Func151(uint16 k); -void CinematicFunction_Intro_Func152(uint16 j); -void CinematicFunction_Intro_Func153(uint16 j); -void CinematicFunction_Intro_Func154(uint16 j); -void CinematicFunction_Intro_Func155(uint16 j); -void CinematicFunction_Intro_Func156(uint16 j); -void CinematicFunction_Intro_Func157(uint16 j); -void CinematicFunction_Intro_Func158(uint16 j); -void CinematicFunction_Intro_Func159(uint16 j); -void CinematicFunction_Intro_Func15b(void); -void CinematicFunction_Intro_Func160(uint16 j, uint16 a); -void CinematicFunction_Intro_Func161(uint16 j); -void CinematicFunction_Intro_Func162(uint16 j); -void CinematicFunction_Intro_Func163(uint16 j); -void CinematicFunction_Intro_Func164(uint16 j); -void CinematicFunction_Intro_Func165(uint16 j); -void CinematicFunction_Intro_Func166(uint16 j); -void CinematicFunction_Intro_Func167(uint16 j); -void CinematicFunction_Intro_Func168(uint16 j); -void CinematicFunction_Intro_Func169(uint16 j); -void CinematicFunction_Intro_Func170(uint16 j); -void CinematicFunction_Intro_Func171(uint16 j); -void CinematicFunction_Intro_Func172(uint16 j); -void CinematicFunction_Intro_Func173(uint16 j); -void CinematicFunction_Intro_Func174(uint16 j); -void CinematicFunction_Intro_Func175(uint16 j); -void CinematicFunction_Intro_Func176(uint16 j); -void CinematicFunction_Intro_Func177(uint16 j); -void CinematicFunction_Intro_Func178(uint16 j); -void CinematicFunction_Intro_Func179(uint16 k); -void CinematicFunction_Intro_Func18(void); -void CinematicFunction_Intro_Func180(uint16 k); -void CinematicFunction_Intro_Func184(uint16 j); -void CinematicFunction_Intro_Func189(uint16 k); -void CinematicFunction_Intro_Func189b(uint16 k); -void CinematicFunction_Intro_Func19(uint16 k); -void CinematicFunction_Intro_Func191(uint16 k); -void CinematicFunction_Intro_Func199(uint16 k); -void CinematicFunction_Intro_Func20(uint16 j); -void CinematicFunction_Intro_Func200(uint16 k); -void CinematicFunction_Intro_Func201(uint16 k); -void CinematicFunction_Intro_Func202(uint16 k); -void CinematicFunction_Intro_Func203(uint16 k); -void CinematicFunction_Intro_Func204(uint16 k); -void CinematicFunction_Intro_Func205(uint16 k); -void CinematicFunction_Intro_Func206(uint16 k); -void CinematicFunction_Intro_Func207(uint16 k); -uint16 CinematicFunction_Intro_Func21(uint16 k, uint16 j); -void CinematicFunction_Intro_Func210_EndingSamusFall(uint16 k); -void CinematicFunction_Intro_Func215(uint16 k); -void CinematicFunction_Intro_Func216(void); -void CinematicFunction_Intro_Func22(uint16 k); -uint16 CinematicFunction_Intro_Func23(uint16 k, uint16 j); -void CinematicFunction_Intro_Func24(uint16 k); -uint16 CinematicFunction_Intro_Func25(uint16 k, uint16 j); -uint16 CinematicFunction_Intro_Func26(uint16 k, uint16 j); -void CinematicFunction_Intro_Func27(uint16 k); -uint16 CinematicFunction_Intro_Func28(uint16 k, uint16 j); -uint16 CinematicFunction_Intro_Func29(uint16 k, uint16 j); -void CinematicFunction_Intro_Func30(uint16 k); -uint16 CinematicFunction_Intro_Func31(uint16 k, uint16 j); -uint16 CinematicFunction_Intro_Func32(uint16 k, uint16 j); -void CinematicFunction_Intro_Func33(void); -void CinematicFunction_Intro_Func34(void); -void CinematicFunction_Intro_Func35(uint16 j); -void CinematicFunction_Intro_Func36(uint16 k); -void CinematicFunction_Intro_Func37(uint16 k); -void CinematicFunction_Intro_Func39(uint16 k); -void CinematicFunction_Intro_Func40(void); -void CinematicFunction_Intro_Func42(uint16 j); -void CinematicFunction_Intro_Func44(uint16 k); -void CinematicFunction_Intro_Func45(uint16 k); -void CinematicFunction_Intro_Func46(uint16 j); -void CinematicFunction_Intro_Func47(uint16 j); -void CinematicFunction_Intro_Func48(uint16 k); -void CinematicFunction_Intro_Func49(uint16 j); -void CinematicFunction_Intro_Func50(uint16 k); -void CinematicFunction_Intro_Func51(uint16 k); -void CinematicFunction_Intro_Func52(uint16 k); -void CinematicFunction_Intro_Func53(uint16 k); -void CinematicFunction_Intro_Func54(void); -void CinematicFunction_Intro_Func55(void); -void CinematicFunction_Intro_Func56(void); -void CinematicFunction_Intro_Func57(uint16 j); -void CinematicFunction_Intro_Func58(uint16 k); -void CinematicFunction_Intro_Func59(uint16 j); -void CinematicFunction_Intro_Func60(uint16 k); -void CinematicFunction_Intro_Func61(uint16 j); -void CinematicFunction_Intro_Func62(uint16 k); -void CinematicFunction_Intro_Func63(uint16 j); -void CinematicFunction_Intro_Func64(uint16 k); -void CinematicFunction_Intro_Func65(uint16 j); -void CinematicFunction_Intro_Func66(uint16 k); -void CinematicFunction_Intro_Func67(void); -void CinematicFunction_Intro_Func68(uint16 j); -void CinematicFunction_Intro_Func71(uint16 j); -void CinematicFunction_Intro_Func72(void); -void CinematicFunction_Intro_Func73(void); -void CinematicFunction_Intro_Func74(void); -void CinematicFunction_Intro_Func75(void); -void CinematicFunction_Intro_Func76(void); -void CinematicFunction_Intro_Func77(void); -void CinematicFunction_Intro_Func78(uint16 j); -void CinematicFunction_Intro_Func80(uint16 j); -void CinematicFunction_Intro_Func81(uint16 j); -void CinematicFunction_Intro_Func82(uint16 k); -void CinematicFunction_Intro_Func83(uint16 j); -void CinematicFunction_Intro_Func84(void); -void CinematicFunction_Intro_Func85(void); -void CinematicFunction_Intro_Func86(void); -void CinematicFunction_Intro_Func87(void); -void CinematicFunction_Intro_Func88(void); -void CinematicFunction_Intro_Func89(uint16 j); -void CinematicFunction_Intro_Func90(uint16 k); -void CinematicFunction_Intro_Func91(uint16 k); -void CinematicFunction_Intro_Func92(uint16 j); -void CinematicFunction_Intro_Func93(uint16 k); -void CinematicFunction_Intro_Func94(uint16 k); -void CinematicFunction_Intro_Func95(void); -void CinematicFunction_Intro_Func96(uint16 k); -void CinematicFunction_Intro_Func97(uint16 k); -void CinematicFunction_Intro_Func98(uint16 j); -void CinematicFunction_Intro_Func99(uint16 j); -void CinematicFunction_Intro_Initial(void); -void CinematicFunction_Intro_LastMetroidCaptivity(void); -void CinematicFunction_Intro_Page2(void); -void CinematicFunction_Intro_Page3(void); -void CinematicFunction_Intro_Page4(void); -void CinematicFunction_Intro_Page5(void); -void CinematicFunction_Intro_SetupStuff(void); -void CinematicFunction_Intro_SetupTransitionToGameplay(void); -uint16 CinematicFunction_Intro_ThenWaitInputSetupBabyMetroid(uint16 k, uint16 j); -void CinematicFunction_Intro_WaitInputSetupBabyMetroid(void); -void CinematicFunction_Intro_WaitInputSetupMotherBrainFight(void); -void CinematicFunction_Intro_XfadeGameplayFade(void); -void CinematicFunction_Intro_XfadeScientistFade(void); -void CinematicFunction_nullsub_116(uint16 j); -void CinematicFunction_nullsub_298(void); -void CinematicSprPreInstr_A903(uint16 k); -void CinematicSprPreInstr_B82E(uint16 k); -void CinematicSprPreInstr_C489(uint16 k); -void CinematicSprPreInstr_F35A(uint16 k); -void CinematicSprPreInstr_F528(uint16 k); -void CinematicSprPreInstr_F57F(uint16 k); -void CinematicSprPreInstr_nullsub_300(void); -void CinematicSpriteInit_0(uint16 j); -void CinematicSpriteInit_1(uint16 j); -void CinematicSpriteInit_2(uint16 j); -void CinematicSpriteInit_3(uint16 j); -void CinematicSpriteInit_4(uint16 j); -void CinematicSpriteInit_5(uint16 j); -void CinematicSpriteInit_6(uint16 j); -void CinematicSpriteInit_7(uint16 j); -void CinematicSpriteInit_8(uint16 j); -void CinematicSpriteInit_9(uint16 j); +Point16U CalcCeresSteamPos_Mode7(Point16U pt); +Point16U CalcExplosion_Mode7(uint16 k); void CinematicUpdateSomeBg(void); void ClearCinematicBgObjects(uint16 a); void ClearCinematicSprites(void); @@ -2003,10 +949,6 @@ CoroutineRet GameState_39_EndingAndCredits_(void); void HandleCinematicBgObjects(void); void HandleCinematicSprites(void); void HandleCinematicsTransitions(void); -void HandleCinematicsTransitions_1(void); -void HandleCinematicsTransitions_2(void); -void HandleCinematicsTransitions_3(void); -void HandleFadeIn_(void); void HandleMode7Objects(void); void HandleMode7TransformationMatrix(void); void HandleMode7TransformationNoRotation(void); @@ -2017,15 +959,14 @@ void Instr_StartIntroPage_Common(void); void LoadTitleSequenceGraphics(void); void MaybeHandleCinematicBgObjects(void); void MaybeSkipCinematics(void); -void MoveUnusedSpritesOffScreen_IGNORE(void); -void Mult0x80Add(void); -void ProcessCinematicBgObject(uint16 k); -void ProcessCinematicBgObject_DrawChar(uint16 k, uint16 j); -void ProcessCinematicBgObject_DrawToBgTilemap(uint16 k, uint16 j); -void ProcessCinematicBgObject_DrawToTextTilemap(uint16 k, uint16 j); -void ProcessCinematicBgObject_Nothing(uint16 k, uint16 j); -void ProcessCinematicBgObject_Unk1(uint16 k, uint16 j); -void ProcessCinematicBgObject_Unk2(uint16 k, uint16 j); +uint16 Mult0x80Add(uint16 r18); +void ProcessCinematicBgObject(uint16 k, uint16 r18); +void ProcessCinematicBgObject_DrawChar(uint16 k, uint16 j, uint16 r18); +void ProcessCinematicBgObject_DrawToBgTilemap(uint16 k, uint16 j, uint16 r18); +void ProcessCinematicBgObject_DrawToTextTilemap(uint16 k, uint16 j, uint16 r18); +void ProcessCinematicBgObject_Nothing(uint16 k, uint16 j, uint16 r18); +void ProcessCinematicBgObject_Unk1(uint16 k, uint16 j, uint16 r18); +void ProcessCinematicBgObject_Unk2(uint16 k, uint16 j, uint16 r18); void ProcessCinematicBgObjectsInstrs(uint16 k); void ProcessCinematicSpriteInstructionList(uint16 k); void ProcessMode7ObjectInstructions(uint16 k); @@ -2035,21 +976,6 @@ void RevertButtonConfig(void); void Samus_CalcPos_Mode7(void); void SetPpuBackdropBlack(void); void SetPpuBackdropSomeColor(void); -void SetSomeStuffForSpriteObject_10(uint16 j); -void SetSomeStuffForSpriteObject_11(uint16 k); -void SetSomeStuffForSpriteObject_12(uint16 j); -void SetSomeStuffForSpriteObject_13(uint16 k); -void SetSomeStuffForSpriteObject_15(void); -void SetSomeStuffForSpriteObject_16(void); -void SetSomeStuffForSpriteObject_17(uint16 j); -void SetSomeStuffForSpriteObject_18(uint16 k); -void SetSomeStuffForSpriteObject_2(uint16 j); -void SetSomeStuffForSpriteObject_3(uint16 j); -void SetSomeStuffForSpriteObject_4_MetroidEgg(uint16 k); -void SetSomeStuffForSpriteObject_6(uint16 j); -void SetSomeStuffForSpriteObject_7(uint16 k); -void SetSomeStuffForSpriteObject_8(uint16 j); -void SetSomeStuffForSpriteObject_9(uint16 k); void SetupPpuForTitleSequence(void); void SetupPpu_3_Mode7(void); void SetupPpu_4_Mode1(void); @@ -2057,10 +983,8 @@ void SetupPpu_5_Mode7(void); void SetupPpu_6_Mode1(void); void SetupPpu_7_Mode1(void); void SetupPpu_Intro(void); -void Smult16x16Shr16(void); -void SpawnTextGlowObject(uint16 j); +void SpawnTextGlowObject(uint16 j, uint16 r18); void TransferJapaneseTextTilesToVram(void); -void Umult16x16Shr16(void); void UpdateCinematicBgTilemap(void); void UpdateSamusEyesTilemap(void); void sub_8B94E1(void); @@ -2070,46 +994,12 @@ void sub_8B9CDE(void); uint16 sub_8BB51E(uint16 k, uint16 j); // Bank 8D -PairU16 PalInstr_ClearPreInstr(uint16 k, uint16 j); -PairU16 PalInstr_ColorPlus15(uint16 k, uint16 j); -PairU16 PalInstr_ColorPlus2(uint16 k, uint16 j); -PairU16 PalInstr_ColorPlus3(uint16 k, uint16 j); -PairU16 PalInstr_ColorPlus4(uint16 k, uint16 j); -PairU16 PalInstr_ColorPlus8(uint16 k, uint16 j); -PairU16 PalInstr_ColorPlus9(uint16 k, uint16 j); -PairU16 PalInstr_DecTimerGoto(uint16 k, uint16 j); -PairU16 PalInstr_DecTimerGotoRel(uint16 k, uint16 j); -PairU16 PalInstr_Delete(uint16 k, uint16 j); -PairU16 PalInstr_Finish(uint16 k, uint16 j); -PairU16 PalInstr_Goto(uint16 k, uint16 j); -PairU16 PalInstr_GotoRel(uint16 k, uint16 j); -PairU16 PalInstr_QueueMusic(uint16 k, uint16 j); -PairU16 PalInstr_QueueSfx1(uint16 k, uint16 j); -PairU16 PalInstr_QueueSfx2(uint16 k, uint16 j); -PairU16 PalInstr_QueueSfx3(uint16 k, uint16 j); -PairU16 PalInstr_SetColorIndex(uint16 k, uint16 j); -PairU16 PalInstr_SetPalfxIndex(uint16 k, uint16 j); -PairU16 PalInstr_SetPreInstr(uint16 k, uint16 j); -PairU16 PalInstr_SetTimer(uint16 k, uint16 j); -PairU16 PalInstr_SetTimerIfBossBit(uint16 k, uint16 j); void ClearPaletteFXObjects(void); void DisablePaletteFx(void); void EnablePaletteFx(void); void PalFx_ProcessOne(uint16 k); -void PalInit_E1BC(uint16 k, uint16 j); -void PalInit_F761_Norfair1(uint16 k, uint16 j); -void PalInit_F779_Brinstar8(uint16 k, uint16 j); -void PalPreInstr_CheckEnemy0Health(uint16 k); -void PalPreInstr_DeletePalfxIfMinibossDead(uint16 k); -void PalPreInstr_E1BC(uint16 k); -void PalPreInstr_F621(uint16 k); -void PalPreInstr_SamusInHeat(uint16 k); -void PalPreInstr_SwitchIfYpos(uint16 k); -void PalPreInstr_SwitchIfYpos2(uint16 k); -void PalPreInstr_nullsub_129(uint16 k); void PaletteFxHandler(void); void SpawnPalfxObject(uint16 j); -void sub_8DC589(void); // Bank 8F uint16 RoomDefStateSelect_Door(uint16 k); @@ -2119,126 +1009,8 @@ uint16 RoomDefStateSelect_IsEventSet(uint16 k); uint16 RoomDefStateSelect_MorphBallMissiles(uint16 k); uint16 RoomDefStateSelect_PowerBombs(uint16 k); uint16 RoomDefStateSelect_TourianBoss01(uint16 k); -void DoorCode_CeresElevatorShaft(void); -void DoorCode_CeresElevatorShaft_2(void); -void DoorCode_ResetElevatubeNorthExit(void); -void DoorCode_ResetElevatubeSouthExit(void); -void DoorCode_Scroll0_Blue(void); -void DoorCode_Scroll13_Blue(void); -void DoorCode_Scroll6_Green(void); -void DoorCode_Scroll_17_Blue(void); -void DoorCode_Scroll_1_4_Green(void); -void DoorCode_Scroll_2_Blue(void); -void DoorCode_Scroll_3_Green(void); -void DoorCode_Scroll_4Blue_8Green(void); -void DoorCode_Scroll_4_Blue(void); -void DoorCode_Scroll_6_Green(void); -void DoorCode_Scroll_8toB_Red(void); -void DoorCode_Scroll_LotsRed(void); -void DoorCode_SetScroll_0(void); -void DoorCode_SetScroll_1(void); -void DoorCode_SetScroll_10(void); -void DoorCode_SetScroll_11(void); -void DoorCode_SetScroll_12(void); -void DoorCode_SetScroll_13(void); -void DoorCode_SetScroll_14(void); -void DoorCode_SetScroll_15(void); -void DoorCode_SetScroll_16(void); -void DoorCode_SetScroll_17(void); -void DoorCode_SetScroll_18(void); -void DoorCode_SetScroll_19(void); -void DoorCode_SetScroll_2(void); -void DoorCode_SetScroll_20(void); -void DoorCode_SetScroll_21(void); -void DoorCode_SetScroll_22(void); -void DoorCode_SetScroll_23(void); -void DoorCode_SetScroll_24(void); -void DoorCode_SetScroll_25(void); -void DoorCode_SetScroll_26(void); -void DoorCode_SetScroll_27(void); -void DoorCode_SetScroll_28(void); -void DoorCode_SetScroll_29(void); -void DoorCode_SetScroll_3(void); -void DoorCode_SetScroll_30(void); -void DoorCode_SetScroll_31(void); -void DoorCode_SetScroll_32(void); -void DoorCode_SetScroll_33(void); -void DoorCode_SetScroll_34(void); -void DoorCode_SetScroll_35(void); -void DoorCode_SetScroll_36(void); -void DoorCode_SetScroll_37(void); -void DoorCode_SetScroll_38(void); -void DoorCode_SetScroll_39(void); -void DoorCode_SetScroll_4(void); -void DoorCode_SetScroll_40(void); -void DoorCode_SetScroll_41(void); -void DoorCode_SetScroll_42(void); -void DoorCode_SetScroll_43(void); -void DoorCode_SetScroll_44(void); -void DoorCode_SetScroll_45(void); -void DoorCode_SetScroll_46(void); -void DoorCode_SetScroll_47(void); -void DoorCode_SetScroll_48(void); -void DoorCode_SetScroll_49(void); -void DoorCode_SetScroll_5(void); -void DoorCode_SetScroll_50(void); -void DoorCode_SetScroll_53(void); -void DoorCode_SetScroll_54(void); -void DoorCode_SetScroll_55(void); -void DoorCode_SetScroll_56(void); -void DoorCode_SetScroll_57(void); -void DoorCode_SetScroll_58(void); -void DoorCode_SetScroll_59(void); -void DoorCode_SetScroll_6(void); -void DoorCode_SetScroll_60(void); -void DoorCode_SetScroll_61(void); -void DoorCode_SetScroll_62(void); -void DoorCode_SetScroll_63(void); -void DoorCode_SetScroll_64(void); -void DoorCode_SetScroll_65(void); -void DoorCode_SetScroll_7(void); -void DoorCode_SetScroll_8(void); -void DoorCode_SetScroll_9(void); -void DoorCode_SetupElevatubeFromNorth(void); -void DoorCode_SetupElevatubeFromSouth(void); -void DoorCode_StartWreckedShipTreadmillWest(void); -void DoorCode_StartWreckedSkipTreadmill_East(void); void HandleRoomDefStateSelect(uint16 k); void PauseHook_DraygonRoom(void); -void RoomCode_8FC8C8(void); -void RoomCode_CeresColorMathHdma(void); -void RoomCode_CeresColorMathHdma_BgBase(void); -void RoomCode_CeresElevatorShaft_(void); -void RoomCode_CrocomireShaking(void); -void RoomCode_Elevatube(void); -void RoomCode_Escape4_SetMediumHorizRoomShake(void); -void RoomCode_ExplodeShakes(void); -void RoomCode_GenRandomExplodes(void); -void RoomCode_GenRandomExplodes_4th(void); -void RoomCode_GenRandomExplodes_Nonblank(void); -void RoomCode_HandleCeresRidleyGetaway(void); -void RoomCode_RidleyRoomShaking(void); -void RoomCode_ScrollRightDachora(void); -void RoomCode_ScrollingSkyLand_(void); -void RoomCode_ScrollingSkyLand_Shakes(void); -void RoomCode_ScrollingSkyOcean_(void); -void RoomCode_SetCeresDoorSolid(void); -void RoomCode_SetCollectedMap(void); -void RoomCode_SetLightHorizRoomShake(void); -void RoomCode_SetMediumHorizRoomShake(void); -void RoomCode_SetPauseCodeForDraygon(void); -void RoomCode_SetZebesTimebombEvent(void); -void RoomCode_SetupShaktoolRoomPlm(void); -void RoomCode_ShakeScreenHorizDiag(void); -void RoomCode_ShakeScreenHorizDiagStrong(void); -void RoomCode_SpawnCeresFallingDebris(void); -void RoomSetup_AfterSavingAnimals(void); -void RoomSetup_AutoDestroyWallAfterEscape(void); -void RoomSetup_RunStatueUnlockAnims(void); -void RoomSetup_ScrollingSkyLand(void); -void RoomSetup_ScrollingSkyOcean(void); -void RoomSetup_ShakeDuringEscape(void); -void RoomSetup_TurnWallIntoShotblocks(void); void RunDoorSetupCode(void); void RunRoomMainCode(void); void RunRoomSetupCode(void); @@ -2251,21 +1023,8 @@ PairU16 Samus_CalcSpritemapPos_Default(uint16 j); PairU16 Samus_CalcSpritemapPos_Special(uint16 j); PairU16 Samus_CalcSpritemapPos_Standing(uint16 j); uint16 CallSomeSamusCode(uint16 a); -uint16 Projectile_SinLookup_Inner(uint16 k); -uint16 Samus_AnimDelayFunc_0to5(uint16 j); -uint16 Samus_AnimDelayFunc_11_SelectDelaySequenceWalljump(uint16 j); -uint16 Samus_AnimDelayFunc_12_TransToPose(uint16 j); -uint16 Samus_AnimDelayFunc_13_TransToPose(uint16 j); -uint16 Samus_AnimDelayFunc_14_Goto(uint16 j); -uint16 Samus_AnimDelayFunc_15_GotoStart(uint16 j); -uint16 Samus_AnimDelayFunc_6_GotoStartIfLittleHealth(uint16 j); -uint16 Samus_AnimDelayFunc_7(uint16 j); -uint16 Samus_AnimDelayFunc_8_AutoJumpHack(uint16 j); -uint16 Samus_AnimDelayFunc_9_TransToPose(uint16 j); uint16 Samus_DetermineGrappleSwingSpeed_X(void); uint16 Samus_DetermineSpeedTableEntryPtr_X(void); -uint16 Samus_HandleSpeedBoosterAnimDelay(uint16 j); -uint16 UNUSED_Samus_AnimDelayFunc_10(uint16 j); uint8 ClearCarry(void); uint8 DeleteProjectileIfFarOffScreen(void); uint8 FireSba(void); @@ -2277,7 +1036,7 @@ uint8 FireSba_FireWave(void); uint8 Hdmaobj_CrystalFlash(void); uint8 HudSelectionHandler_MorphBall_Helper(void); uint8 HudSelectionHandler_MorphBall_Helper2(void); -uint8 InitProjectilePositionDirection(void); +uint8 InitProjectilePositionDirection(uint16 r20); uint8 SamusBottomDrawn_0_Standing(void); uint8 SamusBottomDrawn_1(void); uint8 SamusBottomDrawn_14_WallJump(void); @@ -2321,13 +1080,12 @@ uint8 SamusCode_1C(void); uint8 SamusCode_1D_ClearSoundInDoor(void); uint8 SamusCode_1E(void); uint8 SamusCode_1F(void); -uint8 Samus_CalcBaseSpeed_NoDecel_X(uint16 k); uint8 Samus_CanFireBeam(void); uint8 Samus_CanFireSuperMissile(void); uint8 Samus_CheckAndMoveY(void); uint8 Samus_EndSuperJump(void); uint8 Samus_Func26(void); -uint8 Samus_GrappleWallJumpCheck(void); +uint8 Samus_GrappleWallJumpCheck(int32 amt); uint8 Samus_HitInterrupt_Ball(void); uint8 Samus_HitInterrupt_Falling(void); uint8 Samus_HitInterrupt_KnockbackGrapple(void); @@ -2337,7 +1095,7 @@ uint8 Samus_HitInterrupt_Turning(void); uint8 Samus_HitInterrupt_Unused(void); uint8 Samus_MoveY_Simple_(void); uint8 Samus_SetupForBeingDrained(void); -uint8 Samus_WallJumpCheck(void); +uint8 Samus_WallJumpCheck(int32 amt); uint8 SetupBombJump_1(void); uint8 SetupBombJump_1A(void); uint8 SetupBombJump_2(void); @@ -2351,7 +1109,6 @@ uint8 SwitchToHudHandler_SuperMissiles(void); uint8 SwitchToHudHandler_Xray(void); uint8 UNUSED_SamusBottomDrawn_D(void); uint8 UpdateArmCannonIsOpenFlag(void); -void AdjustMapBitsForMapPageSpill(void); void AdvanceArmCannonFrame(void); void AtmosphericTypeFunc_1_FootstepSplash(uint16 k, uint16 j); void AtmosphericTypeFunc_3_DivingSplash(uint16 k, uint16 j); @@ -2399,8 +1156,8 @@ void HudSelectionHandler_NothingOrPowerBombs(void); void HudSelectionHandler_TurningAround(void); void HudSelectionHandler_Xray(void); void InitializeMiniMapBroken(void); -void InitializeProjectileSpeed(uint16 k); -void InitializeProjectileSpeedOfType(void); +void InitializeProjectileSpeed(uint16 k, uint16 r22); +void InitializeProjectileSpeedOfType(uint16 r20); void KillProjectile(uint16 k); void KillProjectileFunc_0(uint16 j); void KillProjectileFunc_1(uint16 j); @@ -2410,14 +1167,8 @@ void KillProjectileFunc_4(uint16 j); void KillProjectileFunc_6(uint16 j); void KillProjectileFunc_7(uint16 j); void KillProjectileFunc_8(uint16 j); -void LiquidPhysicsType_0(void); -void LiquidPhysicsType_24_LavaAcid(void); -void LiquidPhysicsType_6_Water(void); void LoadProjectilePalette(uint16 a); -void LoadProjectilePalette_(uint16 a); void MainScrollingRoutine(void); -void MarkMapTileAboveSamusAsExplored(void); -void MarkMapTileAsExplored(void); void Missile_Func1(uint16 k); void Missile_Func2(void); void MoveSamusWithControlPad(void); @@ -2431,7 +1182,6 @@ void ProjPreInstr_Bomb(uint16 k); void ProjPreInstr_Dir0459(uint16 k); void ProjPreInstr_Dir1368(uint16 k); void ProjPreInstr_Dir27(uint16 k); -void ProjPreInstr_Empty(void); void ProjPreInstr_EndOfSpazerSba(uint16 k); void ProjPreInstr_Func1(uint16 k); void ProjPreInstr_HyperBeam(uint16 k); @@ -2451,9 +1201,9 @@ void ProjPreInstr_SpazerSba_FuncA_0(uint16 k); void ProjPreInstr_SpazerSba_FuncA_1(uint16 k); void ProjPreInstr_SpazerSba_FuncA_2(uint16 k); void ProjPreInstr_SpazerSba_FuncA_3(uint16 k); -void ProjPreInstr_SpazerSba_FuncB_0(uint16 j); -void ProjPreInstr_SpazerSba_FuncB_1(uint16 j); -void ProjPreInstr_SpazerSba_FuncB_2(uint16 j); +void ProjPreInstr_SpazerSba_FuncB_0(uint16 j, uint16 r22); +void ProjPreInstr_SpazerSba_FuncB_1(uint16 j, uint16 r22); +void ProjPreInstr_SpazerSba_FuncB_2(uint16 j, uint16 r22); void ProjPreInstr_SpeedEcho(uint16 k); void ProjPreInstr_SpreadBomb(uint16 k); void ProjPreInstr_SuperMissile(uint16 k); @@ -2467,10 +1217,10 @@ void ProjPreInstr_WavePlasmaEtc_1368(uint16 k); void ProjPreInstr_WavePlasmaEtc_27(uint16 k); void ProjPreInstr_WaveSba(uint16 k); void ProjPreInstr_Wave_Shared(uint16 k); -void ProjectileReflection(void); +void ProjectileReflection(uint16 r20); void Projectile_Func4(uint16 k); void Projectile_Func7_Shinespark(void); -void Projectile_SinLookup(uint16 j, uint16 a); +Point16U Projectile_SinLookup(uint16 j, uint16 a); void ResetProjectileData(void); void RunFrameHandlerGamma(void); void RunSamusMovementHandler(void); @@ -2497,12 +1247,12 @@ void Samus_BombJumpFallingXMovement_(void); void Samus_BombJumpFallingYMovement_(void); void Samus_BombJumpRisingXMovement_(void); void Samus_BombJumpRisingYMovement_(void); -void Samus_CalcBaseSpeed_X(uint16 k); -void Samus_CalcDisplacementMoveLeft(void); -void Samus_CalcDisplacementMoveRight(void); +int32 Samus_CalcBaseSpeed_X(uint16 k); +int32 Samus_CalcDisplacementMoveLeft(int32 amt); +int32 Samus_CalcDisplacementMoveRight(int32 amt); void Samus_CalcDistanceMoved_X(void); void Samus_CalcDistanceMoved_Y(void); -void Samus_CalcSpeed_X(void); +int32 Samus_CalcSpeed_X(int32 amt); void Samus_CalcSpritemapPos_Default_(void); void Samus_CallInputHandler(void); void Samus_CheckStartFalling(void); @@ -2545,16 +1295,15 @@ void Samus_Func6(void); void Samus_Func7(void); void Samus_Func8(void); void Samus_Func9(void); -void Samus_GetBottomBoundary(void); -void Samus_GetTopBottomBoundary(void); +uint16 Samus_GetTop_R20(void); +uint16 Samus_GetBottom_R18(void); void Samus_GrabbedByDraygonFrameHandler(void); -void Samus_HandleAnimDelay(void); +static void Samus_HandleAnimDelay(void); void Samus_HandleCooldown(void); void Samus_HandleExtraRunspeedX(void); void Samus_HandleHudSpecificBehaviorAndProjs(void); void Samus_HandleMovement_DrainedCrouching(void); void Samus_HandleMovement_X(void); -void Samus_HandleNormalAnimDelay(uint16 j); void Samus_HandlePeriodicDamage(void); void Samus_HandleScroll_X(void); void Samus_HandleScroll_Y(void); @@ -2572,8 +1321,8 @@ void Samus_LowHealthCheck_(void); void Samus_LowHealthCheck_0(void); void Samus_MorphedBouncingMovement(void); void Samus_MorphedFallingMovement(void); -void Samus_MoveDown(void); -void Samus_MoveDown_NoColl(void); +void Samus_MoveDown(int32 amt); +void Samus_MoveDown_NoColl(int32 amt); void Samus_MoveDown_SetPoseCalcInput(void); void Samus_MoveExtraY(void); void Samus_MoveHandlerShinesparkWindup(void); @@ -2596,14 +1345,14 @@ void Samus_MoveHandler_ShinesparkCrash_1(void); void Samus_MoveHandler_ShinesparkCrash_2(void); void Samus_MoveHandler_Shinespark_Diag(void); void Samus_MoveHandler_Shinespark_Horiz(void); -void Samus_MoveLeft(void); -void Samus_MoveLeft_NoColl(void); -void Samus_MoveRight(void); -void Samus_MoveRight_NoColl(void); -void Samus_MoveUp(void); -void Samus_MoveUp_NoColl(void); +void Samus_MoveLeft(int32 amt); +void Samus_MoveLeft_NoColl(int32 amt); +void Samus_MoveRight(int32 amt); +void Samus_MoveRight_NoColl(int32 amt); +void Samus_MoveUp(int32 amt); +void Samus_MoveUp_NoColl(int32 amt); void Samus_MoveUp_SetPoseCalcInput(void); -void Samus_MoveX(void); +void Samus_MoveX(int32 amt); void Samus_MoveY_WithSpeedCalc(void); void Samus_Move_NoBaseSpeed_X(void); void Samus_Move_NoSpeedCalc_Y(void); @@ -2650,14 +1399,14 @@ void Samus_ShinesparkMove_X(void); void Samus_ShinesparkMove_Y(void); void Samus_ShootCheck(void); void Samus_SpawnAirBubbles(void); -void Samus_SpawnWaterSplash(void); +void Samus_SpawnWaterSplash(uint16 r18); void Samus_SpinJumpMovement(void); void Samus_UpdatePreviousPose(void); void Samus_UpdateSpeedEchoPos(void); void Samus_UpdateSuitPaletteIndex(void); void Samus_VerticalBombJump(void); void SetContactDamageIndexAndUpdateMinimap(void); -void SetInitialProjectileSpeed(void); +void SetInitialProjectileSpeed(uint16 r20); void SetLiquidPhysicsType(void); void SetupBombJump(void); void SpawnProjectileTrail(uint16 k); @@ -2666,7 +1415,8 @@ void SuperMissileBlockCollDetect_Y(void); void SwappedAmmoRoutine(void); void UpdateBeamTilesAndPalette(void); void UpdateMinimap(void); -void UpdateMinimapInside(void); +void UpdateMinimapInside(uint16 r18, uint16 r22, uint16 r34, uint16 r30, uint16 r32, uint16 r38, uint16 r24, uint16 r40, uint16 r26, uint16 r42, uint16 r28); + void WaveBeam_CheckColl(uint16 k); void WaveBeam_CheckColl_0459(void); void WaveBeam_CheckColl_1368(void); @@ -2679,7 +1429,6 @@ void sub_90EB55(void); void sub_90EB86(void); // Bank 91 -PairU16 Xray_HandleXrayedBlock(uint16 k); uint16 DemoInstr_ClearPreInstr(uint16 k, uint16 j); uint16 DemoInstr_DecTimerAndGoto(uint16 k, uint16 j); uint16 DemoInstr_Disable(uint16 k, uint16 j); @@ -2689,13 +1438,6 @@ uint16 DemoInstr_Func3(uint16 k, uint16 j); uint16 DemoInstr_Goto(uint16 k, uint16 j); uint16 DemoInstr_SetPreInstr(uint16 k, uint16 j); uint16 DemoInstr_SetTimer(uint16 k, uint16 j); -uint16 Xray_Func10(uint16 j); -uint16 Xray_Func11(uint16 j); -uint16 Xray_Func21(uint16 j); -uint16 Xray_Func5(void); -uint16 Xray_Func7(uint16 j); -uint16 Xray_Func8(uint16 j); -uint16 Xray_Func9(uint16 j); bool CanXrayShowBlocks(void); uint8 HandleBeamChargePalettes(void); uint8 HandleCollDueToChangedPose_Block_CollAbove(void); @@ -2729,7 +1471,7 @@ uint8 SamusFunc_F468_TurnAroundJumping(void); uint8 SamusFunc_F468_TurningAroundOnGround(void); uint8 SamusFunc_F468_Unused(void); uint8 SamusFunc_F468_WallJumping(void); -uint8 Samus_CheckWalkedIntoSomething(void); +void Samus_CheckWalkedIntoSomething(void); uint8 Samus_CrouchTrans(void); uint8 Samus_HandleCrystalFlashPals(void); uint8 Samus_HandleScrewAttackSpeedBoostingPals(void); @@ -2762,8 +1504,7 @@ uint8 SomeMotherBrainScripts_3_EnableHyperBeam(void); uint8 SomeMotherBrainScripts_4(void); uint8 Xray_Initialize(void); uint8 nullsub_164(void); -void CalculateXrayHdmaTable_OriginOffScreen(uint16 k, uint16 j); -void CalculateXrayHdmaTable_OriginOnScreen(uint16 k, uint16 j); +void CalculateXrayHdmaTableInner(uint16 k, uint16 j, uint16 r18, uint16 r20, bool off_screen, uint16 *dest_addr); void CopyToSamusSuitPalette(uint16 k); void CopyToSamusSuitTargetPalette(uint16 k); void DemoObjectInputHandler(void); @@ -2771,7 +1512,6 @@ void DemoPreInstr_864F(void); void DemoPreInstr_866A(void); void DemoPreInstr_8AB0(void); void DemoPreInstr_CheckLeaveDemo(void); -void DemoPreInstr_nullsub_162(void); void DemoSetFunc_0(void); void DemoSetFunc_1(void); void DemoSetFunc_2(void); @@ -2782,7 +1522,6 @@ void DemoSetFunc_6(void); void DemoSetFunc_7(void); void DemoSetFunc_Common(uint16 a); void DisableDemoInput(void); -void DrawDemoRecorderFrameCounter(void); void EnableDemoInput(void); void GameState_28_Unused_(void); void GravitySuitPickup(void); @@ -2807,7 +1546,6 @@ void LoadBlockToXrayTilemap(uint16 a, uint16 k, uint16 j); void LoadDemoData(void); void LoadDemoInputObject(uint16 a, uint16 j); void MakeSamusFaceForward(void); -void PauseDemoRecorder(void); void ProcessDemoInputObject(void); void ResetDemoData(void); void ResponsibleForXrayStandupGlitch(void); @@ -2904,54 +1642,19 @@ void Samus_RestoreSuperMissiles(uint16 a); void Samus_SetAnimationFrameIfPoseChanged(void); void Samus_UpdatePreviousPose_0(void); void SomeMotherBrainScripts(uint16 a); -void TranslateCustomControllerBindingsToDefault(void); void VariaSuitPickup(void); -void XrayHdmaFunc_BeamAimedD(void); -void XrayHdmaFunc_BeamAimedDD(uint16 j); -void XrayHdmaFunc_BeamAimedDDL(uint16 j); -void XrayHdmaFunc_BeamAimedDDR(uint16 j); -void XrayHdmaFunc_BeamAimedL(void); -void XrayHdmaFunc_BeamAimedR(void); -void XrayHdmaFunc_BeamAimedU(void); -void XrayHdmaFunc_BeamAimedUU(uint16 j); -void XrayHdmaFunc_BeamAimedUUL(uint16 j); -void XrayHdmaFunc_BeamAimedUUR(uint16 j); -void XrayHdmaFunc_BeamHoriz(void); -void XrayHdmaOnScreen_BeamAimedD(void); -void XrayHdmaOnScreen_BeamAimedDD(uint16 j); -void XrayHdmaOnScreen_BeamAimedDDL(uint16 j); -void XrayHdmaOnScreen_BeamAimedDDR(uint16 j); -void XrayHdmaOnScreen_BeamAimedL(void); -void XrayHdmaOnScreen_BeamAimedR(void); -void XrayHdmaOnScreen_BeamAimedU(void); -void XrayHdmaOnScreen_BeamAimedUU(uint16 j); -void XrayHdmaOnScreen_BeamAimedUUL(uint16 j); -void XrayHdmaOnScreen_BeamAimedUUR(uint16 j); -void XrayHdmaOnScreen_BeamHoriz(void); void XrayRunHandler(void); -void Xray_Func12(uint16 j); -void Xray_Func13(uint16 a); -void Xray_Func14(uint16 j); -void Xray_Func15(uint16 j); -void Xray_Func16(uint16 a); -void Xray_Func20(void); -void Xray_Func6(void); -void Xray_Func6B(void); -void Xray_Func6C(void); -void Xray_Func6D(void); void Xray_SetupStage1_FreezeTimeBackup(uint16 k); void Xray_SetupStage2_ReadBg1_2ndScreen(void); void Xray_SetupStage3_ReadBg1_1stScreen(void); void Xray_SetupStage4(void); -void Xray_SetupStage4_Func1(void); -void Xray_SetupStage4_Func2(void); -void Xray_SetupStage4_Func3(void); +void Xray_SetupStage4_Func1(uint16 dst_r22, uint16 r26, uint16 r28, uint16 r30); +void Xray_SetupStage4_Func2(uint16 dst_r22, uint16 r34); +void Xray_SetupStage4_Func3(uint16 r18, uint16 r22, uint16 r36); void Xray_SetupStage5(void); void Xray_SetupStage6(void); void Xray_SetupStage7(void); void Xray_SetupStage8_SetBackdropColor(void); -void Xray_SomeDivide(void); -void sub_91D2D1(void); void sub_91EFC3(void); // Bank 92 @@ -2973,28 +1676,11 @@ void InitializeProjectile(uint16 k); void InitializeSbaProjectile(uint16 k); void InitializeShinesparkEchoOrSpazerSba(uint16 k); void KillProjectileInner(uint16 k); -void ProjectileInsts_GetValue(uint16 k); +uint16 ProjectileInsts_GetValue(uint16 k); void RunProjectileInstructions(void); void sub_9382FD(void); // Bank 94 -uint16 BlockColl_GetBlockIndexAbove(uint16 k); -uint16 BlockColl_GetBlockIndexBelow(uint16 k); -uint16 BlockColl_GetBlockIndexLeft(uint16 k); -uint16 BlockColl_GetBlockIndexRight(uint16 k); -uint16 ClearCarry_0(void); -uint16 GrappleInstr_Goto(uint16 j); -uint16 PostGrappleColl_Horiz(uint16 k); -uint16 PostGrappleColl_Horiz_Slope(void); -uint16 PostGrappleColl_Horiz_Slope_NonSquare(uint16 k); -uint16 PostGrappleColl_Horiz_Slope_Square(uint16 k); -uint16 PostGrappleColl_Horiz_Solid(void); -uint16 PostGrappleColl_Vert(uint16 k); -uint16 PostGrappleColl_Vert_Slope(void); -uint16 PostGrappleColl_Vert_Slope_NonSquare(uint16 k); -uint16 PostGrappleColl_Vert_Solid(void); -uint16 PostGrappleColl_Vertical_Slope_Square(uint16 k); -uint8 BlockBombedReact_Special(void); uint8 BlockCollGrappleBeam(void); uint8 BlockCollMissileHoriz(uint16 k); uint8 BlockCollMissileVert(uint16 k); @@ -3003,133 +1689,24 @@ uint8 BlockCollNoWaveBeamVert(uint16 k); uint8 BlockCollSpreadBomb(uint16 k); uint8 BlockCollWaveBeamHoriz(uint16 k); uint8 BlockCollWaveBeamVert(uint16 k); -uint8 BlockColl_Handle_Horiz(void); -uint8 BlockColl_Handle_Vert_LeftToRight(void); -uint8 BlockColl_Handle_Vert_RightToLeft(void); -uint8 BlockColl_Horiz_BombBlock(void); -uint8 BlockColl_Horiz_BombableAir(void); -uint8 BlockColl_Horiz_CheckColl(uint16 k); -uint8 BlockColl_Horiz_Door(void); -uint8 BlockColl_Horiz_Slope(void); -uint8 BlockColl_Horiz_Slope_NonSquare(void); -uint8 BlockColl_Horiz_Slope_Square(uint16 a, uint16 k); -uint8 BlockColl_Horiz_SolidShootGrappleBlock(void); -uint8 BlockColl_Horiz_SpecialAir(void); -uint8 BlockColl_Horiz_SpecialBlock(void); -uint8 BlockColl_Horiz_SpikeBlock(void); -uint8 BlockColl_Vert_BombBlock(void); -uint8 BlockColl_Vert_BombableAir(void); -uint8 BlockColl_Vert_CheckColl(uint16 k); -uint8 BlockColl_Vert_Door(void); -uint8 BlockColl_Vert_Slope(void); -uint8 BlockColl_Vert_Slope_NonSquare(uint16 k); -uint8 BlockColl_Vert_Slope_Square(uint16 a, uint16 k); -uint8 BlockColl_Vert_SolidShootGrappleBlock(void); -uint8 BlockColl_Vert_SpecialAir(void); -uint8 BlockColl_Vert_SpecialBlock(void); -uint8 BlockColl_Vert_SpikeAir(void); -uint8 BlockColl_Vert_SpikeBlock(void); -uint8 BlockFunc_ABB0(void); -uint8 BlockFunc_ABE6(void); uint8 BlockFunc_AC31(void); -uint8 BlockFunc_AEE3(void); -uint8 BlockFunc_AF0D(uint16 k); -uint8 BlockInsideReact_ShootableAir(void); -uint8 BlockInsideReact_Slope(void); -uint8 BlockInsideReact_SpecialAir(void); -uint8 BlockInsideReact_Special_(void); -uint8 BlockInsideReact_SpikeAir(void); -uint8 BlockInsideReact_SpikeAir_BTS1(void); uint8 BlockReactGrapple(void); -uint8 BlockReactGrapple_GrappleBlock(void); -uint8 BlockReactGrapple_SpikeBlock(void); -uint8 BlockReact_AA64(void); -uint8 BlockReact_AA64_SpikeAir(void); -uint8 BlockReact_AA64_SpikeBlock(void); -uint8 BlockReact_BombableAir(void); -uint8 BlockReact_BombableBlock(void); -uint8 BlockReact_HorizExt(void); -uint8 BlockReact_Shootable(void); -uint8 BlockReact_ShootableAir(void); -uint8 BlockReact_VertExt(void); -uint8 BlockShotReactHoriz(uint16 k); -uint8 BlockShotReactHoriz_Slope(void); -uint8 BlockShotReactHoriz_Slope_NonSquare(void); -uint8 BlockShotReactHoriz_Slope_Square(uint16 a, uint16 k); -uint8 BlockShotReactVert(uint16 k); -uint8 BlockShotReactVert_Slope(void); -uint8 BlockShotReactVert_Slope_NonSquare(void); -uint8 BlockShotReactVert_Slope_Square(uint16 a, uint16 k); -uint8 BlockShotReact_Slope_NonSquare(uint16 j, uint16 k); -uint8 ClearCarrySetZero(void); -uint8 ClearCarryZero(void); -uint8 ClearCarry_1(void); -uint8 ClearCarry_10(void); -uint8 ClearCarry_11(void); -uint8 ClearCarry_2(void); -uint8 ClearCarry_3(void); -uint8 ClearCarry_4(void); -uint8 ClearCarry_5(void); -uint8 ClearCarry_6(void); -uint8 ClearCarry_7(void); -uint8 ClearCarry_9(void); -uint8 CollDetectDueToPoseChange_SingleBlock(void); uint8 HandleMovementAndCollForSamusGrapple(void); -uint8 MaybeUnused_sub_9497DA(void); -uint8 MaybeUnused_sub_9497F2(void); -uint8 Samus_CollDetectChangedPose(void); -uint8 Samus_MoveDown_NoSolidColl(void); -uint8 Samus_MoveRight_NoSolidColl(void); -uint8 SetCarry_0(void); -uint8 SetCarry_1(void); -uint8 SetCarry_2(void); -uint8 SetCarry_3(void); -uint8 WallJumpBlockCollDetect(void); -uint8 sub_949D5D(void); -void AbsoluteValueOfInt32(void); -void AbsoluteValueOfInt32_0(void); -void BlockBombedReact(uint16 k); -void BlockColl_BombExplosion(uint16 k); -void BlockColl_SpikeBlock_BTS0(void); -void BlockColl_SpikeBlock_BTS1(void); -void BlockColl_SpikeBlock_BTS3(void); -void BlockFunc_9C73(uint16 k); -void BlockFunc_A06A(uint16 k); -void BlockFunc_A0F4(uint16 a); -void BlockFunc_A11A(uint16 a); -void BlockFunc_A957(void); +int32 Samus_CollDetectChangedPose(int32 amt); +int32 Samus_MoveDown_NoSolidColl(int32 amt); +int32 Samus_MoveRight_NoSolidColl(int32 amt); +int32 WallJumpBlockCollDetect(int32 amt); void BlockFunc_AC11(void); -void BlockGetSomePos1(uint16 k); -void BlockGetSomePos2(uint16 k); void BlockInsideDetection(void); -void BlockInsideReact_SpecialAir_10(void); -void BlockInsideReact_SpecialAir_11(void); -void BlockInsideReact_SpecialAir_70(void); -void BlockInsideReact_SpecialAir_8(void); -void BlockInsideReact_SpecialAir_9(void); -void BlockInsideReact_SpecialAir_Default(void); -void BlockInsideReact_SpikeAir_BTS2(void); void BombOrPowerBomb_Func1(uint16 k); -void CalculateBlockAt(uint16 r26, uint16 r28, uint16 r30, uint16 r32); -void ClearCarry_8(void); -void DrawGrappleOams(uint16 j); -void DrawGrappleOams2(void); -void DrawGrappleOams3(void); void GrappleFunc_AF87(void); void HandleGrappleBeamGfx(void); -void PostGrappleCollisionDetect_Down(void); -void PostGrappleCollisionDetect_Left(void); -void PostGrappleCollisionDetect_Right(void); -void PostGrappleCollisionDetect_Up(void); void PostGrappleCollisionDetect_X(void); void PostGrappleCollisionDetect_Y(void); void Samus_AlignYPosSlope(void); -void Samus_GetXposSpan(void); -void Samus_GetYposSpan(void); // Bank 9B uint16 CheckBannedDraygonGrappleDirs(uint16 a); -int ProcessEnemyGrappleBeamColl(uint16 a); uint16 GameState_24_SamusNoHealth_Explosion_2(void); uint16 GameState_24_SamusNoHealth_Explosion_Helper(void); uint16 HandleSamusDeathSequence(void); @@ -3140,26 +1717,7 @@ void CancelGrappleBeamIfIncompatiblePose(void); void CopyPalettesForSamusDeath(uint16 k); void DrawSamusStartingDeathAnim_(void); void GameState_24_SamusNoHealth_Explosion_1(void); -void GrappleBeamFunc_BB64(void); -void GrappleBeamFunc_BC1F(void); -void GrappleBeamFunc_BCFF(void); -void GrappleBeamFunc_BD44(void); -void GrappleBeamFunc_BD95(void); -void GrappleBeamFunc_BE98(void); -void GrappleBeamFunc_BEEB(void); -void GrappleBeamFunc_BF1B(void); -void GrappleBeamFunc_C832(void); -void GrappleBeamFunc_C9CE(void); -void GrappleBeamFunc_Cancel(void); -void GrappleBeamFunc_ConnectedLockedInPlace(void); -void GrappleBeamFunc_Connected_Swinging(void); -void GrappleBeamFunc_FireGoToCancel(void); -void GrappleBeamFunc_Firing(void); -void GrappleBeamFunc_Inactive(void); -void GrappleBeamFunc_ReleaseFromSwing(void); -void GrappleBeamFunc_Wallgrab(void); void GrappleBeamHandler(void); -void GrappleBeam_Func2(void); void GrappleNext_CrouchAimDownLeft(void); void GrappleNext_CrouchAimDownRight(void); void GrappleNext_CrouchAimLeft(void); @@ -3179,91 +1737,73 @@ void ProjectileTrail_Func5(uint16 k, uint16 j); void PropelSamusFromGrappleSwing(void); void QueueTransferOfSamusDeathSequence(uint16 j); void StartSamusDeathAnimation(void); -void UNUSED_sub_9BB8D5(void); -void UNUSED_sub_9BBA31(void); -void UNUSED_sub_9BC759(void); void UpdateGrappleBeamTiles(void); void UpdateGrappleBeamTilesAndIncrFlameCtr(void); +void GrappleBeamFunc_BD95(void); +void GrappleBeamFunc_BEEB(void); +void GrappleBeamFunc_BF1B(void); // Bank A0 uint16 Abs16(uint16 a); -uint16 CalculateAngleFromXY(void); -uint16 CalculateAngleFromXY_(void); -uint16 CalculateAngleFromXY_0(uint16 div); -uint16 CalculateAngleFromXY_1(uint16 div); -uint16 CalculateAngleFromXY_2(uint16 div); -uint16 CalculateAngleFromXY_3(uint16 div); -uint16 CalculateAngleFromXY_4(uint16 div); -uint16 CalculateAngleFromXY_5(uint16 div); -uint16 CalculateAngleFromXY_6(uint16 div); -uint16 CalculateAngleFromXY_7(uint16 div); +uint16 CalculateAngleFromXY(uint16 x_r18, uint16 y_r20); uint16 CalculateAngleOfEnemyXfromEnemyY(uint16 k, uint16 j); uint16 CalculateAngleOfSamusFromEnemy(uint16 k); uint16 CalculateAngleOfSamusFromEproj(uint16 k); uint16 CheckIfEnemyIsOnScreen(void); uint16 CheckIfEnemyTouchesSamus(uint16 k); -uint16 CosineMult8bit(uint16 a); uint16 DetermineDirectionOfSamusFromEnemy(void); uint16 EnemyFunc_AC67(uint16 k); -uint16 EnemyFunc_ACA8(void); +PairU16 EnemyFunc_ACA8(Point16U base_pt, Point16U samus_pt); uint16 EnemyFunc_ADA3(uint16 a); -const uint16 *EnemyInstr_ClearAiPreInstr(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_CopyToVram(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_DecTimerAndGoto(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_DecTimerAndGotoRel(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_DisableOffScreenProcessing(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_EnableOffScreenProcessing(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_Goto(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_GotoRel(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_SetAiPreInstr(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_SetTimer(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_Skip2bytes(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_Sleep(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_StopScript(uint16 k, const uint16 *jp); -const uint16 *EnemyInstr_WaitNframes(uint16 k, const uint16 *jp); uint16 EnemyWithNormalSpritesIsOffScreen(void); uint16 GetSamusEnemyDelta_X(uint16 k); uint16 GetSamusEnemyDelta_Y(uint16 k); -uint16 GrappleBeam_CollDetect_Enemy(void); +PairU16 GrappleBeam_CollDetect_Enemy(void); uint16 IsSamusWithinEnemy_X(uint16 k, uint16 a); uint16 IsSamusWithinEnemy_Y(uint16 k, uint16 a); uint16 Mult32(uint16 a); -uint16 Samus_CheckSolidEnemyColl(void); + +typedef struct Pair_Bool_Amt { + bool flag; + int32 amt; +} Pair_Bool_Amt; + +typedef struct CheckSolidEnemyColl_Result { + uint16 collision; + int32 amt; +} CheckEnemyColl_Result; + +CheckEnemyColl_Result Samus_CheckSolidEnemyColl(int32 amt); uint16 SignExtend8(uint16 a); -uint16 SineMult8bit(void); -uint16 SineMult8bitNegative(uint16 a); +uint16 SineMult8bit(uint16 a, uint16 varE32); +uint16 CosineMult8bit(uint16 a, uint16 varE32); +uint32 CosineMult8bitFull(uint16 a, uint16 varE32); +uint32 SineMult8bitFull(uint16 a, uint16 varE32); + uint16 SpawnEnemy(uint8 db, uint16 k); uint16 SubtractThenAbs16(uint16 k, uint16 j); uint16 SuitDamageDivision(uint16 a); -uint8 ClearCarry_13(void); uint8 CompareDistToSamus_X(uint16 k, uint16 a); uint8 CompareDistToSamus_Y(uint16 k, uint16 a); -uint8 EnemyBlockCollHorizReact_Slope(void); -uint8 EnemyBlockCollHorizReact_Slope_NonSquare(void); -uint8 EnemyBlockCollHorizReact_Slope_Square(uint16 k, uint16 a); -uint8 EnemyBlockCollReact_Horiz(uint16 k); -uint8 EnemyBlockCollReact_HorizExt(void); -uint8 EnemyBlockCollReact_Spike(void); -uint8 EnemyBlockCollReact_Vert(uint16 k); -uint8 EnemyBlockCollReact_VertExt(void); -uint8 EnemyBlockCollVertReact_Slope(void); -uint8 EnemyBlockCollVertReact_Slope_NonSquare(void); -uint8 EnemyBlockCollVertReact_Slope_Square(uint16 a, uint16 k); -uint8 EnemyFunc_BBBF(uint16 k); -uint8 EnemyFunc_BC76(uint16 k); -uint8 EnemyFunc_BF8A(uint16 k, uint16 a); +uint8 EnemyFunc_BBBF(uint16 k, int32 amt); +uint8 EnemyFunc_BC76(uint16 k, int32 amt); +uint8 EnemyFunc_BF8A(uint16 k, uint16 a, int32 amt); uint8 EnemyFunc_C8AD(uint16 k); -uint8 Enemy_MoveDown(uint16 k); -uint8 Enemy_MoveDownInner(uint16 k); -uint8 Enemy_MoveRight_IgnoreSlopes(uint16 k); -uint8 Enemy_MoveRight_IgnoreSlopes_Inner(uint16 k); -uint8 Enemy_MoveRight_ProcessSlopes(uint16 k); -uint8 Enemy_MoveRight_SlopesAsWalls(uint16 k); -uint8 Enemy_SetYpos_Aligned(uint16 j); +uint8 Enemy_MoveDown(uint16 k, int32 amt); +uint8 Enemy_MoveRight_IgnoreSlopes(uint16 k, int32 amt); +uint8 Enemy_MoveRight_ProcessSlopes(uint16 k, int32 amt); +uint8 Enemy_MoveRight_SlopesAsWalls(uint16 k, int32 amt); uint8 IsEnemyLeavingScreen(uint16 k); -uint8 SetCarry_4(void); void ClearEnemyDataAndProcessEnemySet(void); -void ConvertAngleToXy(void); + +typedef struct Point32 { + uint32 x; + uint32 y; +} Point32; + +Point32 ConvertAngleToXy(uint16 r18, uint16 r20); + + void CreateADudShot(void); void CreateDudShot(void); void DecrementSamusTimers(void); @@ -3276,8 +1816,8 @@ void EnemyBombCollHandler_Multibox(void); void EnemyCollisionHandler(void); void EnemyDeathAnimation(uint16 k, uint16 a); void EnemyFunc_A6B4_UsedBySporeSpawn(void); -void EnemyFunc_B691(void); -void EnemyFunc_B761(void); +void EnemyFunc_B691(uint16 varE20, Point32 pt); +uint32 EnemyFunc_Divide(uint32 a, uint32 b); void EnemyFunc_B7A1(void); void EnemyGrappleDeath(void); void EnemyMain(void); @@ -3285,8 +1825,8 @@ void EnemyProjectileCollHandler(void); void EnemyProjectileCollHandler_Multibox(void); void EnemySamusCollHandler(void); void EnemySamusCollHandler_Multibox(void); -void Enemy_AddPos_X(uint16 k); -void Enemy_AddPos_Y(uint16 k); +void Enemy_AddPos_X(uint16 k, uint32 amount32); +void Enemy_AddPos_Y(uint16 k, uint32 amount32); void Enemy_GrappleReact_CancelBeam_A0(void); void Enemy_GrappleReact_HurtSamus_A0(void); void Enemy_GrappleReact_KillEnemy_A0(void); @@ -3313,9 +1853,8 @@ void Enemy_NormalShotAI_A0(void); void Enemy_NormalShotAI_SkipSomeParts_A0(void); void Enemy_NormalTouchAI_A0(void); void Enemy_NormalTouchAI_SkipDeathAnim_A0(void); -void Enemy_SetXpos_Aligned(uint16 j); -void Enemy_SubPos_X(uint16 k); -void Enemy_SubPos_Y(uint16 k); +void Enemy_SubPos_X(uint16 k, uint32 amount32); +void Enemy_SubPos_Y(uint16 k, uint32 amount32); void Enemy_SwitchToFrozenAi(void); void EprojProjCollDet(void); void EprojSamusCollDetect(void); @@ -3326,13 +1865,12 @@ void InitializeEnemies(void); void LoadEnemies(void); void LoadEnemyGfxIndexes(uint16 k, uint16 j); void LoadEnemyTileData(void); -void Mult32bit(void); void NormalEnemyFrozenAI(void); void NormalEnemyPowerBombAi(void); void NormalEnemyPowerBombAiSkipDeathAnim(void); void NormalEnemyPowerBombAiSkipDeathAnim_CurEnemy(void); void NormalEnemyShotAi(void); -void NormalEnemyShotAiSkipDeathAnim(void); +uint16 NormalEnemyShotAiSkipDeathAnim(void); void NormalEnemyShotAiSkipDeathAnim_CurEnemy(void); void NormalEnemyTouchAi(void); void NormalEnemyTouchAiSkipDeathAnim(void); @@ -3340,7 +1878,7 @@ void NormalEnemyTouchAiSkipDeathAnim_CurEnemy(void); void ProcessEnemyInstructions(void); void ProcessEnemyPowerBombInteraction(void); void ProcessEnemyTilesets(void); -void ProcessExtendedTilemap(uint8 db); +void ProcessExtendedTilemap(uint8 db, uint16 r22); void QueueEnemyBG2TilemapTransfers(void); void RecordEnemySpawnData(uint16 j); void RinkasDeathAnimation(uint16 a); @@ -3350,7 +1888,7 @@ void SamusLatchesOnWithGrappleNoInvinc(void); void SamusLatchesOnWithGrappleParalyze(void); void SamusProjectileInteractionHandler(void); void SetAllEnemiesToShakeFor2Frames(void); -void SpawnEnemyDrops(uint16 a, uint16 k); +void SpawnEnemyDrops(uint16 a, uint16 k, uint16 varE20); void SwitchEnemyAiToMainAi(void); void TransferEnemyTilesToVramAndInit(void); void WriteEnemyOams(void); @@ -3406,7 +1944,7 @@ const uint16 *SpikeShootingPlant_Instr_A0A7(uint16 k, const uint16 *jp); uint8 Gripper_Func_1(uint16 k); uint8 Gripper_Func_2(uint16 k); uint8 MiniCrocomire_Func9(void); -uint8 Rinka_10(void); +bool Rinka_10(uint16 r18, uint16 r20); uint8 Rinka_9(uint16 k); void BouncingGoofball_Func1(uint16 k); void BouncingGoofball_Func2(void); @@ -3458,8 +1996,7 @@ void GunshipTop_8(uint16 k); void GunshipTop_9(uint16 k); void GunshipTop_Init(void); void GunshipTop_Main(void); -void HirisingSlowfalling_Func_1(uint16 k); -void HirisingSlowfalling_Func_2(uint16 k); +void HirisingSlowfalling_Func_2(uint16 k, uint16 r18); void HirisingSlowfalling_Func_3(uint16 a); void HirisingSlowfalling_Func_4(void); void HirisingSlowfalling_Func_5(void); @@ -3562,7 +2099,7 @@ void MiniCrocomire_Func1(void); void MiniCrocomire_Func2(void); void MiniCrocomire_Func3(void); void MiniCrocomire_Func4(void); -void MiniCrocomire_Func7(void); +void MiniCrocomire_Func7(int32 amt); void MiniCrocomire_Func8(void); void MiniCrocomire_Init(void); void MiniCrocomire_Main(void); @@ -3665,7 +2202,7 @@ void ThinHoppingBlobs_Func14(void); void ThinHoppingBlobs_Func15(void); void ThinHoppingBlobs_Func16(void); void ThinHoppingBlobs_Func3(void); -void ThinHoppingBlobs_Func4(void); +uint16 ThinHoppingBlobs_Func4(void); void ThinHoppingBlobs_Func5(void); void ThinHoppingBlobs_Func6(uint16 k); void ThinHoppingBlobs_Func7(void); @@ -3717,7 +2254,7 @@ const uint16 *PlatformThatFallsWithSamus_Instr_3(uint16 k, const uint16 *jp); const uint16 *PlatformThatFallsWithSamus_Instr_4(uint16 k, const uint16 *jp); const uint16 *Reflec_Instr_1(uint16 k, const uint16 *jp); const uint16 *Sidehopper_Func_1(uint16 k, const uint16 *jp); -uint16 Sidehopper_Func_2(void); +uint16 Sidehopper_Func_2(uint16 r22, uint16 r24); const uint16 *Sidehopper_Instr_1(uint16 k, const uint16 *jp); const uint16 *Skree_Instr_1(uint16 k, const uint16 *jp); const uint16 *Waver_Instr_1(uint16 k, const uint16 *jp); @@ -3735,8 +2272,6 @@ void Bang_Func_12(void); void Bang_Func_13(void); void Bang_Func_14(void); void Bang_Func_15(void); -void Bang_Func_16(void); -void Bang_Func_17(void); void Bang_Func_18(void); void Bang_Func_2(void); void Bang_Func_3(void); @@ -3768,7 +2303,7 @@ void Enemy_NormalShotAI_SkipSomeParts_A3(void); void Enemy_NormalTouchAI_A3(void); void FastMovingSlowSinkingPlatform_Init(void); void FastMovingSlowSinkingPlatform_Shot(void); -void FireZoomer_E8A5(uint16 k); +int32 FireZoomer_E8A5(uint16 k); void FireZoomer_Func_1(uint16 k); void FireZoomer_Func_2(uint16 k); void FireZoomer_Func_3(uint16 k); @@ -3785,10 +2320,6 @@ void Fireflea_Main(void); void Fireflea_Powerbomb(void); void Fireflea_Shot(void); void Fireflea_Touch(uint16 k); -void MaridiaFish_Func_1(void); -void MaridiaFish_Func_2(void); -void MaridiaFish_Func_3(void); -void MaridiaFish_Func_4(void); void MaridiaFish_Init(void); void MaridiaFish_Main(void); void MaridiaRefillCandy_Func_1(void); @@ -3806,11 +2337,11 @@ void MaridiaSnail_CFD4(uint16 k); void MaridiaSnail_CFE5(uint16 k); void MaridiaSnail_CFEB(uint16 k); void MaridiaSnail_CFFC(uint16 k); -void MaridiaSnail_D002(uint16 k, uint16 j); -void MaridiaSnail_D07E(uint16 k, uint16 j); +void MaridiaSnail_D002(uint16 k, const uint8 *j); +void MaridiaSnail_D07E(uint16 k, const uint8 *j); void MaridiaSnail_Func_1(uint16 k); -void MaridiaSnail_Func_10(uint16 k, uint16 j); -void MaridiaSnail_Func_11(uint16 k, uint16 j); +void MaridiaSnail_Func_10(uint16 k, const uint8 *j); +void MaridiaSnail_Func_11(uint16 k, const uint8 *j); void MaridiaSnail_Func_12(uint16 k, uint16 a); void MaridiaSnail_Func_13(uint16 k, uint16 a); void MaridiaSnail_Func_14(uint16 k); @@ -3824,7 +2355,6 @@ void MaridiaSnail_Func_4(uint16 k); void MaridiaSnail_Func_5(uint16 k); void MaridiaSnail_Func_6(uint16 k); void MaridiaSnail_Func_7(uint16 k); -void MaridiaSnail_Func_8(uint16 a); void MaridiaSnail_Func_9(uint16 k); void MaridiaSnail_Init(void); void MaridiaSnail_Main(void); @@ -3840,10 +2370,10 @@ void Metalee_Init(void); void Metalee_Main(void); void Metalee_Shot(void); void Metroid_Frozen(void); -void Metroid_Func_1(void); -void Metroid_Func_2(void); -void Metroid_Func_3(void); -void Metroid_Func_4(void); +void Metroid_Func_1(uint16 varE32); +void Metroid_Func_2(uint16 varE32); +void Metroid_Func_3(uint16 varE32); +void Metroid_Func_4(uint16 varE32); void Metroid_Func_5(uint16 k); void Metroid_Hurt(void); void Metroid_Init(void); @@ -3875,18 +2405,6 @@ void PlatformThatFallsWithSamus_Init(void); void PlatformThatFallsWithSamus_Main(void); void PlatformThatFalls_Init(uint16 k, uint16 j); void Reflec_Func_1(void); -void Reflec_Func_10(void); -void Reflec_Func_11(void); -void Reflec_Func_12(void); -void Reflec_Func_13(void); -void Reflec_Func_2(void); -void Reflec_Func_3(void); -void Reflec_Func_4(void); -void Reflec_Func_5(void); -void Reflec_Func_6(void); -void Reflec_Func_7(void); -void Reflec_Func_8(void); -void Reflec_Func_9(void); void Reflec_Init(void); void Reflec_Shot(void); void Roach_Func_1(void); @@ -3924,26 +2442,11 @@ void Roach_Func_8(uint16 k); void Roach_Func_9(void); void Roach_Init(void); void Roach_Main(void); -void Sidehopper_Func_10(void); -void Sidehopper_Func_11(void); -void Sidehopper_Func_12(void); -void Sidehopper_Func_13(void); -void Sidehopper_Func_14(void); -void Sidehopper_Func_15(void); -void Sidehopper_Func_16(void); -void Sidehopper_Func_17(void); -void Sidehopper_Func_18(void); void Sidehopper_Func_19(void); void Sidehopper_Func_20(void); void Sidehopper_Func_21(void); void Sidehopper_Func_22(void); void Sidehopper_Func_3(void); -void Sidehopper_Func_4(uint16 k); -void Sidehopper_Func_5(void); -void Sidehopper_Func_6(void); -void Sidehopper_Func_7(void); -void Sidehopper_Func_8(void); -void Sidehopper_Func_9(void); void Sidehopper_Init(void); void Sidehopper_Main(void); void Skree_Func_1(void); @@ -4044,7 +2547,6 @@ void Crocomire_Func_31(void); void Crocomire_Func_35(void); void Crocomire_Func_36(void); void Crocomire_Func_37(void); -void Crocomire_Func_38(uint16 k); void Crocomire_Func_43(void); void Crocomire_Func_49(void); void Crocomire_Func_50(void); @@ -4084,10 +2586,8 @@ void Crocomire_Main(void); void Crocomire_Powerbomb(void); void Enemy_GrappleReact_SamusLatchesOn_A4(void); void Enemy_NormalFrozenAI_A4(void); -void Enemy_NormalPowerBombAI_A4(void); void Enemy_NormalShotAI_A4(void); void Enemy_NormalTouchAI_A4(void); -void GetCurEnemyIndex(void); // Bank A5 const uint16 *Draygon_Instr_1(uint16 k, const uint16 *jp); @@ -4120,7 +2620,6 @@ const uint16 *Draygon_Instr_6(uint16 k, const uint16 *jp); const uint16 *Draygon_Instr_7(uint16 k, const uint16 *jp); const uint16 *Draygon_Instr_8(uint16 k, const uint16 *jp); const uint16 *Draygon_Instr_9(uint16 k, const uint16 *jp); -void CreateADudShot_A5(void); void Draygon_Func_1(void); void Draygon_Func_10(void); void Draygon_Func_11(void); @@ -4157,12 +2656,11 @@ void Draygon_Func_39(void); void Draygon_Func_4(void); void Draygon_Func_40(uint16 k); void Draygon_Func_41(void); -void Draygon_Func_42(void); +void Draygon_Func_42(uint16 varE24); void Draygon_Func_43(void); void Draygon_Func_44(void); void Draygon_Func_45(void); void Draygon_Func_46(void); -void Draygon_Func_47(void); void Draygon_Func_48(uint16 k); void Draygon_Func_49(uint16 k); void Draygon_Func_5(void); @@ -4186,7 +2684,6 @@ void DraygonsTail_Init(void); void Enemy_GrappleReact_CancelBeam_A5(void); void Enemy_GrappleReact_NoInteract_A5(void); void Enemy_NormalFrozenAI_A5(void); -void Enemy_NormalPowerBombAI_A5(void); void Enemy_NormalShotAI_A5(void); void Enemy_NormalTouchAI_A5(void); void SporeSpawn_Func_1(void); @@ -4216,9 +2713,7 @@ const uint16 *CeresDoor_Instr_5(uint16 k, const uint16 *jp); const uint16 *CeresDoor_Instr_6(uint16 k, const uint16 *jp); const uint16 *CeresDoor_Instr_7(uint16 k, const uint16 *jp); const uint16 *CeresDoor_Instr_8(uint16 k, const uint16 *jp); -uint16 CeresRidley_AC30(uint16 a); -uint16 CeresRidley_Func_30(uint16 a); -uint16 CeresRidley_Func_31(uint16 a); +int16 CeresRidley_AC30(uint16 a, int16 r20); const uint16 *CeresSteam_Instr_1(uint16 k, const uint16 *jp); const uint16 *CeresSteam_Instr_2(uint16 k, const uint16 *jp); const uint16 *CeresSteam_Instr_3(uint16 k, const uint16 *jp); @@ -4253,10 +2748,9 @@ const uint16 *FireGeyser_Instr_6(uint16 k, const uint16 *jp); const uint16 *FireGeyser_Instr_7(uint16 k, const uint16 *jp); const uint16 *FireGeyser_Instr_8(uint16 k, const uint16 *jp); const uint16 *FireGeyser_Instr_9(uint16 k, const uint16 *jp); -uint16 NuclearWaffle_Func_5(uint16 a); -uint16 NuclearWaffle_Func_6(uint16 a); +uint16 NuclearWaffle_Func_5(uint16 a, uint16 *r28_out); const uint16 *Ridley_E90C(uint16 k, const uint16 *j, uint16 a); -uint16 Ridley_Func_122(void); +uint16 Ridley_Func_122(Rect16U rect); uint16 Ridley_Func_7(void); const uint16 *Ridley_Instr_1(uint16 k, const uint16 *jp); const uint16 *Ridley_Instr_10(uint16 k, const uint16 *jp); @@ -4283,18 +2777,17 @@ uint8 HandleTypewriterText_Ext(uint16 a); uint8 ProcessEscapeTimerTileTransfers(void); uint8 Ridley_Func_103(uint16 k, uint16 j); uint8 Ridley_Func_121(void); -uint8 Ridley_Func_124(void); -uint8 Ridley_Func_17(void); +uint8 Ridley_Func_124(Rect16U rect); +uint8 Ridley_Func_17(uint16 r18); uint8 Ridley_Func_23(void); uint8 Ridley_Func_25(void); uint8 Ridley_Func_26(uint16 k, uint16 j); -uint8 Ridley_Func_40(void); uint8 Ridley_Func_41(void); -uint8 Ridley_Func_48(void); +uint8 Ridley_Func_48(Rect16U rect); uint8 Ridley_Func_68(void); uint8 Ridley_Func_78(void); uint8 Ridley_Func_80_DoubleRet(void); -uint8 Ridley_Func_90(void); +uint8 Ridley_Func_90(Point16U *out); uint8 Ridley_Func_97(void); void Boulder_Func_1(void); void Boulder_Func_2(void); @@ -4344,7 +2837,6 @@ void CeresRidley_Func_27(void); void CeresRidley_Func_28(void); void CeresRidley_Func_29(void); void CeresRidley_Func_3(void); -void CeresRidley_Func_32(void); void CeresRidley_Func_33(void); void CeresRidley_Func_34(void); void CeresRidley_Func_35(uint16 a); @@ -4364,7 +2856,6 @@ void DrawBabyMetroid_0(void); void Enemy_GrappleReact_CancelBeam_A6(void); void Enemy_GrappleReact_NoInteract_A6(void); void Enemy_NormalFrozenAI_A6(void); -void Enemy_NormalPowerBombAI_A6(void); void Enemy_NormalShotAI_A6(void); void Enemy_NormalTouchAI_A6(void); void FakeKraid_9C50(void); @@ -4381,9 +2872,9 @@ void FireGeyser_Main(void); void HandleCeresRidleyGetawayCutscene(void); void NuclearWaffle_Func_1(void); void NuclearWaffle_Func_2(void); -void NuclearWaffle_Func_3(void); -void NuclearWaffle_Func_4(void); -void NuclearWaffle_Func_7(void); +void NuclearWaffle_Func_3(uint16 varE32); +void NuclearWaffle_Func_4(uint16 varE32); +void NuclearWaffle_Func_7(uint16 r30); void NuclearWaffle_Init(void); void NuclearWaffle_Main(void); void Ridley_A2DC(void); @@ -4399,22 +2890,19 @@ void Ridley_CBC7(void); void Ridley_CBCE(void); void Ridley_CBD5(void); void Ridley_CBDC(void); -void Ridley_D495(void); +void Ridley_D495(uint16 r18); void Ridley_Func_1(void); void Ridley_Func_10(void); void Ridley_Func_100(void); void Ridley_Func_101(void); void Ridley_Func_102(void); -void Ridley_Func_104(uint16 k, uint16 j, uint16 a); -void Ridley_Func_104_0(uint16 k, uint16 j); -void Ridley_Func_105(uint16 k); -void Ridley_Func_106(uint16 k, uint16 j); -void Ridley_Func_107(uint16 k); -void Ridley_Func_108(uint16 k); -void Ridley_Func_109(uint16 k); +void Ridley_Func_104(uint16 k, uint16 j, uint16 a, uint16 r18, uint16 r20); +void Ridley_Func_104_0(uint16 k, uint16 j, uint16 r18, uint16 r20); +void Ridley_Func_105(uint16 k, uint16 r18, uint16 r24, uint16 r26); +void Ridley_Func_106(uint16 k, uint16 j, uint16 r18, uint16 r20); +void Ridley_Func_107(uint16 k, uint16 r18, uint16 r24); void Ridley_Func_11(void); -void Ridley_Func_110(uint16 k); -void Ridley_Func_111(void); +void Ridley_Func_111(uint16 r18, uint16 r20, uint16 r22); void Ridley_Func_112(void); void Ridley_Func_113(uint16 k); void Ridley_Func_114(void); @@ -4460,7 +2948,7 @@ void Ridley_Func_37(void); void Ridley_Func_38(void); void Ridley_Func_39(void); void Ridley_Func_3b(void); -void Ridley_Func_4(void); +uint16 Ridley_Func_4(void); void Ridley_Func_42(void); void Ridley_Func_43(void); void Ridley_Func_44(void); @@ -4499,7 +2987,6 @@ void Ridley_Func_77(void); void Ridley_Func_79(void); void Ridley_Func_8(void); void Ridley_Func_81(void); -void Ridley_Func_82(void); void Ridley_Func_83(void); void Ridley_Func_84(void); void Ridley_Func_85(void); @@ -4548,8 +3035,8 @@ void Zebetites_Shot(void); void Zebetites_Touch(void); void sub_A69C0B(void); void sub_A6DB2A(void); -void sub_A6DBC2(uint16 j); -void sub_A6DC13(uint16 j); +void sub_A6DBC2(uint16 j, uint16 x, uint16 y); +void sub_A6DC13(uint16 j, uint16 r18, uint16 r20, uint16 ); void sub_A6DF59(void); void sub_A6DF60(void); @@ -4572,7 +3059,7 @@ uint16 Phantoon_CalculateNthTransitionColorComponentFromXtoY(uint16 a, uint16 k, uint16 Phantoon_Func_10_CalculateNthTransitionColorFromXtoY(uint16 a, uint16 k, uint16 j); uint8 Etecoon_Func_2(uint16 k); uint8 Etecoon_Func_3(uint16 k); -uint8 Phantoon_Func_3(void); +uint8 Phantoon_Func_3(int32 amt); uint8 Phantoon_Func_8(void); uint8 Phantoon_Func_9(void); uint8 Phantoon_SetColorBasedOnHp(void); @@ -4584,7 +3071,7 @@ void Dachora_Func_2(uint16 k); void Dachora_Func_3(uint16 k); void Dachora_Func_4(uint16 k); void Dachora_Func_5(uint16 k); -void Dachora_Func_6(uint16 k); +int32 Dachora_Func_6(uint16 k); void Dachora_Func_7(uint16 k); void Dachora_Func_8(uint16 k); void Dachora_Func_9(uint16 k); @@ -4618,96 +3105,9 @@ void Etecoon_Func_5(uint16 k); void Etecoon_Func_6(uint16 k); void Etecoon_Func_7(uint16 k); void Etecoon_Func_8(uint16 k); -void Etecoon_Func_9(uint16 k); -void Etecoon_Init(void); -void Etecoon_Main(void); -void KraidEnemy_DecrementEnemyFunctionTimer(void); -void KraidEnemy_HandleFunctionTimer(uint16 k); -void KraidEnemy_ProcessInstrEnemyTimer(uint16 k); -void KraidFingernailInit(uint16 k); -void KraidFingernail_WaitForLintXpos(uint16 k); -void KraidFoot_FirstPhase_Thinking(uint16 k); -void KraidInstr_PlayDyingSfx(void); -void KraidInstr_PlayRoarSfx(void); -void KraidLintCommon_Main(uint16 k); -void KraidLint_ChargeLint(uint16 k); -void KraidLint_FireLint(uint16 k); -void KraidLint_ProduceLint(uint16 k); -void Kraid_AlignEnemyToKraid(uint16 k); -void Kraid_Arm_Shot(uint16 j); -void Kraid_ClearSomeSpikes(void); -void Kraid_CrumbleLeftPlatform_Left(void); -void Kraid_CrumbleLeftPlatform_Middle(void); -void Kraid_CrumbleLeftPlatform_Right(void); -void Kraid_CrumbleRightPlatform_Left(void); -void Kraid_CrumbleRightPlatform_Middle(void); -void Kraid_CrumbleRightPlatform_Right(void); -void Kraid_Death_Fadeout(void); -void Kraid_Death_Init(void); -void Kraid_Death_SinkThroughFloor(void); -void Kraid_Death_UpdateBG2TilemapBottomHalf(void); -void Kraid_Death_UpdateBG2TilemapTopHalf(void); -void Kraid_DrawRoomBg(void); -void Kraid_EnemyTouch_Lint(uint16 k); -void Kraid_Enemy_Touch(void); -void Kraid_FadeInBg_ClearBg2TilemapBottomHalf(void); -void Kraid_FadeInBg_ClearBg2TilemapTopHalf(void); -void Kraid_FadeInBg_FadeInBp6(void); -void Kraid_FadeInBg_LoadBg3Tiles1of4(void); -void Kraid_FadeInBg_LoadBg3Tiles2of4(void); -void Kraid_FadeInBg_LoadBg3Tiles3of4(void); -void Kraid_FadeInBg_LoadBg3Tiles4of4(void); -void Kraid_FadeInBg_SetEnemyDead_KraidWasAlive(void); -void Kraid_FadeInBg_SetEnemyDead_KraidWasDead(void); -void Kraid_Func_1(void); -void Kraid_GetsBig_BreakCeilingPlatforms(void); -void Kraid_GetsBig_DrawRoomBg(void); -void Kraid_GetsBig_FadeInRoomBg(void); -void Kraid_GetsBig_FinishUpdateBg2Tilemap(void); -void Kraid_GetsBig_ReleaseCamera(void); -void Kraid_GetsBig_SetBG2TilemapPrioBits(void); -void Kraid_GetsBig_Thinking(void); -void Kraid_GetsBig_Thinking_Setup(void); -void Kraid_HandleFirstPhase(void); -void Kraid_HandleSinking(void); -void Kraid_HealthBasedPaletteHandling(void); -void Kraid_HurtFlash_Handling(void); -void Kraid_Init(void); -void Kraid_InitEyeGlowing(void); -void Kraid_Lints_Enable(uint16 k, uint16 a); -void Kraid_Main(void); -void Kraid_Main_AttackWithMouthOpen(void); -void Kraid_Mainloop_Thinking(void); -void Kraid_Mainloop_Thinking_Setup(void); -void Kraid_Palette_Handling(void); -void Kraid_PlaySoundEveryHalfSecond(void); -void Kraid_RaiseKraidThroughFloor(uint16 k); -void Kraid_Raise_Handler(void); -void Kraid_Raise_LoadTilemapBottomAndShake(void); -void Kraid_Raise_SpawnRandomEarthquakeProjs16(void); -void Kraid_Raise_SpawnRandomEarthquakeProjs8(void); -void Kraid_RestrictSamusXtoFirstScreen(uint16 k); -void Kraid_RestrictSamusXtoFirstScreen_2(void); -void Kraid_SetEnemyPropsToDead(void); -void Kraid_SetLintYAndRandomThinkTimer(void); -void Kraid_SetWalkingBackwards(uint16 j, uint16 a); -void Kraid_SetWalkingForwards(uint16 j, uint16 a); -void Kraid_SetupGfxWithTilePrioClear(void); void Kraid_Shot(void); -void Kraid_Shot_Body(void); -void Kraid_Shot_GlowHisEye(void); -void Kraid_Shot_Mouth(void); -void Kraid_Shot_MouthIsOpen(void); -void Kraid_Shot_UnglowEye(void); -void Kraid_SpawnExplosionEproj(uint16 k); -void Kraid_SpawnPlmToClearCeiling(void); -void Kraid_SpawnRandomQuakeProjs(void); void Kraid_Touch(void); void Kraid_Touch_ArmFoot(void); -void Kraid_TransferTopHalfToVram(void); -CoroutineRet Kraid_UnpauseHook_IsSinking(void); -void Kraid_UpdateBG2TilemapBottomHalf(void); -void Kraid_UpdateBg2TilemapTopHalf(void); void KraidsArm_Init(void); void KraidsArm_Main(void); void KraidsArm_Touch(void); @@ -4716,18 +3116,10 @@ void KraidsBadFingernail_Main(void); void KraidsBadFingernail_Touch(void); void KraidsBottomLint_Init(void); void KraidsBottomLint_Main(void); -void KraidsFingernail_Fire(uint16 k); void KraidsFingernail_Init(void); -void KraidsFoot_FirstPhase_LungeForward(void); -void KraidsFoot_FirstPhase_RetreatFromLunge(void); void KraidsFoot_Init(void); void KraidsFoot_Main(void); -void KraidsFoot_PrepareToLungeForward(void); -void KraidsFoot_SecondPhaseSetup_WalkToStartPt(void); void KraidsFoot_SecondPhase_Init(void); -void KraidsFoot_SecondPhase_Thinking(void); -void KraidsFoot_SecondPhase_WalkForward(void); -void KraidsFoot_SecondPhase_WalkingBackwards(void); void KraidsGoodFingernail_Init(void); void KraidsGoodFingernail_Main(void); void KraidsGoodFingernail_Touch(void); @@ -4735,6 +3127,14 @@ void KraidsMiddleLint_Init(void); void KraidsMiddleLint_Main(void); void KraidsTopLint_Init(void); void KraidsTopLint_Main(void); +void Kraid_Init(void); +void Kraid_Main(void); +void Kraid_Arm_Shot(uint16 j); +CoroutineRet Kraid_UnpauseHook_IsSinking(void); + +void Etecoon_Func_9(uint16 k); +void Etecoon_Init(void); +void Etecoon_Main(void); void PauseHook_Kraid(void); void Phantoon2_Init(void); void Phantoon_AdjustSpeedAndMoveInFigure8(void); @@ -4774,8 +3174,8 @@ void Phantoon_Init(void); void Phantoon_IsSwooping(uint16 k); void Phantoon_Main(void); void Phantoon_MoveEnragedPhantoonToTopCenter(uint16 k); -void Phantoon_MoveInFigure8_LeftSideClockwise(uint16 j); -void Phantoon_MoveInFigure8_RightSideClockwise(uint16 j); +void Phantoon_MoveInFigure8_LeftSideClockwise(uint16 j, uint16 r20); +void Phantoon_MoveInFigure8_RightSideClockwise(uint16 j, uint16 r20); void Phantoon_MoveInSwoopingPattern(uint16 k); void Phantoon_MoveLeftOrRightAndPickEyeOpenPatt(uint16 k); void Phantoon_MovePhantoonInFigure8ThenOpenEye(uint16 k); @@ -4797,7 +3197,7 @@ CoroutineRet UnpauseHook_Kraid_IsDead(void); void sub_A7A92A(void); // Bank A8 -uint16 Beetom_Func_2(void); +uint16 Beetom_Func_2(uint16 r22, uint16 r24); const uint16 *Beetom_Instr_1(uint16 k, const uint16 *jp); uint16 Fune_Func_3(void); const uint16 *Fune_Instr_1(uint16 k, const uint16 *jp); @@ -4840,9 +3240,9 @@ const uint16 *WalkingLavaSeahorse_Instr_4(uint16 k, const uint16 *jp); const uint16 *WalkingLavaSeahorse_Instr_5(uint16 k, const uint16 *jp); const uint16 *WalkingLavaSeahorse_Instr_6(uint16 k, const uint16 *jp); uint16 WreckedShipGhost_Func_8(void); -const uint16 *WreckedShipRobot_CommonInstr(uint16 k, const uint16 *jp); -const uint16 *WreckedShipRobot_D10C(uint16 k, const uint16 *jp); -const uint16 *WreckedShipRobot_D147(uint16 k, const uint16 *jp); +const uint16 *WreckedShipRobot_CommonInstr(uint16 k, const uint16 *jp, uint16 r50, uint16 r48); +const uint16 *WreckedShipRobot_D10C(uint16 k, const uint16 *jp, uint16 r50); +const uint16 *WreckedShipRobot_D147(uint16 k, const uint16 *jp, uint16 r48, uint16 r50); const uint16 *WreckedShipRobot_Instr_1(uint16 k, const uint16 *jp); const uint16 *WreckedShipRobot_Instr_10(uint16 k, const uint16 *jp); const uint16 *WreckedShipRobot_Instr_11(uint16 k, const uint16 *jp); @@ -4863,8 +3263,8 @@ const uint16 *WreckedShipRobot_Instr_8(uint16 k, const uint16 *jp); const uint16 *WreckedShipRobot_Instr_9(uint16 k, const uint16 *jp); const uint16 *WreckedShipSpark_Instr_1(uint16 k, const uint16 *jp); const uint16 *WreckedShipSpark_Instr_2(uint16 k, const uint16 *jp); -uint16 YappingMaw_Func_16(uint16 a); -uint16 YappingMaw_Func_17(uint16 a); +uint16 YappingMaw_Func_16(uint16 a, uint16 varE32); +uint16 YappingMaw_Func_17(uint16 a, uint16 varE32); const uint16 *YappingMaw_Instr_1(uint16 k, const uint16 *jp); const uint16 *YappingMaw_Instr_2(uint16 k, const uint16 *jp); const uint16 *YappingMaw_Instr_3(uint16 k, const uint16 *jp); @@ -4872,42 +3272,6 @@ const uint16 *YappingMaw_Instr_4(uint16 k, const uint16 *jp); const uint16 *YappingMaw_Instr_5(uint16 k, const uint16 *jp); const uint16 *YappingMaw_Instr_6(uint16 k, const uint16 *jp); const uint16 *YappingMaw_Instr_7(uint16 k, const uint16 *jp); -void Beetom_Func_1(void); -void Beetom_Func_10(void); -void Beetom_Func_11(void); -void Beetom_Func_12(void); -void Beetom_Func_13(void); -void Beetom_Func_14(void); -void Beetom_Func_15(void); -void Beetom_Func_16(void); -void Beetom_Func_17(void); -void Beetom_Func_18(void); -void Beetom_Func_19(void); -void Beetom_Func_20(void); -void Beetom_Func_21(void); -void Beetom_Func_22(uint16 k); -void Beetom_Func_23(uint16 k); -void Beetom_Func_24(void); -void Beetom_Func_25(void); -void Beetom_Func_26(uint16 k); -void Beetom_Func_27(uint16 k); -void Beetom_Func_28(void); -void Beetom_Func_29(void); -void Beetom_Func_3(void); -void Beetom_Func_30(uint16 k); -void Beetom_Func_31(uint16 k); -void Beetom_Func_32(void); -void Beetom_Func_33(void); -void Beetom_Func_34(void); -void Beetom_Func_35(void); -void Beetom_Func_36(void); -void Beetom_Func_37(uint16 k); -void Beetom_Func_4(void); -void Beetom_Func_5(void); -void Beetom_Func_6(void); -void Beetom_Func_7(void); -void Beetom_Func_8(void); -void Beetom_Func_9(void); void Beetom_Init(void); void Beetom_Main(void); void Beetom_Shot(void); @@ -5082,7 +3446,6 @@ void WreckedShipRobot_Shot(void); void WreckedShipSpark_Func_1(uint16 k); void WreckedShipSpark_Func_2(uint16 k); void WreckedShipSpark_Func_3(uint16 k); -void WreckedShipSpark_Func_4(uint16 k); void WreckedShipSpark_Init(void); void WreckedShipSpark_Main(void); void WreckedShipSpark_Shot(void); @@ -5115,8 +3478,8 @@ void sub_A8DDDE(uint16 k); void sub_A8F6DC(uint16 k, uint16 j); // Bank A9 -uint16 ComputeCosMult(uint16 a); -uint16 ComputeSinMult(uint16 a); +uint16 ComputeCosMult(uint16 a, uint16 r18); +uint16 ComputeSinMult(uint16 a, uint16 r18); uint16 HandleMotherBrainInstructionList(uint16 a); uint16 MotherBrain_DetermineShotReactionType(void); uint16 MotherBrain_Func_1_DoubleRetTmp(void); @@ -5194,18 +3557,18 @@ uint8 MotherBrain_MoveSamusHorizTowardsWall(uint16 a); uint8 MotherBrain_MoveSamusTowardsWallDueToBeam(void); uint8 MotherBrain_MoveSamusVerticallyTowardsCeilingFloor(uint16 a); uint8 MotherBrain_Phase2_DecideAttackStrategy_DoubleRet(void); -uint8 MotherBrain_SamusCollDetectPart(uint16 k); +uint8 MotherBrain_SamusCollDetectPart(uint16 k, uint16 r18, uint16 r20); uint8 MotherBrain_WalkBackwardsSlowlyAndRetractHead(uint16 a); uint8 ProcessCorpseRotting(uint16 k); uint8 ProcessSpriteTilesTransfers(uint8 db, uint16 k); uint8 Samus_HealDueToShitroid(void); uint8 ShitroidInCutscene_FadeShitroidToBlack(uint16 k); -uint8 Shitroid_AccelerateTowardsPoint(uint16 k, uint16 a); +uint8 Shitroid_AccelerateTowardsPoint(uint16 k, uint16 a, uint16 r18, uint16 r20); uint8 Shitroid_CheckIfOnScreen(uint16 k); uint8 Shitroid_Func_1(uint16 k, uint16 j); -uint8 Shitroid_Func_2(uint16 k); +uint8 Shitroid_Func_2(uint16 k, Rect16U rect); uint8 Shitroid_Func_27(uint16 k); -void CopyMoveCorpseRottingRotEntry(LongPtr r20, uint16 a); +void CopyMoveCorpseRottingRotEntry(LongPtr r20, uint16 a, uint16 r18); void CorpseRottingRotEntryFinishedHook(void); void DeadMonsters_Func_1(uint16 k); void DeadMonsters_Func_2(uint16 k); @@ -5330,7 +3693,7 @@ void MotherBrainBody_FakeDeath_Descent_3(void); void MotherBrainBody_FakeDeath_Descent_4(void); void MotherBrainBody_FakeDeath_Descent_5(void); void MotherBrainBody_FakeDeath_Descent_6(void); -void MotherBrain_AddSpritemapToOam(uint16 j); +void MotherBrain_AddSpritemapToOam(uint16 j, uint16 r18, uint16 r20, uint16 r22); void MotherBrain_AimBeam(void); void MotherBrain_AimBeamAndIncrWidth(void); void MotherBrain_B7CB(void); @@ -5354,7 +3717,7 @@ void MotherBrain_DrainedByShitroid_7(void); void MotherBrain_DrawBrain(void); void MotherBrain_DrawBrainNeck_EnemyGfxDrawHook(void); void MotherBrain_DrawNeck(void); -void MotherBrain_DrawNeckSegment(void); +void MotherBrain_DrawNeckSegment(uint16 x, uint16 y); void MotherBrain_ExplodeEscapeDoor(void); void MotherBrain_FiringBomb_Crouch(void); void MotherBrain_FiringBomb_DecideOnCrouching(void); @@ -5365,7 +3728,7 @@ void MotherBrain_FiringBomb_Standup(void); void MotherBrain_FiringBomb_WalkingBackwards(void); void MotherBrain_FootstepEffect(void); void MotherBrain_GenerateEscapeDoorExploding(void); -void MotherBrain_GenerateExplosions(uint16 a); +void MotherBrain_GenerateExplosions(uint16 a, uint16 r22, uint16 r24); void MotherBrain_GenerateMixedExplosions(void); void MotherBrain_GenerateSmokyExplosions(void); void MotherBrain_HandleBrainPal(void); @@ -5383,7 +3746,7 @@ void MotherBrain_HandleRainbowBeamExplosions(void); void MotherBrain_HandleRainbowBeamPalette(void); void MotherBrain_HandleWalking(void); void MotherBrain_HurtSamus(void); -void MotherBrain_Instr_AimRings(void); +void MotherBrain_Instr_AimRings(uint16 x, uint16 y); void MotherBrain_MaybeStandupOrLeanDown(void); void MotherBrain_MoveBodyDown(uint16 a); void MotherBrain_MoveBodyDownScrollLeft(uint16 k, uint16 a); @@ -5540,15 +3903,14 @@ void ShitroidInCutscene_ReleaseSamus(uint16 k); void ShitroidInCutscene_SetMotherBrainToStumbleBack(uint16 k); void ShitroidInCutscene_Shake(uint16 k); void ShitroidInCutscene_ShitroidFinalBelow(uint16 k); -void ShitroidInCutscene_SpawnOneDustCloudAt(uint16 a); void ShitroidInCutscene_SpawnThreeDustClouds(void); void ShitroidInCutscene_StareDownMotherBrain(uint16 k); void ShitroidInCutscene_StopDraining(uint16 k); void ShitroidInCutscene_Touch(void); void ShitroidInCutscene_UnloadShitroid(uint16 k); -void ShitroidInCutscene_UpdateSpeedAndAngle(uint16 k); -void Shitroid_AccelerateTowardsX(uint16 k); -void Shitroid_AccelerateTowardsY(uint16 k); +void ShitroidInCutscene_UpdateSpeedAndAngle(uint16 k, uint16 r18, uint16 r20, uint16 r22); +uint16 Shitroid_AccelerateTowardsX(uint16 k, uint16 r18, uint16 r22); +uint16 Shitroid_AccelerateTowardsY(uint16 k, uint16 r20, uint16 r22); void Shitroid_F3C4(uint16 k); void Shitroid_Func_10(uint16 k); void Shitroid_Func_11(uint16 k); @@ -5574,14 +3936,14 @@ void Shitroid_Func_6(uint16 k); void Shitroid_Func_7(uint16 k); void Shitroid_Func_8(uint16 k); void Shitroid_Func_9(uint16 k); -void Shitroid_Func_GraduallyAccelerateTowards0x400(uint16 k, uint16 j); -void Shitroid_GraduallyAccelerateHoriz(uint16 k); -void Shitroid_GraduallyAccelerateTowards0x10(uint16 k, uint16 j); -void Shitroid_GraduallyAccelerateTowards0x4(uint16 k, uint16 j); -void Shitroid_GraduallyAccelerateTowards0x8(uint16 k, uint16 j); -void Shitroid_GraduallyAccelerateTowardsPt(uint16 k, uint16 j); +void Shitroid_Func_GraduallyAccelerateTowards0x400(uint16 k, uint16 j, uint16 r18, uint16 r20); +void Shitroid_GraduallyAccelerateHoriz(uint16 k, uint16 r18, uint16 r24, uint16 r26); +void Shitroid_GraduallyAccelerateTowards0x10(uint16 k, uint16 j, uint16 r18, uint16 r20); +void Shitroid_GraduallyAccelerateTowards0x4(uint16 k, uint16 j, uint16 r18, uint16 r20); +void Shitroid_GraduallyAccelerateTowards0x8(uint16 k, uint16 j, uint16 r18, uint16 r20); +void Shitroid_GraduallyAccelerateTowardsPt(uint16 k, uint16 j, uint16 r18, uint16 r20, uint16 r26); void Shitroid_HandleCutscenePalette(void); -void Shitroid_HandleCutscenePalette_Common(void); +void Shitroid_HandleCutscenePalette_Common(uint16 r22, uint16 r18); void Shitroid_HandleCutscenePalette_LowHealth(void); void Shitroid_HandleNormalPalette(void); void Shitroid_Init(void); @@ -5773,16 +4135,16 @@ uint8 MotherBrain_Phase3_TurnLightsBackOn(uint16 a); void EnableEarthquakeAframes(uint16 a); void HandleMotherBrainBodyFlickering(void); void MotherBrain_CalcHdma(void); -void MotherBrain_CalcHdma_BeamAimedRight(void); +void MotherBrain_CalcHdma_BeamAimedRight(uint16 r22, uint16 r24); void MotherBrain_CalcHdma_BeamAimedRight2(void); void MotherBrain_CalcHdma_BeamAimedUp(void); void MotherBrain_CalcHdma_Down(void); -void MotherBrain_CalcHdma_Down_Down(void); -void MotherBrain_CalcHdma_Down_DownLeft(void); -void MotherBrain_CalcHdma_Down_DownRight(void); -void MotherBrain_CalcHdma_Up_Up(void); -void MotherBrain_CalcHdma_Up_UpLeft(void); -void MotherBrain_CalcHdma_Up_UpRight(void); +void MotherBrain_CalcHdma_Down_Down(uint16 r22, uint16 r24); +void MotherBrain_CalcHdma_Down_DownLeft(uint16 r22, uint16 r24); +void MotherBrain_CalcHdma_Down_DownRight(uint16 r22, uint16 r24); +void MotherBrain_CalcHdma_Up_Up(uint16 r22, uint16 r24); +void MotherBrain_CalcHdma_Up_UpLeft(uint16 r22, uint16 r24); +void MotherBrain_CalcHdma_Up_UpRight(uint16 r22, uint16 r24); void MotherBrain_HealthBasedPaletteHandling(void); void MotherBrain_SealWall(void); void TurnOffLightsForShitroidDeath(void); @@ -5885,7 +4247,7 @@ void Botwoon_Func_17(uint16 k); void Botwoon_Func_18(uint16 k); void Botwoon_Func_19(void); void Botwoon_Func_2(void); -void Botwoon_Func_20(uint16 k); +Point16U Botwoon_Func_20(uint16 k); void Botwoon_Func_21(void); void Botwoon_Func_22(void); void Botwoon_Func_23(void); @@ -5969,7 +4331,7 @@ void sub_B38E56(void); // Bank B4 void ClearSpriteObjects(void); -void CreateSpriteAtPos(void); +uint16 CreateSpriteAtPos(uint16 x_r18, uint16 y_r20, uint16 ilist_r22, uint16 pal_r24); void DrawSpriteObjects(void); void HandleSpriteObjects(void); void SpriteObject_Instr_Goto(void); @@ -6365,13 +4727,10 @@ void VerifySRAM(void); #define fnEprojInit_DraygonsGunk 0x868D04 #define fnEprojInit_DraygonsWallTurretProjs 0x868D40 #define fnnullsub_84 0x868D54 -#define fnEprojInstr_868D55 0x868D55 #define fnEprojInstr_868D99 0x868D99 #define fnEprojPreInstr_8DCA 0x868DCA #define fnEprojPreInstr_DraygonsTurret_8DFF 0x868DFF #define fnEprojPreInstr_DraygonsGunk_8E0F 0x868E0F -#define fnEprojInit_8E6C 0x868E7A -#define fnEprojPreInstr_8E6C 0x868E99 #define fnEprojInit_CrocomireProjectile 0x869023 #define fnEprojPreInstr_CrocomireProjectile 0x86906B #define fnsub_8690B3 0x8690B3 @@ -6637,7 +4996,7 @@ void VerifySRAM(void); #define fnsub_86E049 0x86E049 #define fnEproj_LavaThrownByLavaman_MoveX1 0x86E050 #define fnEproj_LavaThrownByLavaman_MoveX2 0x86E07A -#define fnEprojInst_DustCloudOrExplosion 0x86E468 +#define fnEprojInit_DustCloudOrExplosion 0x86E468 #define fnEprojInit_EyeDoorSmoke 0x86E4A6 #define fnEprojPreInstr_DustCloudOrExplosion 0x86E4FE #define fnEprojPreInstr_nullsub_98 0x86E508 @@ -7458,6 +5817,7 @@ void VerifySRAM(void); #define fnXray_Func6 0x91CE79 #define fnXray_Func6B 0x91CEBB #define fnXray_Func7 0x91CF36 +#define fnXray_Func8 0x91CF3E #define fnXray_Func9 0x91CF4E #define fnXray_Func10 0x91CF62 #define fnXray_Func11 0x91CF6F diff --git a/src/ida_types.h b/src/ida_types.h index 3e29e4a..1493e4c 100644 --- a/src/ida_types.h +++ b/src/ida_types.h @@ -64,11 +64,6 @@ typedef struct XraySpecialCasing { } XraySpecialCasing; /* 7 */ -typedef struct SpawnHardcodedPlmArgs { - uint8 field_0; - uint8 field_1; - VoidP field_2; -} SpawnHardcodedPlmArgs; /* 8 */ typedef struct RoomPlmEntry { @@ -1514,8 +1509,8 @@ enum Consts_60 { enum Consts_80 { addr_kHudTilemaps_AutoReserve = 0x998B, addr_kHudTilemaps_Missiles = 0x99A3, - addr_kDigitTilesetsHealth = 0x9DBF, - addr_kDigitTilesetsWeapon = 0x9DD3, + addrl_kDigitTilesetsHealth = 0x809DBF, + addrl_kDigitTilesetsWeapon = 0x809DD3, addr_word_80A060 = 0xA060, }; enum Consts_81 { @@ -2009,6 +2004,8 @@ enum Consts_90 { addr_kSamusSpeedTable_Normal_X__plus__12 = 0x9F55, addr_kSamusSpeedTable_Water_X = 0xA08D, addr_kSamusSpeedTable_LavaAcid_X = 0xA1DD, + addr_kSuperMissileAccelerations = 0xc303, + addr_kSuperMissileAccelerations2 = 0xc32b, addr_loc_90C4F0 = 0xC4F0, }; enum Consts_91 { diff --git a/src/sm_80.c b/src/sm_80.c index d1ef27d..f8a5ad5 100644 --- a/src/sm_80.c +++ b/src/sm_80.c @@ -16,10 +16,10 @@ -void APU_UploadBank(void) { // 0x808028 +void APU_UploadBank(uint32 addr) { // 0x808028 if (!g_use_my_apu_code) return; - RtlApuUpload(RomPtr(Load24(&R0_))); + RtlApuUpload(RomPtr(addr)); } uint16 NextRandom(void) { // 0x808111 @@ -42,7 +42,7 @@ void ReleaseButtonsFilter(uint16 v0) { // 0x808146 timed_held_input = 0; goto LABEL_6; } - if ((--timed_held_input_timer & 0x8000u) == 0) { + if ((--timed_held_input_timer & 0x8000) == 0) { timed_held_input = 0; goto LABEL_6; } @@ -59,18 +59,15 @@ uint16 PrepareBitAccess(uint16 a) { // 0x80818E } void SetBossBitForCurArea(uint16 a) { // 0x8081A6 - LOBYTE(bitmask) = a; boss_bits_for_area[area_index] |= a; } void ClearBossBitForCurArea(uint16 a) { // 0x8081C0 - LOBYTE(bitmask) = ~a; boss_bits_for_area[area_index] &= ~a; } uint8 CheckBossBitForCurArea(uint16 a) { // 0x8081DC - LOBYTE(bitmask) = a; - return ((uint8)a & boss_bits_for_area[area_index]) != 0; + return (a & boss_bits_for_area[area_index]) != 0; } void SetEventHappened(uint16 a) { // 0x8081FA @@ -80,8 +77,7 @@ void SetEventHappened(uint16 a) { // 0x8081FA void ClearEventHappened(uint16 v0) { // 0x808212 uint16 v1 = PrepareBitAccess(v0); - bitmask = ~bitmask; - events_that_happened[v1] &= bitmask; + events_that_happened[v1] &= ~bitmask; } uint16 CheckEventHappened(uint16 a) { // 0x808233 @@ -105,10 +101,9 @@ void VerifySRAM(void) { // 0x808261 } } -void Multiply16x16(uint16 a, uint16 j) { // 0x8082D6 +uint32 Multiply16x16(uint16 a, uint16 j) { // 0x8082D6 uint32 result = (uint32)a * (uint32)j; - mult_product_lo = result; - mult_product_hi = result >> 16; + return result; } CoroutineRet WaitForNMI_Async(void) { // 0x808338 @@ -160,16 +155,19 @@ void memset7E(uint16 *k, uint16 a, uint16 j) { // 0x8083F6 CoroutineRet Vector_RESET_Async(void) { // 0x80841C COROUTINE_BEGIN(coroutine_state_0, 1) - WriteReg(MEMSEL, 1u); + WriteReg(MEMSEL, 1); reg_MEMSEL = 1; // Removed code to wait 4 frames + uint16 bak = bug_fix_counter; memset(g_ram, 0, 8192); + bug_fix_counter = bak; COROUTINE_AWAIT(2, InitializeIoDisplayLogo_Async()); COROUTINE_MANUAL_POS(3); // Soft reset position - mov24(&R0_, 0xCF8000); - APU_UploadBank(); + APU_UploadBank(0xCF8000); WriteReg(INIDISP, 0x8F); + bak = bug_fix_counter; memset(g_ram, 0, 0x10000); + bug_fix_counter = bak; WriteReg(NMITIMEN, 0); reg_NMITIMEN = 0; reg_INIDISP = 0x8f; @@ -249,11 +247,11 @@ void SaveExploredMapTilesToSaved(void) { // 0x8085C6 v2 += 2; } while ((int16)(v2 - 256) < 0); if (has_area_map) - *(uint16 *)&map_station_byte_array[area_index] |= 0xFFu; + *(uint16 *)&map_station_byte_array[area_index] |= 0xFF; } void InitializeCpuIoRegs(void) { // 0x80875D - WriteReg(NMITIMEN, 1u); + WriteReg(NMITIMEN, 1); reg_NMITIMEN = 1; WriteReg(WRIO, 0); WriteReg(WRMPYA, 0); @@ -268,14 +266,14 @@ void InitializeCpuIoRegs(void) { // 0x80875D WriteReg(MDMAEN, 0); WriteReg(HDMAEN, 0); reg_HDMAEN = 0; - WriteReg(MEMSEL, 1u); + WriteReg(MEMSEL, 1); reg_MEMSEL = 1; } void InitializePpuIoRegs(void) { // 0x808792 WriteReg(INIDISP, 0x8F); reg_INIDISP = 0x8f; - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; WriteReg(OAMADDL, 0); LOBYTE(reg_OAMaddr_UNUSED) = 0; @@ -283,7 +281,7 @@ void InitializePpuIoRegs(void) { // 0x808792 HIBYTE(reg_OAMaddr_UNUSED) = 0x80; WriteReg(OAMDATA, 0); WriteReg(OAMDATA, 0); - WriteReg(BGMODE, 9u); + WriteReg(BGMODE, 9); reg_BGMODE = 9; WriteReg(MOSAIC, 0); reg_MOSAIC = 0; @@ -297,7 +295,7 @@ void InitializePpuIoRegs(void) { // 0x808792 reg_BG4SC = 0; WriteReg(BG12NBA, 0); reg_BG12NBA = 0; - WriteReg(BG34NBA, 5u); + WriteReg(BG34NBA, 5); reg_BG34NBA = 5; WriteReg(BG1HOFS, 0); WriteReg(BG1HOFS, 0); @@ -346,11 +344,11 @@ void InitializePpuIoRegs(void) { // 0x808792 reg_TM = 17; WriteReg(TMW, 0x11); reg_TMW = 17; - WriteReg(TS, 2u); + WriteReg(TS, 2); reg_TS = 2; - WriteReg(TSW, 2u); + WriteReg(TSW, 2); reg_TSW = 2; - WriteReg(CGWSEL, 2u); + WriteReg(CGWSEL, 2); next_gameplay_CGWSEL = 2; WriteReg(CGADSUB, 0xA1); next_gameplay_CGADSUB = -95; @@ -367,9 +365,9 @@ void InitializePpuIoRegs(void) { // 0x808792 } void WriteLotsOf0x1c2f(void) { // 0x8088D1 - sub_8088EB(0x1C2Fu); - sub_8088FE(0x1C2Fu); - sub_808911(0x1C2Fu); + sub_8088EB(0x1C2F); + sub_8088FE(0x1C2F); + sub_808911(0x1C2F); } void sub_8088EB(uint16 a) { // 0x8088EB @@ -420,27 +418,22 @@ void ClearOamExt(void) { // 0x808B1A void QueueMode7Transfers(uint8 db, uint16 k) { // 0x808B4F const uint8 *p = RomPtrWithBank(db, k); - uint16 v2 = mode7_vram_write_queue_tail; + uint8 *dst = (uint8 *)mode7_write_queue + mode7_vram_write_queue_tail; for (;;) { int f = GET_BYTE(p); if (f & 0x80) { - *(uint16 *)(&mode7_write_queue[0].field_0 + v2) = GET_WORD(p); - *(uint16 *)((uint8 *)&mode7_write_queue[0].field_1 + v2 + 1) = GET_WORD(p + 2); - *(uint16 *)&mode7_write_queue[0].gap3[v2 + 1] = GET_WORD(p + 4); - *(uint16 *)&mode7_write_queue[0].gap3[v2 + 3] = GET_WORD(p + 6); - *(uint16 *)((uint8 *)&mode7_write_queue[1].field_1 + v2) = p[8]; - p += 9, v2 += 9; + dst[9] = 0; + memcpy(dst, p, 9); + p += 9, dst += 9; } else if (f & 0x40) { - *(uint16 *)(&mode7_write_queue[0].field_0 + v2) = GET_WORD(p); - *(uint16 *)((uint8 *)&mode7_write_queue[0].field_1 + v2 + 1) = GET_WORD(p + 2); - *(uint16 *)&mode7_write_queue[0].gap3[v2 + 1] = GET_WORD(p + 4); - *(uint16 *)&mode7_write_queue[0].gap3[v2 + 3] = p[6]; - p += 7, v2 += 7; + dst[7] = 0; + memcpy(dst, p, 7); + p += 7, dst += 7; } else { break; } } - mode7_vram_write_queue_tail = v2; + mode7_vram_write_queue_tail = dst - (uint8 *)mode7_write_queue; } void NMI_ProcessMode7Queue(void) { // 0x808BBA @@ -469,7 +462,7 @@ void NMI_ProcessMode7QueueInner(const uint8 *p) { // 0x808BD3 WriteReg(BBAD1, 0x18); WriteRegWord(VMADDL, v5->vram_addr); WriteReg(VMAIN, v5->vmain); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); p += sizeof(Mode7CgvmWriteQueue); } if (!(v2 & 0x40)) @@ -480,7 +473,7 @@ void NMI_ProcessMode7QueueInner(const uint8 *p) { // 0x808BD3 WriteRegWord(DAS1L, *((uint16 *)p + 2)); WriteReg(BBAD1, 0x22); WriteReg(CGADD, p[6]); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); p += 7; } } @@ -498,7 +491,7 @@ void NMI_ProcessVramWriteQueue(void) { // 0x808C83 WriteReg(A1B1, e->src.bank); WriteRegWord(VMAIN, sign16(e->vram_dst) ? 0x81 : 0x80); WriteRegWord(VMADDL, e->vram_dst); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } } vram_write_queue_tail = 0; @@ -517,22 +510,22 @@ void Nmi_ProcessHorizScrollingDma(void) { // 0x808CD8 WriteReg(A1B1, 0x7E); uint16 v1 = bg1_update_col_unwrapped_size; WriteRegWord(DAS1L, bg1_update_col_unwrapped_size); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v0 + 1); WriteRegWord(DAS1L, v1); WriteRegWord(A1T1L, ADDR16_OF_RAM(*bg1_column_update_tilemap_right_halves)); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(A1T1L, bg1_update_col_wrapped_left_src); uint16 v2 = bg1_update_col_wrapped_size; if (bg1_update_col_wrapped_size) { WriteRegWord(DAS1L, bg1_update_col_wrapped_size); uint16 v3 = bg1_update_col_wrapped_dst; WriteRegWord(VMADDL, bg1_update_col_wrapped_dst); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v3 + 1); WriteRegWord(DAS1L, v2); WriteRegWord(A1T1L, bg1_update_col_wrapped_right_src); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } } if ((uint8)bg2_update_col_enable) { @@ -544,22 +537,22 @@ void Nmi_ProcessHorizScrollingDma(void) { // 0x808CD8 WriteReg(A1B1, 0x7E); uint16 v5 = bg2_update_col_unwrapped_size; WriteRegWord(DAS1L, bg2_update_col_unwrapped_size); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v4 + 1); WriteRegWord(DAS1L, v5); WriteRegWord(A1T1L, ADDR16_OF_RAM(*bg2_column_update_tilemap_right_halves)); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(A1T1L, bg2_update_col_wrapped_left_src); uint16 v6 = bg2_update_col_wrapped_size; if (bg2_update_col_wrapped_size) { WriteRegWord(DAS1L, bg2_update_col_wrapped_size); uint16 v7 = bg2_update_col_wrapped_dst; WriteRegWord(VMADDL, bg2_update_col_wrapped_dst); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v7 + 1); WriteRegWord(DAS1L, v6); WriteRegWord(A1T1L, bg2_update_col_wrapped_right_src); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } } } @@ -575,22 +568,22 @@ void Nmi_ProcessVertScrollingDma(void) { // 0x808DAC WriteReg(A1B1, 0x7E); uint16 v1 = bg1_update_row_unwrapped_size; WriteRegWord(DAS1L, bg1_update_row_unwrapped_size); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v0 | 0x20); WriteRegWord(DAS1L, v1); WriteRegWord(A1T1L, ADDR16_OF_RAM(*bg1_column_update_tilemap_bottom_halves)); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(A1T1L, bg1_update_row_wrapped_top_src); uint16 v2 = bg1_update_row_wrapped_size; if (bg1_update_row_wrapped_size) { WriteRegWord(DAS1L, bg1_update_row_wrapped_size); uint16 v3 = bg1_update_row_wrapped_dst; WriteRegWord(VMADDL, bg1_update_row_wrapped_dst); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v3 | 0x20); WriteRegWord(DAS1L, v2); WriteRegWord(A1T1L, bg1_update_row_wrapped_bottom_src); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } } if ((uint8)bg2_update_row_enable) { @@ -602,22 +595,22 @@ void Nmi_ProcessVertScrollingDma(void) { // 0x808DAC WriteReg(A1B1, 0x7E); uint16 v5 = bg2_update_row_unwrapped_size; WriteRegWord(DAS1L, bg2_update_row_unwrapped_size); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v4 | 0x20); WriteRegWord(DAS1L, v5); WriteRegWord(A1T1L, ADDR16_OF_RAM(*bg2_column_update_tilemap_bottom_halves)); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(A1T1L, bg2_update_row_wrapped_top_src); uint16 v6 = bg2_update_row_wrapped_size; if (bg2_update_row_wrapped_size) { WriteRegWord(DAS1L, bg2_update_row_wrapped_size); uint16 v7 = bg2_update_row_wrapped_dst; WriteRegWord(VMADDL, bg2_update_row_wrapped_dst); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, v7 | 0x20); WriteRegWord(DAS1L, v6); WriteRegWord(A1T1L, bg2_update_row_wrapped_bottom_src); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } } } @@ -636,7 +629,7 @@ void NMI_ProcessVramReadQueue(void) { // 0x808EA2 WriteRegWord(DAS1L, vram_read_queue[v0].size); WriteRegWord(DAS10, 0); WriteRegWord(A2A1H, 0); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); ++v0; } LOBYTE(vram_read_queue_tail) = 0; @@ -655,14 +648,13 @@ uint8 HasQueuedMusic(void) { // 0x808EF4 void HandleMusicQueue(void) { // 0x808F0C bool v0 = music_timer-- == 1; - if ((music_timer & 0x8000u) == 0) { + if ((music_timer & 0x8000) == 0) { if (!v0) return; - if ((music_entry & 0x8000u) != 0) { + if ((music_entry & 0x8000) != 0) { music_data_index = (uint8)music_entry; cur_music_track = -1; - copy24(&R0_, (LongPtr *)((uint8 *)&kMusicPointers + (uint8)music_entry)); - APU_UploadBank(); + APU_UploadBank(Load24((LongPtr *)((uint8 *)&kMusicPointers + (uint8)music_entry))); cur_music_track = 0; int v5 = music_queue_read_pos; music_queue_track[v5 >> 1] = 0; @@ -693,7 +685,7 @@ void HandleMusicQueue(void) { // 0x808F0C void QueueMusic_Delayed8(uint16 a) { // 0x808FC1 int8 v1; - if (game_state < kGameState_40_TransitionToDemo && (((uint8)music_queue_write_pos + 2) & 0xE) != music_queue_read_pos) { + if (game_state < kGameState_40_TransitionToDemo && ((music_queue_write_pos + 2) & 0xE) != music_queue_read_pos) { v1 = music_queue_write_pos; int v2 = music_queue_write_pos >> 1; music_queue_track[v2] = a; @@ -703,11 +695,11 @@ void QueueMusic_Delayed8(uint16 a) { // 0x808FC1 } void QueueMusic_DelayedY(uint16 a, uint16 j) { // 0x808FF7 - if (game_state < 0x28u) { + if (game_state < 0x28) { int v2 = music_queue_write_pos; music_queue_track[v2 >> 1] = a; int v4 = j; - if (j < 8u) + if (j < 8) v4 = 8; music_queue_delay[v2 >> 1] = v4; music_queue_write_pos = (v2 + 2) & 0xE; @@ -736,12 +728,12 @@ void QueueSfx1_Max6(uint16 a) { // 0x809049 void QueueSfx1_Internal(uint16 a) { // 0x809051 sfx_max_queued[0] = a; - if ((uint8)((sfx_writepos[0] - sfx_readpos[0]) & 0xF) < (uint8)a) { + if (((sfx_writepos[0] - sfx_readpos[0]) & 0xF) < (uint8)a) { uint8 v2 = GET_HIBYTE(a); - if (!debug_disable_sounds && game_state < 0x28u && (power_bomb_explosion_status & 0x8000u) == 0) { + if (!debug_disable_sounds && game_state < 0x28 && (power_bomb_explosion_status & 0x8000) == 0) { uint8 v1 = sfx_writepos[0]; uint8 v3 = sfx_writepos[0] + 1; - if (v3 >= 0x10u) + if (v3 >= 0x10) v3 = 0; if (v3 == sfx_readpos[0]) { if (v2 < sfx1_queue[v1]) @@ -777,12 +769,12 @@ void QueueSfx2_Max6(uint16 a) { // 0x8090CB void QueueSfx2_Internal(uint16 a) { // 0x8090D3 sfx_max_queued[1] = a; - if ((uint8)((sfx_writepos[1] - sfx_readpos[1]) & 0xF) < (uint8)a) { + if (((sfx_writepos[1] - sfx_readpos[1]) & 0xF) < (uint8)a) { uint8 v2 = GET_HIBYTE(a); - if (!debug_disable_sounds && game_state < 0x28u && (power_bomb_explosion_status & 0x8000u) == 0) { + if (!debug_disable_sounds && game_state < 0x28 && (power_bomb_explosion_status & 0x8000) == 0) { uint8 v1 = sfx_writepos[1]; uint8 v3 = sfx_writepos[1] + 1; - if (v3 >= 0x10u) + if (v3 >= 0x10) v3 = 0; if (v3 == sfx_readpos[1]) { if (v2 < sfx2_queue[v1]) @@ -818,12 +810,12 @@ void QueueSfx3_Max6(uint16 a) { // 0x80914D void QueueSfx3_Internal(uint16 a) { // 0x809155 sfx_max_queued[2] = a; - if ((uint8)((sfx_writepos[2] - sfx_readpos[2]) & 0xF) < (uint8)a) { + if (((sfx_writepos[2] - sfx_readpos[2]) & 0xF) < (uint8)a) { uint8 v2 = GET_HIBYTE(a); - if (!debug_disable_sounds && game_state < 0x28u && (power_bomb_explosion_status & 0x8000u) == 0) { + if (!debug_disable_sounds && game_state < 0x28 && (power_bomb_explosion_status & 0x8000) == 0) { uint8 v1 = sfx_writepos[2]; uint8 v3 = sfx_writepos[2] + 1; - if (v3 >= 0x10u) + if (v3 >= 0x10) v3 = 0; if (v3 == sfx_readpos[2]) { if (v2 < sfx3_queue[v1]) @@ -926,7 +918,7 @@ void NmiUpdatePalettesAndOam(void) { // 0x80933A WriteReg(A1B1, 0x7E); WriteRegWord(DAS1L, 0x200); WriteReg(CGADD, 0); - WriteReg(MDMAEN, 3u); + WriteReg(MDMAEN, 3); } void NmiTransferSamusToVram(void) { // 0x809376 @@ -940,12 +932,12 @@ void NmiTransferSamusToVram(void) { // 0x809376 WriteRegWord(A1B1, GET_WORD(rp + 2)); uint16 v2 = GET_WORD(rp + 3); WriteRegWord(DAS1L, v2); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, 0x6100); WriteRegWord(A1T1L, v0 + v2); if (GET_WORD(rp + 5)) { WriteRegWord(DAS1L, GET_WORD(rp + 5)); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } } if (HIBYTE(nmi_copy_samus_halves)) { @@ -957,18 +949,18 @@ void NmiTransferSamusToVram(void) { // 0x809376 WriteRegWord(A1B1, GET_WORD(rp + 2)); uint16 v6 = GET_WORD(rp + 3); WriteRegWord(DAS1L, v6); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, 0x6180); WriteRegWord(A1T1L, v4 + v6); if (GET_WORD(rp + 5)) { WriteRegWord(DAS1L, GET_WORD(rp + 5)); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } } } void NmiProcessAnimtilesVramTransfers(void) { // 0x809416 - if ((animtiles_enable_flag & 0x8000u) != 0) { + if ((animtiles_enable_flag & 0x8000) != 0) { for (int i = 10; (i & 0x80) == 0; i -= 2) { int v1 = i >> 1; if (animtiles_ids[v1]) { @@ -979,7 +971,7 @@ void NmiProcessAnimtilesVramTransfers(void) { // 0x809416 WriteRegWord(DAS0L, animtiles_sizes[v1]); WriteRegWord(VMADDL, animtiles_vram_ptr[v1]); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 1u); + WriteReg(MDMAEN, 1); animtiles_src_ptr[v1] = 0; } } @@ -1031,10 +1023,10 @@ void ReadJoypadInputs(void) { // 0x809459 joypad1_newkeys = 0; } if ((joypad_dbg_2 & 0x80) != 0) - *(uint16 *)®_NMITIMEN ^= 0x30u; - if ((joypad_dbg_2 & 0x8000u) != 0) { - bool v2 = (~joypad_dbg_flags & 0x8000u) != 0; - joypad_dbg_flags ^= 0x8000u; + *(uint16 *)®_NMITIMEN ^= 0x30; + if ((joypad_dbg_2 & 0x8000) != 0) { + bool v2 = (~joypad_dbg_flags & 0x8000) != 0; + joypad_dbg_flags ^= 0x8000; if (v2) { joypad_dbg_missiles_swap = samus_missiles; joypad_dbg_super_missiles_swap = samus_super_missiles; @@ -1049,13 +1041,13 @@ void ReadJoypadInputs(void) { // 0x809459 } } if ((joypad_dbg_2 & 0x40) != 0) - joypad_dbg_flags ^= 0x2000u; + joypad_dbg_flags ^= 0x2000; } } else { joypad_dbg_1 = 0; joypad_dbg_2 = 0; - joypad2_last &= 0x10u; - joypad2_new_keys &= 0x10u; + joypad2_last &= 0x10; + joypad2_new_keys &= 0x10; } } else { debug_disable_sounds = 0; @@ -1097,13 +1089,13 @@ void Irq_DoorTransitionVramUpdate(void) { // 0x809632 WriteReg(A1B1, door_transition_vram_update_src.bank); WriteRegWord(DAS1L, door_transition_vram_update_size); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); door_transition_vram_update_enabled &= ~0x8000; WriteReg(INIDISP, 0xF); } void WaitForIrqDoorTransitionVramUpdate(void) { - door_transition_vram_update_enabled |= 0x8000u; + door_transition_vram_update_enabled |= 0x8000; Irq_DoorTransitionVramUpdate(); } @@ -1129,7 +1121,7 @@ void IrqHandler_4_Main_BeginHudDraw(void) { // 0x80968B WriteReg(BG3SC, 0x5A); WriteReg(CGWSEL, 0); WriteReg(CGADSUB, 0); - WriteReg(TM, 4u); + WriteReg(TM, 4); IrqHandler_SetResult(6, 31, 152); } @@ -1146,7 +1138,7 @@ void IrqHandler_6_Main_EndHudDraw(void) { // 0x8096A9 void IrqHandler_8_StartOfDoor_BeginHud(void) { // 0x8096D3 WriteReg(BG3SC, 0x5A); - WriteReg(TM, 4u); + WriteReg(TM, 4); WriteReg(CGWSEL, 0); WriteReg(CGADSUB, 0); IrqHandler_SetResult(10, 31, 152); @@ -1154,7 +1146,7 @@ void IrqHandler_8_StartOfDoor_BeginHud(void) { // 0x8096D3 void IrqHandler_10_StartOfDoor_EndHud(void) { // 0x8096F1 uint8 v0; - if ((((uint8)previous_cre_bitset | (uint8)cre_bitset) & 1) != 0) + if (((previous_cre_bitset | cre_bitset) & 1) != 0) v0 = 16; else v0 = 17; @@ -1165,7 +1157,7 @@ void IrqHandler_10_StartOfDoor_EndHud(void) { // 0x8096F1 } void IrqHandler_12_Draygon_BeginHud(void) { // 0x80971A - WriteReg(TM, 4u); + WriteReg(TM, 4); WriteReg(CGWSEL, 0); WriteReg(CGADSUB, 0); IrqHandler_SetResult(14, 31, 152); @@ -1181,7 +1173,7 @@ void IrqHandler_14_Draygon_EndHud(void) { // 0x809733 } void IrqHandler_16_VerticalDoor_BeginHud(void) { // 0x809758 - WriteReg(TM, 4u); + WriteReg(TM, 4); WriteReg(CGWSEL, 0); WriteReg(CGADSUB, 0); IrqHandler_SetResult(18, 31, 152); @@ -1196,9 +1188,9 @@ void IrqHandler_18_VerticalDoor_EndHud(void) { // 0x809771 WriteReg(TM, v0); WriteReg(CGWSEL, 0); WriteReg(CGADSUB, 0); -// if ((door_transition_vram_update_enabled & 0x8000u) != 0) +// if ((door_transition_vram_update_enabled & 0x8000) != 0) // Irq_DoorTransitionVramUpdate(); - if ((door_transition_flag & 0x8000u) == 0) + if ((door_transition_flag & 0x8000) == 0) Irq_FollowDoorTransition(); IrqHandler_SetResult(20, 216, 152); } @@ -1211,7 +1203,7 @@ void IrqHandler_20_VerticalDoor_EndDraw(void) { // 0x8097A9 } void IrqHandler_22_HorizDoor_BeginHud(void) { // 0x8097C1 - WriteReg(TM, 4u); + WriteReg(TM, 4); WriteReg(CGWSEL, 0); WriteReg(CGADSUB, 0); IrqHandler_SetResult(24, 31, 152); @@ -1227,7 +1219,7 @@ void IrqHandler_24_HorizDoor_EndHud(void) { // 0x8097DA WriteReg(TM, v0); WriteReg(CGWSEL, 0); WriteReg(CGADSUB, 0); - if ((door_transition_flag & 0x8000u) == 0) + if ((door_transition_flag & 0x8000) == 0) Irq_FollowDoorTransition(); IrqHandler_SetResult(26, 160, 152); } @@ -1241,13 +1233,13 @@ void IrqHandler_26_HorizDoor_EndDraw(void) { // 0x80980A void EnableIrqInterrupts(void) { // 0x80982A WriteRegWord(VTIMEL, 0); WriteRegWord(HTIMEL, 152); - *(uint16 *)®_NMITIMEN |= 0x30u; + *(uint16 *)®_NMITIMEN |= 0x30; } void EnableIrqInterruptsNow(void) { // 0x809841 WriteRegWord(VTIMEL, 0); WriteRegWord(HTIMEL, 152); - *(uint16 *)®_NMITIMEN |= 0x30u; + *(uint16 *)®_NMITIMEN |= 0x30; WriteReg(NMITIMEN, reg_NMITIMEN); } @@ -1336,10 +1328,10 @@ void InitializeHud(void) { // 0x809A79 WriteRegWord(VMAIN, 0x80); static const StartDmaCopy unk_809A8F = { 1, 1, 0x18, LONGPTR(0x80988b), 0x0040 }; SetupDmaTransfer(&unk_809A8F); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); for (int i = 0; i != 192; i += 2) hud_tilemap[i >> 1] = kHudTilemaps_Row1to3[i >> 1]; - if ((equipped_items & 0x8000u) != 0) + if ((equipped_items & 0x8000) != 0) AddXrayToHudTilemap(); if ((equipped_items & 0x4000) != 0) AddGrappleToHudTilemap(); @@ -1355,14 +1347,12 @@ void InitializeHud(void) { // 0x809A79 samus_prev_power_bombs = 0; samus_prev_hud_item_index = 0; InitializeMiniMapBroken(); - R0_.addr = addr_kDigitTilesetsWeapon; - *(uint16 *)&R0_.bank = 128; if (samus_max_missiles) - DrawThreeHudDigits(R0_, samus_missiles, 0x94); + DrawThreeHudDigits(addrl_kDigitTilesetsWeapon, samus_missiles, 0x94); if (samus_max_super_missiles) - DrawTwoHudDigits(R0_, samus_super_missiles, 0x9C); + DrawTwoHudDigits(addrl_kDigitTilesetsWeapon, samus_super_missiles, 0x9C); if (samus_max_power_bombs) - DrawTwoHudDigits(R0_, samus_power_bombs, 0xA2); + DrawTwoHudDigits(addrl_kDigitTilesetsWeapon, samus_power_bombs, 0xA2); ToggleHudItemHighlight(hud_item_index, 0x1000); ToggleHudItemHighlight(samus_prev_hud_item_index, 0x1400); HandleHudTilemap(); @@ -1371,7 +1361,6 @@ void InitializeHud(void) { // 0x809A79 static const uint16 kEnergyTankIconTilemapOffsets[14] = { 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 2, 4, 6, 8, 0xa, 0xc, 0xe }; void HandleHudTilemap(void) { // 0x809B44 - R0_.bank = 0; if (reserve_health_mode == 1) { const uint16 *v1 = (const uint16 *)RomPtr_80(addr_kHudTilemaps_AutoReserve); if (!samus_reserve_health) @@ -1386,39 +1375,37 @@ void HandleHudTilemap(void) { // 0x809B44 if (samus_health != samus_prev_health) { samus_prev_health = samus_health; - R20_ = SnesDivide(samus_health, 100); - R18_ = SnesModulus(samus_health, 100); + uint16 r20 = SnesDivide(samus_health, 100); + uint16 r18 = SnesModulus(samus_health, 100); int v2 = 0; - R22_ = SnesDivide(samus_max_health, 100) + 1; + int n = SnesDivide(samus_max_health, 100) + 1; do { - if (!--R22_) + if (!--n) break; uint16 v3 = 13360; - if (R20_) { - --R20_; + if (r20) { + --r20; v3 = 10289; } hud_tilemap[kEnergyTankIconTilemapOffsets[v2 >> 1] >> 1] = v3; v2 += 2; } while ((int16)(v2 - 28) < 0); - R0_.addr = addr_kDigitTilesetsHealth; - DrawTwoHudDigits(R0_, R18_, 0x8C); + DrawTwoHudDigits(addrl_kDigitTilesetsHealth, r18, 0x8C); } - R0_.addr = addr_kDigitTilesetsWeapon; if (samus_max_missiles && samus_missiles != samus_prev_missiles) { samus_prev_missiles = samus_missiles; - DrawThreeHudDigits(R0_, samus_missiles, 0x94); + DrawThreeHudDigits(addrl_kDigitTilesetsWeapon, samus_missiles, 0x94); } if (samus_max_super_missiles && samus_super_missiles != samus_prev_super_missiles) { samus_prev_super_missiles = samus_super_missiles; if ((joypad_dbg_flags & 0x1F40) != 0) - DrawThreeHudDigits(R0_, samus_prev_super_missiles, 0x9C); + DrawThreeHudDigits(addrl_kDigitTilesetsWeapon, samus_prev_super_missiles, 0x9C); else - DrawTwoHudDigits(R0_, samus_prev_super_missiles, 0x9C); + DrawTwoHudDigits(addrl_kDigitTilesetsWeapon, samus_prev_super_missiles, 0x9C); } if (samus_max_power_bombs && samus_power_bombs != samus_prev_power_bombs) { samus_prev_power_bombs = samus_power_bombs; - DrawTwoHudDigits(R0_, samus_power_bombs, 0xA2); + DrawTwoHudDigits(addrl_kDigitTilesetsWeapon, samus_power_bombs, 0xA2); } if (hud_item_index != samus_prev_hud_item_index) { ToggleHudItemHighlight(hud_item_index, 0x1000); @@ -1428,7 +1415,7 @@ void HandleHudTilemap(void) { // 0x809B44 && samus_movement_type != 20 && grapple_beam_function == 0xC4F0 && !time_is_frozen_flag) { - QueueSfx1_Max6(0x39u); + QueueSfx1_Max6(0x39); } } uint16 v4 = 5120; @@ -1471,19 +1458,15 @@ void ToggleHudItemHighlight(uint16 a, uint16 k) { // 0x809CEA } } -void DrawThreeHudDigits(LongPtr r0, uint16 a, uint16 k) { // 0x809D78 - uint16 v2 = 2 * (a / 100); - hud_tilemap[k >> 1] = IndirReadWord(r0, v2); - uint16 RegWord = (a % 100); - DrawTwoHudDigits(r0, RegWord, k + 2); +void DrawThreeHudDigits(uint32 addr, uint16 a, uint16 k) { // 0x809D78 + hud_tilemap[k >> 1] = GET_WORD(RomPtr(addr + 2 * (a / 100))); + DrawTwoHudDigits(addr, a % 100, k + 2); } -void DrawTwoHudDigits(LongPtr r0, uint16 a, uint16 k) { // 0x809D98 - uint16 RegWord = a / 10; +void DrawTwoHudDigits(uint32 addr, uint16 a, uint16 k) { // 0x809D98 int v3 = k >> 1; - hud_tilemap[v3] = IndirReadWord(r0, 2 * RegWord); - uint16 v4 = 2 * (a % 10); - hud_tilemap[v3 + 1] = IndirReadWord(r0, v4); + hud_tilemap[v3] = GET_WORD(RomPtr(addr + 2 * (a / 10))); + hud_tilemap[v3 + 1] = GET_WORD(RomPtr(addr + 2 * (a % 10))); } static Func_U8 *const kTimerProcessFuncs[7] = { // 0x809DE7 @@ -1493,7 +1476,7 @@ static Func_U8 *const kTimerProcessFuncs[7] = { // 0x809DE7 ProcessTimer_InitialDelay, ProcessTimer_MovementDelayed, ProcessTimer_MovingIntoPlace, - j_ProcessTimer_Decrement, + ProcessTimer_Decrement, }; uint8 ProcessTimer(void) { @@ -1520,14 +1503,14 @@ uint8 ProcessTimer_MotherBrainStart(void) { // 0x809E1C uint8 ProcessTimer_InitialDelay(void) { // 0x809E2F LOBYTE(timer_x_pos) = timer_x_pos + 1; - if ((uint8)timer_x_pos >= 0x10u) + if ((uint8)timer_x_pos >= 0x10) LOBYTE(timer_status) = timer_status + 1; return 0; } uint8 ProcessTimer_MovementDelayed(void) { // 0x809E41 LOBYTE(timer_x_pos) = timer_x_pos + 1; - if ((uint8)timer_x_pos >= 0x60u) { + if ((uint8)timer_x_pos >= 0x60) { LOBYTE(timer_x_pos) = 0; LOBYTE(timer_status) = timer_status + 1; } @@ -1537,23 +1520,19 @@ uint8 ProcessTimer_MovementDelayed(void) { // 0x809E41 uint8 ProcessTimer_MovingIntoPlace(void) { // 0x809E58 int v0 = 0; uint16 v1 = timer_x_pos + 224; - if ((uint16)(timer_x_pos + 224) >= 0xDC00u) { + if ((uint16)(timer_x_pos + 224) >= 0xDC00) { v0 = 1; v1 = -9216; } timer_x_pos = v1; uint16 v2 = timer_y_pos - 193; - if ((uint16)(timer_y_pos - 193) < 0x3000u) { + if ((uint16)(timer_y_pos - 193) < 0x3000) { ++v0; v2 = 12288; } timer_y_pos = v2; if (v0 == 2) ++timer_status; - return j_ProcessTimer_Decrement(); -} - -uint8 j_ProcessTimer_Decrement(void) { // 0x809E89 return ProcessTimer_Decrement(); } @@ -1614,18 +1593,12 @@ void DrawTimer(void) { // 0x809F6C void DrawTwoTimerDigits(uint16 a, uint16 k) { // 0x809F95 - int8 v2; - - v2 = a; - DrawTimerSpritemap(k, kTimerDigitsSpritemapPtr[(uint16)((uint8)(a & 0xF0) >> 3) >> 1]); - DrawTimerSpritemap(k + 8, kTimerDigitsSpritemapPtr[v2 & 0xF]); + DrawTimerSpritemap(k, kTimerDigitsSpritemapPtr[(a & 0xF0) >> 4]); + DrawTimerSpritemap(k + 8, kTimerDigitsSpritemapPtr[a & 0xF]); } void DrawTimerSpritemap(uint16 a, uint16 j) { // 0x809FB3 - R20_ = a + HIBYTE(timer_x_pos); - R18_ = HIBYTE(timer_y_pos); - R22_ = 2560; - DrawSpritemap(0x80, j); + DrawSpritemap(0x80, j, a + HIBYTE(timer_x_pos), HIBYTE(timer_y_pos), 2560); } CoroutineRet StartGameplay_Async(void) { // 0x80A07B @@ -1668,8 +1641,7 @@ CoroutineRet StartGameplay_Async(void) { // 0x80A07B irqhandler_next_handler = (room_loading_irq_handler == 0) ? 4 : room_loading_irq_handler; EnableIrqInterrupts(); COROUTINE_AWAIT(3, Play20FramesOfMusic_Async()); - static const SpawnHardcodedPlmArgs unk_80A11E = { 0x08, 0x08, 0xb7eb }; - SpawnHardcodedPlm(&unk_80A11E); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x08, 0x08, 0xb7eb }); door_transition_function = FUNC16(DoorTransition_FadeInScreenAndFinish); COROUTINE_END(0); } @@ -1746,14 +1718,14 @@ void ClearBG2Tilemap(void) { // 0x80A23F WriteRegWord(A1B1, 0x80); WriteRegWord(DAS1L, 0x800); WriteReg(VMAIN, 0); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, 0x4800); WriteRegWord(DMAP1, 0x1908); WriteRegWord(A1T1L, 0xA29A); WriteRegWord(A1B1, 0x80); WriteRegWord(DAS1L, 0x800); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } void ClearFXTilemap(void) { // 0x80A29C @@ -1763,14 +1735,14 @@ void ClearFXTilemap(void) { // 0x80A29C WriteRegWord(A1B1, 0x80); WriteRegWord(DAS1L, 0x780); WriteReg(VMAIN, 0); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, 0x5880); WriteRegWord(DMAP1, 0x1908); WriteRegWord(A1T1L, 0xA2F8); WriteRegWord(A1B1, 0x80); WriteRegWord(DAS1L, 0x780); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } uint8 CalculateLayer2Xpos(void) { // 0x80A2F9 @@ -1780,9 +1752,9 @@ uint8 CalculateLayer2Xpos(void) { // 0x80A2F9 } if (layer2_scroll_x != 1) { int t = layer2_scroll_x & 0xFE; - HIBYTE(temp933) = 0; - LOBYTE(temp933) = t * LOBYTE(layer1_x_pos) >> 8; - layer2_x_pos = t * HIBYTE(layer1_x_pos) + temp933; + HIBYTE(var933) = 0; + LOBYTE(var933) = t * LOBYTE(layer1_x_pos) >> 8; + layer2_x_pos = t * HIBYTE(layer1_x_pos) + var933; return 0; } return 1; @@ -1795,9 +1767,9 @@ uint8 CalculateLayer2Ypos(void) { // 0x80A33A } if (layer2_scroll_y != 1) { int t = layer2_scroll_y & 0xFE; - HIBYTE(temp933) = 0; - LOBYTE(temp933) = t * (uint8)layer1_y_pos >> 8; - layer2_y_pos = t * HIBYTE(layer1_y_pos) + temp933; + HIBYTE(var933) = 0; + LOBYTE(var933) = t * (uint8)layer1_y_pos >> 8; + layer2_y_pos = t * HIBYTE(layer1_y_pos) + var933; return 0; } return 1; @@ -1888,21 +1860,21 @@ void CalculateBgScrollAndLayerPositionBlocks(void) { // 0x80A4BB bg2_x_block = reg_BG2HOFS >> 4; uint16 v0 = layer1_x_pos >> 4; if (((layer1_x_pos >> 4) & 0x800) != 0) - v0 |= 0xF000u; + v0 |= 0xF000; layer1_x_block = v0; uint16 v1 = layer2_x_pos >> 4; if (((layer2_x_pos >> 4) & 0x800) != 0) - v1 |= 0xF000u; + v1 |= 0xF000; layer2_x_block = v1; bg1_y_block = reg_BG1VOFS >> 4; bg2_y_block = reg_BG2VOFS >> 4; uint16 v2 = layer1_y_pos >> 4; if (((layer1_y_pos >> 4) & 0x800) != 0) - v2 |= 0xF000u; + v2 |= 0xF000; layer1_y_block = v2; uint16 v3 = layer2_y_pos >> 4; if (((layer2_y_pos >> 4) & 0x800) != 0) - v3 |= 0xF000u; + v3 |= 0xF000; layer2_y_block = v3; } @@ -1913,8 +1885,8 @@ void HandleAutoscrolling_X(void) { // 0x80A528 uint16 v4; if (!time_is_frozen_flag) { - loopcounter = layer1_x_pos; - if ((layer1_x_pos & 0x8000u) != 0) + var939 = layer1_x_pos; + if ((layer1_x_pos & 0x8000) != 0) layer1_x_pos = 0; uint16 v0 = swap16(room_width_in_scrolls - 1); if (v0 < layer1_x_pos) @@ -1924,32 +1896,32 @@ void HandleAutoscrolling_X(void) { // 0x80A528 if (scrolls[v2]) { if (scrolls[(uint16)(v2 + 1)]) return; - temp933 = layer1_x_pos & 0xFF00; - uint16 v5 = (__PAIR32__(loopcounter - absolute_moved_last_frame_x, loopcounter) - (absolute_moved_last_frame_x | 0x20000)) >> 16; + var933 = layer1_x_pos & 0xFF00; + uint16 v5 = (__PAIR32__(var939 - absolute_moved_last_frame_x, var939) - (absolute_moved_last_frame_x | 0x20000)) >> 16; if ((int16)(v5 - (layer1_x_pos & 0xFF00)) < 0) { - v4 = temp933; + v4 = var933; } else { - loopcounter = v5; - v6 = HIBYTE(loopcounter); + var939 = v5; + v6 = HIBYTE(var939); if (scrolls[(uint16)(Mult8x8((uint16)(layer1_y_pos + 128) >> 8, room_width_in_scrolls) + v6)]) - v4 = loopcounter; + v4 = var939; else - v4 = (loopcounter & 0xFF00) + 256; + v4 = (var939 & 0xFF00) + 256; } } else { - temp933 = (layer1_x_pos & 0xFF00) + 256; + var933 = (layer1_x_pos & 0xFF00) + 256; if ((uint16)(absolute_moved_last_frame_x - + loopcounter - + 2) >= temp933) { - v4 = temp933; + + var939 + + 2) >= var933) { + v4 = var933; } else { - loopcounter += absolute_moved_last_frame_x + 2; - v3 = (uint8)(HIBYTE(loopcounter) + 1); + var939 += absolute_moved_last_frame_x + 2; + v3 = (uint8)(HIBYTE(var939) + 1); if (scrolls[(uint16)(Mult8x8((uint16)(layer1_y_pos + 128) >> 8, room_width_in_scrolls) + v3)]) - v4 = loopcounter; + v4 = var939; else - v4 = loopcounter & 0xFF00; + v4 = var939 & 0xFF00; } } layer1_x_pos = v4; @@ -1959,7 +1931,7 @@ void HandleAutoscrolling_X(void) { // 0x80A528 void HandleScrollingWhenTriggeringScrollRight(void) { // 0x80A641 int16 v1; - loopcounter = layer1_x_pos; + var939 = layer1_x_pos; if ((int16)(ideal_layer1_xpos - layer1_x_pos) < 0) { layer1_x_pos = ideal_layer1_xpos; layer1_x_subpos = 0; @@ -1969,10 +1941,10 @@ void HandleScrollingWhenTriggeringScrollRight(void) { // 0x80A641 v1 = HIBYTE(layer1_x_pos); uint16 RegWord = Mult8x8((uint16)(layer1_y_pos + 128) >> 8, room_width_in_scrolls); if (!scrolls[(uint16)(RegWord + 1 + v1)]) { - temp933 = layer1_x_pos & 0xFF00; - uint16 v4 = (__PAIR32__(loopcounter - absolute_moved_last_frame_x, loopcounter) - (absolute_moved_last_frame_x | 0x20000)) >> 16; + var933 = layer1_x_pos & 0xFF00; + uint16 v4 = (__PAIR32__(var939 - absolute_moved_last_frame_x, var939) - (absolute_moved_last_frame_x | 0x20000)) >> 16; if ((int16)(v4 - (layer1_x_pos & 0xFF00)) < 0) - v4 = temp933; + v4 = var933; layer1_x_pos = v4; } } else { @@ -1983,19 +1955,19 @@ void HandleScrollingWhenTriggeringScrollRight(void) { // 0x80A641 void HandleScrollingWhenTriggeringScrollLeft(void) { // 0x80A6BB int16 v0; - loopcounter = layer1_x_pos; + var939 = layer1_x_pos; if ((int16)(layer1_x_pos - ideal_layer1_xpos) < 0) { layer1_x_pos = ideal_layer1_xpos; layer1_x_subpos = 0; } - if ((layer1_x_pos & 0x8000u) == 0) { + if ((layer1_x_pos & 0x8000) == 0) { v0 = HIBYTE(layer1_x_pos); uint16 prod = Mult8x8((uint16)(layer1_y_pos + 128) >> 8, room_width_in_scrolls); if (!scrolls[(uint16)(prod + v0)]) { - temp933 = (layer1_x_pos & 0xFF00) + 256; - uint16 v1 = absolute_moved_last_frame_x + loopcounter + 2; - if (v1 >= temp933) - v1 = temp933; + var933 = (layer1_x_pos & 0xFF00) + 256; + uint16 v1 = absolute_moved_last_frame_x + var939 + 2; + if (v1 >= var933) + v1 = var933; layer1_x_pos = v1; } } else { @@ -2014,51 +1986,51 @@ void HandleAutoscrolling_Y(void) { // 0x80A731 if (!time_is_frozen_flag) { uint16 v0 = 0; v1 = (uint16)(layer1_x_pos + 128) >> 8; - R20_ = Mult8x8(HIBYTE(layer1_y_pos), room_width_in_scrolls) + v1; - if (scrolls[R20_] != 1) + uint16 r20 = Mult8x8(HIBYTE(layer1_y_pos), room_width_in_scrolls) + v1; + if (scrolls[r20] != 1) v0 = 31; - temp933 = v0; - loopcounter = layer1_y_pos; - if ((layer1_y_pos & 0x8000u) != 0) + var933 = v0; + var939 = layer1_y_pos; + if ((layer1_y_pos & 0x8000) != 0) layer1_y_pos = 0; LOBYTE(v2) = (uint16)(room_height_in_scrolls - 1) >> 8; HIBYTE(v2) = room_height_in_scrolls - 1; - uint16 v3 = temp933 + v2; + uint16 v3 = var933 + v2; if (v3 < layer1_y_pos) layer1_y_pos = v3; v4 = (uint16)(layer1_x_pos + 128) >> 8; uint16 v5 = Mult8x8(HIBYTE(layer1_y_pos), room_width_in_scrolls) + v4; if (!scrolls[v5]) { - x_block_of_vram_blocks_to_update = (layer1_y_pos & 0xFF00) + 256; - uint16 v6 = absolute_moved_last_frame_y + loopcounter + 2; - if (v6 >= x_block_of_vram_blocks_to_update) { - v8 = x_block_of_vram_blocks_to_update; + var935 = (layer1_y_pos & 0xFF00) + 256; + uint16 v6 = absolute_moved_last_frame_y + var939 + 2; + if (v6 >= var935) { + v8 = var935; } else { - loopcounter += absolute_moved_last_frame_y + 2; + var939 += absolute_moved_last_frame_y + 2; v7 = (uint16)(layer1_x_pos + 128) >> 8; uint16 prod = Mult8x8(HIBYTE(v6) + 1, room_width_in_scrolls); if (scrolls[(uint16)(prod + v7)]) - v8 = loopcounter; + v8 = var939; else - v8 = loopcounter & 0xFF00; + v8 = var939 & 0xFF00; } layer1_y_pos = v8; return; } if (!scrolls[(uint16)(room_width_in_scrolls + v5)]) { - tmp_vram_base_addr = temp933 + (layer1_y_pos & 0xFF00); - if (tmp_vram_base_addr < layer1_y_pos) { - uint16 v9 = (__PAIR32__(loopcounter - absolute_moved_last_frame_y, loopcounter) - (absolute_moved_last_frame_y | 0x20000)) >> 16; - if ((int16)(v9 - tmp_vram_base_addr) < 0) { - v8 = tmp_vram_base_addr; + var937 = var933 + (layer1_y_pos & 0xFF00); + if (var937 < layer1_y_pos) { + uint16 v9 = (__PAIR32__(var939 - absolute_moved_last_frame_y, var939) - (absolute_moved_last_frame_y | 0x20000)) >> 16; + if ((int16)(v9 - var937) < 0) { + v8 = var937; } else { - loopcounter = v9; + var939 = v9; uint16 prod = Mult8x8(HIBYTE(v9), room_width_in_scrolls); v10 = (uint16)(layer1_x_pos + 128) >> 8; if (scrolls[(uint16)(prod + v10)]) - v8 = loopcounter; + v8 = var939; else - v8 = (loopcounter & 0xFF00) + 256; + v8 = (var939 & 0xFF00) + 256; } layer1_y_pos = v8; return; @@ -2068,26 +2040,26 @@ void HandleAutoscrolling_Y(void) { // 0x80A731 } void HandleScrollingWhenTriggeringScrollDown(void) { // 0x80A893 - loopcounter = layer1_y_pos; + var939 = layer1_y_pos; int v0 = 0; uint16 prod = Mult8x8(HIBYTE(layer1_y_pos), room_width_in_scrolls); uint16 v1 = (uint16)(layer1_x_pos + 128) >> 8; - R20_ = prod + v1; - if (scrolls[R20_] != 1) + uint16 r20 = prod + v1; + if (scrolls[r20] != 1) v0 = 31; - temp933 = v0; + var933 = v0; if ((int16)(ideal_layer1_ypos - layer1_y_pos) < 0) { layer1_y_pos = ideal_layer1_ypos; layer1_y_subpos = 0; } uint16 v2 = swap16(room_height_in_scrolls - 1); - tmp_vram_base_addr = temp933 + v2; - if ((uint16)(temp933 + v2) < layer1_y_pos - || !scrolls[(uint16)(room_width_in_scrolls + R20_)] - && (tmp_vram_base_addr = temp933 + (layer1_y_pos & 0xFF00), tmp_vram_base_addr < layer1_y_pos)) { - uint16 v3 = (__PAIR32__(loopcounter - absolute_moved_last_frame_y, loopcounter) - (absolute_moved_last_frame_y | 0x20000)) >> 16; - if ((int16)(v3 - tmp_vram_base_addr) < 0) - v3 = tmp_vram_base_addr; + var937 = var933 + v2; + if ((uint16)(var933 + v2) < layer1_y_pos + || !scrolls[(uint16)(room_width_in_scrolls + r20)] + && (var937 = var933 + (layer1_y_pos & 0xFF00), var937 < layer1_y_pos)) { + uint16 v3 = (__PAIR32__(var939 - absolute_moved_last_frame_y, var939) - (absolute_moved_last_frame_y | 0x20000)) >> 16; + if ((int16)(v3 - var937) < 0) + v3 = var937; layer1_y_pos = v3; } } @@ -2095,19 +2067,19 @@ void HandleScrollingWhenTriggeringScrollDown(void) { // 0x80A893 void HandleScrollingWhenTriggeringScrollUp(void) { // 0x80A936 int16 v0; - loopcounter = layer1_y_pos; + var939 = layer1_y_pos; if ((int16)(layer1_y_pos - ideal_layer1_ypos) < 0) { layer1_y_pos = ideal_layer1_ypos; layer1_y_subpos = 0; } - if ((layer1_y_pos & 0x8000u) == 0) { + if ((layer1_y_pos & 0x8000) == 0) { uint16 prod = Mult8x8(HIBYTE(layer1_y_pos), room_width_in_scrolls); v0 = (uint16)(layer1_x_pos + 128) >> 8; if (!scrolls[(uint16)(prod + v0)]) { - temp933 = (layer1_y_pos & 0xFF00) + 256; - uint16 v1 = absolute_moved_last_frame_y + loopcounter + 2; - if (v1 >= temp933) - v1 = temp933; + var933 = (layer1_y_pos & 0xFF00) + 256; + uint16 v1 = absolute_moved_last_frame_y + var939 + 2; + if (v1 >= var933) + v1 = var933; layer1_y_pos = v1; } } else { @@ -2144,23 +2116,21 @@ void UpdateLevelOrBackgroundDataColumn(uint16 k) { // 0x80A9DE v2 += 0x9600; copywithflip_src.addr = v2; copywithflip_src.bank = 127; - uint16 v3 = (4 * (uint8)vram_blocks_to_update_y_block) & 0x3C; + uint16 v3 = (4 * vram_blocks_to_update_y_block) & 0x3C; *(uint16 *)((uint8 *)&bg1_update_col_wrapped_size + k) = v3; *(uint16 *)((uint8 *)&bg1_update_col_unwrapped_size + k) = (v3 ^ 0x3F) + 1; prod = Mult8x8(vram_blocks_to_update_y_block & 0xF, 0x40); - x_block_of_vram_blocks_to_update = vram_blocks_to_update_x_block & 0x1F; - uint16 v4 = 2 * x_block_of_vram_blocks_to_update; - temp933 = prod + v4; + var935 = vram_blocks_to_update_x_block & 0x1F; + uint16 v4 = 2 * var935; + var933 = prod + v4; uint16 v5 = addr_unk_605000; - if (x_block_of_vram_blocks_to_update >= 0x10u) + if (var935 >= 0x10) v5 = addr_unk_6053E0; if (k) v5 -= size_of_bg2; - tmp_vram_base_addr = v5; - *(uint16 *)((uint8 *)&bg1_update_col_unwrapped_dst + k) = temp933 + v5; - *(uint16 *)((uint8 *)&bg1_update_col_wrapped_dst + k) = x_block_of_vram_blocks_to_update - + x_block_of_vram_blocks_to_update - + tmp_vram_base_addr; + var937 = v5; + *(uint16 *)((uint8 *)&bg1_update_col_unwrapped_dst + k) = var933 + v5; + *(uint16 *)((uint8 *)&bg1_update_col_wrapped_dst + k) = var935 + var935 + var937; uint16 v6 = ADDR16_OF_RAM(*bg1_column_update_tilemap_left_halves); uint16 v7 = 0; if (k) { @@ -2170,25 +2140,25 @@ void UpdateLevelOrBackgroundDataColumn(uint16 k) { // 0x80A9DE uint16 v8 = *(uint16 *)((uint8 *)&bg1_update_col_unwrapped_size + k) + v6; *(uint16 *)((uint8 *)&bg1_update_col_wrapped_left_src + k) = v8; *(uint16 *)((uint8 *)&bg1_update_col_wrapped_right_src + k) = v8 + 64; - tmp_vram_base_addr = v7; + var937 = v7; uint16 t2 = k; uint16 v9 = 0; - loopcounter = 16; + var939 = 16; do { - tmp_block_to_update = IndirReadWord(copywithflip_src, v9); - uint16 v10 = tmp_block_to_update & 0x3FF; + var93B = IndirReadWord(copywithflip_src, v9); + uint16 v10 = var93B & 0x3FF; uint16 v17 = v9; - uint16 v11 = tmp_vram_base_addr; - uint16 v12 = tmp_block_to_update & 0xC00; - if ((tmp_block_to_update & 0xC00) != 0) { + uint16 v11 = var937; + uint16 v12 = var93B & 0xC00; + if ((var93B & 0xC00) != 0) { if (v12 == 1024) { - uint16 v14 = tmp_vram_base_addr >> 1; + uint16 v14 = var937 >> 1; bg1_column_update_tilemap_left_halves[v14] = tile_table.tables[v10].top_right ^ 0x4000; bg1_column_update_tilemap_right_halves[v14] = tile_table.tables[v10].top_left ^ 0x4000; bg1_column_update_tilemap_left_halves[v14 + 1] = tile_table.tables[v10].bottom_right ^ 0x4000; bg1_column_update_tilemap_right_halves[v14 + 1] = tile_table.tables[v10].bottom_left ^ 0x4000; } else { - uint16 v15 = tmp_vram_base_addr >> 1; + uint16 v15 = var937 >> 1; uint16 v16; if (v12 == 2048) { bg1_column_update_tilemap_left_halves[v15] = tile_table.tables[v10].bottom_left ^ 0x8000; @@ -2204,16 +2174,16 @@ void UpdateLevelOrBackgroundDataColumn(uint16 k) { // 0x80A9DE bg1_column_update_tilemap_right_halves[v15 + 1] = v16; } } else { - uint16 v13 = tmp_vram_base_addr >> 1; + uint16 v13 = var937 >> 1; bg1_column_update_tilemap_left_halves[v13] = tile_table.tables[v10].top_left; bg1_column_update_tilemap_right_halves[v13] = tile_table.tables[v10].top_right; bg1_column_update_tilemap_left_halves[v13 + 1] = tile_table.tables[v10].bottom_left; bg1_column_update_tilemap_right_halves[v13 + 1] = tile_table.tables[v10].bottom_right; } - tmp_vram_base_addr = v11 + 4; + var937 = v11 + 4; v9 = room_width_in_blocks * 2 + v17; - --loopcounter; - } while (loopcounter); + --var939; + } while (var939); ++ *(uint16 *)((uint8 *)&bg1_update_col_enable + t2); } } @@ -2235,25 +2205,25 @@ void UpdateLevelOrBackgroundDataRow(uint16 v0) { // 0x80AB78 v2 -= 27136; copywithflip_src.addr = v2; copywithflip_src.bank = 127; - temp933 = vram_blocks_to_update_x_block & 0xF; - *(uint16 *)((uint8 *)&bg1_update_row_unwrapped_size + v0) = 4 * (16 - temp933); - *(uint16 *)((uint8 *)&bg1_update_row_wrapped_size + v0) = 4 * (temp933 + 1); + var933 = vram_blocks_to_update_x_block & 0xF; + *(uint16 *)((uint8 *)&bg1_update_row_unwrapped_size + v0) = 4 * (16 - var933); + *(uint16 *)((uint8 *)&bg1_update_row_wrapped_size + v0) = 4 * (var933 + 1); prod = Mult8x8(vram_blocks_to_update_y_block & 0xF, 0x40); - x_block_of_vram_blocks_to_update = vram_blocks_to_update_x_block & 0x1F; - uint16 v3 = 2 * x_block_of_vram_blocks_to_update; - temp933 = prod + v3; - tmp_vram_base_addr = addr_unk_605400; + var935 = vram_blocks_to_update_x_block & 0x1F; + uint16 v3 = 2 * var935; + var933 = prod + v3; + var937 = addr_unk_605400; uint16 v4 = addr_unk_605000; - if (x_block_of_vram_blocks_to_update >= 0x10u) { - tmp_vram_base_addr = addr_unk_605000; + if (var935 >= 0x10) { + var937 = addr_unk_605000; v4 = addr_unk_6053E0; } if (v0) v4 -= size_of_bg2; - *(uint16 *)((uint8 *)&bg1_update_row_unwrapped_dst + v0) = temp933 + v4; - uint16 v5 = tmp_vram_base_addr; + *(uint16 *)((uint8 *)&bg1_update_row_unwrapped_dst + v0) = var933 + v4; + uint16 v5 = var937; if (v0) - v5 = tmp_vram_base_addr - size_of_bg2; + v5 = var937 - size_of_bg2; *(uint16 *)((uint8 *)&bg1_update_row_wrapped_dst + v0) = prod + v5; uint16 v6 = ADDR16_OF_RAM(*bg1_column_update_tilemap_top_halves); uint16 v7 = 0; @@ -2264,25 +2234,25 @@ void UpdateLevelOrBackgroundDataRow(uint16 v0) { // 0x80AB78 uint16 v8 = *(uint16 *)((uint8 *)&bg1_update_row_unwrapped_size + v0) + v6; *(uint16 *)((uint8 *)&bg1_update_row_wrapped_top_src + v0) = v8; *(uint16 *)((uint8 *)&bg1_update_row_wrapped_bottom_src + v0) = v8 + 68; - tmp_vram_base_addr = v7; + var937 = v7; uint16 t2 = v0; uint16 v9 = 0; - loopcounter = 17; + var939 = 17; do { - tmp_block_to_update = IndirReadWord(copywithflip_src, v9); - uint16 v10 = tmp_block_to_update & 0x3FF; + var93B = IndirReadWord(copywithflip_src, v9); + uint16 v10 = var93B & 0x3FF; uint16 v17 = v9; - uint16 v11 = tmp_vram_base_addr; - uint16 v12 = tmp_block_to_update & 0xC00; - if ((tmp_block_to_update & 0xC00) != 0) { + uint16 v11 = var937; + uint16 v12 = var93B & 0xC00; + if ((var93B & 0xC00) != 0) { if (v12 == 1024) { - uint16 v14 = tmp_vram_base_addr >> 1; + uint16 v14 = var937 >> 1; bg1_column_update_tilemap_top_halves[v14] = tile_table.tables[v10].top_right ^ 0x4000; bg1_column_update_tilemap_top_halves[v14 + 1] = tile_table.tables[v10].top_left ^ 0x4000; bg1_column_update_tilemap_bottom_halves[v14] = tile_table.tables[v10].bottom_right ^ 0x4000; bg1_column_update_tilemap_bottom_halves[v14 + 1] = tile_table.tables[v10].bottom_left ^ 0x4000; } else { - uint16 v15 = tmp_vram_base_addr >> 1; + uint16 v15 = var937 >> 1; uint16 v16; if (v12 == 2048) { bg1_column_update_tilemap_top_halves[v15] = tile_table.tables[v10].bottom_left ^ 0x8000; @@ -2298,16 +2268,16 @@ void UpdateLevelOrBackgroundDataRow(uint16 v0) { // 0x80AB78 bg1_column_update_tilemap_bottom_halves[v15 + 1] = v16; } } else { - uint16 v13 = tmp_vram_base_addr >> 1; + uint16 v13 = var937 >> 1; bg1_column_update_tilemap_top_halves[v13] = tile_table.tables[v10].top_left; bg1_column_update_tilemap_top_halves[v13 + 1] = tile_table.tables[v10].top_right; bg1_column_update_tilemap_bottom_halves[v13] = tile_table.tables[v10].bottom_left; bg1_column_update_tilemap_bottom_halves[v13 + 1] = tile_table.tables[v10].bottom_right; } - tmp_vram_base_addr = v11 + 4; + var937 = v11 + 4; v9 = v17 + 2; - --loopcounter; - } while (loopcounter); + --var939; + } while (var939); ++ *(uint16 *)((uint8 *)&bg1_update_row_enable + t2); } } @@ -2415,7 +2385,7 @@ void Irq_FollowDoorTransition(void) { if (kDoorTransitionFuncs[door_direction & 3]()) { layer1_x_pos = door_destination_x_pos; layer1_y_pos = door_destination_y_pos; - door_transition_flag |= 0x8000u; + door_transition_flag |= 0x8000; } } @@ -2454,7 +2424,7 @@ uint8 DoorTransition_Left(void) { // 0x80AEC2 uint8 DoorTransition_Down(void) { // 0x80AF02 uint16 v6 = door_transition_frame_counter; if (door_transition_frame_counter) { - if (door_transition_frame_counter < 0x39u) { + if (door_transition_frame_counter < 0x39) { uint16 v0 = (__PAIR32__(samus_door_transition_speed, samus_door_transition_subspeed) + __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16; samus_y_subpos += samus_door_transition_subspeed; @@ -2482,7 +2452,7 @@ uint8 DoorTransition_Down(void) { // 0x80AF02 reg_BG1VOFS = v5; } door_transition_frame_counter = v6 + 1; - if ((uint16)(v6 + 1) < 0x39u) + if ((uint16)(v6 + 1) < 0x39) return 0; UpdateScrollVarsUpdateMap(); return 1; @@ -2498,7 +2468,7 @@ uint8 DoorTransition_Up(void) { // 0x80AF89 samus_prev_y_pos = v0; layer1_y_pos -= 4; layer2_y_pos -= 4; - if (door_transition_frame_counter >= 5u) { + if (door_transition_frame_counter >= 5) { UpdateScrollVarsUpdateMap(); } else { reg_BG1HOFS = bg1_x_offset + layer1_x_pos; @@ -2542,7 +2512,7 @@ void ConfigureMode7RotationMatrix(void) { // 0x80B0C2 static uint32 decompress_src; static uint8 DecompNextByte() { - uint8 b = *RomPtrWithBank(decompress_src >> 16, decompress_src); + uint8 b = *RomPtr(decompress_src); if ((decompress_src++ & 0xffff) == 0xffff) decompress_src += 0x8000; return b; @@ -2688,7 +2658,6 @@ void DecompressToVRAM(uint32 src, uint16 dst_addr) { // 0x80B271 void LoadFromLoadStation(void) { // 0x80C437 save_station_lockout_flag = 1; - R18_ = 2 * load_station_index; const uint16 *v0 = (const uint16 *)RomPtr_80(kLoadStationLists[area_index] + 14 * load_station_index); room_ptr = *v0; door_def_ptr = v0[1]; @@ -2709,7 +2678,7 @@ void LoadFromLoadStation(void) { // 0x80C437 void SetElevatorsAsUsed(void) { // 0x80CD07 - const uint8 *v0 = RomPtr_80(off_80CD46[area_index] + 4 * (((uint8)elevator_door_properties_orientation & 0xF) - 1)); + const uint8 *v0 = RomPtr_80(off_80CD46[area_index] + 4 * ((elevator_door_properties_orientation & 0xF) - 1)); used_save_stations_and_elevators[v0[0]] |= v0[1]; used_save_stations_and_elevators[v0[2]] |= v0[3]; -} \ No newline at end of file +} diff --git a/src/sm_81.c b/src/sm_81.c index 1d1ee29..061e534 100644 --- a/src/sm_81.c +++ b/src/sm_81.c @@ -41,8 +41,8 @@ void SaveToSram(uint16 a) { // 0x818000 uint16 v7; uint16 v11; - uint16 R20 = 0; - uint16 R18 = 2 * (a & 3); + uint16 r20 = 0; + uint16 r18 = 2 * (a & 3); for (int i = 94; i >= 0; i -= 2) player_data_saved[i >> 1] = *(uint16 *)((uint8 *)&equipped_items + i); uint16 v3 = area_index * 256; @@ -55,18 +55,18 @@ void SaveToSram(uint16 a) { // 0x818000 PackMapToSave(); sram_save_station_index = load_station_index; sram_area_index = area_index; - uint16 v5 = kOffsetToSaveSlot[R18 >> 1]; + uint16 v5 = kOffsetToSaveSlot[r18 >> 1]; uint16 *v6 = player_data_saved; do { v7 = *v6++; *(uint16 *)(&g_sram[2 * (v5 >> 1)]) = v7; - R20 += v7; + r20 += v7; v5 += 2; } while (v6 != plm_instruction_timer); - uint16 v8 = R18; - uint16 v9 = R20; - int v10 = R18 >> 1; - *(uint16 *)(&g_sram[2 * v10]) = R20; + uint16 v8 = r18; + uint16 v9 = r20; + int v10 = r18 >> 1; + *(uint16 *)(&g_sram[2 * v10]) = r20; *(uint16 *)(&g_sram[2 * v10 + 0x1FF0]) = v9; v11 = ~v9; *(uint16 *)(&g_sram[2 * v10 + 8]) = v11; @@ -76,19 +76,19 @@ void SaveToSram(uint16 a) { // 0x818000 } uint8 LoadFromSram(uint16 a) { // 0x818085 - R20_ = 0; - R18_ = 2 * (a & 3); + uint16 r20 = 0; + uint16 r18 = 2 * (a & 3); uint16 v1 = kOffsetToSaveSlot[a & 3]; uint16 *v2 = player_data_saved; do { uint16 v3 = kSramChecksum[v1 >> 1]; *v2++ = v3; - R20_ += v3; + r20 += v3; v1 += 2; } while (v2 != plm_instruction_timer); - int v4 = R18_ >> 1; - if (R20_ == kSramChecksum[v4] && (R20_ ^ 0xffff) == kSramChecksumInverted[v4] - || R20_ == kSramChecksumUpper[v4] && (R20_ ^ 0xffff) == kSramChecksumInvertedUpper[v4]) { + int v4 = r18 >> 1; + if (r20 == kSramChecksum[v4] && (r20 ^ 0xffff) == kSramChecksumInverted[v4] + || r20 == kSramChecksumUpper[v4] && (r20 ^ 0xffff) == kSramChecksumInvertedUpper[v4]) { for (int i = 94; i >= 0; i -= 2) *(uint16 *)((uint8 *)&equipped_items + i) = player_data_saved[i >> 1]; UnpackMapFromSave(); @@ -96,14 +96,14 @@ uint8 LoadFromSram(uint16 a) { // 0x818085 area_index = sram_area_index; return 0; } else { - R20_ = 0; - uint16 v7 = kOffsetToSaveSlot[R18_ >> 1]; + r20 = 0; + uint16 v7 = kOffsetToSaveSlot[r18 >> 1]; uint16 v8 = ADDR16_OF_RAM(*player_data_saved); uint16 v9 = 0; do { kSramChecksum[v7 >> 1] = v9; - v9 += R20_; - R20_ = v9; + v9 += r20; + r20 = v9; v7 += 2; v8 += 2; } while (v8 != ADDR16_OF_RAM(*plm_instruction_timer)); // 0xDE1C @@ -116,63 +116,55 @@ uint8 LoadFromSram(uint16 a) { // 0x818085 void UnpackMapFromSave(void) { // 0x8182E4 for (int i = 1792; i >= 0; i -= 2) explored_map_tiles_saved[i >> 1] = 0; - R22_ = 0; - do { - R20_ = swap16(R22_); - R18_ = kPackedBytesPerArea_Count[R22_]; - int v2 = (uint16)(2 * R22_) >> 1; - R0_.addr = kPackedBytesPerArea_UnpackedOffs[v2]; - *(uint16 *)&R0_.bank = 129; - int v3 = kPackedBytesPerArea_PackedOffs[v2]; - R3_.addr = ADDR16_OF_RAM(*explored_map_tiles_saved); - *(uint16 *)&R3_.bank = 126; + for(int i = 0; i < 6; i++) { + uint16 r20 = swap16(i); + int n = kPackedBytesPerArea_Count[i]; + uint16 r0 = kPackedBytesPerArea_UnpackedOffs[i]; + int v3 = kPackedBytesPerArea_PackedOffs[i]; + LongPtr r3 = { ADDR16_OF_RAM(*explored_map_tiles_saved), 126}; do { - uint16 v4 = R20_ + *RomPtr_81(R0_.addr); - IndirWriteByte(R3_, v4, compressed_map_data[v3]); - ++R0_.addr; + uint16 v4 = r20 + *RomPtr_81(r0); + IndirWriteByte(r3, v4, compressed_map_data[v3]); + ++r0; ++v3; - --R18_; - } while (R18_); - ++R22_; - } while (sign16(R22_ - 6)); + } while (--n); + } } void PackMapToSave(void) { // 0x81834B - R26_ = 0; + uint16 r26 = 0; do { - R22_ = kPackedBytesPerArea_Count[R26_]; - int v0 = R26_; - R0_.addr = kPackedBytesPerArea_UnpackedOffs[v0]; + int n = kPackedBytesPerArea_Count[r26]; + int v0 = r26; + uint16 r0 = kPackedBytesPerArea_UnpackedOffs[v0]; int v1 = kPackedBytesPerArea_PackedOffs[v0]; - R24_ = swap16(R26_); - R3_.addr = ADDR16_OF_RAM(*explored_map_tiles_saved); - *(uint16 *)&R3_.bank = 126; + uint16 r24 = swap16(r26); + LongPtr r3 = { ADDR16_OF_RAM(*explored_map_tiles_saved), 126 }; do { - int v3 = R24_ + *RomPtr_81(R0_.addr); - compressed_map_data[v1] = IndirReadByte(R3_, v3); - ++R0_.addr; + int v3 = r24 + *RomPtr_81(r0); + compressed_map_data[v1] = IndirReadByte(r3, v3); + ++r0; ++v1; - --R22_; - } while (R22_); - ++R26_; - } while (sign16(R26_ - 6)); + } while (--n); + ++r26; + } while (sign16(r26 - 6)); } -void DrawSpritemap(uint8 db, uint16 j) { // 0x81879F +void DrawSpritemap(uint8 db, uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r22) { // 0x81879F const uint8 *pp = RomPtrWithBank(db, j); int n = GET_WORD(pp); pp += 2; int idx = oam_next_ptr; for (; (n != 0) && (idx < 0x200); n--) { OamEnt *oam = gOamEnt(idx); - int x = R20_ + GET_WORD(pp); - int y = (uint8)R18_ + pp[2]; + int x = x_r20 + GET_WORD(pp); + int y = (uint8)y_r18 + pp[2]; // can this be simplified? if (!sign8(pp[2]) ? (y >= 0xe0) : (y & 0x100) ? ((uint8)y >= 0xe0) : ((uint8)y < 0xe0)) x = 0x180, y = 0xe0; oam->xcoord = x; oam->ycoord = y; - *(uint16 *)&oam->charnum = R22_ | GET_WORD(pp + 3) & 0xF1FF; + *(uint16 *)&oam->charnum = chr_r22 | GET_WORD(pp + 3) & 0xF1FF; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); idx += 4; pp += 5; @@ -180,21 +172,21 @@ void DrawSpritemap(uint8 db, uint16 j) { // 0x81879F oam_next_ptr = idx; } -void DrawSpritemapOffScreen(uint16 j) { // 0x818853 +void DrawSpritemapOffScreen(uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r22) { // 0x818853 const uint8 *pp = RomPtr_8C(j); int n = GET_WORD(pp); pp += 2; int idx = oam_next_ptr; for (; (n != 0) && (idx < 0x200); n--) { OamEnt *oam = gOamEnt(idx); - int x = R20_ + GET_WORD(pp); - int y = (uint8)R18_ + pp[2]; + int x = x_r20 + GET_WORD(pp); + int y = (uint8)y_r18 + pp[2]; // can this be simplified? if (!sign8(pp[2]) ? (y < 0xe0) : (y & 0x100) ? ((uint8)y < 0xe0) : ((uint8)y >= 0xe0)) x = 0x180, y = 0xe0; oam->xcoord = x; oam->ycoord = y; - *(uint16 *)&oam->charnum = R22_ | *(uint16 *)(pp + 3) & 0xF1FF; + *(uint16 *)&oam->charnum = chr_r22 | *(uint16 *)(pp + 3) & 0xF1FF; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); idx += 4; pp += 5; @@ -202,7 +194,7 @@ void DrawSpritemapOffScreen(uint16 j) { // 0x818853 oam_next_ptr = idx; } -void DrawMenuSpritemap(uint16 a, uint16 k, uint16 j) { // 0x81891F +void DrawMenuSpritemap(uint16 a, uint16 k, uint16 j, uint16 chr_r3) { // 0x81891F const uint8 *pp = RomPtr_82(g_off_82C569[a]); int n = GET_WORD(pp); pp += 2; @@ -213,7 +205,7 @@ void DrawMenuSpritemap(uint16 a, uint16 k, uint16 j) { // 0x81891F oam->xcoord = x; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); oam->ycoord = j + pp[2]; - *(uint16 *)&oam->charnum = R3_.addr | GET_WORD(pp + 3) & 0xF1FF; + *(uint16 *)&oam->charnum = chr_r3 | GET_WORD(pp + 3) & 0xF1FF; pp += 5; idx = (idx + 4) & 0x1FF; } @@ -228,8 +220,6 @@ void DrawSamusSpritemap(uint16 a, uint16 x_pos, uint16 y_pos) { // 0x8189AE int n = GET_WORD(pp); pp += 2; for(; n != 0; n--) { - int v10 = idx >> 1; - uint16 *dst = (uint16 *)RomPtr_RAM(kOamExtra_Address_And_X8Large[v10]); uint16 x = x_pos + GET_WORD(pp); OamEnt *v9 = gOamEnt(idx); v9->xcoord = x; @@ -242,24 +232,24 @@ void DrawSamusSpritemap(uint16 a, uint16 x_pos, uint16 y_pos) { // 0x8189AE oam_next_ptr = idx; } -void DrawBeamGrappleSpritemap(uint16 a) { // 0x818A37 - DrawGrappleOrProjectileSpritemap(RomPtr_93(g_off_93A1A1[a])); +void DrawBeamGrappleSpritemap(uint16 a, uint16 x_r20, uint16 y_r18) { // 0x818A37 + DrawGrappleOrProjectileSpritemap(RomPtr_93(g_off_93A1A1[a]), x_r20, y_r18); } -void DrawProjectileSpritemap(uint16 k) { // 0x818A4B - DrawGrappleOrProjectileSpritemap(RomPtr_93(projectile_spritemap_pointers[k >> 1])); +void DrawProjectileSpritemap(uint16 k, uint16 x_r20, uint16 y_r18) { // 0x818A4B + DrawGrappleOrProjectileSpritemap(RomPtr_93(projectile_spritemap_pointers[k >> 1]), x_r20, y_r18); } -void DrawGrappleOrProjectileSpritemap(const uint8 *pp) { // 0x818A5F +void DrawGrappleOrProjectileSpritemap(const uint8 *pp, uint16 x_r20, uint16 y_r18) { // 0x818A5F int idx = oam_next_ptr; int n = GET_WORD(pp); pp += 2; for (; n != 0; n--) { - uint16 x = R20_ + GET_WORD(pp); + uint16 x = x_r20 + GET_WORD(pp); OamEnt *v4 = gOamEnt(idx); v4->xcoord = x; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); - v4->ycoord = R18_ + pp[2]; + v4->ycoord = y_r18 + pp[2]; *(uint16 *)&v4->charnum = GET_WORD(pp + 3); pp += 5; idx = (idx + 4) & 0x1FF; @@ -267,7 +257,7 @@ void DrawGrappleOrProjectileSpritemap(const uint8 *pp) { // 0x818A5F oam_next_ptr = idx; } -void DrawSpritemapWithBaseTile(uint8 db, uint16 j) { // 0x818AB8 +void DrawSpritemapWithBaseTile(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y, uint16 r3, uint16 r0) { // 0x818AB8 if (j == 0) return; // bug fix uint8 *pp = (uint8 *)RomPtrWithBank(db, j); @@ -276,87 +266,87 @@ void DrawSpritemapWithBaseTile(uint8 db, uint16 j) { // 0x818AB8 pp += 2; for(; n != 0; n--) { OamEnt *oam = gOamEnt(idx); - uint16 x = R20_ + GET_WORD(pp + 0); + uint16 x = r20_x + GET_WORD(pp + 0); oam->xcoord = x; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); - oam->ycoord = R18_ + pp[2]; - *(uint16 *)&oam->charnum = R3_.addr | (R0_.addr + GET_WORD(pp + 3)); + oam->ycoord = r18_y + pp[2]; + *(uint16 *)&oam->charnum = r3 | (r0 + GET_WORD(pp + 3)); pp += 5; idx = (idx + 4) & 0x1FF; } oam_next_ptr = idx; } -void DrawSpritemapWithBaseTile2(uint8 db, uint16 j) { // 0x818B22 +void DrawSpritemapWithBaseTile2(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y, uint16 r3, uint16 r0) { // 0x818B22 const uint8 *pp = RomPtrWithBank(db, j); int idx = oam_next_ptr; int n = GET_WORD(pp); pp += 2; for (; n != 0; n--) { OamEnt *oam = gOamEnt(idx); - uint16 x = R20_ + GET_WORD(pp + 0); + uint16 x = r20_x + GET_WORD(pp); oam->xcoord = x; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); - int y = pp[2] + (uint8)R18_; + int y = pp[2] + (uint8)r18_y; oam->ycoord = (!(y & 0x100) == !sign8(pp[2])) ? y : 0xf0; - *(uint16 *)&oam->charnum = R3_.addr | (R0_.addr + GET_WORD(pp + 3)); + *(uint16 *)&oam->charnum = r3 | (r0 + GET_WORD(pp + 3)); pp += 5; idx = (idx + 4) & 0x1FF; } oam_next_ptr = idx; } -void DrawSpritemapWithBaseTileOffscreen(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y) { // 0x818B96 +void DrawSpritemapWithBaseTileOffscreen(uint8 db, uint16 j, uint16 r20_x, uint16 r18_y, uint16 r3, uint16 r0) { // 0x818B96 const uint8 *pp = RomPtrWithBank(db, j); int idx = oam_next_ptr; int n = GET_WORD(pp); pp += 2; for (; n != 0; n--) { OamEnt *oam = gOamEnt(idx); - int x = r20_x + GET_WORD(pp + 0); + int x = r20_x + GET_WORD(pp); oam->xcoord = x; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); int y = pp[2] + (uint8)r18_y; oam->ycoord = (!(y & 0x100) != !sign8(pp[2])) ? y : 0xf0; - *(uint16 *)&oam->charnum = R3_.addr | (R0_.addr + GET_WORD(pp + 3)); + *(uint16 *)&oam->charnum = r3 | (r0 + GET_WORD(pp + 3)); pp += 5; idx = (idx + 4) & 0x1FF; } oam_next_ptr = idx; } -void DrawEnemyProjectileSpritemapWithBaseTile(uint8 db, uint16 j) { // 0x818C0A +void DrawEnemyProjectileSpritemapWithBaseTile(uint8 db, uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r26, uint16 chr_r28) { // 0x818C0A const uint8 *pp = RomPtrWithBank(db, j); int idx = oam_next_ptr; int n = GET_WORD(pp); pp += 2; for (; n != 0; n--) { OamEnt *oam = gOamEnt(idx); - uint16 x = R20_ + GET_WORD(pp); + uint16 x = x_r20 + GET_WORD(pp); oam->xcoord = x; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); - int y = pp[2] + (uint8)R18_; + int y = pp[2] + (uint8)y_r18; oam->ycoord = (!(y & 0x100) == !sign8(pp[2])) ? y : 0xf0; - *(uint16 *)&oam->charnum = R28_ | (R26_ + GET_WORD(pp + 3)); + *(uint16 *)&oam->charnum = chr_r28 | (chr_r26 + GET_WORD(pp + 3)); idx = (idx + 4) & 0x1FF; pp += 5; } oam_next_ptr = idx; } -void DrawEnemyProjectileSpritemapWithBaseTileOffscreen(uint8 db, uint16 j) { // 0x818C7F +void DrawEnemyProjectileSpritemapWithBaseTileOffscreen(uint8 db, uint16 j, uint16 x_r20, uint16 y_r18, uint16 chr_r26, uint16 chr_r28) { // 0x818C7F const uint8 *pp = RomPtrWithBank(db, j); int idx = oam_next_ptr; int n = GET_WORD(pp); pp += 2; for (; n != 0; n--) { OamEnt *oam = gOamEnt(idx); - uint16 x = R20_ + GET_WORD(pp); + uint16 x = x_r20 + GET_WORD(pp); oam->xcoord = x; oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)pp < 0) * 2) << (2 * ((idx >> 2) & 7)); - int y = pp[2] + (uint8)R18_; + int y = pp[2] + (uint8)y_r18; oam->ycoord = (!(y & 0x100) != !sign8(pp[2])) ? y : 0xf0; - *(uint16 *)&oam->charnum = R28_ | (R26_ + GET_WORD(pp + 3)); + *(uint16 *)&oam->charnum = chr_r28 | (chr_r26 + GET_WORD(pp + 3)); idx = (idx + 4) & 0x1FF; pp += 5; } @@ -367,7 +357,7 @@ void GameOverMenu_0_FadeOutConfigGfx(void) { // 0x818D0F HandleFadeOut(); if ((reg_INIDISP & 0xF) == 0) { ScreenOff(); - QueueSfx3_Max6(1u); + QueueSfx3_Max6(1); DisableHdmaObjects(); WaitUntilEndOfVblankAndClearHdma(); uint16 v0 = 0; @@ -416,25 +406,25 @@ void LoadInitialMenuTiles(void) { // 0x818DDB WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_818DF1 = { 1, 1, 0x18, LONGPTR(0x8e8000), 0x5600 }; SetupDmaTransfer(&unk_818DF1); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x30); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_818E11 = { 1, 1, 0x18, LONGPTR(0xb68000), 0x2000 }; SetupDmaTransfer(&unk_818E11); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_818E31 = { 1, 1, 0x18, LONGPTR(0xb6c000), 0x2000 }; SetupDmaTransfer(&unk_818E31); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x40); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_818E51 = { 1, 1, 0x18, LONGPTR(0x8ed600), 0x0600 }; SetupDmaTransfer(&unk_818E51); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } void LoadMenuPalettes(void) { // 0x818E60 @@ -447,33 +437,6 @@ void LoadMenuPalettes(void) { // 0x818E60 } while ((int16)(v0 - 512) < 0); } -void LoadDebugGameOverMenuTilemaps(void) { // 0x818E7F - int v0 = 0; - do - ram3800.cinematic_bg_tilemap[v0++] = 15; - while ((int16)(v0 * 2 - 2048) < 0); - uint16 v1 = vram_write_queue_tail; - VramWriteEntry *v2 = gVramWriteEntry(vram_write_queue_tail); - v2->size = 2048; - v2->src.addr = 14336; - *(uint16 *)&v2->src.bank = 126; - v2->vram_dst = (reg_BG1SC & 0xFC) << 8; - vram_write_queue_tail = v1 + 7; - uint16 v3 = v1 + 7; - for (int i = 0; ; i += 8) { - uint16 v5 = IndirReadWord(R0_, i); - if (v5 == 0xFFFF) - break; - VramWriteEntry *v6 = gVramWriteEntry(v3); - v6->size = v5; - v6->src.addr = IndirReadWord(R0_, i + 2); - *(uint16 *)&v6->src.bank = IndirReadWord(R0_, i + 4); - v6->vram_dst = IndirReadWord(R0_, i + 6); - v3 += 7; - } - vram_write_queue_tail = v3; -} - void GameOverMenu_3_Main(void) { // 0x819003 int16 v0; int16 v1; @@ -481,7 +444,7 @@ void GameOverMenu_3_Main(void) { // 0x819003 if ((joypad1_newkeys & kButton_Select) != 0 || (joypad1_newkeys & kButton_Up) != 0 || (joypad1_newkeys & kButton_Down) != 0) { - file_select_map_area_index ^= 1u; + file_select_map_area_index ^= 1; } else if ((joypad1_newkeys & (uint16)(kButton_B | kButton_Start | kButton_A)) != 0) { if (file_select_map_area_index) { ++menu_index; @@ -520,7 +483,7 @@ void GameOverMenu_5_Continue(void) { // 0x81907E WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_819093 = { 1, 1, 0x18, LONGPTR(0x9ab200), 0x2000 }; SetupDmaTransfer(&unk_819093); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); game_state = 16; file_select_map_area_index = 0; RestorePalettesAndIoAfterDebugGameover(); @@ -576,8 +539,8 @@ void GameOverMenu_4_Main(void) { // 0x81912B if ((joypad1_newkeys & kButton_Select) != 0 || (joypad1_newkeys & kButton_Up) != 0 || (joypad1_newkeys & kButton_Down) != 0) { - QueueSfx1_Max6(0x37u); - file_select_map_area_index ^= 1u; + QueueSfx1_Max6(0x37); + file_select_map_area_index ^= 1; } else if ((joypad1_newkeys & kButton_A) != 0) { enemy_data[0].instruction_timer = 180; if (file_select_map_area_index) { @@ -604,7 +567,7 @@ void GameOverMenu_1_Init(void) { // 0x8191A4 reg_COLDATA[1] = 64; reg_COLDATA[2] = 0x80; QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF03u); + QueueMusic_Delayed8(0xFF03); enemy_projectile_enable_flag = 1; enemy_projectile_id[0] = 0; int v0 = 0; @@ -648,7 +611,7 @@ void GameOverMenu_1_Init(void) { // 0x8191A4 void GameOverMenu_2_PlayMusic(void) { // 0x8193E8 if (!(HasQueuedMusic())) { ++menu_index; - QueueMusic_Delayed8(4u); + QueueMusic_Delayed8(4); } } @@ -698,7 +661,7 @@ void FileSelectMenu_0_FadeOutConfigGfx(void) { // 0x81944E if ((reg_INIDISP & 0xF) != 0) return; ScreenOff(); - QueueSfx3_Max6(1u); + QueueSfx3_Max6(1); DisableHdmaObjects(); WaitUntilEndOfVblankAndClearHdma(); ++menu_index; @@ -755,8 +718,7 @@ void FileSelectMenu_5_FadeOutFromMain(void) { // 0x8194EE void FileSelectMenu_15_FadeOutToMain(void) { // 0x8194F4 HandleFadeOut(); - R18_ = *(uint16 *)®_MOSAIC & 0xFF0F; - *(uint16 *)®_MOSAIC = *(uint16 *)®_MOSAIC & 0xFF0F | (16 * (reg_INIDISP & 0xF)) ^ 0xF0; + reg_MOSAIC = reg_MOSAIC & 0x0F | (16 * (reg_INIDISP & 0xF)) ^ 0xF0; if ((reg_INIDISP & 0xF) == 0) { ScreenOff(); ++menu_index; @@ -782,8 +744,7 @@ void FileSelectMenu_17_FadeInToMain(void) { void FileSelectMenu_7_FadeInFromMain(void) { // 0x819532 DrawMenuSelectionMissile(); HandleFadeIn(); - R18_ = *(uint16 *)®_MOSAIC & 0xFF0F; - *(uint16 *)®_MOSAIC = *(uint16 *)®_MOSAIC & 0xFF0F | (16 * (reg_INIDISP & 0xF)) ^ 0xF0; + reg_MOSAIC = reg_MOSAIC & 0x0F | (16 * (reg_INIDISP & 0xF)) ^ 0xF0; if ((reg_INIDISP & 0xF) == 15) ++menu_index; } @@ -858,15 +819,15 @@ void DrawFileCopySaveSlotAInfo(void) { // 0x81960F } void DrawFileCopySaveSlotBInfo(void) { // 0x81963F - DrawFileSelectionHealth(~(uint8)nonempty_save_slots & 2, 0x318); - DrawFileSelectionTime(~(uint8)nonempty_save_slots & 2, 0x372); + DrawFileSelectionHealth(~nonempty_save_slots & 2, 0x318); + DrawFileSelectionTime(~nonempty_save_slots & 2, 0x372); LoadMenuTilemap(0x334, addr_kMenuTilemap_TIME); LoadMenuTilemap(0x308, addr_kMenuTilemap_SamusB); } void DrawFileCopySaveSlotCInfo(void) { // 0x81966F - DrawFileSelectionHealth(~(uint8)nonempty_save_slots & 4, 0x418); - DrawFileSelectionTime(~(uint8)nonempty_save_slots & 4, 0x472); + DrawFileSelectionHealth(~nonempty_save_slots & 4, 0x418); + DrawFileSelectionTime(~nonempty_save_slots & 4, 0x472); LoadMenuTilemap(0x434, addr_kMenuTilemap_TIME); LoadMenuTilemap(0x408, addr_kMenuTilemap_SamusC); } @@ -893,16 +854,16 @@ void FileSelectMenu_8(void) { DrawBorderAroundDataCopyMode(); DrawMenuSelectionMissile(); if ((joypad1_newkeys & (kButton_Start | kButton_A)) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); if (enemy_projectile_id[15] == 3) { menu_index += 7; } else { enemy_projectile_id[16] = enemy_projectile_id[15]; ++menu_index; } - } else if ((joypad1_newkeys & 0x8000u) != 0) { + } else if ((joypad1_newkeys & 0x8000) != 0) { menu_index += 7; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); } else { if ((joypad1_newkeys & kButton_Up) != 0) { v0 = enemy_projectile_id[15]; @@ -910,7 +871,7 @@ void FileSelectMenu_8(void) { if ((kBitShl[v0] & nonempty_save_slots) != 0) { LABEL_16: LOBYTE(enemy_projectile_id[15]) = v0; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); SetFileCopyMenuSelectionMissilePosition(); return; } @@ -982,7 +943,7 @@ void FileSelectMenu_10_FileCopySelectDest(void) { // 0x819813 DrawBorderAroundDataCopyMode(); DrawMenuSelectionMissile(); if ((joypad1_newkeys & (kButton_Start | kButton_A)) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); if (enemy_projectile_id[15] != 3) { enemy_projectile_id[17] = enemy_projectile_id[15]; ++menu_index; @@ -993,11 +954,11 @@ LABEL_9: } menu_index += 5; } else { - if ((joypad1_newkeys & 0x8000u) == 0) { + if ((joypad1_newkeys & 0x8000) == 0) { if ((joypad1_newkeys & kButton_Up) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); v0 = enemy_projectile_id[15]; - while ((--v0 & 0x8000u) == 0) { + while ((--v0 & 0x8000) == 0) { if (v0 != enemy_projectile_id[16]) { LABEL_8: enemy_projectile_id[15] = v0; @@ -1005,7 +966,7 @@ LABEL_8: } } } else if ((joypad1_newkeys & kButton_Down) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); v0 = enemy_projectile_id[15]; while (++v0 != 4) { if (v0 != enemy_projectile_id[16]) @@ -1016,7 +977,7 @@ LABEL_8: } menu_index -= 2; enemy_projectile_id[15] = enemy_projectile_id[16]; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); FileSelectMenu_Func1(); } } @@ -1076,17 +1037,17 @@ void FileSelectMenu_12_FileCopyConfirm(void) { // 0x819984 HandleFileCopyArrowPalette(); DrawFileCopyArrow(); if ((joypad1_newkeys & (kButton_Up | kButton_Down)) != 0) { - enemy_projectile_id[15] ^= 1u; - QueueSfx1_Max6(0x37u); + enemy_projectile_id[15] ^= 1; + QueueSfx1_Max6(0x37); } else { - if ((joypad1_newkeys & 0x8000u) != 0) { + if ((joypad1_newkeys & 0x8000) != 0) { menu_index -= 3; enemy_projectile_id[15] = enemy_projectile_id[17]; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); return; } if ((joypad1_newkeys & (kButton_Start | kButton_A)) != 0) { - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); if (enemy_projectile_id[15]) { menu_index -= 4; FileSelectMenu_Func1(); @@ -1125,8 +1086,6 @@ void FileSelectMenu_13_FileCopyDoIt(void) { // 0x819A2C DrawMenuSelectionMissile(); HandleFileCopyArrowPalette(); DrawFileCopyArrow(); - *(uint16 *)&R0_.bank = 112; - *(uint16 *)&R3_.bank = 112; uint16 src_addr = kOffsetToSaveSlot[enemy_projectile_id[16]]; uint16 dst_addr = kOffsetToSaveSlot[enemy_projectile_id[17]]; memcpy(&g_sram[dst_addr], &g_sram[src_addr], 1628); @@ -1163,7 +1122,7 @@ void FileSelectMenu_13_FileCopyDoIt(void) { // 0x819A2C void FileSelectMenu_14_CopyCompleted(void) { // 0x819AFA DrawBorderAroundDataCopyMode(); if (joypad1_newkeys) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); ++menu_index; int slot = sram_save_slot_selected; if (sign16(slot) || !sign16(sram_save_slot_selected - 3) || @@ -1205,23 +1164,23 @@ void FileSelectMenu_22_FileClearSelectSlot(void) { // 0x819B64 DrawMenuSelectionMissile(); HIBYTE(v0) = HIBYTE(joypad1_newkeys); if ((joypad1_newkeys & (kButton_Start | kButton_A)) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); if (enemy_projectile_id[15] != 3) { enemy_projectile_id[16] = enemy_projectile_id[15]; ++menu_index; return; } LABEL_11: - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); menu_index += 5; return; } - if ((joypad1_newkeys & 0x8000u) != 0) + if ((joypad1_newkeys & 0x8000) != 0) goto LABEL_11; if ((joypad1_newkeys & kButton_Up) != 0) { v1 = enemy_projectile_id[15]; while ((--v1 & 0x80) == 0) { - if ((kBitShl_[v1] & (uint8)nonempty_save_slots) != 0) { + if ((kBitShl_[v1] & nonempty_save_slots) != 0) { LABEL_16: LOBYTE(enemy_projectile_id[15]) = v1; LOBYTE(v0) = 55; @@ -1233,7 +1192,7 @@ LABEL_16: } else if ((joypad1_newkeys & kButton_Down) != 0) { v1 = enemy_projectile_id[15]; while ((int8)(++v1 - 4) < 0) { - if (v1 == 3 || (kBitShl_[v1] & (uint8)nonempty_save_slots) != 0) + if (v1 == 3 || (kBitShl_[v1] & nonempty_save_slots) != 0) goto LABEL_16; } } @@ -1262,8 +1221,8 @@ void FileSelectMenu_24_FileClearConfirm(void) { // 0x819C36 DrawBorderAroundDataClearMode(); DrawMenuSelectionMissile(); if ((joypad1_newkeys & (kButton_Up | kButton_Down)) != 0) { - enemy_projectile_id[15] ^= 1u; - QueueSfx1_Max6(0x37u); + enemy_projectile_id[15] ^= 1; + QueueSfx1_Max6(0x37); LABEL_8: v0 = 184; if (enemy_projectile_id[15]) @@ -1272,17 +1231,17 @@ LABEL_8: enemy_projectile_id[5] = 94; return; } - if ((joypad1_newkeys & 0x8000u) != 0) { + if ((joypad1_newkeys & 0x8000) != 0) { LABEL_5: menu_index -= 2; enemy_projectile_id[15] = enemy_projectile_id[16]; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); InitFileSelectMenuFileClear(); return; } if ((joypad1_newkeys & (kButton_Start | kButton_A)) == 0) goto LABEL_8; - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); if (enemy_projectile_id[15]) goto LABEL_5; ++menu_index; @@ -1292,12 +1251,11 @@ void FileSelectMenu_25_FileClearDoClear(void) { // 0x819C9E static const uint16 kBitShl_Not[3] = { 0xfffe, 0xfffd, 0xfffb }; DrawBorderAroundDataClearMode(); - *(uint16 *)&R0_.bank = 112; int sram_addr = kOffsetToSaveSlot[enemy_projectile_id[16]]; memset(&g_sram[sram_addr], 0, 1628); uint16 v1 = 2 * enemy_projectile_id[16]; - int v2 = (uint16)(2 * enemy_projectile_id[16]) >> 1; + int v2 = enemy_projectile_id[16]; *(uint16 *)(&g_sram[2 * v2]) = 0; *(uint16 *)(&g_sram[2 * v2 + 8]) = 0; *(uint16 *)(&g_sram[2 * v2 + 0x1FF0]) = 0; @@ -1322,7 +1280,7 @@ void FileSelectMenu_25_FileClearDoClear(void) { // 0x819C9E void FileSelectMenu_26_ClearCompleted(void) { // 0x819D26 DrawBorderAroundDataClearMode(); if (joypad1_newkeys) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); ++menu_index; if (!(LoadFromSram(0))) { LABEL_3: @@ -1352,7 +1310,7 @@ void FileSelectMenu_31_TurnSamusHelmet(void) { // 0x819D77 DrawFileSelectSlotSamusHelmet(8); if ((joypad1_newkeys & (kButton_Start | kButton_A)) != 0 || enemy_projectile_id[2] == 7 && !enemy_projectile_index - || enemy_projectile_id[3] == 7 && !enemy_projectile_init_param + || enemy_projectile_id[3] == 7 && !enemy_projectile_init_param_1 || enemy_projectile_id[4] == 7 && !enemy_projectile_unk1995) { ++menu_index; } @@ -1361,7 +1319,7 @@ void FileSelectMenu_31_TurnSamusHelmet(void) { // 0x819D77 void DrawFileSelectSamusHelmets(void) { // 0x819DC3 enemy_projectile_index = 0; DrawFileSelectSlotSamusHelmet(4); - enemy_projectile_init_param = 0; + enemy_projectile_init_param_1 = 0; DrawFileSelectSlotSamusHelmet(6); enemy_projectile_unk1995 = 0; DrawFileSelectSlotSamusHelmet(8); @@ -1388,9 +1346,8 @@ void DrawFileSelectSlotSamusHelmet(uint16 k) { // 0x819DE4 } int v5 = v0 >> 1; uint16 v6 = 2 * enemy_projectile_id[v5]; - R3_.addr = 3584; static const uint16 kDrawFileSlotHelmet_Spritemaps[9] = { 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x33 }; - DrawMenuSpritemap(kDrawFileSlotHelmet_Spritemaps[v6 >> 1], enemy_projectile_id[v5 + 5], enemy_projectile_id[v5 + 10]); + DrawMenuSpritemap(kDrawFileSlotHelmet_Spritemaps[v6 >> 1], enemy_projectile_id[v5 + 5], enemy_projectile_id[v5 + 10], 3584); } static Func_V *const kFileSelectMapFuncs[23] = { // 0x819E3E FileSelectMap_0, @@ -1473,14 +1430,14 @@ void FileSelectMenu_16(void) { // 0x819EF3 LoadMenuTilemap(0x176, addr_kMenuTilemap_TIME); enemy_data[0].palette_index = 0; LoadMenuTilemap(0x286, addr_kMenuTilemap_SamusB); - c = LoadFromSram_(1u); + c = LoadFromSram_(1); nonempty_save_slots = (nonempty_save_slots >> 1) | (c << 15); DrawFileSelectionHealth(nonempty_save_slots & 0x8000, 0x29C); DrawFileSelectionTime(nonempty_save_slots & 0x8000, 0x2F4); LoadMenuTilemap(0x2B6, addr_kMenuTilemap_TIME); enemy_data[0].palette_index = 0; LoadMenuTilemap(0x3C6, addr_kMenuTilemap_SamusC); - c = LoadFromSram_(2u); + c = LoadFromSram_(2); nonempty_save_slots = (nonempty_save_slots >> 1) | (c << 15); DrawFileSelectionHealth(nonempty_save_slots & 0x8000, 0x3DC); DrawFileSelectionTime(nonempty_save_slots & 0x8000, 0x434); @@ -1498,7 +1455,7 @@ void FileSelectMenu_16(void) { // 0x819EF3 enemy_projectile_enable_flag = 1; enemy_projectile_unk198F = 0; enemy_projectile_index = 0; - enemy_projectile_init_param = 0; + enemy_projectile_init_param_1 = 0; enemy_projectile_unk1995 = 0; enemy_projectile_id[0] = 0; enemy_projectile_id[1] = 0; @@ -1543,57 +1500,54 @@ void FileSelectMenu_3_FadeInToMain(void) { // 0x81A058 void DrawFileSelectionHealth(uint16 a, uint16 k) { // 0x81A087 int16 v2; int16 v4; - unsigned int v5; if (a) { FileSelectClearRestOfMenuTilemapRow(k); LoadMenuTilemap(k + 64, addr_kMenuTilemap_NoData); } else { - R26_ = k; LoadMenuTilemap(k, addr_kMenuTilemap_Energy); - v2 = R26_ + 8; + v2 = k + 8; - R20_ = samus_health / 100; - R18_ = samus_health % 100; - R22_ = samus_max_health / 100; - R24_ = 7; + int n = samus_health / 100; + int q = samus_health % 100; + int mh = samus_max_health / 100; + int m = 7; uint16 v3 = v2 + 64; - while ((--R22_ & 0x8000u) == 0) { + while (--mh >= 0) { v4 = 153; - if (R20_) { - --R20_; + if (n) { + --n; v4 = 152; } *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[768] + v3) = enemy_data[0].palette_index | v4; v3 += 2; - if (!--R24_) { + if (!--m) { v3 -= 78; - R24_ = 8; + m = 8; } } - R20_ = R18_ / 10; - R18_ = R18_ % 10; - v5 = R26_; - *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[802] + R26_) = enemy_data[0].palette_index | (R18_ + 8288); - *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[801] + v5) = enemy_data[0].palette_index | (R20_ + 8288); + n = q / 10; + q = q % 10; + *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[802] + k) = enemy_data[0].palette_index | (q + 8288); + *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[801] + k) = enemy_data[0].palette_index | (n + 8288); } } void DrawFileSelectionTime(uint16 a, uint16 k) { // 0x81A14E if (!a) { - R26_ = k; + uint16 r26 = k; int div_val = game_time_hours / 10; int mod_val = game_time_hours % 10; - uint16 v2 = R26_; + uint16 v2 = r26; *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[769] + v2) = enemy_data[0].palette_index | (mod_val + 8288); *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[768] + v2) = enemy_data[0].palette_index | (div_val + 8288); - LoadMenuTilemap(R26_ + 4, addr_word_81B4A8); + LoadMenuTilemap(r26 + 4, addr_word_81B4A8); int div_min = game_time_minutes / 10; int mod_min = game_time_minutes % 10; - uint16 v3 = R26_; + uint16 v3 = r26; *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[772] + v3) = enemy_data[0].palette_index | (mod_min + 8288); *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[771] + v3) = enemy_data[0].palette_index | (div_min + 8288); } @@ -1628,9 +1582,9 @@ void FileSelectMenu_4_Main(void) { // 0x81A1C2 } else { if ((joypad1_newkeys & kButton_Down) == 0) { if ((joypad1_newkeys & kButton_B) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); menu_index = 33; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); } goto LABEL_28; } @@ -1649,7 +1603,7 @@ void FileSelectMenu_4_Main(void) { // 0x81A1C2 } selected_save_slot = v2; } - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); LABEL_28: v3 = (uint16)(4 * selected_save_slot) >> 1; enemy_projectile_id[10] = kMenuSelectionMissileXY[v3]; @@ -1658,7 +1612,7 @@ LABEL_28: } v0 = selected_save_slot; if (sign16(selected_save_slot - 3)) { - QueueSfx1_Max6(0x2Au); + QueueSfx1_Max6(0x2A); menu_index += 27; *(uint16 *)((uint8 *)&enemy_projectile_enable_flag + (uint16)(2 * (selected_save_slot + 2))) = 1; *(uint16 *)&g_sram[0x1FEC] = selected_save_slot; @@ -1673,12 +1627,12 @@ LABEL_28: goto LABEL_28; } if (selected_save_slot == 3) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); ++menu_index; *(uint16 *)®_MOSAIC = *(uint16 *)®_MOSAIC & 0xFF0C | 3; } else { if (selected_save_slot == 4) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); menu_index += 15; v0 = *(uint16 *)®_MOSAIC & 0xFF0C | 3; *(uint16 *)®_MOSAIC = v0; @@ -1772,13 +1726,12 @@ void LoadAreaMapForegroundColors(uint16 j) { // 0x81A3E3 uint16 v4 = j; uint16 v2 = kAreaMapForegroundSetDefs[v1 + 1]; uint16 v3 = kAreaMapForegroundSetDefs[v1]; - R18_ = 5; + int n = 5; do { palette_buffer[v2 >> 1] = kAreaMapForegroundColors[v3 >> 1]; v2 += 2; v3 += 2; - --R18_; - } while (R18_); + } while (--n); j = v4 + 4; } } @@ -1819,11 +1772,11 @@ void LoadAreaSelectBackgroundTilemap(uint16 j) { // 0x81A58A void FileSelectMap_4_SetupExpandingSquareTransition(void) { // 0x81A5B3 reg_TS = 4; - WriteReg(TS, 4u); + WriteReg(TS, 4); reg_TSW = 4; - WriteReg(TSW, 4u); + WriteReg(TSW, 4); reg_CGWSEL = 2; - WriteReg(CGWSEL, 2u); + WriteReg(CGWSEL, 2); reg_CGADSUB = 37; WriteReg(CGADSUB, 0x25); reg_COLDATA[2] = 0x80; @@ -1845,7 +1798,7 @@ void ConfigureWindow1ForExpandingSquare(void) { // 0x81A5F6 reg_W12SEL = 35; WriteReg(W12SEL, 0x23); reg_W34SEL = 3; - WriteReg(W34SEL, 3u); + WriteReg(W34SEL, 3); reg_WOBJSEL = 35; WriteReg(WOBJSEL, 0x23); } @@ -1912,7 +1865,7 @@ void FileSelectMap_5_ExpandingSquare(void) { // 0x81A725 uint8 v0 = hdma_window_1_left_pos[0].field_0 - kExpandingSquareTransitionSpeed; if ((int8)(hdma_window_1_left_pos[0].field_0 - kExpandingSquareTransitionSpeed) < 0) { LOBYTE(menu_index) = menu_index + 1; - reg_TM &= ~2u; + reg_TM &= ~2; reg_TMW = 0; reg_TSW = 0; reg_BG2VOFS = 24; @@ -1925,10 +1878,7 @@ void FileSelectMap_5_ExpandingSquare(void) { // 0x81A725 do ram4000.xray_tilemaps[v1++] = 10241; while ((int16)(v1 * 2 - 2048) < 0); - - R0_.addr = ADDR16_OF_RAM(ram4000) + 340; - *(uint16 *)&R0_.bank = 126; - DrawRoomSelectMapAreaLabel(); + DrawRoomSelectMapAreaLabel((LongPtr) { ADDR16_OF_RAM(ram4000) + 340, 0x7e }); uint16 v2 = 320; uint16 v3 = 959; do { @@ -1939,7 +1889,7 @@ void FileSelectMap_5_ExpandingSquare(void) { // 0x81A725 v5 = gVramWriteEntry(vram_write_queue_tail); v5->size = 2048; v5->src.addr = ADDR16_OF_RAM(ram4000); - *(uint16 *)&v5->src.bank = 126; + v5->src.bank = 126; v5->vram_dst = (reg_BG2SC & 0xFC) << 8; vram_write_queue_tail = v4 + 7; } else { @@ -1958,20 +1908,18 @@ void FileSelectMap_5_ExpandingSquare(void) { // 0x81A725 void FileSelectMap_6_AreaSelectMap(void) { // 0x81A800 int16 v0; - uint16 v2; - uint16 v3; v0 = joypad1_newkeys; if ((joypad1_newkeys & (kButton_Up | kButton_Left)) != 0) { v0 = enable_debug; if (enable_debug) { - R24_ = R22_; - uint16 v1 = DecAndWraparoundTo5(file_select_map_area_index); - if (CheckIfFileSelectMapAreaCanBeSelected(v1) - || (v2 = DecAndWraparoundTo5(R28_), CheckIfFileSelectMapAreaCanBeSelected(v2)) - || (v3 = DecAndWraparoundTo5(R28_), CheckIfFileSelectMapAreaCanBeSelected(v3))) { - QueueSfx1_Max6(0x37u); - SwitchActiveFileSelectMapArea(); +//?? r24 = R22_; + uint16 R28 = DecAndWraparoundTo5(file_select_map_area_index); + if (CheckIfFileSelectMapAreaCanBeSelected(R28) + || (R28 = DecAndWraparoundTo5(R28), CheckIfFileSelectMapAreaCanBeSelected(R28)) + || (R28 = DecAndWraparoundTo5(R28), CheckIfFileSelectMapAreaCanBeSelected(R28))) { + QueueSfx1_Max6(0x37); + SwitchActiveFileSelectMapArea(R28); DrawAreaSelectMapLabels(); return; } @@ -1984,7 +1932,7 @@ LABEL_6: return; } if ((v0 & (kButton_Start | kButton_A)) != 0) { - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); SelectFileSelectMapArea(); return; } @@ -1997,23 +1945,23 @@ LABEL_18: v0 = enable_debug; if (!enable_debug) goto LABEL_6; - R22_ = 6; - R28_ = file_select_map_area_index; + int n = 6; + uint16 R28 = file_select_map_area_index; while (1) { - uint16 v4 = WraparoundFrom6to0(R28_); - if (CheckIfFileSelectMapAreaCanBeSelected(v4)) + R28 = WraparoundFrom6to0(R28); + if (CheckIfFileSelectMapAreaCanBeSelected(R28)) break; - if (!--R22_) + if (!--n) goto LABEL_18; } - SwitchActiveFileSelectMapArea(); - QueueSfx1_Max6(0x37u); + SwitchActiveFileSelectMapArea(R28); + QueueSfx1_Max6(0x37); DrawAreaSelectMapLabels(); } uint16 DecAndWraparoundTo5(uint16 a) { // 0x81A898 uint16 result = a - 1; - if ((result & 0x8000u) != 0) + if ((result & 0x8000) != 0) return 5; return result; } @@ -2038,20 +1986,19 @@ void SelectFileSelectMapArea(void) { // 0x81A8A9 return; } area_index = kFileSelectMap_AreaIndexes[file_select_map_area_index]; - R18_ = *(uint16 *)&used_save_stations_and_elevators[(uint16)(2 * area_index)]; + uint16 q = *(uint16 *)&used_save_stations_and_elevators[2 * area_index]; uint16 v0 = 0; - R0_.bank = 130; - R0_.addr = addr_kMapIconDataPointers + 64; - R0_.addr = IndirReadWord(R0_, 2 * area_index); - if (!R0_.addr) + LongPtr r0 = { addr_kMapIconDataPointers + 64, 0x82}; + r0.addr = IndirReadWord(r0, 2 * area_index); + if (!r0.addr) InvalidInterrupt_Crash(); - R20_ = 16; + uint16 r20 = 16; while (1) { - v2 = R18_ & 1; - R18_ >>= 1; + v2 = q & 1; + q >>= 1; if (!v2) goto LABEL_10; - v3 = IndirReadWord(R0_, 4 * v0); + v3 = IndirReadWord(r0, 4 * v0); if (v3 == -2) goto LABEL_10; if (v3 != -1) @@ -2059,18 +2006,17 @@ void SelectFileSelectMapArea(void) { // 0x81A8A9 v0 = -1; LABEL_10: ++v0; - if (!--R20_) { + if (!--r20) { while (1) { - v4 = IndirReadWord(R0_, 4 * v0); + v4 = IndirReadWord(r0, 4 * v0); if (v4 != -2) { if (v4 != -1) goto LABEL_16; v0 = -1; } ++v0; - if (!--R20_) { - while (1) - ; + if (!--r20) { + Unreachable(); } } } @@ -2081,7 +2027,6 @@ LABEL_16: } uint16 CheckIfFileSelectMapAreaCanBeSelected(uint16 a) { // 0x81A931 - R28_ = a; int v1 = 2 * kFileSelectMap_AreaIndexes[a]; if (*(uint16 *)&used_save_stations_and_elevators[v1]) return true; @@ -2089,10 +2034,10 @@ uint16 CheckIfFileSelectMapAreaCanBeSelected(uint16 a) { // 0x81A931 return t != 0xffff; } -void SwitchActiveFileSelectMapArea(void) { // 0x81A958 +void SwitchActiveFileSelectMapArea(uint16 R28) { // 0x81A958 LoadInactiveAreaMapForegroundColors(kFileSelectMap_AreaIndexes[file_select_map_area_index]); - file_select_map_area_index = R28_; - LoadActiveAreaMapForegroundColors(kFileSelectMap_AreaIndexes[R28_]); + file_select_map_area_index = R28; + LoadActiveAreaMapForegroundColors(kFileSelectMap_AreaIndexes[R28]); LoadAreaSelectBackgroundTilemap(kFileSelectMap_AreaIndexes[file_select_map_area_index]); } static const uint16 kAreaSelectMapLabelPositions[12] = { // 0x81A97E @@ -2104,10 +2049,10 @@ static const uint16 kAreaSelectMapLabelPositions[12] = { // 0x81A97E 0x87, 0x8b, }; void DrawAreaSelectMapLabels(void) { - R3_.addr = 0; - DrawMenuSpritemap(g_word_82C749[0], 0x80, 0x10); + uint16 r3 = 0; + DrawMenuSpritemap(g_word_82C749[0], 0x80, 0x10, r3); for(int i = 0; i < 6; i++) { - R3_.addr = (i == file_select_map_area_index) ? 0 : 512; + r3 = (i == file_select_map_area_index) ? 0 : 512; uint16 v1 = 2 * kFileSelectMap_AreaIndexes[i]; uint16 r36 = *(uint16 *)&used_save_stations_and_elevators[v1]; const uint16 *v2 = (const uint16 *)RomPtr_82(*(VoidP *)((uint8 *)&kMapIconDataPointers[4].crateria + v1)); @@ -2125,7 +2070,7 @@ LABEL_11:; DrawMenuSpritemap( g_word_82C749[0] + kFileSelectMap_AreaIndexes[i] + 1, kAreaSelectMapLabelPositions[j], - kAreaSelectMapLabelPositions[j + 1]); + kAreaSelectMapLabelPositions[j + 1], r3); break; } break; @@ -2138,8 +2083,6 @@ LABEL_11:; static const uint16 kRoomSelectMapExpandingSquareTimers[6] = { 0x33, 0x35, 0x2d, 0x33, 0x33, 0x22 }; void FileSelectMap_7_PrepExpandSquareTransToRoomMap(void) { // 0x81AAAC - VramWriteEntry *v1; - DrawAreaSelectMapLabels(); SetupInitialExpandingSquareHDMA(); reg_TM = 19; @@ -2147,24 +2090,23 @@ void FileSelectMap_7_PrepExpandSquareTransToRoomMap(void) { // 0x81AAAC reg_W12SEL = 50; WriteReg(W12SEL, 0x32); reg_W34SEL = 2; - WriteReg(W34SEL, 2u); + WriteReg(W34SEL, 2); reg_CGADSUB = 5; - WriteReg(CGADSUB, 5u); + WriteReg(CGADSUB, 5); reg_WOBJSEL = 34; WriteReg(WOBJSEL, 0x22); reg_BG12NBA = 48; hdma_window_1_left_pos[3].field_0 = 0; hdma_window_1_right_pos[3].field_0 = 0; - R0_.addr = ADDR16_OF_RAM(ram4000) + 340; - *(uint16 *)&R0_.bank = 126; - DrawRoomSelectMapAreaLabel(); + DrawRoomSelectMapAreaLabel((LongPtr) { ADDR16_OF_RAM(ram4000) + 340, 0x7e }); uint16 v0 = vram_write_queue_tail; - v1 = gVramWriteEntry(vram_write_queue_tail); + VramWriteEntry *v1 = gVramWriteEntry(vram_write_queue_tail); v1->size = 512; v1->src.addr = ADDR16_OF_RAM(ram4000); - *(uint16 *)&v1->src.bank = 126; + v1->src.bank = 126; v1->vram_dst = (reg_BG2SC & 0xFC) << 8; vram_write_queue_tail = v0 + 7; + expanding_square_timer = kRoomSelectMapExpandingSquareTimers[area_index]; int v2 = (uint16)(4 * area_index) >> 1; expanding_square_left_pos = kAreaSelectMapLabelPositions[v2]; @@ -2175,25 +2117,21 @@ void FileSelectMap_7_PrepExpandSquareTransToRoomMap(void) { // 0x81AAAC expanding_square_right_subpos = 0; expanding_square_top_subpos = 0; expanding_square_bottom_subpos = 0; - expanding_square_left_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].left_subvel - + (uint16)(16 * area_index)); - expanding_square_left_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].left_vel + (uint16)(16 * area_index)); - expanding_square_right_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].right_subvel - + (uint16)(16 * area_index)); - expanding_square_right_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].right_vel - + (uint16)(16 * area_index)); - expanding_square_top_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].top_subvel - + (uint16)(16 * area_index)); - expanding_square_top_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].top_vel + (uint16)(16 * area_index)); - expanding_square_bottom_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].bottom_subvel - + (uint16)(16 * area_index)); - expanding_square_bottom_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].bottom_vel - + (uint16)(16 * area_index)); + + const ExpandingSquareVels *vels = &kExpandingSquareVels[area_index]; + expanding_square_left_subvel = vels->left_subvel; + expanding_square_left_vel = vels->left_vel; + expanding_square_right_subvel = vels->right_subvel; + expanding_square_right_vel = vels->right_vel; + expanding_square_top_subvel = vels->top_subvel; + expanding_square_top_vel = vels->top_vel; + expanding_square_bottom_subvel = vels->bottom_subvel; + expanding_square_bottom_vel = vels->bottom_vel; SetupRoomSelectMapExpandingSquareTransHDMA(); reg_HDMAEN = 12; WriteReg(HDMAEN, 0xC); ++menu_index; - QueueSfx1_Max6(0x3Bu); + QueueSfx1_Max6(0x3B); } void SetupRoomSelectMapExpandingSquareTransHDMA(void) { // 0x81ABA7 @@ -2242,7 +2180,7 @@ uint16 AddExpandingSqTransRightIndirHDMA(uint16 a, uint16 k, uint16 j) { // 0x8 } void FileSelectMap_8_ExpandSquareTransToRoomSelectMap(void) { // 0x81AC66 - if ((HandleRoomSelectMapExpandingSquareTrans() & 0x8000u) != 0) { + if ((HandleRoomSelectMapExpandingSquareTrans() & 0x8000) != 0) { ++menu_index; reg_TM = 2; reg_TMW = 0; @@ -2294,7 +2232,7 @@ void FileSelectMap_9_InitRoomSelectMap(void) { // 0x81AD17 SetupMapScrollingForFileSelectMap(); map_min_y_scroll += 24; reg_BG2VOFS = 24; - *(uint16 *)®_TM &= ~4u; + *(uint16 *)®_TM &= ~4; ++menu_index; map_scrolling_direction = 0; map_scrolling_speed_index = 0; @@ -2316,27 +2254,27 @@ void FileSelectMap_10_RoomSelectMap(void) { // 0x81AD7F MapScrolling(); DisplayMapElevatorDestinations(); if (enable_debug && (joypad2_new_keys & kButton_Select) != 0) { - QueueSfx1_Max6(0x38u); - R0_.bank = -126; - R24_ = *(uint16 *)&used_save_stations_and_elevators[(uint16)(2 * area_index)]; + QueueSfx1_Max6(0x38); + + uint16 r24 = *(uint16 *)&used_save_stations_and_elevators[2 * area_index]; v1 = load_station_index; do { - R24_ >>= 1; + r24 >>= 1; --v1; } while (v1 >= 0); - v2 = (VoidP *)RomPtr_82(2 * area_index - 14325); - while (!*v2) - ; - R0_.addr = *v2; + v2 = (VoidP *)RomPtr_82(2 * area_index + 0xC80B); + if (!*v2) + Unreachable(); + LongPtr r0 = { *v2, 0x82 }; v3 = 4 * load_station_index; - R18_ = IndirReadWord(R0_, 4 * load_station_index); - R20_ = IndirReadWord(R0_, v3 + 2); + uint16 r18 = IndirReadWord(r0, v3); + uint16 r20 = IndirReadWord(r0, v3 + 2); if (!sign16(load_station_index - 16)) goto LABEL_23; do { if (!sign16(++load_station_index - 16)) { while (1) { - v5 = IndirReadWord(R0_, 4 * load_station_index); + v5 = IndirReadWord(r0, 4 * load_station_index); if (v5 == -1) break; if (v5 != -2) @@ -2345,16 +2283,16 @@ LABEL_23: ++load_station_index; } load_station_index = 0; - R24_ = *(uint16 *)&used_save_stations_and_elevators[(uint16)(2 * area_index)]; + r24 = *(uint16 *)&used_save_stations_and_elevators[2 * area_index]; } - v4 = R24_ & 1; - R24_ >>= 1; - } while (!v4 || IndirReadWord(R0_, 4 * load_station_index) >= 0xFFFEu); + v4 = r24 & 1; + r24 >>= 1; + } while (!v4 || IndirReadWord(r0, 4 * load_station_index) >= 0xFFFE); LABEL_25:; uint16 v6 = 4 * load_station_index; - uint16 w7 = IndirReadWord(R0_, 4 * load_station_index); + uint16 w7 = IndirReadWord(r0, 4 * load_station_index); if (sign16(w7 - reg_BG1HOFS) || !sign16(w7 - 256 - reg_BG1HOFS)) { - v8 = reg_BG1HOFS + IndirReadWord(R0_, v6) - R18_; + v8 = reg_BG1HOFS + IndirReadWord(r0, v6) - r18; if (v8 >= 0) { if ((int16)(v8 - map_min_x_scroll) >= 0) v8 = map_min_x_scroll; @@ -2364,14 +2302,14 @@ LABEL_25:; reg_BG1HOFS = v8; } uint16 v9 = v6 + 2; - uint16 v10 = IndirReadWord(R0_, v9); + uint16 v10 = IndirReadWord(r0, v9); if (sign16(v10 - reg_BG1VOFS) || !sign16(v10 - 161 - reg_BG1VOFS)) { - uint16 v11 = reg_BG1VOFS + IndirReadWord(R0_, v9) - R20_; + uint16 v11 = reg_BG1VOFS + IndirReadWord(r0, v9) - r20; if ((int16)(v11 - map_min_y_scroll) >= 0) v11 = map_min_y_scroll; reg_BG1VOFS = v11; } - } else if ((joypad1_newkeys & 0x8000u) != 0) { + } else if ((joypad1_newkeys & 0x8000) != 0) { menu_index += 5; uint16 v0 = 0; while (area_index != kFileSelectMap_AreaIndexes[v0 >> 1]) { @@ -2382,10 +2320,10 @@ LABEL_25:; } } file_select_map_area_index = v0 >> 1; - QueueSfx1_Max6(0x3Cu); + QueueSfx1_Max6(0x3C); } else if ((joypad1_newkeys & (kButton_Start | kButton_A)) != 0) { ++menu_index; - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); } } @@ -2466,7 +2404,7 @@ void FileSelectMap_16_LoadPalettes(void) { // 0x81AFD3 void FileSelectMap_20_SetupExpandingSquare(void) { // 0x81AFF6 reg_HDMAEN = 0; - QueueSfx1_Max6(0x3Cu); + QueueSfx1_Max6(0x3C); expanding_square_timer = kRoomSelectMapExpandingSquareTimers[area_index] - 12; expanding_square_left_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].left_subvel + (uint16)(16 * area_index)); @@ -2497,7 +2435,7 @@ void FileSelectMap_20_SetupExpandingSquare(void) { // 0x81AFF6 reg_W12SEL = 50; WriteReg(W12SEL, 0x32); reg_W34SEL = 2; - WriteReg(W34SEL, 2u); + WriteReg(W34SEL, 2); reg_BG12NBA = 48; reg_WOBJSEL = 34; hdma_window_1_left_pos[3].field_0 = 0; @@ -2525,7 +2463,7 @@ void FileSelectMap_21_MoveExpandingSquare(void) { // 0x81B0BB expanding_square_bottom_pos = v3; SetupRoomSelectMapExpandingSquareTransHDMA(); DrawAreaSelectMapLabels(); - if ((--expanding_square_timer & 0x8000u) != 0) { + if ((--expanding_square_timer & 0x8000) != 0) { menu_index -= 15; reg_TM = 17; reg_TMW = 0; @@ -2600,12 +2538,11 @@ void NewSaveFile(void) { // 0x81B2CB } void FileSelectClearRestOfMenuTilemapRow(uint16 v0) { // 0x81B3C5 - R18_ = 32 - ((uint8)(v0 & 0x3F) >> 1); + int n = 32 - ((v0 & 0x3F) >> 1); do { *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[768] + v0) = 15; v0 += 2; - --R18_; - } while (R18_); + } while (--n); } void LoadMenuTilemap(uint16 k, uint16 j) { // 0x81B3E2 @@ -2626,4 +2563,4 @@ void LoadMenuTilemap(uint16 k, uint16 j) { // 0x81B3E2 k += 2; j += 2; } -} \ No newline at end of file +} diff --git a/src/sm_82.c b/src/sm_82.c index ecefe80..2006b98 100644 --- a/src/sm_82.c +++ b/src/sm_82.c @@ -135,10 +135,9 @@ CoroutineRet InitAndLoadGameData_Async(void) { // 0x828000 TransferEnemyTilesToVramAndInit(); COROUTINE_AWAIT(2, WaitForNMI_Async()); --loop_counter_transfer_enemies_to_vram; - } while ((loop_counter_transfer_enemies_to_vram & 0x8000u) == 0); - R18_ = 18 * (demo_scene - 1); - R18_ = get_DemoRoomData(R18_ + kDemoRoomData[demo_set])->demo_code_ptr; - CallDemoRoomDataFunc(R18_ | 0x820000); + } while ((loop_counter_transfer_enemies_to_vram & 0x8000) == 0); + uint16 r18 = get_DemoRoomData(kDemoRoomData[demo_set] + 18 * (demo_scene - 1))->demo_code_ptr; + CallDemoRoomDataFunc(r18 | 0x820000); ++game_state; v7 = 512; uint16 v8 = 0; @@ -148,13 +147,13 @@ CoroutineRet InitAndLoadGameData_Async(void) { // 0x828000 v7 -= 2; } while (v7); } else if (loading_game_state == kLoadingGameState_22_EscapingCeres) { - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); loop_counter_transfer_enemies_to_vram = 15; do { TransferEnemyTilesToVramAndInit(); COROUTINE_AWAIT(3, WaitForNMI_Async()); --loop_counter_transfer_enemies_to_vram; - } while ((loop_counter_transfer_enemies_to_vram & 0x8000u) == 0); + } while ((loop_counter_transfer_enemies_to_vram & 0x8000) == 0); ++game_state; v2 = 512; uint16 v3 = 0; @@ -169,7 +168,7 @@ CoroutineRet InitAndLoadGameData_Async(void) { // 0x828000 TransferEnemyTilesToVramAndInit(); COROUTINE_AWAIT(4, WaitForNMI_Async()); --loop_counter_transfer_enemies_to_vram; - } while ((loop_counter_transfer_enemies_to_vram & 0x8000u) == 0); + } while ((loop_counter_transfer_enemies_to_vram & 0x8000) == 0); game_state = kGameState_7_MainGameplayFadeIn; v4 = 512; uint16 v5 = 0; @@ -180,9 +179,9 @@ CoroutineRet InitAndLoadGameData_Async(void) { // 0x828000 } while (v4); if (loading_game_state == kLoadingGameState_1F_StartingAtCeres) { palette_buffer[223] = 0; - CallSomeSamusCode(8u); + CallSomeSamusCode(8); } else { - CallSomeSamusCode(9u); + CallSomeSamusCode(9); } } @@ -195,7 +194,7 @@ void InitIoForGameplay(void) { // 0x82819B } void InitCpuForGameplay(void) { // 0x8281A4 - WriteReg(NMITIMEN, 1u); + WriteReg(NMITIMEN, 1); reg_NMITIMEN = 1; WriteReg(WRIO, 0); WriteReg(WRMPYA, 0); @@ -210,14 +209,14 @@ void InitCpuForGameplay(void) { // 0x8281A4 WriteReg(MDMAEN, 0); WriteReg(HDMAEN, 0); reg_HDMAEN = 0; - WriteReg(MEMSEL, 1u); + WriteReg(MEMSEL, 1); reg_MEMSEL = 1; } void InitPpuForGameplay(void) { // 0x8281DD WriteReg(INIDISP, 0x80); reg_INIDISP = 0x80; - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; WriteReg(OAMADDL, 0); LOBYTE(reg_OAMaddr_UNUSED) = 0; @@ -225,14 +224,14 @@ void InitPpuForGameplay(void) { // 0x8281DD HIBYTE(reg_OAMaddr_UNUSED) = 0x80; WriteReg(OAMDATA, 0); WriteReg(OAMDATA, 0); - WriteReg(BGMODE, 9u); + WriteReg(BGMODE, 9); reg_BGMODE = 9; WriteReg(MOSAIC, 0); reg_MOSAIC = 0; reg_BG12NBA = 0; WriteReg(BG12NBA, 0); reg_BG34NBA = 4; - WriteReg(BG34NBA, 4u); + WriteReg(BG34NBA, 4); reg_BG1SC = 81; WriteReg(BG1SC, 0x51); reg_BG2SC = 73; @@ -302,33 +301,33 @@ void LoadStdBG3andSpriteTilesClearTilemaps(void) { // 0x8282E2 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8282F8 = { 1, 1, 0x18, LONGPTR(0x9ab200), 0x2000 }; SetupDmaTransfer(&unk_8282F8); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); // Bug fix: Asm code does DMA from RAM here. static const StartDmaCopy unk_828318 = { 1, 1, 0x18, LONGPTR(0x9ad200), 0x2e00 }; SetupDmaTransfer(&unk_828318); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x50); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_828338 = { 1, 1, 0x18, LONGPTR(0x7e4000), 0x1000 }; SetupDmaTransfer(&unk_828338); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x58); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_828358 = { 1, 1, 0x18, LONGPTR(0x7e4000), 0x0800 }; SetupDmaTransfer(&unk_828358); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } CoroutineRet GameState_32_MadeItToCeresElevator(void) { // 0x828367 if (timer_status) DrawTimer(); COROUTINE_AWAIT_ONLY(GameState_8_MainGameplay()); - bool v0 = (--reached_ceres_elevator_fade_timer & 0x8000u) != 0; + bool v0 = (--reached_ceres_elevator_fade_timer & 0x8000) != 0; if (!reached_ceres_elevator_fade_timer || v0) { ++game_state; screen_fade_delay = 0; @@ -364,9 +363,9 @@ CoroutineRet GameState_33_BlackoutFromCeres(void) { // 0x828388 ceres_status = 0; timer_status = 0; QueueMusic_Delayed8(0); - QueueSfx1_Max15(2u); - QueueSfx2_Max15(0x71u); - QueueSfx3_Max15(1u); + QueueSfx1_Max15(2); + QueueSfx2_Max15(0x71); + QueueSfx3_Max15(1); } return kCoroutineNone; } @@ -401,10 +400,10 @@ CoroutineRet GameState_36_WhitingOutFromTimeUp(void) { // 0x828431 screen_fade_counter = 0; ceres_status = 0; timer_status = 0; - QueueSfx1_Max15(2u); - QueueSfx2_Max15(0x71u); - QueueSfx3_Max15(1u); - if (CheckEventHappened(0xEu)) { + QueueSfx1_Max15(2); + QueueSfx2_Max15(0x71); + QueueSfx3_Max15(1); + if (CheckEventHappened(0xE)) { game_options_screen_index = 0; menu_index = 0; for (int i = 254; i >= 0; i -= 2) @@ -439,9 +438,9 @@ CoroutineRet GameState_38_SamusEscapesFromZebes(void) { // 0x8284BD cinematic_function = FUNC16(CinematicFunctionEscapeFromCebes); timer_status = 0; QueueMusic_Delayed8(0); - QueueSfx1_Max15(2u); - QueueSfx2_Max15(0x71u); - QueueSfx3_Max15(1u); + QueueSfx1_Max15(2); + QueueSfx2_Max15(0x71); + QueueSfx3_Max15(1); } return kCoroutineNone; } @@ -463,7 +462,7 @@ CoroutineRet GameState_42_PlayingDemo_Async(void) { // 0x828548 goto LABEL_10; } demo_timer--; - if (!demo_timer || (demo_timer & 0x8000u) != 0) { + if (!demo_timer || (demo_timer & 0x8000) != 0) { substate = 0; my_counter = 90; while (1) { @@ -514,7 +513,7 @@ CoroutineRet GameState_43_TransitionFromDemo(void) { // 0x828593 CoroutineRet GameState_44_TransitionFromDemo(void) { // 0x8285FB game_state = kGameState_1_OpeningCinematic; - if ((substate & 0x8000u) != 0) { + if ((substate & 0x8000) != 0) { game_state = kGameState_40_TransitionToDemo; } else if (substate) { LoadTitleSequenceGraphics(); @@ -530,11 +529,10 @@ CoroutineRet GameState_44_TransitionFromDemo(void) { // 0x8285FB void CheckForNextDemo(void) { // 0x828637 - R18_ = 2 * (demo_scene + 8 * demo_scene); - if (*(uint16 *)RomPtr_82(R18_ + kDemoRoomData[demo_set]) == 0xFFFF) { + if (*(uint16 *)RomPtr_82(kDemoRoomData[demo_set] + 18 * demo_scene) == 0xFFFF) { substate = 0; uint16 v0 = demo_set + 1; - if ((uint16)(demo_set + 1) >= num_demo_sets) + if (v0 >= num_demo_sets) v0 = 0; demo_set = v0; demo_scene = 0; @@ -547,7 +545,6 @@ void LoadDemoRoomData(void) { // 0x828679 DemoRoomData *drd; door_def_ptr = 0; - R18_ = 18 * demo_scene; drd = get_DemoRoomData(18 * demo_scene + kDemoRoomData[demo_set]); room_ptr = drd->room_ptr_; door_def_ptr = drd->door_ptr; @@ -805,10 +802,6 @@ void ResetSoundQueues(void) { // 0x828A9A } void ShowSpareCpu(void) { // 0x828AB0 - if ((joypad_dbg_1 & 0x4000) != 0) - debug_spare_cpu_display_flag = debug_spare_cpu_display_flag == 0; - if (debug_spare_cpu_display_flag) - WriteReg(INIDISP, reg_INIDISP & 0xF0 | 5); joypad1_input_samusfilter = joypad1_lastkeys; } @@ -923,7 +916,7 @@ uint8 CreateOptionsMenuObject_(uint16 a, uint16 j) { uint16 v3 = 14; while (optionsmenu_instr_ptr[v3 >> 1]) { v3 -= 2; - if ((v3 & 0x8000u) != 0) + if ((v3 & 0x8000) != 0) return 1; } const uint8 *v5 = RomPtr_82(j); @@ -987,7 +980,7 @@ void OptionsMenuFunc2(uint16 k) { // 0x828C2B uint16 *v5; while (1) { v5 = (uint16 *)RomPtr_82(v4); - if ((v5[0] & 0x8000u) == 0) + if ((v5[0] & 0x8000) == 0) break; v4 = CallOptionsInstr(v5[0] | 0x820000, v1, v4 + 2); if (!v4) @@ -1044,10 +1037,7 @@ void DrawOptionsMenuSpritemaps(void) { // 0x828CA1 int v1 = i >> 1; if (optionsmenu_cur_data[v1]) { uint16 v2 = optionsmenu_cur_data[v1]; - R22_ = optionsmenu_arr10[v1]; - R20_ = optionsmenu_arr8[v1]; - R18_ = optionsmenu_arr9[v1]; - DrawSpritemap(0x82, v2); + DrawSpritemap(0x82, v2, optionsmenu_arr8[v1], optionsmenu_arr9[v1], optionsmenu_arr10[v1]); } } } @@ -1122,7 +1112,7 @@ void BackupBG2TilemapForPauseMenu(void) { // 0x828D51 WriteReg(DAS10, 0); WriteRegWord(A2A1L, 0); WriteReg(NTRL1, 0); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } void RestoreBG2TilemapFromPauseScreen(void) { // 0x828D96 @@ -1130,7 +1120,7 @@ void RestoreBG2TilemapFromPauseScreen(void) { // 0x828D96 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_828DAE = { 1, 1, 0x18, LONGPTR(0x7edf5c), 0x1000 }; SetupDmaTransfer(&unk_828DAE); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } void BackupSomeGfxStateForPause(void) { // 0x828DBD @@ -1179,19 +1169,19 @@ void LoadPauseMenuTilesAndClearBG2(void) { // 0x828E75 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_828E8B = { 1, 1, 0x18, LONGPTR(0xb68000), 0x4000 }; SetupDmaTransfer(&unk_828E8B); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x20); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_828EAB = { 1, 1, 0x18, LONGPTR(0xb6c000), 0x2000 }; SetupDmaTransfer(&unk_828EAB); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x40); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_828ECB = { 1, 1, 0x18, LONGPTR(0x9ab200), 0x2000 }; SetupDmaTransfer(&unk_828ECB); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } void LoadPauseScreenBaseTilemaps(void) { // 0x828EDA @@ -1200,46 +1190,44 @@ void LoadPauseScreenBaseTilemaps(void) { // 0x828EDA WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_828EF0 = { 1, 1, 0x18, LONGPTR(0xb6e000), 0x0800 }; SetupDmaTransfer(&unk_828EF0); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(WMADDL, 0); WriteReg(WMADDM, 0x34); WriteReg(WMADDH, 0x7E); static const StartDmaCopy unk_828F10 = { 1, 0, 0x80, LONGPTR(0xb6e400), 0x0400 }; SetupDmaTransfer(&unk_828F10); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(WMADDL, 0); WriteReg(WMADDM, 0x38); WriteReg(WMADDH, 0x7E); static const StartDmaCopy unk_828F30 = { 1, 0, 0x80, LONGPTR(0xb6e800), 0x0800 }; SetupDmaTransfer(&unk_828F30); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); uint16 v0 = addr_kDummySamusWireframeTilemap; uint16 v1 = 236; - R20_ = 17; + int m = 17; do { - R18_ = 8; + int n = 8; do { ram3000.pause_menu_map_tilemap[v1++] = *(uint16 *)RomPtr_82(v0); v0 += 2; - --R18_; - } while (R18_); + } while (--n); v1 += 8; - --R20_; - } while (R20_); + } while (--m); WriteSamusWireframeTilemap(); LoadEqupmentScreenReserveHealthTilemap(); } void LoadEqupmentScreenReserveHealthTilemap(void) { // 0x828F70 if (samus_max_reserve_health) { - R42 = samus_reserve_health / 100; + int r42 = samus_reserve_health / 100; int rest = samus_reserve_health % 100; int div10 = rest / 10; int mod10 = rest % 10; ram3800.cinematic_bg_tilemap[394] = mod10 + 2052; ram3800.cinematic_bg_tilemap[393] = div10 + 2052; - ram3800.cinematic_bg_tilemap[392] = R42 + 2052; + ram3800.cinematic_bg_tilemap[392] = r42 + 2052; } } @@ -1274,28 +1262,25 @@ void ContinueInitPauseMenu(void) { // 0x829009 } void SetupMapScrollingForFileSelectMap(void) { // 0x829028 - int16 v0; - int16 v1; - ResetPauseMenuAnimations(); DetermineMapScrollLimits(); reg_BG1HOFS = map_min_x_scroll + ((uint16)(map_max_x_scroll - map_min_x_scroll) >> 1) - 128; - R18_ = 8 * (room_x_coordinate_on_map + (uint8)((uint16)(samus_x_pos & 0xFF00) >> 8)) - reg_BG1HOFS; - v0 = 224 - R18_; - if ((int16)(224 - R18_) >= 0) { - R18_ = 32 - R18_; - if ((R18_ & 0x8000u) == 0) - reg_BG1HOFS -= R18_; + uint16 r18 = 8 * (room_x_coordinate_on_map + ((samus_x_pos & 0xFF00) >> 8)) - reg_BG1HOFS; + int16 v0 = 224 - r18; + if ((int16)(224 - r18) >= 0) { + r18 = 32 - r18; + if ((r18 & 0x8000) == 0) + reg_BG1HOFS -= r18; } else { - R18_ = 224 - R18_; + r18 = 224 - r18; reg_BG1HOFS -= v0; } - R18_ = map_min_y_scroll + ((uint16)(map_max_y_scroll - map_min_y_scroll) >> 1) + 16; - reg_BG1VOFS = -((112 - R18_) & 0xFFF8); - R18_ = 8 * (room_y_coordinate_on_map + HIBYTE(samus_y_pos) + 1) + ((112 - R18_) & 0xFFF8); - v1 = 64 - R18_; - if ((int16)(64 - R18_) >= 0) { - R18_ = 64 - R18_; + r18 = map_min_y_scroll + ((uint16)(map_max_y_scroll - map_min_y_scroll) >> 1) + 16; + reg_BG1VOFS = -((112 - r18) & 0xFFF8); + r18 = 8 * (room_y_coordinate_on_map + HIBYTE(samus_y_pos) + 1) + ((112 - r18) & 0xFFF8); + int16 v1 = 64 - r18; + if ((int16)(64 - r18) >= 0) { + r18 = 64 - r18; reg_BG1VOFS -= v1; if (sign16(reg_BG1VOFS + 40)) reg_BG1VOFS = -40; @@ -1479,7 +1464,7 @@ void MapScrolling_1_Left(void) { void MapScrolling_Common(void) { // 0x829299 ++map_scrolling_speed_index; if ((++map_scrolling_speed_index & 0xF) == 0) { - QueueSfx1_Max6(0x36u); + QueueSfx1_Max6(0x36); map_scrolling_direction = 0; map_scrolling_speed_index = 0; if (map_scrolling_gear_switch_timer) @@ -1564,11 +1549,11 @@ void LoadPauseMenuMapTilemapAndAreaLabel(void) { // 0x8293C3 LoadPauseMenuMapTilemap(); static const StartDmaCopy unk_8293E9 = { 1, 1, 0x18, LONGPTR(0x7e4000), 0x1000 }; SetupDmaTransfer(&unk_8293E9); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0xAA); WriteReg(VMADDH, 0x38); WriteReg(VMAIN, 0x80); - WriteReg(DMAP1, 1u); + WriteReg(DMAP1, 1); WriteReg(BBAD1, 0x18); WriteReg(DAS1L, 0x18); WriteReg(DAS1H, 0); @@ -1577,73 +1562,70 @@ void LoadPauseMenuMapTilemapAndAreaLabel(void) { // 0x8293C3 v0 = 0; WriteRegWord(A1T1L, kPauseAreaLabelTilemap[v0]); WriteReg(A1B1, 0x82); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } void LoadPauseMenuMapTilemap(void) { // 0x82943D - uint16 v6; int16 v9; - + uint16 r18, r38, r40; + LongPtr r0, r3, r6, r9; uint16 v0 = area_index; if (!sign16(area_index - 7)) v0 = 0; - R18_ = v0; - R0_.addr = *(VoidP *)((uint8 *)&kPauseMenuMapTilemaps[0].addr + (uint16)(3 * v0)); - *(uint16 *)&R0_.bank = *(uint16 *)(&kPauseMenuMapTilemaps[0].bank + (uint16)(3 * v0)); - R3_.addr = ADDR16_OF_RAM(ram4000); - *(uint16 *)&R3_.bank = 126; - R6_.bank = 130; - R6_.addr = kPauseMenuMapData[v0]; + r18 = v0; + r0 = kPauseMenuMapTilemaps[v0]; + r3.addr = ADDR16_OF_RAM(ram4000); + r3.bank = 126; + r6.addr = kPauseMenuMapData[v0]; + r6.bank = 130; if (map_station_byte_array[area_index]) { - R38 = swap16(IndirReadWord(R6_, 0)); - R6_.addr += 2; - v6 = ADDR16_OF_RAM(*map_tiles_explored); - R9_.bank = 0; - R9_.addr = v6; - R40 = swap16(IndirReadWord(R9_, 0)); - R9_.addr += 2; + r38 = swap16(IndirReadWord(r6, 0)); + r6.addr += 2; + r9.bank = 0; + r9.addr = ADDR16_OF_RAM(*map_tiles_explored); + r40 = swap16(IndirReadWord(r9, 0)); + r9.addr += 2; uint16 v8 = 0; v9 = 16; do { - uint16 v10 = IndirReadWord(R0_, v8); - bool v11 = R40 >> 15; - R40 *= 2; + uint16 v10 = IndirReadWord(r0, v8); + bool v11 = r40 >> 15; + r40 *= 2; if (v11) { - v10 &= ~0x400u; - R38 *= 2; + v10 &= ~0x400; + r38 *= 2; } else { - v11 = R38 >> 15; - R38 *= 2; + v11 = r38 >> 15; + r38 *= 2; if (!v11) v10 = 31; } - IndirWriteWord(R3_, v8, v10); + IndirWriteWord(r3, v8, v10); if (!--v9) { v9 = 16; - R38 = swap16(IndirReadWord(R6_, 0)); - R6_.addr += 2; - R40 = swap16(IndirReadWord(R9_, 0)); - R9_.addr += 2; + r38 = swap16(IndirReadWord(r6, 0)); + r6.addr += 2; + r40 = swap16(IndirReadWord(r9, 0)); + r9.addr += 2; } v8 += 2; } while ((int16)(v8 - 4096) < 0); } else { uint16 v1 = 0; uint16 v2 = 0; - LOBYTE(R18_) = 0; + uint8 r18 = 0; while (1) { uint8 t = map_tiles_explored[v2]; map_tiles_explored[v2] <<= 1; if (!(t & 0x80)) { - IndirWriteWord(R3_, v1, 0x1F); + IndirWriteWord(r3, v1, 0x1F); } else { ++map_tiles_explored[v2]; - IndirWriteWord(R3_, v1, IndirReadWord(R0_, v1) & 0xFBFF); + IndirWriteWord(r3, v1, IndirReadWord(r0, v1) & 0xFBFF); } v1 += 2; - LOBYTE(R18_) = R18_ + 1; - if (!sign8(R18_ - 8)) { - LOBYTE(R18_) = 0; + if (++r18 >= 8) { + r18 = 0; if ((int16)(++v2 - 256) >= 0) break; } @@ -1652,10 +1634,11 @@ void LoadPauseMenuMapTilemap(void) { // 0x82943D } void DrawRoomSelectMap(void) { // 0x829517 - uint16 v3; // r8 unsigned int v7; // kr00_4 int16 v10; VramWriteEntry *v17; + LongPtr r0, r3, r6, r9; + uint16 r38, r40; reg_BG12NBA = 51; reg_TM = 19; @@ -1663,65 +1646,61 @@ void DrawRoomSelectMap(void) { // 0x829517 uint16 v0 = area_index; if (!sign16(area_index - 7)) v0 = 0; - R18_ = v0; - R0_.addr = *(VoidP *)((uint8 *)&kPauseMenuMapTilemaps[0].addr + (uint16)(3 * v0)); - *(uint16 *)&R0_.bank = *(uint16 *)(&kPauseMenuMapTilemaps[0].bank + (uint16)(3 * v0)); - R3_.addr = ADDR16_OF_RAM(ram3000); - R3_.bank = 126; - R6_.bank = 130; - R6_.addr = kPauseMenuMapData[v0]; + r0 = kPauseMenuMapTilemaps[v0]; + r3.addr = ADDR16_OF_RAM(ram3000); + r3.bank = 126; + r6.bank = 130; + r6.addr = kPauseMenuMapData[v0]; if (map_station_byte_array[area_index]) { - R38 = swap16(IndirReadWord(R6_, 0)); - ++R6_.addr; - ++R6_.addr; + r38 = swap16(IndirReadWord(r6, 0)); + r6.addr += 2; v7 = 2039; - R9_.bank = HIWORD(v7); - R9_.addr = v7; - R40 = swap16(IndirReadWord(R9_, 0)); - R9_.addr += 2; + r9.bank = HIWORD(v7); + r9.addr = v7; + r40 = swap16(IndirReadWord(r9, 0)); + r9.addr += 2; uint16 v9 = 0; v10 = 16; do { - uint16 v11 = IndirReadWord(R0_, v9); - bool v12 = R40 >> 15; - R40 *= 2; + uint16 v11 = IndirReadWord(r0, v9); + bool v12 = r40 >> 15; + r40 *= 2; if (v12) { - v11 &= ~0x400u; - R38 *= 2; + v11 &= ~0x400; + r38 *= 2; } else { - v12 = R38 >> 15; - R38 *= 2; + v12 = r38 >> 15; + r38 *= 2; if (!v12) v11 = 31; } - IndirWriteWord(R3_, v9, v11); + IndirWriteWord(r3, v9, v11); if (!--v10) { v10 = 16; - R38 = swap16(IndirReadWord(R6_, 0)); - R6_.addr += 2; - R40 = swap16(IndirReadWord(R9_, 0)); - R9_.addr += 2; + r38 = swap16(IndirReadWord(r6, 0)); + r6.addr += 2; + r40 = swap16(IndirReadWord(r9, 0)); + r9.addr += 2; } v9 += 2; } while ((int16)(v9 - 4096) < 0); } else { uint16 v1 = 0; uint16 v2 = 0; - LOBYTE(R18_) = 0; + uint8 r18 = 0; while (1) { uint8 what = map_tiles_explored[v2]; map_tiles_explored[v2] <<= 1; if (!(what & 0x80)) { - IndirWriteWord(R3_, v1, 0xF); + IndirWriteWord(r3, v1, 0xF); } else { ++map_tiles_explored[v2]; - IndirWriteWord(R3_, v1, IndirReadWord(R0_, v1) & ~0x400); + IndirWriteWord(r3, v1, IndirReadWord(r0, v1) & ~0x400); } v1 += 2; - LOBYTE(R18_) = R18_ + 1; - LOBYTE(v3) = R18_ - 8; - if (!(uint8)sign8(v3)) { - LOBYTE(R18_) = 0; + r18++; + if (!sign8(r18 - 8)) { + r18 = 0; if ((int16)(++v2 - 256) >= 0) break; } @@ -1731,98 +1710,64 @@ void DrawRoomSelectMap(void) { // 0x829517 v17 = gVramWriteEntry(vram_write_queue_tail); v17->size = 4096; v17->src.addr = ADDR16_OF_RAM(ram3000); - *(uint16 *)&v17->src.bank = 126; + v17->src.bank = 126; v17->vram_dst = (reg_BG1SC & 0xFC) << 8; vram_write_queue_tail = v16 + 7; } -void DrawRoomSelectMapAreaLabel(void) { // 0x829628 +void DrawRoomSelectMapAreaLabel(LongPtr r0) { // 0x829628 const uint8 *v2 = RomPtr_82(kPauseAreaLabelTilemap[area_index]); for(int i = 0; i < 24; i += 2) - IndirWriteWord(R0_, i, *(uint16 *)(v2 + i) & 0xEFFF); + IndirWriteWord(r0, i, *(uint16 *)(v2 + i) & 0xEFFF); } void SetupMapScrollingForPauseMenu(uint16 a) { // 0x829E27 int16 v1; int16 v2; - R20_ = a; reg_BG1HOFS = map_min_x_scroll + ((uint16)(map_max_x_scroll - map_min_x_scroll) >> 1) - 128; - R18_ = 8 * (room_x_coordinate_on_map + (uint8)((uint16)(samus_x_pos & 0xFF00) >> 8)) - reg_BG1HOFS; - v1 = 224 - R18_; - if ((int16)(224 - R18_) >= 0) { - R18_ = 32 - R18_; - if ((R18_ & 0x8000u) == 0) - reg_BG1HOFS -= R18_; + uint16 r18 = 8 * (room_x_coordinate_on_map + ((samus_x_pos & 0xFF00) >> 8)) - reg_BG1HOFS; + v1 = 224 - r18; + if ((int16)(224 - r18) >= 0) { + r18 = 32 - r18; + if ((r18 & 0x8000) == 0) + reg_BG1HOFS -= r18; } else { - R18_ = 224 - R18_; + r18 = 224 - r18; reg_BG1HOFS -= v1; } - R18_ = map_min_y_scroll + ((uint16)(map_max_y_scroll - map_min_y_scroll) >> 1) + 16; - reg_BG1VOFS = -((R20_ - R18_) & 0xFFF8); - R18_ = 8 * (room_y_coordinate_on_map + HIBYTE(samus_y_pos) + 1) + ((R20_ - R18_) & 0xFFF8); - v2 = 64 - R18_; - if ((int16)(64 - R18_) >= 0) { - R18_ = 64 - R18_; + r18 = map_min_y_scroll + ((uint16)(map_max_y_scroll - map_min_y_scroll) >> 1) + 16; + reg_BG1VOFS = -((a - r18) & 0xFFF8); + r18 = 8 * (room_y_coordinate_on_map + HIBYTE(samus_y_pos) + 1) + ((a - r18) & 0xFFF8); + v2 = 64 - r18; + if ((int16)v2 >= 0) { reg_BG1VOFS -= v2; if (sign16(reg_BG1VOFS + 40)) reg_BG1VOFS = -40; } } -void DetermineMapScrollLimits(void) { // 0x829EC4 - if (has_area_map) { - R6_.bank = 130; - R6_.addr = addr_kPauseMenuMapData; - R6_.addr = IndirReadWord(R6_, 2 * area_index); - } else { - R6_.bank = 0; - R6_.addr = 2039; - } - R0_.bank = R6_.bank; - R0_.addr = R6_.addr; - uint16 v0 = DetermineLeftmostMapColumn(); - map_min_x_scroll = MultiplyBy8(v0); - if (area_index == 4) - map_min_x_scroll -= 24; - R0_.addr = R6_.addr + 131; - uint16 v1 = DetermineRightmostMapColumn(); - map_max_x_scroll = MultiplyBy8(v1); - R0_.addr = R6_.addr; - uint16 v2 = DetermineTopmostMapColumn(); - map_min_y_scroll = MultiplyBy8(v2); - R0_.addr = R6_.addr + 124; - uint16 v3 = DetermineBottommostMapColumn(); - map_max_y_scroll = MultiplyBy8(v3); -} - -uint16 MultiplyBy8(uint16 k) { // 0x829F45 - return 8 * k; -} -static const uint8 k0x80Shr[8] = { // 0x829F4A - 0x80, 0x40, 0x20, 0x10, - 8, 4, 2, 1, -}; +static const uint8 k0x80Shr[8] = { 0x80, 0x40, 0x20, 0x10, 8, 4, 2, 1, }; static const uint8 k0x80Shr_0[8] = { 0x80, 0x40, 0x20, 0x10, 8, 4, 2, 1 }; -uint16 DetermineLeftmostMapColumn(void) { + +static uint16 DetermineLeftmostMapColumn(LongPtr r0) { uint16 v0; - HIBYTE(v0) = 0; uint16 result = 0; LABEL_2: - LOBYTE(v0) = result & 7; - LOBYTE(R18_) = k0x80Shr[v0]; + v0 = result & 7; + uint8 r18 = k0x80Shr[v0]; uint16 v2 = 0; - while (((uint8)R18_ & IndirReadByte(R0_, v2)) == 0) { + while ((r18 & IndirReadByte(r0, v2)) == 0) { v2 += 4; if ((int16)(v2 - 128) >= 0) { if ((int16)(++result - 64) >= 0) return 26; if ((result & 7) == 0) { - R0_.addr += 1; + r0.addr += 1; } if (result == 32) { - R0_.addr += 123; + r0.addr += 123; } goto LABEL_2; } @@ -1830,38 +1775,37 @@ LABEL_2: return result; } -uint16 DetermineRightmostMapColumn(void) { // 0x829FA9 +static uint16 DetermineRightmostMapColumn(LongPtr r0) { // 0x829FA9 uint16 result = 63; -LABEL_2: - LOBYTE(R18_) = k0x80Shr_0[result & 7]; +LABEL_2:; + uint8 r18 = k0x80Shr_0[result & 7]; uint16 v1 = 0; - while (((uint8)R18_ & IndirReadByte(R0_, v1)) == 0) { + while ((r18 & IndirReadByte(r0, v1)) == 0) { v1 += 4; if ((int16)(v1 - 128) >= 0) { - if ((--result & 0x8000u) != 0) + if ((--result & 0x8000) != 0) return 28; if ((result & 7) == 7) { - bool v2 = LOBYTE(R0_.addr)-- != 0; - HIBYTE(R0_.addr) -= !v2; + bool v2 = LOBYTE(r0.addr)-- != 0; + HIBYTE(r0.addr) -= !v2; } if (result == 31) - R0_.addr -= 124; + r0.addr -= 124; goto LABEL_2; } } return result; } -uint16 DetermineTopmostMapColumn(void) { // 0x82A009 - R3_.addr = R0_.addr + 128; - R3_.bank = R0_.bank; +static uint16 DetermineTopmostMapColumn(LongPtr r0) { // 0x82A009 + LongPtr r3 = (LongPtr){ r0.addr + 128, r0.bank }; uint16 result = 0; uint16 v1 = 0; - while (!IndirReadByte(R0_, v1) && !IndirReadByte(R3_, v1)) { + while (!IndirReadByte(r0, v1) && !IndirReadByte(r3, v1)) { if ((int16)(++v1 - 4) >= 0) { v1 = 0; - R0_.addr += 4; - R3_.addr += 4; + r0.addr += 4; + r3.addr += 4; if ((int16)(++result - 31) >= 0) return 1; } @@ -1869,16 +1813,15 @@ uint16 DetermineTopmostMapColumn(void) { // 0x82A009 return result; } -uint16 DetermineBottommostMapColumn(void) { // 0x82A053 - R3_.addr = R0_.addr + 128; - R3_.bank = R0_.bank; +static uint16 DetermineBottommostMapColumn(LongPtr r0) { // 0x82A053 + LongPtr r3 = (LongPtr){ r0.addr + 128, r0.bank }; uint16 result = 31; uint16 v1 = 0; - while (!IndirReadByte(R0_, v1) && !IndirReadByte(R3_, v1)) { + while (!IndirReadByte(r0, v1) && !IndirReadByte(r3, v1)) { if ((int16)(++v1 - 4) >= 0) { v1 = 0; - R0_.addr -= 4; - R3_.addr -= 4; + r0.addr -= 4; + r3.addr -= 4; if (!--result) return 11; } @@ -1886,15 +1829,33 @@ uint16 DetermineBottommostMapColumn(void) { // 0x82A053 return result; } +void DetermineMapScrollLimits(void) { // 0x829EC4 + LongPtr r6; + if (has_area_map) { + r6.bank = 130; + r6.addr = addr_kPauseMenuMapData; + r6.addr = IndirReadWord(r6, 2 * area_index); + } else { + r6.bank = 0; + r6.addr = 2039; + } + map_min_x_scroll = DetermineLeftmostMapColumn(r6) * 8; + if (area_index == 4) + map_min_x_scroll -= 24; + map_max_x_scroll = DetermineRightmostMapColumn((LongPtr) { r6.addr + 131, r6.bank }) * 8; + map_min_y_scroll = DetermineTopmostMapColumn((LongPtr) { r6.addr, r6.bank }) * 8; + map_max_y_scroll = DetermineBottommostMapColumn((LongPtr) { r6.addr + 124, r6.bank }) * 8; +} + void SetupPpuForPauseMenu(void) { // 0x82A09A - WriteReg(OBSEL, 1u); + WriteReg(OBSEL, 1); reg_OBSEL = 1; - WriteReg(BGMODE, 9u); + WriteReg(BGMODE, 9); reg_BGMODE = 9; reg_BG12NBA = 0; WriteReg(BG12NBA, 0); reg_BG34NBA = 4; - WriteReg(BG34NBA, 4u); + WriteReg(BG34NBA, 4); reg_BG1SC = 49; WriteReg(BG1SC, 0x31); reg_BG2SC = 56; @@ -1907,9 +1868,9 @@ void SetupPpuForPauseMenu(void) { // 0x82A09A reg_TM = 23; WriteReg(MOSAIC, 0); reg_MOSAIC = 0; - reg_COLDATA[0] &= 0xE0u; - reg_COLDATA[1] &= 0xE0u; - reg_COLDATA[2] &= 0xE0u; + reg_COLDATA[0] &= 0xE0; + reg_COLDATA[1] &= 0xE0; + reg_COLDATA[2] &= 0xE0; next_gameplay_CGADSUB = 0; } @@ -1930,118 +1891,59 @@ void ResetPauseMenuAnimations(void) { // 0x82A0F7 pausemenu_palette_animation_timer = 1; pausemenu_palette_animation_frame = 0; } + +static void ChangePaletteValues(uint16 *target, uint16 new_color, size_t n) { // 0x82A29D + for (size_t i = 0; i != n; i++) + target[i] = target[i] & ~0x1C00 | new_color; +} + void LoadEquipmentScreenEquipmentTilemaps(void) { // 0x82A12B if (samus_max_reserve_health) { - R3_.addr = addr_kEquipmentTilemapOffs_Tanks; - *(uint16 *)&R3_.bank = 130; - R0_.addr = IndirReadWord(R3_, 0); - R22_ = 14; - Copy_R22_Bytes(kEquipmentTilemaps_Tanks[0]); - R3_.addr = addr_kEquipmentTilemapOffs_Tanks; - *(uint16 *)&R3_.bank = 130; - R0_.addr = IndirReadWord(R3_, 2u); - R22_ = 14; - Copy_R22_Bytes(kEquipmentTilemaps_Tanks[1]); + memcpy(g_ram + kEquipmentTilemapOffs_Tanks[0], RomPtr_82(kEquipmentTilemaps_Tanks[0]), 14); + memcpy(g_ram + kEquipmentTilemapOffs_Tanks[1], RomPtr_82(kEquipmentTilemaps_Tanks[1]), 14); } - uint16 v0 = 0; - R3_.addr = addr_kEquipmentTilemapOffs_Weapons; - *(uint16 *)&R3_.bank = 130; - R0_.addr = IndirReadWord(R3_, 0); + const uint16 *p = (uint16*)RomPtr_82(addr_kEquipmentTilemapOffs_Weapons); if (hyper_beam_flag) { - uint16 v3 = 0; - do { - uint16 v4 = kHyperBeamWeaponsTilemaps[v3 >> 1]; - R22_ = 10; - Copy_R22_Bytes(v4); - v3 += 2; - R0_.addr = IndirReadWord(R3_, v3); - } while ((int16)(v3 - 10) < 0); + for(int i = 0; i < 5; i++) + memcpy(g_ram + p[i], RomPtr_82(kHyperBeamWeaponsTilemaps[i]), 10); } else { - do { - int v1 = v0 >> 1; - if ((collected_beams & kEquipmentBitmasks_Weapons[v1]) != 0) { - uint16 v2 = kEquipmentTilemaps_Weapons[v1]; - R22_ = 10; - Copy_R22_Bytes(v2); - if ((equipped_beams & kEquipmentBitmasks_Weapons[v1]) == 0) { - R18_ = 3072; - R22_ = 10; - SetPaletteOfR22TilemapBytesToR18(); - } + for (int i = 0; i < 6; i++) { + uint16 *target = (uint16 *)(g_ram + p[i]); + if ((collected_beams & kEquipmentBitmasks_Weapons[i]) != 0) { + memcpy(target, RomPtr_82(kEquipmentTilemaps_Weapons[i]), 10); + if ((equipped_beams & kEquipmentBitmasks_Weapons[i]) == 0) + ChangePaletteValues(target, 3072, 5); } else { - R22_ = 10; - Copy_R22_Bytes(addr_kEquipmentScreenTilemap_Blank); + memcpy(target, RomPtr_82(addr_kEquipmentScreenTilemap_Blank), 10); } - v0 += 2; - R0_.addr = IndirReadWord(R3_, v0); - } while ((int16)(v0 - 12) < 0); + } } - uint16 v5 = 0; - R3_.addr = addr_kEquipmentTilemapOffs_Suits; - *(uint16 *)&R3_.bank = 130; - R0_.addr = IndirReadWord(R3_, 0); - do { - int v6 = v5 >> 1; - if ((collected_items & kEquipmentBitmasks_Suits[v6]) != 0) { - uint16 v7 = kEquipmentTilemaps_Suits[v6]; - R22_ = 18; - Copy_R22_Bytes(v7); - if ((equipped_items & kEquipmentBitmasks_Suits[v6]) == 0) { - R18_ = 3072; - R22_ = 18; - SetPaletteOfR22TilemapBytesToR18(); - } + + p = (uint16*)RomPtr_82(addr_kEquipmentTilemapOffs_Suits); + for(int i = 0; i < 6; i++) { + uint16 *target = (uint16*)(g_ram + p[i]); + if ((collected_items & kEquipmentBitmasks_Suits[i]) != 0) { + memcpy(target, RomPtr_82(kEquipmentTilemaps_Suits[i]), 18); + if ((equipped_items & kEquipmentBitmasks_Suits[i]) == 0) + ChangePaletteValues(target, 3072, 9); } else { - R22_ = 18; - Copy_R22_Bytes(addr_kEquipmentScreenTilemap_Blank); + memcpy(target, RomPtr_82(addr_kEquipmentScreenTilemap_Blank), 18); } - v5 += 2; - R0_.addr = IndirReadWord(R3_, v5); - } while ((int16)(v5 - 12) < 0); - uint16 v8 = 0; - R3_.addr = addr_kEquipmentTilemapOffs_Boots; - *(uint16 *)&R3_.bank = 130; - R0_.addr = IndirReadWord(R3_, 0); - do { - int v9 = v8 >> 1; - if ((collected_items & kEquipmentBitmasks_Boots[v9]) != 0) { - R22_ = 18; - Copy_R22_Bytes(kEquipmentTilemaps_Boots[v9]); - if ((equipped_items & kEquipmentBitmasks_Boots[v9]) == 0) { - R18_ = 3072; - R22_ = 18; - SetPaletteOfR22TilemapBytesToR18(); - } + } + + p = (uint16*)RomPtr_82(addr_kEquipmentTilemapOffs_Boots); + for (int i = 0; i < 3; i++) { + uint16 *target = (uint16*)(g_ram + p[i]); + if ((collected_items & kEquipmentBitmasks_Boots[i]) != 0) { + memcpy(target, RomPtr_82(kEquipmentTilemaps_Boots[i]), 18); + if ((equipped_items & kEquipmentBitmasks_Boots[i]) == 0) + ChangePaletteValues(target, 3072, 9); } else { - R22_ = 18; - Copy_R22_Bytes(addr_kEquipmentScreenTilemap_Blank); + memcpy(target, RomPtr_82(addr_kEquipmentScreenTilemap_Blank), 18); } - v8 += 2; - R0_.addr = IndirReadWord(R3_, v8); - } while ((int16)(v8 - 6) < 0); + } } -void Copy_R22_Bytes(uint16 k) { // 0x82A27E - R0_.bank = 0x7E; - uint16 v1 = 0; - do { - const uint16 *v2 = (const uint16 *)RomPtr_82(k); - IndirWriteWord(R0_, v1, *v2); - k += 2; - v1 += 2; - R22_ -= 2; - } while (R22_); -} - -void SetPaletteOfR22TilemapBytesToR18(void) { // 0x82A29D - R0_.bank = 0x7E; - uint16 v0 = 0; - do { - IndirWriteWord(R0_, v0, R18_ | IndirReadWord(R0_, v0) & 0xE3FF); - v0 += 2; - R22_ -= 2; - } while (R22_); -} void ClearSamusBeamTiles(void) { // 0x82A2BE WriteReg(VMADDL, 0); @@ -2049,7 +1951,7 @@ void ClearSamusBeamTiles(void) { // 0x82A2BE WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_82A2D4 = { 1, 1, 0x18, LONGPTR(0x9ad200), 0x1000 }; SetupDmaTransfer(&unk_82A2D4); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } void ContinueInitGameplayResume(void) { // 0x82A2E3 @@ -2066,18 +1968,18 @@ void ContinueInitGameplayResume(void) { // 0x82A2E3 CalculateBgScrolls_Unpause(); UpdateBeamTilesAndPalette_Unpause(); ClearPauseMenuData(); - CallSomeSamusCode(0xCu); + CallSomeSamusCode(0xC); } void SetupPpuForGameplayResume(void) { // 0x82A313 - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; - WriteReg(BGMODE, 9u); + WriteReg(BGMODE, 9); reg_BGMODE = 9; reg_BG12NBA = 0; WriteReg(BG12NBA, 0); reg_BG34NBA = 4; - WriteReg(BG34NBA, 4u); + WriteReg(BG34NBA, 4); reg_BG1SC = 81; WriteReg(BG1SC, 0x51); reg_BG2SC = 73; @@ -2198,7 +2100,7 @@ void HandlePauseScreenLrInput(void) { // 0x82A50C pausemenu_button_label_mode = 2; SetPauseScreenButtonLabelPalettes(); LABEL_7: - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); } } static const uint16 kPauseLrButtonPressedHighlight_Spritemap[2] = { 0x28, 0x29 }; @@ -2208,24 +2110,23 @@ void HandlePauseMenuLRPressHighlight(void) { // 0x82A56D if (pausemenu_start_lr_pressed_highlight_timer) { --pausemenu_start_lr_pressed_highlight_timer; if (pausemenu_shoulder_button_highlight) { - R3_.addr = 0; int v0 = pausemenu_shoulder_button_highlight - 1; DrawMenuSpritemap( kPauseLrButtonPressedHighlight_Spritemap[v0], kPauseLrButtonPressedHighlight_Y[v0], - kPauseLrButtonPressedHighlight_X[v0] - 1); + kPauseLrButtonPressedHighlight_X[v0] - 1, 0); } } } void DrawLrHighlight(void) { // 0x82A59A - DrawPauseScreenSpriteAnim(2u, 0x18, 0xD0); - DrawPauseScreenSpriteAnim(2u, 0xE8, 0xD0); + DrawPauseScreenSpriteAnim(2, 0x18, 0xD0); + DrawPauseScreenSpriteAnim(2, 0xE8, 0xD0); } void HandlePauseScreenStart(void) { // 0x82A5B7 if ((newly_held_down_timed_held_input & kButton_Start) != 0) { - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); screen_fade_delay = 1; screen_fade_counter = 1; uint16 v0 = pausemenu_button_label_mode; @@ -2241,8 +2142,7 @@ void HandlePauseScreenStart(void) { // 0x82A5B7 void HighlightPauseScreenButton(void) { // 0x82A5F1 if (pausemenu_start_lr_pressed_highlight_timer) { --pausemenu_start_lr_pressed_highlight_timer; - R3_.addr = 0; - DrawMenuSpritemap(0x2B, 0x90, 0xD0); + DrawMenuSpritemap(0x2B, 0x90, 0xD0, 0); } } static Func_V *const kSetPauseScreenButtonLabelPalettes_Funcs[3] = { // 0x82A615 @@ -2434,11 +2334,11 @@ void DrawPauseScreenSpriteAnim(uint16 a, uint16 input_k, uint16 input_j) { // 0 } *v5 = v10; } - R3_.addr = kPAuseSpritePaletteIndexValues[3]; + uint16 r3 = kPAuseSpritePaletteIndexValues[3]; int r24 = v3[3 * *v8 + 2]; int r26 = 2 * *RomPtr_RAM(kPauseScreenSpriteAnimationData_2.arr[t]); const uint8 *v11 = RomPtr_82(r26 + kPausePtsToAnimationSpritemapBaseIds[t]); - DrawMenuSpritemap(r24 + GET_WORD(v11), input_k, input_j - 1); + DrawMenuSpritemap(r24 + GET_WORD(v11), input_k, input_j - 1, r3); } void HandlePauseScreenPaletteAnimation(void) { // 0x82A92B uint16 v2; @@ -2450,16 +2350,16 @@ void HandlePauseScreenPaletteAnimation(void) { // 0x82A92B if (!(uint8)pausemenu_palette_animation_timer) { for (int i = pausemenu_palette_animation_frame + 1; ; i = 0) { LOBYTE(pausemenu_palette_animation_frame) = i; - v1 = kPauseLrHighlightAnimData[(uint8)(3 * i)]; + v1 = kPauseLrHighlightAnimData[3 * i]; if (v1 != 0xFF) break; - QueueSfx3_Max6(0x2Au); + QueueSfx3_Max6(0x2A); } LOBYTE(pausemenu_palette_animation_timer) = v1; LOBYTE(v2) = 0; HIBYTE(v2) = pausemenu_palette_animation_frame; uint16 v3 = (v2 >> 3) + 30; - for (j = 30; (j & 0x8000u) == 0; j -= 2) { + for (j = 30; (j & 0x8000) == 0; j -= 2) { palette_buffer[(j >> 1) + 176] = kPauseAnimatedPalette[v3 >> 1]; v3 -= 2; } @@ -2468,7 +2368,6 @@ void HandlePauseScreenPaletteAnimation(void) { // 0x82A92B } void EquipmentScreenSetupReserveMode(void) { // 0x82AB47 VoidP v0; - int16 v3; int16 v5; int16 v7; int16 v8; @@ -2481,18 +2380,9 @@ void EquipmentScreenSetupReserveMode(void) { // 0x82AB47 v0 = addr_kEquipmentScreenTilemap_AUTO; if (reserve_health_mode != 1) v0 = addr_kEquipmentScreenTilemap_MANUAL; - *(uint16 *)&R0_.bank = 130; - R0_.addr = v0; - R18_ = 4; - uint16 v1 = 0; - uint16 v2 = 0; - do { - v3 = ram3800.cinematic_bg_tilemap[v1 + 327] & 0xFC00; - ram3800.cinematic_bg_tilemap[v1 + 327] = IndirReadWord(R0_, v2) | v3; - v2 += 2; - ++v1; - --R18_; - } while (R18_); + uint16 *table = (uint16 *)RomPtr_82(v0); + for (int i = 0; i < 4; i++) + ram3800.cinematic_bg_tilemap[i + 327] = ram3800.cinematic_bg_tilemap[i + 327] & 0xFC00 | table[i]; } pausemenu_item_selector_animation_frame = 0; pausemenu_item_selector_animation_timer = kPauseLrHighlightAnimData[0]; @@ -2540,7 +2430,7 @@ void EquipmentScreenTransferBG1Tilemap(void) { // 0x82AC22 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_82AC3B = { 1, 1, 0x18, LONGPTR(0x7e3800), 0x0800 }; SetupDmaTransfer(&unk_82AC3B); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); reg_BG1VOFS = 0; } static Func_V *const kEquipmentScreenCategories[4] = { // 0x82AC4F @@ -2566,22 +2456,22 @@ void EquipmentScreenCategory_Tanks(void) { } void EquipmentScreenHandleDpad(void) { // 0x82AC8B - R18_ = pausemenu_equipment_category_item; + uint16 r18 = pausemenu_equipment_category_item; if ((joypad1_newkeys & kButton_Right) != 0) { if ((joypad1_newkeys & kButton_Down) != 0 || EquipmentScreenMoveLowerOnSuitsMisc(0) == 0xFFFF) - EquipmentScreenMoveToHighJumpOrLowerInBoots(0); + EquipmentScreenMoveToHighJumpOrLowerInBoots(0, r18); } else if ((joypad1_newkeys & kButton_Up) != 0) { if ((pausemenu_equipment_category_item & 0xFF00) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); pausemenu_equipment_category_item -= 256; } } else if ((joypad1_newkeys & kButton_Down) != 0) { if ((pausemenu_equipment_category_item & 0xFF00) == 256 || reserve_health_mode == 1 || (pausemenu_equipment_category_item += 256, !samus_reserve_health)) { - EquipmentScreenMoveToBeams(0); + EquipmentScreenMoveToBeams(0, r18); } else { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); } } } @@ -2697,7 +2587,7 @@ void EquipmentScreenCategory_Tanks_0(void) { int16 v2; if ((joypad1_newkeys & kButton_A) != 0 && samus_max_reserve_health) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); if (reserve_health_mode == 1) { reserve_health_mode = 2; EquipmentScreenHudReserveAutoTilemap_Off(); @@ -2752,7 +2642,7 @@ void EquipmentScreenCategory_Tanks_1(void) { // 0x82AF4F pausemenu_reserve_tank_delay_ctr = (samus_reserve_health + 7) & 0xFFF8; } if ((--pausemenu_reserve_tank_delay_ctr & 7) == 7) - QueueSfx3_Max6(0x2Du); + QueueSfx3_Max6(0x2D); samus_health += kReserveTankEnergyTransferPerFrame; if ((int16)(samus_health - samus_max_health) < 0) { samus_reserve_health -= kReserveTankEnergyTransferPerFrame; @@ -2770,114 +2660,106 @@ void EquipmentScreenCategory_Tanks_1(void) { // 0x82AF4F void EquipmentScreenCategory_Weapons(void) { // 0x82AFBE EquipmentScreenCategory_Weapons_MoveButtons(); - R36 = equipped_beams; + uint16 R36 = equipped_beams; if (collected_beams) { - R24_ = 10; // Fixed var bug if ((uint8)pausemenu_equipment_category_item == 1) { - EquipmentScreenCategory_ButtonResponse(); - EquipmentScreenCategory_Weapons_PlazmaSpazerCheck(); + EquipmentScreenCategory_ButtonResponse(10); + EquipmentScreenCategory_Weapons_PlazmaSpazerCheck(R36); } } } void EquipmentScreenCategory_Weapons_MoveButtons(void) { // 0x82AFDB - R18_ = pausemenu_equipment_category_item; + uint16 r18 = pausemenu_equipment_category_item; if ((joypad1_newkeys & 0x100) != 0) { if ((joypad1_newkeys & 0x800) != 0) { EquipmentScreenMoveLowerOnSuitsMisc(0); - } else if (EquipmentScreenMoveLowerOnSuitsMisc(4u)) { - EquipmentScreenMoveToHighJumpOrLowerInBoots(0); + } else if (EquipmentScreenMoveLowerOnSuitsMisc(4)) { + EquipmentScreenMoveToHighJumpOrLowerInBoots(0, r18); } } else if ((joypad1_newkeys & 0x400) != 0) { if (!hyper_beam_flag && pausemenu_equipment_category_item != 1025) { pausemenu_equipment_category_item += 256; - EquipmentScreenMoveToBeams(2 * HIBYTE(pausemenu_equipment_category_item)); + EquipmentScreenMoveToBeams(2 * HIBYTE(pausemenu_equipment_category_item), r18); } } else if ((joypad1_newkeys & 0x800) != 0) { if ((pausemenu_equipment_category_item & 0xFF00) == 0 || (pausemenu_equipment_category_item -= 256, EquipmentScreenMoveToBottomOfBeams(2 * HIBYTE(pausemenu_equipment_category_item)) == 0xFFFF)) { if (!EquipmentScreenMoveToReserveTanks()) - pausemenu_equipment_category_item = R18_; + pausemenu_equipment_category_item = r18; } } } -void EquipmentScreenCategory_Weapons_PlazmaSpazerCheck(void) { // 0x82B068 +void EquipmentScreenCategory_Weapons_PlazmaSpazerCheck(uint16 R36) { // 0x82B068 int t = equipped_beams & ~R36; if ((t & 4) != 0) { if ((R36 & 4) == 0 && (equipped_beams & 8) != 0) { equipped_beams &= ~8; - R0_.addr = kEquipmentTilemapOffs_Weapons[4]; - goto LABEL_9; + ChangePaletteValues((uint16 *)(g_ram + kEquipmentTilemapOffs_Weapons[4]), 3072, 5); } } else if ((t & 8) != 0 && (R36 & 8) == 0 && (equipped_beams & 4) != 0) { equipped_beams &= ~4; - R0_.addr = kEquipmentTilemapOffs_Weapons[3]; -LABEL_9: - R18_ = 3072; - R22_ = 10; - SetPaletteOfR22TilemapBytesToR18(); + ChangePaletteValues((uint16 *)(g_ram + kEquipmentTilemapOffs_Weapons[3]), 3072, 5); } } void EquipmentScreenCategory_Suit(void) { // 0x82B0C2 EquipmentScreenCategory_Suit_MoveResponse(); - R24_ = 18; // Fixed var bug if ((uint8)pausemenu_equipment_category_item == 2) - EquipmentScreenCategory_ButtonResponse(); + EquipmentScreenCategory_ButtonResponse(18); } void EquipmentScreenCategory_Suit_MoveResponse(void) { // 0x82B0D2 - R18_ = pausemenu_equipment_category_item; + uint16 r18 = pausemenu_equipment_category_item; if ((joypad1_newkeys & kButton_Left) != 0) { if ((joypad1_newkeys & kButton_Down) == 0) { if (EquipmentScreenMoveToReserveTanks()) return; - pausemenu_equipment_category_item = R18_; + pausemenu_equipment_category_item = r18; } - EquipmentScreenMoveToBeams(0); + EquipmentScreenMoveToBeams(0, r18); } else if ((joypad1_newkeys & kButton_Up) != 0) { if ((pausemenu_equipment_category_item & 0xFF00) != 0) { pausemenu_equipment_category_item -= 256; - EquipmentScreenMoveToScrewOrHigherOnSuits(2 * HIBYTE(pausemenu_equipment_category_item)); + EquipmentScreenMoveToScrewOrHigherOnSuits(2 * HIBYTE(pausemenu_equipment_category_item), r18); } } else if ((joypad1_newkeys & kButton_Down) != 0) { if ((pausemenu_equipment_category_item & 0xFF00) == 1280 || (pausemenu_equipment_category_item += 256, EquipmentScreenMoveLowerOnSuitsMisc(2 * HIBYTE(pausemenu_equipment_category_item)) == 0xFFFF)) { - EquipmentScreenMoveToHighJumpOrLowerInBoots(0); + EquipmentScreenMoveToHighJumpOrLowerInBoots(0, r18); } } } void EquipmentScreenCategory_Boots(void) { // 0x82B150 EquipmentScreenCategory_Boots_MoveResponse(); - R24_ = 18; // Fixed var bug if ((uint8)pausemenu_equipment_category_item == 3) - EquipmentScreenCategory_ButtonResponse(); + EquipmentScreenCategory_ButtonResponse(18); } void EquipmentScreenCategory_Boots_MoveResponse(void) { // 0x82B160 - R18_ = pausemenu_equipment_category_item; + uint16 r18 = pausemenu_equipment_category_item; if ((joypad1_newkeys & kButton_Left) != 0) { - if (((joypad1_newkeys & kButton_Up) != 0 || EquipmentScreenMoveToBottomOfBeams(8u) == 0xFFFF) + if (((joypad1_newkeys & kButton_Up) != 0 || EquipmentScreenMoveToBottomOfBeams(8) == 0xFFFF) && !EquipmentScreenMoveToReserveTanks()) { - pausemenu_equipment_category_item = R18_; + pausemenu_equipment_category_item = r18; } } else if ((joypad1_newkeys & kButton_Down) != 0) { if (pausemenu_equipment_category_item != 515) { pausemenu_equipment_category_item += 256; - EquipmentScreenMoveToHighJumpOrLowerInBoots(2 * HIBYTE(pausemenu_equipment_category_item)); + EquipmentScreenMoveToHighJumpOrLowerInBoots(2 * HIBYTE(pausemenu_equipment_category_item), r18); } } else if ((joypad1_newkeys & kButton_Up) != 0) { if ((pausemenu_equipment_category_item & 0xFF00) == 0 || (pausemenu_equipment_category_item -= 256, EquipmentScreenCategory_Boots_MoveUpInBoots(2 * HIBYTE(pausemenu_equipment_category_item)) == 0xFFFF)) { - EquipmentScreenMoveToScrewOrHigherOnSuits(0xAu); + EquipmentScreenMoveToScrewOrHigherOnSuits(0xA, r18); } } } @@ -2900,23 +2782,20 @@ void WriteSamusWireframeTilemap(void) { // 0x82B20C for (i = 0; (equipped_items & 0x101) != kEquipmentScreenWireframeCmp[i >> 1]; i += 2) ; - R0_.addr = kEquipmentScreenWireframePtrs[i >> 1]; - *(uint16 *)&R0_.bank = 130; - R20_ = 17; + + const uint16 *src = (const uint16*)RomPtr_82(kEquipmentScreenWireframePtrs[i >> 1]); + int m = 17; uint16 v1 = 0; uint16 v2 = 472; do { uint16 v3 = v2; - R18_ = 8; + int n = 8; do { - *(uint16 *)((uint8 *)ram3800.cinematic_bg_tilemap + v2) = IndirReadWord(R0_, v1); + *(uint16 *)((uint8 *)ram3800.cinematic_bg_tilemap + v2) = *src++; v2 += 2; - v1 += 2; - --R18_; - } while (R18_); + } while (--n); v2 = v3 + 64; - --R20_; - } while (R20_); + } while (--m); } @@ -2940,80 +2819,65 @@ static const uint16 kEquipmentScreenReserveTank_Y = 0x60; static const uint16 kPartialReserveTankSpritemapIds[16] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 }; void EquipmentScreenDisplayReserveTankAmount_(void) { - uint16 a; - - R3_.addr = 0; - EquipmentScreenDisplayReserves_PaletteSetup(); + uint16 r3 = EquipmentScreenDisplayReserves_PaletteSetup(); bg3_tilemap_offset = 0; - if (samus_max_reserve_health) { - R44 = samus_max_reserve_health / 100; + if (!samus_max_reserve_health) + return; + uint16 R44 = samus_max_reserve_health / 100; + int mod_value = samus_reserve_health % 100; + uint16 R50 = mod_value; + int r42 = samus_reserve_health / 100; - int mod_value = samus_reserve_health % 100; - R50 = mod_value; - R42 = samus_reserve_health / 100; - - R48 = R42; - R46 = R42; - if (R42) { - uint16 v0 = 0; - do { - a = v0; - DrawMenuSpritemap(0x1B, kEquipmentScreenReserveTank_X[v0 >> 1], kEquipmentScreenReserveTank_Y - 1); - v0 += 2; - --R46; - } while (R46); - bg3_tilemap_offset = a + 2; - } - uint16 RegWord = mod_value; - if (RegWord) { - uint16 v2 = 2 * (RegWord / 14); - if (sign16(v2 - 7) && RegWord % 14 && (nmi_frame_counter_byte & 4) == 0) - v2 += 2; - if (!sign16(samus_reserve_health - 100)) - v2 += 16; - DrawMenuSpritemap( - kPartialReserveTankSpritemapIds[v2 >> 1], - kEquipmentScreenReserveTank_X[bg3_tilemap_offset >> 1], - kEquipmentScreenReserveTank_Y - 1); - ++R48; - ++bg3_tilemap_offset; - ++bg3_tilemap_offset; - } - while (sign16(R48 - R44)) { - DrawMenuSpritemap( - 0x20u, - kEquipmentScreenReserveTank_X[bg3_tilemap_offset >> 1], - kEquipmentScreenReserveTank_Y - 1); - ++bg3_tilemap_offset; - ++bg3_tilemap_offset; - ++R48; - } - DrawMenuSpritemap( - 0x1Fu, - kEquipmentScreenReserveTank_X[bg3_tilemap_offset >> 1], - kEquipmentScreenReserveTank_Y - 1); - int div_val = R50 / 10; - int mod_val = R50 % 10; - ram3800.cinematic_bg_tilemap[394] = mod_val + 2052; - ram3800.cinematic_bg_tilemap[393] = div_val + 2052; - ram3800.cinematic_bg_tilemap[392] = R42 + 2052; + uint16 R48 = r42; + int r46 = r42; + if (r42) { + uint16 v0 = 0; + do { + DrawMenuSpritemap(0x1B, kEquipmentScreenReserveTank_X[v0 >> 1], kEquipmentScreenReserveTank_Y - 1, r3); + v0 += 2; + } while (--r46); + bg3_tilemap_offset = v0; } + uint16 RegWord = mod_value; + if (RegWord) { + uint16 v2 = 2 * (RegWord / 14); + if (sign16(v2 - 7) && RegWord % 14 && (nmi_frame_counter_byte & 4) == 0) + v2 += 2; + if (!sign16(samus_reserve_health - 100)) + v2 += 16; + DrawMenuSpritemap(kPartialReserveTankSpritemapIds[v2 >> 1], kEquipmentScreenReserveTank_X[bg3_tilemap_offset >> 1], + kEquipmentScreenReserveTank_Y - 1, r3); + ++R48; + bg3_tilemap_offset += 2; + } + while (sign16(R48 - R44)) { + DrawMenuSpritemap(0x20, kEquipmentScreenReserveTank_X[bg3_tilemap_offset >> 1], kEquipmentScreenReserveTank_Y - 1, r3); + bg3_tilemap_offset += 2; + ++R48; + } + DrawMenuSpritemap(0x1F, kEquipmentScreenReserveTank_X[bg3_tilemap_offset >> 1], kEquipmentScreenReserveTank_Y - 1, r3); + int div_val = R50 / 10; + int mod_val = R50 % 10; + ram3800.cinematic_bg_tilemap[394] = mod_val + 2052; + ram3800.cinematic_bg_tilemap[393] = div_val + 2052; + ram3800.cinematic_bg_tilemap[392] = r42 + 2052; } -void EquipmentScreenDisplayReserves_PaletteSetup(void) { // 0x82B3F9 - R3_.addr = 1536; +uint16 EquipmentScreenDisplayReserves_PaletteSetup(void) { // 0x82B3F9 if (samus_reserve_health) { - bool v0 = (--pausemenu_reserve_tank_animation_timer & 0x8000u) != 0; + bool v0 = (--pausemenu_reserve_tank_animation_timer & 0x8000) != 0; if (!pausemenu_reserve_tank_animation_timer || v0) { ++pausemenu_reserve_tank_animation_frame; - uint16 v1 = kPauseReserveTankAnimationData[(uint16)(2 * pausemenu_reserve_tank_animation_frame)]; + uint16 v1 = kPauseReserveTankAnimationData[2 * pausemenu_reserve_tank_animation_frame]; if (v1 == 255) { pausemenu_reserve_tank_animation_frame = 0; v1 = kPauseReserveTankAnimationData[0]; } pausemenu_reserve_tank_animation_timer = v1; } - R3_.addr = kPAuseSpritePaletteIndexValues[3]; + return kPAuseSpritePaletteIndexValues[3]; + } else { + return 1536; } } @@ -3021,18 +2885,18 @@ uint16 EquipmentScreenMoveToReserveTanks(void) { // 0x82B43F uint16 result = samus_max_reserve_health; if (samus_max_reserve_health) { pausemenu_equipment_category_item = 0; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); return 1; } return result; } -void EquipmentScreenMoveToBeams(uint16 v0) { // 0x82B456 +void EquipmentScreenMoveToBeams(uint16 v0, uint16 r18) { // 0x82B456 int16 v1; if (hyper_beam_flag) { LABEL_4: - pausemenu_equipment_category_item = R18_; + pausemenu_equipment_category_item = r18; } else { while ((kEquipmentBitmasks_Weapons[v0 >> 1] & collected_beams) == 0) { v0 += 2; @@ -3042,24 +2906,20 @@ LABEL_4: LOBYTE(v1) = (uint16)(v0 >> 1) >> 8; HIBYTE(v1) = v0 >> 1; pausemenu_equipment_category_item = v1 & 0xFF00 | 1; - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); } } uint16 EquipmentScreenMoveToBottomOfBeams(uint16 k) { // 0x82B489 - int16 v2; - if (hyper_beam_flag) return -1; while ((kEquipmentBitmasks_Weapons[k >> 1] & collected_beams) == 0) { k -= 2; - if ((k & 0x8000u) != 0) + if ((k & 0x8000) != 0) return -1; } - QueueSfx1_Max6(0x37u); - LOBYTE(v2) = (uint16)(k >> 1) >> 8; - HIBYTE(v2) = k >> 1; - uint16 result = v2 & 0xFF00 | 1; + QueueSfx1_Max6(0x37); + uint16 result = (k >> 1) << 8 | 1; pausemenu_equipment_category_item = result; return result; } @@ -3072,79 +2932,64 @@ uint16 EquipmentScreenMoveLowerOnSuitsMisc(uint16 v0) { // 0x82B4B7 if ((int16)(v0 - 10) >= 0) return -1; } - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); LOBYTE(v1) = (uint16)(v0 >> 1) >> 8; HIBYTE(v1) = v0 >> 1; pausemenu_equipment_category_item = v1 & 0xFF00 | 2; return 0; } -void EquipmentScreenMoveToScrewOrHigherOnSuits(uint16 v0) { // 0x82B4E6 - int16 v1; - +void EquipmentScreenMoveToScrewOrHigherOnSuits(uint16 v0, uint16 r18) { // 0x82B4E6 while ((kEquipmentBitmasks_Suits[v0 >> 1] & collected_items) == 0) { v0 -= 2; - if ((v0 & 0x8000u) != 0) { - pausemenu_equipment_category_item = R18_; + if ((v0 & 0x8000) != 0) { + pausemenu_equipment_category_item = r18; return; } } - QueueSfx1_Max6(0x37u); - LOBYTE(v1) = (uint16)(v0 >> 1) >> 8; - HIBYTE(v1) = v0 >> 1; - pausemenu_equipment_category_item = v1 & 0xFF00 | 2; + QueueSfx1_Max6(0x37); + pausemenu_equipment_category_item = (v0 >> 1) << 8 | 2; } -void EquipmentScreenMoveToHighJumpOrLowerInBoots(uint16 v0) { // 0x82B511 - int16 v1; - +void EquipmentScreenMoveToHighJumpOrLowerInBoots(uint16 v0, uint16 r18) { // 0x82B511 while ((kEquipmentBitmasks_Boots[v0 >> 1] & collected_items) == 0) { v0 += 2; if ((int16)(v0 - 6) >= 0) { - pausemenu_equipment_category_item = R18_; + pausemenu_equipment_category_item = r18; return; } } - QueueSfx1_Max6(0x37u); - LOBYTE(v1) = (uint16)(v0 >> 1) >> 8; - HIBYTE(v1) = v0 >> 1; - pausemenu_equipment_category_item = v1 & 0xFF00 | 3; + QueueSfx1_Max6(0x37); + pausemenu_equipment_category_item = (v0 >> 1) << 8 | 3; } uint16 EquipmentScreenCategory_Boots_MoveUpInBoots(uint16 k) { // 0x82B53F - int16 v2; - while ((kEquipmentBitmasks_Boots[k >> 1] & collected_items) == 0) { k -= 2; - if ((k & 0x8000u) != 0) + if ((k & 0x8000) != 0) return -1; } - QueueSfx1_Max6(0x37u); - LOBYTE(v2) = (uint16)(k >> 1) >> 8; - HIBYTE(v2) = k >> 1; - uint16 result = v2 & 0xFF00 | 3; + QueueSfx1_Max6(0x37); + uint16 result = (k >> 1) << 8 | 3; pausemenu_equipment_category_item = result; return result; } -void EquipmentScreenCategory_ButtonResponse(void) { // 0x82B568 + +void EquipmentScreenCategory_ButtonResponse(uint16 r24) { // 0x82B568 if ((joypad1_newkeys & kButton_A) != 0) { - QueueSfx1_Max6(0x38u); - R26_ = 2 * (uint8)pausemenu_equipment_category_item; - R18_ = 2 * HIBYTE(pausemenu_equipment_category_item); + QueueSfx1_Max6(0x38); int item = HIBYTE(pausemenu_equipment_category_item); int category = (uint8)pausemenu_equipment_category_item; - R0_.addr = *(uint16 *)RomPtr_82(kEquipmentPtrsToRamTilemapOffsets[category] + item * 2); + uint8 *target = g_ram + *(uint16 *)RomPtr_82(kEquipmentPtrsToRamTilemapOffsets[category] + item * 2); uint16 *var = (uint16 *)RomPtr_RAM(kEquipmentPtrsToBitsets[category]); uint16 mask = *(uint16 *)RomPtr_82(kEquipmentPtrsToBitmasks[category] + item * 2); if ((*var & mask) != 0) { *var &= ~mask; - R18_ = 0xC00; - R22_ = R24_; - SetPaletteOfR22TilemapBytesToR18(); + ChangePaletteValues((uint16*)target, 0xc00, r24 >> 1); } else { *var |= mask; - R22_ = R24_; - Copy_R22_Bytes(*(uint16 *)RomPtr_82(kEquipmentPtrsToEquipmentTilemaps[category] + item * 2)); + uint16 src = *(uint16 *)RomPtr_82(kEquipmentPtrsToEquipmentTilemaps[category] + item * 2); + memcpy(target, RomPtr_82(src), r24); } } } @@ -3171,109 +3016,92 @@ void UNKNOWN_sub_82B650(void) { // 0x82B650 EquipmentScreenDisplayReserveTankAmount(); } } + static const uint16 kMap_Criteria_SavePoints[16] = { 0xd8, 0x28, 0x90, 0x38, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe, 0xfffe }; + void DrawMapIcons(void) { // 0x82B672 - DrawBossMapIcons(9u, addr_kMapIconDataPointers); - R3_.addr = 3584; - DrawSimpleMapIcons(0xB, addr_kMapIconDataPointers + 0x10); - DrawSimpleMapIcons(0xA, addr_kMapIconDataPointers + 0x20); - DrawSimpleMapIcons(0x4E, addr_kMapIconDataPointers + 0x30); - R3_.addr = 1024; - DrawSaveStationMapIcon(8u, 0xC80B); + DrawBossMapIcons(9, addr_kMapIconDataPointers); + DrawSimpleMapIcons(0xB, addr_kMapIconDataPointers + 0x10, 3584); + DrawSimpleMapIcons(0xA, addr_kMapIconDataPointers + 0x20, 3584); + DrawSimpleMapIcons(0x4E, addr_kMapIconDataPointers + 0x30, 3584); + DrawSaveStationMapIcon(8, 0xC80B, 1024); if (enable_debug) - DrawSimpleMapIcons(8u, 0xC82B); + DrawSimpleMapIcons(8, 0xC82B, 1024); if (!area_index) { - R3_.addr = 3584; - DrawMenuSpritemap( - 0x63u, - kMap_Criteria_SavePoints[0] - reg_BG1HOFS, - kMap_Criteria_SavePoints[1] - reg_BG1VOFS); + DrawMenuSpritemap(0x63, kMap_Criteria_SavePoints[0] - reg_BG1HOFS, kMap_Criteria_SavePoints[1] - reg_BG1VOFS, 3584); } } void DrawFileSelectMapIcons(void) { // 0x82B6DD - int16 v0; - HandlePauseScreenPaletteAnimation(); - DrawBossMapIcons(9u, 0xC7CB); - R3_.addr = 3584; - DrawSimpleMapIcons(0xB, 0xC7DB); - DrawSimpleMapIcons(0xA, 0xC7EB); - DrawSimpleMapIcons(0x4E, 0xC7FB); - R3_.addr = 3584; + DrawBossMapIcons(9, 0xC7CB); + DrawSimpleMapIcons(0xB, 0xC7DB, 3584); + DrawSimpleMapIcons(0xA, 0xC7EB, 3584); + DrawSimpleMapIcons(0x4E, 0xC7FB, 3584); uint16 a = UpdateSamusPositionIndicatorAnimation(); - *(uint16 *)&R0_.bank = 130; - R0_.addr = *(VoidP *)((uint8 *)&kMapIconDataPointers[4].crateria + (uint16)(2 * area_index)); - v0 = 4 * load_station_index; - uint16 v1 = IndirReadWord(R0_, 4 * load_station_index) - reg_BG1HOFS; - uint16 v2 = IndirReadWord(R0_, v0 + 2) - reg_BG1VOFS; + const uint16 *data = (uint16 *)RomPtr_82(*(VoidP *)((uint8 *)&kMapIconDataPointers[4].crateria + 2 * area_index)) + load_station_index * 2; + uint16 v1 = data[0] - reg_BG1HOFS; + uint16 v2 = data[1] - reg_BG1VOFS; if ((samus_position_indicator_animation_loop_counter & 1) == 0) - DrawMenuSpritemap(0x12, v1, v2); - DrawMenuSpritemap(a, v1, v2); + DrawMenuSpritemap(0x12, v1, v2, 3584); + DrawMenuSpritemap(a, v1, v2, 3584); if (enable_debug) { - R3_.addr = 1536; - DrawDebugSaveMapIcons(0xC, 0xC80B); - DrawDebugElevatorMapIcons(0x17, 0xC81B); - DrawSimpleMapIcons(0xC, 0xC82B); - } - if (!area_index) { - R3_.addr = 3584; - DrawMenuSpritemap( - 0x63u, - kMap_Criteria_SavePoints[0] - reg_BG1HOFS, - kMap_Criteria_SavePoints[1] - reg_BG1VOFS); + DrawDebugSaveMapIcons(0xC, 0xC80B, 1536); + DrawDebugElevatorMapIcons(0x17, 0xC81B, 1536); + DrawSimpleMapIcons(0xC, 0xC82B, 1536); } + if (!area_index) + DrawMenuSpritemap(0x63, kMap_Criteria_SavePoints[0] - reg_BG1HOFS, kMap_Criteria_SavePoints[1] - reg_BG1VOFS, 3584); } -void DrawSaveStationMapIcon(uint16 a, uint16 k) { // 0x82B798 +void DrawSaveStationMapIcon(uint16 a, uint16 k, uint16 r3) { // 0x82B798 static const uint8 kShlBit[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 }; - R34 = a; + uint16 R34 = a; if (area_index == sram_area_index) { - R36 = *(uint16 *)&used_save_stations_and_elevators[(uint16)(2 * area_index)]; + uint16 R36 = *(uint16 *)&used_save_stations_and_elevators[2 * area_index]; LOBYTE(R36) = R36 & kShlBit[load_station_index]; uint16 v2 = *(uint16 *)RomPtr_82(k + 2 * area_index); if (v2) - DrawMapIconsOfType(v2); + DrawMapIconsOfType(v2, R34, R36, r3); } } -void DrawDebugSaveMapIcons(uint16 a, uint16 k) { // 0x82B7D1 - R34 = a; - R36 = *(uint16 *)&used_save_stations_and_elevators[(uint16)(2 * area_index)]; +void DrawDebugSaveMapIcons(uint16 a, uint16 k, uint16 r3) { // 0x82B7D1 + uint16 R34 = a; + uint16 R36 = *(uint16 *)&used_save_stations_and_elevators[2 * area_index]; uint16 v2 = *(uint16 *)RomPtr_82(k + 2 * area_index); if (v2) - DrawMapIconsOfType(v2); + DrawMapIconsOfType(v2, R34, R36, r3); } -void DrawDebugElevatorMapIcons(uint16 a, uint16 k) { // 0x82B7EB - R34 = a; - R36 = *(uint16 *)&used_save_stations_and_elevators[(uint16)(2 * area_index) + 1]; +void DrawDebugElevatorMapIcons(uint16 a, uint16 k, uint16 r3) { // 0x82B7EB + uint16 R34 = a; + uint16 R36 = *(uint16 *)&used_save_stations_and_elevators[2 * area_index + 1]; uint16 v2 = *(uint16 *)RomPtr_82(k + 2 * area_index); if (v2) - DrawMapIconsOfType(v2); + DrawMapIconsOfType(v2, R34, R36, r3); } -void DrawSimpleMapIcons(uint16 a, uint16 k) { // 0x82B805 - R34 = a; - R36 = -1; +void DrawSimpleMapIcons(uint16 a, uint16 k, uint16 r3) { // 0x82B805 + uint16 R34 = a; uint16 v2 = *(uint16 *)RomPtr_82(k + 2 * area_index); if (v2) - DrawMapIconsOfType(v2); + DrawMapIconsOfType(v2, R34, -1, r3); } -void DrawMapIconsOfType(uint16 a) { // 0x82B81C +void DrawMapIconsOfType(uint16 a, uint16 r34, uint16 r36, uint16 r3) { // 0x82B81C int8 v3; // cf int16 v4; while (1) { const uint16 *v2 = (const uint16 *)RomPtr_82(a); - if ((*v2 & 0x8000u) != 0) + if ((*v2 & 0x8000) != 0) break; - v3 = R36 & 1; - R36 >>= 1; + v3 = r36 & 1; + r36 >>= 1; if (v3) { v4 = CheckIfMapPositionIsExplored(v2[0], v2[1]); if (v4) - DrawMenuSpritemap(R34, v2[0] - reg_BG1HOFS, v2[1] - reg_BG1VOFS); + DrawMenuSpritemap(r34, v2[0] - reg_BG1HOFS, v2[1] - reg_BG1VOFS, r3); } a += 4; } @@ -3281,18 +3109,11 @@ void DrawMapIconsOfType(uint16 a) { // 0x82B81C uint16 CheckIfMapPositionIsExplored(uint16 k, uint16 j) { // 0x82B855 static const uint8 kBits0x80Shr[8] = { 0x80, 0x40, 0x20, 0x10, 8, 4, 2, 1 }; - uint16 v2; - uint16 v4; // dx - - R18_ = (uint16)(k & 0xFF00) >> 1; - R18_ += (uint8)k >> 6; - R18_ += (uint16)(j & 0xFFF8) >> 1; + int r18 = (uint16)(k & 0xFF00) >> 1; + r18 += (uint8)k >> 6; + r18 += (uint16)(j & 0xFFF8) >> 1; uint16 v3 = (k >> 3) & 7; - HIBYTE(v2) = HIBYTE(v3); - LOBYTE(v2) = map_tiles_explored[R18_]; - HIBYTE(v4) = HIBYTE(v3); - LOBYTE(v4) = kBits0x80Shr[v3]; - return (v4 & v2) != 0; + return (kBits0x80Shr[v3] & map_tiles_explored[r18]) != 0; } void DrawBossMapIcons(uint16 a, uint16 k) { // 0x82B892 @@ -3305,17 +3126,15 @@ void DrawBossMapIcons(uint16 a, uint16 k) { // 0x82B892 if (v4[0] == 0xffff) return; if (v4[0] != 0xfffe) { - R3_.addr = 3584; int v5 = bits & 1; bits >>= 1; if (v5) { - DrawMenuSpritemap(0x62, v4[0] - reg_BG1HOFS, v4[1] - reg_BG1VOFS); - R3_.addr = 3072; - DrawMenuSpritemap(a, v4[0] - reg_BG1HOFS, v4[1] - reg_BG1VOFS); + DrawMenuSpritemap(0x62, v4[0] - reg_BG1HOFS, v4[1] - reg_BG1VOFS, 3584); + DrawMenuSpritemap(a, v4[0] - reg_BG1HOFS, v4[1] - reg_BG1VOFS, 3072); continue; } if (has_area_map) { - DrawMenuSpritemap(a, v4[0] - reg_BG1HOFS, v4[1] - reg_BG1VOFS); + DrawMenuSpritemap(a, v4[0] - reg_BG1HOFS, v4[1] - reg_BG1VOFS, 3584); continue; } } @@ -3355,12 +3174,9 @@ void HandleMapScrollArrows(void) { // 0x82B934 } void MapScreenDrawSamusPositionIndicator(void) { // 0x82B9C8 - R3_.addr = 3584; uint16 a = UpdateSamusPositionIndicatorAnimation(); - DrawMenuSpritemap( - a, - 8 * (room_x_coordinate_on_map + HIBYTE(samus_x_pos)) - reg_BG1HOFS, - 8 * (room_y_coordinate_on_map + HIBYTE(samus_y_pos) + 1) - reg_BG1VOFS); + DrawMenuSpritemap(a, 8 * (room_x_coordinate_on_map + HIBYTE(samus_x_pos)) - reg_BG1HOFS, + 8 * (room_y_coordinate_on_map + HIBYTE(samus_y_pos) + 1) - reg_BG1VOFS, 3584); } static const uint16 kMap_SamusPositionIndicator_Delays[4] = { 8, 4, 8, 4 }; @@ -3383,19 +3199,17 @@ uint16 UpdateSamusPositionIndicatorAnimation(void) { // 0x82B9FC } void DrawBorderAroundSamusData(void) { // 0x82BA35 - R3_.addr = 3584; - DrawMenuSpritemap(0x48, 0x80, 0x10); + DrawMenuSpritemap(0x48, 0x80, 0x10, 3584); } void DrawBorderAroundDataCopyMode(void) { // 0x82BA48 - R3_.addr = 3584; - DrawMenuSpritemap(0x49, 0x80, 0x10); + DrawMenuSpritemap(0x49, 0x80, 0x10, 3584); } void DrawBorderAroundDataClearMode(void) { // 0x82BA5B - R3_.addr = 3584; - DrawMenuSpritemap(0x4A, 0x7C, 0x10); + DrawMenuSpritemap(0x4A, 0x7C, 0x10, 3584); } + static const uint16 kDrawMenuSelectionMissile_Enable[4] = { 8, 8, 8, 8 }; static const uint16 kDrawMenuSelectionMissile_SpriteMap[4] = { 0x37, 0x36, 0x35, 0x34 }; void DrawMenuSelectionMissile(void) { // 0x82BA6E @@ -3405,12 +3219,10 @@ void DrawMenuSelectionMissile(void) { // 0x82BA6E enemy_projectile_enable_flag = kDrawMenuSelectionMissile_Enable[enemy_projectile_id[0]]; } } - R3_.addr = 3584; - DrawMenuSpritemap( - kDrawMenuSelectionMissile_SpriteMap[enemy_projectile_id[0]], - enemy_projectile_id[5], - enemy_projectile_id[10]); + DrawMenuSpritemap(kDrawMenuSelectionMissile_SpriteMap[enemy_projectile_id[0]], + enemy_projectile_id[5], enemy_projectile_id[10], 3584); } + void DrawFileCopyArrow(void) { // 0x82BABA uint16 v0; if ((int16)(enemy_projectile_id[16] - enemy_projectile_id[17]) >= 0) { @@ -3428,20 +3240,16 @@ void DrawFileCopyArrow(void) { // 0x82BABA v0 = 2; } } - R3_.addr = 512; - DrawMenuSpritemap( - file_copy_arrow_stuff[v0].spritemap, - file_copy_arrow_stuff[v0].xpos, - file_copy_arrow_stuff[v0].ypos); + DrawMenuSpritemap(file_copy_arrow_stuff[v0].spritemap, file_copy_arrow_stuff[v0].xpos, file_copy_arrow_stuff[v0].ypos, 512); } + void DisplayMapElevatorDestinations(void) { // 0x82BB30 - R3_.addr = 0; if (map_station_byte_array[area_index]) { for (int i = kMapElevatorDests[area_index]; ; i += 6) { const uint8 *v1 = RomPtr_82(i); if (GET_WORD(v1) == 0xFFFF) break; - DrawMenuSpritemap(GET_WORD(v1 + 4), GET_WORD(v1) - reg_BG1HOFS, GET_WORD(v1 + 2) - reg_BG1VOFS); + DrawMenuSpritemap(GET_WORD(v1 + 4), GET_WORD(v1) - reg_BG1HOFS, GET_WORD(v1 + 2) - reg_BG1VOFS, 0); } } } @@ -3474,8 +3282,7 @@ void sub_82BB7F(uint16 a) { // 0x82BB7F enemy_data[0].current_instruction += 6; DrawBabyMetroid(current_instruction + 6); } else { - R18_ = GET_WORD(v2 + 6); - CallBabyMetroidPlaySfx(R18_ | 0x820000); + CallBabyMetroidPlaySfx(GET_WORD(v2 + 6) | 0x820000); } } else { DrawBabyMetroid(enemy_data[0].current_instruction); @@ -3485,18 +3292,16 @@ void sub_82BB7F(uint16 a) { // 0x82BB7F void sub_82BBDD(void) { // 0x82BBDD enemy_data[0].current_instruction = addr_kgameOverBabyMetridInstructionList; enemy_data[0].instruction_timer = 10; - sub_82BB7F(0xAu); + sub_82BB7F(0xA); } void DrawBabyMetroid(uint16 k) { // 0x82BB9E uint16 v1 = *((uint16 *)RomPtr_82(k) + 2); for(int i = 0; i < 32; i += 2) palette_buffer[(i >> 1) + 192] = *(uint16 *)RomPtr_82(v1 + i); - R3_.addr = 2048; const uint8 *v3 = RomPtr_82(k); - DrawMenuSpritemap(GET_WORD(v3 + 2), 0x7C, 0x50); - R3_.addr = 2560; - DrawMenuSpritemap(0x64, 0x7C, 0x50); + DrawMenuSpritemap(GET_WORD(v3 + 2), 0x7C, 0x50, 2048); + DrawMenuSpritemap(0x64, 0x7C, 0x50, 2560); } void FinishProcessingGameOverBabyMetroidAsm(void) { // 0x82BBF0 @@ -3510,32 +3315,32 @@ void FinishProcessingGameOverBabyMetroidAsm(void) { // 0x82BBF0 } void BabyMetroidPlaySfx0x23(void) { // 0x82BC0C - QueueSfx3_Max6(0x23u); + QueueSfx3_Max6(0x23); FinishProcessingGameOverBabyMetroidAsm(); } void BabyMetroidPlaySfx0x26(void) { // 0x82BC15 - QueueSfx3_Max6(0x26u); + QueueSfx3_Max6(0x26); FinishProcessingGameOverBabyMetroidAsm(); } void BabyMetroidPlaySfx0x27(void) { // 0x82BC1E - QueueSfx3_Max6(0x27u); + QueueSfx3_Max6(0x27); FinishProcessingGameOverBabyMetroidAsm(); } void CancelSoundEffects(void) { // 0x82BE17 - QueueSfx1_Max6(2u); - QueueSfx2_Max6(0x71u); - QueueSfx3_Max6(1u); + QueueSfx1_Max6(2); + QueueSfx2_Max6(0x71); + QueueSfx3_Max6(1); } void QueueSamusMovementSfx(void) { // 0x82BE2F if ((speed_boost_counter & 0xFF00) == 1024) - QueueSfx3_Max6(0x2Bu); + QueueSfx3_Max6(0x2B); if (!sign16(flare_counter - 16)) - QueueSfx1_Max6(0x41u); - CallSomeSamusCode(0x14u); + QueueSfx1_Max6(0x41); + CallSomeSamusCode(0x14); } @@ -3546,8 +3351,8 @@ uint8 AdvancePaletteFadeForAllPalettes_0xc(void) { // 0x82D961 uint8 AdvancePaletteFade_BgPalette6(void) { // 0x82D96C palette_change_denom = 12; - if (palette_change_num <= 0xDu) { - for (int i = 192; i < 0xE0u; i += 2) + if (palette_change_num <= 0xD) { + for (int i = 192; i < 0xE0; i += 2) palette_buffer[i >> 1] = CalculateNthTransitionColorFromXtoY( palette_change_num, palette_buffer[i >> 1], @@ -3563,7 +3368,7 @@ uint8 AdvancePaletteFade_BgPalette6(void) { // 0x82D96C uint8 AdvanceGradualColorChangeOfPalette(uint16 k, uint16 j) { // 0x82D9B8 palette_change_denom = 15; if ((int16)(15 - palette_change_num) >= 0) { - R34 = j; + uint16 R34 = j; do { palette_buffer[k >> 1] = CalculateNthTransitionColorFromXtoY( palette_change_num + 1, @@ -3581,7 +3386,7 @@ uint8 AdvanceGradualColorChangeOfPalette(uint16 k, uint16 j) { // 0x82D9B8 uint8 AdvancePaletteFadeForAllPalettes(void) { // 0x82DA02 if ((uint16)(palette_change_denom + 1) >= palette_change_num) { - for (int i = 0; i < 0x200u; i += 2) { + for (int i = 0; i < 0x200; i += 2) { g_word_7EC404 = i; int v2 = i >> 1; if (target_palettes[v2] != palette_buffer[v2]) { @@ -3610,11 +3415,9 @@ uint16 CalculateNthTransitionColorComponentFromXtoY(uint16 a, uint16 k, uint16 j uint16 v4 = a - 1; if (v4 == palette_change_denom) return j; - R20_ = v4 + 1; - R18_ = j - k; - uint16 RegWord = SnesDivide((abs16(j - k) << 8) & 0xFF00, palette_change_denom - R20_ + 1); - R18_ = sign16(R18_) ? -RegWord : RegWord; - return (uint16)(R18_ + (k << 8)) >> 8; + uint16 RegWord = SnesDivide(abs16(j - k) << 8, palette_change_denom - (v4 + 1) + 1); + uint16 r18 = sign16(j - k) ? -RegWord : RegWord; + return (uint16)(r18 + (k << 8)) >> 8; } uint8 sub_82DAF7(uint16 a) { // 0x82DAF7 @@ -3660,12 +3463,12 @@ void HandleSamusOutOfHealthAndGameTile(void) { // 0x82DB69 if ((reserve_health_mode & 1) != 0 && samus_reserve_health) { time_is_frozen_flag = 0x8000; game_state = kGameState_27_ReserveTanksAuto; - CallSomeSamusCode(0x1Bu); + CallSomeSamusCode(0x1B); } else { if (game_state != kGameState_8_MainGameplay) return; time_is_frozen_flag = 0x8000; - CallSomeSamusCode(0x11u); + CallSomeSamusCode(0x11); game_state = kGameState_19_SamusNoHealth; } } @@ -3692,7 +3495,7 @@ CoroutineRet GameState_27_ReserveTanksAuto(void) { // 0x82DC10 if (coroutine_state_1 == 0 && RefillHealthFromReserveTanks()) { time_is_frozen_flag = 0; game_state = kGameState_8_MainGameplay; - CallSomeSamusCode(0x10u); + CallSomeSamusCode(0x10); } COROUTINE_AWAIT_ONLY(GameState_8_MainGameplay()); Samus_LowHealthCheck_0(); @@ -3702,14 +3505,14 @@ CoroutineRet GameState_27_ReserveTanksAuto(void) { // 0x82DC10 uint8 RefillHealthFromReserveTanks(void) { // 0x82DC31 if (samus_reserve_health) { if ((nmi_frame_counter_word & 7) == 0) - QueueSfx3_Max3(0x2Du); + QueueSfx3_Max3(0x2D); if ((int16)(++samus_health - samus_max_health) >= 0) { samus_health = samus_max_health; LABEL_9: samus_reserve_health = 0; return samus_reserve_health == 0; } - bool v0 = (--samus_reserve_health & 0x8000u) != 0; + bool v0 = (--samus_reserve_health & 0x8000) != 0; if (!samus_reserve_health) goto LABEL_9; if (v0) { @@ -3724,11 +3527,11 @@ CoroutineRet GameState_19_SamusNoHealth(void) { // 0x82DC80 COROUTINE_AWAIT_ONLY(GameState_8_MainGameplay()); for (int i = 255; i >= 0; --i) ram3000.pause_menu_map_tilemap[i + 384] = palette_buffer[i]; - for (int j = 382; (j & 0x8000u) == 0; j -= 2) + for (int j = 382; (j & 0x8000) == 0; j -= 2) target_palettes[j >> 1] = 0; - for (int k = 94; (k & 0x8000u) == 0; k -= 2) + for (int k = 94; (k & 0x8000) == 0; k -= 2) target_palettes[(k >> 1) + 208] = 0; - for (int m = 30; (m & 0x8000u) == 0; m -= 2) + for (int m = 30; (m & 0x8000) == 0; m -= 2) target_palettes[(m >> 1) + 192] = palette_buffer[(m >> 1) + 192]; game_options_screen_index = 3; g_word_7E0DE4 = 0; @@ -3769,12 +3572,12 @@ CoroutineRet GameState_20_SamusNoHealth_BlackOut(void) { // 0x82DCE0 g_word_7E0DE6 = 0; ++game_state; power_bomb_explosion_status = 0; - QueueSfx1_Max15(2u); - QueueSfx2_Max15(0x71u); - QueueSfx3_Max15(1u); + QueueSfx1_Max15(2); + QueueSfx2_Max15(0x71); + QueueSfx3_Max15(1); QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF39u); - QueueMusic_DelayedY(5u, 0xE); + QueueMusic_Delayed8(0xFF39); + QueueMusic_DelayedY(5, 0xE); } return kCoroutineNone; } @@ -3790,7 +3593,7 @@ CoroutineRet GameState_21_SamusNoHealth(void) { // 0x82DD71 CoroutineRet GameState_22_SamusNoHealth_Dying(void) { // 0x82DD87 DrawSamusStartingDeathAnim_(); - bool v0 = (--g_word_7E0DE8 & 0x8000u) != 0; + bool v0 = (--g_word_7E0DE8 & 0x8000) != 0; if (!g_word_7E0DE8 || v0) ++game_state; return kCoroutineNone; @@ -3843,8 +3646,6 @@ void LoadDoorHeader(void) { // 0x82DE12 door_direction = DoorDef->door_orientation; door_destination_x_pos = DoorDef->x_pos_in_room << 8; door_destination_y_pos = DoorDef->y_pos_in_room << 8; - R18_ = 0; - R20_ = 0; samus_distance_from_door = DoorDef->samus_distance_from_door; if (samus_distance_from_door < 0) { if ((door_direction & 2) != 0) @@ -3852,9 +3653,9 @@ void LoadDoorHeader(void) { // 0x82DE12 else samus_distance_from_door = 200; } - R19_ = samus_distance_from_door; - samus_door_transition_subspeed = R18_; - samus_door_transition_speed = R20_; + uint32 t = samus_distance_from_door << 8; + samus_door_transition_subspeed = t & 0xffff; + samus_door_transition_speed = t >> 16; } void LoadRoomHeader(void) { // 0x82DE6F @@ -3880,7 +3681,7 @@ void LoadStateHeader(void) { // 0x82DEF2 StateHeaderTiles *StateHeaderTiles; // r10 RoomDefRoomstate *RoomDefRoomstate; // r11 - int v0 = (uint16)(2 * get_RoomDefRoomstate(roomdefroomstate_ptr)->graphics_set) >> 1; + int v0 = get_RoomDefRoomstate(roomdefroomstate_ptr)->graphics_set; StateHeaderTiles = get_StateHeaderTiles(kStateHeaderGraphicsSets[v0]); copy24(&tileset_tile_table_pointer, &StateHeaderTiles->tile_table_ptr); copy24(&tileset_tiles_pointer, &StateHeaderTiles->tiles_ptr); @@ -3922,24 +3723,24 @@ void EnsureSamusDrawnEachFrame(void) { // 0x82DFC7 } void LoadEnemyGfxToVram(void) { // 0x82DFD1 - EnemyDef_A2 *EnemyDef_A2; + EnemyDef_A2 *ED; - R18_ = 28672; + uint16 dst = 0x7000; uint16 v0 = room_enemy_tilesets_ptr; if (room_enemy_tilesets_ptr) { for (int i = room_enemy_tilesets_ptr; ; v0 = i) { uint16 enemy_def = get_EnemyTileset(v0)->enemy_def; if (enemy_def == 0xFFFF) break; - EnemyDef_A2 = get_EnemyDef_A2(enemy_def); - copy24(&door_transition_vram_update_src, &EnemyDef_A2->tile_data); - if ((EnemyDef_A2->tile_data_size & 0x8000u) != 0) { - door_transition_vram_update_size = EnemyDef_A2->tile_data_size & 0x7FFF; + ED = get_EnemyDef_A2(enemy_def); + copy24(&door_transition_vram_update_src, &ED->tile_data); + if ((ED->tile_data_size & 0x8000) != 0) { + door_transition_vram_update_size = ED->tile_data_size & 0x7FFF; door_transition_vram_update_dst = ((uint16)(get_EnemyTileset(i)->vram_dst & 0xF000) >> 4) | 0x6000; } else { - door_transition_vram_update_size = EnemyDef_A2->tile_data_size; - door_transition_vram_update_dst = R18_; - R18_ += EnemyDef_A2->tile_data_size >> 1; + door_transition_vram_update_size = ED->tile_data_size; + door_transition_vram_update_dst = dst; + dst += ED->tile_data_size >> 1; } WaitForIrqDoorTransitionVramUpdate(); i += 4; @@ -3958,29 +3759,29 @@ void CopyToVramAtNextInterrupt(const void *p) { // 0x82E039 void LoadRoomMusic(void) { // 0x82E071 if (game_state < kGameState_40_TransitionToDemo && room_music_data_index && room_music_data_index != music_data_index) { QueueMusic_Delayed8(0); - QueueMusic_Delayed8((uint8)room_music_data_index | 0xFF00); + QueueMusic_Delayed8(room_music_data_index | 0xFF00); } } void UpdateMusicTrackIndex(void) { // 0x82E09B if (game_state < kGameState_40_TransitionToDemo && room_music_track_index) { - R18_ = (uint8)room_music_data_index << 8; - R18_ |= room_music_track_index; - R20_ = (uint8)music_data_index << 8; - R20_ |= music_track_index; - if (R18_ != R20_) + uint16 r18 = room_music_data_index << 8; + r18 |= room_music_track_index; + uint16 r20 = music_data_index << 8; + r20 |= music_track_index; + if (r18 != r20) music_track_index = room_music_track_index; } } void LoadNewMusicTrackIfChanged(void) { // 0x82E0D5 - if (game_state < 0x28u && room_music_track_index) { - R18_ = (uint8)room_music_data_index << 8; - R18_ |= room_music_track_index; - R20_ = (uint8)music_data_index << 8; - R20_ |= music_track_index; - if (R18_ != R20_) - QueueMusic_DelayedY(room_music_track_index, 6u); + if (game_state < 0x28 && room_music_track_index) { + uint16 r18 = room_music_data_index << 8; + r18 |= room_music_track_index; + uint16 r20 = music_data_index << 8; + r20 |= music_track_index; + if (r18 != r20) + QueueMusic_DelayedY(room_music_track_index, 6); } } @@ -4001,9 +3802,9 @@ void LoadColorsForSpritesBeamsAndEnemies(void) { // 0x82E139 for (int i = 30; i >= 0; i -= 2) target_palettes[(i >> 1) + 208] = kInitialPalette[(i >> 1) + 208]; - for (j = 30; (j & 0x8000u) == 0; j -= 2) + for (j = 30; (j & 0x8000) == 0; j -= 2) target_palettes[(j >> 1) + 224] = palette_buffer[(j >> 1) + 224]; - for (k = 30; (k & 0x8000u) == 0; k -= 2) + for (k = 30; (k & 0x8000) == 0; k -= 2) target_palettes[(k >> 1) + 128] = kCommonSpritesPalette1[k >> 1]; } @@ -4038,7 +3839,7 @@ CoroutineRet DoorTransitionFunction_HandleElevator(void) { // 0x82E17D return GameState_10_LoadingNextRoom_Async(); } CallSomeSamusCode(0); - if ((elevator_direction & 0x8000u) != 0) { + if ((elevator_direction & 0x8000) != 0) { ++game_state; return GameState_10_LoadingNextRoom_Async(); } @@ -4048,7 +3849,7 @@ CoroutineRet DoorTransitionFunction_HandleElevator(void) { // 0x82E17D } CoroutineRet DoorTransitionFunction_Wait48frames(void) { // 0x82E19F - if ((--downwards_elevator_delay_timer & 0x8000u) != 0) { + if ((--downwards_elevator_delay_timer & 0x8000) != 0) { ++game_state; return GameState_10_LoadingNextRoom_Async(); } else { @@ -4098,7 +3899,7 @@ CoroutineRet GameState_10_LoadingNextRoom_Async(void) { // 0x82E1B7 } } ClearSoundsWhenGoingThroughDoor(); - QueueSfx2_Max15(0x71u); + QueueSfx2_Max15(0x71); debug_disable_sounds = -1; door_transition_function = FUNC16(DoorTransitionFunction_WaitForSoundsToFinish); ++game_state; @@ -4140,7 +3941,7 @@ CoroutineRet DoorTransitionFunction_FadeOutScreen(void) { // 0x82E2DB CoroutineRet DoorTransitionFunction_LoadDoorHeaderEtc(void) { // 0x82E2F7 LoadDoorHeader(); sub_8882AC(); - hdma_objects_enable_flag &= ~0x8000u; + hdma_objects_enable_flag &= ~0x8000; irqhandler_next_handler = 8; door_transition_function = FUNC16(DoorTransitionFunction_ScrollScreenToAlignment); return kCoroutineNone; @@ -4287,7 +4088,7 @@ CoroutineRet DoorTransitionFunction_LoadMoreThings_Async(void) { } while (bg_data_ptr); } // Wait until the screen has finished scrolling as a result of the door opening - while ((door_transition_flag & 0x8000u) == 0) { + while ((door_transition_flag & 0x8000) == 0) { COROUTINE_AWAIT(1, WaitForNMI_Async()); } palette_buffer[196] = 15328; @@ -4297,9 +4098,9 @@ CoroutineRet DoorTransitionFunction_LoadMoreThings_Async(void) { if ((door_direction & 2) == 0) { if ((door_direction & 3) != 0) - samus_x_pos &= 0xFFF8u; + samus_x_pos &= 0xFFF8; else - samus_x_pos |= 7u; + samus_x_pos |= 7; } door_transition_function = FUNC16(DoorTransition_C_HandleAnimTiles); COROUTINE_END(0); @@ -4414,14 +4215,14 @@ CoroutineRet DoorTransition_HandleTransition(void) { // 0x82E6A2 irqhandler_next_handler = v1; PointlessFunctionStupidToo(); if (elevator_flags) { - if ((elevator_direction & 0x8000u) == 0) - CallSomeSamusCode(7u); + if ((elevator_direction & 0x8000) == 0) + CallSomeSamusCode(7); else CallSomeSamusCode(0); } SetLiquidPhysicsType(); door_transition_function = FUNC16(DoorTransition_FadeInScreenAndFinish); - *(uint16 *)®_INIDISP |= 0x1Fu; + *(uint16 *)®_INIDISP |= 0x1F; return kCoroutineNone; } @@ -4481,7 +4282,7 @@ void LoadLevelDataAndOtherThings(void) { // 0x82E7D3 for (j = ram7F_start + ram7F_start + (ram7F_start >> 1); ; custom_background[v1 >> 1] = level_data[j >> 1]) { j -= 2; v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) break; } v3 = ram7F_start >> 1; @@ -4500,14 +4301,14 @@ void LoadLevelDataAndOtherThings(void) { // 0x82E7D3 RoomDefRoomstate = get_RoomDefRoomstate(roomdefroomstate_ptr); rdf_scroll_ptr = RoomDefRoomstate->rdf_scroll_ptr; if (rdf_scroll_ptr >= 0) { - R18_ = RoomDefRoomstate->rdf_scroll_ptr; - LOBYTE(R20_) = room_height_in_scrolls - 1; + uint16 scrollval = RoomDefRoomstate->rdf_scroll_ptr; + uint8 r20 = room_height_in_scrolls - 1; uint8 v8 = 2; uint8 v9 = 0; v10 = 0; do { - if (v10 == (uint8)R20_) - v8 = R18_ + 1; + if (v10 == r20) + v8 = scrollval + 1; v14 = v10; v11 = 0; do { @@ -4537,9 +4338,11 @@ void SpawnDoorClosingPLM(void) { // 0x82E8EB if (!CheckIfColoredDoorCapSpawned()) { const uint16 *v0 = (const uint16 *)RomPtr_8F(2 * door_direction + addr_kDoorClosingPlmIds); if (*v0) { - R18_ = *v0; - R20_ = *(uint16 *)&get_DoorDef(door_def_ptr)->x_pos_plm; - SpawnRoomPLM(0x12u); // This reads from R18 + RoomPlmEntry *rp = (RoomPlmEntry *)(g_ram + 0x12); + rp->plm_header_ptr_ = *v0; + WORD(rp->x_block) = *(uint16 *)&get_DoorDef(door_def_ptr)->x_pos_plm; + rp->plm_room_argument = 0; + SpawnRoomPLM(0x12); // This reads from r18 } } } @@ -4551,7 +4354,7 @@ uint8 CheckIfColoredDoorCapSpawned(void) { // 0x82E91C uint16 v3 = 78; while (v2 != plm_block_indices[v3 >> 1]) { v3 -= 2; - if ((v3 & 0x8000u) != 0) + if ((v3 & 0x8000) != 0) return 0; } int v5 = v3 >> 1; @@ -4593,7 +4396,7 @@ void LoadLibraryBackground(void) { WriteRegWord(A1B1, 0x8A); WriteRegWord(DAS1L, 0x840); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } bg_data_ptr = get_RoomDefRoomstate(roomdefroomstate_ptr)->bg_data_ptr; if (bg_data_ptr & 0x8000) { @@ -4624,7 +4427,7 @@ uint16 LoadLibraryBackgroundFunc_2_TransferToVram(uint16 j) { // 0x82E9F9 WriteRegWord(A1B1, LoadBg_28[1]); WriteRegWord(DAS1L, *(uint16 *)((uint8 *)LoadBg_28 + 5)); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); return j + 7; } @@ -4678,7 +4481,7 @@ void LoadLevelScrollAndCre(void) { // 0x82EA73 for (j = ram7F_start + ram7F_start + (ram7F_start >> 1); ; custom_background[v1 >> 1] = level_data[j >> 1]) { j -= 2; v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) break; } v3 = ram7F_start >> 1; @@ -4701,14 +4504,14 @@ void LoadLevelScrollAndCre(void) { // 0x82EA73 RoomDefRoomstate = get_RoomDefRoomstate(roomdefroomstate_ptr); rdf_scroll_ptr = RoomDefRoomstate->rdf_scroll_ptr; if (rdf_scroll_ptr >= 0) { - R18_ = RoomDefRoomstate->rdf_scroll_ptr; - LOBYTE(R20_) = room_height_in_scrolls - 1; + uint16 r18 = RoomDefRoomstate->rdf_scroll_ptr; + uint8 r20 = room_height_in_scrolls - 1; uint8 v8 = 2; uint8 v9 = 0; v10 = 0; do { - if (v10 == (uint8)R20_) - v8 = R18_ + 1; + if (v10 == r20) + v8 = r18 + 1; v12 = v10; v11 = 0; do { @@ -4793,7 +4596,7 @@ void GameOptionsMenu_1_LoadingOptionsScreen(void) { // 0x82EC11 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_82EC3D = { 1, 1, 0x18, LONGPTR(0x8edc00), 0x0800 }; SetupDmaTransfer(&unk_82EC3D); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); reg_BG1HOFS = 0; reg_BG1VOFS = 0; reg_BG2HOFS = 0; @@ -4806,7 +4609,7 @@ void GameOptionsMenu_1_LoadingOptionsScreen(void) { // 0x82EC11 DecompressToMem(0x9791C4, g_ram + 0x1d000); DecompressToMem(0x97938D, g_ram + 0x1d800); DecompressToMem(0x97953A, g_ram + 0x1e000); - for (j = 1023; (j & 0x8000u) == 0; --j) + for (j = 1023; (j & 0x8000) == 0; --j) ram3000.pause_menu_map_tilemap[j] = custom_background[j + 5375]; menu_option_index = 0; DeleteAllOptionsMenuObjects_(); @@ -4837,10 +4640,8 @@ void OptionsMenu_AddToVramQueue(void) { // 0x82ECFF } void OptionsMenuFunc5(uint16 a, uint16 k, uint16 j) { // 0x82ED28 - R18_ = a; do { - *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + k) = R18_ | *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap - + k) & 0xE3FF; + *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + k) = a | *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + k) & 0xE3FF; k += 2; j -= 2; } while (j); @@ -4854,18 +4655,18 @@ static Func_V *const kGameOptionsMenuItemFuncs[5] = { // 0x82ED42 }; void GameOptionsMenu_3_OptionsScreen(void) { if ((joypad1_newkeys & kButton_Up) != 0) { - QueueSfx1_Max6(0x37u); - if ((--menu_option_index & 0x8000u) != 0) + QueueSfx1_Max6(0x37); + if ((--menu_option_index & 0x8000) != 0) menu_option_index = 4; } else if ((joypad1_newkeys & kButton_Down) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); if (++menu_option_index == 5) menu_option_index = 0; } - if ((joypad1_newkeys & 0x8000u) != 0) { + if ((joypad1_newkeys & 0x8000) != 0) { game_options_screen_index = 11; } else if ((joypad1_newkeys & kButton_A) != 0 || (joypad1_newkeys & kButton_Start) != 0) { - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); kGameOptionsMenuItemFuncs[menu_option_index](); } } @@ -4974,7 +4775,7 @@ void GameOptionsMenu_5_DissolveOutScreen(void) { // 0x82EF18 for (int i = 1023; i >= 0; --i) ram3000.pause_menu_map_tilemap[i] = custom_background[i + 9471]; } else { - for (j = 1023; (j & 0x8000u) == 0; --j) + for (j = 1023; (j & 0x8000) == 0; --j) ram3000.pause_menu_map_tilemap[j] = custom_background[j + 8447]; } menu_option_index = 0; @@ -4982,15 +4783,15 @@ void GameOptionsMenu_5_DissolveOutScreen(void) { // 0x82EF18 menu_option_index = 1; OptionsMenuFunc7(); menu_option_index = 4; - CreateOptionsMenuObject_(4u, addr_stru_82F4D0); + CreateOptionsMenuObject_(4, addr_stru_82F4D0); } else { if (japanese_text_flag) { - for (k = 1023; (k & 0x8000u) == 0; --k) { + for (k = 1023; (k & 0x8000) == 0; --k) { v1 = custom_background[k + 7423]; ram3000.pause_menu_map_tilemap[k] = v1; } } else { - for (m = 1023; (m & 0x8000u) == 0; --m) { + for (m = 1023; (m & 0x8000) == 0; --m) { v1 = custom_background[m + 6399]; ram3000.pause_menu_map_tilemap[m] = v1; } @@ -5000,7 +4801,7 @@ void GameOptionsMenu_5_DissolveOutScreen(void) { // 0x82EF18 OptionsMenuFunc6(); } } else { - for (n = 1023; (n & 0x8000u) == 0; --n) + for (n = 1023; (n & 0x8000) == 0; --n) ram3000.pause_menu_map_tilemap[n] = custom_background[n + 5375]; OptionsMenuFunc4(); uint16 v6 = 0; // bug @@ -5035,21 +4836,21 @@ static Func_V *const kGameOptionsMenuSpecialSettings[3] = { // 0x82F024 }; void GameOptionsMenu_8_SpecialSettings(void) { if ((joypad1_newkeys & kButton_Up) != 0) { - QueueSfx1_Max6(0x37u); - if ((--menu_option_index & 0x8000u) != 0) + QueueSfx1_Max6(0x37); + if ((--menu_option_index & 0x8000) != 0) menu_option_index = 2; } else if ((joypad1_newkeys & kButton_Down) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); if (++menu_option_index == 3) menu_option_index = 0; } - if ((joypad1_newkeys & 0x8000u) == 0) { + if ((joypad1_newkeys & 0x8000) == 0) { if ((joypad1_newkeys & (kButton_Start | kButton_Left | kButton_Right | kButton_A)) != 0) { - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); kGameOptionsMenuSpecialSettings[menu_option_index](); } } else { - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); menu_option_index = 0; GameOptionsMenuItemFunc_4(); } @@ -5102,9 +4903,9 @@ static const uint16 word_82F204[16] = { // 0x82F159 void GameOptionsMenu_7_ControllerSettings(void) { if ((joypad1_newkeys & kButton_Up) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); uint16 v0 = --menu_option_index; - if ((menu_option_index & 0x8000u) == 0) { + if ((menu_option_index & 0x8000) == 0) { if (v0 != 6) return; game_options_screen_index = 10; @@ -5115,7 +4916,7 @@ void GameOptionsMenu_7_ControllerSettings(void) { return; } if ((joypad1_newkeys & kButton_Down) != 0) { - QueueSfx1_Max6(0x37u); + QueueSfx1_Max6(0x37); uint16 v1 = menu_option_index + 1; menu_option_index = v1; if (v1 == 7) { @@ -5128,7 +4929,7 @@ void GameOptionsMenu_7_ControllerSettings(void) { return; } } else if (joypad1_newkeys) { - QueueSfx1_Max6(0x38u); + QueueSfx1_Max6(0x38); static Func_V *const kOptionsMenuControllerFuncs[9] = { OptionsMenuControllerFunc_0, OptionsMenuControllerFunc_0, @@ -5193,7 +4994,6 @@ void OptionsPreInstr_F2A9(uint16 v0) { // 0x82F2A9 int v2 = game_options_screen_index; uint16 v3 = off_82F2ED[v2]; if (v3) { - R18_ = off_82F2ED[v2]; const uint16 *v4 = (const uint16 *)RomPtr_82(v3 + 4 * menu_option_index); int v5 = v0 >> 1; enemy_projectile_y_pos[v5 + 13] = *v4; @@ -5244,17 +5044,17 @@ void OptionsPreInstr_F376(uint16 k) { // 0x82F376 void OptionsPreInstr_F3A0(uint16 k) { // 0x82F3A0 switch (game_options_screen_index) { - case 6u: + case 6: if (reg_INIDISP == 0x80) { int v1 = k >> 1; enemy_projectile_E[v1 + 15] = 1; enemy_projectile_y_vel[v1 + 17] = -2890; } break; - case 9u: + case 9: enemy_projectile_x_vel[(k >> 1) + 3] -= 2; break; - case 0xAu: + case 0xA: enemy_projectile_x_vel[(k >> 1) + 3] += 2; break; } @@ -5336,7 +5136,7 @@ uint8 OptionsMenuFunc8(void) { int v0 = 0, v2; do { v2 = v0; - *(uint16 *)&g_ram[off_82F54A[v0 >> 1]] = word_82F575[(uint16)(2 * enemy_projectile_F[(v0 >> 1) + 13]) >> 1]; + *(uint16 *)&g_ram[off_82F54A[v0 >> 1]] = word_82F575[enemy_projectile_F[(v0 >> 1) + 13]]; v0 += 2; } while (v2 < 12); return 0; @@ -5356,7 +5156,7 @@ void OptionsMenuFunc6(void) { v4 = v0; int v1 = v0 >> 1; uint16 v2 = g_word_82F639[v1]; - const uint16 *v3 = (const uint16 *)RomPtr_82(g_off_82F647[(uint16)(2 * enemy_projectile_F[v1 + 13]) >> 1]); + const uint16 *v3 = (const uint16 *)RomPtr_82(g_off_82F647[enemy_projectile_F[v1 + 13]]); *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + v2) = *v3; *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[1] + v2) = v3[1]; *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[2] + v2) = v3[2]; @@ -5383,24 +5183,24 @@ void OptionsMenuControllerFunc_0(void) { // 0x82F6B9 uint16 v0 = 12; while ((word_82F575[v0 >> 1] & joypad1_newkeys) == 0) { v0 -= 2; - if ((v0 & 0x8000u) != 0) + if ((v0 & 0x8000) != 0) return; } - R18_ = v0 >> 1; + uint16 r18 = v0 >> 1; uint16 v1 = 2 * menu_option_index + 2; if (!sign16(2 * menu_option_index - 12)) v1 = 0; uint16 v2 = v1; for (int i = 5; i >= 0; --i) { - if (enemy_projectile_F[(v2 >> 1) + 13] == R18_) + if (enemy_projectile_F[(v2 >> 1) + 13] == r18) break; v2 += 2; if ((int16)(v2 - 14) >= 0) v2 = 0; } int v4 = menu_option_index; - R20_ = enemy_projectile_F[v4 + 13]; - enemy_projectile_F[v4 + 13] = R18_; - enemy_projectile_F[(v2 >> 1) + 13] = R20_; + uint16 r20 = enemy_projectile_F[v4 + 13]; + enemy_projectile_F[v4 + 13] = r18; + enemy_projectile_F[(v2 >> 1) + 13] = r20; OptionsMenuFunc6(); -} \ No newline at end of file +} diff --git a/src/sm_84.c b/src/sm_84.c index 06c3c78..ad1c200 100644 --- a/src/sm_84.c +++ b/src/sm_84.c @@ -23,11 +23,10 @@ #define kPlmTileDataOffs ((uint16*)RomFixedPtr(0x8487d5)) #define kPlmStartingTileNumber ((uint16*)RomFixedPtr(0x8487dd)) - - void CallPlmPreInstr(uint32 ea, uint16 k); const uint8 *CallPlmInstr(uint32 ea, const uint8 *j, uint16 k); - +uint8 CallPlmHeaderFunc(uint32 ea, uint16 j); +const uint8 *PlmInstr_LoadItemPlmGfx(const uint8 *plmp, uint16 k); void SetGoldenTorizoPalette(uint16 a) { // 0x848000 int16 v1; @@ -56,21 +55,21 @@ void LoadRoomPlmGfx(void) { // 0x848232 } void ClearSoundsWhenGoingThroughDoor(void) { // 0x848250 - CallSomeSamusCode(0x1Du); + CallSomeSamusCode(0x1D); } void UNUSED_sub_848258(void) { // 0x848258 if (samus_movement_type << 8 == 768 || samus_movement_type << 8 == 5120) - QueueSfx1_Max15(0x32u); + QueueSfx1_Max15(0x32); } void PlaySpinJumpSoundIfSpinJumping(void) { // 0x848270 - CallSomeSamusCode(0x1Cu); + CallSomeSamusCode(0x1C); } void UNUSED_sub_848278(void) { // 0x848278 if (samus_movement_type << 8 == 768 || samus_movement_type << 8 == 5120) - QueueSfx1_Max15(0x30u); + QueueSfx1_Max15(0x30); } void CalculatePlmBlockCoords(uint16 k) { // 0x848290 @@ -118,21 +117,19 @@ void LoadXrayBlocks(void) { // 0x84831A for (j = RoomDefRoomstate->xray_special_casing_ptr; ; j += 4) { const uint8 *v6 = RomPtr_8F(j); v7 = GET_WORD(v6); - if (!GET_WORD(v6)) + if (!v7) break; - R18_ = (uint8)v7; - R20_ = v6[1]; - LoadBlockToXrayTilemap(GET_WORD(v6 + 2), (uint8)v7, R20_); + LoadBlockToXrayTilemap(GET_WORD(v6 + 2), (uint8)v7, v6[1]); } } } void EnablePLMs(void) { // 0x8483AD - plm_flag |= 0x8000u; + plm_flag |= 0x8000; } void DisablePLMs(void) { // 0x8483B8 - plm_flag &= ~0x8000u; + plm_flag &= ~0x8000; } void ClearPLMs(void) { // 0x8483C3 @@ -141,136 +138,15 @@ void ClearPLMs(void) { // 0x8483C3 plm_item_gfx_index = 0; } -uint8 CallPlmHeaderFunc(uint32 ea, uint16 j) { - switch (ea) { - case fnnullsub_67: - case fnnullsub_290: - case fnnullsub_68: - case fnnullsub_84BAFA: - case fnnullsub_71: - case fnnullsub_72: - case fnnullsub_69: return 0; - case fnPlmSetup_CrumbleBotwoonWall: return PlmSetup_CrumbleBotwoonWall(j); - case fnPlmSetup_SetrupWreckedShipEntrance: return PlmSetup_SetrupWreckedShipEntrance(j); - case fnPlmSetup_BTS_Brinstar_0x80_Floorplant: return PlmSetup_BTS_Brinstar_0x80_Floorplant(j); - case fnPlmSetup_BTS_Brinstar_0x81_Ceilingplant: return PlmSetup_BTS_Brinstar_0x81_Ceilingplant(j); - case fnPlmSetup_B6D3_MapStation: return PlmSetup_B6D3_MapStation(j); - case fnPlmSetup_Bts47_MapStationRightAccess: return PlmSetup_Bts47_MapStationRightAccess(j); - case fnPlmSetup_Bts4_MapStationLeftAccess: return PlmSetup_Bts4_MapStationLeftAccess(j); - case fnPlmSetup_PlmB6DF_EnergyStation: return PlmSetup_PlmB6DF_EnergyStation(j); - case fnPlmSetup_PlmB6EB_EnergyStation: return PlmSetup_PlmB6EB_EnergyStation(j); - case fnPlmSetup_B6E3_EnergyStationRightAccess: return PlmSetup_B6E3_EnergyStationRightAccess(j); - case fnPlmSetup_B6E7_EnergyStationLeftAccess: return PlmSetup_B6E7_EnergyStationLeftAccess(j); - case fnPlmSetup_B6EF_MissileStationRightAccess: return PlmSetup_B6EF_MissileStationRightAccess(j); - case fnPlmSetup_B6F3_MissileStationLeftAccess: return PlmSetup_B6F3_MissileStationLeftAccess(j); - case fnPlmSetup_B638_Rightwards_Extension: return PlmSetup_B638_Rightwards_Extension(j); - case fnPlmSetup_B63F_Leftwards_Extension: return PlmSetup_B63F_Leftwards_Extension(j); - case fnPlmSetup_B643_Downwards_Extension: return PlmSetup_B643_Downwards_Extension(j); - case fnPlmSetup_B647_Upwards_Extension: return PlmSetup_B647_Upwards_Extension(j); - case fnPlmSetup_B703_ScrollPLM: return PlmSetup_B703_ScrollPLM(j); - case fnPlmSetup_B707_SolidScrollPLM: return PlmSetup_B707_SolidScrollPLM(j); - case fnPlmSetup_B6FF_ScrollBlockTouch: return PlmSetup_B6FF_ScrollBlockTouch(j); - case fnPlmSetup_DeactivatePlm: return PlmSetup_DeactivatePlm(j); - case fnPlmSetup_ReturnCarryClear: return PlmSetup_ReturnCarryClear(j); - case fnPlmSetup_ReturnCarrySet: return PlmSetup_ReturnCarrySet(j); - case fnPlmSetup_D094_EnemyBreakableBlock: return PlmSetup_D094_EnemyBreakableBlock(j); - case fnUNUSED_sub_84B3E3: return UNUSED_sub_84B3E3(j); - case fnPlmSetup_B70F_IcePhysics: return PlmSetup_B70F_IcePhysics(j); - case fnPlmSetup_QuicksandSurface: return PlmSetup_QuicksandSurface(j); - case fnPlmSetup_B71F_SubmergingQuicksand: return PlmSetup_B71F_SubmergingQuicksand(j); - case fnPlmSetup_B723_SandfallsSlow: return PlmSetup_B723_SandfallsSlow(j); - case fnPlmSetup_B727_SandFallsFast: return PlmSetup_B727_SandFallsFast(j); - case fnPlmSetup_QuicksandSurfaceB: return PlmSetup_QuicksandSurfaceB(j); - case fnPlmSetup_B737_SubmergingQuicksand: return PlmSetup_B737_SubmergingQuicksand(j); - case fnPlmSetup_B73B_B73F_SandFalls: return PlmSetup_B73B_B73F_SandFalls(j); - case fnPlmSetup_ClearShitroidInvisibleWall: return PlmSetup_ClearShitroidInvisibleWall(j); - case fnPlmSetup_B767_ClearShitroidInvisibleWall: return PlmSetup_B767_ClearShitroidInvisibleWall(j); - case fnPlmSetup_B76B_SaveStationTrigger: return PlmSetup_B76B_SaveStationTrigger(j); - case fnPlmSetup_B76F_SaveStation: return PlmSetup_B76F_SaveStation(j); - case fnPlmSetup_MotherBrainRoomEscapeDoor: return PlmSetup_MotherBrainRoomEscapeDoor(j); - case fnPlmSetup_B7EB_EnableSoundsIn32Frames: return PlmSetup_B7EB_EnableSoundsIn32Frames(j); - case fnPlmSetup_SpeedBoosterEscape: return PlmSetup_SpeedBoosterEscape(j); - case fnPlmSetup_ShaktoolsRoom: return PlmSetup_ShaktoolsRoom(j); - case fnPlmSetup_B974: return PlmSetup_B974(j); - case fnPlmSetup_B9C1_CrittersEscapeBlock: return PlmSetup_B9C1_CrittersEscapeBlock(j); - case fnPlmSetup_B9ED_CrittersEscapeBlock: return PlmSetup_B9ED_CrittersEscapeBlock(j); - case fnsub_84B9F1: return sub_84B9F1(j); - case fnPlmSetup_BB30_CrateriaMainstreetEscape: return PlmSetup_BB30_CrateriaMainstreetEscape(j); - case fnPlmSetup_C806_LeftGreenGateTrigger: return PlmSetup_C806_LeftGreenGateTrigger(j); - case fnPlmSetup_C80A_RightGreenGateTrigger: return PlmSetup_C80A_RightGreenGateTrigger(j); - case fnPlmSetup_C80E_LeftRedGateTrigger: return PlmSetup_C80E_LeftRedGateTrigger(j); - case fnPlmSetup_C812_RightRedGateTrigger: return PlmSetup_C812_RightRedGateTrigger(j); - case fnPlmSetup_C81E_LeftYellowGateTrigger: return PlmSetup_C81E_LeftYellowGateTrigger(j); - case fnPlmSetup_C822_RightYellowGateTrigger: return PlmSetup_C822_RightYellowGateTrigger(j); - case fnPlmSetup_C816_LeftBlueGateTrigger: return PlmSetup_C816_LeftBlueGateTrigger(j); - case fnPlmSetup_C81A_RightBlueGateTrigger: return PlmSetup_C81A_RightBlueGateTrigger(j); - case fnPlmSetup_C82A_DownwardsClosedGate: return PlmSetup_C82A_DownwardsClosedGate(j); - case fnPlmSetup_C832_UpwardsClosedGate: return PlmSetup_C832_UpwardsClosedGate(j); - case fnPlmSetup_C826_DownwardsOpenGate: return PlmSetup_C826_DownwardsOpenGate(j); - case fnPlmSetup_C82E_UpwardsOpenGate: return PlmSetup_C82E_UpwardsOpenGate(j); - case fnPlmSetup_C836_DownwardsGateShootblock: return PlmSetup_C836_DownwardsGateShootblock(j); - case fnPlmSetup_C73A_UpwardsGateShootblock: return PlmSetup_C73A_UpwardsGateShootblock(j); - case fnPlmSetup_C794_GreyDoor: return PlmSetup_C794_GreyDoor(j); - case fnPlmSetup_Door_Colored: return PlmSetup_Door_Colored(j); - case fnPlmSetup_Door_Blue: return PlmSetup_Door_Blue(j); - case fnPlmSetup_Door_Strange: return PlmSetup_Door_Strange(j); - case fnPlmSetup_D028_D02C_Unused: return PlmSetup_D028_D02C_Unused(j); - case fnPlmSetup_RespawningSpeedBoostBlock: return PlmSetup_RespawningSpeedBoostBlock(j); - case fnPlmSetup_RespawningCrumbleBlock: return PlmSetup_RespawningCrumbleBlock(j); - case fnPlmSetup_RespawningShotBlock: return PlmSetup_RespawningShotBlock(j); - case fnPlmSetup_RespawningBombBlock: return PlmSetup_RespawningBombBlock(j); - case fnPlmSetup_RespawningBombBlock2: return PlmSetup_RespawningBombBlock2(j); - case fnPlmSetup_RespawningPowerBombBlock: return PlmSetup_RespawningPowerBombBlock(j); - case fnPlmSetup_D08C_SuperMissileBlockRespawning: return PlmSetup_D08C_SuperMissileBlockRespawning(j); - case fnPlmSetup_D08C_CrumbleBlock: return PlmSetup_D08C_CrumbleBlock(j); - case fnPlmSetup_D0DC_BreakableGrappleBlock: return PlmSetup_D0DC_BreakableGrappleBlock(j); - case fnPlmSetup_D0D8_SetVFlag: return PlmSetup_D0D8_SetVFlag(j); - case fnPlmSetup_D0D8_ClearVflag: return PlmSetup_D0D8_ClearVflag(j); - case fnPlmSetup_D0E8_GiveSamusDamage: return PlmSetup_D0E8_GiveSamusDamage(j); - case fnPlmSetup_D113_LowerNorfairChozoRoomPlug: return PlmSetup_D113_LowerNorfairChozoRoomPlug(j); - case fnPlmSetup_D127: return PlmSetup_D127(j); - case fnPlmSetup_D138: return PlmSetup_D138(j); - case fnPlmSetup_D6DA_LowerNorfairChozoHandTrigger: return PlmSetup_D6DA_LowerNorfairChozoHandTrigger(j); - case fnPlmSetup_MotherBrainGlass: return PlmSetup_MotherBrainGlass(j); - case fnPlmSetup_DeletePlmIfAreaTorizoDead: return PlmSetup_DeletePlmIfAreaTorizoDead(j); - case fnPlmSetup_MakeBllockChozoHandTrigger: return PlmSetup_MakeBllockChozoHandTrigger(j); - case fnPlmSetup_D6F2_WreckedShipChozoHandTrigger: return PlmSetup_D6F2_WreckedShipChozoHandTrigger(j); - case fnPlmSetup_D700_MakePlmAirBlock_Unused: return PlmSetup_D700_MakePlmAirBlock_Unused(j); - case fnPlmSetup_D704_AlteranateLowerNorfairChozoHand_Unused: return PlmSetup_D704_AlteranateLowerNorfairChozoHand_Unused(j); - case fnPlmSetup_D708_LowerNorfairChozoBlockUnused: return PlmSetup_D708_LowerNorfairChozoBlockUnused(j); - case fnPlmSetup_D70C_NoobTube: return PlmSetup_D70C_NoobTube(j); - case fnPlmSetup_EyeDoorEye: return PlmSetup_EyeDoorEye(j); - case fnPlmSetup_EyeDoor: return PlmSetup_EyeDoor(j); - case fnPlmSetup_SetMetroidRequiredClearState: return PlmSetup_SetMetroidRequiredClearState(j); - case fnPlmSetup_DraygonCannonFacingRight: return PlmSetup_DraygonCannonFacingRight(j); - case fnPlmSetup_DraygonCannonFacingDiagonalRight: return PlmSetup_DraygonCannonFacingDiagonalRight(j); - case fnPlmSetup_DraygonCannonFacingLeft: return PlmSetup_DraygonCannonFacingLeft(j); - case fnPlmSetup_DraygonCannonFacingDiagonalLeft: return PlmSetup_DraygonCannonFacingDiagonalLeft(j); - case fnPlmSetup_DraygonCannon: return PlmSetup_DraygonCannon(j); - case fnsub_84EE4D: return sub_84EE4D(j); - case fnsub_84EE52: return sub_84EE52(j); - case fnsub_84EE57: return sub_84EE57(j); - case fnsub_84EE5C: return sub_84EE5C(j); - case fnsub_84EE64: return sub_84EE64(j); - case fnsub_84EE77: return sub_84EE77(j); - case fnsub_84EE7C: return sub_84EE7C(j); - case fnsub_84EE81: return sub_84EE81(j); - case fnsub_84EE86: return sub_84EE86(j); - case fnsub_84EE8E: return sub_84EE8E(j); - case fnsub_84EEAB: return sub_84EEAB(j); - default: return Unreachable(); - } -} - -void SpawnHardcodedPlm(const void *p) { // 0x8483D7 - SpawnHardcodedPlmArgs *pp = (SpawnHardcodedPlmArgs *)p; +void SpawnHardcodedPlm(SpawnHardcodedPlmArgs p) { // 0x8483D7 + SpawnHardcodedPlmArgs *pp = &p; int16 v2; PlmHeader_Size4 *PlmHeader_Size4; uint16 v1 = 78; while (plm_header_ptr[v1 >> 1]) { v1 -= 2; - if ((v1 & 0x8000u) != 0) { + if ((v1 & 0x8000) != 0) { return; } } @@ -295,15 +171,15 @@ void SpawnHardcodedPlm(const void *p) { // 0x8483D7 void SpawnRoomPLM(uint16 k) { // 0x84846A RoomPlmEntry *rpe; int16 x_block; - PlmHeader_Size4 *PlmHeader_Size4; + PlmHeader_Size4 *PH; uint16 v1 = 78; while (plm_header_ptr[v1 >> 1]) { v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) return; } - rpe = (k == 0x12) ? (RoomPlmEntry *)&R18_ : get_RoomPlmEntry(k); + rpe = (k == 0x12) ? (RoomPlmEntry *)(g_ram + 0x12) : get_RoomPlmEntry(k); uint16 prod = Mult8x8(rpe->y_block, room_width_in_blocks); x_block = rpe->x_block; int v4 = v1 >> 1; @@ -313,13 +189,14 @@ void SpawnRoomPLM(uint16 k) { // 0x84846A plm_header_ptr[v4] = rpe->plm_header_ptr_; plm_variables[v4] = 0; plm_pre_instrs[v4] = FUNC16(PlmPreInstr_Empty2); - plm_instr_list_ptrs[v4] = get_PlmHeader_Size4(pp)->instr_list_ptr; + PH = get_PlmHeader_Size4(pp); + plm_instr_list_ptrs[v4] = PH->instr_list_ptr; plm_instruction_timer[v4] = 1; plm_instruction_draw_ptr[v4] = addr_kDefaultPlmDrawInstruction; plm_timers[v4] = 0; plm_id = v1; - PlmHeader_Size4 = get_PlmHeader_Size4(pp); - CallPlmHeaderFunc(PlmHeader_Size4->func_ptr | 0x840000, v1); + + CallPlmHeaderFunc(PH->func_ptr | 0x840000, v1); } void PlmPreInstr_Empty2(void) { // 0x8484E6 @@ -333,7 +210,7 @@ uint8 SpawnPLM(uint16 a) { // 0x8484E7 uint16 v1 = 78; while (plm_header_ptr[v1 >> 1]) { v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) return 0; } int v3 = v1 >> 1; @@ -362,8 +239,7 @@ CoroutineRet PlmHandler_Async(void) { // 0x8485B4 CallPlmPreInstr(plm_pre_instrs[plm_id >> 1] | 0x840000, plm_id); if (--plm_instruction_timer[plm_id >> 1]) continue; - const uint8 *base, *v5; - base = RomPtr_84(0x8000) - 0x8000; + const uint8 *base = RomBankBase(0x84), *v5; v5 = base + plm_instr_list_ptrs[plm_id >> 1]; while (1) { if ((GET_WORD(v5) & 0x8000) == 0) @@ -378,7 +254,7 @@ CoroutineRet PlmHandler_Async(void) { // 0x8485B4 plm_instr_list_ptrs[plm_id >> 1] = v5 - base; COROUTINE_AWAIT(1, DisplayMessageBox_Async(queued_message_box_index)); queued_message_box_index = 0; - base = RomPtr_84(0x8000) - 0x8000; + base = RomBankBase(0x84); v5 = base + plm_instr_list_ptrs[plm_id >> 1]; } } @@ -396,185 +272,6 @@ NEXT_PLM:; COROUTINE_END(0); } -void CallPlmPreInstr(uint32 ea, uint16 k) { - switch (ea) { - case fnPlmPreInstr_nullsub_60: return; - case fnPlmPreInstr_nullsub_301: return; - case fnPlmPreInstr_Empty: return; - case fnPlmPreInstr_Empty2: return; - case fnPlmPreInstr_Empty3: return; - case fnPlmPreInstr_Empty4: return; - case fnPlmPreInstr_Empty5: return; - case fnnullsub_351: return; - case fnnullsub_84BAFA: return; - case fnPlmSetup_BTS_Brinstar_0x80_Floorplant: PlmSetup_BTS_Brinstar_0x80_Floorplant(k); return; - case fnPlmSetup_BTS_Brinstar_0x81_Ceilingplant: PlmSetup_BTS_Brinstar_0x81_Ceilingplant(k); return; - case fnPlmPreInstr_B7EB_DecTimerEnableSoundsDeletePlm: PlmPreInstr_B7EB_DecTimerEnableSoundsDeletePlm(k); return; - case fnPlmPreInstr_WakeAndLavaIfBoosterCollected: PlmPreInstr_WakeAndLavaIfBoosterCollected(k); return; - case fnPlmPreInstr_WakePLMAndStartFxMotionSamusFarLeft: PlmPreInstr_WakePLMAndStartFxMotionSamusFarLeft(k); return; - case fnPlmPreInstr_AdvanceLavaSamusMovesLeft: PlmPreInstr_AdvanceLavaSamusMovesLeft(k); return; - case fnPlmPreInstr_ShaktoolsRoom: PlmPreInstr_ShaktoolsRoom(k); return; - case fnPlmPreInstr_OldTourianEscapeShaftEscape: PlmPreInstr_OldTourianEscapeShaftEscape(k); return; - case fnPlmPreInstr_EscapeRoomBeforeOldTourianEscapeShaft: PlmPreInstr_EscapeRoomBeforeOldTourianEscapeShaft(k); return; - case fnPlmPreInstr_WakePlmIfTriggered: PlmPreInstr_WakePlmIfTriggered(k); return; - case fnPlmPreInstr_WakePlmIfTriggeredOrSamusBelowPlm: PlmPreInstr_WakePlmIfTriggeredOrSamusBelowPlm(k); return; - case fnPlmPreInstr_WakePlmIfTriggeredOrSamusAbovePlm: PlmPreInstr_WakePlmIfTriggeredOrSamusAbovePlm(k); return; - case fnPlmPreInstr_DeletePlmAndSpawnTriggerIfBlockDestroyed: PlmPreInstr_DeletePlmAndSpawnTriggerIfBlockDestroyed(k); return; - case fnPlmPreInstr_IncrementRoomArgIfShotBySuperMissile: PlmPreInstr_IncrementRoomArgIfShotBySuperMissile(k); return; - case fnPlmPreInstr_WakePlmIfSamusHasBombs: PlmPreInstr_WakePlmIfSamusHasBombs(k); return; - case fnPlmPreInstr_WakePlmIfRoomArgumentDoorIsSet: PlmPreInstr_WakePlmIfRoomArgumentDoorIsSet(k); return; - case fnPlmPreInstr_GotoLinkIfShotWithSuperMissile: PlmPreInstr_GotoLinkIfShotWithSuperMissile(k); return; - case fnPlmPreInstr_GotoLinkIfTriggered: PlmPreInstr_GotoLinkIfTriggered(k); return; - case fnPlmPreInstr_WakeIfTriggered: PlmPreInstr_WakeIfTriggered(k); return; - case fnPlmPreInstr_GoToLinkInstrIfShot: PlmPreInstr_GoToLinkInstrIfShot(k); return; - case fnPlmPreInstr_GoToLinkInstrIfShotWithPowerBomb: PlmPreInstr_GoToLinkInstrIfShotWithPowerBomb(k); return; - case fnPlmPreInstr_GoToLinkInstrIfShotWithAnyMissile: PlmPreInstr_GoToLinkInstrIfShotWithAnyMissile(k); return; - case fnPlmPreInstr_GoToLinkInstrIfShotWithSuperMissile: PlmPreInstr_GoToLinkInstrIfShotWithSuperMissile(k); return; - case fnPlmPreInstr_GoToLinkInstruction: PlmPreInstr_GoToLinkInstruction(k); return; - case fnPlmPreInstr_PlayDudSound: PlmPreInstr_PlayDudSound(k); return; - case fnPlmPreInstr_GotoLinkIfBoss1Dead: PlmPreInstr_GotoLinkIfBoss1Dead(k); return; - case fnPlmPreInstr_GotoLinkIfMiniBossDead: PlmPreInstr_GotoLinkIfMiniBossDead(k); return; - case fnPlmPreInstr_GotoLinkIfTorizoDead: PlmPreInstr_GotoLinkIfTorizoDead(k); return; - case fnPlmPreInstr_GotoLinkIfEnemyDeathQuotaOk: PlmPreInstr_GotoLinkIfEnemyDeathQuotaOk(k); return; - case fnPlmPreInstr_GotoLinkIfTourianStatueFinishedProcessing: PlmPreInstr_GotoLinkIfTourianStatueFinishedProcessing(k); return; - case fnPlmPreInstr_GotoLinkIfCrittersEscaped: PlmPreInstr_GotoLinkIfCrittersEscaped(k); return; - case fnPlmPreInstr_PositionSamusAndInvincible: PlmPreInstr_PositionSamusAndInvincible(k); return; - case fnPlmPreInstr_WakeOnKeyPress: PlmPreInstr_WakeOnKeyPress(k); return; - case fnnullsub_359: return; - case fnnullsub_73: - case fnnullsub_74: - case fnnullsub_75: - case fnnullsub_76: - case fnnullsub_77: - case fnnullsub_78: - case fnnullsub_79: - case fnnullsub_80: - case fnnullsub_81: - case fnlocret_848AE0: return; - case fnPlmPreInstr_SetMetroidsClearState_Ev0x10: PlmPreInstr_SetMetroidsClearState_Ev0x10(k); return; - case fnPlmPreInstr_SetMetroidsClearState_Ev0x11: PlmPreInstr_SetMetroidsClearState_Ev0x11(k); return; - case fnPlmPreInstr_SetMetroidsClearState_Ev0x12: PlmPreInstr_SetMetroidsClearState_Ev0x12(k); return; - case fnPlmPreInstr_SetMetroidsClearState_Ev0x13: PlmPreInstr_SetMetroidsClearState_Ev0x13(k); return; - default: Unreachable(); - } -} - -const uint8 *CallPlmInstr(uint32 ea, const uint8 *j, uint16 k) { - switch (ea) { - case fnPlmInstr_Sleep: return PlmInstr_Sleep(j, k); - case fnPlmInstr_Delete: return PlmInstr_Delete(j, k); - case fnPlmInstr_PreInstr: return PlmInstr_PreInstr(j, k); - case fnPlmInstr_ClearPreInstr: return PlmInstr_ClearPreInstr(j, k); - case fnPlmInstr_CallFunction: return PlmInstr_CallFunction(j, k); - case fnPlmInstr_Goto: return PlmInstr_Goto(j, k); - case fnPlmInstr_DecrementAndBranchNonzero: return PlmInstr_DecrementAndBranchNonzero(j, k); - case fnPlmInstr_SetTimer: return PlmInstr_SetTimer(j, k); - case fnPlmInstr_LoadItemPlmGfx: return PlmInstr_LoadItemPlmGfx(j, k); - case fnPlmInstr_CopyFromRamToVram: return PlmInstr_CopyFromRamToVram(j, k); - case fnPlmInstr_GotoIfBossBitSet: return PlmInstr_GotoIfBossBitSet(j, k); - case fnPlmInstr_GotoIfEventSet: return PlmInstr_GotoIfEventSet(j, k); - case fnPlmInstr_SetEvent: return PlmInstr_SetEvent(j, k); - case fnPlmInstr_GotoIfChozoSet: return PlmInstr_GotoIfChozoSet(j, k); - case fnPlmInstr_SetRoomChozoBit: return PlmInstr_SetRoomChozoBit(j, k); - case fnPlmInstr_GotoIfItemBitSet: return PlmInstr_GotoIfItemBitSet(j, k); - case fnPlmInstr_SetItemBit: return PlmInstr_SetItemBit(j, k); - case fnPlmInstr_PickupBeamAndShowMessage: return PlmInstr_PickupBeamAndShowMessage(j, k); - case fnPlmInstr_PickupEquipmentAndShowMessage: return PlmInstr_PickupEquipmentAndShowMessage(j, k); - case fnPlmInstr_PickupEquipmentAddGrappleShowMessage: return PlmInstr_PickupEquipmentAddGrappleShowMessage(j, k); - case fnPlmInstr_PickupEquipmentAddXrayShowMessage: return PlmInstr_PickupEquipmentAddXrayShowMessage(j, k); - case fnPlmInstr_CollectHealthEnergyTank: return PlmInstr_CollectHealthEnergyTank(j, k); - case fnPlmInstr_CollectHealthReserveTank: return PlmInstr_CollectHealthReserveTank(j, k); - case fnPlmInstr_CollectAmmoMissileTank: return PlmInstr_CollectAmmoMissileTank(j, k); - case fnPlmInstr_CollectAmmoSuperMissileTank: return PlmInstr_CollectAmmoSuperMissileTank(j, k); - case fnPlmInstr_CollectAmmoPowerBombTank: return PlmInstr_CollectAmmoPowerBombTank(j, k); - case fnPlmInstr_SetLinkReg: return PlmInstr_SetLinkReg(j, k); - case fnPlmInstr_Call: return PlmInstr_Call(j, k); - case fnPlmInstr_Return: return PlmInstr_Return(j, k); - case fnPlmInstr_GotoIfDoorBitSet: return PlmInstr_GotoIfDoorBitSet(j, k); - case fnPlmInstr_IncrementDoorHitCounterAndJGE: return PlmInstr_IncrementDoorHitCounterAndJGE(j, k); - case fnPlmInstr_IncrementArgumentAndJGE: return PlmInstr_IncrementArgumentAndJGE(j, k); - case fnPlmInstr_SetBTS: return PlmInstr_SetBTS(j, k); - case fnPlmInstr_DrawPlmBlock: return PlmInstr_DrawPlmBlock(j, k); - case fnPlmInstr_DrawPlmBlock_: return PlmInstr_DrawPlmBlock_(j, k); - case fnPlmInstr_ProcessAirScrollUpdate: return PlmInstr_ProcessAirScrollUpdate(j, k); - case fnPlmInstr_ProcessSolidScrollUpdate: return PlmInstr_ProcessSolidScrollUpdate(j, k); - case fnPlmInstr_QueueMusic: return PlmInstr_QueueMusic(j, k); - case fnPlmInstr_ClearMusicQueueAndQueueTrack: return PlmInstr_ClearMusicQueueAndQueueTrack(j, k); - case fnPlmInstr_QueueSfx1_Max6: return PlmInstr_QueueSfx1_Max6(j, k); - case fnPlmInstr_QueueSfx2_Max6: return PlmInstr_QueueSfx2_Max6(j, k); - case fnPlmInstr_QueueSfx3_Max6: return PlmInstr_QueueSfx3_Max6(j, k); - case fnPlmInstr_QueueSfx1_Max15: return PlmInstr_QueueSfx1_Max15(j, k); - case fnPlmInstr_QueueSfx2_Max15: return PlmInstr_QueueSfx2_Max15(j, k); - case fnPlmInstr_QueueSfx3_Max15: return PlmInstr_QueueSfx3_Max15(j, k); - case fnPlmInstr_QueueSfx1_Max3: return PlmInstr_QueueSfx1_Max3(j, k); - case fnPlmInstr_QueueSfx2_Max3: return PlmInstr_QueueSfx2_Max3(j, k); - case fnPlmInstr_QueueSfx_Max3: return PlmInstr_QueueSfx_Max3(j, k); - case fnPlmInstr_QueueSfx1_Max9: return PlmInstr_QueueSfx1_Max9(j, k); - case fnPlmInstr_QueueSfx2_Max9: return PlmInstr_QueueSfx2_Max9(j, k); - case fnPlmInstr_QueueSfx3_Max9: return PlmInstr_QueueSfx3_Max9(j, k); - case fnPlmInstr_QueueSfx1_Max1: return PlmInstr_QueueSfx1_Max1(j, k); - case fnPlmInstr_QueueSfx2_Max1: return PlmInstr_QueueSfx2_Max1(j, k); - case fnPlmInstr_QueueSfx3_Max1: return PlmInstr_QueueSfx3_Max1(j, k); - case fnPlmInstr_ActivateMapStation: return PlmInstr_ActivateMapStation(j, k); - case fnPlmInstr_ActivateEnergyStation: return PlmInstr_ActivateEnergyStation(j, k); - case fnPlmInstr_ActivateMissileStation: return PlmInstr_ActivateMissileStation(j, k); - case fnPlmInstr_ActivateSaveStationAndGotoIfNo: return PlmInstr_ActivateSaveStationAndGotoIfNo(j, k); - case fnPlmInstr_GotoIfSamusNear: return PlmInstr_GotoIfSamusNear(j, k); - case fnPlmInstr_MovePlmDownOneBlock: return PlmInstr_MovePlmDownOneBlock(j, k); - case fnPlmInstr_Scroll_0_1_Blue: return PlmInstr_Scroll_0_1_Blue(j, k); - case fnPlmInstr_MovePlmDownOneBlock_0: return PlmInstr_MovePlmDownOneBlock_0(j, k); - case fnPlmInstr_DealDamage_2: return PlmInstr_DealDamage_2(j, k); - case fnPlmInstr_GiveInvincibility: return PlmInstr_GiveInvincibility(j, k); - case fnPlmInstr_Draw0x38FramesOfRightTreadmill: return PlmInstr_Draw0x38FramesOfRightTreadmill(j, k); - case fnPlmInstr_Draw0x38FramesOfLeftTreadmill: return PlmInstr_Draw0x38FramesOfLeftTreadmill(j, k); - case fnPlmInstr_GotoIfSamusHealthFull: return PlmInstr_GotoIfSamusHealthFull(j, k); - case fnPlmInstr_GotoIfMissilesFull: return PlmInstr_GotoIfMissilesFull(j, k); - case fnPlmInstr_PlaceSamusOnSaveStation: return PlmInstr_PlaceSamusOnSaveStation(j, k); - case fnPlmInstr_DisplayGameSavedMessageBox: return PlmInstr_DisplayGameSavedMessageBox(j, k); - case fnPlmInstr_EnableMovementAndSetSaveStationUsed: return PlmInstr_EnableMovementAndSetSaveStationUsed(j, k); - case fnPlmInstr_SetCrittersEscapedEvent: return PlmInstr_SetCrittersEscapedEvent(j, k); - case fnPlmInstr_JumpIfSamusHasNoBombs: return PlmInstr_JumpIfSamusHasNoBombs(j, k); - case fnPlmInstr_MovePlmRight4Blocks: return PlmInstr_MovePlmRight4Blocks(j, k); - case fnPlmInstr_ClearTrigger: return PlmInstr_ClearTrigger(j, k); - case fnPlmInstr_SpawnEnemyProjectile: return PlmInstr_SpawnEnemyProjectile(j, k); - case fnPlmInstr_WakeEnemyProjectileAtPlmPos: return PlmInstr_WakeEnemyProjectileAtPlmPos(j, k); - case fnPlmInstr_SetGreyDoorPreInstr: return PlmInstr_SetGreyDoorPreInstr(j, k); - case fnPlmInstr_FxBaseYPos_0x2D2: return PlmInstr_FxBaseYPos_0x2D2(j, k); - case fnPlmInstr_GotoIfRoomArgLess: return PlmInstr_GotoIfRoomArgLess(j, k); - case fnPlmInstr_SpawnFourMotherBrainGlass: return PlmInstr_SpawnFourMotherBrainGlass(j, k); - case fnPlmInstr_SpawnTorizoStatueBreaking: return PlmInstr_SpawnTorizoStatueBreaking(j, k); - case fnPlmInstr_QueueSong1MusicTrack: return PlmInstr_QueueSong1MusicTrack(j, k); - case fnPlmInstr_TransferWreckedShipChozoSpikesToSlopes: return PlmInstr_TransferWreckedShipChozoSpikesToSlopes(j, k); - case fnPlmInstr_TransferWreckedShipSlopesToChozoSpikes: return PlmInstr_TransferWreckedShipSlopesToChozoSpikes(j, k); - case fnPlmInstr_EnableWaterPhysics: return PlmInstr_EnableWaterPhysics(j, k); - case fnPlmInstr_SpawnN00bTubeCrackEnemyProjectile: return PlmInstr_SpawnN00bTubeCrackEnemyProjectile(j, k); - case fnPlmInstr_DiagonalEarthquake: return PlmInstr_DiagonalEarthquake(j, k); - case fnPlmInstr_Spawn10shardsAnd6n00bs: return PlmInstr_Spawn10shardsAnd6n00bs(j, k); - case fnPlmInstr_ShootEyeDoorProjectileWithProjectileArg: return PlmInstr_ShootEyeDoorProjectileWithProjectileArg(j, k); - case fnPlmInstr_SpawnEyeDoorSweatEnemyProjectile: return PlmInstr_SpawnEyeDoorSweatEnemyProjectile(j, k); - case fnPlmInstr_SpawnTwoEyeDoorSmoke: return PlmInstr_SpawnTwoEyeDoorSmoke(j, k); - case fnPlmInstr_SpawnEyeDoorSmokeProjectile: return PlmInstr_SpawnEyeDoorSmokeProjectile(j, k); - case fnPlmInstr_MoveUpAndMakeBlueDoorFacingRight: return PlmInstr_MoveUpAndMakeBlueDoorFacingRight(j, k); - case fnPlmInstr_MoveUpAndMakeBlueDoorFacingLeft: return PlmInstr_MoveUpAndMakeBlueDoorFacingLeft(j, k); - case fnPlmInstr_DamageDraygonTurret: return PlmInstr_DamageDraygonTurret(j, k); - case fnPlmInstr_DamageDraygonTurretFacingDownRight: return PlmInstr_DamageDraygonTurretFacingDownRight(j, k); - case fnPlmInstr_DamageDraygonTurretFacingUpRight: return PlmInstr_DamageDraygonTurretFacingUpRight(j, k); - case fnPlmInstr_DamageDraygonTurret2: return PlmInstr_DamageDraygonTurret2(j, k); - case fnPlmInstr_DamageDraygonTurretFacingDownLeft: return PlmInstr_DamageDraygonTurretFacingDownLeft(j, k); - case fnPlmInstr_DamageDraygonTurretFacingUpLeft: return PlmInstr_DamageDraygonTurretFacingUpLeft(j, k); - case fnPlmInstr_DrawItemFrame0: return PlmInstr_DrawItemFrame0(j, k); - case fnPlmInstr_DrawItemFrame1: return PlmInstr_DrawItemFrame1(j, k); - case fnPlmInstr_DrawItemFrame_Common: return PlmInstr_DrawItemFrame_Common(j, k); - case fnPlmInstr_ClearChargeBeamCounter: return PlmInstr_ClearChargeBeamCounter(j, k); - case fnPlmInstr_ABD6: return PlmInstr_ABD6(j, k); - case fnPlmInstr_E63B: return PlmInstr_E63B(j, k); - case fnPlmInstr_SetBtsTo1: return PlmInstr_SetBtsTo1(j, k); - case fnPlmInstr_DisableSamusControls: return PlmInstr_DisableSamusControls(j, k); - case fnPlmInstr_EnableSamusControls: return PlmInstr_EnableSamusControls(j, k); - default: Unreachable(); return NULL; - } -} - static inline uint8 *RomPtr_84orRAM(uint16_t addr) { if (addr & 0x8000) { return (uint8*)RomPtr(0x840000 | addr); @@ -605,8 +302,7 @@ void ProcessPlmDrawInstruction(uint16 v0) { // 0x84861E } const uint8 *PlmInstr_Sleep(const uint8 *plmp, uint16 k) { // 0x8486B4 - const uint8 *base = RomPtr_84(0x8000) - 0x8000; - plm_instr_list_ptrs[k >> 1] = plmp - base - 2; + plm_instr_list_ptrs[k >> 1] = plmp - RomBankBase(0x84) - 2; return 0; } @@ -655,27 +351,25 @@ const uint8 *PlmInstr_SetTimer(const uint8 *plmp, uint16 k) { // 0x84874E return plmp + 1; } - const uint8 *PlmInstr_LoadItemPlmGfx(const uint8 *plmp, uint16 k) { // 0x848764 uint16 v2 = plm_item_gfx_index; plm_variables[k >> 1] = plm_item_gfx_index; plm_item_gfx_index = (v2 + 2) & 6; int v3 = v2 >> 1; - int R18 = kPlmVramAddresses[v3]; - int R20 = kPlmTileDataOffs[v3]; + int r18 = kPlmVramAddresses[v3]; + int r20 = kPlmTileDataOffs[v3]; int R22 = kPlmStartingTileNumber[v3]; - const uint8 *base = RomPtr_84(0x8000) - 0x8000; - plm_item_gfx_ptrs[v3] = plmp - base; + plm_item_gfx_ptrs[v3] = plmp - RomBankBase(0x84); int v4 = vram_write_queue_tail; VramWriteEntry *v5 = gVramWriteEntry(vram_write_queue_tail); v5->size = 256; v5->src.addr = GET_WORD(plmp); v5->src.bank = 0x89; - v5->vram_dst = R18; + v5->vram_dst = r18; vram_write_queue_tail = v4 + 7; plmp += 2; - int v7 = R20; - int R24 = R20 + 16; + int v7 = r20; + int R24 = r20 + 16; do { *(uint16 *)((uint8 *)&tile_table.tables[0].top_left + v7) = R22 + (plmp[0] << 10); ++R22; @@ -758,7 +452,7 @@ const uint8 *PlmInstr_PickupBeamAndShowMessage(const uint8 *plmp, uint16 k) { / equipped_beams &= ~((t << 1) & 8); equipped_beams &= ~((t >> 1) & 4); UpdateBeamTilesAndPalette(); - PlayRoomMusicTrackAfterAFrames(0x168u); + PlayRoomMusicTrackAfterAFrames(0x168); DisplayMessageBox(plmp[2]); return plmp + 3; } @@ -767,7 +461,7 @@ const uint8 *PlmInstr_PickupEquipmentAndShowMessage(const uint8 *plmp, uint16 k) uint16 t = GET_WORD(plmp); equipped_items |= t; collected_items |= t; - PlayRoomMusicTrackAfterAFrames(0x168u); + PlayRoomMusicTrackAfterAFrames(0x168); DisplayMessageBox(plmp[2]); return plmp + 3; } @@ -777,8 +471,8 @@ const uint8 *PlmInstr_PickupEquipmentAddGrappleShowMessage(const uint8 *plmp, ui equipped_items |= t; collected_items |= t; AddGrappleToHudTilemap(); - PlayRoomMusicTrackAfterAFrames(0x168u); - DisplayMessageBox(5u); + PlayRoomMusicTrackAfterAFrames(0x168); + DisplayMessageBox(5); return plmp + 2; } @@ -787,16 +481,16 @@ const uint8 *PlmInstr_PickupEquipmentAddXrayShowMessage(const uint8 *plmp, uint1 equipped_items |= t; collected_items |= t; AddXrayToHudTilemap(); - PlayRoomMusicTrackAfterAFrames(0x168u); - DisplayMessageBox(6u); + PlayRoomMusicTrackAfterAFrames(0x168); + DisplayMessageBox(6); return plmp + 2; } const uint8 *PlmInstr_CollectHealthEnergyTank(const uint8 *plmp, uint16 k) { // 0x848968 samus_max_health += GET_WORD(plmp); samus_health = samus_max_health; - PlayRoomMusicTrackAfterAFrames(0x168u); - DisplayMessageBox(1u); + PlayRoomMusicTrackAfterAFrames(0x168); + DisplayMessageBox(1); return plmp + 2; } @@ -804,8 +498,8 @@ const uint8 *PlmInstr_CollectHealthReserveTank(const uint8 *plmp, uint16 k) { / samus_max_reserve_health += GET_WORD(plmp); if (!reserve_health_mode) ++reserve_health_mode; - PlayRoomMusicTrackAfterAFrames(0x168u); - DisplayMessageBox(0x19u); + PlayRoomMusicTrackAfterAFrames(0x168); + DisplayMessageBox(0x19); return plmp + 2; } @@ -814,8 +508,8 @@ const uint8 *PlmInstr_CollectAmmoMissileTank(const uint8 *plmp, uint16 k) { // samus_max_missiles += t; samus_missiles += t; AddMissilesToHudTilemap(); - PlayRoomMusicTrackAfterAFrames(0x168u); - DisplayMessageBox(2u); + PlayRoomMusicTrackAfterAFrames(0x168); + DisplayMessageBox(2); return plmp + 2; } @@ -824,8 +518,8 @@ const uint8 *PlmInstr_CollectAmmoSuperMissileTank(const uint8 *plmp, uint16 k) { samus_max_super_missiles += t; samus_super_missiles += t; AddSuperMissilesToHudTilemap(); - PlayRoomMusicTrackAfterAFrames(0x168u); - DisplayMessageBox(3u); + PlayRoomMusicTrackAfterAFrames(0x168); + DisplayMessageBox(3); return plmp + 2; } @@ -834,8 +528,8 @@ const uint8 *PlmInstr_CollectAmmoPowerBombTank(const uint8 *plmp, uint16 k) { / samus_max_power_bombs += t; samus_power_bombs += t; AddPowerBombsToHudTilemap(); - PlayRoomMusicTrackAfterAFrames(0x168u); - DisplayMessageBox(4u); + PlayRoomMusicTrackAfterAFrames(0x168); + DisplayMessageBox(4); return plmp + 2; } @@ -845,13 +539,12 @@ const uint8 *PlmInstr_SetLinkReg(const uint8 *plmp, uint16 k) { // 0x848A24 } const uint8 *PlmInstr_Call(const uint8 *plmp, uint16 k) { // 0x848A2E - const uint8 *base = RomPtr_84(0x8000) - 0x8000; - plm_instruction_list_link_reg[k >> 1] = plmp - base + 2; + plm_instruction_list_link_reg[k >> 1] = plmp - RomBankBase(0x84) + 2; return INSTRB_RETURN_ADDR(GET_WORD(plmp)); } const uint8 *PlmInstr_Return(const uint8 *plmp, uint16 k) { // 0x848A3A - return RomPtr_84(plm_instruction_list_link_reg[k >> 1]); + return INSTRB_RETURN_ADDR(plm_instruction_list_link_reg[k >> 1]); } const uint8 *PlmInstr_GotoIfDoorBitSet(const uint8 *plmp, uint16 k) { // 0x848A72 @@ -897,11 +590,7 @@ const uint8 *PlmInstr_SetBTS(const uint8 *plmp, uint16 k) { // 0x848AF1 return plmp + 1; } -const uint8 *PlmInstr_DrawPlmBlock(const uint8 *plmp, uint16 k) { // 0x848B05 - return PlmInstr_DrawPlmBlock_(plmp, k); -} - -const uint8 *PlmInstr_DrawPlmBlock_(const uint8 *plmp, uint16 k) { // 0x848B17 +const uint8 *PlmInstr_DrawPlmBlock(const uint8 *plmp, uint16 k) { // 0x848B17 int v2 = k >> 1; uint16 v3 = plm_variable[v2]; level_data[plm_block_indices[v2] >> 1] = v3; @@ -910,8 +599,7 @@ const uint8 *PlmInstr_DrawPlmBlock_(const uint8 *plmp, uint16 k) { // 0x848B17 custom_draw_instr_zero_terminator = 0; plm_instruction_timer[v2] = 1; plm_instruction_draw_ptr[v2] = ADDR16_OF_RAM(custom_draw_instr_num_blocks); - const uint8 *base = RomPtr_84(0x8000) - 0x8000; - plm_instr_list_ptrs[v2] = plmp - base; + plm_instr_list_ptrs[v2] = plmp - RomBankBase(0x84); ProcessPlmDrawInstruction(k); uint16 v4 = plm_id; CalculatePlmBlockCoords(plm_id); @@ -920,15 +608,13 @@ const uint8 *PlmInstr_DrawPlmBlock_(const uint8 *plmp, uint16 k) { // 0x848B17 } const uint8 *PlmInstr_ProcessAirScrollUpdate(const uint8 *plmp, uint16 k) { // 0x848B55 - int v2 = k >> 1; - plm_variable[v2] = 0; - uint16 v3 = plm_room_arguments[v2]; + plm_variable[k >> 1] = 0; + const uint8 *v5 = RomPtr_8F(plm_room_arguments[k >> 1]); while (1) { - const uint8 *v5 = RomPtr_8F(v3); if (v5[0] & 0x80) break; scrolls[v5[0]] = v5[1]; - v3 += 2; + v5 += 2; } int v7 = plm_block_indices[k >> 1] >> 1; level_data[v7] = level_data[v7] & 0xFFF | 0x3000; @@ -936,15 +622,13 @@ const uint8 *PlmInstr_ProcessAirScrollUpdate(const uint8 *plmp, uint16 k) { // } const uint8 *PlmInstr_ProcessSolidScrollUpdate(const uint8 *plmp, uint16 k) { // 0x848B93 - int v2 = k >> 1; - plm_variable[v2] = 0; - uint16 v3 = plm_room_arguments[v2]; + plm_variable[k >> 1] = 0; + const uint8 *v5 = RomPtr_8F(plm_room_arguments[k >> 1]); while (1) { - const uint8 *v5 = RomPtr_8F(v3); if (v5[0] & 0x80) break; scrolls[v5[0]] = v5[1]; - v3 += 2; + v5 += 2; } int v7 = plm_block_indices[k >> 1] >> 1; level_data[v7] = level_data[v7] & 0xFFF | 0xB000; @@ -1045,27 +729,27 @@ const uint8 *PlmInstr_QueueSfx3_Max1(const uint8 *plmp, uint16 k) { // 0x848C85 } const uint8 *PlmInstr_ActivateMapStation(const uint8 *plmp, uint16 k) { // 0x848C8F - *(uint16 *)&map_station_byte_array[area_index] |= 0xFFu; - DisplayMessageBox(0x14u); + *(uint16 *)&map_station_byte_array[area_index] |= 0xFF; + DisplayMessageBox(0x14); has_area_map = 1; return plmp; } const uint8 *PlmInstr_ActivateEnergyStation(const uint8 *plmp, uint16 k) { // 0x848CAF if (samus_max_health != samus_health) { - DisplayMessageBox(0x15u); + DisplayMessageBox(0x15); samus_health = samus_max_health; } - CallSomeSamusCode(1u); + CallSomeSamusCode(1); return plmp; } const uint8 *PlmInstr_ActivateMissileStation(const uint8 *plmp, uint16 k) { // 0x848CD0 if (samus_max_missiles != samus_missiles) { - DisplayMessageBox(0x16u); + DisplayMessageBox(0x16); samus_missiles = samus_max_missiles; } - CallSomeSamusCode(1u); + CallSomeSamusCode(1); return plmp; } @@ -1078,7 +762,7 @@ const uint8 *PlmInstr_ActivateSaveStationAndGotoIfNo(const uint8 *plmp, uint16 k SpawnEnemyProjectileWithRoomGfx(addr_kEproj_SaveStationElectricity, 0); load_station_index = plm_room_arguments[plm_id >> 1] & 7; PrepareBitAccess(load_station_index); - used_save_stations_and_elevators[(uint16)(2 * area_index)] |= bitmask; + used_save_stations_and_elevators[2 * area_index] |= bitmask; SaveToSram(selected_save_slot); return plmp + 2; } @@ -1093,6 +777,34 @@ const uint8 *PlmInstr_GotoIfSamusNear(const uint8 *plmp, uint16 k) { // 0x848D4 return plmp + 4; } +static void PartiallyQueueVramForSingleScreenPlm(uint16 a, uint16 k, uint16 r20, uint16 r28) { // 0x849220 + VramWriteEntry *ent = gVramWriteEntry(k); + ent->vram_dst = r28 | a; + uint16 size = 4 * r20; + VoidP base = plm_draw_tilemap_index + 0xC6C8; + ent[0].size = size; + ent[1].size = size; + ent[0].src = (LongPtr){ base, 126 }; + ent[1].src = (LongPtr){ base + size, 126 }; + // R0/R6 assignments move to caller +} + +static void CalculatePlmDrawTilemapVramDst(uint16 k, uint16 r9, uint16 r12, uint16 r20, uint16 r24, uint16 r26, uint16 r28) { // 0x8491DC + uint16 a; + uint16 prod = (r26 & 0xF) * 0x40; + uint16 v1 = r24 & 0x1F; + if (v1 >= 0x10) { + a = prod + r12 + 2 * v1; + if ((bg1_x_offset & 0x100) != 0) + a -= 1024; + } else { + a = prod + r9 + 2 * v1; + if ((bg1_x_offset & 0x100) != 0) + a += 1024; + } + PartiallyQueueVramForSingleScreenPlm(a, k, r20, r28); +} + void DrawPlm(uint16 k) { // 0x848DAA int16 v2; int16 v5; @@ -1107,234 +819,239 @@ void DrawPlm(uint16 k) { // 0x848DAA VramWriteEntry *v25; int16 v28; int16 v31; - uint16 v35; - uint16 a; - - R9_.addr = addr_unk_605000; - R12_ = addr_unk_6053E0; + uint16 v35, r26, r22; + uint16 a, r24; + uint16 r20, r18; + uint16 r9 = addr_unk_605000; + uint16 r12 = addr_unk_6053E0; uint16 v1 = plm_instruction_draw_ptr[k >> 1]; - R30_ = plm_x_block; - R32_ = plm_y_block; + uint16 x = plm_x_block; + uint16 y = plm_y_block; + uint16 r3; + LongPtr r0, r6; LABEL_2: - R26_ = layer1_y_pos >> 4; - if (!sign16((layer1_y_pos >> 4) + 15 - R32_)) { - v2 = *(uint16 *)RomPtr_84orRAM(v1); - if (v2 < 0) { - R20_ = v2 & 0x7FFF; - if (layer1_x_pos >> 4 == R30_ || (int16)((layer1_x_pos >> 4) - R30_) < 0) { - v20 = (layer1_x_pos >> 4) + 17; - if (v20 != R30_ && (int16)(v20 - R30_) >= 0) { - R24_ = R30_; - R18_ = 0; - R22_ = R26_ + 16; - if ((int16)(R26_ - R32_) < 0) { - R26_ = R32_; - } else { - R18_ = R26_ - R32_; - if (sign16(R32_ + R20_ - R26_)) - return; - bool v21 = R20_ == R18_; - bool v22 = (int16)(R20_ - R18_) < 0; - R20_ -= R18_; - while (v22) - ; - if (v21) - return; - } - R22_ = R20_ + R26_ - R22_; - if ((R22_ & 0x8000u) != 0 || (v23 = (int16)(R20_ - R22_) < 0, (R20_ -= R22_) != 0) && !v23) { - v35 = k; - uint16 v24; - v24 = vram_write_queue_tail; - if ((int16)(vram_write_queue_tail - 240) < 0 - && !sign16(((uint16)(512 - plm_draw_tilemap_index) >> 3) - R20_)) { - R28_ = 0x8000; - CalculatePlmDrawTilemapVramDst(vram_write_queue_tail); - v25 = gVramWriteEntry(v24); - v25[1].vram_dst = v25->vram_dst + 1; - vram_write_queue_tail = v24 + 14; - R18_ *= 2; - R3_.addr = R18_ + v1 + 2; - uint16 v26; - v26 = 0; - while (1) { - R30_ = *(uint16 *)RomPtr_84orRAM(R3_.addr); - uint16 v27, v29; - v27 = R30_ & 0x3FF; - v28 = R30_ & 0xC00; - if ((R30_ & 0xC00) != 0) { - if (v28 == 1024) { - IndirWriteWord(R0_, v26, tile_table.tables[v27].top_right ^ 0x4000); - IndirWriteWord(R6_, v26, tile_table.tables[v27].top_left ^ 0x4000); - v29 = v26 + 2; - IndirWriteWord(R0_, v29, tile_table.tables[v27].bottom_right ^ 0x4000); - IndirWriteWord(R6_, v29, tile_table.tables[v27].bottom_left ^ 0x4000); - } else if (v28 == 2048) { - IndirWriteWord(R0_, v26, tile_table.tables[v27].bottom_left ^ 0x8000); - IndirWriteWord(R6_, v26, tile_table.tables[v27].bottom_right ^ 0x8000); - v29 = v26 + 2; - IndirWriteWord(R0_, v29, tile_table.tables[v27].top_left ^ 0x8000); - IndirWriteWord(R6_, v29, tile_table.tables[v27].top_right ^ 0x8000); - } else { - IndirWriteWord(R0_, v26, tile_table.tables[v27].bottom_right ^ 0xC000); - IndirWriteWord(R6_, v26, tile_table.tables[v27].bottom_left ^ 0xC000); - v29 = v26 + 2; - IndirWriteWord(R0_, v29, tile_table.tables[v27].top_right ^ 0xC000); - IndirWriteWord(R6_, v29, tile_table.tables[v27].top_left ^ 0xC000); - } - } else { - IndirWriteWord(R0_, v26, tile_table.tables[v27].top_left); - IndirWriteWord(R6_, v26, tile_table.tables[v27].top_right); + r26 = layer1_y_pos >> 4; + if (sign16((layer1_y_pos >> 4) + 15 - y)) + return; + v2 = *(uint16 *)RomPtr_84orRAM(v1); + if (v2 < 0) { + r20 = v2 & 0x7FFF; + if (layer1_x_pos >> 4 == x || (int16)((layer1_x_pos >> 4) - x) < 0) { + v20 = (layer1_x_pos >> 4) + 17; + if (v20 != x && (int16)(v20 - x) >= 0) { + r24 = x; + r18 = 0; + r22 = r26 + 16; + if ((int16)(r26 - y) < 0) { + r26 = y; + } else { + r18 = r26 - y; + if (sign16(y + r20 - r26)) + return; + bool v21 = r20 == r18; + bool v22 = (int16)(r20 - r18) < 0; + r20 -= r18; + if (v22) + Unreachable(); + if (v21) + return; + } + r22 = r20 + r26 - r22; + if ((r22 & 0x8000) != 0 || (v23 = (int16)(r20 - r22) < 0, (r20 -= r22) != 0) && !v23) { + v35 = k; + uint16 v24; + v24 = vram_write_queue_tail; + if ((int16)(vram_write_queue_tail - 240) < 0 + && !sign16(((uint16)(512 - plm_draw_tilemap_index) >> 3) - r20)) { + CalculatePlmDrawTilemapVramDst(vram_write_queue_tail, r9, r12, r20, r24, r26, 0x8000); + v25 = gVramWriteEntry(v24); + v25[1].vram_dst = v25[0].vram_dst + 1; + r0 = v25[0].src; + r6 = v25[1].src; + + vram_write_queue_tail = v24 + 14; + r18 *= 2; + r3 = r18 + v1 + 2; + uint16 v26; + v26 = 0; + while (1) { + x = *(uint16 *)RomPtr_84orRAM(r3); + uint16 v27, v29; + v27 = x & 0x3FF; + v28 = x & 0xC00; + if ((x & 0xC00) != 0) { + if (v28 == 1024) { + IndirWriteWord(r0, v26, tile_table.tables[v27].top_right ^ 0x4000); + IndirWriteWord(r6, v26, tile_table.tables[v27].top_left ^ 0x4000); v29 = v26 + 2; - IndirWriteWord(R0_, v29, tile_table.tables[v27].bottom_left); - IndirWriteWord(R6_, v29, tile_table.tables[v27].bottom_right); + IndirWriteWord(r0, v29, tile_table.tables[v27].bottom_right ^ 0x4000); + IndirWriteWord(r6, v29, tile_table.tables[v27].bottom_left ^ 0x4000); + } else if (v28 == 2048) { + IndirWriteWord(r0, v26, tile_table.tables[v27].bottom_left ^ 0x8000); + IndirWriteWord(r6, v26, tile_table.tables[v27].bottom_right ^ 0x8000); + v29 = v26 + 2; + IndirWriteWord(r0, v29, tile_table.tables[v27].top_left ^ 0x8000); + IndirWriteWord(r6, v29, tile_table.tables[v27].top_right ^ 0x8000); + } else { + IndirWriteWord(r0, v26, tile_table.tables[v27].bottom_right ^ 0xC000); + IndirWriteWord(r6, v26, tile_table.tables[v27].bottom_left ^ 0xC000); + v29 = v26 + 2; + IndirWriteWord(r0, v29, tile_table.tables[v27].top_right ^ 0xC000); + IndirWriteWord(r6, v29, tile_table.tables[v27].top_left ^ 0xC000); } - v26 = v29 + 2; - ++R3_.addr; - ++R3_.addr; - plm_draw_tilemap_index += 8; - if (!sign16(plm_draw_tilemap_index - 512)) - break; - if (!--R20_) { + } else { + IndirWriteWord(r0, v26, tile_table.tables[v27].top_left); + IndirWriteWord(r6, v26, tile_table.tables[v27].top_right); + v29 = v26 + 2; + IndirWriteWord(r0, v29, tile_table.tables[v27].bottom_left); + IndirWriteWord(r6, v29, tile_table.tables[v27].bottom_right); + } + v26 = v29 + 2; + ++r3; + ++r3; + plm_draw_tilemap_index += 8; + if (!sign16(plm_draw_tilemap_index - 512)) + break; + if (!--r20) { LABEL_70: - k = v35; - uint16 addr = R3_.addr; - if ((R22_ & 0x8000u) == 0) - addr = R3_.addr + 2 * R22_; - v31 = *(uint16 *)RomPtr_84orRAM(addr); - if (v31) { - R30_ = plm_x_block + (int8)v31; - uint16 v32 = addr + 1; - R32_ = plm_y_block + (int8)*RomPtr_84orRAM(v32); - v1 = v32 + 1; - goto LABEL_2; - } - return; + k = v35; + uint16 addr = r3; + if ((r22 & 0x8000) == 0) + addr = r3 + 2 * r22; + v31 = *(uint16 *)RomPtr_84orRAM(addr); + if (v31) { + x = plm_x_block + (int8)v31; + uint16 v32 = addr + 1; + y = plm_y_block + (int8)*RomPtr_84orRAM(v32); + v1 = v32 + 1; + goto LABEL_2; } + return; } } } } } - } else { - R20_ = v2 & 0x7FFF; - R28_ = 0; - if (sign16(R32_ - R26_)) + } + } else { + r20 = v2 & 0x7FFF; + if (sign16(y - r26)) + return; + r26 = y; + r18 = 0; + r24 = x; + r22 = ((uint16)(layer1_x_pos + 15) >> 4) - 1; + if ((int16)(r22 - x) >= 0 && r22 != x) { + r18 = r22 - x; + if (x + r20 == r22 || (int16)(x + r20 - r22) < 0) return; - R26_ = R32_; - R18_ = 0; - R24_ = R30_; - R22_ = ((uint16)(layer1_x_pos + 15) >> 4) - 1; - if ((int16)(R22_ - R30_) >= 0 && R22_ != R30_) { - R18_ = R22_ - R30_; - if (R30_ + R20_ == R22_ || (int16)(R30_ + R20_ - R22_) < 0) - return; - R20_ -= R18_; - R24_ = R22_; - } - R22_ += 17; - if (!sign16(R22_ - R30_)) { - R22_ = R20_ + R24_ - 1 - R22_; - if ((R22_ & 0x8000u) != 0 || (R20_ -= R22_) != 0) { - v35 = k; - uint16 v3 = vram_write_queue_tail; - if ((int16)(vram_write_queue_tail - 480) < 0 - && !sign16(((uint16)(512 - plm_draw_tilemap_index) >> 3) - R20_)) { - uint16 prod = (R26_ & 0xF) * 0x40; - uint16 v4 = R24_ & 0x1F; - if (v4 >= 0x10u) { - v8 = R12_ + 2 * v4; - a = prod + v8; - if ((bg1_x_offset & 0x100) != 0) - a -= 1024; - } else { - v5 = R9_.addr + 2 * v4; - uint16 RegWord = prod; - a = RegWord + v5; - if ((bg1_x_offset & 0x100) != 0) - a += 1024; - } - R30_ = 2 * R20_; - R34 = a & 0x1F; - if (((2 * R20_ + (a & 0x1F) - 1) & 0xFFE0) != 0) { - if ((int16)(v3 - 228) >= 0 || (int16)(32 - R34) < 0) - return; - uint16 v9 = 2 * (32 - R34); - v10 = gVramWriteEntry(v3); - v10->size = v9; - v10[2].size = v9; - v10->vram_dst = a; - v10[1].vram_dst = a & 0xFFE0 ^ 0x400; - v10[3].vram_dst = v10[1].vram_dst + 32; - v10[2].vram_dst = v10->vram_dst + 32; - R30_ = 4 * R20_; - uint16 v11 = 4 * R20_ - v10->size; - v10[1].size = v11; - v10[3].size = v11; - v12 = plm_draw_tilemap_index - 14648; - v10->src.addr = plm_draw_tilemap_index - 14648; - R0_.addr = v12; - v13 = v10->size + v12; - v10[1].src.addr = v13; - uint16 v14 = v10[1].size + v13; - v10[2].src.addr = v14; - R6_.addr = v14; - v10[3].src.addr = v10[2].size + v14; - v10->src.bank = 126; - R0_.bank = 126; - v10[1].src.bank = 126; - R6_.bank = 126; - v10[2].src.bank = 126; - v10[3].src.bank = 126; - vram_write_queue_tail = v3 + 28; - } else { - PartiallyQueueVramForSingleScreenPlm(a, v3); - v15 = gVramWriteEntry(v3); - v15[1].vram_dst = v15->vram_dst + 32; - vram_write_queue_tail = v3 + 14; - } - R18_ *= 2; - R3_.addr = R18_ + v1 + 2; - uint16 v16 = 0; - while (1) { - R30_ = *(uint16 *)RomPtr_84orRAM(R3_.addr); - uint16 v17 = R30_ & 0x3FF, v19; - v18 = R30_ & 0xC00; - if ((R30_ & 0xC00) != 0) { - if (v18 == 1024) { - IndirWriteWord(R0_, v16, tile_table.tables[v17].top_right ^ 0x4000); - IndirWriteWord(R6_, v16, tile_table.tables[v17].bottom_right ^ 0x4000); - v19 = v16 + 2; - IndirWriteWord(R0_, v19, tile_table.tables[v17].top_left ^ 0x4000); - IndirWriteWord(R6_, v19, tile_table.tables[v17].bottom_left ^ 0x4000); - } else if (v18 == 2048) { - IndirWriteWord(R0_, v16, tile_table.tables[v17].bottom_left ^ 0x8000); - IndirWriteWord(R6_, v16, tile_table.tables[v17].top_left ^ 0x8000); - v19 = v16 + 2; - IndirWriteWord(R0_, v19, tile_table.tables[v17].bottom_right ^ 0x8000); - IndirWriteWord(R6_, v19, tile_table.tables[v17].top_right ^ 0x8000); - } else { - IndirWriteWord(R0_, v16, tile_table.tables[v17].bottom_right ^ 0xC000); - IndirWriteWord(R6_, v16, tile_table.tables[v17].top_right ^ 0xC000); - v19 = v16 + 2; - IndirWriteWord(R0_, v19, tile_table.tables[v17].bottom_left ^ 0xC000); - IndirWriteWord(R6_, v19, tile_table.tables[v17].top_left ^ 0xC000); - } - } else { - IndirWriteWord(R0_, v16, tile_table.tables[v17].top_left); - IndirWriteWord(R6_, v16, tile_table.tables[v17].bottom_left); + r20 -= r18; + r24 = r22; + } + r22 += 17; + if (!sign16(r22 - x)) { + r22 = r20 + r24 - 1 - r22; + if ((r22 & 0x8000) != 0 || (r20 -= r22) != 0) { + v35 = k; + uint16 v3 = vram_write_queue_tail; + if ((int16)(vram_write_queue_tail - 480) < 0 + && !sign16(((uint16)(512 - plm_draw_tilemap_index) >> 3) - r20)) { + uint16 prod = (r26 & 0xF) * 0x40; + uint16 v4 = r24 & 0x1F; + if (v4 >= 0x10) { + v8 = r12 + 2 * v4; + a = prod + v8; + if ((bg1_x_offset & 0x100) != 0) + a -= 1024; + } else { + v5 = r9 + 2 * v4; + uint16 RegWord = prod; + a = RegWord + v5; + if ((bg1_x_offset & 0x100) != 0) + a += 1024; + } + x = 2 * r20; + uint16 R34 = a & 0x1F; + if (((2 * r20 + (a & 0x1F) - 1) & 0xFFE0) != 0) { + if ((int16)(v3 - 228) >= 0 || (int16)(32 - R34) < 0) + return; + uint16 v9 = 2 * (32 - R34); + v10 = gVramWriteEntry(v3); + v10->size = v9; + v10[2].size = v9; + v10[0].vram_dst = a; + v10[1].vram_dst = a & 0xFFE0 ^ 0x400; + v10[3].vram_dst = v10[1].vram_dst + 32; + v10[2].vram_dst = v10->vram_dst + 32; + x = 4 * r20; + uint16 v11 = 4 * r20 - v10->size; + v10[1].size = v11; + v10[3].size = v11; + v12 = plm_draw_tilemap_index - 14648; + v10->src.addr = plm_draw_tilemap_index - 14648; + r0.addr = v12; + v13 = v10->size + v12; + v10[1].src.addr = v13; + uint16 v14 = v10[1].size + v13; + v10[2].src.addr = v14; + r0.bank = 126; + r6.bank = 126; + r6.addr = v14; + v10[3].src.addr = v10[2].size + v14; + v10->src.bank = 126; + v10[1].src.bank = 126; + v10[2].src.bank = 126; + v10[3].src.bank = 126; + vram_write_queue_tail = v3 + 28; + } else { + PartiallyQueueVramForSingleScreenPlm(a, v3, r20, 0); + v15 = gVramWriteEntry(v3); + v15[1].vram_dst = v15[0].vram_dst + 32; + r0 = v15[0].src; + r6 = v15[1].src; + vram_write_queue_tail = v3 + 14; + } + r18 *= 2; + r3 = r18 + v1 + 2; + uint16 v16 = 0; + while (1) { + x = *(uint16 *)RomPtr_84orRAM(r3); + uint16 v17 = x & 0x3FF, v19; + v18 = x & 0xC00; + if ((x & 0xC00) != 0) { + if (v18 == 1024) { + IndirWriteWord(r0, v16, tile_table.tables[v17].top_right ^ 0x4000); + IndirWriteWord(r6, v16, tile_table.tables[v17].bottom_right ^ 0x4000); v19 = v16 + 2; - IndirWriteWord(R0_, v19, tile_table.tables[v17].top_right); - IndirWriteWord(R6_, v19, tile_table.tables[v17].bottom_right); + IndirWriteWord(r0, v19, tile_table.tables[v17].top_left ^ 0x4000); + IndirWriteWord(r6, v19, tile_table.tables[v17].bottom_left ^ 0x4000); + } else if (v18 == 2048) { + IndirWriteWord(r0, v16, tile_table.tables[v17].bottom_left ^ 0x8000); + IndirWriteWord(r6, v16, tile_table.tables[v17].top_left ^ 0x8000); + v19 = v16 + 2; + IndirWriteWord(r0, v19, tile_table.tables[v17].bottom_right ^ 0x8000); + IndirWriteWord(r6, v19, tile_table.tables[v17].top_right ^ 0x8000); + } else { + IndirWriteWord(r0, v16, tile_table.tables[v17].bottom_right ^ 0xC000); + IndirWriteWord(r6, v16, tile_table.tables[v17].top_right ^ 0xC000); + v19 = v16 + 2; + IndirWriteWord(r0, v19, tile_table.tables[v17].bottom_left ^ 0xC000); + IndirWriteWord(r6, v19, tile_table.tables[v17].top_left ^ 0xC000); } - v16 = v19 + 2; - R3_.addr += 2; - plm_draw_tilemap_index += 8; - if (!sign16(plm_draw_tilemap_index - 512)) - break; - if (!--R20_) - goto LABEL_70; + } else { + IndirWriteWord(r0, v16, tile_table.tables[v17].top_left); + IndirWriteWord(r6, v16, tile_table.tables[v17].bottom_left); + v19 = v16 + 2; + IndirWriteWord(r0, v19, tile_table.tables[v17].top_right); + IndirWriteWord(r6, v19, tile_table.tables[v17].bottom_right); } + v16 = v19 + 2; + r3 += 2; + plm_draw_tilemap_index += 8; + if (!sign16(plm_draw_tilemap_index - 512)) + break; + if (!--r20) + goto LABEL_70; } } } @@ -1343,49 +1060,6 @@ LABEL_70: } -void CalculatePlmDrawTilemapVramDst(uint16 k) { // 0x8491DC - int16 v2; - int16 v5; - uint16 a; - - uint16 prod = (R26_ & 0xF) * 0x40; - uint16 v1 = R24_ & 0x1F; - if (v1 >= 0x10u) { - v5 = R12_ + 2 * v1; - uint16 RegWord = prod; - a = RegWord + v5; - if ((bg1_x_offset & 0x100) != 0) - a -= 1024; - } else { - v2 = R9_.addr + 2 * v1; - uint16 v3 = prod; - a = v3 + v2; - if ((bg1_x_offset & 0x100) != 0) - a += 1024; - } - PartiallyQueueVramForSingleScreenPlm(a, k); -} - -void PartiallyQueueVramForSingleScreenPlm(uint16 a, uint16 k) { // 0x849220 - VramWriteEntry *v2; - VoidP v4; - - v2 = gVramWriteEntry(k); - v2->vram_dst = R28_ | a; - uint16 v3 = 4 * R20_; - v2->size = 4 * R20_; - v2[1].size = v3; - v4 = plm_draw_tilemap_index - 14648; - v2->src.addr = plm_draw_tilemap_index - 14648; - R0_.addr = v4; - uint16 v5 = v2->size + v4; - v2[1].src.addr = v5; - R6_.addr = v5; - v2->src.bank = 126; - v2[1].src.bank = 126; - R0_.bank = 126; - R6_.bank = 126; -} const uint8 *PlmInstr_MovePlmDownOneBlock(const uint8 *plmp, uint16 k) { // 0x84AB00 plm_block_indices[k >> 1] += 2 * room_width_in_blocks; @@ -1416,7 +1090,7 @@ void PlmPreInstr_PositionSamusAndInvincible(uint16 k) { // 0x84AC89 int v1 = k >> 1; samus_x_pos = plm_variable[v1]; samus_y_pos = plm_variables[v1]; - samus_invincibility_timer |= 0x10u; + samus_invincibility_timer |= 0x10; } const uint8 *PlmInstr_DealDamage_2(const uint8 *plmp, uint16 k) { // 0x84AC9D @@ -1442,14 +1116,14 @@ const uint8 *PlmInstr_Draw0x38FramesOfLeftTreadmill(const uint8 *plmp, uint16 k) const uint8 *PlmInstr_GotoIfSamusHealthFull(const uint8 *plmp, uint16 k) { // 0x84AE35 if (samus_max_health != samus_health) return plmp + 2; - CallSomeSamusCode(1u); + CallSomeSamusCode(1); return INSTRB_RETURN_ADDR(GET_WORD(plmp)); } const uint8 *PlmInstr_GotoIfMissilesFull(const uint8 *plmp, uint16 k) { // 0x84AEBF if (samus_max_missiles != samus_missiles) return plmp + 2; - CallSomeSamusCode(1u); + CallSomeSamusCode(1); return INSTRB_RETURN_ADDR(GET_WORD(plmp)); } @@ -1460,12 +1134,12 @@ const uint8 *PlmInstr_PlaceSamusOnSaveStation(const uint8 *plmp, uint16 k) { // } const uint8 *PlmInstr_DisplayGameSavedMessageBox(const uint8 *plmp, uint16 k) { // 0x84B024 - DisplayMessageBox(0x18u); + DisplayMessageBox(0x18); return plmp; } const uint8 *PlmInstr_EnableMovementAndSetSaveStationUsed(const uint8 *plmp, uint16 k) { // 0x84B030 - CallSomeSamusCode(1u); + CallSomeSamusCode(1); save_station_lockout_flag = 1; return plmp; } @@ -1484,9 +1158,9 @@ uint8 PlmSetup_SetrupWreckedShipEntrance(uint16 j) { // 0x84B04A } uint8 PlmSetup_BTS_Brinstar_0x80_Floorplant(uint16 j) { // 0x84B0DC - if ((((uint8)samus_y_radius + (uint8)samus_y_pos - 1) & 0xF) == 15) { + if (((samus_y_radius + samus_y_pos - 1) & 0xF) == 15) { int v1 = plm_block_indices[j >> 1] >> 1; - level_data[v1] &= 0x8FFFu; + level_data[v1] &= 0x8FFF; int v2 = j >> 1; plm_variable[v2] = samus_x_pos; plm_variables[v2] = samus_y_pos - 1; @@ -1497,11 +1171,11 @@ uint8 PlmSetup_BTS_Brinstar_0x80_Floorplant(uint16 j) { // 0x84B0DC } uint8 PlmSetup_BTS_Brinstar_0x81_Ceilingplant(uint16 j) { // 0x84B113 - if ((((uint8)samus_y_pos - (uint8)samus_y_radius) & 0xF) != 0) { + if (((samus_y_pos - samus_y_radius) & 0xF) != 0) { plm_header_ptr[j >> 1] = 0; } else { int v1 = plm_block_indices[j >> 1] >> 1; - level_data[v1] &= 0x8FFFu; + level_data[v1] &= 0x8FFF; int v2 = j >> 1; plm_variable[v2] = samus_x_pos; plm_variables[v2] = samus_y_pos + 1; @@ -1513,7 +1187,7 @@ uint8 ActivateStationIfSamusCannonLinedUp(uint16 a, uint16 j) { // 0x84B146 uint16 v2 = 78; while (a != plm_block_indices[v2 >> 1]) { v2 -= 2; - if ((v2 & 0x8000u) != 0) + if ((v2 & 0x8000) != 0) goto LABEL_7; } CalculatePlmBlockCoords(plm_id); @@ -1521,7 +1195,7 @@ uint8 ActivateStationIfSamusCannonLinedUp(uint16 a, uint16 j) { // 0x84B146 int v3 = v2 >> 1; plm_instr_list_ptrs[v3] = plm_instruction_list_link_reg[v3]; plm_instruction_timer[v3] = 1; - CallSomeSamusCode(6u); + CallSomeSamusCode(6); return 1; } LABEL_7: @@ -1675,13 +1349,13 @@ uint8 PlmSetup_B6FF_ScrollBlockTouch(uint16 j) { // 0x84B393 uint16 v3 = 78; while (v2 != plm_block_indices[v3 >> 1]) { v3 -= 2; - if ((v3 & 0x8000u) != 0) { + if ((v3 & 0x8000) != 0) { while (1) ; } } int v4 = v3 >> 1; - if ((plm_variable[v4] & 0x8000u) == 0) { + if ((plm_variable[v4] & 0x8000) == 0) { plm_variable[v4] = 0x8000; ++plm_instr_list_ptrs[v4]; ++plm_instr_list_ptrs[v4]; @@ -1692,7 +1366,7 @@ uint8 PlmSetup_B6FF_ScrollBlockTouch(uint16 j) { // 0x84B393 uint8 PlmSetup_DeactivatePlm(uint16 j) { // 0x84B3C1 int v1 = plm_block_indices[j >> 1] >> 1; - level_data[v1] &= 0x8FFFu; + level_data[v1] &= 0x8FFF; return 0; } @@ -1706,7 +1380,7 @@ uint8 PlmSetup_ReturnCarrySet(uint16 j) { // 0x84B3D2 uint8 PlmSetup_D094_EnemyBreakableBlock(uint16 j) { // 0x84B3D4 int v1 = plm_block_indices[j >> 1] >> 1; - level_data[v1] &= 0xFFFu; + level_data[v1] &= 0xFFF; return 0; } @@ -1716,8 +1390,7 @@ uint8 UNUSED_sub_84B3E3(uint16 j) { // 0x84B3E3 } uint8 PlmSetup_B70F_IcePhysics(uint16 j) { // 0x84B3EB - if ((((uint8)samus_y_radius + (uint8)samus_y_pos - 1) & 0xF) == 7 - || (((uint8)samus_y_radius + (uint8)samus_y_pos - 1) & 0xF) == 15) { + if (((samus_y_radius + samus_y_pos - 1) & 0xF) == 7 || ((samus_y_radius + samus_y_pos - 1) & 0xF) == 15) { *(uint16 *)&samus_x_decel_mult = 16; } return 0; @@ -1741,7 +1414,7 @@ uint8 PlmSetup_QuicksandSurface(uint16 j) { samus_echoes_sound_flag = 0; samus_x_extra_run_subspeed = 0; samus_x_extra_run_speed = 0; - samus_x_base_subspeed &= ~0x8000u; + samus_x_base_subspeed &= ~0x8000; samus_x_base_speed = 0; uint16 v1 = 0; if ((equipped_items & 0x20) != 0) @@ -1797,66 +1470,42 @@ uint8 PlmSetup_B727_SandFallsFast(uint16 j) { // 0x84B4B6 return 0; } -static Func_Y_U8 *const kPlmSetup_QuicksandSurfaceB[4] = { // 0x84B4C4 - PlmSetup_QuicksandSurfaceB_0, - PlmSetup_QuicksandSurfaceB_1, - PlmSetup_QuicksandSurfaceB_2, - PlmSetup_QuicksandSurfaceB_0, -}; - uint8 PlmSetup_QuicksandSurfaceB(uint16 j) { - if ((samus_collision_direction & 2) == 0) - return 0; + return 0; - uint16 v1 = 0; - if ((equipped_items & 0x20) != 0) - v1 = 2; - uint16 v2 = R18_; - R18_ = R20_; - R20_ = v2; - uint8 rv = kPlmSetup_QuicksandSurfaceB[samus_y_dir & 3](v1); - uint16 v3 = R18_; - R18_ = R20_; - R20_ = v3; - return rv; -} + if (cur_coll_amt32 == NULL) { + printf("ERROR: PlmSetup_QuicksandSurfaceB is broken!!\n"); + Unreachable(); + return 0; + } -uint8 PlmSetup_QuicksandSurfaceB_0(uint16 j) { // 0x84B500 - static const uint16 word_84B53D[2] = { - 0x30, - 0x30, - }; - if ((samus_collision_direction & 0xF) == 3) { + switch (samus_y_dir & 3) { + case 0: + case 3: + if ((samus_collision_direction & 0xF) == 3) { + if (samus_contact_damage_index == 1) { + *cur_coll_amt32 = 0; + return 1; + } else { + if ((uint16)(*cur_coll_amt32 >> 8) > 0x30) + *cur_coll_amt32 = (*cur_coll_amt32 & 0xff0000ff) | 0x3000;// R19_ = 0x30; + flag_samus_in_quicksand++; + } + } + break; + case 2: if (samus_contact_damage_index == 1) { - R18_ = 0; - R20_ = 0; + *cur_coll_amt32 = 0; return 1; } else { - if (word_84B53D[j >> 1] < R19_) - R19_ = word_84B53D[j >> 1]; - ++flag_samus_in_quicksand; + flag_samus_in_quicksand++; + return 0; } } return 0; } -uint8 PlmSetup_QuicksandSurfaceB_1(uint16 j) { // 0x84B528 - return 0; -} - -uint8 PlmSetup_QuicksandSurfaceB_2(uint16 j) { // 0x84B52A - if (samus_contact_damage_index == 1) { - R18_ = 0; - R20_ = 0; - return 1; - } else { - flag_samus_in_quicksand++; - return 0; - } -} - - uint8 PlmSetup_B737_SubmergingQuicksand(uint16 j) { // 0x84B541 samus_y_subspeed = 0; samus_y_speed = 0; @@ -1875,7 +1524,7 @@ uint8 PlmSetup_ClearShitroidInvisibleWall(uint16 j) { // 0x84B551 uint16 v1 = plm_block_indices[j >> 1]; v2 = 10; do { - level_data[v1 >> 1] &= 0xFFFu; + level_data[v1 >> 1] &= 0xFFF; v1 += room_width_in_blocks * 2; --v2; } while (v2); @@ -1909,7 +1558,7 @@ uint8 PlmSetup_B76B_SaveStationTrigger(uint16 j) { // 0x84B590 uint16 v3 = 78; while (v2 != plm_block_indices[v3 >> 1]) { v3 -= 2; - if ((v3 & 0x8000u) != 0) + if ((v3 & 0x8000) != 0) return 1; } int v4 = v3 >> 1; @@ -1935,7 +1584,7 @@ uint8 PlmSetup_MotherBrainRoomEscapeDoor(uint16 j) { // 0x84B5F8 WriteLevelDataBlockTypeAndBts(v3, 0xD0FF); WriteLevelDataBlockTypeAndBts( room_width_in_blocks * 2 + v3, - 0xD0FFu); + 0xD0FF); return 0; } @@ -1961,7 +1610,7 @@ void PlmPreInstr_B7EB_DecTimerEnableSoundsDeletePlm(uint16 k) { // 0x84B7DD void PlmPreInstr_WakeAndLavaIfBoosterCollected(uint16 k) { // 0x84B7EF if ((collected_items & 0x2000) != 0) { - if ((fx_target_y_pos & 0x8000u) != 0) { + if ((fx_target_y_pos & 0x8000) != 0) { plm_header_ptr[k >> 1] = 0; } else { fx_y_vel = -128; @@ -1981,7 +1630,7 @@ void PlmPreInstr_WakeAndLavaIfBoosterCollected(uint16 k) { // 0x84B7EF } void PlmPreInstr_WakePLMAndStartFxMotionSamusFarLeft(uint16 k) { // 0x84B82A - if (samus_x_pos <= 0xAE0u) { + if (samus_x_pos <= 0xAE0) { fx_timer = 1; int v1 = k >> 1; plm_instruction_timer[v1] = 1; @@ -2005,8 +1654,8 @@ void PlmPreInstr_AdvanceLavaSamusMovesLeft(uint16 k) { // 0x84B846 uint16 v2 = plm_timers[v1]; int v3 = v2 >> 1; uint16 v4 = g_word_84B876[v3]; - if ((v4 & 0x8000u) != 0) { - SetEventHappened(0x15u); + if ((v4 & 0x8000) != 0) { + SetEventHappened(0x15); } else if (v4 >= samus_x_pos) { if (g_word_84B876[v3 + 1] < fx_base_y_pos) fx_base_y_pos = g_word_84B876[v3 + 1]; @@ -2016,7 +1665,7 @@ void PlmPreInstr_AdvanceLavaSamusMovesLeft(uint16 k) { // 0x84B846 } uint8 PlmSetup_SpeedBoosterEscape(uint16 j) { // 0x84B89C - if (CheckEventHappened(0x15u)) + if (CheckEventHappened(0x15)) plm_header_ptr[j >> 1] = 0; return 0; } @@ -2026,8 +1675,8 @@ void PlmPreInstr_ShaktoolsRoom(uint16 k) { // 0x84B8B0 *(uint16 *)scrolls = 257; *(uint16 *)&scrolls[2] = 257; } - if (samus_x_pos > 0x348u) { - SetEventHappened(0xDu); + if (samus_x_pos > 0x348) { + SetEventHappened(0xD); plm_header_ptr[k >> 1] = 0; } } @@ -2038,40 +1687,30 @@ uint8 PlmSetup_ShaktoolsRoom(uint16 j) { // 0x84B8DC return 0; } -uint8 WakePlmIfSamusIsBelowAndRightOfTarget(uint16 k) { // 0x84B8FD - uint8 v1 = R18_ >= samus_x_pos; - if (R18_ < samus_x_pos) { - v1 = R20_ >= samus_y_pos; - if (R20_ < samus_y_pos) { - v1 = k & 1; - int v2 = k >> 1; - ++plm_instr_list_ptrs[v2]; - ++plm_instr_list_ptrs[v2]; - plm_instruction_timer[v2] = 1; - } +uint8 WakePlmIfSamusIsBelowAndRightOfTarget(uint16 k, uint16 x_r18, uint16 y_r20) { // 0x84B8FD + if (x_r18 < samus_x_pos && y_r20 < samus_y_pos) { + int v2 = k >> 1; + plm_instr_list_ptrs[v2] += 2; + plm_instruction_timer[v2] = 1; + return false; } - return v1; + return true; } void PlmPreInstr_OldTourianEscapeShaftEscape(uint16 k) { // 0x84B927 - R18_ = 240; - R20_ = 2080; - if (!WakePlmIfSamusIsBelowAndRightOfTarget(k)) + if (!WakePlmIfSamusIsBelowAndRightOfTarget(k, 240, 2080)) SpawnEnemyProjectileWithRoomGfx(0xB4B1, 0); } void PlmPreInstr_EscapeRoomBeforeOldTourianEscapeShaft(uint16 k) { // 0x84B948 - R18_ = 240; - R20_ = 1344; - if (!WakePlmIfSamusIsBelowAndRightOfTarget(k)) { + if (!WakePlmIfSamusIsBelowAndRightOfTarget(k, 240, 1344)) { fx_y_vel = -104; fx_timer = 16; } } uint8 PlmSetup_B974(uint16 j) { // 0x84B96C - R38 = 0; - R40 = -1; + // Implemented in BlockReact_ShootableAir return 0; } @@ -2089,27 +1728,25 @@ uint8 PlmSetup_B9C1_CrittersEscapeBlock(uint16 j) { // 0x84B978 } const uint8 *PlmInstr_SetCrittersEscapedEvent(const uint8 *plmp, uint16 k) { // 0x84B9B9 - SetEventHappened(0xFu); + SetEventHappened(0xF); return plmp; } uint8 PlmSetup_B9ED_CrittersEscapeBlock(uint16 j) { // 0x84B9C5 uint16 v1 = plm_block_indices[j >> 1]; WriteLevelDataBlockTypeAndBts(v1, 0xC04F); - uint16 v2 = room_width_in_blocks * 2 + v1; + uint16 v2 = v1 + room_width_in_blocks * 2; WriteLevelDataBlockTypeAndBts(v2, 0xD0FF); - WriteLevelDataBlockTypeAndBts( - room_width_in_blocks * 2 + v2, - 0xD0FFu); + WriteLevelDataBlockTypeAndBts(v2 + room_width_in_blocks * 2, 0xD0FF); return 0; } -uint8 sub_84B9F1(uint16 j) { // 0x84B9F1 +uint8 sub_84B9F1(uint16 j) { // 0x84B9F1 uint16 v1 = plm_block_indices[j >> 1]; level_data[v1 >> 1] = level_data[v1 >> 1] & 0xFFF | 0x8000; uint16 v2 = room_width_in_blocks * 2 + v1; level_data[v2 >> 1] = level_data[v2 >> 1] & 0xFFF | 0x8000; - uint16 v3 = room_width_in_blocks + room_width_in_blocks + v2; + uint16 v3 = room_width_in_blocks + room_width_in_blocks + v2; level_data[v3 >> 1] = level_data[v3 >> 1] & 0xFFF | 0x8000; int v4 = (uint16)(room_width_in_blocks * 2 + v3) >> 1; level_data[v4] = level_data[v4] & 0xFFF | 0x8000; @@ -2131,7 +1768,7 @@ void UNUSED_sub_84BAD1(uint16 j) { // 0x84BAD1 } uint8 PlmSetup_BB30_CrateriaMainstreetEscape(uint16 j) { // 0x84BB09 - if (!CheckEventHappened(0xFu)) + if (!CheckEventHappened(0xF)) plm_header_ptr[j >> 1] = 0; return 0; } @@ -2153,7 +1790,7 @@ void PlmPreInstr_WakePlmIfTriggered(uint16 k) { // 0x84BB52 void PlmPreInstr_WakePlmIfTriggeredOrSamusBelowPlm(uint16 k) { // 0x84BB6B CalculatePlmBlockCoords(k); - if (samus_x_pos >> 4 == plm_x_block && (uint16)((samus_y_pos >> 4) - plm_y_block) < 5u + if (samus_x_pos >> 4 == plm_x_block && (uint16)((samus_y_pos >> 4) - plm_y_block) < 5 || plm_timers[k >> 1]) { int v1 = k >> 1; ++plm_instr_list_ptrs[v1]; @@ -2165,7 +1802,7 @@ void PlmPreInstr_WakePlmIfTriggeredOrSamusBelowPlm(uint16 k) { // 0x84BB6B void PlmPreInstr_WakePlmIfTriggeredOrSamusAbovePlm(uint16 k) { // 0x84BBA4 CalculatePlmBlockCoords(k); - if (samus_x_pos >> 4 == plm_x_block && (uint16)((samus_y_pos >> 4) - plm_y_block) >= 0xFFFCu + if (samus_x_pos >> 4 == plm_x_block && (uint16)((samus_y_pos >> 4) - plm_y_block) >= 0xFFFC || plm_timers[k >> 1]) { int v1 = k >> 1; ++plm_instr_list_ptrs[v1]; @@ -2218,7 +1855,7 @@ void PlmPreInstr_GoToLinkInstrIfShotWithPowerBomb(uint16 k) { // 0x84BD26 plm_instruction_timer[v2] = 1; return; } - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); } plm_timers[v2] = 0; } @@ -2241,7 +1878,7 @@ LABEL_4:; plm_instruction_timer[v4] = 1; return; } - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); } plm_timers[k >> 1] = 0; } @@ -2256,7 +1893,7 @@ void PlmPreInstr_GoToLinkInstrIfShotWithSuperMissile(uint16 k) { // 0x84BD88 plm_instruction_timer[v2] = 1; return; } - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); } plm_timers[v2] = 0; } @@ -2271,26 +1908,26 @@ void PlmPreInstr_GoToLinkInstruction(uint16 k) { // 0x84BDB2 void PlmPreInstr_PlayDudSound(uint16 k) { // 0x84BE1C int v2 = k >> 1; if (plm_timers[v2]) - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); plm_timers[v2] = 0; } void PlmPreInstr_GotoLinkIfBoss1Dead(uint16 k) { // 0x84BDD4 - if (CheckBossBitForCurArea(1u) & 1) + if (CheckBossBitForCurArea(1) & 1) PlmPreInstr_GoToLinkInstruction(k); else PlmPreInstr_PlayDudSound(k); } void PlmPreInstr_GotoLinkIfMiniBossDead(uint16 k) { // 0x84BDE3 - if (CheckBossBitForCurArea(2u) & 1) + if (CheckBossBitForCurArea(2) & 1) PlmPreInstr_GoToLinkInstruction(k); else PlmPreInstr_PlayDudSound(k); } void PlmPreInstr_GotoLinkIfTorizoDead(uint16 k) { // 0x84BDF2 - if (CheckBossBitForCurArea(4u) & 1) + if (CheckBossBitForCurArea(4) & 1) PlmPreInstr_GoToLinkInstruction(k); else PlmPreInstr_PlayDudSound(k); @@ -2306,14 +1943,14 @@ void PlmPreInstr_GotoLinkIfEnemyDeathQuotaOk(uint16 k) { // 0x84BE01 } void PlmPreInstr_GotoLinkIfTourianStatueFinishedProcessing(uint16 k) { // 0x84BE1F - if ((tourian_entrance_statue_finished & 0x8000u) == 0) + if ((tourian_entrance_statue_finished & 0x8000) == 0) PlmPreInstr_PlayDudSound(k); else PlmPreInstr_GoToLinkInstruction(k); } void PlmPreInstr_GotoLinkIfCrittersEscaped(uint16 k) { // 0x84BE30 - if (CheckEventHappened(0xFu) & 1) + if (CheckEventHappened(0xF) & 1) PlmPreInstr_GoToLinkInstruction(k); else PlmPreInstr_PlayDudSound(k); @@ -2327,7 +1964,7 @@ const uint8 *PlmInstr_SetGreyDoorPreInstr(const uint8 *plmp, uint16 k) { // 0x8 uint8 PlmSetup_C806_LeftGreenGateTrigger(uint16 j) { // 0x84C54D if ((projectile_type[projectile_index >> 1] & 0xFFF) == 512) return sub_84C63F(j); - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); plm_header_ptr[j >> 1] = 0; return 0; } @@ -2335,7 +1972,7 @@ uint8 PlmSetup_C806_LeftGreenGateTrigger(uint16 j) { // 0x84C54D uint8 PlmSetup_C80A_RightGreenGateTrigger(uint16 j) { // 0x84C56C if ((projectile_type[projectile_index >> 1] & 0xFFF) == 512) return sub_84C647(j); - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); plm_header_ptr[j >> 1] = 0; return 0; } @@ -2346,7 +1983,7 @@ uint8 PlmSetup_C80E_LeftRedGateTrigger(uint16 j) { // 0x84C58B v1 = projectile_type[projectile_index >> 1] & 0xFFF; if (v1 == 256 || v1 == 512) return sub_84C63F(j); - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); plm_header_ptr[j >> 1] = 0; return 0; } @@ -2357,7 +1994,15 @@ uint8 PlmSetup_C812_RightRedGateTrigger(uint16 j) { // 0x84C5AF v1 = projectile_type[projectile_index >> 1] & 0xFFF; if (v1 == 256 || v1 == 512) return sub_84C647(j); - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); + plm_header_ptr[j >> 1] = 0; + return 0; +} + +uint8 PlmSetup_C822_RightYellowGateTrigger(uint16 j) { // 0x84C5F1 + if ((projectile_type[projectile_index >> 1] & 0xFFF) != 768) + return sub_84C647(j); + QueueSfx2_Max6(0x57); plm_header_ptr[j >> 1] = 0; return 0; } @@ -2365,17 +2010,15 @@ uint8 PlmSetup_C812_RightRedGateTrigger(uint16 j) { // 0x84C5AF uint8 PlmSetup_C81E_LeftYellowGateTrigger(uint16 j) { // 0x84C5D3 if ((projectile_type[projectile_index >> 1] & 0xFFF) == 768) return sub_84C63F(j); - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); int v1 = j >> 1; plm_header_ptr[v1] = 0; - PlmSetup_C822_RightYellowGateTrigger(j); - return 0; + return PlmSetup_C822_RightYellowGateTrigger(j); } -uint8 PlmSetup_C822_RightYellowGateTrigger(uint16 j) { // 0x84C5F1 +uint8 PlmSetup_C81A_RightBlueGateTrigger(uint16 j) { // 0x84C627 if ((projectile_type[projectile_index >> 1] & 0xFFF) != 768) return sub_84C647(j); - QueueSfx2_Max6(0x57u); plm_header_ptr[j >> 1] = 0; return 0; } @@ -2384,15 +2027,7 @@ uint8 PlmSetup_C816_LeftBlueGateTrigger(uint16 j) { // 0x84C610 if ((projectile_type[projectile_index >> 1] & 0xFFF) != 768) return sub_84C63F(j); plm_header_ptr[j >> 1] = 0; - PlmSetup_C81A_RightBlueGateTrigger(j); - return 0; -} - -uint8 PlmSetup_C81A_RightBlueGateTrigger(uint16 j) { // 0x84C627 - if ((projectile_type[projectile_index >> 1] & 0xFFF) != 768) - return sub_84C647(j); - plm_header_ptr[j >> 1] = 0; - return 0; + return PlmSetup_C81A_RightBlueGateTrigger(j); } uint8 sub_84C63F(uint16 j) { // 0x84C63F @@ -2403,11 +2038,11 @@ uint8 sub_84C647(uint16 j) { // 0x84C647 return sub_84C64C(j, plm_block_indices[j >> 1] - 2); } -uint8 sub_84C64C(uint16 j, uint16 a) { // 0x84C64C +uint8 sub_84C64C(uint16 j, uint16 a) { // 0x84C64C uint16 v2 = 78; while (a != plm_block_indices[v2 >> 1]) { v2 -= 2; - if ((v2 & 0x8000u) != 0) + if ((v2 & 0x8000) != 0) goto LABEL_7; } int v3; @@ -2523,7 +2158,7 @@ uint8 PlmSetup_Door_Strange(uint16 j) { // 0x84C7E2 uint16 v3 = 78; while (v2 != plm_block_indices[v3 >> 1]) { v3 -= 2; - if ((v3 & 0x8000u) != 0) + if ((v3 & 0x8000) != 0) return 0; } plm_timers[v3 >> 1] = projectile_type[(int16)projectile_index >> 1] & 0x1FFF | 0x8000; @@ -2679,12 +2314,12 @@ uint8 PlmSetup_D08C_CrumbleBlock(uint16 j) { // 0x84CFA0 return 0; } -uint8 PlmSetup_D0DC_BreakableGrappleBlock(uint16 j) { // 0x84CFB5 +uint8 PlmSetup_D0DC_BreakableGrappleBlock(uint16 j) { // 0x84CFB5 int v1 = j >> 1; uint16 v2 = plm_block_indices[v1]; plm_variable[v1] = level_data[v2 >> 1]; *(uint16 *)&BTS[v2 >> 1] = BTS[(v2 >> 1) + 1] << 8; - return PlmSetup_D0D8_SetVFlag(j); + return 0x41; } uint8 PlmSetup_D0D8_SetVFlag(uint16 j) { // 0x84CFCD @@ -2695,7 +2330,7 @@ uint8 PlmSetup_D0D8_ClearVflag(uint16 j) { // 0x84CFD1 return 1; } -uint8 PlmSetup_D0E8_GiveSamusDamage(uint16 j) { // 0x84CFD5 +uint8 PlmSetup_D0E8_GiveSamusDamage(uint16 j) { // 0x84CFD5 ++samus_periodic_damage; return 0x41; } @@ -2731,19 +2366,17 @@ void PlmPreInstr_DeletePlmAndSpawnTriggerIfBlockDestroyed(uint16 k) { // 0x84D1 } uint8 PlmSetup_D6DA_LowerNorfairChozoHandTrigger(uint16 j) { // 0x84D18F - static const SpawnHardcodedPlmArgs unk_84D1DA = { 0x0c, 0x1d, 0xd113 }; - if ((collected_items & 0x200) != 0 && (samus_collision_direction & 0xF) == 3 && (samus_pose == kPose_1D_FaceR_Morphball_Ground || samus_pose == kPose_79_FaceR_Springball_Ground || samus_pose == kPose_7A_FaceL_Springball_Ground)) { - SetEventHappened(0xCu); + SetEventHappened(0xC); enemy_data[0].parameter_1 = 1; int v2 = plm_block_indices[j >> 1] >> 1; - level_data[v2] &= 0xFFFu; + level_data[v2] &= 0xFFF; CallSomeSamusCode(0); - SpawnHardcodedPlm(&unk_84D1DA); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0c, 0x1d, 0xd113 }); } plm_header_ptr[j >> 1] = 0; return 1; @@ -2765,7 +2398,7 @@ const uint8 *PlmInstr_GotoIfRoomArgLess(const uint8 *plmp, uint16 k) { // 0x84D } const uint8 *PlmInstr_SpawnFourMotherBrainGlass(const uint8 *plmp, uint16 k) { // 0x84D30B - QueueSfx3_Max15(0x2Eu); + QueueSfx3_Max15(0x2E); SpawnMotherBrainGlassShatteringShard(GET_WORD(plmp + 0)); SpawnMotherBrainGlassShatteringShard(GET_WORD(plmp + 2)); SpawnMotherBrainGlassShatteringShard(GET_WORD(plmp + 4)); @@ -2793,7 +2426,7 @@ const uint8 *PlmInstr_SpawnTorizoStatueBreaking(const uint8 *plmp, uint16 k) { } const uint8 *PlmInstr_QueueSong1MusicTrack(const uint8 *plmp, uint16 k) { // 0x84D3C7 - QueueMusic_Delayed8(6u); + QueueMusic_Delayed8(6); return plmp; } @@ -2819,13 +2452,12 @@ void PlmPreInstr_WakeOnKeyPress(uint16 k) { // 0x84D4BF } const uint8 *PlmInstr_EnableWaterPhysics(const uint8 *plmp, uint16 k) { // 0x84D525 - fx_liquid_options &= ~4u; + fx_liquid_options &= ~4; return plmp; } const uint8 *PlmInstr_SpawnN00bTubeCrackEnemyProjectile(const uint8 *plmp, uint16 k) { // 0x84D52C - uint16 v2 = 0; // undefined - SpawnEnemyProjectileWithRoomGfx(0xD904, v2); + SpawnEnemyProjectileWithRoomGfx(0xD904, 0); return plmp; } @@ -2837,20 +2469,20 @@ const uint8 *PlmInstr_DiagonalEarthquake(const uint8 *plmp, uint16 k) { // 0x84 const uint8 *PlmInstr_Spawn10shardsAnd6n00bs(const uint8 *plmp, uint16 k) { // 0x84D543 SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 0); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 2u); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 4u); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 6u); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 8u); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 2); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 4); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 6); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 8); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 0xA); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 0xC); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 0xE); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 0x10); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeShards, 0x12); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 0); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 2u); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 4u); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 6u); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 8u); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 2); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 4); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 6); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 8); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_N00bTubeReleasedAirBubbles, 0xA); return plmp; } @@ -2873,7 +2505,7 @@ uint8 PlmSetup_MotherBrainGlass(uint16 j) { // 0x84D5F6 } uint8 PlmSetup_DeletePlmIfAreaTorizoDead(uint16 j) { // 0x84D606 - if (CheckBossBitForCurArea(4u) & 1) + if (CheckBossBitForCurArea(4) & 1) plm_header_ptr[j >> 1] = 0; return 0; } @@ -2884,7 +2516,7 @@ uint8 PlmSetup_MakeBllockChozoHandTrigger(uint16 j) { // 0x84D616 } uint8 PlmSetup_D6F2_WreckedShipChozoHandTrigger(uint16 j) { // 0x84D620 - if (CheckBossBitForCurArea(1u) & 1 + if (CheckBossBitForCurArea(1) & 1 && (samus_collision_direction & 0xF) == 3 && (samus_pose == kPose_1D_FaceR_Morphball_Ground || samus_pose == kPose_79_FaceR_Springball_Ground @@ -2893,10 +2525,9 @@ uint8 PlmSetup_D6F2_WreckedShipChozoHandTrigger(uint16 j) { // 0x84D620 *(uint16 *)&scrolls[7] = 514; *(uint16 *)&scrolls[13] = 257; int v1 = plm_block_indices[j >> 1] >> 1; - level_data[v1] &= 0xFFFu; + level_data[v1] &= 0xFFF; CallSomeSamusCode(0); - static const SpawnHardcodedPlmArgs unk_84D673 = { 0x17, 0x1d, 0xd6f8 }; - SpawnHardcodedPlm(&unk_84D673); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x17, 0x1d, 0xd6f8 }); } plm_header_ptr[j >> 1] = 0; return 1; @@ -2920,13 +2551,13 @@ uint8 PlmSetup_D708_LowerNorfairChozoBlockUnused(uint16 j) { // 0x84D693 room_width_in_blocks + room_width_in_blocks + plm_block_indices[v1], - 0xD0FFu); + 0xD0FF); WriteLevelDataBlockTypeAndBts( room_width_in_blocks + room_width_in_blocks + plm_block_indices[v1] + 2, - 0xD0FFu); + 0xD0FF); return 0; } @@ -2948,7 +2579,7 @@ void PlmPreInstr_WakePlmIfRoomArgumentDoorIsSet(uint16 k) { // 0x84D753 const uint8 *PlmInstr_ShootEyeDoorProjectileWithProjectileArg(const uint8 *plmp, uint16 k) { // 0x84D77A SpawnEnemyProjectileWithRoomGfx(addr_kEproj_EyeDoorProjectile, GET_WORD(plmp)); - QueueSfx2_Max6(0x4Cu); + QueueSfx2_Max6(0x4C); return plmp + 2; } @@ -2995,7 +2626,7 @@ void sub_84D7EF(uint16 k) { // 0x84D7EF WriteLevelDataBlockTypeAndBts(v1, 0xD0FF); uint16 v2 = room_width_in_blocks * 2 + v1; WriteLevelDataBlockTypeAndBts(v2, 0xD0FE); - WriteLevelDataBlockTypeAndBts(room_width_in_blocks * 2 + v2, 0xD0FDu); + WriteLevelDataBlockTypeAndBts(room_width_in_blocks * 2 + v2, 0xD0FD); } uint8 PlmSetup_EyeDoorEye(uint16 j) { // 0x84DA8C @@ -3003,7 +2634,7 @@ uint8 PlmSetup_EyeDoorEye(uint16 j) { // 0x84DA8C if ((bitmask & opened_door_bit_array[idx]) == 0) { int v1 = j >> 1; WriteLevelDataBlockTypeAndBts(plm_block_indices[v1], 0xC044); - WriteLevelDataBlockTypeAndBts(2 * room_width_in_blocks + plm_block_indices[v1], 0xD0FFu); + WriteLevelDataBlockTypeAndBts(2 * room_width_in_blocks + plm_block_indices[v1], 0xD0FF); } return 0; } @@ -3017,22 +2648,22 @@ uint8 PlmSetup_EyeDoor(uint16 j) { // 0x84DAB9 void PlmPreInstr_SetMetroidsClearState_Ev0x10(uint16 k) { // 0x84DADE if (num_enemies_killed_in_room >= num_enemy_deaths_left_to_clear) - SetEventHappened(0x10u); + SetEventHappened(0x10); } void PlmPreInstr_SetMetroidsClearState_Ev0x11(uint16 k) { // 0x84DAEE if (num_enemies_killed_in_room >= num_enemy_deaths_left_to_clear) - SetEventHappened(0x11u); + SetEventHappened(0x11); } void PlmPreInstr_SetMetroidsClearState_Ev0x12(uint16 k) { // 0x84DAFE if (num_enemies_killed_in_room >= num_enemy_deaths_left_to_clear) - SetEventHappened(0x12u); + SetEventHappened(0x12); } void PlmPreInstr_SetMetroidsClearState_Ev0x13(uint16 k) { // 0x84DB0E if (num_enemies_killed_in_room >= num_enemy_deaths_left_to_clear) - SetEventHappened(0x13u); + SetEventHappened(0x13); } uint8 PlmSetup_SetMetroidRequiredClearState(uint16 j) { // 0x84DB1E @@ -3063,7 +2694,7 @@ const uint8 *PlmInstr_DamageDraygonTurret(const uint8 *plmp, uint16 k) { // 0x8 SetPlmVarPtr(k, 1); uint16 v2 = plm_block_indices[k >> 1]; WriteLevelDataBlockTypeAndBts(v2, 0xA003); - WriteLevelDataBlockTypeAndBts(room_width_in_blocks * 2 + v2, 0xA003u); + WriteLevelDataBlockTypeAndBts(room_width_in_blocks * 2 + v2, 0xA003); return plmp; } @@ -3094,7 +2725,7 @@ const uint8 *PlmInstr_DamageDraygonTurret2(const uint8 *plmp, uint16 k) { // 0x SetPlmVarPtr(k, 1); uint16 v2 = plm_block_indices[k >> 1]; WriteLevelDataBlockTypeAndBts(v2, 0xA003); - WriteLevelDataBlockTypeAndBts(room_width_in_blocks * 2 + v2, 0xA003u); + WriteLevelDataBlockTypeAndBts(room_width_in_blocks * 2 + v2, 0xA003); return plmp; } @@ -3193,6 +2824,17 @@ void PlmPreInstr_WakeIfTriggered(uint16 k) { // 0x84DFE6 } } +const uint8 *PlmInstr_DrawItemFrame_Common(const uint8 *plmp, uint16 k) { // 0x84E07F + int v2 = k >> 1; + plm_instruction_timer[v2] = 4; + plm_instr_list_ptrs[v2] = plmp - RomBankBase(0x84); + ProcessPlmDrawInstruction(k); + uint16 v3 = plm_id; + CalculatePlmBlockCoords(plm_id); + DrawPlm(v3); + return 0; +} + const uint8 *PlmInstr_DrawItemFrame0(const uint8 *plmp, uint16 k) { // 0x84E04F plm_instruction_draw_ptr[k >> 1] = off_84E05F[plm_variables[k >> 1] >> 1]; return PlmInstr_DrawItemFrame_Common(plmp, k); @@ -3203,18 +2845,6 @@ const uint8 *PlmInstr_DrawItemFrame1(const uint8 *plmp, uint16 k) { // 0x84E067 return PlmInstr_DrawItemFrame_Common(plmp, k); } -const uint8 *PlmInstr_DrawItemFrame_Common(const uint8 *plmp, uint16 k) { // 0x84E07F - int v2 = k >> 1; - plm_instruction_timer[v2] = 4; - const uint8 *base = RomPtr_84(0x8000) - 0x8000; - plm_instr_list_ptrs[v2] = plmp - base; - ProcessPlmDrawInstruction(k); - uint16 v3 = plm_id; - CalculatePlmBlockCoords(plm_id); - DrawPlm(v3); - return 0; -} - const uint8 *PlmInstr_ClearChargeBeamCounter(const uint8 *plmp, uint16 k) { // 0x84E29D flare_counter = 0; return plmp; @@ -3226,7 +2856,7 @@ const uint8 *PlmInstr_E63B(const uint8 *plmp, uint16 k) { // 0x84E63B } uint8 sub_84EE4D(uint16 j) { // 0x84EE4D - return sub_84EE5F(j, 8u); + return sub_84EE5F(j, 8); } uint8 sub_84EE52(uint16 j) { // 0x84EE52 @@ -3253,7 +2883,7 @@ uint8 sub_84EE64(uint16 j) { // 0x84EE64 } uint8 sub_84EE77(uint16 j) { // 0x84EE77 - return sub_84EE89(j, 8u); + return sub_84EE89(j, 8); } uint8 sub_84EE7C(uint16 j) { // 0x84EE7C @@ -3297,4 +2927,305 @@ uint8 sub_84EEAB(uint16 v0) { // 0x84EEAB plm_timers[i >> 1] = 255; } return 0; -} \ No newline at end of file +} + + +uint8 CallPlmHeaderFunc(uint32 ea, uint16 j) { + switch (ea) { + case fnnullsub_67: + case fnnullsub_290: + case fnnullsub_68: + case fnnullsub_84BAFA: + case fnnullsub_71: + case fnnullsub_72: + case fnnullsub_69: return 0; + case fnPlmSetup_CrumbleBotwoonWall: return PlmSetup_CrumbleBotwoonWall(j); + case fnPlmSetup_SetrupWreckedShipEntrance: return PlmSetup_SetrupWreckedShipEntrance(j); + case fnPlmSetup_BTS_Brinstar_0x80_Floorplant: return PlmSetup_BTS_Brinstar_0x80_Floorplant(j); + case fnPlmSetup_BTS_Brinstar_0x81_Ceilingplant: return PlmSetup_BTS_Brinstar_0x81_Ceilingplant(j); + case fnPlmSetup_B6D3_MapStation: return PlmSetup_B6D3_MapStation(j); + case fnPlmSetup_Bts47_MapStationRightAccess: return PlmSetup_Bts47_MapStationRightAccess(j); + case fnPlmSetup_Bts4_MapStationLeftAccess: return PlmSetup_Bts4_MapStationLeftAccess(j); + case fnPlmSetup_PlmB6DF_EnergyStation: return PlmSetup_PlmB6DF_EnergyStation(j); + case fnPlmSetup_PlmB6EB_EnergyStation: return PlmSetup_PlmB6EB_EnergyStation(j); + case fnPlmSetup_B6E3_EnergyStationRightAccess: return PlmSetup_B6E3_EnergyStationRightAccess(j); + case fnPlmSetup_B6E7_EnergyStationLeftAccess: return PlmSetup_B6E7_EnergyStationLeftAccess(j); + case fnPlmSetup_B6EF_MissileStationRightAccess: return PlmSetup_B6EF_MissileStationRightAccess(j); + case fnPlmSetup_B6F3_MissileStationLeftAccess: return PlmSetup_B6F3_MissileStationLeftAccess(j); + case fnPlmSetup_B638_Rightwards_Extension: return PlmSetup_B638_Rightwards_Extension(j); + case fnPlmSetup_B63F_Leftwards_Extension: return PlmSetup_B63F_Leftwards_Extension(j); + case fnPlmSetup_B643_Downwards_Extension: return PlmSetup_B643_Downwards_Extension(j); + case fnPlmSetup_B647_Upwards_Extension: return PlmSetup_B647_Upwards_Extension(j); + case fnPlmSetup_B703_ScrollPLM: return PlmSetup_B703_ScrollPLM(j); + case fnPlmSetup_B707_SolidScrollPLM: return PlmSetup_B707_SolidScrollPLM(j); + case fnPlmSetup_B6FF_ScrollBlockTouch: return PlmSetup_B6FF_ScrollBlockTouch(j); + case fnPlmSetup_DeactivatePlm: return PlmSetup_DeactivatePlm(j); + case fnPlmSetup_ReturnCarryClear: return PlmSetup_ReturnCarryClear(j); + case fnPlmSetup_ReturnCarrySet: return PlmSetup_ReturnCarrySet(j); + case fnPlmSetup_D094_EnemyBreakableBlock: return PlmSetup_D094_EnemyBreakableBlock(j); + case fnUNUSED_sub_84B3E3: return UNUSED_sub_84B3E3(j); + case fnPlmSetup_B70F_IcePhysics: return PlmSetup_B70F_IcePhysics(j); + case fnPlmSetup_QuicksandSurface: return PlmSetup_QuicksandSurface(j); + case fnPlmSetup_B71F_SubmergingQuicksand: return PlmSetup_B71F_SubmergingQuicksand(j); + case fnPlmSetup_B723_SandfallsSlow: return PlmSetup_B723_SandfallsSlow(j); + case fnPlmSetup_B727_SandFallsFast: return PlmSetup_B727_SandFallsFast(j); + case fnPlmSetup_QuicksandSurfaceB: return PlmSetup_QuicksandSurfaceB(j); + case fnPlmSetup_B737_SubmergingQuicksand: return PlmSetup_B737_SubmergingQuicksand(j); + case fnPlmSetup_B73B_B73F_SandFalls: return PlmSetup_B73B_B73F_SandFalls(j); + case fnPlmSetup_ClearShitroidInvisibleWall: return PlmSetup_ClearShitroidInvisibleWall(j); + case fnPlmSetup_B767_ClearShitroidInvisibleWall: return PlmSetup_B767_ClearShitroidInvisibleWall(j); + case fnPlmSetup_B76B_SaveStationTrigger: return PlmSetup_B76B_SaveStationTrigger(j); + case fnPlmSetup_B76F_SaveStation: return PlmSetup_B76F_SaveStation(j); + case fnPlmSetup_MotherBrainRoomEscapeDoor: return PlmSetup_MotherBrainRoomEscapeDoor(j); + case fnPlmSetup_B7EB_EnableSoundsIn32Frames: return PlmSetup_B7EB_EnableSoundsIn32Frames(j); + case fnPlmSetup_SpeedBoosterEscape: return PlmSetup_SpeedBoosterEscape(j); + case fnPlmSetup_ShaktoolsRoom: return PlmSetup_ShaktoolsRoom(j); + case fnPlmSetup_B974: return PlmSetup_B974(j); + case fnPlmSetup_B9C1_CrittersEscapeBlock: return PlmSetup_B9C1_CrittersEscapeBlock(j); + case fnPlmSetup_B9ED_CrittersEscapeBlock: return PlmSetup_B9ED_CrittersEscapeBlock(j); + case fnsub_84B9F1: return sub_84B9F1(j); + case fnPlmSetup_BB30_CrateriaMainstreetEscape: return PlmSetup_BB30_CrateriaMainstreetEscape(j); + case fnPlmSetup_C806_LeftGreenGateTrigger: return PlmSetup_C806_LeftGreenGateTrigger(j); + case fnPlmSetup_C80A_RightGreenGateTrigger: return PlmSetup_C80A_RightGreenGateTrigger(j); + case fnPlmSetup_C80E_LeftRedGateTrigger: return PlmSetup_C80E_LeftRedGateTrigger(j); + case fnPlmSetup_C812_RightRedGateTrigger: return PlmSetup_C812_RightRedGateTrigger(j); + case fnPlmSetup_C81E_LeftYellowGateTrigger: return PlmSetup_C81E_LeftYellowGateTrigger(j); + case fnPlmSetup_C822_RightYellowGateTrigger: return PlmSetup_C822_RightYellowGateTrigger(j); + case fnPlmSetup_C816_LeftBlueGateTrigger: return PlmSetup_C816_LeftBlueGateTrigger(j); + case fnPlmSetup_C81A_RightBlueGateTrigger: return PlmSetup_C81A_RightBlueGateTrigger(j); + case fnPlmSetup_C82A_DownwardsClosedGate: return PlmSetup_C82A_DownwardsClosedGate(j); + case fnPlmSetup_C832_UpwardsClosedGate: return PlmSetup_C832_UpwardsClosedGate(j); + case fnPlmSetup_C826_DownwardsOpenGate: return PlmSetup_C826_DownwardsOpenGate(j); + case fnPlmSetup_C82E_UpwardsOpenGate: return PlmSetup_C82E_UpwardsOpenGate(j); + case fnPlmSetup_C836_DownwardsGateShootblock: return PlmSetup_C836_DownwardsGateShootblock(j); + case fnPlmSetup_C73A_UpwardsGateShootblock: return PlmSetup_C73A_UpwardsGateShootblock(j); + case fnPlmSetup_C794_GreyDoor: return PlmSetup_C794_GreyDoor(j); + case fnPlmSetup_Door_Colored: return PlmSetup_Door_Colored(j); + case fnPlmSetup_Door_Blue: return PlmSetup_Door_Blue(j); + case fnPlmSetup_Door_Strange: return PlmSetup_Door_Strange(j); + case fnPlmSetup_D028_D02C_Unused: return PlmSetup_D028_D02C_Unused(j); + case fnPlmSetup_RespawningSpeedBoostBlock: return PlmSetup_RespawningSpeedBoostBlock(j); + case fnPlmSetup_RespawningCrumbleBlock: return PlmSetup_RespawningCrumbleBlock(j); + case fnPlmSetup_RespawningShotBlock: return PlmSetup_RespawningShotBlock(j); + case fnPlmSetup_RespawningBombBlock: return PlmSetup_RespawningBombBlock(j); + case fnPlmSetup_RespawningBombBlock2: return PlmSetup_RespawningBombBlock2(j); + case fnPlmSetup_RespawningPowerBombBlock: return PlmSetup_RespawningPowerBombBlock(j); + case fnPlmSetup_D08C_SuperMissileBlockRespawning: return PlmSetup_D08C_SuperMissileBlockRespawning(j); + case fnPlmSetup_D08C_CrumbleBlock: return PlmSetup_D08C_CrumbleBlock(j); + case fnPlmSetup_D0DC_BreakableGrappleBlock: return PlmSetup_D0DC_BreakableGrappleBlock(j); + case fnPlmSetup_D0D8_SetVFlag: return PlmSetup_D0D8_SetVFlag(j); + case fnPlmSetup_D0D8_ClearVflag: return PlmSetup_D0D8_ClearVflag(j); + case fnPlmSetup_D0E8_GiveSamusDamage: return PlmSetup_D0E8_GiveSamusDamage(j); + case fnPlmSetup_D113_LowerNorfairChozoRoomPlug: return PlmSetup_D113_LowerNorfairChozoRoomPlug(j); + case fnPlmSetup_D127: return PlmSetup_D127(j); + case fnPlmSetup_D138: return PlmSetup_D138(j); + case fnPlmSetup_D6DA_LowerNorfairChozoHandTrigger: return PlmSetup_D6DA_LowerNorfairChozoHandTrigger(j); + case fnPlmSetup_MotherBrainGlass: return PlmSetup_MotherBrainGlass(j); + case fnPlmSetup_DeletePlmIfAreaTorizoDead: return PlmSetup_DeletePlmIfAreaTorizoDead(j); + case fnPlmSetup_MakeBllockChozoHandTrigger: return PlmSetup_MakeBllockChozoHandTrigger(j); + case fnPlmSetup_D6F2_WreckedShipChozoHandTrigger: return PlmSetup_D6F2_WreckedShipChozoHandTrigger(j); + case fnPlmSetup_D700_MakePlmAirBlock_Unused: return PlmSetup_D700_MakePlmAirBlock_Unused(j); + case fnPlmSetup_D704_AlteranateLowerNorfairChozoHand_Unused: return PlmSetup_D704_AlteranateLowerNorfairChozoHand_Unused(j); + case fnPlmSetup_D708_LowerNorfairChozoBlockUnused: return PlmSetup_D708_LowerNorfairChozoBlockUnused(j); + case fnPlmSetup_D70C_NoobTube: return PlmSetup_D70C_NoobTube(j); + case fnPlmSetup_EyeDoorEye: return PlmSetup_EyeDoorEye(j); + case fnPlmSetup_EyeDoor: return PlmSetup_EyeDoor(j); + case fnPlmSetup_SetMetroidRequiredClearState: return PlmSetup_SetMetroidRequiredClearState(j); + case fnPlmSetup_DraygonCannonFacingRight: return PlmSetup_DraygonCannonFacingRight(j); + case fnPlmSetup_DraygonCannonFacingDiagonalRight: return PlmSetup_DraygonCannonFacingDiagonalRight(j); + case fnPlmSetup_DraygonCannonFacingLeft: return PlmSetup_DraygonCannonFacingLeft(j); + case fnPlmSetup_DraygonCannonFacingDiagonalLeft: return PlmSetup_DraygonCannonFacingDiagonalLeft(j); + case fnPlmSetup_DraygonCannon: return PlmSetup_DraygonCannon(j); + case fnsub_84EE4D: return sub_84EE4D(j); + case fnsub_84EE52: return sub_84EE52(j); + case fnsub_84EE57: return sub_84EE57(j); + case fnsub_84EE5C: return sub_84EE5C(j); + case fnsub_84EE64: return sub_84EE64(j); + case fnsub_84EE77: return sub_84EE77(j); + case fnsub_84EE7C: return sub_84EE7C(j); + case fnsub_84EE81: return sub_84EE81(j); + case fnsub_84EE86: return sub_84EE86(j); + case fnsub_84EE8E: return sub_84EE8E(j); + case fnsub_84EEAB: return sub_84EEAB(j); + default: return Unreachable(); + } +} + +void CallPlmPreInstr(uint32 ea, uint16 k) { + switch (ea) { + case fnPlmPreInstr_nullsub_60: return; + case fnPlmPreInstr_nullsub_301: return; + case fnPlmPreInstr_Empty: return; + case fnPlmPreInstr_Empty2: return; + case fnPlmPreInstr_Empty3: return; + case fnPlmPreInstr_Empty4: return; + case fnPlmPreInstr_Empty5: return; + case fnnullsub_351: return; + case fnnullsub_84BAFA: return; + case fnPlmSetup_BTS_Brinstar_0x80_Floorplant: PlmSetup_BTS_Brinstar_0x80_Floorplant(k); return; + case fnPlmSetup_BTS_Brinstar_0x81_Ceilingplant: PlmSetup_BTS_Brinstar_0x81_Ceilingplant(k); return; + case fnPlmPreInstr_B7EB_DecTimerEnableSoundsDeletePlm: PlmPreInstr_B7EB_DecTimerEnableSoundsDeletePlm(k); return; + case fnPlmPreInstr_WakeAndLavaIfBoosterCollected: PlmPreInstr_WakeAndLavaIfBoosterCollected(k); return; + case fnPlmPreInstr_WakePLMAndStartFxMotionSamusFarLeft: PlmPreInstr_WakePLMAndStartFxMotionSamusFarLeft(k); return; + case fnPlmPreInstr_AdvanceLavaSamusMovesLeft: PlmPreInstr_AdvanceLavaSamusMovesLeft(k); return; + case fnPlmPreInstr_ShaktoolsRoom: PlmPreInstr_ShaktoolsRoom(k); return; + case fnPlmPreInstr_OldTourianEscapeShaftEscape: PlmPreInstr_OldTourianEscapeShaftEscape(k); return; + case fnPlmPreInstr_EscapeRoomBeforeOldTourianEscapeShaft: PlmPreInstr_EscapeRoomBeforeOldTourianEscapeShaft(k); return; + case fnPlmPreInstr_WakePlmIfTriggered: PlmPreInstr_WakePlmIfTriggered(k); return; + case fnPlmPreInstr_WakePlmIfTriggeredOrSamusBelowPlm: PlmPreInstr_WakePlmIfTriggeredOrSamusBelowPlm(k); return; + case fnPlmPreInstr_WakePlmIfTriggeredOrSamusAbovePlm: PlmPreInstr_WakePlmIfTriggeredOrSamusAbovePlm(k); return; + case fnPlmPreInstr_DeletePlmAndSpawnTriggerIfBlockDestroyed: PlmPreInstr_DeletePlmAndSpawnTriggerIfBlockDestroyed(k); return; + case fnPlmPreInstr_IncrementRoomArgIfShotBySuperMissile: PlmPreInstr_IncrementRoomArgIfShotBySuperMissile(k); return; + case fnPlmPreInstr_WakePlmIfSamusHasBombs: PlmPreInstr_WakePlmIfSamusHasBombs(k); return; + case fnPlmPreInstr_WakePlmIfRoomArgumentDoorIsSet: PlmPreInstr_WakePlmIfRoomArgumentDoorIsSet(k); return; + case fnPlmPreInstr_GotoLinkIfShotWithSuperMissile: PlmPreInstr_GotoLinkIfShotWithSuperMissile(k); return; + case fnPlmPreInstr_GotoLinkIfTriggered: PlmPreInstr_GotoLinkIfTriggered(k); return; + case fnPlmPreInstr_WakeIfTriggered: PlmPreInstr_WakeIfTriggered(k); return; + case fnPlmPreInstr_GoToLinkInstrIfShot: PlmPreInstr_GoToLinkInstrIfShot(k); return; + case fnPlmPreInstr_GoToLinkInstrIfShotWithPowerBomb: PlmPreInstr_GoToLinkInstrIfShotWithPowerBomb(k); return; + case fnPlmPreInstr_GoToLinkInstrIfShotWithAnyMissile: PlmPreInstr_GoToLinkInstrIfShotWithAnyMissile(k); return; + case fnPlmPreInstr_GoToLinkInstrIfShotWithSuperMissile: PlmPreInstr_GoToLinkInstrIfShotWithSuperMissile(k); return; + case fnPlmPreInstr_GoToLinkInstruction: PlmPreInstr_GoToLinkInstruction(k); return; + case fnPlmPreInstr_PlayDudSound: PlmPreInstr_PlayDudSound(k); return; + case fnPlmPreInstr_GotoLinkIfBoss1Dead: PlmPreInstr_GotoLinkIfBoss1Dead(k); return; + case fnPlmPreInstr_GotoLinkIfMiniBossDead: PlmPreInstr_GotoLinkIfMiniBossDead(k); return; + case fnPlmPreInstr_GotoLinkIfTorizoDead: PlmPreInstr_GotoLinkIfTorizoDead(k); return; + case fnPlmPreInstr_GotoLinkIfEnemyDeathQuotaOk: PlmPreInstr_GotoLinkIfEnemyDeathQuotaOk(k); return; + case fnPlmPreInstr_GotoLinkIfTourianStatueFinishedProcessing: PlmPreInstr_GotoLinkIfTourianStatueFinishedProcessing(k); return; + case fnPlmPreInstr_GotoLinkIfCrittersEscaped: PlmPreInstr_GotoLinkIfCrittersEscaped(k); return; + case fnPlmPreInstr_PositionSamusAndInvincible: PlmPreInstr_PositionSamusAndInvincible(k); return; + case fnPlmPreInstr_WakeOnKeyPress: PlmPreInstr_WakeOnKeyPress(k); return; + case fnnullsub_359: return; + case fnnullsub_73: + case fnnullsub_74: + case fnnullsub_75: + case fnnullsub_76: + case fnnullsub_77: + case fnnullsub_78: + case fnnullsub_79: + case fnnullsub_80: + case fnnullsub_81: + case fnlocret_848AE0: return; + case fnPlmPreInstr_SetMetroidsClearState_Ev0x10: PlmPreInstr_SetMetroidsClearState_Ev0x10(k); return; + case fnPlmPreInstr_SetMetroidsClearState_Ev0x11: PlmPreInstr_SetMetroidsClearState_Ev0x11(k); return; + case fnPlmPreInstr_SetMetroidsClearState_Ev0x12: PlmPreInstr_SetMetroidsClearState_Ev0x12(k); return; + case fnPlmPreInstr_SetMetroidsClearState_Ev0x13: PlmPreInstr_SetMetroidsClearState_Ev0x13(k); return; + default: Unreachable(); + } +} + +const uint8 *CallPlmInstr(uint32 ea, const uint8 *j, uint16 k) { + switch (ea) { + case fnPlmInstr_Sleep: return PlmInstr_Sleep(j, k); + case fnPlmInstr_Delete: return PlmInstr_Delete(j, k); + case fnPlmInstr_PreInstr: return PlmInstr_PreInstr(j, k); + case fnPlmInstr_ClearPreInstr: return PlmInstr_ClearPreInstr(j, k); + case fnPlmInstr_CallFunction: return PlmInstr_CallFunction(j, k); + case fnPlmInstr_Goto: return PlmInstr_Goto(j, k); + case fnPlmInstr_DecrementAndBranchNonzero: return PlmInstr_DecrementAndBranchNonzero(j, k); + case fnPlmInstr_SetTimer: return PlmInstr_SetTimer(j, k); + case fnPlmInstr_LoadItemPlmGfx: return PlmInstr_LoadItemPlmGfx(j, k); + case fnPlmInstr_CopyFromRamToVram: return PlmInstr_CopyFromRamToVram(j, k); + case fnPlmInstr_GotoIfBossBitSet: return PlmInstr_GotoIfBossBitSet(j, k); + case fnPlmInstr_GotoIfEventSet: return PlmInstr_GotoIfEventSet(j, k); + case fnPlmInstr_SetEvent: return PlmInstr_SetEvent(j, k); + case fnPlmInstr_GotoIfChozoSet: return PlmInstr_GotoIfChozoSet(j, k); + case fnPlmInstr_SetRoomChozoBit: return PlmInstr_SetRoomChozoBit(j, k); + case fnPlmInstr_GotoIfItemBitSet: return PlmInstr_GotoIfItemBitSet(j, k); + case fnPlmInstr_SetItemBit: return PlmInstr_SetItemBit(j, k); + case fnPlmInstr_PickupBeamAndShowMessage: return PlmInstr_PickupBeamAndShowMessage(j, k); + case fnPlmInstr_PickupEquipmentAndShowMessage: return PlmInstr_PickupEquipmentAndShowMessage(j, k); + case fnPlmInstr_PickupEquipmentAddGrappleShowMessage: return PlmInstr_PickupEquipmentAddGrappleShowMessage(j, k); + case fnPlmInstr_PickupEquipmentAddXrayShowMessage: return PlmInstr_PickupEquipmentAddXrayShowMessage(j, k); + case fnPlmInstr_CollectHealthEnergyTank: return PlmInstr_CollectHealthEnergyTank(j, k); + case fnPlmInstr_CollectHealthReserveTank: return PlmInstr_CollectHealthReserveTank(j, k); + case fnPlmInstr_CollectAmmoMissileTank: return PlmInstr_CollectAmmoMissileTank(j, k); + case fnPlmInstr_CollectAmmoSuperMissileTank: return PlmInstr_CollectAmmoSuperMissileTank(j, k); + case fnPlmInstr_CollectAmmoPowerBombTank: return PlmInstr_CollectAmmoPowerBombTank(j, k); + case fnPlmInstr_SetLinkReg: return PlmInstr_SetLinkReg(j, k); + case fnPlmInstr_Call: return PlmInstr_Call(j, k); + case fnPlmInstr_Return: return PlmInstr_Return(j, k); + case fnPlmInstr_GotoIfDoorBitSet: return PlmInstr_GotoIfDoorBitSet(j, k); + case fnPlmInstr_IncrementDoorHitCounterAndJGE: return PlmInstr_IncrementDoorHitCounterAndJGE(j, k); + case fnPlmInstr_IncrementArgumentAndJGE: return PlmInstr_IncrementArgumentAndJGE(j, k); + case fnPlmInstr_SetBTS: return PlmInstr_SetBTS(j, k); + case fnPlmInstr_DrawPlmBlock: return PlmInstr_DrawPlmBlock(j, k); + case fnPlmInstr_DrawPlmBlock_: return PlmInstr_DrawPlmBlock(j, k); + case fnPlmInstr_ProcessAirScrollUpdate: return PlmInstr_ProcessAirScrollUpdate(j, k); + case fnPlmInstr_ProcessSolidScrollUpdate: return PlmInstr_ProcessSolidScrollUpdate(j, k); + case fnPlmInstr_QueueMusic: return PlmInstr_QueueMusic(j, k); + case fnPlmInstr_ClearMusicQueueAndQueueTrack: return PlmInstr_ClearMusicQueueAndQueueTrack(j, k); + case fnPlmInstr_QueueSfx1_Max6: return PlmInstr_QueueSfx1_Max6(j, k); + case fnPlmInstr_QueueSfx2_Max6: return PlmInstr_QueueSfx2_Max6(j, k); + case fnPlmInstr_QueueSfx3_Max6: return PlmInstr_QueueSfx3_Max6(j, k); + case fnPlmInstr_QueueSfx1_Max15: return PlmInstr_QueueSfx1_Max15(j, k); + case fnPlmInstr_QueueSfx2_Max15: return PlmInstr_QueueSfx2_Max15(j, k); + case fnPlmInstr_QueueSfx3_Max15: return PlmInstr_QueueSfx3_Max15(j, k); + case fnPlmInstr_QueueSfx1_Max3: return PlmInstr_QueueSfx1_Max3(j, k); + case fnPlmInstr_QueueSfx2_Max3: return PlmInstr_QueueSfx2_Max3(j, k); + case fnPlmInstr_QueueSfx_Max3: return PlmInstr_QueueSfx_Max3(j, k); + case fnPlmInstr_QueueSfx1_Max9: return PlmInstr_QueueSfx1_Max9(j, k); + case fnPlmInstr_QueueSfx2_Max9: return PlmInstr_QueueSfx2_Max9(j, k); + case fnPlmInstr_QueueSfx3_Max9: return PlmInstr_QueueSfx3_Max9(j, k); + case fnPlmInstr_QueueSfx1_Max1: return PlmInstr_QueueSfx1_Max1(j, k); + case fnPlmInstr_QueueSfx2_Max1: return PlmInstr_QueueSfx2_Max1(j, k); + case fnPlmInstr_QueueSfx3_Max1: return PlmInstr_QueueSfx3_Max1(j, k); + case fnPlmInstr_ActivateMapStation: return PlmInstr_ActivateMapStation(j, k); + case fnPlmInstr_ActivateEnergyStation: return PlmInstr_ActivateEnergyStation(j, k); + case fnPlmInstr_ActivateMissileStation: return PlmInstr_ActivateMissileStation(j, k); + case fnPlmInstr_ActivateSaveStationAndGotoIfNo: return PlmInstr_ActivateSaveStationAndGotoIfNo(j, k); + case fnPlmInstr_GotoIfSamusNear: return PlmInstr_GotoIfSamusNear(j, k); + case fnPlmInstr_MovePlmDownOneBlock: return PlmInstr_MovePlmDownOneBlock(j, k); + case fnPlmInstr_Scroll_0_1_Blue: return PlmInstr_Scroll_0_1_Blue(j, k); + case fnPlmInstr_MovePlmDownOneBlock_0: return PlmInstr_MovePlmDownOneBlock_0(j, k); + case fnPlmInstr_DealDamage_2: return PlmInstr_DealDamage_2(j, k); + case fnPlmInstr_GiveInvincibility: return PlmInstr_GiveInvincibility(j, k); + case fnPlmInstr_Draw0x38FramesOfRightTreadmill: return PlmInstr_Draw0x38FramesOfRightTreadmill(j, k); + case fnPlmInstr_Draw0x38FramesOfLeftTreadmill: return PlmInstr_Draw0x38FramesOfLeftTreadmill(j, k); + case fnPlmInstr_GotoIfSamusHealthFull: return PlmInstr_GotoIfSamusHealthFull(j, k); + case fnPlmInstr_GotoIfMissilesFull: return PlmInstr_GotoIfMissilesFull(j, k); + case fnPlmInstr_PlaceSamusOnSaveStation: return PlmInstr_PlaceSamusOnSaveStation(j, k); + case fnPlmInstr_DisplayGameSavedMessageBox: return PlmInstr_DisplayGameSavedMessageBox(j, k); + case fnPlmInstr_EnableMovementAndSetSaveStationUsed: return PlmInstr_EnableMovementAndSetSaveStationUsed(j, k); + case fnPlmInstr_SetCrittersEscapedEvent: return PlmInstr_SetCrittersEscapedEvent(j, k); + case fnPlmInstr_JumpIfSamusHasNoBombs: return PlmInstr_JumpIfSamusHasNoBombs(j, k); + case fnPlmInstr_MovePlmRight4Blocks: return PlmInstr_MovePlmRight4Blocks(j, k); + case fnPlmInstr_ClearTrigger: return PlmInstr_ClearTrigger(j, k); + case fnPlmInstr_SpawnEnemyProjectile: return PlmInstr_SpawnEnemyProjectile(j, k); + case fnPlmInstr_WakeEnemyProjectileAtPlmPos: return PlmInstr_WakeEnemyProjectileAtPlmPos(j, k); + case fnPlmInstr_SetGreyDoorPreInstr: return PlmInstr_SetGreyDoorPreInstr(j, k); + case fnPlmInstr_FxBaseYPos_0x2D2: return PlmInstr_FxBaseYPos_0x2D2(j, k); + case fnPlmInstr_GotoIfRoomArgLess: return PlmInstr_GotoIfRoomArgLess(j, k); + case fnPlmInstr_SpawnFourMotherBrainGlass: return PlmInstr_SpawnFourMotherBrainGlass(j, k); + case fnPlmInstr_SpawnTorizoStatueBreaking: return PlmInstr_SpawnTorizoStatueBreaking(j, k); + case fnPlmInstr_QueueSong1MusicTrack: return PlmInstr_QueueSong1MusicTrack(j, k); + case fnPlmInstr_TransferWreckedShipChozoSpikesToSlopes: return PlmInstr_TransferWreckedShipChozoSpikesToSlopes(j, k); + case fnPlmInstr_TransferWreckedShipSlopesToChozoSpikes: return PlmInstr_TransferWreckedShipSlopesToChozoSpikes(j, k); + case fnPlmInstr_EnableWaterPhysics: return PlmInstr_EnableWaterPhysics(j, k); + case fnPlmInstr_SpawnN00bTubeCrackEnemyProjectile: return PlmInstr_SpawnN00bTubeCrackEnemyProjectile(j, k); + case fnPlmInstr_DiagonalEarthquake: return PlmInstr_DiagonalEarthquake(j, k); + case fnPlmInstr_Spawn10shardsAnd6n00bs: return PlmInstr_Spawn10shardsAnd6n00bs(j, k); + case fnPlmInstr_ShootEyeDoorProjectileWithProjectileArg: return PlmInstr_ShootEyeDoorProjectileWithProjectileArg(j, k); + case fnPlmInstr_SpawnEyeDoorSweatEnemyProjectile: return PlmInstr_SpawnEyeDoorSweatEnemyProjectile(j, k); + case fnPlmInstr_SpawnTwoEyeDoorSmoke: return PlmInstr_SpawnTwoEyeDoorSmoke(j, k); + case fnPlmInstr_SpawnEyeDoorSmokeProjectile: return PlmInstr_SpawnEyeDoorSmokeProjectile(j, k); + case fnPlmInstr_MoveUpAndMakeBlueDoorFacingRight: return PlmInstr_MoveUpAndMakeBlueDoorFacingRight(j, k); + case fnPlmInstr_MoveUpAndMakeBlueDoorFacingLeft: return PlmInstr_MoveUpAndMakeBlueDoorFacingLeft(j, k); + case fnPlmInstr_DamageDraygonTurret: return PlmInstr_DamageDraygonTurret(j, k); + case fnPlmInstr_DamageDraygonTurretFacingDownRight: return PlmInstr_DamageDraygonTurretFacingDownRight(j, k); + case fnPlmInstr_DamageDraygonTurretFacingUpRight: return PlmInstr_DamageDraygonTurretFacingUpRight(j, k); + case fnPlmInstr_DamageDraygonTurret2: return PlmInstr_DamageDraygonTurret2(j, k); + case fnPlmInstr_DamageDraygonTurretFacingDownLeft: return PlmInstr_DamageDraygonTurretFacingDownLeft(j, k); + case fnPlmInstr_DamageDraygonTurretFacingUpLeft: return PlmInstr_DamageDraygonTurretFacingUpLeft(j, k); + case fnPlmInstr_DrawItemFrame0: return PlmInstr_DrawItemFrame0(j, k); + case fnPlmInstr_DrawItemFrame1: return PlmInstr_DrawItemFrame1(j, k); + case fnPlmInstr_DrawItemFrame_Common: return PlmInstr_DrawItemFrame_Common(j, k); + case fnPlmInstr_ClearChargeBeamCounter: return PlmInstr_ClearChargeBeamCounter(j, k); + case fnPlmInstr_ABD6: return PlmInstr_ABD6(j, k); + case fnPlmInstr_E63B: return PlmInstr_E63B(j, k); + case fnPlmInstr_SetBtsTo1: return PlmInstr_SetBtsTo1(j, k); + case fnPlmInstr_DisableSamusControls: return PlmInstr_DisableSamusControls(j, k); + case fnPlmInstr_EnableSamusControls: return PlmInstr_EnableSamusControls(j, k); + default: Unreachable(); return NULL; + } +} diff --git a/src/sm_85.c b/src/sm_85.c index 72746c1..0c82587 100644 --- a/src/sm_85.c +++ b/src/sm_85.c @@ -3,68 +3,17 @@ #include "variables.h" #include "funcs.h" +uint16 message_box_das0l_value; + #define kMessageBoxDefs ((MsgBoxConfig*)RomFixedPtr(0x85869b)) +static const uint16 kMsgBoxSpecialButtonTilemapOffs[27] = { // 0x8583D1 + 0, 0x12a, 0x12a, 0x12c, 0x12c, 0x12c, 0, 0, 0, 0, 0, 0, 0x120, 0, 0, 0, + 0, 0, 0x12a, 0, 0, 0, 0, 0, 0, 0, 0, +}; +static const uint16 kTileNumbersForButtonLetters[8] = { 0x28e0, 0x3ce1, 0x2cf7, 0x38f8, 0x38d0, 0x38eb, 0x38f1, 0x284e }; - - -int DisplayMessageBox_Poll(uint16 a) { - if (a == message_box_index) { - message_box_index = 0; - return save_confirmation_selection; - } - queued_message_box_index = a; - return -1; -} - -void DisplayMessageBox(uint16 a) { // 0x858080 - queued_message_box_index = a; -} - -CoroutineRet DisplayMessageBox_Async(uint16 a) { // 0x858080 - COROUTINE_BEGIN(coroutine_state_3, 0) - message_box_index = a; - CancelSoundEffects(); - InitializePpuForMessageBoxes(); - ClearMessageBoxBg3Tilemap(); - InitializeMessageBox(); - COROUTINE_AWAIT(2, OpenMessageBox_Async()); - COROUTINE_AWAIT(3, HandleMessageBoxInteraction_Async()); - COROUTINE_AWAIT(4, CloseMessageBox_Async()); - - if (message_box_index == 28 && save_confirmation_selection != 2) { - message_box_index = 24; - ClearMessageBoxBg3Tilemap(); - QueueSfx1_Max6(0x2Eu); - - my_counter = 160; - do { - HandleMusicQueue(); - HandleSoundEffects(); - COROUTINE_AWAIT(8, WaitForNMI_NoUpdate_Async()); - } while (--my_counter); - - InitializeMessageBox(); - COROUTINE_AWAIT(5, OpenMessageBox_Async()); - COROUTINE_AWAIT(6, HandleMessageBoxInteraction_Async()); - COROUTINE_AWAIT(7, CloseMessageBox_Async()); - message_box_index = 28; - } - ClearMessageBoxBg3Tilemap(); - RestorePpuForMessageBox(); - QueueSamusMovementSfx(); - - if (message_box_index == 20) { - game_state = kGameState_12_Pausing; - } - COROUTINE_END(0); -// else if (message_box_index == 28 || message_box_index == 23) { -// return save_confirmation_selection; -// } -// return 0; -} - -void InitializePpuForMessageBoxes(void) { // 0x858143 +static void InitializePpuForMessageBoxes(void) { // 0x858143 save_confirmation_selection = 0; WriteReg(HDMAEN, 0); WriteReg(CGADD, 0x19); @@ -98,10 +47,10 @@ void InitializePpuForMessageBoxes(void) { // 0x858143 WriteRegWord(DAS10, 0); WriteRegWord(A2A1H, 0); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } -void ClearMessageBoxBg3Tilemap(void) { // 0x8581F3 +static void ClearMessageBoxBg3Tilemap(void) { // 0x8581F3 int16 v0; v0 = 1790; do { @@ -116,30 +65,7 @@ void ClearMessageBoxBg3Tilemap(void) { // 0x8581F3 WriteRegWord(DAS10, 0); WriteRegWord(A2A1H, 0); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); -} - -void CallMsgBoxDraw(uint32 ea) { - switch (ea) { - case fnWriteLargeMessageBoxTilemap: WriteLargeMessageBoxTilemap(); return; - case fnWriteSmallMessageBoxTilemap: WriteSmallMessageBoxTilemap(); return; - default: Unreachable(); - } -} -void CallMsgBoxModify(uint32 ea) { - switch (ea) { - case fnDrawShootButtonAndSetupPpuForLargeMessageBox: DrawShootButtonAndSetupPpuForLargeMessageBox(); return; - case fnDrawRunButtonAndSetupPpuForLargeMessageBox: DrawRunButtonAndSetupPpuForLargeMessageBox(); return; - case fnSetupPpuForSmallMessageBox: SetupPpuForSmallMessageBox(); return; - case fnSetupPpuForLargeMessageBox: SetupPpuForLargeMessageBox(); return; - default: Unreachable(); - } -} -void InitializeMessageBox(void) { // 0x858241 - bg3_tilemap_offset = 2 * (message_box_index - 1); - uint16 v0 = message_box_index - 1; - CallMsgBoxDraw(kMessageBoxDefs[v0].draw_initial_tilemap | 0x850000); - CallMsgBoxModify(kMessageBoxDefs[v0].modify_box_func | 0x850000); + WriteReg(MDMAEN, 2); } static const uint16 kLargeMsgBoxTopBottomBorderTilemap[32] = { // 0x85825A @@ -150,59 +76,89 @@ static const uint16 kSmallMsgBoxTopBottomBorderTilemap[32] = { 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0x284e, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, }; -void WriteLargeMessageBoxTilemap(void) { - for (int i = 0; i != 32; ++i) - ram3000.pause_menu_map_tilemap[i + 256] = kLargeMsgBoxTopBottomBorderTilemap[i]; - uint16 i = WriteMessageTilemap(); - R22_ = 32; - uint16 v1 = 0; - do { - ram3000.pause_menu_map_tilemap[i + 256] = kLargeMsgBoxTopBottomBorderTilemap[v1 >> 1]; - v1 += 2; - ++i; - --R22_; - } while (R22_); -} -void WriteSmallMessageBoxTilemap(void) { // 0x858289 - for (int i = 0; i != 32; ++i) - ram3000.pause_menu_map_tilemap[i + 256] = kSmallMsgBoxTopBottomBorderTilemap[i]; - uint16 i = WriteMessageTilemap(); - R22_ = 32; - uint16 v1 = 0; - do { - ram3000.pause_menu_map_tilemap[i + 256] = kSmallMsgBoxTopBottomBorderTilemap[v1 >> 1]; - v1 += 2; - ++i; - --R22_; - } while (R22_); -} - -uint16 WriteMessageTilemap(void) { // 0x8582B8 +static uint16 WriteMessageTilemap(void) { // 0x8582B8 message_box_animation_y1 = 112; message_box_animation_y0 = 124; message_box_animation_y_radius = 0; for (int i = 0; i != 112; ++i) ram3000.pause_menu_map_tilemap[i] = 0; bg3_tilemap_offset = 2 * (message_box_index - 1); - R0_.addr = *(VoidP *)((uint8 *)&kMessageBoxDefs[0].message_tilemap + (uint16)(6 * (message_box_index - 1))); - R9_.addr = *(VoidP *)((uint8 *)&kMessageBoxDefs[1].message_tilemap - + (uint16)(6 * (message_box_index - 1))) - - R0_.addr; - R22_ = R9_.addr >> 1; - R9_.addr += 128; + uint16 r0 = *(VoidP *)((uint8 *)&kMessageBoxDefs[0].message_tilemap + (6 * (message_box_index - 1))); + uint16 r9 = *(VoidP *)((uint8 *)&kMessageBoxDefs[1].message_tilemap + (6 * (message_box_index - 1))) - r0; + int n = r9 >> 1; + r9 += 128; + message_box_das0l_value = r9; uint16 v1 = 32; uint16 v2 = 0; do { - ram3000.pause_menu_map_tilemap[v1 + 256] = *(uint16 *)&RomPtr_85(R0_.addr)[v2]; + ram3000.pause_menu_map_tilemap[v1 + 256] = *(uint16 *)&RomPtr_85(r0)[v2]; ++v1; v2 += 2; - --R22_; - } while (R22_); + } while (--n); return v1; } -void SetupMessageBoxBg3YscrollHdma(void) { // 0x858363 +static void WriteLargeMessageBoxTilemap(void) { + for (int i = 0; i != 32; ++i) + ram3000.pause_menu_map_tilemap[i + 256] = kLargeMsgBoxTopBottomBorderTilemap[i]; + uint16 i = WriteMessageTilemap(); + int n = 32; + uint16 v1 = 0; + do { + ram3000.pause_menu_map_tilemap[i + 256] = kLargeMsgBoxTopBottomBorderTilemap[v1 >> 1]; + v1 += 2; + ++i; + } while (--n); +} + +static void WriteSmallMessageBoxTilemap(void) { // 0x858289 + for (int i = 0; i != 32; ++i) + ram3000.pause_menu_map_tilemap[i + 256] = kSmallMsgBoxTopBottomBorderTilemap[i]; + uint16 i = WriteMessageTilemap(); + int n = 32; + uint16 v1 = 0; + do { + ram3000.pause_menu_map_tilemap[i + 256] = kSmallMsgBoxTopBottomBorderTilemap[v1 >> 1]; + v1 += 2; + ++i; + } while (--n); +} + +static void CallMsgBoxDraw(uint32 ea) { + switch (ea) { + case fnWriteLargeMessageBoxTilemap: WriteLargeMessageBoxTilemap(); return; + case fnWriteSmallMessageBoxTilemap: WriteSmallMessageBoxTilemap(); return; + default: Unreachable(); + } +} + +static void MsgBoxMakeHdmaTable(void) { + message_box_animation_y2 = (uint16)(31488 - message_box_animation_y_radius) >> 8; + message_box_animation_y3 = 99; + message_box_animation_y0 = (uint16)(message_box_animation_y_radius + 31744) >> 8; + message_box_animation_y1 = 148; + uint16 v0 = 123; + uint16 v1 = 124; + uint16 r20 = 30; + do { + ram3000.pause_menu_map_tilemap[v0] = message_box_animation_y3 - message_box_animation_y2; + --message_box_animation_y3; + --message_box_animation_y2; + ram3000.pause_menu_map_tilemap[v1] = message_box_animation_y1 - message_box_animation_y0; + --v0; + ++message_box_animation_y1; + ++message_box_animation_y0; + ++v1; + } while (--r20); + uint16 v2 = v1 * 2; + do { + *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + v2) = 0; + v2 += 2; + } while ((int16)(v2 - 480) < 0); +} + +static void SetupMessageBoxBg3YscrollHdma(void) { // 0x858363 *(uint32 *)&ram3000.menu.palette_backup_in_menu[64] = -516947713; ram3000.pause_menu_map_tilemap[450] = 12542; ram3000.msgbox.indirect_hdma[6] = 0; @@ -221,64 +177,25 @@ void SetupMessageBoxBg3YscrollHdma(void) { // 0x858363 WriteReg(HDMAEN, 0x40); } -void SetupPpuForActiveMessageBox(void) { // 0x85831E +static void SetupPpuForActiveMessageBox(void) { // 0x85831E SetupMessageBoxBg3YscrollHdma(); bg3_tilemap_offset += 22528; WriteRegWord(VMADDL, bg3_tilemap_offset); WriteRegWord(DMAP1, 0x1801); WriteRegWord(A1T1L, ADDR16_OF_RAM(ram3000) + 512); WriteRegWord(A1B1, 0x7E); - WriteRegWord(DAS1L, R9_.addr); + WriteRegWord(DAS1L, message_box_das0l_value); WriteRegWord(DAS10, 0); WriteRegWord(A2A1H, 0); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } -CoroutineRet OpenMessageBox_Async(void) { // 0x85844C - COROUTINE_BEGIN(coroutine_state_4, 0); - for (message_box_animation_y_radius = 0;; message_box_animation_y_radius += 512) { - COROUTINE_AWAIT(1, WaitForNMI_NoUpdate_Async()); - HandleMusicQueue(); - HandleSoundEffects(); - MsgBoxMakeHdmaTable(); - if (message_box_animation_y_radius == 0x1800) - break; - } - COROUTINE_END(0); -} - -CoroutineRet CloseMessageBox_Async(void) { // 0x858589 - COROUTINE_BEGIN(coroutine_state_4, 0); - do { - COROUTINE_AWAIT(1, WaitForNMI_NoUpdate_Async()); - HandleMusicQueue(); - HandleSoundEffects(); - MsgBoxMakeHdmaTable(); - message_box_animation_y_radius -= 512; - } while ((message_box_animation_y_radius & 0x8000u) == 0); - COROUTINE_END(0); -} - - -void DrawShootButtonAndSetupPpuForLargeMessageBox(void) { // 0x8583C5 - DrawSpecialButtonAndSetupPpuForLargeMessageBox(button_config_shoot_x); -} - -void DrawRunButtonAndSetupPpuForLargeMessageBox(void) { // 0x8583CC - DrawSpecialButtonAndSetupPpuForLargeMessageBox(button_config_run_b); -} -static const uint16 kMsgBoxSpecialButtonTilemapOffs[27] = { // 0x8583D1 - 0, 0x12a, 0x12a, 0x12c, 0x12c, 0x12c, 0, 0, 0, 0, 0, 0, 0x120, 0, 0, 0, - 0, 0, 0x12a, 0, 0, 0, 0, 0, 0, 0, 0, -}; -static const uint16 kTileNumbersForButtonLetters[8] = { 0x28e0, 0x3ce1, 0x2cf7, 0x38f8, 0x38d0, 0x38eb, 0x38f1, 0x284e }; - -void DrawSpecialButtonAndSetupPpuForLargeMessageBox(uint16 a) { +static void DrawSpecialButtonAndSetupPpuForLargeMessageBox(uint16 a) { uint16 v1 = 0; if ((a & kButton_A) == 0) { v1 = 2; - if ((a & 0x8000u) == 0) { + if ((a & 0x8000) == 0) { v1 = 4; if ((a & kButton_X) == 0) { v1 = 6; @@ -296,64 +213,47 @@ void DrawSpecialButtonAndSetupPpuForLargeMessageBox(uint16 a) { } } } - *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[256] - + kMsgBoxSpecialButtonTilemapOffs[message_box_index - 1]) = kTileNumbersForButtonLetters[v1 >> 1]; + *(uint16 *)((uint8 *)&ram3000.pause_menu_map_tilemap[256] + kMsgBoxSpecialButtonTilemapOffs[message_box_index - 1]) = kTileNumbersForButtonLetters[v1 >> 1]; bg3_tilemap_offset = 416; SetupPpuForActiveMessageBox(); } -void SetupPpuForSmallMessageBox(void) { // 0x858436 +static void DrawShootButtonAndSetupPpuForLargeMessageBox(void) { // 0x8583C5 + DrawSpecialButtonAndSetupPpuForLargeMessageBox(button_config_shoot_x); +} + +static void DrawRunButtonAndSetupPpuForLargeMessageBox(void) { // 0x8583CC + DrawSpecialButtonAndSetupPpuForLargeMessageBox(button_config_run_b); +} + +static void SetupPpuForSmallMessageBox(void) { // 0x858436 bg3_tilemap_offset = 448; SetupPpuForActiveMessageBox(); } -void SetupPpuForLargeMessageBox(void) { // 0x858441 +static void SetupPpuForLargeMessageBox(void) { // 0x858441 bg3_tilemap_offset = 416; SetupPpuForActiveMessageBox(); } - -CoroutineRet HandleMessageBoxInteraction_Async(void) { // 0x85846D - COROUTINE_BEGIN(coroutine_state_4, 0); - - if (message_box_index == 23 || message_box_index == 28) { - save_confirmation_selection = 0; - while (1) { - do { - COROUTINE_AWAIT(1, WaitForNMI_NoUpdate_Async()); - HandleMusicQueue(); - HandleSoundEffects(); - ReadJoypadInputs(); - } while (!joypad1_newkeys); - if ((joypad1_newkeys & kButton_A) != 0) - break; - if ((joypad1_newkeys & kButton_B) != 0) { - save_confirmation_selection = 2; - goto GETOUT; - } - if ((joypad1_newkeys & (kButton_Select | kButton_Left | kButton_Right)) != 0) { - ToggleSaveConfirmationSelection(); - QueueSfx1_Max6(0x37u); - } - } - } else { - my_counter = 10; - if (message_box_index != 20 && message_box_index != 21 && message_box_index != 22 && message_box_index != 24) - my_counter = 360; - do { - COROUTINE_AWAIT(2, WaitForNMI_NoUpdate_Async()); - HandleMusicQueue(); - HandleSoundEffects(); - } while (--my_counter); - do { - COROUTINE_AWAIT(3, WaitForNMI_NoUpdate_Async()); - ReadJoypadInputs(); - } while ((bug_fix_counter < 1 ? joypad1_newkeys : joypad1_lastkeys) == 0); +static void CallMsgBoxModify(uint32 ea) { + switch (ea) { + case fnDrawShootButtonAndSetupPpuForLargeMessageBox: DrawShootButtonAndSetupPpuForLargeMessageBox(); return; + case fnDrawRunButtonAndSetupPpuForLargeMessageBox: DrawRunButtonAndSetupPpuForLargeMessageBox(); return; + case fnSetupPpuForSmallMessageBox: SetupPpuForSmallMessageBox(); return; + case fnSetupPpuForLargeMessageBox: SetupPpuForLargeMessageBox(); return; + default: Unreachable(); } -GETOUT:; - COROUTINE_END(0); } +static void InitializeMessageBox(void) { // 0x858241 + bg3_tilemap_offset = 2 * (message_box_index - 1); + uint16 v0 = message_box_index - 1; + CallMsgBoxDraw(kMessageBoxDefs[v0].draw_initial_tilemap | 0x850000); + CallMsgBoxModify(kMessageBoxDefs[v0].modify_box_func | 0x850000); +} + + static const uint16 kSaveConfirmationSelectionTilemap[96] = { // 0x858507 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0x3c4e, 0x3c4e, 0x38cc, 0x38cd, 0x3cf8, 0x3ce4, 0x3cf2, 0x3c4e, 0x3c4e, 0x3c4e, 0x3c4e, 0x3c4e, 0x3c4e, 0x2ced, 0x2cee, 0x3c4e, 0x3c4e, 0x3c4e, 0x3c4e, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, @@ -363,8 +263,8 @@ static const uint16 kSaveConfirmationSelectionTilemap[96] = { // 0x858507 0x3c4e, 0x38cc, 0x38cd, 0x3ced, 0x3cee, 0x3c4e, 0x3c4e, 0x3c4e, 0x3c4e, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, }; -void ToggleSaveConfirmationSelection(void) { - save_confirmation_selection ^= 2u; +static void ToggleSaveConfirmationSelection(void) { + save_confirmation_selection ^= 2; uint16 v0 = 64; if (save_confirmation_selection == 2) v0 = 128; @@ -385,37 +285,10 @@ void ToggleSaveConfirmationSelection(void) { WriteRegWord(DAS10, 0); WriteRegWord(A2A1H, 0); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } - -void MsgBoxMakeHdmaTable(void) { - message_box_animation_y2 = (uint16)(31488 - message_box_animation_y_radius) >> 8; - message_box_animation_y3 = 99; - message_box_animation_y0 = (uint16)(message_box_animation_y_radius + 31744) >> 8; - message_box_animation_y1 = 148; - uint16 v0 = 123; - uint16 v1 = 124; - R20_ = 30; - do { - ram3000.pause_menu_map_tilemap[v0] = message_box_animation_y3 - message_box_animation_y2; - --message_box_animation_y3; - --message_box_animation_y2; - ram3000.pause_menu_map_tilemap[v1] = message_box_animation_y1 - message_box_animation_y0; - --v0; - ++message_box_animation_y1; - ++message_box_animation_y0; - ++v1; - --R20_; - } while (R20_); - uint16 v2 = v1 * 2; - do { - *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + v2) = 0; - v2 += 2; - } while ((int16)(v2 - 480) < 0); -} - -void RestorePpuForMessageBox(void) { // 0x85861A +static void RestorePpuForMessageBox(void) { // 0x85861A WriteRegWord(VMADDL, addr_unk_605880); WriteRegWord(DMAP1, 0x1801); WriteRegWord(A1T1L, ADDR16_OF_RAM(ram4000) + 256); @@ -424,7 +297,7 @@ void RestorePpuForMessageBox(void) { // 0x85861A WriteRegWord(DAS10, 0); WriteRegWord(A2A1H, 0); WriteReg(VMAIN, 0x80); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); reg_HDMAEN = ram3000.msgbox.backup_of_enabled_hdma_channels; WriteReg(HDMAEN, ram3000.msgbox.backup_of_enabled_hdma_channels); gameplay_BG3SC = ram3000.misc.field_3E8[3]; @@ -436,4 +309,126 @@ void RestorePpuForMessageBox(void) { // 0x85861A WriteReg(CGDATA, HIBYTE(palette_buffer[25])); WriteReg(CGDATA, palette_buffer[26]); WriteReg(CGDATA, HIBYTE(palette_buffer[26])); -} \ No newline at end of file +} + +static CoroutineRet OpenMessageBox_Async(void) { // 0x85844C + COROUTINE_BEGIN(coroutine_state_4, 0); + for (message_box_animation_y_radius = 0;; message_box_animation_y_radius += 512) { + COROUTINE_AWAIT(1, WaitForNMI_NoUpdate_Async()); + HandleMusicQueue(); + HandleSoundEffects(); + MsgBoxMakeHdmaTable(); + if (message_box_animation_y_radius == 0x1800) + break; + } + COROUTINE_END(0); +} + +static CoroutineRet HandleMessageBoxInteraction_Async(void) { // 0x85846D + COROUTINE_BEGIN(coroutine_state_4, 0); + + if (message_box_index == 23 || message_box_index == 28) { + save_confirmation_selection = 0; + while (1) { + do { + COROUTINE_AWAIT(1, WaitForNMI_NoUpdate_Async()); + HandleMusicQueue(); + HandleSoundEffects(); + ReadJoypadInputs(); + } while (!joypad1_newkeys); + if ((joypad1_newkeys & kButton_A) != 0) + break; + if ((joypad1_newkeys & kButton_B) != 0) { + save_confirmation_selection = 2; + goto GETOUT; + } + if ((joypad1_newkeys & (kButton_Select | kButton_Left | kButton_Right)) != 0) { + ToggleSaveConfirmationSelection(); + QueueSfx1_Max6(0x37); + } + } + } else { + my_counter = 10; + if (message_box_index != 20 && message_box_index != 21 && message_box_index != 22 && message_box_index != 24) + my_counter = 360; + do { + COROUTINE_AWAIT(2, WaitForNMI_NoUpdate_Async()); + HandleMusicQueue(); + HandleSoundEffects(); + } while (--my_counter); + do { + COROUTINE_AWAIT(3, WaitForNMI_NoUpdate_Async()); + ReadJoypadInputs(); + } while ((bug_fix_counter < 1 ? joypad1_newkeys : joypad1_lastkeys) == 0); + } +GETOUT:; + COROUTINE_END(0); +} + +static CoroutineRet CloseMessageBox_Async(void) { // 0x858589 + COROUTINE_BEGIN(coroutine_state_4, 0); + do { + COROUTINE_AWAIT(1, WaitForNMI_NoUpdate_Async()); + HandleMusicQueue(); + HandleSoundEffects(); + MsgBoxMakeHdmaTable(); + message_box_animation_y_radius -= 512; + } while ((message_box_animation_y_radius & 0x8000) == 0); + COROUTINE_END(0); +} + +CoroutineRet DisplayMessageBox_Async(uint16 a) { // 0x858080 + COROUTINE_BEGIN(coroutine_state_3, 0) + message_box_index = a; + CancelSoundEffects(); + InitializePpuForMessageBoxes(); + ClearMessageBoxBg3Tilemap(); + InitializeMessageBox(); + COROUTINE_AWAIT(2, OpenMessageBox_Async()); + COROUTINE_AWAIT(3, HandleMessageBoxInteraction_Async()); + COROUTINE_AWAIT(4, CloseMessageBox_Async()); + + if (message_box_index == 28 && save_confirmation_selection != 2) { + message_box_index = 24; + ClearMessageBoxBg3Tilemap(); + QueueSfx1_Max6(0x2E); + + my_counter = 160; + do { + HandleMusicQueue(); + HandleSoundEffects(); + COROUTINE_AWAIT(8, WaitForNMI_NoUpdate_Async()); + } while (--my_counter); + + InitializeMessageBox(); + COROUTINE_AWAIT(5, OpenMessageBox_Async()); + COROUTINE_AWAIT(6, HandleMessageBoxInteraction_Async()); + COROUTINE_AWAIT(7, CloseMessageBox_Async()); + message_box_index = 28; + } + ClearMessageBoxBg3Tilemap(); + RestorePpuForMessageBox(); + QueueSamusMovementSfx(); + + if (message_box_index == 20) { + game_state = kGameState_12_Pausing; + } + COROUTINE_END(0); + // else if (message_box_index == 28 || message_box_index == 23) { + // return save_confirmation_selection; + // } + // return 0; +} + +int DisplayMessageBox_Poll(uint16 a) { + if (a == message_box_index) { + message_box_index = 0; + return save_confirmation_selection; + } + queued_message_box_index = a; + return -1; +} + +void DisplayMessageBox(uint16 a) { // 0x858080 + queued_message_box_index = a; +} diff --git a/src/sm_86.c b/src/sm_86.c index dea5fc7..ecec2b4 100644 --- a/src/sm_86.c +++ b/src/sm_86.c @@ -5,6 +5,10 @@ #include "funcs.h" #include "enemy_types.h" +Rect16U eproj_spawn_rect; +uint16 eproj_spawn_r22; +Point16U eproj_spawn_pt; // R18/R20 +uint16 eproj_spawn_varE24; #define kScreenShakeOffsets ((uint16*)RomFixedPtr(0x86846b)) #define kAlignYPos_Tab0 ((uint8*)RomFixedPtr(0x948b2b)) @@ -15,6 +19,7 @@ #define stru_86BB50 (*(EnemyProjectileDef*)RomFixedPtr(0x86bb50)) #define off_86BB1E ((uint16*)RomFixedPtr(0x86bb1e)) #define kCommonEnemySpeeds_Quadratic_Copy ((uint16*)RomFixedPtr(0xa0cbc7)) +#define kCommonEnemySpeeds_Quadratic32 ((uint32*)RomFixedPtr(0xa0cbc7)) #define off_86C040 ((uint16*)RomFixedPtr(0x86c040)) #define off_86C929 ((uint16*)RomFixedPtr(0x86c929)) #define CHECK_locret_868728(i) (unk_868729[i] & 0x80 ? -1 : 0) @@ -39,15 +44,63 @@ #define kEnemyDef_F3D3 (*(EnemyDef_B2*)RomFixedPtr(0xa0f3d3)) #define g_word_86F3D4 ((uint16*)RomFixedPtr(0x86f3d4)) // bug:: oob read +typedef struct EprojCollInfo { + uint16 eci_r20; + uint16 eci_r24; + uint16 eci_r26; + uint16 eci_r28; + uint16 eci_r30; + uint16 eci_r32; + uint16 eci_r34; +} EprojCollInfo; +static uint8 EprojColl_85C2(EprojCollInfo *eci, uint16 a, uint16 k); +static uint8 EprojColl_8676(EprojCollInfo *eci, uint16 a, uint16 k, uint16 j); +static uint8 EprojColl_874E(EprojCollInfo *eci); +static Rect16U Eproj_GetCollDetectRect(uint16 k); + +static void CallEprojPreInstr(uint32 ea, uint16 k); +static const uint8 *CallEprojInstr(uint32 ea, uint16 k, const uint8 *j); +static void CallEnemyProjectileInit(uint32 ea, uint16 j); +static uint16 CheckIfEnemyProjectileIsOffScreen(uint16 k); + +uint16 MoveEprojWithVelocity(uint16 k); +uint16 MoveEprojWithVelocityX(uint16 k); +uint16 MoveEprojWithVelocityY(uint16 k); + +void sub_8690B3(uint16 k); +void sub_869DA5(uint16 k); +void sub_86A301(uint16 j); +void sub_86A887(uint16 k); +void sub_86A91A(uint16 v0); +void sub_86B0B9(uint16 k); +void sub_86B0DD(uint16 k); +void sub_86B535(uint16 k); +void sub_86BB30(uint16 j); +void sub_86C320(uint16 k); +void sub_86C42E(uint16 k); +void sub_86C605(uint16 j); +void sub_86CFD5(uint16 k); +void sub_86CFE6(uint16 k); +void sub_86CFF8(uint16 k); +void sub_86D7BF(uint16 k); +void sub_86D7DE(uint16 k); +void sub_86D83D(uint16 k); +void sub_86D89F(uint16 k); +void sub_86D8DF(uint16 k); +void sub_86D992(uint16 k); +void sub_86DCC3(uint16 j); +void sub_86E049(uint16 k); +void sub_86E0A4(uint16 k); +void sub_86EC0C(uint16 k); void EnableEnemyProjectiles(void) { // 0x868000 - enemy_projectile_enable_flag |= 0x8000u; + enemy_projectile_enable_flag |= 0x8000; } void DisableEnemyProjectiles(void) { // 0x86800B - enemy_projectile_enable_flag &= ~0x8000u; + enemy_projectile_enable_flag &= ~0x8000; } void ClearEnemyProjectiles(void) { // 0x868016 @@ -55,7 +108,4840 @@ void ClearEnemyProjectiles(void) { // 0x868016 enemy_projectile_id[i >> 1] = 0; } -void CallEnemyProjectileInit(uint32 ea, uint16 j) { +static void SpawnEnemyProjectileInner(uint16 j, uint16 gfx_idx) { // 0x868027 + uint16 v3 = 34; + while (enemy_projectile_id[v3 >> 1]) { + v3 -= 2; + if ((v3 & 0x8000) != 0) + return; + } + int v4 = v3 >> 1; + enemy_projectile_gfx_idx[v4] = gfx_idx; + enemy_projectile_id[v4] = j; + EnemyProjectileDef *Edef = get_EnemyProjectileDef(j); + enemy_projectile_pre_instr[v4] = Edef->pre_instr_ptr; + enemy_projectile_instr_list_ptr[v4] = Edef->instr_list; + enemy_projectile_radius[v4] = Edef->radius; + enemy_projectile_properties[v4] = Edef->properties; + enemy_projectile_instr_timers[v4] = 1; + enemy_projectile_spritemap_ptr[v4] = 0x8000; + enemy_projectile_E[v4] = 0; + enemy_projectile_F[v4] = 0; + enemy_projectile_timers[v4] = 0; + enemy_projectile_x_subpos[v4] = 0; + enemy_projectile_y_subpos[v4] = 0; + enemy_projectile_G[v4] = 0; + CallEnemyProjectileInit(Edef->init_code_ptr | 0x860000, v3); +} + +void SpawnEnemyProjectileWithGfx(uint16 a, uint16 k, uint16 j) { // 0x868027 + enemy_projectile_init_param_1 = a; + EnemyData *E = gEnemyData(k); + SpawnEnemyProjectileInner(j, E->vram_tiles_index | E->palette_index); +} + +void SpawnEnemyProjectileWithRoomGfx(uint16 j, uint16 a) { // 0x868097 + enemy_projectile_init_param_1 = a; + SpawnEnemyProjectileInner(j, 0); +} + +static void EprojRunOne(uint16 k) { // 0x868125 + CallEprojPreInstr(enemy_projectile_pre_instr[k >> 1] | 0x860000, k); + uint16 v1 = enemy_projectile_index; + int v2 = enemy_projectile_index >> 1; + if (enemy_projectile_instr_timers[v2]-- == 1) { + const uint8 *base = RomBankBase(0x86); + const uint8 *p = base + enemy_projectile_instr_list_ptr[v2]; + while (1) { + if ((GET_WORD(p) & 0x8000) == 0) + break; + p = CallEprojInstr(GET_WORD(p) | 0x860000, v1, p + 2); + if ((uintptr_t)p < 0x10000) { + if (!p) + return; + p = base + (uintptr_t)p; + } + } + int v7 = v1 >> 1; + enemy_projectile_instr_timers[v7] = GET_WORD(p); + enemy_projectile_spritemap_ptr[v7] = GET_WORD(p + 2); + enemy_projectile_instr_list_ptr[v7] = p + 4 - base; + } +} + +void EprojRunAll(void) { // 0x868104 + if ((enemy_projectile_enable_flag & 0x8000) != 0) { + for (int i = 34; i >= 0; i -= 2) { + enemy_projectile_index = i; + if (enemy_projectile_id[i >> 1]) { + EprojRunOne(i); + i = enemy_projectile_index; + } + } + } +} + +const uint8 *EprojInstr_Delete(uint16 k, const uint8 *epjp) { // 0x868154 + enemy_projectile_id[k >> 1] = 0; + return 0; +} + +const uint8 *EprojInstr_Sleep(uint16 k, const uint8 *epjp) { // 0x868159 + enemy_projectile_instr_list_ptr[k >> 1] = epjp - RomBankBase(0x86) - 2; + return 0; +} + +const uint8 *EprojInstr_SetPreInstr_(uint16 k, const uint8 *epjp) { // 0x868161 + enemy_projectile_pre_instr[k >> 1] = GET_WORD(epjp); + return epjp + 2; +} + +const uint8 *EprojInstr_ClearPreInstr(uint16 k, const uint8 *epjp) { // 0x86816A + enemy_projectile_pre_instr[k >> 1] = 0x8170; + return epjp; +} + +void CallEprojFunc(uint32 ea, uint32 k) { + switch (ea) { + case fnSpawnMotherBrainDeathBeam: SpawnMotherBrainDeathBeam(k); return; + default: Unreachable(); + } +} + +const uint8 *EprojInstr_CallFunc(uint16 k, const uint8 *epjp) { // 0x868171 + CallEprojFunc(Load24((LongPtr *)epjp), k); + return epjp + 3; +} + +const uint8 *EprojInstr_Goto(uint16 k, const uint8 *epjp) { // 0x8681AB + return INSTRB_RETURN_ADDR(GET_WORD(epjp)); +} + +const uint8 *EprojInstr_GotoRel(uint16 k, const uint8 *epjp) { // 0x8681B0 + return epjp + (int8)*epjp; +} + +const uint8 *EprojInstr_DecTimerAndGotoIfNonZero(uint16 k, const uint8 *epjp) { // 0x8681C6 + int v2 = k >> 1; + if (enemy_projectile_timers[v2]-- == 1) + return epjp + 2; + else + return EprojInstr_Goto(k, epjp); +} + +const uint8 *EprojInstr_DecTimerAndGotoRelIfNonZero(uint16 k, const uint8 *epjp) { // 0x8681CE + int v2 = k >> 1; + if (enemy_projectile_timers[v2]-- == 1) + return epjp + 1; + else + return EprojInstr_GotoRel(k, epjp); +} + +const uint8 *EprojInstr_SetTimer(uint16 k, const uint8 *epjp) { // 0x8681D5 + enemy_projectile_timers[k >> 1] = GET_WORD(epjp); + return epjp + 2; +} + +const uint8 *EprojInstr_MoveRandomlyWithinRadius(uint16 k, const uint8 *epjp) { // 0x8681DF + int8 Random; + int8 v4; + int16 v6; + + uint16 r18 = NextRandom(); + do { + Random = NextRandom(); + v4 = (*epjp & Random) - epjp[1]; + } while (v4 < 0); + enemy_projectile_x_pos[k >> 1] += sign16(r18) ? -(uint8)v4 : (uint8)v4; + do { + LOBYTE(v6) = NextRandom(); + LOBYTE(v6) = (epjp[2] & v6) - epjp[3]; + } while ((v6 & 0x80) != 0); + v6 = (uint8)v6; + if ((r18 & 0x4000) != 0) + v6 = -(uint8)v6; + enemy_projectile_y_pos[k >> 1] += v6; + return epjp + 4; +} + +const uint8 *EprojInstr_SetProjectileProperties(uint16 k, const uint8 *epjp) { // 0x868230 + enemy_projectile_properties[k >> 1] |= GET_WORD(epjp); + return epjp + 2; +} + +const uint8 *EprojInstr_ClearProjectileProperties(uint16 k, const uint8 *epjp) { // 0x86823C + enemy_projectile_properties[k >> 1] &= GET_WORD(epjp); + return epjp + 2; +} + +const uint8 *EprojInstr_EnableCollisionWithSamusProj(uint16 k, const uint8 *epjp) { // 0x868248 + enemy_projectile_properties[k >> 1] |= 0x8000; + return epjp; +} + +const uint8 *EprojInstr_DisableCollisionWithSamusProj(uint16 k, const uint8 *epjp) { // 0x868252 + enemy_projectile_properties[k >> 1] &= ~0x8000; + return epjp; +} + +const uint8 *EprojInstr_DisableCollisionWithSamus(uint16 k, const uint8 *epjp) { // 0x86825C + enemy_projectile_properties[k >> 1] |= 0x2000; + return epjp; +} + +const uint8 *EprojInstr_EnableCollisionWithSamus(uint16 k, const uint8 *epjp) { // 0x868266 + enemy_projectile_properties[k >> 1] &= ~0x2000; + return epjp; +} + +const uint8 *EprojInstr_SetToNotDieOnContact(uint16 k, const uint8 *epjp) { // 0x868270 + enemy_projectile_properties[k >> 1] |= 0x4000; + return epjp; +} + +const uint8 *EprojInstr_SetToDieOnContact(uint16 k, const uint8 *epjp) { // 0x86827A + enemy_projectile_properties[k >> 1] &= ~0x4000; + return epjp; +} + +const uint8 *EprojInstr_SetLowPriority(uint16 k, const uint8 *epjp) { // 0x868284 + enemy_projectile_properties[k >> 1] |= 0x1000; + return epjp; +} + +const uint8 *EprojInstr_SetHighPriority(uint16 k, const uint8 *epjp) { // 0x86828E + enemy_projectile_properties[k >> 1] &= ~0x1000; + return epjp; +} + +const uint8 *EprojInstr_SetXyRadius(uint16 k, const uint8 *epjp) { // 0x868298 + enemy_projectile_radius[k >> 1] = GET_WORD(epjp); + return epjp + 2; +} + +const uint8 *EprojInstr_SetXyRadiusZero(uint16 k, const uint8 *epjp) { // 0x8682A1 + enemy_projectile_radius[k >> 1] = 0; + return epjp; +} + +const uint8 *EprojInstr_CalculateDirectionTowardsSamus(uint16 k, const uint8 *epjp) { // 0x8682A5 + int v2 = k >> 1; + uint16 x = samus_x_pos - enemy_projectile_x_pos[v2]; + uint16 y = samus_y_pos - enemy_projectile_y_pos[v2]; + uint16 v3 = 2 * CalculateAngleFromXY(x, y); + int v4 = enemy_projectile_index >> 1; + enemy_projectile_E[v4] = v3; + int v5 = v3 >> 1; + enemy_projectile_x_vel[v4] = kSinCosTable8bit_Sext[v5 + 64]; + enemy_projectile_y_vel[v4] = kSinCosTable8bit_Sext[v5]; + return epjp; +} + +const uint8 *EprojInstr_WriteColorsToPalette(uint16 k, const uint8 *epjp) { // 0x8682D5 + uint16 v3 = GET_WORD(epjp + 2); + int n = epjp[4]; + uint16 v4 = GET_WORD(epjp); + do { + palette_buffer[v3 >> 1] = *(uint16 *)RomPtr_86(v4); + v4 += 2; + v3 += 2; + } while ((--n & 0x8000) == 0); + return epjp + 5; +} + +const uint8 *EprojInstr_QueueMusic(uint16 k, const uint8 *epjp) { // 0x8682FD + QueueMusic_Delayed8(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx1_Max6(uint16 k, const uint8 *epjp) { // 0x868309 + QueueSfx1_Max6(*epjp); + return epjp + 1; +} +const uint8 *EprojInstr_QueueSfx2_Max6(uint16 k, const uint8 *epjp) { // 0x868312 + QueueSfx2_Max6(*epjp); + return epjp + 1; +} +const uint8 *EprojInstr_QueueSfx3_Max6(uint16 k, const uint8 *epjp) { // 0x86831B + QueueSfx3_Max6(*epjp); + return epjp + 1; +} +const uint8 *EprojInstr_QueueSfx1_Max15(uint16 k, const uint8 *epjp) { // 0x868324 + QueueSfx1_Max15(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx2_Max15(uint16 k, const uint8 *epjp) { // 0x86832D + QueueSfx2_Max15(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx3_Max15(uint16 k, const uint8 *epjp) { // 0x868336 + QueueSfx3_Max15(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx1_Max3(uint16 k, const uint8 *epjp) { // 0x86833F + QueueSfx1_Max3(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx2_Max3(uint16 k, const uint8 *epjp) { // 0x868348 + QueueSfx2_Max3(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx3_Max3(uint16 k, const uint8 *epjp) { // 0x868351 + QueueSfx3_Max3(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx1_Max9(uint16 k, const uint8 *epjp) { // 0x86835A + QueueSfx1_Max9(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx2_Max9(uint16 k, const uint8 *epjp) { // 0x868363 + QueueSfx2_Max9(*epjp); + return epjp + 1; +} + +const uint8 *EprojInstr_QueueSfx3_Max9(uint16 k, const uint8 *epjp) { // 0x86836C + QueueSfx3_Max9(*epjp); + return epjp + 1; +} +const uint8 *EprojInstr_QueueSfx1_Max1(uint16 k, const uint8 *epjp) { // 0x868375 + QueueSfx1_Max1(*epjp); + return epjp + 1; +} +const uint8 *EprojInstr_QueueSfx2_Max1(uint16 k, const uint8 *epjp) { // 0x86837E + QueueSfx2_Max1(*epjp); + return epjp + 1; +} +const uint8 *EprojInstr_QueueSfx3_Max1(uint16 k, const uint8 *epjp) { // 0x868387 + QueueSfx3_Max1(*epjp); + return epjp + 1; +} + +void DrawLowPriorityEnemyProjectiles(void) { // 0x868390 + Point16U pt = GetValuesForScreenShaking(); + for (int i = 34; i >= 0; i -= 2) { + int v1 = i >> 1; + if (enemy_projectile_id[v1]) { + if ((enemy_projectile_properties[v1] & 0x1000) != 0) + DrawEnemyProjectiles(i, pt); + } + } +} + +void DrawHighPriorityEnemyProjectiles(void) { // 0x8683B2 + Point16U pt = GetValuesForScreenShaking(); + for (int i = 34; i >= 0; i -= 2) { + int v1 = i >> 1; + if (enemy_projectile_id[v1]) { + if ((enemy_projectile_properties[v1] & 0x1000) == 0) + DrawEnemyProjectiles(i, pt); + } + } +} + +void DrawEnemyProjectiles(uint16 k, Point16U pt) { // 0x8683D6 + int v1 = k >> 1; + uint16 v2 = enemy_projectile_spritemap_ptr[v1]; + uint16 r26 = LOBYTE(enemy_projectile_gfx_idx[v1]); + uint16 R28 = enemy_projectile_gfx_idx[v1] & 0xFF00; + uint16 r20 = pt.x + enemy_projectile_x_pos[v1] - layer1_x_pos; + if (((r20 + 128) & 0xFE00) == 0) { + uint16 v3 = pt.y + enemy_projectile_y_pos[v1] - layer1_y_pos; + uint16 r18 = v3; + if ((v3 & 0xFF00) != 0) { + if (((v3 + 128) & 0xFE00) == 0) + DrawEnemyProjectileSpritemapWithBaseTileOffscreen(0x8D, v2, r20, r18, r26, R28); + } else { + DrawEnemyProjectileSpritemapWithBaseTile(0x8D, v2, r20, r18, r26, R28); + } + } +} + +Point16U GetValuesForScreenShaking(void) { // 0x868427 + uint16 R34, R36; + if (earthquake_timer && !time_is_frozen_flag && sign16(earthquake_type - 36)) { + int v0 = (uint16)(4 * earthquake_type) >> 1; + if ((earthquake_timer & 2) != 0) { + R36 = -kScreenShakeOffsets[v0]; + R34 = -kScreenShakeOffsets[v0 + 1]; + } else { + R36 = kScreenShakeOffsets[v0]; + R34 = kScreenShakeOffsets[v0 + 1]; + } + } else { + R34 = 0; + R36 = 0; + } + return (Point16U) {R36, R34}; +} + +static uint8 EprojColl_8506(EprojCollInfo *eci) { // 0x868506 + if (BTS[cur_block_index]) { + cur_block_index += (int8)BTS[cur_block_index]; + return 0xff; + } + return 0; +} + +static uint8 EprojColl_Unknown8536(EprojCollInfo *eci) { // 0x86853C + if (BTS[cur_block_index]) { + cur_block_index += (int8)BTS[cur_block_index] * room_width_in_blocks; + return 0xff; + } + return 0; +} + +static uint8 EprojColl_ClearCarry(EprojCollInfo *eci) { // 0x86858A + return 0; +} + +static uint8 EprojColl_SetCarry(EprojCollInfo *eci) { // 0x86858C + return 1; +} + +static uint8 EprojColl_858E(EprojCollInfo *eci) { // 0x86858E + uint16 v0 = BTS[cur_block_index] & 0x1F; + if (v0 < 5) + return EprojColl_85C2(eci, v0, cur_block_index); + current_slope_bts = BTS[cur_block_index]; + return EprojColl_873D(); +} + +static uint8 EprojColl_85AD(EprojCollInfo *eci) { // 0x8685AD + uint16 v0 = BTS[cur_block_index] & 0x1F; + if (v0 >= 5) + return EprojColl_874E(eci); + else + return EprojColl_8676(eci, v0, cur_block_index, 0); +} + +static const uint8 unk_868729[20] = { // 0x8685C2 + 0, 1, 0x82, 0x83, 0, 0x81, 2, 0x83, 0, 1, 2, 0x83, 0, 0x81, 0x82, 0x83, + 0x80, 0x81, 0x82, 0x83, +}; + +static uint8 EprojColl_85C2(EprojCollInfo *eci, uint16 a, uint16 k) { + uint16 temp_collision_DD4 = 4 * a; + uint16 temp_collision_DD6 = BTS[k] >> 6; + uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((eci->eci_r34 & 8) >> 3)); + if (!eci->eci_r32) { + int v3 = enemy_projectile_index >> 1; + if (((enemy_projectile_y_pos[v3] - eci->eci_r30) & 8) != 0 + || CHECK_locret_868728(v2) >= 0) { + uint16 v4 = v2 ^ 2; + if (((eci->eci_r30 + enemy_projectile_y_pos[v3] - 1) & 8) == 0 + || CHECK_locret_868728(v4) >= 0) { + return 0; + } + } + goto LABEL_17; + } + if (!eci->eci_r26) { + if (((eci->eci_r30 + enemy_projectile_y_pos[enemy_projectile_index >> 1] - 1) & 8) == 0) { + if (CHECK_locret_868728(v2) >= 0) + return 0; + goto LABEL_17; + } + goto LABEL_14; + } + if (eci->eci_r26 != eci->eci_r32 || ((enemy_projectile_y_pos[enemy_projectile_index >> 1] - eci->eci_r30) & 8) == 0) { +LABEL_14: + if (CHECK_locret_868728(v2) < 0) + goto LABEL_17; + } + if (CHECK_locret_868728(v2 ^ 2) >= 0) + return 0; +LABEL_17:; + int v6 = enemy_projectile_index >> 1; + uint16 v7; + enemy_projectile_x_subpos[v6] = 0; + if ((eci->eci_r20 & 0x8000) != 0) + v7 = eci->eci_r28 + (eci->eci_r34 | 7) + 1; + else + v7 = (eci->eci_r34 & 0xFFF8) - eci->eci_r28; + enemy_projectile_x_pos[v6] = v7; + return 1; +} + +static uint8 EprojColl_8676(EprojCollInfo *eci, uint16 a, uint16 k, uint16 j) { // 0x868676 + uint16 v2 = enemy_projectile_index; + + uint16 temp_collision_DD4 = 4 * a; + uint16 temp_collision_DD6 = BTS[k] >> 6; + uint16 v3 = 4 * a + (temp_collision_DD6 ^ ((eci->eci_r34 & 8) >> 2)); + if (!eci->eci_r32) { + int v4 = v2 >> 1; + if (((enemy_projectile_x_pos[v4] - eci->eci_r28) & 8) != 0 + || CHECK_locret_868728(v3) >= 0) { + uint16 v5 = v3 ^ 1; + if (((eci->eci_r28 + enemy_projectile_x_pos[v4] - 1) & 8) == 0 + || CHECK_locret_868728(v5) >= 0) { + return 0; + } + } + goto LABEL_17; + } + if (!eci->eci_r26) { + if (((eci->eci_r28 + enemy_projectile_x_pos[enemy_projectile_index >> 1] - 1) & 8) == 0) { + if (CHECK_locret_868728(v3) >= 0) + return 0; + goto LABEL_17; + } + goto LABEL_14; + } + if (eci->eci_r26 != eci->eci_r32 || ((enemy_projectile_x_pos[enemy_projectile_index >> 1] - eci->eci_r28) & 8) == 0) { +LABEL_14: + if (CHECK_locret_868728(v3) < 0) + goto LABEL_17; + } + if (CHECK_locret_868728(v3 ^ 1) >= 0) + return 0; +LABEL_17:; + int v7 = enemy_projectile_index >> 1; + uint16 v8; + enemy_projectile_y_subpos[v7] = 0; + if ((eci->eci_r20 & 0x8000) != 0) + v8 = eci->eci_r30 + (eci->eci_r34 | 7) + 1; + else + v8 = (eci->eci_r34 & 0xFFF8) - eci->eci_r30; + enemy_projectile_y_pos[v7] = v8; + return 1; +} + +uint8 EprojColl_873D(void) { // 0x86873D + return 0; +} + +static uint8 EprojColl_874E(EprojCollInfo *eci) { // 0x86874E + int16 v3; + int16 v5; + uint16 v6; + uint16 v7; + int16 v8; + int16 v11; + int16 v12; + uint16 v13; + uint16 v14; + int16 v15; + + uint16 v0 = enemy_projectile_index; + if ((eci->eci_r20 & 0x8000) != 0) { + uint16 v9 = cur_block_index; + uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); + int v10 = v0 >> 1; + v11 = enemy_projectile_x_pos[v10] >> 4; + if (v11 == mod) { + uint16 temp_collision_DD4 = (eci->eci_r24 - eci->eci_r30) & 0xF ^ 0xF; + uint16 temp_collision_DD6 = 16 * (BTS[v9] & 0x1F); + v12 = BTS[v9] << 8; + if (v12 < 0 + && ((v12 & 0x4000) != 0 ? (v13 = enemy_projectile_x_pos[v10] ^ 0xF) : (v13 = enemy_projectile_x_pos[v10]), + (v14 = temp_collision_DD6 + (v13 & 0xF), + v15 = (kAlignYPos_Tab0[v14] & 0x1F) - temp_collision_DD4 - 1, + (kAlignYPos_Tab0[v14] & 0x1F) - temp_collision_DD4 == 1) + || v15 < 0)) { + enemy_projectile_y_pos[v10] = eci->eci_r24 - v15; + enemy_projectile_y_subpos[v10] = 0; + return 1; + } else { + return 0; + } + } else { + return 0; + } + } else { + uint16 v1 = cur_block_index; + uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); + int v2 = v0 >> 1; + v3 = enemy_projectile_x_pos[v2] >> 4; + if (v3 == mod) { + uint16 temp_collision_DD4 = (eci->eci_r30 + eci->eci_r24 - 1) & 0xF; + uint16 temp_collision_DD6 = 16 * (BTS[v1] & 0x1F); + v5 = BTS[v1] << 8; + if (v5 >= 0 + && ((v5 & 0x4000) != 0 ? (v6 = enemy_projectile_x_pos[v2] ^ 0xF) : (v6 = enemy_projectile_x_pos[v2]), + (v7 = temp_collision_DD6 + (v6 & 0xF), + v8 = (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 - 1, + (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 == 1) + || v8 < 0)) { + enemy_projectile_y_pos[v2] = eci->eci_r24 + v8; + enemy_projectile_y_subpos[v2] = -1; + return 1; + } else { + return 0; + } + } else { + return 0; + } + } +} + +typedef uint8 Func_EprojCollInfo_U8(EprojCollInfo *eci); + +static Func_EprojCollInfo_U8 *const kEnemyProjectileBlockCollisition_FuncA[16] = { // 0x868886 + EprojColl_ClearCarry, + EprojColl_858E, + EprojColl_ClearCarry, + EprojColl_ClearCarry, + EprojColl_ClearCarry, + EprojColl_8506, + EprojColl_ClearCarry, + EprojColl_ClearCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_Unknown8536, + EprojColl_ClearCarry, + EprojColl_SetCarry, +}; +static Func_EprojCollInfo_U8 *const kEnemyProjectileBlockCollisition_FuncB[16] = { + EprojColl_ClearCarry, + EprojColl_85AD, + EprojColl_ClearCarry, + EprojColl_ClearCarry, + EprojColl_ClearCarry, + EprojColl_8506, + EprojColl_ClearCarry, + EprojColl_ClearCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_SetCarry, + EprojColl_Unknown8536, + EprojColl_ClearCarry, + EprojColl_SetCarry, +}; + +uint8 EnemyProjectileBlockCollisition_CheckHorizontal(EprojCollInfo *eci, uint16 k) { + uint8 rv; + cur_block_index = k >> 1; + do { + rv = kEnemyProjectileBlockCollisition_FuncA[(level_data[cur_block_index] & 0xF000) >> 12](eci); + } while (rv & 0x80); + return rv; +} + +uint8 EnemyProjectileBlockCollisition_CheckVertical(EprojCollInfo *eci, uint16 k) { // 0x86889E + uint8 rv; + cur_block_index = k >> 1; + do { + rv = kEnemyProjectileBlockCollisition_FuncB[(level_data[cur_block_index] & 0xF000) >> 12](eci); + } while (rv & 0x80); + return rv; +} + +uint8 EnemyProjectileBlockCollisition_Horiz(uint16 k) { // 0x8688B6 + int v1 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_x_vel[v1]); + uint16 R30 = HIBYTE(enemy_projectile_radius[v1]); + uint16 R28 = LOBYTE(enemy_projectile_radius[v1]); + uint16 r26 = (enemy_projectile_y_pos[v1] - R30) & 0xFFF0; + r26 = (uint16)(R30 + enemy_projectile_y_pos[v1] - 1 - r26) >> 4; + uint16 R32 = r26; + uint16 prod = Mult8x8((uint16)(enemy_projectile_y_pos[v1] - R30) >> 4, room_width_in_blocks); + uint16 v3 = (amt + __PAIR32__(enemy_projectile_x_pos[v1], enemy_projectile_x_subpos[v1])) >> 16; + uint16 r22 = amt + enemy_projectile_x_subpos[v1]; + uint16 r24 = v3; + uint16 v4; + if (amt < 0) + v4 = v3 - R28; + else + v4 = R28 + v3 - 1; + EprojCollInfo eci = { .eci_r20 = amt >> 16, .eci_r24 = r24, .eci_r26 = r26, .eci_r28 = R28, .eci_r30 = R30, .eci_r32 = R32, .eci_r34 = v4 }; + uint16 v5 = 2 * (prod + (v4 >> 4)); + while (!(EnemyProjectileBlockCollisition_CheckHorizontal(&eci, v5) & 1)) { + v5 += room_width_in_blocks * 2; + if ((--eci.eci_r26 & 0x8000) != 0) { + int v6 = k >> 1; + enemy_projectile_x_subpos[v6] = r22; + enemy_projectile_x_pos[v6] = r24; + return 0; + } + } + int v8 = k >> 1; + enemy_projectile_x_subpos[v8] = 0; + if (amt < 0) { + uint16 v10 = eci.eci_r28 + (eci.eci_r34 | 0xF) + 1; + if (v10 <= enemy_projectile_x_pos[v8]) + enemy_projectile_x_pos[v8] = v10; + } else { + uint16 v9 = (eci.eci_r34 & 0xFFF0) - eci.eci_r28; + if (v9 >= enemy_projectile_x_pos[v8]) + enemy_projectile_x_pos[v8] = v9; + } + return 1; +} + +uint8 EnemyProjectileBlockCollisition_Vertical(uint16 k) { // 0x86897B + int16 v5; + + int v1 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_y_vel[v1]); + uint16 R30 = HIBYTE(enemy_projectile_radius[v1]); + uint16 R28 = LOBYTE(enemy_projectile_radius[v1]); + uint16 r26 = (enemy_projectile_x_pos[v1] - R28) & 0xFFF0; + r26 = (uint16)(R28 + enemy_projectile_x_pos[v1] - 1 - r26) >> 4; + uint16 R32 = r26; + uint16 v3 = (amt + __PAIR32__(enemy_projectile_y_pos[v1], enemy_projectile_y_subpos[v1])) >> 16; + uint16 r22 = amt + enemy_projectile_y_subpos[v1]; + uint16 r24 = v3; + uint16 v4; + if (amt < 0) + v4 = v3 - R30; + else + v4 = R30 + v3 - 1; + EprojCollInfo eci = { .eci_r20 = amt >> 16, .eci_r24 = r24, .eci_r26 = r26, .eci_r28 = R28, .eci_r30 = R30, .eci_r32 = R32, .eci_r34 = v4 }; + uint16 prod = Mult8x8(v4 >> 4, room_width_in_blocks); + v5 = (uint16)(enemy_projectile_x_pos[v1] - R28) >> 4; + for (int i = 2 * (prod + v5); !(EnemyProjectileBlockCollisition_CheckVertical(&eci, i) & 1); i += 2) { + if ((--eci.eci_r26 & 0x8000) != 0) { + int v7 = k >> 1; + enemy_projectile_y_subpos[v7] = r22; + enemy_projectile_y_pos[v7] = r24; + return 0; + } + } + int v9 = k >> 1; + enemy_projectile_y_subpos[v9] = 0; + if (amt < 0) { + uint16 v11 = eci.eci_r30 + (eci.eci_r34 | 0xF) + 1; + if (v11 <= enemy_projectile_y_pos[v9]) + enemy_projectile_y_pos[v9] = v11; + } else { + uint16 v10 = (eci.eci_r34 & 0xFFF0) - eci.eci_r30; + if (v10 >= enemy_projectile_y_pos[v9]) + enemy_projectile_y_pos[v9] = v10; + } + return 1; +} + +static void EnemyProj_Init_0x8aaf(uint16 j) { // 0x868A39 + NextRandom(); + EnemyData *v1 = gEnemyData(cur_enemy_index); + uint16 v2 = v1->y_pos + 12; + int v3 = j >> 1; + enemy_projectile_y_pos[v3] = v2; + enemy_projectile_timers[v3] = v2 + 72; + enemy_projectile_y_vel[v3] = v1->ai_var_D; + enemy_projectile_x_pos[v3] = v1->x_pos + (random_number & 0x1F) - 16; + enemy_projectile_instr_list_ptr[v3] = off_868A75[(uint16)(HIBYTE(enemy_projectile_y_vel[v3]) & 6) >> 1]; +} + +void EnemyProj_PreInit_0x8aaf(uint16 k) { // 0x868A7D + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); + + if (enemy_projectile_y_pos[v1] >= enemy_projectile_timers[v1]) + enemy_projectile_id[v1] = 0; +} + +static void EnemyProj_Init_0x8bc2_SkreeDownRight(uint16 j) { // 0x868ACD + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos; + enemy_projectile_y_vel[v2] = -769; + enemy_projectile_x_pos[v2] = v1->x_pos + 6; + enemy_projectile_x_vel[v2] = 320; +} + +static void EnemyProj_Init_0x8bd0_SkreeUpRight(uint16 j) { // 0x868AF1 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos; + enemy_projectile_y_vel[v2] = -1025; + enemy_projectile_x_pos[v2] = v1->x_pos + 6; + enemy_projectile_x_vel[v2] = 96; +} + +static void EnemyProj_Init_0x8bde_SkreeDownLeft(uint16 j) { // 0x868B15 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos; + enemy_projectile_y_vel[v2] = -769; + enemy_projectile_x_pos[v2] = v1->x_pos - 6; + enemy_projectile_x_vel[v2] = -320; +} + +static void EnemyProj_Init_0x8bec_SkreeUpLeft(uint16 j) { // 0x868B39 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos; + enemy_projectile_y_vel[v2] = -1025; + enemy_projectile_x_pos[v2] = v1->x_pos - 6; + enemy_projectile_x_vel[v2] = -96; +} + +void EnemyProj_PreInstr_SkreeParticle(uint16 k) { // 0x868B5D + int v1 = k >> 1; + + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); + + enemy_projectile_y_vel[v1] += 80; + if (CheckIfEnemyProjectileIsOffScreen(k)) + enemy_projectile_id[v1] = 0; +} + +const uint8 *EprojInstr_SpawnEnemyDropsWithDraygonsEyeDrops(uint16 k, const uint8 *epjp) { // 0x868C68 + int v1 = k >> 1; + eproj_spawn_pt = (Point16U) { enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyDrops(addr_kEnemyDef_DE7F, k, 0); + return epjp; +} + +const uint8 *EprojInstr_SetPreInstrA(uint16 k, const uint8 *epjp) { // 0x868CF6 + enemy_projectile_pre_instr[k >> 1] = FUNC16(EprojPreInstr_DraygonsTurret_8DFF); + return epjp; +} + +const uint8 *EprojInstr_SetPreInstrB(uint16 k, const uint8 *epjp) { // 0x868CFD + enemy_projectile_pre_instr[k >> 1] = FUNC16(EprojPreInstr_8DCA); + return epjp; +} + +static void EprojInit_DraygonsGunk(uint16 j) { // 0x868D04 + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = eproj_spawn_pt.x; + enemy_projectile_y_pos[v1] = eproj_spawn_pt.y; + g_word_7E97DC[v1] = enemy_projectile_unk1995; + Point32 pt = ConvertAngleToXy(enemy_projectile_unk1995, enemy_projectile_init_param_1); + enemy_projectile_x_vel[v1] = pt.x >> 16; + enemy_projectile_E[v1] = pt.x; + enemy_projectile_y_vel[v1] = pt.y >> 16; + enemy_projectile_F[v1] = pt.y; + enemy_projectile_gfx_idx[v1] = 1024; +} + +static void EprojInit_DraygonsWallTurretProjs(uint16 j) { // 0x868D40 + Eproj_AngleToSamus(j, eproj_spawn_pt.x, eproj_spawn_pt.y); + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 2560; + enemy_projectile_pre_instr[v1] = FUNC16(nullsub_84); +} + +void EprojPowerBombCollision(uint16 k) { // 0x868D5C + uint16 r18 = HIBYTE(power_bomb_explosion_radius); + if (HIBYTE(power_bomb_explosion_radius)) { + uint16 r20 = (uint16)(r18 + (HIBYTE(power_bomb_explosion_radius) & 1) + (power_bomb_explosion_radius >> 9)) >> 1; + int v1 = k >> 1; + if (abs16(power_bomb_explosion_x_pos - enemy_projectile_x_pos[v1]) < r18 + && abs16(power_bomb_explosion_y_pos - enemy_projectile_y_pos[v1]) < r20) { + enemy_projectile_id[v1] = 0; + samus_x_speed_divisor = 0; + } + } +} + +const uint8 *EprojInstr_868D99(uint16 k, const uint8 *epjp) { // 0x868D99 + EprojPowerBombCollision(k); + uint16 v2 = samus_x_speed_divisor + 1; + if (sign16(samus_x_speed_divisor - 5)) { + ++samus_x_speed_divisor; + int v3 = k >> 1; + enemy_projectile_F[v3] = v2; + enemy_projectile_E[v3] = 256; + enemy_projectile_pre_instr[v3] = FUNC16(EprojPreInstr_8DCA); + enemy_projectile_properties[v3] = enemy_projectile_properties[v3] & 0x5FFF | 0x2000; + samus_invincibility_timer = 0; + samus_knockback_timer = 0; + } + return epjp; +} + +void EprojPreInstr_8DCA(uint16 k) { // 0x868DCA + int v1; + + EprojPowerBombCollision(k); + if (samus_contact_damage_index + || (v1 = k >> 1, + enemy_projectile_x_pos[v1] = samus_x_pos, + enemy_projectile_y_pos[v1] = samus_y_pos + 4 * enemy_projectile_F[v1] - 12, + --enemy_projectile_E[v1], + !enemy_projectile_E[v1])) { + enemy_projectile_id[k >> 1] = 0; + if ((--samus_x_speed_divisor & 0x8000) != 0) + samus_x_speed_divisor = 0; + } +} + +void EprojPreInstr_DraygonsTurret_8DFF(uint16 k) { // 0x868DFF + int16 v1; + + EprojPowerBombCollision(k); + Eproj_FuncE73E_MoveXY(k); + v1 = Eproj_FuncE722(k); + if (v1) + enemy_projectile_id[k >> 1] = 0; +} + +void EprojPreInstr_DraygonsGunk_8E0F(uint16 k) { // 0x868E0F + uint16 v3; + + EprojPowerBombCollision(k); + Eproj_FuncE73E_MoveXY(k); + int v1 = k >> 1; + uint16 v2 = abs16(samus_x_pos - enemy_projectile_x_pos[v1]); + if (sign16(v2 - 16) && (v3 = abs16(samus_y_pos - enemy_projectile_y_pos[v1]), sign16(v3 - 20))) { + enemy_projectile_instr_list_ptr[v1] = 0x8C38; + enemy_projectile_instr_timers[v1] = 1; + } else { + if (Eproj_FuncE722(k)) + enemy_projectile_id[v1] = 0; + } +} + +static void EprojInit_CrocomireProjectile(uint16 j) { // 0x869023 + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = -512; + enemy_projectile_y_vel[v2] = 1; + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos - 32; + enemy_projectile_y_pos[v2] = v3->y_pos - 16; + enemy_projectile_timers[v2] = 0; + enemy_projectile_x_subpos[v2] = 0; + enemy_projectile_y_subpos[v2] = 0; + enemy_projectile_gfx_idx[v2] = 2560; +} + +static const int16 word_869059[9] = { -16, 0, 32, -16, 0, 32, -16, 0, 32 }; // bug: oob read +void EprojPreInstr_CrocomireProjectile(uint16 k) { // 0x86906B + EnemyProjectileBlockCollisition_Horiz(k); + enemy_projectile_gfx_idx[0] = 2560; + enemy_projectile_timers[k >> 1] += enemy_projectile_x_vel[k >> 1]; + uint16 x = -64; + uint16 y = g_word_869059[enemy_data[0].ai_preinstr >> 1]; // bug: out of bounds read... + int v1 = CalculateAngleFromXY(x, y); + int v2 = k >> 1; + enemy_projectile_x_vel[v2] = 4 * kSinCosTable8bit_Sext[v1 + 64]; + enemy_projectile_y_vel[v2] = 4 * kSinCosTable8bit_Sext[v1]; + enemy_projectile_pre_instr[v2] = FUNC16(sub_8690B3); +} + +void sub_8690B3(uint16 k) { // 0x8690B3 + if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) + enemy_projectile_id[k >> 1] = 0; +} + +static void EprojInit_CrocomireSpikeWallPieces(uint16 j) { // 0x8690CF + int v1 = j >> 1; + enemy_projectile_y_pos[v1] = word_869105[(uint16)(j - 20) >> 1]; + enemy_projectile_x_pos[v1] = 528; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_E[v1] = 0; + enemy_projectile_F[v1] = 0; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_y_subpos[v1] = 0; + enemy_projectile_y_vel[v1] = -5; + enemy_projectile_F[v1] = -30720; +} + +static const uint16 CrocomireSpikeWallPieces_Tab2[18] = { // 0x869115 + 0, 0, 0xff0, 0xee0, 0xcc0, 0xaa0, 0x880, 0x660, 0x440, 0x220, 0xff0, 0xee0, + 0xcc0, 0xaa0, 0x880, 0x660, 0x440, 0x220, +}; +static const uint16 CrocomireSpikeWallPieces_Tab1[18] = { + 0, 0, 0xff00, 0xee00, 0xcc00, 0xaa00, 0x8800, 0x6600, 0x4400, 0x2200, 0xff00, 0xee00, + 0xcc00, 0xaa00, 0x8800, 0x6600, 0x4400, 0x2200, +}; +static const int8 CrocomireSpikeWallPieces_Tab3[36] = { + 0, 0, 0, 0, 4, 0, 4, 0, 3, 0, 3, 0, + 2, 0, 2, 0, 1, 0, 1, 0, 6, 0, 5, 0, + 4, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1, 0, +}; + +void EprojPreInstr_CrocomireSpikeWallPieces(uint16 k) { + int8 v3; + int8 v6; + int8 v7; + int8 v8; + + int v1 = k >> 1; + uint16 v2 = enemy_projectile_E[v1]; + if (v2 != CrocomireSpikeWallPieces_Tab1[v1]) { + v2 += CrocomireSpikeWallPieces_Tab2[v1]; + if (v2 >= CrocomireSpikeWallPieces_Tab1[v1]) + v2 = CrocomireSpikeWallPieces_Tab1[v1]; + } + enemy_projectile_E[v1] = v2; + v3 = *((uint8 *)enemy_projectile_E + k + 1); + bool v4 = __CFADD__uint8(*((uint8 *)enemy_projectile_x_vel + k), v3); + *((uint8 *)enemy_projectile_x_vel + k) += v3; + uint8 v5 = v4 + *((uint8 *)enemy_projectile_x_vel + k + 1); + if ((int8)(v5 - CrocomireSpikeWallPieces_Tab3[k]) >= 0) + v5 = CrocomireSpikeWallPieces_Tab3[k]; + *((uint8 *)enemy_projectile_x_vel + k + 1) = v5; + v6 = *((uint8 *)enemy_projectile_x_vel + k); + v4 = __CFADD__uint8(*((uint8 *)enemy_projectile_x_subpos + k + 1), v6); + *((uint8 *)enemy_projectile_x_subpos + k + 1) += v6; + v7 = *((uint8 *)enemy_projectile_x_vel + k + 1); + bool v9 = v4; + v4 = __CFADD__uint8(v4, v7); + v8 = v9 + v7; + v4 |= __CFADD__uint8(*((uint8 *)enemy_projectile_x_pos + k), v8); + *((uint8 *)enemy_projectile_x_pos + k) += v8; + *((uint8 *)enemy_projectile_x_pos + k + 1) += v4; + uint16 v10 = enemy_projectile_F[v1]; + enemy_projectile_F[v1] = v10 + 12288; + enemy_projectile_y_vel[v1] += __CFADD__uint16(v10, 12288); + uint16 v11 = enemy_projectile_y_subpos[v1]; + v4 = __CFADD__uint16(enemy_projectile_F[v1], v11); + enemy_projectile_y_subpos[v1] = enemy_projectile_F[v1] + v11; + enemy_projectile_y_pos[v1] += enemy_projectile_y_vel[v1] + v4; + if (enemy_projectile_y_pos[v1] >= 0xA8) { + enemy_projectile_id[v1] = 0; + if ((k & 2) == 0) + QueueSfx2_Max6(0x29); + int v12 = k >> 1; + eproj_spawn_pt = (Point16U) { enemy_projectile_x_pos[v12], enemy_projectile_y_pos[v12] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); + QueueSfx2_Max6(0x25); + } +} + +const uint8 *EprojInstr_9270(uint16 k, const uint8 *epjp) { // 0x869270 + int v1 = k >> 1; + eproj_spawn_pt = (Point16U) { enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyDrops(addr_kEnemyDef_DDBF, k, 0); + return epjp; +} + +static void EprojInit_CrocomireBridgeCrumbling(uint16 j) { // 0x869286 + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = enemy_projectile_init_param_1; + enemy_projectile_y_pos[v1] = 187; + enemy_projectile_y_subpos[v1] = 0; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = (random_number & 0x3F) + 64; + enemy_projectile_gfx_idx[v1] = 1024; +} + +void EprojPreInstr_CrocomireBridgeCrumbling(uint16 k) { // 0x8692BA + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) + enemy_projectile_id[k >> 1] = 0; + else + enemy_projectile_y_vel[k >> 1] = (enemy_projectile_y_vel[k >> 1] + 24) & 0x3FFF; +} + +uint16 MoveEprojWithVelocity(uint16 k) { // 0x8692D6 + int v1 = k >> 1; + uint16 v2 = enemy_projectile_x_vel[v1]; + int carry = *((uint8 *)enemy_projectile_x_subpos + k + 1) + (v2 & 0xff); + *((uint8 *)enemy_projectile_x_subpos + k + 1) = carry; + enemy_projectile_x_pos[v1] += (int8)(v2 >> 8) + (carry >> 8); + return MoveEprojWithVelocityY(k); +} + +uint16 MoveEprojWithVelocityY(uint16 k) { // 0x8692F3 + int v1 = k >> 1; + uint16 v2 = enemy_projectile_y_vel[v1]; + int carry = *((uint8 *)enemy_projectile_y_subpos + k + 1) + (v2 & 0xff); + *((uint8 *)enemy_projectile_y_subpos + k + 1) = carry; + uint16 result = enemy_projectile_y_pos[v1] + (int8)(v2 >> 8) + (carry >> 8); + enemy_projectile_y_pos[v1] = result; + return result; +} + +uint16 MoveEprojWithVelocityX(uint16 k) { // 0x869311 + int v1 = k >> 1; + uint16 v2 = enemy_projectile_x_vel[v1]; + int carry = *((uint8 *)enemy_projectile_x_subpos + k + 1) + (v2 & 0xff); + *((uint8 *)enemy_projectile_x_subpos + k + 1) = carry; + uint16 result = enemy_projectile_x_pos[v1] + (int8)(v2 >> 8) + (carry >> 8); + enemy_projectile_x_pos[v1] = result; + return result; +} + +void SetAreaDependentEprojPropertiesEx(uint16 k, uint16 j) { // 0x86932F + uint16 v2; + uint16 *p = (uint16 *)RomPtr_86(k); + if (area_index == 2) { + v2 = p[1]; + } else if (area_index == 5) { + v2 = p[2]; + } else { + v2 = p[0]; + } + enemy_projectile_properties[j >> 1] = v2; +} + +static const int16 kEprojInit_9634_Xvel[4] = { -0x200, -0x1f0, -0x1bc, -0x16a }; +static const int16 kEprojInit_9634_Yvel[4] = { 0, 0x88, 0xfc, 0x16a }; + +static void EprojInit_9634(uint16 j) { // 0x86934D + int v1 = j >> 1; + enemy_projectile_E[v1] = 0; + enemy_projectile_F[v1] = 0; + enemy_projectile_x_pos[v1] = enemy_data[0].x_pos - 29; + enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - 35; + enemy_projectile_gfx_idx[v1] = 2560; + int v2 = enemy_data[0].parameter_1; + enemy_projectile_x_vel[v1] = kEprojInit_9634_Xvel[v2]; + enemy_projectile_y_vel[v1] = kEprojInit_9634_Yvel[v2]; +} + +void EprojPreInstr_9634(uint16 k) { // 0x869392 + int v1 = k >> 1; + if (enemy_projectile_E[v1] >= 8) { + MoveEprojWithVelocity(k); + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_instr_list_ptr[v1] = addr_off_869574; + ++enemy_projectile_E[v1]; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_gfx_idx[v1] = 2560; + QueueSfx2_Max6(0x2B); + } + } else { + ++enemy_projectile_E[v1]; + } +} + +static void EprojInit_9642_RidleysFireball(uint16 j) { // 0x8693CA + int v1 = j >> 1; + enemy_projectile_F[v1] = enemy_projectile_unk1995; + int16 v2 = enemy_projectile_init_param_1 ? 25 : -25; + enemy_projectile_x_pos[v1] = enemy_data[0].x_pos + v2; + enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - 43; + enemy_projectile_gfx_idx[v1] = 2560; + + Ram7800_Default *v4 = gRam7800_Default(0); + enemy_projectile_x_vel[v1] = v4->var_19; + enemy_projectile_y_vel[v1] = v4->var_1A; + SetAreaDependentEprojPropertiesEx(addr_kRidleysFireball_Tab0, j); +} + +void SetAreaDependentEprojProperties(uint16 j) { // 0x869402 + SetAreaDependentEprojPropertiesEx(addr_kRidleysFireball_Tab0, j); +} + +void EprojPreInstr_9642_RidleysFireball(uint16 k) { // 0x86940E + uint16 v1; + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { + v1 = -27042; + } else { + if (!(EnemyProjectileBlockCollisition_Vertical(k) & 1)) + return; + v1 = -27056; + } + int v2 = k >> 1; + enemy_projectile_id[v2] = 0; + if (!enemy_projectile_F[v2]) { + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v2], enemy_projectile_y_pos[v2] }; + SpawnEnemyProjectileWithRoomGfx(v1, 3); + QueueSfx2_Max6(0x2B); + } +} + +const uint8 *EprojInstr_DisableCollisionsWithSamus(uint16 k, const uint8 *epjp) { // 0x869475 + enemy_projectile_properties[k >> 1] |= 0x2000; + return epjp; +} + +static void EprojInit_9660_FireballExplosion(uint16 j) { // 0x86947F + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 2560; + enemy_projectile_x_pos[v1] = eproj_spawn_pt.x; + enemy_projectile_y_pos[v1] = eproj_spawn_pt.y; + enemy_projectile_E[v1] = enemy_projectile_init_param_1; + enemy_projectile_F[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; +} + +static void EprojInit_Common(uint16 j, uint16 k, uint16 a) { // 0x8694EE + int v3 = j >> 1; + enemy_projectile_F[v3] = a; + int v4 = k >> 1; + enemy_projectile_x_pos[v3] = enemy_projectile_x_pos[v4]; + enemy_projectile_y_pos[v3] = enemy_projectile_y_pos[v4]; + enemy_projectile_E[v3] = enemy_projectile_E[v4]; + enemy_projectile_gfx_idx[v3] = 2560; + SetAreaDependentEprojProperties(j); +} + +static void EprojInit_9688(uint16 j) { // 0x8694A0 + uint16 v1 = enemy_projectile_init_param_1; + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = 0; + enemy_projectile_y_vel[v2] = -3584; + EprojInit_Common(j, v1, 0x9688); +} + +static void EprojInit_9696(uint16 j) { // 0x8694B4 + uint16 v1 = enemy_projectile_init_param_1; + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = 0; + enemy_projectile_y_vel[v2] = 3584; + EprojInit_Common(j, v1, 0x9696); +} + +static void EprojInit_966C(uint16 j) { // 0x8694C8 + uint16 v1 = enemy_projectile_init_param_1; + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = 3584; + enemy_projectile_y_vel[v2] = 0; + EprojInit_Common(j, v1, 0x966C); +} + +static void EprojInit_967A(uint16 j) { // 0x8694DC + uint16 v1 = enemy_projectile_init_param_1; + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = -3584; + enemy_projectile_y_vel[v2] = 0; + EprojInit_Common(j, v1, 0x967A); +} + +void EprojPreInstr_966C(uint16 k) { // 0x86950D + MoveEprojWithVelocityX(k); + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + int v1 = k >> 1; + enemy_projectile_instr_list_ptr[v1] = addr_off_869574; + enemy_projectile_instr_timers[v1] = 1; + } +} + +void EprojPreInstr_9688(uint16 k) { // 0x869522 + MoveEprojWithVelocityY(k); + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { + int v1 = k >> 1; + enemy_projectile_instr_list_ptr[v1] = addr_off_869574; + enemy_projectile_instr_timers[v1] = 1; + } +} + +void EprojPreInstr_96A4(uint16 k) { // 0x869537 + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) + enemy_projectile_id[k >> 1] = 0; +} + +void EprojPreInstr_96C0(uint16 k) { // 0x869540 + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) + enemy_projectile_id[k >> 1] = 0; +} + +void EprojPreInstr_96CE(uint16 k) { // 0x869549 + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) + enemy_projectile_id[k >> 1] = 0; +} + +const uint8 *EprojInstr_95BA(uint16 k, const uint8 *epjp) { // 0x8695BA + enemy_projectile_unk1995 = 0; + SpawnEnemyProjectileWithRoomGfx(addr_stru_86966C, k); + enemy_projectile_unk1995 = 0; + SpawnEnemyProjectileWithRoomGfx(addr_stru_86967A, k); + return epjp; +} + +const uint8 *EprojInstr_95ED(uint16 k, const uint8 *epjp) { // 0x8695ED + enemy_projectile_unk1995 = 0; + SpawnEnemyProjectileWithRoomGfx(addr_stru_869688, k); + enemy_projectile_unk1995 = 0; + SpawnEnemyProjectileWithRoomGfx(addr_stru_869696, k); + return epjp; +} + +const uint8 *EprojInstr_9620(uint16 k, const uint8 *epjp) { // 0x869620 + if ((int8)-- * ((uint8 *)enemy_projectile_E + k) >= 0) + SpawnEnemyProjectileWithRoomGfx(enemy_projectile_F[k >> 1], k); + return epjp; +} + +static void EprojInit_9734_CeresFallingDebris(uint16 j) { // 0x8696DC + int v1 = j >> 1; + enemy_projectile_E[v1] = 0; + enemy_projectile_F[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_gfx_idx[v1] = 3584; + enemy_projectile_x_pos[v1] = enemy_projectile_init_param_1; + enemy_projectile_y_pos[v1] = 42; + enemy_projectile_y_vel[v1] = 16; +} + +void EprojPreInstr_9734_CeresFallingDebris(uint16 k) { // 0x869701 + int v1 = k >> 1; + enemy_projectile_y_vel[v1] += 16; + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_id[v1] = 0; + eproj_spawn_pt = (Point16U) { enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); + QueueSfx2_Max6(0x6D); + } +} + +const uint8 *EprojInstr_980E(uint16 k, const uint8 *epjp) { // 0x86980E + int v2 = k >> 1; + eproj_spawn_pt = (Point16U) { enemy_projectile_x_pos[v2], enemy_projectile_y_pos[v2] }; + SpawnEnemyDrops(addr_kEnemyDef_E4FF, k, 0); + return epjp; +} + +static const uint8 byte_8698B4[16] = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0xf0, 0xe0, 0xd0, 0xc0, 0xb0, 0xa0, 0x90, 0x80 }; +static const uint8 byte_8698F7[9] = { 0x30, 0x44, 0x58, 0x6c, 0x80, 0x94, 0xa8, 0xbc, 0xd0 }; +static const uint8 byte_869979[8] = { 0, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; + + +static void EprojInit_PhantoonDestroyableFireballs(uint16 j) { // 0x869824 + int8 v1; + + v1 = (uint16)(enemy_projectile_init_param_1 & 0xFF00) >> 8; + switch (v1) { + case 0: { + int v2 = j >> 1; + enemy_projectile_x_subpos[v2] = 0; + enemy_projectile_y_subpos[v2] = 0; + enemy_projectile_x_vel[v2] = 0; + enemy_projectile_y_vel[v2] = 0; + enemy_projectile_x_pos[v2] = enemy_data[0].x_pos; + enemy_projectile_y_pos[v2] = enemy_data[0].y_pos + 32; + enemy_projectile_instr_list_ptr[v2] = addr_off_8697B4; + enemy_projectile_properties[v2] = enemy_projectile_properties[v2] & 0xFFF | 0x2000; + break; + } + case 2: { + int v3 = j >> 1; + enemy_projectile_x_subpos[v3] = 0; + enemy_projectile_y_subpos[v3] = 0; + enemy_projectile_y_vel[v3] = 0; + uint16 v4 = (uint8)enemy_projectile_init_param_1; + if ((int16)((uint8)enemy_projectile_init_param_1 - 8) >= 0) + enemy_projectile_x_vel[v3] = -2; + else + enemy_projectile_x_vel[v3] = 2; + enemy_projectile_E[v3] = byte_8698B4[v4]; + enemy_projectile_x_pos[v3] = enemy_data[0].x_pos; + enemy_projectile_y_pos[v3] = enemy_data[0].y_pos + 32; + enemy_projectile_pre_instr[v3] = FUNC16(EprojPreInstr_PhantoonDestroyableFireballs); + break; + } + case 4: { + int v5 = j >> 1; + enemy_projectile_x_subpos[v5] = 0; + enemy_projectile_y_subpos[v5] = 0; + enemy_projectile_y_vel[v5] = 0; + enemy_projectile_x_vel[v5] = (enemy_projectile_init_param_1 & 0xF0) >> 1; + enemy_projectile_x_pos[v5] = byte_8698F7[enemy_projectile_init_param_1 & 0xF]; + enemy_projectile_y_pos[v5] = 40; + enemy_projectile_pre_instr[v5] = FUNC16(EprojPreInstr_PhantoonDestroyableFireballs_2); + break; + } + case 6: { + int v7 = j >> 1; + enemy_projectile_x_subpos[v7] = 0; + enemy_projectile_y_subpos[v7] = 0; + enemy_projectile_y_vel[v7] = 0; + enemy_projectile_x_vel[v7] = 128; + enemy_projectile_E[v7] = byte_869979[(uint8)enemy_projectile_init_param_1]; + enemy_projectile_x_pos[v7] = enemy_data[0].x_pos; + enemy_projectile_y_pos[v7] = enemy_data[0].y_pos + 16; + enemy_projectile_pre_instr[v7] = FUNC16(EprojPreInstr_PhantoonDestroyableFireballs_3); + break; + } + default: + Unreachable(); + } +} + +static void EprojInit_PhantoonStartingFireballs(uint16 j) { // 0x86993A + int v1 = j >> 1; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_y_subpos[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + uint16 v2 = byte_869979[enemy_projectile_init_param_1]; + enemy_projectile_E[v1] = v2; + Point16U pt = Eproj_PhantomFireballs_Func1(v2, 0x30); + enemy_projectile_x_pos[v1] = pt.x + enemy_data[0].x_pos; + enemy_projectile_y_pos[v1] = pt.y + enemy_data[0].y_pos + 16; +} + +void EprojPreInstr_PhantoonStartingFireballs(uint16 k) { // 0x869981 + int v1 = k >> 1; + enemy_projectile_y_vel[v1] += 16; + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_properties[v1] = enemy_projectile_properties[v1] & 0xFFF | 0x8000; + enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_PhantoonStartingFireballs2); + enemy_projectile_instr_list_ptr[v1] = addr_word_86976C; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_E[v1] = 8; + enemy_projectile_y_pos[v1] += 8; + } +} + +void EprojPreInstr_PhantoonStartingFireballs2(uint16 k) { // 0x8699BF + int v1 = k >> 1; + bool v2 = enemy_projectile_E[v1] == 1; + bool v3 = (--enemy_projectile_E[v1] & 0x8000) != 0; + if (v2 || v3) { + enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_PhantoonStartingFireballs3); + enemy_projectile_instr_list_ptr[v1] = addr_word_869772; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_y_pos[v1] -= 8; + enemy_projectile_y_vel[v1] = -768; + enemy_projectile_E[v1] = 0; + if ((nmi_frame_counter_word & 1) != 0) + enemy_projectile_x_vel[v1] = -128; + else + enemy_projectile_x_vel[v1] = 128; + } +} + +static const uint16 word_869A3E[3] = { 0xfd00, 0xfe00, 0xff00 }; + +void EprojPreInstr_PhantoonStartingFireballs3(uint16 k) { // 0x869A01 + int v1 = k >> 1; + enemy_projectile_y_vel[v1] += 16; + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + uint16 v2 = enemy_projectile_E[v1] + 1; + enemy_projectile_E[v1] = v2; + if (sign16(v2 - 3)) { + enemy_projectile_y_vel[v1] = word_869A3E[v2]; + return; + } + goto LABEL_6; + } + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { +LABEL_6: + enemy_projectile_instr_list_ptr[v1] = addr_word_869782; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_pre_instr[v1] = FUNC16(nullsub_86); + } +} + +void EprojPreInstr_PhantoonDestroyableFireballs(uint16 k) { // 0x869A45 + int16 v4; + uint16 v5; + int v1 = k >> 1; + enemy_projectile_y_vel[v1] += 4; + uint16 v2 = (uint8)(LOBYTE(enemy_projectile_x_vel[v1]) + enemy_projectile_E[v1]); + enemy_projectile_E[v1] = v2; + Point16U pt = Eproj_PhantomFireballs_Func1(v2, enemy_projectile_y_vel[v1]); + bool v3 = (int16)(pt.x + enemy_data[0].x_pos) < 0; + v4 = pt.x + enemy_data[0].x_pos; + enemy_projectile_x_pos[v1] = pt.x + enemy_data[0].x_pos; + if (v3 + || !sign16(v4 - 256) + || (v3 = (int16)(pt.y + enemy_data[0].y_pos + 16) < 0, + v5 = pt.y + enemy_data[0].y_pos + 16, + enemy_projectile_y_pos[v1] = v5, + v3) + || !sign16(v5 - 256)) { + enemy_projectile_instr_list_ptr[v1] = addr_off_8697F8; + enemy_projectile_instr_timers[v1] = 1; + } +} + +void EprojPreInstr_PhantoonDestroyableFireballs_2(uint16 k) { // 0x869A94 + int v1 = k >> 1; + if (!enemy_projectile_x_vel[v1]) + goto LABEL_5; + bool v2, v3; + v2 = enemy_projectile_x_vel[v1] == 1; + v3 = (--enemy_projectile_x_vel[v1] & 0x8000) != 0; + if (v2 || v3) { + QueueSfx3_Max6(0x1D); +LABEL_5: + enemy_projectile_y_vel[v1] += 16; + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_instr_list_ptr[v1] = addr_word_8697AC; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_y_pos[v1] += 8; + enemy_projectile_pre_instr[v1] = FUNC16(nullsub_86); + QueueSfx3_Max6(0x1D); + } + } +} + +void EprojPreInstr_PhantoonDestroyableFireballs_3(uint16 k) { // 0x869ADA + int16 v4; + uint16 v5; + int v1 = k >> 1; + enemy_projectile_y_vel[v1] += 2; + uint16 v2 = (uint8)(enemy_projectile_E[v1] + 2); + enemy_projectile_E[v1] = v2; + Point16U pt = Eproj_PhantomFireballs_Func1(v2, enemy_projectile_y_vel[v1]); + bool v3 = (int16)(pt.x + enemy_data[0].x_pos) < 0; + v4 = pt.x + enemy_data[0].x_pos; + enemy_projectile_x_pos[v1] = pt.x + enemy_data[0].x_pos; + if (v3 + || !sign16(v4 - 256) + || (v3 = (int16)(pt.y + enemy_data[0].y_pos + 16) < 0, + v5 = pt.y + enemy_data[0].y_pos + 16, + enemy_projectile_y_pos[v1] = v5, + v3) + || !sign16(v5 - 256)) { + enemy_projectile_instr_list_ptr[v1] = addr_off_8697F8; + enemy_projectile_instr_timers[v1] = 1; + } +} + +void EprojPreInstr_PhantoonStartingFireballsB(uint16 k) { // 0x869B29 + if (enemy_data[0].ai_var_B) { + int v1 = k >> 1; + enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_PhantoonStartingFireballsB_2); + enemy_projectile_x_vel[v1] = 180; + enemy_projectile_y_vel[v1] = 48; + } +} + +void EprojPreInstr_PhantoonStartingFireballsB_2(uint16 k) { // 0x869B41 + int v1 = k >> 1; + uint16 v2 = enemy_projectile_x_vel[v1]; + if (v2) { + enemy_projectile_x_vel[v1] = v2 - 1; +LABEL_5:; + uint8 v4 = enemy_projectile_E[v1] + 1; + enemy_projectile_E[v1] = v4; + Point16U pt = Eproj_PhantomFireballs_Func1(v4, enemy_projectile_y_vel[v1]); + enemy_projectile_x_pos[v1] = pt.x + enemy_data[0].x_pos; + enemy_projectile_y_pos[v1] = pt.y + enemy_data[0].y_pos + 16; + return; + } + if ((nmi_frame_counter_word & 1) == 0) + goto LABEL_5; + uint16 v3 = enemy_projectile_y_vel[v1] - 1; + enemy_projectile_y_vel[v1] = v3; + if (v3) + goto LABEL_5; + enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; + enemy_projectile_y_pos[v1] = enemy_data[0].y_pos + 16; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_instr_list_ptr[v1] = addr_off_8697F8; +} + +Point16U Eproj_PhantomFireballs_Func1(uint16 j, uint16 a) { // 0x869BA2 + int16 v3; + uint16 v2, v4; + + uint16 r24 = a; + uint16 r26 = j; + if (sign16(j - 128)) + v2 = Eproj_PhantomFireballs_Func2(2 * j, r24); + else + v2 = -Eproj_PhantomFireballs_Func2(2 * (uint8)(j + 0x80), r24); + uint16 r20 = v2; + v3 = (uint8)(r26 - 64); + if (sign16(v3 - 128)) + v4 = Eproj_PhantomFireballs_Func2(2 * v3, r24); + else + v4 = -Eproj_PhantomFireballs_Func2(2 * (uint8)(v3 + 0x80), r24); + uint16 r22 = v4; + return (Point16U) { r20, r22 }; +} + + +uint16 Eproj_PhantomFireballs_Func2(uint16 k, uint16 r24) { // 0x869BF3 + uint16 r18 = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k), r24) >> 8; + return r18 + Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k + 1), r24); +} + +static void EprojInit_RocksKraidSpits(uint16 j) { // 0x869CA3 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = v1->x_pos + 16; + enemy_projectile_y_pos[v2] = v1->y_pos - 96; + enemy_projectile_y_subpos[v2] = 0; + enemy_projectile_x_subpos[v2] = 0; + enemy_projectile_x_vel[v2] = enemy_projectile_init_param_1; + enemy_projectile_y_vel[v2] = -1024; + enemy_projectile_gfx_idx[v2] = 1536; +} + +static void EprojInit_RocksFallingKraidCeiling(uint16 j) { // 0x869CD8 + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = enemy_projectile_init_param_1; + enemy_projectile_y_pos[v1] = 312; + enemy_projectile_y_subpos[v1] = 0; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = (random_number & 0x3F) + 64; + enemy_projectile_gfx_idx[v1] = 1536; +} + +static void EprojInit_RocksWhenKraidRises(uint16 j) { // 0x869D0C + int16 v1; + + v1 = random_number & 0x3F; + if ((random_number & 1) == 0) + v1 = ~v1; + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = gEnemyData(cur_enemy_index)->x_pos + v1; + enemy_projectile_y_pos[v2] = 432; + enemy_projectile_y_subpos[v2] = 0; + enemy_projectile_x_subpos[v2] = 0; + enemy_projectile_x_vel[v2] = enemy_projectile_init_param_1; + enemy_projectile_y_vel[v2] = -1280; + enemy_projectile_gfx_idx[v2] = 1536; + QueueSfx3_Max6(0x1E); +} + +void EprojPreInstr_KraidRocks(uint16 k) { // 0x869D56 + if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_id[k >> 1] = 0; + } else { + int v1 = k >> 1; + uint16 v2 = enemy_projectile_x_vel[v1] + 8; + enemy_projectile_x_vel[v1] = v2; + if (!sign16(v2 - 256)) + v2 = -256; + enemy_projectile_x_vel[v1] = v2; + enemy_projectile_y_vel[v1] += 64; + } +} + +void EprojPreInstr_RocksFallingKraidCeiling(uint16 k) { // 0x869D89 + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) + enemy_projectile_id[k >> 1] = 0; + else + enemy_projectile_y_vel[k >> 1] = (enemy_projectile_y_vel[k >> 1] + 24) & 0x3FFF; +} + +void sub_869DA5(uint16 k) { // 0x869DA5 + enemy_projectile_gfx_idx[k >> 1] = 0; +} + +static void EprojInit_MiniKraidSpit(uint16 j) { // 0x869DEC + ExtraEnemyRam7800 *v2; + + EnemyData *v1 = gEnemyData(cur_enemy_index); + v2 = gExtraEnemyRam7800(cur_enemy_index); + int v3 = j >> 1; + enemy_projectile_x_pos[v3] = v2->kraid.field_4 + v1->x_pos; + enemy_projectile_y_pos[v3] = v1->y_pos - 16; + enemy_projectile_y_subpos[v3] = 0; + enemy_projectile_x_subpos[v3] = 0; + enemy_projectile_x_vel[v3] = v2->kraid.kraid_next; + enemy_projectile_y_vel[v3] = v2->kraid.field_2; +} + +void EprojPreInit_MiniKraidSpit(uint16 k) { // 0x869E1E + int16 v2; + + if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_id[k >> 1] = 0; + } else { + int v1 = k >> 1; + v2 = enemy_projectile_y_vel[v1] + 64; + if (v2 >= 0 && !sign16(enemy_projectile_y_vel[v1] - 960)) + v2 = 1024; + enemy_projectile_y_vel[v1] = v2; + } +} + +static const int16 kEprojInit_MiniKraidSpikes_Tab0[3] = { -2, 12, 24 }; + +static void EprojInit_MiniKraidSpikes(uint16 j, uint16 a) { // 0x869E4E + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = a; + uint16 r18 = kEprojInit_MiniKraidSpikes_Tab0[gExtraEnemyRam7800(cur_enemy_index)->kraid.kraid_healths_8ths[0] >> 1]; + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos; + enemy_projectile_y_pos[v2] = r18 + v3->y_pos; + enemy_projectile_y_subpos[v2] = 0; + enemy_projectile_x_subpos[v2] = 0; + enemy_projectile_y_vel[v2] = 0; +} + +static void EprojInit_MiniKraidSpikesLeft(uint16 j) { // 0x869E46 + EprojInit_MiniKraidSpikes(j, -0x200); +} + +static void EprojInit_MiniKraidSpikesRight(uint16 j) { // 0x869E4B + EprojInit_MiniKraidSpikes(j, 0x200); +} + +void EprojPreInstr_MiniKraidSpikes(uint16 k) { // 0x869E83 + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) + enemy_projectile_id[k >> 1] = 0; +} + +static void EprojInit_WalkingLavaSeahorseFireball(uint16 j) { // 0x869EB2 + static const int16 word_869EF9[3] = { -0x100, 0, 0x100 }; + + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos - 12; + enemy_projectile_x_vel[v2] = -1024; + enemy_projectile_x_pos[v2] = v1->x_pos - 16; + if ((v1->ai_var_D & 0x8000) == 0) { + enemy_projectile_x_vel[v2] = 1024; + enemy_projectile_x_pos[v2] = v1->x_pos + 16; + } + enemy_projectile_y_vel[v2] = word_869EF9[enemy_projectile_init_param_1 >> 1]; + enemy_projectile_y_subpos[v2] = 0; + enemy_projectile_x_subpos[v2] = 0; +} + +void EprojPreInstr_WalkingLavaSeahorseFireball(uint16 k) { // 0x869EFF + uint16 v2; + if (EnemyProjectileBlockCollisition_Vertical(k) & 1 || EnemyProjectileBlockCollisition_Horiz(k) & 1) { + enemy_projectile_id[k >> 1] = 0; + } else { + int v1 = k >> 1; + if ((enemy_projectile_x_vel[v1] & 0x8000) == 0) { + v2 = enemy_projectile_x_vel[v1] - 64; + enemy_projectile_x_vel[v1] = v2; + if (sign16(v2 - 512)) + v2 = 512; + } else { + v2 = enemy_projectile_x_vel[v1] + 64; + enemy_projectile_x_vel[v1] = v2; + if (!sign16(v2 + 512)) + v2 = -512; + } + enemy_projectile_x_vel[v1] = v2; + } +} + +static void EprojInit_PirateMotherBrainLaser(uint16 j) { // 0x86A009 + int v2 = j >> 1; + enemy_projectile_instr_list_ptr[v2] = eproj_spawn_r22 ? addr_word_869F7D : addr_word_869F41; + enemy_projectile_pre_instr[v2] = FUNC16(nullsub_87); + enemy_projectile_x_pos[v2] = eproj_spawn_pt.x; + enemy_projectile_y_pos[v2] = eproj_spawn_pt.y; + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_properties[v2] = *((uint16 *)RomPtr_A0(v3->enemy_ptr) + 3) | 0x1000; + enemy_projectile_E[v2] = v3->parameter_1; + QueueSfx2_Max6(0x67); +} + +const uint8 *EprojInstr_SetPreInstrAndRun(uint16 k, const uint8 *epjp) { // 0x86A050 + enemy_projectile_pre_instr[k >> 1] = GET_WORD(epjp); + return epjp; +} + +void EprojPreInstr_PirateMotherBrainLaser_MoveLeft(uint16 k) { // 0x86A05C + int v1 = k >> 1; + enemy_projectile_x_pos[v1] -= 2; + if ((enemy_projectile_E[v1] & 0x8000) == 0) + enemy_projectile_x_pos[v1] -= 2; + if (CheckIfEnemyProjectileIsOffScreen(k)) + enemy_projectile_id[v1] = 0; +} + +void EprojPreInstr_PirateMotherBrainLaser_MoveRight(uint16 k) { // 0x86A07A + int v1 = k >> 1; + enemy_projectile_x_pos[v1] += 2; + if ((enemy_projectile_E[v1] & 0x8000) == 0) + enemy_projectile_x_pos[v1] += 2; + if (CheckIfEnemyProjectileIsOffScreen(k)) + enemy_projectile_id[v1] = 0; +} + +static void EprojInit_PirateClaw(uint16 j) { // 0x86A098 + Rect16U r = eproj_spawn_rect; + int v1 = j >> 1; + enemy_projectile_y_pos[v1] = r.y + r.h; + enemy_projectile_x_pos[v1] = r.x + r.w; + enemy_projectile_instr_list_ptr[v1] = enemy_projectile_init_param_1 ? addr_off_869FE1 : addr_off_869FB9; + enemy_projectile_pre_instr[v1] = FUNC16(nullsub_87); + enemy_projectile_E[v1] = 2048; + enemy_projectile_F[v1] = 1; +} + +void EprojPreInstr_PirateClawThrownLeft(uint16 k) { // 0x86A0D1 + int v1 = k >> 1; + if (enemy_projectile_F[v1]) { + enemy_projectile_x_pos[v1] -= HIBYTE(enemy_projectile_E[v1]); + uint16 v2 = enemy_projectile_E[v1] - 32; + enemy_projectile_E[v1] = v2; + if (!v2) + enemy_projectile_F[v1] = 0; + } else { + enemy_projectile_x_pos[v1] += HIBYTE(enemy_projectile_E[v1]); + enemy_projectile_E[v1] += 32; + } + ++enemy_projectile_y_pos[v1]; + if (CheckIfEnemyProjectileIsOffScreen(k)) + enemy_projectile_id[v1] = 0; +} + +void EprojPreInstr_PirateClawThrownRight(uint16 k) { // 0x86A124 + int v1 = k >> 1; + if (enemy_projectile_F[v1]) { + enemy_projectile_x_pos[v1] += HIBYTE(enemy_projectile_E[v1]); + uint16 v2 = enemy_projectile_E[v1] - 32; + enemy_projectile_E[v1] = v2; + if (!v2) + enemy_projectile_F[v1] = 0; + } else { + enemy_projectile_x_pos[v1] -= HIBYTE(enemy_projectile_E[v1]); + enemy_projectile_E[v1] += 32; + } + ++enemy_projectile_y_pos[v1]; + if (CheckIfEnemyProjectileIsOffScreen(k)) + enemy_projectile_id[v1] = 0; +} + +static const int16 word_86A2D6[6] = { 64, 72, 80, -64, -72, -80 }; + +static void EprojInit_A379(uint16 j) { // 0x86A2A1 + int v1 = j >> 1; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_y_subpos[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + uint16 v2 = enemy_projectile_init_param_1; + int v3 = enemy_projectile_init_param_1 >> 1; + enemy_projectile_x_pos[v1] = word_86A2D6[v3] + samus_x_pos; + enemy_projectile_y_pos[v1] = samus_y_pos + 80; + enemy_projectile_instr_list_ptr[v1] = off_86A2E2[v3]; + enemy_projectile_E[v1] = v2; +} + +static void EprojInit_CeresElevatorPad(uint16 j) { // 0x86A2EE + int v1 = j >> 1; + enemy_projectile_y_pos[v1] = samus_y_pos + 28; + enemy_projectile_E[v1] = 60; + sub_86A301(j); +} + +void sub_86A301(uint16 j) { // 0x86A301 + int v1 = j >> 1; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_y_subpos[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_x_pos[v1] = samus_x_pos; +} + + +static void EprojInit_CeresElevatorPlatform(uint16 j) { // 0x86A31B + enemy_projectile_y_pos[j >> 1] = 97; + sub_86A301(j); +} + + +void EprojPreInstr_CeresElevatorPad(uint16 k) { // 0x86A328 + bool v2; // zf + bool v3; // sf + + int v1 = k >> 1; + if (!enemy_projectile_E[v1] + || (v2 = enemy_projectile_E[v1] == 1, v3 = (int16)(enemy_projectile_E[v1] - 1) < 0, --enemy_projectile_E[v1], v2) + || v3) { + enemy_projectile_y_pos[v1] = samus_y_pos + 28; + if (!sign16(++samus_y_pos - 73)) { + samus_y_pos = 72; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_instr_list_ptr[v1] = addr_off_86A28B; + CallSomeSamusCode(0xE); + } + } +} + +void EprojPreInstr_CeresElevatorPlatform(uint16 k) { // 0x86A364 + if (samus_y_pos == 72) { + int v1 = k >> 1; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_instr_list_ptr[v1] = addr_off_86A28B; + } +} + +void EprojPreInstr_PrePhantomRoom(uint16 j) { // 0x86A3A3 + bg2_y_scroll = 0; +} + +const uint8 *EprojInstr_A3BE(uint16 k, const uint8 *epjp) { // 0x86A3BE + int v1 = k >> 1; + enemy_projectile_x_pos[v1] = enemy_projectile_E[v1]; + enemy_projectile_y_pos[v1] = enemy_projectile_F[v1]; + return epjp; +} + +const uint8 *EprojInstr_GotoWithProbability25(uint16 k, const uint8 *epjp) { // 0x86A456 + if ((NextRandom() & 0xC000) == 0xC000) + return INSTRB_RETURN_ADDR(GET_WORD(epjp)); + else + return epjp + 2; +} + +static void EprojInit_BombTorizoLowHealthDrool(uint16 j) { // 0x86A5D3 + int16 parameter_1; // dx + uint16 v4, v5, v8; + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_instr_list_ptr[v1] = off_86A64D[(uint16)((NextRandom() >> 1) & 0xE) >> 1]; + NextRandom(); + EnemyData *v2 = gEnemyData(cur_enemy_index); + enemy_projectile_y_pos[v1] = v2->y_pos - 5; + parameter_1 = v2->parameter_1; + if ((parameter_1 & 0x4000) != 0) { + v4 = random_number & 0x1FE; + } else { + if (parameter_1 < 0) + v5 = 32; + else + v5 = 224; + v4 = 2 * (v5 + (random_number & 0xF) - 8); + } + int v6 = v4 >> 1; + enemy_projectile_x_vel[v1] = kSinCosTable8bit_Sext[v6 + 64]; + enemy_projectile_y_vel[v1] = kSinCosTable8bit_Sext[v6]; + EnemyData *v7 = gEnemyData(cur_enemy_index); + if ((v7->parameter_1 & 0x8000) != 0) + v8 = v7->x_pos + 8; + else + v8 = v7->x_pos - 8; + enemy_projectile_x_pos[v1] = v8; +} + +static void EprojInit_BombTorizoLowHealthInitialDrool(uint16 j) { // 0x86A65D + int16 v3; + int16 parameter_1; // dx + + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + NextRandom(); + EnemyData *v2 = gEnemyData(cur_enemy_index); + enemy_projectile_y_pos[v1] = v2->y_pos + (random_number & 3) - 5; + enemy_projectile_y_vel[v1] = (random_number & 0x1F) + 48; + NextRandom(); + v3 = random_number & 3; + parameter_1 = v2->parameter_1; + if ((parameter_1 & 0x4000) != 0) { + enemy_projectile_x_pos[v1] = v2->x_pos + v3; + enemy_projectile_x_vel[v1] = 0; + } else { + if (parameter_1 < 0) + enemy_projectile_x_pos[v1] = v2->x_pos + v3 + 8; + else + enemy_projectile_x_pos[v1] = v2->x_pos + v3 - 8; + enemy_projectile_x_vel[v1] = 0; + } +} + +static void EprojInit_A977(uint16 j) { // 0x86A6C7 + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + CalculatePlmBlockCoords(plm_id); + enemy_projectile_x_pos[v1] = 16 * plm_x_block; + enemy_projectile_y_pos[v1] = 16 * plm_y_block - 4; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_y_subpos[v1] = 0; +} + +static const int16 kEprojInit_BombTorizoExplosiveSwipe_Tab0[11] = { -30, -40, -47, -31, -21, -1, -28, -43, -48, -31, -21 }; +static const int16 kEprojInit_BombTorizoExplosiveSwipe_Tab1[11] = { -52, -28, -11, 9, 21, 20, -52, -27, -10, 9, 20 }; +static const int16 kEprojInit_BombTorizoStatueBreaking_Xpos[16] = { 8, 0x18, -8, 8, 0x18, -8, 8, 0x18, 8, -8, 0x18, 8, -8, 0x18, 8, -8 }; +static const int16 kEprojInit_BombTorizoStatueBreaking_Ypos[8] = { -8, -8, 8, 8, 8, 0x18, 0x18, 0x18 }; +static const int16 kEprojInit_BombTorizoStatueBreaking_Yvel[8] = { 256, 256, 256, 256, 256, 256, 256, 256 }; +static const int16 kEprojInit_BombTorizoStatueBreaking_F[8] = { 16, 16, 16, 16, 16, 16, 16, 16 }; +static const int16 kEprojInit_BombTorizoLowHealthExplode_X[6] = { 0, 12, -12, 0, 16, -16 }; +static const int16 kEprojInit_BombTorizoLowHealthExplode_Y[6] = { -8, -8, -8, -20, -20, -20 }; + +static void EprojInit_BombTorizoExplosiveSwipe(uint16 j) { // 0x86A6F6 + EnemyData *v1 = gEnemyData(cur_enemy_index); + if ((v1->parameter_1 & 0x8000) != 0) { + int v4 = enemy_projectile_init_param_1 >> 1; + int v5 = j >> 1; + enemy_projectile_x_pos[v5] = v1->x_pos - kEprojInit_BombTorizoExplosiveSwipe_Tab0[v4]; + enemy_projectile_y_pos[v5] = v1->y_pos + kEprojInit_BombTorizoExplosiveSwipe_Tab1[v4]; + } else { + int v2 = enemy_projectile_init_param_1 >> 1; + int v3 = j >> 1; + enemy_projectile_x_pos[v3] = v1->x_pos + kEprojInit_BombTorizoExplosiveSwipe_Tab0[v2]; + enemy_projectile_y_pos[v3] = v1->y_pos + kEprojInit_BombTorizoExplosiveSwipe_Tab1[v2]; + } +} + +static void EprojInit_BombTorizoStatueBreaking(uint16 j) { // 0x86A764 + int8 v1; + + CalculatePlmBlockCoords(plm_id); + v1 = enemy_projectile_init_param_1; + int v2 = enemy_projectile_init_param_1 >> 1; + int v3 = j >> 1; + enemy_projectile_instr_list_ptr[v3] = kEprojInit_BombTorizoStatueBreaking_InstrList[v2]; + enemy_projectile_x_pos[v3] = kEprojInit_BombTorizoStatueBreaking_Xpos[v2] + 16 * plm_x_block; + int v4 = (v1 & 0xF) >> 1; + enemy_projectile_y_pos[v3] = kEprojInit_BombTorizoStatueBreaking_Ypos[v4] + 16 * plm_y_block; + enemy_projectile_y_vel[v3] = kEprojInit_BombTorizoStatueBreaking_Yvel[v4]; + enemy_projectile_F[v3] = kEprojInit_BombTorizoStatueBreaking_F[v4]; + enemy_projectile_properties[v3] |= 0x1000; +} + +static void EprojInit_BombTorizoLowHealthExplode(uint16 j) { // 0x86A81B + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = v1->x_pos; + enemy_projectile_y_pos[v2] = v1->y_pos; + if ((v1->parameter_1 & 0x8000) == 0) + enemy_projectile_init_param_1 += 2; + enemy_projectile_init_param_1 += 2; + int v3 = enemy_projectile_init_param_1 >> 1; + uint16 v4 = kEprojInit_BombTorizoLowHealthExplode_X[v3] + enemy_projectile_x_pos[v2]; + enemy_projectile_x_pos[v2] = v4; + enemy_projectile_E[v2] = v4; + uint16 v5 = kEprojInit_BombTorizoLowHealthExplode_Y[v3] + enemy_projectile_y_pos[v2]; + enemy_projectile_y_pos[v2] = v5; + enemy_projectile_F[v2] = v5; +} + +static void EprojInit_BombTorizoDeathExplosion(uint16 j) { // 0x86A871 + EnemyData *v1 = gEnemyData(cur_enemy_index); + uint16 x_pos = v1->x_pos; + int v3 = j >> 1; + enemy_projectile_x_pos[v3] = x_pos; + enemy_projectile_E[v3] = x_pos; + uint16 y_pos = v1->y_pos; + enemy_projectile_y_pos[v3] = y_pos; + enemy_projectile_F[v3] = y_pos; +} + +void sub_86A887(uint16 v0) { // 0x86A887 + int16 v2; + int16 v3; + int16 v4; + + if (EnemyProjectileBlockCollisition_Horiz(v0) & 1) { + int v6 = v0 >> 1; + enemy_projectile_instr_list_ptr[v6] = 0xA48A; + enemy_projectile_instr_timers[v6] = 1; + } else { + int v1 = v0 >> 1; + v2 = enemy_projectile_x_vel[v1]; + if (v2 >= 0) { + v4 = v2 - 4; + if (v4 < 0) + v4 = 3; + enemy_projectile_x_vel[v1] = v4; + } else { + v3 = v2 + 4; + if (v3 >= 0) + v3 = 3; + enemy_projectile_x_vel[v1] = v3; + } + uint8 carry = EnemyProjectileBlockCollisition_Vertical(v0); + if ((enemy_projectile_y_vel[v1] & 0x8000) != 0 || !carry) { + uint16 v5 = enemy_projectile_y_vel[v1] + 16; + enemy_projectile_y_vel[v1] = v5; + if ((v5 & 0xF000) == 4096) + enemy_projectile_id[v1] = 0; + } else { + int v7 = v0 >> 1; + enemy_projectile_y_pos[v7] -= 3; + enemy_projectile_instr_list_ptr[v7] = 0xA48E; + enemy_projectile_instr_timers[v7] = 1; + } + } +} + +void EprojPreInstr_A977(uint16 k) { // 0x86A8EF + uint8 carry = EnemyProjectileBlockCollisition_Vertical(k); + int v1 = k >> 1; + if ((enemy_projectile_y_vel[v1] & 0x8000) != 0 || !carry) { + uint16 v2 = enemy_projectile_F[0] + enemy_projectile_y_vel[v1]; + enemy_projectile_y_vel[v1] = v2; + if ((v2 & 0xF000) == 4096) + enemy_projectile_y_vel[v1] = 4096; + } else { + enemy_projectile_pre_instr[v1] = 0xA918; + } +} + +void sub_86A91A(uint16 v0) { // 0x86A91A + int v1 = v0 >> 1; + enemy_projectile_x_vel[v1] = 0; + if ((joypad2_last & 0x100) != 0) + enemy_projectile_x_vel[v1] = 256; + if ((joypad2_last & 0x200) != 0) + enemy_projectile_x_vel[v1] = -256; + EnemyProjectileBlockCollisition_Horiz(v0); + enemy_projectile_y_vel[v1] = 0; + if ((joypad2_last & 0x400) != 0) + enemy_projectile_y_vel[v1] = 256; + if ((joypad2_last & 0x800) != 0) + enemy_projectile_y_vel[v1] = -256; + EnemyProjectileBlockCollisition_Vertical(v0); +} + +static void EprojInit_AB07(uint16 j) { // 0x86AA3D + uint16 v1 = vram_write_queue_tail; + VramWriteEntry *v2 = gVramWriteEntry(vram_write_queue_tail); + v2->size = 64; + v2->src.addr = addr_kEprojInit_AB07_Tile0; + *(uint16 *)&v2->src.bank = 134; + v2->vram_dst = 28160; + v1 += 7; + VramWriteEntry *v3 = gVramWriteEntry(v1); + v3->size = 64; + v3->src.addr = addr_kEprojInit_AB07_Tile1; + *(uint16 *)&v3->src.bank = 134; + v3->vram_dst = 28416; + vram_write_queue_tail = v1 + 7; + int v4 = j >> 1; + enemy_projectile_x_pos[v4] = samus_x_pos; + enemy_projectile_y_pos[v4] = samus_y_pos - 36; +} + +void EprojPreInstr_AB07(uint16 k) { // 0x86AA8C + int v1 = k >> 1; + int32 amt = INT16_SHL8(8 * (samus_x_pos - enemy_projectile_x_pos[v1])); + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], amt); + + amt = INT16_SHL8(8 * (samus_y_pos - 36 - enemy_projectile_y_pos[v1])); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], amt); +} + +const uint8 *EprojInstr_SpawnEnemyDrops(uint16 k, const uint8 *epjp) { // 0x86AB8A + int v2 = k >> 1; + eproj_spawn_pt = (Point16U) { enemy_projectile_x_pos[v2], enemy_projectile_y_pos[v2] }; + SpawnEnemyDrops(area_index ? GET_WORD(epjp + 2) : GET_WORD(epjp), k, 0); + return epjp + 4; +} + +static void Eproj_InitXYVelRandom(uint16 j, uint16 k, Point16U pt) { // 0x86ABAE + const uint16 *v2 = (const uint16 *)RomPtr_86(k); + int v3 = j >> 1; + enemy_projectile_instr_list_ptr[v3] = *v2; + enemy_projectile_x_pos[v3] = v2[1] + pt.x; + enemy_projectile_x_vel[v3] = v2[2] + (uint8)NextRandom() - 128; + enemy_projectile_y_pos[v3] = v2[3] + pt.y; + enemy_projectile_y_vel[v3] = v2[4] + (uint8)NextRandom() - 128; +} + +static void EprojInit_BombTorizosChozoOrbs(uint16 j) { // 0x86ABEB + EnemyData *E = gEnemyData(cur_enemy_index); + uint16 v2 = ((E->parameter_1 & 0x8000) != 0) ? addr_kEprojInit_BombTorizosChozoOrbs_init0 : addr_kEprojInit_BombTorizosChozoOrbs_init1; + Eproj_InitXYVelRandom(j, v2, (Point16U) { E->x_pos, E->y_pos }); +} + +static void EprojInit_GoldenTorizosChozoOrbs(uint16 j) { // 0x86AC7C + EnemyData *E = gEnemyData(cur_enemy_index); + uint16 v2 = ((E->parameter_1 & 0x8000) != 0) ? addr_kEprojInit_GoldenTorizosChozoOrbs_init0 : addr_kEprojInit_GoldenTorizosChozoOrbs_init1; + Eproj_InitXYVelRandom(j, v2, (Point16U) { E->x_pos, E->y_pos }); +} + +void EprojPreInstr_BombTorizosChozoOrbs(uint16 k) { // 0x86ACAD + if (EnemyProjectileBlockCollisition_Horiz(k)) { + int v3 = k >> 1; + enemy_projectile_instr_list_ptr[v3] = addr_off_86AB25; + enemy_projectile_instr_timers[v3] = 1; + } else { + uint8 carry = EnemyProjectileBlockCollisition_Vertical(k); + int v1 = k >> 1; + if ((enemy_projectile_y_vel[v1] & 0x8000) != 0 || !carry) { + uint16 v2 = enemy_projectile_y_vel[v1] + 18; + enemy_projectile_y_vel[v1] = v2; + if ((v2 & 0xF000) == 4096) + enemy_projectile_id[v1] = 0; + } else { + int v4 = k >> 1; + enemy_projectile_y_pos[v4] = (enemy_projectile_y_pos[v4] & 0xFFF0 | 8) - 2; + enemy_projectile_instr_list_ptr[v4] = addr_off_86AB41; + enemy_projectile_instr_timers[v4] = 1; + } + } +} + +void EprojPreInstr_GoldenTorizosChozoOrbs(uint16 k) { // 0x86ACFA + int v1; + int16 v2; + uint16 v3; + uint16 v4; + + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) + enemy_projectile_x_vel[k >> 1] = -enemy_projectile_x_vel[k >> 1]; + if (EnemyProjectileBlockCollisition_Vertical(k) & 1 + && (v1 = k >> 1, (enemy_projectile_y_vel[v1] & 0x8000) == 0) + && ((v2 = enemy_projectile_x_vel[v1], v2 >= 0) ? (v3 = v2 - 64) : (v3 = v2 + 64), + enemy_projectile_x_vel[v1] = v3, + v4 = -(enemy_projectile_y_vel[v1] >> 1), + enemy_projectile_y_vel[v1] = v4, + (v4 & 0xFF80) == 0xFF80)) { + int v5 = k >> 1; + enemy_projectile_y_pos[v5] = (enemy_projectile_y_pos[v5] & 0xFFF0 | 8) - 2; + enemy_projectile_instr_list_ptr[v5] = addr_off_86AB41; + enemy_projectile_instr_timers[v5] = 1; + } else { + enemy_projectile_y_vel[k >> 1] += 24; + } +} + +const uint8 *EprojInstr_GotoDependingOnXDirection(uint16 k, const uint8 *epjp) { // 0x86AD92 + int v2 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_x_vel[v2]); + AddToHiLo(&enemy_projectile_x_pos[v2], &enemy_projectile_x_subpos[v2], amt); + if ((enemy_projectile_x_vel[v2] & 0x8000) == 0) + return INSTRB_RETURN_ADDR(GET_WORD(epjp + 2)); + else + return INSTRB_RETURN_ADDR(GET_WORD(epjp)); +} + +static void EprojInit_TorizoSonicBoom(uint16 j) { // 0x86AE15 + int v1 = ((NextRandom() & 1) != 0) ? -12 : 20; + EnemyData *v2 = gEnemyData(cur_enemy_index); + int v3 = j >> 1; + enemy_projectile_y_pos[v3] = v2->y_pos + v1; + enemy_projectile_y_vel[v3] = 0; + if ((v2->parameter_1 & 0x8000) != 0) { + enemy_projectile_x_pos[v3] = v2->x_pos + 32; + enemy_projectile_x_vel[v3] = 624; + enemy_projectile_instr_list_ptr[v3] = addr_off_86ADD2; + } else { + enemy_projectile_x_pos[v3] = v2->x_pos - 32; + enemy_projectile_x_vel[v3] = -624; + enemy_projectile_instr_list_ptr[v3] = addr_off_86ADBF; + } +} + +void EprojPreInstr_TorizoSonicBoom(uint16 k) { // 0x86AE6C + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { + int v4 = k >> 1; + enemy_projectile_instr_list_ptr[v4] = addr_off_86ADE5; + enemy_projectile_instr_timers[v4] = 1; + enemy_projectile_E[v4] = enemy_projectile_x_pos[v4]; + enemy_projectile_F[v4] = enemy_projectile_y_pos[v4]; + } else { + int v1 = k >> 1; + enemy_projectile_x_vel[v1] += sign16(enemy_projectile_x_vel[v1]) ? -16 : 16; + if ((enemy_projectile_x_vel[v1] & 0xF000) == 4096) + enemy_projectile_id[v1] = 0; + } +} + +static void EprojInit_WreckedShipChozoSpikeFootsteps(uint16 j) { // 0x86AEFC + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = enemy_projectile_init_param_1 + v1->x_pos; + enemy_projectile_y_pos[v2] = v1->y_pos + 28; +} + +const uint8 *EprojInstr_ResetXYpos1(uint16 k, const uint8 *epjp) { // 0x86AF36 + int v2 = k >> 1; + enemy_projectile_x_pos[v2] = enemy_projectile_E[v2]; + enemy_projectile_y_pos[v2] = enemy_projectile_F[v2]; + return epjp; +} + +static void EprojInit_TourianStatueDustClouds(uint16 j) { // 0x86AF43 + int v1 = j >> 1; + enemy_projectile_E[v1] = 128; + enemy_projectile_F[v1] = 188; +} + +static void EprojInit_TourianLandingDustCloudsRightFoot(uint16 j) { // 0x86AF50 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos + 48; + enemy_projectile_x_pos[v2] = v1->x_pos + 24; +} + +const uint8 *EprojInstr_MoveY_Minus4(uint16 k, const uint8 *epjp) { // 0x86AF92 + enemy_projectile_y_pos[k >> 1] -= 4; + return epjp; +} + +static void EprojInit_TorizoLandingDustCloudLeftFoot(uint16 j) { // 0x86AFCD + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos + 48; + enemy_projectile_x_pos[v2] = v1->x_pos - 24; +} + +static void EprojInit_GoldenTorizoEgg(uint16 j) { // 0x86B001 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_F[v2] = (0xe2 & 0x1F) + 64; // bug + enemy_projectile_E[v2] = v1->parameter_1; + uint16 v4 = sign16(v1->parameter_1) ? addr_kEprojInit_GoldenTorizoEgg0 : addr_kEprojInit_GoldenTorizoEgg1; + Eproj_InitXYVelRandom(j, v4, (Point16U) { v1->x_pos, v1->y_pos }); +} + +void EprojPreInstr_GoldenTorizoEgg(uint16 k) { // 0x86B043 + int v1 = k >> 1; + if ((--enemy_projectile_F[v1] & 0x8000) != 0) { + enemy_projectile_instr_list_ptr[v1] += 2; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_x_vel[v1] = ((enemy_projectile_E[v1] & 0x8000) != 0) ? 256 : -256; + } else { + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { + enemy_projectile_x_vel[v1] = -enemy_projectile_x_vel[v1]; + enemy_projectile_E[v1] ^= 0x8000; + } + if (EnemyProjectileBlockCollisition_Vertical(k) & 1 && (enemy_projectile_y_vel[v1] & 0x8000) == 0) { + enemy_projectile_x_vel[v1] += sign16(enemy_projectile_x_vel[v1]) ? 32 : -32; + enemy_projectile_y_vel[v1] = -enemy_projectile_y_vel[v1]; + } + enemy_projectile_y_vel[v1] += 48; + if ((enemy_projectile_y_vel[v1] & 0xF000) == 4096) + enemy_projectile_id[v1] = 0; + } +} + +void sub_86B0B9(uint16 k) { // 0x86B0B9 + int16 v2; + + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { + int v3 = k >> 1; + enemy_projectile_pre_instr[v3] = 0xB0DD; + enemy_projectile_y_vel[v3] = 0; + } else { + int v1 = k >> 1; + if ((enemy_projectile_E[v1] & 0x8000) != 0) + v2 = 48; + else + v2 = -48; + enemy_projectile_x_vel[v1] += v2; + } +} + +void sub_86B0DD(uint16 k) { // 0x86B0DD + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + int v1 = k >> 1; + enemy_projectile_instr_list_ptr[v1] = ((enemy_projectile_E[v1] & 0x8000) != 0) ? addr_off_86B1A8 : addr_off_86B190; + enemy_projectile_instr_timers[v1] = 1; + } else { + enemy_projectile_y_vel[k >> 1] += 48; + } +} + +const uint8 *sub_86B13E(uint16 k, const uint8 *epjp) { // 0x86B13E + return INSTRB_RETURN_ADDR(((enemy_projectile_E[k >> 1] & 0x8000) != 0) ? addr_off_86B166 : addr_off_86B14B); +} + +static const int16 word_86B205[2] = { -0x1e, 0x1e }; + +static void EprojInit_GoldenTorizoSuperMissile(uint16 j) { // 0x86B1CE + int v2 = j >> 1; + enemy_projectile_E[v2] = cur_enemy_index; + EnemyData *v3 = gEnemyData(cur_enemy_index); + int v4 = ((v3->parameter_1 & 0x8000) != 0) ? 1 : 0; + enemy_projectile_x_pos[v2] = v3->x_pos + word_86B205[v4]; + enemy_projectile_y_pos[v2] = v3->y_pos - 52; + enemy_projectile_instr_list_ptr[v2] = off_86B209[v4]; +} + +void EprojPreInstr_GoldenTorizoSuperMissile(uint16 k) { // 0x86B20D + int v1 = k >> 1; + EnemyData *v2 = gEnemyData(enemy_projectile_E[v1]); + int v3 = ((v2->parameter_1 & 0x8000) != 0) ? 32 : -32; + enemy_projectile_x_pos[v1] = v2->x_pos + v3; + enemy_projectile_y_pos[v1] = v2->y_pos - 52; +} + +void EprojPreInstr_B237(uint16 k) { // 0x86B237 + int v1; + uint8 carry; + + if (EnemyProjectileBlockCollisition_Horiz(k) + || (carry = EnemyProjectileBlockCollisition_Vertical(k), v1 = k >> 1, (enemy_projectile_y_vel[v1] & 0x8000) == 0) + && carry) { + int v3 = k >> 1; + enemy_projectile_instr_list_ptr[v3] = addr_off_86B2EF; + enemy_projectile_instr_timers[v3] = 1; + } else { + uint16 v2 = enemy_projectile_y_vel[v1] + 16; + enemy_projectile_y_vel[v1] = v2; + if ((v2 & 0xF000) == 4096) + enemy_projectile_id[v1] = 0; + } +} + +static void sub_86B279(uint16 k, uint16 a) { // 0x86B279 + int v3 = k >> 1; + enemy_projectile_x_vel[v3] = 4 * kSinCosTable8bit_Sext[a + 64]; + enemy_projectile_y_vel[v3] = 4 * kSinCosTable8bit_Sext[a]; +} + +const uint8 *EprojInstr_SetVelTowardsSamus1(uint16 k, const uint8 *epjp) { // 0x86B269 + sub_86B279(k, CalculateAngleOfSamusFromEproj(k) & 0x7F); + return epjp; +} + +const uint8 *EprojInstr_SetVelTowardsSamus2(uint16 k, const uint8 *epjp) { // 0x86B272 + sub_86B279(k, CalculateAngleOfSamusFromEproj(k) | 0x80); + return epjp; +} + +static void EprojInit_GoldenTorizoEyeBeam(uint16 j) { // 0x86B328 + EnemyData *E = gEnemyData(cur_enemy_index); + uint16 v2 = ((E->parameter_1 & 0x8000) != 0) ? addr_stru_86B376 : addr_stru_86B380; + Eproj_InitXYVelRandom(j, v2, (Point16U) { E->x_pos, E->y_pos }); + uint16 v3 = (NextRandom() & 0x1E) - 16 + 192; + if ((E->parameter_1 & 0x8000) == 0) + v3 += 128; + int v4 = v3 >> 1; + int v5 = j >> 1; + enemy_projectile_x_vel[v5] = 8 * kSinCosTable8bit_Sext[v4 + 64]; + enemy_projectile_y_vel[v5] = 8 * kSinCosTable8bit_Sext[v4]; +} + +void EprojPreInstr_GoldenTorizoEyeBeam(uint16 k) { // 0x86B38A + if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { + enemy_projectile_instr_list_ptr[k >> 1] = addr_off_86B3CD; + enemy_projectile_instr_timers[k >> 1] = 1; + return; + } + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + int v1 = k >> 1; + enemy_projectile_y_pos[v1] = (enemy_projectile_y_pos[v1] & 0xFFF0 | 8) - 2; + enemy_projectile_instr_list_ptr[v1] = addr_off_86B3E5; + enemy_projectile_instr_timers[v1] = 1; + return; + } +} + +const uint8 *EprojInstr_GotoIfFunc1(uint16 k, const uint8 *epjp) { // 0x86B3B8 + if ((gExtraEnemyRam7800(enemy_projectile_F[k >> 1])->kraid.kraid_healths_8ths[0] & 0x8000) == 0) + return INSTRB_RETURN_ADDR(GET_WORD(epjp)); + else + return epjp + 2; +} + +const uint8 *EprojInstr_ResetXYpos2(uint16 k, const uint8 *epjp) { // 0x86B436 + int v2 = k >> 1; + enemy_projectile_x_pos[v2] = enemy_projectile_E[v2]; + enemy_projectile_y_pos[v2] = enemy_projectile_F[v2]; + return epjp; +} + +static void EprojInit_TourianEscapeShaftFakeWallExplode(uint16 j) { // 0x86B49D + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = 272; + enemy_projectile_E[v1] = 272; + enemy_projectile_y_pos[v1] = 2184; + enemy_projectile_F[v1] = 2184; +} + +static void EprojInit_LavaSeahorseFireball(uint16 j) { // 0x86B4EF + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_y_pos[v2] = v1->y_pos - 28; + enemy_projectile_y_vel[v2] = -961; + if ((v1->ai_var_A & 0x8000) == 0) { + enemy_projectile_x_pos[v2] = v1->x_pos + 12; + enemy_projectile_x_vel[v2] = 704; + enemy_projectile_instr_list_ptr[v2] = addr_word_86B4CB; + } else { + enemy_projectile_x_pos[v2] = v1->x_pos - 12; + enemy_projectile_x_vel[v2] = -704; + enemy_projectile_instr_list_ptr[v2] = addr_word_86B4BF; + } +} + +void sub_86B535(uint16 k) { // 0x86B535 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); + + int16 v6 = enemy_projectile_y_vel[v1]; + if (v6 >= 0) { + enemy_projectile_y_vel[v1] = v6 + 32; + Eproj_DeleteIfYposOutside(k); + } else { + enemy_projectile_y_vel[v1] = v6 + 32; + if ((int16)(v6 + 32) >= 0) { + enemy_projectile_instr_list_ptr[v1] = (enemy_projectile_x_vel[v1] & 0x8000) == 0 ? + addr_word_86B4E3 : addr_word_86B4D7; + enemy_projectile_instr_timers[v1] = 1; + } + } +} + +void Eproj_DeleteIfYposOutside(uint16 k) { // 0x86B5B9 + int v1 = k >> 1; + if ((int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) >= 288) + enemy_projectile_id[v1] = 0; +} + +static const int16 word_86B65B[20] = { // 0x86B62D + -16, 16, -96, -64, -128, -32, -96, 64, -128, 32, 16, 16, 96, -64, 112, -64, + 128, -64, 144, -64, +}; + +static void EprojInit_EyeDoorProjectile(uint16 j) { + uint16 v1 = plm_id; + int v2 = j >> 1; + enemy_projectile_F[v2] = plm_room_arguments[plm_id >> 1]; + CalculatePlmBlockCoords(v1); + int v3 = enemy_projectile_init_param_1 >> 1; + enemy_projectile_x_pos[v2] = word_86B65B[v3] + 8 * (2 * plm_x_block + 1); + enemy_projectile_y_pos[v2] = word_86B65B[v3 + 1] + 16 * plm_y_block; +} + +static const int16 word_86B6B1[4] = { -64, 512, 64, 512 }; + +static void EprojInit_EyeDoorSweat(uint16 j) { // 0x86B683 + CalculatePlmBlockCoords(plm_id); + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = 8 * (2 * (plm_x_block - 1) + 1); + enemy_projectile_y_pos[v1] = 16 * (plm_y_block + 1); + int v2 = enemy_projectile_init_param_1 >> 1; + enemy_projectile_x_vel[v1] = word_86B6B1[v2]; + enemy_projectile_y_vel[v1] = word_86B6B1[v2 + 1]; +} + +void EprojPreInstr_EyeDoorProjectile(uint16 k) { // 0x86B6B9 + int v3 = k >> 1; + if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) { +LABEL_8:; + enemy_projectile_instr_list_ptr[v3] = addr_off_86B5F3; + enemy_projectile_instr_timers[v3] = 1; + return; + } + int v1 = enemy_projectile_E[k >> 1] >> 1; + enemy_projectile_x_vel[v3] += kSinCosTable8bit_Sext[v1 + 64] >> 4; + enemy_projectile_y_vel[v3] += kSinCosTable8bit_Sext[v1] >> 4; + int t = PrepareBitAccess(enemy_projectile_F[v3]); + if ((bitmask & opened_door_bit_array[t]) != 0) { + goto LABEL_8; + } +} + +void EprojPreInstr_EyeDoorSweat(uint16 k) { // 0x86B714 + EnemyProjectileBlockCollisition_Horiz(k); + uint8 carry = EnemyProjectileBlockCollisition_Vertical(k); + int v1 = k >> 1; + if ((enemy_projectile_y_vel[v1] & 0x8000) != 0 || !carry) { + enemy_projectile_y_vel[v1] += 12; + } else { + enemy_projectile_y_pos[v1] -= 4; + enemy_projectile_instr_list_ptr[v1] = addr_off_86B61D; + enemy_projectile_instr_timers[v1] = 1; + } +} + +const uint8 *EprojInstr_SpawnTourianStatueUnlockingParticle(uint16 k, const uint8 *epjp) { // 0x86B7EA + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueUnlockingParticle, k); + return epjp; +} + +const uint8 *EprojInstr_Earthquake(uint16 k, const uint8 *epjp) { // 0x86B7F5 + earthquake_type = 1; + earthquake_timer |= 0x20; + return epjp; +} + +const uint8 *EprojInstr_SpawnTourianStatueUnlockingParticleTail(uint16 k, const uint8 *epjp) { // 0x86B818 + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueUnlockingParticleTail, k); + return epjp; +} + +const uint8 *EprojInstr_AddToYpos(uint16 k, const uint8 *epjp) { // 0x86B841 + enemy_projectile_y_pos[k >> 1] += GET_WORD(epjp); + return epjp + 2; +} + +static void EprojInit_TourianStatueUnlockingParticleWaterSplash(uint16 j) { // 0x86B87A + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = enemy_projectile_x_pos[enemy_projectile_init_param_1 >> 1]; + enemy_projectile_y_pos[v1] = fx_y_pos - 4; +} + +static const uint16 kEprojInit_TourianStatueEyeGlow_X[4] = { 0x84, 0x7a, 0x9e, 0x68 }; +static const uint16 kEprojInit_TourianStatueEyeGlow_Y[4] = { 0x90, 0x51, 0x80, 0x72 }; +static const uint16 kEprojInit_TourianStatueEyeGlow_Colors[16] = { 0x6bff, 0x33b, 0x216, 0x173, 0x7f5f, 0x7c1f, 0x5816, 0x300c, 0x7f5a, 0x7ec0, 0x6de0, 0x54e0, 0x6bfa, 0x3be0, 0x2680, 0x1580 }; + +static void EprojInit_TourianStatueEyeGlow(uint16 j) { // 0x86B88E + uint16 v1 = enemy_projectile_init_param_1; + int v2 = enemy_projectile_init_param_1 >> 1; + int v3 = j >> 1; + enemy_projectile_x_pos[v3] = kEprojInit_TourianStatueEyeGlow_X[v2]; + enemy_projectile_y_pos[v3] = kEprojInit_TourianStatueEyeGlow_Y[v2]; + uint16 v4 = 4 * v1; + for (int i = 498; i != 506; i += 2) { + palette_buffer[i >> 1] = kEprojInit_TourianStatueEyeGlow_Colors[v4 >> 1]; + v4 += 2; + } +} + +static void EprojInit_TourianStatueUnlockingParticle(uint16 j) { // 0x86B8B5 + int v1 = enemy_projectile_init_param_1 >> 1; + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = enemy_projectile_x_pos[v1]; + enemy_projectile_y_pos[v2] = enemy_projectile_y_pos[v1]; + uint16 v3 = 2 * (uint8)((NextRandom() & 0x3F) - 32); + enemy_projectile_E[v2] = v3; + int v4 = v3 >> 1; + enemy_projectile_x_vel[v2] = kSinCosTable8bit_Sext[v4 + 64]; + enemy_projectile_y_vel[v2] = 4 * kSinCosTable8bit_Sext[v4]; +} + +void EprojIni_TourianStatueUnlockingParticleTail(uint16 v0) { // 0x86B8E8 + int v1 = enemy_projectile_init_param_1 >> 1; + int v2 = v0 >> 1; + enemy_projectile_x_pos[v2] = enemy_projectile_x_pos[v1]; + enemy_projectile_y_pos[v2] = enemy_projectile_y_pos[v1]; +} + +static void EprojInit_TourianStatueSoul(uint16 j) { // 0x86B8F8 + int v1 = enemy_projectile_init_param_1 >> 1; + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = kEprojInit_TourianStatueEyeGlow_X[v1]; + enemy_projectile_y_pos[v2] = kEprojInit_TourianStatueEyeGlow_Y[v1]; + enemy_projectile_y_vel[v2] = -1024; +} + +static void EprojInit_TourianStatueBaseDecoration(uint16 j) { // 0x86B93E + int v1 = j >> 1; + enemy_projectile_E[v1] = 120; + enemy_projectile_x_pos[v1] = 120; + enemy_projectile_F[v1] = 184; + enemy_projectile_y_pos[v1] = 184; +} + +static void EprojInit_TourianStatueRidley(uint16 j) { // 0x86B951 + int v1 = j >> 1; + enemy_projectile_E[v1] = 142; + enemy_projectile_x_pos[v1] = 142; + enemy_projectile_F[v1] = 85; + enemy_projectile_y_pos[v1] = 85; +} + +static void EprojInit_TourianStatuePhantoon(uint16 j) { // 0x86B964 + int v1 = j >> 1; + enemy_projectile_E[v1] = 132; + enemy_projectile_x_pos[v1] = 132; + enemy_projectile_F[v1] = 136; + enemy_projectile_y_pos[v1] = 136; +} + +void EprojPreInstr_TourianStatueUnlockingParticleWaterSplash(uint16 k) { // 0x86B977 + enemy_projectile_y_pos[k >> 1] = fx_y_pos - 4; +} + +void EprojPreInstr_TourianStatueUnlockingParticle(uint16 k) { // 0x86B982 + int v1 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_x_vel[v1]); + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], amt); + uint16 v7 = fx_y_pos - enemy_projectile_y_pos[v1]; + amt = INT16_SHL8(enemy_projectile_y_vel[v1]); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], amt); + if (((v7 ^ (fx_y_pos - enemy_projectile_y_pos[v1])) & 0x8000) != 0) + SpawnEnemyProjectileWithRoomGfx(addr_stru_86BA5C, k); + if ((enemy_projectile_y_pos[v1] & 0xFF00) == 256) { + enemy_projectile_instr_list_ptr[v1] = addr_off_86B79F; + enemy_projectile_instr_timers[v1] = 1; + } else { + enemy_projectile_y_vel[v1] += 16; + } +} + +void EprojPreInstr_TourianStatueSoul(uint16 k) { // 0x86B9FD + int v1 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_y_vel[v1]); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], amt); + if ((enemy_projectile_y_pos[v1] & 0x100) != 0) { + enemy_projectile_instr_list_ptr[v1] = addr_off_86B79F; + enemy_projectile_instr_timers[v1] = 1; + } + enemy_projectile_y_vel[v1] -= 128; +} + + +static void EprojPreInstr_BA42(uint16 k) { // 0x86BA42 + int v1 = k >> 1; + enemy_projectile_x_pos[v1] = enemy_projectile_E[v1]; + enemy_projectile_y_pos[v1] = enemy_projectile_F[v1] + layer1_y_pos - *(uint16 *)&hdma_window_1_left_pos[0].field_0; +} + +void EprojPreInstr_TourianStatueStuff(uint16 k) { // 0x86BA37 + if (!tourian_entrance_statue_animstate) + tourian_entrance_statue_finished |= 0x8000; + EprojPreInstr_BA42(k); +} + +const uint8 *EprojInstr_BB24(uint16 k, const uint8 *epjp) { // 0x86BB24 + enemy_projectile_instr_list_ptr[stru_86BB50.init_code_ptr >> 1] = 0; + return epjp; +} + +void sub_86BB30(uint16 j) { // 0x86BB30 + ExtraEnemyRam8000 *v1 = gExtraEnemyRam8000(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = *(uint16 *)&v1->pad[34]; + enemy_projectile_y_pos[v2] = *(uint16 *)&v1->pad[36]; + enemy_projectile_instr_list_ptr[v2] = off_86BB1E[enemy_projectile_init_param_1]; +} + +static void EprojInit_NuclearWaffleBody(uint16 j) { // 0x86BB92 + EnemyData *v2 = gEnemyData(cur_enemy_index); + int v3 = j >> 1; + enemy_projectile_x_pos[v3] = v2->x_pos; + enemy_projectile_x_subpos[v3] = v2->x_subpos; + enemy_projectile_y_pos[v3] = v2->y_pos; + enemy_projectile_y_subpos[v3] = v2->y_subpos; + ExtraEnemyRam8000 *v4 = gExtraEnemyRam8000(cur_enemy_index); + gExtraEnemyRam7800(cur_enemy_index + *(uint16 *)&v4->pad[20])->kraid.kraid_next = j; + enemy_projectile_flags[v3] = 1; +} + +static void EprojInit_NorfairLavaquakeRocks(uint16 j) { // 0x86BBDB + int v1 = j >> 1; + enemy_projectile_instr_list_ptr[v1] = addr_word_86BBD5; + enemy_projectile_E[v1] = FUNC16(Eproj_NorfairLavaquakeRocks_Func1); + enemy_projectile_y_vel[v1] = enemy_projectile_init_param_1; + enemy_projectile_x_vel[v1] = enemy_projectile_unk1995; + EnemyData *v2 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v1] = v2->x_pos; + enemy_projectile_x_subpos[v1] = v2->x_subpos; + enemy_projectile_y_pos[v1] = v2->y_pos; + enemy_projectile_y_subpos[v1] = v2->y_subpos; +} + +void CallNorfairLavaquakeRocksFunc(uint32 ea, uint16 k) { + switch (ea) { + case fnEproj_NorfairLavaquakeRocks_Func1: Eproj_NorfairLavaquakeRocks_Func1(k); return; + case fnEproj_NorfairLavaquakeRocks_Func2: Eproj_NorfairLavaquakeRocks_Func2(k); return; + default: Unreachable(); + } +} + +uint16 EprojPreInstr_NorfairLavaquakeRocks_Inner2(uint16 k) { // 0x86BD2A + int v1 = k >> 1; + return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 + || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 + || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 + || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; +} + +void EprojPreInstr_NorfairLavaquakeRocks_Inner(uint16 k) { // 0x86BD1E + if (EprojPreInstr_NorfairLavaquakeRocks_Inner2(k)) + enemy_projectile_id[k >> 1] = 0; +} + +void EprojPreInstr_NorfairLavaquakeRocks(uint16 k) { // 0x86BC0F + CallNorfairLavaquakeRocksFunc(enemy_projectile_E[k >> 1] | 0x860000, k); + EprojPreInstr_NorfairLavaquakeRocks_Inner(k); +} + +void Eproj_NorfairLavaquakeRocks_Func1(uint16 k) { // 0x86BC16 + int16 v2; + int16 v3; + + int v1 = k >> 1; + v2 = enemy_projectile_y_vel[v1] - 2; + enemy_projectile_y_vel[v1] = v2; + if (v2 >= 0) { + int n = 2; + do { + v3 = n + enemy_projectile_y_vel[v1] - 1; + if (v3 < 0) + v3 = 0; + int t = (8 * v3 + 4) >> 1; + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], kCommonEnemySpeeds_Quadratic32[t >> 1]); + enemy_projectile_F[v1] = kCommonEnemySpeeds_Quadratic_Copy[t + 1]; // junk + } while (--n); + Eproj_NorfairLavaquakeRocks_Func3(k); + } else { + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_E[v1] = FUNC16(Eproj_NorfairLavaquakeRocks_Func2); + } +} + +void Eproj_NorfairLavaquakeRocks_Func2(uint16 k) { // 0x86BC8F + int v1 = k >> 1; + uint16 v2 = enemy_projectile_y_vel[v1] + 2; + enemy_projectile_y_vel[v1] = v2; + if (!sign16(v2 - 64)) + enemy_projectile_y_vel[v1] = 64; + int n = 2; + do { + int t = (8 * (enemy_projectile_y_vel[v1] - n + 1)) >> 1; + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], kCommonEnemySpeeds_Quadratic32[t >> 1]); + enemy_projectile_F[v1] = kCommonEnemySpeeds_Quadratic_Copy[t + 1]; // junk + } while (--n); + Eproj_NorfairLavaquakeRocks_Func3(k); +} + +void Eproj_NorfairLavaquakeRocks_Func3(uint16 k) { // 0x86BCF4 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); +} + + +static const int16 kEprojInit_ShaktoolAttackMiddleBackCircle_X[8] = { 0, 12, 16, 12, 0, -12, -16, -12 }; +static const int16 kEprojInit_ShaktoolAttackMiddleBackCircle_Y[8] = { -16, -12, 0, 12, 16, 12, 0, -12 }; + +static void EprojInit_BDA2(uint16 j) { // 0x86BDA2 + int v1 = j >> 1; + EnemyData *v2 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v1] = v2->x_pos; + enemy_projectile_y_pos[v1] = v2->y_pos; + uint16 v3 = 2 * LOBYTE(v2->ai_var_D); + int v4 = v3 >> 1; + enemy_projectile_x_vel[v1] = kSinCosTable8bit_Sext[v4 + 64]; + enemy_projectile_y_vel[v1] = kSinCosTable8bit_Sext[v4]; + int v5 = (uint16)(v3 >> 5) >> 1; + enemy_projectile_x_pos[v1] += kEprojInit_ShaktoolAttackMiddleBackCircle_X[v5]; + enemy_projectile_y_pos[v1] += kEprojInit_ShaktoolAttackMiddleBackCircle_Y[v5]; +} + +static void EprojInit_ShaktoolAttackMiddleBackCircle(uint16 j) { // 0x86BD9C + enemy_projectile_E[j >> 1] = enemy_projectile_init_param_1; + EprojInit_BDA2(j); +} + +static void EprojInit_ShaktoolAttackFrontCircle(uint16 v1) { // 0x86BE03 + if (EnemyProjectileBlockCollisition_Horiz(v1) & 1 || EnemyProjectileBlockCollisition_Vertical(v1) & 1) + enemy_projectile_id[v1 >> 1] = 0; +} + +void EprojPreInstr_BE12(uint16 k) { // 0x86BE12 + int v1 = k >> 1; + if (enemy_projectile_id[enemy_projectile_E[v1] >> 1]) { + EnemyProjectileBlockCollisition_Horiz(k); + EnemyProjectileBlockCollisition_Vertical(k); + } else { + enemy_projectile_id[v1] = 0; + } +} + +static const int16 kEprojInit_MotherBrainRoomTurrets_X[12] = { 0x398, 0x348, 0x328, 0x2d8, 0x288, 0x268, 0x218, 0x1c8, 0x1a8, 0x158, 0x108, 0xe8 }; +static const int16 EprojInit_MotherBrainRoomTurrets_Y[12] = { 0x30, 0x40, 0x40, 0x30, 0x40, 0x40, 0x30, 0x40, 0x40, 0x30, 0x40, 0x40 }; + +static void EprojInit_MotherBrainRoomTurrets(uint16 j) { // 0x86BE4F + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 1024; + uint16 v2 = 2 * enemy_projectile_init_param_1; + uint16 v3 = kEproj_MotherBrainRoomTurrets_DirectionIndexes[enemy_projectile_init_param_1] | 0x100; + enemy_projectile_y_subpos[v1] = v3; + enemy_projectile_instr_list_ptr[v1] = kEproj_MotherBrainRoomTurrets_InstrLists[(uint16)(2 + * (uint8)v3) >> 1]; + int v4 = v2 >> 1; + enemy_projectile_x_pos[v1] = kEprojInit_MotherBrainRoomTurrets_X[v4]; + enemy_projectile_y_pos[v1] = EprojInit_MotherBrainRoomTurrets_Y[v4]; + enemy_projectile_x_subpos[v1] = kEproj_MotherBrainRoomTurrets_AllowedRotations[v4]; + Eproj_SetXvelRandom(j); + Eproj_SetYvelRandom(j); +} + +static const int16 kEproj_MotherBrainRoomTurretBullets_X[8] = { -17, -12, 0, 12, 17, 12, 0, -12 }; +static const int16 kEproj_MotherBrainRoomTurretBullets_Y[8] = { -9, 3, 7, 3, -9, -19, -21, -19 }; +static const int16 kEproj_MotherBrainRoomTurretBullets_Xvel[8] = { -704, -498, 0, 498, 704, 498, 0, -498 }; +static const int16 kEproj_MotherBrainRoomTurretBullets_Yvel[8] = { 0, 498, 704, 498, 0, -498, -704, -498 }; + +static void EprojInit_MotherBrainRoomTurretBullets(uint16 j) { // 0x86BF59 + int v1 = j >> 1; + enemy_projectile_F[v1] = 0; + enemy_projectile_gfx_idx[v1] = 1024; + uint16 v2 = 2 * LOBYTE(enemy_projectile_y_subpos[enemy_projectile_init_param_1 >> 1]); + enemy_projectile_E[v1] = v2; + int v3 = v2 >> 1; + Point16U pt = { kEproj_MotherBrainRoomTurretBullets_X[v3], kEproj_MotherBrainRoomTurretBullets_Y[v3] }; + enemy_projectile_x_vel[v1] = kEproj_MotherBrainRoomTurretBullets_Xvel[v3]; + enemy_projectile_y_vel[v1] = kEproj_MotherBrainRoomTurretBullets_Yvel[v3]; + int v4 = enemy_projectile_init_param_1 >> 1; + enemy_projectile_x_pos[v1] = pt.x + enemy_projectile_x_pos[v4]; + enemy_projectile_y_pos[v1] = pt.y + enemy_projectile_y_pos[v4]; +} + +void EprojPreInstr_MotherBrainRoomTurrets(uint16 k) { // 0x86BFDF + if (Eproj_MotherBrainRoomTurretBullets_CheckIfTurretOnScreen(k) & 1) { + if (gRam7800_Default(0)->var_1D) + *(uint16 *)((uint8 *)enemy_projectile_id + k) = 0; + } else if (gRam7800_Default(0)->var_1D) { + *(uint16 *)((uint8 *)enemy_projectile_id + k) = 0; + int v5 = k >> 1; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v5], enemy_projectile_y_pos[v5] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0xC); + } else { + int v1 = k >> 1; + bool v2 = enemy_projectile_x_vel[v1]-- == 1; + if (v2) { + Eproj_SetXvelRandom(k); + Eproj_MotherBrainRoomTurretBullets_Func2(k); + int v3 = k >> 1; + enemy_projectile_instr_list_ptr[v3] = g_off_86C040[LOBYTE(enemy_projectile_y_subpos[v3])]; + enemy_projectile_instr_timers[v3] = 1; + } + int v4 = k >> 1; + v2 = enemy_projectile_y_vel[v4]-- == 1; + if (v2) { + Eproj_SetYvelRandom(k); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainRoomTurretBullets, k); + } + } +} + +void Eproj_MotherBrainRoomTurretBullets_Func2(uint16 v0) { // 0x86C050 + uint8 r20 = (*((uint8 *)enemy_projectile_y_subpos + v0 + 1) + *((uint8 *)enemy_projectile_y_subpos + v0)) & 7; + uint16 r18 = enemy_projectile_x_subpos[v0 >> 1]; + if (RomPtr_86(r18)[r20 & 7]) { + *((uint8 *)enemy_projectile_y_subpos + v0) = r20; + } else { + int8 v1 = -*((uint8 *)enemy_projectile_y_subpos + v0 + 1); + *((uint8 *)enemy_projectile_y_subpos + v0 + 1) = v1; + *((uint8 *)enemy_projectile_y_subpos + v0) += v1; + } +} + +void Eproj_SetXvelRandom(uint16 v0) { // 0x86C08E + uint16 Random = (uint8)NextRandom(); + if (sign16((uint8)Random - 32)) + Random = 32; + enemy_projectile_x_vel[v0 >> 1] = Random; +} + +void Eproj_SetYvelRandom(uint16 v0) { // 0x86C0A1 + uint16 Random = (uint8)NextRandom(); + if (sign16((uint8)Random - 128)) + Random = 128; + enemy_projectile_y_vel[v0 >> 1] = Random; +} + +uint8 Eproj_MotherBrainRoomTurretBullets_CheckIfTurretOnScreen(uint16 k) { // 0x86C0B4 + int16 v2; + int16 v3; + int16 v4; + int16 v5; + + int v1 = k >> 1; + v2 = enemy_projectile_y_pos[v1]; + uint8 result = 1; + if (v2 >= 0) { + v3 = v2 + 16 - layer1_y_pos; + if (v3 >= 0) { + if (sign16(v3 - 256)) { + v4 = enemy_projectile_x_pos[v1]; + if (v4 >= 0) { + v5 = v4 + 4 - layer1_x_pos; + if (v5 >= 0) { + if (sign16(v5 - 264)) + return 0; + } + } + } + } + } + return result; +} + +void EprojPreInstr_MotherBrainRoomTurretBullets(uint16 k) { // 0x86C0E0 + int v1 = k >> 1; + enemy_projectile_properties[v1] ^= 0x8000; + MoveEprojWithVelocity(k); + if (Ridley_Func_103(enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1]) & 1) + enemy_projectile_id[enemy_projectile_index >> 1] = 0; +} + +static const int16 kMotherBrainsBomb_Yaccel[10] = { 7, 0x10, 0x20, 0x40, 0x70, 0xb0, 0xf0, 0x130, 0x170, 0 }; + +void EprojPreInstr_MotherBrainBomb(uint16 k) { // 0x86C4C8 + int16 v2; + + if (MotherBrainBomb_Bomb_CollDetect_DoubleRet(k)) + return; + int v1 = k >> 1; + if (enemy_projectile_F[v1]) { + int v4 = k >> 1; + uint16 v5 = kMotherBrainsBomb_Yaccel[enemy_projectile_F[v4] >> 1]; + if (!v5) { + enemy_projectile_x_vel[v4] = 0; + enemy_projectile_y_vel[v4] = 0; + --enemy_ram7800[1].kraid.kraid_mouth_flags; + enemy_projectile_id[v4] = 0; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v4], enemy_projectile_y_pos[v4] }; + SpawnEnemyProjectileWithRoomGfx(addr_stru_869650, LOBYTE(enemy_projectile_x_subpos[v4])); + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v4], enemy_projectile_y_pos[v4] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3); + QueueSfx3_Max6(0x13); + return; + } + if (MoveMotherBrainBomb(k, v5) & 1) + goto LABEL_5; + } else { + v2 = abs16(enemy_projectile_x_vel[v1]) - 2; + if (v2 < 0) + v2 = 0; + enemy_projectile_x_vel[v1] = sign16(enemy_projectile_x_vel[v1]) ? -v2 : v2; + if (MoveMotherBrainBomb(k, 7) & 1) { +LABEL_5:; + int v3 = k >> 1; + enemy_projectile_F[v3] += 2; + } + } +} + +const uint8 *EprojInstr_SwitchJump(uint16 k, const uint8 *epjp) { // 0x86C173 + return INSTRB_RETURN_ADDR(GET_WORD(epjp + enemy_projectile_E[k >> 1])); +} + +const uint8 *EprojInstr_UserPalette0(uint16 k, const uint8 *epjp) { // 0x86C1B4 + enemy_projectile_gfx_idx[k >> 1] = 0; + return epjp; +} + +static uint8 Eproj_CheckForBombCollisionWithRect(Rect16U rect) { // 0x86C1B8 + if (!bomb_counter) + return 0; + for(int v1 = 10; v1 < 20; v1 += 2) { + int v2 = v1 >> 1; + if ((projectile_type[v2] & 0xF00) == 1280 && !projectile_variables[v2]) { + uint16 x = abs16(projectile_x_pos[v2] - rect.x); + if (x < projectile_x_radius[v2] || (uint16)(x - projectile_x_radius[v2]) < rect.w) { + uint16 y = abs16(projectile_y_pos[v2] - rect.y); + if (y < projectile_y_radius[v2] || (uint16)(y - projectile_y_radius[v2]) < rect.h) + return 1; + } + } + } + return 0; +} + +static uint8 Eproj_CheckForEnemyCollisionWithRect(uint16 k, Rect16U rect) { // 0x86C209 + EnemyData *v1 = gEnemyData(k); + return (abs16(v1->x_pos - rect.x) - v1->x_width) < rect.w && + (abs16(v1->y_pos - rect.y) - v1->y_height) < rect.h; +} + +static uint8 Eproj_CheckForCollisionWithSamus(uint16 v0) { // 0x86C239 + Rect16U rect = Eproj_GetCollDetectRect(v0); + uint16 v1 = abs16(samus_x_pos - rect.x); + bool v2 = v1 < samus_x_radius; + uint16 v3 = v1 - samus_x_radius; + uint8 result = 0; + if (v2 || v3 < rect.w) { + uint16 v4 = abs16(samus_y_pos - rect.y); + v2 = v4 < samus_y_radius; + uint16 v5 = v4 - samus_y_radius; + if (v2 || v5 < rect.h) + return 1; + } + return result; +} + +uint16 Math_MultBySin(uint16 a, uint16 r18) { // 0x86C26C + return Math_MultBySinCos(a, r18); +} + +uint16 Math_MultByCos(uint16 a, uint16 r18) { // 0x86C272 + return Math_MultBySinCos(a, r18 + 64); +} + +uint16 Math_MultBySinCos(uint16 r38, uint16 a) { // 0x86C27A + uint16 r46 = kSinCosTable8bit_Sext[(a & 0xff) + 64]; + uint16 prod = (uint32)r38 * abs16(r46) >> 8; + return sign16(r46) ? -prod : prod; +} + +void Eproj_MotherBrainsBlueRingLasers(uint16 j) { // 0x86C2F3 + int v1 = j >> 1; + enemy_projectile_E[v1] = 8; + enemy_projectile_F[v1] = 0; + enemy_projectile_gfx_idx[v1] = 1024; + uint16 r18 = enemy_projectile_init_param_1; + enemy_projectile_x_vel[v1] = Math_MultBySin(0x450, r18); + enemy_projectile_y_vel[v1] = Math_MultByCos(0x450, r18); + enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 10; + enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; + sub_86C320(j); +} + +void sub_86C320(uint16 k) { // 0x86C320 + int v1 = k >> 1; + enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 10; + enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; +} + +void Eproj_MoveToBlueRingSpawnPosition(uint16 k) { // 0x86C335 + int16 v5; + + int v1 = k >> 1; + if (enemy_projectile_E[v1]) { + --enemy_projectile_E[v1]; + sub_86C320(k); + } else { + MoveEprojWithVelocity(k); + uint8 t = CheckForCollisionWithShitroid_DoubleRet(k); + if (t & 0x80) + return; + if (t) { + ++enemy_ram7800[0].kraid.field_28; + BlueRingContactExplosion(k); + uint16 v3 = enemy_ram7800[1].kraid.kraid_healths_8ths[4]; + gExtraEnemyRam7800(enemy_ram7800[1].kraid.kraid_healths_8ths[4])->kraid.kraid_healths_8ths[0] = 16; + EnemyData *v4 = gEnemyData(v3); + v5 = v4->health - 80; + if (v5 < 0) + v5 = 0; + v4->health = v5; + } else if (Eproj_CheckForCollisionWithSamus(k) & 1) { + BlueRingContactExplosion(k); + Samus_DealDamage(SuitDamageDivision(0x50)); + samus_invincibility_timer = 96; + samus_knockback_timer = 5; + knockback_x_dir = (int16)(samus_x_pos - enemy_projectile_x_pos[k >> 1]) >= 0; + } else if (CheckForBlueRingCollisionWithRoom(k) & 1) { + Eproj_Earthqhake5(k); + } + } +} + +uint8 CheckForCollisionWithShitroid_DoubleRet(uint16 v0) { // 0x86C3A9 + if (!enemy_ram7800[1].kraid.kraid_healths_8ths[4]) + return 0; + if (gEnemyData(enemy_ram7800[1].kraid.kraid_healths_8ths[4])->health) { + Rect16U rect = Eproj_GetCollDetectRect(v0); + return Eproj_CheckForEnemyCollisionWithRect(enemy_ram7800[1].kraid.kraid_healths_8ths[4], rect); + } + enemy_projectile_id[v0 >> 1] = 0; + return 0xff; +} + +uint8 CheckForBlueRingCollisionWithRoom(uint16 k) { // 0x86C3C9 + int16 v2; + int16 v3; + + int v1 = k >> 1; + uint8 result = 1; + if (!sign16(enemy_projectile_y_pos[v1] - 32) && enemy_projectile_y_pos[v1] < 0xD8) { + v2 = enemy_projectile_x_pos[v1]; + if (v2 >= 0) { + v3 = v2 - layer1_x_pos; + if (v3 >= 0) { + if (sign16(v3 - 248)) + return 0; + } + } + } + return result; +} + +Rect16U Eproj_GetCollDetectRect(uint16 k) { // 0x86C3E9 + int v1 = k >> 1; + Rect16U rect = { + enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1], + LOBYTE(enemy_projectile_radius[v1]), HIBYTE(enemy_projectile_radius[v1]) + }; + return rect; +} + +void Eproj_Earthqhake5(uint16 k) { // 0x86C404 + earthquake_timer = 10; + earthquake_type = 5; + BlueRingContactExplosion(k); +} + +void BlueRingContactExplosion(uint16 k) { // 0x86C410 + int v1 = k >> 1; + enemy_projectile_id[v1] = 0; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3); + QueueSfx3_Max6(0x13); + sub_86C42E(k); +} + +void sub_86C42E(uint16 k) { // 0x86C42E + enemy_projectile_gfx_idx[k >> 1] = 0; +} + +static void EprojInit_MotherBrainBomb(uint16 j) { // 0x86C482 + *((uint8 *)enemy_projectile_x_subpos + j) = enemy_projectile_init_param_1; + int v1 = j >> 1; + enemy_projectile_y_vel[v1] = 256; + enemy_projectile_x_vel[v1] = 224; + enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 12; + enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; + enemy_projectile_gfx_idx[v1] = 1024; + enemy_projectile_E[v1] = 112; + enemy_projectile_F[v1] = 0; + ++enemy_ram7800[1].kraid.kraid_mouth_flags; +} + +uint8 MotherBrainBomb_Bomb_CollDetect_DoubleRet(uint16 k) { // 0x86C564 + int v1 = k >> 1; + Rect16U rect = { + enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1], + LOBYTE(enemy_projectile_radius[v1]), HIBYTE(enemy_projectile_radius[v1]) + }; + if (!Eproj_CheckForBombCollisionWithRect(rect)) + return 0; + + --enemy_ram7800[1].kraid.kraid_mouth_flags; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_id[v1] = 0; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyDrops(addr_kEnemyDef_EC3F, k, 0); + return 1; // double return +} + +uint8 MoveMotherBrainBomb(uint16 k, uint16 a) { // 0x86C5C2 + int v2 = k >> 1; + enemy_projectile_y_vel[v2] += a; + MoveEprojWithVelocity(k); + if (!sign16(enemy_projectile_x_pos[v2] - 240)) + enemy_projectile_x_vel[v2] = -enemy_projectile_x_vel[v2]; + if (sign16(enemy_projectile_y_pos[v2] - 208)) + return 0; + enemy_projectile_y_pos[v2] = 208; + enemy_projectile_x_vel[v2] = sign16(enemy_projectile_x_vel[v2]) ? -enemy_projectile_E[v2] : enemy_projectile_E[v2]; + enemy_projectile_y_vel[v2] = -512; + return 1; +} + +void sub_86C605(uint16 j) { // 0x86C605 + int v1 = j >> 1; + enemy_projectile_E[v1] = 0; + enemy_projectile_F[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_y_subpos[v1] = 0; + Enemy_MotherBrain *E = Get_MotherBrain(0); + E->mbn_var_23 = 0; + E->mbn_var_25 = 0; + enemy_projectile_gfx_idx[v1] = 1024; + E->mbn_var_24 = enemy_projectile_x_pos[v1] = E->base.x_pos + 64; + uint16 x = samus_x_pos - E->mbn_var_24; + E->mbn_var_26 = enemy_projectile_y_pos[v1] = E->base.y_pos - 48; + uint16 y = samus_y_pos - E->mbn_var_26; + int r18 = (uint8)-(CalculateAngleFromXY(x, y) + 0x80); + E->mbn_var_29 = r18; + E->mbn_var_27 = Math_MultBySin(0xC00, r18); + E->mbn_var_28 = Math_MultByCos(0xC00, r18); +} + +static void EprojInit_MotherBrainDeathBeemFired(uint16 j) { // 0x86C684 + int v1 = j >> 1; + + Enemy_MotherBrain *E = Get_MotherBrain(0); + enemy_projectile_x_pos[v1] = E->mbn_var_24; + enemy_projectile_x_subpos[v1] = E->mbn_var_23; + enemy_projectile_y_pos[v1] = E->mbn_var_26; + enemy_projectile_y_subpos[v1] = E->mbn_var_25; + enemy_projectile_x_vel[v1] = E->mbn_var_27; + enemy_projectile_y_vel[v1] = E->mbn_var_28; + MoveEprojWithVelocity(j); + E->mbn_var_24 = enemy_projectile_x_pos[v1]; + E->mbn_var_23 = enemy_projectile_x_subpos[v1]; + E->mbn_var_26 = enemy_projectile_y_pos[v1]; + E->mbn_var_25 = enemy_projectile_y_subpos[v1]; + uint16 r18 = (uint8)(LOBYTE(E->mbn_var_29) + NextRandom()); + uint16 rv = NextRandom(); + enemy_projectile_x_vel[v1] = Math_MultBySin(rv & 0x700, r18); + enemy_projectile_y_vel[v1] = Math_MultByCos(random_number & 0x700, r18); + MoveEprojWithVelocity(j); + if (sign16(enemy_projectile_y_pos[v1] - 34) + || !sign16(enemy_projectile_y_pos[v1] - 206) + || sign16(enemy_projectile_x_pos[v1] - 2) + || !sign16(enemy_projectile_x_pos[v1] - 238)) { + enemy_projectile_id[v1] = 0; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x1D); + QueueSfx3_Max6(0x13); + earthquake_timer = 10; + earthquake_type = 5; + } else { + enemy_projectile_E[v1] = (enemy_projectile_E[v1] + 1) & 3; + enemy_projectile_F[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + } +} + +void SpawnMotherBrainDeathBeam(uint16 x) { // 0x86C7FB + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainDeathBeamFired, enemy_projectile_E[x >> 1]); +} + +void EprojPreInstr_MotherBrainRainbowBeam(uint16 k) { // 0x86C814 + int v2 = k >> 1; + enemy_projectile_x_pos[v2] = enemy_data[1].x_pos; + enemy_projectile_y_pos[v2] = enemy_data[1].y_pos; +} + +static void EprojInit_MotherBrainRainbowBeam(uint16 j) { // 0x86C80A + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + EprojPreInstr_MotherBrainRainbowBeam(j); +} + +static const int16 kEprojInit_MotherBrainsDrool[12] = { 6, 0x14, 0xe, 0x12, 8, 0x17, 0xa, 0x13, 0xb, 0x19, 0xc, 0x12 }; + +void EprojPreInstr_C84D(uint16 k) { // 0x86C84D + int v1 = k >> 1; + int v2 = (uint16)(4 * enemy_projectile_E[v1]) >> 1; + enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + kEprojInit_MotherBrainsDrool[v2]; + enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + kEprojInit_MotherBrainsDrool[v2 + 1]; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; +} + +static void EprojInit_MotherBrainsDrool(uint16 j) { // 0x86C843 + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_E[v1] = enemy_projectile_init_param_1; + EprojPreInstr_C84D(j); +} + +static void EprojInit_MotherBrainsDrool_Falling(uint16 k) { // 0x86C886 + int v1 = k >> 1; + enemy_projectile_y_vel[v1] += 12; + if (MoveEprojWithVelocityY(k) >= 0xD7) { + enemy_projectile_y_pos[v1] -= 4; + enemy_projectile_instr_list_ptr[v1] = addr_off_86C8E1; + enemy_projectile_instr_timers[v1] = 1; + } +} + +const uint8 *EprojInstr_Add12ToY(uint16 k, const uint8 *epjp) { // 0x86C8D0 + enemy_projectile_y_pos[k >> 1] += 12; + return epjp; +} + +void EprojPreInit_MotherBrainsDeathExplosion_0(uint16 k) { // 0x86C914 + int v2 = k >> 1; + enemy_projectile_x_pos[v2] = enemy_data[0].x_pos + enemy_projectile_x_vel[v2]; + enemy_projectile_y_pos[v2] = enemy_data[0].y_pos + enemy_projectile_y_vel[v2]; +} + +static void EprojInit_MotherBrainsDeathExplosion(uint16 j) { // 0x86C8F5 + int v1 = j >> 1; + enemy_projectile_instr_list_ptr[v1] = off_86C929[enemy_projectile_init_param_1]; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_x_vel[v1] = eproj_spawn_pt.x; + enemy_projectile_y_vel[v1] = eproj_spawn_pt.y; + EprojPreInit_MotherBrainsDeathExplosion_0(j); +} + +static void EprojInit_MotherBrainsRainbowBeamExplosion(uint16 j) { // 0x86C92F + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_x_vel[v1] = eproj_spawn_pt.x; + enemy_projectile_x_pos[v1] = samus_x_pos + eproj_spawn_pt.x; + enemy_projectile_y_vel[v1] = eproj_spawn_pt.y; + enemy_projectile_y_pos[v1] = samus_y_pos + eproj_spawn_pt.y; +} + +void EprojPreInstr_MotherBrainsRainbowBeamExplosion(uint16 k) { // 0x86C94C + int v1 = k >> 1; + enemy_projectile_x_pos[v1] = samus_x_pos + enemy_projectile_x_vel[v1]; + enemy_projectile_y_pos[v1] = samus_y_pos + enemy_projectile_y_vel[v1]; +} + +static void EprojInit_MotherBrainEscapeDoorParticles(uint16 j) { // 0x86C961 + static const int16 kEprojInit_MotherBrainEscapeDoorParticles_X[16] = { + 0, -0x20, 0, -0x18, 0, -0x10, 0, -8, 0, 0, 0, 8, + 0, 0x10, 0, 0x18, + }; + + static const int16 kEprojInit_MotherBrainEscapeDoorParticles_Xvel[16] = { + 0x500, -0x200, 0x500, -0x100, 0x500, -0x100, 0x500, -0x80, 0x500, -0x80, 0x500, 0x80, + 0x500, -0x100, 0x500, 0x200, + }; + + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + int v2 = (4 * enemy_projectile_init_param_1) >> 1; + enemy_projectile_x_pos[v1] = kEprojInit_MotherBrainEscapeDoorParticles_X[v2] + 16; + enemy_projectile_y_pos[v1] = kEprojInit_MotherBrainEscapeDoorParticles_X[v2 + 1] + 128; + enemy_projectile_x_vel[v1] = kEprojInit_MotherBrainEscapeDoorParticles_Xvel[v2]; + enemy_projectile_y_vel[v1] = kEprojInit_MotherBrainEscapeDoorParticles_Xvel[v2 + 1]; + enemy_projectile_E[v1] = 32; +} + +void EprojPreInstr_MotherBrainsExplodedDoorParticles(uint16 k) { // 0x86C9D2 + int v1 = k >> 1; + int16 v2 = abs16(enemy_projectile_x_vel[v1]) - 16; + if (v2 < 0) + v2 = 0; + enemy_projectile_x_vel[v1] = sign16(enemy_projectile_x_vel[v1]) ? -v2 : v2; + enemy_projectile_y_vel[v1] += 32; + MoveEprojWithVelocity(k); + if ((--enemy_projectile_E[v1] & 0x8000) != 0) { + enemy_projectile_id[v1] = 0; + enemy_projectile_y_pos[v1] -= 4; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); + } +} + +static void EprojInit_MotherBrainPurpleBreathBig(uint16 j) { // 0x86CA6A + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 6; + enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; +} + +static void EprojInit_MotherBrainPurpleBreathSmall(uint16 j) { // 0x86CA83 + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 0; + enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 6; + enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; + enemy_ram7800[1].kraid.kraid_hurt_frame = 1; +} + +const uint8 *EprojInstr_MotherBrainPurpleBreathIsActive(uint16 k, const uint8 *epjp) { // 0x86CAEE + enemy_ram7800[1].kraid.kraid_hurt_frame = 0; + return epjp; +} + +void EprojPreInstr_TimeBombSetJapaneseText(uint16 k) { // 0x86CAFA + int v1 = k >> 1; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_x_pos[v1] = 128; + enemy_projectile_y_pos[v1] = 192; +} + +static void EprojInit_TimeBombSetJapaneseText(uint16 j) { // 0x86CAF6 + enemy_projectile_gfx_idx[j >> 1] = 0; + EprojPreInstr_TimeBombSetJapaneseText(j); +} + +static void EprojInit_MotherBrainTubeFalling(uint16 j) { // 0x86CBC9 + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] = 3584; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + enemy_projectile_x_pos[v1] = eproj_spawn_pt.x; + enemy_projectile_y_pos[v1] = eproj_spawn_pt.y; + enemy_projectile_E[v1] = FUNC16(MotherBrainTubeFallingFunc_GenerateExplosion); +} + +void CallMotherBrainTubeFallingFunc(uint32 ea, uint16 k) { + switch (ea) { + case fnMotherBrainTubeFallingFunc_GenerateExplosion: MotherBrainTubeFallingFunc_GenerateExplosion(k); return; + case fnMotherBrainTubeFallingFunc_Falling: MotherBrainTubeFallingFunc_Falling(k); return; + default: Unreachable(); + } +} + +void EprojPreInstr_MotherBrainTubeFalling(uint16 k) { // 0x86CBE7 + CallMotherBrainTubeFallingFunc(enemy_projectile_E[k >> 1] | 0x860000, k); +} + +void MotherBrainTubeFallingFunc_GenerateExplosion(uint16 k) { // 0x86CBEA + int v1 = k >> 1; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] + 8 }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); + enemy_projectile_E[v1] = FUNC16(MotherBrainTubeFallingFunc_Falling); + MotherBrainTubeFallingFunc_Falling(k); +} + +void MotherBrainTubeFallingFunc_Falling(uint16 k) { // 0x86CC08 + int16 v2; + + int v1 = k >> 1; + enemy_projectile_y_vel[v1] += 6; + v2 = MoveEprojWithVelocityY(k); + if (!sign16(v2 - 208)) { + enemy_projectile_id[v1] = 0; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0xC); + } +} + +static const int16 kEprojInit_MotherBrainGlassShatteringShard_X[3] = { 8, -40, -16 }; +static const int16 kEprojInit_MotherBrainGlassShatteringShard_Y[3] = { 32, 32, 32 }; + +static void EprojInit_MotherBrainGlassShatteringShard(uint16 j) { // 0x86CDC5 + uint16 v1 = (2 * NextRandom()) & 0x1FE; + int v2 = j >> 1; + enemy_projectile_E[v2] = v1; + int v3 = v1 >> 1; + enemy_projectile_x_vel[v2] = kSinCosTable8bit_Sext[v3 + 64]; + enemy_projectile_y_vel[v2] = 4 * kSinCosTable8bit_Sext[v3]; + enemy_projectile_instr_list_ptr[v2] = kEprojInit_MotherBrainGlassShatteringShard_InstrPtrs[(uint16)((v1 >> 4) & 0x1E) >> 1]; + enemy_projectile_gfx_idx[v2] = 1600; + CalculatePlmBlockCoords(plm_id); + int v4 = enemy_projectile_init_param_1 >> 1; + enemy_projectile_x_pos[v2] = kEprojInit_MotherBrainGlassShatteringShard_X[v4] + 16 * plm_x_block; + enemy_projectile_y_pos[v2] = kEprojInit_MotherBrainGlassShatteringShard_Y[v4] + 16 * plm_y_block; + enemy_projectile_x_pos[v2] += (NextRandom() & 0xF) - 8; + enemy_projectile_y_pos[v2] += (NextRandom() & 0xF) - 8; +} + +static void EprojInit_MotherBrainGlassShatteringSparkle(uint16 j) { // 0x86CE6D + int v1 = enemy_projectile_init_param_1 >> 1; + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = enemy_projectile_x_pos[v1] + (NextRandom() & 0x1F) - 16; + enemy_projectile_y_pos[v2] = enemy_projectile_y_pos[v1] + (NextRandom() & 0x1F) - 16; + enemy_projectile_gfx_idx[v2] = 1600; +} + +void EprojPreInstr_MotherBrainGlassShatteringShard(uint16 k) { // 0x86CE9B + int v1 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_x_vel[v1]); + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], amt); + amt = INT16_SHL8(enemy_projectile_y_vel[v1]); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], amt); + uint16 v6 = enemy_projectile_y_subpos[v1]; + if ((enemy_projectile_y_pos[v1] & 0xFF00) != 0) { + enemy_projectile_id[v1] = 0; + } else { + enemy_projectile_y_vel[v1] += 32; + if ((NextRandom() & 0x420) == 0) + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainGlassShatteringSparkle, k); + } +} + +static void EprojInit_KiHunterAcidSpitCommon(uint16 k, uint16 j) { // 0x86CFBA + int v2 = j >> 1; + enemy_projectile_y_vel[v2] = 0; + enemy_projectile_y_pos[v2] = gEnemyData(k)->y_pos - 16; + enemy_projectile_y_subpos[v2] = 0; + enemy_projectile_x_subpos[v2] = 0; +} + +static void EprojInit_KiHunterAcidSpitLeft(uint16 j) { // 0x86CF90 + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = -768; + enemy_projectile_x_pos[v2] = gEnemyData(cur_enemy_index)->x_pos - 22; + EprojInit_KiHunterAcidSpitCommon(cur_enemy_index, j); +} + +static void EprojInit_KiHunterAcidSpitRight(uint16 j) { // 0x86CFA6 + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = 768; + enemy_projectile_x_pos[v2] = gEnemyData(cur_enemy_index)->x_pos + 22; + EprojInit_KiHunterAcidSpitCommon(cur_enemy_index, j); +} + +void sub_86CFD5(uint16 k) { // 0x86CFD5 + int v1 = k >> 1; + enemy_projectile_pre_instr[v1] = FUNC16(sub_86CFF8); + enemy_projectile_x_pos[v1] -= 19; +} + +void sub_86CFE6(uint16 k) { // 0x86CFE6 + int v1 = k >> 1; + enemy_projectile_pre_instr[v1] = FUNC16(sub_86CFF8); + enemy_projectile_x_pos[v1] += 19; +} + +void sub_86CFF8(uint16 k) { // 0x86CFF8 + int v1 = k >> 1; + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_instr_list_ptr[v1] = addr_off_86CF56; + enemy_projectile_instr_timers[v1] = 1; + } else if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { + enemy_projectile_x_vel[k >> 1] = 0; + } else { + uint16 v2 = enemy_projectile_y_vel[v1] + 16; + enemy_projectile_y_vel[v1] = v2; + if (!sign16(v2 - 512)) + v2 = 512; + enemy_projectile_y_vel[v1] = v2; + } +} + +static void EprojInit_KagosBugs(uint16 j) { // 0x86D088 + int v2 = j >> 1; + enemy_projectile_F[v2] = cur_enemy_index; + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos; + enemy_projectile_y_pos[v2] = v3->y_pos; + uint16 v4 = (random_number & 7) + 1; + enemy_projectile_G[v2] = v4; + enemy_projectile_E[v2] = v4 + 4; + enemy_projectile_pre_instr[v2] = FUNC16(EprojPreInstr_KagosBugs); +} + +void EprojPreInstr_KagosBugs_Func1(uint16 k) { // 0x86D0B3 + int v1 = k >> 1; + uint16 v2 = enemy_projectile_E[v1]; + if (v2) { + uint16 v3 = v2 - 1; + enemy_projectile_E[v1] = v3; + if (!v3) + QueueSfx2_Max6(0x6C); + } +} + +void EprojPreInstr_KagosBugs_Func2(uint16 k) { // 0x86D1E4 + int v1 = k >> 1; + EnemyData *v2 = gEnemyData(enemy_projectile_F[v1]); + uint16 v3 = abs16(v2->x_pos - enemy_projectile_x_pos[v1]); + if (!sign16(v3 - 23)) + enemy_projectile_properties[v1] |= 0x8000; +} + +void EprojPreInstr_KagosBugs(uint16 k) { // 0x86D0CA + EprojPreInstr_KagosBugs_Func1(k); + EprojPreInstr_KagosBugs_Func2(k); + int v1 = k >> 1; + if (enemy_projectile_G[v1]) { + --enemy_projectile_G[v1]; + } else { + enemy_projectile_instr_list_ptr[v1] = addr_word_86D052; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_pre_instr[v1] = FUNC16(nullsub_302); + } +} + +static const uint16 word_86D082 = 0xe0; + +void EprojPreInstr_D0EC(uint16 k) { // 0x86D0EC + EprojPreInstr_KagosBugs_Func1(k); + EprojPreInstr_KagosBugs_Func2(k); + if (EnemyProjectileBlockCollisition_Horiz(k)) { + enemy_projectile_x_vel[k >> 1] = 0; + goto LABEL_6; + } + if (EnemyProjectileBlockCollisition_Vertical(k)) { +LABEL_6: + enemy_projectile_y_vel[k >> 1] = 256; +LABEL_7:; + enemy_projectile_pre_instr[k >> 1] = FUNC16(EprojPreInstr_D128); + enemy_projectile_instr_list_ptr[k >> 1] = addr_word_86D04A; + enemy_projectile_instr_timers[k >> 1] = 1; + return; + } + uint16 v2 = enemy_projectile_y_vel[k >> 1]; + bool v3 = (int16)(word_86D082 + v2) < 0; + enemy_projectile_y_vel[k >> 1] = word_86D082 + v2; + if (!v3) { + goto LABEL_7; + } +} + +void EprojPreInstr_D128(uint16 v0) { // 0x86D128 + EprojPreInstr_KagosBugs_Func1(v0); + EprojPreInstr_KagosBugs_Func2(v0); + if (EnemyProjectileBlockCollisition_Horiz(v0) & 1) { + enemy_projectile_x_vel[v0 >> 1] = 0; + } else if (EnemyProjectileBlockCollisition_Vertical(v0) & 1) { + int v1 = v0 >> 1; + enemy_projectile_pre_instr[v1] = FUNC16(nullsub_302); + enemy_projectile_instr_list_ptr[v1] = addr_word_86D03C; + enemy_projectile_instr_timers[v1] = 1; + } else { + enemy_projectile_y_vel[v0 >> 1] += word_86D082; + } +} + +static const uint16 g_word_86D086 = 0x200; +static const uint16 g_word_86D084 = 0x30; + +const uint8 *EprojInstr_D15C(uint16 k, const uint8 *epjp) { // 0x86D15C + EprojPreInstr_KagosBugs_Func1(k); + EprojPreInstr_KagosBugs_Func2(k); + int v2 = k >> 1; + + uint16 t = (random_number & 0x300) + 2048; + enemy_projectile_y_vel[v2] = -t; + EnemyData *v3 = gEnemyData(enemy_projectile_F[v2]); + uint16 t2 = v3->x_pos - enemy_projectile_x_pos[v2]; + + if ((int16)(abs16(t2) - g_word_86D084) >= 0) + t = sign16(t2) ? -1 : 0; + + uint16 v4 = g_word_86D086; + if (t & 0x100) + v4 = -v4; + enemy_projectile_x_vel[v2] = v4; + enemy_projectile_pre_instr[v2] = FUNC16(EprojPreInstr_D0EC); + return epjp; +} + +const uint8 *EprojInstr_D1B6(uint16 k, const uint8 *epjp) { // 0x86D1B6 + int v1 = k >> 1; + enemy_projectile_G[v1] = (random_number & 0x1F) + 1; + enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_KagosBugs); + return epjp; +} + +const uint8 *EprojInstr_D1C7(uint16 k, const uint8 *epjp) { // 0x86D1C7 + enemy_projectile_gfx_idx[k >> 1] = 0; + return epjp; +} + +const uint8 *EprojInstr_D1CE(uint16 k, const uint8 *epjp) { // 0x86D1CE + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[k >> 1], enemy_projectile_y_pos[k >> 1] }; + SpawnEnemyDrops(addr_kEnemyDef_E7FF, k, 0); + return epjp; +} + +static void EprojInit_MaridiaFloatersSpikes(uint16 j) { // 0x86D23A + int v1 = j >> 1; + enemy_projectile_x_subpos[v1] = 0; + enemy_projectile_y_subpos[v1] = 0; + enemy_projectile_x_vel[v1] = 0; + enemy_projectile_y_vel[v1] = 0; + EnemyData *v2 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v1] = v2->x_pos; + enemy_projectile_y_pos[v1] = v2->y_pos; + enemy_projectile_E[v1] = enemy_projectile_init_param_1; +} + +static const int16 word_86D21A[8] = { 0, 32, 32, 32, 0, -32, -32, -32 }; +static const int16 word_86D22A[8] = { -32, -32, 0, 32, 32, 32, 0, -32 }; + +void EprojPreInstr_MaridiaFloatersSpikes(uint16 k) { // 0x86D263 + int v1 = k >> 1; + enemy_projectile_x_vel[v1] += word_86D21A[enemy_projectile_E[v1]]; + if (EnemyProjectileBlockCollisition_Horiz(k) & 1 + || (enemy_projectile_y_vel[v1] += word_86D22A[enemy_projectile_E[v1]], EnemyProjectileBlockCollisition_Vertical(k) & 1)) { + enemy_projectile_instr_list_ptr[v1] = addr_off_86D218; + enemy_projectile_instr_timers[v1] = 1; + } +} + +static void EprojInit_WreckedShipRobotLaserCommon(uint16 k, uint16 j) { // 0x86D35B + EnemyData *v2 = gEnemyData(k); + int v3 = j >> 1; + enemy_projectile_y_pos[v3] = v2->y_pos - 16; + enemy_projectile_x_pos[v3] = v2->x_pos + (sign16(enemy_projectile_x_vel[v3]) ? -4 : 4); + enemy_projectile_y_subpos[v3] = 0; + enemy_projectile_x_subpos[v3] = 0; + if ((int16)(v2->x_width + v2->x_pos - layer1_x_pos) >= 0 + && (int16)(v2->x_pos - v2->x_width - 257 - layer1_x_pos) < 0 + && (int16)(v2->y_height + v2->y_pos - layer1_y_pos) >= 0 + && (int16)(v2->y_pos - v2->y_height - 224) < 0) { + QueueSfx2_Max6(0x67); + } +} + +static void EprojInit_WreckedShipRobotLaserDown(uint16 j) { // 0x86D30C + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = gEnemyData(cur_enemy_index)->ai_var_A; + enemy_projectile_y_vel[v2] = 128; + enemy_projectile_gfx_idx[v2] = 0; + EprojInit_WreckedShipRobotLaserCommon(cur_enemy_index, j); +} + +static void EprojInit_WreckedShipRobotLaserHorizontal(uint16 j) { // 0x86D32E + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = gEnemyData(cur_enemy_index)->ai_var_A; + enemy_projectile_y_vel[v2] = 0; + EprojInit_WreckedShipRobotLaserCommon(cur_enemy_index, j); +} + +static void EprojInit_WreckedShipRobotLaserUp(uint16 j) { // 0x86D341 + int v2 = j >> 1; + enemy_projectile_x_vel[v2] = gEnemyData(cur_enemy_index)->ai_var_A; + enemy_projectile_y_vel[v2] = -128; + EprojInit_WreckedShipRobotLaserCommon(cur_enemy_index, j); +} + +void EprojPreInstr_WreckedShipRobotLaser(uint16 k) { // 0x86D3BF + int v1 = k >> 1; + enemy_projectile_gfx_idx[v1] = 0; + if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) + enemy_projectile_id[v1] = 0; +} + +const uint8 *EprojInstr_AssignNewN00bTubeShardVelocity(uint16 k, const uint8 *epjp) { // 0x86D5E1 + NextRandom(); + int v2 = k >> 1; + enemy_projectile_x_vel[v2] = *(uint16 *)((uint8 *)&random_number + 1); + enemy_projectile_y_vel[v2] = 192; + return epjp; +} + +const uint8 *EprojInstr_SetN00bTubeShardX(uint16 k, const uint8 *epjp) { // 0x86D5F2 + int v2 = k >> 1; + if (nmi_frame_counter_word & 1) { + enemy_projectile_x_pos[v2] = enemy_projectile_F[v2]; + enemy_projectile_spritemap_ptr[v2] = GET_WORD(epjp); + } else { + enemy_projectile_x_pos[v2] = 128 - enemy_projectile_F[v2] + 128; + enemy_projectile_spritemap_ptr[v2] = GET_WORD(epjp + 2); + } + enemy_projectile_instr_list_ptr[v2] = epjp - RomBankBase(0x86) + 4; + enemy_projectile_instr_timers[v2] = 1; + return 0; +} + +const uint8 *EprojInstr_D62A(uint16 k, const uint8 *epjp) { // 0x86D62A + if (nmi_frame_counter_word & 1) + enemy_projectile_x_pos[k >> 1] = enemy_projectile_F[k >> 1]; + else + enemy_projectile_x_pos[k >> 1] = -4608; + int v2 = k >> 1; + enemy_projectile_spritemap_ptr[v2] = GET_WORD(epjp); + enemy_projectile_instr_list_ptr[v2] = epjp - RomBankBase(0x86) + 2; + enemy_projectile_instr_timers[v2] = 1; + return 0; +} + +const uint8 *EprojInstr_SetXvelRandom(uint16 k, const uint8 *epjp) { // 0x86D69A + NextRandom(); + enemy_projectile_x_vel[k >> 1] = *(uint16 *)((uint8 *)&random_number + 1); + return epjp; +} + +static void EprojInit_N00bTubeCrack(uint16 j) { // 0x86D6A5 + CalculatePlmBlockCoords(plm_id); + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = 16 * plm_x_block + 96; + enemy_projectile_y_pos[v1] = 16 * plm_y_block + 48; +} + +static const int16 kEprojInit_N00bTubeShards_X[10] = { -56, -64, -20, -40, -64, -48, -24, -40, 0, -8 }; +static const int16 kEprojInit_N00bTubeShards_Y[10] = { 8, -12, -26, -24, -32, 28, 16, -8, -24, 16 }; +static const int16 kEprojInit_N00bTubeShards_Xvel[10] = { -384, -384, -160, -288, -288, -320, -96, -352, 0, -64 }; +static const int16 kEprojInit_N00bTubeShards_Yvel[10] = { 320, -256, -416, -288, -288, 448, 576, -96, -288, 384 }; + +static void EprojInit_N00bTubeShards(uint16 j) { // 0x86D6C9 + CalculatePlmBlockCoords(plm_id); + int v1 = enemy_projectile_init_param_1 >> 1; + int v2 = j >> 1; + enemy_projectile_F[v2] = kEprojInit_N00bTubeShards_X[v1] + 16 * plm_x_block + 96; + enemy_projectile_E[v2] = 0; + enemy_projectile_y_pos[v2] = kEprojInit_N00bTubeShards_Y[v1] + 16 * plm_y_block + 48; + enemy_projectile_instr_list_ptr[v2] = kEprojInit_N00bTubeShards_InstrPtrs[v1]; + enemy_projectile_x_vel[v2] = kEprojInit_N00bTubeShards_Xvel[v1]; + enemy_projectile_y_vel[v2] = kEprojInit_N00bTubeShards_Yvel[v1]; +} + +static const uint16 kEprojInit_N00bTubeReleasedAirBubbles_X[6] = { 40, 80, 104, 120, 152, 184 }; +static const uint16 kEprojInit_N00bTubeReleasedAirBubbles_Y[6] = { 80, 72, 84, 32, 64, 84 }; + +static void EprojInit_N00bTubeReleasedAirBubbles(uint16 j) { // 0x86D774 + CalculatePlmBlockCoords(plm_id); + int v1 = enemy_projectile_init_param_1 >> 1; + int v2 = j >> 1; + enemy_projectile_F[v2] = kEprojInit_N00bTubeReleasedAirBubbles_X[v1] + 16 * plm_x_block; + enemy_projectile_E[v2] = 0; + enemy_projectile_y_pos[v2] = kEprojInit_N00bTubeReleasedAirBubbles_Y[v1] + 16 * plm_y_block; + enemy_projectile_y_vel[v2] = -1280; +} + +void sub_86D7BF(uint16 k) { // 0x86D7BF + int v1 = k >> 1; + if (enemy_projectile_x_pos[v1] != 0xEE00) + enemy_projectile_E[v1] = enemy_projectile_x_pos[v1]; + if (nmi_frame_counter_word & 1) + enemy_projectile_x_pos[v1] = -4608; + else + enemy_projectile_x_pos[v1] = enemy_projectile_E[v1]; +} + +void sub_86D7DE(uint16 k) { // 0x86D7DE + int v1 = k >> 1; + int32 amt = INT16_SHL8(192); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], amt); +} + +void EprojPreInstr_N00bTubeShards(uint16 k) { // 0x86D7FD + int v1 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_x_vel[v1]); + AddToHiLo(&enemy_projectile_F[v1], &enemy_projectile_E[v1], amt); + amt = INT16_SHL8(enemy_projectile_y_vel[v1]); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], amt); + Eproj_DeleteIfYposOutside(k); +} + +void sub_86D83D(uint16 k) { // 0x86D83D + int v2 = (enemy_projectile_x_vel[k >> 1] & 0x17E | 0x80) >> 1; + int v6 = enemy_projectile_index >> 1; + int32 amt = INT16_SHL8((int16)kSinCosTable8bit_Sext[v2 + 64] >> 2); + AddToHiLo(&enemy_projectile_F[v6], &enemy_projectile_E[v6], amt); + enemy_projectile_x_vel[v6] += 2; + amt = INT16_SHL8(enemy_projectile_y_vel[v6]); + AddToHiLo(&enemy_projectile_y_pos[v6], &enemy_projectile_y_subpos[v6], amt); + Eproj_DeleteIfYposOutside(enemy_projectile_index); +} + +void sub_86D89F(uint16 k) { // 0x86D89F + uint16 v1 = enemy_projectile_x_vel[k >> 1] & 0x17E | 0x80; + int v2 = v1 >> 1; + int32 amt = INT16_SHL8((int16)kSinCosTable8bit_Sext[v2 + 64]); + int v5 = enemy_projectile_index >> 1; + AddToHiLo(&enemy_projectile_F[v5], &enemy_projectile_E[v5], amt); + enemy_projectile_x_vel[v5] += 4; + sub_86D8DF(enemy_projectile_index); +} + +void sub_86D8DF(uint16 k) { // 0x86D8DF + int v5 = k >> 1; + int32 amt = INT16_SHL8(enemy_projectile_y_vel[v5]); + AddToHiLo(&enemy_projectile_y_pos[v5], &enemy_projectile_y_subpos[v5], amt); + enemy_projectile_x_pos[v5] = enemy_projectile_F[v5]; +} + +void sub_86D992(uint16 v0) { // 0x86D992 + uint16 v1 = enemy_projectile_init_param_1; + int v2 = v0 >> 1; + enemy_projectile_E[v2] = enemy_projectile_init_param_1; + enemy_projectile_instr_list_ptr[v2] = off_86D96A[v1 >> 1]; + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos; + enemy_projectile_x_subpos[v2] = v3->x_subpos; + enemy_projectile_y_pos[v2] = v3->y_pos; + enemy_projectile_y_subpos[v2] = v3->y_subpos; + enemy_projectile_y_vel[v2] = -512; + enemy_projectile_x_vel[v2] = 512; + if (!sign16(enemy_projectile_init_param_1 - 12)) { + enemy_projectile_y_vel[v2] = -384; + enemy_projectile_x_vel[v2] = 384; + } +} + +void EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(uint16 k) { // 0x86D9E6 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(uint16 k) { // 0x86DA10 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(uint16 k) { // 0x86DA3A + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(uint16 k) { // 0x86DA64 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_0_MoveX1(uint16 k) { // 0x86DA8E + EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(k); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_2_MoveX2(uint16 k) { // 0x86DA93 + EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(k); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_1_MoveY1(uint16 k) { // 0x86DA98 + EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(k); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_4_MoveY2(uint16 k) { // 0x86DA9D + EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(k); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_6_MoveX1Y1(uint16 k) { // 0x86DAA2 + EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(k); + EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(k); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_8_MoveX1Y2(uint16 k) { // 0x86DAAA + EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(k); + EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(k); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_7_MoveX2Y1(uint16 k) { // 0x86DAB2 + EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(k); + EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(k); +} + +void EprojPreInstr_SpikeShootingPlantSpikes_9_MoveX2Y2(uint16 k) { // 0x86DABA + EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(k); + EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(k); +} + +static Func_X_V *const kEprojPreInstr_SpikeShootingPlantSpikes[10] = { // 0x86D9DB + EprojPreInstr_SpikeShootingPlantSpikes_0_MoveX1, + EprojPreInstr_SpikeShootingPlantSpikes_1_MoveY1, + EprojPreInstr_SpikeShootingPlantSpikes_2_MoveX2, + EprojPreInstr_SpikeShootingPlantSpikes_0_MoveX1, + EprojPreInstr_SpikeShootingPlantSpikes_4_MoveY2, + EprojPreInstr_SpikeShootingPlantSpikes_2_MoveX2, + EprojPreInstr_SpikeShootingPlantSpikes_6_MoveX1Y1, + EprojPreInstr_SpikeShootingPlantSpikes_7_MoveX2Y1, + EprojPreInstr_SpikeShootingPlantSpikes_8_MoveX1Y2, + EprojPreInstr_SpikeShootingPlantSpikes_9_MoveX2Y2, +}; + +void EprojPreInstrHelper_SpikeShootingPlantSpikes_Func1(uint16 k) { // 0x86DAC2 + if (EprojPreInstrHelper_SpikeShootingPlantSpikes_Func2(k)) + enemy_projectile_id[k >> 1] = 0; +} + +void EprojPreInstr_SpikeShootingPlantSpikes(uint16 k) { + kEprojPreInstr_SpikeShootingPlantSpikes[enemy_projectile_E[k >> 1] >> 1](k); + EprojPreInstrHelper_SpikeShootingPlantSpikes_Func1(k); +} + +uint16 EprojPreInstrHelper_SpikeShootingPlantSpikes_Func2(uint16 k) { // 0x86DACE + int v1 = k >> 1; + return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 + || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 + || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 + || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; +} + +static void EprojInit_DBF2(uint16 j) { // 0x86DB18 + int v2 = j >> 1; + enemy_projectile_instr_list_ptr[v2] = addr_word_86DB0C; + enemy_projectile_E[v2] = FUNC16(EprojPreInstr_DBF2_MoveX1); + if (enemy_projectile_init_param_1) + enemy_projectile_E[v2] = FUNC16(EprojPreInstr_DBF2_MoveX2); + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos; + enemy_projectile_x_subpos[v2] = v3->x_subpos; + enemy_projectile_y_pos[v2] = v3->y_pos + 2; + enemy_projectile_y_subpos[v2] = v3->y_subpos; + enemy_projectile_y_vel[v2] = -256; + enemy_projectile_x_vel[v2] = 256; +} + +void EprojPreInstr_DBF2_Func1(uint16 k) { // 0x86DBB6 + if (EprojPreInstrHelper_DBF2_Func2(k)) + enemy_projectile_id[k >> 1] = 0; +} + +void EprojPreInstr_DBF2(uint16 k) { // 0x86DB5B + CallEprojPreInstr(enemy_projectile_E[k >> 1] | 0x860000, k); + EprojPreInstr_DBF2_Func1(k); +} + +void EprojPreInstr_DBF2_MoveX1(uint16 k) { // 0x86DB62 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); +} + +void EprojPreInstr_DBF2_MoveX2(uint16 k) { // 0x86DB8C + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); +} + +uint16 EprojPreInstrHelper_DBF2_Func2(uint16 k) { // 0x86DBC2 + int v1 = k >> 1; + return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 + || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 + || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 + || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; +} + +const uint8 *EprojInstr_DC5A(uint16 k, const uint8 *epjp) { // 0x86DC5A + enemy_projectile_properties[k >> 1] = 12288; + return epjp; +} + +const uint8 *EprojInstr_SpawnEnemyDrops_0(uint16 k, const uint8 *epjp) { // 0x86DC61 + int v2 = k >> 1; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v2], enemy_projectile_y_pos[v2] }; + SpawnEnemyDrops(addr_kEnemyDef_DF7F, k, 0); + return epjp; +} + +const uint8 *EprojInstr_SpawnSporesEproj(uint16 k, const uint8 *epjp) { // 0x86DC77 + int v2 = k >> 1; + eproj_spawn_pt = (Point16U) { enemy_projectile_x_pos[v2], enemy_projectile_y_pos[v2] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_Spores, 0); + return epjp; +} + +static void EprojInit_Spores(uint16 j) { // 0x86DC8D + int v2 = j >> 1; + enemy_projectile_F[v2] = enemy_projectile_x_pos[v2] = eproj_spawn_pt.x; + enemy_projectile_y_pos[v2] = eproj_spawn_pt.y; + enemy_projectile_gfx_idx[v2] = 512; +} + +static const int16 word_86DCB9[5] = { -64, -56, -48, -40, -32 }; + +static void EprojInit_SporeSpawnStalk(uint16 j) { // 0x86DCA3 + int v1 = j >> 1; + enemy_projectile_y_pos[v1] = enemy_data[0].y_pos + word_86DCB9[enemy_projectile_init_param_1]; + enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; +} + +void sub_86DCC3(uint16 v0) { // 0x86DCC3 + int v1 = v0 >> 1; + enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - 96; + enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; +} + +static const int16 kEprojInit_SporeSpawners_X[4] = { 0x20, 0x60, 0xa0, 0xe0 }; + +static void EprojInit_SporeSpawners(uint16 j) { // 0x86DCD4 + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = kEprojInit_SporeSpawners_X[enemy_projectile_init_param_1]; + enemy_projectile_y_pos[v1] = 520; +} + +void EprojPreInstr_Spores(uint16 k) { // 0x86DCEE + int v1 = k >> 1; + uint16 v2 = LOBYTE(enemy_projectile_E[v1]); + uint16 r18 = SignExtend8(kSporeMovementData[LOBYTE(enemy_projectile_E[v1])]); + if ((enemy_projectile_F[v1] & 0x80) != 0) + r18 = -r18; + enemy_projectile_x_pos[v1] += r18; + r18 = SignExtend8(kSporeMovementData[v2 + 1]); + uint16 v3 = r18 + enemy_projectile_y_pos[v1] + r18; + enemy_projectile_y_pos[v1] = v3; + if (!sign16(v3 - 768)) + enemy_projectile_id[v1] = 0; + enemy_projectile_E[v1] = (uint8)(LOBYTE(enemy_projectile_E[v1]) + 2); +} + +void EprojPreInstr_SporeSpawners(uint16 k) { // 0x86DD46 + if (!kraid_unk9000) { + int v1 = k >> 1; + if (!enemy_projectile_F[v1]) { + enemy_projectile_instr_list_ptr[v1] = addr_word_86DC06; + enemy_projectile_instr_timers[v1] = 1; + enemy_projectile_F[v1] = NextRandom() & 0x1FF; + } + --enemy_projectile_F[v1]; + } +} + +static void EprojInit_NamiFuneFireball(uint16 j) { // 0x86DED6 + int v2 = j >> 1; + enemy_projectile_instr_list_ptr[v2] = addr_word_86DE96; + enemy_projectile_E[v2] = FUNC16(EprojInit_NamiFuneFireball_MoveX1); + if (enemy_projectile_init_param_1) { + enemy_projectile_instr_list_ptr[v2] = addr_word_86DEA6; + enemy_projectile_E[v2] = FUNC16(EprojInit_NamiFuneFireball_MoveX2); + } + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos; + enemy_projectile_x_subpos[v2] = v3->x_subpos; + enemy_projectile_y_pos[v2] = v3->y_pos; + enemy_projectile_y_subpos[v2] = v3->y_subpos; + if ((v3->parameter_1 & 0xF) != 0) + enemy_projectile_y_pos[v2] += 4; + int v4 = (uint16)(4 * LOBYTE(v3->parameter_2)) >> 1; + enemy_projectile_y_vel[v2] = word_86DEB6[v4]; + enemy_projectile_x_vel[v2] = word_86DEB6[v4 + 1]; +} + +static void EprojInit_NamiFuneFireball_MoveX1(uint16 k) { // 0x86DF40 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); +} + +static void EprojInit_NamiFuneFireball_MoveX2(uint16 k) { // 0x86DF6A + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); +} + +void CallNamiFuneFireballFunc(uint32 ea, uint16 k) { + switch (ea) { + case fnEprojInit_NamiFuneFireball_MoveX1: EprojInit_NamiFuneFireball_MoveX1(k); return; + case fnEprojInit_NamiFuneFireball_MoveX2: EprojInit_NamiFuneFireball_MoveX2(k); return; + default: Unreachable(); + } +} + +void EprojPreInstr_NamiFuneFireball(uint16 v0) { // 0x86DF39 + CallNamiFuneFireballFunc(enemy_projectile_E[v0 >> 1] | 0x860000, v0); + Eproj_NamiFuneFireball_After(v0); +} + +void Eproj_NamiFuneFireball_After(uint16 v0) { // 0x86DF94 + if (EprojPreInstrHelper_DBF2_Func2(v0)) + enemy_projectile_id[v0 >> 1] = 0; +} + +uint16 sub_86DFA0(uint16 k) { // 0x86DFA0 + int v1 = k >> 1; + return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 + || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0; +} + +const uint8 *EprojInstr_DFEA(uint16 k, const uint8 *epjp) { // 0x86DFEA + int v1 = k >> 1; + eproj_spawn_pt = (Point16U){ enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1] }; + SpawnEnemyDrops(addr_kEnemyDef_E83F, k, 0); + return epjp; +} + +static void EprojInit_LavaThrownByLavaman(uint16 j) { // 0x86E000 + int v2 = j >> 1; + enemy_projectile_instr_list_ptr[v2] = addr_word_86DFD8; + enemy_projectile_E[v2] = FUNC16(Eproj_LavaThrownByLavaman_MoveX1); + if (enemy_projectile_init_param_1) { + enemy_projectile_instr_list_ptr[v2] = addr_word_86DFDE; + enemy_projectile_E[v2] = FUNC16(Eproj_LavaThrownByLavaman_MoveX2); + } + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos; + enemy_projectile_x_subpos[v2] = v3->x_subpos; + enemy_projectile_y_pos[v2] = v3->y_pos + 2; + enemy_projectile_y_subpos[v2] = v3->y_subpos; + enemy_projectile_y_vel[v2] = -768; + enemy_projectile_x_vel[v2] = 768; +} + +void CallLavamanFunc(uint32 ea, uint16 k) { + switch (ea) { + case fnEproj_LavaThrownByLavaman_MoveX1: Eproj_LavaThrownByLavaman_MoveX1(k); return; + case fnEproj_LavaThrownByLavaman_MoveX2: Eproj_LavaThrownByLavaman_MoveX2(k); return; + default: Unreachable(); + } +} + +void sub_86E049(uint16 v0) { // 0x86E049 + CallLavamanFunc(enemy_projectile_E[v0 >> 1] | 0x860000, v0); + sub_86E0A4(v0); +} + +void Eproj_LavaThrownByLavaman_MoveX1(uint16 k) { // 0x86E050 + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_y_vel[v1])); +} + +void Eproj_LavaThrownByLavaman_MoveX2(uint16 k) { // 0x86E07A + int v1 = k >> 1; + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], INT16_SHL8(enemy_projectile_x_vel[v1])); +} + +void sub_86E0A4(uint16 v0) { // 0x86E0A4 + if (sub_86E0B0(v0)) + enemy_projectile_id[v0 >> 1] = 0; +} + +uint16 sub_86E0B0(uint16 k) { // 0x86E0B0 + int v1 = k >> 1; + return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 + || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 + || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 + || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; +} + + +static void EprojInit_DustCloudOrExplosion(uint16 v0) { // 0x86E468 + int v1 = v0 >> 1; + enemy_projectile_instr_list_ptr[v1] = off_86E42C[enemy_projectile_init_param_1]; + enemy_projectile_x_pos[v1] = eproj_spawn_pt.x; + enemy_projectile_y_pos[v1] = eproj_spawn_pt.y; +} + +static void EprojInit_EyeDoorSmoke(uint16 j) { // 0x86E4A6 + int v1 = j >> 1; + enemy_projectile_instr_list_ptr[v1] = off_86E42C[(uint8)enemy_projectile_init_param_1]; + int v2 = (8 * HIBYTE(enemy_projectile_init_param_1)) >> 1; + uint16 x = word_86E47E[v2 + 2] + (word_86E47E[v2] & random_number); + uint16 y = word_86E47E[v2 + 3] + (word_86E47E[v2 + 1] & (random_number >> 8)); + CalculatePlmBlockCoords(plm_id); + enemy_projectile_x_pos[v1] = x + 8 * (2 * plm_x_block + 1); + enemy_projectile_y_pos[v1] = y + 8 * (2 * plm_y_block + 1); + NextRandom(); +} + +void EprojPreInstr_DustCloudOrExplosion(uint16 k) { // 0x86E4FE + if (CheckIfEnemyProjectileIsOffScreen(k)) + enemy_projectile_id[k >> 1] = 0; +} + +const uint8 *EprojInstr_SetYVel(uint16 k, const uint8 *epjp) { // 0x86E533 + enemy_projectile_y_vel[k >> 1] = GET_WORD(epjp); + return epjp + 2; +} + +static void EprojInit_SpawnedGate_Common(uint16 j, uint16 v1) { // 0x86E5DD + uint16 v2 = plm_id; + CalculatePlmBlockCoords(plm_id); + int v3 = j >> 1; + enemy_projectile_E[v3] = plm_block_indices[v2 >> 1]; + enemy_projectile_x_pos[v3] = 16 * plm_x_block; + enemy_projectile_y_pos[v3] = v1 + 16 * plm_y_block; +} + +static void EprojInit_SpawnedShotGate(uint16 j) { // 0x86E5D0 + EprojInit_SpawnedGate_Common(j, 0); +} + +static void EprojInit_ClosedDownwardsShotGate(uint16 j) { // 0x86E5D5 + EprojInit_SpawnedGate_Common(j, 0x40); +} + +static void EprojInit_ClosedUpwardsShotGate(uint16 j) { // 0x86E5DA + EprojInit_SpawnedGate_Common(j, -0x40); +} + +void EprojPreInstr_E605(uint16 k) { // 0x86E605 + int v1 = k >> 1; + uint16 v2 = enemy_projectile_timers[v1] + abs16(enemy_projectile_y_vel[v1]); + if (v2 >= 0x1000) { + enemy_projectile_instr_timers[v1] = 1; + ++enemy_projectile_instr_list_ptr[v1]; + ++enemy_projectile_instr_list_ptr[v1]; + v2 = 0; + } + enemy_projectile_timers[v1] = v2; + enemy_projectile_y_subpos[v1] += LOBYTE(enemy_projectile_y_vel[v1]) << 8; + enemy_projectile_y_pos[v1] += (int8)HIBYTE(enemy_projectile_y_vel[v1]); +} + +static void EprojInit_SaveStationElectricity(uint16 j) { // 0x86E6AD + CalculatePlmBlockCoords(plm_id); + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = 16 * (plm_x_block + 1); + enemy_projectile_y_pos[v1] = 16 * (plm_y_block - 2); +} + +static uint16 CheckIfEnemyProjectileIsOffScreen(uint16 k) { // 0x86E6E0 + int v1 = k >> 1; + if ((int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) >= 0) { + if ((int16)(enemy_projectile_x_pos[v1] - (layer1_x_pos + 256)) < 0 + && (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) >= 0) { + if ((int16)(enemy_projectile_y_pos[v1] - (layer1_y_pos + 256)) < 0) + return 0; + } + } + return 1; +} + +uint16 Eproj_FuncE722(uint16 k) { // 0x86E722 + int16 v2; + int16 v3; + + int v1 = k >> 1; + v2 = enemy_projectile_x_pos[v1]; + uint16 result = 1; + if (v2 >= 0) { + if (sign16(v2 - 512)) { + v3 = enemy_projectile_y_pos[v1]; + if (v3 >= 0) { + if (sign16(v3 - 512)) + return 0; + } + } + } + return result; +} + +void Eproj_FuncE73E_MoveXY(uint16 k) { // 0x86E73E + int v1 = k >> 1; + if (((g_word_7E97DC[v1] + 64) & 0x80) != 0) { + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], + -(int32)__PAIR32__(enemy_projectile_x_vel[v1], enemy_projectile_E[v1])); + } else { + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], + __PAIR32__(enemy_projectile_x_vel[v1], enemy_projectile_E[v1])); + } + if (((g_word_7E97DC[v1] + 128) & 0x80) != 0) { + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], + -(int32)__PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_F[v1])); + } else { + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], + __PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_F[v1])); + } +} + +void Eproj_AngleToSamus(uint16 j, uint16 r18, uint16 r20) { // 0x86E7AB + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = r18; + enemy_projectile_y_pos[v1] = r20; + uint16 v2 = (uint8)(64 - CalculateAngleFromXY(samus_x_pos - enemy_projectile_x_pos[v1], samus_y_pos - enemy_projectile_y_pos[v1])); + g_word_7E97DC[v1] = v2; + Point32 pt = ConvertAngleToXy(v2, enemy_projectile_init_param_1); + enemy_projectile_x_vel[v1] = pt.x >> 16; + enemy_projectile_E[v1] = pt.x; + enemy_projectile_y_vel[v1] = pt.y >> 16; + enemy_projectile_F[v1] = pt.y; +} + + +static void EprojInit_BotwoonsBody(uint16 j) { // 0x86EA31 + int v1 = j >> 1; + enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; + enemy_projectile_y_pos[v1] = enemy_data[0].y_pos; + enemy_projectile_y_vel[v1] = 0; + uint16 v2 = enemy_data[0].ai_var_A ? 16 : 48; + uint16 v3 = kEprojInit_BotwoonsBody_InstrLists[v2 >> 1]; + enemy_projectile_instr_list_ptr[v1] = v3; + enemy_projectile_F[v1] = v3; + enemy_projectile_E[v1] = v2; + enemy_projectile_x_vel[v1] = FUNC16(Eproj_BotwoonsBody_Main); + ExtraEnemyRam7800 *Ex = gExtraEnemyRam7800(enemy_data[0].ai_var_A); + Ex->kraid.kraid_next = j; + enemy_projectile_flags[v1] = 2; + Ex->kraid.kraid_healths_4ths[0] = 1; +} + +void CallBotwoonEprojFunc(uint32 ea, uint16 k) { + switch (ea) { + case fnEproj_BotwoonsBody_Main: Eproj_BotwoonsBody_Main(k); return; + case fnEproj_BotwonsBodyFunction_Dying: Eproj_BotwonsBodyFunction_Dying(k); return; + case fnEproj_BotwonsBodyFunction_Dying2: Eproj_BotwonsBodyFunction_Dying2(k); return; + case fnEproj_BotwonsBodyFunction_DyingFalling: Eproj_BotwonsBodyFunction_DyingFalling(k); return; + case fnnullsub_101: return; + default: Unreachable(); + } +} + +void EprojPreInstr_BotwoonsBody(uint16 k) { // 0x86EA80 + if (*(uint16 *)&extra_enemy_ram8000[0].pad[32]) { + int v1 = k >> 1; + if (enemy_projectile_x_vel[v1] == FUNC16(Eproj_BotwoonsBody_Main)) + enemy_projectile_x_vel[v1] = FUNC16(Eproj_BotwonsBodyFunction_Dying); + } + CallBotwoonEprojFunc(enemy_projectile_x_vel[k >> 1] | 0x860000, k); +} + +void Eproj_BotwoonsBody_Main(uint16 k) { // 0x86EA98 + int v1 = k >> 1; + uint16 v2 = kEprojInit_BotwoonsBody_InstrLists[enemy_projectile_E[v1] >> 1]; + if (v2 != enemy_projectile_F[v1]) { + enemy_projectile_instr_list_ptr[v1] = v2; + enemy_projectile_F[v1] = v2; + enemy_projectile_instr_timers[v1] = 1; + } + Eproj_BotwoonsBodyHurtFlashHandling1(k); +} + +void Eproj_BotwoonsBodyHurtFlashHandling1(uint16 k) { // 0x86EAB4 + int v1 = k >> 1; + enemy_projectile_gfx_idx[v1] |= 0xE00; + if (enemy_data[0].flash_timer) { + if ((random_enemy_counter & 2) != 0) + enemy_projectile_gfx_idx[v1] &= 0xF1FF; + } +} + +void Eproj_BotwoonsBodyHurtFlashHandling2(uint16 j) { // 0x86EAD4 + int v1 = j >> 1; + enemy_projectile_gfx_idx[v1] |= 0xE00; + if (enemy_data[0].flash_timer) { + if ((random_enemy_counter & 2) != 0) + enemy_projectile_gfx_idx[v1] &= 0xF1FF; + } +} + +void Eproj_BotwonsBodyFunction_Dying(uint16 v0) { // 0x86EAF4 + int v1 = v0 >> 1; + enemy_projectile_E[v1] = 4 * v0 + 96; + enemy_projectile_x_vel[v1] = 0xEB04; + Eproj_BotwonsBodyFunction_Dying2(v0); +} + +void Eproj_BotwonsBodyFunction_Dying2(uint16 v0) { // 0x86EB04 + int v1 = v0 >> 1; + if (!sign16(++enemy_projectile_E[v1] - 256)) + enemy_projectile_x_vel[v1] = FUNC16(Eproj_BotwonsBodyFunction_DyingFalling); + enemy_projectile_instr_timers[v1] = 0; + Eproj_BotwoonsBodyHurtFlashHandling1(v0); +} + +void Eproj_BotwonsBodyFunction_DyingFalling(uint16 v0) { // 0x86EB1F + int v1 = v0 >> 1; + int v3 = (8 * ((enemy_projectile_y_vel[v1] & 0xFF00) >> 8)) >> 1; + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], kCommonEnemySpeeds_Quadratic32[v3 >> 1]); + + if (sign16(enemy_projectile_y_pos[v1] - 200)) { + int v7 = v0 >> 1; + enemy_projectile_y_vel[v7] += 192; + enemy_projectile_instr_timers[v7] = 0; + Eproj_BotwoonsBodyHurtFlashHandling2(v0); + } else { + enemy_projectile_y_pos[v1] = 200; + enemy_projectile_x_vel[v1] = FUNC16(nullsub_101); + enemy_projectile_instr_list_ptr[v1] = addr_word_86E208; + enemy_projectile_gfx_idx[v1] = 2560; + enemy_projectile_instr_timers[v1] = 1; + QueueSmallExplosionSfx(); + if (v0 == 10) + *(uint16 *)&extra_enemy_ram8800[0].pad[62] = 1; + } +} + +void QueueSmallExplosionSfx(void) { // 0x86EB94 + QueueSfx2_Max6(0x24); +} + +static void EprojInit_BotwoonsSpit(uint16 j) { // 0x86EBC6 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = v1->x_pos; + enemy_projectile_y_pos[v2] = v1->y_pos; + enemy_projectile_instr_list_ptr[v2] = addr_word_86EBAE; + g_word_7E97DC[v2] = enemy_projectile_init_param_3; + Point32 pt = ConvertAngleToXy(enemy_projectile_init_param_3, enemy_projectile_init_param_1); + enemy_projectile_x_vel[v2] = pt.x >> 16; + enemy_projectile_E[v2] = pt.x; + enemy_projectile_y_vel[v2] = pt.y >> 16; + enemy_projectile_F[v2] = pt.y; +} + +void EprojPreInstr_BotwoonsSpit(uint16 k) { // 0x86EC05 + Eproj_FuncE73E_MoveXY(k); + sub_86EC0C(k); +} + +void sub_86EC0C(uint16 k) { // 0x86EC0C + if (sub_86EC18(k)) + enemy_projectile_id[k >> 1] = 0; +} + +uint16 sub_86EC18(uint16 k) { // 0x86EC18 + int v1 = k >> 1; + return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 + || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 + || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 + || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; +} + +static void EprojInit_YappingMawsBody(uint16 j) { // 0x86EC62 + EnemyData *v2 = gEnemyData(cur_enemy_index); + int v3 = j >> 1; + enemy_projectile_x_pos[v3] = v2->x_pos; + enemy_projectile_y_pos[v3] = v2->y_pos; + enemy_projectile_instr_list_ptr[v3] = addr_word_86EC5C; + if (!v2->parameter_2) + enemy_projectile_instr_list_ptr[v3] = addr_word_86EC56; + *(uint16 *)&extra_enemy_ram8800[0].pad[(uint16)(cur_enemy_index + + 2 * *(uint16 *)&extra_enemy_ram8800[0].pad[cur_enemy_index + 8])] = j; +} + +const uint8 *EprojInstr_ECE3(uint16 k, const uint8 *epjp) { // 0x86ECE3 + int v2 = k >> 1; + uint16 x = enemy_projectile_x_pos[v2] + (NextRandom() & 0x3F) - 32; + uint16 y = enemy_projectile_y_pos[v2] + ((uint16)(random_number & 0x3F00) >> 8) - 32; + CreateSpriteAtPos(x, y, GET_WORD(epjp), 0); + return epjp + 2; +} + +const uint8 *EprojInstr_ED17(uint16 k, const uint8 *epjp) { // 0x86ED17 + int v2 = k >> 1; + uint16 x = enemy_projectile_x_pos[v2] + (NextRandom() & 0x1F) - 16; + uint16 y = enemy_projectile_y_pos[v2] + ((uint16)(random_number & 0x1F00) >> 8) - 16; + CreateSpriteAtPos(x, y, GET_WORD(epjp), 0); + return epjp + 2; +} + +const uint8 *EprojInstr_QueueSfx2_9(uint16 k, const uint8 *epjp) { // 0x86EE8B + QueueSfx2_Max1(9); + return epjp; +} + +const uint8 *EprojInstr_QueueSfx2_24(uint16 k, const uint8 *epjp) { // 0x86EE97 + QueueSfx2_Max1(0x24); + return epjp; +} + +const uint8 *EprojInstr_QueueSfx2_B(uint16 k, const uint8 *epjp) { // 0x86EEA3 + QueueSfx2_Max1(0xB); + return epjp; +} + +const uint8 *EprojInstr_EEAF(uint16 k, const uint8 *epjp) { // 0x86EEAF + uint16 v2 = RandomDropRoutine(k); + if (k != 0 && sign16(v2 - 6)) { + uint16 v3 = 2 * v2; + int v4 = k >> 1; + enemy_projectile_E[v4] = v3; + enemy_projectile_instr_list_ptr[v4] = off_86EF04[v3 >> 1]; + enemy_projectile_instr_timers[v4] = 1; + enemy_projectile_F[v4] = 400; + enemy_projectile_pre_instr[v4] = FUNC16(EprojPreInstr_Pickup); + enemy_projectile_properties[v4] &= ~0x4000; + return INSTRB_RETURN_ADDR(enemy_projectile_instr_list_ptr[v4]); + } else { + int v6 = k >> 1; + enemy_projectile_instr_timers[v6] = 1; + enemy_projectile_properties[v6] = 12288; + enemy_projectile_pre_instr[v6] = FUNC16(EprojPreInstr_Empty); + enemy_projectile_instr_list_ptr[v6] = 0xECA3; + return INSTRB_RETURN_ADDR(0xECA3); + } +} + +const uint8 *EprojInstr_HandleRespawningEnemy(uint16 k, const uint8 *epjp) { // 0x86EF10 + if ((int16)enemy_projectile_killed_enemy_index[k >> 1] <= -2) + RespawnEnemy(enemy_projectile_killed_enemy_index[k >> 1] & 0x7fff); + return epjp; +} + +static void EprojInit_F337(uint16 j) { // 0x86EF29 + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = eproj_spawn_pt.x; + enemy_projectile_y_pos[v2] = eproj_spawn_pt.y; + enemy_projectile_gfx_idx[v2] = 0; + enemy_projectile_enemy_header_ptr[v2] = eproj_spawn_varE24; // this is X?! + uint16 v3 = RandomDropRoutine(j); + if (v3 != 0 && sign16(v3 - 6)) { // bug, why does it compare x here. + uint16 v4 = 2 * v3; + enemy_projectile_E[v2] = v4; + enemy_projectile_instr_list_ptr[v2] = off_86EF04[v4 >> 1]; + enemy_projectile_instr_timers[v2] = 1; + enemy_projectile_F[v2] = 400; + enemy_projectile_killed_enemy_index[j >> 1] = -1; + } else { + int v5 = j >> 1; + enemy_projectile_instr_list_ptr[v5] = addr_word_86ECA3; + enemy_projectile_instr_timers[v5] = 1; + enemy_projectile_properties[v5] = 12288; + enemy_projectile_pre_instr[v5] = FUNC16(EprojPreInstr_Empty); + } +} + + +static void EprojInit_EnemyDeathExplosion(uint16 j) { // 0x86EF89 + EnemyData *v1 = gEnemyData(cur_enemy_index); + int v2 = j >> 1; + enemy_projectile_x_pos[v2] = v1->x_pos; + enemy_projectile_y_pos[v2] = v1->y_pos; + enemy_projectile_killed_enemy_index[v2] = cur_enemy_index; + if ((v1->properties & 0x4000) != 0) + enemy_projectile_killed_enemy_index[v2] = cur_enemy_index | 0x8000; + enemy_projectile_enemy_header_ptr[v2] = v1->enemy_ptr; + enemy_projectile_gfx_idx[v2] = 0; + enemy_projectile_instr_list_ptr[v2] = off_86EFD5[enemy_projectile_init_param_1]; + enemy_projectile_instr_timers[v2] = 1; +} + +static Func_V *const off_86F0AD[7] = { // 0x86EFE0 + 0, + Eproj_Pickup_SmallHealth, + Eproj_Pickup_BigHealth, + Eproj_Pickup_PowerBombs, + Eproj_Pickup_Missiles, + Eproj_Pickup_SuperMissiles, + 0, +}; + +void EprojPreInstr_Pickup(uint16 k) { + int v1 = k >> 1; + if (!--enemy_projectile_F[v1]) + goto LABEL_7; + if (CallSomeSamusCode(0xD)) { + if (sign16(enemy_projectile_F[v1] - 384)) { + uint16 v2, v3; + v2 = abs16(enemy_projectile_x_pos[v1] - grapple_beam_end_x_pos); + if (sign16(v2 - 16)) { + v3 = abs16(enemy_projectile_y_pos[v1] - grapple_beam_end_y_pos); + if (sign16(v3 - 16)) { + off_86F0AD[enemy_projectile_E[v1] >> 1](); +LABEL_7:; + int v4 = k >> 1; + enemy_projectile_instr_list_ptr[v4] = addr_word_86ECA3; + enemy_projectile_instr_timers[v4] = 1; + enemy_projectile_properties[v4] = 12288; + enemy_projectile_pre_instr[v4] = FUNC16(EprojPreInstr_Empty); + return; + } + } + } + } + int v5 = k >> 1; + uint16 varE20 = LOBYTE(enemy_projectile_radius[v5]); + uint16 varE22 = HIBYTE(enemy_projectile_radius[v5]); + uint16 v6 = abs16(samus_x_pos - enemy_projectile_x_pos[v5]); + bool v7 = v6 < samus_x_radius; + uint16 v8 = v6 - samus_x_radius; + if (v7 || v8 < varE20) { + uint16 v9 = abs16(samus_y_pos - enemy_projectile_y_pos[v5]); + v7 = v9 < samus_y_radius; + uint16 v10 = v9 - samus_y_radius; + if (v7 || v10 < varE22) { + off_86F0AD[enemy_projectile_E[v5] >> 1](); + int v11 = k >> 1; + enemy_projectile_instr_list_ptr[v11] = addr_word_86ECA3; + enemy_projectile_instr_timers[v11] = 1; + enemy_projectile_properties[v11] = 12288; + enemy_projectile_pre_instr[v11] = FUNC16(EprojPreInstr_Empty); + } + } +} + +void Eproj_Pickup_SmallHealth(void) { // 0x86F0BB + Samus_RestoreHealth(5); + QueueSfx2_Max1(1); +} + +void Eproj_Pickup_BigHealth(void) { // 0x86F0CA + Samus_RestoreHealth(0x14); + QueueSfx2_Max1(2); +} + +void Eproj_Pickup_PowerBombs(void) { // 0x86F0D9 + Samus_RestorePowerBombs(1); + QueueSfx2_Max1(5); +} + +void Eproj_Pickup_Missiles(void) { // 0x86F0E8 + Samus_RestoreMissiles(2); + QueueSfx2_Max1(3); +} + +void Eproj_Pickup_SuperMissiles(void) { // 0x86F0F7 + Samus_RestoreSuperMissiles(1); + QueueSfx2_Max1(4); +} + +static const uint8 byte_86F25E[6] = { 1, 2, 4, 6, 5, 3 }; + +uint16 RandomDropRoutine(uint16 k) { // 0x86F106 + int8 v9; // cf + uint8 r18, r22, r20; + uint16 r24; + + int v1 = k >> 1; + //varE2A = enemy_projectile_killed_enemy_index[v1] & 0x7FFF; + uint16 varE28 = enemy_projectile_enemy_header_ptr[v1]; + if (varE28 == 0) + goto LABEL_30; + uint16 v2; + v2 = *((uint16 *)RomPtr_A0(varE28) + 29); + if (!v2) + goto LABEL_30; + uint8 Random; + do + Random = NextRandom(); + while (!Random); + r20 = 255; + r24 = 0; + uint16 v5; + v5 = 1; + if ((uint16)(samus_reserve_health + samus_health) >= 0x1E) { + if ((uint16)(samus_reserve_health + samus_health) < 0x32) + goto LABEL_7; + v5 = 0; + } + health_drop_bias_flag = v5; +LABEL_7:; + const uint8 *v7 = RomPtr_B4(v2); + if ((uint8)health_drop_bias_flag) { + r18 = v7[1] + *v7; + r22 = 3; + } else { + r18 = v7[3]; + r22 = 8; + if (samus_health != samus_max_health || samus_reserve_health != samus_max_reserve_health) { + r18 = v7[1] + *v7 + r18; + r22 = r22 | 3; + } + if (samus_missiles != samus_max_missiles) { + r18 = v7[2] + r18; + r22 = r22 | 4; + } + if (samus_super_missiles != samus_max_super_missiles) { + r20 = r20 - v7[4]; + r22 = r22 | 0x10; + } + if (samus_power_bombs != samus_max_power_bombs) { + r20 = r20 - v7[5]; + r22 = r22 | 0x20; + } + } + int i; + for (i = 0; i != 4; ++i) { + if (!(uint8)r18) { + r22 = (uint8)r22 >> 4; + v2 += 4; + i = 4; + goto LABEL_26; + } + v9 = r22 & 1; + r22 = (uint8)r22 >> 1; + if (v9) { + const uint8 *v10 = RomPtr_B4(v2); + uint16 RegWord = Mult8x8(r20, *v10); + int divved = SnesDivide(RegWord, r18); + uint16 v12 = r24; + uint16 v13 = divved + v12; + if (v13 >= Random) + return byte_86F25E[i]; + r24 = v13; + } + ++v2; + } + do { +LABEL_26: + v9 = r22 & 1; + r22 = (uint8)r22 >> 1; + if (v9) { + const uint8 *v14 = RomPtr_B4(v2); + if ((uint16)(r24 + *v14) >= Random) + return byte_86F25E[i]; + r24 += *v14; + } + ++v2; + ++i; + } while (i != 6); +LABEL_30: + i = 3; + return byte_86F25E[i]; +} + +void RespawnEnemy(uint16 v0) { // 0x86F264 + cur_enemy_index = v0; + const uint8 *v1 = RomPtr_A1(room_enemy_population_ptr + (v0 >> 2)); + EnemyData *E = gEnemyData(v0); + E->enemy_ptr = GET_WORD(v1); + E->x_pos = GET_WORD(v1 + 2); + E->y_pos = GET_WORD(v1 + 4); + E->current_instruction = GET_WORD(v1 + 6); + E->properties = GET_WORD(v1 + 8); + E->extra_properties = GET_WORD(v1 + 10); + E->parameter_1 = GET_WORD(v1 + 12); + E->parameter_2 = GET_WORD(v1 + 14); + EnemySpawnData *ESD = gEnemySpawnData(v0); + E->palette_index = ESD->palette_index; + E->vram_tiles_index = ESD->vram_tiles_index; + E->frozen_timer = 0; + E->flash_timer = 0; + E->invincibility_timer = 0; + E->timer = 0; + E->frame_counter = 0; + E->ai_var_A = 0; + E->ai_var_B = 0; + E->ai_var_C = 0; + E->ai_var_D = 0; + E->ai_var_E = 0; + E->ai_preinstr = 0; + E->instruction_timer = 1; + EnemyDef_A2 *Edef = get_EnemyDef_A2(E->enemy_ptr); + E->x_width = Edef->x_radius; + E->y_height = Edef->y_radius; + E->health = Edef->health; + E->layer = Edef->layer; + *(uint16 *)&E->bank = *(uint16 *)&Edef->bank; + CallEnemyAi(Edef->bank << 16 | Edef->ai_init); +} + + +static void EprojInit_Sparks(uint16 j) { // 0x86F391 + static const uint16 word_86F3D4[14] = { 0xffff, 0xb800, 0xffff, 0xc000, 0xffff, 0xe000, 0xffff, 0xff00, 0, 0x100, 0, 0x2000, 0, 0x4000 }; + int v2 = j >> 1; + enemy_projectile_instr_list_ptr[v2] = addr_kEnemyDef_F353; + EnemyData *v3 = gEnemyData(cur_enemy_index); + enemy_projectile_x_pos[v2] = v3->x_pos; + enemy_projectile_x_subpos[v2] = v3->x_subpos; + enemy_projectile_y_pos[v2] = v3->y_pos + 8; + enemy_projectile_y_subpos[v2] = v3->y_subpos; + enemy_projectile_x_vel[v2] = 0; + enemy_projectile_y_vel[v2] = 0; + uint16 v4 = (NextRandom() & 0x1C) >> 1; + enemy_projectile_F[v2] = g_word_86F3D4[v4 + 0]; + enemy_projectile_E[v2] = g_word_86F3D4[v4 + 1]; +} + +void EprojPreInstr_Sparks(uint16 k) { // 0x86F3F0 + int v1 = k >> 1; + if ((enemy_projectile_y_vel[v1] & 0x8000) == 0) { + if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { + enemy_projectile_instr_list_ptr[v1] = 0xF363; + enemy_projectile_instr_timers[v1] = 1; + + enemy_projectile_F[v1] = enemy_projectile_F[v1] * 2 + (enemy_projectile_E[v1] >> 15); + enemy_projectile_E[v1] *= 2; + + enemy_projectile_F[v1] = enemy_projectile_F[v1] * 2 + (enemy_projectile_E[v1] >> 15); + enemy_projectile_E[v1] *= 2; + + enemy_projectile_x_vel[v1] = 0x8000; + enemy_projectile_y_vel[v1] = -1; + enemy_projectile_y_pos[v1] -= 2; + return; + } + uint16 v2 = enemy_projectile_x_vel[v1]; + enemy_projectile_x_vel[v1] = v2 + 0x4000; + uint16 v3 = __CFADD__uint16(v2, 0x4000) + enemy_projectile_y_vel[v1]; + if (v3 < 4) + enemy_projectile_y_vel[v1] = v3; + } + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], + __PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_x_vel[v1])); + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], + __PAIR32__(enemy_projectile_F[v1], enemy_projectile_E[v1])); + if ((nmi_frame_counter_byte & 3) == 0) + CreateSpriteAtPos(enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1], 48, enemy_projectile_gfx_idx[v1]); +} + +static void CallEnemyProjectileInit(uint32 ea, uint16 j) { switch (ea) { case fnEnemyProj_Init_0x8aaf: EnemyProj_Init_0x8aaf(j); return; case fnEnemyProj_Init_0x8bc2_SkreeDownRight: EnemyProj_Init_0x8bc2_SkreeDownRight(j); return; @@ -64,7 +4950,6 @@ void CallEnemyProjectileInit(uint32 ea, uint16 j) { case fnEnemyProj_Init_0x8bec_SkreeUpLeft: EnemyProj_Init_0x8bec_SkreeUpLeft(j); return; case fnEprojInit_DraygonsGunk: EprojInit_DraygonsGunk(j); return; case fnEprojInit_DraygonsWallTurretProjs: EprojInit_DraygonsWallTurretProjs(j); return; - case fnEprojInit_8E6C: EprojInit_8E6C(j); return; case fnEprojInit_CrocomireProjectile: EprojInit_CrocomireProjectile(j); return; case fnEprojInit_CrocomireSpikeWallPieces: EprojInit_CrocomireSpikeWallPieces(j); return; case fnEprojInit_CrocomireBridgeCrumbling: EprojInit_CrocomireBridgeCrumbling(j); return; @@ -160,7 +5045,7 @@ void CallEnemyProjectileInit(uint32 ea, uint16 j) { case fnEprojInit_SporeSpawners: EprojInit_SporeSpawners(j); return; case fnEprojInit_NamiFuneFireball: EprojInit_NamiFuneFireball(j); return; case fnEprojInit_LavaThrownByLavaman: EprojInit_LavaThrownByLavaman(j); return; - case fnEprojInst_DustCloudOrExplosion: EprojInst_DustCloudOrExplosion(j); return; + case fnEprojInit_DustCloudOrExplosion: EprojInit_DustCloudOrExplosion(j); return; case fnEprojInit_EyeDoorSmoke: EprojInit_EyeDoorSmoke(j); return; case fnEprojInit_SpawnedShotGate: EprojInit_SpawnedShotGate(j); return; case fnEprojInit_ClosedDownwardsShotGate: EprojInit_ClosedDownwardsShotGate(j); return; @@ -175,79 +5060,8 @@ void CallEnemyProjectileInit(uint32 ea, uint16 j) { default: Unreachable(); } } -void SpawnEnemyProjectileWithGfx(uint16 a, uint16 k, uint16 j) { // 0x868027 - EnemyProjectileDef *EnemyProjectileDef; - enemy_projectile_init_param = a; - EnemyData *v3 = gEnemyData(k); - uint16 v5 = 34; - while (enemy_projectile_id[v5 >> 1]) { - v5 -= 2; - if ((v5 & 0x8000u) != 0) - return; - } - int v6 = v5 >> 1; - enemy_projectile_gfx_idx[v6] = v3->vram_tiles_index | v3->palette_index; - enemy_projectile_id[v6] = j; - EnemyProjectileDef = get_EnemyProjectileDef(j); - enemy_projectile_pre_instr[v6] = EnemyProjectileDef->pre_instr_ptr; - enemy_projectile_instr_list_ptr[v6] = EnemyProjectileDef->instr_list; - enemy_projectile_radius[v6] = EnemyProjectileDef->radius; - enemy_projectile_properties[v6] = EnemyProjectileDef->properties; - enemy_projectile_instr_timers[v6] = 1; - enemy_projectile_spritemap_ptr[v6] = 0x8000; - enemy_projectile_E[v6] = 0; - enemy_projectile_F[v6] = 0; - enemy_projectile_timers[v6] = 0; - enemy_projectile_1A27[v6] = 0; - enemy_projectile_y_subpos[v6] = 0; - enemy_projectile_G[v6] = 0; - CallEnemyProjectileInit(EnemyProjectileDef->init_code_ptr | 0x860000, v5); -} - -void SpawnEnemyProjectileWithRoomGfx(uint16 j, uint16 a) { // 0x868097 - EnemyProjectileDef *EnemyProjectileDef; - - enemy_projectile_init_param = a; - uint16 v3 = 34; - while (enemy_projectile_id[v3 >> 1]) { - v3 -= 2; - if ((v3 & 0x8000u) != 0) - return; - } - int v4 = v3 >> 1; - enemy_projectile_gfx_idx[v4] = 0; - enemy_projectile_id[v4] = j; - EnemyProjectileDef = get_EnemyProjectileDef(j); - enemy_projectile_pre_instr[v4] = EnemyProjectileDef->pre_instr_ptr; - enemy_projectile_instr_list_ptr[v4] = EnemyProjectileDef->instr_list; - enemy_projectile_radius[v4] = EnemyProjectileDef->radius; - enemy_projectile_properties[v4] = EnemyProjectileDef->properties; - enemy_projectile_instr_timers[v4] = 1; - enemy_projectile_spritemap_ptr[v4] = 0x8000; - enemy_projectile_E[v4] = 0; - enemy_projectile_F[v4] = 0; - enemy_projectile_timers[v4] = 0; - enemy_projectile_timers[v4] = 0; - enemy_projectile_1A27[v4] = 0; - enemy_projectile_y_subpos[v4] = 0; - enemy_projectile_G[v4] = 0; - CallEnemyProjectileInit(EnemyProjectileDef->init_code_ptr | 0x860000, v3); -} - -void EprojRunAll(void) { // 0x868104 - if ((enemy_projectile_enable_flag & 0x8000u) != 0) { - for (int i = 34; i >= 0; i -= 2) { - enemy_projectile_index = i; - if (enemy_projectile_id[i >> 1]) { - EprojRunOne(i); - i = enemy_projectile_index; - } - } - } -} - -void CallEprojPreInstr(uint32 ea, uint16 k) { +static void CallEprojPreInstr(uint32 ea, uint16 k) { switch (ea) { case fnnullsub_352: return; case fnEprojPreInstr_nullsub_297: return; @@ -258,7 +5072,6 @@ void CallEprojPreInstr(uint32 ea, uint16 k) { case fnEprojPreInstr_8DCA: EprojPreInstr_8DCA(k); return; case fnEprojPreInstr_DraygonsTurret_8DFF: EprojPreInstr_DraygonsTurret_8DFF(k); return; case fnEprojPreInstr_DraygonsGunk_8E0F: EprojPreInstr_DraygonsGunk_8E0F(k); return; - case fnEprojPreInstr_8E6C: EprojPreInstr_8E6C(k); return; case fnEprojPreInstr_CrocomireProjectile: EprojPreInstr_CrocomireProjectile(k); return; case fnsub_8690B3: sub_8690B3(k); return; case fnEprojPreInstr_CrocomireSpikeWallPieces: EprojPreInstr_CrocomireSpikeWallPieces(k); return; @@ -394,7 +5207,8 @@ void CallEprojPreInstr(uint32 ea, uint16 k) { default: Unreachable(); } } -uint16 CallEprojInstr(uint32 ea, uint16 k, uint16 j) { + +static const uint8 *CallEprojInstr(uint32 ea, uint16 k, const uint8 *j) { switch (ea) { case fnEprojInstr_Delete: return EprojInstr_Delete(k, j); case fnEprojInstr_Sleep: return EprojInstr_Sleep(k, j); @@ -438,7 +5252,6 @@ uint16 CallEprojInstr(uint32 ea, uint16 k, uint16 j) { case fnEprojInstr_QueueSfx2_Max1: return EprojInstr_QueueSfx2_Max1(k, j); case fnEprojInstr_QueueSfx3_Max1: return EprojInstr_QueueSfx3_Max1(k, j); case fnEprojInstr_SpawnEnemyDropsWithDraygonsEyeDrops: return EprojInstr_SpawnEnemyDropsWithDraygonsEyeDrops(k, j); - case fnEprojInstr_868D55: return EprojInstr_868D55(k, j); case fnEprojInstr_868D99: return EprojInstr_868D99(k, j); case fnEprojInstr_DisableCollisionsWithSamus: return EprojInstr_DisableCollisionsWithSamus(k, j); case fnEprojInstr_95BA: return EprojInstr_95BA(k, j); @@ -486,5432 +5299,13 @@ uint16 CallEprojInstr(uint32 ea, uint16 k, uint16 j) { case fnEprojInstr_HandleRespawningEnemy: return EprojInstr_HandleRespawningEnemy(k, j); case fnEprojInstr_SetPreInstrA: return EprojInstr_SetPreInstrA(k, j); case fnEprojInstr_SetPreInstrB: return EprojInstr_SetPreInstrB(k, j); - // EXTRA!!! - case fnEprojPreInstr_PirateMotherBrainLaser_MoveRight: - EprojPreInstr_PirateMotherBrainLaser_MoveRight(k); - return j; - case fnEprojPreInstr_PirateMotherBrainLaser_MoveLeft: - EprojPreInstr_PirateMotherBrainLaser_MoveLeft(k); - return j; - + case fnEprojPreInstr_PirateMotherBrainLaser_MoveRight: EprojPreInstr_PirateMotherBrainLaser_MoveRight(k); return j; + case fnEprojPreInstr_PirateMotherBrainLaser_MoveLeft: EprojPreInstr_PirateMotherBrainLaser_MoveLeft(k); return j; case fnEprojInstr_A3BE: return EprojInstr_A3BE(k, j); case fnEprojInstr_9270: return EprojInstr_9270(k, j); case fnnullsub_82: return j; // really j case fnsub_86B13E: return sub_86B13E(k, j); - default: return Unreachable(); + default: Unreachable(); return NULL; } } -void EprojRunOne(uint16 k) { // 0x868125 - CallEprojPreInstr(enemy_projectile_pre_instr[k >> 1] | 0x860000, k); - uint16 v1 = enemy_projectile_index; - int v2 = enemy_projectile_index >> 1; - if (enemy_projectile_instr_timers[v2]-- == 1) { - uint16 v4 = enemy_projectile_instr_list_ptr[v2], v6; - while (1) { - const uint16 *v5 = (const uint16 *)RomPtr_86(v4); - v6 = *v5; - if ((*v5 & 0x8000u) == 0) - break; - R18_ = *v5; - v4 = CallEprojInstr(v6 | 0x860000, v1, v4 + 2); - if (!v4) - return; - } - if (v4 == 0) { - - v4 = 0; - } - int v7 = v1 >> 1; - enemy_projectile_instr_timers[v7] = v6; - enemy_projectile_spritemap_ptr[v7] = *((uint16 *)RomPtr_86(v4) + 1); - enemy_projectile_instr_list_ptr[v7] = v4 + 4; - } -} - -uint16 EprojInstr_Delete(uint16 k, uint16 j) { // 0x868154 - enemy_projectile_id[k >> 1] = 0; - return 0; -} - -uint16 EprojInstr_Sleep(uint16 k, uint16 j) { // 0x868159 - enemy_projectile_instr_list_ptr[k >> 1] = j - 2; - return 0; -} - -uint16 EprojInstr_SetPreInstr_(uint16 k, uint16 j) { // 0x868161 - enemy_projectile_pre_instr[k >> 1] = *(uint16 *)RomPtr_86(j); - return j + 2; -} - -uint16 EprojInstr_ClearPreInstr(uint16 k, uint16 j) { // 0x86816A - enemy_projectile_pre_instr[k >> 1] = 0x8170; - return j; -} - -void CallEprojFunc(uint32 ea, uint32 k) { - switch (ea) { - case fnSpawnMotherBrainDeathBeam: SpawnMotherBrainDeathBeam(k); return; - default: Unreachable(); - } -} - -uint16 EprojInstr_CallFunc(uint16 k, uint16 j) { // 0x868171 - const uint8 *v2 = RomPtr_86(j); - copy24((LongPtr *)&R18_, (LongPtr *)v2); - - uint32 ea = Load24((LongPtr *)&R18_); - CallEprojFunc(ea, k); - - //CallFar((LongPtr *)&R18_); - return j + 3; -} - -uint16 EprojInstr_Goto(uint16 k, uint16 j) { // 0x8681AB - return *(uint16 *)RomPtr_86(j); -} - -uint16 EprojInstr_GotoRel(uint16 k, uint16 j) { // 0x8681B0 - R18_ = j; - return R18_ + (int8)*RomPtr_86(j); -} - -uint16 EprojInstr_DecTimerAndGotoIfNonZero(uint16 k, uint16 j) { // 0x8681C6 - int v2 = k >> 1; - if (enemy_projectile_timers[v2]-- == 1) - return j + 2; - else - return EprojInstr_Goto(k, j); -} - -uint16 EprojInstr_DecTimerAndGotoRelIfNonZero(uint16 k, uint16 j) { // 0x8681CE - int v2 = k >> 1; - if (enemy_projectile_timers[v2]-- == 1) - return j + 1; - else - return EprojInstr_GotoRel(k, j); -} - -uint16 EprojInstr_SetTimer(uint16 k, uint16 j) { // 0x8681D5 - enemy_projectile_timers[k >> 1] = *(uint16 *)RomPtr_86(j); - return j + 2; -} - -uint16 EprojInstr_MoveRandomlyWithinRadius(uint16 k, uint16 j) { // 0x8681DF - int8 Random; - int8 v4; - int16 v6; - - R18_ = NextRandom(); - do { - Random = NextRandom(); - const uint8 *v3 = RomPtr_86(j); - v4 = (*v3 & Random) - v3[1]; - } while (v4 < 0); - enemy_projectile_x_pos[k >> 1] += sign16(R18_) ? -(uint8)v4 : (uint8)v4; - do { - LOBYTE(v6) = NextRandom(); - const uint8 *v5 = RomPtr_86(j); - LOBYTE(v6) = (v5[2] & v6) - v5[3]; - } while ((v6 & 0x80) != 0); - v6 = (uint8)v6; - if ((R18_ & 0x4000) != 0) - v6 = -(uint8)v6; - enemy_projectile_y_pos[k >> 1] += v6; - return j + 4; -} - -uint16 EprojInstr_SetProjectileProperties(uint16 k, uint16 j) { // 0x868230 - enemy_projectile_properties[k >> 1] |= *(uint16 *)RomPtr_86(j); - return j + 2; -} - -uint16 EprojInstr_ClearProjectileProperties(uint16 k, uint16 j) { // 0x86823C - enemy_projectile_properties[k >> 1] &= *(uint16 *)RomPtr_86(j); - return j + 2; -} - -uint16 EprojInstr_EnableCollisionWithSamusProj(uint16 k, uint16 j) { // 0x868248 - enemy_projectile_properties[k >> 1] |= 0x8000u; - return j; -} - -uint16 EprojInstr_DisableCollisionWithSamusProj(uint16 k, uint16 j) { // 0x868252 - enemy_projectile_properties[k >> 1] &= ~0x8000u; - return j; -} - -uint16 EprojInstr_DisableCollisionWithSamus(uint16 k, uint16 j) { // 0x86825C - enemy_projectile_properties[k >> 1] |= 0x2000u; - return j; -} - -uint16 EprojInstr_EnableCollisionWithSamus(uint16 k, uint16 j) { // 0x868266 - enemy_projectile_properties[k >> 1] &= ~0x2000u; - return j; -} - -uint16 EprojInstr_SetToNotDieOnContact(uint16 k, uint16 j) { // 0x868270 - enemy_projectile_properties[k >> 1] |= 0x4000u; - return j; -} - -uint16 EprojInstr_SetToDieOnContact(uint16 k, uint16 j) { // 0x86827A - enemy_projectile_properties[k >> 1] &= ~0x4000u; - return j; -} - -uint16 EprojInstr_SetLowPriority(uint16 k, uint16 j) { // 0x868284 - enemy_projectile_properties[k >> 1] |= 0x1000u; - return j; -} - -uint16 EprojInstr_SetHighPriority(uint16 k, uint16 j) { // 0x86828E - enemy_projectile_properties[k >> 1] &= ~0x1000u; - return j; -} - -uint16 EprojInstr_SetXyRadius(uint16 k, uint16 j) { // 0x868298 - enemy_projectile_radius[k >> 1] = *(uint16 *)RomPtr_86(j); - return j + 2; -} - -uint16 EprojInstr_SetXyRadiusZero(uint16 k, uint16 j) { // 0x8682A1 - enemy_projectile_radius[k >> 1] = 0; - return j; -} - -uint16 EprojInstr_CalculateDirectionTowardsSamus(uint16 k, uint16 j) { // 0x8682A5 - int v2 = k >> 1; - R18_ = samus_x_pos - enemy_projectile_x_pos[v2]; - R20_ = samus_y_pos - enemy_projectile_y_pos[v2]; - uint16 v3 = 2 * CalculateAngleFromXY(); - int v4 = enemy_projectile_index >> 1; - enemy_projectile_E[v4] = v3; - int v5 = v3 >> 1; - enemy_projectile_x_vel[v4] = kSinCosTable8bit_Sext[v5 + 64]; - enemy_projectile_y_vel[v4] = kSinCosTable8bit_Sext[v5]; - return j; -} - -uint16 EprojInstr_WriteColorsToPalette(uint16 k, uint16 j) { // 0x8682D5 - const uint8 *v2 = RomPtr_86(j); - uint16 v3 = GET_WORD(v2 + 2); - R18_ = v2[4]; - uint16 v4 = GET_WORD(v2); - do { - palette_buffer[v3 >> 1] = *(uint16 *)RomPtr_86(v4); - v4 += 2; - v3 += 2; - --R18_; - } while ((R18_ & 0x8000u) == 0); - return j + 5; -} - -uint16 EprojInstr_QueueMusic(uint16 k, uint16 j) { // 0x8682FD - const uint8 *v2 = RomPtr_86(j); - QueueMusic_Delayed8(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx1_Max6(uint16 k, uint16 j) { // 0x868309 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx1_Max6(*v2); - return j + 1; -} -uint16 EprojInstr_QueueSfx2_Max6(uint16 k, uint16 j) { // 0x868312 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx2_Max6(*v2); - return j + 1; -} -uint16 EprojInstr_QueueSfx3_Max6(uint16 k, uint16 j) { // 0x86831B - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx3_Max6(*v2); - return j + 1; -} -uint16 EprojInstr_QueueSfx1_Max15(uint16 k, uint16 j) { // 0x868324 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx1_Max15(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx2_Max15(uint16 k, uint16 j) { // 0x86832D - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx2_Max15(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx3_Max15(uint16 k, uint16 j) { // 0x868336 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx3_Max15(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx1_Max3(uint16 k, uint16 j) { // 0x86833F - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx1_Max3(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx2_Max3(uint16 k, uint16 j) { // 0x868348 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx2_Max3(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx3_Max3(uint16 k, uint16 j) { // 0x868351 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx3_Max3(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx1_Max9(uint16 k, uint16 j) { // 0x86835A - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx1_Max9(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx2_Max9(uint16 k, uint16 j) { // 0x868363 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx2_Max9(*v2); - return j + 1; -} - -uint16 EprojInstr_QueueSfx3_Max9(uint16 k, uint16 j) { // 0x86836C - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx3_Max9(*v2); - return j + 1; -} -uint16 EprojInstr_QueueSfx1_Max1(uint16 k, uint16 j) { // 0x868375 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx1_Max1(*v2); - return j + 1; -} -uint16 EprojInstr_QueueSfx2_Max1(uint16 k, uint16 j) { // 0x86837E - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx2_Max1(*v2); - return j + 1; -} -uint16 EprojInstr_QueueSfx3_Max1(uint16 k, uint16 j) { // 0x868387 - const uint16 *v2 = (uint16 *)RomPtr_86(j); - QueueSfx3_Max1(*v2); - return j + 1; -} - -void DrawLowPriorityEnemyProjectiles(void) { // 0x868390 - GetValuesForScreenShaking(); - for (int i = 34; i >= 0; i -= 2) { - int v1 = i >> 1; - if (enemy_projectile_id[v1]) { - if ((enemy_projectile_properties[v1] & 0x1000) != 0) - DrawEnemyProjectiles(i); - } - } -} - -void DrawHighPriorityEnemyProjectiles(void) { // 0x8683B2 - GetValuesForScreenShaking(); - for (int i = 34; i >= 0; i -= 2) { - int v1 = i >> 1; - if (enemy_projectile_id[v1]) { - if ((enemy_projectile_properties[v1] & 0x1000) == 0) - DrawEnemyProjectiles(i); - } - } -} - -void DrawEnemyProjectiles(uint16 k) { // 0x8683D6 - int v1 = k >> 1; - uint16 v2 = enemy_projectile_spritemap_ptr[v1]; - R26_ = LOBYTE(enemy_projectile_gfx_idx[v1]); - R28_ = enemy_projectile_gfx_idx[v1] & 0xFF00; - R20_ = R36 + enemy_projectile_x_pos[v1] - layer1_x_pos; - if (((R20_ + 128) & 0xFE00) == 0) { - uint16 v3 = R34 + enemy_projectile_y_pos[v1] - layer1_y_pos; - R18_ = v3; - if ((v3 & 0xFF00) != 0) { - if (((v3 + 128) & 0xFE00) == 0) - DrawEnemyProjectileSpritemapWithBaseTileOffscreen(0x8D, v2); - } else { - DrawEnemyProjectileSpritemapWithBaseTile(0x8D, v2); - } - } -} - -void GetValuesForScreenShaking(void) { // 0x868427 - if (earthquake_timer && !time_is_frozen_flag && sign16(earthquake_type - 36)) { - int v0 = (uint16)(4 * earthquake_type) >> 1; - if ((earthquake_timer & 2) != 0) { - R36 = -kScreenShakeOffsets[v0]; - R34 = -kScreenShakeOffsets[v0 + 1]; - } else { - R36 = kScreenShakeOffsets[v0]; - R34 = kScreenShakeOffsets[v0 + 1]; - } - } else { - R34 = 0; - R36 = 0; - } -} - -uint8 EprojColl_8506(void) { // 0x868506 - uint8 t = BTS[cur_block_index]; - if (t) { - cur_block_index += (int8)t; - return 0xff; - } - return 0; -} - -uint8 EprojColl_Unknown8536(void) { // 0x86853C - if (BTS[cur_block_index]) { - uint16 v1; - if ((BTS[cur_block_index] & 0x80) != 0) { - uint16 temp_collision_DD4 = BTS[cur_block_index] | 0xFF00; - v1 = cur_block_index; - do { - v1 -= room_width_in_blocks; - ++temp_collision_DD4; - } while (temp_collision_DD4); - } else { - uint16 temp_collision_DD4 = BTS[cur_block_index]; - v1 = cur_block_index; - do { - v1 += room_width_in_blocks; - --temp_collision_DD4; - } while (temp_collision_DD4); - } - cur_block_index = v1; - return 0xff; - } - return 0; -} - -uint8 EprojColl_ClearCarry(void) { // 0x86858A - return 0; -} - -uint8 EprojColl_SetCarry(void) { // 0x86858C - return 1; -} - -uint8 EprojColl_858E(void) { // 0x86858E - uint16 v0 = BTS[cur_block_index] & 0x1F; - if (v0 < 5u) - return EprojColl_85C2(v0, cur_block_index); - current_slope_bts = BTS[cur_block_index]; - return EprojColl_873D(); -} - -uint8 EprojColl_85AD(void) { // 0x8685AD - uint16 v0 = BTS[cur_block_index] & 0x1F; - if (v0 >= 5u) - return EprojColl_874E(); - else - return EprojColl_8676(v0, cur_block_index, 0); -} - -static const uint8 unk_868729[20] = { // 0x8685C2 - 0, 1, 0x82, 0x83, 0, 0x81, 2, 0x83, 0, 1, 2, 0x83, 0, 0x81, 0x82, 0x83, - 0x80, 0x81, 0x82, 0x83, -}; - - - -uint8 EprojColl_85C2(uint16 a, uint16 k) { - - uint16 temp_collision_DD4 = 4 * a; - uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R34 & 8) >> 3)); - if (!R32_) { - int v3 = enemy_projectile_index >> 1; - if ((((uint8)enemy_projectile_y_pos[v3] - (uint8)R30_) & 8) != 0 - || CHECK_locret_868728(v2) >= 0) { - uint16 v4 = v2 ^ 2; - if ((((uint8)R30_ + (uint8)enemy_projectile_y_pos[v3] - 1) & 8) == 0 - || CHECK_locret_868728(v4) >= 0) { - return 0; - } - } - goto LABEL_17; - } - if (!R26_) { - if ((((uint8)R30_ + (uint8)enemy_projectile_y_pos[enemy_projectile_index >> 1] - 1) & 8) == 0) { - if (CHECK_locret_868728(v2) >= 0) - return 0; - goto LABEL_17; - } - goto LABEL_14; - } - if (R26_ != R32_ - || (((uint8)enemy_projectile_y_pos[enemy_projectile_index >> 1] - (uint8)R30_) & 8) == 0) { -LABEL_14: - if (CHECK_locret_868728(v2) < 0) - goto LABEL_17; - } - if (CHECK_locret_868728(v2 ^ 2) >= 0) - return 0; -LABEL_17:; - int v6 = enemy_projectile_index >> 1; - uint16 v7; - enemy_projectile_1A27[v6] = 0; - if ((R20_ & 0x8000u) != 0) - v7 = R28_ + (R34 | 7) + 1; - else - v7 = (R34 & 0xFFF8) - R28_; - enemy_projectile_x_pos[v6] = v7; - return 1; -} - -uint8 EprojColl_8676(uint16 a, uint16 k, uint16 j) { // 0x868676 - uint16 v2 = enemy_projectile_index; - - uint16 temp_collision_DD4 = 4 * a; - uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v3 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R34 & 8) >> 2)); - if (!R32_) { - printf("Y unknown!\n"); - int v4 = v2 >> 1; - if ((((uint8)enemy_projectile_x_pos[v4] - (uint8)R28_) & 8) != 0 - || CHECK_locret_868728(v3) >= 0) { - uint16 v5 = v3 ^ 1; - if ((((uint8)R28_ + (uint8)enemy_projectile_x_pos[v4] - 1) & 8) == 0 - || CHECK_locret_868728(v5) >= 0) { - return 0; - } - } - goto LABEL_17; - } - if (!R26_) { - if ((((uint8)R28_ + (uint8)enemy_projectile_x_pos[enemy_projectile_index >> 1] - 1) & 8) == 0) { - if (CHECK_locret_868728(v3) >= 0) - return 0; - goto LABEL_17; - } - goto LABEL_14; - } - if (R26_ != R32_ || (((uint8)enemy_projectile_x_pos[enemy_projectile_index >> 1] - (uint8)R28_) & 8) == 0) { -LABEL_14: - if (CHECK_locret_868728(v3) < 0) - goto LABEL_17; - } - if (CHECK_locret_868728(v3 ^ 1) >= 0) - return 0; -LABEL_17:; - int v7 = enemy_projectile_index >> 1; - uint16 v8; - enemy_projectile_y_subpos[v7] = 0; - if ((R20_ & 0x8000u) != 0) - v8 = R30_ + (R34 | 7) + 1; - else - v8 = (R34 & 0xFFF8) - R30_; - enemy_projectile_y_pos[v7] = v8; - return 1; -} - -uint8 EprojColl_873D(void) { // 0x86873D - return 0; -} - -uint8 EprojColl_874E(void) { // 0x86874E - int16 v3; - int16 v5; - uint16 v6; - uint16 v7; - int16 v8; - int16 v11; - int16 v12; - uint16 v13; - uint16 v14; - int16 v15; - - uint16 v0 = enemy_projectile_index; - if ((R20_ & 0x8000u) != 0) { - uint16 v9 = cur_block_index; - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - int v10 = v0 >> 1; - v11 = enemy_projectile_x_pos[v10] >> 4; - if (v11 == mod) { - uint16 temp_collision_DD4 = ((uint8)R24_ - (uint8)R30_) & 0xF ^ 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[v9] & 0x1F); - v12 = BTS[v9] << 8; - if (v12 < 0 - && ((v12 & 0x4000) != 0 ? (v13 = enemy_projectile_x_pos[v10] ^ 0xF) : (v13 = enemy_projectile_x_pos[v10]), - (v14 = temp_collision_DD6 + (v13 & 0xF), - v15 = (kAlignYPos_Tab0[v14] & 0x1F) - temp_collision_DD4 - 1, - (kAlignYPos_Tab0[v14] & 0x1F) - temp_collision_DD4 == 1) - || v15 < 0)) { - enemy_projectile_y_pos[v10] = R24_ - v15; - enemy_projectile_y_subpos[v10] = 0; - return 1; - } else { - return 0; - } - } else { - return 0; - } - } else { - uint16 v1 = cur_block_index; - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - int v2 = v0 >> 1; - v3 = enemy_projectile_x_pos[v2] >> 4; - if (v3 == mod) { - uint16 temp_collision_DD4 = ((uint8)R30_ + (uint8)R24_ - 1) & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[v1] & 0x1F); - v5 = BTS[v1] << 8; - if (v5 >= 0 - && ((v5 & 0x4000) != 0 ? (v6 = enemy_projectile_x_pos[v2] ^ 0xF) : (v6 = enemy_projectile_x_pos[v2]), - (v7 = temp_collision_DD6 + (v6 & 0xF), - v8 = (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 - 1, - (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 == 1) - || v8 < 0)) { - enemy_projectile_y_pos[v2] = R24_ + v8; - enemy_projectile_y_subpos[v2] = -1; - return 1; - } else { - return 0; - } - } else { - return 0; - } - } -} - -static Func_U8 *const kEnemyProjectileBlockCollisition_FuncA[16] = { // 0x868886 - EprojColl_ClearCarry, - EprojColl_858E, - EprojColl_ClearCarry, - EprojColl_ClearCarry, - EprojColl_ClearCarry, - EprojColl_8506, - EprojColl_ClearCarry, - EprojColl_ClearCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_Unknown8536, - EprojColl_ClearCarry, - EprojColl_SetCarry, -}; -static Func_U8 *const kEnemyProjectileBlockCollisition_FuncB[16] = { - EprojColl_ClearCarry, - EprojColl_85AD, - EprojColl_ClearCarry, - EprojColl_ClearCarry, - EprojColl_ClearCarry, - EprojColl_8506, - EprojColl_ClearCarry, - EprojColl_ClearCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_SetCarry, - EprojColl_Unknown8536, - EprojColl_ClearCarry, - EprojColl_SetCarry, -}; - -uint8 EnemyProjectileBlockCollisition_CheckHorizontal(uint16 k) { - uint8 rv; - cur_block_index = k >> 1; - do { - rv = kEnemyProjectileBlockCollisition_FuncA[(level_data[cur_block_index] & 0xF000) >> 12](); - } while (rv & 0x80); - return rv; -} - -uint8 EnemyProjectileBlockCollisition_CheckVertical(uint16 k) { // 0x86889E - uint8 rv; - cur_block_index = k >> 1; - do { - rv = kEnemyProjectileBlockCollisition_FuncB[(level_data[cur_block_index] & 0xF000) >> 12](); - } while (rv & 0x80); - return rv; -} - -uint8 EnemyProjectileBlockCollisition_Horiz(uint16 k) { // 0x8688B6 - int16 v2; - - R18_ = 0; - R20_ = 0; - int v1 = k >> 1; - v2 = enemy_projectile_x_vel[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - R30_ = HIBYTE(enemy_projectile_radius[v1]); - R28_ = LOBYTE(enemy_projectile_radius[v1]); - R26_ = (enemy_projectile_y_pos[v1] - R30_) & 0xFFF0; - R26_ = (uint16)(R30_ + enemy_projectile_y_pos[v1] - 1 - R26_) >> 4; - R32_ = R26_; - uint16 prod = Mult8x8((uint16)(enemy_projectile_y_pos[v1] - R30_) >> 4, room_width_in_blocks); - uint16 v3 = (__PAIR32__(R20_, R18_) + __PAIR32__(enemy_projectile_x_pos[v1], enemy_projectile_1A27[v1])) >> 16; - R22_ = R18_ + enemy_projectile_1A27[v1]; - R24_ = v3; - uint16 v4; - if ((R20_ & 0x8000u) != 0) - v4 = v3 - R28_; - else - v4 = R28_ + v3 - 1; - R34 = v4; - uint16 v5 = 2 * (prod + (v4 >> 4)); - while (!(EnemyProjectileBlockCollisition_CheckHorizontal(v5) & 1)) { - v5 += room_width_in_blocks * 2; - if ((--R26_ & 0x8000u) != 0) { - int v6 = k >> 1; - enemy_projectile_1A27[v6] = R22_; - enemy_projectile_x_pos[v6] = R24_; - return 0; - } - } - int v8 = k >> 1; - enemy_projectile_1A27[v8] = 0; - if ((R20_ & 0x8000u) != 0) { - uint16 v10 = R28_ + (R34 | 0xF) + 1; - if (v10 < enemy_projectile_x_pos[v8] || v10 == enemy_projectile_x_pos[v8]) - enemy_projectile_x_pos[v8] = v10; - return 1; - } else { - uint16 v9 = (R34 & 0xFFF0) - R28_; - if (v9 >= enemy_projectile_x_pos[v8]) - enemy_projectile_x_pos[v8] = v9; - return 1; - } -} - -uint8 EnemyProjectileBlockCollisition_Vertical(uint16 k) { // 0x86897B - int16 v2; - int16 v5; - - R18_ = 0; - R20_ = 0; - int v1 = k >> 1; - v2 = enemy_projectile_y_vel[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - R30_ = HIBYTE(enemy_projectile_radius[v1]); - R28_ = LOBYTE(enemy_projectile_radius[v1]); - R26_ = (enemy_projectile_x_pos[v1] - R28_) & 0xFFF0; - R26_ = (uint16)(R28_ + enemy_projectile_x_pos[v1] - 1 - R26_) >> 4; - R32_ = R26_; - uint16 v3 = (__PAIR32__(R20_, R18_) + __PAIR32__(enemy_projectile_y_pos[v1], enemy_projectile_y_subpos[v1])) >> 16; - R22_ = R18_ + enemy_projectile_y_subpos[v1]; - R24_ = v3; - uint16 v4; - if ((R20_ & 0x8000u) != 0) - v4 = v3 - R30_; - else - v4 = R30_ + v3 - 1; - R34 = v4; - uint16 prod = Mult8x8(v4 >> 4, room_width_in_blocks); - v5 = (uint16)(enemy_projectile_x_pos[v1] - R28_) >> 4; - for (int i = 2 * (prod + v5); !(EnemyProjectileBlockCollisition_CheckVertical(i) & 1); i += 2) { - if ((--R26_ & 0x8000u) != 0) { - int v7 = k >> 1; - enemy_projectile_y_subpos[v7] = R22_; - enemy_projectile_y_pos[v7] = R24_; - return 0; - } - } - int v9 = k >> 1; - enemy_projectile_y_subpos[v9] = 0; - if ((R20_ & 0x8000u) != 0) { - uint16 v11 = R30_ + (R34 | 0xF) + 1; - if (v11 < enemy_projectile_y_pos[v9] || v11 == enemy_projectile_y_pos[v9]) - enemy_projectile_y_pos[v9] = v11; - return 1; - } else { - uint16 v10 = (R34 & 0xFFF0) - R30_; - if (v10 >= enemy_projectile_y_pos[v9]) - enemy_projectile_y_pos[v9] = v10; - return 1; - } -} - -void EnemyProj_Init_0x8aaf(uint16 j) { // 0x868A39 - NextRandom(); - EnemyData *v1 = gEnemyData(cur_enemy_index); - uint16 v2 = v1->y_pos + 12; - int v3 = j >> 1; - enemy_projectile_y_pos[v3] = v2; - enemy_projectile_timers[v3] = v2 + 72; - enemy_projectile_y_vel[v3] = v1->ai_var_D; - enemy_projectile_x_pos[v3] = v1->x_pos + (random_number & 0x1F) - 16; - enemy_projectile_instr_list_ptr[v3] = off_868A75[(uint16)(HIBYTE(enemy_projectile_y_vel[v3]) & 6) >> 1]; -} - -void EnemyProj_PreInit_0x8aaf(uint16 k) { // 0x868A7D - int v1 = k >> 1; - R20_ = LOBYTE(enemy_projectile_y_vel[v1]) << 8; - R18_ = (int8)HIBYTE(enemy_projectile_y_vel[v1]); - uint16 v3 = enemy_projectile_y_subpos[v1]; - bool v4 = __CFADD__uint16(R20_, v3); - enemy_projectile_y_subpos[v1] = R20_ + v3; - uint16 v5 = R18_ + v4 + enemy_projectile_y_pos[v1]; - enemy_projectile_y_pos[v1] = v5; - if (v5 >= enemy_projectile_timers[v1]) - enemy_projectile_id[v1] = 0; -} - -void EnemyProj_Init_0x8bc2_SkreeDownRight(uint16 j) { // 0x868ACD - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos; - enemy_projectile_y_vel[v2] = -769; - enemy_projectile_x_pos[v2] = v1->x_pos + 6; - enemy_projectile_x_vel[v2] = 320; -} - -void EnemyProj_Init_0x8bd0_SkreeUpRight(uint16 j) { // 0x868AF1 - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos; - enemy_projectile_y_vel[v2] = -1025; - enemy_projectile_x_pos[v2] = v1->x_pos + 6; - enemy_projectile_x_vel[v2] = 96; -} - -void EnemyProj_Init_0x8bde_SkreeDownLeft(uint16 j) { // 0x868B15 - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos; - enemy_projectile_y_vel[v2] = -769; - enemy_projectile_x_pos[v2] = v1->x_pos - 6; - enemy_projectile_x_vel[v2] = -320; -} - -void EnemyProj_Init_0x8bec_SkreeUpLeft(uint16 j) { // 0x868B39 - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos; - enemy_projectile_y_vel[v2] = -1025; - enemy_projectile_x_pos[v2] = v1->x_pos - 6; - enemy_projectile_x_vel[v2] = -96; -} - -void EnemyProj_PreInstr_SkreeParticle(uint16 k) { // 0x868B5D - int v1 = k >> 1; - R20_ = LOBYTE(enemy_projectile_x_vel[v1]) << 8; - R18_ = (int8)HIBYTE(enemy_projectile_x_vel[v1]); - uint16 v4 = enemy_projectile_1A27[v1]; - bool v3 = __CFADD__uint16(R20_, v4); - enemy_projectile_1A27[v1] = R20_ + v4; - enemy_projectile_x_pos[v1] += R18_ + v3; - R20_ = LOBYTE(enemy_projectile_y_vel[v1]) << 8; - R18_ = (int8)HIBYTE(enemy_projectile_y_vel[v1]); - uint16 v5 = enemy_projectile_y_subpos[v1]; - v3 = __CFADD__uint16(R20_, v5); - enemy_projectile_y_subpos[v1] = R20_ + v5; - enemy_projectile_y_pos[v1] += R18_ + v3; - enemy_projectile_y_vel[v1] += 80; - if (CheckIfEnemyProjectileIsOffScreen(k)) - enemy_projectile_id[v1] = 0; -} - -uint16 EprojInstr_SpawnEnemyDropsWithDraygonsEyeDrops(uint16 k, uint16 j) { // 0x868C68 - int v1 = k >> 1; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyDrops(addr_kEnemyDef_DE7F, k); - return j; -} - -uint16 EprojInstr_SetPreInstrA(uint16 k, uint16 j) { // 0x868CF6 - enemy_projectile_pre_instr[k >> 1] = FUNC16(EprojPreInstr_DraygonsTurret_8DFF); - return j; -} - -uint16 EprojInstr_SetPreInstrB(uint16 k, uint16 j) { // 0x868CFD - enemy_projectile_pre_instr[k >> 1] = FUNC16(EprojPreInstr_8DCA); - return j; -} - -void EprojInit_DraygonsGunk(uint16 j) { // 0x868D04 - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = R18_; - enemy_projectile_y_pos[v1] = R20_; - uint16 v2 = enemy_projectile_unk1995; - g_word_7E97DC[v1] = enemy_projectile_unk1995; - R18_ = v2; - R20_ = enemy_projectile_init_param; - ConvertAngleToXy(); - enemy_projectile_x_vel[v1] = R22_; - enemy_projectile_E[v1] = R24_; - enemy_projectile_y_vel[v1] = R26_; - enemy_projectile_F[v1] = R28_; - enemy_projectile_gfx_idx[v1] = 1024; -} - -void EprojInit_DraygonsWallTurretProjs(uint16 j) { // 0x868D40 - Eproj_AngleToSamus(j); - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 2560; - enemy_projectile_pre_instr[v1] = FUNC16(nullsub_84); -} - -uint16 EprojInstr_868D55(uint16 k, uint16 j) { // 0x868D55 - enemy_projectile_id[j >> 1] = 0; - return j; -} - -void EprojPowerBombCollision(uint16 k) { // 0x868D5C - R18_ = HIBYTE(power_bomb_explosion_radius); - if (HIBYTE(power_bomb_explosion_radius)) { - R20_ = (uint16)(R18_ + (HIBYTE(power_bomb_explosion_radius) & 1) + (power_bomb_explosion_radius >> 9)) >> 1; - int v1 = k >> 1; - if (abs16(power_bomb_explosion_x_pos - enemy_projectile_x_pos[v1]) < R18_ - && abs16(power_bomb_explosion_y_pos - enemy_projectile_y_pos[v1]) < R20_) { - enemy_projectile_id[v1] = 0; - samus_x_speed_divisor = 0; - } - } -} - -uint16 EprojInstr_868D99(uint16 k, uint16 j) { // 0x868D99 - EprojPowerBombCollision(k); - uint16 v2 = samus_x_speed_divisor + 1; - if (sign16(samus_x_speed_divisor - 5)) { - ++samus_x_speed_divisor; - int v3 = k >> 1; - enemy_projectile_F[v3] = v2; - enemy_projectile_E[v3] = 256; - enemy_projectile_pre_instr[v3] = FUNC16(EprojPreInstr_8DCA); - enemy_projectile_properties[v3] = enemy_projectile_properties[v3] & 0x5FFF | 0x2000; - samus_invincibility_timer = 0; - samus_knockback_timer = 0; - } - return j; -} - -void EprojPreInstr_8DCA(uint16 k) { // 0x868DCA - int v1; - - EprojPowerBombCollision(k); - if (samus_contact_damage_index - || (v1 = k >> 1, - enemy_projectile_x_pos[v1] = samus_x_pos, - enemy_projectile_y_pos[v1] = samus_y_pos + 4 * enemy_projectile_F[v1] - 12, - --enemy_projectile_E[v1], - !enemy_projectile_E[v1])) { - enemy_projectile_id[k >> 1] = 0; - if ((--samus_x_speed_divisor & 0x8000u) != 0) - samus_x_speed_divisor = 0; - } -} - -void EprojPreInstr_DraygonsTurret_8DFF(uint16 k) { // 0x868DFF - int16 v1; - - EprojPowerBombCollision(k); - Eproj_FuncE73E_MoveXY(k); - v1 = Eproj_FuncE722(k); - if (v1) - enemy_projectile_id[k >> 1] = 0; -} - -void EprojPreInstr_DraygonsGunk_8E0F(uint16 k) { // 0x868E0F - uint16 v3; - - EprojPowerBombCollision(k); - Eproj_FuncE73E_MoveXY(k); - int v1 = k >> 1; - uint16 v2 = abs16(samus_x_pos - enemy_projectile_x_pos[v1]); - if (sign16(v2 - 16) && (v3 = abs16(samus_y_pos - enemy_projectile_y_pos[v1]), sign16(v3 - 20))) { - enemy_projectile_instr_list_ptr[v1] = 0x8C38; - enemy_projectile_instr_timers[v1] = 1; - } else { - if (Eproj_FuncE722(k)) - enemy_projectile_id[v1] = 0; - } -} - -void EprojInit_8E6C(uint16 j) { // 0x868E7A - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 1008; - enemy_projectile_x_pos[v1] = R18_; - enemy_projectile_y_pos[v1] = R20_; - enemy_projectile_instr_list_ptr[v1] = addr_word_868EDF; - enemy_projectile_instr_timers[v1] = 1; -} - -void EprojPreInstr_8E6C(uint16 k) { // 0x868E99 - R18_ = enemy_data[0].x_pos - R18_; - R20_ = enemy_data[0].y_pos - R20_; - uint16 v1 = (uint8)(64 - CalculateAngleFromXY()); - int v2 = k >> 1; - g_word_7E97DC[v2] = v1; - R18_ = v1; - R20_ = 1; - ConvertAngleToXy(); - enemy_projectile_x_vel[v2] = R22_; - enemy_projectile_E[v2] = R24_; - enemy_projectile_y_vel[v2] = R26_; - enemy_projectile_F[v2] = R28_; - Eproj_FuncE73E_MoveXY(k); -} - -void EprojInit_CrocomireProjectile(uint16 j) { // 0x869023 - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = -512; - enemy_projectile_y_vel[v2] = 1; - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos - 32; - enemy_projectile_y_pos[v2] = v3->y_pos - 16; - enemy_projectile_timers[v2] = 0; - enemy_projectile_1A27[v2] = 0; - enemy_projectile_y_subpos[v2] = 0; - enemy_projectile_gfx_idx[v2] = 2560; -} - -static const int16 word_869059[9] = { -16, 0, 32, -16, 0, 32, -16, 0, 32 }; // bug: oob read -void EprojPreInstr_CrocomireProjectile(uint16 k) { // 0x86906B - EnemyProjectileBlockCollisition_Horiz(k); - enemy_projectile_gfx_idx[0] = 2560; - enemy_projectile_timers[k >> 1] += enemy_projectile_x_vel[k >> 1]; - R18_ = -64; - R20_ = g_word_869059[enemy_data[0].ai_preinstr >> 1]; // bug: out of bounds read... - int v1 = (uint16)(2 * CalculateAngleFromXY()) >> 1; - R18_ = kSinCosTable8bit_Sext[v1 + 64]; - int v2 = k >> 1; - enemy_projectile_x_vel[v2] = 4 * R18_; - R18_ = kSinCosTable8bit_Sext[v1]; - enemy_projectile_y_vel[v2] = 4 * R18_; - enemy_projectile_pre_instr[v2] = FUNC16(sub_8690B3); -} - -void sub_8690B3(uint16 k) { // 0x8690B3 - if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) - enemy_projectile_id[k >> 1] = 0; -} - -void EprojInit_CrocomireSpikeWallPieces(uint16 j) { // 0x8690CF - int v1 = j >> 1; - enemy_projectile_y_pos[v1] = word_869105[(uint16)(j - 20) >> 1]; - enemy_projectile_x_pos[v1] = 528; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_E[v1] = 0; - enemy_projectile_F[v1] = 0; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_y_subpos[v1] = 0; - enemy_projectile_y_vel[v1] = -5; - enemy_projectile_F[v1] = -30720; -} - -static const uint16 CrocomireSpikeWallPieces_Tab2[18] = { // 0x869115 - 0, 0, 0xff0, 0xee0, 0xcc0, 0xaa0, 0x880, 0x660, 0x440, 0x220, 0xff0, 0xee0, - 0xcc0, 0xaa0, 0x880, 0x660, 0x440, 0x220, -}; -static const uint16 CrocomireSpikeWallPieces_Tab1[18] = { - 0, 0, 0xff00, 0xee00, 0xcc00, 0xaa00, 0x8800, 0x6600, 0x4400, 0x2200, 0xff00, 0xee00, - 0xcc00, 0xaa00, 0x8800, 0x6600, 0x4400, 0x2200, -}; -static const int8 CrocomireSpikeWallPieces_Tab3[36] = { - 0, 0, 0, 0, 4, 0, 4, 0, 3, 0, 3, 0, - 2, 0, 2, 0, 1, 0, 1, 0, 6, 0, 5, 0, - 4, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1, 0, -}; - -void EprojPreInstr_CrocomireSpikeWallPieces(uint16 k) { - int8 v3; - int8 v6; - int8 v7; - int8 v8; - - int v1 = k >> 1; - uint16 v2 = enemy_projectile_E[v1]; - if (v2 != CrocomireSpikeWallPieces_Tab1[v1]) { - v2 += CrocomireSpikeWallPieces_Tab2[v1]; - if (v2 >= CrocomireSpikeWallPieces_Tab1[v1]) - v2 = CrocomireSpikeWallPieces_Tab1[v1]; - } - enemy_projectile_E[v1] = v2; - v3 = *((uint8 *)enemy_projectile_E + k + 1); - bool v4 = __CFADD__uint8(*((uint8 *)enemy_projectile_x_vel + k), v3); - *((uint8 *)enemy_projectile_x_vel + k) += v3; - uint8 v5 = v4 + *((uint8 *)enemy_projectile_x_vel + k + 1); - if ((int8)(v5 - CrocomireSpikeWallPieces_Tab3[k]) >= 0) - v5 = CrocomireSpikeWallPieces_Tab3[k]; - *((uint8 *)enemy_projectile_x_vel + k + 1) = v5; - v6 = *((uint8 *)enemy_projectile_x_vel + k); - v4 = __CFADD__uint8(*((uint8 *)enemy_projectile_1A27 + k + 1), v6); - *((uint8 *)enemy_projectile_1A27 + k + 1) += v6; - v7 = *((uint8 *)enemy_projectile_x_vel + k + 1); - bool v9 = v4; - v4 = __CFADD__uint8(v4, v7); - v8 = v9 + v7; - v4 |= __CFADD__uint8(*((uint8 *)enemy_projectile_x_pos + k), v8); - *((uint8 *)enemy_projectile_x_pos + k) += v8; - *((uint8 *)enemy_projectile_x_pos + k + 1) += v4; - uint16 v10 = enemy_projectile_F[v1]; - enemy_projectile_F[v1] = v10 + 12288; - enemy_projectile_y_vel[v1] += __CFADD__uint16(v10, 12288); - uint16 v11 = enemy_projectile_y_subpos[v1]; - v4 = __CFADD__uint16(enemy_projectile_F[v1], v11); - enemy_projectile_y_subpos[v1] = enemy_projectile_F[v1] + v11; - enemy_projectile_y_pos[v1] += enemy_projectile_y_vel[v1] + v4; - if (enemy_projectile_y_pos[v1] >= 0xA8u) { - enemy_projectile_id[v1] = 0; - if ((k & 2) == 0) - QueueSfx2_Max6(0x29u); - int v12 = k >> 1; - R18_ = enemy_projectile_x_pos[v12]; - R20_ = enemy_projectile_y_pos[v12]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); - QueueSfx2_Max6(0x25u); - } -} - -uint16 EprojInstr_9270(uint16 v0, uint16 j) { // 0x869270 - int v1 = v0 >> 1; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyDrops(addr_kEnemyDef_DDBF, v0); - return j; -} - -void EprojInit_CrocomireBridgeCrumbling(uint16 j) { // 0x869286 - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = enemy_projectile_init_param; - enemy_projectile_y_pos[v1] = 187; - enemy_projectile_y_subpos[v1] = 0; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = (random_number & 0x3F) + 64; - enemy_projectile_gfx_idx[v1] = 1024; -} - -void EprojPreInstr_CrocomireBridgeCrumbling(uint16 k) { // 0x8692BA - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) - enemy_projectile_id[k >> 1] = 0; - else - enemy_projectile_y_vel[k >> 1] = (enemy_projectile_y_vel[k >> 1] + 24) & 0x3FFF; -} - -uint16 MoveEprojWithVelocity(uint16 k) { // 0x8692D6 - int v1 = k >> 1; - uint16 v2 = enemy_projectile_x_vel[v1]; - int carry = *((uint8 *)enemy_projectile_1A27 + k + 1) + (v2 & 0xff); - *((uint8 *)enemy_projectile_1A27 + k + 1) = carry; - enemy_projectile_x_pos[v1] += (int8)(v2 >> 8) + (carry >> 8); - return MoveEprojWithVelocityY(k); -} - -uint16 MoveEprojWithVelocityY(uint16 k) { // 0x8692F3 - int v1 = k >> 1; - uint16 v2 = enemy_projectile_y_vel[v1]; - int carry = *((uint8 *)enemy_projectile_y_subpos + k + 1) + (v2 & 0xff); - *((uint8 *)enemy_projectile_y_subpos + k + 1) = carry; - uint16 result = enemy_projectile_y_pos[v1] + (int8)(v2 >> 8) + (carry >> 8); - enemy_projectile_y_pos[v1] = result; - return result; -} - -uint16 MoveEprojWithVelocityX(uint16 k) { // 0x869311 - int v1 = k >> 1; - uint16 v2 = enemy_projectile_x_vel[v1]; - int carry = *((uint8 *)enemy_projectile_1A27 + k + 1) + (v2 & 0xff); - *((uint8 *)enemy_projectile_1A27 + k + 1) = carry; - uint16 result = enemy_projectile_x_pos[v1] + (int8)(v2 >> 8) + (carry >> 8); - enemy_projectile_x_pos[v1] = result; - return result; -} - -void SetAreaDependentEprojPropertiesEx(uint16 k, uint16 j) { // 0x86932F - uint16 v2; - uint16 *p = (uint16 *)RomPtr_86(k); - if (area_index == 2) { - v2 = p[1]; - } else if (area_index == 5) { - v2 = p[2]; - } else { - v2 = p[0]; - } - enemy_projectile_properties[j >> 1] = v2; -} - -static const int16 kEprojInit_9634_Xvel[4] = { -0x200, -0x1f0, -0x1bc, -0x16a }; -static const int16 kEprojInit_9634_Yvel[4] = { 0, 0x88, 0xfc, 0x16a }; - -void EprojInit_9634(uint16 j) { // 0x86934D - int v1 = j >> 1; - enemy_projectile_E[v1] = 0; - enemy_projectile_F[v1] = 0; - enemy_projectile_x_pos[v1] = enemy_data[0].x_pos - 29; - enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - 35; - enemy_projectile_gfx_idx[v1] = 2560; - int v2 = (uint16)(2 * enemy_data[0].parameter_1) >> 1; - enemy_projectile_x_vel[v1] = kEprojInit_9634_Xvel[v2]; - enemy_projectile_y_vel[v1] = kEprojInit_9634_Yvel[v2]; -} - -void EprojPreInstr_9634(uint16 k) { // 0x869392 - int v1 = k >> 1; - if (enemy_projectile_E[v1] >= 8u) { - MoveEprojWithVelocity(k); - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - enemy_projectile_instr_list_ptr[v1] = addr_off_869574; - ++enemy_projectile_E[v1]; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_gfx_idx[v1] = 2560; - QueueSfx2_Max6(0x2Bu); - } - } else { - ++enemy_projectile_E[v1]; - } -} - -void EprojInit_9642_RidleysFireball(uint16 j) { // 0x8693CA - int16 v2; - - int v1 = j >> 1; - enemy_projectile_F[v1] = enemy_projectile_unk1995; - if (enemy_projectile_init_param) - v2 = 25; - else - v2 = -25; - enemy_projectile_x_pos[v1] = enemy_data[0].x_pos + v2; - enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - 43; - enemy_projectile_gfx_idx[v1] = 2560; - - Ram7800_Default *v4 = gRam7800_Default(0); - enemy_projectile_x_vel[v1] = v4->var_19; - enemy_projectile_y_vel[v1] = v4->var_1A; - SetAreaDependentEprojPropertiesEx(addr_kRidleysFireball_Tab0, j); -} - -void SetAreaDependentEprojProperties(uint16 j) { // 0x869402 - SetAreaDependentEprojPropertiesEx(addr_kRidleysFireball_Tab0, j); -} - -void EprojPreInstr_9642_RidleysFireball(uint16 k) { // 0x86940E - uint16 v1; - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { - v1 = -27042; - } else { - if (!(EnemyProjectileBlockCollisition_Vertical(k) & 1)) - return; - v1 = -27056; - } - int v2 = k >> 1; - enemy_projectile_id[v2] = 0; - if (!enemy_projectile_F[v2]) { - R18_ = enemy_projectile_x_pos[v2]; - R20_ = enemy_projectile_y_pos[v2]; - SpawnEnemyProjectileWithRoomGfx(v1, 3u); - QueueSfx2_Max6(0x2Bu); - } -} - -uint16 EprojInstr_DisableCollisionsWithSamus(uint16 k, uint16 j) { // 0x869475 - enemy_projectile_properties[k >> 1] |= 0x2000u; - return j; -} - -void EprojInit_9660_FireballExplosion(uint16 j) { // 0x86947F - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 2560; - enemy_projectile_x_pos[v1] = R18_; - enemy_projectile_y_pos[v1] = R20_; - enemy_projectile_E[v1] = enemy_projectile_init_param; - enemy_projectile_F[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; -} - -void EprojInit_9688(uint16 j) { // 0x8694A0 - uint16 v1 = enemy_projectile_init_param; - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = 0; - enemy_projectile_y_vel[v2] = -3584; - EprojInit_Common(j, v1, 0x9688); -} - -void EprojInit_9696(uint16 j) { // 0x8694B4 - uint16 v1 = enemy_projectile_init_param; - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = 0; - enemy_projectile_y_vel[v2] = 3584; - EprojInit_Common(j, v1, 0x9696); -} - -void EprojInit_966C(uint16 j) { // 0x8694C8 - uint16 v1 = enemy_projectile_init_param; - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = 3584; - enemy_projectile_y_vel[v2] = 0; - EprojInit_Common(j, v1, 0x966C); -} - -void EprojInit_967A(uint16 j) { // 0x8694DC - uint16 v1 = enemy_projectile_init_param; - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = -3584; - enemy_projectile_y_vel[v2] = 0; - EprojInit_Common(j, v1, 0x967A); -} - -void EprojInit_Common(uint16 j, uint16 k, uint16 a) { // 0x8694EE - int v3 = j >> 1; - enemy_projectile_F[v3] = a; - int v4 = k >> 1; - enemy_projectile_x_pos[v3] = enemy_projectile_x_pos[v4]; - enemy_projectile_y_pos[v3] = enemy_projectile_y_pos[v4]; - enemy_projectile_E[v3] = enemy_projectile_E[v4]; - enemy_projectile_gfx_idx[v3] = 2560; - SetAreaDependentEprojProperties(j); -} - -void EprojPreInstr_966C(uint16 k) { // 0x86950D - MoveEprojWithVelocityX(k); - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - int v1 = k >> 1; - enemy_projectile_instr_list_ptr[v1] = addr_off_869574; - enemy_projectile_instr_timers[v1] = 1; - } -} - -void EprojPreInstr_9688(uint16 k) { // 0x869522 - MoveEprojWithVelocityY(k); - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { - int v1 = k >> 1; - enemy_projectile_instr_list_ptr[v1] = addr_off_869574; - enemy_projectile_instr_timers[v1] = 1; - } -} - -void EprojPreInstr_96A4(uint16 k) { // 0x869537 - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) - enemy_projectile_id[k >> 1] = 0; -} - -void EprojPreInstr_96C0(uint16 k) { // 0x869540 - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) - enemy_projectile_id[k >> 1] = 0; -} - -void EprojPreInstr_96CE(uint16 k) { // 0x869549 - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) - enemy_projectile_id[k >> 1] = 0; -} - -uint16 EprojInstr_95BA(uint16 k, uint16 j) { // 0x8695BA - enemy_projectile_unk1995 = 0; - SpawnEnemyProjectileWithRoomGfx(addr_stru_86966C, k); - enemy_projectile_unk1995 = 0; - SpawnEnemyProjectileWithRoomGfx(addr_stru_86967A, k); - return j; -} - -uint16 EprojInstr_95ED(uint16 k, uint16 j) { // 0x8695ED - enemy_projectile_unk1995 = 0; - SpawnEnemyProjectileWithRoomGfx(addr_stru_869688, k); - enemy_projectile_unk1995 = 0; - SpawnEnemyProjectileWithRoomGfx(addr_stru_869696, k); - return j; -} - -uint16 EprojInstr_9620(uint16 k, uint16 j) { // 0x869620 - if ((int8)-- * ((uint8 *)enemy_projectile_E + k) >= 0) - SpawnEnemyProjectileWithRoomGfx(enemy_projectile_F[k >> 1], k); - return j; -} - -void EprojInit_9734_CeresFallingDebris(uint16 j) { // 0x8696DC - int v1 = j >> 1; - enemy_projectile_E[v1] = 0; - enemy_projectile_F[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_gfx_idx[v1] = 3584; - enemy_projectile_x_pos[v1] = enemy_projectile_init_param; - enemy_projectile_y_pos[v1] = 42; - enemy_projectile_y_vel[v1] = 16; -} - -void EprojPreInstr_9734_CeresFallingDebris(uint16 k) { // 0x869701 - int v1 = k >> 1; - enemy_projectile_y_vel[v1] += 16; - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - enemy_projectile_id[v1] = 0; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); - QueueSfx2_Max6(0x6Du); - } -} - -uint16 EprojInstr_980E(uint16 k, uint16 j) { // 0x86980E - int v2 = k >> 1; - R18_ = enemy_projectile_x_pos[v2]; - R20_ = enemy_projectile_y_pos[v2]; - SpawnEnemyDrops(addr_kEnemyDef_E4FF, k); - return j; -} - -static const uint8 byte_8698B4[16] = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0xf0, 0xe0, 0xd0, 0xc0, 0xb0, 0xa0, 0x90, 0x80 }; -static const uint8 byte_8698F7[9] = { 0x30, 0x44, 0x58, 0x6c, 0x80, 0x94, 0xa8, 0xbc, 0xd0 }; -static const uint8 byte_869979[8] = { 0, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 }; - - -void EprojInit_PhantoonDestroyableFireballs(uint16 j) { // 0x869824 - int8 v1; - - v1 = (uint16)(enemy_projectile_init_param & 0xFF00) >> 8; - if (v1) { - switch (v1) { - case 2: { - int v3 = j >> 1; - enemy_projectile_1A27[v3] = 0; - enemy_projectile_y_subpos[v3] = 0; - enemy_projectile_y_vel[v3] = 0; - uint16 v4 = (uint8)enemy_projectile_init_param; - if ((int16)((uint8)enemy_projectile_init_param - 8) >= 0) - enemy_projectile_x_vel[v3] = -2; - else - enemy_projectile_x_vel[v3] = 2; - enemy_projectile_E[v3] = byte_8698B4[v4]; - enemy_projectile_x_pos[v3] = enemy_data[0].x_pos; - enemy_projectile_y_pos[v3] = enemy_data[0].y_pos + 32; - enemy_projectile_pre_instr[v3] = FUNC16(EprojPreInstr_PhantoonDestroyableFireballs); - break; - } - case 4: { - int v5 = j >> 1; - enemy_projectile_1A27[v5] = 0; - enemy_projectile_y_subpos[v5] = 0; - enemy_projectile_y_vel[v5] = 0; - uint16 v6 = enemy_projectile_init_param & 0xF; - enemy_projectile_x_vel[v5] = (uint8)(enemy_projectile_init_param & 0xF0) >> 1; - enemy_projectile_x_pos[v5] = byte_8698F7[v6]; - enemy_projectile_y_pos[v5] = 40; - enemy_projectile_pre_instr[v5] = FUNC16(EprojPreInstr_PhantoonDestroyableFireballs_2); - break; - } - case 6: { - int v7 = j >> 1; - enemy_projectile_1A27[v7] = 0; - enemy_projectile_y_subpos[v7] = 0; - enemy_projectile_y_vel[v7] = 0; - enemy_projectile_x_vel[v7] = 128; - enemy_projectile_E[v7] = byte_869979[(uint8)enemy_projectile_init_param]; - enemy_projectile_x_pos[v7] = enemy_data[0].x_pos; - enemy_projectile_y_pos[v7] = enemy_data[0].y_pos + 16; - enemy_projectile_pre_instr[v7] = FUNC16(EprojPreInstr_PhantoonDestroyableFireballs_3); - break; - } - default: - Unreachable(); - while (1) - ; - } - } else { - int v2 = j >> 1; - enemy_projectile_1A27[v2] = 0; - enemy_projectile_y_subpos[v2] = 0; - enemy_projectile_x_vel[v2] = 0; - enemy_projectile_y_vel[v2] = 0; - enemy_projectile_x_pos[v2] = enemy_data[0].x_pos; - enemy_projectile_y_pos[v2] = enemy_data[0].y_pos + 32; - enemy_projectile_instr_list_ptr[v2] = addr_off_8697B4; - enemy_projectile_properties[v2] = enemy_projectile_properties[v2] & 0xFFF | 0x2000; - } -} - -void EprojInit_PhantoonStartingFireballs(uint16 j) { // 0x86993A - int v1 = j >> 1; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_y_subpos[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - uint16 v2 = byte_869979[enemy_projectile_init_param]; - enemy_projectile_E[v1] = v2; - Eproj_PhantomFireballs_Func1(v2, 0x30); - enemy_projectile_x_pos[v1] = R20_ + enemy_data[0].x_pos; - enemy_projectile_y_pos[v1] = R22_ + enemy_data[0].y_pos + 16; -} - -void EprojPreInstr_PhantoonStartingFireballs(uint16 k) { // 0x869981 - int v1 = k >> 1; - enemy_projectile_y_vel[v1] += 16; - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - enemy_projectile_properties[v1] = enemy_projectile_properties[v1] & 0xFFF | 0x8000; - enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_PhantoonStartingFireballs2); - enemy_projectile_instr_list_ptr[v1] = addr_word_86976C; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_E[v1] = 8; - enemy_projectile_y_pos[v1] += 8; - } -} - -void EprojPreInstr_PhantoonStartingFireballs2(uint16 k) { // 0x8699BF - int v1 = k >> 1; - bool v2 = enemy_projectile_E[v1] == 1; - bool v3 = (--enemy_projectile_E[v1] & 0x8000u) != 0; - if (v2 || v3) { - enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_PhantoonStartingFireballs3); - enemy_projectile_instr_list_ptr[v1] = addr_word_869772; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_y_pos[v1] -= 8; - enemy_projectile_y_vel[v1] = -768; - enemy_projectile_E[v1] = 0; - if ((nmi_frame_counter_word & 1) != 0) - enemy_projectile_x_vel[v1] = -128; - else - enemy_projectile_x_vel[v1] = 128; - } -} - -static const uint16 word_869A3E[3] = { 0xfd00, 0xfe00, 0xff00 }; - -void EprojPreInstr_PhantoonStartingFireballs3(uint16 k) { // 0x869A01 - int v1 = k >> 1; - enemy_projectile_y_vel[v1] += 16; - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - uint16 v2 = enemy_projectile_E[v1] + 1; - enemy_projectile_E[v1] = v2; - if (sign16(v2 - 3)) { - enemy_projectile_y_vel[v1] = word_869A3E[v2]; - return; - } - goto LABEL_6; - } - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { -LABEL_6: - enemy_projectile_instr_list_ptr[v1] = addr_word_869782; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_pre_instr[v1] = FUNC16(nullsub_86); - } -} - -void EprojPreInstr_PhantoonDestroyableFireballs(uint16 k) { // 0x869A45 - int16 v4; - uint16 v5; - int v1 = k >> 1; - enemy_projectile_y_vel[v1] += 4; - uint16 v2 = (uint8)(LOBYTE(enemy_projectile_x_vel[v1]) + enemy_projectile_E[v1]); - enemy_projectile_E[v1] = v2; - Eproj_PhantomFireballs_Func1(v2, enemy_projectile_y_vel[v1]); - bool v3 = (int16)(R20_ + enemy_data[0].x_pos) < 0; - v4 = R20_ + enemy_data[0].x_pos; - enemy_projectile_x_pos[v1] = R20_ + enemy_data[0].x_pos; - if (v3 - || !sign16(v4 - 256) - || (v3 = (int16)(R22_ + enemy_data[0].y_pos + 16) < 0, - v5 = R22_ + enemy_data[0].y_pos + 16, - enemy_projectile_y_pos[v1] = v5, - v3) - || !sign16(v5 - 256)) { - enemy_projectile_instr_list_ptr[v1] = addr_off_8697F8; - enemy_projectile_instr_timers[v1] = 1; - } -} - -void EprojPreInstr_PhantoonDestroyableFireballs_2(uint16 k) { // 0x869A94 - int v1 = k >> 1; - if (!enemy_projectile_x_vel[v1]) - goto LABEL_5; - bool v2, v3; - v2 = enemy_projectile_x_vel[v1] == 1; - v3 = (--enemy_projectile_x_vel[v1] & 0x8000u) != 0; - if (v2 || v3) { - QueueSfx3_Max6(0x1Du); -LABEL_5: - enemy_projectile_y_vel[v1] += 16; - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - enemy_projectile_instr_list_ptr[v1] = addr_word_8697AC; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_y_pos[v1] += 8; - enemy_projectile_pre_instr[v1] = FUNC16(nullsub_86); - QueueSfx3_Max6(0x1Du); - } - } -} - -void EprojPreInstr_PhantoonDestroyableFireballs_3(uint16 k) { // 0x869ADA - int16 v4; - uint16 v5; - int v1 = k >> 1; - enemy_projectile_y_vel[v1] += 2; - uint16 v2 = (uint8)(enemy_projectile_E[v1] + 2); - enemy_projectile_E[v1] = v2; - Eproj_PhantomFireballs_Func1(v2, enemy_projectile_y_vel[v1]); - bool v3 = (int16)(R20_ + enemy_data[0].x_pos) < 0; - v4 = R20_ + enemy_data[0].x_pos; - enemy_projectile_x_pos[v1] = R20_ + enemy_data[0].x_pos; - if (v3 - || !sign16(v4 - 256) - || (v3 = (int16)(R22_ + enemy_data[0].y_pos + 16) < 0, - v5 = R22_ + enemy_data[0].y_pos + 16, - enemy_projectile_y_pos[v1] = v5, - v3) - || !sign16(v5 - 256)) { - enemy_projectile_instr_list_ptr[v1] = addr_off_8697F8; - enemy_projectile_instr_timers[v1] = 1; - } -} - -void EprojPreInstr_PhantoonStartingFireballsB(uint16 k) { // 0x869B29 - if (enemy_data[0].ai_var_B) { - int v1 = k >> 1; - enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_PhantoonStartingFireballsB_2); - enemy_projectile_x_vel[v1] = 180; - enemy_projectile_y_vel[v1] = 48; - } -} - -void EprojPreInstr_PhantoonStartingFireballsB_2(uint16 k) { // 0x869B41 - int v1 = k >> 1; - uint16 v2 = enemy_projectile_x_vel[v1]; - if (v2) { - enemy_projectile_x_vel[v1] = v2 - 1; -LABEL_5:; - uint8 v4 = enemy_projectile_E[v1] + 1; - enemy_projectile_E[v1] = v4; - Eproj_PhantomFireballs_Func1(v4, enemy_projectile_y_vel[v1]); - enemy_projectile_x_pos[v1] = R20_ + enemy_data[0].x_pos; - enemy_projectile_y_pos[v1] = R22_ + enemy_data[0].y_pos + 16; - return; - } - if ((nmi_frame_counter_word & 1) == 0) - goto LABEL_5; - uint16 v3 = enemy_projectile_y_vel[v1] - 1; - enemy_projectile_y_vel[v1] = v3; - if (v3) - goto LABEL_5; - enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; - enemy_projectile_y_pos[v1] = enemy_data[0].y_pos + 16; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_instr_list_ptr[v1] = addr_off_8697F8; -} - -void Eproj_PhantomFireballs_Func1(uint16 j, uint16 a) { // 0x869BA2 - int16 v3; - uint16 v2, v4; - - R24_ = a; - R26_ = j; - if (sign16(j - 128)) - v2 = Eproj_PhantomFireballs_Func2(2 * j); - else - v2 = -Eproj_PhantomFireballs_Func2(2 * (uint8)(j + 0x80)); - R20_ = v2; - v3 = (uint8)(R26_ - 64); - if (sign16(v3 - 128)) - v4 = Eproj_PhantomFireballs_Func2(2 * v3); - else - v4 = -Eproj_PhantomFireballs_Func2(2 * (uint8)(v3 + 0x80)); - R22_ = v4; -} - - -uint16 Eproj_PhantomFireballs_Func2(uint16 k) { // 0x869BF3 - R18_ = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k), R24_) >> 8; - return R18_ + Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k + 1), R24_); -} - -void EprojInit_RocksKraidSpits(uint16 j) { // 0x869CA3 - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = v1->x_pos + 16; - enemy_projectile_y_pos[v2] = v1->y_pos - 96; - enemy_projectile_y_subpos[v2] = 0; - enemy_projectile_1A27[v2] = 0; - enemy_projectile_x_vel[v2] = enemy_projectile_init_param; - enemy_projectile_y_vel[v2] = -1024; - enemy_projectile_gfx_idx[v2] = 1536; -} - -void EprojInit_RocksFallingKraidCeiling(uint16 j) { // 0x869CD8 - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = enemy_projectile_init_param; - enemy_projectile_y_pos[v1] = 312; - enemy_projectile_y_subpos[v1] = 0; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = (random_number & 0x3F) + 64; - enemy_projectile_gfx_idx[v1] = 1536; -} - -void EprojInit_RocksWhenKraidRises(uint16 j) { // 0x869D0C - int16 v1; - - v1 = random_number & 0x3F; - if ((random_number & 1) == 0) - v1 = ~v1; - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = gEnemyData(cur_enemy_index)->x_pos + v1; - enemy_projectile_y_pos[v2] = 432; - enemy_projectile_y_subpos[v2] = 0; - enemy_projectile_1A27[v2] = 0; - enemy_projectile_x_vel[v2] = enemy_projectile_init_param; - enemy_projectile_y_vel[v2] = -1280; - enemy_projectile_gfx_idx[v2] = 1536; - QueueSfx3_Max6(0x1Eu); -} - -void EprojPreInstr_KraidRocks(uint16 k) { // 0x869D56 - if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) { - enemy_projectile_id[k >> 1] = 0; - } else { - int v1 = k >> 1; - uint16 v2 = enemy_projectile_x_vel[v1] + 8; - enemy_projectile_x_vel[v1] = v2; - if (!sign16(v2 - 256)) - v2 = -256; - enemy_projectile_x_vel[v1] = v2; - enemy_projectile_y_vel[v1] += 64; - } -} - -void EprojPreInstr_RocksFallingKraidCeiling(uint16 k) { // 0x869D89 - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) - enemy_projectile_id[k >> 1] = 0; - else - enemy_projectile_y_vel[k >> 1] = (enemy_projectile_y_vel[k >> 1] + 24) & 0x3FFF; -} - -void sub_869DA5(uint16 k) { // 0x869DA5 - enemy_projectile_gfx_idx[k >> 1] = 0; -} - -void EprojInit_MiniKraidSpit(uint16 j) { // 0x869DEC - ExtraEnemyRam7800 *v2; - - EnemyData *v1 = gEnemyData(cur_enemy_index); - v2 = gExtraEnemyRam7800(cur_enemy_index); - int v3 = j >> 1; - enemy_projectile_x_pos[v3] = v2->kraid.field_4 + v1->x_pos; - enemy_projectile_y_pos[v3] = v1->y_pos - 16; - enemy_projectile_y_subpos[v3] = 0; - enemy_projectile_1A27[v3] = 0; - enemy_projectile_x_vel[v3] = v2->kraid.kraid_next; - enemy_projectile_y_vel[v3] = v2->kraid.field_2; -} - -void EprojPreInit_MiniKraidSpit(uint16 k) { // 0x869E1E - int16 v2; - - if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) { - enemy_projectile_id[k >> 1] = 0; - } else { - int v1 = k >> 1; - v2 = enemy_projectile_y_vel[v1] + 64; - if (v2 >= 0 && !sign16(enemy_projectile_y_vel[v1] - 960)) - v2 = 1024; - enemy_projectile_y_vel[v1] = v2; - } -} - -void EprojInit_MiniKraidSpikesLeft(uint16 j) { // 0x869E46 - EprojInit_MiniKraidSpikes(j, -0x200); -} - -void EprojInit_MiniKraidSpikesRight(uint16 j) { // 0x869E4B - EprojInit_MiniKraidSpikes(j, 0x200); -} -static const int16 kEprojInit_MiniKraidSpikes_Tab0[3] = { -2, 12, 24 }; -void EprojInit_MiniKraidSpikes(uint16 j, uint16 a) { // 0x869E4E - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = a; - R18_ = kEprojInit_MiniKraidSpikes_Tab0[gExtraEnemyRam7800(cur_enemy_index)->kraid.kraid_healths_8ths[0] >> 1]; - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos; - enemy_projectile_y_pos[v2] = R18_ + v3->y_pos; - enemy_projectile_y_subpos[v2] = 0; - enemy_projectile_1A27[v2] = 0; - enemy_projectile_y_vel[v2] = 0; -} - -void EprojPreInstr_MiniKraidSpikes(uint16 k) { // 0x869E83 - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) - enemy_projectile_id[k >> 1] = 0; -} - -void EprojInit_WalkingLavaSeahorseFireball(uint16 j) { // 0x869EB2 - static const int16 word_869EF9[3] = { -0x100, 0, 0x100 }; - - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos - 12; - enemy_projectile_x_vel[v2] = -1024; - enemy_projectile_x_pos[v2] = v1->x_pos - 16; - if ((v1->ai_var_D & 0x8000u) == 0) { - enemy_projectile_x_vel[v2] = 1024; - enemy_projectile_x_pos[v2] = v1->x_pos + 16; - } - enemy_projectile_y_vel[v2] = word_869EF9[enemy_projectile_init_param >> 1]; - enemy_projectile_y_subpos[v2] = 0; - enemy_projectile_1A27[v2] = 0; -} - -void EprojPreInstr_WalkingLavaSeahorseFireball(uint16 k) { // 0x869EFF - uint16 v2; - if (EnemyProjectileBlockCollisition_Vertical(k) & 1 || EnemyProjectileBlockCollisition_Horiz(k) & 1) { - enemy_projectile_id[k >> 1] = 0; - } else { - int v1 = k >> 1; - if ((enemy_projectile_x_vel[v1] & 0x8000u) == 0) { - v2 = enemy_projectile_x_vel[v1] - 64; - enemy_projectile_x_vel[v1] = v2; - if (sign16(v2 - 512)) - v2 = 512; - } else { - v2 = enemy_projectile_x_vel[v1] + 64; - enemy_projectile_x_vel[v1] = v2; - if (!sign16(v2 + 512)) - v2 = -512; - } - enemy_projectile_x_vel[v1] = v2; - } -} - -void EprojInit_PirateMotherBrainLaser(uint16 j) { // 0x86A009 - uint16 v1 = addr_word_869F41; - if (R22_) - v1 = addr_word_869F7D; - int v2 = j >> 1; - enemy_projectile_instr_list_ptr[v2] = v1; - enemy_projectile_pre_instr[v2] = FUNC16(nullsub_87); - enemy_projectile_x_pos[v2] = R18_; - enemy_projectile_y_pos[v2] = R20_; - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_properties[v2] = *((uint16 *)RomPtr_A0(v3->enemy_ptr) + 3) | 0x1000; - enemy_projectile_E[v2] = gEnemyData(cur_enemy_index)->parameter_1; - QueueSfx2_Max6(0x67u); -} - -uint16 EprojInstr_SetPreInstrAndRun(uint16 k, uint16 j) { // 0x86A050 - enemy_projectile_pre_instr[k >> 1] = *(uint16 *)RomPtr_86(j); - return j; -} - -void EprojPreInstr_PirateMotherBrainLaser_MoveLeft(uint16 k) { // 0x86A05C - int v1 = k >> 1; - --enemy_projectile_x_pos[v1]; - --enemy_projectile_x_pos[v1]; - if ((enemy_projectile_E[v1] & 0x8000u) == 0) { - --enemy_projectile_x_pos[v1]; - --enemy_projectile_x_pos[v1]; - } - if (CheckIfEnemyProjectileIsOffScreen(k)) - enemy_projectile_id[v1] = 0; -} - -void EprojPreInstr_PirateMotherBrainLaser_MoveRight(uint16 k) { // 0x86A07A - int v1 = k >> 1; - ++enemy_projectile_x_pos[v1]; - ++enemy_projectile_x_pos[v1]; - if ((enemy_projectile_E[v1] & 0x8000u) == 0) { - ++enemy_projectile_x_pos[v1]; - ++enemy_projectile_x_pos[v1]; - } - if (CheckIfEnemyProjectileIsOffScreen(k)) - enemy_projectile_id[v1] = 0; -} - -void EprojInit_PirateClaw(uint16 j) { // 0x86A098 - int v1 = j >> 1; - enemy_projectile_y_pos[v1] = R24_ + R20_; - enemy_projectile_x_pos[v1] = R22_ + R18_; - uint16 v2 = addr_off_869FB9; - if (enemy_projectile_init_param) - v2 = addr_off_869FE1; - enemy_projectile_instr_list_ptr[v1] = v2; - enemy_projectile_pre_instr[v1] = FUNC16(nullsub_87); - enemy_projectile_E[v1] = 2048; - enemy_projectile_F[v1] = 1; -} - -void EprojPreInstr_PirateClawThrownLeft(uint16 k) { // 0x86A0D1 - int v1 = k >> 1; - if (enemy_projectile_F[v1]) { - R18_ = HIBYTE(enemy_projectile_E[v1]); - enemy_projectile_x_pos[v1] -= R18_; - uint16 v2 = enemy_projectile_E[v1] - 32; - enemy_projectile_E[v1] = v2; - if (!v2) - enemy_projectile_F[v1] = 0; - } else { - enemy_projectile_x_pos[v1] += HIBYTE(enemy_projectile_E[v1]); - enemy_projectile_E[v1] += 32; - } - ++enemy_projectile_y_pos[v1]; - if (CheckIfEnemyProjectileIsOffScreen(k)) - enemy_projectile_id[v1] = 0; -} - -void EprojPreInstr_PirateClawThrownRight(uint16 k) { // 0x86A124 - int v1 = k >> 1; - if (enemy_projectile_F[v1]) { - R18_ = HIBYTE(enemy_projectile_E[v1]); - enemy_projectile_x_pos[v1] += R18_; - uint16 v2 = enemy_projectile_E[v1] - 32; - enemy_projectile_E[v1] = v2; - if (!v2) - enemy_projectile_F[v1] = 0; - } else { - R18_ = HIBYTE(enemy_projectile_E[v1]); - enemy_projectile_x_pos[v1] -= R18_; - enemy_projectile_E[v1] += 32; - } - ++enemy_projectile_y_pos[v1]; - if (CheckIfEnemyProjectileIsOffScreen(k)) - enemy_projectile_id[v1] = 0; -} - -static const int16 word_86A2D6[6] = { 64, 72, 80, -64, -72, -80 }; - -void EprojInit_A379(uint16 j) { // 0x86A2A1 - int v1 = j >> 1; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_y_subpos[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - uint16 v2 = enemy_projectile_init_param; - int v3 = enemy_projectile_init_param >> 1; - enemy_projectile_x_pos[v1] = word_86A2D6[v3] + samus_x_pos; - enemy_projectile_y_pos[v1] = samus_y_pos + 80; - enemy_projectile_instr_list_ptr[v1] = off_86A2E2[v3]; - enemy_projectile_E[v1] = v2; -} - -void EprojInit_CeresElevatorPad(uint16 j) { // 0x86A2EE - int v1 = j >> 1; - enemy_projectile_y_pos[v1] = samus_y_pos + 28; - enemy_projectile_E[v1] = 60; - sub_86A301(j); -} - -void sub_86A301(uint16 j) { // 0x86A301 - int v1 = j >> 1; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_y_subpos[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_gfx_idx[v1] = 0; - enemy_projectile_x_pos[v1] = samus_x_pos; -} - - -void EprojInit_CeresElevatorPlatform(uint16 j) { // 0x86A31B - enemy_projectile_y_pos[j >> 1] = 97; - sub_86A301(j); -} - - -void EprojPreInstr_CeresElevatorPad(uint16 k) { // 0x86A328 - bool v2; // zf - bool v3; // sf - - int v1 = k >> 1; - if (!enemy_projectile_E[v1] - || (v2 = enemy_projectile_E[v1] == 1, v3 = (int16)(enemy_projectile_E[v1] - 1) < 0, --enemy_projectile_E[v1], v2) - || v3) { - enemy_projectile_y_pos[v1] = samus_y_pos + 28; - if (!sign16(++samus_y_pos - 73)) { - samus_y_pos = 72; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_instr_list_ptr[v1] = addr_off_86A28B; - CallSomeSamusCode(0xEu); - } - } -} - -void EprojPreInstr_CeresElevatorPlatform(uint16 k) { // 0x86A364 - if (samus_y_pos == 72) { - int v1 = k >> 1; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_instr_list_ptr[v1] = addr_off_86A28B; - } -} - -void EprojPreInstr_PrePhantomRoom(uint16 j) { // 0x86A3A3 - bg2_y_scroll = 0; -} - -uint16 EprojInstr_A3BE(uint16 k, uint16 j) { // 0x86A3BE - int v1 = k >> 1; - enemy_projectile_x_pos[v1] = enemy_projectile_E[v1]; - enemy_projectile_y_pos[v1] = enemy_projectile_F[v1]; - return j; -} - -uint16 EprojInstr_GotoWithProbability25(uint16 k, uint16 j) { // 0x86A456 - if ((NextRandom() & 0xC000) == 0xC000) - return *(uint16 *)RomPtr_86(j); - else - return j + 2; -} - -void EprojInit_BombTorizoLowHealthDrool(uint16 j) { // 0x86A5D3 - int16 parameter_1; // dx - uint16 v4, v5, v8; - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - enemy_projectile_instr_list_ptr[v1] = off_86A64D[(uint16)((NextRandom() >> 1) & 0xE) >> 1]; - NextRandom(); - EnemyData *v2 = gEnemyData(cur_enemy_index); - enemy_projectile_y_pos[v1] = v2->y_pos - 5; - parameter_1 = v2->parameter_1; - if ((parameter_1 & 0x4000) != 0) { - v4 = random_number & 0x1FE; - } else { - if (parameter_1 < 0) - v5 = 32; - else - v5 = 224; - R18_ = v5; - v4 = 2 * (v5 + (random_number & 0xF) - 8); - } - int v6 = v4 >> 1; - enemy_projectile_x_vel[v1] = kSinCosTable8bit_Sext[v6 + 64]; - enemy_projectile_y_vel[v1] = kSinCosTable8bit_Sext[v6]; - EnemyData *v7 = gEnemyData(cur_enemy_index); - if ((v7->parameter_1 & 0x8000u) != 0) - v8 = v7->x_pos + 8; - else - v8 = v7->x_pos - 8; - enemy_projectile_x_pos[v1] = v8; -} - -void EprojInit_BombTorizoLowHealthInitialDrool(uint16 j) { // 0x86A65D - int16 v3; - int16 parameter_1; // dx - - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - NextRandom(); - EnemyData *v2 = gEnemyData(cur_enemy_index); - enemy_projectile_y_pos[v1] = v2->y_pos + (random_number & 3) - 5; - enemy_projectile_y_vel[v1] = (random_number & 0x1F) + 48; - NextRandom(); - v3 = random_number & 3; - parameter_1 = v2->parameter_1; - if ((parameter_1 & 0x4000) != 0) { - enemy_projectile_x_pos[v1] = v2->x_pos + v3; - enemy_projectile_x_vel[v1] = 0; - } else { - if (parameter_1 < 0) - enemy_projectile_x_pos[v1] = v2->x_pos + v3 + 8; - else - enemy_projectile_x_pos[v1] = v2->x_pos + v3 - 8; - enemy_projectile_x_vel[v1] = 0; - } -} - -void EprojInit_A977(uint16 j) { // 0x86A6C7 - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - CalculatePlmBlockCoords(plm_id); - enemy_projectile_x_pos[v1] = 16 * plm_x_block; - enemy_projectile_y_pos[v1] = 16 * plm_y_block - 4; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_y_subpos[v1] = 0; -} - -static const int16 kEprojInit_BombTorizoExplosiveSwipe_Tab0[11] = { -30, -40, -47, -31, -21, -1, -28, -43, -48, -31, -21 }; -static const int16 kEprojInit_BombTorizoExplosiveSwipe_Tab1[11] = { -52, -28, -11, 9, 21, 20, -52, -27, -10, 9, 20 }; -static const int16 kEprojInit_BombTorizoStatueBreaking_Xpos[16] = { 8, 0x18, -8, 8, 0x18, -8, 8, 0x18, 8, -8, 0x18, 8, -8, 0x18, 8, -8 }; -static const int16 kEprojInit_BombTorizoStatueBreaking_Ypos[8] = { -8, -8, 8, 8, 8, 0x18, 0x18, 0x18 }; -static const int16 kEprojInit_BombTorizoStatueBreaking_Yvel[8] = { 256, 256, 256, 256, 256, 256, 256, 256 }; -static const int16 kEprojInit_BombTorizoStatueBreaking_F[8] = { 16, 16, 16, 16, 16, 16, 16, 16 }; -static const int16 kEprojInit_BombTorizoLowHealthExplode_X[6] = { 0, 12, -12, 0, 16, -16 }; -static const int16 kEprojInit_BombTorizoLowHealthExplode_Y[6] = { -8, -8, -8, -20, -20, -20 }; - -void EprojInit_BombTorizoExplosiveSwipe(uint16 j) { // 0x86A6F6 - EnemyData *v1 = gEnemyData(cur_enemy_index); - R18_ = v1->x_pos; - R20_ = v1->y_pos; - if ((v1->parameter_1 & 0x8000u) != 0) { - int v4 = enemy_projectile_init_param >> 1; - int v5 = j >> 1; - enemy_projectile_x_pos[v5] = R18_ - kEprojInit_BombTorizoExplosiveSwipe_Tab0[v4]; - enemy_projectile_y_pos[v5] = R20_ + kEprojInit_BombTorizoExplosiveSwipe_Tab1[v4]; - } else { - int v2 = enemy_projectile_init_param >> 1; - int v3 = j >> 1; - enemy_projectile_x_pos[v3] = R18_ + kEprojInit_BombTorizoExplosiveSwipe_Tab0[v2]; - enemy_projectile_y_pos[v3] = R20_ + kEprojInit_BombTorizoExplosiveSwipe_Tab1[v2]; - } -} - -void EprojInit_BombTorizoStatueBreaking(uint16 j) { // 0x86A764 - int8 v1; - - CalculatePlmBlockCoords(plm_id); - v1 = enemy_projectile_init_param; - int v2 = enemy_projectile_init_param >> 1; - int v3 = j >> 1; - enemy_projectile_instr_list_ptr[v3] = kEprojInit_BombTorizoStatueBreaking_InstrList[v2]; - enemy_projectile_x_pos[v3] = kEprojInit_BombTorizoStatueBreaking_Xpos[v2] + 16 * plm_x_block; - int v4 = (uint8)(v1 & 0xF) >> 1; - enemy_projectile_y_pos[v3] = kEprojInit_BombTorizoStatueBreaking_Ypos[v4] + 16 * plm_y_block; - enemy_projectile_y_vel[v3] = kEprojInit_BombTorizoStatueBreaking_Yvel[v4]; - enemy_projectile_F[v3] = kEprojInit_BombTorizoStatueBreaking_F[v4]; - enemy_projectile_properties[v3] |= 0x1000u; -} - -void EprojInit_BombTorizoLowHealthExplode(uint16 j) { // 0x86A81B - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = v1->x_pos; - enemy_projectile_y_pos[v2] = v1->y_pos; - if ((v1->parameter_1 & 0x8000u) == 0) { - ++enemy_projectile_init_param; - ++enemy_projectile_init_param; - } - ++enemy_projectile_init_param; - int v3 = ++enemy_projectile_init_param >> 1; - uint16 v4 = kEprojInit_BombTorizoLowHealthExplode_X[v3] + enemy_projectile_x_pos[v2]; - enemy_projectile_x_pos[v2] = v4; - enemy_projectile_E[v2] = v4; - uint16 v5 = kEprojInit_BombTorizoLowHealthExplode_Y[v3] + enemy_projectile_y_pos[v2]; - enemy_projectile_y_pos[v2] = v5; - enemy_projectile_F[v2] = v5; -} - -void EprojInit_BombTorizoDeathExplosion(uint16 j) { // 0x86A871 - EnemyData *v1 = gEnemyData(cur_enemy_index); - uint16 x_pos = v1->x_pos; - int v3 = j >> 1; - enemy_projectile_x_pos[v3] = x_pos; - enemy_projectile_E[v3] = x_pos; - uint16 y_pos = v1->y_pos; - enemy_projectile_y_pos[v3] = y_pos; - enemy_projectile_F[v3] = y_pos; -} - -void sub_86A887(uint16 v0) { // 0x86A887 - int16 v2; - int16 v3; - int16 v4; - - if (EnemyProjectileBlockCollisition_Horiz(v0) & 1) { - int v6 = v0 >> 1; - enemy_projectile_instr_list_ptr[v6] = 0xA48A; - enemy_projectile_instr_timers[v6] = 1; - } else { - int v1 = v0 >> 1; - v2 = enemy_projectile_x_vel[v1]; - if (v2 >= 0) { - v4 = v2 - 4; - if (v4 < 0) - v4 = 3; - enemy_projectile_x_vel[v1] = v4; - } else { - v3 = v2 + 4; - if (v3 >= 0) - v3 = 3; - enemy_projectile_x_vel[v1] = v3; - } - uint8 carry = EnemyProjectileBlockCollisition_Vertical(v0); - if ((enemy_projectile_y_vel[v1] & 0x8000u) != 0 || !carry) { - uint16 v5 = enemy_projectile_y_vel[v1] + 16; - enemy_projectile_y_vel[v1] = v5; - if ((v5 & 0xF000) == 4096) - enemy_projectile_id[v1] = 0; - } else { - int v7 = v0 >> 1; - enemy_projectile_y_pos[v7] -= 3; - enemy_projectile_instr_list_ptr[v7] = 0xA48E; - enemy_projectile_instr_timers[v7] = 1; - } - } -} - -void EprojPreInstr_A977(uint16 k) { // 0x86A8EF - uint8 carry = EnemyProjectileBlockCollisition_Vertical(k); - int v1 = k >> 1; - if ((enemy_projectile_y_vel[v1] & 0x8000u) != 0 || !carry) { - uint16 v2 = enemy_projectile_F[0] + enemy_projectile_y_vel[v1]; - enemy_projectile_y_vel[v1] = v2; - if ((v2 & 0xF000) == 4096) - enemy_projectile_y_vel[v1] = 4096; - } else { - enemy_projectile_pre_instr[v1] = 0xA918; - } -} - -void sub_86A91A(uint16 v0) { // 0x86A91A - int v1 = v0 >> 1; - enemy_projectile_x_vel[v1] = 0; - if ((joypad2_last & 0x100) != 0) - enemy_projectile_x_vel[v1] = 256; - if ((joypad2_last & 0x200) != 0) - enemy_projectile_x_vel[v1] = -256; - EnemyProjectileBlockCollisition_Horiz(v0); - enemy_projectile_y_vel[v1] = 0; - if ((joypad2_last & 0x400) != 0) - enemy_projectile_y_vel[v1] = 256; - if ((joypad2_last & 0x800) != 0) - enemy_projectile_y_vel[v1] = -256; - EnemyProjectileBlockCollisition_Vertical(v0); -} - -void EprojInit_AB07(uint16 j) { // 0x86AA3D - VramWriteEntry *v2; - VramWriteEntry *v3; - - uint16 v1 = vram_write_queue_tail; - v2 = gVramWriteEntry(vram_write_queue_tail); - v2->size = 64; - v2->src.addr = addr_kEprojInit_AB07_Tile0; - *(uint16 *)&v2->src.bank = 134; - v2->vram_dst = 28160; - v1 += 7; - v3 = gVramWriteEntry(v1); - v3->size = 64; - v3->src.addr = addr_kEprojInit_AB07_Tile1; - *(uint16 *)&v3->src.bank = 134; - v3->vram_dst = 28416; - vram_write_queue_tail = v1 + 7; - int v4 = j >> 1; - enemy_projectile_x_pos[v4] = samus_x_pos; - enemy_projectile_y_pos[v4] = samus_y_pos - 36; -} - -void EprojPreInstr_AB07(uint16 k) { // 0x86AA8C - R18_ = 0; - R20_ = 0; - int v1 = k >> 1; - uint16 v2 = 8 * (samus_x_pos - enemy_projectile_x_pos[v1]); - if (((samus_x_pos - enemy_projectile_x_pos[v1]) & 0x1000) != 0) - --R20_; - R19_ = v2; - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], R18_); - enemy_projectile_1A27[v1] += R18_; - enemy_projectile_x_pos[v1] += v3 + R20_; - R18_ = 0; - R20_ = 0; - uint16 v4 = 8 * (samus_y_pos - 36 - enemy_projectile_y_pos[v1]); - if (((samus_y_pos - 36 - enemy_projectile_y_pos[v1]) & 0x1000) != 0) - --R20_; - R19_ = v4; - v3 = __CFADD__uint16(enemy_projectile_y_subpos[v1], R18_); - enemy_projectile_y_subpos[v1] += R18_; - enemy_projectile_y_pos[v1] += v3 + R20_; -} - -uint16 EprojInstr_SpawnEnemyDrops(uint16 k, uint16 j) { // 0x86AB8A - int v2 = k >> 1; - R18_ = enemy_projectile_x_pos[v2]; - R20_ = enemy_projectile_y_pos[v2]; - uint16 *p = (uint16 *)RomPtr_86(j); - SpawnEnemyDrops(area_index ? p[1] : p[0], k); - return j + 4; -} - -void Eproj_InitXYVelRandom(uint16 j, uint16 k) { // 0x86ABAE - const uint16 *v2 = (const uint16 *)RomPtr_86(k); - int v3 = j >> 1; - enemy_projectile_instr_list_ptr[v3] = *v2; - enemy_projectile_x_pos[v3] = v2[1] + R18_; - enemy_projectile_x_vel[v3] = v2[2] + (uint8)NextRandom() - 128; - enemy_projectile_y_pos[v3] = v2[3] + R20_; - enemy_projectile_y_vel[v3] = v2[4] + (uint8)NextRandom() - 128; -} - -void EprojInit_BombTorizosChozoOrbs(uint16 j) { // 0x86ABEB - EnemyData *v1 = gEnemyData(cur_enemy_index); - uint16 v2; - R18_ = v1->x_pos; - R20_ = v1->y_pos; - if ((v1->parameter_1 & 0x8000u) != 0) - v2 = addr_kEprojInit_BombTorizosChozoOrbs_init0; - else - v2 = addr_kEprojInit_BombTorizosChozoOrbs_init1; - Eproj_InitXYVelRandom(j, v2); -} - -void EprojInit_GoldenTorizosChozoOrbs(uint16 j) { // 0x86AC7C - EnemyData *v1 = gEnemyData(cur_enemy_index); - uint16 v2; - R18_ = v1->x_pos; - R20_ = v1->y_pos; - if ((v1->parameter_1 & 0x8000u) != 0) - v2 = addr_kEprojInit_GoldenTorizosChozoOrbs_init0; - else - v2 = addr_kEprojInit_GoldenTorizosChozoOrbs_init1; - Eproj_InitXYVelRandom(j, v2); -} - -void EprojPreInstr_BombTorizosChozoOrbs(uint16 k) { // 0x86ACAD - if (EnemyProjectileBlockCollisition_Horiz(k)) { - int v3 = k >> 1; - enemy_projectile_instr_list_ptr[v3] = addr_off_86AB25; - enemy_projectile_instr_timers[v3] = 1; - } else { - uint8 carry = EnemyProjectileBlockCollisition_Vertical(k); - int v1 = k >> 1; - if ((enemy_projectile_y_vel[v1] & 0x8000u) != 0 || !carry) { - uint16 v2 = enemy_projectile_y_vel[v1] + 18; - enemy_projectile_y_vel[v1] = v2; - if ((v2 & 0xF000) == 4096) - enemy_projectile_id[v1] = 0; - } else { - int v4 = k >> 1; - enemy_projectile_y_pos[v4] = (enemy_projectile_y_pos[v4] & 0xFFF0 | 8) - 2; - enemy_projectile_instr_list_ptr[v4] = addr_off_86AB41; - enemy_projectile_instr_timers[v4] = 1; - } - } -} - -void EprojPreInstr_GoldenTorizosChozoOrbs(uint16 k) { // 0x86ACFA - int v1; - int16 v2; - uint16 v3; - uint16 v4; - - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) - enemy_projectile_x_vel[k >> 1] = -enemy_projectile_x_vel[k >> 1]; - if (EnemyProjectileBlockCollisition_Vertical(k) & 1 - && (v1 = k >> 1, (enemy_projectile_y_vel[v1] & 0x8000u) == 0) - && ((v2 = enemy_projectile_x_vel[v1], v2 >= 0) ? (v3 = v2 - 64) : (v3 = v2 + 64), - enemy_projectile_x_vel[v1] = v3, - v4 = -(enemy_projectile_y_vel[v1] >> 1), - enemy_projectile_y_vel[v1] = v4, - (v4 & 0xFF80) == 0xFF80)) { - int v5 = k >> 1; - enemy_projectile_y_pos[v5] = (enemy_projectile_y_pos[v5] & 0xFFF0 | 8) - 2; - enemy_projectile_instr_list_ptr[v5] = addr_off_86AB41; - enemy_projectile_instr_timers[v5] = 1; - } else { - enemy_projectile_y_vel[k >> 1] += 24; - } -} - -uint16 EprojInstr_GotoDependingOnXDirection(uint16 k, uint16 j) { // 0x86AD92 - int16 v3; - - R18_ = 0; - R20_ = 0; - int v2 = k >> 1; - v3 = enemy_projectile_x_vel[v2]; - if (v3 < 0) - --R20_; - R19_ = v3; - uint16 v4 = enemy_projectile_1A27[v2]; - bool v5 = __CFADD__uint16(R18_, v4); - enemy_projectile_1A27[v2] = R18_ + v4; - enemy_projectile_x_pos[v2] += R20_ + v5; - uint16 *t = (uint16 *)RomPtr_86(j); - if ((enemy_projectile_x_vel[v2] & 0x8000u) == 0) - return t[1]; - else - return t[0]; -} - -void EprojInit_TorizoSonicBoom(uint16 j) { // 0x86AE15 - int16 v1; - - NextRandom(); - if ((random_number & 1) != 0) - v1 = -12; - else - v1 = 20; - EnemyData *v2 = gEnemyData(cur_enemy_index); - int v3 = j >> 1; - enemy_projectile_y_pos[v3] = v2->y_pos + v1; - enemy_projectile_y_vel[v3] = 0; - if ((v2->parameter_1 & 0x8000u) != 0) { - enemy_projectile_x_pos[v3] = v2->x_pos + 32; - enemy_projectile_x_vel[v3] = 624; - enemy_projectile_instr_list_ptr[v3] = addr_off_86ADD2; - } else { - enemy_projectile_x_pos[v3] = v2->x_pos - 32; - enemy_projectile_x_vel[v3] = -624; - enemy_projectile_instr_list_ptr[v3] = addr_off_86ADBF; - } -} - -void EprojPreInstr_TorizoSonicBoom(uint16 k) { // 0x86AE6C - int16 v2; - uint16 v3; - - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { - int v4 = k >> 1; - enemy_projectile_instr_list_ptr[v4] = addr_off_86ADE5; - enemy_projectile_instr_timers[v4] = 1; - enemy_projectile_E[v4] = enemy_projectile_x_pos[v4]; - enemy_projectile_F[v4] = enemy_projectile_y_pos[v4]; - } else { - int v1 = k >> 1; - v2 = enemy_projectile_x_vel[v1]; - if (v2 < 0) - v3 = v2 - 16; - else - v3 = v2 + 16; - enemy_projectile_x_vel[v1] = v3; - if ((v3 & 0xF000) == 4096) - enemy_projectile_id[v1] = 0; - } -} - -void EprojInit_WreckedShipChozoSpikeFootsteps(uint16 j) { // 0x86AEFC - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = enemy_projectile_init_param + v1->x_pos; - enemy_projectile_y_pos[v2] = v1->y_pos + 28; -} - -uint16 EprojInstr_ResetXYpos1(uint16 k, uint16 j) { // 0x86AF36 - int v2 = k >> 1; - enemy_projectile_x_pos[v2] = enemy_projectile_E[v2]; - enemy_projectile_y_pos[v2] = enemy_projectile_F[v2]; - return j; -} - -void EprojInit_TourianStatueDustClouds(uint16 j) { // 0x86AF43 - int v1 = j >> 1; - enemy_projectile_E[v1] = 128; - enemy_projectile_F[v1] = 188; -} - -void EprojInit_TourianLandingDustCloudsRightFoot(uint16 j) { // 0x86AF50 - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos + 48; - enemy_projectile_x_pos[v2] = v1->x_pos + 24; -} - -uint16 EprojInstr_MoveY_Minus4(uint16 k, uint16 j) { // 0x86AF92 - enemy_projectile_y_pos[k >> 1] -= 4; - return j; -} - -void EprojInit_TorizoLandingDustCloudLeftFoot(uint16 j) { // 0x86AFCD - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos + 48; - enemy_projectile_x_pos[v2] = v1->x_pos - 24; -} - -void EprojInit_GoldenTorizoEgg(uint16 j) { // 0x86B001 - int16 parameter_1; - uint16 v4; - EnemyData *v1 = gEnemyData(cur_enemy_index); - R18_ = v1->x_pos; - R20_ = v1->y_pos; - int v2 = j >> 1; - enemy_projectile_F[v2] = (0xe2 & 0x1F) + 64; - parameter_1 = v1->parameter_1; - enemy_projectile_E[v2] = parameter_1; - if (parameter_1 < 0) - v4 = addr_kEprojInit_GoldenTorizoEgg0; - else - v4 = addr_kEprojInit_GoldenTorizoEgg1; - Eproj_InitXYVelRandom(j, v4); -} - -void EprojPreInstr_GoldenTorizoEgg(uint16 k) { // 0x86B043 - int16 v3; - uint16 v4, v6; - int v1 = k >> 1; - if ((--enemy_projectile_F[v1] & 0x8000u) != 0) { - ++enemy_projectile_instr_list_ptr[v1]; - ++enemy_projectile_instr_list_ptr[v1]; - enemy_projectile_instr_timers[v1] = 1; - if ((enemy_projectile_E[v1] & 0x8000u) != 0) - v6 = 256; - else - v6 = -256; - enemy_projectile_x_vel[v1] = v6; - } else { - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { - enemy_projectile_x_vel[v1] = -enemy_projectile_x_vel[v1]; - enemy_projectile_E[v1] ^= 0x8000u; - } - if (EnemyProjectileBlockCollisition_Vertical(k) & 1 && (enemy_projectile_y_vel[v1] & 0x8000u) == 0) { - v3 = enemy_projectile_x_vel[v1]; - if (v3 >= 0) - v4 = v3 - 32; - else - v4 = v3 + 32; - enemy_projectile_x_vel[v1] = v4; - enemy_projectile_y_vel[v1] = -enemy_projectile_y_vel[v1]; - } - uint16 v5 = enemy_projectile_y_vel[v1] + 48; - enemy_projectile_y_vel[v1] = v5; - if ((v5 & 0xF000) == 4096) - enemy_projectile_id[v1] = 0; - } -} - -void sub_86B0B9(uint16 k) { // 0x86B0B9 - int16 v2; - - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { - int v3 = k >> 1; - enemy_projectile_pre_instr[v3] = 0xB0DD; - enemy_projectile_y_vel[v3] = 0; - } else { - int v1 = k >> 1; - if ((enemy_projectile_E[v1] & 0x8000u) != 0) - v2 = 48; - else - v2 = -48; - enemy_projectile_x_vel[v1] += v2; - } -} - -void sub_86B0DD(uint16 k) { // 0x86B0DD - uint16 v2; - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - int v1 = k >> 1; - if ((enemy_projectile_E[v1] & 0x8000u) != 0) - v2 = addr_off_86B1A8; - else - v2 = addr_off_86B190; - enemy_projectile_instr_list_ptr[v1] = v2; - enemy_projectile_instr_timers[v1] = 1; - } else { - enemy_projectile_y_vel[k >> 1] += 48; - } -} - -uint16 sub_86B13E(uint16 k, uint16 j) { // 0x86B13E - if ((enemy_projectile_E[k >> 1] & 0x8000u) != 0) - return addr_off_86B166; - else - return addr_off_86B14B; -} - -uint16 sub_86B183(uint16 k, uint16 j) { // 0x86B183 - if ((enemy_projectile_E[k >> 1] & 0x8000u) != 0) - return addr_off_86B1A8; - else - return addr_off_86B190; -} - -static const int16 word_86B205[2] = { -0x1e, 0x1e }; - -void EprojInit_GoldenTorizoSuperMissile(uint16 j) { // 0x86B1CE - uint16 v4; - - int v2 = j >> 1; - enemy_projectile_E[v2] = cur_enemy_index; - EnemyData *v3 = gEnemyData(cur_enemy_index); - R18_ = v3->x_pos; - R20_ = v3->y_pos; - if ((v3->parameter_1 & 0x8000u) != 0) - v4 = 2; - else - v4 = 0; - int v5 = v4 >> 1; - enemy_projectile_x_pos[v2] = R18_ + word_86B205[v5]; - enemy_projectile_y_pos[v2] = R20_ - 52; - enemy_projectile_instr_list_ptr[v2] = off_86B209[v5]; -} - -void EprojPreInstr_GoldenTorizoSuperMissile(uint16 k) { // 0x86B20D - int16 v3; - - int v1 = k >> 1; - EnemyData *v2 = gEnemyData(enemy_projectile_E[v1]); - R18_ = v2->x_pos; - R20_ = v2->y_pos; - if ((v2->parameter_1 & 0x8000u) != 0) - v3 = 32; - else - v3 = -32; - enemy_projectile_x_pos[v1] = R18_ + v3; - enemy_projectile_y_pos[v1] = R20_ - 52; -} - -void EprojPreInstr_B237(uint16 k) { // 0x86B237 - int v1; - uint8 carry; - - if (EnemyProjectileBlockCollisition_Horiz(k) - || (carry = EnemyProjectileBlockCollisition_Vertical(k), v1 = k >> 1, (enemy_projectile_y_vel[v1] & 0x8000u) == 0) - && carry) { - int v3 = k >> 1; - enemy_projectile_instr_list_ptr[v3] = addr_off_86B2EF; - enemy_projectile_instr_timers[v3] = 1; - } else { - uint16 v2 = enemy_projectile_y_vel[v1] + 16; - enemy_projectile_y_vel[v1] = v2; - if ((v2 & 0xF000) == 4096) - enemy_projectile_id[v1] = 0; - } -} - -uint16 EprojInstr_SetVelTowardsSamus1(uint16 k, uint16 j) { // 0x86B269 - sub_86B279(k, CalculateAngleOfSamusFromEproj(k) & 0x7F); - return j; -} - -uint16 EprojInstr_SetVelTowardsSamus2(uint16 k, uint16 j) { // 0x86B272 - sub_86B279(k, CalculateAngleOfSamusFromEproj(k) | 0x80); - return j; -} - -void sub_86B279(uint16 k, uint16 a) { // 0x86B279 - int v2 = a; - int v3 = k >> 1; - enemy_projectile_x_vel[v3] = 4 * kSinCosTable8bit_Sext[v2 + 64]; - enemy_projectile_y_vel[v3] = 4 * kSinCosTable8bit_Sext[v2]; -} -void EprojInit_GoldenTorizoEyeBeam(uint16 j) { // 0x86B328 - EnemyData *v1 = gEnemyData(cur_enemy_index); - uint16 v2; - R18_ = v1->x_pos; - R20_ = v1->y_pos; - if ((v1->parameter_1 & 0x8000u) != 0) - v2 = addr_stru_86B376; - else - v2 = addr_stru_86B380; - Eproj_InitXYVelRandom(j, v2); - uint16 v3 = (NextRandom() & 0x1E) - 16 + 192; - if ((gEnemyData(cur_enemy_index)->parameter_1 & 0x8000u) == 0) - v3 += 128; - int v4 = v3 >> 1; - int v5 = j >> 1; - enemy_projectile_x_vel[v5] = 8 * kSinCosTable8bit_Sext[v4 + 64]; - enemy_projectile_y_vel[v5] = 8 * kSinCosTable8bit_Sext[v4]; -} - -void EprojPreInstr_GoldenTorizoEyeBeam(uint16 k) { // 0x86B38A - if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { - enemy_projectile_instr_list_ptr[k >> 1] = addr_off_86B3CD; -LABEL_6: - enemy_projectile_instr_timers[k >> 1] = 1; - return; - } - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - int v1 = k >> 1; - enemy_projectile_y_pos[v1] = (enemy_projectile_y_pos[v1] & 0xFFF0 | 8) - 2; - enemy_projectile_instr_list_ptr[v1] = addr_off_86B3E5; - goto LABEL_6; - } -} - -uint16 EprojInstr_GotoIfFunc1(uint16 k, uint16 j) { // 0x86B3B8 - if ((gExtraEnemyRam7800(enemy_projectile_F[k >> 1])->kraid.kraid_healths_8ths[0] & 0x8000u) == 0) - return *(uint16 *)RomPtr_86(j); - else - return j + 2; -} - -uint16 EprojInstr_ResetXYpos2(uint16 k, uint16 j) { // 0x86B436 - int v2 = k >> 1; - enemy_projectile_x_pos[v2] = enemy_projectile_E[v2]; - enemy_projectile_y_pos[v2] = enemy_projectile_F[v2]; - return j; -} - -void EprojInit_TourianEscapeShaftFakeWallExplode(uint16 j) { // 0x86B49D - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = 272; - enemy_projectile_E[v1] = 272; - enemy_projectile_y_pos[v1] = 2184; - enemy_projectile_F[v1] = 2184; -} - -void EprojInit_LavaSeahorseFireball(uint16 j) { // 0x86B4EF - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_y_pos[v2] = v1->y_pos - 28; - enemy_projectile_y_vel[v2] = -961; - if ((v1->ai_var_A & 0x8000u) == 0) { - enemy_projectile_x_pos[v2] = v1->x_pos + 12; - enemy_projectile_x_vel[v2] = 704; - enemy_projectile_instr_list_ptr[v2] = addr_word_86B4CB; - } else { - enemy_projectile_x_pos[v2] = v1->x_pos - 12; - enemy_projectile_x_vel[v2] = -704; - enemy_projectile_instr_list_ptr[v2] = addr_word_86B4BF; - } -} - -void sub_86B535(uint16 k) { // 0x86B535 - int16 v6; - uint16 v7; - - int v1 = k >> 1; - R20_ = LOBYTE(enemy_projectile_x_vel[v1]) << 8; - R18_ = (int8)HIBYTE(enemy_projectile_x_vel[v1]); - uint16 v4 = enemy_projectile_1A27[v1]; - bool v3 = __CFADD__uint16(R20_, v4); - enemy_projectile_1A27[v1] = R20_ + v4; - enemy_projectile_x_pos[v1] += R18_ + v3; - R20_ = LOBYTE(enemy_projectile_y_vel[v1]) << 8; - R18_ = (int8)HIBYTE(enemy_projectile_y_vel[v1]); - uint16 v5 = enemy_projectile_y_subpos[v1]; - v3 = __CFADD__uint16(R20_, v5); - enemy_projectile_y_subpos[v1] = R20_ + v5; - enemy_projectile_y_pos[v1] += R18_ + v3; - v6 = enemy_projectile_y_vel[v1]; - if (v6 >= 0) { - enemy_projectile_y_vel[v1] = v6 + 32; - Eproj_DeleteIfYposOutside(k); - } else { - enemy_projectile_y_vel[v1] = v6 + 32; - if ((int16)(v6 + 32) >= 0) { - if ((enemy_projectile_x_vel[v1] & 0x8000u) == 0) - v7 = addr_word_86B4E3; - else - v7 = addr_word_86B4D7; - enemy_projectile_instr_list_ptr[v1] = v7; - enemy_projectile_instr_timers[v1] = 1; - } - } -} - -void Eproj_DeleteIfYposOutside(uint16 k) { // 0x86B5B9 - int v1 = k >> 1; - if ((int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) >= 288) - enemy_projectile_id[v1] = 0; -} - -static const int16 word_86B65B[20] = { // 0x86B62D - -16, 16, -96, -64, -128, -32, -96, 64, -128, 32, 16, 16, 96, -64, 112, -64, - 128, -64, 144, -64, -}; - -void EprojInit_EyeDoorProjectile(uint16 j) { - - uint16 v1 = plm_id; - int v2 = j >> 1; - enemy_projectile_F[v2] = plm_room_arguments[plm_id >> 1]; - CalculatePlmBlockCoords(v1); - int v3 = enemy_projectile_init_param >> 1; - enemy_projectile_x_pos[v2] = word_86B65B[v3] + 8 * (2 * plm_x_block + 1); - enemy_projectile_y_pos[v2] = word_86B65B[v3 + 1] + 16 * plm_y_block; -} - -static const int16 word_86B6B1[4] = { -64, 512, 64, 512 }; - -void EprojInit_EyeDoorSweat(uint16 j) { // 0x86B683 - CalculatePlmBlockCoords(plm_id); - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = 8 * (2 * (plm_x_block - 1) + 1); - enemy_projectile_y_pos[v1] = 16 * (plm_y_block + 1); - int v2 = enemy_projectile_init_param >> 1; - enemy_projectile_x_vel[v1] = word_86B6B1[v2]; - enemy_projectile_y_vel[v1] = word_86B6B1[v2 + 1]; -} - -void EprojPreInstr_EyeDoorProjectile(uint16 k) { // 0x86B6B9 - int16 v2; - int16 v4; - - if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) { -LABEL_8:; - int v5 = k >> 1; // bug fixed - enemy_projectile_instr_list_ptr[v5] = addr_off_86B5F3; - enemy_projectile_instr_timers[v5] = 1; - return; - } - int v1 = enemy_projectile_E[k >> 1] >> 1; - v2 = kSinCosTable8bit_Sext[v1 + 64] >> 4; - if ((v2 & 0x800) != 0) - v2 |= 0xF000u; - int v3 = k >> 1; - enemy_projectile_x_vel[v3] += v2; - v4 = kSinCosTable8bit_Sext[v1] >> 4; - if ((v4 & 0x800) != 0) - v4 |= 0xF000u; - enemy_projectile_y_vel[v3] += v4; - int t = PrepareBitAccess(enemy_projectile_F[v3]); - if ((bitmask & opened_door_bit_array[t]) != 0) { - goto LABEL_8; - } -} - -void EprojPreInstr_EyeDoorSweat(uint16 k) { // 0x86B714 - EnemyProjectileBlockCollisition_Horiz(k); - uint8 carry = EnemyProjectileBlockCollisition_Vertical(k); - int v1 = k >> 1; - if ((enemy_projectile_y_vel[v1] & 0x8000u) != 0 || !carry) { - enemy_projectile_y_vel[v1] += 12; - } else { - enemy_projectile_y_pos[v1] -= 4; - enemy_projectile_instr_list_ptr[v1] = addr_off_86B61D; - enemy_projectile_instr_timers[v1] = 1; - } -} - -uint16 EprojInstr_SpawnTourianStatueUnlockingParticle(uint16 k, uint16 j) { // 0x86B7EA - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueUnlockingParticle, k); - return j; -} - -uint16 EprojInstr_Earthquake(uint16 k, uint16 j) { // 0x86B7F5 - earthquake_type = 1; - earthquake_timer |= 0x20u; - return j; -} - -uint16 EprojInstr_SpawnTourianStatueUnlockingParticleTail(uint16 k, uint16 j) { // 0x86B818 - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueUnlockingParticleTail, k); - return j; -} - -uint16 EprojInstr_AddToYpos(uint16 k, uint16 j) { // 0x86B841 - enemy_projectile_y_pos[k >> 1] += *(uint16 *)RomPtr_86(j); - return j + 2; -} - -void EprojInit_TourianStatueUnlockingParticleWaterSplash(uint16 j) { // 0x86B87A - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = enemy_projectile_x_pos[enemy_projectile_init_param >> 1]; - enemy_projectile_y_pos[v1] = fx_y_pos - 4; -} - -static const uint16 kEprojInit_TourianStatueEyeGlow_X[4] = { 0x84, 0x7a, 0x9e, 0x68 }; -static const uint16 kEprojInit_TourianStatueEyeGlow_Y[4] = { 0x90, 0x51, 0x80, 0x72 }; -static const uint16 kEprojInit_TourianStatueEyeGlow_Colors[16] = { 0x6bff, 0x33b, 0x216, 0x173, 0x7f5f, 0x7c1f, 0x5816, 0x300c, 0x7f5a, 0x7ec0, 0x6de0, 0x54e0, 0x6bfa, 0x3be0, 0x2680, 0x1580 }; - -void EprojInit_TourianStatueEyeGlow(uint16 j) { // 0x86B88E - uint16 v1 = enemy_projectile_init_param; - int v2 = enemy_projectile_init_param >> 1; - int v3 = j >> 1; - enemy_projectile_x_pos[v3] = kEprojInit_TourianStatueEyeGlow_X[v2]; - enemy_projectile_y_pos[v3] = kEprojInit_TourianStatueEyeGlow_Y[v2]; - uint16 v4 = 4 * v1; - for (int i = 498; i != 506; i += 2) { - palette_buffer[i >> 1] = kEprojInit_TourianStatueEyeGlow_Colors[v4 >> 1]; - v4 += 2; - } -} - -void EprojInit_TourianStatueUnlockingParticle(uint16 j) { // 0x86B8B5 - int v1 = enemy_projectile_init_param >> 1; - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = enemy_projectile_x_pos[v1]; - enemy_projectile_y_pos[v2] = enemy_projectile_y_pos[v1]; - uint16 v3 = 2 * (uint8)((NextRandom() & 0x3F) - 32); - enemy_projectile_E[v2] = v3; - int v4 = v3 >> 1; - enemy_projectile_x_vel[v2] = kSinCosTable8bit_Sext[v4 + 64]; - enemy_projectile_y_vel[v2] = 4 * kSinCosTable8bit_Sext[v4]; -} - -void EprojIni_TourianStatueUnlockingParticleTail(uint16 v0) { // 0x86B8E8 - int v1 = enemy_projectile_init_param >> 1; - int v2 = v0 >> 1; - enemy_projectile_x_pos[v2] = enemy_projectile_x_pos[v1]; - enemy_projectile_y_pos[v2] = enemy_projectile_y_pos[v1]; -} - -void EprojInit_TourianStatueSoul(uint16 j) { // 0x86B8F8 - int v1 = enemy_projectile_init_param >> 1; - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = kEprojInit_TourianStatueEyeGlow_X[v1]; - enemy_projectile_y_pos[v2] = kEprojInit_TourianStatueEyeGlow_Y[v1]; - enemy_projectile_y_vel[v2] = -1024; -} - -void EprojInit_TourianStatueBaseDecoration(uint16 j) { // 0x86B93E - int v1 = j >> 1; - enemy_projectile_E[v1] = 120; - enemy_projectile_x_pos[v1] = 120; - enemy_projectile_F[v1] = 184; - enemy_projectile_y_pos[v1] = 184; -} - -void EprojInit_TourianStatueRidley(uint16 j) { // 0x86B951 - int v1 = j >> 1; - enemy_projectile_E[v1] = 142; - enemy_projectile_x_pos[v1] = 142; - enemy_projectile_F[v1] = 85; - enemy_projectile_y_pos[v1] = 85; -} - -void EprojInit_TourianStatuePhantoon(uint16 j) { // 0x86B964 - int v1 = j >> 1; - enemy_projectile_E[v1] = 132; - enemy_projectile_x_pos[v1] = 132; - enemy_projectile_F[v1] = 136; - enemy_projectile_y_pos[v1] = 136; -} - -void EprojPreInstr_TourianStatueUnlockingParticleWaterSplash(uint16 k) { // 0x86B977 - enemy_projectile_y_pos[k >> 1] = fx_y_pos - 4; -} - -void EprojPreInstr_TourianStatueUnlockingParticle(uint16 k) { // 0x86B982 - int16 v2; - int16 v5; - int16 v7; - - R18_ = 0; - R20_ = 0; - int v1 = k >> 1; - v2 = enemy_projectile_x_vel[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - uint16 v3 = enemy_projectile_1A27[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - enemy_projectile_1A27[v1] = R18_ + v3; - enemy_projectile_x_pos[v1] += R20_ + v4; - v7 = fx_y_pos - enemy_projectile_y_pos[v1]; - R18_ = 0; - R20_ = 0; - v5 = enemy_projectile_y_vel[v1]; - if (v5 < 0) - --R20_; - R19_ = v5; - uint16 v6 = enemy_projectile_y_subpos[v1]; - v4 = __CFADD__uint16(R18_, v6); - enemy_projectile_y_subpos[v1] = R18_ + v6; - enemy_projectile_y_pos[v1] += R20_ + v4; - if (((v7 ^ (fx_y_pos - enemy_projectile_y_pos[v1])) & 0x8000u) != 0) - SpawnEnemyProjectileWithRoomGfx(addr_stru_86BA5C, k); - if ((enemy_projectile_y_pos[v1] & 0xFF00) == 256) { - enemy_projectile_instr_list_ptr[v1] = addr_off_86B79F; - enemy_projectile_instr_timers[v1] = 1; - } else { - enemy_projectile_y_vel[v1] += 16; - } -} - -void EprojPreInstr_TourianStatueSoul(uint16 k) { // 0x86B9FD - int16 v2; - - R18_ = 0; - R20_ = 0; - int v1 = k >> 1; - v2 = enemy_projectile_y_vel[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - uint16 v3 = enemy_projectile_y_subpos[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - enemy_projectile_y_subpos[v1] = R18_ + v3; - uint16 v5 = R20_ + v4 + enemy_projectile_y_pos[v1]; - enemy_projectile_y_pos[v1] = v5; - if ((v5 & 0x100) != 0) { - enemy_projectile_instr_list_ptr[v1] = addr_off_86B79F; - enemy_projectile_instr_timers[v1] = 1; - } - enemy_projectile_y_vel[v1] -= 128; -} - -void EprojPreInstr_TourianStatueStuff(uint16 k) { // 0x86BA37 - if (!tourian_entrance_statue_animstate) - tourian_entrance_statue_finished |= 0x8000; - EprojPreInstr_BA42(k); -} - -void EprojPreInstr_BA42(uint16 k) { // 0x86BA42 - int v1 = k >> 1; - enemy_projectile_x_pos[v1] = enemy_projectile_E[v1]; - enemy_projectile_y_pos[v1] = enemy_projectile_F[v1] + layer1_y_pos - *(uint16 *)&hdma_window_1_left_pos[0].field_0; -} - -uint16 EprojInstr_BB24(uint16 k, uint16 j) { // 0x86BB24 - enemy_projectile_instr_list_ptr[stru_86BB50.init_code_ptr >> 1] = 0; - return j; -} - -void sub_86BB30(uint16 j) { // 0x86BB30 - ExtraEnemyRam8000 *v1; - - v1 = gExtraEnemyRam8000(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = *(uint16 *)&v1->pad[34]; - enemy_projectile_y_pos[v2] = *(uint16 *)&v1->pad[36]; - enemy_projectile_instr_list_ptr[v2] = off_86BB1E[enemy_projectile_init_param]; -} - -void EprojInit_NuclearWaffleBody(uint16 j) { // 0x86BB92 - ExtraEnemyRam8000 *v4; - - EnemyData *v2 = gEnemyData(cur_enemy_index); - int v3 = j >> 1; - enemy_projectile_x_pos[v3] = v2->x_pos; - enemy_projectile_1A27[v3] = v2->x_subpos; - enemy_projectile_y_pos[v3] = v2->y_pos; - enemy_projectile_y_subpos[v3] = v2->y_subpos; - v4 = gExtraEnemyRam8000(cur_enemy_index); - gExtraEnemyRam7800(cur_enemy_index + *(uint16 *)&v4->pad[20])->kraid.kraid_next = j; - enemy_projectile_flags[v3] = 1; -} - -void EprojInit_NorfairLavaquakeRocks(uint16 j) { // 0x86BBDB - int v1 = j >> 1; - enemy_projectile_instr_list_ptr[v1] = addr_word_86BBD5; - enemy_projectile_E[v1] = FUNC16(Eproj_NorfairLavaquakeRocks_Func1); - enemy_projectile_y_vel[v1] = enemy_projectile_init_param; - enemy_projectile_x_vel[v1] = enemy_projectile_unk1995; - EnemyData *v2 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v1] = v2->x_pos; - enemy_projectile_1A27[v1] = v2->x_subpos; - enemy_projectile_y_pos[v1] = v2->y_pos; - enemy_projectile_y_subpos[v1] = v2->y_subpos; -} - -void CallNorfairLavaquakeRocksFunc(uint32 ea, uint16 k) { - switch (ea) { - case fnEproj_NorfairLavaquakeRocks_Func1: Eproj_NorfairLavaquakeRocks_Func1(k); return; - case fnEproj_NorfairLavaquakeRocks_Func2: Eproj_NorfairLavaquakeRocks_Func2(k); return; - default: Unreachable(); - } -} - -void EprojPreInstr_NorfairLavaquakeRocks(uint16 k) { // 0x86BC0F - CallNorfairLavaquakeRocksFunc(enemy_projectile_E[k >> 1] | 0x860000, k); - EprojPreInstr_NorfairLavaquakeRocks_Inner(k); -} - -void Eproj_NorfairLavaquakeRocks_Func1(uint16 k) { // 0x86BC16 - int16 v2; - int16 v3; - int16 v8; - - int v1 = k >> 1; - v2 = enemy_projectile_y_vel[v1] - 2; - enemy_projectile_y_vel[v1] = v2; - if (v2 >= 0) { - R18_ = 2; - do { - v3 = R18_ + enemy_projectile_y_vel[k >> 1] - 1; - if (v3 < 0) - v3 = 0; - int v4 = k >> 1; - enemy_projectile_F[v4] = kCommonEnemySpeeds_Quadratic_Copy[(uint16)(8 * v3 + 4) >> 1]; - uint16 v5 = enemy_projectile_y_subpos[v4]; - bool v6 = __CFADD__uint16(enemy_projectile_F[v4], v5); - uint16 v7 = enemy_projectile_F[v4] + v5; - if (v6) - ++enemy_projectile_y_pos[v4]; - enemy_projectile_y_subpos[v4] = v7; - v8 = R18_ + enemy_projectile_y_vel[v4] - 1; - if (v8 < 0) - v8 = 0; - int v9 = k >> 1; - enemy_projectile_F[v9] = kCommonEnemySpeeds_Quadratic_Copy[(uint16)(8 * v8 + 6) >> 1]; - enemy_projectile_y_pos[v9] += enemy_projectile_F[v9]; - --R18_; - } while (R18_); - Eproj_NorfairLavaquakeRocks_Func3(k); - } else { - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_E[v1] = FUNC16(Eproj_NorfairLavaquakeRocks_Func2); - } -} - -void Eproj_NorfairLavaquakeRocks_Func2(uint16 k) { // 0x86BC8F - int v1 = k >> 1; - uint16 v2 = enemy_projectile_y_vel[v1] + 2; - enemy_projectile_y_vel[v1] = v2; - if (!sign16(v2 - 64)) - enemy_projectile_y_vel[v1] = 64; - R18_ = 2; - do { - int v3 = k >> 1; - enemy_projectile_F[v3] = kCommonEnemySpeeds_Quadratic_Copy[(uint16)(8 - * (enemy_projectile_y_vel[v3] - R18_ + 1)) >> 1]; - uint16 v4 = enemy_projectile_y_subpos[v3]; - bool v5 = __CFADD__uint16(enemy_projectile_F[v3], v4); - uint16 v6 = enemy_projectile_F[v3] + v4; - if (v5) - ++enemy_projectile_y_pos[v3]; - enemy_projectile_y_subpos[v3] = v6; - int v7 = k >> 1; - enemy_projectile_F[v7] = kCommonEnemySpeeds_Quadratic_Copy[(uint16)(8 - * (enemy_projectile_y_vel[v3] - R18_ + 1) - + 2) >> 1]; - enemy_projectile_y_pos[v7] += enemy_projectile_F[v7]; - --R18_; - } while (R18_); - Eproj_NorfairLavaquakeRocks_Func3(k); -} - -void Eproj_NorfairLavaquakeRocks_Func3(uint16 k) { // 0x86BCF4 - int v1 = k >> 1; - enemy_projectile_x_pos[v1] += SignExtend8((uint8)((uint16)(enemy_projectile_x_vel[v1] & 0xFF00) >> 8)); - uint16 v2 = SignExtend8(LOBYTE(enemy_projectile_x_vel[v1]) << 8); - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], v2); - uint16 v4 = enemy_projectile_1A27[v1] + v2; - if (v3) - ++enemy_projectile_x_pos[v1]; - enemy_projectile_1A27[v1] = v4; -} - -void EprojPreInstr_NorfairLavaquakeRocks_Inner(uint16 k) { // 0x86BD1E - if (EprojPreInstr_NorfairLavaquakeRocks_Inner2(k)) - enemy_projectile_id[k >> 1] = 0; -} - -uint16 EprojPreInstr_NorfairLavaquakeRocks_Inner2(uint16 k) { // 0x86BD2A - int v1 = k >> 1; - return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 - || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 - || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 - || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; -} - -static const int16 kEprojInit_ShaktoolAttackMiddleBackCircle_X[8] = { 0, 12, 16, 12, 0, -12, -16, -12 }; -static const int16 kEprojInit_ShaktoolAttackMiddleBackCircle_Y[8] = { -16, -12, 0, 12, 16, 12, 0, -12 }; - -void EprojInit_ShaktoolAttackMiddleBackCircle(uint16 j) { // 0x86BD9C - enemy_projectile_E[j >> 1] = enemy_projectile_init_param; - EprojInit_BDA2(j); -} - -void EprojInit_BDA2(uint16 j) { // 0x86BDA2 - int v1 = j >> 1; - EnemyData *v2 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v1] = v2->x_pos; - enemy_projectile_y_pos[v1] = v2->y_pos; - uint16 v3 = 2 * LOBYTE(v2->ai_var_D); - int v4 = v3 >> 1; - enemy_projectile_x_vel[v1] = kSinCosTable8bit_Sext[v4 + 64]; - enemy_projectile_y_vel[v1] = kSinCosTable8bit_Sext[v4]; - int v5 = (uint16)(v3 >> 5) >> 1; - enemy_projectile_x_pos[v1] += kEprojInit_ShaktoolAttackMiddleBackCircle_X[v5]; - enemy_projectile_y_pos[v1] += kEprojInit_ShaktoolAttackMiddleBackCircle_Y[v5]; -} - -void EprojInit_ShaktoolAttackFrontCircle(uint16 v1) { // 0x86BE03 - if (EnemyProjectileBlockCollisition_Horiz(v1) & 1 || EnemyProjectileBlockCollisition_Vertical(v1) & 1) - enemy_projectile_id[v1 >> 1] = 0; -} - -void EprojPreInstr_BE12(uint16 k) { // 0x86BE12 - int v1 = k >> 1; - if (enemy_projectile_id[enemy_projectile_E[v1] >> 1]) { - EnemyProjectileBlockCollisition_Horiz(k); - EnemyProjectileBlockCollisition_Vertical(k); - } else { - enemy_projectile_id[v1] = 0; - } -} - -static const int16 kEprojInit_MotherBrainRoomTurrets_X[12] = { 0x398, 0x348, 0x328, 0x2d8, 0x288, 0x268, 0x218, 0x1c8, 0x1a8, 0x158, 0x108, 0xe8 }; -static const int16 EprojInit_MotherBrainRoomTurrets_Y[12] = { 0x30, 0x40, 0x40, 0x30, 0x40, 0x40, 0x30, 0x40, 0x40, 0x30, 0x40, 0x40 }; - -void EprojInit_MotherBrainRoomTurrets(uint16 j) { // 0x86BE4F - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 1024; - uint16 v2 = 2 * enemy_projectile_init_param; - uint16 v3 = kEproj_MotherBrainRoomTurrets_DirectionIndexes[enemy_projectile_init_param] | 0x100; - enemy_projectile_y_subpos[v1] = v3; - enemy_projectile_instr_list_ptr[v1] = kEproj_MotherBrainRoomTurrets_InstrLists[(uint16)(2 - * (uint8)v3) >> 1]; - int v4 = v2 >> 1; - enemy_projectile_x_pos[v1] = kEprojInit_MotherBrainRoomTurrets_X[v4]; - enemy_projectile_y_pos[v1] = EprojInit_MotherBrainRoomTurrets_Y[v4]; - enemy_projectile_1A27[v1] = kEproj_MotherBrainRoomTurrets_AllowedRotations[v4]; - Eproj_SetXvelRandom(j); - Eproj_SetYvelRandom(j); -} - -static const int16 kEproj_MotherBrainRoomTurretBullets_X[8] = { -17, -12, 0, 12, 17, 12, 0, -12 }; -static const int16 kEproj_MotherBrainRoomTurretBullets_Y[8] = { -9, 3, 7, 3, -9, -19, -21, -19 }; -static const int16 kEproj_MotherBrainRoomTurretBullets_Xvel[8] = { -704, -498, 0, 498, 704, 498, 0, -498 }; -static const int16 kEproj_MotherBrainRoomTurretBullets_Yvel[8] = { 0, 498, 704, 498, 0, -498, -704, -498 }; - -void EprojInit_MotherBrainRoomTurretBullets(uint16 j) { // 0x86BF59 - int v1 = j >> 1; - enemy_projectile_F[v1] = 0; - enemy_projectile_gfx_idx[v1] = 1024; - uint16 v2 = 2 * LOBYTE(enemy_projectile_y_subpos[enemy_projectile_init_param >> 1]); - enemy_projectile_E[v1] = v2; - int v3 = v2 >> 1; - R18_ = kEproj_MotherBrainRoomTurretBullets_X[v3]; - R20_ = kEproj_MotherBrainRoomTurretBullets_Y[v3]; - enemy_projectile_x_vel[v1] = kEproj_MotherBrainRoomTurretBullets_Xvel[v3]; - enemy_projectile_y_vel[v1] = kEproj_MotherBrainRoomTurretBullets_Yvel[v3]; - int v4 = enemy_projectile_init_param >> 1; - enemy_projectile_x_pos[v1] = R18_ + enemy_projectile_x_pos[v4]; - enemy_projectile_y_pos[v1] = R20_ + enemy_projectile_y_pos[v4]; -} - - -void EprojPreInstr_MotherBrainRoomTurrets(uint16 k) { // 0x86BFDF - if (Eproj_MotherBrainRoomTurretBullets_CheckIfTurretOnScreen(k) & 1) { - if (gRam7800_Default(0)->var_1D) - *(uint16 *)((uint8 *)enemy_projectile_id + k) = 0; - } else if (gRam7800_Default(0)->var_1D) { - *(uint16 *)((uint8 *)enemy_projectile_id + k) = 0; - int v5 = k >> 1; - R18_ = enemy_projectile_x_pos[v5]; - R20_ = enemy_projectile_y_pos[v5]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0xC); - } else { - int v1 = k >> 1; - bool v2 = enemy_projectile_x_vel[v1]-- == 1; - if (v2) { - Eproj_SetXvelRandom(k); - Eproj_MotherBrainRoomTurretBullets_Func2(k); - int v3 = k >> 1; - enemy_projectile_instr_list_ptr[v3] = g_off_86C040[(uint16)(2 * LOBYTE(enemy_projectile_y_subpos[v3])) >> 1]; - enemy_projectile_instr_timers[v3] = 1; - } - int v4 = k >> 1; - v2 = enemy_projectile_y_vel[v4]-- == 1; - if (v2) { - Eproj_SetYvelRandom(k); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainRoomTurretBullets, k); - } - } -} - -void Eproj_MotherBrainRoomTurretBullets_Func2(uint16 v0) { // 0x86C050 - int8 v1; - - LOBYTE(R20_) = (*((uint8 *)enemy_projectile_y_subpos + v0 + 1) + *((uint8 *)enemy_projectile_y_subpos + v0)) & 7; - R18_ = enemy_projectile_1A27[v0 >> 1]; - if (RomPtr_86(R18_)[R20_ & 7]) { - *((uint8 *)enemy_projectile_y_subpos + v0) = R20_; - } else { - v1 = -*((uint8 *)enemy_projectile_y_subpos + v0 + 1); - *((uint8 *)enemy_projectile_y_subpos + v0 + 1) = v1; - *((uint8 *)enemy_projectile_y_subpos + v0) += v1; - } -} - -void Eproj_SetXvelRandom(uint16 v0) { // 0x86C08E - uint16 Random = (uint8)NextRandom(); - if (sign16((uint8)Random - 32)) - Random = 32; - enemy_projectile_x_vel[v0 >> 1] = Random; -} - -void Eproj_SetYvelRandom(uint16 v0) { // 0x86C0A1 - uint16 Random = (uint8)NextRandom(); - if (sign16((uint8)Random - 128)) - Random = 128; - enemy_projectile_y_vel[v0 >> 1] = Random; -} - -uint8 Eproj_MotherBrainRoomTurretBullets_CheckIfTurretOnScreen(uint16 k) { // 0x86C0B4 - int16 v2; - int16 v3; - int16 v4; - int16 v5; - - int v1 = k >> 1; - v2 = enemy_projectile_y_pos[v1]; - uint8 result = 1; - if (v2 >= 0) { - v3 = v2 + 16 - layer1_y_pos; - if (v3 >= 0) { - if (sign16(v3 - 256)) { - v4 = enemy_projectile_x_pos[v1]; - if (v4 >= 0) { - v5 = v4 + 4 - layer1_x_pos; - if (v5 >= 0) { - if (sign16(v5 - 264)) - return 0; - } - } - } - } - } - return result; -} - -void EprojPreInstr_MotherBrainRoomTurretBullets(uint16 k) { // 0x86C0E0 - int v1 = k >> 1; - enemy_projectile_properties[v1] ^= 0x8000u; - MoveEprojWithVelocity(k); - if (Ridley_Func_103(enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1]) & 1) - enemy_projectile_id[enemy_projectile_index >> 1] = 0; -} - -static const int16 kMotherBrainsBomb_Yaccel[10] = { 7, 0x10, 0x20, 0x40, 0x70, 0xb0, 0xf0, 0x130, 0x170, 0 }; - -void EprojPreInstr_MotherBrainBomb(uint16 k) { // 0x86C4C8 - int16 v2; - - if (MotherBrainBomb_Bomb_CollDetect_DoubleRet(k)) - return; - int v1 = k >> 1; - if (enemy_projectile_F[v1]) { - int v4 = k >> 1; - uint16 v5 = kMotherBrainsBomb_Yaccel[enemy_projectile_F[v4] >> 1]; - if (!v5) { - enemy_projectile_x_vel[v4] = 0; - enemy_projectile_y_vel[v4] = 0; - --enemy_ram7800[1].kraid.kraid_mouth_flags; - enemy_projectile_id[v4] = 0; - R18_ = enemy_projectile_x_pos[v4]; - R20_ = enemy_projectile_y_pos[v4]; - SpawnEnemyProjectileWithRoomGfx(addr_stru_869650, LOBYTE(enemy_projectile_1A27[v4])); - R18_ = enemy_projectile_x_pos[v4]; - R20_ = enemy_projectile_y_pos[v4]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3u); - QueueSfx3_Max6(0x13u); - return; - } - if (MoveMotherBrainBomb(k, v5) & 1) - goto LABEL_5; - } else { - v2 = abs16(enemy_projectile_x_vel[v1]) - 2; - if (v2 < 0) - v2 = 0; - enemy_projectile_x_vel[v1] = sign16(enemy_projectile_x_vel[v1]) ? -v2 : v2; - if (MoveMotherBrainBomb(k, 7u) & 1) { -LABEL_5:; - int v3 = k >> 1; - ++enemy_projectile_F[v3]; - ++enemy_projectile_F[v3]; - } - } -} - -uint16 EprojInstr_SwitchJump(uint16 k, uint16 j) { // 0x86C173 - return *(uint16 *)RomPtr_86(enemy_projectile_E[k >> 1] + j); -} - -uint16 EprojInstr_UserPalette0(uint16 k, uint16 j) { // 0x86C1B4 - enemy_projectile_gfx_idx[k >> 1] = 0; - return j; -} - -uint8 Eproj_CheckForBombCollisionWithRect(void) { // 0x86C1B8 - if (!bomb_counter) - return 0; - uint16 v1 = 10; - while (1) { - int v2 = v1 >> 1; - if ((projectile_type[v2] & 0xF00) == 1280 && !projectile_variables[v2]) { - uint16 v3 = abs16(projectile_x_pos[v2] - R18_); - bool v4 = v3 < projectile_x_radius[v2]; - uint16 v5 = v3 - projectile_x_radius[v2]; - if (v4 || v5 < R22_) { - uint16 v6 = abs16(projectile_y_pos[v2] - R20_); - v4 = v6 < projectile_y_radius[v2]; - uint16 v7 = v6 - projectile_y_radius[v2]; - if (v4 || v7 < R24_) - break; - } - } - v1 += 2; - if ((int16)(v1 - 20) >= 0) - return 0; - } - return 1; -} - -uint8 Eproj_CheckForEnemyCollisionWithRect(uint16 k) { // 0x86C209 - EnemyData *v1 = gEnemyData(k); - uint16 v2 = abs16(v1->x_pos - R18_); - bool v3 = v2 < v1->x_width; - uint16 v4 = v2 - v1->x_width; - uint8 result = 0; - if (v3 || v4 < R22_) { - uint16 v5 = abs16(v1->y_pos - R20_); - v3 = v5 < v1->y_height; - uint16 v6 = v5 - v1->y_height; - if (v3 || v6 < R24_) - return 1; - } - return result; -} - -uint8 Eproj_CheckForCollisionWithSamus(uint16 v0) { // 0x86C239 - Eproj_InitForCollDetect(v0); - uint16 v1 = abs16(samus_x_pos - R18_); - bool v2 = v1 < samus_x_radius; - uint16 v3 = v1 - samus_x_radius; - uint8 result = 0; - if (v2 || v3 < R22_) { - uint16 v4 = abs16(samus_y_pos - R20_); - v2 = v4 < samus_y_radius; - uint16 v5 = v4 - samus_y_radius; - if (v2 || v5 < R24_) - return 1; - } - return result; -} - -uint16 Math_MultBySin(uint16 a) { // 0x86C26C - R38 = a; - return Math_MultBySinCos(R18_); -} - -uint16 Math_MultByCos(uint16 a) { // 0x86C272 - R38 = a; - return Math_MultBySinCos(R18_ + 64); -} - -uint16 Math_MultBySinCos(uint16 a) { // 0x86C27A - R46 = kSinCosTable8bit_Sext[(a & 0xff) + 64]; - R40 = abs16(R46); - Math_Mult16U(); - uint16 r = *(uint16 *)((uint8 *)&R42 + 1); - return sign16(R46) ? -r : r; -} - - -void Math_Mult16U(void) { // 0x86C29B - uint32 t = (uint32)R38 * (uint32)R40; - R42 = t; - R44 = (t >> 16); -} - -void Eproj_MotherBrainsBlueRingLasers(uint16 j) { // 0x86C2F3 - int v1 = j >> 1; - enemy_projectile_E[v1] = 8; - enemy_projectile_F[v1] = 0; - enemy_projectile_gfx_idx[v1] = 1024; - R18_ = enemy_projectile_init_param; - enemy_projectile_x_vel[v1] = Math_MultBySin(0x450u); - enemy_projectile_y_vel[v1] = Math_MultByCos(0x450u); - enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 10; - enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; - sub_86C320(j); -} - -void sub_86C320(uint16 k) { // 0x86C320 - int v1 = k >> 1; - enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 10; - enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; -} - -void Eproj_MoveToBlueRingSpawnPosition(uint16 k) { // 0x86C335 - int16 v5; - - int v1 = k >> 1; - if (enemy_projectile_E[v1]) { - --enemy_projectile_E[v1]; - sub_86C320(k); - } else { - MoveEprojWithVelocity(k); - uint8 t = CheckForCollisionWithShitroid_DoubleRet(k); - if (t & 0x80) - return; - if (t) { - ++enemy_ram7800[0].kraid.field_28; - BlueRingContactExplosion(k); - uint16 v3 = enemy_ram7800[1].kraid.kraid_healths_8ths[4]; - gExtraEnemyRam7800(enemy_ram7800[1].kraid.kraid_healths_8ths[4])->kraid.kraid_healths_8ths[0] = 16; - EnemyData *v4 = gEnemyData(v3); - v5 = v4->health - 80; - if (v5 < 0) - v5 = 0; - v4->health = v5; - } else if (Eproj_CheckForCollisionWithSamus(k) & 1) { - BlueRingContactExplosion(k); - uint16 v2 = SuitDamageDivision(0x50u); - Samus_DealDamage(v2); - samus_invincibility_timer = 96; - samus_knockback_timer = 5; - knockback_x_dir = (int16)(samus_x_pos - enemy_projectile_x_pos[k >> 1]) >= 0; - } else if (CheckForBlueRingCollisionWithRoom(k) & 1) { - Eproj_Earthqhake5(k); - } - } -} - -uint8 CheckForCollisionWithShitroid_DoubleRet(uint16 v0) { // 0x86C3A9 - if (!enemy_ram7800[1].kraid.kraid_healths_8ths[4]) - return 0; - if (gEnemyData(enemy_ram7800[1].kraid.kraid_healths_8ths[4])->health) { - Eproj_InitForCollDetect(v0); - return Eproj_CheckForEnemyCollisionWithRect(enemy_ram7800[1].kraid.kraid_healths_8ths[4]); - } - enemy_projectile_id[v0 >> 1] = 0; - return 0xff; -} - -uint8 CheckForBlueRingCollisionWithRoom(uint16 k) { // 0x86C3C9 - int16 v2; - int16 v3; - - int v1 = k >> 1; - uint8 result = 1; - if (!sign16(enemy_projectile_y_pos[v1] - 32) && enemy_projectile_y_pos[v1] < 0xD8u) { - v2 = enemy_projectile_x_pos[v1]; - if (v2 >= 0) { - v3 = v2 - layer1_x_pos; - if (v3 >= 0) { - if (sign16(v3 - 248)) - return 0; - } - } - } - return result; -} - -void Eproj_InitForCollDetect(uint16 k) { // 0x86C3E9 - int v1 = k >> 1; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - R22_ = LOBYTE(enemy_projectile_radius[v1]); - R24_ = HIBYTE(enemy_projectile_radius[v1]); -} - -void Eproj_Earthqhake5(uint16 k) { // 0x86C404 - earthquake_timer = 10; - earthquake_type = 5; - BlueRingContactExplosion(k); -} - -void BlueRingContactExplosion(uint16 k) { // 0x86C410 - int v1 = k >> 1; - enemy_projectile_id[v1] = 0; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3u); - QueueSfx3_Max6(0x13u); - sub_86C42E(k); -} - -void sub_86C42E(uint16 k) { // 0x86C42E - enemy_projectile_gfx_idx[k >> 1] = 0; -} - -void EprojInit_MotherBrainBomb(uint16 j) { // 0x86C482 - *((uint8 *)enemy_projectile_1A27 + j) = enemy_projectile_init_param; - int v1 = j >> 1; - enemy_projectile_y_vel[v1] = 256; - enemy_projectile_x_vel[v1] = 224; - enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 12; - enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; - enemy_projectile_gfx_idx[v1] = 1024; - enemy_projectile_E[v1] = 112; - enemy_projectile_F[v1] = 0; - ++enemy_ram7800[1].kraid.kraid_mouth_flags; -} - -uint8 MotherBrainBomb_Bomb_CollDetect_DoubleRet(uint16 k) { // 0x86C564 - int v1 = k >> 1; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - R22_ = LOBYTE(enemy_projectile_radius[v1]); - R24_ = HIBYTE(enemy_projectile_radius[v1]); - if (!Eproj_CheckForBombCollisionWithRect()) - return 0; - - --enemy_ram7800[1].kraid.kraid_mouth_flags; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_id[v1] = 0; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyDrops(addr_kEnemyDef_EC3F, k); - return 1; // double return -} - -uint8 MoveMotherBrainBomb(uint16 k, uint16 a) { // 0x86C5C2 - int v2 = k >> 1; - enemy_projectile_y_vel[v2] += a; - MoveEprojWithVelocity(k); - if (!sign16(enemy_projectile_x_pos[v2] - 240)) - enemy_projectile_x_vel[v2] = -enemy_projectile_x_vel[v2]; - if (sign16(enemy_projectile_y_pos[v2] - 208)) - return 0; - enemy_projectile_y_pos[v2] = 208; - enemy_projectile_x_vel[v2] = sign16(enemy_projectile_x_vel[v2]) ? -enemy_projectile_E[v2] : enemy_projectile_E[v2]; - enemy_projectile_y_vel[v2] = -512; - return 1; -} - -void sub_86C605(uint16 j) { // 0x86C605 - int16 v2; - int16 v3; - - int v1 = j >> 1; - enemy_projectile_E[v1] = 0; - enemy_projectile_F[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_y_subpos[v1] = 0; - *(uint16 *)&extra_enemy_ram8000[0].pad[6] = 0; - *(uint16 *)&extra_enemy_ram8000[0].pad[10] = 0; - enemy_projectile_gfx_idx[v1] = 1024; - v2 = enemy_data[0].x_pos + 64; - enemy_projectile_x_pos[v1] = enemy_data[0].x_pos + 64; - *(uint16 *)&extra_enemy_ram8000[0].pad[8] = v2; - R18_ = samus_x_pos - v2; - v3 = enemy_data[0].y_pos - 48; - enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - 48; - *(uint16 *)&extra_enemy_ram8000[0].pad[12] = v3; - R20_ = samus_y_pos - v3; - R18_ = (uint8)-(int8)(CalculateAngleFromXY() + 0x80); - *(uint16 *)&extra_enemy_ram8000[0].pad[18] = R18_; - *(uint16 *)&extra_enemy_ram8000[0].pad[14] = Math_MultBySin(0xC00u); - *(uint16 *)&extra_enemy_ram8000[0].pad[16] = Math_MultByCos(0xC00u); -} - -void EprojInit_MotherBrainDeathBeemFired(uint16 j) { // 0x86C684 - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = *(uint16 *)&extra_enemy_ram8000[0].pad[8]; - enemy_projectile_1A27[v1] = *(uint16 *)&extra_enemy_ram8000[0].pad[6]; - enemy_projectile_y_pos[v1] = *(uint16 *)&extra_enemy_ram8000[0].pad[12]; - enemy_projectile_y_subpos[v1] = *(uint16 *)&extra_enemy_ram8000[0].pad[10]; - enemy_projectile_x_vel[v1] = *(uint16 *)&extra_enemy_ram8000[0].pad[14]; - enemy_projectile_y_vel[v1] = *(uint16 *)&extra_enemy_ram8000[0].pad[16]; - MoveEprojWithVelocity(j); - *(uint16 *)&extra_enemy_ram8000[0].pad[8] = enemy_projectile_x_pos[v1]; - *(uint16 *)&extra_enemy_ram8000[0].pad[6] = enemy_projectile_1A27[v1]; - *(uint16 *)&extra_enemy_ram8000[0].pad[12] = enemy_projectile_y_pos[v1]; - *(uint16 *)&extra_enemy_ram8000[0].pad[10] = enemy_projectile_y_subpos[v1]; - R18_ = (uint8)(extra_enemy_ram8000[0].pad[18] + NextRandom()); - uint16 rv = NextRandom(); - enemy_projectile_x_vel[v1] = Math_MultBySin(rv & 0x700); - enemy_projectile_y_vel[v1] = Math_MultByCos(random_number & 0x700); - MoveEprojWithVelocity(j); - if (sign16(enemy_projectile_y_pos[v1] - 34) - || !sign16(enemy_projectile_y_pos[v1] - 206) - || sign16(enemy_projectile_x_pos[v1] - 2) - || !sign16(enemy_projectile_x_pos[v1] - 238)) { - enemy_projectile_id[v1] = 0; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x1D); - QueueSfx3_Max6(0x13u); - earthquake_timer = 10; - earthquake_type = 5; - } else { - enemy_projectile_E[v1] = ((uint8)enemy_projectile_E[v1] + 1) & 3; - enemy_projectile_F[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - } -} - -void SpawnMotherBrainDeathBeam(uint16 x) { // 0x86C7FB - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainDeathBeamFired, enemy_projectile_E[x >> 1]); -} - -void EprojInit_MotherBrainRainbowBeam(uint16 j) { // 0x86C80A - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - EprojPreInstr_MotherBrainRainbowBeam(j); -} - -void EprojPreInstr_MotherBrainRainbowBeam(uint16 k) { // 0x86C814 - int v2 = k >> 1; - enemy_projectile_x_pos[v2] = enemy_data[1].x_pos; - enemy_projectile_y_pos[v2] = enemy_data[1].y_pos; -} - -static const int16 kEprojInit_MotherBrainsDrool[12] = { 6, 0x14, 0xe, 0x12, 8, 0x17, 0xa, 0x13, 0xb, 0x19, 0xc, 0x12 }; - -void EprojInit_MotherBrainsDrool(uint16 j) { // 0x86C843 - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - enemy_projectile_E[v1] = enemy_projectile_init_param; - EprojPreInstr_C84D(j); -} - -void EprojPreInstr_C84D(uint16 k) { // 0x86C84D - int v1 = k >> 1; - int v2 = (uint16)(4 * enemy_projectile_E[v1]) >> 1; - enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + kEprojInit_MotherBrainsDrool[v2]; - enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + kEprojInit_MotherBrainsDrool[v2 + 1]; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - -} - -void EprojInit_MotherBrainsDrool_Falling(uint16 k) { // 0x86C886 - int v1 = k >> 1; - enemy_projectile_y_vel[v1] += 12; - if (MoveEprojWithVelocityY(k) >= 0xD7u) { - enemy_projectile_y_pos[v1] -= 4; - enemy_projectile_instr_list_ptr[v1] = addr_off_86C8E1; - enemy_projectile_instr_timers[v1] = 1; - } -} - -uint16 EprojInstr_Add12ToY(uint16 k, uint16 j) { // 0x86C8D0 - enemy_projectile_y_pos[k >> 1] += 12; - return j; -} - -void EprojInit_MotherBrainsDeathExplosion(uint16 j) { // 0x86C8F5 - int v1 = j >> 1; - enemy_projectile_instr_list_ptr[v1] = off_86C929[enemy_projectile_init_param]; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_gfx_idx[v1] = 0; - enemy_projectile_x_vel[v1] = R18_; - enemy_projectile_y_vel[v1] = R20_; - EprojPreInit_MotherBrainsDeathExplosion_0(j); -} - -void EprojPreInit_MotherBrainsDeathExplosion_0(uint16 k) { // 0x86C914 - int v2 = k >> 1; - enemy_projectile_x_pos[v2] = enemy_data[0].x_pos + enemy_projectile_x_vel[v2]; - enemy_projectile_y_pos[v2] = enemy_data[0].y_pos + enemy_projectile_y_vel[v2]; -} - -void EprojInit_MotherBrainsRainbowBeamExplosion(uint16 j) { // 0x86C92F - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - uint16 v2 = R18_; - enemy_projectile_x_vel[v1] = R18_; - enemy_projectile_x_pos[v1] = samus_x_pos + v2; - uint16 v3 = R20_; - enemy_projectile_y_vel[v1] = R20_; - enemy_projectile_y_pos[v1] = samus_y_pos + v3; -} - -void EprojPreInstr_MotherBrainsRainbowBeamExplosion(uint16 k) { // 0x86C94C - int v1 = k >> 1; - enemy_projectile_x_pos[v1] = samus_x_pos + enemy_projectile_x_vel[v1]; - enemy_projectile_y_pos[v1] = samus_y_pos + enemy_projectile_y_vel[v1]; -} - -void EprojInit_MotherBrainEscapeDoorParticles(uint16 j) { // 0x86C961 - static const int16 kEprojInit_MotherBrainEscapeDoorParticles_X[16] = { - 0, -0x20, 0, -0x18, 0, -0x10, 0, -8, 0, 0, 0, 8, - 0, 0x10, 0, 0x18, - }; - static const int16 kEprojInit_MotherBrainEscapeDoorParticles_Xvel[16] = { - 0x500, -0x200, 0x500, -0x100, 0x500, -0x100, 0x500, -0x80, 0x500, -0x80, 0x500, 0x80, - 0x500, -0x100, 0x500, 0x200, - }; - - - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - int v2 = (uint16)(4 * enemy_projectile_init_param) >> 1; - enemy_projectile_x_pos[v1] = kEprojInit_MotherBrainEscapeDoorParticles_X[v2] + 16; - enemy_projectile_y_pos[v1] = kEprojInit_MotherBrainEscapeDoorParticles_X[v2 + 1] + 128; - enemy_projectile_x_vel[v1] = kEprojInit_MotherBrainEscapeDoorParticles_Xvel[v2]; - enemy_projectile_y_vel[v1] = kEprojInit_MotherBrainEscapeDoorParticles_Xvel[v2 + 1]; - enemy_projectile_E[v1] = 32; -} - -void EprojPreInstr_MotherBrainsExplodedDoorParticles(uint16 k) { // 0x86C9D2 - int16 v2; - - int v1 = k >> 1; - v2 = abs16(enemy_projectile_x_vel[v1]) - 16; - if (v2 < 0) - v2 = 0; - enemy_projectile_x_vel[v1] = sign16(enemy_projectile_x_vel[v1]) ? -v2 : v2; - enemy_projectile_y_vel[v1] += 32; - MoveEprojWithVelocity(k); - if ((--enemy_projectile_E[v1] & 0x8000u) != 0) { - enemy_projectile_id[v1] = 0; - uint16 v4 = enemy_projectile_y_pos[v1] - 4; - enemy_projectile_y_pos[v1] = v4; - R20_ = v4; - R18_ = enemy_projectile_x_pos[v1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); - } -} - -void EprojInit_MotherBrainPurpleBreathBig(uint16 j) { // 0x86CA6A - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 6; - enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; -} - -void EprojInit_MotherBrainPurpleBreathSmall(uint16 j) { // 0x86CA83 - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 0; - enemy_projectile_x_pos[v1] = enemy_data[1].x_pos + 6; - enemy_projectile_y_pos[v1] = enemy_data[1].y_pos + 16; - enemy_ram7800[1].kraid.kraid_hurt_frame = 1; -} - -uint16 EprojInstr_MotherBrainPurpleBreathIsActive(uint16 k, uint16 j) { // 0x86CAEE - enemy_ram7800[1].kraid.kraid_hurt_frame = 0; - return j; -} - -void EprojInit_TimeBombSetJapaneseText(uint16 j) { // 0x86CAF6 - enemy_projectile_gfx_idx[j >> 1] = 0; - EprojPreInstr_TimeBombSetJapaneseText(j); -} - -void EprojPreInstr_TimeBombSetJapaneseText(uint16 k) { // 0x86CAFA - int v1 = k >> 1; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_x_pos[v1] = 128; - enemy_projectile_y_pos[v1] = 192; -} -void EprojInit_MotherBrainTubeFalling(uint16 j) { // 0x86CBC9 - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] = 3584; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - enemy_projectile_x_pos[v1] = R18_; - enemy_projectile_y_pos[v1] = R20_; - enemy_projectile_E[v1] = FUNC16(MotherBrainTubeFallingFunc_GenerateExplosion); -} - -void CallMotherBrainTubeFallingFunc(uint32 ea, uint16 k) { - switch (ea) { - case fnMotherBrainTubeFallingFunc_GenerateExplosion: MotherBrainTubeFallingFunc_GenerateExplosion(k); return; - case fnMotherBrainTubeFallingFunc_Falling: MotherBrainTubeFallingFunc_Falling(k); return; - default: Unreachable(); - } -} - -void EprojPreInstr_MotherBrainTubeFalling(uint16 k) { // 0x86CBE7 - CallMotherBrainTubeFallingFunc(enemy_projectile_E[k >> 1] | 0x860000, k); -} - -void MotherBrainTubeFallingFunc_GenerateExplosion(uint16 k) { // 0x86CBEA - int v1 = k >> 1; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1] + 8; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); - enemy_projectile_E[v1] = FUNC16(MotherBrainTubeFallingFunc_Falling); - MotherBrainTubeFallingFunc_Falling(k); -} - -void MotherBrainTubeFallingFunc_Falling(uint16 k) { // 0x86CC08 - int16 v2; - - int v1 = k >> 1; - enemy_projectile_y_vel[v1] += 6; - v2 = MoveEprojWithVelocityY(k); - if (!sign16(v2 - 208)) { - enemy_projectile_id[v1] = 0; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0xC); - } -} - -static const int16 kEprojInit_MotherBrainGlassShatteringShard_X[3] = { 8, -40, -16 }; -static const int16 kEprojInit_MotherBrainGlassShatteringShard_Y[3] = { 32, 32, 32 }; - -void EprojInit_MotherBrainGlassShatteringShard(uint16 j) { // 0x86CDC5 - uint16 v1 = (2 * NextRandom()) & 0x1FE; - int v2 = j >> 1; - enemy_projectile_E[v2] = v1; - int v3 = v1 >> 1; - enemy_projectile_x_vel[v2] = kSinCosTable8bit_Sext[v3 + 64]; - enemy_projectile_y_vel[v2] = 4 * kSinCosTable8bit_Sext[v3]; - enemy_projectile_instr_list_ptr[v2] = kEprojInit_MotherBrainGlassShatteringShard_InstrPtrs[(uint16)((v1 >> 4) & 0x1E) >> 1]; - enemy_projectile_gfx_idx[v2] = 1600; - CalculatePlmBlockCoords(plm_id); - int v4 = enemy_projectile_init_param >> 1; - enemy_projectile_x_pos[v2] = kEprojInit_MotherBrainGlassShatteringShard_X[v4] + 16 * plm_x_block; - enemy_projectile_y_pos[v2] = kEprojInit_MotherBrainGlassShatteringShard_Y[v4] + 16 * plm_y_block; - enemy_projectile_x_pos[v2] += (NextRandom() & 0xF) - 8; - enemy_projectile_y_pos[v2] += (NextRandom() & 0xF) - 8; -} - -void EprojInit_MotherBrainGlassShatteringSparkle(uint16 j) { // 0x86CE6D - int v1 = enemy_projectile_init_param >> 1; - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = enemy_projectile_x_pos[v1] + (NextRandom() & 0x1F) - 16; - enemy_projectile_y_pos[v2] = enemy_projectile_y_pos[v1] + (NextRandom() & 0x1F) - 16; - enemy_projectile_gfx_idx[v2] = 1600; -} - -void EprojPreInstr_MotherBrainGlassShatteringShard(uint16 k) { // 0x86CE9B - int16 v2; - int16 v5; - - R18_ = 0; - R20_ = 0; - int v1 = k >> 1; - v2 = enemy_projectile_x_vel[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - uint16 v3 = enemy_projectile_1A27[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - enemy_projectile_1A27[v1] = R18_ + v3; - enemy_projectile_x_pos[v1] += R20_ + v4; - R18_ = 0; - R20_ = 0; - v5 = enemy_projectile_y_vel[v1]; - if (v5 < 0) - --R20_; - R19_ = v5; - uint16 v6 = enemy_projectile_y_subpos[v1]; - v4 = __CFADD__uint16(R18_, v6); - enemy_projectile_y_subpos[v1] = R18_ + v6; - uint16 v7 = R20_ + v4 + enemy_projectile_y_pos[v1]; - enemy_projectile_y_pos[v1] = v7; - if ((v7 & 0xFF00) != 0) { - enemy_projectile_id[v1] = 0; - } else { - enemy_projectile_y_vel[v1] += 32; - if ((NextRandom() & 0x420) == 0) - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainGlassShatteringSparkle, k); - } -} - -void EprojInit_KiHunterAcidSpitLeft(uint16 j) { // 0x86CF90 - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = -768; - enemy_projectile_x_pos[v2] = gEnemyData(cur_enemy_index)->x_pos - 22; - EprojInit_KiHunterAcidSpitCommon(cur_enemy_index, j); -} - -void EprojInit_KiHunterAcidSpitRight(uint16 j) { // 0x86CFA6 - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = 768; - enemy_projectile_x_pos[v2] = gEnemyData(cur_enemy_index)->x_pos + 22; - EprojInit_KiHunterAcidSpitCommon(cur_enemy_index, j); -} - -void EprojInit_KiHunterAcidSpitCommon(uint16 k, uint16 j) { // 0x86CFBA - int v2 = j >> 1; - enemy_projectile_y_vel[v2] = 0; - enemy_projectile_y_pos[v2] = gEnemyData(k)->y_pos - 16; - enemy_projectile_y_subpos[v2] = 0; - enemy_projectile_1A27[v2] = 0; -} - -void sub_86CFD5(uint16 k) { // 0x86CFD5 - int v1 = k >> 1; - enemy_projectile_pre_instr[v1] = FUNC16(sub_86CFF8); - enemy_projectile_x_pos[v1] -= 19; -} - -void sub_86CFE6(uint16 k) { // 0x86CFE6 - int v1 = k >> 1; - enemy_projectile_pre_instr[v1] = FUNC16(sub_86CFF8); - enemy_projectile_x_pos[v1] += 19; -} - -void sub_86CFF8(uint16 k) { // 0x86CFF8 - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - int v3 = k >> 1; - enemy_projectile_instr_list_ptr[v3] = addr_off_86CF56; - enemy_projectile_instr_timers[v3] = 1; - } else if (EnemyProjectileBlockCollisition_Horiz(k) & 1) { - enemy_projectile_x_vel[k >> 1] = 0; - } else { - int v1 = k >> 1; - uint16 v2 = enemy_projectile_y_vel[v1] + 16; - enemy_projectile_y_vel[v1] = v2; - if (!sign16(v2 - 512)) - v2 = 512; - enemy_projectile_y_vel[v1] = v2; - } -} - -void EprojInit_KagosBugs(uint16 j) { // 0x86D088 - int v2 = j >> 1; - enemy_projectile_F[v2] = cur_enemy_index; - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos; - enemy_projectile_y_pos[v2] = v3->y_pos; - uint16 v4 = (random_number & 7) + 1; - enemy_projectile_G[v2] = v4; - enemy_projectile_E[v2] = v4 + 4; - enemy_projectile_pre_instr[v2] = FUNC16(EprojPreInstr_KagosBugs); -} - -void EprojPreInstr_KagosBugs_Func1(uint16 k) { // 0x86D0B3 - int v1 = k >> 1; - uint16 v2 = enemy_projectile_E[v1]; - if (v2) { - uint16 v3 = v2 - 1; - enemy_projectile_E[v1] = v3; - if (!v3) - QueueSfx2_Max6(0x6Cu); - } -} - -void EprojPreInstr_KagosBugs(uint16 k) { // 0x86D0CA - EprojPreInstr_KagosBugs_Func1(k); - EprojPreInstr_KagosBugs_Func2(k); - int v1 = k >> 1; - if (enemy_projectile_G[v1]) { - --enemy_projectile_G[v1]; - } else { - enemy_projectile_instr_list_ptr[v1] = addr_word_86D052; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_pre_instr[v1] = FUNC16(nullsub_302); - } -} - -static const uint16 word_86D082 = 0xe0; - -void EprojPreInstr_D0EC(uint16 k) { // 0x86D0EC - EprojPreInstr_KagosBugs_Func1(k); - EprojPreInstr_KagosBugs_Func2(k); - if (EnemyProjectileBlockCollisition_Horiz(k)) { - enemy_projectile_x_vel[k >> 1] = 0; - goto LABEL_6; - } - if (EnemyProjectileBlockCollisition_Vertical(k)) { -LABEL_6: - enemy_projectile_y_vel[k >> 1] = 256; -LABEL_7:; - enemy_projectile_pre_instr[k >> 1] = FUNC16(EprojPreInstr_D128); - enemy_projectile_instr_list_ptr[k >> 1] = addr_word_86D04A; - enemy_projectile_instr_timers[k >> 1] = 1; - return; - } - uint16 v2 = enemy_projectile_y_vel[k >> 1]; - bool v3 = (int16)(word_86D082 + v2) < 0; - enemy_projectile_y_vel[k >> 1] = word_86D082 + v2; - if (!v3) { - goto LABEL_7; - } -} - -void EprojPreInstr_D128(uint16 v0) { // 0x86D128 - EprojPreInstr_KagosBugs_Func1(v0); - EprojPreInstr_KagosBugs_Func2(v0); - if (EnemyProjectileBlockCollisition_Horiz(v0) & 1) { - enemy_projectile_x_vel[v0 >> 1] = 0; - } else if (EnemyProjectileBlockCollisition_Vertical(v0) & 1) { - int v1 = v0 >> 1; - enemy_projectile_pre_instr[v1] = FUNC16(nullsub_302); - enemy_projectile_instr_list_ptr[v1] = addr_word_86D03C; - enemy_projectile_instr_timers[v1] = 1; - } else { - enemy_projectile_y_vel[v0 >> 1] += word_86D082; - } -} - -static const uint16 g_word_86D086 = 0x200; -static const uint16 g_word_86D084 = 0x30; - -uint16 EprojInstr_D15C(uint16 k, uint16 j) { // 0x86D15C - EprojPreInstr_KagosBugs_Func1(k); - EprojPreInstr_KagosBugs_Func2(k); - int v2 = k >> 1; - - uint16 t = (random_number & 0x300) + 2048; - enemy_projectile_y_vel[v2] = -t; - EnemyData *v3 = gEnemyData(enemy_projectile_F[v2]); - uint16 t2 = v3->x_pos - enemy_projectile_x_pos[v2]; - - if ((int16)(abs16(t2) - g_word_86D084) >= 0) - t = sign16(t2) ? -1 : 0; - - uint16 v4 = g_word_86D086; - if (t & 0x100) - v4 = -v4; - enemy_projectile_x_vel[v2] = v4; - enemy_projectile_pre_instr[v2] = FUNC16(EprojPreInstr_D0EC); - - return j; -} - -uint16 EprojInstr_D1B6(uint16 k, uint16 j) { // 0x86D1B6 - int v1 = k >> 1; - enemy_projectile_G[v1] = (random_number & 0x1F) + 1; - enemy_projectile_pre_instr[v1] = FUNC16(EprojPreInstr_KagosBugs); - - return j; -} - - -uint16 EprojInstr_D1C7(uint16 v0, uint16 j) { // 0x86D1C7 - enemy_projectile_gfx_idx[v0 >> 1] = 0; - return j; -} - -uint16 EprojInstr_D1CE(uint16 v0, uint16 j) { // 0x86D1CE - int v1 = v0 >> 1; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyDrops(addr_kEnemyDef_E7FF, v0); - return j; -} - -void EprojPreInstr_KagosBugs_Func2(uint16 k) { // 0x86D1E4 - int v1 = k >> 1; - EnemyData *v2 = gEnemyData(enemy_projectile_F[v1]); - uint16 v3 = abs16(v2->x_pos - enemy_projectile_x_pos[v1]); - if (!sign16(v3 - 23)) - enemy_projectile_properties[v1] |= 0x8000u; -} - -void EprojInit_MaridiaFloatersSpikes(uint16 j) { // 0x86D23A - int v1 = j >> 1; - enemy_projectile_1A27[v1] = 0; - enemy_projectile_y_subpos[v1] = 0; - enemy_projectile_x_vel[v1] = 0; - enemy_projectile_y_vel[v1] = 0; - EnemyData *v2 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v1] = v2->x_pos; - enemy_projectile_y_pos[v1] = v2->y_pos; - enemy_projectile_E[v1] = enemy_projectile_init_param; -} - -static const int16 word_86D21A[8] = { 0, 32, 32, 32, 0, -32, -32, -32 }; -static const int16 word_86D22A[8] = { -32, -32, 0, 32, 32, 32, 0, -32 }; - -void EprojPreInstr_MaridiaFloatersSpikes(uint16 k) { // 0x86D263 - int v1 = k >> 1; - enemy_projectile_x_vel[v1] += word_86D21A[enemy_projectile_E[v1]]; - if (EnemyProjectileBlockCollisition_Horiz(k) & 1 - || (enemy_projectile_y_vel[v1] += word_86D22A[enemy_projectile_E[v1]], - EnemyProjectileBlockCollisition_Vertical(k) & 1)) { - enemy_projectile_instr_list_ptr[v1] = addr_off_86D218; - enemy_projectile_instr_timers[v1] = 1; - } -} - -void EprojInit_WreckedShipRobotLaserDown(uint16 j) { // 0x86D30C - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = gEnemyData(cur_enemy_index)->ai_var_A; - enemy_projectile_y_vel[v2] = 128; - enemy_projectile_gfx_idx[v2] = 0; - EprojInit_WreckedShipRobotLaserCommon(cur_enemy_index, j); -} - -void EprojInit_WreckedShipRobotLaserHorizontal(uint16 j) { // 0x86D32E - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = gEnemyData(cur_enemy_index)->ai_var_A; - enemy_projectile_y_vel[v2] = 0; - EprojInit_WreckedShipRobotLaserCommon(cur_enemy_index, j); -} - -void EprojInit_WreckedShipRobotLaserUp(uint16 j) { // 0x86D341 - int v2 = j >> 1; - enemy_projectile_x_vel[v2] = gEnemyData(cur_enemy_index)->ai_var_A; - enemy_projectile_y_vel[v2] = -128; - EprojInit_WreckedShipRobotLaserCommon(cur_enemy_index, j); -} - -void EprojInit_WreckedShipRobotLaserCommon(uint16 k, uint16 j) { // 0x86D35B - int16 x_pos; - uint16 v5; - - EnemyData *v2 = gEnemyData(k); - int v3 = j >> 1; - enemy_projectile_y_pos[v3] = v2->y_pos - 16; - x_pos = v2->x_pos; - if (sign16(enemy_projectile_x_vel[v3])) - v5 = x_pos - 4; - else - v5 = x_pos + 4; - enemy_projectile_x_pos[v3] = v5; - enemy_projectile_y_subpos[v3] = 0; - enemy_projectile_1A27[v3] = 0; - if ((int16)(v2->x_width + v2->x_pos - layer1_x_pos) >= 0 - && (int16)(v2->x_pos - v2->x_width - 257 - layer1_x_pos) < 0 - && (int16)(v2->y_height + v2->y_pos - layer1_y_pos) >= 0 - && (int16)(v2->y_pos - v2->y_height - 224) < 0) { - QueueSfx2_Max6(0x67u); - } -} - -void EprojPreInstr_WreckedShipRobotLaser(uint16 k) { // 0x86D3BF - int v1 = k >> 1; - enemy_projectile_gfx_idx[v1] = 0; - if (EnemyProjectileBlockCollisition_Horiz(k) & 1 || EnemyProjectileBlockCollisition_Vertical(k) & 1) - enemy_projectile_id[v1] = 0; -} - -uint16 EprojInstr_AssignNewN00bTubeShardVelocity(uint16 k, uint16 j) { // 0x86D5E1 - NextRandom(); - int v2 = k >> 1; - enemy_projectile_x_vel[v2] = *(uint16 *)((uint8 *)&random_number + 1); - enemy_projectile_y_vel[v2] = 192; - return j; -} - -uint16 EprojInstr_SetN00bTubeShardX(uint16 k, uint16 j) { // 0x86D5F2 - int v2 = k >> 1; - if (nmi_frame_counter_word & 1) { - enemy_projectile_x_pos[v2] = enemy_projectile_F[v2]; - enemy_projectile_spritemap_ptr[v2] = *(uint16 *)RomPtr_86(j); - } else { - enemy_projectile_x_pos[v2] = 128 - enemy_projectile_F[v2] + 128; - enemy_projectile_spritemap_ptr[v2] = *((uint16 *)RomPtr_86(j) + 1); - } - int v3 = k >> 1; - enemy_projectile_instr_list_ptr[v3] = j + 4; - enemy_projectile_instr_timers[v3] = 1; - return 0; -} - -uint16 EprojInstr_D62A(uint16 k, uint16 j) { // 0x86D62A - if (nmi_frame_counter_word & 1) - enemy_projectile_x_pos[k >> 1] = enemy_projectile_F[k >> 1]; - else - enemy_projectile_x_pos[k >> 1] = -4608; - int v2 = k >> 1; - enemy_projectile_spritemap_ptr[v2] = *(uint16 *)RomPtr_86(j); - enemy_projectile_instr_list_ptr[v2] = j + 2; - enemy_projectile_instr_timers[v2] = 1; - return 0; -} - -uint16 EprojInstr_SetXvelRandom(uint16 k, uint16 j) { // 0x86D69A - NextRandom(); - enemy_projectile_x_vel[k >> 1] = *(uint16 *)((uint8 *)&random_number + 1); - return j; -} - -void EprojInit_N00bTubeCrack(uint16 j) { // 0x86D6A5 - CalculatePlmBlockCoords(plm_id); - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = 16 * plm_x_block + 96; - enemy_projectile_y_pos[v1] = 16 * plm_y_block + 48; -} - -static const int16 kEprojInit_N00bTubeShards_X[10] = { -56, -64, -20, -40, -64, -48, -24, -40, 0, -8 }; -static const int16 kEprojInit_N00bTubeShards_Y[10] = { 8, -12, -26, -24, -32, 28, 16, -8, -24, 16 }; -static const int16 kEprojInit_N00bTubeShards_Xvel[10] = { -384, -384, -160, -288, -288, -320, -96, -352, 0, -64 }; -static const int16 kEprojInit_N00bTubeShards_Yvel[10] = { 320, -256, -416, -288, -288, 448, 576, -96, -288, 384 }; - -void EprojInit_N00bTubeShards(uint16 j) { // 0x86D6C9 - CalculatePlmBlockCoords(plm_id); - int v1 = enemy_projectile_init_param >> 1; - int v2 = j >> 1; - enemy_projectile_F[v2] = kEprojInit_N00bTubeShards_X[v1] + 16 * plm_x_block + 96; - enemy_projectile_E[v2] = 0; - enemy_projectile_y_pos[v2] = kEprojInit_N00bTubeShards_Y[v1] + 16 * plm_y_block + 48; - enemy_projectile_instr_list_ptr[v2] = kEprojInit_N00bTubeShards_InstrPtrs[v1]; - enemy_projectile_x_vel[v2] = kEprojInit_N00bTubeShards_Xvel[v1]; - enemy_projectile_y_vel[v2] = kEprojInit_N00bTubeShards_Yvel[v1]; -} - -static const uint16 kEprojInit_N00bTubeReleasedAirBubbles_X[6] = { 40, 80, 104, 120, 152, 184 }; -static const uint16 kEprojInit_N00bTubeReleasedAirBubbles_Y[6] = { 80, 72, 84, 32, 64, 84 }; - -void EprojInit_N00bTubeReleasedAirBubbles(uint16 j) { // 0x86D774 - CalculatePlmBlockCoords(plm_id); - int v1 = enemy_projectile_init_param >> 1; - int v2 = j >> 1; - enemy_projectile_F[v2] = kEprojInit_N00bTubeReleasedAirBubbles_X[v1] + 16 * plm_x_block; - enemy_projectile_E[v2] = 0; - enemy_projectile_y_pos[v2] = kEprojInit_N00bTubeReleasedAirBubbles_Y[v1] + 16 * plm_y_block; - enemy_projectile_y_vel[v2] = -1280; -} - -void sub_86D7BF(uint16 k) { // 0x86D7BF - int v1 = k >> 1; - if (enemy_projectile_x_pos[v1] != 0xEE00) - enemy_projectile_E[v1] = enemy_projectile_x_pos[v1]; - if (nmi_frame_counter_word & 1) - enemy_projectile_x_pos[v1] = -4608; - else - enemy_projectile_x_pos[v1] = enemy_projectile_E[v1]; -} - -void sub_86D7DE(uint16 k) { // 0x86D7DE - R18_ = 0; - R20_ = 0; - R19_ = 192; - int v1 = k >> 1; - uint16 v2 = enemy_projectile_y_subpos[v1]; - bool v3 = __CFADD__uint16(R18_, v2); - enemy_projectile_y_subpos[v1] = R18_ + v2; - enemy_projectile_y_pos[v1] += R20_ + v3; -} - -void EprojPreInstr_N00bTubeShards(uint16 k) { // 0x86D7FD - int16 v2; - int16 v5; - - R18_ = 0; - R20_ = 0; - int v1 = k >> 1; - v2 = enemy_projectile_x_vel[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - uint16 v3 = enemy_projectile_E[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - enemy_projectile_E[v1] = R18_ + v3; - enemy_projectile_F[v1] += R20_ + v4; - R18_ = 0; - R20_ = 0; - v5 = enemy_projectile_y_vel[v1]; - if (v5 < 0) - --R20_; - R19_ = v5; - uint16 v6 = enemy_projectile_y_subpos[v1]; - v4 = __CFADD__uint16(R18_, v6); - enemy_projectile_y_subpos[v1] = R18_ + v6; - enemy_projectile_y_pos[v1] += R20_ + v4; - Eproj_DeleteIfYposOutside(k); -} - -void sub_86D83D(uint16 k) { // 0x86D83D - int16 v8; - - uint16 v1 = enemy_projectile_x_vel[k >> 1] & 0x17E | 0x80; - R18_ = 0; - R20_ = 0; - int v2 = v1 >> 1; - uint16 v3 = kSinCosTable8bit_Sext[v2 + 64]; - if ((kSinCosTable8bit_Sext[v2 + 64] & 0x8000u) != 0) - --R20_; - R19_ = (int16)v3 >> 2; - uint16 v5 = enemy_projectile_index; - int v6 = enemy_projectile_index >> 1; - uint16 v7 = enemy_projectile_E[v6]; - bool v4 = __CFADD__uint16(R18_, v7); - enemy_projectile_E[v6] = R18_ + v7; - enemy_projectile_F[v6] += R20_ + v4; - enemy_projectile_x_vel[v6] += 2; - R18_ = 0; - R20_ = 0; - v8 = enemy_projectile_y_vel[v6]; - if (v8 < 0) - --R20_; - R19_ = v8; - uint16 v9 = enemy_projectile_y_subpos[v6]; - v4 = __CFADD__uint16(R18_, v9); - enemy_projectile_y_subpos[v6] = R18_ + v9; - enemy_projectile_y_pos[v6] += R20_ + v4; - Eproj_DeleteIfYposOutside(v5); -} - -void sub_86D89F(uint16 k) { // 0x86D89F - uint16 v1 = enemy_projectile_x_vel[k >> 1] & 0x17E | 0x80; - R18_ = 0; - R20_ = 0; - int v2 = v1 >> 1; - uint16 v3 = kSinCosTable8bit_Sext[v2 + 64]; - if ((kSinCosTable8bit_Sext[v2 + 64] & 0x8000u) != 0) - --R20_; - R19_ = (int16)v3 >> 2; - int v5 = enemy_projectile_index >> 1; - uint16 v6 = enemy_projectile_E[v5]; - bool v4 = __CFADD__uint16(R18_, v6); - enemy_projectile_E[v5] = R18_ + v6; - enemy_projectile_F[v5] += R20_ + v4; - enemy_projectile_x_vel[v5] += 4; - sub_86D8DF(enemy_projectile_index); -} - -void sub_86D8DF(uint16 k) { // 0x86D8DF - int v5 = k >> 1; - int16 v7; - R18_ = 0; - R20_ = 0; - v7 = enemy_projectile_y_vel[v5]; - if (v7 < 0) - --R20_; - R19_ = v7; - uint16 v8 = enemy_projectile_y_subpos[v5]; - bool v4 = __CFADD__uint16(R18_, v8); - enemy_projectile_y_subpos[v5] = R18_ + v8; - enemy_projectile_y_pos[v5] += R20_ + v4; - enemy_projectile_x_pos[v5] = enemy_projectile_F[v5]; -} - - -void sub_86D992(uint16 v0) { // 0x86D992 - uint16 v1 = enemy_projectile_init_param; - int v2 = v0 >> 1; - enemy_projectile_E[v2] = enemy_projectile_init_param; - enemy_projectile_instr_list_ptr[v2] = off_86D96A[v1 >> 1]; - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos; - enemy_projectile_1A27[v2] = v3->x_subpos; - enemy_projectile_y_pos[v2] = v3->y_pos; - enemy_projectile_y_subpos[v2] = v3->y_subpos; - enemy_projectile_y_vel[v2] = -512; - enemy_projectile_x_vel[v2] = 512; - if (!sign16(enemy_projectile_init_param - 12)) { - enemy_projectile_y_vel[v2] = -384; - enemy_projectile_x_vel[v2] = 384; - } -} - -static Func_X_V *const kEprojPreInstr_SpikeShootingPlantSpikes[10] = { // 0x86D9DB - EprojPreInstr_SpikeShootingPlantSpikes_0_MoveX1, - EprojPreInstr_SpikeShootingPlantSpikes_1_MoveY1, - EprojPreInstr_SpikeShootingPlantSpikes_2_MoveX2, - EprojPreInstr_SpikeShootingPlantSpikes_0_MoveX1, - EprojPreInstr_SpikeShootingPlantSpikes_4_MoveY2, - EprojPreInstr_SpikeShootingPlantSpikes_2_MoveX2, - EprojPreInstr_SpikeShootingPlantSpikes_6_MoveX1Y1, - EprojPreInstr_SpikeShootingPlantSpikes_7_MoveX2Y1, - EprojPreInstr_SpikeShootingPlantSpikes_8_MoveX1Y2, - EprojPreInstr_SpikeShootingPlantSpikes_9_MoveX2Y2, -}; - -void EprojPreInstr_SpikeShootingPlantSpikes(uint16 k) { - kEprojPreInstr_SpikeShootingPlantSpikes[enemy_projectile_E[k >> 1] >> 1](k); - EprojPreInstrHelper_SpikeShootingPlantSpikes_Func1(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(uint16 k) { // 0x86D9E6 - int16 v2; - - int v1 = k >> 1; - enemy_projectile_y_pos[v1] += SignExtend8((uint8)((uint16)(enemy_projectile_y_vel[v1] & 0xFF00) >> 8)); - v2 = LOBYTE(enemy_projectile_y_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_y_subpos[v1], v2); - enemy_projectile_y_subpos[v1] += v2; - if (v3) - ++enemy_projectile_y_pos[v1]; -} - -void EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(uint16 k) { // 0x86DA10 - int16 v2; - - int v1 = k >> 1; - enemy_projectile_y_pos[v1] += SignExtend8((uint8)((uint16)(enemy_projectile_x_vel[v1] & 0xFF00) >> 8)); - v2 = LOBYTE(enemy_projectile_x_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_y_subpos[v1], v2); - enemy_projectile_y_subpos[v1] += v2; - if (v3) - ++enemy_projectile_y_pos[v1]; -} - -void EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(uint16 k) { // 0x86DA3A - int16 v2; - - int v1 = k >> 1; - enemy_projectile_x_pos[v1] += SignExtend8((uint8)((uint16)(enemy_projectile_y_vel[v1] & 0xFF00) >> 8)); - v2 = LOBYTE(enemy_projectile_y_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], v2); - enemy_projectile_1A27[v1] += v2; - if (v3) - ++enemy_projectile_x_pos[v1]; -} - -void EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(uint16 k) { // 0x86DA64 - int16 v2; - - int v1 = k >> 1; - enemy_projectile_x_pos[v1] += SignExtend8((uint8)((uint16)(enemy_projectile_x_vel[v1] & 0xFF00) >> 8)); - v2 = LOBYTE(enemy_projectile_x_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], v2); - enemy_projectile_1A27[v1] += v2; - if (v3) - ++enemy_projectile_x_pos[v1]; -} - -void EprojPreInstr_SpikeShootingPlantSpikes_0_MoveX1(uint16 k) { // 0x86DA8E - EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_2_MoveX2(uint16 k) { // 0x86DA93 - EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_1_MoveY1(uint16 k) { // 0x86DA98 - EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_4_MoveY2(uint16 k) { // 0x86DA9D - EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_6_MoveX1Y1(uint16 k) { // 0x86DAA2 - EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(k); - EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_8_MoveX1Y2(uint16 k) { // 0x86DAAA - EprojPreInstr_SpikeShootingPlantSpikes_MoveX1(k); - EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_7_MoveX2Y1(uint16 k) { // 0x86DAB2 - EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(k); - EprojPreInstr_SpikeShootingPlantSpikes_MoveY1(k); -} - -void EprojPreInstr_SpikeShootingPlantSpikes_9_MoveX2Y2(uint16 k) { // 0x86DABA - EprojPreInstr_SpikeShootingPlantSpikes_MoveX2(k); - EprojPreInstr_SpikeShootingPlantSpikes_MoveY2(k); -} - -void EprojPreInstrHelper_SpikeShootingPlantSpikes_Func1(uint16 k) { // 0x86DAC2 - if (EprojPreInstrHelper_SpikeShootingPlantSpikes_Func2(k)) - enemy_projectile_id[k >> 1] = 0; -} - -uint16 EprojPreInstrHelper_SpikeShootingPlantSpikes_Func2(uint16 k) { // 0x86DACE - int v1 = k >> 1; - return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 - || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 - || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 - || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; -} - -void EprojInit_DBF2(uint16 j) { // 0x86DB18 - int v2 = j >> 1; - enemy_projectile_instr_list_ptr[v2] = addr_word_86DB0C; - enemy_projectile_E[v2] = FUNC16(EprojPreInstr_DBF2_MoveX1); - if (enemy_projectile_init_param) - enemy_projectile_E[v2] = FUNC16(EprojPreInstr_DBF2_MoveX2); - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos; - enemy_projectile_1A27[v2] = v3->x_subpos; - enemy_projectile_y_pos[v2] = v3->y_pos + 2; - enemy_projectile_y_subpos[v2] = v3->y_subpos; - enemy_projectile_y_vel[v2] = -256; - enemy_projectile_x_vel[v2] = 256; -} - -void EprojPreInstr_DBF2(uint16 k) { // 0x86DB5B - CallEprojPreInstr(enemy_projectile_E[k >> 1] | 0x860000, k); - EprojPreInstr_DBF2_Func1(k); -} - -void EprojPreInstr_DBF2_MoveX1(uint16 k) { // 0x86DB62 - int16 v2; - - int v1 = k >> 1; - enemy_projectile_x_pos[v1] += SignExtend8((uint8)((uint16)(enemy_projectile_y_vel[v1] & 0xFF00) >> 8)); - v2 = LOBYTE(enemy_projectile_y_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], v2); - enemy_projectile_1A27[v1] += v2; - if (v3) - ++enemy_projectile_x_pos[v1]; -} - -void EprojPreInstr_DBF2_MoveX2(uint16 k) { // 0x86DB8C - int16 v2; - - int v1 = k >> 1; - enemy_projectile_x_pos[v1] += SignExtend8((uint8)((uint16)(enemy_projectile_x_vel[v1] & 0xFF00) >> 8)); - v2 = LOBYTE(enemy_projectile_x_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], v2); - enemy_projectile_1A27[v1] += v2; - if (v3) - ++enemy_projectile_x_pos[v1]; -} - -void EprojPreInstr_DBF2_Func1(uint16 k) { // 0x86DBB6 - if (EprojPreInstrHelper_DBF2_Func2(k)) - enemy_projectile_id[k >> 1] = 0; -} - -uint16 EprojPreInstrHelper_DBF2_Func2(uint16 k) { // 0x86DBC2 - int v1 = k >> 1; - return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 - || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 - || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 - || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; -} - -uint16 EprojInstr_DC5A(uint16 k, uint16 j) { // 0x86DC5A - enemy_projectile_properties[k >> 1] = 12288; - return j; -} - -uint16 EprojInstr_SpawnEnemyDrops_0(uint16 k, uint16 j) { // 0x86DC61 - int v2 = k >> 1; - R18_ = enemy_projectile_x_pos[v2]; - R20_ = enemy_projectile_y_pos[v2]; - SpawnEnemyDrops(addr_kEnemyDef_DF7F, k); - return j; -} - -uint16 EprojInstr_SpawnSporesEproj(uint16 k, uint16 j) { // 0x86DC77 - int v2 = k >> 1; - R18_ = enemy_projectile_x_pos[v2]; - R20_ = enemy_projectile_y_pos[v2]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_Spores, R20_); - return j; -} - -void EprojInit_Spores(uint16 j) { // 0x86DC8D - uint16 v1 = R18_; - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = R18_; - enemy_projectile_F[v2] = v1; - enemy_projectile_y_pos[v2] = R20_; - enemy_projectile_gfx_idx[v2] = 512; -} - -static const int16 word_86DCB9[5] = { -64, -56, -48, -40, -32 }; - -void EprojInit_SporeSpawnStalk(uint16 j) { // 0x86DCA3 - int v1 = j >> 1; - enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - + word_86DCB9[enemy_projectile_init_param]; - enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; -} - -void sub_86DCC3(uint16 v0) { // 0x86DCC3 - int v1 = v0 >> 1; - enemy_projectile_y_pos[v1] = enemy_data[0].y_pos - 96; - enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; -} - -static const int16 kEprojInit_SporeSpawners_X[4] = { 0x20, 0x60, 0xa0, 0xe0 }; - -void EprojInit_SporeSpawners(uint16 j) { // 0x86DCD4 - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = kEprojInit_SporeSpawners_X[enemy_projectile_init_param]; - enemy_projectile_y_pos[v1] = 520; -} - - -void EprojPreInstr_Spores(uint16 k) { // 0x86DCEE - int v1 = k >> 1; - uint16 v2 = LOBYTE(enemy_projectile_E[v1]); - R18_ = SignExtend8(kSporeMovementData[LOBYTE(enemy_projectile_E[v1])]); - if ((enemy_projectile_F[v1] & 0x80) != 0) - R18_ = -R18_; - enemy_projectile_x_pos[v1] += R18_; - R18_ = SignExtend8(kSporeMovementData[v2 + 1]); - uint16 v3 = R18_ + enemy_projectile_y_pos[v1] + R18_; - enemy_projectile_y_pos[v1] = v3; - if (!sign16(v3 - 768)) - enemy_projectile_id[v1] = 0; - enemy_projectile_E[v1] = (uint8)(LOBYTE(enemy_projectile_E[v1]) + 2); -} - -void EprojPreInstr_SporeSpawners(uint16 k) { // 0x86DD46 - if (!kraid_unk9000) { - int v1 = k >> 1; - if (!enemy_projectile_F[v1]) { - enemy_projectile_instr_list_ptr[v1] = addr_word_86DC06; - enemy_projectile_instr_timers[v1] = 1; - enemy_projectile_F[v1] = NextRandom() & 0x1FF; - } - --enemy_projectile_F[v1]; - } -} - - -void EprojInit_NamiFuneFireball(uint16 j) { // 0x86DED6 - int v2 = j >> 1; - enemy_projectile_instr_list_ptr[v2] = addr_word_86DE96; - enemy_projectile_E[v2] = FUNC16(EprojInit_NamiFuneFireball_MoveX1); - if (enemy_projectile_init_param) { - enemy_projectile_instr_list_ptr[v2] = addr_word_86DEA6; - enemy_projectile_E[v2] = FUNC16(EprojInit_NamiFuneFireball_MoveX2); - } - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos; - enemy_projectile_1A27[v2] = v3->x_subpos; - enemy_projectile_y_pos[v2] = v3->y_pos; - enemy_projectile_y_subpos[v2] = v3->y_subpos; - if ((v3->parameter_1 & 0xF) != 0) - enemy_projectile_y_pos[v2] += 4; - int v4 = (uint16)(4 * LOBYTE(v3->parameter_2)) >> 1; - enemy_projectile_y_vel[v2] = word_86DEB6[v4]; - enemy_projectile_x_vel[v2] = word_86DEB6[v4 + 1]; -} - -void CallNamiFuneFireballFunc(uint32 ea, uint16 k) { - switch (ea) { - case fnEprojInit_NamiFuneFireball_MoveX1: EprojInit_NamiFuneFireball_MoveX1(k); return; - case fnEprojInit_NamiFuneFireball_MoveX2: EprojInit_NamiFuneFireball_MoveX2(k); return; - default: Unreachable(); - } -} -void EprojPreInstr_NamiFuneFireball(uint16 v0) { // 0x86DF39 - CallNamiFuneFireballFunc(enemy_projectile_E[v0 >> 1] | 0x860000, v0); - Eproj_NamiFuneFireball_After(v0); -} - -void EprojInit_NamiFuneFireball_MoveX1(uint16 v1) { // 0x86DF40 - int16 v3; - - int v2 = v1 >> 1; - enemy_projectile_x_pos[v2] += SignExtend8((uint8)((uint16)(enemy_projectile_y_vel[v2] & 0xFF00) >> 8)); - v3 = LOBYTE(enemy_projectile_y_vel[v2]) << 8; - bool v4 = __CFADD__uint16(enemy_projectile_1A27[v2], v3); - enemy_projectile_1A27[v2] += v3; - if (v4) - ++enemy_projectile_x_pos[v2]; -} - -void EprojInit_NamiFuneFireball_MoveX2(uint16 v1) { // 0x86DF6A - int16 v3; - - int v2 = v1 >> 1; - enemy_projectile_x_pos[v2] += SignExtend8((uint8)((uint16)(enemy_projectile_x_vel[v2] & 0xFF00) >> 8)); - v3 = LOBYTE(enemy_projectile_x_vel[v2]) << 8; - bool v4 = __CFADD__uint16(enemy_projectile_1A27[v2], v3); - enemy_projectile_1A27[v2] += v3; - if (v4) - ++enemy_projectile_x_pos[v2]; -} - -void Eproj_NamiFuneFireball_After(uint16 v0) { // 0x86DF94 - if (EprojPreInstrHelper_DBF2_Func2(v0)) - enemy_projectile_id[v0 >> 1] = 0; -} - -uint16 sub_86DFA0(uint16 k) { // 0x86DFA0 - int v1 = k >> 1; - return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 - || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0; -} - -uint16 EprojInstr_DFEA(uint16 k, uint16 j) { // 0x86DFEA - int v1 = k >> 1; - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - SpawnEnemyDrops(addr_kEnemyDef_E83F, k); - return j; -} - -void EprojInit_LavaThrownByLavaman(uint16 j) { // 0x86E000 - int v2 = j >> 1; - enemy_projectile_instr_list_ptr[v2] = addr_word_86DFD8; - enemy_projectile_E[v2] = FUNC16(Eproj_LavaThrownByLavaman_MoveX1); - if (enemy_projectile_init_param) { - enemy_projectile_instr_list_ptr[v2] = addr_word_86DFDE; - enemy_projectile_E[v2] = FUNC16(Eproj_LavaThrownByLavaman_MoveX2); - } - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos; - enemy_projectile_1A27[v2] = v3->x_subpos; - enemy_projectile_y_pos[v2] = v3->y_pos + 2; - enemy_projectile_y_subpos[v2] = v3->y_subpos; - enemy_projectile_y_vel[v2] = -768; - enemy_projectile_x_vel[v2] = 768; -} - -void CallLavamanFunc(uint32 ea, uint16 k) { - switch (ea) { - case fnEproj_LavaThrownByLavaman_MoveX1: Eproj_LavaThrownByLavaman_MoveX1(k); return; - case fnEproj_LavaThrownByLavaman_MoveX2: Eproj_LavaThrownByLavaman_MoveX2(k); return; - default: Unreachable(); - } -} - -void sub_86E049(uint16 v0) { // 0x86E049 - CallLavamanFunc(enemy_projectile_E[v0 >> 1] | 0x860000, v0); - sub_86E0A4(v0); -} - -void Eproj_LavaThrownByLavaman_MoveX1(uint16 k) { // 0x86E050 - int16 v2; - - int v1 = k >> 1; - enemy_projectile_x_pos[v1] += SignExtend8((enemy_projectile_y_vel[v1] & 0xFF00) >> 8); - v2 = LOBYTE(enemy_projectile_y_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], v2); - enemy_projectile_1A27[v1] += v2; - if (v3) - ++enemy_projectile_x_pos[v1]; -} - -void Eproj_LavaThrownByLavaman_MoveX2(uint16 k) { // 0x86E07A - int16 v2; - - int v1 = k >> 1; - enemy_projectile_x_pos[v1] += SignExtend8((enemy_projectile_x_vel[v1] & 0xFF00) >> 8); - v2 = LOBYTE(enemy_projectile_x_vel[v1]) << 8; - bool v3 = __CFADD__uint16(enemy_projectile_1A27[v1], v2); - enemy_projectile_1A27[v1] += v2; - if (v3) - ++enemy_projectile_x_pos[v1]; -} - -void sub_86E0A4(uint16 v0) { // 0x86E0A4 - int16 v1; - - v1 = sub_86E0B0(v0); - if (v1) - enemy_projectile_id[v0 >> 1] = 0; -} - -uint16 sub_86E0B0(uint16 k) { // 0x86E0B0 - int v1 = k >> 1; - return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 - || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 - || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 - || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; -} - - -void EprojInst_DustCloudOrExplosion(uint16 v0) { // 0x86E468 - int v1 = v0 >> 1; - enemy_projectile_instr_list_ptr[v1] = off_86E42C[enemy_projectile_init_param]; - enemy_projectile_x_pos[v1] = R18_; - enemy_projectile_y_pos[v1] = R20_; -} - -void EprojInit_EyeDoorSmoke(uint16 j) { // 0x86E4A6 - int v1 = j >> 1; - enemy_projectile_instr_list_ptr[v1] = off_86E42C[(uint8)enemy_projectile_init_param]; - int v2 = (uint16)(8 * HIBYTE(enemy_projectile_init_param)) >> 1; - R18_ = word_86E47E[v2 + 2] + (word_86E47E[v2] & random_number); - R20_ = word_86E47E[v2 + 3] + (word_86E47E[v2 + 1] & *(uint16 *)((uint8 *)&random_number + 1)); - CalculatePlmBlockCoords(plm_id); - enemy_projectile_x_pos[v1] = R18_ + 8 * (2 * plm_x_block + 1); - enemy_projectile_y_pos[v1] = R20_ + 8 * (2 * plm_y_block + 1); - NextRandom(); -} - -void EprojPreInstr_DustCloudOrExplosion(uint16 k) { // 0x86E4FE - if (CheckIfEnemyProjectileIsOffScreen(k)) - enemy_projectile_id[k >> 1] = 0; -} - -uint16 EprojInstr_SetYVel(uint16 k, uint16 j) { // 0x86E533 - enemy_projectile_y_vel[k >> 1] = *(uint16 *)RomPtr_86(j); - return j + 2; -} - -void EprojInit_SpawnedShotGate(uint16 j) { // 0x86E5D0 - EprojInit_SpawnedGate_Common(j, 0); -} - -void EprojInit_ClosedDownwardsShotGate(uint16 j) { // 0x86E5D5 - EprojInit_SpawnedGate_Common(j, 0x40); -} - -void EprojInit_ClosedUpwardsShotGate(uint16 j) { // 0x86E5DA - EprojInit_SpawnedGate_Common(j, -0x40); -} - -void EprojInit_SpawnedGate_Common(uint16 j, uint16 v1) { // 0x86E5DD - R18_ = v1; - uint16 v2 = plm_id; - CalculatePlmBlockCoords(plm_id); - int v3 = j >> 1; - enemy_projectile_E[v3] = plm_block_indices[v2 >> 1]; - enemy_projectile_x_pos[v3] = 16 * plm_x_block; - enemy_projectile_y_pos[v3] = R18_ + 16 * plm_y_block; -} - -void EprojPreInstr_E605(uint16 k) { // 0x86E605 - int v1 = k >> 1; - uint16 v2 = enemy_projectile_timers[v1] + abs16(enemy_projectile_y_vel[v1]); - if (v2 >= 0x1000u) { - enemy_projectile_instr_timers[v1] = 1; - ++enemy_projectile_instr_list_ptr[v1]; - ++enemy_projectile_instr_list_ptr[v1]; - v2 = 0; - } - enemy_projectile_timers[v1] = v2; - enemy_projectile_y_subpos[v1] += LOBYTE(enemy_projectile_y_vel[v1]) << 8; - enemy_projectile_y_pos[v1] += (int8)HIBYTE(enemy_projectile_y_vel[v1]); -} - -void EprojInit_SaveStationElectricity(uint16 j) { // 0x86E6AD - CalculatePlmBlockCoords(plm_id); - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = 16 * (plm_x_block + 1); - enemy_projectile_y_pos[v1] = 16 * (plm_y_block - 2); -} - -uint16 CheckIfEnemyProjectileIsOffScreen(uint16 k) { // 0x86E6E0 - int v1 = k >> 1; - uint16 result = 1; - if ((int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) >= 0) { - enemy_population_ptr = layer1_x_pos + 256; - if ((int16)(enemy_projectile_x_pos[v1] - (layer1_x_pos + 256)) < 0 - && (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) >= 0) { - enemy_population_ptr = layer1_y_pos + 256; - if ((int16)(enemy_projectile_y_pos[v1] - (layer1_y_pos + 256)) < 0) - return 0; - } - } - return result; -} - -uint16 Eproj_FuncE722(uint16 k) { // 0x86E722 - int16 v2; - int16 v3; - - int v1 = k >> 1; - v2 = enemy_projectile_x_pos[v1]; - uint16 result = 1; - if (v2 >= 0) { - if (sign16(v2 - 512)) { - v3 = enemy_projectile_y_pos[v1]; - if (v3 >= 0) { - if (sign16(v3 - 512)) - return 0; - } - } - } - return result; -} - -void Eproj_FuncE73E_MoveXY(uint16 k) { // 0x86E73E - int v1 = k >> 1; - uint16 v2 = enemy_projectile_1A27[v1]; - uint16 v4; - if (((g_word_7E97DC[v1] + 64) & 0x80) != 0) { - bool v3 = v2 < enemy_projectile_E[v1]; - enemy_projectile_1A27[v1] = v2 - enemy_projectile_E[v1]; - v4 = enemy_projectile_x_pos[v1] - (v3 + enemy_projectile_x_vel[v1]); - } else { - bool v3 = __CFADD__uint16(enemy_projectile_E[v1], v2); - enemy_projectile_1A27[v1] = enemy_projectile_E[v1] + v2; - v4 = enemy_projectile_x_vel[v1] + v3 + enemy_projectile_x_pos[v1]; - } - enemy_projectile_x_pos[v1] = v4; - uint16 v5 = enemy_projectile_y_subpos[v1], v6; - if (((g_word_7E97DC[v1] + 128) & 0x80) != 0) { - bool v3 = v5 < enemy_projectile_F[v1]; - enemy_projectile_y_subpos[v1] = v5 - enemy_projectile_F[v1]; - v6 = enemy_projectile_y_pos[v1] - (v3 + enemy_projectile_y_vel[v1]); - } else { - bool v3 = __CFADD__uint16(enemy_projectile_F[v1], v5); - enemy_projectile_y_subpos[v1] = enemy_projectile_F[v1] + v5; - v6 = enemy_projectile_y_vel[v1] + v3 + enemy_projectile_y_pos[v1]; - } - enemy_projectile_y_pos[v1] = v6; -} - -void Eproj_AngleToSamus(uint16 j) { // 0x86E7AB - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = R18_; - enemy_projectile_y_pos[v1] = R20_; - R18_ = samus_x_pos - enemy_projectile_x_pos[v1]; - R20_ = samus_y_pos - enemy_projectile_y_pos[v1]; - uint16 v2 = (uint8)(64 - CalculateAngleFromXY()); - g_word_7E97DC[v1] = v2; - R18_ = v2; - R20_ = enemy_projectile_init_param; - ConvertAngleToXy(); - enemy_projectile_x_vel[v1] = R22_; - enemy_projectile_E[v1] = R24_; - enemy_projectile_y_vel[v1] = R26_; - enemy_projectile_F[v1] = R28_; -} - - -void EprojInit_BotwoonsBody(uint16 j) { // 0x86EA31 - int v1 = j >> 1; - enemy_projectile_x_pos[v1] = enemy_data[0].x_pos; - enemy_projectile_y_pos[v1] = enemy_data[0].y_pos; - enemy_projectile_y_vel[v1] = 0; - uint16 v2 = 16; - if (!enemy_data[0].ai_var_A) - v2 = 48; - R18_ = v2; - uint16 v3 = kEprojInit_BotwoonsBody_InstrLists[v2 >> 1]; - int v4 = j >> 1; - enemy_projectile_instr_list_ptr[v4] = v3; - enemy_projectile_F[v4] = v3; - enemy_projectile_E[v4] = R18_; - enemy_projectile_x_vel[v4] = FUNC16(Eproj_BotwoonsBody_Main); - uint16 ai_var_A = enemy_data[0].ai_var_A; - gExtraEnemyRam7800(enemy_data[0].ai_var_A)->kraid.kraid_next = j; - enemy_projectile_flags[v4] = 2; - gExtraEnemyRam7800(ai_var_A)->kraid.kraid_healths_4ths[0] = 1; -} - -void CallBotwoonEprojFunc(uint32 ea, uint16 k) { - switch (ea) { - case fnEproj_BotwoonsBody_Main: Eproj_BotwoonsBody_Main(k); return; - case fnEproj_BotwonsBodyFunction_Dying: Eproj_BotwonsBodyFunction_Dying(k); return; - case fnEproj_BotwonsBodyFunction_Dying2: Eproj_BotwonsBodyFunction_Dying2(k); return; - case fnEproj_BotwonsBodyFunction_DyingFalling: Eproj_BotwonsBodyFunction_DyingFalling(k); return; - case fnnullsub_101: return; - default: Unreachable(); - } -} - -void EprojPreInstr_BotwoonsBody(uint16 k) { // 0x86EA80 - if (*(uint16 *)&extra_enemy_ram8000[0].pad[32]) { - int v1 = k >> 1; - if (enemy_projectile_x_vel[v1] == FUNC16(Eproj_BotwoonsBody_Main)) - enemy_projectile_x_vel[v1] = FUNC16(Eproj_BotwonsBodyFunction_Dying); - } - CallBotwoonEprojFunc(enemy_projectile_x_vel[k >> 1] | 0x860000, k); -} - -void Eproj_BotwoonsBody_Main(uint16 k) { // 0x86EA98 - int v1 = k >> 1; - uint16 v2 = kEprojInit_BotwoonsBody_InstrLists[enemy_projectile_E[v1] >> 1]; - if (v2 != enemy_projectile_F[v1]) { - enemy_projectile_instr_list_ptr[v1] = v2; - enemy_projectile_F[v1] = v2; - enemy_projectile_instr_timers[v1] = 1; - } - Eproj_BotwoonsBodyHurtFlashHandling1(k); -} - -void Eproj_BotwoonsBodyHurtFlashHandling1(uint16 k) { // 0x86EAB4 - int v1 = k >> 1; - enemy_projectile_gfx_idx[v1] |= 0xE00u; - if (enemy_data[0].flash_timer) { - if ((enemy_damage_routine_exec_count & 2) != 0) - enemy_projectile_gfx_idx[v1] &= 0xF1FFu; - } -} - -void Eproj_BotwoonsBodyHurtFlashHandling2(uint16 j) { // 0x86EAD4 - int v1 = j >> 1; - enemy_projectile_gfx_idx[v1] |= 0xE00u; - if (enemy_data[0].flash_timer) { - if ((enemy_damage_routine_exec_count & 2) != 0) - enemy_projectile_gfx_idx[v1] &= 0xF1FFu; - } -} - -void Eproj_BotwonsBodyFunction_Dying(uint16 v0) { // 0x86EAF4 - int v1 = v0 >> 1; - enemy_projectile_E[v1] = 4 * v0 + 96; - enemy_projectile_x_vel[v1] = 0xEB04; - Eproj_BotwonsBodyFunction_Dying2(v0); -} - -void Eproj_BotwonsBodyFunction_Dying2(uint16 v0) { // 0x86EB04 - int v1 = v0 >> 1; - if (!sign16(++enemy_projectile_E[v1] - 256)) - enemy_projectile_x_vel[v1] = FUNC16(Eproj_BotwonsBodyFunction_DyingFalling); - enemy_projectile_instr_timers[v1] = 0; - Eproj_BotwoonsBodyHurtFlashHandling1(v0); -} - -void Eproj_BotwonsBodyFunction_DyingFalling(uint16 v0) { // 0x86EB1F - int v1 = v0 >> 1; - uint16 v2 = enemy_projectile_y_subpos[v1]; - int v3 = (uint16)(8 * (uint8)((uint16)(enemy_projectile_y_vel[v1] & 0xFF00) >> 8)) >> 1; - bool v4 = __CFADD__uint16(kCommonEnemySpeeds_Quadratic_Copy[v3], v2); - uint16 v5 = kCommonEnemySpeeds_Quadratic_Copy[v3] + v2; - if (v4) - ++enemy_projectile_y_pos[v1]; - enemy_projectile_y_subpos[v1] = v5; - uint16 v6 = kCommonEnemySpeeds_Quadratic_Copy[v3 + 1] + enemy_projectile_y_pos[v1]; - enemy_projectile_y_pos[v1] = v6; - if (sign16(v6 - 200)) { - int v7 = v0 >> 1; - enemy_projectile_y_vel[v7] += 192; - enemy_projectile_instr_timers[v7] = 0; - Eproj_BotwoonsBodyHurtFlashHandling2(v0); - } else { - enemy_projectile_y_pos[v1] = 200; - enemy_projectile_x_vel[v1] = FUNC16(nullsub_101); - enemy_projectile_instr_list_ptr[v1] = addr_word_86E208; - enemy_projectile_gfx_idx[v1] = 2560; - enemy_projectile_instr_timers[v1] = 1; - QueueSmallExplosionSfx(); - if (v0 == 10) - *(uint16 *)&extra_enemy_ram8800[0].pad[62] = 1; - } -} - -void QueueSmallExplosionSfx(void) { // 0x86EB94 - QueueSfx2_Max6(0x24u); -} - -void EprojInit_BotwoonsSpit(uint16 j) { // 0x86EBC6 - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = v1->x_pos; - enemy_projectile_y_pos[v2] = v1->y_pos; - enemy_projectile_instr_list_ptr[v2] = addr_word_86EBAE; - uint16 v3 = remaining_enemy_spritemap_entries; - g_word_7E97DC[v2] = remaining_enemy_spritemap_entries; - R18_ = v3; - R20_ = enemy_projectile_init_param; - ConvertAngleToXy(); - enemy_projectile_x_vel[v2] = R22_; - enemy_projectile_E[v2] = R24_; - enemy_projectile_y_vel[v2] = R26_; - enemy_projectile_F[v2] = R28_; -} - -void EprojPreInstr_BotwoonsSpit(uint16 k) { // 0x86EC05 - Eproj_FuncE73E_MoveXY(k); - sub_86EC0C(k); -} - -void sub_86EC0C(uint16 k) { // 0x86EC0C - int16 v1; - - v1 = sub_86EC18(k); - if (v1) - enemy_projectile_id[k >> 1] = 0; -} - -uint16 sub_86EC18(uint16 k) { // 0x86EC18 - int v1 = k >> 1; - return (int16)(enemy_projectile_x_pos[v1] - layer1_x_pos) < 0 - || (int16)(layer1_x_pos + 256 - enemy_projectile_x_pos[v1]) < 0 - || (int16)(enemy_projectile_y_pos[v1] - layer1_y_pos) < 0 - || (int16)(layer1_y_pos + 256 - enemy_projectile_y_pos[v1]) < 0; -} - -void EprojInit_YappingMawsBody(uint16 j) { // 0x86EC62 - EnemyData *v2 = gEnemyData(cur_enemy_index); - int v3 = j >> 1; - enemy_projectile_x_pos[v3] = v2->x_pos; - enemy_projectile_y_pos[v3] = v2->y_pos; - enemy_projectile_instr_list_ptr[v3] = addr_word_86EC5C; - if (!v2->parameter_2) - enemy_projectile_instr_list_ptr[v3] = addr_word_86EC56; - *(uint16 *)&extra_enemy_ram8800[0].pad[(uint16)(cur_enemy_index - + 2 * *(uint16 *)&extra_enemy_ram8800[0].pad[cur_enemy_index + 8])] = j; -} - -uint16 EprojInstr_ECE3(uint16 k, uint16 j) { // 0x86ECE3 - int v2 = k >> 1; - R18_ = enemy_projectile_x_pos[v2] + (NextRandom() & 0x3F) - 32; - R20_ = enemy_projectile_y_pos[v2] + ((uint16)(random_number & 0x3F00) >> 8) - 32; - R22_ = *(uint16 *)RomPtr_86(j); - R24_ = 0; - CreateSpriteAtPos(); - return j + 2; -} - -uint16 EprojInstr_ED17(uint16 k, uint16 j) { // 0x86ED17 - int v2 = k >> 1; - R18_ = enemy_projectile_x_pos[v2] + (NextRandom() & 0x1F) - 16; - R20_ = enemy_projectile_y_pos[v2] + ((uint16)(random_number & 0x1F00) >> 8) - 16; - R22_ = *(uint16 *)RomPtr_86(j); - R24_ = 0; - CreateSpriteAtPos(); - return j + 2; -} - -uint16 EprojInstr_QueueSfx2_9(uint16 k, uint16 j) { // 0x86EE8B - QueueSfx2_Max1(9u); - return j; -} - -uint16 EprojInstr_QueueSfx2_24(uint16 k, uint16 j) { // 0x86EE97 - QueueSfx2_Max1(0x24u); - return j; -} - -uint16 EprojInstr_QueueSfx2_B(uint16 k, uint16 j) { // 0x86EEA3 - QueueSfx2_Max1(0xBu); - return j; -} - - -uint16 EprojInstr_EEAF(uint16 k, uint16 j) { // 0x86EEAF - uint16 v2 = RandomDropRoutine(k); - if (k != 0 && sign16(v2 - 6)) { - uint16 v3 = 2 * v2; - int v4 = k >> 1; - enemy_projectile_E[v4] = v3; - enemy_projectile_instr_list_ptr[v4] = off_86EF04[v3 >> 1]; - enemy_projectile_instr_timers[v4] = 1; - enemy_projectile_F[v4] = 400; - enemy_projectile_pre_instr[v4] = FUNC16(EprojPreInstr_Pickup); - enemy_projectile_properties[v4] &= ~0x4000u; - return enemy_projectile_instr_list_ptr[v4]; - } else { - int v6 = k >> 1; - enemy_projectile_instr_timers[v6] = 1; - enemy_projectile_properties[v6] = 12288; - enemy_projectile_pre_instr[v6] = FUNC16(EprojPreInstr_Empty); - enemy_projectile_instr_list_ptr[v6] = 0xECA3; - return 0xECA3; - } -} - -uint16 EprojInstr_HandleRespawningEnemy(uint16 k, uint16 j) { // 0x86EF10 - if ((int16)enemy_projectile_killed_enemy_index[k >> 1] <= -2) - RespawnEnemy(enemy_projectile_killed_enemy_index[k >> 1] & 0x7fff); - return j; -} - -void EprojInit_F337(uint16 j) { // 0x86EF29 - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = R18_; - enemy_projectile_y_pos[v2] = R20_; - enemy_projectile_gfx_idx[v2] = 0; - enemy_projectile_enemy_header_ptr[v2] = varE24; // this is X?! - uint16 v3 = RandomDropRoutine(j); - if (v3 != 0 && sign16(v3 - 6)) { // bug, why does it compare x here. - uint16 v4 = 2 * v3; - enemy_projectile_E[v2] = v4; - enemy_projectile_instr_list_ptr[v2] = off_86EF04[v4 >> 1]; - enemy_projectile_instr_timers[v2] = 1; - enemy_projectile_F[v2] = 400; - enemy_projectile_killed_enemy_index[j >> 1] = -1; - } else { - int v5 = j >> 1; - enemy_projectile_instr_list_ptr[v5] = addr_word_86ECA3; - enemy_projectile_instr_timers[v5] = 1; - enemy_projectile_properties[v5] = 12288; - enemy_projectile_pre_instr[v5] = FUNC16(EprojPreInstr_Empty); - } -} - - -void EprojInit_EnemyDeathExplosion(uint16 j) { // 0x86EF89 - EnemyData *v1 = gEnemyData(cur_enemy_index); - int v2 = j >> 1; - enemy_projectile_x_pos[v2] = v1->x_pos; - enemy_projectile_y_pos[v2] = v1->y_pos; - enemy_projectile_killed_enemy_index[v2] = cur_enemy_index; - if ((v1->properties & 0x4000) != 0) - enemy_projectile_killed_enemy_index[v2] = cur_enemy_index | 0x8000; - enemy_projectile_enemy_header_ptr[v2] = v1->enemy_ptr; - enemy_projectile_gfx_idx[v2] = 0; - enemy_projectile_instr_list_ptr[v2] = off_86EFD5[enemy_projectile_init_param]; - enemy_projectile_instr_timers[v2] = 1; -} - -static Func_V *const off_86F0AD[7] = { // 0x86EFE0 - 0, - Eproj_Pickup_SmallHealth, - Eproj_Pickup_BigHealth, - Eproj_Pickup_PowerBombs, - Eproj_Pickup_Missiles, - Eproj_Pickup_SuperMissiles, - 0, -}; - -void EprojPreInstr_Pickup(uint16 k) { - - int v1 = k >> 1; - if (!--enemy_projectile_F[v1]) - goto LABEL_7; - if (CallSomeSamusCode(0xDu)) { - if (sign16(enemy_projectile_F[v1] - 384)) { - uint16 v2, v3; - v2 = abs16(enemy_projectile_x_pos[v1] - grapple_beam_end_x_pos); - if (sign16(v2 - 16)) { - v3 = abs16(enemy_projectile_y_pos[v1] - grapple_beam_end_y_pos); - if (sign16(v3 - 16)) { - off_86F0AD[enemy_projectile_E[v1] >> 1](); -LABEL_7:; - int v4 = k >> 1; - enemy_projectile_instr_list_ptr[v4] = addr_word_86ECA3; - enemy_projectile_instr_timers[v4] = 1; - enemy_projectile_properties[v4] = 12288; - enemy_projectile_pre_instr[v4] = FUNC16(EprojPreInstr_Empty); - return; - } - } - } - } - int v5 = k >> 1; - enemy_population_ptr = LOBYTE(enemy_projectile_radius[v5]); - draw_oam_x_offset = HIBYTE(enemy_projectile_radius[v5]); - uint16 v6 = abs16(samus_x_pos - enemy_projectile_x_pos[v5]); - bool v7 = v6 < samus_x_radius; - uint16 v8 = v6 - samus_x_radius; - if (v7 || v8 < enemy_population_ptr) { - uint16 v9 = abs16(samus_y_pos - enemy_projectile_y_pos[v5]); - v7 = v9 < samus_y_radius; - uint16 v10 = v9 - samus_y_radius; - if (v7 || v10 < draw_oam_x_offset) { - off_86F0AD[enemy_projectile_E[v5] >> 1](); - int v11 = k >> 1; - enemy_projectile_instr_list_ptr[v11] = addr_word_86ECA3; - enemy_projectile_instr_timers[v11] = 1; - enemy_projectile_properties[v11] = 12288; - enemy_projectile_pre_instr[v11] = FUNC16(EprojPreInstr_Empty); - } - } -} - -void Eproj_Pickup_SmallHealth(void) { // 0x86F0BB - Samus_RestoreHealth(5u); - QueueSfx2_Max1(1u); -} - -void Eproj_Pickup_BigHealth(void) { // 0x86F0CA - Samus_RestoreHealth(0x14u); - QueueSfx2_Max1(2u); -} - -void Eproj_Pickup_PowerBombs(void) { // 0x86F0D9 - Samus_RestorePowerBombs(1u); - QueueSfx2_Max1(5u); -} - -void Eproj_Pickup_Missiles(void) { // 0x86F0E8 - Samus_RestoreMissiles(2u); - QueueSfx2_Max1(3u); -} - -void Eproj_Pickup_SuperMissiles(void) { // 0x86F0F7 - Samus_RestoreSuperMissiles(1u); - QueueSfx2_Max1(4u); -} - -static const uint8 byte_86F25E[6] = { 1, 2, 4, 6, 5, 3 }; - -uint16 RandomDropRoutine(uint16 k) { // 0x86F106 - int8 v9; // cf - - int v1 = k >> 1; - varE2A = enemy_projectile_killed_enemy_index[v1] & 0x7FFF; - varE28 = enemy_projectile_enemy_header_ptr[v1]; - if (varE28 == 0) - goto LABEL_30; - uint16 v2; - v2 = *((uint16 *)RomPtr_A0(varE28) + 29); - if (!v2) - goto LABEL_30; - uint8 Random; - do - Random = NextRandom(); - while (!Random); - R26_ = Random; - R20_ = 255; - R24_ = 0; - uint16 v5; - v5 = 1; - if ((uint16)(samus_reserve_health + samus_health) >= 0x1Eu) { - if ((uint16)(samus_reserve_health + samus_health) < 0x32u) - goto LABEL_7; - v5 = 0; - } - health_drop_bias_flag = v5; -LABEL_7: - if ((uint8)health_drop_bias_flag) { - const uint8 *v6 = RomPtr_B4(v2); - LOBYTE(R18_) = v6[1] + *v6; - LOBYTE(R22_) = 3; - } else { - const uint8 *v7 = RomPtr_B4(v2); - LOBYTE(R18_) = v7[3]; - LOBYTE(R22_) = 8; - if (samus_health != samus_max_health || samus_reserve_health != samus_max_reserve_health) { - LOBYTE(R18_) = v7[1] + *v7 + R18_; - LOBYTE(R22_) = R22_ | 3; - } - if (samus_missiles != samus_max_missiles) { - LOBYTE(R18_) = v7[2] + R18_; - LOBYTE(R22_) = R22_ | 4; - } - if (samus_super_missiles != samus_max_super_missiles) { - LOBYTE(R20_) = R20_ - v7[4]; - LOBYTE(R22_) = R22_ | 0x10; - } - if (samus_power_bombs != samus_max_power_bombs) { - LOBYTE(R20_) = R20_ - v7[5]; - LOBYTE(R22_) = R22_ | 0x20; - } - } - int i; - for (i = 0; i != 4; ++i) { - if (!(uint8)R18_) { - LOBYTE(R22_) = (uint8)R22_ >> 4; - v2 += 4; - i = 4; - goto LABEL_26; - } - v9 = R22_ & 1; - LOBYTE(R22_) = (uint8)R22_ >> 1; - if (v9) { - const uint8 *v10 = RomPtr_B4(v2); - uint16 RegWord = Mult8x8(R20_, *v10); - int divved = SnesDivide(RegWord, R18_); - uint16 v12 = R24_; - uint16 v13 = divved + v12; - if (v13 >= R26_) - return byte_86F25E[i]; - R24_ = v13; - } - ++v2; - } - do { -LABEL_26: - v9 = R22_ & 1; - LOBYTE(R22_) = (uint8)R22_ >> 1; - if (v9) { - const uint8 *v14 = RomPtr_B4(v2); - if ((uint16)(R24_ + *v14) >= R26_) - return byte_86F25E[i]; - R24_ += *v14; - } - ++v2; - ++i; - } while (i != 6); -LABEL_30: - i = 3; - return byte_86F25E[i]; -} - -void RespawnEnemy(uint16 v0) { // 0x86F264 - EnemySpawnData *v3; // r10 - EnemyDef_A2 *EnemyDef_A2; // r10 - int16 v7; - - cur_enemy_index = v0; - const uint8 *v1 = RomPtr_A1(room_enemy_population_ptr + (v0 >> 2)); - EnemyData *v2 = gEnemyData(v0); - v2->enemy_ptr = GET_WORD(v1); - v2->x_pos = GET_WORD(v1 + 2); - v2->y_pos = GET_WORD(v1 + 4); - v2->current_instruction = GET_WORD(v1 + 6); - v2->properties = GET_WORD(v1 + 8); - v2->extra_properties = GET_WORD(v1 + 10); - v2->parameter_1 = GET_WORD(v1 + 12); - v2->parameter_2 = GET_WORD(v1 + 14); - v3 = gEnemySpawnData(v0); - EnemyData *v4 = gEnemyData(v0); - v4->palette_index = v3->palette_index; - v4->vram_tiles_index = v3->vram_tiles_index; - v2->frozen_timer = 0; - v2->flash_timer = 0; - v2->invincibility_timer = 0; - v2->timer = 0; - v2->frame_counter = 0; - v2->ai_var_A = 0; - v2->ai_var_B = 0; - v2->ai_var_C = 0; - v2->ai_var_D = 0; - v2->ai_var_E = 0; - v2->ai_preinstr = 0; - v2->instruction_timer = 1; - uint16 enemy_ptr = gEnemyData(cur_enemy_index)->enemy_ptr; - EnemyDef_A2 = get_EnemyDef_A2(enemy_ptr); - enemy_ai_pointer.addr = EnemyDef_A2->ai_init; - v2->x_width = EnemyDef_A2->x_radius; - v2->y_height = EnemyDef_A2->y_radius; - v2->health = EnemyDef_A2->health; - v2->layer = EnemyDef_A2->layer; - v7 = *(uint16 *)&EnemyDef_A2->bank; - *(uint16 *)&v2->bank = v7; - enemy_ai_pointer.bank = v7; - CallEnemyAi(Load24(&enemy_ai_pointer)); -} - - -void EprojInit_Sparks(uint16 j) { // 0x86F391 - static const uint16 word_86F3D4[14] = { 0xffff, 0xb800, 0xffff, 0xc000, 0xffff, 0xe000, 0xffff, 0xff00, 0, 0x100, 0, 0x2000, 0, 0x4000 }; - int v2 = j >> 1; - enemy_projectile_instr_list_ptr[v2] = addr_kEnemyDef_F353; - EnemyData *v3 = gEnemyData(cur_enemy_index); - enemy_projectile_x_pos[v2] = v3->x_pos; - enemy_projectile_1A27[v2] = v3->x_subpos; - enemy_projectile_y_pos[v2] = v3->y_pos + 8; - enemy_projectile_y_subpos[v2] = v3->y_subpos; - enemy_projectile_x_vel[v2] = 0; - enemy_projectile_y_vel[v2] = 0; - uint16 v4 = (NextRandom() & 0x1C) >> 1; - enemy_projectile_F[v2] = g_word_86F3D4[v4 + 0]; - enemy_projectile_E[v2] = g_word_86F3D4[v4 + 1]; -} - -void EprojPreInstr_Sparks(uint16 k) { // 0x86F3F0 - int v1 = k >> 1; - if ((enemy_projectile_y_vel[v1] & 0x8000u) == 0) { - if (EnemyProjectileBlockCollisition_Vertical(k) & 1) { - enemy_projectile_instr_list_ptr[v1] = 0xF363; - enemy_projectile_instr_timers[v1] = 1; - - enemy_projectile_F[v1] = enemy_projectile_F[v1] * 2 + (enemy_projectile_E[v1] >> 15); - enemy_projectile_E[v1] *= 2; - - enemy_projectile_F[v1] = enemy_projectile_F[v1] * 2 + (enemy_projectile_E[v1] >> 15); - enemy_projectile_E[v1] *= 2; - - enemy_projectile_x_vel[v1] = 0x8000; - enemy_projectile_y_vel[v1] = -1; - enemy_projectile_y_pos[v1] -= 2; - return; - } - uint16 v2 = enemy_projectile_x_vel[v1]; - enemy_projectile_x_vel[v1] = v2 + 0x4000; - uint16 v3 = __CFADD__uint16(v2, 0x4000) + enemy_projectile_y_vel[v1]; - if (v3 < 4u) - enemy_projectile_y_vel[v1] = v3; - } - uint16 v4 = enemy_projectile_y_subpos[v1]; - bool v5 = __CFADD__uint16(enemy_projectile_x_vel[v1], v4); - enemy_projectile_y_subpos[v1] = enemy_projectile_x_vel[v1] + v4; - enemy_projectile_y_pos[v1] += enemy_projectile_y_vel[v1] + v5; - uint16 v6 = enemy_projectile_1A27[v1]; - v5 = __CFADD__uint16(enemy_projectile_E[v1], v6); - enemy_projectile_1A27[v1] = enemy_projectile_E[v1] + v6; - enemy_projectile_x_pos[v1] += enemy_projectile_F[v1] + v5; - if ((nmi_frame_counter_byte & 3) == 0) { - R18_ = enemy_projectile_x_pos[v1]; - R20_ = enemy_projectile_y_pos[v1]; - R22_ = 48; - R24_ = enemy_projectile_gfx_idx[v1]; - CreateSpriteAtPos(); - } -} \ No newline at end of file diff --git a/src/sm_87.c b/src/sm_87.c index 2bafee1..9c2f087 100644 --- a/src/sm_87.c +++ b/src/sm_87.c @@ -12,7 +12,7 @@ void EnableAnimtiles(void) { // 0x878000 } void DisableAnimtiles(void) { // 0x87800B - animtiles_enable_flag &= ~0x8000u; + animtiles_enable_flag &= ~0x8000; } void ClearAnimtiles(void) { // 0x878016 @@ -26,7 +26,7 @@ void SpawnAnimtiles(uint16 j) { // 0x878027 uint16 v1 = 10; while (animtiles_ids[v1 >> 1]) { v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) return; } int v2 = v1 >> 1; @@ -41,7 +41,7 @@ void SpawnAnimtiles(uint16 j) { // 0x878027 } void AnimtilesHandler(void) { // 0x878064 - if ((animtiles_enable_flag & 0x8000u) != 0) { + if ((animtiles_enable_flag & 0x8000) != 0) { for (int i = 10; i >= 0; i -= 2) { animtiles_object_index = i; if (animtiles_ids[i >> 1]) { @@ -90,7 +90,7 @@ void ProcessAnimtilesObject(void) { // 0x878085 while (1) { const uint16 *v4 = (const uint16 *)RomPtr_87(v3); v5 = *v4; - if ((*v4 & 0x8000u) == 0) + if ((*v4 & 0x8000) == 0) break; animtiles_instruction = *v4; v3 = CallAnimtilesInstr(v5 | 0x870000, v0, v3 + 2); @@ -166,7 +166,7 @@ uint16 AnimtilesInstr_QueueSfx3(uint16 k, uint16 j) { // 0x878114 uint16 AnimtilesInstr_GotoIfBossBitSet(uint16 k, uint16 j) { // 0x878120 const uint8 *v2 = RomPtr_87(j); uint16 v3 = j + 1; - if (CheckBossBitForCurArea((uint8) * (uint16 *)v2) & 1) + if (CheckBossBitForCurArea((uint8) *(uint16 *)v2) & 1) return AnimtilesInstr_Goto(k, v3); else return v3 + 2; @@ -198,11 +198,11 @@ void UNUSED_sub_87815A(void) { // 0x87815A } void UNUSED_sub_878162(void) { // 0x878162 - CallSomeSamusCode(1u); + CallSomeSamusCode(1); } uint16 AnimtilesInstr_WaitUntilAreaBossDead_DoubleRet(uint16 k, uint16 j) { // 0x8781BA - if (!(CheckBossBitForCurArea(1u) & 1)) { + if (!(CheckBossBitForCurArea(1) & 1)) { animtiles_instr_timers[k >> 1] = 1; return 0; } @@ -231,7 +231,7 @@ uint16 AnimtilesInstr_SpawnTourianStatueSoul(uint16 k, uint16 j) { // 0x87832F } uint16 AnimtilesInstr_GotoIfTourianStatueBusy(uint16 k, uint16 j) { // 0x87833E - if ((tourian_entrance_statue_animstate & 0x8000u) == 0) + if ((tourian_entrance_statue_animstate & 0x8000) == 0) return j + 2; else return AnimtilesInstr_Goto(k, j); @@ -270,4 +270,4 @@ uint16 AnimtilesInstr_Write8PaletteColors(uint16 k, uint16 j) { // 0x87837F v2 += 2; } return j + 2; -} \ No newline at end of file +} diff --git a/src/sm_88.c b/src/sm_88.c index 59219ec..81a612d 100644 --- a/src/sm_88.c +++ b/src/sm_88.c @@ -18,57 +18,12 @@ #define g_word_88E833 ((uint16*)RomFixedPtr(0x88e833)) #define g_byte_88EA8B ((uint8*)RomFixedPtr(0x88ea8b)) - - -static Func_Y_Y *const kLayerBlendFuncTable[27] = { - nullsub_9, - nullsub_9, - LayerBlendFunc_4_PhantoonIntro, - LayerBlendFunc_6, - LayerBlendFunc_8, - LayerBlendFunc_A, - LayerBlendFunc_C, - nullsub_10, - LayerBlendFunc_10, - LayerBlendFunc_10, - LayerBlendFunc_14, - LayerBlendFunc_16, - LayerBlendFunc_18, - LayerBlendFunc_1A, - LayerBlendFunc_1C, - LayerBlendFunc_18, - nullsub_11, - LayerBlendFunc_14, - LayerBlendFunc_24, - LayerBlendFunc_26, - LayerBlendFunc_28, - LayerBlendFunc_2A, - LayerBlendFunc_2C, - LayerBlendFunc_2E, - LayerBlendFunc_18, - LayerBlendFunc_32, - LayerBlendFunc_34, -}; - -void LayerBlendingHandler(void) { // 0x888000 - uint16 v0 = 0; - uint8 v1 = fx_layer_blending_config_c; - if ((uint8)fx_layer_blending_config_c) { - InitializeLayerBlending(); - v0 = kLayerBlendFuncTable[v1 >> 1](v0); - } - if ((fx_layer_blending_config_c & 0x8000u) == 0) { - if ((fx_layer_blending_config_c & 0x4000) != 0) { - HandleLayerBlendingXrayCanShowBlocks(); - } else if ((fx_layer_blending_config_c & 0x2000) != 0) { - HandleLayerBlendingXrayCantShowBlocks(); - } else if ((fx_layer_blending_config_c & 0x1000) != 0) { - HandleLayerBlendingXrayFirefleaRoom(); - } - } else { - HandleLayerBlendingPowerBomb(v0); - } -} +void CallHdmaobjPreInstr(uint32 ea, uint16 k); +const uint8 *CallHdmaobjInstr(uint32 ea, uint16 k, const uint8 *j); +void HdmaobjPreInstr_FxType22_BG3Yscroll(uint16 k); +void HdmaobjPreInstr_WaterBG2XScroll_Func2(uint16 k); +void HdmaobjPreInstr_WaterBG2XScroll_Func1(uint16 k); +void HdmaobjPreInstr_HazeColorMathSubscreen_FadingIn(uint16 k); uint16 nullsub_9(uint16 j) { // 0x888074 return j; @@ -176,7 +131,7 @@ uint16 LayerBlendFunc_26(uint16 j) { // 0x88810D uint16 LayerBlendFunc_28(uint16 j) { // 0x888112 next_gameplay_CGWSEL = 0; next_gameplay_CGADSUB = -77; - if ((fx_layer_blending_config_c & 0x8000u) == 0) { + if ((fx_layer_blending_config_c & 0x8000) == 0) { reg_COLDATA[0] = 37; reg_COLDATA[1] = 64; reg_COLDATA[2] = 0x80; @@ -187,7 +142,7 @@ uint16 LayerBlendFunc_28(uint16 j) { // 0x888112 uint16 LayerBlendFunc_2A(uint16 j) { // 0x88812A next_gameplay_CGWSEL = 0; next_gameplay_CGADSUB = -77; - if ((fx_layer_blending_config_c & 0x8000u) == 0) { + if ((fx_layer_blending_config_c & 0x8000) == 0) { reg_COLDATA[0] = 38; reg_COLDATA[1] = 66; reg_COLDATA[2] = 0x80; @@ -266,17 +221,6 @@ void HandleLayerBlendingXrayFirefleaRoom(void) { // 0x8881DB next_gameplay_CGWSEL = 32; next_gameplay_CGADSUB = -77; } -static Func_V *const kLayerBlendPowerBombFuncs[4] = { // 0x8881FE - LayerBlendPowerBombFunc_0, - LayerBlendPowerBombFunc_0, - LayerBlendPowerBombFunc_4, - LayerBlendPowerBombFunc_6, -}; -void HandleLayerBlendingPowerBomb(uint16 j) { - if (room_ptr == addr_kRoom_a66a) - j = 6; - kLayerBlendPowerBombFuncs[j >> 1](); -} void LayerBlendPowerBombFunc_0(void) { // 0x888219 reg_W12SEL = 0; @@ -314,12 +258,75 @@ void LayerBlendPowerBombFunc_6(void) { // 0x888263 reg_TS = 4; } +static Func_Y_Y *const kLayerBlendFuncTable[27] = { + nullsub_9, + nullsub_9, + LayerBlendFunc_4_PhantoonIntro, + LayerBlendFunc_6, + LayerBlendFunc_8, + LayerBlendFunc_A, + LayerBlendFunc_C, + nullsub_10, + LayerBlendFunc_10, + LayerBlendFunc_10, + LayerBlendFunc_14, + LayerBlendFunc_16, + LayerBlendFunc_18, + LayerBlendFunc_1A, + LayerBlendFunc_1C, + LayerBlendFunc_18, + nullsub_11, + LayerBlendFunc_14, + LayerBlendFunc_24, + LayerBlendFunc_26, + LayerBlendFunc_28, + LayerBlendFunc_2A, + LayerBlendFunc_2C, + LayerBlendFunc_2E, + LayerBlendFunc_18, + LayerBlendFunc_32, + LayerBlendFunc_34, +}; + +void LayerBlendingHandler(void) { // 0x888000 + uint16 v0 = 0; + uint8 v1 = fx_layer_blending_config_c; + if ((uint8)fx_layer_blending_config_c) { + InitializeLayerBlending(); + v0 = kLayerBlendFuncTable[v1 >> 1](v0); + } + if ((fx_layer_blending_config_c & 0x8000) == 0) { + if ((fx_layer_blending_config_c & 0x4000) != 0) { + HandleLayerBlendingXrayCanShowBlocks(); + } else if ((fx_layer_blending_config_c & 0x2000) != 0) { + HandleLayerBlendingXrayCantShowBlocks(); + } else if ((fx_layer_blending_config_c & 0x1000) != 0) { + HandleLayerBlendingXrayFirefleaRoom(); + } + } else { + HandleLayerBlendingPowerBomb(v0); + } +} + +static Func_V *const kLayerBlendPowerBombFuncs[4] = { // 0x8881FE + LayerBlendPowerBombFunc_0, + LayerBlendPowerBombFunc_0, + LayerBlendPowerBombFunc_4, + LayerBlendPowerBombFunc_6, +}; + +void HandleLayerBlendingPowerBomb(uint16 j) { + if (room_ptr == addr_kRoom_a66a) + j = 6; + kLayerBlendPowerBombFuncs[j >> 1](); +} + void EnableHdmaObjects(void) { // 0x888288 - hdma_objects_enable_flag |= 0x8000u; + hdma_objects_enable_flag |= 0x8000; } void DisableHdmaObjects(void) { // 0x888293 - hdma_objects_enable_flag &= ~0x8000u; + hdma_objects_enable_flag &= ~0x8000; } void WaitUntilEndOfVblankAndClearHdma(void) { // 0x88829E @@ -399,7 +406,7 @@ void InitializeSpecialEffectsForNewRoom(void) { // 0x8882C1 unpause_hook.addr = FUNC16(PauseHook_Empty); WriteReg(WMADDL, 0xF0); WriteReg(WMADDM, 0xFF); - WriteReg(WMADDH, 1u); + WriteReg(WMADDH, 1); reg_HDMAEN = 0; reg_COLDATA[0] = 32; reg_COLDATA[1] = 64; @@ -415,7 +422,7 @@ void InitializeSpecialEffectsForNewRoom(void) { // 0x8882C1 gameplay_BG3SC = 90; } -uint16 SpawnHdmaObjectInner(uint16 k, uint16 *p) { // 0x888477 +static uint16 SpawnHdmaObjectInner(uint16 k, uint16 *p, uint16 r18, uint16 r20, uint16 r24) { // 0x888477 int v2 = k >> 1; hdma_object_pre_instructions[v2] = FUNC16(nullsub_293); hdma_object_pre_instruction_bank[v2] = 136; @@ -426,25 +433,23 @@ uint16 SpawnHdmaObjectInner(uint16 k, uint16 *p) { // 0x888477 hdma_object_B[v2] = 0; hdma_object_C[v2] = 0; hdma_object_D[v2] = 0; - hdma_object_channels_bitmask[v2] = swap16(R18_); - hdma_object_bank_slot[v2] = R24_ | R20_; - WriteRegWord((SnesRegs)(R20_ + 17152), *p); + hdma_object_channels_bitmask[v2] = swap16(r18); + hdma_object_bank_slot[v2] = r24 | r20; + WriteRegWord((SnesRegs)(r20 + DMAP0), *p); return k; } uint16 SpawnHdmaObject(uint8 db, const void *p) { // 0x888435 - R24_ = db << 8; - R18_ = 1024; - R20_ = 32; + uint16 r18 = 1024, r20 = 32; uint16 v3 = 0; for (;;) { if (!hdma_object_channels_bitmask[v3 >> 1]) - return SpawnHdmaObjectInner(v3, (uint16 *)p); - bool v4 = R18_ >> 15; - R18_ *= 2; + return SpawnHdmaObjectInner(v3, (uint16 *)p, r18, r20, db << 8); + bool v4 = r18 >> 15; + r18 *= 2; if (v4) return -1; - R20_ += 16; + r20 += 16; v3 += 2; if (v3 == 12) return -1; @@ -452,10 +457,7 @@ uint16 SpawnHdmaObject(uint8 db, const void *p) { // 0x888435 } void SpawnHdmaObjectToSlot0xA(uint8 db, const void *p) { // 0x88840A - R18_ = 0x8000; - R20_ = 0x70; - R24_ = db << 8; - SpawnHdmaObjectInner(0xa, (uint16 *)p); + SpawnHdmaObjectInner(0xa, (uint16 *)p, 0x8000, 0x70, db << 8); } void HdmaObjectHandler(void) { // 0x8884B9 @@ -470,7 +472,7 @@ void HdmaObjectHandler(void) { // 0x8884B9 SpawnHdmaObject(0x88, &unk_8884DD); } fx_layer_blending_config_c = fx_layer_blending_config_a; - if ((hdma_objects_enable_flag & 0x8000u) != 0) { + if ((hdma_objects_enable_flag & 0x8000) != 0) { reg_HDMAEN = 0; int i = 0; do { @@ -487,111 +489,11 @@ void HdmaObjectHandler(void) { // 0x8884B9 } } -void CallHdmaobjPreInstr(uint32 ea, uint16 k) { - switch (ea) { - case fnnullsub_56: return; - case fnnullsub_293: return; - case fnnullsub_309: return; - case fnHdmaobjPreInstr_XraySetup: HdmaobjPreInstr_XraySetup(k); return; - case fnHdmaobjPreInstr_Xray: HdmaobjPreInstr_Xray(k); return; - case fnHdmaobjPreInstr_XrayFunc0_NoBeam: HdmaobjPreInstr_XrayFunc0_NoBeam(k); return; - case fnHdmaobjPreInstr_XrayFunc1_BeamWidening: HdmaobjPreInstr_XrayFunc1_BeamWidening(k); return; - case fnHdmaobjPreInstr_XrayFunc2_FullBeam: HdmaobjPreInstr_XrayFunc2_FullBeam(k); return; - case fnHdmaobjPreInstr_XrayFunc3_DeactivateBeam: HdmaobjPreInstr_XrayFunc3_DeactivateBeam(k); return; - case fnHdmaobjPreInstr_XrayFunc4_DeactivateBeam: HdmaobjPreInstr_XrayFunc4_DeactivateBeam(k); return; - case fnHdmaobjPreInstr_XrayFunc5_DeactivateBeam: HdmaobjPreInstr_XrayFunc5_DeactivateBeam(k); return; - case fnHdmaobjPreInstr_PowerBombExplode_SetWindowConf: HdmaobjPreInstr_PowerBombExplode_SetWindowConf(k); return; - case fnHdmaobjPreInstr_PowerBombExplode_Stage5_Afterglow: HdmaobjPreInstr_PowerBombExplode_Stage5_Afterglow(k); return; - case fnHdmaobjPreInstr_PowerBombExplode_ExplosionYellow: HdmaobjPreInstr_PowerBombExplode_ExplosionYellow(k); return; - case fnHdmaobjPreInstr_PowerBombExplode_ExplosionWhite: HdmaobjPreInstr_PowerBombExplode_ExplosionWhite(k); return; - case fnHdmaobjPreInstr_PowerBombExplode_PreExplosionWhite: HdmaobjPreInstr_PowerBombExplode_PreExplosionWhite(k); return; - case fnHdmaobjPreInstr_PowerBombExplode_PreExplosionYellow: HdmaobjPreInstr_PowerBombExplode_PreExplosionYellow(k); return; - case fnHdmaobjPreInstr_CrystalFlash_CustomLayerBlend: HdmaobjPreInstr_CrystalFlash_CustomLayerBlend(k); return; - case fnHdmaobjPreInstr_CrystalFlash_Stage2_AfterGlow: HdmaobjPreInstr_CrystalFlash_Stage2_AfterGlow(k); return; - case fnHdmaobjPreInstr_CrystalFlash_Stage1_Explosion: HdmaobjPreInstr_CrystalFlash_Stage1_Explosion(k); return; - case fnHdmaobjPreInstr_FxType22_BG3Yscroll: HdmaobjPreInstr_FxType22_BG3Yscroll(k); return; - case fnHdmaobjPreInstr_BG3Xscroll: HdmaobjPreInstr_BG3Xscroll(k); return; - case fnHdmaobjPreInstr_SkyLandBG2Xscroll: HdmaobjPreInstr_SkyLandBG2Xscroll(k); return; - case fnHdmaobjPreInstr_SkyLandBG2Xscroll2: HdmaobjPreInstr_SkyLandBG2Xscroll2(k); return; - case fnHdmaobjPreInstr_SkyLandBG2XscrollInner: HdmaobjPreInstr_SkyLandBG2XscrollInner(k); return; - case fnHdmaobjPreInstr_FirefleaBG3XScroll: HdmaobjPreInstr_FirefleaBG3XScroll(k); return; - case fnHdmaobjPreInstr_LavaAcidBG3YScroll: HdmaobjPreInstr_LavaAcidBG3YScroll(k); return; - case fnHdmaobjPreInstr_LavaAcidBG2YScroll: HdmaobjPreInstr_LavaAcidBG2YScroll(k); return; - case fnHdmaobjPreInstr_WaterBG3XScroll: HdmaobjPreInstr_WaterBG3XScroll(k); return; - case fnHdmaobjPreInstr_WaterBG2XScroll: HdmaobjPreInstr_WaterBG2XScroll(k); return; - case fnHdmaobjPreInstr_WaterBG2XScroll_Func2: HdmaobjPreInstr_WaterBG2XScroll_Func2(k); return; - case fnHdmaobjPreInstr_WaterBG2XScroll_Func1: HdmaobjPreInstr_WaterBG2XScroll_Func1(k); return; - case fnHdmaobjPreInstr_RainBg3Scroll: HdmaobjPreInstr_RainBg3Scroll(k); return; - case fnHdmaobjPreInstr_SporesBG3Xscroll: HdmaobjPreInstr_SporesBG3Xscroll(k); return; - case fnHdmaobjPreInstr_FogBG3Scroll: HdmaobjPreInstr_FogBG3Scroll(k); return; - case fnHdmaobjPreInstr_CheckLotsOfEventsHappened: HdmaobjPreInstr_CheckLotsOfEventsHappened(k); return; - case fnHdmaobjPreInstr_DC23: HdmaobjPreInstr_DC23(k); return; - case fnHdmaobjPreInstr_DC69: HdmaobjPreInstr_DC69(k); return; - case fnHdmaobjPreInstr_DCBA: HdmaobjPreInstr_DCBA(k); return; - case fnHdmaobjPreInstr_BombTorizoHazeColorMathBgColor: HdmaobjPreInstr_BombTorizoHazeColorMathBgColor(k); return; - case fnHdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyAlive: HdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyAlive(k); return; - case fnHdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyDead: HdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyDead(k); return; - case fnHdmaobjPreInstr_HazeColorMathSubscreen_FadingIn: HdmaobjPreInstr_HazeColorMathSubscreen_FadingIn(k); return; - case fnHdmaobjPreInstr_HazeColorMathSubscreen_FadedIn: HdmaobjPreInstr_HazeColorMathSubscreen_FadedIn(k); return; - case fnHdmaobjPreInstr_HazeColorMathSubscreen_FadingOut: HdmaobjPreInstr_HazeColorMathSubscreen_FadingOut(k); return; - case fnHdmaobjPreInstr_DF94: HdmaobjPreInstr_DF94(k); return; - case fnHdmaobjPreInstr_VariaSuitPickup: HdmaobjPreInstr_VariaSuitPickup(k); return; - case fnHdmaobjPreInstr_GravitySuitPickup: HdmaobjPreInstr_GravitySuitPickup(k); return; - case fnHdmaobjPreInstr_E449: HdmaobjPreInstr_E449(k); return; - case fnHdmaobjPreInstr_E567: HdmaobjPreInstr_E567(k); return; - case fnHdmaobjPreInstr_E7BC: HdmaobjPreInstr_E7BC(k); return; - case fnHdmaobjPreInstr_E9E6: HdmaobjPreInstr_E9E6(k); return; - case fnHdmaobjPreInstr_EA3C: HdmaobjPreInstr_EA3C(k); return; - case fnHdmaobjPreInstr_EACB: HdmaobjPreInstr_EACB(k); return; - case fnHdmaobjPreInstr_Backdrop_TitleSequenceGradient: HdmaobjPreInstr_Backdrop_TitleSequenceGradient(k); return; - case fnHdmaobjPreInstr_ColorMathControlB_TitleGradient: HdmaobjPreInstr_ColorMathControlB_TitleGradient(k); return; - case fnHdmaobjPreInstr_IntroCutsceneCrossfade: HdmaobjPreInstr_IntroCutsceneCrossfade(k); return; - case fnnullsub_357: return; - case fnHdmaobjPreInstr_ECB6: HdmaobjPreInstr_ECB6(k); return; - default: Unreachable(); - } -} - -const uint8 *CallHdmaobjInstr(uint32 ea, uint16 k, const uint8 *j) { - switch (ea) { - case fnnullsub_112: return j; - case fnHdmaobjInstr_Delete: return HdmaobjInstr_Delete(k, j); - case fnHdmaobjInstr_SetPreInstr: return HdmaobjInstr_SetPreInstr(k, j); - case fnHdmaobjInstr_ClearPreInstr: return HdmaobjInstr_ClearPreInstr(k, j); - case fnHdmaobjInstr_CallFarFunc: return HdmaobjInstr_CallFarFunc(k, j); - case fnHdmaobjInstr_Goto: return HdmaobjInstr_Goto(k, j); - case fnHdmaobjInstr_GotoRel: return HdmaobjInstr_GotoRel(k, j); - case fnHdmaobjInstr_DecrementAndGoto: return HdmaobjInstr_DecrementAndGoto(k, j); - case fnHdmaobjInstr_DecrementAndGotoRel: return HdmaobjInstr_DecrementAndGotoRel(k, j); - case fnHdmaobjInstr_SetTimer: return HdmaobjInstr_SetTimer(k, j); - case fnHdmaobjInstr_SetHdmaControl: return HdmaobjInstr_SetHdmaControl(k, j); - case fnHdmaobjInstr_SetHdmaTarget: return HdmaobjInstr_SetHdmaTarget(k, j); - case fnHdmaobjInstr_SetHdmaTablePtr: return HdmaobjInstr_SetHdmaTablePtr(k, j); - case fnHdmaobjInstr_SetHdmaTableBank: return HdmaobjInstr_SetHdmaTableBank(k, j); - case fnHdmaobjInstr_SetIndirectHdmaDataBank: return HdmaobjInstr_SetIndirectHdmaDataBank(k, j); - case fnHdmaobjInstr_Sleep: return HdmaobjInstr_Sleep(k, j); - case fnHdmaobjInstr_SetFlagB: return HdmaobjInstr_SetFlagB(k, j); - case fnHdmaobjInstr_SetFlagB_Copy: return HdmaobjInstr_SetFlagB_Copy(k, j); - case fnHdmaobjInstr_SetFlagB_Copy2: return HdmaobjInstr_SetFlagB_Copy2(k, j); - case fnHdmaobjInstr_SetFlagB_Copy3: return HdmaobjInstr_SetFlagB_Copy3(k, j); - case fnHdmaobjInstr_SetVideoMode1: return HdmaobjInstr_SetVideoMode1(k, j); - case fnHdmaobjInstr_1938_RandomNumber: return HdmaobjInstr_1938_RandomNumber(k, j); - case fnHdmaobjInstr_GotoIfEventHappened: return HdmaobjInstr_GotoIfEventHappened(k, j); - case fnHdmaobjInstr_E4BD: return HdmaobjInstr_E4BD(k, j); - case fnHdmaobjInstr_InitMorphBallEyeBeamHdma: return HdmaobjInstr_InitMorphBallEyeBeamHdma(k, j); - case fnHdmaobjInstr_EC9F_ClearVars: return HdmaobjInstr_EC9F_ClearVars(k, j); - case fnHdmaobjInstr_B3A9: return HdmaobjInstr_B3A9(k, j); - case fnHdmaobjInsr_ConfigTitleSequenceGradientHDMA: return HdmaobjInsr_ConfigTitleSequenceGradientHDMA(k, j); - case fnsub_88D916: sub_88D916(); return j; - default: Unreachable(); return NULL; - } -} - void HdmaobjInstructionHandler(uint8 k) { // 0x88851C int kh = k >> 1; CallHdmaobjPreInstr(hdma_object_pre_instruction_bank[kh] << 16 | hdma_object_pre_instructions[kh], k); if (hdma_object_instruction_timers[kh]-- == 1) { - const uint8 *base = RomPtrWithBank(*((uint8 *)hdma_object_bank_slot + k + 1), 0x8000) - 0x8000; + const uint8 *base = RomBankBase(*((uint8 *)hdma_object_bank_slot + k + 1)); const uint8 *p = base + hdma_object_instruction_list_pointers[kh]; while (GET_WORD(p) & 0x8000) { p = CallHdmaobjInstr(GET_WORD(p) | 0x880000, k, p + 2); @@ -710,21 +612,19 @@ const uint8 *HdmaobjInstr_SetIndirectHdmaDataBank(uint16 k, const uint8 *hdp) { } const uint8 *HdmaobjInstr_Sleep(uint16 k, const uint8 *hdp) { // 0x888682 - const uint8 *base = RomPtrWithBank(*((uint8 *)hdma_object_bank_slot + k + 1), 0x8000) - 0x8000; + const uint8 *base = RomBankBase(*((uint8 *)hdma_object_bank_slot + k + 1)); hdma_object_instruction_list_pointers[k >> 1] = hdp - base - 2; return 0; } uint8 RaiseOrLowerFx(void) { // 0x88868C - if ((fx_target_y_pos & 0x8000u) != 0) + if ((fx_target_y_pos & 0x8000) != 0) return 1; - R22_ = 0; - R24_ = 0; - if ((fx_y_vel & 0x8000u) == 0) { - *(uint16 *)((uint8 *)&R22_ + 1) = fx_y_vel; - uint16 v2 = (__PAIR32__(R24_, R22_) + __PAIR32__(fx_base_y_pos, fx_base_y_subpos)) >> 16; - fx_base_y_subpos += R22_; - if ((v2 & 0x8000u) != 0) + uint32 r24_r22 = (int16)fx_y_vel << 8; + if ((fx_y_vel & 0x8000) == 0) { + uint16 v2 = (r24_r22 + __PAIR32__(fx_base_y_pos, fx_base_y_subpos)) >> 16; + fx_base_y_subpos += r24_r22; + if ((v2 & 0x8000) != 0) v2 = -1; fx_base_y_pos = v2; if (fx_target_y_pos >= v2) { @@ -735,11 +635,9 @@ uint8 RaiseOrLowerFx(void) { // 0x88868C return 1; } } else { - --R24_; - *(uint16 *)((uint8 *)&R22_ + 1) = fx_y_vel; - uint16 v0 = (__PAIR32__(R24_, R22_) + __PAIR32__(fx_base_y_pos, fx_base_y_subpos)) >> 16; - fx_base_y_subpos += R22_; - if ((v0 & 0x8000u) != 0) + uint16 v0 = (r24_r22 + __PAIR32__(fx_base_y_pos, fx_base_y_subpos)) >> 16; + fx_base_y_subpos += r24_r22; + if ((v0 & 0x8000) != 0) v0 = 0; fx_base_y_pos = v0; if (fx_target_y_pos >= v0) { @@ -750,32 +648,6 @@ uint8 RaiseOrLowerFx(void) { // 0x88868C } } -static Func_X_V *const kHdmaobjPreInstr_XrayFuncs[6] = { // 0x8886EF - HdmaobjPreInstr_XrayFunc0_NoBeam, - HdmaobjPreInstr_XrayFunc1_BeamWidening, - HdmaobjPreInstr_XrayFunc2_FullBeam, - HdmaobjPreInstr_XrayFunc3_DeactivateBeam, - HdmaobjPreInstr_XrayFunc4_DeactivateBeam, - HdmaobjPreInstr_XrayFunc5_DeactivateBeam, -}; - -void HdmaobjPreInstr_Xray(uint16 k) { - int16 v1; - - v1 = 4096; - if (fx_type != 36) { - v1 = 0x2000; - if (CanXrayShowBlocks()) { - v1 = 0x4000; - *(uint16 *)®_COLDATA[0] = 0x27; - *(uint16 *)®_COLDATA[1] = 0x47; - *(uint16 *)®_COLDATA[2] = 0x87; - } - } - fx_layer_blending_config_c |= v1; - kHdmaobjPreInstr_XrayFuncs[demo_input_pre_instr](2 * demo_input_pre_instr); -} - void HdmaobjPreInstr_XrayFunc0_NoBeam(uint16 k) { // 0x888732 if ((button_config_run_b & joypad1_lastkeys) != 0) { CalculateXrayHdmaTable(); @@ -867,9 +739,6 @@ void MoveXrayDown(void) { // 0x888835 void CalculateXrayHdmaTable(void) { // 0x888896 int16 v0; - mov24(&R0_, 0x7e9800); - R18_ = xray_angle; - R20_ = demo_input; if (samus_pose_x_dir == 4) v0 = (__PAIR32__(samus_x_pos - layer1_x_pos, samus_x_pos) - (layer1_x_pos | 0x30000)) >> 16; else @@ -881,19 +750,20 @@ void CalculateXrayHdmaTable(void) { // 0x888896 v1 = (__PAIR32__(samus_y_pos - layer1_y_pos, samus_y_pos) - (layer1_y_pos | 0x100000)) >> 16; if (v0 < 0) { if (samus_pose_x_dir != 4) { -LABEL_14: - CalculateXrayHdmaTable_OriginOffScreen(v0, v1); +off_screen: + CalculateXrayHdmaTableInner(v0, v1, xray_angle, demo_input, true, (uint16*)(g_ram + 0x9800)); return; } } else { if ((int16)(v0 - 256) < 0) { - CalculateXrayHdmaTable_OriginOnScreen(v0, v1); + CalculateXrayHdmaTableInner(v0, v1, xray_angle, demo_input, false, (uint16 *)(g_ram + 0x9800)); return; } if (samus_pose_x_dir != 8) - goto LABEL_14; + goto off_screen; } - for (int i = 510; i >= 0; i -= 2) + + for (int i = 510; i >= 0; i -= 2) // Clear hdma_table_1[i >> 1] = 255; } @@ -978,16 +848,14 @@ void HdmaobjPreInstr_XrayFunc5_DeactivateBeam(uint16 k) { // 0x888A08 demo_backup_prev_controller_input = 0; ResponsibleForXrayStandupGlitch(); hdma_object_channels_bitmask[hdma_object_index >> 1] = 0; - QueueSfx1_Max6(0xAu); + QueueSfx1_Max6(0xA); if ((uint8)fx_type != 36) { reg_COLDATA[2] = 0x80; reg_COLDATA[1] = 64; reg_COLDATA[0] = 32; } - R0_.bank = 126; - R0_.addr = ADDR16_OF_RAM(*hdma_table_1); - for (int i = 510; i >= 0; i -= 2) - IndirWriteWord(R0_, i, 0xFF); + for (int i = 510/2; i >= 0; i--) + hdma_table_1[i] = 0xff; if (samus_auto_cancel_hud_item_index) { hud_item_index = 0; samus_auto_cancel_hud_item_index = 0; @@ -995,11 +863,37 @@ void HdmaobjPreInstr_XrayFunc5_DeactivateBeam(uint16 k) { // 0x888A08 } } +static Func_X_V *const kHdmaobjPreInstr_XrayFuncs[6] = { // 0x8886EF + HdmaobjPreInstr_XrayFunc0_NoBeam, + HdmaobjPreInstr_XrayFunc1_BeamWidening, + HdmaobjPreInstr_XrayFunc2_FullBeam, + HdmaobjPreInstr_XrayFunc3_DeactivateBeam, + HdmaobjPreInstr_XrayFunc4_DeactivateBeam, + HdmaobjPreInstr_XrayFunc5_DeactivateBeam, +}; + +void HdmaobjPreInstr_Xray(uint16 k) { + int16 v1; + + v1 = 4096; + if (fx_type != 36) { + v1 = 0x2000; + if (CanXrayShowBlocks()) { + v1 = 0x4000; + *(uint16 *)®_COLDATA[0] = 0x27; + *(uint16 *)®_COLDATA[1] = 0x47; + *(uint16 *)®_COLDATA[2] = 0x87; + } + } + fx_layer_blending_config_c |= v1; + kHdmaobjPreInstr_XrayFuncs[demo_input_pre_instr](2 * demo_input_pre_instr); +} + void SpawnPowerBombExplosion(void) { // 0x888AA4 if (time_is_frozen_flag) { power_bomb_explosion_status = 0x4000; } else { - QueueSfx1_Max15(1u); + QueueSfx1_Max15(1); power_bomb_explosion_status = 0x8000; static const SpawnHdmaObject_Args unk_888ABA = { 0x40, 0x28, 0x8ace }; @@ -1047,17 +941,17 @@ void Hdmaobj_CleanUpTryCrystalFlash(uint16 v0) { // 0x888B4E hdma_object_channels_bitmask[v1 + 1] = 0; power_bomb_pre_explosion_flash_radius = 0; power_bomb_explosion_radius = 0; - CallSomeSamusCode(0x1Eu); + CallSomeSamusCode(0x1E); } void HdmaobjPreInstr_PowerBombExplode_SetWindowConf(uint16 k) { // 0x888B8F - fx_layer_blending_config_c |= 0x8000u; + fx_layer_blending_config_c |= 0x8000; } void HdmaobjPreInstr_PowerBombExplode_Stage5_Afterglow(uint16 k) { // 0x888B98 - if ((power_bomb_explosion_status & 0x8000u) != 0) { + if ((power_bomb_explosion_status & 0x8000) != 0) { int v1 = (uint8)k >> 1; - if ((--hdma_object_timers[v1] & 0x8000u) != 0) { + if ((--hdma_object_timers[v1] & 0x8000) != 0) { if ((*((uint8 *)hdma_object_D + (uint8)k))-- == 1) { hdma_object_instruction_timers[v1] = 1; hdma_object_instruction_list_pointers[v1] += 2; @@ -1122,18 +1016,17 @@ void CalculatePowerBombHdma_RightOfScreen(uint16 k, const uint8 *j) { // 0x888C void CalculatePowerBombHdmaObjectTablePtrs(uint16 k) { // 0x888C62 uint16 v1; - if ((uint16)(power_bomb_explosion_x_pos - layer1_x_pos + 256) >= 0x300u + if ((uint16)(power_bomb_explosion_x_pos - layer1_x_pos + 256) >= 0x300 || (power_bomb_explosion_x_pos_plus_0x100 = power_bomb_explosion_x_pos - layer1_x_pos + 256, v1 = power_bomb_explosion_y_pos - layer1_y_pos + 256, - v1 >= 0x300u)) { + v1 >= 0x300)) { v1 = 0; } power_bomb_explosion_y_pos_rsub_0x1ff = (v1 ^ 0x3FF) - 256; if ((power_bomb_explosion_radius & 0xFF00) == 0) power_bomb_explosion_y_pos_rsub_0x1ff = 0; - R22_ = 3 * power_bomb_explosion_y_pos_rsub_0x1ff; hdma_object_table_pointers[(k >> 1) + 0] = 3 * power_bomb_explosion_y_pos_rsub_0x1ff + addr_kIndirectHdmaTable_PowerBombExplodeLeft; - hdma_object_table_pointers[(k >> 1) + 1] = R22_ + addr_kIndirectHdmaTable_PowerBombExplodeRight; + hdma_object_table_pointers[(k >> 1) + 1] = 3 * power_bomb_explosion_y_pos_rsub_0x1ff + addr_kIndirectHdmaTable_PowerBombExplodeRight; } @@ -1143,7 +1036,7 @@ uint16 CalculatePowerBombHdmaScaled_LeftOfScreen(uint16 k, uint16 j, uint8 multv int8 v2; uint8 v6, v7; do { - LOBYTE(R20_) = Mult8x8(multval, g_byte_88A206[(uint8)j + 32]) >> 8; + uint8 r20 = Mult8x8(multval, g_byte_88A206[(uint8)j + 32]) >> 8; v2 = power_bomb_explosion_x_pos_plus_0x100; uint8 Reg = Mult8x8(multval, g_byte_88A206[(uint8)j]) >> 8; bool v4 = __CFADD__uint8(Reg, v2); @@ -1158,7 +1051,7 @@ uint16 CalculatePowerBombHdmaScaled_LeftOfScreen(uint16 k, uint16 j, uint8 multv while (1) { power_bomb_explosion_left_hdma[(uint8)k] = v7; power_bomb_explosion_right_hdma[(uint8)k] = v6; - if ((uint8)k == (uint8)R20_) + if ((uint8)k == r20) break; LOBYTE(k) = k - 1; } @@ -1173,7 +1066,7 @@ uint16 CalculatePowerBombHdmaScaled_OnScreen(uint16 k, uint16 j, uint8 multval) int8 v5; uint8 v6, v9; do { - LOBYTE(R20_) = Mult8x8(multval, g_byte_88A206[(uint8)j + 32]) >> 8; + uint8 r20 = Mult8x8(multval, g_byte_88A206[(uint8)j + 32]) >> 8; v2 = power_bomb_explosion_x_pos_plus_0x100; uint8 Reg = Mult8x8(multval, g_byte_88A206[(uint8)j]) >> 8; bool v4 = __CFADD__uint8(Reg, v2); @@ -1190,7 +1083,7 @@ uint16 CalculatePowerBombHdmaScaled_OnScreen(uint16 k, uint16 j, uint8 multval) while (1) { power_bomb_explosion_left_hdma[(uint8)k] = v9; power_bomb_explosion_right_hdma[(uint8)k] = v6; - if ((uint8)k == (uint8)R20_) + if ((uint8)k == r20) break; LOBYTE(k) = k - 1; } @@ -1207,7 +1100,7 @@ uint16 CalculatePowerBombHdmaScaled_RightOfScreen(uint16 k, uint16 j, uint8 mult int8 v10; // t2 uint8 v8, v9; do { - LOBYTE(R20_) = Mult8x8(multval, g_byte_88A206[(uint8)j + 32]) >> 8; + uint8 r20 = Mult8x8(multval, g_byte_88A206[(uint8)j + 32]) >> 8; uint8 v2 = power_bomb_explosion_x_pos_plus_0x100; uint8 Reg = Mult8x8(multval, g_byte_88A206[(uint8)j]) >> 8; bool v4 = v2 < Reg; @@ -1225,7 +1118,7 @@ uint16 CalculatePowerBombHdmaScaled_RightOfScreen(uint16 k, uint16 j, uint8 mult while (1) { power_bomb_explosion_left_hdma[(uint8)k] = v8; power_bomb_explosion_right_hdma[(uint8)k] = v9; - if ((uint8)k == (uint8)R20_) + if ((uint8)k == r20) break; LOBYTE(k) = k - 1; } @@ -1238,7 +1131,7 @@ uint16 CalculatePowerBombHdmaScaled_RightOfScreen(uint16 k, uint16 j, uint8 mult void HdmaobjPreInstr_PowerBombExplode_ExplosionYellow(uint16 k) { // 0x888DE9 uint16 v2; - if ((power_bomb_explosion_status & 0x8000u) == 0) + if ((power_bomb_explosion_status & 0x8000) == 0) return; CalculatePowerBombHdmaObjectTablePtrs(k); int kk = Mult8x8(GET_HIBYTE(power_bomb_explosion_radius), g_byte_88A286[0]) >> 8; @@ -1265,7 +1158,7 @@ void HdmaobjPreInstr_PowerBombExplode_ExplosionYellow(uint16 k) { // 0x888DE9 reg_COLDATA[1] = kPowerBombExplosionColors[t + 1] | 0x40; reg_COLDATA[2] = kPowerBombExplosionColors[t + 2] | 0x80; power_bomb_explosion_radius += power_bomb_pre_explosion_radius_speed; - if (power_bomb_explosion_radius < 0x8600u) { + if (power_bomb_explosion_radius < 0x8600) { power_bomb_pre_explosion_radius_speed += kPowerBombExplosionRadiusAccel; } else { int v7 = k >> 1; @@ -1276,7 +1169,7 @@ void HdmaobjPreInstr_PowerBombExplode_ExplosionYellow(uint16 k) { // 0x888DE9 } void HdmaobjPreInstr_PowerBombExplode_ExplosionWhite(uint16 k) { // 0x888EB2 - if ((power_bomb_explosion_status & 0x8000u) == 0) + if ((power_bomb_explosion_status & 0x8000) == 0) return; CalculatePowerBombHdmaObjectTablePtrs(k); @@ -1309,26 +1202,25 @@ void HdmaobjPreInstr_PowerBombExplode_ExplosionWhite(uint16 k) { // 0x888EB2 void CalculatePowerBombHdmaTablePointers(uint16 v0) { // 0x888F56 uint16 v1; - if ((power_bomb_explosion_status & 0x8000u) != 0) { - if ((uint16)(power_bomb_explosion_x_pos - layer1_x_pos + 256) >= 0x300u + if ((power_bomb_explosion_status & 0x8000) != 0) { + if ((uint16)(power_bomb_explosion_x_pos - layer1_x_pos + 256) >= 0x300 || (power_bomb_explosion_x_pos_plus_0x100 = power_bomb_explosion_x_pos - layer1_x_pos + 256, v1 = power_bomb_explosion_y_pos - layer1_y_pos + 256, - v1 >= 0x300u)) { + v1 >= 0x300)) { v1 = 0; } power_bomb_explosion_y_pos_rsub_0x1ff = (v1 ^ 0x3FF) - 256; if ((power_bomb_pre_explosion_flash_radius & 0xFF00) == 0) power_bomb_explosion_y_pos_rsub_0x1ff = 0; int v2 = v0 >> 1; - R22_ = 3 * power_bomb_explosion_y_pos_rsub_0x1ff; hdma_object_table_pointers[v2] = 3 * power_bomb_explosion_y_pos_rsub_0x1ff + addr_kIndirectHdmaTable_PowerBombExplodeLeft; - hdma_object_table_pointers[v2 + 1] = R22_ + addr_kIndirectHdmaTable_PowerBombExplodeRight; + hdma_object_table_pointers[v2 + 1] = 3 * power_bomb_explosion_y_pos_rsub_0x1ff + addr_kIndirectHdmaTable_PowerBombExplodeRight; } } void HdmaobjPreInstr_PowerBombExplode_PreExplosionWhite(uint16 k) { // 0x8890DF - if ((power_bomb_explosion_status & 0x8000u) == 0) + if ((power_bomb_explosion_status & 0x8000) == 0) return; CalculatePowerBombHdmaTablePointers(k); uint16 v1 = 96, v2; @@ -1366,7 +1258,7 @@ void HdmaobjPreInstr_PowerBombExplode_PreExplosionWhite(uint16 k) { // 0x8890DF } void HdmaobjPreInstr_PowerBombExplode_PreExplosionYellow(uint16 k) { // 0x8891A8 - if ((power_bomb_explosion_status & 0x8000u) == 0) + if ((power_bomb_explosion_status & 0x8000) == 0) return; CalculatePowerBombHdmaTablePointers(k); const uint8 *v1 = RomPtr_88(pre_scaled_power_bomb_explosion_shape_def_ptr); @@ -1407,7 +1299,7 @@ void CrystalFlashSetupPart1(void) { // 0x88A2E4 offscreen_power_bomb_right_hdma = 0; power_bomb_pre_explosion_flash_radius = 1024; power_bomb_pre_explosion_radius_speed = kPowerBombPreExplosionRadiusSpeed; - QueueSfx1_Max6(1u); + QueueSfx1_Max6(1); } void CrystalFlashSetupPart2(void) { // 0x88A309 @@ -1438,10 +1330,10 @@ void HdmaobjPreInstr_CrystalFlash_CustomLayerBlend(uint16 k) { // 0x88A339 } void HdmaobjPreInstr_CrystalFlash_Stage2_AfterGlow(uint16 k) { // 0x88A35D - if ((power_bomb_explosion_status & 0x8000u) != 0) { + if ((power_bomb_explosion_status & 0x8000) != 0) { int v1 = k >> 1; - if ((--hdma_object_timers[v1] & 0x8000u) != 0) { - if (((reg_COLDATA[2] | (uint8)(reg_COLDATA[1] | reg_COLDATA[0])) & 0x1F) != 0) { + if ((--hdma_object_timers[v1] & 0x8000) != 0) { + if (((reg_COLDATA[2] | reg_COLDATA[1] | reg_COLDATA[0]) & 0x1F) != 0) { if ((reg_COLDATA[0] & 0x1F) != 0) reg_COLDATA[0] = ((reg_COLDATA[0] & 0x1F) - 1) | 0x20; if ((reg_COLDATA[1] & 0x1F) != 0) @@ -1463,15 +1355,14 @@ void CalculateCrystalFlashHdmaObjectTablePtrs(uint16 k) { // 0x88A42F if ((uint16)(power_bomb_explosion_x_pos - layer1_x_pos + 256) >= 0x300 || (power_bomb_explosion_x_pos_plus_0x100 = power_bomb_explosion_x_pos - layer1_x_pos + 256, v1 = power_bomb_explosion_y_pos - layer1_y_pos + 256, - v1 >= 0x300u)) { + v1 >= 0x300)) { v1 = 0; } power_bomb_explosion_y_pos_rsub_0x1ff = (v1 ^ 0x3FF) - 256; if ((power_bomb_explosion_radius & 0xFF00) == 0) power_bomb_explosion_y_pos_rsub_0x1ff = 0; - R22_ = 3 * power_bomb_explosion_y_pos_rsub_0x1ff; hdma_object_table_pointers[(k >> 1)] = 3 * power_bomb_explosion_y_pos_rsub_0x1ff + addr_kIndirectHdmaTable_PowerBombExplodeLeft; - hdma_object_table_pointers[(k >> 1) + 1] = R22_ + addr_kIndirectHdmaTable_PowerBombExplodeRight; + hdma_object_table_pointers[(k >> 1) + 1] = 3 * power_bomb_explosion_y_pos_rsub_0x1ff + addr_kIndirectHdmaTable_PowerBombExplodeRight; } uint16 CalculateCrystalFlashHdmaDataTablesScaled_LeftOfScreen(uint16 k, uint16 j) { // 0x88A493 @@ -1489,7 +1380,7 @@ uint16 CalculateCrystalFlashHdmaDataTablesScaled_LeftOfScreen(uint16 k, uint16 j break; k--; } - j--; + j++; // note ++ } while ((j & 0x80) == 0); k_out = LOBYTE(k); return right << 8 | left; @@ -1510,7 +1401,7 @@ uint16 CalculateCrystalFlashHdmaDataTablesScaled_OnScreen(uint16 k, uint16 j) { break; k--; } - j--; + j++; // note ++ } while ((j & 0x80) == 0); k_out = LOBYTE(k); return right << 8 | left; @@ -1531,7 +1422,7 @@ uint16 CalculateCrystalFlashHdmaDataTablesScaled_RightOfScreen(uint16 k, uint16 break; k--; } - j--; + j++; // note ++ } while ((j & 0x80) == 0); k_out = LOBYTE(k); return right << 8 | left; @@ -1557,7 +1448,7 @@ void HdmaobjPreInstr_CrystalFlash_Stage1_Explosion(uint16 k) { // 0x88A552 power_bomb_explosion_left_hdma[(uint8)i] = v2; power_bomb_explosion_right_hdma[(uint8)i] = GET_HIBYTE(v2); i--; - } while ((i & 0x80u) == 0); + } while ((i & 0x80) == 0); for (uint8 v3 = kk + 1; v3 != 0xc0; v3++) { power_bomb_explosion_left_hdma[v3] = 255; power_bomb_explosion_right_hdma[v3] = 0; @@ -1589,15 +1480,52 @@ void FxTypeFunc_22_ScrollingSky(void) { // 0x88A61B HdmaobjPreInstr_FxType22_BG3Yscroll(0); } +static uint16 SetupSomeHdmaTablesBG3(uint16 r24, uint16 r0, uint16 r3, uint16 r6, uint16 r9) { // 0x88A81C + int16 v1; + + g_word_7E0598 = 32; + *(uint16 *)mother_brain_indirect_hdma = 31; + *(uint16 *)&mother_brain_indirect_hdma[1] = 0; + uint16 v0 = 3; + v1 = layer1_y_pos + 32; + uint16 r18 = layer1_y_pos + 32; + uint16 v2 = 0; + while ((int16)(v1 - *(uint16 *)&RomPtr_88(r0)[v2]) < 0 + || (int16)(v1 - *(uint16 *)&RomPtr_88(r9)[v2]) >= 0) { + v2 += 6; + if ((int16)(v2 - r24) >= 0) + return v0; + } + uint16 v3; + if (sign16(r18 - 1248)) + v3 = r18 & 0xF; + else + v3 = r18 & 0x1F; + uint16 R22_ = v3; + *(uint16 *)&mother_brain_indirect_hdma[3] = *(uint16 *)&RomPtr_88(r3)[v2] - v3; + *(uint16 *)&mother_brain_indirect_hdma[4] = R22_ + *(uint16 *)&RomPtr_88(r6)[v2] - g_word_7E0598; + while (1) { + uint16 r20 = mother_brain_indirect_hdma[v0]; + r18 += r20; + v0 += 3; + g_word_7E0598 += r20; + if (!sign16(g_word_7E0598 - 224)) + break; + while ((int16)(r18 - *(uint16 *)&RomPtr_88(r0)[v2]) < 0 + || (int16)(r18 - *(uint16 *)&RomPtr_88(r9)[v2]) >= 0) { + v2 += 6; + if ((int16)(v2 - r24) >= 0) + return v0; + } + *(uint16 *)&mother_brain_indirect_hdma[v0] = *(uint16 *)&RomPtr_88(r3)[v2]; + *(uint16 *)&mother_brain_indirect_hdma[v0 + 1] = *(uint16 *)&RomPtr_88(r6)[v2] - g_word_7E0598; + } + return v0; +} + void HdmaobjPreInstr_FxType22_BG3Yscroll(uint16 k) { // 0x88A643 DamageSamusInTopRow(); - R0_.addr = addr_word_88A8E8; - R3_.addr = addr_word_88A8E8__plus__2; - R6_.addr = addr_word_88A8E8__plus__4; - R9_.addr = addr_word_88A8E8__plus__6; - R24_ = 78; - Unreachable(); - k = SetupSomeHdmaTablesBG3(); + k = SetupSomeHdmaTablesBG3(78, addr_word_88A8E8, addr_word_88A8E8 + 2, addr_word_88A8E8 + 4, addr_word_88A8E8 + 6); *(uint16 *)&mother_brain_indirect_hdma[k] = 0; } @@ -1615,7 +1543,7 @@ void HdmaobjPreInstr_BG3Xscroll(uint16 k) { if (sign16(layer1_y_pos - 1024)) { if ((nmi_frame_counter_byte & 1) == 0) - g_word_7E0596 = ((uint8)g_word_7E0596 + 2) & 0x1E; + g_word_7E0596 = (g_word_7E0596 + 2) & 0x1E; uint16 v1 = g_word_7E0596; uint16 v2 = 0; do { @@ -1627,33 +1555,29 @@ void HdmaobjPreInstr_BG3Xscroll(uint16 k) { int v3 = k >> 1; if (hdma_object_B[v3]-- == 1) { hdma_object_B[v3] = 6; - hdma_object_A[v3] = ((uint8)hdma_object_A[v3] + 2) & 0x1F; + hdma_object_A[v3] = (hdma_object_A[v3] + 2) & 0x1F; } uint16 v5 = hdma_object_A[v3]; for (int i = 30; i >= 0; i -= 2) { g_word_7E9E80[v5 >> 1] = g_word_88C46E[i >> 1] + reg_BG1HOFS; - v5 = ((uint8)v5 - 2) & 0x1F; + v5 = (v5 - 2) & 0x1F; } } *(uint16 *)&hdma_window_1_left_pos[0].field_0 = 0; *(uint16 *)scrolling_sky_bg2_indirect_hdma = 0; *(uint16 *)&hdma_window_1_left_pos[0].field_2 = 31; *(uint16 *)&scrolling_sky_bg2_indirect_hdma[2] = 31; - R18_ = 31; + uint16 r18 = 31; *(uint16 *)&hdma_window_1_left_pos[1].field_0 = -25088; *(uint16 *)&scrolling_sky_bg2_indirect_hdma[3] = -25088; if (sign16(layer1_y_pos - 1024)) { *(uint16 *)&scrolling_sky_bg2_indirect_hdma[2] = 0; } else { - R20_ = 177; - R22_ = 0; - HdmaFunc_A786(0x105u); + r18 = HdmaFunc_A786(0x105, r18, 177, 0); } uint16 v7 = 5; - R20_ = -24960; - R22_ = 128; - HdmaFunc_A786(5u); - v8 = 224 - R18_; + r18 = HdmaFunc_A786(5, r18, -24960, 128); + v8 = 224 - r18; while ((int16)(v8 - 16) >= 0) { v8 -= 16; *(uint16 *)(&hdma_window_1_left_pos[0].field_0 + v7) = 144; @@ -1673,43 +1597,44 @@ void HdmaobjPreInstr_BG3Xscroll(uint16 k) { *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v7 + 3] = 0; } -void HdmaFunc_A786(uint16 k) { // 0x88A786 +uint16 HdmaFunc_A786(uint16 k, uint16 r18, uint16 r20, uint16 r22) { // 0x88A786 uint16 v0 = k; int16 v2; uint16 v1 = 1216 - layer1_y_pos; - R24_ = 1216 - layer1_y_pos; + uint16 r24 = 1216 - layer1_y_pos; if ((int16)(1216 - layer1_y_pos) >= 0 && layer1_y_pos != 1216) { if (sign16(v1 - 128)) { - R18_ = 1216 - layer1_y_pos; + r18 = 1216 - layer1_y_pos; } else { - R18_ = 1216 - layer1_y_pos; + r18 = 1216 - layer1_y_pos; if (!sign16(v1 - 193)) v1 = 193; - R18_ = v1; - R24_ = v1; + r18 = v1; + r24 = v1; while (1) { v2 = v1 - 16; if (v2 < 0) break; - R24_ = v2; - *(uint16 *)(&hdma_window_1_left_pos[0].field_0 + v0) = R22_ | 0x10; - *(uint16 *)(&hdma_window_1_left_pos[0].field_1 + v0) = R20_; - v1 = R24_; + r24 = v2; + *(uint16 *)(&hdma_window_1_left_pos[0].field_0 + v0) = r22 | 0x10; + *(uint16 *)(&hdma_window_1_left_pos[0].field_1 + v0) = r20; + v1 = r24; v0 += 3; } } - *(uint16 *)(&hdma_window_1_left_pos[0].field_0 + v0) = R22_ | R24_; - *(uint16 *)(&hdma_window_1_left_pos[0].field_1 + v0) = R20_; + *(uint16 *)(&hdma_window_1_left_pos[0].field_0 + v0) = r22 | r24; + *(uint16 *)(&hdma_window_1_left_pos[0].field_1 + v0) = r20; } + return r18; } static const SpawnHdmaObject_Args unk_88A7EF = { 0x42, 0x0f, 0xad76 }; static const SpawnHdmaObject_Args unk_88A80B = { 0x42, 0x0f, 0xad89 }; void FxTypeFunc_20(void) { // 0x88A7D8 - layer2_scroll_x |= 1u; - layer2_scroll_y |= 1u; + layer2_scroll_x |= 1; + layer2_scroll_y |= 1; SpawnHdmaObject(0x88, &unk_88A7EF); set_to_e0_by_scrolling_sky = 224; UNUSED_word_7E059C = 0; @@ -1722,66 +1647,14 @@ void RoomSetupAsm_ScrollingSkyOcean(void) { // 0x88A800 UNUSED_word_7E059C = 0; } -uint16 SetupSomeHdmaTablesBG3(void) { // 0x88A81C - int16 v1; - - g_word_7E0598 = 32; - *(uint16 *)mother_brain_indirect_hdma = 31; - *(uint16 *)&mother_brain_indirect_hdma[1] = 0; - uint16 v0 = 3; - v1 = layer1_y_pos + 32; - R18_ = layer1_y_pos + 32; - uint16 v2 = 0; - while ((int16)(v1 - *(uint16 *)&RomPtr_88(R0_.addr)[v2]) < 0 - || (int16)(v1 - *(uint16 *)&RomPtr_88(R9_.addr)[v2]) >= 0) { - v2 += 6; - if ((int16)(v2 - R24_) >= 0) - return v0; - } - uint16 v3; - if (sign16(R18_ - 1248)) - v3 = R18_ & 0xF; - else - v3 = R18_ & 0x1F; - R22_ = v3; - *(uint16 *)&mother_brain_indirect_hdma[3] = *(uint16 *)&RomPtr_88(R3_.addr)[v2] - v3; - *(uint16 *)&mother_brain_indirect_hdma[4] = R22_ + *(uint16 *)&RomPtr_88(R6_.addr)[v2] - g_word_7E0598; - while (1) { - R20_ = mother_brain_indirect_hdma[v0]; - R18_ += R20_; - v0 += 3; - g_word_7E0598 += R20_; - if (!sign16(g_word_7E0598 - 224)) - break; - while ((int16)(R18_ - *(uint16 *)&RomPtr_88(R0_.addr)[v2]) < 0 - || (int16)(R18_ - *(uint16 *)&RomPtr_88(R9_.addr)[v2]) >= 0) { - v2 += 6; - if ((int16)(v2 - R24_) >= 0) - return v0; - } - *(uint16 *)&mother_brain_indirect_hdma[v0] = *(uint16 *)&RomPtr_88(R3_.addr)[v2]; - *(uint16 *)&mother_brain_indirect_hdma[v0 + 1] = *(uint16 *)&RomPtr_88(R6_.addr)[v2] - g_word_7E0598; - } - return v0; -} - void DamageSamusInTopRow(void) { // 0x88A8C4 if ((int16)(samus_y_pos - samus_y_radius) < 0 || sign16(samus_y_pos - samus_y_radius - 17)) samus_periodic_damage = 8; } -void HdmaobjPreInstr_SkyLandBG2Xscroll(uint16 k) { // 0x88ADB2 - if (!time_is_frozen_flag) - HdmaobjPreInstr_SkyLandBG2XscrollInner(k); -} - -void HdmaobjPreInstr_SkyLandBG2Xscroll2(uint16 k) { // 0x88ADBA - if (!time_is_frozen_flag) - HdmaobjPreInstr_SkyLandBG2XscrollInner(k); -} void HdmaobjPreInstr_SkyLandBG2XscrollInner(uint16 k) { // 0x88ADC2 uint16 i; - + uint16 r24 = 0; reg_BG2SC = 74; uint16 v1 = 0; do { @@ -1795,34 +1668,33 @@ void HdmaobjPreInstr_SkyLandBG2XscrollInner(uint16 k) { // 0x88ADC2 scrolling_sky_bg2_hdma_data[45] = 0; *(uint16 *)scrolling_sky_bg2_indirect_hdma = 31; *(uint16 *)&scrolling_sky_bg2_indirect_hdma[1] = 1438; - R18_ = layer1_y_pos + 32; - R20_ = layer1_y_pos + 224; + uint16 r18 = layer1_y_pos + 32; + uint16 r20 = layer1_y_pos + 224; uint16 v5 = 0; uint16 v6 = 3; do { - while ((int16)(R18_ - kHdmaScrollEntrys[v5].top_pos) >= 0 - && (int16)(R18_ - kHdmaScrollEntrys[v5 + 1].top_pos) < 0) { - uint16 v8 = kHdmaScrollEntrys[v5 + 1].top_pos - R18_; - R24_ = v8; + while ((int16)(r18 - kHdmaScrollEntrys[v5].top_pos) >= 0 && (int16)(r18 - kHdmaScrollEntrys[v5 + 1].top_pos) < 0) { + uint16 v8 = kHdmaScrollEntrys[v5 + 1].top_pos - r18; + r24 = v8; if (!sign16(v8 - 128)) { *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v6] = 127; *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v6 + 1] = kHdmaScrollEntrys[v5].hdma_data_table_entry + 2; v6 += 3; - v8 = R24_ - 127; + v8 = r24 - 127; } *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v6] = v8; *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v6 + 1] = kHdmaScrollEntrys[v5].hdma_data_table_entry + 2; - R18_ += R24_; + r18 += r24; v6 += 3; - if (!sign16(R18_ - R20_)) { + if (!sign16(r18 - r20)) { *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v6 + 3] = 0; return; } } ++v5; } while (sign16(v5 * 8 - 184)); - for (i = 1535 - R18_; ; i = R24_ - 127) { - R24_ = i; + for (i = 1535 - r18; ; i = r24 - 127) { + r24 = i; if (sign16(i - 128)) break; *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v6] = 127; @@ -1834,19 +1706,18 @@ void HdmaobjPreInstr_SkyLandBG2XscrollInner(uint16 k) { // 0x88ADC2 *(uint16 *)&scrolling_sky_bg2_indirect_hdma[v6 + 3] = 0; } -void RoomCode_ScrollingSkyLand(void) { // 0x88AF8D - R0_.addr = addr_off_88AD9C; - *(uint16 *)&R0_.bank = 136; - RoomMainAsm_ScrollingSky(); + +void HdmaobjPreInstr_SkyLandBG2Xscroll(uint16 k) { // 0x88ADB2 + if (!time_is_frozen_flag) + HdmaobjPreInstr_SkyLandBG2XscrollInner(k); } -void RoomMainAsm_ScrollingSkyOcean(void) { // 0x88AF99 - R0_.addr = addr_off_88ADA6; - *(uint16 *)&R0_.bank = 136; - RoomMainAsm_ScrollingSky(); +void HdmaobjPreInstr_SkyLandBG2Xscroll2(uint16 k) { // 0x88ADBA + if (!time_is_frozen_flag) + HdmaobjPreInstr_SkyLandBG2XscrollInner(k); } -void RoomMainAsm_ScrollingSky(void) { // 0x88AFA3 +void RoomMainAsm_ScrollingSky(LongPtr r0) { // 0x88AFA3 if (time_is_frozen_flag) { WORD(scrolling_sky_bg2_indirect_hdma[0]) = 0; } else { @@ -1864,10 +1735,10 @@ void RoomMainAsm_ScrollingSky(void) { // 0x88AFA3 int v2 = 8 * (uint8)tt; int y1 = (uint8)(tt >> 8); int y2 = (uint8)((tt >> 8) + 1); - VoidP v3 = IndirReadWord(R0_, 2 * y1) + v2; + VoidP v3 = IndirReadWord(r0, 2 * y1) + v2; v1[0].src.addr = v3; v1[1].src.addr = v3 + 64; - VoidP v5 = IndirReadWord(R0_, 2 * y2) + v2; + VoidP v5 = IndirReadWord(r0, 2 * y2) + v2; v1[2].src.addr = v5; v1[3].src.addr = v5 + 64; v1[0].src.bank = 0x8a; @@ -1875,7 +1746,6 @@ void RoomMainAsm_ScrollingSky(void) { // 0x88AFA3 v1[2].src.bank = 0x8a; v1[3].src.bank = 0x8a; int t = (reg_BG2SC & 0xFC) << 8; - R18_ = t; uint16 v6 = t + 4 * ((layer1_y_pos - 16) & 0x1F8); v1[0].vram_dst = v6; v1[1].vram_dst = v6 + 32; @@ -1886,6 +1756,14 @@ void RoomMainAsm_ScrollingSky(void) { // 0x88AFA3 } } +void RoomCode_ScrollingSkyLand(void) { // 0x88AF8D + RoomMainAsm_ScrollingSky((LongPtr) { addr_off_88AD9C, 0x88 }); +} + +void RoomMainAsm_ScrollingSkyOcean(void) { // 0x88AF99 + RoomMainAsm_ScrollingSky((LongPtr) { addr_off_88ADA6, 0x88 }); +} + static const SpawnHdmaObject_Args unk_88B08C = { 0x42, 0x11, 0xb0ac }; static const uint16 kFirefleaFlashingShades[12] = { 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x500, 0x400, 0x300, 0x200, 0x100 }; @@ -1912,7 +1790,7 @@ void HdmaobjPreInstr_FirefleaBG3XScroll(uint16 k) { // 0x88B0BC fireflea_flashing_timer = 6; if (sign16(fireflea_darkness_level - 10)) { v1 = fireflea_flashing_index + 1; - if ((uint16)(fireflea_flashing_index + 1) >= 0xCu) + if ((uint16)(fireflea_flashing_index + 1) >= 0xC) v1 = 0; } else { v1 = 6; @@ -1949,12 +1827,11 @@ void ExpandingContractingHdmaEffect(void) { // 0x88B17F } uint16 v0 = 2 * message_box_animation_y0; uint16 v1 = 2 * message_box_animation_y2; - R18_ = 0; - R20_ = 32; + uint16 r18 = 0, r20 = 32; do { *(uint16 *)&mother_brain_indirect_hdma[v0] = message_box_animation_y1 - message_box_animation_y0; *(uint16 *)&mother_brain_indirect_hdma[v1] = message_box_animation_y3 - message_box_animation_y2; - R18_ += message_box_animation_y_radius; + r18 += message_box_animation_y_radius; if (Unreachable()) { ++message_box_animation_y1; --message_box_animation_y3; @@ -1963,8 +1840,7 @@ void ExpandingContractingHdmaEffect(void) { // 0x88B17F --message_box_animation_y2; v1 -= 2; v0 += 2; - --R20_; - } while (R20_); + } while (--r20); } static const uint16 g_word_88B256[17] = { 0x46, 1, 0x46, 3, 0x46, 2, 0x46, 1, 0x46, 1, 0x46, 2, 0x46, 2, 0x46, 1, 0x8000 }; @@ -1972,7 +1848,7 @@ static const uint16 g_word_88B256[17] = { 0x46, 1, 0x46, 3, 0x46, 2, 0x46, 1, 0x void HandleEarthquakeSoundEffect(void) { // 0x88B21D int16 v1; - if ((earthquake_sfx_timer & 0x8000u) == 0 && (--earthquake_sfx_timer & 0x8000u) != 0) { + if ((earthquake_sfx_timer & 0x8000) == 0 && (--earthquake_sfx_timer & 0x8000) != 0) { uint16 v0 = earthquake_sfx_index; v1 = g_word_88B256[earthquake_sfx_index >> 1]; if (v1 < 0) { @@ -2013,12 +1889,12 @@ void FxHandleTide(void) { // 0x88B2C9 if (*(int16 *)((uint8 *)&fx_y_vel + 1) < 0) { fx_y_suboffset = 0; fx_y_offset = 0; - int v0 = (uint16)(2 * HIBYTE(tide_phase)) >> 1; + int v0 = HIBYTE(tide_phase); uint16 v1 = 8 * kSinCosTable8bit_Sext[v0]; if ((kSinCosTable8bit_Sext[v0] & 0x1000) != 0) --fx_y_offset; *(uint16 *)((uint8 *)&fx_y_suboffset + 1) = v1; - if ((kSinCosTable8bit_Sext[v0] & 0x8000u) == 0) + if ((kSinCosTable8bit_Sext[v0] & 0x8000) == 0) v2 = tide_phase + 288; else v2 = tide_phase + 192; @@ -2026,12 +1902,12 @@ void FxHandleTide(void) { // 0x88B2C9 } else if ((*(uint16 *)((uint8 *)&fx_y_vel + 1) & 0x4000) != 0) { fx_y_suboffset = 0; fx_y_offset = 0; - int v3 = (uint16)(2 * HIBYTE(tide_phase)) >> 1; + int v3 = HIBYTE(tide_phase); uint16 v4 = 32 * kSinCosTable8bit_Sext[v3]; if ((kSinCosTable8bit_Sext[v3] & 0x400) != 0) --fx_y_offset; *(uint16 *)((uint8 *)&fx_y_suboffset + 1) = v4; - if ((kSinCosTable8bit_Sext[v3] & 0x8000u) == 0) + if ((kSinCosTable8bit_Sext[v3] & 0x8000) == 0) v5 = tide_phase + 224; else v5 = tide_phase + 128; @@ -2041,7 +1917,7 @@ void FxHandleTide(void) { // 0x88B2C9 void FxRisingFunction_LavaAcid(void) { // 0x88B343 if (fx_y_vel) { - if ((fx_y_vel & 0x8000u) == 0) { + if ((fx_y_vel & 0x8000) == 0) { if (fx_target_y_pos < fx_base_y_pos || fx_target_y_pos == fx_base_y_pos) return; LABEL_8: @@ -2056,7 +1932,7 @@ LABEL_8: void FxRisingFunction_LavaAcid_WaitToRise(void) { // 0x88B367 HandleEarthquakeSoundEffect(); earthquake_type = 21; - earthquake_timer |= 0x20u; + earthquake_timer |= 0x20; if (!--fx_timer) fx_rising_function_bank_88 = FUNC16(FxRisingFunction_LavaAcid_Raising); } @@ -2064,7 +1940,7 @@ void FxRisingFunction_LavaAcid_WaitToRise(void) { // 0x88B367 void FxRisingFunction_LavaAcid_Raising(void) { // 0x88B382 HandleEarthquakeSoundEffect(); earthquake_type = 21; - earthquake_timer |= 0x20u; + earthquake_timer |= 0x20; if (RaiseOrLowerFx() & 1) { fx_y_vel = 0; fx_rising_function_bank_88 = FUNC16(FxRisingFunction_LavaAcid); @@ -2111,10 +1987,10 @@ void HdmaobjPreInstr_LavaAcidBG3YScroll(uint16 k) { // 0x88B3B0 if (v2 >= 0) { v3 = v2 - layer1_y_pos; if (v3 <= 0) { - v4 = ((uint8)v3 ^ 0x1F) & 0x1F | 0x100; + v4 = (v3 ^ 0x1F) & 0x1F | 0x100; LABEL_8: *(uint16 *)&mother_brain_indirect_hdma[2] = v4; - if (fx_type == 2 && (lava_acid_y_pos & 0x8000u) == 0) { + if (fx_type == 2 && (lava_acid_y_pos & 0x8000) == 0) { int v5 = (uint8)hdma_object_index >> 1; if (hdma_object_C[v5]-- == 1) { hdma_object_C[v5] = 112; @@ -2122,22 +1998,21 @@ LABEL_8: } } random_number = swap16(random_number); - if ((lava_acid_y_pos & 0x8000u) == 0) { + if ((lava_acid_y_pos & 0x8000) == 0) { v8 = lava_acid_y_pos - layer1_y_pos + 256; if (v8 < 0) { v8 = 255; LABEL_17: - R18_ = ((v8 ^ 0x1FF) + 1) & 0x3FF; hdma_object_table_pointers[(uint8)hdma_object_index >> 1] = 3 * (((v8 ^ 0x1FF) + 1) & 0x3FF) + 0xB62A; return; } - if ((uint16)v8 < 0x200u) + if ((uint16)v8 < 0x200) goto LABEL_17; } v8 = 511; goto LABEL_17; } - if ((uint16)v3 < 0x100u) { + if ((uint16)v3 < 0x100) { v4 = (uint8)~v3; goto LABEL_8; } @@ -2162,7 +2037,6 @@ void HdmaobjPreInstr_LavaAcidBG2YScroll(uint16 k) { // 0x88B4D5 } else { Handle_LavaAcidBG2YScroll_Func1(k); } - R18_ = reg_BG2VOFS & 0xF; hdma_object_table_pointers[(uint8)hdma_object_index >> 1] = 3 * (reg_BG2VOFS & 0xF) + 0xC0B1; } @@ -2180,34 +2054,32 @@ void Handle_LavaAcidBG2YScroll_Func2(uint16 v0) { // 0x88B53B int v1 = v0 >> 1; if (hdma_object_B[v1]-- == 1) { hdma_object_B[v1] = 6; - hdma_object_A[v1] = ((uint8)hdma_object_A[v1] - 2) & 0x1E; + hdma_object_A[v1] = (hdma_object_A[v1] - 2) & 0x1E; } uint8 v3 = *((uint8 *)hdma_object_A + v0); uint8 v4 = 30; - R18_ = 15; + int n = 15; do { g_word_7E9C46[v4 >> 1] = (g_word_88B589[v3 >> 1] + reg_BG2HOFS) & 0x1FF; v3 = (v3 - 2) & 0x1E; v4 = (v4 - 2) & 0x1E; - --R18_; - } while ((R18_ & 0x8000u) == 0); + } while (--n >= 0); } void Handle_LavaAcidBG2YScroll_Func3(uint16 v0) { // 0x88B5A9 WriteReg((SnesRegs)(*((uint8 *)hdma_object_bank_slot + v0) + BBAD0), 0x10); int v1 = v0 >> 1; if (hdma_object_B[v1]-- == 1) { hdma_object_B[v1] = 4; - hdma_object_A[v1] = ((uint8)hdma_object_A[v1] - 2) & 0x1E; + hdma_object_A[v1] = (hdma_object_A[v1] - 2) & 0x1E; } uint8 v3 = (LOBYTE(hdma_object_A[v1]) + 2 * (reg_BG2VOFS & 0xF)) & 0x1E; uint8 v4 = (2 * (reg_BG2VOFS & 0xF) + 30) & 0x1E; - R18_ = 15; + int n = 15; do { g_word_7E9C46[v4 >> 1] = (g_word_88B60A[v3 >> 1] + reg_BG2VOFS) & 0x1FF; v4 = (v4 - 2) & 0x1E; v3 = (v3 - 2) & 0x1E; - --R18_; - } while ((R18_ & 0x8000u) == 0); + } while (--n >= 0); } static const SpawnHdmaObject_Args unk_88C40F = { 0x42, 0x11, 0xd856 }; static const SpawnHdmaObject_Args unk_88C41F = { 0x42, 0x0f, 0xd847 }; @@ -2222,7 +2094,7 @@ void FxTypeFunc_6_Water(void) { // 0x88C3FF void FxRisingFunction_C428_WaterNormal(void) { // 0x88C428 if (fx_y_vel) { - if ((fx_y_vel & 0x8000u) == 0) { + if ((fx_y_vel & 0x8000) == 0) { if (fx_target_y_pos < fx_base_y_pos || fx_target_y_pos == fx_base_y_pos) return; LABEL_8: @@ -2282,10 +2154,10 @@ void HdmaobjPreInstr_WaterBG3XScroll(uint16 k) { // 0x88C48E goto LABEL_6; v3 = v2 - layer1_y_pos; if (v3 <= 0) { - v4 = ((uint8)v3 ^ 0x1F) & 0x1F | 0x100; + v4 = (v3 ^ 0x1F) & 0x1F | 0x100; goto LABEL_8; } - if ((uint16)v3 < 0x100u) + if ((uint16)v3 < 0x100) v4 = (uint8)~(uint8)v3; else LABEL_6: @@ -2293,28 +2165,27 @@ void HdmaobjPreInstr_WaterBG3XScroll(uint16 k) { // 0x88C48E LABEL_8: bg3_ypos = v4; int v5 = (uint8)hdma_object_index >> 1; - R20_ = layer1_x_pos + (int8)HIBYTE(hdma_object_C[v5]); + uint16 r20 = layer1_x_pos + (int8)HIBYTE(hdma_object_C[v5]); if (hdma_object_B[v5]-- == 1) { hdma_object_B[v5] = 10; - hdma_object_A[v5] = ((uint8)hdma_object_A[v5] + 2) & 0x1E; + hdma_object_A[v5] = (hdma_object_A[v5] + 2) & 0x1E; } uint8 v7 = hdma_object_A[v5]; for (int i = 30; (i & 0x80) == 0; i -= 2) { - *(uint16 *)&mother_brain_indirect_hdma[v7 + 4] = g_word_88C46E[i >> 1] + R20_; + *(uint16 *)&mother_brain_indirect_hdma[v7 + 4] = g_word_88C46E[i >> 1] + r20; v7 = (v7 - 2) & 0x1E; } if ((fx_liquid_options & 1) != 0) hdma_object_C[(uint8)hdma_object_index >> 1] += 64; - if ((fx_y_pos & 0x8000u) == 0) { + if ((fx_y_pos & 0x8000) == 0) { v9 = fx_y_pos - layer1_y_pos + 256; if (v9 < 0) { - v9 = ((uint8)fx_y_pos - (uint8)layer1_y_pos) & 0xF | 0x100; + v9 = (fx_y_pos - layer1_y_pos) & 0xF | 0x100; LABEL_22: - R18_ = ((v9 ^ 0x1FF) + 1) & 0x3FF; hdma_object_table_pointers[(uint8)hdma_object_index >> 1] = 3 * (((v9 ^ 0x1FF) + 1) & 0x3FF) + 0xC645; return; } - if ((uint16)v9 < 0x200u) + if ((uint16)v9 < 0x200) goto LABEL_22; } v9 = 511; @@ -2341,37 +2212,35 @@ LABEL_4: } HdmaobjPreInstr_WaterBG2XScroll_Func2(k); LABEL_6: - if ((fx_y_pos & 0x8000u) != 0) + if ((fx_y_pos & 0x8000) != 0) goto LABEL_10; v1 = fx_y_pos - layer1_y_pos + 256; if (v1 >= 0) { - if ((uint16)v1 < 0x200u) + if ((uint16)v1 < 0x200) goto LABEL_11; LABEL_10: v1 = 511; goto LABEL_11; } - v1 = ((uint8)fx_y_pos - (uint8)layer1_y_pos) & 0xF | 0x100; + v1 = (fx_y_pos - layer1_y_pos) & 0xF | 0x100; LABEL_11: - R18_ = (v1 ^ 0x1FF) & 0x3FF; - hdma_object_table_pointers[(uint8)k >> 1] = 3 * ((v1 ^ 0x1FF) & 0x3FF) - 0x30BA; + hdma_object_table_pointers[(uint8)k >> 1] = 3 * ((v1 ^ 0x1FF) & 0x3FF) + 0xCF46; } void HdmaobjPreInstr_WaterBG2XScroll_Func2(uint16 k) { // 0x88C5E4 int v1 = (uint8)k >> 1; if (hdma_object_B[v1]-- == 1) { hdma_object_B[v1] = 6; - hdma_object_A[v1] = ((uint8)hdma_object_A[v1] + 2) & 0x1E; + hdma_object_A[v1] = (hdma_object_A[v1] + 2) & 0x1E; } uint8 v3 = (LOBYTE(hdma_object_A[v1]) + 2 * (reg_BG2VOFS & 0xF)) & 0x1E; uint8 v4 = (2 * (reg_BG2VOFS & 0xF) + 30) & 0x1E; - R18_ = 15; + int n = 15; do { g_word_7E9C46[(v4 >> 1) + 1] = g_word_88C46E[v3 >> 1] + reg_BG2HOFS; v4 = (v4 - 2) & 0x1E; v3 = (v3 - 2) & 0x1E; - --R18_; - } while ((R18_ & 0x8000u) == 0); + } while (--n >= 0); } void HdmaobjPreInstr_WaterBG2XScroll_Func1(uint16 k) { // 0x88C636 @@ -2428,12 +2297,10 @@ void HdmaobjPreInstr_RainBg3Scroll(uint16 k) { // 0x88D9A1 fx_layer_blending_config_c = fx_layer_blending_config_b; if (!time_is_frozen_flag) { int v1 = (uint8)k >> 1; - R18_ = hdma_object_E[v1] - layer1_y_pos; - bg3_ypos = R18_ + (int8)HIBYTE(hdma_object_A[v1]); + bg3_ypos = hdma_object_E[v1] - layer1_y_pos + (int8)HIBYTE(hdma_object_A[v1]); hdma_object_A[v1] -= 1536; hdma_object_E[v1] = layer1_y_pos; - R18_ = hdma_object_F[v1] - layer1_x_pos; - bg3_xpos = R18_ + (int8)HIBYTE(hdma_object_B[v1]); + bg3_xpos = hdma_object_F[v1] - layer1_x_pos + (int8)HIBYTE(hdma_object_B[v1]); hdma_object_B[v1] += hdma_object_D[v1]; hdma_object_F[v1] = layer1_x_pos; } @@ -2455,27 +2322,12 @@ void HdmaobjPreInstr_SporesBG3Xscroll(uint16 k) { // 0x88DA47 bg3_ypos = layer1_y_pos + (int8)HIBYTE(hdma_object_C[v1]); uint16 v3 = hdma_object_C[v1] - 64; hdma_object_C[v1] = v3; - R20_ = v3; +// R20 = v3; bg3_xpos = layer1_x_pos + (int8)HIBYTE(hdma_object_D[v1]); - R18_ = layer1_x_pos + v3; +// R18 = layer1_x_pos + v3; hdma_object_D[v1] = hdma_object_D[v1]; } } -static const uint16 g_word_88DAE8[16] = { 0, 1, 1, 0, 0, 65535, 65535, 0, 0, 1, 1, 0, 0, 65535, 65535, 0 }; -void sub_88DA9F(uint16 k) { // 0x88DA9F - int v1 = (uint8)k >> 1; - if (hdma_object_B[v1]-- == 1) { - hdma_object_B[v1] = 10; - hdma_object_A[v1] = ((uint8)hdma_object_A[v1] + 2) & 0x1F; - } - uint8 v3 = hdma_object_A[v1]; - for (int i = 30; (i & 0x80) == 0; i -= 2) { - *(uint16 *)&mother_brain_indirect_hdma[v3 + 4] = g_word_88DAE8[i >> 1] + (i & 1) + samus_x_pos + R18_; - v3 = (v3 - 2) & 0x1F; - } - R20_ &= 0xFu; - hdma_object_table_pointers[(uint8)hdma_object_index >> 1] = 3 * R20_ + 0xC945; -} void FxTypeFunc_C(void) { // 0x88DB08 gameplay_BG3SC = 92; @@ -2496,12 +2348,11 @@ void HdmaobjPreInstr_FogBG3Scroll(uint16 k) { // 0x88DB36 } void FxTypeFunc_26_TourianEntranceStatue(void) { // 0x88DB8A - static const SpawnHardcodedPlmArgs unk_88DB97 = { 0x06, 0x0c, 0xb777 }; static const SpawnHdmaObject_Args unk_88DBBA = { 0x42, 0x11, 0xd856 }; static const SpawnHdmaObject_Args unk_88DBC2 = { 0x42, 0x10, 0xdcfa }; - if (CheckEventHappened(0xAu) & 1) { - SpawnHardcodedPlm(&unk_88DB97); + if (CheckEventHappened(0xA) & 1) { + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x06, 0x0c, 0xb777 }); *(uint16 *)scrolls = 514; } reg_BG2SC = 74; @@ -2517,12 +2368,12 @@ void sub_88DBCB(uint16 k) { // 0x88DBCB } void HdmaobjPreInstr_CheckLotsOfEventsHappened(uint16 v0) { // 0x88DBD7 - if (CheckEventHappened(6u) & 1) { - if (CheckEventHappened(7u) & 1) { - if (CheckEventHappened(8u) & 1) { - if (CheckEventHappened(9u) & 1) { - tourian_entrance_statue_animstate |= 0x10u; - if ((tourian_entrance_statue_animstate & 0x8000u) == 0) { + if (CheckEventHappened(6) & 1) { + if (CheckEventHappened(7) & 1) { + if (CheckEventHappened(8) & 1) { + if (CheckEventHappened(9) & 1) { + tourian_entrance_statue_animstate |= 0x10; + if ((tourian_entrance_statue_animstate & 0x8000) == 0) { hdma_object_C[v0 >> 1] = 300; v0 = hdma_object_index; int v1 = hdma_object_index >> 1; @@ -2541,9 +2392,9 @@ void HdmaobjPreInstr_DC23(uint16 k) { // 0x88DC23 HandleEarthquakeSoundEffect(); earthquake_type = 13; - earthquake_timer |= 0x20u; + earthquake_timer |= 0x20; int v1 = (uint8)v0 >> 1; - if ((--hdma_object_C[v1] & 0x8000u) != 0) { + if ((--hdma_object_C[v1] & 0x8000) != 0) { SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueDustClouds, 0); // ? SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueDustClouds, 0); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueDustClouds, 0); @@ -2559,7 +2410,7 @@ void HdmaobjPreInstr_DC69(uint16 k) { // 0x88DC69 HandleEarthquakeSoundEffect(); earthquake_type = 13; - earthquake_timer |= 0x20u; + earthquake_timer |= 0x20; if (!time_is_frozen_flag) { int v1 = (uint8)v0 >> 1; uint16 v2 = hdma_object_A[v1]; @@ -2567,9 +2418,8 @@ void HdmaobjPreInstr_DC69(uint16 k) { // 0x88DC69 uint16 v3 = __CFADD__uint16(v2, -16384) + hdma_object_B[v1] - 1; hdma_object_B[v1] = v3; if (v3 == 0xFF10) { - static const SpawnHardcodedPlmArgs unk_88DC9D = { 0x06, 0x0c, 0xb773 }; - SpawnHardcodedPlm(&unk_88DC9D); - SetEventHappened(0xAu); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x06, 0x0c, 0xb773 }); + SetEventHappened(0xA); int v4 = (uint8)v0 >> 1; hdma_object_instruction_timers[v4] = 1; hdma_object_instruction_list_pointers[v4] += 2; @@ -2588,7 +2438,7 @@ const uint8 *HdmaobjInstr_GotoIfEventHappened(uint16 k, const uint8 *hdp) { // int v2 = k >> 1; hdma_object_C[v2] = 0; hdma_object_A[v2] = 0; - if (CheckEventHappened(0xAu)) { + if (CheckEventHappened(0xA)) { hdma_object_B[v2] = -240; *(uint16 *)&hdma_window_1_left_pos[0].field_0 = -240; return INSTRB_RETURN_ADDR(GET_WORD(hdp)); @@ -2614,7 +2464,7 @@ void HdmaobjPreInstr_BombTorizoHazeColorMathBgColor(uint16 k) { // 0x88DD43 void FxTypeFunc_2C_Haze(void) { // 0x88DDC7 static const SpawnHdmaObject_Args unk_88DDD4 = { 0x40, 0x32, 0xded3 }; static const SpawnHdmaObject_Args unk_88DDDD = { 0x40, 0x32, 0xdeeb }; - if (CheckBossBitForCurArea(1u) & 1) + if (CheckBossBitForCurArea(1) & 1) SpawnHdmaObject(0x88, &unk_88DDDD); else SpawnHdmaObject(0x88, &unk_88DDD4); @@ -2649,13 +2499,13 @@ void HdmaobjPreInstr_HazeColorMathSubscreen_FadingIn(uint16 k) { // 0x88DE2D hdma_object_pre_instructions[(uint8)k >> 1] = FUNC16(HdmaobjPreInstr_HazeColorMathSubscreen_FadedIn); } else { uint8 v3 = k; - LOBYTE(R20_) = *((uint8 *)hdma_object_B + (uint8)k); + uint8 r20 = *((uint8 *)hdma_object_B + (uint8)k); v1 = *((uint8 *)hdma_object_A + (uint8)k); for (int i = 15; i >= 0; --i) { - LOBYTE(R18_) = v1; - *((uint8 *)hdma_table_2 + (uint8)i) = R20_ | v1; - v1 = R18_ - 1; - if ((int8)(R18_ - 1) < 0) + uint8 r18 = v1; + *((uint8 *)hdma_table_2 + (uint8)i) = r20 | v1; + v1 = r18 - 1; + if ((int8)(r18 - 1) < 0) v1 = 0; } ++hdma_object_A[v3 >> 1]; @@ -2680,13 +2530,13 @@ void HdmaobjPreInstr_HazeColorMathSubscreen_FadingOut(uint16 k) { // 0x88DE96 fx_layer_blending_config_c = 44; if (hdma_object_A[(uint8)k >> 1]) { uint8 v3 = k; - LOBYTE(R20_) = *((uint8 *)hdma_object_B + (uint8)k); + uint8 r20 = *((uint8 *)hdma_object_B + (uint8)k); v1 = *((uint8 *)hdma_object_A + (uint8)k); for (int i = 15; i >= 0; --i) { - LOBYTE(R18_) = v1; - *((uint8 *)hdma_table_2 + (uint8)i) = R20_ | v1; - v1 = R18_ - 1; - if ((int8)(R18_ - 1) < 0) + uint8 r18 = v1; + *((uint8 *)hdma_table_2 + (uint8)i) = r20 | v1; + v1 = r18 - 1; + if ((int8)(r18 - 1) < 0) v1 = 0; } --hdma_object_A[v3 >> 1]; @@ -2871,16 +2721,12 @@ uint8 VariaSuitPickup_2_LightBeamWidens(void) { // 0x88E113 } uint8 VariaSuitPickup_4_LightBeamShrinks(void) { // 0x88E1BA - int16 v0; - int16 v3; - if (suit_pickup_palette_transition_color) AdvanceSuitPickupColorMathToBlue(); else AdvanceSuitPickupColorMathToOrange(); - R18_ = (uint8)((uint16)(suit_pickup_light_beam_widening_speed & 0xFF00) >> 8); - suit_pickup_light_beam_pos += R18_; - v0 = suit_pickup_light_beam_pos; + suit_pickup_light_beam_pos += (suit_pickup_light_beam_widening_speed & 0xFF00) >> 8; + int16 v0 = suit_pickup_light_beam_pos; uint16 v1 = 0; do { hdma_table_1[v1 >> 1] = 255; @@ -2888,7 +2734,7 @@ uint8 VariaSuitPickup_4_LightBeamShrinks(void) { // 0x88E1BA --v0; } while (v0 > 0); uint16 v2 = 510; - v3 = suit_pickup_light_beam_pos - 1; + int16 v3 = suit_pickup_light_beam_pos - 1; do { hdma_table_1[v2 >> 1] = 255; v2 -= 2; @@ -2914,7 +2760,7 @@ uint8 VariaSuitPickup_5_LightBeamDissipates(void) { // 0x88E22B } uint8 VariaSuitPickup_6(void) { // 0x88E258 - QueueMusic_Delayed8(3u); + QueueMusic_Delayed8(3); return GravitySuitPickup_6(); } @@ -2935,7 +2781,7 @@ uint8 GravitySuitPickup_6(void) { // 0x88E25F int v0 = hdma_object_index >> 1; hdma_object_instruction_list_pointers[v0] += 2; hdma_object_instruction_timers[v0] = 1; - CallSomeSamusCode(0xBu); + CallSomeSamusCode(0xB); return 0; } @@ -2969,8 +2815,8 @@ uint8 AdvanceSuitPickupColorMathToOrange(void) { // 0x88E2F9 } uint8 VariaSuitPickup_3(void) { // 0x88E320 - equipped_items |= 1u; - collected_items |= 1u; + equipped_items |= 1; + collected_items |= 1; samus_pose = kPose_9B_FaceF_VariaGravitySuit; SamusFunc_F433(); Samus_SetAnimationFrameIfPoseChanged(); @@ -2984,8 +2830,8 @@ uint8 VariaSuitPickup_3(void) { // 0x88E320 } uint8 GravitySuitPickup_3(void) { // 0x88E361 - equipped_items |= 0x20u; - collected_items |= 0x20u; + equipped_items |= 0x20; + collected_items |= 0x20; samus_pose = kPose_9B_FaceF_VariaGravitySuit; SamusFunc_F433(); Samus_SetAnimationFrameIfPoseChanged(); @@ -3023,11 +2869,11 @@ void HdmaobjPreInstr_E449(uint16 k) { // 0x88E449 } } static const SpawnHdmaObject_Args unk_88E4A0 = { 0x42, 0x0f, 0xe4a8 }; -void sub_88E487(uint16 v0) { // 0x88E487 +void sub_88E487(uint16 v0, uint16 r22) { // 0x88E487 enemy_data[2].parameter_1 = v0; enemy_data[3].ai_var_D = 0; enemy_data[3].ai_var_E = 0; - enemy_data[3].ai_preinstr = R22_; + enemy_data[3].ai_preinstr = r22; SpawnHdmaObject(0x88, &unk_88E4A0); } @@ -3083,58 +2929,59 @@ void HdmaobjPreInstr_E567(uint16 v0) { // 0x88E567 int16 v7; uint16 j; uint16 v8; + uint16 r28; + uint16 r30; if (enemy_data[1].parameter_1) { if ((enemy_data[1].parameter_1 & 1) != 0) { - R28_ = 4; - R30_ = 128; + r28 = 4; + r30 = 128; } else { - R28_ = 8; - R30_ = 64; + r28 = 8; + r30 = 64; } int v2 = v0 >> 1; if (hdma_object_B[v2]-- == 1) { hdma_object_B[v2] = 1; - R18_ = 2 * enemy_data[3].ai_preinstr; hdma_object_A[v2] = (2 * enemy_data[3].ai_preinstr + hdma_object_A[v2]) & 0x1FF; } - R20_ = hdma_object_A[v2]; + uint16 r20 = hdma_object_A[v2]; uint16 v4 = 0; do { uint16 v11 = v4; - uint16 v5 = R20_; - int v6 = R20_ >> 1; + uint16 v5 = r20; + int v6 = r20 >> 1; v7 = kSinCosTable8bit_Sext[v6 + 64]; if (v7 < 0) { - R18_ = -v7; - R22_ = Mult8x8(-(int8)v7, enemy_data[3].ai_var_D) >> 8; - R22_ += Mult8x8(HIBYTE(R18_), enemy_data[3].ai_var_D); - R24_ = Mult8x8(R18_, HIBYTE(enemy_data[3].ai_var_D)); - uint8 mult = Mult8x8(HIBYTE(R18_), HIBYTE(enemy_data[3].ai_var_D)); - R22_ += R24_; - R18_ = (uint8)((uint16)((R22_ + (mult << 8)) & 0xFF00) >> 8); - R20_ = (R28_ + v5) & 0x1FF; + uint16 r18 = -v7; + uint16 r22 = Mult8x8(-(int8)v7, enemy_data[3].ai_var_D) >> 8; + r22 += Mult8x8(HIBYTE(r18), enemy_data[3].ai_var_D); + uint16 r24 = Mult8x8(r18, HIBYTE(enemy_data[3].ai_var_D)); + uint8 mult = Mult8x8(HIBYTE(r18), HIBYTE(enemy_data[3].ai_var_D)); + r22 += r24; + r18 = ((r22 + (mult << 8)) & 0xFF00) >> 8; + r20 = (r28 + v5) & 0x1FF; v8 = v11; - *(uint16 *)((uint8 *)&g_word_7E9100 + v11) = reg_BG2HOFS - R18_; + *(uint16 *)((uint8 *)&g_word_7E9100 + v11) = reg_BG2HOFS - r18; } else { - R18_ = kSinCosTable8bit_Sext[v6 + 64]; - R22_ = Mult8x8(v7, enemy_data[3].ai_var_D) >> 8; - R22_ += Mult8x8(HIBYTE(R18_), enemy_data[3].ai_var_D); - R24_ = Mult8x8(R18_, HIBYTE(enemy_data[3].ai_var_D)); - uint8 mult = Mult8x8(HIBYTE(R18_), HIBYTE(enemy_data[3].ai_var_D)); - R22_ += R24_; - R18_ = (uint8)((uint16)((R22_ + (mult << 8)) & 0xFF00) >> 8); - R20_ = (R28_ + v5) & 0x1FF; + uint16 r18 = kSinCosTable8bit_Sext[v6 + 64]; + uint16 r22 = Mult8x8(v7, enemy_data[3].ai_var_D) >> 8; + r22 += Mult8x8(HIBYTE(r18), enemy_data[3].ai_var_D); + uint16 r24 = Mult8x8(r18, HIBYTE(enemy_data[3].ai_var_D)); + uint8 mult = Mult8x8(HIBYTE(r18), HIBYTE(enemy_data[3].ai_var_D)); + r22 += r24; + r18 = ((r22 + (mult << 8)) & 0xFF00) >> 8; + r20 = (r28 + v5) & 0x1FF; v8 = v11; - *(uint16 *)((uint8 *)&g_word_7E9100 + v11) = R18_ + reg_BG2HOFS; + *(uint16 *)((uint8 *)&g_word_7E9100 + v11) = r18 + reg_BG2HOFS; } v4 = v8 + 2; - } while ((int16)(v4 - R30_) < 0); + } while ((int16)(v4 - r30) < 0); if ((enemy_data[1].parameter_1 & 1) != 0) { for (int i = 126; i >= 0; i -= 2) *(uint16 *)((uint8 *)&g_word_7E9180 + i) = reg_BG2HOFS + reg_BG2HOFS - *(uint16 *)((uint8 *)&g_word_7E9100 + i); } else { - for (j = 62; (j & 0x8000u) == 0; j -= 2) + for (j = 62; (j & 0x8000) == 0; j -= 2) *(uint16 *)((uint8 *)&g_word_7E9140 + j) = reg_BG2HOFS + reg_BG2HOFS - *(uint16 *)((uint8 *)&g_word_7E9100 + j); } } else { @@ -3182,7 +3029,7 @@ void HdmaobjPreInstr_E7BC(uint16 k) { // 0x88E7BC void sub_88E7ED(void) { // 0x88E7ED uint16 v0 = g_word_88E833[hdma_object_A[0] >> 1]; - if ((v0 & 0x8000u) == 0) { + if ((v0 & 0x8000) == 0) { ++hdma_object_A[0]; ++hdma_object_A[0]; ++hdma_object_A[0]; @@ -3233,18 +3080,14 @@ const uint8 *HdmaobjInstr_InitMorphBallEyeBeamHdma(uint16 k, const uint8 *hdp) { void sub_88E987(uint16 v0) { // 0x88E987 uint16 v3 = v0; - R18_ = enemy_data[1].ai_var_D; - R20_ = hdma_object_C[v0 >> 1]; + uint16 r18 = enemy_data[1].ai_var_D; + uint16 r20 = hdma_object_C[v0 >> 1]; uint16 v1 = enemy_data[1].y_pos - layer1_y_pos; uint16 v2 = enemy_data[1].x_pos - layer1_x_pos; if ((int16)(enemy_data[1].x_pos - layer1_x_pos) >= 0 && sign16(enemy_data[1].x_pos - layer1_x_pos - 256)) { - R0_.bank = 126; - R0_.addr = ADDR16_OF_RAM(g_word_7E9100); - CalculateXrayHdmaTable_OriginOnScreen(v2, v1); + CalculateXrayHdmaTableInner(v2, v1, r18, r20, false, &g_word_7E9100); } else { - R0_.bank = 126; - R0_.addr = ADDR16_OF_RAM(g_word_7E9100); - CalculateXrayHdmaTable_OriginOffScreen(v2, v1); + CalculateXrayHdmaTableInner(v2, v1, r18, r20, true, &g_word_7E9100); } reg_COLDATA[0] = *((uint8 *)hdma_object_A + v3); reg_COLDATA[1] = *((uint8 *)hdma_object_A + v3 + 1); @@ -3281,7 +3124,7 @@ void HdmaobjPreInstr_EA3C(uint16 k) { // 0x88EA3C *((uint8 *)hdma_object_A + k) = g_byte_88EA8B[(uint16)(4 * g_word_7E9090)]; *((uint8 *)hdma_object_A + k + 1) = g_byte_88EA8B[v2 + 1]; *((uint8 *)hdma_object_B + k) = g_byte_88EA8B[v2 + 2]; - g_word_7E9090 = ((uint8)g_word_7E9090 + 1) & 0xF; + g_word_7E9090 = (g_word_7E9090 + 1) & 0xF; } else { int v1 = hdma_object_index >> 1; hdma_object_instruction_list_pointers[v1] += 2; @@ -3370,17 +3213,17 @@ void CinematicFunction_Intro_Func133(void) { // 0x88EC3B g_word_7E0D9C = 1; *(uint16 *)&g_byte_7E0D9E = 0x4000; loop_counter_transfer_enemies_to_vram = 8; - grapple_beam_tmpD82 = 192; - grapple_beam_y_quarter_vel = 192; + button_config_shoot_x_saved = 192; + button_config_itemcancel_y_saved = 192; v0 = 12621824; - *(uint16 *)((uint8 *)&grapple_beam_tmpD84 + 1) = HIWORD(v0); - *(uint16 *)((uint8 *)&grapple_beam_tmpD82 + 1) = v0; - grapple_beam_y_quarter_subvel = -26496; + *(uint16 *)((uint8 *)&button_config_jump_a_saved + 1) = HIWORD(v0); + *(uint16 *)((uint8 *)&button_config_shoot_x_saved + 1) = v0; + button_config_run_b_saved = -26496; v1 = 12621824; - *(uint16 *)((uint8 *)&grapple_beam_tmpD8A + 1) = HIWORD(v1); - *(uint16 *)((uint8 *)&grapple_beam_y_quarter_vel + 1) = v1; - grapple_beam_varD8C = -26496; - grapple_beam_varD8E = 0; + *(uint16 *)((uint8 *)&button_config_itemswitch_saved + 1) = HIWORD(v1); + *(uint16 *)((uint8 *)&button_config_itemcancel_y_saved + 1) = v1; + button_config_aim_down_L_saved = -26496; + button_config_aim_up_R_saved = 0; static const SpawnHdmaObject_Args unk_88EC82 = { 0x42, 0x11, 0xec8a }; SpawnHdmaObject(0x88, &unk_88EC82); } @@ -3399,43 +3242,42 @@ void HdmaobjPreInstr_ECB6(uint16 k) { // 0x88ECB6 uint16 v8; if (g_word_7E0D9C) { - R28_ = 4; - R30_ = 128; - R18_ = 2 * loop_counter_transfer_enemies_to_vram; + uint16 r28 = 4; + int n = 128; int v3 = k >> 1; hdma_object_A[v3] = (2 * loop_counter_transfer_enemies_to_vram + hdma_object_A[v3]) & 0x1FF; - R20_ = hdma_object_A[v3]; + uint16 r20 = hdma_object_A[v3]; uint16 v4 = 0; do { uint16 v10 = v4; - uint16 v5 = R20_; - int v6 = R20_ >> 1; + uint16 v5 = r20; + int v6 = r20 >> 1; v7 = kSinCosTable8bit_Sext[v6 + 64]; if (v7 < 0) { - R18_ = -v7; - R22_ = Mult8x8(-(int8)v7, g_byte_7E0D9E) >> 8; - R22_ += Mult8x8(HIBYTE(R18_), g_byte_7E0D9E); - R24_ = Mult8x8(R18_, g_byte_7E0D9F); - uint8 mult = Mult8x8(HIBYTE(R18_), g_byte_7E0D9F); - R22_ += R24_; - R18_ = (uint8)((uint16)((R22_ + (mult << 8)) & 0xFF00) >> 8); - R20_ = (R28_ + v5) & 0x1FF; + uint16 r18 = -v7; + uint16 r22 = Mult8x8(-(int8)v7, g_byte_7E0D9E) >> 8; + r22 += Mult8x8(HIBYTE(r18), g_byte_7E0D9E); + uint16 r24 = Mult8x8(r18, g_byte_7E0D9F); + uint8 mult = Mult8x8(HIBYTE(r18), g_byte_7E0D9F); + r22 += r24; + r18 = ((r22 + (mult << 8)) & 0xFF00) >> 8; + r20 = (r28 + v5) & 0x1FF; v8 = v10; - hdma_table_1[v10 >> 1] = reg_BG3HOFS - R18_; + hdma_table_1[v10 >> 1] = reg_BG3HOFS - r18; } else { - R18_ = kSinCosTable8bit_Sext[v6 + 64]; - R22_ = Mult8x8(v7, g_byte_7E0D9E) >> 8; - R22_ += Mult8x8(HIBYTE(R18_), g_byte_7E0D9E); - R24_ = Mult8x8(R18_, g_byte_7E0D9F); - uint8 mult = Mult8x8(HIBYTE(R18_), g_byte_7E0D9F); - R22_ += R24_; - R18_ = (uint8)((uint16)((R22_ + (mult << 8)) & 0xFF00) >> 8); - R20_ = (R28_ + v5) & 0x1FF; + uint16 r18 = kSinCosTable8bit_Sext[v6 + 64]; + uint16 r22 = Mult8x8(v7, g_byte_7E0D9E) >> 8; + r22 += Mult8x8(HIBYTE(r18), g_byte_7E0D9E); + uint16 r24 = Mult8x8(r18, g_byte_7E0D9F); + uint8 mult = Mult8x8(HIBYTE(r18), g_byte_7E0D9F); + r22 += r24; + r18 = ((r22 + (mult << 8)) & 0xFF00) >> 8; + r20 = (r28 + v5) & 0x1FF; v8 = v10; - hdma_table_1[v10 >> 1] = R18_ + reg_BG3HOFS; + hdma_table_1[v10 >> 1] = r18 + reg_BG3HOFS; } v4 = v8 + 2; - } while ((int16)(v4 - R30_) < 0); + } while ((int16)(v4 - n) < 0); for (int i = 126; i >= 0; i -= 2) hdma_table_1[(i >> 1) + 64] = reg_BG3HOFS + reg_BG3HOFS - hdma_table_1[i >> 1]; } else { @@ -3443,4 +3285,104 @@ void HdmaobjPreInstr_ECB6(uint16 k) { // 0x88ECB6 hdma_object_instruction_list_pointers[v2] += 2; hdma_object_instruction_timers[v2] = 1; } -} \ No newline at end of file +} + +void CallHdmaobjPreInstr(uint32 ea, uint16 k) { + switch (ea) { + case fnnullsub_56: return; + case fnnullsub_293: return; + case fnnullsub_309: return; + case fnHdmaobjPreInstr_XraySetup: HdmaobjPreInstr_XraySetup(k); return; + case fnHdmaobjPreInstr_Xray: HdmaobjPreInstr_Xray(k); return; + case fnHdmaobjPreInstr_XrayFunc0_NoBeam: HdmaobjPreInstr_XrayFunc0_NoBeam(k); return; + case fnHdmaobjPreInstr_XrayFunc1_BeamWidening: HdmaobjPreInstr_XrayFunc1_BeamWidening(k); return; + case fnHdmaobjPreInstr_XrayFunc2_FullBeam: HdmaobjPreInstr_XrayFunc2_FullBeam(k); return; + case fnHdmaobjPreInstr_XrayFunc3_DeactivateBeam: HdmaobjPreInstr_XrayFunc3_DeactivateBeam(k); return; + case fnHdmaobjPreInstr_XrayFunc4_DeactivateBeam: HdmaobjPreInstr_XrayFunc4_DeactivateBeam(k); return; + case fnHdmaobjPreInstr_XrayFunc5_DeactivateBeam: HdmaobjPreInstr_XrayFunc5_DeactivateBeam(k); return; + case fnHdmaobjPreInstr_PowerBombExplode_SetWindowConf: HdmaobjPreInstr_PowerBombExplode_SetWindowConf(k); return; + case fnHdmaobjPreInstr_PowerBombExplode_Stage5_Afterglow: HdmaobjPreInstr_PowerBombExplode_Stage5_Afterglow(k); return; + case fnHdmaobjPreInstr_PowerBombExplode_ExplosionYellow: HdmaobjPreInstr_PowerBombExplode_ExplosionYellow(k); return; + case fnHdmaobjPreInstr_PowerBombExplode_ExplosionWhite: HdmaobjPreInstr_PowerBombExplode_ExplosionWhite(k); return; + case fnHdmaobjPreInstr_PowerBombExplode_PreExplosionWhite: HdmaobjPreInstr_PowerBombExplode_PreExplosionWhite(k); return; + case fnHdmaobjPreInstr_PowerBombExplode_PreExplosionYellow: HdmaobjPreInstr_PowerBombExplode_PreExplosionYellow(k); return; + case fnHdmaobjPreInstr_CrystalFlash_CustomLayerBlend: HdmaobjPreInstr_CrystalFlash_CustomLayerBlend(k); return; + case fnHdmaobjPreInstr_CrystalFlash_Stage2_AfterGlow: HdmaobjPreInstr_CrystalFlash_Stage2_AfterGlow(k); return; + case fnHdmaobjPreInstr_CrystalFlash_Stage1_Explosion: HdmaobjPreInstr_CrystalFlash_Stage1_Explosion(k); return; + case fnHdmaobjPreInstr_FxType22_BG3Yscroll: HdmaobjPreInstr_FxType22_BG3Yscroll(k); return; + case fnHdmaobjPreInstr_BG3Xscroll: HdmaobjPreInstr_BG3Xscroll(k); return; + case fnHdmaobjPreInstr_SkyLandBG2Xscroll: HdmaobjPreInstr_SkyLandBG2Xscroll(k); return; + case fnHdmaobjPreInstr_SkyLandBG2Xscroll2: HdmaobjPreInstr_SkyLandBG2Xscroll2(k); return; + case fnHdmaobjPreInstr_SkyLandBG2XscrollInner: HdmaobjPreInstr_SkyLandBG2XscrollInner(k); return; + case fnHdmaobjPreInstr_FirefleaBG3XScroll: HdmaobjPreInstr_FirefleaBG3XScroll(k); return; + case fnHdmaobjPreInstr_LavaAcidBG3YScroll: HdmaobjPreInstr_LavaAcidBG3YScroll(k); return; + case fnHdmaobjPreInstr_LavaAcidBG2YScroll: HdmaobjPreInstr_LavaAcidBG2YScroll(k); return; + case fnHdmaobjPreInstr_WaterBG3XScroll: HdmaobjPreInstr_WaterBG3XScroll(k); return; + case fnHdmaobjPreInstr_WaterBG2XScroll: HdmaobjPreInstr_WaterBG2XScroll(k); return; + case fnHdmaobjPreInstr_WaterBG2XScroll_Func2: HdmaobjPreInstr_WaterBG2XScroll_Func2(k); return; + case fnHdmaobjPreInstr_WaterBG2XScroll_Func1: HdmaobjPreInstr_WaterBG2XScroll_Func1(k); return; + case fnHdmaobjPreInstr_RainBg3Scroll: HdmaobjPreInstr_RainBg3Scroll(k); return; + case fnHdmaobjPreInstr_SporesBG3Xscroll: HdmaobjPreInstr_SporesBG3Xscroll(k); return; + case fnHdmaobjPreInstr_FogBG3Scroll: HdmaobjPreInstr_FogBG3Scroll(k); return; + case fnHdmaobjPreInstr_CheckLotsOfEventsHappened: HdmaobjPreInstr_CheckLotsOfEventsHappened(k); return; + case fnHdmaobjPreInstr_DC23: HdmaobjPreInstr_DC23(k); return; + case fnHdmaobjPreInstr_DC69: HdmaobjPreInstr_DC69(k); return; + case fnHdmaobjPreInstr_DCBA: HdmaobjPreInstr_DCBA(k); return; + case fnHdmaobjPreInstr_BombTorizoHazeColorMathBgColor: HdmaobjPreInstr_BombTorizoHazeColorMathBgColor(k); return; + case fnHdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyAlive: HdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyAlive(k); return; + case fnHdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyDead: HdmaobjPreInstr_HazeColorMathSubscreen_CeresRidleyDead(k); return; + case fnHdmaobjPreInstr_HazeColorMathSubscreen_FadingIn: HdmaobjPreInstr_HazeColorMathSubscreen_FadingIn(k); return; + case fnHdmaobjPreInstr_HazeColorMathSubscreen_FadedIn: HdmaobjPreInstr_HazeColorMathSubscreen_FadedIn(k); return; + case fnHdmaobjPreInstr_HazeColorMathSubscreen_FadingOut: HdmaobjPreInstr_HazeColorMathSubscreen_FadingOut(k); return; + case fnHdmaobjPreInstr_DF94: HdmaobjPreInstr_DF94(k); return; + case fnHdmaobjPreInstr_VariaSuitPickup: HdmaobjPreInstr_VariaSuitPickup(k); return; + case fnHdmaobjPreInstr_GravitySuitPickup: HdmaobjPreInstr_GravitySuitPickup(k); return; + case fnHdmaobjPreInstr_E449: HdmaobjPreInstr_E449(k); return; + case fnHdmaobjPreInstr_E567: HdmaobjPreInstr_E567(k); return; + case fnHdmaobjPreInstr_E7BC: HdmaobjPreInstr_E7BC(k); return; + case fnHdmaobjPreInstr_E9E6: HdmaobjPreInstr_E9E6(k); return; + case fnHdmaobjPreInstr_EA3C: HdmaobjPreInstr_EA3C(k); return; + case fnHdmaobjPreInstr_EACB: HdmaobjPreInstr_EACB(k); return; + case fnHdmaobjPreInstr_Backdrop_TitleSequenceGradient: HdmaobjPreInstr_Backdrop_TitleSequenceGradient(k); return; + case fnHdmaobjPreInstr_ColorMathControlB_TitleGradient: HdmaobjPreInstr_ColorMathControlB_TitleGradient(k); return; + case fnHdmaobjPreInstr_IntroCutsceneCrossfade: HdmaobjPreInstr_IntroCutsceneCrossfade(k); return; + case fnnullsub_357: return; + case fnHdmaobjPreInstr_ECB6: HdmaobjPreInstr_ECB6(k); return; + default: Unreachable(); + } +} + +const uint8 *CallHdmaobjInstr(uint32 ea, uint16 k, const uint8 *j) { + switch (ea) { + case fnnullsub_112: return j; + case fnHdmaobjInstr_Delete: return HdmaobjInstr_Delete(k, j); + case fnHdmaobjInstr_SetPreInstr: return HdmaobjInstr_SetPreInstr(k, j); + case fnHdmaobjInstr_ClearPreInstr: return HdmaobjInstr_ClearPreInstr(k, j); + case fnHdmaobjInstr_CallFarFunc: return HdmaobjInstr_CallFarFunc(k, j); + case fnHdmaobjInstr_Goto: return HdmaobjInstr_Goto(k, j); + case fnHdmaobjInstr_GotoRel: return HdmaobjInstr_GotoRel(k, j); + case fnHdmaobjInstr_DecrementAndGoto: return HdmaobjInstr_DecrementAndGoto(k, j); + case fnHdmaobjInstr_DecrementAndGotoRel: return HdmaobjInstr_DecrementAndGotoRel(k, j); + case fnHdmaobjInstr_SetTimer: return HdmaobjInstr_SetTimer(k, j); + case fnHdmaobjInstr_SetHdmaControl: return HdmaobjInstr_SetHdmaControl(k, j); + case fnHdmaobjInstr_SetHdmaTarget: return HdmaobjInstr_SetHdmaTarget(k, j); + case fnHdmaobjInstr_SetHdmaTablePtr: return HdmaobjInstr_SetHdmaTablePtr(k, j); + case fnHdmaobjInstr_SetHdmaTableBank: return HdmaobjInstr_SetHdmaTableBank(k, j); + case fnHdmaobjInstr_SetIndirectHdmaDataBank: return HdmaobjInstr_SetIndirectHdmaDataBank(k, j); + case fnHdmaobjInstr_Sleep: return HdmaobjInstr_Sleep(k, j); + case fnHdmaobjInstr_SetFlagB: return HdmaobjInstr_SetFlagB(k, j); + case fnHdmaobjInstr_SetFlagB_Copy: return HdmaobjInstr_SetFlagB_Copy(k, j); + case fnHdmaobjInstr_SetFlagB_Copy2: return HdmaobjInstr_SetFlagB_Copy2(k, j); + case fnHdmaobjInstr_SetFlagB_Copy3: return HdmaobjInstr_SetFlagB_Copy3(k, j); + case fnHdmaobjInstr_SetVideoMode1: return HdmaobjInstr_SetVideoMode1(k, j); + case fnHdmaobjInstr_1938_RandomNumber: return HdmaobjInstr_1938_RandomNumber(k, j); + case fnHdmaobjInstr_GotoIfEventHappened: return HdmaobjInstr_GotoIfEventHappened(k, j); + case fnHdmaobjInstr_E4BD: return HdmaobjInstr_E4BD(k, j); + case fnHdmaobjInstr_InitMorphBallEyeBeamHdma: return HdmaobjInstr_InitMorphBallEyeBeamHdma(k, j); + case fnHdmaobjInstr_EC9F_ClearVars: return HdmaobjInstr_EC9F_ClearVars(k, j); + case fnHdmaobjInstr_B3A9: return HdmaobjInstr_B3A9(k, j); + case fnHdmaobjInsr_ConfigTitleSequenceGradientHDMA: return HdmaobjInsr_ConfigTitleSequenceGradientHDMA(k, j); + case fnsub_88D916: sub_88D916(); return j; + default: Unreachable(); return NULL; + } +} diff --git a/src/sm_89.c b/src/sm_89.c index 7a4c7b3..529b8b9 100644 --- a/src/sm_89.c +++ b/src/sm_89.c @@ -110,7 +110,6 @@ void LoadFXHeader(void) { v6 = get_FxDef(current_fx_entry_ptr); uint16 v7 = v6->type; if (v6->type) { - R19_ = -30720; kFxTypeFuncPtrs[v7 >> 1](); } v8 = get_FxDef(current_fx_entry_ptr); @@ -150,7 +149,7 @@ void LoadFXHeader(void) { void RoomCode_CeresElevatorShaft(void) { // 0x89ACC3 int16 v1; - if ((ceres_status & 0x8000u) != 0) { + if ((ceres_status & 0x8000) != 0) { if ((int16)(112 - samus_x_pos) < 0 && (int16)(144 - samus_x_pos) >= 0 && sign16(samus_y_pos - 128) @@ -158,7 +157,7 @@ void RoomCode_CeresElevatorShaft(void) { // 0x89ACC3 && !samus_y_speed && !samus_y_subspeed && game_state == kGameState_8_MainGameplay) { - CallSomeSamusCode(2u); + CallSomeSamusCode(2); screen_fade_delay = 0; screen_fade_counter = 0; game_state = 32; @@ -183,4 +182,4 @@ void RoomCode_CeresElevatorShaft(void) { // 0x89ACC3 *(uint16 *)room_main_asm_variables = v1; } } -} \ No newline at end of file +} diff --git a/src/sm_8b.c b/src/sm_8b.c index dfc4db1..5de585f 100644 --- a/src/sm_8b.c +++ b/src/sm_8b.c @@ -33,15 +33,42 @@ #define g_word_8CE1E9 ((uint16*)RomFixedPtr(0x8ce1e9)) #define g_off_8CBC5D ((uint16*)RomFixedPtr(0x8cbc5d)) +void CallCinematicFunction(uint32 ea); +void CallCinematicSprPreInstr(uint32 ea, uint16 j); +uint16 CallCinematicSprInstr(uint32 ea, uint16 k, uint16 j); +void CallCinematicBgPreInstr(uint32 ea, uint16 j); +uint16 CallCinematicBgInstr(uint32 ea, uint16 k, uint16 j); +void CallCinematicSpriteObjectSetup(uint32 ea, uint16 j); +uint16 CallIntroObjectInstr(uint32 ea, uint16 k, uint16 j); +void CallMode7PreInstr(uint32 ea, uint16 k); +uint16 CallMode7Instr(uint32 ea, uint16 k, uint16 j); +void CallCinematicSpriteInit(uint32 ea, uint16 j); +void CallCreditsObjectFunc(uint32 ea, uint16 k); - +// Misc forwards +void SetSomeStuffForSpriteObject_16(void); +void CinematicFunction_Intro_SetupTransitionToGameplay(void); +void CinematicFunction_Intro_Func13(void); +void CinematicFunction_Intro_Func40(void); +void CinematicFunction_Intro_Func135(void); +void CinematicFunction_Intro_Func145(void); +void CinematicFunction_Intro_Func37(uint16 k); +void CinematicFunction_Intro_Func111(void); +void CinematicFunction_Intro_Func117(void); +void CinematicFunction_Intro_Func127(void); +void CinematicFunction_Intro_Func149(void); +void CinematicFunction_Intro_Func160(uint16 j, uint16 a); +void CinematicFunction_F0B8(uint16 j); +void CinematicFunction_Intro_Func189b(uint16 k); +void CinematicFunction_Intro_Func210_EndingSamusFall(uint16 k); +void CinematicFunction_Intro_Func216(void); void SetupPpuForTitleSequence(void) { // 0x8B8000 WriteReg(INIDISP, 0x80); reg_INIDISP = 0x80; - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; - WriteReg(BGMODE, 7u); + WriteReg(BGMODE, 7); reg_BGMODE = 7; WriteReg(M7SEL, 0x80); reg_M7SEL = 0x80; @@ -71,7 +98,7 @@ void SetupPpuForTitleSequence(void) { // 0x8B8000 WriteReg(COLDATA, 0xE0); WriteReg(SETINI, 0); reg_SETINI = 0; - memset(g_ram + 0x3000u, 0, 0x7FE); + memset(g_ram + 0x3000, 0, 0x7FE); oam_next_ptr = 0; menu_option_index = 0; screen_fade_delay = 0; @@ -108,9 +135,9 @@ void SetupPpuForTitleSequence(void) { // 0x8B8000 void SetupPpu_Intro(void) { // 0x8B80DA WriteReg(INIDISP, 0x80); reg_INIDISP = 0x80; - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; - WriteReg(BGMODE, 9u); + WriteReg(BGMODE, 9); reg_BGMODE = 9; WriteReg(M7SEL, 0); reg_M7SEL = 0; @@ -125,8 +152,8 @@ void SetupPpu_Intro(void) { // 0x8B80DA reg_BG12NBA = 0; WriteReg(BG12NBA, 0); reg_BG34NBA = 4; - WriteReg(BG34NBA, 4u); - WriteReg(TM, 4u); + WriteReg(BG34NBA, 4); + WriteReg(TM, 4); reg_TM = 4; WriteReg(TS, 0); reg_TS = 0; @@ -168,9 +195,9 @@ void SetupPpu_Intro(void) { // 0x8B80DA void SetupPpu_3_Mode7(void) { // 0x8B819B WriteReg(INIDISP, 0x80); reg_INIDISP = 0x80; - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; - WriteReg(BGMODE, 7u); + WriteReg(BGMODE, 7); reg_BGMODE = 7; WriteReg(M7SEL, 0x80); reg_M7SEL = 0x80; @@ -218,9 +245,9 @@ void SetupPpu_3_Mode7(void) { // 0x8B819B void SetupPpu_4_Mode1(void) { // 0x8B8230 WriteReg(INIDISP, 0x80); reg_INIDISP = 0x80; - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; - WriteReg(BGMODE, 1u); + WriteReg(BGMODE, 1); reg_BGMODE = 1; WriteReg(M7SEL, 0); reg_M7SEL = 0; @@ -233,7 +260,7 @@ void SetupPpu_4_Mode1(void) { // 0x8B8230 reg_BG4SC = 0; WriteReg(BG4SC, 0); reg_BG12NBA = 6; - WriteReg(BG12NBA, 6u); + WriteReg(BG12NBA, 6); reg_BG34NBA = 0; WriteReg(BG34NBA, 0); WriteReg(TM, 0x11); @@ -256,7 +283,7 @@ void SetupPpu_5_Mode7(void) { // 0x8B8293 reg_INIDISP = 0x80; WriteReg(OBSEL, 0xA3); reg_OBSEL = -93; - WriteReg(BGMODE, 7u); + WriteReg(BGMODE, 7); reg_BGMODE = 7; WriteReg(M7SEL, 0); reg_M7SEL = 0; @@ -309,9 +336,9 @@ void SetupPpu_5_Mode7(void) { // 0x8B8293 void SetupPpu_6_Mode1(void) { // 0x8B833A WriteReg(INIDISP, 0x80); reg_INIDISP = 0x80; - WriteReg(OBSEL, 2u); + WriteReg(OBSEL, 2); reg_OBSEL = 2; - WriteReg(BGMODE, 1u); + WriteReg(BGMODE, 1); reg_BGMODE = 1; WriteReg(M7SEL, 0); reg_M7SEL = 0; @@ -363,7 +390,7 @@ void SetupPpu_7_Mode1(void) { // 0x8B83D3 reg_INIDISP = 0x80; WriteReg(OBSEL, 0); reg_OBSEL = 0; - WriteReg(BGMODE, 1u); + WriteReg(BGMODE, 1); reg_BGMODE = 1; WriteReg(M7SEL, 0); reg_M7SEL = 0; @@ -378,8 +405,8 @@ void SetupPpu_7_Mode1(void) { // 0x8B83D3 reg_BG12NBA = 84; WriteReg(BG12NBA, 0x54); reg_BG34NBA = 2; - WriteReg(BG34NBA, 2u); - WriteReg(TM, 1u); + WriteReg(BG34NBA, 2); + WriteReg(TM, 1); reg_TM = 1; WriteReg(TS, 0); reg_TS = 0; @@ -427,61 +454,20 @@ void HandleMode7TransformationNoRotation(void) { // 0x8B8518 reg_BG1VOFS = cinematic_var10; } +static uint32 Smult16x16(uint16 r38, uint16 r40) { // 0x8B858F + uint32 t = (int16)r38 * (int16)r40; + return t; +} + void HandleMode7TransformationMatrix(void) { // 0x8B8532 - R38 = kSinCosTable8bit_Sext[((uint8)(cinematic_var5 + 64)) + 64]; - R40 = cinematic_var6; - Smult16x16Shr16(); - reg_M7D = reg_M7A = PAIR16(R42, HIBYTE(R44)); - R38 = kSinCosTable8bit_Sext[((uint8)cinematic_var5) + 64]; - R40 = cinematic_var6; - Smult16x16Shr16(); - uint16 v1 = PAIR16(R42, HIBYTE(R44)); + reg_M7D = reg_M7A = Smult16x16(kSinCosTable8bit_Sext[((uint8)(cinematic_var5 + 64)) + 64], cinematic_var6) >> 8; + uint16 v1 = Smult16x16(kSinCosTable8bit_Sext[((uint8)cinematic_var5) + 64], cinematic_var6) >> 8; reg_M7B = v1; reg_M7C = -v1; reg_BG1HOFS = cinematic_var8; reg_BG1VOFS = cinematic_var10; } - -void Smult16x16Shr16(void) { // 0x8B858F - if ((R38 & 0x8000u) == 0) { - if ((R40 & 0x8000u) != 0) { - R40 = -R40; - Umult16x16Shr16(); - Negate32(&R42, &R44, &R42, &R44); - } else { - Umult16x16Shr16(); - } - } else { - R38 = -R38; - if ((R40 & 0x8000u) != 0) { - R40 = -R40; - Umult16x16Shr16(); - } else { - Umult16x16Shr16(); - Negate32(&R42, &R44, &R42, &R44); - } - } -} - -void Umult16x16Shr16(void) { // 0x8B85EE - R44 = Mult8x8(R38, R40); - R46 = Mult8x8(HIBYTE(R38), R40); - R48 = Mult8x8(R38, HIBYTE(R40)); - uint16 RegWord = Mult8x8(HIBYTE(R38), HIBYTE(R40)); - R42 = RegWord; - R46 += R48; - bool v1 = __CFADD__uint8(HIBYTE(R44), (uint8)R46); - HIBYTE(R44) += R46; - LOBYTE(R42) = RegWord + v1 + HIBYTE(R46); - if (__CFADD__uint8(v1, HIBYTE(R46)) | __CFADD__uint8((uint8)RegWord, v1 + HIBYTE(R46))) - ++HIBYTE(R42); -} - -void HandleFadeIn_(void) { // 0x8B8666 - HandleFadeIn(); -} - void SetPpuBackdropSomeColor(void) { // 0x8B866B reg_CGWSEL = 0; reg_CGADSUB = -127; @@ -537,28 +523,28 @@ void CinematicUpdateSomeBg(void) { // 0x8B8806 } } -void CallProcessCinematicBgObject(uint32 ea, uint16 k, uint16 j) { +void CallProcessCinematicBgObject(uint32 ea, uint16 k, uint16 j, uint16 r18) { switch (ea) { - case fnProcessCinematicBgObject_Nothing: ProcessCinematicBgObject_Nothing(k, j); return; - case fnProcessCinematicBgObject_DrawChar: ProcessCinematicBgObject_DrawChar(k, j); return; - case fnProcessCinematicBgObject_DrawToTextTilemap: ProcessCinematicBgObject_DrawToTextTilemap(k, j); return; - case fnProcessCinematicBgObject_DrawToBgTilemap: ProcessCinematicBgObject_DrawToBgTilemap(k, j); return; - case fnProcessCinematicBgObject_Unk1: ProcessCinematicBgObject_Unk1(k, j); return; - case fnProcessCinematicBgObject_Unk2: ProcessCinematicBgObject_Unk2(k, j); return; + case fnProcessCinematicBgObject_Nothing: ProcessCinematicBgObject_Nothing(k, j, r18); return; + case fnProcessCinematicBgObject_DrawChar: ProcessCinematicBgObject_DrawChar(k, j, r18); return; + case fnProcessCinematicBgObject_DrawToTextTilemap: ProcessCinematicBgObject_DrawToTextTilemap(k, j, r18); return; + case fnProcessCinematicBgObject_DrawToBgTilemap: ProcessCinematicBgObject_DrawToBgTilemap(k, j, r18); return; + case fnProcessCinematicBgObject_Unk1: ProcessCinematicBgObject_Unk1(k, j, r18); return; + case fnProcessCinematicBgObject_Unk2: ProcessCinematicBgObject_Unk2(k, j, r18); return; default: Unreachable(); } } -void ProcessCinematicBgObject(uint16 v0) { // 0x8B8839 + +void ProcessCinematicBgObject(uint16 v0, uint16 r18) { // 0x8B8839 uint16 j = cinematicbg_arr1[v0 >> 1]; - R28_ = *(uint16 *)RomPtr_8C(j); - CallProcessCinematicBgObject(R28_ | 0x8B0000, v0, j); + CallProcessCinematicBgObject(*(uint16 *)RomPtr_8C(j) | 0x8B0000, v0, j, r18); } -void ProcessCinematicBgObject_DrawChar(uint16 k, uint16 j) { // 0x8B884D +void ProcessCinematicBgObject_DrawChar(uint16 k, uint16 j, uint16 r18) { // 0x8B884D int16 v3; cinematicbg_var1 = cinematicbg_var1 == 0; - SpawnTextGlowObject(j); + SpawnTextGlowObject(j, r18); const uint8 *v2 = RomPtr_8C(cinematicbg_instr_ptr[k >> 1]); if (*((int16 *)v2 + 3) < 0) { cinematicbg_arr7[15] = 8; @@ -569,182 +555,146 @@ void ProcessCinematicBgObject_DrawChar(uint16 k, uint16 j) { // 0x8B884D } cinematicbg_arr8[15] = v3 - 8; if (GET_WORD(v2 + 4) != 0xD67D && cinematicbg_var1) - QueueSfx3_Max6(0xDu); - ProcessCinematicBgObject_DrawToTextTilemap(0x1E, j); + QueueSfx3_Max6(0xD); + ProcessCinematicBgObject_DrawToTextTilemap(0x1E, j, r18); } -void ProcessCinematicBgObject_DrawToTextTilemap(uint16 k, uint16 j) { // 0x8B88B7 +void ProcessCinematicBgObject_DrawToTextTilemap(uint16 k, uint16 j, uint16 r18) { // 0x8B88B7 uint16 jorg = j; - uint16 TilemapOffsetForTile = CinematicGetTilemapOffsetForTile(); + uint16 offs = CinematicGetTilemapOffsetForTile(r18); + uint16 r22 = offs; const uint8 *v3 = RomPtr_8C(j); - R18_ = v3[2]; - R24_ = R18_; - R20_ = v3[3]; + uint16 m = v3[2]; + uint16 morg = m; + uint16 n = v3[3]; while (1) { do { - *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + TilemapOffsetForTile) = *((uint16 *)RomPtr_8C(j) + 2); + *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + offs) = *((uint16 *)RomPtr_8C(j) + 2); j += 2; - TilemapOffsetForTile += 2; - --R18_; - } while (R18_); - R18_ = R24_; - if (!--R20_) + offs += 2; + --m; + } while (m); + m = morg; + if (!--n) break; - R22_ += 64; - TilemapOffsetForTile = R22_; + r22 += 64; + offs = r22; } } -void ProcessCinematicBgObject_Nothing(uint16 k, uint16 j) { // 0x8B8849 +void ProcessCinematicBgObject_Nothing(uint16 k, uint16 j, uint16 r18) { // 0x8B8849 } -void ProcessCinematicBgObject_DrawToBgTilemap(uint16 k, uint16 j) { // 0x8B88FD +void ProcessCinematicBgObject_DrawToBgTilemap(uint16 k, uint16 j, uint16 r18) { // 0x8B88FD uint16 jorg = j; - uint16 TilemapOffsetForTile = CinematicGetTilemapOffsetForTile(); + uint16 offs = CinematicGetTilemapOffsetForTile(r18); + uint16 r22 = offs; const uint8 *v3 = RomPtr_8C(j); - R18_ = v3[2]; - R24_ = R18_; - R20_ = v3[3]; + uint16 m = v3[2]; + uint16 morg = m; + int n = v3[3]; while (1) { do { - *(uint16 *)((uint8 *)ram3800.cinematic_bg_tilemap + TilemapOffsetForTile) = *((uint16 *)RomPtr_8C(j) + 2); + *(uint16 *)((uint8 *)ram3800.cinematic_bg_tilemap + offs) = *((uint16 *)RomPtr_8C(j) + 2); j += 2; - TilemapOffsetForTile += 2; - --R18_; - } while (R18_); - R18_ = R24_; - if (!--R20_) + offs += 2; + --m; + } while (m); + m = morg; + if (!--n) break; - R22_ += 64; - TilemapOffsetForTile = R22_; + r22 += 64; + offs = r22; } } -uint16 CinematicGetTilemapOffsetForTile(void) { // 0x8B8943 - R20_ = 2 * (uint8)R18_; - R22_ = R20_ + HIBYTE(R18_) * 0x40; - return R22_; +uint16 CinematicGetTilemapOffsetForTile(uint16 r18) { // 0x8B8943 + return 2 * (uint8)r18 + HIBYTE(r18) * 0x40; } -void ProcessCinematicBgObject_Unk1(uint16 k, uint16 j) { // 0x8B896B - Mult0x80Add(); +void ProcessCinematicBgObject_Unk1(uint16 k, uint16 j, uint16 r18) { // 0x8B896B + uint16 r22 = Mult0x80Add(r18); const uint8 *v2 = RomPtr_8C(j); - R18_ = v2[2]; - R20_ = v2[3]; + uint16 r18x = v2[2]; + uint16 n = v2[3]; uint16 v3 = j + 4; uint16 v4 = mode7_vram_write_queue_tail; do { *(uint16 *)(&mode7_write_queue[0].field_0 + v4) = 128; *(uint16 *)((uint8 *)&mode7_write_queue[0].field_1 + v4) = v3; *(uint16 *)&mode7_write_queue[0].gap3[v4] = 139; - *(uint16 *)&mode7_write_queue[0].gap3[v4 + 1] = R18_; - *(uint16 *)&mode7_write_queue[0].gap3[v4 + 3] = R22_; + *(uint16 *)&mode7_write_queue[0].gap3[v4 + 1] = r18x; + *(uint16 *)&mode7_write_queue[0].gap3[v4 + 3] = r22; *(uint16 *)((uint8 *)&mode7_write_queue[1].field_1 + v4) = 0; v4 += 9; - v3 += R18_; - R22_ += 128; - --R20_; - } while (R20_); + v3 += r18x; + r22 += 128; + } while (--n); mode7_vram_write_queue_tail = v4; } -void ProcessCinematicBgObject_Unk2(uint16 k, uint16 j) { // 0x8B89CF - Mult0x80Add(); +void ProcessCinematicBgObject_Unk2(uint16 k, uint16 j, uint16 r18) { // 0x8B89CF + uint16 r22 = Mult0x80Add(r18); const uint8 *v2 = RomPtr_8C(j); - R18_ = v2[2]; - R20_ = v2[3]; + int n = v2[2]; + uint16 r20 = v2[3]; uint16 v3 = j + 4; uint16 v4 = mode7_vram_write_queue_tail; do { *(uint16 *)(&mode7_write_queue[0].field_0 + v4) = 128; *(uint16 *)((uint8 *)&mode7_write_queue[0].field_1 + v4) = v3; *(uint16 *)&mode7_write_queue[0].gap3[v4] = 139; - *(uint16 *)&mode7_write_queue[0].gap3[v4 + 1] = R20_; - *(uint16 *)&mode7_write_queue[0].gap3[v4 + 3] = R22_; + *(uint16 *)&mode7_write_queue[0].gap3[v4 + 1] = r20; + *(uint16 *)&mode7_write_queue[0].gap3[v4 + 3] = r22; *(uint16 *)((uint8 *)&mode7_write_queue[1].field_1 + v4) = 2; v4 += 9; - v3 += R20_; - ++R22_; - --R18_; - } while (R18_); + v3 += r20; + ++r22; + } while (--n); mode7_vram_write_queue_tail = v4; } -void Mult0x80Add(void) { // 0x8B8A2C - R20_ = (uint8)R18_; - R22_ = R20_ + (0x80 * HIBYTE(R18_)); +uint16 Mult0x80Add(uint16 r18) { // 0x8B8A2C + return (uint8)r18 + (0x80 * HIBYTE(r18)); } void Samus_CalcPos_Mode7(void) { // 0x8B8A52 - R34 = samus_x_pos - reg_M7X; - R36 = reg_M7Y - samus_y_pos; - R38 = samus_x_pos - reg_M7X; - R40 = reg_M7A; - Smult16x16Shr16(); - R26_ = PAIR16(R42, HIBYTE(R44)); - R38 = reg_M7B; - R40 = R36; - Smult16x16Shr16(); - R26_ += PAIR16(R42, HIBYTE(R44)); - samus_x_pos = R26_ + reg_M7X; - R38 = reg_M7C; - R40 = R34; - Smult16x16Shr16(); - R26_ = PAIR16(R42, HIBYTE(R44)); - R38 = reg_M7A; - R40 = R36; - Smult16x16Shr16(); - R26_ += PAIR16(R42, HIBYTE(R44)); - samus_y_pos = reg_M7Y - R26_; + uint16 r34 = samus_x_pos - reg_M7X; + uint16 r36 = reg_M7Y - samus_y_pos; + uint16 r26 = Smult16x16(samus_x_pos - reg_M7X, reg_M7A) >> 8; + r26 += Smult16x16(reg_M7B, r36) >> 8; + samus_x_pos = r26 + reg_M7X; + + r26 = Smult16x16(reg_M7C, r34) >> 8; + r26 += Smult16x16(reg_M7A, r36) >> 8; + samus_y_pos = reg_M7Y - r26; } -void CalcExplosion_Mode7(uint16 k) { // 0x8B8AD9 +Point16U CalcExplosion_Mode7(uint16 k) { // 0x8B8AD9 int v1 = k >> 1; - R34 = projectile_x_pos[v1] - reg_M7X; - R36 = reg_M7Y - projectile_y_pos[v1]; - R38 = R34; - R40 = reg_M7A; - Smult16x16Shr16(); - R26_ = PAIR16(R42, HIBYTE(R44)); - R38 = reg_M7B; - R40 = R36; - Smult16x16Shr16(); - R26_ += PAIR16(R42, HIBYTE(R44)); - R20_ = R26_ + reg_M7X - layer1_x_pos; - R38 = reg_M7C; - R40 = R34; - Smult16x16Shr16(); - R26_ = PAIR16(R42, HIBYTE(R44)); - R38 = reg_M7A; - R40 = R36; - Smult16x16Shr16(); - R26_ += PAIR16(R42, HIBYTE(R44)); - R18_ = reg_M7Y - R26_ - layer1_y_pos; + uint16 r34 = projectile_x_pos[v1] - reg_M7X; + uint16 r36 = reg_M7Y - projectile_y_pos[v1]; + uint16 r26 = Smult16x16(r34, reg_M7A) >> 8; + r26 += Smult16x16(reg_M7B, r36) >> 8; + uint16 r20 = r26 + reg_M7X - layer1_x_pos; + r26 = Smult16x16(reg_M7C, r34) >> 8; + r26 += Smult16x16(reg_M7A, r36) >> 8; + uint16 r18 = reg_M7Y - r26 - layer1_y_pos; + return (Point16U) {r20, r18}; } -void CalcCeresSteamPos_Mode7(void) { // 0x8B8B66 - R34 = R18_ - reg_M7X; - R36 = reg_M7Y - R20_; - R38 = R18_ - reg_M7X; - R40 = reg_M7A; - Smult16x16Shr16(); - R26_ = PAIR16(R42, HIBYTE(R44)); - R38 = reg_M7B; - R40 = R36; - Smult16x16Shr16(); - R26_ += PAIR16(R42, HIBYTE(R44)); - R18_ = R26_ + reg_M7X; - R38 = reg_M7C; - R40 = R34; - Smult16x16Shr16(); - R26_ = PAIR16(R42, HIBYTE(R44)); - R38 = reg_M7A; - R40 = R36; - Smult16x16Shr16(); - R26_ += PAIR16(R42, HIBYTE(R44)); - R20_ = reg_M7Y - R26_; +Point16U CalcCeresSteamPos_Mode7(Point16U pt) { // 0x8B8B66 + uint16 r34 = pt.x - reg_M7X; + uint16 r36 = reg_M7Y - pt.y; + uint16 r26 = Smult16x16(pt.x - reg_M7X, reg_M7A) >> 8; + r26 += Smult16x16(reg_M7B, r36) >> 8; + pt.x = r26 + reg_M7X; + r26 = Smult16x16(reg_M7C, r34) >> 8; + r26 += Smult16x16(reg_M7A, r36) >> 8; + pt.y = reg_M7Y - r26; + return pt; } void CopyPalettesToFadingPalettes(void) { // 0x8B8BE9 @@ -762,14 +712,14 @@ void DecomposePaletteDataForFading(void) { // 0x8B8C09 int v1 = 256; do { int v2 = v0 >> 1; - R18_ = tilemap_stuff[v2 + 256]; - int v3 = (R18_ & 0x1F); + uint16 r18 = tilemap_stuff[v2 + 256]; + int v3 = (r18 & 0x1F); tilemap_stuff[v2 + 512] = v3 << 8; tilemap_stuff[v2 + 1280] = v3 << 3; - int v4 = (R18_ & 0x3E0) >> 5; + int v4 = (r18 & 0x3E0) >> 5; tilemap_stuff[v2 + 768] = v4 << 8; tilemap_stuff[v2 + 1536] = v4 << 3; - int v6 = (R18_ & 0x7C00) >> 10; + int v6 = (r18 & 0x7C00) >> 10; tilemap_stuff[v2 + 1024] = v6 << 8; tilemap_stuff[v2 + 1792] = v6 << 3; v0 += 2; @@ -812,9 +762,9 @@ void ComposeFadingPalettes(void) { // 0x8B8CEA int v1 = 256; do { int v2 = v0 >> 1; - int R18 = HIBYTE(tilemap_stuff[v2 + 512]) & 0x1F; - R18 |= (tilemap_stuff[v2 + 768] >> 3) & 0x3E0; - uint16 v3 = R18 | (tilemap_stuff[v2 + 1024] << 2) & 0x7C00; + int r18 = HIBYTE(tilemap_stuff[v2 + 512]) & 0x1F; + r18 |= (tilemap_stuff[v2 + 768] >> 3) & 0x3E0; + uint16 v3 = r18 | (tilemap_stuff[v2 + 1024] << 2) & 0x7C00; tilemap_stuff[v2] = v3; palette_buffer[v2] = v3; v0 += 2; @@ -824,14 +774,14 @@ void ComposeFadingPalettes(void) { // 0x8B8CEA void CinematicFunction_Intro_Func20(uint16 j) { // 0x8B8D23 uint16 *tt = (uint16 *)RomPtr_8B(j); uint16 v2 = tt[0]; - int R18 = tt[1]; + int r18 = tt[1]; uint16 *dst = ram4000.intro_japanese_text_tiles; do { memcpy(dst + (v2 >> 1), (uint16 *)&g_ram[tt[2] + 0x1a000], 16); memcpy(dst + ((v2 + 768) >> 1), (uint16 *)&g_ram[tt[3] + 0x1a000], 16); v2 += 16; tt += 2; - } while (--R18); + } while (--r18); } void TransferJapaneseTextTilesToVram(void) { // 0x8B8DE6 @@ -858,7 +808,7 @@ void HandleSamusDuringIntro(void) { // 0x8B8E0D void DrawIntroSprites(void) { // 0x8B8E2D if (cinematic_var15) { - if ((cinematic_var15 & 0x8000u) != 0) { + if ((cinematic_var15 & 0x8000) != 0) { DrawSamusAndProjectiles(); DrawPlayerExplosions2(); DrawCinematicSpriteObjects_Intro(); @@ -872,29 +822,9 @@ void DrawIntroSprites(void) { // 0x8B8E2D } } -void CalcSinCos(uint16 a, uint16 j) { // 0x8B8E52 - int16 v3; - uint16 v2; - uint16 v4; - - R24_ = a; - R26_ = j; - if (sign16(j - 128)) - v2 = CalcSinMult(2 * j); - else - v2 = -CalcSinMult(2 * (uint8)(j + 0x80)); - R20_ = v2; - v3 = (uint8)(R26_ - 64); - if (sign16(v3 - 128)) - v4 = CalcSinMult(2 * v3); - else - v4 = -CalcSinMult(2 * (uint8)(v3 + 0x80)); - R22_ = v4; -} - -uint16 CalcSinMult(uint16 k) { // 0x8B8EA3 - R18_ = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k), R24_) >> 8; - return R18_ + *((uint8 *)&kSinCosTable8bit_Sext[64] + k + 1) * (uint8)R24_; +uint16 CalcSinMult(uint16 k, uint16 r24) { // 0x8B8EA3 + uint16 r18 = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k), r24) >> 8; + return r18 + *((uint8 *)&kSinCosTable8bit_Sext[64] + k + 1) * (uint8)r24; } static const uint16 kMoveUnusedSpritesMasks[8] = { 0x5555, 0x5554, 0x5550, 0x5540, 0x5500, 0x5400, 0x5000, 0x4000 }; @@ -976,7 +906,7 @@ CoroutineRet InitializeIoDisplayLogo_Async(void) { // 0x8B9146 nmi_copy_samus_halves = 0; nmi_copy_samus_top_half_src = 0; nmi_copy_samus_bottom_half_src = 0; - WriteReg(NMITIMEN, 1u); + WriteReg(NMITIMEN, 1); reg_NMITIMEN = 1; WriteReg(WRIO, 0); WriteReg(WRMPYA, 0); @@ -991,9 +921,9 @@ CoroutineRet InitializeIoDisplayLogo_Async(void) { // 0x8B9146 WriteReg(MDMAEN, 0); WriteReg(HDMAEN, 0); reg_HDMAEN = 0; - WriteReg(MEMSEL, 1u); + WriteReg(MEMSEL, 1); reg_MEMSEL = 1; - WriteReg(OBSEL, 3u); + WriteReg(OBSEL, 3); reg_OBSEL = 3; WriteReg(OAMADDL, 0); LOBYTE(reg_OAMaddr_UNUSED) = 0; @@ -1001,7 +931,7 @@ CoroutineRet InitializeIoDisplayLogo_Async(void) { // 0x8B9146 HIBYTE(reg_OAMaddr_UNUSED) = 0x80; WriteReg(OAMDATA, 0); WriteReg(OAMDATA, 0); - WriteReg(BGMODE, 1u); + WriteReg(BGMODE, 1); reg_BGMODE = 1; WriteReg(MOSAIC, 0); reg_MOSAIC = 0; @@ -1086,7 +1016,7 @@ CoroutineRet InitializeIoDisplayLogo_Async(void) { // 0x8B9146 static const StartDmaCopy unk_8B92B9 = { 1, 1, 0x18, LONGPTR(0x7f5000), 0x4000 }; SetupDmaTransfer(&unk_8B92B9); } - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); reg_INIDISP = 0x80; { uint16 v0 = 0; @@ -1141,10 +1071,7 @@ CoroutineRet InitializeIoDisplayLogo_Async(void) { // 0x8B9146 } void AddNintentoLogoToOam(void) { // 0x8B936B - R22_ = 0; - R20_ = 128; - R18_ = 112; - DrawSpritemap(0x8C, addr_kSpriteMap_NintendoLogo); + DrawSpritemap(0x8C, addr_kSpriteMap_NintendoLogo, 128, 112, 0); } uint8 SpawnCinematicSpriteObject(uint16 j, uint16 a) { // 0x8B938A @@ -1156,83 +1083,9 @@ uint8 SpawnCinematicSpriteObject(uint16 j, uint16 a) { // 0x8B938A return 1; } -uint8 SpawnCinematicSpriteObjectToR18(uint16 j, uint16 a) { // 0x8B93A2 - cinematic_spawn_param = a; - return SpawnCimenaticSpriteObjectInner(j, R18_); -} - -void CallCinematicSpriteObjectSetup(uint32 ea, uint16 j) { - switch (ea) { - case fnCinematicFunction_nullsub_116: return; - case fnCinematicSpriteInit_7: CinematicSpriteInit_7(j); return; - case fnCinematicSpriteInit_8: CinematicSpriteInit_8(j); return; - case fnCinematicSpriteInit_9: CinematicSpriteInit_9(j); return; - case fnCinematicSpriteInit_0: CinematicSpriteInit_0(j); return; - case fnCinematicSpriteInit_1: CinematicSpriteInit_1(j); return; - case fnCinematicSpriteInit_2: CinematicSpriteInit_2(j); return; - case fnCinematicSpriteInit_3: CinematicSpriteInit_3(j); return; - case fnCinematicSpriteInit_4: CinematicSpriteInit_4(j); return; - case fnCinematicSpriteInit_5: CinematicSpriteInit_5(j); return; - case fnCinematicSpriteInit_6: CinematicSpriteInit_6(j); return; - case fnSetSomeStuffForSpriteObject_2: SetSomeStuffForSpriteObject_2(j); return; - case fnSetSomeStuffForSpriteObject_3: SetSomeStuffForSpriteObject_3(j); return; - case fnSetSomeStuffForSpriteObject_6: SetSomeStuffForSpriteObject_6(j); return; - case fnSetSomeStuffForSpriteObject_8: SetSomeStuffForSpriteObject_8(j); return; - case fnSetSomeStuffForSpriteObject_10: SetSomeStuffForSpriteObject_10(j); return; - case fnSetSomeStuffForSpriteObject_12: SetSomeStuffForSpriteObject_12(j); return; - case fnSetSomeStuffForSpriteObject_17: SetSomeStuffForSpriteObject_17(j); return; - case fnCinematicFunction_Intro_Func35: CinematicFunction_Intro_Func35(j); return; - case fnCinematicFunction_Intro_Func42: CinematicFunction_Intro_Func42(j); return; - case fnCinematicFunction_Intro_Func46: CinematicFunction_Intro_Func46(j); return; - case fnCinematicFunction_Intro_Func47: CinematicFunction_Intro_Func47(j); return; - case fnCinematicFunction_Intro_Func49: CinematicFunction_Intro_Func49(j); return; - case fnCinematicFunction_Intro_Func57: CinematicFunction_Intro_Func57(j); return; - case fnCinematicFunction_Intro_Func59: CinematicFunction_Intro_Func59(j); return; - case fnCinematicFunction_Intro_Func61: CinematicFunction_Intro_Func61(j); return; - case fnCinematicFunction_Intro_Func63: CinematicFunction_Intro_Func63(j); return; - case fnCinematicFunction_Intro_Func65: CinematicFunction_Intro_Func65(j); return; - case fnCinematicFunction_Intro_Func68: CinematicFunction_Intro_Func68(j); return; - case fnCinematicFunction_Intro_Func71: CinematicFunction_Intro_Func71(j); return; - case fnCinematicFunction_Intro_Func78: CinematicFunction_Intro_Func78(j); return; - case fnCinematicFunction_Intro_Func80: CinematicFunction_Intro_Func80(j); return; - case fnCinematicFunction_Intro_Func81: CinematicFunction_Intro_Func81(j); return; - case fnCinematicFunction_Intro_Func83: CinematicFunction_Intro_Func83(j); return; - case fnCinematicFunction_Intro_Func89: CinematicFunction_Intro_Func89(j); return; - case fnCinematicFunction_Intro_Func92: CinematicFunction_Intro_Func92(j); return; - case fnCinematicFunction_Intro_Func98: CinematicFunction_Intro_Func98(j); return; - case fnCinematicFunction_Intro_Func99: CinematicFunction_Intro_Func99(j); return; - case fnCinematicFunction_Intro_Func100: CinematicFunction_Intro_Func100(j); return; - case fnCinematicFunction_Intro_Func101: CinematicFunction_Intro_Func101(j); return; - case fnCinematicFunction_Intro_Func102: CinematicFunction_Intro_Func102(j); return; - case fnCinematicFunction_Intro_Func104: CinematicFunction_Intro_Func104(j); return; - case fnCinematicFunction_Intro_Func150: CinematicFunction_Intro_Func150(j); return; - case fnCinematicFunction_Intro_Func152: CinematicFunction_Intro_Func152(j); return; - case fnCinematicFunction_Intro_Func153: CinematicFunction_Intro_Func153(j); return; - case fnCinematicFunction_Intro_Func154: CinematicFunction_Intro_Func154(j); return; - case fnCinematicFunction_Intro_Func155: CinematicFunction_Intro_Func155(j); return; - case fnCinematicFunction_Intro_Func156: CinematicFunction_Intro_Func156(j); return; - case fnCinematicFunction_Intro_Func157: CinematicFunction_Intro_Func157(j); return; - case fnCinematicFunction_Intro_Func159: CinematicFunction_Intro_Func159(j); return; - case fnCinematicFunction_Intro_Func161: CinematicFunction_Intro_Func161(j); return; - case fnCinematicFunction_Intro_Func162: CinematicFunction_Intro_Func162(j); return; - case fnCinematicFunction_Intro_Func163: CinematicFunction_Intro_Func163(j); return; - case fnCinematicFunction_Intro_Func164: CinematicFunction_Intro_Func164(j); return; - case fnCinematicFunction_Intro_Func165: CinematicFunction_Intro_Func165(j); return; - case fnCinematicFunction_Intro_Func166: CinematicFunction_Intro_Func166(j); return; - case fnCinematicFunction_Intro_Func167: CinematicFunction_Intro_Func167(j); return; - case fnCinematicFunction_Intro_Func168: CinematicFunction_Intro_Func168(j); return; - case fnCinematicFunction_Intro_Func169: CinematicFunction_Intro_Func169(j); return; - case fnCinematicFunction_Intro_Func170: CinematicFunction_Intro_Func170(j); return; - case fnCinematicFunction_Intro_Func171: CinematicFunction_Intro_Func171(j); return; - case fnCinematicFunction_Intro_Func172: CinematicFunction_Intro_Func172(j); return; - case fnCinematicFunction_Intro_Func173: CinematicFunction_Intro_Func173(j); return; - case fnCinematicFunction_Intro_Func174: CinematicFunction_Intro_Func174(j); return; - case fnCinematicFunction_Intro_Func175: CinematicFunction_Intro_Func175(j); return; - case fnCinematicFunction_Intro_Func176: CinematicFunction_Intro_Func176(j); return; - case fnCinematicFunction_Intro_Func177: CinematicFunction_Intro_Func177(j); return; - case fnCinematicFunction_Intro_Func178: CinematicFunction_Intro_Func178(j); return; - default: Unreachable(); - } +uint8 SpawnCinematicSpriteObjectToR18(uint16 j, uint16 r18) { // 0x8B93A2 + cinematic_spawn_param = 0; + return SpawnCimenaticSpriteObjectInner(j, r18); } uint8 SpawnCimenaticSpriteObjectInner(uint16 k, uint16 j) { // 0x8B93AC @@ -1267,124 +1120,6 @@ void HandleCinematicSprites(void) { // 0x8B93EF } } -uint16 CallCinematicSprInstr(uint32 ea, uint16 k, uint16 j) { - switch (ea) { - case fnCinematicSprInstr_Delete: return CinematicSprInstr_Delete(k, j); - case fnCinematicSprInstr_Sleep: return CinematicSprInstr_Sleep(k, j); - case fnCinematicSprInstr_SetPreInstr: return CinematicSprInstr_SetPreInstr(k, j); - case fnCinematicSprInstr_ClearPreInstr: return CinematicSprInstr_ClearPreInstr(k, j); - case fnCinematicSprInstr_GotoRel: return CinematicSprInstr_GotoRel(k, j); - case fnCinematicSprInstr_Goto: return CinematicSprInstr_Goto(k, j); - case fnCinematicSprInstr_DecTimerGoto: return CinematicSprInstr_DecTimerGoto(k, j); - case fnCinematicSprInstr_DecTimerGotoRel: return CinematicSprInstr_DecTimerGotoRel(k, j); - case fnCinematicSprInstr_SetTimer: return CinematicSprInstr_SetTimer(k, j); - case fnCinematicSprInstr_9CE1: return CinematicSprInstr_9CE1(k, j); - case fnCinematicSprInstr_9D5D: return CinematicSprInstr_9D5D(k, j); - case fnCinematicSprInstr_9DD6: return CinematicSprInstr_9DD6(k, j); - case fnCinematicSprInstr_Func8: return CinematicSprInstr_Func8(k, j); - case fnCinematicSprInstr_Func9: return CinematicSprInstr_Func9(k, j); - case fnCinematicSprInstr_sub_8B9EF0: return CinematicSprInstr_sub_8B9EF0(k, j); - case fnCinematicSprInstr_9F19: return CinematicSprInstr_9F19(k, j); - case fnCinematicSprInstr_SpawnMetroidEggParticles: return CinematicSprInstr_SpawnMetroidEggParticles(k, j); - case fnCinematicSprInstr_StartIntroPage2: return CinematicSprInstr_StartIntroPage2(k, j); - case fnCinematicSprInstr_StartIntroPage3: return CinematicSprInstr_StartIntroPage3(k, j); - case fnCinematicSprInstr_StartIntroPage4: return CinematicSprInstr_StartIntroPage4(k, j); - case fnCinematicSprInstr_StartIntroPage5: return CinematicSprInstr_StartIntroPage5(k, j); - case fnCinematicSprInstr_Func43: return CinematicSprInstr_Func43(k, j); - case fnCinematicSprInstr_SpawnIntroRinkas01: return CinematicSprInstr_SpawnIntroRinkas01(k, j); - case fnCinematicSprInstr_SpawnIntroRinkas23: return CinematicSprInstr_SpawnIntroRinkas23(k, j); - case fnCinematicCommonInstr_Func69: return CinematicCommonInstr_Func69(k, j); - case fnCinematicCommonInstr_Func70: return CinematicCommonInstr_Func70(k, j); - case fnCinematicSprInstr_SpawnCeresExplosions1: return CinematicSprInstr_SpawnCeresExplosions1(k, j); - case fnCinematicSprInstr_SpawnCeresExplosions3: return CinematicSprInstr_SpawnCeresExplosions3(k, j); - case fnCinematicSprInstr_C9A5: return CinematicSprInstr_C9A5(k, j); - case fnCinematicSprInstr_C9AF: return CinematicSprInstr_C9AF(k, j); - case fnCinematicSprInstr_C9BD: return CinematicSprInstr_C9BD(k, j); - case fnCinematicSprInstr_C9C7: return CinematicSprInstr_C9C7(k, j); - case fnCinematicSprInstr_Func181: return CinematicSprInstr_Func181(k, j); - case fnCinematicSprInstr_Func182: return CinematicSprInstr_Func182(k, j); - case fnCinematicSprInstr_Func183: return CinematicSprInstr_Func183(k, j); - case fnCinematicSprInstr_Func185: return CinematicSprInstr_Func185(k, j); - case fnCinematicSprInstr_Func186: return CinematicSprInstr_Func186(k, j); - case fnCinematicSprInstr_Func187: return CinematicSprInstr_Func187(k, j); - case fnCinematicSprInstr_Func190: return CinematicSprInstr_Func190(k, j); - case fnCinematicSprInstr_Func192: return CinematicSprInstr_Func192(k, j); - case fnCinematicSprInstr_Func193: return CinematicSprInstr_Func193(k, j); - case fnCinematicSprInstr_Func194: return CinematicSprInstr_Func194(k, j); - case fnCinematicSprInstr_Func195: return CinematicSprInstr_Func195(k, j); - case fnCinematicSprInstr_Func196: return CinematicSprInstr_Func196(k, j); - case fnCinematicSprInstr_Func197: return CinematicSprInstr_Func197(k, j); - case fnCinematicSprInstr_Func198: return CinematicSprInstr_Func198(k, j); - case fnCinematicSprInstr_Func208: return CinematicSprInstr_Func208(k, j); - case fnCinematicSprInstr_Func211: return CinematicSprInstr_Func211(k, j); - case fnCinematicSprInstr_Func213: return CinematicSprInstr_Func213(k, j); - case fnCinematicSprInstr_Func214: return CinematicSprInstr_Func214(k, j); - case fnCinematicSprInstr_Func217: return CinematicSprInstr_Func217(k, j); - case fnCinematicSprInstr_Func218: return CinematicSprInstr_Func218(k, j); - default: return Unreachable(); - } -} -void CallCinematicSprPreInstr(uint32 ea, uint16 j) { - switch (ea) { - case fnCinematicSprPreInstr_nullsub_300: return; - case fnCinematicFunction_nullsub_116: return; - case fnCinematicFunction_nullsub_298: return; - case fnsub_8B9CCF: sub_8B9CCF(j); return; - case fnnullsub_122: return; - case fnSetSomeStuffForSpriteObject_4_MetroidEgg: SetSomeStuffForSpriteObject_4_MetroidEgg(j); return; - case fnCinematicSprPreInstr_A903: CinematicSprPreInstr_A903(j); return; - case fnSetSomeStuffForSpriteObject_7: SetSomeStuffForSpriteObject_7(j); return; - case fnSetSomeStuffForSpriteObject_9: SetSomeStuffForSpriteObject_9(j); return; - case fnSetSomeStuffForSpriteObject_11: SetSomeStuffForSpriteObject_11(j); return; - case fnSetSomeStuffForSpriteObject_13: SetSomeStuffForSpriteObject_13(j); return; - case fnSetSomeStuffForSpriteObject_18: SetSomeStuffForSpriteObject_18(j); return; - case fnCinematicFunction_Intro_Func36: CinematicFunction_Intro_Func36(j); return; - case fnCinematicFunction_Intro_Func39: CinematicFunction_Intro_Func39(j); return; - case fnCinematicSprPreInstr_B82E: CinematicSprPreInstr_B82E(j); return; - case fnCinematicFunction_Intro_Func44: CinematicFunction_Intro_Func44(j); return; - case fnCinematicFunction_Intro_Func45: CinematicFunction_Intro_Func45(j); return; - case fnCinematicFunction_Intro_Func48: CinematicFunction_Intro_Func48(j); return; - case fnCinematicFunction_Intro_Func50: CinematicFunction_Intro_Func50(j); return; - case fnCinematicFunction_Intro_Func51: CinematicFunction_Intro_Func51(j); return; - case fnCinematicFunction_Intro_Func52: CinematicFunction_Intro_Func52(j); return; - case fnCinematicFunction_Intro_Func53: CinematicFunction_Intro_Func53(j); return; - case fnCinematicFunction_Intro_Func58: CinematicFunction_Intro_Func58(j); return; - case fnCinematicFunction_Intro_Func60: CinematicFunction_Intro_Func60(j); return; - case fnCinematicFunction_Intro_Func62: CinematicFunction_Intro_Func62(j); return; - case fnCinematicFunction_Intro_Func64: CinematicFunction_Intro_Func64(j); return; - case fnCinematicFunction_Intro_Func66: CinematicFunction_Intro_Func66(j); return; - case fnCinematicSprPreInstr_C489: CinematicSprPreInstr_C489(j); return; - case fnCinematicFunction_Intro_Func82: CinematicFunction_Intro_Func82(j); return; - case fnCinematicFunction_Intro_Func90: CinematicFunction_Intro_Func90(j); return; - case fnCinematicFunction_Intro_Func91: CinematicFunction_Intro_Func91(j); return; - case fnCinematicFunction_Intro_Func93: CinematicFunction_Intro_Func93(j); return; - case fnCinematicFunction_Intro_Func94: CinematicFunction_Intro_Func94(j); return; - case fnCinematicFunction_Intro_Func96: CinematicFunction_Intro_Func96(j); return; - case fnCinematicFunction_Intro_Func97: CinematicFunction_Intro_Func97(j); return; - case fnCinematicFunction_Intro_Func151: CinematicFunction_Intro_Func151(j); return; - case fnCinematicFunction_Intro_Func179: CinematicFunction_Intro_Func179(j); return; - case fnCinematicFunction_Intro_Func180: CinematicFunction_Intro_Func180(j); return; - case fnCinematicFunction_Intro_Func184: CinematicFunction_Intro_Func184(j); return; - case fnCinematicSprPreInstr_F35A: CinematicSprPreInstr_F35A(j); return; - case fnCinematicFunction_Intro_Func189: CinematicFunction_Intro_Func189(j); return; - case fnCinematicFunction_Intro_Func189b: CinematicFunction_Intro_Func189b(j); return; - case fnCinematicFunction_Intro_Func191: CinematicFunction_Intro_Func191(j); return; - case fnCinematicFunction_Intro_Func199: CinematicFunction_Intro_Func199(j); return; - case fnCinematicFunction_Intro_Func200: CinematicFunction_Intro_Func200(j); return; - case fnCinematicFunction_Intro_Func201: CinematicFunction_Intro_Func201(j); return; - case fnCinematicFunction_Intro_Func202: CinematicFunction_Intro_Func202(j); return; - case fnCinematicFunction_Intro_Func203: CinematicFunction_Intro_Func203(j); return; - case fnCinematicFunction_Intro_Func204: CinematicFunction_Intro_Func204(j); return; - case fnCinematicFunction_Intro_Func205: CinematicFunction_Intro_Func205(j); return; - case fnCinematicFunction_Intro_Func206: CinematicFunction_Intro_Func206(j); return; - case fnCinematicFunction_Intro_Func207: CinematicFunction_Intro_Func207(j); return; - case fnnullsub_128: return; - case fnCinematicSprPreInstr_F528: CinematicSprPreInstr_F528(j); return; - case fnCinematicSprPreInstr_F57F: CinematicSprPreInstr_F57F(j); return; - case fnCinematicFunction_Intro_Func215: CinematicFunction_Intro_Func215(j); return; - default: Unreachable(); - } -} void ProcessCinematicSpriteInstructionList(uint16 k) { // 0x8B9409 CallCinematicSprPreInstr(cinematicspr_preinstr_func[k >> 1] | 0x8B0000, k); uint16 v1 = cinematic_obj_index; @@ -1394,9 +1129,8 @@ void ProcessCinematicSpriteInstructionList(uint16 k) { // 0x8B9409 while (1) { const uint16 *v5 = (const uint16 *)RomPtr_8B(v4); v6 = *v5; - if ((*v5 & 0x8000u) == 0) + if ((*v5 & 0x8000) == 0) break; - R18_ = *v5; v4 = CallCinematicSprInstr(v6 | 0x8B0000, v1, v4 + 2); if (!v4) return; @@ -1432,7 +1166,6 @@ uint16 CinematicSprInstr_ClearPreInstr(uint16 k, uint16 j) { // 0x8B9457 uint16 CinematicSprInstr_GotoRel(uint16 k, uint16 j) { // 0x8B94A2 - R18_ = j; return j + (int8)*RomPtr_8B(j); } @@ -1465,23 +1198,6 @@ void sub_8B94E1(void) { // 0x8B94E1 ; } -void CallCinematicSpriteInit(uint32 ea, uint16 j) { - switch (ea) { - case fnCinematicSpriteInit_7: CinematicSpriteInit_7(j); return; - case fnCinematicSpriteInit_8: CinematicSpriteInit_8(j); return; - case fnCinematicSpriteInit_9: CinematicSpriteInit_9(j); return; - case fnCinematicSpriteInit_0: CinematicSpriteInit_0(j); return; - case fnCinematicSpriteInit_1: CinematicSpriteInit_1(j); return; - case fnCinematicSpriteInit_2: CinematicSpriteInit_2(j); return; - case fnCinematicSpriteInit_3: CinematicSpriteInit_3(j); return; - case fnCinematicSpriteInit_4: CinematicSpriteInit_4(j); return; - case fnCinematicSpriteInit_5: CinematicSpriteInit_5(j); return; - case fnCinematicSpriteInit_6: CinematicSpriteInit_6(j); return; - case fnCinematicFunction_nullsub_116: return; - default: Unreachable(); - } -} - uint8 SpawnMode7Object(uint16 j, uint16 a) { // 0x8B94E4 Mode7ObjectDef *Mode7ObjectDef; @@ -1489,7 +1205,7 @@ uint8 SpawnMode7Object(uint16 j, uint16 a) { // 0x8B94E4 uint16 v3 = 2; while (mode7_obj_instr_ptr[v3 >> 1]) { v3 -= 2; - if ((v3 & 0x8000u) != 0) + if ((v3 & 0x8000) != 0) return 1; } Mode7ObjectDef = get_Mode7ObjectDef(j); @@ -1511,48 +1227,6 @@ void HandleMode7Objects(void) { // 0x8B951D } } } -uint16 CallMode7Instr(uint32 ea, uint16 k, uint16 j) { - switch (ea) { - case fnMode7Instr_Delete: return Mode7Instr_Delete(k, j); - case fnMode7Instr_SetPreInstr: return Mode7Instr_SetPreInstr(k, j); - case fnMode7Instr_ClearPreInstr: return Mode7Instr_ClearPreInstr(k, j); - case fnMode7Instr_Goto: return Mode7Instr_Goto(k, j); - case fnMode7Instr_DecTimerAndGoto: return Mode7Instr_DecTimerAndGoto(k, j); - case fnMode7Instr_SetTimer: return Mode7Instr_SetTimer(k, j); - case fnPlayBabyMetroidCry1: return PlayBabyMetroidCry1(k, j); - case fnPlayBabyMetroidCry2: return PlayBabyMetroidCry2(k, j); - case fnPlayBabyMetroidCry3: return PlayBabyMetroidCry3(k, j); - case fnCinematicSetPal1: return CinematicSetPal1(k, j); - case fnCinematicSetPal2: return CinematicSetPal2(k, j); - case fnCinematicSetPal3: return CinematicSetPal3(k, j); - case fnCinematicSetPal4: return CinematicSetPal4(k, j); - case fnsub_8BB51E: return sub_8BB51E(k, j); - case fnEnableCinematicBgTilemapUpdates__0: return EnableCinematicBgTilemapUpdates__0(k, j); - case fnCinematicFunction_Intro_Func21: return CinematicFunction_Intro_Func21(k, j); - case fnCinematicFunction_Intro_ThenWaitInputSetupBabyMetroid: return CinematicFunction_Intro_ThenWaitInputSetupBabyMetroid(k, j); - case fnCinematicFunction_Intro_Func23: return CinematicFunction_Intro_Func23(k, j); - case fnCinematicFunction_Intro_Func25: return CinematicFunction_Intro_Func25(k, j); - case fnCinematicFunction_Intro_Func26: return CinematicFunction_Intro_Func26(k, j); - case fnCinematicFunction_Intro_Func28: return CinematicFunction_Intro_Func28(k, j); - case fnCinematicFunction_Intro_Func29: return CinematicFunction_Intro_Func29(k, j); - case fnCinematicFunction_Intro_Func31: return CinematicFunction_Intro_Func31(k, j); - case fnCinematicFunction_Intro_Func32: return CinematicFunction_Intro_Func32(k, j); - case fnEnableCinematicBgTilemapUpdates__: return EnableCinematicBgTilemapUpdates__(k, j); - default: return Unreachable(); - } -} - - -void CallMode7PreInstr(uint32 ea, uint16 k) { - switch (ea) { - case fnCinematicFunction_nullsub_116: return; - case fnCinematicFunction_Intro_Func22: CinematicFunction_Intro_Func22(k); return; - case fnCinematicFunction_Intro_Func24: CinematicFunction_Intro_Func24(k); return; - case fnCinematicFunction_Intro_Func27: CinematicFunction_Intro_Func27(k); return; - case fnCinematicFunction_Intro_Func30: CinematicFunction_Intro_Func30(k); return; - default: Unreachable(); - } -} void ProcessMode7ObjectInstructions(uint16 k) { // 0x8B9537 CallMode7PreInstr(mode7_obj_preinstr_func[k >> 1] | 0x8B0000, k); @@ -1563,9 +1237,8 @@ void ProcessMode7ObjectInstructions(uint16 k) { // 0x8B9537 while (1) { const uint16 *v5 = (const uint16 *)RomPtr_8B(v4); v6 = *v5; - if ((*v5 & 0x8000u) == 0) + if ((*v5 & 0x8000) == 0) break; - R18_ = *v5; v4 = CallMode7Instr(v6 | 0x8B0000, v1, v4 + 2); if (!v4) return; @@ -1610,19 +1283,19 @@ uint16 Mode7Instr_SetTimer(uint16 k, uint16 j) { // 0x8B9597 } void EnableCinematicBgObjects(void) { // 0x8B95A2 - cinematic_enable_objs |= 0x8000u; + cinematic_enable_objs |= 0x8000; } void DisableCinematicBgObjects(void) { // 0x8B95AD - cinematic_enable_objs &= ~0x8000u; + cinematic_enable_objs &= ~0x8000; } void EnableCinematicBgTilemapUpdates(void) { // 0x8B95B8 - cinematic_enable_bg_tilemap |= 0x8000u; + cinematic_enable_bg_tilemap |= 0x8000; } void DisableCinematicBgTilemapUpdates(void) { // 0x8B95C3 - cinematic_enable_bg_tilemap &= ~0x8000u; + cinematic_enable_bg_tilemap &= ~0x8000; } void ClearCinematicBgObjects(uint16 a) { // 0x8B95CE @@ -1630,7 +1303,7 @@ void ClearCinematicBgObjects(uint16 a) { // 0x8B95CE for (int i = 2046; i >= 0; i -= 2) *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + (uint16)i) = a; - for (j = 6; (j & 0x8000u) == 0; j -= 2) { + for (j = 6; (j & 0x8000) == 0; j -= 2) { int v3 = j >> 1; cinematicbg_arr1[v3] = 0; cinematicbg_instr_ptr[v3] = 0; @@ -1650,7 +1323,7 @@ uint8 SpawnCinematicBgObject(uint16 j, uint16 a) { // 0x8B95F0 uint16 v3 = 6; while (cinematicbg_instr_ptr[v3 >> 1]) { v3 -= 2; - if ((v3 & 0x8000u) != 0) + if ((v3 & 0x8000) != 0) return 1; } const uint8 *v5 = RomPtr_8B(j); @@ -1665,7 +1338,7 @@ uint8 SpawnCinematicBgObject(uint16 j, uint16 a) { // 0x8B95F0 } void HandleCinematicBgObjects(void) { // 0x8B962F - if ((cinematic_enable_objs & 0x8000u) != 0) { + if ((cinematic_enable_objs & 0x8000) != 0) { for (int i = 6; i >= 0; i -= 2) { cinematicbg_var2 = i; if (cinematicbg_instr_ptr[i >> 1]) { @@ -1673,47 +1346,12 @@ void HandleCinematicBgObjects(void) { // 0x8B962F i = cinematicbg_var2; } } - if ((cinematic_enable_bg_tilemap & 0x8000u) != 0) + if ((cinematic_enable_bg_tilemap & 0x8000) != 0) UpdateCinematicBgTilemap(); UpdateSamusEyesTilemap(); } } -void CallCinematicBgPreInstr(uint32 ea, uint16 j) { - switch (ea) { - case fnCinematicFunction_nullsub_116: return; - case fnCinematicBgPreInstr_SamusBlink: CinematicBgPreInstr_SamusBlink(j); return; - default: Unreachable(); - } -} - -uint16 CallCinematicBgInstr(uint32 ea, uint16 k, uint16 j) { - switch (ea) { - case fnCinematicBgInstr_Delete: return CinematicBgInstr_Delete(k, j); - case fnCinematicBgInstr_Goto: return CinematicBgInstr_Goto(k, j); - case fnCinematicBgInstr_SetSomeStuffForSpriteObject_14: return CinematicBgInstr_SetSomeStuffForSpriteObject_14(k, j); - case fnCinematicBgInstr_HandleCreateJpnText_Page1: return CinematicBgInstr_HandleCreateJpnText_Page1(k, j); - case fnCinematicBgInstr_SpawnMarkerWaitInput_Page1: return CinematicBgInstr_SpawnMarkerWaitInput_Page1(k, j); - case fnCinematicBgInstr_HandleCreateJpnText_Page2: return CinematicBgInstr_HandleCreateJpnText_Page2(k, j); - case fnCinematicBgInstr_SpawnMarkerWaitInput_Page2: return CinematicBgInstr_SpawnMarkerWaitInput_Page2(k, j); - case fnCinematicBgInstr_HandleCreateJpnText_Page3: return CinematicBgInstr_HandleCreateJpnText_Page3(k, j); - case fnCinematicBgInstr_SpawnMarkerWaitInput_Page3: return CinematicBgInstr_SpawnMarkerWaitInput_Page3(k, j); - case fnCinematicBgInstr_HandleCreateJpnText_Page4: return CinematicBgInstr_HandleCreateJpnText_Page4(k, j); - case fnCinematicBgInstr_SpawnMarkerWaitInput_Page4: return CinematicBgInstr_SpawnMarkerWaitInput_Page4(k, j); - case fnCinematicBgInstr_HandleCreateJpnText_Page5: return CinematicBgInstr_HandleCreateJpnText_Page5(k, j); - case fnCinematicBgInstr_SpawnMarkerWaitInput_Page5: return CinematicBgInstr_SpawnMarkerWaitInput_Page5(k, j); - case fnCinematicBgInstr_Func16: return CinematicBgInstr_Func16(k, j); - case fnCinematicBgInstr_Func17: return CinematicBgInstr_Func17(k, j); - case fnCinematicCommonInstr_Func69: return CinematicCommonInstr_Func69(k, j); - case fnCinematicCommonInstr_Func70: return CinematicCommonInstr_Func70(k, j); - case fnCalcItemPercentageCount: return CalcItemPercentageCount(k, j); - case fnCinematicFunction_Intro_Func146: return CinematicFunction_Intro_Func146(k, j); - case fnCinematicFunction_Intro_Func147: return CinematicFunction_Intro_Func147(k, j); - - default: return Unreachable(); - } -} - void ProcessCinematicBgObjectsInstrs(uint16 k) { // 0x8B9659 CallCinematicBgPreInstr(cinematicbg_preinstr[k >> 1] | 0x8B0000, k); uint16 v1 = cinematicbg_var2; @@ -1723,9 +1361,8 @@ void ProcessCinematicBgObjectsInstrs(uint16 k) { // 0x8B9659 while (1) { const uint16 *v5 = (const uint16 *)RomPtr_8C(v4); v6 = *v5; - if ((*v5 & 0x8000u) == 0) + if ((*v5 & 0x8000) == 0) break; - R18_ = *v5; v4 = CallCinematicBgInstr(v6 | 0x8B0000, v1, v4 + 2); if (!v4) return; @@ -1733,9 +1370,8 @@ void ProcessCinematicBgObjectsInstrs(uint16 k) { // 0x8B9659 int v7 = v1 >> 1; cinematicbg_instr_timer[v7] = v6; const uint8 *v8 = RomPtr_8C(v4); - R18_ = GET_WORD(v8 + 2); cinematicbg_arr1[v7] = GET_WORD(v8 + 4); - ProcessCinematicBgObject(v1); + ProcessCinematicBgObject(v1, GET_WORD(v8 + 2)); cinematicbg_instr_ptr[v7] = v4 + 6; } } @@ -1760,15 +1396,14 @@ void DrawCinematicSpriteObjects_Intro(void) { // 0x8B9746 int v1 = i >> 1; if (cinematicspr_whattodraw[v1]) { uint16 v2 = cinematicspr_whattodraw[v1]; - R22_ = cinematicbg_arr9[v1]; - R20_ = cinematicbg_arr7[v1] - layer1_x_pos; - uint16 v3 = cinematicbg_arr8[v1] - layer1_y_pos; - R18_ = v3; - if ((v3 & 0xFF00) != 0) { - if ((uint16)(v3 + 128) < 0x1FFu) - DrawSpritemapOffScreen(v2); - } else if ((uint16)(v3 + 128) < 0x1FFu) { - DrawSpritemap(0x8C, v2); + uint16 chr = cinematicbg_arr9[v1]; + uint16 x = cinematicbg_arr7[v1] - layer1_x_pos; + uint16 y = cinematicbg_arr8[v1] - layer1_y_pos; + if ((y & 0xFF00) != 0) { + if ((uint16)(y + 128) < 0x1FF) + DrawSpritemapOffScreen(v2, x, y, chr); + } else if ((uint16)(y + 128) < 0x1FF) { + DrawSpritemap(0x8C, v2, x, y, chr); } } } @@ -1779,15 +1414,14 @@ void DrawCinematicSpriteObjects_Ending(void) { // 0x8B9799 int v1 = i >> 1; if (cinematicspr_whattodraw[v1]) { uint16 v2 = cinematicspr_whattodraw[v1]; - R22_ = cinematicbg_arr9[v1]; - R20_ = cinematicbg_arr7[v1] - layer1_x_pos; - uint16 v3 = cinematicbg_arr8[v1] - layer1_y_pos; - R18_ = v3; - if ((v3 & 0xFF00) != 0) { - if ((uint16)(v3 + 128) < 0x1FFu) - DrawSpritemapOffScreen(v2); - } else if ((uint16)(v3 + 128) < 0x1FFu) { - DrawSpritemap(0x8C, v2); + uint16 chr = cinematicbg_arr9[v1]; + uint16 x = cinematicbg_arr7[v1] - layer1_x_pos; + uint16 y = cinematicbg_arr8[v1] - layer1_y_pos; + if ((y & 0xFF00) != 0) { + if ((uint16)(y + 128) < 0x1FF) + DrawSpritemapOffScreen(v2, x, y, chr); + } else if ((uint16)(y + 128) < 0x1FF) { + DrawSpritemap(0x8C, v2, x, y, chr); } } } @@ -1795,18 +1429,18 @@ void DrawCinematicSpriteObjects_Ending(void) { // 0x8B9799 MoveUnusedSpritesOffScreen(); } -void SpawnTextGlowObject(uint16 j) { // 0x8B97F7 +void SpawnTextGlowObject(uint16 j, uint16 r18) { // 0x8B97F7 uint16 v1 = 14; while (*(uint16 *)((uint8 *)&cinematic_var21 + v1)) { v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) return; } *(uint16 *)((uint8 *)&cinematic_var21 + v1) = j; int v2 = v1 >> 1; enemy_projectile_pre_instr[v2 + 2] = 1; - enemy_projectile_pre_instr[v2 + 10] = (uint8)R18_; - *(uint16 *)((uint8 *)enemy_projectile_1A27 + v1) = HIBYTE(R18_); + enemy_projectile_pre_instr[v2 + 10] = (uint8)r18; + *(uint16 *)((uint8 *)enemy_projectile_x_subpos + v1) = HIBYTE(r18); *(uint16 *)((uint8 *)&cinematic_var20 + v1) = 0; } @@ -1824,28 +1458,26 @@ void ProcessTextGlowObject(void) { // 0x8B9849 uint16 v0 = cinematic_var19; int v1 = cinematic_var19 >> 1; if (enemy_projectile_pre_instr[v1 + 2]-- == 1) { - R28_ = *(uint16 *)((uint8 *)&cinematic_var20 + v0); + uint16 R28 = *(uint16 *)((uint8 *)&cinematic_var20 + v0); uint16 v3 = *(uint16 *)((uint8 *)&cinematic_var21 + v0); - R20_ = 2 * LOBYTE(enemy_projectile_pre_instr[v1 + 10]); - R22_ = R20_ + Mult8x8(*((uint8 *)enemy_projectile_1A27 + v0), 0x40); - uint16 v4 = R22_; + uint16 r22 = 2 * LOBYTE(enemy_projectile_pre_instr[v1 + 10]) + Mult8x8(*((uint8 *)enemy_projectile_x_subpos + v0), 0x40); + uint16 v4 = r22; const uint8 *v5 = RomPtr_8C(v3); - R18_ = v5[2]; - R24_ = R18_; - R20_ = v5[3]; + int n = v5[2]; + int norg = n; + int m = v5[3]; while (1) { do { - *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + v4) = R28_ | *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap - + v4) & 0xE3FF; + *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + v4) = + R28 | *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + v4) & 0xE3FF; v3 += 2; v4 += 2; - --R18_; - } while (R18_); - R18_ = R24_; - if (!--R20_) + } while (--n); + n = norg; + if (!--m) break; - R22_ += 64; - v4 = R22_; + r22 += 64; + v4 = r22; } uint16 v6 = cinematic_var19; if (*(uint16 *)((uint8 *)&cinematic_var20 + cinematic_var19) == 3072) { @@ -1858,11 +1490,11 @@ void ProcessTextGlowObject(void) { // 0x8B9849 } void EnableTextGlowObjects_(void) { - cinematic_var25 |= 0x8000u; + cinematic_var25 |= 0x8000; } void DisableTextGlowObjects_(void) { - cinematic_var25 &= ~0x8000u; + cinematic_var25 &= ~0x8000; } void CinematicFunction_Intro_Func128(uint16 a) { // 0x8B98F9 @@ -1881,14 +1513,6 @@ void CinematicFunction_Intro_Func128(uint16 a) { // 0x8B98F9 cinematic_var10 = 0; } -void CallCreditsObjectFunc(uint32 ea, uint16 k) { - switch (ea) { - case fnCinematicFunction_nullsub_116: return; - case fnCinematicBgPreInstr_SamusBlink: CinematicBgPreInstr_SamusBlink(k); return; - default: Unreachable(); - } -} - void CreditsObject_Init(uint16 j) { // 0x8B9932 const uint8 *v1 = RomPtr_8B(j); cinematic_var24 = GET_WORD(v1 + 2); @@ -1899,24 +1523,13 @@ void CreditsObject_Init(uint16 j) { // 0x8B9932 } void CreditsObject_Process(void) { // 0x8B9955 - if ((cinematic_var25 & 0x8000u) != 0) { + if ((cinematic_var25 & 0x8000) != 0) { if (cinematic_var21) CreditsObject_ProcessOne(); CinematicUpdateSomeBg(); } } -uint16 CallIntroObjectInstr(uint32 ea, uint16 k, uint16 j) { - switch (ea) { - case fnIntroObject_Delete: return IntroObject_Delete(k, j); - case fnIntroObject_Goto: return IntroObject_Goto(k, j); - case fnIntroObject_DecTimerGoto: return IntroObject_DecTimerGoto(k, j); - case fnIntroObject_SetTimer: return IntroObject_SetTimer(k, j); - case fnCinematicFunction_Intro_Func219: return CinematicFunction_Intro_Func219(k, j); - default: return Unreachable(); - } -} - void CreditsObject_ProcessOne(void) { // 0x8B996A int i; @@ -1929,31 +1542,26 @@ void CreditsObject_ProcessOne(void) { // 0x8B996A for (i = cinematic_var21; ; ) { const uint16 *v2 = (const uint16 *)RomPtr_8C(i); uint16 v3 = *v2; - if ((*v2 & 0x8000u) == 0) + if ((*v2 & 0x8000) == 0) break; - R18_ = *v2; i = CallIntroObjectInstr(v3 | 0x8B0000, 0, i + 2); if (!i) return; } CreditsObject_Func1(i); - cinematic_var26 = ((uint8)cinematic_var26 + 1) & 0x1F; + cinematic_var26 = (cinematic_var26 + 1) & 0x1F; cinematic_var21 = i + 4; } } void CreditsObject_Func1(uint16 j) { // 0x8B99C1 - *(VoidP *)((uint8 *)&R0_.addr + 1) = 32512; - R0_.addr = 0; uint16 RegWord = Mult8x8(cinematic_var26, 0x40); - R20_ = 31; - uint16 v2 = *((uint16 *)RomPtr_8C(j) + 1); + int n = 31; + const uint16 *src = (const uint16*)(g_ram + 0x10000 + *((uint16 *)RomPtr_8C(j) + 1)); do { - *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + RegWord) = IndirReadWord(R0_, v2); + *(uint16 *)((uint8 *)ram3000.pause_menu_map_tilemap + RegWord) = *src++; RegWord += 2; - v2 += 2; - --R20_; - } while ((R20_ & 0x8000u) == 0); + } while (--n >= 0); } uint16 IntroObject_Delete(uint16 k, uint16 j) { // 0x8B99FE @@ -1977,109 +1585,6 @@ uint16 IntroObject_SetTimer(uint16 k, uint16 j) { // 0x8B9A17 return j + 2; } -void CallCinematicFunction(uint32 ea) { - switch (ea) { - case fnCinematicFunctionNone: CinematicFunctionNone(); return; - case fnCinematicFunctionOpening: CinematicFunctionOpening(); return; - case fnCinematicFunc_Func2: CinematicFunc_Func2(); return; - case fnCinematicFunc_Func4: CinematicFunc_Func4(); return; - case fnCinematicFunc_Func5: CinematicFunc_Func5(); return; - case fnCinematicFunc_Func7: CinematicFunc_Func7(); return; - case fnnullsub_117: return; - case fnCinematicFunc_Func1: CinematicFunc_Func1(); return; - case fnCinematicFunc_Func10: CinematicFunc_Func10(); return; - case fnCinematicFunc_Func9: CinematicFunc_Func9(); return; - case fnnullsub_120: return; - case fnnullsub_121: return; - case fnCinematicFunc_Nothing: CinematicFunc_Nothing(); return; - case fnCinematicFunction_Intro_Initial: CinematicFunction_Intro_Initial(); return; - case fnCinematicFunction_Intro_FadeIn: CinematicFunction_Intro_FadeIn(); return; - case fnCinematicFunction_Intro_DrawInitJpn: CinematicFunction_Intro_DrawInitJpn(); return; - case fnCinematicFunction_Intro_LastMetroidCaptivity: CinematicFunction_Intro_LastMetroidCaptivity(); return; - case fnCinematicFunc_Intro_QueueGalaxyIsAtPeace: CinematicFunc_Intro_QueueGalaxyIsAtPeace(); return; - case fnCinematicFunc_Intro_WaitForQueueWait4secs: CinematicFunc_Intro_WaitForQueueWait4secs(); return; - case fnCinematicFunc_Intro_FadeOut: CinematicFunc_Intro_FadeOut(); return; - case fnCinematicFunc_Intro_WaitForFadeOut: CinematicFunc_Intro_WaitForFadeOut(); return; - case fnCinematicFunc_Intro_SetupTextPage2: CinematicFunc_Intro_SetupTextPage2(); return; - case fnCinematicFunc_Intro_WaitFadeinShowText: CinematicFunc_Intro_WaitFadeinShowText(); return; - case fnCinematicFunc_Intro_WaitForFadeinSleep: CinematicFunc_Intro_WaitForFadeinSleep(); return; - case fnCinematicFunction_Intro_WaitInputSetupMotherBrainFight: CinematicFunction_Intro_WaitInputSetupMotherBrainFight(); return; - case fnCinematicFunction_Intro_WaitInputSetupBabyMetroid: CinematicFunction_Intro_WaitInputSetupBabyMetroid(); return; - case fnCinematicFunction_Intro_Func11: CinematicFunction_Intro_Func11(); return; - case fnCinematicFunction_Intro_Func12: CinematicFunction_Intro_Func12(); return; - case fnCinematicFunction_Intro_Func15: CinematicFunction_Intro_Func15(); return; - case fnCinematicFunction_Intro_Func15b: CinematicFunction_Intro_Func15b(); return; - case fnCinematicFunction_Intro_XfadeGameplayFade: CinematicFunction_Intro_XfadeGameplayFade(); return; - case fnCinematicFunction_Intro_XfadeScientistFade: CinematicFunction_Intro_XfadeScientistFade(); return; - case fnCinematicFunction_Intro_Page2: CinematicFunction_Intro_Page2(); return; - case fnCinematicFunction_Intro_Page3: CinematicFunction_Intro_Page3(); return; - case fnCinematicFunction_Intro_Page4: CinematicFunction_Intro_Page4(); return; - case fnCinematicFunction_Intro_Page5: CinematicFunction_Intro_Page5(); return; - case fnCinematicFunction_Intro_Fadestuff: CinematicFunction_Intro_Fadestuff(); return; - case fnCinematicFunction_Intro_Fadestuff2: CinematicFunction_Intro_Fadestuff2(); return; - case fnCinematicFunction_Intro_Func34: CinematicFunction_Intro_Func34(); return; - case fnCinematicFunction_Intro_Func54: CinematicFunction_Intro_Func54(); return; - case fnCinematicFunction_Intro_Func55: CinematicFunction_Intro_Func55(); return; - case fnCinematicFunction_Intro_Func56: CinematicFunction_Intro_Func56(); return; - case fnCinematicFunction_Intro_Func67: CinematicFunction_Intro_Func67(); return; - case fnCinematicFunction_Intro_Func72: CinematicFunction_Intro_Func72(); return; - case fnCinematicFunction_Intro_Func73: CinematicFunction_Intro_Func73(); return; - case fnCinematicFunctionBlackoutFromCeres: CinematicFunctionBlackoutFromCeres(); return; - case fnCinematicFunction_Intro_Func74: CinematicFunction_Intro_Func74(); return; - case fnCinematicFunction_Intro_Func75: CinematicFunction_Intro_Func75(); return; - case fnCinematicFunction_Intro_Func76: CinematicFunction_Intro_Func76(); return; - case fnCinematicFunction_Intro_Func77: CinematicFunction_Intro_Func77(); return; - case fnCinematicFunction_Intro_Func84: CinematicFunction_Intro_Func84(); return; - case fnCinematicFunction_Intro_Func85: CinematicFunction_Intro_Func85(); return; - case fnCinematicFunction_Intro_Func86: CinematicFunction_Intro_Func86(); return; - case fnCinematicFunction_Intro_Func87: CinematicFunction_Intro_Func87(); return; - case fnCinematicFunction_Intro_Func88: CinematicFunction_Intro_Func88(); return; - case fnCinematicFunction_Intro_Func105: CinematicFunction_Intro_Func105(); return; - case fnCinematicFunction_Intro_Func106: CinematicFunction_Intro_Func106(); return; - case fnCinematicFunction_Intro_Func107: CinematicFunction_Intro_Func107(); return; - case fnCinematicFunction_Intro_Func108: CinematicFunction_Intro_Func108(); return; - case fnnullsub_124: return; - case fnCinematicFunction_Intro_Func95: CinematicFunction_Intro_Func95(); return; - case fnCinematicFunctionEscapeFromCebes: CinematicFunctionEscapeFromCebes(); return; - case fnCinematicFunction_Intro_Func109: CinematicFunction_Intro_Func109(); return; - case fnCinematicFunction_Intro_Func110: CinematicFunction_Intro_Func110(); return; - case fnCinematicFunction_Intro_Func111: CinematicFunction_Intro_Func111(); return; - case fnCinematicFunction_Intro_Func112: CinematicFunction_Intro_Func112(); return; - case fnCinematicFunction_Intro_Func113: CinematicFunction_Intro_Func113(); return; - case fnCinematicFunction_Intro_Func114: CinematicFunction_Intro_Func114(); return; - case fnCinematicFunction_Intro_Func115: CinematicFunction_Intro_Func115(); return; - case fnCinematicFunction_Intro_Func116: CinematicFunction_Intro_Func116(); return; - case fnCinematicFunction_Intro_Func117: CinematicFunction_Intro_Func117(); return; - case fnCinematicFunction_Intro_Func118: CinematicFunction_Intro_Func118(); return; - case fnnullsub_125: return; - case fnCinematicFunction_Intro_Func119: CinematicFunction_Intro_Func119(); return; - case fnCinematicFunction_Intro_Func120: CinematicFunction_Intro_Func120(); return; - case fnCinematicFunction_Intro_Func121: CinematicFunction_Intro_Func121(); return; - case fnCinematicFunction_Intro_Func123: CinematicFunction_Intro_Func123(); return; - case fnCinematicFunction_Intro_Func124: CinematicFunction_Intro_Func124(); return; - case fnnullsub_126: return; - case fnCinematicFunction_Intro_Func125: CinematicFunction_Intro_Func125(); return; - case fnCinematicFunction_Intro_Func126: CinematicFunction_Intro_Func126(); return; - case fnCinematicFunction_Intro_Func129: CinematicFunction_Intro_Func129(); return; - case fnCinematicFunction_Intro_Func130: CinematicFunction_Intro_Func130(); return; - case fnCinematicFunction_Intro_Func131: CinematicFunction_Intro_Func131(); return; - case fnCinematicFunction_Intro_Func132: CinematicFunction_Intro_Func132(); return; - case fnCinematicFunction_Intro_Func134: CinematicFunction_Intro_Func134(); return; - case fnCinematicFunction_Intro_Func136: CinematicFunction_Intro_Func136(); return; - case fnCinematicFunction_Intro_Func135: CinematicFunction_Intro_Func135(); return; - case fnCinematicFunction_Intro_Func137: CinematicFunction_Intro_Func137(); return; - case fnCinematicFunction_Intro_Func138: CinematicFunction_Intro_Func138(); return; - case fnCinematicFunction_Intro_Func145: CinematicFunction_Intro_Func145(); return; - case fnCinematicFunction_Intro_Func139: CinematicFunction_Intro_Func139(); return; - case fnCinematicFunction_Intro_Func141: CinematicFunction_Intro_Func141(); return; - case fnCinematicFunction_Intro_Func143: CinematicFunction_Intro_Func143(); return; - case fnCinematicFunction_Intro_Func144: CinematicFunction_Intro_Func144(); return; - case fnCinematicFunction_Intro_Func148: CinematicFunction_Intro_Func148(); return; - case fnnullsub_127: return; - default: Unreachable(); - } -} - CoroutineRet GameState_1_OpeningCinematic_(void) { // 0x8B9A22 CallCinematicFunction(cinematic_function | 0x8b0000); HandleCinematicSprites(); @@ -2106,23 +1611,11 @@ void MaybeSkipCinematics(void) { // 0x8B9A48 } } -static Func_V *const off_8B9A7B[4] = { // 0x8B9A6C - 0, - HandleCinematicsTransitions_1, - HandleCinematicsTransitions_2, - HandleCinematicsTransitions_3, -}; - -void HandleCinematicsTransitions(void) { - if (cinematic_var18) - off_8B9A7B[cinematic_var18](); -} - void HandleCinematicsTransitions_1(void) { // 0x8B9A83 if (AdvanceFastScreenFadeOut() & 1) { cinematic_var18 = 2; cinematic_function = FUNC16(nullsub_117); - QueueMusic_Delayed8(6u); + QueueMusic_Delayed8(6); } } @@ -2186,12 +1679,24 @@ void HandleCinematicsTransitions_3(void) { // 0x8B9B53 } } +static Func_V *const off_8B9A7B[4] = { // 0x8B9A6C + 0, + HandleCinematicsTransitions_1, + HandleCinematicsTransitions_2, + HandleCinematicsTransitions_3, +}; + +void HandleCinematicsTransitions(void) { + if (cinematic_var18) + off_8B9A7B[cinematic_var18](); +} + void CinematicFunctionOpening(void) { // 0x8B9B68 LoadTitleSequenceGraphics(); - QueueMusic_Delayed8(0xFF03u); + QueueMusic_Delayed8(0xFF03); cinematic_function = FUNC16(CinematicFunctionNone); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BA0EF, FUNC16(CinematicFunctionNone)); - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); } void LoadTitleSequenceGraphics(void) { // 0x8B9B87 @@ -2214,7 +1719,7 @@ void LoadTitleSequenceGraphics(void) { // 0x8B9B87 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8B9BFF = { 1, 0, 0x19, LONGPTR(0x7f0000), 0x4000 }; SetupDmaTransfer(&unk_8B9BFF); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMAIN, 0); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0); @@ -2228,13 +1733,13 @@ void LoadTitleSequenceGraphics(void) { // 0x8B9B87 WriteReg(VMAIN, 0); static const StartDmaCopy unk_8B9C37 = { 1, 0, 0x18, LONGPTR(0x7f4000), 0x1000 }; SetupDmaTransfer(&unk_8B9C37); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8B9C57 = { 1, 1, 0x18, LONGPTR(0x7f5000), 0x4000 }; SetupDmaTransfer(&unk_8B9C57); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(M7A, 0x100); reg_M7A = 256; WriteRegWord(M7B, 0); @@ -2450,7 +1955,7 @@ uint16 CinematicSprInstr_9F19(uint16 k, uint16 j) { // 0x8B9F19 } void CinematicFunc_Func1(void) { // 0x8B9F29 - bool v0 = (--demo_timer & 0x8000u) != 0; + bool v0 = (--demo_timer & 0x8000) != 0; if (!demo_timer || v0) { cinematic_function = FUNC16(CinematicFunc_Func9); LABEL_6: @@ -2483,7 +1988,7 @@ void CinematicFunc_Func10(void) { // 0x8B9F52 ClearPaletteFXObjects(); for (int i = 656; i >= 0; i -= 2) *(uint16 *)((uint8 *)&cinematic_var5 + (uint16)i) = 0; - for (j = 510; (j & 0x8000u) == 0; j -= 2) + for (j = 510; (j & 0x8000) == 0; j -= 2) hdma_table_1[j >> 1] = 0; game_state = 4; game_options_screen_index = 0; @@ -2508,7 +2013,7 @@ void CinematicFunc_Func9(void) { // 0x8B9FAE ClearPaletteFXObjects(); for (int i = 656; i >= 0; i -= 2) *(uint16 *)((uint8 *)&cinematic_var5 + (uint16)i) = 0; - for (j = 510; (j & 0x8000u) == 0; j -= 2) + for (j = 510; (j & 0x8000) == 0; j -= 2) hdma_table_1[j >> 1] = 0; game_state = 40; demo_scene = 0; @@ -2516,7 +2021,7 @@ void CinematicFunc_Func9(void) { // 0x8B9FAE } void ConfigureTitleSequenceGradientHDMA(void) { // 0x8BA00A - uint16 v0 = g_off_8CBC5D[(uint16)((uint8)(cinematic_var6 & 0xF0) >> 3) >> 1]; + uint16 v0 = g_off_8CBC5D[(cinematic_var6 & 0xF0) >> 4]; for (int i = 0; ; i += 2) { uint16 v2 = *(uint16 *)RomPtr_8C(v0); hdma_table_1[i >> 1] = v2; @@ -2527,23 +2032,24 @@ void ConfigureTitleSequenceGradientHDMA(void) { // 0x8BA00A } uint16 PlayBabyMetroidCry1(uint16 k, uint16 j) { // 0x8BA25B - QueueSfx3_Max6(0x23u); + QueueSfx3_Max6(0x23); return j; } uint16 PlayBabyMetroidCry2(uint16 k, uint16 j) { // 0x8BA263 - QueueSfx3_Max6(0x26u); + QueueSfx3_Max6(0x26); return j; } uint16 PlayBabyMetroidCry3(uint16 k, uint16 j) { // 0x8BA26B - QueueSfx3_Max6(0x27u); + QueueSfx3_Max6(0x27); return j; } static const uint16 kCinematicPal1[16] = { 0x1000, 0x6bf5, 0x2e41, 0x2da1, 0x2d01, 0x5e5f, 0x183f, 0x1014, 0x80a, 0x404, 0x4f9f, 0x3ed8, 0x2e12, 0x6f70, 0x7fff, 0x5ee0 }; static const uint16 kCinematicPal2[16] = { 0x3800, 0x6bf5, 0x6e1, 0x641, 0x5a1, 0x5e5f, 0x183f, 0x1014, 0x80a, 0x404, 0x4f9f, 0x3ed8, 0x2e12, 0x6f70, 0x7fff, 0x5ee0 }; static const uint16 kCinematicPal3[16] = { 0x3800, 0x77f8, 0x1344, 0x12a4, 0x1204, 0x6abf, 0x249f, 0x1c77, 0x146d, 0x1067, 0x5bff, 0x4b38, 0x3a72, 0x7bd3, 0x7fff, 0x6b43 }; static const uint16 kCinematicPal4[16] = { 0x3800, 0x7ffb, 0x1fa7, 0x1f07, 0x1e67, 0x771f, 0x30ff, 0x28da, 0x20d0, 0x1cca, 0x67ff, 0x579b, 0x46d5, 0x7bd6, 0x7fff, 0x77a6 }; + uint16 CinematicSetPal1(uint16 k, uint16 j) { // 0x8BA273 for (int i = 30; i >= 0; i -= 2) palette_buffer[(i >> 1) + 48] = kCinematicPal1[i >> 1]; @@ -2570,7 +2076,7 @@ uint16 CinematicSetPal4(uint16 k, uint16 j) { // 0x8BA2A6 CoroutineRet GameState_37_CeresGoesBoomWithSamus_(void) { // 0x8BA35B CallCinematicFunction(cinematic_function | 0x8B0000); - if ((cinematic_var11 & 0x8000u) == 0) + if ((cinematic_var11 & 0x8000) == 0) ++cinematic_var11; ++cinematic_var12; HandleSamusDuringIntro(); @@ -2624,43 +2130,43 @@ void CinematicFunction_Intro_Initial(void) { // 0x8BA395 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA469 = { 1, 1, 0x18, LONGPTR(0x7f0000), 0x8000 }; SetupDmaTransfer(&unk_8BA469); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x40); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA489 = { 1, 1, 0x18, LONGPTR(0x7f8000), 0x0900 }; SetupDmaTransfer(&unk_8BA489); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x48); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA4A9 = { 1, 1, 0x18, LONGPTR(0x7f9000), 0x0800 }; SetupDmaTransfer(&unk_8BA4A9); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x4C); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA4C9 = { 1, 1, 0x18, LONGPTR(0x7fe000), 0x0800 }; SetupDmaTransfer(&unk_8BA4C9); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x50); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA4E9 = { 1, 1, 0x18, LONGPTR(0x7f9800), 0x2000 }; SetupDmaTransfer(&unk_8BA4E9); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA509 = { 1, 1, 0x18, LONGPTR(0x9ad200), 0x2000 }; SetupDmaTransfer(&unk_8BA509); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x6E); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA529 = { 1, 1, 0x18, LONGPTR(0x7fb800), 0x2400 }; SetupDmaTransfer(&unk_8BA529); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); DecompressToMem(0x95D713, g_ram + 0x1a000); EnableNMI(); screen_fade_delay = 3; @@ -2672,14 +2178,14 @@ void CinematicFunction_Intro_Initial(void) { // 0x8BA395 layer1_x_pos = 0; layer1_y_pos = 0; cinematic_var16 = 0; - for (j = 1023; (j & 0x8000u) == 0; --j) + for (j = 1023; (j & 0x8000) == 0; --j) ram3800.cinematic_bg_tilemap[j] = *(uint16 *)&BTS[j * 2 + 11262]; - for (k = 127; (k & 0x8000u) == 0; --k) + for (k = 127; (k & 0x8000) == 0; --k) ram3000.pause_menu_map_tilemap[k] = *(uint16 *)((uint8 *)g_word_8CD81B + k * 2); cinematic_var11 = -1; cinematic_function = FUNC16(CinematicFunction_Intro_FadeIn); QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF3Fu); + QueueMusic_Delayed8(0xFF3F); } void CinematicFunction_Intro_FadeIn(void) { // 0x8BA5A7 @@ -2708,20 +2214,20 @@ void CinematicFunction_Intro_DrawInitJpn(void) { // 0x8BA5BD } void CinematicFunction_Intro_LastMetroidCaptivity(void) { // 0x8BA5F8 - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { cinematic_function = FUNC16(CinematicFunc_Intro_QueueGalaxyIsAtPeace); cinematic_var4 = 200; - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); } } void CinematicFunc_Intro_QueueGalaxyIsAtPeace(void) { // 0x8BA613 - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF42u); - QueueMusic_DelayedY(5u, 0xE); + QueueMusic_Delayed8(0xFF42); + QueueMusic_DelayedY(5, 0xE); cinematic_function = FUNC16(CinematicFunc_Intro_WaitForQueueWait4secs); } } @@ -2734,7 +2240,7 @@ void CinematicFunc_Intro_WaitForQueueWait4secs(void) { // 0x8BA639 } void CinematicFunc_Intro_FadeOut(void) { // 0x8BA64C - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { cinematic_function = FUNC16(CinematicFunc_Intro_WaitForFadeOut); screen_fade_delay = 2; @@ -2754,7 +2260,7 @@ void CinematicFunc_Intro_SetupTextPage2(void) { // 0x8BA66F WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BA689 = { 1, 1, 0x18, LONGPTR(0x7e4000), 0x0600 }; SetupDmaTransfer(&unk_8BA689); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(TM, 0x16); reg_TM = 22; ClearCinematicBgObjects(0x2F); @@ -2782,8 +2288,8 @@ void CinematicFunc_Intro_SetupTextPage2(void) { // 0x8BA66F ClearEnglishTextTilemap(); SetSomeStuffForSpriteObject_16(); QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF36u); - QueueMusic_DelayedY(5u, 0xE); + QueueMusic_Delayed8(0xFF36); + QueueMusic_DelayedY(5, 0xE); cinematic_function = FUNC16(CinematicFunc_Intro_WaitFadeinShowText); } @@ -2857,12 +2363,12 @@ void CinematicSprPreInstr_A903(uint16 k) { // 0x8BA903 uint16 CinematicSprInstr_SpawnMetroidEggParticles(uint16 k, uint16 j) { // 0x8BA918 SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCECD, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCED3, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCED9, 2u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEDF, 3u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEE5, 4u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEEB, 5u); - QueueSfx2_Max6(0xBu); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCED3, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCED9, 2); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEDF, 3); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEE5, 4); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEEB, 5); + QueueSfx2_Max6(0xB); return j; } static const int16 kSetSomeStuffForSpriteObject_6_Tab[12] = { 0x5c, 0x58, 0x63, 0x58, 0x59, 0x5d, 0x60, 0x5b, 0x66, 0x5e, 0x63, 0x60 }; @@ -3123,8 +2629,7 @@ void CinematicFunction_Intro_WaitInputSetupMotherBrainFight(void) { // 0x8BAEB8 samus_prev_y_pos = 115; cinematic_var8 = 0; cinematic_var13 = 127; - R18_ = 0; - SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BCE55, 0x7F); + SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BCE55, 0); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF27, 0); uint16 v1 = 0; do { @@ -3200,7 +2705,7 @@ void CinematicFunction_Intro_SetupTransitionToGameplay(void) { // 0x8BB018 v0 += 2; } while ((int16)(v0 - 512) < 0); DecomposePaletteDataForFading(); - ClearYColorsFromIndexX(0x28, 3u); + ClearYColorsFromIndexX(0x28, 3); ClearYColorsFromIndexX(0xE0, 0x10); ClearYColorsFromIndexX(0x180, 0x20); ClearYColorsFromIndexX(0x1E0, 0x10); @@ -3284,7 +2789,7 @@ void CinematicFunction_Intro_Func13(void) { // 0x8BB151 } while ((int16)(v0 - 512) < 0); DecomposePaletteDataForFading(); ClearYColorsFromIndexX(0x40, 0x10); - ClearYColorsFromIndexX(0x1C0, 9u); + ClearYColorsFromIndexX(0x1C0, 9); ComposeFadingPalettes(); } @@ -3306,6 +2811,15 @@ uint16 CinematicBgInstr_SpawnMarkerWaitInput_Page5(uint16 k, uint16 j) { // 0x8 return j; } +void CinematicFunction_Intro_Func15b(void) { // 0x8BB207 + EnableCinematicBgTilemapUpdates(); + ClearEnglishTextTilemap(); + SpawnCinematicBgObject(addr_kCinematicBgObjectDef_8BCF5D, 0x4C00); + cinematic_function = FUNC16(nullsub_121); + SetSomeStuffForSpriteObject_16(); + QueueMusic_Delayed8(0); +} + void CinematicFunction_Intro_Func15(void) { // 0x8BB1DA if (cinematic_var16) { --cinematic_var16; @@ -3322,15 +2836,6 @@ void CinematicFunction_Intro_Func15(void) { // 0x8BB1DA } } -void CinematicFunction_Intro_Func15b(void) { // 0x8BB207 - EnableCinematicBgTilemapUpdates(); - ClearEnglishTextTilemap(); - SpawnCinematicBgObject(addr_kCinematicBgObjectDef_8BCF5D, 0x4C00); - cinematic_function = FUNC16(nullsub_121); - SetSomeStuffForSpriteObject_16(); - QueueMusic_Delayed8(0); -} - uint16 CinematicBgInstr_Func16(uint16 k, uint16 j) { // 0x8BB228 cinematicbg_var1 = 0; if (japanese_text_flag) @@ -3349,14 +2854,14 @@ void CinematicFunction_Intro_XfadeGameplayFade(void) { // 0x8BB250 if ((cinematic_var4 & 3) == 0) { FadeOutYColorsFromIndexX(0, 0x14); FadeOutYColorsFromIndexX(0x60, 0x10); - FadeOutYColorsFromIndexX(0x1D2, 6u); - FadeInYColorsFromIndexX(0x28, 3u); + FadeOutYColorsFromIndexX(0x1D2, 6); + FadeInYColorsFromIndexX(0x28, 3); FadeInYColorsFromIndexX(0xE0, 0x10); FadeInYColorsFromIndexX(0x180, 0x20); FadeInYColorsFromIndexX(0x1E0, 0x10); ComposeFadingPalettes(); } - if ((--cinematic_var4 & 0x8000u) != 0) { + if ((--cinematic_var4 & 0x8000) != 0) { reg_TM = 21; reg_TS = 0; reg_CGWSEL = 0; @@ -3366,7 +2871,7 @@ void CinematicFunction_Intro_XfadeGameplayFade(void) { // 0x8BB250 while ((int16)(v0 * 2 - 1536) < 0); ClearJapaneseTextTiles(); cinematic_function = FUNC16(CinematicFunc_Nothing); - if ((cinematic_var15 & 0x8000u) != 0) + if ((cinematic_var15 & 0x8000) != 0) SpawnPalfxObject(addr_kPalfx_E1BC); } } @@ -3375,12 +2880,12 @@ void CinematicFunction_Intro_XfadeScientistFade(void) { // 0x8BB2D2 if ((cinematic_var4 & 3) == 0) { FadeOutYColorsFromIndexX(0, 0x14); FadeOutYColorsFromIndexX(0x60, 0x10); - FadeOutYColorsFromIndexX(0x1D2, 6u); + FadeOutYColorsFromIndexX(0x1D2, 6); FadeInYColorsFromIndexX(0x40, 0x10); - FadeInYColorsFromIndexX(0x1C0, 9u); + FadeInYColorsFromIndexX(0x1C0, 9); ComposeFadingPalettes(); } - if ((--cinematic_var4 & 0x8000u) != 0) { + if ((--cinematic_var4 & 0x8000) != 0) { reg_TM = 21; reg_TS = 0; reg_CGWSEL = 0; @@ -3423,6 +2928,26 @@ void Instr_StartIntroPage_Common(void) { // 0x8BB354 TransferJapaneseTextTilesToVram(); } +void CinematicFunction_Intro_SetupStuff(void) { // 0x8BB3A1 + reg_TM = 6; + reg_TS = 17; + reg_CGWSEL = 2; + reg_CGADSUB = 0; + uint16 v0 = 0; + do { + tilemap_stuff[(v0 >> 1) + 256] = kPalettes_Intro[v0 >> 1]; + v0 += 2; + } while ((int16)(v0 - 512) < 0); + DecomposePaletteDataForFading(); + ClearYColorsFromIndexX(0, 0x10); + ClearYColorsFromIndexX(0x60, 0x10); + ClearYColorsFromIndexX(0x1D2, 6); + ComposeFadingPalettes(); + cinematic_var4 = 127; + EnableCinematicBgTilemapUpdates(); + SetSomeStuffForSpriteObject_16(); +} + void CinematicFunction_Intro_Page2(void) { // 0x8BB35F SpawnCinematicBgObject(addr_kCinematicBgObjectDef_8BCF45, 0x4C00); cinematic_function = FUNC16(CinematicFunction_Intro_Fadestuff); @@ -3447,38 +2972,18 @@ void CinematicFunction_Intro_Page5(void) { // 0x8BB392 CinematicFunction_Intro_SetupStuff(); } -void CinematicFunction_Intro_SetupStuff(void) { // 0x8BB3A1 - reg_TM = 6; - reg_TS = 17; - reg_CGWSEL = 2; - reg_CGADSUB = 0; - uint16 v0 = 0; - do { - tilemap_stuff[(v0 >> 1) + 256] = kPalettes_Intro[v0 >> 1]; - v0 += 2; - } while ((int16)(v0 - 512) < 0); - DecomposePaletteDataForFading(); - ClearYColorsFromIndexX(0, 0x10); - ClearYColorsFromIndexX(0x60, 0x10); - ClearYColorsFromIndexX(0x1D2, 6u); - ComposeFadingPalettes(); - cinematic_var4 = 127; - EnableCinematicBgTilemapUpdates(); - SetSomeStuffForSpriteObject_16(); -} - void CinematicFunction_Intro_Fadestuff(void) { // 0x8BB3F4 if ((cinematic_var13 & 3) == 0) { FadeInYColorsFromIndexX(0, 0x10); FadeInYColorsFromIndexX(0x60, 0x10); - FadeInYColorsFromIndexX(0x1D2, 6u); - FadeOutYColorsFromIndexX(0x28, 3u); + FadeInYColorsFromIndexX(0x1D2, 6); + FadeOutYColorsFromIndexX(0x28, 3); FadeOutYColorsFromIndexX(0xE0, 0x10); FadeOutYColorsFromIndexX(0x180, 0x20); FadeOutYColorsFromIndexX(0x1E0, 0x10); ComposeFadingPalettes(); } - if ((--cinematic_var13 & 0x8000u) != 0) { + if ((--cinematic_var13 & 0x8000) != 0) { reg_TM = 22; reg_TS = 0; reg_CGWSEL = 0; @@ -3491,12 +2996,12 @@ void CinematicFunction_Intro_Fadestuff2(void) { // 0x8BB458 if ((cinematic_var13 & 3) == 0) { FadeInYColorsFromIndexX(0, 0x10); FadeInYColorsFromIndexX(0x60, 0x10); - FadeInYColorsFromIndexX(0x1D2, 6u); + FadeInYColorsFromIndexX(0x1D2, 6); FadeOutYColorsFromIndexX(0x40, 0x10); - FadeOutYColorsFromIndexX(0x1C0, 9u); + FadeOutYColorsFromIndexX(0x1C0, 9); ComposeFadingPalettes(); } - if ((--cinematic_var13 & 0x8000u) != 0) { + if ((--cinematic_var13 & 0x8000) != 0) { reg_TM = 22; reg_TS = 0; reg_CGWSEL = 0; @@ -3520,6 +3025,15 @@ void CinematicBgPreInstr_SamusBlink(uint16 k) { // 0x8BB4BC } } +void CallCreditsObjectFunc(uint32 ea, uint16 k) { + switch (ea) { + case fnCinematicFunction_nullsub_116: return; + case fnCinematicBgPreInstr_SamusBlink: CinematicBgPreInstr_SamusBlink(k); return; + default: Unreachable(); + } +} + + void CinematicFunction_Intro_Func19(uint16 k) { // 0x8BB4DC if (!sign16(cinematicspr_instr_ptr[15] + 0x33FD)) cinematicbg_instr_timer[k >> 1] = 1; @@ -3535,10 +3049,6 @@ void CinematicFunction_Intro_Func18(void) { // 0x8BB4EB TransferJapaneseTextTilesToVram(); } -void EnableCinematicBgTilemapUpdates_(void) { // 0x8BB519 - EnableCinematicBgTilemapUpdates(); -} - uint16 sub_8BB51E(uint16 k, uint16 j) { // 0x8BB51E DisableCinematicBgTilemapUpdates(); palette_buffer[17] = kPalettes_Intro[17]; @@ -3699,9 +3209,9 @@ uint16 EnableCinematicBgTilemapUpdates__(uint16 k, uint16 j) { // 0x8BB70B void CinematicFunction_Intro_Func33(void) { // 0x8BB711 if ((nmi_frame_counter_word & 1) != 0) - reg_TM &= ~2u; + reg_TM &= ~2; else - reg_TM |= 2u; + reg_TM |= 2; } void CinematicFunction_Intro_Func34(void) { // 0x8BB72F @@ -3736,7 +3246,7 @@ void CinematicFunction_Intro_Func36(uint16 k) { // 0x8BB786 uint16 v1 = 8; while ((projectile_type[v1 >> 1] & 0xFFF) != 256) { v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) return; } if (sign16(projectile_x_pos[v1 >> 1] - 84)) { @@ -3749,13 +3259,13 @@ void CinematicFunction_Intro_Func36(uint16 k) { // 0x8BB786 cinematicspr_goto_timer[v2] = 0; cinematicspr_preinstr_func[v2] = FUNC16(CinematicFunction_Intro_Func39); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF1B, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF1B, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF1B, 2u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF1B, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF1B, 2); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 2u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 3u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 4u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 2); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 3); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF15, 4); } } } @@ -3791,7 +3301,7 @@ void CinematicFunction_Intro_Func37(uint16 k) { // 0x8BB846 palette_buffer[(i >> 1) + 240] = kPalettes_Intro[(i >> 1) + 240]; v3 = k; } else { - for (j = 30; (j & 0x8000u) == 0; j -= 2) + for (j = 30; (j & 0x8000) == 0; j -= 2) palette_buffer[(j >> 1) + 240] = 0x7FFF; v3 = k; } @@ -3805,8 +3315,10 @@ void CinematicFunction_Intro_Func40(void) { // 0x8BB877 else cinematic_var10 += 4; } + static const uint16 kCinematicFunction_Intro_Func42_Tab0[4] = { 0x70, 0xc0, 0x80, 0xe8 }; static const uint16 kCinematicFunction_Intro_Func42_Tab1[4] = { 0x50, 0x40, 0x38, 0x58 }; + void CinematicFunction_Intro_Func42(uint16 j) { // 0x8BB896 uint16 v1 = cinematic_spawn_param; int v2 = j >> 1; @@ -3834,7 +3346,6 @@ void CinematicFunction_Intro_Func44(uint16 k) { // 0x8BB8D8 uint16 v3 = cinematicspr_arr7[v1]; cinematicspr_arr7[v1] = v3 + 0x8000; cinematicbg_arr8[v1] += __CFADD__uint16(v3, 0x8000); - R18_ = samus_x_pos - 5; if (sign16(cinematicbg_arr7[v1] + 8 - (samus_x_pos - 5))) { if (cinematicspr_preinstr_func[0] != FUNC16(CinematicFunction_Intro_Func39)) return; @@ -3846,6 +3357,7 @@ void CinematicFunction_Intro_Func44(uint16 k) { // 0x8BB8D8 cinematicspr_instr_timer[v1] = 1; cinematicspr_instr_ptr[v1] = addr_off_8BCE53; } + static const uint16 kCinematicFunction_Intro_Func45_Tab0[4] = { 0, 0xffff, 0, 0xffff }; void CinematicFunction_Intro_Func45(uint16 k) { // 0x8BB93B int v1 = k >> 1; @@ -3901,13 +3413,13 @@ void CinematicFunction_Intro_Func48(uint16 k) { // 0x8BBA0F uint16 CinematicSprInstr_SpawnIntroRinkas01(uint16 k, uint16 j) { // 0x8BBA21 SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF21, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF21, 1u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF21, 1); return j; } uint16 CinematicSprInstr_SpawnIntroRinkas23(uint16 k, uint16 j) { // 0x8BBA36 - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF21, 2u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF21, 3u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF21, 2); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF21, 3); return j; } @@ -3931,10 +3443,10 @@ void CinematicFunction_Intro_Func51(uint16 k) { // 0x8BBA73 int v1 = k >> 1; if (cinematicbg_arr8[v1] == 145) { SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEF1, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEF1, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEF1, 2u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEF1, 3u); - QueueSfx3_Max6(0x23u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEF1, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEF1, 2); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEF1, 3); + QueueSfx3_Max6(0x23); } if ((int16)(samus_y_pos - 32 - cinematicbg_arr8[v1]) < 0) { if (!sign16(cinematic_var17 + 543)) @@ -3942,20 +3454,20 @@ void CinematicFunction_Intro_Func51(uint16 k) { // 0x8BBA73 } else if (sign16(cinematic_var17 - 544)) { cinematic_var17 += 32; } - R20_ = cinematic_var17 << 8; - R18_ = (int8)(cinematic_var17 >> 8); + uint16 r20 = cinematic_var17 << 8; + uint16 r18 = (int8)(cinematic_var17 >> 8); uint16 v4 = cinematicspr_arr7[v1]; - bool v5 = __CFADD__uint16(R20_, v4); - cinematicspr_arr7[v1] = R20_ + v4; - cinematicbg_arr8[v1] += R18_ + v5; - if ((cinematic_var17 & 0x8000u) == 0) { + bool v5 = __CFADD__uint16(r20, v4); + cinematicspr_arr7[v1] = r20 + v4; + cinematicbg_arr8[v1] += r18 + v5; + if ((cinematic_var17 & 0x8000) == 0) { cinematic_var14 = 128; cinematicspr_preinstr_func[v1] = FUNC16(CinematicFunction_Intro_Func52); } } void CinematicFunction_Intro_Func52(uint16 k) { // 0x8BBB0D - bool v1 = (--cinematic_var14 & 0x8000u) != 0; + bool v1 = (--cinematic_var14 & 0x8000) != 0; if (!cinematic_var14 || v1) { int v2 = k >> 1; cinematicspr_preinstr_func[v2] = FUNC16(CinematicFunction_Intro_Func53); @@ -3972,7 +3484,7 @@ void CinematicFunction_Intro_Func53(uint16 k) { // 0x8BBB24 uint16 v3 = cinematicspr_goto_timer[v2] + 1; cinematicspr_goto_timer[v2] = v3; if ((v3 & 0x3F) == 0) - QueueSfx3_Max6(0x23u); + QueueSfx3_Max6(0x23); } if ((int16)(samus_x_pos - cinematicbg_arr7[v2]) < 0) { if (!sign16(cinematic_var14 + 639)) @@ -3980,28 +3492,28 @@ void CinematicFunction_Intro_Func53(uint16 k) { // 0x8BBB24 } else if (sign16(cinematic_var14 - 640)) { cinematic_var14 += 32; } - R20_ = cinematic_var14 << 8; - R18_ = (int8)GET_HIBYTE(cinematic_var14); - if (!sign16(R18_)) + uint16 r20 = cinematic_var14 << 8; + uint16 r18 = (int8)GET_HIBYTE(cinematic_var14); + if (!sign16(r18)) cinematic_var15 = -1; else cinematic_var15 = 1; uint16 v6 = cinematicspr_arr6[v2]; - bool v7 = __CFADD__uint16(R20_, v6); - cinematicspr_arr6[v2] = R20_ + v6; - cinematicbg_arr7[v2] += R18_ + v7; + bool v7 = __CFADD__uint16(r20, v6); + cinematicspr_arr6[v2] = r20 + v6; + cinematicbg_arr7[v2] += r18 + v7; if ((int16)(samus_y_pos - 8 - cinematicbg_arr8[v2]) < 0) { if (!sign16(cinematic_var17 + 543)) cinematic_var17 -= 32; } else if (sign16(cinematic_var17 - 544)) { cinematic_var17 += 32; } - R20_ = cinematic_var17 << 8; - R18_ = (int8)GET_HIBYTE(cinematic_var17); + r20 = cinematic_var17 << 8; + r18 = (int8)GET_HIBYTE(cinematic_var17); uint16 v10 = cinematicspr_arr7[v2]; - v7 = __CFADD__uint16(R20_, v10); - cinematicspr_arr7[v2] = R20_ + v10; - cinematicbg_arr8[v2] += R18_ + v7; + v7 = __CFADD__uint16(r20, v10); + cinematicspr_arr7[v2] = r20 + v10; + cinematicbg_arr8[v2] += r18 + v7; } else { int v1 = k >> 1; cinematicspr_instr_timer[v1] = 1; @@ -4011,17 +3523,17 @@ void CinematicFunction_Intro_Func53(uint16 k) { // 0x8BBB24 } void ResetButtonAssignmentsToDefault(void) { // 0x8BBC08 + button_config_shoot_x_saved = button_config_shoot_x; + button_config_jump_a_saved = button_config_jump_a; + button_config_run_b_saved = button_config_run_b; + button_config_itemcancel_y_saved = button_config_itemcancel_y; + button_config_itemswitch_saved = button_config_itemswitch; + button_config_aim_down_L_saved = button_config_aim_down_L; + button_config_aim_up_R_saved = button_config_aim_up_R; button_config_up = kButton_Up; button_config_down = kButton_Down; button_config_left = kButton_Left; button_config_right = kButton_Right; - grapple_beam_tmpD82 = button_config_shoot_x; - grapple_beam_tmpD84 = button_config_jump_a; - grapple_beam_y_quarter_subvel = button_config_run_b; - grapple_beam_y_quarter_vel = button_config_itemcancel_y; - grapple_beam_tmpD8A = button_config_itemswitch; - grapple_beam_varD8C = button_config_aim_down_L; - grapple_beam_varD8E = button_config_aim_up_R; button_config_shoot_x = kButton_X; button_config_jump_a = kButton_A; button_config_run_b = kButton_B; @@ -4032,13 +3544,13 @@ void ResetButtonAssignmentsToDefault(void) { // 0x8BBC08 } void RevertButtonConfig(void) { // 0x8BBC75 - button_config_shoot_x = grapple_beam_tmpD82; - button_config_jump_a = grapple_beam_tmpD84; - button_config_run_b = grapple_beam_y_quarter_subvel; - button_config_itemcancel_y = grapple_beam_y_quarter_vel; - button_config_itemswitch = grapple_beam_tmpD8A; - button_config_aim_down_L = grapple_beam_varD8C; - button_config_aim_up_R = grapple_beam_varD8E; + button_config_shoot_x = button_config_shoot_x_saved; + button_config_jump_a = button_config_jump_a_saved; + button_config_run_b = button_config_run_b_saved; + button_config_itemcancel_y = button_config_itemcancel_y_saved; + button_config_itemswitch = button_config_itemswitch_saved; + button_config_aim_down_L = button_config_aim_down_L_saved; + button_config_aim_up_R = button_config_aim_up_R_saved; } void CinematicFunction_Intro_Func54(void) { // 0x8BBCA0 @@ -4060,7 +3572,7 @@ void CinematicFunction_Intro_Func54(void) { // 0x8BBCA0 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BBD04 = { 1, 0, 0x19, LONGPTR(0x7f0000), 0x4000 }; SetupDmaTransfer(&unk_8BBD04); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMAIN, 0); WriteRegWord(VMADDL, 0); @@ -4074,13 +3586,13 @@ void CinematicFunction_Intro_Func54(void) { // 0x8BBCA0 WriteReg(VMAIN, 0); static const StartDmaCopy unk_8BBD3C = { 1, 0, 0x18, LONGPTR(0x7f4000), 0x0300 }; SetupDmaTransfer(&unk_8BBD3C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(VMADDL, 0x6000); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BBD5C = { 1, 1, 0x18, LONGPTR(0x7f5000), 0x4000 }; SetupDmaTransfer(&unk_8BBD5C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(M7A, 0x100); reg_M7A = 256; @@ -4105,8 +3617,8 @@ void CinematicFunction_Intro_Func54(void) { // 0x8BBCA0 EnableNMI(); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF0F, 0); cinematic_function = FUNC16(CinematicFunction_Intro_Func55); - QueueMusic_Delayed8(0xFF2Du); - QueueMusic_DelayedY(5u, 0xE); + QueueMusic_Delayed8(0xFF2D); + QueueMusic_DelayedY(5, 0xE); } void CinematicFunction_Intro_Func55(void) { // 0x8BBDE4 @@ -4131,8 +3643,8 @@ void CinematicFunction_Intro_Func56(void) { // 0x8BBDF9 SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF39, 0); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCE85, 0); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCE8B, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCE91, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF0F, 1u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCE91, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF0F, 1); cinematic_function = FUNC16(CinematicFunction_Intro_Func67); SpawnPalfxObject(addr_kPalfx_E1A8); SpawnPalfxObject(addr_kPalfx_E1AC); @@ -4162,20 +3674,20 @@ void CinematicFunction_Intro_Func58(uint16 k) { // 0x8BBEB5 int v1 = k >> 1; uint16 v2 = cinematicspr_goto_timer[v1] + 128; cinematicspr_goto_timer[v1] = v2; - R20_ = (v2 & 0xff) << 8; - R18_ = (int8)(v2 >> 8); + uint16 r20 = (v2 & 0xff) << 8; + uint16 r18 = (int8)(v2 >> 8); uint16 v5 = cinematicspr_arr7[v1]; - bool v6 = __CFADD__uint16(R20_, v5); - cinematicspr_arr7[v1] = R20_ + v5; - cinematicbg_arr8[v1] += R18_ + v6; + bool v6 = __CFADD__uint16(r20, v5); + cinematicspr_arr7[v1] = r20 + v5; + cinematicbg_arr8[v1] += r18 + v6; uint16 v7 = cinematicspr_arr6[v1]; - v6 = __CFADD__uint16(R20_, v7); - cinematicspr_arr6[v1] = R20_ + v7; - cinematicbg_arr7[v1] += R18_ + v6; - v8 = __PAIR32__(R18_, R20_) + __PAIR32__(cinematic_var8, cinematic_var7); + v6 = __CFADD__uint16(r20, v7); + cinematicspr_arr6[v1] = r20 + v7; + cinematicbg_arr7[v1] += r18 + v6; + v8 = __PAIR32__(r18, r20) + __PAIR32__(cinematic_var8, cinematic_var7); cinematic_var8 = HIWORD(v8); cinematic_var7 = v8; - v9 = __PAIR32__(R18_, R20_) + __PAIR32__(cinematic_var10, cinematic_var9); + v9 = __PAIR32__(r18, r20) + __PAIR32__(cinematic_var10, cinematic_var9); cinematic_var10 = HIWORD(v9); cinematic_var9 = v9; } @@ -4353,7 +3865,7 @@ void CinematicFunctionBlackoutFromCeres(void) { // 0x8BC11B WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BC19C = { 1, 0, 0x19, LONGPTR(0x7f0000), 0x4000 }; SetupDmaTransfer(&unk_8BC19C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMAIN, 0); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0); @@ -4367,19 +3879,19 @@ void CinematicFunctionBlackoutFromCeres(void) { // 0x8BC11B WriteReg(VMAIN, 0); static const StartDmaCopy unk_8BC1D4 = { 1, 0, 0x18, LONGPTR(0x7f4600), 0x0600 }; SetupDmaTransfer(&unk_8BC1D4); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BC1F4 = { 1, 1, 0x18, LONGPTR(0x7f5000), 0x4000 }; SetupDmaTransfer(&unk_8BC1F4); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BC214 = { 1, 1, 0x18, LONGPTR(0x9ad200), 0x1a00 }; SetupDmaTransfer(&unk_8BC214); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(M7A, 0x100); reg_M7A = 256; WriteRegWord(M7B, 0); @@ -4403,9 +3915,7 @@ void CinematicFunctionBlackoutFromCeres(void) { // 0x8BC11B ClearCinematicBgObjects(0x2f); cinematicbg_var3 = 0; SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCE7F, 0); - R18_ = 2; - SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BCE8B, 2u); - R18_ = 0; + SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BCE8B, 2); SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BCE91, 0); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCF33, 0); SpawnPalfxObject(addr_kPalfx_E1B8); @@ -4414,11 +3924,11 @@ void CinematicFunctionBlackoutFromCeres(void) { // 0x8BC11B screen_fade_counter = 1; cinematic_function = FUNC16(CinematicFunction_Intro_Func74); QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF2Du); + QueueMusic_Delayed8(0xFF2D); if (game_state == kGameState_37_CeresGoesBoomWithSamus) - QueueMusic_DelayedY(8u, 0xE); + QueueMusic_DelayedY(8, 0xE); else - QueueMusic_DelayedY(7u, 0xE); + QueueMusic_DelayedY(7, 0xE); } void CinematicFunction_Intro_Func74(void) { // 0x8BC2E4 @@ -4473,10 +3983,10 @@ void CinematicFunction_Intro_Func76(void) { // 0x8BC345 uint16 CinematicSprInstr_SpawnCeresExplosions1(uint16 k, uint16 j) { // 0x8BC404 SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 2u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 3u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 4u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 2); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 3); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEBB, 4); return j; } static const uint16 kCinematicFunction_Intro_Func78_Tab0[5] = { 1, 16, 32, 48, 64 }; @@ -4497,11 +4007,11 @@ void CinematicSprPreInstr_C489(uint16 k) { // 0x8BC489 if (cinematic_function == FUNC16(CinematicFunction_Intro_Func77)) { cinematicspr_preinstr_func[k >> 1] = FUNC16(CinematicFunction_nullsub_116); } else { - bool v1 = (--cinematic_var4 & 0x8000u) != 0; + bool v1 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v1) { SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC1, cinematic_var13); cinematic_var4 = 12; - cinematic_var13 = ((uint8)cinematic_var13 + 1) & 7; + cinematic_var13 = (cinematic_var13 + 1) & 7; } } } @@ -4522,9 +4032,9 @@ void CinematicFunction_Intro_Func80(uint16 j) { uint16 CinematicSprInstr_SpawnCeresExplosions3(uint16 k, uint16 j) { // 0x8BC50C SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC7, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC7, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC7, 2u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC7, 3u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC7, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC7, 2); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BCEC7, 3); return j; } static const int16 kCinematicFunction_Intro_Func81_Tab0[4] = { 1, 4, 8, 16 }; @@ -4572,7 +4082,7 @@ void CinematicFunction_Intro_Func77(void) { // 0x8BC5CA } void CinematicFunction_Intro_Func84(void) { // 0x8BC610 - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { screen_fade_delay = 1; screen_fade_counter = 1; @@ -4624,19 +4134,19 @@ void CinematicFunction_Intro_Func86(void) { // 0x8BC699 WriteReg(VMAIN, 0); static const StartDmaCopy unk_8BC6E4 = { 1, 0, 0x18, LONGPTR(0x7f4300), 0x0300 }; SetupDmaTransfer(&unk_8BC6E4); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x5C); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BC704 = { 1, 1, 0x18, LONGPTR(0x7f9000), 0x0800 }; SetupDmaTransfer(&unk_8BC704); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BC724 = { 1, 1, 0x18, LONGPTR(0x7f5000), 0x4000 }; SetupDmaTransfer(&unk_8BC724); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteRegWord(M7A, 0x100); reg_M7A = 256; WriteRegWord(M7B, 0); @@ -4716,12 +4226,12 @@ void CinematicFunction_Intro_Func91(uint16 k) { // 0x8BC85D int v1 = k >> 1; uint16 v2 = cinematicspr_goto_timer[v1] + 64; cinematicspr_goto_timer[v1] = v2; - R20_ = v2 << 8; - R18_ = (uint8)(v2 >> 8); + uint16 r20 = v2 << 8; + uint16 r18 = (uint8)(v2 >> 8); uint16 v4 = cinematicspr_arr7[v1]; - bool v5 = v4 < R20_; - cinematicspr_arr7[v1] = v4 - R20_; - uint16 v6 = cinematicbg_arr8[v1] - (v5 + R18_); + bool v5 = v4 < r20; + cinematicspr_arr7[v1] = v4 - r20; + uint16 v6 = cinematicbg_arr8[v1] - (v5 + r18); cinematicbg_arr8[v1] = v6; if (sign16(v6 + 128)) { cinematicspr_instr_timer[v1] = 1; @@ -4745,12 +4255,12 @@ void CinematicFunction_Intro_Func94(uint16 k) { // 0x8BC8B9 int v1 = k >> 1; uint16 v2 = cinematicspr_goto_timer[v1] + 32; cinematicspr_goto_timer[v1] = v2; - R20_ = v2 << 8; - R18_ = (uint8)(v2 >> 8); + uint16 r20 = v2 << 8; + uint16 r18 = (uint8)(v2 >> 8); uint16 v4 = cinematicspr_arr7[v1]; - bool v5 = v4 < R20_; - cinematicspr_arr7[v1] = v4 - R20_; - uint16 v6 = cinematicbg_arr8[v1] - (v5 + R18_); + bool v5 = v4 < r20; + cinematicspr_arr7[v1] = v4 - r20; + uint16 v6 = cinematicbg_arr8[v1] - (v5 + r18); cinematicbg_arr8[v1] = v6; if (sign16(v6 + 128)) { cinematicspr_instr_timer[v1] = 1; @@ -4768,12 +4278,12 @@ void CinematicFunction_Intro_Func97(uint16 k) { // 0x8BC908 int v1 = k >> 1; uint16 v2 = cinematicspr_goto_timer[v1] + 32; cinematicspr_goto_timer[v1] = v2; - R20_ = v2 << 8; - R18_ = (uint8)(v2 >> 8); + uint16 r20 = v2 << 8; + uint16 r18 = (uint8)(v2 >> 8); uint16 v4 = cinematicspr_arr7[v1]; - bool v5 = v4 < R20_; - cinematicspr_arr7[v1] = v4 - R20_; - uint16 v6 = cinematicbg_arr8[v1] - (v5 + R18_); + bool v5 = v4 < r20; + cinematicspr_arr7[v1] = v4 - r20; + uint16 v6 = cinematicbg_arr8[v1] - (v5 + r18); cinematicbg_arr8[v1] = v6; if (sign16(v6 + 128)) { cinematicspr_instr_timer[v1] = 1; @@ -4854,7 +4364,7 @@ void CinematicFunction_Intro_Func105(void) { // 0x8BC9F9 v0 = __PAIR32__(cinematic_var10, cinematic_var9) + 0x2000; cinematic_var10 = HIWORD(v0); cinematic_var9 = v0; - bool v1 = cinematic_var7 >= 0x8000u; + bool v1 = cinematic_var7 >= 0x8000; cinematic_var7 += 0x8000; cinematic_var8 -= !v1; if (sign16(cinematic_var6 - 1152)) @@ -4869,7 +4379,7 @@ void CinematicFunction_Intro_Func106(void) { // 0x8BCA36 v0 = __PAIR32__(cinematic_var10, cinematic_var9) + 0x2000; cinematic_var10 = HIWORD(v0); cinematic_var9 = v0; - bool v1 = cinematic_var7 >= 0x8000u; + bool v1 = cinematic_var7 >= 0x8000; cinematic_var7 += 0x8000; cinematic_var8 -= !v1; if (sign16(cinematic_var8 + 128)) { @@ -4901,7 +4411,7 @@ void CinematicFunction_Intro_Func107(void) { // 0x8BCA85 } void CinematicFunction_Intro_Func108(void) { // 0x8BCAD0 - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) cinematic_function = FUNC16(nullsub_124); } @@ -4916,7 +4426,7 @@ void CinematicFunction_Intro_Func95(void) { // 0x8BCADF CoroutineRet GameState_39_EndingAndCredits_(void) { // 0x8BD443 CallCinematicFunction(cinematic_function | 0x8B0000); - if ((cinematic_var11 & 0x8000u) == 0) + if ((cinematic_var11 & 0x8000) == 0) ++cinematic_var11; ++cinematic_var12; HandleCinematicSprites(); @@ -4955,25 +4465,25 @@ void CinematicFunctionEscapeFromCebes(void) { // 0x8BD480 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD4FC = { 1, 1, 0x18, LONGPTR(0x7f8000), 0x4000 }; SetupDmaTransfer(&unk_8BD4FC); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x20); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD51C = { 1, 1, 0x18, LONGPTR(0x7f8000), 0x4000 }; SetupDmaTransfer(&unk_8BD51C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD53C = { 1, 1, 0x18, LONGPTR(0x7f4000), 0x4000 }; SetupDmaTransfer(&unk_8BD53C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD55C = { 1, 0, 0x19, LONGPTR(0x7f0000), 0x4000 }; SetupDmaTransfer(&unk_8BD55C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); DecompressToMem(0x988304, g_ram + 0x18000); DecompressToMem(0x95a82f, g_ram + 0x10000); DecompressToMem(0x96fe69, g_ram + 0x14000); @@ -5018,14 +4528,14 @@ void CinematicFunctionEscapeFromCebes(void) { // 0x8BD480 reg_CGADSUB = 17; SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BEEEB, 0); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BEEF1, 0); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BEEEB, 1u); - SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BEEF1, 1u); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BEEEB, 1); + SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BEEF1, 1); screen_fade_delay = 0; screen_fade_counter = 2; cinematic_function = FUNC16(CinematicFunction_Intro_Func109); QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF33u); - QueueMusic_DelayedY(5u, 0xE); + QueueMusic_Delayed8(0xFF33); + QueueMusic_DelayedY(5, 0xE); } void CinematicFunction_Intro_Func109(void) { // 0x8BD6D7 @@ -5058,20 +4568,20 @@ void CinematicFunction_Intro_Func112(void) { // 0x8BD731 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD746 = { 1, 1, 0x18, LONGPTR(0x7e2000), 0x4000 }; SetupDmaTransfer(&unk_8BD746); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x20); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD766 = { 1, 1, 0x18, LONGPTR(0x7e2000), 0x4000 }; SetupDmaTransfer(&unk_8BD766); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); DecompressToMem(0x98ED4F, g_ram + 0x2000); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD79B = { 1, 0, 0x19, LONGPTR(0x7e2000), 0x4000 }; SetupDmaTransfer(&unk_8BD79B); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); ClearPaletteFXObjects(); ClearCinematicSprites(); SpawnPalfxObject(addr_kPalfx_E1E0); @@ -5086,12 +4596,6 @@ void CinematicFunction_Intro_Func112(void) { // 0x8BD731 cinematic_function = FUNC16(CinematicFunction_Intro_Func113); } -void CinematicFunction_Intro_Func113(void) { // 0x8BD7F8 - CinematicFunction_Intro_Func114(); - if (AdvanceFastScreenFadeIn() & 1) - cinematic_function = FUNC16(CinematicFunction_Intro_Func114); -} - void CinematicFunction_Intro_Func114(void) { // 0x8BD807 if ((cinematic_var12 & 1) == 0) cinematic_var5 = (uint8)(cinematic_var5 - 1); @@ -5102,62 +4606,68 @@ void CinematicFunction_Intro_Func114(void) { // 0x8BD807 } } +void CinematicFunction_Intro_Func113(void) { // 0x8BD7F8 + CinematicFunction_Intro_Func114(); + if (AdvanceFastScreenFadeIn() & 1) + cinematic_function = FUNC16(CinematicFunction_Intro_Func114); +} + void CinematicFunction_Intro_Func115(void) { // 0x8BD837 WriteReg(VMADDL, 0); WriteReg(VMADDH, 0); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD84C = { 1, 1, 0x18, LONGPTR(0x7e6000), 0x4000 }; SetupDmaTransfer(&unk_8BD84C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x20); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD86C = { 1, 1, 0x18, LONGPTR(0x7e6000), 0x4000 }; SetupDmaTransfer(&unk_8BD86C); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); DecompressToMem(0x999101, g_ram + 0x6000); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD8A1 = { 1, 0, 0x19, LONGPTR(0x7e6000), 0x4000 }; SetupDmaTransfer(&unk_8BD8A1); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x40); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD8C1 = { 1, 1, 0x18, LONGPTR(0x7f8000), 0x6000 }; SetupDmaTransfer(&unk_8BD8C1); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x70); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD8E1 = { 1, 1, 0x18, LONGPTR(0x7fe000), 0x0800 }; SetupDmaTransfer(&unk_8BD8E1); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x74); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD901 = { 1, 1, 0x18, LONGPTR(0x7fe800), 0x0800 }; SetupDmaTransfer(&unk_8BD901); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x78); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD921 = { 1, 1, 0x18, LONGPTR(0x7ff000), 0x0800 }; SetupDmaTransfer(&unk_8BD921); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x7C); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD941 = { 1, 1, 0x18, LONGPTR(0x7ff800), 0x0800 }; SetupDmaTransfer(&unk_8BD941); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x50); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BD961 = { 1, 1, 0x18, LONGPTR(0x7ea000), 0x1000 }; SetupDmaTransfer(&unk_8BD961); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); reg_OBSEL = 2; ClearPaletteFXObjects(); ClearCinematicSprites(); @@ -5212,7 +4722,7 @@ void CinematicFunction_Intro_Func117(void) { // 0x8BDA1A FadeInYColorsFromIndexX(0x1E0, 0x10); ComposeFadingPalettes(); } - if ((--cinematic_var4 & 0x8000u) != 0) { + if ((--cinematic_var4 & 0x8000) != 0) { uint16 v0 = 0; do { palette_buffer[v0 >> 1] = kPalettes_Intro6[v0 >> 1]; @@ -5299,11 +4809,11 @@ void CinematicFunction_Intro_Func118(void) { } void CinematicFunction_Intro_Func119(void) { // 0x8BDB9E - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF3Cu); - QueueMusic_DelayedY(5u, 0xE); + QueueMusic_Delayed8(0xFF3C); + QueueMusic_DelayedY(5, 0xE); cinematic_function = FUNC16(CinematicFunction_Intro_Func120); } } @@ -5340,7 +4850,7 @@ void CinematicFunction_Intro_Func120(void) { // 0x8BDBC4 } void CinematicFunction_Intro_Func122(void) { // 0x8BDC4C - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { if (sign8(--reg_COLDATA[0] - 32)) reg_COLDATA[0] = 32; @@ -5371,7 +4881,7 @@ void CinematicFunction_Intro_Func121(void) { v1 = (kCinematicFunction_Intro_Func121_Tab0[v0 + 1] + __PAIR32__(cinematic_var8, cinematic_var7)) >> 16; cinematic_var7 += kCinematicFunction_Intro_Func121_Tab0[v0 + 1]; cinematic_var8 = kCinematicFunction_Intro_Func121_Tab0[v0] + v1; - cinematic_var14 = ((uint8)cinematic_var14 + 1) & 0xF; + cinematic_var14 = (cinematic_var14 + 1) & 0xF; cinematic_var6 -= 8; if (sign16(cinematic_var6 - 1456)) { cinematic_var13 = 1; @@ -5379,7 +4889,9 @@ void CinematicFunction_Intro_Func121(void) { cinematic_function = FUNC16(CinematicFunction_Intro_Func123); } } + static const uint16 kCinematicFunction_Intro_Func123_Tab0[16] = { 1, 0, 1, 0, 1, 0, 0xffff, 0, 0xffff, 0, 1, 0, 1, 0, 0xffff, 0 }; + void CinematicFunction_Intro_Func123(void) { // 0x8BDD42 int16 v1; @@ -5390,19 +4902,20 @@ void CinematicFunction_Intro_Func123(void) { // 0x8BDD42 v1 = (kCinematicFunction_Intro_Func123_Tab0[v0 + 1] + __PAIR32__(cinematic_var8, cinematic_var7)) >> 16; cinematic_var7 += kCinematicFunction_Intro_Func123_Tab0[v0 + 1]; cinematic_var8 = kCinematicFunction_Intro_Func123_Tab0[v0] + v1; - cinematic_var14 = ((uint8)cinematic_var14 + 1) & 7; + cinematic_var14 = (cinematic_var14 + 1) & 7; cinematic_var6 -= 2; if (sign16(cinematic_var6 - 1184)) { cinematic_function = FUNC16(CinematicFunction_Intro_Func124); cinematic_var14 = 0x8000; cinematic_var13 = 0; - if (CheckEventHappened(0xFu)) { - R18_ = 4; - SpawnCinematicSpriteObjectToR18(0xEF21, 4u); + if (CheckEventHappened(0xF)) { + SpawnCinematicSpriteObjectToR18(0xEF21, 4); } } } + static const uint16 g_word_8BDE43[16] = { 0, 0x6f7b, 0x4a52, 0x1ce7, 0, 0x5ad6, 0x4a52, 0x35ad, 0x2529, 0x7fff, 0x56b5, 0x294a, 0x4210, 0x2d6b, 0x18c6, 0x7fff }; + void CinematicFunction_Intro_Func124(void) { // 0x8BDDCD unsigned int v2; // kr04_4 @@ -5458,37 +4971,37 @@ void CinematicFunction_Intro_Func126(void) { // 0x8BDE80 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BDF39 = { 1, 1, 0x18, LONGPTR(0x7fe800), 0x0100 }; SetupDmaTransfer(&unk_8BDF39); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x24); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BDF59 = { 1, 1, 0x18, LONGPTR(0x7ff000), 0x0800 }; SetupDmaTransfer(&unk_8BDF59); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x40); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BDF79 = { 1, 1, 0x18, LONGPTR(0x7fc000), 0x1000 }; SetupDmaTransfer(&unk_8BDF79); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x60); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BDF99 = { 1, 1, 0x18, LONGPTR(0x7e6000), 0x4000 }; SetupDmaTransfer(&unk_8BDF99); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x50); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BDFB9 = { 1, 1, 0x18, LONGPTR(0x7f0000), 0x2000 }; SetupDmaTransfer(&unk_8BDFB9); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x4C); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BDFD9 = { 1, 1, 0x18, LONGPTR(0x7fe000), 0x0800 }; SetupDmaTransfer(&unk_8BDFD9); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); DecompressToMem(0x99E089, g_ram + 0x6000); DecompressToMem(0x99ECC4, g_ram + 0x8000); @@ -5498,14 +5011,14 @@ void CinematicFunction_Intro_Func126(void) { // 0x8BDE80 WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BE027 = { 1, 1, 0x18, LONGPTR(0x7e2000), 0x4000 }; SetupDmaTransfer(&unk_8BE027); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } else { WriteReg(VMADDL, 0); WriteReg(VMADDH, 0); WriteReg(VMAIN, 0x80); static const StartDmaCopy unk_8BE04B = { 1, 1, 0x18, LONGPTR(0x7f0000), 0x4000 }; SetupDmaTransfer(&unk_8BE04B); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); } WriteRegWord(M7A, 0x100); reg_M7A = 256; @@ -5542,7 +5055,7 @@ void CinematicFunction_Intro_Func126(void) { // 0x8BDE80 } void CinematicFunction_Intro_Func129(void) { // 0x8BE0F4 - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { cinematic_function = FUNC16(CinematicFunction_Intro_Func130); cinematic_var4 = 120; @@ -5571,7 +5084,7 @@ void CinematicFunction_Intro_Func130(void) { // 0x8BE110 void CinematicFunction_Intro_Func131(void) { // 0x8BE158 FadeInYColorsFromIndexX(0x40, 0x10); ComposeFadingPalettes(); - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { reg_TM = 18; reg_TS = 4; @@ -5585,7 +5098,7 @@ void CinematicFunction_Intro_Func131(void) { // 0x8BE158 void CinematicFunction_Intro_Func132(void) { // 0x8BE190 reg_BG3VOFS += 2; - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { uint16 v1 = 0; do { @@ -5671,7 +5184,7 @@ void CinematicFunction_Intro_Func135(void) { // 0x8BE293 } void CinematicFunction_Intro_Func137(void) { // 0x8BE2DD - bool v0 = (--cinematic_var13 & 0x8000u) != 0; + bool v0 = (--cinematic_var13 & 0x8000) != 0; if (!cinematic_var13 || v0) { if (sign16(game_time_hours - 3) || sign16(game_time_hours - 10)) { reg_TM = 2; @@ -5699,7 +5212,7 @@ void CinematicFunction_Intro_Func138(void) { // 0x8BE314 } void CinematicFunction_Intro_Func145(void) { // 0x8BE342 - if ((--cinematic_var4 & 0x8000u) != 0) { + if ((--cinematic_var4 & 0x8000) != 0) { reg_TM = 16; reg_TS = 0; reg_CGWSEL = 0; @@ -5724,6 +5237,14 @@ void CinematicFunction_Intro_Func145(void) { // 0x8BE342 } } +void CinematicFunction_Intro_Func140(void) { // 0x8BE409 + if (cinematic_var17) { + --cinematic_var17; + FadeOutYColorsFromIndexX(0x1E0, 0x10); + ComposeFadingPalettes(); + } +} + void CinematicFunction_Intro_Func139(void) { // 0x8BE3AE if (cinematic_var14) { --cinematic_var14; @@ -5745,20 +5266,12 @@ void CinematicFunction_Intro_Func139(void) { // 0x8BE3AE } } -void CinematicFunction_Intro_Func140(void) { // 0x8BE409 - if (cinematic_var17) { - --cinematic_var17; - FadeOutYColorsFromIndexX(0x1E0, 0x10); - ComposeFadingPalettes(); - } -} - void CinematicFunction_Intro_Func142(void) { // 0x8BE41F if (!cinematic_var17) { if (sign16(cinematic_var14 - 6)) { uint16 v0 = 4 * cinematic_var14; uint16 v1 = vram_write_queue_tail; - int v2 = (uint16)(8 * cinematic_var14) >> 1; + int v2 = (8 * cinematic_var14) >> 1; gVramWriteEntry(vram_write_queue_tail)->size = kCinematicFunction_Intro_Func142_Tab0[v2]; v1 += 2; gVramWriteEntry(v1)->size = kCinematicFunction_Intro_Func142_Tab0[v2 + 1]; @@ -5813,7 +5326,7 @@ void CinematicFunction_Intro_Func143(void) { // 0x8BE504 reg_COLDATA[1] = 64; if (sign8(--reg_COLDATA[2] + 0x80)) reg_COLDATA[2] = 0x80; - bool v0 = (--cinematic_var4 & 0x8000u) != 0; + bool v0 = (--cinematic_var4 & 0x8000) != 0; if (!cinematic_var4 || v0) { cinematic_function = FUNC16(nullsub_127); cinematicbg_var3 = 20480; @@ -5826,7 +5339,7 @@ void CinematicFunction_Intro_Func143(void) { // 0x8BE504 SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BEF93, 0); for (int i = 30; i >= 0; i -= 2) palette_buffer[(i >> 1) + 16] = 0; - for (j = 30; (j & 0x8000u) == 0; j -= 2) + for (j = 30; (j & 0x8000) == 0; j -= 2) palette_buffer[(j >> 1) + 240] = g_word_8CEFE9[j >> 1]; } } @@ -5842,7 +5355,7 @@ void CinematicFunction_Intro_Func144(void) { // 0x8BE58A v1 -= 2; } uint16 v3 = v5; - for (j = 30; (j & 0x8000u) == 0; j -= 2) { + for (j = 30; (j & 0x8000) == 0; j -= 2) { palette_buffer[(j >> 1) + 240] = *(uint16 *)RomPtr_8C(v3); v3 -= 2; } @@ -5857,40 +5370,40 @@ uint16 CalcItemPercentageCount(uint16 k, uint16 instrp) { // 0x8BE627 uint16 j; uint16 v0 = 4; - R18_ = 0; + uint16 r18 = 0; do { const uint16 *v1 = (const uint16 *)RomPtr_RAM(g_off_8BE70D[v0]); - R18_ += SnesDivide(*v1, g_word_8BE717[v0]); + r18 += SnesDivide(*v1, g_word_8BE717[v0]); --v0; - } while ((v0 & 0x8000u) == 0); + } while ((v0 & 0x8000) == 0); for (int i = 20; i >= 0; i -= 2) { if ((g_word_8BE721[i >> 1] & collected_items) != 0) - ++R18_; + ++r18; } - for (j = 8; (j & 0x8000u) == 0; j -= 2) { + for (j = 8; (j & 0x8000) == 0; j -= 2) { if ((g_word_8BE737[j >> 1] & collected_beams) != 0) - ++R18_; + ++r18; } - uint16 RegWord = R18_ / 10; - R22_ = R18_ % 10; - R18_ = RegWord / 10; - R20_ = RegWord % 10; - if (R18_) { - int v5 = (uint16)(4 * R18_) >> 1; + uint16 RegWord = r18 / 10; + uint16 r22 = r18 % 10; + r18 = RegWord / 10; + uint16 r20 = RegWord % 10; + if (r18) { + int v5 = (uint16)(4 * r18) >> 1; ram3000.pause_menu_map_tilemap[462] = g_word_8BE741[v5]; ram3000.pause_menu_map_tilemap[494] = g_word_8BE741[v5 + 1]; } - uint16 v6 = R20_; - if (R20_) + uint16 v6 = r20; + if (r20) goto LABEL_16; - if (R18_) { - v6 = R20_; + if (r18) { + v6 = r20; LABEL_16:; int v7 = (uint16)(4 * v6) >> 1; ram3000.pause_menu_map_tilemap[463] = g_word_8BE741[v7]; ram3000.pause_menu_map_tilemap[495] = g_word_8BE741[v7 + 1]; } - int v8 = (uint16)(4 * R22_) >> 1; + int v8 = (uint16)(4 * r22) >> 1; ram3000.pause_menu_map_tilemap[464] = g_word_8BE741[v8]; ram3000.pause_menu_map_tilemap[496] = g_word_8BE741[v8 + 1]; ram3000.pause_menu_map_tilemap[465] = 14442; @@ -5929,17 +5442,17 @@ void CinematicFunction_Intro_Func127(void) { // 0x8BE7BB uint16 v0 = ADDR16_OF_RAM(*g_byte_7E0E0C); v1 = 0; - R18_ = 0; +// R18 = 0; do { v4 = v1; uint8 *v2 = RomPtr_RAM(v0); *(uint16 *)v2 = v1; *((uint16 *)v2 + 6) = 0; *((uint16 *)v2 + 7) = 0; - uint16 v3 = g_word_8BE9CF[((uint16)(8 * v1) >> 1) + 3]; + uint16 v3 = g_word_8BE9CF[((8 * v1) >> 1) + 3]; if (v3) { *((uint16 *)v2 + 5) = v3; - *(uint16 *)v2 |= 0x8000u; + *(uint16 *)v2 |= 0x8000; } else { *((uint16 *)v2 + 5) = 32; } @@ -5964,12 +5477,12 @@ void CinematicFunction_Intro_Func149(void) { // 0x8BE812 int16 v22; if (enemy_projectile_pre_instr[1]) { - R22_ = 40; + int n = 40; uint16 v0 = 0xe0c; do { uint8 *v3 = RomPtr_RAM(v0); if (*(int16 *)v3 < 0) { - uint8 *v1 = RomPtr_RAM(v0); + uint8 *v1 = v3; v2 = GET_WORD(v1 + 10) - 1; *((uint16 *)v1 + 5) = v2; if (v2 < 0) { @@ -5977,7 +5490,7 @@ void CinematicFunction_Intro_Func149(void) { // 0x8BE812 *(uint16 *)v1 = *v1; } } else { - int v4 = (uint16)(8 * (uint8) * (uint16 *)v3) >> 1; + int v4 = (8 * (uint8) * (uint16 *)v3) >> 1; if (sign16((GET_WORD(v3) & 0xFF00) - 1024)) { *((uint16 *)v3 + 6) += g_word_8BE9CF[v4]; v5 = GET_WORD(v3 + 14); @@ -5987,24 +5500,23 @@ void CinematicFunction_Intro_Func149(void) { // 0x8BE812 } *((uint16 *)v3 + 7) = g_word_8BE9CF[v4 + 1] + v5; uint16 v23 = GET_WORD(v3 + 12); - R18_ = (int8)HIBYTE(v23); - R20_ = (v23 << 8) & 0xFF00; + uint16 r18 = (int8)HIBYTE(v23); + uint16 r20 = (v23 << 8) & 0xFF00; v8 = GET_WORD(v3 + 4); - bool v9 = __CFADD__uint16(R20_, v8); - *((uint16 *)v3 + 2) = R20_ + v8; - *((uint16 *)v3 + 1) += R18_ + v9; + bool v9 = __CFADD__uint16(r20, v8); + *((uint16 *)v3 + 2) = r20 + v8; + *((uint16 *)v3 + 1) += r18 + v9; uint16 v24 = GET_WORD(v3 + 14); - R18_ = (int8)HIBYTE(v24); - R20_ = (v24 << 8) & 0xFF00; + r18 = (int8)HIBYTE(v24); + r20 = (v24 << 8) & 0xFF00; v12 = GET_WORD(v3 + 8); - v9 = __CFADD__uint16(R20_, v12); - *((uint16 *)v3 + 4) = R20_ + v12; - *((uint16 *)v3 + 3) += R18_ + v9; + v9 = __CFADD__uint16(r20, v12); + *((uint16 *)v3 + 4) = r20 + v12; + *((uint16 *)v3 + 3) += r18 + v9; } v0 += 16; - --R22_; - } while (R22_); - R22_ = 40; + } while (--n); + int n2 = 40; uint16 v13 = oam_next_ptr; uint16 v14 = 3596; do { @@ -6016,7 +5528,7 @@ void CinematicFunction_Intro_Func149(void) { // 0x8BE812 || ((v17 - 4) & 0xFF00) != 0 || (v18 = gOamEnt(v13), *(uint16 *)&v18->xcoord = v17 - 4, v19 = GET_WORD(v16 + 6), v16[7]) || ((v19 - 4) & 0xFF00) != 0) { - uint8 *v21 = RomPtr_RAM(v14); + uint8 *v21 = v15; *((uint16 *)v21 + 5) = 32; *((uint16 *)v21 + 1) = 128; *((uint16 *)v21 + 3) = 128; @@ -6031,7 +5543,7 @@ void CinematicFunction_Intro_Func149(void) { // 0x8BE812 *((uint16 *)v16 + 5) = v20; if (v20 <= 0) { v22 = GET_WORD(v16); - *((uint16 *)v16 + 5) = g_word_8BE9CF[((uint16)(8 * (uint8) * (uint16 *)v16) >> 1) + 2]; + *((uint16 *)v16 + 5) = g_word_8BE9CF[((8 * (uint8) * (uint16 *)v16) >> 1) + 2]; *(uint16 *)v16 = v22 + 512; } if (v16[1]) { @@ -6041,8 +5553,7 @@ void CinematicFunction_Intro_Func149(void) { // 0x8BE812 } } v14 += 16; - --R22_; - } while (R22_); + } while (--n2); oam_next_ptr = v13; } } @@ -6148,7 +5659,6 @@ void CinematicFunction_Intro_Func164(uint16 j) { // 0x8BF094 } void CinematicFunction_Intro_Func160(uint16 j, uint16 a) { // 0x8BF0A3 - R18_ = 8 * a; cinematicspr_instr_ptr[j >> 1] += 8 * a; } @@ -6333,10 +5843,8 @@ uint16 CinematicSprInstr_Func185(uint16 k, uint16 j) { // 0x8BF2B7 reg_CGADSUB = 17; LOBYTE(v0) = 124; reg_BG2SC = 124; - R18_ = 0; SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEEBB, 0); - R18_ = 2; - SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEEF7, 0); + SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEEF7, 2); SpawnPalfxObject(addr_kPalfx_E1C8); SpawnPalfxObject(addr_kPalfx_E1D0); SpawnPalfxObject(addr_kPalfx_E1E8); @@ -6351,8 +5859,7 @@ uint16 CinematicSprInstr_Func186(uint16 k, uint16 j) { // 0x8BF2FA reg_BG1SC = 116; reg_BG2SC = 120; SpawnPalfxObject(addr_kPalfx_E1CC); - R18_ = 6; - SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEEC1, 6u); + SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEEC1, 6); return j; } @@ -6517,7 +6024,6 @@ void CinematicFunction_Intro_Func207(uint16 k) { // 0x8BF507 } uint16 CinematicSprInstr_Func208(uint16 k, uint16 j) { // 0x8BF51D - R18_ = 0; SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEF3F, 0); return j; } @@ -6535,12 +6041,10 @@ void CinematicSprPreInstr_F528(uint16 k) { // 0x8BF528 } uint16 CinematicSprInstr_Func211(uint16 k, uint16 j) { // 0x8BF554 - R18_ = 2; if (sign16(game_time_hours - 10)) SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEF7B, 2); else SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEF75, 2); - R18_ = 0; SpawnCinematicSpriteObjectToR18(addr_kCinematicSpriteObjectDef_8BEF6F, 0); return j; } @@ -6602,7 +6106,7 @@ uint16 CinematicSprInstr_Func217(uint16 k, uint16 j) { // 0x8BF604 cinematic_var17 = 32; CopyPalettesToFadingPalettes(); DecomposePaletteDataForFading(); - QueueSfx1_Max15(0x22u); + QueueSfx1_Max15(0x22); return j; } @@ -6656,4 +6160,406 @@ uint16 CinematicFunction_Intro_Func219(uint16 k, uint16 j) { // 0x8BF6FE cinematic_function = FUNC16(CinematicFunction_Intro_Func129); cinematic_var4 = 60; return j; -} \ No newline at end of file +} + +void CallCinematicFunction(uint32 ea) { + switch (ea) { + case fnCinematicFunctionNone: CinematicFunctionNone(); return; + case fnCinematicFunctionOpening: CinematicFunctionOpening(); return; + case fnCinematicFunc_Func2: CinematicFunc_Func2(); return; + case fnCinematicFunc_Func4: CinematicFunc_Func4(); return; + case fnCinematicFunc_Func5: CinematicFunc_Func5(); return; + case fnCinematicFunc_Func7: CinematicFunc_Func7(); return; + case fnnullsub_117: return; + case fnCinematicFunc_Func1: CinematicFunc_Func1(); return; + case fnCinematicFunc_Func10: CinematicFunc_Func10(); return; + case fnCinematicFunc_Func9: CinematicFunc_Func9(); return; + case fnnullsub_120: return; + case fnnullsub_121: return; + case fnCinematicFunc_Nothing: CinematicFunc_Nothing(); return; + case fnCinematicFunction_Intro_Initial: CinematicFunction_Intro_Initial(); return; + case fnCinematicFunction_Intro_FadeIn: CinematicFunction_Intro_FadeIn(); return; + case fnCinematicFunction_Intro_DrawInitJpn: CinematicFunction_Intro_DrawInitJpn(); return; + case fnCinematicFunction_Intro_LastMetroidCaptivity: CinematicFunction_Intro_LastMetroidCaptivity(); return; + case fnCinematicFunc_Intro_QueueGalaxyIsAtPeace: CinematicFunc_Intro_QueueGalaxyIsAtPeace(); return; + case fnCinematicFunc_Intro_WaitForQueueWait4secs: CinematicFunc_Intro_WaitForQueueWait4secs(); return; + case fnCinematicFunc_Intro_FadeOut: CinematicFunc_Intro_FadeOut(); return; + case fnCinematicFunc_Intro_WaitForFadeOut: CinematicFunc_Intro_WaitForFadeOut(); return; + case fnCinematicFunc_Intro_SetupTextPage2: CinematicFunc_Intro_SetupTextPage2(); return; + case fnCinematicFunc_Intro_WaitFadeinShowText: CinematicFunc_Intro_WaitFadeinShowText(); return; + case fnCinematicFunc_Intro_WaitForFadeinSleep: CinematicFunc_Intro_WaitForFadeinSleep(); return; + case fnCinematicFunction_Intro_WaitInputSetupMotherBrainFight: CinematicFunction_Intro_WaitInputSetupMotherBrainFight(); return; + case fnCinematicFunction_Intro_WaitInputSetupBabyMetroid: CinematicFunction_Intro_WaitInputSetupBabyMetroid(); return; + case fnCinematicFunction_Intro_Func11: CinematicFunction_Intro_Func11(); return; + case fnCinematicFunction_Intro_Func12: CinematicFunction_Intro_Func12(); return; + case fnCinematicFunction_Intro_Func15: CinematicFunction_Intro_Func15(); return; + case fnCinematicFunction_Intro_Func15b: CinematicFunction_Intro_Func15b(); return; + case fnCinematicFunction_Intro_XfadeGameplayFade: CinematicFunction_Intro_XfadeGameplayFade(); return; + case fnCinematicFunction_Intro_XfadeScientistFade: CinematicFunction_Intro_XfadeScientistFade(); return; + case fnCinematicFunction_Intro_Page2: CinematicFunction_Intro_Page2(); return; + case fnCinematicFunction_Intro_Page3: CinematicFunction_Intro_Page3(); return; + case fnCinematicFunction_Intro_Page4: CinematicFunction_Intro_Page4(); return; + case fnCinematicFunction_Intro_Page5: CinematicFunction_Intro_Page5(); return; + case fnCinematicFunction_Intro_Fadestuff: CinematicFunction_Intro_Fadestuff(); return; + case fnCinematicFunction_Intro_Fadestuff2: CinematicFunction_Intro_Fadestuff2(); return; + case fnCinematicFunction_Intro_Func34: CinematicFunction_Intro_Func34(); return; + case fnCinematicFunction_Intro_Func54: CinematicFunction_Intro_Func54(); return; + case fnCinematicFunction_Intro_Func55: CinematicFunction_Intro_Func55(); return; + case fnCinematicFunction_Intro_Func56: CinematicFunction_Intro_Func56(); return; + case fnCinematicFunction_Intro_Func67: CinematicFunction_Intro_Func67(); return; + case fnCinematicFunction_Intro_Func72: CinematicFunction_Intro_Func72(); return; + case fnCinematicFunction_Intro_Func73: CinematicFunction_Intro_Func73(); return; + case fnCinematicFunctionBlackoutFromCeres: CinematicFunctionBlackoutFromCeres(); return; + case fnCinematicFunction_Intro_Func74: CinematicFunction_Intro_Func74(); return; + case fnCinematicFunction_Intro_Func75: CinematicFunction_Intro_Func75(); return; + case fnCinematicFunction_Intro_Func76: CinematicFunction_Intro_Func76(); return; + case fnCinematicFunction_Intro_Func77: CinematicFunction_Intro_Func77(); return; + case fnCinematicFunction_Intro_Func84: CinematicFunction_Intro_Func84(); return; + case fnCinematicFunction_Intro_Func85: CinematicFunction_Intro_Func85(); return; + case fnCinematicFunction_Intro_Func86: CinematicFunction_Intro_Func86(); return; + case fnCinematicFunction_Intro_Func87: CinematicFunction_Intro_Func87(); return; + case fnCinematicFunction_Intro_Func88: CinematicFunction_Intro_Func88(); return; + case fnCinematicFunction_Intro_Func105: CinematicFunction_Intro_Func105(); return; + case fnCinematicFunction_Intro_Func106: CinematicFunction_Intro_Func106(); return; + case fnCinematicFunction_Intro_Func107: CinematicFunction_Intro_Func107(); return; + case fnCinematicFunction_Intro_Func108: CinematicFunction_Intro_Func108(); return; + case fnnullsub_124: return; + case fnCinematicFunction_Intro_Func95: CinematicFunction_Intro_Func95(); return; + case fnCinematicFunctionEscapeFromCebes: CinematicFunctionEscapeFromCebes(); return; + case fnCinematicFunction_Intro_Func109: CinematicFunction_Intro_Func109(); return; + case fnCinematicFunction_Intro_Func110: CinematicFunction_Intro_Func110(); return; + case fnCinematicFunction_Intro_Func111: CinematicFunction_Intro_Func111(); return; + case fnCinematicFunction_Intro_Func112: CinematicFunction_Intro_Func112(); return; + case fnCinematicFunction_Intro_Func113: CinematicFunction_Intro_Func113(); return; + case fnCinematicFunction_Intro_Func114: CinematicFunction_Intro_Func114(); return; + case fnCinematicFunction_Intro_Func115: CinematicFunction_Intro_Func115(); return; + case fnCinematicFunction_Intro_Func116: CinematicFunction_Intro_Func116(); return; + case fnCinematicFunction_Intro_Func117: CinematicFunction_Intro_Func117(); return; + case fnCinematicFunction_Intro_Func118: CinematicFunction_Intro_Func118(); return; + case fnnullsub_125: return; + case fnCinematicFunction_Intro_Func119: CinematicFunction_Intro_Func119(); return; + case fnCinematicFunction_Intro_Func120: CinematicFunction_Intro_Func120(); return; + case fnCinematicFunction_Intro_Func121: CinematicFunction_Intro_Func121(); return; + case fnCinematicFunction_Intro_Func123: CinematicFunction_Intro_Func123(); return; + case fnCinematicFunction_Intro_Func124: CinematicFunction_Intro_Func124(); return; + case fnnullsub_126: return; + case fnCinematicFunction_Intro_Func125: CinematicFunction_Intro_Func125(); return; + case fnCinematicFunction_Intro_Func126: CinematicFunction_Intro_Func126(); return; + case fnCinematicFunction_Intro_Func129: CinematicFunction_Intro_Func129(); return; + case fnCinematicFunction_Intro_Func130: CinematicFunction_Intro_Func130(); return; + case fnCinematicFunction_Intro_Func131: CinematicFunction_Intro_Func131(); return; + case fnCinematicFunction_Intro_Func132: CinematicFunction_Intro_Func132(); return; + case fnCinematicFunction_Intro_Func134: CinematicFunction_Intro_Func134(); return; + case fnCinematicFunction_Intro_Func136: CinematicFunction_Intro_Func136(); return; + case fnCinematicFunction_Intro_Func135: CinematicFunction_Intro_Func135(); return; + case fnCinematicFunction_Intro_Func137: CinematicFunction_Intro_Func137(); return; + case fnCinematicFunction_Intro_Func138: CinematicFunction_Intro_Func138(); return; + case fnCinematicFunction_Intro_Func145: CinematicFunction_Intro_Func145(); return; + case fnCinematicFunction_Intro_Func139: CinematicFunction_Intro_Func139(); return; + case fnCinematicFunction_Intro_Func141: CinematicFunction_Intro_Func141(); return; + case fnCinematicFunction_Intro_Func143: CinematicFunction_Intro_Func143(); return; + case fnCinematicFunction_Intro_Func144: CinematicFunction_Intro_Func144(); return; + case fnCinematicFunction_Intro_Func148: CinematicFunction_Intro_Func148(); return; + case fnnullsub_127: return; + default: Unreachable(); + } +} + +uint16 CallCinematicSprInstr(uint32 ea, uint16 k, uint16 j) { + switch (ea) { + case fnCinematicSprInstr_Delete: return CinematicSprInstr_Delete(k, j); + case fnCinematicSprInstr_Sleep: return CinematicSprInstr_Sleep(k, j); + case fnCinematicSprInstr_SetPreInstr: return CinematicSprInstr_SetPreInstr(k, j); + case fnCinematicSprInstr_ClearPreInstr: return CinematicSprInstr_ClearPreInstr(k, j); + case fnCinematicSprInstr_GotoRel: return CinematicSprInstr_GotoRel(k, j); + case fnCinematicSprInstr_Goto: return CinematicSprInstr_Goto(k, j); + case fnCinematicSprInstr_DecTimerGoto: return CinematicSprInstr_DecTimerGoto(k, j); + case fnCinematicSprInstr_DecTimerGotoRel: return CinematicSprInstr_DecTimerGotoRel(k, j); + case fnCinematicSprInstr_SetTimer: return CinematicSprInstr_SetTimer(k, j); + case fnCinematicSprInstr_9CE1: return CinematicSprInstr_9CE1(k, j); + case fnCinematicSprInstr_9D5D: return CinematicSprInstr_9D5D(k, j); + case fnCinematicSprInstr_9DD6: return CinematicSprInstr_9DD6(k, j); + case fnCinematicSprInstr_Func8: return CinematicSprInstr_Func8(k, j); + case fnCinematicSprInstr_Func9: return CinematicSprInstr_Func9(k, j); + case fnCinematicSprInstr_sub_8B9EF0: return CinematicSprInstr_sub_8B9EF0(k, j); + case fnCinematicSprInstr_9F19: return CinematicSprInstr_9F19(k, j); + case fnCinematicSprInstr_SpawnMetroidEggParticles: return CinematicSprInstr_SpawnMetroidEggParticles(k, j); + case fnCinematicSprInstr_StartIntroPage2: return CinematicSprInstr_StartIntroPage2(k, j); + case fnCinematicSprInstr_StartIntroPage3: return CinematicSprInstr_StartIntroPage3(k, j); + case fnCinematicSprInstr_StartIntroPage4: return CinematicSprInstr_StartIntroPage4(k, j); + case fnCinematicSprInstr_StartIntroPage5: return CinematicSprInstr_StartIntroPage5(k, j); + case fnCinematicSprInstr_Func43: return CinematicSprInstr_Func43(k, j); + case fnCinematicSprInstr_SpawnIntroRinkas01: return CinematicSprInstr_SpawnIntroRinkas01(k, j); + case fnCinematicSprInstr_SpawnIntroRinkas23: return CinematicSprInstr_SpawnIntroRinkas23(k, j); + case fnCinematicCommonInstr_Func69: return CinematicCommonInstr_Func69(k, j); + case fnCinematicCommonInstr_Func70: return CinematicCommonInstr_Func70(k, j); + case fnCinematicSprInstr_SpawnCeresExplosions1: return CinematicSprInstr_SpawnCeresExplosions1(k, j); + case fnCinematicSprInstr_SpawnCeresExplosions3: return CinematicSprInstr_SpawnCeresExplosions3(k, j); + case fnCinematicSprInstr_C9A5: return CinematicSprInstr_C9A5(k, j); + case fnCinematicSprInstr_C9AF: return CinematicSprInstr_C9AF(k, j); + case fnCinematicSprInstr_C9BD: return CinematicSprInstr_C9BD(k, j); + case fnCinematicSprInstr_C9C7: return CinematicSprInstr_C9C7(k, j); + case fnCinematicSprInstr_Func181: return CinematicSprInstr_Func181(k, j); + case fnCinematicSprInstr_Func182: return CinematicSprInstr_Func182(k, j); + case fnCinematicSprInstr_Func183: return CinematicSprInstr_Func183(k, j); + case fnCinematicSprInstr_Func185: return CinematicSprInstr_Func185(k, j); + case fnCinematicSprInstr_Func186: return CinematicSprInstr_Func186(k, j); + case fnCinematicSprInstr_Func187: return CinematicSprInstr_Func187(k, j); + case fnCinematicSprInstr_Func190: return CinematicSprInstr_Func190(k, j); + case fnCinematicSprInstr_Func192: return CinematicSprInstr_Func192(k, j); + case fnCinematicSprInstr_Func193: return CinematicSprInstr_Func193(k, j); + case fnCinematicSprInstr_Func194: return CinematicSprInstr_Func194(k, j); + case fnCinematicSprInstr_Func195: return CinematicSprInstr_Func195(k, j); + case fnCinematicSprInstr_Func196: return CinematicSprInstr_Func196(k, j); + case fnCinematicSprInstr_Func197: return CinematicSprInstr_Func197(k, j); + case fnCinematicSprInstr_Func198: return CinematicSprInstr_Func198(k, j); + case fnCinematicSprInstr_Func208: return CinematicSprInstr_Func208(k, j); + case fnCinematicSprInstr_Func211: return CinematicSprInstr_Func211(k, j); + case fnCinematicSprInstr_Func213: return CinematicSprInstr_Func213(k, j); + case fnCinematicSprInstr_Func214: return CinematicSprInstr_Func214(k, j); + case fnCinematicSprInstr_Func217: return CinematicSprInstr_Func217(k, j); + case fnCinematicSprInstr_Func218: return CinematicSprInstr_Func218(k, j); + default: return Unreachable(); + } +} + +void CallCinematicSprPreInstr(uint32 ea, uint16 j) { + switch (ea) { + case fnCinematicSprPreInstr_nullsub_300: return; + case fnCinematicFunction_nullsub_116: return; + case fnCinematicFunction_nullsub_298: return; + case fnsub_8B9CCF: sub_8B9CCF(j); return; + case fnnullsub_122: return; + case fnSetSomeStuffForSpriteObject_4_MetroidEgg: SetSomeStuffForSpriteObject_4_MetroidEgg(j); return; + case fnCinematicSprPreInstr_A903: CinematicSprPreInstr_A903(j); return; + case fnSetSomeStuffForSpriteObject_7: SetSomeStuffForSpriteObject_7(j); return; + case fnSetSomeStuffForSpriteObject_9: SetSomeStuffForSpriteObject_9(j); return; + case fnSetSomeStuffForSpriteObject_11: SetSomeStuffForSpriteObject_11(j); return; + case fnSetSomeStuffForSpriteObject_13: SetSomeStuffForSpriteObject_13(j); return; + case fnSetSomeStuffForSpriteObject_18: SetSomeStuffForSpriteObject_18(j); return; + case fnCinematicFunction_Intro_Func36: CinematicFunction_Intro_Func36(j); return; + case fnCinematicFunction_Intro_Func39: CinematicFunction_Intro_Func39(j); return; + case fnCinematicSprPreInstr_B82E: CinematicSprPreInstr_B82E(j); return; + case fnCinematicFunction_Intro_Func44: CinematicFunction_Intro_Func44(j); return; + case fnCinematicFunction_Intro_Func45: CinematicFunction_Intro_Func45(j); return; + case fnCinematicFunction_Intro_Func48: CinematicFunction_Intro_Func48(j); return; + case fnCinematicFunction_Intro_Func50: CinematicFunction_Intro_Func50(j); return; + case fnCinematicFunction_Intro_Func51: CinematicFunction_Intro_Func51(j); return; + case fnCinematicFunction_Intro_Func52: CinematicFunction_Intro_Func52(j); return; + case fnCinematicFunction_Intro_Func53: CinematicFunction_Intro_Func53(j); return; + case fnCinematicFunction_Intro_Func58: CinematicFunction_Intro_Func58(j); return; + case fnCinematicFunction_Intro_Func60: CinematicFunction_Intro_Func60(j); return; + case fnCinematicFunction_Intro_Func62: CinematicFunction_Intro_Func62(j); return; + case fnCinematicFunction_Intro_Func64: CinematicFunction_Intro_Func64(j); return; + case fnCinematicFunction_Intro_Func66: CinematicFunction_Intro_Func66(j); return; + case fnCinematicSprPreInstr_C489: CinematicSprPreInstr_C489(j); return; + case fnCinematicFunction_Intro_Func82: CinematicFunction_Intro_Func82(j); return; + case fnCinematicFunction_Intro_Func90: CinematicFunction_Intro_Func90(j); return; + case fnCinematicFunction_Intro_Func91: CinematicFunction_Intro_Func91(j); return; + case fnCinematicFunction_Intro_Func93: CinematicFunction_Intro_Func93(j); return; + case fnCinematicFunction_Intro_Func94: CinematicFunction_Intro_Func94(j); return; + case fnCinematicFunction_Intro_Func96: CinematicFunction_Intro_Func96(j); return; + case fnCinematicFunction_Intro_Func97: CinematicFunction_Intro_Func97(j); return; + case fnCinematicFunction_Intro_Func151: CinematicFunction_Intro_Func151(j); return; + case fnCinematicFunction_Intro_Func179: CinematicFunction_Intro_Func179(j); return; + case fnCinematicFunction_Intro_Func180: CinematicFunction_Intro_Func180(j); return; + case fnCinematicFunction_Intro_Func184: CinematicFunction_Intro_Func184(j); return; + case fnCinematicSprPreInstr_F35A: CinematicSprPreInstr_F35A(j); return; + case fnCinematicFunction_Intro_Func189: CinematicFunction_Intro_Func189(j); return; + case fnCinematicFunction_Intro_Func189b: CinematicFunction_Intro_Func189b(j); return; + case fnCinematicFunction_Intro_Func191: CinematicFunction_Intro_Func191(j); return; + case fnCinematicFunction_Intro_Func199: CinematicFunction_Intro_Func199(j); return; + case fnCinematicFunction_Intro_Func200: CinematicFunction_Intro_Func200(j); return; + case fnCinematicFunction_Intro_Func201: CinematicFunction_Intro_Func201(j); return; + case fnCinematicFunction_Intro_Func202: CinematicFunction_Intro_Func202(j); return; + case fnCinematicFunction_Intro_Func203: CinematicFunction_Intro_Func203(j); return; + case fnCinematicFunction_Intro_Func204: CinematicFunction_Intro_Func204(j); return; + case fnCinematicFunction_Intro_Func205: CinematicFunction_Intro_Func205(j); return; + case fnCinematicFunction_Intro_Func206: CinematicFunction_Intro_Func206(j); return; + case fnCinematicFunction_Intro_Func207: CinematicFunction_Intro_Func207(j); return; + case fnnullsub_128: return; + case fnCinematicSprPreInstr_F528: CinematicSprPreInstr_F528(j); return; + case fnCinematicSprPreInstr_F57F: CinematicSprPreInstr_F57F(j); return; + case fnCinematicFunction_Intro_Func215: CinematicFunction_Intro_Func215(j); return; + default: Unreachable(); + } +} + +void CallCinematicBgPreInstr(uint32 ea, uint16 j) { + switch (ea) { + case fnCinematicFunction_nullsub_116: return; + case fnCinematicBgPreInstr_SamusBlink: CinematicBgPreInstr_SamusBlink(j); return; + default: Unreachable(); + } +} + +uint16 CallCinematicBgInstr(uint32 ea, uint16 k, uint16 j) { + switch (ea) { + case fnCinematicBgInstr_Delete: return CinematicBgInstr_Delete(k, j); + case fnCinematicBgInstr_Goto: return CinematicBgInstr_Goto(k, j); + case fnCinematicBgInstr_SetSomeStuffForSpriteObject_14: return CinematicBgInstr_SetSomeStuffForSpriteObject_14(k, j); + case fnCinematicBgInstr_HandleCreateJpnText_Page1: return CinematicBgInstr_HandleCreateJpnText_Page1(k, j); + case fnCinematicBgInstr_SpawnMarkerWaitInput_Page1: return CinematicBgInstr_SpawnMarkerWaitInput_Page1(k, j); + case fnCinematicBgInstr_HandleCreateJpnText_Page2: return CinematicBgInstr_HandleCreateJpnText_Page2(k, j); + case fnCinematicBgInstr_SpawnMarkerWaitInput_Page2: return CinematicBgInstr_SpawnMarkerWaitInput_Page2(k, j); + case fnCinematicBgInstr_HandleCreateJpnText_Page3: return CinematicBgInstr_HandleCreateJpnText_Page3(k, j); + case fnCinematicBgInstr_SpawnMarkerWaitInput_Page3: return CinematicBgInstr_SpawnMarkerWaitInput_Page3(k, j); + case fnCinematicBgInstr_HandleCreateJpnText_Page4: return CinematicBgInstr_HandleCreateJpnText_Page4(k, j); + case fnCinematicBgInstr_SpawnMarkerWaitInput_Page4: return CinematicBgInstr_SpawnMarkerWaitInput_Page4(k, j); + case fnCinematicBgInstr_HandleCreateJpnText_Page5: return CinematicBgInstr_HandleCreateJpnText_Page5(k, j); + case fnCinematicBgInstr_SpawnMarkerWaitInput_Page5: return CinematicBgInstr_SpawnMarkerWaitInput_Page5(k, j); + case fnCinematicBgInstr_Func16: return CinematicBgInstr_Func16(k, j); + case fnCinematicBgInstr_Func17: return CinematicBgInstr_Func17(k, j); + case fnCinematicCommonInstr_Func69: return CinematicCommonInstr_Func69(k, j); + case fnCinematicCommonInstr_Func70: return CinematicCommonInstr_Func70(k, j); + case fnCalcItemPercentageCount: return CalcItemPercentageCount(k, j); + case fnCinematicFunction_Intro_Func146: return CinematicFunction_Intro_Func146(k, j); + case fnCinematicFunction_Intro_Func147: return CinematicFunction_Intro_Func147(k, j); + + default: return Unreachable(); + } +} + +void CallCinematicSpriteObjectSetup(uint32 ea, uint16 j) { + switch (ea) { + case fnCinematicFunction_nullsub_116: return; + case fnCinematicSpriteInit_7: CinematicSpriteInit_7(j); return; + case fnCinematicSpriteInit_8: CinematicSpriteInit_8(j); return; + case fnCinematicSpriteInit_9: CinematicSpriteInit_9(j); return; + case fnCinematicSpriteInit_0: CinematicSpriteInit_0(j); return; + case fnCinematicSpriteInit_1: CinematicSpriteInit_1(j); return; + case fnCinematicSpriteInit_2: CinematicSpriteInit_2(j); return; + case fnCinematicSpriteInit_3: CinematicSpriteInit_3(j); return; + case fnCinematicSpriteInit_4: CinematicSpriteInit_4(j); return; + case fnCinematicSpriteInit_5: CinematicSpriteInit_5(j); return; + case fnCinematicSpriteInit_6: CinematicSpriteInit_6(j); return; + case fnSetSomeStuffForSpriteObject_2: SetSomeStuffForSpriteObject_2(j); return; + case fnSetSomeStuffForSpriteObject_3: SetSomeStuffForSpriteObject_3(j); return; + case fnSetSomeStuffForSpriteObject_6: SetSomeStuffForSpriteObject_6(j); return; + case fnSetSomeStuffForSpriteObject_8: SetSomeStuffForSpriteObject_8(j); return; + case fnSetSomeStuffForSpriteObject_10: SetSomeStuffForSpriteObject_10(j); return; + case fnSetSomeStuffForSpriteObject_12: SetSomeStuffForSpriteObject_12(j); return; + case fnSetSomeStuffForSpriteObject_17: SetSomeStuffForSpriteObject_17(j); return; + case fnCinematicFunction_Intro_Func35: CinematicFunction_Intro_Func35(j); return; + case fnCinematicFunction_Intro_Func42: CinematicFunction_Intro_Func42(j); return; + case fnCinematicFunction_Intro_Func46: CinematicFunction_Intro_Func46(j); return; + case fnCinematicFunction_Intro_Func47: CinematicFunction_Intro_Func47(j); return; + case fnCinematicFunction_Intro_Func49: CinematicFunction_Intro_Func49(j); return; + case fnCinematicFunction_Intro_Func57: CinematicFunction_Intro_Func57(j); return; + case fnCinematicFunction_Intro_Func59: CinematicFunction_Intro_Func59(j); return; + case fnCinematicFunction_Intro_Func61: CinematicFunction_Intro_Func61(j); return; + case fnCinematicFunction_Intro_Func63: CinematicFunction_Intro_Func63(j); return; + case fnCinematicFunction_Intro_Func65: CinematicFunction_Intro_Func65(j); return; + case fnCinematicFunction_Intro_Func68: CinematicFunction_Intro_Func68(j); return; + case fnCinematicFunction_Intro_Func71: CinematicFunction_Intro_Func71(j); return; + case fnCinematicFunction_Intro_Func78: CinematicFunction_Intro_Func78(j); return; + case fnCinematicFunction_Intro_Func80: CinematicFunction_Intro_Func80(j); return; + case fnCinematicFunction_Intro_Func81: CinematicFunction_Intro_Func81(j); return; + case fnCinematicFunction_Intro_Func83: CinematicFunction_Intro_Func83(j); return; + case fnCinematicFunction_Intro_Func89: CinematicFunction_Intro_Func89(j); return; + case fnCinematicFunction_Intro_Func92: CinematicFunction_Intro_Func92(j); return; + case fnCinematicFunction_Intro_Func98: CinematicFunction_Intro_Func98(j); return; + case fnCinematicFunction_Intro_Func99: CinematicFunction_Intro_Func99(j); return; + case fnCinematicFunction_Intro_Func100: CinematicFunction_Intro_Func100(j); return; + case fnCinematicFunction_Intro_Func101: CinematicFunction_Intro_Func101(j); return; + case fnCinematicFunction_Intro_Func102: CinematicFunction_Intro_Func102(j); return; + case fnCinematicFunction_Intro_Func104: CinematicFunction_Intro_Func104(j); return; + case fnCinematicFunction_Intro_Func150: CinematicFunction_Intro_Func150(j); return; + case fnCinematicFunction_Intro_Func152: CinematicFunction_Intro_Func152(j); return; + case fnCinematicFunction_Intro_Func153: CinematicFunction_Intro_Func153(j); return; + case fnCinematicFunction_Intro_Func154: CinematicFunction_Intro_Func154(j); return; + case fnCinematicFunction_Intro_Func155: CinematicFunction_Intro_Func155(j); return; + case fnCinematicFunction_Intro_Func156: CinematicFunction_Intro_Func156(j); return; + case fnCinematicFunction_Intro_Func157: CinematicFunction_Intro_Func157(j); return; + case fnCinematicFunction_Intro_Func159: CinematicFunction_Intro_Func159(j); return; + case fnCinematicFunction_Intro_Func161: CinematicFunction_Intro_Func161(j); return; + case fnCinematicFunction_Intro_Func162: CinematicFunction_Intro_Func162(j); return; + case fnCinematicFunction_Intro_Func163: CinematicFunction_Intro_Func163(j); return; + case fnCinematicFunction_Intro_Func164: CinematicFunction_Intro_Func164(j); return; + case fnCinematicFunction_Intro_Func165: CinematicFunction_Intro_Func165(j); return; + case fnCinematicFunction_Intro_Func166: CinematicFunction_Intro_Func166(j); return; + case fnCinematicFunction_Intro_Func167: CinematicFunction_Intro_Func167(j); return; + case fnCinematicFunction_Intro_Func168: CinematicFunction_Intro_Func168(j); return; + case fnCinematicFunction_Intro_Func169: CinematicFunction_Intro_Func169(j); return; + case fnCinematicFunction_Intro_Func170: CinematicFunction_Intro_Func170(j); return; + case fnCinematicFunction_Intro_Func171: CinematicFunction_Intro_Func171(j); return; + case fnCinematicFunction_Intro_Func172: CinematicFunction_Intro_Func172(j); return; + case fnCinematicFunction_Intro_Func173: CinematicFunction_Intro_Func173(j); return; + case fnCinematicFunction_Intro_Func174: CinematicFunction_Intro_Func174(j); return; + case fnCinematicFunction_Intro_Func175: CinematicFunction_Intro_Func175(j); return; + case fnCinematicFunction_Intro_Func176: CinematicFunction_Intro_Func176(j); return; + case fnCinematicFunction_Intro_Func177: CinematicFunction_Intro_Func177(j); return; + case fnCinematicFunction_Intro_Func178: CinematicFunction_Intro_Func178(j); return; + default: Unreachable(); + } +} + +uint16 CallIntroObjectInstr(uint32 ea, uint16 k, uint16 j) { + switch (ea) { + case fnIntroObject_Delete: return IntroObject_Delete(k, j); + case fnIntroObject_Goto: return IntroObject_Goto(k, j); + case fnIntroObject_DecTimerGoto: return IntroObject_DecTimerGoto(k, j); + case fnIntroObject_SetTimer: return IntroObject_SetTimer(k, j); + case fnCinematicFunction_Intro_Func219: return CinematicFunction_Intro_Func219(k, j); + default: return Unreachable(); + } +} + +void CallCinematicSpriteInit(uint32 ea, uint16 j) { + switch (ea) { + case fnCinematicSpriteInit_7: CinematicSpriteInit_7(j); return; + case fnCinematicSpriteInit_8: CinematicSpriteInit_8(j); return; + case fnCinematicSpriteInit_9: CinematicSpriteInit_9(j); return; + case fnCinematicSpriteInit_0: CinematicSpriteInit_0(j); return; + case fnCinematicSpriteInit_1: CinematicSpriteInit_1(j); return; + case fnCinematicSpriteInit_2: CinematicSpriteInit_2(j); return; + case fnCinematicSpriteInit_3: CinematicSpriteInit_3(j); return; + case fnCinematicSpriteInit_4: CinematicSpriteInit_4(j); return; + case fnCinematicSpriteInit_5: CinematicSpriteInit_5(j); return; + case fnCinematicSpriteInit_6: CinematicSpriteInit_6(j); return; + case fnCinematicFunction_nullsub_116: return; + default: Unreachable(); + } +} + +uint16 CallMode7Instr(uint32 ea, uint16 k, uint16 j) { + switch (ea) { + case fnMode7Instr_Delete: return Mode7Instr_Delete(k, j); + case fnMode7Instr_SetPreInstr: return Mode7Instr_SetPreInstr(k, j); + case fnMode7Instr_ClearPreInstr: return Mode7Instr_ClearPreInstr(k, j); + case fnMode7Instr_Goto: return Mode7Instr_Goto(k, j); + case fnMode7Instr_DecTimerAndGoto: return Mode7Instr_DecTimerAndGoto(k, j); + case fnMode7Instr_SetTimer: return Mode7Instr_SetTimer(k, j); + case fnPlayBabyMetroidCry1: return PlayBabyMetroidCry1(k, j); + case fnPlayBabyMetroidCry2: return PlayBabyMetroidCry2(k, j); + case fnPlayBabyMetroidCry3: return PlayBabyMetroidCry3(k, j); + case fnCinematicSetPal1: return CinematicSetPal1(k, j); + case fnCinematicSetPal2: return CinematicSetPal2(k, j); + case fnCinematicSetPal3: return CinematicSetPal3(k, j); + case fnCinematicSetPal4: return CinematicSetPal4(k, j); + case fnsub_8BB51E: return sub_8BB51E(k, j); + case fnEnableCinematicBgTilemapUpdates__0: return EnableCinematicBgTilemapUpdates__0(k, j); + case fnCinematicFunction_Intro_Func21: return CinematicFunction_Intro_Func21(k, j); + case fnCinematicFunction_Intro_ThenWaitInputSetupBabyMetroid: return CinematicFunction_Intro_ThenWaitInputSetupBabyMetroid(k, j); + case fnCinematicFunction_Intro_Func23: return CinematicFunction_Intro_Func23(k, j); + case fnCinematicFunction_Intro_Func25: return CinematicFunction_Intro_Func25(k, j); + case fnCinematicFunction_Intro_Func26: return CinematicFunction_Intro_Func26(k, j); + case fnCinematicFunction_Intro_Func28: return CinematicFunction_Intro_Func28(k, j); + case fnCinematicFunction_Intro_Func29: return CinematicFunction_Intro_Func29(k, j); + case fnCinematicFunction_Intro_Func31: return CinematicFunction_Intro_Func31(k, j); + case fnCinematicFunction_Intro_Func32: return CinematicFunction_Intro_Func32(k, j); + case fnEnableCinematicBgTilemapUpdates__: return EnableCinematicBgTilemapUpdates__(k, j); + default: return Unreachable(); + } +} + +void CallMode7PreInstr(uint32 ea, uint16 k) { + switch (ea) { + case fnCinematicFunction_nullsub_116: return; + case fnCinematicFunction_Intro_Func22: CinematicFunction_Intro_Func22(k); return; + case fnCinematicFunction_Intro_Func24: CinematicFunction_Intro_Func24(k); return; + case fnCinematicFunction_Intro_Func27: CinematicFunction_Intro_Func27(k); return; + case fnCinematicFunction_Intro_Func30: CinematicFunction_Intro_Func30(k); return; + default: Unreachable(); + } +} diff --git a/src/sm_8d.c b/src/sm_8d.c index a750b02..b9f73ef 100644 --- a/src/sm_8d.c +++ b/src/sm_8d.c @@ -4,15 +4,16 @@ #include "funcs.h" - - +void CallPalfxFunc(uint32 ea, uint16 k, uint16 j); +PairU16 CallPalInstr(uint32 ea, uint16 k, uint16 j); +void CallPalFxPreInstr(uint32 ea, uint16 k); void EnablePaletteFx(void) { // 0x8DC4C2 - flag_for_palette_fx_objects |= 0x8000u; + flag_for_palette_fx_objects |= 0x8000; } void DisablePaletteFx(void) { // 0x8DC4CD - flag_for_palette_fx_objects &= ~0x8000u; + flag_for_palette_fx_objects &= ~0x8000; } void ClearPaletteFXObjects(void) { // 0x8DC4D8 @@ -20,23 +21,13 @@ void ClearPaletteFXObjects(void) { // 0x8DC4D8 palettefx_ids[i >> 1] = 0; } -void CallPalfxFunc(uint32 ea, uint16 k, uint16 j) { - switch (ea) { - case fnnullsub_131: return; - case fnPalInit_E1BC: PalInit_E1BC(k, j); return; - case fnPalInit_F761_Norfair1: PalInit_F761_Norfair1(k, j); return; - case fnPalInit_F779_Brinstar8: PalInit_F779_Brinstar8(k, j); return; - default: Unreachable(); - } -} - void SpawnPalfxObject(uint16 j) { // 0x8DC4E9 PalFxDef *PalFxDef; uint16 v1 = 14; while (palettefx_ids[v1 >> 1]) { v1 -= 2; - if ((v1 & 0x8000u) != 0) + if ((v1 & 0x8000) != 0) return; } int v2 = v1 >> 1; @@ -54,7 +45,7 @@ void PalPreInstr_nullsub_129(uint16 k) { // 0x8DC526 } void PaletteFxHandler(void) { // 0x8DC527 - if ((flag_for_palette_fx_objects & 0x8000u) != 0) { + if ((flag_for_palette_fx_objects & 0x8000) != 0) { for (int i = 14; i >= 0; i -= 2) { palettefx_index = i; if (palettefx_ids[i >> 1]) { @@ -65,48 +56,6 @@ void PaletteFxHandler(void) { // 0x8DC527 } } -void CallPalFxPreInstr(uint32 ea, uint16 k) { - switch (ea) { - case fnPalPreInstr_nullsub_129: PalPreInstr_nullsub_129(k); return; - case fnPalPreInstr_E1BC: PalPreInstr_E1BC(k); return; - case fnPalPreInstr_CheckEnemy0Health: PalPreInstr_CheckEnemy0Health(k); return; - case fnPalPreInstr_SamusInHeat: PalPreInstr_SamusInHeat(k); return; - case fnPalPreInstr_DeletePalfxIfMinibossDead: PalPreInstr_DeletePalfxIfMinibossDead(k); return; - case fnPalPreInstr_SwitchIfYpos: PalPreInstr_SwitchIfYpos(k); return; - case fnPalPreInstr_SwitchIfYpos2: PalPreInstr_SwitchIfYpos2(k); return; - case fnPalPreInstr_F621: PalPreInstr_F621(k); return; - default: Unreachable(); - } -} - -PairU16 CallPalInstr(uint32 ea, uint16 k, uint16 j) { - switch (ea) { - case fnPalInstr_Finish: return PalInstr_Finish(k, j); - case fnPalInstr_ColorPlus2: return PalInstr_ColorPlus2(k, j); - case fnPalInstr_ColorPlus3: return PalInstr_ColorPlus3(k, j); - case fnPalInstr_ColorPlus4: return PalInstr_ColorPlus4(k, j); - case fnPalInstr_ColorPlus8: return PalInstr_ColorPlus8(k, j); - case fnPalInstr_ColorPlus9: return PalInstr_ColorPlus9(k, j); - case fnPalInstr_ColorPlus15: return PalInstr_ColorPlus15(k, j); - case fnPalInstr_Delete: return PalInstr_Delete(k, j); - case fnPalInstr_SetPreInstr: return PalInstr_SetPreInstr(k, j); - case fnPalInstr_ClearPreInstr: return PalInstr_ClearPreInstr(k, j); - case fnPalInstr_Goto: return PalInstr_Goto(k, j); - case fnPalInstr_GotoRel: return PalInstr_GotoRel(k, j); - case fnPalInstr_DecTimerGoto: return PalInstr_DecTimerGoto(k, j); - case fnPalInstr_DecTimerGotoRel: return PalInstr_DecTimerGotoRel(k, j); - case fnPalInstr_SetTimer: return PalInstr_SetTimer(k, j); - case fnPalInstr_SetColorIndex: return PalInstr_SetColorIndex(k, j); - case fnPalInstr_QueueMusic: return PalInstr_QueueMusic(k, j); - case fnPalInstr_QueueSfx1: return PalInstr_QueueSfx1(k, j); - case fnPalInstr_QueueSfx2: return PalInstr_QueueSfx2(k, j); - case fnPalInstr_QueueSfx3: return PalInstr_QueueSfx3(k, j); - case fnPalInstr_SetTimerIfBossBit: return PalInstr_SetTimerIfBossBit(k, j); - case fnPalInstr_SetPalfxIndex: return PalInstr_SetPalfxIndex(k, j); - default: Unreachable(); return (PairU16){0, 0}; - } -} - void PalFx_ProcessOne(uint16 k) { // 0x8DC54A PairU16 v7; int16 v11; @@ -120,9 +69,8 @@ void PalFx_ProcessOne(uint16 k) { // 0x8DC54A while (1) { const uint16 *v5 = (const uint16 *)RomPtr_8D(j); v6 = *v5; - if ((*v5 & 0x8000u) == 0) + if ((*v5 & 0x8000) == 0) break; - R18_ = *v5; v7 = CallPalInstr(v6 | 0x8D0000, v1, j + 2); v1 = v7.k; j = v7.j; @@ -143,7 +91,6 @@ void PalFx_ProcessOne(uint16 k) { // 0x8DC54A v9 += 2; j += 2; } - R18_ = GET_WORD(v10 + 2); v12 = CallPalInstr((uint16)v11 | 0x8D0000, v9, j); v9 = v12.k; j = v12.j; @@ -201,7 +148,6 @@ PairU16 PalInstr_Goto(uint16 k, uint16 j) { // 0x8DC61E } PairU16 PalInstr_GotoRel(uint16 k, uint16 j) { // 0x8DC623 - R18_ = j; return MakePairU16(k, j + (int8)*RomPtr_8D(j)); } @@ -281,8 +227,8 @@ void PalPreInstr_SamusInHeat(uint16 k) { // 0x8DE379 uint16 v1 = (__PAIR32__(samus_periodic_damage, samus_periodic_subdamage) + 0x4000) >> 16; samus_periodic_subdamage += 0x4000; samus_periodic_damage = v1; - if ((nmi_frame_counter_word & 7) == 0 && samus_health > 0x46u) - QueueSfx3_Max6(0x2Du); + if ((nmi_frame_counter_word & 7) == 0 && samus_health > 0x46) + QueueSfx3_Max6(0x2D); } if (samus_in_heat_palfx_index != samus_in_heat_palettefx_prev_index) { samus_in_heat_palettefx_prev_index = samus_in_heat_palfx_index; @@ -296,7 +242,6 @@ void PalPreInstr_SamusInHeat(uint16 k) { // 0x8DE379 } else { v4 = addr_off_8DE420; } - R18_ = v4; palettefx_instr_list_ptrs[v3] = *(uint16 *)&RomPtr_8D(v4)[v2]; } } @@ -314,7 +259,7 @@ void PalInit_F761_Norfair1(uint16 k, uint16 j) { // 0x8DE440 } PairU16 PalInstr_SetTimerIfBossBit(uint16 k, uint16 j) { // 0x8DEB2A - if (!(CheckBossBitForCurArea(1u) & 1)) { + if (!(CheckBossBitForCurArea(1) & 1)) { palettefx_instr_timers[k >> 1] = 1; return MakePairU16(k, 0); } @@ -322,7 +267,7 @@ PairU16 PalInstr_SetTimerIfBossBit(uint16 k, uint16 j) { // 0x8DEB2A } void PalPreInstr_SwitchIfYpos(uint16 k) { // 0x8DEC59 - if (samus_y_pos < 0x380u) { + if (samus_y_pos < 0x380) { int v2 = k >> 1; palettefx_instr_timers[v2] = 1; palettefx_instr_list_ptrs[v2] = addr_word_8DEB43; @@ -330,7 +275,7 @@ void PalPreInstr_SwitchIfYpos(uint16 k) { // 0x8DEC59 } void PalPreInstr_SwitchIfYpos2(uint16 k) { // 0x8DED84 - if (samus_y_pos < 0x380u) { + if (samus_y_pos < 0x380) { int v2 = k >> 1; palettefx_instr_timers[v2] = 1; palettefx_instr_list_ptrs[v2] = addr_word_8DEC76; @@ -355,4 +300,56 @@ void PalPreInstr_F621(uint16 k) { // 0x8DF621 void PalInit_F779_Brinstar8(uint16 k, uint16 j) { // 0x8DF730 if ((*(uint16 *)&boss_bits_for_area[area_index] & 2) != 0) palettefx_ids[j >> 1] = 0; -} \ No newline at end of file +} + +void CallPalFxPreInstr(uint32 ea, uint16 k) { + switch (ea) { + case fnPalPreInstr_nullsub_129: PalPreInstr_nullsub_129(k); return; + case fnPalPreInstr_E1BC: PalPreInstr_E1BC(k); return; + case fnPalPreInstr_CheckEnemy0Health: PalPreInstr_CheckEnemy0Health(k); return; + case fnPalPreInstr_SamusInHeat: PalPreInstr_SamusInHeat(k); return; + case fnPalPreInstr_DeletePalfxIfMinibossDead: PalPreInstr_DeletePalfxIfMinibossDead(k); return; + case fnPalPreInstr_SwitchIfYpos: PalPreInstr_SwitchIfYpos(k); return; + case fnPalPreInstr_SwitchIfYpos2: PalPreInstr_SwitchIfYpos2(k); return; + case fnPalPreInstr_F621: PalPreInstr_F621(k); return; + default: Unreachable(); + } +} + +PairU16 CallPalInstr(uint32 ea, uint16 k, uint16 j) { + switch (ea) { + case fnPalInstr_Finish: return PalInstr_Finish(k, j); + case fnPalInstr_ColorPlus2: return PalInstr_ColorPlus2(k, j); + case fnPalInstr_ColorPlus3: return PalInstr_ColorPlus3(k, j); + case fnPalInstr_ColorPlus4: return PalInstr_ColorPlus4(k, j); + case fnPalInstr_ColorPlus8: return PalInstr_ColorPlus8(k, j); + case fnPalInstr_ColorPlus9: return PalInstr_ColorPlus9(k, j); + case fnPalInstr_ColorPlus15: return PalInstr_ColorPlus15(k, j); + case fnPalInstr_Delete: return PalInstr_Delete(k, j); + case fnPalInstr_SetPreInstr: return PalInstr_SetPreInstr(k, j); + case fnPalInstr_ClearPreInstr: return PalInstr_ClearPreInstr(k, j); + case fnPalInstr_Goto: return PalInstr_Goto(k, j); + case fnPalInstr_GotoRel: return PalInstr_GotoRel(k, j); + case fnPalInstr_DecTimerGoto: return PalInstr_DecTimerGoto(k, j); + case fnPalInstr_DecTimerGotoRel: return PalInstr_DecTimerGotoRel(k, j); + case fnPalInstr_SetTimer: return PalInstr_SetTimer(k, j); + case fnPalInstr_SetColorIndex: return PalInstr_SetColorIndex(k, j); + case fnPalInstr_QueueMusic: return PalInstr_QueueMusic(k, j); + case fnPalInstr_QueueSfx1: return PalInstr_QueueSfx1(k, j); + case fnPalInstr_QueueSfx2: return PalInstr_QueueSfx2(k, j); + case fnPalInstr_QueueSfx3: return PalInstr_QueueSfx3(k, j); + case fnPalInstr_SetTimerIfBossBit: return PalInstr_SetTimerIfBossBit(k, j); + case fnPalInstr_SetPalfxIndex: return PalInstr_SetPalfxIndex(k, j); + default: Unreachable(); return (PairU16) { 0, 0 }; + } +} + +void CallPalfxFunc(uint32 ea, uint16 k, uint16 j) { + switch (ea) { + case fnnullsub_131: return; + case fnPalInit_E1BC: PalInit_E1BC(k, j); return; + case fnPalInit_F761_Norfair1: PalInit_F761_Norfair1(k, j); return; + case fnPalInit_F779_Brinstar8: PalInit_F779_Brinstar8(k, j); return; + default: Unreachable(); + } +} diff --git a/src/sm_8f.c b/src/sm_8f.c index 32e6551..ff8d94c 100644 --- a/src/sm_8f.c +++ b/src/sm_8f.c @@ -4,31 +4,28 @@ #include "sm_rtl.h" #include "funcs.h" +void CallDoorDefSetupCode(uint32 ea); +void CallRoomSetupCode(uint32 ea); +void RoomCode_GenRandomExplodes(uint16 x_r18, uint16 y_r20); - - - -static const SpawnHardcodedPlmArgs unk_8F9198 = { 0x3d, 0x0b, 0xbb30 }; -static const SpawnHardcodedPlmArgs unk_8F91AD = { 0x10, 0x87, 0xb964 }; -static const SpawnHardcodedPlmArgs unk_8F91B6 = { 0x0f, 0x0a, 0xb9ed }; void RoomSetup_AfterSavingAnimals(void) { // 0x8F9194 - SpawnHardcodedPlm(&unk_8F9198); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x3d, 0x0b, 0xbb30 }); earthquake_type = 24; earthquake_timer = -1; } void RoomSetup_AutoDestroyWallAfterEscape(void) { // 0x8F91A9 - SpawnHardcodedPlm(&unk_8F91AD); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x10, 0x87, 0xb964 }); } void RoomSetup_TurnWallIntoShotblocks(void) { // 0x8F91B2 - SpawnHardcodedPlm(&unk_8F91B6); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0f, 0x0a, 0xb9ed }); } void RoomSetup_ShakeDuringEscape(void) { // 0x8F91BD earthquake_type = 6; earthquake_timer = -1; - RoomSetup_ScrollingSkyLand(); + FxTypeFunc_20(); } void RoomSetup_ScrollingSkyLand(void) { // 0x8F91C9 @@ -48,9 +45,7 @@ void RoomSetup_RunStatueUnlockAnims(void) { // 0x8F91D7 void DoorCode_StartWreckedShipTreadmillWest(void) { // 0x8FB971 SpawnAnimtiles(addr_kAnimtiles_WreckedShipTradmillRight); - - static const SpawnHardcodedPlmArgs unk_8FB97C = { 0x04, 0x09, 0xb64b }; - SpawnHardcodedPlm(&unk_8FB97C); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x04, 0x09, 0xb64b }); } void DoorCode_Scroll6_Green(void) { // 0x8FB981 @@ -338,60 +333,52 @@ void RoomCode_ScrollingSkyOcean_(void) { // 0x8FC11B RoomMainAsm_ScrollingSkyOcean(); } +void RoomCode_GenRandomExplodes_Nonblank(void) { // 0x8FC131 + if (!time_is_frozen_flag && (nmi_frame_counter_word & 1) == 0) { + uint16 Random = NextRandom(); + uint16 x = layer1_x_pos + (uint8)Random; + uint16 y = layer1_y_pos + HIBYTE(Random); + uint16 prod = Mult8x8(y >> 4, room_width_in_blocks); + if ((level_data[prod + (x >> 4)] & 0x3FF) != 255) + RoomCode_GenRandomExplodes(x, y); + } +} + void RoomCode_ScrollingSkyLand_Shakes(void) { // 0x8FC120 RoomCode_ScrollingSkyLand(); RoomCode_GenRandomExplodes_Nonblank(); - earthquake_timer |= 0x8000u; + earthquake_timer |= 0x8000; } void RoomCode_ExplodeShakes(void) { // 0x8FC124 RoomCode_GenRandomExplodes_Nonblank(); - earthquake_timer |= 0x8000u; -} - -void RoomCode_GenRandomExplodes_Nonblank(void) { // 0x8FC131 - int16 v1; - - if (!time_is_frozen_flag && (nmi_frame_counter_word & 1) == 0) { - uint16 Random = NextRandom(); - R18_ = layer1_x_pos + (uint8)Random; - R20_ = layer1_y_pos + HIBYTE(Random); - uint8 v2 = R20_ >> 4; - uint16 prod = Mult8x8(v2, room_width_in_blocks); - v1 = R18_ >> 4; - if ((level_data[prod + v1] & 0x3FF) != 255) - RoomCode_GenRandomExplodes(); - } + earthquake_timer |= 0x8000; } void RoomCode_GenRandomExplodes_4th(void) { // 0x8FC183 if (!time_is_frozen_flag && (nmi_frame_counter_word & 3) == 0) { uint16 Random = NextRandom(); - R18_ = layer1_x_pos + (uint8)Random; - R20_ = layer1_y_pos + HIBYTE(Random); - RoomCode_GenRandomExplodes(); + RoomCode_GenRandomExplodes(layer1_x_pos + (uint8)Random, layer1_y_pos + HIBYTE(Random)); } } -void RoomCode_GenRandomExplodes(void) { // 0x8FC1A9 +void RoomCode_GenRandomExplodes(uint16 x_r18, uint16 y_r20) { // 0x8FC1A9 static const uint8 kRoomCode_GenRandomExplodes_Sprite[8] = { 3, 3, 9, 12, 12, 18, 18, 21 }; static const uint8 kRoomCode_GenRandomExplodes_Sfx[8] = { 0x24, 0, 0, 0x25, 0, 0, 0, 0 }; // Bugfix, X is garbage uint16 v1 = NextRandom() & 0xF; - if (v1 < 8u) { + if (v1 < 8) { uint16 v2 = kRoomCode_GenRandomExplodes_Sfx[v1]; if (v2) QueueSfx2_Max6(v2); } - R22_ = kRoomCode_GenRandomExplodes_Sprite[v1 & 7]; - R24_ = 0; - CreateSpriteAtPos(); + CreateSpriteAtPos(x_r18, y_r20, kRoomCode_GenRandomExplodes_Sprite[v1 & 7], 0); } void RoomCode_ScrollRightDachora(void) { // 0x8FC1E6 - if (scrolls[11] == 2 && layer1_y_pos < 0x500u && layer1_x_pos < 0x380u) - layer1_x_pos += (layer1_x_pos >= 0x380u) + 3; + if (scrolls[11] == 2 && layer1_y_pos < 0x500 && layer1_x_pos < 0x380) + layer1_x_pos += (layer1_x_pos >= 0x380) + 3; } void RoomCode_8FC8C8(void) { // 0x8FC8C8 @@ -399,8 +386,7 @@ void RoomCode_8FC8C8(void) { // 0x8FC8C8 } void RoomCode_SetupShaktoolRoomPlm(void) { // 0x8FC8D3 - static const SpawnHardcodedPlmArgs unk_8FC8D7 = { 0x00, 0x00, 0xb8eb }; - SpawnHardcodedPlm(&unk_8FC8D7); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x00, 0x00, 0xb8eb }); } void RoomCode_SetPauseCodeForDraygon(void) { // 0x8FC8DD @@ -425,7 +411,7 @@ void RoomCode_SetCollectedMap(void) { // 0x8FC90A } void RoomCode_SetZebesTimebombEvent(void) { // 0x8FC91F - SetEventHappened(0xEu); + SetEventHappened(0xE); earthquake_type = 18; earthquake_timer = -1; } @@ -443,8 +429,7 @@ void RoomCode_SetMediumHorizRoomShake(void) { // 0x8FC946 } void RoomCode_Escape4_SetMediumHorizRoomShake(void) { // 0x8FC953 - static const SpawnHardcodedPlmArgs unk_8FC957 = { 0x10, 0x10, 0xb968 }; - SpawnHardcodedPlm(&unk_8FC957); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x10, 0x10, 0xb968 }); earthquake_type = 21; *(uint16 *)&room_main_asm_variables[2] = 21; *(uint16 *)room_main_asm_variables = 0; @@ -452,8 +437,7 @@ void RoomCode_Escape4_SetMediumHorizRoomShake(void) { // 0x8FC953 } void RoomCode_SetCeresDoorSolid(void) { // 0x8FC96E - static const SpawnHardcodedPlmArgs unk_8FC972 = { 0x0f, 0x26, 0xba48 }; - SpawnHardcodedPlm(&unk_8FC972); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0f, 0x26, 0xba48 }); FxTypeFunc_2C_Haze(); } @@ -469,8 +453,7 @@ void RoomCode_CeresColorMathHdma_BgBase(void) { // 0x8FC97B void DoorCode_StartWreckedSkipTreadmill_East(void) { // 0x8FE1D8 SpawnAnimtiles(addr_kAnimtiles_WreckedShipTradmillLeft); - static const SpawnHardcodedPlmArgs unk_8FE1E3 = { 0x04, 0x09, 0xb64f }; - SpawnHardcodedPlm(&unk_8FE1E3); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x04, 0x09, 0xb64f }); } void DoorCode_SetScroll_44(void) { // 0x8FE1E8 @@ -503,14 +486,13 @@ void DoorCode_SetScroll_49(void) { // 0x8FE229 scrolls[10] = 0; scrolls[11] = 0; } -static const SpawnHardcodedPlmArgs unk_8FE28C = { 0x01, 0x00, 0xb8f9 }; -static const SpawnHardcodedPlmArgs unk_8FE2B1 = { 0x01, 0x00, 0xb8f9 }; + void DoorCode_SetupElevatubeFromSouth(void) { // 0x8FE26C *(uint16 *)&room_main_asm_variables[4] = -256; *(uint16 *)&room_main_asm_variables[2] = 2496; *(uint16 *)&room_main_asm_variables[6] = -32; CallSomeSamusCode(0); - SpawnHardcodedPlm(&unk_8FE28C); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x01, 0x00, 0xb8f9 }); } void DoorCode_SetupElevatubeFromNorth(void) { // 0x8FE291 @@ -518,37 +500,30 @@ void DoorCode_SetupElevatubeFromNorth(void) { // 0x8FE291 strcpy((uint8 *)&room_main_asm_variables[2], "@"); strcpy((uint8 *)&room_main_asm_variables[6], " "); CallSomeSamusCode(0); - SpawnHardcodedPlm(&unk_8FE2B1); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x01, 0x00, 0xb8f9 }); } void RoomCode_Elevatube(void) { // 0x8FE2B6 - int16 v0; + uint16 v0; samus_x_pos = 128; samus_x_subpos = 0; - R18_ = 0; - R20_ = 0; - if (*(int16 *)&room_main_asm_variables[4] < 0) - --R20_; - R19_ = *(uint16 *)&room_main_asm_variables[4]; - v0 = (__PAIR32__(R20_, R18_) + *(uint32 *)room_main_asm_variables) >> 16; - *(uint16 *)room_main_asm_variables += R18_; + int32 amt = INT16_SHL8(*(uint16 *)&room_main_asm_variables[4]); + v0 = (amt + *(uint32 *)room_main_asm_variables) >> 16; + *(uint16 *)room_main_asm_variables += amt; *(uint16 *)&room_main_asm_variables[2] = v0; - uint16 v1 = R18_; - R18_ = R20_; - R20_ = v1; - Samus_MoveDown_NoSolidColl(); - if ((uint16)(*(uint16 *)&room_main_asm_variables[6] + *(uint16 *)&room_main_asm_variables[4] + 3616) < 0x1C41u) + Samus_MoveDown_NoSolidColl(amt); + if ((uint16)(*(uint16 *)&room_main_asm_variables[6] + *(uint16 *)&room_main_asm_variables[4] + 3616) < 0x1C41) *(uint16 *)&room_main_asm_variables[4] += *(uint16 *)&room_main_asm_variables[6]; } void DoorCode_ResetElevatubeNorthExit(void) { // 0x8FE301 - CallSomeSamusCode(1u); + CallSomeSamusCode(1); } void DoorCode_ResetElevatubeSouthExit(void) { // 0x8FE309 *(uint16 *)scrolls = 514; - CallSomeSamusCode(1u); + CallSomeSamusCode(1); } void DoorCode_SetScroll_50(void) { // 0x8FE318 @@ -629,7 +604,7 @@ void DoorCode_SetScroll_65(void) { // 0x8FE4CF void DoorCode_CeresElevatorShaft(void) { // 0x8FE4E0 reg_BGMODE_fake = 7; - WriteReg(BGMODE, 7u); + WriteReg(BGMODE, 7); reg_M7A = 256; reg_M7D = 256; reg_M7B = 0; @@ -656,17 +631,13 @@ static const uint16 kRoomCode_SpawnCeresFallingDebris_Tab[16] = { // 0x8FE525 0xd0, 0xe0, 0xf0, 0x110, 0x130, 0x150, 0x170, 0x190, }; -void RoomCode_SpawnCeresFallingDebris(void) { +void RoomCode_SpawnCeresFallingDebris(void) { if (ceres_status && (-- * (uint16 *)room_main_asm_variables, *(int16 *)room_main_asm_variables < 0)) { - strcpy((uint8 *)room_main_asm_variables, "\b"); - uint16 v0 = addr_stru_869734; - if (random_number & 0x8000) - v0 = addr_stru_869742; - SpawnEnemyProjectileWithRoomGfx( - v0, - kRoomCode_SpawnCeresFallingDebris_Tab[random_number & 0xF]); - } else { + room_main_asm_variables[0] = 8; + room_main_asm_variables[1] = 0; + uint16 v0 = (random_number & 0x8000) ? addr_stru_869742 : addr_stru_869734; + SpawnEnemyProjectileWithRoomGfx(v0, kRoomCode_SpawnCeresFallingDebris_Tab[random_number & 0xF]); } } @@ -678,12 +649,12 @@ void RoomCode_HandleCeresRidleyGetaway(void) { // 0x8FE571 void RoomCode_ShakeScreenHorizDiag(void) { // 0x8FE57C uint16 v0; if (*(uint16 *)room_main_asm_variables) { - if (!-- * (uint16 *)room_main_asm_variables) { + if (!--*(uint16 *)room_main_asm_variables) { v0 = 18; LABEL_6: earthquake_type = v0; } - } else if (NextRandom() < 0x200u) { + } else if (NextRandom() < 0x200) { strcpy((uint8 *)room_main_asm_variables, "*"); v0 = 23; goto LABEL_6; @@ -695,12 +666,12 @@ void RoomCode_ShakeScreenHorizDiagStrong(void) { // 0x8FE5A4 int16 v0; if (*(uint16 *)room_main_asm_variables) { - if (!-- * (uint16 *)room_main_asm_variables) { + if (!--*(uint16 *)room_main_asm_variables) { v0 = 21; LABEL_6: *(uint16 *)&room_main_asm_variables[2] = v0; } - } else if (NextRandom() < 0x180u) { + } else if (NextRandom() < 0x180) { strcpy((uint8 *)room_main_asm_variables, "*"); v0 = 26; goto LABEL_6; @@ -743,7 +714,7 @@ uint16 RoomDefStateSelect_Door(uint16 k) { // 0x8FE5EB } uint16 RoomDefStateSelect_TourianBoss01(uint16 k) { // 0x8FE5FF - if (!(CheckBossBitForCurArea(1u) & 1)) + if (!(CheckBossBitForCurArea(1) & 1)) return k + 2; const uint16 *v1 = (const uint16 *)RomPtr_8F(k); return RoomDefStateSelect_Finish(*v1); @@ -818,6 +789,7 @@ void CallRoomSetupCode(uint32 ea) { default: Unreachable(); } } + void RunRoomSetupCode(void) { // 0x8FE88F RoomDefRoomstate *RoomDefRoomstate; @@ -915,14 +887,47 @@ void CallDoorDefSetupCode(uint32 ea) { } void RunDoorSetupCode(void) { // 0x8FE8A3 - DoorDef *DoorDef; - VoidP door_setup_code; + DoorDef *DD = get_DoorDef(door_def_ptr); + if (DD->door_setup_code) + CallDoorDefSetupCode(DD->door_setup_code | 0x8F0000); +} - DoorDef = get_DoorDef(door_def_ptr); - door_setup_code = DoorDef->door_setup_code; - if (door_setup_code) { - R18_ = DoorDef->door_setup_code; - CallDoorDefSetupCode(door_setup_code | 0x8F0000); +void RoomCode_CrocomireShaking(void) { // 0x8FE8CD + uint16 ai_var_D; + + if ((enemy_data[0].properties & 0x200) == 0) { + if (enemy_data[0].ai_var_A == 64) { + reg_BG1VOFS = enemy_data[1].ai_var_D + bg1_y_offset + layer1_y_pos; + } else if ((enemy_data[0].ai_var_B & 0x400) != 0) { + if (sign16(--enemy_data[1].ai_var_D + 7)) { + ai_var_D = enemy_data[1].ai_var_D - 2 * (enemy_data[1].ai_var_D + 7); + } else { + ai_var_D = enemy_data[1].ai_var_D; + } + reg_BG1VOFS += ai_var_D; + reg_BG2VOFS = ai_var_D - 48; + } else if (enemy_data[0].ai_var_C == 34 && enemy_data[0].ai_var_D) { + --enemy_data[0].ai_var_D; + if ((enemy_data[0].ai_var_D & 1) != 0) + layer1_x_pos -= 4; + else + layer1_x_pos += 4; + } + } +} + +static const int16 kRoomCode_RidleyRoomShaking_X[8] = { 0, 2, 2, 2, 0, -2, -2, -2 }; +static const int16 kRoomCode_RidleyRoomShaking_Y[8] = { -2, -2, 0, 2, 2, 2, 0, -2 }; + +void RoomCode_RidleyRoomShaking(void) { // 0x8FE950 + uint16 ai_var_A = enemy_data[4].ai_var_A; + if (enemy_data[4].ai_var_A) { + --enemy_data[4].ai_var_A; + int v1 = ai_var_A - 1; + reg_BG1HOFS += kRoomCode_RidleyRoomShaking_X[v1]; + reg_BG2HOFS += kRoomCode_RidleyRoomShaking_X[v1]; + reg_BG1VOFS += kRoomCode_RidleyRoomShaking_Y[v1]; + reg_BG2VOFS += kRoomCode_RidleyRoomShaking_Y[v1]; } } @@ -951,44 +956,3 @@ void RunRoomMainCode(void) { // 0x8FE8BD if (room_main_code_ptr) CallRoomCode(room_main_code_ptr | 0x8F0000); } - -void RoomCode_CrocomireShaking(void) { // 0x8FE8CD - uint16 ai_var_D; - - if ((enemy_data[0].properties & 0x200) == 0) { - if (enemy_data[0].ai_var_A == 64) { - reg_BG1VOFS = enemy_data[1].ai_var_D + bg1_y_offset + layer1_y_pos; - } else if ((enemy_data[0].ai_var_B & 0x400) != 0) { - if (sign16(--enemy_data[1].ai_var_D + 7)) { - R18_ = 2 * (enemy_data[1].ai_var_D + 7); - ai_var_D = enemy_data[1].ai_var_D - R18_; - } else { - ai_var_D = enemy_data[1].ai_var_D; - } - R18_ = ai_var_D; - reg_BG1VOFS += ai_var_D; - reg_BG2VOFS = ai_var_D - 48; - } else if (enemy_data[0].ai_var_C == 34 && enemy_data[0].ai_var_D) { - --enemy_data[0].ai_var_D; - if ((enemy_data[0].ai_var_D & 1) != 0) - layer1_x_pos -= 4; - else - layer1_x_pos += 4; - } - } -} - -static const int16 kRoomCode_RidleyRoomShaking_X[8] = { 0, 2, 2, 2, 0, -2, -2, -2 }; -static const int16 kRoomCode_RidleyRoomShaking_Y[8] = { -2, -2, 0, 2, 2, 2, 0, -2 }; - -void RoomCode_RidleyRoomShaking(void) { // 0x8FE950 - uint16 ai_var_A = enemy_data[4].ai_var_A; - if (enemy_data[4].ai_var_A) { - --enemy_data[4].ai_var_A; - int v1 = ai_var_A - 1; - reg_BG1HOFS += kRoomCode_RidleyRoomShaking_X[v1]; - reg_BG2HOFS += kRoomCode_RidleyRoomShaking_X[v1]; - reg_BG1VOFS += kRoomCode_RidleyRoomShaking_Y[v1]; - reg_BG2VOFS += kRoomCode_RidleyRoomShaking_Y[v1]; - } -} \ No newline at end of file diff --git a/src/sm_90.c b/src/sm_90.c index 61928b8..550151a 100644 --- a/src/sm_90.c +++ b/src/sm_90.c @@ -5,7 +5,6 @@ #include "sm_rtl.h" #include "funcs.h" - #define kSamusFramesForUnderwaterSfx ((uint8*)RomFixedPtr(0x90a514)) #define kPauseMenuMapData ((uint16*)RomFixedPtr(0x829717)) #define kPauseMenuMapTilemaps ((LongPtr*)RomFixedPtr(0x82964a)) @@ -15,7 +14,7 @@ #define off_90B609 ((uint16*)RomFixedPtr(0x90b609)) #define kFlareAnimDelays ((uint16*)RomFixedPtr(0x90c481)) - +static Pair_Bool_Amt Samus_CalcBaseSpeed_NoDecel_X(uint16 k); static const uint16 kUnchargedProjectile_Sfx[12] = { 0xb, 0xd, 0xc, 0xe, 0xf, 0x12, 0x10, 0x11, 0x13, 0x16, 0x14, 0x15 }; static const uint16 kChargedProjectile_Sfx[12] = { 0x17, 0x19, 0x18, 0x1a, 0x1b, 0x1e, 0x1c, 0x1d, 0x1f, 0x22, 0x20, 0x21 }; @@ -28,6 +27,8 @@ static const uint8 kProjectileCooldown_Uncharged[38] = { static const uint8 kNonBeamProjectileCooldowns[9] = { 0, 0xa, 0x14, 0x28, 0, 0x10, 0, 0, 0 }; static const uint8 kBeamAutoFireCooldowns[12] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 }; +static void Samus_HandleAnimDelay(void); + void nullsub_12(void) {} static Func_V *const kSamusFxHandlers[8] = { @@ -42,18 +43,17 @@ static Func_V *const kSamusFxHandlers[8] = { }; void Samus_Animate(void) { // 0x908000 - Samus_GetTopBottomBoundary(); - kSamusFxHandlers[(uint8)(fx_type & 0xF) >> 1](); + kSamusFxHandlers[(fx_type & 0xF) >> 1](); if (samus_pose == kPose_4D_FaceR_Jump_NoAim_NoMove_NoGun || samus_pose == kPose_4E_FaceL_Jump_NoAim_NoMove_NoGun) { if (samus_y_dir != 2 && samus_anim_frame == 1 && samus_anim_frame_timer == 1) samus_anim_frame_timer = 4; - bool v1 = (--samus_anim_frame_timer & 0x8000u) != 0; + bool v1 = (--samus_anim_frame_timer & 0x8000) != 0; if (!samus_anim_frame_timer || v1) { ++samus_anim_frame; Samus_HandleAnimDelay(); } } else { - bool v0 = (--samus_anim_frame_timer & 0x8000u) != 0; + bool v0 = (--samus_anim_frame_timer & 0x8000) != 0; if (!samus_anim_frame_timer || v0) { ++samus_anim_frame; Samus_HandleAnimDelay(); @@ -62,14 +62,15 @@ void Samus_Animate(void) { // 0x908000 } void Samus_Animate_NoFx(void) { // 0x908078 + uint16 r18 = Samus_GetBottom_R18(); samus_anim_frame_buffer = samus_x_speed_divisor; if (liquid_physics_type) { if ((liquid_physics_type & 1) != 0) { liquid_physics_type = 0; - QueueSfx2_Max6(0xEu); + QueueSfx2_Max6(0xE); if ((samus_suit_palette_index & 4) == 0 && (samus_movement_type == 3 || samus_movement_type == 20)) - QueueSfx1_Max6(0x30u); - Samus_SpawnWaterSplash(); + QueueSfx1_Max6(0x30); + Samus_SpawnWaterSplash(r18); } else { liquid_physics_type = 0; } @@ -78,21 +79,22 @@ void Samus_Animate_NoFx(void) { // 0x908078 void Samus_Animate_WaterFx(void) { // 0x9080B8 static const uint16 kSamusPhys_AnimDelayInWater = 3; - if ((fx_y_pos & 0x8000u) == 0 && sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) == 0 && sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { samus_anim_frame_buffer = kSamusPhys_AnimDelayInWater; if (liquid_physics_type == kLiquidPhysicsType_Water) { Samus_SpawnAirBubbles(); } else { liquid_physics_type = kLiquidPhysicsType_Water; - QueueSfx2_Max6(0xDu); - Samus_SpawnWaterSplash(); + QueueSfx2_Max6(0xD); + Samus_SpawnWaterSplash(r18); } } else { Samus_Animate_NoFx(); } } -void Samus_SpawnWaterSplash(void) { // 0x9080E6 +void Samus_SpawnWaterSplash(uint16 r18) { // 0x9080E6 static const uint8 kWaterSplashTypeTable[28] = { 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, @@ -104,8 +106,8 @@ void Samus_SpawnWaterSplash(void) { // 0x9080E6 atmospheric_gfx_anim_timer[1] = 3; atmospheric_gfx_x_pos[0] = samus_x_pos + 4; atmospheric_gfx_x_pos[1] = samus_x_pos - 3; - atmospheric_gfx_y_pos[0] = R18_ - 4; - atmospheric_gfx_y_pos[1] = R18_ - 4; + atmospheric_gfx_y_pos[0] = r18 - 4; + atmospheric_gfx_y_pos[1] = r18 - 4; } else { atmospheric_gfx_frame_and_type[0] = 768; atmospheric_gfx_anim_timer[0] = 2; @@ -115,24 +117,17 @@ void Samus_SpawnWaterSplash(void) { // 0x9080E6 Samus_SpawnAirBubbles(); } -void Samus_SpawnAirBubbles(void) { // 0x90813E - uint16 v0; - - if ((int16)(R20_ - 24 - fx_y_pos) >= 0 - && (nmi_frame_counter_word & 0x7F) == 0 +void Samus_SpawnAirBubbles() { // 0x90813E + uint16 r20 = Samus_GetTop_R20(); + if ((int16)(r20 - 24 - fx_y_pos) >= 0 && (nmi_frame_counter_word & 0x7F) == 0 && !atmospheric_gfx_frame_and_type[2]) { atmospheric_gfx_frame_and_type[2] = 1280; atmospheric_gfx_anim_timer[2] = 3; atmospheric_gfx_x_pos[2] = samus_x_pos; atmospheric_gfx_y_pos[2] = samus_y_pos - samus_y_radius + 6; - if ((NextRandom() & 1) != 0) - v0 = 15; - else - v0 = 17; - QueueSfx2_Max6(v0); + QueueSfx2_Max6((NextRandom() & 1) ? 15 : 17); } - if (samus_pose == kPose_00_FaceF_Powersuit - || samus_pose == kPose_9B_FaceF_VariaGravitySuit + if (samus_pose == kPose_00_FaceF_Powersuit || samus_pose == kPose_9B_FaceF_VariaGravitySuit || (equipped_items & 0x20) != 0) { samus_anim_frame_buffer = 0; } @@ -142,8 +137,8 @@ void Samus_Animate_LavaFx(void) { // 0x9081C0 static const uint16 kSamusPhys_LavaDamagePerFrame = 0; static const uint16 kSamusPhys_LavaSubdamagePerFrame = 0x8000; - - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) { + uint16 r18 = Samus_GetBottom_R18(); + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) { if (speed_boost_counter) { Samus_CancelSpeedBoost(); samus_x_extra_run_speed = 0; @@ -154,7 +149,7 @@ void Samus_Animate_LavaFx(void) { // 0x9081C0 liquid_physics_type = 2; } else { if ((game_time_frames & 7) == 0 && !sign16(samus_health - 71)) - QueueSfx3_Max3(0x2Du); + QueueSfx3_Max3(0x2D); uint16 v0 = (__PAIR32__(kSamusPhys_LavaDamagePerFrame, kSamusPhys_LavaSubdamagePerFrame) + __PAIR32__(samus_periodic_damage, samus_periodic_subdamage)) >> 16; samus_periodic_subdamage += kSamusPhys_LavaSubdamagePerFrame; @@ -169,11 +164,11 @@ void Samus_Animate_LavaFx(void) { // 0x9081C0 void Samus_Animate_AcidFx(void) { // 0x908219 static const uint16 kSamusPhys_AcidSubdamagePerFrame = 0x8000; static const uint16 kSamusPhys_AcidDamagePerFrame = 1; + uint16 r18 = Samus_GetBottom_R18(); - - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) { if ((game_time_frames & 7) == 0 && !sign16(samus_health - 71)) - QueueSfx3_Max3(0x2Du); + QueueSfx3_Max3(0x2D); uint16 v0 = (__PAIR32__(kSamusPhys_AcidDamagePerFrame, kSamusPhys_AcidSubdamagePerFrame) + __PAIR32__(samus_periodic_damage, samus_periodic_subdamage)) >> 16; samus_periodic_subdamage += kSamusPhys_AcidSubdamagePerFrame; @@ -186,10 +181,10 @@ void Samus_Animate_AcidFx(void) { // 0x908219 void Samus_Animate_SubmergedLavaAcid(void) { // 0x90824C static const uint16 kSamusPhys_AnimDelayInAcid = 2; - + uint16 r20 = Samus_GetTop_R20(); samus_anim_frame_buffer = kSamusPhys_AnimDelayInAcid; liquid_physics_type = 2; - if ((int16)(R20_ - lava_acid_y_pos) < 0 && (atmospheric_gfx_frame_and_type[0] & 0x400) == 0) { + if ((int16)(r20 - lava_acid_y_pos) < 0 && (atmospheric_gfx_frame_and_type[0] & 0x400) == 0) { atmospheric_gfx_frame_and_type[0] = 1024; atmospheric_gfx_frame_and_type[1] = 1024; atmospheric_gfx_frame_and_type[2] = 1024; @@ -204,10 +199,10 @@ void Samus_Animate_SubmergedLavaAcid(void) { // 0x90824C atmospheric_gfx_y_pos[3] = lava_acid_y_pos; atmospheric_gfx_x_pos[0] = samus_x_pos + 6; atmospheric_gfx_x_pos[1] = samus_x_pos; - *(uint32 *)&atmospheric_gfx_x_pos[2] = __PAIR32__(samus_x_pos - (samus_x_pos >= 0xFFFAu), samus_x_pos) - - ((int)(samus_x_pos >= 0xFFFAu) | 0x60000); + *(uint32 *)&atmospheric_gfx_x_pos[2] = __PAIR32__(samus_x_pos - (samus_x_pos >= 0xFFFA), samus_x_pos) + - ((int)(samus_x_pos >= 0xFFFA) | 0x60000); if ((game_time_frames & 1) == 0) - QueueSfx2_Max6(0x10u); + QueueSfx2_Max6(0x10); } if (samus_pose == kPose_00_FaceF_Powersuit || samus_pose == kPose_9B_FaceF_VariaGravitySuit @@ -216,7 +211,115 @@ void Samus_Animate_SubmergedLavaAcid(void) { // 0x90824C } } -static Func_Y_Y *const kAnimDelayFuncs[16] = { // 0x9082DC +static uint8 Samus_HandleSpeedBoosterAnimDelay(const uint8 *jp); + + +typedef bool Func_AnimDelay(const uint8 *jp); + +static bool Samus_AnimDelayFunc_0to5(const uint8 *jp) { // 0x908344 + return false; +} + +static bool Samus_AnimDelayFunc_6_GotoStartIfLittleHealth(const uint8 *jp) { // 0x908346 + samus_anim_frame = sign16(samus_health - 30) ? samus_anim_frame + 1 : 0; + return true; +} + +static bool Samus_AnimDelayFunc_7(const uint8 *jp) { // 0x908360 + samus_movement_handler = FUNC16(Samus_HandleMovement_DrainedCrouching); + samus_anim_frame++; + return true; +} + +static bool Samus_AnimDelayFunc_13_TransToPose(const uint8 *jp) { // 0x9084B6 + samus_new_pose_transitional = jp[1]; + samus_hurt_switch_index = 3; + return false; +} + +static bool Samus_AnimDelayFunc_8_AutoJumpHack(const uint8 *jp) { // 0x908370 + if (samus_input_handler == FUNC16(Samus_InputHandler_E91D)) + return Samus_AnimDelayFunc_13_TransToPose(jp); + if (samus_new_pose != kPose_4B_FaceR_Jumptrans + && samus_new_pose != kPose_4C_FaceL_Jumptrans + && samus_new_pose != kPose_19_FaceR_SpinJump + && samus_new_pose != kPose_1A_FaceL_SpinJump) { + samus_input_handler = FUNC16(HandleAutoJumpHack); + return Samus_AnimDelayFunc_13_TransToPose(jp); + } + return false; +} + +static bool Samus_AnimDelayFunc_9_TransToPose(const uint8 *jp) { // 0x90839A + if ((GET_WORD(jp + 1) & equipped_items) != 0) { + if (samus_y_speed || samus_y_subspeed) + samus_new_pose_transitional = jp[6]; + else + samus_new_pose_transitional = jp[5]; + } else if (samus_y_speed || samus_y_subspeed) { + samus_new_pose_transitional = jp[4]; + } else { + samus_new_pose_transitional = jp[3]; + } + samus_hurt_switch_index = 3; + return false; +} + +static bool UNUSED_Samus_AnimDelayFunc_10(const uint8 *jp) { // 0x9083F6 + if (samus_y_speed || samus_y_subspeed) + samus_new_pose_transitional = jp[2]; + else + samus_new_pose_transitional = jp[1]; + samus_hurt_switch_index = 3; + return false; +} + +static bool Samus_AnimDelayFunc_11_SelectDelaySequenceWalljump(const uint8 *jp) { // 0x90841D + if ((equipped_items & 0x20) == 0) { + uint16 r20 = Samus_GetTop_R20(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r20)) + goto LABEL_10; + } else if (sign16(fx_y_pos - r20) && (fx_liquid_options & 4) == 0) { + goto LABEL_10; + } + } + if ((equipped_items & 8) != 0) { + QueueSfx1_Max6(0x33); + samus_anim_frame += 21; + } else { + if ((equipped_items & 0x200) == 0) { +LABEL_10: + QueueSfx1_Max6(0x31); + samus_anim_frame += 1; + } else { + QueueSfx1_Max6(0x3E); + samus_anim_frame += 11; + } + } + return true; +} + +static bool Samus_AnimDelayFunc_12_TransToPose(const uint8 *jp) { // 0x90848B + if ((GET_WORD(jp + 1) & equipped_items) != 0) + samus_new_pose_transitional = jp[4]; + else + samus_new_pose_transitional = jp[3]; + samus_hurt_switch_index = 3; + return false; +} + +static bool Samus_AnimDelayFunc_14_Goto(const uint8 *jp) { // 0x9084C7 + samus_anim_frame -= jp[1]; + return true; +} + +static bool Samus_AnimDelayFunc_15_GotoStart(const uint8 *jp) { // 0x9084DB + samus_anim_frame = 0; + return true; +} + +static Func_AnimDelay *const kAnimDelayFuncs[16] = { // 0x9082DC Samus_AnimDelayFunc_0to5, Samus_AnimDelayFunc_0to5, Samus_AnimDelayFunc_0to5, @@ -235,165 +338,19 @@ static Func_Y_Y *const kAnimDelayFuncs[16] = { // 0x9082DC Samus_AnimDelayFunc_15_GotoStart, }; -void Samus_HandleAnimDelay(void) { - int16 v2; - R0_.bank = -111; - uint16 v0 = samus_anim_frame; - R0_.addr = kSamusAnimationDelayData[samus_pose]; - if ((IndirReadByte(R0_, samus_anim_frame) & 0x80) != 0) { - uint16 v1 = Samus_HandleSpeedBoosterAnimDelay(v0); - if (v1) { - v2 = kAnimDelayFuncs[v1 & 0xF](v0); - if (v2 >= 0) - samus_anim_frame_timer = samus_anim_frame_buffer + IndirReadByte(R0_, v2); - } - } else { - Samus_HandleNormalAnimDelay(v0); - } -} +#define kDefaultAnimFramePtr ((uint16 *)RomFixedPtr(0x91B5D1)) -uint16 Samus_AnimDelayFunc_0to5(uint16 j) { // 0x908344 - return -1; -} - -uint16 Samus_AnimDelayFunc_6_GotoStartIfLittleHealth(uint16 j) { // 0x908346 - if (sign16(samus_health - 30)) { - return ++samus_anim_frame; - } else { - samus_anim_frame = 0; - return 0; - } -} - -uint16 Samus_AnimDelayFunc_7(uint16 j) { // 0x908360 - samus_movement_handler = FUNC16(Samus_HandleMovement_DrainedCrouching); - return ++samus_anim_frame; -} - -uint16 Samus_AnimDelayFunc_8_AutoJumpHack(uint16 j) { // 0x908370 - if (samus_input_handler == FUNC16(Samus_InputHandler_E91D)) - return Samus_AnimDelayFunc_13_TransToPose(j); - if (samus_new_pose != kPose_4B_FaceR_Jumptrans - && samus_new_pose != kPose_4C_FaceL_Jumptrans - && samus_new_pose != kPose_19_FaceR_SpinJump - && samus_new_pose != kPose_1A_FaceL_SpinJump) { - samus_input_handler = FUNC16(HandleAutoJumpHack); - return Samus_AnimDelayFunc_13_TransToPose(j); - } - return -1; -} - -uint16 Samus_AnimDelayFunc_9_TransToPose(uint16 j) { // 0x90839A - uint16 v1 = j + 1; - R18_ = IndirReadWord(R0_, v1); - if ((R18_ & equipped_items) != 0) { - if (samus_y_speed || samus_y_subspeed) - samus_new_pose_transitional = IndirReadByte(R0_, v1 + 5); - else - samus_new_pose_transitional = IndirReadByte(R0_, v1 + 4); - } else if (samus_y_speed || samus_y_subspeed) { - samus_new_pose_transitional = IndirReadByte(R0_, v1 + 3); - } else { - samus_new_pose_transitional = IndirReadByte(R0_, v1 + 2); - } - samus_hurt_switch_index = 3; - return -1; -} - -uint16 UNUSED_Samus_AnimDelayFunc_10(uint16 j) { // 0x9083F6 - if (samus_y_speed || samus_y_subspeed) - samus_new_pose_transitional = IndirReadByte(R0_, j + 2); - else - samus_new_pose_transitional = IndirReadByte(R0_, j + 1); - samus_hurt_switch_index = 3; - return -1; -} - -uint16 Samus_AnimDelayFunc_11_SelectDelaySequenceWalljump(uint16 j) { // 0x90841D - if ((equipped_items & 0x20) == 0) { - Samus_GetTopBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R20_)) - goto LABEL_10; - } else if (sign16(fx_y_pos - R20_) && (fx_liquid_options & 4) == 0) { - goto LABEL_10; - } - } - if ((equipped_items & 8) != 0) { - QueueSfx1_Max6(0x33u); - samus_anim_frame += 21; - return samus_anim_frame; - } else { - if ((equipped_items & 0x200) == 0) { -LABEL_10: - QueueSfx1_Max6(0x31u); - return ++samus_anim_frame; - } - QueueSfx1_Max6(0x3Eu); - samus_anim_frame += 11; - return samus_anim_frame; - } -} - -uint16 Samus_AnimDelayFunc_12_TransToPose(uint16 j) { // 0x90848B - uint16 v1 = j + 1; - R18_ = IndirReadWord(R0_, v1); - if ((R18_ & equipped_items) != 0) - samus_new_pose_transitional = IndirReadByte(R0_, v1 + 3); - else - samus_new_pose_transitional = IndirReadByte(R0_, v1 + 2); - samus_hurt_switch_index = 3; - return -1; -} - -uint16 Samus_AnimDelayFunc_13_TransToPose(uint16 j) { // 0x9084B6 - samus_new_pose_transitional = IndirReadByte(R0_, j + 1); - samus_hurt_switch_index = 3; - return -1; -} - -uint16 Samus_AnimDelayFunc_14_Goto(uint16 j) { // 0x9084C7 - R18_ = IndirReadByte(R0_, j + 1); - samus_anim_frame -= R18_; - return samus_anim_frame; -} - -uint16 Samus_AnimDelayFunc_15_GotoStart(uint16 j) { // 0x9084DB - uint16 result = 0; - samus_anim_frame = 0; - return result; -} - -void Samus_HandleNormalAnimDelay(uint16 j) { // 0x9084E3 - R0_.bank = -111; - if (samus_has_momentum_flag && samus_movement_type == 1) { - uint16 *kDefaultAnimFramePtr = (uint16 *)RomPtr(0x91B5D1); - - if ((equipped_items & 0x2000) != 0) - R0_.addr = kSpeedBoostToAnimFramePtr[HIBYTE(speed_boost_counter)]; - else - R0_.addr = *kDefaultAnimFramePtr; - } - samus_anim_frame_timer = samus_anim_frame_buffer + IndirReadByte(R0_, j); -} - - - -uint16 Samus_HandleSpeedBoosterAnimDelay(uint16 j) { // 0x90852C - uint16 *kDefaultAnimFramePtr = (uint16 *)RomPtr(0x91B5D1); - - R0_.bank = 0x91; +static uint8 Samus_HandleSpeedBoosterAnimDelay(const uint8 *jp) { // 0x90852C if (!samus_has_momentum_flag || (button_config_run_b & joypad1_lastkeys) == 0 || samus_movement_type != 1) - return IndirReadByte(R0_, j); + return jp[0]; if ((equipped_items & 0x2000) == 0) { samus_anim_frame = 0; - R0_.addr = *kDefaultAnimFramePtr; - samus_anim_frame_timer = samus_anim_frame_buffer + IndirReadByte(R0_, 0); + samus_anim_frame_timer = samus_anim_frame_buffer + RomPtr_91(*kDefaultAnimFramePtr)[0]; return 0; } if ((uint8)--speed_boost_counter) - return IndirReadByte(R0_, j); + return jp[0]; uint16 v2 = speed_boost_counter; if ((speed_boost_counter & 0x400) == 0) { v2 = speed_boost_counter + 256; @@ -401,18 +358,32 @@ uint16 Samus_HandleSpeedBoosterAnimDelay(uint16 j) { // 0x90852C if ((v2 & 0x400) != 0) { // The original code forgets to preserve A here. samus_echoes_sound_flag = 1; - QueueSfx3_Max6(3u); + QueueSfx3_Max6(3); //v2 = 0x103; // bug! } } int v3 = HIBYTE(v2); speed_boost_counter = kSpeedBoostToCtr[v3] | speed_boost_counter & 0xFF00; samus_anim_frame = 0; - R0_.addr = kSpeedBoostToAnimFramePtr[v3]; - samus_anim_frame_timer = samus_anim_frame_buffer + IndirReadByte(R0_, 0); + samus_anim_frame_timer = samus_anim_frame_buffer + RomPtr_91(kSpeedBoostToAnimFramePtr[v3])[0]; return 0; } +static void Samus_HandleAnimDelay(void) { + const uint8 *p = RomPtr_91(kSamusAnimationDelayData[samus_pose]); + if ((p[samus_anim_frame] & 0x80) != 0) { + uint8 v1 = Samus_HandleSpeedBoosterAnimDelay(p + samus_anim_frame); + if (kAnimDelayFuncs[v1 & 0xF](p + samus_anim_frame)) + samus_anim_frame_timer = samus_anim_frame_buffer + p[samus_anim_frame]; + } else { + if (samus_has_momentum_flag && samus_movement_type == 1) { + uint16 addr = ((equipped_items & 0x2000) != 0) ? kSpeedBoostToAnimFramePtr[HIBYTE(speed_boost_counter)] : *kDefaultAnimFramePtr; + p = RomPtr_91(addr); + } + samus_anim_frame_timer = samus_anim_frame_buffer + p[samus_anim_frame]; + } +} + static Func_U8 *const kSamusIsBottomDrawnFuncs[28] = { // 0x9085E2 SamusBottomDrawn_0_Standing, SamusBottomDrawn_1, @@ -454,7 +425,7 @@ void Samus_Draw(void) { uint16 a = samus_top_half_spritemap_index; v0 = Samus_CalcSpritemapPos(2 * samus_pose); DrawSamusSpritemap(a, v0.k, v0.j); - R36 = v2; + uint16 R36 = v2; if (kSamusIsBottomDrawnFuncs[samus_movement_type]() & 1) { samus_bottom_half_spritemap_index = samus_anim_frame + kSamusPoseToBaseSpritemapIndexBottom[R36 >> 1]; DrawSamusSpritemap(samus_bottom_half_spritemap_index, samus_spritemap_x_pos, samus_spritemap_y_pos); @@ -568,10 +539,10 @@ uint8 SamusBottomDrawn_1B(void) { // 0x908790 } void Samus_DrawEchoes(void) { // 0x9087BD - if ((speed_echoes_index & 0x8000u) == 0) { + if ((speed_echoes_index & 0x8000) == 0) { if ((speed_boost_counter & 0xFF00) == 1024) { if (speed_echo_xpos[1]) - Samus_DrawEcho(2u); + Samus_DrawEcho(2); if (speed_echo_xpos[0]) Samus_DrawEcho(0); } @@ -589,7 +560,7 @@ void Samus_DrawEchoes(void) { // 0x9087BD v3 = v2 - 2; speed_echo_ypos[v1] = v3; } - if ((speed_echo_xspeed[v1] & 0x8000u) != 0) { + if ((speed_echo_xspeed[v1] & 0x8000) != 0) { uint16 v5 = speed_echo_xspeed[v1] + speed_echo_xpos[v1]; speed_echo_xpos[v1] = v5; if ((int16)(v5 - samus_x_pos) < 0) { @@ -611,41 +582,24 @@ void Samus_DrawEchoes(void) { // 0x9087BD } void Samus_DrawEcho(uint16 j) { // 0x908855 - int16 v2; - - R18_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(8 * samus_pose)); int v1 = j >> 1; - v2 = (__PAIR32__(speed_echo_ypos[v1] - R18_, speed_echo_ypos[v1]) - __PAIR32__(layer1_y_pos, R18_)) >> 16; + int16 v2 = speed_echo_ypos[v1] - kPoseParams[samus_pose].y_offset_to_gfx - layer1_y_pos; if (v2 >= 0 && sign16(v2 - 248)) { DrawSamusSpritemap(samus_top_half_spritemap_index, speed_echo_xpos[v1] - layer1_x_pos, v2); - if (samus_bottom_half_spritemap_index) { - R18_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(8 * samus_pose)); - DrawSamusSpritemap( - samus_bottom_half_spritemap_index, - speed_echo_xpos[j >> 1] - layer1_x_pos, - (__PAIR32__(speed_echo_ypos[j >> 1] - R18_, speed_echo_ypos[j >> 1]) - __PAIR32__(layer1_y_pos, R18_)) >> 16); - } + if (samus_bottom_half_spritemap_index) + DrawSamusSpritemap(samus_bottom_half_spritemap_index, speed_echo_xpos[v1] - layer1_x_pos, v2); } } void Samus_DrawShinesparkCrashEchoes(uint16 k) { // 0x9088BA - int16 v2; - if ((nmi_frame_counter_word & 1) != 0) { - uint16 v4 = 2 * samus_pose; uint16 a = samus_anim_frame + kSamusPoseToBaseSpritemapIndexTop[samus_pose]; - R18_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(8 * samus_pose)); - int v1 = k >> 1; - v2 = speed_echo_ypos[v1] - R18_ - layer1_y_pos; - if (v2 >= 0) { - if (sign16(v2 - 248)) { - DrawSamusSpritemap(a, speed_echo_xpos[v1] - layer1_x_pos, v2); - R36 = v4; - if (kSamusIsBottomDrawnFuncs[samus_movement_type]() & 1) { - uint16 v5 = samus_anim_frame + kSamusPoseToBaseSpritemapIndexBottom[R36 >> 1]; - R18_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(4 * R36)); - DrawSamusSpritemap(v5, speed_echo_xpos[k >> 1] - layer1_x_pos, speed_echo_ypos[k >> 1] - R18_ - layer1_y_pos); - } + int16 v2 = speed_echo_ypos[k >> 1] - kPoseParams[samus_pose].y_offset_to_gfx - layer1_y_pos; + if (v2 >= 0 && sign16(v2 - 248)) { + DrawSamusSpritemap(a, speed_echo_xpos[k >> 1] - layer1_x_pos, v2); + if (kSamusIsBottomDrawnFuncs[samus_movement_type]() & 1) { + uint16 v5 = samus_anim_frame + kSamusPoseToBaseSpritemapIndexBottom[samus_pose]; + DrawSamusSpritemap(v5, speed_echo_xpos[k >> 1] - layer1_x_pos, v2); } } } @@ -654,14 +608,14 @@ void Samus_DrawShinesparkCrashEchoes(uint16 k) { // 0x9088BA void Samus_DrawShinesparkCrashEchoProjectiles(void) { // 0x908953 if ((nmi_frame_counter_word & 1) != 0) { if (speed_echo_xspeed[3]) - Samus_DrawEcho(6u); + Samus_DrawEcho(6); if (speed_echo_xspeed[2]) - Samus_DrawEcho(4u); + Samus_DrawEcho(4); } } void Samus_DrawStartingDeathAnim(void) { // 0x908976 - bool v0 = (--samus_anim_frame_timer & 0x8000u) != 0; + bool v0 = (--samus_anim_frame_timer & 0x8000) != 0; if (!samus_anim_frame_timer || v0) { ++samus_anim_frame; Samus_HandleAnimDelay(); @@ -674,7 +628,7 @@ void Samus_DrawDuringDeathAnim(void) { // 0x908998 uint16 a = samus_anim_frame + kSamusPoseToBaseSpritemapIndexTop[samus_pose]; Samus_CalcSpritemapPos(2 * samus_pose); DrawSamusSpritemap(a, layer1_x_pos + samus_spritemap_x_pos, layer1_y_pos + samus_spritemap_y_pos); - R36 = v1; + uint16 R36 = v1; if (kSamusIsBottomDrawnFuncs[samus_movement_type]() & 1) DrawSamusSpritemap( samus_anim_frame + kSamusPoseToBaseSpritemapIndexBottom[R36 >> 1], @@ -690,7 +644,7 @@ void Samus_DrawWhenNotAnimatingOrDying(void) { // 0x908A00 uint16 a = samus_anim_frame + kSamusPoseToBaseSpritemapIndexTop[samus_pose]; v0 = Samus_CalcSpritemapPos(2 * samus_pose); DrawSamusSpritemap(a, v0.k, v0.j); - R36 = v2; + uint16 R36 = v2; if (kSamusIsBottomDrawnFuncs[samus_movement_type]() & 1) DrawSamusSpritemap( samus_anim_frame + kSamusPoseToBaseSpritemapIndexBottom[R36 >> 1], @@ -718,7 +672,7 @@ void HandleAtmosphericEffects(void) { uint16 v2 = atmospheric_gfx_frame_and_type[v1]; if (!v2) continue; - R18_ = 2 * (uint8)v2; + uint16 r18 = 2 * (uint8)v2; uint16 v3 = 2 * HIBYTE(v2); v4 = atmospheric_gfx_anim_timer[v1] - 1; atmospheric_gfx_anim_timer[v1] = v4; @@ -726,10 +680,10 @@ void HandleAtmosphericEffects(void) { if (v4 < 0) { if (v4 != (int16)0x8000) continue; - atmospheric_gfx_anim_timer[v1] = *(uint16 *)RomPtr_90(R18_ + kAtmosphericGraphicAnimationTimers[v3 >> 1]); + atmospheric_gfx_anim_timer[v1] = *(uint16 *)RomPtr_90(r18 + kAtmosphericGraphicAnimationTimers[v3 >> 1]); } } else { - atmospheric_gfx_anim_timer[v1] = *(uint16 *)RomPtr_90(R18_ + kAtmosphericGraphicAnimationTimers[v3 >> 1]); + atmospheric_gfx_anim_timer[v1] = *(uint16 *)RomPtr_90(r18 + kAtmosphericGraphicAnimationTimers[v3 >> 1]); uint16 v5 = atmospheric_gfx_frame_and_type[v1] + 1; atmospheric_gfx_frame_and_type[v1] = v5; if ((int16)((uint8)v5 - kAtmosphericTypeNumFrames[v3 >> 1]) >= 0) { @@ -747,18 +701,18 @@ void AtmosphericTypeFunc_1_FootstepSplash(uint16 k, uint16 j) { // 0x908AC5 int16 v6; int v2 = j >> 1; - R18_ = 2 * LOBYTE(atmospheric_gfx_frame_and_type[v2]); + uint16 r18 = 2 * LOBYTE(atmospheric_gfx_frame_and_type[v2]); uint16 v3 = oam_next_ptr; v4 = atmospheric_gfx_x_pos[v2] - layer1_x_pos - 4; if (v4 >= 0) { if (sign16(atmospheric_gfx_x_pos[v2] - layer1_x_pos - 260)) { v5 = gOamEnt(oam_next_ptr); - *(uint16 *)&v5->xcoord = v4; + v5->xcoord = v4; v6 = atmospheric_gfx_y_pos[v2] - layer1_y_pos - 4; if (v6 >= 0) { if (sign16(atmospheric_gfx_y_pos[v2] - layer1_y_pos - 260)) { - *(uint16 *)&v5->ycoord = v6; - *(uint16 *)&v5->charnum = *(uint16 *)RomPtr_90(R18_ + g_off_908BFF[k >> 1]); + v5->ycoord = v6; + *(uint16 *)&v5->charnum = *(uint16 *)RomPtr_90(r18 + g_off_908BFF[k >> 1]); oam_next_ptr = v3 + 4; } } @@ -774,9 +728,9 @@ void AtmosphericTypeFunc_Common(uint16 j, uint16 a) { // 0x908B74 void AtmosphericTypeFunc_3_DivingSplash(uint16 k, uint16 j) { // 0x908B16 int v2 = j >> 1; - R18_ = LOBYTE(atmospheric_gfx_frame_and_type[v2]); + uint16 r18 = LOBYTE(atmospheric_gfx_frame_and_type[v2]); atmospheric_gfx_y_pos[v2] = fx_y_pos; - AtmosphericTypeFunc_Common(j, R18_ + 399); + AtmosphericTypeFunc_Common(j, r18 + 399); } void AtmosphericTypeFunc_4_LavaSurfaceDmg(uint16 k, uint16 j) { // 0x908B2E @@ -797,8 +751,8 @@ void AtmosphericTypeFunc_67_Dust(uint16 k, uint16 j) { // 0x908B57 } void AtmosphericTypeFunc_5_Bubbles(uint16 k, uint16 j) { // 0x908B64 - R18_ = LOBYTE(atmospheric_gfx_frame_and_type[j >> 1]); - AtmosphericTypeFunc_Common(j, R18_ + 390); + uint16 r18 = LOBYTE(atmospheric_gfx_frame_and_type[j >> 1]); + AtmosphericTypeFunc_Common(j, r18 + 390); } static Func_Y_To_PairU16 *const kSamus_CalcSpritemapPos[28] = { // 0x908C1F @@ -835,22 +789,20 @@ static Func_Y_To_PairU16 *const kSamus_CalcSpritemapPos[28] = { // 0x908C1F PairU16 Samus_CalcSpritemapPos(uint16 k) { PairU16 v1; - if ((ceres_status & 0x8000u) == 0) { + if ((ceres_status & 0x8000) == 0) { v1 = kSamus_CalcSpritemapPos[samus_movement_type](k); } else { - grapple_beam_tmpD82 = samus_x_pos; - grapple_beam_tmpD84 = samus_y_pos; + uint16 old_x = samus_x_pos, old_y = samus_y_pos; Samus_CalcPos_Mode7(); v1 = kSamus_CalcSpritemapPos[samus_movement_type](k); - samus_y_pos = grapple_beam_tmpD84; - samus_x_pos = grapple_beam_tmpD82; + samus_y_pos = old_y; + samus_x_pos = old_x; } return MakePairU16(v1.k, v1.j); } PairU16 Samus_CalcSpritemapPos_Default(uint16 j) { // 0x908C94 int v1 = (int8)*(&kPoseParams[0].y_offset_to_gfx + 4 * j); - R18_ = v1; samus_spritemap_y_pos = samus_y_pos - v1 - layer1_y_pos; samus_spritemap_x_pos = samus_x_pos - layer1_x_pos; return MakePairU16(samus_spritemap_x_pos, samus_spritemap_y_pos); @@ -875,10 +827,10 @@ PairU16 Samus_CalcSpritemapPos_Standing(uint16 j) { // 0x908CC3 return MakePairU16(samus_x_pos - layer1_x_pos, samus_y_pos - 1 - layer1_y_pos); } } else if (!sign16(v1 - kPose_A4_FaceR_LandJump) && sign16(v1 - kPose_A8_FaceR_Grappling)) { - R18_ = *(uint16 *)&g_byte_908D28[(uint16)(samus_anim_frame + 4 * (v1 - 164))]; - samus_spritemap_y_pos = samus_y_pos - R18_ - layer1_y_pos; + uint16 r18 = *(uint16 *)&g_byte_908D28[(uint16)(samus_anim_frame + 4 * (v1 - 164))]; + samus_spritemap_y_pos = samus_y_pos - r18 - layer1_y_pos; samus_spritemap_x_pos = samus_x_pos - layer1_x_pos; - return MakePairU16(samus_x_pos - layer1_x_pos, samus_y_pos - R18_ - layer1_y_pos); + return MakePairU16(samus_x_pos - layer1_x_pos, samus_y_pos - r18 - layer1_y_pos); } v3 = Samus_CalcSpritemapPos_Default(j); return MakePairU16(v3.k, v3.j); @@ -901,7 +853,6 @@ PairU16 Samus_CalcSpritemapPos_Crouch(uint16 j) { // 0x908D3C return Samus_CalcSpritemapPos_Default(j); } else { int v4 = byte_908D80[(uint16)(samus_anim_frame + 2 * (v1 - 53))]; - R18_ = v4; samus_spritemap_y_pos = v4 + samus_y_pos - layer1_y_pos; samus_spritemap_x_pos = samus_x_pos - layer1_x_pos; return MakePairU16(samus_x_pos - layer1_x_pos, samus_spritemap_y_pos); @@ -926,94 +877,80 @@ PairU16 Samus_CalcSpritemapPos_Special(uint16 j) { // 0x908D98 } v2 = -3; } - R18_ = v2; samus_spritemap_y_pos = v2 + samus_y_pos - layer1_y_pos; samus_spritemap_x_pos = samus_x_pos - layer1_x_pos; return MakePairU16(samus_x_pos - layer1_x_pos, v2 + samus_y_pos - layer1_y_pos); } -static Func_V *const kLiquidPhysicsType[8] = { // 0x908E0F - LiquidPhysicsType_0, - LiquidPhysicsType_24_LavaAcid, - LiquidPhysicsType_24_LavaAcid, - LiquidPhysicsType_6_Water, - LiquidPhysicsType_0, - LiquidPhysicsType_0, - LiquidPhysicsType_0, - LiquidPhysicsType_0, -}; - void SetLiquidPhysicsType(void) { - Samus_GetTopBottomBoundary(); - kLiquidPhysicsType[(uint8)(fx_type & 0xF) >> 1](); -} - -void LiquidPhysicsType_0(void) { // 0x908E36 - liquid_physics_type = 0; -} - -void LiquidPhysicsType_24_LavaAcid(void) { // 0x908E3A - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) - liquid_physics_type = kLiquidPhysicsType_LavaAcid; - else - LiquidPhysicsType_0(); -} - -void LiquidPhysicsType_6_Water(void) { // 0x908E4A - if ((fx_y_pos & 0x8000u) == 0 && sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) - liquid_physics_type = kLiquidPhysicsType_Water; - else - LiquidPhysicsType_0(); + uint16 r18 = Samus_GetBottom_R18(); + switch ((fx_type & 0xF) >> 1) { + case 1: + case 2: + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) + liquid_physics_type = kLiquidPhysicsType_LavaAcid; + else + liquid_physics_type = 0; + break; + case 3: + if ((fx_y_pos & 0x8000) == 0 && sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) + liquid_physics_type = kLiquidPhysicsType_Water; + else + liquid_physics_type = 0; + break; + default: + liquid_physics_type = 0; + } } void Samus_HandleMovement_X(void) { // 0x908E64 Samus_HandleExtraRunspeedX(); - Samus_CalcBaseSpeed_X(Samus_DetermineSpeedTableEntryPtr_X()); - Samus_MoveX(); + Samus_MoveX(Samus_CalcBaseSpeed_X(Samus_DetermineSpeedTableEntryPtr_X())); } -void Samus_MoveX(void) { // 0x908EA9 +void Samus_MoveX(int32 amt) { // 0x908EA9 if (!samus_x_accel_mode || samus_x_accel_mode == 2) { if (samus_pose_x_dir != 4) { LABEL_6: - Samus_CalcDisplacementMoveRight(); + amt = Samus_CalcDisplacementMoveRight(amt); goto LABEL_8; } } else if (samus_pose_x_dir != 8) { goto LABEL_6; } - Samus_CalcDisplacementMoveLeft(); + amt = Samus_CalcDisplacementMoveLeft(amt); LABEL_8: - if ((R18_ & 0x8000u) != 0) - Samus_MoveLeft(); + if (amt < 0) + Samus_MoveLeft(amt); else - Samus_MoveRight(); + Samus_MoveRight(amt); } void Samus_BombJumpRisingXMovement_(void) { + int32 amt; if (knockback_dir) { - Samus_CalcBaseSpeed_X(Samus_DetermineSpeedTableEntryPtr_X()); + amt = Samus_CalcBaseSpeed_X(Samus_DetermineSpeedTableEntryPtr_X()); if (!knockback_x_dir) goto LABEL_6; LABEL_5: - Samus_CalcDisplacementMoveRight(); + amt = Samus_CalcDisplacementMoveRight(amt); goto LABEL_7; } - Samus_CalcBaseSpeed_X(addr_stru_909F25); + amt = Samus_CalcBaseSpeed_X(addr_stru_909F25); if ((uint8)bomb_jump_dir != 1) goto LABEL_5; LABEL_6: - Samus_CalcDisplacementMoveLeft(); + amt = Samus_CalcDisplacementMoveLeft(amt); LABEL_7: - if ((R18_ & 0x8000u) != 0) - Samus_MoveLeft(); + if (amt < 0) + Samus_MoveLeft(amt); else - Samus_MoveRight(); + Samus_MoveRight(amt); } void Samus_BombJumpRisingYMovement_(void) { if (samus_y_dir == 1) { - if ((samus_y_speed & 0x8000u) != 0) { + if ((samus_y_speed & 0x8000) != 0) { samus_y_subspeed = 0; samus_y_speed = 0; samus_y_dir = 2; @@ -1027,26 +964,21 @@ void Samus_BombJumpRisingYMovement_(void) { } void Samus_BombJumpFallingXMovement_(void) { - Samus_CalcBaseSpeed_X(Samus_DetermineSpeedTableEntryPtr_X()); + int32 amt = Samus_CalcBaseSpeed_X(Samus_DetermineSpeedTableEntryPtr_X()); if (samus_var62 == 1) - Samus_CalcDisplacementMoveLeft(); + amt = Samus_CalcDisplacementMoveLeft(amt); else - Samus_CalcDisplacementMoveRight(); - if ((R18_ & 0x8000u) != 0) - Samus_MoveLeft(); + amt = Samus_CalcDisplacementMoveRight(amt); + if (amt < 0) + Samus_MoveLeft(amt); else - Samus_MoveRight(); + Samus_MoveRight(amt); } void Samus_BombJumpFallingYMovement_(void) { - if (sign16(samus_y_speed - 5)) { - uint16 v0 = (__PAIR32__(samus_y_accel, samus_y_subaccel) + __PAIR32__(samus_y_speed, samus_y_subspeed)) >> 16; - samus_y_subspeed += samus_y_subaccel; - samus_y_speed = v0; - } - R20_ = samus_y_subspeed; - R18_ = samus_y_speed; - Samus_MoveDown(); + if (sign16(samus_y_speed - 5)) + AddToHiLo(&samus_y_speed, &samus_y_subspeed, __PAIR32__(samus_y_accel, samus_y_subaccel)); + Samus_MoveDown(__PAIR32__(samus_y_speed, samus_y_subspeed)); } void Samus_JumpingMovement(void) { // 0x908FB3 @@ -1059,12 +991,12 @@ void Samus_JumpingMovement(void) { // 0x908FB3 Samus_MoveExtraY(); return; } - if (samus_y_dir == 1 && ((button_config_jump_a & joypad1_lastkeys) == 0 || (samus_y_speed & 0x8000u) != 0)) { + if (samus_y_dir == 1 && ((button_config_jump_a & joypad1_lastkeys) == 0 || (samus_y_speed & 0x8000) != 0)) { samus_y_subspeed = 0; samus_y_speed = 0; samus_y_dir = 2; } - Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); + Pair_Bool_Amt pair = Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); if (samus_movement_type == 20) { if (!samus_x_accel_mode) samus_x_accel_mode = 2; @@ -1072,11 +1004,9 @@ void Samus_JumpingMovement(void) { // 0x908FB3 } if (samus_x_accel_mode || (joypad1_lastkeys & 0x100) != 0 || (joypad1_lastkeys & 0x200) != 0) { LABEL_17: - Samus_MoveX(); + Samus_MoveX(pair.amt); goto LABEL_18; } - R18_ = 0; - R20_ = 0; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_collision_flag = 0; @@ -1088,19 +1018,19 @@ void Samus_SpinJumpMovement(void) { // 0x909040 static const uint16 g_word_909E9F = 8; Samus_HandleExtraRunspeedX(); - if (samus_y_dir == 1 && ((button_config_jump_a & joypad1_lastkeys) == 0 || (samus_y_speed & 0x8000u) != 0)) { + if (samus_y_dir == 1 && ((button_config_jump_a & joypad1_lastkeys) == 0 || (samus_y_speed & 0x8000) != 0)) { samus_y_subspeed = 0; samus_y_speed = 0; samus_y_dir = 2; } - if (Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()) & 1 || samus_x_accel_mode == 1) + Pair_Bool_Amt pair = Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); + if (pair.flag || samus_x_accel_mode == 1) goto LABEL_12; if (samus_pose_x_dir == 4) { if ((joypad1_lastkeys & kButton_Left) != 0) goto LABEL_12; LABEL_11: - R18_ = 0; - R20_ = 0; + pair.amt = 0; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_collision_flag = 0; @@ -1113,15 +1043,13 @@ LABEL_12: if (!samus_x_accel_mode) samus_x_accel_mode = 2; LABEL_14: - Samus_MoveX(); - R18_ = g_word_909E9F; - R20_ = 0; - if (!(Samus_WallJumpCheck() & 1)) + Samus_MoveX(pair.amt); + if (!Samus_WallJumpCheck(INT16_SHL16(g_word_909E9F))) Samus_MoveY_WithSpeedCalc(); } void Samus_CheckStartFalling(void) { // 0x9090C4 - if (samus_y_dir == 1 && (samus_y_speed & 0x8000u) != 0) { + if (samus_y_dir == 1 && (samus_y_speed & 0x8000) != 0) { samus_y_subspeed = 0; samus_y_speed = 0; samus_y_dir = 2; @@ -1129,45 +1057,28 @@ void Samus_CheckStartFalling(void) { // 0x9090C4 } void Samus_MoveY_WithSpeedCalc(void) { // 0x9090E2 - int16 v3; - - R20_ = samus_y_subspeed; - R18_ = samus_y_speed; + int32 amt = __PAIR32__(samus_y_speed, samus_y_subspeed); if (samus_y_dir == 2) { - if (samus_y_speed != 5) { - uint16 v1 = (__PAIR32__(samus_y_accel, samus_y_subaccel) + __PAIR32__(samus_y_speed, samus_y_subspeed)) >> 16; - samus_y_subspeed += samus_y_subaccel; - samus_y_speed = v1; - } + if (samus_y_speed != 5) + AddToHiLo(&samus_y_speed, &samus_y_subspeed, __PAIR32__(samus_y_accel, samus_y_subaccel)); } else { - uint16 v0 = (__PAIR32__(samus_y_speed, samus_y_subspeed) - __PAIR32__(samus_y_accel, samus_y_subaccel)) >> 16; - samus_y_subspeed -= samus_y_subaccel; - samus_y_speed = v0; + AddToHiLo(&samus_y_speed, &samus_y_subspeed, -(int32)__PAIR32__(samus_y_accel, samus_y_subaccel)); } - if (samus_y_dir != 2) { - R18_ = ~R18_; - bool v2 = R20_ == 0; - R20_ = -R20_; - if (v2) - ++R18_; - } - v3 = (__PAIR32__(R18_, R20_) + __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement)) >> 16; - R20_ += extra_samus_y_subdisplacement; - R18_ = v3; - if (v3 < 0) - Samus_MoveUp(); + if (samus_y_dir != 2) + amt = -amt; + amt += __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement); + if (amt < 0) + Samus_MoveUp(amt); else - Samus_MoveDown(); + Samus_MoveDown(amt); } void Samus_FallingMovement(void) { // 0x909168 Samus_HandleExtraRunspeedX(); - Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); + Pair_Bool_Amt pair = Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); if (samus_x_accel_mode || (joypad1_lastkeys & kButton_Right) != 0 || (joypad1_lastkeys & kButton_Left) != 0) { - Samus_MoveX(); + Samus_MoveX(pair.amt); } else { - R18_ = 0; - R20_ = 0; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_collision_flag = 0; @@ -1177,41 +1088,37 @@ void Samus_FallingMovement(void) { // 0x909168 } void Samus_MorphedFallingMovement(void) { // 0x90919F - Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); + Pair_Bool_Amt pair = Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); if (!samus_x_accel_mode && (joypad1_lastkeys & kButton_Right) == 0 && (joypad1_lastkeys & kButton_Left) == 0) { - R18_ = 0; - R20_ = 0; + pair.amt = 0; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_collision_flag = 0; } - Samus_MoveX(); + Samus_MoveX(pair.amt); Samus_CheckStartFalling(); Samus_MoveY_WithSpeedCalc(); } void Samus_MorphedBouncingMovement(void) { // 0x9091D1 - Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); + Pair_Bool_Amt pair = Samus_CalcBaseSpeed_NoDecel_X(Samus_DetermineSpeedTableEntryPtr_X()); if (!samus_x_accel_mode && (joypad1_lastkeys & kButton_Right) == 0 && (joypad1_lastkeys & kButton_Left) == 0) { - R18_ = 0; - R20_ = 0; + pair.amt = 0; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_collision_flag = 0; } - Samus_MoveX(); + Samus_MoveX(pair.amt); if (!knockback_dir) { if (extra_samus_y_displacement || extra_samus_y_subdisplacement) { samus_y_dir = 2; samus_y_subspeed = 0; samus_y_speed = 0; - R20_ = extra_samus_y_subdisplacement; - R18_ = extra_samus_y_displacement; - if ((extra_samus_y_displacement & 0x8000u) != 0) { - Samus_MoveUp(); + int32 amt = __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement); + if (amt < 0) { + Samus_MoveUp(amt); } else { - ++R18_; - Samus_MoveDown(); + Samus_MoveDown(amt + INT16_SHL16(1)); } } else { Samus_CheckStartFalling(); @@ -1221,37 +1128,26 @@ void Samus_MorphedBouncingMovement(void) { // 0x9091D1 } void Samus_Move_NoSpeedCalc_Y(void) { // 0x90923F - if (!extra_samus_y_displacement && !extra_samus_y_subdisplacement) { - if (samus_pos_adjusted_by_slope_flag) { - R20_ = 0; - R18_ = 1; - } else { - R20_ = samus_total_x_subspeed; - R18_ = samus_total_x_speed + 1; - } - goto LABEL_8; + int32 amt = __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement); + if (amt == 0) { + if (!samus_pos_adjusted_by_slope_flag) + amt = __PAIR32__(samus_total_x_speed, samus_total_x_subspeed); + Samus_MoveDown(amt + INT16_SHL16(1)); + } else { + if (amt < 0) + Samus_MoveUp(amt); + else + Samus_MoveDown(amt + INT16_SHL16(1)); } - R20_ = extra_samus_y_subdisplacement; - R18_ = extra_samus_y_displacement; - if ((extra_samus_y_displacement & 0x8000u) == 0) { - ++R18_; -LABEL_8: - Samus_MoveDown(); - return; - } - Samus_MoveUp(); } void Samus_MoveExtraY(void) { // 0x909288 - if (extra_samus_y_displacement || extra_samus_y_subdisplacement) { - R20_ = extra_samus_y_subdisplacement; - R18_ = extra_samus_y_displacement; - if ((extra_samus_y_displacement & 0x8000u) != 0) { - Samus_MoveUp(); - } else { - ++R18_; - Samus_MoveDown(); - } + int32 amt = __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement); + if (amt != 0) { + if (amt < 0) + Samus_MoveUp(amt); + else + Samus_MoveDown(amt + INT16_SHL16(1)); } } @@ -1271,37 +1167,21 @@ uint8 Samus_MoveY_Simple_(void) { // 0x9092C7 return 1; } -void UNUSED_sub_9092D6(void) { // 0x9092D6 - samus_y_pos += R18_; - samus_prev_y_pos = samus_y_pos; -} - void Samus_Move_NoBaseSpeed_X(void) { // 0x909348 - R18_ = 0; - R20_ = 0; - Samus_MoveX(); + Samus_MoveX(0); } -void Samus_MoveLeft(void) { // 0x909350 - R18_ = ~R18_; - bool v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - samus_collision_flag = Samus_CheckSolidEnemyColl(); +void Samus_MoveLeft(int32 amt) { // 0x909350 + amt = -amt; + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + samus_collision_flag = cres.collision, amt = cres.amt; if (samus_collision_flag) { Samus_ClearXSpeedIfColl(); - Samus_MoveLeft_NoColl(); + Samus_MoveLeft_NoColl(amt); Samus_AlignYPosSlope(); } else { - R18_ = ~R18_; - v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - Samus_MoveRight_NoSolidColl(); - projectile_init_speed_samus_moved_left_fract = R20_; - projectile_init_speed_samus_moved_left = R18_; + amt = Samus_MoveRight_NoSolidColl(-amt); + SetHiLo(&projectile_init_speed_samus_moved_left, &projectile_init_speed_samus_moved_left_fract, amt); if ((samus_collision_direction & 1) != 0) samus_collision_flag = 0; Samus_ClearXSpeedIfColl(); @@ -1309,16 +1189,16 @@ void Samus_MoveLeft(void) { // 0x909350 } } -void Samus_MoveRight(void) { // 0x9093B1 - samus_collision_flag = Samus_CheckSolidEnemyColl(); +void Samus_MoveRight(int32 amt) { // 0x9093B1 + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + samus_collision_flag = cres.collision, amt = cres.amt; if (samus_collision_flag) { Samus_ClearXSpeedIfColl(); - Samus_MoveRight_NoColl(); + Samus_MoveRight_NoColl(amt); Samus_AlignYPosSlope(); } else { - Samus_MoveRight_NoSolidColl(); - projectile_init_speed_samus_moved_right_fract = R20_; - projectile_init_speed_samus_moved_right = R18_; + amt = Samus_MoveRight_NoSolidColl(amt); + SetHiLo(&projectile_init_speed_samus_moved_right, &projectile_init_speed_samus_moved_right_fract, amt); if ((samus_collision_direction & 1) == 0) samus_collision_flag = 0; Samus_ClearXSpeedIfColl(); @@ -1326,58 +1206,47 @@ void Samus_MoveRight(void) { // 0x9093B1 } } -void Samus_MoveUp(void) { // 0x9093EC +void Samus_MoveUp(int32 amt) { // 0x9093EC samus_collision_direction = 2; - R18_ = ~R18_; - bool v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - samus_collision_flag = Samus_CheckSolidEnemyColl(); + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(-amt); + samus_collision_flag = cres.collision, amt = cres.amt; if (samus_collision_flag) { Samus_MoveUp_SetPoseCalcInput(); - Samus_MoveUp_NoColl(); + Samus_MoveUp_NoColl(amt); } else { - R18_ = ~R18_; - v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - Samus_MoveDown_NoSolidColl(); - projectile_init_speed_samus_moved_up_fract = R20_; - projectile_init_speed_samus_moved_up = R18_; + amt = Samus_MoveDown_NoSolidColl(-amt); + SetHiLo(&projectile_init_speed_samus_moved_up, &projectile_init_speed_samus_moved_up_fract, amt); Samus_MoveUp_SetPoseCalcInput(); } } -void Samus_MoveDown(void) { // 0x909440 +void Samus_MoveDown(int32 amt) { // 0x909440 samus_collision_direction = 3; - samus_collision_flag = Samus_CheckSolidEnemyColl(); + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + samus_collision_flag = cres.collision, amt = cres.amt; if (samus_collision_flag) { Samus_MoveDown_SetPoseCalcInput(); - Samus_MoveDown_NoColl(); + Samus_MoveDown_NoColl(amt); } else { - Samus_MoveDown_NoSolidColl(); - projectile_init_speed_samus_moved_down_fract = R20_; - projectile_init_speed_samus_moved_down = R18_; + amt = Samus_MoveDown_NoSolidColl(amt); + projectile_init_speed_samus_moved_down_fract = amt; + projectile_init_speed_samus_moved_down = amt >> 16; Samus_MoveDown_SetPoseCalcInput(); } } void Samus_MoveHandler_ReleaseFromGrapple(void) { // 0x90946E - if (samus_y_dir == 1 && (samus_y_speed & 0x8000u) != 0) { + if (samus_y_dir == 1 && (samus_y_speed & 0x8000) != 0) { samus_y_subspeed = 0; samus_y_speed = 0; samus_y_dir = 2; samus_movement_handler = FUNC16(Samus_MovementHandler_Normal); } samus_x_accel_mode = 2; - Samus_CalcBaseSpeed_X(Samus_DetermineGrappleSwingSpeed_X()); + int32 amt = Samus_CalcBaseSpeed_X(Samus_DetermineGrappleSwingSpeed_X()); if (samus_x_accel_mode || (joypad1_lastkeys & kButton_Right) != 0 || (joypad1_lastkeys & kButton_Left) != 0) { - Samus_MoveX(); + Samus_MoveX(amt); } else { - R18_ = 0; - R20_ = 0; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_collision_flag = 0; @@ -1407,28 +1276,28 @@ void CallScrollingFinishedHook(uint32 ea) { void MainScrollingRoutine(void) { // 0x9094EC if (slow_grabble_scrolling_flag) { - if ((samus_x_pos & 0x8000u) != 0) + if ((samus_x_pos & 0x8000) != 0) goto LABEL_14; uint16 v0; v0 = samus_x_pos - layer1_x_pos; if (samus_x_pos < layer1_x_pos) goto LABEL_7; - if (v0 >= 0xA0u) { + if (v0 >= 0xA0) { layer1_x_pos += 3; goto LABEL_8; } - if (v0 < 0x60u) + if (v0 < 0x60) LABEL_7: layer1_x_pos -= 3; LABEL_8: - if ((samus_y_pos & 0x8000u) == 0) { + if ((samus_y_pos & 0x8000) == 0) { uint16 v1 = samus_y_pos - layer1_y_pos; if (samus_y_pos >= layer1_y_pos) { - if (v1 >= 0x90u) { + if (v1 >= 0x90) { layer1_y_pos += 3; goto LABEL_14; } - if (v1 >= 0x70u) + if (v1 >= 0x70) goto LABEL_14; } layer1_y_pos -= 3; @@ -1452,7 +1321,7 @@ LABEL_16: } void Samus_ScrollFinishedHook_SporeSpawnFight(void) { // 0x909589 - if (layer1_y_pos <= 0x1D0u) + if (layer1_y_pos <= 0x1D0) layer1_y_pos = 464; } @@ -1465,7 +1334,7 @@ void Samus_HandleScroll_X(void) { // 0x9095A0 HandleAutoscrolling_X(); return; } - R18_ = layer1_x_pos; + // r18 = layer1_x_pos; if (knockback_dir || samus_movement_type == 16 || samus_x_accel_mode == 1) { if (samus_pose_x_dir == 4) { LABEL_9: @@ -1496,7 +1365,7 @@ void Samus_HandleScroll_Y(void) { // 0x90964F if (samus_prev_y_pos == samus_y_pos) { HandleAutoscrolling_Y(); } else { - R18_ = layer1_y_pos; + //r18 = layer1_y_pos; if (samus_y_dir == 1) ideal_layer1_ypos = samus_y_pos - down_scroller; else @@ -1524,28 +1393,20 @@ static const uint16 g_word_909EAD = 1; void Samus_CalcDistanceMoved_X(void) { // 0x9096C0 if ((int16)(samus_x_pos - samus_prev_x_pos) >= 0) { absolute_moved_last_frame_x_fract = samus_x_subpos - samus_prev_x_subpos; - absolute_moved_last_frame_x = g_word_909EAD - + ((__PAIR32__(samus_x_pos, samus_x_subpos) - - __PAIR32__(samus_prev_x_pos, samus_prev_x_subpos)) >> 16); + absolute_moved_last_frame_x = g_word_909EAD + ((__PAIR32__(samus_x_pos, samus_x_subpos) - __PAIR32__(samus_prev_x_pos, samus_prev_x_subpos)) >> 16); } else { absolute_moved_last_frame_x_fract = samus_prev_x_subpos - samus_x_subpos; - absolute_moved_last_frame_x = g_word_909EAD - + ((__PAIR32__(samus_prev_x_pos, samus_prev_x_subpos) - - __PAIR32__(samus_x_pos, samus_x_subpos)) >> 16); + absolute_moved_last_frame_x = g_word_909EAD + ((__PAIR32__(samus_prev_x_pos, samus_prev_x_subpos) - __PAIR32__(samus_x_pos, samus_x_subpos)) >> 16); } } void Samus_CalcDistanceMoved_Y(void) { // 0x9096FF if ((int16)(samus_y_pos - samus_prev_y_pos) >= 0) { absolute_moved_last_frame_y_fract = samus_y_subpos - samus_prev_y_subpos; - absolute_moved_last_frame_y = g_word_909EAD - + ((__PAIR32__(samus_y_pos, samus_y_subpos) - - __PAIR32__(samus_prev_y_pos, samus_prev_y_subpos)) >> 16); + absolute_moved_last_frame_y = g_word_909EAD + ((__PAIR32__(samus_y_pos, samus_y_subpos) - __PAIR32__(samus_prev_y_pos, samus_prev_y_subpos)) >> 16); } else { absolute_moved_last_frame_y_fract = samus_prev_y_subpos - samus_y_subpos; - absolute_moved_last_frame_y = g_word_909EAD - + ((__PAIR32__(samus_prev_y_pos, samus_prev_y_subpos) - - __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16); + absolute_moved_last_frame_y = g_word_909EAD + ((__PAIR32__(samus_prev_y_pos, samus_prev_y_subpos) - __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16); } } @@ -1558,9 +1419,9 @@ static const uint16 kSamus_HandleExtraRunspeedX_Tab5[3] = { 0, 0, 0 }; void Samus_HandleExtraRunspeedX(void) { // 0x90973E if ((equipped_items & 0x20) == 0) { - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) { + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) { LABEL_24: if (!samus_has_momentum_flag) { samus_x_extra_run_speed = 0; @@ -1568,7 +1429,7 @@ LABEL_24: } goto LABEL_26; } - } else if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { goto LABEL_24; } } @@ -1608,46 +1469,24 @@ LABEL_26: samus_contact_damage_index = 1; } -void Samus_MoveRight_NoColl(void) { // 0x909826 - bool v0 = __CFADD__uint16(R20_, samus_x_subpos); - samus_x_subpos += R20_; - samus_x_pos += R18_ + v0; - projectile_init_speed_samus_moved_right_fract = R20_; - projectile_init_speed_samus_moved_right = R18_; +void Samus_MoveRight_NoColl(int32 amt) { // 0x909826 + AddToHiLo(&samus_x_pos, &samus_x_subpos, amt); + SetHiLo(&projectile_init_speed_samus_moved_right, &projectile_init_speed_samus_moved_right_fract, amt); } -void Samus_MoveLeft_NoColl(void) { // 0x909842 - uint16 v0 = (__PAIR32__(samus_x_pos, samus_x_subpos) - __PAIR32__(R18_, R20_)) >> 16; - samus_x_subpos -= R20_; - samus_x_pos = v0; - R18_ = ~R18_; - bool v1 = R20_ == 0; - R20_ = -R20_; - if (v1) - ++R18_; - projectile_init_speed_samus_moved_left_fract = R20_; - projectile_init_speed_samus_moved_left = R18_; +void Samus_MoveLeft_NoColl(int32 amt) { // 0x909842 + AddToHiLo(&samus_x_pos, &samus_x_subpos, -amt); + SetHiLo(&projectile_init_speed_samus_moved_left, &projectile_init_speed_samus_moved_left_fract, -amt); } -void Samus_MoveDown_NoColl(void) { // 0x909871 - bool v0 = __CFADD__uint16(R20_, samus_y_subpos); - samus_y_subpos += R20_; - samus_y_pos += R18_ + v0; - projectile_init_speed_samus_moved_down_fract = R20_; - projectile_init_speed_samus_moved_down = R18_; +void Samus_MoveDown_NoColl(int32 amt) { // 0x909871 + AddToHiLo(&samus_y_pos, &samus_y_subpos, amt); + SetHiLo(&projectile_init_speed_samus_moved_down, &projectile_init_speed_samus_moved_down_fract, amt); } -void Samus_MoveUp_NoColl(void) { // 0x90988D - uint16 v0 = (__PAIR32__(samus_y_pos, samus_y_subpos) - __PAIR32__(R18_, R20_)) >> 16; - samus_y_subpos -= R20_; - samus_y_pos = v0; - R18_ = ~R18_; - bool v1 = R20_ == 0; - R20_ = -R20_; - if (v1) - ++R18_; - projectile_init_speed_samus_moved_up_fract = R20_; - projectile_init_speed_samus_moved_up = R18_; +void Samus_MoveUp_NoColl(int32 amt) { // 0x90988D + AddToHiLo(&samus_y_pos, &samus_y_subpos, -amt); + SetHiLo(&projectile_init_speed_samus_moved_up, &projectile_init_speed_samus_moved_up_fract, -amt); } void Samus_InitJump(void) { // 0x9098BC @@ -1659,9 +1498,9 @@ void Samus_InitJump(void) { // 0x9098BC if ((equipped_items & 0x20) != 0) goto LABEL_7; - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) == 0) { - if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) == 0) { + if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { v0 = 2; goto LABEL_11; } @@ -1669,7 +1508,7 @@ LABEL_7: v0 = 0; goto LABEL_11; } - if ((lava_acid_y_pos & 0x8000u) != 0 || !sign16(lava_acid_y_pos - R18_)) + if ((lava_acid_y_pos & 0x8000) != 0 || !sign16(lava_acid_y_pos - r18)) goto LABEL_7; v0 = 4; LABEL_11:; @@ -1682,7 +1521,6 @@ LABEL_11:; samus_y_speed = kSamus_InitJump_Speed_Y[v1]; } if ((equipped_items & 0x2000) != 0) { - R18_ = samus_x_extra_run_speed >> 1; samus_y_subspeed += samus_x_extra_run_subspeed; samus_y_speed += samus_x_extra_run_speed >> 1; } @@ -1700,9 +1538,9 @@ void Samus_InitWallJump(void) { // 0x909949 if ((equipped_items & 0x20) != 0) goto LABEL_7; - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) == 0) { - if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) == 0) { + if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { v0 = 2; goto LABEL_11; } @@ -1710,7 +1548,7 @@ LABEL_7: v0 = 0; goto LABEL_11; } - if ((lava_acid_y_pos & 0x8000u) != 0 || !sign16(lava_acid_y_pos - R18_)) + if ((lava_acid_y_pos & 0x8000) != 0 || !sign16(lava_acid_y_pos - r18)) goto LABEL_7; v0 = 4; LABEL_11:; @@ -1723,7 +1561,7 @@ LABEL_11:; samus_y_speed = kSamus_InitWallJump_0[v1]; } if ((equipped_items & 0x2000) != 0) { - R18_ = samus_x_extra_run_speed >> 1; + r18 = samus_x_extra_run_speed >> 1; samus_y_subspeed += samus_x_extra_run_subspeed; samus_y_speed += samus_x_extra_run_speed >> 1; } @@ -1739,13 +1577,13 @@ void Samus_SetSpeedForKnockback_Y(void) { // 0x9099D6 uint16 v0; if ((equipped_items & 0x20) == 0) { - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) { + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) { v0 = 4; goto LABEL_11; } - } else if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { v0 = 2; goto LABEL_11; } @@ -1766,13 +1604,13 @@ void Samus_InitBombJump(void) { // 0x909A2C uint16 v0; if ((equipped_items & 0x20) == 0) { - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) { + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) { v0 = 4; goto LABEL_11; } - } else if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { v0 = 2; goto LABEL_11; } @@ -1787,26 +1625,20 @@ LABEL_11:; samus_y_dir = 1; } -void Samus_CalcBaseSpeed_X(uint16 k) { // 0x909A7E - SamusSpeedTableEntry *v1; - SamusSpeedTableEntry *v4; - SamusSpeedTableEntry *v5; - SamusSpeedTableEntry *sste; - SamusSpeedTableEntry *v7; - int16 v8; +int32 Samus_CalcBaseSpeed_X(uint16 k) { // 0x909A7E + SamusSpeedTableEntry *sste = get_SamusSpeedTableEntry(k); + uint16 r18, r20; if (samus_x_accel_mode) { if (samus_x_decel_mult) { - sste = get_SamusSpeedTableEntry(k); - R20_ = Mult8x8(samus_x_decel_mult, HIBYTE(sste->decel_sub)); - R18_ = Mult8x8(samus_x_decel_mult, sste->decel) >> 8; + r20 = Mult8x8(samus_x_decel_mult, HIBYTE(sste->decel_sub)); + r18 = Mult8x8(samus_x_decel_mult, sste->decel) >> 8; } else { - v7 = get_SamusSpeedTableEntry(k); - R20_ = v7->decel_sub; - R18_ = v7->decel; + r20 = sste->decel_sub; + r18 = sste->decel; } - v8 = (__PAIR32__(samus_x_base_speed, samus_x_base_subspeed) - __PAIR32__(R18_, R20_)) >> 16; - samus_x_base_subspeed -= R20_; + int16 v8 = (__PAIR32__(samus_x_base_speed, samus_x_base_subspeed) - __PAIR32__(r18, r20)) >> 16; + samus_x_base_subspeed -= r20; samus_x_base_speed = v8; if (v8 < 0) { samus_x_base_speed = 0; @@ -1814,45 +1646,36 @@ void Samus_CalcBaseSpeed_X(uint16 k) { // 0x909A7E samus_x_accel_mode = 0; } } else { - v1 = get_SamusSpeedTableEntry(k); - bool v2 = __CFADD__uint16(v1->accel_sub, samus_x_base_subspeed); - samus_x_base_subspeed += v1->accel_sub; - uint16 v3 = v1->accel + v2 + samus_x_base_speed; + bool v2 = __CFADD__uint16(sste->accel_sub, samus_x_base_subspeed); + samus_x_base_subspeed += sste->accel_sub; + uint16 v3 = sste->accel + v2 + samus_x_base_speed; samus_x_base_speed = v3; - if ((int16)(v3 - v1->max_speed) >= 0) { - if (v3 != v1->max_speed - || (v5 = get_SamusSpeedTableEntry(k), (int16)(samus_x_base_subspeed - v5->max_speed_sub) >= 0) - && samus_x_base_subspeed != v5->max_speed_sub) { - v4 = get_SamusSpeedTableEntry(k); - samus_x_base_speed = v4->max_speed; - samus_x_base_subspeed = v4->max_speed_sub; + if ((int16)(v3 - sste->max_speed) >= 0) { + if (v3 != sste->max_speed + || ((int16)(samus_x_base_subspeed - sste->max_speed_sub) >= 0) + && samus_x_base_subspeed != sste->max_speed_sub) { + samus_x_base_speed = sste->max_speed; + samus_x_base_subspeed = sste->max_speed_sub; } } } - R18_ = samus_x_base_speed; - R20_ = samus_x_base_subspeed; + return __PAIR32__(samus_x_base_speed, samus_x_base_subspeed); } -uint8 Samus_CalcBaseSpeed_NoDecel_X(uint16 k) { // 0x909B1F - SamusSpeedTableEntry *v1; - SamusSpeedTableEntry *v4; - SamusSpeedTableEntry *v5; - SamusSpeedTableEntry *sste; - SamusSpeedTableEntry *v7; - int16 v8; +static Pair_Bool_Amt Samus_CalcBaseSpeed_NoDecel_X(uint16 k) { // 0x909B1F + uint16 r18, r20; + SamusSpeedTableEntry *sste = get_SamusSpeedTableEntry(k); if ((samus_x_accel_mode & 1) != 0) { if (samus_x_decel_mult) { - sste = get_SamusSpeedTableEntry(k); - R20_ = Mult8x8(samus_x_decel_mult, HIBYTE(sste->decel_sub)); - R18_ = Mult8x8(samus_x_decel_mult, sste->decel) >> 8; + r20 = Mult8x8(samus_x_decel_mult, HIBYTE(sste->decel_sub)); + r18 = Mult8x8(samus_x_decel_mult, sste->decel) >> 8; } else { - v7 = get_SamusSpeedTableEntry(k); - R20_ = v7->decel_sub; - R18_ = v7->decel; + r20 = sste->decel_sub; + r18 = sste->decel; } - v8 = (__PAIR32__(samus_x_base_speed, samus_x_base_subspeed) - __PAIR32__(R18_, R20_)) >> 16; - samus_x_base_subspeed -= R20_; + int16 v8 = (__PAIR32__(samus_x_base_speed, samus_x_base_subspeed) - __PAIR32__(r18, r20)) >> 16; + samus_x_base_subspeed -= r20; samus_x_base_speed = v8; if (v8 < 0) { samus_x_base_speed = 0; @@ -1860,53 +1683,46 @@ uint8 Samus_CalcBaseSpeed_NoDecel_X(uint16 k) { // 0x909B1F samus_x_accel_mode = 0; } } else { - v1 = get_SamusSpeedTableEntry(k); - bool v2 = __CFADD__uint16(v1->accel_sub, samus_x_base_subspeed); - samus_x_base_subspeed += v1->accel_sub; - uint16 v3 = v1->accel + v2 + samus_x_base_speed; + bool v2 = __CFADD__uint16(sste->accel_sub, samus_x_base_subspeed); + samus_x_base_subspeed += sste->accel_sub; + uint16 v3 = sste->accel + v2 + samus_x_base_speed; samus_x_base_speed = v3; - if ((int16)(v3 - v1->max_speed) >= 0) { - if (v3 != v1->max_speed - || (v5 = get_SamusSpeedTableEntry(k), (int16)(samus_x_base_subspeed - v5->max_speed_sub) >= 0) - && samus_x_base_subspeed != v5->max_speed_sub) { - v4 = get_SamusSpeedTableEntry(k); - samus_x_base_speed = v4->max_speed; - samus_x_base_subspeed = v4->max_speed_sub; - R18_ = samus_x_base_speed; - R20_ = samus_x_base_subspeed; - return 1; + if ((int16)(v3 - sste->max_speed) >= 0) { + if (v3 != sste->max_speed + || ((int16)(samus_x_base_subspeed - sste->max_speed_sub) >= 0) + && samus_x_base_subspeed != sste->max_speed_sub) { + samus_x_base_speed = sste->max_speed; + samus_x_base_subspeed = sste->max_speed_sub; + return (Pair_Bool_Amt) { true, __PAIR32__(samus_x_base_speed, samus_x_base_subspeed) }; } } } - R18_ = samus_x_base_speed; - R20_ = samus_x_base_subspeed; - return 0; + return (Pair_Bool_Amt) { false, __PAIR32__(samus_x_base_speed, samus_x_base_subspeed) }; } uint16 Samus_DetermineSpeedTableEntryPtr_X(void) { // 0x909BD1 if ((equipped_items & 0x20) == 0) { - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) samus_x_speed_table_pointer = addr_kSamusSpeedTable_LavaAcid_X; - } else if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { samus_x_speed_table_pointer = addr_kSamusSpeedTable_Water_X; } } - R20_ = samus_movement_type; return samus_x_speed_table_pointer + 12 * samus_movement_type; } uint16 Samus_DetermineGrappleSwingSpeed_X(void) { // 0x909C21 if ((equipped_items & 0x20) != 0) return addr_stru_909F31; - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) == 0) { - if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) == 0) { + if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) return addr_stru_909F3D; return addr_stru_909F31; } - if ((lava_acid_y_pos & 0x8000u) != 0 || !sign16(lava_acid_y_pos - R18_)) + if ((lava_acid_y_pos & 0x8000) != 0 || !sign16(lava_acid_y_pos - r18)) return addr_stru_909F31; return addr_kSamusSpeedTable_Normal_X; } @@ -1922,9 +1738,9 @@ void Samus_DetermineAccel_Y(void) { // 0x909C5B if ((equipped_items & 0x20) != 0) goto LABEL_7; - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) == 0) { - if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) == 0) { + if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { samus_y_subaccel = g_word_909EA3; samus_y_accel = g_word_909EA9; return; @@ -1934,42 +1750,35 @@ LABEL_7: samus_y_accel = g_word_909EA7; return; } - if ((lava_acid_y_pos & 0x8000u) != 0 || !sign16(lava_acid_y_pos - R18_)) + if ((lava_acid_y_pos & 0x8000) != 0 || !sign16(lava_acid_y_pos - r18)) goto LABEL_7; samus_y_subaccel = g_word_909EA5; samus_y_accel = g_word_909EAB; } -uint8 Samus_GrappleWallJumpCheck(void) { // 0x909CAC +uint8 Samus_GrappleWallJumpCheck(int32 amt) { // 0x909CAC enemy_index_to_shake = -1; if (samus_pose_x_dir != 4) { if (samus_pose_x_dir != 8) return 0; samus_collision_direction = 1; - if (!Samus_CheckSolidEnemyColl()) - return WallJumpBlockCollDetect() & 1 && (button_config_jump_a & joypad1_newkeys) != 0; - if ((button_config_jump_a & joypad1_newkeys) == 0) - return 0; - goto LABEL_17; + } else { + samus_collision_direction = 0; } - samus_collision_direction = 0; - if (!Samus_CheckSolidEnemyColl()) { - R18_ = ~R18_; - bool v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - return WallJumpBlockCollDetect() & 1 && (button_config_jump_a & joypad1_newkeys) != 0; + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + if (!cres.collision) { + amt = WallJumpBlockCollDetect(cres.amt); + return samus_collision_flag && (button_config_jump_a & joypad1_newkeys) != 0; } - if ((button_config_jump_a & joypad1_newkeys) != 0) { -LABEL_17: - enemy_index_to_shake = R22_; - return 1; - } - return 0; + if ((button_config_jump_a & joypad1_newkeys) == 0) + return 0; + enemy_index_to_shake = collision_detection_index; + return 1; } -uint8 Samus_WallJumpCheck(void) { // 0x909D35 +uint8 Samus_WallJumpCheck(int32 amt) { // 0x909D35 + CheckEnemyColl_Result cres; + if (samus_last_different_pose_movement_type != 3 && samus_last_different_pose_movement_type != 20) return 0; if (samus_pose == kPose_81_FaceR_Screwattack || samus_pose == kPose_82_FaceL_Screwattack) { @@ -1983,71 +1792,76 @@ LABEL_8: if ((joypad1_lastkeys & kButton_Right) == 0) return 0; samus_collision_direction = 0; - if (!Samus_CheckSolidEnemyColl()) { - R18_ = ~R18_; - bool v1 = R20_ == 0; - R20_ = -R20_; - if (v1) - ++R18_; - if (!(WallJumpBlockCollDetect() & 1)) + cres = Samus_CheckSolidEnemyColl(amt); + amt = cres.amt; + if (!cres.collision) { + amt = WallJumpBlockCollDetect(-amt); + if (!samus_collision_flag) return 0; } - goto LABEL_18; - } - samus_collision_direction = 1; - if (Samus_CheckSolidEnemyColl() || WallJumpBlockCollDetect() & 1) { -LABEL_18: - if (samus_pose == kPose_81_FaceR_Screwattack || samus_pose == kPose_82_FaceL_Screwattack) { - samus_anim_frame_timer = 1; - samus_anim_frame = 26; - } else { - samus_anim_frame_timer = 1; - samus_anim_frame = 10; + } else { + samus_collision_direction = 1; + cres = Samus_CheckSolidEnemyColl(amt); + amt = cres.amt; + if (!cres.collision) { + amt = WallJumpBlockCollDetect(amt); + if (!samus_collision_flag) + return 0; } } + if (samus_pose == kPose_81_FaceR_Screwattack || samus_pose == kPose_82_FaceL_Screwattack) { + samus_anim_frame_timer = 1; + samus_anim_frame = 26; + } else { + samus_anim_frame_timer = 1; + samus_anim_frame = 10; + } return 0; } LABEL_22: enemy_index_to_shake = -1; if ((joypad1_lastkeys & kButton_Left) != 0) { samus_collision_direction = 1; - if (!Samus_CheckSolidEnemyColl()) { - if (!(WallJumpBlockCollDetect() & 1) || (button_config_jump_a & joypad1_newkeys) == 0) - return 0; - goto LABEL_40; + cres = Samus_CheckSolidEnemyColl(amt), amt = cres.amt; + if (!cres.collision) { + amt = WallJumpBlockCollDetect(amt); + if (samus_collision_flag && (button_config_jump_a & joypad1_newkeys) != 0) + goto LABEL_40; + return 0; } if ((button_config_jump_a & joypad1_newkeys) == 0) return 0; -LABEL_38: - if (sign16(R18_ - 8)) { + goto LABEL_38; + } else { + if ((joypad1_lastkeys & kButton_Right) == 0) + return 0; + samus_collision_direction = 0; + cres = Samus_CheckSolidEnemyColl(amt), amt = cres.amt; + if (!cres.collision) { + amt = -amt; + WallJumpBlockCollDetect(amt); + if (samus_collision_flag && (button_config_jump_a & joypad1_newkeys) != 0) + goto LABEL_40; + return 0; + } + if ((button_config_jump_a & joypad1_newkeys) == 0) + return 0; + goto LABEL_38; + +LABEL_40: + if (sign16((amt >> 16) - 8)) { input_to_pose_calc = 5; - enemy_index_to_shake = R22_; + return 1; + } + return 0; +LABEL_38: + if (sign16((amt >> 16) - 8)) { + input_to_pose_calc = 5; + enemy_index_to_shake = collision_detection_index; return 1; } return 0; } - if ((joypad1_lastkeys & kButton_Right) == 0) - return 0; - samus_collision_direction = 0; - if (Samus_CheckSolidEnemyColl()) { - if ((button_config_jump_a & joypad1_newkeys) == 0) - return 0; - goto LABEL_38; - } - R18_ = ~R18_; - bool v1; - v1 = R20_ == 0; - R20_ = -R20_; - if (v1) - ++R18_; - if (!(WallJumpBlockCollDetect() & 1) || (button_config_jump_a & joypad1_newkeys) == 0) - return 0; -LABEL_40: - if (sign16(R18_ - 8)) { - input_to_pose_calc = 5; - return 1; - } - return 0; } void Samus_Movement_07_Unused(void) { // 0x90A32D @@ -2110,9 +1924,7 @@ void Samus_Movement_00_Standing(void) { // 0x90A383 } else { if (elevator_status) { samus_collision_direction = 2; - R18_ = 1; - R20_ = 0; - Samus_MoveDown_NoSolidColl(); + Samus_MoveDown_NoSolidColl(INT16_SHL16(1)); } input_to_pose_calc = 0; } @@ -2126,7 +1938,7 @@ void Samus_Movement_01_Running(void) { // 0x90A3E5 if (kSamusFootstepFrame[samus_anim_frame]) { Samus_FootstepGraphics(); if (!cinematic_function && !boss_id && !samus_shine_timer && (speed_boost_counter & 0x400) == 0) - QueueSfx3_Max6(6u); + QueueSfx3_Max6(6); } } } @@ -2142,53 +1954,43 @@ void Samus_Movement_03_SpinJumping(void) { // 0x90A436 static const uint16 kSamusPhys_JumpMaxYVelAir = 0x500; static const uint16 kSamusPhys_JumpMinYVelWater = 0x80; static const uint16 kSamusPhys_JumpMaxYVelWater = 0x500; - + uint16 r18 = 0; if ((samus_suit_palette_index & 4) == 0) { - Samus_GetTopBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R20_)) - goto LABEL_8; - } else if (sign16(fx_y_pos - R20_) && (fx_liquid_options & 4) == 0) { -LABEL_8: - R18_ = 1; - goto LABEL_10; + uint16 r20 = Samus_GetTop_R20(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r20)) + r18 = 1; + } else if (sign16(fx_y_pos - r20) && (fx_liquid_options & 4) == 0) { + r18 = 1; } } - R18_ = 0; -LABEL_10: - if (R18_) - goto LABEL_26; - if ((equipped_items & 0x200) != 0) { - if (samus_y_dir != 2) - goto LABEL_24; - if (liquid_physics_type) { - if ((int16)(*(uint16 *)((uint8 *)&samus_y_subspeed + 1) - kSamusPhys_JumpMinYVelWater) < 0 + if (!r18) { + if ((equipped_items & 0x200) != 0) { + if (samus_y_dir != 2) + goto LABEL_24; + if (liquid_physics_type) { + if ((int16)(*(uint16 *)((uint8 *)&samus_y_subspeed + 1) - kSamusPhys_JumpMinYVelWater) < 0 || (int16)(*(uint16 *)((uint8 *)&samus_y_subspeed + 1) - kSamusPhys_JumpMaxYVelWater) >= 0) { + goto LABEL_24; + } + } else if ((int16)(*(uint16 *)((uint8 *)&samus_y_subspeed + 1) - kSamusPhys_JumpMinYVelAir) < 0 + || (int16)(*(uint16 *)((uint8 *)&samus_y_subspeed + 1) - kSamusPhys_JumpMaxYVelAir) >= 0) { goto LABEL_24; } - } else if ((int16)(*(uint16 *)((uint8 *)&samus_y_subspeed + 1) - kSamusPhys_JumpMinYVelAir) < 0 - || (int16)(*(uint16 *)((uint8 *)&samus_y_subspeed + 1) - kSamusPhys_JumpMaxYVelAir) >= 0) { - goto LABEL_24; + UNUSED_word_7E0DFA = UNUSED_word_7E0DFA & 0xFF00 | 1; + if ((button_config_jump_a & joypad1_newkeys) != 0) + Samus_InitJump(); // bug: this overwrites r18 } - UNUSED_word_7E0DFA = UNUSED_word_7E0DFA & 0xFF00 | 1; - if ((button_config_jump_a & joypad1_newkeys) != 0) - Samus_InitJump(); -LABEL_24: - if (samus_pose == kPose_81_FaceR_Screwattack || samus_pose == kPose_82_FaceL_Screwattack) - goto LABEL_33; - goto LABEL_26; +LABEL_24:; + if (samus_pose == kPose_81_FaceR_Screwattack || samus_pose == kPose_82_FaceL_Screwattack) { + samus_contact_damage_index = 3; + } else if (!sign16(flare_counter - 60)) { + samus_contact_damage_index = 4; + } + } else { + if (samus_anim_frame_timer == 1 && kSamusFramesForUnderwaterSfx[samus_anim_frame]) + QueueSfx1_Max6(0x2F); } - if (samus_pose == kPose_81_FaceR_Screwattack || samus_pose == kPose_82_FaceL_Screwattack) { -LABEL_33: - samus_contact_damage_index = 3; - goto LABEL_34; - } -LABEL_26: - if (R18_ && samus_anim_frame_timer == 1 && kSamusFramesForUnderwaterSfx[samus_anim_frame]) - QueueSfx1_Max6(0x2Fu); - if (!sign16(flare_counter - 60) && !R18_) - samus_contact_damage_index = 4; -LABEL_34: Samus_SpinJumpMovement(); } @@ -2437,6 +2239,17 @@ void Samus_Movement_1B_ShinesparkEtc(void) { // 0x90A7DA input_to_pose_calc = 0; } +static const uint8 kShr0x80[8] = { 0x80, 0x40, 0x20, 0x10, 8, 4, 2, 1 }; +static const uint16 kShr0xFc00[8] = { 0xfc00, 0x7e00, 0x3f00, 0x1f80, 0xfc0, 0x7e0, 0x3f0, 0x1f8 }; + +static void MarkMapTileAsExplored(uint16 r18, uint16 r24) { // 0x90A8A6 + uint8 v0 = (uint16)(r18 & 0xFF00) >> 8; + uint16 R34 = (room_x_coordinate_on_map + v0) & 0x20; + uint16 r20 = ((room_x_coordinate_on_map + v0) & 0x1F) >> 3; + uint16 R22 = room_y_coordinate_on_map + ((r24 & 0xFF00) >> 8) + 1; + map_tiles_explored[(uint16)(r20 + 4 * (R34 + R22))] |= kShr0x80[(room_x_coordinate_on_map + v0) & 7]; +} + void DisableMinimapAndMarkBossRoomAsExplored(void) { // 0x90A7E2 debug_disable_minimap = 1; uint16 v0 = 0; @@ -2449,212 +2262,194 @@ void DisableMinimapAndMarkBossRoomAsExplored(void) { // 0x90A7E2 } while ((int16)(v0 - 10) < 0); uint16 v2 = 5; while (boss_id != g_stru_90A83A[v2].boss_id_) { - if ((--v2 & 0x8000u) != 0) + if ((--v2 & 0x8000) != 0) return; } for (int i = g_stru_90A83A[v2].ptrs; ; i += 4) { const uint16 *v4 = (const uint16 *)RomPtr_90(i); - if ((*v4 & 0x8000u) != 0) + if ((*v4 & 0x8000) != 0) break; - R18_ = *v4; - R24_ = v4[1]; - MarkMapTileAsExplored(); + MarkMapTileAsExplored(v4[0], v4[1]); } } -static const uint8 kShr0x80[8] = { 0x80, 0x40, 0x20, 0x10, 8, 4, 2, 1 }; -static const uint16 kShr0xFc00[8] = { 0xfc00, 0x7e00, 0x3f00, 0x1f80, 0xfc0, 0x7e0, 0x3f0, 0x1f8 }; - -void MarkMapTileAsExplored(void) { // 0x90A8A6 - uint8 v0 = (uint16)(R18_ & 0xFF00) >> 8; - R34 = (room_x_coordinate_on_map + v0) & 0x20; - R18_ = ((uint8)room_x_coordinate_on_map + v0) & 0x1F; - R20_ = (uint8)((room_x_coordinate_on_map + v0) & 0x1F) >> 3; - R22_ = room_y_coordinate_on_map + (uint8)((uint16)(R24_ & 0xFF00) >> 8) + 1; - map_tiles_explored[(uint16)(R20_ + 4 * (R34 + R22_))] |= kShr0x80[((uint8)room_x_coordinate_on_map + v0) & 7]; -} - void InitializeMiniMapBroken(void) { // 0x90A8EF - R18_ = room_x_coordinate_on_map + (uint8)((uint16)(samus_x_pos & 0xFF00) >> 8); - R20_ = R18_ >> 3; - R22_ = room_y_coordinate_on_map + (uint8)((uint16)(samus_y_pos & 0xFF00) >> 8) + 1; - UpdateMinimapInside(); + //SetR18_R20(room_x_coordinate_on_map + ((samus_x_pos & 0xFF00) >> 8), r18 >> 3); + //R22_ = room_y_coordinate_on_map + ((samus_y_pos & 0xFF00) >> 8) + 1; + //UpdateMinimapInside(); } void UpdateMinimap(void) { // 0x90A91B int16 v4; int16 v10; - int16 v11; + LongPtr r9; - if (!debug_disable_minimap - && (uint16)(samus_x_pos >> 4) < room_width_in_blocks - && (uint16)(samus_y_pos >> 4) < room_height_in_blocks) { - R46 = 0; - uint8 v0 = (uint16)(samus_x_pos & 0xFF00) >> 8; - R34 = (room_x_coordinate_on_map + v0) & 0x20; - R18_ = ((uint8)room_x_coordinate_on_map + v0) & 0x1F; - uint16 v1 = ((uint8)room_x_coordinate_on_map + v0) & 7; - R20_ = (uint8)((room_x_coordinate_on_map + v0) & 0x1F) >> 3; - R22_ = room_y_coordinate_on_map + (uint8)((uint16)(samus_y_pos & 0xFF00) >> 8) + 1; - uint16 v2 = R20_ + 4 * (R34 + R22_); - map_tiles_explored[v2] |= kShr0x80[((uint8)room_x_coordinate_on_map + v0) & 7]; - R32_ = v1; - R30_ = v2; - uint16 v3 = v2 - 4; - v4 = v1 - 2; - if ((int16)(v1 - 2) < 0) { - v4 &= 7u; - --v3; - ++R46; - } - R50 = v3; - bg3_tilemap_offset = 2 * v4; - int v6 = bg3_tilemap_offset >> 1; - R24_ = kShr0xFc00[v6] & swap16(*(uint16 *)&map_tiles_explored[v3]); - R26_ = kShr0xFc00[v6] & swap16(*(uint16 *)&map_tiles_explored[v3 + 4]); - R28_ = kShr0xFc00[v6] & swap16(*(uint16 *)&map_tiles_explored[v3 + 8]); - R9_.bank = 130; - R9_.addr = kPauseMenuMapData[area_index]; - *(uint16 *)((uint8 *)&R14_ + 1) = R9_.addr; - R9_.addr += v3; - R38 = swap16(IndirReadWord(R9_, 0)); - R9_.addr += 4; - R40 = swap16(IndirReadWord(R9_, 0)); - R9_.addr += 4; - R42 = swap16(IndirReadWord(R9_, 0)); - if ((R50 & 3) == 3) { - v10 = R46 ? bg3_tilemap_offset >> 1 : R32_; - if (!sign16(v10 - 6)) { - if (R34) - LOBYTE(R48) = R50 - 124; - else - LOBYTE(R48) = R50 + 125; - AdjustMapBitsForMapPageSpill(); + if (debug_disable_minimap || (samus_x_pos >> 4) >= room_width_in_blocks || + (samus_y_pos >> 4) >= room_height_in_blocks) + return; + uint16 r46 = 0; + uint8 v0 = (uint16)(samus_x_pos & 0xFF00) >> 8; + uint16 r34 = (room_x_coordinate_on_map + v0) & 0x20; + uint16 r18 = (room_x_coordinate_on_map + v0) & 0x1F; + uint16 v1 = (room_x_coordinate_on_map + v0) & 7; + uint16 r20 = ((room_x_coordinate_on_map + v0) & 0x1F) >> 3; + uint16 r22 = room_y_coordinate_on_map + ((samus_y_pos & 0xFF00) >> 8) + 1; + uint16 v2 = r20 + 4 * (r34 + r22); + map_tiles_explored[v2] |= kShr0x80[(room_x_coordinate_on_map + v0) & 7]; + uint16 r32 = v1; + uint16 r30 = v2; + uint16 v3 = v2 - 4; + v4 = v1 - 2; + if ((int16)(v1 - 2) < 0) { + v4 &= 7; + --v3; + ++r46; + } + uint16 R50 = v3; + bg3_tilemap_offset = 2 * v4; + int v6 = bg3_tilemap_offset >> 1; + uint16 r24 = kShr0xFc00[v6] & swap16(*(uint16 *)&map_tiles_explored[v3]); + uint16 r26 = kShr0xFc00[v6] & swap16(*(uint16 *)&map_tiles_explored[v3 + 4]); + uint16 r28 = kShr0xFc00[v6] & swap16(*(uint16 *)&map_tiles_explored[v3 + 8]); + r9.bank = 130; + r9.addr = kPauseMenuMapData[area_index]; + uint16 r15 = r9.addr; + r9.addr += v3; + uint16 r38 = swap16(IndirReadWord(r9, 0)); + r9.addr += 4; + uint16 r40 = swap16(IndirReadWord(r9, 0)); + r9.addr += 4; + uint16 r42 = swap16(IndirReadWord(r9, 0)); + if ((R50 & 3) == 3) { + v10 = r46 ? bg3_tilemap_offset >> 1 : r32; + if (!sign16(v10 - 6)) { + uint8 R48 = r34 ? (R50 - 124) : (R50 + 125); + + uint16 v0 = (uint8)R48; + uint16 r44 = 0; + r9.addr = r15 + (uint8)R48; + LOBYTE(r44) = map_tiles_explored[(uint8)R48]; + HIBYTE(r44) = IndirReadByte(r9, 0); + if ((uint8)r34 == 32) { + HIBYTE(r38) = HIBYTE(r44); + HIBYTE(r24) = r44; + } else { + LOBYTE(r38) = HIBYTE(r44); + LOBYTE(r24) = r44; + } + LOBYTE(r44) = map_tiles_explored[v0 + 4]; + r9.addr += 4; + HIBYTE(r44) = IndirReadByte(r9, 0); + if ((uint8)r34 == 32) { + HIBYTE(r40) = HIBYTE(r44); + HIBYTE(r26) = r44; + } else { + LOBYTE(r40) = HIBYTE(r44); + LOBYTE(r26) = r44; + } + LOBYTE(r44) = map_tiles_explored[v0 + 8]; + r9.addr += 4; + HIBYTE(r44) = IndirReadByte(r9, 0); + if ((uint8)r34 == 32) { + HIBYTE(r42) = HIBYTE(r44); + HIBYTE(r28) = r44; + } else { + LOBYTE(r42) = HIBYTE(r44); + LOBYTE(r28) = r44; } } - v11 = bg3_tilemap_offset >> 1; - for (int i = bg3_tilemap_offset >> 1 == 0; !i; i = v11 == 0) { - R24_ *= 2; - R38 *= 2; - R26_ *= 2; - R40 *= 2; - R28_ *= 2; - R42 *= 2; - --v11; - } - UpdateMinimapInside(); } + for (int n = bg3_tilemap_offset >> 1; n; n--) { + r24 *= 2; + r38 *= 2; + r26 *= 2; + r40 *= 2; + r28 *= 2; + r42 *= 2; + } + UpdateMinimapInside(r18, r22, r34, r30, r32, r38, r24, r40, r26, r42, r28); } -void UpdateMinimapInside(void) { // 0x90AA43 +void UpdateMinimapInside(uint16 r18, uint16 r22, uint16 r34, uint16 r30, uint16 r32, + uint16 r38, uint16 r24, uint16 r40, + uint16 r26, uint16 r42, uint16 r28) { // 0x90AA43 uint16 v0; int16 v1; int16 v5; int16 v7; int16 v8; + LongPtr r0, r3, r6; - LOBYTE(v0) = (uint16)(R34 + R22_) >> 8; - HIBYTE(v0) = R34 + R22_; - remaining_enemy_spritemap_entries = R18_ + (v0 >> 3); - if (R34 && sign16((remaining_enemy_spritemap_entries & 0x1F) - 2)) - v1 = remaining_enemy_spritemap_entries - 1026; + LOBYTE(v0) = (uint16)(r34 + r22) >> 8; + HIBYTE(v0) = r34 + r22; + uint16 t = r18 + (v0 >> 3); + if (r34 && sign16((t & 0x1F) - 2)) + v1 = t - 1026; else - v1 = remaining_enemy_spritemap_entries - 34; + v1 = t - 34; uint16 v2 = 2 * v1; - *(uint16 *)&R0_.bank = *(uint16 *)((uint8 *)kPauseMenuMapTilemaps + 2 + (uint16)(3 * area_index)); - R3_.bank = *(uint16 *)&R0_.bank; - R6_.bank = *(uint16 *)&R0_.bank; - R0_.addr = *(uint16 *)((uint8 *)kPauseMenuMapTilemaps + (uint16)(3 * area_index)); - R3_.addr = R0_.addr + 64; - R6_.addr = R0_.addr + 128; - R18_ = 5; + r0 = kPauseMenuMapTilemaps[area_index]; + r3.bank = r0.bank; + r6.bank = r0.bank; + r3.addr = r0.addr + 64; + r6.addr = r0.addr + 128; + int n = 5; uint16 v3 = 0; do { - bool v4 = R38 >> 15; - R38 *= 2; - if (!v4 || (v5 = IndirReadWord(R0_, v2), !has_area_map)) + bool v4 = r38 >> 15; + r38 *= 2; + if (!v4 || (v5 = IndirReadWord(r0, v2), !has_area_map)) v5 = 31; int v6 = v3 >> 1; hud_tilemap[v6 + 26] = v5 & 0xC3FF | 0x2C00; - v4 = R24_ >> 15; - R24_ *= 2; + + v4 = r24 >> 15; + r24 *= 2; if (v4) - hud_tilemap[v6 + 26] = IndirReadWord(R0_, v2) & 0xC3FF | 0x2800; - v4 = R40 >> 15; - R40 *= 2; - if (!v4 || (v7 = IndirReadWord(R3_, v2), !has_area_map)) + hud_tilemap[v6 + 26] = IndirReadWord(r0, v2) & 0xC3FF | 0x2800; + + v4 = r40 >> 15; + r40 *= 2; + if (!v4 || (v7 = IndirReadWord(r3, v2), !has_area_map)) v7 = 31; hud_tilemap[v6 + 58] = v7 & 0xC3FF | 0x2C00; - v4 = R26_ >> 15; - R26_ *= 2; + + v4 = r26 >> 15; + r26 *= 2; if (v4) { - hud_tilemap[v6 + 58] = IndirReadWord(R3_, v2) & 0xC3FF | 0x2800; - if (R18_ == 3 && (hud_tilemap[v6 + 58] & 0x1FF) == 40) - MarkMapTileAboveSamusAsExplored(); + hud_tilemap[v6 + 58] = IndirReadWord(r3, v2) & 0xC3FF | 0x2800; + if (n == 3 && (hud_tilemap[v6 + 58] & 0x1FF) == 40) { + // MarkMapTileAboveSamusAsExplored + *((uint8 *)&music_data_index + r30) |= kShr0x80[r32]; + } } - v4 = R42 >> 15; - R42 *= 2; - if (!v4 || (v8 = IndirReadWord(R6_, v2), !has_area_map)) + + v4 = r42 >> 15; + r42 *= 2; + if (!v4 || (v8 = IndirReadWord(r6, v2), !has_area_map)) v8 = 31; hud_tilemap[v6 + 90] = v8 & 0xC3FF | 0x2C00; - v4 = R28_ >> 15; - R28_ *= 2; + + v4 = r28 >> 15; + r28 *= 2; if (v4) - hud_tilemap[v6 + 90] = IndirReadWord(R6_, v2) & 0xC3FF | 0x2800; + hud_tilemap[v6 + 90] = IndirReadWord(r6, v2) & 0xC3FF | 0x2800; + v3 += 2; v2 += 2; if ((v2 & 0x3F) == 0) v2 += 1984; - --R18_; - } while (R18_); + } while (--n); if ((nmi_frame_counter_byte & 8) == 0) - hud_tilemap[60] |= 0x1C00u; -} - -void MarkMapTileAboveSamusAsExplored(void) { // 0x90AB5F - *((uint8 *)&music_data_index + R30_) |= kShr0x80[R32_]; -} - -void AdjustMapBitsForMapPageSpill(void) { // 0x90AB75 - uint16 v0 = (uint8)R48; - R9_.addr = *(uint16 *)((uint8 *)&R14_ + 1) + (uint8)R48; - LOBYTE(R44) = map_tiles_explored[(uint8)R48]; - HIBYTE(R44) = IndirReadByte(R9_, 0); - if ((uint8)R34 == 32) { - HIBYTE(R38) = HIBYTE(R44); - HIBYTE(R24_) = R44; - } else { - LOBYTE(R38) = HIBYTE(R44); - LOBYTE(R24_) = R44; - } - LOBYTE(R44) = map_tiles_explored[v0 + 4]; - R9_.addr += 4; - HIBYTE(R44) = IndirReadByte(R9_, 0); - if ((uint8)R34 == 32) { - HIBYTE(R40) = HIBYTE(R44); - HIBYTE(R26_) = R44; - } else { - LOBYTE(R40) = HIBYTE(R44); - LOBYTE(R26_) = R44; - } - LOBYTE(R44) = map_tiles_explored[v0 + 8]; - R9_.addr += 4; - HIBYTE(R44) = IndirReadByte(R9_, 0); - if ((uint8)R34 == 32) { - HIBYTE(R42) = HIBYTE(R44); - HIBYTE(R28_) = R44; - } else { - LOBYTE(R42) = HIBYTE(R44); - LOBYTE(R28_) = R44; - } + hud_tilemap[60] |= 0x1C00; } void Samus_HandleCooldown(void) { // 0x90AC1C if (time_is_frozen_flag) { cooldown_timer = 32; } else if (cooldown_timer) { - if ((cooldown_timer & 0x8000u) != 0 || (--cooldown_timer, (cooldown_timer & 0x8000u) != 0)) + if ((cooldown_timer & 0x8000) != 0 || (--cooldown_timer, (cooldown_timer & 0x8000) != 0)) cooldown_timer = 0; } } @@ -2703,24 +2498,22 @@ void WriteBeamPalette_A(uint16 a) { // 0x90ACC2 } void WriteBeamPalette_Y(uint16 j) { // 0x90ACCD - R0_.bank = 0x90; - R0_.addr = kBeamPalettePtrs[j >> 1]; + uint16 r0 = kBeamPalettePtrs[j >> 1]; uint16 v1 = 0; uint16 v2 = 0; do { - palette_buffer[(v2 >> 1) + 224] = IndirReadWord(R0_, v1); + palette_buffer[(v2 >> 1) + 224] = GET_WORD(RomPtr_90(r0 + v1)); v2 += 2; v1 += 2; } while ((int16)(v1 - 32) < 0); } void LoadProjectilePalette(uint16 a) { // 0x90ACFC - R0_.bank = 0x90; - R0_.addr = kBeamPalettePtrs[a & 0xFFF]; + uint16 r0 = kBeamPalettePtrs[a & 0xFFF]; uint16 v1 = 0; uint16 v2 = 0; do { - palette_buffer[(v2 >> 1) + 224] = IndirReadWord(R0_, v1); + palette_buffer[(v2 >> 1) + 224] = GET_WORD(RomPtr_90(r0 + v1)); v2 += 2; v1 += 2; } while ((int16)(v1 - 32) < 0); @@ -2795,9 +2588,9 @@ void ClearProjectile(uint16 k) { // 0x90ADB7 projectile_spritemap_pointers[v1] = 0; projectile_bomb_pre_instructions[v1] = FUNC16(ProjPreInstr_Empty); if ((int16)(k - 10) >= 0) { - if ((--bomb_counter & 0x8000u) != 0) + if ((--bomb_counter & 0x8000) != 0) bomb_counter = 0; - } else if ((--projectile_counter & 0x8000u) != 0) { + } else if ((--projectile_counter & 0x8000) != 0) { projectile_counter = 0; } } @@ -2905,13 +2698,6 @@ void CallProjPreInstr(uint32 ea, uint16 k) { case fnProjPreInstr_SpreadBomb: ProjPreInstr_SpreadBomb(k); return; case fnProjPreInstr_WaveSba: ProjPreInstr_WaveSba(k); return; case fnProjPreInstr_SpazerSba: ProjPreInstr_SpazerSba(k); return; - case fnProjPreInstr_SpazerSba_FuncA_0: ProjPreInstr_SpazerSba_FuncA_0(k); return; - case fnProjPreInstr_SpazerSba_FuncA_1: ProjPreInstr_SpazerSba_FuncA_1(k); return; - case fnProjPreInstr_SpazerSba_FuncA_2: ProjPreInstr_SpazerSba_FuncA_2(k); return; - case fnProjPreInstr_SpazerSba_FuncA_3: ProjPreInstr_SpazerSba_FuncA_3(k); return; - case fnProjPreInstr_SpazerSba_FuncB_0: ProjPreInstr_SpazerSba_FuncB_0(k); return; - case fnProjPreInstr_SpazerSba_FuncB_1: ProjPreInstr_SpazerSba_FuncB_1(k); return; - case fnProjPreInstr_SpazerSba_FuncB_2: ProjPreInstr_SpazerSba_FuncB_2(k); return; case fnProjPreInstr_EndOfSpazerSba: ProjPreInstr_EndOfSpazerSba(k); return; case fnProjPreInstr_UnknownProj8027: ProjPreInstr_UnknownProj8027(k); return; default: Unreachable(); @@ -2929,7 +2715,6 @@ void HandleProjectile(void) { // 0x90AECE } i -= 2; } - temp_collision_DD2 = 0; } static const int16 kDirToVelMult16_X[10] = { 0, 16, 16, 16, 0, 0, -16, -16, -16, 0 }; @@ -3024,7 +2809,7 @@ void ProjPreInstr_Missile_Func0459(uint16 k) { // 0x90AFC7 void ProjPreInstr_Missile_Func1368(uint16 k) { // 0x90AFCF uint16 v1 = projectile_index; - if (!(BlockCollMissileHoriz(projectile_index) & 1)) + if (!BlockCollMissileHoriz(projectile_index)) BlockCollMissileVert(v1); } @@ -3077,7 +2862,7 @@ void ProjPreInstr_SuperMissile_Func0459(uint16 k) { // 0x90B047 void ProjPreInstr_SuperMissile_Func1368(uint16 k) { // 0x90B052 uint16 v1 = projectile_index; - if (BlockCollMissileHoriz(projectile_index) & 1) { + if (BlockCollMissileHoriz(projectile_index)) { SuperMissileBlockCollDetect_X(); } else { SuperMissileBlockCollDetect_X(); @@ -3223,109 +3008,88 @@ static const uint16 kInitializeProjectileSpeed_XY_Diag[24] = { // 0x90B197 0x400, 0x2ab, }; -void SetInitialProjectileSpeed(void) { - int16 v2; - - int v0 = R20_ >> 1; +void SetInitialProjectileSpeed(uint16 r20) { + int v0 = r20 >> 1; uint16 v1 = 4 * (projectile_type[v0] & 0xF); - v2 = 2 * (projectile_dir[v0] & 0xF); + uint16 v2 = 2 * (projectile_dir[v0] & 0xF); + uint16 r22; if (!v2 || v2 == 4 || v2 == 8 || v2 == 10 || v2 == 14 || v2 == 18) { - R22_ = kInitializeProjectileSpeed_XY_Diag[v1 >> 1]; + r22 = kInitializeProjectileSpeed_XY_Diag[v1 >> 1]; } else { - if (v2 != 2 && v2 != 6 && v2 != 12 && v2 != 16) { + if (v2 != 2 && v2 != 6 && v2 != 12 && v2 != 16) Unreachable(); - while (1) - ; - } - R22_ = kInitializeProjectileSpeed_XY_Diag[(v1 >> 1) + 1]; + r22 = kInitializeProjectileSpeed_XY_Diag[(v1 >> 1) + 1]; } - R18_ = R20_; - InitializeProjectileSpeed(R20_); + InitializeProjectileSpeed(r20, r22); } -void InitializeProjectileSpeedOfType(void) { // 0x90B1DD - R22_ = 0; - R18_ = R20_; - InitializeProjectileSpeed(R20_); +void InitializeProjectileSpeedOfType(uint16 r20) { // 0x90B1DD + InitializeProjectileSpeed(r20, 0); } -void InitializeProjectileSpeed(uint16 k) { // 0x90B1F3 - int16 v2; +void InitializeProjectileSpeed(uint16 k, uint16 r22) { // 0x90B1F3 + uint16 r18; - int v1 = k >> 1; - projectile_bomb_x_subpos[v1] = 0; - projectile_bomb_y_subpos[v1] = 0; - v2 = 2 * (projectile_dir[v1] & 0xF); - switch (v2) { + int kh = k >> 1; + projectile_bomb_x_subpos[kh] = 0; + projectile_bomb_y_subpos[kh] = 0; + switch (2 * (projectile_dir[kh] & 0xF)) { case 0: case 18: { - uint16 v3 = R18_; if ((uint8)projectile_init_speed_samus_moved_up) - R18_ = (*(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_right_fract + 1) >> 2) | 0xC000; + r18 = (*(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_right_fract + 1) >> 2) | 0xC000; else - R18_ = 0; - int v4 = v3 >> 1; - projectile_bomb_y_speed[v4] = R18_ - R22_; - projectile_bomb_x_speed[v4] = 0; + r18 = 0; + projectile_bomb_y_speed[kh] = r18 - r22; + projectile_bomb_x_speed[kh] = 0; break; } case 2: { - uint16 v5 = R18_; if ((uint8)projectile_init_speed_samus_moved_up) - R18_ = (*(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_right_fract + 1) >> 2) | 0xC000; + r18 = (*(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_right_fract + 1) >> 2) | 0xC000; else - R18_ = 0; - int v6 = v5 >> 1; - projectile_bomb_y_speed[v6] = R18_ - R22_; - projectile_bomb_x_speed[v6] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_left_fract + 1) + R22_; + r18 = 0; + projectile_bomb_y_speed[kh] = r18 - r22; + projectile_bomb_x_speed[kh] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_left_fract + 1) + r22; break; } case 4: { - int v7 = R18_ >> 1; - projectile_bomb_y_speed[v7] = 0; - projectile_bomb_x_speed[v7] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_left_fract + 1) + R22_; + projectile_bomb_y_speed[kh] = 0; + projectile_bomb_x_speed[kh] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_left_fract + 1) + r22; break; } case 6: { - int v8 = R18_ >> 1; - projectile_bomb_y_speed[v8] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_up_fract + 1) + R22_; - projectile_bomb_x_speed[v8] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_left_fract + 1) + R22_; + projectile_bomb_y_speed[kh] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_up_fract + 1) + r22; + projectile_bomb_x_speed[kh] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_left_fract + 1) + r22; break; } case 8: case 10: { - int v9 = R18_ >> 1; - projectile_bomb_y_speed[v9] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_up_fract + 1) + R22_; - projectile_bomb_x_speed[v9] = 0; + projectile_bomb_y_speed[kh] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_up_fract + 1) + r22; + projectile_bomb_x_speed[kh] = 0; break; } case 12: { - int v10 = R18_ >> 1; - projectile_bomb_y_speed[v10] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_up_fract + 1) + R22_; - projectile_bomb_x_speed[v10] = *(uint16 *)((uint8 *)&absolute_moved_last_frame_y_fract + 1) - R22_; + projectile_bomb_y_speed[kh] = *(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_up_fract + 1) + r22; + projectile_bomb_x_speed[kh] = *(uint16 *)((uint8 *)&absolute_moved_last_frame_y_fract + 1) - r22; break; } case 14: { - int v11 = R18_ >> 1; - projectile_bomb_y_speed[v11] = 0; - projectile_bomb_x_speed[v11] = *(uint16 *)((uint8 *)&absolute_moved_last_frame_y_fract + 1) - R22_; + projectile_bomb_y_speed[kh] = 0; + projectile_bomb_x_speed[kh] = *(uint16 *)((uint8 *)&absolute_moved_last_frame_y_fract + 1) - r22; break; } case 16: { - uint16 v12 = R18_; if ((uint8)projectile_init_speed_samus_moved_up) - R18_ = (*(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_right_fract + 1) >> 2) | 0xC000; + r18 = (*(uint16 *)((uint8 *)&projectile_init_speed_samus_moved_right_fract + 1) >> 2) | 0xC000; else - R18_ = 0; - int v13 = v12 >> 1; - projectile_bomb_y_speed[v13] = R18_ - R22_; - projectile_bomb_x_speed[v13] = *(uint16 *)((uint8 *)&absolute_moved_last_frame_y_fract + 1) - R22_; + r18 = 0; + projectile_bomb_y_speed[kh] = r18 - r22; + projectile_bomb_x_speed[kh] = *(uint16 *)((uint8 *)&absolute_moved_last_frame_y_fract + 1) - r22; break; } default: Unreachable(); - while (1) - ; } } @@ -3335,21 +3099,18 @@ void Missile_Func1(uint16 k) { // 0x90B2F6 int v1 = k >> 1; if ((projectile_variables[v1] & 0xFF00) != 0) { - R18_ = 4 * (projectile_dir[v1] & 0xF); if ((projectile_type[v1] & 0x200) != 0) - v3 = R18_ - 0x3CD5; + v3 = addr_kSuperMissileAccelerations2; else - v3 = R18_ - 0x3CFD; - const uint8 *v4 = RomPtr_90(v3); + v3 = addr_kSuperMissileAccelerations; + const uint8 *v4 = RomPtr_90(v3 + 4 * (projectile_dir[v1] & 0xF)); projectile_bomb_x_speed[v1] += GET_WORD(v4); projectile_bomb_y_speed[v1] += GET_WORD(v4 + 2); } else { uint16 v2 = word_90C301 + projectile_variables[v1]; projectile_variables[v1] = v2; if ((v2 & 0xFF00) != 0) { - R22_ = projectile_variables[v1]; - R18_ = k; - InitializeProjectileSpeed(k); + InitializeProjectileSpeed(k, projectile_variables[v1]); if ((projectile_type[v1] & 0x200) != 0) Missile_Func2(); } @@ -3369,10 +3130,10 @@ void SuperMissileBlockCollDetect_Y(void) { // 0x90B366 return; } } else { - R18_ = (v1 >> 8) - 10; - if ((projectile_bomb_y_speed[v0] & 0x8000u) == 0) { + uint16 r18 = (v1 >> 8) - 10; + if ((projectile_bomb_y_speed[v0] & 0x8000) == 0) { uint16 v6 = projectile_index; - projectile_y_pos[v5 >> 1] = projectile_y_pos[v0] - R18_; + projectile_y_pos[v5 >> 1] = projectile_y_pos[v0] - r18; projectile_index = v5; BlockCollMissileVert(v5); projectile_index = v6; @@ -3381,7 +3142,7 @@ void SuperMissileBlockCollDetect_Y(void) { // 0x90B366 return; } uint16 v7 = projectile_index; - projectile_y_pos[v5 >> 1] = R18_ + projectile_y_pos[projectile_index >> 1]; + projectile_y_pos[v5 >> 1] = r18 + projectile_y_pos[projectile_index >> 1]; projectile_index = v5; BlockCollMissileVert(v5); projectile_index = v7; @@ -3414,10 +3175,10 @@ void SuperMissileBlockCollDetect_X(void) { // 0x90B406 return; } } else { - R18_ = (v1 >> 8) - 10; - if ((projectile_bomb_x_speed[v0] & 0x8000u) == 0) { + uint16 r18 = (v1 >> 8) - 10; + if ((projectile_bomb_x_speed[v0] & 0x8000) == 0) { uint16 v6 = projectile_index; - projectile_x_pos[v5 >> 1] = projectile_x_pos[v0] - R18_; + projectile_x_pos[v5 >> 1] = projectile_x_pos[v0] - r18; projectile_index = v5; BlockCollMissileHoriz(v5); projectile_index = v6; @@ -3426,7 +3187,7 @@ void SuperMissileBlockCollDetect_X(void) { // 0x90B406 return; } uint16 v7 = projectile_index; - projectile_x_pos[v5 >> 1] = R18_ + projectile_x_pos[projectile_index >> 1]; + projectile_x_pos[v5 >> 1] = r18 + projectile_x_pos[projectile_index >> 1]; projectile_index = v5; BlockCollMissileHoriz(v5); projectile_index = v7; @@ -3456,7 +3217,7 @@ void SpawnProjectileTrail(uint16 k) { // 0x90B657 uint16 v1 = projectile_type[k >> 1]; if ((v1 & 0xF00) != 0) { uint16 v3 = HIBYTE(v1) & 0xF; - if (v3 >= 3u) + if (v3 >= 3) return; v2 = v3 + 31; } else { @@ -3465,7 +3226,7 @@ void SpawnProjectileTrail(uint16 k) { // 0x90B657 uint16 v4 = 34; while (projectiletrail_left_instr_timer[v4 >> 1]) { v4 -= 2; - if ((v4 & 0x8000u) != 0) + if ((v4 & 0x8000) != 0) return; } int v5 = v4 >> 1; @@ -3520,9 +3281,8 @@ void HandleProjectileTrails(void) { // 0x90B6A9 for (i = projectiletrail_left_instr_list_ptr[v1]; ; i += 2) { const uint16 *v5 = (const uint16 *)RomPtr_90(i); v6 = *v5; - if ((*v5 & 0x8000u) == 0) + if ((*v5 & 0x8000) == 0) break; - R18_ = *v5; CallProjInstr(v6 | 0x900000, v0); } v7 = v0 >> 1; @@ -3541,9 +3301,8 @@ LABEL_14:; for (j = projectiletrail_right_instr_list_ptr[v13]; ; j += 2) { const uint16 *v17 = (const uint16 *)RomPtr_90(j); v18 = *v17; - if ((*v17 & 0x8000u) == 0) + if ((*v17 & 0x8000) == 0) break; - R18_ = *v17; CallProjInstr(v18 | 0x900000, v0); } int v19; @@ -3571,7 +3330,7 @@ LABEL_21:; } } v0 -= 2; - if ((v0 & 0x8000u) != 0) + if ((v0 & 0x8000) != 0) return; } projectiletrail_left_tile_and_attribs[v7] = *((uint16 *)RomPtr_90(i) + 1); @@ -3594,7 +3353,7 @@ LABEL_10:; } goto LABEL_14; } - for (k = 34; (k & 0x8000u) == 0; k -= 2) { + for (k = 34; (k & 0x8000) == 0; k -= 2) { uint16 v26 = oam_next_ptr; if ((int16)(oam_next_ptr - 512) < 0) { int v27 = k >> 1; @@ -3703,11 +3462,10 @@ void FireUnchargedBeam(void) { break; } } - R20_ = v0; - if (!(InitProjectilePositionDirection() & 1)) { + if (!(InitProjectilePositionDirection(v0) & 1)) { projectile_invincibility_timer = 10; - uint16 v1 = R20_; - int v2 = R20_ >> 1; + uint16 v1 = v0; + int v2 = v0 >> 1; projectile_timers[v2] = 4; v3 = equipped_beams; projectile_type[v2] = equipped_beams | 0x8000; @@ -3745,15 +3503,14 @@ LABEL_17: projectile_index = v1; WaveBeam_CheckColl(v1); LABEL_20: - R20_ = v1; projectile_bomb_pre_instructions[v1 >> 1] = kProjectileBombPreInstr[projectile_type[v1 >> 1] & 0xF]; - SetInitialProjectileSpeed(); + SetInitialProjectileSpeed(v1); return; } } if (!sign16(prev_beam_charge_counter - 16)) { play_resume_charging_beam_sfx = 0; - QueueSfx1_Max15(2u); + QueueSfx1_Max15(2); } } @@ -3773,7 +3530,6 @@ static const uint16 kFireChargedBeam_Funcs[12] = { // 0x90B986 }; void FireChargedBeam(void) { - if (Samus_CanFireBeam() & 1) { uint16 v0 = 0; while (projectile_damage[v0 >> 1]) { @@ -3783,11 +3539,11 @@ void FireChargedBeam(void) { break; } } - R20_ = v0; - if (!(InitProjectilePositionDirection() & 1)) { + uint16 r20 = v0; + if (!(InitProjectilePositionDirection(r20) & 1)) { projectile_invincibility_timer = 10; - uint16 v1 = R20_; - int v2 = R20_ >> 1; + uint16 v1 = r20; + int v2 = r20 >> 1; projectile_timers[v2] = 4; uint16 v3 = equipped_beams & 0x100F | 0x8010; projectile_type[v2] = v3; @@ -3814,16 +3570,15 @@ LABEL_14: return; } } - R20_ = v1; - projectile_bomb_pre_instructions[v1 >> 1] = kFireChargedBeam_Funcs[(uint16)(2 - * (projectile_type[v1 >> 1] & 0xF)) >> 1]; - SetInitialProjectileSpeed(); + r20 = v1; + projectile_bomb_pre_instructions[v1 >> 1] = kFireChargedBeam_Funcs[projectile_type[v1 >> 1] & 0xF]; + SetInitialProjectileSpeed(r20); goto LABEL_14; } } if (!sign16(prev_beam_charge_counter - 16)) { play_resume_charging_beam_sfx = 0; - QueueSfx1_Max15(2u); + QueueSfx1_Max15(2); } } @@ -3832,7 +3587,7 @@ static const int16 kProjectileOriginOffsets3_Y[10] = { -8, -13, 1, 4, 13, 13, 4, static const int16 kProjectileOriginOffsets4_X[10] = { 2, 15, 15, 13, 2, -5, -13, -13, -15, -2 }; static const int16 kProjectileOriginOffsets4_Y[10] = { -8, -16, -2, 1, 13, 13, 1, -2, -16, -8 }; -uint8 InitProjectilePositionDirection(void) { // 0x90BA56 +uint8 InitProjectilePositionDirection(uint16 r20) { // 0x90BA56 uint16 v0 = samus_pose; uint16 direction_shots_fired; @@ -3843,8 +3598,7 @@ uint8 InitProjectilePositionDirection(void) { // 0x90BA56 direction_shots_fired = kPoseParams[v0].direction_shots_fired; if ((direction_shots_fired & 0xF0) != 0) { if (direction_shots_fired != 16 - || (LOBYTE(direction_shots_fired) = *(&kPoseParams[0].direction_shots_fired - + (uint16)(8 * samus_last_different_pose)), + || (LOBYTE(direction_shots_fired) = kPoseParams[samus_last_different_pose].direction_shots_fired, (direction_shots_fired & 0xF0) != 0)) { --projectile_counter; return 1; @@ -3853,21 +3607,21 @@ uint8 InitProjectilePositionDirection(void) { // 0x90BA56 v0 = samus_pose; } } - int v2 = R20_ >> 1; + int v2 = r20 >> 1; projectile_dir[v2] = direction_shots_fired; - R22_ = kPoseParams[v0].y_offset_to_gfx; + uint16 r22 = kPoseParams[v0].y_offset_to_gfx; uint16 v3 = 2 * (projectile_dir[v2] & 0xF); if (samus_pose == kPose_75_FaceL_Moonwalk_AimUL || samus_pose == kPose_76_FaceR_Moonwalk_AimUR || samus_movement_type == 1) { int v6 = v3 >> 1; projectile_x_pos[v2] = samus_x_pos + kProjectileOriginOffsets4_X[v6]; - projectile_y_pos[v2] = samus_y_pos + kProjectileOriginOffsets4_Y[v6] - R22_; + projectile_y_pos[v2] = samus_y_pos + kProjectileOriginOffsets4_Y[v6] - r22; return 0; } else { int v4 = v3 >> 1; projectile_x_pos[v2] = samus_x_pos + kProjectileOriginOffsets3_X[v4]; - projectile_y_pos[v2] = samus_y_pos + kProjectileOriginOffsets3_Y[v4] - R22_; + projectile_y_pos[v2] = samus_y_pos + kProjectileOriginOffsets3_Y[v4] - r22; return 0; } } @@ -3881,7 +3635,7 @@ void HandleChargingBeamGfxAudio(void) { // 0x90BAFC if (flare_counter) { for (int i = 4; i >= 0; i -= 2) { bool v7 = *(uint16 *)((uint8 *)&flare_animation_timer + i) == 1; - bool v8 = (-- * (uint16 *)((uint8 *)&flare_animation_timer + i) & 0x8000u) != 0; + bool v8 = (-- * (uint16 *)((uint8 *)&flare_animation_timer + i) & 0x8000) != 0; if (v7 || v8) { v7 = (*(uint16 *)((uint8 *)&flare_animation_frame + i))-- == 1; if (v7) { @@ -3905,28 +3659,26 @@ void HandleChargingBeamGfxAudio(void) { // 0x90BAFC } if (!sign16(flare_counter - 15)) { if (flare_counter == 16) - QueueSfx1_Max9(8u); + QueueSfx1_Max9(8); uint16 v0 = 0; do { - R0_.bank = -112; v1 = *(uint16 *)((uint8 *)&flare_animation_timer + v0) - 1; *(uint16 *)((uint8 *)&flare_animation_timer + v0) = v1; if (v1 < 0) { uint16 v2 = *(uint16 *)((uint8 *)&flare_animation_frame + v0) + 1; *(uint16 *)((uint8 *)&flare_animation_frame + v0) = v2; uint16 v3 = v2; - R0_.addr = kFlareAnimDelays[v0 >> 1]; - v4 = IndirReadByte(R0_, v2); + const uint8 *r0 = RomPtr_90(kFlareAnimDelays[v0 >> 1]); + v4 = r0[v2]; if (v4 == 255) { *(uint16 *)((uint8 *)&flare_animation_frame + v0) = 0; v3 = 0; } else if (v4 == 254) { - R18_ = IndirReadByte(R0_, v3 + 1); - uint16 v5 = *(uint16 *)((uint8 *)&flare_animation_frame + v0) - R18_; + uint16 v5 = *(uint16 *)((uint8 *)&flare_animation_frame + v0) - r0[v3 + 1]; *(uint16 *)((uint8 *)&flare_animation_frame + v0) = v5; v3 = v5; } - *(uint16 *)((uint8 *)&flare_animation_timer + v0) = IndirReadByte(R0_, v3); + *(uint16 *)((uint8 *)&flare_animation_timer + v0) = r0[v3]; } v9 = v0; DrawFlareAnimationComponent(v0); @@ -3943,53 +3695,39 @@ static const int16 kProjectileOriginOffsets_Y[13] = { -28, -19, 1, 6, 17, 17, 6, static const int16 kProjectileOriginOffsets2_X[10] = { 2, 19, 20, 18, 3, -4, -18, -20, -19, -2 }; static const int16 kProjectileOriginOffsets2_Y[10] = { -32, -22, -3, 6, 25, 25, 6, -3, -20, -32 }; - void DrawFlareAnimationComponent(uint16 k) { // 0x90BBE1 static const uint16 word_93A225[3] = { 0, 0x1e, 0x24 }; static const uint16 word_93A22B[3] = { 0, 0x2a, 0x30 }; int16 v2; uint16 v1; - - R0_.bank = -109; - R18_ = *((uint8 *)&flare_animation_frame + k); + uint16 r20; + uint16 r18 = *((uint8 *)&flare_animation_frame + k); if (samus_pose_x_dir == 4) v1 = word_93A22B[k >> 1]; else v1 = word_93A225[k >> 1]; - R22_ = R18_ + v1; - R24_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(8 * samus_pose)); - v2 = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)); + uint16 r22 = r18 + v1; + uint16 r24 = kPoseParams[samus_pose].y_offset_to_gfx; + v2 = kPoseParams[samus_pose].direction_shots_fired; if (v2 != 255 && v2 != 16) { uint16 v3 = 2 * (v2 & 0xF); - if ((ceres_status & 0x8000u) != 0) { - grapple_beam_tmpD82 = samus_x_pos; - grapple_beam_tmpD84 = samus_y_pos; + uint16 old_x = samus_x_pos, old_y = samus_y_pos; + if ((ceres_status & 0x8000) != 0) Samus_CalcPos_Mode7(); - } int v4 = v3 >> 1; uint16 v5; if (samus_movement_type == 1) { - R20_ = samus_x_pos + kProjectileOriginOffsets2_X[v4] - layer1_x_pos; - v5 = (__PAIR32__( - samus_y_pos + kProjectileOriginOffsets2_Y[v4] - R24_, - samus_y_pos + kProjectileOriginOffsets2_Y[v4]) - - __PAIR32__(layer1_y_pos, R24_)) >> 16; + r20 = samus_x_pos + kProjectileOriginOffsets2_X[v4] - layer1_x_pos; + v5 = samus_y_pos + kProjectileOriginOffsets2_Y[v4] - r24 - layer1_y_pos; } else { - R20_ = samus_x_pos + kProjectileOriginOffsets_X[v4] - layer1_x_pos; - v5 = (__PAIR32__( - samus_y_pos + kProjectileOriginOffsets_Y[v4] - R24_, - samus_y_pos + kProjectileOriginOffsets_Y[v4]) - - __PAIR32__(layer1_y_pos, R24_)) >> 16; - } - R18_ = v5; - if ((v5 & 0xFF00) != 0) - ; - else - DrawBeamGrappleSpritemap(R22_); - if ((ceres_status & 0x8000u) != 0) { - samus_y_pos = grapple_beam_tmpD84; - samus_x_pos = grapple_beam_tmpD82; + r20 = samus_x_pos + kProjectileOriginOffsets_X[v4] - layer1_x_pos; + v5 = samus_y_pos + kProjectileOriginOffsets_Y[v4] - r24 - layer1_y_pos; } + r18 = v5; + if ((v5 & 0xFF00) == 0) + DrawBeamGrappleSpritemap(r22, r20, r18); + if ((ceres_status & 0x8000) != 0) + samus_y_pos = old_y, samus_x_pos = old_x; } } @@ -4012,11 +3750,11 @@ void FireHyperBeam(void) { // 0x90BCD1 break; } } - R20_ = v0; - if (!(InitProjectilePositionDirection() & 1)) { + uint16 r20 = v0; + if (!(InitProjectilePositionDirection(r20) & 1)) { projectile_invincibility_timer = 10; - uint16 k = R20_; - projectile_type[R20_ >> 1] = -28648; + uint16 k = r20; + projectile_type[r20 >> 1] = -28648; QueueSfx1_Max15(kChargedProjectile_Sfx[8]); play_resume_charging_beam_sfx = 0; InitializeProjectile(k); @@ -4029,8 +3767,8 @@ void FireHyperBeam(void) { // 0x90BCD1 int v3 = projectile_index >> 1; projectile_damage[v3] = 1000; projectile_bomb_pre_instructions[v3] = FUNC16(ProjPreInstr_HyperBeam); - R20_ = v2; - SetInitialProjectileSpeed(); + r20 = v2; + SetInitialProjectileSpeed(r20); cooldown_timer = 21; charged_shot_glow_timer = -32748; flare_animation_frame = 29; @@ -4117,23 +3855,23 @@ void WaveBeam_CheckColl_7(void) { // 0x90BDF2 BlockCollWaveBeamHoriz(v0); } -void ProjectileReflection(void) { // 0x90BE00 - uint16 v0 = R20_; - int v1 = R20_ >> 1; +void ProjectileReflection(uint16 r20) { // 0x90BE00 + uint16 v0 = r20; + int v1 = r20 >> 1; uint16 v2 = projectile_type[v1]; if ((v2 & 0x100) != 0) { - InitializeProjectile(R20_); + InitializeProjectile(r20); projectile_bomb_pre_instructions[v1] = FUNC16(ProjPreInstr_Missile); projectile_variables[v1] = 240; } else if ((v2 & 0x200) != 0) { - uint16 k = R20_; + uint16 k = r20; ClearProjectile(LOBYTE(projectile_variables[v1])); InitializeProjectile(k); int v3 = k >> 1; projectile_bomb_pre_instructions[v3] = FUNC16(ProjPreInstr_SuperMissile); projectile_variables[v3] = 240; } else { - SetInitialProjectileSpeed(); + SetInitialProjectileSpeed(r20); InitializeProjectile(v0); projectile_bomb_pre_instructions[v1] = kFireChargedBeam_Funcs[projectile_type[v1] & 0xF]; } @@ -4160,23 +3898,23 @@ LABEL_10:; if ((int16)(v0 - 10) >= 0) goto LABEL_5; } - R20_ = v0; - if (!(InitProjectilePositionDirection() & 1)) { + uint16 r20 = v0; + if (!(InitProjectilePositionDirection(r20) & 1)) { projectile_invincibility_timer = 20; if (hud_item_index == 2) --samus_super_missiles; else --samus_missiles; - int v1 = R20_ >> 1; + int v1 = r20 >> 1; projectile_timers[v1] = 4; uint16 v3 = hud_item_index; - R18_ = swap16(hud_item_index); - projectile_type[v1] |= R18_ | 0x8000; + uint16 r18 = swap16(hud_item_index); + projectile_type[v1] |= r18 | 0x8000; uint16 v4 = 2 * (v3 & 0xF); if (!cinematic_function) QueueSfx1_Max6(kNonBeamProjectile_Sfx[v4 >> 1]); - InitializeProjectileSpeedOfType(); - InitializeProjectile(R20_); + InitializeProjectileSpeedOfType(r20); + InitializeProjectile(r20); uint16 v7 = projectile_type[v1]; if ((v7 & 0x200) != 0) projectile_bomb_pre_instructions[v1] = FUNC16(ProjPreInstr_SuperMissile); @@ -4205,17 +3943,16 @@ void Missile_Func2(void) { // 0x90BF46 if ((int16)(v0 - 10) >= 0) return; } - R20_ = v0; + uint16 r20 = v0; int v1 = v0 >> 1; - projectile_type[v1] |= 0x8200u; + projectile_type[v1] |= 0x8200; int v2 = projectile_index >> 1; projectile_x_pos[v1] = projectile_x_pos[v2]; projectile_y_pos[v1] = projectile_y_pos[v2]; projectile_dir[v1] = projectile_dir[v2]; - InitProjectilePositionDirection(); + InitProjectilePositionDirection(r20); InitializeInstrForSuperMissile(v0); projectile_bomb_pre_instructions[v1] = FUNC16(ProjPreInstr_Func1); - R18_ = v0; projectile_variables[projectile_index >> 1] = v0 + (projectile_variables[projectile_index >> 1] & 0xFF00); ++projectile_counter; } @@ -4223,10 +3960,10 @@ void Missile_Func2(void) { // 0x90BF46 void HudSelectionHandler_MorphBall(void) { // 0x90BF9D if ((button_config_shoot_x & joypad1_lastkeys) != 0) { if (hud_item_index == 3) { - if ((power_bomb_flag & 0x8000u) == 0) { + if ((power_bomb_flag & 0x8000) == 0) { if (HudSelectionHandler_MorphBall_Helper2() & 1) { if (samus_power_bombs) { - if ((--samus_power_bombs & 0x8000u) == 0) { + if ((--samus_power_bombs & 0x8000) == 0) { power_bomb_flag = -1; uint16 v2 = 10; while (projectile_type[v2 >> 1]) { @@ -4236,10 +3973,10 @@ void HudSelectionHandler_MorphBall(void) { // 0x90BF9D break; } } - R20_ = v2; - R18_ = swap16(hud_item_index); +// r20 = v2; + uint16 r18 = swap16(hud_item_index); int v4 = v2 >> 1; - uint16 v5 = R18_ | projectile_type[v4]; + uint16 v5 = r18 | projectile_type[v4]; projectile_type[v4] = v5; uint8 v6 = HIBYTE(v5); projectile_dir[v4] = 0; @@ -4268,7 +4005,7 @@ void HudSelectionHandler_MorphBall(void) { // 0x90BF9D break; } } - R20_ = v0; +// r20 = v0; int v1 = v0 >> 1; projectile_type[v1] = 1280; projectile_dir[v1] = 0; @@ -4280,7 +4017,7 @@ void HudSelectionHandler_MorphBall(void) { // 0x90BF9D cooldown_timer = kNonBeamProjectileCooldowns[5]; } } else if (flare_counter) { - QueueSfx1_Max9(2u); + QueueSfx1_Max9(2); flare_counter = 0; ClearFlareAnimationState(); Samus_LoadSuitPalette(); @@ -4296,7 +4033,7 @@ uint8 HudSelectionHandler_MorphBall_Helper(void) { // 0x90C0AB } else { BombSpread(); Samus_LoadSuitPalette(); - QueueSfx1_Max9(2u); + QueueSfx1_Max9(2); } } return 0; @@ -4306,7 +4043,7 @@ uint8 HudSelectionHandler_MorphBall_Helper2(void) { // 0x90C0E7 if ((button_config_shoot_x & joypad1_newkeys) == 0 || bomb_counter && (!sign16(bomb_counter - 5) || (uint8)cooldown_timer)) { if (flare_counter) { - QueueSfx1_Max9(2u); + QueueSfx1_Max9(2); flare_counter = 0; ClearFlareAnimationState(); Samus_LoadSuitPalette(); @@ -4330,7 +4067,7 @@ void Bomb_Func2(void) { // 0x90C128 if (v3 == 15) projectile_bomb_instruction_ptr[v1] += 28; } else { - QueueSfx2_Max6(8u); + QueueSfx2_Max6(8); InitializeBombExplosion(v0); } } @@ -4368,14 +4105,15 @@ static Func_U8 *const kRunSwitchedToHudHandler[6] = { // 0x90C4B5 }; void HandleSwitchingHudSelection(void) { uint16 v0; - R18_ = hud_item_index; + uint16 r22 = 0; + uint16 r18 = hud_item_index; if ((button_config_itemcancel_y & joypad1_newkeys) != 0) { samus_auto_cancel_hud_item_index = 0; LABEL_5: v0 = 0; goto LABEL_6; } - R22_ = (button_config_itemcancel_y & joypad1_lastkeys) != 0; + r22 = (button_config_itemcancel_y & joypad1_lastkeys) != 0; if ((button_config_itemswitch & joypad1_newkeys) == 0) goto LABEL_13; v0 = hud_item_index + 1; @@ -4391,12 +4129,12 @@ LABEL_6: hud_item_index = 0; } } - if (R22_) + if (r22) samus_auto_cancel_hud_item_index = hud_item_index; else samus_auto_cancel_hud_item_index = 0; LABEL_13: - if (hud_item_index == R18_) { + if (hud_item_index == r18) { uint16 v1 = hud_item_changed_this_frame + 1; if (!sign16(hud_item_changed_this_frame - 2)) v1 = 2; @@ -4453,7 +4191,7 @@ uint8 SwitchToHudHandler_Grapple(void) { // 0x90C58A } uint8 SwitchToHudHandler_Xray(void) { // 0x90C5AE - if ((equipped_items & 0x8000u) == 0) + if ((equipped_items & 0x8000) == 0) return 1; flare_counter = 0; ClearFlareAnimationState(); @@ -4471,14 +4209,14 @@ uint8 UpdateArmCannonIsOpenFlag(void) { // 0x90C5EB static const int8 kFlagShouldArmCannonBeOpen[6] = { 0, 1, 1, 0, 1, 0 }; if (sign16(hud_item_changed_this_frame - 2)) return 0; - R18_ = kFlagShouldArmCannonBeOpen[hud_item_index]; - if (flag_arm_cannon_open_or_opening == R18_) + uint16 r18 = kFlagShouldArmCannonBeOpen[hud_item_index]; + if (flag_arm_cannon_open_or_opening == r18) return 0; - if (R18_) + if (r18) arm_cannon_frame = 0; else arm_cannon_frame = 4; - *(uint16 *)&flag_arm_cannon_open_or_opening = R18_ | 0x100; + *(uint16 *)&flag_arm_cannon_open_or_opening = r18 | 0x100; return 1; } @@ -4501,58 +4239,52 @@ void AdvanceArmCannonFrame(void) { // 0x90C627 void Samus_ArmCannon_Draw(void) { // 0x90C663 static const uint16 kDrawArmCannon_Char[10] = { 0x281f, 0x281f, 0x281f, 0x681f, 0xa81f, 0xe81f, 0x281f, 0x681f, 0x681f, 0x681f }; - int16 v2; - int16 v8; - OamEnt *v9; - int16 v10; - int16 v12; uint16 v3; + uint16 r22; if (arm_cannon_frame && (!samus_invincibility_timer || (nmi_frame_counter_word & 1) == 0)) { uint16 v0 = kPlayerPoseToPtr[samus_pose]; const uint8 *v1 = RomPtr_90(v0); - v2 = *v1; + int16 v2 = *v1; if ((v2 & 0x80) != 0) { if (samus_anim_frame) v3 = 2 * (v1[2] & 0x7F); else v3 = 2 * (*v1 & 0x7F); - R22_ = v0 + 4; + r22 = v0 + 4; } else { v3 = 2 * v2; - R22_ = v0 + 2; + r22 = v0 + 2; } - R24_ = kDrawArmCannon_Char[v3 >> 1]; - const uint8 *v4 = RomPtr_90(R22_ + 2 * samus_anim_frame); - R18_ = (int8)v4[0]; - R20_ = (int8)v4[1]; - R22_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(8 * samus_pose)); + uint16 r24 = kDrawArmCannon_Char[v3 >> 1]; + const uint8 *v4 = RomPtr_90(r22 + 2 * samus_anim_frame); + uint16 r18 = (int8)v4[0], r20 = (int8)v4[1]; + r22 = kPoseParams[samus_pose].y_offset_to_gfx; uint16 v7 = oam_next_ptr; - v8 = R18_ + samus_x_pos - layer1_x_pos; + int16 v8 = r18 + samus_x_pos - layer1_x_pos; if (v8 >= 0) { if (sign16(v8 - 256)) { - v9 = gOamEnt(oam_next_ptr); - *(uint16 *)&v9->xcoord = v8; - v10 = (__PAIR32__(R20_ + samus_y_pos - R22_, R20_ + samus_y_pos) - __PAIR32__(layer1_y_pos, R22_)) >> 16; + OamEnt *v9 = gOamEnt(oam_next_ptr); + v9->xcoord = v8; + int16 v10 = r20 + samus_y_pos - r22 - layer1_y_pos; if (v10 >= 0) { if (sign16(v10 - 256)) { - *(uint16 *)&v9->ycoord = v10; - *(uint16 *)&v9->charnum = R24_; + v9->ycoord = v10; + *(uint16 *)&v9->charnum = r24; oam_next_ptr = v7 + 4; } } } } const uint8 *v11 = RomPtr_90(kPlayerPoseToPtr[samus_pose]); - v12 = *v11; + int16 v12 = *v11; if ((v12 & 0x80) != 0) { if (samus_anim_frame) v12 = *RomPtr_90(kPlayerPoseToPtr[samus_pose] + 2) & 0x7F; else v12 = *v11 & 0x7F; } - R22_ = kDrawArmCannon_Tab2[v12]; - uint16 v13 = R22_ + 2 * arm_cannon_frame; + uint16 v13 = kDrawArmCannon_Tab2[v12] + 2 * arm_cannon_frame; uint16 v14 = vram_write_queue_tail; gVramWriteEntry(vram_write_queue_tail)->size = 32; v14 += 2; @@ -4565,33 +4297,30 @@ void Samus_ArmCannon_Draw(void) { // 0x90C663 } } -void Projectile_SinLookup(uint16 j, uint16 a) { // 0x90CC39 - int16 v3; +static uint16 Projectile_SinLookup_Inner(uint16 k, uint16 r24) { // 0x90CC8A + uint16 prod = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k), r24); + uint16 r18 = prod >> 8; + prod = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k + 1), r24); + return r18 + prod; +} + +Point16U Projectile_SinLookup(uint16 j, uint16 a) { // 0x90CC39 uint16 v2, v4; - - R24_ = a; - R26_ = j; + uint16 r24 = a; + uint16 r26 = j; if (sign16(j - 128)) - v2 = Projectile_SinLookup_Inner(2 * j); + v2 = Projectile_SinLookup_Inner(2 * j, r24); else - v2 = -Projectile_SinLookup_Inner(2 * (uint8)(j + 0x80)); - R20_ = v2; - v3 = (uint8)(R26_ - 64); + v2 = -Projectile_SinLookup_Inner(2 * (uint8)(j + 0x80), r24); + int16 v3 = (uint8)(r26 - 64); if (sign16(v3 - 128)) - v4 = Projectile_SinLookup_Inner(2 * v3); + v4 = Projectile_SinLookup_Inner(2 * v3, r24); else - v4 = -Projectile_SinLookup_Inner(2 * (uint8)(v3 + 0x80)); - R22_ = v4; + v4 = -Projectile_SinLookup_Inner(2 * (uint8)(v3 + 0x80), r24); + return (Point16U) { v2, v4 }; } -uint16 Projectile_SinLookup_Inner(uint16 k) { // 0x90CC8A - uint16 prod = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k), R24_); - R18_ = prod >> 8; - prod = Mult8x8(*((uint8 *)&kSinCosTable8bit_Sext[64] + k + 1), R24_); - return R18_ + prod; -} - static const uint16 kCostOfSbaInPowerBombs[12] = { // 0x90CCC0 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, @@ -4656,7 +4385,7 @@ uint8 FireSba_FireWave(void) { // 0x90CD1A projectile_counter = 4; cooldown_timer = kProjectileCooldown_Uncharged[projectile_type[0] & 0x3F]; used_for_sba_attacksB60 = 4; - QueueSfx1_Max6(0x28u); + QueueSfx1_Max6(0x28); return 1; } @@ -4683,7 +4412,7 @@ uint8 FireSba_FireIce(void) { // 0x90CD9B used_for_sba_attacksB60 = -4; else used_for_sba_attacksB60 = 4; - QueueSfx1_Max6(0x23u); + QueueSfx1_Max6(0x23); return 1; } @@ -4713,7 +4442,7 @@ uint8 FireSba_FireSpazer(void) { // 0x90CE14 projectile_counter = 4; cooldown_timer = kProjectileCooldown_Uncharged[projectile_type[0] & 0x3F]; used_for_sba_attacksB60 = 0; - QueueSfx1_Max6(0x25u); + QueueSfx1_Max6(0x25); return 1; } @@ -4739,14 +4468,14 @@ uint8 FireSba_FirePlasma(void) { // 0x90CE98 used_for_sba_attacksB60 = -4; else used_for_sba_attacksB60 = 4; - QueueSfx1_Max6(0x27u); + QueueSfx1_Max6(0x27); return 1; } void ProjPreInstr_IceSba(uint16 k) { // 0x90CF09 int v1 = k >> 1; if ((projectile_dir[v1] & 0xF0) != 0) { - QueueSfx1_Max6(0x24u); + QueueSfx1_Max6(0x24); ClearProjectile(k); } else { bool v2 = projectile_timers[v1]-- == 1; @@ -4756,15 +4485,15 @@ void ProjPreInstr_IceSba(uint16 k) { // 0x90CF09 k = projectile_index; } int v3 = k >> 1; - Projectile_SinLookup(projectile_variables[v3], 0x20); - projectile_x_pos[v3] = R20_ + samus_x_pos; - projectile_y_pos[v3] = R22_ + samus_y_pos; + Point16U pt = Projectile_SinLookup(projectile_variables[v3], 0x20); + projectile_x_pos[v3] = pt.x + samus_x_pos; + projectile_y_pos[v3] = pt.y + samus_y_pos; projectile_variables[v3] = (uint8)(used_for_sba_attacksB60 + projectile_variables[v3]); v2 = projectile_bomb_y_speed[v3]-- == 1; if (v2) { projectile_bomb_pre_instructions[v3] = FUNC16(ProjPreInstr_IceSba2); projectile_bomb_x_speed[v3] = 40; - QueueSfx1_Max6(0x24u); + QueueSfx1_Max6(0x24); } cooldown_timer = 2; flare_counter = 0; @@ -4772,7 +4501,6 @@ void ProjPreInstr_IceSba(uint16 k) { // 0x90CF09 } void ProjPreInstr_IceSba2(uint16 k) { // 0x90CF7A - int16 v4; int16 v5; int16 v6; int16 v7; @@ -4787,13 +4515,13 @@ void ProjPreInstr_IceSba2(uint16 k) { // 0x90CF7A } int v3; v3 = k >> 1; - Projectile_SinLookup(projectile_variables[v3], projectile_bomb_x_speed[v3]); - v4 = R20_ + samus_x_pos; - projectile_x_pos[v3] = R20_ + samus_x_pos; - v5 = v4 - layer1_x_pos; + Point16U pt = Projectile_SinLookup(projectile_variables[v3], projectile_bomb_x_speed[v3]); + pt.x += samus_x_pos; + projectile_x_pos[v3] = pt.x; + v5 = pt.x - layer1_x_pos; if (sign16(v5 + 32) || !sign16(v5 - 288) - || (v6 = R22_ + samus_y_pos, projectile_y_pos[v3] = R22_ + samus_y_pos, v7 = v6 - layer1_y_pos, sign16(v7 - 16)) + || (v6 = pt.y + samus_y_pos, projectile_y_pos[v3] = pt.y + samus_y_pos, v7 = v6 - layer1_y_pos, sign16(v7 - 16)) || !sign16(v7 - 256)) { LABEL_9: ClearProjectile(k); @@ -4826,14 +4554,14 @@ void Projectile_Func7_Shinespark(void) { // 0x90CFFA bomb_jump_dir = 0; if (flare_counter) { if (!sign16(flare_counter - 16)) - QueueSfx1_Max9(2u); + QueueSfx1_Max9(2); flare_counter = 0; ClearFlareAnimationState(); } } void Samus_MoveHandlerShinesparkWindup(void) { // 0x90D068 - bool v0 = (--timer_for_shinesparks_startstop & 0x8000u) != 0; + bool v0 = (--timer_for_shinesparks_startstop & 0x8000) != 0; if (!timer_for_shinesparks_startstop || v0) { if (samus_pose_x_dir == 4) samus_new_pose_interrupted = 204; @@ -4846,7 +4574,7 @@ void Samus_MoveHandlerShinesparkWindup(void) { // 0x90D068 speed_echo_xspeed[1] = 0; speed_echo_xpos[0] = 0; speed_echo_xpos[1] = 0; - QueueSfx3_Max9(0xFu); + QueueSfx3_Max9(0xF); } } @@ -4856,7 +4584,7 @@ void Samus_MoveHandlerVerticalShinespark(void) { // 0x90D0AB Samus_UpdateSpeedEchoPos(); Samus_ShinesparkMove_Y(); Samus_EndSuperJump(); - if (!sign16(samus_health - 30) && (--samus_health & 0x8000u) != 0) + if (!sign16(samus_health - 30) && (--samus_health & 0x8000) != 0) samus_health = 0; } @@ -4867,7 +4595,7 @@ void Samus_MoveHandler_Shinespark_Diag(void) { // 0x90D0D7 Samus_ShinesparkMove_X(); Samus_ShinesparkMove_Y(); Samus_EndSuperJump(); - if (!sign16(samus_health - 30) && (--samus_health & 0x8000u) != 0) + if (!sign16(samus_health - 30) && (--samus_health & 0x8000) != 0) samus_health = 0; } @@ -4877,10 +4605,16 @@ void Samus_MoveHandler_Shinespark_Horiz(void) { // 0x90D106 Samus_UpdateSpeedEchoPos(); Samus_ShinesparkMove_X(); Samus_EndSuperJump(); - if (!sign16(samus_health - 30) && (--samus_health & 0x8000u) != 0) + if (!sign16(samus_health - 30) && (--samus_health & 0x8000) != 0) samus_health = 0; } +static uint32 Samus_ClampSpeedHi(int32 amt, int val) { + if (!sign16((amt >> 16) - val)) + amt = val << 16 | (amt & 0xffff); + return amt; +} + void Samus_ShinesparkMove_X(void) { // 0x90D132 int16 v4; @@ -4892,38 +4626,26 @@ void Samus_ShinesparkMove_X(void) { // 0x90D132 samus_x_extra_run_speed = 15; samus_x_extra_run_subspeed = 0; } - R18_ = 0; - R20_ = 0; + int32 amt = 0; if (samus_pose_x_dir == 4) { - Samus_CalcDisplacementMoveLeft(); - R18_ = ~R18_; - bool v2 = R20_ == 0; - R20_ = -R20_; - if (v2) - ++R18_; - if (!sign16(R18_ - 15)) - R18_ = 15; - uint16 v3 = Samus_CheckSolidEnemyColl(); - if (v3) { - samus_collision_flag = v3; + amt = Samus_ClampSpeedHi(-(int32)Samus_CalcDisplacementMoveLeft(amt), 15); + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + amt = cres.amt; + if (cres.collision) { + samus_collision_flag = cres.collision; goto LABEL_18; } - R18_ = ~R18_; - v2 = R20_ == 0; - R20_ = -R20_; - if (v2) - ++R18_; + amt = -(int32)amt; } else { - Samus_CalcDisplacementMoveRight(); - if (!sign16(R18_ - 15)) - R18_ = 15; - uint16 v1 = Samus_CheckSolidEnemyColl(); - if (v1) { - samus_collision_flag = v1; + amt = Samus_ClampSpeedHi(Samus_CalcDisplacementMoveRight(amt), 25); + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + amt = cres.amt; + if (cres.collision) { + samus_collision_flag = cres.collision; goto LABEL_18; } } - Samus_MoveRight_NoSolidColl(); + Samus_MoveRight_NoSolidColl(amt); Samus_AlignYPosSlope(); LABEL_18: v4 = samus_x_pos - samus_prev_x_pos; @@ -4936,44 +4658,20 @@ LABEL_18: } void Samus_ShinesparkMove_Y(void) { // 0x90D1FF - int16 v3; - samus_shine_timer = 15; - uint16 v0 = (__PAIR32__(samus_y_accel, samus_y_subaccel) + __PAIR32__(substate, suit_pickup_light_beam_pos)) >> 16; - suit_pickup_light_beam_pos += samus_y_subaccel; - substate = v0; - bool v1 = __CFADD__uint16(suit_pickup_light_beam_pos, samus_y_subspeed); - samus_y_subspeed += suit_pickup_light_beam_pos; - R20_ = samus_y_subspeed; - samus_y_speed += v0 + v1; - R18_ = samus_y_speed; - if (!sign16(samus_y_speed - 14)) - R18_ = 14; - R18_ = ~R18_; - bool v2 = R20_ == 0; - R20_ = -R20_; - if (v2) - ++R18_; - v3 = (__PAIR32__(R18_, R20_) + __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement)) >> 16; - R20_ += extra_samus_y_subdisplacement; + + AddToHiLo(&substate, &suit_pickup_light_beam_pos, __PAIR32__(samus_y_accel, samus_y_subaccel)); + + AddToHiLo(&samus_y_speed, &samus_y_subspeed, __PAIR32__(substate, suit_pickup_light_beam_pos)); + int32 amt = Samus_ClampSpeedHi(__PAIR32__(samus_y_speed, samus_y_subspeed), 14); + amt -= __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement); samus_collision_direction = 2; - R18_ = ~v3; - v2 = R20_ == 0; - R20_ = -R20_; - if (v2) - ++R18_; - if (!sign16(R18_ - 15)) - R18_ = 15; - uint16 v4 = Samus_CheckSolidEnemyColl(); - if (v4) { - samus_collision_flag = v4; + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(Samus_ClampSpeedHi(amt, 15)); + amt = cres.amt; + if (cres.collision) { + samus_collision_flag = cres.collision; } else { - R18_ = ~R18_; - v2 = R20_ == 0; - R20_ = -R20_; - if (v2) - ++R18_; - Samus_MoveDown_NoSolidColl(); + Samus_MoveDown_NoSolidColl(-(int32)amt); } if (sign16(samus_y_pos - samus_prev_y_pos + 14)) samus_prev_y_pos = samus_y_pos + 14; @@ -5007,8 +4705,8 @@ uint8 Samus_EndSuperJump(void) { // 0x90D2BA speed_echo_ypos[1] = samus_y_pos; speed_echo_xspeed[2] = 0; samus_hurt_flash_counter = 0; - QueueSfx1_Max6(0x35u); - QueueSfx3_Max6(0x10u); + QueueSfx1_Max6(0x35); + QueueSfx3_Max6(0x10); return 1; } @@ -5024,16 +4722,16 @@ void Samus_MoveHandler_ShinesparkCrash(void) { kSamus_MoveHandler_ShinesparkCrash[HIBYTE(speed_echoes_index)](); for (int i = 2; i >= 0; i -= 2) { int v1 = i >> 1; - Projectile_SinLookup(speed_echo_xspeed[v1], (uint8)speed_echoes_index); - speed_echo_xpos[v1] = R20_ + samus_x_pos; - speed_echo_ypos[v1] = R22_ + samus_y_pos; + Point16U pt = Projectile_SinLookup(speed_echo_xspeed[v1], (uint8)speed_echoes_index); + speed_echo_xpos[v1] = pt.x + samus_x_pos; + speed_echo_ypos[v1] = pt.y + samus_y_pos; } } void Samus_MoveHandler_ShinesparkCrash_0(void) { // 0x90D383 uint16 v0 = speed_echoes_index + 4; if (!sign16(speed_echoes_index - 12)) - v0 |= 0x100u; + v0 |= 0x100; speed_echoes_index = v0; } @@ -5058,7 +4756,7 @@ void Samus_MoveHandler_ShinesparkCrash_2(void) { // 0x90D3CC void Samus_MoveHandler_ShinesparkCrashEchoCircle(void) { // 0x90D3F3 samus_shine_timer = 15; - bool v0 = (--timer_for_shinesparks_startstop & 0x8000u) != 0; + bool v0 = (--timer_for_shinesparks_startstop & 0x8000) != 0; if (!timer_for_shinesparks_startstop || v0) { samus_movement_handler = FUNC16(Samus_MoveHandler_ShinesparkCrashFinish); samus_draw_handler = FUNC16(SamusDrawHandler_Default); @@ -5075,7 +4773,7 @@ void Samus_MoveHandler_ShinesparkCrashFinish(void) { // 0x90D40D speed_echo_xpos[2] = samus_x_pos; speed_echo_ypos[2] = samus_y_pos; projectile_type[3] = addr_loc_908029; - InitializeShinesparkEchoOrSpazerSba(6u); + InitializeShinesparkEchoOrSpazerSba(6); projectile_bomb_pre_instructions[3] = FUNC16(ProjPreInstr_SpeedEcho); projectile_variables[3] = kShinesparkCrashFinish_Tab0[(uint16)(2 * (samus_pose - 201))]; projectile_bomb_x_speed[3] = 0; @@ -5085,7 +4783,7 @@ void Samus_MoveHandler_ShinesparkCrashFinish(void) { // 0x90D40D speed_echo_xpos[3] = samus_x_pos; speed_echo_ypos[3] = samus_y_pos; projectile_type[4] = addr_loc_908029; - InitializeShinesparkEchoOrSpazerSba(8u); + InitializeShinesparkEchoOrSpazerSba(8); projectile_bomb_pre_instructions[4] = FUNC16(ProjPreInstr_SpeedEcho); projectile_variables[4] = kShinesparkCrashFinish_Tab0[(uint16)(2 * (samus_pose - 201)) + 1]; projectile_bomb_x_speed[4] = 0; @@ -5108,15 +4806,15 @@ void ProjPreInstr_SpeedEcho(uint16 k) { // 0x90D4D2 int v1 = k >> 1; projectile_bomb_x_speed[v1] += 8; - Projectile_SinLookup(projectile_variables[v1], LOBYTE(projectile_bomb_x_speed[v1])); - uint16 v2 = R20_ + samus_x_pos; - *(uint16 *)((uint8 *)&speed_echoes_index + k) = R20_ + samus_x_pos; + Point16U pt = Projectile_SinLookup(projectile_variables[v1], LOBYTE(projectile_bomb_x_speed[v1])); + uint16 v2 = pt.x + samus_x_pos; + *(uint16 *)((uint8 *)&speed_echoes_index + k) = pt.x + samus_x_pos; projectile_x_pos[v1] = v2; v3 = v2 - layer1_x_pos; if (v3 < 0 || !sign16(v3 - 256) - || (v4 = R22_ + samus_y_pos, - speed_echo_xpos[v1 + 3] = R22_ + samus_y_pos, + || (v4 = pt.y + samus_y_pos, + speed_echo_xpos[v1 + 3] = pt.y + samus_y_pos, projectile_y_pos[v1] = v4, v5 = v4 - layer1_y_pos, v5 < 0) @@ -5134,15 +4832,15 @@ void Grapple_Func1(void) { // 0x90D525 if ((button_config_shoot_x & joypad1_lastkeys) != 0 && (v0 = (int16)(grapple_walljump_timer - 1) < 0, --grapple_walljump_timer, grapple_walljump_timer) && !v0) { - if ((grapple_beam_length_delta & 0x8000u) == 0) { + if ((grapple_beam_length_delta & 0x8000) == 0) { grapple_beam_length += grapple_beam_length_delta; if (!sign16(grapple_beam_length - 96)) grapple_beam_length_delta = -16; } - Projectile_SinLookup(HIBYTE(*(uint16 *)&grapple_beam_end_subangle), grapple_beam_length); - grapple_beam_end_x_pos = R20_ + x_pos_of_start_of_grapple_beam; - grapple_beam_end_y_pos = R22_ + y_pos_of_start_of_grapple_beam; - *(uint16 *)&grapple_beam_end_subangle += 2048; + Point16U pt = Projectile_SinLookup(HIBYTE(grapple_beam_end_angle16), grapple_beam_length); + grapple_beam_end_x_pos = pt.x + x_pos_of_start_of_grapple_beam; + grapple_beam_end_y_pos = pt.y + y_pos_of_start_of_grapple_beam; + grapple_beam_end_angle16 += 2048; GrappleBeamFunc_BF1B(); } else { grapple_beam_function = FUNC16(GrappleBeamFunc_Cancel); @@ -5153,7 +4851,6 @@ uint8 Hdmaobj_CrystalFlash(void) { // 0x90D5A2 SamusPose v1; if (sign16(game_state - 40)) { - R18_ = button_config_shoot_x | 0x430; if (joypad1_lastkeys != (button_config_shoot_x | 0x430)) return 1; } @@ -5196,14 +4893,14 @@ uint8 Hdmaobj_CrystalFlash(void) { // 0x90D5A2 void SamusMoveHandler_CrystalFlashStart(void) { // 0x90D678 samus_y_pos -= 2; - if ((--timer_for_shinesparks_startstop & 0x8000u) != 0) { + if ((--timer_for_shinesparks_startstop & 0x8000) != 0) { samus_anim_frame_timer = 3; samus_anim_frame = 6; *(uint16 *)&suit_pickup_color_math_R = samus_y_pos; samus_movement_handler = FUNC16(SamusMoveHandler_CrystalFlashMain); samus_invincibility_timer = 0; samus_knockback_timer = 0; - QueueSfx3_Max15(1u); + QueueSfx3_Max15(1); power_bomb_flag = 0; power_bomb_explosion_x_pos = samus_x_pos; power_bomb_explosion_y_pos = samus_y_pos; @@ -5227,7 +4924,7 @@ void SamusMoveHandler_CrystalFlashMain(void) { void SamusMoveHandler_CrystalFlashMain_0(void) { // 0x90D6E3 if ((nmi_frame_counter_word & 7) == 0) { --samus_missiles; - Samus_RestoreHealth(0x32u); + Samus_RestoreHealth(0x32); bool v0 = (int16)(substate - 1) < 0; if (!--substate || v0) { substate = 10; @@ -5239,7 +4936,7 @@ void SamusMoveHandler_CrystalFlashMain_0(void) { // 0x90D6E3 void SamusMoveHandler_CrystalFlashMain_1(void) { // 0x90D706 if ((nmi_frame_counter_word & 7) == 0) { --samus_super_missiles; - Samus_RestoreHealth(0x32u); + Samus_RestoreHealth(0x32); bool v0 = (int16)(substate - 1) < 0; if (!--substate || v0) { substate = 10; @@ -5251,7 +4948,7 @@ void SamusMoveHandler_CrystalFlashMain_1(void) { // 0x90D706 void SamusMoveHandler_CrystalFlashMain_2(void) { // 0x90D729 if ((nmi_frame_counter_word & 7) == 0) { --samus_power_bombs; - Samus_RestoreHealth(0x32u); + Samus_RestoreHealth(0x32); bool v0 = (int16)(substate - 1) < 0; if (!--substate || v0) { samus_movement_handler = FUNC16(kSamusMoveHandler_CrystalFlashFinish); @@ -5286,9 +4983,9 @@ void ProjPreInstr_PlasmaSba(uint16 k) { // 0x90D793 } else { cooldown_timer = 2; flare_counter = 0; - Projectile_SinLookup(projectile_variables[v1], projectile_bomb_x_speed[v1]); - projectile_x_pos[v1] = R20_ + samus_x_pos; - projectile_y_pos[v1] = R22_ + samus_y_pos; + Point16U pt = Projectile_SinLookup(projectile_variables[v1], projectile_bomb_x_speed[v1]); + projectile_x_pos[v1] = pt.x + samus_x_pos; + projectile_y_pos[v1] = pt.y + samus_y_pos; projectile_variables[v1] = (uint8)(used_for_sba_attacksB60 + projectile_variables[v1]); v3 = 2 * projectile_bomb_y_speed[v1]; if (v3) { @@ -5364,7 +5061,7 @@ void ProjPreInstr_SpreadBomb(uint16 k) { // 0x90D8F7 v3 = v7 < projectile_timers[v6]; projectile_bomb_y_subpos[v6] = v7 - projectile_timers[v6]; projectile_y_pos[v6] -= v3 + projectile_bomb_y_speed[v6]; - if ((projectile_bomb_y_speed[v6] & 0x8000u) != 0) { + if ((projectile_bomb_y_speed[v6] & 0x8000) != 0) { projectile_bomb_y_speed[v6] = 0; projectile_y_radius[v6] = 0; } else { @@ -5376,38 +5073,38 @@ void ProjPreInstr_SpreadBomb(uint16 k) { // 0x90D8F7 k = projectile_index; int v8 = projectile_index >> 1; uint16 t = projectile_bomb_x_speed[v8]; - R20_ = t << 8; - R18_ = t >> 8; + uint16 r20 = t << 8; + uint16 r18 = t >> 8; if (t & 0x8000) { - R18_ = R18_ & 0x7F; + r18 = r18 & 0x7F; uint16 v11 = projectile_bomb_x_subpos[v8]; - v3 = v11 < R20_; - projectile_bomb_x_subpos[v8] = v11 - R20_; - projectile_x_pos[v8] -= v3 + R18_; + v3 = v11 < r20; + projectile_bomb_x_subpos[v8] = v11 - r20; + projectile_x_pos[v8] -= v3 + r18; } else { uint16 v10 = projectile_bomb_x_subpos[v8]; - v3 = __CFADD__uint16(R20_, v10); - projectile_bomb_x_subpos[v8] = R20_ + v10; - projectile_x_pos[v8] += R18_ + v3; + v3 = __CFADD__uint16(r20, v10); + projectile_bomb_x_subpos[v8] = r20 + v10; + projectile_x_pos[v8] += r18 + v3; } } if (BlockCollSpreadBomb(k) & 1) { int v12 = projectile_index >> 1; uint16 t = projectile_bomb_x_speed[v12]; - R20_ = t << 8; - R18_ = (t >> 8) & 0x7F; + uint16 r20 = t << 8; + uint16 r18 = (t >> 8) & 0x7F; if (t & 0x8000) { projectile_bomb_x_speed[v12] = t | 0x8000; uint16 v16 = projectile_bomb_x_subpos[v12]; - bool v3 = v16 < R20_; - projectile_bomb_x_subpos[v12] = v16 - R20_; - projectile_x_pos[v12] -= v3 + R18_; + bool v3 = v16 < r20; + projectile_bomb_x_subpos[v12] = v16 - r20; + projectile_x_pos[v12] -= v3 + r18; } else { projectile_bomb_x_speed[v12] = t & 0x7FFF; uint16 v14 = projectile_bomb_x_subpos[v12]; - bool v3 = __CFADD__uint16(R20_, v14); - projectile_bomb_x_subpos[v12] = R20_ + v14; - projectile_x_pos[v12] += R18_ + v3; + bool v3 = __CFADD__uint16(r20, v14); + projectile_bomb_x_subpos[v12] = r20 + v14; + projectile_x_pos[v12] += r18 + v3; } } } @@ -5421,12 +5118,12 @@ void ProjPreInstr_WaveSba(uint16 k) { // 0x90DA08 --projectile_bomb_y_speed[v1], v2) || v3) { - QueueSfx1_Max6(0x29u); + QueueSfx1_Max6(0x29); ClearProjectile(k); return; } - R34 = projectile_bomb_x_speed[v1]; - R36 = projectile_variables[v1]; + uint16 R34 = projectile_bomb_x_speed[v1]; + //R36 = projectile_variables[v1]; v2 = projectile_timers[v1]-- == 1; if (v2) { projectile_timers[v1] = 4; @@ -5441,12 +5138,12 @@ void ProjPreInstr_WaveSba(uint16 k) { // 0x90DA08 projectile_bomb_x_speed[v4] += 64; } uint16 v5 = swap16(projectile_bomb_x_speed[v4]); - R20_ = v5 & 0xFF00; - R18_ = (int8)v5; + uint16 r20 = v5 & 0xFF00; + uint16 r18 = (int8)v5; uint16 v6 = projectile_bomb_x_subpos[v4]; - bool v7 = __CFADD__uint16(R20_, v6); - projectile_bomb_x_subpos[v4] = R20_ + v6; - projectile_x_pos[v4] += R18_ + v7; + bool v7 = __CFADD__uint16(r20, v6); + projectile_bomb_x_subpos[v4] = r20 + v6; + projectile_x_pos[v4] += r18 + v7; if ((int16)(samus_y_pos - projectile_y_pos[v4]) < 0) { if (!sign16(projectile_variables[v4] + 2047)) projectile_variables[v4] -= 64; @@ -5454,18 +5151,18 @@ void ProjPreInstr_WaveSba(uint16 k) { // 0x90DA08 projectile_variables[v4] += 64; } uint16 v8 = swap16(projectile_variables[v4]); - R20_ = v8 & 0xFF00; - R18_ = (int8)v8; + r20 = v8 & 0xFF00; + r18 = (int8)v8; uint16 v9 = projectile_bomb_y_subpos[v4]; - v7 = __CFADD__uint16(R20_, v9); - projectile_bomb_y_subpos[v4] = R20_ + v9; - projectile_y_pos[v4] += R18_ + v7; + v7 = __CFADD__uint16(r20, v9); + projectile_bomb_y_subpos[v4] = r20 + v9; + projectile_y_pos[v4] += r18 + v7; if (k == 6) { - if ((projectile_bomb_x_speed[3] & 0x8000u) != 0) { - if ((R34 & 0x8000u) == 0) + if ((projectile_bomb_x_speed[3] & 0x8000) != 0) { + if ((R34 & 0x8000) == 0) LABEL_26: - QueueSfx1_Max6(0x28u); - } else if ((R34 & 0x8000u) != 0) { + QueueSfx1_Max6(0x28); + } else if ((R34 & 0x8000) != 0) { goto LABEL_26; } } @@ -5473,7 +5170,6 @@ void ProjPreInstr_WaveSba(uint16 k) { // 0x90DA08 flare_counter = 0; } - void BombSpread(void) { // 0x90D849 if (bomb_functions[0] != FUNC16(ProjPreInstr_SpreadBomb)) { uint16 v0 = 10; @@ -5503,11 +5199,14 @@ void BombSpread(void) { // 0x90D849 } } -static Func_Y_V *const kProjPreInstr_SpazerSba_FuncsB[3] = { // 0x90DB06 +typedef void Func_SpazerSba_V(uint16 j, uint16 r22); + +static Func_SpazerSba_V *const kProjPreInstr_SpazerSba_FuncsB[3] = { // 0x90DB06 ProjPreInstr_SpazerSba_FuncB_0, ProjPreInstr_SpazerSba_FuncB_1, ProjPreInstr_SpazerSba_FuncB_2, }; + static Func_Y_V *const kProjPreInstr_SpazerSba_FuncsA[4] = { ProjPreInstr_SpazerSba_FuncA_0, ProjPreInstr_SpazerSba_FuncA_1, @@ -5516,7 +5215,6 @@ static Func_Y_V *const kProjPreInstr_SpazerSba_FuncsA[4] = { }; void ProjPreInstr_SpazerSba(uint16 k) { - int v1 = k >> 1; if ((projectile_dir[v1] & 0xF0) != 0) { kProjPreInstr_SpazerSba_FuncsA[v1](k); @@ -5528,9 +5226,9 @@ void ProjPreInstr_SpazerSba(uint16 k) { k = projectile_index; } int v4 = k >> 1; - Projectile_SinLookup(projectile_variables[v4], projectile_bomb_x_speed[v4]); - projectile_x_pos[v4] = R20_ + samus_x_pos; - kProjPreInstr_SpazerSba_FuncsB[projectile_unk_A[v4] >> 1](k); + Point16U pt = Projectile_SinLookup(projectile_variables[v4], projectile_bomb_x_speed[v4]); + projectile_x_pos[v4] = pt.x + samus_x_pos; + kProjPreInstr_SpazerSba_FuncsB[projectile_unk_A[v4] >> 1](k, pt.y); cooldown_timer = 2; flare_counter = 0; } @@ -5538,12 +5236,12 @@ void ProjPreInstr_SpazerSba(uint16 k) { void ProjPreInstr_SpazerSba_FuncA_0(uint16 k) { // 0x90DB57 ClearProjectile(k); - ClearProjectile(4u); + ClearProjectile(4); } void ProjPreInstr_SpazerSba_FuncA_1(uint16 k) { // 0x90DB66 ClearProjectile(k); - ClearProjectile(6u); + ClearProjectile(6); } void ProjPreInstr_SpazerSba_FuncA_2(uint16 k) { // 0x90DB75 @@ -5553,14 +5251,14 @@ void ProjPreInstr_SpazerSba_FuncA_2(uint16 k) { // 0x90DB75 void ProjPreInstr_SpazerSba_FuncA_3(uint16 k) { // 0x90DB84 ClearProjectile(k); - ClearProjectile(2u); + ClearProjectile(2); } -void ProjPreInstr_SpazerSba_FuncB_0(uint16 j) { // 0x90DB93 +void ProjPreInstr_SpazerSba_FuncB_0(uint16 j, uint16 r22) { // 0x90DB93 static const int16 kProjPreInstr_SpazerSba_Yspeed[4] = { 2, -2, 2, -2 }; int v1 = j >> 1; - projectile_y_pos[v1] = R22_ + samus_y_pos; + projectile_y_pos[v1] = r22 + samus_y_pos; uint16 v2 = (uint8)(LOBYTE(projectile_bomb_y_speed[v1]) + LOBYTE(projectile_variables[v1])); projectile_variables[v1] = v2; if (v2 == 128) { @@ -5571,10 +5269,10 @@ void ProjPreInstr_SpazerSba_FuncB_0(uint16 j) { // 0x90DB93 } } -void ProjPreInstr_SpazerSba_FuncB_1(uint16 j) { // 0x90DBCF +void ProjPreInstr_SpazerSba_FuncB_1(uint16 j, uint16 r22) { // 0x90DBCF static const int16 kSpazerProjectileYSpeed[4] = { -2, 2, -2, 2 }; - uint16 v1 = R22_ + samus_y_pos - 114; + uint16 v1 = r22 + samus_y_pos - 114; int v2 = j >> 1; projectile_y_pos[v2] = v1; if (sign16(v1 - layer1_y_pos - 16)) { @@ -5588,16 +5286,16 @@ void ProjPreInstr_SpazerSba_FuncB_1(uint16 j) { // 0x90DBCF projectile_variables[v2] = (uint8)(projectile_variables[v2] + 0x80); projectile_unk_A[v2] = 4; if (!j) - QueueSfx1_Max6(0x26u); + QueueSfx1_Max6(0x26); } } } -void ProjPreInstr_SpazerSba_FuncB_2(uint16 j) { // 0x90DC30 +void ProjPreInstr_SpazerSba_FuncB_2(uint16 j, uint16 r22) { // 0x90DC30 int v2; uint16 v3; - uint16 v1 = R22_ + samus_y_pos - 114; + uint16 v1 = r22 + samus_y_pos - 114; projectile_y_pos[j >> 1] = v1; if (sign16(v1 - layer1_y_pos - 16) || (v2 = j >> 1, @@ -5806,7 +5504,7 @@ void Samus_HitInterruption(void) { } else if (knockback_dir) { if (samus_movement_type == kPose_0A_MoveL_NoAim) { if (!sign16(flare_counter - 16)) - QueueSfx1_Max6(0x41u); + QueueSfx1_Max6(0x41); if (samus_pose_x_dir == 4) samus_new_pose_transitional = kPose_2A_FaceL_Fall; else @@ -6102,7 +5800,6 @@ void Samus_PushOutOfRidleysWay(void) { // 0x90E12E *(uint16 *)&samus_last_different_pose_x_dir = *(uint16 *)&samus_prev_pose_x_dir; samus_prev_pose = samus_pose; *(uint16 *)&samus_prev_pose_x_dir = *(uint16 *)&samus_pose_x_dir; - R18_ = 21 - samus_y_radius; samus_y_pos -= 21 - samus_y_radius; if (sign16(samus_x_pos - layer1_x_pos - 128)) samus_var62 = 1; @@ -6253,124 +5950,107 @@ void Samus_Func8(void) { // 0x90E400 } void Samus_Func9(void) { // 0x90E41B - unsigned int v0; // kr00_4 - if (sign16(samus_y_speed - 5)) { - v0 = __PAIR32__(samus_y_accel, samus_y_subaccel) + __PAIR32__(samus_y_speed, samus_y_subspeed); + uint32 v0 = __PAIR32__(samus_y_accel, samus_y_subaccel) + __PAIR32__(samus_y_speed, samus_y_subspeed); samus_y_speed = HIWORD(v0); samus_y_subspeed = v0; } - if ((samus_pose == kPose_29_FaceR_Fall - || samus_pose == kPose_2A_FaceL_Fall - || samus_pose == kPose_67_FaceR_Fall_Gun - || samus_pose == kPose_68_FaceL_Fall_Gun) + if ((samus_pose == kPose_29_FaceR_Fall || samus_pose == kPose_2A_FaceL_Fall + || samus_pose == kPose_67_FaceR_Fall_Gun || samus_pose == kPose_68_FaceL_Fall_Gun) && !sign16(samus_y_speed - 5)) { samus_anim_frame_timer = 16; samus_anim_frame = 4; } } -void Samus_CalcDisplacementMoveLeft(void) { // 0x90E464 - int16 v1; - - Samus_CalcSpeed_X(); - samus_collision_direction = 0; - R18_ = ~R18_; - bool v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - v1 = (__PAIR32__(R18_, R20_) + __PAIR32__(extra_samus_x_displacement, extra_samus_x_subdisplacement)) >> 16; - R20_ += extra_samus_x_subdisplacement; - R18_ = v1; - if (v1 < 0) { - if (sign16(v1 + 15)) - R18_ = -15; - } else if (!sign16(v1 - 16)) { - R18_ = 15; - } -} - -void Samus_CalcDisplacementMoveRight(void) { // 0x90E4AD - int16 v0; - - Samus_CalcSpeed_X(); - samus_collision_direction = 1; - v0 = (__PAIR32__(R18_, R20_) + __PAIR32__(extra_samus_x_displacement, extra_samus_x_subdisplacement)) >> 16; - R20_ += extra_samus_x_subdisplacement; - R18_ = v0; +static int32 Samus_ClampSpeed(int32 amt) { + uint16 r18 = amt >> 16, r20 = amt; + int16 v0 = r18; if (v0 < 0) { if (sign16(v0 + 15)) - R18_ = -15; + r18 = -15; } else if (!sign16(v0 - 16)) { - R18_ = 15; + r18 = 15; } + return r18 << 16 | r20; } -void Samus_CalcSpeed_X(void) { // 0x90E4E6 +int32 Samus_CalcDisplacementMoveLeft(int32 amt) { // 0x90E464 + amt = Samus_CalcSpeed_X(amt); + samus_collision_direction = 0; + amt = __PAIR32__(extra_samus_x_displacement, extra_samus_x_subdisplacement) - amt; + return Samus_ClampSpeed(amt); +} + +int32 Samus_CalcDisplacementMoveRight(int32 amt) { // 0x90E4AD + amt = Samus_CalcSpeed_X(amt); + samus_collision_direction = 1; + amt += __PAIR32__(extra_samus_x_displacement, extra_samus_x_subdisplacement); + return Samus_ClampSpeed(amt); +} + +int32 Samus_CalcSpeed_X(int32 amt) { // 0x90E4E6 + uint16 r18 = amt >> 16, r20 = amt; uint16 v0 = samus_x_speed_divisor; if (!sign16(samus_x_speed_divisor - 5)) v0 = 4; switch (v0) { case 0: { - bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, R20_); - R20_ += samus_x_extra_run_subspeed; - samus_total_x_subspeed = R20_; - R18_ += samus_x_extra_run_speed + v2; - samus_total_x_speed = R18_; + bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, r20); + r20 += samus_x_extra_run_subspeed; + samus_total_x_subspeed = r20; + r18 += samus_x_extra_run_speed + v2; + samus_total_x_speed = r18; break; } case 1: { - bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, R20_); - R20_ += samus_x_extra_run_subspeed; - uint16 t = samus_x_extra_run_speed + v2 + R18_; + bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, r20); + r20 += samus_x_extra_run_subspeed; + uint16 t = samus_x_extra_run_speed + v2 + r18; uint16 v3 = swap16(swap16(t) >> 1); - R18_ = (uint8)v3; + r18 = (uint8)v3; samus_total_x_speed = (uint8)v3; - R22_ = v3 & 0xFF00; - R20_ = R22_ + (R20_ >> 1); - samus_total_x_subspeed = R20_; + r20 = (v3 & 0xFF00) + (r20 >> 1); + samus_total_x_subspeed = r20; break; } case 2: { - bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, R20_); - R20_ += samus_x_extra_run_subspeed; - uint16 t = samus_x_extra_run_speed + v2 + R18_; + bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, r20); + r20 += samus_x_extra_run_subspeed; + uint16 t = samus_x_extra_run_speed + v2 + r18; uint16 v5 = swap16(swap16(t) >> 2); - R18_ = (uint8)v5; + r18 = (uint8)v5; samus_total_x_speed = (uint8)v5; - R22_ = v5 & 0xFF00; - R20_ = (v5 & 0xFF00) + (R20_ >> 2); - samus_total_x_subspeed = R20_; + r20 = (v5 & 0xFF00) + (r20 >> 2); + samus_total_x_subspeed = r20; break; } case 3: { - bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, R20_); - R20_ += samus_x_extra_run_subspeed; - uint16 t = samus_x_extra_run_speed + v2 + R18_; + bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, r20); + r20 += samus_x_extra_run_subspeed; + uint16 t = samus_x_extra_run_speed + v2 + r18; uint16 v7 = swap16(swap16(t) >> 3); - R18_ = (uint8)v7; + r18 = (uint8)v7; samus_total_x_speed = (uint8)v7; - R22_ = v7 & 0xFF00; - R20_ = (v7 & 0xFF00) + (R20_ >> 3); - samus_total_x_subspeed = R20_; + r20 = (v7 & 0xFF00) + (r20 >> 3); + samus_total_x_subspeed = r20; break; } case 4: { - bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, R20_); - R20_ += samus_x_extra_run_subspeed; - uint16 t = samus_x_extra_run_speed + v2 + R18_; + bool v2 = __CFADD__uint16(samus_x_extra_run_subspeed, r20); + r20 += samus_x_extra_run_subspeed; + uint16 t = samus_x_extra_run_speed + v2 + r18; uint16 v9 = swap16(swap16(t) >> 4); - R18_ = (uint8)v9; + r18 = (uint8)v9; samus_total_x_speed = (uint8)v9; - R22_ = v9 & 0xFF00; - R20_ = (v9 & 0xFF00) + (R20_ >> 4); - samus_total_x_subspeed = R20_; + r20 = (v9 & 0xFF00) + (r20 >> 4); + samus_total_x_subspeed = r20; break; } default: Unreachable(); } + return r18 << 16 | r20; } void Samus_ClearXSpeedIfColl(void) { // 0x90E5CE @@ -6512,7 +6192,7 @@ void Samus_FrameHandlerBeta_Func17(void) { // 0x90E725 } void HandleDemoRecorder_1(void) { // 0x90E786 - if ((joypad2_new_keys & 0x8000u) == 0) { + if ((joypad2_new_keys & 0x8000) == 0) { if (!debug_flag && (joypad2_new_keys & 0x80) != 0) { DisableEnemyProjectiles(); time_is_frozen_flag = 1; @@ -6573,7 +6253,7 @@ void Samus_Func16(void) { // 0x90E86A elevator_status = 0; samus_prev_y_pos = samus_y_pos; if (PlaySamusFanfare() & 1) { - if (sign16(debug_invincibility - 7) || (joypad2_last & 0x8000u) == 0) + if (sign16(debug_invincibility - 7) || (joypad2_last & 0x8000) == 0) debug_invincibility = 0; frame_handler_alfa = FUNC16(Samus_FrameHandlerAlfa_Func11); frame_handler_beta = FUNC16(Samus_FrameHandlerBeta_Func17); @@ -6728,7 +6408,7 @@ void Samus_HandlePeriodicDamage(void) { // 0x90E9CE samus_periodic_subdamage = v0 & 0xFF00; samus_periodic_damage = HIBYTE(v3); } - if ((samus_periodic_damage & 0x8000u) != 0) { + if ((samus_periodic_damage & 0x8000) != 0) { InvalidInterrupt_Crash(); return; } @@ -6763,12 +6443,12 @@ void Samus_PauseCheck(void) { // 0x90EA45 void Samus_LowHealthCheck_(void) { // 0x90EA7F if (sign16(samus_health - 31)) { if (!samus_health_warning) { - QueueSfx3_Max6(2u); + QueueSfx3_Max6(2); samus_health_warning = 1; } } else if (samus_health_warning) { samus_health_warning = 0; - QueueSfx3_Max6(1u); + QueueSfx3_Max6(1); } } @@ -6916,27 +6596,23 @@ void SamusDisplayHandler_SamusReceivedFatal(void) { // 0x90EC1D } void Samus_SetRadius(void) { // 0x90EC22 - samus_y_radius = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); + samus_y_radius = kPoseParams[samus_pose].y_radius; samus_x_radius = 5; } -void Samus_GetBottomBoundary(void) { // 0x90EC3E - R18_ = samus_y_pos + *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)) - 1; +uint16 Samus_GetBottom_R18(void) { + return samus_y_pos + kPoseParams[samus_pose].y_radius - 1; } -void Samus_GetTopBottomBoundary(void) { // 0x90EC58 - int16 v0; - - v0 = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); - R18_ = samus_y_pos + v0 - 1; - R20_ = samus_y_pos - v0; +uint16 Samus_GetTop_R20(void) { + return samus_y_pos - kPoseParams[samus_pose].y_radius; } void Samus_AlignBottomWithPrevPose(void) { // 0x90EC7E - R18_ = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); - R18_ = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_prev_pose)) - R18_; - samus_y_pos += R18_; - samus_prev_y_pos += R18_; + uint16 r18 = kPoseParams[samus_pose].y_radius; + r18 = kPoseParams[samus_prev_pose].y_radius - r18; + samus_y_pos += r18; + samus_prev_y_pos += r18; } void Samus_UpdateSuitPaletteIndex(void) { // 0x90ECB6 @@ -6950,26 +6626,14 @@ void Samus_UpdateSuitPaletteIndex(void) { // 0x90ECB6 } void MoveSamusWithControlPad(void) { // 0x90ECD5 - if ((joypad1_lastkeys & 0x800) != 0) { - R18_ = -4; - R20_ = 0; - Samus_MoveUp(); - } - if ((joypad1_lastkeys & 0x400) != 0) { - R18_ = 4; - R20_ = 0; - Samus_MoveDown(); - } - if ((joypad1_lastkeys & 0x200) != 0) { - R18_ = -4; - R20_ = 0; - Samus_MoveLeft(); - } - if ((joypad1_lastkeys & 0x100) != 0) { - R18_ = 4; - R20_ = 0; - Samus_MoveRight(); - } + if ((joypad1_lastkeys & 0x800) != 0) + Samus_MoveUp(INT16_SHL16(-4)); + if ((joypad1_lastkeys & 0x400) != 0) + Samus_MoveDown(INT16_SHL16(4)); + if ((joypad1_lastkeys & 0x200) != 0) + Samus_MoveLeft(INT16_SHL16(-4)); + if ((joypad1_lastkeys & 0x100) != 0) + Samus_MoveRight(INT16_SHL16(4)); } static const uint8 byte_90ED50[28] = { // 0x90ED26 @@ -7036,11 +6700,11 @@ LABEL_12: } void Samus_FootstepGraphics_Maridia(void) { // 0x90EDEC - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) return; - } else if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { return; } if (samus_pose_x_dir == 4) { @@ -7060,11 +6724,11 @@ void Samus_FootstepGraphics_Maridia(void) { // 0x90EDEC void Samus_FootstepGraphics_1(void) { // 0x90EE64 if ((speed_boost_counter & 0xFF00) == 1024) { - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) + uint16 r18 = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) return; - } else if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r18) && (fx_liquid_options & 4) == 0) { return; } if (samus_pose_x_dir == 4) { @@ -7084,7 +6748,7 @@ void Samus_FootstepGraphics_1(void) { // 0x90EE64 } void Samus_UpdateSpeedEchoPos(void) { // 0x90EEE7 - if ((speed_boost_counter & 0xFF00) == 1024 && (speed_echoes_index & 0x8000u) == 0 && (game_time_frames & 3) == 0) { + if ((speed_boost_counter & 0xFF00) == 1024 && (speed_echoes_index & 0x8000) == 0 && (game_time_frames & 3) == 0) { uint16 v0 = speed_echoes_index; int v1 = speed_echoes_index >> 1; speed_echo_xpos[v1] = samus_x_pos; @@ -7273,7 +6937,7 @@ uint8 SamusCode_06_LockToStation(void) { // 0x90F1AA frame_handler_alfa = FUNC16(Samus_FrameHandlerAlfa_Func13); frame_handler_beta = FUNC16(j_HandleDemoRecorder_2); if (!sign16(flare_counter - 15)) - QueueSfx1_Max15(2u); + QueueSfx1_Max15(2); return SamusCode_04_06_Common(); } @@ -7288,9 +6952,6 @@ uint8 SamusCode_07_SetupForElevator(void) { // 0x90F1C8 } uint8 SamusCode_08_SetupForCeresStart(void) { // 0x90F1E9 - uint16 v1; - uint16 v2; - frame_handler_alfa = FUNC16(EmptyFunction); frame_handler_beta = FUNC16(SetContactDamageIndexAndUpdateMinimap); samus_pose = kPose_00_FaceF_Powersuit; @@ -7304,7 +6965,6 @@ uint8 SamusCode_08_SetupForCeresStart(void) { // 0x90F1E9 *(uint16 *)&samus_prev_pose_x_dir = *(uint16 *)&samus_pose_x_dir; *(uint16 *)&samus_last_different_pose_x_dir = *(uint16 *)&samus_pose_x_dir; samus_y_pos = 0; - uint16 v0 = v1 = v2 = 0; SpawnEnemyProjectileWithGfx(0, 0, addr_kEproj_CeresElevatorPad); SpawnEnemyProjectileWithGfx(0, 0, addr_kEproj_CeresElevatorPlatform); debug_disable_minimap = 0; @@ -7358,7 +7018,6 @@ uint8 SamusCode_0D_IsGrappleActive_A(void) { return grapple_beam_function != FUNC16(GrappleBeamFunc_Inactive); } - uint8 SamusCode_0E(void) { // 0x90F2CA frame_handler_alfa = FUNC16(Samus_FrameHandlerAlfa_Func11); frame_handler_beta = FUNC16(Samus_Func18); @@ -7384,12 +7043,12 @@ uint8 SamusCode_11_15_Common(void) { // 0x90F2FC samus_draw_handler = FUNC16(SamusDisplayHandler_SamusReceivedFatal); return 1; } + uint8 SamusCode_11_SetupForDeath(void) { // 0x90F2F8 DisablePaletteFx(); return SamusCode_11_15_Common(); } - uint8 SamusCode_15_CalledBySuitAcquision(void) { // 0x90F310 Samus_UpdatePreviousPose(); flare_counter = 0; @@ -7411,26 +7070,21 @@ uint8 SamusCode_12_SetSuperPaletteFlag0(void) { // 0x90F328 uint8 SamusCode_14(void) { // 0x90F331 if (sign16(samus_health - 31)) - QueueSfx3_Max6(2u); + QueueSfx3_Max6(2); if (!SamusCode_0D_IsGrappleActive_A()) { if (samus_pose_x_dir == 3) { if (samus_pose == kPose_81_FaceR_Screwattack || samus_pose == kPose_82_FaceL_Screwattack) { - QueueSfx1_Max6(0x33u); - return 0; + QueueSfx1_Max6(0x33); } else if (samus_pose == kPose_1B_FaceR_SpaceJump || samus_pose == kPose_1C_FaceL_SpaceJump) { - QueueSfx1_Max6(0x3Eu); - return 0; + QueueSfx1_Max6(0x3E); } else { - QueueSfx1_Max6(0x31u); - return 0; + QueueSfx1_Max6(0x31); } - } else { - return 0; } } else { - QueueSfx1_Max6(6u); - return 0; + QueueSfx1_Max6(6); } + return 0; } uint8 SamusCode_05_SetupDrained(void) { // 0x90F38E @@ -7499,7 +7153,7 @@ uint8 SamusCode_1C(void) { // 0x90F41E if (sign16(samus_anim_frame - 23)) { if (sign16(samus_anim_frame - 13)) { LABEL_11: - QueueSfx1_Max9(0x31u); + QueueSfx1_Max9(0x31); return 0; } goto LABEL_12; @@ -7511,22 +7165,22 @@ LABEL_11: if (samus_pose != kPose_1B_FaceR_SpaceJump && samus_pose != kPose_1C_FaceL_SpaceJump) goto LABEL_11; LABEL_12: - QueueSfx1_Max9(0x3Eu); + QueueSfx1_Max9(0x3E); return 0; } } - QueueSfx1_Max9(0x33u); + QueueSfx1_Max9(0x33); return 0; } uint8 SamusCode_1D_ClearSoundInDoor(void) { // 0x90F471 if (samus_movement_type == 3 || samus_movement_type == 20) { - QueueSfx1_Max15(0x32u); + QueueSfx1_Max15(0x32); return 0; } else { if ((button_config_shoot_x & joypad1_lastkeys) == 0) { if (sign16(flare_counter - 16)) - QueueSfx1_Max15(2u); + QueueSfx1_Max15(2); } return 0; } @@ -7539,7 +7193,7 @@ uint8 SamusCode_1E(void) { // 0x90F4A2 return 0; } if (!sign16(flare_counter - 16)) - QueueSfx1_Max9(0x41u); + QueueSfx1_Max9(0x41); } return 0; } @@ -7566,27 +7220,27 @@ uint8 Samus_Func26(void) { // 0x90F507 && samus_movement_type != kMovementType_14_WallJumping && (button_config_shoot_x & joypad1_lastkeys) != 0 && !sign16(flare_counter - 16)) { - QueueSfx1_Max9(0x41u); + QueueSfx1_Max9(0x41); } return 0; } void Samus_ShootCheck(void) { // 0x90F576 - if ((play_resume_charging_beam_sfx & 0x8000u) != 0) + if ((play_resume_charging_beam_sfx & 0x8000) != 0) goto LABEL_15; if (play_resume_charging_beam_sfx) { if ((button_config_shoot_x & joypad1_lastkeys) != 0) - QueueSfx1_Max9(0x41u); + QueueSfx1_Max9(0x41); play_resume_charging_beam_sfx = 0; } if (samus_echoes_sound_flag && (speed_boost_counter & 0x400) == 0) { samus_echoes_sound_flag = 0; - QueueSfx3_Max15(0x25u); + QueueSfx3_Max15(0x25); } if ((samus_prev_movement_type == 3 || samus_prev_movement_type == 20) && samus_movement_type != kMovementType_03_SpinJumping && samus_movement_type != kMovementType_14_WallJumping) { - QueueSfx1_Max15(0x32u); + QueueSfx1_Max15(0x32); if (!sign16(flare_counter - 16) && (button_config_shoot_x & joypad1_lastkeys) != 0) LABEL_15: play_resume_charging_beam_sfx = 1; @@ -7601,9 +7255,9 @@ void Samus_ShootCheck(void) { // 0x90F576 debug_invincibility = 0; } } - if (CheckEventHappened(0xEu) & 1 + if (CheckEventHappened(0xE) & 1 && frame_handler_gamma == FUNC16(DrawTimer_) && game_state != kGameState_35_TimeUp) { game_state = kGameState_35_TimeUp; } -} \ No newline at end of file +} diff --git a/src/sm_91.c b/src/sm_91.c index 1677a3f..ca9699f 100644 --- a/src/sm_91.c +++ b/src/sm_91.c @@ -30,6 +30,17 @@ #define kSamusTurnPose_Falling ((uint8*)RomFixedPtr(0x91f9e0)) #define kSamusTurnPose_Moonwalk ((uint8*)RomFixedPtr(0x91f9ea)) +static void Xray_Func12(uint16 dst_r22, const uint8 *jp); +static void Xray_Func13(uint16 dst_r22, uint16 j); +static void Xray_Func14(uint16 dst_r22, const uint8 *jp); +static void Xray_Func15(uint16 dst_r22, const uint8 *jp); +static void Xray_Func16(uint16 dst_r22, uint16 j); + +typedef struct Pair_R18_R20 { + uint16 r18, r20; +} Pair_R18_R20; + +Pair_R18_R20 TranslateCustomControllerBindingsToDefault(void); static Func_V *const kSamusInputHandlers[28] = { @@ -201,16 +212,16 @@ void Samus_LookupTransitionTable(void) { // 0x9181A9 PoseEntry *v6; if (joypad1_lastkeys) { - TranslateCustomControllerBindingsToDefault(); + Pair_R18_R20 pair = TranslateCustomControllerBindingsToDefault(); uint16 v0 = kPoseTransitionTable[samus_pose]; pe = get_PoseEntry(v0); v2 = pe->new_input + 1; if (pe->new_input != 0xFFFF) { while (1) { uint16 v3 = v2 - 1; - if (!v3 || (R18_ & v3) == 0) { + if (!v3 || (pair.r18 & v3) == 0) { uint16 cur_input = get_PoseEntry(v0)->cur_input; - if (!cur_input || (R20_ & cur_input) == 0) + if (!cur_input || (pair.r20 & cur_input) == 0) break; } v0 += 6; @@ -232,66 +243,47 @@ LABEL_8: } } -void TranslateCustomControllerBindingsToDefault(void) { // 0x9181F4 - R18_ = joypad1_newkeys & (kButton_Up | kButton_Down | kButton_Left | kButton_Right); - R20_ = joypad1_lastkeys & (kButton_Up | kButton_Down | kButton_Left | kButton_Right); +Pair_R18_R20 TranslateCustomControllerBindingsToDefault(void) { // 0x9181F4 + uint16 r18 = joypad1_newkeys & (kButton_Up | kButton_Down | kButton_Left | kButton_Right); + uint16 r20 = joypad1_lastkeys & (kButton_Up | kButton_Down | kButton_Left | kButton_Right); uint16 v0 = joypad1_newkeys; - if ((button_config_shoot_x & joypad1_newkeys) != 0) { - R18_ |= kButton_X; - v0 = joypad1_newkeys; - } - if ((button_config_jump_a & v0) != 0) { - R18_ |= kButton_A; - v0 = joypad1_newkeys; - } - if ((button_config_run_b & v0) != 0) { - R18_ |= kButton_B; - v0 = joypad1_newkeys; - } - if ((button_config_itemcancel_y & v0) != 0) { - R18_ |= kButton_Y; - v0 = joypad1_newkeys; - } + if ((button_config_shoot_x & joypad1_newkeys) != 0) + r18 |= kButton_X; + if ((button_config_jump_a & v0) != 0) + r18 |= kButton_A; + if ((button_config_run_b & v0) != 0) + r18 |= kButton_B; + if ((button_config_itemcancel_y & v0) != 0) + r18 |= kButton_Y; if ((button_config_aim_up_R & v0) != 0) { if ((button_config_aim_up_R & (kButton_L | kButton_R)) != 0) - R18_ |= kButton_R; - v0 = joypad1_newkeys; + r18 |= kButton_R; } if ((button_config_aim_down_L & v0) != 0 && (button_config_aim_down_L & (kButton_L | kButton_R)) != 0) - R18_ |= kButton_L; - R18_ = ~R18_; + r18 |= kButton_L; uint16 v1 = joypad1_lastkeys; - if ((button_config_shoot_x & joypad1_lastkeys) != 0) { - R20_ |= kButton_X; - v1 = joypad1_lastkeys; - } - if ((button_config_jump_a & v1) != 0) { - R20_ |= kButton_A; - v1 = joypad1_lastkeys; - } - if ((button_config_run_b & v1) != 0) { - R20_ |= kButton_B; - v1 = joypad1_lastkeys; - } - if ((button_config_itemcancel_y & v1) != 0) { - R20_ |= kButton_Y; - v1 = joypad1_lastkeys; - } + if ((button_config_shoot_x & joypad1_lastkeys) != 0) + r20 |= kButton_X; + if ((button_config_jump_a & v1) != 0) + r20 |= kButton_A; + if ((button_config_run_b & v1) != 0) + r20 |= kButton_B; + if ((button_config_itemcancel_y & v1) != 0) + r20 |= kButton_Y; if ((button_config_aim_up_R & v1) != 0) { if ((button_config_aim_up_R & (kButton_L | kButton_R)) != 0) - R20_ |= kButton_R; - v1 = joypad1_lastkeys; + r20 |= kButton_R; } if ((button_config_aim_down_L & v1) != 0 && (button_config_aim_down_L & (kButton_L | kButton_R)) != 0) - R20_ |= kButton_L; - R20_ = ~R20_; + r20 |= kButton_L; + return (Pair_R18_R20) { ~r18, ~r20 }; } void Samus_Pose_CancelGrapple(void) { // 0x9182D9 - if (Samus_Pose_Func2() & 1 || *(&kPoseParams[0].new_pose_unless_buttons + (uint16)(8 * samus_pose)) == 255) + if (Samus_Pose_Func2() & 1 || kPoseParams[samus_pose].new_pose_unless_buttons == 255) samus_new_pose = samus_pose; else - samus_new_pose = *(&kPoseParams[0].new_pose_unless_buttons + (uint16)(8 * samus_pose)); + samus_new_pose = kPoseParams[samus_pose].new_pose_unless_buttons; } static const uint8 kSamus_Pose_Func2_Tab[28] = { // 0x918304 @@ -316,12 +308,12 @@ LABEL_2: void EnableDemoInput(void) { // 0x91834E samus_input_handler = FUNC16(Samus_InputHandler_E91D); - demo_enable |= 0x8000u; + demo_enable |= 0x8000; } void DisableDemoInput(void) { // 0x91835F samus_input_handler = FUNC16(Samus_InputHandler_E913); - demo_enable &= ~0x8000u; + demo_enable &= ~0x8000; } void ResetDemoData(void) { // 0x918370 @@ -349,7 +341,7 @@ void LoadDemoInputObject(uint16 a, uint16 j) { // 0x918395 } void DemoObjectInputHandler(void) { // 0x9183C0 - if ((demo_enable & 0x8000u) != 0) { + if ((demo_enable & 0x8000) != 0) { if (demo_input_instr_ptr) { ProcessDemoInputObject(); joypad1_input_samusfilter = demo_input_prev; @@ -396,9 +388,8 @@ void ProcessDemoInputObject(void) { // 0x9183F2 while (1) { v1 = (uint16 *)RomPtr_91(v0); uint16 v2 = *v1; - if ((*v1 & 0x8000u) == 0) + if ((*v1 & 0x8000) == 0) break; - R18_ = *v1; v0 = CallDemoInstr(v2 | 0x910000, 0, v0 + 2); if (!v0) return; @@ -543,7 +534,6 @@ static Func_V *const *const kDemoSetFuncPtrs[4] = { void LoadDemoData(void) { DemoSetDef *DemoSetDef; - R18_ = 16 * demo_scene; uint16 v0 = 16 * demo_scene + kDemoSetDefPtrs[demo_set]; DemoSetDef = get_DemoSetDef(v0); collected_items = DemoSetDef->items; @@ -563,7 +553,6 @@ void LoadDemoData(void) { EnableDemoInput(); uint16 demo_obj = get_DemoSetDef(v0)->demo_obj; LoadDemoInputObject(demo_obj, demo_obj); - R18_ = 2 * demo_scene; kDemoSetFuncPtrs[demo_set][demo_scene](); frame_handler_alfa = FUNC16(Samus_FrameHandlerAlfa_Func12); frame_handler_beta = FUNC16(Samus_FrameHandlerBeta_Func14); @@ -597,7 +586,7 @@ void DemoSetFunc_0(void) { // 0x918A33 } void DemoSetFunc_3(void) { // 0x918A3E - DemoSetFunc_Common(0x1Fu); + DemoSetFunc_Common(0x1F); } void DemoSetFunc_7(void) { // 0x918A43 @@ -606,15 +595,15 @@ void DemoSetFunc_7(void) { // 0x918A43 } void DemoSetFunc_2(void) { // 0x918A49 - DemoSetFunc_Common(2u); + DemoSetFunc_Common(2); } void DemoSetFunc_4(void) { // 0x918A4E - DemoSetFunc_Common(0x2Au); + DemoSetFunc_Common(0x2A); } void DemoSetFunc_1(void) { // 0x918A53 - DemoSetFunc_Common(1u); + DemoSetFunc_Common(1); } void DemoSetFunc_Common(uint16 a) { // 0x918A56 @@ -656,1213 +645,222 @@ void DemoPreInstr_8AB0(void) { // 0x918AB0 } -static Func_V *const kXrayHdmaFuncs[5] = { // 0x91BE11 - XrayHdmaFunc_BeamAimedR, - XrayHdmaFunc_BeamAimedU, - XrayHdmaFunc_BeamAimedD, - XrayHdmaFunc_BeamAimedL, - XrayHdmaFunc_BeamHoriz, -}; +typedef struct XrayHdmaCtx { + uint16 r22; + uint16 r24; + uint16 r26; + uint16 r28; + uint16 r30; + uint16 r32; + uint16 r18_avoid; + uint16 *dest; +} XrayHdmaCtx; -void CalculateXrayHdmaTable_OriginOffScreen(uint16 k, uint16 j) { +static void XrayFillUp(uint16 *dest, uint16 fill_with, uint16 v1) { + do { + dest[v1 >> 1] = fill_with; + } while (!sign16(v1 -= 2)); +} + +static void XrayFillDown(uint16 *dest, uint16 fill_with, uint16 v1) { + do { + dest[v1 >> 1] = fill_with; + } while ((v1 += 2) < 460); +} + +static void XrayFillUpRamped(uint16 *dest, int pos, uint32 left, uint32 left_step, uint32 right, uint32 right_step, int adjust) { + do { + left += left_step; + right += right_step; + uint32 left_val = (left & ~0xffff) ? (((int32)left < 0) ? 0 : 0xffff) : left; + uint32 right_val = (right & ~0xffff) ? (((int32)right < 0) ? 0 : 0xffff) : right; + // If both left and right reached the end, fill the remainder with 0xff + bool finished = (left & ~0xffff) && (right & ~0xffff) && (((left_step ^ left) | (right_step ^ right)) >> 31) == 0; + dest[pos >> 1] = ((int32)right < 0 || (int32)left >= 0x10000) ? 0xff : (left_val >> 8 | right_val & ~0xff); + if (finished) { + pos += adjust; + while ((pos -= 2) >= 0) + dest[pos >> 1] = 0xff; + return; + } + } while ((pos -= 2) >= 0); +} + +static void XrayFillDownRamped(uint16 *dest, int pos, uint32 left, uint32 left_step, uint32 right, uint32 right_step, int adjust) { + do { + left += left_step; + right += right_step; + uint32 left_val = (left & ~0xffff) ? (((int32)left < 0) ? 0 : 0xffff) : left; + uint32 right_val = (right & ~0xffff) ? (((int32)right < 0) ? 0 : 0xffff) : right; + bool finished = (left & ~0xffff) && (right & ~0xffff) && (((left_step ^ left) | (right_step ^ right)) >> 31) == 0; + // If both left and right got clamped, fill the remainder with 0xff + dest[pos >> 1] = ((int32)right < 0 || (int32)left >= 0x10000) ? 0xff : (left_val >> 8 | right_val & ~0xff); + if (finished) { + pos += adjust; + while ((pos += 2) < 460) + dest[pos >> 1] = 0xff; + return; + } + } while ((pos += 2) < 460); +} + +typedef void XrayHdma0Func(XrayHdmaCtx *ctx); +static void XrayHdmaFunc_BeamAimedD(XrayHdmaCtx *ctx); +static void XrayHdmaFunc_BeamAimedL(XrayHdmaCtx *ctx); +static void XrayHdmaFunc_BeamAimedR(XrayHdmaCtx *ctx); +static void XrayHdmaFunc_BeamAimedU(XrayHdmaCtx *ctx); +static void XrayHdmaFunc_BeamHoriz(XrayHdmaCtx *ctx); +static void XrayHdmaOnScreen_BeamAimedD(XrayHdmaCtx *ctx); +static void XrayHdmaOnScreen_BeamAimedL(XrayHdmaCtx *ctx); +static void XrayHdmaOnScreen_BeamAimedR(XrayHdmaCtx *ctx); +static void XrayHdmaOnScreen_BeamAimedU(XrayHdmaCtx *ctx); +static void XrayHdmaOnScreen_BeamHoriz(XrayHdmaCtx *ctx); + +static void XrayHdmaFunc_BeamAimedR(XrayHdmaCtx *ctx) { // 0x91BEC2 + int p = 2 * ctx->r24; + XrayFillUpRamped(ctx->dest, p - 2, ctx->r22 - 0x10000, ctx->r30, 65535, 1, 2); + XrayFillDownRamped(ctx->dest, p, ctx->r22 - 0x10000, ctx->r32, 65535, 1, -2); +} + +static void XrayHdmaFunc_BeamAimedL(XrayHdmaCtx *ctx) { // 0x91BF72 + int t = 2 * ctx->r24; + XrayFillUpRamped(ctx->dest, t - 2, 0, -1, ctx->r22 + 0x10000, -ctx->r32, 2); + XrayFillDownRamped(ctx->dest, t, 0, -1, ctx->r22 + 0x10000, -ctx->r30, -2); +} + +static void XrayHdmaFunc_BeamAimedU(XrayHdmaCtx *ctx) { + int p = 2 * ctx->r24; + if (sign16(ctx->r26 - 192)) { + XrayFillUpRamped(ctx->dest, p - 2, ctx->r22 - 0x10000, ctx->r30, ctx->r22 - 0x10000, ctx->r32, 0); + } else if (sign16(ctx->r28 - 192)) { + XrayFillUpRamped(ctx->dest, p - 2, ctx->r22 + 0x10000, -ctx->r30, ctx->r22 - 0x10000, ctx->r32, 0); + } else { + XrayFillUpRamped(ctx->dest, p - 2, ctx->r22 + 0x10000, -ctx->r30, ctx->r22 + 0x10000, -ctx->r32, 2); + } + XrayFillDown(ctx->dest, 0xff, p); +} + +static void XrayHdmaFunc_BeamAimedD(XrayHdmaCtx *ctx) { + int p = 2 * ctx->r24; + if (sign16(ctx->r28 - 128)) { + XrayFillDownRamped(ctx->dest, p, ctx->r22 - 0x10000, ctx->r32, ctx->r22 - 0x10000, ctx->r30, 0); + } else if (sign16(ctx->r26 - 128)) { + XrayFillDownRamped(ctx->dest, p, ctx->r22 + 0x10000, -ctx->r32, ctx->r22 - 0x10000, ctx->r30, 0); + } else { + XrayFillDownRamped(ctx->dest, p, ctx->r22 + 0x10000, -ctx->r32, ctx->r22 + 0x10000, -ctx->r30, 0); + } + XrayFillUp(ctx->dest, 0xff, p - 2); +} + +static void XrayHdmaFunc_BeamHoriz(XrayHdmaCtx *ctx) { // 0x91C505 + uint16 v0 = 2 * (ctx->r24 - 1); + ctx->dest[v0 >> 1] = 0xff00; + XrayFillUp(ctx->dest, 0xff, v0 - 2); + XrayFillDown(ctx->dest, 0xff, v0 + 2); +} + +static void XrayHdmaOnScreen_BeamAimedR(XrayHdmaCtx *ctx) { // 0x91C5FF + int p = 2 * ctx->r24; + ctx->dest[(p - 2) >> 1] = ctx->r22 >> 8 | 0xff00; + XrayFillUpRamped(ctx->dest, p - 4, ctx->r22, ctx->r30, 65535, 1, 2); + XrayFillDownRamped(ctx->dest, p, ctx->r22, ctx->r32, 65535, 1, -2); +} + +static void XrayHdmaOnScreen_BeamAimedL(XrayHdmaCtx *ctx) { // 0x91C660 + int v0 = 2 * ctx->r24; + ctx->dest[(v0 - 2) >> 1] = (ctx->r22 >> 8) << 8; + XrayFillUpRamped(ctx->dest, v0 - 4, 0, -1, ctx->r22, -ctx->r32, 2); + XrayFillDownRamped(ctx->dest, v0, 0, -1, ctx->r22, -ctx->r30, -2); +} + +static void XrayHdmaOnScreen_BeamAimedU(XrayHdmaCtx *ctx) { // 0x91C6C1 + int v0 = 2 * ctx->r24; + ctx->dest[(v0 - 2) >> 1] = (ctx->r22 >> 8) * 0x101; + if (sign16(ctx->r26 - 192)) { + XrayFillUpRamped(ctx->dest, v0 - 4, ctx->r22, ctx->r30, ctx->r22, ctx->r32, 0); + } else if (sign16(ctx->r28 - 192)) { + XrayFillUpRamped(ctx->dest, v0 - 4, ctx->r22, -ctx->r30, ctx->r22, ctx->r32, 0); + } else { + XrayFillUpRamped(ctx->dest, v0 - 4, ctx->r22, -ctx->r30, ctx->r22, -ctx->r32, 2); + } + XrayFillDown(ctx->dest, 0xff, v0); +} + +static void XrayHdmaOnScreen_BeamAimedD(XrayHdmaCtx *ctx) { // 0x91C822 + int v0 = 2 * ctx->r24; + ctx->dest[(v0 - 2) >> 1] = (ctx->r22 >> 8) * 0x101; + if (sign16(ctx->r28 - 128)) { + XrayFillDownRamped(ctx->dest, v0, ctx->r22, ctx->r32, ctx->r22, ctx->r30, 0); + } else if (sign16(ctx->r26 - 128)) { + XrayFillDownRamped(ctx->dest, v0, ctx->r22, -ctx->r32, ctx->r22, ctx->r30, 0); + } else { + XrayFillDownRamped(ctx->dest, v0, ctx->r22, -ctx->r32, ctx->r22, -ctx->r30, 0); + } + XrayFillUp(ctx->dest, 0xff, v0 - 4); +} + +static void XrayHdmaOnScreen_BeamHoriz(XrayHdmaCtx *ctx) { // 0x91C998 + uint16 v0 = 2 * (ctx->r24 - 1); + uint32 t = (ctx->r22 >> 8); + ctx->dest[v0 >> 1] = (ctx->r18_avoid == 64) ? t | 0xFF00 : t << 8; + XrayFillUp(ctx->dest, 0xff, v0 - 2); + XrayFillDown(ctx->dest, 0xff, v0 + 2); +} + +void CalculateXrayHdmaTableInner(uint16 k, uint16 j, uint16 r18, uint16 r20, bool off_screen, uint16 *dest_addr) { int v3; + XrayHdmaCtx ctx[1]; + ctx->dest = (uint16*)dest_addr; + ctx->r18_avoid = r18; + ctx->r22 = k << 8; + ctx->r24 = j; + ctx->r26 = r18 - r20; + ctx->r26 += (ctx->r26 & 0x8000) != 0 ? 0x100 : 0; + ctx->r28 = r20 + r18; + if (!sign16(r20 + r18 - 257)) + ctx->r28 = r20 + r18 - 256; + ctx->r30 = kTanTable[sign16(ctx->r26 - 128) ? ctx->r26 : ctx->r26 - 128]; + ctx->r32 = kTanTable[sign16(ctx->r28 - 128) ? ctx->r28 : ctx->r28 - 128]; - R22_ = (k << 8); - R24_ = j; - R26_ = R18_ - R20_; - R26_ += (R26_ & 0x8000u) != 0 ? 0x100 : 0; - R28_ = R20_ + R18_; - if (!sign16(R20_ + R18_ - 257)) - R28_ = R20_ + R18_ - 256; - if (!R20_ && (R18_ == 64 || R18_ == 192)) { + if (!r20 && (r18 == 64 || r18 == 192)) { v3 = 8; - } else { - if (sign16(R26_ - 128)) { - if (sign16(R26_ - 64)) { - if (!sign16(R28_ - 64)) { - v3 = 0; - goto LABEL_16; - } - goto LABEL_13; - } + } else if (sign16(ctx->r26 - 128)) { + if (!sign16(ctx->r26 - 64)) { + v3 = 4; + } else if (!sign16(ctx->r28 - 64)) { + v3 = 0; } else { - if (!sign16(R26_ - 192)) { -LABEL_13: - v3 = 2; - goto LABEL_16; - } - if (!sign16(R28_ - 192)) { - v3 = 6; - goto LABEL_16; - } + v3 = 2; } - v3 = 4; - } -LABEL_16:; - uint16 v4 = R26_; - if (!sign16(R26_ - 128)) - v4 = R26_ - 128; - R30_ = kTanTable[v4]; - uint16 v5 = R28_; - if (!sign16(R28_ - 128)) - v5 = R28_ - 128; - R32_ = kTanTable[v5]; - kXrayHdmaFuncs[v3 >> 1](); -} - -void XrayHdmaFunc_BeamAimedR(void) { // 0x91BEC2 - int16 v0; - int16 v2; - - v0 = 2 * (R24_ - 1); - R34 = R22_; - R36 = R22_; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - v0 -= 2; - if (v0 < 0) { - R18_ = 0; - goto LABEL_10; - } - } - IndirWriteWord(R0_, v0, HIBYTE(R34) | 0xFF00); - R18_ = v0 + 2; - v2 = v0 - 2; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - IndirWriteWord(R0_, v2, HIBYTE(R34) | 0xFF00); - v2 -= 2; - if (v2 < 0) - goto LABEL_10; - } - do { - IndirWriteWord(R0_, v2, 0xFF); - v2 -= 2; - } while (v2 >= 0); -LABEL_10:; - uint16 v3 = 2 * R24_; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - v3 += 2; - if ((int16)(v3 - 460) >= 0) { - R20_ = v3; - goto LABEL_19; - } - } - IndirWriteWord(R0_, v3, HIBYTE(R36) | 0xFF00); - R20_ = v3 - 2; - uint16 v4; - v4 = v3 - 2 + 4; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - IndirWriteWord(R0_, v4, HIBYTE(R36) | 0xFF00); - v4 += 2; - if ((int16)(v4 - 460) >= 0) - goto LABEL_19; - } - do { - IndirWriteWord(R0_, v4, 0xFF); - v4 += 2; - } while ((int16)(v4 - 460) < 0); -LABEL_19:; - uint16 v5 = R18_; - do { - do { - IndirWriteWord(R0_, v5, 0xFF00); - v5 += 2; - } while ((int16)(v5 - R20_) < 0); - } while (v5 == R20_); -} - -void XrayHdmaFunc_BeamAimedL(void) { // 0x91BF72 - int16 v0; - int16 v2; - - v0 = 2 * (R24_ - 1); - R34 = R22_; - R36 = R22_; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - v0 -= 2; - if (v0 < 0) { - R18_ = 0; - goto LABEL_10; - } - } - IndirWriteWord(R0_, v0, R36 & 0xFF00); - R18_ = v0 + 2; - v2 = v0 - 2; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - IndirWriteWord(R0_, v2, R36 & 0xFF00); - v2 -= 2; - if (v2 < 0) - goto LABEL_10; - } - do { - IndirWriteWord(R0_, v2, 0xFF); - v2 -= 2; - } while (v2 >= 0); -LABEL_10:; - uint16 v3 = 2 * R24_; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - v3 += 2; - if ((int16)(v3 - 460) >= 0) { - R20_ = v3; - goto LABEL_19; - } - } - IndirWriteWord(R0_, v3, R34 & 0xFF00); - R20_ = v3 - 2; - uint16 v4; - v4 = v3 - 2 + 4; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - IndirWriteWord(R0_, v4, R34 & 0xFF00); - v4 += 2; - if ((int16)(v4 - 460) >= 0) - goto LABEL_19; - } - do { - IndirWriteWord(R0_, v4, 0xFF); - v4 += 2; - } while ((int16)(v4 - 460) < 0); -LABEL_19:; - uint16 v5 = R18_; - do { - do { - IndirWriteWord(R0_, v5, 0xFF00); - v5 += 2; - } while ((int16)(v5 - R20_) < 0); - } while (v5 == R20_); -} - -static Func_Y_V *const off_91C063[3] = { // 0x91C022 - XrayHdmaFunc_BeamAimedUUR, - XrayHdmaFunc_BeamAimedUU, - XrayHdmaFunc_BeamAimedUUL, -}; - -void XrayHdmaFunc_BeamAimedU(void) { - uint16 v0; - R34 = R22_; - R36 = R22_; - if (sign16(R26_ - 192)) { - v0 = 0; - } else if (sign16(R28_ - 192)) { - v0 = 2; } else { - v0 = 4; - } - R26_ = 2 * R24_; - off_91C063[v0 >> 1](2 * (R24_ - 1)); - uint16 v1 = R18_; - do { - IndirWriteWord(R0_, v1, 0xFF); - v1 += 2; - } while ((int16)(v1 - 460) < 0); -} - -void XrayHdmaFunc_BeamAimedUUR(uint16 v0) { // 0x91C069 - int16 v2; - int16 v3; - int16 v4; - int16 v6; - - v6 = v0; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - v0 -= 2; - if (v0 < 0) { - R18_ = 0; - goto LABEL_12; - } - } - IndirWriteByte(R0_, v0, HIBYTE(R34)); - v2 = v0 - 2; - if (v2 >= 0) { - R18_ = v2 + 4; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R34)); - v2 -= 2; - if (v2 < 0) - goto LABEL_12; - } - do { - IndirWriteByte(R0_, v2, 0xFF); - v2 -= 2; - } while (v2 >= 0); - } else { - R18_ = 2; - } -LABEL_12: - v3 = v6 + 1; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - v3 -= 2; - if (v3 < 0) { - R20_ = 1; - goto LABEL_23; - } - } - IndirWriteByte(R0_, v3, HIBYTE(R36)); - v4 = v3 - 2; - if (v4 >= 0) { - R20_ = v4 + 4; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - IndirWriteByte(R0_, v4, HIBYTE(R36)); - v4 -= 2; - if (v4 < 0) - goto LABEL_23; - } - do { - IndirWriteByte(R0_, v4, 0xFF); - v4 -= 2; - } while (v4 >= 0); - } else { - R20_ = 3; - } -LABEL_23:; - uint16 v5 = R18_; - do { - IndirWriteByte(R0_, v5, 0); - v5 += 2; - } while ((int16)(v5 - R20_) < 0); - R18_ = R20_ - 1; -} - -void XrayHdmaFunc_BeamAimedUU(uint16 j) { // 0x91C123 - int16 v2; - int16 v3; - int16 v4; - - uint16 v5 = j; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - j -= 2; - if ((j & 0x8000u) != 0) { - R18_ = 0; - goto LABEL_12; - } - } - IndirWriteByte(R0_, j, HIBYTE(R34)); - v2 = j - 2; - if (v2 >= 0) { - R18_ = v2 + 4; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R34)); - v2 -= 2; - if (v2 < 0) - goto LABEL_12; - } - do { - IndirWriteByte(R0_, v2, 0); - v2 -= 2; - } while (v2 >= 0); - } else { - R18_ = 2; - } -LABEL_12: - v3 = v5 + 1; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - v3 -= 2; - if (v3 < 0) { - R20_ = 1; - return; - } - } - IndirWriteByte(R0_, v3, HIBYTE(R36)); - v4 = v3 - 2; - if (v4 >= 0) { - R20_ = v4 + 4; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - IndirWriteByte(R0_, v4, HIBYTE(R36)); - v4 -= 2; - if (v4 < 0) - return; - } - do { - IndirWriteByte(R0_, v4, 0xFF); - v4 -= 2; - } while (v4 >= 0); - } else { - R20_ = 3; - } -} - -void XrayHdmaFunc_BeamAimedUUL(uint16 j) { // 0x91C1CA - int16 v2; - int16 v3; - int16 v4; - - uint16 v6 = j; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - j -= 2; - if ((j & 0x8000u) != 0) { - R18_ = 0; - goto LABEL_12; - } - } - IndirWriteByte(R0_, j, HIBYTE(R34)); - v2 = j - 2; - if (v2 >= 0) { - R18_ = v2 + 4; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R34)); - v2 -= 2; - if (v2 < 0) - goto LABEL_12; - } - do { - IndirWriteByte(R0_, v2, 0); - v2 -= 2; - } while (v2 >= 0); - } else { - R18_ = 2; - } -LABEL_12: - v3 = v6 + 1; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - v3 -= 2; - if (v3 < 0) { - R20_ = 1; - goto LABEL_23; - } - } - IndirWriteByte(R0_, v3, HIBYTE(R34)); - v4 = v3 - 2; - if (v4 >= 0) { - R20_ = v4 + 4; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - IndirWriteByte(R0_, v4, HIBYTE(R36)); - v4 -= 2; - if (v4 < 0) - goto LABEL_23; - } - do { - IndirWriteByte(R0_, v4, 0); - v4 -= 2; - } while (v4 >= 0); - } else { - R20_ = 3; - } -LABEL_23:; - uint16 v5 = R20_; - do { - IndirWriteByte(R0_, v5, 0xFF); - v5 += 2; - } while ((int16)(v5 - R18_) < 0); -} - -static Func_Y_V *const off_91C2B7[3] = { // 0x91C27F - XrayHdmaFunc_BeamAimedDDR, - XrayHdmaFunc_BeamAimedDD, - XrayHdmaFunc_BeamAimedDDL, -}; - -void XrayHdmaFunc_BeamAimedD(void) { - int16 v1; - uint16 v0; - - R34 = R22_; - R36 = R22_; - if (sign16(R28_ - 128)) { - v0 = 0; - } else if (sign16(R26_ - 128)) { - v0 = 2; - } else { - v0 = 4; - } - off_91C2B7[v0 >> 1](R24_ * 2); - v1 = R18_; - do { - IndirWriteWord(R0_, v1, 0xFF); - v1 -= 2; - } while (v1 >= 0); -} - -void XrayHdmaFunc_BeamAimedDDR(uint16 j) { // 0x91C2BD - uint16 v6 = j; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - j += 2; - if ((int16)(j - 460) >= 0) { - R18_ = j; - goto LABEL_12; - } - } - IndirWriteWord(R0_, j, *(uint16 *)((uint8 *)&R36 + 1)); - uint16 v2; - v2 = j + 2; - if ((int16)(v2 - 460) < 0) { - R18_ = v2 - 4; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - IndirWriteWord(R0_, v2, *(uint16 *)((uint8 *)&R36 + 1)); - v2 += 2; - if ((int16)(v2 - 460) >= 0) - goto LABEL_12; - } - do { - IndirWriteWord(R0_, v2, 0xFF); - v2 += 2; - } while ((int16)(v2 - 460) < 0); - } else { - R18_ = 458; - } -LABEL_12:; - uint16 v3 = v6 + 1; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - v3 += 2; - if ((int16)(v3 - 460) >= 0) { - R20_ = v3; - goto LABEL_23; - } - } - IndirWriteByte(R0_, v3, HIBYTE(R34)); - uint16 v4; - v4 = v3 + 2; - if ((int16)(v4 - 460) < 0) { - R20_ = v4 - 4; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - IndirWriteByte(R0_, v4, HIBYTE(R34)); - v4 += 2; - if ((int16)(v4 - 460) >= 0) - goto LABEL_23; - } - do { - IndirWriteByte(R0_, v4, 0xFF); - v4 += 2; - } while ((int16)(v4 - 460) < 0); - } else { - R20_ = 459; - } -LABEL_23:; - uint16 v5 = R18_; - do { - IndirWriteByte(R0_, v5, 0); - v5 -= 2; - } while ((int16)(v5 - R20_) >= 0); - R18_ = R20_ - 1; -} - -void XrayHdmaFunc_BeamAimedDD(uint16 j) { // 0x91C381 - uint16 v5 = j; - if (R32_) { - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - j += 2; - if ((int16)(j - 460) >= 0) { - R18_ = j; - goto LABEL_15; - } - } - IndirWriteWord(R0_, j, *(uint16 *)((uint8 *)&R36 + 1)); - uint16 v2 = j + 2; - if ((int16)(v2 - 460) < 0) { - R18_ = v2 - 4; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - IndirWriteWord(R0_, v2, *(uint16 *)((uint8 *)&R36 + 1)); - v2 += 2; - if ((int16)(v2 - 460) >= 0) - goto LABEL_15; - } - do { - IndirWriteWord(R0_, v2, 0); - v2 += 2; - } while ((int16)(v2 - 460) < 0); + if (!sign16(ctx->r26 - 192)) { + v3 = 2; + } else if (!sign16(ctx->r28 - 192)) { + v3 = 6; } else { - R18_ = 458; + v3 = 4; } + } + + if (off_screen) { + static XrayHdma0Func *const kXrayHdmaFuncs[5] = { // 0x91BE11 + XrayHdmaFunc_BeamAimedR, + XrayHdmaFunc_BeamAimedU, + XrayHdmaFunc_BeamAimedD, + XrayHdmaFunc_BeamAimedL, + XrayHdmaFunc_BeamHoriz, + }; + kXrayHdmaFuncs[v3 >> 1](ctx); } else { - R18_ = j; - do { - IndirWriteWord(R0_, j, 0); - j += 2; - } while ((int16)(j - 460) < 0); + static XrayHdma0Func *const kXrayHdmaOnScreen_Funcs[5] = { + XrayHdmaOnScreen_BeamAimedR, + XrayHdmaOnScreen_BeamAimedU, + XrayHdmaOnScreen_BeamAimedD, + XrayHdmaOnScreen_BeamAimedL, + XrayHdmaOnScreen_BeamHoriz, + }; + kXrayHdmaOnScreen_Funcs[v3 >> 1](ctx); } -LABEL_15:; - uint16 v3 = v5 + 1; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - v3 += 2; - if ((int16)(v3 - 460) >= 0) { - R20_ = v3; - return; - } - } - IndirWriteByte(R0_, v3, HIBYTE(R34)); - uint16 v4 = v3 + 2; - if ((int16)(v4 - 460) < 0) { - R20_ = v4 - 4; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - IndirWriteByte(R0_, v4, HIBYTE(R34)); - v4 += 2; - if ((int16)(v4 - 460) >= 0) - return; - } - do { - IndirWriteByte(R0_, v4, 0xFF); - v4 += 2; - } while ((int16)(v4 - 460) < 0); - } else { - R20_ = 459; - } -} - -void XrayHdmaFunc_BeamAimedDDL(uint16 j) { // 0x91C446 - uint16 v6 = j; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - j += 2; - if ((int16)(j - 460) >= 0) { - R18_ = j; - goto LABEL_12; - } - } - IndirWriteWord(R0_, j, *(uint16 *)((uint8 *)&R36 + 1)); - uint16 v2; - v2 = j + 2; - if ((int16)(v2 - 460) < 0) { - R18_ = v2 - 4; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - IndirWriteWord(R0_, v2, *(uint16 *)((uint8 *)&R36 + 1)); - v2 += 2; - if ((int16)(v2 - 460) >= 0) - goto LABEL_12; - } - do { - IndirWriteWord(R0_, v2, 0); - v2 += 2; - } while ((int16)(v2 - 460) < 0); - } else { - R18_ = 458; - } -LABEL_12:; - uint16 v3 = v6 + 1; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - v3 += 2; - if ((int16)(v3 - 460) >= 0) { - R20_ = v3; - goto LABEL_23; - } - } - IndirWriteByte(R0_, v3, HIBYTE(R34)); - uint16 v4; - v4 = v3 + 2; - if ((int16)(v4 - 460) < 0) { - R20_ = v4 - 4; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - IndirWriteByte(R0_, v4, HIBYTE(R34)); - v4 += 2; - if ((int16)(v4 - 460) >= 0) - goto LABEL_23; - } - do { - IndirWriteByte(R0_, v4, 0); - v4 += 2; - } while ((int16)(v4 - 460) < 0); - } else { - R20_ = 459; - } -LABEL_23:; - uint16 v5 = R20_; - do { - IndirWriteByte(R0_, v5, 0xFF); - v5 -= 2; - } while ((int16)(v5 - R18_) >= 0); -} - -void XrayHdmaFunc_BeamHoriz(void) { // 0x91C505 - int16 v1; - - uint16 v0 = 2 * (R24_ - 1); - IndirWriteWord(R0_, v0, 0xFF00); - v1 = v0 - 2; - do { - if (IndirReadWord(R0_, v1) == 255) - break; - IndirWriteWord(R0_, v1, 0xFF); - v1 -= 2; - } while (v1 >= 0); - uint16 v2 = 2 * R24_; - do { - if (IndirReadWord(R0_, v2) == 255) - break; - IndirWriteWord(R0_, v2, 0xFF); - v2 += 2; - } while ((int16)(v2 - 460) < 0); -} - -void CalculateXrayHdmaTable_OriginOnScreen(uint16 k, uint16 j) { // 0x91C54B - int v3; - - R22_ = k << 8; - R24_ = j; - R26_ = R18_ - R20_; - R26_ += (R26_ & 0x8000u) != 0 ? 0x100 : 0; - R28_ = R20_ + R18_; - if (!sign16(R20_ + R18_ - 257)) - R28_ = R20_ + R18_ - 256; - if (!R20_ && (R18_ == 64 || R18_ == 192)) { - v3 = 8; - } else { - if (sign16(R26_ - 128)) { - if (sign16(R26_ - 64)) { - if (!sign16(R28_ - 64)) { - v3 = 0; - goto LABEL_16; - } - goto LABEL_13; - } - } else { - if (!sign16(R26_ - 192)) { -LABEL_13: - v3 = 2; - goto LABEL_16; - } - if (!sign16(R28_ - 192)) { - v3 = 6; - goto LABEL_16; - } - } - v3 = 4; - } -LABEL_16:; - uint16 v4 = R26_; - if (!sign16(R26_ - 128)) - v4 = R26_ - 128; - R30_ = kTanTable[v4]; - uint16 v5 = R28_; - if (!sign16(R28_ - 128)) - v5 = R28_ - 128; - R32_ = kTanTable[v5]; - grapple_beam_unkD1E = 0; - static Func_V *const kXrayHdmaOnScreen_Funcs[5] = { - XrayHdmaOnScreen_BeamAimedR, - XrayHdmaOnScreen_BeamAimedU, - XrayHdmaOnScreen_BeamAimedD, - XrayHdmaOnScreen_BeamAimedL, - XrayHdmaOnScreen_BeamHoriz, - }; - - kXrayHdmaOnScreen_Funcs[v3 >> 1](); -} - -void XrayHdmaOnScreen_BeamAimedR(void) { // 0x91C5FF - int16 v1; - - uint16 v0 = 2 * (R24_ - 1); - IndirWriteWord(R0_, v0, HIBYTE(R22_) | 0xFF00); - v1 = v0 - 2; - R34 = R22_; - R36 = R22_; - while (1) { - bool v2 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v2) - break; - IndirWriteWord(R0_, v1, HIBYTE(R34) | 0xFF00); - v1 -= 2; - if (v1 < 0) - goto LABEL_6; - } - do { - IndirWriteWord(R0_, v1, 0xFF); - v1 -= 2; - } while (v1 >= 0); -LABEL_6:; - uint16 v3 = 2 * R24_; - while (1) { - bool v2 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v2) - break; - IndirWriteWord(R0_, v3, HIBYTE(R36) | 0xFF00); - v3 += 2; - if ((int16)(v3 - 460) >= 0) - return; - } - do { - IndirWriteWord(R0_, v3, 0xFF); - v3 += 2; - } while ((int16)(v3 - 460) < 0); -} - -void XrayHdmaOnScreen_BeamAimedL(void) { // 0x91C660 - int16 v1; - - uint16 v0 = 2 * (R24_ - 1); - IndirWriteWord(R0_, v0, R22_ & 0xFF00); - v1 = v0 - 2; - R34 = R22_; - R36 = R22_; - while (1) { - bool v2 = R36 >= R32_; - R36 -= R32_; - if (!v2) - break; - IndirWriteWord(R0_, v1, R36 & 0xFF00); - v1 -= 2; - if (v1 < 0) - goto LABEL_6; - } - do { - IndirWriteWord(R0_, v1, 0xFF); - v1 -= 2; - } while (v1 >= 0); -LABEL_6:; - uint16 v3 = 2 * R24_; - while (1) { - bool v2 = R34 >= R30_; - R34 -= R30_; - if (!v2) - break; - IndirWriteWord(R0_, v3, R34 & 0xFF00); - v3 += 2; - if ((int16)(v3 - 460) >= 0) - return; - } - do { - IndirWriteWord(R0_, v3, 0xFF); - v3 += 2; - } while ((int16)(v3 - 460) < 0); -} - -void XrayHdmaOnScreen_BeamAimedU(void) { // 0x91C6C1 - uint16 v0 = 2 * (R24_ - 1); - IndirWriteByte(R0_, v0++, HIBYTE(R22_)); - IndirWriteByte(R0_, v0, HIBYTE(R22_)); - uint16 v1 = v0 - 3; - uint16 v2; - R34 = R22_; - R36 = R22_; - if (sign16(R26_ - 192)) { - v2 = 0; - } else if (sign16(R28_ - 192)) { - v2 = 2; - } else { - v2 = 4; - } - static Func_Y_V *const off_91C716[3] = { - XrayHdmaOnScreen_BeamAimedUUR, - XrayHdmaOnScreen_BeamAimedUU, - XrayHdmaOnScreen_BeamAimedUUL, - }; - off_91C716[v2 >> 1](v1); - uint16 v3 = 2 * R24_; - do { - if (IndirReadWord(R0_, v3) == 255) - break; - IndirWriteWord(R0_, v3, 0xFF); - v3 += 2; - } while ((int16)(v3 - 460) < 0); -} - -void XrayHdmaOnScreen_BeamAimedUUR(uint16 v0) { // 0x91C71C - int16 v2; - int16 v4; - - v4 = v0; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - IndirWriteByte(R0_, v0, HIBYTE(R34)); - v0 -= 2; - if ((v0 & 0x8000u) != 0) - goto LABEL_7; - } - grapple_beam_unkD1E = v0; - do { - IndirWriteByte(R0_, v0, 0xFF); - v0 -= 2; - } while ((v0 & 0x8000u) == 0); -LABEL_7: - v2 = v4 + 1; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R36)); - v2 -= 2; - if (v2 < 0) - return; - } - do { - IndirWriteByte(R0_, v2, 0xFF); - v2 -= 2; - } while (v2 >= 0); - if (grapple_beam_unkD1E) { - for (int i = grapple_beam_unkD1E - 2; i >= 0; i -= 2) - IndirWriteWord(R0_, i, 0xFF); - } -} - -void XrayHdmaOnScreen_BeamAimedUU(uint16 v0) { // 0x91C77F - int16 v2; - int16 v3; - - v3 = v0; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - IndirWriteByte(R0_, v0, HIBYTE(R34)); - v0 -= 2; - if (v0 < 0) - goto LABEL_6; - } - do { - IndirWriteByte(R0_, v0, 0); - v0 -= 2; - } while (v0 >= 0); -LABEL_6: - v2 = v3 + 1; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R36)); - v2 -= 2; - if (v2 < 0) - return; - } - do { - IndirWriteByte(R0_, v2, 0xFF); - v2 -= 2; - } while (v2 >= 0); -} - -void XrayHdmaOnScreen_BeamAimedUUL(uint16 j) { // 0x91C7CB - int16 v2; - int16 v3; - int16 v5; - - uint16 v4 = j; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - IndirWriteByte(R0_, j, HIBYTE(R34)); - j -= 2; - if ((j & 0x8000u) != 0) - goto LABEL_6; - } - do { - IndirWriteByte(R0_, j, 0); - j -= 2; - } while ((j & 0x8000u) == 0); -LABEL_6: - v2 = v4 + 1; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R36)); - v2 -= 2; - if (v2 < 0) - return; - } - v5 = v2; - do { - IndirWriteByte(R0_, v2, 0); - v2 -= 2; - } while (v2 >= 0); - v3 = v5 - 1; - do { - IndirWriteByte(R0_, v3, 0xFF); - v3 -= 2; - } while (v3 >= 0); -} - -void XrayHdmaOnScreen_BeamAimedD(void) { // 0x91C822 - int16 v3; - - uint16 v2; - uint16 v0 = 2 * (R24_ - 1); - IndirWriteByte(R0_, v0++, HIBYTE(R22_)); - IndirWriteByte(R0_, v0, HIBYTE(R22_)); - uint16 v1 = v0 + 1; - R34 = R22_; - R36 = R22_; - if (sign16(R28_ - 128)) { - v2 = 0; - } else if (sign16(R26_ - 128)) { - v2 = 2; - } else { - v2 = 4; - } - static Func_Y_V *const off_91C874[3] = { - XrayHdmaOnScreen_BeamAimedDDR, - XrayHdmaOnScreen_BeamAimedDD, - XrayHdmaOnScreen_BeamAimedDDL, - }; - off_91C874[v2 >> 1](v1); - v3 = 2 * (R24_ - 2); - do { - if (IndirReadWord(R0_, v3) == 255) - break; - IndirWriteWord(R0_, v3, 0xFF); - v3 -= 2; - } while (v3 >= 0); -} - -void XrayHdmaOnScreen_BeamAimedDDR(uint16 j) { // 0x91C87A - uint16 v4 = j; - while (1) { - bool v1 = __CFADD__uint16(R32_, R36); - R36 += R32_; - if (v1) - break; - IndirWriteWord(R0_, j, *(uint16 *)((uint8 *)&R36 + 1)); - j += 2; - if ((int16)(j - 460) >= 0) - goto LABEL_7; - } - grapple_beam_unkD1E = j; - do { - IndirWriteWord(R0_, j, 0xFF); - j += 2; - } while ((int16)(j - 460) < 0); -LABEL_7:; - uint16 v2 = v4 + 1; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R34)); - v2 += 2; - if ((int16)(v2 - 460) >= 0) - return; - } - do { - IndirWriteByte(R0_, v2, 0xFF); - v2 += 2; - } while ((int16)(v2 - 460) < 0); - if (grapple_beam_unkD1E) { - uint16 v3 = grapple_beam_unkD1E + 2; - if ((int16)(grapple_beam_unkD1E - 458) < 0) { - do { - IndirWriteWord(R0_, v3, 0xFF); - v3 += 2; - } while ((int16)(v3 - 460) < 0); - } - } -} - -void XrayHdmaOnScreen_BeamAimedDD(uint16 j) { // 0x91C8E8 - uint16 v3 = j; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - IndirWriteWord(R0_, j, *(uint16 *)((uint8 *)&R36 + 1)); - j += 2; - if ((int16)(j - 460) >= 0) - goto LABEL_6; - } - do { - IndirWriteWord(R0_, j, 0); - j += 2; - } while ((int16)(j - 460) < 0); -LABEL_6:; - uint16 v2 = v3 + 1; - while (1) { - bool v1 = __CFADD__uint16(R30_, R34); - R34 += R30_; - if (v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R34)); - v2 += 2; - if ((int16)(v2 - 460) >= 0) - return; - } - do { - IndirWriteByte(R0_, v2, 0xFF); - v2 += 2; - } while ((int16)(v2 - 460) < 0); -} - -void XrayHdmaOnScreen_BeamAimedDDL(uint16 j) { // 0x91C939 - uint16 v4 = j; - while (1) { - bool v1 = R36 >= R32_; - R36 -= R32_; - if (!v1) - break; - IndirWriteWord(R0_, j, *(uint16 *)((uint8 *)&R36 + 1)); - j += 2; - if ((int16)(j - 460) >= 0) - goto LABEL_6; - } - do { - IndirWriteWord(R0_, j, 0); - j += 2; - } while ((int16)(j - 460) < 0); -LABEL_6:; - uint16 v2 = v4 + 1; - while (1) { - bool v1 = R34 >= R30_; - R34 -= R30_; - if (!v1) - break; - IndirWriteByte(R0_, v2, HIBYTE(R34)); - v2 += 2; - if ((int16)(v2 - 460) >= 0) - return; - } - uint16 v5 = v2; - do { - IndirWriteByte(R0_, v2, 0); - v2 += 2; - } while ((int16)(v2 - 460) < 0); - uint16 v3 = v5 - 1; - do { - IndirWriteByte(R0_, v3, 0xFF); - v3 += 2; - } while ((int16)(v3 - 460) < 0); -} - -void XrayHdmaOnScreen_BeamHoriz(void) { // 0x91C998 - int16 v1; - - uint16 v0 = 2 * (R24_ - 1); - if (R18_ == 64) - IndirWriteWord(R0_, v0, HIBYTE(R22_) | 0xFF00); - else - IndirWriteWord(R0_, v0, R22_ & 0xFF00); - v1 = v0 - 2; - do { - IndirWriteWord(R0_, v1, 0xFF); - v1 -= 2; - } while (v1 >= 0); - uint16 v2 = 2 * R24_; - do { - IndirWriteWord(R0_, v2, 0xFF); - v2 += 2; - } while ((int16)(v2 - 460) < 0); } void XrayRunHandler(void) { // 0x91CAD6 @@ -1882,12 +880,9 @@ void Xray_SetupStage1_FreezeTimeBackup(uint16 k) { // 0x91CAF9 } void Xray_SetupStage2_ReadBg1_2ndScreen(void) { // 0x91CB1C - unsigned int v1; - uint16 v0 = vram_read_queue_tail; - v1 = vram_read_queue_tail; - *(uint16 *)((uint8 *)&vram_read_queue[0].vram_target + vram_read_queue_tail) = ((reg_BG1SC & 0xFC) << 8) + 1024; - *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v1) = 129; + *(uint16 *)((uint8 *)&vram_read_queue[0].vram_target + v0) = ((reg_BG1SC & 0xFC) << 8) + 1024; + *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v0) = 129; *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v0 + 1) = 57; *(VoidP *)((uint8 *)&vram_read_queue[0].src.addr + v0) = ADDR16_OF_RAM(ram4000) + 0x2800; *(uint16 *)(&vram_read_queue[0].src.bank + v0) = 126; @@ -1896,12 +891,10 @@ void Xray_SetupStage2_ReadBg1_2ndScreen(void) { // 0x91CB1C } void Xray_SetupStage3_ReadBg1_1stScreen(void) { // 0x91CB57 - unsigned int v1; uint16 v0 = vram_read_queue_tail; - v1 = vram_read_queue_tail; - *(uint16 *)((uint8 *)&vram_read_queue[0].vram_target + vram_read_queue_tail) = (reg_BG1SC & 0xFC) << 8; - *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v1) = 129; + *(uint16 *)((uint8 *)&vram_read_queue[0].vram_target + v0) = (reg_BG1SC & 0xFC) << 8; + *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v0) = 129; *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v0 + 1) = 57; *(VoidP *)((uint8 *)&vram_read_queue[0].src.addr + v0) = ADDR16_OF_RAM(ram4000) + 0x2000; *(uint16 *)(&vram_read_queue[0].src.bank + v0) = 126; @@ -1910,70 +903,61 @@ void Xray_SetupStage3_ReadBg1_1stScreen(void) { // 0x91CB57 } void Xray_SetupStage4(void) { // 0x91CB8E - unsigned int v3; - unsigned int v8; - - R24_ = 4 * (((uint8)layer1_y_pos + (uint8)bg1_y_offset) & 0xF0); - R24_ += (uint8)((layer1_x_pos + bg1_x_offset) & 0xF0) >> 3; - R24_ += 4 * ((layer1_x_pos + bg1_x_offset) & 0x100); - R22_ = 0; - R20_ = 16; + uint16 r24 = 4 * ((layer1_y_pos + bg1_y_offset) & 0xF0); + r24 += ((layer1_x_pos + bg1_x_offset) & 0xF0) >> 3; + r24 += 4 * ((layer1_x_pos + bg1_x_offset) & 0x100); + uint16 r22 = 0; + int m = 16; do { - R18_ = 16; - R26_ = R24_ & 0x7E0; - R28_ = R24_ & 0x1F; - R30_ = 0; + int n = 16; + uint16 r26 = r24 & 0x7E0; + uint16 r28 = r24 & 0x1F; + uint16 r30 = 0; do { - if (!sign16(R30_ + R28_ - 32)) { - R26_ = (R26_ + 1024) & 0x7E0; - R28_ = 0; - R30_ = 0; + if (!sign16(r30 + r28 - 32)) { + r26 = (r26 + 1024) & 0x7E0; + r28 = 0; + r30 = 0; } - uint16 v0 = R30_ + R28_ + R26_; + uint16 v0 = r30 + r28 + r26; uint16 v11 = ram4000.xray_tilemaps[v0 + 4096]; uint16 v10 = ram4000.xray_tilemaps[v0 + 4097]; uint16 v9 = ram4000.xray_tilemaps[v0 + 4128]; uint16 v1 = ram4000.xray_tilemaps[v0 + 4129]; - uint16 v2 = R22_; - v3 = R22_; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + R22_) = v1; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[32] + v3) = v9; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[1] + v2) = v10; - *(uint16 *)((uint8 *)ram4000.xray_tilemaps + v2) = v11; - R22_ += 4; - R30_ += 2; - --R18_; - } while (R18_); - Xray_SetupStage4_Func1(); - R32_ = R24_ & 0x400; - R24_ = (R24_ & 0x400) + ((R24_ + 64) & 0x3FF); - R22_ += 64; - --R20_; - } while (R20_); + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + r22) = v1; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[32] + r22) = v9; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[1] + r22) = v10; + *(uint16 *)((uint8 *)ram4000.xray_tilemaps + r22) = v11; + r22 += 4; + r30 += 2; + } while (--n); + Xray_SetupStage4_Func1(r22, r26, r28, r30); + r24 = (r24 & 0x400) + ((r24 + 64) & 0x3FF); + r22 += 64; + } while (--m); assert((uint16)(layer1_y_pos >> 12) == 0); - R34 = Mult8x8(layer1_y_pos >> 4, room_width_in_blocks) + (layer1_x_pos >> 4); - R22_ = 0; - R20_ = 16; + uint16 r34 = Mult8x8(layer1_y_pos >> 4, room_width_in_blocks) + (layer1_x_pos >> 4); + r22 = 0; + m = 16; do { - Xray_SetupStage4_Func2(); - R18_ = 16; - R36 = R34; + Xray_SetupStage4_Func2(r22, r34); + int n = 16; + uint16 r36 = r34; do { - Xray_SetupStage4_Func3(); - --R18_; - } while (R18_); - uint16 v12 = R22_; - R22_ += 1984; - Xray_SetupStage4_Func3(); - R22_ = v12 + 64; - R34 += room_width_in_blocks; - --R20_; - } while (R20_); + Xray_SetupStage4_Func3(n, r22, r36); + r22 += 4; + r36 += 1; + } while (--n); + uint16 v12 = r22; + r22 += 1984; + Xray_SetupStage4_Func3(0, r22, r36); + r22 = v12 + 64; + r34 += room_width_in_blocks; + } while (--m); LoadXrayBlocks(); uint16 v7 = vram_read_queue_tail; - v8 = vram_read_queue_tail; - *(uint16 *)((uint8 *)&vram_read_queue[0].vram_target + vram_read_queue_tail) = (reg_BG2SC & 0xFC) << 8; - *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v8) = 129; + *(uint16 *)((uint8 *)&vram_read_queue[0].vram_target + v7) = (reg_BG2SC & 0xFC) << 8; + *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v7) = 129; *(uint16 *)((uint8 *)&vram_read_queue[0].dma_parameters + v7 + 1) = 57; *(VoidP *)((uint8 *)&vram_read_queue[0].src.addr + v7) = 0x5000; *(uint16 *)(&vram_read_queue[0].src.bank + v7) = 126; @@ -1981,356 +965,235 @@ void Xray_SetupStage4(void) { // 0x91CB8E vram_read_queue_tail = v7 + 9; } -void Xray_SetupStage4_Func1(void) { // 0x91CCF1 +void Xray_SetupStage4_Func1(uint16 dst_r22, uint16 r26, uint16 r28, uint16 r30) { // 0x91CCF1 int16 v0; - R32_ = R26_; - v0 = R30_ + R28_; - if (!sign16(R30_ + R28_ - 32)) { - R32_ = (R32_ + 1024) & 0x7E0; + uint16 R32 = r26; + v0 = r30 + r28; + if (!sign16(r30 + r28 - 32)) { + R32 = (R32 + 1024) & 0x7E0; v0 = 0; } - uint16 v1 = R32_ + v0; + uint16 v1 = R32 + v0; uint16 v6 = ram4000.xray_tilemaps[v1 + 4096]; uint16 v5 = ram4000.xray_tilemaps[v1 + 4097]; uint16 v4 = ram4000.xray_tilemaps[v1 + 4128]; uint16 v3 = ram4000.xray_tilemaps[v1 + 4129]; - uint16 v2 = R22_ + 1984; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + (uint16)(R22_ + 1984)) = v3; + uint16 v2 = dst_r22 + 1984; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + v2) = v3; *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[32] + v2) = v4; *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[1] + v2) = v5; *(uint16 *)((uint8 *)ram4000.xray_tilemaps + v2) = v6; } -void Xray_SetupStage4_Func2(void) { // 0x91CD42 - // bug: passing 0xffff to this function is invalid and will read invalid memory. - if (R34 == 0) - return; - PairU16 pay = Xray_HandleXrayedBlock(R34 - 1); - uint16 *dst = (uint16 *)((uint8 *)ram4000.xray_tilemaps + R22_); +static const uint8 *Xray_GetXrayedBlock(uint16 k) { // 0x91CDD6 + uint16 value; - if (pay.k != FUNC16(Xray_Func9)) { - if (pay.k != FUNC16(Xray_Func11)) + uint16 bts = BTS[k]; + uint16 r40 = level_data[k] & 0xF000; + for (int i = 0; ; ++i) { + value = stru_91D2D6[i].value; + if (value == 0xFFFF) + break; + if (value == r40) { + for (const uint8 *p = RomPtr_91(stru_91D2D6[i].addr); ; p += 4) { + value = GET_WORD(p); + if (value == 0xFFFF) + break; + if (value == 0xFF00 || value == bts) + return RomPtr_91(GET_WORD(p + 2)); + } + return NULL; + } + } + return NULL; +} + + +void Xray_SetupStage4_Func2(uint16 dst_r22, uint16 r34) { // 0x91CD42 + // bug: passing 0xffff to this function is invalid and will read invalid memory. + if (r34 == 0) + return; + const uint8 *jp = Xray_GetXrayedBlock(r34 - 1); + uint16 *dst = (uint16 *)((uint8 *)ram4000.xray_tilemaps + dst_r22); + + if (jp == NULL) + return; + + if (GET_WORD(jp) != FUNC16(Xray_Func9)) { + if (GET_WORD(jp) != FUNC16(Xray_Func11)) return; - TileTable *src = tile_table.tables + *(uint16 *)&RomPtr_91(R3_.addr)[pay.j + 8]; + TileTable *src = tile_table.tables + GET_WORD(jp + 8); dst[64] = src->top_left; dst[65] = src->top_right; dst[96] = src->bottom_left; dst[97] = src->bottom_right; } - TileTable *src = tile_table.tables + *(uint16 *)&RomPtr_91(R3_.addr)[pay.j + 4]; + TileTable *src = tile_table.tables + GET_WORD(jp + 4); dst[0] = src->top_left; dst[1] = src->top_right; dst[32] = src->bottom_left; dst[33] = src->bottom_right; } -void CallXrayFunc(uint32 ea, uint16 j) { - switch (ea) { - case fnXray_Func6: Xray_Func6(); return; - case fnXray_Func6B: Xray_Func6B(); return; - case fnXray_Func7: Xray_Func7(j); return; - case fnXray_Func9: Xray_Func9(j); return; - case fnXray_Func10: Xray_Func10(j); return; - case fnXray_Func11: Xray_Func11(j); return; - default: Unreachable(); - } -} -void Xray_SetupStage4_Func3(void) { // 0x91CDBE - PairU16 pay = Xray_HandleXrayedBlock(R36); - if (pay.k == 0xFFFF) - Xray_Func21(0); - else - CallXrayFunc(pay.k | 0x910000, pay.j); -} - -uint16 Xray_Func21(uint16 j) { // 0x91CDCB - R22_ += 4; - ++R36; - return j; -} - - -PairU16 Xray_HandleXrayedBlock(uint16 k) { // 0x91CDD6 - uint16 value; - uint16 j; - - R38 = BTS[k]; - R40 = level_data[k] & 0xF000; - for (int i = 0; ; ++i) { - value = stru_91D2D6[i].value; - if (value == 0xFFFF) - break; - if (value == R40) { - R0_.addr = stru_91D2D6[i].addr; - for (j = 0; ; j += 4) { - value = *(uint16 *)&RomPtr_91(R0_.addr)[j]; - if (value == 0xFFFF) - break; - if (value == 0xFF00 || value == R38) { - R3_.addr = *(uint16 *)&RomPtr_91(R0_.addr)[j + 2]; - value = *(uint16 *)RomPtr_91(R3_.addr); - R0_.addr = value; - return MakePairU16(value, 0); - } - } - return MakePairU16(value, j); - } - } - return MakePairU16(value, 0); -} - -void Xray_SomeDivide(void) { // 0x91CE2C - R44 = R36 / room_width_in_blocks; - R42 = R36 % room_width_in_blocks; -} - -uint16 Xray_Func5(void) { // 0x91CE51 - uint16 v1 = R42; - uint16 RegWord = room_width_in_blocks * (uint8)R44; - R46 = BTS[(uint16)(RegWord + v1)]; - R48 = level_data[RegWord + v1] & 0xF000; - return R48; -} - -void Xray_Func6(void) { // 0x91CE79 - Xray_SomeDivide(); - R48 = R40; - uint16 v0 = R38; - if (R38) { - if ((R38 & 0x80) != 0) - v0 = R38 | 0xFF00; - R46 = v0; - Xray_Func6D(); - } else { - Xray_Func20(); - } -} - -void Xray_Func6D(void) { // 0x91CE8E - uint16 v1; - do { - do { - if ((int16)(R46 + R44) < 0) { - Xray_Func13(0xFFu); - Xray_Func21(0); +static void Xray_CombinedMove(uint16 dst_r22, uint16 r36, bool which_dir) { + uint16 y = r36 / room_width_in_blocks; + uint16 x = r36 % room_width_in_blocks; + uint16 r48 = level_data[r36] & 0xF000; + int step = (int8)BTS[r36]; + if (step) { + uint16 *variable = which_dir ? &y : &x; + for (;;) { + if ((int16)(*variable + step) < 0) { + Xray_Func13(dst_r22, 0xFF); return; } - R44 += R46; - v1 = Xray_Func5(); - } while (v1 == 0xD000); - if (v1 != 20480) { - Xray_Func20(); - return; - } - } while ((R46 & 0x80) == 0); - R46 = (uint8)R46 ^ 0xFF00; - Xray_Func6C(); -} - -void Xray_Func6B(void) { // 0x91CEBB - Xray_SomeDivide(); - R48 = R40; - uint16 v0 = R38; - if (R38) { - if ((R38 & 0x80) != 0) - v0 = R38 | 0xFF00; - R46 = v0; - Xray_Func6C(); - } else { - Xray_Func20(); - } -} - -void Xray_Func6C(void) { // 0x91CED0 - while (1) { - if ((int16)(R46 + R42) < 0) { - Xray_Func13(0xFFu); - Xray_Func21(0); // ?? - return; - } - R42 += R46; - uint16 v1 = Xray_Func5(); - if (v1 == 0xD000) { - Xray_Func6D(); - return; - } - if (v1 != 20480) - break; - if ((R46 & 0x80) != 0) - R46 = (uint8)R46 ^ 0xFF00; - } - Xray_Func20(); -} - - -void Xray_Func20(void) { // 0x91CEFD - int i; - int16 v1; - - if (stru_91D2D6[1].value == R48) { - R0_.addr = stru_91D2D6[1].addr; - for (i = 0; ; i += 4) { - v1 = *(uint16 *)&RomPtr_91(R0_.addr)[i]; - if (v1 == -1) + *variable += step; + int pos = y * room_width_in_blocks + x; + step = (int8)BTS[pos]; + r48 = level_data[pos] & 0xF000; + if (r48 == 0xd000) { + variable = &y; + continue; + } + if (r48 != 0x5000) break; - if (v1 == -256 || v1 == R46) { - R3_.addr = *(uint16 *)&RomPtr_91(R0_.addr)[(uint16)(i + 2)] + 2; - Xray_Func12(0); - Xray_Func21(0); + if (step < 0) + variable = &x; // wtf? + } + } + + if (stru_91D2D6[1].value == r48) { + uint16 *t = (uint16 *)RomPtr_91(stru_91D2D6[1].addr); + for (; t[0] != 0xffff; t += 2) { + if (t[0] == 0xff00 || t[0] == (step & 0xff)) { + Xray_Func12(dst_r22, RomPtr_91(t[1] + 2)); return; } } } - Xray_Func21(i); } -uint16 Xray_Func7(uint16 j) { // 0x91CF36 - uint16 v1 = j + 2; - Xray_Func12(v1); - return Xray_Func21(v1); +static void Xray_Func7(uint16 dst_r22, const uint8 *jp) { // 0x91CF36 + Xray_Func12(dst_r22, jp + 2); } -uint16 Xray_Func8(uint16 j) { // 0x91CF3E - uint16 v1 = j + 2; +static void Xray_Func8(uint16 dst_r22, const uint8 *jp) { // 0x91CF3E if (area_index == 1) - Xray_Func12(v1); - return Xray_Func21(v1); + Xray_Func12(dst_r22, jp + 2); } -uint16 Xray_Func9(uint16 j) { // 0x91CF4E - uint16 v1 = j + 2; - Xray_Func12(v1); - if (R18_ != 1) { - v1 += 2; - Xray_Func14(v1); - } - return Xray_Func21(v1); +static void Xray_Func9(uint16 r18, uint16 dst_r22, const uint8 *jp) { // 0x91CF4E + Xray_Func12(dst_r22, jp + 2); + if (r18 != 1) + Xray_Func14(dst_r22, jp + 4); } -uint16 Xray_Func10(uint16 j) { // 0x91CF62 - uint16 v1 = j + 2; - Xray_Func12(v1); - v1 += 2; - Xray_Func15(v1); - return Xray_Func21(v1); +static void Xray_Func10(uint16 dst_r22, const uint8 *jp) { // 0x91CF62 + Xray_Func12(dst_r22, jp + 2); + Xray_Func15(dst_r22, jp + 2); } -uint16 Xray_Func11(uint16 j) { // 0x91CF6F - unsigned int v8; - - uint16 v1 = j + 2; - Xray_Func12(v1); - uint16 v2 = v1 + 2; - if (R18_ != 1) - Xray_Func14(v2); - uint16 v3 = v2 + 2; - Xray_Func15(v3); - uint16 v4 = v3 + 2; - if (R18_ != 1) { - uint16 v5 = *(uint16 *)&RomPtr_91(R3_.addr)[v4]; +static void Xray_Func11(uint16 r18, uint16 dst_r22, const uint8 *jp) { // 0x91CF6F + Xray_Func12(dst_r22, jp + 2); + if (r18 != 1) + Xray_Func14(dst_r22, jp + 4); + Xray_Func15(dst_r22, jp + 6); + if (r18 != 1) { + uint16 v5 = GET_WORD(jp + 8); uint16 top_left = tile_table.tables[v5].top_left; uint16 top_right = tile_table.tables[v5].top_right; uint16 bottom_left = tile_table.tables[v5].bottom_left; uint16 bottom_right = tile_table.tables[v5].bottom_right; - uint16 v7 = R22_; - v8 = R22_; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[99] + R22_) = bottom_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[98] + v8) = bottom_left; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[67] + v7) = top_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[66] + v7) = top_left; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[99] + dst_r22) = bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[98] + dst_r22) = bottom_left; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[67] + dst_r22) = top_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[66] + dst_r22) = top_left; } - return Xray_Func21(v4); } -void Xray_Func12(uint16 j) { // 0x91CFBF - const uint8 *v1 = RomPtr_91(R3_.addr); - Xray_Func13(*(uint16 *)&v1[j]); +static void CallXrayFunc(uint32 ea, const uint8 *jp, uint16 r18, uint16 r22, uint16 r36) { + switch (ea) { + case fnXray_Func6: Xray_CombinedMove(r22, r36, true); return; + case fnXray_Func6B: Xray_CombinedMove(r22, r36, false); return; + case fnXray_Func7: Xray_Func7(r22, jp); return; + case fnXray_Func8: Xray_Func8(r22, jp); return; + case fnXray_Func9: Xray_Func9(r18, r22, jp); return; + case fnXray_Func10: Xray_Func10(r22, jp); return; + case fnXray_Func11: Xray_Func11(r18, r22, jp); return; + default: Unreachable(); + } } -void Xray_Func13(uint16 a) { // 0x91CFC1 - unsigned int v3; - - uint16 v1 = a; - uint16 top_left = tile_table.tables[v1].top_left; - uint16 top_right = tile_table.tables[v1].top_right; - uint16 bottom_left = tile_table.tables[v1].bottom_left; - uint16 v2 = R22_; - v3 = R22_; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + R22_) = tile_table.tables[v1].bottom_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[32] + v3) = bottom_left; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[1] + v2) = top_right; - *(uint16 *)((uint8 *)ram4000.xray_tilemaps + v2) = top_left; +void Xray_SetupStage4_Func3(uint16 r18, uint16 r22, uint16 r36) { // 0x91CDBE + const uint8 *jp = Xray_GetXrayedBlock(r36); + if (jp != NULL) { + CallXrayFunc(GET_WORD(jp) | 0x910000, jp, r18, r22, r36); + } } -void Xray_Func14(uint16 j) { // 0x91CFEE - unsigned int v4; - - uint16 v1 = *(uint16 *)&RomPtr_91(R3_.addr)[j]; - uint16 top_left = tile_table.tables[v1].top_left; - uint16 top_right = tile_table.tables[v1].top_right; - uint16 bottom_left = tile_table.tables[v1].bottom_left; - uint16 bottom_right = tile_table.tables[v1].bottom_right; - uint16 v3 = R22_; - v4 = R22_; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[35] + R22_) = bottom_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[34] + v4) = bottom_left; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[3] + v3) = top_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[2] + v3) = top_left; +static void Xray_Func12(uint16 dst_r22, const uint8 *jp) { // 0x91CFBF + Xray_Func13(dst_r22, GET_WORD(jp)); } -void Xray_Func15(uint16 j) { // 0x91D01D - unsigned int v4; +static void Xray_Func13(uint16 dst_r22, uint16 a) { // 0x91CFC1 + uint16 top_left = tile_table.tables[a].top_left; + uint16 top_right = tile_table.tables[a].top_right; + uint16 bottom_left = tile_table.tables[a].bottom_left; + uint16 bottom_right = tile_table.tables[a].bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + dst_r22) = bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[32] + dst_r22) = bottom_left; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[1] + dst_r22) = top_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[0] + dst_r22) = top_left; +} - uint16 v1 = *(uint16 *)&RomPtr_91(R3_.addr)[j]; - uint16 top_left = tile_table.tables[v1].top_left; - uint16 top_right = tile_table.tables[v1].top_right; - uint16 bottom_left = tile_table.tables[v1].bottom_left; - uint16 bottom_right = tile_table.tables[v1].bottom_right; - uint16 v3 = R22_; - v4 = R22_; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[97] + R22_) = bottom_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[96] + v4) = bottom_left; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[65] + v3) = top_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[64] + v3) = top_left; +static void Xray_Func14(uint16 dst_r22, const uint8 *jp) { // 0x91CFEE + uint16 a = GET_WORD(jp); + uint16 top_left = tile_table.tables[a].top_left; + uint16 top_right = tile_table.tables[a].top_right; + uint16 bottom_left = tile_table.tables[a].bottom_left; + uint16 bottom_right = tile_table.tables[a].bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[35] + dst_r22) = bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[34] + dst_r22) = bottom_left; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[3] + dst_r22) = top_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[2] + dst_r22) = top_left; +} + +static void Xray_Func15(uint16 dst_r22, const uint8 *jp) { // 0x91D01D + uint16 a = GET_WORD(jp); + uint16 top_left = tile_table.tables[a].top_left; + uint16 top_right = tile_table.tables[a].top_right; + uint16 bottom_left = tile_table.tables[a].bottom_left; + uint16 bottom_right = tile_table.tables[a].bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[97] + dst_r22) = bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[96] + dst_r22) = bottom_left; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[65] + dst_r22) = top_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[64] + dst_r22) = top_left; +} + +static void Xray_Func16(uint16 dst_r22, uint16 a) { // 0x91D0A6 + uint16 top_left = tile_table.tables[a].top_left; + uint16 top_right = tile_table.tables[a].top_right; + uint16 bottom_left = tile_table.tables[a].bottom_left; + uint16 bottom_right = tile_table.tables[a].bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[1] + dst_r22) = bottom_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[0] + dst_r22) = bottom_left; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + dst_r22) = top_right; + *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[32] + dst_r22) = top_left; } void LoadBlockToXrayTilemap(uint16 a, uint16 k, uint16 j) { // 0x91D04C - R40 = a; - R24_ = layer1_x_pos >> 4; - if ((int16)(k - (layer1_x_pos >> 4)) >= 0) { - R24_ = k - (layer1_x_pos >> 4); - if ((((__PAIR32__(k - (layer1_x_pos >> 4), k) - ((layer1_x_pos >> 4) | 0x100000)) >> 16) & 0x8000u) != 0) { - R26_ = layer1_y_pos >> 4; - if ((int16)(j - (layer1_y_pos >> 4)) >= 0) { - R26_ = j - (layer1_y_pos >> 4); - if ((((__PAIR32__(j - (layer1_y_pos >> 4), j) - ((layer1_y_pos >> 4) | 0x100000)) >> 16) & 0x8000u) != 0) { - R22_ = 4 * (R24_ + 32 * R26_); - if ((R40 & 0x800) != 0) - Xray_Func16(R40 & 0x3FF); - else - Xray_Func13(R40 & 0x3FF); - } - } - } + uint16 R24 = k - (layer1_x_pos >> 4); + uint16 R26 = j - (layer1_y_pos >> 4); + if (!sign16(R24) && sign16(R24 - 16) && !sign16(R26) && sign16(R26 - 16)) { + uint16 R22 = 4 * (R24 + 32 * R26); + if ((a & 0x800) != 0) + Xray_Func16(R22, a & 0x3FF); + else + Xray_Func13(R22, a & 0x3FF); } } -void Xray_Func16(uint16 a) { // 0x91D0A6 - unsigned int v3; - - uint16 v1 = a; - uint16 top_left = tile_table.tables[v1].top_left; - uint16 top_right = tile_table.tables[v1].top_right; - uint16 bottom_left = tile_table.tables[v1].bottom_left; - uint16 v2 = R22_; - v3 = R22_; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[1] + R22_) = tile_table.tables[v1].bottom_right; - *(uint16 *)((uint8 *)ram4000.xray_tilemaps + v3) = bottom_left; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[33] + v2) = top_right; - *(uint16 *)((uint8 *)&ram4000.xray_tilemaps[32] + v2) = top_left; -} - void Xray_SetupStage5(void) { // 0x91D0D3 unsigned int v1; @@ -2455,19 +1318,19 @@ void VariaSuitPickup(void) { // 0x91D4E4 for (int i = 510; i >= 0; i -= 2) hdma_table_1[i >> 1] = 255; if (samus_movement_type == 3 || samus_movement_type == 20) - QueueSfx1_Max9(0x32u); + QueueSfx1_Max9(0x32); if ((equipped_items & 0x20) != 0) samus_pose = kPose_9B_FaceF_VariaGravitySuit; else samus_pose = kPose_00_FaceF_Powersuit; SamusFunc_F433(); Samus_SetAnimationFrameIfPoseChanged(); - CallSomeSamusCode(0x15u); + CallSomeSamusCode(0x15); samus_x_pos = layer1_x_pos + 120; samus_prev_x_pos = layer1_x_pos + 120; samus_y_pos = layer1_y_pos + 136; samus_prev_y_pos = layer1_y_pos + 136; - QueueSfx2_Max6(0x56u); + QueueSfx2_Max6(0x56); static const SpawnHdmaObject_Args unk_91D59B = { 0x41, 0x26, 0xd5a2 }; SpawnHdmaObject(0x91, &unk_91D59B); } @@ -2494,19 +1357,19 @@ void GravitySuitPickup(void) { // 0x91D5BA for (int i = 510; i >= 0; i -= 2) hdma_table_1[i >> 1] = 255; if (samus_movement_type == kMovementType_03_SpinJumping || samus_movement_type == kMovementType_14_WallJumping) - QueueSfx1_Max9(0x32u); + QueueSfx1_Max9(0x32); if ((equipped_items & 1) != 0) samus_pose = kPose_9B_FaceF_VariaGravitySuit; else samus_pose = kPose_00_FaceF_Powersuit; SamusFunc_F433(); Samus_SetAnimationFrameIfPoseChanged(); - CallSomeSamusCode(0x15u); + CallSomeSamusCode(0x15); samus_x_pos = layer1_x_pos + 120; samus_prev_x_pos = layer1_x_pos + 120; samus_y_pos = layer1_y_pos + 136; samus_prev_y_pos = layer1_y_pos + 136; - QueueSfx2_Max6(0x56u); + QueueSfx2_Max6(0x56); static const SpawnHdmaObject_Args unk_91D673 = { 0x41, 0x26, 0xd67a }; SpawnHdmaObject(0x91, &unk_91D673); } @@ -2546,7 +1409,7 @@ static Func_U8 *const off_91D72D[11] = { // 0x91D6F7 }; void Samus_HandlePalette(void) { - if ((samus_special_super_palette_flags & 0x8000u) == 0 + if ((samus_special_super_palette_flags & 0x8000) == 0 && (HandleBeamChargePalettes() & 1 || !(off_91D72D[timer_for_shine_timer]() & 1))) { CopyToSamusSuitPalette(off_91D727[samus_suit_palette_index >> 1]); @@ -2577,6 +1440,7 @@ uint8 HandleBeamChargePalettes(void) { // 0x91D743 } else if (grapple_beam_function == FUNC16(GrappleBeamFunc_Inactive) && flare_counter && !sign16(flare_counter - 60)) { + uint16 R36; if (samus_contact_damage_index == 4) R36 = kSamusPalette_PseudoScrew[samus_suit_palette_index >> 1]; else @@ -2605,8 +1469,7 @@ uint8 HandleVisorPalette(void) { // 0x91D83F palette_buffer[196] = word_9BA3C0[HIBYTE(v1) >> 1]; int v2 = HIBYTE(v1) + 2; if (sign16(v2 - 12)) { - R18_ = swap16(v2); - samus_visor_palette_timer_index = R18_ | (uint8)samus_visor_palette_timer_index; + samus_visor_palette_timer_index = swap16(v2) | (uint8)samus_visor_palette_timer_index; } else { samus_visor_palette_timer_index = (uint8)samus_visor_palette_timer_index | 0x600; } @@ -2627,7 +1490,7 @@ void HandleMiscSamusPalette(void) { // 0x91D8A5 if (!cinematic_function && (frame_handler_beta != FUNC16(j_HandleDemoRecorder_2_0) || samus_pose != kPose_54_FaceL_Knockback)) { - QueueSfx1_Max6(0x35u); + QueueSfx1_Max6(0x35); goto LABEL_14; } v0 = samus_hurt_flash_counter; @@ -2649,21 +1512,21 @@ LABEL_17:; if (v1 == 40) { if (grapple_beam_function == FUNC16(GrappleBeamFunc_Inactive)) { if (samus_movement_type == kMovementType_03_SpinJumping || samus_movement_type == kMovementType_14_WallJumping) { - CallSomeSamusCode(0x1Cu); + CallSomeSamusCode(0x1C); } else if (!sign16(flare_counter - 16) && (button_config_shoot_x & joypad1_lastkeys) != 0) { play_resume_charging_beam_sfx = 1; } } else if (sign16(grapple_beam_function + 0x37AA)) { - QueueSfx1_Max9(6u); + QueueSfx1_Max9(6); } } else if (!sign16(v1 - 60)) { samus_hurt_flash_counter = 0; } return; } - if ((samus_special_super_palette_flags & 0x8000u) != 0) { + if ((samus_special_super_palette_flags & 0x8000) != 0) { CopyToSamusSuitPalette(kSamus_HyperBeamPalettes[samus_charge_palette_index]); - bool v2 = (--special_samus_palette_timer & 0x8000u) != 0; + bool v2 = (--special_samus_palette_timer & 0x8000) != 0; if (!special_samus_palette_timer || v2) { special_samus_palette_timer = special_samus_palette_frame; if (!sign16(++samus_charge_palette_index - 10)) @@ -2681,11 +1544,11 @@ LABEL_17:; uint8 Samus_HandleScrewAttackSpeedBoostingPals(void) { // 0x91D9B2 if ((samus_suit_palette_index & 4) == 0) { - Samus_GetTopBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R20_)) + uint16 r20 = Samus_GetTop_R20(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r20)) return 1; - } else if (sign16(fx_y_pos - R20_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r20) && (fx_liquid_options & 4) == 0) { return 1; } } @@ -2703,8 +1566,8 @@ uint8 Samus_HandleScrewAttackSpeedBoostingPals(void) { // 0x91D9B2 if ((equipped_items & 8) == 0) return 1; if (!sign16(samus_anim_frame - 3)) { -LABEL_18: - R36 = kSamusPal_ScrewAttack[samus_suit_palette_index >> 1]; +LABEL_18:; + uint16 R36 = kSamusPal_ScrewAttack[samus_suit_palette_index >> 1]; uint16 v1 = *(uint16 *)RomPtr_91(R36 + special_samus_palette_frame); CopyToSamusSuitPalette(v1); uint16 v2 = special_samus_palette_frame + 2; @@ -2720,10 +1583,10 @@ LABEL_21: LABEL_10: if ((speed_boost_counter & 0xFF00) != 1024) return 1; - bool v3 = (--special_samus_palette_timer & 0x8000u) != 0; + bool v3 = (--special_samus_palette_timer & 0x8000) != 0; if (!special_samus_palette_timer || v3) { special_samus_palette_timer = 4; - R36 = kSamusPal_SpeedBoost[samus_suit_palette_index >> 1]; + uint16 R36 = kSamusPal_SpeedBoost[samus_suit_palette_index >> 1]; // Bugfix: The original game can do an out of bounds read here. if (special_samus_palette_frame > 6) special_samus_palette_frame = 6; @@ -2742,7 +1605,7 @@ uint8 Samus_SpeedBoosterShinePals(void) { // 0x91DAC7 uint16 v0 = samus_shine_timer; if (samus_shine_timer == 170) { uint16 v4 = samus_shine_timer; - QueueSfx3_Max9(0xCu); + QueueSfx3_Max9(0xC); v0 = v4; } samus_shine_timer = v0 - 1; @@ -2751,7 +1614,7 @@ uint8 Samus_SpeedBoosterShinePals(void) { // 0x91DAC7 timer_for_shine_timer = 0; return 0; } else { - R36 = kSamusPal_SpeedBoostShine[samus_suit_palette_index >> 1]; + uint16 R36 = kSamusPal_SpeedBoostShine[samus_suit_palette_index >> 1]; uint16 v1 = *(uint16 *)RomPtr_91(R36 + special_samus_palette_frame); CopyToSamusSuitPalette(v1); uint16 v2 = special_samus_palette_frame + 2; @@ -2763,13 +1626,13 @@ uint8 Samus_SpeedBoosterShinePals(void) { // 0x91DAC7 } uint8 Samus_HandleShinesparkingPals(void) { // 0x91DB3A - bool v0 = (--samus_shine_timer & 0x8000u) != 0; + bool v0 = (--samus_shine_timer & 0x8000) != 0; if (!samus_shine_timer || v0) { timer_for_shine_timer = 0; special_samus_palette_frame = 0; return 0; } else { - R36 = kSamusPal_Shinespark[samus_suit_palette_index >> 1]; + uint16 R36 = kSamusPal_Shinespark[samus_suit_palette_index >> 1]; uint16 v1 = *(uint16 *)RomPtr_91(R36 + special_samus_palette_frame); CopyToSamusSuitPalette(v1); uint16 v2 = special_samus_palette_frame + 2; @@ -2781,7 +1644,7 @@ uint8 Samus_HandleShinesparkingPals(void) { // 0x91DB3A } uint8 Samus_HandleCrystalFlashPals(void) { // 0x91DB93 - if ((samus_shine_timer & 0x8000u) != 0) { + if ((samus_shine_timer & 0x8000) != 0) { WriteBeamPalette_A(equipped_beams); timer_for_shine_timer = 0; special_samus_palette_frame = 0; @@ -2819,7 +1682,7 @@ void Samus_Copy6PalColors(uint16 j) { // 0x91DC82 } uint8 Samus_HandleXrayPals(void) { // 0x91DCB4 - if ((demo_timer_counter & 0x8000u) != 0) { + if ((demo_timer_counter & 0x8000) != 0) { timer_for_shine_timer = 0; special_samus_palette_frame = 0; special_samus_palette_timer = 0; @@ -2828,7 +1691,7 @@ uint8 Samus_HandleXrayPals(void) { // 0x91DCB4 } else { if (!demo_timer_counter) { if (sign16(demo_input_pre_instr - 2)) { - bool v0 = (--special_samus_palette_timer & 0x8000u) != 0; + bool v0 = (--special_samus_palette_timer & 0x8000) != 0; if (!special_samus_palette_timer || v0) { special_samus_palette_timer = 5; palette_buffer[196] = word_9BA3C0[special_samus_palette_frame >> 1]; @@ -2841,7 +1704,7 @@ uint8 Samus_HandleXrayPals(void) { // 0x91DCB4 special_samus_palette_timer = 1; demo_timer_counter = 1; } - bool v2 = (--special_samus_palette_timer & 0x8000u) != 0; + bool v2 = (--special_samus_palette_timer & 0x8000) != 0; if (special_samus_palette_timer && !v2) return 1; special_samus_palette_timer = 5; @@ -2880,7 +1743,7 @@ void Samus_CancelSpeedBoost(void) { // 0x91DE53 CopyToSamusSuitPalette(addr_kSamusPalette_PowerSuit); } } - if ((speed_echoes_index & 0x8000u) == 0) { + if ((speed_echoes_index & 0x8000) == 0) { speed_echoes_index = -1; if (samus_pose_x_dir == 4) { speed_echo_xspeed[0] = -8; @@ -2913,7 +1776,6 @@ void Samus_LoadSuitTargetPalette(void) { // 0x91DEE6 } void Samus_RestoreHealth(uint16 a) { // 0x91DF12 - R18_ = a; uint16 v1 = a + samus_health; samus_health = v1; if ((int16)(v1 - samus_max_health) >= 0) { @@ -2930,11 +1792,10 @@ void Samus_RestoreHealth(uint16 a) { // 0x91DF12 } void Samus_DealDamage(uint16 a) { // 0x91DF51 - R18_ = a; - if ((a & 0x8000u) == 0) { + if ((a & 0x8000) == 0) { if (a != 300 && !time_is_frozen_flag) { - samus_health -= R18_; - if ((samus_health & 0x8000u) != 0) + samus_health -= a; + if ((samus_health & 0x8000) != 0) samus_health = 0; } } else { @@ -2946,13 +1807,12 @@ void Samus_RestoreMissiles(uint16 a) { // 0x91DF80 uint16 v1 = samus_missiles + a; samus_missiles = v1; if ((int16)(v1 - samus_max_missiles) >= 0) { - R18_ = v1 - samus_max_missiles; if (sign16(samus_max_missiles - 99)) { - samus_reserve_missiles += R18_; + samus_reserve_missiles += v1 - samus_max_missiles; if ((int16)(samus_reserve_missiles - samus_max_missiles) >= 0) samus_reserve_missiles = samus_max_missiles; } else { - samus_reserve_missiles += R18_; + samus_reserve_missiles += v1 - samus_max_missiles; if (!sign16(samus_reserve_missiles - 99)) samus_reserve_missiles = 99; } @@ -2981,7 +1841,7 @@ void Samus_Initialize(void) { // 0x91E00D static const uint16 word_909EB1 = 1; static const uint16 word_909EA1 = 0x1c00; static const uint16 word_909EA7 = 0; - R18_ = debug_invincibility; + uint16 r18 = debug_invincibility; uint16 v0 = 0xE0B; do *RomPtr_RAM(v0--) = 0; @@ -3003,7 +1863,7 @@ void Samus_Initialize(void) { // 0x91E00D samus_special_transgfx_index = 0; samus_hurt_switch_index = 0; samus_input_handler = FUNC16(Samus_InputHandler_E913); - debug_invincibility = R18_; + debug_invincibility = r18; } } samus_new_pose = -1; @@ -3133,9 +1993,9 @@ void ResponsibleForXrayStandupGlitch(void) { // 0x91E2AD samus_movement_handler = FUNC16(Samus_MovementHandler_Normal); samus_input_handler = FUNC16(Samus_InputHandler_E913); demo_timer_counter = -1; - R18_ = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)) - samus_y_radius; - if ((R18_ & 0x8000u) == 0) { - samus_y_pos -= R18_; + uint16 r18 = kPoseParams[samus_pose].y_radius - samus_y_radius; + if ((r18 & 0x8000) == 0) { + samus_y_pos -= r18; samus_prev_y_pos = samus_y_pos; } EnableEnemyProjectiles(); @@ -3167,7 +2027,7 @@ void MakeSamusFaceForward(void) { // 0x91E3F6 samus_momentum_routine_index = 0; samus_special_transgfx_index = 0; samus_hurt_switch_index = 0; - CallSomeSamusCode(0x1Fu); + CallSomeSamusCode(0x1F); samus_x_extra_run_speed = 0; samus_x_extra_run_subspeed = 0; samus_x_base_speed = 0; @@ -3211,7 +2071,6 @@ void SomeMotherBrainScripts(uint16 a) { } uint8 SomeMotherBrainScripts_0(void) { // 0x91E4F8 - R18_ = 21 - samus_y_radius; samus_y_pos -= 21 - samus_y_radius; samus_prev_y_pos = samus_y_pos; if (samus_pose_x_dir == 4) @@ -3221,7 +2080,7 @@ uint8 SomeMotherBrainScripts_0(void) { // 0x91E4F8 samus_anim_frame_skip = 2; SamusFunc_F433(); Samus_SetAnimationFrameIfPoseChanged(); - samus_y_radius = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); + samus_y_radius = kPoseParams[samus_pose].y_radius; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_y_subspeed = 0; @@ -3257,7 +2116,7 @@ uint8 SomeMotherBrainScripts_2(void) { // 0x91E59B samus_anim_frame_timer = 1; samus_anim_frame = 4; } - samus_y_radius = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); + samus_y_radius = kPoseParams[samus_pose].y_radius; samus_x_base_speed = 0; samus_x_base_subspeed = 0; samus_y_subspeed = 0; @@ -3342,7 +2201,7 @@ void SamusFunc_E633(void) { if (grapple_beam_function == FUNC16(GrappleBeamFunc_Inactive)) { if ((equipped_beams & 0x1000) != 0) { if (!sign16(flare_counter - 16)) - QueueSfx1_Max6(0x41u); + QueueSfx1_Max6(0x41); } else { flare_counter = 0; flare_animation_frame = 0; @@ -3353,12 +2212,12 @@ void SamusFunc_E633(void) { flare_fast_sparks_anim_timer = 0; } } else { - LoadProjectilePalette(2u); - QueueSfx1_Max6(6u); + LoadProjectilePalette(2); + QueueSfx1_Max6(6); } Samus_LoadSuitPalette(); if (sign16(samus_health - 31)) - QueueSfx3_Max6(2u); + QueueSfx3_Max6(2); } void Samus_UpdatePreviousPose_0(void) { // 0x91E719 @@ -3474,7 +2333,6 @@ void Samus_HandleTransFromBlockColl_4(void) { // 0x91E8E5 samus_momentum_routine_index = 5; } - uint8 nullsub_18_U8(void) { return 0; } @@ -3508,6 +2366,7 @@ void Samus_HandleTransFromBlockColl_1(void) { // 0x91E931 samus_momentum_routine_index = 5; } } + uint8 Samus_HandleTransFromBlockColl_1_0(void) { // 0x91E95D int16 v0; @@ -3519,7 +2378,7 @@ uint8 Samus_HandleTransFromBlockColl_1_0(void) { // 0x91E95D samus_new_pose = kPose_A6_FaceR_LandSpinJump; return 0; } else { - v0 = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)); + v0 = kPoseParams[samus_pose].direction_shots_fired; if (v0 == 255) { if (samus_pose_x_dir == 4) samus_new_pose = kPose_A5_FaceL_LandJump; @@ -3530,7 +2389,7 @@ uint8 Samus_HandleTransFromBlockColl_1_0(void) { // 0x91E95D if (v0 != 2 && v0 != 7) goto LABEL_6; if ((button_config_shoot_x & joypad1_lastkeys) == 0) { - v0 = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)); + v0 = kPoseParams[samus_pose].direction_shots_fired; LABEL_6: samus_new_pose = word_91E9F3[v0]; return 0; @@ -3553,11 +2412,8 @@ uint8 Samus_HandleTransFromBlockColl_1_1(void) { // 0x91EA07 samus_new_pose = samus_pose; return 0; } - if (v0 != 4) { + if (v0 != 4) Unreachable(); - while (1) - ; - } } else if (!sign16(samus_y_speed - 3)) { samus_new_pose = samus_pose; return 0; @@ -3590,11 +2446,8 @@ uint8 Samus_HandleTransFromBlockColl_1_3(void) { // 0x91EA63 samus_new_pose = samus_pose; return 0; } - if (v1 != 4) { + if (v1 != 4) Unreachable(); - while (1) - ; - } } else if (!sign16(samus_y_speed - 3)) { samus_new_pose = samus_pose; return 0; @@ -3620,48 +2473,44 @@ void Samus_HandleTransFromBlockColl_5(void) { // 0x91EABE } -uint8 Samus_CheckWalkedIntoSomething(void) { // 0x91EADE - int16 v0; +void Samus_CheckWalkedIntoSomething(void) { // 0x91EADE + int32 amt; if (samus_collides_with_solid_enemy && samus_movement_type == 1) { - v0 = samus_pose; - goto LABEL_13; + samus_new_pose = word_91EB74[*(&kPoseParams[0].direction_shots_fired + (8 * samus_pose))]; + samus_collides_with_solid_enemy = 0; + return; + } + if (samus_new_pose == 0xFFFF || kPoseParams[samus_new_pose].movement_type != 1) { + samus_collides_with_solid_enemy = 0; + return; } - if (samus_new_pose == 0xFFFF || *(&kPoseParams[0].movement_type + (uint16)(8 * samus_new_pose)) != 1) - goto LABEL_14; if (samus_pose_x_dir != 4) { - R18_ = 1; samus_collision_direction = 1; - R20_ = 0; - if (!Samus_CheckSolidEnemyColl()) { - R18_ = 1; + amt = INT16_SHL16(1); + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + if (!cres.collision) { samus_collision_direction = 1; - R20_ = 0; + amt = INT16_SHL16(1); goto LABEL_10; } LABEL_11: - v0 = samus_new_pose; -LABEL_13: - samus_new_pose = word_91EB74[(uint16)(2 - * *(&kPoseParams[0].direction_shots_fired - + (uint16)(8 * v0))) >> 1]; + samus_new_pose = word_91EB74[*(&kPoseParams[0].direction_shots_fired + (8 * samus_new_pose))]; samus_collides_with_solid_enemy = 0; - return 1; + return; } - R18_ = 1; - R20_ = 0; samus_collision_direction = 0; - if (Samus_CheckSolidEnemyColl()) + amt = INT16_SHL16(1); + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(amt); + if (cres.collision) goto LABEL_11; - R18_ = -1; - R20_ = 0; + amt = INT16_SHL16(-1); samus_collision_direction = 0; LABEL_10: - if (Samus_MoveRight_NoSolidColl() & 1) + Samus_MoveRight_NoSolidColl(amt); + if (samus_collision_flag) goto LABEL_11; -LABEL_14: samus_collides_with_solid_enemy = 0; - return 0; } void nullsub_19(void) {} @@ -3705,7 +2554,7 @@ static Func_V *const kSamus_HandleTransitionsC[9] = { }; void Samus_HandleTransitions(void) { - if ((samus_new_pose_transitional & 0x8000u) == 0) { + if ((samus_new_pose_transitional & 0x8000) == 0) { if (samus_hurt_switch_index != 3) { if (samus_hurt_switch_index == 1) goto LABEL_7; @@ -3726,14 +2575,14 @@ LABEL_15: goto LABEL_16; } } - if ((samus_new_pose_interrupted & 0x8000u) == 0) { + if ((samus_new_pose_interrupted & 0x8000) == 0) { samus_pose = samus_new_pose_interrupted; if (!(SamusFunc_F404() & 1)) kSamus_HandleTransitionsB[samus_special_transgfx_index](); goto LABEL_15; } Samus_CheckWalkedIntoSomething(); - if ((samus_new_pose & 0x8000u) == 0) { + if ((samus_new_pose & 0x8000) == 0) { samus_pose = samus_new_pose; if (!(SamusFunc_F404() & 1)) kSamus_HandleTransitionsA[samus_momentum_routine_index](); @@ -3773,8 +2622,6 @@ void Samus_HandleTransitionsA_8(void) { // 0x91EC8E SamusFunc_EC80(); } - - void Samus_HandleTransitionsA_2(void) { // 0x91ECD0 samus_x_accel_mode = 0; Samus_CancelSpeedBoost(); @@ -3786,16 +2633,16 @@ static const uint16 word_91ED36[12] = { // 0x91ECDA }; void Samus_HandleTransitionsA_7(void) { + int32 amt; + if (sign16(samus_pose - kPose_DB)) { - R18_ = word_91ED36[samus_pose - 53]; - if (!R18_) - goto LABEL_5; - R20_ = 0; + amt = INT16_SHL16(word_91ED36[samus_pose - 53]); + if (amt) { LABEL_4: - samus_y_radius = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); - Samus_CollDetectChangedPose(); -LABEL_5: - samus_y_pos += R18_; + samus_y_radius = kPoseParams[samus_pose].y_radius; + amt = Samus_CollDetectChangedPose(amt); + } + samus_y_pos += amt >> 16; samus_prev_y_pos = samus_y_pos; if (used_for_ball_bounce_on_landing) { used_for_ball_bounce_on_landing = 0; @@ -3803,11 +2650,8 @@ LABEL_5: samus_y_speed = 0; samus_y_dir = 0; } - return; - } - if (!sign16(samus_pose - kPose_F1_FaceR_CrouchTrans_AimU) && sign16(samus_pose - kPose_F7_FaceR_StandTrans_AimU)) { - R18_ = 5; - R20_ = 0; + } else if (!sign16(samus_pose - kPose_F1_FaceR_CrouchTrans_AimU) && sign16(samus_pose - kPose_F7_FaceR_StandTrans_AimU)) { + amt = INT16_SHL16(5); goto LABEL_4; } } @@ -3963,7 +2807,7 @@ LABEL_11: flare_animation_timer = 0; flare_slow_sparks_anim_timer = 0; flare_fast_sparks_anim_timer = 0; - QueueSfx1_Max6(9u); + QueueSfx1_Max6(9); break; } } @@ -4100,18 +2944,18 @@ void HandleLandingSoundEffectsAndGfx(void) { // 0x91F046 || samus_prev_movement_type2 == kMovementType_14_WallJumping) && !cinematic_function) { if (samus_prev_pose == kPose_81_FaceR_Screwattack || samus_prev_pose == kPose_82_FaceL_Screwattack) - QueueSfx1_Max6(0x34u); + QueueSfx1_Max6(0x34); else - QueueSfx1_Max6(0x32u); + QueueSfx1_Max6(0x32); } if (samus_y_speed && !sign16(samus_y_speed - 5)) { if (!cinematic_function) - QueueSfx3_Max6(4u); + QueueSfx3_Max6(4); } else { if (!samus_y_subspeed) return; if (!cinematic_function) - QueueSfx3_Max6(5u); + QueueSfx3_Max6(5); } HandleLandingGraphics(); } @@ -4166,9 +3010,9 @@ LABEL_14: } void HandleLandingGraphics_Maridia(void) { // 0x91F116 - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) == 0) { - if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) + uint16 bottom = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) == 0) { + if (sign16(fx_y_pos - bottom) && (fx_liquid_options & 4) == 0) return; LABEL_7: atmospheric_gfx_frame_and_type[2] = 256; @@ -4177,18 +3021,18 @@ LABEL_7: atmospheric_gfx_anim_timer[3] = 3; atmospheric_gfx_x_pos[2] = samus_x_pos + 4; atmospheric_gfx_x_pos[3] = samus_x_pos - 3; - atmospheric_gfx_y_pos[2] = R18_ - 4; - atmospheric_gfx_y_pos[3] = R18_ - 4; + atmospheric_gfx_y_pos[2] = bottom - 4; + atmospheric_gfx_y_pos[3] = bottom - 4; return; } - if ((lava_acid_y_pos & 0x8000u) != 0 || !sign16(lava_acid_y_pos - R18_)) + if ((lava_acid_y_pos & 0x8000) != 0 || !sign16(lava_acid_y_pos - bottom)) goto LABEL_7; } void HandleLandingGraphics_Norfair(void) { // 0x91F166 - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) == 0) { - if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) + uint16 bottom = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) == 0) { + if (sign16(fx_y_pos - bottom) && (fx_liquid_options & 4) == 0) return; LABEL_7: atmospheric_gfx_frame_and_type[2] = 1536; @@ -4197,11 +3041,11 @@ LABEL_7: atmospheric_gfx_anim_timer[3] = 3; atmospheric_gfx_x_pos[2] = samus_x_pos + 8; atmospheric_gfx_x_pos[3] = samus_x_pos - 8; - atmospheric_gfx_y_pos[2] = R18_; - atmospheric_gfx_y_pos[3] = R18_; + atmospheric_gfx_y_pos[2] = bottom; + atmospheric_gfx_y_pos[3] = bottom; return; } - if ((lava_acid_y_pos & 0x8000u) != 0 || !sign16(lava_acid_y_pos - R18_)) + if ((lava_acid_y_pos & 0x8000) != 0 || !sign16(lava_acid_y_pos - bottom)) goto LABEL_7; } @@ -4251,11 +3095,8 @@ uint8 Samus_MorphBallBounceNoSpringballTrans(void) { // 0x91F1FC samus_y_speed = g_word_909EB5 - 1; return 1; } - if (v0 != 4) { + if (v0 != 4) Unreachable(); - while (1) - ; - } } else if (!sign16(samus_y_speed - 3)) { ++used_for_ball_bounce_on_landing; samus_y_dir = 1; @@ -4293,11 +3134,8 @@ uint8 Samus_MorphBallBounceSpringballTrans(void) { // 0x91F25E samus_y_speed = g_word_909EB5 - 1; return 1; } - if (v1 != 4) { + if (v1 != 4) Unreachable(); - while (1) - ; - } } else if (!sign16(samus_y_speed - 3)) { used_for_ball_bounce_on_landing = 1537; samus_y_dir = 1; @@ -4325,7 +3163,7 @@ void Samus_HandleTransitionsA_5_5(void) { // 0x91F2D3 samus_x_base_speed = 0; samus_x_base_subspeed = 0; UNUSED_word_7E0A18 = 0; - QueueSfx3_Max6(5u); + QueueSfx3_Max6(5); } void Samus_HandleTransitionsA_5_6(void) { // 0x91F2F0 @@ -4420,7 +3258,7 @@ uint8 SamusFunc_F404(void) { // 0x91F404 } void SamusFunc_F433(void) { // 0x91F433 - *(uint16 *)&samus_pose_x_dir = *(uint16 *)(&kPoseParams[0].pose_x_dir + (uint16)(8 * samus_pose)); + *(uint16 *)&samus_pose_x_dir = *(uint16 *)(&kPoseParams[0].pose_x_dir + (8 * samus_pose)); SamusFunc_F468(); if ((samus_prev_movement_type2 == kMovementType_03_SpinJumping || samus_prev_movement_type2 == kMovementType_14_WallJumping) @@ -4462,10 +3300,10 @@ static Func_U8 *const off_91F4A2[28] = { // 0x91F468 void SamusFunc_F468(void) { if (off_91F4A2[samus_movement_type]() & 1) { - *(uint16 *)&samus_pose_x_dir = *(uint16 *)(&kPoseParams[0].pose_x_dir + (uint16)(8 * samus_pose)); + *(uint16 *)&samus_pose_x_dir = *(uint16 *)(&kPoseParams[0].pose_x_dir + (8 * samus_pose)); if ((*(uint16 *)&samus_pose_x_dir & 0xFF00) == 3584) { off_91F4A2[14](); - *(uint16 *)&samus_pose_x_dir = *(uint16 *)(&kPoseParams[0].pose_x_dir + (uint16)(8 * samus_pose)); + *(uint16 *)&samus_pose_x_dir = *(uint16 *)(&kPoseParams[0].pose_x_dir + (8 * samus_pose)); } } } @@ -4475,10 +3313,10 @@ uint8 SamusFunc_F468_Unused(void) { // 0x91F4DA } uint8 SamusFunc_F468_Standing(void) { // 0x91F4DC - if ((!*(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)) - || *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)) == 9) - && (!*(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_prev_pose)) - || *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_prev_pose)) == 9)) { + if ((!kPoseParams[samus_pose].direction_shots_fired + || kPoseParams[samus_pose].direction_shots_fired == 9) + && (!kPoseParams[samus_prev_pose].direction_shots_fired + || kPoseParams[samus_prev_pose].direction_shots_fired == 9)) { samus_anim_frame_skip = 1; } return 0; @@ -4534,7 +3372,7 @@ LABEL_14: samus_anim_frame_skip = 1; } if ((button_config_shoot_x & joypad1_newkeys) != 0) - new_projectile_direction_changed_pose = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)) | 0x8000; + new_projectile_direction_changed_pose = kPoseParams[samus_pose].direction_shots_fired | 0x8000; return 0; } @@ -4576,11 +3414,11 @@ uint8 SamusFunc_F468_SpinJump(void) { // 0x91F624 LABEL_9: if (samus_pose_x_dir == 4) { if ((equipped_items & 0x20) == 0) { - Samus_GetTopBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R20_)) + uint16 r20 = Samus_GetTop_R20(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r20)) return 0; - } else if (sign16(fx_y_pos - R20_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r20) && (fx_liquid_options & 4) == 0) { return 0; } } @@ -4589,23 +3427,23 @@ LABEL_9: goto LABEL_40; } if ((equipped_items & 0x200) != 0) { - QueueSfx1_Max6(0x3Eu); + QueueSfx1_Max6(0x3E); samus_pose = kPose_1C_FaceL_SpaceJump; return 0; } if (!samus_anim_frame_skip && !cinematic_function) { LABEL_22: - QueueSfx1_Max6(0x31u); + QueueSfx1_Max6(0x31); return 0; } return 0; } if ((equipped_items & 0x20) == 0) { - Samus_GetTopBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R20_)) + uint16 r20 = Samus_GetTop_R20(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r20)) return 0; - } else if (sign16(fx_y_pos - R20_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - r20) && (fx_liquid_options & 4) == 0) { return 0; } } @@ -4613,7 +3451,7 @@ LABEL_22: samus_pose = kPose_81_FaceR_Screwattack; LABEL_40: if (!samus_anim_frame_skip) - QueueSfx1_Max6(0x33u); + QueueSfx1_Max6(0x33); return 0; } if ((equipped_items & 0x200) == 0) { @@ -4621,10 +3459,11 @@ LABEL_40: return 0; goto LABEL_22; } - QueueSfx1_Max6(0x3Eu); + QueueSfx1_Max6(0x3E); samus_pose = kPose_1B_FaceR_SpaceJump; return 0; } + static Func_U8 *const off_91F790[12] = { // 0x91F758 Samus_CrouchTrans, Samus_CrouchTrans, @@ -4639,12 +3478,14 @@ static Func_U8 *const off_91F790[12] = { // 0x91F758 Samus_StandOrUnmorphTrans, Samus_StandOrUnmorphTrans, }; + static Func_U8 *const off_91F7A8[4] = { Samus_MorphTrans, Samus_MorphTrans, Samus_StandOrUnmorphTrans, Samus_StandOrUnmorphTrans, }; + uint8 SamusFunc_F468_CrouchTransEtc(void) { uint16 v0; if (sign16(samus_pose - kPose_F1_FaceR_CrouchTrans_AimU)) { @@ -4749,17 +3590,17 @@ uint8 SamusFunc_F468_DamageBoost_(void) { // 0x91F8CB uint8 SamusFunc_F468_TurningAroundOnGround(void) { // 0x91F8D3 if (samus_prev_pose && samus_prev_pose != kPose_9B_FaceF_VariaGravitySuit) { - uint16 v0 = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_prev_pose)); + uint16 v0 = kPoseParams[samus_prev_pose].direction_shots_fired; if (samus_prev_movement_type2 == kMovementType_10_Moonwalking) { new_projectile_direction_changed_pose = *(&kPoseParams[0].direction_shots_fired - + (uint16)(8 * samus_prev_pose)) | 0x100; + + (8 * samus_prev_pose)) | 0x100; if ((button_config_jump_a & joypad1_lastkeys) != 0) { samus_pose = kSamusTurnPose_Moonwalk[v0]; goto LABEL_9; } } else if (samus_prev_movement_type2 == 5) { samus_pose = kSamusTurnPose_Crouching[*(&kPoseParams[0].direction_shots_fired - + (uint16)(8 * samus_prev_pose))]; + + (8 * samus_prev_pose))]; goto LABEL_9; } samus_pose = kSamusTurnPose_Standing[v0]; @@ -4776,7 +3617,7 @@ LABEL_9:; } uint8 SamusFunc_F468_TurnAroundJumping(void) { // 0x91F952 - samus_pose = kSamusTurnPose_Jumping[*(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_prev_pose))]; + samus_pose = kSamusTurnPose_Jumping[kPoseParams[samus_prev_pose].direction_shots_fired]; uint16 v0 = (__PAIR32__(samus_x_extra_run_speed, samus_x_base_subspeed) + __PAIR32__(samus_x_base_speed, samus_x_extra_run_subspeed)) >> 16; samus_x_base_subspeed += samus_x_extra_run_subspeed; @@ -4788,7 +3629,7 @@ uint8 SamusFunc_F468_TurnAroundJumping(void) { // 0x91F952 } uint8 SamusFunc_F468_TurnAroundFalling(void) { // 0x91F98A - samus_pose = kSamusTurnPose_Falling[*(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_prev_pose))]; + samus_pose = kSamusTurnPose_Falling[kPoseParams[samus_prev_pose].direction_shots_fired]; uint16 v0 = (__PAIR32__(samus_x_extra_run_speed, samus_x_base_subspeed) + __PAIR32__(samus_x_base_speed, samus_x_extra_run_subspeed)) >> 16; samus_x_base_subspeed += samus_x_extra_run_subspeed; @@ -4838,16 +3679,16 @@ uint8 SamusFunc_F468_Springball(void) { // 0x91FA56 } uint8 SamusFunc_F468_WallJumping(void) { // 0x91FA76 - Samus_GetBottomBoundary(); - if ((fx_y_pos & 0x8000u) != 0) { - if ((lava_acid_y_pos & 0x8000u) == 0 && sign16(lava_acid_y_pos - R18_)) + uint16 bottom = Samus_GetBottom_R18(); + if ((fx_y_pos & 0x8000) != 0) { + if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - bottom)) return 0; - } else if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { + } else if (sign16(fx_y_pos - bottom) && (fx_liquid_options & 4) == 0) { return 0; } atmospheric_gfx_frame_and_type[3] = 1536; atmospheric_gfx_anim_timer[3] = 3; - atmospheric_gfx_y_pos[3] = R18_; + atmospheric_gfx_y_pos[3] = bottom; if (samus_pose_x_dir != 8) { atmospheric_gfx_x_pos[3] = samus_x_pos + 6; return 0; @@ -4873,7 +3714,7 @@ uint8 SamusFunc_F468_Shinespark(void) { speed_echo_xspeed[1] = 0; speed_echo_xpos[0] = 0; speed_echo_xpos[1] = 0; - QueueSfx3_Max9(0xFu); + QueueSfx3_Max9(0xF); } return 0; } @@ -4881,28 +3722,22 @@ static const uint16 kSamusPhys_AnimDelayInWater = 3; static const uint16 kSamusPhys_AnimDelayInAcid = 2; void Samus_SetAnimationFrameIfPoseChanged(void) { // 0x91FB08 - if ((equipped_items & 0x20) != 0) - goto LABEL_7; - R18_ = samus_y_pos + *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)) - 1; - if ((fx_y_pos & 0x8000u) == 0) { - if (sign16(fx_y_pos - R18_) && (fx_liquid_options & 4) == 0) { - R18_ = kSamusPhys_AnimDelayInWater; - goto LABEL_11; + uint16 t; + if ((equipped_items & 0x20) != 0) { + t = samus_x_speed_divisor; + } else { + uint16 r = samus_y_pos + kPoseParams[samus_pose].y_radius - 1; + if ((fx_y_pos & 0x8000) == 0) { + t = (sign16(fx_y_pos - r) && (fx_liquid_options & 4) == 0) ? kSamusPhys_AnimDelayInWater : samus_x_speed_divisor; + } else if ((lava_acid_y_pos & 0x8000) != 0 || !sign16(lava_acid_y_pos - r)) { + t = samus_x_speed_divisor; + } else { + t = kSamusPhys_AnimDelayInAcid; } -LABEL_7: - R18_ = samus_x_speed_divisor; - goto LABEL_11; } - if ((lava_acid_y_pos & 0x8000u) != 0 || !sign16(lava_acid_y_pos - R18_)) - goto LABEL_7; - R18_ = kSamusPhys_AnimDelayInAcid; -LABEL_11: - if ((samus_anim_frame_skip & 0x8000u) == 0 && samus_pose != samus_prev_pose) { + if ((samus_anim_frame_skip & 0x8000) == 0 && samus_pose != samus_prev_pose) { samus_anim_frame = samus_anim_frame_skip; - samus_anim_frame_timer = R18_ - + *RomPtr_91( - kSamusAnimationDelayData[samus_pose] - + samus_anim_frame_skip); + samus_anim_frame_timer = t + *RomPtr_91(kSamusAnimationDelayData[samus_pose] + samus_anim_frame_skip); } } @@ -5062,48 +3897,46 @@ static Func_U8 *const off_91FE92[4] = { }; void HandleCollDueToChangedPose(void) { + CheckEnemyColl_Result cres; + int32 amt; int16 v0; - if (samus_pose) { - if (samus_pose != kPose_9B_FaceF_VariaGravitySuit) { - solid_enemy_collision_flags = 0; - block_collision_flags = 0; - R18_ = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); - v0 = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_prev_pose)); - if (sign16(v0 - R18_)) { - samus_y_radius = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_prev_pose)); - samus_y_radius_diff = R18_ - v0; - R18_ -= v0; - R20_ = 0; - samus_collision_direction = 2; - samus_collision_flag = Samus_CheckSolidEnemyColl(); - if (samus_collision_flag) - solid_enemy_collision_flags = 1; - samus_space_to_move_up_enemy = R18_; - R18_ = samus_y_radius_diff; - R20_ = 0; - samus_collision_direction = 3; - samus_collision_flag = Samus_CheckSolidEnemyColl(); - if (samus_collision_flag) - solid_enemy_collision_flags |= 2u; - samus_space_to_move_down_enemy = R18_; - if (off_91FE8A[solid_enemy_collision_flags]() & 1) - goto LABEL_15; - R18_ = -samus_y_radius_diff; - R20_ = 0; - if (Samus_CollDetectChangedPose() & 1) - block_collision_flags = 1; - samus_space_to_move_up_blocks = R18_; - R18_ = samus_y_radius_diff; - R20_ = 0; - if (Samus_CollDetectChangedPose() & 1) - block_collision_flags |= 2u; - samus_space_to_move_down_blocks = R18_; - if (off_91FE92[block_collision_flags]() & 1) - LABEL_15: - samus_pose = samus_prev_pose; - } - } + if (!samus_pose || samus_pose == kPose_9B_FaceF_VariaGravitySuit) + return; + solid_enemy_collision_flags = 0; + block_collision_flags = 0; + v0 = kPoseParams[samus_prev_pose].y_radius; + if (!sign16(v0 - kPoseParams[samus_pose].y_radius)) + return; + samus_y_radius = kPoseParams[samus_prev_pose].y_radius; + samus_y_radius_diff = kPoseParams[samus_pose].y_radius - v0; + samus_collision_direction = 2; + cres = Samus_CheckSolidEnemyColl(INT16_SHL16(samus_y_radius_diff)); + samus_collision_flag = cres.collision, amt = cres.amt; + if (samus_collision_flag) + solid_enemy_collision_flags = 1; + samus_space_to_move_up_enemy = (amt >> 16); + samus_collision_direction = 3; + cres = Samus_CheckSolidEnemyColl(INT16_SHL16(samus_y_radius_diff)); + samus_collision_flag = cres.collision, amt = cres.amt; + if (samus_collision_flag) + solid_enemy_collision_flags |= 2; + samus_space_to_move_down_enemy = (amt >> 16); + if (off_91FE8A[solid_enemy_collision_flags]()) { + samus_pose = samus_prev_pose; + return; + } + amt = Samus_CollDetectChangedPose(INT16_SHL16(-samus_y_radius_diff)); + if (samus_collision_flag) + block_collision_flags = 1; + samus_space_to_move_up_blocks = (amt >> 16); + + amt = Samus_CollDetectChangedPose(INT16_SHL16(samus_y_radius_diff)); + if (samus_collision_flag) + block_collision_flags |= 2; + samus_space_to_move_down_blocks = (amt >> 16); + if (off_91FE92[block_collision_flags]()) { + samus_pose = samus_prev_pose; } } @@ -5116,102 +3949,81 @@ uint8 HandleCollDueToChangedPose_Solid_CollBoth(void) { // 0x91FE9C } uint8 HandleCollDueToChangedPose_Solid_CollAbove(void) { // 0x91FE9E - R18_ = samus_y_radius_diff - samus_space_to_move_up_enemy; - R20_ = 0; uint16 v1 = samus_y_radius; - samus_y_radius = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); + samus_y_radius = kPoseParams[samus_pose].y_radius; samus_collision_direction = 3; - samus_collision_flag = Samus_CheckSolidEnemyColl(); - if (samus_collision_flag) { - samus_y_radius = v1; + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(INT16_SHL16(samus_y_radius_diff - samus_space_to_move_up_enemy)); + samus_y_radius = v1; + samus_collision_flag = cres.collision; + if (samus_collision_flag) return 1; - } else { - samus_space_to_move_up_enemy = R18_; - samus_y_radius = v1; - return 0; - } + samus_space_to_move_up_enemy = cres.amt >> 16; + return 0; } uint8 HandleCollDueToChangedPose_Solid_CollBelow(void) { // 0x91FEDF - R18_ = samus_y_radius_diff - samus_space_to_move_down_enemy; - R20_ = 0; uint16 v1 = samus_y_radius; - samus_y_radius = *(&kPoseParams[0].y_radius + (uint16)(8 * samus_pose)); + samus_y_radius = kPoseParams[samus_pose].y_radius; samus_collision_direction = 2; - samus_collision_flag = Samus_CheckSolidEnemyColl(); - if (samus_collision_flag) { - samus_y_radius = v1; + CheckEnemyColl_Result cres = Samus_CheckSolidEnemyColl(INT16_SHL16(samus_y_radius_diff - samus_space_to_move_down_enemy)); + samus_y_radius = v1; + samus_collision_flag = cres.collision; + if (samus_collision_flag) return 1; - } else { - samus_space_to_move_down_enemy = R18_; - samus_y_radius = v1; - return 0; - } + samus_space_to_move_down_enemy = cres.amt >> 16; + return 0; } uint8 HandleCollDueToChangedPose_Block_CollAbove(void) { // 0x91FF20 - R18_ = samus_y_radius_diff - samus_space_to_move_up_blocks; - R20_ = 0; - if (Samus_CollDetectChangedPose() & 1) + int32 amt = Samus_CollDetectChangedPose(INT16_SHL16(samus_y_radius_diff - samus_space_to_move_up_blocks)); + if (samus_collision_flag) return 1; if ((solid_enemy_collision_flags & 2) != 0) return HandleCollDueToChangedPose_Block_CollBoth(); - samus_y_pos += R18_; + samus_y_pos += amt >> 16; samus_prev_y_pos = samus_y_pos; return 0; } uint8 HandleCollDueToChangedPose_Block_CollBelow(void) { // 0x91FF49 - R18_ = samus_space_to_move_down_blocks - samus_y_radius_diff; - R20_ = 0; - if (Samus_CollDetectChangedPose() & 1) + int32 amt = Samus_CollDetectChangedPose(INT16_SHL16(samus_space_to_move_down_blocks - samus_y_radius_diff)); + if (samus_collision_flag) return 1; if ((solid_enemy_collision_flags & 1) != 0) return HandleCollDueToChangedPose_Block_CollBoth(); - samus_y_pos -= R18_; + samus_y_pos -= amt >> 16; samus_prev_y_pos = samus_y_pos; return 0; } uint8 HandleCollDueToChangedPose_Block_NoColl(void) { // 0x91FF76 - int16 v0; - - v0 = 2 * solid_enemy_collision_flags; - if (!(2 * solid_enemy_collision_flags)) + switch (solid_enemy_collision_flags) { + case 0: return 0; - switch (v0) { - case 2: + case 1: samus_y_pos += samus_space_to_move_up_enemy; samus_prev_y_pos = samus_y_pos; return 0; - case 4: + case 2: samus_y_pos -= samus_space_to_move_down_enemy; samus_prev_y_pos = samus_y_pos; return 0; - case 6: + case 3: return HandleCollDueToChangedPose_Block_CollBoth(); default: Unreachable(); - while (1) - ; + return 0; } } uint8 HandleCollDueToChangedPose_Block_CollBoth(void) { // 0x91FFA7 - SamusPose v1; - if (sign16(samus_y_radius - 8)) return 1; - if (samus_pose_x_dir == 4) - v1 = kPose_28_FaceL_Crouch; - else - v1 = kPose_27_FaceR_Crouch; - samus_pose = v1; - R18_ = *(&kPoseParams[0].y_radius + (uint16)(8 * v1)); - if (sign16(samus_y_radius - R18_)) { - R18_ = samus_y_radius - R18_; - samus_y_pos += R18_; + samus_pose = (samus_pose_x_dir == 4) ? kPose_28_FaceL_Crouch : kPose_27_FaceR_Crouch; + uint16 r18 = kPoseParams[samus_pose].y_radius; + if (sign16(samus_y_radius - r18)) { + samus_y_pos += samus_y_radius - r18; samus_prev_y_pos = samus_y_pos; } return 0; -} \ No newline at end of file +} diff --git a/src/sm_92.c b/src/sm_92.c index cd63ae6..4639a2e 100644 --- a/src/sm_92.c +++ b/src/sm_92.c @@ -4,30 +4,20 @@ #include "variables.h" #include "funcs.h" - #define kSamus_AnimationDefinitionPtrs ((uint16*)RomFixedPtr(0x92d94e)) #define kSamus_TileDefs_TopHalf ((uint16*)RomFixedPtr(0x92d91e)) #define kSamus_TileDefs_BottomHalf ((uint16*)RomFixedPtr(0x92d938)) - - - void SetSamusTilesDefsForCurAnim(void) { // 0x928000 - int16 v2; - - R18_ = 4 * samus_anim_frame; - R20_ = 4 * samus_anim_frame + 2; uint16 v0 = 4 * samus_anim_frame + kSamus_AnimationDefinitionPtrs[samus_pose]; - R22_ = get_SamusTileAnimationDefs(v0)->top_half_idx; + uint16 r22 = get_SamusTileAnimationDefs(v0)->top_half_idx; tempB24 = get_SamusTileAnimationDefs(v0 + 1)->top_half_idx; - R18_ = 7 * tempB24; - nmi_copy_samus_top_half_src = 7 * tempB24 + kSamus_TileDefs_TopHalf[R22_]; + nmi_copy_samus_top_half_src = 7 * tempB24 + kSamus_TileDefs_TopHalf[r22]; LOBYTE(nmi_copy_samus_halves) = 1; - uint16 v1 = R20_ + kSamus_AnimationDefinitionPtrs[samus_pose]; - v2 = *RomPtr_92(v1); + uint16 v1 = kSamus_AnimationDefinitionPtrs[samus_pose] + 4 * samus_anim_frame + 2; + uint8 v2 = *RomPtr_92(v1); if (v2 != 255) { tempB26 = *RomPtr_92(v1 + 1); - R20_ = 7 * tempB26; nmi_copy_samus_bottom_half_src = 7 * tempB26 + kSamus_TileDefs_BottomHalf[v2]; HIBYTE(nmi_copy_samus_halves) = 1; } @@ -36,9 +26,9 @@ void SetSamusTilesDefsForCurAnim(void) { // 0x928000 uint8 PlaySamusFanfare(void) { // 0x92ED24 if (substate) { if (substate == 5) - PlayRoomMusicTrackAfterAFrames(0x168u); + PlayRoomMusicTrackAfterAFrames(0x168); } else { - QueueMusic_DelayedY(1u, 0xE); + QueueMusic_DelayedY(1, 0xE); } if (sign16(substate - 359)) { ++substate; @@ -61,9 +51,6 @@ void Unused_SamusTileViewer(void) { // 0x92ED7A } void DrawSamusSuitExploding(void) { // 0x92EDBE - if (samus_pose_x_dir == 4) - R18_ = g_word_7E0DE4 + 2085; - else - R18_ = g_word_7E0DE4 + 2076; - DrawSamusSpritemap(R18_, samus_x_pos, samus_y_pos); -} \ No newline at end of file + uint16 r18 = (samus_pose_x_dir == 4) ? g_word_7E0DE4 + 2085 : g_word_7E0DE4 + 2076; + DrawSamusSpritemap(r18, samus_x_pos, samus_y_pos); +} diff --git a/src/sm_93.c b/src/sm_93.c index 9b2cffe..329f72e 100644 --- a/src/sm_93.c +++ b/src/sm_93.c @@ -14,14 +14,11 @@ #define kProjInstrList_Explosion (*(ProjectileDamagesAndInstrPtr*)RomFixedPtr(0x938681)) #define g_off_938413 ((uint16*)RomFixedPtr(0x938413)) - - - void InitializeProjectile(uint16 k) { // 0x938000 ProjectileDataTable *ProjectileDataTable; int v1 = k >> 1; - int R18 = 2 * (projectile_dir[v1] & 0xF); + int r18 = 2 * (projectile_dir[v1] & 0xF); uint16 v2 = projectile_type[v1], v3; if ((v2 & 0xF00) != 0) { v3 = kProjectileData_NonBeams[HIBYTE(v2) & 0xF]; @@ -34,7 +31,7 @@ void InitializeProjectile(uint16 k) { // 0x938000 if (sign16(ProjectileDataTable->damage)) InvalidInterrupt_Crash(); projectile_damage[v1] = ProjectileDataTable->damage; - uint16 v7 = GET_WORD(RomPtr_93(v3 + R18 + 2)); + uint16 v7 = GET_WORD(RomPtr_93(v3 + r18 + 2)); projectile_bomb_instruction_ptr[v1] = v7; const uint8 *v8 = RomPtr_93(v7); projectile_x_radius[v1] = v8[4]; @@ -68,7 +65,7 @@ void KillProjectileInner(uint16 k) { // 0x9380CF int v1 = k >> 1; if ((projectile_type[v1] & 0xF00) != 0) { if (!cinematic_function) - QueueSfx2_Max6(7u); + QueueSfx2_Max6(7); uint16 v2 = projectile_type[v1]; projectile_type[v1] = v2 & 0xF0FF | 0x800; if ((v2 & 0x200) != 0) { @@ -83,7 +80,7 @@ void KillProjectileInner(uint16 k) { // 0x9380CF } else { projectile_type[v1] = projectile_type[v1] & 0xF0FF | 0x700; projectile_bomb_instruction_ptr[v1] = HIWORD(g_stru_938679.damages); - QueueSfx2_Max6(0xCu); + QueueSfx2_Max6(0xC); } projectile_bomb_instruction_timers[v1] = 1; projectile_damage[v1] = 8; @@ -97,13 +94,13 @@ void InitializeBombExplosion(uint16 k) { // 0x93814E void InitializeShinesparkEchoOrSpazerSba(uint16 k) { // 0x938163 int v1 = k >> 1; - int R18 = 2 * (projectile_dir[v1] & 0xF); + int r18 = 2 * (projectile_dir[v1] & 0xF); const uint8 *v3 = RomPtr_93(kShinesparkEchoSpazer_ProjectileData[LOBYTE(projectile_type[v1]) - 34]); uint16 v4 = GET_WORD(v3); projectile_damage[v1] = GET_WORD(v3); if (sign16(v4)) InvalidInterrupt_Crash(); - projectile_bomb_instruction_ptr[v1] = GET_WORD(v3 + 2 + R18); + projectile_bomb_instruction_ptr[v1] = GET_WORD(v3 + 2 + r18); projectile_bomb_instruction_timers[v1] = 1; } @@ -118,10 +115,10 @@ void InitializeSbaProjectile(uint16 k) { // 0x9381A4 projectile_bomb_instruction_timers[v1] = 1; } -void ProjectileInsts_GetValue(uint16 k) { // 0x9381D1 +uint16 ProjectileInsts_GetValue(uint16 k) { // 0x9381D1 int ip = projectile_bomb_instruction_ptr[k >> 1]; int delta = (projectile_bomb_instruction_timers[k >> 1] == 1 && !sign16(get_ProjectileInstr(ip)->timer)) ? 0 : -8; - R22_ = get_ProjectileInstr(ip + delta)->field_6; + return get_ProjectileInstr(ip + delta)->field_6; } uint16 CallProj93Instr(uint32 ea, uint16 j, uint16 k) { @@ -134,30 +131,25 @@ uint16 CallProj93Instr(uint32 ea, uint16 j, uint16 k) { } void RunProjectileInstructions(void) { // 0x9381E9 - ProjectileInstr *v7; - ProjectileInstr *ProjectileInstr; + ProjectileInstr *PI; uint16 v0 = projectile_index; int v1 = projectile_index >> 1; if (projectile_bomb_instruction_timers[v1]-- == 1) { - uint16 v3 = projectile_bomb_instruction_ptr[v1], timer; + uint16 v3 = projectile_bomb_instruction_ptr[v1]; while (1) { - ProjectileInstr = get_ProjectileInstr(v3); - timer = ProjectileInstr->timer; - if ((ProjectileInstr->timer & 0x8000u) == 0) + PI = get_ProjectileInstr(v3); + if ((PI->timer & 0x8000) == 0) break; - R18_ = ProjectileInstr->timer; - v3 = CallProj93Instr(timer | 0x930000, v0, v3 + 2); + v3 = CallProj93Instr(PI->timer | 0x930000, v0, v3 + 2); if (!v3) return; } - int v6 = v0 >> 1; - projectile_bomb_instruction_timers[v6] = timer; - v7 = get_ProjectileInstr(v3); - projectile_spritemap_pointers[v6] = v7->spritemap_ptr; - projectile_x_radius[v6] = v7->x_radius; - projectile_y_radius[v6] = v7->y_radius; - projectile_bomb_instruction_ptr[v6] = v3 + 8; + projectile_bomb_instruction_timers[v1] = PI->timer; + projectile_spritemap_pointers[v1] = PI->spritemap_ptr; + projectile_x_radius[v1] = PI->x_radius; + projectile_y_radius[v1] = PI->y_radius; + projectile_bomb_instruction_ptr[v1] = v3 + 8; } } @@ -180,6 +172,7 @@ uint16 Proj93Instr_GotoIfLess(uint16 k, uint16 j) { // 0x938240 void DrawPlayerExplosions2(void) { // 0x938254 uint16 v0 = 8; + uint16 r18, r20; projectile_index = 8; do { int v1 = v0 >> 1; @@ -203,25 +196,23 @@ void DrawPlayerExplosions2(void) { // 0x938254 } else if ((nmi_frame_counter_word & 1) == 0) { goto LABEL_25; } - if ((ceres_status & 0x8000u) == 0) { - R20_ = projectile_x_pos[v1] - layer1_x_pos; + if ((ceres_status & 0x8000) == 0) { + r20 = projectile_x_pos[v1] - layer1_x_pos; v3 = projectile_y_pos[v1] - layer1_y_pos; - R18_ = v3; + r18 = v3; } else { - CalcExplosion_Mode7(v0); - v3 = R18_; + Point16U pt = CalcExplosion_Mode7(v0); + v3 = pt.y; + r20 = pt.x; } - if ((v3 & 0xFF00) != 0) { - if ((projectile_spritemap_pointers[v1] & 0x8000u) != 0){ - } - } else if ((projectile_spritemap_pointers[v1] & 0x8000u) != 0) { - DrawProjectileSpritemap(v0); + if ((v3 & 0xFF00) == 0 && (projectile_spritemap_pointers[v1] & 0x8000) != 0) { + DrawProjectileSpritemap(v0, r20, r18); } v0 = projectile_index; LABEL_25: v0 -= 2; projectile_index = v0; - } while ((v0 & 0x8000u) == 0); + } while ((v0 & 0x8000) == 0); Samus_DrawShinesparkCrashEchoProjectiles(); HandleProjectileTrails(); } @@ -232,22 +223,23 @@ void sub_9382FD(void) { // 0x9382FD do { int v1 = v0 >> 1; if (projectile_bomb_instruction_ptr[v1]) { - R20_ = projectile_x_pos[v1] - layer1_x_pos; - R18_ = projectile_y_pos[v1] - 8 - layer1_y_pos; - if ((R18_ & 0xFF00) != 0) { - } else if ((projectile_spritemap_pointers[v1] & 0x8000u) != 0) { - DrawProjectileSpritemap(v0); + uint16 r20 = projectile_x_pos[v1] - layer1_x_pos; + uint16 r18 = projectile_y_pos[v1] - 8 - layer1_y_pos; + if ((r18 & 0xFF00) != 0) { + } else if ((projectile_spritemap_pointers[v1] & 0x8000) != 0) { + DrawProjectileSpritemap(v0, r20, r18); } v0 = projectile_index; } v0 -= 2; projectile_index = v0; - } while ((v0 & 0x8000u) == 0); + } while ((v0 & 0x8000) == 0); HandleProjectileTrails(); } void DrawBombAndProjectileExplosions(void) { // 0x93834D uint16 v0 = 18, v2; + uint16 r18, r20; projectile_index = 18; do { int v1 = v0 >> 1; @@ -258,25 +250,25 @@ void DrawBombAndProjectileExplosions(void) { // 0x93834D goto LABEL_16; LABEL_9:; uint16 v3 = projectile_x_pos[v1] - layer1_x_pos; - R20_ = v3; + r20 = v3; if (!sign16(v3 - 304) || sign16(v3 + 48)) goto LABEL_16; v2 = projectile_y_pos[v1] - layer1_y_pos; - R18_ = v2; + r18 = v2; goto LABEL_12; } - if ((projectile_type[v1] & 0xF00) == 1280 || (ceres_status & 0x8000u) == 0) + if ((projectile_type[v1] & 0xF00) == 1280 || (ceres_status & 0x8000) == 0) goto LABEL_9; CalcExplosion_Mode7(v0); - v2 = R18_; + v2 = r18; LABEL_12: if ((v2 & 0xFF00) != 0) ; else - DrawProjectileSpritemap(v0); + DrawProjectileSpritemap(v0, r20, r18); v0 = projectile_index; LABEL_16: v0 -= 2; projectile_index = v0; - } while ((v0 & 0x8000u) == 0); -} \ No newline at end of file + } while ((v0 & 0x8000) == 0); +} diff --git a/src/sm_94.c b/src/sm_94.c index b25ea19..3f3781c 100644 --- a/src/sm_94.c +++ b/src/sm_94.c @@ -4,14 +4,56 @@ #include "variables.h" #include "funcs.h" - #define fnkPlmHeaderDefPtrs 0x949139 #define off_9492D9 ((uint16*)RomFixedPtr(0x9492d9)) #define off_9492E9 ((uint16*)RomFixedPtr(0x9492e9)) #define kPlmHeaderDefPtrs ((uint16*)RomFixedPtr(0x949139)) #define off_94936B ((uint16*)RomFixedPtr(0x94936b)) +#define kBlockShotBombedReactionShootablePlm ((uint16 *)RomPtr_94(0x9ea6)) +int32 *cur_coll_amt32; +typedef struct CollInfo { + int32 ci_r18_r20; + uint16 ci_r24; + uint16 ci_r26; + uint16 ci_r28; + uint16 ci_r30; + uint16 ci_r32; + uint16 ci_r38; + uint16 ci_r40; +} CollInfo; + +typedef struct PostGrappleCollInfo { + uint16 pgci_r26; + uint16 pgci_r28; + uint16 pgci_r32; +} PostGrappleCollInfo; + +typedef uint8 Func_CollInfo_U8(CollInfo *ci); +typedef uint16 Func_PostGrappleCollInfo_U16(PostGrappleCollInfo *pgci); + +static uint16 GrappleInstr_Goto(uint16 j); + +static uint16 Samus_GetXposSpan(void); +static uint16 Samus_GetYposSpan(void); +static uint16 BlockFunc_9C73(uint16 k); +static void BlockFunc_A06A(uint16 k); +static void BlockFunc_A0F4(uint16 a, uint16 r22, uint16 r24, uint16 r26, uint16 r28); +static void BlockFunc_A11A(uint16 a, uint16 r24, uint16 r26, uint16 r28); +static void CalculateBlockAt(uint16 r26, uint16 r28, uint16 r30, uint16 r32); +static void BlockBombedReact(CollInfo *ci, uint16 v0); +static void BlockColl_BombExplosion(CollInfo *ci, uint16 k); +static uint8 BlockShotReactHoriz_Slope_Square(CollInfo *ci, uint16 a, uint16 k); +static uint8 BlockShotReactVert_Slope_Square(CollInfo *ci, uint16 a, uint16 k); +static uint8 BlockShotReactHoriz_Slope_NonSquare(CollInfo *ci); +static uint8 BlockShotReactVert_Slope_NonSquare(CollInfo *ci); +static uint8 BlockReact_AA64_SpikeAir(CollInfo *ci); +static uint8 BlockReact_AA64_SpikeBlock(CollInfo *ci); +static void DrawGrappleOams(uint16 x_r20, uint16 y_r24, uint16 chr_r38); +static void DrawGrappleOams3(void); +static uint16 PostGrappleColl_Vert_Solid(PostGrappleCollInfo *pgci); +static uint16 PostGrappleColl_Horiz_Solid(PostGrappleCollInfo *pgci); static const uint8 kAlignPos_Tab1[512] = { 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, @@ -130,117 +172,66 @@ static const uint16 kBlockColl_Horiz_Slope_NonSquare_Tab[64] = { -uint16 PostGrappleColl_Horiz_Slope_NonSquare(uint16 k) { // 0x948000 - int16 v1; - int8 v3; - int16 v5; - int8 v6; - int16 v8; +static uint16 PostGrappleColl_Horiz_Slope_NonSquare(PostGrappleCollInfo *pgci, uint16 k) { // 0x948000 + if (!(samus_collision_direction & 1)) { + if ((samus_x_pos >> 4) != SnesModulus(cur_block_index, room_width_in_blocks)) + return -1; + if ((BTS[k] & 0x40) == 0) + return PostGrappleColl_Horiz_Solid(pgci); + uint16 v3 = samus_y_pos ^ (BTS[k] & 0x80 ? 0xF : 0); + uint16 v4 = 16 * (BTS[k] & 0x1F) + (v3 & 0xF); + int16 result = (kAlignPos_Tab1[v4] & 0x1F) - (pgci->pgci_r32 & 0xF) - 1; + return (result >= 0) ? result : -1; + } else { + if ((samus_x_pos >> 4) != SnesModulus(cur_block_index, room_width_in_blocks)) + return -1; + if (BTS[k] & 0x40) + return PostGrappleColl_Horiz_Solid(pgci); + uint16 v6 = samus_y_pos ^ (BTS[k] & 0x80 ? 0xF : 0); + uint16 v7 = 16 * (BTS[k] & 0x1F) + (v6 & 0xF); + int16 result = (kAlignPos_Tab1[v7] & 0x1F) - (pgci->pgci_r32 & 0xF) - 1; + return (result <= 0) ? ~result : -1; + } +} +static uint16 PostGrappleColl_Vert_Slope_NonSquare(PostGrappleCollInfo *pgci, uint16 k) { // 0x9480E0 if (!(samus_collision_direction & 1)) { uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - v1 = samus_x_pos >> 4; - if (v1 != mod) + if ((samus_x_pos >> 4) != mod) return -1; - uint16 temp_collision_DD4 = R32_ & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[k] & 0x1F); - if ((BTS[k] & 0x40) != 0) { - if (BTS[k] & 0x80) - v3 = samus_y_pos ^ 0xF; - else - v3 = samus_y_pos; - uint16 v4 = temp_collision_DD6 + (v3 & 0xF); - uint16 result = (kAlignPos_Tab1[v4] & 0x1F) - temp_collision_DD4 - 1; - if ((kAlignPos_Tab1[v4] & 0x1F) - temp_collision_DD4 != 1 && (result & 0x8000) != 0) - return -1; - return result; - } - return PostGrappleColl_Horiz_Solid(); + uint16 temp_collision_DD4 = pgci->pgci_r32 & 0xF; + if (!(BTS[k] & 0x80)) + return PostGrappleColl_Vert_Solid(pgci); + uint16 v4 = samus_x_pos ^ ((BTS[k] & 0x40) != 0 ? 0xf : 0); + uint16 v5 = 16 * (BTS[k] & 0x1F) + (v4 & 0xF); + uint16 result = (kAlignYPos_Tab0[v5] & 0x1F) - temp_collision_DD4 - 1; + return ((int16)result >= 0) ? result : -1; } uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - v5 = samus_x_pos >> 4; - if (v5 != mod) + if ((samus_x_pos >> 4) != mod) return -1; - uint16 temp_collision_DD4 = R32_ & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[k] & 0x1F); - if (BTS[k] & 0x40) - return PostGrappleColl_Horiz_Solid(); + uint16 temp_collision_DD4 = pgci->pgci_r32 & 0xF; if (BTS[k] & 0x80) - v6 = samus_y_pos ^ 0xF; - else - v6 = samus_y_pos; - uint16 v7 = temp_collision_DD6 + (v6 & 0xF); - v8 = (kAlignPos_Tab1[v7] & 0x1F) - temp_collision_DD4 - 1; - if ((kAlignPos_Tab1[v7] & 0x1F) - temp_collision_DD4 == 1 || v8 < 0) - return ~v8; - else - return -1; + return PostGrappleColl_Vert_Solid(pgci); + uint16 v8 = samus_x_pos ^ ((BTS[k] & 0x40) != 0 ? 0xf : 0); + uint16 v9 = 16 * (BTS[k] & 0x1F) + (v8 & 0xF); + uint16 v10 = (kAlignYPos_Tab0[v9] & 0x1F) - temp_collision_DD4 - 1; + return ((int16)v10 <= 0) ? ~v10 : -1; } -uint16 PostGrappleColl_Vert_Slope_NonSquare(uint16 k) { // 0x9480E0 - int16 v1; - int16 v3; - int8 v4; - int16 v6; - int16 v7; - int8 v8; - int16 v10; - - if (!(samus_collision_direction & 1)) { - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - v1 = samus_x_pos >> 4; - if (v1 != mod) - return -1; - uint16 temp_collision_DD4 = R32_ & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[k] & 0x1F); - v3 = BTS[k]; - if (v3 & 0x80) { - if ((v3 & 0x40) != 0) - v4 = samus_x_pos ^ 0xF; - else - v4 = samus_x_pos; - uint16 v5 = temp_collision_DD6 + (v4 & 0xF); - uint16 result = (kAlignYPos_Tab0[v5] & 0x1F) - temp_collision_DD4 - 1; - if ((kAlignYPos_Tab0[v5] & 0x1F) - temp_collision_DD4 != 1 && (result & 0x8000) != 0) - return -1; - return result; - } - return PostGrappleColl_Vert_Solid(); - } - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - v6 = samus_x_pos >> 4; - if (v6 != mod) - return -1; - uint16 temp_collision_DD4 = R32_ & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[k] & 0x1F); - v7 = BTS[k]; - if (v7 & 0x80) - return PostGrappleColl_Vert_Solid(); - if ((v7 & 0x40) != 0) - v8 = samus_x_pos ^ 0xF; - else - v8 = samus_x_pos; - uint16 v9 = temp_collision_DD6 + (v8 & 0xF); - v10 = (kAlignYPos_Tab0[v9] & 0x1F) - temp_collision_DD4 - 1; - if ((kAlignYPos_Tab0[v9] & 0x1F) - temp_collision_DD4 == 1 || v10 < 0) - return ~v10; - else - return -1; -} - -uint16 PostGrappleColl_Horiz_Slope_Square(uint16 k) { // 0x9481B8 +static uint16 PostGrappleColl_Horiz_Slope_Square(PostGrappleCollInfo *pgci, uint16 k) { // 0x9481B8 uint16 temp_collision_DD4 = 4 * (BTS[k] & 0x1F); uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v1 = temp_collision_DD4 + (temp_collision_DD6 ^ ((uint8)(R32_ & 8) >> 3)); - if (!R26_) { - if ((((uint8)samus_y_radius + (uint8)samus_y_pos - 1) & 8) == 0) { + uint16 v1 = temp_collision_DD4 + (temp_collision_DD6 ^ ((pgci->pgci_r32 & 8) >> 3)); + if (!pgci->pgci_r26) { + if (((samus_y_radius + samus_y_pos - 1) & 8) == 0) { if (!kTab948E54[v1]) return -1; goto LABEL_10; } goto LABEL_7; } - if (R26_ != R28_ || (((uint8)samus_y_pos - (uint8)samus_y_radius) & 8) == 0) { + if (pgci->pgci_r26 != pgci->pgci_r28 || ((samus_y_pos - samus_y_radius) & 8) == 0) { LABEL_7: if (kTab948E54[v1]) goto LABEL_10; @@ -249,24 +240,24 @@ LABEL_7: return -1; LABEL_10: if (samus_collision_direction & 1) - return R32_ & 7; + return pgci->pgci_r32 & 7; else - return R32_ & 7 ^ 7; + return pgci->pgci_r32 & 7 ^ 7; } -uint16 PostGrappleColl_Vertical_Slope_Square(uint16 k) { // 0x948230 +static uint16 PostGrappleColl_Vertical_Slope_Square(PostGrappleCollInfo *pgci, uint16 k) { // 0x948230 uint16 temp_collision_DD4 = 4 * (BTS[k] & 0x1F); uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v1 = temp_collision_DD4 + (temp_collision_DD6 ^ ((uint8)(R32_ & 8) >> 2)); - if (!R26_) { - if ((((uint8)samus_x_radius + (uint8)samus_x_pos - 1) & 8) == 0) { + uint16 v1 = temp_collision_DD4 + (temp_collision_DD6 ^ ((pgci->pgci_r32 & 8) >> 2)); + if (!pgci->pgci_r26) { + if (((samus_x_radius + samus_x_pos - 1) & 8) == 0) { if (!kTab948E54[v1]) return -1; goto LABEL_10; } goto LABEL_7; } - if (R26_ != R28_ || (((uint8)samus_x_pos - (uint8)samus_x_radius) & 8) == 0) { + if (pgci->pgci_r26 != pgci->pgci_r28 || ((samus_x_pos - samus_x_radius) & 8) == 0) { LABEL_7: if (kTab948E54[v1]) goto LABEL_10; @@ -275,38 +266,38 @@ LABEL_7: return -1; LABEL_10: if (samus_collision_direction & 1) - return R32_ & 7; + return pgci->pgci_r32 & 7; else - return R32_ & 7 ^ 7; + return pgci->pgci_r32 & 7 ^ 7; } -uint16 ClearCarry_0(void) { // 0x9482A7 +static uint16 ClearCarry_0(PostGrappleCollInfo *pgci) { // 0x9482A7 return -1; } -uint16 PostGrappleColl_Horiz_Slope(void) { // 0x9482A9 +static uint16 PostGrappleColl_Horiz_Slope(PostGrappleCollInfo *pgci) { // 0x9482A9 if ((BTS[cur_block_index] & 0x1F) < 5) - return PostGrappleColl_Horiz_Slope_Square(cur_block_index); + return PostGrappleColl_Horiz_Slope_Square(pgci, cur_block_index); else - return PostGrappleColl_Horiz_Slope_NonSquare(cur_block_index); + return PostGrappleColl_Horiz_Slope_NonSquare(pgci, cur_block_index); } -uint16 PostGrappleColl_Horiz_Solid(void) { // 0x9482BE - return R32_ & 0xF; +static uint16 PostGrappleColl_Horiz_Solid(PostGrappleCollInfo *pgci) { // 0x9482BE + return pgci->pgci_r32 & 0xF; } -uint16 PostGrappleColl_Vert_Slope(void) { // 0x9482C5 +static uint16 PostGrappleColl_Vert_Slope(PostGrappleCollInfo *pgci) { // 0x9482C5 if ((BTS[cur_block_index] & 0x1F) < 5) - return PostGrappleColl_Vertical_Slope_Square(cur_block_index); + return PostGrappleColl_Vertical_Slope_Square(pgci, cur_block_index); else - return PostGrappleColl_Vert_Slope_NonSquare(cur_block_index); + return PostGrappleColl_Vert_Slope_NonSquare(pgci, cur_block_index); } -uint16 PostGrappleColl_Vert_Solid(void) { // 0x9482DA - return R32_ & 0xF; +static uint16 PostGrappleColl_Vert_Solid(PostGrappleCollInfo *pgci) { // 0x9482DA + return pgci->pgci_r32 & 0xF; } -static Func_U16 *const kPostGrappleColl_Horiz[16] = { // 0x948321 +static Func_PostGrappleCollInfo_U16 *const kPostGrappleColl_Horiz[16] = { // 0x948321 ClearCarry_0, PostGrappleColl_Horiz_Slope, ClearCarry_0, @@ -324,7 +315,8 @@ static Func_U16 *const kPostGrappleColl_Horiz[16] = { // 0x948321 PostGrappleColl_Horiz_Solid, PostGrappleColl_Horiz_Solid, }; -static Func_U16 *const kPostGrappleColl_Vert[16] = { + +static Func_PostGrappleCollInfo_U16 *const kPostGrappleColl_Vert[16] = { ClearCarry_0, PostGrappleColl_Vert_Slope, ClearCarry_0, @@ -342,118 +334,123 @@ static Func_U16 *const kPostGrappleColl_Vert[16] = { PostGrappleColl_Vert_Solid, PostGrappleColl_Vert_Solid, }; -uint16 PostGrappleColl_Horiz(uint16 k) { + +static uint16 PostGrappleColl_Horiz(PostGrappleCollInfo *pgci, uint16 k) { cur_block_index = k >> 1; - return kPostGrappleColl_Horiz[(uint16)((uint8)((uint16)(level_data[k >> 1] & 0xF000) >> 8) >> 3) >> 1](); + return kPostGrappleColl_Horiz[(level_data[k >> 1] & 0xF000) >> 12](pgci); } -uint16 PostGrappleColl_Vert(uint16 k) { // 0x948338 +static uint16 PostGrappleColl_Vert(PostGrappleCollInfo *pgci, uint16 k) { // 0x948338 cur_block_index = k >> 1; - return kPostGrappleColl_Vert[(uint16)((uint8)((uint16)(level_data[k >> 1] & 0xF000) >> 8) >> 3) >> 1](); + return kPostGrappleColl_Vert[(level_data[k >> 1] & 0xF000) >> 12](pgci); } -void PostGrappleCollisionDetect_Right(void) { // 0x94834F +static void PostGrappleCollisionDetect_Right(void) { // 0x94834F int16 v0; int16 v2; samus_collision_direction = 1; distance_to_eject_samus_left = 0; - Samus_GetYposSpan(); + uint16 r28 = Samus_GetYposSpan(); uint16 prod = Mult8x8((uint16)(samus_y_pos - samus_y_radius) >> 4, room_width_in_blocks); - R22_ = samus_x_subpos; - R24_ = samus_x_pos; - R32_ = samus_x_radius + samus_x_pos - 1; - v0 = R32_ >> 4; +// r22 = samus_x_subpos; + uint16 r24 = samus_x_pos; + uint16 R32 = samus_x_radius + samus_x_pos - 1; + v0 = R32 >> 4; cur_block_index = prod + v0; uint16 v1 = 2 * cur_block_index; + PostGrappleCollInfo pgci = { .pgci_r26 = r28, .pgci_r28 = r28, .pgci_r32 = R32 }; do { - v2 = PostGrappleColl_Horiz(v1); + v2 = PostGrappleColl_Horiz(&pgci, v1); if (v2 >= 0) { uint16 v3 = v2 + 1; if (v3 >= distance_to_eject_samus_left) distance_to_eject_samus_left = v3; } v1 += room_width_in_blocks * 2; - --R26_; - } while ((R26_ & 0x8000) == 0); + --pgci.pgci_r26; + } while ((pgci.pgci_r26 & 0x8000) == 0); } -void PostGrappleCollisionDetect_Left(void) { // 0x9483B1 +static void PostGrappleCollisionDetect_Left(void) { // 0x9483B1 int16 v0; int16 v2; samus_collision_direction = 0; distance_to_eject_samus_right = 0; - Samus_GetYposSpan(); + uint16 r28 = Samus_GetYposSpan(); uint16 prod = Mult8x8((uint16)(samus_y_pos - samus_y_radius) >> 4, room_width_in_blocks); - R22_ = samus_x_subpos; - R24_ = samus_x_pos; - R32_ = samus_x_pos - samus_x_radius; + //r22 = samus_x_subpos; + uint16 r24 = samus_x_pos; + uint16 R32 = samus_x_pos - samus_x_radius; v0 = (uint16)(samus_x_pos - samus_x_radius) >> 4; cur_block_index = prod + v0; uint16 v1 = 2 * cur_block_index; + PostGrappleCollInfo pgci = { .pgci_r26 = r28, .pgci_r28 = r28, .pgci_r32 = R32 }; do { - v2 = PostGrappleColl_Horiz(v1); + v2 = PostGrappleColl_Horiz(&pgci, v1); if (v2 >= 0) { uint16 v3 = v2 + 1; if (v3 >= distance_to_eject_samus_right) distance_to_eject_samus_right = v3; } v1 += room_width_in_blocks * 2; - --R26_; - } while ((R26_ & 0x8000) == 0); + --pgci.pgci_r26; + } while ((pgci.pgci_r26 & 0x8000) == 0); } -void PostGrappleCollisionDetect_Down(void) { // 0x94840F +static void PostGrappleCollisionDetect_Down(void) { // 0x94840F int16 v0; int16 v2; samus_collision_direction = 3; distance_to_eject_samus_up = 0; - Samus_GetXposSpan(); - R22_ = samus_y_subpos; - R24_ = samus_y_pos; - R32_ = samus_y_radius + samus_y_pos - 1; - uint16 prod = Mult8x8(R32_ >> 4, room_width_in_blocks); + uint16 r28 = Samus_GetXposSpan(); + //r22 = samus_y_subpos; + uint16 r24 = samus_y_pos; + uint16 R32 = samus_y_radius + samus_y_pos - 1; + uint16 prod = Mult8x8(R32 >> 4, room_width_in_blocks); v0 = (uint16)(samus_x_pos - samus_x_radius) >> 4; cur_block_index = prod + v0; uint16 v1 = 2 * cur_block_index; + PostGrappleCollInfo pgci = { .pgci_r26 = r28, .pgci_r28 = r28, .pgci_r32 = R32 }; do { - v2 = PostGrappleColl_Vert(v1); + v2 = PostGrappleColl_Vert(&pgci, v1); if (v2 >= 0) { uint16 v3 = v2 + 1; if (v3 >= distance_to_eject_samus_up) distance_to_eject_samus_up = v3; } v1 += 2; - --R26_; - } while ((R26_ & 0x8000) == 0); + --pgci.pgci_r26; + } while ((pgci.pgci_r26 & 0x8000) == 0); } -void PostGrappleCollisionDetect_Up(void) { // 0x94846A +static void PostGrappleCollisionDetect_Up(void) { // 0x94846A int16 v0; int16 v2; samus_collision_direction = 2; distance_to_eject_samus_down = 0; - Samus_GetXposSpan(); - R22_ = samus_y_subpos; - R24_ = samus_y_pos; - R32_ = samus_y_pos - samus_y_radius; + uint16 r28 = Samus_GetXposSpan(); + //r22 = samus_y_subpos; + uint16 r24 = samus_y_pos; + uint16 R32 = samus_y_pos - samus_y_radius; uint16 prod = Mult8x8((uint16)(samus_y_pos - samus_y_radius) >> 4, room_width_in_blocks); v0 = (uint16)(samus_x_pos - samus_x_radius) >> 4; cur_block_index = prod + v0; uint16 v1 = 2 * cur_block_index; + PostGrappleCollInfo pgci = { .pgci_r26 = r28, .pgci_r28 = r28, .pgci_r32 = R32 }; do { - v2 = PostGrappleColl_Vert(v1); + v2 = PostGrappleColl_Vert(&pgci, v1); if (v2 >= 0) { uint16 v3 = v2 + 1; if (v3 >= distance_to_eject_samus_down) distance_to_eject_samus_down = v3; } v1 += 2; - --R26_; - } while ((R26_ & 0x8000) == 0); + --pgci.pgci_r26; + } while ((pgci.pgci_r26 & 0x8000) == 0); } void PostGrappleCollisionDetect_X(void) { // 0x9484C4 @@ -466,83 +463,51 @@ void PostGrappleCollisionDetect_Y(void) { // 0x9484CD PostGrappleCollisionDetect_Up(); } -uint8 BlockColl_Horiz_Slope_NonSquare(void) { // 0x9484D6 +static uint8 BlockColl_Horiz_Slope_NonSquare(CollInfo *ci) { // 0x9484D6 if ((current_slope_bts & 0x80) != 0 || __PAIR32__(samus_y_speed, samus_y_subspeed)) return 0; uint16 v1 = 4 * (current_slope_bts & 0x1F); - uint16 v2 = PAIR16(R18_, HIBYTE(R20_)); - if ((R18_ & 0x8000) == 0) { - Multiply16x16(v2, kBlockColl_Horiz_Slope_NonSquare_Tab[(v1 >> 1) + 1]); - R20_ = mult_product_lo; - R18_ = mult_product_hi; + uint16 v2 = ci->ci_r18_r20 >> 8; + if (ci->ci_r18_r20 >= 0) { + ci->ci_r18_r20 = Multiply16x16(v2, kBlockColl_Horiz_Slope_NonSquare_Tab[(v1 >> 1) + 1]); } else { - Multiply16x16(-v2, kBlockColl_Horiz_Slope_NonSquare_Tab[(v1 >> 1) + 1]); - Negate32(&mult_product_hi, &mult_product_lo, &R18_, &R20_); + ci->ci_r18_r20 = -(int32)Multiply16x16(-v2, kBlockColl_Horiz_Slope_NonSquare_Tab[(v1 >> 1) + 1]); } return 0; } -uint8 BlockColl_Vert_Slope_NonSquare(uint16 k) { // 0x9486FE - int16 v1; - int16 v3; - int8 v4; - uint16 v5; - int16 v6; - int16 v7; - int16 v8; - int16 v9; - int8 v10; - uint16 v11; - int16 v12; - int16 v13; - +static uint8 BlockColl_Vert_Slope_NonSquare(CollInfo *ci, uint16 k) { // 0x9486FE if (samus_collision_direction & 1) { - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - v8 = samus_x_pos >> 4; - if (v8 == mod) { - uint16 temp_collision_DD4 = ((uint8)samus_y_radius + (uint8)R24_ - 1) & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[k] & 0x1F); - v9 = BTS[k]; - if (!(v9 & 0x80) - && ((v9 & 0x40) != 0 ? (v10 = samus_x_pos ^ 0xF) : (v10 = samus_x_pos), - (v11 = temp_collision_DD6 + (v10 & 0xF), - v12 = (kAlignYPos_Tab0[v11] & 0x1F) - temp_collision_DD4 - 1, - (kAlignYPos_Tab0[v11] & 0x1F) - temp_collision_DD4 == 1) - || v12 < 0)) { - v13 = R18_ + v12; - if (v13 < 0) - v13 = 0; - R18_ = v13; - R20_ = 0; - return 1; - } else { - return 0; - } + if ((samus_x_pos >> 4) != SnesModulus(cur_block_index, room_width_in_blocks)) + return 0; + if (BTS[k] & 0x80) + return 0; + uint16 v10 = (BTS[k] & 0x40) != 0 ? samus_x_pos ^ 0xF : samus_x_pos; + uint16 v11 = 16 * (BTS[k] & 0x1F) + (v10 & 0xF); + int16 v12 = (kAlignYPos_Tab0[v11] & 0x1F) - ((samus_y_radius + ci->ci_r24 - 1) & 0xF) - 1; + if (v12 <= 0) { + int16 v13 = (ci->ci_r18_r20 >> 16) + v12; + if (v13 < 0) + v13 = 0; + ci->ci_r18_r20 = v13 << 16; + return 1; } else { return 0; } } else { - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - v1 = samus_x_pos >> 4; - if (v1 == mod) { - uint16 temp_collision_DD4 = ((uint8)R24_ - (uint8)samus_y_radius) & 0xF ^ 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[k] & 0x1F); - v3 = BTS[k]; - if ((v3 & 0x80) - && ((v3 & 0x40) != 0 ? (v4 = samus_x_pos ^ 0xF) : (v4 = samus_x_pos), - (v5 = temp_collision_DD6 + (v4 & 0xF), - v6 = (kAlignYPos_Tab0[v5] & 0x1F) - temp_collision_DD4 - 1, - (kAlignYPos_Tab0[v5] & 0x1F) - temp_collision_DD4 == 1) - || v6 < 0)) { - v7 = R18_ + v6; - if (v7 < 0) - v7 = 0; - R18_ = v7; - R20_ = 0; - return 1; - } else { - return 0; - } + if ((samus_x_pos >> 4) != SnesModulus(cur_block_index, room_width_in_blocks)) + return 0; + if (!(BTS[k] & 0x80)) + return 0; + uint16 v4 = (BTS[k] & 0x40) != 0 ? (samus_x_pos ^ 0xF) : (samus_x_pos); + uint16 v5 = 16 * (BTS[k] & 0x1F) + (v4 & 0xF); + int16 v6 = (kAlignYPos_Tab0[v5] & 0x1F) - ((ci->ci_r24 - samus_y_radius) & 0xF ^ 0xF) - 1; + if (v6 <= 0) { + int16 v7 = (ci->ci_r18_r20 >> 16) + v6; + if (v7 < 0) + v7 = 0; + ci->ci_r18_r20 = v7 << 16; + return 1; } else { return 0; } @@ -550,58 +515,55 @@ uint8 BlockColl_Vert_Slope_NonSquare(uint16 k) { // 0x9486FE } void Samus_AlignYPosSlope(void) { // 0x9487F4 - if ((enable_horiz_slope_coll & 2) != 0) { - R26_ = samus_x_pos; - R28_ = samus_y_radius + samus_y_pos - 1; - CalculateBlockAt(R26_, R28_, 0, 0); - if ((level_data[cur_block_index] & 0xF000) == 4096 && (BTS[cur_block_index] & 0x1F) >= 5) { - uint16 temp_collision_DD4 = (samus_y_radius + samus_y_pos - 1) & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[cur_block_index] & 0x1F); - uint8 v0 = BTS[cur_block_index]; - if (!(v0 & 0x80)) { - uint16 v1 = (v0 & 0x40) != 0 ? samus_x_pos ^ 0xF : samus_x_pos; - uint16 v2 = (kAlignYPos_Tab0[temp_collision_DD6 + (v1 & 0xF)] & 0x1F) - temp_collision_DD4 - 1; - if ((int16)v2 < 0) { - samus_y_pos += v2; - samus_pos_adjusted_by_slope_flag = 1; - } + if ((enable_horiz_slope_coll & 2) == 0) + return; + uint16 r26 = samus_x_pos; + uint16 R28 = samus_y_radius + samus_y_pos - 1; + CalculateBlockAt(r26, R28, 0, 0); + if ((level_data[cur_block_index] & 0xF000) == 4096 && (BTS[cur_block_index] & 0x1F) >= 5) { + uint16 temp_collision_DD4 = (samus_y_radius + samus_y_pos - 1) & 0xF; + uint16 temp_collision_DD6 = 16 * (BTS[cur_block_index] & 0x1F); + uint8 v0 = BTS[cur_block_index]; + if (!(v0 & 0x80)) { + uint16 v1 = (v0 & 0x40) != 0 ? samus_x_pos ^ 0xF : samus_x_pos; + uint16 v2 = (kAlignYPos_Tab0[temp_collision_DD6 + (v1 & 0xF)] & 0x1F) - temp_collision_DD4 - 1; + if ((int16)v2 < 0) { + samus_y_pos += v2; + samus_pos_adjusted_by_slope_flag = 1; } } - R26_ = samus_x_pos; - R28_ = samus_y_pos - samus_y_radius; - CalculateBlockAt(R26_, R28_, 0, 0); - if ((level_data[cur_block_index] & 0xF000) == 4096 && (BTS[cur_block_index] & 0x1F) >= 5) { - uint16 temp_collision_DD4 = (samus_y_pos - samus_y_radius) & 0xF ^ 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[cur_block_index] & 0x1F); - uint8 v3 = BTS[cur_block_index]; - if (v3 & 0x80) { - uint16 v4 = (v3 & 0x40) != 0 ? samus_x_pos ^ 0xF : samus_x_pos; - uint16 v6 = (kAlignYPos_Tab0[temp_collision_DD6 + (v4 & 0xF)] & 0x1F) - temp_collision_DD4 - 1; - if ((int16)v6 <= 0) { - samus_y_pos -= v6; - samus_pos_adjusted_by_slope_flag = 1; - } + } + r26 = samus_x_pos; + R28 = samus_y_pos - samus_y_radius; + CalculateBlockAt(r26, R28, 0, 0); + if ((level_data[cur_block_index] & 0xF000) == 4096 && (BTS[cur_block_index] & 0x1F) >= 5) { + uint16 temp_collision_DD4 = (samus_y_pos - samus_y_radius) & 0xF ^ 0xF; + uint16 temp_collision_DD6 = 16 * (BTS[cur_block_index] & 0x1F); + uint8 v3 = BTS[cur_block_index]; + if (v3 & 0x80) { + uint16 v4 = (v3 & 0x40) != 0 ? samus_x_pos ^ 0xF : samus_x_pos; + uint16 v6 = (kAlignYPos_Tab0[temp_collision_DD6 + (v4 & 0xF)] & 0x1F) - temp_collision_DD4 - 1; + if ((int16)v6 <= 0) { + samus_y_pos -= v6; + samus_pos_adjusted_by_slope_flag = 1; } } } } -uint8 BlockColl_Horiz_Slope_Square(uint16 a, uint16 k) { // 0x948D2B - int16 v4; - int16 v5; - +static uint8 BlockColl_Horiz_Slope_Square(CollInfo *ci, uint16 a, uint16 k) { // 0x948D2B uint16 temp_collision_DD4 = 4 * a; uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R32_ & 8) >> 3)); - if (!R26_) { - if ((((uint8)samus_y_radius + (uint8)samus_y_pos - 1) & 8) == 0) { + uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((ci->ci_r32 & 8) >> 3)); + if (!ci->ci_r26) { + if (((samus_y_radius + samus_y_pos - 1) & 8) == 0) { if (!kTab948E54[v2]) return 0; goto LABEL_10; } goto LABEL_7; } - if (R26_ != R28_ || (((uint8)samus_y_pos - (uint8)samus_y_radius) & 8) == 0) { + if (ci->ci_r26 != ci->ci_r28 || ((samus_y_pos - samus_y_radius) & 8) == 0) { LABEL_7: if (kTab948E54[v2]) goto LABEL_10; @@ -609,40 +571,36 @@ LABEL_7: if (!kTab948E54[v2 ^ 2]) return 0; LABEL_10: - R20_ = 0; - if ((R18_ & 0x8000) != 0) { - v5 = samus_x_radius + (R32_ | 7) + 1 - samus_x_pos; + if (ci->ci_r18_r20 < 0) { + int16 v5 = samus_x_radius + (ci->ci_r32 | 7) + 1 - samus_x_pos; if (v5 >= 0) v5 = 0; - R18_ = v5; + ci->ci_r18_r20 = v5 << 16; samus_x_subpos = 0; - return 1; } else { - v4 = (__PAIR32__((R32_ & 0xFFF8) - samus_x_radius, R32_ & 0xFFF8) - __PAIR32__(samus_x_pos, samus_x_radius)) >> 16; + // todo: carry + int16 v4 = (__PAIR32__((ci->ci_r32 & 0xFFF8) - samus_x_radius, ci->ci_r32 & 0xFFF8) - __PAIR32__(samus_x_pos, samus_x_radius)) >> 16; if (v4 < 0) v4 = 0; - R18_ = v4; + ci->ci_r18_r20 = v4 << 16; samus_x_subpos = -1; - return 1; } + return 1; } -uint8 BlockColl_Vert_Slope_Square(uint16 a, uint16 k) { // 0x948DBD - int16 v4; - int16 v5; - +static uint8 BlockColl_Vert_Slope_Square(CollInfo *ci, uint16 a, uint16 k) { // 0x948DBD uint16 temp_collision_DD4 = 4 * a; uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R32_ & 8) >> 2)); - if (!R26_) { - if ((((uint8)samus_x_radius + (uint8)samus_x_pos - 1) & 8) == 0) { + uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((ci->ci_r32 & 8) >> 2)); + if (!ci->ci_r26) { + if (((samus_x_radius + samus_x_pos - 1) & 8) == 0) { if (!kTab948E54[v2]) return 0; goto LABEL_10; } goto LABEL_7; } - if (R26_ != R28_ || (((uint8)samus_x_pos - (uint8)samus_x_radius) & 8) == 0) { + if (ci->ci_r26 != ci->ci_r28 || ((samus_x_pos - samus_x_radius) & 8) == 0) { LABEL_7: if (kTab948E54[v2]) goto LABEL_10; @@ -650,142 +608,133 @@ LABEL_7: if (!kTab948E54[v2 ^ 1]) return 0; LABEL_10: - R20_ = 0; - if ((R18_ & 0x8000) != 0) { - v5 = samus_y_radius + (R32_ | 7) + 1 - samus_y_pos; + if (ci->ci_r18_r20 < 0) { + int16 v5 = samus_y_radius + (ci->ci_r32 | 7) + 1 - samus_y_pos; if (v5 >= 0) v5 = 0; - R18_ = v5; + ci->ci_r18_r20 = v5 << 16; samus_y_subpos = 0; return 1; } else { - v4 = (__PAIR32__((R32_ & 0xFFF8) - samus_y_radius, R32_ & 0xFFF8) - __PAIR32__(samus_y_pos, samus_y_radius)) >> 16; + // todo: fix carry + int16 v4 = (__PAIR32__((ci->ci_r32 & 0xFFF8) - samus_y_radius, ci->ci_r32 & 0xFFF8) - __PAIR32__(samus_y_pos, samus_y_radius)) >> 16; if (v4 < 0) v4 = 0; - R18_ = v4; + ci->ci_r18_r20 = v4 << 16; samus_y_subpos = -1; samus_pos_adjusted_by_slope_flag = 1; return 1; } } - -uint8 ClearCarry_1(void) { // 0x948E7D +static uint8 ClearCarry_1(CollInfo *ci) { // 0x948E7D return 0; } -uint8 ClearCarry_2(void) { // 0x948E7F +static uint8 ClearCarry_2(CollInfo *ci) { // 0x948E7F return 0; } -uint8 ClearCarry_3(void) { // 0x948E81 +static uint8 ClearCarry_3(CollInfo *ci) { // 0x948E81 return 0; } -void BlockColl_SpikeBlock_BTS0(void) { // 0x948E83 - if ((area_index != 3 || CheckBossBitForCurArea(1u) & 1) && !samus_invincibility_timer) { +static void BlockColl_SpikeBlock_BTS0(void) { // 0x948E83 + if ((area_index != 3 || CheckBossBitForCurArea(1) & 1) && !samus_invincibility_timer) { samus_invincibility_timer = 60; samus_knockback_timer = 10; samus_periodic_damage += 60; - knockback_x_dir = ((*(uint16 *)&samus_pose_x_dir ^ 0xC) & 8) != 0; + knockback_x_dir = ((samus_pose_x_dir ^ 0xC) & 8) != 0; } } -void BlockColl_SpikeBlock_BTS1(void) { // 0x948ECF +static void BlockColl_SpikeBlock_BTS1(void) { // 0x948ECF if (!samus_invincibility_timer) { samus_invincibility_timer = 60; samus_knockback_timer = 10; samus_periodic_damage += 16; - knockback_x_dir = ((*(uint16 *)&samus_pose_x_dir ^ 0xC) & 8) != 0; + knockback_x_dir = ((samus_pose_x_dir ^ 0xC) & 8) != 0; } } -void BlockColl_SpikeBlock_BTS3(void) { // 0x948F0A +static void BlockColl_SpikeBlock_BTS3(void) { // 0x948F0A if (!samus_invincibility_timer) { samus_invincibility_timer = 60; samus_knockback_timer = 10; samus_periodic_damage += 16; - knockback_x_dir = ((*(uint16 *)&samus_pose_x_dir ^ 0xC) & 8) != 0; + knockback_x_dir = ((samus_pose_x_dir ^ 0xC) & 8) != 0; } } -uint8 SetCarry(void) { +static uint8 SetCarry(CollInfo *ci) { return 1; } -uint8 ClearCarry_4(void) { // 0x948F47 +static uint8 ClearCarry_4(CollInfo *ci) { // 0x948F47 return 0; } -uint8 BlockColl_Horiz_SolidShootGrappleBlock(void) { // 0x948F49 - int16 v0; - int16 v2; - - R20_ = 0; - if ((R18_ & 0x8000) != 0) { - v2 = samus_x_radius + (R32_ | 0xF) + 1 - samus_x_pos; +static uint8 BlockColl_Horiz_SolidShootGrappleBlock(CollInfo *ci) { // 0x948F49 + if (ci->ci_r18_r20 < 0) { + int16 v2 = samus_x_radius + (ci->ci_r32 | 0xF) + 1 - samus_x_pos; if (v2 >= 0) v2 = 0; - R18_ = v2; + ci->ci_r18_r20 = v2 << 16; samus_x_subpos = 0; return 1; } else { - v0 = (R32_ & 0xFFF0) - samus_x_radius - samus_x_pos; + int16 v0 = (ci->ci_r32 & 0xFFF0) - samus_x_radius - samus_x_pos; if (v0 < 0) v0 = 0; - R18_ = v0; + ci->ci_r18_r20 = v0 << 16; samus_x_subpos = -1; return 1; } } -uint8 BlockColl_Vert_SolidShootGrappleBlock(void) { // 0x948F82 - int16 v0; - int16 v2; - - R20_ = 0; - if ((R18_ & 0x8000) != 0) { - v2 = samus_y_radius + (R32_ | 0xF) + 1 - samus_y_pos; +static uint8 BlockColl_Vert_SolidShootGrappleBlock(CollInfo *ci) { // 0x948F82 + if (ci->ci_r18_r20 < 0) { + int16 v2 = samus_y_radius + (ci->ci_r32 | 0xF) + 1 - samus_y_pos; if (v2 >= 0) v2 = 0; - R18_ = v2; + ci->ci_r18_r20 = v2 << 16; samus_y_subpos = 0; return 1; } else { - v0 = (R32_ & 0xFFF0) - samus_y_radius - samus_y_pos; + int16 v0 = (ci->ci_r32 & 0xFFF0) - samus_y_radius - samus_y_pos; if (v0 < 0) v0 = 0; - R18_ = v0; + ci->ci_r18_r20 = v0 << 16; samus_y_subpos = -1; return 1; } } -uint8 BlockColl_Horiz_Slope(void) { // 0x948FBB +static uint8 BlockColl_Horiz_Slope(CollInfo *ci) { // 0x948FBB uint16 v0 = BTS[cur_block_index] & 0x1F; - if (v0 < 5u) - return BlockColl_Horiz_Slope_Square(v0, cur_block_index); + if (v0 < 5) + return BlockColl_Horiz_Slope_Square(ci, v0, cur_block_index); current_slope_bts = BTS[cur_block_index]; - return BlockColl_Horiz_Slope_NonSquare(); + return BlockColl_Horiz_Slope_NonSquare(ci); } -uint8 BlockColl_Vert_Slope(void) { // 0x948FDA +static uint8 BlockColl_Vert_Slope(CollInfo *ci) { // 0x948FDA uint16 v0 = BTS[cur_block_index] & 0x1F; - if (v0 < 5u) - return BlockColl_Vert_Slope_Square(v0, cur_block_index); - current_slope_bts = *(uint16 *)&BTS[cur_block_index]; - return BlockColl_Vert_Slope_NonSquare(cur_block_index); + if (v0 < 5) + return BlockColl_Vert_Slope_Square(ci, v0, cur_block_index); + current_slope_bts = BTS[cur_block_index]; + return BlockColl_Vert_Slope_NonSquare(ci, cur_block_index); } -uint8 ClearCarry_5(void) { // 0x949018 +static uint8 ClearCarry_5(CollInfo *ci) { // 0x949018 return 0; } -uint8 BlockColl_Vert_SpikeAir(void) { // 0x94901A +static uint8 BlockColl_Vert_SpikeAir(CollInfo *ci) { // 0x94901A return 0; } -void SetCarry_Spikeblk(void) { +static void SetCarry_Spikeblk(void) { } static Func_V *const kBlockColl_SpikeBlock[16] = { // 0x94904B @@ -807,20 +756,18 @@ static Func_V *const kBlockColl_SpikeBlock[16] = { // 0x94904B SetCarry_Spikeblk, }; -uint8 BlockColl_Horiz_SpikeBlock(void) { - kBlockColl_SpikeBlock[(uint16)((2 * *(uint16 *)&BTS[cur_block_index]) & 0x1FF) >> 1](); - return BlockColl_Horiz_SolidShootGrappleBlock(); +static uint8 BlockColl_Horiz_SpikeBlock(CollInfo *ci) { + kBlockColl_SpikeBlock[BTS[cur_block_index]](); + return BlockColl_Horiz_SolidShootGrappleBlock(ci); } -uint8 BlockColl_Vert_SpikeBlock(void) { // 0x94905D - kBlockColl_SpikeBlock[(uint16)((2 * *(uint16 *)&BTS[cur_block_index]) & 0x1FF) >> 1](); - return BlockColl_Vert_SolidShootGrappleBlock(); +static uint8 BlockColl_Vert_SpikeBlock(CollInfo *ci) { // 0x94905D + kBlockColl_SpikeBlock[BTS[cur_block_index]](); + return BlockColl_Vert_SolidShootGrappleBlock(ci); } -uint8 BlockColl_Horiz_SpecialAir(void) { // 0x94906F - int16 v0; - - v0 = BTS[cur_block_index]; +static uint8 BlockColl_Horiz_SpecialAir(CollInfo *ci) { // 0x94906F + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) { const uint16 *v2 = (const uint16 *)RomPtr_94(off_9492D9[area_index]); return SpawnPLM(v2[v0 & 0x7f]) & 1; @@ -830,10 +777,8 @@ uint8 BlockColl_Horiz_SpecialAir(void) { // 0x94906F } } -uint8 BlockColl_Vert_SpecialAir(void) { // 0x94909D - int16 v0; - - v0 = BTS[cur_block_index]; +static uint8 BlockColl_Vert_SpecialAir(CollInfo *ci) { // 0x94909D + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) { const uint16 *v2 = (const uint16 *)RomPtr_94(off_9492D9[area_index]); return SpawnPLM(v2[v0 & 0x7f]) & 1; @@ -843,87 +788,83 @@ uint8 BlockColl_Vert_SpecialAir(void) { // 0x94909D } } -uint8 BlockColl_Horiz_SpecialBlock(void) { // 0x9490CB - int16 v0; - - v0 = BTS[cur_block_index]; +static uint8 BlockColl_Horiz_SpecialBlock(CollInfo *ci) { // 0x9490CB + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) { const uint16 *v2 = (const uint16 *)RomPtr_94(off_9492E9[area_index]); uint8 v4 = SpawnPLM(v2[v0 & 0x7f]) & 1; if (v4) - return BlockColl_Horiz_SolidShootGrappleBlock(); + return BlockColl_Horiz_SolidShootGrappleBlock(ci); return v4; } else { uint8 v1 = SpawnPLM(kPlmHeaderDefPtrs[v0]) & 1; if (v1) - return BlockColl_Horiz_SolidShootGrappleBlock(); + return BlockColl_Horiz_SolidShootGrappleBlock(ci); return v1; } } -uint8 BlockColl_Vert_SpecialBlock(void) { // 0x949102 - int16 v0; - - v0 = BTS[cur_block_index]; +static uint8 BlockColl_Vert_SpecialBlock(CollInfo *ci) { // 0x949102 + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) { const uint16 *v3 = (const uint16 *)RomPtr_94(off_9492E9[area_index]); uint8 v4 = SpawnPLM(v3[v0 & 0x7F]) & 1; if (v4) - return BlockColl_Vert_SolidShootGrappleBlock(); + return BlockColl_Vert_SolidShootGrappleBlock(ci); return v4; } else { uint8 v1 = SpawnPLM(kPlmHeaderDefPtrs[v0]) & 1; if (v1) - return BlockColl_Vert_SolidShootGrappleBlock(); + return BlockColl_Vert_SolidShootGrappleBlock(ci); return v1; } } -uint8 BlockColl_Horiz_BombableAir(void) { // 0x9492F9 - uint16 v0 = BTS[cur_block_index]; +static uint8 BlockColl_Horiz_BombableAir(CollInfo *ci) { // 0x9492F9 + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) == 0) SpawnPLM(off_94936B[v0]); return 0; } -uint8 BlockColl_Vert_BombableAir(void) { // 0x949313 - uint16 v0 = BTS[cur_block_index]; +static uint8 BlockColl_Vert_BombableAir(CollInfo *ci) { // 0x949313 + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) == 0) SpawnPLM(off_94936B[v0]); return 0; } -uint8 BlockColl_Horiz_BombBlock(void) { // 0x94932D - uint16 v0 = BTS[cur_block_index]; +static uint8 BlockColl_Horiz_BombBlock(CollInfo *ci) { // 0x94932D + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) - return BlockColl_Horiz_SolidShootGrappleBlock(); + return BlockColl_Horiz_SolidShootGrappleBlock(ci); uint8 v1 = SpawnPLM(off_94936B[v0]) & 1; if (v1) - return BlockColl_Horiz_SolidShootGrappleBlock(); + return BlockColl_Horiz_SolidShootGrappleBlock(ci); else return v1; } -uint8 BlockColl_Vert_BombBlock(void) { // 0x94934C - uint16 v0 = BTS[cur_block_index]; +static uint8 BlockColl_Vert_BombBlock(CollInfo *ci) { // 0x94934C + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) - return BlockColl_Vert_SolidShootGrappleBlock(); + return BlockColl_Vert_SolidShootGrappleBlock(ci); uint8 v1 = SpawnPLM(off_94936B[v0]) & 1; if (v1) - return BlockColl_Vert_SolidShootGrappleBlock(); + return BlockColl_Vert_SolidShootGrappleBlock(ci); else return v1; } -uint8 BlockColl_Horiz_Door(void) { // 0x94938B +uint8 BlockColl_Horiz_Door(CollInfo *ci) { // 0x94938B door_transition_function = FUNC16(DoorTransitionFunction_HandleElevator); door_bts = BTS[cur_block_index]; uint16 v0 = *(uint16 *)RomPtr_8F(door_list_pointer + 2 * (door_bts & 0x7F)); if ((get_DoorDef(v0)->room_definition_ptr & 0x8000) == 0) { if (samus_pose < kGameState_9_HitDoorBlock) elevator_flags = 1; - return BlockColl_Horiz_SolidShootGrappleBlock(); + return BlockColl_Horiz_SolidShootGrappleBlock(ci); } else { door_def_ptr = v0; game_state = kGameState_9_HitDoorBlock; @@ -931,14 +872,14 @@ uint8 BlockColl_Horiz_Door(void) { // 0x94938B } } -uint8 BlockColl_Vert_Door(void) { // 0x9493CE +uint8 BlockColl_Vert_Door(CollInfo *ci) { // 0x9493CE door_transition_function = FUNC16(DoorTransitionFunction_HandleElevator); door_bts = BTS[cur_block_index]; uint16 v0 = *(uint16 *)RomPtr_8F(door_list_pointer + 2 * (door_bts & 0x7F)); if ((get_DoorDef(v0)->room_definition_ptr & 0x8000) == 0) { if (samus_pose < kPose_09_MoveR_NoAim) elevator_flags = 1; - return BlockColl_Vert_SolidShootGrappleBlock(); + return BlockColl_Vert_SolidShootGrappleBlock(ci); } else { door_def_ptr = v0; game_state = kPose_09_MoveR_NoAim; @@ -946,52 +887,35 @@ uint8 BlockColl_Vert_Door(void) { // 0x9493CE } } -uint8 BlockReact_HorizExt(void) { // 0x949411 - uint8 t = BTS[cur_block_index]; - if (t) { - cur_block_index += (int8)t; - return 0xff; // special - } - return 0; -} - -uint8 BlockReact_VertExt(void) { // 0x949447 - uint16 v0; +static uint8 BlockReact_HorizExt(CollInfo *ci) { // 0x949411 if (BTS[cur_block_index]) { - if ((BTS[cur_block_index] & 0x80) != 0) { - uint16 temp_collision_DD4 = BTS[cur_block_index] | 0xFF00; - v0 = cur_block_index; - do { - v0 -= room_width_in_blocks; - ++temp_collision_DD4; - } while (temp_collision_DD4); - } else { - uint16 temp_collision_DD4 = BTS[cur_block_index]; - v0 = cur_block_index; - do { - v0 += room_width_in_blocks; - --temp_collision_DD4; - } while (temp_collision_DD4); - } - cur_block_index = v0; + cur_block_index += (int8)BTS[cur_block_index]; return 0xff; // special } return 0; } -void Samus_GetYposSpan(void) { // 0x949495 - R26_ = (samus_y_pos - samus_y_radius) & 0xFFF0; - R26_ = (uint16)(samus_y_radius + samus_y_pos - 1 - R26_) >> 4; - R28_ = R26_; +static uint8 BlockReact_VertExt(CollInfo *ci) { // 0x949447 + if (BTS[cur_block_index]) { + cur_block_index += (int8)BTS[cur_block_index] * room_width_in_blocks; + return 0xff; // special + } + return 0; } -void Samus_GetXposSpan(void) { // 0x9494B5 - R26_ = (samus_x_pos - samus_x_radius) & 0xFFF0; - R26_ = (uint16)(samus_x_radius + samus_x_pos - 1 - R26_) >> 4; - R28_ = R26_; +static uint16 Samus_GetYposSpan(void) { // 0x949495 + uint16 r26 = (samus_y_pos - samus_y_radius) & 0xFFF0; + r26 = (uint16)(samus_y_radius + samus_y_pos - 1 - r26) >> 4; + return r26; } -static Func_U8 *const kBlockColl_Horiz_CheckColl[16] = { // 0x949515 +static uint16 Samus_GetXposSpan(void) { // 0x9494B5 + uint16 r26 = (samus_x_pos - samus_x_radius) & 0xFFF0; + r26 = (uint16)(samus_x_radius + samus_x_pos - 1 - r26) >> 4; + return r26; +} + +static Func_CollInfo_U8 *const kBlockColl_Horiz_CheckColl[16] = { // 0x949515 ClearCarry_4, BlockColl_Horiz_Slope, ClearCarry_5, @@ -1009,7 +933,8 @@ static Func_U8 *const kBlockColl_Horiz_CheckColl[16] = { // 0x949515 BlockColl_Horiz_SolidShootGrappleBlock, BlockColl_Horiz_BombBlock, }; -static Func_U8 *const kBlockColl_Vert_CheckColl[16] = { + +static Func_CollInfo_U8 *const kBlockColl_Vert_CheckColl[16] = { ClearCarry_4, BlockColl_Vert_Slope, BlockColl_Vert_SpikeAir, @@ -1028,270 +953,163 @@ static Func_U8 *const kBlockColl_Vert_CheckColl[16] = { BlockColl_Vert_BombBlock, }; -uint8 BlockColl_Horiz_CheckColl(uint16 k) { +static uint8 BlockColl_Horiz_CheckColl(CollInfo *ci, uint16 k) { uint8 rv; cur_block_index = k >> 1; + cur_coll_amt32 = &ci->ci_r18_r20; // kludge needed for SpawnPLM do { - rv = kBlockColl_Horiz_CheckColl[(level_data[cur_block_index] & 0xF000) >> 12](); + rv = kBlockColl_Horiz_CheckColl[(level_data[cur_block_index] & 0xF000) >> 12](ci); } while (rv & 0x80); + cur_coll_amt32 = NULL; return rv; } -uint8 BlockColl_Vert_CheckColl(uint16 k) { // 0x94952C +static uint8 BlockColl_Vert_CheckColl(CollInfo *ci, uint16 k) { // 0x94952C uint8 rv; cur_block_index = k >> 1; + cur_coll_amt32 = &ci->ci_r18_r20; do { - rv = kBlockColl_Vert_CheckColl[(level_data[cur_block_index] & 0xF000) >> 12](); + rv = kBlockColl_Vert_CheckColl[(level_data[cur_block_index] & 0xF000) >> 12](ci); } while (rv & 0x80); + cur_coll_amt32 = NULL; return rv; } -uint8 BlockColl_Handle_Horiz(void) { // 0x949543 - Samus_GetYposSpan(); +static Pair_Bool_Amt BlockColl_Handle_Horiz(int32 amt) { // 0x949543 + uint16 r28 = Samus_GetYposSpan(); uint16 prod = Mult8x8((uint16)(samus_y_pos - samus_y_radius) >> 4, room_width_in_blocks); uint16 v1; - R22_ = R20_ + samus_x_subpos; - uint16 v0 = R18_ + __CFADD__uint16(R20_, samus_x_subpos) + samus_x_pos; - R24_ = v0; - if ((R18_ & 0x8000) == 0) + //r22 = r20 + samus_x_subpos; + uint16 v0 = (amt + __PAIR32__(samus_x_pos, samus_x_subpos)) >> 16; + uint16 r24 = v0; + if (amt >= 0) v1 = samus_x_radius + v0 - 1; else v1 = v0 - samus_x_radius; - R32_ = v1; uint16 v2 = 2 * (prod + (v1 >> 4)); - while (!(BlockColl_Horiz_CheckColl(v2) & 1)) { + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = r28, .ci_r28 = r28, .ci_r32 = v1 }; + while (!(BlockColl_Horiz_CheckColl(&ci, v2) & 1)) { v2 += room_width_in_blocks * 2; - if ((--R26_ & 0x8000) != 0) - return 0; + if ((--ci.ci_r26 & 0x8000) != 0) + return (Pair_Bool_Amt) {false, ci.ci_r18_r20}; } - return 1; + return (Pair_Bool_Amt) { true, ci.ci_r18_r20 }; } -uint8 BlockColl_Handle_Vert_LeftToRight(void) { // 0x94959E - int16 v2; - - Samus_GetXposSpan(); - R22_ = R20_ + samus_y_subpos; - uint16 v0 = R18_ + __CFADD__uint16(R20_, samus_y_subpos) + samus_y_pos, v1; - R24_ = v0; - if ((R18_ & 0x8000) == 0) +static Pair_Bool_Amt BlockColl_Handle_Vert_LeftToRight(int32 amt) { // 0x94959E + uint16 r28 = Samus_GetXposSpan(); + //r22 = r20 + samus_y_subpos; + uint16 v0 = (amt + __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16, v1; + uint16 r24 = v0; + if (amt >= 0) v1 = samus_y_radius + v0 - 1; else v1 = v0 - samus_y_radius; - R32_ = v1; uint16 prod = Mult8x8(v1 >> 4, room_width_in_blocks); - v2 = (uint16)(samus_x_pos - samus_x_radius) >> 4; + uint16 v2 = (uint16)(samus_x_pos - samus_x_radius) >> 4; cur_block_index = prod + v2; - for (int i = 2 * cur_block_index; !(BlockColl_Vert_CheckColl(i) & 1); i += 2) { - if ((--R26_ & 0x8000) != 0) - return 0; + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = r28, .ci_r28 = r28, .ci_r32 = v1 }; + for (int i = 2 * cur_block_index; !(BlockColl_Vert_CheckColl(&ci, i) & 1); i += 2) { + if ((--ci.ci_r26 & 0x8000) != 0) + return (Pair_Bool_Amt) { false, ci.ci_r18_r20 }; } - return 1; + return (Pair_Bool_Amt) { true, ci.ci_r18_r20 }; } -uint8 BlockColl_Handle_Vert_RightToLeft(void) { // 0x9495F5 - int16 v2; - - Samus_GetXposSpan(); - R26_ = 0; - R22_ = R20_ + samus_y_subpos; - uint16 v0 = R18_ + __CFADD__uint16(R20_, samus_y_subpos) + samus_y_pos, v1; - R24_ = v0; - if ((R18_ & 0x8000) == 0) +static Pair_Bool_Amt BlockColl_Handle_Vert_RightToLeft(int32 amt) { // 0x9495F5 + uint16 r28 = Samus_GetXposSpan(); + uint16 r26 = 0; + //r22 = r20 + samus_y_subpos; + uint16 v0 = (amt + __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16, v1; + uint16 r24 = v0; + if (amt >= 0) v1 = samus_y_radius + v0 - 1; else v1 = v0 - samus_y_radius; - R32_ = v1; uint16 prod = Mult8x8(v1 >> 4, room_width_in_blocks); - v2 = (uint16)(samus_x_radius + samus_x_pos - 1) >> 4; + uint16 v2 = (uint16)(samus_x_radius + samus_x_pos - 1) >> 4; cur_block_index = prod + v2; - for (int i = 2 * cur_block_index; !(BlockColl_Vert_CheckColl(i) & 1); i -= 2) { - if (R28_ < ++R26_) - return 0; + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = r26, .ci_r28 = r28, .ci_r32 = v1 }; + for (int i = 2 * cur_block_index; !(BlockColl_Vert_CheckColl(&ci, i) & 1); i -= 2) { + if (ci.ci_r28 < ++ci.ci_r26) + return (Pair_Bool_Amt) { false, ci.ci_r18_r20 }; } - return 1; + return (Pair_Bool_Amt) { true, ci.ci_r18_r20 }; } -void AbsoluteValueOfInt32(void) { // 0x949653 - if ((R18_ & 0x8000) != 0) { - R18_ = ~R18_; - bool v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - } -} - -void AbsoluteValueOfInt32_0(void) { // 0x949669 - if ((R18_ & 0x8000) != 0) { - R18_ = ~R18_; - bool v0 = R20_ == 0; - R20_ = -R20_; - if (v0) - ++R18_; - } -} - -uint8 WallJumpBlockCollDetect(void) { // 0x94967F - samus_collision_direction |= 0xFu; +// Returns the new value of amt and not the carry flag, +// it can be inferred from samus_collision_flag +int32 WallJumpBlockCollDetect(int32 amt) { // 0x94967F + samus_collision_direction |= 0xF; flag_samus_in_quicksand = 0; - if (BlockColl_Handle_Horiz()) { - AbsoluteValueOfInt32(); - samus_collision_flag = 1; - return 1; - } else { - AbsoluteValueOfInt32(); - samus_collision_flag = 0; - return 0; - } + Pair_Bool_Amt pair = BlockColl_Handle_Horiz(amt); + samus_collision_flag = pair.flag; + return pair.amt >= 0 ? pair.amt : -pair.amt; } -uint8 Samus_CollDetectChangedPose(void) { // 0x9496AB - if ((abs16(R18_) & 0xFFF8) == 0) - return CollDetectDueToPoseChange_SingleBlock(); - uint16 v3 = R18_; - uint16 v2 = R20_; - R18_ = R18_ & 0xFFF0 | 8; - R20_ = 0; - uint8 v1 = CollDetectDueToPoseChange_SingleBlock(); - if (v1) - return v1; - R20_ = v2; - R18_ = v3; - return CollDetectDueToPoseChange_SingleBlock(); -} - -uint8 CollDetectDueToPoseChange_SingleBlock(void) { // 0x9496E3 - int8 v0; // cf - - samus_collision_direction |= 0xFu; +// Returns the new value of amt and not the carry flag, +// it can be inferred from samus_collision_flag +static int32 CollDetectDueToPoseChange_SingleBlock(int32 amt) { // 0x9496E3 + samus_collision_direction |= 0xF; flag_samus_in_quicksand = 0; - if (!(nmi_frame_counter_word & 1)) { - v0 = BlockColl_Handle_Vert_LeftToRight(); - if (!v0) - goto LABEL_6; - if (v0) { -LABEL_5: - AbsoluteValueOfInt32_0(); - samus_collision_flag = 1; - return 1; - } - } - if (BlockColl_Handle_Vert_RightToLeft()) - goto LABEL_5; -LABEL_6: - AbsoluteValueOfInt32_0(); - samus_collision_flag = 0; - return 0; + Pair_Bool_Amt pair = !(nmi_frame_counter_word & 1) ? + BlockColl_Handle_Vert_LeftToRight(amt) : BlockColl_Handle_Vert_RightToLeft(amt); + samus_collision_flag = pair.flag; + return pair.amt >= 0 ? pair.amt : -pair.amt; } -uint8 Samus_MoveRight_NoSolidColl(void) { // 0x94971E - if (__PAIR32__(R20_, R18_) && (flag_samus_in_quicksand = 0, BlockColl_Handle_Horiz())) { - bool v0 = __CFADD__uint16(R20_, samus_x_subpos); - samus_x_subpos += R20_; - samus_x_pos += R18_ + v0; - samus_collision_flag = 1; - return 1; - } else { - bool v0 = __CFADD__uint16(R20_, samus_x_subpos); - samus_x_subpos += R20_; - samus_x_pos += R18_ + v0; - samus_collision_flag = 0; - return 0; - } +// Returns the new value of amt and not the carry flag, +// it can be inferred from samus_collision_flag +int32 Samus_CollDetectChangedPose(int32 amt) { // 0x9496AB + if ((abs16(amt >> 16) & 0xFFF8) == 0) + return CollDetectDueToPoseChange_SingleBlock(amt); + int32 amt_backup = amt; + amt = CollDetectDueToPoseChange_SingleBlock(INT16_SHL16((amt >> 16) & 0xFFF0 | 8)); + if (samus_collision_flag) + return amt; + return CollDetectDueToPoseChange_SingleBlock(amt_backup); } -uint8 Samus_MoveDown_NoSolidColl(void) { // 0x949763 - if (__PAIR32__(R20_, R18_)) { +int32 Samus_MoveRight_NoSolidColl(int32 amt) { // 0x94971E + Pair_Bool_Amt pair; + samus_collision_flag = (amt != 0 && (flag_samus_in_quicksand = 0, pair = BlockColl_Handle_Horiz(amt), amt = pair.amt, pair.flag)); + AddToHiLo(&samus_x_pos, &samus_x_subpos, amt); + return amt; +} + +int32 Samus_MoveDown_NoSolidColl(int32 amt) { // 0x949763 + if (amt) { samus_pos_adjusted_by_slope_flag = 0; flag_samus_in_quicksand = 0; - if (!(nmi_frame_counter_word & 1)) { - bool v0; - v0 = BlockColl_Handle_Vert_LeftToRight(); - if (!v0) - goto LABEL_8; - if (v0) { -LABEL_6: - v0 = __CFADD__uint16(R20_, samus_y_subpos); - samus_y_subpos += R20_; - samus_y_pos += R18_ + v0; -LABEL_7: - samus_collision_flag = 1; - return 1; - } + Pair_Bool_Amt pair = (nmi_frame_counter_word & 1) == 0 ? BlockColl_Handle_Vert_LeftToRight(amt) : BlockColl_Handle_Vert_RightToLeft(amt); + amt = pair.amt; + if (pair.flag) { + samus_collision_flag = 1; + AddToHiLo(&samus_y_pos, &samus_y_subpos, amt); + return amt; } - if (BlockColl_Handle_Vert_RightToLeft()) - goto LABEL_6; } -LABEL_8:; - bool v0 = __CFADD__uint16(R20_, samus_y_subpos); - samus_y_subpos += R20_; - samus_y_pos += R18_ + v0; - if (flag_samus_in_quicksand) - goto LABEL_7; - samus_collision_flag = 0; + samus_collision_flag = (flag_samus_in_quicksand != 0); + AddToHiLo(&samus_y_pos, &samus_y_subpos, amt); + return amt; +} + +static uint8 BlockInsideReact_Slope(CollInfo *ci) { // 0x9497BF return 0; } -uint8 BlockInsideReact_Slope(void) { // 0x9497BF - return 0; -} - -uint8 BlockInsideReact_ShootableAir(void) { // 0x9497D0 +static uint8 BlockInsideReact_ShootableAir(CollInfo *ci) { // 0x9497D0 samus_x_speed_table_pointer = addr_kSamusSpeedTable_Normal_X__plus__12; return 0; } -void ClearCarry_8(void) { // 0x9497D8 +static void ClearCarry_8(void) { // 0x9497D8 } -uint8 MaybeUnused_sub_9497DA(void) { // 0x9497DA - ++samus_periodic_damage; - samus_x_extra_run_speed = 0; - samus_x_base_speed = 0; - return 0; +static void nullsub_165(void) { // 0x9497D7 } -uint8 MaybeUnused_sub_9497F2(void) { // 0x9497F2 - if (samus_y_dir == 1) { - samus_y_subaccel = 0; - samus_y_accel = 2; - } else { - samus_y_speed = 0; - samus_y_subspeed = 0; - } - return 0; -} - -uint8 ClearCarry_6(void) { // 0x949810 - return 0; -} - -uint8 ClearCarry_7(void) { // 0x949812 - return 0; -} - -uint8 BlockInsideReact_SpikeAir_BTS1(void) { // 0x949814 - ++samus_periodic_damage; - samus_x_speed_table_pointer = addr_kSamusSpeedTable_LavaAcid_X; - samus_y_subaccel = 0; - samus_y_accel = 0; - if (samus_y_dir == 1) { - samus_y_subaccel = 0; - samus_y_accel = 5; - } else { - samus_y_speed = 0; - samus_y_subspeed = 0; - extra_samus_y_subdisplacement = 0; - extra_samus_y_displacement = 2; - } - return 0; -} - -void nullsub_165(void) { // 0x9497D7 -} - -void BlockInsideReact_SpikeAir_BTS2(void) { // 0x949866 +static void BlockInsideReact_SpikeAir_BTS2(void) { // 0x949866 if (!samus_contact_damage_index && !samus_invincibility_timer) { samus_invincibility_timer = 60; samus_knockback_timer = 10; @@ -1320,49 +1138,49 @@ static Func_V *const kBlockInsideReact_SpikeAir[16] = { // 0x9498CC nullsub_165, }; -uint8 BlockInsideReact_SpikeAir(void) { +static uint8 BlockInsideReact_SpikeAir(CollInfo *ci) { kBlockInsideReact_SpikeAir[BTS[cur_block_index]](); return 0; } -uint8 BlockInsideReact_Special_(void) { // 0x9498DC +static uint8 BlockInsideReact_Special_(CollInfo *ci) { // 0x9498DC samus_x_speed_table_pointer = addr_kSamusSpeedTable_Normal_X__plus__12; return 0; } -void BlockInsideReact_SpecialAir_Default(void) { // 0x9498E3 +static void BlockInsideReact_SpecialAir_Default(void) { // 0x9498E3 samus_x_speed_table_pointer = addr_kSamusSpeedTable_Normal_X__plus__12; } -void BlockInsideReact_SpecialAir_8(void) { // 0x9498EA - if ((area_index != 3 || CheckBossBitForCurArea(1u) & 1) && !samus_y_speed) { +static void BlockInsideReact_SpecialAir_8(void) { // 0x9498EA + if ((area_index != 3 || CheckBossBitForCurArea(1) & 1) && !samus_y_speed) { extra_samus_x_subdisplacement = 0; extra_samus_x_displacement = 2; } samus_x_speed_table_pointer = addr_kSamusSpeedTable_Normal_X__plus__12; } -void BlockInsideReact_SpecialAir_9(void) { // 0x949910 - if ((area_index != 3 || CheckBossBitForCurArea(1u) & 1) && !samus_y_speed) { +static void BlockInsideReact_SpecialAir_9(void) { // 0x949910 + if ((area_index != 3 || CheckBossBitForCurArea(1) & 1) && !samus_y_speed) { extra_samus_x_subdisplacement = 0; extra_samus_x_displacement = -2; } samus_x_speed_table_pointer = addr_kSamusSpeedTable_Normal_X__plus__12; } -void BlockInsideReact_SpecialAir_10(void) { // 0x949936 +static void BlockInsideReact_SpecialAir_10(void) { // 0x949936 extra_samus_x_subdisplacement = 0; extra_samus_x_displacement = 2; samus_x_speed_table_pointer = addr_kSamusSpeedTable_Normal_X__plus__12; } -void BlockInsideReact_SpecialAir_11(void) { // 0x949946 +static void BlockInsideReact_SpecialAir_11(void) { // 0x949946 extra_samus_x_subdisplacement = 0; extra_samus_x_displacement = -2; samus_x_speed_table_pointer = addr_kSamusSpeedTable_Normal_X__plus__12; } -void BlockInsideReact_SpecialAir_70(void) { // 0x949956 +static void BlockInsideReact_SpecialAir_70(void) { // 0x949956 if (inside_block_reaction_samus_point == 1) SpawnPLM(addr_kPlmHeader_B6FF); } @@ -1461,22 +1279,19 @@ static Func_V *const off_949966[80] = { BlockInsideReact_SpecialAir_Default, }; -uint8 BlockInsideReact_SpecialAir(void) { - int16 v0; - - v0 = BTS[cur_block_index] << 8; - if (v0 < 0) { - R34 = g_off_949B06[area_index]; - const uint8 *v3 = RomPtr_94(R34); - SpawnPLM(*(uint16 *)&v3[(2 * (HIBYTE(v0) & 0x7F))]); +static uint8 BlockInsideReact_SpecialAir(CollInfo *ci) { + uint8 v0 = BTS[cur_block_index]; + if (v0 & 0x80) { + const uint8 *v3 = RomPtr_94(g_off_949B06[area_index]); + SpawnPLM(*(uint16 *)&v3[2 * (v0 & 0x7F)]); } else { - off_949966[v0 >> 8](); + off_949966[v0](); } return 0; } void BlockInsideDetection(void) { // 0x949B60 - static Func_U8 *const kSamus_BlockInsideDetection[16] = { + static Func_CollInfo_U8 *const kSamus_BlockInsideDetection[16] = { BlockInsideReact_ShootableAir, BlockInsideReact_Slope, BlockInsideReact_SpikeAir, @@ -1501,31 +1316,34 @@ void BlockInsideDetection(void) { // 0x949B60 extra_samus_y_subdisplacement = 0; extra_samus_y_displacement = 0; inside_block_reaction_samus_point = 0; - R26_ = samus_x_pos; - samus_bottom_boundary_position = samus_y_radius + samus_y_pos - 1; - R28_ = samus_y_radius + samus_y_pos - 1; - CalculateBlockAt(R26_, R28_, 0, 0); + uint16 r26 = samus_x_pos; + uint16 samus_bottom_boundary_position = samus_y_radius + samus_y_pos - 1; + uint16 r28 = samus_y_radius + samus_y_pos - 1; + CalculateBlockAt(r26, r28, 0, 0); + CollInfo ci = { .ci_r24 = 0, .ci_r26 = r26, .ci_r28 = r28 }; uint8 rv; do { - rv = kSamus_BlockInsideDetection[(HIBYTE(level_data[cur_block_index]) & 0xF0) >> 4](); + rv = kSamus_BlockInsideDetection[(HIBYTE(level_data[cur_block_index]) & 0xF0) >> 4](&ci); } while (rv & 0x80); inside_block_reaction_samus_point = 1; if (((samus_bottom_boundary_position ^ samus_y_pos) & 0xFFF0) != 0) { - R26_ = samus_x_pos; - R28_ = samus_y_pos; - CalculateBlockAt(R26_, R28_, 0, 0); + r26 = samus_x_pos; + r28 = samus_y_pos; + CalculateBlockAt(r26, r28, 0, 0); + CollInfo ci = { .ci_r24 = 0, .ci_r26 = r26, .ci_r28 = r28 }; do { - rv = kSamus_BlockInsideDetection[(HIBYTE(level_data[cur_block_index]) & 0xF0) >> 4](); + rv = kSamus_BlockInsideDetection[(HIBYTE(level_data[cur_block_index]) & 0xF0) >> 4](&ci); } while (rv & 0x80); } inside_block_reaction_samus_point = 2; if (((samus_bottom_boundary_position ^ (uint16)(samus_y_pos - samus_y_radius)) & 0xFFF0) != 0 && ((samus_y_pos ^ (samus_bottom_boundary_position ^ (uint16)(samus_y_pos - samus_y_radius)) & 0xFFF0) & 0xFFF0) != 0) { - R26_ = samus_x_pos; - R28_ = samus_y_pos - samus_y_radius; - CalculateBlockAt(R26_, R28_, 0, 0); + r26 = samus_x_pos; + r28 = samus_y_pos - samus_y_radius; + CalculateBlockAt(r26, r28, 0, 0); + CollInfo ci = { .ci_r24 = 0, .ci_r26 = r26, .ci_r28 = r28 }; do { - rv = kSamus_BlockInsideDetection[(HIBYTE(level_data[cur_block_index]) & 0xF0) >> 4](); + rv = kSamus_BlockInsideDetection[(HIBYTE(level_data[cur_block_index]) & 0xF0) >> 4](&ci); } while (rv & 0x80); } } @@ -1576,14 +1394,13 @@ static const int8 kBlockFunc_9C73_Tab1[18] = { 0, -1, }; -void BlockFunc_9C73(uint16 v0) { - +uint16 BlockFunc_9C73(uint16 v0) { int v1 = v0 >> 1; if ((projectile_type[v1] & 0xF00) != 0) { - temp_collision_DD2 = kBlockFunc_9C73_Tab1[2 * (HIBYTE(projectile_type[v1]) & 0xF) + 1]; + return kBlockFunc_9C73_Tab1[2 * (HIBYTE(projectile_type[v1]) & 0xF) + 1]; } else { - int R18 = projectile_type[v1] & 0xF; - temp_collision_DD2 = kBlockFunc_9C73_Tab0[3 * R18 + 2]; + int r18 = projectile_type[v1] & 0xF; + return kBlockFunc_9C73_Tab0[3 * r18 + 2]; } } @@ -1591,20 +1408,21 @@ void BombOrPowerBomb_Func1(uint16 v0) { // 0x949CAC int16 v2; int16 v3; - BlockFunc_9C73(v0); + uint16 temp_collision_DD2 = BlockFunc_9C73(v0); int v1 = v0 >> 1; v2 = projectile_x_pos[v1]; if (v2 >= 0) { - R26_ = projectile_x_pos[v1]; + uint16 r26 = projectile_x_pos[v1]; if ((int16)(HIBYTE(v2) - room_width_in_scrolls) < 0) { v3 = projectile_y_pos[v1]; if (v3 >= 0) { - R28_ = projectile_y_pos[v1]; + uint16 R28 = projectile_y_pos[v1]; if ((int16)(HIBYTE(v3) - room_height_in_scrolls) < 0) { cur_block_index = 0; - CalculateBlockAt(R26_, R28_, 0, 0); + CalculateBlockAt(r26, R28, 0, 0); + CollInfo ci = { .ci_r24 = 0, .ci_r26 = r26, .ci_r28 = R28 }; if (temp_collision_DD2 == 2) - BlockColl_BombExplosion(v0); + BlockColl_BombExplosion(&ci, v0); else BlockFunc_A06A(v0); } @@ -1613,7 +1431,24 @@ void BombOrPowerBomb_Func1(uint16 v0) { // 0x949CAC } } -void BlockColl_BombExplosion(uint16 k) { // 0x949CF4 + +static uint16 BlockColl_GetBlockIndexAbove(uint16 k) { // 0x949D34 + return k - room_width_in_blocks - room_width_in_blocks; +} + +static uint16 BlockColl_GetBlockIndexRight(uint16 k) { // 0x949D3E + return room_width_in_blocks * 2 + k + 1 + 1; +} + +static uint16 BlockColl_GetBlockIndexLeft(uint16 k) { // 0x949D49 + return k - 4; +} + +static uint16 BlockColl_GetBlockIndexBelow(uint16 k) { // 0x949D4E + return room_width_in_blocks * 2 + k + 1 + 1; +} + +static void BlockColl_BombExplosion(CollInfo *ci, uint16 k) { // 0x949CF4 int16 v2; int v1 = k >> 1; @@ -1623,60 +1458,41 @@ void BlockColl_BombExplosion(uint16 k) { // 0x949CF4 projectile_type[v1] = v2 | 1; if (cur_block_index != 0xFFFF) { uint16 v3 = 2 * cur_block_index; - BlockBombedReact(2 * cur_block_index); + BlockBombedReact(ci, 2 * cur_block_index); uint16 idx = BlockColl_GetBlockIndexAbove(v3); - BlockBombedReact(idx); + BlockBombedReact(ci, idx); uint16 idx2 = BlockColl_GetBlockIndexRight(idx); - BlockBombedReact(idx2); + BlockBombedReact(ci, idx2); idx = BlockColl_GetBlockIndexLeft(idx2); - BlockBombedReact(idx); + BlockBombedReact(ci, idx); idx = BlockColl_GetBlockIndexBelow(idx); - BlockBombedReact(idx); + BlockBombedReact(ci, idx); } } } } -uint16 BlockColl_GetBlockIndexAbove(uint16 k) { // 0x949D34 - return k - room_width_in_blocks - room_width_in_blocks; -} - -uint16 BlockColl_GetBlockIndexRight(uint16 k) { // 0x949D3E - return room_width_in_blocks * 2 + k + 1 + 1; -} - -uint16 BlockColl_GetBlockIndexLeft(uint16 k) { // 0x949D49 - return k - 4; -} - -uint16 BlockColl_GetBlockIndexBelow(uint16 k) { // 0x949D4E - return room_width_in_blocks * 2 + k + 1 + 1; -} - -uint8 ClearCarry_9(void) { // 0x949D59 +static uint8 ClearCarry_9(CollInfo *ci) { // 0x949D59 return 0; } -uint8 SetCarry_0(void) { // 0x949D5B +static uint8 SetCarry_0(CollInfo *ci) { // 0x949D5B return 1; } -uint8 sub_949D5D(void) { // 0x949D5D +static uint8 sub_949D5D(CollInfo *ci) { // 0x949D5D if ((BTS[cur_block_index] & 0x1F) < 5) return 1; else - return BlockShotReactVert_Slope_NonSquare() & 1; + return BlockShotReactVert_Slope_NonSquare(ci); } -uint8 BlockBombedReact_Special(void) { // 0x949D71 - int16 v0; - - v0 = BTS[cur_block_index]; +static uint8 BlockBombedReact_Special(CollInfo *ci) { // 0x949D71 + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) { uint16 *kBlockBombedReact_Region_Plm = (uint16 *)RomPtr_94(0x9e44); - R18_ = kBlockBombedReact_Region_Plm[area_index]; - const uint8 *v2 = RomPtr_94(R18_); - SpawnPLM(*(uint16 *)&v2[(uint16)(2 * (v0 & 0x7F))]); + const uint16 *v2 = (uint16*)RomPtr_94(kBlockBombedReact_Region_Plm[area_index]); + SpawnPLM(v2[v0 & 0x7F]); } else { uint16 *kBlockBombedReact_Special_Plm = (uint16 *)RomPtr_94(0x9dA4); SpawnPLM(kBlockBombedReact_Special_Plm[v0]); @@ -1684,51 +1500,49 @@ uint8 BlockBombedReact_Special(void) { // 0x949D71 return 1; } -uint8 BlockReact_ShootableAir(void) { // 0x949E55 - int16 v0; - uint16 *kBlockShotBombedReactionShootablePlm = (uint16 *)RomPtr_94(0x9ea6); - v0 = BTS[cur_block_index]; - if ((v0 & 0x80) == 0) - SpawnPLM(kBlockShotBombedReactionShootablePlm[v0]); +static uint8 BlockReact_ShootableAir(CollInfo *ci) { // 0x949E55 + uint8 v0 = BTS[cur_block_index]; + if ((v0 & 0x80) == 0) { + uint16 t = kBlockShotBombedReactionShootablePlm[v0]; + if (t == 0xb974) + ci->ci_r38 = 0, ci->ci_r40 = 0xffff; + SpawnPLM(t); + } return 0; } -uint8 BlockReact_Shootable(void) { // 0x949E73 - int16 v0; - - v0 = BTS[cur_block_index]; +static uint8 BlockReact_Shootable(CollInfo *ci) { // 0x949E73 + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) != 0) { uint16 *kBlockShotBombGrappleReaction_ShootableBlock_RegionPlm = (uint16 *)RomPtr_94(0x9FC6); uint16 *v2 = (uint16*)RomPtr_94(kBlockShotBombGrappleReaction_ShootableBlock_RegionPlm[area_index]); SpawnPLM(v2[v0 & 0x7f]); } else { - uint16 *kBlockShotBombedReactionShootablePlm = (uint16 *)RomPtr_94(0x9ea6); - SpawnPLM(kBlockShotBombedReactionShootablePlm[v0]); + uint16 t = kBlockShotBombedReactionShootablePlm[v0]; + if (t == 0xb974) + ci->ci_r38 = 0, ci->ci_r40 = 0xffff; + SpawnPLM(t); } return 1; } -uint8 BlockReact_BombableAir(void) { // 0x949FD6 - int16 v0; - +static uint8 BlockReact_BombableAir(CollInfo *ci) { // 0x949FD6 uint16 *kBlockShotBombGrappleReact_BombableBlockPlm = (uint16 *)RomPtr_94(0xA012); - v0 = BTS[cur_block_index]; + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) == 0) SpawnPLM(kBlockShotBombGrappleReact_BombableBlockPlm[v0]); return 0; } -uint8 BlockReact_BombableBlock(void) { // 0x949FF4 - int16 v0; - +static uint8 BlockReact_BombableBlock(CollInfo *ci) { // 0x949FF4 uint16 *kBlockShotBombGrappleReact_BombableBlockPlm = (uint16 *)RomPtr_94(0xA012); - v0 = BTS[cur_block_index]; + uint8 v0 = BTS[cur_block_index]; if ((v0 & 0x80) == 0) SpawnPLM(kBlockShotBombGrappleReact_BombableBlockPlm[v0]); return 1; } -static Func_U8 *const kBlockBombedReact[16] = { // 0x94A052 +static Func_CollInfo_U8 *const kBlockBombedReact[16] = { // 0x94A052 ClearCarry_9, ClearCarry_9, ClearCarry_9, @@ -1746,9 +1560,10 @@ static Func_U8 *const kBlockBombedReact[16] = { // 0x94A052 SetCarry_0, BlockReact_BombableBlock, }; -void BlockBombedReact(uint16 v0) { + +static void BlockBombedReact(CollInfo *ci, uint16 v0) { cur_block_index = v0 >> 1; - while (kBlockBombedReact[(level_data[cur_block_index] & 0xF000) >> 12]() & 0x80) {} + while (kBlockBombedReact[(level_data[cur_block_index] & 0xF000) >> 12](ci) & 0x80) {} } void BlockFunc_A06A(uint16 k) { // 0x94A06A @@ -1761,85 +1576,78 @@ void BlockFunc_A06A(uint16 k) { // 0x94A06A if (v2 < 0) projectile_variables[v1] = 0; } else { - R18_ = HIBYTE(power_bomb_explosion_radius); - R20_ = (uint16)(HIBYTE(power_bomb_explosion_radius) - + 2 * HIBYTE(power_bomb_explosion_radius)) >> 2; + uint16 r18 = HIBYTE(power_bomb_explosion_radius); + uint16 r20 = (uint16)(3 * HIBYTE(power_bomb_explosion_radius)) >> 2; v3 = power_bomb_explosion_x_pos - HIBYTE(power_bomb_explosion_radius); if (v3 < 0) v3 = 0; - R22_ = (uint16)v3 >> 4; - uint16 v4 = (uint16)(R18_ + power_bomb_explosion_x_pos) >> 4; + uint16 r22 = (uint16)v3 >> 4; + uint16 v4 = (uint16)(r18 + power_bomb_explosion_x_pos) >> 4; if (v4 >= room_width_in_blocks) v4 = room_width_in_blocks - 1; - R24_ = v4; - uint16 v5 = power_bomb_explosion_y_pos - R20_; - if ((int16)(power_bomb_explosion_y_pos - R20_) < 0) + uint16 r24 = v4; + uint16 v5 = power_bomb_explosion_y_pos - r20; + if ((int16)v5 < 0) v5 = 0; - R26_ = v5 >> 4; - uint16 v6 = (uint16)(R20_ + power_bomb_explosion_y_pos) >> 4; + uint16 r26 = v5 >> 4; + uint16 v6 = (uint16)(r20 + power_bomb_explosion_y_pos) >> 4; if (v6 >= room_height_in_blocks) v6 = room_height_in_blocks - 1; - R28_ = v6; - uint16 a = R26_ | ((uint8)R22_ << 8); - BlockFunc_A0F4(a); - BlockFunc_A11A(a); - BlockFunc_A0F4(R28_ | ((uint8)R22_ << 8)); - BlockFunc_A11A(R26_ | ((uint8)R24_ << 8)); + uint16 R28 = v6; + uint16 a = r26 | (r22 << 8); + BlockFunc_A0F4(a, r22, r24, r26, R28); + BlockFunc_A11A(a, r24, r26, R28); + BlockFunc_A0F4(R28 | (r22 << 8), r22, r24, r26, R28); + BlockFunc_A11A(r26 | (r24 << 8), r24, r26, R28); } } -void BlockFunc_A0F4(uint16 a) { // 0x94A0F4 - int16 v4; - +static void BlockFunc_A0F4(uint16 a, uint16 r22, uint16 r24, uint16 r26, uint16 r28) { // 0x94A0F4 uint16 RegWord = Mult8x8(a, room_width_in_blocks); uint16 v3 = 2 * (RegWord + HIBYTE(a)); - v4 = R24_ - R22_; + int16 v4 = r24 - r22; + CollInfo ci = { .ci_r24 = r24, .ci_r26 = r26, .ci_r28 = r28 }; do { - BlockBombedReact(v3); + BlockBombedReact(&ci, v3); v3 += 2; - --v4; - } while (v4 >= 0); + } while (--v4 >= 0); } - -void BlockFunc_A11A(uint16 a) { // 0x94A11A - int16 v4; - +static void BlockFunc_A11A(uint16 a, uint16 r24, uint16 r26, uint16 r28) { // 0x94A11A uint16 RegWord = Mult8x8(a, room_width_in_blocks); uint16 v3 = 2 * (RegWord + HIBYTE(a)); - v4 = R28_ - R26_; + int16 v4 = r28 - r26; + CollInfo ci = { .ci_r24 = r24, .ci_r26 = r26, .ci_r28 = r28 }; do { - BlockBombedReact(v3); + BlockBombedReact(&ci, v3); v3 += room_width_in_blocks * 2; - --v4; - } while (v4 >= 0); + } while (--v4 >= 0); } - -uint8 BlockShotReactHoriz_Slope(void) { // 0x94A147 +static uint8 BlockShotReactHoriz_Slope(CollInfo *ci) { // 0x94A147 if ((BTS[cur_block_index] & 0x1F) < 5) - return BlockShotReactVert_Slope_Square(BTS[cur_block_index] & 0x1F, cur_block_index); + return BlockShotReactVert_Slope_Square(ci, BTS[cur_block_index] & 0x1F, cur_block_index); else - return BlockShotReactVert_Slope_NonSquare(); + return BlockShotReactVert_Slope_NonSquare(ci); } -uint8 SetCarry_1(void) { // 0x94A15C +static uint8 SetCarry_1(void) { // 0x94A15C return 1; } -uint8 BlockShotReactVert_Slope(void) { // 0x94A15E +static uint8 BlockShotReactVert_Slope(CollInfo *ci) { // 0x94A15E if ((BTS[cur_block_index] & 0x1F) < 5) - return BlockShotReactHoriz_Slope_Square(BTS[cur_block_index] & 0x1F, cur_block_index); + return BlockShotReactHoriz_Slope_Square(ci, BTS[cur_block_index] & 0x1F, cur_block_index); else - return BlockShotReactHoriz_Slope_NonSquare(); + return BlockShotReactHoriz_Slope_NonSquare(ci); } -uint8 SetCarry_2(void) { // 0x94A173 +static uint8 SetCarry_2(void) { // 0x94A173 return 1; } -uint8 BlockShotReactHoriz(uint16 k) { // 0x94A1B5 - static Func_U8 *const kBlockShotReactHoriz[16] = { +static uint8 BlockShotReactHoriz(CollInfo *ci, uint16 k) { // 0x94A1B5 + static Func_CollInfo_U8 *const kBlockShotReactHoriz[16] = { ClearCarry_9, BlockShotReactHoriz_Slope, ClearCarry_9, @@ -1857,461 +1665,333 @@ uint8 BlockShotReactHoriz(uint16 k) { // 0x94A1B5 SetCarry_0, BlockReact_BombableBlock, }; - - uint8 v1 = k >= room_size_in_blocks; - if (k < room_size_in_blocks) { - cur_block_index = k >> 1; - do { - v1 = kBlockShotReactHoriz[(level_data[cur_block_index] & 0xF000) >> 12](); - } while (v1 & 0x80); - if (v1) - --R40; - } + uint8 v1; + if (k >= room_size_in_blocks) + return 1; + cur_block_index = k >> 1; + do { + v1 = kBlockShotReactHoriz[(level_data[cur_block_index] & 0xF000) >> 12](ci); + } while (v1 & 0x80); + if (v1) + ci->ci_r40--; return v1; } -uint8 BlockShotReactVert(uint16 k) { // 0x94A1D6 - static Func_U8 *const kBlockShotReactVert[16] = { - ClearCarry_9, - BlockShotReactVert_Slope, - ClearCarry_9, - ClearCarry_9, - BlockReact_ShootableAir, - BlockReact_HorizExt, - ClearCarry_9, - BlockReact_BombableAir, - SetCarry_0, - SetCarry_0, - SetCarry_0, - SetCarry_0, - BlockReact_Shootable, - BlockReact_VertExt, - SetCarry_0, - BlockReact_BombableBlock, +static uint8 BlockShotReactVert(CollInfo *ci, uint16 k) { // 0x94A1D6 + static Func_CollInfo_U8 *const kBlockShotReactVert[16] = { + ClearCarry_9, + BlockShotReactVert_Slope, + ClearCarry_9, + ClearCarry_9, + BlockReact_ShootableAir, + BlockReact_HorizExt, + ClearCarry_9, + BlockReact_BombableAir, + SetCarry_0, + SetCarry_0, + SetCarry_0, + SetCarry_0, + BlockReact_Shootable, + BlockReact_VertExt, + SetCarry_0, + BlockReact_BombableBlock, }; - - uint8 v1 = k >= room_size_in_blocks; - if (k < room_size_in_blocks) { - cur_block_index = k >> 1; - do { - v1 = kBlockShotReactVert[(level_data[cur_block_index] & 0xF000) >> 12](); - } while (v1 & 0x80); - if (v1) - --R40; - } + uint8 v1; + if (k >= room_size_in_blocks) + return 1; + cur_block_index = k >> 1; + do { + v1 = kBlockShotReactVert[(level_data[cur_block_index] & 0xF000) >> 12](ci); + } while (v1 & 0x80); + if (v1) + --ci->ci_r40; return v1; } -void BlockGetSomePos1(uint16 k) { // 0x94A1F7 +static uint16 BlockGetSomePos1(uint16 k) { // 0x94A1F7 int v1 = k >> 1; - R38 = (projectile_y_pos[v1] - projectile_y_radius[v1]) & 0xFFF0; - R38 = (uint16)(projectile_y_radius[v1] + projectile_y_pos[v1] - 1 - R38) >> 4; - R26_ = R38; - R40 = R38; + uint16 r38 = (projectile_y_pos[v1] - projectile_y_radius[v1]) & 0xFFF0; + return (uint16)(projectile_y_radius[v1] + projectile_y_pos[v1] - 1 - r38) >> 4; } -void BlockGetSomePos2(uint16 k) { // 0x94A219 +static uint16 BlockGetSomePos2(uint16 k) { // 0x94A219 int v1 = k >> 1; - R38 = (projectile_x_pos[v1] - projectile_x_radius[v1]) & 0xFFF0; - R38 = (uint16)(projectile_x_radius[v1] + projectile_x_pos[v1] - 1 - R38) >> 4; - R26_ = R38; - R40 = R38; + uint16 r38 = (projectile_x_pos[v1] - projectile_x_radius[v1]) & 0xFFF0; + return (uint16)(projectile_x_radius[v1] + projectile_x_pos[v1] - 1 - r38) >> 4; } uint8 BlockCollNoWaveBeamHoriz(uint16 k) { // 0x94A23B - int16 v2; + uint16 v7; - R30_ = 0; - R18_ = 0; - R20_ = 0; int v1 = k >> 1; - v2 = projectile_bomb_x_speed[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - BlockGetSomePos1(k); + int32 amt = INT16_SHL8(projectile_bomb_x_speed[v1]); + uint16 some_pos = BlockGetSomePos1(k); uint16 prod = Mult8x8((uint16)(projectile_y_pos[v1] - projectile_y_radius[v1]) >> 4, room_width_in_blocks); - uint16 v3 = projectile_bomb_x_subpos[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - uint16 v5 = R18_ + v3; - projectile_bomb_x_subpos[v1] = v5; - R22_ = v5; - uint16 v6 = R20_ + v4 + projectile_x_pos[v1], v7; - projectile_x_pos[v1] = v6; - R24_ = v6; - if ((R20_ & 0x8000) != 0) - v7 = v6 - projectile_x_radius[v1]; + + AddToHiLo(&projectile_x_pos[v1], &projectile_bomb_x_subpos[v1], amt); + //r22 = projectile_bomb_x_subpos[v1]; + uint16 r24 = projectile_x_pos[v1]; + if (amt < 0) + v7 = projectile_x_pos[v1] - projectile_x_radius[v1]; else - v7 = projectile_x_radius[v1] + v6 - 1; - R28_ = v7; + v7 = projectile_x_radius[v1] + projectile_x_pos[v1] - 1; + uint16 R28 = v7; uint16 v8 = 2 * (prod + (v7 >> 4)); - if (!sign16(R38 - 16) || (int16)(HIBYTE(R28_) - room_width_in_scrolls) >= 0) + if (!sign16(some_pos - 16) || (int16)(HIBYTE(R28) - room_width_in_scrolls) >= 0) return 0; + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = some_pos, .ci_r28 = R28, .ci_r30 = 0, .ci_r38 = some_pos, .ci_r40 = some_pos }; do { - BlockShotReactHoriz(v8); + BlockShotReactHoriz(&ci, v8); v8 += room_width_in_blocks * 2; - --R38; - } while ((R38 & 0x8000) == 0); - if ((R40 & 0x8000) == 0) + } while ((--ci.ci_r38 & 0x8000) == 0); + if ((ci.ci_r40 & 0x8000) == 0) return 0; KillProjectile(k); return 1; } uint8 BlockCollNoWaveBeamVert(uint16 k) { // 0x94A2CA - int16 v2; - int16 v8; - int16 v9; + uint16 v7; - R30_ = 0; - R18_ = 0; - R20_ = 0; int v1 = k >> 1; - v2 = projectile_bomb_y_speed[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - BlockGetSomePos2(k); - uint16 v3 = projectile_bomb_y_subpos[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - uint16 v5 = R18_ + v3; - projectile_bomb_y_subpos[v1] = v5; - R22_ = v5; - uint16 v6 = R20_ + v4 + projectile_y_pos[v1], v7; - projectile_y_pos[v1] = v6; - R24_ = v6; - if ((R20_ & 0x8000) != 0) - v7 = v6 - projectile_y_radius[v1]; + int32 amt = INT16_SHL8(projectile_bomb_y_speed[v1]); + uint16 some_pos = BlockGetSomePos2(k); + AddToHiLo(&projectile_y_pos[v1], &projectile_bomb_y_subpos[v1], amt); + //r22 = projectile_bomb_y_subpos[v1]; + uint16 r24 = projectile_y_pos[v1]; + if (amt < 0) + v7 = projectile_y_pos[v1] - projectile_y_radius[v1]; else - v7 = projectile_y_radius[v1] + v6 - 1; - R28_ = v7; - v8 = (uint16)(projectile_x_pos[v1] - projectile_x_radius[v1]) >> 4; - v9 = 2 * (Mult8x8(v7 >> 4, room_width_in_blocks) + v8); - if (!sign16(R38 - 16) || (int16)(HIBYTE(R28_) - room_height_in_scrolls) >= 0) + v7 = projectile_y_radius[v1] + projectile_y_pos[v1] - 1; + uint16 R28 = v7; + uint16 v8 = (uint16)(projectile_x_pos[v1] - projectile_x_radius[v1]) >> 4; + uint16 v9 = 2 * (Mult8x8(v7 >> 4, room_width_in_blocks) + v8); + if (!sign16(some_pos - 16) || (int16)(HIBYTE(R28) - room_height_in_scrolls) >= 0) return 0; + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = some_pos, .ci_r28 = R28, .ci_r30 = 0, .ci_r38 = some_pos, .ci_r40 = some_pos }; do { - BlockShotReactVert(v9); + BlockShotReactVert(&ci, v9); v9 += 2; - --R38; - } while ((R38 & 0x8000) == 0); - if ((R40 & 0x8000) == 0) + } while ((--ci.ci_r38 & 0x8000) == 0); + if ((ci.ci_r40 & 0x8000) == 0) return 0; KillProjectile(k); return 1; } uint8 BlockCollWaveBeamHoriz(uint16 k) { // 0x94A352 - int16 v2; - int16 v8; - int8 v9; - int16 v10; + uint16 v7; - R30_ = 0; - R18_ = 0; - R20_ = 0; int v1 = k >> 1; - v2 = projectile_bomb_x_speed[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - BlockGetSomePos1(k); + int32 amt = INT16_SHL8(projectile_bomb_x_speed[v1]); + uint16 some_pos = BlockGetSomePos1(k); uint16 prod = Mult8x8((uint16)(projectile_y_pos[v1] - projectile_y_radius[v1]) >> 4, room_width_in_blocks); - uint16 v3 = projectile_bomb_x_subpos[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - uint16 v5 = R18_ + v3; - projectile_bomb_x_subpos[v1] = v5; - R22_ = v5; - uint16 v6 = R20_ + v4 + projectile_x_pos[v1], v7; - projectile_x_pos[v1] = v6; - R24_ = v6; - if ((R20_ & 0x8000) != 0) - v7 = v6 - projectile_x_radius[v1]; + AddToHiLo(&projectile_x_pos[v1], &projectile_bomb_x_subpos[v1], amt); + //r22 = projectile_bomb_x_subpos[v1]; + uint16 r24 = projectile_x_pos[v1]; + if (amt < 0) + v7 = projectile_x_pos[v1] - projectile_x_radius[v1]; else - v7 = projectile_x_radius[v1] + v6 - 1; - R28_ = v7; - v8 = 2 * (prod + (v7 >> 4)); - if (sign16(R38 - 16)) { - v9 = HIBYTE(projectile_y_pos[v1]); - if (v9 >= 0 - && (int16)((uint8)v9 - room_height_in_scrolls) < 0 - && (int16)(HIBYTE(R28_) - room_width_in_scrolls) < 0) { - v10 = v8; - do { - BlockShotReactHoriz(v10); - v10 += room_width_in_blocks * 2; - --R38; - } while ((R38 & 0x8000) == 0); - } + v7 = projectile_x_radius[v1] + projectile_x_pos[v1] - 1; + uint16 R28 = v7; + uint16 v8 = 2 * (prod + (v7 >> 4)); + if (!sign16(some_pos - 16)) + return 0; + + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = some_pos, .ci_r28 = R28, .ci_r30 = 0, .ci_r38 = some_pos, .ci_r40 = some_pos }; + uint8 v9 = HIBYTE(projectile_y_pos[v1]); + if (!sign8(v9) && (int16)(v9 - room_height_in_scrolls) < 0 && (int16)(HIBYTE(R28) - room_width_in_scrolls) < 0) { + do { + BlockShotReactHoriz(&ci, v8); + v8 += room_width_in_blocks * 2; + } while ((--ci.ci_r38 & 0x8000) == 0); } return 0; } uint8 BlockCollWaveBeamVert(uint16 k) { // 0x94A3E4 - int16 v2; - int16 v8; - int16 v9; - int8 v10; - int16 v11; + uint16 v7; - R30_ = 0; - R18_ = 0; - R20_ = 0; int v1 = k >> 1; - v2 = projectile_bomb_y_speed[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - BlockGetSomePos2(k); - uint16 v3 = projectile_bomb_y_subpos[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - uint16 v5 = R18_ + v3; - projectile_bomb_y_subpos[v1] = v5; - R22_ = v5; - uint16 v6 = R20_ + v4 + projectile_y_pos[v1], v7; - projectile_y_pos[v1] = v6; - R24_ = v6; - if ((R20_ & 0x8000) != 0) - v7 = v6 - projectile_y_radius[v1]; + int32 amt = INT16_SHL8(projectile_bomb_y_speed[v1]); + uint16 some_pos = BlockGetSomePos2(k); + AddToHiLo(&projectile_y_pos[v1], &projectile_bomb_y_subpos[v1], amt); + //r22 = projectile_bomb_y_subpos[v1]; + uint16 r24 = projectile_y_pos[v1]; + if (amt < 0) + v7 = projectile_y_pos[v1] - projectile_y_radius[v1]; else - v7 = projectile_y_radius[v1] + v6 - 1; - R28_ = v7; + v7 = projectile_y_radius[v1] + projectile_y_pos[v1] - 1; + uint16 R28 = v7; uint16 prod = Mult8x8(v7 >> 4, room_width_in_blocks); - v8 = (uint16)(projectile_x_pos[v1] - projectile_x_radius[v1]) >> 4; - v9 = 2 * (prod + v8); - if (sign16(R38 - 16)) { - v10 = HIBYTE(projectile_x_pos[v1]); - if (v10 >= 0 - && (int16)((uint8)v10 - room_width_in_scrolls) < 0 - && (int16)(HIBYTE(R28_) - room_height_in_scrolls) < 0) { - v11 = v9; - do { - BlockShotReactVert(v11); - v11 += 2; - --R38; - } while ((R38 & 0x8000) == 0); - } + uint16 v8 = (uint16)(projectile_x_pos[v1] - projectile_x_radius[v1]) >> 4; + uint16 v9 = 2 * (prod + v8); + if (!sign16(some_pos - 16)) + return 0; + uint8 v10 = HIBYTE(projectile_x_pos[v1]); + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = some_pos, .ci_r28 = R28, .ci_r30 = 0, .ci_r38 = some_pos, .ci_r40 = some_pos }; + if (!sign8(v10) && (int16)(v10 - room_width_in_scrolls) < 0 && (int16)(HIBYTE(R28) - room_height_in_scrolls) < 0) { + do { + BlockShotReactVert(&ci, v9); + v9 += 2; + } while ((--ci.ci_r38 & 0x8000) == 0); } return 0; } uint8 BlockCollMissileHoriz(uint16 k) { // 0x94A46F - int16 v2; - - R30_ = 1; - R38 = 0; - R26_ = 0; - R18_ = 0; - R20_ = 0; int v1 = k >> 1; - v2 = projectile_bomb_x_speed[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; + int32 amt = INT16_SHL8(projectile_bomb_x_speed[v1]); uint16 prod = Mult8x8(projectile_y_pos[v1] >> 4, room_width_in_blocks); + AddToHiLo(&projectile_x_pos[v1], &projectile_bomb_x_subpos[v1], amt); uint16 v3 = projectile_bomb_x_subpos[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - uint16 v5 = R18_ + v3; - projectile_bomb_x_subpos[v1] = v5; - R22_ = v5; - uint16 v6 = R20_ + v4 + projectile_x_pos[v1]; - projectile_x_pos[v1] = v6; - R24_ = v6; - R28_ = v6; - uint16 v7 = 2 * (prod + (v6 >> 4)); - if ((int16)(HIBYTE(R24_) - room_width_in_scrolls) >= 0 || !(BlockShotReactHoriz(v7) & 1)) + //r22 = projectile_bomb_x_subpos[v1]; + uint16 r24 = projectile_x_pos[v1]; + uint16 r28 = r24; + uint16 v7 = 2 * (prod + (projectile_x_pos[v1] >> 4)); + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = 0, .ci_r28 = r28, .ci_r30 = 1, .ci_r38 = 0 }; + if ((int16)(HIBYTE(r24) - room_width_in_scrolls) >= 0 || !BlockShotReactHoriz(&ci, v7)) return 0; KillProjectile(k); return 1; } uint8 BlockCollMissileVert(uint16 k) { // 0x94A4D9 - int16 v2; - int16 v7; - - R30_ = 1; - R38 = 0; - R26_ = 0; - R18_ = 0; - R20_ = 0; int v1 = k >> 1; - v2 = projectile_bomb_y_speed[v1]; - if (v2 < 0) - --R20_; - R19_ = v2; - uint16 v3 = projectile_bomb_y_subpos[v1]; - bool v4 = __CFADD__uint16(R18_, v3); - uint16 v5 = R18_ + v3; - projectile_bomb_y_subpos[v1] = v5; - R22_ = v5; - uint16 v6 = R20_ + v4 + projectile_y_pos[v1]; - projectile_y_pos[v1] = v6; - R24_ = v6; - R28_ = v6; - uint16 prod = Mult8x8(v6 >> 4, room_width_in_blocks); - v7 = projectile_x_pos[v1] >> 4; + int32 amt = INT16_SHL8(projectile_bomb_y_speed[v1]); + AddToHiLo(&projectile_y_pos[v1], &projectile_bomb_y_subpos[v1], amt); + //2r22 = projectile_bomb_y_subpos[v1]; + uint16 r24 = projectile_y_pos[v1]; + uint16 r28 = r24; + uint16 prod = Mult8x8(projectile_y_pos[v1] >> 4, room_width_in_blocks); + uint16 v7 = projectile_x_pos[v1] >> 4; uint16 v8 = 2 * (prod + v7); - if ((int16)(HIBYTE(R24_) - room_height_in_scrolls) >= 0 || !(BlockShotReactVert(v8) & 1)) + CollInfo ci = { .ci_r18_r20 = amt, .ci_r24 = r24, .ci_r26 = 0, .ci_r28 = r28, .ci_r30 = 1, .ci_r38 = 0 }; + if ((int16)(HIBYTE(r24) - room_height_in_scrolls) >= 0 || !BlockShotReactVert(&ci, v8)) return 0; KillProjectile(k); return 1; } -uint8 BlockShotReactVert_Slope_NonSquare(void) { // 0x94A543 - int16 v2; - - uint16 v0 = cur_block_index; - uint16 v1 = projectile_index; - uint16 div = SnesDivide(cur_block_index, room_width_in_blocks); - v2 = projectile_y_pos[v1 >> 1] >> 4; - if (v2 == div) - return BlockShotReact_Slope_NonSquare(v1, v0) & 1; - else - return 0; -} - -uint8 BlockShotReactHoriz_Slope_NonSquare(void) { // 0x94A569 - int16 v2; - - uint16 v0 = cur_block_index; - uint16 v1 = projectile_index; - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - v2 = projectile_x_pos[v1 >> 1] >> 4; - if (v2 == mod) - return BlockShotReact_Slope_NonSquare(v1, v0) & 1; - else - return 0; -} - -uint8 BlockShotReact_Slope_NonSquare(uint16 j, uint16 k) { // 0x94A58F - int16 v3; - int16 v5; - uint16 v2; - - uint16 temp_collision_DD6 = 16 * (BTS[k] & 0x1F); - if ((BTS[k] & 0x40) != 0) - v2 = projectile_x_pos[j >> 1] ^ 0xF; - else - v2 = projectile_x_pos[j >> 1]; - uint16 v6 = temp_collision_DD6 + (v2 & 0xF); - if (!(BTS[k] & 0x80)) { - uint16 temp_collision_DD4 = projectile_y_pos[j >> 1] & 0xF; - v5 = kAlignYPos_Tab0[v6] & 0x1F; - if ((int16)(v5 - temp_collision_DD4) < 0 || v5 == temp_collision_DD4) { - R38 = 0; - R40 = 0; - return 1; - } else { - return 0; - } +static uint8 BlockShotReact_Slope_NonSquare(CollInfo *ci, uint16 j, uint16 k) { // 0x94A58F + uint16 v2 = (projectile_x_pos[j >> 1] & 0xf) ^ ((BTS[k] & 0x40) != 0 ? 0xf : 0); + uint16 v4 = (projectile_y_pos[j >> 1] & 0xf) ^ ((BTS[k] & 0x80) != 0 ? 0xf : 0); + uint16 v5 = kAlignYPos_Tab0[16 * (BTS[k] & 0x1F) + (v2 & 0xF)] & 0x1F; + if ((int16)(v5 - v4) <= 0) { + ci->ci_r38 = 0; + ci->ci_r40 = 0; + return 1; } else { - uint16 temp_collision_DD4 = projectile_y_pos[j >> 1] & 0xF ^ 0xF; - v3 = kAlignYPos_Tab0[v6] & 0x1F; - if ((int16)(v3 - temp_collision_DD4) < 0 || v3 == temp_collision_DD4) { - R38 = 0; - R40 = 0; - return 1; - } else { - return 0; - } + return 0; } } +static uint8 BlockShotReactVert_Slope_NonSquare(CollInfo *ci) { // 0x94A543 + uint16 v0 = cur_block_index; + uint16 v1 = projectile_index; + uint16 div = SnesDivide(cur_block_index, room_width_in_blocks); + if ((projectile_y_pos[v1 >> 1] >> 4) == div) + return BlockShotReact_Slope_NonSquare(ci, v1, v0); + else + return 0; +} + +static uint8 BlockShotReactHoriz_Slope_NonSquare(CollInfo *ci) { // 0x94A569 + uint16 v0 = cur_block_index; + uint16 v1 = projectile_index; + uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); + if ((projectile_x_pos[v1 >> 1] >> 4) == mod) + return BlockShotReact_Slope_NonSquare(ci, v1, v0); + else + return 0; +} + uint8 BlockCollSpreadBomb(uint16 k) { // 0x94A621 - static Func_U8 *const kBlockCollSpreadBomb[16] = { - ClearCarry_9, - sub_949D5D, - ClearCarry_9, - ClearCarry_9, - SetCarry_0, - BlockReact_HorizExt, - ClearCarry_9, - ClearCarry_9, - SetCarry_0, - SetCarry_0, - SetCarry_0, - SetCarry_0, - SetCarry_0, - BlockReact_VertExt, - SetCarry_0, - SetCarry_0, + static Func_CollInfo_U8 *const kBlockCollSpreadBomb[16] = { + ClearCarry_9, + sub_949D5D, + ClearCarry_9, + ClearCarry_9, + SetCarry_0, + BlockReact_HorizExt, + ClearCarry_9, + ClearCarry_9, + SetCarry_0, + SetCarry_0, + SetCarry_0, + SetCarry_0, + SetCarry_0, + BlockReact_VertExt, + SetCarry_0, + SetCarry_0, }; - - int v1 = k >> 1; - R26_ = projectile_x_pos[v1]; - R28_ = projectile_y_pos[v1]; - R30_ = 0; - R32_ = 0; + uint16 r26 = projectile_x_pos[v1]; + uint16 r28 = projectile_y_pos[v1]; cur_block_index = 0; - CalculateBlockAt(R26_, R28_, R30_, R32_); + CalculateBlockAt(r26, r28, 0, 0); + CollInfo ci = { .ci_r24 = 0, .ci_r26 = r26, .ci_r28 = r28, .ci_r30 = 0, .ci_r32 = 0 }; if (!projectile_variables[v1]) { - BlockColl_BombExplosion(k); + BlockColl_BombExplosion(&ci, k); return 0; } if (cur_block_index == 0xFFFF) return 1; uint8 rv; do { - rv = kBlockCollSpreadBomb[(level_data[cur_block_index] & 0xF000) >> 12](); + rv = kBlockCollSpreadBomb[(level_data[cur_block_index] & 0xF000) >> 12](&ci); } while (rv & 0x80); return rv; } -uint8 BlockShotReactVert_Slope_Square(uint16 a, uint16 k) { // 0x94A66A +static uint8 BlockShotReactVert_Slope_Square(CollInfo *ci, uint16 a, uint16 k) { // 0x94A66A uint16 temp_collision_DD4 = 4 * a; uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R28_ & 8) >> 3)); - if (!R30_) { - if (!R26_) { - int v3 = projectile_index >> 1; - if (((projectile_y_pos[v3] - projectile_y_radius[v3]) & 8) != 0 - || !kTab948E54[v2]) { + uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((ci->ci_r28 & 8) >> 3)); + int v3 = projectile_index >> 1; + if (!ci->ci_r30) { + if (!ci->ci_r26) { + if (((projectile_y_pos[v3] - projectile_y_radius[v3]) & 8) != 0 || !kTab948E54[v2]) { uint16 v4 = v2 ^ 2; - if (((LOBYTE(projectile_y_radius[v3]) + LOBYTE(projectile_y_pos[v3]) - 1) & 8) == 0 - || !kTab948E54[v4]) { + if (((LOBYTE(projectile_y_radius[v3]) + LOBYTE(projectile_y_pos[v3]) - 1) & 8) == 0 || !kTab948E54[v4]) { return 0; } } return 1; } - if (R38) { - if (R38 == R26_ - && ((projectile_y_pos[projectile_index >> 1] - projectile_y_radius[projectile_index >> 1]) & 8) != 0) { + if (ci->ci_r38) { + if (ci->ci_r38 == ci->ci_r26 && ((projectile_y_pos[v3] - projectile_y_radius[v3]) & 8) != 0) { return kTab948E54[v2 ^ 2] != 0; } - } else if (((LOBYTE(projectile_y_radius[projectile_index >> 1]) + LOBYTE(projectile_y_pos[projectile_index >> 1]) - 1) & 8) == 0) { + } else if (((LOBYTE(projectile_y_radius[v3]) + LOBYTE(projectile_y_pos[v3]) - 1) & 8) == 0) { return kTab948E54[v2] != 0; } if (kTab948E54[v2] != 0) return 1; return kTab948E54[v2 ^ 2] != 0; } - if ((projectile_y_pos[projectile_index >> 1] & 8) != 0) - v2 ^= 2u; + if ((projectile_y_pos[v3] & 8) != 0) + v2 ^= 2; return kTab948E54[v2] != 0; } - -uint8 BlockShotReactHoriz_Slope_Square(uint16 a, uint16 k) { // 0x94A71A +static uint8 BlockShotReactHoriz_Slope_Square(CollInfo *ci, uint16 a, uint16 k) { // 0x94A71A uint16 temp_collision_DD4 = 4 * a; uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R28_ & 8) >> 2)); - if (!R30_) { - if (!R26_) { + uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((ci->ci_r28 & 8) >> 2)); + if (!ci->ci_r30) { + if (!ci->ci_r26) { int v3 = projectile_index >> 1; - if (((projectile_x_pos[v3] - projectile_x_radius[v3]) & 8) != 0 - || kTab948E54[v2] == 0) { + if (((projectile_x_pos[v3] - projectile_x_radius[v3]) & 8) != 0 || kTab948E54[v2] == 0) { uint16 v4 = v2 ^ 1; - if (((LOBYTE(projectile_x_radius[v3]) + LOBYTE(projectile_x_pos[v3]) - 1) & 8) == 0 - || kTab948E54[v4] == 0) { + if (((LOBYTE(projectile_x_radius[v3]) + LOBYTE(projectile_x_pos[v3]) - 1) & 8) == 0 || kTab948E54[v4] == 0) { return 0; } } return 1; } - if (R38) { - if (R38 == R26_ - && ((projectile_x_pos[projectile_index >> 1] - projectile_x_radius[projectile_index >> 1]) & 8) != 0) { + if (ci->ci_r38) { + if (ci->ci_r38 == ci->ci_r26 && ((projectile_x_pos[projectile_index >> 1] - projectile_x_radius[projectile_index >> 1]) & 8) != 0) { return kTab948E54[v2 ^ 1] != 0; } } else if (((LOBYTE(projectile_x_radius[projectile_index >> 1]) + LOBYTE(projectile_x_pos[projectile_index >> 1]) - 1) & 8) == 0) { @@ -2322,116 +2002,93 @@ uint8 BlockShotReactHoriz_Slope_Square(uint16 a, uint16 k) { // 0x94A71A return kTab948E54[v2 ^ 1] != 0; } if ((projectile_x_pos[projectile_index >> 1] & 8) != 0) - v2 ^= 1u; + v2 ^= 1; return kTab948E54[v2] != 0; } - -uint8 ClearCarryZero(void) { // 0x94A7C9 +static uint8 ClearCarryZero(CollInfo *ci) { // 0x94A7C9 return 0; } -uint8 ClearCarrySetZero(void) { // 0x94A7CD +static uint8 SetCarryClearOvf(CollInfo *ci) { // 0x94A7CD return 1; } -uint8 BlockReactGrapple_GrappleBlock(void) { // 0x94A7D1 +static uint8 BlockReactGrapple_GrappleBlock(CollInfo *ci) { // 0x94A7D1 static const uint16 kBlockReactGrapple_GrappleBlockPlm[4] = { 0xd0d8, 0xd0dc, 0xd0e0, 0xd0d8, }; - - int8 v0; - - grapple_beam_flags &= ~0x8000u; - v0 = BTS[cur_block_index]; - if (v0 < 0) + grapple_beam_flags &= ~0x8000; + if (BTS[cur_block_index] & 0x80) return 0; else - return SpawnPLM(kBlockReactGrapple_GrappleBlockPlm[v0 & 0x7F]); + return SpawnPLM(kBlockReactGrapple_GrappleBlockPlm[BTS[cur_block_index]]); } -uint8 BlockReactGrapple_SpikeBlock(void) { // 0x94A7FD +static uint8 BlockReactGrapple_SpikeBlock(CollInfo *ci) { // 0x94A7FD static const uint16 kBlockReactGrapple_SpikeBlockPlm[16] = { - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e8, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, - 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e8, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, + 0xd0e4, }; - int8 v0; - - v0 = BTS[cur_block_index]; - if (v0 < 0) + if (BTS[cur_block_index] & 0x80) return 0; else - return SpawnPLM(kBlockReactGrapple_SpikeBlockPlm[v0 & 0x7F]); + return SpawnPLM(kBlockReactGrapple_SpikeBlockPlm[BTS[cur_block_index]]); } uint8 BlockCollGrappleBeam(void) { // 0x94A85B - uint8 result; - - *(uint16 *)((uint8 *)&grapple_beam_tmpD82 + 1) = grapple_beam_extension_x_velocity; - *(uint32 *)&grapple_beam_tmpD82 >>= 2; - if ((grapple_beam_extension_x_velocity & 0x8000) != 0) - grapple_beam_tmpD84 |= 0xFFC0u; - *(uint16 *)((uint8 *)&grapple_beam_y_quarter_subvel + 1) = grapple_beam_extension_y_velocity; - - *(uint32 *)&grapple_beam_y_quarter_subvel >>= 2; - if ((grapple_beam_extension_y_velocity & 0x8000) != 0) - grapple_beam_y_quarter_vel |= 0xFFC0u; - grapple_beam_tmpD8A = 4; - while (1) { - uint16 v0 = (__PAIR32__(grapple_beam_tmpD84, grapple_beam_tmpD82) + __PAIR32__(grapple_beam_end_x_offset, grapple_beam_end_x_suboffset)) >> 16; - grapple_beam_end_x_suboffset += grapple_beam_tmpD82; - grapple_beam_end_x_offset = v0; - uint16 v1 = (__PAIR32__(grapple_beam_y_quarter_vel, grapple_beam_y_quarter_subvel) + __PAIR32__(grapple_beam_end_y_offset, grapple_beam_end_y_suboffset)) >> 16; - grapple_beam_end_y_suboffset += grapple_beam_y_quarter_subvel; - grapple_beam_end_y_offset = v1; - grapple_beam_end_x_subpos = grapple_beam_end_x_suboffset + samus_x_subpos; - grapple_beam_end_x_pos = grapple_beam_origin_x_offset + ((__PAIR32__(grapple_beam_end_x_offset, grapple_beam_end_x_suboffset) + - __PAIR32__(samus_x_pos, samus_x_subpos)) >> 16); - grapple_beam_end_y_subpos = grapple_beam_end_y_suboffset + samus_y_subpos; - grapple_beam_end_y_pos = grapple_beam_origin_y_offset + ((__PAIR32__(v1, grapple_beam_end_y_suboffset) + __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16); + int32 grapple_vel_x = (int16)grapple_beam_extension_x_velocity << 6; + int32 grapple_vel_y = (int16)grapple_beam_extension_y_velocity << 6; + uint8 result = 0; + for(int i = 0; i < 4; i++) { + AddToHiLo(&grapple_beam_end_x_offset, &grapple_beam_end_x_suboffset, grapple_vel_x); + AddToHiLo(&grapple_beam_end_y_offset, &grapple_beam_end_y_suboffset, grapple_vel_y); + SetHiLo(&grapple_beam_end_x_pos, &grapple_beam_end_x_subpos, + __PAIR32__(grapple_beam_end_x_offset, grapple_beam_end_x_suboffset) + __PAIR32__(samus_x_pos, samus_x_subpos) + (grapple_beam_origin_x_offset << 16)); + SetHiLo(&grapple_beam_end_y_pos, &grapple_beam_end_y_subpos, + __PAIR32__(grapple_beam_end_y_offset, grapple_beam_end_y_suboffset) + __PAIR32__(samus_y_pos, samus_y_subpos) + (grapple_beam_origin_y_offset << 16)); result = BlockReactGrapple(); - if ((result & 0x40) != 0 && (result & 1) != 0) - break; - if (!--grapple_beam_tmpD8A) + if ((result & 0x40) != 0 && (result & 1) != 0) { + grapple_beam_end_x_pos = grapple_beam_end_x_pos & 0xFFF0 | 8; + grapple_beam_end_y_pos = grapple_beam_end_y_pos & 0xFFF0 | 8; return result; + } } - grapple_beam_end_x_pos = grapple_beam_end_x_pos & 0xFFF0 | 8; - grapple_beam_end_y_pos = grapple_beam_end_y_pos & 0xFFF0 | 8; return result; } uint8 BlockReactGrapple(void) { // 0x94A91F int16 v0; - static Func_U8 *const kBlockReactGrapple[16] = { + static Func_CollInfo_U8 *const kBlockReactGrapple[16] = { ClearCarryZero, - ClearCarrySetZero, + SetCarryClearOvf, ClearCarryZero, ClearCarryZero, BlockReact_ShootableAir, BlockReact_HorizExt, ClearCarryZero, BlockReact_BombableAir, - ClearCarrySetZero, - ClearCarrySetZero, + SetCarryClearOvf, + SetCarryClearOvf, BlockReactGrapple_SpikeBlock, - ClearCarrySetZero, + SetCarryClearOvf, BlockReact_Shootable, BlockReact_VertExt, BlockReactGrapple_GrappleBlock, @@ -2440,9 +2097,10 @@ uint8 BlockReactGrapple(void) { // 0x94A91F uint16 prod = Mult8x8(grapple_beam_end_y_pos >> 4, room_width_in_blocks); v0 = grapple_beam_end_x_pos >> 4; cur_block_index = prod + v0; + CollInfo ci = { 0 }; uint8 rv; do { - rv = kBlockReactGrapple[(level_data[cur_block_index] & 0xF000) >> 12](); + rv = kBlockReactGrapple[(level_data[cur_block_index] & 0xF000) >> 12](&ci); } while (rv & 0x80); return rv; } @@ -2470,13 +2128,13 @@ const int16 kSinCosTable8bit_Sext[320] = { // 0x94A957 -97, -92, -86, -80, -74, -68, -62, -56, -49, -43, -37, -31, -25, -18, -12, -6, }; -void BlockFunc_A957(void) { +static void BlockFunc_A957(uint16 tmpD82, uint16 tmpD84) { int16 v5; int16 v7; - uint16 v0 = grapple_beam_tmpD82, v2, v3; + uint16 v0 = tmpD82, v2, v3; if ((grapple_beam_flags & 0x8000) == 0) { - int v1 = grapple_beam_tmpD82 >> 1; + int v1 = tmpD82 >> 1; if ((kSinCosTable8bit_Sext[v1 + 64] & 0x8000) != 0) v2 = grapple_beam_end_x_pos & 0xFFF0 | 7; else @@ -2488,21 +2146,20 @@ void BlockFunc_A957(void) { v3 = grapple_beam_end_y_pos & 0xFFF0 | 8; grapple_beam_end_y_pos = v3; } - WriteReg(WRMPYA, grapple_beam_tmpD84); int v4 = v0 >> 1; v5 = kSinCosTable8bit_Sext[v4 + 64]; uint16 v6, v8; if (v5 < 0) { if (v5 == -256) { - v6 = grapple_beam_end_x_pos - grapple_beam_tmpD84; + v6 = grapple_beam_end_x_pos - tmpD84; } else { - uint16 prod = Mult8x8(grapple_beam_tmpD84, -(int8)v5); + uint16 prod = Mult8x8(tmpD84, -(int8)v5); v6 = grapple_beam_end_x_pos - (prod >> 8); } } else if (v5 == 256) { - v6 = grapple_beam_tmpD84 + grapple_beam_end_x_pos; + v6 = tmpD84 + grapple_beam_end_x_pos; } else { - uint16 prod = Mult8x8(grapple_beam_tmpD84, kSinCosTable8bit_Sext[v4 + 64]); + uint16 prod = Mult8x8(tmpD84, kSinCosTable8bit_Sext[v4 + 64]); v6 = grapple_beam_end_x_pos + (prod >> 8); } grapple_beam_grapple_start_x = v6; @@ -2510,59 +2167,60 @@ void BlockFunc_A957(void) { v7 = kSinCosTable8bit_Sext[v4]; if (v7 < 0) { if (v7 == -256) { - v8 = grapple_beam_end_y_pos - grapple_beam_tmpD84; + v8 = grapple_beam_end_y_pos - tmpD84; } else { - uint16 prod = Mult8x8(grapple_beam_tmpD84, -v7); + uint16 prod = Mult8x8(tmpD84, -v7); v8 = grapple_beam_end_y_pos - (prod >> 8); } } else if (v7 == 256) { - v8 = grapple_beam_tmpD84 + grapple_beam_end_y_pos; + v8 = tmpD84 + grapple_beam_end_y_pos; } else { - uint16 prod = Mult8x8(grapple_beam_tmpD84, kSinCosTable8bit_Sext[v4]); + uint16 prod = Mult8x8(tmpD84, kSinCosTable8bit_Sext[v4]); v8 = grapple_beam_end_y_pos + (prod >> 8); } grapple_beam_grapple_start_y = v8; grapple_beam_grapple_start_block_y = (uint8)(v8 >> 4); } -uint8 BlockReact_AA64(void) { // 0x94AA64 - static Func_U8 *const kBlockReactLut_AB90[16] = { - ClearCarry_10, - SetCarry_3, - BlockReact_AA64_SpikeAir, - ClearCarry_10, - ClearCarry_10, - BlockReact_HorizExt, - ClearCarry_10, - ClearCarry_10, - SetCarry_3, - SetCarry_3, - BlockReact_AA64_SpikeBlock, - SetCarry_3, - SetCarry_3, - BlockReact_VertExt, - SetCarry_3, - SetCarry_3, +static uint8 ClearCarry_10(CollInfo *ci) { // 0x94AA9A + return 0; +} + +static uint8 SetCarry_3(CollInfo *ci) { // 0x94AA9C + return 1; +} + +static uint8 BlockReact_AA64(void) { // 0x94AA64 + static Func_CollInfo_U8 *const kBlockReactLut_AB90[16] = { + ClearCarry_10, + SetCarry_3, + BlockReact_AA64_SpikeAir, + ClearCarry_10, + ClearCarry_10, + BlockReact_HorizExt, + ClearCarry_10, + ClearCarry_10, + SetCarry_3, + SetCarry_3, + BlockReact_AA64_SpikeBlock, + SetCarry_3, + SetCarry_3, + BlockReact_VertExt, + SetCarry_3, + SetCarry_3, }; uint16 v0 = grapple_beam_grapple_start_block_x; uint16 RegWord = Mult8x8(grapple_beam_grapple_start_block_y, room_width_in_blocks); cur_block_index = RegWord + v0; + CollInfo ci = { 0 }; uint8 rv; do { - rv = kBlockReactLut_AB90[(level_data[cur_block_index] & 0xF000) >> 12](); + rv = kBlockReactLut_AB90[(level_data[cur_block_index] & 0xF000) >> 12](&ci); } while (rv & 0x80); return rv; } -uint8 ClearCarry_10(void) { // 0x94AA9A - return 0; -} - -uint8 SetCarry_3(void) { // 0x94AA9C - return 1; -} - static const uint16 g_word_94AAD7[16] = { // 0x94AA9E 0, 0, 0, 0, 0, 0, 0, 0, @@ -2576,7 +2234,7 @@ static const uint16 g_word_94AAF7[16] = { 0, 0, 0, 0, }; -uint8 BlockReact_AA64_SpikeAir(void) { +static uint8 BlockReact_AA64_SpikeAir(CollInfo *ci) { int16 v0; int16 v2; @@ -2609,7 +2267,7 @@ static const uint16 g_word_94AB70[16] = { 0, 0, 0, 0, }; -uint8 BlockReact_AA64_SpikeBlock(void) { +static uint8 BlockReact_AA64_SpikeBlock(CollInfo *ci) { int16 v0; int16 v2; @@ -2629,7 +2287,7 @@ uint8 BlockReact_AA64_SpikeBlock(void) { return 1; } -static Func_U8 *const kBlockReactLut_AB90[16] = { // 0x94ABB0 +static Func_CollInfo_U8 *const kBlockReactLut_AB90[16] = { // 0x94ABB0 ClearCarry_10, SetCarry_3, BlockReact_AA64_SpikeAir, @@ -2648,23 +2306,24 @@ static Func_U8 *const kBlockReactLut_AB90[16] = { // 0x94ABB0 SetCarry_3, }; -uint8 BlockFunc_ABB0(void) { +static uint8 BlockFunc_ABB0(void) { uint8 rv; uint16 v0 = grapple_beam_grapple_start_block_x; uint16 RegWord = Mult8x8(grapple_beam_grapple_start_block_y, room_width_in_blocks); cur_block_index = RegWord + v0; + CollInfo ci = { 0 }; do { - rv = kBlockReactLut_AB90[(level_data[cur_block_index] & 0xF000) >> 12](); + rv = kBlockReactLut_AB90[(level_data[cur_block_index] & 0xF000) >> 12](&ci); } while (rv & 0x80); return rv; } -uint8 BlockFunc_ABE6(void) { // 0x94ABE6 +static uint8 BlockFunc_ABE6(uint16 tmpD82) { // 0x94ABE6 uint8 v0; g_word_7E0D98 = 6; - grapple_beam_tmpD84 = grapple_beam_length + 8; + uint16 grapple_beam_tmpD84 = grapple_beam_length + 8; while (1) { - BlockFunc_A957(); + BlockFunc_A957(tmpD82, grapple_beam_tmpD84); v0 = BlockFunc_ABB0() & 1; if (v0) break; @@ -2676,9 +2335,9 @@ uint8 BlockFunc_ABE6(void) { // 0x94ABE6 } void BlockFunc_AC11(void) { // 0x94AC11 - grapple_beam_tmpD82 = 2 * grapple_beam_end_angle; - grapple_beam_tmpD84 = grapple_beam_length; - BlockFunc_A957(); + uint16 grapple_beam_tmpD82 = 2 * grapple_beam_end_angle_hi; + uint16 grapple_beam_tmpD84 = grapple_beam_length; + BlockFunc_A957(grapple_beam_tmpD82, grapple_beam_tmpD84); x_pos_of_start_of_grapple_beam = grapple_beam_grapple_start_x; y_pos_of_start_of_grapple_beam = grapple_beam_grapple_start_y; } @@ -2686,109 +2345,90 @@ void BlockFunc_AC11(void) { // 0x94AC11 uint8 BlockFunc_AC31(void) { // 0x94AC31 if (!grapple_beam_length_delta) return 0; + + uint16 end = grapple_beam_length_delta + grapple_beam_length; if ((grapple_beam_length_delta & 0x8000) != 0) { - uint16 v0 = grapple_beam_length_delta + grapple_beam_length; - if ((uint16)(grapple_beam_length_delta + grapple_beam_length) < 8u) { + if (end < 8) { grapple_beam_length_delta = 0; - v0 = 8; + end = 8; } - grapple_beam_varD8C = v0; - grapple_beam_varD8E = 8; - grapple_beam_tmpD82 = 2 * grapple_beam_end_angle; - uint16 v1 = grapple_beam_length; - if (grapple_beam_length == grapple_beam_varD8C) { -LABEL_8: - grapple_beam_length = grapple_beam_varD8C; - return 0; + int increment = 8; + uint16 grapple_beam_tmpD82 = 2 * grapple_beam_end_angle_hi; + for (uint16 v1 = grapple_beam_length; v1 != end; v1--) { + uint16 grapple_beam_tmpD84 = increment + v1 - 1; + BlockFunc_A957(grapple_beam_tmpD82, grapple_beam_tmpD84); + if (BlockReact_AA64()) { + grapple_beam_length = v1; + return 1; + } } - while (1) { - grapple_beam_tmpD8A = v1; - grapple_beam_tmpD84 = grapple_beam_varD8E + v1 - 1; - BlockFunc_A957(); - if (BlockReact_AA64() & 1) - goto LABEL_9; - v1 = --grapple_beam_tmpD8A; - if (grapple_beam_tmpD8A == grapple_beam_varD8C) - goto LABEL_8; + grapple_beam_length = end; + return 0; + } else { + if (end >= 63) { + grapple_beam_length_delta = 0; + end = 63; } + int increment = 56; + uint16 grapple_beam_tmpD82 = 2 * grapple_beam_end_angle_hi; + for (uint16 v1 = grapple_beam_length; v1 != end; v1++) { + uint16 grapple_beam_tmpD84 = increment + v1 + 1; + BlockFunc_A957(grapple_beam_tmpD82, grapple_beam_tmpD84); + if (BlockReact_AA64()) { + grapple_beam_length = v1; + return 1; + } + } + grapple_beam_length = end; + return 0; } - uint16 v3; - v3 = grapple_beam_length_delta + grapple_beam_length; - if ((uint16)(grapple_beam_length_delta + grapple_beam_length) >= 0x3F) { - grapple_beam_length_delta = 0; - v3 = 63; - } - grapple_beam_varD8C = v3; - grapple_beam_varD8E = 56; - grapple_beam_tmpD82 = 2 * grapple_beam_end_angle; - uint16 v4; - v4 = grapple_beam_length; - if (grapple_beam_length != grapple_beam_varD8C) { - while (1) { - grapple_beam_tmpD8A = v4; - grapple_beam_tmpD84 = grapple_beam_varD8E + v4 + 1; - BlockFunc_A957(); - if (BlockReact_AA64() & 1) - break; - v4 = ++grapple_beam_tmpD8A; - if (grapple_beam_tmpD8A == grapple_beam_varD8C) - goto LABEL_15; - } -LABEL_9: - grapple_beam_length = grapple_beam_tmpD8A; - return 1; - } -LABEL_15: - grapple_beam_length = grapple_beam_varD8C; - return 0; } uint8 HandleMovementAndCollForSamusGrapple(void) { // 0x94ACFE + uint16 prod16; int16 v4; int16 v7; uint16 v3, v6; - + uint16 grapple_beam_tmpD86, grapple_beam_tmpD88; + uint16 tmpD9C; uint16 v0 = 256; if ((grapple_beam_flags & 1) != 0) v0 = 160; uint16 v1 = grapple_beam_unkD2E + grapple_beam_unkD26; if ((int16)(grapple_beam_unkD2E + grapple_beam_unkD26) >= 0) { - Multiply16x16(v1, v0); - if (!*(uint16 *)((uint8 *)&mult_product_lo + 1)) + prod16 = Multiply16x16(v1, v0) >> 8; + if (!prod16) return 0; - g_word_7E0D9C = *(uint16 *)((uint8 *)&mult_product_lo + 1); - grapple_beam_y_quarter_vel = 2 - * ((uint16)(*(uint16 *)&grapple_beam_end_subangle - + *(uint16 *)((uint8 *)&mult_product_lo + 1)) >> 8); - grapple_beam_tmpD84 = grapple_beam_length; + tmpD9C = prod16; + grapple_beam_tmpD88 = 2 * ((uint16)(grapple_beam_end_angle16 + prod16) >> 8); uint16 v2; - v2 = 2 * grapple_beam_end_angle; - if (v2 != grapple_beam_y_quarter_vel) { + v2 = 2 * grapple_beam_end_angle_hi; + if (v2 != grapple_beam_tmpD88) { while (1) { - grapple_beam_y_quarter_subvel = v2; - grapple_beam_tmpD82 = (v2 + 2) & 0x1FF; - if (BlockFunc_ABE6() & 1) + grapple_beam_tmpD86 = v2; + uint16 grapple_beam_tmpD82 = (v2 + 2) & 0x1FF; + if (BlockFunc_ABE6(grapple_beam_tmpD82) & 1) break; - v2 = (grapple_beam_y_quarter_subvel + 2) & 0x1FF; - if (v2 == grapple_beam_y_quarter_vel) + v2 = (grapple_beam_tmpD86 + 2) & 0x1FF; + if (v2 == grapple_beam_tmpD88) goto LABEL_12; } LOBYTE(v4) = 0; - HIBYTE(v4) = grapple_beam_y_quarter_subvel >> 1; - *(uint16 *)&grapple_beam_end_subangle = v4 | 0x80; + HIBYTE(v4) = grapple_beam_tmpD86 >> 1; + grapple_beam_end_angle16 = v4 | 0x80; grapple_beam_end_angles_mirror = v4 | 0x80; if (g_word_7E0D98 != 6 && g_word_7E0D98 != 5 || grapple_beam_length != 8) goto LABEL_39; LABEL_23: - grapple_beam_unkD36 |= 0x8000u; + grapple_beam_unkD36 |= 0x8000; grapple_beam_unkD26 = 0; grapple_beam_unkD2E = 0; return 1; } LABEL_12: - *(uint16 *)&grapple_beam_end_subangle += g_word_7E0D9C; - grapple_beam_end_angles_mirror = *(uint16 *)&grapple_beam_end_subangle; - grapple_beam_unkD36 &= ~0x8000u; + grapple_beam_end_angle16 += tmpD9C; + grapple_beam_end_angles_mirror = grapple_beam_end_angle16; + grapple_beam_unkD36 &= ~0x8000; if ((--grapple_beam_unkD30 & 0x8000) != 0) grapple_beam_unkD30 = 0; if ((grapple_beam_unkD2E & 0x8000) == 0) { @@ -2806,21 +2446,18 @@ LABEL_19: v3 = 0; goto LABEL_19; } - Multiply16x16(-v1, v0); - if (!*(uint16 *)((uint8 *)&mult_product_lo + 1)) + prod16 = Multiply16x16(-v1, v0) >> 8; + if (!prod16) return 0; - g_word_7E0D9C = -*(uint16 *)((uint8 *)&mult_product_lo + 1); - grapple_beam_y_quarter_vel = 2 - * ((uint16)(*(uint16 *)&grapple_beam_end_subangle - - *(uint16 *)((uint8 *)&mult_product_lo + 1)) >> 8); - grapple_beam_tmpD84 = grapple_beam_length; + tmpD9C = -prod16; + grapple_beam_tmpD88 = 2 * ((uint16)(grapple_beam_end_angle16 - prod16) >> 8); uint16 v5; - v5 = 2 * grapple_beam_end_angle; - if (v5 == grapple_beam_y_quarter_vel) { + v5 = 2 * grapple_beam_end_angle_hi; + if (v5 == grapple_beam_tmpD88) { LABEL_28: - *(uint16 *)&grapple_beam_end_subangle += g_word_7E0D9C; - grapple_beam_end_angles_mirror = *(uint16 *)&grapple_beam_end_subangle; - grapple_beam_unkD36 &= ~0x8000u; + grapple_beam_end_angle16 += tmpD9C; + grapple_beam_end_angles_mirror = grapple_beam_end_angle16; + grapple_beam_unkD36 &= ~0x8000; if ((--grapple_beam_unkD30 & 0x8000) != 0) grapple_beam_unkD30 = 0; if ((grapple_beam_unkD2E & 0x8000) == 0) { @@ -2839,17 +2476,17 @@ LABEL_35: goto LABEL_35; } while (1) { - grapple_beam_y_quarter_subvel = v5; - grapple_beam_tmpD82 = (v5 - 2) & 0x1FF; - if (BlockFunc_ABE6() & 1) + grapple_beam_tmpD86 = v5; + uint16 grapple_beam_tmpD82 = (v5 - 2) & 0x1FF; + if (BlockFunc_ABE6(grapple_beam_tmpD82) & 1) break; - v5 = (grapple_beam_y_quarter_subvel - 2) & 0x1FF; - if (v5 == grapple_beam_y_quarter_vel) + v5 = (grapple_beam_tmpD86 - 2) & 0x1FF; + if (v5 == grapple_beam_tmpD88) goto LABEL_28; } LOBYTE(v7) = 0; - HIBYTE(v7) = grapple_beam_y_quarter_subvel >> 1; - *(uint16 *)&grapple_beam_end_subangle = v7 | 0x80; + HIBYTE(v7) = grapple_beam_tmpD86 >> 1; + grapple_beam_end_angle16 = v7 | 0x80; grapple_beam_end_angles_mirror = v7 | 0x80; if ((g_word_7E0D98 == 6 || g_word_7E0D98 == 5) && grapple_beam_length == 8) goto LABEL_23; @@ -2861,7 +2498,7 @@ LABEL_39: } uint8 BlockFunc_AEE3(void) { // 0x94AEE3 - if (((grapple_beam_unkD26 ^ *(uint16 *)&grapple_beam_end_subangle) & 0x8000) != 0) { + if (((grapple_beam_unkD26 ^ grapple_beam_end_angle16) & 0x8000) != 0) { grapple_beam_unkD38 = 0; return 1; } else { @@ -2873,10 +2510,6 @@ uint8 BlockFunc_AEE3(void) { // 0x94AEE3 } } -uint8 ClearCarry_11(void) { // 0x94AF0B - return 0; -} - void GrappleFunc_AF87(void) { // 0x94AF87 for (int i = 30; i >= 0; i -= 8) { int v1 = i >> 1; @@ -2891,6 +2524,10 @@ void GrappleFunc_AF87(void) { // 0x94AF87 } } +uint16 GrappleInstr_Goto(uint16 j) { // 0x94B0F4 + return *(uint16 *)RomPtr_94(j); +} + uint16 CallGrappleInstr(uint32 ea, uint16 j) { switch (ea) { case fnGrappleInstr_Goto: return GrappleInstr_Goto(j); // 0x94b0f4 @@ -2899,128 +2536,66 @@ uint16 CallGrappleInstr(uint32 ea, uint16 j) { } void HandleGrappleBeamGfx(void) { // 0x94AFBA - int16 RegWord; // dx + int v1 = CalculateAngleFromXY(grapple_beam_end_x_pos - x_pos_of_start_of_grapple_beam_prevframe, + grapple_beam_end_y_pos - y_pos_of_start_of_grapple_beam_prevframe); - R18_ = grapple_beam_end_x_pos - x_pos_of_start_of_grapple_beam_prevframe; - R20_ = grapple_beam_end_y_pos - y_pos_of_start_of_grapple_beam_prevframe; - uint16 v0 = 2 * CalculateAngleFromXY(); - R26_ = 0; - R28_ = 0; - int v1 = v0 >> 1; - uint16 v2 = 8 * kSinCosTable8bit_Sext[v1 + 64]; - if ((kSinCosTable8bit_Sext[v1 + 64] & 0x1000) != 0) - --R28_; - *(uint16 *)((uint8 *)&R26_ + 1) = v2; - R30_ = 0; - R32_ = 0; - uint16 v3 = 8 * kSinCosTable8bit_Sext[v1]; - if ((kSinCosTable8bit_Sext[v1] & 0x1000) != 0) - --R32_; - *(uint16 *)((uint8 *)&R30_ + 1) = v3; - R38 = (uint16)(*(uint16 *)&grapple_beam_end_subangle & 0x8000) >> 1; - R38 |= 2 * ((*(uint16 *)&grapple_beam_end_subangle ^ R38) & 0x4000 ^ 0x4000); - R20_ = x_pos_of_start_of_grapple_beam_prevframe - layer1_x_pos - 4; - R18_ = 0; - R24_ = y_pos_of_start_of_grapple_beam_prevframe - layer1_y_pos - 4; - R22_ = 0; - if ((grapple_beam_length & 0x8000) == 0) { - RegWord = grapple_beam_length / 8; - if (RegWord >= 0) { - R40 = (RegWord & 0xF) - 1; - uint16 v5 = 30; - do { - int i, v6 = v5 >> 1; - uint16 v10; - if (grapple_segment_anim_instr_timers[v6]-- == 1) { - for (i = grapple_segment_anim_instr_ptrs[v6]; ; ) { - const uint16 *v9 = (const uint16 *)RomPtr_94(i); - v10 = *v9; - if ((*v9 & 0x8000) == 0) - break; - R36 = *v9; - i = CallGrappleInstr(v10 | 0x940000, i + 2); - } - int v11 = v5 >> 1; - grapple_segment_anim_instr_timers[v11] = v10; - grapple_segment_anim_instr_ptrs[v11] = i + 4; - } - if (((R24_ | R20_) & 0xFF00) != 0) + uint32 r28_r26 = (int16)kSinCosTable8bit_Sext[v1 + 64] << 11; + uint32 r32_r30 = (int16)kSinCosTable8bit_Sext[v1] << 11; + + uint16 chr = (grapple_beam_end_angle_hi & 0x80) >> 1; + chr |= 2 * ((grapple_beam_end_angle_hi ^ chr) & 0x40 ^ 0x40); + chr <<= 8; + + uint32 r20_r18 = (x_pos_of_start_of_grapple_beam_prevframe - layer1_x_pos - 4) << 16; + uint32 r24_r22 = (y_pos_of_start_of_grapple_beam_prevframe - layer1_y_pos - 4) << 16; + if ((grapple_beam_length & 0x8000) != 0) + return; + int n = ((grapple_beam_length / 8) & 0xF) - 1; + int q = 15; + do { + int i; + if (grapple_segment_anim_instr_timers[q]-- == 1) { + const uint16 *v9; + for (i = grapple_segment_anim_instr_ptrs[q]; ; ) { + v9 = (const uint16 *)RomPtr_94(i); + if ((*v9 & 0x8000) == 0) break; - uint16 v12 = *(uint16 *)RomPtr_94(grapple_segment_anim_instr_ptrs[v5 >> 1] - 2); - DrawGrappleOams(v12); - v5 -= 2; - --R40; - } while ((R40 & 0x8000) == 0); - if (samus_pose == kPose_B2_FaceR_Grapple_Air || samus_pose == kPose_B3_FaceL_Grapple_Air) - DrawGrappleOams3(); - else - DrawGrappleOams2(); + i = CallGrappleInstr(*v9 | 0x940000, i + 2); + } + grapple_segment_anim_instr_timers[q] = *v9; + grapple_segment_anim_instr_ptrs[q] = i + 4; } + if (((r24_r22 | r20_r18) & 0xFF000000) != 0) + break; + uint16 v12 = *(uint16 *)RomPtr_94(grapple_segment_anim_instr_ptrs[q] - 2); + DrawGrappleOams(r20_r18 >> 16, r24_r22 >> 16, chr | v12); + r20_r18 += r28_r26; + r24_r22 += r32_r30; + } while (q--, --n >= 0); + if (samus_pose == kPose_B2_FaceR_Grapple_Air || samus_pose == kPose_B3_FaceL_Grapple_Air) { + DrawGrappleOams3(); + } else { + if (((grapple_beam_end_y_pos - layer1_y_pos) & 0xFF00) == 0) + DrawGrappleOams3(); } } -void DrawGrappleOams(uint16 j) { // 0x94B0AA - OamEnt *v2; - unsigned int v3; // kr00_4 - unsigned int v4; // kr04_4 - +static void DrawGrappleOams(uint16 x_r20, uint16 y_r24, uint16 chr_r38) { // 0x94B0AA uint16 v1 = oam_next_ptr; - v2 = gOamEnt(oam_next_ptr); - *(uint16 *)&v2->xcoord = R20_; - v3 = __PAIR32__(R28_, R26_) + __PAIR32__(R20_, R18_); - R20_ = HIWORD(v3); - R18_ = v3; - *(uint16 *)&v2->ycoord = R24_; - v4 = __PAIR32__(R32_, R30_) + __PAIR32__(R24_, R22_); - R24_ = HIWORD(v4); - R22_ = v4; - *(uint16 *)&v2->charnum = R38 | j; + OamEnt *v2 = gOamEnt(oam_next_ptr); + v2->xcoord = x_r20; + v2->ycoord = y_r24; + *(uint16 *)&v2->charnum = chr_r38; oam_next_ptr = v1 + 4; } -uint16 GrappleInstr_Goto(uint16 j) { // 0x94B0F4 - return *(uint16 *)RomPtr_94(j); -} - - -void DrawGrappleOams2(void) { // 0x94B0F9 - int16 v1; - OamEnt *v2; - int16 v4; - - if (((grapple_beam_end_y_pos - layer1_y_pos) & 0xFF00) == 0) { - uint16 v0 = oam_next_ptr; - v1 = grapple_beam_end_x_pos - layer1_x_pos - 4; - v2 = gOamEnt(oam_next_ptr); - *(uint16 *)&v2->xcoord = v1; - if ((v1 & 0x100) != 0) { - int v3 = v0 >> 1; - R34 = kOamExtra_Address_And_X8Large[v3]; - v4 = kOamExtra_X8Small_And_Large[v3] | *(uint16 *)RomPtr_RAM(R34); - *(uint16 *)RomPtr_RAM(R34) = v4; - } - *(uint16 *)&v2->ycoord = grapple_beam_end_y_pos - layer1_y_pos - 4; - *(uint16 *)&v2->charnum = 14880; - oam_next_ptr = v0 + 4; - } -} - -void DrawGrappleOams3(void) { // 0x94B14B - int16 v1; - OamEnt *v2; - int16 v4; - - uint16 v0 = oam_next_ptr; - v1 = grapple_beam_end_x_pos - layer1_x_pos - 4; - v2 = gOamEnt(oam_next_ptr); - *(uint16 *)&v2->xcoord = v1; - if ((v1 & 0x100) != 0) { - int v3 = v0 >> 1; - R34 = kOamExtra_Address_And_X8Large[v3]; - v4 = kOamExtra_X8Small_And_Large[v3] | *(uint16 *)RomPtr_RAM(R34); - *(uint16 *)RomPtr_RAM(R34) = v4; - } - *(uint16 *)&v2->ycoord = grapple_beam_end_y_pos - layer1_y_pos - 4; +static void DrawGrappleOams3(void) { // 0x94B14B + uint16 idx = oam_next_ptr; + OamEnt *v2 = gOamEnt(idx); + uint16 x = grapple_beam_end_x_pos - layer1_x_pos - 4; + v2->xcoord = x; + v2->ycoord = grapple_beam_end_y_pos - layer1_y_pos - 4; *(uint16 *)&v2->charnum = 14880; - oam_next_ptr = v0 + 4; -} \ No newline at end of file + oam_ext[idx >> 5] |= (((x & 0x100) >> 8)) << (2 * ((idx >> 2) & 7)); + oam_next_ptr = idx + 4; +} diff --git a/src/sm_9b.c b/src/sm_9b.c index fb72a0c..cfbee0d 100644 --- a/src/sm_9b.c +++ b/src/sm_9b.c @@ -3,7 +3,6 @@ #include "variables.h" #include "funcs.h" - #define g_off_9BA4B3 ((uint16*)RomFixedPtr(0x9ba4b3)) #define g_off_9BA4CB ((uint16*)RomFixedPtr(0x9ba4cb)) #define g_off_9BA4E3 ((uint16*)RomFixedPtr(0x9ba4e3)) @@ -44,7 +43,9 @@ #define kGrappleBeam_Ext_Yvel ((uint16*)RomFixedPtr(0x9bc0ef)) #define kGrappleBeam_Init_EndAngle ((uint16*)RomFixedPtr(0x9bc104)) - +void CallGrappleBeamFunc(uint32 ea); +void GrappleBeamFunc_BE98(void); +void GrappleBeamFunc_FireGoToCancel(void); static const uint8 kDeathAnimationFrames[28] = { 5, 5, 5, 5, 1, 5, 5, 0, 1, @@ -73,16 +74,16 @@ static const uint8 kIsGrappleBannedForMovementType[28] = { }; void ProjectileTrail_Func5(uint16 k, uint16 j) { // 0x9BA3CC - ProjectileInsts_GetValue(k); - if ((ceres_status & 0x8000u) == 0) { + uint16 R22 = ProjectileInsts_GetValue(k); + uint16 r18, r20; + if ((ceres_status & 0x8000) == 0) { int v2 = k >> 1; - R18_ = projectile_x_pos[v2]; - R20_ = projectile_y_pos[v2]; + r18 = projectile_x_pos[v2]; + r20 = projectile_y_pos[v2]; } else { - CalcExplosion_Mode7(k); - uint16 v10 = R18_; - R18_ = layer1_x_pos + R20_; - R20_ = layer1_y_pos + v10; + Point16U pt = CalcExplosion_Mode7(k); + r18 = layer1_x_pos + pt.x; + r20 = layer1_y_pos + pt.y; } int v3 = k >> 1; uint16 v4 = projectile_type[v3], v5; @@ -93,19 +94,19 @@ void ProjectileTrail_Func5(uint16 k, uint16 j) { // 0x9BA3CC } else { v5 = g_off_9BA4B3[projectile_type[v3] & 0xF] + 2 * (projectile_dir[v3] & 0xF); } - uint16 v6 = *(uint16 *)RomPtr_9B(v5) + 4 * R22_; + uint16 v6 = *(uint16 *)RomPtr_9B(v5) + 4 * R22; const uint8 *p = RomPtr_9B(v6); int v7 = j >> 1; - projectiletrail_left_y_pos[v7] = R20_ + (int8)p[1] - 4; - projectiletrail_left_x_pos[v7] = R18_ + (int8)p[0] - 4; - projectiletrail_right_y_pos[v7] = R20_ + (int8)p[3] - 4; - projectiletrail_right_x_pos[v7] = R18_ + (int8)p[2] - 4; + projectiletrail_left_y_pos[v7] = r20 + (int8)p[1] - 4; + projectiletrail_left_x_pos[v7] = r18 + (int8)p[0] - 4; + projectiletrail_right_y_pos[v7] = r20 + (int8)p[3] - 4; + projectiletrail_right_x_pos[v7] = r18 + (int8)p[2] - 4; } void StartSamusDeathAnimation(void) { // 0x9BB3A7 uint16 v0 = samus_movement_type; if (samus_movement_type == 3) - QueueSfx1_Max6(0x32u); + QueueSfx1_Max6(0x32); uint16 v1 = kDeathAnimationFrames[v0]; if (samus_pose_x_dir == 4) samus_pose = kPose_D8_FaceL_CrystalFlashEnd; @@ -131,7 +132,7 @@ uint16 HandleSamusDeathSequence(void) { // 0x9BB441 if (sign16(g_word_7E0DE6 - 4)) QueueTransferOfSamusDeathSequence(2 * g_word_7E0DE6); if (sign16(++g_word_7E0DE6 - 60)) { - bool v0 = (--game_options_screen_index & 0x8000u) != 0; + bool v0 = (--game_options_screen_index & 0x8000) != 0; if (!game_options_screen_index || v0) { if (g_word_7E0DE4) { g_word_7E0DE4 = 0; @@ -162,8 +163,8 @@ void HandleSamusDeathSequence_Helper2(void) { // 0x9BB4B6 } void CopyPalettesForSamusDeath(uint16 v0) { // 0x9BB5CE - int R20 = g_off_9BB6D2[samus_suit_palette_index >> 1]; - const uint16 *v1 = (const uint16 *)RomPtr_9B(R20 + v0); + int r20 = g_off_9BB6D2[samus_suit_palette_index >> 1]; + const uint16 *v1 = (const uint16 *)RomPtr_9B(r20 + v0); memcpy(&palette_buffer[192], RomPtr_9B(*v1), 32); memcpy(&palette_buffer[240], RomPtr_9B(kDeathSequencePals_Suitless[v0 >> 1]), 32); } @@ -199,7 +200,7 @@ void GameState_24_SamusNoHealth_Explosion_1(void) { // 0x9BB710 } uint16 GameState_24_SamusNoHealth_Explosion_2(void) { // 0x9BB758 - bool v0 = (--game_options_screen_index & 0x8000u) != 0; + bool v0 = (--game_options_screen_index & 0x8000) != 0; if (!game_options_screen_index || v0) { if (!sign16(++g_word_7E0DE4 - 9)) { g_word_7E0DE6 = 21; @@ -208,10 +209,10 @@ uint16 GameState_24_SamusNoHealth_Explosion_2(void) { // 0x9BB758 return 1; } if (!substate || sign16(g_word_7E0DE4 - 2)) { - game_options_screen_index = g_byte_9BB823[(uint16)(2 * g_word_7E0DE4)]; - CopyPalettesForSamusDeath(2 * g_byte_9BB823[(uint16)(2 * g_word_7E0DE4) + 1]); + game_options_screen_index = g_byte_9BB823[(2 * g_word_7E0DE4)]; + CopyPalettesForSamusDeath(2 * g_byte_9BB823[(2 * g_word_7E0DE4) + 1]); } else { - game_options_screen_index = g_byte_9BB823[(uint16)(2 * g_word_7E0DE4)]; + game_options_screen_index = g_byte_9BB823[(2 * g_word_7E0DE4)]; } } DrawSamusSuitExploding(); @@ -229,12 +230,12 @@ LABEL_2: } if (grapple_beam_function != FUNC16(GrappleBeamFunc_Inactive) && sign16(grapple_beam_function + 0x3882)) { - v0 = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)); + v0 = kPoseParams[samus_pose].direction_shots_fired; if ((v0 & 0xF0) == 0) { if (v0 == grapple_beam_direction) return; if (grapple_varCF6) { - QueueSfx1_Max6(7u); + QueueSfx1_Max6(7); grapple_beam_function = FUNC16(GrappleBeamFunc_FireGoToCancel); return; } @@ -243,14 +244,6 @@ LABEL_2: } } -void UNUSED_sub_9BB8D5(void) { // 0x9BB8D5 - int16 v0; - - v0 = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)); - if ((v0 & 0xF0) == 0 && v0 != grapple_beam_direction) - grapple_beam_direction = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)); -} - uint8 CheckIfGrappleIsConnectedToBlock(void) { // 0x9BB8F1 grapple_beam_extension_x_velocity = 0; grapple_beam_extension_y_velocity = 0; @@ -260,11 +253,7 @@ uint8 CheckIfGrappleIsConnectedToBlock(void) { // 0x9BB8F1 return 1; } -int ProcessEnemyGrappleBeamColl(uint16 a) { // 0x9BB907 - int16 v1; - uint16 v3; - - v1 = 2 * a; +static int ProcessEnemyGrappleBeamColl(uint16 a, uint16 r18) { // 0x9BB907 switch (a) { case 0: case 2: @@ -276,17 +265,13 @@ int ProcessEnemyGrappleBeamColl(uint16 a) { // 0x9BB907 case 5: return 0; case 6: - R18_ = *((uint16 *)RomPtr_A0(R18_) + 3); + r18 = *((uint16 *)RomPtr_A0(r18) + 3); if ((equipped_items & 0x20) != 0) { - R18_ >>= 1; - R18_ >>= 1; - v3 = R18_; - } else { - if (equipped_items & 1) - R18_ >>= 1; - v3 = R18_; + r18 >>= 2; + } else if (equipped_items & 1) { + r18 >>= 1; } - Samus_DealDamage(v3); + Samus_DealDamage(r18); samus_invincibility_timer = 96; samus_knockback_timer = 5; knockback_x_dir = samus_pose_x_dir == 4; @@ -318,22 +303,16 @@ void HandleConnectingGrapple(void) { // 0x9BB97C grapple_beam_function = FUNC16(GrappleBeamFunc_ConnectedLockedInPlace); grapple_beam_length_delta = 0; } else { - uint16 v0 = 4 * grapple_beam_direction; + int v1 = 2 * grapple_beam_direction; if (samus_y_speed || samus_y_subspeed) { - int v2 = v0 >> 1; - grapple_beam_function = g_off_9BC3EE[v2]; - grapple_beam_tmpD82 = g_off_9BC3EE[v2 + 1]; - CallGrappleNextFunc(grapple_beam_tmpD82 | 0x9B0000); + grapple_beam_function = g_off_9BC3EE[v1]; + CallGrappleNextFunc(g_off_9BC3EE[v1 + 1] | 0x9B0000); + } else if (samus_movement_type == 5) { + grapple_beam_function = g_off_9BC416[v1]; + CallGrappleNextFunc(g_off_9BC416[v1 + 1] | 0x9B0000); } else { - int v1 = v0 >> 1; - if (samus_movement_type == 5) { - grapple_beam_function = g_off_9BC416[v1]; - grapple_beam_tmpD82 = g_off_9BC416[v1 + 1]; - } else { - grapple_beam_function = g_off_9BC3C6[v1]; - grapple_beam_tmpD82 = g_off_9BC3C6[v1 + 1]; - } - CallGrappleNextFunc(grapple_beam_tmpD82 | 0x9B0000); + grapple_beam_function = g_off_9BC3C6[v1]; + CallGrappleNextFunc(g_off_9BC3C6[v1 + 1] | 0x9B0000); } } } @@ -388,17 +367,10 @@ void GrappleNext_CrouchAimLeft(void) { // 0x9BBA29 HandleConnectingGrapple_StuckInPlace(); } -void UNUSED_sub_9BBA31(void) { // 0x9BBA31 - samus_new_pose_interrupted = 172; - HandleConnectingGrapple_StuckInPlace(); -} - void HandleConnectingGrapple_Swinging(void) { // 0x9BBA61 samus_special_transgfx_index = 9; - R18_ = samus_x_pos - grapple_beam_end_x_pos; - R20_ = samus_y_pos - grapple_beam_end_y_pos; - uint16 v0 = swap16(CalculateAngleFromXY()); - *(uint16 *)&grapple_beam_end_subangle = v0; + uint16 v0 = swap16(CalculateAngleFromXY(samus_x_pos - grapple_beam_end_x_pos, samus_y_pos - grapple_beam_end_y_pos)); + grapple_beam_end_angle16 = v0; grapple_beam_end_angles_mirror = v0; grapple_beam_length_delta = 0; if (!sign16(grapple_beam_length - 64)) @@ -408,10 +380,8 @@ void HandleConnectingGrapple_Swinging(void) { // 0x9BBA61 void HandleConnectingGrapple_StuckInPlace(void) { // 0x9BBA9B samus_special_transgfx_index = 10; - R18_ = samus_x_pos - grapple_beam_end_x_pos; - R20_ = samus_y_pos - grapple_beam_end_y_pos; - uint16 v0 = swap16(CalculateAngleFromXY()); - *(uint16 *)&grapple_beam_end_subangle = v0; + uint16 v0 = swap16(CalculateAngleFromXY(samus_x_pos - grapple_beam_end_x_pos, samus_y_pos - grapple_beam_end_y_pos)); + grapple_beam_end_angle16 = v0; grapple_beam_end_angles_mirror = v0; grapple_beam_length_delta = 0; if (!sign16(grapple_beam_length - 64)) @@ -421,8 +391,8 @@ void HandleConnectingGrapple_StuckInPlace(void) { // 0x9BBA9B uint8 HandleSpecialGrappleBeamAngles(void) { // 0x9BBAD5 uint16 v0 = 7; - while (*(uint16 *)&grapple_beam_end_subangle != grapple_beam_special_angles[v0].field_0) { - if ((--v0 & 0x8000u) != 0) + while (grapple_beam_end_angle16 != grapple_beam_special_angles[v0].field_0) { + if ((--v0 & 0x8000) != 0) return 0; } samus_new_pose_interrupted = grapple_beam_special_angles[v0].field_2; @@ -458,10 +428,10 @@ void GrappleBeamFunc_BB64(void) { // 0x9BBB64 else grapple_beam_length = 64; } - if (sign16((grapple_beam_end_angle << 8) - 0x4000) || !sign16((grapple_beam_end_angle << 8) + 0x4000)) + if (sign16((grapple_beam_end_angle_hi << 8) - 0x4000) || !sign16((grapple_beam_end_angle_hi << 8) + 0x4000)) goto LABEL_13; if ((joypad1_lastkeys & 0x200) != 0) { - if (grapple_beam_end_angle << 8 == 0x8000 && !grapple_beam_unkD26) + if (grapple_beam_end_angle_hi << 8 == 0x8000 && !grapple_beam_unkD26) grapple_beam_unkD26 = 256; if (grapple_beam_flags && (grapple_beam_flags & 1) != 0) grapple_beam_unkD2A = g_word_9BC11A >> 1; @@ -473,7 +443,7 @@ LABEL_13: grapple_beam_unkD2A = 0; return; } - if (grapple_beam_end_angle << 8 == 0x8000 && !grapple_beam_unkD26) + if (grapple_beam_end_angle_hi << 8 == 0x8000 && !grapple_beam_unkD26) grapple_beam_unkD26 = -256; if (grapple_beam_flags && (grapple_beam_flags & 1) != 0) grapple_beam_unkD2A = -(g_word_9BC11A >> 1); @@ -483,18 +453,18 @@ LABEL_13: } void GrappleBeamFunc_BC1F(void) { // 0x9BBC1F - if ((*(uint16 *)&grapple_beam_end_subangle & 0xC000) == 0xC000) { + if ((grapple_beam_end_angle16 & 0xC000) == 0xC000) { grapple_beam_unkD2C = -(g_word_9BC11C >> 2); if (grapple_beam_flags && (grapple_beam_flags & 1) != 0) grapple_beam_unkD28 = -(g_word_9BC118 >> 3); else grapple_beam_unkD28 = -(g_word_9BC118 >> 2); - } else if (*(int16 *)&grapple_beam_end_subangle < 0) { - if (grapple_beam_end_angle << 8 == 0x8000) { + } else if (sign16(grapple_beam_end_angle16)) { + if (grapple_beam_end_angle_hi << 8 == 0x8000) { grapple_beam_unkD28 = 0; grapple_beam_unkD2C = 0; uint16 v0 = grapple_beam_unkD26; - if ((grapple_beam_unkD26 & 0x8000u) != 0) + if ((grapple_beam_unkD26 & 0x8000) != 0) v0 = ~(grapple_beam_unkD26 - 1); if (sign16(HIBYTE(v0) - 1)) grapple_beam_unkD26 = 0; @@ -505,7 +475,7 @@ void GrappleBeamFunc_BC1F(void) { // 0x9BBC1F else grapple_beam_unkD28 = -g_word_9BC118; } - } else if ((*(uint16 *)&grapple_beam_end_subangle & 0x4000) != 0) { + } else if ((grapple_beam_end_angle16 & 0x4000) != 0) { grapple_beam_unkD2C = g_word_9BC11C; if (grapple_beam_flags && (grapple_beam_flags & 1) != 0) grapple_beam_unkD28 = g_word_9BC118 >> 1; @@ -522,9 +492,9 @@ void GrappleBeamFunc_BC1F(void) { // 0x9BBC1F void GrappleBeamFunc_BCFF(void) { // 0x9BBCFF grapple_beam_unkD26 += grapple_beam_unkD2A + grapple_beam_unkD28; - if (((grapple_beam_unkD26 ^ *(uint16 *)&grapple_beam_end_subangle) & 0x8000u) != 0) + if (((grapple_beam_unkD26 ^ grapple_beam_end_angle16) & 0x8000) != 0) grapple_beam_unkD26 += grapple_beam_unkD2C; - if ((grapple_beam_unkD26 & 0x8000u) == 0) { + if ((grapple_beam_unkD26 & 0x8000) == 0) { if (grapple_beam_unkD26 >= g_word_9BC11E) grapple_beam_unkD26 = g_word_9BC11E; } else if ((uint16)-grapple_beam_unkD26 >= g_word_9BC11E) { @@ -535,7 +505,7 @@ void GrappleBeamFunc_BCFF(void) { // 0x9BBCFF void GrappleBeamFunc_BD44(void) { // 0x9BBD44 if (grapple_beam_unkD30 && (button_config_jump_a & joypad1_newkeys) != 0) { if (grapple_beam_unkD26) { - if ((grapple_beam_unkD26 & 0x8000u) != 0) { + if ((grapple_beam_unkD26 & 0x8000) != 0) { if (grapple_beam_flags && (grapple_beam_flags & 1) != 0) grapple_beam_unkD2E = -(g_word_9BC120 >> 1); else @@ -564,7 +534,7 @@ LABEL_7: goto LABEL_8; } slow_grabble_scrolling_flag = 0; - if (grapple_beam_end_angle << 8 != 0x8000) + if (grapple_beam_end_angle_hi << 8 != 0x8000) goto LABEL_7; if (sign16(samus_anim_frame - 64)) { samus_anim_frame_timer = 8; @@ -620,31 +590,31 @@ void GrappleBeamFunc_BEEB(void) { // 0x9BBEEB } void GrappleBeamFunc_BF1B(void) { // 0x9BBF1B - R22_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(8 * samus_pose)); + uint16 r22 = kPoseParams[samus_pose].y_offset_to_gfx; uint16 v0 = 2 * grapple_beam_direction; if (samus_pose == kPose_49_FaceL_Moonwalk || samus_pose == kPose_4A_FaceR_Moonwalk || samus_movement_type != 1) { int v1 = v0 >> 1; x_pos_of_start_of_grapple_beam = kGrappleBeam_OriginX_NoRun[v1] + samus_x_pos; x_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1a_offs_NoRun[v1] + samus_x_pos; - y_pos_of_start_of_grapple_beam = kGrappleBeam_OriginY_NoRun[v1] + samus_y_pos - R22_; - y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_NoRun[v1] + samus_y_pos - R22_; + y_pos_of_start_of_grapple_beam = kGrappleBeam_OriginY_NoRun[v1] + samus_y_pos - r22; + y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_NoRun[v1] + samus_y_pos - r22; } else { int v2 = v0 >> 1; x_pos_of_start_of_grapple_beam = kGrappleBeam_OriginX_Run[v2] + samus_x_pos; x_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1a_offs_Run[v2] + samus_x_pos; - y_pos_of_start_of_grapple_beam = kGrappleBeam_OriginY_Run[v2] + samus_y_pos - R22_; - y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_Run[v2] + samus_y_pos - R22_; + y_pos_of_start_of_grapple_beam = kGrappleBeam_OriginY_Run[v2] + samus_y_pos - r22; + y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_Run[v2] + samus_y_pos - r22; } } void UpdateGrappleBeamTilesAndIncrFlameCtr(void) { // 0x9BBFA5 - UpdateGrappleBeamTiles(); + UpdateGrappleBeamTiles(); if (sign16(flare_counter - 120)) ++flare_counter; } void UpdateGrappleBeamTiles(void) { // 0x9BBFBD - if ((--grapple_point_anim_timer & 0x8000u) != 0) { + if ((--grapple_point_anim_timer & 0x8000) != 0) { grapple_point_anim_timer = 5; grapple_point_anim_ptr += 512; if ((int16)(grapple_point_anim_ptr - g_off_9BC344) >= 0) @@ -658,7 +628,7 @@ void UpdateGrappleBeamTiles(void) { // 0x9BBFBD LOBYTE(gVramWriteEntry(v0++)->size) = -102; gVramWriteEntry(v0)->size = 25088; vram_write_queue_tail = v0 + 2; - uint16 v1 = (grapple_beam_end_angle >> 1) & 0xFE; + uint16 v1 = (grapple_beam_end_angle_hi >> 1) & 0xFE; v0 += 2; gVramWriteEntry(v0)->size = 128; v0 += 2; @@ -675,68 +645,44 @@ void HandleGrappleBeamFlare(void) { // 0x9BC036 flare_animation_frame = 16; flare_animation_timer = 3; } - if ((--flare_animation_timer & 0x8000u) != 0) { + if ((--flare_animation_timer & 0x8000) != 0) { uint16 v0 = ++flare_animation_frame; if (kFlareAnimDelays_Main[flare_animation_frame] == 254) { - R18_ = kFlareAnimDelays_Main[(uint16)(flare_animation_frame + 1)]; - flare_animation_frame -= R18_; + flare_animation_frame -= kFlareAnimDelays_Main[(uint16)(flare_animation_frame + 1)]; v0 = flare_animation_frame; } flare_animation_timer = kFlareAnimDelays_Main[v0]; } + uint16 r22; if (samus_pose_x_dir == 4) - R22_ = flare_animation_frame + g_word_93A22B[0]; + r22 = flare_animation_frame + g_word_93A22B[0]; else - R22_ = flare_animation_frame + g_word_93A225[0]; - R20_ = x_pos_of_start_of_grapple_beam_prevframe - layer1_x_pos; - R18_ = y_pos_of_start_of_grapple_beam_prevframe - layer1_y_pos; + r22 = flare_animation_frame + g_word_93A225[0]; + uint16 r20 = x_pos_of_start_of_grapple_beam_prevframe - layer1_x_pos; + uint16 r18 = y_pos_of_start_of_grapple_beam_prevframe - layer1_y_pos; if (((y_pos_of_start_of_grapple_beam_prevframe - layer1_y_pos) & 0xFF00) != 0) ; else - DrawBeamGrappleSpritemap(R22_); - } -} - -void CallGrappleBeamFunc(uint32 ea) { - switch (ea) { - case fnGrappleBeamFunc_BB64: GrappleBeamFunc_BB64(); return; - case fnGrappleBeamFunc_BC1F: GrappleBeamFunc_BC1F(); return; - case fnGrappleBeamFunc_BCFF: GrappleBeamFunc_BCFF(); return; - case fnGrappleBeamFunc_BD44: GrappleBeamFunc_BD44(); return; - case fnGrappleBeamFunc_BD95: GrappleBeamFunc_BD95(); return; - case fnGrappleBeamFunc_BE98: GrappleBeamFunc_BE98(); return; - case fnGrappleBeamFunc_BEEB: GrappleBeamFunc_BEEB(); return; - case fnGrappleBeamFunc_BF1B: GrappleBeamFunc_BF1B(); return; - case fnGrappleBeamFunc_Inactive: GrappleBeamFunc_Inactive(); return; - case fnGrappleBeamFunc_FireGoToCancel: GrappleBeamFunc_FireGoToCancel(); return; - case fnGrappleBeamFunc_Firing: GrappleBeamFunc_Firing(); return; - case fnGrappleBeamFunc_ConnectedLockedInPlace: GrappleBeamFunc_ConnectedLockedInPlace(); return; - case fnGrappleBeamFunc_Connected_Swinging: GrappleBeamFunc_Connected_Swinging(); return; - case fnGrappleBeamFunc_Wallgrab: GrappleBeamFunc_Wallgrab(); return; - case fnGrappleBeamFunc_C832: GrappleBeamFunc_C832(); return; - case fnGrappleBeamFunc_Cancel: GrappleBeamFunc_Cancel(); return; - case fnGrappleBeamFunc_C9CE: GrappleBeamFunc_C9CE(); return; - case fnGrappleBeamFunc_ReleaseFromSwing: GrappleBeamFunc_ReleaseFromSwing(); return; - case fnGrappleBeam_Func2: GrappleBeam_Func2(); return; - default: Unreachable(); + DrawBeamGrappleSpritemap(r22, r20, r18); } } void GrappleBeamHandler(void) { // 0x9BC490 + uint16 r18; if (grapple_varCF6) --grapple_varCF6; - samus_grapple_flags &= ~1u; + samus_grapple_flags &= ~1; CancelGrappleBeamIfIncompatiblePose(); CallGrappleBeamFunc(grapple_beam_function | 0x9B0000); if (grapple_beam_function != FUNC16(GrappleBeamFunc_Inactive) - && sign16(grapple_beam_function + 0x37AA) + && sign16(grapple_beam_function - FUNC16(GrappleBeamFunc_Cancel)) && (samus_suit_palette_index & 4) == 0 && fx_type - && (Samus_GetTopBottomBoundary(), (fx_y_pos & 0x8000u) == 0) - && sign16(fx_y_pos - R18_)) { - grapple_beam_flags |= 1u; + && (r18 = Samus_GetBottom_R18(), (fx_y_pos & 0x8000) == 0) + && sign16(fx_y_pos - r18)) { + grapple_beam_flags |= 1; } else { - grapple_beam_flags &= ~1u; + grapple_beam_flags &= ~1; } } @@ -756,12 +702,15 @@ void GrappleBeamFunc_Inactive(void) { // 0x9BC4F0 } void GrappleBeamFunc_FireGoToCancel(void) { // 0x9BC51E + uint16 r22; + int v0; if (samus_pose == kPose_F0_FaceR_Draygon_Move || samus_pose == kPose_BE_FaceL_Draygon_Move) { v0 = CheckBannedDraygonGrappleDirs(samus_pose); + r22 = 6; } else { - R22_ = *(&kPoseParams[0].y_offset_to_gfx + (uint16)(8 * samus_pose)); - v0 = *(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)); + r22 = kPoseParams[samus_pose].y_offset_to_gfx; + v0 = kPoseParams[samus_pose].direction_shots_fired; if ((v0 & 0xF0) != 0) { grapple_beam_function = FUNC16(GrappleBeamFunc_Cancel); return; @@ -771,27 +720,27 @@ void GrappleBeamFunc_FireGoToCancel(void) { // 0x9BC51E int v1 = v0; grapple_beam_extension_x_velocity = kGrappleBeam_Ext_Xvel[v1]; grapple_beam_extension_y_velocity = kGrappleBeam_Ext_Yvel[v1]; - *(uint16 *)&grapple_beam_end_subangle = kGrappleBeam_Init_EndAngle[v1]; - grapple_beam_end_angles_mirror = *(uint16 *)&grapple_beam_end_subangle; + grapple_beam_end_angle16 = kGrappleBeam_Init_EndAngle[v1]; + grapple_beam_end_angles_mirror = grapple_beam_end_angle16; grapple_varCF6 = 10; if (samus_pose == kPose_49_FaceL_Moonwalk || samus_pose == kPose_4A_FaceR_Moonwalk || samus_movement_type != 1) { grapple_beam_origin_x_offset = kGrappleBeam_OriginX_NoRun[v1]; - grapple_beam_origin_y_offset = kGrappleBeam_OriginY_NoRun[v1] - R22_; + grapple_beam_origin_y_offset = kGrappleBeam_OriginY_NoRun[v1] - r22; grapple_beam_end_x_pos = kGrappleBeam_OriginX_NoRun[v1] + samus_x_pos; x_pos_of_start_of_grapple_beam = grapple_beam_end_x_pos; x_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1a_offs_NoRun[v1] + samus_x_pos; - grapple_beam_end_y_pos = kGrappleBeam_OriginY_NoRun[v1] + samus_y_pos - R22_; + grapple_beam_end_y_pos = kGrappleBeam_OriginY_NoRun[v1] + samus_y_pos - r22; y_pos_of_start_of_grapple_beam = grapple_beam_end_y_pos; - y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_NoRun[v1] + samus_y_pos - R22_; + y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_NoRun[v1] + samus_y_pos - r22; } else { grapple_beam_origin_x_offset = kGrappleBeam_OriginX_Run[v1]; - grapple_beam_origin_y_offset = kGrappleBeam_OriginY_Run[v1] - R22_; + grapple_beam_origin_y_offset = kGrappleBeam_OriginY_Run[v1] - r22; grapple_beam_end_x_pos = kGrappleBeam_OriginX_Run[v1] + samus_x_pos; x_pos_of_start_of_grapple_beam = grapple_beam_end_x_pos; x_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1a_offs_Run[v1] + samus_x_pos; - grapple_beam_end_y_pos = kGrappleBeam_OriginY_Run[v1] + samus_y_pos - R22_; + grapple_beam_end_y_pos = kGrappleBeam_OriginY_Run[v1] + samus_y_pos - r22; y_pos_of_start_of_grapple_beam = grapple_beam_end_y_pos; - y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_Run[v1] + samus_y_pos - R22_; + y_pos_of_start_of_grapple_beam_prevframe = kGrappleBeam_0x0d1c_offs_Run[v1] + samus_y_pos - r22; } grapple_beam_end_x_subpos = 0; grapple_beam_end_y_subpos = 0; @@ -814,13 +763,6 @@ void GrappleBeamFunc_FireGoToCancel(void) { // 0x9BC51E grapple_beam_unkD3C = 0; grapple_point_anim_timer = 5; grapple_point_anim_ptr = g_off_9BC342; - grapple_beam_tmpD82 = 0; - grapple_beam_tmpD84 = 0; - grapple_beam_y_quarter_subvel = 0; - grapple_beam_y_quarter_vel = 0; - grapple_beam_tmpD8A = 0; - grapple_beam_varD8C = 0; - grapple_beam_varD8E = 0; grapple_beam_grapple_start_x = 0; grapple_beam_unkD38 = 0; grapple_beam_unkD36 = 0; @@ -828,10 +770,10 @@ void GrappleBeamFunc_FireGoToCancel(void) { // 0x9BC51E GrappleFunc_AF87(); samus_draw_handler = FUNC16(sub_90EB86); grapple_walljump_timer = 0; - LoadProjectilePalette(2u); + LoadProjectilePalette(2); palette_buffer[223] = 32657; grapple_beam_function = FUNC16(GrappleBeamFunc_Firing); - QueueSfx1_Max1(5u); + QueueSfx1_Max1(5); flare_counter = 1; play_resume_charging_beam_sfx = 0; if (samus_movement_handler == FUNC16(Samus_MoveHandler_ReleaseFromGrapple)) @@ -840,7 +782,6 @@ void GrappleBeamFunc_FireGoToCancel(void) { // 0x9BC51E uint16 CheckBannedDraygonGrappleDirs(uint16 a) { // 0x9BC6B2 if (a == kPose_BE_FaceL_Draygon_Move) { - R22_ = 6; if ((joypad1_lastkeys & kButton_Left) != 0) { if ((joypad1_lastkeys & kButton_Down) != 0) return 6; @@ -849,7 +790,6 @@ uint16 CheckBannedDraygonGrappleDirs(uint16 a) { // 0x9BC6B2 } return 7; } - R22_ = 6; if ((joypad1_lastkeys & kButton_Right) == 0) return 2; if ((joypad1_lastkeys & kButton_Down) != 0) @@ -873,7 +813,8 @@ void GrappleBeamFunc_Firing(void) { // 0x9BC703 grapple_beam_function = FUNC16(GrappleBeamFunc_Cancel); return; } - int v1 = ProcessEnemyGrappleBeamColl(GrappleBeam_CollDetect_Enemy()); + PairU16 pair = GrappleBeam_CollDetect_Enemy(); + int v1 = ProcessEnemyGrappleBeamColl(pair.k, pair.j); if (v1 >= 0) { if (v1) { grapple_beam_function = FUNC16(GrappleBeamFunc_Cancel); @@ -888,25 +829,14 @@ void GrappleBeamFunc_Firing(void) { // 0x9BC703 return; } } - QueueSfx1_Max6(6u); + QueueSfx1_Max6(6); HandleConnectingGrapple(); grapple_beam_length_delta = -8; - samus_grapple_flags |= 1u; -} - -void UNUSED_sub_9BC759(void) { // 0x9BC759 - if ((button_config_shoot_x & joypad1_lastkeys) == 0 - || (grapple_beam_length -= grapple_beam_length_delta, sign16(grapple_beam_length - 13))) { - grapple_beam_function = FUNC16(GrappleBeamFunc_Cancel); - } else { - BlockCollGrappleBeam(); - } + samus_grapple_flags |= 1; } void GrappleBeamFunc_ConnectedLockedInPlace(void) { // 0x9BC77E - if ((button_config_shoot_x & joypad1_lastkeys) != 0 - && (GrappleBeam_CollDetect_Enemy() || CheckIfGrappleIsConnectedToBlock() & 1)) { - ClearCarry_11(); + if ((button_config_shoot_x & joypad1_lastkeys) != 0 && (GrappleBeam_CollDetect_Enemy().k || CheckIfGrappleIsConnectedToBlock())) { } else { grapple_beam_function = FUNC16(GrappleBeamFunc_Cancel); } @@ -921,22 +851,20 @@ void GrappleBeamFunc_Connected_Swinging(void) { // 0x9BC79D GrappleBeamFunc_BCFF(); GrappleBeamFunc_BD44(); HandleMovementAndCollForSamusGrapple(); - if ((grapple_beam_unkD36 & 0x8000u) != 0 && HandleSpecialGrappleBeamAngles() & 1) { - ClearCarry_11(); + if ((grapple_beam_unkD36 & 0x8000) != 0 && HandleSpecialGrappleBeamAngles() & 1) { return; } - if (GrappleBeam_CollDetect_Enemy()) { - grapple_beam_flags |= 0x8000u; + if (GrappleBeam_CollDetect_Enemy().k) { + grapple_beam_flags |= 0x8000; } else if (!(CheckIfGrappleIsConnectedToBlock() & 1)) { goto LABEL_2; } BlockFunc_AC11(); - ClearCarry_11(); GrappleBeamFunc_BD95(); return; } LABEL_2: - if (grapple_beam_unkD26 || *(uint16 *)&grapple_beam_end_subangle != 0x8000) { + if (grapple_beam_unkD26 || grapple_beam_end_angle16 != 0x8000) { PropelSamusFromGrappleSwing(); grapple_beam_function = FUNC16(GrappleBeamFunc_ReleaseFromSwing); samus_movement_handler = FUNC16(Samus_MoveHandler_ReleaseFromGrapple); @@ -947,7 +875,7 @@ LABEL_2: void GrappleBeamFunc_Wallgrab(void) { // 0x9BC814 if ((button_config_shoot_x & joypad1_lastkeys) != 0 && CheckIfGrappleIsConnectedToBlock() & 1) { - ClearCarry_11(); + } else { grapple_walljump_timer = 30; grapple_beam_function = FUNC16(GrappleBeamFunc_C832); @@ -955,10 +883,8 @@ void GrappleBeamFunc_Wallgrab(void) { // 0x9BC814 } void GrappleBeamFunc_C832(void) { // 0x9BC832 - if ((--grapple_walljump_timer & 0x8000u) == 0) { - R18_ = 16; - R20_ = 0; - if (Samus_GrappleWallJumpCheck() & 1) + if ((--grapple_walljump_timer & 0x8000) == 0) { + if (Samus_GrappleWallJumpCheck(INT16_SHL16(16))) grapple_beam_function = FUNC16(GrappleBeamFunc_C9CE); } else { grapple_beam_function = FUNC16(GrappleBeam_Func2); @@ -966,11 +892,11 @@ void GrappleBeamFunc_C832(void) { // 0x9BC832 } void GrappleBeamFunc_Cancel(void) { // 0x9BC856 - QueueSfx1_Max15(7u); + QueueSfx1_Max15(7); if (samus_movement_type == kMovementType_16_Grappling) Samus_Pose_CancelGrapple(); else - CallSomeSamusCode(0x1Cu); + CallSomeSamusCode(0x1C); grapple_beam_unkD1E = 0; grapple_beam_unkD20 = 0; grapple_beam_direction = 0; @@ -997,7 +923,7 @@ void GrappleBeamFunc_Cancel(void) { // 0x9BC856 } void GrappleBeam_Func2(void) { // 0x9BC8C5 - QueueSfx1_Max15(7u); + QueueSfx1_Max15(7); if (samus_pose == kPose_B2_FaceR_Grapple_Air) goto LABEL_5; if (samus_pose == kPose_B3_FaceL_Grapple_Air) { @@ -1006,18 +932,18 @@ LABEL_6: goto LABEL_15; } if (sign16(samus_y_radius - 17)) { - if ((*(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)) & 0xF0) != 0) { + if ((kPoseParams[samus_pose].direction_shots_fired & 0xF0) != 0) { if (samus_pose_x_dir == 4) samus_new_pose_transitional = kPose_28_FaceL_Crouch; else samus_new_pose_transitional = kPose_27_FaceR_Crouch; } else { samus_new_pose_transitional = g_byte_9BC9C4[*(&kPoseParams[0].direction_shots_fired - + (uint16)(8 * samus_pose))]; + + (8 * samus_pose))]; } goto LABEL_15; } - if ((*(&kPoseParams[0].direction_shots_fired + (uint16)(8 * samus_pose)) & 0xF0) != 0) { + if ((kPoseParams[samus_pose].direction_shots_fired & 0xF0) != 0) { if (samus_pose_x_dir != 4) { LABEL_5: samus_new_pose_transitional = kPose_01_FaceR_Normal; @@ -1026,7 +952,7 @@ LABEL_5: goto LABEL_6; } samus_new_pose_transitional = g_byte_9BC9BA[*(&kPoseParams[0].direction_shots_fired - + (uint16)(8 * samus_pose))]; + + (8 * samus_pose))]; LABEL_15: samus_hurt_switch_index = 0; input_to_pose_calc = 1; @@ -1060,7 +986,7 @@ LABEL_15: } void GrappleBeamFunc_C9CE(void) { // 0x9BC9CE - QueueSfx1_Max15(7u); + QueueSfx1_Max15(7); if (samus_pose_x_dir == 8) samus_new_pose_transitional = kPose_84_FaceL_Walljump; else @@ -1107,47 +1033,37 @@ void PropelSamusFromGrappleSwing(void) { // 0x9BCA65 int16 v2; uint16 v0; - if ((grapple_beam_unkD26 & 0x8000u) == 0) { + if ((grapple_beam_unkD26 & 0x8000) == 0) { v0 = 2 * grapple_beam_unkD26; - v2 = kSinCosTable8bit_Sext[((uint16)(2 * HIBYTE(*(uint16 *)&grapple_beam_end_subangle)) >> 1) + 64]; + v2 = kSinCosTable8bit_Sext[HIBYTE(grapple_beam_end_angle16) + 64]; if (v2 >= 0) { - Multiply16x16(v2, v0); - samus_y_subspeed = mult_product_lo; - samus_y_speed = mult_product_hi; + SetHiLo(&samus_y_speed, &samus_y_subspeed, Multiply16x16(v2, v0)); samus_y_dir = 2; } else { - Multiply16x16(-v2, v0); - samus_y_subspeed = mult_product_lo; - samus_y_speed = mult_product_hi; + SetHiLo(&samus_y_speed, &samus_y_subspeed, Multiply16x16(-v2, v0)); samus_y_dir = 1; } } else { v0 = -2 * grapple_beam_unkD26; - v1 = kSinCosTable8bit_Sext[((uint16)(2 * HIBYTE(*(uint16 *)&grapple_beam_end_subangle)) >> 1) + 64]; + v1 = kSinCosTable8bit_Sext[HIBYTE(grapple_beam_end_angle16) + 64]; if (v1 < 0) { - Multiply16x16(-v1, v0); - samus_y_subspeed = mult_product_lo; - samus_y_speed = mult_product_hi; + SetHiLo(&samus_y_speed, &samus_y_subspeed, Multiply16x16(-v1, v0)); samus_y_dir = 2; } else { - Multiply16x16(v1, v0); - samus_y_subspeed = mult_product_lo; - samus_y_speed = mult_product_hi; + SetHiLo(&samus_y_speed, &samus_y_subspeed, Multiply16x16(v1, v0)); samus_y_dir = 1; } } samus_x_accel_mode = 2; - R18_ = 3 * (v0 >> 9); - R18_ = 64 - R18_; - uint16 v3 = abs16(kSinCosTable8bit_Sext[((uint16)(2 * (uint8)(grapple_beam_end_angle - R18_)) >> 1) + 64]); - Multiply16x16(v3, v0); - samus_x_base_subspeed = mult_product_lo; - samus_x_base_speed = mult_product_hi; + uint16 r18 = 3 * (v0 >> 9); + r18 = 64 - r18; + uint16 v3 = abs16(kSinCosTable8bit_Sext[(uint8)(grapple_beam_end_angle_hi - r18) + 64]); + SetHiLo(&samus_x_base_speed, &samus_x_base_subspeed, Multiply16x16(v3, v0)); } void GrappleBeamFunc_ReleaseFromSwing(void) { // 0x9BCB8B - QueueSfx1_Max15(7u); - if ((grapple_beam_unkD26 & 0x8000u) == 0) + QueueSfx1_Max15(7); + if ((grapple_beam_unkD26 & 0x8000) == 0) samus_new_pose_transitional = kPose_52_FaceL_Jump_NoAim_MoveF; else samus_new_pose_transitional = kPose_51_FaceR_Jump_NoAim_MoveF; @@ -1175,4 +1091,29 @@ void GrappleBeamFunc_ReleaseFromSwing(void) { // 0x9BCB8B hud_item_index = 0; samus_auto_cancel_hud_item_index = 0; } -} \ No newline at end of file +} + +void CallGrappleBeamFunc(uint32 ea) { + switch (ea) { + case fnGrappleBeamFunc_BB64: GrappleBeamFunc_BB64(); return; + case fnGrappleBeamFunc_BC1F: GrappleBeamFunc_BC1F(); return; + case fnGrappleBeamFunc_BCFF: GrappleBeamFunc_BCFF(); return; + case fnGrappleBeamFunc_BD44: GrappleBeamFunc_BD44(); return; + case fnGrappleBeamFunc_BD95: GrappleBeamFunc_BD95(); return; + case fnGrappleBeamFunc_BE98: GrappleBeamFunc_BE98(); return; + case fnGrappleBeamFunc_BEEB: GrappleBeamFunc_BEEB(); return; + case fnGrappleBeamFunc_BF1B: GrappleBeamFunc_BF1B(); return; + case fnGrappleBeamFunc_Inactive: GrappleBeamFunc_Inactive(); return; + case fnGrappleBeamFunc_FireGoToCancel: GrappleBeamFunc_FireGoToCancel(); return; + case fnGrappleBeamFunc_Firing: GrappleBeamFunc_Firing(); return; + case fnGrappleBeamFunc_ConnectedLockedInPlace: GrappleBeamFunc_ConnectedLockedInPlace(); return; + case fnGrappleBeamFunc_Connected_Swinging: GrappleBeamFunc_Connected_Swinging(); return; + case fnGrappleBeamFunc_Wallgrab: GrappleBeamFunc_Wallgrab(); return; + case fnGrappleBeamFunc_C832: GrappleBeamFunc_C832(); return; + case fnGrappleBeamFunc_Cancel: GrappleBeamFunc_Cancel(); return; + case fnGrappleBeamFunc_C9CE: GrappleBeamFunc_C9CE(); return; + case fnGrappleBeamFunc_ReleaseFromSwing: GrappleBeamFunc_ReleaseFromSwing(); return; + case fnGrappleBeam_Func2: GrappleBeam_Func2(); return; + default: Unreachable(); + } +} diff --git a/src/sm_a0.c b/src/sm_a0.c index 01688ec..9040679 100644 --- a/src/sm_a0.c +++ b/src/sm_a0.c @@ -5,18 +5,33 @@ #include "funcs.h" #include "enemy_types.h" - #define kEnemyLayerToQueuePtr ((uint16*)RomFixedPtr(0xa0b133)) #define kStandardSpriteTiles ((uint16*)RomFixedPtr(0x9ad200)) #define kSine8bit ((uint8*)RomFixedPtr(0xa0b143)) #define kEquationForQuarterCircle ((uint16*)RomFixedPtr(0xa0b7ee)) #define g_off_A0C2DA ((uint16*)RomFixedPtr(0xa0c2da)) -#define CHECK_locret_A0C434(i) (byte_A0C435[i] & 0x80 ? -1 : 0) +#define CHECK_locret_A0C434(Ek) (byte_A0C435[Ek] & 0x80 ? -1 : 0) #define g_word_A0C49F ((uint16*)RomFixedPtr(0xa0c49f)) #define kAlignYPos_Tab0 ((uint8*)RomFixedPtr(0x948b2b)) +typedef struct EnemyBlockCollInfo { + int32 ebci_r18_r20; + uint16 ebci_r24; + uint16 ebci_r26; + uint16 ebci_r28; + uint16 ebci_r30; + uint16 ebci_r32; +} EnemyBlockCollInfo; +typedef uint8 Func_EnemyBlockCollInfo_U8(EnemyBlockCollInfo *ebci); +static uint8 EnemyBlockCollReact_Vert(EnemyBlockCollInfo *ebci, uint16 k); +static uint8 EnemyBlockCollReact_Horiz(EnemyBlockCollInfo *ebci, uint16 k); +static uint8 Enemy_MoveRight_IgnoreSlopes_Inner(uint16 k, int32 amount32, uint16 r32); +static uint8 EnemyBlockCollHorizReact_Slope_NonSquare(EnemyBlockCollInfo *ebci); +static uint8 EnemyBlockCollHorizReact_Slope_Square(EnemyBlockCollInfo *ebci, uint16 k, uint16 a); +static uint8 EnemyBlockCollVertReact_Slope_NonSquare(EnemyBlockCollInfo *ebci); +static uint8 EnemyBlockCollVertReact_Slope_Square(EnemyBlockCollInfo *ebci, uint16 a, uint16 k); void Enemy_GrappleReact_NoInteract_A0(void) { // 0xA08000 SwitchEnemyAiToMainAi(); @@ -141,14 +156,14 @@ const uint16 *EnemyInstr_Skip2bytes(uint16 k, const uint16 *jp) { // 0xA0812C const uint16 *EnemyInstr_Sleep(uint16 k, const uint16 *jp) { // 0xA2812F EnemyData *ED = gEnemyData(k); - const uint8 *base_ptr = RomPtrWithBank(ED->bank, 0x8000) - 0x8000; + const uint8 *base_ptr = RomBankBase(ED->bank); ED->current_instruction = (const uint8 *)jp - 2 - base_ptr; return 0; } const uint16 *EnemyInstr_WaitNframes(uint16 k, const uint16 *jp) { // 0xA0813A EnemyData *ED = gEnemyData(k); - const uint8 *base_ptr = RomPtrWithBank(ED->bank, 0x8000) - 0x8000; + const uint8 *base_ptr = RomBankBase(ED->bank); ED->instruction_timer = jp[0]; ED->current_instruction = (const uint8 *)jp + 2 - base_ptr; return 0; @@ -170,13 +185,13 @@ const uint16 *EnemyInstr_CopyToVram(uint16 k, const uint16 *jp) { // 0xA0814B const uint16 *EnemyInstr_EnableOffScreenProcessing(uint16 k, const uint16 *jp) { // 0xA08173 EnemyData *v2 = gEnemyData(k); - v2->properties |= 0x800u; + v2->properties |= 0x800; return jp; } const uint16 *EnemyInstr_DisableOffScreenProcessing(uint16 k, const uint16 *jp) { // 0xA0817D EnemyData *v2 = gEnemyData(k); - v2->properties &= ~0x800u; + v2->properties &= ~0x800; return jp; } @@ -222,7 +237,7 @@ static const uint16 kRoomShakes[144] = { // 0xA08687 void HandleRoomShaking(void) { if (earthquake_timer && !time_is_frozen_flag && sign16(earthquake_type - 36)) { - int v0 = (uint16)(8 * earthquake_type) >> 1; + int v0 = (8 * earthquake_type) >> 1; if ((earthquake_timer & 2) != 0) { reg_BG1HOFS -= kRoomShakes[v0]; reg_BG1VOFS -= kRoomShakes[v0 + 1]; @@ -272,27 +287,26 @@ void DrawSamusEnemiesAndProjectiles(void) { // 0xA0884D DrawSpriteObjects(); DrawBombAndProjectileExplosions(); DrawLowPriorityEnemyProjectiles(); - for (draw_enemy_layer = 0; draw_enemy_layer != 8; ++draw_enemy_layer) { - if (draw_enemy_layer == 3) { + for (uint16 phase_varE32 = 0; phase_varE32 != 8; ++phase_varE32) { + if (phase_varE32 == 3) { DrawSamusAndProjectiles(); - } else if (draw_enemy_layer == 6) { + } else if (phase_varE32 == 6) { DrawHighPriorityEnemyProjectiles(); } - int v0 = draw_enemy_layer; - if (enemy_drawing_queue_sizes[v0]) { - loop_index_end = enemy_drawing_queue_sizes[v0]; - enemy_drawing_queue_base = kEnemyLayerToQueuePtr[v0]; - uint16 v1 = 0; - enemy_drawing_queue_sizes[v0] = 0; + if (enemy_drawing_queue_sizes[phase_varE32]) { + uint16 varE36 = enemy_drawing_queue_sizes[phase_varE32]; + uint16 varE3A = kEnemyLayerToQueuePtr[phase_varE32]; + uint16 v1 = 0, varE38; + enemy_drawing_queue_sizes[phase_varE32] = 0; do { - loop_index = v1; - uint8 *v2 = RomPtr_RAM(enemy_drawing_queue_base + v1); + varE38 = v1; + uint8 *v2 = RomPtr_RAM(varE3A + v1); uint16 v3 = GET_WORD(v2); *(uint16 *)v2 = 0; cur_enemy_index = v3; WriteEnemyOams(); - v1 = loop_index + 2; - } while (loop_index + 2 != loop_index_end); + v1 = varE38 + 2; + } while (varE38 + 2 != varE36); } } CallEnemyGfxDrawHook(Load24(&enemy_gfx_drawn_hook)); @@ -312,37 +326,30 @@ void RecordEnemySpawnData(uint16 j) { // 0xA088D0 v2->extra_properties = v1->extra_properties; v2->param_1 = v1->parameter_1; v2->param_2 = v1->parameter_2; - R18_ = 0; - R20_ = 0; - R22_ = 0; - R24_ = 0; - R26_ = 0; - R28_ = 0; + uint16 r18 = 0, r20 = 0, r22 = 0, r24 = 0, R26 = 0, R28 = 0; uint16 name_ptr = get_EnemyDef_A2(v1->enemy_ptr)->name_ptr; if (name_ptr) { const uint16 *v4 = (const uint16 *)RomPtr_B4(name_ptr); - R18_ = *v4; - R20_ = v4[1]; - R22_ = v4[2]; - R24_ = v4[3]; - R26_ = v4[4]; - R28_ = v4[6]; + r18 = v4[0]; + r20 = v4[1]; + r22 = v4[2]; + r24 = v4[3]; + R26 = v4[4]; + R28 = v4[6]; } v5 = gEnemySpawnData(j); - *(uint16 *)v5->name = R18_; - *(uint16 *)&v5->name[2] = R20_; - *(uint16 *)&v5->name[4] = R22_; - *(uint16 *)&v5->name[6] = R24_; - *(uint16 *)&v5->name[8] = R26_; - *(uint16 *)&v5->name[10] = R28_; + *(uint16 *)v5->name = r18; + *(uint16 *)&v5->name[2] = r20; + *(uint16 *)&v5->name[4] = r22; + *(uint16 *)&v5->name[6] = r24; + *(uint16 *)&v5->name[8] = R26; + *(uint16 *)&v5->name[10] = R28; } void LoadEnemies(void) { // 0xA08A1E debug_time_frozen_for_enemies = 0; - *(uint16 *)&enemy_gfx_drawn_hook.bank = 160; + enemy_gfx_drawn_hook.bank = 160; enemy_gfx_drawn_hook.addr = FUNC16(nullsub_170); - *(uint16 *)&set_to_rtl_when_loading_enemies_unused.bank = 160; - set_to_rtl_when_loading_enemies_unused.addr = FUNC16(nullsub_170); enemy_bg2_tilemap_size = 2048; UNUSED_word_7E179E = 0; UNUSED_word_7E17A0 = 0; @@ -355,133 +362,89 @@ void LoadEnemies(void) { // 0xA08A1E } void ClearEnemyDataAndProcessEnemySet(void) { // 0xA08A6D - int16 v0; - - v0 = 2048; - uint16 v1 = 0; - do { - gEnemyData(v1)->enemy_ptr = 0; - v1 += 2; - v0 -= 2; - } while (v0); + memset(g_ram + 0xF78, 0, 2048); if (*(uint16 *)RomPtr_A1(room_enemy_population_ptr) != 0xFFFF) ProcessEnemyTilesets(); } void InitializeEnemies(void) { // 0xA08A9E - int16 v0; - uint16 j; - EnemyPopulation *v9; - EnemyDef_A2 *v10; - EnemyPopulation *EnemyPopulation; - EnemyDef_A2 *EnemyDef_A2; - - v0 = 5120; - uint16 v1 = 0; - do { - gEnemySpawnData(v1)->some_flag = 0; - v1 += 2; - --v0; - } while (v0); + memset(&g_ram[0x7000], 0, 0x2800); num_enemies_in_room = 0; num_enemies_killed_in_room = 0; flag_process_all_enemies = 0; for (int i = 286; i >= 0; i -= 2) enemy_projectile_flags[i >> 1] = 0; - for (j = 34; (j & 0x8000u) == 0; j -= 2) + for (int j = 34; j >= 0; j -= 2) enemy_projectile_killed_enemy_index[j >> 1] = -1; uint16 v4 = room_enemy_population_ptr; - if (get_EnemyPopulation(0xa1, room_enemy_population_ptr)->enemy_ptr != 0xFFFF) { - UNUSED_word_7E0E48 = 0; - uint16 v5 = 0; - do { - LoadEnemyGfxIndexes(v4, v5); - uint16 v13 = v4; - EnemyPopulation = get_EnemyPopulation(0xa1, v4); - EnemyDef_A2 = get_EnemyDef_A2(EnemyPopulation->enemy_ptr); - uint16 *v8 = (uint16 *)gEnemyData(v5); - v8[5] = EnemyDef_A2->x_radius; - v8[6] = EnemyDef_A2->y_radius; - v8[10] = EnemyDef_A2->health; - v8[17] = EnemyDef_A2->layer; - v8[23] = *(uint16 *)&EnemyDef_A2->bank; - if (EnemyDef_A2->boss_fight_value) - boss_id = EnemyDef_A2->boss_fight_value; - v9 = get_EnemyPopulation(0xa1, v4); - *v8 = v9->enemy_ptr; - v8[1] = v9->x_pos; - v8[3] = v9->y_pos; - v8[13] = v9->init_param; - v8[7] = v9->properties; - v8[8] = v9->extra_properties; - v8[30] = v9->parameter1; - v8[31] = v9->parameter2; - v8[22] = 0; - v8[12] = 0; - v8[14] = 1; - v8[22] = 0; - RecordEnemySpawnData(v5); - cur_enemy_index = v5; - v10 = get_EnemyDef_A2(*v8); - enemy_ai_pointer.addr = v10->ai_init; - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&v10->bank; - CallEnemyAi(Load24(&enemy_ai_pointer)); - EnemyData *v11 = gEnemyData(v5); - v11->spritemap_pointer = 0; - if ((v11->properties & 0x2000) != 0) { - uint16 v12 = addr_kSpritemap_Nothing_A4; - if ((v11->extra_properties & 4) != 0) - v12 = addr_kExtendedSpritemap_Nothing_A4; - v11->spritemap_pointer = v12; - v4 = v13; - } - v5 += 64; - v4 += 16; - } while (get_EnemyPopulation(0xa1, v4)->enemy_ptr != 0xFFFF); - first_free_enemy_index = v5; - num_enemies_in_room = v5 >> 6; - num_enemy_deaths_left_to_clear = RomPtr_A1(v4)[2]; - } + if (get_EnemyPopulation(0xa1, room_enemy_population_ptr)->enemy_ptr == 0xFFFF) + return; + UNUSED_word_7E0E48 = 0; + uint16 v5 = 0; + do { + LoadEnemyGfxIndexes(v4, v5); + EnemyPopulation *EP = get_EnemyPopulation(0xa1, v4); + EnemyDef_A2 *ED = get_EnemyDef_A2(EP->enemy_ptr); + EnemyData *E = gEnemyData(v5); + E->x_width = ED->x_radius; + E->y_height = ED->y_radius; + E->health = ED->health; + E->layer = ED->layer; + *(uint16 *)&E->bank = *(uint16 *)&ED->bank; + if (ED->boss_fight_value) + boss_id = ED->boss_fight_value; + E->enemy_ptr = EP->enemy_ptr; + E->x_pos = EP->x_pos; + E->y_pos = EP->y_pos; + E->current_instruction = EP->init_param; + E->properties = EP->properties; + E->extra_properties = EP->extra_properties; + E->parameter_1 = EP->parameter1; + E->parameter_2 = EP->parameter2; + E->frame_counter = 0; + E->timer = 0; + E->instruction_timer = 1; + E->frame_counter = 0; + RecordEnemySpawnData(v5); + cur_enemy_index = v5; + CallEnemyAi(ED->bank << 16 | ED->ai_init); + E->spritemap_pointer = 0; + if ((E->properties & 0x2000) != 0) { + uint16 v12 = addr_kSpritemap_Nothing_A4; + if ((E->extra_properties & 4) != 0) + v12 = addr_kExtendedSpritemap_Nothing_A4; + E->spritemap_pointer = v12; + } + v5 += 64; + v4 += 16; + } while (get_EnemyPopulation(0xa1, v4)->enemy_ptr != 0xFFFF); + first_free_enemy_index = v5; + num_enemies_in_room = v5 >> 6; + num_enemy_deaths_left_to_clear = RomPtr_A1(v4)[2]; } void LoadEnemyGfxIndexes(uint16 k, uint16 j) { // 0xA08BF3 - VoidP enemy_ptr; - EnemyTileset *EnemyTileset; - EnemySpawnData *v6; - EnemySpawnData *v10; - - R18_ = k; - R20_ = j; - R28_ = room_enemy_tilesets_ptr; - R30_ = 0; + EnemyData *E = gEnemyData(j); + EnemySpawnData *ES = gEnemySpawnData(j); + uint16 e = room_enemy_tilesets_ptr; + uint16 f = 0; while (1) { - enemy_ptr = get_EnemyPopulation(0xa1, R18_)->enemy_ptr; - EnemyTileset = get_EnemyTileset(R28_); - if (enemy_ptr == EnemyTileset->enemy_def) - break; - if (EnemyTileset->enemy_def == 0xFFFF) { - uint16 v4 = R20_; - EnemyData *v5 = gEnemyData(R20_); - v5->vram_tiles_index = 0; - v6 = gEnemySpawnData(v4); - v6->vram_tiles_index = 0; - v5->palette_index = 2560; - v6->palette_index = 2560; + EnemyTileset *ET = get_EnemyTileset(e); + if (get_EnemyPopulation(0xa1, k)->enemy_ptr == ET->enemy_def) { + E->palette_index = ES->palette_index = (ET->vram_dst & 0xF) << 9; + E->vram_tiles_index = ES->vram_tiles_index = f; return; } - R30_ += get_EnemyDef_A2(EnemyTileset->enemy_def)->tile_data_size >> 5; - R28_ += 4; + if (ET->enemy_def == 0xFFFF) { + E->vram_tiles_index = ES->vram_tiles_index = 0; + E->palette_index = ES->palette_index = 2560; + return; + } + f += get_EnemyDef_A2(ET->enemy_def)->tile_data_size >> 5; + e += 4; } - uint16 v7 = (get_EnemyTileset(R28_)->vram_dst & 0xF) << 9; - uint16 v8 = R20_; - EnemyData *v9 = gEnemyData(R20_); - v9->palette_index = v7; - v10 = gEnemySpawnData(v8); - v10->palette_index = v7; - uint16 v11 = R30_; - v9->vram_tiles_index = R30_; - v10->vram_tiles_index = v11; } + void LoadEnemyTileData(void) { // 0xA08C6C for (int i = 510; i >= 0; i -= 2) gEnemySpawnData(i)->some_flag = kStandardSpriteTiles[(i >> 1) + 3072]; @@ -490,14 +453,14 @@ void LoadEnemyTileData(void) { // 0xA08C6C EnemyTileLoadData *load_data = enemy_tile_load_data; do { uint16 v2 = load_data->tile_data_ptr.addr; - R18_ = load_data->tile_data_size + v2; + uint16 r18 = load_data->tile_data_size + v2; uint16 v3 = load_data->offset_into_ram; uint8 db = load_data->tile_data_ptr.bank; do { memcpy(&g_ram[0x7000 + v3], RomPtrWithBank(db, v2), 8); v3 += 8; v2 += 8; - } while (v2 != R18_); + } while (v2 != r18); load_data++; v1 += 7; } while (v1 != enemy_tile_load_data_write_pos); @@ -506,8 +469,6 @@ void LoadEnemyTileData(void) { // 0xA08C6C } void TransferEnemyTilesToVramAndInit(void) { // 0xA08CD7 - VramWriteEntry *v2; - uint16 v0 = enemy_tile_vram_src; if (!enemy_tile_vram_src) { v0 = ADDR16_OF_RAM(*enemy_spawn_data); @@ -522,7 +483,7 @@ void TransferEnemyTilesToVramAndInit(void) { // 0xA08CD7 enemy_tile_vram_src = -2; } else { uint16 v1 = vram_write_queue_tail; - v2 = gVramWriteEntry(vram_write_queue_tail); + VramWriteEntry *v2 = gVramWriteEntry(vram_write_queue_tail); v2->size = 2048; uint16 v3 = enemy_tile_vram_src; v2->src.addr = enemy_tile_vram_src; @@ -538,7 +499,7 @@ void TransferEnemyTilesToVramAndInit(void) { // 0xA08CD7 void ProcessEnemyTilesets(void) { // 0xA08D64 enemy_tile_load_data_write_pos = 0; - R30_ = 2048; + uint16 r30 = 2048; enemy_def_ptr[0] = 0; enemy_def_ptr[1] = 0; enemy_def_ptr[2] = 0; @@ -551,19 +512,18 @@ void ProcessEnemyTilesets(void) { // 0xA08D64 enemy_gfxdata_vram_ptr[1] = 0; enemy_gfxdata_vram_ptr[2] = 0; enemy_gfxdata_vram_ptr[3] = 0; - enemy_gfx_data_write_ptr = 0; - next_enemy_tiles_index = 0; + uint16 enemy_gfx_data_write_ptr = 0; + uint16 next_enemy_tiles_index = 0; EnemyTileset *ET = get_EnemyTileset(room_enemy_tilesets_ptr); EnemyTileLoadData *LD = enemy_tile_load_data; for (; ET->enemy_def != 0xffff; ET++) { EnemyDef_A2 *ED = get_EnemyDef_A2(ET->enemy_def); memcpy(&target_palettes[(LOBYTE(ET->vram_dst) + 8) * 16], RomPtrWithBank(ED->bank, ED->palette_ptr), 32); - varE2E = 0; LD->tile_data_size = ED->tile_data_size & 0x7FFF; LD->tile_data_ptr = ED->tile_data; - uint16 v10 = R30_; - if ((ED->tile_data_size & 0x8000u) != 0) + uint16 v10 = r30; + if ((ED->tile_data_size & 0x8000) != 0) v10 = (uint16)(ET->vram_dst & 0x3000) >> 3; LD->offset_into_ram = v10; enemy_tile_load_data_write_pos += 7; @@ -574,7 +534,7 @@ void ProcessEnemyTilesets(void) { // 0xA08D64 enemy_gfxdata_vram_ptr[v11 >> 1] = ET->vram_dst; enemy_gfx_data_write_ptr += 2; next_enemy_tiles_index += ED->tile_data_size >> 5; - R30_ += ED->tile_data_size; + r30 += ED->tile_data_size; } } @@ -1757,13 +1717,12 @@ const uint16 *CallEnemyInstr(uint32 ea, uint16 k, const uint16 *j) { case fnMotherBrain_Instr_SpawnEprojToOffset: return MotherBrain_Instr_SpawnEprojToOffset(k, j); case fnMotherBrain_Instr_SpawnDeathBeamEproj: return MotherBrain_Instr_SpawnDeathBeamEproj(k, j); case fnMotherBrain_Instr_IncrBeamAttackPhase: return MotherBrain_Instr_IncrBeamAttackPhase(k, j); - default: Unreachable(); return NULL; } } void EnemyMain(void) { // 0xA08FD4 - EnemyDef_A2 *EnemyDef_A2; + EnemyDef_A2 *ED; int16 v6; int8 v8; // cf @@ -1772,34 +1731,29 @@ void EnemyMain(void) { // 0xA08FD4 gEnemyData(enemy_index_to_shake)->shake_timer = 64; enemy_index_to_shake = -1; } - for (active_enemy_indexes_index = 0; ; ++active_enemy_indexes_index) { - int v0 = active_enemy_indexes_index >> 1; - uint16 v1 = active_enemy_indexes[v0]; + for (int active_enemy_indexes_index = 0; ; active_enemy_indexes_index += 2) { + uint16 v1 = active_enemy_indexes[active_enemy_indexes_index >> 1]; if (v1 == 0xFFFF) break; - cur_enemy_index = active_enemy_indexes[v0]; - uint16 v2 = v1; - enemy_data_ptr = v1 + 3960; - EnemyData *v3 = gEnemyData(v1); - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&v3->bank; - if ((v3->properties & 0x400) == 0) { - if (v3->invincibility_timer) { - --v3->invincibility_timer; + cur_enemy_index = v1; + EnemyData *E = gEnemyData(cur_enemy_index); + if ((E->properties & 0x400) == 0) { + if (E->invincibility_timer) { + --E->invincibility_timer; } else if (!debug_disable_sprite_interact) { if (!(debug_time_frozen_for_enemies | time_is_frozen_flag)) { EnemyCollisionHandler(); - if (!gEnemyData(cur_enemy_index)->enemy_ptr) + if (!E->enemy_ptr) goto LABEL_32; } - v2 = cur_enemy_index; - if ((gEnemyData(cur_enemy_index)->extra_properties & 1) != 0) + if ((E->extra_properties & 1) != 0) goto LABEL_23; } } UNUSED_word_7E17A2 = 0; if (!(debug_time_frozen_for_enemies | time_is_frozen_flag)) { v6 = 0; - uint16 ai_handler_bits = gEnemyData(cur_enemy_index)->ai_handler_bits; + uint16 ai_handler_bits = E->ai_handler_bits; if (ai_handler_bits) { do { ++v6; @@ -1807,60 +1761,44 @@ void EnemyMain(void) { // 0xA08FD4 ai_handler_bits >>= 1; } while (!v8); } - EnemyData *v9 = gEnemyData(cur_enemy_index); - enemy_ai_pointer.addr = get_EnemyDef_A2(v9->enemy_ptr + 2 * v6)->main_ai; + CallEnemyAi(E->bank << 16 | get_EnemyDef_A2(E->enemy_ptr + 2 * v6)->main_ai); goto LABEL_20; } - EnemyData *v4; - v4 = gEnemyData(v2); - EnemyDef_A2 = get_EnemyDef_A2(v4->enemy_ptr); - if (EnemyDef_A2->time_is_frozen_ai) { - enemy_ai_pointer.addr = EnemyDef_A2->time_is_frozen_ai; + ED = get_EnemyDef_A2(E->enemy_ptr); + if (ED->time_is_frozen_ai) { + CallEnemyAi(E->bank << 16 | ED->time_is_frozen_ai); LABEL_20: - enemy_ai_pointer.bank = gEnemyData(cur_enemy_index)->bank; - CallEnemyAi(Load24(&enemy_ai_pointer)); if (!(debug_time_frozen_for_enemies | time_is_frozen_flag)) { - EnemyData *v10 = gEnemyData(cur_enemy_index); - ++v10->frame_counter; - if ((v10->properties & 0x2000) != 0) { + ++E->frame_counter; + if ((E->properties & 0x2000) != 0) { enemy_processing_stage = 2; ProcessEnemyInstructions(); } } } LABEL_23:; - uint16 v11; - v11 = cur_enemy_index; - EnemyData *v12; - v12 = gEnemyData(cur_enemy_index); - if ((v12->extra_properties & 1) != 0 && (v12->flash_timer == 1 || v12->frozen_timer == 1)) { + if ((E->extra_properties & 1) != 0 && (E->flash_timer == 1 || E->frozen_timer == 1)) { gEnemySpawnData(cur_enemy_index)->cause_of_death = 0; - EnemyDeathAnimation(v11, 0); + EnemyDeathAnimation(cur_enemy_index, 0); } - if (((gEnemyData(cur_enemy_index)->extra_properties & 4) != 0 || !EnemyWithNormalSpritesIsOffScreen()) - && (gEnemyData(cur_enemy_index)->properties & 0x300) == 0 + if (((E->extra_properties & 4) != 0 || !EnemyWithNormalSpritesIsOffScreen()) + && (E->properties & 0x300) == 0 && (UNUSED_word_7E17A2 & 1) == 0) { DrawOneEnemy(); } LABEL_32:; - EnemyData *v13 = gEnemyData(cur_enemy_index); - if (v13->flash_timer && !(debug_time_frozen_for_enemies | time_is_frozen_flag)) { - if (sign16(--v13->flash_timer - 8)) - v13->ai_handler_bits &= ~2u; + if (E->flash_timer && !(debug_time_frozen_for_enemies | time_is_frozen_flag)) { + if (sign16(--E->flash_timer - 8)) + E->ai_handler_bits &= ~2; } - ++active_enemy_indexes_index; } } HandleSpriteObjects(); - ++enemy_damage_routine_exec_count; + random_enemy_counter++; enemy_index_colliding_dirs[0] = -1; enemy_index_colliding_dirs[1] = -1; enemy_index_colliding_dirs[2] = -1; enemy_index_colliding_dirs[3] = -1; - distance_to_enemy_colliding_dirs[0] = 0; - distance_to_enemy_colliding_dirs[1] = 0; - distance_to_enemy_colliding_dirs[2] = 0; - distance_to_enemy_colliding_dirs[3] = 0; } void DecrementSamusTimers(void) { // 0xA09169 @@ -1874,9 +1812,9 @@ void DecrementSamusTimers(void) { // 0xA09169 active_enemy_indexes[0] = -1; } -void SpawnEnemyDrops(uint16 a, uint16 k) { // 0xA0920E - varE24 = a; - SpawnEnemyProjectileWithGfx(enemy_population_ptr, k, addr_kEproj_Pickup); +void SpawnEnemyDrops(uint16 a, uint16 k, uint16 varE20) { // 0xA0920E + eproj_spawn_varE24 = a; + SpawnEnemyProjectileWithGfx(varE20, k, addr_kEproj_Pickup); } void DeleteEnemyAndConnectedEnemies(void) { // 0xA0922B @@ -1893,175 +1831,138 @@ void DeleteEnemyAndConnectedEnemies(void) { // 0xA0922B } uint16 SpawnEnemy(uint8 db, uint16 k) { // 0xA09275 - VoidP v7; - enemy_population_ptr = k; - cur_enemy_index_backup = cur_enemy_index; - enemy_ai_pointer_backup.addr = enemy_ai_pointer.addr; - *(uint16 *)&enemy_ai_pointer_backup.bank = *(uint16 *)&enemy_ai_pointer.bank; + uint16 varE20 = k; + uint16 cur_enemy_index_backup = cur_enemy_index; uint16 enemy_ptr = get_EnemyPopulation(db, k)->enemy_ptr; int16 v3 = get_EnemyDef_A2(enemy_ptr)->num_parts - 1; if (v3 < 0) v3 = 0; - draw_oam_x_offset = v3; - varE26 = v3; - new_enemy_index = 0; + uint16 varE22 = v3; + uint16 varE26 = v3; + uint16 new_enemy_index = 0; do { uint16 v4 = new_enemy_index; - if (!gEnemyData(new_enemy_index)->enemy_ptr) { - while (!gEnemyData(v4)->enemy_ptr) { - if (!draw_oam_x_offset) { - while (1) { - uint16 v5 = new_enemy_index; - EnemyPopulation *EP = get_EnemyPopulation(db, enemy_population_ptr); - v7 = EP->enemy_ptr; - uint16 v8 = 0; - if (EP->enemy_ptr == enemy_def_ptr[0] - || (v8 = 2, v7 == enemy_def_ptr[1]) - || (v8 = 4, v7 == enemy_def_ptr[2]) - || (v8 = 6, v7 == enemy_def_ptr[3])) { - int v10 = v8 >> 1; - EnemyData *v11 = gEnemyData(new_enemy_index); - v11->vram_tiles_index = enemy_gfxdata_tiles_index[v10]; - v11->palette_index = 2 * swap16(enemy_gfxdata_vram_ptr[v10]); - } else { - EnemyData *v9 = gEnemyData(new_enemy_index); - v9->vram_tiles_index = 0; - v9->palette_index = 0; - } - EnemyDef_A2 * edef = get_EnemyDef_A2(EP->enemy_ptr); - EnemyData *v15 = gEnemyData(v5); - v15->x_width = edef->x_radius; - v15->y_height = edef->y_radius; - v15->health = edef->health; - v15->layer = edef->layer; - *(uint16 *)&v15->bank = *(uint16 *)&edef->bank; - v15->enemy_ptr = EP->enemy_ptr; - v15->x_pos = EP->x_pos; - v15->y_pos = EP->y_pos; - v15->current_instruction = EP->init_param; - v15->properties = EP->properties; - v15->extra_properties = EP->extra_properties; - v15->parameter_1 = EP->parameter1; - v15->parameter_2 = EP->parameter2; - v15->frame_counter = 0; - v15->timer = 0; - v15->ai_var_A = 0; - v15->ai_var_B = 0; - v15->ai_var_C = 0; - v15->ai_var_D = 0; - v15->ai_var_E = 0; - v15->ai_preinstr = 0; - v15->instruction_timer = 1; - v15->frame_counter = 0; - RecordEnemySpawnData(v5); - cur_enemy_index = v5; - if (sign16(edef->ai_init)) - CallEnemyAi(edef->bank << 16 | edef->ai_init); - EnemyData *v18 = gEnemyData(v5); - if ((v18->properties & 0x2000) != 0) - v18->spritemap_pointer = addr_kSpritemap_Nothing_A0; - if (!varE26) - break; - if (!--varE26) - break; - new_enemy_index += 64; - enemy_population_ptr += 16; - } - enemy_ai_pointer.addr = enemy_ai_pointer_backup.addr; - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&enemy_ai_pointer_backup.bank; - cur_enemy_index = cur_enemy_index_backup; - return new_enemy_index; - } - --draw_oam_x_offset; - v4 += 64; - if ((int16)(v4 - 2048) >= 0) - return 0xffff; - } + while (!gEnemyData(v4)->enemy_ptr) { + if (!varE22) + goto add_enemy; + --varE22; + v4 += 64; + if (v4 >= 2048) + return 0xffff; } new_enemy_index += 64; - } while (sign16(new_enemy_index - 2048)); + } while (new_enemy_index < 2048); return 0xffff; + +add_enemy: + while (1) { + EnemyData *E = gEnemyData(new_enemy_index); + EnemyPopulation *EP = get_EnemyPopulation(db, varE20); + int v10 = 0; + if (EP->enemy_ptr == enemy_def_ptr[0] || + (v10 = 1, EP->enemy_ptr == enemy_def_ptr[1]) || + (v10 = 2, EP->enemy_ptr == enemy_def_ptr[2]) || + (v10 = 3, EP->enemy_ptr == enemy_def_ptr[3])) { + E->vram_tiles_index = enemy_gfxdata_tiles_index[v10]; + E->palette_index = 2 * swap16(enemy_gfxdata_vram_ptr[v10]); + } else { + E->vram_tiles_index = 0; + E->palette_index = 0; + } + EnemyDef_A2 *ED = get_EnemyDef_A2(EP->enemy_ptr); + E->x_width = ED->x_radius; + E->y_height = ED->y_radius; + E->health = ED->health; + E->layer = ED->layer; + *(uint16 *)&E->bank = *(uint16 *)&ED->bank; + E->enemy_ptr = EP->enemy_ptr; + E->x_pos = EP->x_pos; + E->y_pos = EP->y_pos; + E->current_instruction = EP->init_param; + E->properties = EP->properties; + E->extra_properties = EP->extra_properties; + E->parameter_1 = EP->parameter1; + E->parameter_2 = EP->parameter2; + E->frame_counter = 0; + E->timer = 0; + E->ai_var_A = 0; + E->ai_var_B = 0; + E->ai_var_C = 0; + E->ai_var_D = 0; + E->ai_var_E = 0; + E->ai_preinstr = 0; + E->instruction_timer = 1; + E->frame_counter = 0; + RecordEnemySpawnData(new_enemy_index); + cur_enemy_index = new_enemy_index; + if (sign16(ED->ai_init)) + CallEnemyAi(ED->bank << 16 | ED->ai_init); + if ((E->properties & 0x2000) != 0) + E->spritemap_pointer = addr_kSpritemap_Nothing_A0; + if (!varE26 || !--varE26) { + cur_enemy_index = cur_enemy_index_backup; + return new_enemy_index; + } + new_enemy_index += 64; + varE20 += 16; + } } void DrawOneEnemy(void) { // 0xA09423 - enemy_drawing_queue_index = 2 * gEnemyData(cur_enemy_index)->layer; - *(uint16 *)RomPtr_RAM( - enemy_drawing_queue_sizes[enemy_drawing_queue_index >> 1] - + kEnemyLayerToQueuePtr[enemy_drawing_queue_index >> 1]) = cur_enemy_index; - int v0 = enemy_drawing_queue_index >> 1; - ++enemy_drawing_queue_sizes[v0]; - ++enemy_drawing_queue_sizes[v0]; + uint16 varE34 = 2 * gEnemyData(cur_enemy_index)->layer; + *(uint16 *)RomPtr_RAM(enemy_drawing_queue_sizes[varE34 >> 1] + kEnemyLayerToQueuePtr[varE34 >> 1]) = cur_enemy_index; + enemy_drawing_queue_sizes[varE34 >> 1] += 2; } void WriteEnemyOams(void) { // 0xA0944A - EnemySpawnData *v1; VoidP palette_index; - ExtendedSpriteMap *ExtendedSpriteMap; - - uint8 db = gEnemyData(cur_enemy_index)->bank; - EnemyData *v0 = gEnemyData(cur_enemy_index); - v1 = gEnemySpawnData(cur_enemy_index); - draw_oam_x_offset = v1->xpos2 + v0->x_pos - layer1_x_pos; - R20_ = draw_oam_x_offset; - enemy_population_ptr = v1->ypos2 + v0->y_pos - layer1_y_pos; - R18_ = enemy_population_ptr; - if (v0->shake_timer) { - if ((v0->frame_counter & 2) != 0) { - --R20_; - --draw_oam_x_offset; - } else { - ++R20_; - ++draw_oam_x_offset; - } - --v0->shake_timer; + + EnemyData *E = gEnemyData(cur_enemy_index); + EnemySpawnData *ES = gEnemySpawnData(cur_enemy_index); + uint16 x2 = ES->xpos2 + E->x_pos - layer1_x_pos; + uint16 y2 = ES->ypos2 + E->y_pos - layer1_y_pos; + if (E->shake_timer) { + x2 += ((E->frame_counter & 2) == 0) ? 1 : -1; + E->shake_timer--; } - if (v0->flash_timer && (enemy_damage_routine_exec_count & 2) != 0) { + uint16 x = x2, y = y2; + if (E->flash_timer && (random_enemy_counter & 2) != 0) { palette_index = 0; } else { - uint16 frozen_timer = v0->frozen_timer; - if (frozen_timer && (frozen_timer >= 0x5Au || (frozen_timer & 2) != 0)) + if (E->frozen_timer && (E->frozen_timer >= 0x5A || (E->frozen_timer & 2) != 0)) palette_index = 3072; else - palette_index = v0->palette_index; + palette_index = E->palette_index; } - R3_.addr = palette_index; - R0_.addr = v0->vram_tiles_index; - if ((v0->extra_properties & 4) != 0) { - while ((int16)(v0->spritemap_pointer + 0x8000) < 0) - ; - uint16 spritemap_pointer = v0->spritemap_pointer; - remaining_enemy_spritemap_entries = *RomPtrWithBank(db, spritemap_pointer); - uint16 v5 = spritemap_pointer + 2; + uint16 r3 = palette_index; + uint16 r0 = E->vram_tiles_index; + if ((E->extra_properties & 4) != 0) { + if ((int16)(E->spritemap_pointer + 0x8000) < 0) + Unreachable(); + int n = *RomPtrWithBank(E->bank, E->spritemap_pointer); + uint16 v5 = E->spritemap_pointer + 2; do { - ExtendedSpriteMap = get_ExtendedSpriteMap(db, v5); - R22_ = ExtendedSpriteMap->spritemap; - if (*(uint16 *)RomPtrWithBank(db, R22_) == 0xFFFE) { - R20_ = draw_oam_x_offset + ExtendedSpriteMap->xpos; - R18_ = enemy_population_ptr + ExtendedSpriteMap->ypos; - if ((gEnemyData(cur_enemy_index)->extra_properties & 0x8000u) != 0) - ProcessExtendedTilemap(db); + ExtendedSpriteMap *ext = get_ExtendedSpriteMap(E->bank, v5); + if (*(uint16 *)RomPtrWithBank(E->bank, ext->spritemap) == 0xFFFE) { + x = x2 + ext->xpos; + y = y2 + ext->ypos; + if ((E->extra_properties & 0x8000) != 0) + ProcessExtendedTilemap(E->bank, ext->spritemap); } else { - R20_ = draw_oam_x_offset + ExtendedSpriteMap->xpos; - if (((R20_ + 128) & 0xFE00) == 0) { - uint16 ypos = ExtendedSpriteMap->ypos; - R18_ = enemy_population_ptr + ypos; - if (((R18_ + 128) & 0xFE00) == 0) { - if (HIBYTE(R18_)) - DrawSpritemapWithBaseTileOffscreen(db, R22_, R20_, R18_); - else - DrawSpritemapWithBaseTile2(db, R22_); - } + x = x2 + ext->xpos; + y = y2 + ext->ypos; + if (((x + 128) & 0xFE00) == 0 && ((y + 128) & 0xFE00) == 0) { + if (HIBYTE(y)) + DrawSpritemapWithBaseTileOffscreen(E->bank, ext->spritemap, x, y, r3, r0); + else + DrawSpritemapWithBaseTile2(E->bank, ext->spritemap, x, y, r3, r0); } } v5 += 8; - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + } while (--n); } else { - g_word_7EF37E = v0->enemy_ptr; - g_word_7EF37A = v0->current_instruction; - g_word_7EF37C = cur_enemy_index; enemy_processing_stage = 1; - DrawSpritemapWithBaseTile(db, v0->spritemap_pointer); + DrawSpritemapWithBaseTile(E->bank, E->spritemap_pointer, x, y, r3, r0); } } @@ -2075,8 +1976,8 @@ void NormalEnemyFrozenAI(void) { // 0xA0957E } } -void ProcessExtendedTilemap(uint8 db) { // 0xA096CA - const uint8 *p = RomPtrWithBank(db, R22_ + 2); +void ProcessExtendedTilemap(uint8 db, uint16 r22) { // 0xA096CA + const uint8 *p = RomPtrWithBank(db, r22 + 2); while (1) { uint16 v2 = *(uint16 *)p; if (v2 == 0xFFFF) @@ -2087,7 +1988,6 @@ void ProcessExtendedTilemap(uint8 db) { // 0xA096CA p += n * 2; } ++nmi_flag_bg2_enemy_vram_transfer; - remaining_enemy_hitbox_entries = 0; } void QueueEnemyBG2TilemapTransfers(void) { // 0xA09726 @@ -2097,7 +1997,7 @@ void QueueEnemyBG2TilemapTransfers(void) { // 0xA09726 v0 = gVramWriteEntry(vram_write_queue_tail); v0->size = enemy_bg2_tilemap_size; v0->src.addr = ADDR16_OF_RAM(*tilemap_stuff); - *(uint16 *)&v0->src.bank = 126; + v0->src.bank = 126; v0->vram_dst = addr_unk_604800; vram_write_queue_tail += 7; } @@ -2121,97 +2021,57 @@ void func_nullsub_4(void) { } void SamusProjectileInteractionHandler(void) { // 0xA09785 - int16 v2; - enemy_processing_stage = 10; - if (!flag_disable_projectile_interaction) { - num_projs_to_check = 5; - if (bomb_counter) { - num_projs_to_check = 10; - } else if (!projectile_counter) { - return; - } - if (!projectile_invincibility_timer && !samus_contact_damage_index) { - collision_detection_index = 0; - do { - int v1 = collision_detection_index; - if (projectile_damage[v1]) { - v2 = projectile_type[v1]; - if (v2 >= 0) { - if (sign16((v2 & 0xF00) - 1792)) { - int v3 = collision_detection_index; - if ((projectile_dir[v3] & 0x10) == 0) { - uint16 v4 = abs16(projectile_x_pos[v3] - samus_x_pos); - bool v5 = v4 < projectile_x_radius[v3]; - uint16 v6 = v4 - projectile_x_radius[v3]; - if (v5 || v6 < samus_x_radius) { - uint16 v7 = abs16(projectile_y_pos[v3] - samus_y_pos); - v5 = v7 < projectile_y_radius[v3]; - uint16 v8 = v7 - projectile_y_radius[v3]; - if (v5 || v8 < samus_y_radius) { - if ((projectile_type[v3] & 0xFF00) != 768 && (projectile_type[v3] & 0xFF00) != 1280) { - projectile_dir[v3] |= 0x10u; - uint16 v10 = SuitDamageDivision(projectile_damage[v3]); - Samus_DealDamage(v10); - samus_invincibility_timer = 96; - samus_knockback_timer = 5; - assert(0); - uint16 v0 = 0; - knockback_x_dir = (int16)(samus_x_pos - enemy_projectile_x_pos[v0 >> 1]) >= 0; - return; - } - if (projectile_variables[v3] == 8) { - uint16 v9; - if (samus_x_pos == projectile_x_pos[v3]) { - v9 = 2; - } else if ((int16)(samus_x_pos - projectile_x_pos[v3]) < 0) { - v9 = 1; - } else { - v9 = 3; - } - bomb_jump_dir = v9; - } - } - } - } - } - } - } - ++collision_detection_index; - } while (collision_detection_index != num_projs_to_check); + if (flag_disable_projectile_interaction) + return; + int num_colls_to_check = 5; + if (bomb_counter) { + num_colls_to_check = 10; + } else if (!projectile_counter) { + return; + } + if (projectile_invincibility_timer || samus_contact_damage_index) + return; + for (int pidx = 0; pidx != num_colls_to_check;pidx++) { + collision_detection_index = pidx; + if (!projectile_damage[pidx] || sign16(projectile_type[pidx]) || !sign16((projectile_type[pidx] & 0xF00) - 1792)) + continue; + if ((projectile_dir[pidx] & 0x10) != 0) + continue; + if (abs16(projectile_x_pos[pidx] - samus_x_pos) - projectile_x_radius[pidx] < samus_x_radius && + abs16(projectile_y_pos[pidx] - samus_y_pos) - projectile_y_radius[pidx] < samus_y_radius) { + if ((projectile_type[pidx] & 0xFF00) != 768 && (projectile_type[pidx] & 0xFF00) != 1280) { + projectile_dir[pidx] |= 0x10; + Samus_DealDamage(SuitDamageDivision(projectile_damage[pidx])); + samus_invincibility_timer = 96; + samus_knockback_timer = 5; + assert(0); + uint16 v0 = 0; + knockback_x_dir = (int16)(samus_x_pos - enemy_projectile_x_pos[v0 >> 1]) >= 0; + return; + } + if (projectile_variables[pidx] == 8) { + bomb_jump_dir = (samus_x_pos == projectile_x_pos[pidx]) ? 2 : + (int16)(samus_x_pos - projectile_x_pos[pidx]) < 0 ? 1 : 3; + } } } } void EprojSamusCollDetect(void) { // 0xA09894 enemy_processing_stage = 11; - if (!samus_invincibility_timer && !samus_contact_damage_index) { - collision_detection_index = 34; - do { - if (*(uint16 *)((uint8 *)enemy_projectile_id + collision_detection_index)) { - int v0 = collision_detection_index >> 1; - if ((enemy_projectile_properties[v0] & 0x2000) == 0) { - if (LOBYTE(enemy_projectile_radius[v0])) { - enemy_population_ptr = LOBYTE(enemy_projectile_radius[v0]); - if (HIBYTE(enemy_projectile_radius[v0])) { - draw_oam_x_offset = HIBYTE(enemy_projectile_radius[v0]); - uint16 v1 = abs16(samus_x_pos - enemy_projectile_x_pos[v0]); - bool v2 = v1 < samus_x_radius; - uint16 v3 = v1 - samus_x_radius; - if (v2 || v3 < enemy_population_ptr) { - uint16 v4 = abs16(samus_y_pos - enemy_projectile_y_pos[v0]); - v2 = v4 < samus_y_radius; - uint16 v5 = v4 - samus_y_radius; - if (v2 || v5 < draw_oam_x_offset) - HandleEprojCollWithSamus(collision_detection_index); - } - } - } - } + if (samus_invincibility_timer || samus_contact_damage_index) + return; + for(int i = 17; i >= 0; i--) { + if (enemy_projectile_id[i] && (enemy_projectile_properties[i] & 0x2000) == 0 && enemy_projectile_radius[i]) { + uint16 varE20 = LOBYTE(enemy_projectile_radius[i]); + uint16 varE22 = HIBYTE(enemy_projectile_radius[i]); + if (abs16(samus_x_pos - enemy_projectile_x_pos[i]) - samus_x_radius < varE20 && + abs16(samus_y_pos - enemy_projectile_y_pos[i]) - samus_y_radius < varE22) { + collision_detection_index = i * 2; + HandleEprojCollWithSamus(i * 2); } - --collision_detection_index; - --collision_detection_index; - } while ((collision_detection_index & 0x8000u) == 0); + } } } @@ -2227,69 +2087,46 @@ void HandleEprojCollWithSamus(uint16 k) { // 0xA09923 int v3 = k >> 1; if ((enemy_projectile_properties[v3] & 0x4000) == 0) *(uint16 *)((uint8 *)enemy_projectile_id + k) = 0; - uint16 v4 = SuitDamageDivision(enemy_projectile_properties[v3] & 0xFFF); - Samus_DealDamage(v4); + Samus_DealDamage(SuitDamageDivision(enemy_projectile_properties[v3] & 0xFFF)); knockback_x_dir = (int16)(samus_x_pos - enemy_projectile_x_pos[v3]) >= 0; } void EprojProjCollDet(void) { // 0xA0996C - int16 v5; - enemy_processing_stage = 12; - if (projectile_counter) { - collision_detection_index = 34; - do { - uint16 v0 = collision_detection_index; - if (*(uint16 *)((uint8 *)enemy_projectile_id + collision_detection_index) - && (enemy_projectile_properties[collision_detection_index >> 1] & 0x8000u) != 0) { - uint16 v1 = 0; - do { - int v2 = v0 >> 1; - if (enemy_projectile_flags[v2] == 2) - break; - int v3 = v1 >> 1; - uint16 v4 = projectile_type[v3]; - if (v4) { - v5 = v4 & 0xF00; - if (v5 != 768 && v5 != 1280) { - if (sign16(v5 - 1792)) { - R18_ = projectile_x_pos[v3] & 0xFFE0; - if ((enemy_projectile_x_pos[v2] & 0xFFE0) == R18_) { - R18_ = projectile_y_pos[v3] & 0xFFE0; - if ((enemy_projectile_y_pos[v2] & 0xFFE0) == R18_) - HandleEprojCollWithProj(v0, v1); - } - } - } - } - v1 += 2; - } while ((int16)(v1 - 10) < 0); + if (!projectile_counter) + return; + for(int i = 17; i >= 0; i--) { + if (!enemy_projectile_id[i] || (enemy_projectile_properties[i] & 0x8000) == 0) + continue; + for(int j = 0; j < 5; j++) { + if (enemy_projectile_flags[i] == 2) + break; + uint16 v4 = projectile_type[j]; + if (v4 && (v4 & 0xF00) != 768 && (v4 & 0xF00) != 1280 && sign16((v4 & 0xF00) - 1792)) { + if ((enemy_projectile_x_pos[i] & 0xFFE0) == (projectile_x_pos[j] & 0xFFE0) && + (enemy_projectile_y_pos[i] & 0xFFE0) == (projectile_y_pos[j] & 0xFFE0)) { + HandleEprojCollWithProj(i * 2, j * 2); + } } - --collision_detection_index; - --collision_detection_index; - } while ((collision_detection_index & 0x8000u) == 0); + } } } void HandleEprojCollWithProj(uint16 k, uint16 j) { // 0xA099F9 - int v2 = j >> 1; - if ((projectile_type[v2] & 8) == 0) - projectile_dir[v2] |= 0x10u; + int i = j >> 1; + if ((projectile_type[i] & 8) == 0) + projectile_dir[i] |= 0x10; if (enemy_projectile_flags[k >> 1] == 1) { int v4 = k >> 1; - R18_ = projectile_x_pos[v4]; - R20_ = projectile_y_pos[v4]; - R22_ = 6; - R24_ = 0; - CreateSpriteAtPos(); - QueueSfx1_Max6(0x3Du); + CreateSpriteAtPos(projectile_x_pos[v4], projectile_y_pos[v4], 6, 0); + QueueSfx1_Max6(0x3D); } else { - int v3 = k >> 1; - enemy_projectile_G[v3] = projectile_type[v2]; - enemy_projectile_instr_list_ptr[v3] = get_EnemyProjectileDef(*(uint16 *)((uint8 *)enemy_projectile_id + k))->shot_instruction_list; - enemy_projectile_instr_timers[v3] = 1; - enemy_projectile_pre_instr[v3] = FUNC16(EprojPreInstr_nullsub_83); - enemy_projectile_properties[v3] &= 0xFFFu; + int j = k >> 1; + enemy_projectile_G[j] = projectile_type[i]; + enemy_projectile_instr_list_ptr[j] = get_EnemyProjectileDef(enemy_projectile_id[j])->shot_instruction_list; + enemy_projectile_instr_timers[j] = 1; + enemy_projectile_pre_instr[j] = FUNC16(EprojPreInstr_nullsub_83); + enemy_projectile_properties[j] &= 0xFFF; } } @@ -2351,157 +2188,84 @@ void CallHitboxShot(uint32 ea, uint16 j) { // 0xA09D17 } void EnemySamusCollHandler_Multibox(void) { // 0xA09A5A - VoidP touch_ai; - ExtendedSpriteMap *ExtendedSpriteMap; - VoidP hitbox_ptr_; - Hitbox *Hitbox; - - uint16 *v0 = (uint16 *)gEnemyData(cur_enemy_index); - *(uint16 *)&enemy_ai_pointer.bank = v0[23]; + EnemyData *E = gEnemyData(cur_enemy_index); enemy_processing_stage = 6; - if (v0[11]) { - touch_ai = get_EnemyDef_A2(*v0)->touch_ai; - if (touch_ai != FUNC16(nullsub_170) && touch_ai != FUNC16(nullsub_169)) { - if (samus_contact_damage_index) { - samus_invincibility_timer = 0; - } else if (samus_invincibility_timer) { + if (!E->spritemap_pointer) + return; + + uint16 touch_ai = get_EnemyDef_A2(E->enemy_ptr)->touch_ai; + if (touch_ai == FUNC16(nullsub_170) || touch_ai == FUNC16(nullsub_169)) + return; + + if (samus_contact_damage_index) { + samus_invincibility_timer = 0; + } else if (samus_invincibility_timer) { + return; + } + if (!sign16(E->spritemap_pointer)) + return; + + uint16 samus_right_border_coll = samus_x_radius + samus_x_pos; + uint16 samus_left_border_coll = samus_x_pos - samus_x_radius; + uint16 samus_bottom_border_coll = samus_y_radius + samus_y_pos; + uint16 samus_top_border_coll = samus_y_pos - samus_y_radius; + int n = *RomPtrWithBank(E->bank, E->spritemap_pointer); + uint16 enemy_spritemap_entry_pointer = E->spritemap_pointer + 2; + do { + ExtendedSpriteMap *ES = get_ExtendedSpriteMap(E->bank, enemy_spritemap_entry_pointer); + uint16 coll_x_pos = ES->xpos + E->x_pos; + uint16 coll_y_pos = ES->ypos + E->y_pos; + const uint8 *p = RomPtrWithBank(E->bank, ES->hitbox_ptr_); + int m = GET_WORD(p); + for(Hitbox *hb = (Hitbox *)(p + 2); m; m--, hb++) { + if ((int16)(hb->left + coll_x_pos - samus_right_border_coll) < 0 + && (int16)(hb->right + coll_x_pos - samus_left_border_coll) >= 0 + && (int16)(hb->top + coll_y_pos - samus_bottom_border_coll) < 0 + && (int16)(hb->bottom + coll_y_pos - samus_top_border_coll) >= 0) { + CallHitboxTouch(E->bank << 16 | hb->func_ptr); return; } - EnemyData *v2 = gEnemyData(cur_enemy_index); - if (!sign16(v2->spritemap_pointer + 0x8000)) { - samus_right_border_coll = samus_x_radius + samus_x_pos; - samus_left_border_coll = samus_x_pos - samus_x_radius; - samus_bottom_border_coll = samus_y_radius + samus_y_pos; - samus_top_border_coll = samus_y_pos - samus_y_radius; - uint16 spritemap_pointer = v2->spritemap_pointer; - remaining_enemy_spritemap_entries = *RomPtrWithBank(enemy_ai_pointer.bank, spritemap_pointer); - enemy_spritemap_entry_pointer = spritemap_pointer + 2; - uint16 *v7; - while (1) { - EnemyData *v4; - v4 = gEnemyData(cur_enemy_index); - ExtendedSpriteMap = get_ExtendedSpriteMap(enemy_ai_pointer.bank, enemy_spritemap_entry_pointer); - enemy_spritemap_entry_coll_x_pos = ExtendedSpriteMap->xpos + v4->x_pos; - num_projs_to_check = ExtendedSpriteMap->ypos + v4->y_pos; - hitbox_ptr_ = ExtendedSpriteMap->hitbox_ptr_; - v7 = (uint16 *)RomPtrWithBank(enemy_ai_pointer.bank, hitbox_ptr_); - if (*v7) - break; -LABEL_18: - enemy_spritemap_entry_pointer += 8; - if ((int16)--remaining_enemy_spritemap_entries <= 0) - return; - } - remaining_enemy_hitbox_entries = *v7; - hitbox_ptr = hitbox_ptr_ + 2; - while (1) { - Hitbox = get_Hitbox(enemy_ai_pointer.bank, hitbox_ptr); - if ((int16)(Hitbox->left + enemy_spritemap_entry_coll_x_pos - samus_right_border_coll) < 0 - && (int16)(Hitbox->right + enemy_spritemap_entry_coll_x_pos - samus_left_border_coll) >= 0 - && (int16)(Hitbox->top + num_projs_to_check - samus_bottom_border_coll) < 0 - && (int16)(Hitbox->bottom + num_projs_to_check - samus_top_border_coll) >= 0) { - break; - } - hitbox_ptr += 12; - if ((int16)--remaining_enemy_hitbox_entries <= 0) - goto LABEL_18; - } - enemy_ai_pointer.addr = get_Hitbox(enemy_ai_pointer.bank, hitbox_ptr)->func_ptr; - CallHitboxTouch(Load24(&enemy_ai_pointer)); - } } - } + enemy_spritemap_entry_pointer += 8; + } while (--n); } void EnemyProjectileCollHandler_Multibox(void) { // 0xA09B7F - VoidP shot_ai; - int16 v5; - Hitbox *v11; - Hitbox *v12; - Hitbox *Hitbox; - - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&gEnemyData(cur_enemy_index)->bank; + EnemyData *E = gEnemyData(cur_enemy_index); enemy_processing_stage = 3; - if (projectile_counter) { - num_projectiles_to_check_enemy_coll = projectile_counter; - EnemyData *v0 = gEnemyData(cur_enemy_index); - uint16 spritemap_pointer = v0->spritemap_pointer; - if (spritemap_pointer) { - if (spritemap_pointer != addr_kExtendedSpritemap_Nothing_A0) { - shot_ai = get_EnemyDef_A2(v0->enemy_ptr)->shot_ai; - if (shot_ai != FUNC16(nullsub_170) && shot_ai != FUNC16(nullsub_169)) { - EnemyData *v3 = gEnemyData(cur_enemy_index); - if ((v3->properties & 0x400) == 0 - && !v3->invincibility_timer - && v3->enemy_ptr != addr_kEnemyDef_DAFF) { - collision_detection_index = 0; - while (1) { - uint16 v4; - v4 = projectile_type[collision_detection_index]; - if (v4) { - v5 = v4 & 0xF00; - if (v5 != 768 && v5 != 1280 && sign16(v5 - 1792)) - break; - } -LABEL_37: - if (!sign16(++collision_detection_index - 5)) - return; - } - EnemyData *v6 = gEnemyData(cur_enemy_index); - while ((int16)(v6->spritemap_pointer + 0x8000) < 0) - ; - uint16 v7 = v6->spritemap_pointer; - uint16 bottom; - remaining_enemy_spritemap_entries = *RomPtrWithBank(enemy_ai_pointer.bank, v7); - enemy_spritemap_entry_pointer = v7 + 2; - while (1) { - EnemyData *v8; - v8 = gEnemyData(cur_enemy_index); - Hitbox = get_Hitbox(enemy_ai_pointer.bank, enemy_spritemap_entry_pointer); - enemy_spritemap_entry_coll_x_pos = Hitbox->left + v8->x_pos; - num_projs_to_check = Hitbox->top + v8->y_pos; - bottom = Hitbox->bottom; - v11 = get_Hitbox(enemy_ai_pointer.bank, bottom); - if (v11->left) - break; -LABEL_34: - enemy_spritemap_entry_pointer += 8; - bool v15 = (--remaining_enemy_spritemap_entries & 0x8000u) != 0; - if (!remaining_enemy_spritemap_entries || v15) - goto LABEL_37; - } - remaining_enemy_hitbox_entries = v11->left; - hitbox_ptr = bottom + 2; - int v13; - while (1) { - v12 = get_Hitbox(enemy_ai_pointer.bank, hitbox_ptr); - enemy_left_border_collision = enemy_spritemap_entry_coll_x_pos + v12->left; - v13 = collision_detection_index; - if ((int16)(projectile_x_radius[v13] + projectile_x_pos[v13] - enemy_left_border_collision) >= 0) { - enemy_right_border_collision = enemy_spritemap_entry_coll_x_pos + v12->right; - if ((int16)(projectile_x_pos[v13] - projectile_x_radius[v13] - enemy_right_border_collision) < 0) { - enemy_bottom_border_collision = num_projs_to_check + v12->top; - if ((int16)(projectile_y_radius[v13] + projectile_y_pos[v13] - enemy_bottom_border_collision) >= 0) { - enemy_top_border_collision = num_projs_to_check + v12->bottom; - if ((int16)(projectile_y_pos[v13] - projectile_y_radius[v13] - enemy_top_border_collision) < 0) - break; - } - } - } - hitbox_ptr += 12; - bool v14 = (--remaining_enemy_hitbox_entries & 0x8000u) != 0; - if (!remaining_enemy_hitbox_entries || v14) - goto LABEL_34; - } - if ((projectile_type[v13] & 0xF00) == 512) { - earthquake_timer = 30; - earthquake_type = 18; - } - if ((gEnemyData(cur_enemy_index)->properties & 0x1000) != 0 || (projectile_type[v13] & 8) == 0) - projectile_dir[v13] |= 0x10u; - enemy_ai_pointer.addr = get_Hitbox(enemy_ai_pointer.bank, hitbox_ptr)->func_ptrA; - CallHitboxShot(Load24(&enemy_ai_pointer), collision_detection_index * 2); + if (!projectile_counter || !E->spritemap_pointer || E->spritemap_pointer == addr_kExtendedSpritemap_Nothing_A0) + return; + uint16 shot_ai = get_EnemyDef_A2(E->enemy_ptr)->shot_ai; + if (shot_ai == FUNC16(nullsub_170) || shot_ai == FUNC16(nullsub_169)) + return; + if ((E->properties & 0x400) != 0 || E->invincibility_timer || E->enemy_ptr == addr_kEnemyDef_DAFF) + return; + for(int pidx = 0; pidx < 5; pidx++) { + uint16 v4 = projectile_type[pidx]; + if (!(v4 && (v4 & 0xF00) != 768 && (v4 & 0xF00) != 1280 && sign16((v4 & 0xF00) - 1792))) + continue; + if (!sign16(E->spritemap_pointer)) + Unreachable(); + const uint8 *esep = RomPtrWithBank(E->bank, E->spritemap_pointer); + int n = esep[0]; + for(ExtendedSpriteMap *ES = (ExtendedSpriteMap *)(esep + 2); n; n--, ES++) { + uint16 coll_x_pos = ES->xpos + E->x_pos, coll_y_pos = ES->ypos + E->y_pos; + const uint8 *p = RomPtrWithBank(E->bank, ES->hitbox_ptr_); + int m = GET_WORD(p); + for (Hitbox *hb = (Hitbox *)(p + 2); m; m--, hb++) { + if ((int16)(projectile_x_radius[pidx] + projectile_x_pos[pidx] - (coll_x_pos + hb->left)) >= 0 && + (int16)(projectile_x_pos[pidx] - projectile_x_radius[pidx] - (coll_x_pos + hb->right)) < 0 && + (int16)(projectile_y_radius[pidx] + projectile_y_pos[pidx] - (coll_y_pos + hb->top)) >= 0 && + (int16)(projectile_y_pos[pidx] - projectile_y_radius[pidx] - (coll_y_pos + hb->bottom)) < 0) { + if ((projectile_type[pidx] & 0xF00) == 512) { + earthquake_timer = 30; + earthquake_type = 18; } + if ((E->properties & 0x1000) != 0 || (projectile_type[pidx] & 8) == 0) + projectile_dir[pidx] |= 0x10; + collision_detection_index = pidx; + CallHitboxShot(E->bank << 16 | hb->func_ptrA, pidx * 2); + return; } } } @@ -2509,119 +2273,71 @@ LABEL_34: } void EnemyBombCollHandler_Multibox(void) { // 0xA09D23 - VoidP shot_ai; - Hitbox *v11; - ExtendedSpriteMap *ExtendedSpriteMap; - Hitbox *Hitbox; - - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&gEnemyData(cur_enemy_index)->bank; + EnemyData *E = gEnemyData(cur_enemy_index); enemy_processing_stage = 4; - if (gEnemyData(cur_enemy_index)->spritemap_pointer) { - EnemyData *v0 = gEnemyData(cur_enemy_index); - if ((v0->properties & 0x400) == 0 && !v0->invincibility_timer) { - uint16 enemy_ptr = gEnemyData(cur_enemy_index)->enemy_ptr; - shot_ai = get_EnemyDef_A2(enemy_ptr)->shot_ai; - if (shot_ai != FUNC16(nullsub_170) - && shot_ai != FUNC16(nullsub_169) - && bomb_counter) { - collision_detection_index = 5; - while (1) { - int v3; - v3 = collision_detection_index; - if (projectile_x_pos[v3]) { - uint16 v4 = projectile_type[v3]; - if (v4) { - if ((v4 & 0xF00) == 1280 && !projectile_variables[v3]) - break; - } - } -LABEL_26: - if (++collision_detection_index == 10) - return; + if (!E->spritemap_pointer || (E->properties & 0x400) != 0 || E->invincibility_timer) + return; + uint16 shot_ai = get_EnemyDef_A2(E->enemy_ptr)->shot_ai; + if (shot_ai == FUNC16(nullsub_170) || shot_ai == FUNC16(nullsub_169) || !bomb_counter) + return; + for (int pidx = 5; pidx != 10; pidx++) { + if (!projectile_x_pos[pidx]) + continue; + uint16 v4 = projectile_type[pidx]; + if (!(v4 && (v4 & 0xF00) == 1280 && !projectile_variables[pidx])) + continue; + if (!sign16(E->spritemap_pointer)) + Unreachable(); + const uint8 *esep = RomPtrWithBank(E->bank, E->spritemap_pointer); + int n = GET_WORD(esep); + for (ExtendedSpriteMap *ES = (ExtendedSpriteMap *)(esep + 2); n; n--, ES++) { + uint16 coll_x_pos = ES->xpos + E->x_pos, coll_y_pos = ES->ypos + E->y_pos; + const uint8 *p = RomPtrWithBank(E->bank, ES->hitbox_ptr_); + int m = GET_WORD(p); + for (Hitbox *hb = (Hitbox *)(p + 2); m; m--, hb++) { + if ((int16)(projectile_x_radius[pidx] + projectile_x_pos[pidx] - (coll_x_pos + hb->left)) >= 0 && + (int16)(projectile_x_pos[pidx] - projectile_x_radius[pidx] - (coll_x_pos + hb->right)) < 0 && + (int16)(projectile_y_radius[pidx] + projectile_y_pos[pidx] - (coll_y_pos + hb->top)) >= 0 && + (int16)(projectile_y_pos[pidx] - projectile_y_radius[pidx] - (coll_y_pos + hb->bottom)) < 0) { + projectile_dir[pidx] |= 0x10; + collision_detection_index = pidx; + CallHitboxShot(E->bank << 16 | hb->func_ptrA, pidx * 2); + return; } - EnemyData *v5 = gEnemyData(cur_enemy_index); - while ((int16)(v5->spritemap_pointer + 0x8000) < 0) - ; - uint16 spritemap_pointer = v5->spritemap_pointer; - remaining_enemy_spritemap_entries = *RomPtrWithBank(enemy_ai_pointer.bank, spritemap_pointer); - enemy_spritemap_entry_pointer = spritemap_pointer + 2; - uint16 hitbox_ptr_; - while (1) { - EnemyData *v7; - v7 = gEnemyData(cur_enemy_index); - ExtendedSpriteMap = get_ExtendedSpriteMap(enemy_ai_pointer.bank, enemy_spritemap_entry_pointer); - enemy_spritemap_entry_coll_x_pos = ExtendedSpriteMap->xpos + v7->x_pos; - num_projs_to_check = ExtendedSpriteMap->ypos + v7->y_pos; - hitbox_ptr_ = ExtendedSpriteMap->hitbox_ptr_; - Hitbox = get_Hitbox(enemy_ai_pointer.bank, hitbox_ptr_); - if (Hitbox->left) - break; -LABEL_25: - enemy_spritemap_entry_pointer += 8; - if ((int16)--remaining_enemy_spritemap_entries <= 0) - goto LABEL_26; - } - remaining_enemy_hitbox_entries = Hitbox->left; - hitbox_ptr = hitbox_ptr_ + 2; - int v12; - while (1) { - v11 = get_Hitbox(enemy_ai_pointer.bank, hitbox_ptr); - enemy_left_border_collision = enemy_spritemap_entry_coll_x_pos + v11->left; - v12 = collision_detection_index; - if ((int16)(projectile_x_radius[v12] + projectile_x_pos[v12] - enemy_left_border_collision) >= 0) { - enemy_right_border_collision = enemy_spritemap_entry_coll_x_pos + v11->right; - if ((int16)(projectile_x_pos[v12] - projectile_x_radius[v12] - enemy_right_border_collision) < 0) { - enemy_bottom_border_collision = num_projs_to_check + v11->top; - if ((int16)(projectile_y_radius[v12] + projectile_y_pos[v12] - enemy_bottom_border_collision) >= 0) { - enemy_top_border_collision = num_projs_to_check + v11->bottom; - if ((int16)(projectile_y_pos[v12] - projectile_y_radius[v12] - enemy_top_border_collision) < 0) - break; - } - } - } - hitbox_ptr += 12; - if ((int16)--remaining_enemy_hitbox_entries <= 0) - goto LABEL_25; - } - projectile_dir[v12] |= 0x10u; - enemy_ai_pointer.addr = get_Hitbox(enemy_ai_pointer.bank, hitbox_ptr)->func_ptrA; - CallHitboxShot(Load24(&enemy_ai_pointer), collision_detection_index * 2); } } } } -uint16 GrappleBeam_CollDetect_Enemy(void) { // 0xA09E9A +PairU16 GrappleBeam_CollDetect_Enemy(void) { // 0xA09E9A VoidP grapple_ai; - EnemyData *ED; + EnemyData *E; - CallSomeSamusCode(0xDu); + CallSomeSamusCode(0xD); collision_detection_index = 0; for (int i = 0; ; i++) { cur_enemy_index = interactive_enemy_indexes[i]; - if (cur_enemy_index == 0xFFFF) { - R18_ = 0; - return 0; - } - ED = gEnemyData(cur_enemy_index); - if (!ED->invincibility_timer) { - uint16 v5 = abs16(ED->x_pos - grapple_beam_end_x_pos); - bool v6 = v5 < ED->x_width; - uint16 v7 = v5 - ED->x_width; - if (v6 || v7 < 8u) { - uint16 v8 = abs16(ED->y_pos - grapple_beam_end_y_pos); - v6 = v8 < ED->y_height; - uint16 v9 = v8 - ED->y_height; - if (v6 || v9 < 8u) + if (cur_enemy_index == 0xFFFF) + return (PairU16) { 0, 0 }; + E = gEnemyData(cur_enemy_index); + if (!E->invincibility_timer) { + uint16 v5 = abs16(E->x_pos - grapple_beam_end_x_pos); + bool v6 = v5 < E->x_width; + uint16 v7 = v5 - E->x_width; + if (v6 || v7 < 8) { + uint16 v8 = abs16(E->y_pos - grapple_beam_end_y_pos); + v6 = v8 < E->y_height; + uint16 v9 = v8 - E->y_height; + if (v6 || v9 < 8) break; } } } - ED->ai_handler_bits = 1; + E->ai_handler_bits = 1; uint16 v0 = 0; - uint16 enemy_ptr = ED->enemy_ptr; - grapple_ai = get_EnemyDef_A2(ED->enemy_ptr)->grapple_ai; - if (grapple_ai + FUNC16(Enemy_GrappleReact_NoInteract_A0)) { + uint16 enemy_ptr = E->enemy_ptr; + grapple_ai = get_EnemyDef_A2(E->enemy_ptr)->grapple_ai; + if (grapple_ai != FUNC16(Enemy_GrappleReact_NoInteract_A0)) { v0 = 1; if (grapple_ai != FUNC16(Enemy_GrappleReact_SamusLatchesOn_A0)) { v0 = 2; @@ -2641,41 +2357,32 @@ uint16 GrappleBeam_CollDetect_Enemy(void) { // 0xA09E9A } } } - R18_ = enemy_ptr; - uint16 result = v0; if (v0 == 1 || v0 == 4 || v0 == 5) { EnemyData *v11 = gEnemyData(cur_enemy_index); grapple_beam_end_x_pos = v11->x_pos; grapple_beam_end_y_pos = v11->y_pos; - return v0; } - return result; + return (PairU16) { v0, enemy_ptr }; } void SwitchEnemyAiToMainAi(void) { // 0xA09F6D - EnemyData *v0 = gEnemyData(cur_enemy_index); - v0->ai_handler_bits = 0; - v0->invincibility_timer = 0; - v0->frozen_timer = 0; - v0->shake_timer = 0; + EnemyData *E = gEnemyData(cur_enemy_index); + E->ai_handler_bits = 0; + E->invincibility_timer = 0; + E->frozen_timer = 0; + E->shake_timer = 0; } void SamusLatchesOnWithGrapple(void) { // 0xA09F7D - EnemyDef_A2 *EnemyDef_A2; - - EnemyData *v0 = gEnemyData(cur_enemy_index); - grapple_beam_end_x_pos = v0->x_pos; - grapple_beam_end_y_pos = v0->y_pos; - if (v0->frozen_timer) { - gEnemyData(cur_enemy_index)->ai_handler_bits = 4; + EnemyData *E = gEnemyData(cur_enemy_index); + grapple_beam_end_x_pos = E->x_pos; + grapple_beam_end_y_pos = E->y_pos; + if (E->frozen_timer) { + E->ai_handler_bits = 4; } else { - EnemyData *v1 = gEnemyData(cur_enemy_index); - EnemyDef_A2 = get_EnemyDef_A2(v1->enemy_ptr); - uint16 hurt_ai_time = EnemyDef_A2->hurt_ai_time; - if (!EnemyDef_A2->hurt_ai_time) - hurt_ai_time = 4; - gEnemyData(cur_enemy_index)->flash_timer = hurt_ai_time; - gEnemyData(cur_enemy_index)->ai_handler_bits = 0; + EnemyDef_A2 *ED = get_EnemyDef_A2(E->enemy_ptr); + E->flash_timer = ED->hurt_ai_time ? ED->hurt_ai_time : 4; + E->ai_handler_bits = 0; } } @@ -2690,37 +2397,23 @@ void Enemy_SwitchToFrozenAi(void) { // 0xA09FDF } void SamusLatchesOnWithGrappleNoInvinc(void) { // 0xA09FE9 - EnemyData *v0; - - if (gEnemyData(cur_enemy_index)->frozen_timer) { - v0 = gEnemyData(cur_enemy_index); - grapple_beam_end_x_pos = v0->x_pos; - grapple_beam_end_y_pos = v0->y_pos; - v0->ai_handler_bits = 4; + EnemyData *E = gEnemyData(cur_enemy_index); + if (E->frozen_timer) { + E->ai_handler_bits = 4; } else { - v0 = gEnemyData(cur_enemy_index); - enemy_ai_pointer.addr = get_EnemyDef_A2(v0->enemy_ptr)->main_ai; - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&gEnemyData(cur_enemy_index)->bank; - CallEnemyAi(Load24(&enemy_ai_pointer)); - EnemyData *v1 = gEnemyData(cur_enemy_index); - grapple_beam_end_x_pos = v1->x_pos; - grapple_beam_end_y_pos = v1->y_pos; - v1->ai_handler_bits = 0; + CallEnemyAi(E->bank << 16 | get_EnemyDef_A2(E->enemy_ptr)->main_ai); + E->ai_handler_bits = 0; } + grapple_beam_end_x_pos = E->x_pos; + grapple_beam_end_y_pos = E->y_pos; } void SamusLatchesOnWithGrappleParalyze(void) { // 0xA0A03E - EnemyDef_A2 *EnemyDef_A2; - - EnemyData *v0 = gEnemyData(cur_enemy_index); - EnemyDef_A2 = get_EnemyDef_A2(v0->enemy_ptr); - uint16 hurt_ai_time = EnemyDef_A2->hurt_ai_time; - if (!EnemyDef_A2->hurt_ai_time) - hurt_ai_time = 4; - gEnemyData(cur_enemy_index)->flash_timer = hurt_ai_time; - gEnemyData(cur_enemy_index)->ai_handler_bits = 0; - EnemyData *v3 = gEnemyData(cur_enemy_index); - v3->extra_properties |= 1u; + EnemyData *E = gEnemyData(cur_enemy_index); + EnemyDef_A2 *ED = get_EnemyDef_A2(E->enemy_ptr); + E->flash_timer = ED->hurt_ai_time ? ED->hurt_ai_time : 4; + E->ai_handler_bits = 0; + E->extra_properties |= 1; } void SamusHurtFromGrapple(void) { // 0xA0A070 @@ -2728,246 +2421,144 @@ void SamusHurtFromGrapple(void) { // 0xA0A070 } void EnemySamusCollHandler(void) { // 0xA0A07A - VoidP touch_ai; - + EnemyData *E = gEnemyData(cur_enemy_index); enemy_processing_stage = 9; - if (gEnemyData(cur_enemy_index)->spritemap_pointer) { - if (samus_contact_damage_index) { - samus_invincibility_timer = 0; - } else if (samus_invincibility_timer) { - if (gEnemyData(cur_enemy_index)->enemy_ptr != addr_kEnemyDef_DAFF) - return; - uint16 some_flag = gEnemySpawnData(cur_enemy_index)->some_flag; - if (!some_flag || some_flag == 8) - return; - } - uint16 enemy_ptr = gEnemyData(cur_enemy_index)->enemy_ptr; - touch_ai = get_EnemyDef_A2(enemy_ptr)->touch_ai; - if (touch_ai != FUNC16(nullsub_170) && touch_ai != FUNC16(nullsub_169)) { - EnemyData *v3 = gEnemyData(cur_enemy_index); - uint16 v4 = abs16(samus_x_pos - v3->x_pos); - bool v5 = v4 < samus_x_radius; - uint16 v6 = v4 - samus_x_radius; - if (v5 || v6 < v3->x_width) { - uint16 v7 = abs16(samus_y_pos - v3->y_pos); - v5 = v7 < samus_y_radius; - uint16 v8 = v7 - samus_y_radius; - if (v5 || v8 < v3->y_height) { - R20_ = 2 * gEnemyData(cur_enemy_index)->spritemap_pointer; - if (gEnemyData(cur_enemy_index)->enemy_ptr == addr_kEnemyDef_DAFF - || !gEnemyData(cur_enemy_index)->frozen_timer) { - enemy_ptr = gEnemyData(cur_enemy_index)->enemy_ptr; - enemy_ai_pointer.addr = get_EnemyDef_A2(enemy_ptr)->touch_ai; - enemy_ai_pointer.bank = gEnemyData(cur_enemy_index)->bank; - CallEnemyAi(Load24(&enemy_ai_pointer)); - } - } - } - } + if (!E->spritemap_pointer) + return; + if (samus_contact_damage_index) { + samus_invincibility_timer = 0; + } else if (samus_invincibility_timer) { + if (E->enemy_ptr != addr_kEnemyDef_DAFF) + return; + uint16 some_flag = gEnemySpawnData(cur_enemy_index)->some_flag; + if (some_flag == 0 || some_flag == 8) + return; + } + EnemyDef_A2 *ED = get_EnemyDef_A2(E->enemy_ptr); + if (ED->touch_ai == FUNC16(nullsub_170) || ED->touch_ai == FUNC16(nullsub_169)) + return; + if (abs16(samus_x_pos - E->x_pos) - samus_x_radius < E->x_width && + abs16(samus_y_pos - E->y_pos) - samus_y_radius < E->y_height) { + // r20 = 2 * E->spritemap_pointer; + if (E->enemy_ptr == addr_kEnemyDef_DAFF || !E->frozen_timer) + CallEnemyAi(E->bank << 16 | ED->touch_ai); } } void EnemyProjectileCollHandler(void) { // 0xA0A143 - int16 v4; - - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&gEnemyData(cur_enemy_index)->bank; + EnemyData *E = gEnemyData(cur_enemy_index); enemy_processing_stage = 7; - if (projectile_counter) { - EnemyData *v0 = gEnemyData(cur_enemy_index); - uint16 spritemap_pointer = v0->spritemap_pointer; - if (spritemap_pointer) { - if (spritemap_pointer != addr_kSpritemap_Nothing_A0 - && (v0->properties & 0x400) == 0 - && v0->enemy_ptr != addr_kEnemyDef_DAFF - && !v0->invincibility_timer) { - collision_detection_index = 0; - int v2; - while (1) { - v2 = collision_detection_index; - uint16 v3 = projectile_type[v2]; - if (v3) { - v4 = v3 & 0xF00; - if (v4 != 768 && v4 != 1280) { - if (sign16(v4 - 1792)) { - EnemyData *v5 = gEnemyData(cur_enemy_index); - uint16 v6 = abs16(projectile_x_pos[v2] - v5->x_pos); - bool v7 = v6 < projectile_x_radius[v2]; - uint16 v8 = v6 - projectile_x_radius[v2]; - if (v7 || v8 < v5->x_width) { - uint16 v9 = abs16(projectile_y_pos[v2] - v5->y_pos); - v7 = v9 < projectile_y_radius[v2]; - uint16 v10 = v9 - projectile_y_radius[v2]; - if (v7 || v10 < v5->y_height) - break; - } - } - } + if (!projectile_counter) + return; + if (!E->spritemap_pointer || E->spritemap_pointer == addr_kSpritemap_Nothing_A0 || (E->properties & 0x400) != 0 || + E->enemy_ptr == addr_kEnemyDef_DAFF || E->invincibility_timer) + return; + for (int pidx = 0; pidx < 5; pidx++) { + uint16 j = projectile_type[pidx]; + if (j && (j & 0xF00) != 768 && (j & 0xF00) != 1280 && sign16((j & 0xF00) - 1792)) { + uint16 x = abs16(projectile_x_pos[pidx] - E->x_pos); + uint16 y = abs16(projectile_y_pos[pidx] - E->y_pos); + if (x - projectile_x_radius[pidx] < E->x_width) { + if (y - projectile_y_radius[pidx] < E->y_height) { + if ((projectile_type[pidx] & 0xF00) == 512) { + earthquake_timer = 30; + earthquake_type = 18; } - if (++collision_detection_index == 5) - return; + if ((E->properties & 0x1000) != 0 || (projectile_type[pidx] & 8) == 0) + projectile_dir[pidx] |= 0x10; + collision_detection_index = pidx; + CallEnemyAi(E->bank << 16 | get_EnemyDef_A2(E->enemy_ptr)->shot_ai); + return; } - if ((projectile_type[v2] & 0xF00) == 512) { - earthquake_timer = 30; - earthquake_type = 18; - } - uint16 v11 = 2 * collision_detection_index; - if ((gEnemyData(cur_enemy_index)->properties & 0x1000) != 0 || (projectile_type[v11 >> 1] & 8) == 0) - projectile_dir[v11 >> 1] |= 0x10u; - uint16 enemy_ptr; - enemy_ptr = gEnemyData(cur_enemy_index)->enemy_ptr; - enemy_ai_pointer.addr = get_EnemyDef_A2(enemy_ptr)->shot_ai; - CallEnemyAi(Load24(&enemy_ai_pointer)); } } } } void EnemyBombCollHandler(void) { // 0xA0A236 - int v8; - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&gEnemyData(cur_enemy_index)->bank; + EnemyData *E = gEnemyData(cur_enemy_index); enemy_processing_stage = 8; - if (bomb_counter) { - if (gEnemyData(cur_enemy_index)->spritemap_pointer) { - EnemyData *v0 = gEnemyData(cur_enemy_index); - if (!v0->invincibility_timer && v0->enemy_ptr != addr_kEnemyDef_DAFF) { - collision_detection_index = 5; - while (1) { - int v1 = collision_detection_index; - if (projectile_type[v1] - && !projectile_variables[v1] - && ((projectile_type[v1] & 0xF00) == 1280 || (projectile_type[v1] & 0x8000u) != 0)) { - EnemyData *v2 = gEnemyData(cur_enemy_index); - uint16 v3 = abs16(projectile_x_pos[v1] - v2->x_pos); - bool v4 = v3 < projectile_x_radius[v1]; - uint16 v5 = v3 - projectile_x_radius[v1]; - if (v4 || v5 < v2->x_width) { - uint16 v6 = abs16(projectile_y_pos[v1] - v2->y_pos); - v4 = v6 < projectile_y_radius[v1]; - uint16 v7 = v6 - projectile_y_radius[v1]; - if (v4 || v7 < v2->y_height) { - v8 = collision_detection_index; - if (!projectile_variables[v8]) - break; - } - } - } - if (++collision_detection_index == 10) - return; - } - projectile_dir[v8] |= 0x10u; - uint16 enemy_ptr = gEnemyData(cur_enemy_index)->enemy_ptr; - enemy_ai_pointer.addr = get_EnemyDef_A2(enemy_ptr)->shot_ai; - CallEnemyAi(Load24(&enemy_ai_pointer)); - } + if (!bomb_counter || !E->spritemap_pointer || + E->invincibility_timer || E->enemy_ptr == addr_kEnemyDef_DAFF) + return; + for(int pidx = 5; pidx < 10; pidx++) { + if (!projectile_type[pidx] || projectile_variables[pidx] || + (projectile_type[pidx] & 0xF00) != 1280 && (projectile_type[pidx] & 0x8000) == 0) + continue; + if (abs16(projectile_x_pos[pidx] - E->x_pos) - projectile_x_radius[pidx] < E->x_width && + abs16(projectile_y_pos[pidx] - E->y_pos) - projectile_y_radius[pidx] < E->y_height) { + collision_detection_index = pidx; + projectile_dir[pidx] |= 0x10; + CallEnemyAi(E->bank << 16 | get_EnemyDef_A2(E->enemy_ptr)->shot_ai); + return; } } } void ProcessEnemyPowerBombInteraction(void) { // 0xA0A306 - VoidP powerbomb_reaction; - enemy_processing_stage = 5; - R18_ = HIBYTE(power_bomb_explosion_radius); - if (HIBYTE(power_bomb_explosion_radius)) { - R20_ = (uint16)(R18_ + (HIBYTE(power_bomb_explosion_radius) & 1) + (power_bomb_explosion_radius >> 9)) >> 1; - cur_enemy_index = 1984; - do { - EnemyData *v0 = gEnemyData(cur_enemy_index); - if (!v0->invincibility_timer) { - uint16 enemy_ptr = v0->enemy_ptr; - if (v0->enemy_ptr) { - if (enemy_ptr != addr_kEnemyDef_DAFF) { - uint16 vulnerability_ptr = get_EnemyDef_A2(enemy_ptr)->vulnerability_ptr; - if (!vulnerability_ptr) - vulnerability_ptr = addr_stru_B4EC1C; - if ((get_Vulnerability(vulnerability_ptr)->power_bomb & 0x7F) != 0) { - EnemyData *v3 = gEnemyData(cur_enemy_index); - if (abs16(power_bomb_explosion_x_pos - v3->x_pos) < R18_ - && abs16(power_bomb_explosion_y_pos - v3->y_pos) < R20_) { - powerbomb_reaction = get_EnemyDef_A2(v3->enemy_ptr)->powerbomb_reaction; - if (!powerbomb_reaction) - powerbomb_reaction = FUNC16(Enemy_NormalPowerBombAI_A0); - enemy_ai_pointer.addr = powerbomb_reaction; - *(uint16 *)&enemy_ai_pointer.bank = *(uint16 *)&gEnemyData(cur_enemy_index)->bank; - CallEnemyAi(Load24(&enemy_ai_pointer)); - EnemyData *v5 = gEnemyData(cur_enemy_index); - v5->properties |= 0x800u; - } - } - } - } - } - cur_enemy_index -= 64; - } while ((cur_enemy_index & 0x8000u) == 0); + uint16 rx = HIBYTE(power_bomb_explosion_radius); + uint16 ry = (rx + (rx >> 1)) >> 1; + for(int i = 0x7c0; rx && i >= 0; i -= 0x40) { + EnemyData *E = gEnemyData(i); + if (E->invincibility_timer || !E->enemy_ptr || E->enemy_ptr == addr_kEnemyDef_DAFF) + continue; + EnemyDef_A2 *ED = get_EnemyDef_A2(E->enemy_ptr); + if ((get_Vulnerability(ED->vulnerability_ptr ? ED->vulnerability_ptr : addr_stru_B4EC1C)->power_bomb & 0x7F) == 0) + continue; + if (abs16(power_bomb_explosion_x_pos - E->x_pos) < rx && abs16(power_bomb_explosion_y_pos - E->y_pos) < ry) { + cur_enemy_index = i; + uint16 func = ED->powerbomb_reaction ? ED->powerbomb_reaction : FUNC16(Enemy_NormalPowerBombAI_A0); + CallEnemyAi(E->bank << 16 | func); + E->properties |= 0x800; + } } } void EnemyDeathAnimation(uint16 k, uint16 a) { // 0xA0A3AF - int16 v3; - - if (gEnemyData(k)->ai_handler_bits == 1) + EnemyData *E = gEnemyData(cur_enemy_index); + if (E->ai_handler_bits == 1) grapple_beam_function = FUNC16(GrappleBeam_Func2); if (!sign16(a - 5)) a = 0; - enemy_population_ptr = a; +// varE20 = a; SpawnEnemyProjectileWithGfx(a, cur_enemy_index, addr_kEproj_EnemyDeathExplosion); - R18_ = gEnemyData(cur_enemy_index)->properties & 0x4000; - v3 = 62; - int v4 = cur_enemy_index; - do { - gEnemyData(v4)->enemy_ptr = 0; - v4 += 2; - v3 -= 2; - } while (v3 >= 0); - if (R18_) { - EnemyData *v5 = gEnemyData(cur_enemy_index); - v5->enemy_ptr = addr_kEnemyDef_DAFF; - *(uint16 *)&v5->bank = 0xa3; + uint16 r18 = E->properties & 0x4000; + memset(E, 0, 64); + if (r18) { + E->enemy_ptr = addr_kEnemyDef_DAFF; + E->bank = 0xa3; } - ++num_enemies_killed_in_room; + num_enemies_killed_in_room++; } void RinkasDeathAnimation(uint16 a) { // 0xA0A410 - int16 v2; - + EnemyData *E = gEnemyData(cur_enemy_index); if (!sign16(a - 3)) a = 0; - enemy_population_ptr = a; +// varE20 = a; SpawnEnemyProjectileWithGfx(a, cur_enemy_index, addr_kEproj_EnemyDeathExplosion); - R18_ = gEnemyData(cur_enemy_index)->properties & 0x4000; - v2 = 62; - int v4 = cur_enemy_index; - do { - gEnemyData(v4)->enemy_ptr = 0; - v4 += 2; - v2 -= 2; - } while (v2 >= 0); - if (R18_) { - EnemyData *v4 = gEnemyData(cur_enemy_index); - v4->enemy_ptr = addr_kEnemyDef_DAFF; - *(uint16 *)&v4->bank = 163; + uint16 r18 = E->properties & 0x4000; + memset(E, 0, 64); + if (r18) { + E->enemy_ptr = addr_kEnemyDef_DAFF; + E->bank = 0xa3; } } uint16 SuitDamageDivision(uint16 a) { // 0xA0A45E - R18_ = a; - if ((equipped_items & 0x20) != 0) { - R18_ >>= 1; - R18_ >>= 1; - return R18_; - } else { - if (equipped_items & 1) - R18_ >>= 1; - return R18_; - } + if ((equipped_items & 0x20) != 0) + return a >> 2; + if (equipped_items & 1) + return a >> 1; + return a; } void NormalEnemyTouchAi(void) { // 0xA0A477 - NormalEnemyTouchAiSkipDeathAnim(); if (!gEnemyData(cur_enemy_index)->health) { gEnemySpawnData(cur_enemy_index)->cause_of_death = 6; - EnemyDeathAnimation(cur_enemy_index, 1u); + EnemyDeathAnimation(cur_enemy_index, 1); } } @@ -2976,70 +2567,44 @@ void NormalEnemyTouchAiSkipDeathAnim_CurEnemy(void) { // 0xA0A497 } void NormalEnemyTouchAiSkipDeathAnim(void) { // 0xA0A4A1 - VoidP vulnerability_ptr; - int16 hurt_ai_time; - int16 v7; - EnemyDef_A2 *v9; - EnemyDef_A2 *EnemyDef_A2; - - if (samus_contact_damage_index) { - R20_ = samus_contact_damage_index + 15; - uint16 v0 = 500; - if (samus_contact_damage_index != 1) { - v0 = 300; - if (samus_contact_damage_index != 2) { - v0 = 2000; - if (samus_contact_damage_index != 3) { - ++R20_; - v0 = 200; - if (samus_contact_damage_index == 4) - CallSomeSamusCode(4u); - else - v0 = 200; - } - } - } - R22_ = v0; - EnemyData *v1 = gEnemyData(cur_enemy_index); - vulnerability_ptr = get_EnemyDef_A2(v1->enemy_ptr)->vulnerability_ptr; - if (!vulnerability_ptr) - vulnerability_ptr = addr_stru_B4EC1C; - enemy_damage_multiplier = *(uint16 *)&get_Vulnerability(R20_ + vulnerability_ptr)->power; - draw_enemy_layer = enemy_damage_multiplier & 0x7F; - if ((enemy_damage_multiplier & 0x7F) != 0) { - R40 = draw_enemy_layer; - R38 = R22_ >> 1; - Mult32bit(); - if (R42) { - R18_ = R42; - EnemyData *v3 = gEnemyData(cur_enemy_index); - EnemyDef_A2 = get_EnemyDef_A2(v3->enemy_ptr); - hurt_ai_time = EnemyDef_A2->hurt_ai_time; - if (!EnemyDef_A2->hurt_ai_time) - hurt_ai_time = 4; - EnemyData *v6 = gEnemyData(cur_enemy_index); - v6->flash_timer = hurt_ai_time; - v6->ai_handler_bits |= 2u; - samus_invincibility_timer = 0; - samus_knockback_timer = 0; - v7 = v6->health - R18_; - if (v7 < 0) - v7 = 0; - v6->health = v7; - QueueSfx2_Max1(0xBu); - } - } - } else { - EnemyData *v8 = gEnemyData(cur_enemy_index); - v9 = get_EnemyDef_A2(v8->enemy_ptr); - uint16 v10 = SuitDamageDivision(v9->damage); - Samus_DealDamage(v10); + EnemyData *E = gEnemyData(cur_enemy_index); + EnemyDef_A2 *ED = get_EnemyDef_A2(E->enemy_ptr); + if (samus_contact_damage_index == 0) { + Samus_DealDamage(SuitDamageDivision(ED->damage)); samus_invincibility_timer = 96; samus_knockback_timer = 5; - knockback_x_dir = (int16)(samus_x_pos - gEnemyData(cur_enemy_index)->x_pos) >= 0; + knockback_x_dir = (int16)(samus_x_pos - E->x_pos) >= 0; + return; + } + uint16 r20 = samus_contact_damage_index + 15; + uint16 r22; + if (samus_contact_damage_index == 1) { + r22 = 500; + } else if (samus_contact_damage_index == 2) { + r22 = 300; + } else if (samus_contact_damage_index == 3) { + r22 = 2000; + } else { + ++r20; + if (samus_contact_damage_index == 4) + CallSomeSamusCode(4); + r22 = 200; + } + uint16 vp = ED->vulnerability_ptr ? ED->vulnerability_ptr : addr_stru_B4EC1C; + last_enemy_power = *(uint16 *)&get_Vulnerability(r20 + vp)->power; + uint16 varE32 = last_enemy_power & 0x7F; + if ((last_enemy_power & 0x7F) != 0) { + uint16 dmg = (r22 >> 1) * varE32; + if (dmg) { + E->flash_timer = ED->hurt_ai_time ? ED->hurt_ai_time : 4; + E->ai_handler_bits |= kEnemyAiBits_Hurt; + samus_invincibility_timer = 0; + samus_knockback_timer = 0; + E->health = (int16)(E->health - dmg) < 0 ? 0 : (int16)(E->health - dmg); + QueueSfx2_Max1(0xB); + } } } -// 72078: conditional instruction was optimized away because ax.2<80u void NormalEnemyPowerBombAi(void) { // 0xA0A597 NormalEnemyPowerBombAiSkipDeathAnim(); @@ -3063,25 +2628,22 @@ void NormalEnemyPowerBombAiSkipDeathAnim(void) { // 0xA0A5C1 vulnerability_ptr = -5092; uint8 power_bomb = get_Vulnerability(vulnerability_ptr)->power_bomb; if (power_bomb != 255) { - draw_enemy_layer = power_bomb & 0x7F; + uint16 varE32 = power_bomb & 0x7F; if ((power_bomb & 0x7F) != 0) { - R38 = 100; - R40 = draw_enemy_layer; - Mult32bit(); - enemy_spritemap_entry_coll_x_pos = R42; - if (R42) { + uint32 ttt = 100 * varE32; + if (ttt) { gEnemyData(cur_enemy_index)->invincibility_timer = 48; - EnemyData *v3 = gEnemyData(cur_enemy_index); - EnemyDef_A2 = get_EnemyDef_A2(v3->enemy_ptr); + EnemyData *j = gEnemyData(cur_enemy_index); + EnemyDef_A2 = get_EnemyDef_A2(j->enemy_ptr); hurt_ai_time = EnemyDef_A2->hurt_ai_time; if (!EnemyDef_A2->hurt_ai_time) hurt_ai_time = 4; EnemyData *v6 = gEnemyData(cur_enemy_index); v6->flash_timer = hurt_ai_time + 8; - v6->ai_handler_bits |= 2u; + v6->ai_handler_bits |= 2; uint16 health = v6->health; - bool v9 = health < enemy_spritemap_entry_coll_x_pos; - uint16 v8 = health - enemy_spritemap_entry_coll_x_pos; + bool v9 = health < ttt; + uint16 v8 = health - ttt; v9 = !v9; if (!v8 || !v9) v8 = 0; @@ -3092,90 +2654,73 @@ void NormalEnemyPowerBombAiSkipDeathAnim(void) { // 0xA0A5C1 } void NormalEnemyShotAi(void) { // 0xA0A63D - EnemyDef_A2 *EnemyDef_A2; - - varE2E = 0; - NormalEnemyShotAiSkipDeathAnim(); + uint16 varE2E = NormalEnemyShotAiSkipDeathAnim(); + EnemyData *E = gEnemyData(cur_enemy_index); if (varE2E) { - EnemyData *v1 = gEnemyData(cur_enemy_index); - R18_ = v1->x_pos; - R20_ = v1->y_pos; - R22_ = 55; - R24_ = 0; - CreateSpriteAtPos(); + CreateSpriteAtPos(E->x_pos, E->y_pos, 55, 0); } - EnemyData *v2 = gEnemyData(cur_enemy_index); - if (!v2->health) { - uint16 v3 = HIBYTE(projectile_type[collision_detection_index]) & 0xF; - gEnemySpawnData(cur_enemy_index)->cause_of_death = v3; + if (!E->health) { + uint16 j = HIBYTE(projectile_type[collision_detection_index]) & 0xF; + gEnemySpawnData(cur_enemy_index)->cause_of_death = j; uint16 death_anim = 2; - uint16 enemy_ptr; - if (v3 == 2) { - enemy_ptr = gEnemyData(cur_enemy_index)->enemy_ptr; - EnemyDef_A2 = get_EnemyDef_A2(enemy_ptr); - if (!sign16(EnemyDef_A2->death_anim - 3)) - death_anim = EnemyDef_A2->death_anim; + if (j == 2) { + EnemyDef_A2 *ED = get_EnemyDef_A2(E->enemy_ptr); + if (!sign16(ED->death_anim - 3)) + death_anim = ED->death_anim; } else { - enemy_ptr = v2->enemy_ptr; - death_anim = get_EnemyDef_A2(v2->enemy_ptr)->death_anim; + death_anim = get_EnemyDef_A2(E->enemy_ptr)->death_anim; } - EnemyDeathAnimation(enemy_ptr, death_anim); + EnemyDeathAnimation(E->enemy_ptr, death_anim); } } void NormalEnemyShotAiSkipDeathAnim_CurEnemy(void) { // 0xA0A6A7 - varE2E = 0; NormalEnemyShotAiSkipDeathAnim(); } void EnemyFunc_A6B4_UsedBySporeSpawn(void) { // 0xA0A6B4 - varE2E = 0; - NormalEnemyShotAiSkipDeathAnim(); + uint16 varE2E = NormalEnemyShotAiSkipDeathAnim(); if (varE2E) { - EnemyData *v0 = gEnemyData(cur_enemy_index); - R18_ = v0->x_pos; - R20_ = v0->y_pos; - R22_ = 55; - R24_ = 0; - CreateSpriteAtPos(); + EnemyData *ED = gEnemyData(cur_enemy_index); + CreateSpriteAtPos(ED->x_pos, ED->y_pos, 55, 0); } } -void NormalEnemyShotAiSkipDeathAnim(void) { // 0xA0A6DE +uint16 NormalEnemyShotAiSkipDeathAnim(void) { // 0xA0A6DE + uint16 varE2E = 0; int16 v5; int16 v6; int16 v9; EnemyDef_A2 *EnemyDef_A2; int16 hurt_ai_time; int16 v20; + uint16 varE32; int v0 = collision_detection_index; - enemy_spritemap_entry_coll_x_pos = projectile_damage[v0]; - R18_ = projectile_type[v0]; - EnemyData *v1 = gEnemyData(cur_enemy_index); - uint16 vulnerability_ptr = get_EnemyDef_A2(v1->enemy_ptr)->vulnerability_ptr; + uint16 pd = projectile_damage[v0]; + uint16 r18 = projectile_type[v0]; + EnemyData *j = gEnemyData(cur_enemy_index); + uint16 vulnerability_ptr = get_EnemyDef_A2(j->enemy_ptr)->vulnerability_ptr; if (!vulnerability_ptr) vulnerability_ptr = addr_stru_B4EC1C; - R20_ = vulnerability_ptr; - if ((R18_ & 0xF00) != 0) { - v5 = R18_ & 0xF00; - if ((R18_ & 0xF00) == 256 || v5 == 512) { - LOBYTE(v6) = (uint16)(R18_ & 0xF00) >> 8; - HIBYTE(v6) = 0; - draw_enemy_layer = get_Vulnerability(R20_ + v6)->plasma_ice_wave & 0x7F; + uint16 r20 = vulnerability_ptr; + if ((r18 & 0xF00) != 0) { + v5 = r18 & 0xF00; + if ((r18 & 0xF00) == 256 || v5 == 512) { + v6 = (r18 & 0xF00) >> 8; + varE32 = get_Vulnerability(r20 + v6)->plasma_ice_wave & 0x7F; } else if (v5 == 1280) { - draw_enemy_layer = get_Vulnerability(R20_)->bomb & 0x7F; + varE32 = get_Vulnerability(r20)->bomb & 0x7F; } else { if (v5 != 768) goto LABEL_18; - draw_enemy_layer = get_Vulnerability(R20_)->power_bomb & 0x7F; + varE32 = get_Vulnerability(r20)->power_bomb & 0x7F; } -LABEL_9: - R38 = enemy_spritemap_entry_coll_x_pos >> 1; - R40 = draw_enemy_layer; - Mult32bit(); - if (R42) { - enemy_spritemap_entry_coll_x_pos = R42; +LABEL_9:; + uint32 ttt = (uint32)(pd >> 1) * (uint32)varE32; + uint16 r42 = ttt; + if (r42) { + pd = r42; EnemyData *v10 = gEnemyData(cur_enemy_index); EnemyDef_A2 = get_EnemyDef_A2(v10->enemy_ptr); hurt_ai_time = EnemyDef_A2->hurt_ai_time; @@ -3183,7 +2728,7 @@ LABEL_9: hurt_ai_time = 4; EnemyData *v13 = gEnemyData(cur_enemy_index); v13->flash_timer = hurt_ai_time + 8; - v13->ai_handler_bits |= 2u; + v13->ai_handler_bits |= 2; if (!v13->frozen_timer) { uint16 hurt_sfx = get_EnemyDef_A2(v13->enemy_ptr)->hurt_sfx; if (hurt_sfx) @@ -3195,134 +2740,134 @@ LABEL_9: gEnemyData(cur_enemy_index)->invincibility_timer = 16; EnemyData *v16 = gEnemyData(v15); uint16 health = v16->health; - bool v19 = health < enemy_spritemap_entry_coll_x_pos; - uint16 v18 = health - enemy_spritemap_entry_coll_x_pos; + bool v19 = health < pd; + uint16 v18 = health - pd; v19 = !v19; if (!v18 || !v19) { if ((projectile_type[collision_detection_index] & 2) != 0 - && (enemy_damage_multiplier & 0xF0) != 128 + && (last_enemy_power & 0xF0) != 128 && !v16->frozen_timer) { v20 = 400; if (area_index == 2) v20 = 300; v16->frozen_timer = v20; - v16->ai_handler_bits |= 4u; + v16->ai_handler_bits |= 4; v16->invincibility_timer = 10; - QueueSfx3_Max3(0xAu); - return; + QueueSfx3_Max3(0xA); + return varE2E; } v18 = 0; } v16->health = v18; - return; + return varE2E; } LABEL_18:; int v7 = collision_detection_index; - projectile_dir[v7] |= 0x10u; - R18_ = projectile_x_pos[v7]; - R20_ = projectile_y_pos[v7]; - R22_ = 6; - R24_ = 0; - CreateSpriteAtPos(); - QueueSfx1_Max3(0x3Du); - return; + projectile_dir[v7] |= 0x10; + CreateSpriteAtPos(projectile_x_pos[v7], projectile_y_pos[v7], 6, 0); + QueueSfx1_Max3(0x3D); + return varE2E; } - enemy_damage_multiplier = get_Vulnerability(R20_ + ((uint8)R18_ & 0xFu))->power; - draw_enemy_layer = enemy_damage_multiplier & 0x7F; - if (enemy_damage_multiplier != 255) { - if ((R18_ & 0x10) != 0) { - uint8 charged_beam = get_Vulnerability(R20_)->charged_beam; + last_enemy_power = get_Vulnerability(r20 + (r18 & 0xF))->power; + varE32 = last_enemy_power & 0x7F; + if (last_enemy_power != 255) { + if ((r18 & 0x10) != 0) { + uint8 charged_beam = get_Vulnerability(r20)->charged_beam; if (charged_beam == 255) goto LABEL_18; uint16 v4 = charged_beam & 0xF; if (!v4) goto LABEL_18; - draw_enemy_layer = v4; + varE32 = v4; } goto LABEL_9; } EnemyData *v8 = gEnemyData(cur_enemy_index); if (!v8->frozen_timer) - QueueSfx3_Max3(0xAu); + QueueSfx3_Max3(0xA); v9 = 400; if (area_index == 2) v9 = 300; v8->frozen_timer = v9; - v8->ai_handler_bits |= 4u; + v8->ai_handler_bits |= 4; v8->invincibility_timer = 10; + return varE2E; } void CreateDudShot(void) { // 0xA0A8BC int v0 = collision_detection_index; - R18_ = projectile_x_pos[v0]; - R20_ = projectile_y_pos[v0]; - R22_ = 6; - R24_ = 0; - CreateSpriteAtPos(); - QueueSfx1_Max3(0x3Du); - projectile_dir[collision_detection_index] |= 0x10u; + CreateSpriteAtPos(projectile_x_pos[v0], projectile_y_pos[v0], 6, 0); + QueueSfx1_Max3(0x3D); + projectile_dir[collision_detection_index] |= 0x10; } -uint16 Samus_CheckSolidEnemyColl(void) { // 0xA0A8F0 - int16 v1; - int16 v16; +typedef struct PositionAndWidth { + uint16 x_pos; + uint16 x_subpos; + uint16 y_pos; + uint16 y_subpos; + uint16 width; + uint16 height; +} PositionAndWidth; + +CheckEnemyColl_Result Samus_CheckSolidEnemyColl(int32 amt) { // 0xA0A8F0 int16 v18; + uint16 r18 = amt >> 16, r20 = amt; + uint16 varE32; + PositionAndWidth pos; if (!interactive_enemy_indexes_write_ptr) - return 0; - v1 = 2 * (samus_collision_direction & 3); - switch (v1) { + return (CheckEnemyColl_Result) {0, amt}; + switch (samus_collision_direction & 3) { case 0: { - samus_target_x_pos = samus_x_pos - R18_; - bool v2 = samus_x_subpos == R20_; - if (samus_x_subpos < R20_) - v2 = samus_target_x_pos-- == 1; - if (!v2) - --samus_target_x_pos; - samus_target_y_pos = samus_y_pos; - samus_target_y_subpos = samus_y_subpos; + pos.x_pos = samus_x_pos - r18; + bool i = samus_x_subpos == r20; + if (samus_x_subpos < r20) + i = pos.x_pos-- == 1; + if (!i) + --pos.x_pos; + pos.y_pos = samus_y_pos; + pos.y_subpos = samus_y_subpos; + break; + } + case 1: { + pos.x_pos = samus_x_pos + r18; + bool j = samus_x_subpos + r20 == 0; + if (__CFADD__uint16(samus_x_subpos, r20)) + j = pos.x_pos++ == 0xFFFF; + if (!j) + ++pos.x_pos; + pos.y_pos = samus_y_pos; + pos.y_subpos = samus_y_subpos; break; } case 2: { - samus_target_x_pos = samus_x_pos + R18_; - bool v3 = samus_x_subpos + R20_ == 0; - if (__CFADD__uint16(samus_x_subpos, R20_)) - v3 = samus_target_x_pos++ == 0xFFFF; - if (!v3) - ++samus_target_x_pos; - samus_target_y_pos = samus_y_pos; - samus_target_y_subpos = samus_y_subpos; - break; - } - case 4: { - samus_target_y_pos = samus_y_pos - R18_; - bool v4 = samus_y_subpos == R20_; - if (samus_y_subpos < R20_) - v4 = samus_target_y_pos-- == 1; + pos.y_pos = samus_y_pos - r18; + bool v4 = samus_y_subpos == r20; + if (samus_y_subpos < r20) + v4 = pos.y_pos-- == 1; if (!v4) - --samus_target_y_pos; - samus_target_x_pos = samus_x_pos; - samus_target_x_subpos = samus_x_subpos; + --pos.y_pos; + pos.x_pos = samus_x_pos; + pos.x_subpos = samus_x_subpos; break; } - case 6: { - samus_target_y_pos = samus_y_pos + R18_; - bool v5 = samus_y_subpos + R20_ == 0; - if (__CFADD__uint16(samus_y_subpos, R20_)) - v5 = samus_target_y_pos++ == 0xFFFF; + case 3: { + pos.y_pos = samus_y_pos + r18; + bool v5 = samus_y_subpos + r20 == 0; + if (__CFADD__uint16(samus_y_subpos, r20)) + v5 = pos.y_pos++ == 0xFFFF; if (!v5) - ++samus_target_y_pos; - samus_target_x_pos = samus_x_pos; - samus_target_x_subpos = samus_x_subpos; + ++pos.y_pos; + pos.x_pos = samus_x_pos; + pos.x_subpos = samus_x_subpos; break; } default: Unreachable(); - while (1) - ; } - samus_x_radius_mirror = samus_x_radius; - samus_y_radius_mirror = samus_y_radius; + pos.width = samus_x_radius; + pos.height = samus_y_radius; collision_detection_index = 0; for (int i = 0; ;i++) { uint16 v7 = interactive_enemy_indexes[i]; @@ -3330,10 +2875,10 @@ uint16 Samus_CheckSolidEnemyColl(void) { // 0xA0A8F0 break; collision_detection_index = v7; EnemyData *ED = gEnemyData(v7); - if (!ED->frozen_timer && (ED->properties & 0x8000u) == 0) + if (!ED->frozen_timer && (ED->properties & 0x8000) == 0) continue; uint16 *v9 = &ED->x_pos; - uint16 *v10 = &samus_target_x_pos; + uint16 *v10 = &pos.x_pos; uint16 v11 = abs16(*v9 - *v10); bool v12 = v11 < *(v9 + 4); uint16 v13 = v11 - *(v9 + 4); @@ -3342,19 +2887,18 @@ uint16 Samus_CheckSolidEnemyColl(void) { // 0xA0A8F0 v12 = v14 < *(v9 + 5); uint16 v15 = v14 - *(v9 + 5); if (v12 || v15 < *(v10 + 5)) { - v16 = 2 * (samus_collision_direction & 3); - switch (v16) { + switch (samus_collision_direction & 3) { case 0: { - draw_enemy_layer = ED->x_width + ED->x_pos; - v18 = samus_x_pos - samus_x_radius - draw_enemy_layer; - if (samus_x_pos - samus_x_radius == draw_enemy_layer) + varE32 = ED->x_width + ED->x_pos; + v18 = samus_x_pos - samus_x_radius - varE32; + if (samus_x_pos - samus_x_radius == varE32) goto LABEL_57; - if ((int16)(samus_x_pos - samus_x_radius - draw_enemy_layer) >= 0) + if ((int16)(samus_x_pos - samus_x_radius - varE32) >= 0) goto LABEL_58; break; } - case 2: { - draw_enemy_layer = samus_x_radius + samus_x_pos; + case 1: { + varE32 = samus_x_radius + samus_x_pos; v18 = ED->x_pos - ED->x_width - (samus_x_radius + samus_x_pos); if (!v18) goto LABEL_57; @@ -3362,187 +2906,132 @@ uint16 Samus_CheckSolidEnemyColl(void) { // 0xA0A8F0 goto LABEL_58; break; } - case 4: { - draw_enemy_layer = ED->y_height + ED->y_pos; - v18 = samus_y_pos - samus_y_radius - draw_enemy_layer; - if (samus_y_pos - samus_y_radius == draw_enemy_layer) + case 2: { + varE32 = ED->y_height + ED->y_pos; + v18 = samus_y_pos - samus_y_radius - varE32; + if (samus_y_pos - samus_y_radius == varE32) goto LABEL_57; - if ((int16)(samus_y_pos - samus_y_radius - draw_enemy_layer) >= 0) + if ((int16)(samus_y_pos - samus_y_radius - varE32) >= 0) goto LABEL_58; break; } - case 6: { - draw_enemy_layer = samus_y_radius + samus_y_pos; + case 3: { + varE32 = samus_y_radius + samus_y_pos; v18 = ED->y_pos - ED->y_height - (samus_y_radius + samus_y_pos); if (!v18) { LABEL_57: samus_y_subpos = 0; - samus_x_pos_colliding_solid = samus_x_pos; - samus_x_subpos_colliding_solid = samus_x_subpos; - enemy_x_pos_colliding_solid = ED->x_pos; - enemy_x_subpos_colliding_solid = ED->x_subpos; - samus_pos_delta_colliding_solid = R18_; - samus_subpos_delta_colliding_solid = R20_; - samus_y_pos_colliding_solid = samus_y_pos; - samus_y_subpos_colliding_solid = 0; - solid_enemy_collision_type = 1; - R18_ = 0; - R20_ = 0; - R22_ = collision_detection_index; int v23 = samus_collision_direction & 3; enemy_index_colliding_dirs[v23] = collision_detection_index; - distance_to_enemy_colliding_dirs[v23] = 0; - return -1; + return (CheckEnemyColl_Result) { -1, 0 }; } if (v18 >= 0) { LABEL_58: - samus_x_pos_colliding_solid = samus_x_pos; - samus_x_subpos_colliding_solid = samus_x_subpos; - enemy_x_pos_colliding_solid = ED->x_pos; - enemy_x_subpos_colliding_solid = ED->x_subpos; - samus_pos_delta_colliding_solid = R18_; - samus_subpos_delta_colliding_solid = R20_; - samus_y_pos_colliding_solid = samus_y_pos; - samus_y_subpos_colliding_solid = samus_y_subpos; - solid_enemy_collision_type = 2; - R18_ = v18; int v25 = samus_collision_direction & 3; - distance_to_enemy_colliding_dirs[v25] = v18; - R20_ = 0; - R22_ = collision_detection_index; enemy_index_colliding_dirs[v25] = collision_detection_index; - return -1; + return (CheckEnemyColl_Result) { -1, INT16_SHL16(v18) }; } break; } default: Unreachable(); - while (1) - ; } } } } - return 0; + return (CheckEnemyColl_Result) { 0, amt }; } uint16 CheckIfEnemyTouchesSamus(uint16 k) { // 0xA0ABE7 - EnemyData *v1 = gEnemyData(k); - uint16 v2 = abs16(samus_x_pos - v1->x_pos); - bool v3 = v2 < samus_x_radius; - uint16 v4 = v2 - samus_x_radius; - if (!v3 && v4 >= v1->x_width) + EnemyData *E = gEnemyData(k); + uint16 i = abs16(samus_x_pos - E->x_pos); + bool v3 = i < samus_x_radius; + uint16 v4 = i - samus_x_radius; + if (!v3 && v4 >= E->x_width) return 0; - if ((int16)(samus_y_pos + 3 - v1->y_pos) < 0) { - uint16 v6 = v1->y_pos - (samus_y_pos + 3); - v3 = v6 < samus_y_radius; + if ((int16)(samus_y_pos + 3 - E->y_pos) < 0) { + uint16 v6 = E->y_pos - (samus_y_pos + 3); uint16 v7 = v6 - samus_y_radius; - if (v3 || v7 == v1->y_height || v7 < v1->y_height) + if (v6 < samus_y_radius || v7 == E->y_height || v7 < E->y_height) return -1; } return 0; } uint16 EnemyFunc_AC67(uint16 k) { // 0xA0AC67 - EnemyData *v1 = gEnemyData(k); - uint16 v2 = abs16(samus_x_pos - v1->x_pos); - bool v3 = v2 < samus_x_radius; - uint16 v4 = v2 - samus_x_radius; - if (!v3 && v4 >= v1->x_width && v4 >= 8u) + EnemyData *E = gEnemyData(k); + uint16 i = abs16(samus_x_pos - E->x_pos); + bool v3 = i < samus_x_radius; + uint16 v4 = i - samus_x_radius; + if (!v3 && v4 >= E->x_width && v4 >= 8) return 0; - uint16 v6 = abs16(samus_y_pos - v1->y_pos); + uint16 v6 = abs16(samus_y_pos - E->y_pos); v3 = v6 < samus_y_radius; uint16 v7 = v6 - samus_y_radius; - if (v3 || v7 < v1->y_height) + if (v3 || v7 < E->y_height) return -1; else return 0; } -uint16 EnemyFunc_ACA8(void) { // 0xA0ACA8 - int16 v1; - int16 v2; - - g_word_7E0E3C = loop_index_end - draw_enemy_layer; - uint16 result = abs16(loop_index_end - draw_enemy_layer); +PairU16 EnemyFunc_ACA8(Point16U base_pt, Point16U samus_pt) { // 0xA0ACA8 + uint16 varE3C = samus_pt.x - base_pt.x; + uint16 result = abs16(varE3C); if (sign16(result - 255)) { - R18_ = result; - enemy_population_ptr = result; - g_word_7E0E3E = loop_index - enemy_drawing_queue_index; - result = abs16(loop_index - enemy_drawing_queue_index); + uint16 x = result; + uint16 varE20 = result; + uint16 varE3E = samus_pt.y - base_pt.y; + result = abs16(varE3E); if (sign16(result - 255)) { - R20_ = result; - draw_oam_x_offset = result; - varE24 = CalculateAngleFromXY(); - draw_enemy_layer = enemy_population_ptr; - v1 = SineMult8bitNegative(varE24); - if (v1 < 0) - v1 = -v1; - varE26 = v1; - draw_enemy_layer = draw_oam_x_offset; - v2 = CosineMult8bit(varE24); - if (v2 < 0) - v2 = -v2; - uint16 v3 = varE26 + v2; - R18_ = g_word_7E0E3C; - R20_ = g_word_7E0E3E; - enemy_drawing_queue_base = CalculateAngleFromXY(); - return v3; + uint16 y = result; + uint16 varE22 = result; + uint16 varE24 = CalculateAngleFromXY(x, y); + uint16 dist = abs16(SineMult8bit(varE24, varE20)) + abs16(CosineMult8bit(varE24, varE22)); + uint16 varE3A = CalculateAngleFromXY(varE3C, varE3E); + return (PairU16) {dist, varE3A }; } } - return result; + return (PairU16) { result, 0 }; } uint16 CheckIfEnemyIsOnScreen(void) { // 0xA0AD70 EnemyData *v0 = gEnemyData(cur_enemy_index); - return (int16)(v0->x_pos - layer1_x_pos) < 0 - || (int16)(layer1_x_pos + 256 - v0->x_pos) < 0 - || (int16)(v0->y_pos - layer1_y_pos) < 0 - || (int16)(layer1_y_pos + 256 - v0->y_pos) < 0; + return (int16)(v0->x_pos - layer1_x_pos) < 0 || (int16)(layer1_x_pos + 256 - v0->x_pos) < 0 || + (int16)(v0->y_pos - layer1_y_pos) < 0 || (int16)(layer1_y_pos + 256 - v0->y_pos) < 0; } uint16 EnemyFunc_ADA3(uint16 a) { // 0xA0ADA3 - R18_ = a; - EnemyData *v1 = gEnemyData(cur_enemy_index); - return (int16)(a + v1->x_pos - layer1_x_pos) < 0 - || (int16)(R18_ + layer1_x_pos + 256 - v1->x_pos) < 0 - || (int16)(R18_ + v1->y_pos - layer1_y_pos) < 0 - || (int16)(R18_ + layer1_y_pos + 256 - v1->y_pos) < 0; + EnemyData *E = gEnemyData(cur_enemy_index); + return (int16)(a + E->x_pos - layer1_x_pos) < 0 || (int16)(a + layer1_x_pos + 256 - E->x_pos) < 0 || + (int16)(a + E->y_pos - layer1_y_pos) < 0 || (int16)(a + layer1_y_pos + 256 - E->y_pos) < 0; } uint16 EnemyWithNormalSpritesIsOffScreen(void) { // 0xA0ADE7 - EnemyData *v0 = gEnemyData(cur_enemy_index); - return (int16)(v0->x_width + v0->x_pos - layer1_x_pos) < 0 - || (int16)(v0->x_width + layer1_x_pos + 256 - v0->x_pos) < 0 - || (int16)(v0->y_pos + 8 - layer1_y_pos) < 0 - || (int16)(layer1_y_pos + 248 - v0->y_pos) < 0; + EnemyData *E = gEnemyData(cur_enemy_index); + return (int16)(E->x_width + E->x_pos - layer1_x_pos) < 0 || (int16)(E->x_width + layer1_x_pos + 256 - E->x_pos) < 0 || + (int16)(E->y_pos + 8 - layer1_y_pos) < 0 || (int16)(layer1_y_pos + 248 - E->y_pos) < 0; } uint16 DetermineDirectionOfSamusFromEnemy(void) { // 0xA0AE29 if (IsSamusWithinEnemy_Y(cur_enemy_index, 0x20)) { - uint16 v1 = 2; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) return 7; - return v1; + return 2; } else if (IsSamusWithinEnemy_X(cur_enemy_index, 0x20)) { - uint16 v3 = 4; - if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000u) != 0) + if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000) != 0) return 0; - return v3; - } else if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) { - uint16 v5 = 6; - if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000u) != 0) + return 4; + } else if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) { + if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000) != 0) return 8; - return v5; + return 6; } else { - uint16 v4 = 3; - if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000u) != 0) + if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000) != 0) return 1; - return v4; + return 3; } } - uint16 GetSamusEnemyDelta_Y(uint16 k) { // 0xA0AEDD return samus_y_pos - gEnemyData(k)->y_pos; } @@ -3552,55 +3041,44 @@ uint16 GetSamusEnemyDelta_X(uint16 k) { // 0xA0AEE5 } uint16 IsSamusWithinEnemy_Y(uint16 k, uint16 a) { // 0xA0AEED - enemy_population_ptr = a; - EnemyData *v2 = gEnemyData(k); - return (int16)(SubtractThenAbs16(v2->y_pos, samus_y_pos) - a) < 0; + return (int16)(SubtractThenAbs16(gEnemyData(k)->y_pos, samus_y_pos) - a) < 0; } uint16 IsSamusWithinEnemy_X(uint16 k, uint16 a) { // 0xA0AF0B - enemy_population_ptr = a; - EnemyData *v2 = gEnemyData(k); - return (int16)(SubtractThenAbs16(v2->x_pos, samus_x_pos) - a) < 0; + return (int16)(SubtractThenAbs16(gEnemyData(k)->x_pos, samus_x_pos) - a) < 0; } -void Enemy_SubPos_X(uint16 k) { // 0xA0AF5A - EnemyData *v1 = gEnemyData(k); - uint16 x_subpos = v1->x_subpos; - bool v3 = x_subpos < R18_; - v1->x_subpos = x_subpos - R18_; - v1->x_pos -= v3 + R20_; +void Enemy_SubPos_X(uint16 k, uint32 amount32) { // 0xA0AF5A + EnemyData *E = gEnemyData(k); + uint32 t = __PAIR32__(E->x_pos, E->x_subpos) - amount32; + E->x_subpos = t; + E->x_pos = t >> 16; } -void Enemy_AddPos_X(uint16 k) { // 0xA0AF6C - EnemyData *v1 = gEnemyData(k); - uint16 x_subpos = v1->x_subpos; - bool v3 = __CFADD__uint16(R18_, x_subpos); - v1->x_subpos = R18_ + x_subpos; - v1->x_pos += R20_ + v3; +void Enemy_AddPos_X(uint16 k, uint32 amount32) { // 0xA0AF6C + EnemyData *E = gEnemyData(k); + uint32 t = __PAIR32__(E->x_pos, E->x_subpos) + amount32; + E->x_subpos = t; + E->x_pos = t >> 16; } -void Enemy_SubPos_Y(uint16 k) { // 0xA0AF7E - EnemyData *v1 = gEnemyData(k); - uint16 y_subpos = v1->y_subpos; - bool v3 = y_subpos < R18_; - v1->y_subpos = y_subpos - R18_; - v1->y_pos -= v3 + R20_; +void Enemy_SubPos_Y(uint16 k, uint32 amount32) { // 0xA0AF7E + EnemyData *E = gEnemyData(k); + uint32 t = __PAIR32__(E->y_pos, E->y_subpos) - amount32; + E->y_subpos = t; + E->y_pos = t >> 16; } -void Enemy_AddPos_Y(uint16 k) { // 0xA0AF90 - EnemyData *v1 = gEnemyData(k); - uint16 y_subpos = v1->y_subpos; - bool v3 = __CFADD__uint16(R18_, y_subpos); - v1->y_subpos = R18_ + y_subpos; - v1->y_pos += R20_ + v3; +void Enemy_AddPos_Y(uint16 k, uint32 amount32) { // 0xA0AF90 + EnemyData *E = gEnemyData(k); + uint32 t = __PAIR32__(E->y_pos, E->y_subpos) + amount32; + E->y_subpos = t; + E->y_pos = t >> 16; } uint16 SignExtend8(uint16 a) { // 0xA0AFEA - draw_enemy_layer = a; - if ((a & 0x80) != 0) - return (uint8)draw_enemy_layer | 0xFF00; - else - return draw_enemy_layer; + // not quite sign extend + return (a & 0x80) ? a | 0xff00 : a; } uint16 Mult32(uint16 a) { // 0xA0B002 @@ -3608,547 +3086,464 @@ uint16 Mult32(uint16 a) { // 0xA0B002 } uint16 Abs16(uint16 a) { // 0xA0B067 - draw_enemy_layer = a; - if ((a & 0x8000) != 0) - draw_enemy_layer = -draw_enemy_layer; - return draw_enemy_layer; + return ((a & 0x8000) != 0) ? -a : a; } uint16 SubtractThenAbs16(uint16 k, uint16 j) { // 0xA0B07D - draw_enemy_layer = k; - enemy_drawing_queue_index = j - k; - if ((int16)(j - k) < 0) - enemy_drawing_queue_index = -enemy_drawing_queue_index; - return enemy_drawing_queue_index; + return Abs16(j - k); } -uint16 CosineMult8bit(uint16 a) { // 0xA0B0B2 - enemy_drawing_queue_index = (uint8)(a + 64); - return SineMult8bit(); -} - -uint16 SineMult8bitNegative(uint16 a) { // 0xA0B0C6 - enemy_drawing_queue_index = (uint8)(a + 0x80); - return SineMult8bit(); -} - -uint16 SineMult8bit(void) { // 0xA0B0DA - uint16 RegWord = Mult8x8(kSine8bit[enemy_drawing_queue_index & 0x7F], draw_enemy_layer); - loop_index_end = RegWord >> 8; - loop_index = RegWord << 8; - if ((enemy_drawing_queue_index & 0x80) != 0) { - loop_index_end = -loop_index_end; - loop_index = -loop_index; +static uint32 SineMult8bitInner(uint16 varE32, uint16 varE34) { // 0xA0B0DA + uint16 mult = Mult8x8(kSine8bit[varE34 & 0x7F], varE32); + uint16 a = mult >> 8; + uint16 b = mult << 8; + if ((varE34 & 0x80) != 0) { + a = -a; + b = -b; } - return loop_index_end; + return __PAIR32__(a, b); +// varE38 = b; +// varE36 = a; +// return a; } -void ConvertAngleToXy(void) { // 0xA0B643 - R38 = kEquationForQuarterCircle[((uint8)R18_ + 0x80) & 0x7F]; - R40 = R20_; - Mult32bit(); - R26_ = R44; - R28_ = R42; - R38 = kEquationForQuarterCircle[((uint8)R18_ + 64) & 0x7F]; - R40 = R20_; - Mult32bit(); - R22_ = R44; - R24_ = R42; +uint16 CosineMult8bit(uint16 a, uint16 varE32) { // 0xA0B0B2 + return SineMult8bitInner(varE32, (uint8)(a + 64)) >> 16; } -void EnemyFunc_B691(void) { // 0xA0B691 - EnemyData *v1 = gEnemyData(cur_enemy_index); - uint16 x_subpos = v1->x_subpos; - if (((enemy_population_ptr + 64) & 0x80) != 0) { +uint16 SineMult8bit(uint16 a, uint16 varE32) { // 0xA0B0C6 + return SineMult8bitInner(varE32, (uint8)(a + 0x80)) >> 16; +} + +uint32 CosineMult8bitFull(uint16 a, uint16 varE32) { + return SineMult8bitInner(varE32, (uint8)(a + 64)); +} + +uint32 SineMult8bitFull(uint16 a, uint16 varE32) { + return SineMult8bitInner(varE32, (uint8)(a + 0x80)); +} + + +Point32 ConvertAngleToXy(uint16 r18, uint16 r20) { // 0xA0B643 + uint32 ss = kEquationForQuarterCircle[(r18 + 0x40) & 0x7F] * r20; + uint32 tt = kEquationForQuarterCircle[(r18 + 0x80) & 0x7F] * r20; + return (Point32) { ss, tt }; +} + +void EnemyFunc_B691(uint16 varE20, Point32 pt) { // 0xA0B691 + uint16 varE24 = pt.x >> 16; + uint16 varE26 = pt.x; + uint16 varE28 = pt.y >> 16; + uint16 varE2A = pt.y; + + EnemyData *E = gEnemyData(cur_enemy_index); + uint16 x_subpos = E->x_subpos; + if (((varE20 + 64) & 0x80) != 0) { bool v3 = x_subpos < varE26; - v1->x_subpos = x_subpos - varE26; - v1->x_pos -= v3 + varE24; + E->x_subpos = x_subpos - varE26; + E->x_pos -= v3 + varE24; } else { bool v3 = __CFADD__uint16(varE26, x_subpos); - v1->x_subpos = varE26 + x_subpos; - v1->x_pos += varE24 + v3; + E->x_subpos = varE26 + x_subpos; + E->x_pos += varE24 + v3; } - EnemyData *v4 = gEnemyData(cur_enemy_index); - uint16 y_subpos = v4->y_subpos; - if (((enemy_population_ptr + 128) & 0x80) != 0) { + uint16 y_subpos = E->y_subpos; + if (((varE20 + 128) & 0x80) != 0) { bool v3 = y_subpos < varE2A; - v4->y_subpos = y_subpos - varE2A; - v4->y_pos -= v3 + varE28; + E->y_subpos = y_subpos - varE2A; + E->y_pos -= v3 + varE28; } else { bool v3 = __CFADD__uint16(varE2A, y_subpos); - v4->y_subpos = varE2A + y_subpos; - v4->y_pos += varE28 + v3; + E->y_subpos = varE2A + y_subpos; + E->y_pos += varE28 + v3; } } -void Mult32bit(void) { // 0xA0B6FF - uint32 t = (uint32)R38 * (uint32)R40; - R42 = t; - R44 = t >> 16; -} - -void EnemyFunc_B761(void) { // 0xA0B761 - int16 v0; - unsigned int v1; // kr00_4 - - R40 = 0; - R38 = 0; - if (__PAIR32__(R48, R46)) { - v0 = 33; - uint8 carry = 0, carry2; - - while (1) { - carry2 = R44 >> 15; - R44 = (R44 << 1) | (R42 >> 15); - R42 = (R42 << 1) | carry; - if (!--v0) - break; - carry = R38 >> 15; - R40 = (R40 << 1) | (R38 >> 15); - R38 = (R38 << 1) | carry2; - - if (__PAIR32__(R40, R38)) { - carry = 0; - v1 = __PAIR32__(R40, R38) - __PAIR32__(R48, R46); - if (__PAIR32__(R40, R38) >= __PAIR32__(R48, R46)) { - R40 = v1 >> 16; - R38 = v1; - carry = 1; - } +uint32 EnemyFunc_Divide(uint32 a, uint32 b) { // 0xA0B761 + if (!a) + return 0; + uint32 c = 0; + int n = 33; + uint8 carry = 0, carry2; + while (1) { + carry2 = b >> 31; + b = b * 2 + carry; + if (!--n) + break; + carry = c >> 31; + c = c * 2 + carry2; + if (c) { + carry = 0; + if (c >= a) { + c -= a; + carry = 1; } } - } else { - R44 = 0; - R42 = 0; } + return b; } void EnemyFunc_B7A1(void) { // 0xA0B7A1 - int16 v1; - int16 v3; - - R18_ = samus_y_pos - samus_prev_y_pos; + uint16 yd = samus_y_pos - samus_prev_y_pos; uint16 v0 = Abs16(samus_y_pos - samus_prev_y_pos); - if (!sign16(v0 - 12)) { - v1 = -12; - if ((R18_ & 0x8000u) == 0) - v1 = 12; - samus_prev_y_pos = samus_y_pos + v1; - } - R18_ = samus_x_pos - samus_prev_x_pos; - uint16 v2 = Abs16(samus_x_pos - samus_prev_x_pos); - if (!sign16(v2 - 12)) { - v3 = -12; - if ((R18_ & 0x8000u) == 0) - v3 = 12; - samus_prev_x_pos = samus_x_pos + v3; - } + if (!sign16(v0 - 12)) + samus_prev_y_pos = samus_y_pos + ((yd & 0x8000) == 0 ? 12 : -12); + uint16 xd = samus_x_pos - samus_prev_x_pos; + uint16 i = Abs16(samus_x_pos - samus_prev_x_pos); + if (!sign16(i - 12)) + samus_prev_x_pos = samus_x_pos + ((xd & 0x8000) == 0 ? 12 : -12); } void Enemy_ItemDrop_MiniKraid(uint16 k) { // 0xA0B8EE - remaining_enemy_spritemap_entries = 4; + int n = 4; do { - R18_ = special_death_item_drop_x_origin_pos + (NextRandom() & 0x1F) - 16; - R20_ = special_death_item_drop_y_origin_pos + ((uint16)(random_number & 0x1F00) >> 8) - 16; - SpawnEnemyDrops(addr_kEnemyDef_E0FF, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = special_death_item_drop_x_origin_pos + (NextRandom() & 0x1F) - 16; + eproj_spawn_pt.y = special_death_item_drop_y_origin_pos + ((random_number & 0x1F00) >> 8) - 16; + SpawnEnemyDrops(addr_kEnemyDef_E0FF, k, 0); + } while (--n); } void Enemy_ItemDrop_LowerNorfairSpacePirate(uint16 k) { // 0xA0B92B - remaining_enemy_spritemap_entries = 5; + int n = 5; do { - R18_ = special_death_item_drop_x_origin_pos + (NextRandom() & 0x1F) - 16; - R20_ = special_death_item_drop_y_origin_pos + ((uint16)(random_number & 0x1F00) >> 8) - 16; - SpawnEnemyDrops(addr_kEnemyDef_F593, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = special_death_item_drop_x_origin_pos + (NextRandom() & 0x1F) - 16; + eproj_spawn_pt.y = special_death_item_drop_y_origin_pos + ((random_number & 0x1F00) >> 8) - 16; + SpawnEnemyDrops(addr_kEnemyDef_F593, k, 0); + } while (--n); } void Enemy_ItemDrop_Metroid(uint16 k) { // 0xA0B968 - remaining_enemy_spritemap_entries = 5; + int n = 5; do { - R18_ = special_death_item_drop_x_origin_pos + (NextRandom() & 0x1F) - 16; - R20_ = special_death_item_drop_y_origin_pos + ((uint16)(random_number & 0x1F00) >> 8) - 16; - SpawnEnemyDrops(addr_kEnemyDef_DD7F, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = special_death_item_drop_x_origin_pos + (NextRandom() & 0x1F) - 16; + eproj_spawn_pt.y = special_death_item_drop_y_origin_pos + ((random_number & 0x1F00) >> 8) - 16; + SpawnEnemyDrops(addr_kEnemyDef_DD7F, k, 0); + } while (--n); } void Enemy_ItemDrop_Ridley(uint16 k) { // 0xA0B9A5 - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (NextRandom() & 0x7F) + 64; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 320; - SpawnEnemyDrops(addr_kEnemyDef_E17F, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (NextRandom() & 0x7F) + 64; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 320; + SpawnEnemyDrops(addr_kEnemyDef_E17F, k, 0); + } while (--n); } void Enemy_ItemDrop_Crocomire(uint16 k) { // 0xA0B9D8 - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (NextRandom() & 0x7F) + 576; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 96; - SpawnEnemyDrops(addr_kEnemyDef_DDBF, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (NextRandom() & 0x7F) + 576; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 96; + SpawnEnemyDrops(addr_kEnemyDef_DDBF, k, 0); + } while (--n); } void Enemy_ItemDrop_Phantoon(uint16 k) { // 0xA0BA0B - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (NextRandom() & 0x7F) + 64; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 96; - SpawnEnemyDrops(addr_kEnemyDef_E4BF, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (NextRandom() & 0x7F) + 64; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 96; + SpawnEnemyDrops(addr_kEnemyDef_E4BF, k, 0); + } while (--n); } void Enemy_ItemDrop_Botwoon(uint16 k) { // 0xA0BA3E - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (NextRandom() & 0x7F) + 64; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 128; - SpawnEnemyDrops(addr_kEnemyDef_F293, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (NextRandom() & 0x7F) + 64; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 128; + SpawnEnemyDrops(addr_kEnemyDef_F293, k, 0); + } while (--n); } void Enemy_ItemDrop_Kraid(uint16 k) { // 0xA0BA71 - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (uint8)NextRandom() + 128; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 352; - SpawnEnemyDrops(addr_kEnemyDef_E2BF, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (uint8)NextRandom() + 128; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 352; + SpawnEnemyDrops(addr_kEnemyDef_E2BF, k, 0); + } while (--n); } void Enemy_ItemDrop_BombTorizo(uint16 k) { // 0xA0BAA4 - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (NextRandom() & 0x7F) + 64; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 96; - SpawnEnemyDrops(addr_kEnemyDef_EEFF, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (NextRandom() & 0x7F) + 64; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 96; + SpawnEnemyDrops(addr_kEnemyDef_EEFF, k, 0); + } while (--n); } void Enemy_ItemDrop_GoldenTorizo(uint16 k) { // 0xA0BAD7 - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (uint8)NextRandom() + 128; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 288; - SpawnEnemyDrops(addr_kEnemyDef_EEFF, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (uint8)NextRandom() + 128; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 288; + SpawnEnemyDrops(addr_kEnemyDef_EEFF, k, 0); + } while (--n); } void Enemy_ItemDrop_SporeSpawn(uint16 k) { // 0xA0BB0A - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (NextRandom() & 0x7F) + 64; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 528; - SpawnEnemyDrops(addr_kEnemyDef_DF3F, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (NextRandom() & 0x7F) + 64; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 528; + SpawnEnemyDrops(addr_kEnemyDef_DF3F, k, 0); + } while (--n); } void Enemy_ItemDrop_Draygon(uint16 k) { // 0xA0BB3D - remaining_enemy_spritemap_entries = 16; + int n = 16; do { - R18_ = (uint8)NextRandom() + 128; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 352; - SpawnEnemyDrops(addr_kEnemyDef_DE3F, k); - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + eproj_spawn_pt.x = (uint8)NextRandom() + 128; + eproj_spawn_pt.y = ((random_number & 0x3F00) >> 8) + 352; + SpawnEnemyDrops(addr_kEnemyDef_DE3F, k, 0); + } while (--n); } uint8 CompareDistToSamus_X(uint16 k, uint16 a) { // 0xA0BB9B - EnemyData *v2 = gEnemyData(k); - return abs16(samus_x_pos - v2->x_pos) >= a; + EnemyData *i = gEnemyData(k); + return abs16(samus_x_pos - i->x_pos) >= a; } uint8 CompareDistToSamus_Y(uint16 k, uint16 a) { // 0xA0BBAD - EnemyData *v2 = gEnemyData(k); - return abs16(samus_y_pos - v2->y_pos) >= a; + EnemyData *i = gEnemyData(k); + return abs16(samus_y_pos - i->y_pos) >= a; } -uint8 EnemyFunc_BBBF(uint16 k) { // 0xA0BBBF - int16 v7; - int16 v8; - int16 v11; - - EnemyData *v1 = gEnemyData(k); - R26_ = (v1->y_pos - v1->y_height) & 0xFFF0; - R26_ = (uint16)(v1->y_height + v1->y_pos - 1 - R26_) >> 4; - uint16 prod = Mult8x8((uint16)(v1->y_pos - v1->y_height) >> 4, room_width_in_blocks); - uint16 v2 = (__PAIR32__(R20_, R18_) + __PAIR32__(v1->x_pos, v1->x_subpos)) >> 16; - uint16 v3; - R22_ = R18_ + v1->x_subpos; - R24_ = v2; - if ((R20_ & 0x8000u) != 0) - v3 = v2 - v1->x_width; +uint8 EnemyFunc_BBBF(uint16 k, int32 amt) { // 0xA0BBBF + EnemyData *E = gEnemyData(k); + uint16 R26 = (E->y_pos - E->y_height) & 0xFFF0; + R26 = (uint16)(E->y_height + E->y_pos - 1 - R26) >> 4; + uint16 prod = Mult8x8((uint16)(E->y_pos - E->y_height) >> 4, room_width_in_blocks); + uint16 i = (amt + __PAIR32__(E->x_pos, E->x_subpos)) >> 16; + uint16 j; + //R22_ = r18 + E->x_subpos; + //r24 = i; + if (sign32(amt)) + j = i - E->x_width; else - v3 = v1->x_width + v2 - 1; - R34 = v3; - uint16 v4 = 2 * (prod + (v3 >> 4)); - while ((level_data[v4 >> 1] & 0x8000u) == 0) { + j = E->x_width + i - 1; + uint16 R34 = j; + uint16 v4 = 2 * (prod + (j >> 4)); + while ((level_data[v4 >> 1] & 0x8000) == 0) { v4 += room_width_in_blocks * 2; - if ((--R26_ & 0x8000u) != 0) + if ((--R26 & 0x8000) != 0) return 0; } - R18_ = 0; - if ((R20_ & 0x8000u) != 0) { + /* + r18 = 0; + if (sign32(amt)) { v8 = R34 | 0xF; - EnemyData *v9 = gEnemyData(k); - v11 = v9->x_width + 1 + v8 - v9->x_pos; + v11 = E->x_width + 1 + v8 - E->x_pos; if (v11 >= 0) v11 = 0; - R20_ = -v11; - return 1; + r20 = -v11; } else { - EnemyData *v6 = gEnemyData(k); - v7 = (R34 & 0xFFF0) - v6->x_width - v6->x_pos; + v7 = (R34 & 0xFFF0) - E->x_width - E->x_pos; if (v7 < 0) v7 = 0; - R20_ = v7; - return 1; - } + r20 = v7; + }*/ + return 1; } -uint8 EnemyFunc_BC76(uint16 k) { // 0xA0BC76 +uint8 EnemyFunc_BC76(uint16 k, int32 amt) { // 0xA0BC76 int16 v4; - int16 v8; - int16 v9; - int16 v12; - EnemyData *v1 = gEnemyData(k); - R26_ = (v1->x_pos - v1->x_width) & 0xFFF0; - R26_ = (uint16)(v1->x_width + v1->x_pos - 1 - R26_) >> 4; - uint16 v2 = (__PAIR32__(R20_, R18_) + __PAIR32__(v1->y_pos, v1->y_subpos)) >> 16; - uint16 v3; - R22_ = R18_ + v1->y_subpos; - R24_ = v2; - if ((R20_ & 0x8000u) != 0) - v3 = v2 - v1->y_height; + EnemyData *E = gEnemyData(k); + uint16 R26 = (E->x_pos - E->x_width) & 0xFFF0; + R26 = (uint16)(E->x_width + E->x_pos - 1 - R26) >> 4; + uint16 i = (amt + __PAIR32__(E->y_pos, E->y_subpos)) >> 16; + uint16 j; + //R22_ = r18 + E->y_subpos; + //r24 = i; + if (sign32(amt)) + j = i - E->y_height; else - v3 = v1->y_height + v2 - 1; - R34 = v3; - uint16 prod = Mult8x8(v3 >> 4, room_width_in_blocks); - v4 = (uint16)(v1->x_pos - v1->x_width) >> 4; - for (int i = 2 * (prod + v4); (level_data[i >> 1] & 0x8000u) == 0; i += 2) { - if ((--R26_ & 0x8000u) != 0) + j = E->y_height + i - 1; + uint16 R34 = j; + uint16 prod = Mult8x8(j >> 4, room_width_in_blocks); + v4 = (uint16)(E->x_pos - E->x_width) >> 4; + for (int i = 2 * (prod + v4); (level_data[i >> 1] & 0x8000) == 0; i += 2) { + if ((--R26 & 0x8000) != 0) return 0; } - R18_ = 0; - if ((R20_ & 0x8000u) != 0) { + /*r18 = 0; + if (sign32(amt)) { v9 = R34 | 0xF; - EnemyData *v10 = gEnemyData(k); - v12 = v10->y_height + 1 + v9 - v10->y_pos; + v12 = E->y_height + 1 + v9 - E->y_pos; if (v12 >= 0) v12 = 0; - R20_ = -v12; - return 1; + r20 = -v12; } else { - EnemyData *v7 = gEnemyData(k); - v8 = (R34 & 0xFFF0) - v7->y_height - v7->y_pos; + v8 = (R34 & 0xFFF0) - E->y_height - E->y_pos; if (v8 < 0) v8 = 0; - R20_ = v8; - return 1; - } + r20 = v8; + }*/ + return 1; } -uint8 EnemyFunc_BF8A(uint16 k, uint16 a) { // 0xA0BF8A +uint8 EnemyFunc_BF8A(uint16 k, uint16 a, int32 amt) { // 0xA0BF8A int16 v6; - int16 v10; - int16 v13; uint16 v4; - R28_ = a; - EnemyData *v2 = gEnemyData(k); - R26_ = (v2->x_pos - v2->x_width) & 0xFFF0; - R26_ = (uint16)(v2->x_width + v2->x_pos - 1 - R26_) >> 4; + EnemyData *E = gEnemyData(k); + uint16 R26 = (E->x_pos - E->x_width) & 0xFFF0; + R26 = (uint16)(E->x_width + E->x_pos - 1 - R26) >> 4; if (a & 1) { - uint16 v3 = (__PAIR32__(R20_, R18_) + __PAIR32__(v2->y_pos, v2->y_subpos)) >> 16; - R22_ = R18_ + v2->y_subpos; - R24_ = v3; - v4 = v2->y_height + v3 - 1; + uint16 j = (amt + __PAIR32__(E->y_pos, E->y_subpos)) >> 16; + //R22_ = r18 + E->y_subpos; + //r24 = j; + v4 = E->y_height + j - 1; } else { - uint16 v5 = (__PAIR32__(v2->y_pos, v2->y_subpos) - __PAIR32__(R20_, R18_)) >> 16; - R22_ = v2->y_subpos - R18_; - R24_ = v5; - v4 = v5 - v2->y_height; + uint16 v5 = (__PAIR32__(E->y_pos, E->y_subpos) - amt) >> 16; + //R22_ = E->y_subpos - r18; + //r24 = v5; + v4 = v5 - E->y_height; } - R34 = v4; + uint16 R34 = v4; uint16 prod = Mult8x8(v4 >> 4, room_width_in_blocks); - v6 = (uint16)(v2->x_pos - v2->x_width) >> 4; - for (int i = 2 * (prod + v6); (level_data[i >> 1] & 0x8000u) == 0; i += 2) { - if ((--R26_ & 0x8000u) != 0) + v6 = (uint16)(E->x_pos - E->x_width) >> 4; + for (int i = 2 * (prod + v6); (level_data[i >> 1] & 0x8000) == 0; i += 2) { + if ((--R26 & 0x8000) != 0) return 0; } - R18_ = 0; - if (R28_ & 1) { - EnemyData *v9 = gEnemyData(k); - v10 = (__PAIR32__((R34 & 0xFFF0) - v9->y_height, R34 & 0xFFF0) - __PAIR32__(v9->y_pos, v9->y_height)) >> 16; +/* r18 = 0; + if (a & 1) { + v10 = (__PAIR32__((R34 & 0xFFF0) - E->y_height, R34 & 0xFFF0) - __PAIR32__(E->y_pos, E->y_height)) >> 16; if (v10 < 0) v10 = 0; - R20_ = v10; - return 1; + r20 = v10; } else { - EnemyData *v11 = gEnemyData(k); - v13 = v11->y_height + 1 + (R34 | 0xF) - v11->y_pos; + v13 = E->y_height + 1 + (R34 | 0xF) - E->y_pos; if (v13 >= 0) v13 = 0; - R20_ = -v13; - return 1; - } + r20 = -v13; + }*/ + return 1; } uint16 CalculateAngleOfSamusFromEproj(uint16 k) { // 0xA0C04E - int v1 = k >> 1; - R18_ = samus_x_pos - enemy_projectile_x_pos[v1]; - R20_ = samus_y_pos - enemy_projectile_y_pos[v1]; - return CalculateAngleFromXY_(); + int j = k >> 1; + return CalculateAngleFromXY(samus_x_pos - enemy_projectile_x_pos[j], samus_y_pos - enemy_projectile_y_pos[j]); } uint16 CalculateAngleOfSamusFromEnemy(uint16 k) { // 0xA0C066 - EnemyData *v1 = gEnemyData(k); - R18_ = samus_x_pos - v1->x_pos; - R20_ = samus_y_pos - v1->y_pos; - return CalculateAngleFromXY_(); + EnemyData *E = gEnemyData(k); + return CalculateAngleFromXY(samus_x_pos - E->x_pos, samus_y_pos - E->y_pos); } uint16 CalculateAngleOfEnemyXfromEnemyY(uint16 k, uint16 j) { // 0xA0C096 - EnemyData *v2 = gEnemyData(k); - EnemyData *v3 = gEnemyData(j); - R18_ = v2->x_pos - v3->x_pos; - R20_ = v2->y_pos - v3->y_pos; - return CalculateAngleFromXY_(); + EnemyData *Ek = gEnemyData(k); + EnemyData *Ej = gEnemyData(j); + return CalculateAngleFromXY(Ek->x_pos - Ej->x_pos, Ek->y_pos - Ej->y_pos); } -uint16 CalculateAngleFromXY(void) { // 0xA0C0AE - return CalculateAngleFromXY_(); +static uint8 CalculateAngleFromXY_0(uint16 div) { // 0xA0C112 + return (div >> 3) + 64; } -static Func_Y_Y *const funcs_758EE[4] = { CalculateAngleFromXY_1, CalculateAngleFromXY_2, CalculateAngleFromXY_4, CalculateAngleFromXY_7 }; -static Func_Y_Y *const funcs_7587D[4] = { CalculateAngleFromXY_0, CalculateAngleFromXY_3, CalculateAngleFromXY_5, CalculateAngleFromXY_6 }; -uint16 CalculateAngleFromXY_(void) { // 0xA0C0B1 - uint16 v0 = 0; - uint16 v1 = R18_; - uint16 r; +static uint8 CalculateAngleFromXY_1(uint16 div) { // 0xA0C120 + return 0x80 - (div >> 3); +} - if ((R18_ & 0x8000u) != 0) { - v0 = 4; - v1 = -R18_; +static uint8 CalculateAngleFromXY_2(uint16 div) { // 0xA0C132 + return div >> 3; +} + +static uint8 CalculateAngleFromXY_3(uint16 div) { // 0xA0C13C + return 64 - (div >> 3); +} + +static uint8 CalculateAngleFromXY_4(uint16 div) { // 0xA0C14E + return (div >> 3) + 0x80; +} + +static uint8 CalculateAngleFromXY_5(uint16 div) { // 0xA0C15C + return -64 - (div >> 3); +} + +static uint8 CalculateAngleFromXY_6(uint16 div) { // 0xA0C16E + return (div >> 3) - 64; +} + +static uint8 CalculateAngleFromXY_7(uint16 div) { // 0xA0C17C + return 0 - (div >> 3); +} + +typedef uint8 CalculateAngleFromXYFunc(uint16 j); +static CalculateAngleFromXYFunc *const funcs_758EE[4] = { CalculateAngleFromXY_1, CalculateAngleFromXY_2, CalculateAngleFromXY_4, CalculateAngleFromXY_7 }; +static CalculateAngleFromXYFunc *const funcs_7587D[4] = { CalculateAngleFromXY_0, CalculateAngleFromXY_3, CalculateAngleFromXY_5, CalculateAngleFromXY_6 }; +uint16 CalculateAngleFromXY(uint16 x_r18, uint16 y_r20) { // 0xA0C0B1 + int idx = 0; + if ((x_r18 & 0x8000) != 0) { + idx += 2; + x_r18 = -x_r18; } - R18_ = v1; - uint16 v2 = R20_; - if ((R20_ & 0x8000u) != 0) { - v0 += 2; - v2 = -R20_; + if ((y_r20 & 0x8000) != 0) { + idx += 1; + y_r20 = -y_r20; } - R20_ = v2; - if (v2 < R18_) { - uint16 div = SnesDivide(R20_ << 8, R18_); - r = funcs_7587D[v0 >> 1](div); + if (y_r20 < x_r18) { + uint16 div = SnesDivide(y_r20 << 8, x_r18); + return funcs_7587D[idx](div); } else { - uint16 div = SnesDivide(R18_ << 8, R20_); - r = funcs_758EE[v0 >> 1](div); + uint16 div = SnesDivide(x_r18 << 8, y_r20); + return funcs_758EE[idx](div); } - - return r; -} - -uint16 CalculateAngleFromXY_0(uint16 div) { // 0xA0C112 - return (uint8)((div >> 3) + 64); -} - -uint16 CalculateAngleFromXY_1(uint16 div) { // 0xA0C120 - R18_ = div >> 3; - return (uint8)(0x80 - R18_); -} - -uint16 CalculateAngleFromXY_2(uint16 div) { // 0xA0C132 - return (uint8)(div >> 3); -} - -uint16 CalculateAngleFromXY_3(uint16 div) { // 0xA0C13C - R18_ = div >> 3; - return (uint8)(64 - R18_); -} - -uint16 CalculateAngleFromXY_4(uint16 div) { // 0xA0C14E - return (div >> 3) + 0x80 & 0xff; -} - -uint16 CalculateAngleFromXY_5(uint16 div) { // 0xA0C15C - R18_ = div >> 3; - return (uint8)(-64 - R18_); -} - -uint16 CalculateAngleFromXY_6(uint16 div) { // 0xA0C16E - return (uint8)((div >> 3) - 64); -} - -uint16 CalculateAngleFromXY_7(uint16 div) { // 0xA0C17C - R18_ = div >> 3; - return (uint8)-(int8)R18_; } uint8 IsEnemyLeavingScreen(uint16 k) { // 0xA0C18E int16 x_pos; int16 v3; - EnemyData *v1 = gEnemyData(k); - x_pos = v1->x_pos; - uint8 result = 1; + EnemyData *E = gEnemyData(k); + x_pos = E->x_pos; if (x_pos >= 0) { - v3 = v1->x_width + x_pos - layer1_x_pos; - if (v3 >= 0 && (int16)(v3 - 256 - v1->x_width) < 0) + v3 = E->x_width + x_pos - layer1_x_pos; + if (v3 >= 0 && (int16)(v3 - 256 - E->x_width) < 0) return 0; } - return result; + return 1; } void ProcessEnemyInstructions(void) { // 0xA0C26A - EnemyData *ED = gEnemyData(cur_enemy_index); - if ((ED->ai_handler_bits & 4) == 0) { - if (ED->instruction_timer-- == 1) { - assert(ED->current_instruction & 0x8000); - const uint8 *base_ptr = RomPtrWithBank(ED->bank, 0x8000) - 0x8000; - const uint16 *pc = (const uint16 *)(base_ptr + ED->current_instruction); - while ((*pc & 0x8000u) != 0) { - enemy_ai_pointer.addr = *pc; - pc = CallEnemyInstr(Load24(&enemy_ai_pointer), cur_enemy_index, pc + 1); + EnemyData *E = gEnemyData(cur_enemy_index); + if ((E->ai_handler_bits & 4) == 0) { + if (E->instruction_timer-- == 1) { + assert(E->current_instruction & 0x8000); + const uint8 *base_ptr = RomBankBase(E->bank); + const uint16 *pc = (const uint16 *)(base_ptr + E->current_instruction); + while ((*pc & 0x8000) != 0) { + pc = CallEnemyInstr(E->bank << 16 | *pc, cur_enemy_index, pc + 1); if (!pc) return; if ((uintptr_t)pc < 0x10000) pc = (const uint16*)(base_ptr + (uintptr_t)pc); } - ED->instruction_timer = pc[0]; - ED->spritemap_pointer = pc[1]; - ED->current_instruction = (uint8 *)pc + 4 - base_ptr; - ED->extra_properties |= 0x8000; + E->instruction_timer = pc[0]; + E->spritemap_pointer = pc[1]; + E->current_instruction = (uint8 *)pc + 4 - base_ptr; + E->extra_properties |= 0x8000; } else { - ED->extra_properties &= ~0x8000; + E->extra_properties &= ~0x8000; } } } -uint8 ClearCarry_13(void) { // 0xA0C2BC +static uint8 ClearCarry_13(EnemyBlockCollInfo *ebci) { // 0xA0C2BC return 0; } -uint8 SetCarry_4(void) { // 0xA0C2BE +static uint8 SetCarry_4(EnemyBlockCollInfo *ebci) { // 0xA0C2BE return 1; } - -uint8 EnemyBlockCollReact_Spike(void) { // 0xA0C2C0 +static uint8 EnemyBlockCollReact_Spike(EnemyBlockCollInfo *ebci) { // 0xA0C2C0 uint16 v0 = g_off_A0C2DA[BTS[cur_block_index] & 0x7F]; if (!v0) return 1; @@ -4156,22 +3551,20 @@ uint8 EnemyBlockCollReact_Spike(void) { // 0xA0C2C0 return 0; } -uint8 EnemyBlockCollHorizReact_Slope(void) { // 0xA0C2FA - if ((BTS[cur_block_index] & 0x1Fu) >= 5) { - uint16 v0 = BTS[cur_block_index]; - current_slope_bts = v0; - return EnemyBlockCollHorizReact_Slope_NonSquare(); +static uint8 EnemyBlockCollHorizReact_Slope(EnemyBlockCollInfo *ebci) { // 0xA0C2FA + if ((BTS[cur_block_index] & 0x1F) >= 5) { + current_slope_bts = BTS[cur_block_index]; + return EnemyBlockCollHorizReact_Slope_NonSquare(ebci); } else { - return EnemyBlockCollHorizReact_Slope_Square(cur_block_index, BTS[cur_block_index] & 0x1F); + return EnemyBlockCollHorizReact_Slope_Square(ebci, cur_block_index, BTS[cur_block_index] & 0x1F); } } -uint8 EnemyBlockCollVertReact_Slope(void) { // 0xA0C319 - uint16 v0 = BTS[cur_block_index] & 0x1F; - if (v0 >= 5u) - return EnemyBlockCollVertReact_Slope_NonSquare(); +static uint8 EnemyBlockCollVertReact_Slope(EnemyBlockCollInfo *ebci) { // 0xA0C319 + if ((BTS[cur_block_index] & 0x1F) >= 5) + return EnemyBlockCollVertReact_Slope_NonSquare(ebci); else - return EnemyBlockCollVertReact_Slope_Square(v0, cur_block_index); + return EnemyBlockCollVertReact_Slope_Square(ebci, BTS[cur_block_index] & 0x1F, cur_block_index); } static const uint8 byte_A0C435[20] = { // 0xA0C32E @@ -4182,86 +3575,56 @@ static const uint8 byte_A0C435[20] = { // 0xA0C32E 0x80, 0x81, 0x82, 0x83, }; - -uint8 EnemyBlockCollHorizReact_Slope_Square(uint16 k, uint16 a) { - EnemyData *v4; +static uint8 EnemyBlockCollHorizReact_Slope_Square(EnemyBlockCollInfo *ebci, uint16 k, uint16 a) { + EnemyData *E = gEnemyData(cur_enemy_index); uint16 temp_collision_DD4 = 4 * a; uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R26_ & 8) >> 3)); - if (!R28_) { - EnemyData *v3 = gEnemyData(cur_enemy_index); - if (((LOBYTE(v3->y_height) + LOBYTE(v3->y_pos) - 1) & 8) == 0) - return CHECK_locret_A0C434(v2) < 0; + uint16 i = 4 * a + (temp_collision_DD6 ^ ((ebci->ebci_r26 & 8) >> 3)); + if (!ebci->ebci_r28) { + if (((LOBYTE(E->y_height) + LOBYTE(E->y_pos) - 1) & 8) == 0) + return CHECK_locret_A0C434(i) < 0; goto LABEL_7; } - if (R28_ != R30_ || (v4 = gEnemyData(cur_enemy_index), ((v4->y_pos - v4->y_height) & 8) == 0)) { + if (ebci->ebci_r28 != ebci->ebci_r30 || ((E->y_pos - E->y_height) & 8) == 0) { LABEL_7: - if (CHECK_locret_A0C434(v2) < 0) + if (CHECK_locret_A0C434(i) < 0) return 1; } - return CHECK_locret_A0C434(v2 ^ 2) < 0; + return CHECK_locret_A0C434(i ^ 2) < 0; } -void Enemy_SetXpos_Aligned(uint16 j) { // 0xA0C390 - EnemyData *v1 = gEnemyData(j); - uint16 v2; - v1->x_subpos = 0; - if ((R20_ & 0x8000u) != 0) - v2 = v1->x_width + (R26_ | 7) + 1; - else - v2 = (R26_ & 0xFFF8) - v1->x_width; - v1->x_pos = v2; -} - -uint8 EnemyBlockCollVertReact_Slope_Square(uint16 a, uint16 k) { // 0xA0C3B2 - EnemyData *v4; - +static uint8 EnemyBlockCollVertReact_Slope_Square(EnemyBlockCollInfo *ebci, uint16 a, uint16 k) { // 0xA0C3B2 + EnemyData *E = gEnemyData(cur_enemy_index); uint16 temp_collision_DD4 = 4 * a; uint16 temp_collision_DD6 = BTS[k] >> 6; - uint16 v2 = 4 * a + (temp_collision_DD6 ^ ((uint8)(R26_ & 8) >> 2)); - if (!R28_) { - EnemyData *v3 = gEnemyData(cur_enemy_index); - if (((LOBYTE(v3->x_width) + LOBYTE(v3->x_pos) - 1) & 8) == 0) - return CHECK_locret_A0C434(v2) < 0; + uint16 i = 4 * a + (temp_collision_DD6 ^ ((ebci->ebci_r26 & 8) >> 2)); + if (!ebci->ebci_r28) { + if (((LOBYTE(E->x_width) + LOBYTE(E->x_pos) - 1) & 8) == 0) + return CHECK_locret_A0C434(i) < 0; goto LABEL_7; } - if (R28_ != R30_ || (v4 = gEnemyData(cur_enemy_index), ((v4->x_pos - v4->x_width) & 8) == 0)) { + if (ebci->ebci_r28 != ebci->ebci_r30 || ((E->x_pos - E->x_width) & 8) == 0) { LABEL_7: - if (CHECK_locret_A0C434(v2) < 0) + if (CHECK_locret_A0C434(i) < 0) return 1; } - return CHECK_locret_A0C434(v2 ^ 1) < 0; + return CHECK_locret_A0C434(i ^ 1) < 0; } -uint8 Enemy_SetYpos_Aligned(uint16 j) { // 0xA0C413 - EnemyData *v1 = gEnemyData(j); - uint16 v2; - v1->y_subpos = 0; - if ((R20_ & 0x8000u) != 0) - v2 = v1->y_height + (R26_ | 7) + 1; - else - v2 = (R26_ & 0xFFF8) - v1->y_height; - v1->y_pos = v2; - return 1; -} -uint8 EnemyBlockCollHorizReact_Slope_NonSquare(void) { // 0xA0C449 - if ((R32_ & 0x8000u) == 0) - return (R32_ & 0x4000) != 0; - uint16 v2 = 4 * (current_slope_bts & 0x1F); - if ((R20_ & 0x8000u) == 0) { - Multiply16x16(R19_, g_word_A0C49F[(v2 >> 1) + 1]); - R18_ = mult_product_lo; - R20_ = mult_product_hi; +static uint8 EnemyBlockCollHorizReact_Slope_NonSquare(EnemyBlockCollInfo *ebci) { // 0xA0C449 + if ((ebci->ebci_r32 & 0x8000) == 0) + return (ebci->ebci_r32 & 0x4000) != 0; + int i = 2 * (current_slope_bts & 0x1F); + if (ebci->ebci_r18_r20 >= 0) { + ebci->ebci_r18_r20 = (ebci->ebci_r18_r20 >> 8) * g_word_A0C49F[i + 1]; } else { - Multiply16x16(-R19_, g_word_A0C49F[(v2 >> 1) + 1]); - Negate32(&mult_product_hi, &mult_product_lo, &R20_, &R18_); + ebci->ebci_r18_r20 = -(-(int16)(ebci->ebci_r18_r20 >> 8) * g_word_A0C49F[i + 1]); } return 0; } - -uint8 EnemyBlockCollVertReact_Slope_NonSquare(void) { // 0xA0C51F +static uint8 EnemyBlockCollVertReact_Slope_NonSquare(EnemyBlockCollInfo *ebci) { // 0xA0C51F int16 v3; int16 v5; int16 v6; @@ -4272,59 +3635,49 @@ uint8 EnemyBlockCollVertReact_Slope_NonSquare(void) { // 0xA0C51F int16 x_pos; uint16 v14; int16 v15; + uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); + EnemyData *E = gEnemyData(cur_enemy_index); + uint16 v1 = cur_block_index; - if ((R20_ & 0x8000u) != 0) { - uint16 v9 = cur_block_index; - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - EnemyData *v10 = gEnemyData(cur_enemy_index); - v11 = v10->x_pos >> 4; - if (v11 == mod) { - uint16 temp_collision_DD4 = (R24_ - v10->y_height) & 0xF ^ 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[v9] & 0x1F); - v12 = BTS[v9] << 8; - if (v12 < 0 - && ((v12 & 0x4000) != 0 ? (x_pos = v10->x_pos ^ 0xF) : (x_pos = v10->x_pos), - (v14 = temp_collision_DD6 + (x_pos & 0xF), - v15 = (kAlignYPos_Tab0[v14] & 0x1F) - temp_collision_DD4 - 1, - (kAlignYPos_Tab0[v14] & 0x1F) - temp_collision_DD4 == 1) - || v15 < 0)) { - v10->y_pos = R24_ - v15; - v10->y_subpos = 0; - return 1; - } else { - return 0; - } + if (ebci->ebci_r18_r20 < 0) { + v11 = E->x_pos >> 4; + if (v11 != mod) + return 0; + uint16 temp_collision_DD4 = (ebci->ebci_r24 - E->y_height) & 0xF ^ 0xF; + uint16 temp_collision_DD6 = 16 * (BTS[v1] & 0x1F); + v12 = BTS[v1] << 8; + if (v12 < 0 + && ((v12 & 0x4000) != 0 ? (x_pos = E->x_pos ^ 0xF) : (x_pos = E->x_pos), + (v14 = temp_collision_DD6 + (x_pos & 0xF), + v15 = (kAlignYPos_Tab0[v14] & 0x1F) - temp_collision_DD4 - 1, v15 <= 0))) { + E->y_pos = ebci->ebci_r24 - v15; + E->y_subpos = 0; + return 1; } else { return 0; } } else { - uint16 v1 = cur_block_index; - uint16 mod = SnesModulus(cur_block_index, room_width_in_blocks); - EnemyData *v2 = gEnemyData(cur_enemy_index); - v3 = v2->x_pos >> 4; - if (v3 == mod) { - uint16 temp_collision_DD4 = (LOBYTE(v2->y_height) + (uint8)R24_ - 1) & 0xF; - uint16 temp_collision_DD6 = 16 * (BTS[v1] & 0x1F); - v5 = BTS[v1] << 8; - if (v5 >= 0 - && ((v5 & 0x4000) != 0 ? (v6 = v2->x_pos ^ 0xF) : (v6 = v2->x_pos), - (v7 = temp_collision_DD6 + (v6 & 0xF), - v8 = (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 - 1, - (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 == 1) - || v8 < 0)) { - v2->y_pos = R24_ + v8; - v2->y_subpos = -1; - return 1; - } else { - return 0; - } + v3 = E->x_pos >> 4; + if (v3 != mod) + return 0; + uint16 temp_collision_DD4 = (E->y_height + ebci->ebci_r24 - 1) & 0xF; + uint16 temp_collision_DD6 = 16 * (BTS[v1] & 0x1F); + v5 = BTS[v1] << 8; + if (v5 >= 0 + && ((v5 & 0x4000) != 0 ? (v6 = E->x_pos ^ 0xF) : (v6 = E->x_pos), + (v7 = temp_collision_DD6 + (v6 & 0xF), + v8 = (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 - 1, + (kAlignYPos_Tab0[v7] & 0x1F) - temp_collision_DD4 == 1) || v8 < 0)) { + E->y_pos = ebci->ebci_r24 + v8; + E->y_subpos = -1; + return 1; } else { return 0; } } } -uint8 EnemyBlockCollReact_HorizExt(void) { // 0xA0C619 +static uint8 EnemyBlockCollReact_HorizExt(EnemyBlockCollInfo *ebci) { // 0xA0C619 uint8 t = BTS[cur_block_index]; if (t) { cur_block_index += (int8)t; @@ -4333,141 +3686,105 @@ uint8 EnemyBlockCollReact_HorizExt(void) { // 0xA0C619 return 0; } -uint8 EnemyBlockCollReact_VertExt(void) { // 0xA0C64F - uint16 v0; +static uint8 EnemyBlockCollReact_VertExt(EnemyBlockCollInfo *ebci) { // 0xA0C64F if (BTS[cur_block_index]) { - if ((BTS[cur_block_index] & 0x80) != 0) { - uint16 temp_collision_DD4 = BTS[cur_block_index] | 0xFF00; - v0 = cur_block_index; - do { - v0 -= room_width_in_blocks; - ++temp_collision_DD4; - } while (temp_collision_DD4); - } else { - uint16 temp_collision_DD4 = BTS[cur_block_index]; - v0 = cur_block_index; - do { - v0 += room_width_in_blocks; - --temp_collision_DD4; - } while (temp_collision_DD4); - } - cur_block_index = v0; + cur_block_index += (int8)BTS[cur_block_index] * room_width_in_blocks; return 0xff; } return 0; } -uint8 Enemy_MoveRight_SlopesAsWalls(uint16 k) { // 0xA0C69D - R32_ = 0x4000; - return Enemy_MoveRight_IgnoreSlopes_Inner(k); +uint8 Enemy_MoveRight_SlopesAsWalls(uint16 k, int32 amt) { // 0xA0C69D + return Enemy_MoveRight_IgnoreSlopes_Inner(k, amt, 0x4000); } -uint8 Enemy_MoveRight_ProcessSlopes(uint16 k) { // 0xA0C6A4 - R32_ = 0x8000; - return Enemy_MoveRight_IgnoreSlopes_Inner(k); +uint8 Enemy_MoveRight_ProcessSlopes(uint16 k, int32 amt) { // 0xA0C6A4 + return Enemy_MoveRight_IgnoreSlopes_Inner(k, amt, 0x8000); } -uint8 Enemy_MoveRight_IgnoreSlopes(uint16 k) { // 0xA0C6AB - R32_ = 0; - return Enemy_MoveRight_IgnoreSlopes_Inner(k); +uint8 Enemy_MoveRight_IgnoreSlopes(uint16 k, int32 amt) { // 0xA0C6AB + return Enemy_MoveRight_IgnoreSlopes_Inner(k, amt, 0); } -uint8 Enemy_MoveRight_IgnoreSlopes_Inner(uint16 k) { // 0xA0C6AD - if (!__PAIR32__(R20_, R18_)) +// amount32 is r20:r18 +static uint8 Enemy_MoveRight_IgnoreSlopes_Inner(uint16 k, int32 amount32, uint16 r32) { // 0xA0C6AD + if (!amount32) return 0; - EnemyData *v3 = gEnemyData(k); - R28_ = (v3->y_pos - v3->y_height) & 0xFFF0; - R28_ = (uint16)(v3->y_height + v3->y_pos - 1 - R28_) >> 4; - R30_ = R28_; - uint16 prod = Mult8x8((uint16)(v3->y_pos - v3->y_height) >> 4, room_width_in_blocks); - uint16 v4 = (__PAIR32__(R20_, R18_) + __PAIR32__(v3->x_pos, v3->x_subpos)) >> 16; - R22_ = R18_ + v3->x_subpos; - R24_ = v4; + EnemyData *E = gEnemyData(k); + uint16 r28 = (uint16)(E->y_height + E->y_pos - 1 - ((E->y_pos - E->y_height) & 0xFFF0)) >> 4; + uint16 r30 = r28; + uint16 prod = Mult8x8((uint16)(E->y_pos - E->y_height) >> 4, room_width_in_blocks); + uint32 new_pos = amount32 + __PAIR32__(E->x_pos, E->x_subpos); uint16 v5; - if ((R20_ & 0x8000u) != 0) - v5 = v4 - v3->x_width; + uint16 r24 = new_pos >> 16; // read by EnemyBlockCollVertReact_Slope_NonSquare + if (sign32(amount32)) + v5 = (new_pos >> 16) - E->x_width; else - v5 = v3->x_width + v4 - 1; - R26_ = v5; + v5 = E->x_width + (new_pos >> 16) - 1; + EnemyBlockCollInfo ebci = { .ebci_r18_r20 = amount32, .ebci_r24 = r24, .ebci_r26 = v5, .ebci_r28 = r28, .ebci_r30 = r30, .ebci_r32 = r32}; uint16 v6 = 2 * (prod + (v5 >> 4)); - while (!(EnemyBlockCollReact_Horiz(v6) & 1)) { + while (!(EnemyBlockCollReact_Horiz(&ebci, v6) & 1)) { v6 += room_width_in_blocks * 2; - if ((--R28_ & 0x8000u) != 0) { - EnemyData *v7 = gEnemyData(k); - bool v8 = __CFADD__uint16(v7->x_subpos, R18_); - v7->x_subpos += R18_; - v7->x_pos += v8 + R20_; + if ((--ebci.ebci_r28 & 0x8000) != 0) { + AddToHiLo(&E->x_pos, &E->x_subpos, ebci.ebci_r18_r20); return 0; } } - if ((R20_ & 0x8000u) != 0) { - EnemyData *v11 = gEnemyData(k); - uint16 v12 = v11->x_width + 1 + (R26_ | 0xF); - if (v12 == v11->x_pos || v12 < v11->x_pos) - v11->x_pos = v12; - v11->x_subpos = 0; + if (sign32(amount32)) { + uint16 v12 = E->x_width + 1 + (ebci.ebci_r26 | 0xF); + if (v12 <= E->x_pos) + E->x_pos = v12; + E->x_subpos = 0; return 1; } else { - EnemyData *v9 = gEnemyData(k); - uint16 v10 = (R26_ & 0xFFF0) - v9->x_width; - if (v10 >= v9->x_pos) - v9->x_pos = v10; - v9->x_subpos = -1; + uint16 v10 = (ebci.ebci_r26 & 0xFFF0) - E->x_width; + if (v10 >= E->x_pos) + E->x_pos = v10; + E->x_subpos = -1; return 1; } } -uint8 Enemy_MoveDown(uint16 k) { // 0xA0C786 - R32_ = 0; - return Enemy_MoveDownInner(k); -} - -uint8 Enemy_MoveDownInner(uint16 k) { // 0xA0C788 +uint8 Enemy_MoveDown(uint16 k, int32 amount32) { // 0xA0C786 int16 v6; uint16 v5; - - if (!__PAIR32__(R20_, R18_)) + if (!amount32) return 0; - EnemyData *v3 = gEnemyData(k); - R28_ = (v3->x_pos - v3->x_width) & 0xFFF0; - R28_ = (uint16)(v3->x_width + v3->x_pos - 1 - R28_) >> 4; - R30_ = R28_; - uint16 v4 = (__PAIR32__(R20_, R18_) + __PAIR32__(v3->y_pos, v3->y_subpos)) >> 16; - R22_ = R18_ + v3->y_subpos; - R24_ = v4; - if ((R20_ & 0x8000u) != 0) - v5 = v4 - v3->y_height; + EnemyData *E = gEnemyData(k); + uint16 r28 = (uint16)(E->x_width + E->x_pos - 1 - ((E->x_pos - E->x_width) & 0xFFF0)) >> 4; + uint16 r30 = r28; + uint32 new_pos = amount32 + __PAIR32__(E->y_pos, E->y_subpos); + uint16 r24 = new_pos >> 16; // read by EnemyBlockCollVertReact_Slope_NonSquare +// R22_ = new_pos; + if (sign32(amount32)) + v5 = (new_pos >> 16) - E->y_height; else - v5 = v3->y_height + v4 - 1; - R26_ = v5; + v5 = E->y_height + (new_pos >> 16) - 1; uint16 prod = Mult8x8(v5 >> 4, room_width_in_blocks); - v6 = (uint16)(v3->x_pos - v3->x_width) >> 4; - for (int i = 2 * (prod + v6); !(EnemyBlockCollReact_Vert(i) & 1); i += 2) { - if ((--R28_ & 0x8000u) != 0) { - EnemyData *v8 = gEnemyData(k); - v8->y_subpos = R22_; - v8->y_pos = R24_; + v6 = (uint16)(E->x_pos - E->x_width) >> 4; + EnemyBlockCollInfo ebci = { .ebci_r18_r20 = amount32, .ebci_r24 = r24, .ebci_r26 = v5, .ebci_r28 = r28, .ebci_r30 = r30, .ebci_r32 = 0 }; + for (int i = 2 * (prod + v6); !(EnemyBlockCollReact_Vert(&ebci, i) & 1); i += 2) { + if ((--ebci.ebci_r28 & 0x8000) != 0) { + E->y_subpos = new_pos, E->y_pos = new_pos >> 16; return 0; } } - if ((R20_ & 0x8000u) != 0) { - EnemyData *v11 = gEnemyData(k); - uint16 v13 = v11->y_height + 1 + (R26_ | 0xF); - if (v13 == v11->y_pos || v13 < v11->y_pos) - v11->y_pos = v13; - v11->y_subpos = 0; + if (sign32(amount32)) { + uint16 v13 = E->y_height + 1 + (ebci.ebci_r26 | 0xF); + if (v13 <= E->y_pos) + E->y_pos = v13; + E->y_subpos = 0; return 1; } else { - EnemyData *v9 = gEnemyData(k); - uint16 v10 = (R26_ & 0xFFF0) - v9->y_height; - if (v10 >= v9->y_pos) - v9->y_pos = v10; - v9->y_subpos = -1; + uint16 v10 = (ebci.ebci_r26 & 0xFFF0) - E->y_height; + if (v10 >= E->y_pos) + E->y_pos = v10; + E->y_subpos = -1; return 1; } } -static Func_U8 *const off_A0C859[16] = { // 0xA0C845 +static Func_EnemyBlockCollInfo_U8 *const off_A0C859[16] = { // 0xA0C845 ClearCarry_13, EnemyBlockCollHorizReact_Slope, ClearCarry_13, @@ -4486,16 +3803,16 @@ static Func_U8 *const off_A0C859[16] = { // 0xA0C845 SetCarry_4, }; -uint8 EnemyBlockCollReact_Horiz(uint16 k) { +static uint8 EnemyBlockCollReact_Horiz(EnemyBlockCollInfo *ebci, uint16 k) { cur_block_index = k >> 1; uint8 rv = 0; do { - rv = off_A0C859[(level_data[cur_block_index] & 0xf000) >> 12](); + rv = off_A0C859[(level_data[cur_block_index] & 0xf000) >> 12](ebci); } while (rv & 0x80); return rv; } -static Func_U8 *const off_A0C88D[16] = { // 0xA0C879 +static Func_EnemyBlockCollInfo_U8 *const off_A0C88D[16] = { // 0xA0C879 ClearCarry_13, EnemyBlockCollVertReact_Slope, ClearCarry_13, @@ -4514,11 +3831,11 @@ static Func_U8 *const off_A0C88D[16] = { // 0xA0C879 SetCarry_4, }; -uint8 EnemyBlockCollReact_Vert(uint16 k) { +static uint8 EnemyBlockCollReact_Vert(EnemyBlockCollInfo *ebci, uint16 k) { cur_block_index = k >> 1; uint8 rv = 0; do { - rv = off_A0C88D[(level_data[cur_block_index] & 0xf000) >> 12](); + rv = off_A0C88D[(level_data[cur_block_index] & 0xf000) >> 12](ebci); } while (rv & 0x80); return rv; } @@ -4529,46 +3846,32 @@ void CalculateBlockContainingPixelPos(uint16 xpos, uint16 ypos) { } uint8 EnemyFunc_C8AD(uint16 k) { // 0xA0C8AD - int16 v2; - int16 v3; - int16 v4; - int16 v5; - int16 x_pos; - int16 v7; - uint8 result = 0; - EnemyData *v1 = gEnemyData(k); - CalculateBlockContainingPixelPos(v1->x_pos, v1->y_pos + v1->y_height - 1); - if ((level_data[cur_block_index] & 0xF000) == 4096 - && (BTS[cur_block_index] & 0x1Fu) >= 5) { + EnemyData *E = gEnemyData(k); + CalculateBlockContainingPixelPos(E->x_pos, E->y_pos + E->y_height - 1); + if ((level_data[cur_block_index] & 0xF000) == 4096 && (BTS[cur_block_index] & 0x1F) >= 5) { result = 1; - uint16 temp_collision_DD4 = (LOBYTE(v1->y_height) + LOBYTE(v1->y_pos) - 1) & 0xF; + uint16 temp_collision_DD4 = (E->y_height + E->y_pos - 1) & 0xF; uint16 temp_collision_DD6 = 16 * (BTS[cur_block_index] & 0x1F); - v2 = BTS[cur_block_index] << 8; - if (v2 >= 0) { - v3 = (v2 & 0x4000) != 0 ? v1->x_pos ^ 0xF : v1->x_pos; - v4 = (kAlignYPos_Tab0[(uint16)(temp_collision_DD6 + (v3 & 0xF))] & 0x1F) - temp_collision_DD4 - 1; + if ((BTS[cur_block_index] & 0x80) == 0) { + uint16 j = (BTS[cur_block_index] & 0x40) != 0 ? E->x_pos ^ 0xF : E->x_pos; + int16 v4 = (kAlignYPos_Tab0[temp_collision_DD6 + (j & 0xF)] & 0x1F) - temp_collision_DD4 - 1; if (v4 < 0) - v1->y_pos += v4; + E->y_pos += v4; } } - CalculateBlockContainingPixelPos(v1->x_pos, v1->y_pos - v1->y_height); - if ((level_data[cur_block_index] & 0xF000) == 4096 - && (BTS[cur_block_index] & 0x1Fu) >= 5) { + CalculateBlockContainingPixelPos(E->x_pos, E->y_pos - E->y_height); + if ((level_data[cur_block_index] & 0xF000) == 4096 && (BTS[cur_block_index] & 0x1F) >= 5) { result = 1; - uint16 temp_collision_DD4 = (v1->y_pos - v1->y_height) & 0xF ^ 0xF; + uint16 temp_collision_DD4 = (E->y_pos - E->y_height) & 0xF ^ 0xF; uint16 temp_collision_DD6 = 16 * (BTS[cur_block_index] & 0x1F); - v5 = BTS[cur_block_index] << 8; - if (v5 < 0) { - if ((v5 & 0x4000) != 0) - x_pos = v1->x_pos ^ 0xF; - else - x_pos = v1->x_pos; - v7 = (kAlignYPos_Tab0[(uint16)(temp_collision_DD6 + (x_pos & 0xF))] & 0x1F) - temp_collision_DD4 - 1; - if (v7 <= 0) - v1->y_pos -= v7; + if (BTS[cur_block_index] & 0x80) { + uint16 j = (BTS[cur_block_index] & 0x40) != 0 ? E->x_pos ^ 0xF : E->x_pos; + int16 v7 = (kAlignYPos_Tab0[temp_collision_DD6 + (j & 0xF)] & 0x1F) - temp_collision_DD4 - 1; + if (v7 < 0) + E->y_pos -= v7; } } return result; -} \ No newline at end of file +} diff --git a/src/sm_a2.c b/src/sm_a2.c index 9479792..ba978bb 100644 --- a/src/sm_a2.c +++ b/src/sm_a2.c @@ -185,7 +185,7 @@ void BouncingGoofball_State1(void) { // 0xA28850 uint16 RegWord = Mult8x8(v2, E->bgl_var_A); E->bgl_var_B = RegWord; E->base.y_pos -= HIBYTE(RegWord); - if ((--E->bgl_var_E & 0x8000u) != 0) + if ((--E->bgl_var_E & 0x8000) != 0) E->bgl_var_01 = 0; } @@ -214,7 +214,7 @@ const uint16 *BouncingGoofball_Instr_88C5(uint16 k, const uint16 *jp) { // 0xA2 const uint16 *BouncingGoofball_Instr_88C6(uint16 k, const uint16 *jp) { // 0xA288C6 Get_BouncingGoofball(cur_enemy_index)->bgl_var_02 = 0; - QueueSfx2_Max6(0xEu); + QueueSfx2_Max6(0xE); return jp; } @@ -240,7 +240,7 @@ const uint16 *MiniCrocomire_Instr_899D(uint16 k, const uint16 *jp) { // 0xA2899 void MiniCrocomire_Init(void) { // 0xA289AD Enemy_MiniCrocomire *E = Get_MiniCrocomire(cur_enemy_index); E->base.spritemap_pointer = addr_kSpritemap_Nothing_A2; - int v1 = (uint16)(8 * E->mce_parameter_2) >> 1; + int v1 = (8 * E->mce_parameter_2) >> 1; E->mce_var_B = kCommonEnemySpeeds_Linear[v1]; E->mce_var_A = kCommonEnemySpeeds_Linear[v1 + 1]; E->mce_var_D = kCommonEnemySpeeds_Linear[v1 + 2]; @@ -290,25 +290,24 @@ void MiniCrocomire_Func4(void) { // 0xA28A30 void MiniCrocomire_PreInstr5(uint16 k) { // 0xA28A43 Enemy_MiniCrocomire *E = Get_MiniCrocomire(cur_enemy_index); - R20_ = E->mce_var_D; - R18_ = E->mce_var_C; - MiniCrocomire_Func7(); - if (MiniCrocomire_Func9() & 1) + MiniCrocomire_Func7(__PAIR32__(E->mce_var_D, E->mce_var_C)); + if (MiniCrocomire_Func9()) MiniCrocomire_Func2(); } void MiniCrocomire_PreInstr6(uint16 k) { // 0xA28A5C Enemy_MiniCrocomire *E = Get_MiniCrocomire(cur_enemy_index); - R20_ = E->mce_var_B; - R18_ = E->mce_var_A; - MiniCrocomire_Func7(); - if (MiniCrocomire_Func9() & 1) + MiniCrocomire_Func7(__PAIR32__(E->mce_var_B, E->mce_var_A)); + if (MiniCrocomire_Func9()) MiniCrocomire_Func4(); } -void MiniCrocomire_Func7(void) { // 0xA28A76 - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1 || (R20_ = 2, R18_ = 0, !(EnemyFunc_BC76(cur_enemy_index) & 1))) - MiniCrocomire_Func8(); +void MiniCrocomire_Func7(int32 amt) { // 0xA28A76 + if (!Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, amt)) { + if (EnemyFunc_BC76(cur_enemy_index, INT16_SHL16(2))) + return; + } + MiniCrocomire_Func8(); } void MiniCrocomire_Func8(void) { // 0xA28A95 @@ -417,11 +416,11 @@ void MaridiaBeybladeTurtle_Func2(uint16 k) { // 0xA28E0A v2 += 24; uint16 v3 = cur_enemy_index; E->base.y_height = -g_word_A28E80[v2]; - E->base.properties |= 0x8000u; + E->base.properties |= 0x8000; if (CheckIfEnemyTouchesSamus(v3)) { - R18_ = E->base.y_pos - E->base.y_height; - if ((int16)(samus_y_radius + samus_y_pos - R18_) >= 0) - extra_samus_y_displacement += R18_ - (samus_y_radius + samus_y_pos); + uint16 r18 = E->base.y_pos - E->base.y_height; + if ((int16)(samus_y_radius + samus_y_pos - r18) >= 0) + extra_samus_y_displacement += r18 - (samus_y_radius + samus_y_pos); } } } else { @@ -437,14 +436,12 @@ void MaridiaBeybladeTurtle_Func3(uint16 k) { // 0xA28EE0 --extra_samus_x_displacement; Enemy_MaridiaBeybladeTurtle *E = Get_MaridiaBeybladeTurtle(k); --E->base.y_pos; - R18_ = 0; E->base.y_height = 16; if ((E->base.y_pos & 1) != 0) --E->base.x_pos; else ++E->base.x_pos; - R20_ = 1; - if (!(Enemy_MoveRight_IgnoreSlopes(k) & 1)) { + if (!(Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL16(1)))) { E->base.current_instruction = addr_kMaridiaBeybladeTurtle_Ilist_8C4A; E->base.instruction_timer = 1; //*((uint16 *)RomPtr_A2(k) + 3) = g_word_A28D54; // WTF? @@ -478,9 +475,7 @@ void MaridiaBeybladeTurtle_Func6(uint16 k) { // 0xA28F5F void MaridiaBeybladeTurtle_Func7(uint16 k) { // 0xA28F8D MaridiaBeybladeTurtle_Func4(); - R20_ = -1; - R18_ = 0; - if (!(Enemy_MoveDown(k) & 1)) { + if (!(Enemy_MoveDown(k, INT16_SHL16(-1)))) { if (CheckIfEnemyTouchesSamus(k)) --extra_samus_y_displacement; Enemy_MaridiaTurtle *E = Get_MaridiaTurtle(k); @@ -502,16 +497,12 @@ void MaridiaBeybladeTurtle_Func7(uint16 k) { // 0xA28F8D void MaridiaBeybladeTurtle_Func8(uint16 k) { // 0xA28FEB MaridiaBeybladeTurtle_Func4(); Enemy_MaridiaTurtle *E = Get_MaridiaTurtle(k); - R20_ = E->mte_var_E; - R18_ = E->mte_var_03; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { - Negate32(&E->mte_var_E, &E->mte_var_03, - &E->mte_var_E, &E->mte_var_03); - Negate32(&E->mte_var_02, &E->mte_var_01, - &E->mte_var_02, &E->mte_var_01); + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->mte_var_E, E->mte_var_03))) { + Negate32(&E->mte_var_E, &E->mte_var_03, &E->mte_var_E, &E->mte_var_03); + Negate32(&E->mte_var_02, &E->mte_var_01, &E->mte_var_02, &E->mte_var_01); earthquake_type = 0; earthquake_timer = 16; - QueueSfx2_Max6(0x1Bu); + QueueSfx2_Max6(0x1B); } else { MaridiaBeybladeTurtle_Func6(k); uint16 mte_var_03 = E->mte_var_03; @@ -520,7 +511,7 @@ void MaridiaBeybladeTurtle_Func8(uint16 k) { // 0xA28FEB uint16 v5 = E->mte_var_02 + v3 + E->mte_var_E; if ((int16)(abs16(v5) - g_word_A28D5E) >= 0) { uint16 v4 = g_word_A28D5E; - if ((E->mte_var_E & 0x8000u) != 0) + if ((E->mte_var_E & 0x8000) != 0) v4 = -g_word_A28D5E; v5 = v4; } @@ -565,11 +556,9 @@ void MaridiaBeybladeTurtle_Func11(uint16 k) { // 0xA290E1 E->mte_var_07 = mte_var_07 + 0x2000; E->mte_var_04 += __CFADD__uint16(mte_var_07, 0x2000); } - R18_ = 0; - R20_ = E->mte_var_04; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, INT16_SHL16(E->mte_var_04))) { uint16 v4 = addr_kMaridiaBeybladeTurtle_Ilist_8C4A; - if ((E->mte_var_E & 0x8000u) == 0) + if ((E->mte_var_E & 0x8000) == 0) v4 = addr_kMaridiaBeybladeTurtle_Ilist_8D28; E->base.current_instruction = v4; E->base.instruction_timer = 1; @@ -589,7 +578,7 @@ void MiniMaridiaBeybladeTurtle_Func1(uint16 k) { // 0xA29142 E->mmte_var_A = FUNC16(MiniMaridiaBeybladeTurtle_Func2); E->mmte_var_05 = 4; uint16 v2 = addr_kMaridiaBeybladeTurtle_Ilist_8C30; - if ((E->mmte_var_E & 0x8000u) == 0) + if ((E->mmte_var_E & 0x8000) == 0) v2 = addr_kMaridiaBeybladeTurtle_Ilist_8D14; E->base.current_instruction = v2; E->base.instruction_timer = 1; @@ -626,7 +615,7 @@ void MiniMaridiaBeybladeTurtle_Func3(uint16 k) { // 0xA29198 E->mmte_var_00 = v4; if (!v4) { uint16 v5 = addr_kMaridiaBeybladeTurtle_Ilist_8B80; - if ((E->mmte_var_E & 0x8000u) == 0) + if ((E->mmte_var_E & 0x8000) == 0) v5 = addr_kMaridiaBeybladeTurtle_Ilist_8C72; E->base.current_instruction = v5; E->base.instruction_timer = 1; @@ -636,22 +625,18 @@ void MiniMaridiaBeybladeTurtle_Func3(uint16 k) { // 0xA29198 } void MiniMaridiaBeybladeTurtle_Func4(uint16 k) { // 0xA291F8 - R18_ = 0; Enemy_MiniMaridiaTurtle *E = Get_MiniMaridiaTurtle(k); - R20_ = E->mmte_var_E; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->mmte_var_E, 0))) { E->mmte_var_E = -E->mmte_var_E; } else { - R18_ = 0; - R20_ = E->mmte_var_04; - Enemy_MoveDown(k); + Enemy_MoveDown(k, INT16_SHL16(E->mmte_var_04)); } } void MiniMaridiaBeybladeTurtle_Func5(uint16 k) { // 0xA2921D uint16 v1 = addr_kMaridiaBeybladeTurtle_Ilist_8B80; Enemy_MiniMaridiaBeybladeTurtle *E = Get_MiniMaridiaBeybladeTurtle(k); - if ((E->mmbte_var_E & 0x8000u) == 0) + if ((E->mmbte_var_E & 0x8000) == 0) v1 = addr_kMaridiaBeybladeTurtle_Ilist_8C72; E->base.current_instruction = v1; E->base.instruction_timer = 1; @@ -662,7 +647,7 @@ void MiniMaridiaBeybladeTurtle_Func6(uint16 k) { // 0xA29239 if (CheckIfEnemyTouchesSamus(k)) { uint16 v1 = addr_kMaridiaBeybladeTurtle_Ilist_8B80; Enemy_MiniMaridiaBeybladeTurtle *E = Get_MiniMaridiaBeybladeTurtle(k); - if ((E->mmbte_var_E & 0x8000u) == 0) + if ((E->mmbte_var_E & 0x8000) == 0) v1 = addr_kMaridiaBeybladeTurtle_Ilist_8C72; E->base.current_instruction = v1; E->base.instruction_timer = 1; @@ -681,7 +666,7 @@ void MiniMaridiaBeybladeTurtle_Func7(void) { // 0xA2925E void MaridiaBeybladeTurtle_Touch(void) { // 0xA29281 Enemy_MiniMaridiaTurtle *E = Get_MiniMaridiaTurtle(cur_enemy_index); - if ((E->base.properties & 0x8000u) == 0) { + if ((E->base.properties & 0x8000) == 0) { Enemy_NormalTouchAI_A2(); E->mmte_var_A = FUNC16(MaridiaBeybladeTurtle_Func11); E->mmte_var_04 = 2; @@ -693,7 +678,7 @@ void MiniMaridiaBeybladeTurtle_Touch(void) { // 0xA2929F Enemy_MiniMaridiaBeybladeTurtle *E = Get_MiniMaridiaBeybladeTurtle(cur_enemy_index); if (E->mmbte_var_A != 0x925E) { - if ((E->mmbte_var_E & 0x8000u) != 0) { + if ((E->mmbte_var_E & 0x8000) != 0) { E->base.current_instruction = addr_kMaridiaBeybladeTurtle_Ilist_8C72; v2 = 1; } else { @@ -710,9 +695,7 @@ void MiniMaridiaBeybladeTurtle_Touch(void) { // 0xA2929F - __PAIR32__(E->base.x_width, samus_x_radius)) >> 16; E->base.x_pos = v3; E->mmbte_var_A = FUNC16(MiniMaridiaBeybladeTurtle_Func1); - R18_ = 0; - R20_ = E->mmbte_var_E; - Enemy_MoveRight_IgnoreSlopes(cur_enemy_index); + Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->mmbte_var_E, 0)); MaridiaBeybladeTurtle_Func21(); } } @@ -731,31 +714,29 @@ void MiniMaridiaBeybladeTurtle_Shot(void) { // 0xA2930F void MaridiaBeybladeTurtle_Func4(void) { // 0xA29315 Enemy_MaridiaBeybladeTurtle *E = Get_MaridiaBeybladeTurtle(0); - R18_ = E->base.x_pos - E->base.x_width - 8; - R20_ = E->base.x_width + E->base.x_pos + 8; - R22_ = E->base.y_pos - E->base.y_height + 4; - R24_ = E->base.y_height + E->base.y_pos - 4; - if (sign16(samus_x_pos - samus_x_radius - 1 - R20_) - && !sign16(samus_x_radius + samus_x_pos - R18_) - && sign16(samus_y_pos - samus_y_radius + 1 - R24_) - && !sign16(samus_y_radius + samus_y_pos - R22_) + uint16 r18 = E->base.x_pos - E->base.x_width - 8; + uint16 r20 = E->base.x_width + E->base.x_pos + 8; + uint16 r22 = E->base.y_pos - E->base.y_height + 4; + uint16 r24 = E->base.y_height + E->base.y_pos - 4; + if (sign16(samus_x_pos - samus_x_radius - 1 - r20) + && !sign16(samus_x_radius + samus_x_pos - r18) + && sign16(samus_y_pos - samus_y_radius + 1 - r24) + && !sign16(samus_y_radius + samus_y_pos - r22) && !samus_invincibility_timer) { NormalEnemyTouchAi(); } } const uint16 *MaridiaBeybladeTurtle_Instr_9381(uint16 k, const uint16 *jp) { // 0xA29381 - R48 = 0; + uint16 R48 = 0; if (CheckIfEnemyTouchesSamus(cur_enemy_index)) { extra_samus_x_displacement += Get_MaridiaBeybladeTurtle(cur_enemy_index)->mbte_var_E; R48 = 1; } Enemy_MaridiaBeybladeTurtle *E = Get_MaridiaBeybladeTurtle(cur_enemy_index); - R50 = E->base.y_pos; + uint16 R50 = E->base.y_pos; E->base.y_pos = E->mbte_var_D; - R18_ = 0; - R20_ = E->mbte_var_E; - Enemy_MoveRight_IgnoreSlopes(cur_enemy_index); + Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(E->mbte_var_E)); if (Get_MaridiaBeybladeTurtle(E->mbte_var_B)->mbte_var_A == 0x8E0A) { uint16 x_pos = Get_MaridiaBeybladeTurtle(E->mbte_var_B)->base.x_pos; uint16 xd = x_pos - E->base.x_pos; @@ -768,12 +749,9 @@ const uint16 *MaridiaBeybladeTurtle_Instr_9381(uint16 k, const uint16 *jp) { // } else { v8 = 1; } - R20_ = v8; - R18_ = 0; - uint16 v9 = cur_enemy_index; - Enemy_MoveDown(cur_enemy_index); + Enemy_MoveDown(cur_enemy_index, INT16_SHL16(v8)); if (R48) - extra_samus_y_displacement += Get_MaridiaBeybladeTurtle(v9)->base.y_pos - R50; + extra_samus_y_displacement += Get_MaridiaBeybladeTurtle(cur_enemy_index)->base.y_pos - R50; } return jp; } @@ -790,7 +768,7 @@ const uint16 *MaridiaBeybladeTurtle_Instr_9412(uint16 k, const uint16 *jp) { // v4 = -1; E->mbte_var_E = v4; } - if ((Get_MaridiaBeybladeTurtle(cur_enemy_index)->mbte_var_E & 0x8000u) != 0) + if ((Get_MaridiaBeybladeTurtle(cur_enemy_index)->mbte_var_E & 0x8000) != 0) return INSTR_RETURN_ADDR(addr_kMaridiaBeybladeTurtle_Ilist_8B80); return INSTR_RETURN_ADDR(addr_kMaridiaBeybladeTurtle_Ilist_8C72); } @@ -818,7 +796,7 @@ const uint16 *MaridiaBeybladeTurtle_Instr_946B(uint16 k, const uint16 *jp) { // const uint16 *MaridiaBeybladeTurtle_Instr_9485(uint16 k, const uint16 *jp) { // 0xA29485 if (CheckIfEnemyTouchesSamus(cur_enemy_index)) { - if ((Get_MaridiaBeybladeTurtle(cur_enemy_index)->mbte_var_E & 0x8000u) == 0) + if ((Get_MaridiaBeybladeTurtle(cur_enemy_index)->mbte_var_E & 0x8000) == 0) return INSTR_RETURN_ADDR(addr_kMaridiaBeybladeTurtle_Ilist_8D40); else return INSTR_RETURN_ADDR(addr_kMaridiaBeybladeTurtle_Ilist_8C62); @@ -832,7 +810,7 @@ const uint16 *MaridiaBeybladeTurtle_Instr_94A1(uint16 k, const uint16 *jp) { // E->mbte_var_A = FUNC16(MiniMaridiaBeybladeTurtle_Func7); else E->mbte_var_A = FUNC16(MiniMaridiaBeybladeTurtle_Func1); - if ((E->mbte_var_E & 0x8000u) == 0) + if ((E->mbte_var_E & 0x8000) == 0) return INSTR_RETURN_ADDR(addr_kMaridiaBeybladeTurtle_Ilist_8C72); return INSTR_RETURN_ADDR(addr_kMaridiaBeybladeTurtle_Ilist_8B80); } @@ -844,7 +822,7 @@ const uint16 *MaridiaBeybladeTurtle_Instr_94C7(uint16 k, const uint16 *jp) { // } const uint16 *MaridiaBeybladeTurtle_Instr_94D1(uint16 k, const uint16 *jp) { // 0xA294D1 - QueueSfx2_Max6(0x3Au); + QueueSfx2_Max6(0x3A); return jp; } @@ -895,18 +873,18 @@ void TwinHoppingBlobs_Func2(void) { // 0xA29A9B void ThinHoppingBlobs_Func3(void) { // 0xA29AAA Enemy_ThinHoppingBlobs *E = Get_ThinHoppingBlobs(cur_enemy_index); E->thbs_var_02 = 1; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) E->thbs_var_02 = 0; if (E->thbs_var_04) E->thbs_var_02 = E->thbs_var_05; E->thbs_var_04 = 0; - ThinHoppingBlobs_Func4(); + uint16 R28 = ThinHoppingBlobs_Func4(); uint16 thbs_var_00 = E->thbs_var_00; if (sign16(thbs_var_00 - 3)) { if (!thbs_var_00) - R28_ &= 1u; - thbs_var_00 = R28_; - if (!sign16(R28_ - 2)) + R28 &= 1; + thbs_var_00 = R28; + if (!sign16(R28 - 2)) thbs_var_00 = 2; } uint16 v3 = 8 * thbs_var_00; @@ -914,35 +892,33 @@ void ThinHoppingBlobs_Func3(void) { // 0xA29AAA E->thbs_var_E = *(uint16 *)((uint8 *)&g_word_A29A0D + v3); } -void ThinHoppingBlobs_Func4(void) { // 0xA29B06 +uint16 ThinHoppingBlobs_Func4(void) { // 0xA29B06 NextRandom(); - R28_ = (Get_ThinHoppingBlobs(cur_enemy_index)->base.frame_counter + random_number) & 7; + return (Get_ThinHoppingBlobs(cur_enemy_index)->base.frame_counter + random_number) & 7; } void ThinHoppingBlobs_Func5(void) { // 0xA29B1A uint16 v2; Enemy_ThinHoppingBlobs *E = Get_ThinHoppingBlobs(cur_enemy_index); uint16 thbs_var_F = E->thbs_var_F; - R22_ = 0; - R24_ = 0; + uint16 r22 = 0; + uint16 r24 = 0; do { - R22_ += *(uint16 *)((uint8 *)&g_word_A29A09 + thbs_var_F); - R24_ += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic - + (uint16)(8 * (uint8)((uint16)(R22_ & 0xFF00) >> 8)) - + 1); + r22 += *(uint16 *)((uint8 *)&g_word_A29A09 + thbs_var_F); + r24 += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (8 * ((r22 & 0xFF00) >> 8)) + 1); thbs_var_F = E->thbs_var_F; v2 = swap16(*(uint16 *)((uint8 *)&g_word_A29A07 + thbs_var_F)); - } while (!sign16(v2 - R24_)); - E->thbs_var_B = R22_; + } while (!sign16(v2 - r24)); + E->thbs_var_B = r22; E->thbs_var_03 = 0; - uint16 v3 = R22_ >> 1; - E->thbs_var_07 = R22_ >> 1; + uint16 v3 = r22 >> 1; + E->thbs_var_07 = r22 >> 1; E->thbs_var_06 = E->thbs_var_07 + (v3 >> 1); } void ThinHoppingBlobs_Func6(uint16 k) { // 0xA29B65 Enemy_ThinHoppingBlobs *E = Get_ThinHoppingBlobs(k); - if ((--E->thbs_var_C & 0x8000u) != 0) { + if ((--E->thbs_var_C & 0x8000) != 0) { E->thbs_var_D = FUNC16(ThinHoppingBlobs_Func7); E->thbs_var_C = E->thbs_parameter_1; E->thbs_var_01 = 1; @@ -972,17 +948,14 @@ void ThinHoppingBlobs_Func8(void) { // 0xA29B88 uint16 thbs_var_B = E->thbs_var_B; if (!sign16(thbs_var_B - 0x4000)) thbs_var_B = 0x4000; - uint16 v6 = 8 * swap16(thbs_var_B); - if (E->thbs_var_03) - v6 -= 4; - int v7 = v6 >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v7 + 2]; - R20_ = kCommonEnemySpeeds_Quadratic[v7 + 3]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + uint16 v6 = 8 * (thbs_var_B >> 8); + if (!E->thbs_var_03) + v6 += 4; + if (Enemy_MoveDown(cur_enemy_index, kCommonEnemySpeeds_Quadratic32[v6 >> 2])) { if (E->thbs_var_03) { E->thbs_var_D = FUNC16(ThinHoppingBlobs_Func6); } else { - E->thbs_var_04 = *(VoidP *)((uint8 *)&R0_.addr + 1); + E->thbs_var_04 = 1; E->thbs_var_05 = E->thbs_var_02 ^ 1; E->thbs_var_00 = 4; E->thbs_var_E = FUNC16(ThinHoppingBlobs_Func15); @@ -1001,11 +974,10 @@ void ThinHoppingBlobs_Func8(void) { // 0xA29B88 E->thbs_var_03 = 1; E->thbs_var_B = 0; } - R20_ = (uint8)((uint16)(*(uint16 *)((uint8 *)&g_word_A29A09 + E->thbs_var_F) & 0xFF00) >> 8); - R18_ = 0; + uint16 R20 = (*(uint16 *)((uint8 *)&g_word_A29A09 + E->thbs_var_F) & 0xFF00) >> 8; if (E->thbs_var_02) - R20_ = -R20_; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + R20 = -R20; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(R20))) { E->thbs_var_04 = 1; E->thbs_var_05 = E->thbs_var_02 ^ 1; E->thbs_var_01 = 0; @@ -1112,11 +1084,11 @@ void ThinHoppingBlobs_Func14(void) { // 0xA29D6B void ThinHoppingBlobs_Func15(void) { // 0xA29D98 Enemy_ThinHoppingBlobs *E = Get_ThinHoppingBlobs(cur_enemy_index); uint16 thbs_var_F = E->thbs_var_F; - R20_ = (uint8)((uint16)(*(uint16 *)((uint8 *)&g_word_A29A0B + thbs_var_F) & 0xFF00) >> 8); - R18_ = *((uint8 *)&g_word_A29A0B + thbs_var_F) << 8; - if (Enemy_MoveDown(cur_enemy_index) & 1) { - ThinHoppingBlobs_Func4(); - E->thbs_var_00 = (R28_ & 1) + 5; + uint16 R20 = (*(uint16 *)((uint8 *)&g_word_A29A0B + thbs_var_F) & 0xFF00) >> 8; + uint16 R18 = *((uint8 *)&g_word_A29A0B + thbs_var_F) << 8; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(R20, R18))) { + uint16 R28 = ThinHoppingBlobs_Func4(); + E->thbs_var_00 = (R28 & 1) + 5; E->thbs_var_D = FUNC16(ThinHoppingBlobs_Func6); } } @@ -1134,7 +1106,7 @@ void ThinHoppingBlobs_Func16(void) { // 0xA29DCD } const uint16 *SpikeShootingPlant_Instr_9F2A(uint16 k, const uint16 *jp) { // 0xA29F2A - QueueSfx2_Max6(0x34u); + QueueSfx2_Max6(0x34); return jp; } @@ -1148,10 +1120,10 @@ void SpikeShootingPlant_Init(void) { // 0xA29F48 uint16 sspt_parameter_1_low = LOBYTE(E->sspt_parameter_1); E->sspt_var_E = sspt_parameter_1_low; E->sspt_var_F = g_off_A29F42[sspt_parameter_1_low]; - int v2 = (uint16)(2 * LOBYTE(E->sspt_parameter_2)) >> 1; + int v2 = LOBYTE(E->sspt_parameter_2); E->sspt_var_01 = g_word_A29F36[v2] + E->base.x_pos; E->sspt_var_00 = E->base.x_pos - g_word_A29F36[v2]; - int v3 = (uint16)(8 * HIBYTE(E->sspt_parameter_2)) >> 1; + int v3 = (8 * HIBYTE(E->sspt_parameter_2)) >> 1; E->sspt_var_B = kCommonEnemySpeeds_Linear[v3]; E->sspt_var_A = kCommonEnemySpeeds_Linear[v3 + 1]; E->sspt_var_D = kCommonEnemySpeeds_Linear[v3 + 2]; @@ -1266,12 +1238,12 @@ void MaridiaSpikeyShell_Init(void) { uint16 mssl_parameter_1_low = LOBYTE(E->mssl_parameter_1); E->mssl_var_E = mssl_parameter_1_low; off_A2A3D3[mssl_parameter_1_low & 1](); - int v3 = (uint16)(8 * LOBYTE(E->mssl_parameter_2)) >> 1; + int v3 = 4 * LOBYTE(E->mssl_parameter_2); E->mssl_var_B = kCommonEnemySpeeds_Linear[v3]; E->mssl_var_A = kCommonEnemySpeeds_Linear[v3 + 1]; E->mssl_var_D = kCommonEnemySpeeds_Linear[v3 + 2]; E->mssl_var_C = kCommonEnemySpeeds_Linear[v3 + 3]; - int v4 = (uint16)(2 * HIBYTE(E->mssl_parameter_2)) >> 1; + int v4 = HIBYTE(E->mssl_parameter_2); E->mssl_var_02 = g_word_A2A3DD[v4] + E->base.x_pos; E->mssl_var_01 = E->base.x_pos - g_word_A2A3DD[v4]; E->mssl_var_00 = g_word_A2A3ED[HIBYTE(E->mssl_parameter_1)]; @@ -1438,9 +1410,9 @@ void GunshipBottom_Init(void) { // 0xA2A6D2 void GunshipTop_Main(void) { // 0xA2A759 Enemy_GunshipTop *E1 = Get_GunshipTop(cur_enemy_index + 64); bool v2 = E1->gtp_var_D == 1; - bool v3 = (--E1->gtp_var_D & 0x8000u) != 0; + bool v3 = (--E1->gtp_var_D & 0x8000) != 0; if (v2 || v3) { - QueueSfx2_Max6(0x4Du); + QueueSfx2_Max6(0x4D); E1->gtp_var_D = 70; } Enemy_GunshipTop *E0 = Get_GunshipTop(cur_enemy_index); @@ -1452,18 +1424,17 @@ void GunshipTop_Main(void) { // 0xA2A759 void GunshipTop_1(uint16 k) { // 0xA2A784 Enemy_GunshipTop *E0 = Get_GunshipTop(k); bool v3 = E0->gtp_var_D == 1; - bool v4 = (--E0->gtp_var_D & 0x8000u) != 0; + bool v4 = (--E0->gtp_var_D & 0x8000) != 0; if (v3 || v4) { uint16 v5 = 2 * E0->gtp_var_C; E0->gtp_var_D = g_byte_A2A7CF[v5]; uint16 v6 = (int8)g_byte_A2A7CF[v5 + 1]; - R18_ = v6; E0->base.y_pos += v6; Enemy_GunshipTop *E1 = Get_GunshipTop(k + 64); E1->base.y_pos += v6; Enemy_GunshipTop *E2 = Get_GunshipTop(k + 128); E2->base.y_pos += v6; - E0->gtp_var_C = ((uint8)E0->gtp_var_C + 1) & 3; + E0->gtp_var_C = (E0->gtp_var_C + 1) & 3; } } @@ -1538,7 +1509,7 @@ void GunshipTop_4(uint16 k) { // 0xA2A8D0 uint16 v5; Enemy_GunshipTop *GunshipTop = Get_GunshipTop(k); - v2 = (uint16)(2 * GunshipTop->gtp_var_E) >> 1; + v2 = GunshipTop->gtp_var_E; samus_y_pos += g_word_A2A622[v2]; Enemy_GunshipTop *v3 = Get_GunshipTop(k + 128); v3->base.y_pos += g_word_A2A622[v2]; @@ -1559,41 +1530,41 @@ void GunshipTop_4(uint16 k) { // 0xA2A8D0 v7->base.instruction_timer = 1; v7->base.current_instruction = addr_kGunshipTop_Ilist_A5BE; v6->gtp_var_A = 144; - QueueSfx3_Max6(0x14u); + QueueSfx3_Max6(0x14); } } void GunshipTop_5(uint16 k) { // 0xA2A942 Enemy_GunshipTop *E = Get_GunshipTop(0); bool v2 = E->gtp_var_A == 1; - bool v3 = (--E->gtp_var_A & 0x8000u) != 0; + bool v3 = (--E->gtp_var_A & 0x8000) != 0; if (v2 || v3) Get_GunshipTop(k)->gtp_var_F = FUNC16(GunshipTop_6); } void GunshipTop_6(uint16 k) { // 0xA2A950 Enemy_GunshipTop *E = Get_GunshipTop(k); - R18_ = E->gtp_var_E - 30; - if (sign16(--samus_y_pos - R18_)) { + uint16 r18 = E->gtp_var_E - 30; + if (sign16(--samus_y_pos - r18)) { E->gtp_var_F = FUNC16(GunshipTop_7); Enemy_GunshipTop *E2 = Get_GunshipTop(k + 128); E2->base.instruction_timer = 1; E2->base.current_instruction = addr_kGunshipTop_Ilist_A5EE; Get_GunshipTop(0)->gtp_var_A = 144; - QueueSfx3_Max6(0x15u); + QueueSfx3_Max6(0x15); } } void GunshipTop_7(uint16 k) { // 0xA2A987 Enemy_GunshipTop *E = Get_GunshipTop(0); bool v2 = E->gtp_var_A == 1; - bool v3 = (--E->gtp_var_A & 0x8000u) != 0; + bool v3 = (--E->gtp_var_A & 0x8000) != 0; if (v2 || v3) { Get_GunshipTop(k)->gtp_var_F = FUNC16(GunshipTop_8); frame_handler_alfa = FUNC16(Samus_FrameHandlerAlfa_Func11); frame_handler_beta = FUNC16(Samus_FrameHandlerBeta_Func17); loading_game_state = kLoadingGameState_5_Main; - *(uint16 *)used_save_stations_and_elevators |= 1u; + *(uint16 *)used_save_stations_and_elevators |= 1; load_station_index = 0; SaveToSram(selected_save_slot); } @@ -1614,7 +1585,7 @@ void GunshipTop_8(uint16 k) { // 0xA2A9BD samus_prev_x_pos = samus_x_pos; } MakeSamusFaceForward(); - CallSomeSamusCode(0x1Au); + CallSomeSamusCode(0x1A); elevator_status = 0; uint16 v3 = E->base.y_pos - 1; Enemy_GunshipTop *E2 = Get_GunshipTop(k + 128); @@ -1622,7 +1593,7 @@ void GunshipTop_8(uint16 k) { // 0xA2A9BD E2->base.instruction_timer = 1; E2->base.current_instruction = addr_kGunshipTop_Ilist_A5BE; Get_GunshipTop(0)->gtp_var_A = 144; - QueueSfx3_Max6(0x14u); + QueueSfx3_Max6(0x14); } } } @@ -1630,35 +1601,35 @@ void GunshipTop_8(uint16 k) { // 0xA2A9BD void GunshipTop_9(uint16 k) { // 0xA2AA4F Enemy_GunshipTop *E = Get_GunshipTop(0); bool v2 = E->gtp_var_A == 1; - bool v3 = (--E->gtp_var_A & 0x8000u) != 0; + bool v3 = (--E->gtp_var_A & 0x8000) != 0; if (v2 || v3) Get_GunshipTop(k)->gtp_var_F = FUNC16(GunshipTop_10); } void GunshipTop_10(uint16 k) { // 0xA2AA5D Enemy_GunshipTop *E = Get_GunshipTop(k); - R18_ = E->gtp_var_E + 18; + uint16 r18 = E->gtp_var_E + 18; samus_y_pos += 2; - if (!sign16(samus_y_pos - R18_)) { + if (!sign16(samus_y_pos - r18)) { E->gtp_var_F = FUNC16(GunshipTop_11); Enemy_GunshipTop *E2 = Get_GunshipTop(k + 128); E2->base.instruction_timer = 1; E2->base.current_instruction = addr_kGunshipTop_Ilist_A5EE; Get_GunshipTop(0)->gtp_var_A = 144; - QueueSfx3_Max6(0x15u); + QueueSfx3_Max6(0x15); } } void GunshipTop_11(uint16 k) { // 0xA2AA94 Enemy_GunshipTop *E = Get_GunshipTop(0); bool v2 = E->gtp_var_A == 1; - bool v3 = (--E->gtp_var_A & 0x8000u) != 0; + bool v3 = (--E->gtp_var_A & 0x8000) != 0; if (v2 || v3) Get_GunshipTop(k)->gtp_var_F = FUNC16(GunshipTop_12); } void GunshipTop_12(uint16 k) { // 0xA2AAA2 - if (CheckEventHappened(0xEu)) { + if (CheckEventHappened(0xE)) { Get_GunshipTop(k)->gtp_var_F = FUNC16(GunshipTop_17); Enemy_GunshipTop *E = Get_GunshipTop(k + 64); E->gtp_var_F = 0; @@ -1667,12 +1638,12 @@ void GunshipTop_12(uint16 k) { // 0xA2AAA2 suit_pickup_light_beam_pos = 0; *(uint16 *)&suit_pickup_color_math_R = 0; *(uint16 *)&suit_pickup_color_math_B = 0; - CallSomeSamusCode(0xAu); + CallSomeSamusCode(0xA); } else { - Samus_RestoreHealth(2u); - Samus_RestoreMissiles(2u); - Samus_RestoreSuperMissiles(2u); - Samus_RestorePowerBombs(2u); + Samus_RestoreHealth(2); + Samus_RestoreMissiles(2); + Samus_RestoreSuperMissiles(2); + Samus_RestorePowerBombs(2); if ((int16)(samus_reserve_health - samus_max_reserve_health) >= 0 && (int16)(samus_health - samus_max_health) >= 0 && (int16)(samus_missiles - samus_max_missiles) >= 0 @@ -1690,7 +1661,7 @@ void GunshipTop_13(uint16 k) { // 0xA2AB1F return; if (rv != 2) { - *(uint16 *)used_save_stations_and_elevators |= 1u; + *(uint16 *)used_save_stations_and_elevators |= 1; load_station_index = 0; SaveToSram(selected_save_slot); } @@ -1699,35 +1670,35 @@ void GunshipTop_13(uint16 k) { // 0xA2AB1F E->base.instruction_timer = 1; E->base.current_instruction = addr_kGunshipTop_Ilist_A5BE; Get_GunshipTop(0)->gtp_var_A = 144; - QueueSfx3_Max6(0x14u); + QueueSfx3_Max6(0x14); } void GunshipTop_14(uint16 k) { // 0xA2AB60 Enemy_GunshipTop *E = Get_GunshipTop(0); bool v2 = E->gtp_var_A == 1; - bool v3 = (--E->gtp_var_A & 0x8000u) != 0; + bool v3 = (--E->gtp_var_A & 0x8000) != 0; if (v2 || v3) Get_GunshipTop(k)->gtp_var_F = FUNC16(GunshipTop_15); } void GunshipTop_15(uint16 k) { // 0xA2AB6E Enemy_GunshipTop *E = Get_GunshipTop(k); - R18_ = E->gtp_var_E - 30; + uint16 r18 = E->gtp_var_E - 30; samus_y_pos -= 2; - if (sign16(samus_y_pos - R18_)) { + if (sign16(samus_y_pos - r18)) { E->gtp_var_F = FUNC16(GunshipTop_16); Enemy_GunshipTop *E2 = Get_GunshipTop(k + 128); E2->base.instruction_timer = 1; E2->base.current_instruction = addr_kGunshipTop_Ilist_A5EE; Get_GunshipTop(0)->gtp_var_A = 144; - QueueSfx3_Max6(0x15u); + QueueSfx3_Max6(0x15); } } void GunshipTop_16(uint16 k) { // 0xA2ABA5 Enemy_GunshipTop *E = Get_GunshipTop(0); bool v2 = E->gtp_var_A == 1; - bool v3 = (--E->gtp_var_A & 0x8000u) != 0; + bool v3 = (--E->gtp_var_A & 0x8000) != 0; if (v2 || v3) { Get_GunshipTop(k)->gtp_var_F = FUNC16(GunshipTop_8); if (sign16(game_state - kGameState_40_TransitionToDemo)) { @@ -1787,10 +1758,10 @@ void GunshipTop_18(uint16 k) { // 0xA2AC1B if (sign16(v7 - 128)) { if (v7 == 64) { SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 0); - SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 2u); - SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 4u); - SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 6u); - SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 8u); + SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 2); + SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 4); + SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 6); + SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 8); SpawnEnemyProjectileWithRoomGfx(addr_stru_86A379, 0xA); } } else { @@ -1832,13 +1803,10 @@ void GunshipTop_21(uint16 k) { // 0xA2AD2D E->gtp_var_F = v3; if (!sign16((v3 & 0xFF00) - 2560)) E->gtp_var_F = 2304; - R20_ = E->gtp_var_F << 8; - R18_ = E->gtp_var_F >> 8; - uint32 v6 = __PAIR32__(samus_y_pos, samus_y_subpos) - __PAIR32__(R18_, R20_); - uint16 v5 = (__PAIR32__(samus_y_pos, samus_y_subpos) - __PAIR32__(R18_, R20_)) >> 16; + uint32 v6 = __PAIR32__(samus_y_pos, samus_y_subpos) - __PAIR32__(E->gtp_var_F >> 8, E->gtp_var_F << 8); samus_y_subpos = v6; - samus_y_pos = v5; - v5 -= 17; + samus_y_pos = v6 >> 16; + uint16 v5 = samus_y_pos - 17; Get_GunshipTop(k)->base.y_pos = v5; Get_GunshipTop(k + 128)->base.y_pos = v5 - 1; E->base.y_pos = samus_y_pos + 23; @@ -1886,7 +1854,7 @@ void Flies_Main(void) { // 0xA2B11F } void Flies_3(uint16 k) { // 0xA2B129 - int v1 = (uint16)(2 * CalculateAngleOfSamusFromEnemy(k)) >> 1; + int v1 = CalculateAngleOfSamusFromEnemy(k); Enemy_Flies *E = Get_Flies(k); E->flies_var_B = 2 * kSinCosTable8bit_Sext[v1 + 64]; E->flies_var_C = 4 * kSinCosTable8bit_Sext[v1]; @@ -1930,7 +1898,7 @@ void Flies_6(uint16 k) { // 0xA2B1AA uint16 v1 = Flies_2(k); Enemy_Flies *E = Get_Flies(k); ++E->flies_var_A; - if ((E->flies_var_C & 0x8000u) == 0) { + if ((E->flies_var_C & 0x8000) == 0) { if (v1 < E->flies_var_D) return; goto LABEL_5; @@ -1945,7 +1913,7 @@ LABEL_5: void Flies_7(uint16 k) { // 0xA2B1D2 Flies_2(k); Enemy_Flies *E = Get_Flies(k); - if ((--E->flies_var_A & 0x8000u) != 0) { + if ((--E->flies_var_A & 0x8000) != 0) { E->flies_var_A = 24; E->flies_var_F = FUNC16(Flies_4); } @@ -1953,42 +1921,34 @@ void Flies_7(uint16 k) { // 0xA2B1D2 void NorfairErraticFireball_Init(void) { // 0xA2B3E0 Enemy_NorfairErraticFireball *E = Get_NorfairErraticFireball(cur_enemy_index); - R18_ = E->nefl_parameter_1; - R20_ = LOBYTE(E->nefl_parameter_2); - ConvertAngleToXy(); - E->nefl_var_C = R22_; - E->nefl_var_D = R24_; - E->nefl_var_E = R26_; - E->nefl_var_F = R28_; + Point32 pt = ConvertAngleToXy(E->nefl_parameter_1, LOBYTE(E->nefl_parameter_2)); + E->nefl_var_C = pt.x >> 16; + E->nefl_var_D = pt.x; + E->nefl_var_E = pt.y >> 16; + E->nefl_var_F = pt.y; E->base.current_instruction = addr_kNorfairErraticFireball_Ilist_B2DC; } void NorfairErraticFireball_Main(void) { // 0xA2B40F Enemy_NorfairErraticFireball *E = Get_NorfairErraticFireball(cur_enemy_index); - R18_ = E->nefl_parameter_1; - R20_ = LOBYTE(E->nefl_parameter_2); - ConvertAngleToXy(); - E->nefl_var_C = R22_; - E->nefl_var_D = R24_; - E->nefl_var_E = R26_; - E->nefl_var_F = R28_; + Point32 pt = ConvertAngleToXy(E->nefl_parameter_1, LOBYTE(E->nefl_parameter_2)); + E->nefl_var_C = pt.x >> 16; + E->nefl_var_D = pt.x; + E->nefl_var_E = pt.y >> 16; + E->nefl_var_F = pt.y; if (((E->nefl_parameter_1 + 64) & 0x80) == 0) { E->nefl_var_C = ~E->nefl_var_C; E->nefl_var_D = -E->nefl_var_D; } - R20_ = E->nefl_var_C; - R18_ = E->nefl_var_D; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->nefl_parameter_1 ^= 0x40u; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->nefl_var_C, E->nefl_var_D))) { + E->nefl_parameter_1 ^= 0x40; } else { if (((E->nefl_parameter_1 + 128) & 0x80) == 0) { E->nefl_var_E = ~E->nefl_var_E; E->nefl_var_F = -E->nefl_var_F; } - R20_ = E->nefl_var_E; - R18_ = E->nefl_var_F; - if (Enemy_MoveDown(cur_enemy_index) & 1) - E->nefl_parameter_1 ^= 0xC0u; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(E->nefl_var_E, E->nefl_var_F))) + E->nefl_parameter_1 ^= 0xC0; } } @@ -2023,8 +1983,8 @@ void LavaquakeRocks_1(void) { // 0xA2B596 } void LavaquakeRocks_2(void) { // 0xA2B5B2 - enemy_projectile_unk1995 = g_word_A2B550[(uint8)(NextRandom() & 0x1E) >> 1]; - int v1 = (uint8)(NextRandom() & 0x1E) >> 1; + enemy_projectile_unk1995 = g_word_A2B550[(NextRandom() & 0x1E) >> 1]; + int v1 = (NextRandom() & 0x1E) >> 1; SpawnEnemyProjectileWithGfx(g_word_A2B530[v1], cur_enemy_index, addr_stru_86BD5A); Enemy_LavaquakeRocks *E = Get_LavaquakeRocks(cur_enemy_index); E->lrs_var_A = FUNC16(LavaquakeRocks_3); @@ -2033,7 +1993,7 @@ void LavaquakeRocks_2(void) { // 0xA2B5B2 void LavaquakeRocks_3(void) { // 0xA2B5EA Enemy_LavaquakeRocks *E = Get_LavaquakeRocks(cur_enemy_index); - if ((--E->lrs_var_B & 0x8000u) != 0) + if ((--E->lrs_var_B & 0x8000) != 0) E->lrs_var_A = FUNC16(LavaquakeRocks_1); } @@ -2083,32 +2043,23 @@ void Rinka_Init3(uint16 k) { // 0xA2B654 } void Rinka_1(uint16 k) { // 0xA2B69B - EnemySpawnData *v1; uint16 v2; - EnemySpawnData *v6; - EnemySpawnData *v13; - - v1 = gEnemySpawnData(k); - R18_ = v1->x_pos; - R20_ = v1->y_pos; - if (Rinka_10() || (v2 = Rinka_2(k), gRam8000_Default(v2)[31].var_3F & 1)) { + EnemySpawnData *ES = gEnemySpawnData(k); + if (Rinka_10(ES->x_pos, ES->y_pos) || (v2 = Rinka_2(k), gRam8000_Default(v2)[31].var_3F & 1)) { uint16 v3 = 0; do { int v4 = v3 >> 1; - R18_ = g_word_A2B75B[v4]; - R20_ = g_word_A2B75B[v4 + 1]; - if (!(Rinka_10() & 1) && !(gRam8000_Default(g_word_A2B75B[v4 + 2])[31].var_3F & 1)) { - uint16 v5 = R18_; - v6 = gEnemySpawnData(k); - v6->x_pos = R18_; + uint16 x = g_word_A2B75B[v4]; + uint16 y = g_word_A2B75B[v4 + 1]; + if (!Rinka_10(x, y) && !(gRam8000_Default(g_word_A2B75B[v4 + 2])[31].var_3F & 1)) { Enemy_Rinka *E = Get_Rinka(k); - E->base.x_pos = v5; - uint16 v8 = R20_; - v6->y_pos = R20_; - E->base.y_pos = v8; + ES->x_pos = x; + E->base.x_pos = x; + ES->y_pos = y; + E->base.y_pos = y; uint16 v9 = g_word_A2B75B[(v3 >> 1) + 2]; gRam8000_Default(v9)[31].var_3F = -1; - Get_Rinka(k)->rinka_var_D = v9; + E->rinka_var_D = v9; return; } v3 += 6; @@ -2121,12 +2072,11 @@ void Rinka_1(uint16 k) { // 0xA2B69B } int v11 = v10 >> 1; uint16 v12 = g_word_A2B75B[v11]; - v13 = gEnemySpawnData(k); - v13->x_pos = v12; + ES->x_pos = v12; Enemy_Rinka *E = Get_Rinka(k); E->base.x_pos = v12; uint16 v15 = g_word_A2B75B[v11 + 1]; - v13->y_pos = v15; + ES->y_pos = v15; E->base.y_pos = v15; uint16 v16 = g_word_A2B75B[v11 + 2]; E->rinka_var_D = v16; @@ -2182,7 +2132,7 @@ void Rinka_Main(void) { // 0xA2B7C4 void Rinka_3(uint16 k) { // 0xA2B7DF Enemy_Rinka *E = Get_Rinka(k); - if ((--E->rinka_var_F & 0x8000u) != 0) { + if ((--E->rinka_var_F & 0x8000) != 0) { E->rinka_var_A = FUNC16(Rinka_B85B); uint16 v3; if (E->rinka_parameter_1) @@ -2190,19 +2140,15 @@ void Rinka_3(uint16 k) { // 0xA2B7DF else v3 = E->base.properties & 0xF3FF | 0x800; E->base.properties = v3; - R18_ = samus_x_pos - E->base.x_pos; - R20_ = samus_y_pos - E->base.y_pos; - R18_ = (uint8)-(int8)(CalculateAngleFromXY() + 0x80); - uint16 v4 = Math_MultBySin(0x120u); - Get_Rinka(cur_enemy_index)->rinka_var_B = v4; - uint16 v5 = Math_MultByCos(0x120u); - Get_Rinka(cur_enemy_index)->rinka_var_C = v5; + uint16 r18 = (uint8)-(CalculateAngleFromXY(samus_x_pos - E->base.x_pos, samus_y_pos - E->base.y_pos) + 0x80); + E->rinka_var_B = Math_MultBySin(0x120, r18); + E->rinka_var_C = Math_MultByCos(0x120, r18); } } void Rinka_4(uint16 k) { // 0xA2B844 Enemy_Rinka *E = Get_Rinka(k); - if ((--E->rinka_var_F & 0x8000u) != 0) { + if ((--E->rinka_var_F & 0x8000) != 0) { E->base.health = 10; Rinka_Init2(k); } @@ -2244,7 +2190,7 @@ void Rinka_6(uint16 k) { // 0xA2B880 void Rinka_7(uint16 k) { // 0xA2B89C Enemy_Rinka *E = Get_Rinka(k); - if ((enemy_damage_routine_exec_count & 3) == E->rinka_parameter_1) + if ((random_enemy_counter & 3) == E->rinka_parameter_1) E->base.properties &= ~kEnemyProps_Tangible; else E->base.properties |= kEnemyProps_Tangible; @@ -2256,7 +2202,7 @@ void Rinka_8(uint16 k) { // 0xA2B8BB uint16 rinka_var_D = E->rinka_var_D; if (rinka_var_D) { gRam8000_Default(rinka_var_D)[31].var_3F = 0; - Get_Rinka(k)->rinka_var_D = 0; + E->rinka_var_D = 0; } } } @@ -2288,13 +2234,9 @@ uint8 Rinka_9(uint16 k) { // 0xA2B8D3 return result; } -uint8 Rinka_10(void) { // 0xA2B8FF - return (R20_ & 0x8000u) != 0 - || (int16)(R20_ - layer1_y_pos) < 0 - || !sign16(R20_ - layer1_y_pos - 224) - || (R18_ & 0x8000u) != 0 - || (int16)(R18_ - layer1_x_pos) < 0 - || !sign16(R18_ - layer1_x_pos - 256); +bool Rinka_10(uint16 r18, uint16 r20) { // 0xA2B8FF + return (r20 & 0x8000) != 0 || (int16)(r20 - layer1_y_pos) < 0 || !sign16(r20 - layer1_y_pos - 224) + || (r20 & 0x8000) != 0 || (int16)(r18 - layer1_x_pos) < 0 || !sign16(r18 - layer1_x_pos - 256); } void Rinka_Frozen(uint16 k) { // 0xA2B929 @@ -2334,9 +2276,8 @@ void Rinka_B960(uint16 k) { // 0xA2B960 Rinka_8(k); if (E->rinka_parameter_1) { E->base.properties |= kEnemyProps_Tangible | kEnemyProps_Invisible; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - SpawnEnemyProjectileWithRoomGfx(0xE509, 3u); + eproj_spawn_pt = (Point16U){ E->base.x_pos, E->base.y_pos }; + SpawnEnemyProjectileWithRoomGfx(0xE509, 3); E->rinka_var_A = FUNC16(Rinka_4); E->rinka_var_F = 1; } else { @@ -2415,7 +2356,7 @@ void Rio_1(uint16 k) { // 0xA2BBED Rio_6(addr_kRio_Ilist_BB7F); E->rio_var_B = FUNC16(Rio_3); if (!CheckIfEnemyIsOnScreen()) - QueueSfx2_Max6(0x65u); + QueueSfx2_Max6(0x65); } } @@ -2429,31 +2370,18 @@ void Rio_2(uint16 k) { // 0xA2BC32 } void Rio_3(uint16 k) { // 0xA2BC48 - int16 rio_var_D; - int16 rio_var_C; int16 v4; - R18_ = 0; - R20_ = 0; Enemy_Rio *E = Get_Rio(k); - rio_var_D = E->rio_var_D; - if (rio_var_D < 0) - --R20_; - R19_ = rio_var_D; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + ; + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->rio_var_D))) { E->rio_var_D = -E->rio_var_D; LABEL_13: E->rio_var_C = -E->rio_var_C; E->rio_var_B = FUNC16(Rio_4); return; } - R18_ = 0; - R20_ = 0; - rio_var_C = E->rio_var_C; - if (rio_var_C < 0) - --R20_; - R19_ = rio_var_C; - if (Enemy_MoveDown(k) & 1) + if (Enemy_MoveDown(k, INT16_SHL8(E->rio_var_C))) goto LABEL_13; v4 = E->rio_var_C - 24; E->rio_var_C = v4; @@ -2469,25 +2397,10 @@ LABEL_13: } void Rio_4(uint16 k) { // 0xA2BCB7 - int16 rio_var_D; - int16 rio_var_C; - - R18_ = 0; - R20_ = 0; Enemy_Rio *E = Get_Rio(k); - rio_var_D = E->rio_var_D; - if (rio_var_D < 0) - --R20_; - R19_ = rio_var_D; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->rio_var_D))) E->rio_var_D = -E->rio_var_D; - R18_ = 0; - R20_ = 0; - rio_var_C = E->rio_var_C; - if (rio_var_C < 0) - --R20_; - R19_ = rio_var_C; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, INT16_SHL8(E->rio_var_C))) { Rio_6(addr_kRio_Ilist_BBA3); E->rio_var_B = FUNC16(Rio_2); } else { @@ -2496,31 +2409,17 @@ void Rio_4(uint16 k) { // 0xA2BCB7 } void Rio_5(uint16 k) { // 0xA2BCFF - int16 rio_var_D; - int16 rio_var_C; Enemy_Rio *E = Get_Rio(k); if ((int16)(Get_Rio(k)->base.y_pos - samus_y_pos) >= 0) { E->rio_var_D = E->rio_var_A; E->rio_var_C = -1; E->rio_var_B = FUNC16(Rio_4); } else { - int v1 = (uint16)(2 * CalculateAngleOfSamusFromEnemy(k)) >> 1; + int v1 = CalculateAngleOfSamusFromEnemy(k); E->rio_var_D = kSinCosTable8bit_Sext[v1 + 64]; E->rio_var_C = kSinCosTable8bit_Sext[v1]; - R18_ = 0; - R20_ = 0; - rio_var_D = E->rio_var_D; - if (rio_var_D < 0) - --R20_; - R19_ = rio_var_D; - Enemy_MoveRight_IgnoreSlopes(k); - R18_ = 0; - R20_ = 0; - rio_var_C = E->rio_var_C; - if (rio_var_C < 0) - --R20_; - R19_ = rio_var_C; - Enemy_MoveDown(k); + Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->rio_var_D)); + Enemy_MoveDown(k, INT16_SHL8(E->rio_var_C)); } } @@ -2543,7 +2442,7 @@ void NorfairLavajumpingEnemy_Init(void) { // 0xA2BE99 Enemy_NorfairLavajumpingEnemy *E = Get_NorfairLavajumpingEnemy(cur_enemy_index); E->nley_var_00 = 0; E->nley_var_01 = 0; - if ((E->nley_parameter_1 & 0x8000u) != 0) { + if ((E->nley_parameter_1 & 0x8000) != 0) { E->base.current_instruction = addr_kNorfairLavajumpingEnemy_Ilist_BE62; E->nley_var_F = FUNC16(NorfairLavajumpingEnemy_Func_1); } else { @@ -2566,7 +2465,7 @@ void NorfairLavajumpingEnemy_Func_1(uint16 k) { // 0xA2BEDC if (enemy_drawing_queue[v1 + 100]) { uint16 v3 = enemy_drawing_queue[v1 + 109]; E->base.frozen_timer = v3; - if (v3 || (enemy_drawing_queue_sizes[v1 + 2] & 0x8000u) == 0) { + if (v3 || (enemy_drawing_queue_sizes[v1 + 2] & 0x8000) == 0) { E->base.properties |= kEnemyProps_Invisible; } else { E->base.properties &= ~kEnemyProps_Invisible; @@ -2582,7 +2481,7 @@ void NorfairLavajumpingEnemy_Func_2(uint16 k) { // 0xA2BF1A E->nley_var_C = g_word_A2BE86[(uint16)(HIBYTE(random_number) & 6) >> 1]; E->nley_var_F = FUNC16(NorfairLavajumpingEnemy_Func_3); E->base.properties |= kEnemyProps_ProcessedOffscreen; - QueueSfx2_Max6(0xDu); + QueueSfx2_Max6(0xD); } void NorfairLavajumpingEnemy_Func_3(uint16 k) { // 0xA2BF3E @@ -2592,7 +2491,7 @@ void NorfairLavajumpingEnemy_Func_3(uint16 k) { // 0xA2BF3E E->base.y_pos += (int8)HIBYTE(E->nley_var_C) + (t >> 16); uint16 v3 = E->nley_var_C + 56; E->nley_var_C = v3; - if (v3 >= 0xFC00u) { + if (v3 >= 0xFC00) { NorfairLavajumpingEnemy_Func_6(addr_kNorfairLavajumpingEnemy_Ilist_BE42); E->nley_var_F = FUNC16(NorfairLavajumpingEnemy_Func_4); } @@ -2695,7 +2594,7 @@ void NorfairRio_Init(void) { // 0xA2C242 Enemy_NorfairRio *E = Get_NorfairRio(cur_enemy_index); E->nro_var_01 = 0; E->nro_var_02 = 0; - if ((E->nro_parameter_1 & 0x8000u) != 0) { + if ((E->nro_parameter_1 & 0x8000) != 0) { E->nro_var_00 = addr_kNorfairRio_Ilist_C18F; E->base.current_instruction = addr_kNorfairRio_Ilist_C18F; E->nro_var_F = FUNC16(NorfairRio_Func_1); @@ -2725,11 +2624,11 @@ void NorfairRio_Func_1(uint16 k) { // 0xA2C281 gEnemySpawnData(k)[31].some_flag == addr_kNorfairRio_Ilist_C0F1)) { E->base.properties |= kEnemyProps_Invisible; } else { - R18_ = addr_kNorfairRio_Ilist_C18F; + uint16 r18 = addr_kNorfairRio_Ilist_C18F; v6 = gEnemySpawnData(k); - if ((v6[31].field_4 & 0x8000u) != 0) - R18_ = addr_kNorfairRio_Ilist_C1A3; - NorfairRio_Func_7(R18_); + if ((v6[31].field_4 & 0x8000) != 0) + r18 = addr_kNorfairRio_Ilist_C1A3; + NorfairRio_Func_7(r18); E->base.properties &= ~kEnemyProps_Invisible; E->base.x_pos = enemy_drawing_queue[v1 + 91]; E->base.y_pos = v6[31].field_4 + enemy_drawing_queue[v1 + 93]; @@ -2762,31 +2661,17 @@ void NorfairRio_Func_3(uint16 k) { // 0xA2C33F E->nro_var_01 = 0; NorfairRio_Func_7(addr_kNorfairRio_Ilist_C12F); E->nro_var_F = FUNC16(NorfairRio_Func_4); - QueueSfx2_Max6(0x65u); + QueueSfx2_Max6(0x65); } } void NorfairRio_Func_4(uint16 k) { // 0xA2C361 - int16 nro_var_B; - int16 nro_var_A; int16 v4; - R18_ = 0; - R20_ = 0; Enemy_NorfairRio *E = Get_NorfairRio(k); - nro_var_B = E->nro_var_B; - if (nro_var_B < 0) - --R20_; - R19_ = nro_var_B; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->nro_var_B))) E->nro_var_B = -E->nro_var_B; - R18_ = 0; - R20_ = 0; - nro_var_A = E->nro_var_A; - if (nro_var_A < 0) - --R20_; - R19_ = nro_var_A; - if (Enemy_MoveDown(k) & 1 || (v4 = E->nro_var_A - 32, E->nro_var_A = v4, v4 < 0)) { + if (Enemy_MoveDown(k, INT16_SHL8(E->nro_var_A)) || (v4 = E->nro_var_A - 32, E->nro_var_A = v4, v4 < 0)) { E->nro_var_A = -1; NorfairRio_Func_7(addr_kNorfairRio_Ilist_C145); E->nro_var_F = FUNC16(NorfairRio_Func_5); @@ -2794,25 +2679,10 @@ void NorfairRio_Func_4(uint16 k) { // 0xA2C361 } void NorfairRio_Func_5(uint16 k) { // 0xA2C3B1 - int16 nro_var_B; - int16 nro_var_A; - - R18_ = 0; - R20_ = 0; Enemy_NorfairRio *E = Get_NorfairRio(k); - nro_var_B = E->nro_var_B; - if (nro_var_B < 0) - --R20_; - R19_ = nro_var_B; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->nro_var_B))) E->nro_var_B = -E->nro_var_B; - R18_ = 0; - R20_ = 0; - nro_var_A = E->nro_var_A; - if (nro_var_A < 0) - --R20_; - R19_ = nro_var_A; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, INT16_SHL8(E->nro_var_A))) { E->nro_var_F = FUNC16(NorfairRio_Func_6); } else { E->nro_var_A -= 32; @@ -2855,7 +2725,7 @@ const uint16 *LowerNorfairRio_Instr_C6E8(uint16 k, const uint16 *jp) { // 0xA2C void LowerNorfairRio_Init(void) { // 0xA2C6F3 Enemy_NorfairRio *E = Get_NorfairRio(cur_enemy_index); E->nro_var_01 = 0; - if ((E->nro_parameter_1 & 0x8000u) == 0) { + if ((E->nro_parameter_1 & 0x8000) == 0) { E->nro_var_F = FUNC16(LowerNorfairRio_Func_2); E->nro_var_00 = addr_kLowerNorfairRio_Ilist_C61A; E->base.current_instruction = addr_kLowerNorfairRio_Ilist_C61A; @@ -2916,53 +2786,24 @@ void LowerNorfairRio_Func_3(uint16 k) { // 0xA2C7BB } void LowerNorfairRio_Func_4(uint16 k) { // 0xA2C7D6 - int16 lnro_var_D; - int16 lnro_var_C; int16 v4; - R18_ = 0; - R20_ = 0; Enemy_LowerNorfairRio *E = Get_LowerNorfairRio(k); - lnro_var_D = E->lnro_var_D; - if (lnro_var_D < 0) - --R20_; - R19_ = lnro_var_D; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->lnro_var_D))) E->lnro_var_D = -E->lnro_var_D; - R18_ = 0; - R20_ = 0; - lnro_var_C = E->lnro_var_C; - if (lnro_var_C < 0) - --R20_; - R19_ = lnro_var_C; - if (Enemy_MoveDown(k) & 1 || (v4 = E->lnro_var_C - 32, E->lnro_var_C = v4, v4 < 0)) { + if (Enemy_MoveDown(k, INT16_SHL8(E->lnro_var_C)) || (v4 = E->lnro_var_C - 32, E->lnro_var_C = v4, v4 < 0)) { E->lnro_var_C = -1; LowerNorfairRio_Func_7(addr_kLowerNorfairRio_Ilist_C662); E->lnro_var_F = FUNC16(LowerNorfairRio_Func_5); - QueueSfx2_Max6(0x64u); + QueueSfx2_Max6(0x64); } } void LowerNorfairRio_Func_5(uint16 k) { // 0xA2C82D - int16 nro_var_D; - int16 nro_var_C; - - R18_ = 0; - R20_ = 0; Enemy_NorfairRio *E = Get_NorfairRio(k); - nro_var_D = E->nro_var_D; - if (nro_var_D < 0) - --R20_; - R19_ = nro_var_D; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->nro_var_D))) E->nro_var_D = -E->nro_var_D; - R18_ = 0; - R20_ = 0; - nro_var_C = E->nro_var_C; - if (nro_var_C < 0) - --R20_; - R19_ = nro_var_C; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, INT16_SHL8(E->nro_var_C))) { LowerNorfairRio_Func_7(addr_kLowerNorfairRio_Ilist_C686); E->nro_var_F = FUNC16(LowerNorfairRio_Func_6); } else { @@ -2994,7 +2835,7 @@ void LowerNorfairRio_Func_7(uint16 a) { // 0xA2C8A3 } const uint16 *MaridiaLargeSnail_Instr_CB6B(uint16 k, const uint16 *jp) { // 0xA2CB6B - QueueSfx2_Max6(0xEu); + QueueSfx2_Max6(0xE); return jp; } @@ -3059,14 +2900,14 @@ void MaridiaLargeSnail_Func_2(uint16 k) { // 0xA2CD35 if (CheckIfEnemyTouchesSamus(k)) extra_samus_y_displacement = E->base.y_pos - E->mlsl_var_08; if (E->mlsl_var_04) { - R18_ = E->base.x_pos - E->mlsl_var_06; - if ((R18_ & 0x8000u) != 0) { + uint16 r18 = E->base.x_pos - E->mlsl_var_06; + if ((r18 & 0x8000) != 0) { if (!E->mlsl_var_05) return; } else if (E->mlsl_var_05) { return; } - extra_samus_x_displacement += R18_; + extra_samus_x_displacement += r18; } } @@ -3105,13 +2946,13 @@ void MaridiaLargeSnail_Func_4(void) { // 0xA2CDE6 CallEnemyPreInstr(E->mlsl_var_F | 0xA20000); } else { E->mlsl_var_00 = 0; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) { + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) { E->mlsl_var_D = 1; E->mlsl_var_00 = 1; } MaridiaLargeSnail_Func_10(cur_enemy_index); if (IsSamusWithinEnemy_X(cur_enemy_index, 0x18)) { - E->mlsl_var_00 |= 2u; + E->mlsl_var_00 |= 2; MaridiaLargeSnail_Func_10(cur_enemy_index); E->mlsl_var_A = FUNC16(MaridiaLargeSnail_Func_5); } @@ -3123,21 +2964,19 @@ void MaridiaLargeSnail_Func_5(void) { // 0xA2CE2B if (E->mlsl_var_E) { CallEnemyPreInstr(E->mlsl_var_F | 0xA20000); } else { - R18_ = 0; - R20_ = 1; - if (!(Enemy_MoveDown(cur_enemy_index) & 1)) { + if (!(Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1)))) { E->mlsl_var_B = 0; E->mlsl_var_F = FUNC16(MaridiaLargeSnail_Func_7); E->mlsl_var_E = 3; } } if (!E->mlsl_var_0B) { - R36 = 0; - bool v4 = (--E->mlsl_var_C & 0x8000u) != 0; + uint16 R36 = 0; + bool v4 = (--E->mlsl_var_C & 0x8000) != 0; if (v4 && (E->mlsl_var_C = 0, IsSamusWithinEnemy_X(cur_enemy_index, 0x20)) && E->mlsl_var_03 && !E->mlsl_var_E) { E->mlsl_var_00 = 0; E->mlsl_var_D = 0; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) { + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) { E->mlsl_var_00 = 1; E->mlsl_var_D = 1; } @@ -3150,15 +2989,15 @@ void MaridiaLargeSnail_Func_5(void) { // 0xA2CE2B if (E->mlsl_var_D) v5 = 132; int v6 = v5 >> 1; - R18_ = kCommonEnemySpeeds_Linear[v6 + 1]; - R20_ = kCommonEnemySpeeds_Linear[v6]; + uint16 r18 = kCommonEnemySpeeds_Linear[v6 + 1]; + uint16 r20 = kCommonEnemySpeeds_Linear[v6]; if (E->mlsl_var_04 && E->mlsl_var_D == E->mlsl_var_05) { if (E->mlsl_var_D) - R20_ -= 16; + r20 -= 16; else - R20_ += 16; + r20 += 16; } - if (Enemy_MoveRight_SlopesAsWalls(cur_enemy_index) & 1) + if (Enemy_MoveRight_SlopesAsWalls(cur_enemy_index, __PAIR32__(r20, r18))) ++R36; if (E->mlsl_var_04 && E->mlsl_var_D == E->mlsl_var_05) { uint16 v7; @@ -3169,8 +3008,8 @@ void MaridiaLargeSnail_Func_5(void) { // 0xA2CE2B E->base.x_pos = v7; } if (R36) { - E->mlsl_var_D ^= 1u; - E->mlsl_var_00 ^= 4u; + E->mlsl_var_D ^= 1; + E->mlsl_var_00 ^= 4; MaridiaLargeSnail_Func_10(cur_enemy_index); } } @@ -3194,11 +3033,8 @@ void MaridiaLargeSnail_Func_7(uint16 k) { // 0xA2CF66 v2 = 0x4000; E->mlsl_var_B = v2; - uint16 v3 = swap16(v2); - int v5 = (uint16)(8 * v3) >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v5]; - R20_ = kCommonEnemySpeeds_Quadratic[v5 + 1]; - if (Enemy_MoveDown(k) & 1) { + int v5 = (8 * (v2 >> 8)) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[v5 >> 1])) { --E->mlsl_var_E; int16 v6 = E->mlsl_var_B - 4096; if (v6 < 0) @@ -3214,10 +3050,8 @@ void MaridiaLargeSnail_Func_8(uint16 k) { // 0xA2CFA9 E->mlsl_var_B = v2; if (v2 >= 0) { uint16 v3 = (v2 & 0x7F00) >> 8; - int v5 = (uint16)(8 * v3) >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v5 + 2]; - R20_ = kCommonEnemySpeeds_Quadratic[v5 + 3]; - Enemy_MoveDown(k); + int v5 = (8 * v3) >> 1; + Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[(v5 + 2) >> 1]); } else { E->mlsl_var_B = 0; E->mlsl_var_F = FUNC16(MaridiaLargeSnail_Func_7); @@ -3226,7 +3060,7 @@ void MaridiaLargeSnail_Func_8(uint16 k) { // 0xA2CFA9 // 7DD25: mask 0xFF00 is shortened because ax.2 <= 0x7FFF void MaridiaLargeSnail_Func_9(void) { // 0xA2CFD7 - QueueSfx2_Max6(0x63u); + QueueSfx2_Max6(0x63); } void MaridiaLargeSnail_Func_10(uint16 k) { // 0xA2CFDF @@ -3246,7 +3080,7 @@ void MaridiaLargeSnail_Func_11(void) { // 0xA2CFFF E->mlsl_var_05 = 0; if (IsSamusWithinEnemy_Y(cur_enemy_index, 0x20) && IsSamusWithinEnemy_X(cur_enemy_index, 0x18)) { E->mlsl_var_04 = 1; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) E->mlsl_var_05 = 1; } } @@ -3268,7 +3102,12 @@ void MaridiaLargeSnail_Touch() { // 0xA2D38C void MaridiaLargeSnail_Shot(void) { // 0xA2D3B4 NormalEnemyShotAi(); - QueueSfx2_Max6(0x57u); + QueueSfx2_Max6(0x57); +} + +static uint16 HirisingSlowfalling_Func_1(uint16 k) { // 0xA2DFCE + Enemy_HirisingSlowfalling *E = Get_HirisingSlowfalling(k); + return Mult8x8(E->hsg_parameter_1, E->hsg_var_F); } void HirisingSlowfalling_Init(void) { // 0xA2DF76 @@ -3277,35 +3116,30 @@ void HirisingSlowfalling_Init(void) { // 0xA2DF76 E->hsg_var_A = FUNC16(HirisingSlowfalling_Func_4); E->hsg_var_00 = E->base.x_pos; E->hsg_var_01 = E->base.y_pos; - int v2 = (uint16)(2 * HIBYTE(E->hsg_parameter_1)) >> 1; + int v2 = HIBYTE(E->hsg_parameter_1); E->hsg_var_E = g_off_A2DF5E[v2]; E->hsg_var_F = *(uint16 *)RomPtr_A2(g_off_A2DF6A[v2]); - HirisingSlowfalling_Func_1(cur_enemy_index); - HirisingSlowfalling_Func_2(cur_enemy_index); - E->hsg_var_03 = E->hsg_var_01 - R18_; + uint16 r18 = HirisingSlowfalling_Func_1(cur_enemy_index); + HirisingSlowfalling_Func_2(cur_enemy_index, r18); + E->hsg_var_03 = E->hsg_var_01 - r18; E->hsg_var_02 = E->hsg_var_00; E->hsg_var_B = E->hsg_var_06; } -void HirisingSlowfalling_Func_1(uint16 k) { // 0xA2DFCE - Enemy_HirisingSlowfalling *E = Get_HirisingSlowfalling(k); - R18_ = Mult8x8(E->hsg_parameter_1, E->hsg_var_F); -} - -void HirisingSlowfalling_Func_2(uint16 k) { // 0xA2DFE9 - R20_ = 0; - R22_ = 0; - R24_ = 0; +void HirisingSlowfalling_Func_2(uint16 k, uint16 r18) { // 0xA2DFE9 + uint16 r20 = 0; + uint16 r22 = 0; + uint16 r24 = 0; do { - R24_ += 512; - int v1 = (uint16)(8 * (uint8)((uint16)(R24_ & 0xFF00) >> 8)) >> 1; - uint16 v2 = kCommonEnemySpeeds_Quadratic[v1] + R20_; - if (__CFADD__uint16(kCommonEnemySpeeds_Quadratic[v1], R20_)) - ++R22_; - R20_ = v2; - R22_ += kCommonEnemySpeeds_Quadratic[v1 + 1]; - } while (sign16(R22_ - R18_)); - Get_HirisingSlowfalling(k)->hsg_var_06 = R24_; + r24 += 512; + int v1 = (8 * ((r24 & 0xFF00) >> 8)) >> 1; + uint16 v2 = kCommonEnemySpeeds_Quadratic[v1] + r20; + if (__CFADD__uint16(kCommonEnemySpeeds_Quadratic[v1], r20)) + ++r22; + r20 = v2; + r22 += kCommonEnemySpeeds_Quadratic[v1 + 1]; + } while (sign16(r22 - r18)); + Get_HirisingSlowfalling(k)->hsg_var_06 = r24; } void HirisingSlowfalling_Func_3(uint16 a) { // 0xA2E01E @@ -3355,7 +3189,7 @@ void HirisingSlowfalling_Func_6(void) { // 0xA2E06A Enemy_HirisingSlowfalling *E = Get_HirisingSlowfalling(cur_enemy_index); uint16 y_subpos = E->base.y_subpos; - int v2 = (uint16)(8 * HIBYTE(E->hsg_var_B)) >> 1; + int v2 = (8 * HIBYTE(E->hsg_var_B)) >> 1; bool v3 = __CFADD__uint16(kCommonEnemySpeeds_Quadratic[v2 + 2], y_subpos); uint16 v4 = kCommonEnemySpeeds_Quadratic[v2 + 2] + y_subpos; if (v3) @@ -3384,7 +3218,7 @@ void HirisingSlowfalling_Func_7(void) { // 0xA2E0CD if (GET_WORD(v1) == 0x8000) { E->hsg_var_05 += E->hsg_var_F; E->hsg_var_C = 0; - if ((--E->hsg_var_D & 0x8000u) != 0) { + if ((--E->hsg_var_D & 0x8000) != 0) { E->hsg_var_B = E->hsg_var_06; E->base.x_pos = E->hsg_var_00; E->base.x_subpos = 0; @@ -3415,7 +3249,7 @@ void Gripper_Init(void) { // 0xA2E1D3 } E->gripper_var_C = v3; uint16 v4 = addr_kGripper_Ilist_E19B; - if ((E->gripper_var_D & 0x8000u) == 0) + if ((E->gripper_var_D & 0x8000) == 0) v4 = addr_kGripper_Ilist_E1AF; E->base.current_instruction = v4; E->gripper_var_A = E->gripper_parameter_1; @@ -3424,12 +3258,11 @@ void Gripper_Init(void) { // 0xA2E1D3 void Gripper_Main(void) { // 0xA2E221 Enemy_Gripper *E = Get_Gripper(cur_enemy_index); - R18_ = E->gripper_var_C; - R20_ = E->gripper_var_D; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1 || Gripper_Func_1(cur_enemy_index) & 1 || Gripper_Func_2(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->gripper_var_D, E->gripper_var_C)) || + Gripper_Func_1(cur_enemy_index) & 1 || Gripper_Func_2(cur_enemy_index) & 1) { int v3 = E->gripper_var_E >> 1; uint16 v4; - if ((E->gripper_var_D & 0x8000u) == 0) { + if ((E->gripper_var_D & 0x8000) == 0) { E->gripper_var_D = kCommonEnemySpeeds_Linear[v3 + 2]; E->gripper_var_C = kCommonEnemySpeeds_Linear[v3 + 3]; v4 = addr_kGripper_Ilist_E19B; @@ -3446,12 +3279,12 @@ void Gripper_Main(void) { // 0xA2E221 uint8 Gripper_Func_1(uint16 k) { // 0xA2E279 Enemy_Gripper *E = Get_Gripper(k); - return (E->gripper_var_D & 0x8000u) != 0 && (int16)(E->base.x_pos - E->gripper_var_A) < 0; + return (E->gripper_var_D & 0x8000) != 0 && (int16)(E->base.x_pos - E->gripper_var_A) < 0; } uint8 Gripper_Func_2(uint16 k) { // 0xA2E28A Enemy_Gripper *E = Get_Gripper(k); - return (E->gripper_var_D & 0x8000u) == 0 && (int16)(E->base.x_pos - E->gripper_var_B) >= 0; + return (E->gripper_var_D & 0x8000) == 0 && (int16)(E->base.x_pos - E->gripper_var_B) >= 0; } void Gripper_Func_3(void) { // 0xA2E29B @@ -3463,7 +3296,7 @@ void Gripper_Func_4(void) { // 0xA2E2A4 Enemy_Gripper *E = Get_Gripper(cur_enemy_index); if (E->base.frozen_timer) { uint16 v1 = addr_kGripper_Sprmap_E43F; - if ((E->gripper_var_D & 0x8000u) == 0) + if ((E->gripper_var_D & 0x8000) == 0) v1 = addr_kGripper_Sprmap_E44B; E->base.spritemap_pointer = v1; } @@ -3493,11 +3326,9 @@ void JetPowerRipper_Main(void) { // 0xA2E353 int16 v3; Enemy_JetPowerRipper *E = Get_JetPowerRipper(cur_enemy_index); - R18_ = E->jprr_var_C; - R20_ = E->jprr_var_D; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->jprr_var_D, E->jprr_var_C))) { int v2 = E->jprr_var_E >> 1; - if ((E->jprr_var_D & 0x8000u) == 0) { + if ((E->jprr_var_D & 0x8000) == 0) { E->jprr_var_D = kCommonEnemySpeeds_Linear[v2 + 2]; E->jprr_var_C = kCommonEnemySpeeds_Linear[v2 + 3]; v3 = -7456; @@ -3523,7 +3354,7 @@ void JetPowerRipper_Shot(void) { // 0xA2E3A9 Enemy_JetPowerRipper *E = Get_JetPowerRipper(cur_enemy_index); if (E->base.frozen_timer) { v1 = -7105; - if ((E->jprr_var_D & 0x8000u) == 0) + if ((E->jprr_var_D & 0x8000) == 0) v1 = -7093; E->base.spritemap_pointer = v1; } @@ -3553,11 +3384,9 @@ void Ripper_Main(void) { // 0xA2E4DA int16 v3; Enemy_Ripper *E = Get_Ripper(cur_enemy_index); - R18_ = E->ripper_var_C; - R20_ = E->ripper_var_D; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->ripper_var_D, E->ripper_var_C))) { int v2 = E->ripper_var_E >> 1; - if ((E->ripper_var_D & 0x8000u) == 0) { + if ((E->ripper_var_D & 0x8000) == 0) { E->ripper_var_D = kCommonEnemySpeeds_Linear[v2 + 2]; E->ripper_var_C = kCommonEnemySpeeds_Linear[v2 + 3]; v3 = -7029; @@ -3601,19 +3430,19 @@ void LavaSeahorse_Main(void) { // 0xA2E64E void LavaSeahorse_Func_1(uint16 k) { // 0xA2E654 Enemy_LavaSeahorse *E = Get_LavaSeahorse(k); - if ((--E->lse_var_D & 0x8000u) != 0) { + if ((--E->lse_var_D & 0x8000) != 0) { E->lse_var_D = 48; E->lse_var_F = FUNC16(LavaSeahorse_Func_2); uint16 t = GetSamusEnemyDelta_X(k); E->lse_var_A = (E->lse_var_A & 0x7fff) | (t & 0x8000); - if ((E->lse_var_A & 0x8000u) != 0) { - LOBYTE(E->lse_var_00) &= ~1u; + if ((E->lse_var_A & 0x8000) != 0) { + LOBYTE(E->lse_var_00) &= ~1; Enemy_LavaSeahorse *E1 = Get_LavaSeahorse(k + 64); - LOBYTE(E1->lse_var_00) &= ~1u; + LOBYTE(E1->lse_var_00) &= ~1; } else { - LOBYTE(E->lse_var_00) |= 1u; + LOBYTE(E->lse_var_00) |= 1; Enemy_LavaSeahorse *E1 = Get_LavaSeahorse(k + 64); - LOBYTE(E1->lse_var_00) |= 1u; + LOBYTE(E1->lse_var_00) |= 1; } LavaSeahorse_Func_6(); LavaSeahorse_Func_7(); @@ -3622,7 +3451,7 @@ void LavaSeahorse_Func_1(uint16 k) { // 0xA2E654 void LavaSeahorse_Func_2(uint16 k) { // 0xA2E6AD Enemy_LavaSeahorse *E = Get_LavaSeahorse(k); - if ((--E->lse_var_D & 0x8000u) != 0) { + if ((--E->lse_var_D & 0x8000) != 0) { E->lse_var_00 += 4; E->lse_var_D = 3; E->lse_var_F = FUNC16(LavaSeahorse_Func_3); @@ -3639,7 +3468,7 @@ void LavaSeahorse_Func_3(uint16 k) { // 0xA2E6F1 E->lse_var_02 = 0; E->lse_var_01 = -1; SpawnEnemyProjectileWithGfx(0xFFFF, k, addr_kEproj_LavaSeahorseFireball); - QueueSfx2_Max6(0x61u); + QueueSfx2_Max6(0x61); if (E->lse_var_D-- == 1) { E->lse_var_00 -= 4; E->lse_var_D = 96; @@ -3659,7 +3488,7 @@ void LavaSeahorse_Func_4(uint16 k) { // 0xA2E734 void LavaSeahorse_Func_5(uint16 k) { // 0xA2E749 Enemy_LavaSeahorse *E = Get_LavaSeahorse(k); - if ((--E->lse_var_D & 0x8000u) != 0) { + if ((--E->lse_var_D & 0x8000) != 0) { E->lse_var_D = 128; E->lse_var_F = FUNC16(LavaSeahorse_Func_1); } @@ -3717,14 +3546,13 @@ void LavaSeahorse_E7DA(void) { // 0xA2E7DA E1->base.ai_handler_bits = E->base.ai_handler_bits; } else { Enemy_LavaSeahorse *E1 = Get_LavaSeahorse(cur_enemy_index + 64); - E1->base.properties |= 0x200u; + E1->base.properties |= 0x200; } } void TimedShutter_Init(void) { // 0xA2E9DA Enemy_TimedShutter *E = Get_TimedShutter(cur_enemy_index); - E->tsr_var_A = g_off_A2EA4E[(uint16)(2 * (E->base.current_instruction - + 2 * E->base.extra_properties)) >> 1]; + E->tsr_var_A = g_off_A2EA4E[E->base.current_instruction + 2 * E->base.extra_properties]; uint16 y_pos = E->base.y_pos; uint16 v3; if (E->base.extra_properties) { @@ -3814,7 +3642,7 @@ void TimedShutter_Func_Null(void) { static Func_V *const off_A2EB1A[5] = { TimedShutter_Func_6, TimedShutter_Func_7, TimedShutter_Func_8, TimedShutter_Func_9, TimedShutter_Func_Null }; void TimedShutter_Func_5(uint16 k) { // 0xA2EB11 - int v1 = (uint16)(2 * Get_TimedShutter(k)->tsr_var_F) >> 1; + int v1 = Get_TimedShutter(k)->tsr_var_F; off_A2EB1A[v1](); } @@ -3987,7 +3815,7 @@ void RisingFallingPlatform_Func_1(uint16 k) { // 0xA2EE1F Enemy_RisingFallingPlatform *E = Get_RisingFallingPlatform(k); uint16 current_instruction_low = LOBYTE(E->base.current_instruction); E->rfpm_var_00 = current_instruction_low; - int v3 = (uint16)(8 * current_instruction_low) >> 1; + int v3 = (8 * current_instruction_low) >> 1; E->rfpm_var_D = kCommonEnemySpeeds_Linear[v3]; E->rfpm_var_C = kCommonEnemySpeeds_Linear[v3 + 1]; E->rfpm_var_F = kCommonEnemySpeeds_Linear[v3 + 2]; @@ -4099,7 +3927,7 @@ void RisingFallingPlatform_Func_7(uint16 k) { // 0xA2EF44 void RisingFallingPlatform_Func_8(void) { // 0xA2EF5A if (!CheckIfEnemyIsOnScreen()) - QueueSfx3_Max6(0xEu); + QueueSfx3_Max6(0xE); } void RisingFallingPlatform_Func_9(void) { // 0xA2EF68 @@ -4154,7 +3982,7 @@ void RisingFallingPlatform_Func_10(void) { // 0xA2EFD4 void RisingFallingPlatform_Func_11(void) { // 0xA2F040 Enemy_RisingFallingPlatform *E = Get_RisingFallingPlatform(cur_enemy_index); - if ((--E->rfpm_var_B & 0x8000u) != 0) { + if ((--E->rfpm_var_B & 0x8000) != 0) { E->rfpm_var_A = FUNC16(RisingFallingPlatform_Func_10); if (E->rfpm_var_04 == 1 && E->rfpm_var_01) E->rfpm_var_A = FUNC16(RisingFallingPlatform_Func_4); @@ -4165,7 +3993,7 @@ void RisingFallingPlatform_Func_11(void) { // 0xA2F040 void RisingFallingPlatform_Func_12(void) { // 0xA2F072 Enemy_RisingFallingPlatform *E = Get_RisingFallingPlatform(cur_enemy_index); - if ((--E->rfpm_var_B & 0x8000u) != 0) { + if ((--E->rfpm_var_B & 0x8000) != 0) { RisingFallingPlatform_Func_8(); E->rfpm_var_A = FUNC16(RisingFallingPlatform_Func_9); if (E->rfpm_var_04 == 1 && !E->rfpm_var_01) @@ -4207,7 +4035,7 @@ LABEL_10: E->rfpm_var_A = FUNC16(RisingFallingPlatform_Func_9); if (E->rfpm_var_20) E->rfpm_var_A = FUNC16(RisingFallingPlatform_Func_10); - E->rfpm_var_20 ^= 1u; + E->rfpm_var_20 ^= 1; goto LABEL_10; } } @@ -4221,7 +4049,7 @@ void HorizontalShootableShutter_Func_1(uint16 k) { // 0xA2F11E Enemy_RisingFallingPlatform *E = Get_RisingFallingPlatform(k); uint16 current_instruction_low = LOBYTE(E->base.current_instruction); E->rfpm_var_00 = current_instruction_low; - int v3 = (uint16)(8 * current_instruction_low) >> 1; + int v3 = (8 * current_instruction_low) >> 1; E->rfpm_var_D = kCommonEnemySpeeds_Linear[v3]; E->rfpm_var_C = kCommonEnemySpeeds_Linear[v3 + 1]; E->rfpm_var_F = kCommonEnemySpeeds_Linear[v3 + 2]; @@ -4383,7 +4211,7 @@ void HorizontalShootableShutter_Func_11(uint16 k) { // 0xA2F371 void HorizontalShootableShutter_Func_12(void) { // 0xA2F38C Enemy_RisingFallingPlatform *E = Get_RisingFallingPlatform(cur_enemy_index); - if ((--E->rfpm_var_B & 0x8000u) != 0) { + if ((--E->rfpm_var_B & 0x8000) != 0) { E->rfpm_var_A = FUNC16(HorizontalShootableShutter_Func_9); if (E->rfpm_var_04 == 1) { if (E->rfpm_var_01) @@ -4394,7 +4222,7 @@ void HorizontalShootableShutter_Func_12(void) { // 0xA2F38C void HorizontalShootableShutter_Func_13(void) { // 0xA2F3B0 Enemy_RisingFallingPlatform *E = Get_RisingFallingPlatform(cur_enemy_index); - if ((--E->rfpm_var_B & 0x8000u) != 0) { + if ((--E->rfpm_var_B & 0x8000) != 0) { E->rfpm_var_A = FUNC16(HorizontalShootableShutter_Func_8); if (E->rfpm_var_04 == 1 && !E->rfpm_var_01) E->rfpm_var_A = FUNC16(HorizontalShootableShutter_Func_4); @@ -4435,10 +4263,10 @@ void HorizontalShootableShutter_Powerbomb(void) { // 0xA2F41A } if (E->rfpm_var_A != FUNC16(HorizontalShootableShutter_Func_8) && E->rfpm_var_A != FUNC16(HorizontalShootableShutter_Func_9)) { - E->rfpm_var_20 ^= 1u; + E->rfpm_var_20 ^= 1; E->rfpm_var_A = FUNC16(HorizontalShootableShutter_Func_8); if (E->rfpm_var_20) E->rfpm_var_A = FUNC16(HorizontalShootableShutter_Func_9); } } -} \ No newline at end of file +} diff --git a/src/sm_a3.c b/src/sm_a3.c index d42e70a..f271a40 100644 --- a/src/sm_a3.c +++ b/src/sm_a3.c @@ -5,7 +5,6 @@ #include "funcs.h" #include "enemy_types.h" - #define g_off_A386DB ((uint16*)RomFixedPtr(0xa386db)) #define g_off_A3894E ((uint16*)RomFixedPtr(0xa3894e)) #define g_word_A38D1D ((uint16*)RomFixedPtr(0xa38d1d)) @@ -59,12 +58,11 @@ #define g_word_A3EAD6 ((uint16*)RomFixedPtr(0xa3ead6)) #define g_word_A3EA3F ((uint16*)RomFixedPtr(0xa3ea3f)) - +void CallSidehopperFunc(uint32 ea); static const int16 g_word_A3A76D[4] = { 2, 0, -2, 0 }; static const int16 g_word_A3A775[4] = { 0, -2, 0, 2 }; - void Enemy_GrappleReact_NoInteract_A3(void) { // 0xA38000 SwitchEnemyAiToMainAi(); } @@ -107,8 +105,8 @@ void Waver_Init(void) { // 0xA386ED E->waver_var_B = 1; E->waver_var_A = 0x8000; if ((E->waver_parameter_1 & 1) == 0) { - E->waver_var_B = SignExtend8(0xFEu); - E->waver_var_A = SignExtend8(0x8000u); + E->waver_var_B = SignExtend8(0xFE); + E->waver_var_A = SignExtend8(0x8000); } E->waver_var_F = 0; E->waver_var_C = 0; @@ -119,31 +117,22 @@ void Waver_Init(void) { // 0xA386ED } void Waver_Main(void) { // 0xA3874C - uint16 v2; - Enemy_Waver *E = Get_Waver(cur_enemy_index); - R18_ = E->waver_var_A; - R20_ = E->waver_var_B; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - R18_ = *(uint16 *)((uint8 *)&E->waver_var_A + 1); - E->waver_var_B = SignExtend8((uint8)((uint16)(-R18_ & 0xFF00) >> 8)); - LOBYTE(v2) = 0; - HIBYTE(v2) = -(int8)R18_; - E->waver_var_A = SignExtend8(v2); - E->waver_var_F = ((uint8)E->waver_var_F ^ 1) & 1; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->waver_var_B, E->waver_var_A))) { + uint16 r18 = *(uint16 *)((uint8 *)&E->waver_var_A + 1); + E->waver_var_B = SignExtend8((-r18 & 0xFF00) >> 8); + E->waver_var_A = -(int8)r18 << 8; + E->waver_var_F = (E->waver_var_F ^ 1) & 1; Waver_Func_1(); } else { - draw_enemy_layer = 4; - R20_ = SineMult8bitNegative(LOBYTE(E->waver_var_D)); - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(SineMult8bit(LOBYTE(E->waver_var_D), 4)))) { E->waver_var_D = (uint8)(E->waver_var_D + 0x80); } else { E->waver_var_D += 2; } } if ((E->waver_var_D & 0x7F) == 56) { - E->waver_var_F |= 2u; + E->waver_var_F |= 2; Waver_Func_1(); } if (E->waver_var_E) { @@ -195,7 +184,7 @@ void Metalee_Main(void) { // 0xA38979 void Metalee_Func_1(void) { // 0xA38987 Enemy_Metalee *E = Get_Metalee(cur_enemy_index); - if (abs16(E->base.x_pos - samus_x_pos) < 0x48u) { + if (abs16(E->base.x_pos - samus_x_pos) < 0x48) { Metalee_Func_2(cur_enemy_index); ++E->metalee_var_C; Metalee_Func_6(); @@ -206,7 +195,7 @@ void Metalee_Func_1(void) { // 0xA38987 void Metalee_Func_2(uint16 k) { // 0xA389AC Enemy_Metalee *E = Get_Metalee(k); uint16 div = (uint8)SnesDivide(samus_y_pos - E->base.y_pos, 24); - Get_Metalee(k)->metalee_var_F = div + 4; + E->metalee_var_F = div + 4; } void Metalee_Func_3(uint16 k) { // 0xA389D4 @@ -216,28 +205,23 @@ void Metalee_Func_3(uint16 k) { // 0xA389D4 ++E->metalee_var_C; Metalee_Func_6(); E->metalee_var_B = FUNC16(Metalee_Func_4); - QueueSfx2_Max6(0x5Bu); + QueueSfx2_Max6(0x5B); } } void Metalee_Func_4(void) { // 0xA389F3 Enemy_Metalee *E = Get_Metalee(cur_enemy_index); E->metalee_var_A = 21; - R20_ = E->metalee_var_F; - R18_ = 0; uint16 v1 = E->base.properties | 3; E->base.properties = v1; - if (EnemyFunc_BF8A(cur_enemy_index, v1) & 1) { + if (EnemyFunc_BF8A(cur_enemy_index, v1, INT16_SHL16(E->metalee_var_F)) & 1) { E->base.instruction_timer = 1; E->base.timer = 0; E->metalee_var_B = FUNC16(Metalee_Func_5); - QueueSfx2_Max6(0x5Cu); + QueueSfx2_Max6(0x5C); } else { E->base.y_pos += E->metalee_var_F; - varE24 = 2; - if ((int16)(E->base.x_pos - samus_x_pos) >= 0) - varE24 = -2; - E->base.x_pos += varE24; + E->base.x_pos += ((int16)(E->base.x_pos - samus_x_pos) >= 0) ? -2 : 2; } } @@ -273,8 +257,8 @@ void Metalee_Func_6(void) { // 0xA38AB2 void Metalee_Shot(void) { // 0xA38B0F Enemy_Metalee *E = Get_Metalee(cur_enemy_index); - varE2A = E->base.vram_tiles_index; - varE2C = E->base.palette_index; + uint16 varE2A = E->base.vram_tiles_index; + uint16 varE2C = E->base.palette_index; Enemy_NormalShotAI_A3(); if (!Get_Metalee(cur_enemy_index)->base.health) { E->base.vram_tiles_index = varE2A; @@ -290,10 +274,9 @@ void Metalee_Shot(void) { // 0xA38B0F } void Fireflea_Init(void) { // 0xA38D2D - Enemy_Fireflea *E = Get_Fireflea(cur_enemy_index); + Enemy_FireFlea *E = Get_FireFlea(cur_enemy_index); E->base.current_instruction = addr_kFireflea_Ilist_8C2F; - R18_ = LOBYTE(E->firefl_parameter_1); - if ((R18_ & 2) != 0) { + if ((E->ffa_parameter_1 & 2) != 0) { Fireflea_Func_1(cur_enemy_index); Fireflea_Func_2(cur_enemy_index); Fireflea_Func_3(cur_enemy_index); @@ -307,20 +290,20 @@ void Fireflea_Init(void) { // 0xA38D2D } void Fireflea_Func_1(uint16 k) { // 0xA38D5D - Enemy_Fireflea *E = Get_Fireflea(k); - E->firefl_var_E = E->base.x_pos; - E->firefl_var_F = E->base.y_pos; + Enemy_FireFlea *E = Get_FireFlea(k); + E->ffa_var_E = E->base.x_pos; + E->ffa_var_F = E->base.y_pos; } void Fireflea_Func_2(uint16 k) { // 0xA38D6A - Enemy_Fireflea *E = Get_Fireflea(k); - E->firefl_var_D = HIBYTE(E->firefl_parameter_1) << 8; + Enemy_FireFlea *E = Get_FireFlea(k); + E->ffa_var_D = HIBYTE(E->ffa_parameter_1) << 8; } void Fireflea_Func_3(uint16 k) { // 0xA38D75 Enemy_FireFlea *E = Get_FireFlea(k); uint16 v2 = 8 * LOBYTE(E->ffa_parameter_2); - if ((R18_ & 1) == 0) + if ((E->ffa_parameter_1 & 1) == 0) v2 += 4; E->ffa_var_02 = v2; int v3 = v2 >> 1; @@ -329,16 +312,14 @@ void Fireflea_Func_3(uint16 k) { // 0xA38D75 } void Fireflea_Func_4(uint16 k) { // 0xA38D9C - Enemy_Fireflea *E = Get_Fireflea(k); - E->firefl_var_C = LOBYTE(g_word_A38D1D[HIBYTE(E->firefl_parameter_2)]); + Enemy_FireFlea *E = Get_FireFlea(k); + E->ffa_var_C = LOBYTE(g_word_A38D1D[HIBYTE(E->ffa_parameter_2)]); } void Fireflea_Func_5(uint16 k) { // 0xA38DAE - Enemy_Fireflea *E = Get_Fireflea(k); - draw_enemy_layer = E->firefl_var_C; - E->base.x_pos = E->firefl_var_E + CosineMult8bit(E->firefl_var_D); - draw_enemy_layer = E->firefl_var_C; - E->base.y_pos = E->firefl_var_F + SineMult8bitNegative(E->firefl_var_D); + Enemy_FireFlea *E = Get_FireFlea(k); + E->base.x_pos = E->ffa_var_E + CosineMult8bit(E->ffa_var_D, E->ffa_var_C); + E->base.y_pos = E->ffa_var_F + SineMult8bit(E->ffa_var_D, E->ffa_var_C); } void Fireflea_Func_6(uint16 k) { // 0xA38DD7 @@ -350,10 +331,8 @@ void Fireflea_Func_6(uint16 k) { // 0xA38DD7 void Fireflea_Main(void) { // 0xA38DEE Enemy_FireFlea *E = Get_FireFlea(cur_enemy_index); if ((E->ffa_parameter_1 & 2) != 0) { - draw_enemy_layer = E->ffa_var_C; - E->base.x_pos = E->ffa_var_E + CosineMult8bit(HIBYTE(E->ffa_var_D)); - draw_enemy_layer = E->ffa_var_C; - E->base.y_pos = E->ffa_var_F + SineMult8bitNegative(HIBYTE(E->ffa_var_D)); + E->base.x_pos = E->ffa_var_E + CosineMult8bit(HIBYTE(E->ffa_var_D), E->ffa_var_C); + E->base.y_pos = E->ffa_var_F + SineMult8bit(HIBYTE(E->ffa_var_D), E->ffa_var_C); E->ffa_var_D += *(uint16 *)((uint8 *)&E->ffa_var_A + 1); } else { uint16 y_subpos = E->base.y_subpos; @@ -363,7 +342,7 @@ void Fireflea_Main(void) { // 0xA38DEE E->base.y_pos += kCommonEnemySpeeds_Linear[v2] + v3; if ((int16)(E->base.y_pos - E->ffa_var_00) < 0 || (int16)(E->base.y_pos - E->ffa_var_01) >= 0) { - E->ffa_var_02 ^= 4u; + E->ffa_var_02 ^= 4; } } } @@ -388,7 +367,7 @@ void Fireflea_Shot(void) { // 0xA38E89 } void Fireflea_Common(void) { // 0xA38E8D - if (!Get_Fireflea(cur_enemy_index)->base.health) { + if (!Get_FireFlea(cur_enemy_index)->base.health) { if (sign16(fireflea_darkness_level - 12)) fireflea_darkness_level += 2; } @@ -417,7 +396,7 @@ void MaridiaFish_Init(void) { // 0xA390B5 E->base.current_instruction = addr_kMaridiaFish_Ilist_9060; E->mfh_var_A = FUNC16(MaridiaFish_Func_2); } - int v1 = (uint16)(8 * LOBYTE(E->mfh_parameter_1)) >> 1; + int v1 = (8 * LOBYTE(E->mfh_parameter_1)) >> 1; E->mfh_var_C = kCommonEnemySpeeds_Linear[v1]; E->mfh_var_B = kCommonEnemySpeeds_Linear[v1 + 1]; E->mfh_var_E = kCommonEnemySpeeds_Linear[v1 + 2]; @@ -426,41 +405,20 @@ void MaridiaFish_Init(void) { // 0xA390B5 E->mfh_var_02 = HIBYTE(E->mfh_parameter_2); E->mfh_var_F = 0; E->mfh_var_01 = 0; - draw_enemy_layer = E->mfh_var_00; - E->mfh_var_03 = SineMult8bitNegative(E->mfh_var_F); -} - -void CallMaridiaFishFunc(uint32 ea) { - switch (ea) { - case fnMaridiaFish_Func_1: MaridiaFish_Func_1(); return; - case fnMaridiaFish_Func_2: MaridiaFish_Func_2(); return; - case fnMaridiaFish_Func_3: MaridiaFish_Func_3(); return; - case fnMaridiaFish_Func_4: MaridiaFish_Func_4(); return; - default: Unreachable(); - } -} - -void MaridiaFish_Main(void) { // 0xA3912B - Enemy_MaridiaFish *E = Get_MaridiaFish(cur_enemy_index); - CallMaridiaFishFunc(E->mfh_var_A | 0xA30000); + E->mfh_var_03 = SineMult8bit(E->mfh_var_F, E->mfh_var_00); } void MaridiaFish_Func_1(void) { // 0xA39132 Enemy_MaridiaFish *E = Get_MaridiaFish(cur_enemy_index); - R18_ = E->mfh_var_D; - R20_ = E->mfh_var_E; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->mfh_var_E, E->mfh_var_D))) { E->mfh_var_A = FUNC16(MaridiaFish_Func_3); E->base.instruction_timer = 1; E->base.timer = 0; E->base.current_instruction = addr_kMaridiaFish_Ilist_903C; } else { - draw_enemy_layer = E->mfh_var_00; - uint16 v2 = SineMult8bitNegative(E->mfh_var_F); + uint16 v2 = SineMult8bit(E->mfh_var_F, E->mfh_var_00); E->mfh_var_04 = v2; - R20_ = v2 - E->mfh_var_03; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(v2 - E->mfh_var_03))) { E->mfh_var_A = FUNC16(MaridiaFish_Func_3); E->base.instruction_timer = 1; E->base.timer = 0; @@ -474,20 +432,15 @@ void MaridiaFish_Func_1(void) { // 0xA39132 void MaridiaFish_Func_2(void) { // 0xA391AB Enemy_MaridiaFish *E = Get_MaridiaFish(cur_enemy_index); - R18_ = E->mfh_var_B; - R20_ = E->mfh_var_C; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->mfh_var_C, E->mfh_var_B))) { E->mfh_var_A = FUNC16(MaridiaFish_Func_4); E->base.instruction_timer = 1; E->base.timer = 0; E->base.current_instruction = addr_kMaridiaFish_Ilist_9072; } else { - draw_enemy_layer = E->mfh_var_00; - uint16 v2 = SineMult8bitNegative(E->mfh_var_F); + uint16 v2 = SineMult8bit(E->mfh_var_F, E->mfh_var_00); E->mfh_var_04 = v2; - R20_ = v2 - E->mfh_var_03; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(v2 - E->mfh_var_03))) { E->mfh_var_A = FUNC16(MaridiaFish_Func_4); E->base.instruction_timer = 1; E->base.timer = 0; @@ -523,6 +476,21 @@ void MaridiaFish_Func_4(void) { // 0xA39256 } } +void CallMaridiaFishFunc(uint32 ea) { + switch (ea) { + case fnMaridiaFish_Func_1: MaridiaFish_Func_1(); return; + case fnMaridiaFish_Func_2: MaridiaFish_Func_2(); return; + case fnMaridiaFish_Func_3: MaridiaFish_Func_3(); return; + case fnMaridiaFish_Func_4: MaridiaFish_Func_4(); return; + default: Unreachable(); + } +} + +void MaridiaFish_Main(void) { // 0xA3912B + Enemy_MaridiaFish *E = Get_MaridiaFish(cur_enemy_index); + CallMaridiaFishFunc(E->mfh_var_A | 0xA30000); +} + void Elevator_Init(void) { // 0xA394E6 Enemy_Elevator *E = Get_Elevator(cur_enemy_index); E->base.spritemap_pointer = addr_kSpritemap_Nothing_A3; @@ -550,9 +518,9 @@ void Elevator_Frozen(void) { // 0xA3952A void Elevator_Func_1(void) { // 0xA39548 if ((g_word_A394E2[Get_Elevator(cur_enemy_index)->elevat_parameter_1 >> 1] & joypad1_newkeys) != 0) { - QueueSfx3_Max6(0xBu); - QueueSfx1_Max6(0x32u); - CallSomeSamusCode(7u); + QueueSfx3_Max6(0xB); + QueueSfx1_Max6(0x32); + CallSomeSamusCode(7); ResetProjectileData(); Elevator_Func_4(); ++elevator_status; @@ -565,7 +533,7 @@ void Elevator_Func_2(void) { // 0xA39579 Enemy_Elevator *E = Get_Elevator(cur_enemy_index); uint16 v2; if (E->elevat_parameter_1) { - elevator_direction = FUNC16(Enemy_GrappleReact_NoInteract_A3); + elevator_direction = 0x8000; uint16 y_subpos = E->base.y_subpos; E->base.y_subpos = y_subpos + 0x8000; v2 = (__PAIR32__(E->base.y_pos, y_subpos) - 98304) >> 16; @@ -608,9 +576,9 @@ LABEL_3: } elevator_status = 0; elevator_flags = 0; - QueueSfx3_Max6(0x25u); + QueueSfx3_Max6(0x25); E->base.y_pos = E->elevat_var_A; - CallSomeSamusCode(0xBu); + CallSomeSamusCode(0xB); Elevator_Func_4(); } @@ -689,7 +657,7 @@ void FastMovingSlowSinkingPlatform_Init(void) { // 0xA39CBA void PlatformThatFalls_Init(uint16 k, uint16 j) { // 0xA39CCC Enemy_PlatformThatFallsWithSamus *E = Get_PlatformThatFallsWithSamus(k); E->base.current_instruction = j; - int v3 = (uint16)(8 * LOBYTE(E->ptfwss_parameter_2)) >> 1; + int v3 = (8 * LOBYTE(E->ptfwss_parameter_2)) >> 1; E->ptfwss_var_C = kCommonEnemySpeeds_Linear[v3]; E->ptfwss_var_B = kCommonEnemySpeeds_Linear[v3 + 1]; E->ptfwss_var_E = kCommonEnemySpeeds_Linear[v3 + 2]; @@ -709,7 +677,7 @@ void PlatformThatFallsWithSamus_Main(void) { // 0xA39D16 if (CheckIfEnemyTouchesSamus(cur_enemy_index)) E->ptfwss_var_00 = 1; off_A39C97[E->ptfwss_var_02](); - int v3 = (uint16)(2 * Get_PlatformThatFallsWithSamus(cur_enemy_index)->ptfwss_var_00) >> 1; + int v3 = Get_PlatformThatFallsWithSamus(cur_enemy_index)->ptfwss_var_00; off_A39C9B[v3](); if (E->ptfwss_var_00 != E->ptfwss_var_06) E->ptfwss_var_F = 0; @@ -719,9 +687,7 @@ void PlatformThatFallsWithSamus_Main(void) { // 0xA39D16 void PlatformThatFallsWithSamus_Func_1(void) { // 0xA39D5E Enemy_PlatformThatFallsWithSamus *E = Get_PlatformThatFallsWithSamus(cur_enemy_index); E->ptfwss_var_01 = E->base.x_pos; - R18_ = E->ptfwss_var_D; - R20_ = E->ptfwss_var_E; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->ptfwss_var_E, E->ptfwss_var_D))) { E->ptfwss_var_02 = 1; PlatformThatFallsWithSamus_Func_8(); } @@ -730,9 +696,7 @@ void PlatformThatFallsWithSamus_Func_1(void) { // 0xA39D5E void PlatformThatFallsWithSamus_Func_2(void) { // 0xA39D83 Enemy_PlatformThatFallsWithSamus *E = Get_PlatformThatFallsWithSamus(cur_enemy_index); E->ptfwss_var_01 = E->base.x_pos; - R18_ = E->ptfwss_var_B; - R20_ = E->ptfwss_var_C; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->ptfwss_var_C, E->ptfwss_var_B))) { E->ptfwss_var_02 = 0; PlatformThatFallsWithSamus_Func_7(); } @@ -750,10 +714,8 @@ void PlatformThatFallsWithSamus_Func_3(void) { // 0xA39DA8 E->ptfwss_var_F = ptfwss_var_05; } int v3; - v3 = (uint16)(8 * ptfwss_var_05) >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v3 + 2]; - R20_ = kCommonEnemySpeeds_Quadratic[v3 + 3]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + v3 = (8 * ptfwss_var_05) >> 1; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Quadratic[v3 + 3], kCommonEnemySpeeds_Quadratic[v3 + 2]))) { LABEL_5: E->ptfwss_var_F = 0; PlatformThatFallsWithSamus_Func_10(); @@ -766,10 +728,8 @@ void PlatformThatFallsWithSamus_Func_4(void) { // 0xA39DE4 E->ptfwss_var_F = E->ptfwss_var_05; extra_samus_x_displacement += E->base.x_pos - E->ptfwss_var_01; E->ptfwss_var_01 = E->base.y_pos; - int v2 = (uint16)(8 * E->ptfwss_var_F) >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v2]; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 1]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + int v2 = (8 * E->ptfwss_var_F) >> 1; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Quadratic[v2 + 1], kCommonEnemySpeeds_Quadratic[v2]))) { E->ptfwss_var_F = 0; PlatformThatFallsWithSamus_Func_10(); } @@ -779,7 +739,7 @@ void PlatformThatFallsWithSamus_Func_4(void) { // 0xA39DE4 void PlatformThatFallsWithSamus_Func_5(void) { // 0xA39E47 Enemy_PlatformThatFallsWithSamus *E = Get_PlatformThatFallsWithSamus(cur_enemy_index); uint16 v0 = addr_kPlatformThatFallsWithSamus_Ilist_9C13; - if ((E->ptfwss_var_1F & 0x8000u) != 0) + if ((E->ptfwss_var_1F & 0x8000) != 0) v0 = addr_kPlatformThatFallsWithSamus_Ilist_9BBB; E->base.current_instruction = v0; E->base.instruction_timer = 1; @@ -789,7 +749,7 @@ void PlatformThatFallsWithSamus_Func_5(void) { // 0xA39E47 void PlatformThatFallsWithSamus_Func_6(void) { // 0xA39E64 Enemy_PlatformThatFallsWithSamus *E = Get_PlatformThatFallsWithSamus(cur_enemy_index); uint16 v0 = addr_kPlatformThatFallsWithSamus_Ilist_9C29; - if ((E->ptfwss_var_1F & 0x8000u) != 0) + if ((E->ptfwss_var_1F & 0x8000) != 0) v0 = addr_kPlatformThatFallsWithSamus_Ilist_9BD1; E->base.current_instruction = v0; E->base.instruction_timer = 1; @@ -799,7 +759,7 @@ void PlatformThatFallsWithSamus_Func_6(void) { // 0xA39E64 void PlatformThatFallsWithSamus_Func_7(void) { // 0xA39E81 Enemy_PlatformThatFallsWithSamus *E = Get_PlatformThatFallsWithSamus(cur_enemy_index); uint16 v0 = addr_kPlatformThatFallsWithSamus_Ilist_9C3F; - if ((E->ptfwss_var_1F & 0x8000u) != 0) + if ((E->ptfwss_var_1F & 0x8000) != 0) v0 = addr_kPlatformThatFallsWithSamus_Ilist_9BE7; E->base.current_instruction = v0; E->base.instruction_timer = 1; @@ -809,7 +769,7 @@ void PlatformThatFallsWithSamus_Func_7(void) { // 0xA39E81 void PlatformThatFallsWithSamus_Func_8(void) { // 0xA39E9E Enemy_PlatformThatFallsWithSamus *E = Get_PlatformThatFallsWithSamus(cur_enemy_index); uint16 v0 = addr_kPlatformThatFallsWithSamus_Ilist_9C55; - if ((E->ptfwss_var_1F & 0x8000u) != 0) + if ((E->ptfwss_var_1F & 0x8000) != 0) v0 = addr_kPlatformThatFallsWithSamus_Ilist_9BFD; E->base.current_instruction = v0; E->base.instruction_timer = 1; @@ -879,49 +839,27 @@ void Roach_Init(void) { // 0xA3A14D void Roach_Func_2(uint16 k) { // 0xA3A183 Enemy_Roach *E = Get_Roach(k); - R20_ = LOBYTE(E->roach_parameter_1); - R18_ = HIBYTE(E->roach_parameter_1); - ConvertAngleToXy(); - E->roach_var_01 = R22_; - E->roach_var_00 = R24_; - E->roach_var_03 = R26_; - E->roach_var_02 = R28_; + Point32 pt = ConvertAngleToXy(HIBYTE(E->roach_parameter_1), LOBYTE(E->roach_parameter_1)); + SetHiLo(&E->roach_var_01, &E->roach_var_00, pt.x); + SetHiLo(&E->roach_var_03, &E->roach_var_02, pt.y); } void Roach_Func_3(uint16 k) { // 0xA3A1B0 Enemy_Roach *E = Get_Roach(k); - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - CosineMult8bit(HIBYTE(E->roach_parameter_1)); - E->roach_var_01 = loop_index_end; - E->roach_var_00 = loop_index; - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - SineMult8bitNegative(HIBYTE(E->roach_parameter_1)); - E->roach_var_03 = loop_index_end; - E->roach_var_02 = loop_index; + SetHiLo(&E->roach_var_01, &E->roach_var_00, CosineMult8bit(HIBYTE(E->roach_parameter_1), LOBYTE(E->roach_parameter_1))); + SetHiLo(&E->roach_var_03, &E->roach_var_02, SineMult8bit(HIBYTE(E->roach_parameter_1), LOBYTE(E->roach_parameter_1))); } void Roach_Func_4(uint16 k) { // 0xA3A1F3 Enemy_Roach *E = Get_Roach(k); - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - CosineMult8bit((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) - 32)); - E->roach_var_05 = loop_index_end; - E->roach_var_04 = loop_index; - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - SineMult8bitNegative((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) - 32)); - E->roach_var_07 = loop_index_end; - E->roach_var_06 = loop_index; + SetHiLo(&E->roach_var_05, &E->roach_var_04, CosineMult8bit((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) - 32), LOBYTE(E->roach_parameter_1))); + SetHiLo(&E->roach_var_07, &E->roach_var_06, SineMult8bit((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) - 32), LOBYTE(E->roach_parameter_1))); } void Roach_Func_5(uint16 k) { // 0xA3A23E Enemy_Roach *E = Get_Roach(k); - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - CosineMult8bit((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) + 32)); - E->roach_var_09 = loop_index_end; - E->roach_var_08 = loop_index; - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - SineMult8bitNegative((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) + 32)); - E->roach_var_0B = loop_index_end; - E->roach_var_0A = loop_index; + SetHiLo(&E->roach_var_09, &E->roach_var_08, CosineMult8bit((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) + 32), LOBYTE(E->roach_parameter_1))); + SetHiLo(&E->roach_var_0B, &E->roach_var_0A, SineMult8bit((uint8)(*(uint16 *)((uint8 *)&E->roach_parameter_1 + 1) + 32), LOBYTE(E->roach_parameter_1))); } void Roach_Func_6(uint16 k) { // 0xA3A289 @@ -1030,14 +968,8 @@ void Roach_Func_17(uint16 k) { // 0xA3A3B5 void Roach_Func_18(uint16 k) { // 0xA3A3CA Enemy_Roach *E = Get_Roach(k); - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - CosineMult8bit(E->roach_var_C); - E->roach_var_0D = loop_index_end; - E->roach_var_0C = loop_index; - draw_enemy_layer = LOBYTE(E->roach_parameter_1); - SineMult8bitNegative(E->roach_var_C); - E->roach_var_0F = loop_index_end; - E->roach_var_0E = loop_index; + SetHiLo(&E->roach_var_0D, &E->roach_var_0C, CosineMult8bit(E->roach_var_C, LOBYTE(E->roach_parameter_1))); + SetHiLo(&E->roach_var_0F, &E->roach_var_0E, SineMult8bit(E->roach_var_C, LOBYTE(E->roach_parameter_1))); } void Roach_Func_19(void) { // 0xA3A407 @@ -1067,7 +999,7 @@ void Roach_Func_22(void) { // 0xA3A447 void Roach_Func_23(void) { // 0xA3A44E Enemy_Roach *E = Get_Roach(cur_enemy_index); - if ((--E->roach_var_F & 0x8000u) != 0) + if ((--E->roach_var_F & 0x8000) != 0) E->roach_var_B = FUNC16(Roach_Func_9); else Roach_Func_29(cur_enemy_index); @@ -1075,7 +1007,7 @@ void Roach_Func_23(void) { // 0xA3A44E void Roach_Func_24(void) { // 0xA3A462 Enemy_Roach *E = Get_Roach(cur_enemy_index); - if ((--E->roach_var_F & 0x8000u) != 0) + if ((--E->roach_var_F & 0x8000) != 0) E->roach_var_B = FUNC16(Roach_Func_27); else Roach_Func_33(cur_enemy_index); @@ -1083,13 +1015,13 @@ void Roach_Func_24(void) { // 0xA3A462 void Roach_Func_25(void) { // 0xA3A476 Enemy_Roach *E = Get_Roach(cur_enemy_index); - bool v2 = (--E->roach_var_A & 0x8000u) != 0; + bool v2 = (--E->roach_var_A & 0x8000) != 0; if (v2) { LABEL_6: Roach_Func_32(cur_enemy_index); return; } - v2 = (--E->roach_var_F & 0x8000u) != 0; + v2 = (--E->roach_var_F & 0x8000) != 0; if (!v2) { uint16 v3 = Abs16(E->base.x_pos - samus_x_pos); if (!sign16(v3 - 96)) { @@ -1132,7 +1064,7 @@ void Roach_Func_28(void) { // 0xA3A52A E->roach_var_0C = -E->roach_var_0C; E->roach_var_0F = -E->roach_var_0F; E->roach_var_0E = -E->roach_var_0E; - uint16 v1 = ((uint8)E->roach_var_23 + 4) & 7; + uint16 v1 = (E->roach_var_23 + 4) & 7; E->roach_var_23 = v1; E->roach_var_24 = g_off_A3A111[v1 >> 1]; Roach_Func_1(); @@ -1140,12 +1072,8 @@ void Roach_Func_28(void) { // 0xA3A52A void Roach_Func_29(uint16 k) { // 0xA3A578 Enemy_Roach *E = Get_Roach(k); - varE24 = E->roach_var_01; - varE26 = E->roach_var_00; - varE28 = E->roach_var_03; - varE2A = E->roach_var_02; - enemy_population_ptr = HIBYTE(E->roach_parameter_1); - EnemyFunc_B691(); + uint16 varE20 = HIBYTE(E->roach_parameter_1); + EnemyFunc_B691(varE20, (Point32) { __PAIR32__(E->roach_var_01, E->roach_var_00), __PAIR32__(E->roach_var_03, E->roach_var_02) }); } void Roach_Func_30(uint16 k) { // 0xA3A5A3 @@ -1204,14 +1132,10 @@ void Roach_Func_32(uint16 k) { // 0xA3A611 void Roach_Func_33(uint16 k) { // 0xA3A648 Enemy_Roach *E = Get_Roach(k); - R18_ = E->roach_var_0C; - R20_ = E->roach_var_0D; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->roach_var_0D, E->roach_var_0C))) { E->roach_var_B = FUNC16(Roach_Func_9); } else { - R18_ = E->roach_var_0E; - R20_ = E->roach_var_0F; - if (Enemy_MoveDown(k) & 1) + if (Enemy_MoveDown(k, __PAIR32__(E->roach_var_0F, E->roach_var_0E))) E->roach_var_B = FUNC16(Roach_Func_9); } } @@ -1235,66 +1159,48 @@ void Mochtroid_Func_1(void) { // 0xA3A7AA int16 v9; int16 v10; - R18_ = 0; - R20_ = 0; Enemy_Mochtroid *E = Get_Mochtroid(cur_enemy_index); - R19_ = (uint16)(E->base.y_pos - samus_y_pos) >> 2; - if ((R19_ & 0x2000) != 0) - R20_ = (uint8)R20_ | 0xFFC0; + uint32 t = INT16_SHL8((int16)(E->base.y_pos - samus_y_pos) >> 2); + uint16 r18 = t, r20 = t >> 16; uint16 mochtr_var_C = E->mochtr_var_C; - bool v3 = mochtr_var_C < R18_; - E->mochtr_var_C = mochtr_var_C - R18_; - v4 = E->mochtr_var_D - (v3 + R20_); + bool v3 = mochtr_var_C < r18; + E->mochtr_var_C = mochtr_var_C - r18; + v4 = E->mochtr_var_D - (v3 + r20); E->mochtr_var_D = v4; - if (v4 < 0) { - if ((uint16)v4 < 0xFFFDu) { + if ((int16)E->mochtr_var_D < 0) { + if ((uint16)E->mochtr_var_D < 0xFFFD) { v5 = -3; goto LABEL_8; } - } else if ((uint16)v4 >= 3u) { + } else if ((uint16)E->mochtr_var_D >= 3) { v5 = 3; LABEL_8: E->mochtr_var_D = v5; E->mochtr_var_C = 0; } - if (!E->mochtr_var_C && !E->mochtr_var_D) { + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(E->mochtr_var_D, E->mochtr_var_C))) { E->mochtr_var_C = 0; E->mochtr_var_D = 0; } - R18_ = E->mochtr_var_C; - R20_ = E->mochtr_var_D; - if (Enemy_MoveDown(cur_enemy_index) & 1) { - E->mochtr_var_C = 0; - E->mochtr_var_D = 0; - } - R18_ = 0; - R20_ = 0; - R19_ = (uint16)(E->base.x_pos - samus_x_pos) >> 2; - if ((R19_ & 0x2000) != 0) - R20_ = (uint8)R20_ | 0xFFC0; + t = INT16_SHL8((int16)(E->base.x_pos - samus_x_pos) >> 2); + r18 = t, r20 = t >> 16; uint16 mochtr_var_A = E->mochtr_var_A; - v3 = mochtr_var_A < R18_; - E->mochtr_var_A = mochtr_var_A - R18_; - v9 = E->mochtr_var_B - (v3 + R20_); + v3 = mochtr_var_A < r18; + E->mochtr_var_A = mochtr_var_A - r18; + v9 = E->mochtr_var_B - (v3 + r20); E->mochtr_var_B = v9; - if (v9 < 0) { - if ((uint16)v9 < 0xFFFDu) { + if ((int16)E->mochtr_var_B < 0) { + if ((uint16)E->mochtr_var_B < 0xFFFD) { v10 = -3; goto LABEL_21; } - } else if ((uint16)v9 >= 3u) { + } else if ((uint16)E->mochtr_var_B >= 3) { v10 = 3; LABEL_21: E->mochtr_var_B = v10; E->mochtr_var_A = 0; } - if (!E->mochtr_var_A && !E->mochtr_var_B) { - E->mochtr_var_A = 0; - E->mochtr_var_B = 0; - } - R18_ = E->mochtr_var_A; - R20_ = E->mochtr_var_B; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->mochtr_var_B, E->mochtr_var_A))) { E->mochtr_var_A = 0; E->mochtr_var_B = 0; } @@ -1303,7 +1209,7 @@ LABEL_21: void Mochtroid_Func_2(void) { // 0xA3A88F Enemy_Mochtroid *E = Get_Mochtroid(cur_enemy_index); - int v2 = (uint8)(E->mochtr_var_E & 6) >> 1; + int v2 = (E->mochtr_var_E & 6) >> 1; E->base.x_pos += g_word_A3A76D[v2]; E->base.y_pos += g_word_A3A775[v2]; E->mochtr_var_A = 0; @@ -1328,9 +1234,7 @@ void Mochtroid_Func_3(void) { // 0xA3A8C8 E->mochtr_var_A = 0; E->mochtr_var_B = 1; } - R18_ = E->mochtr_var_A; - R20_ = E->mochtr_var_B; - Enemy_MoveRight_IgnoreSlopes(cur_enemy_index); + Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->mochtr_var_B, E->mochtr_var_A)); uint16 y_pos = E->base.y_pos; if (y_pos == samus_y_pos) { E->mochtr_var_C = 0; @@ -1342,9 +1246,7 @@ void Mochtroid_Func_3(void) { // 0xA3A8C8 E->mochtr_var_C = 0; E->mochtr_var_D = 1; } - R18_ = E->mochtr_var_C; - R20_ = E->mochtr_var_D; - Enemy_MoveDown(cur_enemy_index); + Enemy_MoveDown(cur_enemy_index, __PAIR32__(E->mochtr_var_D, E->mochtr_var_C)); } void Mochtroid_Func_4(uint16 k, uint16 a) { // 0xA3A93C @@ -1364,8 +1266,8 @@ void Mochtroid_Touch(void) { // 0xA3A953 ++E->mochtr_var_20; if (samus_contact_damage_index) goto LABEL_7; - if ((enemy_damage_routine_exec_count & 7) == 7 && !sign16(samus_health - 30)) - QueueSfx3_Max6(0x2Du); + if ((random_enemy_counter & 7) == 7 && !sign16(samus_health - 30)) + QueueSfx3_Max6(0x2D); if (!sign16(E->mochtr_var_20 - 80)) { E->mochtr_var_20 = 0; LABEL_7: @@ -1406,26 +1308,21 @@ void Sidehopper_Init(void) { // 0xA3AB09 E->sideh_var_00 = v4; Sidehopper_Func_3(); if (get_EnemyDef_A2(E->base.enemy_ptr)->field_2A) - Get_Sidehopper(cur_enemy_index)->sideh_var_05 = 2; + E->sideh_var_05 = 2; int v6 = E->sideh_var_05 >> 1; - R22_ = g_word_A3AAEE[v6]; - R24_ = g_word_A3AAE6[v6]; - E->sideh_var_01 = Sidehopper_Func_2(); + E->sideh_var_01 = Sidehopper_Func_2(g_word_A3AAEE[v6], g_word_A3AAE6[v6]); int v8 = E->sideh_var_05 >> 1; - R22_ = g_word_A3AAFA[v8]; - R24_ = g_word_A3AAF2[v8]; - E->sideh_var_02 = Sidehopper_Func_2(); + E->sideh_var_02 = Sidehopper_Func_2(g_word_A3AAFA[v8], g_word_A3AAF2[v8]); E->sideh_var_B = FUNC16(Sidehopper_Func_4); } -uint16 Sidehopper_Func_2(void) { // 0xA3AB9D - R18_ = 0; - R20_ = 0; +uint16 Sidehopper_Func_2(uint16 r22, uint16 r24) { // 0xA3AB9D + uint16 r18 = 0, r20 = 0; do { - R18_ += R24_; - R20_ += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (uint16)(8 * R18_) + 1); - } while (sign16(R20_ - R22_)); - return R18_; + r18 += r24; + r20 += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (8 * r18) + 1); + } while (sign16(r20 - r22)); + return r18; } void Sidehopper_Func_3(void) { // 0xA3ABBB @@ -1435,27 +1332,6 @@ void Sidehopper_Func_3(void) { // 0xA3ABBB E->base.timer = 0; } -void CallSidehopperFunc(uint32 ea) { - switch (ea) { - case fnSidehopper_Func_4: Sidehopper_Func_4(cur_enemy_index); return; // 0xa3abd6 - case fnSidehopper_Func_5: Sidehopper_Func_5(); return; // 0xa3abe6 - case fnSidehopper_Func_6: Sidehopper_Func_6(); return; // 0xa3ac13 - case fnSidehopper_Func_7: Sidehopper_Func_7(); return; // 0xa3ac40 - case fnSidehopper_Func_8: Sidehopper_Func_8(); return; // 0xa3ac56 - case fnSidehopper_Func_9: Sidehopper_Func_9(); return; // 0xa3ac6c - case fnSidehopper_Func_10: Sidehopper_Func_10(); return; // 0xa3ac8f - case fnSidehopper_Func_11: Sidehopper_Func_11(); return; // 0xa3aca8 - case fnSidehopper_Func_12: Sidehopper_Func_12(); return; // 0xa3accb - case fnSidehopper_Func_13: Sidehopper_Func_13(); return; // 0xa3ace4 - case fnSidehopper_Func_14: Sidehopper_Func_14(); return; // 0xa3ad0e - case fnSidehopper_Func_15: Sidehopper_Func_15(); return; // 0xa3ad20 - case fnSidehopper_Func_16: Sidehopper_Func_16(); return; // 0xa3ad32 - case fnSidehopper_Func_17: Sidehopper_Func_17(); return; // 0xa3ad44 - case fnSidehopper_Func_18: Sidehopper_Func_18(); return; // 0xa3ad56 - default: Unreachable(); - } -} - void Sidehopper_Main(void) { // 0xA3ABCF Enemy_Sidehopper *E = Get_Sidehopper(cur_enemy_index); CallSidehopperFunc(E->sideh_var_B | 0xA30000); @@ -1491,14 +1367,14 @@ void Sidehopper_Func_6(void) { // 0xA3AC13 void Sidehopper_Func_7(void) { // 0xA3AC40 Enemy_Sidehopper *E = Get_Sidehopper(cur_enemy_index); E->sideh_var_B = FUNC16(Sidehopper_Func_9); - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) E->sideh_var_B = FUNC16(Sidehopper_Func_10); } void Sidehopper_Func_8(void) { // 0xA3AC56 Enemy_Sidehopper *E = Get_Sidehopper(cur_enemy_index); E->sideh_var_B = FUNC16(Sidehopper_Func_11); - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) E->sideh_var_B = FUNC16(Sidehopper_Func_12); } @@ -1577,24 +1453,39 @@ void Sidehopper_Func_18(void) { // 0xA3AD56 } } -void Sidehopper_Func_19(void) { // 0xA3AD6D - int16 v3; +static void CallSidehopperFunc(uint32 ea) { + switch (ea) { + case fnSidehopper_Func_4: Sidehopper_Func_4(cur_enemy_index); return; // 0xa3abd6 + case fnSidehopper_Func_5: Sidehopper_Func_5(); return; // 0xa3abe6 + case fnSidehopper_Func_6: Sidehopper_Func_6(); return; // 0xa3ac13 + case fnSidehopper_Func_7: Sidehopper_Func_7(); return; // 0xa3ac40 + case fnSidehopper_Func_8: Sidehopper_Func_8(); return; // 0xa3ac56 + case fnSidehopper_Func_9: Sidehopper_Func_9(); return; // 0xa3ac6c + case fnSidehopper_Func_10: Sidehopper_Func_10(); return; // 0xa3ac8f + case fnSidehopper_Func_11: Sidehopper_Func_11(); return; // 0xa3aca8 + case fnSidehopper_Func_12: Sidehopper_Func_12(); return; // 0xa3accb + case fnSidehopper_Func_13: Sidehopper_Func_13(); return; // 0xa3ace4 + case fnSidehopper_Func_14: Sidehopper_Func_14(); return; // 0xa3ad0e + case fnSidehopper_Func_15: Sidehopper_Func_15(); return; // 0xa3ad20 + case fnSidehopper_Func_16: Sidehopper_Func_16(); return; // 0xa3ad32 + case fnSidehopper_Func_17: Sidehopper_Func_17(); return; // 0xa3ad44 + case fnSidehopper_Func_18: Sidehopper_Func_18(); return; // 0xa3ad56 + default: Unreachable(); + } +} +void Sidehopper_Func_19(void) { // 0xA3AD6D Enemy_Sidehopper *E = Get_Sidehopper(cur_enemy_index); - int v2 = (uint16)(8 * E->sideh_var_C) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 3]; - R18_ = kCommonEnemySpeeds_Quadratic[v2 + 2]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + int v2 = (8 * E->sideh_var_C) >> 1; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Quadratic[v2 + 3], kCommonEnemySpeeds_Quadratic[v2 + 2]))) { E->sideh_var_D = -E->sideh_var_D; E->sideh_var_03 = 1; } else { - R20_ = E->sideh_var_D; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(E->sideh_var_D))) { E->sideh_var_D = -E->sideh_var_D; E->sideh_var_03 = 1; } else { - v3 = E->sideh_var_C - E->sideh_var_E; + int16 v3 = E->sideh_var_C - E->sideh_var_E; E->sideh_var_C = v3; if (v3 < 0) { E->sideh_var_03 = 1; @@ -1605,21 +1496,15 @@ void Sidehopper_Func_19(void) { // 0xA3AD6D } void Sidehopper_Func_20(void) { // 0xA3ADD4 - int16 v3; - Enemy_Sidehopper *E = Get_Sidehopper(cur_enemy_index); - int v2 = (uint16)(8 * E->sideh_var_C) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 1]; - R18_ = kCommonEnemySpeeds_Quadratic[v2]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + int v2 = (8 * E->sideh_var_C) >> 1; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Quadratic[v2 + 1], kCommonEnemySpeeds_Quadratic[v2]))) { E->sideh_var_03 = 0; E->sideh_var_B = FUNC16(Sidehopper_Func_13); } else { - R20_ = E->sideh_var_D; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(E->sideh_var_D))) E->sideh_var_D = -E->sideh_var_D; - v3 = E->sideh_var_E + E->sideh_var_C; + int16 v3 = E->sideh_var_E + E->sideh_var_C; if (!sign16(v3 - 64)) v3 = 64; E->sideh_var_C = v3; @@ -1627,23 +1512,17 @@ void Sidehopper_Func_20(void) { // 0xA3ADD4 } void Sidehopper_Func_21(void) { // 0xA3AE27 - int16 v3; - Enemy_Sidehopper *E = Get_Sidehopper(cur_enemy_index); - int v2 = (uint16)(8 * E->sideh_var_C) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 1]; - R18_ = kCommonEnemySpeeds_Quadratic[v2]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + int v2 = (8 * E->sideh_var_C) >> 1; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Quadratic[v2 + 1], kCommonEnemySpeeds_Quadratic[v2]))) { E->sideh_var_D = -E->sideh_var_D; E->sideh_var_03 = 1; } else { - R20_ = E->sideh_var_D; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(E->sideh_var_D))) { E->sideh_var_D = -E->sideh_var_D; E->sideh_var_03 = 1; } else { - v3 = E->sideh_var_C - E->sideh_var_E; + int16 v3 = E->sideh_var_C - E->sideh_var_E; E->sideh_var_C = v3; if (v3 < 0) { E->sideh_var_03 = 1; @@ -1657,16 +1536,12 @@ void Sidehopper_Func_22(void) { // 0xA3AE8E int16 v3; Enemy_Sidehopper *E = Get_Sidehopper(cur_enemy_index); - int v2 = (uint16)(8 * E->sideh_var_C) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 3]; - R18_ = kCommonEnemySpeeds_Quadratic[v2 + 2]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + int v2 = (8 * E->sideh_var_C) >> 1; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Quadratic[v2 + 3], kCommonEnemySpeeds_Quadratic[v2 + 2]))) { E->sideh_var_03 = 0; E->sideh_var_B = FUNC16(Sidehopper_Func_13); } else { - R20_ = E->sideh_var_D; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(E->sideh_var_D))) E->sideh_var_D = -E->sideh_var_D; v3 = E->sideh_var_E + E->sideh_var_C; if (!sign16(v3 - 64)) @@ -1721,7 +1596,7 @@ void MaridiaRefillCandy_Func_1(void) { // 0xA3B482 if (IsSamusWithinEnemy_X(cur_enemy_index, 0x80)) { v1 = 1; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) v1 = 3; Enemy_MaridiaRefillCandy *E = Get_MaridiaRefillCandy(cur_enemy_index); E->mrcy_var_D = v1; @@ -1733,10 +1608,8 @@ void MaridiaRefillCandy_Func_1(void) { // 0xA3B482 void MaridiaRefillCandy_Func_2(uint16 k) { // 0xA3B4A8 Enemy_MaridiaRefillCandy *E = Get_MaridiaRefillCandy(k); E->base.properties &= ~kEnemyProps_Invisible; - if ((GetSamusEnemyDelta_Y(k) & 0x8000u) != 0) { - R20_ = 0; - R18_ = FUNC16(Enemy_GrappleReact_NoInteract_A3); - Enemy_SubPos_Y(k); + if ((GetSamusEnemyDelta_Y(k) & 0x8000) != 0) { + Enemy_SubPos_Y(k, 0x8000); } else { --E->mrcy_var_D; MaridiaRefillCandy_Func_4(); @@ -1747,24 +1620,14 @@ void MaridiaRefillCandy_Func_2(uint16 k) { // 0xA3B4A8 void MaridiaRefillCandy_Func_3(uint16 k) { // 0xA3B4D6 Enemy_MaridiaRefillCandy *E = Get_MaridiaRefillCandy(k); - if (E->mrcy_var_D) { - int v2; - v2 = E->mrcy_var_00 >> 1; - R20_ = g_word_A3B415[v2]; - R18_ = g_word_A3B415[v2 + 1]; - Enemy_AddPos_X(k); - if (!CheckIfEnemyIsOnScreen()) { -LABEL_3: - MaridiaRefillCandy_Func_4(); - return; - } - } else { - int v3 = E->mrcy_var_00 >> 1; - R20_ = g_word_A3B415[v3]; - R18_ = g_word_A3B415[v3 + 1]; - Enemy_SubPos_X(k); - if (!CheckIfEnemyIsOnScreen()) - goto LABEL_3; + int v2 = E->mrcy_var_00 >> 1; + if (E->mrcy_var_D) + Enemy_AddPos_X(k, __PAIR32__(g_word_A3B415[v2], g_word_A3B415[v2 + 1])); + else + Enemy_SubPos_X(k, __PAIR32__(g_word_A3B415[v2], g_word_A3B415[v2 + 1])); + if (!CheckIfEnemyIsOnScreen()) { + MaridiaRefillCandy_Func_4(); + return; } E->base.properties |= kEnemyProps_Invisible; E->base.x_pos = E->mrcy_var_B; @@ -1802,12 +1665,12 @@ void NorfairSlowFireball_Init(void) { // 0xA3B66F void NorfairSlowFireball_Func_1(void) { // 0xA3B6F9 uint16 current_instruction = gEnemyData(cur_enemy_index)->current_instruction; - while (current_instruction) - ; + if (current_instruction) + Unreachable(); } const uint16 *Bang_Instr_1(uint16 k, const uint16 *jp) { // 0xA3BA78 - QueueSfx2_Max6(0x56u); + QueueSfx2_Max6(0x56); return jp; } @@ -1827,8 +1690,8 @@ void Bang_Init(void) { // 0xA3BAB3 E->bang_var_20 = 0; E->bang_var_21 = 0; E->bang_var_22 = 0; - E->bang_var_0B = g_word_A3BA84[(uint16)(2 * LOBYTE(E->bang_parameter_2)) >> 1]; - int v1 = (uint16)(4 * HIBYTE(E->bang_parameter_2)) >> 1; + E->bang_var_0B = g_word_A3BA84[LOBYTE(E->bang_parameter_2)]; + int v1 = 2 * HIBYTE(E->bang_parameter_2); uint16 v2 = g_word_A3BC6A[v1]; E->bang_var_0C = v2; E->bang_var_0D = v2; @@ -1887,8 +1750,8 @@ void Bang_Func_3(void) { // 0xA3BB66 EnemyDeathAnimation(cur_enemy_index, v8); uint16 v9 = cur_enemy_index; Enemy_Bang *E = Get_Bang(cur_enemy_index + 64); - E->base.properties |= 0x200u; - enemy_drawing_queue[(v9 >> 1) + 97] |= 0x200u; + E->base.properties |= 0x200; + enemy_drawing_queue[(v9 >> 1) + 97] |= 0x200; } else { ++E0->bang_var_20; Bang_Func_18(); @@ -1899,7 +1762,6 @@ void Bang_Func_3(void) { // 0xA3BB66 uint16 Bang_Func_4(uint16 a) { // 0xA3BBEB int i; - enemy_bottom_border_collision = a; if (!sign16(projectile_counter - 5)) return 1; for (i = 0; projectile_damage[i >> 1]; i += 2) @@ -1908,11 +1770,10 @@ uint16 Bang_Func_4(uint16 a) { // 0xA3BBEB int v3 = i >> 1; projectile_x_pos[v3] = E->base.x_pos; projectile_y_pos[v3] = E->base.y_pos; - projectile_dir[v3] = enemy_bottom_border_collision; + projectile_dir[v3] = a; projectile_type[v3] = equipped_beams & 0xF | 0x10; ++projectile_counter; - R20_ = i; - ProjectileReflection(); + ProjectileReflection(i); projectile_damage[v3] = E->bang_var_E; QueueSfx1_Max6(g_word_A3BC4A[projectile_type[v3] & 0xF]); return 0; @@ -1934,7 +1795,6 @@ void Bang_Func_6(uint16 k) { // 0xA3BCA5 } void Bang_Func_7(uint16 k) { // 0xA3BCC1 - ; } void Bang_Func_8(uint16 k) { // 0xA3BCC5 @@ -1975,10 +1835,8 @@ void Bang_Func_11(uint16 k) { // 0xA3BD2C } void Bang_Func_12(void) { // 0xA3BD4F - int16 v1; - Enemy_Bang *E = Get_Bang(cur_enemy_index); - v1 = E->bang_var_0C - 1; + int16 v1 = E->bang_var_0C - 1; E->bang_var_0C = v1; if (v1 < 0) { E->bang_var_0C = E->bang_var_0D; @@ -1990,10 +1848,8 @@ void Bang_Func_12(void) { // 0xA3BD4F } void Bang_Func_13(void) { // 0xA3BD89 - int16 v1; - Enemy_Bang *E = Get_Bang(cur_enemy_index); - v1 = E->bang_var_0C - 1; + int16 v1 = E->bang_var_0C - 1; E->bang_var_0C = v1; if (v1 < 0) { E->bang_var_0C = E->bang_var_0E; @@ -2003,63 +1859,27 @@ void Bang_Func_13(void) { // 0xA3BD89 } void Bang_Func_14(void) { // 0xA3BDB9 - R18_ = kSine16bit[(uint8)(Get_Bang(cur_enemy_index)->bang_var_01 + 64)]; - if ((R18_ & 0x8000u) != 0) - Get_Bang(cur_enemy_index)->bang_var_07 = 1; - R22_ = (uint16)Abs16(R18_) >> 8; Enemy_Bang *E = Get_Bang(cur_enemy_index); - R24_ = E->bang_var_0A; - Bang_Func_16(); - R22_ = R28_; - R24_ = R30_; - if (E->bang_var_07) { - Bang_Func_17(); - R22_ = R28_; - R24_ = R30_; - } - uint16 x_subpos = E->base.x_subpos; - bool v5 = __CFADD__uint16(R22_, x_subpos); - E->base.x_subpos = R22_ + x_subpos; - E->base.x_pos += R24_ + v5; + uint16 r18 = kSine16bit[(uint8)(E->bang_var_01 + 64)]; + if ((r18 & 0x8000) != 0) + E->bang_var_07 = 1; + uint32 t = ((uint16)Abs16(r18) >> 8) * E->bang_var_0A; + if (E->bang_var_07) + t = -(int32)t; + t = t + E->base.x_subpos; + E->base.x_subpos = t, E->base.x_pos = t >> 16; } void Bang_Func_15(void) { // 0xA3BE1C - R18_ = kSine16bit[(uint8)Get_Bang(cur_enemy_index)->bang_var_01]; - if ((R18_ & 0x8000u) != 0) - Get_Bang(cur_enemy_index)->bang_var_08 = 1; - R22_ = (uint16)Abs16(R18_) >> 8; Enemy_Bang *E = Get_Bang(cur_enemy_index); - R24_ = E->bang_var_0A; - Bang_Func_16(); - R22_ = R28_; - R24_ = R30_; - if (E->bang_var_08) { - Bang_Func_17(); - R22_ = R28_; - R24_ = R30_; - } - uint16 y_subpos = E->base.y_subpos; - bool v5 = __CFADD__uint16(R22_, y_subpos); - E->base.y_subpos = R22_ + y_subpos; - E->base.y_pos += R24_ + v5; -} - -void Bang_Func_16(void) { // 0xA3BE7B - R28_ = Mult8x8(R22_, R24_); - uint16 prod = Mult8x8(R22_, HIBYTE(R24_)); - R30_ = (prod & 0xFF00) >> 8; - uint16 v1 = prod << 8; - bool v2 = __CFADD__uint16(R28_, v1); - R28_ += v1; - if (v2) - ++R30_; -} - -void Bang_Func_17(void) { // 0xA3BEBE - if (R22_ || R24_) { - R28_ = -R22_; - R30_ = ~R24_; - } + uint16 r18 = kSine16bit[(uint8)E->bang_var_01]; + if ((r18 & 0x8000) != 0) + E->bang_var_08 = 1; + uint32 t = ((uint16)Abs16(r18) >> 8) * E->bang_var_0A; + if (E->bang_var_08) + t = -(int32)t; + t = t + E->base.y_subpos; + E->base.y_subpos = t, E->base.y_pos = t >> 16; } void Bang_Func_18(void) { // 0xA3BEDA @@ -2076,8 +1896,7 @@ void Bang_Func_18(void) { // 0xA3BEDA void Bang_Shot(void) { // 0xA3BEFD Enemy_Bang *E = Get_Bang(cur_enemy_index); if (E->bang_var_F != 0xBCC1) { - E->bang_var_01 = g_word_A3BA94[(uint16)(2 - * (projectile_dir[collision_detection_index] & 0xF)) >> 1]; + E->bang_var_01 = g_word_A3BA94[projectile_dir[collision_detection_index] & 0xF]; E->bang_var_F = FUNC16(Bang_Func_11); E->bang_var_07 = 0; E->bang_var_08 = 0; @@ -2089,7 +1908,7 @@ void Bang_Shot(void) { // 0xA3BEFD Bang_Func_18(); int v1 = collision_detection_index; E->bang_var_E += projectile_damage[v1]; - projectile_dir[v1] |= 0x10u; + projectile_dir[v1] |= 0x10; if (E->bang_var_20 == 9) E->bang_var_D = 1; } @@ -2125,7 +1944,7 @@ void Skree_Main(void) { // 0xA3C6C7 void Skree_Func_1(void) { // 0xA3C6D5 Enemy_Skree *E = Get_Skree(cur_enemy_index); - if (abs16(E->base.x_pos - samus_x_pos) < 0x30u) { + if (abs16(E->base.x_pos - samus_x_pos) < 0x30) { ++E->skree_var_C; Skree_Func_5(); E->skree_var_B = FUNC16(Skree_Func_2); @@ -2139,28 +1958,23 @@ void Skree_Func_2(uint16 k) { // 0xA3C6F7 ++E->skree_var_C; Skree_Func_5(); E->skree_var_B = FUNC16(Skree_Func_3); - QueueSfx2_Max6(0x5Bu); + QueueSfx2_Max6(0x5B); } } void Skree_Func_3(void) { // 0xA3C716 Enemy_Skree *E = Get_Skree(cur_enemy_index); E->skree_var_A = 21; - R20_ = 6; - R18_ = 0; uint16 v1 = E->base.properties | 3; E->base.properties = v1; - if (EnemyFunc_BF8A(cur_enemy_index, v1) & 1) { + if (EnemyFunc_BF8A(cur_enemy_index, v1, INT16_SHL16(6)) & 1) { E->base.instruction_timer = 1; E->base.timer = 0; E->skree_var_B = FUNC16(Skree_Func_4); - QueueSfx2_Max6(0x5Cu); + QueueSfx2_Max6(0x5C); } else { E->base.y_pos += 6; - varE24 = 1; - if ((int16)(E->base.x_pos - samus_x_pos) >= 0) - varE24 = -1; - E->base.x_pos += varE24; + E->base.x_pos += ((int16)(E->base.x_pos - samus_x_pos) >= 0) ? -1 : 1; } } @@ -2174,7 +1988,7 @@ void Skree_Func_4(void) { // 0xA3C77F } else { if (E->skree_var_A == 8) { uint16 v2 = cur_enemy_index; - SpawnEnemyProjectileWithGfx(8u, cur_enemy_index, addr_stru_868BC2); + SpawnEnemyProjectileWithGfx(8, cur_enemy_index, addr_stru_868BC2); SpawnEnemyProjectileWithGfx(0, v2, addr_stru_868BD0); SpawnEnemyProjectileWithGfx(0, v2, addr_stru_868BDE); SpawnEnemyProjectileWithGfx(0, v2, addr_stru_868BEC); @@ -2261,14 +2075,13 @@ void MaridiaSnail_Init(void) { // 0xA3CDE2 void MaridiaSnail_Func_2(uint16 k, uint16 j) { // 0xA3CE27 int v2 = j >> 1; - R18_ = g_word_A3CD82[v2]; - R20_ = g_word_A3CD82[v2 + 1]; - R22_ = g_word_A3CD82[v2 + 2]; - R24_ = g_word_A3CD82[v2 + 3]; + uint16 r18 = g_word_A3CD82[v2]; + uint16 r20 = g_word_A3CD82[v2 + 1]; + uint16 r22 = g_word_A3CD82[v2 + 2]; + uint16 r24 = g_word_A3CD82[v2 + 3]; Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); - int v4 = (uint16)(2 * E->msl_parameter_1) >> 1; - E->msl_var_A = R20_ + (R18_ ^ g_word_A3CCA2[v4]); - E->msl_var_B = R24_ + (R22_ ^ g_word_A3CCA2[v4]); + E->msl_var_A = r20 + (r18 ^ g_word_A3CCA2[E->msl_parameter_1]); + E->msl_var_B = r24 + (r22 ^ g_word_A3CCA2[E->msl_parameter_1]); } void MaridiaSnail_Func_3(uint16 k) { // 0xA3CE57 @@ -2325,7 +2138,7 @@ void MaridiaSnail_Func_6(uint16 k) { // 0xA3CF11 if (samus_has_momentum_flag || E->msl_var_F != FUNC16(nullsub_215)) goto LABEL_11; LABEL_10: - E->base.properties |= 0x8000u; + E->base.properties |= 0x8000; return; } if (!samus_has_momentum_flag) { @@ -2334,76 +2147,52 @@ LABEL_10: goto LABEL_10; } LABEL_11: - E->base.properties &= 0x7FFFu; + E->base.properties &= 0x7FFF; +} + +static uint32 Shift8AddMagn(int16 a, int s) { + int32 r = (a << 8); + r += (r < 0) ? -(s << 16) : (s << 16); + return r; } void MaridiaSnail_Func_7(uint16 k) { // 0xA3CF60 Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); - if (E->msl_var_07 >= 4u) { - R18_ = 0; - R20_ = 0; - MaridiaSnail_Func_8(E->msl_var_B); - if (EnemyFunc_BC76(k) & 1) + if (E->msl_var_07 >= 4) { + if (EnemyFunc_BC76(k, Shift8AddMagn(E->msl_var_B, 7))) + return; + } else { + if (EnemyFunc_BBBF(k, Shift8AddMagn(E->msl_var_A, 7))) return; - goto LABEL_5; } - R18_ = 0; - R20_ = 0; - MaridiaSnail_Func_8(E->msl_var_A); - if (!(EnemyFunc_BBBF(k) & 1)) - LABEL_5: MaridiaSnail_Func_14(k); } -void MaridiaSnail_Func_8(uint16 a) { // 0xA3CF8F - if ((a & 0x8000u) != 0) - --R20_; - R19_ = a; - uint16 v1; - if ((R20_ & 0x8000u) == 0) - v1 = R20_ + 7; - else - v1 = R20_ - 7; - R20_ = v1; -} - void MaridiaSnail_Func_9(uint16 k) { // 0xA3CFA6 - uint16 v1; - if (Get_MaridiaSnail(k)->msl_var_05) - v1 = addr_stru_A3CD22; - else - v1 = addr_stru_A3CCE2; - MaridiaSnail_D07E(k, v1); + uint16 v1 = Get_MaridiaSnail(k)->msl_var_05 ? addr_stru_A3CD22 : addr_stru_A3CCE2; + MaridiaSnail_D07E(k, RomPtr_A3(v1)); } void MaridiaSnail_CFB7(uint16 k) { // 0xA3CFB7 - MaridiaSnail_D002(k, addr_stru_A3CCEA); + MaridiaSnail_D002(k, RomPtr_A3(addr_stru_A3CCEA)); } void MaridiaSnail_CFBD(uint16 k) { // 0xA3CFBD - uint16 v1; - if (Get_MaridiaSnail(k)->msl_var_05) - v1 = addr_stru_A3CD2A; - else - v1 = addr_stru_A3CCF2; - MaridiaSnail_D07E(k, v1); + uint16 v1 = Get_MaridiaSnail(k)->msl_var_05 ? addr_stru_A3CD2A : addr_stru_A3CCF2; + MaridiaSnail_D07E(k, RomPtr_A3(v1)); } void MaridiaSnail_CFCE(uint16 k) { // 0xA3CFCE - MaridiaSnail_D002(k, addr_stru_A3CCFA); + MaridiaSnail_D002(k, RomPtr_A3(addr_stru_A3CCFA)); } void MaridiaSnail_CFD4(uint16 k) { // 0xA3CFD4 - uint16 v1; - if (Get_MaridiaSnail(k)->msl_var_05) - v1 = addr_stru_A3CD32; - else - v1 = addr_stru_A3CD02; - MaridiaSnail_D07E(k, v1); + uint16 v1 = Get_MaridiaSnail(k)->msl_var_05 ? addr_stru_A3CD32 : addr_stru_A3CD02; + MaridiaSnail_D07E(k, RomPtr_A3(v1)); } void MaridiaSnail_CFE5(uint16 k) { // 0xA3CFE5 - MaridiaSnail_D002(k, addr_stru_A3CD0A); + MaridiaSnail_D002(k, RomPtr_A3(addr_stru_A3CD0A)); } void MaridiaSnail_CFEB(uint16 k) { // 0xA3CFEB @@ -2412,93 +2201,48 @@ void MaridiaSnail_CFEB(uint16 k) { // 0xA3CFEB v1 = addr_stru_A3CD3A; else v1 = addr_stru_A3CD12; - MaridiaSnail_D07E(k, v1); + MaridiaSnail_D07E(k, RomPtr_A3(v1)); } void MaridiaSnail_CFFC(uint16 k) { // 0xA3CFFC - MaridiaSnail_D002(k, addr_stru_A3CD1A); + MaridiaSnail_D002(k, RomPtr_A3(addr_stru_A3CD1A)); } -void MaridiaSnail_D002(uint16 k, uint16 j) { // 0xA3D002 - int16 msl_var_A; - int16 msl_var_B; - +void MaridiaSnail_D002(uint16 k, const uint8 *j) { // 0xA3D002 MaridiaSnail_Func_10(k, j); - R18_ = 0; - R20_ = 0; Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); - msl_var_A = E->msl_var_A; - if (msl_var_A < 0) - --R20_; - R19_ = msl_var_A; - uint16 v4; - if ((R20_ & 0x8000u) == 0) - v4 = R20_ + 1; - else - v4 = R20_ - 1; - R20_ = v4; - uint8 rv = Enemy_MoveRight_ProcessSlopes(k); + uint8 rv = Enemy_MoveRight_ProcessSlopes(k, Shift8AddMagn(E->msl_var_A, 1)); MaridiaSnail_Func_11(k, j); if (rv) { E->msl_var_E = 0; uint8 carry = EnemyFunc_C8AD(k); MaridiaSnail_Func_12(k, carry); - R18_ = 0; - R20_ = 0; - msl_var_B = E->msl_var_B; - if (msl_var_B < 0) - --R20_; - R19_ = msl_var_B; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, INT16_SHL8(E->msl_var_B))) { E->msl_var_A = -E->msl_var_A; - const uint8 *v6 = RomPtr_A3(j); - MaridiaSnail_Func_13(k, GET_WORD(v6 + 6)); + MaridiaSnail_Func_13(k, GET_WORD(j + 6)); } } else { uint16 v7 = E->msl_var_E + 1; E->msl_var_E = v7; if (sign16(v7 - 4)) { E->msl_var_B = -E->msl_var_B; - const uint8 *v8 = RomPtr_A3(j); - MaridiaSnail_Func_13(k, GET_WORD(v8 + 4)); + MaridiaSnail_Func_13(k, GET_WORD(j + 4)); } else { MaridiaSnail_Func_14(k); } } } -void MaridiaSnail_D07E(uint16 k, uint16 j) { // 0xA3D07E - int16 msl_var_B; - int16 msl_var_A; - +void MaridiaSnail_D07E(uint16 k, const uint8 *j) { // 0xA3D07E MaridiaSnail_Func_10(k, j); - R18_ = 0; - R20_ = 0; Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); - msl_var_B = E->msl_var_B; - if (msl_var_B < 0) - --R20_; - R19_ = msl_var_B; - uint16 v4; - if ((R20_ & 0x8000u) == 0) - v4 = R20_ + 1; - else - v4 = R20_ - 1; - R20_ = v4; - uint8 rv = Enemy_MoveDown(k); + uint8 rv = Enemy_MoveDown(k, Shift8AddMagn(E->msl_var_B, 1)); MaridiaSnail_Func_11(k, j); if (rv) { E->msl_var_E = 0; - R18_ = 0; - R20_ = 0; - msl_var_A = E->msl_var_A; - if (msl_var_A < 0) - --R20_; - R19_ = msl_var_A; - if (Enemy_MoveRight_ProcessSlopes(k) & 1) { + if (Enemy_MoveRight_ProcessSlopes(k, INT16_SHL8(E->msl_var_A))) { E->msl_var_B = -E->msl_var_B; - const uint8 *v6 = RomPtr_A3(j); - MaridiaSnail_Func_13(k, GET_WORD(v6 + 6)); + MaridiaSnail_Func_13(k, GET_WORD(j + 6)); } else { uint8 carry = EnemyFunc_C8AD(k); MaridiaSnail_Func_12(k, carry); @@ -2508,32 +2252,29 @@ void MaridiaSnail_D07E(uint16 k, uint16 j) { // 0xA3D07E E->msl_var_E = v7; if (sign16(v7 - 4)) { E->msl_var_A = -E->msl_var_A; - const uint8 *v8 = RomPtr_A3(j); - MaridiaSnail_Func_13(k, GET_WORD(v8 + 4)); + MaridiaSnail_Func_13(k, GET_WORD(j + 4)); } else { MaridiaSnail_Func_14(k); } } } -void MaridiaSnail_Func_10(uint16 k, uint16 j) { // 0xA3D0F8 +void MaridiaSnail_Func_10(uint16 k, const uint8 *j) { // 0xA3D0F8 Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); - const uint8 *v3 = RomPtr_A3(j); - E->base.x_pos += GET_WORD(v3); - E->base.y_pos += GET_WORD(v3 + 2); + E->base.x_pos += GET_WORD(j); + E->base.y_pos += GET_WORD(j + 2); } -void MaridiaSnail_Func_11(uint16 k, uint16 j) { // 0xA3D10D +void MaridiaSnail_Func_11(uint16 k, const uint8 *j) { // 0xA3D10D Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); - const uint8 *v3 = RomPtr_A3(j); - E->base.x_pos -= GET_WORD(v3); - E->base.y_pos = E->base.y_pos - GET_WORD(v3 + 2); + E->base.x_pos -= GET_WORD(j); + E->base.y_pos -= GET_WORD(j + 2); } void MaridiaSnail_Func_12(uint16 k, uint16 carry) { // 0xA3D124 Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); if (!carry) { - if ((uint16)(E->msl_var_04 + 1) >= 0x10u) + if ((uint16)(E->msl_var_04 + 1) >= 0x10) E->msl_var_05 = 0; else ++E->msl_var_04; @@ -2556,7 +2297,7 @@ void MaridiaSnail_Func_14(uint16 k) { // 0xA3D164 if (E->msl_var_08 != 3) { E->msl_var_08 = 3; E->msl_var_F = FUNC16(MaridiaSnail_Func_15); - int v2 = (uint16)(4 * E->msl_var_C) >> 1; + int v2 = 2 * E->msl_var_C; E->base.current_instruction = g_off_A3D1AB[v2]; E->msl_var_D = g_off_A3D1AB[v2 + 1]; E->base.instruction_timer = 1; @@ -2569,37 +2310,32 @@ void MaridiaSnail_Func_14(uint16 k) { // 0xA3D164 } void MaridiaSnail_Func_15(uint16 k) { // 0xA3D1B3 - int16 msl_var_01; - Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); if (E->msl_var_08 != 3) { - R18_ = E->msl_var_02; - R20_ = E->msl_var_03; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->msl_var_03, E->msl_var_02))) { E->msl_var_02 = -E->msl_var_02; E->msl_var_03 = -E->msl_var_03; E->msl_var_20 = 1; - QueueSfx2_Max3(0x70u); + QueueSfx2_Max3(0x70); } else { - if ((E->msl_var_03 & 0x8000u) != 0) { - R22_ = 4096; - R24_ = 0; + uint16 r22, r24; + if ((E->msl_var_03 & 0x8000) != 0) { + r22 = 4096; + r24 = 0; } else { - R22_ = -4096; - R24_ = -1; + r22 = -4096; + r24 = -1; } uint16 msl_var_02 = E->msl_var_02; - bool v3 = __CFADD__uint16(R22_, msl_var_02); - E->msl_var_02 = R22_ + msl_var_02; - uint16 v4 = R24_ + v3 + E->msl_var_03; + bool v3 = __CFADD__uint16(r22, msl_var_02); + E->msl_var_02 = r22 + msl_var_02; + uint16 v4 = r24 + v3 + E->msl_var_03; if (v4) E->msl_var_03 = v4; } } - R18_ = E->msl_var_00; - R20_ = E->msl_var_01; - if (Enemy_MoveDown(k) & 1) { - msl_var_01 = E->msl_var_01; + if (Enemy_MoveDown(k, __PAIR32__(E->msl_var_01, E->msl_var_00))) { + int16 msl_var_01 = E->msl_var_01; if (msl_var_01 >= 0 && sign16(msl_var_01 - 3)) { E->msl_var_03 = 0; E->msl_var_02 = 0; @@ -2616,7 +2352,7 @@ void MaridiaSnail_Func_15(uint16 k) { // 0xA3D1B3 MaridiaSnail_Func_18(k); MaridiaSnail_Func_16(k); } - E->base.properties = E->msl_var_C | E->base.properties & ~3u; + E->base.properties = E->msl_var_C | E->base.properties & ~3; StoneZoomer_E67A(k); E->msl_var_F = FUNC16(nullsub_215); E->base.current_instruction = E->msl_var_D; @@ -2647,32 +2383,21 @@ uint8 MaridiaSnail_Func_17(uint16 k) { // 0xA3D315 Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); if (E->msl_var_05) return 0; - uint16 msl_var_07 = E->msl_var_07; - if (msl_var_07 >= 4u) + if (E->msl_var_07 >= 4) return MaridiaSnail_Func_18(k) & 1; - if ((msl_var_07 & 1) != 0) { - uint16 y_pos = E->base.y_pos; - if (y_pos >= samus_y_pos) - return MaridiaSnail_Func_19(k) & 1; - return y_pos >= samus_y_pos; + if ((E->msl_var_07 & 1) != 0) { + return (E->base.y_pos >= samus_y_pos) ? MaridiaSnail_Func_19(k) : 0; } else { - if (E->base.y_pos < samus_y_pos) - return MaridiaSnail_Func_19(k) & 1; - return 0; + return (E->base.y_pos < samus_y_pos) ? MaridiaSnail_Func_19(k) : 0; } } uint8 MaridiaSnail_Func_18(uint16 k) { // 0xA3D33E Enemy_MaridiaSnail *E = Get_MaridiaSnail(k); if (E->msl_var_C) { - uint16 x_pos = E->base.x_pos; - if (x_pos >= samus_x_pos) - return MaridiaSnail_Func_19(k) & 1; - return x_pos >= samus_x_pos; + return (E->base.x_pos >= samus_x_pos) ? MaridiaSnail_Func_19(k) : 0; } else { - if (E->base.x_pos < samus_x_pos) - return MaridiaSnail_Func_19(k) & 1; - return 0; + return (E->base.x_pos < samus_x_pos) ? MaridiaSnail_Func_19(k) : 0; } } @@ -2682,10 +2407,10 @@ uint8 MaridiaSnail_Func_19(uint16 k) { // 0xA3D356 return 0; uint16 v2 = g_word_A3CDC2[E->msl_var_07]; E->msl_var_07 = v2; - E->base.current_instruction = *(VoidP *)((uint8 *)&g_stru_A3CD42[0].field_0 + (uint16)(8 * v2)); - E->base.properties = *(uint16 *)((uint8 *)&g_stru_A3CD42[0].field_2 + (uint16)(8 * v2)) | E->base.properties & ~3u; - E->msl_var_D = *(VoidP *)((uint8 *)&g_stru_A3CD42[0].field_4 + (uint16)(8 * v2)); - E->msl_var_C = *(uint16 *)((uint8 *)&g_stru_A3CD42[0].field_6 + (uint16)(8 * v2)); + E->base.current_instruction = *(VoidP *)((uint8 *)&g_stru_A3CD42[0].field_0 + (8 * v2)); + E->base.properties = *(uint16 *)((uint8 *)&g_stru_A3CD42[0].field_2 + (8 * v2)) | E->base.properties & ~3; + E->msl_var_D = *(VoidP *)((uint8 *)&g_stru_A3CD42[0].field_4 + (8 * v2)); + E->msl_var_C = *(uint16 *)((uint8 *)&g_stru_A3CD42[0].field_6 + (8 * v2)); MaridiaSnail_Func_2(k, 8 * v2); MaridiaSnail_Func_3(k); E->msl_var_05 = 1; @@ -2701,7 +2426,7 @@ void MaridiaSnail_Touch(void) { // 0xA3D3B0 && (E->msl_var_F == 0xD1B3 || samus_has_momentum_flag)) { MaridiaSnail_Func_22(cur_enemy_index); if (E->msl_var_F == 0xD1B3) - QueueSfx2_Max3(0x70u); + QueueSfx2_Max3(0x70); } else if (E->msl_var_F != 0xCF5F && E->msl_var_08 != 4 && E->msl_var_08 != 3) { Enemy_NormalTouchAI_A3(); E->msl_parameter_1 = E->msl_var_06; @@ -2712,34 +2437,31 @@ void MaridiaSnail_Touch(void) { // 0xA3D3B0 } uint8 MaridiaSnail_Func_20(uint16 k) { // 0xA3D421 - R18_ = ((uint16)(joypad1_lastkeys & 0x300) >> 8) - 1; - R20_ = Get_MaridiaSnail(k)->msl_var_C & 1; + uint16 r20 = Get_MaridiaSnail(k)->msl_var_C & 1; if ((uint16)(joypad1_lastkeys & 0x300) >> 8 == 1) { - if (R20_) + if (r20) return 0; - } else if (!R20_) { + } else if (!r20) { return 0; } return 1; } uint8 MaridiaSnail_Func_21(uint16 k) { // 0xA3D446 - if ((Get_MaridiaSnail(k)->msl_var_A & 0x8000u) != 0) + if ((Get_MaridiaSnail(k)->msl_var_A & 0x8000) != 0) return samus_pose_x_dir == 8; return samus_pose_x_dir == 4; } void MaridiaSnail_Shot(void) { // 0xA3D469 - int16 v0; - - v0 = projectile_type[collision_detection_index] & 0xFF00; + uint16 v0 = projectile_type[collision_detection_index] & 0xFF00; if (v0 == 768 || v0 == 1280) { Enemy_NormalShotAI_A3(); } else { uint16 msl_var_08 = Get_MaridiaSnail(cur_enemy_index)->msl_var_08; if (msl_var_08 != 3 && msl_var_08 != 4) MaridiaSnail_Func_23(cur_enemy_index); - QueueSfx2_Max3(0x70u); + QueueSfx2_Max3(0x70); } } @@ -2755,7 +2477,7 @@ void MaridiaSnail_Func_22(uint16 k) { // 0xA3D49F E->msl_var_02 = absolute_moved_last_frame_x_fract; uint16 v3 = absolute_moved_last_frame_x; E->msl_var_03 = absolute_moved_last_frame_x; - if (v3 >= 0x10u) + if (v3 >= 0x10) v3 = 15; int v4 = (uint16)(4 * v3) >> 1; E->msl_var_00 = g_word_A3D517[v4]; @@ -2776,10 +2498,7 @@ void MaridiaSnail_Func_23(uint16 k) { // 0xA3D557 E->base.instruction_timer = 1; E->base.timer = 0; E->msl_var_01 = -1; - if (samus_pose_x_dir == 4) - E->msl_var_03 = -1; - else - E->msl_var_03 = 1; + E->msl_var_03 = (samus_pose_x_dir == 4) ? -1 : 1; } void Reflec_Func_1(void) { // 0xA3DB0C @@ -2787,13 +2506,12 @@ void Reflec_Func_1(void) { // 0xA3DB0C variables_for_enemy_graphics_drawn_hook[2] = 16; uint16 v0 = variables_for_enemy_graphics_drawn_hook[0]; uint16 v1 = 8 * variables_for_enemy_graphics_drawn_hook[1]; - remaining_enemy_spritemap_entries = 4; + int n = 4; do { palette_buffer[(v0 >> 1) + 137] = g_word_A3DABC[v1 >> 1]; v1 += 2; v0 += 2; - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + } while (--n); variables_for_enemy_graphics_drawn_hook[1] = (LOBYTE(variables_for_enemy_graphics_drawn_hook[1]) + 1) & 7; } } @@ -2809,29 +2527,19 @@ void Reflec_Init(void) { // 0xA3DBD3 E->base.current_instruction = g_off_A3DC0B[E->reflec_parameter_1]; enemy_gfx_drawn_hook.addr = FUNC16(Reflec_Func_1); *(uint16 *)&enemy_gfx_drawn_hook.bank = 163; - variables_for_enemy_graphics_drawn_hook[0] = (uint8)((uint16)((16 * E->base.palette_index) & 0xFF00) >> 8); + variables_for_enemy_graphics_drawn_hook[0] = ((16 * E->base.palette_index) & 0xFF00) >> 8; variables_for_enemy_graphics_drawn_hook[2] = 16; } -static Func_V *const off_A3DD2E[64] = { // 0xA3DC1C - 0, Reflec_Func_2, 0, Reflec_Func_2, 0, 0, Reflec_Func_3, 0, Reflec_Func_3, 0, 0, 0, 0, 0, 0, 0, - Reflec_Func_4, 0, Reflec_Func_5, 0, Reflec_Func_6, Reflec_Func_6, 0, Reflec_Func_7, 0, Reflec_Func_4, 0, 0, 0, 0, 0, 0, - 0, Reflec_Func_8, 0, Reflec_Func_9, 0, 0, Reflec_Func_9, 0, Reflec_Func_8, 0, 0, 0, 0, 0, 0, 0, - Reflec_Func_10, 0, Reflec_Func_11, 0, Reflec_Func_12, Reflec_Func_12, 0, Reflec_Func_13, 0, Reflec_Func_10, 0, 0, 0, 0, 0, 0, -}; - void Reflec_Shot(void) { - int16 v4; - uint16 v0 = 2 * collision_detection_index; Enemy_Reflec *EK = Get_Reflec(cur_enemy_index); EK->base.invincibility_timer = 10; - draw_enemy_layer = 32 * EK->reflec_parameter_2; - uint16 v2 = draw_enemy_layer + 2 * (projectile_dir[v0 >> 1] & 0xF); - draw_enemy_layer = v2; + uint16 v2 = 32 * EK->reflec_parameter_2 + 2 * (projectile_dir[v0 >> 1] & 0xF); + uint16 varE32 = v2; int v3 = v2 >> 1; if (g_word_A3DCAE[v3] == 0x8000) { - projectile_dir[v0 >> 1] |= 0x10u; + projectile_dir[v0 >> 1] |= 0x10; printf("Possible bug. What is X?\n"); Enemy_Reflec *ET = Get_Reflec(v2); if (ET->base.health) { @@ -2843,68 +2551,17 @@ void Reflec_Shot(void) { } } } else { - v4 = g_word_A3DCAE[v3]; - if (v4 < 0) { - off_A3DD2E[v3](); - v4 = -g_word_A3DCAE[draw_enemy_layer >> 1]; - } + int16 v4 = g_word_A3DCAE[v3]; + if (v4 < 0) + v4 = -g_word_A3DCAE[varE32 >> 1]; int v5 = v0 >> 1; projectile_dir[v5] = v4; - projectile_type[v5] &= ~0x8000u; - R20_ = v0; - ProjectileReflection(); - QueueSfx2_Max6(0x57u); + projectile_type[v5] &= ~0x8000; + ProjectileReflection(v0); + QueueSfx2_Max6(0x57); } } -void Reflec_Func_2(void) { // 0xA3DDAE - loop_index_end = Get_Reflec(cur_enemy_index)->base.x_pos - 8; -} - -void Reflec_Func_3(void) { // 0xA3DDCF - loop_index_end = Get_Reflec(cur_enemy_index)->base.x_pos + 8; -} - -void Reflec_Func_4(void) { // 0xA3DDF0 - loop_index_end = Get_Reflec(cur_enemy_index)->base.x_pos; -} - -void Reflec_Func_5(void) { // 0xA3DE0D - loop_index_end = Get_Reflec(cur_enemy_index)->base.y_pos; -} - -void Reflec_Func_6(void) { // 0xA3DE2A - loop_index_end = Get_Reflec(cur_enemy_index)->base.x_pos; -} - -void Reflec_Func_7(void) { // 0xA3DE47 - loop_index_end = Get_Reflec(cur_enemy_index)->base.y_pos; -} - -void Reflec_Func_8(void) { // 0xA3DE64 - loop_index_end = Get_Reflec(cur_enemy_index)->base.y_pos + 8; -} - -void Reflec_Func_9(void) { // 0xA3DE85 - loop_index_end = Get_Reflec(cur_enemy_index)->base.y_pos - 8; -} - -void Reflec_Func_10(void) { // 0xA3DEA6 - loop_index_end = Get_Reflec(cur_enemy_index)->base.x_pos; -} - -void Reflec_Func_11(void) { // 0xA3DEC3 - loop_index_end = Get_Reflec(cur_enemy_index)->base.y_pos; -} - -void Reflec_Func_12(void) { // 0xA3DEE0 - loop_index_end = Get_Reflec(cur_enemy_index)->base.x_pos; -} - -void Reflec_Func_13(void) { // 0xA3DEFD - loop_index_end = Get_Reflec(cur_enemy_index)->base.y_pos; -} - const uint16 *WreckedShipOrangeZoomer_Func_1(uint16 k, const uint16 *jp) { // 0xA3DFC2 Get_WreckedShipOrangeZoomer(k)->wsozr_var_F = jp[0]; return jp + 1; @@ -2912,8 +2569,7 @@ const uint16 *WreckedShipOrangeZoomer_Func_1(uint16 k, const uint16 *jp) { // 0 void WreckedShipOrangeZoomer_Init(void) { // 0xA3E043 Enemy_WreckedShipOrangeZoomer *E = Get_WreckedShipOrangeZoomer(cur_enemy_index); - E->base.current_instruction = g_off_A3E03B[(uint16)(2 - * (E->base.current_instruction & 3)) >> 1]; + E->base.current_instruction = g_off_A3E03B[E->base.current_instruction & 3]; E->wsozr_var_F = addr_locret_A3E08A; uint16 v1 = g_word_A3E5F0[E->wsozr_parameter_1]; E->wsozr_var_A = v1; @@ -2932,8 +2588,6 @@ void WreckedShipOrangeZoomer_Main(void) { // 0xA3E08B } void WreckedShipOrangeZoomer_Func_2(uint16 k) { // 0xA3E091 - int16 wsozr_var_A; - int16 wsozr_var_B; int16 v7; uint16 v9; uint16 v12; @@ -2943,28 +2597,10 @@ void WreckedShipOrangeZoomer_Func_2(uint16 k) { // 0xA3E091 E->wsozr_var_03 = E->wsozr_var_F; E->wsozr_var_F = FUNC16(FireZoomer_Func_2); } - R18_ = 0; - R20_ = 0; - wsozr_var_A = E->wsozr_var_A; - if (wsozr_var_A < 0) - --R20_; - R19_ = wsozr_var_A; - uint16 v4; - if ((R20_ & 0x8000u) == 0) - v4 = R20_ + 1; - else - v4 = R20_ - 1; - R20_ = v4; - if (Enemy_MoveRight_ProcessSlopes(k) & 1) { + if (Enemy_MoveRight_ProcessSlopes(k, Shift8AddMagn(E->wsozr_var_A, 1))) { E->wsozr_var_04 = 0; EnemyFunc_C8AD(k); - R18_ = 0; - R20_ = 0; - wsozr_var_B = E->wsozr_var_B; - if (wsozr_var_B < 0) - --R20_; - R19_ = wsozr_var_B; - if (!(Enemy_MoveDown(k) & 1)) { + if (!(Enemy_MoveDown(k, INT16_SHL8(E->wsozr_var_B)))) { if ((int16)(samus_y_pos - E->base.y_pos) >= 0) { v7 = E->wsozr_var_B; if (v7 < 0) @@ -2980,7 +2616,7 @@ void WreckedShipOrangeZoomer_Func_2(uint16 k) { // 0xA3E091 } E->wsozr_var_A = -E->wsozr_var_A; v9 = addr_kWreckedShipOrangeZoomer_Ilist_E01F; - if ((E->wsozr_var_B & 0x8000u) != 0) + if ((E->wsozr_var_B & 0x8000) != 0) v9 = addr_kWreckedShipOrangeZoomer_Ilist_E003; E->base.current_instruction = v9; E->base.instruction_timer = 1; @@ -2990,7 +2626,7 @@ void WreckedShipOrangeZoomer_Func_2(uint16 k) { // 0xA3E091 if (sign16(v11 - 4)) { E->wsozr_var_B = -E->wsozr_var_B; v12 = addr_kWreckedShipOrangeZoomer_Ilist_E01F; - if ((E->wsozr_var_B & 0x8000u) != 0) + if ((E->wsozr_var_B & 0x8000) != 0) v12 = addr_kWreckedShipOrangeZoomer_Ilist_E003; E->base.current_instruction = v12; E->base.instruction_timer = 1; @@ -3002,8 +2638,6 @@ void WreckedShipOrangeZoomer_Func_2(uint16 k) { // 0xA3E091 } void sub_A3E168(uint16 k) { // 0xA3E168 - int16 wsozr_var_B; - int16 wsozr_var_A; int16 v7; uint16 v9; uint16 v12; @@ -3013,45 +2647,25 @@ void sub_A3E168(uint16 k) { // 0xA3E168 E->wsozr_var_03 = E->wsozr_var_F; E->wsozr_var_F = FUNC16(FireZoomer_Func_2); } - R18_ = 0; - R20_ = 0; - - wsozr_var_B = E->wsozr_var_B; - if (wsozr_var_B < 0) - --R20_; - R19_ = wsozr_var_B; - uint16 v4; - if ((R20_ & 0x8000u) == 0) - v4 = R20_ + 1; - else - v4 = R20_ - 1; - R20_ = v4; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, Shift8AddMagn(E->wsozr_var_B, 1))) { E->wsozr_var_04 = 0; - R18_ = 0; - R20_ = 0; - wsozr_var_A = E->wsozr_var_A; - if (wsozr_var_A < 0) - --R20_; - R19_ = wsozr_var_A; - if (!(Enemy_MoveRight_ProcessSlopes(k) & 1)) { + if (!(Enemy_MoveRight_ProcessSlopes(k, INT16_SHL8(E->wsozr_var_A)))) { EnemyFunc_C8AD(k); if ((int16)(samus_x_pos - E->base.x_pos) >= 0) { v7 = E->wsozr_var_A; if (v7 < 0) - LABEL_17: - v7 = -v7; + v7 = -v7; } else { v7 = E->wsozr_var_A; if (v7 >= 0) - goto LABEL_17; + v7 = -v7; } E->wsozr_var_A = v7; return; } E->wsozr_var_B = -E->wsozr_var_B; v9 = addr_kWreckedShipOrangeZoomer_Ilist_DFE7; - if ((E->wsozr_var_A & 0x8000u) != 0) + if ((E->wsozr_var_A & 0x8000) != 0) v9 = addr_kWreckedShipOrangeZoomer_Ilist_DFCB; E->base.current_instruction = v9; E->base.instruction_timer = 1; @@ -3061,7 +2675,7 @@ void sub_A3E168(uint16 k) { // 0xA3E168 if (sign16(v11 - 4)) { E->wsozr_var_A = -E->wsozr_var_A; v12 = addr_kWreckedShipOrangeZoomer_Ilist_DFE7; - if ((E->wsozr_var_A & 0x8000u) != 0) + if ((E->wsozr_var_A & 0x8000) != 0) v12 = addr_kWreckedShipOrangeZoomer_Ilist_DFCB; E->base.current_instruction = v12; E->base.instruction_timer = 1; @@ -3119,40 +2733,18 @@ void StoneZoomer_Main(void) { // 0xA3E6C2 } void FireZoomer_Func_1(uint16 k) { // 0xA3E6C8 - int16 fzr_var_A; - int16 fzr_var_B; - Enemy_FireZoomer *E = Get_FireZoomer(k); if (earthquake_timer == 30 && earthquake_type == 20) { E->fzr_var_03 = E->fzr_var_F; E->fzr_var_F = FUNC16(FireZoomer_Func_2); } - R18_ = 0; - R20_ = 0; - - fzr_var_A = E->fzr_var_A; - if (fzr_var_A < 0) - --R20_; - R19_ = fzr_var_A; - uint16 v4; - if ((R20_ & 0x8000u) == 0) - v4 = R20_ + 1; - else - v4 = R20_ - 1; - R20_ = v4; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, Shift8AddMagn(E->fzr_var_A, 1))) { E->fzr_var_04 = 0; EnemyFunc_C8AD(k); - R18_ = 0; - R20_ = 0; - fzr_var_B = E->fzr_var_B; - if (fzr_var_B < 0) - --R20_; - R19_ = fzr_var_B; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, INT16_SHL8(E->fzr_var_B))) { E->fzr_var_A = -E->fzr_var_A; uint16 fzr_parameter_2 = E->fzr_parameter_2, v7; - if ((E->fzr_var_B & 0x8000u) == 0) + if ((E->fzr_var_B & 0x8000) == 0) v7 = g_off_A3E63C[fzr_parameter_2 >> 1]; else v7 = g_off_A3E630[fzr_parameter_2 >> 1]; @@ -3165,7 +2757,7 @@ void FireZoomer_Func_1(uint16 k) { // 0xA3E6C8 if (sign16(v8 - 4)) { E->fzr_var_B = -E->fzr_var_B; uint16 v9 = E->fzr_parameter_2, v10; - if ((E->fzr_var_B & 0x8000u) == 0) + if ((E->fzr_var_B & 0x8000) == 0) v10 = g_off_A3E63C[v9 >> 1]; else v10 = g_off_A3E630[v9 >> 1]; @@ -3180,9 +2772,7 @@ void FireZoomer_Func_1(uint16 k) { // 0xA3E6C8 void FireZoomer_Func_2(uint16 k) { // 0xA3E785 Enemy_FireZoomer *E = Get_FireZoomer(k); - R18_ = E->fzr_var_01; - R20_ = E->fzr_var_02; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, __PAIR32__(E->fzr_var_02, E->fzr_var_01))) { if (E->fzr_parameter_1 == 255) { E->fzr_var_A = 128; E->fzr_var_B = 128; @@ -3203,33 +2793,19 @@ void FireZoomer_Func_2(uint16 k) { // 0xA3E785 } void FireZoomer_Func_3(uint16 k) { // 0xA3E7F2 - int16 fzr_var_B; Enemy_FireZoomer *E = Get_FireZoomer(k); if (earthquake_timer == 30 && earthquake_type == 20) { E->fzr_var_03 = E->fzr_var_F; E->fzr_var_F = FUNC16(FireZoomer_Func_2); } - R18_ = 0; - R20_ = 0; - - fzr_var_B = E->fzr_var_B; - if (fzr_var_B < 0) - --R20_; - R19_ = fzr_var_B; - uint16 v4; - if ((R20_ & 0x8000u) == 0) - v4 = R20_ + 1; - else - v4 = R20_ - 1; - R20_ = v4; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, Shift8AddMagn(E->fzr_var_B, 1))) { E->fzr_var_04 = 0; - FireZoomer_E8A5(k); - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + int32 amt = FireZoomer_E8A5(k); + if (Enemy_MoveRight_IgnoreSlopes(k, amt)) { E->fzr_var_B = -E->fzr_var_B; uint16 fzr_parameter_2 = E->fzr_parameter_2, v6; - if ((E->fzr_var_A & 0x8000u) == 0) + if ((E->fzr_var_A & 0x8000) == 0) v6 = g_off_A3E654[fzr_parameter_2 >> 1]; else v6 = g_off_A3E648[fzr_parameter_2 >> 1]; @@ -3244,7 +2820,7 @@ void FireZoomer_Func_3(uint16 k) { // 0xA3E7F2 if (sign16(v7 - 4)) { E->fzr_var_A = -E->fzr_var_A; uint16 v8 = E->fzr_parameter_2, v9; - if ((E->fzr_var_A & 0x8000u) == 0) + if ((E->fzr_var_A & 0x8000) == 0) v9 = g_off_A3E654[v8 >> 1]; else v9 = g_off_A3E648[v8 >> 1]; @@ -3257,9 +2833,7 @@ void FireZoomer_Func_3(uint16 k) { // 0xA3E7F2 } } -void FireZoomer_E8A5(uint16 k) { // 0xA3E8A5 - int16 fzr_var_A; - int16 v3; +int32 FireZoomer_E8A5(uint16 k) { // 0xA3E8A5 Enemy_FireZoomer *E = Get_FireZoomer(cur_enemy_index); uint16 xpos = E->base.x_pos; @@ -3268,53 +2842,32 @@ void FireZoomer_E8A5(uint16 k) { // 0xA3E8A5 E->base.y_pos + E->base.y_height - 1; CalculateBlockContainingPixelPos(xpos, ypos); - if ((level_data[cur_block_index] & 0xF000) == 4096 - && (BTS[cur_block_index] & 0x1Fu) >= 5) { + if ((level_data[cur_block_index] & 0xF000) == 4096 && (BTS[cur_block_index] & 0x1F) >= 5) { uint16 v1 = g_word_A3E931[(uint16)(4 * (BTS[cur_block_index] & 0x1F)) >> 1]; - fzr_var_A = E->fzr_var_A; - if (fzr_var_A >= 0) { - Multiply16x16(fzr_var_A, v1); - R18_ = mult_product_lo; - R20_ = mult_product_hi; - } else { - Multiply16x16(-fzr_var_A, v1); - Negate32(&mult_product_hi, &mult_product_lo, &R20_, &R18_); - } + if ((int16)E->fzr_var_A >= 0) + return Multiply16x16(E->fzr_var_A, v1); + else + return -(int32)Multiply16x16(-E->fzr_var_A, v1); } else { - R18_ = 0; - R20_ = 0; - v3 = E->fzr_var_A; - if (v3 < 0) - --R20_; - R19_ = v3; + return INT16_SHL8(E->fzr_var_A); } } void Metroid_Init(void) { // 0xA3EA4F Enemy_Metroid *E = Get_Metroid(cur_enemy_index); E->base.current_instruction = addr_kMetroid_Ilist_E9CF; - R24_ = E->base.vram_tiles_index | E->base.palette_index; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - R22_ = 50; - CreateSpriteAtPos(); - E->metroid_var_00 = R18_; - R24_ = E->base.vram_tiles_index | E->base.palette_index; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - R22_ = 52; - CreateSpriteAtPos(); - E->metroid_var_01 = R18_; + E->metroid_var_00 = CreateSpriteAtPos(E->base.x_pos, E->base.y_pos, 50, E->base.vram_tiles_index | E->base.palette_index); + E->metroid_var_01 = CreateSpriteAtPos(E->base.x_pos, E->base.y_pos, 52, E->base.vram_tiles_index | E->base.palette_index); E->metroid_var_02 = 0; } const uint16 *Metroid_Instr_2(uint16 k, const uint16 *jp) { // 0xA3EAA5 - QueueSfx2_Max6(0x50u); + QueueSfx2_Max6(0x50); return jp; } const uint16 *Metroid_Instr_1(uint16 k, const uint16 *jp) { // 0xA3EAB1 - int v2 = (uint16)(2 * (NextRandom() & 7)) >> 1; + int v2 = NextRandom() & 7; QueueSfx2_Max6(g_word_A3EAD6[v2]); return jp; } @@ -3339,175 +2892,158 @@ void Metroid_Frozen(void) { // 0xA3EAE6 void Metroid_Hurt(void) { // 0xA3EB33 Enemy_Metroid *E = Get_Metroid(cur_enemy_index); if ((E->base.flash_timer & 2) != 0) { - R18_ = E->base.palette_index; + uint16 r18 = E->base.palette_index; int v1 = E->metroid_var_00 >> 1; - sprite_palettes[v1] = R18_ | sprite_palettes[v1] & 0xF1FF; + sprite_palettes[v1] = r18 | sprite_palettes[v1] & 0xF1FF; int v2 = E->metroid_var_01 >> 1; - sprite_palettes[v2] = R18_ | sprite_palettes[v2] & 0xF1FF; + sprite_palettes[v2] = r18 | sprite_palettes[v2] & 0xF1FF; } else { int v3 = E->metroid_var_00 >> 1; - sprite_palettes[v3] &= 0xF1FFu; + sprite_palettes[v3] &= 0xF1FF; uint16 metroid_var_01 = E->metroid_var_01; - sprite_palettes[metroid_var_01 >> 1] &= 0xF1FFu; + sprite_palettes[metroid_var_01 >> 1] &= 0xF1FF; } } -static Func_V *const off_A3EC09[4] = { Metroid_Func_1, Metroid_Func_2, Metroid_Func_3, Metroid_Func_4 }; +static Func_Y_V *const off_A3EC09[4] = { Metroid_Func_1, Metroid_Func_2, Metroid_Func_3, Metroid_Func_4 }; + void Metroid_Main(void) { // 0xA3EB98 Enemy_Metroid *E = Get_Metroid(cur_enemy_index); - draw_enemy_layer = samus_y_pos - 8; - uint16 v0 = 2 * E->metroid_var_F; - off_A3EC09[v0 >> 1](); - R24_ = E->base.vram_tiles_index | E->base.palette_index; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; + off_A3EC09[E->metroid_var_F](samus_y_pos - 8); + uint16 r24 = E->base.vram_tiles_index | E->base.palette_index; int v2 = E->metroid_var_00 >> 1; - sprite_x_pos[v2] = R18_; - sprite_y_pos[v2] = R20_; - sprite_palettes[v2] = R24_; + sprite_x_pos[v2] = E->base.x_pos; + sprite_y_pos[v2] = E->base.y_pos; + sprite_palettes[v2] = r24; sprite_disable_flag[v2] = 0; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; int v4 = E->metroid_var_01 >> 1; - sprite_x_pos[v4] = R18_; - sprite_y_pos[v4] = R20_; - sprite_palettes[v4] = R24_; + sprite_x_pos[v4] = E->base.x_pos; + sprite_y_pos[v4] = E->base.y_pos; + sprite_palettes[v4] = r24; sprite_disable_flag[v4] = 0; } -void Metroid_Func_1(void) { // 0xA3EC11 +void Metroid_Func_1(uint16 varE32) { // 0xA3EC11 int16 v3; int16 v4; int16 v8; int16 v9; - R18_ = 0; - R20_ = 0; Enemy_Metroid *E = Get_Metroid(cur_enemy_index); - R19_ = (uint16)(E->base.y_pos - draw_enemy_layer) >> 2; - if ((R19_ & 0x2000) != 0) - R20_ = (uint8)R20_ | 0xFFC0; + int32 t = INT16_SHL8((int16)(E->base.y_pos - varE32) >> 2); + uint16 r18 = t, r20 = t >> 16; uint16 metroid_var_C = E->metroid_var_C; - bool v2 = metroid_var_C < R18_; - E->metroid_var_C = metroid_var_C - R18_; - v3 = E->metroid_var_D - (v2 + R20_); + bool v2 = metroid_var_C < r18; + E->metroid_var_C = metroid_var_C - r18; + v3 = E->metroid_var_D - (v2 + r20); E->metroid_var_D = v3; if (v3 < 0) { - if ((uint16)v3 >= 0xFFFDu) + if ((uint16)v3 >= 0xFFFD) goto LABEL_9; v4 = -3; } else { - if ((uint16)v3 < 3u) + if ((uint16)v3 < 3) goto LABEL_9; v4 = 3; } E->metroid_var_D = v4; E->metroid_var_C = 0; LABEL_9: - R18_ = E->metroid_var_C; - R20_ = E->metroid_var_D; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(E->metroid_var_D, E->metroid_var_C))) { E->metroid_var_C = 0; E->metroid_var_D = 0; } - R18_ = 0; - R20_ = 0; - R19_ = (uint16)(E->base.x_pos - samus_x_pos) >> 2; - if ((R19_ & 0x2000) != 0) - R20_ = (uint8)R20_ | 0xFFC0; + t = INT16_SHL8((int16)(E->base.x_pos - samus_x_pos) >> 2); + r18 = t, r20 = t >> 16; uint16 metroid_var_A = E->metroid_var_A; - v2 = metroid_var_A < R18_; - E->metroid_var_A = metroid_var_A - R18_; - v8 = E->metroid_var_B - (v2 + R20_); + v2 = metroid_var_A < r18; + E->metroid_var_A = metroid_var_A - r18; + v8 = E->metroid_var_B - (v2 + r20); E->metroid_var_B = v8; if (v8 < 0) { - if ((uint16)v8 >= 0xFFFDu) + if ((uint16)v8 >= 0xFFFD) goto LABEL_19; v9 = -3; } else { - if ((uint16)v8 < 3u) + if ((uint16)v8 < 3) goto LABEL_19; v9 = 3; } E->metroid_var_B = v9; E->metroid_var_A = 0; LABEL_19: - R18_ = E->metroid_var_A; - R20_ = E->metroid_var_B; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(E->metroid_var_B, E->metroid_var_A))) { E->metroid_var_A = 0; E->metroid_var_B = 0; } } -void Metroid_Func_2(void) { // 0xA3ECDC +void Metroid_Func_2(uint16 varE32) { // 0xA3ECDC int16 v1; int16 v5; uint16 v2, v6; - R18_ = 0; - R20_ = 0; + uint16 r18 = 0, r20 = 0; Enemy_Metroid *E = Get_Metroid(cur_enemy_index); - LOBYTE(v1) = (uint16)(draw_enemy_layer - E->base.y_pos) >> 8; - HIBYTE(v1) = draw_enemy_layer - LOBYTE(E->base.y_pos); - R20_ = (uint16)(v1 & 0xFF00) >> 3; - if ((R20_ & 0x1000) != 0) - R20_ |= 0xE000u; - if ((R20_ & 0x8000u) != 0) { - if (R20_ >= 0xFFFDu) + LOBYTE(v1) = (uint16)(varE32 - E->base.y_pos) >> 8; + HIBYTE(v1) = varE32 - LOBYTE(E->base.y_pos); + r20 = (uint16)(v1 & 0xFF00) >> 3; + if ((r20 & 0x1000) != 0) + r20 |= 0xE000; + if ((r20 & 0x8000) != 0) { + if (r20 >= 0xFFFD) goto LABEL_9; v2 = -3; } else { - if (R20_ < 3u) + if (r20 < 3) goto LABEL_9; v2 = 3; } - R20_ = v2; - R18_ = 0; + r20 = v2; + r18 = 0; LABEL_9: - E->metroid_var_C = R18_; - E->metroid_var_D = R20_; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + E->metroid_var_C = r18; + E->metroid_var_D = r20; + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(r20, r18))) { E->metroid_var_C = 0; E->metroid_var_D = 0; } - R18_ = 0; - R20_ = 0; + r18 = 0, r20 = 0; LOBYTE(v5) = (uint16)(samus_x_pos - E->base.x_pos) >> 8; HIBYTE(v5) = samus_x_pos - LOBYTE(E->base.x_pos); - R20_ = (uint16)(v5 & 0xFF00) >> 3; - if ((R20_ & 0x1000) != 0) - R20_ |= 0xE000u; - if ((R20_ & 0x8000u) != 0) { - if (R20_ >= 0xFFFDu) + r20 = (uint16)(v5 & 0xFF00) >> 3; + if ((r20 & 0x1000) != 0) + r20 |= 0xE000; + if ((r20 & 0x8000) != 0) { + if (r20 >= 0xFFFD) goto LABEL_19; v6 = -3; } else { - if (R20_ < 3u) + if (r20 < 3) goto LABEL_19; v6 = 3; } - R20_ = v6; - R18_ = 0; + r20 = v6; + r18 = 0; LABEL_19: - E->metroid_var_A = R18_; - E->metroid_var_B = R20_; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + E->metroid_var_A = r18; + E->metroid_var_B = r20; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(r20, r18))) { E->metroid_var_A = 0; E->metroid_var_B = 0; } } -void Metroid_Func_3(void) { // 0xA3ED8F +void Metroid_Func_3(uint16 varE32) { // 0xA3ED8F Enemy_Metroid *E = Get_Metroid(cur_enemy_index); E->base.x_pos = samus_x_pos; - E->base.y_pos = draw_enemy_layer; + E->base.y_pos = varE32; E->metroid_var_A = 0; E->metroid_var_B = 0; E->metroid_var_C = 0; E->metroid_var_D = 0; } -void Metroid_Func_4(void) { // 0xA3EDAB +void Metroid_Func_4(uint16 varE32) { // 0xA3EDAB Enemy_Metroid *E = Get_Metroid(cur_enemy_index); int v1 = E->metroid_var_E & 3; E->base.x_pos += g_word_A3EA3F[v1]; @@ -3524,29 +3060,17 @@ void Metroid_Func_4(void) { // 0xA3EDAB } void Metroid_Touch(void) { // 0xA3EDEB - int16 v1; - int16 v2; - int16 v3; - int16 v4; - int16 v7; - Enemy_Metroid *E = Get_Metroid(cur_enemy_index); - draw_enemy_layer = samus_y_pos - 8; + uint16 varE32 = samus_y_pos - 8; if (samus_contact_damage_index) { if (E->metroid_var_F != 2) { E->metroid_var_A = 0; E->metroid_var_C = 0; - v1 = 0; - v2 = E->base.x_pos - samus_x_pos; - if (v2 < 0) - v1 = -256; - E->metroid_var_B = v1; + int16 v2 = E->base.x_pos - samus_x_pos; + E->metroid_var_B = (v2 < 0) ? -256 : 0; *(uint16 *)((uint8 *)&E->metroid_var_A + 1) = v2 << 6; - v3 = 0; - v4 = E->base.y_pos - draw_enemy_layer; - if (v4 < 0) - v3 = -256; - E->metroid_var_D = v3; + int16 v4 = E->base.y_pos - varE32; + E->metroid_var_D = (v4 < 0) ? -256 : 0; *(uint16 *)((uint8 *)&E->metroid_var_C + 1) = v4 << 6; E->metroid_var_F = 0; E->base.current_instruction = addr_kMetroid_Ilist_E9CF; @@ -3555,15 +3079,15 @@ void Metroid_Touch(void) { // 0xA3EDEB } else { uint16 v5 = cur_enemy_index; if (E->metroid_var_F != 3) { - if ((enemy_damage_routine_exec_count & 7) == 7 && !sign16(samus_health - 30)) - QueueSfx3_Max6(0x2Du); + if ((random_enemy_counter & 7) == 7 && !sign16(samus_health - 30)) + QueueSfx3_Max6(0x2D); Metroid_Func_5(v5); } - if (E->metroid_var_F < 2u) { - v7 = 1; - if (abs16(E->base.x_pos - samus_x_pos) < 8u && abs16(E->base.y_pos - draw_enemy_layer) < 8u) { + if (E->metroid_var_F < 2) { + uint16 v7 = 1; + if (abs16(E->base.x_pos - samus_x_pos) < 8 && abs16(E->base.y_pos - varE32) < 8) { v7 = 2; - CallSomeSamusCode(0x12u); + CallSomeSamusCode(0x12); } E->metroid_var_F = v7; if (v7 == 2) { @@ -3576,7 +3100,7 @@ void Metroid_Touch(void) { // 0xA3EDEB void Metroid_Func_5(uint16 k) { // 0xA3EECE uint16 v1; - draw_enemy_layer = samus_y_pos - 8; + uint16 varE32 = samus_y_pos - 8; if ((equipped_items & 0x20) != 0) { v1 = 12288; } else if (equipped_items & 1) { @@ -3584,35 +3108,28 @@ void Metroid_Func_5(uint16 k) { // 0xA3EECE } else { v1 = -16384; } - R18_ = v1; + uint16 r18 = v1; Enemy_Metroid *E = Get_Metroid(k); uint16 metroid_var_02 = E->metroid_var_02; - bool v4 = metroid_var_02 < R18_; - E->metroid_var_02 = metroid_var_02 - R18_; + bool v4 = metroid_var_02 < r18; + E->metroid_var_02 = metroid_var_02 - r18; if (v4) - Samus_DealDamage(1u); + Samus_DealDamage(1); } void Metroid_Shot(void) { // 0xA3EF07 - int16 v3; - int16 v6; - int16 v7; - int16 v8; - int16 v9; - - draw_enemy_layer = samus_y_pos - 8; uint16 v0 = 2 * collision_detection_index; Enemy_Metroid *E = Get_Metroid(cur_enemy_index); if (E->base.frozen_timer) { - v3 = projectile_type[v0 >> 1] & 0xF00; + uint16 v3 = projectile_type[v0 >> 1] & 0xF00; if (v3 == 256 || v3 == 512) { special_death_item_drop_x_origin_pos = E->base.x_pos; special_death_item_drop_y_origin_pos = E->base.y_pos; Enemy_NormalShotAI_SkipSomeParts_A3(); if (!E->base.health) { E->metroid_var_B = 0; - EnemyDeathAnimation(cur_enemy_index, 4u); - CallSomeSamusCode(0x13u); + EnemyDeathAnimation(cur_enemy_index, 4); + CallSomeSamusCode(0x13); sprite_instr_list_ptrs[E->metroid_var_00 >> 1] = 0; uint16 metroid_var_01 = E->metroid_var_01; sprite_instr_list_ptrs[metroid_var_01 >> 1] = 0; @@ -3626,44 +3143,38 @@ void Metroid_Shot(void) { // 0xA3EF07 E->metroid_var_F = 3; E->base.current_instruction = addr_kMetroid_Ilist_E9CF; E->base.instruction_timer = 1; - CallSomeSamusCode(0x13u); + CallSomeSamusCode(0x13); } } else { E->metroid_var_A = 0; E->metroid_var_C = 0; - v6 = 0; - v7 = E->base.x_pos - projectile_x_pos[0]; - if (v7 < 0) - v6 = -256; - E->metroid_var_B = v6; + int16 v7 = E->base.x_pos - projectile_x_pos[0]; + E->metroid_var_B = (v7 < 0) ? -256 : 0; *(uint16 *)((uint8 *)&E->metroid_var_A + 1) = 32 * v7; - v8 = 0; - v9 = E->base.y_pos - projectile_y_pos[0]; - if (v9 < 0) - v8 = -256; - E->metroid_var_D = v8; + int16 v9 = E->base.y_pos - projectile_y_pos[0]; + E->metroid_var_D = (v9 < 0) ? -256 : 0; *(uint16 *)((uint8 *)&E->metroid_var_C + 1) = 32 * v9; E->metroid_var_F = 0; E->base.current_instruction = addr_kMetroid_Ilist_E9CF; E->base.instruction_timer = 1; int v10 = collision_detection_index; if ((projectile_type[v10] & 2) != 0) { - QueueSfx3_Max6(0xAu); - R18_ = projectile_damage[v10]; + QueueSfx3_Max6(0xA); + uint16 r18 = projectile_damage[v10]; E->base.flash_timer = 4; uint16 metroid_parameter_2 = E->metroid_parameter_2; - bool v13 = metroid_parameter_2 < R18_; - uint16 v12 = metroid_parameter_2 - R18_; + bool v13 = metroid_parameter_2 < r18; + uint16 v12 = metroid_parameter_2 - r18; v13 = !v13; if (!v12 || !v13) { E->metroid_parameter_2 = 0; E->base.frozen_timer = 400; - E->base.ai_handler_bits |= 4u; + E->base.ai_handler_bits |= 4; return; } E->metroid_parameter_2 = v12; } - QueueSfx2_Max6(0x5Au); + QueueSfx2_Max6(0x5A); } } } @@ -3671,8 +3182,8 @@ void Metroid_Shot(void) { // 0xA3EF07 void Metroid_Powerbomb(uint16 k) { // 0xA3F042 NormalEnemyPowerBombAi(); if (!Get_Metroid(k)->base.health) { - CallSomeSamusCode(0x13u); + CallSomeSamusCode(0x13); sprite_instr_list_ptrs[Get_Metroid(cur_enemy_index)->metroid_var_00 >> 1] = 0; sprite_instr_list_ptrs[Get_Metroid(cur_enemy_index)->metroid_var_01 >> 1] = 0; } -} \ No newline at end of file +} diff --git a/src/sm_a4.c b/src/sm_a4.c index 8af8f41..ea759b4 100644 --- a/src/sm_a4.c +++ b/src/sm_a4.c @@ -88,7 +88,7 @@ const uint16 *Crocomire_Func_4(uint16 k, const uint16 *jp) { // 0xA486F2 Enemy_Crocomire *E = Get_Crocomire(0); uint16 v1 = abs16(E->base.x_pos - samus_x_pos); if (sign16(v1 - 224)) { - E->crocom_var_B |= 0x8000u; + E->crocom_var_B |= 0x8000; E->crocom_var_C = 18; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BC56); } @@ -97,7 +97,7 @@ const uint16 *Crocomire_Func_4(uint16 k, const uint16 *jp) { // 0xA486F2 const uint16 *Crocomire_Func_5(uint16 k, const uint16 *jp) { // 0xA48717 Enemy_Crocomire *E = Get_Crocomire(0); - if ((E->crocom_var_B & 0x800) != 0 && (E->crocom_var_B &= ~0x800u, E->crocom_var_D)) { + if ((E->crocom_var_B & 0x800) != 0 && (E->crocom_var_B &= ~0x800, E->crocom_var_D)) { jp = INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BC30); E->crocom_var_C = 12; } else if ((int16)(E->base.x_pos - g_word_A486A2) < 0) { @@ -129,10 +129,9 @@ const uint16 *Crocomire_Func_7(uint16 k, const uint16 *jp) { // 0xA4876C } else { uint16 crocom_var_F = E->crocom_var_F; if (sign16(crocom_var_F - 18)) { - ++E->crocom_var_F; - ++E->crocom_var_F; + E->crocom_var_F += 2; SpawnEnemyProjectileWithGfx(crocom_var_F, cur_enemy_index, addr_stru_868F8F); - QueueSfx3_Max6(0x1Cu); + QueueSfx3_Max6(0x1C); } else { jp = INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BBCA); E->crocom_var_C = 6; @@ -182,14 +181,14 @@ const uint16 *Crocomire_Func_11(uint16 k, const uint16 *jp) { // 0xA487FB const uint16 *Crocomire_Func_12(uint16 k, const uint16 *jp) { // 0xA48805 Enemy_Crocomire *E = Get_Crocomire(0); - E->crocom_var_B &= ~0x400u; + E->crocom_var_B &= ~0x400; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BCD8); } const uint16 *Crocomire_Func_13(uint16 k, const uint16 *jp) { // 0xA48812 Enemy_Crocomire *E = Get_Crocomire(0); if ((E->crocom_var_B & 0x800) != 0) { - E->crocom_var_B &= ~0x800u; + E->crocom_var_B &= ~0x800; E->crocom_var_C = 20; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BC30); } else if ((int16)(INSTR_ADDR_TO_PTR(0, jp) - addr_kCrocomire_Ilist_BDA2) >= 0) { @@ -201,7 +200,7 @@ const uint16 *Crocomire_Func_13(uint16 k, const uint16 *jp) { // 0xA48812 const uint16 *Crocomire_Func_14(uint16 k, const uint16 *jp) { // 0xA48836 Enemy_Crocomire *E = Get_Crocomire(0); if ((E->crocom_var_B & 0x800) != 0) { - E->crocom_var_B &= ~0x800u; + E->crocom_var_B &= ~0x800; E->crocom_var_C = 12; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BC30); } else if ((int16)(INSTR_ADDR_TO_PTR(0, jp) - addr_kCrocomire_Ilist_BDA2) >= 0) { @@ -213,7 +212,7 @@ const uint16 *Crocomire_Func_14(uint16 k, const uint16 *jp) { // 0xA48836 const uint16 *Crocomire_Func_15(uint16 k, const uint16 *jp) { // 0xA4885A Enemy_Crocomire *E = Get_Crocomire(0); if ((E->crocom_var_B & 0x800) != 0) { - E->crocom_var_B &= ~0x800u; + E->crocom_var_B &= ~0x800; E->crocom_var_C = 12; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BC30); } else if ((int16)(INSTR_ADDR_TO_PTR(0, jp) - addr_kCrocomire_Ilist_BDA2) >= 0) { @@ -242,7 +241,7 @@ const uint16 *Crocomire_Func_17(uint16 k, const uint16 *jp) { // 0xA4889A E->crocom_var_D = 1; E->crocom_var_E = 10; E->crocom_var_C = 12; - QueueSfx2_Max6(0x54u); + QueueSfx2_Max6(0x54); } else { Get_Crocomire(cur_enemy_index)->crocom_var_C = 10; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BD8E); @@ -253,7 +252,7 @@ const uint16 *Crocomire_Func_17(uint16 k, const uint16 *jp) { // 0xA4889A const uint16 *Crocomire_Func_18(uint16 k, const uint16 *jp) { // 0xA488D2 const uint16 *result = Crocomire_Func_2(cur_enemy_index, jp); Enemy_Crocomire *E = Get_Crocomire(0); - E->crocom_var_B |= 0x200u; + E->crocom_var_B |= 0x200; E->crocom_var_D = 32; E->crocom_var_C = 30; return result; @@ -296,7 +295,7 @@ const uint16 *Crocomire_Func_22(uint16 k, const uint16 *jp) { // 0xA48940 jp = Crocomire_Func_2(k, jp); Enemy_Crocomire *E = Get_Crocomire(0); if (!E->crocom_var_D) { - E->crocom_var_B |= 0x2000u; + E->crocom_var_B |= 0x2000; jp = Crocomire_Func_3(k, jp); E->crocom_var_C = 36; } @@ -334,11 +333,11 @@ const uint16 *Crocomire_Func_24(uint16 k, const uint16 *jp) { // 0xA489A8 if (!E->crocom_var_D || (v2 = E->crocom_var_D == 1, --E->crocom_var_D, v2)) { jp = Crocomire_Func_3(k, jp); E->crocom_var_C = 40; - E->crocom_var_B &= ~0x400u; + E->crocom_var_B &= ~0x400; } else { E->crocom_var_C = 36; - Get_Crocomire(0x40u)->crocom_var_D = 0; - E->crocom_var_B |= 0x400u; + Get_Crocomire(0x40)->crocom_var_D = 0; + E->crocom_var_B |= 0x400; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BCD8); } return jp; @@ -361,14 +360,14 @@ const uint16 *Crocomire_Func_26(uint16 k, const uint16 *jp) { // 0xA489F9 uint16 crocom_var_B = E->crocom_var_B; if ((crocom_var_B & 0x4000) != 0) { --E->crocom_var_D; - QueueSfx2_Max6(0x3Bu); + QueueSfx2_Max6(0x3B); return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BCD8); } else { E->crocom_var_B = crocom_var_B & 0xBFFF; E->crocom_var_C = 12; } } else { - E->crocom_var_B &= ~0x4000u; + E->crocom_var_B &= ~0x4000; E->base.instruction_timer = 1; E->crocom_var_C = E->crocom_var_F; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BCD8); @@ -391,12 +390,9 @@ void Crocomire_Init(void) { // 0xA48A5A croco_target_0688 = 0; Enemy_Crocomire *E = Get_Crocomire(0); E->base.properties = E->base.properties & 0x7BFF | 0x400; - static const SpawnHardcodedPlmArgs unk_A48AFA = { 0x20, 0x03, 0xb753 }; - static const SpawnHardcodedPlmArgs unk_A48B02 = { 0x1e, 0x03, 0xb753 }; - static const SpawnHardcodedPlmArgs unk_A48B0A = { 0x61, 0x0b, 0xb747 }; - SpawnHardcodedPlm(&unk_A48AFA); - SpawnHardcodedPlm(&unk_A48B02); - SpawnHardcodedPlm(&unk_A48B0A); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x20, 0x03, 0xb753 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x1e, 0x03, 0xb753 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x61, 0x0b, 0xb747 }); E->crocom_var_A = 84; E->base.current_instruction = addr_kCrocomire_Ilist_E1CC; E->base.instruction_timer = 1; @@ -428,7 +424,7 @@ void Crocomire_Init(void) { // 0xA48A5A camera_distance_index = 2; enemy_bg2_tilemap_size = 1024; E->base.current_instruction = addr_kCrocomire_Ilist_BADE; - E->base.extra_properties |= 4u; + E->base.extra_properties |= 4; E->base.instruction_timer = 1; } } @@ -442,7 +438,7 @@ void Crocomire_Func_27(uint16 k) { // 0xA48B5B if (spritemap_pointer == g_off_A48B79[v1 >> 1]) break; v1 -= 2; - if ((v1 & 0x8000u) != 0) { + if ((v1 & 0x8000) != 0) { Crocomire_8BA4(); return; } @@ -458,7 +454,6 @@ void Crocomire_8BA4(void) { // 0xA48BA4 E1->base.y_pos = E0->base.y_pos; uint16 x_pos = E0->base.x_pos; if ((int16)(x_pos - layer1_x_pos) >= 0) { - R18_ = layer1_x_pos + 256; if (sign16(E0->base.x_pos - 128 - (layer1_x_pos + 256))) goto LABEL_3; LABEL_6: @@ -512,7 +507,7 @@ void Crocomire_Func_30(void) { // 0xA48C95 if (!E->crocom_var_A && (((__PAIR32__(E->base.x_pos - E->base.x_width, E->base.x_pos) - __PAIR32__(samus_x_radius, E->base.x_width) - - __PAIR32__(samus_x_pos, (E->base.x_pos < E->base.x_width) + samus_x_radius)) >> 16) & 0x8000u) != 0) { + - __PAIR32__(samus_x_pos, (E->base.x_pos < E->base.x_width) + samus_x_radius)) >> 16) & 0x8000) != 0) { NormalEnemyTouchAi(); samus_x_pos = E->base.x_pos - E->base.x_width - samus_x_radius; samus_prev_x_pos = samus_x_pos; @@ -525,28 +520,28 @@ void Crocomire_Func_31(void) { // 0xA48CCB uint16 j; if (!door_transition_flag_enemies) { - if (Get_Crocomire(0)->base.flash_timer && (enemy_damage_routine_exec_count & 2) != 0) { + if (Get_Crocomire(0)->base.flash_timer && (random_enemy_counter & 2) != 0) { for (int i = 14; i >= 0; i -= 2) palette_buffer[(i >> 1) + 112] = 0x7FFF; } else { - for (j = 14; (j & 0x8000u) == 0; j -= 2) + for (j = 14; (j & 0x8000) == 0; j -= 2) palette_buffer[(j >> 1) + 112] = g_word_A4B89D[j >> 1]; } } } const uint16 *Crocomire_Instr_11(uint16 k, const uint16 *jp) { // 0xA48CFB - QueueSfx2_Max6(0x74u); + QueueSfx2_Max6(0x74); return jp; } const uint16 *Crocomire_Instr_7(uint16 k, const uint16 *jp) { // 0xA48D07 - QueueSfx2_Max6(0x25u); + QueueSfx2_Max6(0x25); return jp; } const uint16 *Crocomire_Instr_19(uint16 k, const uint16 *jp) { // 0xA48D13 - QueueSfx2_Max6(0x75u); + QueueSfx2_Max6(0x75); return jp; } @@ -558,7 +553,7 @@ void Crocomire_Func_35(void) { // 0xA48D1F E->crocom_var_20 = v2; if (!v2) { E->crocom_var_20 = 32; - QueueSfx3_Max6(0x22u); + QueueSfx3_Max6(0x22); } } } @@ -582,10 +577,6 @@ void Crocomire_8D47(void) { // 0xA48D47 } void Crocomire_Func_37(void) { // 0xA48D5E - static const SpawnHardcodedPlmArgs unk_A48DC2 = { 0x61, 0x0b, 0xb74b }; - static const SpawnHardcodedPlmArgs unk_A48E0B = { 0x62, 0x0b, 0xb74b }; - static const SpawnHardcodedPlmArgs unk_A48E13 = { 0x63, 0x0b, 0xb74b }; - static const SpawnHardcodedPlmArgs unk_A48EA3 = { 0x4e, 0x03, 0xb757 }; Enemy_Crocomire *E0 = Get_Crocomire(0); if (sign16(E0->base.x_pos - 1536)) { @@ -596,8 +587,7 @@ void Crocomire_Func_37(void) { // 0xA48D5E } else if (sign16(E0->base.x_pos - 1552)) { if (!kraid_unk9000) { kraid_unk9000 = 1; - R18_ = 1536; - R20_ = 176; + eproj_spawn_pt = (Point16U){ 1536, 176 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); } } else if (sign16(E0->base.x_pos - 1552)) { @@ -607,9 +597,8 @@ void Crocomire_Func_37(void) { // 0xA48D5E } else if (sign16(E0->base.x_pos - 1568)) { if (!g_word_7E9002) { g_word_7E9002 = 1; - SpawnHardcodedPlm(&unk_A48DC2); - R18_ = 1568; - R20_ = 176; + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x61, 0x0b, 0xb74b }); + eproj_spawn_pt = (Point16U){ 1568, 176 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); } } else { @@ -620,10 +609,9 @@ void Crocomire_Func_37(void) { // 0xA48D5E } else if (sign16(x_pos - 1584)) { if (!g_word_7E9006) { g_word_7E9006 = 1; - SpawnHardcodedPlm(&unk_A48E0B); - SpawnHardcodedPlm(&unk_A48E13); - R18_ = 1584; - R20_ = 176; + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x62, 0x0b, 0xb74b }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x63, 0x0b, 0xb74b }); + eproj_spawn_pt = (Point16U){ 1584, 176 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); } } else if ((int16)(x_pos - g_word_A486A4) >= 0) { @@ -632,30 +620,29 @@ void Crocomire_Func_37(void) { // 0xA48D5E g_word_7E9018 = 1; uint16 v3 = cur_enemy_index; Enemy_Crocomire *EK = Get_Crocomire(cur_enemy_index); - ++EK->crocom_var_A; - ++EK->crocom_var_A; + EK->crocom_var_A += 2; Get_Crocomire(0)->crocom_var_00 = 2; - Get_Crocomire(0x40u)->crocom_var_00 = 2; + Get_Crocomire(0x40)->crocom_var_00 = 2; Get_Crocomire(0x80)->crocom_var_00 = 2; - Get_Crocomire(0xC0u)->crocom_var_00 = 2; - Get_Crocomire(0x100u)->crocom_var_00 = 2; - Get_Crocomire(0x140u)->crocom_var_00 = 2; + Get_Crocomire(0xC0)->crocom_var_00 = 2; + Get_Crocomire(0x100)->crocom_var_00 = 2; + Get_Crocomire(0x140)->crocom_var_00 = 2; Get_Crocomire(0)->crocom_var_01 = 0; - Get_Crocomire(0x40u)->crocom_var_01 = 0; + Get_Crocomire(0x40)->crocom_var_01 = 0; Get_Crocomire(0x80)->crocom_var_01 = 0; - Get_Crocomire(0xC0u)->crocom_var_01 = 0; - Get_Crocomire(0x100u)->crocom_var_01 = 0; - Get_Crocomire(0x140u)->crocom_var_01 = 0; - QueueSfx2_Max6(0x3Bu); + Get_Crocomire(0xC0)->crocom_var_01 = 0; + Get_Crocomire(0x100)->crocom_var_01 = 0; + Get_Crocomire(0x140)->crocom_var_01 = 0; + QueueSfx2_Max6(0x3B); *(uint16 *)((uint8 *)&g_word_7E9015 + 1) = 0; - SpawnHardcodedPlm(&unk_A48EA3); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x4e, 0x03, 0xb757 }); EK->base.current_instruction = addr_kCrocomire_Ilist_BFB0; EK->base.instruction_timer = 1; EK->base.properties |= kEnemyProps_Tangible; Enemy_Crocomire *E1 = Get_Crocomire(cur_enemy_index + 64); E1->base.instruction_timer = 0x7FFF; E1->base.current_instruction = addr_kCrocomire_Ilist_BF62; - Get_Crocomire(0x40u)->base.properties |= 0x100u; + Get_Crocomire(0x40)->base.properties |= 0x100; EK->crocom_var_E = 0; EK->crocom_var_F = 0; EK->crocom_var_D = 2048; @@ -665,70 +652,42 @@ void Crocomire_Func_37(void) { // 0xA48D5E } void Crocomire_8EE5(void) { // 0xA48EE5 - static const SpawnHardcodedPlmArgs unk_A48DC2 = { 0x61, 0x0b, 0xb74b }; - static const SpawnHardcodedPlmArgs unk_A48E0B = { 0x62, 0x0b, 0xb74b }; - static const SpawnHardcodedPlmArgs unk_A48E13 = { 0x63, 0x0b, 0xb74b }; - static const SpawnHardcodedPlmArgs unk_A48EA3 = { 0x4e, 0x03, 0xb757 }; - static const SpawnHardcodedPlmArgs unk_A48EE9 = { 0x61, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48EF1 = { 0x62, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48EF9 = { 0x63, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48F01 = { 0x64, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48F09 = { 0x65, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48F11 = { 0x66, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48F19 = { 0x67, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48F21 = { 0x68, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48F29 = { 0x69, 0x0b, 0xb74f }; - static const SpawnHardcodedPlmArgs unk_A48F31 = { 0x6a, 0x0b, 0xb74f }; - SpawnHardcodedPlm(&unk_A48EE9); - SpawnHardcodedPlm(&unk_A48EF1); - SpawnHardcodedPlm(&unk_A48EF9); - SpawnHardcodedPlm(&unk_A48F01); - SpawnHardcodedPlm(&unk_A48F09); - SpawnHardcodedPlm(&unk_A48F11); - SpawnHardcodedPlm(&unk_A48F19); - SpawnHardcodedPlm(&unk_A48F21); - SpawnHardcodedPlm(&unk_A48F29); - SpawnHardcodedPlm(&unk_A48F31); - R18_ = 1536; - R20_ = 176; + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x61, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x62, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x63, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x64, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x65, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x66, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x67, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x68, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x69, 0x0b, 0xb74f }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x6a, 0x0b, 0xb74f }); + eproj_spawn_pt = (Point16U){ 1536, 176 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); - R18_ = 1552; - R20_ = 192; + eproj_spawn_pt = (Point16U){ 1552, 192 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); - R18_ = 1568; - R20_ = 176; + eproj_spawn_pt = (Point16U){ 1568, 176 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); - R18_ = 1584; - R20_ = 192; + eproj_spawn_pt = (Point16U){ 1584, 192 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); - R18_ = 1600; - R20_ = 192; + eproj_spawn_pt = (Point16U){ 1600, 192 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); - R18_ = 1616; - R20_ = 192; + eproj_spawn_pt = (Point16U){ 1616, 192 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); - R18_ = 1632; - R20_ = 192; + eproj_spawn_pt = (Point16U){ 1632, 192 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); } -void Crocomire_Func_38(uint16 k) { // 0xA48FC2 - Enemy_MoveDown(k); -} - const uint16 *Crocomire_Instr_2(uint16 k, const uint16 *jp) { // 0xA48FC7 earthquake_type = 4; earthquake_timer = 5; - QueueSfx2_Max6(0x76u); + QueueSfx2_Max6(0x76); return jp; } const uint16 *Crocomire_Instr_4(uint16 k, const uint16 *jp) { // 0xA48FDF - if ((Get_Crocomire(0)->crocom_var_B & 0x800) == 0) { - R18_ = 0; - R20_ = -4; - Enemy_MoveRight_IgnoreSlopes(cur_enemy_index); - } + if ((Get_Crocomire(0)->crocom_var_B & 0x800) == 0) + Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(-4)); return jp; } @@ -750,36 +709,26 @@ void Crocomire_Func_43(void) { // 0xA49004 } const uint16 *Crocomire_Instr_16(uint16 k, const uint16 *jp) { // 0xA4901D - R18_ = 0; - R20_ = -4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(-4))) { Get_Crocomire(0)->crocom_var_C = 14; return INSTR_RETURN_ADDR(addr_kCrocomire_Ilist_BF3C); } else { uint16 v2 = 32; if (!sign16(random_number - 2048)) v2 = -32; - R18_ = v2; return Crocomire_Func_87(jp, v2 + (random_number & 0xF)); } } const uint16 *Crocomire_Instr_13(uint16 k, const uint16 *jp) { // 0xA4905B - R18_ = 0; - R20_ = 4; Enemy_Crocomire *E = Get_Crocomire(0); - if ((int16)(((__PAIR32__(E->base.x_pos - E->base.x_width, E->base.x_pos) - - (E->base.x_width | 0x1000000) - - ((uint16)((E->base.x_pos < E->base.x_width) + 256) | 0x40000)) >> 16) - - layer1_x_pos) < 0) - Enemy_MoveRight_IgnoreSlopes(cur_enemy_index); + if ((int16)(E->base.x_pos - E->base.x_width - 260 - layer1_x_pos) < 0) + Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(4)); return jp; } const uint16 *Crocomire_Instr_18(uint16 k, const uint16 *jp) { // 0xA4907F - R18_ = 0; - R20_ = 4; - Enemy_MoveRight_IgnoreSlopes(k); + Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL16(4)); return jp; } @@ -794,20 +743,18 @@ const uint16 *Crocomire_Instr_17(uint16 k, const uint16 *jp) { // 0xA49094 } void Crocomire_Func_49(void) { // 0xA49099 - static const SpawnHardcodedPlmArgs unk_A490D4 = { 0x4e, 0x03, 0xb753 }; - Crocomire_Func_50(); Crocomire_Func_53(); Crocomire_Func_55(); Enemy_Crocomire *E = Get_Crocomire(0); if (E->crocom_var_A == 62) { - QueueMusic_Delayed8(6u); + QueueMusic_Delayed8(6); E->crocom_var_A = 88; E->base.current_instruction = addr_kCrocomire_Ilist_E1D2; *(uint16 *)&scrolls[4] = 257; debug_disable_minimap = 0; - Get_Crocomire(0x40u)->base.properties |= 0x200u; - SpawnHardcodedPlm(&unk_A490D4); + Get_Crocomire(0x40)->base.properties |= 0x200; + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x4e, 0x03, 0xb753 }); camera_distance_index = 0; croco_target_0688 = 0; } @@ -858,19 +805,14 @@ void Crocomire_Func_52(void) { // 0xA49136 } void Crocomire_Func_53(void) { // 0xA4916C - int16 v0; - if (!--g_word_7E9018) { g_word_7E9018 = 6; - v0 = random_number & 0x3F; + uint16 v0 = random_number & 0x3F; if ((random_number & 2) == 0) v0 = ~v0; - R18_ = Get_Crocomire(0)->base.x_pos + v0; - R20_ = (uint16)(random_number & 0x1F00) >> 8; - R20_ = lava_acid_y_pos + 16 - R20_; - R22_ = 21; - R24_ = 0; - CreateSpriteAtPos(); + uint16 x = Get_Crocomire(0)->base.x_pos + v0; + uint16 y = lava_acid_y_pos + 16 - ((uint16)(random_number & 0x1F00) >> 8); + CreateSpriteAtPos(x, y, 21, 0); } } @@ -890,19 +832,18 @@ void Crocomire_Func_55(void) { // 0xA491C1 Crocomire_Func_58(); Enemy_Crocomire *E0 = Get_Crocomire(0); - E0->crocom_var_B &= ~0x800u; + E0->crocom_var_B &= ~0x800; Crocomire_Func_27(cur_enemy_index); Enemy_Crocomire *E = Get_Crocomire(cur_enemy_index); if (sign16(E->base.y_pos - 280)) { uint16 v3 = 8 * ((reg_BG2VOFS + 288) & 0xFFF8); - R18_ = 32; + int m = 32; do { tilemap_stuff[v3 >> 1] = 824; v3 += 2; - --R18_; - } while (R18_); + } while (--m); nmi_flag_bg2_enemy_vram_transfer = 1; - E0->base.extra_properties &= ~0x8000u; + E0->base.extra_properties &= ~0x8000; crocom_var_D = E->crocom_var_D; LOBYTE(E->crocom_var_D) = crocom_var_D + 0x80; v7 = __CFADD__uint8(crocom_var_D, 0x80) + HIBYTE(E->crocom_var_D) + 3; @@ -1087,19 +1028,16 @@ void Crocomire_Func_59(void) { // 0xA493ED void Crocomire_Func_60(void) { // 0xA4943D int i; - int16 j; Enemy_Crocomire *E = Get_Crocomire(cur_enemy_index); - ++E->crocom_var_A; - ++E->crocom_var_A; + E->crocom_var_A += 2; g_word_7E0692 = 256; croco_cur_vline_idx = 0; g_word_7E0698 = *(uint16 *)((uint8 *)&g_word_A49BC5 + croco_word_7E069A); g_word_7E0694 = g_word_7E0698; g_word_7E0696 = *(uint16 *)((uint8 *)&g_word_A49BC7 + croco_word_7E069A); g_word_7E068E = *(uint16 *)((uint8 *)&g_word_A49BC9 + croco_word_7E069A); - R0_.addr = 0; - *(uint16 *)&R0_.bank = *(uint16 *)((uint8 *)&g_word_A49BCB + croco_word_7E069A); + uint8 bank = *(uint16 *)((uint8 *)&g_word_A49BCB + croco_word_7E069A); uint16 v6; for (i = croco_word_7E069A + 8; ; i = v6 + 4) { uint16 v2 = *(uint16 *)((uint8 *)&g_word_A49BC5 + i); @@ -1109,13 +1047,13 @@ void Crocomire_Func_60(void) { // 0xA4943D uint16 v3 = *(uint16 *)((uint8 *)&g_word_A49BC7 + i); int n = g_word_7E068E; do { - *(uint16 *)&g_ram[v3] = IndirReadWord(R0_, v2); + *(uint16 *)&g_ram[v3] = GET_WORD(RomPtrWithBank(bank, v2)); v3 += 2, v2 += 2; } while (--n >= 0); } croco_word_7E069A = i + 2; g_word_7E068A = i + 2; - for (j = 128; j >= 0; j -= 2) + for (int j = 128; j >= 0; j -= 2) *(uint16 *)&croco_vline_height[(uint16)j] = 0; } @@ -1145,12 +1083,12 @@ void Crocomire_Func_62(void) { // 0xA494B6 } void Crocomire_Func_64(void) { // 0xA494FB - QueueSfx2_Max6(0x77u); + QueueSfx2_Max6(0x77); Crocomire_950F(); } void Crocomire_9506(void) { // 0xA49506 - QueueSfx2_Max6(0x2Du); + QueueSfx2_Max6(0x2D); Crocomire_950F(); } @@ -1158,12 +1096,12 @@ void Crocomire_950F(void) { // 0xA4950F static const SpawnHdmaObject_Args unk_A49559 = { 0x42, 0x10, 0x9563 }; Enemy_Crocomire *v4; // r10 - uint16 v1 = 2 * (Get_Crocomire(0x40u)->base.y_pos - 72); + uint16 v1 = 2 * (Get_Crocomire(0x40)->base.y_pos - 72); uint16 v2 = reg_BG2VOFS; do { crocomire_bg2_scroll_hdma_data[v1 >> 1] = v2; v1 -= 2; - } while ((v1 & 0x8000u) == 0); + } while ((v1 & 0x8000) == 0); Enemy_Crocomire *E = Get_Crocomire(cur_enemy_index); ++E->crocom_var_A; ++E->crocom_var_A; @@ -1179,8 +1117,7 @@ void Crocomire_950F(void) { // 0xA4950F void Crocomire_Func_63(void) { // 0xA49576 Enemy_Crocomire *E = Get_Crocomire(cur_enemy_index); - ++E->crocom_var_A; - ++E->crocom_var_A; + E->crocom_var_A += 2; } void Crocomire_Func_65(void) { // 0xA49580 @@ -1198,7 +1135,6 @@ void Crocomire_Func_65(void) { // 0xA49580 if (!Crocomire_Func_67()) goto LABEL_4; Crocomire_Func_27(cur_enemy_index); - R18_ = (uint8)((uint16)(g_word_7E0692 & 0xFF00) >> 8); uint16 v4; v4 = g_word_7E0694 - 3; if (sign16(g_word_7E0694 - 19)) { @@ -1219,14 +1155,14 @@ LABEL_4:; if (!sign16(g_word_7E0692 - 20096)) v5 = 20480; g_word_7E0692 = v5; - R18_ = 0; + uint16 r18 = 0; uint16 v6 = 2 * (E1->base.y_pos - 72); uint16 v7 = g_word_7E0694; message_box_animation_y1 = g_word_7E0694; do { crocomire_bg2_scroll_hdma_data[v6 >> 1] = reg_BG2VOFS + v7 - message_box_animation_y1; - bool v8 = __CFADD__uint16(g_word_7E0692, R18_); - R18_ += g_word_7E0692; + bool v8 = __CFADD__uint16(g_word_7E0692, r18); + r18 += g_word_7E0692; if (!v8) ++v7; ++message_box_animation_y1; @@ -1265,11 +1201,9 @@ static const uint8 kCrocoEraseLineMasks[8] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xf // Used when dissolving the crocomire thing uint16 Crocomire_Func_67(void) { // 0xA496C8 - VramWriteEntry *v9; - int n = croco_word_068C; - R20_ = 0; - R22_ = 0; +// R20 = 0; + //R22_ = 0; while (1) { if (croco_cur_vline_idx > 48) // bugfix return 1; @@ -1295,7 +1229,6 @@ uint16 Crocomire_Func_67(void) { // 0xA496C8 if (croco_vline_height[vline_idx] == 48) break; croco_vline_height[vline_idx]++; - --R18_; } while (--n); uint16 v7, v8; @@ -1306,7 +1239,7 @@ uint16 Crocomire_Func_67(void) { // 0xA496C8 break; g_word_7E068A = 0; } - v9 = gVramWriteEntry(vram_write_queue_tail); + VramWriteEntry *v9 = gVramWriteEntry(vram_write_queue_tail); v9->size = *(uint16 *)((uint8 *)&g_word_A49BC5 + v7); v9->src.addr = *(uint16 *)((uint8 *)&g_word_A49BCB + v7); *(uint16 *)&v9->src.bank = *(uint16 *)((uint8 *)&g_word_A49BC9 + v7); @@ -1317,21 +1250,19 @@ uint16 Crocomire_Func_67(void) { // 0xA496C8 } void Crocomire_Func_68(void) { // 0xA497D3 - static const SpawnHardcodedPlmArgs unk_A497EF = { 0x30, 0x03, 0xb757 }; - if (sign16(samus_x_pos - 640)) { - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); *(uint16 *)&scrolls[3] = 256; - SpawnHardcodedPlm(&unk_A497EF); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x30, 0x03, 0xb757 }); camera_distance_index = 6; Enemy_Crocomire *E0 = Get_Crocomire(0); E0->base.properties = E0->base.properties & 0x7BFF | kEnemyProps_Tangible; - Enemy_Crocomire *E1 = Get_Crocomire(0x40u); - E1->base.properties |= 0x500u; + Enemy_Crocomire *E1 = Get_Crocomire(0x40); + E1->base.properties |= 0x500; E0->crocom_var_D = 4; E1->crocom_var_D = 0; Get_Crocomire(0x80)->crocom_var_D = 10; - Get_Crocomire(0xC0u)->crocom_var_D = 1; + Get_Crocomire(0xC0)->crocom_var_D = 1; E0->crocom_var_B = 0; E0->base.y_height = 56; Crocomire_9BB3(); @@ -1367,12 +1298,12 @@ void Crocomire_Func_70(void) { // 0xA49859 uint16 v3 = E1->crocom_var_D; int v4 = crocom_var_D >> 1; if (v3 == g_word_A498CA[v4]) { - if ((g_word_A498CA[crocom_var_D >> 1] & 0x8000u) != 0) { + if ((g_word_A498CA[crocom_var_D >> 1] & 0x8000) != 0) { uint16 v7 = E2->crocom_var_D; if (v7) { E2->crocom_var_D = v7 - 1; E0->crocom_var_D = crocom_var_D - 2; - QueueSfx2_Max6(0x2Bu); + QueueSfx2_Max6(0x2B); return; } uint16 v8 = crocom_var_D + 2; @@ -1393,9 +1324,6 @@ void Crocomire_Func_70(void) { // 0xA49859 } void Crocomire_Func_71(void) { // 0xA4990A - static const SpawnHardcodedPlmArgs unk_A4996E = { 0x20, 0x03, 0xb753 }; - static const SpawnHardcodedPlmArgs unk_A49976 = { 0x1e, 0x03, 0xb757 }; - static const SpawnHardcodedPlmArgs unk_A4997E = { 0x70, 0x0b, 0xb747 }; int16 v3; VramWriteEntry *v6; @@ -1411,8 +1339,7 @@ void Crocomire_Func_71(void) { // 0xA4990A v6->size = 512; v6->src.addr = g_word_A499D9[v4]; *(uint16 *)&v6->src.bank = 173; - R18_ = (reg_OBSEL & 7) << 13; - v6->vram_dst = g_word_A499CB[v4] + R18_; + v6->vram_dst = g_word_A499CB[v4] + ((reg_OBSEL & 7) << 13); vram_write_queue_tail = v5 + 7; croco_target_0688 = v3 + 2; } @@ -1422,10 +1349,10 @@ void Crocomire_Func_71(void) { // 0xA4990A Get_Crocomire(0x80)->crocom_var_D = 80; E->crocom_var_E = 0; E->crocom_var_F = 0; - SpawnHardcodedPlm(&unk_A4996E); - SpawnHardcodedPlm(&unk_A49976); - SpawnHardcodedPlm(&unk_A4997E); - QueueSfx2_Max6(0x29u); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x20, 0x03, 0xb753 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x1e, 0x03, 0xb757 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x70, 0x0b, 0xb747 }); + QueueSfx2_Max6(0x29); E->base.current_instruction = addr_kCrocomire_Ilist_E158; E->base.instruction_timer = 1; E->base.palette_index = 0; @@ -1433,12 +1360,11 @@ void Crocomire_Func_71(void) { // 0xA4990A palette_buffer[(i >> 1) + 144] = g_word_A4B8FD[i >> 1]; ClearEnemyProjectiles(); uint16 v8 = 8; - R18_ = 8; + int n = 8; do { SpawnEnemyProjectileWithGfx(v8, cur_enemy_index, addr_kEproj_CrocomireSpikeWallPieces); - --R18_; - } while (R18_); - QueueSfx2_Max6(0x30u); + } while (--n); + QueueSfx2_Max6(0x30); Crocomire_9BB3(); } } @@ -1489,8 +1415,8 @@ void Crocomire_Func_73(void) { // 0xA49A38 uint16 v6 = E->crocom_var_F + v4 + E->base.x_pos; E->base.x_pos = v6; if (!sign16(v6 - 576)) { - QueueSfx2_Max6(0x25u); - Get_Crocomire(0x40u)->base.palette_index = E->base.palette_index; + QueueSfx2_Max6(0x25); + Get_Crocomire(0x40)->base.palette_index = E->base.palette_index; E->base.current_instruction = addr_kCrocomire_Ilist_E158; E->base.instruction_timer = 1; Crocomire_9BB3(); @@ -1518,7 +1444,7 @@ const uint16 *Crocomire_Instr_20(uint16 k, const uint16 *jp) { // 0xA49AAF } const uint16 *Crocomire_Instr_21(uint16 k, const uint16 *jp) { // 0xA49AB4 - return Crocomire_Func_87(jp, 8u); + return Crocomire_Func_87(jp, 8); } const uint16 *Crocomire_Instr_22(uint16 k, const uint16 *jp) { // 0xA49AB9 @@ -1550,17 +1476,12 @@ const uint16 *Crocomire_Instr_27(uint16 k, const uint16 *jp) { // 0xA49AD7 } const uint16 *Crocomire_Func_87(const uint16 *jp, uint16 a) { // 0xA49ADA - R18_ = a; Enemy_Crocomire *E = Get_Crocomire(0); - R18_ = a + E->base.x_pos + (random_number & 7); - R20_ = E->base.y_height + E->base.y_pos - 16; + eproj_spawn_pt = (Point16U){ a + E->base.x_pos + (random_number & 7), E->base.y_height + E->base.y_pos - 16 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x15); return jp; } -static const SpawnHardcodedPlmArgs unk_A49B3E = { 0x30, 0x03, 0xb753 }; -static const SpawnHardcodedPlmArgs unk_A49B74 = { 0x1e, 0x03, 0xb753 }; - void Crocomire_Func_88(void) { // 0xA49B06 int16 v3; @@ -1579,18 +1500,16 @@ void Crocomire_Func_88(void) { // 0xA49B06 E->base.y_pos += 21; E->base.y_height = 28; E->base.x_width = 40; - SpawnHardcodedPlm(&unk_A49B3E); - printf("X unknown!\n"); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x30, 0x03, 0xb753 }); Enemy_ItemDrop_Crocomire(0); Crocomire_9BB3(); } } void Crocomire_9B65(void) { // 0xA49B65 - static const SpawnHardcodedPlmArgs unk_A49B74 = { 0x1e, 0x03, 0xb753 }; *(uint16 *)scrolls = 257; *(uint16 *)&scrolls[2] = 257; - SpawnHardcodedPlm(&unk_A49B74); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x1e, 0x03, 0xb753 }); Crocomire_9BB3(); } @@ -1605,10 +1524,10 @@ void Crocomire_Func_90(void) { // 0xA49B7D } void Crocomire_9B86(void) { // 0xA49B86 - QueueMusic_Delayed8(6u); + QueueMusic_Delayed8(6); camera_distance_index = 0; - *(uint16 *)&boss_bits_for_area[area_index] |= 2u; - QueueMusic_Delayed8(6u); + *(uint16 *)&boss_bits_for_area[area_index] |= 2; + QueueMusic_Delayed8(6); Crocomire_Func_87(0, 0xFFF0); Crocomire_Func_87(0, 0x10); Crocomire_9BB3(); @@ -1627,7 +1546,7 @@ void Crocomire_Func_91(void) { // 0xA49BBA void Crocomire_Func_92(void) { // 0xA4B93D NormalEnemyTouchAi(); Enemy_Crocomire *E = Get_Crocomire(0); - E->crocom_var_B |= 0x4000u; + E->crocom_var_B |= 0x4000; extra_samus_x_displacement = -4; } @@ -1636,17 +1555,13 @@ void Crocomire_Func_93(void) { // 0xA4B951 uint16 v1 = E->crocom_var_B & 0xF; if (sign16(v1 - 15)) ++v1; - R18_ = v1; E->crocom_var_B |= v1; } void Crocomire_Func_94(void) { // 0xA4B968 int v0 = collision_detection_index; - R18_ = projectile_x_pos[v0]; - R20_ = projectile_y_pos[v0]; - uint16 v1 = 29; - if ((projectile_type[v0] & 0x200) == 0) - v1 = 6; + eproj_spawn_pt = (Point16U){ projectile_x_pos[v0], projectile_y_pos[v0] }; + uint16 v1 = ((projectile_type[v0] & 0x200) == 0) ? 6 : 29; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, v1); } @@ -1661,11 +1576,11 @@ void Crocomire_Powerbomb(void) { // 0xA4B992 E->crocom_var_B = E->crocom_var_B & 0x3FF0 | 0x8000; E->crocom_var_E = 10; E->base.flash_timer += 4; - E->base.ai_handler_bits |= 2u; + E->base.ai_handler_bits |= 2; E->crocom_var_C = 24; uint16 spritemap_pointer = E->base.spritemap_pointer; uint16 v3; - R18_ = *(uint16 *)RomPtr_A4(spritemap_pointer); + int n = *(uint16 *)RomPtr_A4(spritemap_pointer); while (1) { v2 = *((uint16 *)RomPtr_A4(spritemap_pointer) + 3); v3 = addr_kCrocomire_Ilist_BDAE; @@ -1675,7 +1590,7 @@ void Crocomire_Powerbomb(void) { // 0xA4B992 if (v2 == addr_kCrocomire_BigSprmap_D51C) break; spritemap_pointer += 8; - if (!--R18_) { + if (!--n) { v3 = addr_kCrocomire_Ilist_BDB6; break; } @@ -1719,41 +1634,33 @@ LABEL_10:; uint16 v4 = E->crocom_var_B & 0xF; if (sign16(v4 - 15)) ++v4; - R18_ = v4; if ((E->crocom_var_B & 0x800) == 0) { uint16 v5 = g_word_A48692; if (E->crocom_var_C == 8) v5 = g_word_A48694; E->base.instruction_timer += v5; } - E->crocom_var_B = R18_ | E->crocom_var_B & 0xB7F0 | 0x800; + E->crocom_var_B = v4 | E->crocom_var_B & 0xB7F0 | 0x800; E->crocom_var_E = 10; } E->base.flash_timer += 14; - E->base.ai_handler_bits |= 2u; + E->base.ai_handler_bits |= 2; } void Crocomire_Func_1(void) { // 0xA4BAB4 int v0 = collision_detection_index; - R18_ = projectile_x_pos[v0]; - R20_ = projectile_y_pos[v0]; - uint16 v1 = 29; - if ((projectile_type[v0] & 0x200) == 0) - v1 = 6; + eproj_spawn_pt = (Point16U){ projectile_x_pos[v0], projectile_y_pos[v0] }; + uint16 v1 = ((projectile_type[v0] & 0x200) == 0) ? 6 : 29; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, v1); } -void GetCurEnemyIndex(void) { // 0xA4CB01 - ; -} - void CrocomireTongue_Init(void) { // 0xA4F67A Enemy_Crocomire *E = Get_Crocomire(cur_enemy_index); if ((*(uint16 *)&boss_bits_for_area[area_index] & 2) != 0) { E->base.properties = E->base.properties & 0xDCFF | 0x300; } else { E->base.current_instruction = addr_kCrocomire_Ilist_BE56; - E->base.extra_properties |= 0x404u; + E->base.extra_properties |= 0x404; E->base.instruction_timer = 1; E->crocom_var_A = 23; E->base.palette_index = 3584; @@ -1762,4 +1669,4 @@ void CrocomireTongue_Init(void) { // 0xA4F67A void CrocomireTongue_Main(void) { // 0xA4F6BB ; -} \ No newline at end of file +} diff --git a/src/sm_a5.c b/src/sm_a5.c index fc005db..b7ef855 100644 --- a/src/sm_a5.c +++ b/src/sm_a5.c @@ -51,16 +51,16 @@ void Draygon_Init(void) { // 0xA58687 for (int i = 48; i >= 0; i -= 2) target_palettes[(i >> 1) + 144] = kDraygon_MorePalettes[i >> 1]; - for (j = 4094; (j & 0x8000u) == 0; j -= 2) + for (j = 4094; (j & 0x8000) == 0; j -= 2) tilemap_stuff[j >> 1] = 824; - Get_Draygon(cur_enemy_index)->base.palette_index = 3584; + Get_Draygon(cur_enemy_index)->base.palette_index = 0xe00; *(uint16 *)&enemy_gfx_drawn_hook.bank = 165; enemy_gfx_drawn_hook.addr = FUNC16(Draygon_Func_36); flag_process_all_enemies = -1; Get_Draygon(0)->base.current_instruction = addr_kDraygon_Ilist_9889; - Get_Draygon(0x40u)->base.current_instruction = addr_kDraygon_Ilist_9944; + Get_Draygon(0x40)->base.current_instruction = addr_kDraygon_Ilist_9944; Get_Draygon(0x80)->base.current_instruction = addr_kDraygon_Ilist_99FC; - Get_Draygon(0xC0u)->base.current_instruction = addr_kDraygon_Ilist_9813; + Get_Draygon(0xC0)->base.current_instruction = addr_kDraygon_Ilist_9813; enemy_bg2_tilemap_size = 1024; Get_Draygon(cur_enemy_index)->draygon_var_A = FUNC16(Draygon_Func_1); sub_88DF34(); @@ -120,11 +120,11 @@ void Draygon_Main(void) { // 0xA586FC Enemy_Draygon *E0 = Get_Draygon(0); uint16 x_pos = E0->base.x_pos; - Enemy_Draygon *E1 = Get_Draygon(0x40u); + Enemy_Draygon *E1 = Get_Draygon(0x40); E1->base.x_pos = x_pos; Enemy_Draygon *E2 = Get_Draygon(0x80); E2->base.x_pos = x_pos; - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.x_pos = x_pos; uint16 y_pos = E0->base.y_pos; E1->base.y_pos = y_pos; @@ -181,9 +181,8 @@ void Draygon_Func_3(void) { // 0xA587AA uint16 result = 2 * ((Random & 3) + 2); if (!Get_Draygon(result)->draygon_var_40) { int v2 = (uint16)(4 * ((Random & 3) + 2)) >> 1; - R18_ = g_word_A587DC[v2]; - R20_ = g_word_A587DC[v2 + 1]; - SpawnEnemyProjectileWithGfx(3u, result, addr_stru_868E5E); + eproj_spawn_pt = (Point16U){ g_word_A587DC[v2], g_word_A587DC[v2 + 1] }; + SpawnEnemyProjectileWithGfx(3, result, addr_stru_868E5E); } } } @@ -200,42 +199,25 @@ void Draygon_Func_4(void) { // 0xA587F4 void Draygon_Func_5(void) { // 0xA58817 Enemy_Draygon *E = Get_Draygon(0); - int16 draygon_var_00; - - varE28 = 384; - varE24 = 384; - draw_oam_x_offset = 0; - varE26 = 0; + //varE28 = 384; + uint16 varE24 = 384; + uint16 varE22 = 0; + uint16 varE26 = 0; while (1) { - - draw_oam_x_offset += E->draygon_var_0F; - uint16 v1 = varE24 - HIBYTE(draw_oam_x_offset); + varE22 += E->draygon_var_0F; + uint16 v1 = varE24 - HIBYTE(varE22); if ((int16)(v1 - E->draygon_var_01) < 0) break; - varE24 -= HIBYTE(draw_oam_x_offset); + varE24 -= HIBYTE(varE22); *(uint16 *)((uint8 *)&g_word_7E9002 + varE26++) = v1; - ++varE26; - ++varE26; + varE26 += 2; if (!sign16(++varE26 - 2048)) { - while (1) - ; + Unreachable(); } } - draygon_var_00 = E->draygon_var_00; - uint16 v4; - if (draygon_var_00 < 0) { - uint16 v5 = Abs16(draygon_var_00); - v4 = Abs16(samus_x_pos + v5); - } else { - v4 = Abs16(draygon_var_00 - samus_x_pos); - } - R44 = v4; - R42 = 0; - R46 = varE26 >> 2; - R48 = 0; - EnemyFunc_B761(); - E->draygon_var_D = R44; - E->draygon_var_E = R42; + uint32 t = EnemyFunc_Divide(varE26 >> 2, Abs16(E->draygon_var_00 - samus_x_pos) << 16); + E->draygon_var_D = t >> 16; + E->draygon_var_E = t; uint16 v6 = varE26; *(uint16 *)((uint8 *)&g_word_7E9002 + varE26) = E->base.y_pos; E->draygon_var_B = v6; @@ -248,7 +230,7 @@ void Draygon_Func_6(void) { // 0xA588B1 Enemy_Draygon *E = Get_Draygon(0); uint16 draygon_var_B = E->draygon_var_B; if (draygon_var_B == 104) { - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_9C06; E3->base.instruction_timer = 1; } @@ -277,13 +259,9 @@ void Draygon_Func_7(void) { // 0xA58901 void Draygon_Func_8(void) { // 0xA58922 Draygon_Func_3(); Enemy_Draygon *E = Get_Draygon(0); - R44 = 672 - E->base.x_pos; - R42 = 0; - R46 = E->draygon_var_C >> 2; - R48 = 0; - EnemyFunc_B761(); - E->draygon_var_D = R44; - E->draygon_var_E = R42; + uint32 t = EnemyFunc_Divide(E->draygon_var_C >> 2, (672 - E->base.x_pos) << 16); + E->draygon_var_D = t >> 16; + E->draygon_var_E = t; E->draygon_var_A = FUNC16(Draygon_Func_9); } @@ -292,7 +270,7 @@ void Draygon_Func_9(void) { // 0xA58951 Enemy_Draygon *E = Get_Draygon(0); uint16 draygon_var_B = E->draygon_var_B; if (draygon_var_B == 104) { - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_9BDA; E3->base.instruction_timer = 1; } @@ -315,13 +293,11 @@ void Draygon_Func_9(void) { // 0xA58951 void Draygon_Func_10(void) { // 0xA589B3 Draygon_Func_3(); Enemy_Draygon *E = Get_Draygon(0); - R44 = Abs16(E->draygon_var_02 - samus_x_pos); - R42 = 0; - R46 = varE26 >> 2; - R48 = 0; - EnemyFunc_B761(); - E->draygon_var_D = R44; - E->draygon_var_E = R42; + printf("Wtf is varE26?\n"); + uint16 varE26 = 0; // Wtf is varE26 + uint32 t = EnemyFunc_Divide(varE26 >> 2, Abs16(E->draygon_var_02 - samus_x_pos) << 16); + E->draygon_var_D = t >> 16; + E->draygon_var_E = t; E->draygon_var_A = FUNC16(Draygon_Func_11); E->base.current_instruction = addr_kDraygon_Ilist_97BB; E->base.instruction_timer = 1; @@ -335,7 +311,7 @@ void Draygon_Func_11(void) { // 0xA58A00 Enemy_Draygon *E = Get_Draygon(0); uint16 draygon_var_B = E->draygon_var_B; if (draygon_var_B == 104) { - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_9813; E3->base.instruction_timer = 1; } @@ -352,23 +328,11 @@ void Draygon_Func_11(void) { // 0xA58A00 } void Draygon_Func_12(void) { // 0xA58A50 - int16 draygon_var_00; - Draygon_Func_3(); Enemy_Draygon *E = Get_Draygon(0); - draygon_var_00 = E->draygon_var_00; - uint16 v2; - if (draygon_var_00 < 0) - v2 = E->base.x_pos - draygon_var_00; - else - v2 = E->base.x_pos - E->draygon_var_00; - R44 = v2; - R42 = 0; - R46 = E->draygon_var_C >> 2; - R48 = 0; - EnemyFunc_B761(); - E->draygon_var_D = R44; - E->draygon_var_E = R42; + uint32 t = EnemyFunc_Divide(E->draygon_var_C >> 2, (E->base.x_pos - E->draygon_var_00) << 16); + E->draygon_var_D = t >> 16; + E->draygon_var_E = t; E->draygon_var_A = FUNC16(Draygon_Func_13); } @@ -378,7 +342,7 @@ void Draygon_Func_13(void) { // 0xA58A90 Enemy_Draygon *E = Get_Draygon(0); uint16 draygon_var_B = E->draygon_var_B; if (draygon_var_B == 104) { - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_97E7; E3->base.instruction_timer = 1; } @@ -412,7 +376,7 @@ void Draygon_Func_14(void) { // 0xA58B0A E->draygon_var_E = 0; E->draygon_var_D = 1; E->draygon_var_0D = 0; - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_9C06; E3->base.instruction_timer = 1; E->draygon_var_A = FUNC16(Draygon_Func_15); @@ -430,8 +394,7 @@ void Draygon_Func_15(void) { // 0xA58B52 E->draygon_var_A = FUNC16(Draygon_Func_16); E->draygon_var_03 = 16; } else { - draw_enemy_layer = 32; - E->base.y_pos = CosineMult8bit(E->draygon_var_0D) + 384; + E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); uint16 x_subpos = E->base.x_subpos; bool v4 = __CFADD__uint16(E->draygon_var_E, x_subpos); @@ -455,9 +418,7 @@ void Draygon_Func_16(void) { // 0xA58BAE E->base.current_instruction = addr_kDraygon_Ilist_9C90; E->base.instruction_timer = 1; } - draw_enemy_layer = 32; - - E->base.y_pos = CosineMult8bit(E->draygon_var_0D) + 384; + E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); uint16 x_subpos; x_subpos = E->base.x_subpos; @@ -469,7 +430,7 @@ void Draygon_Func_16(void) { // 0xA58BAE if (v5 >= 0 && !sign16(v5 - 672)) { LABEL_8: if (!samus_x_speed_divisor) { - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_9BDA; E3->base.instruction_timer = 1; E->draygon_var_A = FUNC16(Draygon_Func_17); @@ -484,9 +445,8 @@ void Draygon_Func_17(uint16 k) { // 0xA58C33 int16 v4; Draygon_Func_35(); - draw_enemy_layer = 32; Enemy_Draygon *E = Get_Draygon(0); - E->base.y_pos = CosineMult8bit(E->draygon_var_0D) + 384; + E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); uint16 x_subpos = E->base.x_subpos; bool v3 = __CFADD__uint16(E->draygon_var_E, x_subpos); @@ -508,7 +468,7 @@ void Draygon_Func_18(void) { // 0xA58C8E E->draygon_var_E = 0; E->draygon_var_D = 1; E->draygon_var_0D = 0; - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_9C06; E3->base.instruction_timer = 1; E->draygon_var_A = FUNC16(Draygon_Func_19); @@ -526,8 +486,7 @@ void Draygon_Func_19(void) { // 0xA58CD4 E->draygon_var_A = FUNC16(Draygon_Func_20); E->draygon_var_03 = 16; } else { - draw_enemy_layer = 32; - E->base.y_pos = CosineMult8bit(E->draygon_var_0D) + 384; + E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); uint16 x_subpos = E->base.x_subpos; bool v4 = x_subpos < E->draygon_var_E; @@ -550,9 +509,7 @@ void Draygon_Func_20(void) { // 0xA58D30 E->base.current_instruction = addr_kDraygon_Ilist_98FE; E->base.instruction_timer = 1; } - draw_enemy_layer = 32; - - E->base.y_pos = CosineMult8bit(E->draygon_var_0D) + 384; + E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); uint16 x_subpos; x_subpos = E->base.x_subpos; @@ -564,7 +521,7 @@ void Draygon_Func_20(void) { // 0xA58D30 if (v5 < 0 && sign16(v5 + 80)) { LABEL_8: if (!samus_x_speed_divisor) { - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = addr_kDraygon_Ilist_97E7; E3->base.instruction_timer = 1; Get_Draygon(0)->draygon_var_A = FUNC16(Draygon_Func_21); @@ -583,8 +540,7 @@ void Draygon_Func_21(uint16 k) { // 0xA58DB2 if (samus_x_speed_divisor) { E->draygon_var_A = FUNC16(Draygon_Func_22); } else { - draw_enemy_layer = 32; - E->base.y_pos = CosineMult8bit(E->draygon_var_0D) + 384; + E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); uint16 x_subpos = E->base.x_subpos; bool v3 = x_subpos < E->draygon_var_E; @@ -618,10 +574,10 @@ void Draygon_Func_22(void) { // 0xA58E19 uint16 v5 = addr_kDraygon_Ilist_9845; if (E->draygon_var_20) v5 = addr_kDraygon_Ilist_9C38; - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = v5; E3->base.instruction_timer = 1; - if (CallSomeSamusCode(0xDu)) { + if (CallSomeSamusCode(0xD)) { E->draygon_var_A = FUNC16(Draygon_Func_23); } else { Samus_SetGrabbedByDraygonPose(E->draygon_var_20 != 0); @@ -634,17 +590,9 @@ void Draygon_Func_22(void) { // 0xA58E19 E->draygon_var_A = FUNC16(Draygon_Func_24); } } else { - R18_ = samus_x_pos - E->base.x_pos; - R20_ = samus_y_pos - E->base.y_pos; - enemy_population_ptr = (uint8)(64 - CalculateAngleFromXY()); - R18_ = enemy_population_ptr; - R20_ = 2; - ConvertAngleToXy(); - varE24 = R22_; - varE26 = R24_; - varE28 = R26_; - varE2A = R28_; - EnemyFunc_B691(); + uint16 varE20 = (uint8)(64 - CalculateAngleFromXY(samus_x_pos - E->base.x_pos, samus_y_pos - E->base.y_pos)); + Point32 pt = ConvertAngleToXy(varE20, 2); + EnemyFunc_B691(varE20, pt); } } else { E->draygon_var_A = FUNC16(Draygon_Func_30); @@ -662,7 +610,7 @@ void Draygon_Func_24(uint16 k) { // 0xA58F1E if ((samus_grapple_flags & 1) != 0) { E->base.flash_timer = get_EnemyDef_A2(E->base.enemy_ptr)->hurt_ai_time + 8; - E->base.ai_handler_bits |= 2u; + E->base.ai_handler_bits |= 2; } else { uint16 v4 = Abs16(E->base.x_pos - 256); if (sign16(v4 - 2) && (v5 = Abs16(E->base.y_pos - 384), sign16(v5 - 2))) { @@ -675,17 +623,9 @@ void Draygon_Func_24(uint16 k) { // 0xA58F1E EK->base.instruction_timer = 1; E->base.properties |= kEnemyProps_Tangible; } else { - R18_ = 256 - E->base.x_pos; - R20_ = 384 - E->base.y_pos; - enemy_population_ptr = (uint8)(64 - CalculateAngleFromXY()); - R18_ = enemy_population_ptr; - R20_ = 2; - ConvertAngleToXy(); - varE24 = R22_; - varE26 = R24_; - varE28 = R26_; - varE2A = R28_; - EnemyFunc_B691(); + uint16 varE20 = (uint8)(64 - CalculateAngleFromXY(256 - E->base.x_pos, 384 - E->base.y_pos)); + Point32 pt = ConvertAngleToXy(varE20, 2); + EnemyFunc_B691(varE20, pt); Draygon_Func_40(k); } } @@ -697,20 +637,14 @@ void Draygon_Func_25(uint16 k) { // 0xA58FD6 if ((samus_grapple_flags & 1) != 0) { E->base.flash_timer = get_EnemyDef_A2(E->base.enemy_ptr)->hurt_ai_time + 8; - E->base.ai_handler_bits |= 2u; + E->base.ai_handler_bits |= 2; } else if ((uint8)random_number) { - draw_enemy_layer = E->draygon_var_05; - E->base.x_pos = E->draygon_var_06 + CosineMult8bit(E->draygon_var_08); - draw_enemy_layer = E->draygon_var_05 >> 2; - E->base.y_pos = E->draygon_var_07 + SineMult8bitNegative(E->draygon_var_08); + E->base.x_pos = E->draygon_var_06 + CosineMult8bit(E->draygon_var_08, E->draygon_var_05); + E->base.y_pos = E->draygon_var_07 + SineMult8bit(E->draygon_var_08, E->draygon_var_05 >> 2); if ((Get_Draygon(k)->base.frame_counter & 7) == 0) { - R18_ = E->base.x_pos - 32; - if (E->draygon_var_20) - R18_ = E->base.x_pos + 32; - R20_ = E->base.y_pos - 16; - R22_ = 61; - R24_ = 0; - CreateSpriteAtPos(); + uint16 x = E->draygon_var_20 ? E->base.x_pos + 32 : E->base.x_pos - 32; + uint16 y = E->base.y_pos - 16; + CreateSpriteAtPos(x, y, 61, 0); } uint16 draygon_var_09 = E->draygon_var_09; E->draygon_var_09 = draygon_var_09 + 0x2000; @@ -806,45 +740,30 @@ void Draygon_Func_30(void) { // 0xA59154 void Draygon_Func_31(void) { // 0xA59185 Enemy_Draygon *E = Get_Draygon(0); if ((Get_Draygon(cur_enemy_index)->base.frame_counter & 0xF) == 0) { - R18_ = E->base.x_pos - 32; - if (E->draygon_var_20) - R18_ = E->base.x_pos + 32; - R20_ = E->base.y_pos - 16; - R22_ = 61; - R24_ = 0; - CreateSpriteAtPos(); + uint16 x = E->draygon_var_20 ? E->base.x_pos + 32 : E->base.x_pos - 32; + uint16 y = E->base.y_pos - 16; + CreateSpriteAtPos(x, y, 61, 0); } - R18_ = E->base.x_pos >> 2; - R18_ = 64 - R18_; - R20_ = E->base.y_pos >> 2; - R20_ = 120 - R20_; - E->draygon_var_43 = (uint8)(64 - CalculateAngleFromXY()); - R20_ = 1; - R18_ = LOBYTE(E->draygon_var_43); - ConvertAngleToXy(); - varE24 = R22_; - varE26 = R24_; - varE28 = R26_; - varE2A = R28_; - enemy_population_ptr = LOBYTE(E->draygon_var_43); - EnemyFunc_B691(); + E->draygon_var_43 = (uint8)(64 - CalculateAngleFromXY(64 - (E->base.x_pos >> 2), 120 - (E->base.y_pos >> 2))); + Point32 pt = ConvertAngleToXy(LOBYTE(E->draygon_var_43), 1); + EnemyFunc_B691(LOBYTE(E->draygon_var_43), pt); uint16 v3 = Abs16(E->base.x_pos - 256); if (sign16(v3 - 4)) { uint16 v4 = Abs16(E->base.y_pos - 480); if (sign16(v4 - 4)) { Draygon_Func_43(); E->draygon_var_A = FUNC16(Draygon_Func_32); - QueueMusic_Delayed8(3u); + QueueMusic_Delayed8(3); E->draygon_var_B = 416; E->base.current_instruction = addr_kDraygon_Ilist_97B9; E->base.instruction_timer = 1; uint16 v5 = E->base.properties | kEnemyProps_Deleted; Get_Draygon(0x80)->base.properties = v5; - Get_Draygon(0xC0u)->base.properties = v5; + Get_Draygon(0xC0)->base.properties = v5; uint16 v6 = addr_kDraygon_Ilist_999C; if (E->draygon_var_20) v6 = addr_kDraygon_Ilist_9D3E; - Enemy_Draygon *E1 = Get_Draygon(0x40u); + Enemy_Draygon *E1 = Get_Draygon(0x40); E1->base.current_instruction = v6; E1->base.instruction_timer = 1; E1->draygon_var_A = FUNC16(nullsub_169_A5); @@ -856,23 +775,23 @@ void Draygon_Func_32(void) { // 0xA59294 Draygon_Func_34(); Enemy_Draygon *E = Get_Draygon(0); if (--E->draygon_var_B) - Draygon_Func_42(); + Draygon_Func_42(0); else E->draygon_var_A = FUNC16(Draygon_Func_33); } void Draygon_Func_33(void) { // 0xA592AB Draygon_Func_34(); - Draygon_Func_42(); + Draygon_Func_42(0); // What is varE24 ? Enemy_Draygon *E = Get_Draygon(0); if (!sign16(++E->base.y_pos - 576)) { E->base.current_instruction = addr_kDraygon_Ilist_98ED; E->base.instruction_timer = 1; uint16 v1 = E->base.properties | kEnemyProps_Deleted; E->base.properties = v1; - Get_Draygon(0x40u)->base.properties = v1; + Get_Draygon(0x40)->base.properties = v1; uint16 v2 = area_index; - *(uint16 *)&boss_bits_for_area[area_index] |= 1u; + *(uint16 *)&boss_bits_for_area[area_index] |= 1; Enemy_ItemDrop_Draygon(v2); Draygon_Func_44(); } @@ -880,24 +799,17 @@ void Draygon_Func_33(void) { // 0xA592AB void Draygon_Func_34(void) { // 0xA592EA if ((nmi_frame_counter_word & 7) == 0) { - R18_ = (NextRandom() & 0x7F) + 192; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) + 400; - R22_ = 21; - R24_ = 0; - CreateSpriteAtPos(); + uint16 x = (NextRandom() & 0x7F) + 192; + uint16 y = ((uint16)(random_number & 0x3F00) >> 8) + 400; + CreateSpriteAtPos(x, y, 21, 0); } } void Draygon_Func_35(void) { // 0xA5931C Enemy_Draygon *Draygon = Get_Draygon(cur_enemy_index); - if ((Draygon->base.frame_counter & 0x7F) == 0) { Draygon = Get_Draygon(0); - R18_ = Draygon->base.x_pos - 16; - R20_ = Draygon->base.y_pos - 16; - R22_ = 24; - R24_ = 0; - CreateSpriteAtPos(); + CreateSpriteAtPos(Draygon->base.x_pos - 16, Draygon->base.y_pos - 16, 24, 0); } } @@ -919,12 +831,12 @@ void Draygon_Func_37(void) { // 0xA59367 v0 = addr_kDraygon_Ilist_9C90; E->base.current_instruction = v0; E->base.instruction_timer = 1; - } else if ((joypad2_new_keys & 0x8000u) == 0) { + } else if ((joypad2_new_keys & 0x8000) == 0) { if ((joypad2_new_keys & 0x80) != 0) { uint16 v4 = addr_kDraygon_Ilist_9825; if (E->draygon_var_20) v4 = addr_kDraygon_Ilist_9C18; - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.current_instruction = v4; E3->base.instruction_timer = 1; } @@ -1084,23 +996,19 @@ void sub_A5960D(void) { // 0xA5960D uint16 v3 = addr_kDraygon_Ilist_997A; if (E->draygon_var_20) v3 = addr_kDraygon_Ilist_9D1C; - Enemy_Draygon *E1 = Get_Draygon(0x40u); + Enemy_Draygon *E1 = Get_Draygon(0x40); E1->base.current_instruction = v3; E1->base.instruction_timer = 1; E1->draygon_var_A = FUNC16(nullsub_169_A5); E->draygon_var_A = FUNC16(Draygon_Func_31); Samus_ReleaseFromDraygon_(); samus_grapple_flags = 0; - R18_ = 256 - E->base.x_pos; - R20_ = 480 - E->base.y_pos; - E->draygon_var_43 = (uint8)(64 - CalculateAngleFromXY()); - R20_ = 1; - R18_ = LOBYTE(E->draygon_var_43); - ConvertAngleToXy(); - E->draygon_var_28 = R22_; - E->draygon_var_29 = R24_; - E->draygon_var_2A = R26_; - E->draygon_var_2B = R28_; + E->draygon_var_43 = (uint8)(64 - CalculateAngleFromXY(256 - E->base.x_pos, 480 - E->base.y_pos)); + Point32 pt = ConvertAngleToXy(LOBYTE(E->draygon_var_43), 1); + E->draygon_var_28 = pt.x >> 16; + E->draygon_var_29 = pt.x; + E->draygon_var_2A = pt.y >> 16; + E->draygon_var_2B = pt.y; } } @@ -1127,47 +1035,38 @@ const uint16 *Draygon_Instr_13(uint16 k, const uint16 *jp) { // 0xA59736 return jp + 1; } +static Point16U Draygon_Func_47(void) { // 0xA5978B + NextRandom(); + Enemy_Draygon *E = Get_Draygon(0); + uint16 r18 = (random_number & 0x7F) - 64; + uint16 r20 = ((random_number & 0x7F00) >> 8) - 64; + return (Point16U) {r18 + E->base.x_pos, r20 + E->base.y_pos}; +} + const uint16 *Draygon_Instr_8(uint16 k, const uint16 *jp) { // 0xA5973F - Draygon_Func_47(); - R22_ = 21; - R24_ = 0; - CreateSpriteAtPos(); + Point16U pt = Draygon_Func_47(); + CreateSpriteAtPos(pt.x, pt.y, 21, 0); return jp; } const uint16 *Draygon_Instr_7(uint16 k, const uint16 *jp) { // 0xA59752 - Draygon_Func_47(); - R22_ = 3; - R24_ = 0; - CreateSpriteAtPos(); + Point16U pt = Draygon_Func_47(); + CreateSpriteAtPos(pt.x, pt.y, 3, 0); return jp; } const uint16 *Draygon_Instr_6(uint16 k, const uint16 *jp) { // 0xA59765 - Draygon_Func_47(); - R22_ = 29; - R24_ = 0; - CreateSpriteAtPos(); + Point16U pt = Draygon_Func_47(); + CreateSpriteAtPos(pt.x, pt.y, 29, 0); return jp; } const uint16 *Draygon_Instr_9(uint16 k, const uint16 *jp) { // 0xA59778 - Draygon_Func_47(); - R22_ = 24; - R24_ = 0; - CreateSpriteAtPos(); + Point16U pt = Draygon_Func_47(); + CreateSpriteAtPos(pt.x, pt.y, 24, 0); return jp; } -void Draygon_Func_47(void) { // 0xA5978B - NextRandom(); - R18_ = (random_number & 0x7F) - 64; - Enemy_Draygon *E = Get_Draygon(0); - R18_ += E->base.x_pos; - R20_ = ((uint16)(random_number & 0x7F00) >> 8) - 64; - R20_ += E->base.y_pos; -} - const uint16 *Draygon_Instr_2(uint16 k, const uint16 *jp) { // 0xA59895 room_loading_irq_handler = 12; return jp; @@ -1178,7 +1077,7 @@ const uint16 *Draygon_Instr_11(uint16 k, const uint16 *jp) { // 0xA598D3 E2->base.instruction_timer = 1; E2->base.current_instruction = addr_kDraygon_Ilist_97B9; - Enemy_Draygon *E3 = Get_Draygon(0xC0u); + Enemy_Draygon *E3 = Get_Draygon(0xC0); E3->base.instruction_timer = 1; E3->base.current_instruction = addr_kDraygon_Ilist_97B9; return jp; @@ -1194,15 +1093,10 @@ const uint16 *Draygon_Instr_15(uint16 k, const uint16 *jp) { // 0xA59B9A Enemy_Draygon *E = Get_Draygon(0); E->draygon_var_0F = 24; const uint8 *v3 = RomPtr_A0(E->base.enemy_ptr); - uint16 v4 = SuitDamageDivision(GET_WORD(v3 + 6)); - Samus_DealDamage(v4); + Samus_DealDamage(SuitDamageDivision(GET_WORD(v3 + 6))); earthquake_timer = 32; earthquake_type = 7; - R18_ = samus_x_pos; - R20_ = samus_y_pos + 16; - R22_ = 21; - R24_ = 0; - CreateSpriteAtPos(); + CreateSpriteAtPos(samus_x_pos, samus_y_pos + 16, 21, 0); return jp; } @@ -1235,23 +1129,21 @@ const uint16 *Draygon_Instr_4(uint16 k, const uint16 *jp) { // 0xA59F6E const uint16 *Draygon_Instr_12(uint16 k, const uint16 *jp) { // 0xA59F7C Enemy_Draygon *E = Get_Draygon(0); - R18_ = E->base.x_pos - 28; - R20_ = E->base.y_pos - 16; + eproj_spawn_pt = (Point16U){ E->base.x_pos - 28, E->base.y_pos - 16 }; enemy_projectile_unk1995 = (NextRandom() & 0x3F) + 128; - SpawnEnemyProjectileWithGfx(2u, cur_enemy_index, addr_stru_868E50); + SpawnEnemyProjectileWithGfx(2, cur_enemy_index, addr_stru_868E50); return jp; } const uint16 *Draygon_Instr_18(uint16 k, const uint16 *jp) { // 0xA59FAE Enemy_Draygon *E = Get_Draygon(0); - R18_ = E->base.x_pos + 24; - R20_ = E->base.y_pos - 16; + eproj_spawn_pt = (Point16U){ E->base.x_pos + 24, E->base.y_pos - 16 }; enemy_projectile_unk1995 = (NextRandom() & 0x3F) + 192; - SpawnEnemyProjectileWithGfx(2u, cur_enemy_index, addr_stru_868E50); + SpawnEnemyProjectileWithGfx(2, cur_enemy_index, addr_stru_868E50); return jp; } -void Draygon_Func_42(void) { // 0xA59FE0 +void Draygon_Func_42(uint16 varE24) { // 0xA59FE0 uint16 v0 = 62; for (int i = 20; i >= 0; i -= 4) { int v2 = i >> 1; @@ -1261,24 +1153,26 @@ void Draygon_Func_42(void) { // 0xA59FE0 bool v5 = __CFADD__uint16(g_word_A5A1AF[v2], v4); sprite_x_subpos[v3] = g_word_A5A1AF[v2] + v4; v6 = v5 + sprite_x_pos[v3]; + sprite_x_pos[v3] = v6; } else { bool v5 = v4 < g_word_A5A1AF[v2]; sprite_x_subpos[v3] = v4 - g_word_A5A1AF[v2]; v6 = sprite_x_pos[v3] - (v5 + varE24); + sprite_x_pos[v3] = v6; } - sprite_x_pos[v3] = v6; int v7 = v0 >> 1; uint16 v8 = sprite_y_subpos[v7], v9; if (((g_word_A5A1DF[v2] + 128) & 0x80) != 0) { bool v5 = __CFADD__uint16(g_word_A5A1AF[v2 + 1], v8); sprite_y_subpos[v7] = g_word_A5A1AF[v2 + 1] + v8; v9 = v5 + sprite_y_pos[v7]; + sprite_y_pos[v7] = v9; } else { bool v5 = v8 < g_word_A5A1AF[v2 + 1]; sprite_y_subpos[v7] = v8 - g_word_A5A1AF[v2 + 1]; v9 = sprite_y_pos[v7] - v5; + sprite_y_pos[v7] = v9; } - sprite_y_pos[v7] = v9; v0 -= 2; } } @@ -1293,21 +1187,12 @@ void Draygon_Func_43(void) { // 0xA5A06C uint16 v2 = 20; do { int v3 = v2 >> 1; - R18_ = g_word_A5A1C7[v3]; - R20_ = g_word_A5A1C7[v3 + 1]; - R22_ = 59; - R24_ = 3584; - CreateSpriteAtPos(); + CreateSpriteAtPos(g_word_A5A1C7[v3], g_word_A5A1C7[v3 + 1], 59, 0xe00); v2 -= 4; - --v1; - } while (v1 >= 0); + } while (--v1 >= 0); for (j = 2; j >= 0; --j) { int v5 = v2 >> 1; - R18_ = g_word_A5A1C7[v5]; - R20_ = g_word_A5A1C7[v5 + 1]; - R22_ = 60; - R24_ = 3584; - CreateSpriteAtPos(); + CreateSpriteAtPos(g_word_A5A1C7[v5], g_word_A5A1C7[v5 + 1], 60, 0xe00); v2 -= 4; } } @@ -1318,33 +1203,17 @@ void Draygon_Func_44(void) { // 0xA5A0C6 } void Draygon_Func_45(void) { // 0xA5A0D9 - R18_ = 16; - R20_ = 384; - R22_ = 59; - R24_ = 3584; - CreateSpriteAtPos(); - R18_ = 16; - R20_ = 384; - R22_ = 59; - R24_ = 3584; - CreateSpriteAtPos(); - R18_ = 16; - R20_ = 384; - R22_ = 59; - R24_ = 3584; - CreateSpriteAtPos(); - R18_ = 16; - R20_ = 384; - R22_ = 59; - R24_ = 3584; - CreateSpriteAtPos(); + CreateSpriteAtPos(16, 384, 59, 0xe00); + CreateSpriteAtPos(16, 384, 59, 0xe00); + CreateSpriteAtPos(16, 384, 59, 0xe00); + CreateSpriteAtPos(16, 384, 59, 0xe00); } void Draygon_Func_46(void) { // 0xA5A13E uint16 v0 = 62; do { uint16 v1 = Get_Draygon(0)->draygon_var_46 + g_word_A5A19F[(uint16)(v0 - 56) >> 1]; - if ((v1 & 0x8000u) == 0) { + if ((v1 & 0x8000) == 0) { uint16 v2 = v1; if (*(uint16 *)&g_byte_A5CE07[v1] == 0x8080) { sprite_instr_list_ptrs[v0 >> 1] = 0; @@ -1367,7 +1236,7 @@ void DraygonsEye_Init(void) { // 0xA5C46B } const uint16 *Draygon_Instr_3(uint16 k, const uint16 *jp) { // 0xA5C47B - Get_Draygon(0x40u)->draygon_var_A = jp[0]; + Get_Draygon(0x40)->draygon_var_A = jp[0]; return jp + 1; } @@ -1378,17 +1247,12 @@ void DraygonsEye_Main(void) { // 0xA5C486 void Draygon_Func_48(uint16 k) { // 0xA5C48D if ((Get_Draygon(k)->base.frame_counter & 0x7F) == 0) { - Enemy_Draygon *E1 = Get_Draygon(0x40u); - R18_ = E1->base.x_pos - 24; - R20_ = E1->base.y_pos - 32; + Enemy_Draygon *E1 = Get_Draygon(0x40); + eproj_spawn_pt = (Point16U){ E1->base.x_pos - 24, E1->base.y_pos - 32 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x18); } Enemy_Draygon *E0 = Get_Draygon(0); - R18_ = E0->base.x_pos - 24; - R18_ = samus_x_pos - R18_; - R20_ = E0->base.y_pos - 32; - R20_ = samus_y_pos - R20_; - uint16 v4 = CalculateAngleFromXY(); + uint16 v4 = CalculateAngleFromXY(samus_x_pos - (E0->base.x_pos - 24), samus_y_pos - (E0->base.y_pos - 32)); Enemy_Draygon *E = Get_Draygon(cur_enemy_index); if (v4 != E->draygon_var_F) { uint16 v6 = addr_kDraygon_Ilist_99BA; @@ -1414,16 +1278,11 @@ void Draygon_Func_49(uint16 k) { // 0xA5C513 Enemy_Draygon *E0 = Get_Draygon(0); if ((Get_Draygon(k)->base.frame_counter & 0x7F) == 0) { - R18_ = E0->base.x_pos + 24; - R20_ = E0->base.y_pos - 32; + eproj_spawn_pt = (Point16U){ E0->base.x_pos + 24, E0->base.y_pos - 32 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x18); } - R18_ = E0->base.x_pos + 24; - R18_ = samus_x_pos - R18_; - R20_ = E0->base.y_pos - 32; - R20_ = samus_y_pos - R20_; - uint16 v4 = CalculateAngleFromXY(); + uint16 v4 = CalculateAngleFromXY(samus_x_pos - (E0->base.x_pos + 24), samus_y_pos - (E0->base.y_pos - 32)); Enemy_Draygon *E = Get_Draygon(cur_enemy_index); if (v4 != E->draygon_var_F) { uint16 v6 = addr_kDraygon_Ilist_9D5C; @@ -1448,13 +1307,13 @@ void Draygon_Func_49(uint16 k) { // 0xA5C513 void DraygonsTail_Init(void) { // 0xA5C599 EnemyData *v0 = gEnemyData(cur_enemy_index); v0->current_instruction = addr_kDraygon_Ilist_99FC; - v0->palette_index = 3584; + v0->palette_index = 0xe00; } void DraygonsArms_Init(void) { // 0xA5C5AD EnemyData *v0 = gEnemyData(cur_enemy_index); v0->current_instruction = addr_kDraygon_Ilist_97E7; - v0->palette_index = 3584; + v0->palette_index = 0xe00; v0->layer = 2; } @@ -1553,53 +1412,46 @@ const uint16 *Draygon_Instr_19(uint16 k, const uint16 *jp) { // 0xA5E91C const uint16 *Draygon_Instr_28(uint16 k, const uint16 *jp) { // 0xA5E96E NextRandom(); - R18_ = (random_number & 0x7F) - 64; + uint16 r18 = (random_number & 0x7F) - 64; Enemy_Draygon *E = Get_Draygon(0); - R18_ += E->base.x_pos; - R20_ = ((uint16)(random_number & 0x7F00) >> 8) - 64; - R20_ += E->base.y_pos; + r18 += E->base.x_pos; + uint16 r20 = ((uint16)(random_number & 0x7F00) >> 8) - 64; + r20 += E->base.y_pos; + eproj_spawn_pt = (Point16U){ r18, r20 }; SpawnEnemyProjectileWithRoomGfx(0xE509, 0x15); - QueueSfx2_Max6(0x29u); + QueueSfx2_Max6(0x29); return jp; } const uint16 *Draygon_Instr_26(uint16 k, const uint16 *jp) { // 0xA5E9B1 NextRandom(); - R18_ = (random_number & 0x7F) - 64; Enemy_Draygon *E = Get_Draygon(0); - R18_ += E->base.x_pos; - R20_ = ((uint16)(random_number & 0x3F00) >> 8) - 32; - R20_ += E->base.y_pos; - R22_ = 3; - R24_ = 0; - CreateSpriteAtPos(); - QueueSfx2_Max6(0x25u); + uint16 x = E->base.x_pos + (random_number & 0x7F) - 64; + uint16 y = E->base.y_pos + ((uint16)(random_number & 0x3F00) >> 8) - 32; + CreateSpriteAtPos(x, y, 3, 0); + QueueSfx2_Max6(0x25); return jp; } void sub_A5E9F5(void) { // 0xA5E9F5 if ((nmi_frame_counter_word & 0xF) == 0) { NextRandom(); - R18_ = (random_number & 0x3F) + 96; - R20_ = ((uint16)(random_number & 0xF00) >> 8) + 480; - R22_ = 21; - R24_ = 0; - CreateSpriteAtPos(); + uint16 x = (random_number & 0x3F) + 96; + uint16 y = ((uint16)(random_number & 0xF00) >> 8) + 480; + CreateSpriteAtPos(x, y, 21, 0); } } void SporeSpawn_Init(void) { // 0xA5EA2A - static const SpawnHardcodedPlmArgs unk_A5EAB7 = { 0x07, 0x1e, 0xb793 }; - uint16 v0 = 0; for (int i = 0; i != 32; i += 2) { target_palettes[(i >> 1) + 240] = kSporeSpawn_Palette[v0 >> 1]; v0 += 2; } SpawnEnemyProjectileWithGfx(0, cur_enemy_index, addr_kEproj_SporeSpawnsStalk); - SpawnEnemyProjectileWithGfx(1u, cur_enemy_index, addr_kEproj_SporeSpawnsStalk); - SpawnEnemyProjectileWithGfx(2u, cur_enemy_index, addr_kEproj_SporeSpawnsStalk); - SpawnEnemyProjectileWithGfx(3u, cur_enemy_index, addr_kEproj_SporeSpawnsStalk); + SpawnEnemyProjectileWithGfx(1, cur_enemy_index, addr_kEproj_SporeSpawnsStalk); + SpawnEnemyProjectileWithGfx(2, cur_enemy_index, addr_kEproj_SporeSpawnsStalk); + SpawnEnemyProjectileWithGfx(3, cur_enemy_index, addr_kEproj_SporeSpawnsStalk); Enemy_SporeSpawn *E = Get_SporeSpawn(cur_enemy_index); Enemy_SporeSpawn *E0 = Get_SporeSpawn(0); E->ssn_var_04 = E->base.x_pos; @@ -1610,9 +1462,9 @@ void SporeSpawn_Init(void) { // 0xA5EA2A if ((boss_bits_for_area[area_index] & 2) != 0) { E0->base.current_instruction = addr_kDraygon_Ilist_E6B9; E0->ssn_var_A = FUNC16(nullsub_223); - E0->base.properties |= 0x8000u; + E0->base.properties |= 0x8000; SporeSpawn_Func_5(); - SpawnHardcodedPlm(&unk_A5EAB7); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x07, 0x1e, 0xb793 }); scrolling_finished_hook = 0; } else { E0->base.current_instruction = addr_kDraygon_Ilist_E6C7; @@ -1622,9 +1474,9 @@ void SporeSpawn_Init(void) { // 0xA5EA2A scrolling_finished_hook = FUNC16(Samus_ScrollFinishedHook_SporeSpawnFight); E->base.y_pos -= 128; SpawnEnemyProjectileWithGfx(0, v5, addr_kEproj_SporeSpawners); - SpawnEnemyProjectileWithGfx(1u, v5, addr_kEproj_SporeSpawners); - SpawnEnemyProjectileWithGfx(2u, v5, addr_kEproj_SporeSpawners); - SpawnEnemyProjectileWithGfx(3u, v5, addr_kEproj_SporeSpawners); + SpawnEnemyProjectileWithGfx(1, v5, addr_kEproj_SporeSpawners); + SpawnEnemyProjectileWithGfx(2, v5, addr_kEproj_SporeSpawners); + SpawnEnemyProjectileWithGfx(3, v5, addr_kEproj_SporeSpawners); SporeSpawn_Func_5(); } } @@ -1663,39 +1515,28 @@ void SporeSpawn_Func_1(void) { // 0xA5EB1B void SporeSpawn_Func_2(uint16 k) { // 0xA5EB52 SporeSpawn_Func_5(); Enemy_SporeSpawn *E0 = Get_SporeSpawn(0); - draw_enemy_layer = E0->ssn_var_0B; - uint16 v2 = CosineMult8bit(E0->ssn_var_0A); Enemy_SporeSpawn *E = Get_SporeSpawn(k); - E->base.x_pos = E->ssn_var_C + v2; - draw_enemy_layer = E0->ssn_var_0B - 16; - E->base.y_pos = E->ssn_var_D + SineMult8bitNegative(2 * (E0->ssn_var_0A - 64)); + E->base.x_pos = E->ssn_var_C + CosineMult8bit(E0->ssn_var_0A, E0->ssn_var_0B); + E->base.y_pos = E->ssn_var_D + SineMult8bit(2 * (E0->ssn_var_0A - 64), E0->ssn_var_0B - 16); E0->ssn_var_0A = (uint8)(LOBYTE(E0->ssn_var_0C) + E0->ssn_var_0A); } void SporeSpawn_Func_3(void) { // 0xA5EB9B Enemy_SporeSpawn *E0 = Get_SporeSpawn(0); - R18_ = 128 - E0->base.x_pos; - R20_ = 624 - E0->base.y_pos; - E0->ssn_var_43 = (uint8)(64 - CalculateAngleFromXY()); - R20_ = 1; - R18_ = LOBYTE(E0->ssn_var_43); - ConvertAngleToXy(); + E0->ssn_var_43 = (uint8)(64 - CalculateAngleFromXY(128 - E0->base.x_pos, 624 - E0->base.y_pos)); Enemy_SporeSpawn *E = Get_SporeSpawn(cur_enemy_index); - E->ssn_var_28 = R22_; - E->ssn_var_29 = R24_; - E->ssn_var_2A = R26_; - E->ssn_var_2B = R28_; + Point32 pt = ConvertAngleToXy(LOBYTE(E0->ssn_var_43), 1); + E->ssn_var_28 = pt.x >> 16; + E->ssn_var_29 = pt.x; + E->ssn_var_2A = pt.y >> 16; + E->ssn_var_2B = pt.y; } void SporeSpawn_Func_4(void) { // 0xA5EBEE Enemy_SporeSpawn *E = Get_SporeSpawn(cur_enemy_index); - varE24 = E->ssn_var_28; - varE26 = E->ssn_var_29; - varE28 = E->ssn_var_2A; - varE2A = E->ssn_var_2B; Enemy_SporeSpawn *E0 = Get_SporeSpawn(0); - enemy_population_ptr = LOBYTE(E0->ssn_var_43); - EnemyFunc_B691(); + uint16 varE20 = LOBYTE(E0->ssn_var_43); + EnemyFunc_B691(varE20, (Point32) { __PAIR32__(E->ssn_var_28, E->ssn_var_29), __PAIR32__(E->ssn_var_2A, E->ssn_var_2B) }); uint16 v2 = Abs16(E0->base.x_pos - 128); if (sign16(v2 - 8)) { uint16 v3 = Abs16(E0->base.y_pos - 624); @@ -1709,50 +1550,49 @@ void SporeSpawn_Func_4(void) { // 0xA5EBEE void SporeSpawn_Func_5(void) { // 0xA5EC49 Enemy_SporeSpawn *E = Get_SporeSpawn(0); uint16 v1 = E->base.x_pos - E->ssn_var_04, v2; - if ((v1 & 0x8000u) == 0) { - R18_ = v1 >> 1; - R20_ = v1 >> 2; - R22_ = (v1 >> 1) + (v1 >> 2); + uint16 r18, r20, r22; + if ((v1 & 0x8000) == 0) { + r18 = v1 >> 1, r20 = v1 >> 2; + r22 = (v1 >> 1) + (v1 >> 2); enemy_projectile_x_pos[14] = 128; enemy_projectile_x_pos[15] = E->ssn_var_04 + (v1 >> 2); E->ssn_var_20 = enemy_projectile_x_pos[15]; - enemy_projectile_x_pos[16] = E->ssn_var_04 + R18_; + enemy_projectile_x_pos[16] = E->ssn_var_04 + r18; E->ssn_var_21 = enemy_projectile_x_pos[16]; - v2 = E->ssn_var_04 + R22_; + v2 = E->ssn_var_04 + r22; } else { - R18_ = (uint16)(E->ssn_var_04 - E->base.x_pos) >> 1; - R20_ = (uint16)-v1 >> 2; - R22_ = R18_ + R20_; + r18 = (uint16)(E->ssn_var_04 - E->base.x_pos) >> 1; + r20 = (uint16)-v1 >> 2; + r22 = r18 + r20; enemy_projectile_x_pos[14] = 128; - enemy_projectile_x_pos[15] = E->ssn_var_04 - R20_; + enemy_projectile_x_pos[15] = E->ssn_var_04 - r20; E->ssn_var_20 = enemy_projectile_x_pos[15]; - enemy_projectile_x_pos[16] = E->ssn_var_04 - R18_; + enemy_projectile_x_pos[16] = E->ssn_var_04 - r18; E->ssn_var_21 = enemy_projectile_x_pos[16]; - v2 = E->ssn_var_04 - R22_; + v2 = E->ssn_var_04 - r22; } enemy_projectile_x_pos[17] = v2; E->ssn_var_22 = v2; uint16 v3 = E->base.y_pos - 40 - E->ssn_var_05, v4; - if ((v3 & 0x8000u) == 0) { - R18_ = v3 >> 1; - R20_ = v3 >> 2; - R22_ = (v3 >> 1) + (v3 >> 2); + if ((v3 & 0x8000) == 0) { + r18 = v3 >> 1, r20 = v3 >> 2; + r22 = (v3 >> 1) + (v3 >> 2); enemy_projectile_y_pos[14] = 560; enemy_projectile_y_pos[15] = E->ssn_var_05 + (v3 >> 2); E->ssn_var_23 = enemy_projectile_y_pos[15]; - enemy_projectile_y_pos[16] = E->ssn_var_05 + R18_; + enemy_projectile_y_pos[16] = E->ssn_var_05 + r18; E->ssn_var_24 = enemy_projectile_y_pos[16]; - v4 = E->ssn_var_05 + R22_; + v4 = E->ssn_var_05 + r22; } else { - R18_ = (uint16)(E->ssn_var_05 - (E->base.y_pos - 40)) >> 1; - R20_ = (uint16)-v3 >> 2; - R22_ = R18_ + R20_; + r18 = (uint16)(E->ssn_var_05 - (E->base.y_pos - 40)) >> 1; + r20 = (uint16)-v3 >> 2; + r22 = r18 + r20; enemy_projectile_y_pos[14] = 560; - enemy_projectile_y_pos[15] = E->ssn_var_05 - R20_; + enemy_projectile_y_pos[15] = E->ssn_var_05 - r20; E->ssn_var_23 = enemy_projectile_y_pos[15]; - enemy_projectile_y_pos[16] = E->ssn_var_05 - R18_; + enemy_projectile_y_pos[16] = E->ssn_var_05 - r18; E->ssn_var_24 = enemy_projectile_y_pos[16]; - v4 = E->ssn_var_05 - R22_; + v4 = E->ssn_var_05 - r22; } enemy_projectile_y_pos[17] = v4; E->ssn_var_25 = v4; @@ -1772,7 +1612,7 @@ void SporeSpawn_Shot(void) { // 0xA5ED5A EK->ssn_var_A = FUNC16(SporeSpawn_Func_2); v4 = 2; if (sign16(EK->base.health - 400)) { - if ((E->ssn_var_0C & 0x8000u) != 0) + if ((E->ssn_var_0C & 0x8000) != 0) v4 = -2; E->ssn_var_0C = v4; } @@ -1807,8 +1647,6 @@ void SporeSpawn_Touch(void) { // 0xA5EDEC } void SporeSpawn_Func_6(void) { // 0xA5EDF3 - static const SpawnHardcodedPlmArgs unk_A5EE45 = { 0x07, 0x1e, 0xb78f }; - if (!Get_SporeSpawn(cur_enemy_index)->base.health) { Enemy_SporeSpawn *E = Get_SporeSpawn(cur_enemy_index); Enemy_SporeSpawn *E0 = Get_SporeSpawn(0); @@ -1821,17 +1659,16 @@ void SporeSpawn_Func_6(void) { // 0xA5EDF3 *(uint16 *)((uint8 *)enemy_projectile_id + (uint16)i) = 0; E0->base.current_instruction = addr_kDraygon_Ilist_E77D; E0->base.instruction_timer = 1; - *(uint16 *)&boss_bits_for_area[area_index] |= 2u; + *(uint16 *)&boss_bits_for_area[area_index] |= 2; scrolling_finished_hook = 0; - SpawnHardcodedPlm(&unk_A5EE45); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x07, 0x1e, 0xb78f }); } } void SporeSpawn_Func_7(uint16 a) { // 0xA5EE4A - R18_ = a; uint16 v1 = a; for (int i = 0; i != 32; i += 2) { palette_buffer[(i >> 1) + 144] = g_word_A5E379[v1 >> 1]; v1 += 2; } -} \ No newline at end of file +} diff --git a/src/sm_a6.c b/src/sm_a6.c index 63d9821..3cfed58 100644 --- a/src/sm_a6.c +++ b/src/sm_a6.c @@ -5,7 +5,6 @@ #include "funcs.h" #include "enemy_types.h" - #define g_byte_A6E269 ((uint8*)RomFixedPtr(0xa6e269)) #define g_word_A6E2AA ((uint16*)RomFixedPtr(0xa6e2aa)) #define g_word_A6E30A ((uint16*)RomFixedPtr(0xa6e30a)) @@ -63,11 +62,11 @@ #define g_off_A6FD4A ((uint16*)RomFixedPtr(0xa6fd4a)) #define g_off_A6FD54 ((uint16*)RomFixedPtr(0xa6fd54)) +static PairU16 NuclearWaffle_Func_6(uint16 a); - -int BabyMetroid_DBCB_DoubleRetEx(uint16 a); -uint8 Ridley_Func_40_Carry(); -uint8 Ridley_Func_40_Sign(); +static int BabyMetroid_DBCB_DoubleRetEx(uint16 a); +static uint8 Ridley_Func_40_Carry(); +static uint8 Ridley_Func_40_Sign(); static const uint16 g_word_A686F1[2] = { 0x1000, 0x1800 }; static const uint16 g_word_A68DBB = 5; @@ -265,21 +264,18 @@ void Boulder_Func_3(void) { // 0xA68832 void Boulder_Func_4(void) { // 0xA6888B Enemy_Boulder *E = Get_Boulder(cur_enemy_index); - int v1 = (uint16)(8 * HIBYTE(E->boulder_var_C)) >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v1]; - R20_ = kCommonEnemySpeeds_Quadratic[v1 + 1]; - if (Enemy_MoveDown(cur_enemy_index) & 1) { - QueueSfx2_Max6(0x42u); + int v1 = (8 * HIBYTE(E->boulder_var_C)) >> 1; + if (Enemy_MoveDown(cur_enemy_index, kCommonEnemySpeeds_Quadratic32[v1 >> 1])) { + QueueSfx2_Max6(0x42); if (E->boulder_var_E == 2) { E->base.properties |= kEnemyProps_Deleted; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; + eproj_spawn_pt = (Point16U){ E->base.x_pos, E->base.y_pos }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x11); - QueueSfx2_Max6(0x43u); + QueueSfx2_Max6(0x43); } else { E->boulder_var_A = FUNC16(Boulder_Func_3); E->boulder_var_C = g_word_A686F1[E->boulder_var_D - 1]; - if ((--E->boulder_var_D & 0x8000u) != 0) { + if ((--E->boulder_var_D & 0x8000) != 0) { E->boulder_var_03 = E->base.y_pos; E->boulder_var_02 = E->base.y_subpos; E->boulder_var_A = FUNC16(Boulder_Func_5); @@ -302,23 +298,18 @@ void Boulder_Func_5(void) { // 0xA68942 Enemy_Boulder *E = Get_Boulder(cur_enemy_index); uint16 v2 = 8 * HIBYTE(E->boulder_var_B); int v3 = v2 >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v3]; - R20_ = E->boulder_var_01 + kCommonEnemySpeeds_Quadratic[v3 + 1]; - Enemy_MoveDown(cur_enemy_index); + Enemy_MoveDown(cur_enemy_index, kCommonEnemySpeeds_Quadratic32[v3 >> 1] + (E->boulder_var_01 << 16)); E->base.y_pos -= E->boulder_var_01; if (E->boulder_var_E) v2 += 4; int v4 = v2 >> 1; - R18_ = kCommonEnemySpeeds_Quadratic[v4]; - R20_ = kCommonEnemySpeeds_Quadratic[v4 + 1]; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->base.properties |= 0x300u; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, kCommonEnemySpeeds_Quadratic32[v4 >> 1])) { + E->base.properties |= 0x300; E->boulder_var_A = FUNC16(Boulder_Func_6); - QueueSfx2_Max6(0x42u); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; + QueueSfx2_Max6(0x42); + eproj_spawn_pt = (Point16U){ E->base.x_pos, E->base.y_pos }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x11); - QueueSfx2_Max6(0x43u); + QueueSfx2_Max6(0x43); } else { uint16 v5 = E->boulder_var_B + 64; E->boulder_var_B = v5; @@ -379,10 +370,8 @@ void SpikeyPlatform_Init(void) { // 0xA68B2F uint16 v1 = 8 * LOBYTE(E->spm_parameter_1); E->spm_var_02 = v1; int v2 = v1 >> 1; - R18_ = kCommonEnemySpeeds_Linear[v2]; - R20_ = kCommonEnemySpeeds_Linear[v2 + 1]; - E->spm_var_E = R20_; - E->spm_var_F = R18_; + E->spm_var_E = kCommonEnemySpeeds_Linear[v2 + 1]; + E->spm_var_F = kCommonEnemySpeeds_Linear[v2]; E->spm_var_D = E->base.y_pos + HIBYTE(E->spm_parameter_2); E->spm_var_C = E->base.y_pos; uint16 spm_parameter_2_low = LOBYTE(E->spm_parameter_2); @@ -434,14 +423,12 @@ void SpikeyPlatform_Func_2(void) { // 0xA68BDC Enemy_SpikeyPlatform *E = Get_SpikeyPlatform(cur_enemy_index); E->spm_var_01 = E->base.y_pos; int v1 = E->spm_var_02 >> 1; - R20_ = kCommonEnemySpeeds_Linear[v1]; - R18_ = kCommonEnemySpeeds_Linear[v1 + 1]; - Enemy_AddPos_Y(cur_enemy_index); + Enemy_AddPos_Y(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Linear[v1], kCommonEnemySpeeds_Linear[v1 + 1])); if ((int16)(E->base.y_pos - E->spm_var_D) >= 0) { E->spm_var_03 = 64; E->spm_var_A = FUNC16(SpikeyPlatform_Func_3); E->base.y_pos = E->spm_var_D; - QueueSfx2_Max6(0x1Bu); + QueueSfx2_Max6(0x1B); } if (SpikeyPlatform_Func_5(cur_enemy_index)) extra_samus_y_displacement += E->base.y_pos - E->spm_var_01; @@ -462,9 +449,7 @@ void SpikeyPlatform_Func_3(uint16 k) { // 0xA68C4A void SpikeyPlatform_Func_4(void) { // 0xA68C5D Enemy_SpikeyPlatform *E = Get_SpikeyPlatform(cur_enemy_index); E->spm_var_01 = E->base.y_pos; - R18_ = FUNC16(Enemy_GrappleReact_NoInteract_A6); - R20_ = 0; - Enemy_SubPos_Y(cur_enemy_index); + Enemy_SubPos_Y(cur_enemy_index, 0x8000); if ((int16)(E->base.y_pos - E->spm_var_C) < 0) { E->spm_var_A = FUNC16(SpikeyPlatform_Func_1); E->base.y_pos = E->spm_var_C; @@ -491,7 +476,7 @@ uint16 SpikeyPlatform_Func_5(uint16 k) { // 0xA68CA1 } const uint16 *FireGeyser_Instr_1(uint16 k, const uint16 *jp) { // 0xA68DAF - QueueSfx2_Max6(0x61u); + QueueSfx2_Max6(0x61); return jp; } @@ -680,7 +665,7 @@ const uint16 *FireGeyser_Instr_24(uint16 k, const uint16 *jp) { // 0xA68FD1 E1->base.y_height = 0; E->base.y_pos = E->fgr_var_D; E->base.properties |= kEnemyProps_Invisible; - E1->base.properties |= 0x400u; + E1->base.properties |= 0x400; return jp; } @@ -711,7 +696,7 @@ void FireGeyser_Main(void) { // 0xA69023 void FireGeyser_Func_1(void) { // 0xA6902F Enemy_FireGeyser *E = Get_FireGeyser(cur_enemy_index); - if ((--E->fgr_var_B & 0x8000u) != 0) { + if ((--E->fgr_var_B & 0x8000) != 0) { E->fgr_var_A = FUNC16(FireGeyser_Func_2); E->fgr_var_C = 0; E->base.instruction_timer = 1; @@ -719,7 +704,7 @@ void FireGeyser_Func_1(void) { // 0xA6902F E->base.current_instruction = addr_kFireGeyser_Ilist_8D1B; E->base.properties &= ~kEnemyProps_Invisible; Enemy_FireGeyser *E1 = Get_FireGeyser(cur_enemy_index + 64); - E1->base.properties &= ~0x400u; + E1->base.properties &= ~0x400; } } @@ -759,12 +744,10 @@ void NuclearWaffle_Init(void) { // 0xA694C4 E->nwe_var_24 = kCommonEnemySpeeds_Linear[v5 + 1]; E->nwe_var_26 = E->base.x_pos; E->nwe_var_27 = E->base.y_pos; - draw_enemy_layer = E->nwe_var_D; - uint16 v6 = E->nwe_var_26 + CosineMult8bit(E->nwe_var_23); + uint16 v6 = E->nwe_var_26 + CosineMult8bit(E->nwe_var_23, E->nwe_var_D); E->nwe_var_28 = v6; E->base.x_pos = v6; - draw_enemy_layer = E->nwe_var_D; - uint16 v7 = E->nwe_var_27 + SineMult8bitNegative(E->nwe_var_23); + uint16 v7 = E->nwe_var_27 + SineMult8bit(E->nwe_var_23, E->nwe_var_D); E->nwe_var_29 = v7; E->base.y_pos = v7; uint16 v8 = 8; @@ -777,14 +760,10 @@ void NuclearWaffle_Init(void) { // 0xA694C4 E->nwe_var_2A = 6; uint16 v15; do { - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - R22_ = 43; uint16 v13 = E->base.vram_tiles_index | E->base.palette_index; E->nwe_var_34 = v13; - R24_ = v13; - CreateSpriteAtPos(); - Get_NuclearWaffle(cur_enemy_index + E->nwe_var_2A)->nwe_var_10 = R18_; + uint16 r18 = CreateSpriteAtPos(E->base.x_pos, E->base.y_pos, 43, v13); + Get_NuclearWaffle(cur_enemy_index + E->nwe_var_2A)->nwe_var_10 = r18; v15 = E->nwe_var_2A - 2; E->nwe_var_2A = v15; } while (v15); @@ -805,7 +784,7 @@ void NuclearWaffle_Main(void) { // 0xA6960E void NuclearWaffle_Func_1(void) { // 0xA69615 Enemy_NuclearWaffle *E = Get_NuclearWaffle(cur_enemy_index); - if ((--E->nwe_var_B & 0x8000u) != 0) { + if ((--E->nwe_var_B & 0x8000) != 0) { E->nwe_var_B = E->nwe_var_F; E->nwe_var_21 = E->nwe_var_23; E->nwe_var_A = FUNC16(NuclearWaffle_Func_2); @@ -832,117 +811,95 @@ void NuclearWaffle_Func_1(void) { // 0xA69615 void NuclearWaffle_Func_2(void) { // 0xA69682 Enemy_NuclearWaffle *E = Get_NuclearWaffle(cur_enemy_index); - draw_enemy_layer = E->nwe_var_D; - R30_ = NuclearWaffle_Func_6(E->nwe_var_21); - uint16 v8 = R30_; - if (R30_ != E->nwe_var_33) { - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - R22_ = 46; - R24_ = E->nwe_var_34; - CreateSpriteAtPos(); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - R22_ = R26_ + 44; - R24_ = E->nwe_var_34; - CreateSpriteAtPos(); - NuclearWaffle_Func_7(); + uint16 varE32 = E->nwe_var_D; + PairU16 pair = NuclearWaffle_Func_6(E->nwe_var_21); + uint16 v8 = pair.j; + if (pair.j != E->nwe_var_33) { + CreateSpriteAtPos(E->base.x_pos, E->base.y_pos, 46, E->nwe_var_34); + CreateSpriteAtPos(E->base.x_pos, E->base.y_pos, pair.k + 44, E->nwe_var_34); + NuclearWaffle_Func_7(pair.j); } E->nwe_var_33 = v8; - uint16 v4 = NuclearWaffle_Func_5(E->nwe_var_21); - E->base.x_pos = E->nwe_var_26 + CosineMult8bit(v4); - uint16 v5 = NuclearWaffle_Func_5(E->nwe_var_21); - E->base.y_pos = E->nwe_var_27 + SineMult8bitNegative(v5); - NuclearWaffle_Func_3(); - NuclearWaffle_Func_4(); + uint16 tmp; + uint16 v4 = NuclearWaffle_Func_5(E->nwe_var_21, &tmp); + E->base.x_pos = E->nwe_var_26 + CosineMult8bit(v4, E->nwe_var_D); + uint16 v5 = NuclearWaffle_Func_5(E->nwe_var_21, &tmp); + E->base.y_pos = E->nwe_var_27 + SineMult8bit(v5, E->nwe_var_D); + NuclearWaffle_Func_3(varE32); + NuclearWaffle_Func_4(varE32); uint16 nwe_var_20 = E->nwe_var_20; bool v7 = __CFADD__uint16(E->nwe_var_24, nwe_var_20); E->nwe_var_20 = E->nwe_var_24 + nwe_var_20; E->nwe_var_21 += E->nwe_var_25 + v7; } -void NuclearWaffle_Func_3(void) { // 0xA69721 +void NuclearWaffle_Func_3(uint16 varE32) { // 0xA69721 Enemy_NuclearWaffle *E = Get_NuclearWaffle(cur_enemy_index); uint16 v12; E->nwe_var_2A = 8; - R36 = E->nwe_var_2C + E->nwe_var_21; + uint16 R36 = E->nwe_var_2C + E->nwe_var_21; + uint16 r28; do { R36 -= E->nwe_var_2B; Enemy_NuclearWaffle *ET = Get_NuclearWaffle(cur_enemy_index + E->nwe_var_2A); uint16 nwe_var_00 = ET->nwe_var_00; - R30_ = NuclearWaffle_Func_6(R36); - uint16 v13 = R30_; - if (R30_ != ET->nwe_var_08) { + PairU16 pair = NuclearWaffle_Func_6(R36); + uint16 v13 = pair.j; + if (pair.j != ET->nwe_var_08) { int v5 = nwe_var_00 >> 1; - R18_ = enemy_projectile_x_pos[v5]; - R20_ = enemy_projectile_y_pos[v5]; - R22_ = 46; - R24_ = E->nwe_var_34; - CreateSpriteAtPos(); - R18_ = enemy_projectile_x_pos[v5]; - R20_ = enemy_projectile_y_pos[v5]; - R22_ = R26_ + 44; - R24_ = E->nwe_var_34; - CreateSpriteAtPos(); - NuclearWaffle_Func_7(); + CreateSpriteAtPos(enemy_projectile_x_pos[v5], enemy_projectile_y_pos[v5], 46, E->nwe_var_34); + CreateSpriteAtPos(enemy_projectile_x_pos[v5], enemy_projectile_y_pos[v5], pair.k + 44, E->nwe_var_34); + NuclearWaffle_Func_7(pair.j); } ET->nwe_var_08 = v13; - uint16 v7 = NuclearWaffle_Func_5(R36); - uint16 v8 = CosineMult8bit(v7); + uint16 v7 = NuclearWaffle_Func_5(R36, &r28); int v10 = nwe_var_00 >> 1; - enemy_projectile_x_pos[v10] = E->nwe_var_26 + v8; - uint16 v11 = NuclearWaffle_Func_5(R36); - enemy_projectile_y_pos[v10] = E->nwe_var_27 + SineMult8bitNegative(v11); + enemy_projectile_x_pos[v10] = E->nwe_var_26 + CosineMult8bit(v7, varE32); + uint16 v11 = NuclearWaffle_Func_5(R36, &r28); + enemy_projectile_y_pos[v10] = E->nwe_var_27 + SineMult8bit(v11, varE32); v12 = E->nwe_var_2A - 2; E->nwe_var_2A = v12; } while (v12); - if (R28_) { + if (r28) { E->nwe_var_A = FUNC16(NuclearWaffle_Func_1); E->base.properties &= ~kEnemyProps_ProcessedOffscreen; } } -void NuclearWaffle_Func_4(void) { // 0xA697E9 +void NuclearWaffle_Func_4(uint16 varE32) { // 0xA697E9 Enemy_NuclearWaffle *E = Get_NuclearWaffle(cur_enemy_index); E->nwe_var_2A = 6; - R36 = E->nwe_var_21; + uint16 R36 = E->nwe_var_21; uint16 v12; + uint16 r28 = 0; do { R36 -= E->nwe_var_2B; Enemy_NuclearWaffle *ET = Get_NuclearWaffle(cur_enemy_index + E->nwe_var_2A); uint16 nwe_var_10 = ET->nwe_var_10; - R30_ = NuclearWaffle_Func_6(R36); - uint16 v13 = R30_; - if (R30_ != ET->nwe_var_18) { - R38 = E->nwe_var_34; + PairU16 pair = NuclearWaffle_Func_6(R36); + uint16 v13 = pair.j; + if (pair.j != ET->nwe_var_18) { + uint16 r38 = E->nwe_var_34; int v5 = nwe_var_10 >> 1; - R18_ = sprite_x_pos[v5]; - R20_ = sprite_y_pos[v5]; - R22_ = 46; - R24_ = R38; - CreateSpriteAtPos(); - R18_ = sprite_x_pos[v5]; - R20_ = sprite_y_pos[v5]; - R22_ = R26_ + 44; - R24_ = R38; - CreateSpriteAtPos(); - NuclearWaffle_Func_7(); + CreateSpriteAtPos(sprite_x_pos[v5], sprite_y_pos[v5], 46, r38); + CreateSpriteAtPos(sprite_x_pos[v5], sprite_y_pos[v5], pair.k + 44, r38); + NuclearWaffle_Func_7(pair.j); } ET->nwe_var_18 = v13; - uint16 v6 = NuclearWaffle_Func_5(R36); - uint16 v7 = CosineMult8bit(v6); - R32_ = E->nwe_var_26 + v7; - uint16 v9 = NuclearWaffle_Func_5(R36); - R34 = E->nwe_var_27 + SineMult8bitNegative(v9); - sprite_x_pos[nwe_var_10 >> 1] = R32_; + uint16 v6 = NuclearWaffle_Func_5(R36, &r28); + uint16 v7 = CosineMult8bit(v6, varE32); + uint16 R32 = E->nwe_var_26 + v7; + uint16 v9 = NuclearWaffle_Func_5(R36, &r28); + uint16 R34 = E->nwe_var_27 + SineMult8bit(v9, varE32); + sprite_x_pos[nwe_var_10 >> 1] = R32; sprite_y_pos[nwe_var_10 >> 1] = R34; v12 = E->nwe_var_2A - 2; E->nwe_var_2A = v12; } while (v12); } -uint16 NuclearWaffle_Func_5(uint16 a) { // 0xA698AD - R28_ = 0; +uint16 NuclearWaffle_Func_5(uint16 a, uint16 *r28_out) { // 0xA698AD + *r28_out = 0; Enemy_NuclearWaffle *E = Get_NuclearWaffle(cur_enemy_index); if (!E->nwe_var_E) { if ((int16)(a - E->nwe_var_2E) >= 0) { @@ -951,7 +908,7 @@ uint16 NuclearWaffle_Func_5(uint16 a) { // 0xA698AD return E->nwe_var_23; } LABEL_8: - ++R28_; + ++(*r28_out); return E->nwe_var_2E; } if ((int16)(a - E->nwe_var_2E) >= 0) @@ -961,32 +918,28 @@ LABEL_8: return a; } -uint16 NuclearWaffle_Func_6(uint16 a) { // 0xA698E7 +static PairU16 NuclearWaffle_Func_6(uint16 a) { // 0xA698E7 Enemy_NuclearWaffle *E = Get_NuclearWaffle(cur_enemy_index); if (E->nwe_var_E) { if ((int16)(a - E->nwe_var_2F) >= 0) { - R26_ = 1; - return 2; + return (PairU16) { 1, 2 }; } else if ((int16)(a - E->nwe_var_30) >= 0) { - R26_ = 0; - return 1; + return (PairU16) { 0, 1 }; } else { - return 0; + return (PairU16) { 0, 0 }; } } else if ((int16)(a - E->nwe_var_2F) < 0) { - R26_ = 0; - return 2; + return (PairU16) { 0, 2 }; } else if ((int16)(a - E->nwe_var_30) < 0) { - R26_ = 1; - return 1; + return (PairU16) { 1, 1 }; } else { - return 0; + return (PairU16) { 0, 0 }; } } -void NuclearWaffle_Func_7(void) { // 0xA6993F - if (R30_ != 2) - QueueSfx2_Max6(0x5Eu); +void NuclearWaffle_Func_7(uint16 r30) { // 0xA6993F + if (r30 != 2) + QueueSfx2_Max6(0x5E); } void FakeKraid_Init(void) { // 0xA69A58 @@ -1025,7 +978,6 @@ void FakeKraid_Main(void) { // 0xA69AC2 } void FakeKraid_Func_1(uint16 k, uint16 j) { // 0xA69ADC - R18_ = k; Enemy_FakeKraid *ET = Get_FakeKraid(k + j); uint16 fkd_var_03 = ET->fkd_var_03; if (fkd_var_03) { @@ -1038,9 +990,9 @@ void FakeKraid_Func_1(uint16 k, uint16 j) { // 0xA69ADC int16 fkd_var_C = E->fkd_var_C; if (fkd_var_C >= 0) v6 = addr_kEproj_MiniKraidSpikesRight; - SpawnEnemyProjectileWithGfx(fkd_var_C, k, v6); + SpawnEnemyProjectileWithGfx(0, k, v6); if (!CheckIfEnemyIsOnScreen()) - QueueSfx2_Max6(0x3Fu); + QueueSfx2_Max6(0x3F); } } @@ -1051,9 +1003,7 @@ const uint16 *FakeKraid_Instr_2(uint16 k, const uint16 *jp) { // 0xA69B26 if (E->fkd_var_D-- == 1) { E->fkd_var_D = (random_number & 3) + 7; } else { - R20_ = E->fkd_var_B; - R18_ = 0; - if (!(Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1)) + if (!(Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(E->fkd_var_B)))) goto LABEL_7; } E->fkd_var_B = -E->fkd_var_B; @@ -1067,18 +1017,18 @@ LABEL_7: const uint16 *FakeKraid_Instr_1(uint16 k, const uint16 *jp) { // 0xA69B74 Enemy_FakeKraid *E = Get_FakeKraid(cur_enemy_index); if (E->fkd_var_E) { - if ((E->fkd_var_C & 0x8000u) != 0) { - if ((Get_FakeKraid(cur_enemy_index)->fkd_var_B & 0x8000u) == 0) + if ((E->fkd_var_C & 0x8000) != 0) { + if ((Get_FakeKraid(cur_enemy_index)->fkd_var_B & 0x8000) == 0) return INSTR_RETURN_ADDR(addr_stru_A699C6); return INSTR_RETURN_ADDR(addr_stru_A699AE); } else { - if ((E->fkd_var_B & 0x8000u) != 0) + if ((E->fkd_var_B & 0x8000) != 0) return INSTR_RETURN_ADDR(addr_stru_A69A14); return INSTR_RETURN_ADDR(addr_stru_A699FC); } } else { E->fkd_var_E = (random_number & 3) + 3; - if ((E->fkd_var_C & 0x8000u) != 0) + if ((E->fkd_var_C & 0x8000) != 0) return INSTR_RETURN_ADDR(addr_kFakeKraid_Ilist_99DC); return INSTR_RETURN_ADDR(addr_kFakeKraid_Ilist_9A2A); } @@ -1086,7 +1036,7 @@ const uint16 *FakeKraid_Instr_1(uint16 k, const uint16 *jp) { // 0xA69B74 const uint16 *FakeKraid_Instr_3(uint16 k, const uint16 *jp) { // 0xA69BB2 if (CheckIfEnemyIsOnScreen() == 0) - QueueSfx2_Max6(0x16u); + QueueSfx2_Max6(0x16); return jp; } @@ -1111,7 +1061,7 @@ void FakeKraid_InstrHelper_45(uint16 k, uint16 j, uint16 a) { // 0xA69BCB } const uint16 *FakeKraid_Instr_5(uint16 k, const uint16 *jp) { // 0xA69C02 - FakeKraid_InstrHelper_45(k, 8u, 4u); + FakeKraid_InstrHelper_45(k, 8, 4); return jp; } @@ -1141,7 +1091,7 @@ void FakeKraid_Shot(void) { // 0xA69C39 void FakeKraid_9C50(void) { // 0xA69C50 if (!Get_FakeKraid(cur_enemy_index)->base.health) { - EnemyDeathAnimation(cur_enemy_index, 3u); + EnemyDeathAnimation(cur_enemy_index, 3); Enemy_ItemDrop_MiniKraid(cur_enemy_index); } } @@ -1162,7 +1112,7 @@ void CeresRidley_Init(void) { // 0xA6A0F5 Ridley_Func_99(addr_kRidley_Ilist_E538); E->base.palette_index = 3584; E->cry_var_0C = 3584; - E->base.extra_properties |= 4u; + E->base.extra_properties |= 4; E->cry_var_01 = 0; E->cry_var_0D = 0; earthquake_type = 0; @@ -1316,7 +1266,7 @@ void CeresRidley_Main(void) { // 0xA6A288 } void CeresRidley_Func_1(void) { // 0xA6A2BD - if (random_number >= 0xFF00u) + if (random_number >= 0xFF00) tilemap_stuff[15] = (random_number & 0xF) + 8; } @@ -1339,15 +1289,12 @@ void Ridley_A2DC(void) { // 0xA6A2DC void Ridley_A2F2(void) { // 0xA6A2F2 if (!ceres_status) DrawBabyMetroid_0(); - Enemy_CeresRidley *E = Get_CeresRidley(0x40u); + Enemy_CeresRidley *E = Get_CeresRidley(0x40); if (E->cry_var_B) { // bug static const int16 g_word_A6A321[4] = { 0, -1024, -4, -1 }; - - R20_ = E->base.x_pos + g_word_A6A321[(uint8)(earthquake_timer & 3)]; - R18_ = E->base.y_pos; - R22_ = 1024; - DrawSpritemap(0xA6, addr_kCeresRidley_Sprmap_A329); + DrawSpritemap(0xA6, addr_kCeresRidley_Sprmap_A329, + E->base.x_pos + g_word_A6A321[earthquake_timer & 3], E->base.y_pos, 1024); } } @@ -1374,7 +1321,7 @@ void CeresRidley_Func_3(void) { // 0xA6A35B void CeresRidley_A377(void) { // 0xA6A377 Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((--E->cry_var_F & 0x8000u) != 0) { + if ((--E->cry_var_F & 0x8000) != 0) { E->cry_var_A = FUNC16(CeresRidley_Func_4); E->cry_var_E = 0; E->cry_var_F = 0; @@ -1385,7 +1332,7 @@ void CeresRidley_Func_4(void) { // 0xA6A389 int16 v2; Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((E->cry_var_E & 0x8000u) == 0) { + if ((E->cry_var_E & 0x8000) == 0) { uint16 cry_var_E = E->cry_var_E; if (++E->cry_var_F) { E->cry_var_F = 0; @@ -1395,7 +1342,6 @@ void CeresRidley_Func_4(void) { // 0xA6A389 E->cry_var_A = FUNC16(CeresRidley_Func_5); E->cry_var_02 = 1; } else { - R18_ = g_byte_A6E269[cry_var_E]; E->cry_var_E = cry_var_E + 1; int v3 = (uint16)(6 * v2) >> 1; palette_buffer[252] = g_word_A6E2AA[v3]; @@ -1411,32 +1357,29 @@ void CeresRidley_Func_5(void) { // 0xA6A3DF int16 v5; Enemy_CeresRidley *E = Get_CeresRidley(0); - if (++E->cry_var_F >= 2u) { + if (++E->cry_var_F >= 2) { E->cry_var_F = 0; uint16 cry_var_E = E->cry_var_E; - R18_ = 290; - R20_ = 482; + uint16 r18 = 290, r20 = 482; v2 = 11; do { v5 = v2; uint16 v3 = g_word_A6E30A[cry_var_E >> 1]; - palette_buffer[R18_ >> 1] = v3; - palette_buffer[R20_ >> 1] = v3; + palette_buffer[r18 >> 1] = v3; + palette_buffer[r20 >> 1] = v3; cry_var_E += 2; - ++R18_; - ++R18_; - ++R20_; - ++R20_; + r18 += 2; + r20 += 2; v2 = v5 - 1; } while (v5 != 1); - if (cry_var_E >= 0x160u) { + if (cry_var_E >= 0x160) { if (area_index == 2) E->base.layer = 2; E->base.properties &= ~kEnemyProps_Tangible; E->cry_var_E = 0; E->cry_var_A = FUNC16(CeresRidley_Func_6); E->cry_var_F = 4; - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); } else { E->cry_var_E = cry_var_E; } @@ -1445,7 +1388,7 @@ void CeresRidley_Func_5(void) { // 0xA6A3DF void CeresRidley_Func_6(void) { // 0xA6A455 Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((--E->cry_var_F & 0x8000u) != 0) { + if ((--E->cry_var_F & 0x8000) != 0) { Ridley_Func_99(addr_kRidley_Ilist_E690); E->cry_var_F = 0; E->cry_var_A = FUNC16(CeresRidley_Func_7); @@ -1458,7 +1401,7 @@ void CeresRidley_Func_7(void) { // 0xA6A478 Enemy_CeresRidley *E = Get_CeresRidley(0); if (area_index == 2) { - bool v1 = (--E->cry_var_F & 0x8000u) != 0; + bool v1 = (--E->cry_var_F & 0x8000) != 0; if (!v1) return; E->cry_var_F = 2; @@ -1470,7 +1413,7 @@ void CeresRidley_Func_7(void) { // 0xA6A478 fx_y_vel = -96; fx_timer = 32; } else { - bool v1 = (--E->cry_var_F & 0x8000u) != 0; + bool v1 = (--E->cry_var_F & 0x8000) != 0; if (!v1) return; } @@ -1513,7 +1456,7 @@ void CeresRidley_Func_11(void) { // 0xA6A6E8 uint16 v1; Enemy_CeresRidley *E = Get_CeresRidley(0); - if (E->cry_var_0D >= 0x64u) { + if (E->cry_var_0D >= 0x64) { E->cry_var_01 = 0; E->cry_var_A = FUNC16(Ridley_Func_44); Ridley_Func_44(); @@ -1522,19 +1465,16 @@ void CeresRidley_Func_11(void) { // 0xA6A6E8 E->cry_var_A = FUNC16(CeresRidley_Func_22); CeresRidley_Func_22(); } else if (!(CeresRidley_Func_12() & 1) - || (v1 = E->cry_var_00 + 1, E->cry_var_00 = v1, v1 >= 0x7Cu)) { + || (v1 = E->cry_var_00 + 1, E->cry_var_00 = v1, v1 >= 0x7C)) { E->cry_var_A = g_off_A6A743[random_number & 0xF]; E->cry_var_00 = 0; } } uint8 CeresRidley_Func_12(void) { // 0xA6A763 - R18_ = 192; - R20_ = 100; - Ridley_Func_106(0, 0); - R22_ = 8; - R24_ = 8; - return Shitroid_Func_2(0) & 1; + Rect16U rect = { 192, 100, 8, 8 }; + Ridley_Func_106(0, 0, rect.x, rect.y); + return Shitroid_Func_2(0, rect); } void CeresRidley_Func_13(void) { // 0xA6A782 @@ -1543,13 +1483,11 @@ void CeresRidley_Func_13(void) { // 0xA6A782 if (v1 < 0x80) v1 = 128; E->cry_var_C = sign16(E->cry_var_C) ? -v1 : v1; - R18_ = E->base.x_pos; - R20_ = 88; - Ridley_Func_106(0, 0); + Ridley_Func_106(0, 0, E->base.x_pos, 88); if (sign16(E->base.y_pos - 80)) { uint16 v3 = E->cry_var_00 + 1; E->cry_var_00 = v3; - if (v3 >= 0x30u) + if (v3 >= 0x30) E->cry_var_A = FUNC16(CeresRidley_Func_16); } else if (sign16(E->base.y_pos - 128)) { E->cry_var_17 = E->base.x_pos; @@ -1562,19 +1500,12 @@ void CeresRidley_Func_13(void) { // 0xA6A782 } void CeresRidley_A7F9(void) { // 0xA6A7F9 - unsigned int v3; // kr00_4 - int16 v4; - - R22_ = sign16(random_number) ? -(random_number & 7) : (random_number & 7); + uint16 r22 = sign16(random_number) ? -(random_number & 7) : (random_number & 7); Enemy_CeresRidley *E = Get_CeresRidley(0); - uint16 cry_var_17 = E->cry_var_17; - R18_ = R22_ + cry_var_17; - v3 = __PAIR32__(R22_, R22_) + __PAIR32__(E->cry_var_18, cry_var_17); - uint16 v2 = (__PAIR32__(R22_, R22_) + __PAIR32__(E->cry_var_18, cry_var_17)) >> 16; - R18_ = v3; - R20_ = v2; - Ridley_Func_106(0, 0); - v4 = E->cry_var_00 - 1; + uint16 r18 = E->cry_var_17 + r22; + uint16 r20 = E->cry_var_18 + r22; + Ridley_Func_106(0, 0, r18, r20); + int16 v4 = E->cry_var_00 - 1; E->cry_var_00 = v4; if (v4 < 0) { E->cry_var_00 = 0; @@ -1594,15 +1525,14 @@ void CeresRidley_Func_15(void) { // 0xA6A84E bool v2; // sf Enemy_CeresRidley *E = Get_CeresRidley(0); - R18_ = samus_x_pos; + uint16 r18 = samus_x_pos; uint16 v0 = samus_y_pos - 68; if (sign16(samus_y_pos - 132)) v0 = 64; - R20_ = v0; - Ridley_Func_106(0, 0xD); - R22_ = 2; - R24_ = 2; - if (!(Shitroid_Func_2(0) & 1) + uint16 r20 = v0; + Ridley_Func_106(0, 0xD, r18, r20); + Rect16U rect = { r18, r20, 2, 2 }; + if (!Shitroid_Func_2(0, rect) || (v2 = (int16)(E->cry_var_F - 1) < 0, --E->cry_var_F, v2)) { E->cry_var_00 = 0; E->cry_var_A = FUNC16(CeresRidley_Func_11); @@ -1619,9 +1549,7 @@ void CeresRidley_Func_16(void) { // 0xA6A88D } void CeresRidley_Func_17(void) { // 0xA6A8A4 - R18_ = 192; - R20_ = 80; - Ridley_Func_106(0, 1u); + Ridley_Func_106(0, 1, 192, 80); Enemy_CeresRidley *E = Get_CeresRidley(0); if (sign16(E->base.y_pos - 96)) { E->cry_var_A = FUNC16(CeresRidley_Func_18); @@ -1631,24 +1559,18 @@ void CeresRidley_Func_17(void) { // 0xA6A8A4 } void CeresRidley_Func_18(void) { // 0xA6A8D4 - R18_ = -32; - R20_ = -1024; - R22_ = 768; - Ridley_Func_111(); + Ridley_Func_111(-32, -1024, 768); Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((--E->cry_var_F & 0x8000u) != 0) { + if ((--E->cry_var_F & 0x8000) != 0) { E->cry_var_A = FUNC16(CeresRidley_Func_19); E->cry_var_F = 36; } } void CeresRidley_Func_19(void) { // 0xA6A8F8 - R18_ = -512; - R20_ = -16384; - R22_ = 768; - Ridley_Func_111(); + Ridley_Func_111(-512, -16384, 768); Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((--E->cry_var_F & 0x8000u) != 0) { + if ((--E->cry_var_F & 0x8000) != 0) { E->cry_var_A = FUNC16(CeresRidley_Func_20); E->cry_var_F = 28; tilemap_stuff[2] = 1; @@ -1656,24 +1578,18 @@ void CeresRidley_Func_19(void) { // 0xA6A8F8 } void CeresRidley_Func_20(void) { // 0xA6A923 - R18_ = -512; - R20_ = -30720; - R22_ = 768; - Ridley_Func_111(); + Ridley_Func_111(-512, -30720, 768); Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((--E->cry_var_F & 0x8000u) != 0) { + if ((--E->cry_var_F & 0x8000) != 0) { E->cry_var_A = FUNC16(CeresRidley_Func_21); E->cry_var_F = 1; } } void CeresRidley_Func_21(void) { // 0xA6A947 - R18_ = -768; - R20_ = -30720; - R22_ = 768; - Ridley_Func_111(); + Ridley_Func_111(-768, -30720, 768); Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((--E->cry_var_F & 0x8000u) != 0) { + if ((--E->cry_var_F & 0x8000) != 0) { E->cry_var_A = FUNC16(CeresRidley_Func_11); E->cry_var_00 = 0; tilemap_stuff[1] = 1; @@ -1683,9 +1599,7 @@ void CeresRidley_Func_21(void) { // 0xA6A947 void CeresRidley_Func_22(void) { // 0xA6A971 Enemy_CeresRidley *E = Get_CeresRidley(0); E->cry_var_20 = -192; - R18_ = 192; - R20_ = -128; - Ridley_Func_106(0, 1u); + Ridley_Func_106(0, 1, 192, -128); if (sign16(E->base.y_pos + 128)) CeresRidley_A994(); } @@ -1699,15 +1613,15 @@ void CeresRidley_A994(void) { // 0xA6A994 void CeresRidley_Func_23(void) { // 0xA6A9A0 Enemy_CeresRidley *E = Get_CeresRidley(0); - if ((--E->cry_var_F & 0x8000u) != 0) { + if ((--E->cry_var_F & 0x8000) != 0) { CeresRidley_Func_25(); E->cry_var_B = 0; E->cry_var_C = 0; tilemap_stuff[0] = 0; E->cry_var_A = FUNC16(CeresRidley_Func_24); WriteColorsToPalette(0xA2, 0xa6, addr_word_A6A9E3, 0xF); - WriteColorsToPalette(0x42, 0xa6, addr_word_A6AA01, 8u); - WriteColorsToPalette(0x1E2, 0xa6, addr_word_A6AA01, 8u); + WriteColorsToPalette(0x42, 0xa6, addr_word_A6AA01, 8); + WriteColorsToPalette(0x1E2, 0xa6, addr_word_A6AA01, 8); } } @@ -1758,7 +1672,7 @@ void CeresRidley_Func_28(void) { // 0xA6AABD uint16 cry_var_33 = E->cry_var_33; E->cry_var_33 = cry_var_33 + 2; if (!cry_var_33) - QueueSfx2_Max6(0x4Eu); + QueueSfx2_Max6(0x4E); if (cry_var_33 == 208) { Samus_SetPushedOutOfCeresRidley(); earthquake_type = 35; @@ -1795,75 +1709,28 @@ void CeresRidley_Func_28(void) { // 0xA6AABD } } -uint16 MaybeNegate(uint16 cond, uint16 value) { - return cond & 0x8000 ? -value : value; +static uint16 CeresMult(uint16 a, uint16 b) { + uint16 r = abs16(a) * b >> 8; + return sign16(a) ? -r : r; } void CeresRidley_Func_29(void) { // 0xA6AB5F Enemy_CeresRidley *E = Get_CeresRidley(0); - R18_ = HIBYTE(E->cry_var_0A); - R24_ = CeresRidley_Func_31(0x100u); - R38 = abs16(R24_); - R40 = E->cry_var_30; - CeresRidley_Func_32(); - reg_M7A = MaybeNegate(R24_, *(uint16 *)((uint8 *)&R42 + 1)); - - R24_ = CeresRidley_Func_30(0x100u); - R38 = abs16(R24_); - R40 = E->cry_var_30; - CeresRidley_Func_32(); - reg_M7B = MaybeNegate(R24_, *(uint16 *)((uint8 *)&R42 + 1)); - - R24_ = -CeresRidley_Func_30(0x100u); - R38 = abs16(R24_); - R40 = E->cry_var_30; - CeresRidley_Func_32(); - reg_M7C = MaybeNegate(R24_, *(uint16 *)((uint8 *)&R42 + 1)); - - R24_ = CeresRidley_Func_31(0x100u); - R38 = abs16(R24_); - R40 = E->cry_var_30; - CeresRidley_Func_32(); - reg_M7D = MaybeNegate(R24_, *(uint16 *)((uint8 *)&R42 + 1)); + uint16 r18 = HIBYTE(E->cry_var_0A); + reg_M7A = CeresMult(CeresRidley_AC30(r18 + 64, 0x100), E->cry_var_30); + reg_M7B = CeresMult(CeresRidley_AC30(r18, 0x100), E->cry_var_30); + reg_M7C = CeresMult(-CeresRidley_AC30(r18, 0x100), E->cry_var_30); + reg_M7D = CeresMult(CeresRidley_AC30(r18 + 64, 0x100), E->cry_var_30); } -uint16 CeresRidley_Func_30(uint16 a) { // 0xA6AC0E - R20_ = a; - R38 = abs16(a); - return CeresRidley_AC30(R18_); -} - -uint16 CeresRidley_Func_31(uint16 a) { // 0xA6AC1E - R20_ = a; - R38 = abs16(a); - return CeresRidley_AC30(R18_ + 64); -} - -uint16 CeresRidley_AC30(uint16 a) { // 0xA6AC30 - int v1 = (uint16)((2 * a) & 0x1FE) >> 1; - uint16 result = kSinCosTable8bit_Sext[v1 + 64]; - if (result) { - R22_ = kSinCosTable8bit_Sext[v1 + 64]; - R40 = abs16(result); - CeresRidley_Func_32(); - if (((R22_ ^ R20_) & 0x8000u) != 0) - return -*(uint16 *)((uint8 *)&R42 + 1); - else - return *(uint16 *)((uint8 *)&R42 + 1); - } - return result; -} - -void CeresRidley_Func_32(void) { // 0xA6AC58 - uint32 t = (uint32)R38 * (uint32)R40; - R42 = (uint16)t; - R44 = (uint16)(t >> 16); +int16 CeresRidley_AC30(uint16 a, int16 r20) { // 0xA6AC30 + return (int16)kSinCosTable8bit_Sext[(a & 0xff) + 64] * r20 >> 8; } void CeresRidley_Func_33(void) { // 0xA6ACBC if ((nmi_frame_counter_word & 3) == 0) { Enemy_CeresRidley *E = Get_CeresRidley(0); - uint16 v1 = ((uint8)E->cry_var_36 + 1) & 3; + uint16 v1 = (E->cry_var_36 + 1) & 3; E->cry_var_36 = v1; QueueMode7Transfers(0xA6, g_off_A6ACDA[v1]); } @@ -1872,7 +1739,7 @@ void CeresRidley_Func_33(void) { // 0xA6ACBC void CeresRidley_Func_34(void) { // 0xA6AD27 if ((nmi_frame_counter_word & 7) == 0) { Enemy_CeresRidley *E = Get_CeresRidley(0); - uint16 v1 = ((uint8)E->cry_var_37 + 1) & 1; + uint16 v1 = (E->cry_var_37 + 1) & 1; E->cry_var_37 = v1; QueueMode7Transfers(0xA6, g_off_A6AD45[v1]); } @@ -1911,7 +1778,7 @@ void Ridley_Main(void) { // 0xA6B227 void Ridley_Func_1(void) { // 0xA6B26F Enemy_Ridley *E = Get_Ridley(0); if (!(E->ridley_var_1B | E->ridley_var_1E)) { - if (Ridley_Func_26(4u, 4u) & 1) + if (Ridley_Func_26(4, 4) & 1) Ridley_Func_37(); } } @@ -1954,12 +1821,9 @@ LABEL_7: } void Ridley_Func_3(void) { // 0xA6B2F3 - R18_ = 64; - R20_ = 256; - Ridley_Func_104_0(0, 14); - R22_ = 8; - R24_ = 8; - if (!(Shitroid_Func_2(0) & 1)) { + Rect16U rect = { 64, 256, 8, 8 }; + Ridley_Func_104_0(0, 14, rect.x, rect.y); + if (!Shitroid_Func_2(0, rect)) { Enemy_Ridley *E = Get_Ridley(0); E->ridley_var_01 = 1; E->ridley_var_A = FUNC16(Ridley_Func_3b); @@ -1968,38 +1832,37 @@ void Ridley_Func_3(void) { // 0xA6B2F3 } void Ridley_Func_3b(void) { // 0xA6B321 - Ridley_Func_4(); - int v0 = (uint16)(2 * (NextRandom() & 7)); - uint16 v1 = *(uint16 *)&RomPtr_A6(R18_)[v0]; + uint16 r18 = Ridley_Func_4(); + int v0 = 2 * (NextRandom() & 7); + uint16 v1 = *(uint16 *)&RomPtr_A6(r18)[v0]; Enemy_Ridley *E = Get_Ridley(0); E->ridley_var_A = v1; CallRidleyFunc(E->ridley_var_A | 0xA60000); } -void Ridley_Func_4(void) { // 0xA6B335 +uint16 Ridley_Func_4(void) { // 0xA6B335 + uint16 r18; if (samus_movement_type == 3) { - R18_ = addr_off_A6B3CC; + r18 = addr_off_A6B3CC; } else { Enemy_Ridley *E = Get_Ridley(0); uint16 health = E->base.health; if (health) { if (sign16(health - 14400)) { - R18_ = addr_off_A6B38C; + r18 = addr_off_A6B38C; } else if (Ridley_Func_41() & 1) { - R18_ = addr_off_A6B3BC; + r18 = addr_off_A6B3BC; } else if ((Ridley_Func_40_Carry() & 1) != 0) { - R18_ = addr_off_A6B3AC; + r18 = addr_off_A6B3AC; } else { - uint16 v2 = addr_off_A6B38C; - if (sign16(E->base.health - 9000)) - v2 = addr_off_A6B39C; - R18_ = v2; + r18 = sign16(E->base.health - 9000) ? addr_off_A6B39C : addr_off_A6B38C; } } else { - R18_ = addr_off_A6B3DC; + r18 = addr_off_A6B3DC; ++E->ridley_var_25; } } + return r18; } void Ridley_Func_5(void) { // 0xA6B3EC @@ -2011,22 +1874,18 @@ void Ridley_Func_5(void) { // 0xA6B3EC void Ridley_Func_6(void) { // 0xA6B3F8 Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) + if ((--E->ridley_var_F & 0x8000) != 0) goto LABEL_5; uint16 v2; v2 = 192; if (E->ridley_var_10) v2 = 96; - R18_ = v2; - R20_ = 256; - uint16 v3; - v3 = Ridley_Func_7(); - Ridley_Func_104_0(0, v3); - R22_ = 8; - R24_ = 8; - if (!(Shitroid_Func_2(0) & 1)) - LABEL_5: - E->ridley_var_A = FUNC16(Ridley_Func_3b); + Rect16U rect = { v2, 256, 8, 8 }; + Ridley_Func_104_0(0, Ridley_Func_7(), rect.x, rect.y); + if (!Shitroid_Func_2(0, rect)) { +LABEL_5: + E->ridley_var_A = FUNC16(Ridley_Func_3b); + } } uint16 Ridley_Func_7(void) { // 0xA6B42E @@ -2047,12 +1906,9 @@ void Ridley_B455(void) { // 0xA6B455 uint16 v1 = 192; if (E->ridley_var_10) v1 = 64; - R18_ = v1; - R20_ = 128; - Ridley_Func_104_0(0, 1u); - R22_ = 8; - R24_ = 8; - if (!(Shitroid_Func_2(0) & 1)) { + Rect16U rect = { v1, 128, 8, 8 }; + Ridley_Func_104_0(0, 1, rect.x, rect.y); + if (!Shitroid_Func_2(0, rect)) { E->ridley_var_A = FUNC16(Ridley_Func_9); E->ridley_var_00 = 32; E->ridley_var_0A = 0; @@ -2062,14 +1918,10 @@ void Ridley_B455(void) { // 0xA6B455 void Ridley_Func_9(void) { // 0xA6B493 Enemy_Ridley *E = Get_Ridley(0); if (E->ridley_var_10) { - R18_ = 32; - R20_ = 512; + Ridley_Func_111(32, 512, 1152); } else { - R18_ = -32; - R20_ = -512; + Ridley_Func_111(-32, -512, 1152); } - R22_ = 1152; - Ridley_Func_111(); uint16 ridley_var_00 = E->ridley_var_00; if (ridley_var_00) { E->ridley_var_00 = ridley_var_00 - 1; @@ -2081,15 +1933,10 @@ void Ridley_Func_9(void) { // 0xA6B493 void Ridley_Func_10(void) { // 0xA6B4D1 Enemy_Ridley *E = Get_Ridley(0); - if (E->ridley_var_10) { - R18_ = 320; - R20_ = 0x4000; - } else { - R18_ = -320; - R20_ = -16384; - } - R22_ = 1280; - Ridley_Func_111(); + if (E->ridley_var_10) + Ridley_Func_111(320, 0x4000, 1280); + else + Ridley_Func_111(-320, -16384, 1280); uint16 ridley_var_00 = E->ridley_var_00; if (ridley_var_00) { E->ridley_var_00 = ridley_var_00 - 1; @@ -2102,15 +1949,10 @@ void Ridley_Func_10(void) { // 0xA6B4D1 void Ridley_Func_11(void) { // 0xA6B516 Enemy_Ridley *E = Get_Ridley(0); - if (E->ridley_var_10) { - R18_ = 512; - R20_ = 30720; - } else { - R18_ = -512; - R20_ = -30720; - } - R22_ = 768; - Ridley_Func_111(); + if (E->ridley_var_10) + Ridley_Func_111(512, 30720, 768); + else + Ridley_Func_111(-512, -30720, 768); uint16 ridley_var_00 = E->ridley_var_00; if (ridley_var_00) { E->ridley_var_00 = ridley_var_00 - 1; @@ -2123,14 +1965,10 @@ void Ridley_Func_11(void) { // 0xA6B516 void Ridley_Func_12(void) { // 0xA6B554 Enemy_Ridley *E = Get_Ridley(0); if (E->ridley_var_10) { - R18_ = 1024; - R20_ = 30720; + Ridley_Func_111(1024, 30720, 768); } else { - R18_ = -1024; - R20_ = -30720; + Ridley_Func_111(-1024, -30720, 768); } - R22_ = 768; - Ridley_Func_111(); uint16 ridley_var_00 = E->ridley_var_00; if (ridley_var_00) { E->ridley_var_00 = ridley_var_00 - 1; @@ -2142,16 +1980,13 @@ void Ridley_Func_12(void) { // 0xA6B554 } void Ridley_Func_13(void) { // 0xA6B594 - R18_ = 0; - R20_ = FUNC16(Enemy_GrappleReact_NoInteract_A6); - R22_ = 448; - Ridley_Func_111(); + Ridley_Func_111(0, 0x8000, 448); Enemy_Ridley *E = Get_Ridley(0); uint16 ridley_var_00 = E->ridley_var_00; if (ridley_var_00) { E->ridley_var_00 = ridley_var_00 - 1; } else { - E->ridley_var_A = Ridley_Func_40_Carry() ? FUNC16(Ridley_Func_33) : FUNC16(Ridley_Func_3b);; + E->ridley_var_A = Ridley_Func_40_Carry() ? FUNC16(Ridley_Func_33) : FUNC16(Ridley_Func_3b); } } @@ -2166,10 +2001,9 @@ void Ridley_Func_14(void) { // 0xA6B5C4 void Ridley_Func_15(void) { // 0xA6B5E5 Enemy_Ridley *E = Get_Ridley(0); - R18_ = g_word_A6B60D[E->ridley_var_10]; - if (Ridley_Func_17() & 1) { + if (Ridley_Func_17(g_word_A6B60D[E->ridley_var_10]) & 1) { Ridley_Func_18(); - } else if ((--E->ridley_var_F & 0x8000u) != 0) { + } else if ((--E->ridley_var_F & 0x8000) != 0) { E->ridley_var_A = FUNC16(Ridley_Func_16); E->ridley_var_F = 128; Ridley_Func_114(); @@ -2178,23 +2012,20 @@ void Ridley_Func_15(void) { // 0xA6B5E5 void Ridley_Func_16(void) { // 0xA6B613 Enemy_Ridley *E = Get_Ridley(0); - R18_ = g_word_A6B63B[E->ridley_var_10]; - if (Ridley_Func_17() & 1) { + if (Ridley_Func_17(g_word_A6B63B[E->ridley_var_10]) & 1) { Ridley_Func_18(); - } else if ((--E->ridley_var_F & 0x8000u) != 0) { + } else if ((--E->ridley_var_F & 0x8000) != 0) { E->ridley_var_A = FUNC16(Ridley_Func_15); E->ridley_var_F = 128; Ridley_Func_114(); } } -uint8 Ridley_Func_17(void) { // 0xA6B641 +uint8 Ridley_Func_17(uint16 r18) { // 0xA6B641 uint16 v0 = samus_y_pos; if (!sign16(samus_y_pos - 352)) v0 = 352; - R20_ = v0; - uint16 v1 = Ridley_Func_7(); - Ridley_Func_104_0(0, v1); + Ridley_Func_104_0(0, Ridley_Func_7(), r18, v0); tilemap_stuff[2] = 1; if (samus_movement_type != 3) return 1; @@ -2221,18 +2052,14 @@ void Ridley_Func_19(void) { // 0xA6B6A7 E->ridley_var_F = 32; Ridley_Func_20(); } else { - R18_ = g_word_A6B6C8[E->ridley_var_10]; - R20_ = 288; - Ridley_Func_104_0(0, 0); + Ridley_Func_104_0(0, 0, g_word_A6B6C8[E->ridley_var_10], 288); } } void Ridley_Func_20(void) { // 0xA6B6DD Enemy_Ridley *E = Get_Ridley(0); - R18_ = E->base.x_pos; - R20_ = 288; - Ridley_Func_104_0(0, 0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + Ridley_Func_104_0(0, 0, E->base.x_pos, 288); + if ((--E->ridley_var_F & 0x8000) != 0) { Ridley_Func_71(); Ridley_Func_29(); E->ridley_var_A = FUNC16(Ridley_Func_21); @@ -2253,10 +2080,9 @@ void Ridley_Func_21(void) { // 0xA6B70E v1 = 1536; E->ridley_var_C = v1; if (Ridley_Func_23() & 1) { - R18_ = tilemap_stuff[82]; - R20_ = tilemap_stuff[83] + 12; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); - QueueSfx2_Max6(0x76u); + eproj_spawn_pt = (Point16U) { tilemap_stuff[82], tilemap_stuff[83] + 12 }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); + QueueSfx2_Max6(0x76); earthquake_type = 13; earthquake_timer = 4; Ridley_Func_28(); @@ -2323,18 +2149,18 @@ void Ridley_Func_24(void) { // 0xA6B84D uint8 Ridley_Func_25(void) { // 0xA6B859 if ((Ridley_Func_40_Carry() & 1) != 0) - return Ridley_Func_26(4u, 4u) & 1; + return Ridley_Func_26(4, 4) & 1; else return 0; } uint8 Ridley_Func_26(uint16 k, uint16 j) { // 0xA6B865 - R22_ = k; - R24_ = j; Enemy_Ridley *E = Get_Ridley(0); - R18_ = E->base.x_pos + g_word_A6B9D5[E->ridley_var_10]; - R20_ = E->base.y_pos + g_word_A6B9DB[E->ridley_var_1D >> 1]; - return Ridley_Func_124() & 1; + Rect16U rect = { + E->base.x_pos + g_word_A6B9D5[E->ridley_var_10], E->base.y_pos + g_word_A6B9DB[E->ridley_var_1D >> 1], + k, j + }; + return Ridley_Func_124(rect); } void Ridley_Func_27(void) { // 0xA6B889 @@ -2356,19 +2182,19 @@ void Ridley_Func_28(void) { // 0xA6B8A9 Enemy_Ridley *E = Get_Ridley(0); if (!E->ridley_var_B) E->ridley_var_B = E->base.x_pos & 0x80 ? -0xc0 : 0xc0; - if (((E->ridley_var_B ^ (E->base.x_pos - samus_x_pos)) & 0x8000u) == 0) { + if (((E->ridley_var_B ^ (E->base.x_pos - samus_x_pos)) & 0x8000) == 0) { uint16 x_pos; x_pos = E->base.x_pos; if ((int16)(x_pos - E->ridley_var_22) >= 0) { if ((int16)(x_pos - E->ridley_var_23) < 0) { - if (random_number < 0x555u) + if (random_number < 0x555) return; goto LABEL_7; } goto LABEL_15; } LABEL_13: - if ((E->ridley_var_B & 0x8000u) == 0) + if ((E->ridley_var_B & 0x8000) == 0) return; LABEL_7: E->ridley_var_B = -E->ridley_var_B; @@ -2380,38 +2206,33 @@ LABEL_7: goto LABEL_13; if ((int16)(v4 - E->ridley_var_23) >= 0) { LABEL_15: - if ((E->ridley_var_B & 0x8000u) != 0) + if ((E->ridley_var_B & 0x8000) != 0) return; goto LABEL_7; } - if (random_number < 0x555u) + if (random_number < 0x555) goto LABEL_7; } void Ridley_Func_29(void) { // 0xA6B90F int v0 = random_number & 3; - R18_ = g_off_A6B965[v0]; - R20_ = g_off_A6B96D[v0]; + uint16 r18 = g_off_A6B965[v0], r20 = g_off_A6B96D[v0]; Enemy_Ridley *E = Get_Ridley(0); uint16 v2 = 2 * (E->ridley_var_12 + 2); int v3 = v2 >> 1; tilemap_stuff[7] = g_word_A6B94D[v3]; tilemap_stuff[6] = g_word_A6B959[v3]; - E->ridley_var_C = *(uint16 *)&RomPtr_A6(R20_)[v2]; - const uint8 *v4 = RomPtr_A6(R18_); + E->ridley_var_C = *(uint16 *)&RomPtr_A6(r20)[v2]; + const uint8 *v4 = RomPtr_A6(r18); uint16 t = *(uint16 *)&v4[v2]; E->ridley_var_B = sign16(E->ridley_var_B) ? -t : t; } void Ridley_Func_30(void) { // 0xA6B9E1 - int16 v2; - int16 v5; - Enemy_Ridley *E = Get_Ridley(0); uint16 ridley_var_14 = E->ridley_var_14, v3, v6; if (ridley_var_14) { - R18_ = E->ridley_var_14; - v2 = abs16(ridley_var_14) - 4; + int16 v2 = abs16(ridley_var_14) - 4; if (v2 >= 0) v3 = sign16(ridley_var_14) ? -v2 : v2; else @@ -2420,25 +2241,20 @@ void Ridley_Func_30(void) { // 0xA6B9E1 } uint16 ridley_var_15 = E->ridley_var_15; if (ridley_var_15) { - R18_ = E->ridley_var_15; - v5 = abs16(ridley_var_15) - 4; + int16 v5 = abs16(ridley_var_15) - 4; if (v5 >= 0) v6 = sign16(ridley_var_15) ? -v5 : v5; else v6 = 0; E->ridley_var_15 = v6; } - samus_x_pos = E->ridley_var_14 - + E->base.x_pos - + g_word_A6B9D5[E->ridley_var_10]; + samus_x_pos = E->ridley_var_14 + E->base.x_pos + g_word_A6B9D5[E->ridley_var_10]; samus_y_pos = E->ridley_var_15 + E->base.y_pos + g_word_A6B9DB[E->ridley_var_1D >> 1]; } void Ridley_Func_31(void) { // 0xA6BA54 Enemy_Ridley *E = Get_Ridley(0); - E->ridley_var_14 = samus_x_pos - - (E->base.x_pos - + g_word_A6B9D5[E->ridley_var_10]); + E->ridley_var_14 = samus_x_pos - (E->base.x_pos + g_word_A6B9D5[E->ridley_var_10]); E->ridley_var_15 = samus_y_pos - (E->base.y_pos + g_word_A6B9DB[E->ridley_var_1D >> 1]); } @@ -2463,25 +2279,20 @@ void Ridley_Func_33(void) { // 0xA6BAB7 Enemy_Ridley *E = Get_Ridley(0); uint16 v1; int16 v2; + uint16 r18, r20; if ((Ridley_Func_40_Carry() & 1) != 0 && (!E->ridley_var_1F) - && ((R18_ = g_word_A6BB48[E->ridley_var_10], - R20_ = E->base.x_pos - samus_x_pos, - ((R18_ ^ R20_) & 0x8000u) == 0) - || (v1 = abs16(R20_), sign16(v1 - 32))) + && ((r18 = g_word_A6BB48[E->ridley_var_10], r20 = E->base.x_pos - samus_x_pos, + ((r18 ^ r20) & 0x8000) == 0) + || (v1 = abs16(r20), sign16(v1 - 32))) && (int16)(E->base.y_pos + 35 - samus_y_pos) < 0) { v2 = -16; if (E->ridley_var_10) v2 = 16; - R18_ = samus_x_pos + v2; - R20_ = samus_y_pos - 4; - Ridley_Func_104_0(0, g_word_A6BB4E[E->ridley_var_12]); - R18_ = E->base.x_pos + g_word_A6B9D5[E->ridley_var_10]; - R20_ = E->base.y_pos + 35; - R22_ = 8; - R24_ = 12; - if (Ridley_Func_124() & 1) { + Ridley_Func_104_0(0, g_word_A6BB4E[E->ridley_var_12], samus_x_pos + v2, samus_y_pos - 4); + Rect16U rect = { E->base.x_pos + g_word_A6B9D5[E->ridley_var_10], E->base.y_pos + 35, 8, 12 }; + if (Ridley_Func_124(rect)) { E->ridley_var_C = -E->ridley_var_C; if (E->base.health) { if (power_bomb_flag) { @@ -2522,10 +2333,8 @@ void Ridley_Func_33b(void) { // 0xA6BB8F void Ridley_Func_34(void) { // 0xA6BBC4 Enemy_Ridley *E = Get_Ridley(0); - R18_ = E->ridley_var_17; - R20_ = E->ridley_var_18; - Ridley_Func_104_0(0, 0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + Ridley_Func_104_0(0, 0, E->ridley_var_17, E->ridley_var_18); + if ((--E->ridley_var_F & 0x8000) != 0) { E->ridley_var_A = FUNC16(Ridley_Func_35); E->ridley_var_F = 32; } @@ -2533,29 +2342,25 @@ void Ridley_Func_34(void) { // 0xA6BBC4 void Ridley_Func_35(void) { // 0xA6BBF1 Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + if ((--E->ridley_var_F & 0x8000) != 0) { tilemap_stuff[15] = 8; tilemap_stuff[9] = 240; Ridley_Func_38(); E->ridley_var_A = FUNC16(Ridley_Func_36); E->ridley_var_F = 64; } else { - R18_ = E->ridley_var_17; - R20_ = 256; - Ridley_Func_104_0(0, 0); + Ridley_Func_104_0(0, 0, E->ridley_var_17, 256); } } void Ridley_Func_36(void) { // 0xA6BC2E Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + if ((--E->ridley_var_F & 0x8000) != 0) { tilemap_stuff[15] = 16; tilemap_stuff[9] = 240; E->ridley_var_A = FUNC16(Ridley_Func_3b); } else { - R18_ = g_word_A6BC62[E->ridley_var_10]; - R20_ = 224; - Ridley_Func_104_0(0, 0); + Ridley_Func_104_0(0, 0, g_word_A6BC62[E->ridley_var_10], 224); } } @@ -2572,11 +2377,11 @@ void Ridley_Func_38(void) { // 0xA6BC84 tilemap_stuff[2] = 1; tilemap_stuff[0] = 1; Enemy_Ridley *E = Get_Ridley(0); - if ((E->ridley_var_01 & 0x8000u) == 0) { + if ((E->ridley_var_01 & 0x8000) == 0) { E->ridley_var_1E = Ridley_Func_40_Sign() ? 6 : 10; } E->ridley_var_1B = 0; - CallSomeSamusCode(1u); + CallSomeSamusCode(1); Ridley_Func_119(0); } @@ -2597,7 +2402,7 @@ void Ridley_Func_39(void) { // 0xA6BCB4 if (ridley_var_1E) { uint16 v3 = ridley_var_1E - 1; E->ridley_var_1E = v3; - if (!v3 && (E->ridley_var_01 & 0x8000u) == 0) + if (!v3 && (E->ridley_var_01 & 0x8000) == 0) E->base.properties &= ~kEnemyProps_Tangible; } } @@ -2608,11 +2413,11 @@ static const uint8 byte_A6BD04[28] = { 0x80, 0xff, 0xff, 0xff, 0x80, 0x80, 0, 0x80, 0x80, 0, 0, 0x80, }; -uint8 Ridley_Func_40_Carry(void) { +static uint8 Ridley_Func_40_Carry(void) { return (byte_A6BD04[samus_movement_type] & 0x80) != 0; } -uint8 Ridley_Func_40_Sign(void) { +static uint8 Ridley_Func_40_Sign(void) { return (byte_A6BD04[samus_movement_type] & 0x40) != 0; } @@ -2635,16 +2440,9 @@ void Ridley_Func_42(void) { // 0xA6BD2C void Ridley_Func_43(void) { // 0xA6BD4E if (power_bomb_flag) { Get_Ridley(0)->ridley_var_01 = 2; - uint16 v0 = 80; - if (sign16(power_bomb_explosion_x_pos - 128)) - v0 = 192; - R18_ = v0; - uint16 v1 = 192; - if (sign16(power_bomb_explosion_y_pos - 256)) - v1 = 384; - R20_ = v1; - uint16 v2 = Ridley_Func_7(); - Ridley_Func_104_0(0, v2); + uint16 r18 = sign16(power_bomb_explosion_x_pos - 128) ? 192 : 80; + uint16 r20 = sign16(power_bomb_explosion_y_pos - 256) ? 384 : 192; + Ridley_Func_104_0(0, Ridley_Func_7(), r18, r20); } else { Enemy_Ridley *E = Get_Ridley(0); E->ridley_var_01 = 1; @@ -2653,9 +2451,7 @@ void Ridley_Func_43(void) { // 0xA6BD4E } void Ridley_Func_44(void) { // 0xA6BD9A - R18_ = 192; - R20_ = 128; - Ridley_Func_106(0, 1u); + Ridley_Func_106(0, 1, 192, 128); Enemy_Ridley *E = Get_Ridley(0); if (!sign16(E->base.x_pos - 192)) E->ridley_var_A = FUNC16(Ridley_Func_45); @@ -2664,9 +2460,7 @@ void Ridley_Func_44(void) { // 0xA6BD9A void Ridley_Func_45(void) { // 0xA6BDBC Enemy_Ridley *E = Get_Ridley(0); E->ridley_var_20 = -192; - R18_ = 192; - R20_ = -128; - Ridley_Func_106(0, 1u); + Ridley_Func_106(0, 1, 192, -128); if (sign16(E->base.y_pos - 32)) { E->ridley_var_40 = FUNC16(Ridley_Func_52); E->ridley_var_A = FUNC16(Ridley_Func_46); @@ -2676,7 +2470,7 @@ void Ridley_Func_45(void) { // 0xA6BDBC void Ridley_Func_46(void) { // 0xA6BDF2 Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + if ((--E->ridley_var_F & 0x8000) != 0) { Ridley_Func_99(addr_kRidley_Ilist_E658); E->ridley_var_A = FUNC16(Ridley_Func_47); Ridley_Func_47(); @@ -2685,14 +2479,9 @@ void Ridley_Func_46(void) { // 0xA6BDF2 void Ridley_Func_47(void) { // 0xA6BE03 Enemy_Ridley *E = Get_Ridley(0); - R18_ = E->ridley_var_42 - 10; - R20_ = E->ridley_var_44 - 56; - Ridley_Func_104_0(0, 12); - R18_ = E->base.x_pos + 14; - R20_ = E->base.y_pos + 66; - R22_ = 4; - R24_ = 4; - if (Ridley_Func_48() & 1) { + Ridley_Func_104_0(0, 12, E->ridley_var_42 - 10, E->ridley_var_44 - 56); + Rect16U rect = { E->base.x_pos + 14, E->base.y_pos + 66, 4, 4 }; + if (Ridley_Func_48(rect) & 1) { E->ridley_var_1B = 1; Ridley_Func_119(1); E->ridley_var_C = -512; @@ -2701,17 +2490,17 @@ void Ridley_Func_47(void) { // 0xA6BE03 } } -uint8 Ridley_Func_48(void) { // 0xA6BE61 +uint8 Ridley_Func_48(Rect16U rect) { // 0xA6BE61 Enemy_Ridley *E = Get_Ridley(0); - uint16 v1 = abs16(E->ridley_var_42 - R18_); - bool v2 = v1 < 4u; + uint16 v1 = abs16(E->ridley_var_42 - rect.x); + bool v2 = v1 < 4; uint16 v3 = v1 - 4; uint8 result = 0; - if (v2 || v3 < R22_) { - uint16 v4 = abs16(E->ridley_var_44 - R20_); - v2 = v4 < 4u; + if (v2 || v3 < rect.w) { + uint16 v4 = abs16(E->ridley_var_44 - rect.y); + v2 = v4 < 4; uint16 v5 = v4 - 4; - if (v2 || v5 < R24_) + if (v2 || v5 < rect.h) return 1; } return result; @@ -2729,8 +2518,7 @@ void CallRidleyFunc_var40(uint32 ea) { } void Ridley_Func_49(void) { // 0xA6BE93 - R18_ = Get_Ridley(0)->ridley_var_40; - CallRidleyFunc_var40(R18_ | 0xA60000); + CallRidleyFunc_var40(Get_Ridley(0)->ridley_var_40 | 0xA60000); } void Ridley_Func_50(void) { // 0xA6BE9C @@ -2771,16 +2559,14 @@ void DrawBabyMetroid_0(void) { // 0xA6BF1A if (v0 < 0) return; Enemy_Ridley *E = Get_Ridley(0); - R18_ = E->ridley_var_42; - R20_ = E->ridley_var_44; - R22_ = 0; - sub_A6DC13(v0); + + sub_A6DC13(v0, E->ridley_var_42, E->ridley_var_44, 0); } uint16 BabyMetroid_Instr_2(uint16 k) { // 0xA6BFC9 if (!Get_Ridley(0)->ridley_var_46 && (random_number & 1) != 0) return BabyMetroid_Goto(k); - QueueSfx3_Max6(0x24u); + QueueSfx3_Max6(0x24); return k + 2; } @@ -2805,22 +2591,22 @@ void Ridley_Func_54(void) { // 0xA6C04E uint16 ridley_var_F = Get_Ridley(0)->ridley_var_F; if (ridley_var_F) { switch (ridley_var_F) { - case 2u: + case 2: Ridley_C08E(); break; - case 4u: + case 4: Ridley_C09F(); break; - case 6u: + case 6: Ridley_Func_56(); break; - case 8u: + case 8: Ridley_Func_57(); break; - case 0xAu: + case 0xA: Ridley_C104(); break; - case 0xCu: + case 0xC: Ridley_Func_58(); break; default: @@ -2862,7 +2648,7 @@ void Ridley_C09F(void) { // 0xA6C09F ++E->ridley_var_F; Ridley_Func_59(); E->ridley_var_E = 128; - QueueMusic_Delayed8(7u); + QueueMusic_Delayed8(7); } } @@ -2897,7 +2683,7 @@ void Ridley_Func_57(void) { // 0xA6C0F5 void Ridley_C104(void) { // 0xA6C104 Ridley_Func_61(); - if (HandleTypewriterText_Ext(0x3582u) & 1) { + if (HandleTypewriterText_Ext(0x3582) & 1) { Enemy_Ridley *E = Get_Ridley(0); ++E->ridley_var_F; ++E->ridley_var_F; @@ -2912,7 +2698,7 @@ void Ridley_Func_58(void) { // 0xA6C117 E->ridley_var_A = FUNC16(CeresRidley_Func_26); timer_status = 1; ceres_status = 2; - SetBossBitForCurArea(1u); + SetBossBitForCurArea(1); } void Ridley_Func_59(void) { // 0xA6C136 @@ -2943,10 +2729,10 @@ void Ridley_Func_61(void) { // 0xA6C19C if (!(door_transition_flag_enemies | palette_change_num) && (nmi_frame_counter_word & 3) == 0) { Enemy_Ridley *E = Get_Ridley(0); uint16 v1 = E->ridley_var_38 + 1; - if (v1 >= 0x10u) + if (v1 >= 0x10) v1 = 0; E->ridley_var_38 = v1; - int v2 = (uint16)(2 * (E->ridley_var_38 + 2 * v1)) >> 1; + int v2 = E->ridley_var_38 + 2 * v1; palette_buffer[97] = g_word_A6C1DF[v2]; palette_buffer[98] = g_word_A6C1DF[v2 + 1]; palette_buffer[99] = g_word_A6C1DF[v2 + 2]; @@ -2989,11 +2775,7 @@ uint8 ProcessEscapeTimerTileTransfers(void) { // 0xA6C26E } uint8 HandleTypewriterText_Ext(uint16 a) { // 0xA6C2A7 - R18_ = a; - return HandleTypewriterText() & 1; -} - -uint8 HandleTypewriterText(void) { // 0xA6C2B1 + uint16 r18 = a; int16 v4; VramWriteEntry *v12; @@ -3036,7 +2818,7 @@ uint8 HandleTypewriterText(void) { // 0xA6C2B1 v12 = gVramWriteEntry(vram_write_queue_tail); v12->size = 2; *(VoidP *)((uint8 *)&v12->src.addr + 1) = 32256; - E->mbn_var_3A = R18_ + v4 - 65; + E->mbn_var_3A = r18 + v4 - 65; v12->src.addr = ADDR16_OF_RAM(*extra_enemy_ram8000) + 52; uint16 mbn_var_3C = E->mbn_var_3C; v12->vram_dst = mbn_var_3C; @@ -3047,9 +2829,9 @@ uint8 HandleTypewriterText(void) { // 0xA6C2B1 if (!sign16(v14 - 2)) { E->mbn_var_3F = 0; if (area_index == 6) - QueueSfx2_Max3(0x45u); + QueueSfx2_Max3(0x45); else - QueueSfx3_Max3(0xDu); + QueueSfx3_Max3(0xD); } return 0; } @@ -3090,7 +2872,7 @@ void Ridley_C53E(void) { // 0xA6C53E void Ridley_C551(void) { // 0xA6C551 Ridley_Func_68(); Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + if ((--E->ridley_var_F & 0x8000) != 0) { E->ridley_var_B = 0; E->ridley_var_C = 0; fx_target_y_pos = 528; @@ -3107,7 +2889,7 @@ void Ridley_C551(void) { // 0xA6C551 void Ridley_Func_64(void) { // 0xA6C588 Ridley_Func_69(); Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + if ((--E->ridley_var_F & 0x8000) != 0) { if (E->ridley_var_1B) Ridley_Func_38(); E->ridley_var_A = FUNC16(Ridley_Func_65); @@ -3128,7 +2910,7 @@ void Ridley_Func_65(void) { // 0xA6C5A8 void Ridley_Func_66(void) { // 0xA6C5C8 Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + if ((--E->ridley_var_F & 0x8000) != 0) { E->ridley_var_A = FUNC16(Ridley_Func_67); E->ridley_var_F = 256; } @@ -3136,24 +2918,21 @@ void Ridley_Func_66(void) { // 0xA6C5C8 void Ridley_Func_67(void) { // 0xA6C5DA Enemy_Ridley *E = Get_Ridley(0); - if ((--E->ridley_var_F & 0x8000u) != 0) { + if ((--E->ridley_var_F & 0x8000) != 0) { uint16 k = 0; printf("Warning: X undefined\n"); - SetBossBitForCurArea(1u); + SetBossBitForCurArea(1); Enemy_ItemDrop_Ridley(k); - QueueMusic_Delayed8(3u); + QueueMusic_Delayed8(3); E->base.properties |= kEnemyProps_Deleted; E->ridley_var_A = addr_locret_A6C600; } } uint8 Ridley_Func_68(void) { // 0xA6C601 - R18_ = 128; - R20_ = 328; - Ridley_Func_104(0, 0, 0x10); - R22_ = 4; - R24_ = 4; - return Shitroid_Func_2(0) & 1; + Rect16U rect = { 128, 328, 4, 4 }; + Ridley_Func_104(0, 0, 0x10, rect.x, rect.y); + return Shitroid_Func_2(0, rect); } void Ridley_Func_69(void) { // 0xA6C623 @@ -3168,10 +2947,9 @@ void Ridley_Func_69(void) { // 0xA6C623 v2 = 0; E->ridley_var_28 = v2; int v3 = (uint16)(4 * v2) >> 1; - R18_ = E->base.x_pos + g_word_A6C66E[v3]; - R20_ = E->base.y_pos + g_word_A6C66E[v3 + 1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3u); - QueueSfx2_Max3(0x24u); + eproj_spawn_pt = (Point16U){ E->base.x_pos + g_word_A6C66E[v3], E->base.y_pos + g_word_A6C66E[v3 + 1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3); + QueueSfx2_Max3(0x24); } else { E->ridley_var_27 = v1; } @@ -3190,39 +2968,37 @@ void RidleysExplosion_Init(void) { // 0xA6C696 E->ridley_var_C = 0; if (ridley_parameter_1) { switch (ridley_parameter_1) { - case 2u: + case 2: E->base.x_pos = tilemap_stuff[32]; E->base.y_pos = tilemap_stuff[33]; E->base.current_instruction = addr_kRidleysExplosion_Ilist_CA47; break; - case 4u: + case 4: E->base.x_pos = tilemap_stuff[42]; E->base.y_pos = tilemap_stuff[43]; E->base.current_instruction = addr_kRidleysExplosion_Ilist_CA4D; break; - case 6u: + case 6: E->base.x_pos = tilemap_stuff[52]; E->base.y_pos = tilemap_stuff[53]; E->base.current_instruction = addr_kRidleysExplosion_Ilist_CA4D; break; - case 8u: + case 8: E->base.x_pos = tilemap_stuff[62]; E->base.y_pos = tilemap_stuff[63]; E->base.current_instruction = addr_kRidleysExplosion_Ilist_CA53; break; - case 0xAu: + case 0xA: E->base.x_pos = tilemap_stuff[72]; E->base.y_pos = tilemap_stuff[73]; E->base.current_instruction = addr_kRidleysExplosion_Ilist_CA53; break; - case 0xCu: + case 0xC: E->base.x_pos = tilemap_stuff[82]; E->base.y_pos = tilemap_stuff[83]; - E->base.current_instruction = g_off_A6C7BA[(uint16)((uint8)((LOBYTE(tilemap_stuff[71]) - + LOBYTE(tilemap_stuff[81]) - + 8) & 0xF0) >> 3) >> 1]; + E->base.current_instruction = g_off_A6C7BA[(uint8)((LOBYTE(tilemap_stuff[71]) + LOBYTE(tilemap_stuff[81]) + 8) & 0xF0) >> 4]; break; - case 0xEu: { + case 0xE: { uint16 v10 = 0; Enemy_Ridley *E0 = Get_Ridley(0); if (E0->ridley_var_10) @@ -3234,7 +3010,7 @@ void RidleysExplosion_Init(void) { // 0xA6C696 E->base.current_instruction = g_off_A6C808[v13]; break; } - case 0x10u: { + case 0x10: { uint16 v16 = 0; Enemy_Ridley *E0 = Get_Ridley(0); if (E0->ridley_var_10) @@ -3246,7 +3022,7 @@ void RidleysExplosion_Init(void) { // 0xA6C696 E->base.current_instruction = g_off_A6C83A[v19]; break; } - case 0x12u: { + case 0x12: { uint16 v22 = 0; Enemy_Ridley *E0 = Get_Ridley(0); if (E0->ridley_var_10) @@ -3258,7 +3034,7 @@ void RidleysExplosion_Init(void) { // 0xA6C696 E->base.current_instruction = g_off_A6C86C[v25]; break; } - case 0x14u: { + case 0x14: { uint16 v28 = 0; Enemy_Ridley *E0 = Get_Ridley(0); if (E0->ridley_var_10) @@ -3270,7 +3046,7 @@ void RidleysExplosion_Init(void) { // 0xA6C696 E->base.current_instruction = g_off_A6C89E[v31]; break; } - case 0x16u: { + case 0x16: { uint16 v34 = 0; Enemy_Ridley *E0 = Get_Ridley(0); if (E0->ridley_var_10) @@ -3305,7 +3081,7 @@ void RidleysExplosion_Main(void) { // 0xA6C8D4 E->ren_var_B = sign16(E->ren_var_B) ? -v2 : v2; E->ren_var_C += 4; MoveEnemyWithVelocity(); - if ((--E->ren_var_F & 0x8000u) != 0) + if ((--E->ren_var_F & 0x8000) != 0) EnemyDeathAnimation(cur_enemy_index, 0); } @@ -3385,45 +3161,36 @@ void Ridley_Func_75(void) { // 0xA6CB72 } void Ridley_CBC0(void) { // 0xA6CBC0 - R18_ = FUNC16(Ridley_Func_79); Ridley_Func_79(); Ridley_CBDC(); } void Ridley_CBC7(void) { // 0xA6CBC7 - R18_ = FUNC16(Ridley_Func_83); Ridley_Func_83(); Ridley_CBDC(); } void Ridley_CBCE(void) { // 0xA6CBCE - R18_ = FUNC16(Ridley_Func_84); Ridley_Func_84(); Ridley_CBDC(); } void Ridley_CBD5(void) { // 0xA6CBD5 - R18_ = FUNC16(Ridley_Func_81); Ridley_Func_81(); Ridley_CBDC(); } void Ridley_CBDC(void) { // 0xA6CBDC - int16 v0; - int16 v2; - - v0 = 7; + uint16 v0 = 7; uint16 v1 = 0; do { - v2 = v0; Ridley_Func_88(v1); v1 += 20; - v0 = v2 - 1; - } while (v2 != 1); + } while (v0-- != 1); } void Ridley_Func_77(void) { // 0xA6CBFE - int v0 = (uint16)(2 * Get_Ridley(0)->ridley_var_10) >> 1; + int v0 = Get_Ridley(0)->ridley_var_10; tilemap_stuff[11] = g_word_A6CC12[v0]; tilemap_stuff[12] = g_word_A6CC18[v0]; } @@ -3439,11 +3206,11 @@ void Ridley_Func_79(void) { // 0xA6CC39 return; } if (!(tilemap_stuff[76] | (uint16)(tilemap_stuff[66] | tilemap_stuff[56] | tilemap_stuff[46] | tilemap_stuff[36] | tilemap_stuff[26] | tilemap_stuff[16]))) { - tilemap_stuff[16] = FUNC16(Enemy_GrappleReact_NoInteract_A6); + tilemap_stuff[16] = 0x8000; tilemap_stuff[13] = -1; tilemap_stuff[14] = -1; uint16 v0 = 2; - if (samus_x_pos < 0x70u) + if (samus_x_pos < 0x70) v0 = 1; tilemap_stuff[10] = v0; } @@ -3453,11 +3220,11 @@ uint8 Ridley_Func_80_DoubleRet(void) { // 0xA6CC7D Enemy_Ridley *E = Get_Ridley(0); bool retval = false; uint16 v1; - if (tilemap_stuff[2] && (tilemap_stuff[13] & tilemap_stuff[14] & 0x8000u) != 0) + if (tilemap_stuff[2] && (tilemap_stuff[13] & tilemap_stuff[14] & 0x8000) != 0) goto LABEL_7; if (!tilemap_stuff[1]) goto LABEL_9; - if ((uint8)random_number >= 0xF0u) { + if ((uint8)random_number >= 0xF0) { LABEL_7: v1 = tilemap_stuff[2] - 1; goto LABEL_8; @@ -3482,11 +3249,11 @@ void Ridley_Func_81(void) { // 0xA6CCBD return; } if (!(tilemap_stuff[76] | (uint16)(tilemap_stuff[66] | tilemap_stuff[56] | tilemap_stuff[46] | tilemap_stuff[36] | tilemap_stuff[26] | tilemap_stuff[16]))) { - tilemap_stuff[16] = FUNC16(Enemy_GrappleReact_NoInteract_A6); + tilemap_stuff[16] = 0x8000; tilemap_stuff[13] = -1; tilemap_stuff[14] = -1; uint16 v0 = 2; - if (samus_x_pos < 0x70u) + if (samus_x_pos < 0x70) v0 = 1; tilemap_stuff[10] = v0; } @@ -3494,8 +3261,8 @@ void Ridley_Func_81(void) { // 0xA6CCBD bool Ridley_Func_82_DoubleRet(void) { if (tilemap_stuff[2]) { - if ((tilemap_stuff[13] & tilemap_stuff[14] & 0x8000u) != 0) { - Ridley_Func_89(1u); + if ((tilemap_stuff[13] & tilemap_stuff[14] & 0x8000) != 0) { + Ridley_Func_89(1); tilemap_stuff[2] = 0; return true; } @@ -3507,13 +3274,13 @@ void Ridley_Func_83(void) { // 0xA6CD24 Enemy_Ridley *E = Get_Ridley(0); Ridley_Func_77(); if (Ridley_Func_78() & 1 - && ((uint8)random_number >= 0xF0u + && ((uint8)random_number >= 0xF0 || (abs16(samus_x_pos - E->base.x_pos) < 0x80)) - && (tilemap_stuff[13] & tilemap_stuff[14] & 0x8000u) != 0) { + && (tilemap_stuff[13] & tilemap_stuff[14] & 0x8000) != 0) { tilemap_stuff[13] = 16128; tilemap_stuff[10] = 8; } else if (!(tilemap_stuff[76] | (uint16)(tilemap_stuff[66] | tilemap_stuff[56] | tilemap_stuff[46] | tilemap_stuff[36] | tilemap_stuff[26] | tilemap_stuff[16]))) { - if ((Get_Ridley(0)->ridley_var_C & 0x8000u) == 0) + if ((Get_Ridley(0)->ridley_var_C & 0x8000) == 0) tilemap_stuff[0] = 5; tilemap_stuff[13] = -1; tilemap_stuff[14] = -1; @@ -3521,7 +3288,7 @@ void Ridley_Func_83(void) { // 0xA6CD24 if (!tilemap_stuff[8] || (v1 = tilemap_stuff[8] - 1, (tilemap_stuff[8] = v1) != 0)) { tilemap_stuff[10] = v1; } else { - tilemap_stuff[16] = FUNC16(Enemy_GrappleReact_NoInteract_A6); + tilemap_stuff[16] = 0x8000; Ridley_Func_85(); tilemap_stuff[10] = 8; } @@ -3532,13 +3299,13 @@ void Ridley_Func_84(void) { // 0xA6CDAA Enemy_Ridley *E = Get_Ridley(0); Ridley_Func_77(); if (Ridley_Func_78() & 1 - && ((uint8)random_number >= 0xF0u + && ((uint8)random_number >= 0xF0 || (abs16(samus_x_pos - E->base.x_pos) < 0x80)) - && (tilemap_stuff[13] & tilemap_stuff[14] & 0x8000u) != 0) { + && (tilemap_stuff[13] & tilemap_stuff[14] & 0x8000) != 0) { tilemap_stuff[13] = 16128; tilemap_stuff[10] = 8; } else if (!(tilemap_stuff[76] | (uint16)(tilemap_stuff[66] | tilemap_stuff[56] | tilemap_stuff[46] | tilemap_stuff[36] | tilemap_stuff[26] | tilemap_stuff[16]))) { - if ((E->ridley_var_C & 0x8000u) == 0) { + if ((E->ridley_var_C & 0x8000) == 0) { tilemap_stuff[0] = 6; tilemap_stuff[20] = 2560; tilemap_stuff[30] = 2560; @@ -3554,7 +3321,7 @@ void Ridley_Func_84(void) { // 0xA6CDAA tilemap_stuff[61] = 0x4000; tilemap_stuff[71] = 0x4000; tilemap_stuff[81] = 0x4000; - tilemap_stuff[16] = FUNC16(Enemy_GrappleReact_NoInteract_A6); + tilemap_stuff[16] = 0x8000; } tilemap_stuff[13] = -1; tilemap_stuff[14] = -1; @@ -3563,7 +3330,7 @@ void Ridley_Func_84(void) { // 0xA6CDAA v1 = tilemap_stuff[8] - 1; tilemap_stuff[8] = v1; if (!v1) { - tilemap_stuff[16] = FUNC16(Enemy_GrappleReact_NoInteract_A6); + tilemap_stuff[16] = 0x8000; Ridley_Func_85(); v1 = 8; } @@ -3681,7 +3448,7 @@ void Ridley_Func_88(uint16 k) { // 0xA6D09F int16 v6; uint16 v2; int v1 = k >> 1; - if ((tilemap_stuff[v1 + 16] & 0x8000u) != 0) { + if ((tilemap_stuff[v1 + 16] & 0x8000) != 0) { int v4 = k >> 1; uint16 v5 = tilemap_stuff[v4 + 17]; if (v5 < tilemap_stuff[15]) { @@ -3690,15 +3457,15 @@ void Ridley_Func_88(uint16 k) { // 0xA6D09F } if (v5 != 0xFFFF) { tilemap_stuff[v4 + 17] = -1; - tilemap_stuff[v4 + 26] = FUNC16(Enemy_GrappleReact_NoInteract_A6); + tilemap_stuff[v4 + 26] = 0x8000; tilemap_stuff[v4 + 28] = tilemap_stuff[v4 + 18]; } - if ((tilemap_stuff[v4 + 18] & 0x8000u) == 0) { - if ((tilemap_stuff[14] & 0x8000u) != 0) { + if ((tilemap_stuff[v4 + 18] & 0x8000) == 0) { + if ((tilemap_stuff[14] & 0x8000) != 0) { v2 = tilemap_stuff[10] + tilemap_stuff[v4 + 21]; if ((int16)(v2 - tilemap_stuff[12]) >= 0) { LABEL_15: - tilemap_stuff[v4 + 18] = FUNC16(Enemy_GrappleReact_NoInteract_A6); + tilemap_stuff[v4 + 18] = 0x8000; v2 = tilemap_stuff[12]; } } else { @@ -3711,7 +3478,7 @@ LABEL_3:; int v3 = k >> 1; tilemap_stuff[v3 + 16] = 0; tilemap_stuff[v3 + 17] = 0; - tilemap_stuff[v3 + 18] ^= 0x8000u; + tilemap_stuff[v3 + 18] ^= 0x8000; return; } goto LABEL_15; @@ -3721,7 +3488,7 @@ LABEL_24: tilemap_stuff[v4 + 21] = v2; goto LABEL_25; } - if ((tilemap_stuff[13] & 0x8000u) != 0) { + if ((tilemap_stuff[13] & 0x8000) != 0) { v6 = tilemap_stuff[v4 + 21] - tilemap_stuff[10] - 1; if ((int16)(v6 - tilemap_stuff[11]) < 0) { LABEL_22: @@ -3744,19 +3511,18 @@ LABEL_22: goto LABEL_24; } v2 = tilemap_stuff[v1 + 21]; -LABEL_25: - R18_ = (uint8)v2; +LABEL_25:; + uint16 r18 = (uint8)v2; if (k) - R18_ = (uint8)(LOBYTE(tilemap_stuff[(k >> 1) + 11]) + R18_); + r18 = (uint8)(LOBYTE(tilemap_stuff[(k >> 1) + 11]) + r18); int v7 = k >> 1; - tilemap_stuff[v7 + 24] = ComputeSinMult(HIBYTE(tilemap_stuff[v7 + 19])); - tilemap_stuff[v7 + 25] = ComputeCosMult(HIBYTE(tilemap_stuff[v7 + 19])); + tilemap_stuff[v7 + 24] = ComputeSinMult(HIBYTE(tilemap_stuff[v7 + 19]), r18); + tilemap_stuff[v7 + 25] = ComputeCosMult(HIBYTE(tilemap_stuff[v7 + 19]), r18); } void Ridley_Func_89(uint16 a) { // 0xA6D19D - uint16 v1; + uint16 v1, r18, r20; int8 v2; // t0 - int8 v4; // cf v2 = a; LOBYTE(v1) = 0; @@ -3764,18 +3530,18 @@ void Ridley_Func_89(uint16 a) { // 0xA6D19D tilemap_stuff[5] = v1; Enemy_Ridley *E = Get_Ridley(0); if (E->ridley_var_10 != 1 && E->ridley_var_01) { - v4 = Ridley_Func_90() & 1; - if (v4) { - R18_ -= !v4 + tilemap_stuff[22]; - R20_ -= tilemap_stuff[23]; + Point16U pt; + if (Ridley_Func_90(&pt)) { + r18 = pt.x - tilemap_stuff[22]; + r20 = pt.y - tilemap_stuff[23]; } else { - R18_ = samus_x_pos - tilemap_stuff[22]; - R20_ = samus_y_pos + 24 - tilemap_stuff[23]; + r18 = samus_x_pos - tilemap_stuff[22]; + r20 = samus_y_pos + 24 - tilemap_stuff[23]; } - R18_ = (uint8)-(int8)(CalculateAngleFromXY() + 0x80); + r18 = (uint8)-(CalculateAngleFromXY(r18, r20) + 0x80); if (E->ridley_var_10) { - uint16 v7 = R18_; - if (R18_ >= 0x18u && R18_ < 0xE8u) + uint16 v7 = r18; + if (r18 >= 0x18 && r18 < 0xE8) v7 = 24; uint16 v8 = tilemap_stuff[5] + v7 + 0x4000; if (v8 >= tilemap_stuff[21]) { @@ -3783,8 +3549,8 @@ void Ridley_Func_89(uint16 a) { // 0xA6D19D tilemap_stuff[10] = 8; } } else { - uint16 v5 = R18_; - if (R18_ >= 0x18u && R18_ < 0xE8u) + uint16 v5 = r18; + if (r18 >= 0x18 && r18 < 0xE8) v5 = 232; uint16 v6 = v5 + 16128 - tilemap_stuff[5]; if (v6 < tilemap_stuff[21]) { @@ -3795,25 +3561,23 @@ void Ridley_Func_89(uint16 a) { // 0xA6D19D } } -uint8 Ridley_Func_90(void) { // 0xA6D242 - R18_ = tilemap_stuff[82]; - R20_ = tilemap_stuff[83]; - R22_ = 64; - R24_ = 64; +uint8 Ridley_Func_90(Point16U *out) { // 0xA6D242 + Rect16U rect = { tilemap_stuff[82], tilemap_stuff[83], 64, 64 }; + if (!projectile_counter) return 0; uint16 v1 = 0; while (1) { int v2 = v1 >> 1; if ((HIBYTE(projectile_type[v2]) & 0xF) == 1 || (HIBYTE(projectile_type[v2]) & 0xF) == 2) { - uint16 v3 = abs16(projectile_x_pos[v2] - R18_); + uint16 v3 = abs16(projectile_x_pos[v2] - rect.x); bool v4 = v3 < projectile_x_radius[v2]; uint16 v5 = v3 - projectile_x_radius[v2]; - if (v4 || v5 < R22_) { - uint16 v6 = abs16(projectile_y_pos[v2] - R20_); + if (v4 || v5 < rect.w) { + uint16 v6 = abs16(projectile_y_pos[v2] - rect.y); v4 = v6 < projectile_y_radius[v2]; uint16 v7 = v6 - projectile_y_radius[v2]; - if (v4 || v7 < R24_) + if (v4 || v7 < rect.h) break; } } @@ -3822,8 +3586,8 @@ uint8 Ridley_Func_90(void) { // 0xA6D242 return 0; } int v8 = v1 >> 1; - R18_ = projectile_x_pos[v8]; - R20_ = projectile_y_pos[v8]; + out->x = projectile_x_pos[v8]; + out->y = projectile_y_pos[v8]; return 1; } @@ -3835,7 +3599,7 @@ void Ridley_Func_91(void) { // 0xA6D2AA if (sign16(v1 - 16)) return; if (!E->ridley_var_0F) - QueueSfx3_Max6(0x21u); + QueueSfx3_Max6(0x21); } E->ridley_var_0E = 0; } @@ -3893,7 +3657,7 @@ void Ridley_Func_94(void) { // 0xA6D3D4 } void Ridley_Func_95(void) { // 0xA6D3D9 - Ridley_Func_D3DC(FUNC16(Enemy_GrappleReact_NoInteract_A6)); + Ridley_Func_D3DC(0x8000); } void Ridley_Func_D3DC(uint16 a) { // 0xA6D3DC @@ -3915,7 +3679,7 @@ void Ridley_Func_96(void) { // 0xA6D3F9 do { int v2 = v1 >> 1; tilemap_stuff[v2 + 21] = 0x8000 - tilemap_stuff[v2 + 21]; - tilemap_stuff[v2 + 18] |= 0x8000u; + tilemap_stuff[v2 + 18] |= 0x8000; v1 += 20; --v0; } while (v0); @@ -3928,8 +3692,7 @@ uint8 Ridley_Func_97(void) { // 0xA6D431 void Ridley_Func_98(void) { // 0xA6D453 uint16 enemy_ptr = Get_Ridley(cur_enemy_index)->base.enemy_ptr; const uint8 *v1 = RomPtr_A0(enemy_ptr); - uint16 v2 = SuitDamageDivision(GET_WORD(v1 + 6)); - Samus_DealDamage(v2); + Samus_DealDamage(SuitDamageDivision(GET_WORD(v1 + 6))); } void Ridley_Func_99(uint16 a) { // 0xA6D467 @@ -3945,34 +3708,28 @@ void Ridley_Func_100(void) { // 0xA6D474 v0 = 0; Enemy_Ridley *E = Get_Ridley(0); uint16 health = E->base.health; - if (health < 0x2328u) { + if (health < 0x2328) { v0 = 1; - if (health < 0x1518u) { + if (health < 0x1518) { v0 = 2; - if (health < 0x708u) + if (health < 0x708) v0 = 3; } } E->ridley_var_12 = v0; - R18_ = v0 - 1; if ((int16)(v0 - 1) >= 0) - Ridley_D495(); + Ridley_D495(v0 - 1); } -void Ridley_D495(void) { // 0xA6D495 +void Ridley_D495(uint16 r18) { // 0xA6D495 if (!palette_change_num) - WriteColorsToPalette(0x1E2, 0xa6, 28 * R18_ - 7062, 0xE); + WriteColorsToPalette(0x1E2, 0xa6, 28 * r18 - 7062, 0xE); } void Ridley_Func_101(void) { // 0xA6D4B5 Enemy_Ridley *E = Get_Ridley(0); - if (E->ridley_var_01 && E->ridley_var_0D >= 0x32u) { - uint16 v1 = 0; - if (E->ridley_var_0D >= 0x46u) - v1 = 2; - R18_ = v1; - Ridley_D495(); - } + if (E->ridley_var_01 && E->ridley_var_0D >= 0x32) + Ridley_D495((E->ridley_var_0D >= 0x46) ? 2 : 0); } void Ridley_Func_102(void) { // 0xA6D4DA @@ -3980,7 +3737,7 @@ void Ridley_Func_102(void) { // 0xA6D4DA v0 = 3584; Enemy_Ridley *E = Get_Ridley(0); - if (E->base.flash_timer >= 2u && (((uint8)enemy_damage_routine_exec_count + 1) & 2) != 0) + if (E->base.flash_timer >= 2 && ((random_enemy_counter + 1) & 2) != 0) v0 = 0; E->ridley_var_0C = v0; } @@ -3990,10 +3747,11 @@ uint8 Ridley_Func_103(uint16 k, uint16 j) { // 0xA6D4F9 return (level_data[prod + (k >> 4)] & 0xF000) != 0; } -void Ridley_Func_104_0(uint16 k, uint16 j) { // 0xA6D523 - Ridley_Func_104(k, j, 0); +void Ridley_Func_104_0(uint16 k, uint16 j, uint16 r18, uint16 r20) { // 0xA6D523 + Ridley_Func_104(k, j, 0, r18, r20); } -void Ridley_Func_104(uint16 k, uint16 j, uint16 a) { // 0xA6D526 + +void Ridley_Func_104(uint16 k, uint16 j, uint16 a, uint16 r18, uint16 r20) { // 0xA6D526 int16 v4; int16 v6; int16 v8; @@ -4002,43 +3760,43 @@ void Ridley_Func_104(uint16 k, uint16 j, uint16 a) { // 0xA6D526 int16 ridley_var_C; int16 v17; - R26_ = a; - R24_ = g_byte_A6D61F[j]; - Ridley_Func_105(k); + uint16 R26 = a; + uint16 r24 = g_byte_A6D61F[j]; + Ridley_Func_105(k, r18, r24, a); Enemy_Ridley *E = Get_Ridley(k); - v4 = E->base.y_pos - R20_; + v4 = E->base.y_pos - r20; if (v4) { if (v4 >= 0) { - uint16 RegWord = SnesDivide(v4, R24_); + uint16 RegWord = SnesDivide(v4, r24); if (!RegWord) RegWord = 1; - R22_ = RegWord; + uint16 r22 = RegWord; ridley_var_C = E->ridley_var_C; bool v14 = 0; if (ridley_var_C >= 0) { - uint16 v15 = ridley_var_C - R26_; + uint16 v15 = ridley_var_C - R26; v15 -= 8; - uint16 v16 = R22_; + uint16 v16 = r22; ridley_var_C = v15 - v16; } - v17 = ridley_var_C - R22_; + v17 = ridley_var_C - r22; if (sign16(v17 + 1280)) v17 = -1280; E->ridley_var_C = v17; } else { - uint16 v5 = SnesDivide(R20_ - E->base.y_pos, R24_); + uint16 v5 = SnesDivide(r20 - E->base.y_pos, r24); if (!v5) v5 = 1; - R22_ = v5; + uint16 r22 = v5; v6 = E->ridley_var_C; bool v7 = 0; if (v6 < 0) { - v8 = R26_ + v6; + v8 = R26 + v6; v8 += 8; v9 = v8; - v6 = R22_ + v9; + v6 = r22 + v9; } - v11 = R22_ + v6; + v11 = r22 + v6; if (!sign16(v11 - 1280)) v11 = 1280; E->ridley_var_C = v11; @@ -4046,7 +3804,7 @@ void Ridley_Func_104(uint16 k, uint16 j, uint16 a) { // 0xA6D526 } } -void Ridley_Func_105(uint16 k) { // 0xA6D5A9 +void Ridley_Func_105(uint16 k, uint16 r18, uint16 r24, uint16 r26) { // 0xA6D5A9 int16 v2; int16 v4; int16 v6; @@ -4056,38 +3814,38 @@ void Ridley_Func_105(uint16 k) { // 0xA6D5A9 int16 v15; Enemy_Ridley *E = Get_Ridley(k); - v2 = E->base.x_pos - R18_; + v2 = E->base.x_pos - r18; if (v2) { if (v2 >= 0) { - uint16 RegWord = SnesDivide(v2, R24_); + uint16 RegWord = SnesDivide(v2, r24); if (!RegWord) RegWord = 1; - R22_ = RegWord; + uint16 r22 = RegWord; ridley_var_B = E->ridley_var_B; bool v12 = 0; if (ridley_var_B >= 0) { - uint16 v13 = ridley_var_B - R26_; + uint16 v13 = ridley_var_B - r26; v13 -= 8; - uint16 v14 = R22_; + uint16 v14 = r22; ridley_var_B = v13 - v14; } - v15 = ridley_var_B - R22_; + v15 = ridley_var_B - r22; if (sign16(v15 + 1280)) v15 = -1280; E->ridley_var_B = v15; } else { - uint16 v3 = SnesDivide(R18_ - E->base.x_pos, R24_); + uint16 v3 = SnesDivide(r18 - E->base.x_pos, r24); if (!v3) v3 = 1; - R22_ = v3; + uint16 r22 = v3; v4 = E->ridley_var_B; if (v4 < 0) { - v6 = R26_ + v4; + v6 = r26 + v4; v6 += 8; v7 = v6; - v4 = R22_ + v7; + v4 = r22 + v7; } - v9 = R22_ + v4; + v9 = r22 + v4; if (!sign16(v9 - 1280)) v9 = 1280; E->ridley_var_B = v9; @@ -4095,39 +3853,39 @@ void Ridley_Func_105(uint16 k) { // 0xA6D5A9 } } -void Ridley_Func_106(uint16 k, uint16 j) { // 0xA6D62F +void Ridley_Func_106(uint16 k, uint16 j, uint16 r18, uint16 r20) { // 0xA6D62F int16 v3; int16 v5; int16 v6; int16 ridley_var_C; int16 v9; - R24_ = g_byte_A6D712[j]; - Ridley_Func_107(k); + uint16 r24 = g_byte_A6D712[j]; + Ridley_Func_107(k, r18, r24); Enemy_Ridley *E = Get_Ridley(k); - v3 = E->base.y_pos - R20_; + v3 = E->base.y_pos - r20; if (v3) { if (v3 >= 0) { - uint16 RegWord = SnesDivide(v3, R24_); + uint16 RegWord = SnesDivide(v3, r24); if (!RegWord) RegWord = 1; - R22_ = RegWord; + uint16 r22 = RegWord; ridley_var_C = E->ridley_var_C; if (ridley_var_C >= 0) - ridley_var_C = ridley_var_C - R22_ - R22_; - v9 = ridley_var_C - R22_; + ridley_var_C = ridley_var_C - r22 - r22; + v9 = ridley_var_C - r22; if (sign16(v9 + 1280)) v9 = -1280; E->ridley_var_C = v9; } else { - uint16 v4 = SnesDivide(R20_ - E->base.y_pos, R24_); + uint16 v4 = SnesDivide(r20 - E->base.y_pos, r24); if (!v4) v4 = 1; - R22_ = v4; + uint16 r22 = v4; v5 = E->ridley_var_C; if (v5 < 0) - v5 += R22_ + R22_; - v6 = R22_ + v5; + v5 += r22 + r22; + v6 = r22 + v5; if (!sign16(v6 - 1280)) v6 = 1280; E->ridley_var_C = v6; @@ -4135,130 +3893,60 @@ void Ridley_Func_106(uint16 k, uint16 j) { // 0xA6D62F } } -void Ridley_Func_107(uint16 k) { // 0xA6D6A6 +void Ridley_Func_107(uint16 k, uint16 r18, uint16 r24) { // 0xA6D6A6 Enemy_Ridley *E = Get_Ridley(k); - int16 v2 = E->base.x_pos - R18_; + int16 v2 = E->base.x_pos - r18; if (!v2) return; if (v2 >= 0) { - uint16 RegWord = SnesDivide(v2, R24_); - R22_ = RegWord = RegWord ? RegWord : 1; + uint16 RegWord = SnesDivide(v2, r24); + uint16 r22 = RegWord = RegWord ? RegWord : 1; int16 s = E->ridley_var_B; if (s >= 0) s -= 2 * RegWord; s -= RegWord; E->ridley_var_B = sign16(s + 1280) ? -1280 : s; } else { - uint16 v3 = SnesDivide(R18_ - E->base.x_pos, R24_); - R22_ = v3 ? v3 : 1; + uint16 v3 = SnesDivide(r18 - E->base.x_pos, r24); + uint16 r22 = v3 ? v3 : 1; int16 s = E->ridley_var_B; if (s < 0) - s += 2 * R22_; - s += R22_; + s += 2 * r22; + s += r22; E->ridley_var_B = !sign16(s - 1280) ? 1280 : s; } } -void Ridley_Func_108(uint16 k) { // 0xA6D722 - R22_ = 512; - R28_ = 0; - Ridley_Func_110(k); - Ridley_Func_109(k); - R28_ >>= 1; - R28_ >>= 1; -} - -void Ridley_Func_109(uint16 k) { // 0xA6D734 - int16 v2; - int16 v6; - int16 v10; - - Enemy_Ridley *E = Get_Ridley(k); - if ((int16)(E->base.y_pos - R20_) >= 0) { - v6 = E->ridley_var_C - R22_; - if (sign16(v6 + 1280)) - v6 = -1280; - E->ridley_var_C = v6; - v10 = E->base.y_pos + (int8)(E->ridley_var_C >> 8); - if ((int16)(v10 - R20_) <= 0) { - E->ridley_var_C = 0; - E->base.y_pos = R20_; - ++R28_; - } - } else { - v2 = E->ridley_var_C + R22_; - if (!sign16(v2 - 1280)) - v2 = 1280; - E->ridley_var_C = v2; - v10 = E->base.y_pos + (int8)(E->ridley_var_C >> 8); - if (!sign16(v10 - R20_)) { - E->ridley_var_C = 0; - E->base.y_pos = R20_; - ++R28_; - } - } -} - -void Ridley_Func_110(uint16 k) { // 0xA6D798 - int16 v2; - int16 v6; - int16 v10; - - Enemy_Ridley *E = Get_Ridley(k); - if ((int16)(E->base.x_pos - R18_) >= 0) { - v6 = E->ridley_var_B - R22_; - if (sign16(v6 + 1280)) - v6 = -1280; - E->ridley_var_B = v6; - v10 = E->base.x_pos + (int8)(E->ridley_var_B >> 8); - if ((int16)(v10 - R18_) <= 0) { - E->ridley_var_B = 0; - E->base.x_pos = R18_; - ++R28_; - } - } else { - v2 = R22_ + E->ridley_var_B; - if (!sign16(v2 - 1280)) - v2 = 1280; - E->ridley_var_B = v2; - if (!sign16(E->base.x_pos + (int8)(E->ridley_var_B >> 8) - R18_)) { - E->ridley_var_B = 0; - E->base.x_pos = R18_; - ++R28_; - } - } -} - -void Ridley_Func_111(void) { // 0xA6D800 +void Ridley_Func_111(uint16 r18, uint16 r20, uint16 r22) { // 0xA6D800 Enemy_Ridley *E = Get_Ridley(0); - if (R22_ != E->ridley_var_0B) { - if ((int16)(R22_ - E->ridley_var_0B) >= 0) { + if (r22 != E->ridley_var_0B) { + if ((int16)(r22 - E->ridley_var_0B) >= 0) { uint16 v2 = E->ridley_var_0B + 32; - if (!sign16(v2 - R22_)) - v2 = R22_; + if (!sign16(v2 - r22)) + v2 = r22; E->ridley_var_0B = v2; } else { uint16 v1 = E->ridley_var_0B - 32; - if (sign16(v1 - R22_)) - v1 = R22_; + if (sign16(v1 - r22)) + v1 = r22; E->ridley_var_0B = v1; } } uint16 v3; - if ((R18_ & 0x8000u) != 0) { - v3 = E->ridley_var_0A + R18_; - if (sign16(v3 - R20_)) + if ((r18 & 0x8000) != 0) { + v3 = E->ridley_var_0A + r18; + if (sign16(v3 - r20)) LABEL_13: - v3 = R20_; + v3 = r20; } else { - v3 = E->ridley_var_0A + R18_; - if (!sign16(v3 - R20_)) + v3 = E->ridley_var_0A + r18; + if (!sign16(v3 - r20)) goto LABEL_13; } E->ridley_var_0A = v3; - R18_ = HIBYTE(v3); - E->ridley_var_B = Math_MultBySin(E->ridley_var_0B); - E->ridley_var_C = Math_MultByCos(E->ridley_var_0B); + r18 = HIBYTE(v3); + E->ridley_var_B = Math_MultBySin(E->ridley_var_0B, r18); + E->ridley_var_C = Math_MultByCos(E->ridley_var_0B, r18); } void Ridley_Func_112(void) { // 0xA6D86B @@ -4311,11 +3999,11 @@ void Ridley_Func_112(void) { // 0xA6D86B void Ridley_Func_113(uint16 k) { // 0xA6D914 if (area_index != 2) { Enemy_Ridley *E = Get_Ridley(k); - R18_ = abs16(E->ridley_var_B); + uint16 r18 = abs16(E->ridley_var_B); uint16 v2 = abs16(E->ridley_var_C); - if (v2 < R18_) - v2 = R18_; - if (v2 >= 0x280u) { + if (v2 < r18) + v2 = r18; + if (v2 >= 0x280) { uint16 v3; if (area_index == 2) v3 = 24; @@ -4355,7 +4043,7 @@ void Ridley_Func_115(void) { // 0xA6D97D if (v1 < 0) { E->ridley_var_09 = 32; uint16 v2 = E->ridley_var_07 + 1; - if (v2 >= 0xAu) + if (v2 >= 0xA) v2 = 0; E->ridley_var_07 = v2; } @@ -4363,17 +4051,17 @@ void Ridley_Func_115(void) { // 0xA6D97D void Ridley_Func_116(void) { // 0xA6D9A8 Enemy_Ridley *E = Get_Ridley(0); - R18_ = abs16(E->ridley_var_B); - uint16 v1 = R18_ + abs16(E->ridley_var_C); + uint16 r18 = abs16(E->ridley_var_B); + uint16 v1 = r18 + abs16(E->ridley_var_C); if (v1) { - uint16 v2 = v1 - R18_; - if (sign16(v2 - R18_)) - v2 = R18_; + uint16 v2 = v1 - r18; + if (sign16(v2 - r18)) + v2 = r18; int v5 = (((4 * v2) & 0xF00) >> 8); if (v5 >= 7) v5 = 7; uint16 v6 = g_word_A6D9ED[v5]; - if ((E->ridley_var_C & 0x8000u) == 0) + if ((E->ridley_var_C & 0x8000) == 0) v6 >>= 1; E->ridley_var_08 = v6; } else { @@ -4400,7 +4088,7 @@ void Ridley_Func_118(void) { // 0xA6DA0C v3 = i; v4 = (uint16 *)RomPtr_A6(i); i = *v4; - if ((*v4 & 0x8000u) == 0) + if ((*v4 & 0x8000) == 0) break; } E->ridley_var_06 = i; @@ -4452,43 +4140,24 @@ void Ridley_Func_120(void) { // 0xA6DAD8 ridley_var_10 = 10; } uint16 v2 = g_off_A6DB02[E->ridley_var_07 + ridley_var_10]; - R22_ = E->ridley_var_0C; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - sub_A6DC13(v2); + sub_A6DC13(v2, E->base.x_pos, E->base.y_pos, E->ridley_var_0C); } void sub_A6DB2A(void) { // 0xA6DB2A if ((gEnemyData(0)->properties & kEnemyProps_Invisible) == 0) { - R18_ = tilemap_stuff[82]; - R20_ = tilemap_stuff[83]; - sub_A6DBC2(kRidley_Ilist_DCBA[(uint16)((uint8)((LOBYTE(tilemap_stuff[71]) - + LOBYTE(tilemap_stuff[81]) - + 8) & 0xF0) >> 3) >> 1]); - R20_ = tilemap_stuff[73]; - R18_ = tilemap_stuff[72]; - sub_A6DBC2(0xDC9Eu); - R18_ = tilemap_stuff[62]; - R20_ = tilemap_stuff[63]; - sub_A6DBC2(0xDC9Eu); - R18_ = tilemap_stuff[52]; - R20_ = tilemap_stuff[53]; - sub_A6DBC2(0xDC97u); - R18_ = tilemap_stuff[42]; - R20_ = tilemap_stuff[43]; - sub_A6DBC2(0xDC97u); - R18_ = tilemap_stuff[32]; - R20_ = tilemap_stuff[33]; - sub_A6DBC2(0xDC90u); - R18_ = tilemap_stuff[22]; - R20_ = tilemap_stuff[23]; - sub_A6DBC2(0xDC90u); + sub_A6DBC2(kRidley_Ilist_DCBA[(uint8)((LOBYTE(tilemap_stuff[71]) + LOBYTE(tilemap_stuff[81]) + 8) & 0xF0) >> 4], + tilemap_stuff[82], tilemap_stuff[83]); + sub_A6DBC2(0xDC9E, tilemap_stuff[72], tilemap_stuff[73]); + sub_A6DBC2(0xDC9E, tilemap_stuff[62], tilemap_stuff[63]); + sub_A6DBC2(0xDC97, tilemap_stuff[52], tilemap_stuff[53]); + sub_A6DBC2(0xDC97, tilemap_stuff[42], tilemap_stuff[43]); + sub_A6DBC2(0xDC90, tilemap_stuff[32], tilemap_stuff[33]); + sub_A6DBC2(0xDC90, tilemap_stuff[22], tilemap_stuff[23]); } } -void sub_A6DBC2(uint16 j) { // 0xA6DBC2 - R22_ = Get_Ridley(0)->ridley_var_0C; - sub_A6DC13(j); +void sub_A6DBC2(uint16 j, uint16 x, uint16 y) { // 0xA6DBC2 + sub_A6DC13(j, x, y, Get_Ridley(0)->ridley_var_0C); } uint16 CallBabyMetroidInstr(uint32 ea, uint16 k) { switch (ea) { @@ -4505,10 +4174,10 @@ typedef struct BabyMetroidExecState { uint16 timer; } BabyMetroidExecState; -int BabyMetroid_DBCB_DoubleRetEx(uint16 a) { +static int BabyMetroid_DBCB_DoubleRetEx(uint16 a) { BabyMetroidExecState *st = (BabyMetroidExecState *)&g_ram[a]; - if ((st->ip & 0x8000u) == 0) + if ((st->ip & 0x8000) == 0) return -1; // double ret uint16 v2 = st->ip; const uint16 *v3 = (uint16 *)RomPtr_A6(v2); @@ -4531,29 +4200,25 @@ LABEL_7: return v3[1]; } -void sub_A6DC13(uint16 j) { // 0xA6DC13 +void sub_A6DC13(uint16 j, uint16 r18, uint16 r20, uint16 r22) { // 0xA6DC13 const uint8 *p = RomPtr_A6(j); int n = GET_WORD(p); p += 2; - int v3 = oam_next_ptr; + int idx = oam_next_ptr; do { - int16 v9 = R20_ + (int8)p[2] - layer1_y_pos; + int16 v9 = r20 + (int8)p[2] - layer1_y_pos; if (v9 >= 0 && sign16(v9 - 224)) { - uint16 v10 = R18_ + GET_WORD(p) - layer1_x_pos; - OamEnt *v11 = gOamEnt(v3); - v11->xcoord = v10; - int v12 = v3 >> 1; - if ((v10 & 0x100) != 0) - *(uint16 *)RomPtr_RAM(kOamExtra_Address_And_X8Large[v12]) |= kOamExtra_X8Small_And_Large[v12]; - if (sign16(GET_WORD(p))) - *(uint16 *)RomPtr_RAM(kOamExtra_Address_And_X8Large[v12]) |= kOamExtra_X8Small_And_Large[v12 + 1]; + uint16 x = r18 + GET_WORD(p) - layer1_x_pos; + OamEnt *v11 = gOamEnt(idx); + v11->xcoord = x; v11->ycoord = v9; - *(uint16 *)&v11->charnum = R22_ | GET_WORD(p + 3); - v3 = (v3 + 4) & 0x1FF; + *(uint16 *)&v11->charnum = r22 | GET_WORD(p + 3); + oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)p < 0) * 2) << (2 * ((idx >> 2) & 7)); + idx = (idx + 4) & 0x1FF; } p += 5; } while (--n); - oam_next_ptr = v3; + oam_next_ptr = idx; } uint8 Ridley_Func_121(void) { // 0xA6DE7A @@ -4583,7 +4248,7 @@ uint8 Ridley_Func_121(void) { // 0xA6DE7A return result; } -uint16 Ridley_Func_122(void) { // 0xA6DEA6 +uint16 Ridley_Func_122(Rect16U rect) { // 0xA6DEA6 int16 v2; if (!projectile_counter) @@ -4594,14 +4259,14 @@ uint16 Ridley_Func_122(void) { // 0xA6DEA6 v2 = projectile_type[v1]; if (v2 < 0) { if (sign16((HIBYTE(v2) & 0xF) - 3)) { - uint16 v3 = abs16(projectile_x_pos[v1] - R18_); + uint16 v3 = abs16(projectile_x_pos[v1] - rect.x); bool v4 = v3 < projectile_x_radius[v1]; uint16 v5 = v3 - projectile_x_radius[v1]; - if (v4 || v5 < R22_) { - uint16 v6 = abs16(projectile_y_pos[v1] - R20_); + if (v4 || v5 < rect.w) { + uint16 v6 = abs16(projectile_y_pos[v1] - rect.y); v4 = v6 < projectile_y_radius[v1]; uint16 v7 = v6 - projectile_y_radius[v1]; - if (v4 || v7 < R24_) + if (v4 || v7 < rect.h) break; } } @@ -4611,9 +4276,9 @@ uint16 Ridley_Func_122(void) { // 0xA6DEA6 return 0xffff; } int v8 = result >> 1; - projectile_x_pos[v8] = R18_; - projectile_y_pos[v8] = R20_; - projectile_dir[v8] |= 0x10u; + projectile_x_pos[v8] = rect.x; + projectile_y_pos[v8] = rect.y; + projectile_dir[v8] |= 0x10; return result; } @@ -4630,19 +4295,18 @@ void Ridley_Func_123(uint16 j) { // 0xA6DF08 projectile_dir[v1] = v2; } -uint8 Ridley_Func_124(void) { // 0xA6DF29 - uint16 v0 = abs16(samus_x_pos - R18_); +uint8 Ridley_Func_124(Rect16U rect) { // 0xA6DF29 + uint16 v0 = abs16(samus_x_pos - rect.x); bool v1 = v0 < samus_x_radius; uint16 v2 = v0 - samus_x_radius; - uint8 result = 0; - if (v1 || v2 < R22_) { - uint16 v3 = abs16(samus_y_pos - R20_); + if (v1 || v2 < rect.w) { + uint16 v3 = abs16(samus_y_pos - rect.y); v1 = v3 < samus_y_radius; uint16 v4 = v3 - samus_y_radius; - if (v1 || v4 < R24_) + if (v1 || v4 < rect.h) return 1; } - return result; + return 0; } void sub_A6DF59(void) { // 0xA6DF59 @@ -4684,7 +4348,7 @@ void Ridley_Powerbomb(void) { // 0xA6DFB2 void Ridley_Func_126(void) { // 0xA6DFB7 Enemy_Ridley *E = Get_Ridley(0); - if (!E->base.health && (E->ridley_var_01 & 0x8000u) == 0) { + if (!E->base.health && (E->ridley_var_01 & 0x8000) == 0) { E->ridley_var_01 = -1; E->base.properties |= kEnemyProps_Tangible; E->ridley_var_A = FUNC16(Ridley_Func_63); @@ -4692,14 +4356,10 @@ void Ridley_Func_126(void) { // 0xA6DFB7 } void Ridley_Func_127(void) { // 0xA6DFD9 - R22_ = 14; - R24_ = 14; - R18_ = tilemap_stuff[82]; - R20_ = tilemap_stuff[83]; - if (Ridley_Func_124() & 1) { + Rect16U rect = { tilemap_stuff[82], tilemap_stuff[83], 14, 14 }; + if (Ridley_Func_124(rect)) { Enemy_Ridley *E = Get_Ridley(0); - uint16 v1 = SuitDamageDivision(E->ridley_var_1C); - Samus_DealDamage(v1); + Samus_DealDamage(SuitDamageDivision(E->ridley_var_1C)); samus_invincibility_timer = 96; samus_knockback_timer = 5; knockback_x_dir = (int16)(samus_x_pos - tilemap_stuff[82]) >= 0; @@ -4708,46 +4368,41 @@ void Ridley_Func_127(void) { // 0xA6DFD9 void Ridley_Func_128(void) { // 0xA6E01B Enemy_Ridley *E = Get_Ridley(cur_enemy_index); - R18_ = projectile_x_pos[0] - E->base.x_pos; - R20_ = projectile_y_pos[0] - E->base.y_pos; - R18_ = (uint8)-CalculateAngleFromXY(); + uint16 r18 = (uint8)-CalculateAngleFromXY(projectile_x_pos[0] - E->base.x_pos, projectile_y_pos[0] - E->base.y_pos); uint16 v1 = 4 * projectile_damage[collision_detection_index]; - if (v1 >= 0x300u) + if (v1 >= 0x300) v1 = 768; uint16 a = v1; - R18_ = Math_MultBySin(v1); - if (((E->ridley_var_B ^ R18_) & 0x8000u) != 0) - E->ridley_var_B += R18_; - R18_ = Math_MultByCos(a); - if (((E->ridley_var_C ^ R18_) & 0x8000u) != 0) - E->ridley_var_C += R18_; + r18 = Math_MultBySin(v1, r18); + if (((E->ridley_var_B ^ r18) & 0x8000) != 0) + E->ridley_var_B += r18; + r18 = Math_MultByCos(a, r18); + if (((E->ridley_var_C ^ r18) & 0x8000) != 0) + E->ridley_var_C += r18; } void Ridley_Func_129(void) { // 0xA6E088 if ((Get_Ridley(0)->base.properties & kEnemyProps_Tangible) == 0) { - R22_ = 14; - R24_ = 14; - R18_ = tilemap_stuff[82]; - R20_ = tilemap_stuff[83]; - uint16 v0 = Ridley_Func_122(); - if (!sign16(v0) - || (R22_ = 10, R24_ = 10, R18_ = tilemap_stuff[72], R20_ = tilemap_stuff[73], !sign16(v0 = Ridley_Func_122()))) { - int v1 = v0 >> 1; - R18_ = projectile_x_pos[v1]; - R20_ = projectile_y_pos[v1]; - uint16 v2 = 12; - if ((HIBYTE(projectile_type[v1]) & 0xF) == 1) { - QueueSfx1_Max6(0x3Du); - v2 = 6; - } - SpawnEnemyProjectileWithRoomGfx(0xE509, v2); + uint16 v0 = Ridley_Func_122((Rect16U) { tilemap_stuff[82], tilemap_stuff[83], 14, 14}); + if (sign16(v0)) { + v0 = Ridley_Func_122((Rect16U) { tilemap_stuff[72], tilemap_stuff[73], 10, 10 }); + if (sign16(v0)) + return; } + int v1 = v0 >> 1; + eproj_spawn_pt = (Point16U){ projectile_x_pos[v1], projectile_y_pos[v1] }; + uint16 v2 = 12; + if ((HIBYTE(projectile_type[v1]) & 0xF) == 1) { + QueueSfx1_Max6(0x3D); + v2 = 6; + } + SpawnEnemyProjectileWithRoomGfx(0xE509, v2); } } const uint16 *Ridley_Instr_5(uint16 k, const uint16 *jp) { // 0xA6E4BE Get_Ridley(0)->ridley_var_0F = 89; - QueueSfx2_Max6(0x59u); + QueueSfx2_Max6(0x59); return jp; } @@ -4817,9 +4472,9 @@ const uint16 *Ridley_Instr_8(uint16 k, const uint16 *jp) { // 0xA6E72F void Ridley_Func_131(uint16 k) { // 0xA6E828 Ridley_Func_132(k, 0); - Ridley_Func_132(k, 1u); - Ridley_Func_132(k, 2u); - Ridley_Func_132(k, 3u); + Ridley_Func_132(k, 1); + Ridley_Func_132(k, 2); + Ridley_Func_132(k, 3); } void Ridley_Func_132(uint16 k, uint16 a) { // 0xA6E840 @@ -4828,46 +4483,39 @@ void Ridley_Func_132(uint16 k, uint16 a) { // 0xA6E840 } const uint16 *Ridley_Instr_11(uint16 k, const uint16 *jp) { // 0xA6E84D + uint16 r18; Enemy_Ridley *E = Get_Ridley(0); if (E->ridley_var_10) { - R18_ = E->base.x_pos + 25; - R18_ = samus_x_pos - R18_; - R20_ = E->base.y_pos - 43; - R20_ = samus_y_pos - R20_; - uint16 v4 = (uint8)-(int8)(CalculateAngleFromXY() + 0x80); - if (v4 < 0x50u) { - if (v4 >= 0x15u) + uint16 v4 = (uint8)-(CalculateAngleFromXY(samus_x_pos - (E->base.x_pos + 25), samus_y_pos - (E->base.y_pos - 43)) + 0x80); + if (v4 < 0x50) { + if (v4 >= 0x15) goto LABEL_13; - } else if (v4 < 0xC0u) { + } else if (v4 < 0xC0) { v4 = 80; LABEL_13: - R18_ = v4; + r18 = v4; goto LABEL_14; } v4 = 21; goto LABEL_13; } - R18_ = E->base.x_pos - 25; - R18_ = samus_x_pos - R18_; - R20_ = E->base.y_pos - 43; - R20_ = samus_y_pos - R20_; uint16 v3; - v3 = (uint8)-(int8)(CalculateAngleFromXY() + 0x80); - if (v3 >= 0xB0u) { - if (v3 < 0xEBu) + v3 = (uint8)-(CalculateAngleFromXY(samus_x_pos - (E->base.x_pos - 25), samus_y_pos - (E->base.y_pos - 43)) + 0x80); + if (v3 >= 0xB0) { + if (v3 < 0xEB) goto LABEL_7; LABEL_6: v3 = 235; goto LABEL_7; } - if (v3 < 0x40u) + if (v3 < 0x40) goto LABEL_6; v3 = 176; LABEL_7: - R18_ = v3; + r18 = v3; LABEL_14: - E->ridley_var_19 = Math_MultBySin(0x500u); - E->ridley_var_1A = Math_MultByCos(0x500u); + E->ridley_var_19 = Math_MultBySin(0x500, r18); + E->ridley_var_1A = Math_MultByCos(0x500, r18); return jp; } @@ -4905,12 +4553,12 @@ void CeresSteam_Init(void) { // 0xA6EFB1 Enemy_CeresSteam *E = Get_CeresSteam(cur_enemy_index); E->base.vram_tiles_index = 0; E->base.properties |= kEnemyProps_DisableSamusColl; - E->base.extra_properties |= 4u; + E->base.extra_properties |= 4; E->base.instruction_timer = 1; E->base.timer = 0; E->base.palette_index = 2560; E->csm_var_D = (NextRandom() & 0x1F) + 1; - int v1 = (uint16)(2 * E->csm_parameter_1) >> 1; + int v1 = E->csm_parameter_1; E->base.current_instruction = g_off_A6EFF5[v1]; E->csm_var_A = g_off_A6F001[v1]; } @@ -4930,15 +4578,11 @@ void CeresSteam_Main(void) { // 0xA6F00D } void CeresSteam_Func_1(uint16 k) { // 0xA6F019 - EnemySpawnData *v3; - Enemy_CeresSteam *E = Get_CeresSteam(k); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - CalcCeresSteamPos_Mode7(); - v3 = gEnemySpawnData(cur_enemy_index); - v3->xpos2 = R18_ - E->base.x_pos; - v3->ypos2 = R20_ - E->base.y_pos; + Point16U pt = CalcCeresSteamPos_Mode7((Point16U) { E->base.x_pos, E->base.y_pos }); + EnemySpawnData *v3 = gEnemySpawnData(cur_enemy_index); + v3->xpos2 = pt.x - E->base.x_pos; + v3->ypos2 = pt.y - E->base.y_pos; } void CeresSteam_Touch(void) { // 0xA6F03F @@ -4961,13 +4605,13 @@ const uint16 *CeresSteam_Instr_2(uint16 k, const uint16 *jp) { // 0xA6F127 const uint16 *CeresSteam_Instr_3(uint16 k, const uint16 *jp) { // 0xA6F135 Enemy_CeresSteam *E = Get_CeresSteam(k); - E->base.properties &= 0xFAFFu; + E->base.properties &= 0xFAFF; return jp; } const uint16 *CeresDoor_Instr_6(uint16 k, const uint16 *jp) { // 0xA6F63E Enemy_CeresDoor *E = Get_CeresDoor(k); - if (abs16(E->base.x_pos - samus_x_pos) >= 0x30u || abs16(E->base.y_pos - samus_y_pos) >= 0x30u) + if (abs16(E->base.x_pos - samus_x_pos) >= 0x30 || abs16(E->base.y_pos - samus_y_pos) >= 0x30) return INSTR_RETURN_ADDR(*jp); else return jp + 1; @@ -4989,7 +4633,7 @@ const uint16 *CeresDoor_Instr_8(uint16 k, const uint16 *jp) { // 0xA6F678 void CeresDoor_Func_6b(void) { // 0xA6F67F if (ceres_status) - ceres_status = FUNC16(Enemy_GrappleReact_NoInteract_A6); + ceres_status = 0x8000; } const uint16 *CeresSteam_Instr_4(uint16 k, const uint16 *jp) { // 0xA6F68B @@ -5027,7 +4671,7 @@ const uint16 *CeresDoor_Instr_2(uint16 k, const uint16 *jp) { // 0xA6F6B3 } const uint16 *CeresDoor_Instr_7(uint16 k, const uint16 *jp) { // 0xA6F6BD - QueueSfx3_Max6(0x2Cu); + QueueSfx3_Max6(0x2C); return jp; } @@ -5038,7 +4682,7 @@ void CeresDoor_Init(void) { // 0xA6F6C5 E->base.timer = 0; E->base.vram_tiles_index = 0; E->base.palette_index = 1024; - int v2 = (uint16)(2 * E->cdr_parameter_1) >> 1; + int v2 = E->cdr_parameter_1; E->cdr_var_A = g_off_A6F72B[v2]; E->base.current_instruction = g_off_A6F52C[v2]; E->cdr_var_B = 0; @@ -5090,16 +4734,16 @@ void CeresDoor_Main(void) { // 0xA6F765 } void CeresDoor_Func_2(void) { // 0xA6F76B - CeresDoor_F773(0x14u); + CeresDoor_F773(0x14); } void CeresDoor_Func_3(void) { // 0xA6F770 - CeresDoor_F773(0x1Du); + CeresDoor_F773(0x1D); } void CeresDoor_F773(uint16 j) { // 0xA6F773 - if (ceres_status >= 2u && !earthquake_timer) { - if ((random_number & 0xFFFu) < 0x80) { + if (ceres_status >= 2 && !earthquake_timer) { + if ((random_number & 0xFFF) < 0x80) { earthquake_timer = 4; earthquake_type = j + 6; } else { @@ -5119,7 +4763,7 @@ void CeresDoor_Func_4(void) { // 0xA6F7A5 void CeresDoor_Func_5(uint16 k) { // 0xA6F7BD CeresDoor_Func_7(); - if (ceres_status >= 2u) { + if (ceres_status >= 2) { Enemy_CeresDoor *E = Get_CeresDoor(k); E->cdr_var_A = FUNC16(CeresDoor_Func_6); E->cdr_var_D = 48; @@ -5131,27 +4775,26 @@ void CeresDoor_Func_5(uint16 k) { // 0xA6F7BD void CeresDoor_Func_6(uint16 k) { // 0xA6F7DC Enemy_CeresDoor *E = Get_CeresDoor(k); - bool v3 = (--E->cdr_var_D & 0x8000u) != 0; + bool v3 = (--E->cdr_var_D & 0x8000) != 0; if (v3) { E->base.properties |= kEnemyProps_Invisible; E->cdr_var_A = FUNC16(CeresDoor_Func_7); CeresDoor_Func_6b(); } else { Enemy_CeresDoor *E0 = Get_CeresDoor(0); - v3 = (--E0->cdr_var_E & 0x8000u) != 0; + v3 = (--E0->cdr_var_E & 0x8000) != 0; if (v3) { E0->cdr_var_E = 4; - v3 = (--E0->cdr_var_F & 0x8000u) != 0; + v3 = (--E0->cdr_var_F & 0x8000) != 0; if (v3) E0->cdr_var_F = 3; int v5 = (uint16)(4 * E0->cdr_var_F) >> 1; - R18_ = E->base.x_pos + g_word_A6F840[v5]; - R20_ = E->base.y_pos + g_word_A6F840[v5 + 1]; + eproj_spawn_pt = (Point16U){ E->base.x_pos + g_word_A6F840[v5], E->base.y_pos + g_word_A6F840[v5 + 1] }; uint16 v6 = 3; - if (NextRandom() < 0x4000u) + if (NextRandom() < 0x4000) v6 = 12; SpawnEnemyProjectileWithRoomGfx(0xE509, v6); - QueueSfx2_Max6(0x25u); + QueueSfx2_Max6(0x25); } } } @@ -5160,18 +4803,18 @@ void CeresDoor_Func_7(void) { // 0xA6F850 CeresDoor_Func_8(); if (!palette_change_num) WriteColorsToPalette( - 0x52u, + 0x52, 0xa6, 2 * (nmi_frame_counter_word & 0x38) - 0x78F, - 6u); + 6); } void CeresDoor_Func_8(void) { // 0xA6F8F1 - QueueMode7Transfers(0xA6, g_off_A6F900[(uint8)(nmi_frame_counter_word & 2) >> 1]); + QueueMode7Transfers(0xA6, g_off_A6F900[(nmi_frame_counter_word & 2) >> 1]); } void Zebetites_Init(void) { // 0xA6FB72 Enemy_Zebetites *E = Get_Zebetites(cur_enemy_index); - E->base.properties |= 0xA000u; + E->base.properties |= 0xA000; E->base.instruction_timer = 1; E->base.timer = 0; E->base.palette_index = 1024; @@ -5181,12 +4824,12 @@ void Zebetites_Init(void) { // 0xA6FB72 if (E->zebet_parameter_1) v1 = FUNC16(Zebetites_Func_2); E->zebet_var_A = v1; - R18_ = 0; - R18_ = (R18_ << 1) | CheckEventHappened(5u); - R18_ = (R18_ << 1) | CheckEventHappened(4u); - R18_ = (R18_ << 1) | CheckEventHappened(3u); - uint16 v2 = R18_; - E->zebet_var_D = R18_; + uint16 r18 = 0; + r18 = (r18 << 1) | CheckEventHappened(5); + r18 = (r18 << 1) | CheckEventHappened(4); + r18 = (r18 << 1) | CheckEventHappened(3); + uint16 v2 = r18; + E->zebet_var_D = r18; if (sign16(v2 - 4)) { int v3 = v2; E->zebet_var_F = g_word_A6FC03[v3]; @@ -5222,7 +4865,7 @@ void Zebetites_Main(void) { // 0xA6FC33 void Zebetites_Func_1(uint16 k) { // 0xA6FC41 Enemy_Zebetites *E = Get_Zebetites(k); - if ((E->zebet_var_F & 0x8000u) != 0) { + if ((E->zebet_var_F & 0x8000) != 0) { uint16 new_k = Zebetites_Func_9(); Get_Zebetites(new_k)->zebet_parameter_2 = k; Get_Zebetites(k)->zebet_parameter_2 = new_k; @@ -5265,10 +4908,10 @@ void Zebetites_Func_6(void) { // 0xA6FCAA Enemy_Zebetites *E = Get_Zebetites(cur_enemy_index); v1 = E->zebet_var_D + 1; E->zebet_var_D = v1; - R18_ = v1; - Zebetites_Func_7(3u, (R18_ >> 0) & 1); - Zebetites_Func_7(4u, (R18_ >> 1) & 1); - Zebetites_Func_7(5u, (R18_ >> 2) & 1); + uint16 r18 = v1; + Zebetites_Func_7(3, (r18 >> 0) & 1); + Zebetites_Func_7(4, (r18 >> 1) & 1); + Zebetites_Func_7(5, (r18 >> 2) & 1); } void Zebetites_Func_7(uint16 j, uint8 a) { // 0xA6FCCB @@ -5303,7 +4946,7 @@ void Zebetites_Func_5(void) { // 0xA6FD09 } int v3 = v0 >> 1; uint16 v4 = g_off_A6FD4A[v3]; - if ((E->zebet_var_F & 0x8000u) != 0) + if ((E->zebet_var_F & 0x8000) != 0) v4 = g_off_A6FD54[v3]; E->base.current_instruction = v4; E->base.instruction_timer = 1; @@ -5313,9 +4956,9 @@ void Zebetites_Func_5(void) { // 0xA6FD09 void Zebetites_Func_4(void) { // 0xA6FD5E if (!palette_change_num && !Get_Zebetites(cur_enemy_index)->zebet_parameter_1) { Enemy_Zebetites *E = Get_Zebetites(0); - uint16 v1 = ((uint8)E->zebet_var_C + 1) & 7; + uint16 v1 = (E->zebet_var_C + 1) & 7; E->zebet_var_C = v1; - WriteColorsToPalette(0x158, 0xa6, 4 * v1 - 0x279, 2u); + WriteColorsToPalette(0x158, 0xa6, 4 * v1 - 0x279, 2); } } @@ -5324,10 +4967,10 @@ void Zebetites_Touch(void) { // 0xA6FDA7 } void Zebetites_Shot(void) { // 0xA6FDAC - QueueSfx3_Max6(9u); + QueueSfx3_Max6(9); NormalEnemyShotAiSkipDeathAnim_CurEnemy(); Enemy_Zebetites *E = Get_Zebetites(cur_enemy_index); Enemy_Zebetites *G = Get_Zebetites(E->zebet_parameter_2); G->base.health = E->base.health; G->base.flash_timer = E->base.flash_timer; -} \ No newline at end of file +} diff --git a/src/sm_a7.c b/src/sm_a7.c index 6520b42..0399c98 100644 --- a/src/sm_a7.c +++ b/src/sm_a7.c @@ -5,12 +5,12 @@ #include "enemy_types.h" #include "sm_rtl.h" +#undef r18 #define kKraid_Palette2 ((uint16*)RomFixedPtr(0xa786c7)) #define kKraid_Palette2 ((uint16*)RomFixedPtr(0xa786c7)) #define kKraid_BgTargetPalette3 ((uint16*)RomFixedPtr(0xa7aaa6)) #define g_word_A7ACB3 ((uint16*)RomFixedPtr(0xa7acb3)) -#define g_off_A7ACC5 ((uint16*)RomFixedPtr(0xa7acc5)) #define g_stru_A796D2 (*(KraidInstrList*)RomFixedPtr(0xa796d2)) #define g_stru_A796DA (*(KraidInstrList*)RomFixedPtr(0xa796da)) #define g_word_A7B161 ((uint16*)RomFixedPtr(0xa7b161)) @@ -45,11 +45,6 @@ #define g_word_A7CA61 ((uint16*)RomFixedPtr(0xa7ca61)) #define g_off_A7F55F ((uint16*)RomFixedPtr(0xa7f55f)) - - - - - static const uint16 g_word_A7A916 = 0x120; static const uint16 g_word_A7A918 = 0xa0; static const uint16 g_word_A7A91A = 0x40; @@ -58,8 +53,6 @@ static const uint16 g_word_A7A920 = 3; static const uint16 g_word_A7A922 = 4; static const uint16 g_word_A7A926 = 0x8000; static const uint16 g_word_A7A928 = 3; - - static const uint16 g_word_A7CD73 = 0x600; static const uint16 g_word_A7CD75 = 0; static const uint16 g_word_A7CD77 = 0x1000; @@ -100,6 +93,31 @@ static const uint16 g_word_A7F4D7 = 0; static const uint16 g_word_A7F4D9 = 0; static const uint16 g_word_A7F4DB = 0x1000; +void Kraid_SpawnExplosionEproj(uint16 k); +void Kraid_SpawnPlmToClearCeiling(void); +void Kraid_SpawnRandomQuakeProjs(void); +void Kraid_ClearSomeSpikes(void); +void Kraid_SetupGfxWithTilePrioClear(uint16 r18); +void Kraid_Shot_Mouth(void); +void Kraid_Death_UpdateBG2TilemapBottomHalf(void); +void Kraid_Death_UpdateBG2TilemapTopHalf(void); +void Kraid_Palette_Handling(void); +void Kraid_Shot_Body(void); +void Kraid_Enemy_Touch(void); +void Kraid_UpdateBG2TilemapBottomHalf(void); +void Kraid_UpdateBg2TilemapTopHalf(void); +void Kraid_HurtFlash_Handling(void); +void Kraid_HealthBasedPaletteHandling(void); +void Kraid_Shot_GlowHisEye(void); +void Kraid_Shot_MouthIsOpen(void); +void Kraid_Shot_UnglowEye(void); +void Kraid_HandleFirstPhase(void); +void Kraid_TransferTopHalfToVram(void); +void Kraid_RestrictSamusXtoFirstScreen_2(void); +void Kraid_EnemyTouch_Lint(uint16 k); +void CallKraidSinkTableFunc(uint32 ea); +void CallKraidFunc(uint32 ea); + void CallEnemyInstrExtFunc(uint32 ea, uint16 k) { switch (ea) { case fnPhantoon_Func_1: Phantoon_Func_1(); return; @@ -139,7 +157,7 @@ void Enemy_NormalFrozenAI_A7(void) { // 0xA78041 const uint16 *Kraid_Instr_9(uint16 k, const uint16 *jp) { // 0xA78A8F Enemy_Kraid *E = Get_Kraid(0); if ((int16)(E->base.health - E->kraid_healths_8ths[3]) < 0) { - Enemy_Kraid *E1 = Get_Kraid(0x40u); + Enemy_Kraid *E1 = Get_Kraid(0x40); if (sign16(E1->base.current_instruction + 0x75BF)) return INSTR_RETURN_ADDR(addr_kKraid_Ilist_8A41); } @@ -150,6 +168,19 @@ void Kraid_Touch_ArmFoot(void) { // 0xA7948B NormalEnemyTouchAi(); } +void Kraid_Func_1(void) { // 0xA794A4 + extra_samus_x_displacement = 4; + extra_samus_y_displacement = -8; +} + +void Kraid_Touch(void) { // 0xA7949F + NormalEnemyTouchAiSkipDeathAnim_CurEnemy(); +} + +void Kraid_Shot(void) { // 0xA794B1 + NormalEnemyShotAi(); +} + void KraidsArm_Touch(void) { // 0xA79490 if (!samus_invincibility_timer) { Kraid_Func_1(); @@ -158,22 +189,10 @@ void KraidsArm_Touch(void) { // 0xA79490 } } -void Kraid_Touch(void) { // 0xA7949F - NormalEnemyTouchAiSkipDeathAnim_CurEnemy(); -} - -void Kraid_Func_1(void) { // 0xA794A4 - extra_samus_x_displacement = 4; - extra_samus_y_displacement = -8; -} - -void Kraid_Shot(void) { // 0xA794B1 - NormalEnemyShotAi(); -} void Kraid_Arm_Shot(uint16 j) { // 0xA794B6 Kraid_SpawnExplosionEproj(j); - projectile_dir[j >> 1] |= 0x10u; + projectile_dir[j >> 1] |= 0x10; } void sub_A7A92A(void) { // 0xA7A92A @@ -228,14 +247,13 @@ void Kraid_Init(void) { // 0xA7A959 E->kraid_min_y_pos_eject = 324; uint16 v7 = 0; uint16 v8 = E->base.health >> 3; - R18_ = v8; + uint16 r18 = v8; do { Get_Kraid(v7)->kraid_healths_8ths[0] = v8; - v8 += R18_; + v8 += r18; v7 += 2; } while ((int16)(v7 - 16) < 0); - R18_ = -8193; - Kraid_SetupGfxWithTilePrioClear(); + Kraid_SetupGfxWithTilePrioClear(0xDFFF); uint16 v10 = E->base.health >> 2; E->kraid_healths_4ths[0] = v10; uint16 v11 = E->kraid_healths_4ths[0] + v10; @@ -252,7 +270,7 @@ void Kraid_Init(void) { // 0xA7A959 E->kraid_next = FUNC16(Kraid_RaiseKraidThroughFloor); E->kraid_var_C = 64; DisableMinimapAndMarkBossRoomAsExplored(); - for (j = 62; (j & 0x8000u) == 0; j -= 2) + for (j = 62; (j & 0x8000) == 0; j -= 2) tilemap_stuff[(j >> 1) + 2016] = 824; earthquake_type = 5; uint16 v14 = 0; @@ -263,7 +281,7 @@ void Kraid_Init(void) { // 0xA7A959 } } -void Kraid_SetupGfxWithTilePrioClear(void) { // 0xA7AAC6 +void Kraid_SetupGfxWithTilePrioClear(uint16 r18) { // 0xA7AAC6 DecompressToMem(0xB9FA38, g_ram + 0x4000); DecompressToMem(0xB9FE3E, g_ram + 0x2000); Enemy_Kraid *E = Get_Kraid(0); @@ -276,7 +294,7 @@ void Kraid_SetupGfxWithTilePrioClear(void) { // 0xA7AAC6 } while ((int16)(v1 - 1536) < 0); uint16 v2 = 0; do { - tilemap_stuff[v2] = R18_ & ram4000.xray_tilemaps[v2]; + tilemap_stuff[v2] = r18 & ram4000.xray_tilemaps[v2]; ++v2; } while ((int16)(v2 * 2 - 2048) < 0); } @@ -342,7 +360,7 @@ void KraidsFoot_Init(void) { // 0xA7ABF8 Kraid_SetEnemyPropsToDead(); } else { uint16 palette_index = Get_Kraid(0)->base.palette_index; - Enemy_Kraid *E = Get_Kraid(0x140u); + Enemy_Kraid *E = Get_Kraid(0x140); E->base.palette_index = palette_index; E->base.current_instruction = addr_kKraid_Ilist_86E7; E->base.instruction_timer = 1; @@ -351,66 +369,6 @@ void KraidsFoot_Init(void) { // 0xA7ABF8 } } -void CallKraidFunc(uint32 ea) { - uint16 k = cur_enemy_index; - switch (ea) { - case fnKraid_GetsBig_BreakCeilingPlatforms: Kraid_GetsBig_BreakCeilingPlatforms(); return; // 0x9bc35 - case fnKraid_GetsBig_SetBG2TilemapPrioBits: Kraid_GetsBig_SetBG2TilemapPrioBits(); return; // 0x9bde6 - case fnKraid_GetsBig_FinishUpdateBg2Tilemap: Kraid_GetsBig_FinishUpdateBg2Tilemap(); return; // 0x9be51 - case fnKraid_GetsBig_DrawRoomBg: Kraid_GetsBig_DrawRoomBg(); return; // 0x9bee5 - case fnKraid_GetsBig_FadeInRoomBg: Kraid_GetsBig_FadeInRoomBg(); return; // 0x9c08c - case fnKraid_Mainloop_Thinking: Kraid_Mainloop_Thinking(); return; // 0x9c1b8 - case fnKraid_GetsBig_Thinking: Kraid_GetsBig_Thinking(); return; // 0x9c207 - case fnKraid_Shot_MouthIsOpen: Kraid_Shot_MouthIsOpen(); return; // 0x9c256 - case fnKraid_InitEyeGlowing: Kraid_InitEyeGlowing(); return; // 0x9cf64 - case fnKraid_Shot_GlowHisEye: Kraid_Shot_GlowHisEye(); return; // 0x9cf9f - case fnKraid_Shot_UnglowEye: Kraid_Shot_UnglowEye(); return; // 0x9d0b4 - case fnKraidLint_ProduceLint: KraidLint_ProduceLint(k); return; // 0x9d371 - case fnKraidLint_FireLint: KraidLint_FireLint(k); return; // 0x9d44f - case fnKraidFingernail_WaitForLintXpos: KraidFingernail_WaitForLintXpos(k); return; // 0x9d556 - case fnKraid_AlignEnemyToKraid: Kraid_AlignEnemyToKraid(k); return; // 0x9d5b5 - case fnKraidEnemy_HandleFunctionTimer: KraidEnemy_HandleFunctionTimer(k); return; // 0x9d5e5 - case fnKraidEnemy_DecrementEnemyFunctionTimer: KraidEnemy_DecrementEnemyFunctionTimer(); return; // 0x9d61c - case fnKraidFoot_FirstPhase_Thinking: KraidFoot_FirstPhase_Thinking(k); return; // 0x9d66a - case fnKraidEnemy_ProcessInstrEnemyTimer: KraidEnemy_ProcessInstrEnemyTimer(k); return; // 0x9d67d - case fnKraidsFoot_SecondPhase_Thinking: KraidsFoot_SecondPhase_Thinking(); return; // 0x9d8b2 - case fnKraidsFoot_SecondPhase_WalkingBackwards: KraidsFoot_SecondPhase_WalkingBackwards(); return; // 0x9da2d - case fnKraidsFoot_SecondPhaseSetup_WalkToStartPt: KraidsFoot_SecondPhaseSetup_WalkToStartPt(); return; // 0x9daa2 - case fnKraidsFoot_SecondPhase_Init: KraidsFoot_SecondPhase_Init(); return; // 0x9db2a - case fnKraidsFoot_SecondPhase_WalkForward: KraidsFoot_SecondPhase_WalkForward(); return; // 0x9db40 - case fnKraid_Main_AttackWithMouthOpen: Kraid_Main_AttackWithMouthOpen(); return; // 0x9dbe0 - case fnKraidsFingernail_Init: KraidsFingernail_Init(); return; // 0x9df94 - case fnKraidsFingernail_Fire: KraidsFingernail_Fire(k); return; // 0x9e1ac - case fnKraidsFoot_PrepareToLungeForward: KraidsFoot_PrepareToLungeForward(); return; // 0x9e312 - case fnKraidsFoot_FirstPhase_RetreatFromLunge: KraidsFoot_FirstPhase_RetreatFromLunge(); return; // 0x9e43a - case fnKraid_GetsBig_ReleaseCamera: Kraid_GetsBig_ReleaseCamera(); return; // 0x9e6a7 - case fnKraid_Death_Init: Kraid_Death_Init(); return; // 0x9ec0b - case fnKraid_Death_Fadeout: Kraid_Death_Fadeout(); return; // 0x9ed75 - case fnKraid_Death_UpdateBG2TilemapTopHalf: Kraid_Death_UpdateBG2TilemapTopHalf(); return; // 0x9ef19 - case fnKraid_Death_UpdateBG2TilemapBottomHalf: Kraid_Death_UpdateBG2TilemapBottomHalf(); return; // 0x9ef92 - case fnKraid_Death_SinkThroughFloor: Kraid_Death_SinkThroughFloor(); return; // 0x9f074 - case fnKraid_FadeInBg_ClearBg2TilemapTopHalf: Kraid_FadeInBg_ClearBg2TilemapTopHalf(); return; // 0x9f369 - case fnKraid_FadeInBg_ClearBg2TilemapBottomHalf: Kraid_FadeInBg_ClearBg2TilemapBottomHalf(); return; // 0x9f3ed - case fnKraid_FadeInBg_LoadBg3Tiles1of4: Kraid_FadeInBg_LoadBg3Tiles1of4(); return; // 0x9f448 - case fnKraid_FadeInBg_LoadBg3Tiles2of4: Kraid_FadeInBg_LoadBg3Tiles2of4(); return; // 0x9f4ad - case fnKraid_FadeInBg_LoadBg3Tiles3of4: Kraid_FadeInBg_LoadBg3Tiles3of4(); return; // 0x9f507 - case fnKraid_FadeInBg_LoadBg3Tiles4of4: Kraid_FadeInBg_LoadBg3Tiles4of4(); return; // 0x9f561 - case fnKraid_FadeInBg_FadeInBp6: Kraid_FadeInBg_FadeInBp6(); return; // 0x9f5bb - case fnKraid_FadeInBg_SetEnemyDead_KraidWasAlive: Kraid_FadeInBg_SetEnemyDead_KraidWasAlive(); return; // 0x9f62d - case fnKraid_FadeInBg_SetEnemyDead_KraidWasDead: Kraid_FadeInBg_SetEnemyDead_KraidWasDead(); return; // 0x9f65b - case fnKraid_RestrictSamusXtoFirstScreen: Kraid_RestrictSamusXtoFirstScreen(k); return; // 0x9f694 - case fnKraid_RaiseKraidThroughFloor: Kraid_RaiseKraidThroughFloor(k); return; // 0x9f6a7 - case fnKraid_Raise_LoadTilemapBottomAndShake: Kraid_Raise_LoadTilemapBottomAndShake(); return; // 0x9f71f - case fnKraid_Raise_SpawnRandomEarthquakeProjs16: Kraid_Raise_SpawnRandomEarthquakeProjs16(); return; // 0x9f7b8 - case fnKraid_Raise_SpawnRandomEarthquakeProjs8: Kraid_Raise_SpawnRandomEarthquakeProjs8(); return; // 0x9f805 - case fnKraid_Raise_Handler: Kraid_Raise_Handler(); return; // 0x9f852 - case fnKraidLint_ChargeLint: KraidLint_ChargeLint(k); return; // 0xa7b868 - case fnnullsub_234: return; // 0xa7ba2d - case fnKraidsFoot_FirstPhase_LungeForward: KraidsFoot_FirstPhase_LungeForward(); return; // 0xa7bf5d - case fnnullsub_347: return; - default: Unreachable(); - } -} void Kraid_Main(void) { // 0xA7AC21 Kraid_Shot_Mouth(); Kraid_Palette_Handling(); @@ -431,51 +389,39 @@ void Kraid_GetsBig_BreakCeilingPlatforms(void) { // 0xA7AC4D Enemy_Kraid *E = Get_Kraid(0); if ((E->base.y_pos & 2) != 0) v0 = -1; - R18_ = v0; E->base.x_pos += v0; --E->base.y_pos; if ((E->base.y_pos & 3) != 0 || (kraid_var_F = E->kraid_var_F, (int16)(kraid_var_F - 18) >= 0)) { } else { - static const SpawnHardcodedPlmArgs unk_A7ACDB = { 0x02, 0x12, 0xb7a3 }; - static const SpawnHardcodedPlmArgs unk_A7ACE6 = { 0x03, 0x12, 0xb7ab }; - static const SpawnHardcodedPlmArgs unk_A7ACF1 = { 0x04, 0x12, 0xb7b3 }; - static const SpawnHardcodedPlmArgs unk_A7ACFC = { 0x05, 0x12, 0xb7ab }; - static const SpawnHardcodedPlmArgs unk_A7AD07 = { 0x06, 0x12, 0xb7b3 }; - static const SpawnHardcodedPlmArgs unk_A7AD12 = { 0x0a, 0x12, 0xb7b3 }; - static const SpawnHardcodedPlmArgs unk_A7AD1D = { 0x0b, 0x12, 0xb7ab }; - static const SpawnHardcodedPlmArgs unk_A7AD28 = { 0x0c, 0x12, 0xb7b3 }; - static const SpawnHardcodedPlmArgs unk_A7AD33 = { 0x0d, 0x12, 0xb7ab }; - SpawnEnemyProjectileWithGfx(g_word_A7ACB3[kraid_var_F >> 1], cur_enemy_index, addr_kEproj_RocksFallingKraidCeiling); - R18_ = g_off_A7ACC5[E->kraid_var_F >> 1]; switch (E->kraid_var_F >> 1) { case 0: - SpawnHardcodedPlm(&unk_A7AD07); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x06, 0x12, 0xb7b3 }); break; case 1: - SpawnHardcodedPlm(&unk_A7AD33); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0d, 0x12, 0xb7ab }); break; case 2: - SpawnHardcodedPlm(&unk_A7ACDB); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x12, 0xb7a3 }); break; case 3: - SpawnHardcodedPlm(&unk_A7AD12); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0a, 0x12, 0xb7b3 }); break; case 4: - SpawnHardcodedPlm(&unk_A7ACFC); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x05, 0x12, 0xb7ab }); break; case 5: - SpawnHardcodedPlm(&unk_A7AD28); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0c, 0x12, 0xb7b3 }); break; case 6: - SpawnHardcodedPlm(&unk_A7ACE6); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x03, 0x12, 0xb7ab }); break; case 7: - SpawnHardcodedPlm(&unk_A7AD1D); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0b, 0x12, 0xb7ab }); break; case 8: - SpawnHardcodedPlm(&unk_A7ACF1); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x04, 0x12, 0xb7b3 }); break; } E->kraid_var_F += 2; @@ -487,25 +433,25 @@ void Kraid_GetsBig_BreakCeilingPlatforms(void) { // 0xA7AC4D void Kraid_GetsBig_SetBG2TilemapPrioBits(void) { // 0xA7AD3A uint16 v0 = 0; do { - tilemap_stuff[v0 >> 1] |= 0x2000u; + tilemap_stuff[v0 >> 1] |= 0x2000; v0 += 2; } while ((int16)(v0 - 4096) < 0); - Enemy_Kraid *E = Get_Kraid(0x40u); - E->base.properties &= ~0x400u; + Enemy_Kraid *E = Get_Kraid(0x40); + E->base.properties &= ~0x400; Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_GetsBig_FinishUpdateBg2Tilemap); Kraid_UpdateBg2TilemapTopHalf(); } void Kraid_GetsBig_FinishUpdateBg2Tilemap(void) { // 0xA7AD61 Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_GetsBig_DrawRoomBg); - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); E5->base.instruction_timer = 1; E5->base.current_instruction = addr_kKraid_Ilist_86ED; Enemy_Kraid *E2 = Get_Kraid(0x80); E2->base.current_instruction = addr_kKraid_Ilist_8B04; - Enemy_Kraid *E3 = Get_Kraid(0xC0u); + Enemy_Kraid *E3 = Get_Kraid(0xC0); E3->base.current_instruction = addr_kKraid_Ilist_8B04; - Enemy_Kraid *E = Get_Kraid(0x100u); + Enemy_Kraid *E = Get_Kraid(0x100); E->base.current_instruction = addr_kKraid_Ilist_8B04; E2->base.spritemap_pointer = addr_kKraid_Sprmap_8C6C; E3->base.spritemap_pointer = addr_kKraid_Sprmap_8C6C; @@ -513,14 +459,6 @@ void Kraid_GetsBig_FinishUpdateBg2Tilemap(void) { // 0xA7AD61 Kraid_UpdateBG2TilemapBottomHalf(); } -void Kraid_GetsBig_DrawRoomBg(void) { // 0xA7AD8E - Enemy_Kraid *E = Get_Kraid(0); - E->kraid_var_A = FUNC16(Kraid_GetsBig_FadeInRoomBg); - E->kraid_var_E = 0; - E->kraid_var_F = 0; - Kraid_DrawRoomBg(); -} - void Kraid_DrawRoomBg(void) { // 0xA7AD9A VramWriteEntry *v3; @@ -541,6 +479,27 @@ void Kraid_DrawRoomBg(void) { // 0xA7AD9A vram_write_queue_tail = v2 + 7; } +void Kraid_GetsBig_DrawRoomBg(void) { // 0xA7AD8E + Enemy_Kraid *E = Get_Kraid(0); + E->kraid_var_A = FUNC16(Kraid_GetsBig_FadeInRoomBg); + E->kraid_var_E = 0; + E->kraid_var_F = 0; + Kraid_DrawRoomBg(); +} + +void Kraid_SetLintYAndRandomThinkTimer(void) { // 0xA7ADEF + int16 v1; + + Enemy_Kraid *E = Get_Kraid(0); + Get_Kraid(0x80)->base.y_pos = E->base.y_pos - 20; + Get_Kraid(0xC0)->base.y_pos = E->base.y_pos + 46; + Get_Kraid(0x100)->base.y_pos = E->base.y_pos + 112; + v1 = random_number & 7; + if ((random_number & 7) == 0) + v1 = 2; + E->kraid_thinking = v1 << 6; +} + void Kraid_GetsBig_Thinking_Setup(void) { // 0xA7ADE1 Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_GetsBig_Thinking); Kraid_SetLintYAndRandomThinkTimer(); @@ -551,17 +510,12 @@ void Kraid_Mainloop_Thinking_Setup(void) { // 0xA7ADE9 Kraid_SetLintYAndRandomThinkTimer(); } -void Kraid_SetLintYAndRandomThinkTimer(void) { // 0xA7ADEF - int16 v1; - - Enemy_Kraid *E = Get_Kraid(0); - Get_Kraid(0x80)->base.y_pos = E->base.y_pos - 20; - Get_Kraid(0xC0u)->base.y_pos = E->base.y_pos + 46; - Get_Kraid(0x100u)->base.y_pos = E->base.y_pos + 112; - v1 = random_number & 7; - if ((random_number & 7) == 0) - v1 = 2; - E->kraid_thinking = v1 << 6; +void Kraid_Lints_Enable(uint16 k, uint16 a) { // 0xA7AE90 + Enemy_Kraid *E = Get_Kraid(k); + E->kraid_var_F = a; + E->kraid_var_A = FUNC16(Kraid_AlignEnemyToKraid); + E->kraid_next = FUNC16(KraidLint_ProduceLint); + E->kraid_var_B = 0; } void Kraid_GetsBig_FadeInRoomBg(void) { // 0xA7AE23 @@ -570,33 +524,25 @@ void Kraid_GetsBig_FadeInRoomBg(void) { // 0xA7AE23 Kraid_Lints_Enable(0x80, g_word_A7A916); Kraid_Lints_Enable(0xc0, g_word_A7A918); Kraid_Lints_Enable(0x100, g_word_A7A91A); - Enemy_Kraid *E6 = Get_Kraid(0x180u); + Enemy_Kraid *E6 = Get_Kraid(0x180); E6->kraid_next = FUNC16(KraidsFingernail_Init); - Enemy_Kraid *E7 = Get_Kraid(0x1C0u); + Enemy_Kraid *E7 = Get_Kraid(0x1C0); E7->kraid_next = FUNC16(KraidsFingernail_Init); E6->kraid_var_A = FUNC16(KraidEnemy_HandleFunctionTimer); E7->kraid_var_A = FUNC16(KraidEnemy_HandleFunctionTimer); E6->kraid_var_F = 64; E7->kraid_var_F = 128; - Get_Kraid(0x40u)->kraid_var_C = 1; + Get_Kraid(0x40)->kraid_var_C = 1; Enemy_Kraid *E0 = Get_Kraid(0); E0->kraid_var_B = addr_stru_A796DA; E0->kraid_target_x = 288; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); E5->kraid_var_A = FUNC16(KraidsFoot_SecondPhaseSetup_WalkToStartPt); E5->base.instruction_timer = 1; E5->base.current_instruction = addr_kKraid_Ilist_8887; } } -void Kraid_Lints_Enable(uint16 k, uint16 a) { // 0xA7AE90 - Enemy_Kraid *E = Get_Kraid(k); - E->kraid_var_F = a; - E->kraid_var_A = FUNC16(Kraid_AlignEnemyToKraid); - E->kraid_next = FUNC16(KraidLint_ProduceLint); - E->kraid_var_B = 0; -} - void Kraid_Mainloop_Thinking(void) { // 0xA7AEA4 Enemy_Kraid *E = Get_Kraid(0); uint16 kraid_thinking = E->kraid_thinking; @@ -655,6 +601,14 @@ uint16 Kraid_ProcessKraidInstr(void) { // 0xA7AF32 return result; } +void KraidInstr_PlayRoarSfx(void) { // 0xA7AF94 + QueueSfx2_Max6(0x2D); +} + +void KraidInstr_PlayDyingSfx(void) { // 0xA7AF9F + QueueSfx2_Max15(0x2E); +} + void CallKraidInstr(uint32 ea) { switch (ea) { case fnKraidInstr_PlayRoarSfx: KraidInstr_PlayRoarSfx(); return; @@ -671,7 +625,6 @@ RESTART:; uint16 result = *v2; if (*v2 != 0xFFFF) { if ((int16)(*v2 + 1) < 0) { - R18_ = *v2; CallKraidInstr(result | 0xA70000); E->kraid_var_B += 2; goto RESTART; @@ -693,14 +646,6 @@ RESTART:; return result; } -void KraidInstr_PlayRoarSfx(void) { // 0xA7AF94 - QueueSfx2_Max6(0x2Du); -} - -void KraidInstr_PlayDyingSfx(void) { // 0xA7AF9F - QueueSfx2_Max15(0x2Eu); -} - void Kraid_Shot_Mouth(void) { // 0xA7AFAA int16 v3; @@ -718,17 +663,17 @@ void Kraid_Shot_Mouth(void) { // 0xA7AFAA v3 = 0; const uint8 *v5; v5 = RomPtr_A7(v4); - R22_ = E->base.x_pos + GET_WORD(v5); - R20_ = E->base.y_pos + GET_WORD(v5 + 2); - R18_ = E->base.y_pos + GET_WORD(v5 + 6); + uint16 r22 = E->base.x_pos + GET_WORD(v5); + uint16 r20 = E->base.y_pos + GET_WORD(v5 + 2); + uint16 r18 = E->base.y_pos + GET_WORD(v5 + 6); if (projectile_counter) { uint16 v6 = 2 * projectile_counter; while (1) { int v7; v7 = v6 >> 1; - if (!sign16(projectile_y_pos[v7] - projectile_y_radius[v7] - 1 - R18_) - || sign16(projectile_y_radius[v7] + projectile_y_pos[v7] - R20_) - || sign16(projectile_x_radius[v7] + projectile_x_pos[v7] - R22_)) { + if (!sign16(projectile_y_pos[v7] - projectile_y_radius[v7] - 1 - r18) + || sign16(projectile_y_radius[v7] + projectile_y_pos[v7] - r20) + || sign16(projectile_x_radius[v7] + projectile_x_pos[v7] - r22)) { goto LABEL_13; } uint16 v8; @@ -739,14 +684,14 @@ void Kraid_Shot_Mouth(void) { // 0xA7AFAA break; LABEL_13: v6 -= 2; - if ((v6 & 0x8000u) != 0) + if ((v6 & 0x8000) != 0) goto LABEL_14; } - E->kraid_mouth_flags |= 1u; + E->kraid_mouth_flags |= 1; LABEL_12: collision_detection_index = v6 >> 1; NormalEnemyShotAiSkipDeathAnim_CurEnemy(); - projectile_dir[v6 >> 1] |= 0x10u; + projectile_dir[v6 >> 1] |= 0x10; v3 = 1; goto LABEL_13; } @@ -761,8 +706,7 @@ LABEL_14: E->kraid_var_A = FUNC16(Kraid_Death_Init); E->kraid_mouth_flags = 0; E->base.properties |= kEnemyProps_Tangible; - R18_ = -8193; - Kraid_SetupGfxWithTilePrioClear(); + Kraid_SetupGfxWithTilePrioClear(~0x2000); uint16 v12 = 0; do { Enemy_Kraid *EL = Get_Kraid(v12); @@ -777,13 +721,10 @@ LABEL_14: void Kraid_SpawnExplosionEproj(uint16 k) { // 0xA7B0CB int v1 = k >> 1; - R18_ = projectile_x_pos[v1]; - R20_ = projectile_y_pos[v1]; - uint16 v2 = 29; - if ((projectile_type[v1] & 0x200) == 0) - v2 = 6; + eproj_spawn_pt = (Point16U){ projectile_x_pos[v1], projectile_y_pos[v1] }; + uint16 v2 = ((projectile_type[v1] & 0x200) == 0) ? 6 : 29; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, v2); - QueueSfx1_Max6(0x3Du); + QueueSfx1_Max6(0x3D); } void Kraid_Enemy_Touch(void) { // 0xA7B0F3 @@ -791,7 +732,7 @@ void Kraid_Enemy_Touch(void) { // 0xA7B0F3 Enemy_Kraid *E = Get_Kraid(0); if (sign16(E->kraid_var_A + 0x3CA0)) { - R18_ = samus_x_radius + samus_x_pos; + uint16 r18 = samus_x_radius + samus_x_pos; v1 = samus_y_pos - E->base.y_pos; int i; for (i = 0; ; i += 4) { @@ -799,7 +740,7 @@ void Kraid_Enemy_Touch(void) { // 0xA7B0F3 if ((int16)(v1 - g_word_A7B161[v3]) >= 0 || (int16)(v1 - g_word_A7B161[v3 + 2]) >= 0) break; } - if ((int16)(E->base.x_pos + g_word_A7B161[(i >> 1) + 1] - R18_) < 0) { + if ((int16)(E->base.x_pos + g_word_A7B161[(i >> 1) + 1] - r18) < 0) { if (!sign16(samus_x_pos - 40)) { samus_x_pos -= 8; samus_prev_x_pos = samus_x_pos; @@ -823,38 +764,38 @@ void Kraid_Shot_Body(void) { // 0xA7B181 Enemy_Kraid *E = Get_Kraid(0); if (sign16(E->kraid_var_A + 0x3AC9)) { E->kraid_var_E = 0; - E->kraid_mouth_flags &= ~1u; - R48 = 0; + E->kraid_mouth_flags &= ~1; + uint16 R48 = 0; const uint8 *v2 = RomPtr_A7(E->kraid_var_B - 8); const uint8 *v3 = RomPtr_A7(GET_WORD(v2 + 4)); - R22_ = E->base.x_pos + GET_WORD(v3); - R20_ = E->base.y_pos + GET_WORD(v3 + 2); - R18_ = E->base.y_pos + GET_WORD(v3 + 6); + uint16 r22 = E->base.x_pos + GET_WORD(v3); + uint16 r20 = E->base.y_pos + GET_WORD(v3 + 2); + uint16 r18 = E->base.y_pos + GET_WORD(v3 + 6); if (projectile_counter) { for (int i = 2 * projectile_counter; i >= 0; i -= 2) { int v5 = i >> 1; - if (sign16(projectile_y_pos[v5] - projectile_y_radius[v5] - 1 - R18_)) { - if (!sign16(projectile_y_radius[v5] + projectile_y_pos[v5] - R20_) - && !sign16(projectile_x_radius[v5] + projectile_x_pos[v5] - R22_)) { + if (sign16(projectile_y_pos[v5] - projectile_y_radius[v5] - 1 - r18)) { + if (!sign16(projectile_y_radius[v5] + projectile_y_pos[v5] - r20) + && !sign16(projectile_x_radius[v5] + projectile_x_pos[v5] - r22)) { goto LABEL_7; } } else { int v10; v10 = i >> 1; - R18_ = projectile_x_radius[v10] + projectile_x_pos[v10]; + r18 = projectile_x_radius[v10] + projectile_x_pos[v10]; v11 = projectile_y_pos[v10] - E->base.y_pos; for (j = 0; ; j += 4) { int v13 = j >> 1; if ((int16)(v11 - g_word_A7B161[v13]) >= 0 || (int16)(v11 - g_word_A7B161[v13 + 2]) >= 0) break; } - if ((int16)(E->base.x_pos + g_word_A7B161[(j >> 1) + 1] - R18_) < 0) { + if ((int16)(E->base.x_pos + g_word_A7B161[(j >> 1) + 1] - r18) < 0) { LABEL_7: Kraid_SpawnExplosionEproj(i); int v6 = i >> 1; - projectile_dir[v6] |= 0x10u; + projectile_dir[v6] |= 0x10; if ((projectile_type[v6] & 0x10) != 0) { - E->kraid_mouth_flags |= 1u; + E->kraid_mouth_flags |= 1; } ++R48; } @@ -947,7 +888,7 @@ const uint16 *Kraid_Instr_IncrYpos_Shake(uint16 k, const uint16 *jp) { // 0xA7B } const uint16 *Kraid_Instr_PlaySound_0x76(uint16 k, const uint16 *jp) { // 0xA7B64E - QueueSfx2_Max6(0x76u); + QueueSfx2_Max6(0x76); return jp; } @@ -974,13 +915,11 @@ const uint16 *Kraid_Instr_MoveHimRight(uint16 k, const uint16 *jp) { // 0xA7B68 Enemy_Kraid *E = Get_Kraid(0); if (sign16(E->base.x_pos - 320) || (v3 = E->kraid_target_x - 1, (E->kraid_target_x = v3) == 0)) { - R18_ = 0; - R20_ = g_word_A7A922; - if (Enemy_MoveRight_IgnoreSlopes(0) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(0, INT16_SHL16(g_word_A7A922))) { earthquake_type = 0; earthquake_timer = 7; uint16 x_pos = Get_Kraid(0)->base.x_pos; - Get_Kraid(0x140u)->base.x_pos = x_pos; + Get_Kraid(0x140)->base.x_pos = x_pos; } } return jp; @@ -1008,20 +947,17 @@ void Kraid_Shot_GlowHisEye(void) { // 0xA7B6D7 ++v1; v3 = 31; } - R18_ = v3; uint16 v4 = (palette_buffer[v2] & 0x3E0) + 32; if (!sign16((palette_buffer[v2] & 0x3E0) - 960)) { ++v1; v4 = 992; } - R20_ = v4; - palette_buffer[v2] = v4 | R18_ | palette_buffer[v2] & 0xFC00; + palette_buffer[v2] = v4 | v3 | palette_buffer[v2] & 0xFC00; v0 += 2; } while ((int16)(v0 - 232) < 0); if ((int16)(v1 - 6) >= 0) Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_Shot_UnglowEye); } -// 9CBFB: ignored the value written to the shadow area of the succeeding call void Kraid_Shot_UnglowEye(void) { // 0xA7B73D Enemy_Kraid *E = Get_Kraid(0); @@ -1034,24 +970,24 @@ void Kraid_Shot_UnglowEye(void) { // 0xA7B73D } while (v0); uint16 v2 = 16 * (v0 + 2); uint16 v3 = 226; - R20_ = 0; + uint16 r20 = 0, r18; do { int v4 = v3 >> 1; - R18_ = palette_buffer[v4] & 0x1F; + r18 = palette_buffer[v4] & 0x1F; int v5 = v2 >> 1; - if ((kKraid_BgPalette7[v5 + 1] & 0x1F) != R18_) { - ++R20_; + if ((kKraid_BgPalette7[v5 + 1] & 0x1F) != r18) { + ++r20; --palette_buffer[v4]; } - R18_ = palette_buffer[v4] & 0x3E0; - if ((kKraid_BgPalette7[v5 + 1] & 0x3E0) != R18_) { - ++R20_; + r18 = palette_buffer[v4] & 0x3E0; + if ((kKraid_BgPalette7[v5 + 1] & 0x3E0) != r18) { + ++r20; palette_buffer[v4] -= 32; } v3 += 2; v2 += 2; } while ((int16)(v3 - 232) < 0); - if (!R20_) { + if (!r20) { E->kraid_var_A = FUNC16(Kraid_Shot_MouthIsOpen); E->kraid_var_B = addr_stru_A796DA; E->kraid_var_C = g_stru_A796D2.timer; @@ -1059,14 +995,14 @@ void Kraid_Shot_UnglowEye(void) { // 0xA7B73D } void KraidsArm_Main(void) { // 0xA7B7BD - R18_ = layer1_y_pos + 224; + uint16 r18 = layer1_y_pos + 224; Enemy_Kraid *E = Get_Kraid(0); uint16 v1 = E->base.y_pos - 44; - Enemy_Kraid *E1 = Get_Kraid(0x40u); + Enemy_Kraid *E1 = Get_Kraid(0x40); E1->base.y_pos = v1; uint16 v3 = v1; uint16 v4 = E1->base.properties | 0x100; - if ((int16)(v3 - layer1_y_pos) >= 0 && (int16)(v3 - R18_) < 0) + if ((int16)(v3 - layer1_y_pos) >= 0 && (int16)(v3 - r18) < 0) v4 = E1->base.properties & 0xFEFF; E1->base.properties = v4; E1->base.x_pos = E->base.x_pos; @@ -1074,31 +1010,31 @@ void KraidsArm_Main(void) { // 0xA7B7BD ++E1->base.instruction_timer; } +void KraidLintCommon_Main(uint16 k) { // 0xA7B822 + Kraid_EnemyTouch_Lint(k); + // r18 = layer1_y_pos + 224; + EnemyData *v1 = gEnemyData(k); + CallKraidFunc(v1->ai_var_A | 0xA70000); +} + void KraidsTopLint_Main(void) { // 0xA7B801 gEnemyData(0x80)->instruction_timer = 0x7FFF; KraidLintCommon_Main(0x80); } void KraidsMiddleLint_Main(void) { // 0xA7B80D - gEnemyData(0xC0u)->instruction_timer = 0x7FFF; - KraidLintCommon_Main(0xC0u); + gEnemyData(0xC0)->instruction_timer = 0x7FFF; + KraidLintCommon_Main(0xC0); } void KraidsBottomLint_Main(void) { // 0xA7B819 - gEnemyData(0x100u)->instruction_timer = 0x7FFF; - KraidLintCommon_Main(0x100u); -} - -void KraidLintCommon_Main(uint16 k) { // 0xA7B822 - Kraid_EnemyTouch_Lint(k); - R18_ = layer1_y_pos + 224; - EnemyData *v1 = gEnemyData(k); - CallKraidFunc(v1->ai_var_A | 0xA70000); + gEnemyData(0x100)->instruction_timer = 0x7FFF; + KraidLintCommon_Main(0x100); } void KraidLint_ProduceLint(uint16 k) { // 0xA7B832 EnemyData *v1 = gEnemyData(k); - v1->properties &= 0xFAFFu; + v1->properties &= 0xFAFF; v1->x_pos = v1->ai_var_C + gEnemyData(0)->x_pos - v1->ai_var_B; uint16 v2 = v1->ai_var_B + 1; v1->ai_var_B = v2; @@ -1120,7 +1056,7 @@ void KraidLint_ChargeLint(uint16 k) { // 0xA7B868 v2->x_pos = v2->ai_var_C + gEnemyData(0)->x_pos - v2->ai_var_B; if (v3->ai_preinstr-- == 1) { v3->ai_var_A = FUNC16(KraidLint_FireLint); - QueueSfx3_Max6(0x1Fu); + QueueSfx3_Max6(0x1F); } } @@ -1155,17 +1091,10 @@ void KraidFingernail_WaitForLintXpos(uint16 k) { // 0xA7B907 if (!sign16(E2->base.x_pos - 256)) { Enemy_Kraid *E = Get_Kraid(k); E->kraid_var_A = E->kraid_next; - E->base.properties &= 0xFAFFu; + E->base.properties &= 0xFAFF; } } -void Kraid_AlignEnemyToKraid(uint16 k) { // 0xA7B923 - uint16 x_pos = Get_Kraid(0)->base.x_pos; - Enemy_Kraid *E = Get_Kraid(k); - E->base.x_pos = x_pos - E->base.x_width; - KraidEnemy_HandleFunctionTimer(k); -} - void KraidEnemy_HandleFunctionTimer(uint16 k) { // 0xA7B92D Enemy_Kraid *E = Get_Kraid(k); if (E->kraid_var_F) { @@ -1174,6 +1103,13 @@ void KraidEnemy_HandleFunctionTimer(uint16 k) { // 0xA7B92D } } +void Kraid_AlignEnemyToKraid(uint16 k) { // 0xA7B923 + uint16 x_pos = Get_Kraid(0)->base.x_pos; + Enemy_Kraid *E = Get_Kraid(k); + E->base.x_pos = x_pos - E->base.x_width; + KraidEnemy_HandleFunctionTimer(k); +} + void KraidEnemy_DecrementEnemyFunctionTimer(void) { // 0xA7B93F Enemy_Kraid *E = Get_Kraid(cur_enemy_index); if (E->kraid_var_F) { @@ -1198,13 +1134,13 @@ void KraidEnemy_ProcessInstrEnemyTimer(uint16 k) { // 0xA7B965 void Kraid_EnemyTouch_Lint(uint16 k) { // 0xA7B96A Enemy_Kraid *E = Get_Kraid(k); if ((E->base.properties & kEnemyProps_Tangible) == 0 && !samus_invincibility_timer) { - R18_ = g_stru_A792B7.left + E->base.x_pos - 2; - if (!sign16(samus_x_radius + samus_x_pos - R18_)) { - if (sign16(samus_x_pos - samus_x_radius - R18_)) { - R22_ = g_stru_A792B7.top + E->base.y_pos + 2; - if (!sign16(samus_y_radius + samus_y_pos - R22_)) { - R24_ = g_stru_A792B7.bottom + E->base.y_pos - 2; - if (sign16(samus_y_pos - samus_y_radius - R24_)) { + uint16 r18 = g_stru_A792B7.left + E->base.x_pos - 2; + if (!sign16(samus_x_radius + samus_x_pos - r18)) { + if (sign16(samus_x_pos - samus_x_radius - r18)) { + uint16 r22 = g_stru_A792B7.top + E->base.y_pos + 2; + if (!sign16(samus_y_radius + samus_y_pos - r22)) { + uint16 r24 = g_stru_A792B7.bottom + E->base.y_pos - 2; + if (sign16(samus_y_pos - samus_y_radius - r24)) { uint16 v2 = extra_samus_x_displacement + ~(samus_x_radius + 16); if (!sign16(v2 - 16)) v2 = 16; @@ -1230,18 +1166,36 @@ void KraidsFoot_Main(void) { // 0xA7B9F6 uint16 v4 = v0[5].properties & 0xFEFF; if ((int16)(v2 - layer1_y_pos) >= 0) { if ((int16)(v3 - layer1_y_pos) >= 0) - v4 |= 0x100u; + v4 |= 0x100; } else { - v4 |= 0x100u; + v4 |= 0x100; } v0[5].properties = v4; CallKraidFunc(v0[5].ai_var_A | 0xA70000); } +void Kraid_SetWalkingBackwards(uint16 j, uint16 a) { // 0xA7BB0D + Get_Kraid(0)->kraid_target_x = a; + Enemy_Kraid *E = Get_Kraid(0x140); + E->kraid_next = j; + E->kraid_var_A = FUNC16(KraidsFoot_SecondPhase_WalkingBackwards); + E->base.instruction_timer = 1; + E->base.current_instruction = addr_kKraid_Ilist_8887; +} + +void Kraid_SetWalkingForwards(uint16 j, uint16 a) { // 0xA7BB29 + Get_Kraid(0)->kraid_target_x = a; + Enemy_Kraid *E = Get_Kraid(0x140); + E->kraid_next = j; + E->kraid_var_A = FUNC16(KraidsFoot_SecondPhase_WalkForward); + E->base.instruction_timer = 1; + E->base.current_instruction = addr_kKraid_Ilist_86F3; +} + void KraidsFoot_SecondPhase_Thinking(void) { // 0xA7BA2E int16 v4; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); uint16 v1 = E5->kraid_next - 1; E5->kraid_next = v1; if (!v1) { @@ -1269,24 +1223,6 @@ void KraidsFoot_SecondPhase_Thinking(void) { // 0xA7BA2E } } -void Kraid_SetWalkingBackwards(uint16 j, uint16 a) { // 0xA7BB0D - Get_Kraid(0)->kraid_target_x = a; - Enemy_Kraid *E = Get_Kraid(0x140u); - E->kraid_next = j; - E->kraid_var_A = FUNC16(KraidsFoot_SecondPhase_WalkingBackwards); - E->base.instruction_timer = 1; - E->base.current_instruction = addr_kKraid_Ilist_8887; -} - -void Kraid_SetWalkingForwards(uint16 j, uint16 a) { // 0xA7BB29 - Get_Kraid(0)->kraid_target_x = a; - Enemy_Kraid *E = Get_Kraid(0x140u); - E->kraid_next = j; - E->kraid_var_A = FUNC16(KraidsFoot_SecondPhase_WalkForward); - E->base.instruction_timer = 1; - E->base.current_instruction = addr_kKraid_Ilist_86F3; -} - void KraidsFoot_SecondPhase_WalkingBackwards(void) { // 0xA7BB45 Enemy_Kraid *E0 = Get_Kraid(0); uint16 kraid_target_x = E0->kraid_target_x; @@ -1295,7 +1231,7 @@ void KraidsFoot_SecondPhase_WalkingBackwards(void) { // 0xA7BB45 return; E0->base.x_pos = kraid_target_x; } - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); if (!sign16(E5->base.current_instruction + 0x76C7)) { E5->kraid_var_A = FUNC16(KraidsFoot_SecondPhase_Thinking); E5->base.instruction_timer = 1; @@ -1311,7 +1247,7 @@ void KraidsFoot_SecondPhaseSetup_WalkToStartPt(void) { // 0xA7BB6E return; E0->base.x_pos = kraid_target_x; } - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); if (!sign16(E5->base.current_instruction + 0x76C7)) { E5->kraid_var_A = FUNC16(KraidEnemy_HandleFunctionTimer); E5->kraid_var_F = 180; @@ -1329,14 +1265,14 @@ void KraidsFoot_SecondPhase_WalkForward(void) { // 0xA7BBAE Enemy_Kraid *E0 = Get_Kraid(0); uint16 kraid_target_x = E0->kraid_target_x; if ((int16)(kraid_target_x - E0->base.x_pos) < 0) { - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); if (E5->base.current_instruction == (uint16)addr_off_A787BB) { E5->base.current_instruction = addr_kKraid_Ilist_86F3; E5->base.instruction_timer = 1; } } else { E0->base.x_pos = kraid_target_x; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); if (E5->base.current_instruction == (uint16)addr_off_A787BB) { E5->kraid_var_A = FUNC16(KraidsFoot_SecondPhase_Thinking); E5->base.instruction_timer = 1; @@ -1353,8 +1289,7 @@ void Kraid_Main_AttackWithMouthOpen(void) { // 0xA7BBEA Kraid_Mainloop_Thinking_Setup(); E->kraid_var_C = 90; uint16 kraid_mouth_flags = E->kraid_mouth_flags; - if ((kraid_mouth_flags & 4) != 0 - && (v3 = kraid_mouth_flags - 256, E->kraid_mouth_flags = v3, (v3 & 0xFF00) != 0)) { + if ((kraid_mouth_flags & 4) != 0 && (v3 = kraid_mouth_flags - 256, E->kraid_mouth_flags = v3, (v3 & 0xFF00) != 0)) { E->kraid_var_A = FUNC16(KraidEnemy_HandleFunctionTimer); E->kraid_var_F = 64; E->kraid_next = FUNC16(Kraid_InitEyeGlowing); @@ -1363,13 +1298,9 @@ void Kraid_Main_AttackWithMouthOpen(void) { // 0xA7BBEA E->kraid_mouth_flags = 0; } } else { - if (*((uint16 *)RomPtr_A7(E->kraid_var_B - 8) + 1) == addr_kKraidTilemaps_3 - && (E->kraid_var_C & 0xF) == 0) { - SpawnEnemyProjectileWithGfx( - g_word_A7BC65[(uint8)(random_number & 0xE) >> 1], - random_number & 0xE, - addr_kEproj_RocksKraidSpits); - QueueSfx3_Max6(0x1Eu); + if (*((uint16 *)RomPtr_A7(E->kraid_var_B - 8) + 1) == addr_kKraidTilemaps_3 && (E->kraid_var_C & 0xF) == 0) { + SpawnEnemyProjectileWithGfx(g_word_A7BC65[(random_number & 0xE) >> 1], random_number & 0xE, addr_kEproj_RocksKraidSpits); + QueueSfx3_Max6(0x1E); } } } @@ -1389,10 +1320,6 @@ void KraidsBadFingernail_Touch(void) { // 0xA7BCDE EnemyDeathAnimation(cur_enemy_index, v0); } -void KraidsGoodFingernail_Init(void) { // 0xA7BCEF - KraidFingernailInit(cur_enemy_index); -} - void KraidFingernailInit(uint16 k) { // 0xA7BCF2 uint16 palette_index = Get_Kraid(0)->base.palette_index; Enemy_Kraid *E = Get_Kraid(k); @@ -1407,6 +1334,10 @@ void KraidFingernailInit(uint16 k) { // 0xA7BCF2 E->kraid_var_F = 64; } +void KraidsGoodFingernail_Init(void) { // 0xA7BCEF + KraidFingernailInit(cur_enemy_index); +} + void KraidsBadFingernail_Init(void) { // 0xA7BD2D KraidFingernailInit(cur_enemy_index); } @@ -1434,13 +1365,13 @@ void KraidsBadFingernail_Main(void) { // 0xA7BD49 void KraidsFingernail_Init(void) { // 0xA7BD60 uint16 v2; - uint16 kraid_var_E = Get_Kraid(0x180u)->kraid_var_E; + uint16 kraid_var_E = Get_Kraid(0x180)->kraid_var_E; if (cur_enemy_index == 384) - kraid_var_E = Get_Kraid(0x1C0u)->kraid_var_E; + kraid_var_E = Get_Kraid(0x1C0)->kraid_var_E; if (sign16(kraid_var_E)) - v2 = g_off_A7BE3E[(uint8)(random_number & 6) >> 1]; + v2 = g_off_A7BE3E[(random_number & 6) >> 1]; else - v2 = g_off_A7BE46[(uint8)(random_number & 6) >> 1]; + v2 = g_off_A7BE46[(random_number & 6) >> 1]; const uint8 *v3 = RomPtr_A7(v2); Enemy_Kraid *E = Get_Kraid(cur_enemy_index); E->kraid_var_B = GET_WORD(v3); @@ -1455,15 +1386,15 @@ void KraidsFingernail_Init(void) { // 0xA7BD60 if ((random_number & 1) == 0) goto LABEL_7; uint16 v7; - v7 = Get_Kraid(0x180u)->kraid_healths_8ths[1]; + v7 = Get_Kraid(0x180)->kraid_healths_8ths[1]; if (cur_enemy_index != 448) - v7 = Get_Kraid(0x1C0u)->kraid_healths_8ths[1]; + v7 = Get_Kraid(0x1C0)->kraid_healths_8ths[1]; if (v7 == 1) { LABEL_7: E->kraid_healths_8ths[1] = 0; Enemy_Kraid *E0 = Get_Kraid(0); E->base.x_pos = (E0->base.x_pos - E0->base.x_width - E->base.x_width) & 0xFFF0; - E->base.y_pos = Get_Kraid(0x40u)->base.y_pos + 128; + E->base.y_pos = Get_Kraid(0x40)->base.y_pos + 128; } else { E->kraid_healths_8ths[1] = 1; E->base.x_pos = 50; @@ -1480,9 +1411,7 @@ LABEL_7: void KraidsFingernail_Fire(uint16 k) { // 0xA7BE8E EnemyData *v1 = gEnemyData(k); - R18_ = v1->ai_var_B; - R20_ = v1->ai_var_C; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(v1->ai_var_C, v1->ai_var_B))) { v1->ai_var_B = -v1->ai_var_B; v1->ai_var_C = -v1->ai_var_C; } else { @@ -1494,16 +1423,14 @@ void KraidsFingernail_Fire(uint16 k) { // 0xA7BE8E if ((int16)(g_word_A7BF1D[(i >> 1) + 1] + v3->y_pos - v4->y_pos) < 0) break; } - R18_ = g_word_A7BF1D[i >> 1] + v3->x_pos; - if (!sign16(v4->x_width + v4->x_pos - R18_) && (v4->ai_var_C & 0x8000u) == 0) { + uint16 r18 = g_word_A7BF1D[i >> 1] + v3->x_pos; + if (!sign16(v4->x_width + v4->x_pos - r18) && (v4->ai_var_C & 0x8000) == 0) { v4->ai_var_B = -v4->ai_var_B; v4->ai_var_C = -v4->ai_var_C; } } EnemyData *v5 = gEnemyData(k); - R18_ = v5->ai_var_D; - R20_ = v5->ai_var_E; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, __PAIR32__(v5->ai_var_E, v5->ai_var_D))) { Negate32(&v5->ai_var_E, &v5->ai_var_D, &v5->ai_var_E, &v5->ai_var_D); } } @@ -1526,7 +1453,7 @@ void KraidsFoot_FirstPhase_LungeForward(void) { // 0xA7BF5D Enemy_Kraid *E = Get_Kraid(0); if (sign16(E->base.x_pos - 92)) E->base.x_pos = 92; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); if (E5->base.current_instruction == (uint16)addr_off_A78885) { if (E->base.x_pos == 92) { E5->kraid_next = FUNC16(KraidsFoot_FirstPhase_RetreatFromLunge); @@ -1546,10 +1473,10 @@ void KraidsFoot_FirstPhase_RetreatFromLunge(void) { // 0xA7BFAB Enemy_Kraid *E0 = Get_Kraid(0); if (!sign16(E0->base.x_pos - 176)) E0->base.x_pos = 176; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); if (!sign16(E5->base.current_instruction + 0x76C7)) { if (E0->base.x_pos == 176) { - Enemy_Kraid *E1 = Get_Kraid(0x40u); + Enemy_Kraid *E1 = Get_Kraid(0x40); E1->base.current_instruction = addr_kKraid_Ilist_89F3; E1->base.instruction_timer = 1; E5->base.instruction_timer = 1; @@ -1586,20 +1513,20 @@ void Kraid_HandleFirstPhase(void) { // 0xA7C005 E0->kraid_var_C = *(uint16 *)((uint8 *)&g_stru_A796D2.timer + v3); earthquake_type = 4; earthquake_timer = 340; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); E5->base.current_instruction = addr_kKraid_Ilist_86E7; E5->base.instruction_timer = 1; E5->kraid_var_A = FUNC16(nullsub_234); - Enemy_Kraid *E1 = Get_Kraid(0x40u); + Enemy_Kraid *E1 = Get_Kraid(0x40); E1->base.current_instruction = addr_kKraid_Ilist_89F3; E1->base.instruction_timer = 1; Enemy_Kraid *E2 = Get_Kraid(0x80); - E2->base.properties |= 0x100u; - Enemy_Kraid *E3 = Get_Kraid(0xC0u); - E3->base.properties |= 0x100u; - Enemy_Kraid *E4 = Get_Kraid(0x100u); - E4->base.properties |= 0x100u; - E1->base.properties |= 0x400u; + E2->base.properties |= 0x100; + Enemy_Kraid *E3 = Get_Kraid(0xC0); + E3->base.properties |= 0x100; + Enemy_Kraid *E4 = Get_Kraid(0x100); + E4->base.properties |= 0x100; + E1->base.properties |= 0x400; } } @@ -1610,14 +1537,13 @@ void Kraid_GetsBig_ReleaseCamera(void) { // 0xA7C0A1 *(uint16 *)&scrolls[2] = 257; E->kraid_min_y_pos_eject = 164; } -static const SpawnHardcodedPlmArgs unk_A7C16C = { 0x02, 0x12, 0xb7b7 }; -static const SpawnHardcodedPlmArgs unk_A7C175 = { 0x05, 0x1b, 0xb7bb }; + void Kraid_SpawnPlmToClearCeiling(void) { // 0xA7C168 - SpawnHardcodedPlm(&unk_A7C16C); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x12, 0xb7b7 }); } void Kraid_ClearSomeSpikes(void) { // 0xA7C171 - SpawnHardcodedPlm(&unk_A7C175); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x05, 0x1b, 0xb7bb }); } CoroutineRet UnpauseHook_Kraid_IsDead(void) { // 0xA7C1FB @@ -1628,12 +1554,12 @@ CoroutineRet UnpauseHook_Kraid_IsDead(void) { // 0xA7C1FB WriteReg(VMADDH, 16 * (reg_BG12NBA & 0xF) + 63); WriteReg(VMAIN, 0x80); SetupDmaTransfer(&unk_A7C21E); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); WriteReg(VMADDL, 0); WriteReg(VMADDH, 0x40); WriteReg(VMAIN, 0x80); SetupDmaTransfer(&unk_A7C23E); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); Kraid_TransferTopHalfToVram(); return kCoroutineNone; } @@ -1647,7 +1573,7 @@ CoroutineRet UnpauseHook_Kraid_IsAlive(void) { // 0xA7C24E WriteReg(VMADDH, reg_BG12NBA + 62); WriteReg(VMAIN, 0x80); SetupDmaTransfer(&unk_A7C26B); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); Kraid_TransferTopHalfToVram(); return kCoroutineNone; } @@ -1657,7 +1583,7 @@ void Kraid_TransferTopHalfToVram(void) { // 0xA7C278 WriteReg(VMADDH, reg_BG2SC & 0xFC); WriteReg(VMAIN, 0x80); SetupDmaTransfer(&unk_A7C28D); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); ScreenOn(); } @@ -1670,7 +1596,7 @@ CoroutineRet Kraid_UnpauseHook_IsSinking(void) { // 0xA7C2A0 WriteReg(VMADDH, reg_BG12NBA + 62); WriteReg(VMAIN, 0x80); SetupDmaTransfer(&unk_A7C2BD); - WriteReg(MDMAEN, 2u); + WriteReg(MDMAEN, 2); if ((int16)(Get_Kraid(0)->base.y_pos - kKraidSinkEntry[0].field_0) >= 0) { my_counter = 0; my_counter2 = vram_write_queue_tail; @@ -1714,7 +1640,7 @@ void Kraid_Death_Init(void) { // 0xA7C360 } while ((int16)(v0 - 224) < 0); for (int i = 30; i >= 0; i -= 2) palette_buffer[(i >> 1) + 112] = kKraid_BgPalette7_KraidDeath[i >> 1]; - Enemy_Kraid *E1 = Get_Kraid(0x40u); + Enemy_Kraid *E1 = Get_Kraid(0x40); E1->base.current_instruction = addr_kKraid_Ilist_8AF0; E1->base.instruction_timer = 1; E0->kraid_var_A = FUNC16(Kraid_Death_Fadeout); @@ -1722,12 +1648,12 @@ void Kraid_Death_Init(void) { // 0xA7C360 E0->kraid_var_C = g_stru_A79764[0].timer; uint16 v4 = cur_enemy_index; uint16 v7 = cur_enemy_index; - Enemy_Kraid *E6 = Get_Kraid(0x180u); - E6->base.properties &= ~0x4000u; + Enemy_Kraid *E6 = Get_Kraid(0x180); + E6->base.properties &= ~0x4000; cur_enemy_index = 384; EnemyDeathAnimation(v4, 0x180); - Enemy_Kraid *E7 = Get_Kraid(0x1C0u); - E7->base.properties &= ~0x4000u; + Enemy_Kraid *E7 = Get_Kraid(0x1C0); + E7->base.properties &= ~0x4000; cur_enemy_index = 448; EnemyDeathAnimation(v4, 0x1C0); cur_enemy_index = 128; @@ -1737,8 +1663,7 @@ void Kraid_Death_Init(void) { // 0xA7C360 cur_enemy_index = 256; EnemyDeathAnimation(v4, 0x100); cur_enemy_index = v7; - static const SpawnHardcodedPlmArgs unk_A7C3F4 = { 0x05, 0x1b, 0xb7bf }; - SpawnHardcodedPlm(&unk_A7C3F4); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x05, 0x1b, 0xb7bf }); } } @@ -1774,10 +1699,10 @@ void Kraid_Death_UpdateBG2TilemapTopHalf(void) { // 0xA7C4A4 Enemy_Kraid *E2 = Get_Kraid(0x80); E2->kraid_var_A = FUNC16(Kraid_AlignEnemyToKraid); E2->kraid_var_F = 0x7FFF; - Enemy_Kraid *E3 = Get_Kraid(0xC0u); + Enemy_Kraid *E3 = Get_Kraid(0xC0); E3->kraid_var_A = FUNC16(Kraid_AlignEnemyToKraid); E3->kraid_var_F = 0x7FFF; - Enemy_Kraid *E4 = Get_Kraid(0x100u); + Enemy_Kraid *E4 = Get_Kraid(0x100); E4->kraid_var_A = FUNC16(Kraid_AlignEnemyToKraid); E4->kraid_var_F = 0x7FFF; Kraid_UpdateBg2TilemapTopHalf(); @@ -1790,13 +1715,13 @@ void Kraid_Death_UpdateBG2TilemapBottomHalf(void) { // 0xA7C4C8 Enemy_Kraid *E = Get_Kraid(0); E->kraid_var_A = FUNC16(Kraid_Death_SinkThroughFloor); kraid_unk9000 = 43; - E->base.properties |= 0x8000u; + E->base.properties |= 0x8000; earthquake_type = 1; earthquake_timer = 256; - Enemy_Kraid *E1 = Get_Kraid(0x40u); + Enemy_Kraid *E1 = Get_Kraid(0x40); E1->base.current_instruction = addr_kKraid_Ilist_8AA4; E1->base.instruction_timer = 1; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); E5->base.current_instruction = addr_kKraid_Ilist_86E7; E5->base.instruction_timer = 1; E5->kraid_var_A = FUNC16(nullsub_234); @@ -1805,49 +1730,11 @@ void Kraid_Death_UpdateBG2TilemapBottomHalf(void) { // 0xA7C4C8 void Kraid_PlaySoundEveryHalfSecond(void) { // 0xA7C51D if (!--kraid_unk9000) { - QueueSfx3_Max6(0x1Eu); + QueueSfx3_Max6(0x1E); kraid_unk9000 = 30; } } -void Kraid_Death_SinkThroughFloor(void) { // 0xA7C537 - Kraid_ProcessKraidInstr(); - Kraid_PlaySoundEveryHalfSecond(); - Kraid_HandleSinking(); - Enemy_Kraid *E0 = Get_Kraid(0); - if (!sign16(++E0->base.y_pos - 608)) { - E0->base.properties &= ~kEnemyProps_Tangible; - enemy_bg2_tilemap_size = 2; - uint16 enemy_ptr = Get_Kraid(cur_enemy_index)->base.enemy_ptr; - get_EnemyDef_A2(enemy_ptr)->shot_ai = FUNC16(nullsub_170_A7); - Enemy_Kraid *E1 = Get_Kraid(0x40u); - uint16 v3 = E1->base.properties | kEnemyProps_Tangible | kEnemyProps_Deleted; - E1->base.properties = v3; - uint16 v4 = v3 & 0x51FF | 0x600; - Get_Kraid(0x80)->base.properties = v4; - Get_Kraid(0xC0u)->base.properties = v4; - Get_Kraid(0x100u)->base.properties = v4; - Get_Kraid(0x140u)->base.properties = v4; - Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_FadeInBg_ClearBg2TilemapTopHalf); - camera_distance_index = 0; - Enemy_ItemDrop_Kraid(enemy_ptr); - Kraid_DrawRoomBg(); - } -} - -void CallKraidSinkTableFunc(uint32 ea) { - switch (ea) { - case fnKraid_CrumbleLeftPlatform_Left: Kraid_CrumbleLeftPlatform_Left(); return; - case fnnullsub_356: return; - case fnKraid_CrumbleRightPlatform_Middle: Kraid_CrumbleRightPlatform_Middle(); return; - case fnKraid_CrumbleRightPlatform_Left: Kraid_CrumbleRightPlatform_Left(); return; - case fnKraid_CrumbleLeftPlatform_Right: Kraid_CrumbleLeftPlatform_Right(); return; - case fnKraid_CrumbleLeftPlatform_Middle: Kraid_CrumbleLeftPlatform_Middle(); return; - case fnKraid_CrumbleRightPlatform_Right: Kraid_CrumbleRightPlatform_Right(); return; - default: Unreachable(); - } -} - void Kraid_HandleSinking(void) { // 0xA7C59F int16 v1; VramWriteEntry *v3; @@ -1857,7 +1744,7 @@ void Kraid_HandleSinking(void) { // 0xA7C59F if (v1 < 0) break; if (v1 == Get_Kraid(0)->base.y_pos) { - if ((kKraidSinkEntry[i].field_2 & 0x8000u) == 0) { + if ((kKraidSinkEntry[i].field_2 & 0x8000) == 0) { uint16 v2 = vram_write_queue_tail; v3 = gVramWriteEntry(vram_write_queue_tail); v3->size = 64; @@ -1872,41 +1759,72 @@ void Kraid_HandleSinking(void) { // 0xA7C59F } } -static const SpawnHardcodedPlmArgs unk_A7C6A2 = { 0x07, 0x12, 0xb7a7 }; -static const SpawnHardcodedPlmArgs unk_A7C6B8 = { 0x0f, 0x12, 0xb7a7 }; -static const SpawnHardcodedPlmArgs unk_A7C6CE = { 0x0e, 0x12, 0xb7af }; -static const SpawnHardcodedPlmArgs unk_A7C6E4 = { 0x09, 0x12, 0xb7a7 }; -static const SpawnHardcodedPlmArgs unk_A7C6FA = { 0x08, 0x12, 0xb7af }; -static const SpawnHardcodedPlmArgs unk_A7C710 = { 0x10, 0x12, 0xb7af }; +void Kraid_Death_SinkThroughFloor(void) { // 0xA7C537 + Kraid_ProcessKraidInstr(); + Kraid_PlaySoundEveryHalfSecond(); + Kraid_HandleSinking(); + Enemy_Kraid *E0 = Get_Kraid(0); + if (!sign16(++E0->base.y_pos - 608)) { + E0->base.properties &= ~kEnemyProps_Tangible; + enemy_bg2_tilemap_size = 2; + uint16 enemy_ptr = Get_Kraid(cur_enemy_index)->base.enemy_ptr; + get_EnemyDef_A2(enemy_ptr)->shot_ai = FUNC16(nullsub_170_A7); + Enemy_Kraid *E1 = Get_Kraid(0x40); + uint16 v3 = E1->base.properties | kEnemyProps_Tangible | kEnemyProps_Deleted; + E1->base.properties = v3; + uint16 v4 = v3 & 0x51FF | 0x600; + Get_Kraid(0x80)->base.properties = v4; + Get_Kraid(0xC0)->base.properties = v4; + Get_Kraid(0x100)->base.properties = v4; + Get_Kraid(0x140)->base.properties = v4; + Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_FadeInBg_ClearBg2TilemapTopHalf); + camera_distance_index = 0; + Enemy_ItemDrop_Kraid(enemy_ptr); + Kraid_DrawRoomBg(); + } +} void Kraid_CrumbleLeftPlatform_Left(void) { // 0xA7C691 SpawnEnemyProjectileWithGfx(0x70, cur_enemy_index, addr_kEproj_RocksFallingKraidCeiling); - SpawnHardcodedPlm(&unk_A7C6A2); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x07, 0x12, 0xb7a7 }); } void Kraid_CrumbleRightPlatform_Middle(void) { // 0xA7C6A7 SpawnEnemyProjectileWithGfx(0xF0, cur_enemy_index, addr_kEproj_RocksFallingKraidCeiling); - SpawnHardcodedPlm(&unk_A7C6B8); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0f, 0x12, 0xb7a7 }); } void Kraid_CrumbleRightPlatform_Left(void) { // 0xA7C6BD SpawnEnemyProjectileWithGfx(0xE0, cur_enemy_index, addr_kEproj_RocksFallingKraidCeiling); - SpawnHardcodedPlm(&unk_A7C6CE); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0e, 0x12, 0xb7af }); } void Kraid_CrumbleLeftPlatform_Right(void) { // 0xA7C6D3 SpawnEnemyProjectileWithGfx(0x90, cur_enemy_index, addr_kEproj_RocksFallingKraidCeiling); - SpawnHardcodedPlm(&unk_A7C6E4); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x09, 0x12, 0xb7a7 }); } void Kraid_CrumbleLeftPlatform_Middle(void) { // 0xA7C6E9 SpawnEnemyProjectileWithGfx(0x80, cur_enemy_index, addr_kEproj_RocksFallingKraidCeiling); - SpawnHardcodedPlm(&unk_A7C6FA); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x08, 0x12, 0xb7af }); } void Kraid_CrumbleRightPlatform_Right(void) { // 0xA7C6FF SpawnEnemyProjectileWithGfx(0x100, cur_enemy_index, addr_kEproj_RocksFallingKraidCeiling); - SpawnHardcodedPlm(&unk_A7C710); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x10, 0x12, 0xb7af }); +} + +void CallKraidSinkTableFunc(uint32 ea) { + switch (ea) { + case fnKraid_CrumbleLeftPlatform_Left: Kraid_CrumbleLeftPlatform_Left(); return; + case fnnullsub_356: return; + case fnKraid_CrumbleRightPlatform_Middle: Kraid_CrumbleRightPlatform_Middle(); return; + case fnKraid_CrumbleRightPlatform_Left: Kraid_CrumbleRightPlatform_Left(); return; + case fnKraid_CrumbleLeftPlatform_Right: Kraid_CrumbleLeftPlatform_Right(); return; + case fnKraid_CrumbleLeftPlatform_Middle: Kraid_CrumbleLeftPlatform_Middle(); return; + case fnKraid_CrumbleRightPlatform_Right: Kraid_CrumbleRightPlatform_Right(); return; + default: Unreachable(); + } } void Kraid_FadeInBg_ClearBg2TilemapTopHalf(void) { // 0xA7C715 @@ -1995,7 +1913,7 @@ void Kraid_FadeInBg_FadeInBp6(void) { // 0xA7C815 int16 v0; if (AdvancePaletteFade_BgPalette6() & 1) { - QueueMusic_Delayed8(3u); + QueueMusic_Delayed8(3); v0 = *(uint16 *)&boss_bits_for_area[area_index]; if ((v0 & 1) != 0) { Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_FadeInBg_SetEnemyDead_KraidWasDead); @@ -2022,12 +1940,6 @@ void Kraid_RestrictSamusXtoFirstScreen(uint16 k) { // 0xA7C865 KraidEnemy_HandleFunctionTimer(k); } -void Kraid_RaiseKraidThroughFloor(uint16 k) { // 0xA7C86B - Kraid_RestrictSamusXtoFirstScreen_2(); - Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_Raise_LoadTilemapBottomAndShake); - Kraid_UpdateBg2TilemapTopHalf(); -} - void Kraid_UpdateBg2TilemapTopHalf(void) { // 0xA7C874 VramWriteEntry *v1; @@ -2040,16 +1952,6 @@ void Kraid_UpdateBg2TilemapTopHalf(void) { // 0xA7C874 vram_write_queue_tail = v0 + 7; } -void Kraid_Raise_LoadTilemapBottomAndShake(void) { // 0xA7C89A - Kraid_RestrictSamusXtoFirstScreen_2(); - Enemy_Kraid *E = Get_Kraid(0); - E->kraid_var_A = FUNC16(Kraid_Raise_SpawnRandomEarthquakeProjs16); - E->kraid_var_F = 120; - earthquake_timer = 496; - QueueMusic_Delayed8(5u); - Kraid_UpdateBG2TilemapBottomHalf(); -} - void Kraid_UpdateBG2TilemapBottomHalf(void) { // 0xA7C8B6 VramWriteEntry *v1; @@ -2062,6 +1964,22 @@ void Kraid_UpdateBG2TilemapBottomHalf(void) { // 0xA7C8B6 vram_write_queue_tail = v0 + 7; } +void Kraid_RaiseKraidThroughFloor(uint16 k) { // 0xA7C86B + Kraid_RestrictSamusXtoFirstScreen_2(); + Get_Kraid(0)->kraid_var_A = FUNC16(Kraid_Raise_LoadTilemapBottomAndShake); + Kraid_UpdateBg2TilemapTopHalf(); +} + +void Kraid_Raise_LoadTilemapBottomAndShake(void) { // 0xA7C89A + Kraid_RestrictSamusXtoFirstScreen_2(); + Enemy_Kraid *E = Get_Kraid(0); + E->kraid_var_A = FUNC16(Kraid_Raise_SpawnRandomEarthquakeProjs16); + E->kraid_var_F = 120; + earthquake_timer = 496; + QueueMusic_Delayed8(5); + Kraid_UpdateBG2TilemapBottomHalf(); +} + void Kraid_Raise_SpawnRandomEarthquakeProjs16(void) { // 0xA7C8E0 Kraid_RestrictSamusXtoFirstScreen_2(); Enemy_Kraid *E = Get_Kraid(0); @@ -2098,40 +2016,32 @@ void Kraid_Raise_Handler(void) { // 0xA7C924 Enemy_Kraid *E0 = Get_Kraid(0); if ((E0->base.y_pos & 2) == 0) v0 = -1; - R18_ = v0; E0->base.x_pos += v0; uint16 y_subpos = E0->base.y_subpos; E0->base.y_subpos = y_subpos + 0x8000; E0->base.y_pos = (__PAIR32__(E0->base.y_pos, y_subpos) - 0x8000) >> 16; if (sign16(E0->base.y_pos - 457)) { E0->base.x_pos = 176; - Enemy_Kraid *E5 = Get_Kraid(0x140u); + Enemy_Kraid *E5 = Get_Kraid(0x140); E5->kraid_var_A = FUNC16(KraidFoot_FirstPhase_Thinking); E5->kraid_var_F = 300; E5->kraid_next = FUNC16(KraidsFoot_PrepareToLungeForward); E0->kraid_var_B = addr_stru_A796DA; Kraid_Mainloop_Thinking_Setup(); - Enemy_Kraid *E1 = Get_Kraid(0x40u); + Enemy_Kraid *E1 = Get_Kraid(0x40); E1->base.current_instruction = addr_kKraid_Ilist_89F3; E1->base.instruction_timer = 1; } } void Kraid_SpawnRandomQuakeProjs(void) { // 0xA7C995 - int16 v0; - - v0 = random_number & 0x3F; + uint16 v0 = random_number & 0x3F; if ((random_number & 2) == 0) v0 = ~v0; - R18_ = Get_Kraid(0)->base.x_pos + v0; - R20_ = (uint16)(random_number & 0x3F00) >> 8; - R20_ = 448 - R20_; - R22_ = 21; - R24_ = 0; - CreateSpriteAtPos(); - uint16 v1 = addr_kEproj_RocksWhenKraidRisesLeft; - if ((random_number & 0x10) != 0) - v1 = addr_kEproj_RocksWhenKraidRisesRight; + uint16 x = Get_Kraid(0)->base.x_pos + v0; + uint16 y = 448 - ((uint16)(random_number & 0x3F00) >> 8); + CreateSpriteAtPos(x, y, 21, 0); + uint16 v1 = ((random_number & 0x10) != 0) ? addr_kEproj_RocksWhenKraidRisesRight : addr_kEproj_RocksWhenKraidRisesLeft; SpawnEnemyProjectileWithGfx(random_number & 0x3F0, cur_enemy_index, v1); } @@ -2142,6 +2052,67 @@ void Kraid_RestrictSamusXtoFirstScreen_2(void) { // 0xA7C9EE } } +void CallKraidFunc(uint32 ea) { + uint16 k = cur_enemy_index; + switch (ea) { + case fnKraid_GetsBig_BreakCeilingPlatforms: Kraid_GetsBig_BreakCeilingPlatforms(); return; // 0x9bc35 + case fnKraid_GetsBig_SetBG2TilemapPrioBits: Kraid_GetsBig_SetBG2TilemapPrioBits(); return; // 0x9bde6 + case fnKraid_GetsBig_FinishUpdateBg2Tilemap: Kraid_GetsBig_FinishUpdateBg2Tilemap(); return; // 0x9be51 + case fnKraid_GetsBig_DrawRoomBg: Kraid_GetsBig_DrawRoomBg(); return; // 0x9bee5 + case fnKraid_GetsBig_FadeInRoomBg: Kraid_GetsBig_FadeInRoomBg(); return; // 0x9c08c + case fnKraid_Mainloop_Thinking: Kraid_Mainloop_Thinking(); return; // 0x9c1b8 + case fnKraid_GetsBig_Thinking: Kraid_GetsBig_Thinking(); return; // 0x9c207 + case fnKraid_Shot_MouthIsOpen: Kraid_Shot_MouthIsOpen(); return; // 0x9c256 + case fnKraid_InitEyeGlowing: Kraid_InitEyeGlowing(); return; // 0x9cf64 + case fnKraid_Shot_GlowHisEye: Kraid_Shot_GlowHisEye(); return; // 0x9cf9f + case fnKraid_Shot_UnglowEye: Kraid_Shot_UnglowEye(); return; // 0x9d0b4 + case fnKraidLint_ProduceLint: KraidLint_ProduceLint(k); return; // 0x9d371 + case fnKraidLint_FireLint: KraidLint_FireLint(k); return; // 0x9d44f + case fnKraidFingernail_WaitForLintXpos: KraidFingernail_WaitForLintXpos(k); return; // 0x9d556 + case fnKraid_AlignEnemyToKraid: Kraid_AlignEnemyToKraid(k); return; // 0x9d5b5 + case fnKraidEnemy_HandleFunctionTimer: KraidEnemy_HandleFunctionTimer(k); return; // 0x9d5e5 + case fnKraidEnemy_DecrementEnemyFunctionTimer: KraidEnemy_DecrementEnemyFunctionTimer(); return; // 0x9d61c + case fnKraidFoot_FirstPhase_Thinking: KraidFoot_FirstPhase_Thinking(k); return; // 0x9d66a + case fnKraidEnemy_ProcessInstrEnemyTimer: KraidEnemy_ProcessInstrEnemyTimer(k); return; // 0x9d67d + case fnKraidsFoot_SecondPhase_Thinking: KraidsFoot_SecondPhase_Thinking(); return; // 0x9d8b2 + case fnKraidsFoot_SecondPhase_WalkingBackwards: KraidsFoot_SecondPhase_WalkingBackwards(); return; // 0x9da2d + case fnKraidsFoot_SecondPhaseSetup_WalkToStartPt: KraidsFoot_SecondPhaseSetup_WalkToStartPt(); return; // 0x9daa2 + case fnKraidsFoot_SecondPhase_Init: KraidsFoot_SecondPhase_Init(); return; // 0x9db2a + case fnKraidsFoot_SecondPhase_WalkForward: KraidsFoot_SecondPhase_WalkForward(); return; // 0x9db40 + case fnKraid_Main_AttackWithMouthOpen: Kraid_Main_AttackWithMouthOpen(); return; // 0x9dbe0 + case fnKraidsFingernail_Init: KraidsFingernail_Init(); return; // 0x9df94 + case fnKraidsFingernail_Fire: KraidsFingernail_Fire(k); return; // 0x9e1ac + case fnKraidsFoot_PrepareToLungeForward: KraidsFoot_PrepareToLungeForward(); return; // 0x9e312 + case fnKraidsFoot_FirstPhase_RetreatFromLunge: KraidsFoot_FirstPhase_RetreatFromLunge(); return; // 0x9e43a + case fnKraid_GetsBig_ReleaseCamera: Kraid_GetsBig_ReleaseCamera(); return; // 0x9e6a7 + case fnKraid_Death_Init: Kraid_Death_Init(); return; // 0x9ec0b + case fnKraid_Death_Fadeout: Kraid_Death_Fadeout(); return; // 0x9ed75 + case fnKraid_Death_UpdateBG2TilemapTopHalf: Kraid_Death_UpdateBG2TilemapTopHalf(); return; // 0x9ef19 + case fnKraid_Death_UpdateBG2TilemapBottomHalf: Kraid_Death_UpdateBG2TilemapBottomHalf(); return; // 0x9ef92 + case fnKraid_Death_SinkThroughFloor: Kraid_Death_SinkThroughFloor(); return; // 0x9f074 + case fnKraid_FadeInBg_ClearBg2TilemapTopHalf: Kraid_FadeInBg_ClearBg2TilemapTopHalf(); return; // 0x9f369 + case fnKraid_FadeInBg_ClearBg2TilemapBottomHalf: Kraid_FadeInBg_ClearBg2TilemapBottomHalf(); return; // 0x9f3ed + case fnKraid_FadeInBg_LoadBg3Tiles1of4: Kraid_FadeInBg_LoadBg3Tiles1of4(); return; // 0x9f448 + case fnKraid_FadeInBg_LoadBg3Tiles2of4: Kraid_FadeInBg_LoadBg3Tiles2of4(); return; // 0x9f4ad + case fnKraid_FadeInBg_LoadBg3Tiles3of4: Kraid_FadeInBg_LoadBg3Tiles3of4(); return; // 0x9f507 + case fnKraid_FadeInBg_LoadBg3Tiles4of4: Kraid_FadeInBg_LoadBg3Tiles4of4(); return; // 0x9f561 + case fnKraid_FadeInBg_FadeInBp6: Kraid_FadeInBg_FadeInBp6(); return; // 0x9f5bb + case fnKraid_FadeInBg_SetEnemyDead_KraidWasAlive: Kraid_FadeInBg_SetEnemyDead_KraidWasAlive(); return; // 0x9f62d + case fnKraid_FadeInBg_SetEnemyDead_KraidWasDead: Kraid_FadeInBg_SetEnemyDead_KraidWasDead(); return; // 0x9f65b + case fnKraid_RestrictSamusXtoFirstScreen: Kraid_RestrictSamusXtoFirstScreen(k); return; // 0x9f694 + case fnKraid_RaiseKraidThroughFloor: Kraid_RaiseKraidThroughFloor(k); return; // 0x9f6a7 + case fnKraid_Raise_LoadTilemapBottomAndShake: Kraid_Raise_LoadTilemapBottomAndShake(); return; // 0x9f71f + case fnKraid_Raise_SpawnRandomEarthquakeProjs16: Kraid_Raise_SpawnRandomEarthquakeProjs16(); return; // 0x9f7b8 + case fnKraid_Raise_SpawnRandomEarthquakeProjs8: Kraid_Raise_SpawnRandomEarthquakeProjs8(); return; // 0x9f805 + case fnKraid_Raise_Handler: Kraid_Raise_Handler(); return; // 0x9f852 + case fnKraidLint_ChargeLint: KraidLint_ChargeLint(k); return; // 0xa7b868 + case fnnullsub_234: return; // 0xa7ba2d + case fnKraidsFoot_FirstPhase_LungeForward: KraidsFoot_FirstPhase_LungeForward(); return; // 0xa7bf5d + case fnnullsub_347: return; + default: Unreachable(); + } +} + void Phantoon_Init(void) { // 0xA7CDF3 int16 j; uint16 k; @@ -2150,7 +2121,7 @@ void Phantoon_Init(void) { // 0xA7CDF3 tilemap_stuff[i >> 1] = 824; for (j = 2046; j >= 0; j -= 2) *(uint16 *)((uint8 *)&kraid_unk9000 + (uint16)j) = 0; - for (k = 30; (k & 0x8000u) == 0; k -= 2) + for (k = 30; (k & 0x8000) == 0; k -= 2) target_palettes[(k >> 1) + 112] = 0; enemy_bg2_tilemap_size = 864; DisableMinimapAndMarkBossRoomAsExplored(); @@ -2159,7 +2130,7 @@ void Phantoon_Init(void) { // 0xA7CDF3 E->phant_var_A = 0; E->phant_var_B = 0; g_word_7E9032 = 0; - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_parameter_1 = 0; E1->phant_parameter_2 = 0; Enemy_Phantoon *E0 = Get_Phantoon(0); @@ -2189,9 +2160,9 @@ void Phantoon_Main(void) { // 0xA7CEA6 CallEnemyPreInstr(EK->phant_var_F | 0xA70000); if (cur_enemy_index == 0) { // code bug: X is overwritten Enemy_Phantoon *E0 = Get_Phantoon(0); - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); Enemy_Phantoon *E2 = Get_Phantoon(0x80); - Enemy_Phantoon *E3 = Get_Phantoon(0xC0u); + Enemy_Phantoon *E3 = Get_Phantoon(0xC0); uint16 x_pos = E0->base.x_pos; E1->base.x_pos = x_pos; E2->base.x_pos = x_pos; @@ -2223,36 +2194,37 @@ void Phantoon_Func_2(uint16 k) { // 0xA7CF0C *(uint16 *)((uint8 *)&g_stru_A7902D[0].ypos + 1) = *(uint16 *)((uint8 *)&g_stru_A7902D[0].ypos + 1) == 0; } -uint8 Phantoon_Func_3(void) { // 0xA7CF27 - Enemy_Phantoon *E = Get_Phantoon(0xC0u); +uint8 Phantoon_Func_3(int32 amt) { // 0xA7CF27 + Enemy_Phantoon *E = Get_Phantoon(0xC0); + uint32 r18 = amt, r20 = amt >> 16; if (E->phant_var_E) { uint16 phant_var_D = E->phant_var_D; - bool v4 = phant_var_D < R18_; - E->phant_var_D = phant_var_D - R18_; + bool v4 = phant_var_D < r18; + E->phant_var_D = phant_var_D - r18; if (v4) { E->phant_var_D = 0; return 1; } } else { - R22_ = (R20_ & 0xFF00) >> 8; - uint16 v1 = R18_ + E->phant_var_D; + uint16 r22 = (r20 & 0xFF00) >> 8; + uint16 v1 = r18 + E->phant_var_D; E->phant_var_D = v1; v1 = (v1 & 0xFF00) >> 8; - if (!sign16(v1 - R22_)) - E->phant_var_D = R20_; + if (!sign16(v1 - r22)) + E->phant_var_D = r20; } return 0; } void Phantoon_Func_4(uint16 k) { // 0xA7CF5E SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_DestroyableFireballs); - QueueSfx3_Max6(0x1Du); + QueueSfx3_Max6(0x1D); } void Phantoon_Func_5(uint16 k) { // 0xA7CF70 for (int i = 7; i >= 0; --i) SpawnEnemyProjectileWithGfx(i | 0x600, k, addr_kEproj_DestroyableFireballs); - QueueSfx3_Max6(0x28u); + QueueSfx3_Max6(0x28); } void Phantoon_Func_6(uint16 k, uint16 a) { // 0xA7CF8B @@ -2260,34 +2232,30 @@ void Phantoon_Func_6(uint16 k, uint16 a) { // 0xA7CF8B int16 v3; v2 = g_byte_A7CFC2[a]; - R18_ = 7; - R20_ = 16; + int n = 7; + int r20 = 16; do { v3 = v2; - SpawnEnemyProjectileWithGfx(R20_ | v2++ | 0x400, k, addr_kEproj_DestroyableFireballs); + SpawnEnemyProjectileWithGfx(r20 | v2++ | 0x400, k, addr_kEproj_DestroyableFireballs); if ((int16)(v3 - 8) >= 0) v2 = 0; - R20_ += 16; - --R18_; - } while ((R18_ & 0x8000u) == 0); + r20 += 16; + } while (--n >= 0); } void Phantoon_Func_7(uint16 k) { // 0xA7CFCA Enemy_Phantoon *E = Get_Phantoon(k + 192); bool v3 = E->phant_var_B == 1; - bool v4 = (--E->phant_var_B & 0x8000u) != 0; + bool v4 = (--E->phant_var_B & 0x8000) != 0; if (v3 || v4) { - if ((E->phant_var_C & 0x8000u) == 0) { + if ((E->phant_var_C & 0x8000) == 0) { v3 = E->phant_var_C == 1; - bool v8 = (--E->phant_var_C & 0x8000u) != 0; + bool v8 = (--E->phant_var_C & 0x8000) != 0; if (v3 || v8) { E->phant_var_C = -1; - E->phant_var_B = *((uint16 *)RomPtr_A7(g_off_A7CCFD[E->phant_var_A]) - + 1); + E->phant_var_B = *((uint16 *)RomPtr_A7(g_off_A7CCFD[E->phant_var_A]) + 1); } else { - R18_ = 2 * E->phant_var_C; - E->phant_var_B = *((uint16 *)RomPtr_A7(R18_ + g_off_A7CCFD[E->phant_var_A]) - + 1); + E->phant_var_B = *((uint16 *)RomPtr_A7(2 * E->phant_var_C + g_off_A7CCFD[E->phant_var_A]) + 1); } E->base.instruction_timer = 1; E->base.current_instruction = addr_kKraid_Ilist_CCEB; @@ -2297,7 +2265,6 @@ void Phantoon_Func_7(uint16 k) { // 0xA7CFCA uint16 v6 = g_off_A7CCFD[v5]; uint16 v7 = *(uint16 *)RomPtr_A7(v6); E->phant_var_C = v7; - R18_ = 2 * v7; E->phant_var_B = *((uint16 *)RomPtr_A7(2 * v7 + v6) + 1); } } @@ -2312,7 +2279,7 @@ void Phantoon_StartTrackingSamusAndInitEyeTimer(void) { // 0xA7D03F E->phant_var_E = g_word_A7CD41[NextRandom() & 7]; E->phant_var_F = FUNC16(Phantoon_EyeFollowsSamusUntilTimerRunsOut); - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->base.instruction_timer = 1; E1->base.current_instruction = addr_kKraid_Ilist_CC9D; } @@ -2323,7 +2290,7 @@ void Phantoon_PickPatternForRound2(void) { // 0xA7D076 Enemy_Phantoon *E = Get_Phantoon(0); E->phant_var_E = 60; uint16 v1 = g_word_A7CD53[NextRandom() & 7]; - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_var_A = v1; if ((nmi_frame_counter_word & 1) != 0) { if (!E1->phant_var_C) { @@ -2357,14 +2324,12 @@ void Phantoon_PickPatternForRound2(void) { // 0xA7D076 } void Phantoon_AdjustSpeedAndMoveInFigure8(void) { // 0xA7D0F1 - if (Get_Phantoon(0x40u)->phant_var_C) { + if (Get_Phantoon(0x40)->phant_var_C) { Phantoon_AdjustSpeedRightSideClockwise(); - R20_ = 533; - Phantoon_MoveInFigure8_RightSideClockwise(addr_kPhantoonMoveData); + Phantoon_MoveInFigure8_RightSideClockwise(addr_kPhantoonMoveData, 533); } else { Phantoon_AdjustSpeedLeftSideClockwise(); - R20_ = 534; - Phantoon_MoveInFigure8_LeftSideClockwise(addr_kPhantoonMoveData); + Phantoon_MoveInFigure8_LeftSideClockwise(addr_kPhantoonMoveData, 534); } } @@ -2450,46 +2415,25 @@ void Phantoon_AdjustSpeedRightSideClockwise(void) { // 0xA7D193 } } -void Phantoon_MoveInFigure8_LeftSideClockwise(uint16 j) { // 0xA7D215 +void Phantoon_MoveInFigure8_LeftSideClockwise(uint16 j, uint16 r20) { // 0xA7D215 Enemy_Phantoon *E = Get_Phantoon(0); - for (R22_ = E->phant_var_C; R22_; --R22_) { - R18_ = 2 * E->phant_var_A; - const uint8 *v2 = RomPtr_A7(R18_ + j); - uint16 v3 = (int8)v2[0]; - R18_ = v3; - E->base.x_pos += v3; - uint16 v4 = (int8)v2[1]; - R18_ = v4; - E->base.y_pos += v4; - uint16 v5 = E->phant_var_A + 1; - E->phant_var_A = v5; - if (!sign16(v5 - R20_)) + for (int n = E->phant_var_C; n; --n) { + const uint8 *v2 = RomPtr_A7(2 * E->phant_var_A + j); + E->base.x_pos += (int8)v2[0]; + E->base.y_pos += (int8)v2[1]; + if (!sign16(++E->phant_var_A - r20)) E->phant_var_A = 0; } } -void Phantoon_MoveInFigure8_RightSideClockwise(uint16 j) { // 0xA7D271 - int16 v7; - +void Phantoon_MoveInFigure8_RightSideClockwise(uint16 j, uint16 r20) { // 0xA7D271 Enemy_Phantoon *E = Get_Phantoon(0); - bool v2 = E->phant_var_C == 0; - R22_ = -E->phant_var_C; - if (!v2) { - do { - R18_ = 2 * E->phant_var_A; - const uint8 *v4 = RomPtr_A7(R18_ + j); - uint16 v5 = (int8)*v4; - R18_ = v5; - E->base.x_pos -= v5; - uint16 v6 = (int8)v4[1]; - R18_ = v6; - E->base.y_pos -= v6; - v7 = E->phant_var_A - 1; - E->phant_var_A = v7; - if (v7 < 0) - E->phant_var_A = R20_; - --R22_; - } while (R22_); + for(int n = -E->phant_var_C; n; n--) { + const uint8 *v4 = RomPtr_A7(2 * E->phant_var_A + j); + E->base.x_pos -= (int8)v4[0]; + E->base.y_pos -= (int8)v4[1]; + if (sign16(--E->phant_var_A)) + E->phant_var_A = r20; } } @@ -2540,12 +2484,12 @@ void Phantoon_MoveInSwoopingPattern(uint16 k) { // 0xA7D2D1 v2->phant_var_C += 32; } v9 = swap16(v2->phant_var_C); - R20_ = v9 & 0xFF00; - R18_ = (int8)v9; + uint16 r20 = v9 & 0xFF00; + uint16 r18 = (int8)v9; x_subpos = v7->base.x_subpos; - v11 = __CFADD__uint16(R20_, x_subpos); - v7->base.x_subpos = R20_ + x_subpos; - v12 = R18_ + v11 + v7->base.x_pos; + v11 = __CFADD__uint16(r20, x_subpos); + v7->base.x_subpos = r20 + x_subpos; + v12 = r18 + v11 + v7->base.x_pos; v7->base.x_pos = v12; if (sign16(v12 + 64)) { v7->base.x_pos = -64; @@ -2563,12 +2507,12 @@ void Phantoon_MoveInSwoopingPattern(uint16 k) { // 0xA7D2D1 v2->phant_var_D += 64; } v14 = swap16(v2->phant_var_D); - R20_ = v14 & 0xFF00; - R18_ = (int8)v14; + r20 = v14 & 0xFF00; + r18 = (int8)v14; y_subpos = v8->base.y_subpos; - v11 = __CFADD__uint16(R20_, y_subpos); - v8->base.y_subpos = R20_ + y_subpos; - v16 = R18_ + v11 + v8->base.y_pos; + v11 = __CFADD__uint16(r20, y_subpos); + v8->base.y_subpos = r20 + y_subpos; + v16 = r18 + v11 + v8->base.y_pos; v8->base.y_pos = v16; if (sign16(v16 - 64)) { v8->base.y_pos = 64; @@ -2589,7 +2533,7 @@ void Phantoon_BeginSwoopingPattern(uint16 k) { // 0xA7D3E1 void Phantoon_ChangeEyeSpriteBasedOnSamusDist(void) { // 0xA7D3FA uint16 v0 = 2 * DetermineDirectionOfSamusFromEnemy(); - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); E->base.instruction_timer = 1; E->base.current_instruction = g_off_A7D40D[v0 >> 1]; } @@ -2604,7 +2548,7 @@ void Phantoon_StartDeathSequence(uint16 k) { // 0xA7D421 } else { E->phant_var_F = FUNC16(Phantoon_DyingPhantoonFadeInOut); } - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_var_C = 0; E1->phant_var_F = 0; Phantoon_ChangeEyeSpriteBasedOnSamusDist(); @@ -2614,16 +2558,15 @@ void Phantoon_StartDeathSequence(uint16 k) { // 0xA7D421 *(uint16 *)((uint8 *)&g_word_7E9100 + (uint16)v3) = v4; v3 -= 2; } while (v3 >= 0); - phantom_related_layer_flag |= 0x4000u; - Get_Phantoon(0xC0u)->phant_parameter_2 = 1; + phantom_related_layer_flag |= 0x4000; + Get_Phantoon(0xC0)->phant_parameter_2 = 1; } void Phantoon_FadeOut(uint16 a) { // 0xA7D464 - R18_ = a; if ((nmi_frame_counter_word & 1) == 0) { - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); if (!E->phant_var_F) { - E->phant_var_D = R18_; + E->phant_var_D = a; if (Phantoon_Func_8() & 1) E->phant_var_F = 1; } @@ -2631,11 +2574,10 @@ void Phantoon_FadeOut(uint16 a) { // 0xA7D464 } void Phantoon_FadeIn(uint16 a) { // 0xA7D486 - R18_ = a; if ((nmi_frame_counter_word & 1) == 0) { - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); if (!E->phant_var_F) { - E->phant_var_D = R18_; + E->phant_var_D = a; if (Phantoon_SetColorBasedOnHp() & 1) E->phant_var_F = 1; } @@ -2645,11 +2587,11 @@ void Phantoon_FadeIn(uint16 a) { // 0xA7D486 void Phantoon_Spawn8FireballsInCircleAtStart(uint16 k) { // 0xA7D4A9 Enemy_Phantoon *EK = Get_Phantoon(k); bool v2 = EK->phant_var_E == 1; - bool v3 = (--EK->phant_var_E & 0x8000u) != 0; + bool v3 = (--EK->phant_var_E & 0x8000) != 0; if (v2 || v3) { Enemy_Phantoon *E0 = Get_Phantoon(0); SpawnEnemyProjectileWithGfx(E0->phant_var_A, k, addr_kEproj_StartingFireballs); - QueueSfx3_Max6(0x1Du); + QueueSfx3_Max6(0x1D); EK->phant_var_E = 30; uint16 v5 = E0->phant_var_A + 1; E0->phant_var_A = v5; @@ -2658,8 +2600,7 @@ void Phantoon_Spawn8FireballsInCircleAtStart(uint16 k) { // 0xA7D4A9 Get_Phantoon(k + 128)->phant_var_B = 0; EK->phant_var_F = FUNC16(Phantoon_WaitBetweenSpawningAndSpinningFireballs); EK->phant_var_E = 30; - static const SpawnHardcodedPlmArgs unk_A7D4E9 = { 0x00, 0x06, 0xb781 }; - SpawnHardcodedPlm(&unk_A7D4E9); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x00, 0x06, 0xb781 }); } } } @@ -2667,7 +2608,7 @@ void Phantoon_Spawn8FireballsInCircleAtStart(uint16 k) { // 0xA7D4A9 void Phantoon_WaitBetweenSpawningAndSpinningFireballs(uint16 k) { // 0xA7D4EE Enemy_Phantoon *E = Get_Phantoon(k); bool v2 = E->phant_var_E == 1; - bool v3 = (--E->phant_var_E & 0x8000u) != 0; + bool v3 = (--E->phant_var_E & 0x8000) != 0; if (v2 || v3) { E->phant_var_E = 240; E->phant_var_B = 1; @@ -2678,46 +2619,43 @@ void Phantoon_WaitBetweenSpawningAndSpinningFireballs(uint16 k) { // 0xA7D4EE void Phantoon_SpawnFireballsBeforeFight(uint16 k) { // 0xA7D508 Enemy_Phantoon *EK = Get_Phantoon(k); bool v3 = EK->phant_var_E == 1; - bool v4 = (--EK->phant_var_E & 0x8000u) != 0; + bool v4 = (--EK->phant_var_E & 0x8000) != 0; if (v3 || v4) { EK->phant_var_B = 0; - phantom_related_layer_flag |= 0x4000u; + phantom_related_layer_flag |= 0x4000; EK->phant_var_F = FUNC16(Phantoon_WavyFadeIn); - Enemy_Phantoon *E3 = Get_Phantoon(0xC0u); + Enemy_Phantoon *E3 = Get_Phantoon(0xC0); E3->phant_parameter_1 = -32767; EK->phant_var_E = 120; - R22_ = g_word_A7CDA3; - sub_88E487(2u); + sub_88E487(2, g_word_A7CDA3); E3->phant_var_D = g_word_A7CD9D; - Get_Phantoon(0x40u)->phant_var_F = 0; - QueueMusic_Delayed8(5u); + Get_Phantoon(0x40)->phant_var_F = 0; + QueueMusic_Delayed8(5); } } void Phantoon_WavyFadeIn(uint16 k) { // 0xA7D54A - Phantoon_FadeIn(0xCu); - R18_ = g_word_A7CD9B; - R20_ = g_word_A7CD9D; - if (Phantoon_Func_3() & 1) { + Phantoon_FadeIn(0xC); +if (Phantoon_Func_3(__PAIR32__(g_word_A7CD9D, g_word_A7CD9B))) { Enemy_Phantoon *E = Get_Phantoon(k); E->phant_var_F = FUNC16(Phantoon_PickPatternForRound1); - Get_Phantoon(0xC0u)->phant_parameter_1 = 1; + Get_Phantoon(0xC0)->phant_parameter_1 = 1; E->phant_var_E = 30; } else { Enemy_Phantoon *E = Get_Phantoon(k); bool v2 = E->phant_var_E == 1; - bool v3 = (--E->phant_var_E & 0x8000u) != 0; + bool v3 = (--E->phant_var_E & 0x8000) != 0; if (v2 || v3) - Get_Phantoon(0xC0u)->phant_var_E = 1; + Get_Phantoon(0xC0)->phant_var_E = 1; } } void Phantoon_PickPatternForRound1(uint16 k) { // 0xA7D596 Enemy_Phantoon *EK = Get_Phantoon(k); bool v2 = EK->phant_var_E == 1; - bool v3 = (--EK->phant_var_E & 0x8000u) != 0; + bool v3 = (--EK->phant_var_E & 0x8000) != 0; if (v2 || v3) { - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_parameter_1 = 0; EK->phant_var_F = FUNC16(Phantoon_MovePhantoonInFigure8ThenOpenEye); E1->phant_var_A = g_word_A7CD53[(nmi_frame_counter_word >> 1) & 3]; @@ -2742,9 +2680,9 @@ void Phantoon_PickPatternForRound1(uint16 k) { // 0xA7D596 void Phantoon_MovePhantoonInFigure8ThenOpenEye(uint16 k) { // 0xA7D5E7 Phantoon_AdjustSpeedAndMoveInFigure8(); Phantoon_Func_7(k); - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); bool v2 = E->phant_var_A == 1; - bool v3 = (--E->phant_var_A & 0x8000u) != 0; + bool v3 = (--E->phant_var_A & 0x8000) != 0; if (v2 || v3) { Get_Phantoon(k)->phant_var_F = FUNC16(nullsub_237); E->base.instruction_timer = 1; @@ -2757,7 +2695,7 @@ void Phantoon_MovePhantoonInFigure8ThenOpenEye(uint16 k) { // 0xA7D5E7 void Phantoon_EyeFollowsSamusUntilTimerRunsOut(uint16 k) { // 0xA7D60D Enemy_Phantoon *EK = Get_Phantoon(k); bool v2 = EK->phant_var_E == 1; - bool v3 = (--EK->phant_var_E & 0x8000u) != 0; + bool v3 = (--EK->phant_var_E & 0x8000) != 0; if (v2 || v3) { Get_Phantoon(k + 128)->phant_var_B = 0; Enemy_Phantoon *E2 = Get_Phantoon(0x80); @@ -2765,7 +2703,7 @@ void Phantoon_EyeFollowsSamusUntilTimerRunsOut(uint16 k) { // 0xA7D60D EK->phant_var_F = FUNC16(nullsub_237); Enemy_Phantoon *E0 = Get_Phantoon(0); E0->base.instruction_timer = 1; - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->base.instruction_timer = 1; E0->base.current_instruction = addr_kKraid_Ilist_CC41; E1->base.current_instruction = addr_kKraid_Ilist_CC81; @@ -2782,7 +2720,7 @@ void Phantoon_EyeFollowsSamusUntilTimerRunsOut(uint16 k) { // 0xA7D60D void Phantoon_BecomesSolidAndBodyVuln(uint16 v0) { // 0xA7D65C Phantoon_ChangeEyeSpriteBasedOnSamusDist(); - phantom_related_layer_flag &= ~0x4000u; + phantom_related_layer_flag &= ~0x4000; Phantoon_BeginSwoopingPattern(v0); Enemy_Phantoon *E = Get_Phantoon(0); E->base.instruction_timer = 1; @@ -2794,13 +2732,13 @@ void Phantoon_IsSwooping(uint16 k) { // 0xA7D678 Phantoon_MoveInSwoopingPattern(k); Enemy_Phantoon *EK = Get_Phantoon(k); bool v2 = EK->phant_var_E == 1; - bool v3 = (--EK->phant_var_E & 0x8000u) != 0; + bool v3 = (--EK->phant_var_E & 0x8000) != 0; if (v2 || v3) { EK->phant_var_F = FUNC16(Phantoon_FadeoutWithSwoop); - phantom_related_layer_flag |= 0x4000u; + phantom_related_layer_flag |= 0x4000; Enemy_Phantoon *E0 = Get_Phantoon(0); E0->base.instruction_timer = 1; - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->base.instruction_timer = 1; E0->base.current_instruction = addr_kKraid_Ilist_CC41; E1->base.current_instruction = addr_kKraid_Ilist_CC91; @@ -2812,8 +2750,8 @@ void Phantoon_IsSwooping(uint16 k) { // 0xA7D678 void Phantoon_FadeoutWithSwoop(uint16 k) { // 0xA7D6B9 Phantoon_MoveInSwoopingPattern(k); - Phantoon_FadeOut(0xCu); - if (Get_Phantoon(0x40u)->phant_var_F) { + Phantoon_FadeOut(0xC); + if (Get_Phantoon(0x40)->phant_var_F) { Enemy_Phantoon *E = Get_Phantoon(k); E->phant_var_F = FUNC16(Phantoon_WaitAfterFadeOut); E->phant_var_E = 120; @@ -2823,7 +2761,7 @@ void Phantoon_FadeoutWithSwoop(uint16 k) { // 0xA7D6B9 void Phantoon_WaitAfterFadeOut(uint16 k) { // 0xA7D6D4 Enemy_Phantoon *E = Get_Phantoon(k); bool v2 = E->phant_var_E == 1; - bool v3 = (--E->phant_var_E & 0x8000u) != 0; + bool v3 = (--E->phant_var_E & 0x8000) != 0; if (v2 || v3) E->phant_var_F = FUNC16(Phantoon_MoveLeftOrRightAndPickEyeOpenPatt); } @@ -2838,7 +2776,7 @@ void Phantoon_MoveLeftOrRightAndPickEyeOpenPatt(uint16 k) { // 0xA7D6E2 E->base.x_pos = 48; } E->base.y_pos = 96; - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_var_C = 0; E->phant_var_C = 1; E->phant_var_B = 0; @@ -2849,15 +2787,15 @@ void Phantoon_MoveLeftOrRightAndPickEyeOpenPatt(uint16 k) { // 0xA7D6E2 } void Phantoon_FadeInBeforeFigure8(uint16 k) { // 0xA7D72D - Phantoon_FadeIn(0xCu); - if (Get_Phantoon(0x40u)->phant_var_F) + Phantoon_FadeIn(0xC); + if (Get_Phantoon(0x40)->phant_var_F) Get_Phantoon(0)->phant_var_F = FUNC16(Phantoon_MovePhantoonInFigure8ThenOpenEye); } void Phantoon_BecomeSolidAfterRainingFireballs(uint16 k) { // 0xA7D73F - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_var_F = 0; - phantom_related_layer_flag &= ~0x4000u; + phantom_related_layer_flag &= ~0x4000; Enemy_Phantoon *E = Get_Phantoon(0); E->base.instruction_timer = 1; E1->base.instruction_timer = 1; @@ -2867,8 +2805,8 @@ void Phantoon_BecomeSolidAfterRainingFireballs(uint16 k) { // 0xA7D73F } void Phantoon_FadeInDuringFireballRain(uint16 k) { // 0xA7D767 - Phantoon_FadeIn(1u); - if (Get_Phantoon(0x40u)->phant_var_F) { + Phantoon_FadeIn(1); + if (Get_Phantoon(0x40)->phant_var_F) { Enemy_Phantoon *E = Get_Phantoon(0); E->base.properties &= ~kEnemyProps_Tangible; Get_Phantoon(k)->phant_var_F = FUNC16(Phantoon_FollowSamusWithEyeDuringFireballRain); @@ -2879,7 +2817,7 @@ void Phantoon_FadeInDuringFireballRain(uint16 k) { // 0xA7D767 void Phantoon_FollowSamusWithEyeDuringFireballRain(uint16 k) { // 0xA7D788 Enemy_Phantoon *EK = Get_Phantoon(k); bool v2 = EK->phant_var_E == 1; - bool v3 = (--EK->phant_var_E & 0x8000u) != 0; + bool v3 = (--EK->phant_var_E & 0x8000) != 0; if (v2 || v3) { Get_Phantoon(k + 128)->phant_var_B = 0; Enemy_Phantoon *E2 = Get_Phantoon(0x80); @@ -2889,7 +2827,7 @@ void Phantoon_FollowSamusWithEyeDuringFireballRain(uint16 k) { // 0xA7D788 Phantoon_BeginSwoopingPattern(k); } else { EK->phant_var_F = FUNC16(Phantoon_FadeOutDuringFireballRain); - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_var_F = 0; Enemy_Phantoon *E0 = Get_Phantoon(0); E0->base.instruction_timer = 1; @@ -2897,14 +2835,14 @@ void Phantoon_FollowSamusWithEyeDuringFireballRain(uint16 k) { // 0xA7D788 E0->base.current_instruction = addr_kKraid_Ilist_CC41; E1->base.current_instruction = addr_kKraid_Ilist_CC91; E0->base.properties |= kEnemyProps_Tangible; - phantom_related_layer_flag |= 0x4000u; + phantom_related_layer_flag |= 0x4000; } } } void Phantoon_FadeOutDuringFireballRain(uint16 k) { // 0xA7D7D5 - Phantoon_FadeOut(0xCu); - if (Get_Phantoon(0x40u)->phant_var_F) { + Phantoon_FadeOut(0xC); + if (Get_Phantoon(0x40)->phant_var_F) { Enemy_Phantoon *E = Get_Phantoon(k); E->phant_var_F = FUNC16(Phantoon_SpawnRainingFireballs); E->phant_var_E = g_word_A7CD63[NextRandom() & 7]; @@ -2914,40 +2852,40 @@ void Phantoon_FadeOutDuringFireballRain(uint16 k) { // 0xA7D7D5 void Phantoon_SpawnRainingFireballs(uint16 k) { // 0xA7D7F7 Enemy_Phantoon *EK = Get_Phantoon(k); bool v2 = EK->phant_var_E == 1; - bool v3 = (--EK->phant_var_E & 0x8000u) != 0; + bool v3 = (--EK->phant_var_E & 0x8000) != 0; if (v2 || v3) { uint16 a = NextRandom() & 7; - int v4 = (uint16)(8 * a) >> 1; + int v4 = (8 * a) >> 1; Enemy_Phantoon *E0 = Get_Phantoon(0); E0->phant_var_A = g_word_A7CDAD[v4]; E0->base.x_pos = g_word_A7CDAD[v4 + 1]; E0->base.y_pos = g_word_A7CDAD[v4 + 2]; - Get_Phantoon(0x40u)->phant_var_C = 0; + Get_Phantoon(0x40)->phant_var_C = 0; EK->phant_var_F = FUNC16(Phantoon_BecomeSolidAfterRainingFireballs); Phantoon_Func_6(k, a); } } void Phantoon_FadeOutBeforeFirstFireballRain(uint16 k) { // 0xA7D82A - Phantoon_FadeOut(0xCu); + Phantoon_FadeOut(0xC); Phantoon_AdjustSpeedAndMoveInFigure8(); Phantoon_Func_7(k); - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); bool v2 = E->phant_var_A == 1; - bool v3 = (--E->phant_var_A & 0x8000u) != 0; + bool v3 = (--E->phant_var_A & 0x8000) != 0; if (v2 || v3) { Get_Phantoon(0x80)->phant_var_A = 0; Get_Phantoon(k)->phant_var_F = FUNC16(Phantoon_BecomeSolidAfterRainingFireballs); if (sign16(Get_Phantoon(0)->base.x_pos - 128)) Phantoon_Func_6(k, 0); else - Phantoon_Func_6(k, 2u); + Phantoon_Func_6(k, 2); } } void Phantoon_FadeOutBeforeEnrage(uint16 k) { // 0xA7D85C - Phantoon_FadeOut(0xCu); - if (Get_Phantoon(0x40u)->phant_var_F) { + Phantoon_FadeOut(0xC); + if (Get_Phantoon(0x40)->phant_var_F) { Enemy_Phantoon *E = Get_Phantoon(k); E->phant_var_F = FUNC16(Phantoon_MoveEnragedPhantoonToTopCenter); E->phant_var_E = 120; @@ -2957,19 +2895,19 @@ void Phantoon_FadeOutBeforeEnrage(uint16 k) { // 0xA7D85C void Phantoon_MoveEnragedPhantoonToTopCenter(uint16 k) { // 0xA7D874 Enemy_Phantoon *E = Get_Phantoon(k); bool v2 = E->phant_var_E == 1; - bool v3 = (--E->phant_var_E & 0x8000u) != 0; + bool v3 = (--E->phant_var_E & 0x8000) != 0; if (v2 || v3) { E->phant_var_F = FUNC16(Phantoon_FadeInEnragedPhantoon); Enemy_Phantoon *E = Get_Phantoon(0); E->base.x_pos = 128; E->base.y_pos = 32; - Get_Phantoon(0x40u)->phant_var_F = 0; + Get_Phantoon(0x40)->phant_var_F = 0; } } void Phantoon_FadeInEnragedPhantoon(uint16 k) { // 0xA7D891 - Phantoon_FadeIn(0xCu); - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Phantoon_FadeIn(0xC); + Enemy_Phantoon *E = Get_Phantoon(0x40); if (E->phant_var_F) { Get_Phantoon(0)->phant_var_F = FUNC16(Phantoon_Enraged); Get_Phantoon(k)->phant_var_E = 4; @@ -2983,9 +2921,9 @@ void Phantoon_Enraged(uint16 k) { // 0xA7D8AC Enemy_Phantoon *E = Get_Phantoon(k); bool v2 = E->phant_var_E == 1; - bool v3 = (--E->phant_var_E & 0x8000u) != 0; + bool v3 = (--E->phant_var_E & 0x8000) != 0; if (v2 || v3) { - if ((Get_Phantoon(0x40u)->phant_var_F & 1) != 0) { + if ((Get_Phantoon(0x40)->phant_var_F & 1) != 0) { v5 = 15; do { v8 = v5; @@ -2995,8 +2933,8 @@ void Phantoon_Enraged(uint16 k) { // 0xA7D8AC for (int i = 6; i >= 0; --i) SpawnEnemyProjectileWithGfx(i | 0x200, k, addr_kEproj_DestroyableFireballs); } - QueueSfx3_Max6(0x29u); - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + QueueSfx3_Max6(0x29); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); uint16 v7 = E1->phant_var_F + 1; E1->phant_var_F = v7; if (sign16(v7 - 8)) { @@ -3011,8 +2949,8 @@ void Phantoon_Enraged(uint16 k) { // 0xA7D8AC } void Phantoon_FadeoutAfterEnrage(uint16 k) { // 0xA7D916 - Phantoon_FadeOut(0xCu); - if (Get_Phantoon(0x40u)->phant_var_F) { + Phantoon_FadeOut(0xC); + if (Get_Phantoon(0x40)->phant_var_F) { Enemy_Phantoon *E = Get_Phantoon(k); E->phant_var_F = FUNC16(Phantoon_WaitAfterFadeOut); E->phant_var_E = 120; @@ -3030,13 +2968,13 @@ void Phantoon_CompleteSwoopAfterFatalShot(uint16 k) { // 0xA7D92E } void Phantoon_DyingPhantoonFadeInOut(uint16 k) { // 0xA7D948 - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); if ((E1->phant_var_C & 1) != 0) { - Phantoon_FadeIn(0xCu); + Phantoon_FadeIn(0xC); if (!E1->phant_var_F) return; } else { - Phantoon_FadeOut(0xCu); + Phantoon_FadeOut(0xC); if (!E1->phant_var_F) return; } @@ -3055,19 +2993,18 @@ void Phantoon_DyingPhantoonFadeInOut(uint16 k) { // 0xA7D948 void Phantoon_DyingPhantoonExplosions(uint16 k) { // 0xA7D98B Enemy_Phantoon *EK = Get_Phantoon(k); bool v2 = EK->phant_var_E == 1; - bool v3 = (--EK->phant_var_E & 0x8000u) != 0; + bool v3 = (--EK->phant_var_E & 0x8000) != 0; if (v2 || v3) { Enemy_Phantoon *E2 = Get_Phantoon(0x80); uint16 v5 = 4 * E2->phant_var_F; Enemy_Phantoon *E0 = Get_Phantoon(0); - R18_ = (int8)g_byte_A7DA1D[v5] + E0->base.x_pos; - R20_ = (int8)g_byte_A7DA1D[v5 + 1] + E0->base.y_pos; + eproj_spawn_pt = (Point16U){ (int8)g_byte_A7DA1D[v5] + E0->base.x_pos, (int8)g_byte_A7DA1D[v5 + 1] + E0->base.y_pos }; uint16 v11 = g_byte_A7DA1D[v5 + 2]; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, v11); if (v11 == 29) - QueueSfx2_Max6(0x24u); + QueueSfx2_Max6(0x24); else - QueueSfx2_Max6(0x2Bu); + QueueSfx2_Max6(0x2B); EK->phant_var_E = g_byte_A7DA1D[v5 + 3]; uint16 v9 = E2->phant_var_F + 1; E2->phant_var_F = v9; @@ -3084,26 +3021,23 @@ void Phantoon_DyingPhantoonExplosions(uint16 k) { // 0xA7D98B void Phantoon_WavyDyingPhantoonAndCry(uint16 k) { // 0xA7DA51 Enemy_Phantoon *Phantoon; // r10 - R22_ = g_word_A7CDA3; - sub_88E487(1u); - Get_Phantoon(0xC0u)->phant_var_D = 0; + sub_88E487(1, g_word_A7CDA3); + Get_Phantoon(0xC0)->phant_var_D = 0; Get_Phantoon(k)->phant_var_F = FUNC16(Phantoon_DyingFadeOut); - Phantoon = Get_Phantoon(0x40u); + Phantoon = Get_Phantoon(0x40); Phantoon->phant_var_C = 2; uint16 v2 = Get_Phantoon(0)->base.properties & ~(kEnemyProps_DisableSamusColl | kEnemyProps_Tangible | kEnemyProps_Invisible) | kEnemyProps_Tangible | kEnemyProps_Invisible; Phantoon->base.properties = v2; Get_Phantoon(0x80)->base.properties = v2; - Get_Phantoon(0xC0u)->base.properties = v2; - QueueSfx2_Max6(0x7Eu); + Get_Phantoon(0xC0)->base.properties = v2; + QueueSfx2_Max6(0x7E); } void Phantoon_DyingFadeOut(uint16 k) { // 0xA7DA86 - R18_ = g_word_A7CD9F; - R20_ = g_word_A7CDA1; - Phantoon_Func_3(); - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Phantoon_Func_3(__PAIR32__(g_word_A7CDA1, g_word_A7CD9F)); + Enemy_Phantoon *E = Get_Phantoon(0x40); if (E->phant_var_C == 0xFFFF) { - Phantoon_FadeOut(0xCu); + Phantoon_FadeOut(0xC); if (E->phant_var_F) Get_Phantoon(k)->phant_var_F = FUNC16(Phantoon_AlmostDead); } else if ((nmi_frame_counter_word & 0xF) == 0) { @@ -3120,10 +3054,10 @@ void Phantoon_DyingFadeOut(uint16 k) { // 0xA7DA86 void Phantoon_AlmostDead(uint16 k) { // 0xA7DAD7 reg_MOSAIC = 0; - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_parameter_1 = 0; - phantom_related_layer_flag &= ~0x4000u; - Get_Phantoon(0xC0u)->phant_parameter_1 = -1; + phantom_related_layer_flag &= ~0x4000; + Get_Phantoon(0xC0)->phant_parameter_1 = -1; Enemy_Phantoon *EK = Get_Phantoon(k); EK->phant_var_F = FUNC16(Phantoon_Dead); EK->phant_var_E = 60; @@ -3148,29 +3082,28 @@ void Phantoon_Dead(uint16 k) { // 0xA7DB3D if (EK->phant_var_E) { --EK->phant_var_E; } else if ((nmi_frame_counter_word & 3) == 0) { - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); + Enemy_Phantoon *E1 = Get_Phantoon(0x40); E1->phant_var_D = 12; if (Phantoon_Func_9() & 1) { - reg_TM |= 2u; + reg_TM |= 2; Enemy_ItemDrop_Phantoon(k); Enemy_Phantoon *E0 = Get_Phantoon(0); uint16 v4 = E0->base.properties | kEnemyProps_Deleted; E0->base.properties = v4; E1->base.properties = v4; Get_Phantoon(0x80)->base.properties = v4; - Get_Phantoon(0xC0u)->base.properties = v4; - *(uint16 *)&boss_bits_for_area[area_index] |= 1u; - static const SpawnHardcodedPlmArgs unk_A7DB8D = { 0x00, 0x06, 0xb78b }; - SpawnHardcodedPlm(&unk_A7DB8D); - QueueMusic_Delayed8(3u); + Get_Phantoon(0xC0)->base.properties = v4; + *(uint16 *)&boss_bits_for_area[area_index] |= 1; + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x00, 0x06, 0xb78b }); + QueueMusic_Delayed8(3); } } } uint8 Phantoon_Func_8(void) { // 0xA7DB9A - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); if ((uint16)(E->phant_var_D + 1) >= E->phant_var_E) { - for (int i = 0; i < 0x20u; i += 2) { + for (int i = 0; i < 0x20; i += 2) { palette_buffer[(i >> 1) + 112] = Phantoon_Func_10_CalculateNthTransitionColorFromXtoY(E->phant_var_E, palette_buffer[(i >> 1) + 112], @@ -3187,7 +3120,7 @@ uint8 Phantoon_Func_8(void) { // 0xA7DB9A uint8 Phantoon_SetColorBasedOnHp(void) { // 0xA7DBD5 PairU16 Entry; - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); if ((uint16)(E->phant_var_D + 1) >= E->phant_var_E) { uint16 v2 = 0, v7; do { @@ -3197,7 +3130,7 @@ uint8 Phantoon_SetColorBasedOnHp(void) { // 0xA7DBD5 uint16 v5 = palette_buffer[(Entry.k >> 1) + 112]; palette_buffer[(v7 >> 1) + 112] = Phantoon_Func_10_CalculateNthTransitionColorFromXtoY(E->phant_var_E, v5, j); v2 = v7 + 2; - } while ((uint16)(v7 + 2) < 0x20u); + } while ((uint16)(v7 + 2) < 0x20); ++E->phant_var_E; return 0; } else { @@ -3207,24 +3140,23 @@ uint8 Phantoon_SetColorBasedOnHp(void) { // 0xA7DBD5 } PairU16 Phantoon_SetColorBasedOnHp_FindEntry(uint16 k) { // 0xA7DC0F - R24_ = k; - R18_ = 312; - R20_ = 312; - R22_ = 0; + uint16 r24 = k; + uint16 r18 = 312, r20 = 312; + uint16 r22 = 0; do { - if ((int16)(R20_ - Get_Phantoon(cur_enemy_index)->base.health) >= 0) + if ((int16)(r20 - Get_Phantoon(cur_enemy_index)->base.health) >= 0) break; - R20_ += R18_; - ++R22_; - } while (sign16(R22_ - 7)); - const uint16 *v1 = (const uint16 *)RomPtr_A7(R24_ + g_off_A7DC4A[R22_]); - return MakePairU16(R24_, *v1); + r20 += r18; + ++r22; + } while (sign16(r22 - 7)); + const uint16 *v1 = (const uint16 *)RomPtr_A7(r24 + g_off_A7DC4A[r22]); + return MakePairU16(r24, *v1); } uint8 Phantoon_Func_9(void) { // 0xA7DC5A - Enemy_Phantoon *E = Get_Phantoon(0x40u); + Enemy_Phantoon *E = Get_Phantoon(0x40); if ((uint16)(E->phant_var_D + 1) >= E->phant_var_E) { - for (int i = 0; i < 0xE0u; i += 2) { + for (int i = 0; i < 0xE0; i += 2) { palette_buffer[i >> 1] = Phantoon_Func_10_CalculateNthTransitionColorFromXtoY( E->phant_var_E, palette_buffer[i >> 1], @@ -3245,20 +3177,18 @@ uint16 Phantoon_Func_10_CalculateNthTransitionColorFromXtoY(uint16 a, uint16 k, } uint16 Phantoon_CalculateNthTransitionColorComponentFromXtoY(uint16 a, uint16 k, uint16 j) { // 0xA7DCF1 - int16 v4; - if (!a) return k; - v4 = a - 1; - Enemy_Phantoon *E = Get_Phantoon(0x40u); + uint16 v4 = a - 1; + Enemy_Phantoon *E = Get_Phantoon(0x40); if (v4 == E->phant_var_D) return j; - R20_ = v4 + 1; - R18_ = j - k; - uint8 v6 = abs16(R18_); - uint16 RegWord = SnesDivide(v6 << 8, LOBYTE(E->phant_var_D) - R20_ + 1); - R18_ = sign16(R18_) ? -RegWord : RegWord; - return (uint16)(R18_ + swap16(k)) >> 8; + uint16 r20 = v4 + 1; + uint16 r18 = j - k; + uint8 v6 = abs16(r18); + uint16 RegWord = SnesDivide(v6 << 8, LOBYTE(E->phant_var_D) - r20 + 1); + r18 = sign16(r18) ? -RegWord : RegWord; + return (uint16)(r18 + swap16(k)) >> 8; } void Phantoon_Hurt(void) { // 0xA7DD3F @@ -3286,7 +3216,7 @@ LABEL_4:; for (int i = 30; i >= 0; i -= 2) palette_buffer[(i >> 1) + 112] = 0x7FFF; Enemy_Phantoon *E3 = Get_Phantoon(0x80); - E3->phant_parameter_2 |= 0x100u; + E3->phant_parameter_2 |= 0x100; } } @@ -3297,79 +3227,77 @@ void Phantoon_Touch(void) { // 0xA7DD95 void Phantoon_Shot(void) { // 0xA7DD9B Enemy_Phantoon *E0 = Get_Phantoon(0); - if (sign16(E0->phant_var_F + 0x26B8)) { - uint16 v1 = cur_enemy_index; - Enemy_Phantoon *EK = Get_Phantoon(cur_enemy_index); - uint16 health = EK->base.health; - NormalEnemyShotAiSkipDeathAnim_CurEnemy(); - R18_ = health; - if (!EK->base.health) { - QueueSfx2_Max6(0x73u); - Get_Phantoon(0x80)->phant_parameter_2 = 1; - E0->base.properties |= kEnemyProps_Tangible; - Phantoon_StartDeathSequence(v1); - return; - } - if ((EK->base.ai_handler_bits & 2) != 0) { - QueueSfx2_Max6(0x73u); - uint16 phanto_var_F = EK->phant_var_F; - if (phanto_var_F != FUNC16(Phantoon_EyeFollowsSamusUntilTimerRunsOut) - && phanto_var_F != FUNC16(Phantoon_FollowSamusWithEyeDuringFireballRain)) { - if (phanto_var_F != FUNC16(Phantoon_IsSwooping)) { + if (!sign16(E0->phant_var_F + 0x26B8)) + return; + uint16 v1 = cur_enemy_index; + Enemy_Phantoon *EK = Get_Phantoon(cur_enemy_index); + uint16 health = EK->base.health; + NormalEnemyShotAiSkipDeathAnim_CurEnemy(); + if (!EK->base.health) { + QueueSfx2_Max6(0x73); + Get_Phantoon(0x80)->phant_parameter_2 = 1; + E0->base.properties |= kEnemyProps_Tangible; + Phantoon_StartDeathSequence(v1); + return; + } + if ((EK->base.ai_handler_bits & 2) != 0) { + QueueSfx2_Max6(0x73); + uint16 phanto_var_F = EK->phant_var_F; + if (phanto_var_F != FUNC16(Phantoon_EyeFollowsSamusUntilTimerRunsOut) + && phanto_var_F != FUNC16(Phantoon_FollowSamusWithEyeDuringFireballRain)) { + if (phanto_var_F != FUNC16(Phantoon_IsSwooping)) { LABEL_20: - Get_Phantoon(0x80)->phant_parameter_2 = 2; - return; - } - R18_ -= EK->base.health; - if (sign16(R18_ - 300) - || (projectile_type[collision_detection_index] & 0xF00) != 512) { - Enemy_Phantoon *E2 = Get_Phantoon(v1 + 0x80); - uint16 v7 = R18_ + E2->phant_var_B; - E2->phant_var_B = v7; - if (!sign16(v7 - 300)) - EK->phant_var_E = 1; - goto LABEL_20; - } - goto LABEL_23; + Get_Phantoon(0x80)->phant_parameter_2 = 2; + return; } - R18_ -= EK->base.health; - if (!sign16(R18_ - 300) - && (projectile_type[collision_detection_index] & 0xF00) == 512) { -LABEL_23: - EK->phant_var_F = FUNC16(Phantoon_FadeOutBeforeEnrage); - goto LABEL_22; - } - Enemy_Phantoon *E2; - E2 = Get_Phantoon(v1 + 0x80); - uint16 v9; - v9 = R18_ + E2->phant_var_B; - E2->phant_var_B = v9; - if (!sign16(v9 - 300)) { - EK->phant_var_F = FUNC16(Phantoon_FadeoutWithSwoop); -LABEL_22: - EK->phant_var_E = 0; - Get_Phantoon(0x80)->phant_var_A = 0; - Get_Phantoon(v1 + 0x80)->phant_var_B = 0; - phantom_related_layer_flag |= 0x4000u; - E0->base.instruction_timer = 1; - Enemy_Phantoon *E1 = Get_Phantoon(0x40u); - E1->base.instruction_timer = 1; - E0->base.current_instruction = addr_kKraid_Ilist_CC41; - E1->base.current_instruction = addr_kKraid_Ilist_CC91; - E0->base.properties |= kEnemyProps_Tangible; - E1->phant_var_F = 0; + health -= EK->base.health; + if (sign16(health - 300) + || (projectile_type[collision_detection_index] & 0xF00) != 512) { + Enemy_Phantoon *E2 = Get_Phantoon(v1 + 0x80); + uint16 v7 = health + E2->phant_var_B; + E2->phant_var_B = v7; + if (!sign16(v7 - 300)) + EK->phant_var_E = 1; goto LABEL_20; } - uint16 v10 = NextRandom() & 7; - Get_Phantoon(0x40u)->phant_var_B = *(g_byte_A7CDA5 + v10); - Get_Phantoon(0xC0u)->phant_parameter_2 = v10; - Enemy_Phantoon *E2x = Get_Phantoon(0x80); - E2x->phant_parameter_2 = 1; - if (!E2x->phant_var_A) { - E2x->phant_var_A = 1; - if (!sign16(EK->phant_var_E - 16)) - EK->phant_var_E = 16; - } + goto LABEL_23; + } + health -= EK->base.health; + if (!sign16(health - 300) && (projectile_type[collision_detection_index] & 0xF00) == 512) { +LABEL_23: + EK->phant_var_F = FUNC16(Phantoon_FadeOutBeforeEnrage); + goto LABEL_22; + } + Enemy_Phantoon *E2; + E2 = Get_Phantoon(v1 + 0x80); + uint16 v9; + v9 = health + E2->phant_var_B; + E2->phant_var_B = v9; + if (!sign16(v9 - 300)) { + EK->phant_var_F = FUNC16(Phantoon_FadeoutWithSwoop); +LABEL_22: + EK->phant_var_E = 0; + Get_Phantoon(0x80)->phant_var_A = 0; + Get_Phantoon(v1 + 0x80)->phant_var_B = 0; + phantom_related_layer_flag |= 0x4000; + E0->base.instruction_timer = 1; + Enemy_Phantoon *E1 = Get_Phantoon(0x40); + E1->base.instruction_timer = 1; + E0->base.current_instruction = addr_kKraid_Ilist_CC41; + E1->base.current_instruction = addr_kKraid_Ilist_CC91; + E0->base.properties |= kEnemyProps_Tangible; + E1->phant_var_F = 0; + goto LABEL_20; + } + uint16 v10 = NextRandom() & 7; + Get_Phantoon(0x40)->phant_var_B = *(g_byte_A7CDA5 + v10); + Get_Phantoon(0xC0)->phant_parameter_2 = v10; + Enemy_Phantoon *E2x = Get_Phantoon(0x80); + E2x->phant_parameter_2 = 1; + if (!E2x->phant_var_A) { + E2x->phant_var_A = 1; + if (!sign16(EK->phant_var_E - 16)) + EK->phant_var_E = 16; } } } @@ -3403,30 +3331,27 @@ void Etecoon_Func_1(uint16 k) { // 0xA7E958 uint8 Etecoon_Func_2(uint16 k) { // 0xA7E974 Enemy_Etecoon *E = Get_Etecoon(k); - R20_ = E->etecoon_var_C; - R18_ = E->etecoon_var_D; - return Enemy_MoveRight_IgnoreSlopes(k) & 1; + return Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->etecoon_var_C, E->etecoon_var_D)); } uint8 Etecoon_Func_3(uint16 k) { // 0xA7E983 Enemy_Etecoon *E = Get_Etecoon(k); - R20_ = E->etecoon_var_A; - R18_ = E->etecoon_var_B; + int32 amt = __PAIR32__(E->etecoon_var_A, E->etecoon_var_B); if (sign16(E->etecoon_var_A - 5)) { uint16 etecoo_var_B = E->etecoon_var_B; bool v3 = __CFADD__uint16(samus_y_subaccel, etecoo_var_B); E->etecoon_var_B = samus_y_subaccel + etecoo_var_B; E->etecoon_var_A += samus_y_accel + v3; } - return Enemy_MoveDown(k) & 1; + return Enemy_MoveDown(k, amt); } void Etecoon_Func_4(uint16 k) { // 0xA7E9AF if (!door_transition_flag_enemies) { Enemy_Etecoon *E = Get_Etecoon(k); - if ((E->etecoon_var_E & 0x8000u) == 0) { + if ((E->etecoon_var_E & 0x8000) == 0) { bool v2 = E->etecoon_var_E == 1; - bool v3 = (--E->etecoon_var_E & 0x8000u) != 0; + bool v3 = (--E->etecoon_var_E & 0x8000) != 0; if (v2 || v3) { E->base.current_instruction = addr_kEtecoon_Ilist_E854; E->etecoon_var_F = FUNC16(Etecoon_Func_5); @@ -3434,7 +3359,7 @@ void Etecoon_Func_4(uint16 k) { // 0xA7E9AF } } else if (IsSamusWithinEnemy_Y(k, 0x80)) { if ((E->etecoon_parameter_2 & 3) == 0) - QueueSfx2_Max15(0x35u); + QueueSfx2_Max15(0x35); E->base.instruction_timer = 1; E->base.current_instruction = addr_kEtecoon_Ilist_E8D6; E->etecoon_var_E = 256; @@ -3445,7 +3370,7 @@ void Etecoon_Func_4(uint16 k) { // 0xA7E9AF void Etecoon_Func_5(uint16 k) { // 0xA7EA00 Enemy_Etecoon *E = Get_Etecoon(k); bool v2 = E->etecoon_var_E == 1; - bool v3 = (--E->etecoon_var_E & 0x8000u) != 0; + bool v3 = (--E->etecoon_var_E & 0x8000) != 0; if (v2 || v3) { E->etecoon_var_A = g_word_A7E900; E->etecoon_var_B = g_word_A7E902; @@ -3453,14 +3378,14 @@ void Etecoon_Func_5(uint16 k) { // 0xA7EA00 E->base.instruction_timer = 1; E->etecoon_var_F = FUNC16(Etecoon_Func_6); if (!sign16(samus_x_pos - 256)) - QueueSfx2_Max6(0x33u); + QueueSfx2_Max6(0x33); } } void Etecoon_Func_6(uint16 k) { // 0xA7EA37 if (Etecoon_Func_3(k) & 1) { Enemy_Etecoon *E = Get_Etecoon(k); - if ((E->etecoon_var_A & 0x8000u) == 0) { + if ((E->etecoon_var_A & 0x8000) == 0) { if (IsSamusWithinEnemy_Y(k, 0x40) && IsSamusWithinEnemy_X(k, g_word_A7E910)) { uint16 v2 = DetermineDirectionOfSamusFromEnemy(); if (sign16(v2 - 5)) { @@ -3491,7 +3416,7 @@ void Etecoon_Func_6(uint16 k) { // 0xA7EA37 void Etecoon_Func_7(uint16 k) { // 0xA7EAB5 Enemy_Etecoon *E = Get_Etecoon(k); bool v2 = E->etecoon_var_E == 1; - bool v3 = (--E->etecoon_var_E & 0x8000u) != 0; + bool v3 = (--E->etecoon_var_E & 0x8000) != 0; if (v2 || v3) { E->base.current_instruction += 2; E->base.instruction_timer = 1; @@ -3522,9 +3447,7 @@ void Etecoon_Func_8(uint16 k) { // 0xA7EB02 } void Etecoon_Func_9(uint16 k) { // 0xA7EB2C - R20_ = 32; - R18_ = 0; - if (EnemyFunc_BBBF(k) & 1) { + if (EnemyFunc_BBBF(k, __PAIR32__(32, 0))) { Enemy_Etecoon *E = Get_Etecoon(k); E->base.instruction_timer = 1; E->base.current_instruction = addr_stru_A7E898; @@ -3549,7 +3472,7 @@ void Etecoon_Func_10(uint16 k) { // 0xA7EB50 E->etecoon_var_F = FUNC16(Etecoon_Func_11); E->etecoon_var_E = 8; if (!sign16(samus_x_pos - 256)) - QueueSfx2_Max6(0x32u); + QueueSfx2_Max6(0x32); } else if (Etecoon_Func_3(k) & 1) { Enemy_Etecoon *E = Get_Etecoon(k); if (E->etecoon_parameter_1) @@ -3568,7 +3491,7 @@ void Etecoon_Func_11(uint16 k) { // 0xA7EBCD Etecoon_Func_1(k); Enemy_Etecoon *E = Get_Etecoon(k); bool v2 = E->etecoon_var_E == 1; - bool v3 = (--E->etecoon_var_E & 0x8000u) != 0; + bool v3 = (--E->etecoon_var_E & 0x8000) != 0; if (v2 || v3) { if (E->etecoon_parameter_1) { E->base.current_instruction = addr_kEtecoon_Ilist_E894; @@ -3591,7 +3514,7 @@ static Func_Y_V *const funcs_A2A79[3] = { Etecoon_Func_13, Etecoon_Func_14, Etec void Etecoon_Func_12(uint16 k) { // 0xA7EC1B Enemy_Etecoon *E = Get_Etecoon(k); bool v2 = E->etecoon_var_E == 1; - bool v3 = (--E->etecoon_var_E & 0x8000u) != 0; + bool v3 = (--E->etecoon_var_E & 0x8000) != 0; if (v2 || v3) { E->etecoon_var_A = g_word_A7E900; E->etecoon_var_B = g_word_A7E902; @@ -3696,7 +3619,7 @@ void Etecoon_Func_22(uint16 k) { // 0xA7ED75 Etecoon_Func_1(k); if (Etecoon_Func_3(k) & 1) { Enemy_Etecoon *E = Get_Etecoon(k); - if ((E->etecoon_var_A & 0x8000u) == 0) { + if ((E->etecoon_var_A & 0x8000) == 0) { E->etecoon_var_E = 11; E->base.instruction_timer = 1; E->base.current_instruction = addr_kEtecoon_Ilist_E854; @@ -3717,7 +3640,7 @@ void Etecoon_Func_23(uint16 k) { // 0xA7EDC7 Etecoon_Func_1(k); Enemy_Etecoon *E = Get_Etecoon(k); bool v2 = E->etecoon_var_E == 1; - bool v3 = (--E->etecoon_var_E & 0x8000u) != 0; + bool v3 = (--E->etecoon_var_E & 0x8000) != 0; if (v2 || v3) { uint16 v4 = E->etecoon_parameter_1 + 256; E->etecoon_parameter_1 = v4; @@ -3735,7 +3658,7 @@ void Etecoon_Func_23(uint16 k) { // 0xA7EDC7 E->etecoon_var_B = g_word_A7E902; E->base.instruction_timer = 1; if (!sign16(samus_x_pos - 256)) - QueueSfx2_Max6(0x33u); + QueueSfx2_Max6(0x33); } } @@ -3743,7 +3666,7 @@ void Etecoon_Func_24(uint16 k) { // 0xA7EE3E Etecoon_Func_1(k); Enemy_Etecoon *E = Get_Etecoon(k); bool v2 = E->etecoon_var_E == 1; - bool v3 = (--E->etecoon_var_E & 0x8000u) != 0; + bool v3 = (--E->etecoon_var_E & 0x8000) != 0; if (v2 || v3) { if (IsSamusWithinEnemy_Y(k, 0x40) && IsSamusWithinEnemy_X(k, 0x30)) { E->base.current_instruction = addr_stru_A7E880; @@ -3754,7 +3677,7 @@ void Etecoon_Func_24(uint16 k) { // 0xA7EE3E E->base.current_instruction += 2; E->etecoon_var_F = FUNC16(Etecoon_Func_22); if (!sign16(samus_x_pos - 256)) - QueueSfx2_Max6(0x33u); + QueueSfx2_Max6(0x33); } E->base.instruction_timer = 1; } @@ -3813,23 +3736,13 @@ void Dachora_Main(void) { // 0xA7F52E CallEnemyPreInstr(E->dachor_var_F | 0xA70000); } void Dachora_Func_1(uint16 j, uint16 k) { // 0xA7F535 - *(VoidP *)((uint8 *)&R0_.addr + 1) = 32256; Enemy_Dachora *E = Get_Dachora(k); uint16 v3 = swap16(E->base.palette_index); - R0_.addr = g_off_A7F55F[v3 >> 1]; - uint16 v5 = 0; - do { - const uint16 *v6 = (const uint16 *)RomPtr_A7(j); - IndirWriteWord(R0_, v5, *v6); - j += 2; - v5 += 2; - } while ((int16)(v5 - 32) < 0); + memcpy(g_ram + g_off_A7F55F[v3 >> 1], RomPtr_A7(j), 32); } void Dachora_Func_2(uint16 k) { // 0xA7F570 - R20_ = 1; - R18_ = 0; - Enemy_MoveDown(k); + Enemy_MoveDown(k, __PAIR32__(1, 0)); if (IsSamusWithinEnemy_Y(k, 0x40) && IsSamusWithinEnemy_X(k, g_word_A7F4C9)) { Enemy_Dachora *E = Get_Dachora(k); if (E->dachor_parameter_1) @@ -3839,7 +3752,7 @@ void Dachora_Func_2(uint16 k) { // 0xA7F570 E->base.instruction_timer = 1; E->dachor_var_F = FUNC16(Dachora_Func_3); E->dachor_var_A = g_word_A7F4CD; - QueueSfx2_Max15(0x1Du); + QueueSfx2_Max15(0x1D); } } @@ -3859,14 +3772,9 @@ void Dachora_Func_3(uint16 k) { // 0xA7F5BC } void Dachora_Func_4(uint16 k) { // 0xA7F5ED - Dachora_Func_6(k); - R20_ = ~R20_; - bool v1 = R18_ == 0; - R18_ = -R18_; - if (v1) - ++R20_; + int32 amt = -Dachora_Func_6(k); Enemy_Dachora *E = Get_Dachora(k); - if (Enemy_MoveRight_IgnoreSlopes(k) & 1 || (EnemyFunc_C8AD(k), sign16(E->base.x_pos - 96))) { + if (Enemy_MoveRight_IgnoreSlopes(k, amt) || (EnemyFunc_C8AD(k), sign16(E->base.x_pos - 96))) { E->base.current_instruction = addr_kDachora_Ilist_F407; E->dachor_var_F = FUNC16(Dachora_Func_5); E->dachor_var_E = 1; @@ -3879,10 +3787,10 @@ void Dachora_Func_4(uint16 k) { // 0xA7F5ED } void Dachora_Func_5(uint16 k) { // 0xA7F65E - Dachora_Func_6(k); + int32 amt = Dachora_Func_6(k); Enemy_Dachora *E = Get_Dachora(k); - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { - QueueSfx2_Max15(0x71u); + if (Enemy_MoveRight_IgnoreSlopes(k, amt)) { + QueueSfx2_Max15(0x71); E->base.current_instruction = addr_kDachora_Ilist_F345; E->dachor_var_F = FUNC16(Dachora_Func_4); E->dachor_parameter_1 = 0; @@ -3900,16 +3808,16 @@ LABEL_4: E->dachor_var_F = FUNC16(Dachora_Func_7); E->dachor_var_A = g_word_A7F4CF; E->base.y_pos += 8; - QueueSfx2_Max6(0x3Du); + QueueSfx2_Max6(0x3D); goto LABEL_4; } } -void Dachora_Func_6(uint16 k) { // 0xA7F6D5 +int32 Dachora_Func_6(uint16 k) { // 0xA7F6D5 Enemy_Dachora *E = Get_Dachora(k); if ((int16)(E->dachor_var_A - g_word_A7F4D5) >= 0) { if (E->dachor_var_E == 1) - QueueSfx2_Max6(0x39u); + QueueSfx2_Max6(0x39); uint16 v2 = E->dachor_var_E - 1; E->dachor_var_E = v2; if (!(uint8)v2) { @@ -3920,35 +3828,20 @@ void Dachora_Func_6(uint16 k) { // 0xA7F6D5 E->dachor_var_E = 784; } } - R20_ = 1; - R18_ = 0; - Enemy_MoveDown(k); + Enemy_MoveDown(k, INT16_SHL16(1)); if ((int16)(E->dachor_var_A - g_word_A7F4D5) >= 0 && (int16)(E->dachor_var_B - g_word_A7F4D7) >= 0) { - uint16 v4 = g_word_A7F4D5; E->dachor_var_A = g_word_A7F4D5; - R20_ = v4; - uint16 v5 = g_word_A7F4D7; E->dachor_var_B = g_word_A7F4D7; - R18_ = v5; - return; + return __PAIR32__(g_word_A7F4D5, g_word_A7F4D7); } - uint16 dachor_var_B = E->dachor_var_B; - bool v7 = __CFADD__uint16(g_word_A7F4DB, dachor_var_B); - uint16 v8 = g_word_A7F4DB + dachor_var_B; - E->dachor_var_B = v8; - R18_ = v8; + bool v7 = __CFADD__uint16(g_word_A7F4DB, E->dachor_var_B); + uint16 v8 = g_word_A7F4DB + E->dachor_var_B; uint16 v9 = g_word_A7F4D9 + v7 + E->dachor_var_A; + E->dachor_var_B = v8; E->dachor_var_A = v9; - R20_ = v9; - if (v9 == 4) { - if (R18_) - return; - goto LABEL_12; - } - if (v9 == 8 && !R18_) { -LABEL_12: + if ((v9 == 4 || v9 == 8) && !E->dachor_var_B) E->base.current_instruction += 28; - } + return __PAIR32__(E->dachor_var_A, E->dachor_var_B); } void Dachora_Func_7(uint16 k) { // 0xA7F78F @@ -3967,7 +3860,7 @@ void Dachora_Func_7(uint16 k) { // 0xA7F78F E->dachor_var_C = 0; E->dachor_var_D = 0; E->base.y_pos -= 8; - QueueSfx2_Max6(0x3Bu); + QueueSfx2_Max6(0x3B); if (E->dachor_parameter_1) { Get_Dachora(k + 64)->base.current_instruction = addr_kDachora_Ilist_F4B9; Get_Dachora(k + 128)->base.current_instruction = addr_kDachora_Ilist_F4B9; @@ -3994,22 +3887,16 @@ void Dachora_Func_8(uint16 k) { // 0xA7F806 bool v3 = __CFADD__uint16(samus_y_subaccel, dachor_var_D); E->dachor_var_D = samus_y_subaccel + dachor_var_D; E->dachor_var_C += samus_y_accel + v3; - uint16 dachor_var_B = E->dachor_var_B; - v3 = __CFADD__uint16(E->dachor_var_D, dachor_var_B); - uint16 v5 = E->dachor_var_D + dachor_var_B; - E->dachor_var_B = v5; - R18_ = v5; + + v3 = __CFADD__uint16(E->dachor_var_D, E->dachor_var_B); + uint16 v5 = E->dachor_var_D + E->dachor_var_B; uint16 v6 = E->dachor_var_C + v3 + E->dachor_var_A; + E->dachor_var_B = v5; E->dachor_var_A = v6; - R20_ = v6; if (!sign16(v6 - 15)) - R20_ = 15; - R20_ = ~R20_; - bool v7 = R18_ == 0; - R18_ = -R18_; - if (v7) - ++R20_; - if (Enemy_MoveDown(k) & 1) { + v6 = 15; + int32 amt = __PAIR32__(v6, v5); + if (Enemy_MoveDown(k, -amt)) { if (E->dachor_parameter_1) { E->base.current_instruction = addr_kDachora_Ilist_F3FF; E->dachor_parameter_1 = 0; @@ -4023,7 +3910,7 @@ void Dachora_Func_8(uint16 k) { // 0xA7F806 E->dachor_var_B = 0; E->dachor_var_E = 0; Dachora_Func_1(addr_kDachora_Palette, k); - QueueSfx2_Max6(0x3Cu); + QueueSfx2_Max6(0x3C); } } @@ -4080,15 +3967,12 @@ void Dachora_Func_11(uint16 k) { // 0xA7F935 bool v3 = __CFADD__uint16(samus_y_subaccel, dachor_var_B); uint16 v4 = samus_y_subaccel + dachor_var_B; E->dachor_var_B = v4; - R18_ = v4; uint16 v5 = samus_y_accel + v3 + E->dachor_var_A; E->dachor_var_A = v5; - R20_ = v5; - if (!sign16(v5 - 10)) { - R20_ = 10; - R18_ = 0; - } - if (Enemy_MoveDown(k) & 1) { + int32 amt = __PAIR32__(v5, v4); + if (!sign16((amt >> 16) - 10)) + amt = INT16_SHL16(10); + if (Enemy_MoveDown(k, amt)) { if (E->dachor_parameter_1) { E->base.current_instruction = addr_kDachora_Ilist_F407; E->dachor_var_F = FUNC16(Dachora_Func_5); @@ -4117,4 +4001,4 @@ LABEL_6: return; } E->base.properties &= ~kEnemyProps_Invisible; -} \ No newline at end of file +} diff --git a/src/sm_a8.c b/src/sm_a8.c index 02eb86a..61a482d 100644 --- a/src/sm_a8.c +++ b/src/sm_a8.c @@ -139,7 +139,7 @@ void Enemy_NormalFrozenAI_A8(void) { // 0xA88041 } const uint16 *MiniDraygon_Instr_2(uint16 k, const uint16 *jp) { // 0xA8878F - QueueSfx2_Max6(0x5Eu); + QueueSfx2_Max6(0x5E); return jp; } @@ -190,7 +190,7 @@ void MiniDraygon_Init(void) { // 0xA887E0 } void MiniDraygon_Func_1(void) { // 0xA88838 - Get_MiniDraygon(cur_enemy_index)->mdn_var_B = (GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0; + Get_MiniDraygon(cur_enemy_index)->mdn_var_B = (GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0; Enemy_MiniDraygon *E = Get_MiniDraygon(cur_enemy_index); E->mdn_var_02 = addr_kMiniDraygon_Ilist_86A7; if (E->mdn_var_B) @@ -285,9 +285,9 @@ void MiniDraygon_Func_5(void) { // 0xA88933 ++E->base.y_pos; E->base.y_subpos = v4; } - if ((--E->mdn_var_E & 0x8000u) != 0) { + if ((--E->mdn_var_E & 0x8000) != 0) { E->mdn_var_E = HIBYTE(E->mdn_parameter_2); - E->mdn_var_00 ^= 1u; + E->mdn_var_00 ^= 1; } } @@ -314,14 +314,10 @@ void EvirProjectile_Main(void) { // 0xA8899E void MiniDraygon_Func_7(void) { // 0xA889D4 if (IsSamusWithinEnemy_X(cur_enemy_index - 128, 0x80)) { - draw_enemy_layer = 4; - R22_ = -(uint8)(CalculateAngleOfSamusFromEnemy(cur_enemy_index) - 64); - uint16 v1 = CosineMult8bit(R22_); + uint16 r22 = -(uint8)(CalculateAngleOfSamusFromEnemy(cur_enemy_index) - 64); Enemy_MiniDraygon *E = Get_MiniDraygon(cur_enemy_index); - E->mdn_var_07 = v1; - E->mdn_var_08 = loop_index; - E->mdn_var_09 = SineMult8bitNegative(R22_); - E->mdn_var_0A = loop_index; + SetHiLo(&E->mdn_var_07, &E->mdn_var_08, CosineMult8bitFull(r22, 4)); + SetHiLo(&E->mdn_var_09, &E->mdn_var_0A, SineMult8bitFull(r22, 4)); E->mdn_var_02 = addr_kMiniDraygon_Ilist_876F; MiniDraygon_Func_12(); E->mdn_var_0B = 1; @@ -369,7 +365,7 @@ void MiniDraygon_Func_10(void) { // 0xA88A78 } void MiniDraygon_Func_11(void) { // 0xA88AB1 - if (EnemyFunc_ADA3(0x100u)) { + if (EnemyFunc_ADA3(0x100)) { if (!enemy_drawing_queue[(cur_enemy_index >> 1) + 77]) { Enemy_MiniDraygon *E = Get_MiniDraygon(cur_enemy_index); E->mdn_var_0B = 0; @@ -413,15 +409,15 @@ void MiniDraygon_Func_13(void) { // 0xA88B16 Enemy_MiniDraygon *E1 = Get_MiniDraygon(cur_enemy_index + 64); Enemy_MiniDraygon *E2 = Get_MiniDraygon(cur_enemy_index + 128); if (!E->base.health) { - E1->base.properties |= 0x200u; - E2->base.properties |= 0x200u; + E1->base.properties |= 0x200; + E2->base.properties |= 0x200; } uint16 frozen_timer = E->base.frozen_timer; if (frozen_timer) { E1->base.frozen_timer = frozen_timer; - E1->base.ai_handler_bits |= 4u; + E1->base.ai_handler_bits |= 4; if (E2->mdn_var_C != FUNC16(MiniDraygon_Func_9)) { - E2->base.ai_handler_bits |= 4u; + E2->base.ai_handler_bits |= 4; E2->base.frozen_timer = E->base.frozen_timer; } } @@ -433,7 +429,7 @@ void MorphBallEye_Init(void) { // 0xA89058 E->base.spritemap_pointer = addr_kSpritemap_Nothing_A8; E->base.instruction_timer = 1; E->base.timer = 0; - if ((E->mbee_parameter_2 & 0x8000u) != 0) { + if ((E->mbee_parameter_2 & 0x8000) != 0) { int v1 = E->mbee_parameter_2 & 0xF; E->base.x_pos += g_word_A890CA[v1]; E->base.y_pos += g_word_A890D2[v1]; @@ -473,27 +469,23 @@ void MorphBallEye_Func_1(uint16 k) { // 0xA890F1 void MorphBallEye_Func_2(uint16 k) { // 0xA8912E Enemy_MorphBallEye *E = Get_MorphBallEye(k); bool v2 = E->mbee_var_E == 1; - bool v3 = (--E->mbee_var_E & 0x8000u) != 0; + bool v3 = (--E->mbee_var_E & 0x8000) != 0; if (v2 || v3) { - QueueSfx2_Max6(0x17u); + QueueSfx2_Max6(0x17); SpawnMorphBallEyeBeamHdma(); E->mbee_var_F = FUNC16(MorphBallEye_Func_3); - R18_ = samus_x_pos - E->base.x_pos; - R20_ = samus_y_pos - E->base.y_pos; - E->mbee_var_D = CalculateAngleFromXY(); + E->mbee_var_D = CalculateAngleFromXY(samus_x_pos - E->base.x_pos, samus_y_pos - E->base.y_pos); } } void MorphBallEye_Func_3(uint16 k) { // 0xA89160 Enemy_MorphBallEye *E = Get_MorphBallEye(k); if (IsSamusWithinEnemy_Y(k, g_word_A89056) && IsSamusWithinEnemy_X(k, g_word_A89052)) { - R18_ = samus_x_pos - E->base.x_pos; - R20_ = samus_y_pos - E->base.y_pos; - uint16 v3 = CalculateAngleFromXY(); + uint16 v3 = CalculateAngleFromXY(samus_x_pos - E->base.x_pos, samus_y_pos - E->base.y_pos); E->mbee_var_D = v3; - E->base.current_instruction = ((uint8)(v3 & 0xF0) >> 2) - 28756; + E->base.current_instruction = ((v3 & 0xF0) >> 2) - 28756; } else { - QueueSfx2_Max6(0x71u); + QueueSfx2_Max6(0x71); E->mbee_var_C = 0; E->mbee_var_E = 32; if ((E->mbee_parameter_1 & 1) != 0) @@ -508,13 +500,13 @@ void MorphBallEye_Func_3(uint16 k) { // 0xA89160 void MorphBallEye_Func_4(uint16 k) { // 0xA891CE Enemy_MorphBallEye *E = Get_MorphBallEye(k); bool v2 = E->mbee_var_E == 1; - bool v3 = (--E->mbee_var_E & 0x8000u) != 0; + bool v3 = (--E->mbee_var_E & 0x8000) != 0; if (v2 || v3) E->mbee_var_F = FUNC16(MorphBallEye_Func_1); } const uint16 *Fune_Instr_2(uint16 k, const uint16 *jp) { // 0xA89625 - QueueSfx2_Max9(0x1Fu); + QueueSfx2_Max9(0x1F); return jp; } @@ -526,7 +518,7 @@ const uint16 *Fune_Instr_6(uint16 k, const uint16 *jp) { // 0xA89631 const uint16 *Fune_Instr_7(uint16 k, const uint16 *jp) { // 0xA8964A enemy_projectile_unk1995 = LOBYTE(Get_Fune(cur_enemy_index)->fune_parameter_2); - SpawnEnemyProjectileWithGfx(1u, cur_enemy_index, addr_stru_86DFBC); + SpawnEnemyProjectileWithGfx(1, cur_enemy_index, addr_stru_86DFBC); return jp; } @@ -538,7 +530,7 @@ const uint16 *Fune_Instr_1(uint16 k, const uint16 *jp) { // 0xA89663 const uint16 *Fune_Instr_4(uint16 k, const uint16 *jp) { // 0xA8967C enemy_projectile_unk1995 = LOBYTE(Get_Fune(cur_enemy_index)->fune_parameter_2); - SpawnEnemyProjectileWithGfx(1u, cur_enemy_index, addr_stru_86DFCA); + SpawnEnemyProjectileWithGfx(1, cur_enemy_index, addr_stru_86DFCA); return jp; } @@ -699,7 +691,7 @@ void WreckedShipGhost_Func_2(uint16 k) { // 0xA89BAD WreckedShipGhost_Func_3(cur_enemy_index); Enemy_WreckedShipGhost *E = Get_WreckedShipGhost(cur_enemy_index); if (!(E->wsgt_var_B | v4)) { - E->base.properties &= 0xFAFFu; + E->base.properties &= 0xFAFF; E->wsgt_var_A = FUNC16(WreckedShipGhost_Func_5); E->wsgt_var_00 = E->base.y_pos; E->wsgt_var_B = 1; @@ -789,7 +781,7 @@ void WreckedShipGhost_Func_5(uint16 k) { // 0xA89C8A target_palettes[v9 >> 1] = 0x7FFF; v9 += 2; n--; - } while ((n & 0x8000u) == 0); + } while ((n & 0x8000) == 0); } } @@ -874,58 +866,54 @@ LABEL_13: } uint16 WreckedShipGhost_Func_8(void) { // 0xA89E88 - int16 v5; - int16 v7; - int16 v9; - uint16 v0 = 0; if (!door_transition_flag_enemies) { Enemy_WreckedShipGhost *E = Get_WreckedShipGhost(cur_enemy_index); uint16 v2 = swap16(E->base.palette_index); uint16 v3 = 16 * v2 + 256; - R20_ = 16 * v2 + 288; + uint16 r20 = 16 * v2 + 288; do { int v4 = v3 >> 1; if (target_palettes[v4] != palette_buffer[v4]) { - R18_ = target_palettes[v4] & 0x1F; - v5 = palette_buffer[v4] & 0x1F; - if (v5 != R18_) { + uint16 r18 = target_palettes[v4] & 0x1F; + uint16 v5 = palette_buffer[v4] & 0x1F; + if (v5 != r18) { uint16 v6; - if ((int16)(v5 - R18_) >= 0) + if ((int16)(v5 - r18) >= 0) v6 = v5 - 1; else v6 = v5 + 1; - R18_ = v6; + r18 = v6; palette_buffer[v4] = v6 | palette_buffer[v4] & 0xFFE0; ++v0; } - R18_ = target_palettes[v4] & 0x3E0; - v7 = palette_buffer[v4] & 0x3E0; - if (v7 != R18_) { + r18 = target_palettes[v4] & 0x3E0; + uint16 v7 = palette_buffer[v4] & 0x3E0; + if (v7 != r18) { uint16 v8; - if ((int16)(v7 - R18_) >= 0) + if ((int16)(v7 - r18) >= 0) v8 = v7 - 32; else v8 = v7 + 32; - R18_ = v8; + r18 = v8; palette_buffer[v4] = v8 | palette_buffer[v4] & 0xFC1F; ++v0; } - R18_ = target_palettes[v4] & 0x7C00; - v9 = palette_buffer[v4] & 0x7C00; - if (v9 != R18_) { + r18 = target_palettes[v4] & 0x7C00; + uint16 v9 = palette_buffer[v4] & 0x7C00; + if (v9 != r18) { uint16 v10; - if ((int16)(v9 - R18_) >= 0) + if ((int16)(v9 - r18) >= 0) v10 = v9 - 1024; else v10 = v9 + 1024; - R18_ = v10; + r18 = v10; palette_buffer[v4] = v10 | palette_buffer[v4] & 0x83FF; ++v0; } } v3 += 2; - } while ((int16)(v3 - R20_) < 0); + } while ((int16)(v3 - r20) < 0); } return v0; } @@ -974,7 +962,7 @@ const uint16 *YappingMaw_Instr_6(uint16 k, const uint16 *jp) { // 0xA8A121 const uint16 *YappingMaw_Instr_1(uint16 k, const uint16 *jp) { // 0xA8A133 if (!Get_YappingMaw(cur_enemy_index)->ymw_var_36) - QueueSfx2_Max6(0x2Fu); + QueueSfx2_Max6(0x2F); return jp; } @@ -996,8 +984,8 @@ void YappingMaw_Init(void) { // 0xA8A148 E->ymw_var_F = E->ymw_parameter_1; E->ymw_var_E = 64; E->base.current_instruction = addr_kYappingMaw_Ilist_9F6F; - R36 = 57; - R34 = 8; + uint16 R36 = 57; + uint16 R34 = 8; if (!E->ymw_parameter_2) { E->base.current_instruction = addr_kYappingMaw_Ilist_9FC7; R36 = 56; @@ -1014,14 +1002,9 @@ void YappingMaw_Init(void) { // 0xA8A148 v1 = E->ymw_var_44 - 1; E->ymw_var_44 = v1; } while (v1 >= 0); - R18_ = E->base.x_pos; - R20_ = R34 + E->base.y_pos; - R22_ = R36; uint16 v3 = E->base.vram_tiles_index | E->base.palette_index; E->ymw_var_47 = v3; - R24_ = v3; - CreateSpriteAtPos(); - E->ymw_var_46 = R18_; + E->ymw_var_46 = CreateSpriteAtPos(E->base.x_pos, R34 + E->base.y_pos, R36, v3); } void CallYappingMawFunc(uint32 ea) { @@ -1047,19 +1030,15 @@ void YappingMaw_Main(void) { // 0xA8A211 void YappingMaw_Func_1(void) { // 0xA8A235 Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - draw_enemy_layer = E->base.x_pos; - enemy_drawing_queue_index = E->base.y_pos; - loop_index_end = samus_x_pos; - loop_index = samus_y_pos; - uint16 v1 = EnemyFunc_ACA8(); - uint16 v2 = Abs16(v1); + PairU16 pair = EnemyFunc_ACA8((Point16U) { E->base.x_pos, E->base.y_pos}, (Point16U) { samus_x_pos, samus_y_pos }); + uint16 v2 = Abs16(pair.k); E->ymw_var_08 = v2; if (sign16(v2 - 32)) { E->ymw_var_35 = 48; } else if ((int16)(v2 - E->ymw_var_F) < 0) { if (!sign16(E->ymw_var_08 - 64)) E->ymw_var_08 = 64; - E->ymw_var_0A = enemy_drawing_queue_base; + E->ymw_var_0A = pair.j; E->ymw_var_A = FUNC16(YappingMaw_Func_2); } } @@ -1089,46 +1068,44 @@ void YappingMaw_Func_2(void) { // 0xA8A28C void YappingMaw_Func_3(void) { // 0xA8A310 Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - draw_enemy_layer = E->ymw_var_09; - E->ymw_var_0E = YappingMaw_Func_16(0x80); - draw_enemy_layer = E->ymw_var_09 >> 1; - E->ymw_var_0F = YappingMaw_Func_17(0x80); + E->ymw_var_0E = YappingMaw_Func_16(0x80, E->ymw_var_09); + E->ymw_var_0F = YappingMaw_Func_17(0x80, E->ymw_var_09 >> 1); } void YappingMaw_Func_4(void) { // 0xA8A339 Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - draw_enemy_layer = E->ymw_var_00; - E->ymw_var_10 = YappingMaw_Func_16(0); - E->ymw_var_11 = YappingMaw_Func_17(0); - E->ymw_var_27 = YappingMaw_Func_16(E->ymw_var_0B) - E->ymw_var_10; - E->ymw_var_28 = YappingMaw_Func_17(E->ymw_var_0B) - E->ymw_var_11; + uint16 varE32 = E->ymw_var_00; + E->ymw_var_10 = YappingMaw_Func_16(0, varE32); + E->ymw_var_11 = YappingMaw_Func_17(0, varE32); + E->ymw_var_27 = YappingMaw_Func_16(E->ymw_var_0B, varE32) - E->ymw_var_10; + E->ymw_var_28 = YappingMaw_Func_17(E->ymw_var_0B, varE32) - E->ymw_var_11; } void YappingMaw_Func_5(void) { // 0xA8A37C Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - draw_enemy_layer = E->ymw_var_02; - E->ymw_var_10 = YappingMaw_Func_16(0); - E->ymw_var_11 = YappingMaw_Func_17(0); - E->ymw_var_29 = YappingMaw_Func_16(E->ymw_var_0B) - E->ymw_var_10; - E->ymw_var_2A = YappingMaw_Func_17(E->ymw_var_0B) - E->ymw_var_11; + uint16 varE32 = E->ymw_var_02; + E->ymw_var_10 = YappingMaw_Func_16(0, varE32); + E->ymw_var_11 = YappingMaw_Func_17(0, varE32); + E->ymw_var_29 = YappingMaw_Func_16(E->ymw_var_0B, varE32) - E->ymw_var_10; + E->ymw_var_2A = YappingMaw_Func_17(E->ymw_var_0B, varE32) - E->ymw_var_11; } void YappingMaw_Func_6(void) { // 0xA8A3BF Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - draw_enemy_layer = E->ymw_var_04; - E->ymw_var_10 = YappingMaw_Func_16(0); - E->ymw_var_11 = YappingMaw_Func_17(0); - E->ymw_var_2B = YappingMaw_Func_16(E->ymw_var_0B) - E->ymw_var_10; - E->ymw_var_2C = YappingMaw_Func_17(E->ymw_var_0B) - E->ymw_var_11; + uint16 varE32 = E->ymw_var_04; + E->ymw_var_10 = YappingMaw_Func_16(0, varE32); + E->ymw_var_11 = YappingMaw_Func_17(0, varE32); + E->ymw_var_2B = YappingMaw_Func_16(E->ymw_var_0B, varE32) - E->ymw_var_10; + E->ymw_var_2C = YappingMaw_Func_17(E->ymw_var_0B, varE32) - E->ymw_var_11; } void YappingMaw_Func_7(void) { // 0xA8A402 Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - draw_enemy_layer = E->ymw_var_06; - E->ymw_var_10 = YappingMaw_Func_16(0); - E->ymw_var_11 = YappingMaw_Func_17(0); - E->ymw_var_2D = YappingMaw_Func_16(E->ymw_var_0B) - E->ymw_var_10; - E->ymw_var_2E = YappingMaw_Func_17(E->ymw_var_0B) - E->ymw_var_11; + uint16 varE32 = E->ymw_var_06; + E->ymw_var_10 = YappingMaw_Func_16(0, varE32); + E->ymw_var_11 = YappingMaw_Func_17(0, varE32); + E->ymw_var_2D = YappingMaw_Func_16(E->ymw_var_0B, varE32) - E->ymw_var_10; + E->ymw_var_2E = YappingMaw_Func_17(E->ymw_var_0B, varE32) - E->ymw_var_11; } void YappingMaw_Func_8(void) { // 0xA8A445 @@ -1150,49 +1127,49 @@ void YappingMaw_Func_8(void) { // 0xA8A445 uint16 v8; Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - R20_ = E->ymw_var_B >> 2; + uint16 r20 = E->ymw_var_B >> 2; if (E->ymw_var_2F) { - bool v3 = __CFADD__uint16(R20_, 128); - v9 = R20_ + 128; - E->ymw_var_21 = R20_ + 128; + bool v3 = __CFADD__uint16(r20, 128); + v9 = r20 + 128; + E->ymw_var_21 = r20 + 128; v11 = v3; v3 = __CFADD__uint16(v3, v9); uint16 v10 = v11 + v9; - v3 |= __CFADD__uint16(R20_, v10); - v10 += R20_; + v3 |= __CFADD__uint16(r20, v10); + v10 += r20; E->ymw_var_22 = v10; v13 = v3; v3 = __CFADD__uint16(v3, v10); uint16 v12 = v13 + v10; - v3 |= __CFADD__uint16(R20_, v12); - v12 += R20_; + v3 |= __CFADD__uint16(r20, v12); + v12 += r20; E->ymw_var_23 = v12; - v8 = R20_ + v3 + v12; + v8 = r20 + v3 + v12; } else { - uint16 v2 = 128 - R20_; - bool v3 = R20_ <= 0x80; - E->ymw_var_21 = 128 - R20_; - uint16 v5 = !v3 + R20_; + uint16 v2 = 128 - r20; + bool v3 = r20 <= 0x80; + E->ymw_var_21 = 128 - r20; + uint16 v5 = !v3 + r20; v3 = v2 < v5; uint16 v4 = v2 - v5; E->ymw_var_22 = v4; - uint16 v7 = v3 + R20_; + uint16 v7 = v3 + r20; v3 = v4 < v7; uint16 v6 = v4 - v7; E->ymw_var_23 = v6; - v8 = v6 - (v3 + R20_); + v8 = v6 - (v3 + r20); } E->ymw_var_24 = v8; - draw_enemy_layer = E->ymw_var_09; - E->ymw_var_00 = YappingMaw_Func_16(E->ymw_var_21) - E->ymw_var_0E; - E->ymw_var_02 = YappingMaw_Func_16(E->ymw_var_22) - E->ymw_var_0E; - E->ymw_var_04 = YappingMaw_Func_16(E->ymw_var_23) - E->ymw_var_0E; - E->ymw_var_06 = YappingMaw_Func_16(E->ymw_var_24) - E->ymw_var_0E; - draw_enemy_layer = E->ymw_var_09 >> 1; - E->ymw_var_01 = YappingMaw_Func_17(E->ymw_var_21) - E->ymw_var_0F; - E->ymw_var_03 = YappingMaw_Func_17(E->ymw_var_22) - E->ymw_var_0F; - E->ymw_var_05 = YappingMaw_Func_17(E->ymw_var_23) - E->ymw_var_0F; - E->ymw_var_07 = YappingMaw_Func_17(E->ymw_var_24) - E->ymw_var_0F; + uint16 varE32 = E->ymw_var_09; + E->ymw_var_00 = YappingMaw_Func_16(E->ymw_var_21, varE32) - E->ymw_var_0E; + E->ymw_var_02 = YappingMaw_Func_16(E->ymw_var_22, varE32) - E->ymw_var_0E; + E->ymw_var_04 = YappingMaw_Func_16(E->ymw_var_23, varE32) - E->ymw_var_0E; + E->ymw_var_06 = YappingMaw_Func_16(E->ymw_var_24, varE32) - E->ymw_var_0E; + varE32 = E->ymw_var_09 >> 1; + E->ymw_var_01 = YappingMaw_Func_17(E->ymw_var_21, varE32) - E->ymw_var_0F; + E->ymw_var_03 = YappingMaw_Func_17(E->ymw_var_22, varE32) - E->ymw_var_0F; + E->ymw_var_05 = YappingMaw_Func_17(E->ymw_var_23, varE32) - E->ymw_var_0F; + E->ymw_var_07 = YappingMaw_Func_17(E->ymw_var_24, varE32) - E->ymw_var_0F; YappingMaw_Func_4(); YappingMaw_Func_5(); YappingMaw_Func_6(); @@ -1291,7 +1268,7 @@ void YappingMaw_Func_9(uint16 k) { // 0xA8A63E } void YappingMaw_Func_10(void) { // 0xA8A665 - CallSomeSamusCode(3u); + CallSomeSamusCode(3); Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); samus_x_pos = E->ymw_var_32 + E->base.x_pos; samus_y_pos = E->ymw_var_33 + E->base.y_pos; @@ -1302,7 +1279,7 @@ void YappingMaw_Func_11(void) { // 0xA8A68A Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); if (E->ymw_var_30) YappingMaw_Func_10(); - if ((--E->ymw_var_E & 0x8000u) != 0 && samus_input_handler != FUNC16(Samus_InputHandler_E91D)) { + if ((--E->ymw_var_E & 0x8000) != 0 && samus_input_handler != FUNC16(Samus_InputHandler_E91D)) { samus_input_handler = FUNC16(Samus_InputHandler_E913); E->ymw_var_30 = 0; E->ymw_var_35 = 48; @@ -1339,34 +1316,33 @@ void YappingMaw_Func_15(void) { // 0xA8A71D enemy_projectile_y_pos[v1] = E->ymw_var_05 + E->ymw_var_0D; } -uint16 YappingMaw_Func_16(uint16 a) { // 0xA8A73E - return YappingMaw_Func_17(a - 64); +uint16 YappingMaw_Func_16(uint16 a, uint16 varE32) { // 0xA8A73E + return YappingMaw_Func_17(a - 64, varE32); } -uint16 YappingMaw_Func_17(uint16 a) { // 0xA8A742 +uint16 YappingMaw_Func_17(uint16 a, uint16 varE32) { // 0xA8A742 int16 v1; + uint16 r20 = 0; - R18_ = a; - R20_ = 0; - R22_ = 0; - v1 = kSine16bit[(uint8)-(int8)a]; + uint16 r22 = 0; + v1 = kSine16bit[(uint8)-a]; if (v1 < 0) { v1 = -v1; - ++R20_; + ++r20; } WriteReg(WRMPYA, HIBYTE(v1)); - if ((uint8)draw_enemy_layer) { - uint16 prod = Mult8x8(HIBYTE(v1), draw_enemy_layer); - R22_ = 2 * (uint8)((uint16)(prod & 0xFF00) >> 8); - if (R20_) - R22_ = (uint8)(2 * ((uint16)-prod >> 8)) | 0xFF00; + if ((uint8)varE32) { + uint16 prod = Mult8x8(HIBYTE(v1), varE32); + r22 = 2 * ((prod & 0xFF00) >> 8); + if (r20) + r22 = (2 * ((uint16)-prod >> 8)) | 0xFF00; } - return R22_; + return r22; } void YappingMaw_Touch(void) { // 0xA8A799 Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - if ((E->ymw_var_35 & 0x8000u) != 0 && !E->ymw_var_30) { + if ((E->ymw_var_35 & 0x8000) != 0 && !E->ymw_var_30) { E->ymw_var_35 = 0; E->ymw_var_30 = 1; samus_input_handler = FUNC16(nullsub_152); @@ -1420,15 +1396,15 @@ void YappingMaw_Func_18(uint16 j) { // 0xA8A85D void YappingMaw_Func_19(void) { // 0xA8A899 Enemy_YappingMaw *E = Get_YappingMaw(cur_enemy_index); - R18_ = E->ymw_var_45; - R20_ = E->ymw_var_46; - sprite_palettes[R20_ >> 1] = R18_ | sprite_palettes[R20_ >> 1] & 0xF1FF; - if (Get_YappingMaw(cur_enemy_index)->base.frozen_timer) { - sprite_palettes[R20_ >> 1] = sprite_palettes[R20_ >> 1] & 0xF1FF | 0xC00; - uint16 frozen_timer = Get_YappingMaw(cur_enemy_index)->base.frozen_timer; + uint16 r18 = E->ymw_var_45; + uint16 r20 = E->ymw_var_46; + sprite_palettes[r20 >> 1] = r18 | sprite_palettes[r20 >> 1] & 0xF1FF; + if (E->base.frozen_timer) { + sprite_palettes[r20 >> 1] = sprite_palettes[r20 >> 1] & 0xF1FF | 0xC00; + uint16 frozen_timer = E->base.frozen_timer; if (sign16(frozen_timer - 90)) { if ((frozen_timer & 2) == 0) - sprite_palettes[R20_ >> 1] = R18_ | sprite_palettes[R20_ >> 1] & 0xF1FF; + sprite_palettes[r20 >> 1] = r18 | sprite_palettes[r20 >> 1] & 0xF1FF; } } } @@ -1477,7 +1453,7 @@ void Kago_Shot(void) { // 0xA8AB83 v2 = E->kago_var_04 - 1; E->kago_var_04 = v2; if (v2 < 0) { - EnemyDeathAnimation(cur_enemy_index, 4u); + EnemyDeathAnimation(cur_enemy_index, 4); E->kago_var_F = 1; } SpawnEnemyProjectileWithGfx(E->base.y_pos, cur_enemy_index, addr_loc_A8D02E); @@ -1536,9 +1512,9 @@ const uint16 *NorfairLavaMan_Instr_9(uint16 k, const uint16 *jp) { // 0xA8AE64 E->base.y_pos = v4; Enemy_NorfairLavaMan *E1 = Get_NorfairLavaMan(cur_enemy_index + 64); E1->base.y_pos = v4; - E1->base.properties &= ~0x100u; + E1->base.properties &= ~0x100; Enemy_NorfairLavaMan *E2 = Get_NorfairLavaMan(cur_enemy_index + 128); - E2->base.properties &= ~0x100u; + E2->base.properties &= ~0x100; return jp; } @@ -1556,9 +1532,9 @@ const uint16 *NorfairLavaMan_Instr_13(uint16 k, const uint16 *jp) { // 0xA8AE96 E->base.y_pos = v4; Enemy_NorfairLavaMan *E1 = Get_NorfairLavaMan(cur_enemy_index + 64); E1->base.y_pos = v4; - E1->base.properties |= 0x100u; + E1->base.properties |= 0x100; Enemy_NorfairLavaMan *E2 = Get_NorfairLavaMan(cur_enemy_index + 128); - E2->base.properties |= 0x100u; + E2->base.properties |= 0x100; return jp; } @@ -1620,7 +1596,7 @@ void NorfairLavaMan_Func_1(void) { // 0xA8AF9D E->nlmn_var_00 = 0; E->nlmn_var_02 = 0; E->nlmn_var_03 = E->base.y_pos; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) E->nlmn_var_00 = 1; E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_AC9C; if (!E->nlmn_var_00) @@ -1657,7 +1633,7 @@ void NorfairLavaMan_Func_3(void) { // 0xA8B020 void NorfairLavaMan_Func_4(void) { // 0xA8B05E Enemy_NorfairLavaMan *E = Get_NorfairLavaMan(cur_enemy_index); - int v1 = (uint16)(8 * HIBYTE(E->nlmn_parameter_2)) >> 1; + int v1 = (8 * HIBYTE(E->nlmn_parameter_2)) >> 1; E->nlmn_var_08 = kCommonEnemySpeeds_Linear[v1]; E->nlmn_var_07 = kCommonEnemySpeeds_Linear[v1 + 1]; E->nlmn_var_0A = kCommonEnemySpeeds_Linear[v1 + 2]; @@ -1678,15 +1654,15 @@ void NorfairLavaMan_Func_6(void) { // 0xA8B0B2 variables_for_enemy_graphics_drawn_hook[2] = 8; ++variables_for_enemy_graphics_drawn_hook[1]; int v0 = (uint16)(32 * (variables_for_enemy_graphics_drawn_hook[1] & 3)) >> 1; - R18_ = kNorfairLavaMan_Palette[v0 + 9]; - R20_ = kNorfairLavaMan_Palette[v0 + 10]; - R22_ = kNorfairLavaMan_Palette[v0 + 11]; - R24_ = kNorfairLavaMan_Palette[v0 + 12]; + uint16 r18 = kNorfairLavaMan_Palette[v0 + 9]; + uint16 r20 = kNorfairLavaMan_Palette[v0 + 10]; + uint16 r22 = kNorfairLavaMan_Palette[v0 + 11]; + uint16 r24 = kNorfairLavaMan_Palette[v0 + 12]; int v1 = variables_for_enemy_graphics_drawn_hook[0] >> 1; - palette_buffer[v1 + 9] = R18_; - palette_buffer[v1 + 10] = R20_; - palette_buffer[v1 + 11] = R22_; - palette_buffer[v1 + 12] = R24_; + palette_buffer[v1 + 9] = r18; + palette_buffer[v1 + 10] = r20; + palette_buffer[v1 + 11] = r22; + palette_buffer[v1 + 12] = r24; } } @@ -1700,13 +1676,13 @@ void NorfairLavaMan_Func_7(uint16 k) { // 0xA8B11A Enemy_NorfairLavaMan *E = Get_NorfairLavaMan(cur_enemy_index); E->nlmn_var_00 = 0; E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_AC9C; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) { + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) { E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_AD3C; E->nlmn_var_00 = 1; } NorfairLavaMan_Func_20(); Enemy_NorfairLavaMan *E2 = Get_NorfairLavaMan(cur_enemy_index + 128); - if ((E2->nlmn_var_04 & 0x8000u) != 0) { + if ((E2->nlmn_var_04 & 0x8000) != 0) { E2->nlmn_var_04 = 0; if (IsSamusWithinEnemy_X(cur_enemy_index, LOBYTE(E->nlmn_parameter_2))) { E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_ACDE; @@ -1731,7 +1707,7 @@ void sub_A8B193(uint16 k) { // 0xA8B193 Enemy_NorfairLavaMan *E = Get_NorfairLavaMan(cur_enemy_index); if (!E->nlmn_var_02) { E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_AD0C; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_ADAC; NorfairLavaMan_Func_20(); E->nlmn_var_F = FUNC16(NorfairLavaMan_Func_9); @@ -1742,7 +1718,7 @@ void NorfairLavaMan_Func_9(uint16 k) { // 0xA8B1B8 Enemy_NorfairLavaMan *E = Get_NorfairLavaMan(cur_enemy_index); if (!E->nlmn_var_01) { E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_AC9C; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_AD3C; NorfairLavaMan_Func_20(); E->nlmn_var_F = FUNC16(NorfairLavaMan_Func_7); @@ -1866,7 +1842,7 @@ void NorfairLavaMan_Func_17(uint16 k) { // 0xA8B356 Enemy_NorfairLavaMan *E = Get_NorfairLavaMan(cur_enemy_index); E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_ACB0; E->nlmn_var_B = 0; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) { + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) { E->nlmn_var_D = addr_kNorfairLavaMan_Ilist_AD50; E->nlmn_var_B = 1; } @@ -1930,15 +1906,15 @@ void NorfairLavaMan_Common(void) { // 0xA8B410 Enemy_NorfairLavaMan *E1 = Get_NorfairLavaMan(cur_enemy_index + 64); Enemy_NorfairLavaMan *E2 = Get_NorfairLavaMan(cur_enemy_index + 128); if (!E->base.health) { - E1->base.properties |= 0x200u; - E2->base.properties |= 0x200u; + E1->base.properties |= 0x200; + E2->base.properties |= 0x200; } uint16 frozen_timer = E->base.frozen_timer; if (frozen_timer) { E1->base.frozen_timer = frozen_timer; - E1->base.ai_handler_bits |= 4u; + E1->base.ai_handler_bits |= 4; E2->base.frozen_timer = frozen_timer; - E2->base.ai_handler_bits |= 4u; + E2->base.ai_handler_bits |= 4; } } @@ -1963,68 +1939,23 @@ void Beetom_Init(void) { // 0xA8B776 E->beetom_var_E = 64; E->beetom_var_F = joypad1_lastkeys; random_number = 23; - R22_ = 12288; - R24_ = 4; - E->beetom_var_02 = Beetom_Func_2(); - R22_ = 0x4000; - R24_ = 5; - E->beetom_var_03 = Beetom_Func_2(); - R22_ = 12288; - R24_ = 3; - E->beetom_var_04 = Beetom_Func_2(); + E->beetom_var_02 = Beetom_Func_2(12288, 4); + E->beetom_var_03 = Beetom_Func_2(0x4000, 5); + E->beetom_var_04 = Beetom_Func_2(12288, 3); E->beetom_var_00 = addr_kBeetom_Ilist_B6F2; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) E->beetom_var_00 = addr_kBeetom_Ilist_B696; Beetom_Func_1(); E->beetom_var_C = FUNC16(Beetom_Func_3); } -uint16 Beetom_Func_2(void) { // 0xA8B7EF - R18_ = 0; - R20_ = 0; +uint16 Beetom_Func_2(uint16 r22, uint16 r24) { // 0xA8B7EF + uint16 r18 = 0, r20 = 0; do { - R18_ += R24_; - R20_ += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (uint16)(8 * R18_) + 1); - } while (sign16(R20_ - R22_)); - return R18_; -} - -void CallBeetomFunc(uint32 ea) { - switch (ea) { - case fnBeetom_Func_3: Beetom_Func_3(); return; // 0xa8b814 - case fnBeetom_Func_4: Beetom_Func_4(); return; // 0xa8b82f - case fnBeetom_Func_5: Beetom_Func_5(); return; // 0xa8b84f - case fnBeetom_Func_6: Beetom_Func_6(); return; // 0xa8b85f - case fnBeetom_Func_7: Beetom_Func_7(); return; // 0xa8b873 - case fnBeetom_Func_8: Beetom_Func_8(); return; // 0xa8b887 - case fnBeetom_Func_9: Beetom_Func_9(); return; // 0xa8b8a9 - case fnBeetom_Func_10: Beetom_Func_10(); return; // 0xa8b8cb - case fnBeetom_Func_11: Beetom_Func_11(); return; // 0xa8b8ed - case fnBeetom_Func_12: Beetom_Func_12(); return; // 0xa8b90f - case fnBeetom_Func_13: Beetom_Func_13(); return; // 0xa8b952 - case fnBeetom_Func_14: Beetom_Func_14(); return; // 0xa8b966 - case fnBeetom_Func_15: Beetom_Func_15(); return; // 0xa8b97a - case fnBeetom_Func_16: Beetom_Func_16(); return; // 0xa8b9a2 - case fnBeetom_Func_17: Beetom_Func_17(); return; // 0xa8b9b2 - case fnBeetom_Func_18: Beetom_Func_18(); return; // 0xa8b9c1 - case fnBeetom_Func_19: Beetom_Func_19(); return; // 0xa8ba24 - case fnBeetom_Func_20: Beetom_Func_20(); return; // 0xa8ba84 - case fnBeetom_Func_21: Beetom_Func_21(); return; // 0xa8bab7 - case fnBeetom_Func_24: Beetom_Func_24(); return; // 0xa8bb55 - case fnBeetom_Func_25: Beetom_Func_25(); return; // 0xa8bb88 - case fnBeetom_Func_28: Beetom_Func_28(); return; // 0xa8bc26 - case fnBeetom_Func_29: Beetom_Func_29(); return; // 0xa8bc5a - case fnBeetom_Func_32: Beetom_Func_32(); return; // 0xa8bcf8 - case fnBeetom_Func_33: Beetom_Func_33(); return; // 0xa8bd42 - case fnBeetom_Func_35: Beetom_Func_35(); return; // 0xa8bd9d - case fnBeetom_Func_36: Beetom_Func_36(); return; // 0xa8bdc5 - default: Unreachable(); - } -} - -void Beetom_Main(void) { // 0xA8B80D - Enemy_Beetom *E = Get_Beetom(cur_enemy_index); - CallBeetomFunc(E->beetom_var_C | 0xA80000); + r18 += r24; + r20 += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (8 * r18) + 1); + } while (sign16(r20 - r22)); + return r18; } void Beetom_Func_3(void) { // 0xA8B814 @@ -2103,7 +2034,7 @@ void Beetom_Func_12(void) { // 0xA8B90F E->beetom_var_00 = addr_kBeetom_Ilist_B708; E->beetom_var_C = FUNC16(Beetom_Func_29); E->beetom_var_09 = 1; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) != 0) { + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) != 0) { E->beetom_var_00 = addr_kBeetom_Ilist_B6AC; E->beetom_var_C = FUNC16(Beetom_Func_28); E->beetom_var_09 = 0; @@ -2144,24 +2075,20 @@ void Beetom_Func_16(void) { // 0xA8B9A2 void Beetom_Func_17(void) { // 0xA8B9B2 Enemy_Beetom *E = Get_Beetom(cur_enemy_index); - if ((--E->beetom_var_D & 0x8000u) != 0) + if ((--E->beetom_var_D & 0x8000) != 0) E->beetom_var_C = FUNC16(Beetom_Func_3); } void Beetom_Func_18(void) { // 0xA8B9C1 Enemy_Beetom *E = Get_Beetom(cur_enemy_index); - if ((--E->beetom_var_D & 0x8000u) != 0) { + if ((--E->beetom_var_D & 0x8000) != 0) { E->beetom_var_D = 64; E->beetom_var_C = FUNC16(Beetom_Func_3); } else { E->base.x_pos -= 8; - R20_ = 1; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.x_pos += 8; - R18_ = -16384; - R20_ = -1; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -16384))) E->beetom_var_C = FUNC16(Beetom_Func_7); } else { E->beetom_var_C = FUNC16(Beetom_Func_7); @@ -2173,18 +2100,14 @@ void Beetom_Func_18(void) { // 0xA8B9C1 void Beetom_Func_19(void) { // 0xA8BA24 Enemy_Beetom *E = Get_Beetom(cur_enemy_index); - if ((--E->beetom_var_D & 0x8000u) != 0) { + if ((--E->beetom_var_D & 0x8000) != 0) { E->beetom_var_D = 64; E->beetom_var_C = FUNC16(Beetom_Func_3); } else { E->base.x_pos += 8; - R20_ = 1; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.x_pos -= 8; - R18_ = 0x4000; - R20_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 0x4000))) E->beetom_var_C = FUNC16(Beetom_Func_6); } else { E->beetom_var_C = FUNC16(Beetom_Func_6); @@ -2194,16 +2117,40 @@ void Beetom_Func_19(void) { // 0xA8BA24 } } +void Beetom_Func_22(uint16 k) { // 0xA8BAE7 + Enemy_Beetom *E = Get_Beetom(k); + int v2 = (8 * E->beetom_var_B) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[(v2 + 2) >> 1])) { + E->beetom_var_C = FUNC16(Beetom_Func_15); + } else { + E->beetom_var_B -= 4; + if (sign16(E->beetom_var_B)) { + E->beetom_var_B = 0; + E->beetom_var_05 = 1; + } + } +} + +void Beetom_Func_23(uint16 k) { // 0xA8BB20 + Enemy_Beetom *E = Get_Beetom(k); + int v2 = (8 * E->beetom_var_B) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[v2 >> 1])) { + E->beetom_var_C = FUNC16(Beetom_Func_3); + } else { + E->beetom_var_B += 4; + if (!sign16(E->beetom_var_B - 64)) + E->beetom_var_B = 64; + } +} + void Beetom_Func_20(void) { // 0xA8BA84 Enemy_Beetom *E = Get_Beetom(cur_enemy_index); if (E->beetom_var_05) Beetom_Func_23(cur_enemy_index); else Beetom_Func_22(cur_enemy_index); - R20_ = -1; - R18_ = -16384; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->beetom_var_09 ^= 1u; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -16384))) { + E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } } @@ -2214,44 +2161,34 @@ void Beetom_Func_21(void) { // 0xA8BAB7 Beetom_Func_23(cur_enemy_index); else Beetom_Func_22(cur_enemy_index); - R20_ = 0; - R18_ = 0x4000; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->beetom_var_09 ^= 1u; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 0x4000))) { + E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } } -void Beetom_Func_22(uint16 k) { // 0xA8BAE7 - int16 v3; - +void Beetom_Func_26(uint16 k) { // 0xA8BBB8 Enemy_Beetom *E = Get_Beetom(k); - int v2 = (uint16)(8 * E->beetom_var_B) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 3]; - R18_ = kCommonEnemySpeeds_Quadratic[v2 + 2]; - if (Enemy_MoveDown(k) & 1) { + int v2 = (8 * E->beetom_var_B) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[(v2 + 2) >> 1])) { E->beetom_var_C = FUNC16(Beetom_Func_15); } else { - v3 = E->beetom_var_B - 4; - E->beetom_var_B = v3; - if (v3 < 0) { + E->beetom_var_B -= 5; + if (sign16(E->beetom_var_B)) { E->beetom_var_B = 0; E->beetom_var_05 = 1; } } } -void Beetom_Func_23(uint16 k) { // 0xA8BB20 +void Beetom_Func_27(uint16 k) { // 0xA8BBF1 Enemy_Beetom *E = Get_Beetom(k); - int v2 = (uint16)(8 * E->beetom_var_B) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 1]; - R18_ = kCommonEnemySpeeds_Quadratic[v2]; - if (Enemy_MoveDown(k) & 1) { + int v2 = (8 * E->beetom_var_B) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[v2 >> 1])) { E->beetom_var_C = FUNC16(Beetom_Func_3); } else { - uint16 v3 = E->beetom_var_B + 4; - E->beetom_var_B = v3; - if (!sign16(v3 - 64)) + E->beetom_var_B += 5; + if (!sign16(E->beetom_var_B - 64)) E->beetom_var_B = 64; } } @@ -2262,10 +2199,8 @@ void Beetom_Func_24(void) { // 0xA8BB55 Beetom_Func_27(cur_enemy_index); else Beetom_Func_26(cur_enemy_index); - R20_ = -1; - R18_ = -16384; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->beetom_var_09 ^= 1u; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -16384))) { + E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } } @@ -2276,87 +2211,20 @@ void Beetom_Func_25(void) { // 0xA8BB88 Beetom_Func_27(cur_enemy_index); else Beetom_Func_26(cur_enemy_index); - R20_ = 0; - R18_ = 0x4000; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->beetom_var_09 ^= 1u; + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 0x4000))) { + E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } } -void Beetom_Func_26(uint16 k) { // 0xA8BBB8 - int16 v3; - - Enemy_Beetom *E = Get_Beetom(k); - int v2 = (uint16)(8 * E->beetom_var_B) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 3]; - R18_ = kCommonEnemySpeeds_Quadratic[v2 + 2]; - if (Enemy_MoveDown(k) & 1) { - E->beetom_var_C = FUNC16(Beetom_Func_15); - } else { - v3 = E->beetom_var_B - 5; - E->beetom_var_B = v3; - if (v3 < 0) { - E->beetom_var_B = 0; - E->beetom_var_05 = 1; - } - } -} - -void Beetom_Func_27(uint16 k) { // 0xA8BBF1 - Enemy_Beetom *E = Get_Beetom(k); - int v2 = (uint16)(8 * E->beetom_var_B) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 1]; - R18_ = kCommonEnemySpeeds_Quadratic[v2]; - if (Enemy_MoveDown(k) & 1) { - E->beetom_var_C = FUNC16(Beetom_Func_3); - } else { - uint16 v3 = E->beetom_var_B + 5; - E->beetom_var_B = v3; - if (!sign16(v3 - 64)) - E->beetom_var_B = 64; - } -} - -void Beetom_Func_28(void) { // 0xA8BC26 - Enemy_Beetom *E = Get_Beetom(cur_enemy_index); - if (E->beetom_var_05) - Beetom_Func_31(cur_enemy_index); - else - Beetom_Func_30(cur_enemy_index); - R20_ = -3; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->beetom_var_09 ^= 1u; - E->beetom_var_C = FUNC16(Beetom_Func_15); - } -} - -void Beetom_Func_29(void) { // 0xA8BC5A - Enemy_Beetom *E = Get_Beetom(cur_enemy_index); - if (E->beetom_var_05) - Beetom_Func_31(cur_enemy_index); - else - Beetom_Func_30(cur_enemy_index); - R20_ = 3; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { - E->beetom_var_09 ^= 1u; - E->beetom_var_C = FUNC16(Beetom_Func_15); - } -} void Beetom_Func_30(uint16 k) { // 0xA8BC8A - int16 v3; - Enemy_Beetom *E = Get_Beetom(k); - int v2 = (uint16)(8 * E->beetom_var_B) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 3]; - R18_ = kCommonEnemySpeeds_Quadratic[v2 + 2]; - if (Enemy_MoveDown(k) & 1) { + int v2 = (8 * E->beetom_var_B) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[(v2 + 2) >> 1])) { E->beetom_var_C = FUNC16(Beetom_Func_15); } else { - v3 = E->beetom_var_B - 5; + int16 v3 = E->beetom_var_B - 5; E->beetom_var_B = v3; if (v3 < 0) { E->beetom_var_B = 0; @@ -2367,10 +2235,8 @@ void Beetom_Func_30(uint16 k) { // 0xA8BC8A void Beetom_Func_31(uint16 k) { // 0xA8BCC3 Enemy_Beetom *E = Get_Beetom(k); - int v2 = (uint16)(8 * E->beetom_var_B) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 1]; - R18_ = kCommonEnemySpeeds_Quadratic[v2]; - if (Enemy_MoveDown(k) & 1) { + int v2 = (8 * E->beetom_var_B) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[v2 >> 1])) { E->beetom_var_C = FUNC16(Beetom_Func_3); } else { uint16 v3 = E->beetom_var_B + 3; @@ -2379,6 +2245,37 @@ void Beetom_Func_31(uint16 k) { // 0xA8BCC3 E->beetom_var_B = 64; } } +void Beetom_Func_28(void) { // 0xA8BC26 + Enemy_Beetom *E = Get_Beetom(cur_enemy_index); + if (E->beetom_var_05) + Beetom_Func_31(cur_enemy_index); + else + Beetom_Func_30(cur_enemy_index); + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-3, 0))) { + E->beetom_var_09 ^= 1; + E->beetom_var_C = FUNC16(Beetom_Func_15); + } +} + +void Beetom_Func_29(void) { // 0xA8BC5A + Enemy_Beetom *E = Get_Beetom(cur_enemy_index); + if (E->beetom_var_05) + Beetom_Func_31(cur_enemy_index); + else + Beetom_Func_30(cur_enemy_index); + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(3, 0))) { + E->beetom_var_09 ^= 1; + E->beetom_var_C = FUNC16(Beetom_Func_15); + } +} + +void Beetom_Func_34(void) { // 0xA8BD8C + Enemy_Beetom *E = Get_Beetom(cur_enemy_index); + if (joypad1_lastkeys != E->beetom_var_F) { + E->beetom_var_F = joypad1_lastkeys; + --E->beetom_var_E; + } +} void Beetom_Func_32(void) { // 0xA8BCF8 Enemy_Beetom *E = Get_Beetom(cur_enemy_index); @@ -2387,13 +2284,9 @@ void Beetom_Func_32(void) { // 0xA8BCF8 E->base.y_pos = samus_y_pos - 4; Beetom_Func_34(); } else { - R18_ = 0; - R20_ = 16; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(16, 0))) { E->beetom_var_09 = 1; - R18_ = 0; - R20_ = -32; - Enemy_MoveRight_IgnoreSlopes(cur_enemy_index); + Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-32, 0)); } E->beetom_var_08 = 0; E->beetom_var_C = FUNC16(Beetom_Func_16); @@ -2407,31 +2300,17 @@ void Beetom_Func_33(void) { // 0xA8BD42 E->base.y_pos = samus_y_pos - 4; Beetom_Func_34(); } else { - R18_ = 0; - R20_ = -16; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-16, 0))) { E->beetom_var_09 = 0; - R18_ = 0; - R20_ = 32; - Enemy_MoveRight_IgnoreSlopes(cur_enemy_index); + Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(32, 0)); } E->beetom_var_08 = 0; E->beetom_var_C = FUNC16(Beetom_Func_16); } } -void Beetom_Func_34(void) { // 0xA8BD8C - Enemy_Beetom *E = Get_Beetom(cur_enemy_index); - if (joypad1_lastkeys != E->beetom_var_F) { - E->beetom_var_F = joypad1_lastkeys; - --E->beetom_var_E; - } -} - void Beetom_Func_35(void) { // 0xA8BD9D - R20_ = 3; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(3, 0))) { Enemy_Beetom *E = Get_Beetom(cur_enemy_index); if (E->beetom_var_09) E->beetom_var_C = FUNC16(Beetom_Func_7); @@ -2440,16 +2319,10 @@ void Beetom_Func_35(void) { // 0xA8BD9D } } -void Beetom_Func_36(void) { // 0xA8BDC5 - Beetom_Func_37(cur_enemy_index); -} - void Beetom_Func_37(uint16 k) { // 0xA8BDCC Enemy_Beetom *E = Get_Beetom(k); - int v2 = (uint16)(8 * E->beetom_var_B) >> 1; - R20_ = kCommonEnemySpeeds_Quadratic[v2 + 1]; - R18_ = kCommonEnemySpeeds_Quadratic[v2]; - if (Enemy_MoveDown(k) & 1) { + int v2 = (8 * E->beetom_var_B) >> 1; + if (Enemy_MoveDown(k, kCommonEnemySpeeds_Quadratic32[v2 >> 1])) { E->beetom_var_C = FUNC16(Beetom_Func_3); } else { uint16 v3 = E->beetom_var_B + 1; @@ -2457,19 +2330,55 @@ void Beetom_Func_37(uint16 k) { // 0xA8BDCC if (!sign16(v3 - 64)) E->beetom_var_B = 64; } - uint16 v4; - if (E->beetom_var_09) - v4 = -2; - else - v4 = 2; - R20_ = v4; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { - E->beetom_var_09 ^= 1u; + uint16 v4 = (E->beetom_var_09) ? -2 : 2; + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(v4, 0))) { + E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } } +void Beetom_Func_36(void) { // 0xA8BDC5 + Beetom_Func_37(cur_enemy_index); +} + +void CallBeetomFunc(uint32 ea) { + switch (ea) { + case fnBeetom_Func_3: Beetom_Func_3(); return; // 0xa8b814 + case fnBeetom_Func_4: Beetom_Func_4(); return; // 0xa8b82f + case fnBeetom_Func_5: Beetom_Func_5(); return; // 0xa8b84f + case fnBeetom_Func_6: Beetom_Func_6(); return; // 0xa8b85f + case fnBeetom_Func_7: Beetom_Func_7(); return; // 0xa8b873 + case fnBeetom_Func_8: Beetom_Func_8(); return; // 0xa8b887 + case fnBeetom_Func_9: Beetom_Func_9(); return; // 0xa8b8a9 + case fnBeetom_Func_10: Beetom_Func_10(); return; // 0xa8b8cb + case fnBeetom_Func_11: Beetom_Func_11(); return; // 0xa8b8ed + case fnBeetom_Func_12: Beetom_Func_12(); return; // 0xa8b90f + case fnBeetom_Func_13: Beetom_Func_13(); return; // 0xa8b952 + case fnBeetom_Func_14: Beetom_Func_14(); return; // 0xa8b966 + case fnBeetom_Func_15: Beetom_Func_15(); return; // 0xa8b97a + case fnBeetom_Func_16: Beetom_Func_16(); return; // 0xa8b9a2 + case fnBeetom_Func_17: Beetom_Func_17(); return; // 0xa8b9b2 + case fnBeetom_Func_18: Beetom_Func_18(); return; // 0xa8b9c1 + case fnBeetom_Func_19: Beetom_Func_19(); return; // 0xa8ba24 + case fnBeetom_Func_20: Beetom_Func_20(); return; // 0xa8ba84 + case fnBeetom_Func_21: Beetom_Func_21(); return; // 0xa8bab7 + case fnBeetom_Func_24: Beetom_Func_24(); return; // 0xa8bb55 + case fnBeetom_Func_25: Beetom_Func_25(); return; // 0xa8bb88 + case fnBeetom_Func_28: Beetom_Func_28(); return; // 0xa8bc26 + case fnBeetom_Func_29: Beetom_Func_29(); return; // 0xa8bc5a + case fnBeetom_Func_32: Beetom_Func_32(); return; // 0xa8bcf8 + case fnBeetom_Func_33: Beetom_Func_33(); return; // 0xa8bd42 + case fnBeetom_Func_35: Beetom_Func_35(); return; // 0xa8bd9d + case fnBeetom_Func_36: Beetom_Func_36(); return; // 0xa8bdc5 + default: Unreachable(); + } +} + +void Beetom_Main(void) { // 0xA8B80D + Enemy_Beetom *E = Get_Beetom(cur_enemy_index); + CallBeetomFunc(E->beetom_var_C | 0xA80000); +} + void Beetom_Touch(void) { // 0xA8BE2E Enemy_Beetom *E = Get_Beetom(cur_enemy_index); if (!E->beetom_var_08) { @@ -2485,8 +2394,8 @@ void Beetom_Touch(void) { // 0xA8BE2E } if (samus_contact_damage_index) goto LABEL_11; - if ((enemy_damage_routine_exec_count & 7) == 7 && !sign16(samus_health - 30)) - QueueSfx3_Max6(0x2Du); + if ((random_enemy_counter & 7) == 7 && !sign16(samus_health - 30)) + QueueSfx3_Max6(0x2D); if ((E->base.frame_counter & 0x3F) == 63) { LABEL_11: Enemy_NormalTouchAI_A8(); @@ -2554,7 +2463,7 @@ void MaridiaFloater_Func_2(uint16 k) { // 0xA8C234 void MaridiaFloater_Func_3(uint16 k) { // 0xA8C283 Enemy_MaridiaFloater *E = Get_MaridiaFloater(k); bool v2 = E->mfr_var_E == 1; - bool v3 = (--E->mfr_var_E & 0x8000u) != 0; + bool v3 = (--E->mfr_var_E & 0x8000) != 0; if (v2 || v3) { int v4 = k >> 1; enemy_drawing_queue[v4 + 104] = 1; @@ -2568,7 +2477,7 @@ void MaridiaFloater_Func_3(uint16 k) { // 0xA8C283 void MaridiaFloater_Func_4(uint16 k) { // 0xA8C2A6 Enemy_MaridiaFloater *E = Get_MaridiaFloater(k); bool v2 = E->mfr_var_E == 1; - bool v3 = (--E->mfr_var_E & 0x8000u) != 0; + bool v3 = (--E->mfr_var_E & 0x8000) != 0; if (v2 || v3) { E->mfr_var_F = FUNC16(MaridiaFloater_Func_5); E->mfr_var_A = g_word_A8C1C5; @@ -2586,7 +2495,7 @@ void MaridiaFloater_Func_5(uint16 k) { // 0xA8C2CF MaridiaFloater_Func_7(k); } else { bool v2 = E->mfr_var_D == 1; - bool v3 = (--E->mfr_var_D & 0x8000u) != 0; + bool v3 = (--E->mfr_var_D & 0x8000) != 0; if (v2 || v3) { E->mfr_var_D = 5; int v4 = k >> 1; @@ -2602,9 +2511,7 @@ void MaridiaFloater_Func_5(uint16 k) { // 0xA8C2CF bool v8 = __CFADD__uint16(g_word_A8C1BB, mfr_var_B); E->mfr_var_B = g_word_A8C1BB + mfr_var_B; E->mfr_var_A += g_word_A8C1B9 + v8; - R20_ = E->mfr_var_A; - R18_ = E->mfr_var_B; - if (Enemy_MoveDown(k) & 1 + if (Enemy_MoveDown(k, __PAIR32__(E->mfr_var_A, E->mfr_var_B)) || (int16)(enemy_drawing_queue_sizes[(k >> 1) + 1] - g_word_A8C19F - E->base.y_pos) >= 0) { uint16 mfr_var_C = E->mfr_var_C; if (!mfr_var_C || mfr_var_C == 6) { @@ -2624,16 +2531,14 @@ void MaridiaFloater_Func_5(uint16 k) { // 0xA8C2CF void MaridiaFloater_Func_6(uint16 k) { // 0xA8C36B Enemy_MaridiaFloater *E = Get_MaridiaFloater(k); bool v2 = E->mfr_var_D == 1; - bool v3 = (--E->mfr_var_D & 0x8000u) != 0; + bool v3 = (--E->mfr_var_D & 0x8000) != 0; if (!v2 && !v3) { LABEL_9:; uint16 mfr_var_B = E->mfr_var_B; bool v9 = __CFADD__uint16(g_word_A8C1BB, mfr_var_B); E->mfr_var_B = g_word_A8C1BB + mfr_var_B; E->mfr_var_A += g_word_A8C1B9 + v9; - R20_ = E->mfr_var_A; - R18_ = E->mfr_var_B; - Enemy_MoveDown(k); + Enemy_MoveDown(k, __PAIR32__(E->mfr_var_A, E->mfr_var_B)); goto LABEL_10; } E->mfr_var_D = 5; @@ -2663,7 +2568,7 @@ void MaridiaFloater_Func_7(uint16 k) { // 0xA8C3E1 Enemy_MaridiaFloater *E = Get_MaridiaFloater(k); if ((E->base.ai_handler_bits & 1) != 0) { bool v2 = E->mfr_var_D == 1; - bool v3 = (--E->mfr_var_D & 0x8000u) != 0; + bool v3 = (--E->mfr_var_D & 0x8000) != 0; if (v2 || v3) { E->mfr_var_D = 5; int v4 = k >> 1; @@ -2679,9 +2584,7 @@ void MaridiaFloater_Func_7(uint16 k) { // 0xA8C3E1 bool v8 = __CFADD__uint16(g_word_A8C1BB, mfr_var_B); E->mfr_var_B = g_word_A8C1BB + mfr_var_B; E->mfr_var_A += g_word_A8C1B9 + v8; - R20_ = E->mfr_var_A; - R18_ = E->mfr_var_B; - if (Enemy_MoveDown(k) & 1 + if (Enemy_MoveDown(k, __PAIR32__(E->mfr_var_A, E->mfr_var_B)) || (int16)(enemy_drawing_queue_sizes[(k >> 1) + 1] - enemy_drawing_queue_sizes[(k >> 1) + 3] - E->base.y_pos) >= 0) { @@ -2704,7 +2607,7 @@ void MaridiaFloater_Func_8(uint16 k) { // 0xA8C469 return; } bool v2 = E->mfr_var_D == 1; - bool v3 = (--E->mfr_var_D & 0x8000u) != 0; + bool v3 = (--E->mfr_var_D & 0x8000) != 0; if (!v2 && !v3) goto LABEL_11; E->mfr_var_D = 5; @@ -2726,9 +2629,7 @@ LABEL_11:; bool v9 = __CFADD__uint16(g_word_A8C1BB, mfr_var_B); E->mfr_var_B = g_word_A8C1BB + mfr_var_B; E->mfr_var_A += g_word_A8C1B9 + v9; - R20_ = E->mfr_var_A; - R18_ = E->mfr_var_B; - Enemy_MoveDown(k); + Enemy_MoveDown(k, __PAIR32__(E->mfr_var_A, E->mfr_var_B)); goto LABEL_12; } E->mfr_var_F = FUNC16(MaridiaFloater_Func_9); @@ -2751,7 +2652,7 @@ void MaridiaFloater_Func_9(uint16 k) { // 0xA8C4DC void MaridiaFloater_Func_10(uint16 k) { // 0xA8C500 Enemy_MaridiaFloater *E = Get_MaridiaFloater(k); bool v2 = E->mfr_var_E == 1; - bool v3 = (--E->mfr_var_E & 0x8000u) != 0; + bool v3 = (--E->mfr_var_E & 0x8000) != 0; if (v2 || v3) { E->mfr_var_F = FUNC16(MaridiaFloater_Func_11); E->mfr_var_A = g_word_A8C1C1; @@ -2766,9 +2667,7 @@ void MaridiaFloater_Func_11(uint16 k) { // 0xA8C51D bool v3 = __CFADD__uint16(g_word_A8C1BF, mfr_var_B); E->mfr_var_B = g_word_A8C1BF + mfr_var_B; E->mfr_var_A += g_word_A8C1BD + v3; - R20_ = E->mfr_var_A; - R18_ = E->mfr_var_B; - Enemy_MoveDown(k); + Enemy_MoveDown(k, __PAIR32__(E->mfr_var_A, E->mfr_var_B)); int v4 = k >> 1; if ((int16)(E->base.y_pos - enemy_drawing_queue_sizes[v4 + 1]) >= 0) { E->base.y_pos = enemy_drawing_queue_sizes[v4 + 1]; @@ -2800,11 +2699,11 @@ void MaridiaFloater_Func_13(uint16 k) { // 0xA8C59F Enemy_MaridiaFloater *E = Get_MaridiaFloater(k); bool v2 = E->mfr_var_E == 1; - bool v3 = (--E->mfr_var_E & 0x8000u) != 0; + bool v3 = (--E->mfr_var_E & 0x8000) != 0; if (v2 || v3) { int v4 = k >> 1; enemy_drawing_queue[v4 + 100] = 0; - enemy_drawing_queue[v4 + 97] |= 0x200u; + enemy_drawing_queue[v4 + 97] |= 0x200; MaridiaFloater_Func_1(k); //printf("A undefined!\n"); v5 = 0; @@ -2820,7 +2719,7 @@ void MaridiaFloater_Touch(void) { // 0xA8C5BE uint16 palette_index = E->base.palette_index; NormalEnemyTouchAi(); if (!E->base.health) { - enemy_drawing_queue[(cur_enemy_index >> 1) + 97] |= 0x200u; + enemy_drawing_queue[(cur_enemy_index >> 1) + 97] |= 0x200; E->base.palette_index = palette_index; MaridiaFloater_Func_1(cur_enemy_index); E->base.palette_index = 2560; @@ -2835,12 +2734,12 @@ void MaridiaFloater_Shot(void) { // 0xA8C5EF if ((E->base.ai_handler_bits & 4) != 0) { int v2 = cur_enemy_index >> 1; enemy_drawing_queue[v2 + 109] = E->base.frozen_timer; - enemy_drawing_queue[v2 + 99] |= 4u; + enemy_drawing_queue[v2 + 99] |= 4; } if ((E->base.ai_handler_bits & 2) != 0) { int v3 = cur_enemy_index >> 1; enemy_drawing_queue[v3 + 108] = E->base.flash_timer; - enemy_drawing_queue[v3 + 99] |= 2u; + enemy_drawing_queue[v3 + 99] |= 2; } if (!E->base.health) { E->mfr_var_F = FUNC16(MaridiaFloater_Func_12); @@ -2860,7 +2759,7 @@ void MaridiaFloater_Powerbomb(void) { // 0xA8C63F enemy_drawing_queue[v1 + 109] = E->base.frozen_timer; enemy_drawing_queue[v1 + 99] = E->base.ai_handler_bits; } else { - enemy_drawing_queue[(cur_enemy_index >> 1) + 97] |= 0x200u; + enemy_drawing_queue[(cur_enemy_index >> 1) + 97] |= 0x200; } } @@ -2869,7 +2768,7 @@ void WreckedShipRobot_Init(void) { // 0xA8CB77 enemy_gfx_drawn_hook.bank = -88; enemy_gfx_drawn_hook.addr = FUNC16(WreckedShipRobot_Func_1); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); - E->base.properties |= 0xA000u; + E->base.properties |= 0xA000; E->base.instruction_timer = 4; E->base.timer = 0; E->base.current_instruction = addr_kWreckedShipRobot_Ilist_C6E5; @@ -2890,13 +2789,13 @@ void WreckedShipRobotDeactivated_Init(void) { // 0xA8CBCC parameter_1 = 0; v0->parameter_1 = parameter_1; v0->current_instruction = g_off_A8CC30[parameter_1]; - v0->properties |= 0x8000u; + v0->properties |= 0x8000; v0->instruction_timer = 1; v0->timer = 0; wrecked_ship_robot_palanim_timer = 0; v0->ai_var_E = 0; v0->ai_preinstr = 1; - int v2 = (uint16)(16 * (uint8)((uint16)(wrecked_ship_robot_palanim_palindex & 0xFF00) >> 8)) >> 1; + int v2 = (16 * ((wrecked_ship_robot_palanim_palindex & 0xFF00) >> 8)) >> 1; palette_buffer[v2 + 137] = 10; palette_buffer[v2 + 138] = 10; palette_buffer[v2 + 139] = 10; @@ -2905,9 +2804,7 @@ void WreckedShipRobotDeactivated_Init(void) { // 0xA8CBCC void WreckedShipRobot_Main(void) { // 0xA8CC36 Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); - R18_ = E->wsrt_var_E; - R20_ = E->wsrt_var_F; - if (!(Enemy_MoveDown(cur_enemy_index) & 1)) { + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(E->wsrt_var_F, E->wsrt_var_E))) { ++E->base.instruction_timer; uint16 wsrt_var_E = E->wsrt_var_E; E->wsrt_var_E = wsrt_var_E + 0x8000; @@ -2929,7 +2826,7 @@ void WreckedShipRobot_Func_1(void) { // 0xA8CC67 if (v2 >= 0) break; } - int v3 = (uint16)(16 * (uint8)((uint16)(wrecked_ship_robot_palanim_palindex & 0xFF00) >> 8)) >> 1; + int v3 = (16 * ((wrecked_ship_robot_palanim_palindex & 0xFF00) >> 8)) >> 1; palette_buffer[v3 + 137] = v2; palette_buffer[v3 + 138] = g_word_A8CCC1[v1 + 1]; palette_buffer[v3 + 139] = g_word_A8CCC1[v1 + 2]; @@ -2952,9 +2849,7 @@ const uint16 *WreckedShipRobot_Instr_4(uint16 k, const uint16 *jp) { // 0xA8CD0 WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = -512; - R18_ = 0; - R20_ = -4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(-4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_kWreckedShipRobot_Ilist_C73F); } else { @@ -2966,9 +2861,7 @@ const uint16 *WreckedShipRobot_Instr_4(uint16 k, const uint16 *jp) { // 0xA8CD0 uint16 x_pos = E->base.x_pos; E->wsrt_var_C = x_pos; E->base.x_pos = x_pos - E->base.x_width - E->base.x_width; - R18_ = 0; - R20_ = 1; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.x_pos = E->wsrt_var_C; E->base.y_pos = E->wsrt_var_D; } else { @@ -2986,9 +2879,7 @@ const uint16 *WreckedShipRobot_Instr_9(uint16 k, const uint16 *jp) { // 0xA8CDA WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = -512; - R18_ = 0; - R20_ = -4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(-4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_kWreckedShipRobot_Ilist_C73F); } else if (CheckIfEnemyTouchesSamus(cur_enemy_index)) { @@ -3002,9 +2893,7 @@ const uint16 *WreckedShipRobot_Instr_6(uint16 k, const uint16 *jp) { // 0xA8CDE WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = -512; - R18_ = 0; - R20_ = 4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_stru_A8C6E9); } else { @@ -3016,9 +2905,7 @@ const uint16 *WreckedShipRobot_Instr_6(uint16 k, const uint16 *jp) { // 0xA8CDE uint16 x_pos = E->base.x_pos; E->wsrt_var_C = x_pos; E->base.x_pos = E->base.x_width + E->base.x_width + x_pos; - R18_ = 0; - R20_ = 1; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.x_pos = E->wsrt_var_C; E->base.y_pos = E->wsrt_var_D; } else { @@ -3036,9 +2923,7 @@ const uint16 *WreckedShipRobot_Instr_8(uint16 k, const uint16 *jp) { // 0xA8CE8 WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = -512; - R18_ = 0; - R20_ = 4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_stru_A8C6E9); } else if (CheckIfEnemyTouchesSamus(cur_enemy_index)) { @@ -3056,9 +2941,7 @@ const uint16 *WreckedShipRobot_Instr_15(uint16 k, const uint16 *jp) { // 0xA8CE WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = 512; - R18_ = 0; - R20_ = 4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_kWreckedShipRobot_Ilist_C985); } else { @@ -3070,9 +2953,7 @@ const uint16 *WreckedShipRobot_Instr_15(uint16 k, const uint16 *jp) { // 0xA8CE uint16 x_pos = E->base.x_pos; E->wsrt_var_C = x_pos; E->base.x_pos = E->base.x_width + E->base.x_width + x_pos; - R18_ = 0; - R20_ = 1; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.x_pos = E->wsrt_var_C; E->base.y_pos = E->wsrt_var_D; } else { @@ -3090,9 +2971,7 @@ const uint16 *WreckedShipRobot_Instr_18(uint16 k, const uint16 *jp) { // 0xA8CF WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = 512; - R18_ = 0; - R20_ = 4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_kWreckedShipRobot_Ilist_C985); } else if (CheckIfEnemyTouchesSamus(cur_enemy_index)) { @@ -3106,9 +2985,7 @@ const uint16 *WreckedShipRobot_Instr_16(uint16 k, const uint16 *jp) { // 0xA8CF WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = 512; - R18_ = 0; - R20_ = -4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(-4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_stru_A8C6E9); } else { @@ -3120,9 +2997,7 @@ const uint16 *WreckedShipRobot_Instr_16(uint16 k, const uint16 *jp) { // 0xA8CF uint16 x_pos = E->base.x_pos; E->wsrt_var_C = x_pos; E->base.x_pos = x_pos - E->base.x_width - E->base.x_width; - R18_ = 0; - R20_ = 1; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.y_pos = E->wsrt_var_D; E->base.x_pos = E->wsrt_var_C; } else { @@ -3140,9 +3015,7 @@ const uint16 *WreckedShipRobot_Instr_17(uint16 k, const uint16 *jp) { // 0xA8D0 WreckedShipRobot_Func_2(cur_enemy_index); Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); E->wsrt_var_A = 512; - R18_ = 0; - R20_ = -4; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(-4))) { E->wsrt_var_B += 8; return INSTR_RETURN_ADDR(addr_stru_A8C6E9); } else if (CheckIfEnemyTouchesSamus(cur_enemy_index)) { @@ -3158,7 +3031,7 @@ const uint16 *WreckedShipRobot_Instr_3(uint16 k, const uint16 *jp) { // 0xA8D09 && (int16)(layer1_x_pos + 256 - E->base.x_pos) >= 0 && (int16)(layer1_y_pos - E->base.y_pos) < 0 && (int16)(layer1_y_pos + 224 - E->base.y_pos) >= 0) { - QueueSfx2_Max6(0x68u); + QueueSfx2_Max6(0x68); } return jp; } @@ -3168,41 +3041,37 @@ const uint16 *WreckedShipRobot_Instr_10(uint16 k, const uint16 *jp) { // 0xA8D0 } const uint16 *WreckedShipRobot_Instr_14(uint16 k, const uint16 *jp) { // 0xA8D0C6 - R50 = addr_kWreckedShipRobot_Ilist_CB1D; - R48 = addr_kEproj_WreckedShipRobotLaserUpRight; - return WreckedShipRobot_CommonInstr(k, jp); + return WreckedShipRobot_CommonInstr(k, jp, + addr_kWreckedShipRobot_Ilist_CB1D, addr_kEproj_WreckedShipRobotLaserUpRight); } const uint16 *WreckedShipRobot_Instr_2(uint16 k, const uint16 *jp) { // 0xA8D0D2 - R50 = addr_kWreckedShipRobot_Ilist_C8D1; - R48 = addr_kEproj_WreckedShipRobotLaserUpLeft; - return WreckedShipRobot_CommonInstr(k, jp); + return WreckedShipRobot_CommonInstr(k, jp, + addr_kWreckedShipRobot_Ilist_C8D1, addr_kEproj_WreckedShipRobotLaserUpLeft); } -const uint16 *WreckedShipRobot_CommonInstr(uint16 k, const uint16 *jp) { // 0xA8D0DC +const uint16 *WreckedShipRobot_CommonInstr(uint16 k, const uint16 *jp, uint16 r50, uint16 r48) { // 0xA8D0DC Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(k); if (E->wsrt_var_B) { WreckedShipRobot_Func_2(k); } else { uint16 v3 = (random_number & 0x1F) + 16; E->wsrt_var_B = v3; - SpawnEnemyProjectileWithGfx(v3, cur_enemy_index, R48); - return INSTR_RETURN_ADDR(R50); + SpawnEnemyProjectileWithGfx(v3, cur_enemy_index, r48); + return INSTR_RETURN_ADDR(r50); } return jp; } const uint16 *WreckedShipRobot_Instr_13(uint16 k, const uint16 *jp) { // 0xA8D100 - R50 = addr_kWreckedShipRobot_Ilist_CB09; - return WreckedShipRobot_D10C(k, jp); + return WreckedShipRobot_D10C(k, jp, addr_kWreckedShipRobot_Ilist_CB09); } const uint16 *WreckedShipRobot_Instr_1(uint16 k, const uint16 *jp) { // 0xA8D107 - R50 = addr_kWreckedShipRobot_Ilist_C8BD; - return WreckedShipRobot_D10C(k, jp); + return WreckedShipRobot_D10C(k, jp, addr_kWreckedShipRobot_Ilist_C8BD); } -const uint16 *WreckedShipRobot_D10C(uint16 k, const uint16 *jp) { // 0xA8D10C +const uint16 *WreckedShipRobot_D10C(uint16 k, const uint16 *jp, uint16 r50) { // 0xA8D10C Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(k); if (E->wsrt_var_B) { WreckedShipRobot_Func_2(k); @@ -3210,32 +3079,30 @@ const uint16 *WreckedShipRobot_D10C(uint16 k, const uint16 *jp) { // 0xA8D10C uint16 v3 = (random_number & 0x1F) + 16; E->wsrt_var_B = v3; SpawnEnemyProjectileWithGfx(v3, cur_enemy_index, addr_kEproj_WreckedShipRobotLaserHorizontal); - return INSTR_RETURN_ADDR(R50); + return INSTR_RETURN_ADDR(r50); } return jp; } const uint16 *WreckedShipRobot_Instr_12(uint16 k, const uint16 *jp) { // 0xA8D131 - R48 = addr_kEproj_WreckedShipRobotLaserDownRight; - R50 = addr_kWreckedShipRobot_Ilist_CAFD; - return WreckedShipRobot_D147(k, jp); + return WreckedShipRobot_D147(k, jp, + addr_kEproj_WreckedShipRobotLaserDownRight, addr_kWreckedShipRobot_Ilist_CAFD); } const uint16 *WreckedShipRobot_Instr_5(uint16 k, const uint16 *jp) { // 0xA8D13D - R48 = addr_kEproj_WreckedShipRobotLaserDownLeft; - R50 = addr_kWreckedShipRobot_Ilist_C8B1; - return WreckedShipRobot_D147(k, jp); + return WreckedShipRobot_D147(k, jp, + addr_kEproj_WreckedShipRobotLaserDownLeft, addr_kWreckedShipRobot_Ilist_C8B1); } -const uint16 *WreckedShipRobot_D147(uint16 k, const uint16 *jp) { // 0xA8D147 +const uint16 *WreckedShipRobot_D147(uint16 k, const uint16 *jp, uint16 r48, uint16 r50) { // 0xA8D147 Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(k); if (E->wsrt_var_B) { WreckedShipRobot_Func_2(k); } else { uint16 v3 = (random_number & 0x1F) + 16; E->wsrt_var_B = v3; - SpawnEnemyProjectileWithGfx(v3, cur_enemy_index, R48); - return INSTR_RETURN_ADDR(R50); + SpawnEnemyProjectileWithGfx(v3, cur_enemy_index, r48); + return INSTR_RETURN_ADDR(r50); } return INSTR_RETURN_ADDR(jp[0]); } @@ -3262,7 +3129,7 @@ void WreckedShipRobot_Shot(void) { // 0xA8D192 Enemy_WreckedShipRobot *E = Get_WreckedShipRobot(cur_enemy_index); if (E->base.health) { uint16 v1; - if ((E->wsrt_var_A & 0x8000u) != 0) { + if ((E->wsrt_var_A & 0x8000) != 0) { if ((int16)(samus_x_pos - E->base.x_pos) >= 0) v1 = addr_kWreckedShipRobot_Ilist_C833; else @@ -3368,37 +3235,29 @@ void MaridiaPuffer_Func_5(void) { // 0xA8D9AA } void MaridiaPuffer_Func_6(void) { // 0xA8D9DB - R26_ = 0; - R18_ = kSine16bit[(uint8)(Get_MaridiaPuffer(cur_enemy_index)->mpr_var_02 + 64)]; - if ((R18_ & 0x8000u) != 0) - ++R26_; - R22_ = (Abs16(R18_) & 0xFF00) >> 8; Enemy_MaridiaPuffer *E = Get_MaridiaPuffer(cur_enemy_index); - R24_ = E->mpr_var_D; - MaridiaPuffer_Func_10(); - if (R26_) - MaridiaPuffer_Func_11(); - uint16 x_subpos = E->base.x_subpos; - bool v5 = __CFADD__uint16(R28_, x_subpos); - E->base.x_subpos = R28_ + x_subpos; - E->base.x_pos += R30_ + v5; + uint16 R26 = 0; + uint16 r18 = kSine16bit[(uint8)(E->mpr_var_02 + 64)]; + if ((r18 & 0x8000) != 0) + ++R26; + uint32 t = ((Abs16(r18) & 0xFF00) >> 8) * E->mpr_var_D; + if (R26) + t = -(int32)t; + t = t + E->base.x_subpos; + E->base.x_subpos = t, E->base.x_pos = t >> 16; } void MaridiaPuffer_Func_7(void) { // 0xA8DA28 Enemy_MaridiaPuffer *E = Get_MaridiaPuffer(cur_enemy_index); - R26_ = 0; - R18_ = kSine16bit[(uint8)E->mpr_var_02]; - if ((R18_ & 0x8000u) != 0) - ++R26_; - R22_ = (Abs16(R18_) & 0xFF00) >> 8; - R24_ = E->mpr_var_D; - MaridiaPuffer_Func_10(); - if (R26_) - MaridiaPuffer_Func_11(); - uint16 y_subpos = E->base.y_subpos; - bool v5 = __CFADD__uint16(R28_, y_subpos); - E->base.y_subpos = R28_ + y_subpos; - E->base.y_pos += R30_ + v5; + uint16 R26 = 0; + uint16 r18 = kSine16bit[(uint8)E->mpr_var_02]; + if ((r18 & 0x8000) != 0) + ++R26; + uint32 t = ((Abs16(r18) & 0xFF00) >> 8) * E->mpr_var_D; + if (R26) + t = -(int32)t; + t = t + E->base.y_subpos; + E->base.y_subpos = t, E->base.y_pos = t >> 16; } void MaridiaPuffer_Func_8(uint16 k) { // 0xA8DA71 @@ -3419,29 +3278,6 @@ void MaridiaPuffer_Func_9(uint16 k) { // 0xA8DA92 } } -void MaridiaPuffer_Func_10(void) { // 0xA8DAB3 - uint16 prod1 = Mult8x8(R22_, R24_); - uint16 prod2 = Mult8x8(R22_, HIBYTE(R24_)); - R28_ = prod1; - R30_ = (uint8)(prod2 >> 8); - uint16 v1 = (uint8)prod2 << 8; - bool v2 = __CFADD__uint16(R28_, v1); - R28_ += v1; - if (v2) - ++R30_; -} - -void MaridiaPuffer_Func_11(void) { // 0xA8DAF6 - if (R28_) { - R28_ = -R28_; - } else { - if (!R30_) - return; - --R28_; - } - R30_ = ~R30_; -} - void MaridiaPuffer_Shot(void) { // 0xA8DB14 Enemy_MaridiaPuffer *E = Get_MaridiaPuffer(cur_enemy_index); E->mpr_var_40 = E->base.health; @@ -3450,9 +3286,7 @@ void MaridiaPuffer_Shot(void) { // 0xA8DB14 E->base.instruction_timer = 1; E->base.timer = 0; E->base.current_instruction = addr_kMaridiaPuffer_Ilist_D855; - E->mpr_var_02 = g_word_A8D871[(uint16)(2 - * (projectile_dir[(uint16)(2 - * collision_detection_index) >> 1] & 0xF)) >> 1]; + E->mpr_var_02 = g_word_A8D871[projectile_dir[collision_detection_index] & 0xF]; E->mpr_var_B = 256; E->mpr_var_D = 1536; E->mpr_var_A = FUNC16(MaridiaPuffer_Func_4); @@ -3475,11 +3309,9 @@ void WalkingLavaSeahorse_Init(void) { // 0xA8DCCD bool v4 = __CFADD__uint16(E->base.y_subpos, wlse_var_C); E->base.y_subpos += wlse_var_C; E->base.y_pos += v4 + E->wlse_var_B; - } while ((WalkingLavaSeahorse_Func_2(cur_enemy_index) & 0x8000u) != 0); + } while ((WalkingLavaSeahorse_Func_2(cur_enemy_index) & 0x8000) != 0); while (1) { - R18_ = E->wlse_var_C; - R20_ = E->wlse_var_B; - if (Enemy_MoveDown(cur_enemy_index) & 1) + if (Enemy_MoveDown(cur_enemy_index, __PAIR32__(E->wlse_var_B, E->wlse_var_C))) break; WalkingLavaSeahorse_Func_2(cur_enemy_index); } @@ -3494,7 +3326,7 @@ void WalkingLavaSeahorse_Func_1(uint16 k) { // 0xA8DD37 E->wlse_var_D = 0; E->wlse_var_E = 0; E->wlse_var_00 = 0; - E->wlse_var_01 = FUNC16(Enemy_GrappleReact_NoInteract_A8); + E->wlse_var_01 = 0x8000; } uint16 WalkingLavaSeahorse_Func_2(uint16 k) { // 0xA8DD55 @@ -3544,7 +3376,7 @@ void WalkingLavaSeahorse_Func_3(uint16 k) { // 0xA8DD71 E->base.current_instruction = v4; E->base.instruction_timer = 1; E->wlse_var_A = FUNC16(WalkingLavaSeahorse_Func_4); - QueueSfx2_Max6(0x5Eu); + QueueSfx2_Max6(0x5E); } } @@ -3554,7 +3386,7 @@ void WalkingLavaSeahorse_Func_4(uint16 k) { // 0xA8DDC6 bool v3 = __CFADD__uint16(E->base.y_subpos, wlse_var_C); E->base.y_subpos += wlse_var_C; E->base.y_pos += v3 + E->wlse_var_B; - if ((WalkingLavaSeahorse_Func_2(k) & 0x8000u) == 0) + if ((WalkingLavaSeahorse_Func_2(k) & 0x8000) == 0) sub_A8DDDE(k); } @@ -3562,7 +3394,7 @@ void sub_A8DDDE(uint16 k) { // 0xA8DDDE EnemyData *v1 = gEnemyData(k); v1->ai_var_A = FUNC16(WalkingLavaSeahorse_Func_6); uint16 v2 = addr_kWalkingLavaSeahorse_Ilist_DC51; - if ((v1->ai_var_D & 0x8000u) == 0) + if ((v1->ai_var_D & 0x8000) == 0) v2 = addr_kWalkingLavaSeahorse_Ilist_DCC1; v1->current_instruction = v2; v1->instruction_timer = 1; @@ -3579,9 +3411,7 @@ void WalkingLavaSeahorse_Func_6(uint16 k) { // 0xA8DE05 int16 v3; Enemy_WalkingLavaSeahorse *E = Get_WalkingLavaSeahorse(k); - R18_ = E->wlse_var_C; - R20_ = E->wlse_var_B; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, __PAIR32__(E->wlse_var_B, E->wlse_var_C))) { int t = samus_x_pos - E->base.x_pos; uint16 v2 = addr_kWalkingLavaSeahorse_Ilist_DBE7; v3 = -2; @@ -3600,16 +3430,14 @@ void WalkingLavaSeahorse_Func_6(uint16 k) { // 0xA8DE05 } void WalkingLavaSeahorse_Func_7(uint16 k) { // 0xA8DE4B - R18_ = 0; - R20_ = 2; - Enemy_MoveDown(k); + Enemy_MoveDown(k, INT16_SHL16(2)); Enemy_WalkingLavaSeahorse *E = Get_WalkingLavaSeahorse(k); if ((int16)(abs16(E->wlse_var_02 - E->base.x_pos) - g_word_A8DCCB) >= 0) { E->wlse_var_A = FUNC16(WalkingLavaSeahorse_Func_8); E->wlse_var_B = -4; E->wlse_var_C = 0; uint16 v4 = addr_kWalkingLavaSeahorse_Ilist_DC51; - if ((E->wlse_var_D & 0x8000u) == 0) + if ((E->wlse_var_D & 0x8000) == 0) v4 = addr_kWalkingLavaSeahorse_Ilist_DCC1; E->base.current_instruction = v4; E->base.instruction_timer = 1; @@ -3620,11 +3448,11 @@ void WalkingLavaSeahorse_Func_7(uint16 k) { // 0xA8DE4B uint16 v3; if (!sign16(t)) { v3 = addr_kWalkingLavaSeahorse_Ilist_DC73; - if ((E->wlse_var_D & 0x8000u) != 0) + if ((E->wlse_var_D & 0x8000) != 0) return; } else { v3 = addr_kWalkingLavaSeahorse_Ilist_DC03; - if ((E->wlse_var_D & 0x8000u) == 0) + if ((E->wlse_var_D & 0x8000) == 0) return; } E->base.current_instruction = v3; @@ -3639,7 +3467,7 @@ void WalkingLavaSeahorse_Func_8(uint16 k) { // 0xA8DECD bool v3 = __CFADD__uint16(E->base.y_subpos, wlse_var_C); E->base.y_subpos += wlse_var_C; E->base.y_pos += v3 + E->wlse_var_B; - if ((WalkingLavaSeahorse_Func_2(k) & 0x8000u) == 0) + if ((WalkingLavaSeahorse_Func_2(k) & 0x8000) == 0) E->wlse_var_A = FUNC16(WalkingLavaSeahorse_Func_9); } @@ -3666,16 +3494,16 @@ const uint16 *WalkingLavaSeahorse_Instr_4(uint16 k, const uint16 *jp) { // 0xA8 void WalkingLavaSeahorse_DF20(uint16 a) { // 0xA8DF20 SpawnEnemyProjectileWithGfx(a, cur_enemy_index, addr_loc_A89E90); - QueueSfx2_Max6(0x3Fu); + QueueSfx2_Max6(0x3F); } const uint16 *WalkingLavaSeahorse_Instr_3(uint16 k, const uint16 *jp) { // 0xA8DF33 - WalkingLavaSeahorse_DF20(2u); + WalkingLavaSeahorse_DF20(2); return jp; } const uint16 *WalkingLavaSeahorse_Instr_5(uint16 k, const uint16 *jp) { // 0xA8DF39 - WalkingLavaSeahorse_DF20(4u); + WalkingLavaSeahorse_DF20(4); return jp; } @@ -3688,7 +3516,7 @@ const uint16 *WalkingLavaSeahorse_Instr_6(uint16 k, const uint16 *jp) { // 0xA8 if ((random_number & 3) == 0) v3 = 2; E->wlse_var_04 = v3; - if ((E->wlse_var_D & 0x8000u) == 0) + if ((E->wlse_var_D & 0x8000) == 0) return INSTR_RETURN_ADDR(addr_kWalkingLavaSeahorse_Ilist_DC57); return INSTR_RETURN_ADDR(addr_kWalkingLavaSeahorse_Ilist_DBE7); } @@ -3704,10 +3532,8 @@ const uint16 *WalkingLavaSeahorse_Instr_2(uint16 k, const uint16 *jp) { // 0xA8 const uint16 *WalkingLavaSeahorse_Instr_1(uint16 k, const uint16 *jp) { // 0xA8DF71 int16 wlse_var_D; - R18_ = 0; Enemy_WalkingLavaSeahorse *E = Get_WalkingLavaSeahorse(cur_enemy_index); - R20_ = E->wlse_var_D; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, INT16_SHL16(E->wlse_var_D))) { jp = INSTR_RETURN_ADDR(addr_stru_A8DBE9); wlse_var_D = E->wlse_var_D; if (wlse_var_D < 0) @@ -3728,7 +3554,7 @@ void WreckedShipOrbs_Init(void) { // 0xA8E388 E->base.instruction_timer = 1; E->base.timer = 0; E->base.current_instruction = g_off_A8E380[E->wsos_parameter_1]; - int v1 = (uint16)(8 * E->wsos_parameter_2) >> 1; + int v1 = (8 * E->wsos_parameter_2) >> 1; E->wsos_var_01 = kCommonEnemySpeeds_Linear[v1]; E->wsos_var_00 = kCommonEnemySpeeds_Linear[v1 + 1]; E->wsos_var_03 = kCommonEnemySpeeds_Linear[v1 + 2]; @@ -3760,59 +3586,35 @@ void WreckedShipOrbs_Main(void) { // 0xA8E3C3 void WreckedShipOrbs_Func_1(void) { // 0xA8E3D9 Enemy_WreckedShipOrbs *E = Get_WreckedShipOrbs(cur_enemy_index); E->wsos_var_A = FUNC16(WreckedShipOrbs_Func_3); - if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_Y(cur_enemy_index) & 0x8000) == 0) E->wsos_var_A = FUNC16(WreckedShipOrbs_Func_4); } void WreckedShipOrbs_Func_2(void) { // 0xA8E3EF Enemy_WreckedShipOrbs *E = Get_WreckedShipOrbs(cur_enemy_index); E->wsos_var_B = FUNC16(WreckedShipOrbs_Func_5); - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) E->wsos_var_B = FUNC16(WreckedShipOrbs_Func_6); } void WreckedShipOrbs_Func_3(void) { // 0xA8E405 Enemy_WreckedShipOrbs *E = Get_WreckedShipOrbs(cur_enemy_index); - E->base.y_pos += E->wsos_var_03; - uint16 y_subpos = E->base.y_subpos; - bool v2 = __CFADD__uint16(E->wsos_var_02, y_subpos); - uint16 v3 = E->wsos_var_02 + y_subpos; - if (v2) - ++E->base.y_pos; - E->base.y_subpos = v3; + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, __PAIR32__(E->wsos_var_03, E->wsos_var_02)); } void WreckedShipOrbs_Func_4(void) { // 0xA8E424 Enemy_WreckedShipOrbs *E = Get_WreckedShipOrbs(cur_enemy_index); - E->base.y_pos += E->wsos_var_01; - uint16 y_subpos = E->base.y_subpos; - bool v2 = __CFADD__uint16(E->wsos_var_00, y_subpos); - uint16 v3 = E->wsos_var_00 + y_subpos; - if (v2) - ++E->base.y_pos; - E->base.y_subpos = v3; + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, __PAIR32__(E->wsos_var_01, E->wsos_var_00)); } void WreckedShipOrbs_Func_5(void) { // 0xA8E443 Enemy_WreckedShipOrbs *E = Get_WreckedShipOrbs(cur_enemy_index); - E->base.x_pos += E->wsos_var_03; - uint16 x_subpos = E->base.x_subpos; - bool v2 = __CFADD__uint16(E->wsos_var_02, x_subpos); - uint16 v3 = E->wsos_var_02 + x_subpos; - if (v2) - ++E->base.x_pos; - E->base.x_subpos = v3; + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, __PAIR32__(E->wsos_var_03, E->wsos_var_02)); } void WreckedShipOrbs_Func_6(void) { // 0xA8E462 Enemy_WreckedShipOrbs *E = Get_WreckedShipOrbs(cur_enemy_index); - E->base.x_pos += E->wsos_var_01; - uint16 x_subpos = E->base.x_subpos; - bool v2 = __CFADD__uint16(E->wsos_var_00, x_subpos); - uint16 v3 = E->wsos_var_00 + x_subpos; - if (v2) - ++E->base.x_pos; - E->base.x_subpos = v3; + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, __PAIR32__(E->wsos_var_01, E->wsos_var_00)); } const uint16 *WreckedShipSpark_Instr_2(uint16 k, const uint16 *jp) { // 0xA8E61D @@ -3827,22 +3629,29 @@ const uint16 *WreckedShipSpark_Instr_1(uint16 k, const uint16 *jp) { // 0xA8E62 return jp; } -void WreckedShipSpark_Init(void) { // 0xA8E637 - Enemy_WreckedShipSpark *v3; // r10 +static void WreckedShipSpark_Func_4(uint16 k, uint16 r18) { // 0xA8E6F6 + int16 wssk_var_E; + + Enemy_WreckedShipSpark *E = Get_WreckedShipSpark(k); + wssk_var_E = E->wssk_var_E; + if (wssk_var_E < 0) + wssk_var_E = (NextRandom() & 0x3F) + 4; + E->wssk_var_F = r18 + wssk_var_E; +} + +void WreckedShipSpark_Init(void) { // 0xA8E637 Enemy_WreckedShipSpark *E = Get_WreckedShipSpark(cur_enemy_index); int v2 = E->wssk_parameter_1 & 3; E->wssk_var_B = g_off_A8E688[v2]; E->wssk_var_E = E->wssk_parameter_2; - R18_ = 0; - WreckedShipSpark_Func_4(cur_enemy_index); + WreckedShipSpark_Func_4(cur_enemy_index, 0); E->base.instruction_timer = 1; E->base.current_instruction = g_off_A8E682[v2]; E->base.timer = 0; E->base.instruction_timer = 1; if ((boss_bits_for_area[area_index] & 1) == 0) { - v3 = Get_WreckedShipSpark(cur_enemy_index); - v3->base.properties |= *(uint16 *)((uint8 *)&gVramWriteEntry(0)[6].vram_dst + 1); + E->base.properties |= *(uint16 *)((uint8 *)&gVramWriteEntry(0)[6].vram_dst + 1); } } @@ -3867,8 +3676,7 @@ void WreckedShipSpark_Func_1(uint16 k) { // 0xA8E695 E->wssk_var_B = FUNC16(WreckedShipSpark_Func_2); E->base.current_instruction = addr_kWreckedShipSpark_Ilist_E5A7; E->base.instruction_timer = 1; - R18_ = 0; - WreckedShipSpark_Func_4(k); + WreckedShipSpark_Func_4(k, 0); } else { --E->wssk_var_F; } @@ -3880,8 +3688,7 @@ void WreckedShipSpark_Func_2(uint16 k) { // 0xA8E6B7 E->wssk_var_B = FUNC16(WreckedShipSpark_Func_1); E->base.current_instruction = addr_kWreckedShipSpark_Ilist_E5E5; E->base.instruction_timer = 1; - R18_ = 8; - WreckedShipSpark_Func_4(k); + WreckedShipSpark_Func_4(k, 8); } else { --E->wssk_var_F; } @@ -3892,40 +3699,28 @@ void WreckedShipSpark_Func_3(uint16 k) { // 0xA8E6DC if (E->wssk_var_F == 1) { uint16 v2 = cur_enemy_index; SpawnEnemyProjectileWithGfx(0, cur_enemy_index, addr_kEproj_Sparks); - R18_ = 0; - WreckedShipSpark_Func_4(v2); + WreckedShipSpark_Func_4(v2, 0); } else { --E->wssk_var_F; } } -void WreckedShipSpark_Func_4(uint16 k) { // 0xA8E6F6 - int16 wssk_var_E; - - Enemy_WreckedShipSpark *E = Get_WreckedShipSpark(k); - wssk_var_E = E->wssk_var_E; - if (wssk_var_E < 0) - wssk_var_E = (NextRandom() & 0x3F) + 4; - E->wssk_var_F = R18_ + wssk_var_E; -} void WreckedShipSpark_Shot(void) { // 0xA8E70E - projectile_dir[collision_detection_index] &= ~0x10u; + projectile_dir[collision_detection_index] &= ~0x10; } void BlueBrinstarFaceBlock_Init(void) { // 0xA8E82E - VoidP v1; - EnemyData *v0 = gEnemyData(cur_enemy_index); v0->current_instruction = addr_kBlueBrinstarFaceBlock_Ilist_E828; - v1 = FUNC16(BlueBrinstarFaceBlock_Func_1); + uint16 v1 = FUNC16(BlueBrinstarFaceBlock_Func_1); if ((collected_items & 4) == 0) v1 = FUNC16(nullsub_170_A8); enemy_gfx_drawn_hook.addr = v1; *(uint16 *)&enemy_gfx_drawn_hook.bank = 168; - variables_for_enemy_graphics_drawn_hook[0] = (uint8)((uint16)((16 * v0->palette_index) & 0xFF00) >> 8); + variables_for_enemy_graphics_drawn_hook[0] = ((16 * v0->palette_index) & 0xFF00) >> 8; variables_for_enemy_graphics_drawn_hook[2] = 16; - v0->parameter_2 = ((uint8)(v0->parameter_2 & 1) >> 2) | ((v0->parameter_2 & 1) << 15); + v0->parameter_2 = ((v0->parameter_2 & 1) >> 2) | ((v0->parameter_2 & 1) << 15); } void BlueBrinstarFaceBlock_Func_1(void) { // 0xA8E86E @@ -3933,13 +3728,12 @@ void BlueBrinstarFaceBlock_Func_1(void) { // 0xA8E86E variables_for_enemy_graphics_drawn_hook[2] = 16; uint16 v0 = variables_for_enemy_graphics_drawn_hook[0]; uint16 v1 = 8 * variables_for_enemy_graphics_drawn_hook[1]; - remaining_enemy_spritemap_entries = 4; + int n = 4; do { palette_buffer[(v0 >> 1) + 137] = g_word_A8E7CC[v1 >> 1]; v1 += 2; v0 += 2; - --remaining_enemy_spritemap_entries; - } while (remaining_enemy_spritemap_entries); + } while (--n); variables_for_enemy_graphics_drawn_hook[1] = (LOBYTE(variables_for_enemy_graphics_drawn_hook[1]) + 1) & 7; } } @@ -3948,7 +3742,7 @@ void BlueBrinstarFaceBlock_Main(void) { // 0xA8E8AE if ((collected_items & 4) != 0) { enemy_gfx_drawn_hook.addr = FUNC16(BlueBrinstarFaceBlock_Func_1); EnemyData *v1 = gEnemyData(cur_enemy_index); - variables_for_enemy_graphics_drawn_hook[0] = (uint8)((uint16)((16 * v1->palette_index) & 0xFF00) >> 8); + variables_for_enemy_graphics_drawn_hook[0] = ((16 * v1->palette_index) & 0xFF00) >> 8; if (!v1->ai_var_A) { uint16 SamusEnemyDelta_Y = GetSamusEnemyDelta_Y(cur_enemy_index); if ((int16)(Abs16(SamusEnemyDelta_Y) - v1->parameter_1) < 0) { @@ -3956,7 +3750,7 @@ void BlueBrinstarFaceBlock_Main(void) { // 0xA8E8AE v1->ai_var_B = SamusEnemyDelta_X; if ((int16)(Abs16(SamusEnemyDelta_X) - v1->parameter_1) < 0 && (v1->ai_var_B & 0x8000) != v1->parameter_2) { uint16 v4 = addr_kBlueBrinstarFaceBlock_Ilist_E80C; - if ((v1->ai_var_B & 0x8000u) == 0) + if ((v1->ai_var_B & 0x8000) == 0) v4 = addr_kBlueBrinstarFaceBlock_Ilist_E81A; v1->current_instruction = v4; v1->instruction_timer = 1; @@ -3969,7 +3763,7 @@ void BlueBrinstarFaceBlock_Main(void) { // 0xA8E8AE } void BlueBrinstarFaceBlock_Shot(void) { // 0xA8E91D - projectile_dir[collision_detection_index] &= ~0x10u; + projectile_dir[collision_detection_index] &= ~0x10; } void KiHunter_Init(void) { // 0xA8F188 @@ -3990,7 +3784,7 @@ void KiHunter_Init(void) { // 0xA8F188 E->khr_var_0B = v1 + 32; E->khr_var_0C = E->base.x_pos; E->khr_var_0D = E->base.y_pos; - if ((E->khr_parameter_1 & 0x8000u) != 0) { + if ((E->khr_parameter_1 & 0x8000) != 0) { E->khr_var_14 = 1; E->khr_var_A = FUNC16(KiHunter_Func_4); E->khr_var_08 = 0; @@ -4010,7 +3804,7 @@ void KiHunterWings_Init(void) { // 0xA8F214 E->khr_var_A = FUNC16(KiHunter_Func_9); E->base.palette_index = enemy_drawing_queue[v2 + 105]; E->base.vram_tiles_index = enemy_drawing_queue[v2 + 106]; - if ((enemy_drawing_queue_sizes[v2 + 6] & 0x8000u) != 0) + if ((enemy_drawing_queue_sizes[v2 + 6] & 0x8000) != 0) E->base.properties |= kEnemyProps_Deleted; } @@ -4045,9 +3839,7 @@ void KiHunter_Func_1(uint16 k) { // 0xA8F268 int16 v4; Enemy_KiHunter *E = Get_KiHunter(k); - R18_ = E->khr_var_08; - R20_ = E->khr_var_09; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, __PAIR32__(E->khr_var_09, E->khr_var_08))) { v4 = -E->khr_var_09; } else { uint16 y_pos = E->base.y_pos; @@ -4061,11 +3853,9 @@ void KiHunter_Func_1(uint16 k) { // 0xA8F268 } E->khr_var_09 = v4; LABEL_8: - R18_ = E->khr_var_06; - R20_ = E->khr_var_07; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->khr_var_07, E->khr_var_06))) { uint16 v5 = 0; - bool v6 = (-E->khr_var_07 & 0x8000u) != 0; + bool v6 = (-E->khr_var_07 & 0x8000) != 0; E->khr_var_07 = -E->khr_var_07; if (!v6) v5 = 4; @@ -4077,12 +3867,12 @@ LABEL_8: E1->base.instruction_timer = 1; } EnemyFunc_C8AD(k); - R18_ = samus_x_pos - E->base.x_pos; - R20_ = abs16(R18_); - if ((int16)(R20_ - g_word_A8F180) < 0 && !sign16(samus_y_pos - E->base.y_pos - 32)) { - R24_ = samus_y_pos - E->base.y_pos; + uint16 r18 = samus_x_pos - E->base.x_pos; + uint16 r20 = abs16(r18); + if ((int16)(r20 - g_word_A8F180) < 0 && !sign16(samus_y_pos - E->base.y_pos - 32)) { + uint16 r24 = samus_y_pos - E->base.y_pos; uint16 v9; - if ((R18_ & 0x8000u) != 0) { + if ((r18 & 0x8000) != 0) { E->khr_var_00 = -2; E->khr_var_02 = 0; E->khr_var_03 = 0; @@ -4109,18 +3899,18 @@ LABEL_8: E1->base.current_instruction = g_off_A8F3B0[v10 + 1]; E->base.instruction_timer = 1; E1->base.instruction_timer = 1; - E->khr_var_B = R18_ + E->base.x_pos; + E->khr_var_B = r18 + E->base.x_pos; E->khr_var_C = E->base.y_pos; E->khr_var_A = FUNC16(KiHunter_Func_2); - E->khr_var_12 = R24_; - E->khr_var_11 = R20_; + E->khr_var_12 = r24; + E->khr_var_11 = r20; E->khr_var_10 = 0; } } void KiHunter_Func_2(uint16 k) { // 0xA8F3B8 Enemy_KiHunter *E = Get_KiHunter(k); - if ((E->khr_var_04 & 0x8000u) == 0) { + if ((E->khr_var_04 & 0x8000) == 0) { if ((int16)(E->khr_var_F - E->khr_var_0E) < 0) goto LABEL_9; } else if ((int16)(E->khr_var_F - E->khr_var_0E) >= 0) { @@ -4129,13 +3919,13 @@ void KiHunter_Func_2(uint16 k) { // 0xA8F3B8 if (!E->khr_var_10) { E->khr_var_10 = 1; uint16 v2 = addr_kKiHunter_Ilist_EA32; - if ((E->khr_var_04 & 0x8000u) != 0) + if ((E->khr_var_04 & 0x8000) != 0) v2 = addr_kKiHunter_Ilist_EA08; E->base.current_instruction = v2; E->base.instruction_timer = 1; } LABEL_9: - if ((E->khr_var_04 & 0x8000u) == 0) { + if ((E->khr_var_04 & 0x8000) == 0) { uint16 khr_var_03 = E->khr_var_03; bool v4 = __CFADD__uint16(E->khr_var_05, khr_var_03); E->khr_var_03 = E->khr_var_05 + khr_var_03; @@ -4164,11 +3954,9 @@ LABEL_9: return; } } - draw_enemy_layer = E->khr_var_11; - R20_ = E->khr_var_B + CosineMult8bit(E->khr_var_F) - E->base.x_pos; - R18_ = 0; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { - if ((E->khr_var_04 & 0x8000u) == 0) { + uint16 r20 = E->khr_var_B + CosineMult8bit(E->khr_var_F, E->khr_var_11) - E->base.x_pos; + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL16(r20))) { + if ((E->khr_var_04 & 0x8000) == 0) { E->khr_var_06 = 0; E->khr_var_07 = -1; } else { @@ -4178,10 +3966,8 @@ LABEL_9: goto LABEL_24; } EnemyFunc_C8AD(k); - draw_enemy_layer = E->khr_var_12; - R20_ = E->khr_var_C + SineMult8bitNegative(E->khr_var_F) - E->base.y_pos; - R18_ = 0; - if (Enemy_MoveDown(k) & 1) { + r20 = E->khr_var_C + SineMult8bit(E->khr_var_F, E->khr_var_12) - E->base.y_pos; + if (Enemy_MoveDown(k, INT16_SHL16(r20))) { LABEL_24: E->khr_var_A = FUNC16(KiHunter_Func_3); E->khr_var_08 = 0; @@ -4191,10 +3977,8 @@ LABEL_24: void KiHunter_Func_3(uint16 k) { // 0xA8F4ED Enemy_KiHunter *E = Get_KiHunter(k); - R18_ = E->khr_var_06; - R20_ = E->khr_var_07; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1 - || (EnemyFunc_C8AD(k), R18_ = E->khr_var_08, R20_ = E->khr_var_09, Enemy_MoveDown(k) & 1) + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->khr_var_07, E->khr_var_06)) + || (EnemyFunc_C8AD(k), Enemy_MoveDown(k, __PAIR32__(E->khr_var_09, E->khr_var_08))) || (int16)(E->base.y_pos - E->khr_var_0D) < 0) { E->khr_var_A = FUNC16(KiHunter_Func_1); } @@ -4202,17 +3986,17 @@ void KiHunter_Func_3(uint16 k) { // 0xA8F4ED const uint16 *KiHunter_Instr_1(uint16 k, const uint16 *jp) { // 0xA8F526 uint16 result = addr_kKiHunter_Ilist_E9FA; - R18_ = addr_kKiHunter_Ilist_EA4E; + uint16 r18 = addr_kKiHunter_Ilist_EA4E; Enemy_KiHunter *E = Get_KiHunter(k); - if ((E->khr_var_07 & 0x8000u) == 0) { + if ((E->khr_var_07 & 0x8000) == 0) { result = addr_kKiHunter_Ilist_EA24; - R18_ = addr_kKiHunter_Ilist_EA5E; + r18 = addr_kKiHunter_Ilist_EA5E; } - E->base.current_instruction = R18_; + E->base.current_instruction = r18; E->base.instruction_timer = 1; Enemy_KiHunter *E1 = Get_KiHunter(k + 64); if (E1->khr_var_A == FUNC16(KiHunter_Func_9)) { - E1->base.current_instruction = R18_; + E1->base.current_instruction = r18; E1->base.instruction_timer = 1; } return INSTR_RETURN_ADDR(result); @@ -4220,9 +4004,7 @@ const uint16 *KiHunter_Instr_1(uint16 k, const uint16 *jp) { // 0xA8F526 void KiHunter_Func_4(uint16 k) { // 0xA8F55A Enemy_KiHunter *E = Get_KiHunter(k); - R18_ = E->khr_var_08; - R20_ = E->khr_var_09; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, __PAIR32__(E->khr_var_09, E->khr_var_08))) { E->khr_var_A = FUNC16(KiHunter_Func_5); } else { uint16 khr_var_08 = E->khr_var_08; @@ -4256,10 +4038,8 @@ const uint16 *KiHunter_Instr_2(uint16 k, const uint16 *jp) { // 0xA8F5E4 void KiHunter_Func_6(uint16 k) { // 0xA8F5F0 Enemy_KiHunter *E = Get_KiHunter(k); - R18_ = E->khr_var_08; - R20_ = E->khr_var_09; - if (Enemy_MoveDown(k) & 1) { - if ((E->khr_var_09 & 0x8000u) != 0) { + if (Enemy_MoveDown(k, __PAIR32__(E->khr_var_09, E->khr_var_08))) { + if ((E->khr_var_09 & 0x8000) != 0) { E->khr_var_09 = 1; } else { E->khr_var_08 = 0; @@ -4273,9 +4053,7 @@ void KiHunter_Func_6(uint16 k) { // 0xA8F5F0 E->base.instruction_timer = 1; } } else { - R18_ = E->khr_var_06; - R20_ = E->khr_var_07; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->khr_var_07, E->khr_var_06))) { E->khr_var_07 = -E->khr_var_07; } else { EnemyFunc_C8AD(k); @@ -4326,7 +4104,7 @@ const uint16 *KiHunter_Instr_5(uint16 k, const uint16 *jp) { // 0xA8F6D8 } void sub_A8F6DC(uint16 k, uint16 j) { // 0xA8F6DC - QueueSfx2_Max6(0x4Cu); + QueueSfx2_Max6(0x4C); SpawnEnemyProjectileWithGfx(0, cur_enemy_index, j); Get_KiHunter(cur_enemy_index)->khr_var_0F = 24; } @@ -4391,21 +4169,17 @@ void CallKiHunterBFunc(uint32 ea) { } } void KiHunter_Func_10(uint16 k) { // 0xA8F7CF - R18_ = Get_KiHunter(cur_enemy_index)->khr_var_00; - CallKiHunterBFunc(R18_ | 0xA80000); + uint16 r18 = Get_KiHunter(cur_enemy_index)->khr_var_00; + CallKiHunterBFunc(r18 | 0xA80000); } void KiHunter_Func_11(void) { // 0xA8F7DB int16 v2; Enemy_KiHunter *E = Get_KiHunter(cur_enemy_index); - E->khr_var_F += *(uint16 *)((uint8 *)&kCommonEnemySpeeds_Quadratic[2] - + (uint16)(8 * HIBYTE(E->khr_var_B)) - + 1); - draw_enemy_layer = g_byte_A8F186; - E->base.y_pos = E->khr_var_06 + SineMult8bitNegative(HIBYTE(E->khr_var_F)) - E->khr_var_04; - draw_enemy_layer = g_byte_A8F186; - E->base.x_pos = E->khr_var_05 + CosineMult8bit(HIBYTE(E->khr_var_F)) - E->khr_var_03; + E->khr_var_F += *(uint16 *)((uint8 *)&kCommonEnemySpeeds_Quadratic[2] + (8 * HIBYTE(E->khr_var_B)) + 1); + E->base.y_pos = E->khr_var_06 + SineMult8bit(HIBYTE(E->khr_var_F), g_byte_A8F186) - E->khr_var_04; + E->base.x_pos = E->khr_var_05 + CosineMult8bit(HIBYTE(E->khr_var_F), g_byte_A8F186) - E->khr_var_03; if (sign16(E->khr_var_F + 0x4000)) { KiHunter_Func_16(cur_enemy_index); } else { @@ -4417,44 +4191,32 @@ void KiHunter_Func_11(void) { // 0xA8F7DB } void KiHunter_Func_12(void) { // 0xA8F851 - draw_enemy_layer = g_byte_A8F186; - uint16 v1 = CosineMult8bit(0xE0u); + uint16 v1 = CosineMult8bit(0xE0, g_byte_A8F186); Enemy_KiHunter *E = Get_KiHunter(cur_enemy_index); E->khr_var_03 = v1; - draw_enemy_layer = g_byte_A8F186; - E->khr_var_04 = SineMult8bitNegative(0xE0u); + E->khr_var_04 = SineMult8bit(0xE0, g_byte_A8F186); } void KiHunter_Func_13(void) { // 0xA8F87F - draw_enemy_layer = g_byte_A8F186; - uint16 v1 = CosineMult8bit(0xA0u); + uint16 v1 = CosineMult8bit(0xA0, g_byte_A8F186); Enemy_KiHunter *E = Get_KiHunter(cur_enemy_index); E->khr_var_01 = v1; - draw_enemy_layer = g_byte_A8F186; - E->khr_var_02 = SineMult8bitNegative(0xA0u); + E->khr_var_02 = SineMult8bit(0xA0, g_byte_A8F186); } void KiHunter_Func_14(void) { // 0xA8F8AD int16 khr_var_07; Enemy_KiHunter *E = Get_KiHunter(cur_enemy_index); - E->khr_var_F += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic - + (uint16)(8 * HIBYTE(E->khr_var_B)) - + 1); - draw_enemy_layer = g_byte_A8F186; - R20_ = E->khr_var_06 - + SineMult8bitNegative(HIBYTE(E->khr_var_F)) - - E->khr_var_02 - - E->base.y_pos; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index) & 1) { + E->khr_var_F += *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (8 * HIBYTE(E->khr_var_B)) + 1); + uint16 r20 = E->khr_var_06 + SineMult8bit(HIBYTE(E->khr_var_F), g_byte_A8F186) - E->khr_var_02 - E->base.y_pos; + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(r20))) { E->base.properties |= kEnemyProps_Deleted; E->base.x_pos = E->khr_var_08; khr_var_07 = E->khr_var_07; E->base.y_pos = khr_var_07; } else { - draw_enemy_layer = g_byte_A8F186; - E->base.x_pos = E->khr_var_05 + CosineMult8bit(HIBYTE(E->khr_var_F)) - E->khr_var_01; + E->base.x_pos = E->khr_var_05 + CosineMult8bit(HIBYTE(E->khr_var_F), g_byte_A8F186) - E->khr_var_01; if (!sign16(E->khr_var_F + 0x4000)) { KiHunter_Func_15(cur_enemy_index); return; @@ -4494,7 +4256,7 @@ void KiHunter_Func_17(void) { // 0xA8F98D uint16 v3 = E->khr_var_0A + 384; E->khr_var_0A = v3; v3 >>= 8; - v5 = *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (uint16)(8 * v3) + 1) + E->khr_var_D; + v5 = *(uint16 *)((uint8 *)kCommonEnemySpeeds_Quadratic + (8 * v3) + 1) + E->khr_var_D; E->khr_var_D = v5; } while (sign16(v5 - 0x2000)); -} \ No newline at end of file +} diff --git a/src/sm_a9.c b/src/sm_a9.c index bb97caf..dbf5d32 100644 --- a/src/sm_a9.c +++ b/src/sm_a9.c @@ -285,13 +285,13 @@ void MotherBrainsBody_Init(void) { // 0xA98687 E->mbn_var_04 = 2; E1->mbn_var_A = FUNC16(MotherBrainsBrain_SetupBrainToDraw); E->mbn_var_A = FUNC16(MotherBrainsBody_FirstPhase_DoubleRet); - LoadFxEntry(1u); + LoadFxEntry(1); uint16 v3 = 0, v4; do { v4 = v3; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainRoomTurrets, v3); v3 = v4 + 1; - } while ((uint16)(v4 + 1) < 0xCu); + } while ((uint16)(v4 + 1) < 0xC); } void MotherBrainsBrain_Init(void) { // 0xA98705 @@ -300,7 +300,7 @@ void MotherBrainsBrain_Init(void) { // 0xA98705 E1->base.health = 3000; MotherBrain_SetBrainUnusedInstrs(addr_kMotherBrain_Ilist_9C13); E1->base.vram_tiles_index = 0; - E1->base.properties |= 0x1100u; + E1->base.properties |= 0x1100; E1->base.palette_index = 512; Enemy_MotherBrain *E = Get_MotherBrain(0); E->mbn_var_0C = 512; @@ -372,7 +372,7 @@ void MotherBrainsBrain_GfxDrawHook(void) { // 0xA987DD } void MotherBrainsBody_FirstPhase_DoubleRet(void) { // 0xA987E1 - if (CheckEventHappened(2u)) { + if (CheckEventHappened(2)) { Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); E1->mbn_var_00 = earthquake_timer; if (sign16(samus_x_pos - 236)) { @@ -381,7 +381,7 @@ void MotherBrainsBody_FirstPhase_DoubleRet(void) { // 0xA987E1 E->mbn_var_1D = 1; E->mbn_var_00 = 1; DisableMinimapAndMarkBossRoomAsExplored(); - QueueMusic_Delayed8(6u); + QueueMusic_Delayed8(6); MotherBrain_SealWall(); } } @@ -411,7 +411,7 @@ void MotherBrainBody_FakeDeath_Descent_2(void) { // 0xA9884D Enemy_MotherBrainBody *E = Get_MotherBrainBody(0); if ((--E->mbby_var_F & 0x8000) != 0) { QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF21u); + QueueMusic_Delayed8(0xFF21); E->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Descent_3); E->mbby_var_F = 12; MotherBrainBody_FakeDeath_Descent_3(); @@ -421,7 +421,7 @@ void MotherBrainBody_FakeDeath_Descent_2(void) { // 0xA9884D void MotherBrainBody_FakeDeath_Descent_3(void) { // 0xA9886C Enemy_MotherBrainBody *E = Get_MotherBrainBody(0); if ((--E->mbby_var_F & 0x8000) != 0) { - CallSomeSamusCode(1u); + CallSomeSamusCode(1); E->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Descent_4); E->mbby_var_F = 8; MotherBrainBody_FakeDeath_Descent_4(); @@ -432,13 +432,12 @@ void MotherBrainBody_FakeDeath_Descent_4(void) { // 0xA98884 Enemy_MotherBrain *E = Get_MotherBrain(0); if ((--E->mbn_var_F & 0x8000) != 0) { MotherBrain_Pal_BeginScreenFlash(); - LoadFxEntry(2u); + LoadFxEntry(2); Get_MotherBrain(0x40)->mbn_var_E = FUNC16(MotherBrainBody_0_Wait); E->mbn_var_A = FUNC16(MotherBrainBody_FakeDeath_Descent_5); E->mbn_var_F = 0; E->mbn_var_37 = 0; - static const SpawnHardcodedPlmArgs unk_A988AD = { 0x0e, 0x02, 0xb6b3 }; - SpawnHardcodedPlm(&unk_A988AD); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0e, 0x02, 0xb6b3 }); } } @@ -473,13 +472,10 @@ void MotherBrain_HandleFakeDeathExplosions(void) { // 0xA988DD v2 = 7; E->mbn_var_39 = v2; int v3 = (uint16)(4 * v2) >> 1; - R18_ = g_word_A98929[v3]; - R20_ = g_word_A98929[v3 + 1]; - uint16 v4 = 3; - if (random_number < 0x4000) - v4 = 12; + eproj_spawn_pt = (Point16U){ g_word_A98929[v3], g_word_A98929[v3 + 1] }; + uint16 v4 = (random_number < 0x4000) ? 12 : 3; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, v4); - QueueSfx2_Max3(0x24u); + QueueSfx2_Max3(0x24); } else { E->mbn_var_38 = v1; } @@ -501,18 +497,8 @@ void MotherBrainBody_0_Wait(void) { // 0xA98949 } } -static const SpawnHardcodedPlmArgs unk_A98972 = { 0x05, 0x09, 0xb6c3 }; -static const SpawnHardcodedPlmArgs unk_A989D6 = { 0x06, 0x02, 0xb6b3 }; -static const SpawnHardcodedPlmArgs unk_A989FE = { 0x0a, 0x09, 0xb6c7 }; -static const SpawnHardcodedPlmArgs unk_A98A26 = { 0x06, 0x0a, 0xb6bb }; -static const SpawnHardcodedPlmArgs unk_A98A58 = { 0x07, 0x02, 0xb6b7 }; -static const SpawnHardcodedPlmArgs unk_A98A8A = { 0x08, 0x02, 0xb6b7 }; -static const SpawnHardcodedPlmArgs unk_A989A4 = { 0x09, 0x02, 0xb6b3 }; -static const SpawnHardcodedPlmArgs unk_A98AB2 = { 0x09, 0x0a, 0xb6bb }; -static const SpawnHardcodedPlmArgs unk_A98ADA = { 0x07, 0x07, 0xb6bf }; - void MotherBrainBody_1_ClearBottomLeftTube(void) { // 0xA9896E - SpawnHardcodedPlm(&unk_A98972); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x05, 0x09, 0xb6c3 }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_2_SpawnTopRightTubeFalling); E->mbby_var_F = 32; @@ -521,15 +507,14 @@ void MotherBrainBody_1_ClearBottomLeftTube(void) { // 0xA9896E void MotherBrainBody_2_SpawnTopRightTubeFalling(void) { // 0xA98983 Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); if ((--E->mbby_var_F & 0x8000) != 0) { - R18_ = 152; - R20_ = 47; + eproj_spawn_pt = (Point16U){ 152, 47 }; SpawnEnemyProjectileWithRoomGfx(0xCC5B, 0x2F); E->mbby_var_E = -30304; } } void MotherBrainBody_3_ClearCeilingBlock9(void) { // 0xA989A0 - SpawnHardcodedPlm(&unk_A989A4); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x09, 0x02, 0xb6b3 }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_4_SpawnTopLeftTubeFalling); E->mbby_var_F = 32; @@ -538,15 +523,14 @@ void MotherBrainBody_3_ClearCeilingBlock9(void) { // 0xA989A0 void MotherBrainBody_4_SpawnTopLeftTubeFalling(void) { // 0xA989B5 Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); if ((--E->mbby_var_F & 0x8000) != 0) { - R18_ = 104; - R20_ = 47; + eproj_spawn_pt = (Point16U){ 104, 47 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainTubeFalling_TopLeft, 0x2F); E->mbby_var_E = FUNC16(MotherBrainBody_4_ClearCeilingBlock6); } } void MotherBrainBody_4_ClearCeilingBlock6(void) { // 0xA989D2 - SpawnHardcodedPlm(&unk_A989D6); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x06, 0x02, 0xb6b3 }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_5_SpawnTubeFallingEnemy1); E->mbby_var_F = 32; @@ -561,7 +545,7 @@ void MotherBrainBody_5_SpawnTubeFallingEnemy1(void) { // 0xA989E7 } void MotherBrainBody_6_ClearBottomRightTube(void) { // 0xA989FA - SpawnHardcodedPlm(&unk_A989FE); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0a, 0x09, 0xb6c7 }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_7_SpawnTubeFallingEnemy2); E->mbby_var_F = 32; @@ -576,7 +560,7 @@ void MotherBrainBody_7_SpawnTubeFallingEnemy2(void) { // 0xA98A0F } void MotherBrainBody_8_ClearBottomMiddleLeftTube(void) { // 0xA98A22 - SpawnHardcodedPlm(&unk_A98A26); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x06, 0x0a, 0xb6bb }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_9_SpawnTopMiddleLeftFalling); E->mbby_var_F = 32; @@ -585,15 +569,14 @@ void MotherBrainBody_8_ClearBottomMiddleLeftTube(void) { // 0xA98A22 void MotherBrainBody_9_SpawnTopMiddleLeftFalling(void) { // 0xA98A37 Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); if ((--E->mbby_var_F & 0x8000) != 0) { - R18_ = 120; - R20_ = 59; + eproj_spawn_pt = (Point16U){ 120, 59 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainTubeFalling_TopMiddleLeft, 0x3B); E->mbby_var_E = FUNC16(MotherBrainBody_10_ClearCeilingTubeColumn7); } } void MotherBrainBody_10_ClearCeilingTubeColumn7(void) { // 0xA98A54 - SpawnHardcodedPlm(&unk_A98A58); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x07, 0x02, 0xb6b7 }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_11_SpawnTopMiddleRightFalling); E->mbby_var_F = 32; @@ -602,15 +585,14 @@ void MotherBrainBody_10_ClearCeilingTubeColumn7(void) { // 0xA98A54 void MotherBrainBody_11_SpawnTopMiddleRightFalling(void) { // 0xA98A69 Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); if ((--E->mbby_var_F & 0x8000) != 0) { - R18_ = 136; - R20_ = 59; + eproj_spawn_pt = (Point16U){ 136, 59 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainTubeFalling_TopMiddleRight, 0x3B); E->mbby_var_E = FUNC16(MotherBrainBody_12_ClearCeilingTubeColumn8); } } void MotherBrainBody_12_ClearCeilingTubeColumn8(void) { // 0xA98A86 - SpawnHardcodedPlm(&unk_A98A8A); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x08, 0x02, 0xb6b7 }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_13_SpawnTubeFallingEnemy3); E->mbby_var_F = 32; @@ -625,7 +607,7 @@ void MotherBrainBody_13_SpawnTubeFallingEnemy3(void) { // 0xA98A9B } void MotherBrainBody_14_ClearBottomMiddleRightTube(void) { // 0xA98AAE - SpawnHardcodedPlm(&unk_A98AB2); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x09, 0x0a, 0xb6bb }); Enemy_MotherBrainBody *E = Get_MotherBrainBody(0x40); E->mbby_var_E = FUNC16(MotherBrainBody_15_SpawnTubeFallingEnemy4); E->mbby_var_F = 2; @@ -640,7 +622,7 @@ void MotherBrainBody_15_SpawnTubeFallingEnemy4(void) { // 0xA98AC3 } void MotherBrainBody_16_ClearBottomMiddleTubes(void) { // 0xA98AD6 - SpawnHardcodedPlm(&unk_A98ADA); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x07, 0x07, 0xb6bf }); Get_MotherBrainBody(0x40)->mbby_var_E = addr_locret_A98AE4; } @@ -690,10 +672,9 @@ void MotherBrainsTubesFalling_HandleSmoke(uint16 k) { // 0xA98B9D void MotherBrainsTubesFalling_Explode(uint16 k) { // 0xA98BA6 Enemy_MotherBrainsTubesFalling *E = Get_MotherBrainsTubesFalling(k); E->base.properties |= kEnemyProps_Deleted; - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3u); - QueueSfx2_Max3(0x24u); + eproj_spawn_pt = (Point16U){ E->base.x_pos, E->base.y_pos }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3); + QueueSfx2_Max3(0x24); } void MotherBrainsTubesFalling_WaitToFall(uint16 k) { // 0xA98BCB @@ -718,7 +699,7 @@ void MotherBrainsTubesFalling_Falling(uint16 k) { // 0xA98BD6 MotherBrainsTubesFalling_HandleSmoke(k); } else { MotherBrain_Pal_EndScreenFlash(); - EnableEarthquakeAframes(0x19u); + EnableEarthquakeAframes(0x19); hdma_object_channels_bitmask[0] = 0; hdma_object_channels_bitmask[1] = 0; // BUG! @@ -736,65 +717,51 @@ void MotherBrainsTubesFalling_Falling(uint16 k) { // 0xA98BD6 void MotherBrainsTubesFalling_SpawnSmoke(uint16 k) { // 0xA98C36 Enemy_MotherBrainsTubesFalling *E = Get_MotherBrainsTubesFalling(k); E->mbtfg_var_D = 8; - uint16 v2 = ((uint8)E->mbtfg_var_E + 1) & 3; + uint16 v2 = (E->mbtfg_var_E + 1) & 3; E->mbtfg_var_E = v2; - R18_ = E->base.x_pos + g_word_A98C61[v2]; - R20_ = 208; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); + eproj_spawn_pt = (Point16U){ E->base.x_pos + g_word_A98C61[v2], 208 }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); } -static const SpawnHardcodedPlmArgs unk_A98C8B = { 0x02, 0x02, 0xb67b }; -static const SpawnHardcodedPlmArgs unk_A98C93 = { 0x02, 0x03, 0xb67f }; -static const SpawnHardcodedPlmArgs unk_A98CA2 = { 0x02, 0x04, 0xb683 }; -static const SpawnHardcodedPlmArgs unk_A98CAA = { 0x02, 0x05, 0xb687 }; -static const SpawnHardcodedPlmArgs unk_A98CB9 = { 0x02, 0x06, 0xb68b }; -static const SpawnHardcodedPlmArgs unk_A98CC1 = { 0x02, 0x07, 0xb68f }; -static const SpawnHardcodedPlmArgs unk_A98CD0 = { 0x02, 0x08, 0xb693 }; -static const SpawnHardcodedPlmArgs unk_A98CD8 = { 0x02, 0x09, 0xb697 }; -static const SpawnHardcodedPlmArgs unk_A98CE7 = { 0x02, 0x0a, 0xb69b }; -static const SpawnHardcodedPlmArgs unk_A98CEF = { 0x02, 0x0b, 0xb69f }; -static const SpawnHardcodedPlmArgs unk_A98CFE = { 0x02, 0x0c, 0xb6a3 }; -static const SpawnHardcodedPlmArgs unk_A98D06 = { 0x02, 0x0d, 0xb6a7 }; - void MotherBrainBody_FakeDeath_Ascent_0_DrawBG1Row23(void) { // 0xA98C87 - SpawnHardcodedPlm(&unk_A98C8B); - SpawnHardcodedPlm(&unk_A98C93); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x02, 0xb67b }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x03, 0xb67f }); Get_MotherBrainBody(0)->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_1_DrawBG1Row45); } void MotherBrainBody_FakeDeath_Ascent_1_DrawBG1Row45(void) { // 0xA98C9E - SpawnHardcodedPlm(&unk_A98CA2); - SpawnHardcodedPlm(&unk_A98CAA); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x04, 0xb683 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x05, 0xb687 }); Get_MotherBrainBody(0)->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_2_DrawBG1Row67); } void MotherBrainBody_FakeDeath_Ascent_2_DrawBG1Row67(void) { // 0xA98CB5 - SpawnHardcodedPlm(&unk_A98CB9); - SpawnHardcodedPlm(&unk_A98CC1); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x06, 0xb68b }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x07, 0xb68f }); Get_MotherBrainBody(0)->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_3_DrawBG1Row89); } void MotherBrainBody_FakeDeath_Ascent_3_DrawBG1Row89(void) { // 0xA98CCC - SpawnHardcodedPlm(&unk_A98CD0); - SpawnHardcodedPlm(&unk_A98CD8); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x08, 0xb693 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x09, 0xb697 }); Get_MotherBrainBody(0)->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_4_DrawBG1RowAB); } void MotherBrainBody_FakeDeath_Ascent_4_DrawBG1RowAB(void) { // 0xA98CE3 - SpawnHardcodedPlm(&unk_A98CE7); - SpawnHardcodedPlm(&unk_A98CEF); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x0a, 0xb69b }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x0b, 0xb69f }); Get_MotherBrainBody(0)->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_5_DrawBG1RowCD); } void MotherBrainBody_FakeDeath_Ascent_5_DrawBG1RowCD(void) { // 0xA98CFA - SpawnHardcodedPlm(&unk_A98CFE); - SpawnHardcodedPlm(&unk_A98D06); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x0c, 0xb6a3 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x02, 0x0d, 0xb6a7 }); Get_MotherBrainBody(0)->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_6_SetupPhase2Gfx); } void MotherBrainBody_FakeDeath_Ascent_6_SetupPhase2Gfx(void) { // 0xA98D11 *(uint16 *)&layer2_scroll_x = 257; - *(uint16 *)®_BG2SC &= 0xFFFCu; + *(uint16 *)®_BG2SC &= 0xFFFC; WriteColorsToPalette(0x142, 0xa9, addr_kMotherBrainPalette_1 + 2, 0xF); WriteColorsToPalette(0x162, 0xa9, addr_kMotherBrainPalette_0 + 2, 0xF); Get_MotherBrain(0)->mbn_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_7_SetupPhase2Brain); @@ -808,7 +775,7 @@ void MotherBrainBody_FakeDeath_Ascent_7_SetupPhase2Brain(void) { // 0xA98D49 E->mbby_var_A = FUNC16(MotherBrainsBrain_SetupBrainAndNeckToDraw); Enemy_MotherBrainBody *E0 = Get_MotherBrainBody(0); E0->base.properties &= ~kEnemyProps_Tangible; - E->base.properties &= ~0x400u; + E->base.properties &= ~0x400; E->base.health = 18000; E0->mbby_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_8_Pause); E0->mbby_var_F = 128; @@ -829,7 +796,7 @@ void MotherBrainBody_FakeDeath_Ascent_9_PrepareRise(void) { // 0xA98D8B if ((--E->mbn_var_F & 0x8000) != 0) { E->mbn_var_09 = MotherBrainRisingHdmaObject(); Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); - E1->base.properties |= 0x100u; + E1->base.properties |= 0x100; MotherBrain_SetBrainInstrs(addr_stru_A99C21); E->mbn_var_A = FUNC16(MotherBrainBody_FakeDeath_Ascent_10_LoadLegTiles); E->mbn_var_F = 256; @@ -866,7 +833,7 @@ void MotherBrainBody_FakeDeath_Ascent_12_StartMusic(void) { // 0xA98DEC E0->base.y_pos = 279; reg_BG2HOFS = -27; reg_BG2VOFS = -217; - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); earthquake_type = 2; earthquake_timer = 256; E1->mbn_var_34 = 80; @@ -881,11 +848,10 @@ void MotherBrainBody_FakeDeath_Ascent_13_Raise(void) { // 0xA98E4D uint16 v1; if ((nmi_frame_counter_word & 3) != 0 || (MotherBrain_SpawnDustCloudsForAscent(), - R18_ = 2, reg_BG2VOFS += 2, v1 = E->base.y_pos - 2, E->base.y_pos = v1, - v1 >= 0xBDu)) { + v1 >= 0xBD)) { } else { enemy_bg2_tilemap_size = 320; E->base.y_pos = 188; @@ -961,12 +927,9 @@ void MotherBrain_SpawnDustCloudsForAscent(void) { // 0xA98F46 Enemy_MotherBrain *E = Get_MotherBrain(0x40); if ((--E->mbn_var_F & 0x8000) != 0) E->mbn_var_F = 7; - R18_ = g_word_A98F7F[E->mbn_var_F]; - R20_ = 212; - SpawnEnemyProjectileWithRoomGfx( - addr_kEproj_DustCloudExplosion, - g_byte_A98F7D[(uint16)(random_number & 0x100) >> 8]); - QueueSfx2_Max3(0x29u); + eproj_spawn_pt = (Point16U){ g_word_A98F7F[E->mbn_var_F], 212 }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, g_byte_A98F7D[(uint16)(random_number & 0x100) >> 8]); + QueueSfx2_Max3(0x29); } void MotherBrain_SetupNeckForFakeAscent(void) { // 0xA9903F @@ -985,16 +948,16 @@ void MotherBrain_HandleNeckLower(void) { // 0xA99072 uint16 mbn_var_32 = Get_MotherBrain(0x40)->mbn_var_32; if (mbn_var_32) { switch (mbn_var_32) { - case 2u: + case 2: MotherBrain_HandleNeckLower_2_BobDown(); break; - case 4u: + case 4: MotherBrain_HandleNeckLower_4_BobUp(); break; - case 6u: + case 6: MotherBrain_HandleNeckLower_6_Lower(); break; - case 8u: + case 8: MotherBrain_HandleNeckLower_8_Raise(); break; default: @@ -1070,7 +1033,7 @@ void MotherBrain_HandleNeckUpper(void) { // 0xA99109 uint16 mbn_var_33 = E->mbn_var_33; if (mbn_var_33) { switch (mbn_var_33) { - case 2u: + case 2: if ((int16)(E->base.y_pos + 4 - samus_y_pos) < 0) { v2 = E->mbn_var_21 - E->mbn_var_34; if ((uint16)v2 < 0x2000) { @@ -1083,17 +1046,17 @@ void MotherBrain_HandleNeckUpper(void) { // 0xA99109 E->mbn_var_33 = 4; } break; - case 4u: { - R18_ = E->mbn_var_20 + 2048; + case 4: { + uint16 r18 = E->mbn_var_20 + 2048; uint16 v4 = E->mbn_var_34 + E->mbn_var_21; - if (v4 >= R18_) { + if (v4 >= r18) { E->mbn_var_33 = 2; - v4 = R18_; + v4 = r18; } E->mbn_var_21 = v4; break; } - case 6u: { + case 6: { v6 = E->mbn_var_21 - E->mbn_var_34; if ((uint16)v6 < 0x2000) { E->mbn_var_33 = 0; @@ -1102,12 +1065,12 @@ void MotherBrain_HandleNeckUpper(void) { // 0xA99109 E->mbn_var_21 = v6; break; } - case 8u: { - R18_ = E->mbn_var_20 + 2048; + case 8: { + uint16 r18 = E->mbn_var_20 + 2048; uint16 v8 = E->mbn_var_34 + E->mbn_var_21; - if (v8 >= R18_) { + if (v8 >= r18) { E->mbn_var_33 = 0; - v8 = R18_; + v8 = r18; } E->mbn_var_21 = v8; break; @@ -1130,18 +1093,18 @@ void MotherBrain_HandleNeck(void) { // 0xA991B8 MotherBrain_HandleNeckLower(); MotherBrain_HandleNeckUpper(); } - R18_ = HIBYTE(E1->mbn_var_20); - E1->mbn_var_22 = E->mbn_var_0A + ComputeSinMult(E1->mbn_var_24) + 112; - E1->mbn_var_23 = E->mbn_var_0B + ComputeCosMult(E1->mbn_var_24) - 96; - E1->mbn_var_25 = E->mbn_var_0A + ComputeSinMult(E1->mbn_var_27) + 112; - E1->mbn_var_26 = E->mbn_var_0B + ComputeCosMult(E1->mbn_var_27) - 96; - E1->mbn_var_28 = E->mbn_var_0A + ComputeSinMult(E1->mbn_var_2A) + 112; - E1->mbn_var_29 = E->mbn_var_0B + ComputeCosMult(E1->mbn_var_2A) - 96; - R18_ = HIBYTE(E1->mbn_var_21); - E1->mbn_var_2B = E1->mbn_var_28 + ComputeSinMult(E1->mbn_var_2D); - E1->mbn_var_2C = E1->mbn_var_29 + ComputeCosMult(E1->mbn_var_2D); - E1->mbn_var_2E = E1->mbn_var_28 + ComputeSinMult(E1->mbn_var_30); - E1->mbn_var_2F = E1->mbn_var_29 + ComputeCosMult(E1->mbn_var_30); + uint16 r18 = HIBYTE(E1->mbn_var_20); + E1->mbn_var_22 = E->mbn_var_0A + ComputeSinMult(E1->mbn_var_24, r18) + 112; + E1->mbn_var_23 = E->mbn_var_0B + ComputeCosMult(E1->mbn_var_24, r18) - 96; + E1->mbn_var_25 = E->mbn_var_0A + ComputeSinMult(E1->mbn_var_27, r18) + 112; + E1->mbn_var_26 = E->mbn_var_0B + ComputeCosMult(E1->mbn_var_27, r18) - 96; + E1->mbn_var_28 = E->mbn_var_0A + ComputeSinMult(E1->mbn_var_2A, r18) + 112; + E1->mbn_var_29 = E->mbn_var_0B + ComputeCosMult(E1->mbn_var_2A, r18) - 96; + r18 = HIBYTE(E1->mbn_var_21); + E1->mbn_var_2B = E1->mbn_var_28 + ComputeSinMult(E1->mbn_var_2D, r18); + E1->mbn_var_2C = E1->mbn_var_29 + ComputeCosMult(E1->mbn_var_2D, r18); + E1->mbn_var_2E = E1->mbn_var_28 + ComputeSinMult(E1->mbn_var_30, r18); + E1->mbn_var_2F = E1->mbn_var_29 + ComputeCosMult(E1->mbn_var_30, r18); } @@ -1174,62 +1137,45 @@ uint16 CallMotherBrainInstr(uint32 ea, uint16 k) { } int MotherBrain_Func_1_DoubleRet(void) { - int16 v1; - int16 mbn_var_21; - int16 v5; + uint16 v5; Enemy_MotherBrain *E = Get_MotherBrain(0); + uint16 pc = E->mbn_var_21; + if (!sign16(pc)) + return -1; - if (time_is_frozen_flag) { - mbn_var_21 = E->mbn_var_21; - if (mbn_var_21 >= 0) - return -1; - return *((uint16 *)RomPtr_A9(mbn_var_21) + 1); - } else { - v1 = E->mbn_var_21; - if (v1 >= 0) - return -1; - uint16 v4 = E->mbn_var_21; - v5 = *(uint16 *)RomPtr_A9(v1); - if (v5 < 0) - goto LABEL_10; - if ((int16)(v5 - E->mbn_var_20) >= 0) { - ++E->mbn_var_20; - return *((uint16 *)RomPtr_A9(v4) + 1); - } else { - for (v4 += 4; ; ) { - v5 = *(uint16 *)RomPtr_A9(v4); - if (v5 >= 0) - break; -LABEL_10: - R0_.addr = v5; - v4 = CallMotherBrainInstr((uint16)v5 | 0xA90000, v4 + 2); - } - E->mbn_var_20 = 1; - E->mbn_var_21 = v4; - return *((uint16 *)RomPtr_A9(v4) + 1); - } + const uint8 *p = RomPtr_A9(pc); + if (time_is_frozen_flag) + return GET_WORD(p + 2); + + v5 = GET_WORD(p); + if (sign16(v5)) + goto LABEL_10; + if ((int16)(v5 - E->mbn_var_20) >= 0) { + E->mbn_var_20++; + return GET_WORD(p + 2); } + for (pc += 4; ; ) { + p = RomPtr_A9(pc); + v5 = GET_WORD(p); + if (!sign16(v5)) + break; +LABEL_10: + pc = CallMotherBrainInstr(v5 | 0xA90000, pc + 2); + } + E->mbn_var_20 = 1; + E->mbn_var_21 = pc; + return GET_WORD(p + 2); } void MotherBrain_DrawNeck(void) { // 0xA99303 if ((Get_MotherBrain(0)->base.properties & kEnemyProps_Invisible) == 0) { Enemy_MotherBrain *E = Get_MotherBrain(0x40); - R18_ = E->mbn_var_2E; - R20_ = E->mbn_var_2F; - MotherBrain_DrawNeckSegment(); - R18_ = E->mbn_var_2B; - R20_ = E->mbn_var_2C; - MotherBrain_DrawNeckSegment(); - R18_ = E->mbn_var_28; - R20_ = E->mbn_var_29; - MotherBrain_DrawNeckSegment(); - R18_ = E->mbn_var_25; - R20_ = E->mbn_var_26; - MotherBrain_DrawNeckSegment(); - R18_ = E->mbn_var_22; - R20_ = E->mbn_var_23; - MotherBrain_DrawNeckSegment(); + MotherBrain_DrawNeckSegment(E->mbn_var_2E, E->mbn_var_2F); + MotherBrain_DrawNeckSegment(E->mbn_var_2B, E->mbn_var_2C); + MotherBrain_DrawNeckSegment(E->mbn_var_28, E->mbn_var_29); + MotherBrain_DrawNeckSegment(E->mbn_var_25, E->mbn_var_26); + MotherBrain_DrawNeckSegment(E->mbn_var_22, E->mbn_var_23); } } @@ -1244,7 +1190,7 @@ void MotherBrain_DrawBrain(void) { // 0xA99357 uint16 mbn_var_0D = Get_MotherBrain(0)->mbn_var_0D; if (E->base.flash_timer & 1) mbn_var_0D = 0; - R22_ = mbn_var_0D; + uint16 r22 = mbn_var_0D; uint16 mbn_var_00 = E->mbn_var_00; uint16 flash_timer; if (mbn_var_00) { @@ -1255,45 +1201,39 @@ void MotherBrain_DrawBrain(void) { // 0xA99357 if (!flash_timer) flash_timer = E->base.shake_timer; } - int v6 = (uint8)(flash_timer & 6) >> 1; - R18_ = E->base.x_pos + g_word_A993BB[v6]; - if ((int16)(R18_ + 32 - layer1_x_pos) >= 0) { - R20_ = E->base.y_pos + g_word_A993C3[v6]; - MotherBrain_AddSpritemapToOam(v2); + int v6 = (flash_timer & 6) >> 1; + uint16 r18 = E->base.x_pos + g_word_A993BB[v6]; + if ((int16)(r18 + 32 - layer1_x_pos) >= 0) { + uint16 r20 = E->base.y_pos + g_word_A993C3[v6]; + MotherBrain_AddSpritemapToOam(v2, r18, r20, r22); } } -void MotherBrain_DrawNeckSegment(void) { // 0xA993CB - int v0 = (uint8)(Get_MotherBrain(0x40)->base.flash_timer & 6) >> 1; - R18_ += g_word_A993BB[v0]; - R20_ += g_word_A993C3[v0]; - R22_ = Get_MotherBrain(0)->mbn_var_0C; - MotherBrain_AddSpritemapToOam(addr_kMotherBrain_Sprmap_A694); +void MotherBrain_DrawNeckSegment(uint16 x, uint16 y) { // 0xA993CB + int v0 = (Get_MotherBrain(0x40)->base.flash_timer & 6) >> 1; + MotherBrain_AddSpritemapToOam(addr_kMotherBrain_Sprmap_A694, + x + g_word_A993BB[v0], y + g_word_A993C3[v0], Get_MotherBrain(0)->mbn_var_0C); } -void MotherBrain_AddSpritemapToOam(uint16 j) { // 0xA993EE +void MotherBrain_AddSpritemapToOam(uint16 j, uint16 r18, uint16 r20, uint16 r22) { // 0xA993EE const uint8 *p = RomPtr_A9(j); int n = GET_WORD(p); p += 2; - int v3 = oam_next_ptr; + int idx = oam_next_ptr; do { - int16 v10 = R20_ + (int8)p[2] - layer1_y_pos; - if (v10 >= 0) { - uint16 v12 = R18_ + GET_WORD(p) - layer1_x_pos; - OamEnt *v13 = gOamEnt(v3); - v13->xcoord = v12; - int v14 = v3 >> 1; - if ((v12 & 0x100) != 0) - *(uint16 *)RomPtr_RAM(kOamExtra_Address_And_X8Large[v14]) |= kOamExtra_X8Small_And_Large[v14]; - if (sign16(GET_WORD(p))) - *(uint16 *)RomPtr_RAM(kOamExtra_Address_And_X8Large[v14]) |= kOamExtra_X8Small_And_Large[v14 + 1]; - v13->ycoord = v10; - *(uint16 *)&v13->charnum = R22_ | GET_WORD(p + 3); - v3 = (v3 + 4) & 0x1FF; + int16 y = r20 + (int8)p[2] - layer1_y_pos; + if (y >= 0) { + OamEnt *oam = gOamEnt(idx); + uint16 x = r18 + GET_WORD(p) - layer1_x_pos; + oam->xcoord = x; + oam->ycoord = y; + *(uint16 *)&oam->charnum = r22 | GET_WORD(p + 3); + oam_ext[idx >> 5] |= (((x & 0x100) >> 8) | (*(int16 *)p < 0) * 2) << (2 * ((idx >> 2) & 7)); + idx = (idx + 4) & 0x1FF; } p += 5; } while (--n); - oam_next_ptr = v3; + oam_next_ptr = idx; } void MotherBrain_CalculateRainbowBeamHdma(void) { // 0xA99466 @@ -1304,7 +1244,6 @@ void MotherBrain_MoveBodyDownScrollLeft(uint16 k, uint16 a) { // 0xA99552 Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.y_pos += a; reg_BG2VOFS -= a; - R20_ = k + 34; reg_BG2HOFS = k + 34 - E->base.x_pos; } @@ -1324,12 +1263,12 @@ void MotherBrain_FootstepEffect(void) { // 0xA99599 } const uint16 *MotherBrain_Instr_MoveBodyUp10Left4(uint16 k, const uint16 *jp) { // 0xA995B6 - MotherBrain_MoveBodyDownScrollLeft(4u, 0xFFF6); + MotherBrain_MoveBodyDownScrollLeft(4, 0xFFF6); return jp; } const uint16 *MotherBrain_Instr_MoveBodyUp16Left4(uint16 k, const uint16 *jp) { // 0xA995C0 - MotherBrain_MoveBodyDownScrollLeft(4u, 0xFFF0); + MotherBrain_MoveBodyDownScrollLeft(4, 0xFFF0); return jp; } @@ -1339,7 +1278,7 @@ const uint16 *MotherBrain_Instr_MoveBodyUp12Right2(uint16 k, const uint16 *jp) { } const uint16 *MotherBrain_Instr_MoveDown12Left4(uint16 k, const uint16 *jp) { // 0xA995DE - MotherBrain_MoveBodyDownScrollLeft(4u, 0xC); + MotherBrain_MoveBodyDownScrollLeft(4, 0xC); return jp; } @@ -1356,7 +1295,7 @@ const uint16 *MotherBrain_Instr_MoveDown10Right2(uint16 k, const uint16 *jp) { const uint16 *MotherBrain_Instr_MoveUp2Right1(uint16 k, const uint16 *jp) { // 0xA995FC Enemy_MotherBrain *E = Get_MotherBrain(0); ++E->base.x_pos; - MotherBrain_MoveBodyDown(0xFFFEu); + MotherBrain_MoveBodyDown(0xFFFE); return jp; } @@ -1368,7 +1307,7 @@ const uint16 *MotherBrain_Instr_MoveRight2(uint16 k, const uint16 *jp) { // 0xA } const uint16 *MotherBrain_Instr_MoveUp1(uint16 k, const uint16 *jp) { // 0xA9961C - MotherBrain_MoveBodyDown(1u); + MotherBrain_MoveBodyDown(1); return jp; } @@ -1376,28 +1315,28 @@ const uint16 *MotherBrain_Instr_MoveUp1Right3_Sfx(uint16 k, const uint16 *jp) { MotherBrain_FootstepEffect(); Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos += 3; - MotherBrain_MoveBodyDown(1u); + MotherBrain_MoveBodyDown(1); return jp; } const uint16 *MotherBrain_Instr_Down2Right15(uint16 k, const uint16 *jp) { // 0xA99638 Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos += 15; - MotherBrain_MoveBodyDown(0xFFFEu); + MotherBrain_MoveBodyDown(0xFFFE); return jp; } const uint16 *MotherBrain_Instr_Down4Right6(uint16 k, const uint16 *jp) { // 0xA99648 Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos += 6; - MotherBrain_MoveBodyDown(0xFFFCu); + MotherBrain_MoveBodyDown(0xFFFC); return jp; } const uint16 *MotherBrain_Instr_Up4Left2(uint16 k, const uint16 *jp) { // 0xA99658 Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos -= 2; - MotherBrain_MoveBodyDown(4u); + MotherBrain_MoveBodyDown(4); return jp; } @@ -1405,7 +1344,7 @@ const uint16 *MotherBrain_Instr_Up2Left1_Sfx(uint16 k, const uint16 *jp) { // 0 MotherBrain_FootstepEffect(); Enemy_MotherBrain *E = Get_MotherBrain(0); --E->base.x_pos; - MotherBrain_MoveBodyDown(2u); + MotherBrain_MoveBodyDown(2); return jp; } @@ -1413,7 +1352,7 @@ const uint16 *MotherBrain_Instr_Up2Left1_Sfx2(uint16 k, const uint16 *jp) { // MotherBrain_FootstepEffect(); Enemy_MotherBrain *E = Get_MotherBrain(0); --E->base.x_pos; - MotherBrain_MoveBodyDown(2u); + MotherBrain_MoveBodyDown(2); return jp; } @@ -1425,14 +1364,14 @@ const uint16 *MotherBrain_Instr_MoveLeft2(uint16 k, const uint16 *jp) { // 0xA9 } const uint16 *MotherBrain_Instr_MoveDown1(uint16 k, const uint16 *jp) { // 0xA996A4 - MotherBrain_MoveBodyDown(0xFFFFu); + MotherBrain_MoveBodyDown(0xFFFF); return jp; } const uint16 *MotherBrain_Instr_MoveDown1Left3(uint16 k, const uint16 *jp) { // 0xA996AA Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos -= 3; - MotherBrain_MoveBodyDown(0xFFFFu); + MotherBrain_MoveBodyDown(0xFFFF); return jp; } @@ -1440,28 +1379,28 @@ const uint16 *MotherBrain_Instr_MoveUp2Left15_Sfx(uint16 k, const uint16 *jp) { MotherBrain_FootstepEffect(); Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos -= 15; - MotherBrain_MoveBodyDown(2u); + MotherBrain_MoveBodyDown(2); return jp; } const uint16 *MotherBrain_Instr_MoveUp4Left6(uint16 k, const uint16 *jp) { // 0xA996D0 Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos -= 6; - MotherBrain_MoveBodyDown(4u); + MotherBrain_MoveBodyDown(4); return jp; } const uint16 *MotherBrain_Instr_MoveDown4Right2(uint16 k, const uint16 *jp) { // 0xA996E0 Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.x_pos += 2; - MotherBrain_MoveBodyDown(0xFFFCu); + MotherBrain_MoveBodyDown(0xFFFC); return jp; } const uint16 *MotherBrain_Instr_MoveDown2Right1(uint16 k, const uint16 *jp) { // 0xA996F0 Enemy_MotherBrain *E = Get_MotherBrain(0); ++E->base.x_pos; - MotherBrain_MoveBodyDown(0xFFFEu); + MotherBrain_MoveBodyDown(0xFFFE); return jp; } @@ -1497,18 +1436,14 @@ const uint16 *MotherBrain_Instr_SetPose_LeaningDown(uint16 k, const uint16 *jp) const uint16 *MotherBrain_Instr_SpawnEprojToOffset(uint16 k, const uint16 *jp) { // 0xA99AC8 Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = E->base.x_pos + jp[0]; - R20_ = E->base.y_pos + jp[1]; + eproj_spawn_pt = (Point16U){ E->base.x_pos + jp[0], E->base.y_pos + jp[1] }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, jp[2]); return jp + 3; } const uint16 *MotherBrain_Instr_SpawnDeathBeamEproj(uint16 k, const uint16 *jp) { // 0xA99AEF - uint16 v2; - //printf("A undefined\n"); - v2 = 0; - QueueSfx2_Max6(0x63u); - SpawnEnemyProjectileWithGfx(v2, 0x40, addr_kEproj_MotherBrainDeathBeamCharging); + QueueSfx2_Max6(0x63); + SpawnEnemyProjectileWithGfx(0, 0x40, addr_kEproj_MotherBrainDeathBeamCharging); return jp; } @@ -1551,19 +1486,14 @@ uint16 MotherBrain_Instr_SpawnDroolEproj(uint16 k) { // 0xA99B3C if (!sign16(E->mbn_var_13 - 5)) v2 = 0; E->mbn_var_13 = v2; - uint16 v3 = addr_kEproj_MotherBrainDrool; - if (!sign16(E->mbn_var_34 - 128)) - v3 = addr_kEproj_MotherBrainDyingDrool; + uint16 v3 = sign16(E->mbn_var_34 - 128) ? addr_kEproj_MotherBrainDrool : addr_kEproj_MotherBrainDyingDrool; SpawnEnemyProjectileWithRoomGfx(v3, E->mbn_var_13); } return k; } uint16 MotherBrain_Instr_SpawnPurpleBreath(uint16 k) { // 0xA99B6D - uint16 v2; - //printf("A undefined\n"); - v2 = 0; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainPurpleBreathBig, v2); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainPurpleBreathBig, 0); return k; } @@ -1574,7 +1504,7 @@ uint16 MotherBrain_Instr_SetMainShakeTimer50(uint16 k) { // 0xA99B77 uint16 MotherBrain_Instr_GotoEitherOr(uint16 k) { // 0xA99C65 uint16 result = addr_stru_A99C5F; - if ((random_number & 0xFFFu) >= 0xFE0) + if ((random_number & 0xFFF) >= 0xFE0) return addr_stru_A99C47; return result; } @@ -1586,7 +1516,7 @@ uint16 MotherBrain_Instr_MaybeGoto(uint16 k) { // 0xA99CAD } uint16 MotherBrain_Instr_MaybeGoto2(uint16 k) { // 0xA99D0D - if ((random_number & 0xFFFu) < 0xEC0) + if ((random_number & 0xFFF) < 0xEC0) return MotherBrain_Instr_Goto2(k); return k; } @@ -1610,24 +1540,20 @@ uint16 MotherBrain_Instr_SpawnBlueRingEproj(uint16 k) { // 0xA99E29 uint16 MotherBrain_Instr_AimRingsAtShitroid(uint16 k) { // 0xA99E37 Enemy_MotherBrain *E = Get_MotherBrain(0x40); Enemy_MotherBrain *E1 = Get_MotherBrain(E->mbn_var_0A); - R18_ = E1->base.x_pos - E->base.x_pos - 10; - R20_ = E1->base.y_pos - E->base.y_pos - 16; - MotherBrain_Instr_AimRings(); + MotherBrain_Instr_AimRings(E1->base.x_pos - E->base.x_pos - 10, E1->base.y_pos - E->base.y_pos - 16); return k; } uint16 MotherBrain_Instr_AimRingsAtSamus(uint16 k) { // 0xA99E5B Enemy_MotherBrain *E = Get_MotherBrain(0x40); - R18_ = samus_x_pos - E->base.x_pos - 10; - R20_ = samus_y_pos - E->base.y_pos - 16; - MotherBrain_Instr_AimRings(); + MotherBrain_Instr_AimRings(samus_x_pos - E->base.x_pos - 10, samus_y_pos - E->base.y_pos - 16); return k; } -void MotherBrain_Instr_AimRings(void) { // 0xA99E77 - uint16 v0 = (uint8)-(int8)(CalculateAngleFromXY() + 0x80); +void MotherBrain_Instr_AimRings(uint16 x, uint16 y) { // 0xA99E77 + uint16 v0 = (uint8)-(CalculateAngleFromXY(x, y) + 0x80); if (!sign8(v0 - 16)) { - if ((uint8)v0 < 0x48u) + if ((uint8)v0 < 0x48) goto LABEL_6; LABEL_5: LOBYTE(v0) = 72; @@ -1645,7 +1571,7 @@ uint16 MotherBrain_Instr_IncrShitroidAttackCtr(uint16 k) { // 0xA99EA3 Enemy_MotherBrain *E = Get_MotherBrain(0); v3 = E->mbn_var_13 + 1; - if ((uint16)v3 >= 0xCu) + if ((uint16)v3 >= 0xC) v3 = 12; E->mbn_var_13 = v3; return k; @@ -1665,24 +1591,21 @@ uint16 MotherBrain_Instr_SpawnBombEproj(uint16 k) { // 0xA99EBD uint16 MotherBrain_Instr_SpawnLaserEproj(uint16 k) { // 0xA99F46 Enemy_MotherBrain *E = Get_MotherBrain(0x40); E->mbn_var_31 = 0; - R18_ = E->base.x_pos + 16; - R20_ = E->base.y_pos + 4; - SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 1u); + eproj_spawn_r22 = 1; + eproj_spawn_pt = (Point16U){ E->base.x_pos + 16, E->base.y_pos + 4 }; + SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 1); return k; } uint16 MotherBrain_Instr_SpawnRainbowEproj(uint16 k) { // 0xA99F84 - uint16 v2; - //printf("A undefined\n"); - v2 = 0; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainRainbowBeamCharging, v2); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainRainbowBeamCharging, 0); return k; } uint16 MotherBrain_Instr_SetupFxForRainbowBeam(uint16 k) { // 0xA99F8E Get_MotherBrain(0x40)->mbn_var_14 = 0; MotherBrain_SetupBrainPalForLaser(); - QueueSfx2_Max6(0x7Fu); + QueueSfx2_Max6(0x7F); return k; } @@ -1690,9 +1613,9 @@ void MotherBrain_Phase3_Death_0(void) { // 0xA9AEE1 Enemy_MotherBrain *E = Get_MotherBrain(0); E->base.properties |= kEnemyProps_Tangible; Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); - E1->base.properties |= 0x400u; + E1->base.properties |= 0x400; E->mbn_var_04 = 0; - if (MotherBrain_MakeWalkBackwards(0x28, 6u) & 1) { + if (MotherBrain_MakeWalkBackwards(0x28, 6) & 1) { E->mbn_var_A = FUNC16(MotherBrain_Phase3_Death_1); E->mbn_var_F = 128; MotherBrain_Phase3_Death_1(); @@ -1708,7 +1631,7 @@ void MotherBrain_Phase3_Death_1(void) { // 0xA9AF12 void MotherBrain_Phase3_Death_2(void) { // 0xA9AF21 MotherBrain_GenerateSmokyExplosions(); - if (MotherBrain_MakeWalkForwards(2u, 0x60) & 1) { + if (MotherBrain_MakeWalkForwards(2, 0x60) & 1) { MotherBrain_SetBrainInstrs(addr_kMotherBrain_Ilist_9C39); Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); E1->mbn_var_32 = 6; @@ -1782,18 +1705,14 @@ void MotherBrain_Phase3_Death_6(void) { // 0xA9B013 } void MotherBrain_GenerateSmokyExplosions(void) { // 0xA9B022 - R22_ = addr_word_A9B10F; - R24_ = 2; - MotherBrain_GenerateExplosions(0x10); + MotherBrain_GenerateExplosions(0x10, addr_word_A9B10F, 2); } void MotherBrain_GenerateMixedExplosions(void) { // 0xA9B031 - R22_ = addr_word_A9B109; - R24_ = 4; - MotherBrain_GenerateExplosions(8u); + MotherBrain_GenerateExplosions(8, addr_word_A9B109, 4); } -void MotherBrain_GenerateExplosions(uint16 a) { // 0xA9B03E +void MotherBrain_GenerateExplosions(uint16 a, uint16 r22, uint16 r24) { // 0xA9B03E Enemy_MotherBrain *E = Get_MotherBrain(0x40); bool v2 = (--E->mbn_var_E & 0x8000) != 0; if (v2) { @@ -1802,14 +1721,13 @@ void MotherBrain_GenerateExplosions(uint16 a) { // 0xA9B03E if (v2) E->mbn_var_F = 6; uint16 v3 = 16 * E->mbn_var_F; - uint16 v4 = R24_; + uint16 v4 = r24; uint16 v9; do { v9 = v4; int v5 = v3 >> 1; - R18_ = g_word_A9B099[v5]; - R20_ = g_word_A9B099[v5 + 1]; - const uint16 *v6 = (const uint16 *)RomPtr_A9(R22_); + eproj_spawn_pt = (Point16U){ g_word_A9B099[v5], g_word_A9B099[v5 + 1] }; + const uint16 *v6 = (const uint16 *)RomPtr_A9(r22); uint16 v7 = *v6; uint16 Random = NextRandom(); if (Random >= 0x4000) { @@ -1821,7 +1739,7 @@ void MotherBrain_GenerateExplosions(uint16 a) { // 0xA9B03E v3 += 4; v4 = v9 - 1; } while (v9 != 1); - QueueSfx3_Max3(0x13u); + QueueSfx3_Max3(0x13); } } @@ -1842,8 +1760,8 @@ void MotherBrain_Phase3_Death_8(void) { // 0xA9B12D E->mbn_var_F = v1; Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); v3 = E1->base.y_pos + HIBYTE(v1); - if ((uint16)v3 >= 0xC4u) { - EnableEarthquakeAframes(2u); + if ((uint16)v3 >= 0xC4) { + EnableEarthquakeAframes(2); E->mbn_var_A = FUNC16(MotherBrain_Phase3_Death_9); E->mbn_var_F = 256; v3 = 196; @@ -1888,7 +1806,7 @@ void MotherBrain_Phase3_Death_12(void) { // 0xA9B1B8 if ((--E->mbn_var_F & 0x8000) != 0) { E->mbn_var_A = FUNC16(MotherBrain_Phase3_Death_13); Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); - E1->base.properties |= 0x400u; + E1->base.properties |= 0x400; E->mbn_var_04 = 0; } } @@ -1902,7 +1820,7 @@ void MotherBrain_Phase3_Death_13(void) { // 0xA9B1D5 E1->base.properties = E1->base.properties & 0xDEFF | 0x100; E1->base.extra_properties = 0; QueueMusic_Delayed8(0); - QueueMusic_Delayed8(0xFF24u); + QueueMusic_Delayed8(0xFF24); E1 = Get_DeadMonsters(0); E1->dms_var_A = FUNC16(MotherBrain_Phase3_Death_14_20framedelay); E1->dms_var_F = 20; @@ -1922,10 +1840,9 @@ void MotherBrain_Phase3_Death_14_20framedelay(void) { // 0xA9B211 void MotherBrain_CorpseRottingFinished(void) { // 0xA9B223 Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); - R18_ = E1->base.x_pos + (random_number & 0x1F) - 16; - R20_ = E1->base.y_pos + 16; + eproj_spawn_pt = (Point16U){ E1->base.x_pos + (random_number & 0x1F) - 16, E1->base.y_pos + 16 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0xA); - if ((enemy_damage_routine_exec_count & 7) == 0) + if ((random_enemy_counter & 7) == 0) QueueSfx2_Max3(0x10); } @@ -1939,7 +1856,7 @@ void MotherBrain_Phase3_Death_15_LoadEscapeTimerTiles(void) { // 0xA9B258 void MotherBrain_Phase3_Death_16_StartEscape(void) { // 0xA9B26D if (ProcessSpriteTilesTransfers(0xa9, addr_stru_A9902F)) { WriteColorsToPalette(0x122, 0xa9, addr_kMotherBrainPalette_5 + 2, 0xE); - QueueMusic_Delayed8(7u); + QueueMusic_Delayed8(7); earthquake_type = 5; earthquake_timer = -1; SpawnPalfxObject(addr_kPalfx_FFC9); @@ -1961,9 +1878,7 @@ void MotherBrain_Phase3_Death_17_SpawnTimeBomb(void) { // 0xA9B2D1 Enemy_MotherBrain *E = Get_MotherBrain(0); if ((--E->mbn_var_F & 0x8000) != 0) { E->mbn_var_A = FUNC16(MotherBrain_Phase3_Death_18_TypesZebesText); - SpawnEnemyProjectileWithRoomGfx( - addr_kEproj_TimeBombSetJapaneseText, - FUNC16(MotherBrain_Phase3_Death_18_TypesZebesText)); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TimeBombSetJapaneseText, FUNC16(MotherBrain_Phase3_Death_18_TypesZebesText)); } MotherBrain_Phase3_Death_18_TypesZebesText(); } @@ -1980,10 +1895,10 @@ void MotherBrain_Phase3_Death_19_EscapeDoorExploding(void) { // 0xA9B2F9 MotherBrain_GenerateEscapeDoorExploding(); Enemy_MotherBrain *E = Get_MotherBrain(0); if ((--E->mbn_var_F & 0x8000) != 0) { - CallSomeSamusCode(0xFu); + CallSomeSamusCode(0xF); timer_status = 2; - SetBossBitForCurArea(2u); - SetEventHappened(0xEu); + SetBossBitForCurArea(2); + SetEventHappened(0xE); E->mbn_var_A = FUNC16(MotherBrain_Phase3_Death_20_BlowUpEscapeDoor); Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); E1->mbn_var_E = 0; @@ -1992,10 +1907,9 @@ void MotherBrain_Phase3_Death_19_EscapeDoorExploding(void) { // 0xA9B2F9 } void MotherBrain_Phase3_Death_20_BlowUpEscapeDoor(void) { // 0xA9B32A - static const SpawnHardcodedPlmArgs unk_A9B337 = { 0x00, 0x06, 0xb677 }; MotherBrain_ExplodeEscapeDoor(); Get_MotherBrain(0)->mbn_var_A = FUNC16(MotherBrain_Phase3_Death_21_KeepEarthquakeGoing); - SpawnHardcodedPlm(&unk_A9B337); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x00, 0x06, 0xb677 }); } void MotherBrain_Phase3_Death_21_KeepEarthquakeGoing(void) { // 0xA9B33C @@ -2017,13 +1931,12 @@ void MotherBrain_GenerateEscapeDoorExploding(void) { // 0xA9B346 if (v2 < 0) E->mbn_var_F = 3; int v3 = (uint16)(4 * E->mbn_var_F) >> 1; - R18_ = g_word_A9B393[v3]; - R20_ = g_word_A9B393[v3 + 1]; + eproj_spawn_pt = (Point16U){ g_word_A9B393[v3], g_word_A9B393[v3 + 1] }; uint16 v4 = 3; if (NextRandom() < 0x4000) v4 = 12; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, v4); - QueueSfx2_Max3(0x24u); + QueueSfx2_Max3(0x24); } } @@ -2033,40 +1946,30 @@ void MotherBrain_ExplodeEscapeDoor(void) { // 0xA9B3A3 v1 = v0; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainExplodedEscapeDoor, v0); v0 = v1 + 1; - } while ((uint16)(v1 + 1) < 8u); + } while ((uint16)(v1 + 1) < 8); } void MotherBrain_SamusCollDetect(void) { // 0xA9B3B6 int8 v1; // cf Enemy_MotherBrain *E0 = Get_MotherBrain(0); - R26_ = E0->mbn_var_04; - v1 = R26_ & 1; - R26_ >>= 1; + uint16 R26 = E0->mbn_var_04; + v1 = R26 & 1; + R26 >>= 1; if (!v1 - || (R18_ = E0->base.x_pos, - R20_ = E0->base.y_pos, - !(MotherBrain_SamusCollDetectPart(addr_word_A9B427) & 1))) { + || (!(MotherBrain_SamusCollDetectPart(addr_word_A9B427, E0->base.x_pos, E0->base.y_pos) & 1))) { Enemy_MotherBrain *E = Get_MotherBrain(0x40); - v1 = R26_ & 1; - R26_ >>= 1; + v1 = R26 & 1; + R26 >>= 1; if (!v1 - || (R18_ = E->base.x_pos, - R20_ = E->base.y_pos, - !(MotherBrain_SamusCollDetectPart(0xB439u) & 1))) { - v1 = R26_ & 1; - R26_ >>= 1; + || (!(MotherBrain_SamusCollDetectPart(0xB439, E->base.x_pos, E->base.y_pos) & 1))) { + v1 = R26 & 1; + R26 >>= 1; if (v1) { - R18_ = E->mbn_var_25; - R20_ = E->mbn_var_26; - if (!(MotherBrain_SamusCollDetectPart(0xB44Bu) & 1)) { - R18_ = E->mbn_var_28; - R20_ = E->mbn_var_29; - if (!(MotherBrain_SamusCollDetectPart(0xB44Bu) & 1)) { - R18_ = E->mbn_var_2B; - R20_ = E->mbn_var_2C; - MotherBrain_SamusCollDetectPart(0xB44Bu); + if (!(MotherBrain_SamusCollDetectPart(0xB44B, E->mbn_var_25, E->mbn_var_26) & 1)) { + if (!(MotherBrain_SamusCollDetectPart(0xB44B, E->mbn_var_28, E->mbn_var_29) & 1)) { + MotherBrain_SamusCollDetectPart(0xB44B, E->mbn_var_2B, E->mbn_var_2C); } } } @@ -2074,51 +1977,47 @@ void MotherBrain_SamusCollDetect(void) { // 0xA9B3B6 } } -uint8 MotherBrain_SamusCollDetectPart(uint16 k) { // 0xA9B455 +uint8 MotherBrain_SamusCollDetectPart(uint16 k, uint16 r18, uint16 r20) { // 0xA9B455 int16 v5; - - const uint16 *v1 = (const uint16 *)RomPtr_A9(k); - if (!*v1) - return 0; - R22_ = *v1; - for (int i = k + 2; ; i += 8) { - uint16 v3, v4; - if ((int16)(samus_y_pos - R20_) >= 0) { - R24_ = samus_y_pos - R20_; - v3 = *((uint16 *)RomPtr_A9(i) + 3); + const uint8 *p = RomPtr_A9(k); + int n = GET_WORD(p); + for (p += 2; n; p += 8, n--) { + uint16 v3, v4, R24; + if ((int16)(samus_y_pos - r20) >= 0) { + R24 = samus_y_pos - r20; + v3 = GET_WORD(p + 6); } else { - R24_ = R20_ - samus_y_pos; - v3 = *((uint16 *)RomPtr_A9(i) + 1); + R24 = r20 - samus_y_pos; + v3 = GET_WORD(p + 2); } - if ((int16)(samus_y_radius + abs16(v3) - R24_) >= 0) { - if ((int16)(samus_x_pos - R18_) >= 0) { - R24_ = samus_x_pos - R18_; - v4 = *((uint16 *)RomPtr_A9(i) + 2); + if ((int16)(samus_y_radius + abs16(v3) - R24) >= 0) { + if ((int16)(samus_x_pos - r18) >= 0) { + R24 = samus_x_pos - r18; + v4 = GET_WORD(p + 4); } else { - R24_ = R18_ - samus_x_pos; - v4 = *(uint16 *)RomPtr_A9(i); + R24 = r18 - samus_x_pos; + v4 = GET_WORD(p); + } + v5 = samus_x_radius + abs16(v4) - R24; + if (v5 >= 0) { + if (sign16(v5 - 4)) + v5 = 4; + extra_samus_x_displacement = v5; + extra_samus_y_displacement = 4; + extra_samus_x_subdisplacement = 0; + extra_samus_y_subdisplacement = 0; + samus_invincibility_timer = 96; + samus_knockback_timer = 5; + knockback_x_dir = 1; + if (sign16(samus_y_pos - 192)) + samus_y_dir = 2; + if ((int16)(Get_MotherBrain(0)->base.x_pos + 24 - samus_x_pos) < 0) + MotherBrain_HurtSamus(); + return 1; } - v5 = samus_x_radius + abs16(v4) - R24_; - if (v5 >= 0) - break; } - if (!--R22_) - return 0; } - if (sign16(v5 - 4)) - v5 = 4; - extra_samus_x_displacement = v5; - extra_samus_y_displacement = 4; - extra_samus_x_subdisplacement = 0; - extra_samus_y_subdisplacement = 0; - samus_invincibility_timer = 96; - samus_knockback_timer = 5; - knockback_x_dir = 1; - if (sign16(samus_y_pos - 192)) - samus_y_dir = 2; - if ((int16)(Get_MotherBrain(0)->base.x_pos + 24 - samus_x_pos) < 0) - MotherBrain_HurtSamus(); - return 1; + return 0; } void MotherBrainsBody_Shot(void) { // 0xA9B503 @@ -2139,7 +2038,7 @@ void MotherBrainsBrain_Shot(void) { // 0xA9B507 uint16 v1 = HIBYTE(projectile_type[collision_detection_index]) & 7; if (g_byte_A9B546[v1]) { plm_room_arguments[39] += g_byte_A9B546[v1]; - QueueSfx2_Max6(0x6Eu); + QueueSfx2_Max6(0x6E); v2 = 13; Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); uint16 flash_timer = E1->base.flash_timer; @@ -2328,7 +2227,7 @@ void MotherBrain_FiringBomb_DecideOnWalking(void) { // 0xA9B781 v0 = 96; Enemy_MotherBrain *E = Get_MotherBrain(0); if ((int16)(v0 - E->base.x_pos) >= 0 - || (E->mbn_var_F = v0, MotherBrain_MakeWalkBackwards(v0, 6u) & 1)) { + || (E->mbn_var_F = v0, MotherBrain_MakeWalkBackwards(v0, 6) & 1)) { MotherBrain_FiringBomb_DecideOnCrouching(); } else { E->mbn_var_A = FUNC16(MotherBrain_FiringBomb_WalkingBackwards); @@ -2337,7 +2236,7 @@ void MotherBrain_FiringBomb_DecideOnWalking(void) { // 0xA9B781 void MotherBrain_FiringBomb_WalkingBackwards(void) { // 0xA9B7AC Enemy_MotherBrain *E = Get_MotherBrain(0); - if (MotherBrain_MakeWalkBackwards(E->mbn_var_F, 6u) & 1) + if (MotherBrain_MakeWalkBackwards(E->mbn_var_F, 6) & 1) MotherBrain_FiringBomb_DecideOnCrouching(); } @@ -2439,13 +2338,12 @@ static Func_V *const off_A9B887[4] = { // 0xA9B87D MotherBomb_FiringDeathBeam_3, }; void MotherBomb_FiringDeathBeam(void) { - - int v0 = (uint16)(2 * Get_MotherBrain(0)->mbn_var_17) >> 1; + int v0 = Get_MotherBrain(0)->mbn_var_17; off_A9B887[v0](); } void MotherBomb_FiringDeathBeam_0(void) { // 0xA9B88F - if (MotherBrain_MakeWalkBackwards(0x28, 8u) & 1) { + if (MotherBrain_MakeWalkBackwards(0x28, 8) & 1) { Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); E1->mbn_var_32 = 8; E1->mbn_var_33 = 6; @@ -2499,7 +2397,7 @@ void MotherBomb_FiringRainbowBeam_1_StartCharge(void) { // 0xA9B91A } void MotherBomb_FiringRainbowBeam_2_RetractNeck(void) { // 0xA9B92B - if (MotherBrain_WalkBackwardsSlowlyAndRetractHead(0x28u) & 1) { + if (MotherBrain_WalkBackwardsSlowlyAndRetractHead(0x28) & 1) { Enemy_MotherBomb *E = Get_MotherBomb(0); E->mbb_var_A = FUNC16(MotherBomb_FiringRainbowBeam_3_Wait); E->mbb_var_F = 256; @@ -2510,7 +2408,7 @@ void MotherBomb_FiringRainbowBeam_2_RetractNeck(void) { // 0xA9B92B void MotherBomb_FiringRainbowBeam_3_Wait(void) { // 0xA9B93F Enemy_MotherBomb *E = Get_MotherBomb(0); if ((--E->mbb_var_F & 0x8000) != 0) { - QueueSfx2_Max6(0x71u); + QueueSfx2_Max6(0x71); E->mbb_var_A = FUNC16(MotherBomb_FiringRainbowBeam_4_ExtendNeckDown); MotherBomb_FiringRainbowBeam_4_ExtendNeckDown(); } @@ -2620,9 +2518,9 @@ void MotherBomb_FiringRainbowBeam_10_FinishFiringRainbow(void) { // 0xA9BA5E MotherBrain_SetBrainInstrs(addr_kMotherBrain_Ilist_9C87); MotherBrain_SetupBrainNormalPal(); MotherBrain_WriteDefaultPalette(); - QueueSfx1_Max6(2u); + QueueSfx1_Max6(2); E->mbn_var_16 = 0; - CallSomeSamusCode(1u); + CallSomeSamusCode(1); cooldown_timer = 8; E->mbn_var_A = FUNC16(MotherBomb_FiringRainbowBeam_11_LetSamusFall); } @@ -2702,10 +2600,8 @@ void MotherBrain_AimBeamAndIncrWidth(void) { // 0xA9BB6E void MotherBrain_AimBeam(void) { // 0xA9BB82 Enemy_MotherBrain *E = Get_MotherBrain(0x40); - R18_ = samus_x_pos - E->base.x_pos - 16; - R20_ = samus_y_pos - E->base.y_pos - 4; - uint16 v1 = (uint8)-(int8)(CalculateAngleFromXY() + 0x80); - Get_MotherBrain(0)->mbn_var_31 = v1; + Get_MotherBrain(0)->mbn_var_31 = + (uint8)-(CalculateAngleFromXY(samus_x_pos - E->base.x_pos - 16, samus_y_pos - E->base.y_pos - 4) + 0x80); } void MotherBrain_CalculateRainbowBeamHdma_(void) { // 0xA9BBB0 @@ -2715,8 +2611,7 @@ void MotherBrain_CalculateRainbowBeamHdma_(void) { // 0xA9BBB0 uint8 MotherBrain_MoveSamusTowardsWallDueToBeam(void) { // 0xA9BBB5 uint8 v0 = MotherBrain_MoveSamusHorizTowardsWall(0x1000); if (!v0) { - R18_ = Get_MotherBrain(0)->mbn_var_31; - uint16 v1 = Math_MultByCos(0x1000); + uint16 v1 = Math_MultByCos(0x1000, Get_MotherBrain(0)->mbn_var_31); MotherBrain_MoveSamusVerticallyTowardsCeilingFloor(v1); } return v0; @@ -2787,10 +2682,9 @@ void MotherBrain_HandleRainbowBeamExplosions(void) { // 0xA9BC76 E->mbn_parameter_2 = 8; ++E->mbn_parameter_1; int v2 = E->mbn_parameter_1 & 7; - R18_ = g_word_A9BCA6[v2]; - R20_ = g_word_A9BCB6[v2]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainRainbowBeamExplosion, R20_); - QueueSfx2_Max6(0x24u); + eproj_spawn_pt = (Point16U){ g_word_A9BCA6[v2], g_word_A9BCB6[v2] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_MotherBrainRainbowBeamExplosion, 0); + QueueSfx2_Max6(0x24); } } @@ -2832,13 +2726,13 @@ void MotherBrain_Phase2Cut_0(void) { // 0xA9BD45 uint16 v0 = SuitDamageDivision(0x50); if ((int16)(4 * v0 + 20 - samus_health) >= 0) { Get_MotherBrain(0)->mbn_var_A = FUNC16(MotherBrain_Phase2Cut_1); - } else if ((random_number & 0xFFFu) < 0xFA0) { + } else if ((random_number & 0xFFF) < 0xFA0) { if ((Get_MotherBrain(0)->base.frame_counter & 0x1F) == 0) MotherBrain_MaybeStandupOrLeanDown(); } else { uint16 v1; if ((int16)(SuitDamageDivision(0xA0) + 20 - samus_health) >= 0 - || (v1 = addr_kMotherBrain_Ilist_9ECC, (random_number & 0xFFFu) < 0xFF0)) { + || (v1 = addr_kMotherBrain_Ilist_9ECC, (random_number & 0xFFF) < 0xFF0)) { v1 = addr_kMotherBrain_Ilist_9D7F; } MotherBrain_SetBrainInstrs(v1); @@ -2891,7 +2785,7 @@ void MotherBrain_Phase2Cut_5(void) { // 0xA9BDED E1->mbn_var_32 = 6; E1->mbn_var_33 = 6; E1->mbn_var_34 = 1280; - QueueSfx2_Max6(0x71u); + QueueSfx2_Max6(0x71); E->mbn_var_A = FUNC16(nullsub_364); } } @@ -2941,8 +2835,7 @@ void MotherBrain_DrainedByShitroid_2(void) { // 0xA9BE96 if (!E1->mbn_var_00) E1->mbn_var_00 = 50; MotherBrain_HandleRainbowBeamPalette(); - R18_ = E1->mbn_var_08; - CallMotherBrainPainfulWalk(R18_ | 0xA90000); + CallMotherBrainPainfulWalk(E1->mbn_var_08 | 0xA90000); uint16 v2 = 2 * E1->mbn_var_06; E1->mbn_var_07 = g_byte_A9BEEE[v2]; E1->mbn_var_34 = g_word_A9BEFE[v2 >> 1]; @@ -2951,15 +2844,14 @@ void MotherBrain_DrainedByShitroid_2(void) { // 0xA9BE96 E->mbn_var_16 = 0; E1->mbn_var_10 = 0; MotherBrain_WritePhase2DeathPalette(); - QueueSfx1_Max6(2u); + QueueSfx1_Max6(2); E->mbn_var_A = FUNC16(MotherBrain_DrainedByShitroid_3); } } void MotherBrain_DrainedByShitroid_3(void) { // 0xA9BF0E Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); - R18_ = E1->mbn_var_08; - CallMotherBrainPainfulWalk(R18_ | 0xA90000); + CallMotherBrainPainfulWalk(E1->mbn_var_08 | 0xA90000); if (sign16(E1->mbn_var_06 - 8)) { } else { E1->mbn_var_34 = 64; @@ -3129,7 +3021,7 @@ void MotherBrain_Phase2_Revive_5(void) { // 0xA9C0E4 void MotherBrain_Phase2_Revive_6(void) { // 0xA9C0FB Enemy_MotherBrain *E = Get_MotherBrain(0); bool v1 = (--E->mbn_var_F & 0x8000) != 0; - if (v1 && MotherBrain_MakeWalkForwards(4u, 0x50) & 1) { + if (v1 && MotherBrain_MakeWalkForwards(4, 0x50) & 1) { E->mbn_var_A = FUNC16(MotherBrain_Phase2_Revive_7); E->mbn_var_1F = 2; Get_MotherBrain(0x40)->mbn_var_11 = 1; @@ -3177,7 +3069,7 @@ void MotherBrain_Phase2_MurderShitroid_2(void) { // 0xA9C182 void MotherBrain_Phase2_PrepareForFinalShitroid(void) { // 0xA9C18E MotherBrain_MakeHerStandUp(); - MotherBrain_MakeWalkBackwards(0x40, 4u); + MotherBrain_MakeWalkBackwards(0x40, 4); } void MotherBrain_Phase2_ExecuteFinalkShitroid(void) { // 0xA9C19A @@ -3200,7 +3092,7 @@ void MotherBrain_Phase3_Recover_MakeDistance(void) { // 0xA9C1CF E->mbn_var_00 = 4; E->mbn_var_A = FUNC16(MotherBrain_Phase3_Recover_SetupForFight); E->mbn_var_F = 32; - MotherBrain_MakeWalkBackwards(E->base.x_pos - 14, 2u); + MotherBrain_MakeWalkBackwards(E->base.x_pos - 14, 2); } void MotherBrain_Phase3_Recover_SetupForFight(void) { // 0xA9C1F0 @@ -3249,8 +3141,7 @@ void CallMotherBrainWallkFunc1A(uint32 ea) { void MotherBrain_Phase3_WalkHandler(void) { // 0xA9C25A if (!Get_MotherBrain(0)->mbn_var_02) { - R18_ = Get_MotherBrain(0x40)->mbn_var_1A; - CallMotherBrainWallkFunc1A(R18_ | 0xA90000); + CallMotherBrainWallkFunc1A(Get_MotherBrain(0x40)->mbn_var_1A | 0xA90000); } } @@ -3278,7 +3169,7 @@ void MotherBrain_Phase3_Walk_TryToInchForward(void) { // 0xA9C26A void MotherBrain_Phase3_Walk_RetreatQuickly(void) { // 0xA9C2B3 Enemy_MotherBrain *E = Get_MotherBrain(0x40); - if (MotherBrain_MakeWalkBackwards(E->mbn_var_1B, 2u) & 1) { + if (MotherBrain_MakeWalkBackwards(E->mbn_var_1B, 2) & 1) { E->mbn_var_1B = Get_MotherBrain(0)->base.x_pos - 14; E->mbn_var_1A = FUNC16(MotherBrain_Phase3_Walk_RetreatSlowly); } @@ -3286,7 +3177,7 @@ void MotherBrain_Phase3_Walk_RetreatQuickly(void) { // 0xA9C2B3 void MotherBrain_Phase3_Walk_RetreatSlowly(void) { // 0xA9C2D2 Enemy_MotherBrain *E = Get_MotherBrain(0x40); - if (MotherBrain_MakeWalkBackwards(E->mbn_var_1B, 4u) & 1) + if (MotherBrain_MakeWalkBackwards(E->mbn_var_1B, 4) & 1) MotherBrain_SetToTryToInchForward(0x40); } @@ -3311,8 +3202,7 @@ void CallMotherBrainNeckFunc(uint32 ea) { } void MotherBrain_Phase3_NeckHandler(void) { // 0xA9C327 - R18_ = Get_MotherBrain(0x40)->mbn_var_18; - CallMotherBrainNeckFunc(R18_ | 0xA90000); + CallMotherBrainNeckFunc(Get_MotherBrain(0x40)->mbn_var_18 | 0xA90000); } void MotherBrain_Phase3_Neck_Normal(void) { // 0xA9C330 @@ -3416,12 +3306,12 @@ void Enemy_SetInstrList(uint16 k, uint16 a) { // 0xA9C453 v2->timer = 0; } -uint16 ComputeSinMult(uint16 a) { // 0xA9C460 - return sub_A9C46C(R18_, a); +uint16 ComputeSinMult(uint16 a, uint16 r18) { // 0xA9C460 + return sub_A9C46C(r18, a); } -uint16 ComputeCosMult(uint16 a) { // 0xA9C465 - return sub_A9C46C(R18_ + 64, a); +uint16 ComputeCosMult(uint16 a, uint16 r18) { // 0xA9C465 + return sub_A9C46C(r18 + 64, a); } uint16 sub_A9C46C(uint16 a, uint16 j) { // 0xA9C46C @@ -3440,7 +3330,7 @@ void Enemy_IncreaseYpos(uint16 k, uint16 a) { // 0xA9C4A9 } void Samus_DecrementAmmoDueToRainbowBeam(void) { // 0xA9C4C4 - if ((enemy_damage_routine_exec_count & 3) == 0 && samus_missiles) { + if ((random_enemy_counter & 3) == 0 && samus_missiles) { uint16 v0 = samus_missiles - g_word_A9C544; if (sign16(samus_missiles - g_word_A9C544 - 1)) { if (hud_item_index == 1) @@ -3450,7 +3340,7 @@ void Samus_DecrementAmmoDueToRainbowBeam(void) { // 0xA9C4C4 } samus_missiles = v0; } - if ((enemy_damage_routine_exec_count & 3) == 0 && samus_super_missiles) { + if ((random_enemy_counter & 3) == 0 && samus_super_missiles) { uint16 v1 = samus_super_missiles - g_word_A9C544; if (sign16(samus_super_missiles - g_word_A9C544 - 1)) { if (hud_item_index == 2) @@ -3473,8 +3363,8 @@ void Samus_DecrementAmmoDueToRainbowBeam(void) { // 0xA9C4C4 } void Samus_PlayGainingLosingHealthSfx(void) { // 0xA9C546 - if (!sign16(samus_health - 81) && (enemy_damage_routine_exec_count & 7) == 0) - QueueSfx3_Max3(0x2Du); + if (!sign16(samus_health - 81) && (random_enemy_counter & 7) == 0) + QueueSfx3_Max3(0x2D); } void Samus_DamageDueToShitroid(void) { // 0xA9C560 @@ -3513,21 +3403,20 @@ uint8 ProcessSpriteTilesTransfers(uint8 db, uint16 k) { // 0xA9C5BE VramWriteEntry *v7; Enemy_MotherBrain *E = Get_MotherBrain(0); - uint16 mbn_var_22 = E->mbn_var_22; - if (!mbn_var_22) - mbn_var_22 = k; - uint16 v3 = mbn_var_22; + uint16 src = E->mbn_var_22; + if (!src) + src = k; uint16 v4 = vram_write_queue_tail; - const uint8 *v5 = RomPtrWithBank(db, mbn_var_22); + const uint8 *v5 = RomPtrWithBank(db, src); uint16 v6 = GET_WORD(v5); - if (GET_WORD(v5)) { + if (v6) { v7 = gVramWriteEntry(vram_write_queue_tail); v7->size = v6; *(VoidP *)((uint8 *)&v7->src.addr + 1) = GET_WORD(v5 + 3); v7->src.addr = GET_WORD(v5 + 2); v7->vram_dst = GET_WORD(v5 + 5); vram_write_queue_tail = v4 + 7; - E->mbn_var_22 = v3 + 7; + E->mbn_var_22 = src + 7; v6 = *(uint16 *)RomPtrWithBank(db, E->mbn_var_22); if (v6) return 0; @@ -3701,8 +3590,8 @@ void ShitroidInCutscene_Main(void) { // 0xA9C779 MoveEnemyWithVelocity(); ShitroidInCutscene_Flashing(cur_enemy_index); ShitroidInCutscene_HandleHealthBasedPalette(cur_enemy_index); - R18_ = Get_ShitdroidInCutscene(cur_enemy_index)->sice_var_0F; - CallShitroidCutsceneFunc0F(R18_ | 0xA90000); + uint16 r18 = Get_ShitdroidInCutscene(cur_enemy_index)->sice_var_0F; + CallShitroidCutsceneFunc0F(r18 | 0xA90000); } void ShitroidInCutscene_Flashing(uint16 k) { // 0xA9C79C @@ -3724,7 +3613,7 @@ void ShitroidInCutscene_HandleCry(void) { // 0xA9C7B7 Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(0); if (E->sice_var_14) { E->sice_var_14 = 0; - QueueSfx2_Max6(0x72u); + QueueSfx2_Max6(0x72); } } @@ -3740,10 +3629,7 @@ void ShitroidInCutscene_DashOntoScreen(uint16 k) { // 0xA9C7CC } void ShitroidInCutscene_CurveTowardsBrain(uint16 k) { // 0xA9C7EC - R18_ = -384; - R20_ = -20480; - R22_ = 2560; - ShitroidInCutscene_UpdateSpeedAndAngle(k); + ShitroidInCutscene_UpdateSpeedAndAngle(k, -384, -20480, 2560); Enemy_ShitroidInCutscene *E = Get_ShitroidInCutscene(k); if ((--E->sice_var_F & 0x8000) != 0) { E->sice_var_A = FUNC16(ShitroidInCutscene_GetIntoFace); @@ -3753,46 +3639,34 @@ void ShitroidInCutscene_CurveTowardsBrain(uint16 k) { // 0xA9C7EC void ShitroidInCutscene_GetIntoFace(uint16 k) { // 0xA9C811 bool v3; // sf - - R18_ = -1536; - R20_ = -32256; - R22_ = 3584; - ShitroidInCutscene_UpdateSpeedAndAngle(k); + ShitroidInCutscene_UpdateSpeedAndAngle(k, -1536, -32256, 3584); Enemy_ShitroidInCutscene *E = Get_ShitroidInCutscene(0x40); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - R22_ = 4; - R24_ = 4; - if (!(Shitroid_Func_2(k) & 1) + Rect16U rect = { E->base.x_pos, E->base.y_pos, 4, 4 }; + if (!Shitroid_Func_2(k, rect) || (E = Get_ShitroidInCutscene(k), v3 = (int16)(E->sice_var_F - 1) < 0, --E->sice_var_F, v3)) { Get_ShitroidInCutscene(k)->sice_var_A = FUNC16(ShitroidInCutscene_LatchOntoBrain); - SomeMotherBrainScripts(1u); + SomeMotherBrainScripts(1); } } void ShitroidInCutscene_LatchOntoBrain(uint16 k) { // 0xA9C851 Enemy_ShitroidInCutscene *E = Get_ShitroidInCutscene(0x40); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos - 24; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0); - R22_ = 8; - R24_ = 8; - if (!(Shitroid_Func_2(k) & 1)) + Rect16U rect = { E->base.x_pos, E->base.y_pos - 24, 8, 8 }; + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0, rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) Get_ShitroidInCutscene(k)->sice_var_A = FUNC16(ShitroidInCutscene_SetMotherBrainToStumbleBack); } void ShitroidInCutscene_SetMotherBrainToStumbleBack(uint16 k) { // 0xA9C879 Enemy_ShitroidInCutscene *E = Get_ShitroidInCutscene(0); - MotherBrain_MakeWalkBackwards(E->base.x_pos - 1, 2u); + MotherBrain_MakeWalkBackwards(E->base.x_pos - 1, 2); Get_ShitroidInCutscene(k)->sice_var_A = FUNC16(ShitroidInCutscene_ActivateRainbowBeam); ShitroidInCutscene_ActivateRainbowBeam(k); } void ShitroidInCutscene_ActivateRainbowBeam(uint16 k) { // 0xA9C889 Enemy_ShitroidInCutscene *E1 = Get_ShitdroidInCutscene(0x40); - R18_ = E1->base.x_pos; - R20_ = E1->base.y_pos - 24; - if (Shitroid_AccelerateTowardsPoint(k, 0x200) & 1) { + if (Shitroid_AccelerateTowardsPoint(k, 0x200, E1->base.x_pos, E1->base.y_pos - 24) & 1) { Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); E->sice_var_B = 0; E->sice_var_C = 0; @@ -3812,7 +3686,7 @@ void ShitroidInCutscene_BrainTurnsToCorpse(uint16 k) { // 0xA9C8E2 Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); Enemy_ShitroidInCutscene *E1 = Get_ShitdroidInCutscene(0x40); - int v2 = (uint8)(E->base.frame_counter & 6) >> 1; + int v2 = (E->base.frame_counter & 6) >> 1; E->base.x_pos = E1->base.x_pos + g_word_A993BB[v2]; E->base.y_pos = E1->base.y_pos + g_word_A993C3[v2] - 24; if (Get_ShitdroidInCutscene(0)->sice_var_1F) { @@ -3846,39 +3720,32 @@ void ShitroidInCutscene_LetGoAndSpawnDust(uint16 k) { // 0xA9C94B } void ShitroidInCutscene_MoveUpToCeiling(uint16 k) { // 0xA9C959 - R18_ = Get_ShitdroidInCutscene(0x40)->base.x_pos; - R20_ = 0; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0); - R22_ = 4; - R24_ = 4; - if (!(Shitroid_Func_2(k) & 1)) { - SomeMotherBrainScripts(4u); + Rect16U rect = { Get_ShitdroidInCutscene(0x40)->base.x_pos, 0, 4, 4 }; + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0, rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) { + SomeMotherBrainScripts(4); Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); E->sice_var_A = FUNC16(ShitroidInCutscene_MoveToSamus); E->sice_var_0E = addr_stru_A9CA24; } } -void ShitroidInCutscene_SpawnThreeDustClouds(void) { // 0xA9C98C - R20_ = -8; - ShitroidInCutscene_SpawnOneDustCloudAt(0xFFF0); - R20_ = -16; - ShitroidInCutscene_SpawnOneDustCloudAt(0); - R20_ = -8; - ShitroidInCutscene_SpawnOneDustCloudAt(0x10); -} - -void ShitroidInCutscene_SpawnOneDustCloudAt(uint16 a) { // 0xA9C9AA +void ShitroidInCutscene_SpawnOneDustCloudAt(uint16 xd, uint16 yd) { // 0xA9C9AA Enemy_ShitroidInCutscene *E = Get_ShitroidInCutscene(0x40); - R18_ = E->base.x_pos + a; - R20_ += E->base.y_pos; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); + eproj_spawn_pt = (Point16U){ E->base.x_pos + xd, E->base.y_pos + yd }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); } -void CallShitroidMoveFunc(uint32 ea, uint16 k, uint16 j) { +void ShitroidInCutscene_SpawnThreeDustClouds(void) { // 0xA9C98C + ShitroidInCutscene_SpawnOneDustCloudAt(-16, -8); + ShitroidInCutscene_SpawnOneDustCloudAt(0, -16); + ShitroidInCutscene_SpawnOneDustCloudAt(16, -8); +} + +void CallShitroidMoveFunc(uint32 ea, uint16 k, uint16 j, uint16 r18, uint16 r20) { switch (ea) { - case fnShitroid_GraduallyAccelerateTowards0x8: Shitroid_GraduallyAccelerateTowards0x8(k, j); return; - case fnShitroid_GraduallyAccelerateTowards0x10: Shitroid_GraduallyAccelerateTowards0x10(k, j); return; + case fnShitroid_GraduallyAccelerateTowards0x8: Shitroid_GraduallyAccelerateTowards0x8(k, j, r18, r20); return; + case fnShitroid_GraduallyAccelerateTowards0x10: Shitroid_GraduallyAccelerateTowards0x10(k, j, r18, r20); return; default: Unreachable(); } } @@ -3889,17 +3756,13 @@ void ShitroidInCutscene_MoveToSamus(uint16 k) { // 0xA9C9C3 Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); E->sice_var_04 = 0; E->sice_var_09 = 1; - if ((random_number & 0xFFFu) >= 0xFA0) - QueueSfx2_Max6(0x52u); + if ((random_number & 0xFFF) >= 0xFA0) + QueueSfx2_Max6(0x52); uint16 sice_var_0E = E->sice_var_0E; const uint16 *v3 = (const uint16 *)RomPtr_A9(sice_var_0E); - R18_ = *v3; - R20_ = v3[1]; - R22_ = v3[3]; - CallShitroidMoveFunc(R22_ | 0xA90000, k, v3[2]); - R22_ = 4; - R24_ = 4; - if (!(Shitroid_Func_2(k) & 1)) { + Rect16U rect = { v3[0], v3[1], 4, 4 }; + CallShitroidMoveFunc(v3[3] | 0xA90000, k, v3[2], rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) { v4 = *((uint16 *)RomPtr_A9(sice_var_0E) + 4); if (v4 < 0) { E->sice_var_A = v4; @@ -3910,16 +3773,14 @@ void ShitroidInCutscene_MoveToSamus(uint16 k) { // 0xA9C9C3 } void ShitroidInCutscene_LatchOntoSamus(uint16 k) { // 0xA9CA66 - R18_ = samus_x_pos; - R20_ = samus_y_pos - 20; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0); + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0, samus_x_pos, samus_y_pos - 20); } void ShitroidInCutscene_HealSamusToFullHealth(uint16 k) { // 0xA9CA7A Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); E->sice_var_04 = 0; ShitroidInCutscene_HandleCry(); - int v2 = (uint8)(E->base.frame_counter & 6) >> 1; + int v2 = (E->base.frame_counter & 6) >> 1; E->base.x_pos = samus_x_pos + g_word_A993BB[v2]; E->base.y_pos = samus_y_pos + g_word_A993C3[v2] - 20; if (!(Samus_HealDueToShitroid() & 1)) { @@ -3934,7 +3795,7 @@ void ShitroidInCutscene_IdleUntilToNoHealth(uint16 k) { // 0xA9CABD Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); uint16 sice_var_06 = E->sice_var_06; if (sice_var_06) { - int v3 = (uint8)(sice_var_06 & 6) >> 1; + int v3 = (sice_var_06 & 6) >> 1; E->base.x_pos = samus_x_pos + 2 * g_word_A993BB[v3]; E->base.y_pos = samus_y_pos + 2 * g_word_A993C3[v3] - 20; } @@ -3950,7 +3811,7 @@ void ShitroidInCutscene_IdleUntilToNoHealth(uint16 k) { // 0xA9CABD } void ShitroidInCutscene_ReleaseSamus(uint16 k) { // 0xA9CB13 - QueueSfx2_Max6(0x72u); + QueueSfx2_Max6(0x72); Get_ShitdroidInCutscene(0x40)->sice_var_0B = 1; Get_ShitdroidInCutscene(k)->sice_var_A = FUNC16(ShitroidInCutscene_StareDownMotherBrain); Get_ShitdroidInCutscene(0)->sice_var_A = FUNC16(MotherBrain_Phase2_PrepareForFinalShitroid); @@ -3958,32 +3819,23 @@ void ShitroidInCutscene_ReleaseSamus(uint16 k) { // 0xA9CB13 } void ShitroidInCutscene_StareDownMotherBrain(uint16 k) { // 0xA9CB2D - R18_ = samus_x_pos - 4; - R20_ = 96; - Shitroid_GraduallyAccelerateTowards0x10(k, 0); - R22_ = 4; - R24_ = 4; - if (!(Shitroid_Func_2(k) & 1)) + Rect16U rect = { samus_x_pos - 4, 96, 4, 4 }; + Shitroid_GraduallyAccelerateTowards0x10(k, 0, rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) Get_ShitroidInCutscene(k)->sice_var_A = FUNC16(ShitroidInCutscene_FlyOffScreen); } void ShitroidInCutscene_FlyOffScreen(uint16 k) { // 0xA9CB56 - R18_ = 272; - R20_ = 64; - Shitroid_GraduallyAccelerateTowards0x10(k, 0); - R22_ = 4; - R24_ = 4; - if (!(Shitroid_Func_2(k) & 1)) + Rect16U rect = { 272, 64, 4, 4 }; + Shitroid_GraduallyAccelerateTowards0x10(k, 0, rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) Get_ShitroidInCutscene(k)->sice_var_A = FUNC16(ShitroidInCutscene_MoveToFinalChargeStart); } void ShitroidInCutscene_MoveToFinalChargeStart(uint16 k) { // 0xA9CB7B - R18_ = 305; - R20_ = 160; - Shitroid_GraduallyAccelerateTowards0x10(k, 0); - R22_ = 4; - R24_ = 4; - if (!(Shitroid_Func_2(k) & 1)) { + Rect16U rect = { 305, 160, 4, 4 }; + Shitroid_GraduallyAccelerateTowards0x10(k, 0, rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) { Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); E->base.health = 79; Get_ShitdroidInCutscene(0x40)->sice_var_0B = 0; @@ -3993,25 +3845,20 @@ void ShitroidInCutscene_MoveToFinalChargeStart(uint16 k) { // 0xA9CB7B } void ShitroidInCutscene_InitiateFinalCharge(uint16 k) { // 0xA9CBB3 - R18_ = 290; - R20_ = 128; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xA); - R22_ = 4; - R24_ = 4; - if (!(Shitroid_Func_2(k) & 1)) + Rect16U rect = { 290, 128, 4, 4 }; + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xA, rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) Get_ShitroidInCutscene(k)->sice_var_A = FUNC16(ShitroidInCutscene_FinalCharge); } void ShitroidInCutscene_FinalCharge(uint16 k) { // 0xA9CBD8 Enemy_ShitroidInCutscene *E1 = Get_ShitdroidInCutscene(0x40); - R18_ = E1->base.x_pos; - R20_ = E1->base.y_pos - 32; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xC); + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xC, E1->base.x_pos, E1->base.y_pos - 32); Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); if (!E->base.health) { E->sice_var_0F = FUNC16(nullsub_338); E->base.vram_tiles_index = 4256; - QueueSfx3_Max6(0x19u); + QueueSfx3_Max6(0x19); TurnOffLightsForShitroidDeath(); Enemy_SetInstrList(k, addr_kShitroid_Ilist_CFCE); E->sice_var_B = 0; @@ -4041,8 +3888,8 @@ void ShitroidInCutscene_ShitroidFinalBelow(uint16 k) { // 0xA9CC3E void ShitroidInCutscene_PlaySamusTheme(uint16 k) { // 0xA9CC60 Enemy_ShitroidInCutscene *E = Get_ShitroidInCutscene(k); if ((--E->sice_var_F & 0x8000) != 0) { - QueueMusic_Delayed8(0xFF48u); - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(0xFF48); + QueueMusic_Delayed8(5); E->sice_var_A = FUNC16(ShitroidInCutscene_PrepareSamusHyperbeam); E->sice_var_F = 12; ShitroidInCutscene_PrepareSamusHyperbeam(k); @@ -4052,7 +3899,7 @@ void ShitroidInCutscene_PlaySamusTheme(uint16 k) { // 0xA9CC60 void ShitroidInCutscene_PrepareSamusHyperbeam(uint16 k) { // 0xA9CC7F Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); if ((--E->sice_var_F & 0x8000) != 0) { - CallSomeSamusCode(0x19u); + CallSomeSamusCode(0x19); Get_ShitdroidInCutscene(0x40)->sice_var_16 = FUNC16(SamusRainbowPaletteFunc_ActivateWhenEnemyLow); E->sice_var_A = FUNC16(ShitroidInCutscene_DeathSequence); } @@ -4098,8 +3945,8 @@ void ShitroidInCutscene_FinishCutscene(uint16 k) { // 0xA9CCF0 E->sice_var_37 = v2; if (MotherBrain_Phase3_TurnLightsBackOn(v2 - 1) & 1) { E->sice_var_A = FUNC16(MotherBrain_Phase3_Recover_MakeDistance); - CallSomeSamusCode(0x17u); - SomeMotherBrainScripts(3u); + CallSomeSamusCode(0x17); + SomeMotherBrainScripts(3); Get_ShitdroidInCutscene(k)->base.properties |= kEnemyProps_Deleted; Get_ShitdroidInCutscene(0x40)->sice_var_0A = 0; } @@ -4114,13 +3961,13 @@ void CallSamusRainbowPaletteFunc(uint32 ea, uint16 k) { } void HandleSamusRainbowPaletteAnimation(uint16 k) { // 0xA9CD27 - R18_ = Get_ShitdroidInCutscene(0x40)->sice_var_16; - CallSamusRainbowPaletteFunc(R18_ | 0xA90000, k); + uint16 r18 = Get_ShitdroidInCutscene(0x40)->sice_var_16; + CallSamusRainbowPaletteFunc(r18 | 0xA90000, k); } void SamusRainbowPaletteFunc_ActivateWhenEnemyLow(uint16 k) { // 0xA9CD30 if ((int16)(Get_ShitdroidInCutscene(k)->base.y_pos + 16 - samus_y_pos) >= 0) { - CallSomeSamusCode(0x16u); + CallSomeSamusCode(0x16); Get_ShitdroidInCutscene(0x40)->sice_var_16 = FUNC16(SamusRainbowPaletteFunc_GraduallySlowDown); } } @@ -4169,10 +4016,9 @@ void ShitroidInCutscene_HandleShitroidDeathExplosions(uint16 k) { // 0xA9CDB1 v3 = 0; E->sice_var_07 = v3; int v4 = (uint16)(4 * v3) >> 1; - R18_ = E->base.x_pos + g_word_A9CDFC[v4]; - R20_ = E->base.y_pos + g_word_A9CDFC[v4 + 1]; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3u); - QueueSfx3_Max3(0x13u); + eproj_spawn_pt = (Point16U){ E->base.x_pos + g_word_A9CDFC[v4], E->base.y_pos + g_word_A9CDFC[v4 + 1] }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 3); + QueueSfx3_Max3(0x13); } else { E->sice_var_08 = v2; } @@ -4224,7 +4070,7 @@ void ShitroidInCutscene_HandleHealthBasedPalette(uint16 k) { // 0xA9CE69 uint16 v4 = kShitroid_HealthBasedPalettes_Shell[v3 >> 1]; WriteColorsToPalette(0x1E2, 0xad, v4, 4); WriteColorsToPalette(0x1F4, 0xad, v4 + 8, 5); - WriteColorsToPalette(0x1EA, 0xad, kShitroid_HealthBasedPalettes_Innards[v5 >> 1], 5u); + WriteColorsToPalette(0x1EA, 0xad, kShitroid_HealthBasedPalettes_Innards[v5 >> 1], 5); } } } @@ -4232,7 +4078,7 @@ void ShitroidInCutscene_HandleHealthBasedPalette(uint16 k) { // 0xA9CE69 void ShitroidInCutscene_Shake(uint16 k) { // 0xA9CEDB Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); --E->sice_var_C; - int v2 = (uint8)(E->base.frame_counter & 6) >> 1; + int v2 = (E->base.frame_counter & 6) >> 1; E->base.x_pos = E->sice_var_10 + g_word_A993BB[v2]; E->base.y_pos = E->sice_var_11 + g_word_A993C3[v2]; } @@ -4240,9 +4086,7 @@ void ShitroidInCutscene_Shake(uint16 k) { // 0xA9CEDB void ShitroidInCutscene_Touch(void) { // 0xA9CF03 Enemy_ShitroidInCutscene *E = Get_ShitroidInCutscene(cur_enemy_index); if (E->sice_var_A == FUNC16(ShitroidInCutscene_LatchOntoSamus)) { - R18_ = samus_x_pos; - R20_ = samus_y_pos - 20; - if (Shitroid_AccelerateTowardsPoint(cur_enemy_index, 0x10) & 1) { + if (Shitroid_AccelerateTowardsPoint(cur_enemy_index, 0x10, samus_x_pos, samus_y_pos - 20) & 1) { E->sice_var_B = 0; E->sice_var_C = 0; E->sice_var_A = FUNC16(ShitroidInCutscene_HealSamusToFullHealth); @@ -4250,36 +4094,36 @@ void ShitroidInCutscene_Touch(void) { // 0xA9CF03 } } -void ShitroidInCutscene_UpdateSpeedAndAngle(uint16 k) { // 0xA9CF31 +void ShitroidInCutscene_UpdateSpeedAndAngle(uint16 k, uint16 r18, uint16 r20, uint16 r22) { // 0xA9CF31 Enemy_ShitroidInCutscene *E = Get_ShitdroidInCutscene(k); - if (R22_ != E->sice_var_0B) { - if ((int16)(R22_ - E->sice_var_0B) >= 0) { + if (r22 != E->sice_var_0B) { + if ((int16)(r22 - E->sice_var_0B) >= 0) { uint16 v3 = E->sice_var_0B + 32; - if (!sign16(v3 - R22_)) - v3 = R22_; + if (!sign16(v3 - r22)) + v3 = r22; E->sice_var_0B = v3; } else { uint16 v2 = E->sice_var_0B - 32; - if (sign16(v2 - R22_)) - v2 = R22_; + if (sign16(v2 - r22)) + v2 = r22; E->sice_var_0B = v2; } } uint16 v4; - if ((R18_ & 0x8000) != 0) { - v4 = E->sice_var_0A + R18_; - if (sign16(v4 - R20_)) + if ((r18 & 0x8000) != 0) { + v4 = E->sice_var_0A + r18; + if (sign16(v4 - r20)) LABEL_13: - v4 = R20_; + v4 = r20; } else { - v4 = E->sice_var_0A + R18_; - if (!sign16(v4 - R20_)) + v4 = E->sice_var_0A + r18; + if (!sign16(v4 - r20)) goto LABEL_13; } E->sice_var_0A = v4; - R18_ = HIBYTE(v4); - E->sice_var_B = Math_MultBySin(E->sice_var_0B); - E->sice_var_C = Math_MultByCos(E->sice_var_0B); + r18 = HIBYTE(v4); + E->sice_var_B = Math_MultBySin(E->sice_var_0B, r18); + E->sice_var_C = Math_MultByCos(E->sice_var_0B, r18); } const uint16 *Shitroid_Instr_1(uint16 k, const uint16 *jp) { // 0xA9CFB4 @@ -4342,7 +4186,7 @@ uint16 HandleMotherBrainInstructionList(uint16 a) { // 0xA9D192 if ((st->ip & 0x8000) == 0) return 0; uint16 v2 = st->ip; - const uint16 *v3 = (uint16 *)RomPtr_A6(v2); + const uint16 *v3 = (uint16 *)RomPtr_A9(v2); if (sign16(v3[0])) goto LABEL_8; if (st->timer != v3[0]) { @@ -4351,7 +4195,7 @@ uint16 HandleMotherBrainInstructionList(uint16 a) { // 0xA9D192 } v2 += 4; for (; ; ) { - v3 = (uint16 *)RomPtr_A6(v2); + v3 = (uint16 *)RomPtr_A9(v2); if (!sign16(v3[0])) break; LABEL_8: @@ -4394,40 +4238,37 @@ void MotherBrain_HandleBrainPal(void) { // 0xA9D206 if (mbn_var_D_high) { HIBYTE(E->mbn_var_D) = mbn_var_D_high - 1; } else { - R18_ = g_off_A9D260[HIBYTE(E->mbn_var_E) >> 1]; + uint16 r18 = g_off_A9D260[HIBYTE(E->mbn_var_E) >> 1]; HIBYTE(E->mbn_var_D) = E->mbn_var_E; mbn_var_D = E->mbn_var_D; - if (mbn_var_D - || Get_MotherBrain(0x40)->mbn_var_A == FUNC16(MotherBrainsBrain_SetupBrainAndNeckToDraw)) { + if (mbn_var_D || Get_MotherBrain(0x40)->mbn_var_A == FUNC16(MotherBrainsBrain_SetupBrainAndNeckToDraw)) { uint8 v4 = (mbn_var_D + 1) & 7; LOBYTE(E->mbn_var_D) = v4; uint16 v5 = 290; if (E->mbn_var_0D != 512) v5 = 482; - WriteColorsToPalette(v5, 0xa9, R18_ + 8 * v4, 3u); + WriteColorsToPalette(v5, 0xa9, r18 + 8 * v4, 3); } } } } void WriteColorsToPalette(uint16 k, uint8 db, uint16 j, uint16 a) { // 0xA9D2E4 - R18_ = a; + int n = a; do { palette_buffer[k >> 1] = *(uint16 *)RomPtrWithBank(db, j); k += 2; j += 2; - --R18_; - } while (R18_); + } while (--n); } void WriteColorsToTargetPalette(uint8 db, uint16 k, uint16 j, uint16 a) { // 0xA9D2F6 - R18_ = a; + int n = a; do { target_palettes[k >> 1] = *(uint16 *)RomPtrWithBank(db, j); k += 2; j += 2; - --R18_; - } while (R18_); + } while (--n); } void DeadTorizo_Init(void) { // 0xA9D308 @@ -4435,7 +4276,7 @@ void DeadTorizo_Init(void) { // 0xA9D308 tilemap_stuff[i >> 1] = 0; Enemy_DeadTorizo *E = Get_DeadTorizo(0); E->dto_var_A = FUNC16(DeadTorizo_WaitForSamusColl); - E->base.properties |= 0xA000u; + E->base.properties |= 0xA000; E->base.current_instruction = addr_kDeadTorizo_Ilist_D6DC; E->base.instruction_timer = 1; E->base.timer = 0; @@ -4470,10 +4311,7 @@ void DeadTorizo_Main(void) { // 0xA9D368 } void DeadTorizo_MainGfxHook(void) { // 0xA9D39A - R22_ = 0; - R18_ = 296; - R20_ = 187; - MotherBrain_AddSpritemapToOam(addr_kDeadTorizo_Sprmap_D761); + MotherBrain_AddSpritemapToOam(addr_kDeadTorizo_Sprmap_D761, 296, 187, 0); } void DeadTorizo_WaitForSamusColl(uint16 k) { // 0xA9D3AD @@ -4500,7 +4338,7 @@ void DeadTorizo_Rotting(void) { // 0xA9D3E6 Enemy_DeadTorizo *E = Get_DeadTorizo(0); uint16 v1 = E->dto_var_03 + 1; E->dto_var_03 = v1; - if (v1 >= 0xFu) { + if (v1 >= 0xF) { E->dto_var_03 = 0; uint16 dto_var_02 = E->dto_var_02; if (dto_var_02) { @@ -4528,45 +4366,40 @@ void DeadTorizo_Shot(void) { // 0xA9D433 uint8 DeadTorizo_Func_0(void) { // 0xA9D443 int16 v5; uint16 v3, v4; - Enemy_DeadTorizo *E = Get_DeadTorizo(0); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; - const uint16 *v1 = (const uint16 *)RomPtr_A9(addr_kDeadTorizo_Hitbox_D77C); - if (!*v1) - return 0; - int R22 = *v1; - for (int i = addr_kDeadTorizo_Hitbox_D77C + 2; ; i += 8) { - const uint8 *t = RomPtr_A9(i); - if ((int16)(samus_y_pos - R20_) >= 0) { - R24_ = samus_y_pos - R20_; - v3 = *((uint16 *)t + 3); + uint16 r18 = E->base.x_pos, r20 = E->base.y_pos; + const uint8 *p = RomPtr_A9(addr_kDeadTorizo_Hitbox_D77C); + int R22 = GET_WORD(p); + uint16 R24; + for (p += 2; R22; p += 8, R22--) { + if ((int16)(samus_y_pos - r20) >= 0) { + R24 = samus_y_pos - r20; + v3 = GET_WORD(p + 6); } else { - R24_ = R20_ - samus_y_pos; - v3 = *((uint16 *)t + 1); + R24 = r20 - samus_y_pos; + v3 = GET_WORD(p + 2); } - if ((int16)(samus_y_radius + abs16(v3) - R24_) >= 0) { - if ((int16)(samus_x_pos - R18_) >= 0) { - R24_ = samus_x_pos - R18_; - v4 = *((uint16 *)t + 2); + if ((int16)(samus_y_radius + abs16(v3) - R24) >= 0) { + if ((int16)(samus_x_pos - r18) >= 0) { + R24 = samus_x_pos - r18; + v4 = GET_WORD(p + 4); } else { - R24_ = R18_ - samus_x_pos; - v4 = *(uint16 *)t; + R24 = r18 - samus_x_pos; + v4 = GET_WORD(p); + } + v5 = samus_x_radius + abs16(v4) - R24; + if (v5 >= 0) { + if (sign16(v5 - 4)) + v5 = 4; + extra_samus_x_displacement = v5; + extra_samus_y_displacement = 4; + extra_samus_x_subdisplacement = 0; + extra_samus_y_subdisplacement = 0; + return 1; } - v5 = samus_x_radius + abs16(v4) - R24_; - if (v5 >= 0) - break; } - if (!--R22) - return 0; } - if (sign16(v5 - 4)) - v5 = 4; - extra_samus_x_displacement = v5; - extra_samus_y_displacement = 4; - extra_samus_x_subdisplacement = 0; - extra_samus_y_subdisplacement = 0; - return 1; + return 0; } void DeadTorizo_Func_1(void) { // 0xA9D4CF @@ -4610,10 +4443,9 @@ void DeadTorizo_Func_1(void) { // 0xA9D4CF } void DeadTorizo_CorpseRottingFinished(void) { // 0xA9D5BD - R18_ = (random_number & 0x1F) + 272; - R20_ = 188; + eproj_spawn_pt = (Point16U){ (random_number & 0x1F) + 272, 188 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0xA); - if ((enemy_damage_routine_exec_count & 7) == 0) + if ((random_enemy_counter & 7) == 0) QueueSfx2_Max6(0x10); } @@ -4645,8 +4477,6 @@ void DeadSidehopper_Init(void) { // 0xA9D7B6 if (dsr_parameter_1) { if (dsr_parameter_1 != 2) { Unreachable(); - while (1) - ; } DeadSidehopper_Init_1(); } else { @@ -4708,7 +4538,7 @@ void DeadSkree_Init(void) { // 0xA9D89F } void DeadSidehopper_Powerbomb(void) { // 0xA9D8CC - if (Get_DeadSidehopper(cur_enemy_index)->dsr_var_08 >= 8u) + if (Get_DeadSidehopper(cur_enemy_index)->dsr_var_08 >= 8) DeadSidehopper_Shot(); else DeadSidehopper_Main(); @@ -4759,7 +4589,7 @@ void DeadSidehopper_Alive_WaitForActivate(uint16 k) { // 0xA9D8E2 void DeadSidehopper_Activated(uint16 k) { // 0xA9D8F1 if (DeadMonsters_Func_3(k) & 1) { Enemy_DeadSidehopper *E = Get_DeadSidehopper(k); - E->dsr_var_06 = ((uint8)E->dsr_var_06 + 1) & 3; + E->dsr_var_06 = (E->dsr_var_06 + 1) & 3; Enemy_SetInstrList(k, addr_kDeadMonsters_Ilist_ECAC); E->dsr_var_A = FUNC16(nullsub_362); } @@ -4779,7 +4609,7 @@ void DeadMonsters_Func_2(uint16 k) { // 0xA9D91D } else { E->dms_var_A = FUNC16(DeadSidehopper_Activated); Enemy_SetInstrList(k, addr_kDeadMonsters_Ilist_ECE3); - int v3 = (uint16)(2 * E->dms_var_06) >> 1; + int v3 = E->dms_var_06; E->dms_var_0B = g_word_A9D951[v3]; E->dms_var_0A = g_word_A9D959[v3]; } @@ -4794,7 +4624,6 @@ uint8 DeadMonsters_Func_3(uint16 k) { // 0xA9D961 v2 = 128; uint16 v3 = E->dms_var_0B + v2; E->dms_var_0B = v3; - R18_ = v3; if (sign16(E->base.x_pos - 544)) { int full = HIBYTE(E->base.y_subpos) + LOBYTE(v3); HIBYTE(E->base.y_subpos) = full; @@ -4802,23 +4631,18 @@ uint8 DeadMonsters_Func_3(uint16 k) { // 0xA9D961 E->base.y_pos = v12; return sign16(v12 - 184) == 0; } else { - R18_ = v3 << 8; - R20_ = (int8)(v3 >> 8); - return Enemy_MoveDown(k); + return Enemy_MoveDown(k, INT16_SHL8(v3)); } } void DeadMonsters_Func_4(uint16 k, uint16 a) { // 0xA9D9C7 - R18_ = a; Enemy_DeadMonsters *E = Get_DeadMonsters(k); if (sign16(E->base.x_pos - 544)) { int full = HIBYTE(E->base.x_subpos) + LOBYTE(a); HIBYTE(E->base.x_subpos) = full; E->base.x_pos += (int8)(a >> 8) + (full >> 8); } else { - R18_ = a << 8; - R20_ = (int8)(a >> 8); - Enemy_MoveRight_IgnoreSlopes(k); + Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(a)); } } @@ -4826,19 +4650,19 @@ void DeadMonsters_Func_5(uint16 k) { // 0xA9DA08 Enemy_DeadMonsters *E = Get_DeadMonsters(k); uint16 v2 = E->dms_var_07 + 1; E->dms_var_07 = v2; - if (v2 >= 8u) { + if (v2 >= 8) { E->dms_var_07 = 0; WriteColorsToPalette( - 0x122u, + 0x122, 0xa9, 32 * (E->dms_var_08 - 1) - 0x1434, - 0xFu); + 0xF); uint16 v3 = cur_enemy_index; uint16 v5 = E->dms_var_08 + 1; E->dms_var_08 = v5; - if (v5 >= 8u) { + if (v5 >= 8) { Enemy_SetInstrList(v3, addr_kDeadMonsters_Ilist_ECE9); E->dms_var_A = FUNC16(DeadSidehopper_WaitForSamusColl); - E->base.properties |= 0x8000u; + E->base.properties |= 0x8000; E->base.y_height = 12; } } @@ -4961,34 +4785,33 @@ LABEL_12: if (v7) { v8 = v7 - 1; v5[1] = v8; - if ((uint16)v8 < 4u) { + if ((uint16)v8 < 4) { E0 = Get_DeadMonsters(0); - R18_ = E0->dms_var_42; + uint16 r18 = E0->dms_var_42; if (v15 >= E0->dms_var_47) - R18_ = E0->dms_var_43; + r18 = E0->dms_var_43; LongPtr r20; r20.addr = E0->dms_var_44; r20.bank = 169; - CopyMoveCorpseRottingRotEntry(r20, *v6); + CopyMoveCorpseRottingRotEntry(r20, *v6, r18); } goto LABEL_12; } Enemy_DeadMonsters *E = Get_DeadMonsters(0); - R18_ = E->dms_var_43; + uint16 r18 = E->dms_var_43; LongPtr r20; r20.addr = E->dms_var_44; r20.bank = 169; uint16 *v11 = (uint16 *)(g_ram + dms_var_52); - CopyMoveCorpseRottingRotEntry(r20, *v11); + CopyMoveCorpseRottingRotEntry(r20, *v11, r18); uint16 v12 = *v11 + 2; if (v12 < E->dms_var_46) { *(uint16 *)v11 = v12; goto LABEL_12; } - R18_ = E->dms_var_49; - CallCorpseRottingFinish(R18_ | 0xA90000); + CallCorpseRottingFinish(E->dms_var_49 | 0xA90000); if (v15 < Get_DeadMonsters(0)->dms_var_46) { *(uint16 *)v11 = -1; goto LABEL_12; @@ -4996,37 +4819,36 @@ LABEL_12: return 0; } -void CopyMoveCorpseRottingRotEntry(LongPtr r20, uint16 a) { // 0xA9DBE0 +void CopyMoveCorpseRottingRotEntry(LongPtr r20, uint16 a, uint16 r18) { // 0xA9DBE0 Enemy_DeadMonsters *E = Get_DeadMonsters(0); E->dms_var_41 = a; uint16 v1 = (uint16)(a & 0xFFF8) >> 2; uint16 v2 = a & 7; uint16 v6 = IndirReadWord(r20, v1) + 2 * v2; - if (v2 >= 6u) { - CallCorpseRottingMove(R18_ | 0xA90000, E->dms_var_48 + v6, v6); + if (v2 >= 6) { + CallCorpseRottingMove(r18 | 0xA90000, E->dms_var_48 + v6, v6); } else { - CallCorpseRottingMove(R18_ | 0xA90000, v6, v6); + CallCorpseRottingMove(r18 | 0xA90000, v6, v6); } } void CorpseRottingRotEntryFinishedHook(void) { // 0xA9DC08 EnemyData *v0 = gEnemyData(cur_enemy_index); - R18_ = v0->x_pos + (random_number & 0x1A) - 14; - R20_ = v0->y_pos + 16; + eproj_spawn_pt = (Point16U){ v0->x_pos + (random_number & 0x1A) - 14, v0->y_pos + 16 }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0xA); - if ((enemy_damage_routine_exec_count & 7) == 0) + if ((random_enemy_counter & 7) == 0) QueueSfx2_Max3(0x10); } void InitializeCorpseRottingDataTable(uint16 *table, uint16 a) { // 0xA9DC40 int16 v2; v2 = a - 1; - R18_ = 0; + uint16 r18 = 0; do { table[0] = v2; - table[1] = R18_; + table[1] = r18; table += 2; - R18_ += 2; + r18 += 2; --v2; } while (v2 >= 0); } @@ -5048,8 +4870,7 @@ void InitializeEnemyCorpseRotting(uint16 k, uint16 j) { // 0xA9DC5F E->dms_var_58 = v6; E->dms_var_59 = v6 - 1; InitializeCorpseRottingDataTable((uint16*)(g_ram + *v5), v5[4]); - R18_ = v5[5]; - CallCorpseRottingInit(R18_ | 0xA90000); + CallCorpseRottingInit(v5[5] | 0xA90000); } void ProcessCorpseRottingVramTransfers(uint16 k) { // 0xA9DCB9 @@ -5099,7 +4920,7 @@ void DeadSkree_Shot(void) { // 0xA9DD18 void DeadSidehopper_Shot(void) { // 0xA9DD1D Enemy_DeadSidehopper *E = Get_DeadSidehopper(cur_enemy_index); - if ((E->base.properties & kEnemyProps_Tangible) != 0 || E->dsr_var_08 < 8u) + if ((E->base.properties & kEnemyProps_Tangible) != 0 || E->dsr_var_08 < 8) ; else DeadSidehopper_DD31(); @@ -5116,7 +4937,7 @@ void DeadSidehopper_DD34(uint16 a) { // 0xA9DD34 } void DeadSidehopper_Touch(void) { // 0xA9DD44 - if (Get_DeadSidehopper(cur_enemy_index)->dsr_var_08 < 8u) + if (Get_DeadSidehopper(cur_enemy_index)->dsr_var_08 < 8) NormalEnemyTouchAiSkipDeathAnim_CurEnemy(); else DeadSidehopper_DD31(); @@ -5236,7 +5057,7 @@ void Torizo_CorpseRottingMoveFunc(uint16 j, uint16 k) { // 0xA9E272 tilemap_stuff[v5] = 0; tilemap_stuff[v5 + 8] = 0; } - if (E->dms_var_41 >= 0x48u) { + if (E->dms_var_41 >= 0x48) { if (sign16(E->dms_var_41 - 94)) { int v6 = k >> 1; int v7 = j >> 1; @@ -5315,19 +5136,19 @@ void Torizo_CorpseRottingMoveFunc(uint16 j, uint16 k) { // 0xA9E272 void Torizo_CorpseRottingCopyFunc(uint16 j, uint16 k) { // 0xA9E38B Enemy_DeadMonsters *E = Get_DeadMonsters(0); - if (E->dms_var_41 >= 0x50u && sign16(E->dms_var_41 - 94)) { + if (E->dms_var_41 >= 0x50 && sign16(E->dms_var_41 - 94)) { int v3 = k >> 1; int v4 = j >> 1; tilemap_stuff[v4 + 1] = tilemap_stuff[v3]; tilemap_stuff[v4 + 9] = tilemap_stuff[v3 + 8]; } - if (E->dms_var_41 >= 0x48u && sign16(E->dms_var_41 - 94)) { + if (E->dms_var_41 >= 0x48 && sign16(E->dms_var_41 - 94)) { int v5 = k >> 1; int v6 = j >> 1; tilemap_stuff[v6 + 17] = tilemap_stuff[v5 + 16]; tilemap_stuff[v6 + 25] = tilemap_stuff[v5 + 24]; } - if (E->dms_var_41 >= 0x10u && sign16(E->dms_var_41 - 94)) { + if (E->dms_var_41 >= 0x10 && sign16(E->dms_var_41 - 94)) { int v7 = k >> 1; int v8 = j >> 1; tilemap_stuff[v8 + 33] = tilemap_stuff[v7 + 32]; @@ -5381,7 +5202,7 @@ void Torizo_CorpseRottingCopyFunc(uint16 j, uint16 k) { // 0xA9E38B void Sidehopper_CorpseRottingMoveFunc_0(uint16 j, uint16 k) { // 0xA9E468 Enemy_DeadMonsters *E = Get_DeadMonsters(0); - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 38)) { int v3 = k >> 1; int v4 = j >> 1; @@ -5392,7 +5213,7 @@ void Sidehopper_CorpseRottingMoveFunc_0(uint16 j, uint16 k) { // 0xA9E468 tilemap_stuff[v5] = 0; tilemap_stuff[v5 + 8] = 0; } - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 38)) { int v6 = k >> 1; int v7 = j >> 1; @@ -5430,13 +5251,13 @@ void Sidehopper_CorpseRottingMoveFunc_0(uint16 j, uint16 k) { // 0xA9E468 void Sidehopper_CorpseRottingCopyFunc_0(uint16 j, uint16 k) { // 0xA9E4F5 Enemy_DeadMonsters *E = Get_DeadMonsters(0); - if (E->dms_var_41 >= 8u && sign16(E->dms_var_41 - 38)) { + if (E->dms_var_41 >= 8 && sign16(E->dms_var_41 - 38)) { int v3 = k >> 1; int v4 = j >> 1; tilemap_stuff[v4 + 1] = tilemap_stuff[v3]; tilemap_stuff[v4 + 9] = tilemap_stuff[v3 + 8]; } - if (E->dms_var_41 >= 8u && sign16(E->dms_var_41 - 38)) { + if (E->dms_var_41 >= 8 && sign16(E->dms_var_41 - 38)) { int v5 = k >> 1; int v6 = j >> 1; tilemap_stuff[v6 + 17] = tilemap_stuff[v5 + 16]; @@ -5480,7 +5301,7 @@ void Sidehopper_CorpseRottingMoveFunc_2(uint16 j, uint16 k) { // 0xA9E564 } tilemap_stuff[v5 + 416] = 0; tilemap_stuff[v5 + 424] = 0; - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 38)) { int v7 = j >> 1; tilemap_stuff[v7 + 433] = tilemap_stuff[v5 + 432]; @@ -5489,7 +5310,7 @@ void Sidehopper_CorpseRottingMoveFunc_2(uint16 j, uint16 k) { // 0xA9E564 tilemap_stuff[v5 + 432] = 0; tilemap_stuff[v5 + 440] = 0; } - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 38)) { int v8 = j >> 1; tilemap_stuff[v8 + 449] = tilemap_stuff[v5 + 448]; @@ -5498,7 +5319,7 @@ void Sidehopper_CorpseRottingMoveFunc_2(uint16 j, uint16 k) { // 0xA9E564 tilemap_stuff[v5 + 448] = 0; tilemap_stuff[v5 + 456] = 0; } - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 38)) { int v9 = j >> 1; tilemap_stuff[v9 + 465] = tilemap_stuff[v5 + 464]; @@ -5523,19 +5344,19 @@ void Sidehopper_CorpseRottingCopyFunc_2(uint16 j, uint16 k) { // 0xA9E5F6 tilemap_stuff[v6 + 417] = tilemap_stuff[v5 + 416]; tilemap_stuff[v6 + 425] = tilemap_stuff[v5 + 424]; } - if (E->dms_var_41 >= 8u && sign16(E->dms_var_41 - 38)) { + if (E->dms_var_41 >= 8 && sign16(E->dms_var_41 - 38)) { int v7 = k >> 1; int v8 = j >> 1; tilemap_stuff[v8 + 433] = tilemap_stuff[v7 + 432]; tilemap_stuff[v8 + 441] = tilemap_stuff[v7 + 440]; } - if (E->dms_var_41 >= 8u && sign16(E->dms_var_41 - 38)) { + if (E->dms_var_41 >= 8 && sign16(E->dms_var_41 - 38)) { int v9 = k >> 1; int v10 = j >> 1; tilemap_stuff[v10 + 449] = tilemap_stuff[v9 + 448]; tilemap_stuff[v10 + 457] = tilemap_stuff[v9 + 456]; } - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 38)) { int v11 = k >> 1; int v12 = j >> 1; @@ -5908,7 +5729,7 @@ void MotherBrain_CorpseRottingMoveFunc(uint16 j, uint16 k) { // 0xA9EA40 *(uint16 *)((uint8 *)&kraid_unk9000 + k) = 0; *(uint16 *)((uint8 *)&g_word_7E900F + k + 1) = 0; } - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 46)) { *(uint16 *)((uint8 *)&g_word_7E9022 + j) = *(uint16 *)((uint8 *)&g_word_7E9020 + k); *(uint16 *)((uint8 *)&g_word_7E9032 + j) = *(uint16 *)((uint8 *)&g_word_7E9030 + k); @@ -5934,7 +5755,7 @@ void MotherBrain_CorpseRottingMoveFunc(uint16 j, uint16 k) { // 0xA9EA40 } *(uint16 *)((uint8 *)&g_word_7E9080 + k) = 0; *(uint16 *)((uint8 *)&g_word_7E9090 + k) = 0; - if (E->dms_var_41 >= 8u) { + if (E->dms_var_41 >= 8) { if (sign16(E->dms_var_41 - 46)) { *(uint16 *)((uint8 *)&g_word_7E90A2 + j) = *(uint16 *)((uint8 *)&g_word_7E90A0 + k); *(uint16 *)((uint8 *)&g_word_7E90B2 + j) = *(uint16 *)((uint8 *)&g_word_7E90B0 + k); @@ -5954,11 +5775,11 @@ void MotherBrain_CorpseRottingMoveFunc(uint16 j, uint16 k) { // 0xA9EA40 void MotherBrain_CorpseRottingCopyFunc(uint16 j, uint16 k) { // 0xA9EB0B Enemy_DeadMonsters *E = Get_DeadMonsters(0); - if (E->dms_var_41 >= 0x10u && sign16(E->dms_var_41 - 46)) { + if (E->dms_var_41 >= 0x10 && sign16(E->dms_var_41 - 46)) { *(uint16 *)((uint8 *)&g_word_7E9002 + j) = *(uint16 *)((uint8 *)&kraid_unk9000 + k); *(uint16 *)((uint8 *)&g_word_7E9012 + j) = *(uint16 *)((uint8 *)&g_word_7E900F + k + 1); } - if (E->dms_var_41 >= 8u && sign16(E->dms_var_41 - 46)) { + if (E->dms_var_41 >= 8 && sign16(E->dms_var_41 - 46)) { *(uint16 *)((uint8 *)&g_word_7E9022 + j) = *(uint16 *)((uint8 *)&g_word_7E9020 + k); *(uint16 *)((uint8 *)&g_word_7E9032 + j) = *(uint16 *)((uint8 *)&g_word_7E9030 + k); } @@ -5974,7 +5795,7 @@ void MotherBrain_CorpseRottingCopyFunc(uint16 j, uint16 k) { // 0xA9EB0B *(uint16 *)((uint8 *)&g_word_7E9082 + j) = *(uint16 *)((uint8 *)&g_word_7E9080 + k); *(uint16 *)((uint8 *)&g_word_7E9092 + j) = *(uint16 *)((uint8 *)&g_word_7E9090 + k); } - if (E->dms_var_41 >= 8u && sign16(E->dms_var_41 - 46)) { + if (E->dms_var_41 >= 8 && sign16(E->dms_var_41 - 46)) { *(uint16 *)((uint8 *)&g_word_7E90A2 + j) = *(uint16 *)((uint8 *)&g_word_7E90A0 + k); *(uint16 *)((uint8 *)&g_word_7E90B2 + j) = *(uint16 *)((uint8 *)&g_word_7E90B0 + k); } @@ -5998,24 +5819,24 @@ const uint16 *sub_A9ECD0(uint16 k, const uint16 *jp) { // 0xA9ECD0 uint8 Shitroid_Func_1(uint16 k, uint16 j) { // 0xA9EED1 Enemy_Shitroid *E = Get_Shitroid(j); Enemy_Shitroid *G = Get_Shitroid(k); - R18_ = G->base.x_width + E->base.x_width + 1; + uint16 r18 = G->base.x_width + E->base.x_width + 1; uint16 v4 = abs16(E->base.x_pos - G->base.x_pos); - bool v5 = v4 >= R18_; - if (v4 < R18_) { - R18_ = G->base.y_height + E->base.y_height + 1; - return abs16(E->base.y_pos - G->base.y_pos) >= R18_; + bool v5 = v4 >= r18; + if (v4 < r18) { + r18 = G->base.y_height + E->base.y_height + 1; + return abs16(E->base.y_pos - G->base.y_pos) >= r18; } return v5; } -uint8 Shitroid_Func_2(uint16 k) { // 0xA9EF06 +uint8 Shitroid_Func_2(uint16 k, Rect16U rect) { // 0xA9EF06 Enemy_Shitroid *E = Get_Shitroid(k); - R26_ = E->base.x_width + R22_ + 1; - uint16 v2 = abs16(R18_ - E->base.x_pos); - bool v3 = v2 >= R26_; - if (v2 < R26_) { - R26_ = E->base.y_height + R24_ + 1; - return abs16(R20_ - E->base.y_pos) >= R26_; + uint16 R26 = E->base.x_width + rect.w + 1; + uint16 v2 = abs16(rect.x - E->base.x_pos); + bool v3 = v2 >= R26; + if (v2 < R26) { + R26 = E->base.y_height + rect.h + 1; + return abs16(rect.y - E->base.y_pos) >= R26; } return v3; } @@ -6094,16 +5915,13 @@ void Shitroid_Func_3(uint16 k) { // 0xA9EFDF E->shitr_var_C = 0; } -static const SpawnHardcodedPlmArgs unk_A9F00E = { 0x30, 0x03, 0xb767 }; -static const SpawnHardcodedPlmArgs unk_A9F016 = { 0x1f, 0x03, 0xb767 }; - void Shitroid_Func_4(void) { // 0xA9EFE6 if (sign16(layer1_x_pos - 513)) { layer1_x_pos = 512; *(uint16 *)scrolls = scrolls[0]; *(uint16 *)&scrolls[2] = scrolls[2]; - SpawnHardcodedPlm(&unk_A9F00E); - SpawnHardcodedPlm(&unk_A9F016); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x30, 0x03, 0xb767 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x1f, 0x03, 0xb767 }); Enemy_Shitroid *E = Get_Shitroid(cur_enemy_index); E->shitr_var_A = FUNC16(Shitroid_Func_5); E->shitr_var_04 = 1; @@ -6120,36 +5938,29 @@ void Shitroid_Func_5(uint16 k) { // 0xA9F02B void Shitroid_Func_6(uint16 k) { // 0xA9F037 Enemy_Shitroid *E = Get_Shitroid(k); if ((--E->shitr_var_F & 0x8000) != 0) { - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); E->shitr_var_A = FUNC16(Shitroid_Func_7); Shitroid_Func_7(k); } } void Shitroid_Func_7(uint16 k) { // 0xA9F049 - R18_ = 584; - R20_ = 74; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xF); - R22_ = 1; - R24_ = 1; - if (!(Shitroid_Func_2(k) & 1)) + Rect16U rect = { 584, 74, 1, 1 }; + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xF, rect.x, rect.y); + if (!Shitroid_Func_2(k, rect)) Get_Shitroid(k)->shitr_var_A = FUNC16(Shitroid_Func_8); } void Shitroid_Func_8(uint16 k) { // 0xA9F06D Enemy_Shitroid *E = Get_Shitroid(k + 64); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos - 32; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xF); + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xF, E->base.x_pos, E->base.y_pos - 32); if (!(Shitroid_Func_1(k, k + 64) & 1)) Get_Shitroid(k)->shitr_var_A = FUNC16(Shitroid_Func_9); } void Shitroid_Func_9(uint16 k) { // 0xA9F094 Enemy_Shitroid *E1 = Get_Shitroid(k + 64); - R18_ = E1->base.x_pos; - R20_ = E1->base.y_pos - 32; - if (Shitroid_AccelerateTowardsPoint(k, 0x200) & 1) { + if (Shitroid_AccelerateTowardsPoint(k, 0x200, E1->base.x_pos, E1->base.y_pos - 32) & 1) { Enemy_Shitroid *E = Get_Shitroid(k); E->shitr_var_B = 0; E->shitr_var_C = 0; @@ -6167,7 +5978,7 @@ void Shitroid_Func_9(uint16 k) { // 0xA9F094 void Shitroid_Func_10(uint16 k) { // 0xA9F0E6 Enemy_Shitroid *E = Get_Shitroid(k); - int v2 = (uint8)(E->base.frame_counter & 6) >> 1; + int v2 = (E->base.frame_counter & 6) >> 1; Enemy_Shitroid *E1 = Get_Shitroid(k + 64); E->base.x_pos = E1->base.x_pos + g_word_A993BB[v2]; E->base.y_pos = E1->base.y_pos + g_word_A993C3[v2] - 32; @@ -6188,21 +5999,16 @@ void Shitroid_Func_11(uint16 k) { // 0xA9F125 Shitroid_Func_12(k); } -static const SpawnHardcodedPlmArgs unk_A9F173 = { 0x30, 0x03, 0xb763 }; -static const SpawnHardcodedPlmArgs unk_A9F17B = { 0x1f, 0x03, 0xb763 }; - void Shitroid_Func_12(uint16 k) { // 0xA9F138 Enemy_Shitroid *E = Get_Shitroid(k); - R18_ = E->base.x_pos; - R20_ = 104; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0); + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0, E->base.x_pos, 104); if ((--E->shitr_var_F & 0x8000) != 0) { E->shitr_var_A = FUNC16(Shitroid_Func_13); E->shitr_parameter_2 = 1; - *(uint16 *)scrolls |= 0x100u; - *(uint16 *)&scrolls[2] |= 0x100u; - SpawnHardcodedPlm(&unk_A9F173); - SpawnHardcodedPlm(&unk_A9F17B); + *(uint16 *)scrolls |= 0x100; + *(uint16 *)&scrolls[2] |= 0x100; + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x30, 0x03, 0xb763 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x1f, 0x03, 0xb763 }); } } @@ -6210,17 +6016,17 @@ void Shitroid_Func_13(uint16 k) { // 0xA9F180 Enemy_Shitroid *E = Get_Shitroid(k); uint16 v2 = abs16(E->base.x_pos - samus_x_pos); uint16 shitro_var_02; - if (v2 >= 8u) { + if (v2 >= 8) { shitro_var_02 = E->shitr_var_02; if (shitro_var_02) { if ((--shitro_var_02 & 0x8000) != 0) shitro_var_02 = 0; } } else { - shitro_var_02 = (v2 >= 8u) + E->shitr_var_02 + 2; + shitro_var_02 = (v2 >= 8) + E->shitr_var_02 + 2; } E->shitr_var_02 = shitro_var_02; - if (shitro_var_02 >= 0x100u || sign16(samus_x_pos - 512)) { + if (shitro_var_02 >= 0x100 || sign16(samus_x_pos - 512)) { Get_Shitroid(cur_enemy_index)->shitr_var_A = FUNC16(Shitroid_Func_14); } else { uint16 shitro_var_01 = E->shitr_var_01; @@ -6230,30 +6036,26 @@ void Shitroid_Func_13(uint16 k) { // 0xA9F180 v5 = samus_y_pos; } else { v5 = 80; - if ((random_number & 0xFFFu) >= 0xFE0) + if ((random_number & 0xFFF) >= 0xFE0) E->shitr_var_01 = 32; } - R20_ = v5; - R18_ = samus_x_pos; - Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0xA); + Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0xA, samus_x_pos, v5); } } void Shitroid_Func_14(uint16 k) { // 0xA9F1FA - R18_ = samus_x_pos; - R20_ = samus_y_pos - 32; - Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xF); + Shitroid_Func_GraduallyAccelerateTowards0x400(k, 0xF, samus_x_pos, samus_y_pos - 32); } void Shitroid_Func_15(uint16 k) { // 0xA9F20E - CallSomeSamusCode(0x12u); + CallSomeSamusCode(0x12); Get_Shitroid(0)->shitr_var_A = FUNC16(Shitroid_Func_16); Shitroid_Func_16(k); } void Shitroid_Func_16(uint16 k) { // 0xA9F21B Enemy_Shitroid *E = Get_Shitroid(k); - if (samus_health < 2u) { + if (samus_health < 2) { samus_x_speed_divisor = 0; bomb_counter = 0; E->shitr_var_A = FUNC16(Shitroid_Func_17); @@ -6261,17 +6063,17 @@ void Shitroid_Func_16(uint16 k) { // 0xA9F21B E->shitr_var_C = 0; Enemy_SetInstrList(k, addr_kShitroid_Ilist_F906); E->shitr_var_E = 10; - CallSomeSamusCode(0x13u); + CallSomeSamusCode(0x13); SomeMotherBrainScripts(0); E->shitr_var_04 = 0; - QueueMusic_Delayed8(7u); + QueueMusic_Delayed8(7); } else { cooldown_timer = 8; bomb_counter = 5; samus_x_speed_divisor = 2; if (!sign16(samus_y_speed - 4)) samus_y_speed = 2; - int v2 = (uint8)(E->base.frame_counter & 6) >> 1; + int v2 = (E->base.frame_counter & 6) >> 1; E->base.x_pos = samus_x_pos + g_word_A993BB[v2]; E->base.y_pos = samus_y_pos + g_word_A993C3[v2] - 20; Samus_DamageDueToShitroid(); @@ -6295,12 +6097,10 @@ void Shitroid_Func_18(uint16 k) { // 0xA9F2AE } void Shitroid_Func_19(uint16 k) { // 0xA9F2C0 - R18_ = samus_x_pos; - R20_ = 104; - Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0); + Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0, samus_x_pos, 104); Enemy_Shitroid *E = Get_Shitroid(cur_enemy_index); if ((--E->shitr_var_F & 0x8000) != 0) { - QueueSfx2_Max6(0x7Du); + QueueSfx2_Max6(0x7D); E->shitr_var_A = FUNC16(Shitroid_Func_20); E->shitr_var_F = 88; E->base.current_instruction = addr_kShitroid_Ilist_F924; @@ -6311,9 +6111,7 @@ void Shitroid_Func_19(uint16 k) { // 0xA9F2C0 } void Shitroid_Func_20(void) { // 0xA9F2FB - R18_ = samus_x_pos - 64; - R20_ = 100; - Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0); + Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0, samus_x_pos - 64, 100); Enemy_Shitroid *E = Get_Shitroid(cur_enemy_index); if ((--E->shitr_var_F & 0x8000) != 0) { E->shitr_var_A = FUNC16(Shitroid_Func_21); @@ -6323,9 +6121,7 @@ void Shitroid_Func_20(void) { // 0xA9F2FB } void Shitroid_Func_21(void) { // 0xA9F324 - R18_ = samus_x_pos + 96; - R20_ = 104; - Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0); + Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0, samus_x_pos + 96, 104); Enemy_Shitroid *E = Get_Shitroid(cur_enemy_index); if ((--E->shitr_var_F & 0x8000) != 0) { E->shitr_var_A = FUNC16(Shitroid_Func_24); @@ -6337,18 +6133,15 @@ void Shitroid_Func_21(void) { // 0xA9F324 } void Shitroid_Func_22(uint16 k) { // 0xA9F360 - QueueSfx2_Max6(0x52u); + QueueSfx2_Max6(0x52); Get_Shitroid(k)->shitr_var_A = FUNC16(Shitroid_Func_23); Shitroid_Func_23(); } void Shitroid_Func_23(void) { // 0xA9F36D - R18_ = -128; - R20_ = 64; - Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0); - R22_ = 8; - R24_ = 8; - if (!(Shitroid_Func_2(cur_enemy_index) & 1)) { + Rect16U rect = { -128, 64, 8, 8 }; + Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 0, rect.x, rect.y); + if (!Shitroid_Func_2(cur_enemy_index, rect)) { Enemy_Shitroid *E = Get_Shitroid(cur_enemy_index); E->shitr_var_B = 0; E->shitr_var_C = 0; @@ -6360,7 +6153,7 @@ void Shitroid_Func_23(void) { // 0xA9F36D void Shitroid_Func_24(uint16 k) { // 0xA9F3A3 Enemy_Shitroid *E = Get_Shitroid(k); if ((--E->shitr_var_F & 0x8000) != 0) { - SomeMotherBrainScripts(2u); + SomeMotherBrainScripts(2); E->shitr_parameter_2 = 1; E->shitr_var_A = FUNC16(Shitroid_Func_25); Shitroid_Func_25(k); @@ -6387,14 +6180,14 @@ uint8 Shitroid_Func_27(uint16 k) { // 0xA9F3D4 Enemy_Shitroid *E = Get_Shitroid(k); uint16 v2 = abs16(E->base.x_pos - samus_x_pos); uint16 shitro_var_02; - if (v2 >= 2u) { + if (v2 >= 2) { shitro_var_02 = E->shitr_var_02; if (shitro_var_02) { if ((--shitro_var_02 & 0x8000) != 0) shitro_var_02 = 0; } } else { - shitro_var_02 = (v2 >= 2u) + E->shitr_var_02 + 2; + shitro_var_02 = (v2 >= 2) + E->shitr_var_02 + 2; } E->shitr_var_02 = shitro_var_02; uint16 shitro_var_01 = E->shitr_var_01; @@ -6404,68 +6197,46 @@ uint8 Shitroid_Func_27(uint16 k) { // 0xA9F3D4 v5 = samus_y_pos - 18; } else { v5 = 80; - if ((random_number & 0xFFFu) >= 0xFE0) + if ((random_number & 0xFFF) >= 0xFE0) E->shitr_var_01 = 32; } - R20_ = v5; - R18_ = samus_x_pos; - Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 8u); - return Get_Shitroid(cur_enemy_index)->shitr_var_02 >= 0x400u || sign16(samus_x_pos - 128); + Shitroid_Func_GraduallyAccelerateTowards0x400(cur_enemy_index, 8, samus_x_pos, v5); + return Get_Shitroid(cur_enemy_index)->shitr_var_02 >= 0x400 || sign16(samus_x_pos - 128); } -void Shitroid_Func_GraduallyAccelerateTowards0x400(uint16 k, uint16 j) { // 0xA9F451 - R26_ = 1024; - Shitroid_GraduallyAccelerateTowardsPt(k, j); -} - -void Shitroid_GraduallyAccelerateTowards0x4(uint16 k, uint16 j) { // 0xA9F458 - R26_ = 4; - Shitroid_GraduallyAccelerateTowardsPt(k, j); -} - -void Shitroid_GraduallyAccelerateTowards0x8(uint16 k, uint16 j) { // 0xA9F45F - R26_ = 8; - Shitroid_GraduallyAccelerateTowardsPt(k, j); -} - -void Shitroid_GraduallyAccelerateTowards0x10(uint16 k, uint16 j) { // 0xA9F466 - R26_ = 16; - Shitroid_GraduallyAccelerateTowardsPt(k, j); -} - -void Shitroid_GraduallyAccelerateTowardsPt(uint16 k, uint16 j) { // 0xA9F46B +void Shitroid_GraduallyAccelerateTowardsPt(uint16 k, uint16 j, uint16 r18, uint16 r20, uint16 r26) { // 0xA9F46B int16 v3; int16 v5; int16 v6; int16 shitr_var_C; int16 v9; - R24_ = g_byte_A9F56A[j]; - Shitroid_GraduallyAccelerateHoriz(k); + uint16 r24 = g_byte_A9F56A[j]; + Shitroid_GraduallyAccelerateHoriz(k, r18, r24, r26); Enemy_Shitroid *E = Get_Shitroid(k); - v3 = E->base.y_pos - R20_; + v3 = E->base.y_pos - r20; if (v3) { if (v3 >= 0) { - uint16 RegWord = SnesDivide(v3, R24_); + uint16 RegWord = SnesDivide(v3, r24); if (!RegWord) RegWord = 1; - R22_ = RegWord; + uint16 r22 = RegWord; shitr_var_C = E->shitr_var_C; if (shitr_var_C >= 0) - shitr_var_C = shitr_var_C - 8 - R22_; - v9 = shitr_var_C - R22_; + shitr_var_C = shitr_var_C - 8 - r22; + v9 = shitr_var_C - r22; if (sign16(v9 + 1280)) v9 = -1280; E->shitr_var_C = v9; } else { - uint16 v4 = SnesDivide(R20_ - E->base.y_pos, R24_); + uint16 v4 = SnesDivide(r20 - E->base.y_pos, r24); if (!v4) v4 = 1; - R22_ = v4; + uint16 r22 = v4; v5 = E->shitr_var_C; if (v5 < 0) - v5 += R22_ + 8; - v6 = R22_ + v5; + v5 += r22 + 8; + v6 = r22 + v5; if (!sign16(v6 - 1280)) v6 = 1280; E->shitr_var_C = v6; @@ -6473,7 +6244,23 @@ void Shitroid_GraduallyAccelerateTowardsPt(uint16 k, uint16 j) { // 0xA9F46B } } -void Shitroid_GraduallyAccelerateHoriz(uint16 k) { // 0xA9F4E6 +void Shitroid_Func_GraduallyAccelerateTowards0x400(uint16 k, uint16 j, uint16 r18, uint16 r20) { // 0xA9F451 + Shitroid_GraduallyAccelerateTowardsPt(k, j, r18, r20, 1024); +} + +void Shitroid_GraduallyAccelerateTowards0x4(uint16 k, uint16 j, uint16 r18, uint16 r20) { // 0xA9F458 + Shitroid_GraduallyAccelerateTowardsPt(k, j, r18, r20, 4); +} + +void Shitroid_GraduallyAccelerateTowards0x8(uint16 k, uint16 j, uint16 r18, uint16 r20) { // 0xA9F45F + Shitroid_GraduallyAccelerateTowardsPt(k, j, r18, r20, 8); +} + +void Shitroid_GraduallyAccelerateTowards0x10(uint16 k, uint16 j, uint16 r18, uint16 r20) { // 0xA9F466 + Shitroid_GraduallyAccelerateTowardsPt(k, j, r18, r20, 16); +} + +void Shitroid_GraduallyAccelerateHoriz(uint16 k, uint16 r18, uint16 r24, uint16 r26) { // 0xA9F4E6 int16 v2; int16 v4; int8 v5; // cf @@ -6482,41 +6269,41 @@ void Shitroid_GraduallyAccelerateHoriz(uint16 k) { // 0xA9F4E6 int16 v11; Enemy_Shitroid *E = Get_Shitroid(k); - v2 = E->base.x_pos - R18_; + v2 = E->base.x_pos - r18; if (v2) { if (v2 >= 0) { - uint16 RegWord = SnesDivide(v2, R24_); + uint16 RegWord = SnesDivide(v2, r24); if (!RegWord) RegWord = 1; - R22_ = RegWord; + uint16 r22 = RegWord; shitr_var_B = E->shitr_var_B; if (shitr_var_B >= 0) { uint16 v13 = E->shitr_var_B; v5 = Shitroid_CheckIfOnScreen(k) & 1; uint16 v10 = v13; if (v5) - v10 = v13 - R26_; - shitr_var_B = v10 - 8 - R22_; + v10 = v13 - r26; + shitr_var_B = v10 - 8 - r22; } - v11 = shitr_var_B - R22_; + v11 = shitr_var_B - r22; if (sign16(v11 + 2048)) v11 = -2048; E->shitr_var_B = v11; } else { - uint16 v3 = SnesDivide(R18_ - E->base.x_pos, R24_); + uint16 v3 = SnesDivide(r18 - E->base.x_pos, r24); if (!v3) v3 = 1; - R22_ = v3; + uint16 r22 = v3; v4 = E->shitr_var_B; if (v4 < 0) { uint16 v12 = E->shitr_var_B; v5 = Shitroid_CheckIfOnScreen(k) & 1; uint16 v6 = v12; if (v5) - v6 = R26_ + v12; - v4 = R22_ + v6 + 8; + v6 = r26 + v12; + v4 = r22 + v6 + 8; } - v7 = R22_ + v4; + v7 = r22 + v4; if (!sign16(v7 - 2048)) v7 = 2048; E->shitr_var_B = v7; @@ -6552,87 +6339,80 @@ uint8 Shitroid_CheckIfOnScreen(uint16 k) { // 0xA9F57A return result; } -uint8 Shitroid_AccelerateTowardsPoint(uint16 k, uint16 a) { // 0xA9F5A6 - R22_ = a; - R28_ = 0; - Shitroid_AccelerateTowardsX(k); - Shitroid_AccelerateTowardsY(k); - R28_ >>= 1; - uint8 v2 = R28_ & 1; - R28_ >>= 1; - return v2; +uint8 Shitroid_AccelerateTowardsPoint(uint16 k, uint16 a, uint16 r18, uint16 r20) { // 0xA9F5A6 + uint16 R28 = 0; + R28 += Shitroid_AccelerateTowardsX(k, r18, a); + R28 += Shitroid_AccelerateTowardsY(k, r20, a); + R28 >>= 1; + return R28 & 1; } -void Shitroid_AccelerateTowardsY(uint16 k) { // 0xA9F5B5 +uint16 Shitroid_AccelerateTowardsY(uint16 k, uint16 r20, uint16 r22) { // 0xA9F5B5 Enemy_Shitroid *E = Get_Shitroid(k); - int16 v2 = E->base.y_pos - R20_; + uint16 result = 0; + int16 v2 = E->base.y_pos - r20; if (!v2) { - ++R28_; - return; - } - if (v2 >= 0) { - uint16 v7 = E->shitr_var_C - R22_; + ++result; + } else if (v2 >= 0) { + uint16 v7 = E->shitr_var_C - r22; if (sign16(v7 + 1280)) v7 = -1280; E->shitr_var_C = v7; - if ((int16)(E->base.y_pos + (int8)(v7 >> 8) - R20_) <= 0) { + if ((int16)(E->base.y_pos + (int8)(v7 >> 8) - r20) <= 0) { E->shitr_var_C = 0; - ++R28_; + ++result; } } else { - uint16 v3 = R22_ + E->shitr_var_C; + uint16 v3 = r22 + E->shitr_var_C; if (!sign16(v3 - 1280)) v3 = 1280; E->shitr_var_C = v3; - if ((int16)(E->base.y_pos + (int8)(v3 >> 8) - R20_) >= 0) { + if ((int16)(E->base.y_pos + (int8)(v3 >> 8) - r20) >= 0) { E->shitr_var_C = 0; - ++R28_; + ++result; } } + return result; } -void Shitroid_AccelerateTowardsX(uint16 k) { // 0xA9F615 +uint16 Shitroid_AccelerateTowardsX(uint16 k, uint16 r18, uint16 r22) { // 0xA9F615 Enemy_Shitroid *E = Get_Shitroid(k); - if ((int16)(E->base.x_pos - R18_) >= 0) { - uint16 v6 = E->shitr_var_B - R22_; + uint16 result = 0; + if ((int16)(E->base.x_pos - r18) >= 0) { + uint16 v6 = E->shitr_var_B - r22; if (sign16(v6 + 1280)) v6 = -1280; E->shitr_var_B = v6; - if ((int16)(E->base.x_pos + (int8)(v6 >> 8) - R18_) <= 0) { + if ((int16)(E->base.x_pos + (int8)(v6 >> 8) - r18) <= 0) { E->shitr_var_B = 0; - ++R28_; + ++result; } } else { - uint16 v2 = R22_ + E->shitr_var_B; + uint16 v2 = r22 + E->shitr_var_B; if (!sign16(v2 - 1280)) v2 = 1280; E->shitr_var_B = v2; - if ((int16)(E->base.x_pos + (int8)(v2 >> 8) - R18_) >= 0) { + if ((int16)(E->base.x_pos + (int8)(v2 >> 8) - r18) >= 0) { E->shitr_var_B = 0; - ++R28_; + ++result; } } + return result; } void Shitroid_HandleNormalPalette(void) { // 0xA9F677 - R18_ = 330; - R22_ = addr_word_A9F6D1; - Shitroid_HandleCutscenePalette_Common(); + Shitroid_HandleCutscenePalette_Common(addr_word_A9F6D1, 330); } void Shitroid_HandleCutscenePalette(void) { // 0xA9F683 - R18_ = 490; - R22_ = addr_word_A9F6D1; - Shitroid_HandleCutscenePalette_Common(); + Shitroid_HandleCutscenePalette_Common(addr_word_A9F6D1, 490); } void Shitroid_HandleCutscenePalette_LowHealth(void) { // 0xA9F68F - R18_ = 490; - R22_ = addr_word_A9F711; - Shitroid_HandleCutscenePalette_Common(); + Shitroid_HandleCutscenePalette_Common(addr_word_A9F711, 490); } -void Shitroid_HandleCutscenePalette_Common(void) { // 0xA9F699 +void Shitroid_HandleCutscenePalette_Common(uint16 r22, uint16 r18) { // 0xA9F699 int8 shitro_var_D_high; Enemy_Shitroid *E = Get_Shitroid(cur_enemy_index); @@ -6644,7 +6424,7 @@ void Shitroid_HandleCutscenePalette_Common(void) { // 0xA9F699 uint8 v3 = (LOBYTE(E->shitr_var_D) + 1) & 7; LOBYTE(E->shitr_var_D) = v3; uint16 v4 = Shitroid_HandleCrySoundEffect(cur_enemy_index, v3); - WriteColorsToPalette(R18_, 0xa9, R22_ + 8 * v4, 4u); + WriteColorsToPalette(r18, 0xa9, r22 + 8 * v4, 4); } } @@ -6654,10 +6434,10 @@ uint16 Shitroid_HandleCrySoundEffect(uint16 k, uint16 a) { // 0xA9F751 if (E->shitr_var_04) { uint16 v3 = E->shitr_var_05 + 1; E->shitr_var_05 = v3; - if (v3 >= 4u) { + if (v3 >= 4) { E->shitr_var_05 = 0; uint16 v4 = 114; - if (E->shitr_var_E < 0xAu) + if (E->shitr_var_E < 0xA) v4 = 120; QueueSfx2_Max6(v4); } @@ -6672,17 +6452,11 @@ void Shitroid_Touch(void) { // 0xA9F789 if (E->shitr_parameter_2) { Shitroid_Func_26(cur_enemy_index); if (samus_movement_type == 3 && !sign16(samus_x_pos - 512)) { - R18_ = samus_x_pos - E->base.x_pos; - R20_ = samus_y_pos - E->base.y_pos; - R18_ = (uint8)(0x80 - CalculateAngleFromXY() + 0x80); - uint16 v4 = Math_MultBySin(0x40); - E->shitr_var_B += v4; - uint16 v6 = Math_MultByCos(0x40); - E->shitr_var_C += v6; + uint16 r18 = (uint8)(0x80 - CalculateAngleFromXY(samus_x_pos - E->base.x_pos, samus_y_pos - E->base.y_pos) + 0x80); + E->shitr_var_B += Math_MultBySin(0x40, r18); + E->shitr_var_C += Math_MultByCos(0x40, r18); } else if (E->shitr_var_A == FUNC16(Shitroid_Func_14)) { - R18_ = samus_x_pos; - R20_ = samus_y_pos - 32; - if (Shitroid_AccelerateTowardsPoint(cur_enemy_index, 0x200) & 1) { + if (Shitroid_AccelerateTowardsPoint(cur_enemy_index, 0x200, samus_x_pos, samus_y_pos - 32) & 1) { E->base.current_instruction = addr_kShitroid_Ilist_F924; E->base.instruction_timer = 1; E->base.timer = 0; @@ -6702,17 +6476,12 @@ void Shitroid_Shot(void) { // 0xA9F842 Enemy_Shitroid *E = Get_Shitroid(cur_enemy_index); if (E->shitr_parameter_2) { Shitroid_Func_26(cur_enemy_index); - R18_ = projectile_x_pos[0] - E->base.x_pos; - R20_ = projectile_y_pos[0] - E->base.y_pos; - R18_ = (uint8)-CalculateAngleFromXY(); + uint16 r18 = (uint8)-CalculateAngleFromXY(projectile_x_pos[0] - E->base.x_pos, projectile_y_pos[0] - E->base.y_pos); uint16 v1 = 8 * projectile_damage[collision_detection_index]; if (v1 >= 0xF0) v1 = 240; - uint16 a = v1; - uint16 v2 = Math_MultBySin(v1); - E->shitr_var_B += v2; - uint16 v4 = Math_MultByCos(a); - E->shitr_var_C += v4; + E->shitr_var_B += Math_MultBySin(v1, r18); + E->shitr_var_C += Math_MultByCos(v1, r18); } } @@ -6731,6 +6500,6 @@ const uint16 *Shitroid_Instr_6(uint16 k, const uint16 *jp) { // 0xA9F990 const uint16 *Shitroid_Instr_5(uint16 k, const uint16 *jp) { // 0xA9F994 if ((random_number & 0x8000) == 0) return INSTR_RETURN_ADDR(jp[0]); - QueueSfx2_Max6(0x52u); + QueueSfx2_Max6(0x52); return jp + 1; -} \ No newline at end of file +} diff --git a/src/sm_aa.c b/src/sm_aa.c index e230364..8c009cf 100644 --- a/src/sm_aa.c +++ b/src/sm_aa.c @@ -119,7 +119,7 @@ const uint16 *Torizo_Instr_31(uint16 k, const uint16 *jp) { // 0xAAB11D const uint16 *Torizo_Instr_33(uint16 k, const uint16 *jp) { // 0xAAB1BE Enemy_Torizo *E = Get_Torizo(k); - E->toriz_parameter_2 |= 0x4000u; + E->toriz_parameter_2 |= 0x4000; return jp; } @@ -145,7 +145,7 @@ const uint16 *Torizo_Instr_35(uint16 k, const uint16 *jp) { // 0xAAB238 } const uint16 *Torizo_Instr_38(uint16 k, const uint16 *jp) { // 0xAAB24D - SetBossBitForCurArea(4u); + SetBossBitForCurArea(4); QueueMusic_Delayed8(g_word_AAB09A); if (area_index) Enemy_ItemDrop_GoldenTorizo(k); @@ -155,7 +155,7 @@ const uint16 *Torizo_Instr_38(uint16 k, const uint16 *jp) { // 0xAAB24D } const uint16 *Torizo_Instr_6(uint16 k, const uint16 *jp) { // 0xAAB271 - sub_82DAF7(0x600u); + sub_82DAF7(0x600); return jp; } @@ -174,7 +174,7 @@ void Torizo_C20A(uint16 k) { // 0xAAC20A int16 v2; Enemy_Torizo *E = Get_Torizo(k); - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v2 = 512; else v2 = -512; @@ -188,7 +188,7 @@ void Torizo_C22D(uint16 k) { // 0xAAC22D int16 v2; Enemy_Torizo *E = Get_Torizo(k); - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v2 = -768; else v2 = 768; @@ -286,7 +286,6 @@ const uint16 *Torizo_Instr_30(uint16 k, const uint16 *jp) { // 0xAAC303 } const uint16 *Torizo_Instr_34(uint16 k, const uint16 *jp) { // 0xAAC32F - //printf("A undefined\n"); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_BombTorizoDeathExplosion, 0); Enemy_Torizo *E = Get_Torizo(k); E->base.current_instruction = INSTR_ADDR_TO_PTR(k, jp); @@ -296,7 +295,6 @@ const uint16 *Torizo_Instr_34(uint16 k, const uint16 *jp) { // 0xAAC32F } const uint16 *Torizo_Instr_24(uint16 k, const uint16 *jp) { // 0xAAC34A - //printf("A undefined\n"); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianLandingDustCloudsRightFoot, 0); SpawnEnemyProjectileWithRoomGfx(addr_stru_86AFF3, 0); return jp; @@ -304,20 +302,20 @@ const uint16 *Torizo_Instr_24(uint16 k, const uint16 *jp) { // 0xAAC34A const uint16 *Torizo_Instr_12(uint16 k, const uint16 *jp) { // 0xAAC35B uint16 health = Get_Torizo(k)->base.health; - if (health < 0x15Eu) + if (health < 0x15E) SpawnEnemyProjectileWithGfx(health, k, addr_kEproj_BombTorizoLowHealthInitialDrool); return jp; } const uint16 *Torizo_Instr_10(uint16 k, const uint16 *jp) { // 0xAAC36D Enemy_Torizo *E = Get_Torizo(k); - E->toriz_parameter_1 |= 0x4000u; + E->toriz_parameter_1 |= 0x4000; return jp; } const uint16 *Torizo_Instr_11(uint16 k, const uint16 *jp) { // 0xAAC377 Enemy_Torizo *E = Get_Torizo(k); - E->toriz_parameter_1 &= 0x1FFFu; + E->toriz_parameter_1 &= 0x1FFF; ++E->toriz_var_09; return jp; } @@ -347,7 +345,7 @@ const uint16 *Torizo_Instr_4(uint16 k, const uint16 *jp) { // 0xAAC3CC uint16 v2 = jp[0]; Enemy_Torizo *E = Get_Torizo(k); E->base.x_pos += g_word_AAC3EE[v2 >> 1]; - E->base.y_pos += g_word_AAC40E[(uint8)(v2 & 0xF) >> 1]; + E->base.y_pos += g_word_AAC40E[(v2 & 0xF) >> 1]; return jp + 1; } @@ -355,24 +353,22 @@ const uint16 *Torizo_Instr_40(uint16 k, const uint16 *jp) { // 0xAAC41E uint16 v2 = jp[0]; Enemy_Torizo *E = Get_Torizo(k); E->base.x_pos -= g_word_AAC440[v2 >> 1]; - E->base.y_pos -= g_word_AAC460[(uint8)(v2 & 0xF) >> 1]; + E->base.y_pos -= g_word_AAC460[(v2 & 0xF) >> 1]; return jp + 1; } const uint16 *Torizo_Instr_16(uint16 k, const uint16 *jp) { // 0xAAC470 - R18_ = 0; - R20_ = g_word_AAC4BD[jp[0] >> 1]; Enemy_Torizo *E = Get_Torizo(k); - E->toriz_var_A = R20_; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + E->toriz_var_A = g_word_AAC4BD[jp[0] >> 1]; + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL16(E->toriz_var_A))) { E->toriz_var_03 = 0; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) return INSTR_RETURN_ADDR(addr_kTorizo_Ilist_B962); else return INSTR_RETURN_ADDR(addr_kTorizo_Ilist_BDD8); } else { EnemyFunc_C8AD(k); - if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000u) == 0) { + if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000) == 0) { if (!E->toriz_var_03) E->toriz_var_03 = 72; return jp + 1; @@ -383,19 +379,17 @@ const uint16 *Torizo_Instr_16(uint16 k, const uint16 *jp) { // 0xAAC470 } const uint16 *Torizo_Instr_27(uint16 k, const uint16 *jp) { // 0xAAC4E5 - R18_ = 0; - R20_ = g_word_AAC532[jp[0] >> 1]; Enemy_Torizo *E = Get_Torizo(k); - E->toriz_var_A = R20_; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + E->toriz_var_A = g_word_AAC532[jp[0] >> 1]; + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL16(E->toriz_var_A))) { E->toriz_var_03 = 0; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) return INSTR_RETURN_ADDR(addr_kTorizo_Ilist_BD0E); else return INSTR_RETURN_ADDR(addr_kTorizo_Ilist_C188); } else { EnemyFunc_C8AD(k); - if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000u) == 0) { + if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000) == 0) { if (!E->toriz_var_03) E->toriz_var_03 = 72; return jp + 1; @@ -406,7 +400,7 @@ const uint16 *Torizo_Instr_27(uint16 k, const uint16 *jp) { // 0xAAC4E5 } const uint16 *Torizo_Instr_23(uint16 k, const uint16 *jp) { // 0xAAC55A - if ((Get_Torizo(k)->toriz_var_B & 0x8000u) != 0) + if ((Get_Torizo(k)->toriz_var_B & 0x8000) != 0) return INSTR_RETURN_ADDR(jp[0]); else return jp + 1; @@ -416,14 +410,14 @@ const uint16 *Torizo_Instr_14(uint16 k, const uint16 *jp) { // 0xAAC567 if (CompareDistToSamus_X(k, 0x38) & 1) return jp + 1; Enemy_Torizo *E = Get_Torizo(k); - if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000u) == 0) + if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000) == 0) return jp + 1; E->toriz_var_00 = INSTR_ADDR_TO_PTR(k, jp + 1); return INSTR_RETURN_ADDR(jp[0]); } const uint16 *Torizo_Instr_15(uint16 k, const uint16 *jp) { // 0xAAC58B - if (CompareDistToSamus_X(k, 0x20) & 1 || (Torizo_Func_12(k) & 0x8000u) != 0) + if (CompareDistToSamus_X(k, 0x20) & 1 || (Torizo_Func_12(k) & 0x8000) != 0) return jp + 1; Torizo_C22D(k); return INSTR_RETURN_ADDR(jp[0]); @@ -432,14 +426,13 @@ const uint16 *Torizo_Instr_15(uint16 k, const uint16 *jp) { // 0xAAC58B const uint16 *Torizo_Instr_26(uint16 k, const uint16 *jp) { // 0xAAC5A4 Enemy_Torizo *E = Get_Torizo(k); E->toriz_var_00 = INSTR_ADDR_TO_PTR(k, jp + 2); - if (samus_missiles < 5u || ((nmi_frame_counter_word + (samus_x_pos & 1) + (samus_x_pos >> 1)) & 8) != 0) + if (samus_missiles < 5 || ((nmi_frame_counter_word + (samus_x_pos & 1) + (samus_x_pos >> 1)) & 8) != 0) return INSTR_RETURN_ADDR(jp[0]); else return INSTR_RETURN_ADDR(jp[1]); } const uint16 *Torizo_Instr_18(uint16 k, const uint16 *jp) { // 0xAAC5CB - //printf("A unknown\n"); SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_BombTorizosChozoOrbs); SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_BombTorizosChozoOrbs); SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_BombTorizosChozoOrbs); @@ -462,38 +455,27 @@ const uint16 *Torizo_Instr_21(uint16 k, const uint16 *jp) { // 0xAAC601 } const uint16 *Torizo_Instr_17(uint16 k, const uint16 *jp) { // 0xAAC610 - QueueSfx2_Max6(0x27u); + QueueSfx2_Max6(0x27); return jp; } const uint16 *Torizo_Instr_13(uint16 k, const uint16 *jp) { // 0xAAC618 - QueueSfx2_Max6(0x4Bu); + QueueSfx2_Max6(0x4B); return jp; } void Torizo_C620(uint16 k) { // 0xAAC620 if (!area_index && (random_number & 0x8142) == 0) { uint16 health = Get_Torizo(k)->base.health; - if (health) { - if (health < 0x15Eu) - SpawnEnemyProjectileWithGfx(health, k, addr_kEproj_BombTorizoLowHealthInitialDrool); - } + if (health && health < 0x15E) + SpawnEnemyProjectileWithGfx(health, k, addr_kEproj_BombTorizoLowHealthInitialDrool); } } void Torizo_C643(uint16 k) { // 0xAAC643 - int16 torizo_var_B; - int16 v3; - - R18_ = 0; - R20_ = 0; Enemy_Torizo *E = Get_Torizo(k); - torizo_var_B = E->toriz_var_B; - if (torizo_var_B < 0) - --R20_; - R19_ = torizo_var_B; - if (Enemy_MoveDown(k) & 1) { - v3 = E->toriz_var_B; + if (Enemy_MoveDown(k, INT16_SHL8(E->toriz_var_B))) { + int16 v3 = E->toriz_var_B; if (v3 >= 0 && v3 != 256) { earthquake_type = 4; earthquake_timer = 32; @@ -538,7 +520,7 @@ void Torizo_Main(void) { // 0xAAC6A4 void Torizo_Func_2(uint16 k) { // 0xAAC6AC Torizo_C643(k); - if (!(sub_82DAF7(0x600u) & 1)) + if (!(sub_82DAF7(0x600) & 1)) Get_Torizo(k)->toriz_var_E = FUNC16(nullsub_270); } @@ -553,7 +535,7 @@ void Torizo_Func_4(uint16 k) { // 0xAAC6C6 uint16 v2 = 78; while (plm_header_ptr[v2 >> 1] != addr_kPlmHeader_D6EA) { v2 -= 2; - if ((v2 & 0x8000u) != 0) { + if ((v2 & 0x8000) != 0) { QueueMusic_Delayed8(g_word_AAB096); E->base.properties &= ~kEnemyProps_Tangible; ++E->base.current_instruction; @@ -567,12 +549,12 @@ void Torizo_Func_4(uint16 k) { // 0xAAC6C6 void Torizo_Func_1(uint16 k) { // 0xAAC6FF Torizo_C620(k); Enemy_Torizo *E = Get_Torizo(k); - if ((E->toriz_parameter_2 & 0x8000u) != 0 || E->base.health >= 0x15Eu) { - if ((E->toriz_parameter_2 & 0x4000) != 0 || E->base.health >= 0x64u) { + if ((E->toriz_parameter_2 & 0x8000) != 0 || E->base.health >= 0x15E) { + if ((E->toriz_parameter_2 & 0x4000) != 0 || E->base.health >= 0x64) { CallEnemyPreInstr(E->toriz_var_F | 0xAA0000); } else { uint16 v2; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v2 = addr_kTorizo_Ilist_BD0E; else v2 = addr_kTorizo_Ilist_C188; @@ -595,14 +577,12 @@ void Torizo_Func_5(uint16 k) { // 0xAAC752 if ((E->toriz_parameter_2 & 0x4000) != 0) { uint16 torizo_var_03 = E->toriz_var_03; if (!torizo_var_03 || (v8 = torizo_var_03 - 1, (E->toriz_var_03 = v8) != 0)) { - R18_ = 0; uint16 v10 = abs16(E->toriz_var_A) + 1; - if (v10 >= 0x10u) + if (v10 >= 0x10) v10 = 15; - R20_ = v10; - if (!(Enemy_MoveDown(k) & 1)) { + if (!(Enemy_MoveDown(k, INT16_SHL16(v10)))) { uint16 v11; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v11 = addr_off_AAC0F2; else v11 = addr_off_AABC78; @@ -614,7 +594,7 @@ void Torizo_Func_5(uint16 k) { // 0xAAC752 } else { E->toriz_var_03 = 0; uint16 v9; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v9 = addr_kTorizo_Ilist_BD0E; else v9 = addr_kTorizo_Ilist_C188; @@ -624,14 +604,12 @@ void Torizo_Func_5(uint16 k) { // 0xAAC752 } else { uint16 v2 = E->toriz_var_03; if (!v2 || (v3 = v2 - 1, (E->toriz_var_03 = v3) != 0)) { - R18_ = 0; uint16 v5 = abs16(E->toriz_var_A) + 1; - if (v5 >= 0x10u) + if (v5 >= 0x10) v5 = 15; - R20_ = v5; - if (!(Enemy_MoveDown(k) & 1)) { + if (!(Enemy_MoveDown(k, INT16_SHL16(v5)))) { uint16 v6; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v6 = addr_off_AAC0F2; else v6 = addr_off_AABC78; @@ -643,7 +621,7 @@ void Torizo_Func_5(uint16 k) { // 0xAAC752 } else { E->toriz_var_03 = 0; uint16 v4; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v4 = addr_kTorizo_Ilist_B962; else v4 = addr_kTorizo_Ilist_BDD8; @@ -658,25 +636,10 @@ void Torizo_Func_6(uint16 k) { // 0xAAC828 } void Torizo_Func_7(uint16 k) { // 0xAAC82C - int16 torizo_var_A; - int16 torizo_var_B; - - R18_ = 0; - R20_ = 0; Enemy_Torizo *E = Get_Torizo(k); - torizo_var_A = E->toriz_var_A; - if (torizo_var_A < 0) - --R20_; - R19_ = torizo_var_A; - Enemy_MoveRight_IgnoreSlopes(k); + Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->toriz_var_A)); EnemyFunc_C8AD(k); - R18_ = 0; - R20_ = 0; - torizo_var_B = E->toriz_var_B; - if (torizo_var_B < 0) - --R20_; - R19_ = torizo_var_B; - if (Enemy_MoveDown(k) & 1) { + if (Enemy_MoveDown(k, INT16_SHL8(E->toriz_var_B))) { E->base.current_instruction = E->toriz_var_00; E->base.instruction_timer = 1; E->toriz_var_B = 256; @@ -689,12 +652,12 @@ void Torizo_Func_7(uint16 k) { // 0xAAC82C void Torizo_Init(void) { // 0xAAC87F Enemy_Torizo *E = Get_Torizo(cur_enemy_index); - if (CheckBossBitForCurArea(4u) & 1) { + if (CheckBossBitForCurArea(4) & 1) { E->base.properties |= kEnemyProps_Deleted; } else { int v2 = area_index >> 1; E->base.properties |= g_word_AAC96B[v2]; - E->base.extra_properties |= 4u; + E->base.extra_properties |= 4; E->base.x_width = g_word_AAC96F[v2]; E->base.y_height = g_word_AAC973[v2]; E->toriz_var_E = FUNC16(Torizo_Func_3); @@ -753,7 +716,7 @@ void Torizo_Shot(void) { // 0xAAC97C E->toriz_var_E = FUNC16(nullsub_270); E->base.current_instruction = addr_kTorizo_Ilist_B1C8; E->base.instruction_timer = 1; - E->toriz_parameter_2 |= 0xC000u; + E->toriz_parameter_2 |= 0xC000; E->base.properties |= kEnemyProps_Tangible; } } @@ -778,7 +741,7 @@ const uint16 *Torizo_Instr_41(uint16 k, const uint16 *jp) { // 0xAACADE } const uint16 *Torizo_Instr_42(uint16 k, const uint16 *jp) { // 0xAACAE2 - QueueMusic_Delayed8(5u); + QueueMusic_Delayed8(5); Enemy_Torizo *E = Get_Torizo(k); E->base.x_width = 18; E->base.y_height = 48; @@ -788,12 +751,11 @@ const uint16 *Torizo_Instr_42(uint16 k, const uint16 *jp) { // 0xAACAE2 const uint16 *Torizo_Instr_48(uint16 k, const uint16 *jp) { // 0xAACDD7 Enemy_Torizo *E = Get_Torizo(k); - E->toriz_parameter_2 &= ~0x1000u; + E->toriz_parameter_2 &= ~0x1000; return jp; } const uint16 *Torizo_Instr_57(uint16 k, const uint16 *jp) { // 0xAAD0E9 - //printf("A unknown\n"); SpawnEnemyProjectileWithRoomGfx(addr_stru_86B1C0, 0); return jp; } @@ -812,19 +774,19 @@ const uint16 *Torizo_Instr_58(uint16 k, const uint16 *jp) { // 0xAAD0F3 const uint16 *Torizo_Instr_59(uint16 k, const uint16 *jp) { // 0xAAD17B Enemy_Torizo *E = Get_Torizo(k); - E->toriz_var_06 &= ~0x8000u; + E->toriz_var_06 &= ~0x8000; return jp; } const uint16 *Torizo_Instr_62(uint16 k, const uint16 *jp) { // 0xAAD187 Enemy_Torizo *E = Get_Torizo(k); - E->toriz_var_06 |= 0x8000u; + E->toriz_var_06 |= 0x8000; return jp; } const uint16 *Torizo_Instr_63(uint16 k, const uint16 *jp) { // 0xAAD1E7 Enemy_Torizo *E = Get_Torizo(k); - E->toriz_parameter_2 &= ~0x2000u; + E->toriz_parameter_2 &= ~0x2000; return jp; } @@ -841,17 +803,17 @@ void GoldTorizo_Main(void) { // 0xAAD369 } const uint16 *Torizo_Instr_56(uint16 k, const uint16 *jp) { // 0xAAD38F - QueueSfx2_Max6(0x34u); + QueueSfx2_Max6(0x34); return jp; } const uint16 *Torizo_Instr_60(uint16 k, const uint16 *jp) { // 0xAAD397 - QueueSfx2_Max6(0x67u); + QueueSfx2_Max6(0x67); return jp; } const uint16 *Torizo_Instr_46(uint16 k, const uint16 *jp) { // 0xAAD39F - QueueSfx2_Max6(0x48u); + QueueSfx2_Max6(0x48); return jp; } @@ -879,15 +841,13 @@ void GoldTorizo_Hurt(void) { // 0xAAD3BA } const uint16 *Torizo_Instr_47(uint16 k, const uint16 *jp) { // 0xAAD3E0 - uint16 v2 = 0; - //printf("A unknown\n"); - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_GoldenTorizoSuperMissile, v2); + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_GoldenTorizoSuperMissile, 0); return jp; } const uint16 *Torizo_Instr_49(uint16 k, const uint16 *jp) { // 0xAAD3EA - if ((Torizo_Func_12(k) & 0x8000u) == 0 - || !(CompareDistToSamus_X(k, 4u) & 1) + if ((Torizo_Func_12(k) & 0x8000) == 0 + || !(CompareDistToSamus_X(k, 4) & 1) || CompareDistToSamus_X(k, 0x28) & 1 || samus_pose != kPose_1D_FaceR_Morphball_Ground && samus_pose != kPose_1E_MoveR_Morphball_Ground @@ -908,7 +868,7 @@ const uint16 *Torizo_Instr_61(uint16 k, const uint16 *jp) { // 0xAAD436 } const uint16 *Torizo_Instr_53(uint16 k, const uint16 *jp) { // 0xAAD445 - if ((Torizo_Func_12(k) & 0x8000u) != 0 + if ((Torizo_Func_12(k) & 0x8000) != 0 || !(CompareDistToSamus_X(k, 0x20) & 1) || CompareDistToSamus_X(k, 0x60) & 1 || (NextRandom() & 0x110) != 0) { @@ -920,7 +880,7 @@ const uint16 *Torizo_Instr_53(uint16 k, const uint16 *jp) { // 0xAAD445 const uint16 *Torizo_Instr_55(uint16 k, const uint16 *jp) { // 0xAAD474 Enemy_Torizo *E = Get_Torizo(k); - if (E->base.health > 0x788u || (NextRandom() & 0x102) != 0) + if (E->base.health > 0x788 || (NextRandom() & 0x102) != 0) return INSTR_RETURN_ADDR(jp + 1); E->toriz_var_09 = 0; E->toriz_var_00 = INSTR_ADDR_TO_PTR(k, jp + 1); @@ -929,7 +889,7 @@ const uint16 *Torizo_Instr_55(uint16 k, const uint16 *jp) { // 0xAAD474 const uint16 *Torizo_Instr_52(uint16 k, const uint16 *jp) { // 0xAAD49B Enemy_Torizo *E = Get_Torizo(k); - if (E->base.health <= 0x2A30u || (E->toriz_parameter_2 & 0x2000) == 0) + if (E->base.health <= 0x2A30 || (E->toriz_parameter_2 & 0x2000) == 0) return jp + 1; E->toriz_var_00 = INSTR_ADDR_TO_PTR(k, jp + 1); return INSTR_RETURN_ADDR(jp[0]); @@ -938,10 +898,10 @@ const uint16 *Torizo_Instr_52(uint16 k, const uint16 *jp) { // 0xAAD49B const uint16 *Torizo_Instr_50(uint16 k, const uint16 *jp) { // 0xAAD4BA if (!(CompareDistToSamus_X(k, 0x70) & 1)) return jp + 1; - if ((Torizo_Func_12(k) & 0x8000u) != 0) + if ((Torizo_Func_12(k) & 0x8000) != 0) return jp + 1; Enemy_Torizo *E = Get_Torizo(k); - if (E->toriz_var_07 <= 0x168u && ((joypad1_lastkeys & 0x300) == 0 || (NextRandom() & 0x101) == 0)) + if (E->toriz_var_07 <= 0x168 && ((joypad1_lastkeys & 0x300) == 0 || (NextRandom() & 0x101) == 0)) return jp + 1; E->toriz_var_09 = 0; Torizo_C20A(k); @@ -949,15 +909,13 @@ const uint16 *Torizo_Instr_50(uint16 k, const uint16 *jp) { // 0xAAD4BA } const uint16 *Torizo_Instr_43(uint16 k, const uint16 *jp) { // 0xAAD4F3 - uint16 v2 = 0; - //printf("A unknown\n"); v2 = 0; - SpawnEnemyProjectileWithGfx(v2, k, addr_kEproj_GoldenTorizosChozoOrbs); + SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_GoldenTorizosChozoOrbs); return jp; } const uint16 *Torizo_Instr_51(uint16 k, const uint16 *jp) { // 0xAAD4FD Enemy_Torizo *E = Get_Torizo(k); - if (E->toriz_var_09 < 8u && (CompareDistToSamus_X(k, 0x20) & 1 || (Torizo_Func_12(k) & 0x8000u) != 0)) + if (E->toriz_var_09 < 8 && (CompareDistToSamus_X(k, 0x20) & 1 || (Torizo_Func_12(k) & 0x8000) != 0)) return jp + 1; E->toriz_var_09 = 0; Torizo_C22D(k); @@ -966,8 +924,8 @@ const uint16 *Torizo_Instr_51(uint16 k, const uint16 *jp) { // 0xAAD4FD const uint16 *Torizo_Instr_45(uint16 k, const uint16 *jp) { // 0xAAD526 Get_Torizo(k)->toriz_var_00 = INSTR_ADDR_TO_PTR(k, jp + 2); - if (samus_missiles < 0x20u - || (((uint8)nmi_frame_counter_word + (samus_x_pos & 1) + (uint8)(samus_x_pos >> 1)) & 8) != 0) { + if (samus_missiles < 0x20 + || ((nmi_frame_counter_word + (samus_x_pos & 1) + (samus_x_pos >> 1)) & 8) != 0) { return INSTR_RETURN_ADDR(jp[0]); } else { return INSTR_RETURN_ADDR(jp[1]); @@ -975,19 +933,17 @@ const uint16 *Torizo_Instr_45(uint16 k, const uint16 *jp) { // 0xAAD526 } const uint16 *Torizo_Instr_54(uint16 k, const uint16 *jp) { // 0xAAD54D - R18_ = 0; - R20_ = g_word_AAD59A[jp[0] >> 1]; Enemy_Torizo *E = Get_Torizo(k); - E->toriz_var_A = R20_; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + E->toriz_var_A = g_word_AAD59A[jp[0] >> 1]; + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL16(E->toriz_var_A))) { E->toriz_var_03 = 0; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) return INSTR_RETURN_ADDR(addr_kTorizo_Ilist_D203); else return INSTR_RETURN_ADDR(addr_kTorizo_Ilist_D2BF); } else { EnemyFunc_C8AD(k); - if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000u) == 0) { + if (((E->toriz_parameter_1 ^ (samus_x_pos - E->base.x_pos)) & 0x8000) == 0) { if (!E->toriz_var_03) E->toriz_var_03 = 16; return jp + 1; @@ -999,7 +955,7 @@ const uint16 *Torizo_Instr_54(uint16 k, const uint16 *jp) { // 0xAAD54D void Torizo_Func_9(uint16 k) { // 0xAAD5C2 Enemy_Torizo *E = Get_Torizo(cur_enemy_index); - if (samus_y_pos > 0x140u && samus_x_pos > 0x170u) { + if (samus_y_pos > 0x140 && samus_x_pos > 0x170) { ++E->base.current_instruction; ++E->base.current_instruction; E->base.instruction_timer = 1; @@ -1027,14 +983,12 @@ void Torizo_D5F1(uint16 k) { // 0xAAD5F1 Enemy_Torizo *E = Get_Torizo(k); uint16 torizo_var_03 = E->toriz_var_03; if (!torizo_var_03 || (v3 = torizo_var_03 - 1, (E->toriz_var_03 = v3) != 0)) { - R18_ = 0; uint16 v5 = abs16(E->toriz_var_A) + 1; - if (v5 >= 0x10u) + if (v5 >= 0x10) v5 = 15; - R20_ = v5; - if (!(Enemy_MoveDown(k) & 1)) { + if (!(Enemy_MoveDown(k, INT16_SHL16(v5)))) { uint16 v6; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v6 = addr_off_AAC0F2; else v6 = addr_off_AABC78; @@ -1046,7 +1000,7 @@ void Torizo_D5F1(uint16 k) { // 0xAAD5F1 } else { E->toriz_var_03 = 0; uint16 v4; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v4 = addr_kTorizo_Ilist_D203; else v4 = addr_kTorizo_Ilist_D2BF; @@ -1080,7 +1034,7 @@ void GoldTorizo_Shot(void) { // 0xAAD667 } if (v3 != 512) { LABEL_11: - E->toriz_parameter_2 |= 0x2000u; + E->toriz_parameter_2 |= 0x2000; Torizo_D6A6(); } else { Torizo_D6F7(cur_enemy_index, v2); @@ -1094,18 +1048,18 @@ void Torizo_D6A6(void) { // 0xAAD6A6 if (!E->base.health) { E->base.current_instruction = addr_kTorizo_Ilist_B1C8; E->base.instruction_timer = 1; - E->toriz_parameter_2 |= 0xC000u; + E->toriz_parameter_2 |= 0xC000; E->base.properties |= kEnemyProps_Tangible; } } void Torizo_D6D1(uint16 k, uint16 j) { // 0xAAD6D1 - projectile_dir[j >> 1] &= ~0x10u; + projectile_dir[j >> 1] &= ~0x10; Enemy_Torizo *E = Get_Torizo(k); E->toriz_var_E = FUNC16(nullsub_270); E->base.instruction_timer = 1; uint16 v3; - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v3 = addr_kTorizo_Ilist_D2AD; else v3 = addr_kTorizo_Ilist_D1F1; @@ -1115,18 +1069,18 @@ void Torizo_D6D1(uint16 k, uint16 j) { // 0xAAD6D1 void Torizo_D6F7(uint16 k, uint16 j) { // 0xAAD6F7 Enemy_Torizo *E = Get_Torizo(cur_enemy_index); - if ((Torizo_Func_12(k) & 0x8000u) == 0) { - E->toriz_parameter_2 |= 0x1000u; + if ((Torizo_Func_12(k) & 0x8000) == 0) { + E->toriz_parameter_2 |= 0x1000; E->toriz_var_E = FUNC16(nullsub_270); - projectile_dir[j >> 1] |= 0x10u; + projectile_dir[j >> 1] |= 0x10; E->base.instruction_timer = 1; uint16 v3; if ((E->toriz_parameter_1 & 0x2000) != 0) { - if ((E->toriz_parameter_1 & 0x8000u) != 0) + if ((E->toriz_parameter_1 & 0x8000) != 0) v3 = addr_kTorizo_Ilist_CEFF; else v3 = addr_kTorizo_Ilist_CE43; - } else if ((E->toriz_parameter_1 & 0x8000u) != 0) { + } else if ((E->toriz_parameter_1 & 0x8000) != 0) { v3 = addr_kTorizo_Ilist_CEA5; } else { v3 = addr_kTorizo_Ilist_CDE1; @@ -1145,7 +1099,6 @@ void TourianEntranceStatue_Init(void) { // 0xAAD7C8 uint16 v1 = g_off_AAD810[v0->parameter_1 >> 1]; v0->current_instruction = v1; if (!v0->parameter_1) { -// printf("A unknown\n"); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueBaseDecoration, 0); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatueRidley, 0); SpawnEnemyProjectileWithRoomGfx(addr_kEproj_TourianStatuePhantoon, 0); @@ -1180,31 +1133,10 @@ const uint16 *Shaktool_Instr_5(uint16 k, const uint16 *jp) { // 0xAAD953 } const uint16 *Shaktool_D956(uint16 k, const uint16 *jp, uint16 a) { // 0xAAD956 - int16 v4; - int16 v8; - - R18_ = 0; - R20_ = 0; - int v3 = (uint16)(2 * (uint8)a) >> 1; - v4 = kSinCosTable8bit_Sext[v3 + 64]; - if (v4 < 0) - --R20_; - R19_ = v4; Enemy_Shaktool *E = Get_Shaktool(k); - uint16 x_subpos = E->base.x_subpos; - bool v7 = __CFADD__uint16(R18_, x_subpos); - E->base.x_subpos = R18_ + x_subpos; - E->base.x_pos += R20_ + v7; - R18_ = 0; - R20_ = 0; - v8 = kSinCosTable8bit_Sext[v3]; - if (v8 < 0) - --R20_; - R19_ = v8; - uint16 y_subpos = E->base.y_subpos; - v7 = __CFADD__uint16(R18_, y_subpos); - E->base.y_subpos = R18_ + y_subpos; - E->base.y_pos += R20_ + v7; + int v3 = (uint8)a; + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, INT16_SHL8(kSinCosTable8bit_Sext[v3 + 64])); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, INT16_SHL8(kSinCosTable8bit_Sext[v3])); return jp; } @@ -1213,7 +1145,6 @@ const uint16 *Shaktool_Instr_6(uint16 k, const uint16 *jp) { // 0xAAD99F } void Shaktool_Func_2(uint16 k) { // 0xAAD9A0 -// printf("A unknown!\n"); SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_ShaktoolAttackFrontCircle); SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_ShaktoolAttackMiddleCircle); SpawnEnemyProjectileWithGfx(0, k, addr_kEproj_ShaktoolAttackBackCircle); @@ -1288,7 +1219,7 @@ void Shaktool_DB59(uint16 k) { // 0xAADB59 shakto_var_E = Get_Shaktool(k)->shakt_var_E; Enemy_Shaktool *Shaktool = Get_Shaktool(shakto_var_E + 192); - Shaktool->shakt_var_D ^= 0x8000u; + Shaktool->shakt_var_D ^= 0x8000; Enemy_Shaktool *v3 = Get_Shaktool(shakto_var_E + 384); shakto_var_B = v3->shakt_var_B; Enemy_Shaktool *v5 = Get_Shaktool(shakto_var_E + 64); @@ -1333,7 +1264,7 @@ void Shaktool_DB59(uint16 k) { // 0xAADB59 void Shaktool_DC07(uint16 k) { // 0xAADC07 Enemy_Shaktool *E = Get_Shaktool(k); uint16 v2; - if ((E->shakt_parameter_1 & 0x8000u) != 0) + if ((E->shakt_parameter_1 & 0x8000) != 0) v2 = E->shakt_var_B - E->shakt_var_A; else v2 = E->shakt_var_A - E->shakt_var_B; @@ -1341,31 +1272,13 @@ void Shaktool_DC07(uint16 k) { // 0xAADC07 } void Shaktool_DC2A(uint16 k) { // 0xAADC2A - int16 v4; - int16 v7; - Enemy_Shaktool *E = Get_Shaktool(k); - uint16 v2 = 2 * HIBYTE(E->shakt_var_B); - R18_ = 0; - R20_ = 0; - int v3 = v2 >> 1; - v4 = kSine[v3]; - if (v4 < 0) - --R20_; - R19_ = v4; + int v3 = HIBYTE(E->shakt_var_B); int v5 = k >> 1; - bool v6 = __CFADD__uint16(enemy_drawing_queue[v5 + 92], R18_); - E->base.x_subpos = enemy_drawing_queue[v5 + 92] + R18_; - E->base.x_pos = enemy_drawing_queue[v5 + 91] + v6 + R20_; - R18_ = 0; - R20_ = 0; - v7 = kNegativeCosine[v3]; - if (v7 < 0) - --R20_; - R19_ = v7; - v6 = __CFADD__uint16(enemy_drawing_queue[v5 + 94], R18_); - E->base.y_subpos = enemy_drawing_queue[v5 + 94] + R18_; - E->base.y_pos = enemy_drawing_queue[v5 + 93] + v6 + R20_; + SetHiLo(&E->base.x_pos, &E->base.x_subpos, INT16_SHL8(kSine[v3]) + + __PAIR32__(enemy_drawing_queue[v5 + 91], enemy_drawing_queue[v5 + 92])); + SetHiLo(&E->base.y_pos, &E->base.y_subpos, INT16_SHL8(kNegativeCosine[v3]) + + __PAIR32__(enemy_drawing_queue[v5 + 93], enemy_drawing_queue[v5 + 94])); } void Shaktool_DC6F(uint16 k) { // 0xAADC6F @@ -1400,13 +1313,11 @@ void Shaktool_DCAC(uint16 k) { // 0xAADCAC } void Shaktool_DCD7(uint16 k) { // 0xAADCD7 - int16 v2; - Shaktool_DCAC(k); Enemy_Shaktool *E = Get_Shaktool(k); - R18_ = E->shakt_var_B ^ 0x8000; - v2 = R18_ + ((uint16)(Get_Shaktool(k + 64)->shakt_var_B - R18_) >> 1); - if ((E->shakt_var_D & 0x8000u) != 0) + uint16 r18 = E->shakt_var_B ^ 0x8000; + int16 v2 = r18 + ((uint16)(Get_Shaktool(k + 64)->shakt_var_B - r18) >> 1); + if ((E->shakt_var_D & 0x8000) != 0) HIBYTE(v2) ^= 0x80; uint16 v3 = (HIBYTE(v2) + 8) & 0xE0; LOBYTE(E->shakt_var_D) = v3; @@ -1425,10 +1336,8 @@ void Shaktool_DD25(uint16 k) { // 0xAADD25 uint16 v11 = E->base.x_pos; E->base.x_pos = x_pos; E->base.y_pos = y_pos; - R18_ = 0; - R20_ = v11 - x_pos; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1 - || (E->base.y_pos = y_pos, R18_ = 0, R20_ = v12 - y_pos, Enemy_MoveDown(k) & 1)) { + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL16(v11 - x_pos)) + || (E->base.y_pos = y_pos, Enemy_MoveDown(k, INT16_SHL16(v12 - y_pos)))) { if ((E->shakt_parameter_1 & 0x2000) != 0) { Shaktool_DB0E(k, (E->shakt_parameter_1 ^ 0x8000) & 0x8FFF); } else { @@ -1442,7 +1351,7 @@ void Shaktool_DD25(uint16 k) { // 0xAADD25 uint16 v5 = CalculateAngleOfEnemyXfromEnemyY(k, E->shakt_var_E); v7 = v5 << 8; uint16 v8; - if ((E->shakt_parameter_1 & 0x8000u) != 0) + if ((E->shakt_parameter_1 & 0x8000) != 0) v8 = v7 - 0x4000; else v8 = v7 + 0x4000; @@ -1469,7 +1378,7 @@ void Shaktool_DD25(uint16 k) { // 0xAADD25 } uint16 v2 = E->shakt_var_D + E->shakt_var_C; E->shakt_var_D = v2; - if (v2 >= 0xF000u) + if (v2 >= 0xF000) Shaktool_DB0E(k, E->shakt_parameter_1 | 0x4000); } } @@ -1525,7 +1434,7 @@ const uint16 *Shaktool_Instr_11(uint16 k, const uint16 *jp) { // 0xAAE436 } const uint16 *Shaktool_Instr_10(uint16 k, const uint16 *jp) { // 0xAAE43D - CallSomeSamusCode(1u); + CallSomeSamusCode(1); return jp; } @@ -1538,12 +1447,12 @@ void sub_AAE445(uint16 k) { // 0xAAE445 } const uint16 *Shaktool_Instr_8(uint16 k, const uint16 *jp) { // 0xAAE57F - QueueSfx2_Max6(0x1Cu); + QueueSfx2_Max6(0x1C); return jp; } const uint16 *Shaktool_Instr_13(uint16 k, const uint16 *jp) { // 0xAAE587 - QueueSfx2_Max6(0x4Bu); + QueueSfx2_Max6(0x4B); return jp; } @@ -1560,26 +1469,10 @@ const uint16 *Shaktool_Instr_12(uint16 k, const uint16 *jp) { // 0xAAE58F } const uint16 *Shaktool_Instr_7(uint16 k, const uint16 *jp) { // 0xAAE5D8 - int16 v4; - int16 v5; - - uint16 v2 = jp[0]; Enemy_Shaktool *E = Get_Shaktool(k); - E->shakt_var_C = v2; - R18_ = 0; - R20_ = 0; - v4 = g_word_AAE630[E->shakt_var_C >> 1]; - if (v4 < 0) - --R20_; - R19_ = v4; - Enemy_MoveRight_IgnoreSlopes(k); - R18_ = 0; - R20_ = 0; - v5 = abs16(g_word_AAE630[E->shakt_var_C >> 1]); - if (v5 < 0) - --R20_; - R19_ = v5; - Enemy_MoveDown(k); + E->shakt_var_C = jp[0]; + Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(g_word_AAE630[E->shakt_var_C >> 1])); + Enemy_MoveDown(k, INT16_SHL8(abs16(g_word_AAE630[E->shakt_var_C >> 1]))); EnemyFunc_C8AD(k); int v6 = E->shakt_var_C >> 1; samus_x_pos = g_word_AAE670[v6] + E->base.x_pos; @@ -1588,13 +1481,12 @@ const uint16 *Shaktool_Instr_7(uint16 k, const uint16 *jp) { // 0xAAE5D8 } const uint16 *Shaktool_Instr_14(uint16 k, const uint16 *jp) { // 0xAAE6F0 - CallSomeSamusCode(1u); + CallSomeSamusCode(1); *(uint16 *)&scrolls[6] = 0; *(uint16 *)&scrolls[8] = 0; *(uint16 *)&scrolls[9] = 0; *(uint16 *)&scrolls[13] = 1; - static const SpawnHardcodedPlmArgs unk_AAE711 = { 0x17, 0x1d, 0xd6fc }; - SpawnHardcodedPlm(&unk_AAE711); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x17, 0x1d, 0xd6fc }); return jp; } @@ -1623,22 +1515,18 @@ void ChozoStatue_Init(void) { // 0xAAE725 target_palettes[v3 + 160] = kChozoStatue_Palettes[v3]; target_palettes[v3 + 144] = kChozoStatue_Palette[v3]; } - static const SpawnHardcodedPlmArgs unk_AAE77F = { 0x17, 0x1d, 0xd6fc }; - static const SpawnHardcodedPlmArgs unk_AAE777 = { 0x4a, 0x17, 0xd6ee }; - SpawnHardcodedPlm(&unk_AAE777); - SpawnHardcodedPlm(&unk_AAE77F); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x4a, 0x17, 0xd6ee }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x17, 0x1d, 0xd6fc }); } } -static const SpawnHardcodedPlmArgs unk_AAE79D = { 0x0c, 0x1d, 0xd6d6 }; - void sub_AAE784(void) { // 0xAAE784 for (int i = 30; i >= 0; i -= 2) { int v1 = i >> 1; target_palettes[v1 + 160] = kChozoStatue_Palettes3[v1]; target_palettes[v1 + 144] = kChozoStatue_Palettes2[v1]; } - SpawnHardcodedPlm(&unk_AAE79D); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0c, 0x1d, 0xd6d6 }); } void ChozoStatue_Main(void) { // 0xAAE7A7 @@ -1656,4 +1544,4 @@ void Shaktool_PreInstr_0(uint16 k) { // 0xAAE7AE E->shakt_var_B = 256; } } -} \ No newline at end of file +} diff --git a/src/sm_ad.c b/src/sm_ad.c index cce72d2..2ed4c32 100644 --- a/src/sm_ad.c +++ b/src/sm_ad.c @@ -13,8 +13,6 @@ #define kMotherBrain_FadeToGray_RealDeath ((uint16*)RomFixedPtr(0xadf107)) #define kMotherBrain_Phase3_TurnLightsBackOn ((uint16*)RomFixedPtr(0xadf273)) - - void nullsub_341(void) {} static Func_V *const funcs_BE56D[16] = { @@ -24,30 +22,26 @@ static Func_V *const funcs_BE56D[16] = { MotherBrain_CalcHdma_Down, 0, 0, MotherBrain_CalcHdma_Down, }; - - void MotherBrain_CalcHdma(void) { // 0xADDE00 Enemy_MotherBrain *E = Get_MotherBrain(0); Enemy_MotherBrain *E1 = Get_MotherBrain(0x40); - R18_ = HIBYTE(E->mbn_var_33) >> 1; - E->mbn_var_3A = E->mbn_var_31 - R18_; - E->mbn_var_3B = R18_ + E->mbn_var_31; + uint16 r18 = HIBYTE(E->mbn_var_33) >> 1; + E->mbn_var_3A = E->mbn_var_31 - r18; + E->mbn_var_3B = r18 + E->mbn_var_31; uint16 v2 = (*(uint16 *)((uint8 *)&E1->base.enemy_ptr + 1) + 3584) & 0xFF00; E->mbn_var_3C = v2; E->mbn_var_3E = v2; uint16 v3 = E1->base.y_pos + 5; E->mbn_var_3D = v3; E->mbn_var_3F = v3; - R18_ = 4 * (E->mbn_var_3A & 0xC0); - int i = (R18_ | E->mbn_var_3B & 0xC0) >> 6; + r18 = 4 * (E->mbn_var_3A & 0xC0); + int i = (r18 | E->mbn_var_3B & 0xC0) >> 6; funcs_BE56D[i](); } void MotherBrain_CalcHdma_BeamAimedRight2(void) { // 0xADDE7F Enemy_MotherBrain *E = Get_MotherBrain(0); - R22_ = E->mbn_var_3C; - R24_ = E->mbn_var_3E; - MotherBrain_CalcHdma_BeamAimedRight(); + MotherBrain_CalcHdma_BeamAimedRight(E->mbn_var_3C, E->mbn_var_3E); *(uint16 *)mother_brain_indirect_hdma = 16; *(uint16 *)&mother_brain_indirect_hdma[1] = -25600; *(uint16 *)&mother_brain_indirect_hdma[3] = 16; @@ -59,22 +53,22 @@ void MotherBrain_CalcHdma_BeamAimedRight2(void) { // 0xADDE7F *(uint16 *)&mother_brain_indirect_hdma[12] = 0; } -void MotherBrain_CalcHdma_BeamAimedRight(void) { // 0xADDECE +void MotherBrain_CalcHdma_BeamAimedRight(uint16 r22, uint16 r24) { // 0xADDECE hdma_table_2[0] = 255; hdma_table_2[1] = 255; Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = kTanTable[LOBYTE(E->mbn_var_3A)]; - R20_ = kTanTable[LOBYTE(E->mbn_var_3B)]; + uint16 r18 = kTanTable[LOBYTE(E->mbn_var_3A)]; + uint16 r20 = kTanTable[LOBYTE(E->mbn_var_3B)]; uint16 mbn_var_3F = E->mbn_var_3F; uint16 *v2 = hdma_table_2 + (mbn_var_3F - 32) + 1; v2[1] = 255; v2[2] = 255; uint16 *v8 = v2; do { - uint16 v4 = R20_ + R24_; - if (__CFADD__uint16(R20_, R24_)) + uint16 v4 = r20 + r24; + if (__CFADD__uint16(r20, r24)) break; - R24_ += R20_; + r24 += r20; *v2-- = HIBYTE(v4) | 0xFF00; --mbn_var_3F; } while (mbn_var_3F != 32); @@ -85,10 +79,10 @@ void MotherBrain_CalcHdma_BeamAimedRight(void) { // 0xADDECE uint16 *v5 = v8 + 1; uint16 var_3F = gRam8000_Default(0)->var_3F; while (1) { - uint16 v7 = R18_ + R22_; - if (__CFADD__uint16(R18_, R22_)) + uint16 v7 = r18 + r22; + if (__CFADD__uint16(r18, r22)) break; - R22_ += R18_; + r22 += r18; *v5++ = HIBYTE(v7) | 0xFF00; if (++var_3F == 232) return; @@ -99,7 +93,8 @@ void MotherBrain_CalcHdma_BeamAimedRight(void) { // 0xADDECE } while (var_3F != 232); } -static Func_V *const off_ADE024[4] = { // 0xADDF6E +typedef void Func_CalcHdma(uint16 r22, uint16 r24); +static Func_CalcHdma *const off_ADE024[4] = { // 0xADDF6E MotherBrain_CalcHdma_Up_UpRight, MotherBrain_CalcHdma_Up_Up, 0, @@ -108,12 +103,7 @@ static Func_V *const off_ADE024[4] = { // 0xADDF6E void MotherBrain_CalcHdma_BeamAimedUp(void) { Enemy_MotherBrain *E = Get_MotherBrain(0); - R22_ = E->mbn_var_3C; - R24_ = E->mbn_var_3E; - - R18_ = (E->mbn_var_3A >> 6) & 2 | (E->mbn_var_3B >> 7) & 1; - - off_ADE024[R18_ & 3](); + off_ADE024[(E->mbn_var_3A >> 6) & 2 | (E->mbn_var_3B >> 7) & 1](E->mbn_var_3C, E->mbn_var_3E); *(uint16 *)mother_brain_indirect_hdma = 16; *(uint16 *)&mother_brain_indirect_hdma[1] = -25344; *(uint16 *)&mother_brain_indirect_hdma[3] = 16; @@ -122,7 +112,6 @@ void MotherBrain_CalcHdma_BeamAimedUp(void) { uint16 v2 = E->mbn_var_3D - 32; printf("Carry crap!\n"); if (v2 >= 0x80) { - R18_ = E->mbn_var_3D - 159; *(uint16 *)&mother_brain_indirect_hdma[6] = (v2 - 127) | 0x80; *(uint16 *)&mother_brain_indirect_hdma[7] = -25340; *(uint16 *)&mother_brain_indirect_hdma[9] = 255; @@ -139,26 +128,26 @@ void MotherBrain_CalcHdma_BeamAimedUp(void) { } } -void MotherBrain_CalcHdma_Up_UpRight(void) { // 0xADE02C +void MotherBrain_CalcHdma_Up_UpRight(uint16 r22, uint16 r24) { // 0xADE02C hdma_table_2[0] = 255; hdma_table_2[1] = 255; Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = kTanTable[LOBYTE(E->mbn_var_3B)]; - R20_ = kTanTable[LOBYTE(E->mbn_var_3A)]; + uint16 r18 = kTanTable[LOBYTE(E->mbn_var_3B)]; + uint16 r20 = kTanTable[LOBYTE(E->mbn_var_3A)]; uint16 mbn_var_3D = E->mbn_var_3D; uint16 *v2 = hdma_table_2 + (mbn_var_3D - 32) + 1; v2[1] = 255; v2[2] = 255; do { - uint16 v4 = R18_ + R22_; - if (__CFADD__uint16(R18_, R22_)) + uint16 v4 = r18 + r22; + if (__CFADD__uint16(r18, r22)) v4 = -1; - R22_ = v4; - R36 = (v4 >> 8) & 0xff; - uint16 v7 = R20_ + R24_; - if (__CFADD__uint16(R20_, R24_)) + r22 = v4; + uint16 R36 = (v4 >> 8) & 0xff; + uint16 v7 = r20 + r24; + if (__CFADD__uint16(r20, r24)) v7 = -1; - R24_ = v7; + r24 = v7; uint16 v8 = R36 | v7 & 0xFF00; if (v8 == 0xffff) v8 = 255; @@ -167,27 +156,27 @@ void MotherBrain_CalcHdma_Up_UpRight(void) { // 0xADE02C } while (mbn_var_3D != 32); } -void MotherBrain_CalcHdma_Up_Up(void) { // 0xADE0A6 +void MotherBrain_CalcHdma_Up_Up(uint16 r22, uint16 r24) { // 0xADE0A6 hdma_table_2[0] = 255; hdma_table_2[1] = 255; Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = kTanTable[(uint8)-LOBYTE(E->mbn_var_3B)]; - R20_ = kTanTable[LOBYTE(E->mbn_var_3A)]; + uint16 r18 = kTanTable[(uint8)-LOBYTE(E->mbn_var_3B)]; + uint16 r20 = kTanTable[LOBYTE(E->mbn_var_3A)]; uint16 mbn_var_3D = E->mbn_var_3D; uint16 *v2 = hdma_table_2 + (mbn_var_3D - 32) + 1; v2[1] = 255; v2[2] = 255; do { - uint16 v4 = R22_ - R18_; - if (R22_ < R18_) + uint16 v4 = r22 - r18; + if (r22 < r18) v4 = 0; - R22_ = v4; - R26_ = (uint8)(v4 >> 8); - uint16 v7 = R20_ + R24_; - if (__CFADD__uint16(R20_, R24_)) + r22 = v4; + uint16 r26 = (uint8)(v4 >> 8); + uint16 v7 = r20 + r24; + if (__CFADD__uint16(r20, r24)) v7 = -1; - R24_ = v7; - uint16 v8 = R26_ | v7 & 0xFF00; + r24 = v7; + uint16 v8 = r26 | v7 & 0xFF00; if (v8 == 0xffff) v8 = 255; *v2-- = v8; @@ -195,26 +184,26 @@ void MotherBrain_CalcHdma_Up_Up(void) { // 0xADE0A6 } while (mbn_var_3D != 32); } -void MotherBrain_CalcHdma_Up_UpLeft(void) { // 0xADE124 +void MotherBrain_CalcHdma_Up_UpLeft(uint16 r22, uint16 r24) { // 0xADE124 hdma_table_2[0] = 255; hdma_table_2[1] = 255; Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = kTanTable[(uint8)-LOBYTE(E->mbn_var_3B)]; - R20_ = kTanTable[(uint8)-LOBYTE(E->mbn_var_3A)]; + uint16 r18 = kTanTable[(uint8)-LOBYTE(E->mbn_var_3B)]; + uint16 r20 = kTanTable[(uint8)-LOBYTE(E->mbn_var_3A)]; uint16 mbn_var_3D = E->mbn_var_3D; uint16 *v2 = hdma_table_2 + (mbn_var_3D - 32) + 1; v2[1] = 255; v2[2] = 255; do { - uint16 v4 = R22_ - R18_; - if (R22_ < R18_) + uint16 v4 = r22 - r18; + if (r22 < r18) v4 = 0; - R22_ = v4; - R36 = v4 >> 8; - uint16 v7 = R24_ - R20_; - if (R24_ < R20_) + r22 = v4; + uint16 R36 = v4 >> 8; + uint16 v7 = r24 - r20; + if (r24 < r20) v7 = 0; - R24_ = v7; + r24 = v7; uint16 v8 = R36 | v7 & 0xFF00; if (v8 == 0xffff) v8 = 255; @@ -222,15 +211,11 @@ void MotherBrain_CalcHdma_Up_UpLeft(void) { // 0xADE124 --mbn_var_3D; } while (mbn_var_3D != 32); } -static Func_V *const g_off_ADE20E[4] = { MotherBrain_CalcHdma_Down_DownRight, 0, MotherBrain_CalcHdma_Down_Down, MotherBrain_CalcHdma_Down_DownLeft }; + +static Func_CalcHdma *const g_off_ADE20E[4] = { MotherBrain_CalcHdma_Down_DownRight, 0, MotherBrain_CalcHdma_Down_Down, MotherBrain_CalcHdma_Down_DownLeft }; void MotherBrain_CalcHdma_Down(void) { // 0xADE1A6 Enemy_MotherBrain *E = Get_MotherBrain(0); - R22_ = E->mbn_var_3C; - R24_ = E->mbn_var_3E; - - R18_ = (E->mbn_var_3A >> 6) & 2 | (E->mbn_var_3B >> 7) & 1; - - g_off_ADE20E[R18_ & 3](); + g_off_ADE20E[(E->mbn_var_3A >> 6) & 2 | (E->mbn_var_3B >> 7) & 1](E->mbn_var_3C, E->mbn_var_3E); *(uint16 *)mother_brain_indirect_hdma = 16; *(uint16 *)&mother_brain_indirect_hdma[1] = -25600; *(uint16 *)&mother_brain_indirect_hdma[3] = 16; @@ -242,59 +227,29 @@ void MotherBrain_CalcHdma_Down(void) { // 0xADE1A6 *(uint16 *)&mother_brain_indirect_hdma[12] = 0; } -void MotherBrain_CalcHdma_Down_DownRight(void) { // 0xADE216 +void MotherBrain_CalcHdma_Down_DownRight(uint16 r22, uint16 r24) { // 0xADE216 hdma_table_2[0] = 255; hdma_table_2[1] = 255; Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = kTanTable[LOBYTE(E->mbn_var_3A)]; - R20_ = kTanTable[LOBYTE(E->mbn_var_3B)]; + uint16 r18 = kTanTable[LOBYTE(E->mbn_var_3A)]; + uint16 r20 = kTanTable[LOBYTE(E->mbn_var_3B)]; uint16 v1 = E->mbn_var_3D - 32; - uint16 *dst = hdma_table_2 + 1; + uint16 *dst = hdma_table_2 + 2; do { *dst++ = 255; } while (--v1); uint16 mbn_var_3D = Get_MotherBrain(0)->mbn_var_3D; do { - uint16 v4 = R18_ + R22_; - if (__CFADD__uint16(R18_, R22_)) + uint16 v4 = r18 + r22; + if (__CFADD__uint16(r18, r22)) v4 = -1; - R22_ = v4; - R26_ = v4 >> 8; - uint16 v7 = R20_ + R24_; - if (__CFADD__uint16(R20_, R24_)) + r22 = v4; + uint16 r26 = v4 >> 8; + uint16 v7 = r20 + r24; + if (__CFADD__uint16(r20, r24)) v7 = -1; - R24_ = v7; - uint16 v8 = R26_ | v7 & 0xFF00; - if (v8 == -1) - v8 = 255; - *dst++ = v8; - ++mbn_var_3D; - } while (mbn_var_3D != 232); -} - -void MotherBrain_CalcHdma_Down_Down(void) { // 0xADE293 - hdma_table_2[0] = 255; - hdma_table_2[1] = 255; - Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = kTanTable[(uint8)-LOBYTE(E->mbn_var_3A)]; - R20_ = kTanTable[LOBYTE(E->mbn_var_3B)]; - uint16 v1 = E->mbn_var_3D - 32; - uint16 *dst = hdma_table_2 + 1; - do { - *dst++ = 255; - } while (--v1); - uint16 mbn_var_3D = Get_MotherBrain(0)->mbn_var_3D; - do { - uint16 v4 = R22_ - R18_; - if (R22_ < R18_) - v4 = 0; - R22_ = v4; - R26_ = v4 >> 8; - uint16 v7 = R20_ + R24_; - if (__CFADD__uint16(R20_, R24_)) - v7 = -1; - R24_ = v7; - uint16 v8 = R26_ | v7 & 0xFF00; + r24 = v7; + uint16 v8 = r26 | v7 & 0xFF00; if (v8 == 0xffff) v8 = 255; *dst++ = v8; @@ -302,30 +257,60 @@ void MotherBrain_CalcHdma_Down_Down(void) { // 0xADE293 } while (mbn_var_3D != 232); } -void MotherBrain_CalcHdma_Down_DownLeft(void) { // 0xADE314 +void MotherBrain_CalcHdma_Down_Down(uint16 r22, uint16 r24) { // 0xADE293 hdma_table_2[0] = 255; hdma_table_2[1] = 255; Enemy_MotherBrain *E = Get_MotherBrain(0); - R18_ = kTanTable[(uint8)-LOBYTE(E->mbn_var_3A)]; - R20_ = kTanTable[(uint8)-LOBYTE(E->mbn_var_3B)]; + uint16 r18 = kTanTable[(uint8)-LOBYTE(E->mbn_var_3A)]; + uint16 r20 = kTanTable[LOBYTE(E->mbn_var_3B)]; uint16 v1 = E->mbn_var_3D - 32; - uint16 *dst = hdma_table_2 + 1; + uint16 *dst = hdma_table_2 + 2; do { *dst++ = 255; } while (--v1); uint16 mbn_var_3D = Get_MotherBrain(0)->mbn_var_3D; do { - uint16 v4 = R22_ - R18_; - if (R22_ < R18_) + uint16 v4 = r22 - r18; + if (r22 < r18) v4 = 0; - R22_ = v4; + r22 = v4; + uint16 r26 = v4 >> 8; + uint16 v7 = r20 + r24; + if (__CFADD__uint16(r20, r24)) + v7 = -1; + r24 = v7; + uint16 v8 = r26 | v7 & 0xFF00; + if (v8 == 0xffff) + v8 = 255; + *dst++ = v8; + ++mbn_var_3D; + } while (mbn_var_3D != 232); +} + +void MotherBrain_CalcHdma_Down_DownLeft(uint16 r22, uint16 r24) { // 0xADE314 + hdma_table_2[0] = 255; + hdma_table_2[1] = 255; + Enemy_MotherBrain *E = Get_MotherBrain(0); + uint16 r18 = kTanTable[(uint8)-LOBYTE(E->mbn_var_3A)]; + uint16 r20 = kTanTable[(uint8)-LOBYTE(E->mbn_var_3B)]; + uint16 v1 = E->mbn_var_3D - 32; + uint16 *dst = hdma_table_2 + 2; + do { + *dst++ = 255; + } while (--v1); + uint16 mbn_var_3D = Get_MotherBrain(0)->mbn_var_3D; + do { + uint16 v4 = r22 - r18; + if (r22 < r18) + v4 = 0; + r22 = v4; uint16 v5 = v4 >> 8; - R26_ = v5; - uint16 v7 = R24_ - R20_; - if (R24_ < R20_) + uint16 r26 = v5; + uint16 v7 = r24 - r20; + if (r24 < r20) v7 = 0; - R24_ = v7; - uint16 v8 = R26_ | v7 & 0xFF00; + r24 = v7; + uint16 v8 = r26 | v7 & 0xFF00; if (!v8) v8 = 255; *dst++ = v8; @@ -334,28 +319,24 @@ void MotherBrain_CalcHdma_Down_DownLeft(void) { // 0xADE314 } void MotherBrain_SealWall(void) { // 0xADE396 - R18_ = 248; - R20_ = 72; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); - R18_ = 248; - R20_ = 152; - SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9u); - static const SpawnHardcodedPlmArgs unk_ADE3C2 = { 0x0f, 0x04, 0xb673 }; - static const SpawnHardcodedPlmArgs unk_ADE3CA = { 0x0f, 0x09, 0xb673 }; - SpawnHardcodedPlm(&unk_ADE3C2); - SpawnHardcodedPlm(&unk_ADE3CA); + eproj_spawn_pt = (Point16U){ 248, 72 }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); + eproj_spawn_pt = (Point16U){ 248, 152 }; + SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 9); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0f, 0x04, 0xb673 }); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0f, 0x09, 0xb673 }); Get_MotherBrain(0)->mbn_var_A = FUNC16(MotherBrainBody_FakeDeath_Descent_0_Pause); } void MotherBrain_HealthBasedPaletteHandling(void) { // 0xADE3D5 - if (Get_MotherBrain(0)->mbn_var_1F >= 2u) { + if (Get_MotherBrain(0)->mbn_var_1F >= 2) { uint16 v0 = 0; - uint16 health = Get_MotherBrain(0x40u)->base.health; - if (health < 0x2328u) { + uint16 health = Get_MotherBrain(0x40)->base.health; + if (health < 0x2328) { v0 = 2; - if (health < 0x1518u) { + if (health < 0x1518) { v0 = 4; - if (health < 0x708u) + if (health < 0x708) v0 = 6; } } @@ -393,7 +374,7 @@ uint8 MotherBrain_FadeFromGray_FakeDeath(uint16 a) { // 0xADEEEA } uint8 MotherBrain_EEF6(uint16 a) { // 0xADEEF6 - WriteColorsToPalette(0x122, 0xad, a, 3u); + WriteColorsToPalette(0x122, 0xad, a, 3); return 0; } @@ -447,16 +428,16 @@ uint8 MotherBrain_Phase3_TurnLightsBackOn(uint16 a) { // 0xADF24B void EnableEarthquakeAframes(uint16 a) { // 0xADF40B earthquake_type = a; earthquake_timer = 20; - QueueSfx2_Max6(0x25u); + QueueSfx2_Max6(0x25); } void HandleMotherBrainBodyFlickering(void) { // 0xADF41C EnemyData *v0 = gEnemyData(0); if (v0->frame_counter & 1) { - *(uint16 *)®_TM |= 2u; + *(uint16 *)®_TM |= 2; v0->properties &= ~kEnemyProps_Invisible; } else { - *(uint16 *)®_TM &= ~2u; + *(uint16 *)®_TM &= ~2; v0->properties |= kEnemyProps_Invisible; } -} \ No newline at end of file +} diff --git a/src/sm_b2.c b/src/sm_b2.c index a5bf77d..358c1c9 100644 --- a/src/sm_b2.c +++ b/src/sm_b2.c @@ -44,11 +44,11 @@ void WalkingSpacePirates_8789(void) { // 0xB28789 uint16 v1 = cur_enemy_index; if (E->base.enemy_ptr == addr_kEnemyDef_F593) { E->sps_var_B = 0; - EnemyDeathAnimation(v1, 4u); + EnemyDeathAnimation(v1, 4); Enemy_ItemDrop_LowerNorfairSpacePirate(v1); } else { E->sps_var_B = 0; - EnemyDeathAnimation(v1, 4u); + EnemyDeathAnimation(v1, 4); } } } @@ -56,31 +56,28 @@ void WalkingSpacePirates_8789(void) { // 0xB28789 void WalkingSpacePirates_87C8(void) { // 0xB287C8 Vulnerability *v2; int16 v3; - Vulnerability *Vulnerability; + Vulnerability *v; if (Get_SpacePirates(cur_enemy_index)->base.enemy_ptr != addr_kEnemyDef_F593) goto LABEL_2; - R18_ = projectile_type[collision_detection_index]; - if (sign16((R18_ & kProjectileType_TypeMask) - kProjectileType_PowerBomb)) { + uint16 r18 = projectile_type[collision_detection_index]; + if (sign16((r18 & kProjectileType_TypeMask) - kProjectileType_PowerBomb)) { uint16 enemy_ptr; uint16 vulnerability_ptr; enemy_ptr = Get_SpacePirates(cur_enemy_index)->base.enemy_ptr; vulnerability_ptr = get_EnemyDef_A2(enemy_ptr)->vulnerability_ptr; if (!vulnerability_ptr) vulnerability_ptr = addr_stru_B4EC1C; - R20_ = vulnerability_ptr; - if ((R18_ & kProjectileType_TypeMask) != 0) { - if ((R18_ & kProjectileType_TypeMask) != kProjectileType_Missile - && (R18_ & kProjectileType_TypeMask) != kProjectileType_SuperMissile) { + uint16 r20 = vulnerability_ptr; + if ((r18 & kProjectileType_TypeMask) != 0) { + if ((r18 & kProjectileType_TypeMask) != kProjectileType_Missile && (r18 & kProjectileType_TypeMask) != kProjectileType_SuperMissile) goto LABEL_2; - } - LOBYTE(v3) = (uint16)(R18_ & kProjectileType_TypeMask) >> 8; - HIBYTE(v3) = 0; - Vulnerability = get_Vulnerability(R20_ + v3); - if ((Vulnerability->plasma_ice_wave & 0xF) != 0 && (Vulnerability->plasma_ice_wave & 0xF) != 15) + v3 = (uint16)(r18 & kProjectileType_TypeMask) >> 8; + v = get_Vulnerability(r20 + v3); + if ((v->plasma_ice_wave & 0xF) != 0 && (v->plasma_ice_wave & 0xF) != 15) goto LABEL_2; } else { - v2 = get_Vulnerability(R20_ + ((uint8)R18_ & 0xFu)); + v2 = get_Vulnerability(r20 + (r18 & 0xF)); if ((v2->power & 0xF) != 0 && (v2->power & 0xF) != 15) { LABEL_2: WalkingSpacePirates_8789(); @@ -98,11 +95,11 @@ void WalkingSpacePirates_883E(void) { // 0xB2883E } uint16 v0 = 2 * collision_detection_index; int v1 = collision_detection_index; - R18_ = projectile_type[v1]; - if ((R18_ & kProjectileType_TypeMask) == kProjectileType_SuperMissile) { + uint16 r18 = projectile_type[v1]; + if ((r18 & kProjectileType_TypeMask) == kProjectileType_SuperMissile) { if (!projectile_variables[v1]) return; - } else if (!sign16((R18_ & kProjectileType_TypeMask) - kProjectileType_PowerBomb)) { + } else if (!sign16((r18 & kProjectileType_TypeMask) - kProjectileType_PowerBomb)) { return; } Get_SpacePirates(cur_enemy_index)->base.invincibility_timer = 10; @@ -115,30 +112,25 @@ void WalkingSpacePirates_883E(void) { // 0xB2883E v2 = 5; } projectile_dir[v1] = v2; - R20_ = v0; - ProjectileReflection(); - QueueSfx2_Max6(0x66u); + ProjectileReflection(v0); + QueueSfx2_Max6(0x66); } const uint16 *SpacePirates_Instr_MovePixelsDownAndChangeDirFaceRight(uint16 k, const uint16 *jp) { // 0xB2EE40 - R18_ = 0; - R20_ = jp[0]; - if (!(Enemy_MoveDown(cur_enemy_index) & 1)) + if (!(Enemy_MoveDown(cur_enemy_index, INT16_SHL16(jp[0])))) return jp + 1; Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - E->sps_var_C ^= 1u; + E->sps_var_C ^= 1; if (E->sps_var_C) return INSTR_RETURN_ADDR(addr_off_B2ECEC); return INSTR_RETURN_ADDR(addr_kSpacePirates_Ilist_ED36); } const uint16 *SpacePirates_Instr_MovePixelsDownAndChangeDirFaceLeft(uint16 k, const uint16 *jp) { // 0xB2EE72 - R18_ = 0; - R20_ = jp[0]; - if (!(Enemy_MoveDown(cur_enemy_index) & 1)) + if (!(Enemy_MoveDown(cur_enemy_index, INT16_SHL16(jp[0])))) return jp + 1; Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - E->sps_var_C ^= 1u; + E->sps_var_C ^= 1; if (E->sps_var_C) return INSTR_RETURN_ADDR(addr_kSpacePirates_Ilist_EDF6); return INSTR_RETURN_ADDR(addr_off_B2EDAC); @@ -174,8 +166,7 @@ const uint16 *SpacePirates_Instr_PrepareWallJumpR(uint16 k, const uint16 *jp) { const uint16 *SpacePirates_Instr_PrepareWallJumpL(uint16 k, const uint16 *jp) { // 0xB2EEFD Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); E->sps_var_B = E->base.x_pos - E->sps_parameter_2; - R18_ = E->sps_parameter_2 >> 1; - E->sps_var_D = E->base.x_pos - R18_; + E->sps_var_D = E->base.x_pos - (E->sps_parameter_2 >> 1); E->sps_var_E = E->base.y_pos; E->sps_var_F = 192; return jp; @@ -183,20 +174,18 @@ const uint16 *SpacePirates_Instr_PrepareWallJumpL(uint16 k, const uint16 *jp) { const uint16 *SpacePirates_Instr_FireLaserL(uint16 k, const uint16 *jp) { // 0xB2EF2A Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - enemy_projectile_init_param = *((uint16 *)RomPtr_A0(E->base.enemy_ptr) + 3); - R18_ = E->base.x_pos - 24; - R20_ = E->base.y_pos - 16; - R22_ = 0; + enemy_projectile_init_param_1 = *((uint16 *)RomPtr_A0(E->base.enemy_ptr) + 3); + eproj_spawn_pt = (Point16U){ E->base.x_pos - 24, E->base.y_pos - 16 }; + eproj_spawn_r22 = 0; SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 0); return jp; } const uint16 *SpacePirates_Instr_FireLaserR(uint16 k, const uint16 *jp) { // 0xB2EF5D Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - R18_ = E->base.x_pos + 24; - R20_ = E->base.y_pos - 16; - R22_ = 1; - SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 1u); + eproj_spawn_pt = (Point16U){ E->base.x_pos + 24, E->base.y_pos - 16 }; + eproj_spawn_r22 = 1; + SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 1); return jp; } @@ -206,7 +195,7 @@ const uint16 *SpacePirates_Instr_SetEnemyFunc(uint16 k, const uint16 *jp) { // } const uint16 *SpacePirates_Instr_PlaySfx(uint16 k, const uint16 *jp) { // 0xB2EF93 - QueueSfx2_Max6(0x66u); + QueueSfx2_Max6(0x66); return jp; } @@ -219,7 +208,7 @@ void WallSpacePirates_Init(void) { // 0xB2EF9F E->sps_var_20 = 190; E->sps_var_21 = 66; E->sps_var_22 = 2; - if ((E->sps_parameter_1 & 0x8000u) == 0) { + if ((E->sps_parameter_1 & 0x8000) == 0) { E->sps_var_20 += 2; E->sps_var_21 -= 2; E->sps_var_22 += 2; @@ -280,10 +269,8 @@ void SpacePirates_Func_1(uint16 k) { // 0xB2F034 void SpacePirates_Func_2(uint16 k) { // 0xB2F050 Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - draw_enemy_layer = E->sps_parameter_2 >> 1; - E->base.x_pos = E->sps_var_D + SineMult8bitNegative(E->sps_var_F); - draw_enemy_layer = E->sps_parameter_2 >> 2; - E->base.y_pos = E->sps_var_E - CosineMult8bit(E->sps_var_F); + E->base.x_pos = E->sps_var_D + SineMult8bit(E->sps_var_F, E->sps_parameter_2 >> 1); + E->base.y_pos = E->sps_var_E - CosineMult8bit(E->sps_var_F, E->sps_parameter_2 >> 2); uint16 v1 = (uint8)(LOBYTE(E->sps_var_F) - LOBYTE(E->sps_var_22)); E->sps_var_F = v1; if (v1 == E->sps_var_20) { @@ -308,10 +295,8 @@ void SpacePirates_Func_3(uint16 k) { // 0xB2F0C8 void SpacePirates_Func_4(uint16 k) { // 0xB2F0E4 Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - draw_enemy_layer = E->sps_parameter_2 >> 1; - E->base.x_pos = E->sps_var_D + SineMult8bitNegative(E->sps_var_F); - draw_enemy_layer = E->sps_parameter_2 >> 2; - E->base.y_pos = E->sps_var_E - CosineMult8bit(E->sps_var_F); + E->base.x_pos = E->sps_var_D + SineMult8bit(E->sps_var_F, E->sps_parameter_2 >> 1); + E->base.y_pos = E->sps_var_E - CosineMult8bit(E->sps_var_F, E->sps_parameter_2 >> 2); uint16 v1 = (uint8)(LOBYTE(E->sps_var_22) + LOBYTE(E->sps_var_F)); E->sps_var_F = v1; if (v1 == E->sps_var_21) { @@ -341,34 +326,23 @@ void sub_B2F554(void) { // 0xB2F554 } const uint16 *SpacePirates_Instr_15(uint16 k, const uint16 *jp) { // 0xB2F564 - R22_ = jp[1]; - R24_ = jp[2]; Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; + eproj_spawn_rect = (Rect16U){ E->base.x_pos, E->base.y_pos, jp[1], jp[2] }; SpawnEnemyProjectileWithGfx(jp[0], cur_enemy_index, addr_kEproj_PirateClaw); return jp + 3; } const uint16 *SpacePirates_Instr_18(uint16 k, const uint16 *jp) { // 0xB2F590 Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - R18_ = E->base.x_pos - samus_x_pos; E->base.instruction_timer = 1; - uint16 result = addr_kSpacePirates_Ilist_F22E; - if ((R18_ & 0x8000u) != 0) - result = addr_kSpacePirates_Ilist_F420; - E->sps_var_C = result; - return INSTR_RETURN_ADDR(result); + E->sps_var_C = (((E->base.x_pos - samus_x_pos) & 0x8000) != 0) ? addr_kSpacePirates_Ilist_F420 : addr_kSpacePirates_Ilist_F22E; + return INSTR_RETURN_ADDR(E->sps_var_C); } void sub_B2F5B3(void) { // 0xB2F5B3 EnemyData *v0 = gEnemyData(cur_enemy_index); - R18_ = v0->x_pos - samus_x_pos; v0->instruction_timer = 1; - uint16 v1 = addr_kSpacePirates_Ilist_F32E; - if ((R18_ & 0x8000u) != 0) - v1 = addr_kSpacePirates_Ilist_F51A; - v0->ai_var_C = v1; + v0->ai_var_C = (((v0->x_pos - samus_x_pos) & 0x8000) != 0) ? addr_kSpacePirates_Ilist_F51A : addr_kSpacePirates_Ilist_F32E; } const uint16 *SpacePirates_Instr_17(uint16 k, const uint16 *jp) { // 0xB2F5D6 @@ -377,12 +351,9 @@ const uint16 *SpacePirates_Instr_17(uint16 k, const uint16 *jp) { // 0xB2F5D6 } void NinjaSpacePirates_Init(void) { // 0xB2F5DE - uint16 v1 = addr_kSpacePirates_Ilist_F2DA; Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - if ((E->sps_parameter_1 & 1) != 0) - v1 = addr_kSpacePirates_Ilist_F4CC; - E->base.current_instruction = v1; - E->sps_var_C = v1; + E->base.current_instruction = (E->sps_parameter_1 & 1) != 0 ? addr_kSpacePirates_Ilist_F4CC : addr_kSpacePirates_Ilist_F2DA; + E->sps_var_C = E->base.current_instruction; uint16 x_pos = E->base.x_pos; if ((E->sps_parameter_1 & 1) != 0) { E->sps_var_E = x_pos; @@ -391,19 +362,19 @@ void NinjaSpacePirates_Init(void) { // 0xB2F5DE E->sps_var_F = x_pos; E->sps_var_E = x_pos - E->sps_parameter_2; } - R20_ = (uint16)(E->sps_var_F - E->sps_var_E) >> 1; - E->sps_var_D = E->sps_var_E + R20_; - R18_ = 0; - R22_ = 0; - R20_ = (uint8)R20_ << 8; + uint16 r20 = (uint16)(E->sps_var_F - E->sps_var_E) >> 1; + E->sps_var_D = E->sps_var_E + r20; + uint16 r18 = 0; + uint16 R22 = 0; + r20 = (uint8)r20 << 8; do { - R18_ += 32; - R22_ += R18_; - } while (sign16(R22_ - R20_)); - E->sps_var_B = R18_; - R24_ = (uint8)((uint16)(R22_ & 0xFF00) >> 8); - E->sps_var_F = E->sps_var_D + R24_; - E->sps_var_E = E->sps_var_D - R24_; + r18 += 32; + R22 += r18; + } while (sign16(R22 - r20)); + E->sps_var_B = r18; + uint16 R24 = (R22 & 0xFF00) >> 8; + E->sps_var_F = E->sps_var_D + R24; + E->sps_var_E = E->sps_var_D - R24; uint16 sps_var_E = E->sps_var_E; if ((E->sps_parameter_1 & 1) == 0) sps_var_E = E->sps_var_F; @@ -412,13 +383,12 @@ void NinjaSpacePirates_Init(void) { // 0xB2F5DE E->sps_var_08 = E->base.y_pos; uint16 v6 = 0; uint16 v7 = 0; - R18_ = 15; + int n = 15; do { target_palettes[(v7 >> 1) + 240] = kWallSpacePirates_Palette_3[v6 >> 1]; v6 += 2; v7 += 2; - --R18_; - } while ((R18_ & 0x8000u) == 0); + } while (--n >= 0); } void NinjaSpacePirates_Main(void) { // 0xB2F6A2 @@ -431,12 +401,8 @@ void SpacePirates_Func_5(uint16 k) { // 0xB2F6A9 if ((int16)(abs16(E->base.x_pos - samus_x_pos) - 128) >= 0) { SpacePirates_Func_8(); } else { - R18_ = E->base.x_pos - samus_x_pos; - uint16 v1 = addr_kSpacePirates_Ilist_F22E; - if ((R18_ & 0x8000u) != 0) - v1 = addr_kSpacePirates_Ilist_F420; - E->base.current_instruction = v1; - E->sps_var_C = v1; + E->base.current_instruction = ((E->base.x_pos - samus_x_pos) & 0x8000) ? addr_kSpacePirates_Ilist_F420 : addr_kSpacePirates_Ilist_F22E; + E->sps_var_C = E->base.current_instruction; E->base.instruction_timer = 1; } } @@ -466,7 +432,7 @@ uint16 SpacePirates_Func_8(void) { // 0xB2F72E uint16 v0 = 8; while (!projectile_type[v0 >> 1]) { v0 -= 2; - if ((v0 & 0x8000u) != 0) + if ((v0 & 0x8000) != 0) return 0; } int v1 = v0 >> 1; @@ -475,11 +441,7 @@ uint16 SpacePirates_Func_8(void) { // 0xB2F72E || (int16)(abs16(projectile_y_pos[v1] - E->base.y_pos) - 32) >= 0) { return 0; } - R18_ = E->base.x_pos - samus_x_pos; - uint16 v3 = addr_kSpacePirates_Ilist_F270; - if ((R18_ & 0x8000u) != 0) - v3 = addr_kSpacePirates_Ilist_F462; - E->base.current_instruction = v3; + E->base.current_instruction = (E->base.x_pos - samus_x_pos & 0x8000) ? addr_kSpacePirates_Ilist_F462 : addr_kSpacePirates_Ilist_F270; E->base.instruction_timer = 1; return 1; } @@ -502,19 +464,14 @@ uint16 SpacePirates_Func_10(void) { // 0xB2F7C6 || (int16)(abs16(samus_y_pos - E->base.y_pos) - 40) >= 0) { return 0; } - R18_ = E->base.x_pos - samus_x_pos; - uint16 v1 = addr_kSpacePirates_Ilist_F32E; - if ((R18_ & 0x8000u) != 0) - v1 = addr_kSpacePirates_Ilist_F51A; - E->base.current_instruction = v1; + E->base.current_instruction = ((E->base.x_pos - samus_x_pos) & 0x8000) != 0 ? addr_kSpacePirates_Ilist_F51A : addr_kSpacePirates_Ilist_F32E; E->base.instruction_timer = 1; return 1; } void SpacePirates_Func_11(uint16 k) { // 0xB2F817 Enemy_SpacePirates *E = Get_SpacePirates(k); - R18_ = HIBYTE(E->sps_var_00); - E->base.x_pos -= R18_; + E->base.x_pos -= HIBYTE(E->sps_var_00); --E->base.y_pos; --E->base.y_pos; E->sps_var_00 += 32; @@ -524,8 +481,7 @@ void SpacePirates_Func_11(uint16 k) { // 0xB2F817 void SpacePirates_Func_12(uint16 k) { // 0xB2F84C Enemy_SpacePirates *E = Get_SpacePirates(k); - R18_ = HIBYTE(E->sps_var_00); - E->base.x_pos -= R18_; + E->base.x_pos -= HIBYTE(E->sps_var_00); ++E->base.y_pos; ++E->base.y_pos; uint16 v2 = E->sps_var_00 - 32; @@ -541,8 +497,7 @@ void SpacePirates_Func_12(uint16 k) { // 0xB2F84C void SpacePirates_Func_13(uint16 k) { // 0xB2F890 Enemy_SpacePirates *E = Get_SpacePirates(k); - R18_ = HIBYTE(E->sps_var_00); - E->base.x_pos += R18_; + E->base.x_pos += HIBYTE(E->sps_var_00); --E->base.y_pos; --E->base.y_pos; E->sps_var_00 += 32; @@ -552,8 +507,7 @@ void SpacePirates_Func_13(uint16 k) { // 0xB2F890 void SpacePirates_Func_14(uint16 k) { // 0xB2F8C5 Enemy_SpacePirates *E = Get_SpacePirates(k); - R18_ = HIBYTE(E->sps_var_00); - E->base.x_pos += R18_; + E->base.x_pos += HIBYTE(E->sps_var_00); ++E->base.y_pos; ++E->base.y_pos; uint16 v2 = E->sps_var_00 - 32; @@ -581,11 +535,10 @@ void SpacePirates_Func_16(void) { // 0xB2F917 do v2 = NextRandom() & 3; while (!v2); - R18_ = v2; v3 = 0; if (E->base.x_pos == E->sps_var_E) v3 = 4; - E->base.current_instruction = g_off_B2F959[R18_ + v3]; + E->base.current_instruction = g_off_B2F959[v2 + v3]; E->base.instruction_timer = 1; } } @@ -602,8 +555,7 @@ void SpacePirates_F985(uint16 k) { // 0xB2F985 int16 v2; Enemy_SpacePirates *E = Get_SpacePirates(k); - R18_ = HIBYTE(E->sps_var_00); - E->base.y_pos -= R18_; + E->base.y_pos -= HIBYTE(E->sps_var_00); v2 = E->sps_var_00 - 64; E->sps_var_00 = v2; if (v2 < 0) { @@ -619,9 +571,7 @@ void SpacePirates_F9C1(uint16 k) { // 0xB2F9C1 Enemy_SpacePirates *E = Get_SpacePirates(k); E->base.x_pos -= 5; - R20_ = HIBYTE(E->sps_var_00); - R18_ = LOBYTE(E->sps_var_00); - if (Enemy_MoveDown(k) & 1 + if (Enemy_MoveDown(k, __PAIR32__(HIBYTE(E->sps_var_00), LOBYTE(E->sps_var_00))) || (v2 = E->sps_var_00 - 64, E->sps_var_00 = v2, v2 < 0) || (v2 & 0xFF00) == 0) { E->sps_var_A = FUNC16(SpacePirates_FA15); @@ -656,8 +606,7 @@ void SpacePirates_FA59(uint16 k) { // 0xB2FA59 int16 v2; Enemy_SpacePirates *E = Get_SpacePirates(k); - R18_ = HIBYTE(E->sps_var_00); - E->base.y_pos -= R18_; + E->base.y_pos -= HIBYTE(E->sps_var_00); v2 = E->sps_var_00 - 64; E->sps_var_00 = v2; if (v2 < 0) { @@ -673,9 +622,7 @@ void SpacePirates_FA95(uint16 k) { // 0xB2FA95 Enemy_SpacePirates *E = Get_SpacePirates(k); E->base.x_pos += 5; - R20_ = HIBYTE(E->sps_var_00); - R18_ = LOBYTE(E->sps_var_00); - if (Enemy_MoveDown(k) & 1 + if (Enemy_MoveDown(k, __PAIR32__(HIBYTE(E->sps_var_00), LOBYTE(E->sps_var_00))) || (v2 = E->sps_var_00 - 64, E->sps_var_00 = v2, v2 < 0) || (v2 & 0xFF00) == 0) { E->sps_var_A = FUNC16(SpacePirates_FAE9); @@ -700,33 +647,23 @@ void SpacePirates_FAE9(uint16 k) { // 0xB2FAE9 void SpacePirates_FB11(uint16 k) { // 0xB2FB11 Enemy_SpacePirates *E = Get_SpacePirates(k); - R18_ = E->base.x_pos - 8; - R20_ = E->base.y_pos + 28; - R22_ = 10; - R24_ = 0; - CreateSpriteAtPos(); - R18_ = E->base.x_pos + 8; - R20_ = E->base.y_pos + 28; - R22_ = 10; - R24_ = 0; - CreateSpriteAtPos(); + CreateSpriteAtPos(E->base.x_pos - 8, E->base.y_pos + 28, 10, 0); + CreateSpriteAtPos(E->base.x_pos + 8, E->base.y_pos + 28, 10, 0); } const uint16 *SpacePirates_Instr_12(uint16 k, const uint16 *jp) { // 0xB2FC68 Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - R18_ = E->base.x_pos - 24; - R20_ = E->base.y_pos - jp[0]; - R22_ = 0; + eproj_spawn_pt = (Point16U){ E->base.x_pos - 24, E->base.y_pos - jp[0] }; + eproj_spawn_r22 = 0; SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 0); return jp + 1; } const uint16 *SpacePirates_Instr_14(uint16 k, const uint16 *jp) { // 0xB2FC90 Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); - R18_ = E->base.x_pos + 24; - R20_ = E->base.y_pos - jp[0]; - R22_ = 1; - SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 1u); + eproj_spawn_pt = (Point16U){ E->base.x_pos + 24, E->base.y_pos - jp[0] }; + eproj_spawn_r22 = 1; + SpawnEnemyProjectileWithRoomGfx(addr_stru_86A17B, 1); return jp + 1; } @@ -761,7 +698,7 @@ void WalkingSpacePirates_Init(void) { // 0xB2FD02 void WalkingSpacePirates_Main(void) { // 0xB2FD32 Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); CallSpacePiratesEnemyFunc(E->sps_var_A | 0xB20000, cur_enemy_index); - if ((Get_SpacePirates(cur_enemy_index)->sps_parameter_1 & 0x8000u) != 0) + if ((E->sps_parameter_1 & 0x8000) != 0) WalkingSpacePirates_FE4B(); } @@ -775,22 +712,22 @@ void WalkingSpacePirates_FD44(void) { // 0xB2FD44 E->base.current_instruction = v1; E->base.instruction_timer = 1; } else { - R20_ = 1; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index)) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { uint16 x_pos = E->base.x_pos; E->sps_var_00 = x_pos; E->base.x_pos = x_pos - 17; - R20_ = 1; - R18_ = 0; - uint8 result = Enemy_MoveDown(cur_enemy_index); + uint8 result = Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1)); E->base.x_pos = E->sps_var_00; - if (!result - || (R18_ = 0, R20_ = -9, EnemyFunc_BBBF(cur_enemy_index), R18_ = -14337, R20_ = -1, Enemy_MoveRight_IgnoreSlopes(cur_enemy_index)) - || (int16)(E->base.x_pos - E->sps_var_E) < 0) { - E->base.current_instruction = addr_kSpacePirates_Ilist_FBC6; - E->base.instruction_timer = 1; + + if (result) { + EnemyFunc_BBBF(cur_enemy_index, INT16_SHL16(-9)); + if (!Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -14337))) { + if ((int16)(E->base.x_pos - E->sps_var_E) >= 0) + return; + } } + E->base.current_instruction = addr_kSpacePirates_Ilist_FBC6; + E->base.instruction_timer = 1; } } } @@ -805,18 +742,14 @@ void WalkingSpacePirates_FDCE(void) { // 0xB2FDCE E->base.current_instruction = v1; E->base.instruction_timer = 1; } else { - R20_ = 1; - R18_ = 0; - if (Enemy_MoveDown(cur_enemy_index)) { + if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { uint16 x_pos = E->base.x_pos; E->sps_var_00 = x_pos; E->base.x_pos = x_pos + 16; - R20_ = 1; - R18_ = 0; - uint8 result = Enemy_MoveDown(cur_enemy_index); + uint8 result = Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1)); E->base.x_pos = E->sps_var_00; if (!result || - (R18_ = 14336, R20_ = 0, Enemy_MoveRight_IgnoreSlopes(cur_enemy_index)) || + (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 14336))) || (int16)(E->base.x_pos - E->sps_var_F) >= 0) { E->base.current_instruction = addr_kSpacePirates_Ilist_FC48; E->base.instruction_timer = 1; @@ -829,18 +762,14 @@ void WalkingSpacePirates_FE4B(void) { // 0xB2FE4B uint16 v0 = 8; while (!projectile_type[v0 >> 1]) { v0 -= 2; - if ((v0 & 0x8000u) != 0) + if ((v0 & 0x8000) != 0) return; } int v1 = v0 >> 1; Enemy_SpacePirates *E = Get_SpacePirates(cur_enemy_index); if ((int16)(abs16(projectile_x_pos[v1] - E->base.x_pos) - 32) < 0 && (int16)(abs16(projectile_y_pos[v1] - E->base.y_pos) - 32) < 0) { - R18_ = E->base.x_pos - samus_x_pos; - uint16 v3 = addr_kSpacePirates_Ilist_FB4C; - if ((R18_ & 0x8000u) != 0) - v3 = addr_kSpacePirates_Ilist_FB58; - E->base.current_instruction = v3; + E->base.current_instruction = ((E->base.x_pos - samus_x_pos) & 0x8000) ? addr_kSpacePirates_Ilist_FB58 : addr_kSpacePirates_Ilist_FB4C; E->base.instruction_timer = 1; } -} \ No newline at end of file +} diff --git a/src/sm_b3.c b/src/sm_b3.c index 10d93d8..124713b 100644 --- a/src/sm_b3.c +++ b/src/sm_b3.c @@ -116,12 +116,12 @@ void BrinstarPipeBug_PreInstr_2(uint16 k) { // 0xB38890 uint16 a = GetSamusEnemyDelta_X(k); PipeBug->pbg_var_A = PipeBug->pbg_var_A & 0x7fff | sign16(a); - if (abs16(PipeBug->base.x_pos - samus_x_pos) < 0x40u) { + if (abs16(PipeBug->base.x_pos - samus_x_pos) < 0x40) { PipeBug->pbg_var_F = FUNC16(BrinstarPipeBug_PreInstr_3); PipeBug->base.properties &= ~kEnemyProps_Invisible; PipeBug->base.timer = 0; uint16 v4; - if ((PipeBug->pbg_var_A & 0x8000u) != 0) + if ((PipeBug->pbg_var_A & 0x8000) != 0) v4 = 0; else v4 = 2; @@ -136,7 +136,7 @@ void BrinstarPipeBug_PreInstr_3(uint16 k) { // 0xB388E3 bool v2 = PipeBug->base.y_subpos-- != 0; PipeBug->base.y_pos += v2 - 2; if ((int16)(PipeBug->pbg_var_00 - PipeBug->base.y_pos) >= 0 && PipeBug->base.y_pos < samus_y_pos) { - PipeBug->pbg_var_E |= 1u; + PipeBug->pbg_var_E |= 1; BrinstarPipeBug_Func_1(); PipeBug->pbg_var_F = FUNC16(BrinstarPipeBug_PreInstr_4); } @@ -144,7 +144,7 @@ void BrinstarPipeBug_PreInstr_3(uint16 k) { // 0xB388E3 void BrinstarPipeBug_PreInstr_4(uint16 k) { // 0xB3891C Enemy_PipeBug *PipeBug = Get_PipeBug(k); - if ((PipeBug->pbg_var_A & 0x8000u) == 0) { + if ((PipeBug->pbg_var_A & 0x8000) == 0) { PipeBug->base.x_subpos = PipeBug->base.x_subpos; PipeBug->base.x_pos = PipeBug->base.x_pos + 2; } else { @@ -253,7 +253,7 @@ void NorfairPipeBug_Func_2(void) { // 0xB38BFF ++PipeBug->pbg_var_C; PipeBug->base.instruction_timer = 1; PipeBug->base.timer = 0; - if ((GetSamusEnemyDelta_X(k) & 0x8000u) == 0) { + if ((GetSamusEnemyDelta_X(k) & 0x8000) == 0) { Get_PipeBug(k)->base.current_instruction = addr_kNorfairPipeBug_Ilist_8B21; Get_PipeBug(k + 64)->base.current_instruction = addr_kNorfairPipeBug_Ilist_8B21; Get_PipeBug(k + 128)->base.current_instruction = addr_kNorfairPipeBug_Ilist_8B21; @@ -304,7 +304,7 @@ void NorfairPipeBug_Func_4(void) { // 0xB38CA6 E->pbg_var_01 = E->base.y_pos; E->base.instruction_timer = 1; E->base.timer = 0; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) E->base.current_instruction = addr_kNorfairPipeBug_Ilist_8B21; else E->base.current_instruction = addr_kNorfairPipeBug_Ilist_8AE1; @@ -430,7 +430,7 @@ void NorfairPipeBug_Func_12(void) { // 0xB38E5A E->base.timer = 0; E->pbg_var_A = FUNC16(NorfairPipeBug_Func_10); E->base.current_instruction = addr_kNorfairPipeBug_Ilist_8B05; - if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000u) == 0) { + if ((GetSamusEnemyDelta_X(cur_enemy_index) & 0x8000) == 0) { E->pbg_var_A = FUNC16(NorfairPipeBug_Func_11); E->base.current_instruction = addr_kNorfairPipeBug_Ilist_8B45; } @@ -449,7 +449,7 @@ void BrinstarYellowPipeBug_Init(void) { // 0xB38F4C E->base.current_instruction = addr_kBrinstarYellowPipeBug_Ilist_8EFC; if (!E->pbg_parameter_1) E->base.current_instruction = addr_kBrinstarYellowPipeBug_Ilist_8F24; - int v1 = (uint16)(8 * E->pbg_parameter_2) >> 1; + int v1 = (8 * E->pbg_parameter_2) >> 1; E->pbg_var_01 = kCommonEnemySpeeds_Linear[v1]; E->pbg_var_00 = kCommonEnemySpeeds_Linear[v1 + 1]; E->pbg_var_03 = kCommonEnemySpeeds_Linear[v1 + 2]; @@ -649,7 +649,7 @@ void BrinstarYellowPipeBug_Func_9(uint16 k) { // 0xB39256 Enemy_PipeBug *E = Get_PipeBug(k); ++E->pbg_var_E; uint16 y_subpos = E->base.y_subpos; - int v3 = (uint16)(8 * E->pbg_var_E) >> 1; + int v3 = (8 * E->pbg_var_E) >> 1; bool v4 = __CFADD__uint16(kCommonEnemySpeeds_Quadratic[v3 + 2], y_subpos); uint16 v5 = kCommonEnemySpeeds_Quadratic[v3 + 2] + y_subpos; if (v4) @@ -660,12 +660,12 @@ void BrinstarYellowPipeBug_Func_9(uint16 k) { // 0xB39256 void BrinstarYellowPipeBug_Func_10(uint16 k) { // 0xB3927A Enemy_PipeBug *E = Get_PipeBug(k); - if ((--E->pbg_var_E & 0x8000u) != 0) { + if ((--E->pbg_var_E & 0x8000) != 0) { E->pbg_var_E = 0; E->pbg_var_F = 0; } else { uint16 y_subpos = E->base.y_subpos; - int v4 = (uint16)(8 * E->pbg_var_E) >> 1; + int v4 = (8 * E->pbg_var_E) >> 1; bool v5 = __CFADD__uint16(kCommonEnemySpeeds_Quadratic[v4], y_subpos); uint16 v6 = kCommonEnemySpeeds_Quadratic[v4] + y_subpos; if (v5) @@ -752,19 +752,18 @@ const uint16 *Botwoon_Instr_SetSpitting(uint16 k, const uint16 *jp) { // 0xB395 } const uint16 *Botwoon_Instr_QueueSpitSfx(uint16 k, const uint16 *jp) { // 0xB39572 - QueueSfx2_Max6(0x7Cu); + QueueSfx2_Max6(0x7C); return jp; } void Botwoon_QueueExplosionSfx(void) { // 0xB3957B - QueueSfx2_Max6(0x24u); + QueueSfx2_Max6(0x24); } void Botwoon_Init(void) { // 0xB39583 Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); if ((boss_bits_for_area[4] & 2) != 0) { - static const SpawnHardcodedPlmArgs unk_B39593 = { 0x0f, 0x04, 0xb797 }; - SpawnHardcodedPlm(&unk_B39593); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0f, 0x04, 0xb797 }); *(uint16 *)scrolls = 257; E->base.current_instruction = addr_kBotwoon_Ilist_9389; E->base.properties |= kEnemyProps_Deleted; @@ -841,8 +840,7 @@ void Botwoon_Main(void) { // 0xB39668 void Botwoon_Func_1(uint16 k) { // 0xB3967B Enemy_Botwoon *E = Get_Botwoon(k); - R18_ = g_word_B39675[E->botwoon_var_3F]; - if ((R18_ & NextRandom()) == 0) + if ((g_word_B39675[E->botwoon_var_3F] & NextRandom()) == 0) E->botwoon_var_2E = 1; } @@ -876,7 +874,7 @@ void Botwoon_Func_4(void) { // 0xB396F5 void Botwoon_Func_5(void) { // 0xB396FF uint16 v0 = 34; do { - enemy_projectile_properties[v0 >> 1] |= 0x2000u; + enemy_projectile_properties[v0 >> 1] |= 0x2000; enemy_projectile_flags[v0 >> 1] = 2; v0 -= 2; } while ((int16)(v0 - 10) >= 0); @@ -886,14 +884,13 @@ void Botwoon_HealthBasedPalHandling(void) { // 0xB3982B Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); if (E->botwoon_var_4F != 16 && (int16)(E->base.health - kBotwoonHealthThresForPalChange[E->botwoon_var_4F >> 1]) < 0) { - R18_ = 16 * E->botwoon_var_4F; - R20_ = E->botwoon_var_4E; + uint16 r18 = 16 * E->botwoon_var_4F; + uint16 r20 = E->botwoon_var_4E; do { - palette_buffer[R20_ >> 1] = kBotwoonHealthBasedPalette[R18_++ >> 1]; - ++R18_; - ++R20_; - ++R20_; - } while (R20_ != 512); + palette_buffer[r20 >> 1] = kBotwoonHealthBasedPalette[r18++ >> 1]; + r18++; + r20 += 2; + } while (r20 != 512); E->botwoon_var_4F += 2; } } @@ -910,19 +907,16 @@ void Botwoon_Func_7(void) { // 0xB3989D Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); if (E->botwoon_var_3C) { E->botwoon_var_3C = 0; - R18_ = 0; + uint8 r18 = 0; if (!E->botwoon_var_33 && !E->botwoon_var_59 && !E->botwoon_var_3F) { - LOBYTE(R18_) = NextRandom() & 0xE; - R18_ = (uint8)R18_; + r18 = NextRandom() & 0xE; } E->botwoon_var_59 = 0; - if (!R18_ || R18_ == 2 || R18_ == 4) { + if (!r18 || r18 == 2 || r18 == 4) { Botwoon_Func_8(); } else { - if (R18_ != 6 && R18_ != 8 && R18_ != 10 && R18_ != 12 && R18_ != 14) { + if (r18 != 6 && r18 != 8 && r18 != 10 && r18 != 12 && r18 != 14) { Unreachable(); - while (1) - ; } Botwoon_Func_9(); } @@ -957,13 +951,9 @@ void Botwoon_Func_9(void) { // 0xB39913 void Botwoon_Func_10(uint16 k) { // 0xB39933 Botwoon_Func_11(k); - R18_ = 0; Enemy_Botwoon *E = Get_Botwoon(k); - if (E->botwoon_var_33) - R18_ = 128; - LOBYTE(R20_) = NextRandom() & 0x18; - R20_ = (uint8)R20_; - E->botwoon_var_40 = (uint8)R20_ + R18_ + 4 * E->botwoon_var_37; + uint16 r18 = E->botwoon_var_33 ? 128 : 0; + E->botwoon_var_40 = (NextRandom() & 0x18) + r18 + 4 * E->botwoon_var_37; } void Botwoon_Func_11(uint16 k) { // 0xB3995D @@ -1036,7 +1026,7 @@ void Botwoon_Func_14(void) { // 0xB39A46 void Botwoon_Func_15(void) { // 0xB39A5E Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); uint16 y_subpos = E->base.y_subpos; - int v2 = (uint16)(8 * HIBYTE(E->botwoon_var_28)) >> 1; + int v2 = (8 * HIBYTE(E->botwoon_var_28)) >> 1; bool v3 = __CFADD__uint16(kCommonEnemySpeeds_Quadratic[v2], y_subpos); uint16 v4 = kCommonEnemySpeeds_Quadratic[v2] + y_subpos; if (v3) @@ -1049,11 +1039,10 @@ void Botwoon_Func_15(void) { // 0xB39A5E } else { E->base.y_pos = 200; E->botwoon_var_D = FUNC16(Botwoon_Func_16); - R18_ = E->base.x_pos; - R20_ = E->base.y_pos; + eproj_spawn_pt = (Point16U){ E->base.x_pos, E->base.y_pos }; SpawnEnemyProjectileWithRoomGfx(addr_kEproj_DustCloudExplosion, 0x1D); Botwoon_QueueExplosionSfx(); - E->base.properties |= 0x500u; + E->base.properties |= 0x500; } } @@ -1066,8 +1055,7 @@ void Botwoon_Func_16(void) { // 0xB39ACA } void Botwoon_Func_17(uint16 k) { // 0xB39ADD - static const SpawnHardcodedPlmArgs unk_B39AE1 = { 0x0f, 0x04, 0xb79b }; - SpawnHardcodedPlm(&unk_B39AE1); + SpawnHardcodedPlm((SpawnHardcodedPlmArgs) { 0x0f, 0x04, 0xb79b }); Enemy_ItemDrop_Botwoon(k); Enemy_Botwoon *E = Get_Botwoon(k); E->botwoon_var_23 = 0; @@ -1083,40 +1071,34 @@ void Botwoon_Func_18(uint16 k) { // 0xB39AF9 E->botwoon_var_24 = v2; if (v2 < 0) { E->botwoon_var_24 = 12; - R18_ = (NextRandom() & 0x1F) + 232; - R20_ = E->botwoon_var_23 + (NextRandom() & 0x1F) - 8; - R22_ = 29; - R24_ = 2560; - CreateSpriteAtPos(); + uint16 x = (NextRandom() & 0x1F) + 232; + uint16 y = E->botwoon_var_23 + (NextRandom() & 0x1F) - 8; + CreateSpriteAtPos(x, y, 29, 2560); Botwoon_QueueExplosionSfx(); } int16 v3 = E->botwoon_var_25 - 1; E->botwoon_var_25 = v3; if (v3 < 0) { E->botwoon_var_25 = 4; - R36 = 2; + int n = 2; do { - R18_ = (NextRandom() & 0x3F) + 224; - int16 v4 = (NextRandom() & 0x1F) - 8; - R20_ = Get_Botwoon(k)->botwoon_var_23 + v4; - R22_ = 9; - R24_ = 2560; - CreateSpriteAtPos(); - --R36; - } while (R36); + uint16 x = (NextRandom() & 0x3F) + 224; + uint16 y = Get_Botwoon(k)->botwoon_var_23 + ((NextRandom() & 0x1F) - 8); + CreateSpriteAtPos(x, y, 9, 2560); + } while (--n); } } ++E->botwoon_var_23; } else { E->base.properties |= kEnemyProps_Deleted; - SetBossBitForCurArea(2u); - QueueMusic_Delayed8(3u); + SetBossBitForCurArea(2); + QueueMusic_Delayed8(3); } } void Botwoon_Func_19(void) { // 0xB39BB7 - Botwoon_Func_20(cur_enemy_index); - uint16 v1 = CalculateAngleFromXY(); + Point16U pt = Botwoon_Func_20(cur_enemy_index); + uint16 v1 = CalculateAngleFromXY(pt.x, pt.y); Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); E->botwoon_var_39 = v1; E->botwoon_var_3A = (uint8)(64 - v1); @@ -1128,38 +1110,32 @@ void Botwoon_Func_19(void) { // 0xB39BB7 } } -void Botwoon_Func_20(uint16 k) { // 0xB39BF8 +Point16U Botwoon_Func_20(uint16 k) { // 0xB39BF8 Enemy_Botwoon *E = Get_Botwoon(k); int v2 = E->botwoon_var_37 >> 1; uint16 v3 = g_word_B3949B[v2] + 4 - E->base.x_pos; - R18_ = v3; + uint16 r18 = v3; if (sign16(v3 - 256)) { if (sign16(v3 + 256)) - R18_ = -255; + r18 = -255; } else { - R18_ = 255; + r18 = 255; } uint16 v4 = g_word_B3949B[v2 + 2] + 4 - E->base.y_pos; - R20_ = v4; + uint16 r20 = v4; if (sign16(v4 - 256)) { if (sign16(v4 + 256)) - R20_ = -255; + r20 = -255; } else { - R20_ = 255; + r20 = 255; } + return (Point16U) { r18, r20 }; } void Botwoon_Func_21(void) { // 0xB39C48 Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); - R18_ = E->botwoon_var_3A; - R20_ = E->botwoon_var_38; - ConvertAngleToXy(); - enemy_population_ptr = E->botwoon_var_3A; - varE24 = R22_; - varE26 = R24_; - varE28 = R26_; - varE2A = R28_; - EnemyFunc_B691(); + Point32 pt = ConvertAngleToXy(E->botwoon_var_3A, E->botwoon_var_38); + EnemyFunc_B691(E->botwoon_var_3A, pt); } void Botwoon_Func_22(void) { // 0xB39C7B @@ -1170,23 +1146,21 @@ void Botwoon_Func_22(void) { // 0xB39C7B } void Botwoon_Func_23(void) { // 0xB39C90 - unsigned int v6; - Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); - R18_ = (E->botwoon_var_B - E->botwoon_var_C) & 0x3FF; - R20_ = 24; + uint16 r18 = (E->botwoon_var_B - E->botwoon_var_C) & 0x3FF; + int n = 24; do { - Enemy_Botwoon *ET = Get_Botwoon(R20_); + Enemy_Botwoon *ET = Get_Botwoon(n); uint16 botwoo_var_00 = ET->botwoon_var_00; - if (Get_Botwoon(cur_enemy_index)->botwoon_var_36 == R18_) { - uint16 v2 = R20_; + if (E->botwoon_var_36 == r18) { + uint16 v2 = n; bool v4 = ET->botwoon_var_10 == 1; - ET->botwoon_var_10 ^= 1u; + ET->botwoon_var_10 ^= 1; if (v4) { - enemy_projectile_properties[botwoo_var_00 >> 1] &= ~0x2000u; + enemy_projectile_properties[botwoo_var_00 >> 1] &= ~0x2000; enemy_projectile_flags[botwoo_var_00 >> 1] = 1; } else { - enemy_projectile_properties[botwoo_var_00 >> 1] |= 0x2000u; + enemy_projectile_properties[botwoo_var_00 >> 1] |= 0x2000; enemy_projectile_flags[botwoo_var_00 >> 1] = 2; } if (!v2) { @@ -1197,14 +1171,12 @@ void Botwoon_Func_23(void) { // 0xB39C90 E->botwoon_var_3E = 1; } } - v6 = R18_; int v7 = botwoo_var_00 >> 1; - enemy_projectile_x_pos[v7] = *(uint16 *)((uint8 *)&kraid_unk9000 + R18_); - enemy_projectile_y_pos[v7] = *(uint16 *)((uint8 *)&g_word_7E9002 + v6); - R18_ = (R18_ - E->botwoon_var_C) & 0x3FF; - --R20_; - --R20_; - } while ((R20_ & 0x8000u) == 0); + enemy_projectile_x_pos[v7] = *(uint16 *)((uint8 *)&kraid_unk9000 + r18); + enemy_projectile_y_pos[v7] = *(uint16 *)((uint8 *)&g_word_7E9002 + r18); + r18 = (r18 - E->botwoon_var_C) & 0x3FF; + n -= 2; + } while ((n & 0x8000) == 0); } void Botwoon_Func_24(void) { // 0xB39D3C @@ -1214,45 +1186,46 @@ void Botwoon_Func_24(void) { // 0xB39D3C void Botwoon_Func_25(void) { // 0xB39D4D Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); - R22_ = 24; + int n = 24; do { - R24_ = 0; - Enemy_Botwoon *ERR = Get_Botwoon(R22_); + uint16 r24 = 0; + Enemy_Botwoon *ERR = Get_Botwoon(n); uint16 botwoo_var_00 = ERR->botwoon_var_00; if (ERR->botwoon_var_10) - R24_ = 256; - if (R22_ == 24) { + r24 = 256; + uint16 x, y; + if (n == 24) { int v4 = botwoo_var_00 >> 1; - R18_ = E->base.x_pos - enemy_projectile_x_pos[v4]; - R20_ = E->base.y_pos - enemy_projectile_y_pos[v4]; + x = E->base.x_pos - enemy_projectile_x_pos[v4]; + y = E->base.y_pos - enemy_projectile_y_pos[v4]; } else { - if (!R22_) - R24_ += 512; + if (!n) + r24 += 512; int v2 = botwoo_var_00 >> 1; - R18_ = enemy_projectile_x_pos[v2 + 1] - enemy_projectile_x_pos[v2]; - R20_ = enemy_projectile_y_pos[v2 + 1] - enemy_projectile_y_pos[v2]; + x = enemy_projectile_x_pos[v2 + 1] - enemy_projectile_x_pos[v2]; + y = enemy_projectile_y_pos[v2 + 1] - enemy_projectile_y_pos[v2]; } - enemy_projectile_E[botwoo_var_00 >> 1] = 2 * ((uint16)(R24_ + CalculateAngleFromXY()) >> 5); - --R22_; - --R22_; - } while ((R22_ & 0x8000u) == 0); + enemy_projectile_E[botwoo_var_00 >> 1] = 2 * ((uint16)(r24 + CalculateAngleFromXY(x, y)) >> 5); + n -= 2; + } while (n >= 0); } void Botwoon_Func_26(uint16 k) { // 0xB39DC0 + printf("Botwoon_Func_26 possible bug - overwritten r18\n"); Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); - R18_ = E->base.x_pos - E->botwoon_var_56; - R20_ = E->base.y_pos - E->botwoon_var_57; - R22_ = CalculateAngleFromXY(); - if (R18_ || R20_) { + uint16 x = E->base.x_pos - E->botwoon_var_56; + uint16 y = E->base.y_pos - E->botwoon_var_57; + uint16 r22 = CalculateAngleFromXY(x, y); + if (x || y) { if (E->botwoon_var_33) { E->base.layer = 7; E->base.properties |= kEnemyProps_Tangible; - R22_ += 256; + r22 += 256; } else { E->base.layer = 2; E->base.properties &= ~kEnemyProps_Tangible; } - uint16 v1 = g_off_B3946B[R22_ >> 5]; + uint16 v1 = g_off_B3946B[r22 >> 5]; if (v1 != E->botwoon_var_3B) { E->base.current_instruction = v1; E->botwoon_var_3B = v1; @@ -1290,14 +1263,13 @@ void Botwoon_Func_27(uint16 k) { // 0xB39E7D void Botwoon_Func_28(uint16 k) { // 0xB39EE0 Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); if (E->botwoon_var_5A) { - remaining_enemy_spritemap_entries = (uint8)(E->botwoon_var_3D - 32); - remaining_enemy_hitbox_entries = 5; - draw_enemy_layer = g_word_B39E77[E->botwoon_var_3F]; + enemy_projectile_init_param_3 = E->botwoon_var_3D - 32; + int n = 5; + uint16 varE32 = g_word_B39E77[E->botwoon_var_3F]; do { - SpawnEnemyProjectileWithGfx(draw_enemy_layer, cur_enemy_index, addr_kEproj_BotwoonsSpit); - remaining_enemy_spritemap_entries = (uint8)(remaining_enemy_spritemap_entries + 16); - --remaining_enemy_hitbox_entries; - } while (remaining_enemy_hitbox_entries); + SpawnEnemyProjectileWithGfx(varE32, cur_enemy_index, addr_kEproj_BotwoonsSpit); + enemy_projectile_init_param_3 += 16; + } while (--n); E->botwoon_var_5A = 0; E->botwoon_var_F = FUNC16(Botwoon_Func_30); } @@ -1305,14 +1277,13 @@ void Botwoon_Func_28(uint16 k) { // 0xB39EE0 void Botwoon_Func_29(uint16 k) { // 0xB39F34 Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); - remaining_enemy_spritemap_entries = (uint8)(E->botwoon_var_3D - 16); - remaining_enemy_hitbox_entries = 3; - draw_enemy_layer = g_word_B39E77[E->botwoon_var_3F]; + enemy_projectile_init_param_3 = E->botwoon_var_3D - 16; + int n = 3; + uint16 varE32 = g_word_B39E77[E->botwoon_var_3F]; do { - SpawnEnemyProjectileWithGfx(draw_enemy_layer, cur_enemy_index, addr_kEproj_BotwoonsSpit); - remaining_enemy_spritemap_entries = (uint8)(remaining_enemy_spritemap_entries + 16); - --remaining_enemy_hitbox_entries; - } while (remaining_enemy_hitbox_entries); + SpawnEnemyProjectileWithGfx(varE32, cur_enemy_index, addr_kEproj_BotwoonsSpit); + enemy_projectile_init_param_3 += 16; + } while (--n); Get_Botwoon(cur_enemy_index)->botwoon_var_F = FUNC16(Botwoon_Func_30); } @@ -1330,24 +1301,22 @@ void Botwoon_Func_31(uint16 k) { // 0xB39F93 Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); if (!Get_Botwoon(k)->botwoon_var_35) { - R18_ = 24; - while (1) { - int v2 = R18_ >> 1; + int n = 24; + do { + int v2 = n >> 1; if ((int16)(E->base.x_pos - g_word_B3949B[v2]) >= 0 && (int16)(E->base.x_pos - g_word_B3949B[v2 + 1]) < 0 && (int16)(E->base.y_pos - g_word_B3949B[v2 + 2]) >= 0 && (int16)(E->base.y_pos - g_word_B3949B[v2 + 3]) < 0) { + E->botwoon_var_35 = 1; + E->botwoon_var_33 ^= 1; + E->botwoon_var_36 = E->botwoon_var_B; + --E->botwoon_var_26; break; } E->botwoon_var_35 = 0; - R18_ -= 8; - if ((R18_ & 0x8000u) != 0) - return; - } - E->botwoon_var_35 = 1; - E->botwoon_var_33 ^= 1u; - E->botwoon_var_36 = E->botwoon_var_B; - --E->botwoon_var_26; + n -= 8; + } while (n >= 0); } } @@ -1394,35 +1363,29 @@ void Botwoon_Func_32(void) { // 0xB3E250 } void Botwoon_Func_33(void) { // 0xB3E28C - R18_ = 0; - R20_ = 0; + uint16 x = 0, y = 0; Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); - R24_ = E->botwoon_var_38; - R22_ = 2; - if ((E->botwoon_var_44 & 0x8000u) != 0) - R22_ = -2; + int n = E->botwoon_var_38; + int step = ((E->botwoon_var_44 & 0x8000) == 0) ? 2 : -2; do { const uint8 *v6 = RomPtr_B3(E->botwoon_var_42); uint16 v7 = SignExtend8(*v6), v8; - if (v7 == 0xFF80 || (R18_ += v7, v8 = SignExtend8(v6[1]), v8 == 0xFF80)) { + if (v7 == 0xFF80 || (x += v7, v8 = SignExtend8(v6[1]), v8 == 0xFF80)) { E->botwoon_var_41 = 0; E->botwoon_var_3C = 1; return; } - R20_ += v8; - E->botwoon_var_42 += R22_; - --R24_; - } while (R24_); - if ((E->botwoon_var_44 & 0x8000u) != 0) { - R18_ = -R18_; - R20_ = -R20_; - } - E->base.x_pos += R18_; - E->base.y_pos += R20_; + y += v8; + E->botwoon_var_42 += step; + } while (--n); + if ((E->botwoon_var_44 & 0x8000) != 0) + x = -x, y = -y; + E->base.x_pos += x; + E->base.y_pos += y; } const uint16 *EscapeEtecoon_Instr_1(uint16 k, const uint16 *jp) { // 0xB3E545 - if (lava_acid_y_pos >= 0xCEu) + if (lava_acid_y_pos >= 0xCE) return jp + 1; else return INSTR_RETURN_ADDR(jp[0]); @@ -1447,37 +1410,27 @@ void EscapeEtecoon_E65C(uint16 k) { // 0xB3E65C } void EscapeEtecoon_E670(uint16 k) { // 0xB3E670 - if (CheckEventHappened(0xFu)) + if (CheckEventHappened(0xF)) Get_EscapeEtecoon(k)->base.current_instruction = addr_kEscapeEtecoon_Ilist_E5DA; } void EscapeEtecoon_E680(uint16 k) { // 0xB3E680 - int16 een_var_A; - - R18_ = 0; - R20_ = 0; Enemy_EscapeEtecoon *E = Get_EscapeEtecoon(k); - een_var_A = E->een_var_A; - if (een_var_A < 0) - --R20_; - R19_ = een_var_A; - if (Enemy_MoveRight_IgnoreSlopes(k) & 1) { + if (Enemy_MoveRight_IgnoreSlopes(k, INT16_SHL8(E->een_var_A))) { E->base.instruction_timer = 1; - bool v3 = (-E->een_var_A & 0x8000u) != 0; + bool v3 = (-E->een_var_A & 0x8000) != 0; E->een_var_A = -E->een_var_A; E->base.current_instruction = v3 ? addr_kEscapeEtecoon_Ilist_E556 : addr_kEscapeEtecoon_Ilist_E582; - if (CheckEventHappened(0xFu)) + if (CheckEventHappened(0xF)) E->base.current_instruction = addr_kEscapeEtecoon_Ilist_E5AE; } - R18_ = 0; - R20_ = 1; - Enemy_MoveDown(k); + Enemy_MoveDown(k, INT16_SHL16(1)); } void EscapeEtecoon_Init(void) { // 0xB3E6CB Enemy_EscapeEtecoon *E = Get_EscapeEtecoon(cur_enemy_index); - if (CheckEventHappened(0xFu)) { + if (CheckEventHappened(0xF)) { E->base.properties |= kEnemyProps_Deleted; } else { E->base.properties |= kEnemyProps_DisableSamusColl | kEnemyProps_Tangible | 0x8000; @@ -1494,14 +1447,14 @@ void EscapeEtecoon_Init(void) { // 0xB3E6CB } const uint16 *EscapeDachora_Instr_2(uint16 k, const uint16 *jp) { // 0xB3EAA8 - if (lava_acid_y_pos >= 0xCEu) + if (lava_acid_y_pos >= 0xCE) return jp + 1; else return INSTR_RETURN_ADDR(jp[0]); } const uint16 *EscapeDachora_Instr_3(uint16 k, const uint16 *jp) { // 0xB3EAB8 - if (CheckEventHappened(0xFu)) + if (CheckEventHappened(0xF)) return INSTR_RETURN_ADDR(jp[0]); else return jp + 1; @@ -1521,7 +1474,7 @@ const uint16 *EscapeDachora_Instr_4(uint16 k, const uint16 *jp) { // 0xB3EAD7 void EscapeDachora_Init(void) { // 0xB3EAE5 Enemy_EscapeDachora *E = Get_EscapeDachora(cur_enemy_index); - if (CheckEventHappened(0xFu)) { + if (CheckEventHappened(0xF)) { E->base.properties |= kEnemyProps_Deleted; } else { E->base.properties |= kEnemyProps_DisableSamusColl; @@ -1530,4 +1483,4 @@ void EscapeDachora_Init(void) { // 0xB3EAE5 E->base.timer = 0; E->base.current_instruction = addr_kEscapeDachora_Ilist_E964; } -} \ No newline at end of file +} diff --git a/src/sm_b4.c b/src/sm_b4.c index fb71e9c..9dc1cf5 100644 --- a/src/sm_b4.c +++ b/src/sm_b4.c @@ -10,25 +10,26 @@ -void CreateSpriteAtPos(void) { // 0xB4BC26 +uint16 CreateSpriteAtPos(uint16 x_r18, uint16 y_r20, uint16 ilist_r22, uint16 pal_r24) { // 0xB4BC26 int v0 = 62; while (sprite_instr_list_ptrs[v0 >> 1]) { v0 -= 2; - if ((v0 & 0x8000u) != 0) - return; + if ((v0 & 0x8000) != 0) + return 0xffff; } int v1 = v0 >> 1; sprite_palettes[v1] = 0; sprite_x_subpos[v1] = 0; sprite_y_subpos[v1] = 0; sprite_disable_flag[v1] = 0; - sprite_x_pos[v1] = R18_; - sprite_y_pos[v1] = R20_; - sprite_palettes[v1] = R24_; - uint16 v2 = kCreateSprite_Ilists[R22_]; + sprite_x_pos[v1] = x_r18; + sprite_y_pos[v1] = y_r20; + sprite_palettes[v1] = pal_r24; + uint16 v2 = kCreateSprite_Ilists[ilist_r22]; sprite_instr_list_ptrs[v1] = v2; sprite_instr_timer[v1] = *(uint16 *)RomPtr_B4(v2); - R18_ = v0; +// R18 = v0; + return v0; } void CallSpriteObjectInstr(uint32 ea) { @@ -90,17 +91,16 @@ void DrawSpriteObjects(void) { // 0xB4BD32 for (int i = 62; i >= 0; i -= 2) { int v1 = i >> 1; if (sprite_instr_list_ptrs[v1]) { - R20_ = sprite_x_pos[v1] - layer1_x_pos; - if ((int16)(R20_ + 16) >= 0) { - if (sign16(R20_ - 272)) { - int16 v2 = sprite_y_pos[v1] - layer1_y_pos; - R18_ = v2; - if (v2 >= 0) { - if (sign16(v2 - 272)) { - R3_.addr = sprite_palettes[v1] & 0xE00; - R0_.addr = sprite_palettes[v1] & 0x1FF; + uint16 x = sprite_x_pos[v1] - layer1_x_pos; + if ((int16)(x + 16) >= 0) { + if (sign16(x - 272)) { + int16 y = sprite_y_pos[v1] - layer1_y_pos; + if (y >= 0) { + if (sign16(y - 272)) { + uint16 r3 = sprite_palettes[v1] & 0xE00; + uint16 r0 = sprite_palettes[v1] & 0x1FF; const uint8 *v3 = RomPtr_B4(sprite_instr_list_ptrs[v1]); - DrawSpritemapWithBaseTile(0xB4, GET_WORD(v3 + 2)); + DrawSpritemapWithBaseTile(0xB4, GET_WORD(v3 + 2), x, y, r3, r0); } } } @@ -115,4 +115,4 @@ void ClearSpriteObjects(void) { // 0xB4BD97 sprite_instr_list_ptrs[v0 >> 1] = 0; v0 -= 2; } while (v0); -} \ No newline at end of file +} diff --git a/src/sm_cpu_infra.c b/src/sm_cpu_infra.c index b1da8f6..ecbaf6d 100644 --- a/src/sm_cpu_infra.c +++ b/src/sm_cpu_infra.c @@ -239,6 +239,21 @@ static const uint32 kPatchedCarrys[] = { 0xA9D537, 0xA9DCDB, + + 0xA0A31B, + 0x91D064, + 0x91D07A, + + 0x90C719, + + 0xA6A80E, + 0xA6A816, + + 0xA4906E, + 0xA49071, + + 0x90BC75, + 0x90BC93, }; static uint8 kPatchedCarrysOrg[arraysize(kPatchedCarrys)]; @@ -297,7 +312,7 @@ uint32 PatchBugs(uint32 mode, uint32 addr) { // Phantoon_Main forgots to reload x g_cpu->x = cur_enemy_index; } else if (FixBugHook(0x91CD44)) { - // Xray_SetupStage4_Func2 passes a bad value to Xray_HandleXrayedBlock + // Xray_SetupStage4_Func2 passes a bad value to Xray_GetXrayedBlock if (g_cpu->x == 0) g_cpu->pc = 0xCD52; @@ -340,6 +355,16 @@ uint32 PatchBugs(uint32 mode, uint32 addr) { } else if (FixBugHook(0x8189bd)) { if (g_cpu->y == 0) // DrawSamusSpritemap reads invalid ptr return 0x818A35; + } else if (FixBugHook(0xA29BC1)) { + g_cpu->a = 1; // ThinHoppingBlobs_Func8 reads from R1 instead of #1 + } else if (FixBugHook(0x82E910)) { + WORD(g_ram[22]) = 0; // SpawnDoorClosingPLM doesn't zero R22 + } else if (FixBugHook(0x90A4C8)) { + WORD(g_ram[18]) = 0; // Samus_InitJump overwrites R18 in Samus_Movement_03_SpinJumping + } else if (FixBugHook(0xA99F60)) { + WORD(g_ram[22]) = 1; // MotherBrain_Instr_SpawnLaserEproj doesn't set R22 + } else if (FixBugHook(0x94A85B)) { + memset(g_ram + 0xd82, 0, 8); // grapple_beam_tmpD82 not cleared in BlockCollGrappleBeam } return 0; @@ -384,33 +409,56 @@ bool HookedFunctionRts(int is_long) { } static void VerifySnapshotsEq(Snapshot *b, Snapshot *a, Snapshot *prev) { - memcpy(&b->ram[0x0], &a->ram[0x0], 0x34); // R18, R20, R22 etc + memcpy(&b->ram[0x0], &a->ram[0x0], 0x34); // r18, r20, R22 etc memcpy(&b->ram[0x1f5b], &a->ram[0x1f5b], 0x100 - 0x5b); // stacck - memcpy(&b->ram[0x44], &a->ram[0x44], 13); // decompress temp - memcpy(&b->ram[0x19b3], &a->ram[0x19b3], 1); // mode7_spawn_param - memcpy(&b->ram[0x1993], &a->ram[0x1993], 2); // enemy_projectile_init_param - memcpy(&b->ram[0x1B9D], &a->ram[0x1B9D], 2); // cinematic_spawn_param - memcpy(&b->ram[0x1a93], &a->ram[0x1a93], 2); // cinematic_spawn_param - memcpy(&b->ram[0xA82], &a->ram[0xA82], 2); // xray_angle - memcpy(&b->ram[0xad], &a->ram[0xad], 2); // ptr_to_retaddr_parameters - memcpy(&b->ram[0x641], &a->ram[0x641], 2); // apu_attempts_countdown - memcpy(&b->ram[0x5e9], &a->ram[0x5e9], 4); // mult_tmp - memcpy(&b->ram[0x19b3], &a->ram[0x19b3], 2); // mode7_spawn_param - - memcpy(&a->ram[0x611], &b->ram[0x611], 6); // coroutine_state (copy from mine to theirs) - memcpy(&a->ram[0x77e], &b->ram[0x77e], 5); // my counter - memcpy(&a->ram[0xe20], &b->ram[0xe20], 2); // enemy_population_ptr - - memcpy(&a->ram[0x1784], &b->ram[0x1784], 3); // enemy_ai_pointer memcpy(&a->ram[0x3c], &b->ram[0x3c], 2); // nmicopy1_var_d - memcpy(&a->ram[0x17aa], &b->ram[0x17aa], 2); // interactive_enemy_indexes_index - memcpy(&a->ram[0x60B], &b->ram[0x60B], 2); // remaining_enemy_spritemap_entries + memcpy(&b->ram[0x44], &a->ram[0x44], 13); // decompress temp + memcpy(&b->ram[0xad], &a->ram[0xad], 2); // ptr_to_retaddr_parameters + memcpy(&b->ram[0x5e7], &a->ram[0x5e7], 14); // bitmask, mult_tmp, mult_product_lo etc - memcpy(&a->ram[0xdd4], &b->ram[0xdd4], 4); // temp_collision_DD4 + memcpy(&a->ram[0x60B], &b->ram[0x60B], 6); // enemy_projectile_init_param_2, remaining_enemy_hitbox_entries, REMOVED_num_projectiles_to_check_enemy_coll + memcpy(&a->ram[0x611], &b->ram[0x611], 6); // coroutine_state (copy from mine to theirs) + memcpy(&b->ram[0x641], &a->ram[0x641], 2); // apu_attempts_countdown + memcpy(&a->ram[0x77e], &b->ram[0x77e], 5); // my counter + memcpy(&b->ram[0xA82], &a->ram[0xA82], 2); // xray_angle + memcpy(&a->ram[0xd1e], &b->ram[0xd1e], 2); // grapple_beam_unkD1E + memcpy(&a->ram[0xd82], &b->ram[0xd82], 8); // grapple_beam_tmpD82 + + memcpy(&a->ram[0xd9c], &b->ram[0xd9c], 2); // grapple_beam_tmpD82 + memcpy(&a->ram[0xdd2], &b->ram[0xdd2], 6); // temp_collision_DD2 etc + memcpy(&a->ram[0xd8a], &b->ram[0xd8a], 6); // grapple_beam_tmpD8A + memcpy(&a->ram[0xe20], &b->ram[0xe20], 0xe46 - 0xe20); // temp vars + memcpy(&a->ram[0xe54], &b->ram[0xe54], 2); // cur_enemy_index + + memcpy(&a->ram[0xe02], &b->ram[0xe02], 2); // samus_bottom_boundary_position + memcpy(&a->ram[0xe4a], &b->ram[0xe4a], 2); // new_enemy_index + memcpy(&a->ram[0xe56], &b->ram[0xe56], 4); // REMOVED_cur_enemy_index_backup etc + + + memcpy(&a->ram[0x1784], &b->ram[0x1784], 8); // enemy_ai_pointer etc + memcpy(&a->ram[0x1790], &b->ram[0x1790], 4); // set_to_rtl_when_loading_enemies_unused etc + memcpy(&a->ram[0x17a8], &b->ram[0x17a8], 4); // interactive_enemy_indexes_index + + memcpy(&a->ram[0x1834], &b->ram[0x1834], 8); // distance_to_enemy_colliding_dirs + memcpy(&a->ram[0x184A], &b->ram[0x184A], 18); // samus_x_pos_colliding_solid etc + memcpy(&a->ram[0x186E], &b->ram[0x186E], 16+8); // REMOVED_enemy_spritemap_entry_pointer etc + memcpy(&a->ram[0x18A6], &b->ram[0x18A6], 2); // collision_detection_index + memcpy(&a->ram[0x189A], &b->ram[0x189A], 12); // samus_target_x_pos etc + + memcpy(&b->ram[0x1993], &a->ram[0x1993], 2); // enemy_projectile_init_param + memcpy(&b->ram[0x19b3], &a->ram[0x19b3], 2); // mode7_spawn_param + memcpy(&b->ram[0x1a93], &a->ram[0x1a93], 2); // cinematic_spawn_param + memcpy(&b->ram[0x1B9D], &a->ram[0x1B9D], 2); // cinematic_spawn_param + memcpy(&a->ram[0x1E77], &b->ram[0x1E77], 2); // current_slope_bts + + memcpy(&a->ram[0x9100], &b->ram[0x9100], 0x1cc + 2); // XrayHdmaFunc has some bug that i couldn't fix in asm + memcpy(&a->ram[0x9800], &b->ram[0x9800], 0x1cc+2); // XrayHdmaFunc has some bug that i couldn't fix in asm + memcpy(&a->ram[0x99cc], &b->ram[0x99cc], 2); // XrayHdmaFunc_BeamAimedL writes outside + memcpy(&a->ram[0xEF74], &b->ram[0xEF74], 4); // next_enemy_tiles_index + memcpy(&a->ram[0xF37A], &b->ram[0xF37A], 6); // word_7EF37A etc - if (memcmp(b->ram, a->ram, 0x20000)) { fprintf(stderr, "@%d: Memory compare failed (mine != theirs, prev):\n", snes_frame_counter); int j = 0; @@ -771,6 +819,11 @@ Snes *SnesInit(const char *filename) { // LoadStdBG3andSpriteTilesClearTilemaps does DMA from RAM { uint8 t[] = { 0x00, 0x2E }; PatchBytes(0x82831E, t, sizeof(t)); } + { uint8 t[] = { 0xa5, 0x25 }; PatchBytes(0x91C234, t, sizeof(t)); } // Bugfix in XrayHdmaFunc_BeamAimedUUL + + // Remove call to InitializeMiniMapBroken + { uint8 t[] = { 0x18, 0x18, 0x18, 0x18 }; PatchBytes(0x809AF3, t, sizeof(t)); } // callf InitializeMiniMapBroken + RtlUpdateSnesPatchForBugfix(); for (size_t i = 0; i != arraysize(kPatchedCarrys); i++) { @@ -808,12 +861,15 @@ uint32 RunCpuUntilPC(uint32 pc1, uint32 pc2) { } void RunOneFrameOfGame_Emulated(void) { + uint16 bug_fix_bak = bug_fix_counter; // Execute until either WaitForNMI or WaitForLagFrame RunCpuUntilPC(0x808343, 0x85813C); // Trigger nmi, then run until WaitForNMI or WaitForLagFrame returns g_snes->cpu->nmiWanted = true; RunCpuUntilPC(0x80834A, 0x858142); + + bug_fix_counter = bug_fix_bak; } void DrawFrameToPpu(void) { @@ -922,4 +978,4 @@ void RtlRunFrameCompare(uint16 input, int run_what) { g_use_my_apu_code = true; RunOneFrameOfGame_Both(); } -} \ No newline at end of file +} diff --git a/src/sm_rtl.c b/src/sm_rtl.c index 58e4001..108d3f1 100644 --- a/src/sm_rtl.c +++ b/src/sm_rtl.c @@ -443,7 +443,8 @@ void RtlSaveSnapshot(const char *filename, bool saving_with_bug) { } static const char *const kBugSaves[] = { - "After Crocomire" + "Before Kraid", + "Before Golden Torizo", "After Crocomire", "Baby Metroid", "Tourian Statue", "Before Ridley", "Enter Mother Brain", }; void RtlSaveLoad(int cmd, int slot) { @@ -481,6 +482,10 @@ void RtlSaveLoad(int cmd, int slot) { if (coroutine_state_0 == 4) coroutine_state_0 = 10 + game_state; + // bug_fix_counter_BAD didn't actually belong to free ram... + if (bug_fix_counter == 0) + bug_fix_counter = bug_fix_counter_BAD; + } else { RtlSaveSnapshot(name, false); } @@ -765,4 +770,4 @@ void RtlWriteSram(void) { } else { fprintf(stderr, "Unable to write saves/sm.srm\n"); } -} \ No newline at end of file +} diff --git a/src/sm_rtl.h b/src/sm_rtl.h index a8f6deb..2417027 100644 --- a/src/sm_rtl.h +++ b/src/sm_rtl.h @@ -50,7 +50,7 @@ bool Unreachable(); #define INSTR_RETURN_ADDR(x) ((const uint16*)(uintptr_t)(x)) #define INSTR_INCR_BYTES(x, n) ((const uint16*)((uintptr_t)(x) + n)) -#define INSTR_ADDR_TO_PTR(k, jp) ((uint8*)(jp) - (RomPtrWithBank(gEnemyData(k)->bank, 0x8000) - 0x8000)) +#define INSTR_ADDR_TO_PTR(k, jp) ((uint8*)(jp) - (RomBankBase(gEnemyData(k)->bank))) #define INSTRB_RETURN_ADDR(x) ((const uint8*)(uintptr_t)(x)) @@ -59,6 +59,7 @@ bool Unreachable(); static inline uint16 GET_WORD(const uint8 *p) { return *(uint16 *)(p); } #else #define GET_WORD(p) (*(uint16*)(p)) + #endif #define GET_BYTE(p) (*(uint8*)(p)) @@ -117,6 +118,9 @@ static inline const uint8 *RomPtr_B3(uint16_t addr) { return RomPtr(0xb30000 | a static inline const uint8 *RomPtr_B4(uint16_t addr) { return RomPtr(0xb40000 | addr); } static inline const uint8 *RomPtr_B7(uint16_t addr) { return RomPtr(0xb70000 | addr); } static inline const uint8 *RomPtrWithBank(uint8 bank, uint16_t addr) { return RomPtr((bank << 16) | addr); } +static inline const uint8 *RomBankBase(uint8 bank) { return RomPtr((bank << 16) + 0x8000) - 0x8000; } + + void WriteReg(uint16 reg, uint8 value); void WriteRegWord(uint16 reg, uint16 value); @@ -201,9 +205,8 @@ extern const int16 kSinCosTable8bit_Sext[320]; #define kSamusAnimationDelayData ((uint16*)RomFixedPtr(0x91b010)) #define kCommonEnemySpeeds_Linear ((uint16*)RomFixedPtr(0xa28187)) #define kCommonEnemySpeeds_Quadratic ((uint16*)RomFixedPtr(0xa2838f)) +#define kCommonEnemySpeeds_Quadratic32 ((uint32*)RomFixedPtr(0xa0cbc7)) #define kSine16bit ((uint16*)RomFixedPtr(0xa0b1c3)) -#define kOamExtra_X8Small_And_Large ((uint16*)RomFixedPtr(0x81839f)) -#define kOamExtra_Address_And_X8Large ((uint16*)RomFixedPtr(0x81859f)) #define kTanTable ((uint16*)RomFixedPtr(0x91c9d4)) void CallEnemyAi(uint32 ea); diff --git a/src/snes/cpu.c b/src/snes/cpu.c index a8c3a4f..737dc12 100644 --- a/src/snes/cpu.c +++ b/src/snes/cpu.c @@ -8,8 +8,9 @@ #include "cpu.h" #include "snes.h" #include "../types.h" +#include "../ida_types.h" +#include "../enemy_types.h" #include "../variables.h" - static const int cyclesPerOpcode[256] = { 7, 6, 7, 4, 5, 3, 5, 6, 3, 2, 2, 4, 6, 4, 6, 5, 2, 5, 5, 7, 5, 4, 6, 6, 2, 4, 2, 2, 6, 4, 7, 5, @@ -44,6 +45,8 @@ static void cpu_writeWord(Cpu* cpu, uint32_t adrl, uint32_t adrh, uint16_t value static void cpu_doInterrupt(Cpu* cpu, bool irq); static void cpu_doOpcode(Cpu* cpu, uint8_t opcode); +extern Snes *g_snes; // for debugging + // addressing modes and opcode functions not declared, only used after defintions static uint8_t cpu_read(Cpu* cpu, uint32_t adr) { diff --git a/src/snes/snes.c b/src/snes/snes.c index 59f392e..1e71e5e 100644 --- a/src/snes/snes.c +++ b/src/snes/snes.c @@ -164,7 +164,7 @@ void snes_handle_pos_stuff(Snes *snes) { } } -#define IS_ADR(x) (x == 0xfffff ) +#define IS_ADR(x) (x == 0xfffff) void snes_catchupApu(Snes* snes) { if (snes->apuCatchupCycles > 10000) @@ -407,9 +407,11 @@ uint8_t snes_read(Snes* snes, uint32_t adr) { } void LogWrite(Snes *snes, uint32_t adr, uint8_t val) { - printf("@%d: Write to 0x%x = 0x%.2x: 0x%x: 0x%x: x = 0x%x, y = 0x%x, c = %d\n", + printf("@%d: Write to 0x%x = 0x%.2x: 0x%x: r18=0x%x: r20=0x%x: a = 0x%x, x = 0x%x, y = 0x%x, c = %d\n", snes_frame_counter, adr, val, snes->cpu->k << 16 | snes->cpu->pc, - snes->ram[0x12] | snes->ram[0x13] << 8, snes->cpu->x, snes->cpu->y, snes->cpu->c); + snes->ram[0x12] | snes->ram[0x13] << 8, + snes->ram[0x14] | snes->ram[0x15] << 8, + snes->cpu->a, snes->cpu->x, snes->cpu->y, snes->cpu->c); } void snes_write(Snes* snes, uint32_t adr, uint8_t val) { diff --git a/src/spc_player.c b/src/spc_player.c index 4cbe093..2ea0402 100644 --- a/src/spc_player.c +++ b/src/spc_player.c @@ -1785,4 +1785,4 @@ void RunAudioPlayer(void) { } } } -#endif // WITH_SPC_PLAYER_DEBUGGING \ No newline at end of file +#endif // WITH_SPC_PLAYER_DEBUGGING diff --git a/src/types.h b/src/types.h index f186a29..9c8ecfc 100644 --- a/src/types.h +++ b/src/types.h @@ -30,6 +30,7 @@ typedef uint16 VoidP; #define arraysize(x) sizeof(x)/sizeof(x[0]) #define sign8(x) ((x) & 0x80) #define sign16(x) ((x) & 0x8000) +#define sign32(x) ((x) & 0x80000000) #define load24(x) ((*(uint32*)&(x))&0xffffff) #ifdef _MSC_VER @@ -129,6 +130,9 @@ typedef struct Point16U { uint16 x, y; } Point16U; +typedef struct Rect16U { + uint16 x, y, w, h; +} Rect16U; // Some convenience macros to make partial accesses nicer #define LAST_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1) diff --git a/src/variables.h b/src/variables.h index 15bd728..6c20ae3 100644 --- a/src/variables.h +++ b/src/variables.h @@ -4,36 +4,24 @@ extern uint8 g_ram[0x20000]; +static inline void AddToHiLo(uint16 *hi, uint16 *lo, uint32 v) { + uint32 t = *lo + (*hi << 16) + v; + *lo = t; + *hi = t >> 16; +} -// Aliasing -// This is used in some R18:R20 places to multiply by 256 -#define R19_ (*(uint16*)(g_ram+0x13)) +static inline void SetHiLo(uint16 *hi, uint16 *lo, uint32 t) { + *lo = t; + *hi = t >> 16; +} -#define R0_ (*(LongPtr*)(g_ram+0x0)) -#define R3_ (*(LongPtr*)(g_ram+0x3)) -#define R6_ (*(LongPtr*)(g_ram+0x6)) -#define R9_ (*(LongPtr*)(g_ram+0x9)) -#define R12_ (*(uint16*)(g_ram+0xC)) -#define R14_ (*(uint16*)(g_ram+0xE)) -#define R16_ (*(uint16*)(g_ram+0x10)) -#define R18_ (*(uint16*)(g_ram+0x12)) -#define R20_ (*(uint16*)(g_ram+0x14)) -#define R22_ (*(uint16*)(g_ram+0x16)) -#define R24_ (*(uint16*)(g_ram+0x18)) -#define R26_ (*(uint16*)(g_ram+0x1A)) -#define R28_ (*(uint16*)(g_ram+0x1C)) -#define R30_ (*(uint16*)(g_ram+0x1E)) -#define R32_ (*(uint16*)(g_ram+0x20)) -#define R34 (*(uint16*)(g_ram+0x22)) -#define R36 (*(uint16*)(g_ram+0x24)) -#define R38 (*(uint16*)(g_ram+0x26)) -#define R40 (*(uint16*)(g_ram+0x28)) -#define R42 (*(uint16*)(g_ram+0x2A)) -#define R44 (*(uint16*)(g_ram+0x2C)) -#define R46 (*(uint16*)(g_ram+0x2E)) -#define R48 (*(uint16*)(g_ram+0x30)) -#define R50 (*(uint16*)(g_ram+0x32)) +extern int32 *cur_coll_amt32; + + +#define INT16_SHL8(x) ((int16)(x) << 8) +#define INT16_SHL16(x) ((int16)(x) << 16) + #define bg3_tilemap_offset (*(uint16*)(g_ram+0x34)) #define copywithflip_src (*(LongPtr*)(g_ram+0x36)) #define g_byte_7E0039 (*(uint8*)(g_ram+0x39)) @@ -106,7 +94,7 @@ extern uint8 g_ram[0x20000]; #define irqhandler_next_handler (*(uint16*)(g_ram+0xA7)) #define room_loading_irq_handler (*(uint16*)(g_ram+0xA9)) #define cur_irq_handler (*(uint16*)(g_ram+0xAB)) -#define ptr_to_retaddr_parameters (*(uint16*)(g_ram+0xAD)) +#define REMOVED_ptr_to_retaddr_parameters (*(uint16*)(g_ram+0xAD)) #define current_region_animated_palette_fx (*(uint16*)(g_ram+0xAF)) #define reg_BG1HOFS (*(uint16*)(g_ram+0xB1)) #define reg_BG1VOFS (*(uint16*)(g_ram+0xB3)) @@ -141,7 +129,8 @@ extern uint8 g_ram[0x20000]; // Keep track of which bug fixes have been made to prevent // replays from desyncing. -#define bug_fix_counter (*(uint16*)(g_ram+0x1FF00)) +#define bug_fix_counter_BAD (*(uint16*)(g_ram+0x1FF00)) +#define bug_fix_counter (*(uint16*)(g_ram+0xC2)) #define g_word_7E0596 (*(uint16*)(g_ram+0x596)) #define g_word_7E0598 (*(uint16*)(g_ram+0x598)) @@ -185,10 +174,10 @@ extern uint8 g_ram[0x20000]; #define previous_timed_held_input (*(uint16*)(g_ram+0x5E3)) #define random_number (*(uint16*)(g_ram+0x5E5)) #define bitmask (*(uint16*)(g_ram+0x5E7)) -#define mult_tmp_a (*(uint16*)(g_ram+0x5E9)) -#define mult_tmp_y (*(uint16*)(g_ram+0x5EB)) -#define mult_product_lo (*(uint16*)(g_ram+0x5F1)) -#define mult_product_hi (*(uint16*)(g_ram+0x5F3)) +#define REMOVED_mult_tmp_a (*(uint16*)(g_ram+0x5E9)) +#define REMOVED_mult_tmp_y (*(uint16*)(g_ram+0x5EB)) +#define REMOVED_mult_product_lo (*(uint16*)(g_ram+0x5F1)) +#define REMOVED_mult_product_hi (*(uint16*)(g_ram+0x5F3)) #define debug_disable_sounds (*(uint16*)(g_ram+0x5F5)) #define debug_disable_minimap (*(uint16*)(g_ram+0x5F7)) #define save_confirmation_selection (*(uint16*)(g_ram+0x5F9)) @@ -199,9 +188,9 @@ extern uint8 g_ram[0x20000]; #define unpause_hook (*(LongPtr*)(g_ram+0x604)) #define earthquake_sfx_index (*(uint16*)(g_ram+0x607)) #define earthquake_sfx_timer (*(uint16*)(g_ram+0x609)) -#define remaining_enemy_spritemap_entries (*(uint16*)(g_ram+0x60B)) -#define remaining_enemy_hitbox_entries (*(uint16*)(g_ram+0x60D)) -#define num_projectiles_to_check_enemy_coll (*(uint16*)(g_ram+0x60F)) +#define enemy_projectile_init_param_3 (*(uint8*)(g_ram+0x60B)) +#define REMOVED_remaining_enemy_hitbox_entries (*(uint16*)(g_ram+0x60D)) +#define REMOVED_num_projectiles_to_check_enemy_coll (*(uint16*)(g_ram+0x60F)) #define is_uploading_apu (*(uint16*)(g_ram+0x617)) #define music_queue_track ((uint16*)(g_ram+0x619)) #define music_queue_delay ((uint16*)(g_ram+0x629)) @@ -209,7 +198,7 @@ extern uint8 g_ram[0x20000]; #define music_queue_read_pos (*(uint16*)(g_ram+0x63B)) #define music_entry (*(uint16*)(g_ram+0x63D)) #define music_timer (*(uint16*)(g_ram+0x63F)) -#define apu_attempts_countdown (*(uint16*)(g_ram+0x641)) +#define REMOVED_apu_attempts_countdown (*(uint16*)(g_ram+0x641)) #define sfx_readpos ((uint8*)(g_ram+0x643)) #define sfx_writepos ((uint8*)(g_ram+0x646)) #define sfx_state ((uint8*)(g_ram+0x649)) @@ -366,11 +355,11 @@ extern uint8 g_ram[0x20000]; #define samus_door_transition_speed (*(uint16*)(g_ram+0x92D)) #define downwards_elevator_delay_timer (*(uint16*)(g_ram+0x92F)) #define door_transition_flag (*(uint16*)(g_ram+0x931)) -#define temp933 (*(uint16*)(g_ram+0x933)) -#define x_block_of_vram_blocks_to_update (*(uint16*)(g_ram+0x935)) -#define tmp_vram_base_addr (*(uint16*)(g_ram+0x937)) -#define loopcounter (*(uint16*)(g_ram+0x939)) -#define tmp_block_to_update (*(uint16*)(g_ram+0x93B)) +#define var933 (*(uint16*)(g_ram+0x933)) +#define var935 (*(uint16*)(g_ram+0x935)) +#define var937 (*(uint16*)(g_ram+0x937)) +#define var939 (*(uint16*)(g_ram+0x939)) +#define var93B (*(uint16*)(g_ram+0x93B)) #define ceres_status (*(uint16*)(g_ram+0x93F)) #define camera_distance_index (*(uint16*)(g_ram+0x941)) #define timer_status (*(uint16*)(g_ram+0x943)) @@ -651,8 +640,8 @@ extern uint8 g_ram[0x20000]; #define grapple_beam_flags (*(uint16*)(g_ram+0xCF4)) #define grapple_varCF6 (*(uint16*)(g_ram+0xCF6)) #define slow_grabble_scrolling_flag (*(uint16*)(g_ram+0xCF8)) -#define grapple_beam_end_subangle (*(uint8*)(g_ram+0xCFA)) -#define grapple_beam_end_angle (*(uint8*)(g_ram+0xCFB)) +#define grapple_beam_end_angle16 (*(uint16*)(g_ram+0xCFA)) +#define grapple_beam_end_angle_hi (*(uint8*)(g_ram+0xCFB)) #define grapple_beam_end_angles_mirror (*(uint16*)(g_ram+0xCFC)) #define grapple_beam_length (*(uint16*)(g_ram+0xCFE)) #define grapple_beam_length_delta (*(uint16*)(g_ram+0xD00)) @@ -690,13 +679,13 @@ extern uint8 g_ram[0x20000]; #define grapple_point_anim_ptr (*(uint16*)(g_ram+0xD40)) #define grapple_segment_anim_instr_timers ((uint16*)(g_ram+0xD42)) #define grapple_segment_anim_instr_ptrs ((uint16*)(g_ram+0xD62)) -#define grapple_beam_tmpD82 (*(uint16*)(g_ram+0xD82)) -#define grapple_beam_tmpD84 (*(uint16*)(g_ram+0xD84)) -#define grapple_beam_y_quarter_subvel (*(uint16*)(g_ram+0xD86)) -#define grapple_beam_y_quarter_vel (*(uint16*)(g_ram+0xD88)) -#define grapple_beam_tmpD8A (*(uint16*)(g_ram+0xD8A)) -#define grapple_beam_varD8C (*(uint16*)(g_ram+0xD8C)) -#define grapple_beam_varD8E (*(uint16*)(g_ram+0xD8E)) +#define button_config_shoot_x_saved (*(uint16*)(g_ram+0xD82)) +#define button_config_jump_a_saved (*(uint16*)(g_ram+0xD84)) +#define button_config_run_b_saved (*(uint16*)(g_ram+0xD86)) +#define button_config_itemcancel_y_saved (*(uint16*)(g_ram+0xD88)) +#define button_config_itemswitch_saved (*(uint16*)(g_ram+0xD8A)) +#define button_config_aim_down_L_saved (*(uint16*)(g_ram+0xD8C)) +#define button_config_aim_up_R_saved (*(uint16*)(g_ram+0xD8E)) #define grapple_beam_grapple_start_x (*(uint16*)(g_ram+0xD90)) #define grapple_beam_grapple_start_y (*(uint16*)(g_ram+0xD92)) #define grapple_beam_grapple_start_block_x (*(uint16*)(g_ram+0xD94)) @@ -728,7 +717,7 @@ extern uint8 g_ram[0x20000]; #define queued_message_box_index (*(uint16*)(g_ram+0xDC8)) #define samus_collides_with_solid_enemy (*(uint16*)(g_ram+0xDCE)) #define samus_collision_flag (*(uint16*)(g_ram+0xDD0)) -#define temp_collision_DD2 (*(uint16*)(g_ram+0xDD2)) +#define REMOVED_temp_collision_DD2 (*(uint16*)(g_ram+0xDD2)) #define REMOVED_temp_collision_DD4 (*(uint16*)(g_ram+0xDD4)) #define REMOVED_temp_collision_DD6 (*(uint16*)(g_ram+0xDD6)) #define suit_pickup_light_beam_widening_speed (*(uint16*)(g_ram+0xDDC)) @@ -745,14 +734,14 @@ extern uint8 g_ram[0x20000]; #define suit_pickup_color_math_G (*(uint8*)(g_ram+0xDF1)) #define suit_pickup_color_math_B (*(uint8*)(g_ram+0xDF2)) #define suit_pickup_palette_transition_color (*(uint8*)(g_ram+0xDF3)) -#define debug_spare_cpu_display_flag (*(uint16*)(g_ram+0xDF4)) -#define g_word_7E0DF6 (*(uint16*)(g_ram+0xDF6)) +#define UNUSED_debug_spare_cpu_display_flag (*(uint16*)(g_ram+0xDF4)) +#define UNUSED_word_7E0DF6 (*(uint16*)(g_ram+0xDF6)) #define UNUSED_word_7E0DF8 (*(uint16*)(g_ram+0xDF8)) #define UNUSED_word_7E0DFA (*(uint16*)(g_ram+0xDFA)) #define UNUSED_word_7E0DFC (*(uint16*)(g_ram+0xDFC)) #define joypad1_input_samusfilter (*(uint16*)(g_ram+0xDFE)) #define joypad1_newinput_samusfilter (*(uint16*)(g_ram+0xE00)) -#define samus_bottom_boundary_position (*(uint16*)(g_ram+0xE02)) +#define REMOVED_samus_bottom_boundary_position (*(uint16*)(g_ram+0xE02)) #define distance_to_eject_samus_left (*(uint16*)(g_ram+0xE04)) #define distance_to_eject_samus_right (*(uint16*)(g_ram+0xE06)) #define distance_to_eject_samus_up (*(uint16*)(g_ram+0xE08)) @@ -764,33 +753,33 @@ extern uint8 g_ram[0x20000]; #define health_drop_bias_flag (*(uint16*)(g_ram+0xE1A)) #define enemy_index_to_shake (*(uint16*)(g_ram+0xE1C)) #define nmi_flag_bg2_enemy_vram_transfer (*(uint16*)(g_ram+0xE1E)) -#define enemy_population_ptr (*(uint16*)(g_ram+0xE20)) -#define draw_oam_x_offset (*(uint16*)(g_ram+0xE22)) -#define varE24 (*(uint16*)(g_ram+0xE24)) -#define varE26 (*(uint16*)(g_ram+0xE26)) -#define varE28 (*(uint16*)(g_ram+0xE28)) -#define varE2A (*(uint16*)(g_ram+0xE2A)) -#define varE2C (*(uint16*)(g_ram+0xE2C)) -#define varE2E (*(uint16*)(g_ram+0xE2E)) -#define draw_enemy_layer (*(uint16*)(g_ram+0xE32)) -#define enemy_drawing_queue_index (*(uint16*)(g_ram+0xE34)) -#define loop_index_end (*(uint16*)(g_ram+0xE36)) -#define loop_index (*(uint16*)(g_ram+0xE38)) -#define enemy_drawing_queue_base (*(uint16*)(g_ram+0xE3A)) -#define g_word_7E0E3C (*(uint16*)(g_ram+0xE3C)) -#define g_word_7E0E3E (*(uint16*)(g_ram+0xE3E)) -#define enemy_damage_multiplier (*(uint16*)(g_ram+0xE40)) -#define enemy_damage_routine_exec_count (*(uint16*)(g_ram+0xE44)) +#define REMOVED_varE20 (*(uint16*)(g_ram+0xE20)) +#define REMOVED_varE22 (*(uint16*)(g_ram+0xE22)) +#define REMOVED_varE24 (*(uint16*)(g_ram+0xE24)) +#define REMOVED_varE26 (*(uint16*)(g_ram+0xE26)) +#define REMOVED_varE28 (*(uint16*)(g_ram+0xE28)) +#define REMOVED_varE2A (*(uint16*)(g_ram+0xE2A)) +#define REMOVED_varE2C (*(uint16*)(g_ram+0xE2C)) +#define REMOVED_varE2E (*(uint16*)(g_ram+0xE2E)) +#define REMOVED_varE32 (*(uint16*)(g_ram+0xE32)) +#define REMOVED_varE34 (*(uint16*)(g_ram+0xE34)) +#define REMOVED_varE36 (*(uint16*)(g_ram+0xE36)) +#define REMOVED_varE38 (*(uint16*)(g_ram+0xE38)) +#define REMOVED_varE3A (*(uint16*)(g_ram+0xE3A)) +#define REMOVED_varE3C (*(uint16*)(g_ram+0xE3C)) +#define REMOVED_varE3E (*(uint16*)(g_ram+0xE3E)) +#define last_enemy_power (*(uint16*)(g_ram+0xE40)) +#define random_enemy_counter (*(uint16*)(g_ram+0xE44)) #define UNUSED_word_7E0E46 (*(uint16*)(g_ram+0xE46)) #define UNUSED_word_7E0E48 (*(uint16*)(g_ram+0xE48)) -#define new_enemy_index (*(uint16*)(g_ram+0xE4A)) +#define REMOVED_new_enemy_index (*(uint16*)(g_ram+0xE4A)) #define first_free_enemy_index (*(uint16*)(g_ram+0xE4C)) #define num_enemies_in_room (*(uint16*)(g_ram+0xE4E)) #define num_enemies_killed_in_room (*(uint16*)(g_ram+0xE50)) #define num_enemy_deaths_left_to_clear (*(uint16*)(g_ram+0xE52)) #define cur_enemy_index (*(uint16*)(g_ram+0xE54)) -#define cur_enemy_index_backup (*(uint16*)(g_ram+0xE56)) -#define enemy_data_ptr (*(uint16*)(g_ram+0xE58)) +#define REMOVED_cur_enemy_index_backup (*(uint16*)(g_ram+0xE56)) +#define REMOVED_enemy_data_ptr (*(uint16*)(g_ram+0xE58)) #define enemy_tile_load_data ((EnemyTileLoadData*)(g_ram+0xE5A)) #define enemy_tile_load_data_write_pos (*(uint16*)(g_ram+0xE7A)) #define enemy_tile_vram_src (*(uint16*)(g_ram+0xE7C)) @@ -804,10 +793,10 @@ extern uint8 g_ram[0x20000]; #define fireflea_darkness_level (*(uint16*)(g_ram+0x177E)) #define UNUSED_word_7E1780 (*(uint16*)(g_ram+0x1780)) #define UNUSED_word_7E1782 (*(uint16*)(g_ram+0x1782)) -#define enemy_ai_pointer (*(LongPtr*)(g_ram+0x1784)) -#define enemy_ai_pointer_backup (*(LongPtr*)(g_ram+0x1788)) +#define REMOVED_enemy_ai_pointer (*(LongPtr*)(g_ram+0x1784)) +#define REMOVED_enemy_ai_pointer_backup (*(LongPtr*)(g_ram+0x1788)) #define enemy_gfx_drawn_hook (*(LongPtr*)(g_ram+0x178C)) -#define set_to_rtl_when_loading_enemies_unused (*(LongPtr*)(g_ram+0x1790)) +#define REMOVED_set_to_rtl_when_loading_enemies_unused (*(LongPtr*)(g_ram+0x1790)) #define variables_for_enemy_graphics_drawn_hook ((uint16*)(g_ram+0x1794)) #define enemy_bg2_tilemap_size (*(uint16*)(g_ram+0x179A)) #define boss_id (*(uint16*)(g_ram+0x179C)) @@ -816,28 +805,28 @@ extern uint8 g_ram[0x20000]; #define UNUSED_word_7E17A2 (*(uint16*)(g_ram+0x17A2)) #define active_enemy_indexes_write_ptr (*(uint16*)(g_ram+0x17A4)) #define interactive_enemy_indexes_write_ptr (*(uint16*)(g_ram+0x17A6)) -#define active_enemy_indexes_index (*(uint16*)(g_ram+0x17A8)) +#define REMOVED_active_enemy_indexes_index (*(uint16*)(g_ram+0x17A8)) #define REMOVED_interactive_enemy_indexes_index (*(uint16*)(g_ram+0x17AA)) #define active_enemy_indexes ((uint16*)(g_ram+0x17AC)) #define interactive_enemy_indexes ((uint16*)(g_ram+0x17EC)) #define enemy_index_colliding_dirs ((uint16*)(g_ram+0x182C)) -#define distance_to_enemy_colliding_dirs ((uint16*)(g_ram+0x1834)) +#define REMOVED_distance_to_enemy_colliding_dirs ((uint16*)(g_ram+0x1834)) #define flag_process_all_enemies (*(uint16*)(g_ram+0x183C)) #define earthquake_type (*(uint16*)(g_ram+0x183E)) #define earthquake_timer (*(uint16*)(g_ram+0x1840)) #define frame_counter_every_frame (*(uint16*)(g_ram+0x1842)) #define sprite_object_index (*(uint16*)(g_ram+0x1844)) -#define debug_enemy_index (*(uint16*)(g_ram+0x1846)) +#define debug_enemy_index_UNUSED (*(uint16*)(g_ram+0x1846)) #define log_index_UNUSED (*(uint16*)(g_ram+0x1848)) -#define samus_x_pos_colliding_solid (*(uint16*)(g_ram+0x184A)) -#define samus_x_subpos_colliding_solid (*(uint16*)(g_ram+0x184C)) -#define enemy_x_pos_colliding_solid (*(uint16*)(g_ram+0x184E)) -#define enemy_x_subpos_colliding_solid (*(uint16*)(g_ram+0x1850)) -#define samus_pos_delta_colliding_solid (*(uint16*)(g_ram+0x1852)) -#define samus_subpos_delta_colliding_solid (*(uint16*)(g_ram+0x1854)) -#define samus_y_pos_colliding_solid (*(uint16*)(g_ram+0x1856)) -#define samus_y_subpos_colliding_solid (*(uint16*)(g_ram+0x1858)) -#define solid_enemy_collision_type (*(uint16*)(g_ram+0x185A)) +#define REMOVED_samus_x_pos_colliding_solid (*(uint16*)(g_ram+0x184A)) +#define REMOVED_samus_x_subpos_colliding_solid (*(uint16*)(g_ram+0x184C)) +#define REMOVED_enemy_x_pos_colliding_solid (*(uint16*)(g_ram+0x184E)) +#define REMOVED_enemy_x_subpos_colliding_solid (*(uint16*)(g_ram+0x1850)) +#define REMOVED_samus_pos_delta_colliding_solid (*(uint16*)(g_ram+0x1852)) +#define REMOVED_samus_subpos_delta_colliding_solid (*(uint16*)(g_ram+0x1854)) +#define REMOVED_samus_y_pos_colliding_solid (*(uint16*)(g_ram+0x1856)) +#define REMOVED_samus_y_subpos_colliding_solid (*(uint16*)(g_ram+0x1858)) +#define REMOVED_solid_enemy_collision_type (*(uint16*)(g_ram+0x185A)) #define debug_index (*(uint16*)(g_ram+0x185C)) #define debug_time_frozen_for_enemies (*(uint16*)(g_ram+0x185E)) #define debug_text_cursor_x (*(uint16*)(g_ram+0x1860)) @@ -846,24 +835,24 @@ extern uint8 g_ram[0x20000]; #define debug_enemy_population_pointer (*(uint16*)(g_ram+0x1866)) #define debug_enemy_spawn_x_pos (*(uint16*)(g_ram+0x1868)) #define debug_enemy_spawn_y_pos (*(uint16*)(g_ram+0x186A)) -#define enemy_spritemap_entry_pointer (*(uint16*)(g_ram+0x186E)) -#define enemy_left_border_collision (*(uint16*)(g_ram+0x1870)) -#define enemy_bottom_border_collision (*(uint16*)(g_ram+0x1872)) -#define enemy_right_border_collision (*(uint16*)(g_ram+0x1874)) -#define enemy_top_border_collision (*(uint16*)(g_ram+0x1876)) -#define hitbox_ptr (*(uint16*)(g_ram+0x1878)) -#define enemy_spritemap_entry_coll_x_pos (*(uint16*)(g_ram+0x187A)) -#define num_projs_to_check (*(uint16*)(g_ram+0x187C)) -#define samus_right_border_coll (*(uint16*)(g_ram+0x187E)) -#define samus_left_border_coll (*(uint16*)(g_ram+0x1880)) -#define samus_bottom_border_coll (*(uint16*)(g_ram+0x1882)) -#define samus_top_border_coll (*(uint16*)(g_ram+0x1884)) -#define samus_target_x_pos (*(uint16*)(g_ram+0x189A)) -#define samus_target_x_subpos (*(uint16*)(g_ram+0x189C)) -#define samus_target_y_pos (*(uint16*)(g_ram+0x189E)) -#define samus_target_y_subpos (*(uint16*)(g_ram+0x18A0)) -#define samus_x_radius_mirror (*(uint16*)(g_ram+0x18A2)) -#define samus_y_radius_mirror (*(uint16*)(g_ram+0x18A4)) +#define REMOVED_enemy_spritemap_entry_pointer (*(uint16*)(g_ram+0x186E)) +#define REMOVED_enemy_left_border_collision (*(uint16*)(g_ram+0x1870)) +#define REMOVED_enemy_bottom_border_collision (*(uint16*)(g_ram+0x1872)) +#define REMOVED_enemy_right_border_collision (*(uint16*)(g_ram+0x1874)) +#define REMOVED_enemy_top_border_collision (*(uint16*)(g_ram+0x1876)) +#define REMOVED_hitbox_ptr (*(uint16*)(g_ram+0x1878)) +#define REMOVED_enemy_spritemap_entry_coll_x_pos (*(uint16*)(g_ram+0x187A)) +#define REMOVED_enemy_spritemap_entry_coll_y_pos (*(uint16*)(g_ram+0x187C)) +#define REMOVED_samus_right_border_coll (*(uint16*)(g_ram+0x187E)) +#define REMOVED_samus_left_border_coll (*(uint16*)(g_ram+0x1880)) +#define REMOVED_samus_bottom_border_coll (*(uint16*)(g_ram+0x1882)) +#define REMOVED_samus_top_border_coll (*(uint16*)(g_ram+0x1884)) +#define REMOVED_samus_target_x_pos (*(uint16*)(g_ram+0x189A)) +#define REMOVED_samus_target_x_subpos (*(uint16*)(g_ram+0x189C)) +#define REMOVED_samus_target_y_pos (*(uint16*)(g_ram+0x189E)) +#define REMOVED_samus_target_y_subpos (*(uint16*)(g_ram+0x18A0)) +#define REMOVED_samus_x_radius_mirror (*(uint16*)(g_ram+0x18A2)) +#define REMOVED_samus_y_radius_mirror (*(uint16*)(g_ram+0x18A4)) #define collision_detection_index (*(uint16*)(g_ram+0x18A6)) #define samus_invincibility_timer (*(uint16*)(g_ram+0x18A8)) #define samus_knockback_timer (*(uint16*)(g_ram+0x18AA)) @@ -911,13 +900,13 @@ extern uint8 g_ram[0x20000]; #define enemy_projectile_enable_flag (*(uint16*)(g_ram+0x198D)) #define enemy_projectile_unk198F (*(uint16*)(g_ram+0x198F)) #define enemy_projectile_index (*(uint16*)(g_ram+0x1991)) -#define enemy_projectile_init_param (*(uint16*)(g_ram+0x1993)) +#define enemy_projectile_init_param_1 (*(uint16*)(g_ram+0x1993)) #define enemy_projectile_unk1995 (*(uint16*)(g_ram+0x1995)) #define enemy_projectile_id ((uint16*)(g_ram+0x1997)) #define enemy_projectile_gfx_idx ((uint16*)(g_ram+0x19BB)) #define enemy_projectile_timers ((uint16*)(g_ram+0x19DF)) #define enemy_projectile_pre_instr ((uint16*)(g_ram+0x1A03)) -#define enemy_projectile_1A27 ((uint16*)(g_ram+0x1A27)) +#define enemy_projectile_x_subpos ((uint16*)(g_ram+0x1A27)) #define enemy_projectile_x_pos ((uint16*)(g_ram+0x1A4B)) #define enemy_projectile_y_subpos ((uint16*)(g_ram+0x1A6F)) #define enemy_projectile_y_pos ((uint16*)(g_ram+0x1A93)) @@ -980,7 +969,6 @@ extern uint8 g_ram[0x20000]; #define demo_set (*(uint16*)(g_ram+0x1F55)) #define demo_scene (*(uint16*)(g_ram+0x1F57)) #define num_demo_sets (*(uint16*)(g_ram+0x1F59)) -#define STACK ((uint16*)(g_ram+0x1F5B)) #define tilemap_stuff ((uint16*)(g_ram+0x2000)) #define ram3000 (*(Ram3000*)(g_ram+0x3000)) #define ram3800 (*(Ram3800*)(g_ram+0x3800)) @@ -1140,8 +1128,8 @@ extern uint8 g_ram[0x20000]; #define enemy_def_ptr ((uint16*)(g_ram+0xEF5C)) #define enemy_gfxdata_tiles_index ((uint16*)(g_ram+0xEF64)) #define enemy_gfxdata_vram_ptr ((uint16*)(g_ram+0xEF6C)) -#define enemy_gfx_data_write_ptr (*(uint16*)(g_ram+0xEF74)) -#define next_enemy_tiles_index (*(uint16*)(g_ram+0xEF76)) +#define REMOVED_enemy_gfx_data_write_ptr (*(uint16*)(g_ram+0xEF74)) +#define REMOVED_next_enemy_tiles_index (*(uint16*)(g_ram+0xEF76)) #define sprite_instr_list_ptrs ((uint16*)(g_ram+0xEF78)) #define sprite_instr_timer ((uint16*)(g_ram+0xEFF8)) #define sprite_palettes ((uint16*)(g_ram+0xF078)) @@ -1151,9 +1139,6 @@ extern uint8 g_ram[0x20000]; #define sprite_y_subpos ((uint16*)(g_ram+0xF278)) #define sprite_disable_flag ((uint16*)(g_ram+0xF2F8)) #define enemy_processing_stage (*(uint16*)(g_ram+0xF378)) -#define g_word_7EF37A (*(uint16*)(g_ram+0xF37A)) -#define g_word_7EF37C (*(uint16*)(g_ram+0xF37C)) -#define g_word_7EF37E (*(uint16*)(g_ram+0xF37E)) #define enemy_projectile_flags ((uint16*)(g_ram+0xF380)) #define enemy_projectile_enemy_header_ptr ((uint16*)(g_ram+0xF3C8)) #define enemy_projectile_killed_enemy_index ((uint16*)(g_ram+0xF410)) @@ -1161,13 +1146,8 @@ extern uint8 g_ram[0x20000]; #define special_death_item_drop_y_origin_pos (*(uint16*)(g_ram+0xF436)) #define ram7F_start (*(uint16*)(g_ram+0x10000)) #define level_data ((uint16*)(g_ram+0x10002)) -#define g_word_7F1902 (*(uint16*)(g_ram+0x11902)) -#define g_word_7F3202 (*(uint16*)(g_ram+0x13202)) -#define g_word_7F4000 (*(uint16*)(g_ram+0x14000)) -#define g_word_7F4B02 (*(uint16*)(g_ram+0x14B02)) #define BTS ((uint8*)(g_ram+0x16402)) #define custom_background ((uint16*)(g_ram+0x19602)) -#define unused_1fa02 ((uint8*)(g_ram+0x1FA02)) #define kSramChecksum ((uint16*)(g_sram+0x0)) #define kSramChecksumInverted ((uint16*)(g_sram+0x8)) #define sram_save_slot_selected (*(uint16*)(g_sram+0x1FEC)) @@ -1175,8 +1155,6 @@ extern uint8 g_ram[0x20000]; #define kSramChecksumUpper ((uint16*)(g_sram+0x1FF0)) #define kSramChecksumInvertedUpper ((uint16*)(g_sram+0x1FF8)) - - #include "variables_extra.h" #define ADDR16_OF_RAM(x) ((uint8*)&(x) - g_ram)