If you have spent any time on a local Bulletin Board System, you will have certainly found the mighty, but humble, TS 2068 in the minority. I have had the occasion to offer BASIC programs to fulfill a few BBS users’ requests. However, Sinclair BASIC is incompatible with other computer BASICs. With the help of BASIC2text, one can upload a Sinclair BASIC program via MTERM II to another brand of computer. On the receiving end, the receiver can print out the text/program and key it into their computer, making needed alterations. Some computers can compile a text file into BASIC format, allowing some receivers to simply tailor the text file to their system requirements without having to key in the program.
Sinclair BASIC is stored in the machine using many control codes (number slugs, floating point numbers, line length, ect.) and single codes for Tokens (IF, THEN, GO TO, ect.). BASIC2text will remove any non-ASCII control codes and expand the Tokens to their full ASCII equivalents.
To use BASIC2text, first LOAD a BASIC program, set RAMTOP to 64900 (CLEAR 64899), then LOAD in the machine code version of BASIC2text (LOAD “BASIC2text”CODE 64900). BASIC2text is run in two separate steps. PRINT USR 64909 will move the actual BASIC program to high memory, allowing room to build the text file. When this step is complete, a message will appear on the screen prompting you to Press Any Key to reset memory. RAMTOP will be raised to 28416, protecting the area for the text file. The screen will black out and the copyright message will appear. The machine is now ready to translate the moved BASIC into a text file (use PRINT USR 65042). The program will now convert Sinclair BASIC to an ASCII text file starting at 28416. When the translation is complete, a message will appear on the screen providing information on the start of the text file and its length. Follow the prompts to SAVE a copy to tape. IMPORTANT NOTE: Both routines must be called with the PRINT USR…not the commonly used RANDOMIZE USR. This will insure that the messages will appear on the screen.
To send the text file via MTERM II, load MTERM’s buffer with the text file. I prefer to use LOADER IV. If the length of the text file is larger than the buffer area, it should be saved in two parts, allowing two smaller text files to be loaded and sent separately via MTERM.
BONUS: I have two different printer-drivers for a full-size printer, both of which do not faithfully reproduce a BASIC listing. By using the text file produced by BASIC2text, a faithful copy of the listing can be sent to a full-size printer. Set the driver’s margin to 32 characters wide, and use the following BASIC program to print it to your printer:
10 FOR X=start of text file TO
end of text file: LPRINT CHR$ PE
EK X;: NEXT X
ENTERING BASIC2text
In order to save space, I have not provided a BASIC program to install the machine code. If you have access to an assembler I would suggest enterign the program via the mnemonics. If you do not have and asembler or a favorite machine code loader use Listing 2, and enter the OP Code column in the DATA statement lines.
The author can provide a copy of this program on tape for $4.00 (includes shipping). Please send a check or money order to: Michael E. Carver, 1016 NE Tillamook, Portland, OR 97212. Please specify “BASIC2text”.
Listing 1
ROM CALLS
NEW equ 0D1D
PR_STRING equ 21DB
TO_TABLE equ 0098
PO_SEARCH equ 077C
K_SCAN equ 02B0 Listing 1
SYSTEM VARIABLES
PROG equ 5C53
VARS equ 5C4B
RAMTOP equ 5C82
ORIGIN equ FD84 (64900d)
Address Op Code Mnemonics Label Notes
;PROGRAM VARIABLES
FD84 00 Q_FLAG defb 00
FD85 0000 MOVED_BAS defw 0000 ;Address of moved BASIC
FD87 0000 MOVED_END defw 0000 ;end of moved BASIC
FD89 0000 BAS_LENG defw 0000 ;length of BASIC
FD8B 0000 T_FILE defw 0000 ;current pointer in Text
;file
;Enter here to move BASIC
;Call via PRINT USR 64909
FD8D ED4B535C MOVE_BASIC ld bc,(PROG)
FD91 2A4B5C ld hl,(VARS)
FD94 ED42 sbc hl,bc ;find length of
FD96 23 inc hl ;BASIC program
FD97 23 inc hl
FD98 E5 push hl
FD99 C1 pop bc ;Program length
FD9A ED4389FD ld (BAS_LENG),bc
FD9E ED5BB25C ld de,(RAMTOP)
FDA2 ED5387FD ld (MOVED_END),de ;end of moved
FDA6 2A4B5C ld hl,(VARS) ;BASIC
FDA9 EDB8 lddr ;Move BASIC
FDAB 13 inc de
FDAC ED5385FD ld (MOVED_BAS),de ;start of moved
;Reset RAMTOP and NEW System BASIC
FDB0 11D8FD ld de,MOVED_MSG
FDB3 013A00 ld bc,003A ;message length
FDB6 CDDB21 call PR_STRING ;Print Message
FDB9 CDB002 WAIT call K_SCAN ;Wait until no
FDBC 7B ld a,e ;key is pressed
FDBD FEFF cp FF
FDBF 20F8 jr nz,WAIT
FDC1 7A ld a,d
FDC2 FEFF cp FF
FDC4 20F3 jr nz,WAIT
FDC6 CDB002 NO_KEY call K_SCAN ;Wait until a
FDC9 7B ld a,e ;key is pressed
FDCA FEFF cp FF
FDCC 28F8 jr z,NO_KEY
FDCE 11006F ld de,6F00 ;New RAMTOP
FDD1 ED53B25C ld (RAMTOP),de
FDD5 CD1D0D call NEW ;Reset Memory
FDD8 160000 MOVED_MSG defb 16,00,00 ;PRINT AT 0,0;
FDDB 424153494320 defm "BASIC "
FDE1 68617320 defm "has "
FDE5 6265656E20 defm "been "
FDEA 6D6F7665642E20 defm "moved. "
FDF1 160200 defb 16,02,00 ;PRINT AT 2,0;
FDF4 505245535320 defm "PRESS "
FDFA 414E5920 defm "ANY "
FDFE 4B455920 defm "KEY "
FE02 544F20 defm "TO "
FE05 434C45415220 defm "CLEAR "
FE0B 4D454D4F52592E defm "MEMORY."
;Program to translate the moved BASIC to text file
;Call via PRINT USR 65042
FE12 2AB25C SET_UP ld hl,(RAMTOP)
FE15 228BFD ld (T_FILE),hl
FE18 2184FD ld hl,QFLAG ;program flags
FE1B 3600 ld (hl),00 ;Clear flags
FE1D 2A85FD START ld hl,(MOVED_BAS)
FE20 56 LINE_NO ld d,(hl)
FE21 23 inc hl
FE22 5E ld e,(hl)
FE23 23 inc hl
FE24 23 inc hl ;skip length of
FE25 23 inc hl ;line
FE26 E5 push hl
FE27 E5 push hl
FE28 C1 pop bc
FE29 2A87FD ld hl,(MOVED_END) ;check for end
FE2C AF xor a ;of BASIC
FE2D ED42 sbc hl,bc
FE2F D2AEFE jp nc,NOT_DONE
FE32 E1 pop hl
FE33 1176FE DONE ld de,SAVE_MSG
FE36 013700 ld bc,0037 ;message length
FE39 CDDB21 call PR_STRING
FE3C 2A8BFD ld hl,(T_FILE)
FE3F 11006F ld de,6D84 ;Text file Start
FE42 ED52 sbc hl,de ;# of bytes in
FE44 2B dec hl ;text file
FE45 111027 ld de,2710 ;10000d
FE48 CD69FE call CONVERT ;to decimal
FE4B 11E803 ld de,03E8 ;1000d
FE4E CD69FE call CONVERT
FE51 116400 ld de,0064 ;100d
FE54 CD69FE call CONVERT
FE57 110A00 ld de,000A ;10d
FE5A CD69FE call CONVERT
FE5D 110100 ld de,0001
FE60 CD69FE call CONVERT
FE63 3EFD ld a,FD ;lower screen
FE65 CD3012 call 1230 ;for output
FE68 C9 ret
FE69 AF CONVERT xor a
FE6A 3C COUNT inc a
FE6B ED52 sbc hl,de
FE6D 3802 jr c,PR_LENGTH
FE6F 18F9 jr COUNT
FE71 19 PR_LENGTH add hl,de
FE72 C62F add a,2F ;obtain CHR$ code
FE74 D7 rst 10
FE75 C9 ret
FE76 1600 SAVE_MSG defb 16,00,00 ;PRINT AT 0,0;
FE78 00 nop
FE79 546F207361766520 defm "To save "
FE81 424153494320 defm "BASIC "
FE87 6173207465787420 defm "as text "
FE8F 66696C653A defm "file:"
FE94 0D0D defb 0D,0D ;linefeed " " "
FE96 5341564520 defm "SAVE "
FE9B 226E616D652220 defm ""name""
FEA2 434f444520 defm "CODE "
FEA7 32383431362C defm "28416,"
FEAD 00 nop
FEAE EB NOT_DONE ex de,hl ;convert line #
FEAF 1E20 ld e,20 ;to decimal
FEB1 01E803 ld bc,03E8 ;1000d
FEB4 CDB6FF call OUT_SP_NO
FEB7 016400 ld bc,0064 ;100d
FEBA CDB6FF call OUT_SP_NO
FEBD 010A00 ld bc,000A ;10d
FEC0 CDB6FF call OUT_SP_NO
FEC3 7D ld a,l
FEC4 FE20 cp 20 ;space
FEC6 2802 jr z,STORE
FEC8 C630 add a,30 ;obtain CHR$ code
FECA CDC9FF STORE call STORE_CHAR
FECD E1 BODY pop hl
FECE 7E ld a,(hl)
FECF 23 inc hl
FED0 E5 push hl
FED1 FE22 cp 22 ;Quotes
FED3 200A jr nz,ENTER
FED5 F5 push af
FED6 3A84FD ld a,(QFLAG)
FED9 EE01 xor 01 ;Toggle Quotes
FEDB 3284FD ld (QFLAG),a ;flag
FEDE F1 pop af
FEDF FE0D ENTER cp 0D ;ENTER
FEE1 2817 jr z,ASCII
FEE3 FE0E cp 0E ;Number Slug
FEE5 2009 jr nz,NOT_SLUG
FEE7 E1 pop hl ;BASIC Pointer
FEE8 010500 ld bc,0005 ;skip floating
FEEB ED4A adc hl,bc ;point number
FEED E5 push hl
FEEE 18DD jr BODY
FEF0 FE20 NOT_SLUG cp 20 ;Control Code?
FEF2 3002 jr nc,PRINTABLE
FEF4 18D7 jr BODY
FEF6 FE7B PRINTABLE cp 7B ;ASCII?
FEF8 302A jr nc,NONASCII
FEFA F5 ASCII push af
FEFB 3A84FD ld a,(QFLAG)
FEFE CB8F res 1,a ;Reset Token flag
FF00 3284FD ld (QFLAG),a
FF03 F1 pop af
FF04 FE0D cp 0D ;If Enter
FF06 CC19FF call z,UNREM ;reset REM flag
FF09 FE3A cp 3A ;If :
FF0B CC19FF call z,UNREM ;reset REM flag
FF0E CDC9FF call STORE_CHAR
FF11 FE0D cp 0D ;Enter?
FF13 20B8 jr nz,BODY
FF15 E1 pop hl
FF16 C320FE jp LINE_NO
FF19 F5 UNREM push af
FF1A 3A84FD ld a,(QFLAG)
FF1D CB97 res 2,a ;REM flag
FF1F 3284FD ld (QFLAG),a
FF22 F1 pop af
FF23 C9 ret
FF24 FE80 NONASCII cp 80 ;Block Graphics?
FF26 301D jr nc,BLOCK_GRAPHC
FF28 FE7C cp 7C ;STICK?
FF2A 280F jr z,EXPAND
FF2C FE7E cp 7E ;FREE
FF2E 280B jr z,EXPAND
FF30 2184FD ld hl,QFLAG
FF33 CB46 bit 0,(hl) ;Quotes flag?
FF35 20C3 jr nz,ASCII
FF37 CB56 bit 2,(hl) ;REM flag?
FF39 20BF jr nz,ASCII
FF3B D61F EXPAND sub 1F ;Offset
FF3D CD77FF call TOKENS_1
FF40 CD6EFF call TOKEN_FLAG
FF43 1888 jr BODY
FF45 FE90 BLOCK_GRAPH cp 90 ;User graphics?
FF47 3004 jr nc,GRAPHICS
FF49 3E20 ld a,20 ;Space
FF4B 18AD jr ASCII
FF4D FEA5 GRAPHICS cp A5 ;User graphics?
FF4F 3004 jr nc,TOKENS
FF51 D64F sub 4F ;Make ASCII
FF53 18A5 jr ASCII
FF55 FEEA TOKENS cp EA ;REM
FF57 200A jr nz,NOT_REM
FF59 F5 push af
FF5A 3A84FD ld a,(QFLAG)
FF5D CBD7 set 2,a ;Set REM flag
FF5F 3284FD ld (QFLAG),a
FF62 F1 pop af
FF63 D6A5 NOT_REM sub A5
FF65 CD77FF call TOKENS_1
FF68 CD6EFF call TOKEN_FLAG
FF6B C3CDFE jp BODY
FF6E 3A84FD TOKEN_FLAG ld a,(QFLAG)
FF71 CBCF set 1,a ;Set Token flag
FF73 3284FD ld (QFLAG),a
FF76 C9 ret
FF77 119800 TOKENS_1 ld de,TO_TABLE ;base address of
FF7A F5 push af ;Token Table
FF7B CD7C07 PO_TABLE call PO_SEARCH ;find Token in
FF7E 380C jr c,PO_EACH ;table and store
FF80 3A84FD ld a,(QFLAG)
FF83 CB4F bit 1,a ;Token flag set?
FF85 2005 jr nz,PO_EACH ;Print space
FF87 3E20 ld a,20 ;if needed
FF89 CDA5FF call PO_SAVE
FF8C 1A PO_EACH ld a,(de) ;cancel any
FF8D E67F and 7F ;inverted bits
FF8F CDA5FF call PO_SAVE
FF92 1A ld a,(de)
FF93 13 inc de
FF94 87 add a,a ;if inverted
FF95 30F5 jr nc,PO_EACH ;end of Token
FF97 D1 pop de ;trailing space?
FF98 FE48 cp 48
FF9A 2803 jr z,PO_TRSP
FF9C FE82 cp 82
FF9E D8 ret c
FF9F 7A PO_TRSP ld a,d
FFA0 FE03 cp 03
FFA2 D8 ret c
FFA3 3E20 ld a,20 ;Print trailing
FFA5 D5 PO_SAVE push de ;space
FFA6 D9 exx
FFA7 CDC9FF call STORE_CHAR
FFAA D9 exx
FFAB D1 pop de
FFAC C9 ret
FFAD 7B OUT_SP_2 ld a,e
FFAE FEFF cp FF
FFB0 200E jr nz,PR_DIGIT
FFB2 3E00 ld a,00
FFB4 180A jr PR_DIGIT
FFB6 AF OUT_SP_NO xor a ;Print line #
FFB7 ED42 OUT_SP_1 sbc hl,bc ;as decimal
FFB9 3C inc a
FFBA 30FB jr nc,OUT_SP_1
FFBC 09 add hl,bc
FFBD 3D dec a
FFBE 28ED jr z,OUT_SP_2
FFC0 FE20 PR_DIGIT cp 20 ;Space
FFC2 2805 jr z,STORE_CHAR
FFC4 C630 add a,30 ;Obtain CHR$ code
FFC6 11FF00 ld de,00FF
FFC9 E5 STORE_CHAR push hl
FFCA 2A8BFD ld hl,(T_FILE)
FFCD 77 ld (hl),a
FFCE 23 inc hl
FFCF 228BFD ld (T_FILE),hl
FFD2 E1 pop hl
FFD3 C9 ret
NOTE: Code from FF77 - FFC6 has been borrowed from the ROM
which handles LLIST with necessary changes for present program.
Listing 2
9000 CLEAR 64899: LET a$="": RES
TORE : FOR i=0 TO 73: READ d$: L
ET a$=a$+d$: NEXT i
9010 IF LEN a$<>1184 THEN PRINT
FLASH 1;"Error in Machine Code D
ATA Lines 9925-9998"''"Plea
se correct before continuing": S
TOP
9020 LET address=64900: FOR i=1
TO LEN a$-1 STEP 2
9030 POKE address+INT ((i-1)/2),
(CODE a$(i)-(48 AND CODE a$(i)<5
8)-(55 AND CODE a$(i)>64))*16+CO
DE a$(i+1)-(48 AND CODE a$(i+1)<
58)-(55 AND CODE a$(i+1)>64)
9040 NEXT i
9050 CLS : PRINT "Machine Code h
as been Loaded into memory."'
'"Press any key to SAVE & VERIFY
BASIC2text": PAUSE 0: SAVE "BA
SIC2text"CODE 64900,592: CLS : P
RINT "Rewind and play tape to Ve
rify": VERIFY "BASIC2text"CODE 6
4900,592
9925 DATA "0000000000000000"
9926 DATA "00ED4B535C2A4B5C"
9927 DATA "ED422323E5C1ED43"
. . .Continue this pattern using Line numbers 9928-9997 in increments of 1. . .
9998 DATA "FD7723228BFDE1C9"
Media
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.