Implemented input for Unsigned and Integer
This commit is contained in:
parent
bce77d6846
commit
30ea84ec5c
5
Makefile
5
Makefile
@ -4,7 +4,10 @@ default: sillymachine
|
|||||||
sillymachine: ./src/sillymachine.adb ./src/*.adb ./src/*.ads
|
sillymachine: ./src/sillymachine.adb ./src/*.adb ./src/*.ads
|
||||||
gnatmake ./src/sillymachine.adb
|
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
|
x86_64-w64-mingw32-gnatmake src/sillymachine.adb -lwinmm -lgdi32
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
with Interfaces; use Interfaces;
|
with Interfaces; use Interfaces;
|
||||||
with Ada.Text_IO; use Ada.Text_IO;
|
with Ada.Text_IO; use Ada.Text_IO;
|
||||||
|
with Ada.Integer_Text_IO;
|
||||||
|
with Ada.Float_Text_IO;
|
||||||
|
|
||||||
package body Shardware is
|
package body Shardware is
|
||||||
|
|
||||||
|
package U_IO is new Ada.Text_IO.Modular_IO (Unsigned_32);
|
||||||
|
|
||||||
function TempBytes (Instruction : ByteArr) return ByteArr is
|
function TempBytes (Instruction : ByteArr) return ByteArr is
|
||||||
TheBytes : ByteArr (1 .. 4);
|
TheBytes : ByteArr (1 .. 4);
|
||||||
begin
|
begin
|
||||||
@ -194,11 +198,11 @@ package body Shardware is
|
|||||||
begin
|
begin
|
||||||
if ReverseFlag then
|
if ReverseFlag then
|
||||||
for i in reverse 1 .. Stuff'Length loop
|
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;
|
end loop;
|
||||||
else
|
else
|
||||||
for i in 1 .. Stuff'Length loop
|
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 loop;
|
||||||
end if;
|
end if;
|
||||||
end WriteMem;
|
end WriteMem;
|
||||||
@ -212,8 +216,8 @@ package body Shardware is
|
|||||||
Length : Integer := Integer(Registers (3));
|
Length : Integer := Integer(Registers (3));
|
||||||
CharBuff : String (1 .. Length);
|
CharBuff : String (1 .. Length);
|
||||||
begin
|
begin
|
||||||
Get_Line(CharBuff, Length);
|
|
||||||
if InputTypeFlag = LEString then
|
if InputTypeFlag = LEString then
|
||||||
|
Get_Line(CharBuff, Length);
|
||||||
for i in 1 .. Length loop
|
for i in 1 .. Length loop
|
||||||
Memory (Pointer + Unsigned_32(i)) := Character'Pos(CharBuff (i));
|
Memory (Pointer + Unsigned_32(i)) := Character'Pos(CharBuff (i));
|
||||||
end loop;
|
end loop;
|
||||||
@ -221,22 +225,28 @@ package body Shardware is
|
|||||||
elsif InputTypeFlag = LEUint then
|
elsif InputTypeFlag = LEUint then
|
||||||
declare
|
declare
|
||||||
ByteBuff : ByteArr (1 .. 4);
|
ByteBuff : ByteArr (1 .. 4);
|
||||||
|
ValU : Unsigned_32 := 0;
|
||||||
begin
|
begin
|
||||||
ByteBuff := UToBytes(Unsigned_32'Value(CharBuff));
|
U_IO.Get(ValU);
|
||||||
|
ByteBuff := UToBytes(ValU);
|
||||||
WriteMem(Memory, Pointer, ByteBuff, True);
|
WriteMem(Memory, Pointer, ByteBuff, True);
|
||||||
end;
|
end;
|
||||||
elsif InputTypeFlag = LEInt then
|
elsif InputTypeFlag = LEInt then
|
||||||
declare
|
declare
|
||||||
ByteBuff : ByteArr (1 .. 4);
|
ByteBuff : ByteArr (1 .. 4);
|
||||||
|
ValI : Integer := 0;
|
||||||
begin
|
begin
|
||||||
ByteBuff := IToBytes(Integer'Value(CharBuff));
|
Ada.Integer_Text_IO.Get(ValI);
|
||||||
|
ByteBuff := IToBytes(ValI);
|
||||||
WriteMem(Memory, Pointer, ByteBuff, True);
|
WriteMem(Memory, Pointer, ByteBuff, True);
|
||||||
end;
|
end;
|
||||||
elsif InputTypeFlag = LEFloat then
|
elsif InputTypeFlag = LEFloat then
|
||||||
declare
|
declare
|
||||||
ByteBuff : ByteArr (1 .. 4);
|
ByteBuff : ByteArr (1 .. 4);
|
||||||
|
ValF : Float := 0.0;
|
||||||
begin
|
begin
|
||||||
ByteBuff := FToBytes(Float'Value(CharBuff));
|
Ada.Float_Text_IO.Get(ValF);
|
||||||
|
ByteBuff := FToBytes(ValF);
|
||||||
WriteMem(Memory, Pointer, ByteBuff, True);
|
WriteMem(Memory, Pointer, ByteBuff, True);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
|
@ -213,11 +213,13 @@ begin
|
|||||||
when 3 => InputTypeFlag := LEFloat;
|
when 3 => InputTypeFlag := LEFloat;
|
||||||
when others => InputTypeFlag := LEString;
|
when others => InputTypeFlag := LEString;
|
||||||
end case;
|
end case;
|
||||||
when 65535 => goto THE_END; -- exit opcode
|
when 65535 =>
|
||||||
|
goto THE_END; -- exit opcode
|
||||||
when others => null;
|
when others => null;
|
||||||
end case;
|
end case;
|
||||||
|
|
||||||
PC := PC + 16; -- increment program counter to next instruction
|
PC := PC + 16; -- increment program counter to next instruction
|
||||||
|
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user