MScript Sort and Tasword to MScript Converter

Developer(s): Bob Mitchell
Date: 1990
Type: Program
Platform(s): TS 2068

Bob Mitchell wrote these two utilities for MScript users and compiled both with TIMACHINE. MScript Sort sorts a block of text saved from MScript: up to 200 lines of up to 64 characters, each ending in a carriage return. It shows the block in 64 columns, asks which column to sort on, sorts with a Shell-Faulk sort and shows the result, and can sort again on another column before saving the block for MScript to add back into the document. Mitchell’s help text gives a name, address and phone list as an example of data worth sorting.

The Tasword to MScript Converter (tas2ms, “tas>ms loader with para id”) turns a Tasword II file, stored as 64-character lines, into MScript text. It joins the lines, collapses runs of spaces and starts a new paragraph where a line begins with a space, then saves the result for MScript. Mitchell wrote about it in “Bob’s Notebook: Tasword to MScript converter” in Sinc-Link (Jan/Feb 1990).

The download has both programs as separate tapes, Mitchell’s help text for the sort, and the TIMACHINE compiler report for the converter, which lists the compiled entry points and variables. The source code field below includes the uncompiled BASIC that TIMACHINE turned into each code file.

Program Analysis

MScript Sort

The loader loads taswi.Cx, the 64-column print routine, at 63223 and the compiled sort at 29000. It loads the block at 47050 and calls USR 29000, which asks for the block length, copies the lines into d$(200,64), prints them with RANDOMIZE USR 64300 and runs the sort. The sort (lines 290–430 of the source) is a Shell sort with a gap that halves each pass and is made odd, comparing the slices d$(i,t TO ) from the chosen column. The program stores the length at 30939/30940 so the BASIC can save the sorted block.

Tasword to MScript Converter

The compiled code sits at 64671–65355, and its variables at 65356–65363. The first entry point asks for the file length and load address; the BASIC loads the Tasword file there and calls the second entry point at 64772. The source (8 lines) walks the file a byte at a time, writing to 46927: at each 64-byte line boundary it writes a carriage return if the line starts with a space, and otherwise a space, so that words are not run together.

Notable Techniques

  • Both programs use TIMACHINE REM ! directives (!INT, !USR, !LEN, ! OPEN #) to declare integer variables, the code address and string lengths.
  • The sort keeps its text in a string array and swaps whole rows, which is simple and fast once compiled.

Potential Issues

  • MScript Sort only sorts when the length you give runs past the final carriage return. If it ends exactly on the last one, the end of the data is never recorded and nothing is sorted; giving one byte more works.
  • The disk also has tas>ms.Bb, the version without paragraph detection, but its code file tas>ms.Cc is missing, so it is not included.

These programs came from the TTSUC Larken library disk L-51, “MSCRIPT SUPPORT DISK”. For tape, the LKDOS prefixes and the drive prompts were removed, “0=menu” now stops the program, and the converter’s loader does CLEAR 46900 first, so the stack stays clear of the code at the top of memory. Tested in ZEsarUX: a sample block was sorted, and a Tasword file was converted.

Image Gallery

Source Code

REM ===== mssort.Bb (loader, tape version) =====
   80 CLS : PRINT ''"  MSCRIPT SORT by Bob Mitchell."''"  Prior to using this utility,    SAVE the BLOCK to be sorted,    using the Mscript block         markers."
   82 PRINT '"  Calculate the length between    the block markers and have      this at hand."
   84 PRINT '"  This utility will sort up to    200 lines with max length of    64 chars. Each line must end    with a line feed (code 13)."
   92 INPUT "1=cont. 0=menu ";cm
   94 IF NOT cm THEN STOP 
  100 PAPER SGN PI: BORDER SGN PI: INK VAL "9": CLS : INPUT "MSCRIPT SORTBLOCK SAVE file name? (max 6) ", LINE n$
  105 GO SUB 530
  110 LOAD n$+".CM"CODE 47050
  120 ON ERR GO TO 550: RANDOMIZE USR VAL "29000": GO TO 500
  130 RANDOMIZE USR 29472
  500 CLS : BEEP SGN PI,VAL "10": INPUT "name for save? max 6 "; LINE s$
  505 GO SUB 530
  510 SAVE s$+".CM"CODE 47050,PEEK 30939+256*PEEK 30940
  520 CLS : PRINT "BLOCK saved; now load MSCRIPT   and LOAD relevant file. Delete  old BLOCK; use <ADD> to LOAD    new BLOCK.": STOP 
  530 ON ERR RESET 
  540 RETURN 
  550 PRINT CHR$ 2: GO TO 130
 1000 CLEAR : SAVE "mssort.Bb" LINE VAL "1020"
 1010 STOP 
 1020 REM  was LKDOS-only
 1030 LOAD "taswi.Cx"CODE 
 1040 LOAD "mssort.Cc"CODE 
 1050 POKE 23658,0: GO TO 80
REM ===== mssort.Bp (TIMACHINE source of mssort.Cc) =====
   50 REM ! LIST 
   60 REM ! LPRINT 
   70 REM !LEN h$<=66
   80 REM !INT +b,oa,ob,sf,a,n,i,j,s,ss,t
   90 REM !USR 29000
  100 REM ! OPEN #
  120 INPUT "length of BLOCK SAVE? <=12800"'b
  130 PRINT "Storing CODE in ARRAY"'' FLASH 1;"stand-by..."
  140 DIM d$(200,64)
  145 LET oa=1: LET ob=2: LET sf=64: LET a=47050
  150 LET s=oa
  160 LET n=s
  170 FOR i=a+1 TO a+b
  180 FOR j=1 TO 63
  190 LET d$(s,j)=CHR$ PEEK i
  195 IF PEEK i=13 THEN GO TO 210
  196 IF i=a+b THEN LET e=s-1: GO TO 240
  197 LET i=i+oa
  200 NEXT j
  210 LET s=s+oa
  220 NEXT i
  240 CLS : BEEP oa,VAL "10": RANDOMIZE USR 64300: FOR i=n TO s-1: PRINT CHR$ 3;d$(i): NEXT i
  245 REM ! OPEN #
  250 INPUT "1=sort 0=save? ";ss: IF NOT ss THEN GO TO VAL "440"
  255 INPUT "sort on which col.? (1-63) ";t
  260 CLS : PRINT "sorting on col. ";t'' FLASH 1;" stand-by...": GO SUB VAL "300": GO TO VAL "240"
  290 REM shell-faulk sort
  300 LET sn=e
  310 LET sn=INT (sn/ob)
  320 IF sn<oa THEN CLS : RETURN 
  330 IF sn/ob=INT (sn/ob) THEN LET sn=sn+oa
  340 FOR i=n TO e-sn
  350 LET mm=i
  360 IF d$(mm,t TO )<=d$(mm+sn,t TO ) THEN GO TO VAL "420"
  370 LET h$=d$(mm)
  380 LET d$(mm)=d$(mm+sn)
  390 LET d$(mm+sn)=h$
  400 LET mm=mm-sn
  410 IF mm>0 THEN GO TO VAL "360"
  420 NEXT i
  430 GO TO VAL "310"
  440 CLS : PRINT "storing sorted file for SAVE..."'' FLASH 1;" stand-by... ": LET s=n: POKE a,14: FOR i=a+1 TO a+b
  450 FOR j=SGN PI TO VAL "63"
  460 POKE i,CODE d$(s,j)
  465 IF CODE d$(s,j)=13 THEN GO TO 480
  466 IF i=a+b THEN STOP 
  468 LET i=i+oa
  470 NEXT j
  480 LET s=s+oa
  490 NEXT i
REM ===== tas2ms.Bb (loader, tape version) =====
   10 REM tas>ms loader
   20 REM with para id
  100 RANDOMIZE USR 64671
  200 LET addr=PEEK 65360+256*PEEK 65361
  210 INPUT "file name? (max6) "; LINE n$: LOAD n$+".CT"CODE addr
  220 RANDOMIZE USR 64772
  300 INPUT "file name for SAVE (max6) "; LINE n$
  305 LET len=PEEK 65356+256*PEEK 65357: LET len=len-46926
  310 SAVE n$+".CT"CODE 46927,len: STOP 
 9000 SAVE "tas2ms.Bb" LINE 9900: STOP 
 9900 CLEAR 46900: LOAD "tas2ms.Cc"CODE 
 9910 GO TO 10
REM ===== tas2ms.Bp (TIMACHINE source of tas2ms.Cc) =====
    1 REM ! LPRINT 
    2 REM !INT +j,tl,add,i
    3 REM ! LIST 
    4 REM ! OPEN #
    5 LET j=46927
    6 INPUT "tas len? ";tl
    7 INPUT "load tas file to addr? (>27500) ";add
    8 STOP 
    9 REM ! OPEN #
   10 FOR i=0 TO tl
   12 IF i/64=INT (i/64) AND PEEK (i+add)=32 THEN POKE j,13: LET j=j+1
   15 IF PEEK (i+add)=32 AND PEEK (i+add+1)=32 THEN GO TO 30
   18 IF i/64=INT (i/64) AND PEEK (i+add-1)<>32 THEN POKE j,32: LET j=j+1
   20 POKE j,PEEK (i+add): LET j=j+1
   30 NEXT i
   35 POKE j,0
   40 REM ! CLOSE #

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