Skip to content

Commit ff9c0e9

Browse files
authored
Merge pull request #7 from nihirash/terminal_emulator_update
Terminal emulation update
2 parents e93239e + a6eb8c1 commit ff9c0e9

File tree

9 files changed

+235
-33
lines changed

9 files changed

+235
-33
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2024.05.04
1+
2024.06.09

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ EDOS=src/edos/edos.bin
66
all: $(BINARY)
77

88
$(BINARY): $(EDOS) $(SOURCES)
9-
(cd src && ez80asm -i zinc.asm ../$(BINARY))
9+
(cd src && ez80asm -i -l zinc.asm ../$(BINARY))
1010

1111
$(EDOS): $(SOURCES)
1212
date '+%Y.%m.%d' >.version

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,38 @@ zinc mbasic test
1919

2020
You shouldn't specify file extension for executable file(`.com` will be added automatically) and directory should no contain files with long file names.
2121

22+
## Terminal emulation layer
23+
24+
Currently, it supports "ADM-3a"-like compatible terminal emulation routines(like KayPro or some other computers).
25+
26+
It also allows disable(and re-enable terminal emulation routines) with `27, 255`(two bytes, 27 in decimal first, 255 in decimal secord) character sequence. If you disable terminal emulation routines you'll have possibility use all Agon's VDP commands, including graphics, sounds etc. Also you can get back to terminal emulation mode by same sequence.
27+
28+
### Control sequences and codes
29+
30+
* `0x01` - Home cursor
31+
32+
* `0x07` - Bell(makes single beep)
33+
34+
* `0x08` - move cursor left on one character
35+
36+
* `0x0C` - move cursor right on one character
37+
38+
* `0x14` - move cursor up on one character
39+
40+
* `0x16` - move cursor left on one character
41+
42+
* `0x17` - move cursor right on one character
43+
44+
* `0x18` - clean current line(after current cursor position)
45+
46+
* `0x1A` - clean screen
47+
48+
* `0x1B` - ESCAPE control sequences:
49+
50+
- `ESC`+`=` - load cursor position(`ESC`+`=`+`y-coordinate`+`x-coordinate`)
51+
52+
- `ESC`+`0xFF` - toggle terminal emulation(enable or disable it)
53+
2254
## Development
2355

2456
You should use fresh version of [agon-ez80asm](https://github.com/envenomator/agon-ez80asm) for building system.

src/edos/console.asm

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@
66
;; Works similar to real BDOS
77
console_in:
88
call CONIN
9-
call check_char
10-
ret c ;; Do not echo some symbols
11-
12-
push af
13-
ld c,a
14-
call console_out
15-
pop af
16-
17-
ret
189

19-
check_char:
2010
cp CR
2111
ret z
12+
2213
cp LF
2314
ret z
15+
2416
cp TAB
2517
ret z
18+
2619
cp BS
20+
ret z
21+
2722
ret z
23+
2824
cp ' '
25+
ret c ;; Do not echo some symbols
26+
27+
push af
28+
ld c,a
29+
call console_out
30+
pop af
31+
2932
ret
3033

3134
;; I think we can here skip a bit complex things

src/edos/core.asm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ CNTRLE: equ $05
1818
BS: equ $08
1919
TAB: equ $09
2020
LF: equ $0A
21+
CNTRLL: equ $0C
2122
CR: equ $0D
22-
23+
2324
include "mos.asm"
2425
entrypoint:
2526
jp edos

src/edos/ebios/console.asm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ bios_in:
4242
ld.lil (hl), a
4343

4444
ld a, (keycode)
45+
cp $15
46+
jr nz, @ok
47+
48+
ld a, CNTRLL
49+
50+
@ok:
4551

4652
RESTORESP
4753
ret

src/edos/mos.asm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
;; API CALLS
1212
MOS_GET_KEY: equ $00
13+
MOS_LOAD: equ $01
1314
MOS_DELETE: equ $05
1415
MOS_RENAME: equ $06
1516
MOS_SYS_VARS: equ $08
@@ -37,6 +38,10 @@ FA_CREATE: equ $04
3738
FA_CREATE_ALW: equ $08
3839
FA_OPEN_ALW: equ $10
3940

40-
VAR_VKEYCOUNT: equ $19
41+
VAR_VDP_DONE: equ $04
4142
VAR_KEYASCII: equ $05
42-
VAR_KEYDOWN: equ $18
43+
VAR_CURSORX: equ $07
44+
VAR_CURSORY: equ $08
45+
VAR_SCRWIDTH: equ $13
46+
VAR_KEYDOWN: equ $18
47+
VAR_VKEYCOUNT: equ $19

src/terminal.asm

Lines changed: 170 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,52 @@
1010
;; Emulates simple ADM-3a like terminal
1111
;; It's good enough and fast
1212

13-
TERM_HOME: equ $01
14-
TERM_LEFT: equ $08
15-
TERM_CLS: equ $0C
16-
TERM_UP: equ $14
17-
TERM_LEFT2: equ $16
18-
TERM_RIGHT: equ $17
19-
TERM_CLINE: equ $18
20-
TERM_CLS2: equ $1A
21-
TERM_ESC: equ $1B
13+
TERM_HOME: equ $01
14+
TERM_BELL: equ $07
15+
TERM_LEFT: equ $08
16+
TERM_FF: equ $0C
17+
TERM_UP: equ $14
18+
TERM_LEFT2: equ $16
19+
TERM_RIGHT: equ $17
20+
TERM_CLINE: equ $18
21+
TERM_CLS2: equ $1A
22+
TERM_ESC: equ $1B
23+
TERM_SWITCH: equ $ff
2224

2325
macro VDU byte
2426
ld a, byte
2527
rst.lil $10
2628
endmacro
2729

30+
;; Little preparation for work - setting variables and other things
31+
term_init:
32+
push ix
33+
MOSCALL MOS_SYS_VARS
34+
35+
lea hl, ix + VAR_CURSORX
36+
ld (term_pos), hl
37+
38+
lea hl, ix + VAR_SCRWIDTH
39+
ld (term_size), hl
40+
41+
lea hl, ix + VAR_VDP_DONE
42+
ld (cmd_done), hl
43+
44+
pop ix
45+
46+
ld hl, @msg
47+
ld bc, 0
48+
xor a
49+
rst.lil $18
50+
51+
ret
52+
@msg:
53+
db 13,10, "ADM-3a compatible terminal emulation started", 0
54+
55+
2856
termout:
2957
call _putc
3058
term_fsm: equ $ - 3
31-
3259
ret.lil
3360

3461
_cls:
@@ -44,21 +71,62 @@ _left:
4471
ret
4572
_up:
4673
VDU 11
47-
ret
74+
ret
4875
_right:
4976
VDU 9
5077
ret
5178

79+
_bell:
80+
VDU 7
81+
ret
82+
5283
_esc:
5384
cp '='
5485
jr z, @load_coords
55-
;; You can add some ESC codes here
5686

87+
;; Disable terminal emulation routine
88+
cp TERM_SWITCH
89+
jr z, @term_switch
90+
91+
;; You can add some ESC codes here
5792
jr exit_fsm
5893
@load_coords:
5994
ld hl, _loadx
6095
ld (term_fsm), hl
6196
ret
97+
@term_switch:
98+
ld hl, _vdp
99+
ld (term_fsm), hl
100+
ret
101+
102+
_vdp:
103+
cp TERM_ESC
104+
jr z, @vpd_esc
105+
106+
rst.lil $10
107+
ret
108+
@vpd_esc:
109+
ld hl, _vdp_esc
110+
ld (term_fsm), hl
111+
ret
112+
113+
_vdp_esc:
114+
cp TERM_SWITCH
115+
jr z, @back_to_emul
116+
117+
push af
118+
ld a, TERM_ESC
119+
rst.lil $10
120+
pop af
121+
rst.lil $10
122+
123+
ld hl, _vdp
124+
ld (term_fsm), hl
125+
ret
126+
@back_to_emul:
127+
ld hl, _putc
128+
ld (term_fsm), hl
129+
ret
62130

63131
_loadx:
64132
sub 32
@@ -88,7 +156,8 @@ exit_fsm:
88156
ret
89157

90158
_putc:
91-
and $7f
159+
cp TERM_FF
160+
jp z, _right
92161

93162
cp ' '
94163
jr nc, @draw
@@ -99,6 +168,9 @@ _putc:
99168
cp 10
100169
jr z, @draw
101170

171+
cp TERM_BELL
172+
jp z, _bell
173+
102174
;; Move cursor
103175
cp TERM_LEFT
104176
jp z, _left
@@ -109,15 +181,18 @@ _putc:
109181
cp TERM_RIGHT
110182
jp z, _right
111183

184+
112185
;; Home cursor
113186
cp TERM_HOME
114187
jp z, _home
115-
;; Clear screen
116-
cp TERM_CLS
117-
jp z, _cls
188+
189+
;; Clear screen
118190
cp TERM_CLS2
119191
jp z, _cls
120192

193+
cp TERM_CLINE
194+
jp z, _clear_line
195+
121196
;; ESC control sequences
122197
cp TERM_ESC
123198
jr z, @set_esc
@@ -134,11 +209,90 @@ _putc:
134209
ld (term_fsm), hl
135210
ret
136211

212+
213+
;; Clear current line. Mostly cause KayPro - many softwares except that this command is implemented
214+
;; Even if original ADM-3A haven't it
215+
_clear_line:
216+
xor a
217+
ld mb, a
218+
ld hl, (cmd_done)
219+
ld (hl), a
220+
221+
ld hl, @prepare
222+
ld bc, 3
223+
rst.lil $18
224+
225+
call @cmd_result
226+
227+
xor a
228+
ld (hl), a
229+
230+
ld hl, @prepare2
231+
ld bc, 3
232+
rst.lil $18
233+
call @cmd_result
234+
235+
ld hl, (term_pos)
236+
ld a, (hl)
237+
ld (@coords), a
238+
inc hl
239+
ld a, (hl)
240+
ld (@coords + 1), a
241+
242+
ld hl, @cmd
243+
ld bc, 3
244+
rst.lil $18
245+
246+
ld hl, (term_size)
247+
ld a, (hl)
248+
ld c, a
249+
ld a, (@coords)
250+
ld b, a
251+
ld a, c
252+
sub b
253+
ld b, a
254+
@loop:
255+
push bc
256+
VDU ' '
257+
pop bc
258+
djnz @loop
259+
260+
ld hl, @cmd
261+
ld bc, 3
262+
rst.lil $18
263+
264+
ld a, EDOS_PAGE
265+
ld mb, a
266+
ret
267+
;; It's more robust way be sure that our fetch command was executed
268+
@cmd_result:
269+
ld hl, (cmd_done)
270+
@wait:
271+
ld a, (hl)
272+
and a
273+
jr z, @wait
274+
ret
275+
@prepare:
276+
db 23, 0, $86
277+
@prepare2:
278+
db 23, 0, $82
279+
@cmd:
280+
db 31
281+
@coords:
282+
db 0
283+
db 0
284+
285+
137286
set_pos_cmd:
138287
db 31
139288
term_y:
140289
db 0
141290
term_x:
142291
db 0
143292

293+
cmd_done:
294+
dl 0
295+
term_pos:
296+
dl 0
297+
term_size:
144298
dl 0

0 commit comments

Comments
 (0)