2 ms·
Yes, very old Pascal, not even TurboPascal! I started with Apple ][ UCSD Pascal, but that program was for HP3000 Pascal, which might be even older. There was a
by DonHopkins 6y ago
Yes, very old Pascal, not even TurboPascal! I started with Apple ][ UCSD Pascal, but that program was for HP3000 Pascal, which might be even older.
There was a trick for doing PEEK and POKE in Apple Pascal, using a union that contained a pointer to some type you could dereference to read and write, and also an integer so you could set the pointer. I had the hardest time understanding it, and just could not get my head around the "record case boolean of", but I just typed in the magic code with a bunch of weird ^'s and it worked somehow.
You can use type punning tricks with "union" to implement arbitrary unsafe pointer arithmetic in Pascal, since it lets you convert between pointers and integers.
https://en.wikipedia.org/wiki/Type_punning#Pascal https://en.wikipedia.org/wiki/Type_punning#Pascal
Here's an article about that trick, in German (which makes it sound even cooler):
https://www.robert-tolksdorf.de/book/Tolksdorf-UCSD-Pascal-CC-BY-NC-ND-4.0.pdf https://www.robert-tolksdorf.de/book/Tolksdorf-UCSD-Pascal-C...
p. 63: 3.1 "PEEK" und "POKE" auch in Pascal
[...]
type byte = 0..255
spchrinhalt = packed array [0..0] of byte;
spchrstelle = record case boolean of
true: (adresse:integer); ( Zieger )
false: (inhalt:^spchrinhalt) ( Inhalt )
end;
procedure poke(adresse:integer; inhalt:byte);
var dummy:spchrstelle;
begin
dummy.adresse := adresse;
dummy.inhalt^[0] := inhalt;
end;
function peek(adresse:integer): byte;
var dummy:spchrstelle;
begin
dummy.adresse := adresse;
peek := dummy.inhalt^[0];
end;