Merge pull request #101 from Lorenzooone/window-text-buffering

Change Mother 2 cartridge to EB cartridge + Fix issue with tenda village naming screen
This commit is contained in:
Lorenzooone 2019-10-06 23:50:55 +02:00 committed by GitHub
commit af7ec48ebb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 30 deletions

View File

@ -1,6 +1,7 @@
#include "window.h"
void __attribute__((naked)) cpufastset(void *source, void *dest, int mode) {}
void __attribute__((naked)) cpuset(void *source, void *dest, int mode) {}
byte* __attribute__((naked)) m2_strlookup(int *offset_table, byte *strings, int index) {}
int __attribute__((naked)) bin_to_bcd(int value, int* digit_count) {}
int __attribute__((naked)) m2_drawwindow(WINDOW* window) {}
@ -20,4 +21,6 @@ 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)) store_pixels_overworld() {}
void __attribute__((naked)) m12_dim_palette(short* palette, int total, int dimmingFactor) {}
int __attribute__((naked)) m2_jump_to_offset(byte* character) {}

View File

@ -1276,33 +1276,6 @@ void setStuffWindow_Graphics()
(*(address + 2)) = 0;
}
int jumpToOffset(byte* character)
{
int returnOffset = 0;
int baseOffset = 0;
if((*(character + 1)) != 0xFF)
return 0;
int code = 0xFFFF009F + ((*character) | 0xFF00);
switch(code)
{
case 0x25:
returnOffset += 2;
baseOffset = returnOffset;
for(int i = 0; i < 4; i++)
returnOffset = returnOffset + ((*(character + baseOffset + i)) << (8 * i));
byte* totalJumps = (byte*)0x3005078;
byte** oldOffsets = (byte**)0x3005080;
oldOffsets[*totalJumps] = character + 6;
(*totalJumps)++;
break;
default:
return 0;
}
return returnOffset;
}
byte print_character_with_codes(WINDOW* window, byte* dest)
{
int delay = window->delay--;
@ -1422,7 +1395,7 @@ byte print_character_with_codes(WINDOW* window, byte* dest)
break;
default:
if(code >= 0x60)
window->text_offset += jumpToOffset(character);
window->text_offset += m2_jump_to_offset(character);
else
{
returnedLength = customcodes_parse_generic(code, character, window, dest);
@ -2120,6 +2093,27 @@ void store_pixels_overworld_buffer(int totalYs)
}
}
void eb_cartridge_palette_change(bool background)
{
unsigned short *paletteDest = (unsigned short*)0x5000040;
if(background)
{
if(BUILD_PALETTE)
{
//Makes the game do the palette work. Copy the result in a bin file and use that instead in order to make the swap fast
unsigned short palettes[0x50];
cpuset(paletteDest, palettes, 0x50);
for(int i = 0; i < 5; i++)
m12_dim_palette(&palettes[i * 0x10], 0x10, 0x800);
cpuset(palettes, paletteDest, 0x50);
}
else
cpuset(m12_cartridge_palettes_dimmed, paletteDest, 0x50);
}
else
cpuset(&m12_cartridge_palettes[0x20], paletteDest, 0x50);
}
void store_pixels_overworld_buffer_totalTiles(int totalTiles)
{
int tile = *tile_offset;

View File

@ -27,6 +27,8 @@
#define CUSTOMCC_SET_X 0x5F
#define CUSTOMCC_ADD_X 0x60
#define BUILD_PALETTE false
byte decode_character(byte chr);
byte encode_ascii(char chr);
int get_tile_number(int x, int y);
@ -100,7 +102,6 @@ void clear_tile_buffer(int x, int y, byte* dest);
int buffer_drawwindow(WINDOW* window, byte* dest);
void scrolltext_buffer(WINDOW* window, byte* dest);
void properScroll(WINDOW* window, byte* dest);
int jumpToOffset(byte* character);
void copy_tile_buffer(int xSource, int ySource, int xDest, int yDest, byte *dest);
void copy_tile_up_buffer(int x, int y, byte *dest);
void setStuffWindow_Graphics();
@ -124,6 +125,7 @@ unsigned short printstr_hlight_pixels_buffer(WINDOW* window, byte* str, unsigned
void load_pixels_overworld_buffer();
void store_pixels_overworld_buffer(int totalYs);
void store_pixels_overworld_buffer_totalTiles(int totalTiles);
void eb_cartridge_palette_change(bool background);
extern unsigned short m2_coord_table_fast_progression[];
extern unsigned short m2_coord_table[];
@ -142,12 +144,16 @@ extern byte m12_other_str7[];
extern byte m12_other_str8[];
extern byte m2_cstm_last_printed[];
extern byte *m2_script_readability;
extern unsigned short m12_cartridge_palettes[];
extern unsigned short m12_cartridge_palettes_dimmed[];
extern int overworld_buffer;
extern PC m2_ness_data[];
extern int m2_arrow_tile[];
extern bool m2_isequipped(int item_index);
extern void cpufastset(void *source, void *dest, int mode);
extern void cpuset(void *source, void *dest, int mode);
extern void m12_dim_palette(unsigned short* palette, int total, int dimmingFactor);
extern byte* m2_strlookup(int *offset_table, byte *strings, int index);
extern void m2_formatnumber(int value, byte* strDest, int length);
extern int bin_to_bcd(int value, int* digit_count);
@ -159,6 +165,7 @@ 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();
extern int m2_setupwindow(WINDOW* window, short window_x, short window_y, short window_width, short window_height);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1667,6 +1667,21 @@ nop
.org 0x82D92D4 :: dw moved_graphics_table :: dw moved_graphics_table + 0x1CD2C
.org 0x82D9BBC :: dw moved_graphics_table + 0x26618 :: dw moved_graphics_table + 0x3F818
//==============================================================================
// Cartridge choosing screen hacks
//==============================================================================
.org 0x8013C62 :: bl change_palette_needed_foreground
.org 0x8013CAA :: bl change_palette_needed_background
.org 0x86DD794 :: .incbin "data/m2-cartridge-tiles.bin"
.org 0x8706994 :: .incbin "data/m2-cartridge-arrangements.bin"
.org 0x8705794
m12_cartridge_palettes:
.incbin "data/m2-cartridge-palettes.bin"
//==============================================================================
// Data files
//==============================================================================
@ -1786,6 +1801,9 @@ m2_coord_table_file:
optimized_byte_4bpp_to_1bpp_table:
.incbin "data/optimized-byte-4bpp-to-1bpp-table.bin"
m12_cartridge_palettes_dimmed:
.incbin "data/m12-cartridge-palettes-dimmed.bin"
//==============================================================================
// Existing subroutines/data
@ -1822,9 +1840,11 @@ optimized_byte_4bpp_to_1bpp_table:
.definelabel m2_change_naming_space ,0x8004E08
.definelabel m2_copy_name_temp_mem ,0x8004E34
.definelabel m2_insert_default_name ,0x8005708
.definelabel m12_dim_palette ,0x80137DC
.definelabel m2_enable_script ,0x80A1F6C
.definelabel m2_sub_a334c ,0x80A334C
.definelabel m2_sub_a3384 ,0x80A3384
.definelabel m2_jump_to_offset ,0x80A6C24
.definelabel m2_get_selected_item ,0x80A469C
.definelabel m2_psitargetwindow ,0x80B8AE0
.definelabel m2_isequipped ,0x80BC670
@ -1855,6 +1875,7 @@ optimized_byte_4bpp_to_1bpp_table:
.definelabel m2_stat_symb_checker ,0x8B0EDA4
.definelabel m2_div ,0x80F49D8
.definelabel m2_remainder ,0x80F4A70
.definelabel cpuset ,0x80F47C0
.definelabel m2_items ,0x8B1D62C
.definelabel m2_default_names ,0x82B9330
.definelabel m2_psi_print_table ,0x8B2A9C0

View File

@ -3331,6 +3331,35 @@ mov r0,#0xA
bl store_pixels_overworld_buffer
pop {r0-r3,pc}
//==============================================================================
//Change tile only if need be (it's different) - foreground call
change_palette_needed_foreground:
push {lr}
mov r3,#0
bl change_palette_needed
pop {pc}
//==============================================================================
//Change tile only if need be (it's different) - background call
change_palette_needed_background:
push {lr}
mov r3,#1
bl change_palette_needed
pop {pc}
//==============================================================================
//Change tile only if need be (it's different), r3 contains whether the EB cart is in the background or not
change_palette_needed:
push {lr}
ldrh r2,[r1,#0]
ldrh r1,[r0,#0]
cmp r1,r2
beq @@end
mov r0,r3
bl eb_cartridge_palette_change
@@end:
pop {pc}
//==============================================================================
//Prints the sick tiles and then the names
sick_name: