initial import

This commit is contained in:
Kyle Isom 2023-10-03 01:54:45 -07:00
commit 465e0d1a34
5 changed files with 103 additions and 0 deletions

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
TARGETS := hello test
LIBS := binary.inc
FPC_FLAGS := -g
FPC := fpc $(FPC_FLAGS)
.PHONY: all
all: $(TARGETS)
.PHONY: clean
clean:
rm -f *.o $(TARGETS)
hello: hello.pas
$(FPC) $@.pas
test: test.pas $(LIBS)
$(FPC) $@.pas

52
binary.inc Normal file
View File

@ -0,0 +1,52 @@
function ValidHexDigit(bval: Byte): Boolean;
var
IsValid : Boolean = False;
begin
if ((bval >= $30) and (bval <= $39)) then
IsValid := True;
if ((bval >= $41) and (bval <= $46)) then
IsValid := True;
if ((bval >= $61) and (bval <= $66)) then
IsValid := True;
ValidHexDigit := IsValid;
end;
function ReadDigit(bchr: Char): Byte;
var
bval : Byte = 0;
label
exitearly;
begin
bval := Byte(bchr);
if (not ValidHexDigit(bval)) then
begin
bval := 0;
goto exitearly;
end;
{Normalize downcase digits to upcase digits.}
if (bchr >= 'a') then
bval := bval xor $20;
{Perform the conversion.}
if (bchr >= 'A') then
bval := (bval - $41) + 10
else
bval := bval - $30;
exitearly:
ReadDigit := bval;
end;
function ReadByte(bstr : ByteString): Byte;
var
out : Byte = 0;
begin
out := ReadDigit(bstr[1]) shl 4;
out := out + ReadDigit(bstr[2]);
ReadByte := out;
end;

14
hello.pas Normal file
View File

@ -0,0 +1,14 @@
program hello;
procedure SayHello(name : String);
begin
Writeln('Hello, ', name);
end;
var
name : String[16];
begin
Write('What is your name? ');
Readln(name);
SayHello(name);
end.

15
test.pas Normal file
View File

@ -0,0 +1,15 @@
program test;
type
ByteString = String[2];
{$I 'binary.inc'}
var
bstr : String[2] = '41';
bval : Byte;
begin
bval := ReadByte(bstr);
Writeln('hello', Char(bval));
end.

5
undump.pas Normal file
View File

@ -0,0 +1,5 @@
program undump;
{
undump is a program to take the output from dump
and put it into binary format.
}