-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathvga_text_buffer.si
375 lines (319 loc) · 7.84 KB
/
vga_text_buffer.si
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// -------------------------
// MIT license, see LICENSE_MIT in Silice repo root
// https://github.com/sylefeb/Silice
// @sylefeb 2019
// VGA driver
$include('../common/vga.si')
$$if MOJO then
// Clock
import('../common/plls/mojo_100_25.v')
$$end
$$if ICESTICK then
// Clock
import('../common/plls/icestick_25.v')
$$end
$$if ICEBREAKER then
// Clock
import('../common/plls/icebrkr_25.v')
$$end
$$if RIEGEL then
// Clock
import('../common/plls/riegel_25.v')
$$end
$$if DE10NANO then
// Clock
import('../common/plls/de10nano_100_25.v')
$$end
$$if ECPIX5 then
// Clock
import('../common/plls/ecpix5_100_25.v')
$$end
$$if HARDWARE then
// Reset
$include('../common/clean_reset.si')
$$end
// -------------------------
algorithm text_display(
input uint10 pix_x,
input uint10 pix_y,
input uint1 pix_active,
input uint1 pix_vblank,
output! uint$color_depth$ pix_red,
output! uint$color_depth$ pix_green,
output! uint$color_depth$ pix_blue
) <autorun> {
// Text buffer
bram uint6 txt[1024] = {pad(0)};
// ---------- font
// assumes letter_w_sp (defined in font) is an integer divider of 640
$include('../common/font.si')
// include('../common/font_small.si')
// ---------- text display
uint5 text_i = 0;
uint5 text_j = 0;
uint4 letter_i = 0;
uint5 letter_j = 0;
uint1 pixel = 0;
uint12 addr = 0;
uint10 shf_x = 0;
uint11 next = 0;
uint11 str_x = 0;
uint10 str_y = 0;
int10 frame = 0;
uint4 line = 0;
uint4 stride = 0;
// ---------- table for text swim
uint4 wave[64] = {
$$for i=0,63 do
$math.floor(15.0 * (0.5+0.5*math.sin(2*math.pi*i/63)))$,
$$end
};
// ---------- snow
int10 dotpos = 0;
int2 speed = 0;
int2 inv_speed = 0;
int12 rand_x = 0;
// ---------- string
uint8 str[] = " HELLO WORLD FROM FPGA# THIS IS WRITTEN IN SILICE # MY LANGUAGE FOR FPGA DEVEL #FUN AND SIMPLE YET POWERFUL# --- AVAILABLE ON GITHUB --- ##THIS WAS TESTED ON#-VERILATOR#-ICARUS VERILOG#-MOJO BOARD#-ICESTICK#-ICEBREAKER#-ULX3S#-DE10-NANO#-ECPIX-5#-RIEGEL";
// --------- print string
subroutine print_string(
reads str,
reads str_x,
readwrites str_y,
writes txt_addr,
writes txt_wdata,
writes txt_wenable
) {
uint10 col = 0;
uint8 lttr = 0;
uint5 offs = 0;
// print line
while (str[col] != 0) {
if (str[col] == 35) {
str_y = str_y + 1;
offs = 0;
} else {
switch (str[col]) { // some ASCII to font translation
case 32: {lttr = 36;}
case 45: {lttr = 37;}
case 51: {lttr = 3;}
default: {
if (str[col] <= 57) {
lttr = str[col] - 48;
} else {
lttr = str[col] - 55;
}
}
}
txt_addr = offs + str_x + (str_y << 5);
txt_wdata = lttr[0,6];
txt_wenable = 1;
offs = offs + 1;
}
col = col + 1;
}
txt_wenable = 0;
return;
}
// by default r,g,b are set to zero
pix_red := 0;
pix_green := 0;
pix_blue := 0;
// fill buffer with spaces
txt_wenable = 1;
txt_wdata = 36; // data to write
next = 0;
while (next < 1024) {
txt_addr = next; // address to write
next = next + 1; // next
}
txt_wenable = 0;
// ---------- show time!
while (1) {
// write lines in buffer
str_y = 0;
() <- print_string <- ();
// wait until vblank is over
while (pix_vblank == 1) { }
frame = frame + 1;
// display frame
text_i = 0;
text_j = 0;
letter_i = 0;
letter_j = 0;
while (pix_vblank == 0) {
if (pix_active) {
// background snow effect
if (pix_x == 0) {
rand_x = 1;
} else {
rand_x = rand_x * 31421 + 6927;
}
speed = rand_x[10,2];
dotpos = (frame >> speed) + rand_x;
if (pix_y == dotpos) {
pix_red = ($color_max$);
pix_green = ($color_max$);
pix_blue = ($color_max$);
}
// text
stride = wave[pix_y[2,6] + frame[0,6]];
if (pix_x >= 192 + stride && pix_y > 64) {
if (letter_j < $letter_h$ && letter_i < $letter_w$) {
addr = letter_i + (letter_j << $letter_w_pow2$)
+ (txt_rdata * $letter_w*letter_h$);
pixel = letters[ addr ];
if (pixel == 1) {
switch (text_j)
{
case 0: {
pix_red = 0;
pix_green = $color_max$;
pix_blue = 0;
}
case 4: {
pix_red = 0;
pix_green = 0;
pix_blue = $color_max$;
}
case 6: {
pix_red = $color_max$;
pix_green = 0;
pix_blue = 0;
}
default: {
pix_red = $color_max$;
pix_green = $color_max$;
pix_blue = $color_max$;
}
}
}
}
letter_i = letter_i + 1;
if (letter_i == $letter_w_sp$) { // end of letter
letter_i = 0;
if (text_i < 31) {
text_i = text_i + 1;
}
}
if (pix_x == 639) { // end of line
// back to first column
text_i = 0;
letter_i = 0;
// next letter line
if (letter_j < $2*letter_h$) {
letter_j = letter_j + 1;
} else {
// next text row
text_j = text_j + 1;
letter_j = 0; // back to first letter line
}
}
txt_addr = text_i + (text_j << 5);
}
}
}
}
}
// -------------------------
algorithm main(
output! uint$NUM_LEDS$ leds,
$$if SIMULATION then
output! uint1 video_clock,
$$end
output! uint$color_depth$ video_r,
output! uint$color_depth$ video_g,
output! uint$color_depth$ video_b,
output uint1 video_hs,
output uint1 video_vs
)
$$if HARDWARE and not ULX3S then
// on an actual board, the video signal is produced by a PLL
<@video_clock,!video_reset>
$$end
{
$$if HARDWARE and not ULX3S then
uint1 video_reset = 0;
uint1 video_clock = 0;
$$if MOJO then
uint1 sdram_clock = 0;
// --- clock
pll clk_gen (
CLK_IN1 <: clock,
CLK_OUT1 :> sdram_clock,
CLK_OUT2 :> video_clock
);
$$elseif ICEBREAKER or ICESTICK or RIEGEL then
// --- clock
pll clk_gen (
clock_in <: clock,
clock_out :> video_clock
);
$$elseif DE10NANO then
// --- clock
uint1 sdram_clock = 0;
uint1 pll_lock = 0;
pll clk_gen(
refclk <: clock,
rst <: reset,
outclk_0 :> sdram_clock,
outclk_1 :> video_clock,
locked :> pll_lock
);
$$elseif ECPIX5 then
// --- clock
uint1 sdram_clock = 0;
uint1 pll_lock = 0;
pll clk_gen(
clkin <: clock,
clkout0 :> sdram_clock,
clkout1 :> video_clock,
locked :> pll_lock
);
$$end
// --- video reset
clean_reset vga_rstcond<@video_clock,!reset>(
out :> video_reset
);
$$end
uint1 active = 0;
uint1 vblank = 0;
uint10 pix_x = 0;
uint10 pix_y = 0;
vga vga_driver
(
vga_hs :> video_hs,
vga_vs :> video_vs,
active :> active,
vblank :> vblank,
vga_x :> pix_x,
vga_y :> pix_y
);
text_display display
(
pix_x <: pix_x,
pix_y <: pix_y,
pix_active <: active,
pix_vblank <: vblank,
pix_red :> video_r,
pix_green :> video_g,
pix_blue :> video_b
);
uint8 frame = 0;
$$if SIMULATION then
video_clock := clock;
$$end
$$if SIMULATION then
// we count a number of frames and stop
while (frame < 40) {
while (vblank == 1) { }
__display("vblank off");
while (vblank == 0) { }
__display("vblank on");
frame = frame + 1;
}
$$else
// forever
while (1) { }
$$end
}