The problem can be reproduced with the code below, or alternatively in ZORK2, which appears to show the same (or similar) issue.
I may well have missed something, so I'd be grateful for any pointers!
Thanks,
D.
Code: Select all
BDOS equ 05h ; standard cp/m entry
DCONIO equ 06h ; direct console I/O
INPREQ equ 0ffh ; console input request
org 0100h
ld de,msg ; print 'welcome' msg
call pstr
loop:
call getchar ; get a character
or a
jr z,loop ; nothing, so loop
call putchar ; print the character
jr loop
getchar:
push bc
push de
ld c,DCONIO ; direct console i/o
ld e,INPREQ ; input request
call BDOS ; any chr typed?
pop de ; if yes, (a)<--char
pop bc ; else (a)<--00h (ignore chr)
or a
ret
;
putchar:
push bc
push de
push af
push hl
ld c,DCONIO ; direct console i/o
ld e,a ; output char (a)
call BDOS
pop hl
pop af
pop de
pop bc
ret
pstr:
ld a,(de) ; get a character
inc de ; bump pointer
call putchar ; show character
cp 0dh ; was it a cr?
jr nz,pstr ; no, next character
ret ; yes, returns
msg: db "Type something:",0ah, 0dh