Skip to content

Commit

Permalink
QoL aaaaaa123456789#11: 255-tile mon animations
Browse files Browse the repository at this point in the history
Fix OpenSRAM

Co-Authored-By: aaaaaa123456789 <[email protected]>
  • Loading branch information
aaaaaa123456789 authored and vulcandth committed Oct 16, 2022
1 parent 3055aa9 commit 420902c
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 31 deletions.
2 changes: 1 addition & 1 deletion engine/events/kurt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SelectApricornForKurt:
call Kurt_GiveUpSelectedQuantityOfSelectedApricorn

.done
call Call_ExitMenu
call ExitMenu
ret

Kurt_SelectApricorn:
Expand Down
71 changes: 55 additions & 16 deletions engine/gfx/load_pics.asm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ GetMonFrontpic:
call _GetFrontpic
pop af
ldh [rSVBK], a
ret
jp CloseSRAM

GetAnimatedFrontpic:
ld a, [wCurPartySpecies]
Expand All @@ -70,31 +70,45 @@ GetAnimatedFrontpic:
xor a
ldh [hBGMapMode], a
call _GetFrontpic
ld a, BANK(vTiles3)
ldh [rVBK], a
call GetAnimatedEnemyFrontpic
xor a
ldh [rVBK], a
pop af
ldh [rSVBK], a
ret
jp CloseSRAM

_GetFrontpic:
ld a, BANK(sEnemyFrontPicTileCount)
call OpenSRAM
push de
call GetBaseData
ld a, [wBasePicSize]
and $f
ld b, a
push bc
call GetFrontpicPointer
ld a, BANK(wDecompressEnemyFrontpic)
ld a, BANK(wDecompressScratch)
ldh [rSVBK], a
ld a, b
ld de, wDecompressEnemyFrontpic
ld de, wDecompressScratch
call FarDecompress
; calculate tile count from final address; requires wDecompressScratch to be at the beginning of the bank
swap e
swap d
ld a, d
and $f0 ; get rid of the upper nibble of the address
or e
; and save the tile count for later
ld [sEnemyFrontPicTileCount], a
pop bc
ld hl, wDecompressScratch
ld de, wDecompressEnemyFrontpic
ld hl, sPaddedEnemyFrontPic
ld de, wDecompressScratch
call PadFrontpic
pop hl
push hl
ld de, wDecompressScratch
ld de, sPaddedEnemyFrontPic
ld c, 7 * 7
ldh a, [hROMBank]
ld b, a
Expand Down Expand Up @@ -128,10 +142,8 @@ GetFrontpicPointer:
ret

GetAnimatedEnemyFrontpic:
ld a, BANK(vTiles3)
ldh [rVBK], a
push hl
ld de, wDecompressScratch
ld de, sPaddedEnemyFrontPic
ld c, 7 * 7
ldh a, [hROMBank]
ld b, a
Expand All @@ -145,17 +157,23 @@ GetAnimatedEnemyFrontpic:
call GetFarWRAMByte
pop hl
and $f
ld de, wDecompressEnemyFrontpic + 5 * 5 tiles
ld de, wDecompressScratch + 5 * 5 tiles
ld c, 5 * 5
cp 5
jr z, .got_dims
ld de, wDecompressEnemyFrontpic + 6 * 6 tiles
ld de, wDecompressScratch + 6 * 6 tiles
ld c, 6 * 6
cp 6
jr z, .got_dims
ld de, wDecompressEnemyFrontpic + 7 * 7 tiles
ld de, wDecompressScratch + 7 * 7 tiles
ld c, 7 * 7
.got_dims
; calculate the number of tiles dedicated to animation
ld a, [sEnemyFrontPicTileCount]
sub c
; exit early if none
ret z
ld c, a
push hl
push bc
call LoadFrontpicTiles
Expand All @@ -164,10 +182,24 @@ GetAnimatedEnemyFrontpic:
ld de, wDecompressScratch
ldh a, [hROMBank]
ld b, a
; if the tiles fit in a single VRAM block ($80 tiles), load them...
ld a, c
sub 128 - 7 * 7
jr c, .finish
; otherwise, load as many as we can...
inc a
ld [sEnemyFrontPicTileCount], a ; save the remainder
ld c, 127 - 7 * 7
call Get2bpp
xor a
ldh [rVBK], a
ret
; ...and load the rest into vTiles4
ld de, wDecompressScratch + (127 - 7 * 7) tiles
ld hl, vTiles4
ldh a, [hROMBank]
ld b, a
ld a, [sEnemyFrontPicTileCount]
ld c, a
.finish
jp Get2bpp

LoadFrontpicTiles:
ld hl, wDecompressScratch
Expand All @@ -181,11 +213,18 @@ LoadFrontpicTiles:
push bc
call LoadOrientedFrontpic
pop bc
ld a, c
and a
jr z, .handle_loop
inc b
jr .handle_loop

.loop
push bc
ld c, 0
call LoadOrientedFrontpic
pop bc
.handle_loop
dec b
jr nz, .loop
ret
Expand Down
2 changes: 2 additions & 0 deletions engine/gfx/pic_animation.asm
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ PokeAnim_ConvertAndApplyBitmask:
ld hl, wPokeAnimGraphicStartTile
add [hl]
pop hl
cp $7f
sbc -1 ;increment if no carry
ld [hl], a
ret

Expand Down
2 changes: 1 addition & 1 deletion engine/link/link.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ LinkTrade:
farcall Link_WaitBGMap
call ScrollingMenuJoypad
push af
call Call_ExitMenu
call ExitMenu
call WaitBGMap2
pop af
bit 1, a
Expand Down
4 changes: 2 additions & 2 deletions engine/link/link_trade.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TestMobileTradeBorderTilemap: ; unreferenced
call SetPalettes
call WaitBGMap
call JoyWaitAorB
call Call_ExitMenu
call ExitMenu
ret

MobileTradeBorderTilemap:
Expand Down Expand Up @@ -160,7 +160,7 @@ PrintWaitingTextAndSyncAndExchangeNybble:
call LoadStandardMenuHeader
call .PrintWaitingText
farcall WaitLinkTransfer
call Call_ExitMenu
call ExitMenu
call WaitBGMap2
ret

Expand Down
2 changes: 1 addition & 1 deletion engine/menus/start_menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ StartMenu::

.Clear:
call ClearBGPalettes
call Call_ExitMenu
call ExitMenu
call ReloadTilesetAndPalettes
call .DrawMenuAccount
call DrawVariableLengthMenuBox
Expand Down
2 changes: 1 addition & 1 deletion engine/pokemon/mon_menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ OpenPartyStats:
call LowVolume
predef StatsScreenInit
call MaxVolume
call Call_ExitMenu
call ExitMenu
ld a, 0
ret

Expand Down
4 changes: 2 additions & 2 deletions mobile/mobile_22.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ Function89b28:
call Function891de
call ClearBGPalettes
call Function893e2
call Call_ExitMenu
call ExitMenu
call Function891ab
call SetPalettes
ret
Expand Down Expand Up @@ -2799,7 +2799,7 @@ Function8a241:
.asm_8a254
call Function891de
call ClearBGPalettes
call Call_ExitMenu
call ExitMenu
call Function891de
and a
ret
Expand Down
2 changes: 1 addition & 1 deletion mobile/mobile_40.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,7 @@ Function10138b:

Function1013aa:
call ClearBGPalettes
call Call_ExitMenu
call ExitMenu
call ReloadTilesetAndPalettes
farcall Function106464
call UpdateSprites
Expand Down
2 changes: 1 addition & 1 deletion mobile/mobile_46.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5389,7 +5389,7 @@ BattleTowerRoomMenu_SetMessage:
Function11a9ce:
call ClearBGPalettes
call ReloadTilesetAndPalettes
call Call_ExitMenu
call ExitMenu
farcall Stubbed_Function106462
farcall Function106464
call GSReloadPalettes
Expand Down
6 changes: 3 additions & 3 deletions mobile/mobile_menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Function4a098:
call WaitBGMap
call LoadStandardMenuHeader
farcall Function89de0
call Call_ExitMenu
call ExitMenu
call MG_Mobile_Layout_LoadPals
call Function4a485
pop bc
Expand Down Expand Up @@ -402,7 +402,7 @@ Function4a28a:
.asm_4a2df
farcall Function11765d
call ClearBGPalettes
call Call_ExitMenu
call ExitMenu
call LoadFontsExtra
scf
ret
Expand Down Expand Up @@ -437,7 +437,7 @@ Function4a28a:
.dont_delete_password
call ExitMenu
.quit
call Call_ExitMenu
call ExitMenu
farcall Mobile_OpenAndCloseMenu_HDMATransferTilemapAndAttrmap
xor a
ret
Expand Down
6 changes: 6 additions & 0 deletions ram/sram.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
SECTION "Scratch", SRAM

UNION
sScratch:: ds $60 tiles

NEXTU
sEnemyFrontPicTileCount:: db
sPaddedEnemyFrontPic:: ds 7 * 7 tiles

ENDU

SECTION "SRAM Bank 0", SRAM

Expand Down
3 changes: 1 addition & 2 deletions ram/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3581,8 +3581,7 @@ wScratchTilemap:: ds BG_MAP_WIDTH * BG_MAP_HEIGHT
wScratchAttrmap:: ds BG_MAP_WIDTH * BG_MAP_HEIGHT

NEXTU
wDecompressScratch:: ds $80 tiles
wDecompressEnemyFrontpic:: ds $80 tiles
wDecompressScratch:: ds $100 tiles

NEXTU
; unidentified uses
Expand Down

0 comments on commit 420902c

Please sign in to comment.