Add punched tape emulation support

This commit is contained in:
CrazyEttin 2022-08-14 12:54:37 +03:00
parent 5d92a33796
commit 268bfcb843
2 changed files with 62 additions and 10 deletions

View File

@ -2,7 +2,7 @@ program Emulator;
{$MODE OBJFPC} {$MODE OBJFPC}
uses Crt; uses SysUtils, Crt;
const const
IO = $ffff; IO = $ffff;
@ -14,7 +14,10 @@ var
Addr, IP, RP: word; //Address argument and instruction and return pointers Addr, IP, RP: word; //Address argument and instruction and return pointers
R: array [0 .. 3] of byte; //General-purpose registers R: array [0 .. 3] of byte; //General-purpose registers
Mem: array [0 .. $ffef] of byte; //Memory Mem: array [0 .. $ffef] of byte; //Memory
Prog{$ifdef printer}, Prn{$endif}: file of byte; //Program file and printer Prog{$ifdef printer}, Prn{$endif}{$ifdef tape}, TapeIn, TapeOut{$endif}: file of byte; //Program file, line printer, and punched tape reader and keypunch
{$ifdef tape}
TapePos: integer; //Punched tape reader position pointer
{$endif}
Ch: ansichar; //Character for input and output Ch: ansichar; //Character for input and output
begin begin
@ -23,6 +26,9 @@ begin
Hlt := false; Hlt := false;
IP := 0; IP := 0;
RP := $fff0; RP := $fff0;
{$ifdef tape}
TapePos := 0;
{$endif}
//Read a program file and check for errors //Read a program file and check for errors
if ParamCount <> 1 then begin if ParamCount <> 1 then begin
@ -121,23 +127,42 @@ begin
else if Op = 9 then R [X] := R [X] xor R [Y] else if Op = 9 then R [X] := R [X] xor R [Y]
//Load //Load
else if Op = $a then begin else if Op = $a then begin
//Input //Dumb terminal input
if Addr = IO then begin if Addr = IO then begin
Ch := ReadKey; Ch := ReadKey;
write (Ch); write (Ch); //Local echo
R [X] := byte (Ch); R [X] := byte (Ch);
end end
//Punched tape reader
{$ifdef tape}
else if Addr = $fffd then begin
assign (TapeIn, 'tapein');
try
reset (TapeIn);
seek (TapeIn, TapePos);
if eof (TapeIn) = false then begin
read (TapeIn, R [X]);
TapePos := TapePos + 1;
end
else R [X] := 0;
close (TapeIn);
except
R [X] := 0;
TapePos := 0;
end;
end
{$endif}
//Regular load //Regular load
else R [X] := Mem [Addr]; else R [X] := Mem [Addr];
end end
//Store //Store
else if Op = $b then begin else if Op = $b then begin
//Output //Dumb terminal output
if Addr = IO then begin if Addr = IO then begin
Ch := ansichar (R [X]); Ch := ansichar (R [X]);
write (Ch); write (Ch);
end end
//Printer //Line printer
{$ifdef printer} {$ifdef printer}
else if Addr = $fffe then begin else if Addr = $fffe then begin
assign (Prn, '/dev/usb/lp0'); assign (Prn, '/dev/usb/lp0');
@ -149,6 +174,29 @@ begin
end; end;
end end
{$endif} {$endif}
//Punched tape keypunch
{$ifdef tape}
else if Addr = $fffd then begin
assign (TapeOut, 'tapeout');
if FileExists ('tapeout') = false then begin
try
rewrite (TapeOut);
write (TapeOut, R [X]);
close (TapeOut);
except
end;
end
else begin
try
reset (TapeOut);
seek (TapeOut, FileSize (TapeOut));
write (TapeOut, R [X]);
close (TapeOut);
except
end;
end;
end
{$endif}
//Regular store //Regular store
else Mem [Addr] := R [X]; else Mem [Addr] := R [X];
end end

View File

@ -91,10 +91,14 @@ this.
Arbitrary devices can be mapped to the other reserved addresses. Arbitrary devices can be mapped to the other reserved addresses.
The emulator can be compiled in Linux with support for a line printer at The emulator can be compiled with support for a line printer at
/dev/usb/lp0 with the argument -dprinter. The printer is mapped to /dev/usb/lp0 with the argument -dprinter, and for an emulated punched
address FFFE in the emulator. If you wish to use a different setup you tape reader and keypunch at tapein and tapeout respectively with -dtape.
have to modify the code yourself. The printer is mapped to address FFFE in the emulator and the tape
reader and keypunch 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.
Initial Program Loader Initial Program Loader
---------------------- ----------------------