Toolbox-2/source/boing/boing-bel.spin

287 lines
9.3 KiB
Plaintext

''
'' VGA scanline driver 400x300 - demo
''
'' Based on "Ball" demo for Gameduino
'' Copyright (c) 2011 by James Bowman <jamesb@excamera.com>
''
'' Author: Marko Lukat
'' Last modified: 2012/12/24
'' Version: 0.10
''
'' A few notes on timing. A (double) scan line lasts 2*(100+32) hub windows.
'' The background renderer fills the scan line as soon as the video driver
'' has read the relevant quad. At the same time the foreground renderer
'' fetches its data line.
''
'' +-- video driver reads line N
'' +-- background renderer fills line N+1
'' +-- foreground renderer fetches data for line N+1
'' |
'' | +-- scanline N completely fetched
'' | +-- background renderer idle
'' | visible line area +-- foreground renderer draws shadow and ball
'' | |
'' ----------- 100 -----------#---32---
'' ----------- 100 -----------+---32---
'' ----------- 100 -----------#---32---
'' |
'' +-- video driver reads line N+1
''
CON
_clkmode = XTAL1|PLL16X
_xinfreq = 5_000_000
CON
res_x = driver#res_x
res_y = driver#res_y
OBJ
driver: "boing-bel-driver"
back: "boing-bel-background"
ball: "boing-bel-foreground"
anim: "boing-bel-feeder"
keyb: "bel-keyb"
gcon: "glob-con"
VAR
long feeder ' @scan[-3]
long coordinates ' @scan[-2]
long frame ' @scan[-1]
long scan[res_x / 4]
long grid[12]
long bflag
PUB main | cmd
init
' boing
repeat
case gc
1: pc(keyb.gotkey) 'tastaturstatus senden
2: pc(keyb.key) 'tastaturzeichen senden
3: coordinates.word[0] := gw
coordinates.word[1] := gw
4: waitVBL
5: boing
6: bars{gc,gc,gc}
7: grid_on
8: grid_off
9: show_on
10: bar_on
11: bflag := gc
12: grid[gc] := gw
99: reboot
PRI init
dira := db_in ' datenbus auf eingabe schalten
outa[gcon#bus_hs] := 1 ' handshake inaktiv
keyb.start(gcon#b_keybd, gcon#b_keybc) ' tastaturport starten
driver.init(-1, @scan{0}) ' scanline driver
back.init(-1, @scan{0}) ' background
ball.init(-1, @scan{0}) ' foreground
anim.init(-1, @scan{0}) ' image feeder
grid_on
bflag := 0
anim.uncompress(FALSE) ' uncompress image
CON ''------------------------------------------------- SUBPROTOKOLL-FUNKTIONEN
' hbeat --------+
' clk -------+|
' /wr ------+||
' /hs -----+||| +------------------------- /cs
' |||| | -------- d0..d7
DB_IN = %00001001_00000000_00000000_00000000 'maske: dbus-eingabe
DB_OUT = %00001001_00000000_00000000_11111111 'maske: dbus-ausgabe
M1 = %00000010_00000000_00000000_00000000
M2 = %00000010_10000000_00000000_00000000 'busclk=1? & /cs=0?
M3 = %00000000_00000000_00000000_00000000
M4 = %00000010_00000000_00000000_00000000 'busclk=0?
PUB pc(zeichen) 'chip: ein byte an regnatix senden
''funktionsgruppe : chip
''funktion : ein byte an regnatix senden
''eingabe : byte
''ausgabe : -
waitpeq(M1,M2,0) 'busclk=1? & prop2=0?
dira := db_out 'datenbus auf ausgabe stellen
outa[7..0] := zeichen 'daten ausgeben
outa[gcon#bus_hs] := 0 'daten gültig
waitpeq(M3,M4,0) 'busclk=0?
dira := db_in 'bus freigeben
outa[gcon#bus_hs] := 1 'daten ungültig
PUB gc:zeichen 'chip: ein byte von regnatix empfangen
''funktionsgruppe : chip
''funktion : ein byte von regnatix empfangen
''eingabe : -
''ausgabe : byte
waitpeq(M1,M2,0) 'busclk=1? & prop2=0?
zeichen := ina[7..0] 'daten einlesen
outa[gcon#bus_hs] := 0 'daten quittieren
waitpeq(M3,M4,0) 'busclk=0?
outa[gcon#bus_hs] := 1
PUB pw(wert) 'sub: word senden
''funktionsgruppe : sub
''funktion : subprotokoll um einen long-wert an regnatix zu senden
''eingabe : 16bit wert der gesendet werden soll
''ausgabe : -
''busprotokoll : [put.byte1][put.byte2]
'' : [ hsb ][ ]
pc(wert >> 8)
pc(wert)
PUB gw:wert 'sub: word empfangen
''funktionsgruppe : sub
''funktion : subprotokoll um einen 16bit-wert von regnatix zu empfangen
''eingabe : -
''ausgabe : 16bit-wert der empfangen wurde
''busprotokoll : [get.byte1][get.byte2]
'' : [ hsb ][ lsb ]
wert := gc << 8
wert := wert + gc
PUB gl:wert 'sub: long empfangen
''funktionsgruppe : sub
''funktion : subprotokoll um einen long-wert von regnatix zu empfangen
''eingabe : -
''ausgabe : 32bit-wert der empfangen wurde
''busprotokoll : [get.byte1][get.byte2][get.byte3][get.byte4]
'' : [ hsb ][ ][ ][ lsb ]
wert := gc << 24 '32 bit empfangen hsb/lsb
wert := wert + gc << 16
wert := wert + gc << 8
wert := wert + gc
CON ''------------------------------------------------- DEMO-FUNKTIONEN
LBASE = 0
RBASE = res_x - ball#BSIZE
YBASE = res_y - ball#BSIZE
MBAR = %00000000_11111111
BLINE = 1
PRI boing : r | bx, by, bxv, byv
bx := 0
by := 0
bxv := 2
byv := 1
repeat
bx += bxv
by += byv
if bx < LBASE
bx := constant(2*LBASE) - bx
-bxv
if bx > RBASE
bx := constant(2*RBASE) - bx
-bxv
if by > YBASE
by := constant(2*YBASE) - by
-byv
ifnot ++r & 7 ' add some gravity
byv++
repeat 1
waitVBL
coordinates.word{0} := bx ' |
coordinates.word[1] := by ' update coordinates
PRI bars
grid[BLINE ] := bar(gc)
grid[BLINE+2] := bar(gc)
grid[BLINE+4] := bar(gc)
PRI bar(level):b
b := MBAR
b := !(b >> (level & 7)) & MBAR
b := b | b >< 16
PRI grid_on|i
repeat i from 0 to 11
grid[i] := 0
PRI grid_off|i
repeat i from 0 to 11
grid[i] := $FFFF
PRI show_on|i,n
n := %00000000_11111111
repeat 19
repeat i from 11 to 0
grid[i] := grid[i-1]
n := n >> 1
grid[0] := n | n >< 16
waitcnt(cnt + clkfreq/30)
PRI bar_on
bar_up(BLINE )
waitcnt(cnt + clkfreq/3)
bar_up(BLINE+2)
waitcnt(cnt + clkfreq/3)
bar_up(BLINE+4)
waitcnt(cnt + clkfreq/3)
PRI bar_up(upline)|i
repeat i from 11 to upline
grid[(i+1) <# 11] := 0
grid[i] := %00000111_11100000
waitcnt(cnt+clkfreq/20)
PRI waitVBL
repeat
until frame == res_y ' last line has been fetched
repeat
until frame <> res_y ' vertical blank starts (res_y/0 transition)
DAT
{{
TERMS OF USE: MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}}
DAT