Preliminary string printing

Had to change the signature of the base
print_chr function because the file select
screen uses a lot of non-standard memory
layouts. For example, the tilemap has a
variable width instead of the standard 32
tiles.
This commit is contained in:
jeffman 2019-08-03 20:33:28 -04:00
parent da515e5112
commit 1c1968e3ab
5 changed files with 82 additions and 9 deletions

View File

@ -16,8 +16,23 @@ It seems to get fully overwritten, so we can replace it with all blank tiles
----
We also need to blank out the font that gets loaded to VRAM at 6008000
We also need to blank out the font that gets decompressed from 86D9808 to VRAM at 6008000
----
Note that the palette on these screens uses 0x1 for background, 0x9 for foreground
----
We need to allocate more space for the strings... The same only allocates 32 bytes per file slot,
but we need at least 41:
"X: " 3
"NAME " 5
[FE 5F xx] 3
"Level: XX" 9
[FE 5F xx] 3
"Text speed: Medium" 18
= 41
~8001EAE: file slot number formatting

View File

@ -46,6 +46,56 @@ byte reduce_bit_depth(int row, int foreground)
return lower | (upper << 4);
}
void print_file_string(int x, int y, int length, byte *str, int unknown)
{
int *tilesetBasePtr = (int *)(0x82B79B4 + (unknown * 20));
int width = tilesetBasePtr[2];
unsigned short *tilesetDestPtr = (unsigned short *)(tilesetBasePtr[0]);
int pixelX = x * 8;
int pixelY = y * 8;
for (int i = 0; i < length; i++)
{
byte chr = str[i];
if (chr == 0xFF)
{
break; // the game does something else here, haven't looked into what exactly
}
else if (chr == 0xFE)
{
// Define 0xFE as a control code
byte cmd = str[++i];
switch (cmd)
{
case CUSTOMCC_ADD_X:
pixelX += str[++i];
break;
case CUSTOMCC_SET_X:
pixelX = str[++i];
break;
}
continue;
}
chr = decode_character(chr);
int pixels = print_character_with_callback(
chr,
pixelX,
pixelY,
0,
9,
vram + 0x2000,
&get_tile_number_grid,
tilesetDestPtr,
width);
pixelX += pixels;
}
}
byte print_character(byte chr, int x, int y)
{
return print_character_formatted(chr, x, y, 0, 0xF);
@ -67,12 +117,12 @@ byte print_character_formatted(byte chr, int x, int y, int font, int foreground)
return 8;
}
return print_character_with_callback(chr, x, y, font, foreground, vram, &get_tile_number_with_offset, TRUE);
return print_character_with_callback(chr, x, y, font, foreground, vram, &get_tile_number_with_offset, *tilemap_pointer, 32);
}
byte print_character_to_ram(byte chr, int *dest, int xOffset, int font, int foreground)
{
return print_character_with_callback(chr, xOffset, 0, font, foreground, dest, &get_tile_number_grid, FALSE);
return print_character_with_callback(chr, xOffset, 0, font, foreground, dest, &get_tile_number_grid, NULL, 32);
}
// Prints a special tile. Pixels are copied to the VWF buffer.
@ -110,7 +160,7 @@ 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), int useTilemap)
int *dest, int (*getTileCallback)(int, int), unsigned short *tilemapPtr, int tilemapWidth)
{
int tileWidth = m2_font_widths[font];
int tileHeight = m2_font_heights[font];
@ -149,8 +199,8 @@ byte print_character_with_callback(byte chr, int x, int y, int font, int foregro
dest[(tileIndex * 8) + row] = canvasRow;
}
if (useTilemap)
(*tilemap_pointer)[tileX + dTileX + ((tileY + dTileY) * 32)] = paletteMask | tileIndex;
if (tilemapPtr != NULL)
tilemapPtr[tileX + dTileX + ((tileY + dTileY) * tilemapWidth)] = paletteMask | tileIndex;
if (renderedWidth - leftPortionWidth > 0 && leftPortionWidth < 8)
{
@ -171,8 +221,8 @@ byte print_character_with_callback(byte chr, int x, int y, int font, int foregro
dest[(tileIndex * 8) + row] = canvasRow;
}
if (useTilemap)
(*tilemap_pointer)[tileX + dTileX + 1 + ((tileY + dTileY) * 32)] = paletteMask | tileIndex;
if (tilemapPtr != NULL)
tilemapPtr[tileX + dTileX + 1 + ((tileY + dTileY) * tilemapWidth)] = paletteMask | tileIndex;
}
renderedWidth -= 8;

View File

@ -35,7 +35,7 @@ void print_special_character(int tile, int x, int y);
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), int useTilemap);
int *dest, int (*getTileCallback)(int, int), unsigned short *tilemapPtr, int tilemapWidth);
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);
@ -65,6 +65,7 @@ void print_number_menu_current(byte digit, WINDOW* window);
void clear_number_menu(WINDOW* window);
void format_cash_window(int value, int padding, byte* str);
void handle_first_window(WINDOW* window);
void print_file_string(int x, int y, int length, byte *str, int unknown);
extern unsigned short m2_coord_table[];
extern int m2_bits_to_nybbles[];

Binary file not shown.

View File

@ -972,6 +972,13 @@ nop
.org 0x86DB070
.incbin "data/m2-fileselect-template.bin"
.org 0x86D9808
.incbin "data/m2-fileselect-tileset.bin"
.org 0x80038CE :: bl print_file_string
.org 0x80038E0 :: bl print_file_string
.org 0x80038F4 :: bl print_file_string
//==============================================================================
// Data files
//==============================================================================