commit 465e0d1a34e5959e094d8aa2dc3845f93a920e77 Author: Kyle Isom Date: Tue Oct 3 01:54:45 2023 -0700 initial import diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..933337b --- /dev/null +++ b/Makefile @@ -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 diff --git a/binary.inc b/binary.inc new file mode 100644 index 0000000..5b88e02 --- /dev/null +++ b/binary.inc @@ -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; diff --git a/hello.pas b/hello.pas new file mode 100644 index 0000000..0e1aaf3 --- /dev/null +++ b/hello.pas @@ -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. diff --git a/test.pas b/test.pas new file mode 100644 index 0000000..e64b557 --- /dev/null +++ b/test.pas @@ -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. diff --git a/undump.pas b/undump.pas new file mode 100644 index 0000000..576f81b --- /dev/null +++ b/undump.pas @@ -0,0 +1,5 @@ +program undump; +{ + undump is a program to take the output from dump + and put it into binary format. +}