Add more generic tile drawing routines

This commit is contained in:
Ry 2022-06-21 18:08:16 -07:00
parent f52c279fcd
commit e158dd3bc5
5 changed files with 144 additions and 9 deletions

View File

@ -62,6 +62,25 @@ draw_filled_rectangle_to_background:
pop r5 pop r5
ret ret
; draw a single tile to the background
; inputs:
; r0: tile number
; r1: X coordinate
; r2: Y coordinate
; outputs:
; none
draw_tile_to_background:
push r8
push r9
mov r8, BACKGROUND_FRAMEBUFFER
mov r9, 640
call draw_tile_generic
pop r9
pop r8
ret
; draw a single font tile to the background ; draw a single font tile to the background
; inputs: ; inputs:
; r0: tile number ; r0: tile number

80
draw_tile.asm Normal file
View File

@ -0,0 +1,80 @@
; generic tile drawing routines
const TILEMAP_POINTER: 0x01FFFFF0
const TILEMAP_WIDTH: 0x01FFFFF4
const TILEMAP_HEIGHT: 0x01FFFFF8
; set the current tilemap
; inputs:
; r0: pointer to tilemap data
; r1: tile width
; r2: tile height
set_tilemap:
mov [TILEMAP_POINTER], r0
mov [TILEMAP_WIDTH], r1
mov [TILEMAP_HEIGHT], r2
ret
; draw a single tile to a framebuffer
; inputs:
; r0: tile number
; r1: X coordinate
; r2: Y coordinate
; r8: pointer to framebuffer
; r9: framebuffer width (pixels)
; outputs:
; none
draw_tile_generic:
push r0
push r1
push r2
push r5
push r6
push r7
push r8
push r9
; calculate pointer to the tile data
mov r6, [TILEMAP_WIDTH]
mov r7, [TILEMAP_HEIGHT]
push r6
mul r6, r7
mul r0, r6
mul r0, 4 ; 4 bytes per pixel
add r0, [TILEMAP_POINTER] ; r0: pointer to tile data
pop r6
; calculate pointer to the framebuffer
mul r9, 4 ; 4 bytes per pixel
mul r2, r9 ; y * width * 4
mul r1, 4 ; x * 4
add r1, r2 ; y * width * 4 + (x * 4)
add r1, r8 ; r1: pointer to framebuffer
; r8: tile width in bytes
mov r8, r6
mul r8, 4
draw_tile_generic_y_loop:
mov r5, r6 ; x counter
draw_tile_generic_x_loop:
mov [r1], [r0] ; draw pixel
add r0, 4 ; increment tile pointer
add r1, 4 ; increment framebuffer pointer
dec r5
ifnz jmp draw_tile_generic_x_loop ; loop if there are still more X pixels to draw
sub r1, r8 ; return to the beginning of this line
add r1, r9 ; increment to the next line by adding the framebuffer width in bytes
dec r7 ; decrement height counter
ifnz jmp draw_tile_generic_y_loop ; loop if there are still more Y pixels to draw
pop r9
pop r8
pop r7
pop r6
pop r5
pop r2
pop r1
pop r0
ret

View File

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

View File

@ -121,6 +121,7 @@ get_rom_version:
#include "draw_pixel.asm" #include "draw_pixel.asm"
#include "draw_rectangle.asm" #include "draw_rectangle.asm"
#include "draw_text.asm" #include "draw_text.asm"
#include "draw_tile.asm"
#include "event.asm" #include "event.asm"
#include "integer.asm" #include "integer.asm"
#include "keyboard.asm" #include "keyboard.asm"
@ -157,6 +158,7 @@ get_rom_version:
data.32 draw_format_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_tile_generic
data.32 draw_pixel_generic data.32 draw_pixel_generic
data.32 draw_filled_rectangle_generic data.32 draw_filled_rectangle_generic
@ -168,6 +170,7 @@ get_rom_version:
data.32 draw_decimal_to_background data.32 draw_decimal_to_background
data.32 draw_hex_to_background data.32 draw_hex_to_background
data.32 draw_font_tile_to_background data.32 draw_font_tile_to_background
data.32 draw_tile_to_background
data.32 draw_pixel_to_background data.32 draw_pixel_to_background
data.32 draw_filled_rectangle_to_background data.32 draw_filled_rectangle_to_background
@ -179,6 +182,7 @@ get_rom_version:
data.32 draw_decimal_to_overlay data.32 draw_decimal_to_overlay
data.32 draw_hex_to_overlay data.32 draw_hex_to_overlay
data.32 draw_font_tile_to_overlay data.32 draw_font_tile_to_overlay
data.32 draw_tile_to_overlay
data.32 draw_pixel_to_overlay data.32 draw_pixel_to_overlay
data.32 draw_filled_rectangle_to_overlay data.32 draw_filled_rectangle_to_overlay
data.32 find_overlay_covering_position data.32 find_overlay_covering_position

View File

@ -85,6 +85,35 @@ draw_filled_rectangle_to_overlay:
pop r5 pop r5
ret ret
; draw a single tile to an overlay
; inputs:
; r0: tile number
; r1: X coordinate
; r2: Y coordinate
; r3: overlay number
; outputs:
; none
draw_tile_to_overlay:
push r3
push r4
push r8
push r9
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 r8, r3 ; r8: overlay framebuffer poiner
in r9, r4
and r9, 0x0000FFFF ; r9: overlay width
call draw_tile_generic
pop r9
pop r8
pop r4
pop r3
ret
; draw a single font tile to an overlay ; draw a single font tile to an overlay
; inputs: ; inputs:
; r0: tile number ; r0: tile number