Organize the engine/ directory, take 2

Renamed `game` to `games` and `menu` to `menus`.
Moved some functions from `engine/routines/` to their fitting subdirectories.

Made two new subdirectories:
* engine/rtc: Contains all RTC-related things. Menus, hardware, misc
functions.
* engine/items: Contains all item-related things. Pack, item effects,
other item handlers.
This commit is contained in:
mid-kid
2018-03-14 13:28:36 +01:00
parent baa0dc5a96
commit 97c511cd2f
37 changed files with 36 additions and 36 deletions

235
engine/items/buy_sell_toss.asm Executable file
View File

@@ -0,0 +1,235 @@
SelectQuantityToToss: ; 24fbf
ld hl, TossItem_MenuHeader
call LoadMenuHeader
call Toss_Sell_Loop
ret
; 24fc9
SelectQuantityToBuy: ; 24fc9
farcall GetItemPrice
RooftopSale_SelectQuantityToBuy: ; 24fcf
ld a, d
ld [wBuffer1], a
ld a, e
ld [wBuffer2], a
ld hl, BuyItem_MenuHeader
call LoadMenuHeader
call Toss_Sell_Loop
ret
; 24fe1
SelectQuantityToSell: ; 24fe1
farcall GetItemPrice
ld a, d
ld [wBuffer1], a
ld a, e
ld [wBuffer2], a
ld hl, SellItem_MenuHeader
call LoadMenuHeader
call Toss_Sell_Loop
ret
; 24ff9
Toss_Sell_Loop: ; 24ff9
ld a, 1
ld [wItemQuantityChangeBuffer], a
.loop
call BuySellToss_UpdateQuantityDisplay ; update display
call BuySellToss_InterpretJoypad ; joy action
jr nc, .loop
cp -1
jr nz, .nope ; pressed B
scf
ret
.nope
and a
ret
; 2500e
BuySellToss_InterpretJoypad: ; 2500e
call JoyTextDelay_ForcehJoyDown ; get joypad
bit B_BUTTON_F, c
jr nz, .b
bit A_BUTTON_F, c
jr nz, .a
bit D_DOWN_F, c
jr nz, .down
bit D_UP_F, c
jr nz, .up
bit D_LEFT_F, c
jr nz, .left
bit D_RIGHT_F, c
jr nz, .right
and a
ret
.b
ld a, -1
scf
ret
.a
ld a, 0
scf
ret
.down
ld hl, wItemQuantityChangeBuffer
dec [hl]
jr nz, .finish_down
ld a, [wItemQuantityBuffer]
ld [hl], a
.finish_down
and a
ret
.up
ld hl, wItemQuantityChangeBuffer
inc [hl]
ld a, [wItemQuantityBuffer]
cp [hl]
jr nc, .finish_up
ld [hl], 1
.finish_up
and a
ret
.left
ld a, [wItemQuantityChangeBuffer]
sub 10
jr c, .load_1
jr z, .load_1
jr .finish_left
.load_1
ld a, 1
.finish_left
ld [wItemQuantityChangeBuffer], a
and a
ret
.right
ld a, [wItemQuantityChangeBuffer]
add 10
ld b, a
ld a, [wItemQuantityBuffer]
cp b
jr nc, .finish_right
ld b, a
.finish_right
ld a, b
ld [wItemQuantityChangeBuffer], a
and a
ret
; 25072
BuySellToss_UpdateQuantityDisplay: ; 25072
call MenuBox
call MenuBoxCoord2Tile
ld de, SCREEN_WIDTH + 1
add hl, de
ld [hl], "×"
inc hl
ld de, wItemQuantityChangeBuffer
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
ld a, [wMenuDataPointer]
ld e, a
ld a, [wMenuDataPointer + 1]
ld d, a
ld a, [wMenuDataBank]
call FarCall_de
ret
; 25097
ret_25097: ; 25097
ret
; 25098
DisplayPurchasePrice: ; 25098
call BuySell_MultiplyPrice
call BuySell_DisplaySubtotal
ret
; 2509f
DisplaySellingPrice: ; 2509f
call BuySell_MultiplyPrice
call Sell_HalvePrice
call BuySell_DisplaySubtotal
ret
; 250a9
BuySell_MultiplyPrice: ; 250a9
xor a
ld [hMultiplicand + 0], a
ld a, [wBuffer1]
ld [hMultiplicand + 1], a
ld a, [wBuffer2]
ld [hMultiplicand + 2], a
ld a, [wItemQuantityChangeBuffer]
ld [hMultiplier], a
push hl
call Multiply
pop hl
ret
; 250c1
Sell_HalvePrice: ; 250c1
push hl
ld hl, hProduct + 1
ld a, [hl]
srl a
ld [hli], a
ld a, [hl]
rra
ld [hli], a
ld a, [hl]
rra
ld [hl], a
pop hl
ret
; 250d1
BuySell_DisplaySubtotal: ; 250d1
push hl
ld hl, hMoneyTemp
ld a, [hProduct + 1]
ld [hli], a
ld a, [hProduct + 2]
ld [hli], a
ld a, [hProduct + 3]
ld [hl], a
pop hl
inc hl
ld de, hMoneyTemp
lb bc, PRINTNUM_MONEY | 3, 6
call PrintNum
call WaitBGMap
ret
; 250ed
TossItem_MenuHeader: ; 0x250ed
db MENU_BACKUP_TILES ; flags
menu_coords 15, 9, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw ret_25097
db 0 ; default option
; 0x250f5
BuyItem_MenuHeader: ; 0x250f5
db MENU_BACKUP_TILES ; flags
menu_coords 7, 15, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw DisplayPurchasePrice
db -1 ; default option
; 0x250fd
SellItem_MenuHeader: ; 0x250fd
db MENU_BACKUP_TILES ; flags
menu_coords 7, 15, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw DisplaySellingPrice
db 0 ; default option
; 0x25105

File diff suppressed because it is too large Load Diff

581
engine/items/items.asm Executable file

File diff suppressed because it is too large Load Diff

970
engine/items/mart.asm Executable file

File diff suppressed because it is too large Load Diff

1711
engine/items/pack.asm Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,31 @@
PrintItemDescription: ; 0x1c8955
; Print the description for item [wCurSpecies] at de.
ld a, [wCurSpecies]
cp TM01
jr c, .not_a_tm
ld [wCurItem], a
push de
farcall GetTMHMItemMove
pop hl
ld a, [wd265]
ld [wCurSpecies], a
predef PrintMoveDesc
ret
.not_a_tm
push de
ld hl, ItemDescriptions
ld a, [wCurSpecies]
dec a
ld c, a
ld b, 0
add hl, bc
add hl, bc
ld e, [hl]
inc hl
ld d, [hl]
pop hl
jp PlaceString
; 0x1c8987

274
engine/items/switch_items.asm Executable file
View File

@@ -0,0 +1,274 @@
SwitchItemsInBag: ; 2490c (9:490c)
ld a, [wSwitchItem]
and a
jr z, .init
ld b, a
ld a, [wScrollingMenuCursorPosition]
inc a
cp b
jr z, .trivial
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
ld a, [hl]
cp -1
ret z
ld a, [wSwitchItem]
dec a
ld [wSwitchItem], a
call Function249a7
jp c, Function249d1
ld a, [wScrollingMenuCursorPosition]
ld c, a
ld a, [wSwitchItem]
cp c
jr c, .asm_2497a
jr .asm_2494a
.init
ld a, [wScrollingMenuCursorPosition]
inc a
ld [wSwitchItem], a
ret
.trivial
xor a
ld [wSwitchItem], a
ret
.asm_2494a
ld a, [wSwitchItem]
call Function24a40
ld a, [wScrollingMenuCursorPosition]
ld d, a
ld a, [wSwitchItem]
ld e, a
call Function24a6c
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
dec hl
push hl
call ItemSwitch_ConvertSpacingToDW
add hl, bc
ld d, h
ld e, l
pop hl
pop bc
call Function24aab
ld a, [wScrollingMenuCursorPosition]
call Function24a4d
xor a
ld [wSwitchItem], a
ret
.asm_2497a
ld a, [wSwitchItem]
call Function24a40
ld a, [wScrollingMenuCursorPosition]
ld d, a
ld a, [wSwitchItem]
ld e, a
call Function24a6c
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld d, h
ld e, l
call ItemSwitch_ConvertSpacingToDW
add hl, bc
pop bc
call CopyBytes
ld a, [wScrollingMenuCursorPosition]
call Function24a4d
xor a
ld [wSwitchItem], a
ret
Function249a7: ; 249a7 (9:49a7)
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld d, h
ld e, l
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
ld a, [de]
cp [hl]
jr nz, .asm_249cd
ld a, [wScrollingMenuCursorPosition]
call Function24a97
cp 99
jr z, .asm_249cd
ld a, [wSwitchItem]
call Function24a97
cp 99
jr nz, .asm_249cf
.asm_249cd
and a
ret
.asm_249cf
scf
ret
Function249d1: ; 249d1 (9:49d1)
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
inc hl
push hl
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
inc hl
ld a, [hl]
pop hl
add [hl]
cp 100
jr c, .asm_24a01
sub 99
push af
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
inc hl
ld [hl], 99
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
inc hl
pop af
ld [hl], a
xor a
ld [wSwitchItem], a
ret
.asm_24a01
push af
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
inc hl
pop af
ld [hl], a
ld hl, wMenuData_ItemsPointerAddr
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wSwitchItem]
cp [hl]
jr nz, .asm_24a25
dec [hl]
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld [hl], $ff
xor a
ld [wSwitchItem], a
ret
.asm_24a25
dec [hl]
call ItemSwitch_ConvertSpacingToDW
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
pop bc
push hl
add hl, bc
pop de
.asm_24a34
ld a, [hli]
ld [de], a
inc de
cp $ff
jr nz, .asm_24a34
xor a
ld [wSwitchItem], a
ret
Function24a40: ; 24a40 (9:4a40)
call ItemSwitch_GetNthItem
ld de, wd002
call ItemSwitch_ConvertSpacingToDW
call CopyBytes
ret
Function24a4d: ; 24a4d (9:4a4d)
call ItemSwitch_GetNthItem
ld d, h
ld e, l
ld hl, wd002
call ItemSwitch_ConvertSpacingToDW
call CopyBytes
ret
ItemSwitch_GetNthItem: ; 24a5c (9:4a5c)
push af
call ItemSwitch_ConvertSpacingToDW
ld hl, wMenuData_ItemsPointerAddr
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
pop af
call AddNTimes
ret
Function24a6c: ; 24a6c (9:4a6c)
push hl
call ItemSwitch_ConvertSpacingToDW
ld a, d
sub e
jr nc, .dont_negate
dec a
cpl
.dont_negate
ld hl, 0
call AddNTimes
ld b, h
ld c, l
pop hl
ret
ItemSwitch_ConvertSpacingToDW: ; 24a80 (9:4a80)
; This function is absolutely idiotic.
push hl
ld a, [wMenuData_ScrollingMenuSpacing]
ld c, a
ld b, 0
ld hl, .spacing_dws
add hl, bc
add hl, bc
ld c, [hl]
inc hl
ld b, [hl]
pop hl
ret
; 24a91 (9:4a91)
.spacing_dws ; 24a91
dw 0, 1, 2
; 24a97
Function24a97: ; 24a97 (9:4a97)
push af
call ItemSwitch_ConvertSpacingToDW
ld a, c
cp 2
jr nz, .not_2
pop af
call ItemSwitch_GetNthItem
inc hl
ld a, [hl]
ret
.not_2
pop af
ld a, $1
ret
Function24aab: ; 24aab (9:4aab)
.loop
ld a, [hld]
ld [de], a
dec de
dec bc
ld a, b
or c
jr nz, .loop
ret

49
engine/items/tmhm.asm Executable file
View File

@@ -0,0 +1,49 @@
CanLearnTMHMMove: ; 11639
ld a, [wCurPartySpecies]
ld [wCurSpecies], a
call GetBaseData
ld hl, wBaseTMHM
push hl
ld a, [wPutativeTMHMMove]
ld b, a
ld c, 0
ld hl, TMHMMoves
.loop
ld a, [hli]
and a
jr z, .end
cp b
jr z, .asm_11659
inc c
jr .loop
.asm_11659
pop hl
ld b, CHECK_FLAG
push de
ld d, 0
predef SmallFarFlagAction
pop de
ret
.end
pop hl
ld c, 0
ret
; 1166a
GetTMHMMove: ; 1166a
ld a, [wd265]
dec a
ld hl, TMHMMoves
ld b, 0
ld c, a
add hl, bc
ld a, [hl]
ld [wd265], a
ret
; 1167a
INCLUDE "data/moves/tmhm_moves.asm"

View File

@@ -0,0 +1,13 @@
UpdateItemDescription: ; 0x244c3
ld a, [wMenuSelection]
ld [wCurSpecies], a
hlcoord 0, 12
ld b, 4
ld c, SCREEN_WIDTH - 2
call TextBox
ld a, [wMenuSelection]
cp -1
ret z
decoord 1, 14
farcall PrintItemDescription
ret