Does Binary literal in Turbo Pascal 3.01A for CP/M-80

40 Views Asked by At

I'm currently working on programming the RS-232 serial port on an old computer running a CP/M operating system. The compiler and linker I'm using are Turbo Pascal 3.01A for CP/M-80, and the processor is a Zilog Z80.

Below is a snippet of the code where I should set registers in binary instead of hexadecimal:

procedure SetRegister(reg, value: Byte);
begin
  Port[CTRL_REG] := reg;     { Set pointer to the register }
  Port[CTRL_REG] := value;   { Write the value to the register }
end;

begin
  SetRegister(3, %01110001);
  {instead of SetRegister(3, $71);}
end.

Despite my efforts by consulting the manual, I couldn't find any information on how to achieve definition of binary literal. The Turbo Pascal version I'm using doesn't seem to support the use of a binary literal prefix (%). It's possible that the language is too outdated. Or am I missing something?

I find it much more readable when using binary literals, particularly since certain registers require setting specific flags for different operations or commands. I'm curious to know if this version supports binary literals in any way, or if there's another clever way, perhaps using macros, to achieve this without generating unnecessary additional executable machine code or operands.

1

There are 1 best solutions below

0
Ted Lyngmo On

No, binary literals was not included in Turbo Pascal. In fact, they were added as late as in the descendant Delphi 11 (released in 2021).

[...] if there's another clever way, perhaps using macros, to achieve this without generating unnecessary additional executable machine code

I'm not sure how good Turbo Pascal is at optimizing away function calls and operations when all the operands are known at compile time so you'll have to examine the generated code to see if this generates any machine code or a simple constant.

Helper function:

function Bin(b7, b6, b5, b4, b3, b2, b1, b0: Byte): Byte;
begin
    Bin := (b7 << 7)
        or (b6 << 6)
        or (b5 << 5)
        or (b4 << 4)
        or (b3 << 3)
        or (b2 << 2)
        or (b1 << 1)
        or (b0 << 0);
end;

begin
  SetRegister(3, Bin(0,1,1,1,0,0,0,1));
end.

I'm also not sure how to make macros in Turbo Pascal, but if you know that, you should be able to turn the above into a macro.