~rabbits/uxn

ref: d2c3d0e524e801485c3f5cae89ea976d8146941f uxn/projects/examples/devices/screen.tal -rw-r--r-- 2.2 KiB
d2c3d0e5neauoire Started implementing the sprite port for the screen device 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
( dev/screen )

%RTN { JMP2r }
%MOD { DUP2 DIV MUL SUB }
%2// { #01 SFT2 }

( devices )

|00 @System     [ &vector $2 &pad      $6 &r      $2 &g     $2 &b      $2 ]
|20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y     $2 &addr $2 &color $1 &sprite $1 ]

( variables )

|0000

@center [ &x $2 &y $2 ]

( init )

|0100 ( -> )
	
	( theme ) 
	#025f .System/r DEO2
	#0c2f .System/g DEO2 
	#0da4 .System/b DEO2 

	( find screen center )
	.Screen/width DEI2 2// .center/x STZ2
	.Screen/height DEI2 2// .center/y STZ2

	( draw )
	;draw-table JSR2
	;draw-sprites JSR2
	;draw-circle JSR2
	
BRK

@draw-sprites ( -- )
	
	;preview_icn .Screen/addr DEO2
	#00 #00
	&loop
		( move ) OVR #0f AND #40 SFT #02 DIV #00 SWP 
			.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
		( move ) OVR #f0 AND #02 DIV #00 SWP 
			.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
		( draw ) OVR .Screen/sprite DEO
		( incr ) SWP #01 ADD SWP
		NEQk ,&loop JCN
	POP2
	
RTN

@draw-table ( -- )
	
	#00 #10
	&loop
		OVR #08 MUL #00 SWP ;font-hex ADD2 .Screen/addr DEO2
		( x-axis ) 
		OVR #08 MUL #00 SWP 
		.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
		.center/y LDZ2 #0050 SUB2 .Screen/y DEO2
		( draw ) #01 .Screen/sprite DEO
		( y-axis )
		OVR #08 MUL #00 SWP 
		.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
		.center/x LDZ2 #0050 SUB2 .Screen/x DEO2
		( draw ) #01 .Screen/sprite DEO
		( incr ) SWP #01 ADD SWP
		LTHk ,&loop JCN
	POP2

RTN

@draw-circle ( -- )
	
	;preview_icn .Screen/addr DEO2
	.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
	.center/y LDZ2 #0030 ADD2 .Screen/y DEO2
	#01 .Screen/sprite DEO
	.center/x LDZ2 #0050 ADD2 .Screen/x DEO2
	#11 .Screen/sprite DEO
	.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
	.center/y LDZ2 #0038 ADD2 .Screen/y DEO2
	#21 .Screen/sprite DEO
	.center/x LDZ2 #0050 ADD2 .Screen/x DEO2
	#31 .Screen/sprite DEO

RTN

@preview_icn  [
	0f38 675f dfbf bfbf 0007 1820 2344 4848 

@font-hex 
	007c 8282 8282 827c 0030 1010 1010 1010
	007c 8202 7c80 80fe 007c 8202 1c02 827c
	000c 1424 4484 fe04 00fe 8080 7c02 827c
	007c 8280 fc82 827c 007c 8202 1e02 0202
	007c 8282 7c82 827c 007c 8282 7e02 827c
	007c 8202 7e82 827e 00fc 8282 fc82 82fc
	007c 8280 8080 827c 00fc 8282 8282 82fc
	007c 8280 f080 827c 007c 8280 f080 8080