        USING "LEVEL II ONLY" BASIC PROGRAMS WITH DISK

          Utility software by Roxton Baker / 1979


BACKGROUND

    The TRS-80 Disk Basic includes all of the Level II Basic commands and
features, but there remain some incompatibilities between the two that may
prevent you from running a Level II Basic program from disk.  Usually this
happens with programs using PEEK, POKE, and the USR function, and results from
the fact that Disk Basic puts its programs about 10K bytes higher in memory
than Level II does.  Level II programs that rely on using specific high-memory
locations for data or machine code are likely to write over themselves when
run under Disk Basic.  Or the Level II program may use a reserved disk command
such as NAME for its own purposes, thus becoming incompatible with some Disk
Basics.  Program authors could anticipate and avoid these problems, but they
rarely do.  It is also rare to see such incompatibilities mentioned in the
ads.  Examples of Level II Basic programs that will not work under Disk Basic
are Ultra Trek, Parsector V, X-Wing II, Tiny Comp and Clone 2.  There are many
others.  Such programs can be converted to run under Disk Basic by reassigning
the PEEK and POKE locations, redefining the USR calls, and disassembling and
relocating the machine code as necessary - a great deal of work.  A less
elegant but much easier approach is to save the Level II program on disk in
such a way that it actually runs under Level II Basic rather than Disk Basic.
The utility program TWODISK presented here will do exactly that with any 16K
(or less) Level II program.  TWODISK requires a 48K system to work in.


CREATING TWODISK/CMD

    One way to create TWODISK/CMD is to enter the Basic program of Fig. 1,
using a Memory Size of 65345.  Check it carefully and run it.  A "BAD
CHECKSUM" message indicates an error in the DATA statements.  When it runs
properly SAVE it to disk and then go to DOS with CMD"S" and type:

DUMP TWODISK/CMD (START=X'FF41',END=X'FFF9',TRA=X'FF69') <ENTER>

Do not omit the required two blanks: one after DUMP and one after /CMD.  You
will now be ready to use TWODISK as described below.

Another way to create the program is to assemble the source code shown in Fig.
2 with a disk-based editor-assembler.  An examination of this source code will
reveal how TWODISK works.  First it block-moves the Level II program and its
environment from 4000H+ up to 8012H+.  If any SYSTEM tape code has been
loaded, that is moved as well.  Then a downward block-move routine is placed
at 8000H-8011H which will restore the Level II program to its proper location
and jump into Level II to execute it.  The DUMP command is then used to place
the block of code from 8000H up to the end of the Level II program code onto
disk as PROG2/CMD.


USING TWODISK/CMD

    Assume that you have one of these incompatible Level II Basic programs on
tape.  It may have a SYSTEM tape part as well.  You wish to put this program
on disk and run it from disk in the future.  You have TWODISK/CMD on a disk
with at least 14 grans of free space.  Follow this procedure exactly, in the
sequence indicated.  Starting at DOS READY type in:

               LOAD TWODISK/CMD   <ENTER>

Then type   BASIC2  <ENTER>   to go into Level II.  Set Memory Size to 65345
or lower if required by the Basic program to be put on disk.  Now CLOAD the
Basic program from tape.  If it has a SYSTEM part load that as well, after the
Basic program.  You may list the Basic program, but since it may be
self-modifying don't run it.  With the Level II program, including any SYSTEM
part, completely loaded type:

                    SYSTEM  <ENTER>
                    /65345  <ENTER>

Note that you must use 65345 here even if you actually set a lower memory size
above.  The disk drive will run and you will be returned to DOS READY.  Now
type  TWODISK  <ENTER>.  The Level II program (and its SYSTEM code, if any)
will be written onto the disk as PROG2/CMD.  To run this program from disk you
need only type  PROG2  <ENTER>  .  The program will load from the disk and
jump into Level II from which you can RUN it.  Actually, you should use RENAME
to give PROG2/CMD a more appropriate title and to prevent it from being
overwritten in the future by TWODISK.  Retain the /CMD extension, however.
The Level II program, once on disk, is self-contained and does not require
TWODISK to run.  It might not, however, run in a 32K disk system - see below.


CUTTING PROGRAM SIZE

    Although TWODISK does automatically handle the case where the Level II
program has a SYSTEM tape part, it does this by saving off all of the lower
16K of memory, from 4000H to 7FFFH.  It must do this because it cannot tell
where the SYSTEM code resides.  This procedure is often justified because many
Level II SYSTEM routines do go at the top of 16K.  However, this results in a
14 gran disk file.  It also means that the resulting file PROG2/CMD will not
run in a 32K system  - it's about twelve bytes too long.  You may avoid this
problem by saving the Level II program to disk in two parts.  First use
TWODISK as above to save the Basic part of the program to disk, without
loading the SYSTEM part.  Do set the appropriate Memory Size, though.  Then
use TAPEDISK, LMOFFSET, TDISK, or any other tape-to-disk utility to put the
SYSTEM code on disk, giving it the name SYSCODE/OBJ for example.  To run this
combination of programs, LOAD SYSCODE/OBJ from DOS and then execute PROG2/CMD.



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 REM  MEMORY SIZE MUST BE 65345
20 FOR J=0 TO 184
30 READ D
40 POKE -191+J,D
50 CK=CK+D
60 NEXT J
70 IF CK<>19583 THEN PRINT"BAD CHECKSUM"
80 END
90 DATA 33,232,66,237,91,223,64,205,144,28,40,5,1,255
100 DATA 63,24,8,237,75,249,64,120,214,64,71,237,67,250
110 DATA 255,33,0,64,17,18,128,237,176,195,0,0,42,250
120 DATA 255,34,234,255,6,18,17,232,255,33,0,128,205
130 DATA 215,9,42,250,255,43,17,18,128,25,76,205,152
140 DATA 255,237,83,213,255,77,205,152,255,237,83,215
150 DATA 255,33,177,255,195,5,68,121,205,167,255,87,121
160 DATA 15,15,15,15,205,167,255,95,201,230,15,246,48
170 DATA 254,58,216,198,7,201,68,85,77,80,32,80,82,79
180 DATA 71,50,47,67,77,68,32,40,83,84,65,82,84,61,88
190 DATA 39,56,48,48,48,39,44,69,78,68,61,88,39,88,88
200 DATA 88,88,39,44,84,82,65,61,88,39,56,48,48,48,39
210 DATA 41,13,243,1,0,0,17,0,64,33,18,128,237,176,49
220 DATA 136,66,195,204,6

     Fig. 1:  Basic program to create TWODISK/CMD
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

00010 ;  PROGRAM TWODISK   by Roxton Baker
00020 ;
00030 LEVEL2  EQU     06CCH           ;ENTER LEVEL II NICELY
00040 DOSRET  EQU     402DH           ;RETURN TO DOS
00050 CMDBUF  EQU     4318H           ;DOS COMMAND BUFFER
00060 SYSADD  EQU     40DFH           ;HOLDS SYSTEM TAPE ENTRY
00070 CMHLDE  EQU     1C90H           ;ROM COMPARES HL,DE
00080 EPROGP  EQU     40F9H           ;POINTS TO END BASIC PROG
00090 BOTTOM  EQU     4000H           ;START OF MEM TO SAVE
00100 BMOVE   EQU     09D7H           ;MOVES B BYTES
00110 CMDINT  EQU     4405H           ;DOS COMMAND INTERPRETER
00120 P2ENTR  EQU     8000H           ;ENTRY POINT PROG2/CMD
00130 SAFETY  EQU     P2ENTR+18       ;WHERE LEVEL II PROG HELD
00140 ;
00150 START   EQU     0FF41H          ;DEC. EQUIV. IS 65345.
00160         ORG     START           ;  (EASY TO TYPE)
00170 ;
00180 L2ENTR  LD      HL,42E8H        ;ENTRY FROM LEVEL II.
00190         LD      DE,(SYSADD)     ;SEE IF SYSTEM TAPE WAS
00200         CALL    CMHLDE          ;  LOADED UNDER LEVEL II.
00210         JR      Z,BONLY         ;IF HL=DE, NO SYSTEM TAPE
00220         LD      BC,3FFFH        ;IF ONE WAS, WE MUST SAVE
00230         JR      MOVEUP          ;  MEM FROM 4000 TO 7FFF.
00240 ;
00250 BONLY   LD      BC,(EPROGP)     ;ELSE FIND END OF LEVEL
00260         LD      A,B             ;  II PROGRAM,
00270         SUB     40H             ;AND GET DIFF FROM 4000
00280         LD      B,A             ;  IN BC.
00290 ;
00300 MOVEUP  LD      (TSTORE),BC     ;SAVE #BYTES TO MOVE
00310         LD      HL,BOTTOM       ;  FROM 4000+.
00320         LD      DE,SAFETY       ;WHERE PROG WILL BE HELD.
00330         LDIR                    ;SLIDE IT UP THERE.
00340         JP      0               ;HAVING MOVED LEVEL II
00350                                 ;  STUFF TO SAFETY, BOOT
00360                                 ;  THE DOS.
00370 ;
00380 DCODE   LD      HL,(TSTORE)     ;RETRIEVE #BYTES MOVED
00390         LD      (BYTNUM),HL     ;PUT IN MOVEDOWN CODE
00400         LD      B,12H           ;NOW SLIDE MOVEDOWN CODE
00410         LD      DE,MVDNCD       ;  DOWN INTO PLACE AT
00420         LD      HL,P2ENTR       ;  P2ENTR+.
00430         CALL    BMOVE
00440 ;
00450         LD      HL,(TSTORE)     ;CALC END ADDRESS, AND
00460         DEC     HL              ;  PUT ASCII IN DUMP CMD.
00470         LD      DE,SAFETY
00480         ADD     HL,DE           ;GETS END ADDRESS IN HL.
00490         LD      C,H
00500         CALL    ASCII           ;CONVERT H TO 2 ASCII'S
00510         LD      (DMP2),DE       ;  AND PUT IN COMMAND.
00520         LD      C,L             ;DO THE SAME WITH L.
00530         CALL    ASCII
00540         LD      (DMP2+2),DE
00550         LD      HL,DMPCMD       ;NOW POINT TO COMMAND
00560         JP      CMDINT          ;  AND EXECUTE IT.
00570 ;
00580 ;
00590 ASCII   LD      A,C             ;RETURNS ASCII OF C IN ED
00600         CALL    SBR1
00610         LD      D,A
00620         LD      A,C
00630         RRCA                    ;GET NEXT DIGIT
00640         RRCA
00650         RRCA
00660         RRCA
00670         CALL    SBR1
00680         LD      E,A             ;DONE WITH BOTH DIGITS.
00690         RET
00700 ;
00710 SBR1    AND     0FH             ;CALLED BY ASCII.
00720         OR      30H
00730         CP      3AH
00740         RET     C
00750         ADD     A,07
00760         RET
00770 ;
00780 ; THIS IS THE DUMP COMMAND STRING
00790 DMPCMD  DEFM    'DUMP PROG2/CMD (START=X'
00800         DEFB    '''
00810         DEFM    '8000'
00820         DEFB    '''
00830         DEFM    ',END=X'
00840         DEFB    '''
00850 DMP2    DEFM    'XXXX'
00860         DEFB    '''
00870         DEFM    ',TRA=X'
00880         DEFB    '''
00890         DEFM    '8000'
00900         DEFB    '''
00910         DEFB    ')'
00920         DEFB    0DH
00930 ;
00940 MVDNCD  DI
00950         LD      BC,0000         ;#BYTES TO MOVE (LATER).
00960         LD      DE,BOTTOM       ;START PUTTING IT HERE.
00970         LD      HL,SAFETY       ;FROM WHERE IT WAS HELD.
00980         LDIR
00990         LD      SP,4288H        ;WHERE SYSTEM PUTS STACK.
01000         JP      LEVEL2          ;JUMP INTO LEVEL II.
01010 ;
01020 ;
01030 BYTNUM  EQU     MVDNCD+2
01040 TSTORE  EQU     MVDNCD+18
01050 ;
01060         END     DCODE           ;DCODE IS ENTRY FROM DOS

         Fig. 2:  Source code for TWODISK/CMD
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -