fox32rom: Move rectangle drawing routines to a generic routine

This commit is contained in:
ry755 2022-02-21 21:15:16 -08:00 committed by Ry
parent 5f5771e823
commit 3fae47a36e
5 changed files with 77 additions and 73 deletions

View File

@ -32,43 +32,15 @@ fill_background_loop:
; outputs: ; outputs:
; none ; none
draw_filled_rectangle_to_background: draw_filled_rectangle_to_background:
push r0
push r1
push r2
push r3
push r4
push r5 push r5
push r6 push r6
; calculate pointer to the framebuffer mov r5, BACKGROUND_FRAMEBUFFER
mul r1, 2560 ; y * 2560 (640 * 4 = 2560) mov r6, 640
mul r0, 4 ; x * 4 call draw_filled_rectangle_generic
add r0, r1 ; y * 2560 + (x * 4)
add r0, BACKGROUND_FRAMEBUFFER ; r0: pointer to framebuffer
mov r6, r2
mul r6, 4 ; multiply the X size by 4, since 4 bytes per pixel
draw_filled_rectangle_to_background_y_loop:
mov r5, r2 ; x counter
draw_filled_rectangle_to_background_x_loop:
mov [r0], r4
add r0, 4 ; increment framebuffer pointer
dec r5
ifnz jmp draw_filled_rectangle_to_background_x_loop ; loop if there are still more X pixels to draw
sub r0, r6 ; return to the beginning of this line
add r0, 2560 ; 640*4, increment to the next line
dec r3
ifnz jmp draw_filled_rectangle_to_background_y_loop ; loop if there are still more Y pixels to draw
pop r6 pop r6
pop r5 pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
ret ret
; draw a single font tile to the background ; draw a single font tile to the background

57
draw_rectangle.asm Normal file
View File

@ -0,0 +1,57 @@
; generic rectangle drawing routines
; draw a filled rectangle to a framebuffer
; inputs:
; r0: X coordinate of top-left
; r1: Y coordinate of top-left
; r2: X size
; r3: Y size
; r4: color
; r5: pointer to framebuffer
; r6: framebuffer width (pixels)
; outputs:
; none
draw_filled_rectangle_generic:
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
; calculate pointer to the framebuffer
mul r6, 4 ; 4 bytes per pixel
mul r1, r6 ; y * width * 4
mul r0, 4 ; x * 4
add r0, r1 ; y * width * 4 + (x * 4)
add r5, r0
mov r0, r5 ; r0: pointer to framebuffer
mov r7, r6
mov r6, r2
mul r6, 4 ; multiply the X size by 4, since 4 bytes per pixel
draw_filled_rectangle_generic_y_loop:
mov r5, r2 ; x counter
draw_filled_rectangle_generic_x_loop:
mov [r0], r4
add r0, 4 ; increment framebuffer pointer
dec r5
ifnz jmp draw_filled_rectangle_generic_x_loop ; loop if there are still more X pixels to draw
sub r0, r6 ; return to the beginning of this line
add r0, r7 ; increment to the next line
dec r3
ifnz jmp draw_filled_rectangle_generic_y_loop ; loop if there are still more Y pixels to draw
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
ret

View File

@ -8,22 +8,25 @@ new_event: jmp [0xF004000C]
wait_for_event: jmp [0xF0040010] wait_for_event: jmp [0xF0040010]
get_next_event: jmp [0xF0040014] get_next_event: jmp [0xF0040014]
; generic text drawing jump table ; generic drawing jump table
draw_str_generic: jmp [0xF0041000] draw_str_generic: jmp [0xF0041000]
draw_font_tile_generic: jmp [0xF0041004] draw_font_tile_generic: jmp [0xF0041004]
draw_filled_rectangle_generic: jmp [0xF0041008]
; 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_font_tile_to_background: jmp [0xF0042008] draw_font_tile_to_background: jmp [0xF0042008]
draw_filled_rectangle_to_background: jmp [0xF004200C]
; 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_font_tile_to_overlay: jmp [0xF0043008] draw_font_tile_to_overlay: jmp [0xF0043008]
find_overlay_covering_position: jmp [0xF004300C] draw_filled_rectangle_to_overlay: jmp [0xF004300C]
check_if_overlay_covers_position: jmp [0xF0043010] find_overlay_covering_position: jmp [0xF0043010]
check_if_enabled_overlay_covers_position: jmp [0xF0043014] check_if_overlay_covers_position: jmp [0xF0043014]
check_if_enabled_overlay_covers_position: jmp [0xF0043018]
; menu bar jump table entries ; menu bar jump table entries
menu_bar_click_event: jmp [0xF0044000] menu_bar_click_event: jmp [0xF0044000]

View File

@ -173,6 +173,7 @@ get_rom_version:
#include "background.asm" #include "background.asm"
#include "boot.asm" #include "boot.asm"
#include "debug.asm" #include "debug.asm"
#include "draw_rectangle.asm"
#include "draw_text.asm" #include "draw_text.asm"
#include "event.asm" #include "event.asm"
#include "memory.asm" #include "memory.asm"
@ -197,22 +198,25 @@ get_rom_version:
data.32 wait_for_event data.32 wait_for_event
data.32 get_next_event data.32 get_next_event
; generic text 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_font_tile_generic data.32 draw_font_tile_generic
data.32 draw_filled_rectangle_generic
; background jump table ; background jump table
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_font_tile_to_background data.32 draw_font_tile_to_background
data.32 draw_filled_rectangle_to_background
; overlay jump table ; overlay jump table
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_font_tile_to_overlay data.32 draw_font_tile_to_overlay
data.32 draw_filled_rectangle_to_overlay
data.32 find_overlay_covering_position data.32 find_overlay_covering_position
data.32 check_if_overlay_covers_position data.32 check_if_overlay_covers_position
data.32 check_if_enabled_overlay_covers_position data.32 check_if_enabled_overlay_covers_position

View File

@ -44,52 +44,20 @@ fill_overlay_loop:
; outputs: ; outputs:
; none ; none
draw_filled_rectangle_to_overlay: draw_filled_rectangle_to_overlay:
push r0
push r1
push r2
push r3
push r4
push r5 push r5
push r6 push r6
push r7
; calculate pointer to the framebuffer mov r6, r5
mov r6, r5 ; r6: overlay number
or r6, 0x80000100 ; bitwise or the overlay number with the command to get the overlay size or r6, 0x80000100 ; bitwise or the overlay number with the command to get the overlay size
in r7, r6
and r7, 0x0000FFFF ; mask off the height, we only need the width
mul r7, 4 ; r7: overlay width in bytes (width * 4)
mul r1, r7 ; y * width * 4
mul r0, 4 ; x * 4
add r0, r1 ; y * width * 4 + (x * 4)
or r5, 0x80000200 ; bitwise or the overlay number with the command to get the framebuffer pointer or r5, 0x80000200 ; bitwise or the overlay number with the command to get the framebuffer pointer
in r5, r5 in r5, r5 ; r5: overlay framebuffer poiner
add r0, r5 ; r0: pointer to framebuffer in r6, r6
and r6, 0x0000FFFF ; r6: overlay width
mov r6, r2 call draw_filled_rectangle_generic
mul r6, 4 ; multiply the X size by 4, since 4 bytes per pixel
draw_filled_rectangle_to_overlay_y_loop:
mov r5, r2 ; x counter
draw_filled_rectangle_to_overlay_x_loop:
mov [r0], r4
add r0, 4 ; increment framebuffer pointer
dec r5
ifnz jmp draw_filled_rectangle_to_overlay_x_loop ; loop if there are still more X pixels to draw
sub r0, r6 ; return to the beginning of this line
add r0, r7 ; increment to the next line
dec r3
ifnz jmp draw_filled_rectangle_to_overlay_y_loop ; loop if there are still more Y pixels to draw
pop r7
pop r6 pop r6
pop r5 pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
ret ret
; draw a single font tile to an overlay ; draw a single font tile to an overlay