unit b_utils

Common Utils

author: bocianu bocianu@gmail.com


Set of useful procedures to simplify common tasks in Atari 8-bit programming.
This library is a part of 'blibs' - set of custom Mad-Pascal libraries.
https://gitlab.com/bocianu/blibs

Types:

name:type:description:
TdateTimerecord
  • year: word;
  • month: byte;
  • day: byte; // day of month
  • hour: byte;
  • minute: byte;
  • second: byte;
  • dow: byte; // day of week

end;
Record type used to store date and time.

Interface:

name:description:
CountBits

function CountBits(b: byte):byte;assembler;


Counts number of ones in bits of any byte value.
    parameters:
  • b - byte value to count bits in
  • returns:
  • (byte) - number fo bits turned on
WriteLnCentered

procedure WriteLnCentered(s: string);


Outputs string aligned to center of screen width.
Length of string should not exceed screen width (40).
    parameters:
  • s - string to write
WriteRightAligned

procedure WriteRightAligned(w: byte; s: TString);


Outputs string aligned to right of provided width.
Length of string should not exceed provided width of field.
    parameters:
  • w - width of field to align
  • s - string to write
NullTermToString

function NullTermToString(ptr: word): string;


Parses null terminated string into regular pascal string variable.
    parameters:
  • ptr (word) - address in memory of null terminated string
  • returns:
  • (string) - regular pascal string type variable
FFTermToString

function FFTermToString(ptr: word): string;


Parses string terminated with $FF into regular pascal string variable.
    parameters:
  • ptr (word) - address in memory of null terminated string
  • returns:
  • (string) - regular pascal string type variable
ExpandRLE

procedure ExpandRLE(src: word; dest: word);


Expands RLE compressed data from source memory location and writes expanded data at destination memory address.
    parameters:
  • src (word) - source address of compressed data
  • dest (word) - destination address where data is expanded
ExpandLZ4

procedure ExpandLZ4(source: word; dest: word):assembler;


Expands LZ4 compressed data from source memory location and writes expanded data at destination memory address.
Based on xxl & fox routine from here: https://xxl.atari.pl/lz4-decompressor/
    parameters:
  • src (word) - source address of compressed data
  • dest (word) - destination address where data is expanded
UnixToDate

procedure UnixToDate(ux: cardinal; var date: TDateTime);


Converts unix timestamp to proper date, represented as an record of TDateTime type.
    parameters:
  • ux (cardinal) - unix timestamp
  • date (TDateTime) - record where the result of conversion is stored
Hour24to12

function Hour24to12(hour: byte):byte;


Converts 24 hour clock indication into to 12 hour
    parameters:
  • hour (byte) - hour (0-23)
  • returns:
  • (byte) - hour(0-12)
HexChar2Dec

function HexChar2Dec(c:char):byte;


Converts hex char into proper value in decimal.
    parameters:
  • c (char) - hex char (0-9,a-f)
  • returns:
  • (byte) - decimal value (0-15), on error (invalid char) returns 255