-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsole.fs
150 lines (123 loc) · 3.89 KB
/
console.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
146
147
148
149
150
\ the shell-thing
CREATE cmdline 64 ALLOT
0 VALUE cmdlen
CREATE cmdline' 64 ALLOT
0 VALUE cmdlen'
0 VALUE tick
\ terminal code
: PUT ( c color x y -- ) 3 ROLL @font 3 -ROLL udgput ;
: PUTS ( addr u color x y )
{ addr u color x y }
u 0 ?DO
addr I + C@ color x y PUT
4 x + TO x
LOOP ;
: mockup
s" DATA DISPLAY" 12 8 8 puts
s" 09jul18 16:40" 13 W 8 - 8 puts
s" MOCK-UP DISPLAY" 6 W 2/ 8 puts
6 W 2/ 15 2/ 1+ 8 * - 18 W 2/ 15 2/ 2+ 8 * + 18 line ;
: scroll ( -- )
W 6 * VRAM + ( line1pos+fbaddr )
VRAM ( line1pos+fbaddr fbaddr )
W H 6 - * ( line1pos+fbaddr fbaddr surface )
MOVE
bg @ 0 H 6 - W 6 rect
;
: ?scroll sy @ H 6 / 1- > IF scroll -1 sy @ + sy ! THEN ;
: move-cursor
1 sx +!
sx @ W 4 / 1- > IF 1 sy +! 0 sx ! THEN
?scroll ;
: at-xy ( x y -- ) sy ! sx ! ;
: ?put ( c -- )
\ non-printable characters
DUP 10 = IF 0 sx ! 1 sy +! DROP ?scroll EXIT THEN
DUP 13 = IF 0 sx ! 1 sy +! DROP ?scroll EXIT THEN
\ printable characters
DU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1 C, 1 C, 0 C, 1 C, 1 C, 0 C, 0 C, 1 C,
0 C, 1 C, 0 C, 0 C, 1 C, 0 C, 0 C, 1 C, 1 C, 1 C, 1 C, 1 C, 0 C, 0 C, 0 C, 1 C, 0 C, 0 C, 0 C, 1 C, 0 C, 0 C, 1 C, 0 C, 0 C, 0 C, 1 C, 1 C, 1 C, 0 C, 0 C, 0 C, 0 C, 0 C, 0 C, 0 C, 0 C, 0 C, 0 C, 0 C, 1 C, 0 C, 0 C, 0 C, 1 C, 1 C, 1 C, 0 C,
: print-logo ( -- )
CR
logo
5 0 DO
48 0 DO
DUP C@ IF 4 ELSE 32 THEN EMIT 1+
LOOP CR
LOOP CR CR DROP
;
: <init>
cmdline 64 ERASE
15 fg ! 0 bg ! bg @ cls
0 0 at-xy
print-logo
;
: exec-cmdline
\ breaks IF some word is NOT found (possibly other errors as well)...
\ can we circumvent it by revectoring ABORT ?
cmdline' 64 ERASE
cmdline cmdline' cmdlen MOVE
cmdlen TO cmdlen'
cmdline 64 ERASE
0 TO cmdlen
cmdline' cmdlen' EVALUATE
CR
;
0 VALUE cursor-drawn?
: undraw-cursor ( f -- ) cursor-drawn? IF bg @ sx @ 4 * sy @ 6 * 4 6 rect FALSE TO cursor-drawn? THEN ;
: draw-cursor ( f -- ) 13 sx @ 4 * sy @ 6 * 4 6 rect TRUE TO cursor-drawn? ;
: process-key ( c -- )
\ keybuffer 16 dump
\ enter/execute
13 OVER = IF
DROP
undraw-cursor
0 sx ! 1 sy +!
?scroll
exec-cmdline
EXIT
THEN
10 OVER = IF
DROP
undraw-cursor
0 sx ! 1 sy +!
?scroll
exec-cmdline
EXIT
THEN
\ delete backwards
8 OVER = IF
sx @ 0> IF
DROP undraw-cursor
BL ?PUT
-1 cmdlen + TO cmdlen 0 cmdline cmdlen + C!
THEN
EXIT
THEN
\ exit
\ ASCII ^ OVER = IF TRUE stopping ! EXIT THEN
\ other chars
cmdline cmdlen + C!
cmdlen 1+ TO cmdlen
1 sx +!
;
: <update>
keybuffer { kb }
BEGIN kb C@ WHILE kb C@ process-key kb 1+ TO kb REPEAT
tick 1+ 100 MOD TO tick
;
: <draw>
0 sx !
cmdline cmdlen TYPE
tick 50 < IF undraw-cursor ELSE draw-cursor THEN
;
\ this word starts the system, and will restart it when invoked
INSTALL retro-40