summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rwxr-xr-xengine/events/overworld.asm103
-rwxr-xr-xengine/items/inventory.asm41
-rwxr-xr-xengine/overworld/spawn_points.asm60
-rwxr-xr-xengine/smallflag.asm72
4 files changed, 265 insertions, 11 deletions
diff --git a/engine/events/overworld.asm b/engine/events/overworld.asm
new file mode 100755
index 0000000..a5b4553
--- /dev/null
+++ b/engine/events/overworld.asm
@@ -0,0 +1,103 @@
+INCLUDE "constants.asm"
+
+SECTION "TeleportFunction", ROMX[$52db], BANK[$03]
+
+; Sets wFieldMoveSucceeded to $f if successful, $0 if not
+TeleportFunction: ; 03:52db
+ xor a
+ ld [wFieldMoveScriptID], a
+.loop
+ ld a, [wFieldMoveScriptID]
+ bit SCRIPT_FINISHED, a
+ jr nz, .finish
+ ld hl, .JumpTable
+ call CallJumptable
+ jr .loop
+
+; Finish by returning only the low nibble
+.finish
+ and $FF - SCRIPT_FINISHED_MASK
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.JumpTable
+ dw .TryTeleport
+ dw .DoTeleport
+ dw .FailTeleport
+ dw .CheckIfSpawnPoint
+
+.TryTeleport: ; 03:52fc
+ call GetMapEnvironment
+ cp TOWN
+ jr z, .success
+ cp ROUTE
+ jr z, .success
+ ld a, SCRIPT_ID_02
+ ld [wFieldMoveScriptID], a
+ ret
+.success
+ ld a, SCRIPT_ID_03
+ ld [wFieldMoveScriptID], a
+ ret
+
+.CheckIfSpawnPoint ; 03:5313
+ ld a, [wLastSpawnMapGroup]
+ ld d, a
+ ld a, [wLastSpawnMapNumber]
+ ld e, a
+ callab IsSpawnPoint
+ jr c, .not_spawn
+ ld hl, .Text_CantFindDestination
+ call MenuTextBoxBackup
+ ld a, SCRIPT_FAIL
+ ld [wFieldMoveScriptID], a
+ ret
+.not_spawn
+ ld a, c
+ ld [wDefaultSpawnpoint], a
+ ld a, SCRIPT_ID_01
+ ld [wFieldMoveScriptID], a
+ ret
+
+.Text_CantFindDestination: ; 03:533B
+ text "とびさきが みつかりません"
+ para
+ done
+
+.DoTeleport: ; 03:534b
+ ldh a, [hROMBank]
+ ld hl, .TeleportScript
+ call QueueScript
+ ld a, SCRIPT_SUCCESS
+ ld [wFieldMoveScriptID], a
+ ret
+
+.FailTeleport: ; 03:5359
+ ld hl, .Text_CantUseHere
+ call MenuTextBoxBackup
+ ld a, SCRIPT_FAIL
+ ld [wFieldMoveScriptID], a
+ scf
+ ret
+
+.Text_CantUseHere: ; 03:5366
+ text "ここでは つかえません!"
+ para
+ done
+
+.TeleportScript: ; 03:5375
+ call RefreshScreen
+ ld hl, .Text_ReturnToLastMonCenter
+ call MenuTextBox
+ ld c, 60
+ call DelayFrames
+ call CloseWindow
+ call Function1fea
+ ld a, MAPSETUP_TELEPORT
+ ldh [hMapEntryMethod], a
+ jpab Functionfcc24
+
+.Text_ReturnToLastMonCenter: ; 03:5395
+ text "さいごに たちよった"
+ line "#センターにもどります"
+ done \ No newline at end of file
diff --git a/engine/items/inventory.asm b/engine/items/inventory.asm
index 4a95bac..9c5a1ec 100755
--- a/engine/items/inventory.asm
+++ b/engine/items/inventory.asm
@@ -6,9 +6,7 @@ _ReceiveItem: ; 03:4AA1
call DoesHLEqualwNumBagItems
jp nz, PutItemInPocket
push hl
- ld hl, CheckItemPocket
- ld a, BANK(CheckItemPocket)
- call FarCall_hl
+ callab CheckItemPocket
ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
@@ -47,9 +45,7 @@ _TossItem: ; 03:4AE0
call DoesHLEqualwNumBagItems
jr nz, .remove_item
push hl
- ld hl, CheckItemPocket
- ld a, BANK(CheckItemPocket)
- call FarCall_hl
+ callab CheckItemPocket
ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
@@ -90,9 +86,7 @@ _CheckItem: ; 03:4B1E
call DoesHLEqualwNumBagItems
jr nz, .not_bag
push hl
- ld hl, CheckItemPocket
- ld a, BANK(CheckItemPocket)
- call FarCall_hl
+ callab CheckItemPocket
ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
@@ -570,10 +564,34 @@ GetTMHMNumber: ; 03:4CFF
.not_machine
and a
ret
+
+GetNumberedTMHM: ; 03:4D1A
+; Return the item id of a TM/HM by number c.
+ ld a, c
+ ld c, 0
+; Adjust for any dummy items.
+ cp ITEM_C8 - ITEM_TM01 ; TM01-04
+ jr c, .finish
+ inc c
+ cp ITEM_E1 - ITEM_TM01 - 1 ; TM05-28
+ jr c, .finish
+ inc c
+ cp ITEM_FF - ITEM_TM01 - 2 ; End of list
+ jr nc, .not_machine
+.finish
+ add c
+ add ITEM_TM01
+ ld c, a
+ scf
+ ret
+.not_machine
+ and a
+ ret
SECTION "_CheckTossableItem", ROMX[$53AD], BANK[$03]
-; Return 1 in wItemAttributeParamBuffer and carry if wCurItem can't be removed from the bag.
+; Return 1 in wItemAttributeParamBuffer and
+; carry if wCurItem can't be removed from the bag.
_CheckTossableItem: ; 03:53AD
ld a, ITEMATTR_PERMISSIONS
call GetItemAttr
@@ -582,7 +600,8 @@ _CheckTossableItem: ; 03:53AD
and a
ret
-; Return 1 in wItemAttributeParamBuffer and carry if wCurItem can't be selected.
+; Return 1 in wItemAttributeParamBuffer
+; and carry if wCurItem can't be selected.
CheckSelectableItem: ; 03:53B8
ld a, ITEMATTR_PERMISSIONS
call GetItemAttr
diff --git a/engine/overworld/spawn_points.asm b/engine/overworld/spawn_points.asm
new file mode 100755
index 0000000..81b04b0
--- /dev/null
+++ b/engine/overworld/spawn_points.asm
@@ -0,0 +1,60 @@
+INCLUDE "constants.asm"
+
+SECTION "LoadSpawnPoint", ROMX[$4791], BANK[$03]
+
+LoadSpawnPoint: ; 03:4791
+; loads the spawn point in wDefaultSpawnpoint
+ push hl
+ push de
+ ld a, [wDefaultSpawnpoint]
+ and a
+ jr z, .skip
+ dec a
+ ld l, a
+ ld h, 0
+ add hl, hl
+ add hl, hl
+ ld de, SpawnPoints
+ add hl, de
+ ld a, [hli]
+ ld [wMapGroup], a
+ ld a, [hli]
+ ld [wMapId], a
+ ld a, [hli]
+ ld [wXCoord], a
+ ld a, [hli]
+ ld [wYCoord], a
+.skip
+ pop de
+ pop hl
+ ret
+
+IsSpawnPoint: ; 03:47b6
+; Checks if the map loaded in de is a spawn point.
+; Returns carry if it's a spawn point.
+ ld hl, SpawnPoints
+ ld c, 1
+.loop
+ ld a, [hl]
+ cp SPAWN_N_A
+ jr z, .fail
+ cp d
+ jr nz, .next
+ inc hl
+ ld a, [hld]
+ cp e
+ jr z, .succeed
+.next
+ push bc
+ ld bc, SPAWN_POINT_SIZE
+ add hl, bc
+ pop bc
+ inc c
+ jr .loop
+.fail
+ and a
+ ret
+.succeed
+ scf
+ ret
+
diff --git a/engine/smallflag.asm b/engine/smallflag.asm
new file mode 100755
index 0000000..dfce475
--- /dev/null
+++ b/engine/smallflag.asm
@@ -0,0 +1,72 @@
+SECTION "SmallFarFlagAction", ROMX[$4d33], BANK[$03]
+
+SmallFarFlagAction: ; 03:4d33
+; Perform action b on bit c in flag array hl.
+; If checking a flag, check flag array d:hl unless d is 0.
+
+; For longer flag arrays, see FlagAction.
+
+ push hl
+ push bc
+
+; Divide by 8 to get the byte we want.
+ push bc
+ srl c
+ srl c
+ srl c
+ ld b, 0
+ add hl, bc
+ pop bc
+
+; Which bit we want from the byte
+ ld a, c
+ and 7
+ ld c, a
+
+; Shift left until we can mask the bit
+ ld a, 1
+ jr z, .shifted
+.shift
+ add a
+ dec c
+ jr nz, .shift
+.shifted
+ ld c, a
+
+; What are we doing to this flag?
+ dec b
+ jr z, .set ; 1
+ dec b
+ jr z, .check ; 2
+
+.reset
+ ld a, c
+ cpl
+ and [hl]
+ ld [hl], a
+ jr .done
+
+.set
+ ld a, [hl]
+ or c
+ ld [hl], a
+ jr .done
+
+.check
+ ld a, d
+ cp 0
+ jr nz, .farcheck
+
+ ld a, [hl]
+ and c
+ jr .done
+
+.farcheck
+ call GetFarByte
+ and c
+
+.done
+ pop bc
+ pop hl
+ ld c, a
+ ret \ No newline at end of file