fox32rom: Add draw_pixel routines

This commit is contained in:
Ry 2022-04-16 16:13:16 -07:00
parent 7f830cdceb
commit 8b2df35475
5 changed files with 89 additions and 6 deletions

View File

@ -22,6 +22,25 @@ fill_background_loop:
pop r1
ret
; draw a pixel to the background
; inputs:
; r0: X coordinate
; r1: Y coordinate
; r2: color
; outputs:
; none
draw_pixel_to_background:
push r5
push r6
mov r3, BACKGROUND_FRAMEBUFFER
mov r4, 640
call draw_pixel_generic
pop r6
pop r5
ret
; draw a filled rectangle to the background
; inputs:
; r0: X coordinate of top-left

32
draw_pixel.asm Normal file
View File

@ -0,0 +1,32 @@
; generic pixel drawing routines
; draw a pixel to a framebuffer
; inputs:
; r0: X coordinate
; r1: Y coordinate
; r2: color
; r3: pointer to framebuffer
; r4: framebuffer width (pixels)
; outputs:
; none
draw_pixel_generic:
push r0
push r1
push r3
push r4
; calculate pointer to the framebuffer
mul r4, 4 ; 4 bytes per pixel
mul r1, r4 ; y * width * 4
mul r0, 4 ; x * 4
add r0, r1 ; y * width * 4 + (x * 4)
add r3, r0
mov r0, r3 ; r0: pointer to framebuffer
mov [r0], r2
pop r4
pop r3
pop r1
pop r0
ret

View File

@ -15,7 +15,8 @@ draw_format_str_generic: jmp [0xF0041004]
draw_decimal_generic: jmp [0xF0041008]
draw_hex_generic: jmp [0xF004100C]
draw_font_tile_generic: jmp [0xF0041010]
draw_filled_rectangle_generic: jmp [0xF0041014]
draw_pixel_generic: jmp [0xF0041014]
draw_filled_rectangle_generic: jmp [0xF0041018]
; background jump table entries
fill_background: jmp [0xF0042000]
@ -24,7 +25,8 @@ draw_format_str_to_background: jmp [0xF0042008]
draw_decimal_to_background: jmp [0xF004200C]
draw_hex_to_background: jmp [0xF0042010]
draw_font_tile_to_background: jmp [0xF0042014]
draw_filled_rectangle_to_background: jmp [0xF0042018]
draw_pixel_to_background: jmp [0xF0042018]
draw_filled_rectangle_to_background: jmp [0xF004201C]
; overlay jump table entries
fill_overlay: jmp [0xF0043000]
@ -33,10 +35,11 @@ draw_format_str_to_overlay: jmp [0xF0043008]
draw_decimal_to_overlay: jmp [0xF004300C]
draw_hex_to_overlay: jmp [0xF0043010]
draw_font_tile_to_overlay: jmp [0xF0043014]
draw_filled_rectangle_to_overlay: jmp [0xF0043018]
find_overlay_covering_position: jmp [0xF004301C]
check_if_overlay_covers_position: jmp [0xF0043020]
check_if_enabled_overlay_covers_position: jmp [0xF0043024]
draw_pixel_to_overlay: jmp [0xF0043018]
draw_filled_rectangle_to_overlay: jmp [0xF004301C]
find_overlay_covering_position: jmp [0xF0043020]
check_if_overlay_covers_position: jmp [0xF0043024]
check_if_enabled_overlay_covers_position: jmp [0xF0043028]
; menu bar jump table entries
enable_menu_bar: jmp [0xF0044000]

View File

@ -132,6 +132,7 @@ get_rom_version:
#include "boot.asm"
#include "debug.asm"
#include "disk.asm"
#include "draw_pixel.asm"
#include "draw_rectangle.asm"
#include "draw_text.asm"
#include "event.asm"
@ -165,6 +166,7 @@ get_rom_version:
data.32 draw_format_str_generic
data.32 draw_decimal_generic
data.32 draw_font_tile_generic
data.32 draw_pixel_generic
data.32 draw_filled_rectangle_generic
; background jump table
@ -174,6 +176,7 @@ get_rom_version:
data.32 draw_format_str_to_background
data.32 draw_decimal_to_background
data.32 draw_font_tile_to_background
data.32 draw_pixel_to_background
data.32 draw_filled_rectangle_to_background
; overlay jump table
@ -183,6 +186,7 @@ get_rom_version:
data.32 draw_format_str_to_overlay
data.32 draw_decimal_to_overlay
data.32 draw_font_tile_to_overlay
data.32 draw_pixel_to_overlay
data.32 draw_filled_rectangle_to_overlay
data.32 find_overlay_covering_position
data.32 check_if_overlay_covers_position

View File

@ -33,6 +33,31 @@ fill_overlay_loop:
pop r1
ret
; draw a pixel to an overlay
; inputs:
; r0: X coordinate
; r1: Y coordinate
; r2: color
; r3: overlay number
; outputs:
; none
draw_pixel_to_overlay:
push r3
push r4
mov r4, r3
or r4, 0x80000100 ; bitwise or the overlay number with the command to get the overlay size
or r3, 0x80000200 ; bitwise or the overlay number with the command to get the framebuffer pointer
in r3, r3 ; r3: overlay framebuffer poiner
in r4, r4
and r4, 0x0000FFFF ; r4: overlay width
call draw_pixel_generic
pop r4
pop r3
ret
; draw a filled rectangle to an overlay
; inputs:
; r0: X coordinate of top-left