Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2021-03

SinclairQL (M68K) Port

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Norman Dunbar

Good Afternoon All,

Back in November, we had a visit on our Sinclair QL forum (qlforum.co.uk) from ChainQ informing us that he had created a Sinclair QL version of Free Pascal for M68K. Quite a number of people showed interest, including myself -- and I've not done any Pascal since college in the early 1980s.

I've built a cross compiler, based on version 3.3.1, and tested a couple of very simple examples with no problems.

I've now started messing around in the source code to try get the port up to requirements as per the docs on what should be in the system unit. So far, I have managed to implement and test the "Erase" function, which works fine.

Sadly, when testing, I noticed a problem that causes run time errors 103, and possibly 102 -- sorry I'm a bit vague I'm not at my QL right now. This occurs when any of the following are attempted:

writeln(aFile, 'Some text');
reset(aFile);

writeln('Some text') works fine to the console, just not to a file as in "VAR aFile : Text;" for example.

There may be other problem areas. I'd like to try and fix these but I'm completely unable to find the location of the "writeln" or "reset" functions in the source code. I have grepped and Googled to no avail I'm afraid.

Could someone please point me in the right direction. Thanks.

Also, is there any documentation for anyone coming on to the project which explains the layout of the code, where to find "stuff" what needs doing and such like? Sort of like a "Beginners' guide to developing Free Pascal and/or the RTL" or similar?

It would be helpful to beginners like me, trying to look around and fix/implement stuff. I've been all over the Wiki and found this page, https://wiki.freepascal.org/FPC_development, but it's not what I was looking for although there are some interesting articles on the RTL pages.

Many thanks for any information.

Cheers,
Norm.

Norman Dunbar Dunbar IT Consultants Ltd Registered address: 27a Lidget Hill Pudsey West Yorkshire United Kingdom LS28 7LG Company Number: 05132767

Reply by email

Karoly Balogh
to Norman Dunbar

Hi,

Norman Dunbar wrote 5 lines
Back in November, we had a visit on our Sinclair QL forum (qlforum.co.uk) from ChainQ informing us that he had created a Sinclair QL version of Free Pascal for M68K. Quite a number of people showed interest, including myself -- and I've not done any Pascal since college in the early 1980s.

Yeah, the "bad" influence of #QLvember... :) Sorry, meanwhile I completely "context switched" away from the QL port, as there was plenty of other stuff of my plate. It was on my ToDo to get back to it, but actually, I prefer indeed if the QL community sends patches... I was just not going to the QL forum lately, there's always one too many retro platforms to care for. :| Sorry about it!

Show quoted text 6 lines
Sadly, when testing, I noticed a problem that causes run time errors 103, and possibly 102 -- sorry I'm a bit vague I'm not at my QL right now. This occurs when any of the following are attempted: writeln(aFile, 'Some text'); reset(aFile);

What are you trying to do here? This isn't valid Pascal file handling code. You have to Assign() a file first, then Reset(), Rewrite() or Append(), depending on what you want (read or write), then Write/Read/Seek functions should work on the opened file handle. You need to Close() afterwards.

writeln('Some text') works fine to the console, just not to a file as in "VAR aFile : Text;" for example.

The RTL on init will open stdin/stdout for you on start, so simple I/O works on the console, so your writeln() will succeed, regardless of you trying to reopen the console afterwards.

There may be other problem areas. I'd like to try and fix these but I'm completely unable to find the location of the "writeln" or "reset" functions in the source code. I have grepped and Googled to no avail I'm afraid.

Write()/Writeln() and WriteStr() are special functions, which the compiler handles directly, and breaks them down into a series of individual calls, depending on the type of the parameters in the parameter list printed. It's required, because Write(), Writeln() and WriteStr() are basically what you call in C terms a "varargs" function, which is otherwise not part of Pascal language definition. So you won't find it in the RTL code, and you probably don't need to touch that code anyway, as everything just calls do_write() in the end, which is in rtl/sinclairql/sysfile.inc.

If you want to see what happens in the background, for the individual functions, search for "fpc_write_" in rtl/inc/, you'll see that these are declared as "compilerproc", which marks the special nature of these calls. If you know m68k assembly, You can easily identify which functions are called directly, if you generate assembly code with the -al parameter, while compiling. Then you can check directly what the compiler does with your code, and which functions it calls (even if name mangling obscures them a bit, but it's still possible to understand better what is going on then). But as I said, you won't need to touch any of these.

The Reset() function's implementation is in rtl/inc/file.inc, along with Rewrite(). But you most likely don't have to touch these either, because they internally wrap to do_open(), which is in rtl/sinclairql/sysfile.inc. This might need to be extended to handle various file open modes (read, write, overwrite, append, etc) better. Also, integrating console handling in there might have its own quirks.

Also, is there any documentation for anyone coming on to the project which explains the layout of the code, where to find "stuff" what needs doing and such like? Sort of like a "Beginners' guide to developing Free Pascal and/or the RTL" or similar?

Probably there is something, but it's quite simple in principle, even if the implementation is a bit more the RTL
implementation tries to keep the interface and some of the logic platform independent. This code is in rtl/inc/. And it wraps to system-specific functions internally, which are already in the sinclairql RTL, just mostly weren't implemented. Basically any do_<something>() functions which you see in there.

Additionally, when you get to the implementation of sysutils and classes unit, the platform independent parts will be in rtl/objpas/, but the same principle applies.

It would be helpful to beginners like me, trying to look around and fix/implement stuff. I've been all over the Wiki and found this page, https://wiki.freepascal.org/FPC_development, but it's not what I was looking for although there are some interesting articles on the RTL pages.

Yeah, I think code is the best documentation here, as it's changing quite fast, although some overview is probably there and it wouldn't hurt to make it more easy to find that overview it seems. :)

Cheers,

Charlie (Chain-Q in the QL forum)

Reply by email

Tomas Hajny
to Karoly Balogh
Karoly Balogh wrote
On Sat, 20 Mar 2021, Norman Dunbar via fpc-pascal wrote:

Hi,

.
.

Show quoted text 10 lines
> It would be helpful to beginners like me, trying to look around and > fix/implement stuff. I've been all over the Wiki and found this page, > https://wiki.freepascal.org/FPC_development, but it's not what I was > looking for although there are some interesting articles on the RTL > pages. Yeah, I think code is the best documentation here, as it's changing quite fast, although some overview is probably there and it wouldn't hurt to make it more easy to find that overview it seems. :)

The page https://wiki.freepascal.org/System_unit_structure (referred to from the 'RTL development articles' appearing on the 'FPC development' page mentioned above is the one supposed to help in this case, but it is very incomplete, unfortunately. :-( I'll try to add at least some additional bits.

Tomas

Reply by email

Norman Dunbar
to Karoly Balogh: Yeah, the "bad" influence of #QLvember... :) Sorry, meanwhile I completely "context…

Morning Charlie,

Karoly Balogh wrote
...It was on my ToDo to get back to it, but actually, I prefer indeed if the QL community sends patches...

Ok, no worries. I can "svn diff" if that's what you would prefer? Where should I send them, when I'm ready please?

I was just not going to the QL forum lately, there's always one too many retro platforms to care for. :| Sorry about it!

No problem.

What are you trying to do here? This isn't valid Pascal file handling code. ....

Yes, I know. Sorry, I could have explained better. This is the file I was testing:

{ Program to demonstrate the Erase function. }

Var F : Text;
begin
   Assign(F,'ram1_test.txt');
   Rewrite(F);
   Writeln('The file, "ram1_test.txt" will be deleted.');
   Writeln(F,'Try and find this when I''m finished !');
   Close(F);
   Erase(F);
end.

In the end, the only way I could get it to actually delete the test file, on device ram1_, was:

Var F : Text;
begin
   Assign(F,'ram1_test.txt');
   Writeln('The file, "ram1_test.txt" will be deleted.');
   Erase(F);
end.
The RTL on init will open stdin/stdout for you on start, so simple I/O works on the console, so your writeln() will succeed, regardless of you trying to reopen the console afterwards.

Hmm. I wasn't trying to reopen the console, the line in the test program that barfed was this one:

   Writeln(F,'Try and find this when I''m finished !');

I have a minimum test harness for it at the moment that I'm attempting to sort out.

Var F : Text;
begin
   Assign(F,'ram1_test.txt');
   Rewrite(F);
   Writeln(F,'Try and find this when I''m finished !');
   Close(F);
end.

I've tested with just the assign and rewrite, seems to have had no effect - the output file, which has some text in it, remained untouched. Adding in the writeln call causes runtime error 103. Which I believe is "file not open".

Write()/Writeln() and WriteStr() are special functions, which the compiler handles directly, and breaks them down into a series of individual calls, depending on the type of the parameters in the parameter list printed.

Understood, thanks.

you probably don't need to touch that code anyway, as everything just calls do_write() in the end, which is in rtl/sinclairql/sysfile.inc.

Thanks, that's where I'll start looking for problems.

If you know m68k assembly, You can easily identify which functions are called directly, if you generate assembly code with the -al parameter, while compiling.

Excellent, I'm reasonably au-fait with M68K assembly. (Famous last words!)

Show quoted text 8 lines
Then you can check directly what the compiler does with your code, and which functions it calls (even if name mangling obscures them a bit, but it's still possible to understand better what is going on then). But as I said, you won't need to touch any of these. The Reset() function's implementation is in rtl/inc/file.inc, along with Rewrite(). But you most likely don't have to touch these either, because they internally wrap to do_open(), which is in rtl/sinclairql/sysfile.inc.

Ok, I'll have a look at those as well, just in case.

This might need to be extended to handle various file open modes (read, write, overwrite, append, etc) better. Also, integrating console handling in there might have its own quirks.

Probably not. The QL treats the console as a text file and pretty much anything goes, tabs, positioning etc.

... This code is in rtl/inc/. And it wraps to system-specific functions internally, which are already in the sinclairql RTL, just mostly weren't implemented. Basically any do_<something>() functions which you see in there.

Aha! Just what I was looking for. I knew this stuff had to be system specific.

...

Many thanks indeed, I'll see what I can come up with.

Cheers,
Norm.

Norman Dunbar Dunbar IT Consultants Ltd Registered address: 27a Lidget Hill Pudsey West Yorkshire United Kingdom LS28 7LG Company Number: 05132767

Reply by email

Norman Dunbar
to Tomas Hajny: . . The page https://wiki.freepascal.org/System_unit_structure (referred to from the 'RTL…

Hi Tomas,

Tomas Hajny wrote 5 lines
The page https://wiki.freepascal.org/System_unit_structure (referred to from the 'RTL development articles' appearing on the 'FPC development' page mentioned above is the one supposed to help in this case, but it is very incomplete, unfortunately. :-( I'll try to add at least some additional bits.

I've seen that page, thanks. As you say, it's a wee bit sparse, but it was helpful all the same.

Cheers,
Norm.

Norman Dunbar Dunbar IT Consultants Ltd Registered address: 27a Lidget Hill Pudsey West Yorkshire United Kingdom LS28 7LG Company Number: 05132767

Reply by email

Norman Dunbar
to Norman Dunbar: Ok, no worries. I can "svn diff" if that's what you would prefer? Where should I send…

Replying to self here...

Norman Dunbar wrote 16 lines
I have a minimum test harness for it at the moment that I'm attempting to sort out. Var F : Text; begin   Assign(F,'ram1_test.txt');   Rewrite(F);   Writeln(F,'Try and find this when I''m finished !');   Close(F); end. I've tested with just the assign and rewrite, seems to have had no effect - the output file, which has some text in it, remained untouched. Adding in the writeln call causes runtime error 103. Which I believe is "file not open".

Ok, I've found and fixed that problem. It was related to this FIXME left in the code:

{ rewrite (create a new file) }
{ FIX ME: this will just create a new file, actual overwriting seems to be a more complex endeavor... }

   if (flags and $1000)0 then openMode:=Q_OPEN_NEW;
   res:=io_open(p,openMode);

It was a simple change, Use Q_OPEN_OVER instead of Q_OPEN_NEW as the latter barfs with an "already exists" error if the file is there. The Q_OPEN_OVER will overwrite any existing file or create a new file, as required.

My testing of rewrite is now finished and working. So far anyway!

Cheers,
Norm.

Norman Dunbar Dunbar IT Consultants Ltd Registered address: 27a Lidget Hill Pudsey West Yorkshire United Kingdom LS28 7LG Company Number: 05132767

Reply by email

Tomas Hajny
Norman Dunbar wrote
On 21/03/2021 12:07, Tomas Hajny via fpc-pascal wrote:

Hi Norman,

Show quoted text 8 lines
> The page https://wiki.freepascal.org/System_unit_structure (referred > to from the 'RTL development articles' appearing on the 'FPC > development' page mentioned above is the one supposed to help > in this case, but it is very incomplete, unfortunately. :-( I'll try > to add at least some additional bits. I've seen that page, thanks. As you say, it's a wee bit sparse, but it was helpful all the same.

In the meantime, I managed to extend the page a bit by adding information about the directory layout and some other stuff. I still plan to add at least basic description of the Do_* functions, but any comments are welcome (or even your own improvements based on your findings - remember, that it's a Wiki and you can improve it as well as anyone else).

Tomas

Reply by email