From 65f31e94ea3f49b2004dd8366a518c0ec3799084 Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Sun, 13 Feb 2022 18:49:15 +0100 Subject: [PATCH] add line input with prompt and backspace --- lib/apple1.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/apple1.h b/lib/apple1.h index 248acec..d1d0926 100644 --- a/lib/apple1.h +++ b/lib/apple1.h @@ -116,6 +116,46 @@ void apple1_input_line(byte *buffer, byte max) { buffer[x]=0; } +const byte prompt_char = ']'; + +void apple1_input_line_prompt(byte *buffer, byte max) { + byte x=0; + + woz_putc(prompt_char); + + while(1) { + byte c = apple1_getkey(); + buffer[x] = c; + if(c==13) { + // RETURN ends input + break; + } + else if(c==27) { + // ESC clears the string + x=0; + break; + } + else if(c==8 || c=='_') { + // BACKSPACE + if(x != 0) { + x--; + buffer[x] = 0; + woz_putc('\r'); + woz_putc(prompt_char); + woz_puts(buffer); + } + } + else { + // character input + if(x // for memcpy #define LOWRAM_START 0x280