BSORT/MOD324 - Copyright 1984 MISOSYS., Inc. All rights reserved MOD324 MOD324 is a utility designed to aid in converting programs created under MODEL III BASIC to MODEL 4 BASIC. The MODEL III program must be contained on a diskette formatted by either MODEL 4 TRSDOS/LS-DOS or MODEL III LDOS (use CONV to move the program from a MODEL III TRSDOS diskette to a MODEL 4 TRSDOS/LS-DOS diskette). The following syntax is used (from the DOS Ready level) to perform a conversion: MOD324 filespec1 filespec2 (parm,...,parm) filespec1 MODEL III program to convert. Must be "Saved" in compressed format. If not specified, it will be prompted for. filespec2 File to contain the converted program. If it does not exist, the file will be created. If it exists, the previous contents of the file will be overwritten. If not specified, it will be prompted for. When specified on the on the command line, it must appear after filespec1 Optional parameters are as follows: MODIFY Adjust numeric constants in PRINT@ statements to the corresponding value (absolute row and column position) on the MODEL 4 video. CENTER=n Additional offset value which is added to all PRINT@ positions changed by MODIFY. Will work only if MODIFY is specified. Will also offset numeric constants in PRINT TAB statements according to the column position of the value entered. Default is 328. (4 lines, 8 columns) PRINT Send output of possible manual corrections to the printer. If not specified, output will be to video. WIDTH=n Can be used only if PRINT is specified. Will determine the maximum number of characters to PRINT per line. Default is 80. abbr: All parameters may be abbreviated to their first character. I M P 0 R T A N T N 0 T I C E MOD324 is designed to be used as an aid in converting programs which are currently running on the MODEL III to a format that can be read by the MODEL 4. Some program commands and sequences which function error free on the MODEL III will NOT work on the MODEL 4. Every attempt is made by MOD324 to flag possible error situations that could result. However, there is NO GUARANTEE (implied or otherwise stated) that a program converted by MOD324 will work, even if no "Manual corrections" were indicated. Program Description MOD324 can be used to convert MODEL III programs to a form that can be read by MODEL 4 BASIC. The MODEL III program must be stored in "compressed format" (i.e. it should NOT have been saved in ASCII). MOD324 will create an ASCII file containing many of the necessary changes to allow the program to be run under MODEL 4 BASIC. Some of the conversions that will take place are:. 1. All "Tokenized" key words and symbols found in the MODEL III program will be changed to the corresponding ASCII representation of the key word/symbol in the MODEL 4 file. 2. Spaces will be inserted into the MODEL 4 text where needed. This includes inserting a space after non-function key words (i.e. those that contain no information within parentheses, such as FOR, TO, NEXT), and after variables/constants which precede a key word, and are not separated from the key word by a terminator (e.g. in the sequence IF A%=10THEN A%=5, a space would be inserted between the <0> of 10 and the of THEN). 3. Any value used in conjunction with a CLEAR statement will be "stripped off". For example, if the statement CLEAR 5000 appeared in the MODEL III program, the resulting statement in the MODEL 4 text would be CLEAR (the function of the CLEAR statement is entirely different on the MODEL 4). 4. Numeric constants used with PRINT@ and PRINT TAB will be adjusted to a corresponding print "position" on the MODEL 4 (if the MODIFY parameter is specified). There are cases in which no conversions will take place. Any information which appears in the MODEL III program file as ASCII will be left as is. No alterations will be made to either information appearing within quotes, or information following a "Tokenized" REM statement (i.e. the apostrophe character). Aside from the program conversions that are required, other problems may arise when converting a MODEL III program to run on the MODEL 4. One such source of difficulty is with program statements that exist in MODEL III BASIC but have no meaning on the MODEL 4. Another consideration is in program statements which exist in both BASICs but function differently for one reason or another. Although "translation" of these types of commands would be difficult (if not impossible), MOD324 does provide feedback (i.e. output to the video or printer) on commands that could pose a problem if used with MODEL 4 BASIC. The following is a list of MODEL III commands that will be "flagged" by MOD324 as possibly needing manual correction. CLOAD POINT CMD POS CSAVE PRINT@ ERR PRINT TAB IF (when not followed by THEN) PRINT #-1 , PRINT #-2 INP RESET INPUT #-1 , INPUT #-2 SET NAME SYSTEM OUT TIME$ PEEK USR POKE PRINT statements (in particular PRINT@ and PRINT TAB) receive special consideration when encountered by MOD324. Although these commands are accepted by MODEL 4 BASIC, video output can cause a problem, since the video sizes differ (64x16 vs. 80x24). For this reason, any occurrence of PRINT@ and PRINT TAB statements will be flagged. There are provisions for MOD324 to adjust values associated with these PRINT statements. Refer to the information on the MODIFY and CENTER parameters for further details. The last situation which will be flagged by MOD324 is when the resulting conversion would cause a program line to exceed the maximum line length. Due to the "expansion" of key words and the insertion of spaces, a MODEL III program line could be converted into a line which is greater than 254 characters (the maximum line length in MODEL 4 BASIC). When this type of situation occurs, the line will be truncated, and any information in the original program line that could not be saved to the MODEL 4 program file would be displayed on the video (or sent to the printer). In this case, a new line will need to be added to the MODEL 4 program, incorporating the "Lost" information. Note: Program logic may be affected by the truncation of a line. Program Usage To perform a program conversion, all that is required is to enter at the DOS Ready level. The following prompts to appear (one at a time). Input Filespec? Output Filespec? Pressing in response to either prompt will cause a return to DOS Ready. Any error encountered while answering these prompts (e.g. File not in directory or Write protected disk) will cause the appropriate error message to be displayed, after which the same prompt will re-appear. All entries must follow the rules associated with valid filespecs. The first prompt is for the name of the MODEL III program. Answer this prompt by entering the associated filespec. If a drivespec is not used, a global search of all active drives will be performed. Please note that if the file has an extension, the extension must be specified (i.e. /BAS is NOT assumed). The second prompt is for the name of the file which will contain the converted program. If the filespec entered does not exist, it will be created. If the filespec does exist, any information previously contained in the file will be overwritten by the converted program text. It is recommended that a drivespec be included with the output filespec, to assure that the file is written to the proper place. If a drivespec is not entered, the output file will be written to either the "first" drive containing the file, or to the first available drive if the file does not exist on any drive in the system. Both filespecs may be entered on the command line. For example, if the MODEL 4 program TEST/M4 is to be created (on drive 2) from the MODEL III program TEST/BAS (on drive 1), the following command could be entered. MOD324 TEST/BAS:1 TEST/M4:2 If only one filespec appears on the command line, it will represent the input filespec, and a prompt will appear for the output filespec. To see the results of performing a conversion, assume that the following program has been created by MODEL III BASIC, and was saved in compressed form using the filespec SAMPLE/BAS. 10 CLEAR5000:DEFINTA-N:DEFSTRS,T 20 CLS:FORL=1TO10 30 PRINTTAB(5)"This is Line";L;"on the MOD III video";TAB(45)"Position 45" 40 NEXT L It is desired to "convert" this program for use on the MODEL 4. The name of the file to contain the converted program is SAMPLE/M4 on drive 2. The following command may be entered to accomplish this. MOD324 SAMPLE/BAS SAMPLE/M4:2 Two results will occur from the above command. An ASCII file containing the converted program will be created, and feedback for possible manual program corrections (if any) will be given. The first consideration is the program file that is created. The following is a listing of the file SAMPLE/M4. 10 CLEAR:DEFINT A-N:DEFSTR S,T 20 CLS:FOR L=1 TO 10 30 PRINT TAB(5)"This is Line";L;"on the MOD III video";TAB(45)"Position 45" 40 NEXT L One point to draw from this listing is the insertion of spaces. Spaces will be inserted as needed. This is clearly illustrated in Lines 10, 20 and 30. Note that in Line 40 no space was added, since one already existed (between the of NEXT and the variable L). Of additional interest is the resulting CLEAR statement in Line 10. Since the value associated with a MODEL 4 CLEAR statement does not dictate the amount of string space to allocate, any value following a CLEAR statement will be stripped. In terms of the feedback given (of possible manual corrections), the following information would appear on the video as a result of the conversion performed. The following lines may need manual correction: 30 TAB,TAB File output completed Any "flagged" key word (see the list on Page 2) that appears in the program will be displayed as the output file is being created. The number of the line containing a flagged key word will be displayed, followed by the key words in question. If multiple key words are flagged on a line, they will be separated by commas. In this example, the key words PRINT TAB appeared twice in Line 30. Note that when TAB appears in a manual correction listing, it is taken to be associated with a PRINT TAB sequence. If TAB is used with an LPRINT statement, no flagging will occur. After MOD324 has created the output file, it is the sole responsibility of the user to make any manual corrections. In this example, the program could be run as is. However, if any key words were flagged that did not exist in MODEL 4 BASIC (such as SET), they would have to be removed. Furthermore, if key words were found that could cause unpredictable results (such as a POKE of video ram), lines containing these statements would also need to be modified. PRINT and WIDTH= Parameters Depending on the length of the program to be converted, the resulting output on manual corrections could become quite lengthy. For this reason, the PRINT parameter has been included. By specifying PRINT, any feedback on possible manual corrections will be sent to the printer (as well as the video). If PRINT is specified, the WIDTH= parameter may also be used. This will determine the number of characters sent to the printer per line. The default value for WIDTH= is 80. Any value between 9 and 255 may be used. The printer output will be formatted, so that the line number of a line needing manual corrections will be printed at position 1 (leftmost part) of the line of output. The list of key words will begin at print position 7, and continue for as many key words that exist in the line. If the number of key words to be displayed on the line would cause the WIDTH to be exceeded, the line will be broken at the key word preceding the one causing the "wrap around" (if possible). All remaining key words will then be printed on the next line, starting at print position 7. Assume it is desired to obtain printed output of possible manual corrections when converting the program SAMPLE/BAS to SAMPLE/M4. The total length of an output line is not to exceed 60 characters. The following command will accomplish this. MOD324 SAMPLE/BAS SAMPLE/M4 (P,W=60 MODIFY and CENTER= Parameters A definite problem can arise with respect to "screen formatting" when converting a MODEL III program to run on the MODEL 4. Consider the following (MODEL III) program, which draws a box on the first 15 lines of the video, prints an informative message on the last line, and blinks a message in the middle of the box. 5 CLEAR 2000 10 CLS 20 PRINT@0,CHR$(151);STRING$(62,131);CHR$(171) 30 PRINT@64,CHR$(149):PRINT@127,CHR$(170) 40 PRINT@128,CHR$(149):PRINT@191,CHR$(170) 50 PRINT@192,CHR$(149):PRINT@255,CHR$(170) 60 PRINT@256,CHR$(149):PRINT@319,CHR$(170) 70 PRINT@320,CHR$(149):PRINT@383,CHR$(170) 80 PRINT@384,CHR$(149):PRINT@447,CHR$(170) 90 PRINT@448,CHR$(149):PRINT@511,CHR$(170) 100 PRINT@512,CHR$(149):PRINT@575,CHR$(170) 110 PRINT@576,CHR$(149):,PRINT@639,CHR$(170) 120 PRINT@640,CHR$(149):PRINT@703,CHR$(170) 130 PRINT@704,CHR$(149):PRINT@767,CHR$(170) 140 PRINT@768,CHR$(149):PRINT@831,CHR$(170) 150 PRINT@832,CHR$(149):PRINT@895,CHR$(170) 170 PRINT@896,CHR$(181);STRING$(62,176);CHR$(186); 175 PRINT@960,"";TAB(15)"Press Any Key to end this Program"; 180 PRINT@473,"Center of Box"; 190 I$=INKEY$:IFI$<>""THENEND 200 FORL=1TO30:NEXTL 210 PRINT@473," "; 220 I$=INKEY$:IFI$<>""THENEND 230 FORL=1TO20:NEXTL:GOT0180 Assuming that this program has been saved as CENTER/BAS, the following Conversion command will produce the feedback output shown. MOD324 CENTER/BAS CENTER/M4:3 File CENTER/M4:3 The following lines may need manual correction: 20 PRINT@(0) 30 PRINT@(64),PRINT@(127) 40 PRINT@(128),PRINT@(191) . . . 150 PRINT@(832),PRINT@(895) 170 PRINT@(896) 175 PRINT@(960),TAB 180 PRINT@(473) 210 PRINT@(473) In this example, all PRINT@ commands use numeric constants to represent print positions. The converted program (CENTER/M4) could be run without performing manual corrections. However, the results would not produce a box on the screen. In situations similar to this one, the MODIFY parameter may be used. MODIFY will adjust PRINT@ positions which are represented by numeric constants. The output program file will contain these adjusted values, and the feedback will show both the original and adjusted values. The original PRINT@ position will be divided by 64 to obtain an integer quotient. and remainder. These, numbers correspond to the row and column of the PRINT@ position, offset from 0. The adjusted PRINT@ value is obtained by multiplying the row value by 80 and adding in the column number. The following command will perform a conversion of the program CENTER/BAS, incorporating the MODIFY parameter. The feedback output is shown below. MOD324 CENTER/BAS CENTER/M4:3 (M) File CENTER/M4:3 The following lines may need manual correction: 20 PRINT@(0=>0) 30 PRINT@(64=>80),PRINT@(127=>143) 40 PRINT@(128=>160),PRINT@(191=>223) 50 PRINT@(192=>240),PRINT@(255=>303) 60 PRINT@(256=>320),PRINT@(319=>383) 70 PRINT@(320=>400),PRINT@(383=>463) 80 PRINT@(384=>480),PRINT@(447=>543) 90 PRINT@(448=>560),PRINT@(511=>623) 100 PRINT@(512=>640),PRINT@(575=>703) 110 PRINT@(576=>720),PRINT@(639=>783) 120 PRINT@(640=>800),PRINT@(703=>863) 130 PRINT@(704=>880),PRINT@(767=>943) 140 PRINT@(768=>960),PRINT@(831=>1023) 150 PRINT@(832=>1040),PRINT@(895=>1103) 170 PRINT@(896=>1120) 175 PRINT@(960=>1200),TAB 180 PRINT@(473=>585) 210 PRINT@(473=>585) In examining the adjustments made to Line 40, the original PRINT@ position of 191 was translated into 223 (row 2, column 63). Running the program CENTER/M4 would cause a box to be drawn on the upper left hand corner of the screen. Manual correction of the program would not be required. Notice that PRINT TAB commands (see Line 175) are not adjusted in the case of a MODIFY, as they refer to column position only. Because the MODEL 4 video is larger than that of the MODEL III, it is possible to "overlay" a MODEL III screen onto a portion of the MODEL 4 video. The amount of screen movement available is up to 8 rows, 16 columns. In terms of performing a program conversion, the CENTER= parameter may be used in conjunction with the MODIFY parameter, to further adjust PRINT@ positions represented by numeric constants. The default value for the CENTER= parameter is 328 (4 rows, 8 columns). The following command will perform a conversion of the program CENTER/BAS so that the "box" will be drawn on the center of the MODEL 4 screen. The resulting feedback output is shown below. MOD324 CENTER/BAS CENTER1/M4:3 (M,C) File CENTER1/M4:3 The following lines may need manual correction: 20 PRINT@(0=>328) 30 PRINT@(64=>408),PRINT@(127=>471) 40 PRINT@(128=>488),PRINT@(191=>551) 50 PRINT@(192=>568),PRINT@(255=>631) 60 PRINT@(256=>648),PRINT@(319=>711) 70 PRINT@(320=>728),PRINT@(383=>791) 80 PRINT@(384=>808),PRINT@(447=>871) 90 PRINT@(448=>888),PRINT@(511=>951) 100 PRINT@(512=>968),PRINT@(575=>1031) 110 PRINT@(576=>1048),PRINT@(639=>1111) 120 PRINT@(640=>1128),PRINT@(703=>1191) 130 PRINT@(704=>1208),PRINT@(767=>1271) 140 PRINT@(768=>1288),PRINT@(831=>1351) 150 PRINT@(832=>1368),PRINT@(895=>1431) 170 PRINT@(896=>1448) 175 PRINT@(960=>1528),TAB(15=>23) 180 PRINT@(473=>913) 210 PRINT@(473=>913) In examining Line 40, the original PRINT@ position of 191 was translated into 551. The MODIFY value of 223 was first obtained. Then, the CENTER value of 328 was added in, to obtain the final result. Running the program CENTER1/M4 would cause a box to be drawn in the center of the screen (the upper left corner of the box is positioned at row 4, column 8). Manual correction of the program would not be required. Notice that PRINT TAB commands (see Line 175) are adjusted in the case of a CENTER, as movement of the entire screen affects column positioning. The value that will be added to numeric constants in PRINT TAB statements is the column offset (in this example, 8). If zero is used as a column offset (i.e. if CENTER=80, 160, 240, etc.), PRINT TABs will not be adjusted by CENTER. When using the CENTER= parameter, the MODIFY parameter must also be specified for any adjustments to occur. Although any value may be used with CENTER=, some values (e.g. CENTER=99) will produce undesirable results. Offsets of more than 8 rows and/or 16 columns should be avoided. The following table lists the CENTER= value ranges that make the most practical sense. CENTER= Range Row Offset 0-16 0 80-96 1 160-176 2 240-256 3 320-336 4 400-416 5 480-496 6 560-576 7 640-656 8 Miscellaneous "Feedback" Information When PRINT@ and PRINT TAB statements utilize numeric expressions as print position values, adjustments to the positioning values will not be made. However, the feedback associated with such commands will indicate that the print positioning value is a numeric expression. Consider the following MODEL III program (CNTLOOP/BAS) which will draw a box on the video via a FOR-NEXT loop. 5 CLEAR 2000 10 CLS 20 PRINT@0,CHR$(151);STRING$(62,131);CHR$(171) 25 FORL=1TO13:A1=L*64:PRINT@A1,CHR$(149):PRINT@A1+63,CHR$(170): NEXTL 170 PRINT@896,CHR$(181);STRING$(62,176);CHR$(186); 172 MC$="Center of Box":MB$="Press Any Key to end this Program" 174 M1=LEN(MC$):M2=LEN(MB$):CM=7*64+((64-M1)/2) 175 PRINT@960,"";TAB((64-M2)/2);MB$; 180 PRINT@CM,KCS; - 190 I$=INKEY$:IFI$<>""THENEND 200 FORL=1TO30:NEXTL 210 PRINT@CM,STRING$(M1,32); 220 I$=INKEY$:IFI$<>""THENEND 230 FORL=1TO20:NEXTL:GOT0180 The following command can be used to convert this program, with the resulting feedback output shown below. MOD324 CNTLOOP/BAS CNTLOOP/M4:3 (M,C) File CNTLOOP/M4:3 The following lines may need manual correction: 20 PRINT@(0=>328) 25 PRINT@(EXP),PRINT@(EXP) 170 PRINT@(896=>1448) 175 PRINT@(960=>1528),TAB(EXP) 180 PRINT@(EXP) 210 PRINT@(EXP) Notice that an adjustment did occur in Line 20. However, in Line 25 the print position was specified as a numeric expression. In this case, an adjustment is not made to Line 25 in the output filespec (converted program). Rather, the feedback message associated with the PRINT@ statement indicates that an expression (EXP) follows the PRINT@. PRINT@(EXP) will always be displayed (regardless of the conversion parameters specified) when a numeric expression follows a PRINT@ statement. The same type of feedback will occur with PRINT TAB statements. This will happen when a column offset is dictated by the CENTER parameter, and a numeric expression denotes the tab position (see Line 175). Due to the expansion that takes place during a program conversion (e.g. spaces being inserted), it may be necessary for MOD324 to truncate a program line. Line truncation is done so that the resulting program file may be loaded into memory by MODEL 4 BASIC. When a line is truncated, as much of the line as possible is stored in the output program file, and a feedback message shows the part of the line that was truncated. As an example, assume that the following line exists in a MODEL III program file. 10 FORLL=1TO10:FORLK=1TO20:FORLP=1TO30:LPRINTTAB(20)"This is an example of a converted line being too long":LPRINTTAB(20)"The value of LL is";LL: LPRINTTAB(20)"The value of lk is";LK:LPRINTTAB(20)"The value of LP is"; LP:NEXTLP:NEXTLK:NEXTLL:PRINTTAB(20)"Done" Consider the results of performing a conversion of this line, as shown below (shown first is the line as it would be saved to the output filespec, followed by the feedback message that would be generated). 10 FOR LL=1 TO 10:FOR LK=1 TO 20:FOR LP=1 TO 30:LPRINT TAB(20)"This is an example of a converted line being too long":LPRINT TAB(20)"The value of LL is";LL:LPRINT TAB(20)"The value of lk is";LK:LPRINT TAB(20)"The value of LP is";LP:NEXT LP:NEXT LK:NEX The following lines may need manual correction: 10 TAB 10 - Line truncated, should be extended as follows: T LL:PRINT TAB(20)"Done" Of interest in this example is the ending part of the line in the output file and the information in the "Line Truncated" feedback message. Note that any part of the program line that could not get written to the output file is displayed in the feedback message. One last point which needs to be mentioned concerns the use of IF-THEN statements. In a MODEL III program, the following type of statement is allowable, and would function without error. IF A=1 A=2 In this case, THEN is implied. However, using this type of implied THEN statement on the MODEL 4 would generate a syntax error. For this reason, MOD324 will flag any IF statement which is not followed by a THEN.