My "from PACKAGE import *" (Python) simulation project

Anything QL Software or Programming Related.
User avatar
ql_freak
Gold Card
Posts: 476
Joined: Sun Jan 18, 2015 1:29 am

My "from PACKAGE import *" (Python) simulation project

Post by ql_freak »

To improve this further, I need a method (ideally in SuperBASIC without the need for a machine code extension) to get the highest line no. of the currently loaded SuperBASIC program. I could not find anything, not even in Jan Jones QL SuperBASIC The Definitve Handbook. Any hints?
rnMERGE01.png
rnMERGE01.png (8.53 KiB) Viewed 492 times
rnMERGE02.png
rnMERGE02.png (8.99 KiB) Viewed 492 times
rnMERGE03.png
rnMERGE03.png (10.75 KiB) Viewed 492 times


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
tofro
Font of All Knowledge
Posts: 3070
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: My "from PACKAGE import *" (Python) simulation project

Post by tofro »

S*BASIC doesn't really store BASIC programs "by line number". In all cases where it would need the current highest line number (for example, in order to do a "DLINE TO"), it simply scans through the complete program to find the last line. There's actually no easy way I know to get to that other than doing what S*BASIC itself does.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
ql_freak
Gold Card
Posts: 476
Joined: Sun Jan 18, 2015 1:29 am

Re: My "from PACKAGE import *" (Python) simulation project

Post by ql_freak »

Thanks Tobias,

I have feared that :‑( How can I scan through the program? Is there a (double) linked list or so?

Peter


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
martyn_hill
QL Wafer Drive
Posts: 1065
Joined: Sat Oct 25, 2014 9:53 am

Re: My "from PACKAGE import *" (Python) simulation project

Post by martyn_hill »

Hi Peter

If you wish to stick to vanilla SuperBasic, then the following approach will work for any valid SuperBASIC program file:

1. Open the file with OPEN_IN as usual
2. Iterate through all its lines in a REPeat loop, INPUTing each one sequentially in to a variable, say lastLine$
3. Test before INPUTing the next line with EOF - if EOF, then exit the loop, otherwise read the next
4. CLOSE the file
5. Now simply assign a numeric variable to the entire last line INPUTed, e.g. lastLineNo%=lastLine$ (oercion takes care of ignoring everything after the actual line number that appears at the start of each line.)

Make sense?


User avatar
ql_freak
Gold Card
Posts: 476
Joined: Sun Jan 18, 2015 1:29 am

Re: My "from PACKAGE import *" (Python) simulation project

Post by ql_freak »

Is there no possibility to scan the lines of a loaded SuperBASIC program, without the need to read the source file. DLINE, GO TO, ... must be able to find a line number, so there must be a way. Or is this not documented? I could write a SuperBASIC extension, it must not be done in S(uper)BASIC.


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
janbredenbeek
Super Gold Card
Posts: 668
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands
Contact:

Re: My "from PACKAGE import *" (Python) simulation project

Post by janbredenbeek »

ql_freak wrote: Mon Apr 14, 2025 7:54 pm Is there no possibility to scan the lines of a loaded SuperBASIC program, without the need to read the source file. DLINE, GO TO, ... must be able to find a line number, so there must be a way. Or is this not documented? I could write a SuperBASIC extension, it must not be done in S(uper)BASIC.
It is documented in Jan Jones's Definitive Handbook.
Basically, you start at the base of the program file (pointer at $10(a6)), then each line has a word at the start holding the difference in length from the previous line, followed by the token $8D00, followed by a word holding the line number.
So, in code:

Code: Select all

pointer=PEEK_L(\\16)
cur_length=0
REPeat loop
  IF pointer>=PEEK_L(\\20) THEN EXIT loop: REMark end of program
  cur_length=cur_length+PEEK_W(\16\pointer)
  IF PEEK_W(\16\pointer+4)=desired_line_number THEN EXIT loop
  pointer=pointer+cur_length
END REPeat loop


User avatar
ql_freak
Gold Card
Posts: 476
Joined: Sun Jan 18, 2015 1:29 am

Re: My "from PACKAGE import *" (Python) simulation project

Post by ql_freak »

 
Thank you Jan!

This approach seems not to be too complicated to write a machine code S(uper)BASIC function, especially as line numbers are (short) int, i.e. you must not return an (long) int (which is not possible in machine code functions, int [always long on 68k] must be converted to float :‑( I never did it).

p.s.:
Unfortunately I have now a much more serious problem: The fan of my old ThinkPad (my main computer now), quad core Intel and 32 GByte RAM, is defect and I'm currently working on my old Desktop PC (4 GByte RAM and an old 2 core Intel processor). Arrggghhhh...

And so I have currently no access to my rn executable which adds line numbers. BTW: It has been written in EJC (Erling Jacobsen C), i.e. it is reentrant (and most probably even ROMable).


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
ql_freak
Gold Card
Posts: 476
Joined: Sun Jan 18, 2015 1:29 am

Re: My "from PACKAGE import *" (Python) simulation project

Post by ql_freak »

Unfortunately, the motor of the fan seems to be defect. I have disassembled the ThinkPad (W520) and cleaned the fan. It still fails. But I have seen it has a normal SSD which I can slot to my Desktop PC. And I perhaps find time to install my GPD Pocket 3. It has the advantage (compared to the GPD 2 [which fits in pocket, 3 does not]), that it has a monitor port (HDMI I think). And as it has an Intel Core 7 and it's much newer, it may be even faster than my ThinkPad. The ThinkPad goes to repair next week.

So it may take some time, before I can continue with the "SB-Import" project.


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
Giorgio Garabello
Gold Card
Posts: 299
Joined: Tue Jun 30, 2015 8:39 am
Location: Turin, Italy
Contact:

Re: My "from PACKAGE import *" (Python) simulation project

Post by Giorgio Garabello »

I guess yours is a "challenge" to try to do this in basic, because the simplest thing would be with QD or MicroEmacs to remove the numbers and reintroduce them automatically with SSB.

Giorgio


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

Re: My "from PACKAGE import *" (Python) simulation project

Post by tofro »

Well I'd guess that a

Code: Select all

RENUM 1 TO;1,1
MERGE <to highest possible line number for inserted code (i.e 32767-line count)>
RENUM 1 TO;10,10
Should do as well. Admitted here's no chance to catch errors, but that shouldn't fail more often than any more sophisticated method. This is the pragmatic approach: Just make as much room as possible for the inserted code and when that turns out not enough, any other hugely more complicated method wouldn't have worked as well.....


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Post Reply