home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
UTILITYS
/
PUDD.ARC
/
TURHACK2.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-08-11
|
10KB
|
230 lines
{*************************************************************************
* procedures for Turbo Pascal and CP/M (on the Z-80) *
* *
* Notes: While Turbo provides some nice tools which allow the *
* programmer to get into his machine and twist it's guts inside *
* out (like PortArray, absolute memory access, etc) some of these *
* features need supporting tools to be useful. The following *
* tools have been useful for hard core hacking. Particularly *
* for debugging inline code. *
* If you have similar tools why not add them to the file, *
* update the version # and post it at..... *
* The Power Board (608) 251-3494 *
* *
* version 1.0n 6/85 *
* version 1.1 7/85 added a few more procedures *
* *
* SetBitW: sets the nth bit in a word *
* SetBitB: sets the nth bit in a byte *
* ClrBitW: clears the nth bit in a word *
* ClrBitB: clears the nth bit in a byte *
* HexEqu: returns the Hex equivelent of a word in a string *
* HexByte: returns the Hex equivelent of a byte *
* ReadByte: returns the bit representation of a byte in a string *
* *
*************************************************************************}
{**************************************************************************
* setbitW(bit, word) - set bit #bit in word
*
* input -> (char), (integer)
*
* Results -> The 'bit'th bit in `word` is set. Bits are numbered as laid
* out below:
* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
*************************************************************************}
procedure setbitW(bit : integer; var word : integer);
var tmp : integer;
i : integer;
temp: integer;
begin
temp := word;
tmp := 1;
for i := 1 to bit do
tmp := tmp * 2;
inline( $2A/temp/ {ld HL,(nn) ;get the word }
$ED/$5B/tmp/ {ld DE,(nn) ;get the mask }
$7C/ {ld A,H ;load low byte }
$B2/ {or D ; mask }
$67/ {ld H,A ;save }
$7D/ {ld A,L ;load high byte }
$B3/ {or E ; mask }
$6F/ {ld L,A ;save }
$22/temp); {ld (nn),HL ;restore }
word := temp;
end; { setbit }
{**************************************************************************
* setbitB(bit, byte) - set bit #bit in byte
*
* input -> (char), (integer)
*
* Results -> The 'bit'th bit in `byte` is set. Bits are numbered as laid
* out below:
* 7 6 5 4 3 2 1 0
*************************************************************************}
procedure setbitB(bit : integer; var byte : char);
var tmp : integer;
i : integer;
temp :char;
begin
temp := byte;
tmp := 1;
for i := 1 to bit do
tmp := tmp * 2;
inline($3A/temp/ { ld A,(nn) ;get the byte }
$21/tmp/ { ld HL,nn ;get the mask adr }
$56/ { ld D,(HL) ;get the mask }
$B2/ { or D ;use it }
$32/temp); { ld (nn),A :put it back }
byte := temp;
end; { setbitB }
{**************************************************************************
* clrbitW(bit, word) - set bit #bit in word
*
* input -> (char), (integer)
*
* Results -> The 'bit'th bit in `word` is set. Bits are numbered as laid
* out below:
* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
*************************************************************************}
procedure clrbitW(bit : integer; var word : integer);
var tmp : integer;
i : integer;
temp: integer;
begin
temp := word;
tmp := 1;
for i := 1 to bit do
tmp := tmp * 2;
inline( $2A/temp/ {ld HL,(nn) ;get the word }
$ED/$5B/tmp/ {ld DE,(nn) ;get the mask }
$7A/ {ld A,D ;load low mask }
$2F/ {cpl ;compliment }
$A4/ {and H ;mask from word }
$67/ {ld H,A ;put it back }
$7B/ {ld A,E ;load high mask }
$2F/ {cpl ;compliment }
$A5/ {and L :mask from word }
$6F/ {ld L,A ;save }
$22/temp); {ld (nn),HL ;restore }
word := temp;
end; { clrbitW }
{**************************************************************************
* clrbitB(bit, byte) - clear bit #bit in byte
*
* input -> (char), (integer)
*
* Results -> The 'bit'th bit in `byte` is cleared. Bits are numbered as
* laid out below:
* 7 6 5 4 3 2 1 0
*************************************************************************}
procedure clrbitB(bit : integer; var byte : char);
var tmp : integer;
i : integer;
temp :char;
begin
temp := byte;
tmp := 1;
for i := 1 to bit do
tmp := tmp * 2;
inline($21/tmp/ { ld HL,nn ;get the mask adr }
$7E/ { ld A,(HL) ;get the mask }
$2F/ { cpl ;compliment }
$21/temp/ { ld HL,nn ;get the byte adr }
$56/ { ld D,(HL) ;get the byte }
$A2/ { and D ;mask it }
$32/temp); { ld (nn),A :put it back }
byte := temp;
end; { clrbitB }
{**************************************************************************}
{ HexEqu will return the hex equivelent of a two byte word in a four byte }
{ string. The nibbles are refered to as .... }
{ byte 1 byte 2 }
{ 0000 0000 0000 0000 }
{ nibble 1 2 3 4 }
{type AddH = string[4]; ........................this is needed above }
{**************************************************************************}
procedure HexEqu(typAddr:integer;var HexAddr:AddH);
var j :integer;
begin
j := hi(typAddr) div 16 + 48;
if j > 57 then j := j + 7;
insert(chr(j),HexAddr,1); { set nibble 1 }
j := hi(typAddr) mod 16 + 48;
if j > 57 then j := j + 7;
insert(chr(j),HexAddr,2); { set nibble 2 }
j := lo(typAddr) div 16 + 48;
if j > 57 then j := j + 7;
insert(chr(j),HexAddr,3); { set nibble 3 }
j := lo(typAddr) mod 16 + 48;
if j > 57 then j := j + 7;
insert(chr(j),HexAddr,4); { set nibble 4 }
end;
{**************************************************************************}
{**************************************************************************}
{* ReadByte will return a charactor string with the correct a series *}
{* 1's and 0's in an 8 charactor string to represent the actual bits *}
{* in the byte. *}
{**************************************************************************}
procedure ReadByte(sample:byte; var Bitlist:Blist);
var ListLocal :Blist;
ByteLocal :byte;
begin
ListLocal := '00000000';
ByteLocal := sample;
inline($3A/ByteLocal/ { LD A,(ByteLocal) }
$21/ListLocal/ { LD HL,ListLocal }
$06/$30/ { LD B,0 }
$0E/$31/ { LD C,1 }
$16/$08/ { LD D,8 }
$23/ { INC HL :top }
$CB/$47/ { BIT 1,A }
$20/$03/ { JR NZ,one }
$70/ { LD (HL),B }
$18/$01/ { JR done }
$71/ { LD (HL),C :one }
$CB/$1F/ { RR A :done }
$15/ { DEC D }
$20/$F2 ); { JR NZ,top }
Bitlist := ListLocal;
end; {........................ ......ReadByte}
{**************************************************************************}
{**************************************************************************}
{ HexByte will return the hex equivelent of a byte in a four byte }
{ string. The nibbles are refered to as .... }
{ byte }
{ 0000 0000 }
{ nibble 1 2 }
procedure HexByte(HByte:char;var HexVal:HexString);
var j,i :integer;
k :char;
begin
j := 0;
HexVal := ' ';
k := HByte; {make it local to avoid problems }
inline($ED/$6B/k/ {ld HL,(nn) get the low part }
$ED/$63/j); {ld (nn),HL put it in var }
i := lo(j) div 16 + 48;
if i > 57 then i := i + 7;
insert(chr(i),HexVal,1); { set nibble 3 }
i := lo(j) mod 16 + 48;
if i > 57 then i := i + 7;
insert(chr(i),HexVal,2); { set nibble 4 }
end;