Implemented input for Unsigned and Integer

This commit is contained in:
Bartłomiej Szostak 2024-05-18 14:46:34 +02:00
parent bce77d6846
commit 30ea84ec5c
No known key found for this signature in database
GPG Key ID: 562DACF230A18086
3 changed files with 24 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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;