Getting Started With Beta BASIC, Part 2

Part 2 – Printer & DOS Routines

SPECTRUM or TS2068 in SPECTRUM mode

In Part 1 (SWN Vol. 5 No. 5) of this intro to Beta Basic (BB) we looked at some of the editing and data-manipulation features which may be used on programs entered in T/S mode as well as those written in BB. This time let’s see how it may be adapted for use with a Spectrum-compatible DOS and also how to install relocatable machine code routines with BB in-residence.

The listings as shown were done in LIST FORMAT 2, using the printer driver routine from ProFile re-located into BB to send LLIST output to the printer. Someone may protest, “But the P/F driver doesn’t expand tokenwords for an LLIST.” True, but BB will do this before sending the LLIST data to a SW driver as well as sending the proper number of TAB n spaces for whatever printer column-width has been set by POKE 57500,n. The USING or USING$ function allows fixed-digit justification of columnar tabulations on either or both sides of the decimal point for screen displays and printouts. (LPRINT will work OK with the Oliger EPROM driver routine and possibly others, but BB keywords will not be expanded for LLIST.)

Print Driver Installation

To install the P/F driver routine (or any other re-locatable routine) first load the P/F header and code in normal T/S mode. If loading from tape, BREAK before the main listing as the code portion is all we need. To make the P/F driver routine compatible with Spectrum mode, POKE 63688,84 and POKE 63689,31. Make a save of just the P/F driver code block with the direct command SAVE “prcode”CODE 63672,117 (or revise this to define the location and number of bytes used by any other machine code routine).

Now go to Spectrum mode and load Beta Basic. Use your backup copy of the original program for this to make sure RAMTOP has not been moved downward as it will be in copies made after defining windows and user-defined functions that were not erased. As a direct command enter CLEAR 120, which moves RAMTOP down to make room for the driver code block (or CLEAR no. bytes plus 3 if using a driver other than P/F). The extra bytes are provided to prevent the driver code from over-writing BB and BB from over-writing part of the driver under some circumstances. The special BB CLEAR n accepts values of minus or plus 1-767 to move RAMTOP either upward or downward, and does not affect any existing variables, the screen, or the BB stack.

To find the new location of RAMTOP, enter the direct command LET rt=DPEEK(23730). Enter PRINT rt and write down the result. Note that the rt (RAMTOP) address marks the top location in free RAM available to Basic, not the beginning location of memory reserved by CLEAR n, which is rt+1. To move the driver code to this new location enter the direct command LOAD “prcode”CODE rt+1,117 and load the code block previously saved.

The first two lines of the header supplied with your Beta Basic should look something like those in the BB HEADER listing. (Later versions may have different line nos. but will include the same statements.) Following the RANDOMIZE USR 58419 in the header listing (which activates BB) insert the line DPOKE 61081,n in which n is the actual number obtained by adding 1 to that value previously noted for rt. This sets the pointer for BB printer output to the starting address of the driver that has been patched in. This pointer is reset to the ROM driver routine each time BB is activated by RANDOMIZE USR 58419. Revise the remaining lines in the header to the commands used by your printer.

DOS Modifications

DOS users should delete the tape auto-save POKE PEEK… statement between SAVE “Beta Basic” LINE 2 and SAVE “BB”CODE…. Adjust syntax in this line to that used by your system. Use <RUN> to make saves of this new header and the new code. SDOS users, and possibly others, will need to de-activate BB before each save by entering RANDOMIZE USR 59904 to prevent an “Invalid file name” error during the auto-VERIFY (although the save itself will be made OK). Each re-start of BB with RANDOMIZE USR 58419 installs an additional set of XOS, XRG, YOS, YRG graphics scale/range variables, taking up memory. To delete these without affecting other variables as CLEAR would do, follow each RANDOMIZE USR 58419 re-start with the routine in lines 30-40 of the RESTART listing. Note that only the part following the BB re-start may be defined as a procedure, but the entire RESTART sequence could be made a subroutine if more than one call is to be made to it during a program.

More Commands

The REVAL_DEVAL listing gives two procedures which appeared in BB newsletter #10. Normal floating-point numbers for GO TO, GO SUB, definitions, string-slicing, etc. are easier to use while entering a listing. Then if <reval> is entered these will all be changed to VAL “n” to conserve memory. They are changed back again by <deval>. Note that these procedures must be installed as lines 1-9 since they are designed to alter all lines from 10 on. After checking them out with a few test lines, make a save of them for merging with other programs. They may also be used on T/S Basic listings with BB in-residence. (Make a tape copy if your DOS MERGE function conflicts with BB line 0.) Add them to your main listing, then, after testing, key <reval> and <DELETE 1 TO 9> to remove these procedures for maximum free memory.

My name and address are:

Robert D. Hartung
2416 N. County Line Road
Huntertown, IN 46748

Please note that the version of Beta Basic used by permission of BetaSoft to drive the demo will NOT work with any other listings, and requires Spectrum mode. It may also be used as a tutorial when used with the normal version of BB 3.0.

BB HEADER

  1 LET rt=PEEK 23730+256*PEEK
23731
SAVE "Beta Basic" LINE 2
POKE PEEK 23631+256*PEEK 23
632+2,181
SAVE "BB"CODE rt+1,65367-rt
STOP
2 CLEAR rt
LOAD "BB"CODE
RANDOMIZE USR 58419
3 DPOKE 61081,46559
REM Actual value of rt+1,
not the expression
4 PRINT #0;"Printer: 2040 or
Centronics? "
PAUSE 0
LET p$=INKEY$
5 IF p$="2" THEN DPOKE 61081,
2548
ELSE INPUT "Left MARGIN set
(Up-arrow & your ESC seque
nce";m$
LPRINT m$
6 DELETE 1 TO 6

BB RESTART

 10 PRINT "Delay for SDOS VERIF
Y"
PAUSE 100
20 RANDOMIZE USR 58419
30 IF PEEK (DPEEK(23627)+32)<>
184 THEN GO TO 50
40 POKE DPEEK(23627)+32,65
POKE DPEEK(23627)+33,29
POKE DPEEK(23627)+34,0
DELETE a$
GO TO 30
REM Removes extra x,yos/rg
copies after BB re-start

REVAL_DEVAL

  1 DEF PROC reval
DPOKE 48804,10
LET a$=CHR$ 14+CHR$ 0+CHR
$ 0
get_p
DO
LET p=INSTRING(p,MEMORY
$()( TO DPEEK(23627)),a
$)
EXIT IF p=0
2 LET t$="",t=p
DO
LET t=t-1
LET p$=CHR$ PEEK t
EXIT IF p$<"0" OR p$>"9
"
LET t$=p$+t$
LOOP
3 IF LEN t$<>0 THEN PRINT
"ALTERing: ";t$
LET x=VAL t$
ALTER (x) TO "VAL "+C
HR$ 34+t$+CHR$ 34
4 LET p=p+1
LOOP
DPOKE 48804,i
END PROC
5 DEF PROC deval
DPOKE 48804,10
FOR s=1 TO 5
LET a$="VAL "+CHR$ 34+S
TRING$(s,"#")+CHR$ 34
get_p
6 DO
LET p=INSTRING(p,MEMO
RY$()( TO DPEEK(23627
)),a$)
EXIT IF p=0
LET t$=""
FOR n=0 TO s+2
LET t$=t$+CHR$ PEEK
(p+n)
NEXT n
7 LET x=VAL t$(3 TO 2+s
)
PRINT "ALTERing: ";t$
ALTER (t$) TO (x)
LET p=p+1
LOOP
8 NEXT s
DPOKE 48804,1
END PROC
9 DEF PROC get_p
LET p=DPEEK(23637)
END PROC

MAIL FILE

  1 REM Insert REVAL_DEVAL pro-
cedures here (lines 1-9)
10 PRINT "Delay for SDOS VERIF
Y"
PAUSE 100
20 RANDOMIZE USR 58419
30 IF PEEK (DPEEK(23627)+32)<>
184 THEN GO TO 50
40 POKE DPEEK(23627)+32,65
POKE DPEEK(23627)+33,29
POKE DPEEK(23627)+34,0
DELETE a$
GO TO 30
REM Removes extra x,yos/rg
copies after BB re-start
50 LET I=SGN PI,o=NOT PI,y$=""
,d$=""
60 CLS
GO TO 470
REM To main menu
70 INPUT "EDIT y/n? ";e$;" LPR
INT y/n? ";y$'"ID/phone nos
. y/n? ";d$
80 INPUT "CHR$ in search-word
(#=wild): ";c$
90 FOR n=I TO last
100 LET p$=f$(n)
110 IF INSTRING(I,p$,c$) THEN
fprint y$,f$(n),I,o
IF e$="y" THEN fedit f$
(n),last,I,o
120 NEXT n
130 PRINT #o;"Search is complet
e"
PAUSE 300
GO TO 470
140 REM INPUT
150 INPUT "ALL NEW & ERASE y/n?
";y$
IF y$<>"y" THEN GO TO 180
160 INPUT "Maximum no. of new e
ntries<150? ";E
IF E>150 THEN LET E=150
170 DIM f$(E,115)
180 FOR n=I TO E
190 IF f$(n,2)<>" " AND f$(n,
114)<>"#" THEN NEXT n
200 PRINT INVERSE I;n
INPUT " STOP 1Mr/Mrs 2Mr
3Mrs 4Ms 5Miss 6att: OR
9 then title or first nam
e ";p$
PRINT p$;
LET f$(n, TO 20)=p$,f$(n,
115)=CHR$ LEN p$
IF p$=" STOP " THEN LET f
$(n)=""
GO TO 290
210 INPUT (f$(n, TO 20))'"Las
t name"'f$(n,21 TO 40)'"A
ddress"'f$(n,41 TO 65)'"P
.O. or 1AUB, 2BUT, 3HNT"'
f$(n,66 TO 80)'"State (2
chrs+2 spaces) & ZIP"'f$(
n,81 TO 94)'"IDCODE OR ph
one no. TO re-enter"'f$(n
,95 TO 114)
220 IF f$(n,66)="1" THEN LET
f$(n,66 TO 80)="Auburn",f
$(n,81 TO 94)="IN 46706"
230 IF f$(n,66)="2" THEN LET
f$(n,66 TO 80)="Butler",f
$(n,81 TO 94)="IN 46721"
240 IF f$(n,66)="3" THEN LET
f$(n,66 TO 80)="Huntertow
n",f$(n,81 TO 94)="IN 46
748"
250 REM P.O. auto-entries he
re
260 PRINT " ";f$(n,21 TO 94)'
f$(n,95 TO 114)
270 IF f$(n,95)=" TO " THEN G
O TO 200
280 NEXT n
290 LET last=n-I
SORT f$(I TO last)(21 TO 40
)
GO TO 470
300 REM EDIT
310 CLS
320 FOR n=I TO last
330 fprint y$,f$(n),I,o
340 fedit f$(n),last,I,o
350 NEXT n
360 SORT f$(1 TO last)(21 TO 40
)
370 LET x=last
380 FOR n=x-z TO x
390 IF f$(n,21 TO 30)="zzzzzz
zzzz" THEN LET last=last-
I,f$(n)=""
400 NEXT n
410 GO TO 470
420 REM LPRINT
430 INPUT " PRINT ID/phone nos.
y/n? ";d$
LET y$="y"
440 FOR n=I TO last
450 fprint y$,f$(n),I,o
460 NEXT n
470 CLS
PRINT "1 - Start all new fi
le"'"2 - Add entries"'"3 -
List/edit"'"4 - Search/prin
t/edit"'"5 - LPRINT "'"6 -
SAVE "'"7 - LOAD "' FLASH I
'"B board OFF for SDOS"
480 PAUSE o
490 ON ERROR 470
LET p=VAL INKEY$
CLS
ON ERROR o
500 GO TO ON p;160,180,300,70,4
20,520,540
510 GO TO 470
520 CAT /
INPUT FLASH I;"B board ON";
FLASH o;" & enter SAVE name
: ";c$
RANDOMIZE USR 59904
SAVE /c$ LINE 10
530 GO TO 10
540 CAT /
INPUT "LOAD name? ";c$
RANDOMIZE USR 59904
LOAD /c$
550 GO TO 10
560 DEF PROC fprint y$, REF f$,
I,o
570 IF y$="y" THEN OPEN #2,"P
"
580 PRINT ("Attention of:" AN
D f$(n,I)="6")
REM Or other repeat titl
e
590 PRINT ("Mr. & Mrs." AND f
$(n,I)="1")+("Mr." AND f$
(n,I)="2")+("Mrs." AND f$
(n,I)="3")+("Ms." AND f$(
n,I)="4")+("Miss" AND f$(
n,I)="5")+(" " AND f$(n,I
)<"6");
600 PRINT f$(n,2 TO CODE f$(n
,115));" ";
610 PRINT f$(n,21 TO 40)
620 IF f$(n,41)<>" " THEN PRI
NT f$(n,41 TO 65)
630 IF f$(n,66)<>" " THEN PRI
NT f$(n,66 TO 80)
640 IF f$(n,81)<>" " THEN PRI
NT f$(n,81 TO 94)
650 IF d$="y" AND f$(n,95)<>"
" THEN PRINT f$(n,95 TO
114)
660 PRINT
670 CLOSE #2
680 IF y$="y" THEN PRINT #o;A
T o,o;"Any Key for next e
nvelope"
PAUSE o
INPUT ""
690 END PROC
700 DEF PROC fedit REF f$,last,
I,o
710 LET z=o
720 LET p$=f$(n)
730 INPUT "NL next, # DELETE,
TO Keep, STOP or space: "
;(f$(n, TO 20));TAB 9;d$
IF d$="" THEN GO TO 820
740 IF LEN d$>=2 THEN LET f$(
n, TO 20)=d$(2 TO ),f$(n,
115)=CHR$ LEN d$(2 TO )
750 IF d$=" STOP " THEN GO TO
360
760 IF d$="#" THEN LET f$(n,2
1 TO 40)="zzzzzzzzzz"
LET z=z+I
GO TO 820
770 EDIT f$(n,21 TO 40)
780 EDIT f$(n,41 TO 65)
790 EDIT f$(n,66 TO 80)
800 EDIT f$(n,81 TO 94)
810 EDIT f$(n,95 TO 114)
820 END PROC

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.