PE Programming for dummies

Anything QL Software or Programming Related.
User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PE Programming for dummies

Post by tofro »

Andrew wrote:
tofro wrote:Yep, appman is a bit awkward to handle, but still very useful. Small Recipe:
  • Open appman
  • Add your menus ("load"->"Menu", assign some proper names (last column). Your Window should look like this: APPMAN0.png
  • Save as an extension (Set "Command" to "APPA0", which should be the default, then save as an appendix (e.g. "charmap_app", FILES->SAVE->APPENDIX). Don't try and mess with the "append" option or something - That's a bit of a nuisance in compiled programs, IMHO.
  • LRESPR the app file you made to check it.
  • PRINT appa0('charmap') (Or whatever you called a menu in the app file) must return a reasonable value. x = FOPEN ("con") : MDRAW #x,APPA0("charmap") must display the menu - otherwise, repeat previous steps until you succeed.
  • Up to here, you got it working in S*BASIC. Now you need to be able to use it in a compiled program. This is what I do with Turbo: "200 REMark %%dos2_charmap_app,0,60". For liberated programs, you would probably use something like 400 REMark $$asmb=win1_dev_charmap_app0_app,0,60 (The 60 works for me, but may depend on your appman version. In case 60 doesn't work, provide your _app file for analysis, please)
Hope this helps!
Done! And I still get the same errors when I run the compiled program...
After Lrespr win1_dev_charmap_char_app x = FOPEN ("con") : MDRAW #x,APPA0("charmap") displays the menu
I have attached the char_app (just delete the .zip extension)

What APPMAN version are you using?
I use v4.02, latest version from EasyPtr4 package from Dilwyn's site - and it refuses to run on QPC2 in high colour modes!!!! It only runs in QL colors mode

Later Edit: I noticed that qlib_ext is not corectly linked to the obj when I use QLiberator 3.45 - but it is linked when I use Qliberator 3.36.
This may be because the init and table values are not correct for v3.45

Code: Select all

40 REMark $$asmb=win1_QLiberator_qlib_ext,0,12
I have attached the qlib_ext (just delete the .zip extension) Please , can you tell me the correct values?

You seem to be cursed today: I can't unpack any of your zip files. Neither from Windows nor from MacOS


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PE Programming for dummies

Post by tofro »

Looking at the hexdump of QLIB_EXT, I think the table address should actually be 10 for 3.45 instead of 12, so

Code: Select all

40 REMark $$asmb=win1_QLiberator_qlib_ext,0,10
should do the trick.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PE Programming for dummies

Post by tofro »

And after I realized you sent the files uncompressed and just named them zip to have the forum accept them, I also had a look at the app file: The "60" I stated above seems to be OK.

(I actually don't know what version of appman I use - It's the one I bought a long time ago...)


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Andrew
Aurora
Posts: 796
Joined: Tue Jul 17, 2018 9:10 pm

Re: PE Programming for dummies

Post by Andrew »

tofro wrote:And after I realized you sent the files uncompressed and just named them zip to have the forum accept them, I also had a look at the app file: The "60" I stated above seems to be OK.

(I actually don't know what version of appman I use - It's the one I bought a long time ago...)
Thank you.
So, if 0,60 is the valid value ... and I still get the errors then the bug is somewhere else.
Apart of the char_app I also load ptrmen_cde 4,82 . SHould I also load easymem 4,82? (well I tried, got same error at run)
Or maybe the way I call menus is the problem?

Code: Select all

1070 IF Q_MYJOB <> 0 THEN
1080    OPEN #0,'con' : OPEN #1,'con' : OPEN #2,'con'
1090    mainch%=3
1100    md$ = '' : mx$ = ''
1110 ELSE
1120    mainch%=3
1130    md$ = HOME_DIR$ : mx$ = '_men'
1140 END IF
.................
1630 DEFine PROCedure initialise
1640   OPEN #mainch%,'con_'
1650   MDRAW #mainch%,md$&'charmap'&mx$, 110, 15
1660   menu = MWDEF(#mainch%)
1670   initialise_menu
1680 END DEFine initialise
Should I use instead APP0("charmap") ? Do I need a larger stack?
Last edited by Andrew on Sat Dec 25, 2021 8:48 pm, edited 1 time in total.


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PE Programming for dummies

Post by tofro »

How do I do that:

I use a hexdump application on the binary extension file (I use hexedit, that's probably available from Dilwyn's site, but any will do)
Hexdump.png
In the Hexdump, try and find the first BASIC keyword. Here, it's a function (that becomes important later), and the file's got no other functions and procedures in it.

The layout of a BP.INIT table looks like the following (from QL Technical Guide):
Bildschirmfoto 2021-12-25 um 21.38.41.png
Back to the hexdump:
  • Find the first Basic keyword - here it's "APPA0" at offset $46. The byte in front of it is the length of the command (5)
  • The two bytes in front of that ($000A) are the word offset to the code - not of interest to us here
  • The word in front of that ($0001 at offset $40 is either the number of procedures (we don't have any) or the number of functions (1, that's it here)
  • The word in front of that (0) is a filler word (see manual) between PROCS and FUNCTIONS
  • And the word in front of that ($0000 at offset $3C) is the beginning of the table that is simply $0000, because we have no PROCS in the file. (If we had, we'd need to go backwards even further)
  • $3C hex is 60 decimal, voilá, we got the table address.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Andrew
Aurora
Posts: 796
Joined: Tue Jul 17, 2018 9:10 pm

Re: PE Programming for dummies

Post by Andrew »

Good to know - I'll print this!


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PE Programming for dummies

Post by tofro »

Andrew wrote:

Code: Select all

1070 IF Q_MYJOB <> 0 THEN
1080    OPEN #0,'con' : OPEN #1,'con' : OPEN #2,'con'
1090    mainch%=3
1100    md$ = '' : mx$ = ''
1110 ELSE
1120    mainch%=3
1130    md$ = HOME_DIR$ : mx$ = '_men'
1140 END IF
.................
1630 DEFine PROCedure initialise
1640   OPEN #mainch%,'con_'
1650   MDRAW #mainch%,md$&'charmap'&mx$, 110, 15
1660   menu = MWDEF(#mainch%)
1670   initialise_menu
1680 END DEFine initialise
Should I use instead APP0("charmap") ? Do I need a larger stack?
Line 1650 obviously still tries to load the menu from a file and doesn't even use the appman-generated memory-resident menu. If you have LRESPRed the app file, you should be able to change that to

Code: Select all

1650 MDRAW #mainch%,APPA0("charmap") 
(assumed you named the menu "charmap" in APPMAN)

That should already work in the interpreter and no longer access the _men file. If you can't get that working in the interpreter, there's no point in compiling it....

If you do, however, have problems with the program compiled as above, the problem can't really be caused by the _app file, because you don't even use it yet.

I read the thread back and couldn't find what errors exactly you get with the compiled file. Did you write that anywhere?


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PE Programming for dummies

Post by tofro »

And:

As you seem to be jumping back and forth between QLiberator versions, are you absolutely sure that what you state in the $$asmb directive and what is currently LRESPRed into memory is the same file? Wierd things may happen if that's not the case.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Andrew
Aurora
Posts: 796
Joined: Tue Jul 17, 2018 9:10 pm

Re: PE Programming for dummies

Post by Andrew »

tofro wrote:And:

As you seem to be jumping back and forth between QLiberator versions, are you absolutely sure that what you state in the $$asmb directive and what is currently LRESPRed into memory is the same file? Wierd things may happen if that's not the case.
I am absolutely sure.

This part is copied from DIlwyn's examples ...

Code: Select all

1640   OPEN #mainch%,'con_'
1650   MDRAW #mainch%,md$&'charmap'&mx$, 110, 15
I will modify the code to use

Code: Select all

MDRAW #mainch%,APPA0("charmap")


User avatar
BSJR
Trump Card
Posts: 186
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: PE Programming for dummies

Post by BSJR »

tofro wrote:...
(I actually don't know what version of appman I use - It's the one I bought a long time ago...)
Tofro,
Judging from the "APPMAN MANAGER" image you posted earlier, it's a High Colour version 4.0x and the 60 bytes offset has not changed in that.

Andrew,
The resident Ptrmen code loaded in your BOOT should be the "r" version for APPAx to work.
So Ptrmenr_cde is the best choice giving global access to all the EasyPTR keyword you may need. If memory is limited the "easymenr_cde" option may also work.

BSJR


Post Reply