spinix-hive/vga512/VGA_512x384_Bitmap_Demo.spin

143 lines
5.4 KiB
Plaintext
Raw Normal View History

''********************************************
''* Added argc and argv parms to the start *
''* method, and extract the VGA pin from *
''* the second argv parameter. Check for *
''* key press in loops to terminate *
''* program. *
''* Copyright (c) 2012, Dave Hein *
''* See end of file for terms of use. *
''********************************************
''* VGA 512x384 2-Color Bitmap Driver v1.0 *
''* Author: Chip Gracey *
''* Copyright (c) 2006 Parallax, Inc. *
''* See end of file for terms of use. *
''********************************************
CON
_clkmode = xinput
_xinfreq = $4e495053 ' SPIN
tiles = vga#xtiles * vga#ytiles
tiles32 = tiles * 32
OBJ
vga : "vga_512x384_bitmap"
ser : "FullDuplexSerial"
spinix : "exit"
VAR
long sync, pixels[tiles32]
word colors[tiles]
PUB start(argc, argv) | h, i, j, k, x, y, ptr
'set the linefeed flag
set_linefeed(argc, argv)
'start serial port
ser.start(31, 30, 0, 115_200)
'check for two parms
if argc <> 2
usage
' Check if arg is c3 or C3
ptr := long[argv][1]
if strcomp(ptr, string("c3")) or strcomp(ptr, string("C3"))
j := 16
DIRA |= $8000
' else, check if it's 0, 8, 16 or 24
else
j := atol(ptr)
if j <> 0 and j <> 8 and j <> 16 and j <> 24
usage
'start vga
vga.start(j, @colors, @pixels, @sync)
'print message to serial port
ser.str(string("Hit any key to terminate program"))
putnewline
'init colors to cyan on blue
repeat i from 0 to tiles - 1
colors[i] := $2804
'draw some lines
repeat y from 1 to 8
repeat x from 0 to 511
plot(x, x/y)
'wait ten seconds
repeat 100
if ser.rxcheck <> -1
spinix.exit(0)
waitcnt(clkfreq / 10 + cnt)
'randomize the colors and pixels
repeat
if ser.rxcheck <> -1
spinix.exit(0)
colors[||?h // tiles] := ?i
repeat 100
pixels[||?j // tiles32] := k?
PRI plot(x,y) | i
if x => 0 and x < 512 and y => 0 and y < 384
pixels[y << 4 + x >> 5] |= |< x
PRI usage
ser.str(string("usage: vga512 parm"))
putnewline
ser.str(string(" parm is either 'c3' for the C3 board or"))
putnewline
ser.str(string(" a starting pin number of 0, 8, 16 or 24"))
putnewline
waitcnt(cnt + clkfreq/10)
spinix.exit(1)
PRI set_linefeed(argc, argv) | ptr
ptr := long[argv][argc-1]
ptr += strsize(ptr) + 1
ptr := ((ptr + 3) >> 2) << 2
linefeed := long[ptr] & 1
PRI putnewline
ser.tx(13)
if linefeed
ser.tx(10)
PRI atol(ptr)
repeat while byte[ptr]
result := (result * 10) + byte[ptr++] - "0"
DAT
linefeed long 0
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ 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. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}