fox32rom: Start implementing a basic string formatting system

This commit is contained in:
ry755 2022-02-22 13:45:54 -08:00 committed by Ry
parent f17a15b14a
commit 72258d063f
5 changed files with 194 additions and 12 deletions

View File

@ -73,6 +73,37 @@ draw_font_tile_to_background:
pop r5 pop r5
ret ret
; draw text to the background, using printf-style formatting
; inputs:
; r0: pointer to null-terminated string
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; r10-r15: optional format values
; outputs:
; r1: X coordinate of end of text
draw_format_str_to_background:
push r5
push r6
push r7
push r8
push r9
mov r5, standard_font_data
movz.16 r6, [standard_font_width]
movz.16 r7, [standard_font_height]
mov r8, BACKGROUND_FRAMEBUFFER
mov r9, 640
call draw_format_str_generic
pop r9
pop r8
pop r7
pop r6
pop r5
ret
; draw text to the background ; draw text to the background
; inputs: ; inputs:
; r0: pointer to null-terminated string ; r0: pointer to null-terminated string

View File

@ -81,6 +81,114 @@ draw_font_tile_generic_x_loop_end:
pop r0 pop r0
ret ret
; draw text to a framebuffer, using printf-style formatting
; inputs:
; r0: pointer to null-terminated string
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; r5: pointer to font graphics
; r6: font width
; r7: font height
; r8: pointer to framebuffer
; r9: framebuffer width
; r10-r15: optional format values
; outputs:
; r1: X coordinate of end of text
draw_format_str_generic:
push r0
push r1
push r2
push r5
push r6
push r7
push r8
push r9
push r16
push r17
mov r16, 0 ; current format specifier counter
draw_format_str_generic_loop:
cmp.8 [r0], 0
ifz jmp draw_format_str_generic_end
cmp.8 [r0], '\'
ifz jmp draw_format_str_generic_found_format_specifier
; if this is not a format specifier or the end of the string, print the character
push r0
movz.8 r0, [r0]
call draw_font_tile_generic
pop r0
add r1, r6 ; add the font width to the X coordinate
inc r0
jmp draw_format_str_generic_loop
draw_format_str_generic_found_format_specifier:
inc r0
; unsigned decimal
cmp.8 [r0], 'u'
ifz call draw_format_str_generic_unsigned_decimal
inc r0
jmp draw_format_str_generic_loop
draw_format_str_generic_unsigned_decimal:
call draw_format_str_generic_get_parameter
push r0
mov r0, r17
call draw_decimal_generic
pop r0
inc r16
ret
draw_format_str_generic_get_parameter:
; load the correct format parameter into r17
; this is messy, but i don't know of any other way to do this at the moment
cmp r16, 0
ifz jmp draw_format_str_generic_get_parameter_0
cmp r16, 1
ifz jmp draw_format_str_generic_get_parameter_1
cmp r16, 2
ifz jmp draw_format_str_generic_get_parameter_2
cmp r16, 3
ifz jmp draw_format_str_generic_get_parameter_3
cmp r16, 4
ifz jmp draw_format_str_generic_get_parameter_4
cmp r16, 5
ifz jmp draw_format_str_generic_get_parameter_5
mov r17, 0
ret
draw_format_str_generic_get_parameter_0:
mov r17, r10
ret
draw_format_str_generic_get_parameter_1:
mov r17, r11
ret
draw_format_str_generic_get_parameter_2:
mov r17, r12
ret
draw_format_str_generic_get_parameter_3:
mov r17, r13
ret
draw_format_str_generic_get_parameter_4:
mov r17, r14
ret
draw_format_str_generic_get_parameter_5:
mov r17, r15
ret
draw_format_str_generic_end:
pop r17
pop r16
pop r9
pop r8
pop r7
pop r6
pop r5
pop r2
pop r1
pop r0
ret
; draw text to a framebuffer ; draw text to a framebuffer
; inputs: ; inputs:
; r0: pointer to null-terminated string ; r0: pointer to null-terminated string

View File

@ -10,26 +10,29 @@ get_next_event: jmp [0xF0040014]
; generic drawing jump table ; generic drawing jump table
draw_str_generic: jmp [0xF0041000] draw_str_generic: jmp [0xF0041000]
draw_decimal_generic: jmp [0xF0041004] draw_format_str_generic: jmp [0xF0041004]
draw_font_tile_generic: jmp [0xF0041008] draw_decimal_generic: jmp [0xF0041008]
draw_filled_rectangle_generic: jmp [0xF004100C] draw_font_tile_generic: jmp [0xF004100C]
draw_filled_rectangle_generic: jmp [0xF0041010]
; background jump table entries ; background jump table entries
fill_background: jmp [0xF0042000] fill_background: jmp [0xF0042000]
draw_str_to_background: jmp [0xF0042004] draw_str_to_background: jmp [0xF0042004]
draw_decimal_to_background: jmp [0xF0042008] draw_format_str_to_background: jmp [0xF0042008]
draw_font_tile_to_background: jmp [0xF004200C] draw_decimal_to_background: jmp [0xF004200C]
draw_filled_rectangle_to_background: jmp [0xF0042010] draw_font_tile_to_background: jmp [0xF0042010]
draw_filled_rectangle_to_background: jmp [0xF0042014]
; overlay jump table entries ; overlay jump table entries
fill_overlay: jmp [0xF0043000] fill_overlay: jmp [0xF0043000]
draw_str_to_overlay: jmp [0xF0043004] draw_str_to_overlay: jmp [0xF0043004]
draw_decimal_to_overlay: jmp [0xF0043008] draw_format_str_to_overlay: jmp [0xF0043008]
draw_font_tile_to_overlay: jmp [0xF004300C] draw_decimal_to_overlay: jmp [0xF004300C]
draw_filled_rectangle_to_overlay: jmp [0xF0043010] draw_font_tile_to_overlay: jmp [0xF0043010]
find_overlay_covering_position: jmp [0xF0043014] draw_filled_rectangle_to_overlay: jmp [0xF0043014]
check_if_overlay_covers_position: jmp [0xF0043018] find_overlay_covering_position: jmp [0xF0043018]
check_if_enabled_overlay_covers_position: jmp [0xF004301C] check_if_overlay_covers_position: jmp [0xF004301C]
check_if_enabled_overlay_covers_position: jmp [0xF0043020]
; menu bar jump table entries ; menu bar jump table entries
menu_bar_click_event: jmp [0xF0044000] menu_bar_click_event: jmp [0xF0044000]

View File

@ -201,6 +201,7 @@ get_rom_version:
; generic drawing jump table ; generic drawing jump table
org.pad 0xF0041000 org.pad 0xF0041000
data.32 draw_str_generic data.32 draw_str_generic
data.32 draw_format_str_generic
data.32 draw_decimal_generic data.32 draw_decimal_generic
data.32 draw_font_tile_generic data.32 draw_font_tile_generic
data.32 draw_filled_rectangle_generic data.32 draw_filled_rectangle_generic
@ -209,6 +210,7 @@ get_rom_version:
org.pad 0xF0042000 org.pad 0xF0042000
data.32 fill_background data.32 fill_background
data.32 draw_str_to_background data.32 draw_str_to_background
data.32 draw_format_str_to_background
data.32 draw_decimal_to_background data.32 draw_decimal_to_background
data.32 draw_font_tile_to_background data.32 draw_font_tile_to_background
data.32 draw_filled_rectangle_to_background data.32 draw_filled_rectangle_to_background
@ -217,6 +219,7 @@ get_rom_version:
org.pad 0xF0043000 org.pad 0xF0043000
data.32 fill_overlay data.32 fill_overlay
data.32 draw_str_to_overlay data.32 draw_str_to_overlay
data.32 draw_format_str_to_overlay
data.32 draw_decimal_to_overlay data.32 draw_decimal_to_overlay
data.32 draw_font_tile_to_overlay data.32 draw_font_tile_to_overlay
data.32 draw_filled_rectangle_to_overlay data.32 draw_filled_rectangle_to_overlay

View File

@ -96,6 +96,43 @@ draw_font_tile_to_overlay:
pop r5 pop r5
ret ret
; draw text to an overlay, using printf-style formatting
; inputs:
; r0: pointer to null-terminated string
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; r5: overlay number
; r10-r15: optional format values
; outputs:
; r1: X coordinate of end of text
draw_format_str_to_overlay:
push r5
push r6
push r7
push r8
push r9
mov r6, r5
or r6, 0x80000100 ; bitwise or the overlay number with the command to get the overlay size
or r5, 0x80000200 ; bitwise or the overlay number with the command to get the framebuffer pointer
in r8, r5 ; r8: overlay framebuffer poiner
in r9, r6
and r9, 0x0000FFFF ; r9: overlay width
mov r5, standard_font_data
movz.16 r6, [standard_font_width]
movz.16 r7, [standard_font_height]
call draw_format_str_generic
pop r9
pop r8
pop r7
pop r6
pop r5
ret
; draw text to an overlay ; draw text to an overlay
; inputs: ; inputs:
; r0: pointer to null-terminated string ; r0: pointer to null-terminated string