Forum Announcement
QL Forum Birthday Bash (21st November 2020) - https://qlforum.co.uk/viewtopic.php?f=12&t=3489

Returning values from a basic extension function

Anything QL Software or Programming Related.
User avatar
pjw
Super Gold Card
Posts: 710
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Returning values from a basic extension function

Postby pjw » Thu Oct 15, 2020 11:12 am

mk79 wrote:<>

Code: Select all

        move.w  bv..chrix,a1

Haha, thats pretty definitive, yes!


Per
Be wary of large West-Coast corporations bearing gifts!
- Ancient Trojan proverb
daniel_baum
Bent Pin Expansion Port
Posts: 84
Joined: Sat Aug 26, 2017 11:58 am

Re: Returning values from a basic extension function

Postby daniel_baum » Sun Oct 18, 2020 6:34 pm

Hi all,

I finally have a working sbasic extension function :) :) It takes an sbasic name as a parameter, and returns the value of the last four bytes of the name table entry for that name, which, in the case of an sbasic extension, is the address of the function itself. It returns them as a hex string. I also wrote the same thing in sbasic, so I could find my own function to debug it (using jmon), and, later on, to confirm the results of the assembly language code.

This is the first time I have ever attempted an sbasic extension, so I am rather chuffed that it works. There's still a bit of debugging to do before I am sure that it won't brick the system :(

I do have a couple of questions: the function does not work fully until I have done a NEW, or loaded a new basic program. Before this, it only works partially, not finding names toward the end of the name list. Any ideas why this might be?

Also, is it possible to change the cursor colour in QD? On my system (QPC2 in high colour mode) it's light blue, and doesn't stand out very well against the grey background.

Thanks to all for your help in getting me started :)

D.


User avatar
NormanDunbar
Forum Moderator
Posts: 1162
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Returning values from a basic extension function

Postby NormanDunbar » Sun Oct 18, 2020 7:05 pm

daniel_baum wrote:This is the first time I have ever attempted an sbasic extension, so I am rather chuffed that it works. There's still a bit of debugging to do before I am sure that it won't brick the system :(


It's a good feeling isn't it? Well done.

If you are on pre-JS, I think, extensions don't work after loading the code until NEW is called. From JS one, this is not necessary.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals - https://www.amazon.co.uk/Arduino-Softwa ... 1484257898, https://www.apress.com/gb/book/9781484257890
daniel_baum
Bent Pin Expansion Port
Posts: 84
Joined: Sat Aug 26, 2017 11:58 am

Re: Returning values from a basic extension function

Postby daniel_baum » Sun Oct 18, 2020 7:34 pm

NormanDunbar wrote:
daniel_baum wrote:This is the first time I have ever attempted an sbasic extension, so I am rather chuffed that it works. There's still a bit of debugging to do before I am sure that it won't brick the system :(


It's a good feeling isn't it? Well done.

If you are on pre-JS, I think, extensions don't work after loading the code until NEW is called. From JS one, this is not necessary.


Cheers,
Norm.


Hi Norm,

It's SMSQ/E 3.36. The extension works. It just fails to find some names which it finds successfully after the NEW.

D.


User avatar
mk79
Super Gold Card
Posts: 684
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Returning values from a basic extension function

Postby mk79 » Sun Oct 18, 2020 8:49 pm

daniel_baum wrote:Also, is it possible to change the cursor colour in QD? On my system (QPC2 in high colour mode) it's light blue, and doesn't stand out very well against the grey background.
Cursors are sprites on SMSQ/E, they can have any colour, alpha transparency and even animation. Check out marcel-theme and fading-cursor here https://www.kilgus.net/smsqe/gd2-high-colour/. Should also be part of the QPCDemo.win file supplied with QPC I think.

Marcel


User avatar
mk79
Super Gold Card
Posts: 684
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Returning values from a basic extension function

Postby mk79 » Sun Oct 18, 2020 8:50 pm

daniel_baum wrote:It's SMSQ/E 3.36. The extension works. It just fails to find some names which it finds successfully after the NEW.
You test in the main SBasic or some daughter SBasic?

Marcel


daniel_baum
Bent Pin Expansion Port
Posts: 84
Joined: Sat Aug 26, 2017 11:58 am

Re: Returning values from a basic extension function

Postby daniel_baum » Sun Oct 18, 2020 9:02 pm

Hi Marcel,

In the main Sbasic.

D.

Edit: I think I've found the problem. We'll find out tomorrow...


daniel_baum
Bent Pin Expansion Port
Posts: 84
Joined: Sat Aug 26, 2017 11:58 am

Re: Returning values from a basic extension function

Postby daniel_baum » Fri Oct 23, 2020 12:27 pm

Hi all,

I finally managed to debug my basic extension... it turns out that there are some name table entries with a name pointer of FFFF, and things went screwy when I tried to follow them into the name list. They are SBasic variables of some kind (maybe unused or invalid or something?) , so obviously when you NEW they disappear and everything works. My loop now identifies and ignores them, and everything at least appears to work now :)

Debugging this entailed printing out intermediate values - so I print out all of the name list strings until I find the one I am looking for, and if I don't find anything I print out how many iterations the loop has performed from start to finish. It also entailed getting very intimate with JMON, which really gives you the retro debugging experience ;)

Anyway, this was one of the longest and toughest debugging sessions I have ever had, and I program for a living :shock: But it does give a certain feeling of accomplishment now that it works...

Thanks to all for your help,

D.


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

Re: Returning values from a basic extension function

Postby tofro » Fri Oct 23, 2020 1:07 pm

daniel_baum wrote:Hi all,
I finally managed to debug my basic extension... it turns out that there are some name table entries with a name pointer of FFFF, and things went screwy when I tried to follow them into the name list. They are SBasic variables of some kind (maybe unused or invalid or something?) , so obviously when you NEW they disappear and everything works. My loop now identifies and ignores them, and everything at least appears to work now :)


Congrats on getting it to work!

Name table entries with -1 as a name pointer are typically expressions or substrings - these are sortof internal to the interpreter (they do have a value, but no name), and obviously, you shouldn't follow the -1 pointer ;)

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
janbredenbeek
Gold Card
Posts: 402
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Returning values from a basic extension function

Postby janbredenbeek » Fri Oct 23, 2020 1:46 pm

daniel_baum wrote:I finally managed to debug my basic extension... it turns out that there are some name table entries with a name pointer of FFFF, and things went screwy when I tried to follow them into the name list. They are SBasic variables of some kind (maybe unused or invalid or something?) , so obviously when you NEW they disappear and everything works. My loop now identifies and ignores them, and everything at least appears to work now :)

You've probably found a temporary name table entry which could be the argument to a procedure or function or saved local variable.
I've written a procedure ntdump which generates a dump of the nametable. You can even give it a string argument to search for specific names (unlike EXTRAS!) and it tells you if it's a variable, procedure or function with 'A' appended if it's a procedure argument and 'L' if it's a local variable.
It's still not perfect and gives different results on SMSQ/E and QDOS/Minerva, but it might be useful anyway...

Code: Select all

700 REMark ntdump_bas NameTable Dump Utility
710 REMark v2.0 20190120 Jan Bredenbeek
720 REMark requires: TK2 extensions AND Minerva OR SMSQ
730 DEFine PROCedure ntdump(n$)
740 LOCal l%,nt,ty%,ty$,dt%,dt$,no%,nl%,nl$,q$
750   q$=PARSTR$(n$,1)
755   wh=20:lc=1:REMark window height and counter
760   REMark loop for all NT entries
770   PRINT 'Type','Value','Pointer',,'Name'
775   argb=PEEK_L(\60\-24):locb=PEEK_L(\60\-20):loct=PEEK_L(\60\-16)
780   FOR nt=0 TO PEEK_L(\\28)-PEEK_L(\\24)-8 STEP 8
790     ty%=PEEK(\24\nt):dt%=PEEK(\24\nt+1):REMark name & data type
791     SELect ON ty%
792       =0:ty$="Unset"
793       =1:ty$="Expr"
794       =2:ty$="Var"
795       =3:ty$="Array"
796       =4:ty$="SBproc"
797       =5:ty$="SBfunc"
798       =6:ty$="REP"
799       =7:ty$="FOR"
800       =8:ty$="MCproc"
801       =9:ty$="MCfunc"
802       =REMAINDER :ty$="? ("&HEX$(ty%,8)&")"
803     END SELect
810     no%=PEEK_W(\24\nt+2):REMark namelist offset
815     IF nt>=argb AND no%>=0 THEN no%=PEEK_W(\24\no%+2)
820     IF nt>=argb AND nt<locb THEN ty$=ty$&"A"
825     IF nt>=locb AND nt<loct THEN ty$=ty$&"L"
830     IF no%>=0 THEN
835       nl%=PEEK(\32\no%):nl$=""
840       FOR l%=1 TO nl%:nl$=nl$&CHR$(PEEK(\32\no%+l%))
845     ELSE
850       nl$="*NO NAME*"
855     END IF
860     SELect ON dt%
861       =0:dt$="n/a"
862       =1:dt$="string"
863       =2:dt$="float"
864       =3:dt$="integer"
865       =REMAINDER :dt$="? ("&HEX$(dt%,8)&")"
867     END SELect
870     IF q$<>"" AND NOT (q$ INSTR nl$) THEN NEXT nt
875     lc=lc+1:IF lc>wh THEN
877       i$=INKEY$(-1):IF i$=="q" OR i$=CHR$(27) THEN EXIT nt
878       lc=1
879     END IF
880     PRINT ty$,dt$,HEX$(PEEK_L(\24\nt+4),32),nl$
890   END FOR nt
900 END DEFine ntdump


Jan



Who is online

Users browsing this forum: No registered users and 7 guests