From 6597eb7e505a973a49e0fbd602f66f74395e2200 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 28 Jun 2013 21:51:18 -0400 Subject: [PATCH 01/13] Overworld input handling --- main.asm | 595 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 591 insertions(+), 4 deletions(-) diff --git a/main.asm b/main.asm index 3e6157768..bd6f697a5 100644 --- a/main.asm +++ b/main.asm @@ -2155,7 +2155,16 @@ GetTileType: ; 185d ret ; 1875 -INCBIN "baserom.gbc", $1875, $18ac - $1875 +INCBIN "baserom.gbc", $1875, $18a0 - $1875 + +CheckCounterTile: ; 18a0 + cp $90 + ret z + cp $98 + ret +; 18a6 + +INCBIN "baserom.gbc", $18a6, $18ac - $18a6 CheckIceTile: ; 18ac cp $23 @@ -2803,7 +2812,123 @@ ObjectEventText: db "@" ; 0x26f7 -INCBIN "baserom.gbc", $26f7, $2b74-$26f7 + +INCBIN "baserom.gbc", $26f7, $2a07 - $26f7 + + +GetFacingTileCoord: ; 2a07 +; Return map coordinates in (d, e) and tile id in a +; of the tile the player is facing. + + ld a, [PlayerDirection] + and %1100 + srl a + srl a + ld l, a + ld h, 0 + add hl, hl + add hl, hl + ld de, .Directions + add hl, de + + ld d, [hl] + inc hl + ld e, [hl] + inc hl + + ld a, [hli] + ld h, [hl] + ld l, a + + ld a, [MapX] + add d + ld d, a + ld a, [MapY] + add e + ld e, a + ld a, [hl] + ret + +.Directions + ; x, y + db 0, 1 + dw TileDown + db 0, -1 + dw TileUp + db -1, 0 + dw TileLeft + db 1, 0 + dw TileRight +; 2a3c + + +INCBIN "baserom.gbc", $2a3c, $2a8b - $2a3c + + +CheckFacingSign: ; 2a8b + call GetFacingTileCoord + ld b, a + ld a, d + sub 4 + ld d, a + ld a, e + sub 4 + ld e, a + ld a, [$dc01] + and a + ret z + ld c, a + ld a, [hROMBank] + push af + call $2c52 + call $2aaa + pop hl + ld a, h + rst Bankswitch + ret +; 2aaa + +; 2aaa + ld hl, $dc02 + ld a, [hli] + ld h, [hl] + ld l, a +.asm_2ab0 + push hl + ld a, [hli] + cp e + jr nz, .asm_2abb + ld a, [hli] + cp d + jr nz, .asm_2abb + jr .asm_2ac8 + +.asm_2abb + pop hl + ld a, 5 + add l + ld l, a + jr nc, .asm_2ac3 + inc h + +.asm_2ac3 + dec c + jr nz, .asm_2ab0 + xor a + ret + +.asm_2ac8 + pop hl + ld de, EngineBuffer1 + ld bc, 5 + call CopyBytes + scf + ret +; 0x2ad4 + + +INCBIN "baserom.gbc", $2ad4, $2b74 - $2ad4 + Function2b74: ; 0x2b74 push af @@ -5653,7 +5778,52 @@ DrawGraphic: ; 6eef ; 6f07 -INCBIN "baserom.gbc", $6f07, $7305 - $6f07 +INCBIN "baserom.gbc", $6f07, $6fd9 - $6f07 + + +CheckFacingObject: ; 6fd9 + + call GetFacingTileCoord + +; Double the distance for counter tiles. + call CheckCounterTile + jr nz, .asm_6ff1 + + ld a, [MapX] + sub d + cpl + inc a + add d + ld d, a + + ld a, [MapY] + sub e + cpl + inc a + add e + ld e, a + +.asm_6ff1 + ld bc, $d4d6 + ld a, 0 + ld [hConnectionStripLength], a + call $7041 + ret nc + ld hl, $0007 + add hl, bc + ld a, [hl] + cp $ff + jr z, .asm_7007 + xor a + ret + +.asm_7007 + scf + ret +; 7009 + + +INCBIN "baserom.gbc", $7009, $7305 - $7009 SpecialGiveShuckle: ; 7305 @@ -15810,7 +15980,424 @@ INCLUDE "maps/map_headers.asm" INCLUDE "maps/second_map_headers.asm" -INCBIN "baserom.gbc", $966b0, $96cb1 - $966b0 + +INCBIN "baserom.gbc", $966b0, $96974 - $966b0 + + + +; 96974 + call CheckPlayerMovement + ret c + and a + jr nz, .asm_9698d + +; Can't perform button actions while sliding on ice. + callba Function80404 + jr c, .asm_9698d + + call CheckAPressOW + jr c, .asm_9698f + + call CheckMenuOW + jr c, .asm_9698f + +.asm_9698d + xor a + ret + +.asm_9698f + push af + callba Function80422 + pop af + scf + ret +; 96999 + + +CheckAPressOW: ; 96999 + ld a, [hJoyPressed] + and BUTTON_A + ret z + call TryObjectEvent + ret c + call TryReadSign + ret c + call $7c5f + ret c + xor a + ret +; 969ac + + +PlayTalkObject: ; 969ac + push de + ld de, SFX_READ_TEXT_2 + call StartSFX + pop de + ret +; 969b5 + + +TryObjectEvent: ; 969b5 + callba CheckFacingObject + jr c, .IsObject + xor a + ret + +.IsObject + call PlayTalkObject + ld a, [hConnectedMapWidth] + call $1ae5 + ld hl, $0001 + add hl, bc + ld a, [hl] + ld [$ffe0], a + + ld a, [$ffe0] + call $18d2 + ld hl, $0008 + add hl, bc + ld a, [hl] + and $f + +; Bug: If IsInArray returns nc, data at bc will be executed as code. + push bc + ld de, 3 + ld hl, .data_969ee + call IsInArray + jr nc, .asm_969ec + pop bc + + inc hl + ld a, [hli] + ld h, [hl] + ld l, a + jp [hl] + +.asm_969ec + xor a + ret + +.data_969ee + dbw 0, .zero + dbw 1, .one + dbw 2, .two + dbw 3, .three + dbw 4, .four + dbw 5, .five + dbw 6, .six + db $ff +; 96a04 + +.zero ; 96a04 + ld hl, $000a + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + call $2c57 + call PushScriptPointer +; ld a, -1 + ret +; 96a12 + +.one ; 96a12 + ld hl, $000a + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + call $2c57 + ld de, EngineBuffer1 + ld bc, 2 + call FarCopyBytes + ld a, $3 + scf + ret +; 96a29 + +.two ; 96a29 + call $3674 + ld a, $2 + scf + ret +; 96a30 + +.three ; 96a30 + xor a + ret +; 96a32 + +.four ; 96a32 + xor a + ret +; 96a34 + +.five ; 96a34 + xor a + ret +; 96a36 + +.six ; 96a36 + xor a + ret +; 96a38 + + +TryReadSign: ; 96a38 + call CheckFacingSign + jr c, .IsSign + xor a + ret + +.IsSign + ld a, [$d040] + ld hl, .signs + rst $28 + ret + +.signs + dw .read + dw .up + dw .down + dw .right + dw .left + dw .ifset + dw .ifnotset + dw .itemifset + dw .asm_96aa2 +; 96a59 + +.up + ld b, UP << 2 + jr .checkdir +.down + ld b, DOWN << 2 + jr .checkdir +.right + ld b, RIGHT << 2 + jr .checkdir +.left + ld b, LEFT << 2 + jr .checkdir + +.checkdir + ld a, [PlayerDirection] + and %1100 + cp b + jp nz, $6ad6 + +.read + call PlayTalkObject + ld hl, $d041 + ld a, [hli] + ld h, [hl] + ld l, a + call $2c57 + call PushScriptPointer + scf + ret + +.itemifset + call CheckSignFlag + jp nz, $6ad6 + call PlayTalkObject + call $2c57 + ld de, EngineBuffer1 + ld bc, 3 + call FarCopyBytes + ld a, $4 + ld hl, $7625 + call PushScriptPointer + scf + ret + +.asm_96aa2 + call CheckSignFlag + jr nz, .dontread + call $2c57 + ld de, EngineBuffer1 + ld bc, 3 + call FarCopyBytes + jr .dontread + +.ifset + call CheckSignFlag + jr z, .dontread + jr .asm_96ac1 + +.ifnotset + call CheckSignFlag + jr nz, .dontread + +.asm_96ac1 + push hl + call PlayTalkObject + pop hl + inc hl + inc hl + call $2c57 + call GetFarHalfword + call $2c57 + call PushScriptPointer + scf + ret + +.dontread + xor a + ret +; 96ad8 + + +CheckSignFlag: ; 96ad8 + ld hl, $d041 + ld a, [hli] + ld h, [hl] + ld l, a + push hl + call $2c57 + call GetFarHalfword + ld e, l + ld d, h + ld b, $2 + call BitTable1Func + ld a, c + and a + pop hl + ret +; 96af0 + + +CheckPlayerMovement: ; 96af0 + ld a, BANK(DoPlayerMovement) + ld hl, DoPlayerMovement + rst FarCall + ld a, c + ld hl, .pointers + rst $28 + ld a, c + ret +; 96afd + +.pointers + dw .zero + dw .one + dw .two + dw .three + dw .four + dw .five + dw .six + dw .seven + +.zero +.four ; 96b0d + xor a + ld c, a + ret +; 96b10 + +.seven ; 96b10 + call $68d7 ; empty + xor a + ld c, a + ret +; 96b16 + +.one ; 96b16 + ld a, 5 + ld c, a + scf + ret +; 96b1b + +.two ; 96b1b + ld a, 9 + ld c, a + scf + ret +; 96b20 + +.three ; 96b20 +; force the player to move in some direction + ld a, $4 + ld hl, $653d + call PushScriptPointer +; ld a, -1 + ld c, a + scf + ret +; 96b2b + +.five +.six ; 96b2b + ld a, -1 + ld c, a + and a + ret +; 96b30 + + +CheckMenuOW: ; 96b30 + xor a + ld [$ffa0], a + ld [$ffa1], a + ld a, [hJoyPressed] + + bit 2, a ; SELECT + jr nz, .Select + + bit 3, a ; START + jr z, .NoMenu + + ld a, BANK(StartMenuScript) + ld hl, StartMenuScript + call PushScriptPointer + scf + ret + +.NoMenu + xor a + ret + +.Select + call PlayTalkObject + ld a, BANK(SelectMenuScript) + ld hl, SelectMenuScript + call PushScriptPointer + scf + ret +; 96b58 + + +StartMenuScript: ; 96b58 + 3callasm $04, $65cd ; StartMenu + 2jump UnknownScript_0x96b66 +; 96b5f + +SelectMenuScript: ; 96b5f + 3callasm $04, $7327 ; SelectMenu + 2jump UnknownScript_0x96b66 +; 96b66 + +UnknownScript_0x96b66: ; 96b66 + copybytetovar $ffa0 + if_equal $80, UnknownScript_0x96b72 + if_equal $ff, UnknownScript_0x96b75 + end +; 96b72 + +UnknownScript_0x96b72: ; 96b72 + 2ptjump $d0e8 +; 96b75 + +UnknownScript_0x96b75: ; 96b75 + 2ptcallasm $d0e8 + end +; 96b79 + + +INCBIN "baserom.gbc", $96b79, $96cb1 - $96b79 + INCLUDE "engine/scripting.asm" From d3872d1aa94a2ae6294f7cce3584f4d0aaa16fcb Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 1 Jul 2013 02:48:08 -0400 Subject: [PATCH 02/13] =?UTF-8?q?chars:=20=E2=96=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extras/chars.py | 1 + preprocessor.py | 1 + 2 files changed, 2 insertions(+) diff --git a/extras/chars.py b/extras/chars.py index 1bc25dbe7..3810d83cb 100644 --- a/extras/chars.py +++ b/extras/chars.py @@ -98,6 +98,7 @@ chars = { 0xE9: "&", 0xEA: "é", 0xEB: "→", + 0xEC: "▷", 0xED: "▶", 0xEE: "▼", 0xEF: "♂", diff --git a/preprocessor.py b/preprocessor.py index 242732094..30060e7d7 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -286,6 +286,7 @@ chars = { "&": 0xE9, "é": 0xEA, "→": 0xEB, +"▷": 0xEC, "▶": 0xED, "▼": 0xEE, "♂": 0xEF, From fbf9ae78778adb5ee6ca3291bce495a5041f8064 Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 1 Jul 2013 22:55:13 -0400 Subject: [PATCH 03/13] clean up StartMenu --- main.asm | 1000 ++++++++++++++++++++++++++++++++++++++++++------------ wram.asm | 22 +- 2 files changed, 805 insertions(+), 217 deletions(-) diff --git a/main.asm b/main.asm index bd6f697a5..0b58a7820 100644 --- a/main.asm +++ b/main.asm @@ -7210,54 +7210,62 @@ HalveMoney: ; 12513 INCBIN "baserom.gbc", $12527, $125cd - $12527 -OpenMenu: ; 0x125cd +StartMenu: ; 125cd + call $1fbf + ld de, SFX_MENU call StartSFX + ld a, $1 ld hl, $6454 rst FarCall - ld hl, $d84d - bit 2, [hl] - ld hl, $66d3 - jr z, .asm_125e9 - ld hl, $66db ; draw the menu a little lower -.asm_125e9 + + ld hl, StatusFlags2 + bit 2, [hl] ; bug catching contest + ld hl, .MenuDataHeader + jr z, .GotMenuData + ld hl, .ContestMenuDataHeader +.GotMenuData + call Function1d35 - call SetUpMenuItems + call .SetUpMenuItems ld a, [$d0d2] ld [$cf88], a - call DrawMenuAccount_ - call $1e7f - call $68d1 + call .DrawMenuAccount_ + call MenuFunc_1e7f + call .DrawBugContestStatusBox call $2e31 call $2e20 ld a, $1 ld hl, $64bf rst $8 - call $68de + call .DrawBugContestStatus call $0485 - jr .wait -.reopen + jr .Select + +.Reopen call $1ad2 call $0485 - call $6829 + call .SetUpMenuItems ld a, [$d0d2] ld [$cf88], a -.wait - call MenuWait - jr c, .exit - call DrawMenuAccount + +.Select + call .GetInput + jr c, .Exit + call .DrawMenuAccount ld a, [$cf88] ld [$d0d2], a call PlayClickSFX call $1bee - call $67e5 -; code when you return from a submenu. some submenus force you to quit -; the menu, like save. option forces it to redraw completely. - ld hl, .MenuReturnPointerTable + call .OpenMenu + +; Menu items have different return functions. +; For example, saving exits the menu. + ld hl, .MenuReturns ld e, a - ld d, $0 + ld d, 0 add hl, de add hl, de ld a, [hli] @@ -7265,122 +7273,182 @@ OpenMenu: ; 0x125cd ld l, a jp [hl] -.MenuReturnPointerTable: ; $6644 - dw .reopen - dw .exit - dw $66a2 ; invalid? - dw $6699 ; invalid? - dw $6691 ; invalid? - dw .end - dw $66b1 ; redraw +.MenuReturns + dw .Reopen + dw .Exit + dw .ReturnTwo + dw .ReturnThree + dw .ReturnFour + dw .ReturnEnd + dw .ReturnRedraw -.exit - ld a, [$ffd8] +.Exit + ld a, [hOAMUpdate] push af - ld a, $1 + ld a, 1 ld [hOAMUpdate], a call $0e5f pop af ld [hOAMUpdate], a -.end +.ReturnEnd call Function1c07 +.ReturnEnd2 call $2dcf call $0485 ret -MenuWait: ; 0x12669 -; returns nc if A was pressed, c if B. +.GetInput +; Return carry on exit, and no-carry on selection. xor a ld [hBGMapMode], a - call DrawMenuAccount + call .DrawMenuAccount call SetUpMenu ld a, $ff ld [MenuSelection], a .loop - call PrintMenuAccount + call .PrintMenuAccount call $1f1a ld a, [$cf73] cp BUTTON_B - jr z, .b_button + jr z, .b cp BUTTON_A - jr z, .a_button + jr z, .a jr .loop -.a_button +.a call PlayClickSFX and a ret -.b_button +.b scf ret -; 0x12691 +; 12691 + +.ReturnFour ; 12691 + call Function1c07 + ld a, $80 + ld [$ffa0], a + ret +; 12699 + +.ReturnThree ; 12699 + call Function1c07 + ld a, $80 + ld [$ffa0], a + jr .ReturnEnd2 +; 126a2 + +.ReturnTwo ; 126a2 + call Function1c07 + ld hl, $d0e9 + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [$d0e8] + rst FarCall + jr .ReturnEnd2 +; 126b1 + +.ReturnRedraw ; 126b1 + call .Clear + jp .Reopen +; 126b7 + +.Clear ; 126b7 + call WhiteBGMap + call $1d7d + call $2bae + call .DrawMenuAccount_ + call MenuFunc_1e7f + call .DrawBugContestStatus + call $1ad2 + call $0d90 + call $2b5c + ret +; 126d3 -INCBIN "baserom.gbc", $12691, $12721 - $12691 +.MenuDataHeader + db $40 ; tile backup + db 0, 10 ; start coords + db 17, 19 ; end coords + dw .MenuData + db 1 ; default selection -MenuStringDex: ; 0x12721 - db "#DEX@" +.ContestMenuDataHeader + db $40 ; tile backup + db 2, 10 ; start coords + db 17, 19 ; end coords + dw .MenuData + db 1 ; default selection -MenuStringMon: ; 0x12726 - db "#MON@" +.MenuData + db %10101000 ; x padding, wrap around, start can close + dn 0, 0 ; rows, columns + dw MenuItemsList + dw .MenuString + dw .Items -MenuStringPack: ; 0x1272b - db "PACK@" +.Items + dw StartMenu_Pokedex, .PokedexString, .PokedexDesc + dw StartMenu_Pokemon, .PartyString, .PartyDesc + dw StartMenu_Pack, .PackString, .PackDesc + dw StartMenu_Status, .StatusString, .StatusDesc + dw StartMenu_Save, .SaveString, .SaveDesc + dw StartMenu_Option, .OptionString, .OptionDesc + dw StartMenu_Exit, .ExitString, .ExitDesc + dw StartMenu_Pokegear, .PokegearString, .PokegearDesc + dw StartMenu_Quit, .QuitString, .QuitDesc -MenuStringProfile: ; 0x12730 - db $52, "@" +.PokedexString db "#DEX@" +.PartyString db "#MON@" +.PackString db "PACK@" +.StatusString db $52, "@" +.SaveString db "SAVE@" +.OptionString db "OPTION@" +.ExitString db "EXIT@" +.PokegearString db $24, "GEAR@" +.QuitString db "QUIT@" -MenuStringSave: ; 0x12732 - db "SAVE@" +.PokedexDesc db "#MON", $4e, "database@" +.PartyDesc db "Party ", $4a, $4e, "status@" +.PackDesc db "Contains", $4e, "items@" +.PokegearDesc db "Trainer's", $4e, "key device@" +.StatusDesc db "Your own", $4e, "status@" +.SaveDesc db "Save your", $4e, "progress@" +.OptionDesc db "Change", $4e, "settings@" +.ExitDesc db "Close this", $4e, "menu@" +.QuitDesc db "Quit and", $4e, "be judged.@" -MenuStringOption: ; 0x12737 - db "OPTION@" -MenuStringExit: ; 0x1273e - db "EXIT@" +.OpenMenu ; 127e5 + ld a, [MenuSelection] + call .GetMenuAccountTextPointer + ld a, [hli] + ld h, [hl] + ld l, a + jp [hl] +; 127ef -MenuStringGear: ; 0x12743 - db $24, "GEAR@" +.MenuString ; 127ef + push de + ld a, [MenuSelection] + call .GetMenuAccountTextPointer + inc hl + inc hl + ld a, [hli] + ld d, [hl] + ld e, a + pop hl + call PlaceString + ret +; 12800 -MenuStringQuit: ; 0x12749 - db "QUIT@" - -MenuStringDescDex: ; 0x1274e - db "#MON", $4e, "database@" - -MenuStringDescParty: ; 0x1275c - db "Party ", $4a, $4e, "status@" - -MenuStringDescPack: ; 0x1276b - db "Contains", $4e, "items@" - -MenuStringDescGear: ; 0x1277a - db "Trainer's", $4e, "key device@" - -MenuStringDescProfile: ; 0x1278e - db "Your own", $4e, "status@" - -MenuStringDescSave: ; 0x1279e - db "Save your", $4e, "progress@" - -MenuStringDescOption: ; 0x127b1 - db "Change", $4e, "settings@" - -MenuStringDescExit: ; 0x127c1 - db "Close this", $4e, "menu@" - -MenuStringDescRetire: ; 0x127d1 - db "Quit and", $4e, "be judged.@" - -; 0x127e5 - -INCBIN "baserom.gbc", $127e5, $12800 - $127e5 - -WriteMenuAccount: +.MenuDesc ; 12800 push de ld a, [MenuSelection] cp $ff jr z, .none - call GetMenuAccountTextPointer + call .GetMenuAccountTextPointer inc hl inc hl inc hl @@ -7394,11 +7462,13 @@ WriteMenuAccount: .none pop de ret +; 12819 -GetMenuAccountTextPointer: ; 0x12819 + +.GetMenuAccountTextPointer ; 12819 ld e, a - ld d, $0 - ld hl, $cf97 ; table is dynamic and stored in memory + ld d, 0 + ld hl, $cf97 ld a, [hli] ld h, [hl] ld l, a @@ -7409,115 +7479,275 @@ GetMenuAccountTextPointer: ; 0x12819 add hl, de add hl, de ret +; 12829 -SetUpMenuItems: ; 4:6829 = 0x12829 + +.SetUpMenuItems ; 12829 xor a ld [$cf76], a - call $688d + call .FillMenuList + ld hl, $d84c bit 0, [hl] jr z, .no_pokedex - ld a, $0 - call AppendMenuList + ld a, 0 ; pokedex + call .AppendMenuList .no_pokedex + ld a, [PartyCount] and a jr z, .no_pokemon - ld a, $1 - call AppendMenuList + ld a, 1 ; pokemon + call .AppendMenuList .no_pokemon + ld a, [InLinkBattle] and a jr nz, .no_pack - ld hl, $d84d - bit 2, [hl] + ld hl, StatusFlags2 + bit 2, [hl] ; bug catching contest jr nz, .no_pack - ld a, $2 - call AppendMenuList + ld a, 2 ; pack + call .AppendMenuList .no_pack + ld hl, $d957 bit 7, [hl] - jr z, .no_exit - ld a, $7 - call AppendMenuList -.no_exit - ld a, $3 - call AppendMenuList + jr z, .no_pokegear + ld a, 7 ; pokegear + call .AppendMenuList +.no_pokegear + + ld a, 3 ; status + call .AppendMenuList + ld a, [InLinkBattle] and a jr nz, .no_save - ld hl, $d84d - bit 2, [hl] - ld a, $8 + ld hl, StatusFlags2 + bit 2, [hl] ; bug catching contest + ld a, 8 ; quit jr nz, .write - ld a, $4 + ld a, 4 ; save .write - call AppendMenuList + call .AppendMenuList .no_save - ld a, $5 - call AppendMenuList - ld a, $6 - call AppendMenuList + + ld a, 5 ; option + call .AppendMenuList + ld a, 6 ; exit + call .AppendMenuList ld a, c ld [MenuItemsList], a ret +; 1288d -FillMenuList: ; 0x1288d + +.FillMenuList ; 1288d xor a ld hl, MenuItemsList ld [hli], a ld a, $ff ld bc, $000f call ByteFill - ld de, MenuItemsList+1 + ld de, MenuItemsList + 1 ld c, 0 ret +; 128a0 -AppendMenuList: ; 0x128a0 +.AppendMenuList ; 128a0 ld [de], a inc de inc c ret +; 128a4 -DrawMenuAccount_:; 0x128a4 - jp DrawMenuAccount +.DrawMenuAccount_ ; 128a4 + jp .DrawMenuAccount +; 128a7 -PrintMenuAccount: ; 4:68a7 0x128a7 - call IsMenuAccountOn +.PrintMenuAccount ; 128a7 + call .IsMenuAccountOn ret z - call DrawMenuAccount - decoord 0, 14 ; $c5b8 - jp $6800 + call .DrawMenuAccount + decoord 0, 14 + jp .MenuDesc +; 128b4 -DrawMenuAccount: ; 4:68b4 0x128b4 - call IsMenuAccountOn +.DrawMenuAccount ; 128b4 + call .IsMenuAccountOn ret z - hlcoord 0, 13 ; $c5a4 + hlcoord 0, 13 ld bc, $050a call ClearBox - hlcoord 0, 13 ; $c5a4 - ld b, $3 - ld c, $8 + hlcoord 0, 13 + ld b, 3 + ld c, 8 jp TextBoxPalette +; 128cb -IsMenuAccountOn: ; 0x128cb +.IsMenuAccountOn ; 128cb ld a, [Options2] - and $1 + and 1 ret -; 0x128d1 +; 128d1 -INCBIN "baserom.gbc", $128d1, $12976 - $128d1 +.DrawBugContestStatusBox ; 128d1 + ld hl, StatusFlags2 + bit 2, [hl] ; bug catching contest + ret z + ld a, $9 + ld hl, $4bdc + rst FarCall + ret +; 128de + +.DrawBugContestStatus ; 128de + ld hl, StatusFlags2 + bit 2, [hl] ; bug catching contest + jr nz, .contest + ret +.contest + ld a, $9 + ld hl, $4be7 + rst FarCall + ret +; 128ed + + +StartMenu_Exit: ; 128ed +; Exit the menu. + + ld a, 1 + ret +; 128f0 + + +StartMenu_Quit: ; 128f0 +; Retire from the bug catching contest. + + ld hl, .EndTheContestText + call $6cf5 + jr c, .asm_12903 + ld a, $4 + ld hl, $760b + call $31cf + ld a, 4 + ret +.asm_12903 + ld a, 0 + ret + +.EndTheContestText + text_jump UnknownText_0x1c1a6c, BANK(UnknownText_0x1c1a6c) + db "@" +; 1290b + + +StartMenu_Save: ; 1290b +; Save the game. + + call $2879 + ld a, $5 + ld hl, $4a1a + rst FarCall + jr nc, .asm_12919 + ld a, 0 + ret +.asm_12919 + ld a, 1 + ret +; 1291c + + +StartMenu_Option: ; 1291c +; Game options. + + call $2b29 + ld a, $1 + ld hl, $5b64 + rst FarCall + ld a, 6 + ret +; 12928 + + +StartMenu_Status: ; 12928 +; Player status. + + call $2b29 + ld a, $9 + ld hl, $5105 + rst FarCall + call $2b3c + ld a, 0 + ret +; 12937 + + +StartMenu_Pokedex: ; 12937 -OpenPartyMenu: ; $12976 ld a, [PartyCount] and a - jr z, .return ; no pokémon in party + jr z, .asm_12949 + + call $2b29 + ld a, $10 + ld hl, $4000 + rst FarCall + call $2b3c + +.asm_12949 + ld a, 0 + ret +; 1294c + + +StartMenu_Pokegear: ; 1294c + + call $2b29 + ld a, $24 + ld hl, $4b8d + rst FarCall + call $2b3c + ld a, 0 + ret +; 1295b + + +StartMenu_Pack: ; 1295b + + call $2b29 + ld a, $4 + ld hl, $4000 + rst FarCall + ld a, [$cf66] + and a + jr nz, .asm_12970 + call $2b3c + ld a, 0 + ret +.asm_12970 + call $2b4d + ld a, 4 + ret +; 12976 + + +StartMenu_Pokemon: ; 12976 + + ld a, [PartyCount] + and a + jr z, .return + call $2b29 ; fade in? -.choosemenu ; 1297f + +.choosemenu xor a ld [PartyMenuActionText], a ; Choose a POKéMON. call WhiteBGMap -.menu ; 12986 + +.menu ld a, $14 ld hl, $404f rst FarCall ; load gfx @@ -7527,108 +7757,464 @@ OpenPartyMenu: ; $12976 ld a, $14 ld hl, $43e0 rst FarCall ; load menu pokémon sprites -.menunoreload ; 12998 - ld a, BANK(WritePartyMenuTilemap) - ld hl, WritePartyMenuTilemap - rst FarCall - ld a, BANK(PrintPartyMenuText) - ld hl, PrintPartyMenuText - rst FarCall + +.menunoreload + callba WritePartyMenuTilemap + callba PrintPartyMenuText call WaitBGMap call $32f9 ; load regular palettes? call DelayFrame - ld a, BANK(PartyMenuSelect) - ld hl, PartyMenuSelect - rst FarCall + callba PartyMenuSelect jr c, .return ; if cancelled or pressed B + call PokemonActionSubmenu - cp $3 + cp 3 jr z, .menu - cp $0 + cp 0 jr z, .choosemenu - cp $1 + cp 1 jr z, .menunoreload - cp $2 + cp 2 jr z, .quit -.return ; 129c8 + +.return call $2b3c - ld a, $0 + ld a, 0 ret -.quit ; 129ce + +.quit ld a, b push af call $2b4d pop af ret -; 0x129d5 +; 129d5 -INCBIN "baserom.gbc", $129d5, $12a88 - $129d5 -PokemonActionSubmenu ; 0x12a88 - ld hl, $c5cd ; coord +INCBIN "baserom.gbc", $129d5, $12a6c - $129d5 + + +PartyMonItemName: ; 12a6c + ld a, [CurItem] + ld [$d265], a + call GetItemName + call CopyName1 + ret +; 12a79 + + +CancelPokemonAction: ; 12a79 + ld a, $14 + ld hl, $4405 + rst FarCall + ld a, $23 + ld hl, $6a71 + rst FarCall + ld a, 1 + ret +; 12a88 + + +PokemonActionSubmenu: ; 12a88 + hlcoord 1, 15 ld bc, $0212 ; box size - call $0fb6 ; draw box + call ClearBox ld a, $9 ld hl, $4d19 rst FarCall call $389c ld a, [MenuSelection] - ld hl, PokemonSubmenuActionPointerTable - ld de, $0003 ; skip 3 bytes each time + ld hl, .Actions + ld de, 3 call IsInArray jr nc, .nothing + inc hl ld a, [hli] ld h, [hl] ld l, a jp [hl] + .nothing - ld a, $0 + ld a, 0 ret -; 0x12ab0 -PokemonSubmenuActionPointerTable: ; 0x12ab0 - dbw $01, $6e1b - dbw $02, $6e30 - dbw $03, $6ebd - dbw $04, $6e6a - dbw $06, $6e55 - dbw $07, $6e7f - dbw $08, $6ed1 - dbw $09, $6ea9 - dbw $0a, $6ee6 - dbw $0d, $6ee6 - dbw $0b, $6f26 - dbw $05, $6e94 - dbw $0c, $6f3b - dbw $0e, $6f50 - dbw $0f, OpenPartyStats ; stats - dbw $10, $6aec ; switch - dbw $11, $6b60 ; item - dbw $12, $6a79 - dbw $13, $6fba ; move - dbw $14, $6d45 ; mail -; no terminator? -; 0x12aec +.Actions + dbw $01, $6e1b + dbw $02, $6e30 + dbw $03, $6ebd + dbw $04, $6e6a + dbw $06, $6e55 + dbw $07, $6e7f + dbw $08, $6ed1 + dbw $09, $6ea9 + dbw $0a, $6ee6 + dbw $0d, $6ee6 + dbw $0b, $6f26 + dbw $05, $6e94 + dbw $0c, $6f3b + dbw $0e, $6f50 + dbw $0f, OpenPartyStats + dbw $10, SwitchPartyMons + dbw $11, GiveTakePartyMonItem + dbw $12, CancelPokemonAction + dbw $13, $6fba ; move + dbw $14, $6d45 ; mail +; 12aec + + +SwitchPartyMons: ; 12aec + +; Don't try if there's nothing to switch! + ld a, [PartyCount] + cp 2 + jr c, .DontSwitch + + ld a, [CurPartyMon] + inc a + ld [$d0e3], a + + ld a, $23 + ld hl, $6a8c + rst FarCall + ld a, $14 + ld hl, $442d + rst FarCall + + ld a, 4 + ld [PartyMenuActionText], a + callba WritePartyMenuTilemap + callba PrintPartyMenuText + + hlcoord 0, 1 + ld bc, 20 * 2 + ld a, [$d0e3] + dec a + call AddNTimes + ld [hl], "▷" + call WaitBGMap + call $32f9 + call DelayFrame + + callba PartyMenuSelect + bit 1, b + jr c, .DontSwitch + + ld a, $14 + ld hl, $4f12 + rst FarCall + + xor a + ld [PartyMenuActionText], a + + ld a, $14 + ld hl, $404f + rst FarCall + ld a, $14 + ld hl, $4405 + rst FarCall + ld a, $14 + ld hl, $43e0 + rst FarCall + + ld a, 1 + ret + +.DontSwitch + xor a + ld [PartyMenuActionText], a + call CancelPokemonAction + ret +; 12b60 + + +GiveTakePartyMonItem: ; 12b60 + +; Eggs can't hold items! + ld a, [CurPartySpecies] + cp EGG + jr z, .asm_12ba6 + + ld hl, GiveTakeItemMenuData + call Function1d35 + call Function1d81 + call Function1c07 + jr c, .asm_12ba6 + + call $389c + ld hl, StringBuffer1 + ld de, $d050 + ld bc, $b + call CopyBytes + ld a, [$cfa9] + cp 1 + jr nz, .asm_12ba0 + + call $1d6e + call ClearPalettes + call Function12ba9 + call ClearPalettes + call $0e58 + call Function1c07 + ld a, 0 + ret + +.asm_12ba0 + call TakePartyItem + ld a, 3 + ret + +.asm_12ba6 + ld a, 3 + ret +; 12ba9 + + +Function12ba9: ; 12ba9 + + ld a, $4 + ld hl, $46a5 + rst FarCall + +.loop + ld a, $4 + ld hl, $46be + rst FarCall + + ld a, [$cf66] + and a + jr z, .quit + + ld a, [$cf65] + cp 2 + jr z, .next + + call $2f46 + ld a, [$d142] + and a + jr nz, .next + + call Function12bd9 + jr .quit + +.next + ld hl, CantBeHeldText + call $1d67 + jr .loop + +.quit + ret +; 12bd9 + + +Function12bd9: ; 12bd9 + + call SpeechTextBox + call PartyMonItemName + call GetPartyItemLocation + ld a, [hl] + and a + jr z, .asm_12bf4 + + push hl + ld d, a + ld a, $2e + ld hl, $5e76 + rst FarCall + pop hl + jr c, .asm_12c01 + ld a, [hl] + jr .asm_12c08 + +.asm_12bf4 + call $6cea + ld hl, MadeHoldText + call $1d67 + call GivePartyItem + ret + +.asm_12c01 + ld hl, PleaseRemoveMailText + call $1d67 + ret + +.asm_12c08 + ld [$d265], a + call GetItemName + ld hl, SwitchAlreadyHoldingText + call $6cf5 + jr c, .asm_12c4b + + call $6cea + ld a, [$d265] + push af + ld a, [CurItem] + ld [$d265], a + pop af + ld [CurItem], a + call $6cdf + jr nc, .asm_12c3c + + ld hl, TookAndMadeHoldText + call $1d67 + ld a, [$d265] + ld [CurItem], a + call GivePartyItem + ret + +.asm_12c3c + ld a, [$d265] + ld [CurItem], a + call $6cdf + ld hl, ItemStorageIsFullText + call $1d67 + +.asm_12c4b + ret +; 12c4c + + +GivePartyItem: ; 12c4c + + call GetPartyItemLocation + ld a, [CurItem] + ld [hl], a + ld d, a + ld a, $2e + ld hl, $5e76 + rst FarCall + jr nc, .asm_12c5f + call $6cfe + +.asm_12c5f + ret +; 12c60 + + +TakePartyItem: ; 12c60 + + call SpeechTextBox + call GetPartyItemLocation + ld a, [hl] + and a + jr z, .asm_12c8c + + ld [CurItem], a + call $6cdf + jr nc, .asm_12c94 + + ld a, $2e + ld hl, $5e76 + rst FarCall + call GetPartyItemLocation + ld a, [hl] + ld [$d265], a + ld [hl], NO_ITEM + call GetItemName + ld hl, TookFromText + call $1d67 + jr .asm_12c9a + +.asm_12c8c + ld hl, IsntHoldingAnythingText + call $1d67 + jr .asm_12c9a + +.asm_12c94 + ld hl, ItemStorageIsFullText + call $1d67 + +.asm_12c9a + ret +; 12c9b + + +GiveTakeItemMenuData: ; 12c9b + db %01010000 + db 12, 12 ; start coords + db 17, 19 ; end coords + dw .Items + db 1 ; default option + +.Items + db %10000000 ; x padding + db 2 ; # items + db "GIVE@" + db "TAKE@" +; 12caf + + +TookAndMadeHoldText: ; 12caf + text_jump UnknownText_0x1c1b2c, BANK(UnknownText_0x1c1b2c) + db "@" +; 12cb4 + +MadeHoldText: ; 12cb4 + text_jump UnknownText_0x1c1b57, BANK(UnknownText_0x1c1b57) + db "@" +; 12cb9 + +PleaseRemoveMailText: ; 12cb9 + text_jump UnknownText_0x1c1b6f, BANK(UnknownText_0x1c1b6f) + db "@" +; 12cbe + +IsntHoldingAnythingText: ; 12cbe + text_jump UnknownText_0x1c1b8e, BANK(UnknownText_0x1c1b8e) + db "@" +; 12cc3 + +ItemStorageIsFullText: ; 12cc3 + text_jump UnknownText_0x1c1baa, BANK(UnknownText_0x1c1baa) + db "@" +; 12cc8 + +TookFromText: ; 12cc8 + text_jump UnknownText_0x1c1bc4, BANK(UnknownText_0x1c1bc4) + db "@" +; 12ccd + +SwitchAlreadyHoldingText: ; 12ccd + text_jump UnknownText_0x1c1bdc, BANK(UnknownText_0x1c1bdc) + db "@" +; 12cd2 + +CantBeHeldText: ; 12cd2 + text_jump UnknownText_0x1c1c09, BANK(UnknownText_0x1c1c09) + db "@" +; 12cd7 + + +GetPartyItemLocation: ; 12cd7 + push af + ld a, PartyMon1Item - PartyMon1 + call GetPartyParamLocation + pop af + ret +; 12cdf + + +INCBIN "baserom.gbc", $12cdf, $12e00 - $12cdf -INCBIN "baserom.gbc", $12aec, $12e00 - $12aec OpenPartyStats: ; 12e00 call $1d6e call ClearSprites - xor a - ld [MonType], a ; partymon + xor a ; partymon + ld [MonType], a call LowVolume ld a, $25 call Predef call MaxVolume call $1d7d - ld a, $0 + ld a, 0 ret -; 0x12e1b +; 12e1b + INCBIN "baserom.gbc", $12e1b, $13b87 - $12e1b + GetSquareRoot: ; 13b87 ; Return the square root of de in b. @@ -16269,9 +16855,7 @@ CheckSignFlag: ; 96ad8 CheckPlayerMovement: ; 96af0 - ld a, BANK(DoPlayerMovement) - ld hl, DoPlayerMovement - rst FarCall + callba DoPlayerMovement ld a, c ld hl, .pointers rst $28 @@ -16370,7 +16954,7 @@ CheckMenuOW: ; 96b30 StartMenuScript: ; 96b58 - 3callasm $04, $65cd ; StartMenu + 3callasm BANK(StartMenu), StartMenu 2jump UnknownScript_0x96b66 ; 96b5f diff --git a/wram.asm b/wram.asm index ed5ff6ebd..4154842d8 100644 --- a/wram.asm +++ b/wram.asm @@ -837,9 +837,9 @@ CurSpecies: ; cf60 ds $13 MenuSelection:; cf74 - ds 1 - - ds $cf82-$cf74 + ds 1 + + ds 14 TileY: ; cf82 ds 1 @@ -1058,14 +1058,13 @@ TempMonSpclAtk: ; d13a ds 2 TempMonSpclDef: ; d13c ds 2 -TempMonEnd: ; d13e +TempMonEnd ; d13e ds 3 -PartyMenuActionText ; d141 - ds 1 - - ds 1 +PartyMenuActionText: ; d141 + ds 1 + ds 1 CurPartyLevel: ; d143 ds 1 @@ -1622,7 +1621,12 @@ TimeOfDayPal: ; d841 CurTimeOfDay: ; d848 ds 1 - ds 5 + ds 3 + +StatusFlags: ; d84c + ds 1 +StatusFlags2: ; d84d + ds 1 Money: ; d84e ds 3 From 425b727784801b0d1f2e45f7329a1129f7172f48 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 2 Jul 2013 14:09:14 -0400 Subject: [PATCH 04/13] make: check wram/constants --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 37e9aef4f..697515b6e 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ clean: rm -f pokecrystal.o pokecrystal.gbc @echo 'rm -f $(TEXTFILES:.asm=.tx)' @rm -f $(TEXTFILES:.asm=.tx) -pokecrystal.o: $(TEXTFILES:.asm=.tx) $(LZ_GFX) $(TWOBPP_GFX) +pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constants/ -type f -name '*constants.asm') hram.asm gbhw.asm $(LZ_GFX) $(TWOBPP_GFX) python prequeue.py $(TEXTQUEUE) rgbasm -o pokecrystal.o pokecrystal.asm .asm.tx: From dca6fd37cd16d12b1f35174bcf278d41138903d5 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 2 Jul 2013 14:10:49 -0400 Subject: [PATCH 05/13] start using relevant constants in wram.asm --- battle/effect_commands.asm | 2 +- constants.asm | 64 --------------------------- items/item_effects.asm | 4 +- main.asm | 89 +++++++++++++++++++------------------- wram.asm | 80 ++++++++++++++++++++++++---------- 5 files changed, 105 insertions(+), 134 deletions(-) diff --git a/battle/effect_commands.asm b/battle/effect_commands.asm index a25e5eede..2336c524a 100644 --- a/battle/effect_commands.asm +++ b/battle/effect_commands.asm @@ -9953,7 +9953,7 @@ Function0x377f5: ; 377f5 ld [$d123], a ld a, [hl] ld [$d124], a - ld a, $3 + ld a, 3 ld [MonType], a ld a, $14 ld hl, $4bdd diff --git a/constants.asm b/constants.asm index 4d9b0cb62..9605dafc5 100644 --- a/constants.asm +++ b/constants.asm @@ -184,22 +184,6 @@ ICON_SUDOWOODO EQU $25 ICON_BIGMON EQU $26 -; days of the week -SUNDAY EQU 0 -MONDAY EQU 1 -TUESDAY EQU 2 -WEDNESDAY EQU 3 -THURSDAY EQU 4 -FRIDAY EQU 5 -SATURDAY EQU 6 - -; time of day -MORN EQU 0 -DAY EQU 1 -NITE EQU 2 -DARKNESS EQU 3 - - ; evolution types EVOLVE_LEVEL EQU 1 EVOLVE_ITEM EQU 2 @@ -220,23 +204,6 @@ ATK_LT_DEF EQU 2 ATK_EQ_DEF EQU 3 -; main menu -CONTINUE EQU 0 -NEW_GAME EQU 1 -OPTION EQU 2 -MYSTERY_GIFT EQU 3 -MOBILE EQU 4 -MOBILE_STUDIUM EQU 5 - -; kris's pc menu items -WITHDRAW_ITEM EQU 0 -DEPOSIT_ITEM EQU 1 -TOSS_ITEM EQU 2 -MAIL_BOX EQU 3 -DECORATION EQU 4 -TURN_OFF EQU 5 -LOG_OFF EQU 6 - ; name length PLAYER_NAME_LENGTH EQU 8 PKMN_NAME_LENGTH EQU 11 @@ -258,20 +225,10 @@ SET_FLAG EQU 1 CHECK_FLAG EQU 2 -; player states -PLAYER_NORMAL EQU 0 -PLAYER_BIKE EQU 1 -PLAYER_SLIP EQU 2 -PLAYER_SURF EQU 4 -PLAYER_SURF_PIKA EQU 8 - - ; joypad BUTTONS EQU %00010000 D_PAD EQU %00100000 -AUTO_INPUT EQU $ff - NO_INPUT EQU %00000000 BUTTON_A EQU %00000001 BUTTON_B EQU %00000010 @@ -284,12 +241,6 @@ D_DOWN EQU %10000000 ; movement -STANDING EQU -1 -DOWN EQU 0 -UP EQU 1 -LEFT EQU 2 -RIGHT EQU 3 - STEP_SLOW EQU 0 STEP_WALK EQU 1 STEP_BIKE EQU 2 @@ -299,19 +250,4 @@ STEP_TURN EQU 5 STEP_BACK_LEDGE EQU 6 STEP_WALK_IN_PLACE EQU 7 -; facing -FACE_CURRENT EQU 0 -FACE_DOWN EQU 8 -FACE_UP EQU 4 -FACE_LEFT EQU 2 -FACE_RIGHT EQU 1 - - -; Provisional wram bank 5 labels: - -; 8 4-color palettes -Unkn1Pals EQU $d000 -Unkn2Pals EQU $d040 -BGPals EQU $d080 -OBPals EQU $d0c0 diff --git a/items/item_effects.asm b/items/item_effects.asm index 51e5ff0ef..09e6857bf 100644 --- a/items/item_effects.asm +++ b/items/item_effects.asm @@ -448,7 +448,7 @@ ParkBall: ; e8a2 xor a ld [CurPartyMon], a - ld a, $2 + ld a, BOXMON ld [MonType], a ld de, $d050 ld b, $0 @@ -775,7 +775,7 @@ Function_0xed12: ; ed12 push de ld a, [TempEnemyMonSpecies] ld [CurPartySpecies], a - ld a, $4 + ld a, WILDMON ld [MonType], a ld a, $14 ld hl, $4bdd diff --git a/main.asm b/main.asm index 0b58a7820..231ddbdc8 100644 --- a/main.asm +++ b/main.asm @@ -8200,7 +8200,8 @@ INCBIN "baserom.gbc", $12cdf, $12e00 - $12cdf OpenPartyStats: ; 12e00 call $1d6e call ClearSprites - xor a ; partymon +; PartyMon + xor a ld [MonType], a call LowVolume ld a, $25 @@ -8255,7 +8256,7 @@ INCBIN "baserom.gbc", $14000, $14032 - $14000 GetTimeOfDay: ; 14032 ; get time of day based on the current hour ld a, [hHours] ; hour - ld hl, TimeOfDayTable + ld hl, TimesOfDay .check ; if we're within the given time period, @@ -8276,14 +8277,13 @@ GetTimeOfDay: ; 14032 ret ; 14044 -TimeOfDayTable: ; 14044 -; boundaries for the time of day +TimesOfDay: ; 14044 +; hours for the time of day ; 04-09 morn | 10-17 day | 18-03 nite -; hr, time of day - db 04, $02 ; NITE - db 10, $00 ; MORN - db 18, $01 ; DAY - db 24, $02 ; NITE + db 04, NITE + db 10, MORN + db 18, DAY + db 24, NITE ; 1404c INCBIN "baserom.gbc", $1404c, $152ab - $1404c @@ -8323,8 +8323,8 @@ INCBIN "baserom.gbc", $1531f, $15736 - $1531f KrissPCMenuData: ; 0x15736 db %01000000 - db 0, 0 ; top left corner coords (y, x) - db $c, $f ; bottom right corner coords (y, x) + db 0, 0 ; top left corner coords (y, x) + db 12, 15 ; bottom right corner coords (y, x) dw .KrissPCMenuData2 db 1 ; default selected option @@ -8337,35 +8337,29 @@ KrissPCMenuData: ; 0x15736 dw .KrissPCMenuPointers .KrissPCMenuPointers ; 0x15746 - dw KrisWithdrawItemMenu ; 57d1 - dw .WithdrawItem - dw KrisDepositItemMenu ; 588b - dw .DepositItem - dw KrisTossItemMenu ; 585f - dw .TossItem - dw KrisMailBoxMenu ; 587d - dw .MailBox - dw KrisDecorationMenu ; 597d - dw .Decoration - dw KrisLogOffMenu ; 5888 - dw .LogOff - dw KrisLogOffMenu ; 5888 - dw .TurnOff + dw KrisWithdrawItemMenu, .WithdrawItem + dw KrisDepositItemMenu, .DepositItem + dw KrisTossItemMenu, .TossItem + dw KrisMailBoxMenu, .MailBox + dw KrisDecorationMenu, .Decoration + dw KrisLogOffMenu, .LogOff + dw KrisLogOffMenu, .TurnOff -.WithdrawItem - db "WITHDRAW ITEM@" -.DepositItem - db "DEPOSIT ITEM@" -.TossItem - db "TOSS ITEM@" -.MailBox - db "MAIL BOX@" -.Decoration - db "DECORATION@" -.TurnOff - db "TURN OFF@" -.LogOff - db "LOG OFF@" +.WithdrawItem db "WITHDRAW ITEM@" +.DepositItem db "DEPOSIT ITEM@" +.TossItem db "TOSS ITEM@" +.MailBox db "MAIL BOX@" +.Decoration db "DECORATION@" +.TurnOff db "TURN OFF@" +.LogOff db "LOG OFF@" + +WITHDRAW_ITEM EQU 0 +DEPOSIT_ITEM EQU 1 +TOSS_ITEM EQU 2 +MAIL_BOX EQU 3 +DECORATION EQU 4 +TURN_OFF EQU 5 +LOG_OFF EQU 6 .KrissPCMenuList1 db 5 @@ -8374,7 +8368,7 @@ KrissPCMenuData: ; 0x15736 db TOSS_ITEM db MAIL_BOX db TURN_OFF - db $FF + db $ff .KrissPCMenuList2 db 6 @@ -8384,7 +8378,7 @@ KrissPCMenuData: ; 0x15736 db MAIL_BOX db DECORATION db LOG_OFF - db $FF + db $ff INCBIN "baserom.gbc", $157bb, $157d1 - $157bb @@ -12010,6 +12004,13 @@ Label49d60: ; 0x49d60 dw $5efc ; XXX is this MobileASM? dw $6496 ; XXX is this MobileStudiumASM? +CONTINUE EQU 0 +NEW_GAME EQU 1 +OPTION EQU 2 +MYSTERY_GIFT EQU 3 +MOBILE EQU 4 +MOBILE_STUDIUM EQU 5 + NewGameMenu: ; 0x49d6c db 2 db NEW_GAME @@ -13358,7 +13359,7 @@ GetGender: ; 50bdd ; BoxMon data is read directly from SRAM. ld a, [MonType] - cp 2 + cp BOXMON ld a, 1 call z, GetSRAMBank @@ -13376,8 +13377,8 @@ GetGender: ; 50bdd ld b, a ; Close SRAM if we were dealing with a BoxMon. - ld a, [MonType] ; MonType - cp 2 ; BOXMON + ld a, [MonType] + cp BOXMON call z, CloseSRAM diff --git a/wram.asm b/wram.asm index 4154842d8..b454e9342 100644 --- a/wram.asm +++ b/wram.asm @@ -10,12 +10,14 @@ SECTION "bgmap1",VRAM[$9C00] VBGMap1: -; So far, WRAM banks 0 and 1 are included in this file. -; Any bank 2-7 labels are in constants.asm. +; WRAM banks 0 and 1 are included as BSS labels. +; Other WRAM banks (2-7) are constants for now. +SECTION "WRAMBank0",BSS[$c000] + SECTION "stack",BSS[$c000] - ds 256 + ds $100 Stack: ; c100 @@ -65,10 +67,7 @@ Channel1MusicAddress: ; c107 Channel1LastMusicAddress: ; c109 ds 2 ; could have been meant as a third-level address -; unused? ; c10b - ds 1 -; unused? ; c10c - ds 1 + ds 2 Channel1NoteFlags: ; c10d ; 0: ; 1: @@ -312,8 +311,7 @@ CurMusic: ; c2c0 SECTION "auto",BSS[$c2c7] InputType: ; c2c7 -; 00 normal -; ff auto +AUTO_INPUT EQU $ff ds 1 AutoInputAddress: ; c2c8 ds 2 @@ -824,11 +822,10 @@ AttrMap: ; cdd9 ds 30 MonType: ; cf5f -; 0 partymon -; 1 otpartymon -; 2 boxmon -; 3 ????mon -; 4 wildmon +PARTYMON EQU 0 +OTPARTYMON EQU 1 +BOXMON EQU 2 +WILDMON EQU 4 ds 1 CurSpecies: ; cf60 @@ -907,7 +904,9 @@ Options2: ; cfd1 ds 46 -; d000 + +SECTION "WRAMBank1",BSS[$d000] + ds 2 DefaultFlypoint: ; d002 @@ -937,10 +936,23 @@ CurFruit: ; d03f MovementAnimation: ; d042 ds 1 + WalkingDirection: ; d043 +STANDING EQU -1 +DOWN EQU 0 +UP EQU 1 +LEFT EQU 2 +RIGHT EQU 3 ds 1 + FacingDirection: ; d044 +FACE_CURRENT EQU 0 +FACE_DOWN EQU 8 +FACE_UP EQU 4 +FACE_LEFT EQU 2 +FACE_RIGHT EQU 1 ds 1 + WalkingX: ; d045 ds 1 WalkingY: ; d046 @@ -1378,10 +1390,10 @@ CurDamage: ; d256 SECTION "TimeOfDay",BSS[$d269] TimeOfDay: ; d269 -; 0 morn -; 1 day -; 2 nite -; 3 darkness +MORN EQU 0 +DAY EQU 1 +NITE EQU 2 +DARKNESS EQU 3 ds 1 SECTION "OTParty",BSS[$d280] @@ -1568,6 +1580,13 @@ GameTimeFrames: ; d4c8 ds 2 CurDay: ; d4cb +SUNDAY EQU 0 +MONDAY EQU 1 +TUESDAY EQU 2 +WEDNESDAY EQU 3 +THURSDAY EQU 4 +FRIDAY EQU 5 +SATURDAY EQU 6 ds 1 ds 12 @@ -1660,10 +1679,11 @@ Balls: ; d8d8 SECTION "overworld",BSS[$d95d] PlayerState: ; d95d -; $00: normal -; $01: bicycle -; $04: surf -; $08: surf (pikachu) +PLAYER_NORMAL EQU 0 +PLAYER_BIKE EQU 1 +PLAYER_SLIP EQU 2 +PLAYER_SURF EQU 4 +PLAYER_SURF_PIKA EQU 8 ds 1 SECTION "scriptram",BSS[$d962] @@ -2005,3 +2025,17 @@ RoamMon3CurHP: ; dfe1 ds 1 RoamMon3DVs: ; dfe2 ds 2 + + + +; SECTION "WRAMBank5",BSS[$d000] + +; 8 4-color palettes +Unkn1Pals EQU $d000 +Unkn2Pals EQU $d040 +BGPals EQU $d080 +OBPals EQU $d0c0 + + + + From 24daef7afb9f64ae4df3608c3163457a4a515fd2 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 2 Jul 2013 23:01:34 -0400 Subject: [PATCH 06/13] SelectMenu --- main.asm | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++----- wram.asm | 15 ++- 2 files changed, 306 insertions(+), 33 deletions(-) diff --git a/main.asm b/main.asm index 231ddbdc8..ca8db3006 100644 --- a/main.asm +++ b/main.asm @@ -2927,7 +2927,23 @@ CheckFacingSign: ; 2a8b ; 0x2ad4 -INCBIN "baserom.gbc", $2ad4, $2b74 - $2ad4 +INCBIN "baserom.gbc", $2ad4, $2b29 - $2ad4 + + +FadeToMenu: ; 2b29 + xor a + ld [hBGMapMode], a + call $1d6e + ld a, $23 + ld hl, $4084 + rst FarCall + call ClearSprites + call Function2ed3 + ret +; 2b3c + + +INCBIN "baserom.gbc", $2b3c, $2b74 - $2b3c Function2b74: ; 0x2b74 @@ -3201,7 +3217,27 @@ Predef: ; 2d83 ret ; 2dba -INCBIN "baserom.gbc", $2dba, $2e6f-$2dba + +ResetWindow: ; 2dba + + call $1fbf + ld a, [hROMBank] + push af + ld a, $1 + rst Bankswitch + + call $6454 + call $2e20 + call $64bf + + pop af + rst Bankswitch + ret +; 2dcf + + +INCBIN "baserom.gbc", $2dcf, $2e6f-$2dcf + BitTable1Func: ; 0x2e6f ld hl, $da72 @@ -3323,7 +3359,30 @@ InitString: ; 0x2ef9 ret ; 0x2f17 -INCBIN "baserom.gbc", $2f17, $2f8c - $2f17 + +INCBIN "baserom.gbc", $2f17, $2f3f - $2f17 + + +DoItemEffect: ; 2f3f + callba _DoItemEffect + ret +; 2f46 + + +CheckTossableItem: ; 2f46 + push hl + push de + push bc + callba _CheckTossableItem + pop bc + pop de + pop hl + ret +; 2f53 + + +INCBIN "baserom.gbc", $2f53, $2f8c - $2f53 + RNG: ; 2f8c ; Two random numbers are generated by adding and subtracting @@ -6763,7 +6822,7 @@ GetNumberedTMHM: ; d417 ; d427 -CheckTossableItem: ; d427 +_CheckTossableItem: ; d427 ; Return 1 in $d142 and carry if CurItem can't be removed from the bag. ld a, 4 call GetItemAttr @@ -6872,7 +6931,7 @@ ClearPCItemScreen: ; e58b INCBIN "baserom.gbc", $e5bb, $e722 - $e5bb -DoItemEffect: ; e722 +_DoItemEffect: ; e722 ld a, [CurItem] ld [$d265], a call GetItemName @@ -7663,7 +7722,7 @@ StartMenu_Save: ; 1290b StartMenu_Option: ; 1291c ; Game options. - call $2b29 + call FadeToMenu ld a, $1 ld hl, $5b64 rst FarCall @@ -7675,7 +7734,7 @@ StartMenu_Option: ; 1291c StartMenu_Status: ; 12928 ; Player status. - call $2b29 + call FadeToMenu ld a, $9 ld hl, $5105 rst FarCall @@ -7691,7 +7750,7 @@ StartMenu_Pokedex: ; 12937 and a jr z, .asm_12949 - call $2b29 + call FadeToMenu ld a, $10 ld hl, $4000 rst FarCall @@ -7705,7 +7764,7 @@ StartMenu_Pokedex: ; 12937 StartMenu_Pokegear: ; 1294c - call $2b29 + call FadeToMenu ld a, $24 ld hl, $4b8d rst FarCall @@ -7717,7 +7776,7 @@ StartMenu_Pokegear: ; 1294c StartMenu_Pack: ; 1295b - call $2b29 + call FadeToMenu ld a, $4 ld hl, $4000 rst FarCall @@ -7740,7 +7799,7 @@ StartMenu_Pokemon: ; 12976 and a jr z, .return - call $2b29 ; fade in? + call FadeToMenu .choosemenu xor a @@ -7791,7 +7850,19 @@ StartMenu_Pokemon: ; 12976 ; 129d5 -INCBIN "baserom.gbc", $129d5, $12a6c - $129d5 +INCBIN "baserom.gbc", $129d5, $12a60 - $129d5 + + +CantUseItem: ; 12a60 + ld hl, CantUseItemText + call $2012 + ret +; 12a67 + +CantUseItemText: ; 12a67 + text_jump UnknownText_0x1c1b03, BANK(UnknownText_0x1c1b03) + db "@" +; 12a6c PartyMonItemName: ; 12a6c @@ -7989,7 +8060,7 @@ Function12ba9: ; 12ba9 cp 2 jr z, .next - call $2f46 + call CheckTossableItem ld a, [$d142] and a jr nz, .next @@ -8213,7 +8284,201 @@ OpenPartyStats: ; 12e00 ; 12e1b -INCBIN "baserom.gbc", $12e1b, $13b87 - $12e1b +INCBIN "baserom.gbc", $12e1b, $13327 - $12e1b + + +SelectMenu: ; 13327 + + call CheckRegisteredItem + jr c, .NotRegistered + jp UseRegisteredItem + +.NotRegistered + call $2e08 + ld b, BANK(ItemMayBeRegisteredText) + ld hl, ItemMayBeRegisteredText + call $269a + call $0a46 + jp $2dcf +; 13340 + + +ItemMayBeRegisteredText: ; 13340 + text_jump UnknownText_0x1c1cf3, BANK(UnknownText_0x1c1cf3) + db "@" +; 13345 + + +CheckRegisteredItem: ; 13345 + + ld a, [WhichRegisteredItem] + and a + jr z, .NoRegisteredItem + and REGISTERED_POCKET + rlca + rlca + ld hl, .Pockets + rst $28 + ret + +.Pockets + dw .CheckItem + dw .CheckBall + dw .CheckKeyItem + dw .CheckTMHM + +.CheckItem + ld hl, NumItems + call .CheckRegisteredNo + jr c, .NoRegisteredItem + inc hl + ld e, a + ld d, 0 + add hl, de + add hl, de + call .IsSameItem + jr c, .NoRegisteredItem + and a + ret + +.CheckKeyItem + ld a, [RegisteredItem] + ld hl, KeyItems + ld de, 1 + call IsInArray + jr nc, .NoRegisteredItem + ld a, [RegisteredItem] + ld [CurItem], a + and a + ret + +.CheckBall + ld hl, NumBalls + call .CheckRegisteredNo + jr nc, .NoRegisteredItem + inc hl + ld e, a + ld d, 0 + add hl, de + add hl, de + call .IsSameItem + jr c, .NoRegisteredItem + ret + +.CheckTMHM + jr .NoRegisteredItem + +.NoRegisteredItem + xor a + ld [WhichRegisteredItem], a + ld [RegisteredItem], a + scf + ret +; 133a6 + + +.CheckRegisteredNo ; 133a6 + ld a, [WhichRegisteredItem] + and REGISTERED_NUMBER + dec a + cp [hl] + jr nc, .NotEnoughItems + ld [$d107], a + and a + ret + +.NotEnoughItems + scf + ret +; 133b6 + + +.IsSameItem ; 133b6 + ld a, [RegisteredItem] + cp [hl] + jr nz, .NotSameItem + ld [CurItem], a + and a + ret + +.NotSameItem + scf + ret +; 133c3 + + +UseRegisteredItem: ; 133c3 + + callba CheckItemMenu + ld a, [$d142] + ld hl, .SwitchTo + rst $28 + ret + +.SwitchTo + dw .CantUse + dw .NoFunction + dw .NoFunction + dw .NoFunction + dw .Current + dw .Party + dw .Overworld +; 133df + +.NoFunction ; 133df + call $2e08 + call CantUseItem + call $2dcf + and a + ret +; 133ea + +.Current ; 133ea + call $2e08 + call DoItemEffect + call $2dcf + and a + ret +; 133f5 + +.Party ; 133f5 + call ResetWindow + call FadeToMenu + call DoItemEffect + call $2b3c + call $2dcf + and a + ret +; 13406 + +.Overworld ; 13406 + call ResetWindow + ld a, 1 + ld [$d0ef], a + call DoItemEffect + xor a + ld [$d0ef], a + ld a, [$d0ec] + cp 1 + jr nz, .asm_13425 + scf + ld a, $80 + ld [$ffa0], a + ret +; 13422 + +.CantUse ; 13422 + call ResetWindow + +.asm_13425 + call CantUseItem + call $2dcf + and a + ret +; 1342d + + +INCBIN "baserom.gbc", $1342d, $13b87 - $1342d GetSquareRoot: ; 13b87 @@ -8401,8 +8666,8 @@ KrisWithdrawItemMenu: ; 0x157d1 Function157e9: ; 0x157e9 ; check if the item has a quantity - ld a, BANK(CheckTossableItem) - ld hl, CheckTossableItem + ld a, BANK(_CheckTossableItem) + ld hl, _CheckTossableItem rst $8 ld a, [$d142] and a @@ -8525,7 +8790,7 @@ KrisDepositItemMenu: ; 0x1588b jr z, .asm_158b3 call Function158cc ld a, $4 - ld hl, $7345 + ld hl, CheckRegisteredItem rst $8 jr .asm_1589c @@ -9105,8 +9370,8 @@ Function24ac3: ; 0x24ac3 push de ld a, [MenuSelection] ld [CurItem], a - ld a, BANK(CheckTossableItem) - ld hl, CheckTossableItem + ld a, BANK(_CheckTossableItem) + ld hl, _CheckTossableItem rst $8 ld a, [$d142] pop hl @@ -11803,7 +12068,7 @@ Function4484a: ; 0x4484a dw .Cancel .ReadMail ; 0x44869 - call $2b29 + call FadeToMenu ld a, [MenuSelection] dec a ld b, a @@ -11863,7 +12128,7 @@ Function4484a: ; 0x4484a ; 0x448d2 .AttachMail ; 0x448d2 - call $2b29 + call FadeToMenu xor a ld [$d141], a call $31f3 @@ -16956,26 +17221,27 @@ CheckMenuOW: ; 96b30 StartMenuScript: ; 96b58 3callasm BANK(StartMenu), StartMenu - 2jump UnknownScript_0x96b66 + 2jump StartMenuCallback ; 96b5f SelectMenuScript: ; 96b5f - 3callasm $04, $7327 ; SelectMenu - 2jump UnknownScript_0x96b66 + 3callasm BANK(SelectMenu), SelectMenu + 2jump SelectMenuCallback ; 96b66 -UnknownScript_0x96b66: ; 96b66 +StartMenuCallback: +SelectMenuCallback: ; 96b66 copybytetovar $ffa0 - if_equal $80, UnknownScript_0x96b72 - if_equal $ff, UnknownScript_0x96b75 + if_equal $80, .Script + if_equal $ff, .Asm end ; 96b72 -UnknownScript_0x96b72: ; 96b72 +.Script ; 96b72 2ptjump $d0e8 ; 96b75 -UnknownScript_0x96b75: ; 96b75 +.Asm ; 96b75 2ptcallasm $d0e8 end ; 96b79 diff --git a/wram.asm b/wram.asm index b454e9342..5731bb303 100644 --- a/wram.asm +++ b/wram.asm @@ -1665,19 +1665,26 @@ TMsHMs: ; d859 NumItems: ; d892 ds 1 Items: ; d893 - ds 69 + ds 41 NumKeyItems: ; d8bc ds 1 KeyItems: ; d8bd - ds 13 - + ds 26 + NumBalls: ; d8d7 ds 1 Balls: ; d8d8 ds 25 -SECTION "overworld",BSS[$d95d] +SECTION "overworld",BSS[$d95b] +WhichRegisteredItem: ; d95b +REGISTERED_POCKET EQU %11000000 +REGISTERED_NUMBER EQU %00111111 + ds 1 +RegisteredItem: ; d95c + ds 1 + PlayerState: ; d95d PLAYER_NORMAL EQU 0 PLAYER_BIKE EQU 1 From e7a7fcc92446134d47bbfb0b308c4decc2a2adf8 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 4 Jul 2013 03:53:49 -0400 Subject: [PATCH 07/13] crystal: add more movements --- extras/crystal.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extras/crystal.py b/extras/crystal.py index 680a441e3..d14642cf7 100644 --- a/extras/crystal.py +++ b/extras/crystal.py @@ -1989,6 +1989,7 @@ movement_command_bases = { 0x3A: "remove_fixed_facing", 0x3B: "fix_facing", 0x3D: "hide_person", + 0x3E: "show_person", 0x45: "accelerate_last", 0x46: ["step_sleep", ["duration", DecimalParam]], 0x47: "step_end", @@ -2000,6 +2001,8 @@ movement_command_bases = { 0x4E: "skyfall", 0x4F: "step_wait5", + 0x53: "hide_emote", + 0x54: "show_emote", 0x55: ["step_shake", ["displacement", DecimalParam]], } From aa62a4b88d956af1034bd07d94a4a703269b59b1 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 4 Jul 2013 03:55:04 -0400 Subject: [PATCH 08/13] version constant --- constants.asm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/constants.asm b/constants.asm index 9605dafc5..9cece6daa 100644 --- a/constants.asm +++ b/constants.asm @@ -1,5 +1,11 @@ _CRYSTAL EQU 1 +if _CRYSTAL +VERSION EQU 0 +else +VERSION EQU 1 +endc + INCLUDE "constants/pokemon_constants.asm" INCLUDE "constants/move_constants.asm" INCLUDE "constants/battle_constants.asm" From 82ebad99de7e34fb1bd977e3621ad88a48052b51 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 4 Jul 2013 04:11:28 -0400 Subject: [PATCH 09/13] MapObjects and ScriptRunning --- wram.asm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wram.asm b/wram.asm index 5731bb303..8d6c88bc1 100644 --- a/wram.asm +++ b/wram.asm @@ -1526,8 +1526,10 @@ OTPartyMon5Nickname: ; d416 OTPartyMon6Nickname: ; d421 ds 11 -SECTION "Scripting",BSS[$d439] +SECTION "Scripting",BSS[$d438] +ScriptRunning: ; d438 + ds 1 ScriptBank: ; d439 ds 1 ScriptPos: ; d43a @@ -1630,6 +1632,16 @@ PlayerSpriteY: ; d4ee ds 1 +SECTION "Objects",BSS[$d71e] +MapObjects: ; d71e + +PLAYER_OBJECT EQU 0 + +NUM_OBJECTS EQU $10 +OBJECT_LENGTH EQU $10 + ds OBJECT_LENGTH * NUM_OBJECTS + + SECTION "Status",BSS[$d841] TimeOfDayPal: ; d841 ds 1 From a3870db643c1d120422468ec55e486a59f9b2803 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 4 Jul 2013 04:11:45 -0400 Subject: [PATCH 10/13] Clean up and remove incbins from script commands --- engine/scripting.asm | 591 ++++++++++++++++++++++++++----------------- 1 file changed, 355 insertions(+), 236 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index 2875781f0..b4f5916f4 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -172,21 +172,21 @@ ScriptCommandTable: ; 0x96cb1 ; 0x96e05 Unknown_0x96e05: ; 0x96e05 - ld hl, $d434 - set 2, [hl] - ret + ld hl, $d434 + set 2, [hl] + ret ; 0x96e0b Unknown_0x96e0b: ; 0x96e0b - ld hl, $d434 - bit 2, [hl] - ret + ld hl, $d434 + bit 2, [hl] + ret ; 0x96e11 Unknown_0x96e11: ; 0x96e11 - ld hl, $d434 - res 2, [hl] - ret + ld hl, $d434 + res 2, [hl] + ret ; 0x96e17 Script_3callasm: ; 0x96e17 @@ -250,8 +250,8 @@ Script_jumptextfaceplayer: ; 0x96e45 ld [$d44f], a call GetScriptByte ld [$d450], a - ld b, $25 - ld hl, $6e79 + ld b, BANK(JumpTextFacePlayerScript) + ld hl, JumpTextFacePlayerScript jp ScriptJump ; 0x96e5f @@ -266,12 +266,20 @@ Script_jumptext: ; 0x96e5f ld [$d44f], a call GetScriptByte ld [$d450], a - ld b, $25 - ld hl, $6e7a + ld b, BANK(JumpTextScript) + ld hl, JumpTextScript jp ScriptJump ; 0x96e79 -INCBIN "baserom.gbc",$96e79,$96e81 - $96e79 +JumpTextFacePlayerScript: ; 0x96e79 + faceplayer +JumpTextScript: ; 0x96e7a + loadfont + repeattext $ff, $ff + closetext + loadmovesprites + end +; 0x96e81 Script_3jumptext: ; 0x96e81 ; script command 0x52 @@ -284,8 +292,8 @@ Script_3jumptext: ; 0x96e81 ld [$d44f], a call GetScriptByte ld [$d450], a - ld b, $25 - ld hl, $6e7a + ld b, BANK(JumpTextScript) + ld hl, JumpTextScript jp ScriptJump ; 0x96e9b @@ -478,16 +486,41 @@ Script_verbosegiveitem: ; 0x96f60 ; quantity (DecimalParam) call $77ca - call $7051 - ld de, $d073 + call CurItemName + ld de, StringBuffer1 ld a, $1 call $76c8 - ld b, $25 - ld de, $6f77 - jp $74cb + ld b, BANK(GiveItemScript) + ld de, GiveItemScript + jp ScriptCall ; 0x96f76 -INCBIN "baserom.gbc",$96f76,$96f8e - $96f76 + +Function96f76: ; 96f76 + ret +; 96f77 + +GiveItemScript: ; 96f77 + 3callasm BANK(Function96f76), Function96f76 + 2writetext ReceivedItemText + iffalse .Full + waitbutton + specialsound + closetext + itemnotify + end + +.Full + keeptextopen + pocketisfull + end +; 96f89 + +ReceivedItemText: ; 96f89 + text_jump UnknownText_0x1c4719, BANK(UnknownText_0x1c4719) + db "@" +; 96f8e + Script_verbosegiveitem2: ; 0x96f8e ; script command 0x9f @@ -512,22 +545,22 @@ Script_verbosegiveitem2: ; 0x96f8e xor a .asm_96fb0 ld [$c2dd], a - call $7051 - ld de, $d073 + call CurItemName + ld de, StringBuffer1 ld a, $1 call $76c8 - ld b, $25 - ld de, $6f77 - jp $74cb + ld b, BANK(GiveItemScript) + ld de, GiveItemScript + jp ScriptCall ; 0x96fc6 Script_itemnotify: ; 0x96fc6 ; script command 0x45 - call $6ffe - call $7051 - ld b, $25 - ld hl, $705b + call GetPocketName + call CurItemName + ld b, BANK(PutItemInPocketText) + ld hl, PutItemInPocketText call $269a ret ; 0x96fd5 @@ -535,10 +568,10 @@ Script_itemnotify: ; 0x96fc6 Script_pocketisfull: ; 0x96fd5 ; script command 0x46 - call $6ffe - call $7051 - ld b, $25 - ld hl, $7060 + call GetPocketName + call CurItemName + ld b, BANK(PocketIsFullText) + ld hl, PocketIsFullText call $269a ret ; 0x96fe4 @@ -560,7 +593,58 @@ Script_specialsound: ; 0x96fe4 ret ; 0x96ffe -INCBIN "baserom.gbc",$96ffe,$97065 - $96ffe + +GetPocketName: ; 96ffe + callba CheckItemPocket + ld a, [$d142] + dec a + ld hl, .Pockets + and 3 + add a + ld e, a + ld d, 0 + add hl, de + ld a, [hli] + ld d, [hl] + ld e, a + ld hl, StringBuffer3 + call CopyName2 + ret + +.Pockets + dw .Item + dw .Key + dw .Ball + dw .TM + +.Item + db "ITEM POCKET@" +.Key + db "KEY POCKET@" +.Ball + db "BALL POCKET@" +.TM + db "TM POCKET@" +; 97051 + +CurItemName: ; 97051 + ld a, [CurItem] + ld [$d265], a + call GetItemName + ret +; 9705b + + +PutItemInPocketText: ; 9705b + text_jump UnknownText_0x1c472c, BANK(UnknownText_0x1c472c) + db "@" +; 97060 + +PocketIsFullText: ; 97060 + text_jump UnknownText_0x1c474b, BANK(UnknownText_0x1c474b) + db "@" +; 97065 + Script_pokemart: ; 0x97065 ; script command 0x94 @@ -909,12 +993,12 @@ Script_cry: ; 0x971d1 ; 0x971e3 Unknown_0x971e3: ; 0x971e3 - and a - ret z - cp $fe - ret z - dec a - ret + and a + ret z + cp $fe + ret z + dec a + ret ; 0x971ea Script_setlasttalked: ; 0x971ea @@ -961,10 +1045,10 @@ Script_applymovement: ; 0x971f3 ; 0x97221 Unknown_0x97221: ; 0x97221 - ld a, $1 - ld hl, $5897 - rst $8 - ret + ld a, $1 + ld hl, $5897 + rst $8 + ret ; 0x97228 Script_applymovement2: ; 0x97228 @@ -1056,49 +1140,49 @@ Script_spriteface: ; 0x97274 ; 0x9728b Unknown_0x9728b: ; 0x9728b - ld a, d - push de - call $18de - jr c, .asm_972b9 ; 0x97290 $27 - ld hl, $0000 - add hl, bc - ld a, [hl] - push bc - call $1836 - pop bc - jr c, .asm_972b9 ; 0x9729c $1b - ld hl, $0004 - add hl, bc - bit 2, [hl] - jr nz, .asm_972b9 ; 0x972a4 $13 - pop de - ld a, e - call $1af8 - ld hl, $d0ed - bit 6, [hl] - jr nz, .asm_972b5 ; 0x972b0 $3 - call $72bc + ld a, d + push de + call $18de + jr c, .asm_972b9 ; 0x97290 $27 + ld hl, $0000 + add hl, bc + ld a, [hl] + push bc + call $1836 + pop bc + jr c, .asm_972b9 ; 0x9729c $1b + ld hl, $0004 + add hl, bc + bit 2, [hl] + jr nz, .asm_972b9 ; 0x972a4 $13 + pop de + ld a, e + call $1af8 + ld hl, $d0ed + bit 6, [hl] + jr nz, .asm_972b5 ; 0x972b0 $3 + call $72bc .asm_972b5 - call $1ad2 - ret + call $1ad2 + ret .asm_972b9 - pop de - scf - ret + pop de + scf + ret ; 0x972bc Unknown_0x972bc: ; 0x972bc - call $217a - ld hl, $c4a0 - ld bc, $0168 + call $217a + ld hl, $c4a0 + ld bc, $0168 .asm_972c5 - res 7, [hl] - inc hl - dec bc - ld a, b - or c - jr nz, .asm_972c5 ; 0x972cb $f8 - ret + res 7, [hl] + inc hl + dec bc + ld a, b + or c + jr nz, .asm_972c5 ; 0x972cb $f8 + ret ; 0x972ce Script_variablesprite: ; 0x972ce @@ -1153,24 +1237,24 @@ Script_disappear: ; 0x972ee ; 0x9730b Unknown_0x9730b: ; 0x9730b - push bc - call $18d2 - ld hl, $000c - add hl, bc - pop bc - ld e, [hl] - inc hl - ld d, [hl] - ld a, $ff - cp e - jr nz, .asm_97321 ; 0x9731a $5 - cp d - jr nz, .asm_97321 ; 0x9731d $2 - xor a - ret + push bc + call $18d2 + ld hl, $000c + add hl, bc + pop bc + ld e, [hl] + inc hl + ld d, [hl] + ld a, $ff + cp e + jr nz, .asm_97321 ; 0x9731a $5 + cp d + jr nz, .asm_97321 ; 0x9731d $2 + xor a + ret .asm_97321 - call BitTable1Func - ret + call BitTable1Func + ret ; 0x97325 Script_follow: ; 0x97325 @@ -1292,32 +1376,60 @@ Script_showemote: ; 0x97396 .asm_973a8 call GetScriptByte ld [$d44d], a - ld b, $25 - ld de, $73b6 - jp $74cb + ld b, BANK(ShowEmoteScript) + ld de, ShowEmoteScript + jp ScriptCall ; 0x973b6 -INCBIN "baserom.gbc",$973b6,$973c7 - $973b6 +ShowEmoteScript: ; 973b6 + loademote $ff + applymovement2 .Show + pause 0 + applymovement2 .Hide + end + +.Show + show_emote + show_person + step_end + +.Hide + hide_emote + show_person + step_end +; 973c7 + Script_earthquake: ; 0x973c7 ; script command 0x78 ; parameters: ; param (DecimalParam) - ld hl, $73eb + ld hl, EarthquakeMovement ld de, $d002 - ld bc, $0005 + ld bc, EarthquakeMovementEnd - EarthquakeMovement call CopyBytes call GetScriptByte ld [$d003], a and $3f ld [$d005], a - ld b, $25 - ld de, $73e6 - jp $74cb + ld b, BANK(UnknownScript_0x973e6) + ld de, UnknownScript_0x973e6 + jp ScriptCall ; 0x973e6 -INCBIN "baserom.gbc",$973e6,$973f0 - $973e6 +UnknownScript_0x973e6: ; 973e6 + applymovement $0, $d002 + end +; 973eb + +EarthquakeMovement: ; 973eb + step_shake 16 + step_sleep 16 + step_end +EarthquakeMovementEnd +; 973f0 + Script_loadpikachudata: ; 0x973f0 ; script command 0x5a @@ -1402,7 +1514,7 @@ Script_catchtutorial: ; 0x97447 ld a, $13 ld hl, $6554 rst $8 - jp $7491 + jp Script_reloadmap ; 0x97459 Script_returnafterbattle: ; 0x97459 @@ -1435,7 +1547,7 @@ Script_returnafterbattle: ; 0x97459 ld hl, $7c4f rst $8 .asm_9748e - jp $7491 + jp Script_reloadmap ; 0x97491 Script_reloadmap: ; 0x97491 @@ -1522,10 +1634,10 @@ ScriptCall: ; 0x974cb ; 0x974f3 Unknown_0x974f3: ; 0x974f3 - ld a, [ScriptBank] - or $80 - ld [ScriptBank], a - jp $74cb + ld a, [ScriptBank] + or $80 + ld [ScriptBank], a + jp ScriptCall ; 0x974fe Script_2jump: ; 0x974fe @@ -1580,7 +1692,7 @@ Script_iffalse: ; 0x9752c ld a, [$c2dd] and a - jp nz, $7596 + jp nz, SkipTwoScriptBytes jp Script_2jump ; 0x97536 @@ -1592,7 +1704,7 @@ Script_iftrue: ; 0x97536 ld a, [$c2dd] and a jp nz, Script_2jump - jp $7596 + jp SkipTwoScriptBytes ; 0x97540 Script_if_equal: ; 0x97540 @@ -1605,7 +1717,7 @@ Script_if_equal: ; 0x97540 ld hl, $c2dd cp [hl] jr z, Script_2jump ; 0x97547 $b5 - jr Unknown_97596 ; 0x97549 $4b + jr SkipTwoScriptBytes ; 0x97549 $4b ; 0x9754b Script_if_not_equal: ; 0x9754b @@ -1618,7 +1730,7 @@ Script_if_not_equal: ; 0x9754b ld hl, $c2dd cp [hl] jr nz, Script_2jump ; 0x97552 $aa - jr Unknown_97596 ; 0x97554 $40 + jr SkipTwoScriptBytes ; 0x97554 $40 ; 0x97556 Script_if_less_than: ; 0x97556 @@ -1632,7 +1744,7 @@ Script_if_less_than: ; 0x97556 call GetScriptByte cp b jr c, Script_2jump ; 0x9755e $9e - jr Unknown_97596 ; 0x97560 $34 + jr SkipTwoScriptBytes ; 0x97560 $34 ; 0x97562 Script_if_greater_than: ; 0x97562 @@ -1646,7 +1758,7 @@ Script_if_greater_than: ; 0x97562 ld a, [$c2dd] cp b jr c, Script_2jump ; 0x9756a $92 - jr Unknown_97596 ; 0x9756c $28 + jr SkipTwoScriptBytes ; 0x9756c $28 ; 0x9756e Script_jumpstd: ; 0x9756e @@ -1654,7 +1766,7 @@ Script_jumpstd: ; 0x9756e ; parameters: ; predefined_script (MultiByteParam) - call $757b + call StdScript jr ScriptJump ; 0x97571 $2a ; 0x97573 @@ -1663,31 +1775,31 @@ Script_callstd: ; 0x97573 ; parameters: ; predefined_script (MultiByteParam) - call $757b + call StdScript ld d, h ld e, l - jp $74cb + jp ScriptCall ; 0x9757b -Unknown_0x9757b: ; 0x9757b - call GetScriptByte - ld e, a - call GetScriptByte - ld d, a - ld hl, $4000 - add hl, de - add hl, de - add hl, de - ld a, $2f - call GetFarByte - ld b, a - inc hl - ld a, $2f - call GetFarHalfword - ret +StdScript: ; 0x9757b + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld hl, $4000 ; StdScripts + add hl, de + add hl, de + add hl, de + ld a, $2f ; BANK(StdScripts) + call GetFarByte + ld b, a + inc hl + ld a, $2f ; BANK(StdScripts) + call GetFarHalfword + ret ; 0x97596 -Unknown_97596: ; 0x97596 +SkipTwoScriptBytes: ; 0x97596 call GetScriptByte call GetScriptByte ret @@ -1897,16 +2009,16 @@ Script_random: ; 0x97640 ; 0x97673 Unknown_0x97673: ; 0x97673 - xor a - ld b, a - sub c + xor a + ld b, a + sub c .asm_97676 - inc b - sub c - jr nc, .asm_97676 ; 0x97678 $fc - dec b - add c - ret + inc b + sub c + jr nc, .asm_97676 ; 0x97678 $fc + dec b + add c + ret ; 0x9767d Script_checkcode: ; 0x9767d @@ -1947,22 +2059,24 @@ Script_writecode: ; 0x97693 ; 0x9769e Unknown_0x9769e: ; 0x9769e - ld c, a - ld a, $20 - ld hl, $4648 - rst $8 - ret + ld c, a + ld a, $20 + ld hl, $4648 + rst $8 + ret ; 0x976a6 Script_checkver: ; 0x976a6 ; script command 0x18 - ld a, [$76ad] + ld a, [Version] ld [$c2dd], a ret ; 0x976ad -INCBIN "baserom.gbc",$976ad,$976ae - $976ad +Version: ; 976ad + db VERSION +; 976ae Script_pokenamemem: ; 0x976ae ; script command 0x40 @@ -1977,7 +2091,7 @@ Script_pokenamemem: ; 0x976ae .asm_976b7 ld [$d265], a call $343b - ld de, $d073 + ld de, StringBuffer1 Unknown_976c0: ; 0x976c0 call GetScriptByte @@ -1985,8 +2099,8 @@ Unknown_976c0: ; 0x976c0 jr c, .asm_976c8 ; 0x976c5 $1 xor a .asm_976c8 - ld hl, $d099 - ld bc, $0013 + ld hl, StringBuffer3 + ld bc, 19 call AddNTimes call CopyName2 ret @@ -2005,7 +2119,7 @@ Script_itemtotext: ; 0x976d5 .asm_976de ld [$d265], a call GetItemName - ld de, $d073 + ld de, StringBuffer1 jr Unknown_976c0 ; 0x976e7 $d7 ; 0x976e9 @@ -2025,8 +2139,8 @@ Unknown_976f4: ; 0x976f4 ld a, $72 ld hl, $68a5 rst $8 - ld de, $d073 - jp $76c0 + ld de, StringBuffer1 + jp Unknown_976c0 ; 0x97701 Script_displaylocation: ; 0x97701 @@ -2065,8 +2179,8 @@ Unknown_9771c: ; 0x9771c call GetScriptByte ld [$cf60], a call GetName - ld de, $d073 - jp $76c0 + ld de, StringBuffer1 + jp Unknown_976c0 ; 0x9772b Script_unknown0xa6: ; 0x9772b @@ -2085,11 +2199,11 @@ Script_readmoney: ; 0x97732 call $7771 call $7861 - ld hl, $d073 + ld hl, StringBuffer1 ld bc, $4306 call $3198 - ld de, $d073 - jp $76c0 + ld de, StringBuffer1 + jp Unknown_976c0 ; 0x97747 Script_readcoins: ; 0x97747 @@ -2098,12 +2212,12 @@ Script_readcoins: ; 0x97747 ; memory (SingleByteParam) call $7771 - ld hl, $d073 + ld hl, StringBuffer1 ld de, $d855 ld bc, $4206 call $3198 - ld de, $d073 - jp $76c0 + ld de, StringBuffer1 + jp Unknown_976c0 ; 0x9775c Script_RAM2MEM: ; 0x9775c @@ -2113,19 +2227,19 @@ Script_RAM2MEM: ; 0x9775c call $7771 ld de, $c2dd - ld hl, $d073 + ld hl, StringBuffer1 ld bc, $4103 call $3198 - ld de, $d073 - jp $76c0 + ld de, StringBuffer1 + jp Unknown_976c0 ; 0x97771 Unknown_0x97771: ; 0x97771 - ld hl, $d073 - ld bc, $000b - ld a, $50 - call ByteFill - ret + ld hl, StringBuffer1 + ld bc, $000b + ld a, "@" + call ByteFill + ret ; 0x9777d Script_stringtotext: ; 0x9777d @@ -2141,8 +2255,8 @@ Script_stringtotext: ; 0x9777d ld a, [ScriptBank] ld hl, $30d6 rst $8 - ld de, $d086 - jp $76c0 + ld de, StringBuffer2 + jp Unknown_976c0 ; 0x97792 Script_givepokeitem: ; 0x97792 @@ -2309,27 +2423,27 @@ Unknown_9784f: ; 0x9784f ; 0x97861 Unknown_0x97861: ; 0x97861 - call GetScriptByte - and a - ld de, $d84e - ret z - ld de, $d851 - ret + call GetScriptByte + and a + ld de, $d84e + ret z + ld de, $d851 + ret ; 0x9786d Unknown_0x9786d: ; 0x9786d - ld bc, $ffc3 - push bc - call GetScriptByte - ld [bc], a - inc bc - call GetScriptByte - ld [bc], a - inc bc - call GetScriptByte - ld [bc], a - pop bc - ret + ld bc, $ffc3 + push bc + call GetScriptByte + ld [bc], a + inc bc + call GetScriptByte + ld [bc], a + inc bc + call GetScriptByte + ld [bc], a + pop bc + ret ; 0x97881 Script_givecoins: ; 0x97881 @@ -2643,10 +2757,10 @@ Script_checkbit2: ; 0x979d7 ; 0x979ee Unknown_0x979ee: ; 0x979ee - ld a, $20 - ld hl, $4430 - rst $8 - ret + ld a, $20 + ld hl, $4430 + rst $8 + ret ; 0x979f5 Script_wildon: ; 0x979f5 @@ -2869,10 +2983,10 @@ Script_warpcheck: ; 0x97af6 ; 0x97b01 Unknown_0x97b01: ; 0x97b01 - ld a, $25 - ld hl, $66d0 - rst $8 - ret + ld a, $25 + ld hl, $66d0 + rst $8 + ret ; 0x97b08 Script_newloadmap: ; 0x97b08 @@ -2922,7 +3036,10 @@ Script_loadbytec1ce: ; 0x97b27 ret ; 0x97b2e -INCBIN "baserom.gbc",$97b2e,$97b2f - $97b2e + +LoadMoveSpritesScript: ; 97b2e + loadmovesprites +; 97b2f Script_loadmovesprites: ; 0x97b2f ; script command 0x49 @@ -2932,6 +3049,7 @@ Script_loadmovesprites: ; 0x97b2f ret ; 0x97b36 + Script_passtoengine: ; 0x97b36 ; script command 0x89 ; parameters: @@ -2999,7 +3117,7 @@ Script_end: ; 0x97b74 ret .asm_97b7a xor a - ld [$d438], a + ld [ScriptRunning], a ld a, $0 ld [$d437], a ld hl, $d434 @@ -3021,32 +3139,32 @@ Script_return: ; 0x97b8c ; 0x97b9a Unknown_0x97b9a: ; 0x97b9a - ld hl, $d43c - ld a, [hl] - and a - jr z, .asm_97bbe ; 0x97b9f $1d - dec [hl] - ld e, [hl] - ld d, $0 - ld hl, $d43d - add hl, de - add hl, de - add hl, de - ld a, [hli] - ld b, a - and $7f - ld [ScriptBank], a - ld a, [hli] - ld e, a - ld [ScriptPos], a - ld a, [hl] - ld d, a - ld [ScriptPos + 1], a - and a - ret + ld hl, $d43c + ld a, [hl] + and a + jr z, .asm_97bbe ; 0x97b9f $1d + dec [hl] + ld e, [hl] + ld d, $0 + ld hl, $d43d + add hl, de + add hl, de + add hl, de + ld a, [hli] + ld b, a + and $7f + ld [ScriptBank], a + ld a, [hli] + ld e, a + ld [ScriptPos], a + ld a, [hl] + ld d, a + ld [ScriptPos + 1], a + and a + ret .asm_97bbe - scf - ret + scf + ret ; 0x97bc0 Script_resetfuncs: ; 0x97bc0 @@ -3054,7 +3172,7 @@ Script_resetfuncs: ; 0x97bc0 xor a ld [$d43c], a - ld [$d438], a + ld [ScriptRunning], a ld a, $0 ld [$d437], a ld hl, $d434 @@ -3125,3 +3243,4 @@ Script_unknown0xa9: ; 0x97c15 ld [$c2dd], a ret ; 0x97c20 + From 0988d69d9dfbf29a7866b52264107d8995465f1a Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 4 Jul 2013 05:37:20 -0400 Subject: [PATCH 11/13] more scripting cleanup --- engine/scripting.asm | 104 +++++++++++++++++++++---------------------- wram.asm | 18 +++++++- 2 files changed, 67 insertions(+), 55 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index b4f5916f4..f9ede0041 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -171,21 +171,21 @@ ScriptCommandTable: ; 0x96cb1 dw Script_unknown0xa9 ; 0x96e05 -Unknown_0x96e05: ; 0x96e05 - ld hl, $d434 - set 2, [hl] +StartScript: ; 0x96e05 + ld hl, ScriptFlags + set SCRIPT_RUNNING, [hl] ret ; 0x96e0b -Unknown_0x96e0b: ; 0x96e0b - ld hl, $d434 - bit 2, [hl] +CheckScript: ; 0x96e0b + ld hl, ScriptFlags + bit SCRIPT_RUNNING, [hl] ret ; 0x96e11 -Unknown_0x96e11: ; 0x96e11 - ld hl, $d434 - res 2, [hl] +StopScript: ; 0x96e11 + ld hl, ScriptFlags + res SCRIPT_RUNNING, [hl] ret ; 0x96e17 @@ -877,7 +877,7 @@ Script_talkaftercancel: ; 0x97163 ld a, [$d04d] and a ret z - jp $7b74 + jp Script_end ; 0x9716b Script_talkaftercheck: ; 0x9716b @@ -1038,9 +1038,9 @@ Script_applymovement: ; 0x971f3 ld b, a call $26c7 ret c - ld a, $2 - ld [$d437], a - call Unknown_0x96e11 + ld a, SCRIPT_WAIT_MOVEMENT + ld [ScriptMode], a + call StopScript ret ; 0x97221 @@ -1375,7 +1375,7 @@ Script_showemote: ; 0x97396 ld [$ffe0], a .asm_973a8 call GetScriptByte - ld [$d44d], a + ld [ScriptDelay], a ld b, BANK(ShowEmoteScript) ld de, ShowEmoteScript jp ScriptCall @@ -1559,7 +1559,7 @@ Script_reloadmap: ; 0x97491 ld [$ff9f], a ld a, $1 call $261b - call Unknown_0x96e11 + call StopScript ret ; 0x974a2 @@ -1826,7 +1826,7 @@ Script_priorityjump: ; 0x975aa ld [$d44f], a call GetScriptByte ld [$d450], a - ld hl, $d434 + ld hl, ScriptFlags set 3, [hl] ret ; 0x975c2 @@ -2833,7 +2833,7 @@ Script_warp: ; 0x97a1d ld [$ff9f], a ld a, $1 call $261b - call Unknown_0x96e11 + call StopScript ret .asm_97a4a call GetScriptByte @@ -2845,7 +2845,7 @@ Script_warp: ; 0x97a1d ld [$ff9f], a ld a, $1 call $261b - call Unknown_0x96e11 + call StopScript ret ; 0x97a65 @@ -2998,7 +2998,7 @@ Script_newloadmap: ; 0x97b08 ld [$ff9f], a ld a, $1 call $261b - call Unknown_0x96e11 + call StopScript ret ; 0x97b16 @@ -3006,7 +3006,7 @@ Script_reloadandreturn: ; 0x97b16 ; script command 0x92 call $7b08 - jp $7b74 + jp Script_end ; 0x97b1c Script_loadfont: ; 0x97b1c @@ -3074,11 +3074,11 @@ Script_pause: ; 0x97b47 call GetScriptByte and a jr z, .asm_97b50 ; 0x97b4b $3 - ld [$d44d], a + ld [ScriptDelay], a .asm_97b50 - ld c, $2 + ld c, 2 call DelayFrames - ld hl, $d44d + ld hl, ScriptDelay dec [hl] jr nz, .asm_97b50 ; 0x97b59 $f5 ret @@ -3092,11 +3092,11 @@ Script_deactivatefacing: ; 0x97b5c call GetScriptByte and a jr z, .asm_97b65 ; 0x97b60 $3 - ld [$d44d], a + ld [ScriptDelay], a .asm_97b65 - ld a, $3 - ld [$d437], a - call Unknown_0x96e11 + ld a, SCRIPT_WAIT + ld [ScriptMode], a + call StopScript ret ; 0x97b6e @@ -3105,40 +3105,42 @@ Script_ptpriorityjump: ; 0x97b6e ; parameters: ; pointer (ScriptPointerLabelParam) - call Unknown_0x96e11 + call StopScript jp Script_2jump ; 0x97b74 Script_end: ; 0x97b74 ; script command 0x91 - call $7b9a - jr c, .asm_97b7a ; 0x97b77 $1 + call ExitScriptSubroutine + jr c, .asm_97b7a ret .asm_97b7a xor a ld [ScriptRunning], a - ld a, $0 - ld [$d437], a - ld hl, $d434 + ld a, SCRIPT_OFF + ld [ScriptMode], a + ld hl, ScriptFlags res 0, [hl] - call Unknown_0x96e11 + call StopScript ret ; 0x97b8c Script_return: ; 0x97b8c ; script command 0x90 - call $7b9a - jr c, .asm_97b91 ; 0x97b8f $0 + call ExitScriptSubroutine + jr c, .asm_97b91 .asm_97b91 - ld hl, $d434 + ld hl, ScriptFlags res 0, [hl] - call Unknown_0x96e11 + call StopScript ret ; 0x97b9a -Unknown_0x97b9a: ; 0x97b9a +ExitScriptSubroutine: ; 0x97b9a +; Return carry if there's no parent to return to. + ld hl, $d43c ld a, [hl] and a @@ -3173,11 +3175,11 @@ Script_resetfuncs: ; 0x97bc0 xor a ld [$d43c], a ld [ScriptRunning], a - ld a, $0 - ld [$d437], a - ld hl, $d434 + ld a, SCRIPT_OFF + ld [ScriptMode], a + ld hl, ScriptFlags res 0, [hl] - call Unknown_0x96e11 + call StopScript ret ; 0x97bd5 @@ -3186,15 +3188,9 @@ Script_halloffame: ; 0x97bd5 ld hl, $cfbc res 0, [hl] - ld a, BANK(HallOfFame1) - ld hl, HallOfFame1 - rst $8 - ld a, BANK(HallOfFame2) - ld hl, HallOfFame2 - rst $8 - ld a, BANK(HallOfFame3) - ld hl, HallOfFame3 - rst $8 + callba HallOfFame1 + callba HallOfFame2 + callba HallOfFame3 ld hl, $cfbc set 0, [hl] jr DisplayCredits @@ -3211,7 +3207,7 @@ DisplayCredits: call $7bc0 ld a, $3 call $261b - call Unknown_0x96e11 + call StopScript ret ; 0x97c05 @@ -3224,7 +3220,7 @@ Script_unknown0xa8: ; 0x97c05 call GetScriptByte .asm_97c09 push af - ld c, $6 + ld c, 6 call DelayFrames pop af dec a diff --git a/wram.asm b/wram.asm index 8d6c88bc1..2d4028da4 100644 --- a/wram.asm +++ b/wram.asm @@ -1526,8 +1526,19 @@ OTPartyMon5Nickname: ; d416 OTPartyMon6Nickname: ; d421 ds 11 -SECTION "Scripting",BSS[$d438] +SECTION "Scripting",BSS[$d434] +ScriptFlags: ; d434 +SCRIPT_RUNNING EQU 2 + ds 1 + ds 2 + +ScriptMode: ; d437 +SCRIPT_OFF EQU 0 +SCRIPT_READ EQU 1 +SCRIPT_WAIT_MOVEMENT EQU 2 +SCRIPT_WAIT EQU 3 + ds 1 ScriptRunning: ; d438 ds 1 ScriptBank: ; d439 @@ -1535,6 +1546,11 @@ ScriptBank: ; d439 ScriptPos: ; d43a ds 2 + ds 17 + +ScriptDelay: ; d44d + ds 1 + SECTION "Player",BSS[$d472] PlayerGender: ; d472 ; bit 0: From 37c009ca1c1bd510b050e9801d3d3311cb552aba Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 4 Jul 2013 05:37:48 -0400 Subject: [PATCH 12/13] player/script events --- main.asm | 539 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 508 insertions(+), 31 deletions(-) diff --git a/main.asm b/main.asm index ca8db3006..b6db7d426 100644 --- a/main.asm +++ b/main.asm @@ -2192,7 +2192,35 @@ CheckWaterfallTile: ; 18bd ret ; 18c3 -INCBIN "baserom.gbc", $18c3, $1c07 - $18c3 + +INCBIN "baserom.gbc", $18c3, $18d2 - $18c3 + + +GetMapObject: ; 18d2 +; Return the location of map object a in bc. + ld hl, MapObjects + ld bc, $10 + call AddNTimes + ld b, h + ld c, l + ret +; 18de + + +INCBIN "baserom.gbc", $18de, $1b07 - $18de + + +GetSpriteDirection: ; 1b07 + ld hl, $0008 + add hl, bc + ld a, [hl] + and %00001100 + ret +; 1b0f + + +INCBIN "baserom.gbc", $1b0f, $1c07 - $1b0f + Function1c07: ; 0x1c07 push af @@ -2746,29 +2774,25 @@ INCBIN "baserom.gbc", $261b, $261f - $261b PushScriptPointer: ; 261f -; used to call a script from asm -; input: -; a: bank -; hl: address +; Call a script at a:hl. -; bank - ld [$d439], a ; ScriptBank - -; address + ld [ScriptBank], a ld a, l - ld [$d43a], a ; ScriptAddressLo + ld [ScriptPos], a ld a, h - ld [$d43b], a ; ScriptAddressHi + ld [ScriptPos + 1], a ld a, $ff - ld [$d438], a + ld [ScriptRunning], a scf ret ; 2631 + INCBIN "baserom.gbc", $2631, $26d4 - $2631 + GetScriptByte: ; 0x26d4 ; Return byte at ScriptBank:ScriptPos in a. @@ -4400,7 +4424,223 @@ GetMoveName: ; 34f8 ; 350c -INCBIN "baserom.gbc", $350c, $3856 - $350c +INCBIN "baserom.gbc", $350c, $3600 - $350c + + +CheckTrainerBattle2: ; 3600 + + ld a, [hROMBank] + push af + call $2c52 + + call CheckTrainerBattle + + pop bc + ld a, b + rst Bankswitch + ret +; 360d + + +CheckTrainerBattle: ; 360d +; Check if any trainer on the map sees the player and wants to battle. + +; Skip the player object. + ld a, 1 + ld de, MapObjects + OBJECT_LENGTH + +.loop + +; Start a battle if the object: + + push af + push de + +; Has a sprite + ld hl, $0001 + add hl, de + ld a, [hl] + and a + jr z, .next + +; Is a trainer + ld hl, $0008 + add hl, de + ld a, [hl] + and $f + cp $2 + jr nz, .next + +; Is visible on the map + ld hl, $0000 + add hl, de + ld a, [hl] + cp $ff + jr z, .next + +; Is facing the player... + call $1ae5 + call FacingPlayerDistance_bc + jr nc, .next + +; ...within their sight range + ld hl, $0009 + add hl, de + ld a, [hl] + cp b + jr c, .next + +; And hasn't already been beaten + push bc + push de + ld hl, $000a + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld e, [hl] + inc hl + ld d, [hl] + ld b, CHECK_FLAG + call BitTable1Func + ld a, c + pop de + pop bc + and a + jr z, .asm_3666 + +.next + pop de + ld hl, OBJECT_LENGTH + add hl, de + ld d, h + ld e, l + + pop af + inc a + cp NUM_OBJECTS + jr nz, .loop + xor a + ret + +.asm_3666 + pop de + pop af + ld [$ffe0], a + ld a, b + ld [$d03f], a + ld a, c + ld [$d040], a + jr .asm_367e + + ld a, $1 + ld [$d03f], a + ld a, $ff + ld [$d040], a + +.asm_367e + call $2c57 + ld [EngineBuffer1], a + ld a, [$ffe0] + call GetMapObject + ld hl, $000a + add hl, bc + ld a, [EngineBuffer1] + call GetFarHalfword + ld de, $d041 + ld bc, $000d + ld a, [EngineBuffer1] + call FarCopyBytes + xor a + ld [$d04d], a + scf + ret +; 36a5d + + +FacingPlayerDistance_bc: ; 36a5 + + push de + call FacingPlayerDistance + ld b, d + ld c, e + pop de + ret +; 36ad + + +FacingPlayerDistance: ; 36ad +; Return carry if the sprite at bc is facing the player, +; and its distance in d. + + ld hl, $0010 ; x + add hl, bc + ld d, [hl] + + ld hl, $0011 ; y + add hl, bc + ld e, [hl] + + ld a, [MapX] + cp d + jr z, .CheckY + + ld a, [MapY] + cp e + jr z, .CheckX + + and a + ret + +.CheckY + ld a, [MapY] + sub e + jr z, .NotFacing + jr nc, .Above + +; Below + cpl + inc a + ld d, a + ld e, UP << 2 + jr .CheckFacing + +.Above + ld d, a + ld e, DOWN << 2 + jr .CheckFacing + +.CheckX + ld a, [MapX] + sub d + jr z, .NotFacing + jr nc, .Left + +; Right + cpl + inc a + ld d, a + ld e, LEFT << 2 + jr .CheckFacing + +.Left + ld d, a + ld e, RIGHT << 2 + +.CheckFacing + call GetSpriteDirection + cp e + jr nz, .NotFacing + scf + ret + +.NotFacing + and a + ret +; 36f5 + + +INCBIN "baserom.gbc", $36f5, $3856 - $36f5 GetBaseData: ; 3856 @@ -16833,31 +17073,202 @@ INCLUDE "maps/map_headers.asm" INCLUDE "maps/second_map_headers.asm" -INCBIN "baserom.gbc", $966b0, $96974 - $966b0 +INCBIN "baserom.gbc", $966b0, $96795 - $966b0 +DoEvents: ; 96795 + ld a, [$d433] + ld hl, .pointers + rst $28 + ret +; 9679d -; 96974 - call CheckPlayerMovement - ret c +.pointers + dw Function967a1 + dw Function967ae + +Function967a1: ; 967a1 + call PlayerEvents + call $66cb + callba ScriptEvents + ret +; 967ae + +Function967ae: ; 967ae + ret +; 967af + + +INCBIN "baserom.gbc", $967af, $9681f - $967af + + +PlayerEvents: ; 9681f + +; Reset carry. + xor a + + ld a, [ScriptRunning] and a - jr nz, .asm_9698d + ret nz -; Can't perform button actions while sliding on ice. - callba Function80404 - jr c, .asm_9698d + call $68e4 - call CheckAPressOW - jr c, .asm_9698f + call CheckTrainerBattle3 + jr c, .asm_96848 - call CheckMenuOW - jr c, .asm_9698f + call CheckTileEvent + jr c, .asm_96848 + + call $7c30 + jr c, .asm_96848 + + call $68ec + jr c, .asm_96848 + + call $693a + jr c, .asm_96848 + + call OWPlayerInput + jr c, .asm_96848 -.asm_9698d xor a ret -.asm_9698f + +.asm_96848 + push af + ld a, $25 + ld hl, $6c56 + rst FarCall + pop af + + ld [ScriptRunning], a + call $6beb + ld a, [ScriptRunning] + cp 4 + jr z, .asm_96865 + cp 9 + jr z, .asm_96865 + + xor a + ld [$c2da], a + +.asm_96865 + scf + ret +; 96867 + + +CheckTrainerBattle3: ; 96867 + nop + nop + call CheckTrainerBattle2 + jr nc, .asm_96872 + ld a, 1 + scf + ret + +.asm_96872 + xor a + ret +; 96874 + + +CheckTileEvent: ; 96874 +; Check for warps, tile triggers or wild battles. + + call $670c + jr z, .asm_96886 + + ld a, $41 + ld hl, $4820 + rst FarCall + jr c, .asm_968a6 + + call $2238 + jr c, .asm_968aa + +.asm_96886 + call $6712 + jr z, .asm_96890 + + call $2ad4 + jr c, .asm_968ba + +.asm_96890 + call $6718 + jr z, .asm_96899 + + call $6b79 + ret c + +.asm_96899 + call $671e + jr z, .asm_968a4 + + call $7cc0 + ret c + + jr .asm_968a4 + +.asm_968a4 + xor a + ret + +.asm_968a6 + ld a, 4 + scf + ret + +.asm_968aa + ld a, [StandingTile] + call $18a6 + jr nz, .asm_968b6 + ld a, 6 + scf + ret + +.asm_968b6 + ld a, 5 + scf + ret + +.asm_968ba + ld hl, MovementAnimation + ld a, [hli] + ld h, [hl] + ld l, a + call $2c57 + call PushScriptPointer + ret +; 968c7 + + +INCBIN "baserom.gbc", $968c7, $96974 - $968c7 + + +OWPlayerInput: ; 96974 + + call PlayerMovement + ret c + and a + jr nz, .NoAction + +; Can't perform button actions while sliding on ice. + callba Function80404 + jr c, .NoAction + + call CheckAPressOW + jr c, .Action + + call CheckMenuOW + jr c, .Action + +.NoAction + xor a + ret + +.Action push af callba Function80422 pop af @@ -16906,7 +17317,7 @@ TryObjectEvent: ; 969b5 ld [$ffe0], a ld a, [$ffe0] - call $18d2 + call GetMapObject ld hl, $0008 add hl, bc ld a, [hl] @@ -17120,7 +17531,7 @@ CheckSignFlag: ; 96ad8 ; 96af0 -CheckPlayerMovement: ; 96af0 +PlayerMovement: ; 96af0 callba DoPlayerMovement ld a, c ld hl, .pointers @@ -17247,12 +17658,78 @@ SelectMenuCallback: ; 96b66 ; 96b79 -INCBIN "baserom.gbc", $96b79, $96cb1 - $96b79 +INCBIN "baserom.gbc", $96b79, $96c5e - $96b79 + + +ScriptEvents: ; 96c5e + call StartScript +.loop + ld a, [ScriptMode] + ld hl, .modes + rst $28 + call CheckScript + jr nz, .loop + ret +; 96c6e + +.modes ; 96c6e + dw EndScript + dw RunScriptCommand + dw WaitScriptMovement + dw WaitScript + +EndScript: ; 96c76 + call StopScript + ret +; 96c7a + +WaitScript: ; 96c7a + call StopScript + + ld hl, ScriptDelay + dec [hl] + ret nz + + ld a, $1 + ld hl, $58b9 + rst FarCall + + ld a, SCRIPT_READ + ld [ScriptMode], a + call StartScript + ret +; 96c91 + +WaitScriptMovement: ; 96c91 + call StopScript + + ld hl, VramState + bit 7, [hl] + ret nz + + ld a, $1 + ld hl, $58b9 + rst FarCall + + ld a, SCRIPT_READ + ld [ScriptMode], a + call StartScript + ret +; 96ca9 + +RunScriptCommand: ; 96ca9 + call GetScriptByte + ld hl, ScriptCommandTable + rst $28 + ret +; 96cb1 INCLUDE "engine/scripting.asm" -INCBIN "baserom.gbc", $97c20, $35e + +INCBIN "baserom.gbc", $97c20, $97f7e - $97c20 + SECTION "bank26",DATA,BANK[$26] From 90c18c5cf320be70b0507deda0dd7611052f2bec Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 4 Jul 2013 15:42:01 -0400 Subject: [PATCH 13/13] rst $28 -> JumpTable --- battle/effect_commands.asm | 2 +- constants.asm | 3 ++- main.asm | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/battle/effect_commands.asm b/battle/effect_commands.asm index 2336c524a..4372dacba 100644 --- a/battle/effect_commands.asm +++ b/battle/effect_commands.asm @@ -6796,7 +6796,7 @@ BattleCommandac: ; 3658f ; jump dec a ld hl, .ptrs - rst $28 + rst JumpTable ret .ptrs dw BattleCommand19 ; paralyze diff --git a/constants.asm b/constants.asm index 9cece6daa..c1a0ec0dc 100644 --- a/constants.asm +++ b/constants.asm @@ -16,9 +16,10 @@ INCLUDE "constants/script_constants.asm" INCLUDE "constants/music_constants.asm" -; rst vectors +; macros require rst vectors to be defined FarCall EQU $08 Bankswitch EQU $10 +JumpTable EQU $28 dwb: MACRO diff --git a/main.asm b/main.asm index b6db7d426..88a3e193d 100644 --- a/main.asm +++ b/main.asm @@ -7181,7 +7181,7 @@ _DoItemEffect: ; e722 ld a, [CurItem] dec a ld hl, ItemEffects - rst $28 + rst JumpTable ret ; e73c @@ -8558,7 +8558,7 @@ CheckRegisteredItem: ; 13345 rlca rlca ld hl, .Pockets - rst $28 + rst JumpTable ret .Pockets @@ -8652,7 +8652,7 @@ UseRegisteredItem: ; 133c3 callba CheckItemMenu ld a, [$d142] ld hl, .SwitchTo - rst $28 + rst JumpTable ret .SwitchTo @@ -9068,7 +9068,7 @@ Function158cc: ; 0x158cc rst $8 ld a, [$d142] ld hl, JumpTable158e7 - rst $28 + rst JumpTable pop af ld [$c2ce], a ret @@ -12295,7 +12295,7 @@ Function4484a: ; 0x4484a ld a, [$cfa9] dec a ld hl, $4861 - rst $28 + rst JumpTable .asm_44860 ret @@ -13415,7 +13415,7 @@ StatsScreenMain: ; 0x4dcd2 ld a, [$cf63] and $7f ld hl, StatsScreenPointerTable - rst $28 + rst JumpTable call $5d3a ; check for keys? ld a, [$cf63] bit 7, a @@ -13565,7 +13565,7 @@ WritePartyMenuTilemap: ; 0x5005f jr z, .asm_50084 ; 0x5007a $8 push hl ld hl, $4089 - rst $28 + rst JumpTable pop hl jr .asm_50077 ; 0x50082 $f3 .asm_50084 @@ -17079,7 +17079,7 @@ INCBIN "baserom.gbc", $966b0, $96795 - $966b0 DoEvents: ; 96795 ld a, [$d433] ld hl, .pointers - rst $28 + rst JumpTable ret ; 9679d @@ -17416,7 +17416,7 @@ TryReadSign: ; 96a38 .IsSign ld a, [$d040] ld hl, .signs - rst $28 + rst JumpTable ret .signs @@ -17535,7 +17535,7 @@ PlayerMovement: ; 96af0 callba DoPlayerMovement ld a, c ld hl, .pointers - rst $28 + rst JumpTable ld a, c ret ; 96afd @@ -17666,7 +17666,7 @@ ScriptEvents: ; 96c5e .loop ld a, [ScriptMode] ld hl, .modes - rst $28 + rst JumpTable call CheckScript jr nz, .loop ret @@ -17720,7 +17720,7 @@ WaitScriptMovement: ; 96c91 RunScriptCommand: ; 96ca9 call GetScriptByte ld hl, ScriptCommandTable - rst $28 + rst JumpTable ret ; 96cb1