Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions ff4.s
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Final Fantasy IV the new hack.
.import "dialog"
.import "ingame/init_bg_scroll_hdma"
.import "ingame/items_menu_vwf"
.import "ingame/places_names"
.import "ingame/new_game"
.import "ingame/credits"
.import "ingame/places_names_window"
.import "intro"
.import "kerning"
Expand All @@ -45,45 +48,42 @@ Final Fantasy IV the new hack.


.include "src/libmz.i"
.include "src/items.i"
.include "src/lib/rolling_buffer.s"
.import "items"
.include "src/lib/rolling_buffer.i"
.include "src/menus/system_menus_text.i"
.include "src/minimal_vwf_patches.s"
.import "minimal_vwf_patches"
.if BATTLE_ENABLED {
.include "src/battle/math_patches.s"
.include "src/battle/graphics_patches.s"
.import "battle/math_patches"
.import "battle/graphics_patches"
.if MAGIC_ENABLED {
.include "src/battle/magic/patches.s"
.include "src/battle/commands_patches.s"
.import "battle/magic/patches"
.import "battle/commands_patches"
}
.include "src/battle/message_patches.s"
.include "src/battle/sram_patches.s"
.import "battle/message_patches"
.import "battle/sram_patches"
.if BATTLE_MONSTERS_VWF {
.include "src/battle/monsters_patches.s"
.import "battle/monsters_patches"
}
.include "src/battle/items_patches.s"
.include "src/battle/redraw_writer_patches.s"
.import "battle/items_patches"
.import "battle/redraw_writer_patches"
.if INVENTORY_ROLLING_BUFFER {
.include "src/battle/inventory_rolling_patches.s"
.import "battle/inventory_rolling_patches"
}
.if TREASURE_DEBUG_ALWAYS_DROP {
.include "src/battle/debug_always_drop.s"
.import "battle/debug_always_drop"
}
}

.include "src/ingame/places_names.s"
.include "src/ingame/new_game.s"
.include "src/ingame/credits.s"
.include "src/ingame/menus.i"
; item name expansion patches
.include "src/ingame/items_menu.s"
.import "ingame/items_menu"

; Relocated init_bg_scroll_hdma (was at $01:EBD2, frees 566 bytes in bank $01).
; Blob with internal absolute references - pinned to offset $EBD2 within an
; expansion bank. Caller patch retargets the single JSL at $02:818A.
.if INVENTORY_ROLLING_BUFFER {
.include "src/ingame/init_bg_scroll_hdma_patches.s"
.include "src/ingame/inventory_rolling_trampolines.s"
.import "ingame/init_bg_scroll_hdma_patches"
.import "ingame/inventory_rolling_trampolines"
}


Expand Down Expand Up @@ -365,23 +365,23 @@ signature byte sits at PB:(PC - 1).

.if INVENTORY_ROLLING_BUFFER {
.import "ingame/init_bg_scroll_hdma"
.include "src/ingame/inventory_rolling.s"
.include "src/lib/rolling_inventory_engine.s"
}

.if TREASURE_INVENTORY_ROLLING {
.include "src/ingame/treasure_rolling.s"
.include "src/ingame/drops_rolling.s"
.include "src/ingame/key_item_picker.s"
.include "src/ingame/shop_sell_rolling.s"
.import "ingame/key_item_picker"
.import "ingame/drops_rolling"
.import "ingame/inventory_rolling"
.import "lib/rolling_inventory_engine"
.import "ingame/treasure_rolling"
.import "ingame/shop_sell_rolling"
}

; --- Binary text assets -------------------------------------------------


.if TREASURE_INVENTORY_ROLLING {
.include "src/ingame/key_item_picker_patches.s"
.include "src/ingame/shop_sell_rolling_patches.s"
.import "ingame/key_item_picker_patches"
.import "ingame/shop_sell_rolling_patches"
}

.if TRIGGER_ENDING_CUTSCENE {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [{ name = "Emmanuel Peralta", email = "manz@ringum.net" }]
requires-python = ">=3.13"

dependencies = [
"a816==1.1.0a31",
"a816==1.1.0a33",
"kintsuki[visual]==0.0.0a13",
]

Expand Down
3 changes: 3 additions & 0 deletions src/bank20.i
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ linker dedupes identical ranges via `_merge_one_pool_decl`.
"""


; The pool sits in bank $20, so the ROM map has to be in scope with it.
.include "src/rom_map.i"

.pool bank20_reloc {
range 0x208000 0x20FFFF
strategy order
Expand Down
3 changes: 3 additions & 0 deletions src/battle/commands_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
In-place patches that resize the battle command-window layout when `BATTLE_CMD_VWF` is enabled (shorter slot
stride, command-id base, format-buffer pointer).
"""

.include "src/rom_map.i"

.include "config.i"
command_buffer_ptr = 0x97a6 + 0x601 ; old spell lists buffers
.if BATTLE_CMD_VWF {
Expand Down
3 changes: 3 additions & 0 deletions src/battle/debug_always_drop.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Debug patch (gated by `TREASURE_DEBUG_ALWAYS_DROP`) that forces every battle to roll a successful drop by
NOPing the random-roll gate at $03:ED0D.
"""

.include "src/rom_map.i"

; Debug: force every battle to drop an item.
;

Expand Down
4 changes: 4 additions & 0 deletions src/battle/graphics_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Battle graphics asset patches: MISS sprite glyphs, defend/row text overrides and other small tile fixups that
piggyback on `defend_row` data.
"""

.include "src/rom_map.i"
.extern assets_battle_statuses_dat

.extern defend_row

; MISS sprite graphics
Expand Down
2 changes: 1 addition & 1 deletion src/battle/inventory_rolling.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Battle inventory rolling-buffer engine (single column, 5 visible rows + 1 prefet
runs the field-menu NMI DMA check.
"""
.include "config.i"
.include "../items.i"
.import "items"
.extern assets_items_dat
.extern assets_items_unleashed_dat
.extern mult8_trampoline
Expand Down
4 changes: 4 additions & 0 deletions src/battle/inventory_rolling_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
ROM patches that wire the battle inventory rolling-buffer engine into bank $02 (JSL trampolines for cross-bank
calls, JML hooks for the scroll animation, surgical NOPs / RTS overrides).
"""

.include "src/rom_map.i"
.extern draw_window_render_hook

.include "config.i"
.extern init_inventory_text_buf_rolling
.extern tfr_inventory_list_rolling
Expand Down
4 changes: 4 additions & 0 deletions src/battle/items_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Patches for 12-byte (instead of 9-byte) item names in battle: rewrites every `cpx`/`cmp` boundary check and
every $0F8000 item-data reference to land on `assets_items_dat`.
"""

.include "src/rom_map.i"
.extern assets_items_dat

; Item name expansion patches for battle graphics
; Changes 9-byte items to 12-byte items
; Redirects 0x0F8000 references to assets_items_dat
Expand Down
7 changes: 7 additions & 0 deletions src/battle/magic/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
ROM patches that wire the battle magic system to the relocated `draw_magic_list_direct` renderer + the
long-form attack-name copier.
"""

.include "src/rom_map.i"
.extern assets_attack_names_dat
.extern assets_attack_names_ptr
.extern assets_magic_dat
.extern battle_magic_length

.extern draw_magic_list_direct
.extern magic_list_ptrs

Expand Down
3 changes: 3 additions & 0 deletions src/battle/math_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Patches that re-point the bank-2 hardware multiplier (`Mult8` at $8560) at our reimplementation, plus the JMP
trampoline at $83B9 jumping into `_hw_mult16`.
"""

.include "src/rom_map.i"

; ===========================================================================
; Mult8 Hardware Implementation - Bank 2 version at $8560
; Input: $26, $28 → Output: $2a = $26 * $28
Expand Down
8 changes: 4 additions & 4 deletions src/battle/message.s
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ toggling battle_flags mid-stream.

Caller setup mirrors the vanilla draw_text contract:
$EF50: 16-bit format buffer ptr (source bytes)
$EF52: 16-bit destination tilemap-buffer ptr (in bank \$7E)
$EF52: 16-bit destination tilemap-buffer ptr (in bank $7E)
$EF54: line length (tiles per row, currently 15)
$EF55: palette
$7EEF82: rolling_slot_index (0..5) for VWF allocator base
Expand Down Expand Up @@ -1110,7 +1110,7 @@ _di_clear:
bne _di_clear

; X = src (format buffer ptr), Y = dest offset (0-relative into the
; tilemap buffer pointed to by \$32 / \$34).
; tilemap buffer pointed to by $32 / $34).
ldx 0xEF50
ldy.w #0x0000

Expand Down Expand Up @@ -1151,7 +1151,7 @@ _di_loop:
jmp.w _di_loop

_di_fixed_char:
; Fixed-mode raw char: write current byte as tile_id at (\$34),y. No
; Fixed-mode raw char: write current byte as tile_id at ($34),y. No
; ora #0x01 on the attr -- the +0x100 high bit is only for VWF tiles
; in the 0x1xx range, fixed font tiles live in 0x00..0xFF.
sta (0x34), y
Expand All @@ -1167,7 +1167,7 @@ _di_fixed_char:


_di_fixed:
; 0x03 BB -> write fixed tile_id BB at (\$34),y. Same shape as
; 0x03 BB -> write fixed tile_id BB at ($34),y. Same shape as
; _di_fixed_char (mirror of wram.put_char), no +0x100 bit set.
inx
lda.w 0x0000, x
Expand Down
6 changes: 6 additions & 0 deletions src/battle/message_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Pinned-address overlay rewiring original battle-message pointer loads ($02C909, $02CC07, ...) to the relocated
translated-string tables.
"""

.include "src/rom_map.i"
.extern msg_window_draw_text_trampoline
.extern assets_battle_text_ptr
.extern assets_battle_messages_ptr

.extern messages_vwf

.scope message_patches {
Expand Down
4 changes: 4 additions & 0 deletions src/battle/monsters_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Patches that switch the battle monster-name loader from a fixed-size table to a pointer-indirected one (long
names) and forward to `load_monster_pointer`.
"""

.include "src/rom_map.i"
.extern assets_monsters_long_dat

.extern load_monster_pointer
.extern initialize_monster_slot
.extern tab_escape_code
Expand Down
3 changes: 3 additions & 0 deletions src/battle/redraw_writer_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ follow-up patches.
"""


.include "src/rom_map.i"


.extern set_active_char_and_dirty
.extern messages_vwf
.extern messages_vwf.init_monsters_gated
Expand Down
3 changes: 3 additions & 0 deletions src/battle/sram_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
ROM patches that route every battle-text draw call (commands, monster names, char names, attack names, message
window) through our messages-VWF init/deinit trampolines.
"""

.include "src/rom_map.i"

.include "config.i"
.extern draw_command_list_for_character
.extern battle_display_char
Expand Down
4 changes: 4 additions & 0 deletions src/ingame/credits.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ In-place patches for the staff credits screen: re-point the credits text loader
`assets_credits_text_bin` block.
"""

.include "src/rom_map.i"
.extern assets_credits_text_bin


.alloc at 0x13d7ef {
ldx.w #assets_credits_text_bin & 0xffff
}
Expand Down
19 changes: 14 additions & 5 deletions src/ingame/drops_rolling.s
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ State RAM layout (12 bytes from $1BE0, struct: RollingBufferState):
"""


.import "items"

; Labels borrowed from neighbouring modules. As an include these resolved
; because ff4.s composed one translation unit; a module names what it uses.
.extern check_can_use_item_trampoline
.extern draw_item_slot_inner_trampoline
.extern draw_window_trampoline
.extern drops_select_bg4_trampoline
.extern treasure_drops_window
.extern rolling_engine


DROPS_VISIBLE_ITEMS := 5
DROPS_BUFFER_SLOTS := 6
DROPS_TOTAL_ITEMS := 8
Expand All @@ -51,11 +63,7 @@ DROPS_SCROLL_TOTAL_PIXELS := 16
; code writes to bytes past $1BEB) to clean $7E:9C30. Engine path needs
; the full 35-byte struct ; the macro path only ever touched the first
; 12 bytes so the original $1BE0 base worked there.
; `RollingBufferState` is declared in items.i, which ff4.s includes
; ahead of this module - the assembler resolves the cast, the lint
; sees one file at a time and cannot. Codes are comma-separated, so
; the reason has to sit here rather than after the marker.
drops_rolling := (0x7E9C30 as RollingBufferState) ; noqa: S001
drops_rolling := (0x7E9C30 as RollingBufferState)

; Drops scroll position lives one byte past the state block so it
; doesn't collide with the engine's RollingBufferState fields. Other
Expand Down Expand Up @@ -95,6 +103,7 @@ DROPS_SCROLL_STATE_SCROLLING := 1

.include "../bank20.i"


.alloc drops_rolling_block in bank20_reloc {
drops_ensure_hdma_initialized:
"""Lazy init: pin BG4VOFS shadow to 0 + configure ch4 driving BG4VOFS on first scroll."""
Expand Down
4 changes: 4 additions & 0 deletions src/ingame/init_bg_scroll_hdma_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Caller-side patches retargeting `JSL $01EBD2` (original `InitBGScrollHDMA`) to the relocated copy in bank $21
after the original's ROM space is reclaimed.
"""

.include "src/rom_map.i"
.extern init_bg_scroll_hdma

;; Caller patches for init_bg_scroll_hdma after relocation to bank $21.
;; Original `JSL $01EBD2` at $02:818A becomes `JSL $21EBD2`.
;; (In LoROM bank $21 is the only thing that changes; offset $EBD2 within
Expand Down
12 changes: 12 additions & 0 deletions src/ingame/inventory_rolling.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
Field-menu inventory rolling-buffer engine (single column, 5 visible rows + 1 prefetch): adapts the battle
approach for the main menu items list with HDMA-based circular scrolling.
"""

.import "items"
.include "src/lib/rolling_buffer.i"

; Borrowed from neighbouring modules; inlining used to supply them.
.extern check_can_use_item_trampoline
.extern draw_item_slot_inner_trampoline
.extern draw_window_trampoline
.extern reset_sprites_trampoline
.extern draw_trash_single_column
.extern rolling_engine

; Rolling Buffer Implementation for Main Menu Inventory (Single Column)
;
; HDMA-based circular buffer scrolling for single-column menu inventory.
Expand Down
Loading