QL / PASCAL

Anything QL Software or Programming Related.
User avatar
NormanDunbar
Forum Moderator
Posts: 2274
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: QL / PASCAL

Post by NormanDunbar »

Ruptor wrote:30K for Hello World that is half the microdrive capacity is funny
I rather suspect that as applications get more complex than writeln('HelloWorld!'); the size discrepancy will come down. Even with C68, a hello world type program seems quite big compared to assembly.

Just a thought.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: QL / PASCAL

Post by Tinyfpga »

I found this pascal thread intriguing and it started me thinking about high level language support on SMSQE.

I use an SMS2 interactive (not the SMSQEinterpreter) BASIC programming environment within SMSQE. The complete setup including the OS, takes about 1 second to install/run on QPC2 and about 3 seconds on my Q68. The actual programming environment is less than 250 Kbytes in size.

I thought I might compare this situation with a native installation of DELPHI on my thinkpad X220. Now I know that a comparison between Delphi and SMS BASIC is slightly fatuous, but Pascal is what is being discussed and I wanted to see what a native installation of a PASCAL IDE would entail.
It took me some time overcome the front end of the download section at embarcadero.com before I was able to download the Delphi Community Edition.
The installation process then took more than 15 minutes to complete with all but Windows access switched off. The insallation required 3 Gbytes of disk space, 9 Gbytes if I had added Android access. I then executed the IDE which took 20 seconds to pop up on my screen with the declaration that various files were missing . It then crashed and had to be forcibly removed because it ran out of memory (I only have 4 Gbytes of ram on my laptop and I switch off the virtual memory of my PC )

I then installed various lightweight IDEs that in some ways do less than my SMS-BASIC setup.
Arduino:- 196 Mbyte zip installer
Microbit:- 168 Mbytes for the Makecode installation and 67 Mbytes for the mu_editor
PICAXE 6:- 95 Mbyte installer, excluding the .Net Framework
Dscript:- a BASIC like language for Robot-e devices at 50 Mbytes.

I am not sure that trying to duplicate a Delphi like IDE in SMSQE is going to work, and I, for one, really like my ultra light-weight and relatively simple SMS-BASIC environment. It is rather amazing that it is 200 times smaller than the smallest IDE mentioned above and 670 times smaller than the Microbit Makecode.

I think it will be very difficult to better the SMS-BASIC performance/size ratio.


Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: QL / PASCAL

Post by Tinyfpga »

Ruptor wrote:
30K for Hello World that is half the microdrive capacity is funny

Following my recent post and inspired by Ruptor I wrote two Hello World Programs in my SMS-BASIC running within QPTR. Both are executable and windowing with shadows.

The first is a fixed window program that accepts keyboard entry, it has no embedded documentation. The ex file is 714 bytes
The second is in a moveable window that accepts mouse control and has extensive embedded documentation. The ex file is 5188 bytes.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: QL / PASCAL

Post by mk79 »

Chain-Q wrote:
mk79 wrote:Yay :-P When I find the time I might try to implement EXE support. Of course the real work will be in the libraries... :?
Congrats for being the 2nd person who ever managed to get this shebang somewhat working. :) BTW, in the currently committed version, I think a simple Pascal-ish writeln('Hello, World!') should work to
That was the first thing I tried and it didn't work... but now it does, spooky :? ;)


User avatar
Chain-Q
Chuggy Microdrive
Posts: 62
Joined: Mon Nov 16, 2020 1:10 pm
Location: Berlin, DE, EU
Contact:

Re: QL / PASCAL

Post by Chain-Q »

NormanDunbar wrote:
Ruptor wrote:30K for Hello World that is half the microdrive capacity is funny
I rather suspect that as applications get more complex than writeln('HelloWorld!'); the size discrepancy will come down.
Yes, exactly, this is what I meant. More complex programs usually suffer less from this in relative terms. (Well, depends a lot on how you write those complex programs, but overall it's still true.)

Actually, in theory it's possible to turn off almost all of Free Pascal's features in the RTL, including for example standard Pascal text I/O, and that would help greatly to minimize binary sizes (this is used by our embedded target a lot for example, esp. for microcontrollers), but then you'd also have to fall back entirely to using OS API functions in your own code.


User avatar
Chain-Q
Chuggy Microdrive
Posts: 62
Joined: Mon Nov 16, 2020 1:10 pm
Location: Berlin, DE, EU
Contact:

Re: QL / PASCAL

Post by Chain-Q »

mk79 wrote:
Chain-Q wrote:BTW, in the currently committed version, I think a simple Pascal-ish writeln('Hello, World!') should work to
That was the first thing I tried and it didn't work... but now it does, spooky :? ;)
Well, maybe there was some build issue, or if you tried with standard QL, it didn't have enough memory for some reason, maybe because the code was loaded twice, or something. (The startup code just exits silently if it cannot allocate stack for itself.) But it's just an idea.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: QL / PASCAL

Post by mk79 »

Well, I spent some time on it now. You know things will go well when one of the first things you try results in an "internal error" of the inline assembler... it simply crashed anytime one wants to use "dc.b" or similar statements :( So I had to fix that first (compiler.diff).

The remaining diff changes the compiler to output real QDOS exe files. For my convenience the EXE file will be prepended with a QEmuLator compatible (and QPC2 v5, not yet released) EXE header, so the resulting file can directly be executed here. Alternatively there is some commented out code that can produce the XTcc trailer known from XTC68 instead. Also, a MAP file is now produced to help debugging.

Furthermore I implemented most of the file system API, though I haven't tested most of the code so far. That must wait for another time...

Cheers, Marcel
Attachments
fpc_diff.zip
(5.77 KiB) Downloaded 80 times


User avatar
Peter
QL Wafer Drive
Posts: 1987
Joined: Sat Jan 22, 2011 8:47 am

Re: QL / PASCAL

Post by Peter »

mk79 wrote:Alternatively there is some commented out code that can produce the XTcc trailer known from XTC68 instead.
Thanks Marcel. That's a good idea, as the XTcc trailer is the standard QL cross compiler output, which one gets from QDOS-GCC also, and from cross assembly. Classic tools for native filesystem access like qxltool also support the XTcc trailer rather than the Qemulator header. SMSQmulator NFA also supports the XTcc trailer.

Direct conversion+write into a native QLWA filesystem would look like this:
qxltool -w -c "wr <inputfile> <outfputfile>" <containerfile>

Where <containerfile> usually has the extension .WIN - such container files can be used by a lot of native hardware, ranging from QL-SD equipped original QLs to Q68.


User avatar
Chain-Q
Chuggy Microdrive
Posts: 62
Joined: Mon Nov 16, 2020 1:10 pm
Location: Berlin, DE, EU
Contact:

Re: QL / PASCAL

Post by Chain-Q »

mk79 wrote:Well, I spent some time on it now. You know things will go well when one of the first things you try results in an "internal error" of the inline assembler... it simply crashed anytime one wants to use "dc.b" or similar statements :( So I had to fix that first (compiler.diff).
Yeah, this is a nice catch. The QL port already required 4 or 5 major fixes in the assembler reader so far (this one not included), but I've no doubt there's more to come. The assembler reader was the only major component which we reused and just patched up from the very early 1.0.x m68k Free Pascal, when we resurrected the m68k port for v3.0, and it sadly shows. And no other port needed the internal assembler so much before as the QL port. Your patch was very helpful for a quick identification of where the problem was, but instead of using it directly, I ended up refactoring the entire BuildConstant method in ra68kmot.pas. See here and here.
mk79 wrote:The remaining diff changes the compiler to output real QDOS exe files. For my convenience the EXE file will be prepended with a QEmuLator compatible (and QPC2 v5, not yet released) EXE header, so the resulting file can directly be executed here. Alternatively there is some commented out code that can produce the XTcc trailer known from XTC68 instead.
Looks overall OK, but I haven't looked this one in detail yet.
Also, a MAP file is now produced to help debugging.
This is a great idea, but probably should be done slightly differently. However, just as above the patch is very helpful, and I'll slightly modify it when I'll integrate and commit it. (BTW, you can pass any argument to the linker via the -k command line argument already, so you could have used it to get the map file from the linker, but it's an useful feature, so lets have it.)
Furthermore I implemented most of the file system API, though I haven't tested most of the code so far. That must wait for another time...
I looked quickly through, overall it's looking good. My only hint is that make sure your assembly code respects the ABI. This means registers d2-d7/a2-a6 must be saved before modifying, and the calling convention is slightly complicated. Free Pascal doesn't just pass arguments on the stack, but the first two "pointer" type arguments are passed in registers a0/a1, and the first two "ordinal" type arguments are passed in registers d0/d1. Remaining arguments are passed on the stack. The arguments are passed from left to right. This is important for example when you re-shuffle the input parameters for a QDOS trap/vector call, because if you don't keep it in mind which parameter might be passed in which register, then you could overwrite the parameter accidentally. See the m68k-specific calling convention and registers documentation here.

In other news, I'm still in talks with Frank Wille of vlink, and he's came up with a new relocation format, which is more compact than the current one, and will be generic for several embedded targets as well. His changes will also help us to avoid manually messing with combining various files in post-process. Maybe we can ask him to add the additional exe format(s) too, so we don't have to mess with declaring the header in the startup code. We'll see.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: QL / PASCAL

Post by mk79 »

Wow, thanks for the quick uptake :) Obviously I'm completely foreign to the codebase and in that case I tend to change minimalistically, so if anything can be implemented better I'm all for it. I also very much noticed that my Pascal days have been a while :shock:
Chain-Q wrote:The QL port already required 4 or 5 major fixes in the assembler reader so far (this one not included), but I've no doubt there's more to come. The assembler reader was the only major component which we reused and just patched up from the very early 1.0.x m68k Free Pascal, when we resurrected the m68k port for v3.0, and it sadly shows.
That explains it. I actually went "svn blame" to see when that got broken and which is the "newer" version, only to see that, within the SVN history, it has never worked in the first place.
mk79 wrote:The remaining diff changes the compiler to output real QDOS exe files. For my convenience the EXE file will be prepended with a QEmuLator compatible (and QPC2 v5, not yet released) EXE header, so the resulting file can directly be executed here. Alternatively there is some commented out code that can produce the XTcc trailer known from XTC68 instead.
Looks overall OK, but I haven't looked this one in detail yet.
Is there any mechanism of passing an option to the backend to select which style of output should be produced?
I looked quickly through, overall it's looking good. My only hint is that make sure your assembly code respects the ABI. This means registers d2-d7/a2-a6 must be saved before modifying, and the calling convention is slightly complicated.
Ah, I did check out the calling convention to see what registers should be saved (hopefully I got all, but I was pretty spent by the end of it, might very well have missed some) but I didn't check the register order! Good point. I did see some funny "move.l d1,d1" in the resulting code when the register is already in the right place, though ;)
In other news, I'm still in talks with Frank Wille of vlink, and he's came up with a new relocation format, which is more compact than the current one, and will be generic for several embedded targets as well. His changes will also help us to avoid manually messing with combining various files in post-process. Maybe we can ask him to add the additional exe format(s) too, so we don't have to mess with declaring the header in the startup code. We'll see.
I thought about the linker generating the header, too, but actually no QL linker does so either, so I'm fine with it being linked into the code as a normal object to stay generic. The only special thing QL linkers do is setting the dataspace and filetype in the file header. On non QL-systems there are the two options I've implemented (I'm not happy with either, but that's just the way it is. QPC will support the QemuLator header because XTcc is too limited for full filesystem header compatibility and performance reasons). Again they could also be generated by the compiler for the linker to stay generic, only thing the linker must convey is the size of .bss for this.

Having a smaller relocation section would be very nice, as it already takes some 2.5kb in the Hello World example. However, if any new formats could be established I'd like to put one further possible optimization up for consideration: relocation is not a common concept in the QL world and as the QL does not have any "loader" in that sense, it cannot throw away the reloc info after relocation like other systems would. So they end up occupying memory without any further benefit. It would however be possible for .reloc and .bss to share the same address space in memory, with the loader clearing the info during relocation for .bss usage. Not sure how difficult that would be to implement on the linker side, but definitely worth thinking about for small systems I guess.

All the best, Marcel


Post Reply