Reverse ttysafe escaping order
Sending the escape after its target made things complicated for upcoming stuff I want to add. Although it makes `recv.asm` slightly larger, it's really worth it.
This commit is contained in:
parent
69f0c6dafd
commit
049f2cf222
@ -1,7 +1,17 @@
|
|||||||
ld hl, 0x3000 ; memory address where to put contents.
|
.equ COM_DRV_ADDR 0x0238 ; replace with *CL's DCB addr
|
||||||
|
.equ DEST_ADDR 0x3000 ; memory address where to put contents.
|
||||||
|
|
||||||
|
; We process the 0x20 exception by pre-putting a mask in the (HL) we're going
|
||||||
|
; to write to. If it wasn't a 0x20, we put a 0xff mask. If it was a 0x20, we
|
||||||
|
; put a 0x7f mask.
|
||||||
|
|
||||||
|
ld hl, DEST_ADDR
|
||||||
loop:
|
loop:
|
||||||
|
ld a, 0xff
|
||||||
|
ld (hl), a ; default mask
|
||||||
|
loop2:
|
||||||
ld a, 0x03 ; @GET
|
ld a, 0x03 ; @GET
|
||||||
ld de, 0xffff ; replace with *CL's DCB addr
|
ld de, COM_DRV_ADDR
|
||||||
rst 0x28
|
rst 0x28
|
||||||
jr nz, maybeerror
|
jr nz, maybeerror
|
||||||
or a
|
or a
|
||||||
@ -9,25 +19,24 @@ loop:
|
|||||||
; @PUT that char back
|
; @PUT that char back
|
||||||
ld c, a
|
ld c, a
|
||||||
ld a, 0x04 ; @PUT
|
ld a, 0x04 ; @PUT
|
||||||
ld de, 0xffff ; replace with *CL's DCB addr
|
|
||||||
rst 0x28
|
rst 0x28
|
||||||
jr nz, error
|
jr nz, error
|
||||||
ld a, c
|
ld a, c
|
||||||
cp 0x20
|
cp 0x20
|
||||||
jr z, adjust
|
jr z, escapechar
|
||||||
write:
|
; not an escape char, just apply the mask and write
|
||||||
|
and (hl)
|
||||||
ld (hl), a
|
ld (hl), a
|
||||||
inc hl
|
inc hl
|
||||||
jr loop
|
jr loop
|
||||||
adjust:
|
escapechar:
|
||||||
dec hl
|
; adjust by setting (hl) to 0x7f
|
||||||
ld a, (hl)
|
res 7, (hl)
|
||||||
and 0x7f
|
jr loop2
|
||||||
jr write
|
|
||||||
maybeerror:
|
maybeerror:
|
||||||
; was it an error?
|
; was it an error?
|
||||||
or a
|
or a
|
||||||
jr z, loop ; not an error, just loop
|
jr z, loop2 ; not an error, just loop
|
||||||
; error
|
; error
|
||||||
error:
|
error:
|
||||||
ld c, a ; Error code from @GET/@PUT
|
ld c, a ; Error code from @GET/@PUT
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
/* Converts stdin to a content that is "tty safe", that is, that it doesn't
|
/* Converts stdin to a content that is "tty safe", that is, that it doesn't
|
||||||
* contain ASCII control characters that can mess up serial communication.
|
* contain ASCII control characters that can mess up serial communication.
|
||||||
* How it works is that it leaves any char > 0x20 intact, but any char <= 0x20
|
* How it works is that it leaves any char > 0x20 intact, but any char <= 0x20
|
||||||
* is replaced by two chars: char|0x80, 0x20. A 0x20 char always indicate "take
|
* is replaced by two chars: 0x20, then char|0x80. A 0x20 char always indicate
|
||||||
* the char you've just received and unset the 7th bit from it".
|
* "take the next char you'll receive and unset the 7th bit from it".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@ -13,8 +13,8 @@ int main(void)
|
|||||||
int c = getchar();
|
int c = getchar();
|
||||||
while (c != EOF) {
|
while (c != EOF) {
|
||||||
if (c <= 0x20) {
|
if (c <= 0x20) {
|
||||||
putchar(c|0x80);
|
|
||||||
putchar(0x20);
|
putchar(0x20);
|
||||||
|
putchar(c|0x80);
|
||||||
} else {
|
} else {
|
||||||
putchar(c&0xff);
|
putchar(c&0xff);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user