FillRect example

This commit is contained in:
neauoire 2021-02-11 13:28:13 -08:00
parent 37f3865e54
commit 48d4289671
2 changed files with 80 additions and 1 deletions

View File

@ -24,5 +24,5 @@ rm -f ./bin/emulator
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator
# run # run
./bin/assembler examples/pixels.usm bin/boot.rom ./bin/assembler examples/draw.usm bin/boot.rom
./bin/emulator bin/boot.rom ./bin/emulator bin/boot.rom

79
examples/draw.usm Normal file
View File

@ -0,0 +1,79 @@
( draw routines )
:dev/r fff8 ( std read port )
:dev/w fff9 ( std write port )
;x_ 2 ;y_ 2
;x 2 ;y 2 ;w 2 ;h 2
;color 1
|0100 @RESET
( set dev/write to screen )
,01 ,dev/w STR
( set color 1 )
,03 ,color STR
,01 ,color STR
( fill rect x y w h )
,0020 ,0020 ,0060 ,0040 ,fillrect JSR
,02 ,color STR
( fill rect x y w h )
,0030 ,0030 ,0040 ,0060 ,fillrect JSR
,03 ,color STR
( fill rect x y w h )
,0040 ,0040 ,0060 ,0040 ,fillrect JSR
,redraw JSR
BRK
@redraw
,0000 IOW^
,0000 IOW^
,00 IOW
,01 IOW
RTS
@putpixel
IOW^ ( y short )
IOW^ ( x short )
,color LDR IOW ( color byte )
,00 IOW ( redraw byte )
RTS
@fillrect
( store shape )
,h STR^ ,w STR^ ,y STR^ ,x STR^
( set head )
,x LDR^ ,x_ STR^ ,y LDR^ ,y_ STR^
( paint row )
,fillrectrow JSR
RTS
@fillrectcol
,x_ LDR^ ,y_ LDR^ ,putpixel JSR
( incr x )
,x_ LDR^ ,0001 ADD^ ,x_ STR^
( check if greater than w )
,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ GTH^ RTS?
,fillrectcol JMP
RTS
@fillrectrow
,x LDR^ ,x_ STR^
,fillrectcol JSR
( incr x )
,y_ LDR^ ,0001 ADD^ ,y_ STR^
( check if greater than w )
,y_ LDR^ ,h LDR^ ,y LDR^ ADD^ GTH^ RTS?
,fillrectrow JMP
RTS
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR