Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
396 lines (328 sloc) 6.56 KB
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)