~rabbits/uxn

uxn/projects/examples/devices/screen.tal -rw-r--r-- 3.9 KiB
f77fa80dAndrew Alderwick Replaced duplicate parts of PPU init with resize functions 7 hours 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
( dev/screen )

%RTN { JMP2r }
%2/  { #01 SFT }
%4/  { #02 SFT }

( devices )

|00 @System     [ &vector $2 &wst      $1 &rst    $1 &pad   $4 &r      $2 &g      $2 &b    $2 &debug  $1 &halt $1 ]
|20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y     $2 &addr $2 &pixel $1 &sprite $1 ]

( variables )

|0000

@count $2
@center
	&x $2 &y $2

( init )

|0100 ( -> )
	
	( vector )
	;on-frame .Screen/vector DEO2

	( theme ) 
	#f07f .System/r DEO2
	#f0e0 .System/g DEO2 
	#f0c0 .System/b DEO2 

	( find screen center )
	.Screen/width DEI2 #01 SFT2 #0020 SUB2 .center/x STZ2
	.Screen/height DEI2 #01 SFT2 .center/y STZ2

	( draw )
	;draw-table JSR2
	;draw-sprites JSR2
	;draw-1bpp JSR2
	;draw-2bpp JSR2
	;draw-pixels JSR2
	
BRK

@on-frame ( -> )

	.count LDZ2 INC2 [ DUP2 ] .count STZ2
	
	.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
	.center/y LDZ2 #0050 SUB2 .Screen/y DEO2

	( color ) #01 STH

	SWP 
	DUP #04 SFT [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
	( draw ) STHkr .Screen/sprite DEO
	#0f AND [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
	( draw ) STHkr .Screen/sprite DEO
	DUP #04 SFT [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
	( draw ) STHkr .Screen/sprite DEO
	#0f AND [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
	( draw ) STHr .Screen/sprite DEO

BRK

@draw-table ( -- )
	
	#10 #00
	&loop
		DUP #30 SFT #00 SWP ;font-hex ADD2 .Screen/addr DEO2
		( x-axis ) 
		DUP #30 SFT #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 )
		DUP #30 SFT #00 SWP 
		.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
		.center/x LDZ2 #0050 SUB2 .Screen/x DEO2
		( draw ) #01 .Screen/sprite DEO
		INC GTHk ,&loop JCN
	POP2

RTN

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

@draw-1bpp ( -- )

	#10 #00
	&loop
		( color ) STHk
		( y ) DUP 4/ [ #00 SWP ] #40 SFT2
			[ .center/y LDZ2 #0040 SUB2 ADD2 ] STH2
		( x ) DUP #03 AND [ #00 SWP ] #40 SFT2 #0040 ADD2 
			[ .center/x LDZ2 #0008 ADD2 ADD2 ]
		STH2r STHr #00 ;draw-circle JSR2
		INC GTHk ,&loop JCN
	POP2
	
RTN

@draw-2bpp ( -- )

	#10 #00
	&loop
		( color ) STHk
		( y ) DUP 4/ [ #00 SWP ] #40 SFT2
			[ .center/y LDZ2 ADD2 ] STH2
		( x ) DUP #03 AND [ #00 SWP ] #40 SFT2 #0040 ADD2 
			[ .center/x LDZ2 #0008 ADD2 ADD2 ]
		STH2r STHr #80 ;draw-circle JSR2
		INC GTHk ,&loop JCN
	POP2
	
RTN

@draw-circle ( x* y* color depth -- )
	
	ADD STH
	;preview_icn .Screen/addr DEO2
	.Screen/y DEO2
	.Screen/x DEO2

	#00 STHkr ADD .Screen/sprite DEO
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
		#10 STHkr ADD .Screen/sprite DEO
	.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
	.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
		#20 STHkr ADD .Screen/sprite DEO
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
		#30 STHr ADD .Screen/sprite DEO

RTN

@draw-pixels ( -- )
	
	.center/y LDZ2 #0040 SUB2 .Screen/y DEO2
	.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
		#00 .Screen/pixel DEO
	.center/x LDZ2 #0049 ADD2 .Screen/x DEO2
		#01 .Screen/pixel DEO
	.center/x LDZ2 #004a ADD2 .Screen/x DEO2
		#02 .Screen/pixel DEO
	.center/x LDZ2 #004b ADD2 .Screen/x DEO2
		#03 .Screen/pixel 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