From 0e328339d46c06c0b80dbc15ab2ff226532629a7 Mon Sep 17 00:00:00 2001 From: Frederic Stark Date: Sun, 29 Sep 2024 13:39:21 +0200 Subject: [PATCH 1/3] Added 'K' feature: press 'Shift-K' to 'type' file KBD.TXT --- KBD.TXT | 1 + README | 13 +++++++++++++ src/keyboard.c | 10 ++++++++++ src/makefile | 3 ++- src/memory.c | 25 ++++++++++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 KBD.TXT diff --git a/KBD.TXT b/KBD.TXT new file mode 100644 index 0000000..ef3da74 --- /dev/null +++ b/KBD.TXT @@ -0,0 +1 @@ +Change content of the "kbd.txt" file to change auto-keyboard input. diff --git a/README b/README index 61c40d5..1fbba43 100644 --- a/README +++ b/README @@ -1,3 +1,16 @@ +# Fork of napple1 + +This forks enables to emulate keyboard entry on the apple1 + +This kludge is done by creating a "KBD.TXT" file. When pressing "shift-K", +the keyboard I/O will be replaced by the content of this file. + +This have been done to be able to load basic programs and use the 'dump" +features to transfer them to binary files. + + + + napple1 is an Apple 1 emulator using ncurses, ported from the SDL version Pom1 emulafor. If you have some questions, please report it as an issue. diff --git a/src/keyboard.c b/src/keyboard.c index f66628a..398c6bc 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -25,6 +25,10 @@ #include "keyboard.h" #include "screen.h" +#include + +FILE *kbd_txt; + int handleInput(void) { char tmp; @@ -32,6 +36,12 @@ int handleInput(void) tmp = '\0'; while ( (tmp = getch_screen()) == '\0' ) ; + if (tmp=='K') + { + /* We open the "KBD.TXT" file if it exists */ + kbd_txt = fopen("KBD.TXT", "r"); + return 1; + } if (tmp == 'B') { loadBasic(); resetPia6820(); diff --git a/src/makefile b/src/makefile index eeac56d..e7af123 100644 --- a/src/makefile +++ b/src/makefile @@ -1,7 +1,8 @@ # napple1 makefile # Nobu Hatano CC = gcc -CFLAGS = -Wall -ansi +CFLAGS = -Wall +# CFLAGS = -Wall -ansi THREAD = -lpthread # Support Linux and Cygwin diff --git a/src/memory.c b/src/memory.c index fd43898..9109113 100644 --- a/src/memory.c +++ b/src/memory.c @@ -162,7 +162,30 @@ unsigned char memRead(unsigned short address) if (address == 0xD012) return readDsp(); if (address == 0xD011) - return readKbdCr(); + { + unsigned char v = readKbdCr(); + extern FILE *kbd_txt; + if (!(v & 0x80) && kbd_txt) + { + // Read on char from file + int c = fgetc(kbd_txt); + if (c!=EOF) + { + if (c=='\n') + c = 0x0d; + if (v>='a' && v<='z') + c = c - 'a' + 'A'; + writeKbd((unsigned char)(c + 0x80)); + writeKbdCr(0xA7); + } + else + { + fclose(kbd_txt); + kbd_txt = NULL; + } + } + return v; + } if (address == 0xD010) return readKbd(); From 13baf1a6a7901be9524aba6bbb400e688dad6580 Mon Sep 17 00:00:00 2001 From: Frederic Stark Date: Sun, 6 Oct 2024 14:49:16 +0200 Subject: [PATCH 2/3] Cleaned up autotyping and made code closer to original repo style --- AUTOTYPING.TXT | 1 + KBD.TXT | 1 - README | 12 ++---------- src/keyboard.c | 45 ++++++++++++++++++++++++++++++++++++++------- src/keyboard.h | 3 +++ src/makefile | 3 +-- src/memory.c | 23 +++-------------------- 7 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 AUTOTYPING.TXT delete mode 100644 KBD.TXT diff --git a/AUTOTYPING.TXT b/AUTOTYPING.TXT new file mode 100644 index 0000000..aa2bde6 --- /dev/null +++ b/AUTOTYPING.TXT @@ -0,0 +1 @@ +280.28f diff --git a/KBD.TXT b/KBD.TXT deleted file mode 100644 index ef3da74..0000000 --- a/KBD.TXT +++ /dev/null @@ -1 +0,0 @@ -Change content of the "kbd.txt" file to change auto-keyboard input. diff --git a/README b/README index 1fbba43..5ba6dbf 100644 --- a/README +++ b/README @@ -1,15 +1,7 @@ # Fork of napple1 -This forks enables to emulate keyboard entry on the apple1 - -This kludge is done by creating a "KBD.TXT" file. When pressing "shift-K", -the keyboard I/O will be replaced by the content of this file. - -This have been done to be able to load basic programs and use the 'dump" -features to transfer them to binary files. - - - +This forks enables to emulate keyboard entry on the apple1. When pressing "shift-K", +the keyboard I/O will be replaced by the content of the 'AUTOTYPING.TXT' file. (note: this have been done to be able to type in basic programs and use the 'dump" features to transfer them to binary files). napple1 is an Apple 1 emulator using ncurses, ported from the SDL version Pom1 emulafor. If you have some questions, please report it as an issue. diff --git a/src/keyboard.c b/src/keyboard.c index 398c6bc..ea74af3 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -27,7 +27,40 @@ #include -FILE *kbd_txt; +FILE *autotyping_file = NULL; + +int startAutotyping(const char *filename) +{ + if (autotyping_file) + stopAutotyping(); + autotyping_file = fopen(filename, "r"); + return !!autotyping_file; +} + +int nextAutotyping(void) +{ + if (!autotyping_file) + return -1; + int c = fgetc(autotyping_file); + if (c!=EOF) { + if (c=='\n') + c = 0x0d; + if (c>='a' && c<='z') + c = c - 'a' + 'A'; + writeKbd((unsigned char)(c + 0x80)); + writeKbdCr(0xA7); + } + else + stopAutotyping(); + return c; +} + +void stopAutotyping(void) +{ + if (autotyping_file) + fclose(autotyping_file); + autotyping_file = NULL; +} int handleInput(void) { @@ -36,13 +69,11 @@ int handleInput(void) tmp = '\0'; while ( (tmp = getch_screen()) == '\0' ) ; - if (tmp=='K') - { - /* We open the "KBD.TXT" file if it exists */ - kbd_txt = fopen("KBD.TXT", "r"); - return 1; + if (tmp=='K') { + if (startAutotyping("AUTOTYPING.TXT")) + return 1; } - if (tmp == 'B') { + else if (tmp == 'B') { loadBasic(); resetPia6820(); resetM6502(); diff --git a/src/keyboard.h b/src/keyboard.h index 990226f..fff4664 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -20,3 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ int handleInput(void); +int startAutotyping(const char *filename); +int nextAutotyping(void); +void stopAutotyping(void); diff --git a/src/makefile b/src/makefile index e7af123..eeac56d 100644 --- a/src/makefile +++ b/src/makefile @@ -1,8 +1,7 @@ # napple1 makefile # Nobu Hatano CC = gcc -CFLAGS = -Wall -# CFLAGS = -Wall -ansi +CFLAGS = -Wall -ansi THREAD = -lpthread # Support Linux and Cygwin diff --git a/src/memory.c b/src/memory.c index 9109113..fe90f18 100644 --- a/src/memory.c +++ b/src/memory.c @@ -82,6 +82,7 @@ #include "memory.h" #include "screen.h" #include "msgbuf.h" +#include "keyboard.h" #define MEMMAX 0xFFFF #define FNAME_LEN_MAX 1024 @@ -164,26 +165,8 @@ unsigned char memRead(unsigned short address) if (address == 0xD011) { unsigned char v = readKbdCr(); - extern FILE *kbd_txt; - if (!(v & 0x80) && kbd_txt) - { - // Read on char from file - int c = fgetc(kbd_txt); - if (c!=EOF) - { - if (c=='\n') - c = 0x0d; - if (v>='a' && v<='z') - c = c - 'a' + 'A'; - writeKbd((unsigned char)(c + 0x80)); - writeKbdCr(0xA7); - } - else - { - fclose(kbd_txt); - kbd_txt = NULL; - } - } + if (!(v & 0x80)) + nextAutotyping(); return v; } if (address == 0xD010) From 8762bf447e0cc736f19a7110373cb7f25758b843 Mon Sep 17 00:00:00 2001 From: Frederic Stark Date: Sun, 6 Oct 2024 14:55:22 +0200 Subject: [PATCH 3/3] Updated README. Added sample AUTOTYPING.TXT. Fixed code style --- AUTOTYPING.TXT | 5 ++++- README | 8 ++------ src/memory.c | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/AUTOTYPING.TXT b/AUTOTYPING.TXT index aa2bde6..7ddee74 100644 --- a/AUTOTYPING.TXT +++ b/AUTOTYPING.TXT @@ -1 +1,4 @@ -280.28f +E000R +10 PRINT "HELLO, WORLD! "; +20 GOTO 10 +RUN diff --git a/README b/README index 5ba6dbf..56a8ea3 100644 --- a/README +++ b/README @@ -1,8 +1,3 @@ -# Fork of napple1 - -This forks enables to emulate keyboard entry on the apple1. When pressing "shift-K", -the keyboard I/O will be replaced by the content of the 'AUTOTYPING.TXT' file. (note: this have been done to be able to type in basic programs and use the 'dump" features to transfer them to binary files). - napple1 is an Apple 1 emulator using ncurses, ported from the SDL version Pom1 emulafor. If you have some questions, please report it as an issue. @@ -64,7 +59,7 @@ type E2B3R - Emulator commands Command Key Description --------------------------------------------------------------------- +--------------------------------------------------------------------------- Basic load Shidt + B Load rom/basic.rom to ram Dump core Shift + D Dump memory to core/_file name_ Load core Shift + L Load memory from core/_file name_ @@ -72,6 +67,7 @@ Reset Shift + R Reset the emulator Hard reset Shidt + H Reset & Clear memory Quit Shidt + Q Quit the emulator Mode Shift + M Mode change 8KB & 32KB ram mode + Shift + K Automatically type in AUTOTYPING.TXT file if present - Load / Save programs diff --git a/src/memory.c b/src/memory.c index fe90f18..46d4fd7 100644 --- a/src/memory.c +++ b/src/memory.c @@ -162,8 +162,7 @@ unsigned char memRead(unsigned short address) return readDspCr(); if (address == 0xD012) return readDsp(); - if (address == 0xD011) - { + if (address == 0xD011) { unsigned char v = readKbdCr(); if (!(v & 0x80)) nextAutotyping();