-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvga.ga
More file actions
395 lines (328 loc) · 6.56 KB
/
Copy pathvga.ga
File metadata and controls
395 lines (328 loc) · 6.56 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
include(ga144.hdr)
include(708out.hdr)
\ relevant output pins:
\ GND J27.1
\ 713.ao J27.5 blue
\ 717.ao J27.7 red
\ 617.ao J21.1 green
\ 517.17 J21.3
\ 417.17 J21.4 HSYNC (white)
\ 317.17 J21.5 VSYNC (yellow)
\ 117.ao J21.7
define(WIRE_64DIV, `
\ attr: render wire $1 $2
@p a! @p
$1
$2
b!
: again
@ 2/ 2/
2/ 2/ 2/
2/ !b jump again')
define(DAC, `
\ attr: render color .3 .3 0
@p a!
$1
@p b!
io
@p
0x155
: again
@ 2* 2*
2* over or
!b jump again')
---------------------------- 717 ----------------------------
DAC(WEST)
---------------------------- 617 ----------------------------
DAC(SOUTH)
---------------------------- 713 ----------------------------
DAC(EAST)
---------------------------- 714 ----------------------------
WIRE(EAST, WEST)
---------------------------- 715 ----------------------------
WIRE_64DIV(EAST, WEST)
---------------------------- 517 ----------------------------
WIRE(SOUTH, NORTH_WEST)
---------------------------- 516 ----------------------------
WIRE(EAST, NORTH)
---------------------------- 616 ----------------------------
WIRE_64DIV(SOUTH, NORTH)
---------------------------- 716 ----------------------------
WIRE(SOUTH, EAST_WEST)
---------------------------- 417 ----------------------------
\ http://tinyvga.com/vga-timing/640x480@60Hz
: again
@p call vsync \ sync
0x20000
@p call lines
2-1
@p call vsync
0x30000
@p call lines \ back porch
33-1
@p call lines \ frame
480-1
@p call lines \ front porch
10-1
jump again
: lines
push
: lineloop
@p a!
NORTH
@p b! @p @p
io
0x20000
0x30000
over !b \ vsync low
@p call delay
int(3.8133/.00248) \ sync pulse
dup !b \ vsync high
@p call delay
int((1.906)/.00248) \ back porch
\ @p call delay
\ int((25.422)/.00248)
@p a!
WEST
@p b!
NORTH
@p push
640-1
: display
. . @ .
. . !b .
. . . .
. . next display
dup or !b
@p call delay
int(0.6355/.00248) \ front porch
\ dup !b \ high
\ @p call delay
\ int(27.96/.00248)
\ over !b \ low
\ @p call delay
\ int(3.8133/.00248)
next lineloop
;
: delay
push
unext ;
: vsync
@p a! ! ;
SOUTH
---------------------------- 317 ----------------------------
WIRE(NORTH, io)
---------------------------- 416 ----------------------------
\ Like a wire node from WEST to EAST, but inserts zero pixels
\ for the non-visible lines
@p a!
WEST
@p b!
EAST
: screen
@p call zeroes
640*35-1
\ 640*480 does not fit in 18 bits, so do it twice
@p dup
(640*480)/2-1
push push
@ !b unext
@ !b unext
@p call zeroes
640*10-1
jump screen
: zeroes ( n -- ) \ send n zeroes to b
push
dup dup or
dup !b unext ;
\ CONVEYOR(N) carries N words from WEST then a single word
\ from NORTH.
define(CONVEYOR, `
\ attr: render color 0 .2 .4
@p b!
EAST
: again
@p a! @
NORTH
!b @p a! @p
WEST
$1-1
push
@ !b unext
jump again
')
---------------------------- 415 ----------------------------
CONVEYOR(15)
---------------------------- 414 ----------------------------
CONVEYOR(14)
---------------------------- 413 ----------------------------
CONVEYOR(13)
---------------------------- 412 ----------------------------
CONVEYOR(12)
---------------------------- 411 ----------------------------
CONVEYOR(11)
---------------------------- 410 ----------------------------
CONVEYOR(10)
---------------------------- 409 ----------------------------
CONVEYOR(9)
---------------------------- 408 ----------------------------
CONVEYOR(8)
---------------------------- 407 ----------------------------
CONVEYOR(7)
---------------------------- 406 ----------------------------
CONVEYOR(6)
---------------------------- 405 ----------------------------
CONVEYOR(5)
---------------------------- 404 ----------------------------
CONVEYOR(4)
---------------------------- 403 ----------------------------
CONVEYOR(3)
---------------------------- 402 ----------------------------
CONVEYOR(2)
---------------------------- 401 ----------------------------
CONVEYOR(1)
---------------------------- 400 ----------------------------
WIRE(NORTH, EAST)
define(RGB, `($2|($1<<6)|($3<<12))')
\ These generators have signature ( y x -- y x brg )
\ brg is an 18-bit color, 6 bits per channel.
define(RAMPS, `
over 2/ 2/
2/ 2/
over
2/ 2/ 2/
2/ 2/ 2/ @p
3
and
2* dup 2* +
push next rr
jump done
: rr
2* unext
: done
')
define(CHECKER, `
over @p and
32
over @p and
32
2* 2* 2*
2* 2* 2*
or
')
define(CIRCLES, `
jump fwd
: osq
@p and
63
@p . +
-32
-if sq
- @p . +
1
: sq
dup a! @p @p
0
17
push
+* unext . .
drop drop a ;
: fwd
over
call osq
over
call osq
. +
2/ 2/ 2/
2/ 2/ 2/
2/ a! @
')
define(RANDOM, `
jump fwd
: hash
dup 2* 2*
2* 2* 2*
2* 2* 2*
2* 2* or
dup 2/ 2/
2/ 2/ 2/
2/ 2/ or
dup 2* 2*
2* 2* or ;
: fwd
over
2/ 2/ 2/
call hash
over
2/ 2/ 2/
or call hash
')
define(BODY, RANDOM)
define(PIXEL_GEN, `
---------------------------- $1 ----------------------------
\ attr: render color .4 0 .2
@p b!
$2
@p @p
0
$3
: again
BODY
!b @p . +
16
dup @p . +
-640
-if wrap
drop jump again
: wrap
over or or
over
@p . +
1
dup @p . +
-480
-if wrapy
drop over
jump again
: wrapy
over or or
over jump again
: channel
@p and ;
0xfc00
: rgb
\ ( r g b ), now reformat to 18-bit BRG
\ b: msb 15 to 17
\ g: msb 15 to 5
\ r: msb 15 to 11
\ blue
call channel
2* 2* push
\ green
call channel
2/ 2/ 2/
2/ 2/ 2/
2/ 2/ 2/
2/ push
\ red
call channel
2/ 2/ 2/
2/ pop pop
or or
')
PIXEL_GEN(500, SOUTH, 15)
PIXEL_GEN(501, SOUTH, 14)
PIXEL_GEN(502, SOUTH, 13)
PIXEL_GEN(503, SOUTH, 12)
PIXEL_GEN(504, SOUTH, 11)
PIXEL_GEN(505, SOUTH, 10)
PIXEL_GEN(506, SOUTH, 9)
PIXEL_GEN(507, SOUTH, 8)
PIXEL_GEN(508, SOUTH, 7)
PIXEL_GEN(509, SOUTH, 6)
PIXEL_GEN(510, SOUTH, 5)
PIXEL_GEN(511, SOUTH, 4)
PIXEL_GEN(512, SOUTH, 3)
PIXEL_GEN(513, SOUTH, 2)
PIXEL_GEN(514, SOUTH, 1)
PIXEL_GEN(515, SOUTH, 0)