Skip to content

Commit b958e8a

Browse files
ESC in GET now works, tidied up error handling in OSCLI
1 parent 7a42f9e commit b958e8a

File tree

1 file changed

+52
-36
lines changed

1 file changed

+52
-36
lines changed

patch.asm

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; Title: BBC Basic for AGON
33
; Author: Dean Belfield
44
; Created: 03/05/2022
5-
; Last Updated: 11/10/2022
5+
; Last Updated: 20/10/2022
66
;
77
; Modinfo:
88
; 24/07/2022: OSWRCH and OSRDCH now execute code in MOS
@@ -14,6 +14,7 @@
1414
; 24/09/2022: Added STAR_MKDIR, STAR_EDIT; file errors for MOS commands LOAD, SAVE, CD, ERASE, REN, DIR
1515
; 03/10/2022: Fixed OSBYTE_13 command
1616
; 11/10/2022: Fixed bug introduced in previous fix to OSBYTE_13, OSCLI now calls MOS
17+
; 20/10/2022: ESC in GET now works, tidied up error handling in OSCLI
1718
1819
.ASSUME ADL = 0
1920
@@ -76,19 +77,6 @@
7677
XREF BUF_PBCDL
7778
XREF ONEDIT
7879

79-
; OSWRCH: Write a character out to the ESP32 VDU handler via the MOS
80-
; A: Character to write
81-
;
82-
OSWRCH: RST.LIS 10h ; This is at odds with the manual - assembles to RST.L
83-
RET
84-
85-
; OSRDCH: Read a character in from the ESP32 keyboard handler
86-
;
87-
OSRDCH: MOSCALL mos_getkey
88-
OR A
89-
JR Z, OSRDCH ; Loop until key is pressed
90-
RET
91-
9280
; OSLINE: Invoke the line editor
9381
;
9482
OSLINE: LD E, 1 ; Default is to clear the buffer
@@ -163,7 +151,23 @@ $$: BIT.LIL 0, (IX+sysvar_vpd_pflags)
163151
;
164152
PROMPT: LD A,'>'
165153
JP OSWRCH
154+
155+
; OSWRCH: Write a character out to the ESP32 VDU handler via the MOS
156+
; A: Character to write
157+
;
158+
OSWRCH: RST.LIS 10h ; This is at odds with the manual - assembles to RST.L
159+
RET
166160

161+
; OSRDCH: Read a character in from the ESP32 keyboard handler
162+
; This is only called in GETS (eval.asm)
163+
;
164+
OSRDCH: MOSCALL mos_getkey ; Read keyboard
165+
OR A
166+
JR Z, OSRDCH ; Loop until key is pressed
167+
CP 1BH ; Check for ESC
168+
JR Z, ESCSET ; Yes, so set the ESC flag
169+
RET
170+
167171
;OSKEY - Read key with time-limit, test for ESCape.
168172
;Main function is carried out in user patch.
169173
; Inputs: HL = time limit (centiseconds)
@@ -184,26 +188,36 @@ $$: CP 1BH ; If we are not pressing ESC,
184188
SCF ; then flag we've got a character
185189
RET NZ
186190
;
191+
; ESCSET
192+
; Set the escape flag (bit 7 of FLAGS = 1) if escape is enabled (bit 6 of FLAGS = 0)
193+
;
187194
ESCSET: PUSH HL
188-
LD HL,FLAGS
189-
BIT 6,(HL) ; ESC DISABLED?
190-
JR NZ,ESCDIS
191-
SET 7,(HL) ; SET ESCAPE FLAG
195+
LD HL,FLAGS ; Pointer to FLAGS
196+
BIT 6,(HL) ; If bit 6 is set, then
197+
JR NZ,ESCDIS ; escape is disabled, so skip
198+
SET 7,(HL) ; Set bit 7, the escape flag
192199
ESCDIS: POP HL
193200
RET
194201
;
195-
ESCTEST: MOSCALL mos_getkey
196-
CP 1BH ; ESC
197-
JR Z,ESCSET
202+
; ESCTEST
203+
; Test for ESC key
204+
;
205+
ESCTEST: MOSCALL mos_getkey ; Read keyboard
206+
CP 1BH ; If ESC pressed then
207+
JR Z,ESCSET ; jump to the escape set routine
198208
RET
199209
;
200-
TRAP: CALL ESCTEST
201-
LTRAP: LD A,(FLAGS)
202-
OR A
203-
RET P
204-
LD HL,FLAGS
205-
RES 7,(HL)
206-
JP ESCAPE
210+
; TRAP
211+
; This is called whenever BASIC needs to check for ESC
212+
;
213+
TRAP: CALL ESCTEST ; Read keyboard, test for ESC, set FLAGS
214+
;
215+
LTRAP: LD A,(FLAGS) ; Get FLAGS
216+
OR A ; This checks for bit 7; if it is not set then the result will
217+
RET P ; be positive (bit 7 is the sign bit in Z80), so return
218+
LD HL,FLAGS ; Escape is pressed at this point, so
219+
RES 7,(HL) ; Clear the escape pressed flag and
220+
JP ESCAPE ; Jump to the ESCAPE error routine in exec.asm
207221

208222
;OSINIT - Initialise RAM mapping etc.
209223
;If BASIC is entered by BBCBASIC FILENAME then file
@@ -228,8 +242,6 @@ OSCLI: CALL SKIPSP
228242
RET Z
229243
CP '|'
230244
RET Z
231-
; CP '.'
232-
; JP Z,STAR_DOT ; *.
233245
EX DE,HL
234246
LD HL,COMDS
235247
OSCLI0: LD A,(DE)
@@ -277,16 +289,18 @@ OSCLI6: EX DE, HL ; HL: Buffer for command
277289
CALL CSTR_LINE ; Fetch the line
278290
POP HL ; HL: Pointer to command string in ACCS
279291
PUSH IY
280-
MOSCALL mos_oscli
292+
MOSCALL mos_oscli ; Returns OSCLI error in A
281293
POP IY
282-
RET
283-
284-
HUH: LD A,254
294+
OR A ; 0 means MOS returned OK
295+
RET Z ; So don't do anything
296+
JP OSERROR ; Otherwise it's a MOS error
297+
298+
HUH: LD A,254 ; Bad command error
285299
CALL EXTERR
286-
DB 'Bad command'
300+
DB "Bad command"
287301
DEFB 0
288302

289-
SKIPSP: LD A,(HL)
303+
SKIPSP: LD A,(HL)
290304
CP ' '
291305
RET NZ
292306
INC HL
@@ -501,6 +515,8 @@ OSCALL_TABLE: DB D4h
501515
DW OSWRCH
502516
DB F4h
503517
DW OSBYTE
518+
DB F7h
519+
DW OSCLI
504520
DB FFh
505521

506522
; OSOPEN

0 commit comments

Comments
 (0)