Add verbose function to the emulator and correct some terminology in and reword the readme slightly
This commit is contained in:
parent
582c13630c
commit
06f4c731c3
2 changed files with 34 additions and 12 deletions
36
emulator.pas
36
emulator.pas
|
@ -18,8 +18,8 @@ const
|
||||||
IO = $ffff;
|
IO = $ffff;
|
||||||
|
|
||||||
var
|
var
|
||||||
Hlt, ASCII: boolean; //Halt and ASCII flags
|
Hlt, ASCII, Verbose: boolean; //Halt, ASCII, and verbose flags
|
||||||
Op: 0 .. $f; //Opcode
|
Op, Regs: 0 .. $f; //Opcode
|
||||||
X, Y: 0 .. 3; //Register arguments
|
X, Y: 0 .. 3; //Register arguments
|
||||||
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
|
||||||
|
@ -78,13 +78,30 @@ begin
|
||||||
Punch.Pos := 0;
|
Punch.Pos := 0;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
//Read a program file and check for errors
|
//Check the arguments
|
||||||
if ParamCount <> 1 then begin
|
if ParamCount = 0 then begin
|
||||||
writeln ('Usage: emulator program');
|
writeln ('Usage: emulator (-v) program (2> verbose_output)');
|
||||||
halt;
|
halt;
|
||||||
end;
|
end;
|
||||||
|
if ParamStr (1) = '-v' then begin
|
||||||
|
Verbose := true;
|
||||||
|
if ParamCount <> 2 then begin
|
||||||
|
writeln ('Usage: emulator (-v) program (2> verbose_output)');
|
||||||
|
halt;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
Verbose := false;
|
||||||
|
if ParamCount <> 1 then begin
|
||||||
|
writeln ('Usage: emulator (-v) program (2> verbose_output)');
|
||||||
|
halt;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//Read a program file and check for errors
|
||||||
{$i-}
|
{$i-}
|
||||||
assign (Prog, ParamStr (1));
|
if Verbose = true then assign (Prog, ParamStr (2))
|
||||||
|
else assign (Prog, ParamStr (1));
|
||||||
reset (Prog);
|
reset (Prog);
|
||||||
{$i+}
|
{$i+}
|
||||||
if IOResult <> 0 then begin
|
if IOResult <> 0 then begin
|
||||||
|
@ -106,10 +123,14 @@ begin
|
||||||
//Begin the main loop
|
//Begin the main loop
|
||||||
while Hlt = false do begin
|
while Hlt = false do begin
|
||||||
|
|
||||||
|
//Print the CPU state to StdErr
|
||||||
|
if Verbose = true then writeln (StdErr, 'IR: ', IntToHex (Op, 1), IntToHex (Regs, 1), IntToHex (Addr, 4), '; IP: ', IntToHex (IP, 4), ', RP: ', IntToHex (RP, 4), '; R0: ', IntToHex (R[0], 2), ', R1: ', IntToHex (R[1], 2), ', R2: ', IntToHex (R[2], 2), ', R3: ', IntToHex (R[3], 2), ansichar ($d));
|
||||||
|
|
||||||
//Fetch the instruction and increment the instruction pointer
|
//Fetch the instruction and increment the instruction pointer
|
||||||
//Opcode
|
//Opcode
|
||||||
Op := Mem [IP] and $f0 shr 4;
|
Op := Mem [IP] and $f0 shr 4;
|
||||||
//Register arguments
|
//Register arguments
|
||||||
|
Regs := Mem [IP] and $f;
|
||||||
X := Mem [IP] and $c shr 2;
|
X := Mem [IP] and $c shr 2;
|
||||||
Y := Mem [IP] and 3;
|
Y := Mem [IP] and 3;
|
||||||
IP := IP + 1;
|
IP := IP + 1;
|
||||||
|
@ -134,7 +155,8 @@ begin
|
||||||
writeln ('Error: illegal instruction pointer value');
|
writeln ('Error: illegal instruction pointer value');
|
||||||
halt;
|
halt;
|
||||||
end;
|
end;
|
||||||
end;
|
end
|
||||||
|
else Addr := 0;
|
||||||
|
|
||||||
//Decode and execute the instruction
|
//Decode and execute the instruction
|
||||||
//Halt
|
//Halt
|
||||||
|
|
10
readme.md
10
readme.md
|
@ -17,7 +17,7 @@ Assembly.
|
||||||
Speed
|
Speed
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Thingamajig does not have a prescribed speed. The emulator should run at
|
Thingamajig does not have a prescribed speed. The emulator runs at
|
||||||
roughly 500 KIPS.
|
roughly 500 KIPS.
|
||||||
|
|
||||||
Registers and Memory
|
Registers and Memory
|
||||||
|
@ -92,13 +92,13 @@ reference to or relative to a label.
|
||||||
Memory-Mapped Devices
|
Memory-Mapped Devices
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
Input and output are mapped to address FFFF. The emulator emulates a
|
Input and output are mapped to address FFFF; the emulator emulates a
|
||||||
glass teletype with local echo.
|
roughly 1000 CPS glass teletype with local echo.
|
||||||
|
|
||||||
Arbitrary devices can be mapped to the other reserved addresses.
|
Arbitrary devices can be mapped to the other reserved addresses.
|
||||||
|
|
||||||
In Linux the emulator can be compiled with support for a line printer
|
In Linux the emulator can be compiled with support for a character
|
||||||
and an emulated punched tape reader and punch with the arguments
|
printer and an emulated punched tape reader and punch with the arguments
|
||||||
-dprinter and -dtape respectively. The printer is mapped to address FFFE
|
-dprinter and -dtape respectively. The printer is mapped to address FFFE
|
||||||
and the tape reader and punch to FFFD. The printer prints into
|
and the tape reader and punch to FFFD. The printer prints into
|
||||||
/dev/usb/lp0 and the tape files read from and punched to are (re)set
|
/dev/usb/lp0 and the tape files read from and punched to are (re)set
|
||||||
|
|
Loading…
Reference in a new issue