1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-11 00:52:44 +03:00
mal/basic/readline_char.in.bas
Joel Martin 115e430d02 Basic: QBasic fixes/enabling. Recursive includes.
Enable QBasic console mode usage and fix bugs in newline handling
differences with C64 basic (cbm). To enable console mode for QBasic
programs, have basicpp.py prefix the output with the QB64 specific
console activation variables/functions.

One change to basicpp.py to make this change more straightfowards is
recursive includes so that includes can appear in more than just the
top level step files. This allows us to conditionally include the
right readline implementation. For QBasic in the special console mode
(instead of the default full-screen UI mode) we need to use the LINE
INPUT command in order to read input.
2017-09-14 23:50:15 -05:00

32 lines
787 B
QBasic

REM READLINE(A$) -> R$
READLINE:
EZ=0
PRINT A$;
C$="":R$="":C=0
READCH:
#cbm GET C$
#qbasic C$=INKEY$
IF C$="" THEN GOTO READCH
C=ASC(C$)
REM PRINT C
#qbasic IF ASC(C$)=8 THEN C=20:C$=CHR$(20)
IF C=4 OR C=0 THEN EZ=1:GOTO RL_DONE: REM EOF
IF C=127 OR C=20 THEN GOSUB RL_BACKSPACE
IF C=127 OR C=20 THEN GOTO READCH
IF (C<32 OR C>127) AND C<>13 THEN GOTO READCH
PRINT C$;
IF LEN(R$)<255 AND C$<>CHR$(13) THEN R$=R$+C$
IF LEN(R$)<255 AND C$<>CHR$(13) THEN GOTO READCH
RL_DONE:
RETURN
REM Assumes R$ has input buffer
RL_BACKSPACE:
IF LEN(R$)=0 THEN RETURN
R$=LEFT$(R$,LEN(R$)-1)
#cbm PRINT CHR$(157)+" "+CHR$(157);
#qbasic LOCATE ,POS(0)-1
#qbasic PRINT " ";
#qbasic LOCATE ,POS(0)-1
RETURN