From 2b92cf26a5b1d96c8596c1c7dfe2c13894b69259 Mon Sep 17 00:00:00 2001 From: CrazyEttin <> Date: Mon, 15 Aug 2022 17:21:01 +0300 Subject: [PATCH] Add support for non-ASCII keys and better the punched tape support --- emulator.pas | 48 ++++++++++++++++++++++++++++++++++++------------ readme.md | 16 ++++++++-------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/emulator.pas b/emulator.pas index 0b71b42..15454ad 100644 --- a/emulator.pas +++ b/emulator.pas @@ -8,7 +8,7 @@ const IO = $ffff; var - Hlt: boolean; //Halt flag + Hlt, ASCII: boolean; //Halt and ASCII flags Op: 0 .. $f; //Opcode X, Y: 0 .. 3; //Register arguments Addr, IP, RP: word; //Address argument and instruction and return pointers @@ -16,9 +16,10 @@ var Mem: array [0 .. $ffef] of byte; //Memory Prog{$ifdef printer}, Prn{$endif}{$ifdef tape}, TapeIn, TapeOut{$endif}: file of byte; //Program file, line printer, and punched tape reader and punch {$ifdef tape} - TapePos: integer; //Punched tape reader position pointer + TapeInFile: string; //Punched tape reader source file + TapeInPos: integer; //Punched tape reader position pointer {$endif} - Ch: ansichar; //Character for input and output + Ch, Scan: ansichar; //Character for input and output and scancode for non-ASCII keys begin @@ -27,7 +28,8 @@ begin IP := 0; RP := $fff0; {$ifdef tape} - TapePos := 0; + TapeInFile := ' '; + TapeInPos := 0; {$endif} //Read a program file and check for errors @@ -129,26 +131,48 @@ begin else if Op = $a then begin //Terminal input if Addr = IO then begin + //Read a keypress + repeat Ch := ReadKey; + //Check for non-ASCII keys + if Ch = ansichar (0) then begin + //Non-ASCII + if keypressed then begin + Scan := ReadKey; + {$ifdef tape} + //Insert a tape in the tape reader + if Scan = ansichar ($52) then begin + writeln (); + write ('Tape to be read: '); + readln (TapeInFile); + if TapeInFile = '' then TapeInFile := ' '; + TapeInPos := 0 + end; + {$endif} + ASCII := false; + end + //Null + else ASCII := true; + end + //Other ASCII + else ASCII := true; + until ASCII = true; + //Process the keypress write (Ch); //Local echo R [X] := byte (Ch); end //Tape reader {$ifdef tape} else if Addr = $fffd then begin - assign (TapeIn, 'tapein'); + assign (TapeIn, TapeInFile); try reset (TapeIn); - seek (TapeIn, TapePos); - if eof (TapeIn) = false then begin - read (TapeIn, R [X]); - TapePos := TapePos + 1; - end - else R [X] := 0; + seek (TapeIn, TapeInPos); + read (TapeIn, R [X]); + TapeInPos := TapeInPos + 1; close (TapeIn); except R [X] := 0; - TapePos := 0; end; end {$endif} diff --git a/readme.md b/readme.md index 2a04ceb..78d9f05 100644 --- a/readme.md +++ b/readme.md @@ -91,14 +91,14 @@ this. Arbitrary devices can be mapped to the other reserved addresses. -The emulator can be compiled with support for a line printer at -/dev/usb/lp0 with the argument -dprinter, and for an emulated punched -tape reader and punch at tapein and tapeout respectively with -dtape. -The printer is mapped to address FFFE in the emulator and the tape -reader and punch to FFFD. To reset the tape reader to the beginning of a -tape, for example to change the tape, read once with no file at tapein. -If you wish to use a different setup you have to modify the code -yourself. +The emulator can be compiled with support for a line printer and an +emulated punched tape reader and punch with the arguments -dprinter and +-dtape respectively. The printer outputs into /dev/usb/lp0 and the tape +punch to tapeout. To (re)set the tape to be read press the insert key at +any input and enter a file name; the input will resume after this. The +printer is mapped to address FFFE in the emulator and the tape reader +and punch to FFFD. If you wish to use a different setup you have to +modify the code yourself. Initial Program Loader ----------------------