initial import
This commit is contained in:
commit
465e0d1a34
|
@ -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
|
|
@ -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;
|
|
@ -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.
|
|
@ -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.
|
|
@ -0,0 +1,5 @@
|
|||
program undump;
|
||||
{
|
||||
undump is a program to take the output from dump
|
||||
and put it into binary format.
|
||||
}
|
Loading…
Reference in New Issue