diff --git a/emulator.pas b/emulator.pas index ce8b4f6..d878156 100644 --- a/emulator.pas +++ b/emulator.pas @@ -18,8 +18,8 @@ const IO = $ffff; var - Hlt, ASCII: boolean; //Halt and ASCII flags - Op: 0 .. $f; //Opcode + Hlt, ASCII, Verbose: boolean; //Halt, ASCII, and verbose flags + Op, Regs: 0 .. $f; //Opcode X, Y: 0 .. 3; //Register arguments Addr, IP, RP: word; //Address argument and instruction and return pointers R: array [0 .. 3] of byte; //General-purpose registers @@ -78,13 +78,30 @@ begin Punch.Pos := 0; {$endif} - //Read a program file and check for errors - if ParamCount <> 1 then begin - writeln ('Usage: emulator program'); + //Check the arguments + if ParamCount = 0 then begin + writeln ('Usage: emulator (-v) program (2> verbose_output)'); halt; 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-} - assign (Prog, ParamStr (1)); + if Verbose = true then assign (Prog, ParamStr (2)) + else assign (Prog, ParamStr (1)); reset (Prog); {$i+} if IOResult <> 0 then begin @@ -106,10 +123,14 @@ begin //Begin the main loop 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 //Opcode Op := Mem [IP] and $f0 shr 4; //Register arguments + Regs := Mem [IP] and $f; X := Mem [IP] and $c shr 2; Y := Mem [IP] and 3; IP := IP + 1; @@ -134,7 +155,8 @@ begin writeln ('Error: illegal instruction pointer value'); halt; end; - end; + end + else Addr := 0; //Decode and execute the instruction //Halt diff --git a/readme.md b/readme.md index 06cff61..75e06f7 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ Assembly. 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. Registers and Memory @@ -92,13 +92,13 @@ reference to or relative to a label. Memory-Mapped Devices --------------------- -Input and output are mapped to address FFFF. The emulator emulates a -glass teletype with local echo. +Input and output are mapped to address FFFF; the emulator emulates a +roughly 1000 CPS glass teletype with local echo. Arbitrary devices can be mapped to the other reserved addresses. -In Linux the emulator can be compiled with support for a line printer -and an emulated punched tape reader and punch with the arguments +In Linux the emulator can be compiled with support for a character +printer and an emulated punched tape reader and punch with the arguments -dprinter and -dtape respectively. The printer is mapped to address FFFE 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