diff --git a/src/c/battle.c b/src/c/battle.c index 7ebc742..4bed408 100644 --- a/src/c/battle.c +++ b/src/c/battle.c @@ -26,15 +26,15 @@ void printTargetOfAttack(short a, short target) byte val = *(pointer2 + target); unsigned short ailmentTile = ailmentTileSetup((byte*)(0x2020CCF + (val * 0x94)), 0); if(ailmentTile >= 1) - { + { map_tile(ailmentTile, window->window_x + 0x13, window->window_y); map_tile(ailmentTile + 0x20, window->window_x + 0x13, window->window_y + 1); - } - else - { - map_tile(0x1FF, window->window_x + 0x13, window->window_y); - map_tile(0x1FF, window->window_x + 0x13, window->window_y + 1); - } + } + else + { + map_tile(0x1FF, window->window_x + 0x13, window->window_y); + map_tile(0x1FF, window->window_x + 0x13, window->window_y + 1); + } } else { @@ -55,10 +55,10 @@ void printBattleMenu(byte validXs, byte validYs, byte highlighted) { if(validYs & 1) { - print_blankstr_buffer(2,1,5,(int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(2,1,5,(byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); if((*drawValue) == 2) { - print_blankstr_buffer(7,1,5,(int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(7,1,5,(byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); str = m12_battle_commands_str10; //Do Nothing } else if((*drawValue) == 1) @@ -70,7 +70,7 @@ void printBattleMenu(byte validXs, byte validYs, byte highlighted) if(validYs & 2) { - print_blankstr_buffer(2,3,5,(int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(2,3,5,(byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); if((*active_window_party_member) != 2) printstr_hlight_buffer(window, m12_battle_commands_str3, 1, 1, highlighted & 2); //PSI else @@ -84,14 +84,14 @@ void printBattleMenu(byte validXs, byte validYs, byte highlighted) { if((*drawValue) != 2) { - print_blankstr_buffer(7,1,5,(int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(7,1,5,(byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); printstr_hlight_buffer(window, m12_battle_commands_str1, 6, 0, highlighted & 4); //Goods } } if(validYs & 2) { - print_blankstr_buffer(7,3,5,(int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(7,3,5,(byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); if((*drawValue) != 2) { printstr_hlight_buffer(window, m12_battle_commands_str4, 6, 1, highlighted & 8); //Defend diff --git a/src/c/equip.c b/src/c/equip.c index 5f37af0..fd60941 100644 --- a/src/c/equip.c +++ b/src/c/equip.c @@ -266,7 +266,7 @@ int equippableReadInput(WINDOW* window) //Manages input in equipment-choice inne int counter = 0; - //Loads the total amount of items + //Loads the total amount of items if(possibleEquippablesCount > 6) counter = 7; else if(weird_value > 0) @@ -327,7 +327,7 @@ int equippableReadInput(WINDOW* window) //Manages input in equipment-choice inne window->counter = 0xFFFF; if(freeSpace[window->cursor_y] == 0xFE) { - m2_soundeffect(0x12D); //Do the sound only if we're changing the page. Otherwise the original code will do the appropriate sound + m2_soundeffect(0x12D); //Do the sound only if we're changing the page. Otherwise the original code will do the appropriate sound window->counter = 0; window->cursor_x_base++; if(m2_div(window->cursor_x, 5) < window->cursor_x_base) @@ -362,19 +362,19 @@ int equippableReadInput(WINDOW* window) //Manages input in equipment-choice inne //Simplified inner equip routine (The original routine had a pointer to a table of valid cursor positions as a parameter) int innerEquipInput(WINDOW* window) { - bool printing = !window->vwf_skip; - window->vwf_skip = true; - + bool printing = !window->vwf_skip; + window->vwf_skip = true; + PAD_STATE state = *pad_state; PAD_STATE state_shadow = *pad_state_shadow; short previousY = window->cursor_y; short currentY = window->cursor_y; - - // Clear cursor tiles + + // Clear cursor tiles map_tile(0x1FF, window->window_x, window->window_y + window->cursor_y * 2); map_tile(0x1FF, window->window_x, window->window_y + window->cursor_y * 2 + 1); - + if(state.up) //This has been simplified { currentY--; @@ -398,16 +398,16 @@ int innerEquipInput(WINDOW* window) currentY = 0; } } - - //The game does stuff when pressing left or right, however for the equipment window this is not needed - if(state.right) //This routine in particular did both the main overworld window and the inner equip window - { - } - - - if(state.left) - { - } + + //The game does stuff when pressing left or right, however for the equipment window this is not needed + if(state.right) //This routine in particular did both the main overworld window and the inner equip window + { + } + + + if(state.left) + { + } if(state_shadow.up || state_shadow.down) { @@ -419,24 +419,24 @@ int innerEquipInput(WINDOW* window) } else window->hold = false; - + if((state.b || state.select) && (!printing)) { window->counter = 0; m2_soundeffect(0x12E); - window->vwf_skip = false; + window->vwf_skip = false; return ACTION_STEPOUT; } - - + + if((state.a || state.l) && (!printing)) { window->counter = 0xFFFF; m2_soundeffect(0x12D); - window->vwf_skip = false; + window->vwf_skip = false; return (window->cursor_y << 1) + ACTION_STEPIN; } - + if (window->counter != 0xFFFF) { window->counter++; @@ -449,8 +449,8 @@ int innerEquipInput(WINDOW* window) if (window->counter > 0x10) window->counter = 0; } - - return ACTION_NONE; + + return ACTION_NONE; } void equipPrint(WINDOW* window) //Prints equipment @@ -467,25 +467,25 @@ void equipPrint(WINDOW* window) //Prints equipment byte *item; //Clear the previous equipment - print_blankstr_buffer(window->window_x + 6, 1, 0xC, (int*)(OVERWORLD_BUFFER - 0x2000)); - print_blankstr_buffer(window->window_x + 6, 3, 0xC, (int*)(OVERWORLD_BUFFER - 0x2000)); - print_blankstr_buffer(window->window_x + 6, 5, 0xC, (int*)(OVERWORLD_BUFFER - 0x2000)); - print_blankstr_buffer(window->window_x + 6, 7, 0xC, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(window->window_x + 6, 1, 0xC, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); + print_blankstr_buffer(window->window_x + 6, 3, 0xC, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); + print_blankstr_buffer(window->window_x + 6, 5, 0xC, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); + print_blankstr_buffer(window->window_x + 6, 7, 0xC, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); //Clear the previous numbers - print_blankstr_buffer(8, 0xB, 0x8, (int*)(OVERWORLD_BUFFER - 0x2000)); - print_blankstr_buffer(8, 0xD, 0x8, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(8, 0xB, 0x8, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); + print_blankstr_buffer(8, 0xD, 0x8, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); //Reprint the ":"s - print_character_with_callback(decode_character(0x6A), ((window->window_x + 6) << 3), (0x1 << 3), 0, 0xF, (int*)(OVERWORLD_BUFFER - 0x2000), &get_tile_number_with_offset, *tilemap_pointer, 32, 0xC); - print_character_with_callback(decode_character(0x6A), ((window->window_x + 6) << 3), (0x3 << 3), 0, 0xF, (int*)(OVERWORLD_BUFFER - 0x2000), &get_tile_number_with_offset, *tilemap_pointer, 32, 0xC); - print_character_with_callback(decode_character(0x6A), ((window->window_x + 6) << 3), (0x5 << 3), 0, 0xF, (int*)(OVERWORLD_BUFFER - 0x2000), &get_tile_number_with_offset, *tilemap_pointer, 32, 0xC); - print_character_with_callback(decode_character(0x6A), ((window->window_x + 6) << 3), (0x7 << 3), 0, 0xF, (int*)(OVERWORLD_BUFFER - 0x2000), &get_tile_number_with_offset, *tilemap_pointer, 32, 0xC); + print_character_with_callback_1bpp_buffer(decode_character(0x6A), ((window->window_x + 6) << 3), (0x1 << 3), (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)), &get_tile_number_with_offset, 0, *tilemap_pointer, 32, 0xC); + print_character_with_callback_1bpp_buffer(decode_character(0x6A), ((window->window_x + 6) << 3), (0x3 << 3), (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)), &get_tile_number_with_offset, 0, *tilemap_pointer, 32, 0xC); + print_character_with_callback_1bpp_buffer(decode_character(0x6A), ((window->window_x + 6) << 3), (0x5 << 3), (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)), &get_tile_number_with_offset, 0, *tilemap_pointer, 32, 0xC); + print_character_with_callback_1bpp_buffer(decode_character(0x6A), ((window->window_x + 6) << 3), (0x7 << 3), (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)), &get_tile_number_with_offset, 0, *tilemap_pointer, 32, 0xC); //Print the equipment if(character_data->equipment[0] == 0) //Weapon - print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x1) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x1) << 3, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); else { item = m2_strlookup((int*)0x8B1AF94, (byte*)0x8B1A694, character_data->goods[character_data->equipment[0] - 1]); @@ -494,7 +494,7 @@ void equipPrint(WINDOW* window) //Prints equipment } if(character_data->equipment[1] == 0) //Body - print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x3) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x3) << 3, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); else { item = m2_strlookup((int*)0x8B1AF94, (byte*)0x8B1A694, character_data->goods[character_data->equipment[1] - 1]); @@ -503,7 +503,7 @@ void equipPrint(WINDOW* window) //Prints equipment } if(character_data->equipment[2] == 0) //Arms - print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x5) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x5) << 3, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); else { item = m2_strlookup((int*)0x8B1AF94, (byte*)0x8B1A694, character_data->goods[character_data->equipment[2] - 1]); @@ -512,7 +512,7 @@ void equipPrint(WINDOW* window) //Prints equipment } if(character_data->equipment[3] == 0) //Other - print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x7) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_string_in_buffer(nothing, (((window->window_x + 7)) << 3) - 2, (0x7) << 3, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); else { item = m2_strlookup((int*)0x8B1AF94, (byte*)0x8B1A694, character_data->goods[character_data->equipment[3] - 1]); @@ -524,24 +524,24 @@ void equipPrint(WINDOW* window) //Prints equipment //Prints the numbers in the window in a formatted way void printNumberEquip(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight) { - while((*str) == 0x50) - { - x += 6; - str++; - } - printstr_hlight_pixels_buffer(window, str, x, y, highlight); + while((*str) == 0x50) + { + x += 6; + str++; + } + printstr_hlight_pixels_buffer(window, str, x, y, highlight); } //Prints Offense: and Defense: void printEquipWindowNumberText(WINDOW* window) { - handle_first_window_buffer(window, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); - printstr_hlight_pixels_buffer(window, window->text_start, 0, 3, false); + handle_first_window_buffer(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); + printstr_hlight_pixels_buffer(window, window->text_start, 0, 3, false); } //Prints the arrow for the numbers in the Offense/Defense menu void printEquipNumbersArrow(WINDOW* window) { - printTinyArrow((window->window_x + 9) << 3, (window->window_y + 0) << 3); - printTinyArrow((window->window_x + 9) << 3, (window->window_y + 2) << 3); + printTinyArrow((window->window_x + 9) << 3, (window->window_y + 0) << 3); + printTinyArrow((window->window_x + 9) << 3, (window->window_y + 2) << 3); } diff --git a/src/c/psi.c b/src/c/psi.c index 0ec58e6..d307af0 100644 --- a/src/c/psi.c +++ b/src/c/psi.c @@ -135,7 +135,7 @@ void psiPrint_buffer(byte value, WINDOW* window, bool printPSILine, PSIPrintInfo if(PSIID == 1) { str = (byte*)(m2_ness_name + (7 * 4) + (8 * 2)); //Go to Rockin's name - print_string_in_buffer(str, 0x71, ((printInfo->YPrinting) + window->window_y) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_string_in_buffer(str, 0x71, ((printInfo->YPrinting) + window->window_y) << 3, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); } } @@ -455,7 +455,7 @@ int PSITargetInput(WINDOW* window) if(!window->vwf_skip) { - clear_window_buffer(getWindow(9), (int*)(OVERWORLD_BUFFER - 0x2000)); + clear_window_buffer(getWindow(9), (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); psiTargetWindow_buffer(target); window->vwf_skip = true; } diff --git a/src/c/status.c b/src/c/status.c index d55a9e5..dec91d8 100644 --- a/src/c/status.c +++ b/src/c/status.c @@ -9,17 +9,17 @@ void printNumberOfStatus(int maxLength, int value, int blankX, int y, int strX, int end = setNumber_getLength(value, str, maxLength); str[end] = 0; str[end + 1] = 0xFF; - print_blankstr_buffer(blankX, y, width, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(blankX, y, width, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); int x = (strX - (end * 6)); - print_string_in_buffer(str, x, y << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_string_in_buffer(str, x, y << 3, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); } void printStatusSymbolArrangement(unsigned short symbolTile, WINDOW* window) { - map_tile(symbolTile, window->window_x + 0xA, window->window_y + 2); + map_tile(symbolTile, window->window_x + 0xA, window->window_y + 2); if(symbolTile == 0x1FF) symbolTile -= 0x20; - map_tile(symbolTile + 0x20, window->window_x + 0xA, window->window_y + 3); + map_tile(symbolTile + 0x20, window->window_x + 0xA, window->window_y + 3); } void printStatusString(WINDOW* window, int value) @@ -57,7 +57,7 @@ int statusNumbersPrint(WINDOW* window, bool doNotPrint) printNumberOfStatus(7, experienceLevelUp - character_data->experience, 2, 0xD, 0x3D, 6); } else - print_blankstr_buffer(2, 0xD, 6, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(2, 0xD, 6, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); printNumberOfStatus(3, character_data->offense_effective, 0x19, 0x1, 0xE1, 4); printNumberOfStatus(3, character_data->defense_effective, 0x19, 0x3, 0xE1, 4); printNumberOfStatus(3, character_data->speed_effective, 0x19, 0x5, 0xE1, 4); @@ -65,13 +65,13 @@ int statusNumbersPrint(WINDOW* window, bool doNotPrint) printNumberOfStatus(3, character_data->vitality_effective, 0x19, 0x9, 0xE1, 4); printNumberOfStatus(3, character_data->iq_effective, 0x19, 0xB, 0xE1, 4); printNumberOfStatus(3, character_data->luck_effective, 0x19, 0xD, 0xE1, 4); - print_blankstr_buffer(5, 0xF, 0x14, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(5, 0xF, 0x14, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); if((*active_window_party_member) != JEFF) { byte *str = m2_strlookup((int*)0x8B17EE4, (byte*)0x8B17424, 0x13); - print_string_in_buffer(str, 0x2C, (0xF) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_string_in_buffer(str, 0x2C, (0xF) << 3, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); } - print_blankstr_buffer(1, 0x3, 0xA, (int*)(OVERWORLD_BUFFER - 0x2000)); + print_blankstr_buffer(1, 0x3, 0xA, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); unsigned short symbolTile = ailmentTileSetup(&(character_data->ailment), 0); if(symbolTile == 0) { @@ -223,18 +223,18 @@ int statusWindowNumbers(WINDOW* window, bool doNotPrint) int statusWindowText(WINDOW* window) { if(window->redraw) - buffer_drawwindow(window, (int*)(OVERWORLD_BUFFER - 0x2000)); + buffer_drawwindow(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); if(window->loaded_code != 0 && ((*script_readability) == 0)) { window->delay = 0; while(true) { while(window->text_y >= window->window_height || window->window_y + window->text_y > 0x1F) - properScroll(window, (int*)(OVERWORLD_BUFFER - 0x2000)); + properScroll(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); byte *str = window->text_start + window->text_offset; if((*(str + 1)) == 0xFF) { - int returnedLength = customcodes_parse_generic(*str, str, window, (int*)(OVERWORLD_BUFFER - 0x2000)); + int returnedLength = customcodes_parse_generic(*str, str, window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); if(returnedLength != 0) { if(returnedLength < 0) @@ -265,7 +265,7 @@ int statusWindowText(WINDOW* window) window->text_y += 2; window->text_x = 0; } - weld_entry_custom_buffer(window, str, 0, 0xF, (int*)(OVERWORLD_BUFFER - 0x2000)); + weld_entry_custom_buffer(window, str, 0, 0xF, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); window->text_offset++; } } diff --git a/src/c/vwf.c b/src/c/vwf.c index a2acedb..ba4d742 100644 --- a/src/c/vwf.c +++ b/src/c/vwf.c @@ -24,25 +24,39 @@ int get_tile_number(int x, int y) return m2_coord_table[x + ((y >> 1) * 28)] + (y & 1) * 32; } +int get_tile_number_buffer(int x, int y) +{ + x--; + y--; + int totalLenght = x + ((y >> 1) * 28); + int addedValue = (totalLenght >> 5) << 6; + return (totalLenght & 0x1F) + addedValue + (y & 1) * 32; +} + int get_tile_number_with_offset(int x, int y) { return get_tile_number(x, y) + *tile_offset; } +int get_tile_number_with_offset_buffer(int x, int y) +{ + return get_tile_number_buffer(x, y) + *tile_offset; +} + int get_tile_number_grid(int x, int y) { return x + (y * 32); } -int expand_bit_depth(byte row, int foreground) +int expand_bit_depth(byte row, byte foreground) { foreground &= 0xF; return m2_bits_to_nybbles[row + (foreground * 256)]; } -byte reduce_bit_depth(int row, int foreground) +//The foregroundRow is given as a parameter in order to make this faster +byte reduce_bit_depth(int row, int foregroundRow) { - int foregroundRow = row * 0x11111111; row ^= foregroundRow; int lower = m2_nybbles_to_bits[row & 0xFFFF]; @@ -352,6 +366,105 @@ byte print_character_with_callback(byte chr, int x, int y, int font, int foregro return virtualWidth; } +byte print_character_with_callback_1bpp_buffer(byte chr, int x, int y, byte *dest, int (*getTileCallback)(int, int), int font, + unsigned short *tilemapPtr, int tilemapWidth, byte doubleTileHeight) +{ + int tileWidth = m2_font_widths[font]; + int tileHeight = m2_font_heights[font]; + int widths = m2_widths_table[font][chr]; + + int paletteMask = *palette_mask; + byte *glyphRows = &m2_font_table[font][chr * tileWidth * tileHeight * 8]; + + int virtualWidth = widths & 0xFF; + + int tileX = x >> 3; + int tileY = y >> 3; + + int offsetY = y & 7; + int offsetX = x & 7; + + if((tileY & 1) == 0 && offsetY >= doubleTileHeight - 0x8) + { + tileY++; + offsetY -= (doubleTileHeight - 0x8); + } + + int nextY = offsetY; + for (int dTileY = 0; dTileY < tileHeight; dTileY++) // dest tile Y + { + int dTileX = 0; + int renderedWidth = widths >> 8; + offsetY = nextY; + bool changed = false; + + while (renderedWidth > 0) + { + // Glue the leftmost part of the glyph onto the rightmost part of the canvas + int tileIndex = get_tile_number_with_offset_buffer(tileX + dTileX, tileY + dTileY); + int tileIndexRight = get_tile_number_with_offset_buffer(tileX + dTileX + 1, tileY + dTileY); + bool availableSwap = (dTileY != (tileHeight - 1)); + bool usedRight = false; + int realTileIndex = tileIndex; + int realTileIndexRight = tileIndexRight; + bool useful = false; //Maybe we go over the maximum tile height, let's make sure the extra tile is properly set IF it's useful + int tmpTileY = dTileY; + int limit = ((tmpTileY + tileY) & 1) == 0 ? doubleTileHeight - 8 - 1: 7; + int sumRemoved = 0; + + for (int row = 0; row < 8; row++) + { + unsigned short canvasRow = dest[(realTileIndex * 8) + ((row + offsetY - sumRemoved) & 7)] + (dest[(realTileIndexRight * 8) + ((row + offsetY - sumRemoved) & 7)] << 8); + unsigned short glyphRow = glyphRows[row + (dTileY * 8 * tileWidth) + (dTileX * 8)] << offsetX; + + unsigned short tmpCanvasRow = canvasRow; + canvasRow |= glyphRow; + + if((canvasRow >> 8) != (tmpCanvasRow >> 8)) + usedRight = true; + + if(!availableSwap && ((row + offsetY) >> 3) == 1 && canvasRow != tmpCanvasRow) //This changed the canvas, then it's useful... IF it's the extra vertical tile + useful = true; + + dest[(realTileIndex * 8) + ((row + offsetY - sumRemoved) & 7)] = canvasRow; + dest[(realTileIndexRight * 8) + ((row + offsetY - sumRemoved) & 7)] = canvasRow >> 8; + + if((row + offsetY - sumRemoved) == limit) + { + tmpTileY++; + realTileIndex = get_tile_number_with_offset_buffer(tileX + dTileX, tileY + tmpTileY); + realTileIndexRight = get_tile_number_with_offset_buffer(tileX + 1 + dTileX, tileY + tmpTileY); + sumRemoved += limit + 1; + if(!changed) + { + nextY = (nextY + limit + 1) & 7; + changed = true; + } + limit = ((tmpTileY + tileY) & 1) == 0 ? doubleTileHeight - 8 - 1: 7; + + } + } + + if (tilemapPtr != NULL) + { + tilemapPtr[tileX + dTileX + ((tileY + dTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX, tileY + dTileY); + if(usedRight) + tilemapPtr[tileX + dTileX + 1 + ((tileY + dTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX + 1, tileY + dTileY); + if(useful) + { + tilemapPtr[tileX + dTileX + ((tileY + tmpTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX, tileY + tmpTileY); + if(usedRight) + tilemapPtr[tileX + dTileX + 1 + ((tileY + tmpTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX + 1, tileY + tmpTileY); + } + } + renderedWidth -= 8; + dTileX++; + } + } + + return virtualWidth; +} + int print_window_header_string(int *dest, byte *str, int x, int y) { int pixelX = x & 7; @@ -895,7 +1008,7 @@ int get_pointer_jump_back(byte *character) return (str - character - 2); } -void print_letter_in_buffer(WINDOW* window, byte* character, int* dest) +void print_letter_in_buffer(WINDOW* window, byte* character, byte* dest) { m2_cstm_last_printed[0] = (*character); weld_entry_custom_buffer(window, character, 0, 0xF, dest); @@ -927,13 +1040,13 @@ int print_window_with_buffer(WINDOW* window) while(window->loaded_code !=0) { window->delay = delay; - print_character_with_codes(window, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); + print_character_with_codes(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); } } return 0; } -void scrolltext_buffer(WINDOW* window, int* dest) +void scrolltext_buffer(WINDOW* window, byte* dest) { unsigned short empty_tile = ((*tile_offset) + 0x1FF) | (*palette_mask); unsigned short *arrangementBase = (*tilemap_pointer); @@ -946,7 +1059,7 @@ void scrolltext_buffer(WINDOW* window, int* dest) for(int x = 0; x < window->window_width && x + window->window_x <= 0x1F; x++) { arrangementBase[start + x + (y * 32)] = empty_tile; - clear_tile_buffer(x + window->window_x, y + window->window_y, 0x44444444, dest); + clear_tile_buffer(x + window->window_x, y + window->window_y, dest); } } } @@ -980,11 +1093,11 @@ void scrolltext_buffer(WINDOW* window, int* dest) for(int x = 0; x < window->window_width && x + window->window_x <= 0x1F; x++) { arrangementBase[start + x + (y * 32)] = empty_tile; - clear_tile_buffer(x + window->window_x, y + window->window_y, 0x44444444, dest); + clear_tile_buffer(x + window->window_x, y + window->window_y, dest); } } -void properScroll(WINDOW* window, int* dest) +void properScroll(WINDOW* window, byte* dest) { scrolltext_buffer(window, dest); window->text_y = window->text_y - 2; @@ -1030,7 +1143,7 @@ int jumpToOffset(byte* character) return returnOffset; } -byte print_character_with_codes(WINDOW* window, int* dest) +byte print_character_with_codes(WINDOW* window, byte* dest) { int delay = window->delay--; if(delay > 0) @@ -1164,7 +1277,7 @@ byte print_character_with_codes(WINDOW* window, int* dest) } else { - handle_first_window_buffer(window, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); + handle_first_window_buffer(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); window->delay = window->delay_between_prints; if(x > 0x1F) { @@ -1181,7 +1294,7 @@ byte print_character_with_codes(WINDOW* window, int* dest) return 0; } -byte print_character_formatted_buffer(byte chr, int x, int y, int font, int foreground, int *dest) +byte print_character_formatted_buffer(byte chr, int x, int y, int font, int foreground, byte *dest) { // 0x64 to 0x6C (inclusive) is YOU WON if ((chr >= YOUWON_START) && (chr <= YOUWON_END)) @@ -1197,10 +1310,10 @@ byte print_character_formatted_buffer(byte chr, int x, int y, int font, int fore return 9; } - return print_character_with_callback(chr, x, y, font, foreground, dest, &get_tile_number_with_offset, *tilemap_pointer, 32, 0xC); + return print_character_with_callback_1bpp_buffer(chr, x, y, dest, &get_tile_number_with_offset, font, *tilemap_pointer, 32, 0xC); } -void weld_entry_custom_buffer(WINDOW *window, byte *str, int font, int foreground, int* dest) +void weld_entry_custom_buffer(WINDOW *window, byte *str, int font, int foreground, byte* dest) { int chr = decode_character(*str); @@ -1213,7 +1326,7 @@ void weld_entry_custom_buffer(WINDOW *window, byte *str, int font, int foregroun window->text_x = (x >> 3) - window->window_x; } -void handle_first_window_buffer(WINDOW* window, int* dest) +void handle_first_window_buffer(WINDOW* window, byte* dest) { if (*first_window_flag == 1) { @@ -1227,26 +1340,26 @@ void handle_first_window_buffer(WINDOW* window, int* dest) } } -void clear_window_buffer(WINDOW *window, int* dest) +void clear_window_buffer(WINDOW *window, byte* dest) { clear_rect_buffer(window->window_x, window->window_y, window->window_width, window->window_height, - WINDOW_AREA_BG, dest); + dest); } // x,y: tile coordinates -void clear_rect_buffer(int x, int y, int width, int height, int pixels, int* dest) +void clear_rect_buffer(int x, int y, int width, int height, byte* dest) { for (int tileY = 0; tileY < height; tileY++) { for (int tileX = 0; tileX < width; tileX++) { - clear_tile_buffer(x + tileX, y + tileY, pixels, dest); + clear_tile_buffer(x + tileX, y + tileY, dest); } } } -int print_string_in_buffer(byte *str, int x, int y, int *dest) +int print_string_in_buffer(byte *str, int x, int y, byte *dest) { if (str == NULL) return 0; @@ -1257,19 +1370,19 @@ int print_string_in_buffer(byte *str, int x, int y, int *dest) while (str[1] != 0xFF || str[0] != 0) { - if(str[1] == 0xFF && str[0] == 1) - { - x = initial_x; - str += 2; - y+= 0x10; - } - else if(str[1] != 0xFF) - { - x += print_character_formatted_buffer(decode_character(*str++), x, y, 0, 0xF, dest); - charCount++; - } - else - break; + if(str[1] == 0xFF && str[0] == 1) + { + x = initial_x; + str += 2; + y+= 0x10; + } + else if(str[1] != 0xFF) + { + x += print_character_formatted_buffer(decode_character(*str++), x, y, 0, 0xF, dest); + charCount++; + } + else + break; } int totalWidth = x - initial_x; @@ -1301,7 +1414,7 @@ int printstr_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short while(output != 1) { window->delay = 0; - output = print_character_with_codes(window, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); + output = print_character_with_codes(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); } int retValue = (window->text_x << 3) + window->pixel_x; window->text_start = tmpTextStart; @@ -1329,7 +1442,7 @@ unsigned short printstr_hlight_pixels_buffer(WINDOW* window, byte* str, unsigned palette_mask_highlight += 0x1000; (*palette_mask) = palette_mask_highlight; - unsigned short printed_Characters = print_string_in_buffer(str, printX, printY, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); + unsigned short printed_Characters = print_string_in_buffer(str, printX, printY, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); (*palette_mask) = tmpPaletteMsk; @@ -1357,29 +1470,31 @@ int initWindow_buffer(WINDOW* window, byte* text_start, unsigned short delay_bet window->flags_unknown1 |= 1; window->redraw = true; if(text_start == NULL) - buffer_drawwindow(window, (int*)(OVERWORLD_BUFFER - 0x2000)); + buffer_drawwindow(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); return 0; } void clearWindowTiles_buffer(WINDOW* window) { - clear_window_buffer(window, (int*)(OVERWORLD_BUFFER - 0x2000)); + clear_window_buffer(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); window->text_x = 0; window->text_y = 0; } // x,y: tile coordinates -void clear_tile_buffer(int x, int y, int pixels, int* dest) +void clear_tile_buffer(int x, int y, byte* dest) { // Clear pixels - int tileIndex = get_tile_number(x, y) + *tile_offset; - cpufastset(&pixels, &dest[tileIndex * 8], CPUFASTSET_FILL | 8); + int tileIndex = get_tile_number_buffer(x, y) + *tile_offset; + int *destTileInt = (int*)&dest[(tileIndex) * 8]; + destTileInt[0] = 0; + destTileInt[1] = 0; // Reset the tilemap (e.g. get rid of equip or SMAAAASH!! tiles) - (*tilemap_pointer)[x + (y * 32)] = tileIndex | *palette_mask; + (*tilemap_pointer)[x + (y * 32)] = (get_tile_number(x, y) + (*tile_offset)) | *palette_mask; } -int buffer_reset_window(WINDOW* window, bool skip_redraw, int* dest) +int buffer_reset_window(WINDOW* window, bool skip_redraw, byte* dest) { window->delay = 0; byte code = window->loaded_code - 0xD; @@ -1395,9 +1510,12 @@ int buffer_reset_window(WINDOW* window, bool skip_redraw, int* dest) return 0; } -int buffer_drawwindow(WINDOW* window, int* dest) +int buffer_drawwindow(WINDOW* window, byte* dest) { - clear_window_buffer(window, dest); + if((int*)dest == vram) + clear_window(window); + else + clear_window_buffer(window, dest); unsigned short empty_tile = (0x1FF + (*tile_offset)) | (*palette_mask); int baseOfWindow = ((window->window_y - 1) * 32) + window->window_x - 1; unsigned short *arrangementBase = (*tilemap_pointer); @@ -1555,7 +1673,7 @@ unsigned short ailmentTileSetup(byte *ailmentBase, unsigned short defaultVal) void printTinyArrow(int x, int y) { - print_special_character_buffer(0x9F, x, y); + print_special_character_buffer(0x9F, x, y); } void printCashWindow() @@ -1570,21 +1688,66 @@ void printCashWindow() } // x, y, width: tile coordinates -void print_blankstr_buffer(int x, int y, int width, int *dest) +void print_blankstr_buffer(int x, int y, int width, byte *dest) { - clear_rect_buffer(x, y, width, 2, WINDOW_AREA_BG, dest); + clear_rect_buffer(x, y, width, 2, dest); +} + +void load_pixels_overworld_buffer() +{ + byte* buffer = (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)); + for(int y = 0; y < 0x10; y++) + for(int x = 0; x < 0x1C; x++) + { + int tile_buffer = get_tile_number_with_offset_buffer(x + 1, y + 1); + int tile = get_tile_number_with_offset(x + 1, y + 1); + int foregroundRow = 0xFFFFFFFF; + buffer[(tile_buffer * 8) + 0] = reduce_bit_depth(vram[(tile * 8) + 0], foregroundRow); + buffer[(tile_buffer * 8) + 1] = reduce_bit_depth(vram[(tile * 8) + 1], foregroundRow); + buffer[(tile_buffer * 8) + 2] = reduce_bit_depth(vram[(tile * 8) + 2], foregroundRow); + buffer[(tile_buffer * 8) + 3] = reduce_bit_depth(vram[(tile * 8) + 3], foregroundRow); + buffer[(tile_buffer * 8) + 4] = reduce_bit_depth(vram[(tile * 8) + 4], foregroundRow); + buffer[(tile_buffer * 8) + 5] = reduce_bit_depth(vram[(tile * 8) + 5], foregroundRow); + buffer[(tile_buffer * 8) + 6] = reduce_bit_depth(vram[(tile * 8) + 6], foregroundRow); + buffer[(tile_buffer * 8) + 7] = reduce_bit_depth(vram[(tile * 8) + 7], foregroundRow); + } +} + +void store_pixels_overworld_buffer(int totalYs) +{ + byte* buffer = (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)); + for(int y = 0; y < totalYs; y++) + for(int x = 0; x < 0x1C; x++) + { + int tile = get_tile_number_with_offset(x + 1, y + 1); + int tile_buffer = get_tile_number_with_offset_buffer(x + 1, y + 1); + int* bufferValues = (int*)(&buffer[(tile_buffer * 8)]); + unsigned int first_half = bufferValues[0]; + unsigned int second_half = bufferValues[1]; + vram[(tile * 8) + 0] = m2_bits_to_nybbles_fast[(first_half >> 0) & 0xFF]; + vram[(tile * 8) + 1] = m2_bits_to_nybbles_fast[(first_half >> 8) & 0xFF]; + vram[(tile * 8) + 2] = m2_bits_to_nybbles_fast[(first_half >> 0x10) & 0xFF]; + vram[(tile * 8) + 3] = m2_bits_to_nybbles_fast[(first_half >> 0x18) & 0xFF]; + vram[(tile * 8) + 4] = m2_bits_to_nybbles_fast[(second_half >> 0) & 0xFF]; + vram[(tile * 8) + 5] = m2_bits_to_nybbles_fast[(second_half >> 8) & 0xFF]; + vram[(tile * 8) + 6] = m2_bits_to_nybbles_fast[(second_half >> 0x10) & 0xFF]; + vram[(tile * 8) + 7] = m2_bits_to_nybbles_fast[(second_half >> 0x18) & 0xFF]; + } } // x,y: tile coordinates -void copy_tile_buffer(int xSource, int ySource, int xDest, int yDest, int *dest) +void copy_tile_buffer(int xSource, int ySource, int xDest, int yDest, byte *dest) { - int sourceTileIndex = get_tile_number(xSource, ySource) + *tile_offset; - int destTileIndex = get_tile_number(xDest, yDest) + *tile_offset; - cpufastset(&dest[sourceTileIndex * 8], &dest[destTileIndex * 8], 8); + int sourceTileIndex = get_tile_number_buffer(xSource, ySource) + *tile_offset; + int destTileIndex = get_tile_number_buffer(xDest, yDest) + *tile_offset; + int* sourceTile = (int*)&dest[sourceTileIndex * 8]; + int* destTile = (int*)&dest[destTileIndex * 8]; + destTile[0] = sourceTile[0]; + destTile[1] = sourceTile[1]; } // x,y: tile coordinates -void copy_tile_up_buffer(int x, int y, int *dest) +void copy_tile_up_buffer(int x, int y, byte *dest) { copy_tile_buffer(x, y, x, y - 2, dest); } \ No newline at end of file diff --git a/src/c/vwf.h b/src/c/vwf.h index ceef68c..8309e60 100644 --- a/src/c/vwf.h +++ b/src/c/vwf.h @@ -7,6 +7,7 @@ #define TRUE 1 #define FALSE 0 +#define TILESET_OFFSET_BUFFER_MULTIPLIER 0x8 #define CHAR_OFFSET 0x50 #define CHAR_END 0x60 #define YOUWON_START 0x64 @@ -21,7 +22,7 @@ #define WINDOW_HEADER_Y 0x11 #define WINDOW_HEADER_TILE (WINDOW_HEADER_X + (WINDOW_HEADER_Y * 32)) -#define OVERWORLD_BUFFER 0x200C000 +#define OVERWORLD_BUFFER 0x200F200 #define CUSTOMCC_SET_X 0x5F #define CUSTOMCC_ADD_X 0x60 @@ -30,11 +31,13 @@ byte decode_character(byte chr); byte encode_ascii(char chr); int get_tile_number(int x, int y); int get_tile_number_with_offset(int x, int y); +int get_tile_number_buffer(int x, int y); +int get_tile_number_with_offset_buffer(int x, int y); int ascii_strlen(char *str); int wrapper_count_pixels_to_tiles(byte *str, int length); int count_pixels_to_tiles(byte *str, int length, int startingPos); -int expand_bit_depth(byte row, int foreground); -byte reduce_bit_depth(int row, int foreground); +int expand_bit_depth(byte row, byte foreground); +byte reduce_bit_depth(int row, int foregroundRow); byte print_character(byte chr, int x, int y); byte print_character_formatted(byte chr, int x, int y, int font, int foreground); byte print_character_to_window(byte chr, WINDOW* window); @@ -43,6 +46,8 @@ void map_special_character(unsigned short tile, int x, int y); void map_tile(unsigned short tile, int x, int y); byte print_character_with_callback(byte chr, int x, int y, int font, int foreground, int *dest, int (*getTileCallback)(int, int), unsigned short *tilemapPtr, int tilemapWidth, byte doubleTileHeight); +byte print_character_with_callback_1bpp_buffer(byte chr, int x, int y, byte *dest, int (*getTileCallback)(int, int), int font, + unsigned short *tilemapPtr, int tilemapWidth, byte doubleTileHeight); byte print_character_to_ram(byte chr, int *dest, int xOffset, int font, int foreground); int print_window_header_string(int *dest, byte *str, int x, int y); void clear_window_header(int *dest, int length, int x, int y); @@ -78,39 +83,42 @@ byte getSex(byte character); void getPossessive(byte character, byte *str, int *index); void getPronoun(byte character, byte *str, int *index); int get_pointer_jump_back(byte *character); -void print_letter_in_buffer(WINDOW* window, byte* character, int *dest); -void weld_entry_custom_buffer(WINDOW *window, byte *str, int font, int foreground, int* dest); -byte print_character_formatted_buffer(byte chr, int x, int y, int font, int foreground, int *dest); +void print_letter_in_buffer(WINDOW* window, byte* character, byte *dest); +void weld_entry_custom_buffer(WINDOW *window, byte *str, int font, int foreground, byte* dest); +byte print_character_formatted_buffer(byte chr, int x, int y, int font, int foreground, byte *dest); int print_window_with_buffer(WINDOW* window); -byte print_character_with_codes(WINDOW* window, int* dest); -int buffer_reset_window(WINDOW* window, bool skip_redraw, int* dest); -void handle_first_window_buffer(WINDOW* window, int* dest); -void clear_window_buffer(WINDOW *window, int* dest); -void clear_rect_buffer(int x, int y, int width, int height, int pixels, int* dest); -void clear_tile_buffer(int x, int y, int pixels, int* dest); -int buffer_drawwindow(WINDOW* window, int* dest); -void scrolltext_buffer(WINDOW* window, int* dest); -void properScroll(WINDOW* window, int* dest); +byte print_character_with_codes(WINDOW* window, byte* dest); +int buffer_reset_window(WINDOW* window, bool skip_redraw, byte* dest); +void handle_first_window_buffer(WINDOW* window, byte* dest); +void clear_window_buffer(WINDOW *window, byte* dest); +void clear_rect_buffer(int x, int y, int width, int height, byte* dest); +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, int *dest); -void copy_tile_up_buffer(int x, int y, int *dest); +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(); void clearWindowTiles_buffer(WINDOW* window); int initWindow_buffer(WINDOW* window, byte* text_start, unsigned short delay_between_prints); -void print_blankstr_buffer(int x, int y, int width, int *dest); +void print_blankstr_buffer(int x, int y, int width, byte *dest); unsigned short ailmentTileSetup(byte *ailmentBase, unsigned short defaultVal); int setNumber_getLength(int value, byte *str, int maxLength); -int print_string_in_buffer(byte *str, int x, int y, int *dest); +int print_string_in_buffer(byte *str, int x, int y, byte *dest); void printCashWindow(); WINDOW* getWindow(int index); void printTinyArrow(int x, int y); int printstr_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); unsigned short printstr_hlight_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); unsigned short printstr_hlight_pixels_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); +void load_pixels_overworld_buffer(); +void store_pixels_overworld_buffer(int totalYs); extern unsigned short m2_coord_table[]; extern byte m2_ness_name[]; extern int m2_bits_to_nybbles[]; +extern int m2_bits_to_nybbles_fast[]; extern byte m2_nybbles_to_bits[]; extern byte *m2_font_table[]; extern byte m2_font_widths[]; @@ -138,7 +146,7 @@ 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, int* dest); +extern int customcodes_parse_generic(int code, char* parserAddress, WINDOW* window, byte* dest); 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); diff --git a/src/data/m2-bits-to-nybbles-fast.bin b/src/data/m2-bits-to-nybbles-fast.bin new file mode 100644 index 0000000..8ab9222 --- /dev/null +++ b/src/data/m2-bits-to-nybbles-fast.bin @@ -0,0 +1 @@ +DDDDODDDôDDDÿDDDDODDOODDôODDÿODDDôDDOôDDôôDDÿôDDDÿDDOÿDDôÿDDÿÿDDDDODODODôDODÿDODDOODOOODôOODÿOODDôODOôODôôODÿôODDÿODOÿODôÿODÿÿODDDôDODôDôDôDÿDôDDOôDOOôDôOôDÿOôDDôôDOôôDôôôDÿôôDDÿôDOÿôDôÿôDÿÿôDDDÿDODÿDôDÿDÿDÿDDOÿDOOÿDôOÿDÿOÿDDôÿDOôÿDôôÿDÿôÿDDÿÿDOÿÿDôÿÿDÿÿÿDDDDOODDOôDDOÿDDODODOOODOôODOÿODODôDOOôDOôôDOÿôDODÿDOOÿDOôÿDOÿÿDODDOOODOOôDOOÿDOODOOOOOOOôOOOÿOOODôOOOôOOôôOOÿôOODÿOOOÿOOôÿOOÿÿOODDôOODôOôDôOÿDôODOôOOOôOôOôOÿOôODôôOOôôOôôôOÿôôODÿôOOÿôOôÿôOÿÿôODDÿOODÿOôDÿOÿDÿODOÿOOOÿOôOÿOÿOÿODôÿOOôÿOôôÿOÿôÿODÿÿOOÿÿOôÿÿOÿÿÿODDDôODDôôDDôÿDDôDODôOODôôODôÿODôDôDôOôDôôôDôÿôDôDÿDôOÿDôôÿDôÿÿDôDDOôODOôôDOôÿDOôDOOôOOOôôOOôÿOOôDôOôOôOôôôOôÿôOôDÿOôOÿOôôÿOôÿÿOôDDôôODôôôDôôÿDôôDOôôOOôôôOôôÿOôôDôôôOôôôôôôôÿôôôDÿôôOÿôôôÿôôÿÿôôDDÿôODÿôôDÿôÿDÿôDOÿôOOÿôôOÿôÿOÿôDôÿôOôÿôôôÿôÿôÿôDÿÿôOÿÿôôÿÿôÿÿÿôDDDÿODDÿôDDÿÿDDÿDODÿOODÿôODÿÿODÿDôDÿOôDÿôôDÿÿôDÿDÿDÿOÿDÿôÿDÿÿÿDÿDDOÿODOÿôDOÿÿDOÿDOOÿOOOÿôOOÿÿOOÿDôOÿOôOÿôôOÿÿôOÿDÿOÿOÿOÿôÿOÿÿÿOÿDDôÿODôÿôDôÿÿDôÿDOôÿOOôÿôOôÿÿOôÿDôôÿOôôÿôôôÿÿôôÿDÿôÿOÿôÿôÿôÿÿÿôÿDDÿÿODÿÿôDÿÿÿDÿÿDOÿÿOOÿÿôOÿÿÿOÿÿDôÿÿOôÿÿôôÿÿÿôÿÿDÿÿÿOÿÿÿôÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/src/m2-customcodes.asm b/src/m2-customcodes.asm index 9e529d9..d820ffa 100644 --- a/src/m2-customcodes.asm +++ b/src/m2-customcodes.asm @@ -1,5 +1,5 @@ //============================================================================== -// void parse_generic(int code, char* parserAddress, WINDOW* window, int* dest) +// void parse_generic(int code, char* parserAddress, WINDOW* window, byte* dest) // In: // r0: code // r1: parser address diff --git a/src/m2-hack.asm b/src/m2-hack.asm index 9f74bbd..780870f 100644 --- a/src/m2-hack.asm +++ b/src/m2-hack.asm @@ -1660,6 +1660,9 @@ m2_widths_tiny: m2_bits_to_nybbles: .incbin "data/m2-bits-to-nybbles.bin" +m2_bits_to_nybbles_fast: +.incbin "data/m2-bits-to-nybbles-fast.bin" + m2_nybbles_to_bits: .incbin "data/m2-nybbles-to-bits.bin" @@ -1698,7 +1701,8 @@ m2_coord_table_file: // Existing subroutines/data //============================================================================== -.definelabel overworld_buffer ,0x200C000 +.definelabel buffer_subtractor ,0x0000800 +.definelabel overworld_buffer ,0x200F200 .definelabel m2_ness_data ,0x3001D54 .definelabel m2_ness_name ,0x3001F10 .definelabel m2_old_paula_name ,0x3001F16 diff --git a/src/m2-vwf-entries.asm b/src/m2-vwf-entries.asm index d493667..e2e1b2b 100644 --- a/src/m2-vwf-entries.asm +++ b/src/m2-vwf-entries.asm @@ -491,7 +491,7 @@ beq @@next // If flag 0x10 is set, clear the PSI window ldr r0,[r5,0x1C] // PSI window -ldr r1,=#overworld_buffer - 0x2000 +ldr r1,=#overworld_buffer - buffer_subtractor bl clear_window_buffer @@next: @@ -749,7 +749,7 @@ ldrh r0,[r0] cmp r0,0 beq @@next ldr r0,=#0x3005230 -ldr r1,=#overworld_buffer - 0x2000 +ldr r1,=#overworld_buffer - buffer_subtractor ldr r0,[r0,0x1C] bl clear_window_buffer @@ -2304,7 +2304,7 @@ orr r2,r1 strb r2,[r4,#0x3] mov r3,r0 mov r0,r4 -ldr r1,=#overworld_buffer - 0x2000 +ldr r1,=#overworld_buffer - buffer_subtractor mov r4,r3 bl clear_window_buffer mov r0,r4 @@ -2594,7 +2594,7 @@ pop {r4,pc} //Prints blankstr in the buffer bb21c_print_blankstr_buffer: push {lr} -ldr r3,=#overworld_buffer - 0x2000 +ldr r3,=#overworld_buffer - buffer_subtractor bl print_blankstr_buffer pop {pc} @@ -2602,7 +2602,7 @@ pop {pc} //Prints blankstr in the buffer and stores it bb21c_print_blankstr_buffer_store: push {lr} -ldr r3,=#overworld_buffer - 0x2000 +ldr r3,=#overworld_buffer - buffer_subtractor bl print_blankstr_buffer bl store_pixels_overworld pop {pc} @@ -2969,44 +2969,25 @@ pop {pc} //============================================================================== //Loads the vram into the buffer, it's called each time there is only the main file_select window active (a good way to set the whole thing up) load_pixels_overworld: -push {r0-r1,lr} -ldr r1,=#0x40000C8 //DMA transfer 2 -ldr r0,=#0x6002000 //Source -str r0,[r1] -ldr r0,=#overworld_buffer //Target -str r0,[r1,#4] -ldr r0,=#0xA4001000 //Store 0x4000 bytes - When HBlank and in words of 32 bits -str r0,[r1,#8] -ldr r0,[r1,#8] -pop {r0-r1,pc} +push {r0-r3,lr} +bl load_pixels_overworld_buffer +pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld: -push {r0-r1,lr} -ldr r1,=#0x40000C8 //DMA transfer 2 -ldr r0,=#overworld_buffer //Source -str r0,[r1] -ldr r0,=#0x6002000 //Target -str r0,[r1,#4] -ldr r0,=#0x94001000 //Store 0x4000 bytes - When VBlank and in words of 32 bits -str r0,[r1,#8] -ldr r0,[r1,#8] -pop {r0-r1,pc} +push {r0-r3,lr} +mov r0,#0x10 +bl store_pixels_overworld_buffer +pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld_psi_window: -push {r0-r1,lr} -ldr r1,=#0x40000C8 //DMA transfer 2 -ldr r0,=#overworld_buffer //Source -str r0,[r1] -ldr r0,=#0x6002000 //Target -str r0,[r1,#4] -ldr r0,=#0x94000800 //Store 0x1800 bytes - When VBlank and in words of 32 bits -str r0,[r1,#8] -ldr r0,[r1,#8] -pop {r0-r1,pc} +push {r0-r3,lr} +mov r0,#0xA +bl store_pixels_overworld_buffer +pop {r0-r3,pc} //============================================================================== //Prints the sick tiles and then the names