0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-08 15:25:05 +00:00
uxn/examples/draw.usm

133 lines
3.2 KiB
Text
Raw Normal View History

2021-02-11 21:28:13 +00:00
( draw routines )
:dev/r fff8 ( std read port )
:dev/w fff9 ( std write port )
2021-02-11 21:56:27 +00:00
;x_ 2 ;y_ 2 ;x 2 ;y 2 ;w 2 ;h 2 ;color 1
2021-02-13 03:51:39 +00:00
;x0 2 ;y0 2 ;x1 2 ;y1 2 ;dx 2 ;dy 2 ;err1 2 ;err2 2 ( line )
2021-02-11 21:28:13 +00:00
|0100 @RESET
( set dev/write to screen )
,01 ,dev/w 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
2021-02-11 21:56:27 +00:00
,01 ,color STR
( fill rect x y w h )
,00a0 ,0010 ,0020 ,0020 ,fillrect JSR
2021-02-12 02:48:45 +00:00
,02 ,color STR
( fill rect x y w h )
,00b0 ,0040 ,0020 ,0020 ,linerect JSR
,03 ,color STR
( fill rect x y w h )
,0058 ,0028 ,0050 ,0050 ,linerect JSR
,01 ,color STR
( fill rect x y w h )
,0028 ,0038 ,0050 ,0030 ,linerect JSR
2021-02-13 03:51:39 +00:00
( positive )
,01 ,color STR
2021-02-13 16:38:23 +00:00
+0030 ,x0 STR2 +0040 ,y0 STR2
+0100 ,x1 STR2 +0060 ,y1 STR2
2021-02-13 03:51:39 +00:00
,line JSR
,02 ,color STR
2021-02-13 16:38:23 +00:00
+0020 ,x0 STR2 +0010 ,y0 STR2
+0090 ,x1 STR2 +0070 ,y1 STR2
2021-02-13 03:51:39 +00:00
,line JSR
,03 ,color STR
2021-02-13 16:38:23 +00:00
+0010 ,x0 STR2 +0040 ,y0 STR2
+0070 ,x1 STR2 +0060 ,y1 STR2
2021-02-13 03:51:39 +00:00
,line JSR
2021-02-11 21:28:13 +00:00
,redraw JSR
BRK
2021-02-11 21:56:27 +00:00
@fillrect
2021-02-13 16:38:23 +00:00
,h STR2 ,w STR2 ,y STR2 ,x STR2
,x LDR2 ,x_ STR2 ,y LDR2 ,y_ STR2
2021-02-11 21:56:27 +00:00
@fillrectrow
2021-02-13 16:38:23 +00:00
,x LDR2 ,x_ STR2
2021-02-11 21:56:27 +00:00
@fillrectcol
2021-02-13 16:38:23 +00:00
( draw ) ,x_ LDR2 ,y_ LDR2 ,putpixel JSR
,x_ LDR2 ,0001 ADD2 ,x_ STR2
,x_ LDR2 ,w LDR2 ,x LDR2 ADD2 LTH2 ,fillrectcol ROT JMP? POP2
,y_ LDR2 ,0001 ADD2 ,y_ STR2
,y_ LDR2 ,h LDR2 ,y LDR2 ADD2 LTH2 ,fillrectrow ROT JMP? POP2
2021-02-11 21:56:27 +00:00
RTS
2021-02-12 02:48:45 +00:00
@linerect
2021-02-13 16:38:23 +00:00
,h STR2 ,w STR2 ,y STR2 ,x STR2
,x LDR2 ,x_ STR2 ,y LDR2 ,y_ STR2
2021-02-12 02:48:45 +00:00
@linerectcol
2021-02-13 16:38:23 +00:00
( draw ) ,x LDR2 ,y_ LDR2 ,putpixel JSR
( draw ) ,x LDR2 ,w LDR2 ADD2 ,y_ LDR2 ,putpixel JSR
,y_ LDR2 ,0001 ADD2 ,y_ STR2
,y_ LDR2 ,h LDR2 ,y LDR2 ADD2 LTH2 ,linerectcol ROT JMP? POP2
2021-02-12 02:48:45 +00:00
@linerectrow
2021-02-13 16:38:23 +00:00
( draw ) ,x_ LDR2 ,y LDR2 ,putpixel JSR
( draw ) ,x_ LDR2 ,y LDR2 ,h LDR2 ADD2 ,putpixel JSR
,x_ LDR2 ,0001 ADD2 ,x_ STR2
,x_ LDR2 ,w LDR2 ,x LDR2 ADD2 ,0001 ADD2 LTH2 ,linerectrow ROT JMP? POP2
2021-02-12 02:48:45 +00:00
RTS
2021-02-13 03:51:39 +00:00
@line
2021-02-13 16:38:23 +00:00
,x0 LDR2 ,x_ STR2 ,y0 LDR2 ,y_ STR2 ( start at x0,y0 )
,x1 LDR2 ,x0 LDR2 ,diff16sub JSR ,dx STR2 ( int dx = abs[x1 - x0] )
,y1 LDR2 ,y0 LDR2 ,diff16sub JSR -0001 MULS2 ,dy STR2 ( int dy = -abs[y1 - y0] )
,dx LDR2 ,dy LDR2 ADDS2 ,err1 STR2 ( int err1 = dx + dy, e2; )
2021-02-13 03:51:39 +00:00
@lineloop
2021-02-13 16:38:23 +00:00
,x_ LDR2 ,y_ LDR2 ,putpixel JSR ( draw )
2021-02-13 03:51:39 +00:00
@line-x
2021-02-13 16:38:23 +00:00
,err1 LDR2 +0002 MULS2 ,err2 STR2 ( e2 = 2 * err; )
,err2 LDR2 ,dy LDR2 LTHS2 ,line-y ROT JMP? POP2 ( e2 >= dy )
,err1 LDR2 ,dy LDR2 ADDS2 ,err1 STR2 ( err1 += dy; )
,x_ LDR2 +0001 ADDS2 ,x_ STR2 ( y0 += y0 < y1 ? 1 : -1; )
2021-02-13 03:51:39 +00:00
@line-y
2021-02-13 16:38:23 +00:00
,err2 LDR2 ,dx LDR2 GTHS2 ,line-end ROT JMP? POP2 ( e2 <= dx )
,err1 LDR2 ,dx LDR2 ADDS2 ,err1 STR2 ( err1 += dx; )
,y_ LDR2 +0001 ADDS2 ,y_ STR2 ( y0 += y0 < y1 ? 1 : -1; )
2021-02-13 03:51:39 +00:00
@line-end
2021-02-13 16:38:23 +00:00
,x_ LDR2 ,x1 LDR2 NEQS2 ,lineloop ROT JMP? POP2 ( loop )
2021-02-13 03:51:39 +00:00
RTS
@diff16
2021-02-13 16:38:23 +00:00
OVR2 OVR2 GTH2 ,diff16sub ROT JMP? POP2
SWP2 @diff16sub SUB2
2021-02-13 03:51:39 +00:00
RTS
2021-02-11 21:28:13 +00:00
@redraw
2021-02-13 16:38:23 +00:00
,0000 IOW2
,0000 IOW2
2021-02-11 21:28:13 +00:00
,00 IOW
,01 IOW
RTS
@putpixel
2021-02-13 16:38:23 +00:00
IOW2 ( y short )
IOW2 ( x short )
2021-02-11 21:28:13 +00:00
,color LDR IOW ( color byte )
,00 IOW ( redraw byte )
RTS
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR