Firstly I must apologize. I am still having problems with the autodownloader.
I am trying to resolve the issue with Gunter and Rolf.
I have started to implement my first extension to the compiler. It is attached for those who want to try it.
It is my first extension so there are bound to be issues, so any feedback is appreciated.
The extension allows record functions and procedures. This example shows how it it intended to work.
Regards
I am trying to resolve the issue with Gunter and Rolf.
I have started to implement my first extension to the compiler. It is attached for those who want to try it.
It is my first extension so there are bound to be issues, so any feedback is appreciated.
The extension allows record functions and procedures. This example shows how it it intended to work.
Code
Unit FIFO;
{
Implements a FIFO buffer, such as used by Serial comms
}
interface
// global part
{ $W+} // enable/disable warnings for this unit
uses ;
{--------------------------------------------------------------}
{ Const Declarations }
const
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
tFIFOBuff = record
Buff : pointer to byte;
Size : byte;
addPtr : byte;
rmvPtr : byte;
function AddByte( const pByte : byte ) : boolean;
function RemoveByte( var pByte : byte ) : boolean;
procedure AssignBuffer( const pBuff : pointer to byte; const pSize : byte );
function Full : boolean;
function Empty : boolean;
end;
{--------------------------------------------------------------}
{ Var Declarations }
var
{--------------------------------------------------------------}
{ functions }
implementation
// local part
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
const
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
{--------------------------------------------------------------}
{ functions }
function NextByte( const iVal : byte; pLimit : byte ): byte;
var
Result : byte;
begin
Result := iVal + 1;
if Result = pLimit then
Result := 0;
endif;
return( Result );
end;
function tFIFOBuff.AddByte( const pByte : byte ) : boolean;
var
iNewPtr : byte;
iPtr : pointer to byte;
begin
if Size = 0 then // not initialized
return( FALSE );
else
iNewPtr := NextByte( addPtr, Size );
if iNewPtr = rmvPtr then
return( FALSE ); // buffer full
else
iPtr :=buff+word(addPtr);
iPtr^ := pByte;
addPtr := iNewPtr;
endif;
endif;
end;
function tFIFOBuff.RemoveByte( var pByte : byte ) : boolean;
var
iPtr : pointer to byte;
begin
if Size = 0 then // not initialized
return( FALSE );
else
if rmvPtr = addPtr then // empty
return( FALSE ); // buffer full
else
iPtr := buff+word(addPtr);
pByte := iPtr^;
rmvPtr := NextByte( rmvPtr, Size );
endif;
endif;
end;
function tFIFOBuff.Full : boolean;
var
iNewPtr : byte;
begin
if Size = 0 then // not initialized
return( TRUE );
else
iNewPtr := NextByte( addPtr, Size );
return( iNewPtr = rmvPtr );
endif;
end;
function tFIFOBuff.Empty : boolean;
begin
return( rmvPtr = addPtr );
end;
procedure tFIFOBuff.AssignBuffer( const pBuff : pointer to byte; const pSize : byte );
begin
Buff := pBuff;
Size := pSize;
addPtr := 0;
rmvPtr := 0;
end;
procedure Test;
const
cSize : byte = 10;
var
iBuff : array[ 0..cSize - 1] of byte;
jBuff[ @iBuff ] : byte;
iFIFO : tFIFOBuff;
iVal : byte;
begin
iFIFO.AssignBuffer( @jBuff, cSize );
iFIFO.AddByte( 7 );
iFIFO.RemoveByte( iVal );
end;
initialization
// at StartUp
// finalization // optional
// at System_ShutDown
end FIFO.
{
Implements a FIFO buffer, such as used by Serial comms
}
interface
// global part
{ $W+} // enable/disable warnings for this unit
uses ;
{--------------------------------------------------------------}
{ Const Declarations }
const
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
tFIFOBuff = record
Buff : pointer to byte;
Size : byte;
addPtr : byte;
rmvPtr : byte;
function AddByte( const pByte : byte ) : boolean;
function RemoveByte( var pByte : byte ) : boolean;
procedure AssignBuffer( const pBuff : pointer to byte; const pSize : byte );
function Full : boolean;
function Empty : boolean;
end;
{--------------------------------------------------------------}
{ Var Declarations }
var
{--------------------------------------------------------------}
{ functions }
implementation
// local part
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
const
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
{--------------------------------------------------------------}
{ functions }
function NextByte( const iVal : byte; pLimit : byte ): byte;
var
Result : byte;
begin
Result := iVal + 1;
if Result = pLimit then
Result := 0;
endif;
return( Result );
end;
function tFIFOBuff.AddByte( const pByte : byte ) : boolean;
var
iNewPtr : byte;
iPtr : pointer to byte;
begin
if Size = 0 then // not initialized
return( FALSE );
else
iNewPtr := NextByte( addPtr, Size );
if iNewPtr = rmvPtr then
return( FALSE ); // buffer full
else
iPtr :=buff+word(addPtr);
iPtr^ := pByte;
addPtr := iNewPtr;
endif;
endif;
end;
function tFIFOBuff.RemoveByte( var pByte : byte ) : boolean;
var
iPtr : pointer to byte;
begin
if Size = 0 then // not initialized
return( FALSE );
else
if rmvPtr = addPtr then // empty
return( FALSE ); // buffer full
else
iPtr := buff+word(addPtr);
pByte := iPtr^;
rmvPtr := NextByte( rmvPtr, Size );
endif;
endif;
end;
function tFIFOBuff.Full : boolean;
var
iNewPtr : byte;
begin
if Size = 0 then // not initialized
return( TRUE );
else
iNewPtr := NextByte( addPtr, Size );
return( iNewPtr = rmvPtr );
endif;
end;
function tFIFOBuff.Empty : boolean;
begin
return( rmvPtr = addPtr );
end;
procedure tFIFOBuff.AssignBuffer( const pBuff : pointer to byte; const pSize : byte );
begin
Buff := pBuff;
Size := pSize;
addPtr := 0;
rmvPtr := 0;
end;
procedure Test;
const
cSize : byte = 10;
var
iBuff : array[ 0..cSize - 1] of byte;
jBuff[ @iBuff ] : byte;
iFIFO : tFIFOBuff;
iVal : byte;
begin
iFIFO.AssignBuffer( @jBuff, cSize );
iFIFO.AddByte( 7 );
iFIFO.RemoveByte( iVal );
end;
initialization
// at StartUp
// finalization // optional
// at System_ShutDown
end FIFO.
Regards