Skip to content

Commit

Permalink
Merge pull request #3 from jamesbowman/master
Browse files Browse the repository at this point in the history
updates from upstream
  • Loading branch information
RGD2 committed Jan 8, 2016
2 parents 77cc1ad + 0b3d5f8 commit 08ea8a2
Show file tree
Hide file tree
Showing 2 changed files with 294 additions and 0 deletions.
146 changes: 146 additions & 0 deletions demos/newyear.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
include screenshot.fs

160 constant NSPARKS

GD.init

\ 0 64 64 * GD.cmd_memwrite
\ include star.fs
\ 0 GD.L8 64 64 GD.cmd_setbitmap
\ $0000ff GD.ClearColorRGB#
\ GD.Clear
\ GD.BITMAPS GD.Begin
\ 100 100 31 64 GD.Vertex2ii
\ 100 200 0 0 GD.Vertex2ii
\ GD.swap

: srandom ( n -- x ) dup 2* randrange - ;

object class
1 cells var x
1 cells var y
1 cells var dx
1 cells var dy
1 cells var age
method park \
method born \ randomize position, velocity
method move \ compute new position
method draw \ draw self
end-class spark

: rr ( a b -- u ) over - randrange + ;

:noname ( dx dy x -- )
>r
-8000 r@ x !
16 768 * r@ y !
0 r@ dx !
0 r@ dy !
999 r@ age !
r> drop
; spark defines park

:noname ( dx dy x -- )
>r
r@ x !
-3 3 rr + r@ dx !
-230 r@ dy !
768 16 * -16 16 rr + r@ y !
0 8 rr r@ age !
r> drop
; spark defines born

:noname
>r
r@ x @
r@ y @ GD.Vertex2f
r> drop
; spark defines draw

: lin ( x x0 x255 )
over - >r
-
255 r> */
0 max 255 min
;

:noname
>r
r@ age @ 60 = if
-50 50 rr r@ dx +!
-30 50 rr r@ dy +!
then
r@ dx @ r@ x +!
r@ dy @ r@ y +!
3 r@ dy +!
1 r@ age +!
r> drop
; spark defines move

\ create bb NSPARKS cells allot
\ : b[] ( u -- a ) cells bb + @ ;
\
\ :noname
\ NSPARKS 0 do
\ spark anew
\ i cells bb + !
\ loop
\ ; execute

:noname
NSPARKS 0 do
spark anew drop
loop
;
create bb execute

: b[] ( u -- a ) spark @ * bb + ;

: kind ( color i )
b[] age @ dup
2* 80 max GD.PointSize
160 120 lin GD.ColorA
GD.ColorRGB#
;

: x
NSPARKS 0 do
i b[] park
loop

0 34 GD.cmd_romfont

GD.REG_FRAMES GD.@
6000 0 do
i 40 mod 0= if
-16 16 rr 1024 16 * randrange
i NSPARKS mod dup 40 + swap do
2dup i b[] born
loop
2drop
then
GD.Clear

$808080 GD.ColorRGB#
512 200 0 GD.OPT_CENTER s" HAPPY" GD.cmd_text
512 300 0 GD.OPT_CENTER s" NEW" GD.cmd_text
512 400 0 GD.OPT_CENTER s" YEAR" GD.cmd_text
512 500 0 GD.OPT_CENTER s" 2016" GD.cmd_text

GD.SRC_ALPHA 1 GD.BlendFunc
GD.POINTS GD.Begin
NSPARKS 0 do
i case
0 of $f08040 i kind endof
40 of $80f040 i kind endof
80 of $8040f0 i kind endof
120 of $4080f0 i kind endof
endcase
i b[] dup move draw
loop

GD.swap
\ i 1 and if GD.screenshot then
loop
GD.finish GD.REG_FRAMES GD.@ swap - .
;
148 changes: 148 additions & 0 deletions demos/vga2.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
( Setup for Ken Boak's VGA shield, which uses an FT812 )

9 constant CS

: gd2-sel 0 CS io! ;
: gd2-unsel 1 CS io! ;
: gd2-spi-init
OUTPUT CS pinMode
gd2-unsel
spi-init
;

include gd2.fs

\ H and Vsync parameters start at GD.REG_HCYCLE, VCYCLE
\ and are ordered: HCYCLE HOFFSET HSIZE HSYNC0 HSYNC1

: setsync ( visible sync back whole REG -- )
20 GD.cmd_memwrite
GD.c \ CYCLE
over + GD.c \ OFFSET
swap GD.c \ SIZE
0 GD.c \ SYNC0
GD.c \ SYNC1
;

: hs GD.REG_HCYCLE setsync ;
: vs GD.REG_VCYCLE setsync ;

: pll ( pll -- ) \ set PLL clock multiplier
dup GD.pll GD.crystal
13000000 * GD.REG_FREQUENCY GD.!
;

: pclk ( pclk -- ) \ common register settings for EVITA display
0 GD.REG_CSPREAD GD.!
0 GD.REG_SWIZZLE GD.!
0 GD.REG_ROTATE GD.!
GD.REG_PCLK GD.!
;

\ H/V timing parameters order: visible sync back whole

: res create , does> @ GD.setcustom ;
:noname 5 pll 1024 136 160 1344 hs 768 6 29 806 vs 1 pclk ;
:noname 3 pll 800 128 88 1056 hs 600 4 23 628 vs 1 pclk ;
:noname 4 pll 640 96 48 800 hs 480 2 33 542 vs 2 pclk ;
res 640x480 res 800x600 res 1024x768

1024x768 \ default resolution

: GD.calibrate ; ( there is no touch screen )

: test-page
GD.init

0 34 GD.cmd_romfont

begin
0 0 $00ff00 1024 768 $ff0000 GD.cmd_gradient
16 16 GD.SCISSORXY
1024 32 - 768 32 - GD.SCISSORSIZE
GD.Clear

512 50 GD.SCISSORSIZE
3 0 do
256 i 100 * 484 + GD.SCISSORXY
256 i 100 * 484 + $000000
768 i 100 * 484 + $0000ff i 8 * lshift
GD.cmd_gradient
loop
GD.RestoreContext

512 186 150 0
ms@ 1000 /mod 2>r
r@ 3600 / 12 mod ( hours )
r@ 60 / 60 mod ( minutes )
r> 60 mod ( seconds )
r> ( ms )
GD.cmd_clock

32 32 30 0
GD.wh s>d <# #s 2drop 'x' hold s>d #s #>
GD.cmd_text
512 404 0 GD.OPT_CENTER s" Hello world" GD.cmd_text

GD.swap
GD.finish
again
;

128 48 * 2* constant NB \ bytes in 1024x768 text mode

: test-vga
GD.init

0 GD.TEXTVGA 1024 768 GD.cmd_setbitmap

GD.Clear
1 0 GD.BlendFunc
GD.BITMAPS GD.Begin
0 0 0 0 GD.Vertex2ii
GD.swap
begin
0 NB GD.cmd_memwrite
NB 0 do
random GD.c
4 +loop
1000 ms
again
;

: .3 ( u -- ) \ print as 3-digit decimal
s>d <# # # # '.' hold #s #> type space
;

: sync \ wait until REG_FRAMES changes
GD.REG_FRAMES GD.c@
begin
dup GD.REG_FRAMES GD.c@ xor
until
drop
;

: report
cr
\ GD.@ .

." REG_ID "
GD.REG_ID GD.@ hex2. cr

." resolution "
GD.wh swap 0 .r 'x' emit . cr

." Measured core freq. "
GD.REG_CLOCK GD.@
1000 ms
GD.REG_CLOCK GD.@
swap - 1000 / .3
." MHz" cr

." Measured frame rate "
sync ms@
100 0 do sync loop
ms@ swap -
100000000 swap / .3
." Hz" cr
;

0 comments on commit 08ea8a2

Please sign in to comment.