Haha, thats pretty definitive, yes!mk79 wrote:<>Code: Select all
move.w bv..chrix,a1
Returning values from a basic extension function
Re: Returning values from a basic extension function
Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
-
- Bent Pin Expansion Port
- Posts: 90
- Joined: Sat Aug 26, 2017 11:58 am
Re: Returning values from a basic extension function
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.
I finally have a working sbasic extension function


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.
- NormanDunbar
- Forum Moderator
- Posts: 2470
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: Returning values from a basic extension function
It's a good feeling isn't it? Well done.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![]()
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
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
-
- Bent Pin Expansion Port
- Posts: 90
- Joined: Sat Aug 26, 2017 11:58 am
Re: Returning values from a basic extension function
Hi Norm,NormanDunbar wrote:It's a good feeling isn't it? Well done.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![]()
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.
It's SMSQ/E 3.36. The extension works. It just fails to find some names which it finds successfully after the NEW.
D.
- mk79
- QL Wafer Drive
- Posts: 1349
- Joined: Sun Feb 02, 2014 10:54 am
- Location: Esslingen/Germany
- Contact:
Re: Returning values from a basic extension function
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.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.
Marcel
- mk79
- QL Wafer Drive
- Posts: 1349
- Joined: Sun Feb 02, 2014 10:54 am
- Location: Esslingen/Germany
- Contact:
Re: Returning values from a basic extension function
You test in the main SBasic or some daughter SBasic?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.
Marcel
-
- Bent Pin Expansion Port
- Posts: 90
- Joined: Sat Aug 26, 2017 11:58 am
Re: Returning values from a basic extension function
Hi Marcel,
In the main Sbasic.
D.
Edit: I think I've found the problem. We'll find out tomorrow...
In the main Sbasic.
D.
Edit: I think I've found the problem. We'll find out tomorrow...
-
- Bent Pin Expansion Port
- Posts: 90
- Joined: Sat Aug 26, 2017 11:58 am
Re: Returning values from a basic extension function
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
But it does give a certain feeling of accomplishment now that it works...
Thanks to all for your help,
D.
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

Thanks to all for your help,
D.
Re: Returning values from a basic extension function
Congrats on getting it to work!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![]()
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
- janbredenbeek
- Super Gold Card
- Posts: 673
- Joined: Wed Jan 21, 2015 4:54 pm
- Location: Hilversum, The Netherlands
- Contact:
Re: Returning values from a basic extension function
You've probably found a temporary name table entry which could be the argument to a procedure or function or saved local variable.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![]()
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