-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtext.fs
145 lines (116 loc) · 2.6 KB
/
text.fs
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
\ High-Level Display interface: Fonts & Images
\ (c)copyright 2014 by Gerald Wodni
\ raw \ clear all until ws2812
compiletoflash
$000400 variable text-color
\ TODO: cvariable would be sufficient
cols variable max-column \ stop printing at this column
0 variable cur-column \ current column
0 variable col-offset \ column offset
1 variable boldness \ times to repeat pattern
8px-cond variable font
0 variable cur-text
\ font-sizes, usage: "regular wide
: wide 3 boldness ! ;
: bold 2 boldness ! ;
: regular 1 boldness ! ;
\ get start-address of char
: c-pos ( u-char -- )
font @ swap $7F and $20 - 0 ?do dup c@ 1+ + loop ;
: d-column drop ;
: offset-column ( n-offset n-column )
dup d-column cur-column ! col-offset ! ;
: column ( n-column -- )
0 swap offset-column ;
\ expand lower nibble across byte
: stretch ( x -- x )
0 4 0 do
2 lshift
over $08 and
if
$03 or
then
swap 1 lshift swap
loop nip ;
: >d
led-buffer cur-column @ 4 * +
8 0 do
\ i . 2dup swap hex. hex. cr
over $01 and if \ bit lit?
text-color @ over !
then
row-size +
swap 1 rshift swap \ next bit
loop 2drop ;
\ emit single byte and respect column-max
: d-emit-max ( x-char -- )
cur-column @ max-column @ < if \ don't print after max-column
>d
1 cur-column +!
else
drop
then ;
\ emit single byte and respect column-offset
: d-emit-off ( x-char -- )
col-offset @ 0= if \ don't print negative offsets
d-emit-max
else
-1 col-offset +!
drop
then ;
\ emit pattern n-times
: d-emit-n ( x-char n-count -- )
boldness @ 0 do dup d-emit-off loop drop ;
: d-emit-byte ( x-char -- )
d-emit-n ;
\ emit single char
: d-emit ( u-char -- )
c-pos str-bounds do
i c@ d-emit-byte
loop
$00 d-emit-byte
;
\ : d-emit dup ." EMIT: " emit cr d-emit ;
: d-type ( c-addr u -- )
\ str-bounds ?do i c@ d-emit loop ;
bounds ?do i c@ d-emit loop ;
: d-length ( c-addr -- n-len )
\ 0 swap str-bounds
0 -rot bounds
?do
i c@ c-pos c@ +
1+
loop
dup 0 > if
1-
then boldness @ * ;
: d( [char] ) parse d-type flush immediate ;
: d" postpone s" postpone d-type immediate ;
: clear
buffer-off
off
0 cur-column !
;
: bussi
init-ws
clear
buffer-wave
$3F0000 text-color ! [char] B d-emit
$3F3F00 text-color ! [char] u d-emit
$003F00 text-color ! [char] s d-emit
$003F3F text-color ! [char] s d-emit
$00004F text-color ! [char] i d-emit
$3F3F3F text-color ! d" ;)"
flush
;
: >scroll ( c-addr -- )
2dup d-length 1+ 0 do
i 0 offset-column
clear
2dup d-type flush
100 ms
loop 2drop ;
: scroll( [char] ) parse >scroll immediate ;
: test-text
s" Hi there can anybody read this?" >scroll
;