Printing SuperBASIC programs

Anything QL Software or Programming Related.
RWAP
RWAP Master
Posts: 2846
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: Printing SuperBASIC programs

Post by RWAP »

Is there a reason why you can't just use:

OPEN #3,par
LIST #3
CLOSE #3

(may need to use OPEN #3,ser1c if your printer is connected via the serial port)...


stevepoole
Super Gold Card
Posts: 724
Joined: Mon Nov 24, 2014 2:03 pm

Re: Printing SuperBASIC programs

Post by stevepoole »

Hi Rich,
I just tried your short code fragment, both as a program, and as direct commands. The result was a printer lockup. Yet 'par' works OK in my little program...wierd!
Looks like LIST#3 fails on QPC, or is it SMSQ/E?
Steve.


User avatar
pjw
QL Wafer Drive
Posts: 1322
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Printing SuperBASIC programs

Post by pjw »

I must have missed this thread..

Another alternative is my sb2htm program that outputs a S*Basic listing as navigateable, colour coded html. It has many formatting options, including line length (though this is rather crude). And as a bonus you can print it all out in glorious technicolor(R) using all the various formatting options of your favourite browser.

It can probably be found on Dilwyn's site, or contact me directly if youre interested.

Per

PS The program requires the listing to be in tokenised form, so you need a toolkit that QSAVEs your source code. Native to SMSQ/E


Per
dont be happy. worry
- ?
EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: Printing SuperBASIC programs

Post by EmmBee »

I have updated dilwyn’s program - See a few posts back. The new version requires Turbo Toolkit and DIY VolP_PARAMS_code to be LRESPR‘ed. Word-wrap has been implemented. This turns out to be very simple - pairs of chars are compared for being joined, starting from the right hand end and working backwards. Subsequent lines are printed one character after the indent current position, which seems to be the most readable option. Q-Liberator has also been used to turn the LLIST command into a fully-fledged KEYWORD. Line 29990 has been added with REMark $$external to indicate this. Because compiled programs are not allowed to do a “SAVE” or “LIST”, these commands have to be carried out by the Interpreter. If this were to be Turbo compiled, then the command to LIST could be typed in, then Turbo could wait until the command completes and the SuperBASIC cursor again begins to flash. With an external Q-Liberator job however, this would not work, since whenever an external QLIB job runs, the Interpreter gets suspended, which would involve waiting forever - and never proceeding. To get around this problem, the command to LIST is followed by another command to call LLIST again, and then the program returns, allowing the commands to be carried out. This does the trick and LLIST will be called again. The second time around, the temporary$ file will be in existence, and the program will continue, in the same way that the Interpretor would.

Of course, line numbers 30040 and 30050 should be adjusted to suit your system. My own preference is to use “ram1_test_report” as the device, so that I can see what the final printout would look like. After compiling with Q-Liberator, an output_obj file is produced. This file will need to be LRESPRR’ed. After this, the command LLIST becomes available, just like any other SuperBASIC Keyword. One can then type in, for example: LLIST 2000 to 3000, to get a printout, or a file, of the specified range.

This is great - it works fine - but only under QDOS. Using Q-emuLator and Minerva, this will compile and work as is intended. You will have to, of course, LRESPR the output_obj file in your BOOT file to get this to work.

And now on to the next great step, to get this to work in QPC2. At the moment, this is not happening. I use QPC2 all the time now; this is the future - however, when things go wrong, when things don’t happen, I have to backtrack and use Q-emuLator. QPC2 is reporting a problem running Q-Liberator externals. There is an attempt to correct this problem in their software, in the form of a patch to do with address sensitivity. The problem is I have been unable to successfully use this patch, yet. Here is the updated program ...

Code: Select all

100 REMark TK2-ED-style formatted listings, by Dilwyn Jones February 2012
105 REMark Updated by Michael Bulford December 2014
110 :
113 REMark Requirers Turbo_Toolkit for COMPILED & TYPE_IN
114 REMark Requirers DIY VolP_PARAMS_code for UNSET ... PARSTR$ won't work in QLIB
116 REMark and Q-LIBERATOR in the attempt to finally make LLIST a stand-alone KEYWORD
117 REMark This attempt succeeds under QDOS, but currently fails under QPC2 ...
119 :
120 LLIST 1 TO 32767
130 :
29990 REMark $$external
30000 DEFine PROCedure LLIST (first_line%, last_line%)
30010 LOCal device$(41),left_margin%,line_width%,indent%,temporary$(41)
30015 LOCal get_line,lne$, in, x$(1), i, t$, listing
30020 LOCal Alpha_$(27), Alpha_Numeric$(27+10+1), Alpha_Numeric_Plus$(27+10+1+2)
30021   Alpha_$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
30022   Alpha_Numeric$ = Alpha_$ & "0123456789"
30023   IF VER$ = "HBA" : Alpha_Numeric$ = Alpha_Numeric$ & "."
30024   Alpha_Numeric_Plus$ = Alpha_Numeric$ & "$%"
30025   IF UNSET(first_line%) : first_line% = 0
30027   IF UNSET(last_line%)  :  last_line% = 0
30028   IF first_line% = 0 : first_line% = 1
30029   IF last_line% = 0 : last_line% = 32767
30030   REMark default settings
30040   device$ = "ram1_test_report" : REMark = 'PAR' : REMark SER1/SER2/PAR/PRT etc
30050   left_margin% = 10 : REMark left margin (characters)
30060   line_width% = 55 : REMark suits Q-emuLator's virtual printer = 69 chars max
30070   indent% = 4 : REMark TK2-ED-style indent (characters)
30080   temporary$ = 'ram1_tmp_dat' : REMark temporary listing file
30090   :
30100   OPEN_OVER #3,device$ : REMark send formatted listing to here
30110   :
30120   REMark send a listing to work on to temporary$
30125   IF NOT COMPILED
30130     OPEN_OVER #4,temporary$ : LIST #4,first_line% TO last_line%
30131   ELSE
30132     IF FTEST(temporary$) = -7
30133       TYPE_IN "SAVE "& temporary$ &","& first_line% &" TO "&last_line%&CHR$(10)
30134       TYPE_IN "LLIST "                & first_line% &" TO "&last_line%&CHR$(10)
30135       RETurn
30138     END IF
30139   END IF
30140   CLOSE #4 : OPEN_IN #4,temporary$
30150   :
30160   REPeat get_line
30170     IF EOF(#4) THEN BPUT #3,12 : EXIT get_line : REMark form feed after last li
    ne
30180     REMark INPUT #4,lne$ : REMark get line of BASIC into a string
30182     lne$ = "" : REMark avoid buffer too small error on JM ROM
30184     REPeat in: x$ = INKEY$(#4): IF x$=CHR$(10): EXIT in : ELSE lne$ = lne$ & x$
30190     :
30200     REMark first section of line is not indented
30210     IF LEN(lne$) <= line_width% THEN
30220       REMark whole line of BASIC will fit on one line
30230       PRINT #3,FILL$(' ',left_margin%);lne$ : NEXT get_line
30240     ELSE
30242       REMark set indent% to wrap position
30243       FOR i = " " INSTR lne$ TO LEN(lne$) : IF lne$(i)<>" " : EXIT i
30244       indent% = i : IF indent%>line_width% DIV 2 : indent% = line_width% DIV 2
30250       REMark print first section without indent
30255       t$ = word_wrapped$((lne$(1 TO line_width%+1)))
30260       PRINT #3,FILL$(' ',left_margin%);t$
30270       lne$ = lne$(LEN(t$)+1 TO LEN(lne$))
30280     END IF
30290     :
30300     REPeat listing
30310       IF LEN(lne$) <= (line_width%-indent%) THEN
30320         REMark last section of line to list
30330         PRINT #3,FILL$(' ',left_margin%+indent%);lne$
30340         EXIT listing : REMark that was last section of this line
30350       ELSE
30360         REMark print current section of line
30370         t$ = word_wrapped$((lne$(1 TO line_width%-indent%+1)))
30380         PRINT #3,FILL$(' ',left_margin%+indent%);t$
30390         IF LEN(lne$) > LEN(t$) THEN
30400           REMark truncate line to section not printed yet
30410           lne$ = lne$(LEN(t$)+1 TO LEN(lne$))
30420         ELSE
30430           lne$ = '' :REMark finished
30440           EXIT listing
30450         END IF
30460       END IF
30470     END REPeat listing
30480   END REPeat get_line
30490   :
30500   PRINT #3,CHR$(12); : REMark form feed last sheet of paper
30510   :
30520   CLOSE #4 : CLOSE #3 : DELETE temporary$
30530   PRINT #0, ' ... Successfully printed to "'; device$; '"'
30540 END DEFine LLIST
30550 :
30560 DEFine FuNction word_wrapped$(Lin$)
30570 LOCal p
30580   REMark Lin$ contains one additional character tacked onto the end
30590   FOR p = LEN(Lin$)-1 TO 1 STEP -1
30600     IF NOT JOINED((Lin$(p TO p+1))) : RETurn Lin$(1 TO p)
30610   END FOR p
30620   REMark whole line is joined
30630   RETurn Lin$(1 TO LEN(Lin$)-1)
30640 END DEFine word_wrapped$
30650 :
30660 DEFine FuNction JOINED(twochar$)
30670 LOCal left$(1), right$(1)
30680  left$ = twochar$(1) : right$ = twochar$(2)
30690  IF left$ INSTR Alpha_Numeric$ : IF right$ INSTR Alpha_Numeric_Plus$ : RETurn 1
30700  IF " " & twochar$ INSTR " >= == <> <= || && ^^ ~~" : RETurn 2
30710  IF left$  = ".": IF right$ INSTR "0123456789" : RETurn 1
30720  IF right$ = ".": IF  left$ INSTR "0123456789" : RETurn 1
30730  IF left$  = "$": IF right$ INSTR "0123456789ABCDEF" : IF VER$="HBA" : RETurn 1
30740  IF left$  = "%": IF right$ INSTR "01"               : IF VER$="HBA" : RETurn 1
30750  RETurn 0
30760 END DEFine JOINED
This works under QDOS. How can this be made to work under QPC2, please?

Michael


Post Reply