diff options
Diffstat (limited to 'Add-a-new-Pack-pocket.md')
-rw-r--r-- | Add-a-new-Pack-pocket.md | 82 |
1 files changed, 36 insertions, 46 deletions
diff --git a/Add-a-new-Pack-pocket.md b/Add-a-new-Pack-pocket.md index 97efc9b..4b3f0ff 100644 --- a/Add-a-new-Pack-pocket.md +++ b/Add-a-new-Pack-pocket.md @@ -202,7 +202,7 @@ As the `.InitList` comment explains, this "loads 0 in the count and −1 in the Edit [engine/menus/start_menu.asm](../blob/master/engine/menus/start_menu.asm): ```diff - HasNoItems: ; 129d5 + HasNoItems: ld a, [wNumItems] and a ret nz @@ -272,10 +272,10 @@ Edit [engine/items/items.asm](../blob/master/engine/items/items.asm). Four routi Edit `_ReceiveItem`: ```diff - _ReceiveItem:: ; d1d5 + _ReceiveItem:: ... - .Pockets: ; d1e9 + .Pockets: ; entries correspond to item types dw .Item dw .KeyItem @@ -285,7 +285,7 @@ Edit `_ReceiveItem`: ... - .Ball: ; d1fb + .Ball: ld hl, wNumBalls jp PutItemInPocket + @@ -297,7 +297,7 @@ Edit `_ReceiveItem`: Edit `_TossItem`: ```diff - _TossItem:: ; d20d + _TossItem:: ... .Pockets: @@ -308,7 +308,7 @@ Edit `_TossItem`: dw .TMHM + dw .Berry - .Ball: ; d228 + .Ball: ld hl, wNumBalls jp RemoveItemFromPocket + @@ -320,7 +320,7 @@ Edit `_TossItem`: Edit `_CheckItem`: ```diff - _CheckItem:: ; d244 + _CheckItem:: ... .Pockets: @@ -331,7 +331,7 @@ Edit `_CheckItem`: dw .TMHM + dw .Berry - .Ball: ; d25f + .Ball: ld hl, wNumBalls jp CheckTheItem + @@ -343,7 +343,7 @@ Edit `_CheckItem`: And edit `GetPocketCapacity`: ```diff - GetPocketCapacity: ; d283 + GetPocketCapacity: ld c, MAX_ITEMS ld a, e cp LOW(wNumItems) @@ -405,10 +405,10 @@ These are jumptable indexes. Jumptables are a common design pattern you'll see f Notice the pattern to this table: for each pocket, there's a `PACKSTATE_INIT*POCKET` state followed by a `PACKSTATE_*POCKETMENU` state. They happen to be in the same order as the `*_POCKET` constants, although that isn't actually significant; all that matters is that the default pocket be the first one (since the `PACKSTATE_INITGFX` state increments `wJumptableIndex` and advances to the next state, which should thus be the default pocket's `INIT` state). ```diff - Pack: ; 10000 + Pack: ... - .Jumptable: ; 10030 (4:4030) + .Jumptable: ; entries correspond to PACKSTATE_* constants dw .InitGFX ; 0 dw .InitItemsPocket ; 1 @@ -428,7 +428,7 @@ Notice the pattern to this table: for each pocket, there's a `PACKSTATE_INIT*POC Here's the first jumptable corresponding to those constants. It's the "core" jumptable for when you enter the Pack via the Start Menu. ```diff - .KeyItemsPocketMenu: ; 100a6 (4:40a6) + .KeyItemsPocketMenu: ... - ld b, PACKSTATE_INITBALLSPOCKET ; left + ld b, PACKSTATE_INITBERRYPOCKET ; left @@ -440,7 +440,7 @@ Here's the first jumptable corresponding to those constants. It's the "core" jum ... - .InitBallsPocket: ; 10186 (4:4186) + .InitBallsPocket: ld a, BALL_POCKET ld [wCurrPocket], a call ClearPocketList @@ -449,7 +449,7 @@ Here's the first jumptable corresponding to those constants. It's the "core" jum call Pack_JumptableNext ret - .BallsPocketMenu: ; 10198 (4:4198) + .BallsPocketMenu: ld hl, BallsPocketMenuHeader call CopyMenuHeader ld a, [wBallsPocketCursor] @@ -505,10 +505,10 @@ One, we insert the Berry pocket in-between the Ball and Key Item pockets. Origin Two, we actually write the subroutines that we just added pointers to in the jumptable. Really they're just copy+pasted from the Ball pocket's subroutines, but with "Berry" substituted for "Ball". (As we discussed earlier, the Ball pocket is safe to use as a base, since it stores regular items and isn't a default like the Items pocket.) ```diff - BattlePack: ; 10493 + BattlePack: ... - .Jumptable: ; 104c3 (4:44c3) + .Jumptable: ; entries correspond to PACKSTATE_* constants dw .InitGFX ; 0 dw .InitItemsPocket ; 1 @@ -528,7 +528,7 @@ Two, we actually write the subroutines that we just added pointers to in the jum This is another jumptable, but for using the Pack during battle. Again, we add pointers for the Berry pocket, and will next have to define them. ```diff - .KeyItemsPocketMenu: ; 10539 (4:4539) + .KeyItemsPocketMenu: ... - ld b, PACKSTATE_INITBALLSPOCKET ; left + ld b, PACKSTATE_INITBERRYPOCKET ; left @@ -540,7 +540,7 @@ This is another jumptable, but for using the Pack during battle. Again, we add p ... - .InitBallsPocket: ; 10594 (4:4594) + .InitBallsPocket: ld a, BALL_POCKET ld [wCurrPocket], a call ClearPocketList @@ -549,7 +549,7 @@ This is another jumptable, but for using the Pack during battle. Again, we add p call Pack_JumptableNext ret - .BallsPocketMenu: ; 105a6 (4:45a6) + .BallsPocketMenu: ld hl, BallsPocketMenuHeader call CopyMenuHeader ld a, [wBallsPocketCursor] @@ -601,10 +601,10 @@ This is another jumptable, but for using the Pack during battle. Again, we add p Just like before, we insert the Berry pocket between the Ball and Key Item pockets, and base the Berry pocket's subroutines on the pre-existing Ball pocket ones. ```diff - DepositSellPack: ; 106be + DepositSellPack: ... - .Jumptable: ; 106d1 (4:46d1) + .Jumptable: ; entries correspond to *_POCKET constants dw .ItemsPocket dw .BallsPocket @@ -614,7 +614,7 @@ Just like before, we insert the Berry pocket between the Ball and Key Item pocke ... - .BallsPocket: ; 1073b (4:473b) + .BallsPocket: ld a, BALL_POCKET call InitPocket ld hl, PC_Mart_BallsPocketMenuHeader @@ -686,10 +686,10 @@ Here's a jumptable for when the Pack is opened to deposit or sell an item; it ha This is somewhat tricky to notice. Here the code is decrementing or incrementing `wJumptableIndex` (that is, subtracting or adding 1) when you press Left or Right. But doing that can go beyond the valid range, since it might decrement the minimum or increment the maximum. When there were only four pockets, they neatly took up two bits, so a bitmask could be used to efficiently clamp them within the valid range. But five pockets requires more explicit checks so that the minimum and maximum values (0 and `NUM_POCKETS` − 1) wrap around. ```diff - TutorialPack: ; 107bb + TutorialPack: ... - .dw ; 107e1 (4:47e1) + .dw ; entries correspond to *_POCKET constants dw .Items dw .Balls @@ -699,20 +699,18 @@ This is somewhat tricky to notice. Here the code is decrementing or incrementing ... - .Balls: ; 1083b (4:483b) + .Balls: ld a, BALL_POCKET ld hl, .BallsMenuHeader jr .DisplayPocket - ; 10842 (4:4842) - .BallsMenuHeader: ; 0x10842 + .BallsMenuHeader: db MENU_BACKUP_TILES ; flags menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1 dw .BallsMenuData db 1 ; default option - ; 0x1084a - .BallsMenuData: ; 0x1084a + .BallsMenuData: db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags db 5, 8 ; rows, columns db 2 ; horizontal spacing @@ -720,7 +718,6 @@ This is somewhat tricky to notice. Here the code is decrementing or incrementing dba PlaceMenuItemName dba PlaceMenuItemQuantity dba UpdateItemDescription - ; 1085a + +.Berries: + ld a, BERRY_POCKET @@ -732,7 +729,6 @@ This is somewhat tricky to notice. Here the code is decrementing or incrementing + menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1 + dw .BerriesMenuData + db 1 ; default option -+; 0x107f7 + +.BerriesMenuData: + db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags @@ -747,19 +743,18 @@ This is somewhat tricky to notice. Here the code is decrementing or incrementing Another jumptable, this time used by the catch tutorial dude. Once again, we just add an entry to the jumptable for the Berry pocket and base its code and data on whatever the Ball pocket does. ```diff - PackGFXPointers: ; 108cc + PackGFXPointers: dw PackGFX + (15 tiles) * 1 ; ITEM_POCKET dw PackGFX + (15 tiles) * 3 ; BALL_POCKET dw PackGFX + (15 tiles) * 0 ; KEY_ITEM_POCKET dw PackGFX + (15 tiles) * 2 ; TM_HM_POCKET + dw PackGFX + (15 tiles) * 4 ; BERRY_POCKET - ; 108d4 ``` This is a table of pointers to the individual highlighted pocket pictures in pack.png and pack_f.png. Remember how they were out of order compared to the constants? That's why this table is necessary. For example, the first (#0) picture was of the Key Item pocket, and `KEY_ITEM_POCKET` is 2, so the third (#2) entry here points to the first picture. Anyway, all we have to do is add a pointer for the Berry pocket again. ```diff - .tilemap ; 109e1 + .tilemap ; ITEM_POCKET db $00, $04, $04, $04, $01 ; top border db $06, $07, $08, $09, $0a ; Items @@ -780,20 +775,18 @@ This is a table of pointers to the individual highlighted pocket pictures in pac + db $00, $04, $04, $04, $01 ; top border + db $1a, $1b, $1c, $1d, $1e ; Berries + db $02, $05, $05, $05, $03 ; bottom border - ; 10a1d ``` These are tilemaps for the pocket name labels in pack_menu.png. Each one is three rows of five tiles each, with tile indexes starting at 0. Take a look at pack_menu.png and notice how the hexadecimal indexes here correspond to tiles that form sensible pictures. ```diff - BallsPocketMenuHeader: ; 0x10aaf + BallsPocketMenuHeader: db MENU_BACKUP_TILES ; flags menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1 dw .MenuData db 1 ; default option - ; 0x10ab7 - .MenuData: ; 0x10ab7 + .MenuData: db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags db 5, 8 ; rows, columns db 2 ; horizontal spacing @@ -801,16 +794,14 @@ These are tilemaps for the pocket name labels in pack_menu.png. Each one is thre dba PlaceMenuItemName dba PlaceMenuItemQuantity dba UpdateItemDescription - ; 10ac7 - PC_Mart_BallsPocketMenuHeader: ; 0x10ac7 + PC_Mart_BallsPocketMenuHeader: db MENU_BACKUP_TILES ; flags menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1 dw .MenuData db 1 ; default option - ; 0x10acf - .MenuData: ; 0x10acf + .MenuData: db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP ; flags db 5, 8 ; rows, columns db 2 ; horizontal spacing @@ -818,7 +809,6 @@ These are tilemaps for the pocket name labels in pack_menu.png. Each one is thre dba PlaceMenuItemName dba PlaceMenuItemQuantity dba UpdateItemDescription - ; 10adf + +BerryPocketMenuHeader: + db MENU_BACKUP_TILES ; flags @@ -859,7 +849,7 @@ We saw `BallsPocketMenuHeader` used in the subroutines for the Start Menu Pack a Edit [engine/items/pack_kris.asm](../blob/master/engine/items/pack_kris.asm): ```diff - PackFGFXPointers: ; 48e93 + PackFGFXPointers: dw PackFGFX + (15 tiles) * 1 ; ITEM_POCKET dw PackFGFX + (15 tiles) * 3 ; BALL_POCKET dw PackFGFX + (15 tiles) * 0 ; KEY_ITEM_POCKET @@ -883,10 +873,10 @@ Line 1243 of [engine/items/pack.asm](../blob/master/engine/items/pack.asm) is `j So, `jr` and `jp` both jump to the given label. But `jp` encodes the full two-byte address of the label, while `jr` saves a byte by encoding a one-byte distance to jump. That means it can only reach −128 to 127 bytes away from its own location. Some of the code we added must have made `.DisplayPocket` more than 128 bytes away from this `jr` instruction. Anyway, the solution is simple: change it to `jp`. ```diff - TutorialPack: ; 107bb + TutorialPack: ... - .Items: ; 107e9 (4:47e9) + .Items: xor a ; ITEM_POCKET ld hl, .ItemsMenuHeader - jr .DisplayPocket |