From 87b20762d539888b031aba92b574108f5f817815 Mon Sep 17 00:00:00 2001 From: pikalaxalt Date: Tue, 24 May 2016 18:54:06 -0400 Subject: Numerous changes (see below) * Fix build errors from previous commit * Fix predef text pointers * Disassemble hidden object data and additional accessory functions --- engine/hidden_object_functions17.asm | 109 ++++++++++++++++------------------- 1 file changed, 49 insertions(+), 60 deletions(-) (limited to 'engine/hidden_object_functions17.asm') diff --git a/engine/hidden_object_functions17.asm b/engine/hidden_object_functions17.asm index 90b26578..41f20218 100755 --- a/engine/hidden_object_functions17.asm +++ b/engine/hidden_object_functions17.asm @@ -1,4 +1,4 @@ -PrintRedsNESText: ; 5db79 (17:5b79) +PrintRedsNESText: ; 5dbae (17:5bae) call EnableAutoTextBoxDrawing tx_pre_jump RedBedroomSNESText @@ -22,7 +22,10 @@ Route15GateLeftBinoculars: ; 5db8f (17:5b8f) ld a, ARTICUNO ld [wcf91], a call PlayCry - jp DisplayMonFrontSpriteInBox + call DisplayMonFrontSpriteInBox + xor a + ld [H_AUTOBGTRANSFERENABLED], a + ret Route15UpstairsBinocularsText: ; 5dba8 (17:5ba8) TX_FAR _Route15UpstairsBinocularsText @@ -52,6 +55,30 @@ KabutopsFossilText: ; 5dbd4 (17:5bd4) TX_FAR _KabutopsFossilText db "@" +FanClubPicture1: ; 5dbad (17:5c12) + ld a, RAPIDASH + ld [wcf91], a + call DisplayMonFrontSpriteInBox + call EnableAutoTextBoxDrawing + tx_pre FanClubPicture1Text + ret + +FanClubPicture1Text: ; 5dbbe (17:5bbe) + TX_FAR _FanClubPicture1Text + db "@" + +FanClubPicture2: ; 5dbad (17:5c28) + ld a, FEAROW + ld [wcf91], a + call DisplayMonFrontSpriteInBox + call EnableAutoTextBoxDrawing + tx_pre FanClubPicture2Text + ret + +FanClubPicture2Text: ; 5dc39 (17:5c39) + TX_FAR _FanClubPicture2Text + db "@" + DisplayMonFrontSpriteInBox: ; 5dbd9 (17:5bd9) ; Displays a pokemon's front sprite in a pop-up window. ; [wcf91] = pokemon interal id number @@ -110,8 +137,7 @@ LinkCableHelp: ; 5dc29 (17:5c29) ld hl, wd730 set 6, [hl] coord hl, 0, 0 - ld b, $8 - ld c, $d + lb bc, $8, $d call TextBoxBorder coord hl, 2, 2 ld de, HowToLinkText @@ -339,53 +365,17 @@ GymTrashScript: ; 5ddfc (17:5dfc) .openFirstLock ; Next can is trying for the second switch. SetEvent EVENT_1ST_LOCK_OPENED - - ld hl, GymTrashCans - ld a, [wGymTrashCanIndex] - ; * 5 - ld b, a - add a - add a - add b - - ld d, 0 - ld e, a - add hl, de - ld a, [hli] - -; There is a bug in this code. It should calculate a value in the range [0, 3] -; but if the mask and random number don't have any 1 bits in common, then -; the result of the AND will be 0. When 1 is subtracted from that, the value -; will become $ff. This will result in 255 being added to hl, which will cause -; hl to point to one of the zero bytes that pad the end of the ROM bank. -; Trash can 0 was intended to be able to have the second lock only when the -; first lock was in trash can 1 or 3. However, due to this bug, trash can 0 can -; have the second lock regardless of which trash can had the first lock. - - ld [hGymTrashCanRandNumMask], a - push hl - call Random - swap a - ld b, a - ld a, [hGymTrashCanRandNumMask] - and b - dec a - pop hl - - ld d, 0 - ld e, a - add hl, de - ld a, [hl] - and $f - ld [wSecondLockTrashCanIndex], a - + callab Func_f2d0c tx_pre_id VermilionGymTrashSuccesText1 jr .done .trySecondLock - ld a, [wSecondLockTrashCanIndex] - ld b, a ld a, [wGymTrashCanIndex] + ld b, a + ld a, [wSecondLockTrashCanIndex] + cp b + jr z, .openSecondLock + ld a, [wSecondLockTrashCanIndex + 1] cp b jr z, .openSecondLock @@ -413,25 +403,24 @@ GymTrashScript: ; 5ddfc (17:5dfc) GymTrashCans: ; 5de7d (17:5e7d) ; byte 0: mask for random number ; bytes 1-4: indices of the trash cans that can have the second lock -; (but see the comment above explaining a bug regarding this) ; Note that the mask is simply the number of valid trash can indices that -; follow. The remaining bytes are filled with 0 to pad the length of each entry +; follow. The remaining bytes are filled with -1 to pad the length of each entry ; to 5 bytes. - db 2, 1, 3, 0, 0 ; 0 - db 3, 0, 2, 4, 0 ; 1 - db 2, 1, 5, 0, 0 ; 2 - db 3, 0, 4, 6, 0 ; 3 + db 2, 1, 3, -1, -1 ; 0 + db 3, 0, 2, 4, -1 ; 1 + db 2, 1, 5, -1, -1 ; 2 + db 3, 0, 4, 6, -1 ; 3 db 4, 1, 3, 5, 7 ; 4 - db 3, 2, 4, 8, 0 ; 5 - db 3, 3, 7, 9, 0 ; 6 + db 3, 2, 4, 8, -1 ; 5 + db 3, 3, 7, 9, -1 ; 6 db 4, 4, 6, 8, 10 ; 7 - db 3, 5, 7, 11, 0 ; 8 - db 3, 6, 10, 12, 0 ; 9 + db 3, 5, 7, 11, -1 ; 8 + db 3, 6, 10, 12, -1 ; 9 db 4, 7, 9, 11, 13 ; 10 - db 3, 8, 10, 14, 0 ; 11 - db 2, 9, 13, 0, 0 ; 12 - db 3, 10, 12, 14, 0 ; 13 - db 2, 11, 13, 0, 0 ; 14 + db 3, 8, 10, 14, -1 ; 11 + db 2, 9, 13, -1, -1 ; 12 + db 3, 10, 12, 14, -1 ; 13 + db 2, 11, 13, -1, -1 ; 14 ; 5dec8 VermilionGymTrashSuccesText1: ; 5dec8 (17:5ec8) -- cgit v1.3.1-sl0p From 1e0e17ec528f81ed698df39c9aaeddb58405ede7 Mon Sep 17 00:00:00 2001 From: pikalaxalt Date: Tue, 24 May 2016 20:25:21 -0400 Subject: Comment on bug in bank 3c trash can sampling function --- engine/bank3c.asm | 53 ++++++++++++++++++++++++++---------- engine/hidden_object_functions17.asm | 2 ++ 2 files changed, 40 insertions(+), 15 deletions(-) (limited to 'engine/hidden_object_functions17.asm') diff --git a/engine/bank3c.asm b/engine/bank3c.asm index 2dedb64c..4e5fca0a 100644 --- a/engine/bank3c.asm +++ b/engine/bank3c.asm @@ -351,18 +351,41 @@ Func_f2d0c: ret GymTrashCans3a: ; f2d31 (3c:6d31) - db $04, $01, $03, $03, $01, $01, $ff, $03, $ff - db $03, $00, $02, $02, $04, $04, $00, $ff, $ff - db $04, $01, $05, $05, $01, $01, $ff, $05, $ff - db $03, $00, $04, $04, $06, $06, $00, $ff, $ff - db $04, $01, $03, $03, $01, $05, $05, $07, $07 - db $03, $02, $04, $04, $08, $08, $02, $ff, $ff - db $03, $03, $07, $07, $09, $09, $03, $ff, $ff - db $04, $04, $08, $06, $0a, $08, $04, $0a, $06 - db $03, $05, $07, $07, $0b, $0b, $05, $ff, $ff - db $03, $06, $0a, $0a, $0c, $0c, $06, $ff, $ff - db $04, $07, $09, $09, $07, $0b, $0d, $0d, $0b - db $03, $08, $0a, $0a, $0e, $0e, $08, $ff, $ff - db $04, $09, $0d, $0d, $09, $09, $ff, $0d, $ff - db $03, $0a, $0c, $0c, $0e, $0e, $0a, $ff, $ff - db $04, $0b, $0d, $0d, $0b, $0b, $ff, $0d, $ff +; First byte: number of trashcan entries +; Following four byte pairs: indices for the second trash can. +; BUG: Rows that have 3 trashcan entries are sampled incorrectly. +; The sampling occurs by taking a random number and seeing which +; third of the range 0-255 the number falls in. However, it returns +; that value to the wrong register, so the result is never used. +; Instead of using an offset in [0,1,2], the offset is instead +; in the full range 0-255. This results in truly random behavior. + db 4 + db 1,3, 3,1, 1,-1, 3,-1 + db 3 + db 0,2, 2,4, 4,0, -1,-1 + db 4 + db 1,5, 5,1, 1,-1, 5,-1 + db 3 + db 0,4, 4,6, 6,0, -1,-1 + db 4 + db 1,3, 3,1, 5,5, 7,7 + db 3 + db 2,4, 4,8, 8,2, -1,-1 + db 3 + db 3,7, 7,9, 9,3, -1,-1 + db 4 + db 4,8, 6,10, 8,4, 10,6 + db 3 + db 5,7, 7,11, 11,5, -1,-1 + db 3 + db 6,10, 10,12, 12,6, -1,-1 + db 4 + db 7,9, 9,7, 11,13, 13,11 + db 3 + db 8,10, 10,14, 14,8, -1,-1 + db 4 + db 9,13, 13,9, 9,-1, 13,-1 + db 3 + db 10,12, 12,14, 14,10, -1,-1 + db 4 + db 11,13, 13,11, 11,-1, 13,-1 diff --git a/engine/hidden_object_functions17.asm b/engine/hidden_object_functions17.asm index 41f20218..8e5920d5 100755 --- a/engine/hidden_object_functions17.asm +++ b/engine/hidden_object_functions17.asm @@ -406,6 +406,8 @@ GymTrashCans: ; 5de7d (17:5e7d) ; Note that the mask is simply the number of valid trash can indices that ; follow. The remaining bytes are filled with -1 to pad the length of each entry ; to 5 bytes. +; This is functionally replaced with GymTrashCans3a but was never removed from source. + db 2, 1, 3, -1, -1 ; 0 db 3, 0, 2, 4, -1 ; 1 db 2, 1, 5, -1, -1 ; 2 -- cgit v1.3.1-sl0p