diff --git a/Makefile b/Makefile index 31474a8..80b2cc4 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,10 @@ default: sillymachine sillymachine: ./src/sillymachine.adb ./src/*.adb ./src/*.ads gnatmake ./src/sillymachine.adb -sillymachine.exe: ./src/sillymachine.adb ./src/*.adb ./src/*.ads +debug: ./src/sillymachine.adb ./src/*.adb ./src/*.ads + gnatmake ./src/sillymachine.adb -o sillymachine-debug -g + +win: ./src/sillymachine.adb ./src/*.adb ./src/*.ads x86_64-w64-mingw32-gnatmake src/sillymachine.adb -lwinmm -lgdi32 diff --git a/src/shardware.adb b/src/shardware.adb index c613151..415774c 100644 --- a/src/shardware.adb +++ b/src/shardware.adb @@ -1,8 +1,12 @@ with Interfaces; use Interfaces; with Ada.Text_IO; use Ada.Text_IO; +with Ada.Integer_Text_IO; +with Ada.Float_Text_IO; package body Shardware is + package U_IO is new Ada.Text_IO.Modular_IO (Unsigned_32); + function TempBytes (Instruction : ByteArr) return ByteArr is TheBytes : ByteArr (1 .. 4); begin @@ -194,11 +198,11 @@ package body Shardware is begin if ReverseFlag then for i in reverse 1 .. Stuff'Length loop - Memory (Address - 1 + Unsigned_32(i)) := Stuff (Unsigned_32(i)); + Memory (Address + Unsigned_32(i)) := Stuff (Unsigned_32(i)); end loop; else for i in 1 .. Stuff'Length loop - Memory (Address - 1 + Unsigned_32(i)) := Stuff (Unsigned_32(i)); + Memory (Address + Unsigned_32(i)) := Stuff (Unsigned_32(i)); end loop; end if; end WriteMem; @@ -212,8 +216,8 @@ package body Shardware is Length : Integer := Integer(Registers (3)); CharBuff : String (1 .. Length); begin - Get_Line(CharBuff, Length); if InputTypeFlag = LEString then + Get_Line(CharBuff, Length); for i in 1 .. Length loop Memory (Pointer + Unsigned_32(i)) := Character'Pos(CharBuff (i)); end loop; @@ -221,22 +225,28 @@ package body Shardware is elsif InputTypeFlag = LEUint then declare ByteBuff : ByteArr (1 .. 4); + ValU : Unsigned_32 := 0; begin - ByteBuff := UToBytes(Unsigned_32'Value(CharBuff)); + U_IO.Get(ValU); + ByteBuff := UToBytes(ValU); WriteMem(Memory, Pointer, ByteBuff, True); end; elsif InputTypeFlag = LEInt then declare ByteBuff : ByteArr (1 .. 4); + ValI : Integer := 0; begin - ByteBuff := IToBytes(Integer'Value(CharBuff)); + Ada.Integer_Text_IO.Get(ValI); + ByteBuff := IToBytes(ValI); WriteMem(Memory, Pointer, ByteBuff, True); end; elsif InputTypeFlag = LEFloat then declare ByteBuff : ByteArr (1 .. 4); + ValF : Float := 0.0; begin - ByteBuff := FToBytes(Float'Value(CharBuff)); + Ada.Float_Text_IO.Get(ValF); + ByteBuff := FToBytes(ValF); WriteMem(Memory, Pointer, ByteBuff, True); end; else diff --git a/src/sillymachine.adb b/src/sillymachine.adb index 9d92212..d515df2 100644 --- a/src/sillymachine.adb +++ b/src/sillymachine.adb @@ -213,11 +213,13 @@ begin when 3 => InputTypeFlag := LEFloat; when others => InputTypeFlag := LEString; end case; - when 65535 => goto THE_END; -- exit opcode + when 65535 => + goto THE_END; -- exit opcode when others => null; end case; - PC := PC + 16; -- increment program counter to next instruction + PC := PC + 16; -- increment program counter to next instruction + end loop; end;