-
Notifications
You must be signed in to change notification settings - Fork 3
/
TV_Terminal.spin
244 lines (179 loc) · 15.6 KB
/
TV_Terminal.spin
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
''***************************************
''* TV Terminal v1.1 *
''* Author: Chip Gracey *
''* Copyright (c) 2005 Parallax, Inc. *
''* See end of file for terms of use. *
''***************************************
{-----------------REVISION HISTORY-----------------
v1.1 - Updated 5/15/2006 to use actual pin number, instead of pin group, for Start method's basepin parameter.}
CON
x_tiles = 16
y_tiles = 13
x_screen = x_tiles << 4
y_screen = y_tiles << 4
width = 0 '0 = minimum
x_scale = 1 '1 = minimum
y_scale = 1 '1 = minimum
x_spacing = 6 '6 = normal
y_spacing = 13 '13 = normal
x_chr = x_scale * x_spacing
y_chr = y_scale * y_spacing
y_offset = y_spacing / 6 + y_chr - 1
x_limit = x_screen / (x_scale * x_spacing)
y_limit = y_screen / (y_scale * y_spacing)
y_max = y_limit - 1
y_screen_bytes = y_screen << 2
y_scroll = y_chr << 2
y_scroll_longs = y_chr * y_max
y_clear = y_scroll_longs << 2
y_clear_longs = y_screen - y_scroll_longs
paramcount = 14
VAR
long x, y, bitmap_base
long tv_status '0/1/2 = off/visible/invisible read-only
long tv_enable '0/? = off/on write-only
long tv_pins '%ppmmm = pins write-only
long tv_mode '%ccinp = chroma,interlace,ntsc/pal,swap write-only
long tv_screen 'pointer to screen (words) write-only
long tv_colors 'pointer to colors (longs) write-only
long tv_hc 'horizontal cells write-only
long tv_vc 'vertical cells write-only
long tv_hx 'horizontal cell expansion write-only
long tv_vx 'vertical cell expansion write-only
long tv_ho 'horizontal offset write-only
long tv_vo 'vertical offset write-only
long tv_broadcast 'broadcast frequency (Hz) write-only
long tv_auralcog 'aural fm cog write-only
long bitmap[x_tiles * y_tiles << 4 + 16] 'add 16 longs to allow for 64-byte alignment
word screen[x_tiles * y_tiles]
OBJ
tv : "TV"
gr : "Graphics"
PUB start(basepin)
'' Start terminal
''
'' basepin = first of three pins on a 4-pin boundary (0, 4, 8...) to have
'' 1.1k, 560, and 270 ohm resistors connected and summed to form the 1V,
'' 75 ohm DAC for baseband video
'init bitmap and tile screen
bitmap_base := (@bitmap + $3F) & $7FC0
repeat x from 0 to x_tiles - 1
repeat y from 0 to y_tiles - 1
screen[y * x_tiles + x] := bitmap_base >> 6 + y + x * y_tiles
'start tv
tvparams_pins := (basepin & $38) << 1 | (basepin & 4 == 4) & %0101
longmove(@tv_status, @tvparams, paramcount)
tv_screen := @screen
tv_colors := @color_schemes
tv.start(@tv_status)
'start graphics
gr.start
gr.setup(x_tiles, y_tiles, 0, y_screen, bitmap_base)
gr.textmode(x_scale, y_scale, x_spacing, 0)
gr.width(width)
out(0)
PUB stop
'' Stop terminal
tv.stop
gr.stop
PUB out(c)
'' Print a character
''
'' $00 = home
'' $01..$03 = color
'' $04..$07 = color schemes
'' $09 = tab
'' $0D = return
'' $20..$7E = character
case c
$00: 'home?
gr.clear
x := y := 0
$01..$03: 'color?
gr.color(c)
$04..$07: 'color scheme?
tv_colors := @color_schemes[c & 3]
$09: 'tab?
repeat
out($20)
while x & 7
$0D: 'return?
newline
$20..$7E: 'character?
gr.text(x * x_chr, -y * y_chr - y_offset, @c)
gr.finish
if ++x == x_limit
newline
PUB str(string_ptr)
'' Print a zero-terminated string
repeat strsize(string_ptr)
out(byte[string_ptr++])
PUB dec(value) | i
'' Print a decimal number
if value < 0
-value
out("-")
i := 1_000_000_000
repeat 10
if value => i
out(value / i + "0")
value //= i
result~~
elseif result or i == 1
out("0")
i /= 10
PUB hex(value, digits)
'' Print a hexadecimal number
value <<= (8 - digits) << 2
repeat digits
out(lookupz((value <-= 4) & $F : "0".."9", "A".."F"))
PUB bin(value, digits)
'' Print a binary number
value <<= 32 - digits
repeat digits
out((value <-= 1) & 1 + "0")
PRI newline
if ++y == y_limit
gr.finish
repeat x from 0 to x_tiles - 1
y := bitmap_base + x * y_screen_bytes
longmove(y, y + y_scroll, y_scroll_longs)
longfill(y + y_clear, 0, y_clear_longs)
y := y_max
x := 0
DAT
tvparams long 0 'status
long 1 'enable
tvparams_pins long %001_0101 'pins
long %0000 'mode
long 0 'screen
long 0 'colors
long x_tiles 'hc
long y_tiles 'vc
long 10 'hx
long 1 'vx
long 0 'ho
long 0 'vo
long 55_250_000 'broadcast
long 0 'auralcog
color_schemes long $BC_6C_05_02
long $0E_0D_0C_0A
long $6E_6D_6C_6A
long $BE_BD_BC_BA
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ 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. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}