Author Topic: Two HiSoft Pascal' syntax questions  (Read 391 times)

0 Members and 1 Guest are viewing this topic.

Offline the graveborn

  • CPC464
  • **
  • Posts: 19
  • Country: gb
    • the graveborn
    • Awards
Two HiSoft Pascal' syntax questions
« on: 15:45, 27 August 21 »
Hey there, everybody; a long time has passed since I last asked a programming-related question, on this forum or anywhere else, but I've encountered two obstacles whilst trying to develop my latest program on and for the Amstrad CPC, and I'm uncertain if the obstacles are caused by me being ignorant or by the tools I'm using not being able to do what I'm asking of them, those tools being HiSoft Pascal for CP/M-80 and HiSoft Pascal Amstrad CPC464.

The first obstacle is that I've been unable to figure out the syntax for pointing a pointer-variable to a non-pointer-variable; in Pascal in Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition) the syntax would be…

Code: [Select]
program PointingTest( output );
var
  i : integer;
  pointer : ^integer;
begin
  i := 0;
  pointer := @i;
  writeln( 'Before: ', i:0, '.' );
  pointer^ := 1;
  writeln( 'After:  ', i:0, '.' )
end.

Example output:

Code: [Select]
Before: 0.
After:  1.

…but my every attempt to figure out the syntax in HiSoft Pascal' has been a failure; eg., using the above syntax, pointer := @i;, results in the error "12. Factor expected." when trying to compile it using HiSoft Pascal for CP/M-80.

The second obstacle is that I've no idea about the syntax for getting the address pointed to by a pointer-variable and assigning it to be the value of an INTEGER-variable, or the reverse, assigning the value of an INTEGER-variable to be the address pointed to by a pointer-variable; in C in Leonardo IDE 3.4.1 the syntax would be…

Code: [Select]
#include <stdio.h>

#define k_Limit 3

void main( void )
{
  int i = 0, array[ k_Limit ], *pointer;

  for( ; i < k_Limit; i ++ )
  {
    array[ i ] = i;
    pointer = array + i; /* Simple pointer arithmetic to calculate the address of the `i`th cell of the array `array`. */
    printf( "Address: %p.\n", pointer );
    printf( "Value:   %i.\n", *pointer );
    printf( "Value is correct: %s.\n", ( *pointer == i )?"yes":"no" );
    if( i + 1 < k_Limit )
      printf( "\n" );
  }
}

Example output:

Code: [Select]
Address: 0x00000676.
Value:   0.
Value is correct: yes.

Address: 0x00000678.
Value:   1.
Value is correct: yes.

Address: 0x0000067a.
Value:   2.
Value is correct: yes.
like
0
No reactions

Offline Bread80

  • CPC464
  • **
  • Posts: 19
  • Country: england
    • Bread80.com
    • Awards
Re: Two HiSoft Pascal' syntax questions
« Reply #1 on: 21:04, 27 August 21 »
I just had a scroll through the manual at http://www.primrosebank.net/computers/mtx/documents/HiSoftPascalManual.pdf and it looks like the @ operator isn't supported but there's an addr() function which does the same thing. Beyond that it might be down to peek() and poke() functions. Their examples for peek certainly make it look that way!
like
0
No reactions

Offline the graveborn

  • CPC464
  • **
  • Posts: 19
  • Country: gb
    • the graveborn
    • Awards
Re: Two HiSoft Pascal' syntax questions
« Reply #2 on: 12:14, 30 September 21 »
@Bread80 Thank you for your response..! I'd already read the manual, and so I already knew about the ADDR() function, and that function isn't useful in this situation as it has the "signature" ADDR( generic ) : INTEGER; and so attempting to use that function to point a pointer-variable to a non-pointer-variable – eg., pointer := ADDR( i ); – results in the error "10. Wrong type." (to be useful in this situation, that function would need to have the "signature" ADDR( generic ) : ^generic;). I don't know if it's what you meant when you suggested using the POKE() procedure and the PEEK() function, but I did figure out a workaround using ADDR() and POKE() – it is (I think) unnecessarily long, but it (seems to) work…

Code: [Select]
PROGRAM PointingTest;
VAR
 i, a1, a2 : INTEGER;
 pointer : ^INTEGER;
BEGIN
 i := 0;
 WRITELN( 'Before: ', i:0, '.' );
 a1 := ADDR( i );
 a2 := ADDR( pointer );
 POKE( a2, a1 );
 pointer^ := 1;
 WRITELN( 'After:  ', i:0, '.' )
END.

Example output:

Code: [Select]
Before: 0.
After:  1.
like
0
No reactions

Offline Singaja

  • CPC6128
  • ****
  • Posts: 174
  • Country: pl
    • Awards
Re: Two HiSoft Pascal' syntax questions
« Reply #3 on: 23:36, 13 October 21 »
My Pascal is a little rusty and I don't know what HiSoft syntax allows, but I got this in some online compiler:
Code: [Select]

program PointingTest( output );
type Rec = record
  case integer of
    0: (
        value: integer;
      );
    1: ( pointer: ^integer;
    )
end;
var
  i,y : Rec;
begin
  i.value := 0;
  writeln( 'Before: ', i.value:0, '.' );
  y.value := 1;
  i.pointer := y.pointer;
  writeln( 'After: ', i.value:0, '.' )
end.
outputs

Code: [Select]
Before: 0.
After: 1.
Not sure if that's of any use.
« Last Edit: 12:01, 14 October 21 by Singaja »
like
0
No reactions