Make custom codes use C code instead of ASM
This commit is contained in:
parent
eb080da004
commit
c586a6bcd4
|
@ -26,7 +26,8 @@ $input_c_files =
|
|||
"src/c/battle.c",
|
||||
"src/c/equip.c",
|
||||
"src/c/psi.c",
|
||||
"src/c/luminehall.c"
|
||||
"src/c/luminehall.c",
|
||||
"src/c/custom_codes.c"
|
||||
|
||||
$base_c_address = 0x83755B8;
|
||||
$scripttool_cmd = "bin/ScriptTool/ScriptTool.dll"
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
#include "custom_codes.h"
|
||||
#include "vwf.h"
|
||||
#include "goods.h"
|
||||
|
||||
void set_window_x(WINDOW* window, int pixels)
|
||||
{
|
||||
window->pixel_x = pixels & 7;
|
||||
window->text_x = pixels >> 3;
|
||||
}
|
||||
|
||||
int custom_codes_parse(int code, char* parserAddress, WINDOW* window)
|
||||
{
|
||||
return custom_codes_parse_generic(code, parserAddress, window, (byte*)BASE_GRAPHICS_ADDRESS);
|
||||
}
|
||||
|
||||
int custom_codes_parse_generic(int code, char* parserAddress, WINDOW* window, byte* dest)
|
||||
{
|
||||
int addedSize = 0;
|
||||
|
||||
//Prepare variables for the data in the switches
|
||||
WINDOW* inv_window;
|
||||
WINDOW* dialogue_window;
|
||||
int val_to_store;
|
||||
bool store;
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case ADD_PIXEL_X_RENDERER:
|
||||
// 60 FF XX: Add XX pixels to the renderer
|
||||
handle_first_window_buffer(window, dest);
|
||||
set_window_x(window, window->pixel_x + (window->text_x << 3) + (byte)parserAddress[2]);
|
||||
addedSize = 3;
|
||||
break;
|
||||
|
||||
case SET_PIXEL_X_RENDERER:
|
||||
// 5F FF XX: Set the X value of the renderer to XX
|
||||
handle_first_window_buffer(window, dest);
|
||||
set_window_x(window, (byte)parserAddress[2]);
|
||||
addedSize = 3;
|
||||
break;
|
||||
|
||||
case STORE_ENEMY_PLURALITY:
|
||||
// 5E FF XX : Load a value into memory, based on XX
|
||||
val_to_store = 0;
|
||||
store = false;
|
||||
switch((byte)parserAddress[2])
|
||||
{
|
||||
case ENEMY_PLURALITY:
|
||||
// 5E FF 01 : Load enemy plurality into memory
|
||||
val_to_store = m2_bat_enemies_size > 3 ? 3 : m2_bat_enemies_size;
|
||||
store = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(store)
|
||||
m2_store_to_win_memory(val_to_store);
|
||||
addedSize = 3;
|
||||
break;
|
||||
|
||||
case CALL_GIVE_TEXT:
|
||||
// 5D FF: Call give text
|
||||
handle_first_window_buffer(window, dest);
|
||||
inv_window = (*window_pointers) + INV_WINDOW_VALUE;
|
||||
byte source = m2_source_pc;
|
||||
byte target = m2_active_window_pc;
|
||||
int item_index = inv_window->cursor_x == 0 ? 0 : 1;
|
||||
item_index += (inv_window->cursor_y << 1);
|
||||
unsigned short item = pc_stats[source]->goods[item_index];
|
||||
byte* free_string = *free_strings_pointers;
|
||||
if(item != NULL)
|
||||
give_print(item, target, source, (*window_pointers) + DIALOGUE_WINDOW_VALUE, free_string);
|
||||
addedSize = -1;
|
||||
break;
|
||||
|
||||
case LOAD_BUFFER:
|
||||
// 5C FF: Load buffer
|
||||
load_pixels_overworld();
|
||||
break;
|
||||
|
||||
case PRINT_MAIN_WINDOW:
|
||||
// 5B FF: Print main window (if enabled) without restore of window buffer
|
||||
generic_reprinting_first_menu_talk_to_highlight();
|
||||
addedSize = 2;
|
||||
break;
|
||||
|
||||
case RESTORE_DIALOGUE:
|
||||
// 5A FF: Restore the dialogue window
|
||||
dialogue_window = (*window_pointers) + DIALOGUE_WINDOW_VALUE;
|
||||
dialogue_window->text_x = 0;
|
||||
dialogue_window->text_y = 0;
|
||||
dialogue_window->vwf_skip = false;
|
||||
m2_drawwindow(dialogue_window);
|
||||
addedSize = 2;
|
||||
break;
|
||||
|
||||
case RESET_STORED_GOODS:
|
||||
// 59 FF: Set stored goods window's data so it prints the header from scratch
|
||||
inv_window = (*window_pointers) + INV_WINDOW_VALUE;
|
||||
inv_window->pixel_x = 0xFF;
|
||||
addedSize = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return addedSize;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef HEADER_CUSTOM_CODES_INCLUDED
|
||||
#define HEADER_CUSTOM_CODES_INCLUDED
|
||||
|
||||
#include "types.h"
|
||||
#include "locs.h"
|
||||
#include "window.h"
|
||||
|
||||
#define INV_WINDOW_VALUE 4
|
||||
#define DIALOGUE_WINDOW_VALUE 2
|
||||
|
||||
#define ENEMY_PLURALITY 1
|
||||
|
||||
#define RESET_STORED_GOODS 0x59
|
||||
#define RESTORE_DIALOGUE 0x5A
|
||||
#define PRINT_MAIN_WINDOW 0x5B
|
||||
#define LOAD_BUFFER 0x5C
|
||||
#define CALL_GIVE_TEXT 0x5D
|
||||
#define STORE_ENEMY_PLURALITY 0x5E
|
||||
#define SET_PIXEL_X_RENDERER 0x5F
|
||||
#define ADD_PIXEL_X_RENDERER 0x60
|
||||
#define BASE_GRAPHICS_ADDRESS 0x6000000
|
||||
|
||||
int custom_codes_parse(int code, char* parserAddress, WINDOW* window);
|
||||
int custom_codes_parse_generic(int code, char* parserAddress, WINDOW* window, byte* dest);
|
||||
|
||||
extern void load_pixels_overworld();
|
||||
extern void generic_reprinting_first_menu_talk_to_highlight();
|
||||
|
||||
extern byte m2_bat_enemies_size;
|
||||
extern byte m2_source_pc;
|
||||
extern byte m2_active_window_pc;
|
||||
|
||||
#endif
|
|
@ -13,15 +13,16 @@ void __attribute__((naked)) m2_soundeffect(int index) {}
|
|||
int __attribute__((naked)) m2_div(int dividend, int divisor) {}
|
||||
int __attribute__((naked)) m2_remainder(int dividend, int divisor) {}
|
||||
void __attribute__((naked)) m2_formatnumber(int value, byte* strDest, int length) {}
|
||||
int __attribute__((naked)) m2_sub_a334c(int value) {}
|
||||
int __attribute__((naked)) m2_store_to_win_memory(int value) {}
|
||||
int __attribute__((naked)) m2_sub_a3384(int value) {}
|
||||
void __attribute__((naked)) m2_sub_d3c50() {}
|
||||
void __attribute__((naked)) m2_sub_d6844() {}
|
||||
int __attribute__((naked)) m2_setupwindow(WINDOW* window, short window_x, short window_y, short window_width, short window_height) {}
|
||||
int __attribute__((naked)) m2_clearwindowtiles(WINDOW* window) {}
|
||||
int __attribute__((naked)) customcodes_parse_generic(int code, char* parserAddress, WINDOW* window, int* dest) {}
|
||||
void __attribute__((naked)) m2_printstr(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight) {}
|
||||
void __attribute__((naked)) m2_setupbattlename(short value) {}
|
||||
void __attribute__((naked)) store_pixels_overworld() {}
|
||||
void __attribute__((naked)) load_pixels_overworld() {}
|
||||
void __attribute__((naked)) generic_reprinting_first_menu_talk_to_highlight() {}
|
||||
void __attribute__((naked)) m12_dim_palette(short* palette, int total, int dimmingFactor) {}
|
||||
int __attribute__((naked)) m2_jump_to_offset(byte* character) {}
|
|
@ -257,7 +257,7 @@ int goods_inner_process(WINDOW *window, unsigned short *items)
|
|||
{
|
||||
window->counter = 0;
|
||||
window->vwf_skip = false;
|
||||
m2_sub_a334c(0);
|
||||
m2_store_to_win_memory(0);
|
||||
m2_sub_a3384(0);
|
||||
return -1;
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ int goods_inner_process(WINDOW *window, unsigned short *items)
|
|||
window->counter = 0;
|
||||
window->vwf_skip = false;
|
||||
m2_soundeffect(0x12E);
|
||||
m2_sub_a334c(0);
|
||||
m2_store_to_win_memory(0);
|
||||
m2_sub_a3384(0);
|
||||
return -1;
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ int goods_inner_process(WINDOW *window, unsigned short *items)
|
|||
window->counter = 0xFFFF;
|
||||
window->vwf_skip = false;
|
||||
m2_soundeffect(0x12D);
|
||||
m2_sub_a334c(*active_window_party_member + 1);
|
||||
m2_store_to_win_memory(*active_window_party_member + 1);
|
||||
|
||||
int selected_index = cursor_col + window->cursor_y * 2 + 1;
|
||||
m2_sub_a3384(selected_index);
|
||||
|
|
|
@ -46,7 +46,7 @@ byte *readCharacterGive(byte *outputString, byte chr, byte source, byte target,
|
|||
|
||||
extern void m2_soundeffect(int index);
|
||||
extern int m2_div(int dividend, int divisor);
|
||||
extern int m2_sub_a334c(int value);
|
||||
extern int m2_store_to_win_memory(int value);
|
||||
extern int m2_sub_a3384(int value);
|
||||
extern void m2_clearwindowtiles(WINDOW* window);
|
||||
extern int bin_to_bcd(int value, int* digit_count);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "status.h"
|
||||
#include "number-selector.h"
|
||||
#include "locs.h"
|
||||
#include "custom_codes.h"
|
||||
|
||||
void printNumberOfStatus(int maxLength, int value, int blankX, int y, int strX, int width)
|
||||
{
|
||||
|
@ -234,7 +235,7 @@ int statusWindowText(WINDOW* window)
|
|||
byte *str = window->text_start + window->text_offset;
|
||||
if((*(str + 1)) == 0xFF)
|
||||
{
|
||||
int returnedLength = customcodes_parse_generic(*str, str, window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)));
|
||||
int returnedLength = custom_codes_parse_generic(*str, str, window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)));
|
||||
if(returnedLength != 0)
|
||||
{
|
||||
if(returnedLength < 0)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "vwf.h"
|
||||
#include "number-selector.h"
|
||||
#include "locs.h"
|
||||
#include "custom_codes.h"
|
||||
|
||||
byte decode_character(byte chr)
|
||||
{
|
||||
|
@ -1452,7 +1453,7 @@ byte print_character_with_codes(WINDOW* window, byte* dest)
|
|||
window->text_offset += m2_jump_to_offset(character);
|
||||
else
|
||||
{
|
||||
returnedLength = customcodes_parse_generic(code, character, window, dest);
|
||||
returnedLength = custom_codes_parse_generic(code, character, window, dest);
|
||||
if(returnedLength == 0)
|
||||
returnedLength = 2;
|
||||
else if(returnedLength < 0)
|
||||
|
@ -1968,7 +1969,7 @@ int print_alphabet_buffer(WINDOW* window)
|
|||
|
||||
if(str[1] == 0xFF)
|
||||
{
|
||||
byte returnedVal = customcodes_parse_generic(str[0], str, window, dest);
|
||||
byte returnedVal = custom_codes_parse_generic(str[0], str, window, dest);
|
||||
if(returnedVal != 0)
|
||||
{
|
||||
window->text_offset += returnedVal;
|
||||
|
|
|
@ -167,7 +167,6 @@ extern int m2_div(int dividend, int divisor);
|
|||
extern int m2_remainder(int dividend, int divisor);
|
||||
extern void m2_soundeffect(int index);
|
||||
extern void m2_printstr(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight);
|
||||
extern int customcodes_parse_generic(int code, char* parserAddress, WINDOW* window, byte* dest);
|
||||
extern int m2_jump_to_offset(byte* character);
|
||||
extern void m2_sub_d3c50();
|
||||
extern void m2_sub_d6844();
|
||||
|
|
|
@ -1,210 +0,0 @@
|
|||
//==============================================================================
|
||||
// int parse_generic(int code, char* parserAddress, WINDOW* window, byte* dest)
|
||||
// In:
|
||||
// r0: code
|
||||
// r1: parser address
|
||||
// r2: window
|
||||
// r3: memory_destionation for handle_first_window_buffer
|
||||
// Out:
|
||||
// r0: control code length (0 if not matched)
|
||||
//==============================================================================
|
||||
|
||||
customcodes_parse:
|
||||
push {r3,lr}
|
||||
ldr r3,=#0x6000000
|
||||
bl customcodes_parse_generic
|
||||
pop {r3,pc}
|
||||
|
||||
customcodes_parse_generic:
|
||||
|
||||
push {r1-r5,lr}
|
||||
mov r5,r3
|
||||
mov r3,0
|
||||
mov r4,r0
|
||||
|
||||
//--------------------------------
|
||||
// 60 FF XX: Add XX pixels to the renderer
|
||||
cmp r4,0x60
|
||||
bne @@next
|
||||
|
||||
// 60 FF should be treated as a renderable code
|
||||
push {r0-r3}
|
||||
mov r0,r2
|
||||
mov r1,r5
|
||||
bl handle_first_window_buffer
|
||||
pop {r0-r3}
|
||||
|
||||
mov r3,3
|
||||
|
||||
// Get the current X offset
|
||||
ldrh r4,[r2,2]
|
||||
|
||||
// Get the current X tile
|
||||
ldrh r5,[r2,0x2A]
|
||||
|
||||
lsl r5,r5,3
|
||||
add r4,r4,r5 // Current X location (in pixels)
|
||||
|
||||
// Get the value to add
|
||||
ldrb r5,[r1,2] // Control code parameter
|
||||
add r4,r4,r5 // New X location
|
||||
|
||||
// Store the pixel offset of the new location
|
||||
@@store_x:
|
||||
lsl r5,r4,29
|
||||
lsr r5,r5,29
|
||||
strh r5,[r2,2]
|
||||
|
||||
// Store the X tile of the new location
|
||||
lsr r4,r4,3
|
||||
strh r4,[r2,0x2A]
|
||||
b @@end
|
||||
|
||||
@@next:
|
||||
|
||||
//--------------------------------
|
||||
// 5F FF XX: Set the X value of the renderer
|
||||
cmp r4,0x5F
|
||||
bne @@next2
|
||||
|
||||
// 5F FF should be treated as a renderable code
|
||||
push {r0-r3}
|
||||
mov r1,r5
|
||||
mov r0,r2
|
||||
bl handle_first_window_buffer
|
||||
pop {r0-r3}
|
||||
|
||||
mov r3,3
|
||||
|
||||
// Get the new X value
|
||||
ldrb r4,[r1,2]
|
||||
b @@store_x
|
||||
|
||||
@@next2:
|
||||
|
||||
//--------------------------------
|
||||
// 5E FF XX: Load value into memory
|
||||
cmp r4,0x5E
|
||||
bne @@next3
|
||||
mov r3,3
|
||||
|
||||
// Get the argument
|
||||
ldrb r4,[r1,2]
|
||||
cmp r4,1
|
||||
bne @@end
|
||||
|
||||
// 01: load enemy plurality
|
||||
ldr r1,=0x2025038
|
||||
ldrb r1,[r1] // number of enemies at start of battle
|
||||
cmp r1,4
|
||||
blt @@small
|
||||
mov r1,3
|
||||
@@small:
|
||||
mov r0,r1 // the jump table is 1-indexed
|
||||
mov r4,r3
|
||||
bl 0x80A334C // store to window memory
|
||||
mov r3,r4
|
||||
b @@end
|
||||
|
||||
@@next3:
|
||||
|
||||
//--------------------------------
|
||||
// 5D FF: Print give text
|
||||
cmp r4,0x5D
|
||||
bne @@next4
|
||||
|
||||
// 5D FF should be treated as a renderable code
|
||||
push {r0-r3}
|
||||
mov r1,r5
|
||||
mov r0,r2
|
||||
bl handle_first_window_buffer
|
||||
pop {r0-r3}
|
||||
|
||||
ldr r3,=#0x30009FB
|
||||
ldrb r3,[r3,#0] //Source
|
||||
ldr r2,=#m2_active_window_pc //Target
|
||||
ldrb r2,[r2,#0]
|
||||
ldr r1,=#0x3005230
|
||||
ldr r1,[r1,#0x10] //Inventory Window
|
||||
ldrh r4,[r1,#0x36] //Cursor Y
|
||||
ldrh r1,[r1,#0x34] //Cursor X
|
||||
lsl r4,r4,#1
|
||||
cmp r1,#0
|
||||
beq @@continue
|
||||
add r4,r4,#1 //Selected Item number in inventory
|
||||
@@continue:
|
||||
lsl r4,r4,#1
|
||||
ldr r0,=#0x3005200
|
||||
ldr r0,[r0,#0]
|
||||
push {r0} //String address
|
||||
ldr r0,=#0x3001D40
|
||||
mov r1,#0x6C
|
||||
mul r1,r3
|
||||
add r0,#0x14
|
||||
add r0,r0,r1 //Inventory of source
|
||||
add r0,r0,r4 //Item address
|
||||
ldrh r0,[r0,#0] //Item
|
||||
cmp r0,#0
|
||||
beq @@EndOf5D
|
||||
mov r1,r2
|
||||
mov r2,r3
|
||||
ldr r3,=#0x3005230
|
||||
ldr r3,[r3,#0x08] //Dialogue Window
|
||||
bl give_print
|
||||
|
||||
@@EndOf5D:
|
||||
pop {r0}
|
||||
mov r3,#0
|
||||
sub r3,r3,#1 //r3 is now -1
|
||||
b @@end
|
||||
|
||||
@@next4:
|
||||
|
||||
//--------------------------------
|
||||
// 5C FF: Load buffer
|
||||
cmp r4,#0x5C
|
||||
bne @@next5
|
||||
bl load_pixels_overworld
|
||||
b @@end
|
||||
|
||||
@@next5:
|
||||
|
||||
//--------------------------------
|
||||
// 5B FF: Print main window (if enabled) without restore of window buffer
|
||||
cmp r4,#0x5B
|
||||
bne @@next6
|
||||
bl generic_reprinting_first_menu_talk_to_highlight
|
||||
mov r3,#2
|
||||
b @@end
|
||||
|
||||
@@next6:
|
||||
//--------------------------------
|
||||
// 5A FF: Restore the dialogue window
|
||||
cmp r4,#0x5A
|
||||
bne @@next7
|
||||
ldr r0,=#0x3005230
|
||||
ldr r0,[r0,#8]
|
||||
mov r1,#0
|
||||
strh r1,[r0,#0x2A]
|
||||
strh r1,[r0,#0x2C]
|
||||
strb r1,[r0,#3]
|
||||
bl m2_drawwindow
|
||||
mov r3,#2
|
||||
b @@end
|
||||
|
||||
@@next7:
|
||||
//--------------------------------
|
||||
// 59 FF: Set stored goods window's data so it prints the header from scratch
|
||||
cmp r4,#0x59
|
||||
bne @@end
|
||||
ldr r0,=#0x3005230
|
||||
ldr r0,[r0,#0x10]
|
||||
mov r1,#0xFF //Set pixel_x as 0xFF
|
||||
strb r1,[r0,#2]
|
||||
mov r3,#2
|
||||
|
||||
//--------------------------------
|
||||
@@end:
|
||||
mov r0,r3
|
||||
pop {r1-r5,pc}
|
||||
.pool
|
|
@ -2055,7 +2055,9 @@ disclaimer_map:
|
|||
|
||||
.definelabel buffer_subtractor ,0x0000800
|
||||
.definelabel overworld_buffer ,0x200F200
|
||||
.definelabel m2_bat_enemies_size ,0x2025038
|
||||
.definelabel m2_hall_line_size ,0x3000374
|
||||
.definelabel m2_source_pc ,0x30009FB
|
||||
.definelabel m2_ness_data ,0x3001D54
|
||||
.definelabel m2_ness_name ,0x3001F10
|
||||
.definelabel m2_old_paula_name ,0x3001F16
|
||||
|
@ -2088,7 +2090,7 @@ disclaimer_map:
|
|||
.definelabel m2_get_hall_address ,0x800D7BC
|
||||
.definelabel m12_dim_palette ,0x80137DC
|
||||
.definelabel m2_enable_script ,0x80A1F6C
|
||||
.definelabel m2_sub_a334c ,0x80A334C
|
||||
.definelabel m2_store_to_win_memory ,0x80A334C
|
||||
.definelabel m2_sub_a3384 ,0x80A3384
|
||||
.definelabel m2_jump_to_offset ,0x80A6C24
|
||||
.definelabel m2_get_selected_item ,0x80A469C
|
||||
|
@ -2139,7 +2141,6 @@ disclaimer_map:
|
|||
.include "m2-vwf-entries.asm"
|
||||
.include "m2-bugfixes.asm"
|
||||
.include "m2-formatting.asm"
|
||||
.include "m2-customcodes.asm"
|
||||
.include "m2-compiled.asm"
|
||||
.include "m2-flyover.asm"
|
||||
.include "m12-intro.asm"
|
||||
|
|
|
@ -3,7 +3,7 @@ c980c_custom_codes:
|
|||
push {r1-r2,lr}
|
||||
mov r1,r7
|
||||
mov r2,r5
|
||||
bl customcodes_parse
|
||||
bl custom_codes_parse
|
||||
ldr r1,[r6]
|
||||
|
||||
// If 0, return [r6]+2; otherwise, return [r6]+r0
|
||||
|
@ -34,7 +34,7 @@ ldrb r0,[r2]
|
|||
mov r5,r0
|
||||
mov r1,r2
|
||||
mov r2,r4
|
||||
bl customcodes_parse
|
||||
bl custom_codes_parse
|
||||
cmp r0,0
|
||||
beq @@next
|
||||
mov r2,r12
|
||||
|
@ -1637,7 +1637,7 @@ pop {pc}
|
|||
//Routine which gives the address to the party member's inventory
|
||||
get_inventory_selected:
|
||||
push {r3,lr}
|
||||
ldr r0,=#0x30009FB //Load source pc
|
||||
ldr r0,=m2_source_pc //Load source pc
|
||||
ldrb r0,[r0,#0]
|
||||
ldr r3,=#0x3001D40 //Get inventory
|
||||
mov r2,#0x6C
|
||||
|
@ -1659,7 +1659,7 @@ ldr r2,[r3,#0]
|
|||
lsl r2,r2,#0x10
|
||||
asr r2,r2,#0x10
|
||||
push {r2}
|
||||
ldr r2,=#0x30009FB //Load source pc
|
||||
ldr r2,=m2_source_pc //Load source pc
|
||||
ldrb r2,[r2,#0]
|
||||
str r2,[r3,#0] //Store it
|
||||
|
||||
|
@ -2500,7 +2500,7 @@ pop {pc}
|
|||
//==============================================================================
|
||||
c7ea2_shop_clear:
|
||||
push {lr}
|
||||
bl m2_sub_a334c
|
||||
bl m2_store_to_win_memory
|
||||
ldr r0,=#0x3005230 //Window generic address
|
||||
ldr r0,[r0,#8] //Load the dialogue window
|
||||
bl clear_window
|
||||
|
|
Loading…
Reference in New Issue