10 REM WS4HTM.BAS by Emmanuel ROCHE 20 : 30 PRINT 40 INPUT "WS4-to-HTM> Enter WS4 File Name: " ; file$ 50 PRINT 60 : 70 OPTION BASE 0 80 DIM hexa$ (255), ncr1$ (255), ncr2$ (255), ncr3$ (255) 90 RESTORE 2380 100 FOR i = 127 TO 255 110 READ hexa$ (i) 120 READ ncr1$ (i) 130 READ ncr2$ (i) 140 READ ncr3$ (i) 150 NEXT i 160 : 170 WHILE FIND$ ("*.WS4") <> "" 180 ordinal = ordinal + 1 190 found$ = FIND$ (file$ + ".WS4", ordinal) 200 IF found$ = "" AND ordinal > 1 THEN GOTO 280 210 IF found$ = "" THEN GOTO 270 220 file1$ = found$ 230 file2$ = LEFT$ (file1$, 8) + ".HTM" 240 GOSUB 320 250 WEND 260 : 270 PRINT CHR$ (7) "File not found." 280 PRINT 290 CLOSE 300 END 310 : 320 PRINT found$ 330 OPEN "R", #1, file1$, 1 340 FIELD #1, 1 AS byte$ 350 OPEN "O", #2, file2$ 360 : 370 PRINT #2, "" 390 PRINT #2, "" 400 PRINT #2, "" 410 PRINT #2, "" 450 PRINT #2, "" 490 PRINT #2, "Converted from file " CHR$ (34) ; 500 space = INSTR (file1$, " ") 510 IF space THEN file3$ = LEFT$ (file1$, space-1) ELSE file3$ = LEFT$ (file1$, 8) 520 typ$ = RIGHT$ (file1$, 4) 530 file3$ = file3$ + typ$ 540 PRINT #2, UPPER$ (file3$) CHR$ (34) "" 550 PRINT #2, "" 560 PRINT #2, "" 570 PRINT #2, "" 580 PRINT #2, "
"
590 :
600 PRINT #2, CHR$ (&HEF) ;  ' Byte
610 PRINT #2, CHR$ (&HBB) ;  ' Order
620 PRINT #2, CHR$ (&HBF) ;  ' Mark ("BOM")
630 :
640 GET #1
650 GOSUB 690
660 IF byte$ = CHR$ (&H1A) THEN RETURN
670 GOTO 640
680 :
690 notshown$ = CHR$(130)+CHR$(132)+CHR$(138)+CHR$(147)+CHR$(148)+CHR$(150)+CHR$(153)+CHR$(154)+CHR$(155)
700 notshown = INSTR (notshown$, byte$)
710 ' Bytes:          82    84    8A    93    94    96    99    9A    9B
720 ON notshown GOTO 1010, 1100, 1350, 1720, 1770, 1860, 2000,  900, 2120
730 :
740 ' WS4 text
750 IF byte$ > CHR$ (&H1F) THEN L$ = L$ + STRIP$ (byte$) : RETURN
760 :
770 ' WS4 commands
780 byte = ASC (byte$)
790 REM Byte:       00   01    02    03    04    05    06    07
800 ON byte+1 GOSUB 930, 970, 1010, 1060, 1100, 1150, 1190, 1230
810 IF byte > 7 THEN byte = byte - 7 ELSE RETURN
820 REM Byte:      08    09    0A    0B    0C    0D    0E    0F
830 ON byte GOSUB 1270, 1310, 1350, 1400, 1440, 1480, 1520, 1560
840 IF byte > 8 THEN byte = byte - 8 ELSE RETURN
850 REM Byte:      10    11    12    13    14    15    16    17
860 ON byte GOSUB 1600, 1640, 1680, 1720, 1770, 1820, 1860, 1910
870 IF byte > 8 THEN byte = byte - 8 ELSE RETURN
880 REM Byte:      18    19    1A    1B    1C    1D    1E    1F
890 ON byte GOSUB 1950, 2000, 2050, 2130, 2230, 2270, 2310, 2350
900 RETURN
910 '
920 ' 00h: Fix the print position.
930 PRINT "[00]" ;
940 RETURN
950 '
960 ' 01h: Alternate character width.
970 L$ = L$ + ""
980 RETURN
990 '
1000 ' 02h: Boldface type ON/OFF toggle.
1010 flag02 = NOT flag02
1020 IF flag02 THEN L$ = L$ + "" ELSE L$ = L$ + ""
1030 RETURN
1040 '
1050 ' 03h: Pause for user response during print.
1060 PRINT "[03]" ;
1070 RETURN
1080 '
1090 ' 04h: Double strike printing ON/OFF toggle.
1100 flag04 = NOT flag04
1110 IF flag04 THEN L$ = L$ + "" ELSE L$ = L$ + ""
1120 RETURN
1130 '
1140 ' 05h: Custom print control Ctrl-E.
1150 PRINT "[05]" ;
1160 RETURN
1170 '
1180 ' 06h: Phantom space (default: 20h).
1190 L$ = L$ + CHR$ (32)
1200 RETURN
1210 '
1220 ' 07h: Phantom rubout (default: 7Eh).
1230 L$ = L$ + CHR$ (126)
1240 RETURN
1250 '
1260 ' 08h: Overprint previous character.
1270 PRINT "[08]" ;
1280 RETURN
1290 '
1300 ' 09h: Horizontal Tabulation character.
1310 PRINT "[09]" ;
1320 RETURN
1330 '
1340 ' 0Ah: Line Feed.
1350 IF LEFT$ (L$, 1) <> "." THEN PRINT #2, L$ + CHR$ (10) ;
1360 L$ = ""
1370 RETURN
1380 '
1390 ' 0Bh: Mark index entry.
1400 PRINT "[0B]" ;
1410 RETURN
1420 '
1430 ' 0Ch: Form Feed.
1440 PRINT "[0C]" ;
1450 RETURN
1460 '
1470 ' 0Dh: Carriage Return.
1480 L$ = L$ + CHR$ (13)
1490 RETURN
1500 '
1510 ' 0Eh: Return to the normal character width.
1520 L$ = L$ + ""
1530 RETURN
1540 '
1550 ' 0Fh: Binding space.
1560 L$ = L$ + " "
1570 RETURN
1580 '
1590 ' 10h: Reserved.
1600 PRINT "[10]" ;
1610 RETURN
1620 '
1630 ' 11h: Custom print control Ctrl-Q.
1640 PRINT "[11]" ;
1650 RETURN
1660 '
1670 ' 12h: Custom print control Ctrl-R.
1680 PRINT "[12]" ;
1690 RETURN
1700 '
1710 ' 13h: Underline ON/OFF toggle.
1720 flag13 = NOT flag13
1730 IF flag13 THEN L$ = L$ + "" ELSE L$ = L$ + ""
1740 RETURN
1750 '
1760 ' 14h: Superscript ON/OFF toggle.
1770 flag14 = NOT flag14
1780 IF flag14 THEN L$ = L$ + "" ELSE L$ = L$ + ""
1790 RETURN
1800 '
1810 ' 15h: Reserved.
1820 PRINT "[15]" ;
1830 RETURN
1840 '
1850 ' 16h: Subscript ON/OFF toggle.
1860 flag16 = NOT flag16
1870 IF flag16 THEN L$ = L$ + "" ELSE L$ = L$ + ""
1880 RETURN
1890 '
1900 ' 17h: Custom print control Ctrl-W.
1910 PRINT "[17]" ;
1920 RETURN
1930 '
1940 ' 18h: Strikeout ON/OFF toggle.
1950 flag18 = NOT flag18
1960 IF flag18 THEN L$ = L$ + "" ELSE L$ = L$ + ""
1970 RETURN
1980 '
1990 ' 19h: Italics ON/OFF toggle.
2000 flag19 = NOT flag19
2010 IF flag19 THEN L$ = L$ + "" ELSE L$ = L$ + ""
2020 RETURN
2030 '
2040 ' 1Ah: End Of File character.
2050 PRINT #2, "
" 2060 PRINT #2, "" 2070 PRINT #2, "" 2080 CLOSE 2090 byte$ = CHR$ (&H1A) 2100 RETURN 2110 ' 2120 ' 1Bh: Extended character lead-in code. 2130 GET #1 2140 L$ = L$ + CHR$ (VAL ("&H" + (ncr1$ (ASC (byte$))))) 2150 IF ncr2$ (ASC (byte$) ) = "0" THEN GOTO 2190 2160 L$ = L$ + CHR$ (VAL ("&H" + (ncr2$ (ASC (byte$))))) 2170 IF ncr3$ (ASC (byte$) ) = "0" THEN GOTO 2190 2180 L$ = L$ + CHR$ (VAL ("&H" + (ncr3$ (ASC (byte$))))) 2190 GET #1 2200 RETURN 2210 ' 2220 ' 1Ch: Extended character trailer code. 2230 PRINT "[1C]" ; 2240 RETURN 2250 ' 2260 ' 1Dh: Reserved. 2270 PRINT "[1D]" ; 2280 RETURN 2290 ' 2300 ' 1Eh: Inactive soft hyphen. 2310 PRINT "[1E]" ; 2320 RETURN 2330 ' 2340 ' 1Fh: Active soft hyphen. 2350 PRINT "[1F]" ; 2360 RETURN 2370 : 2380 DATA 7F, E2, 8C, 82 2390 DATA 80, C3, 87, 0 2400 DATA 81, C3, BC, 0 2410 DATA 82, C3, A9, 0 2420 DATA 83, C3, A2, 0 2430 DATA 84, C3, A4, 0 2440 DATA 85, C3, A0, 0 2450 DATA 86, C3, A5, 0 2460 DATA 87, C3, A7, 0 2470 DATA 88, C3, AA, 0 2480 DATA 89, C3, AB, 0 2490 DATA 8A, C3, A8, 0 2500 DATA 8B, C3, AF, 0 2510 DATA 8C, C3, AE, 0 2520 DATA 8D, C3, AC, 0 2530 DATA 8E, C3, 84, 0 2540 DATA 8F, C3, 85, 0 2550 DATA 90, C3, 89, 0 2560 DATA 91, C3, A6, 0 2570 DATA 92, C3, 86, 0 2580 DATA 93, C3, B4, 0 2590 DATA 94, C3, B6, 0 2600 DATA 95, C3, B2, 0 2610 DATA 96, C3, BB, 0 2620 DATA 97, C3, B9, 0 2630 DATA 98, C3, BF, 0 2640 DATA 99, C3, 96, 0 2650 DATA 9A, C3, 9C, 0 2660 DATA 9B, C2, A2, 0 2670 DATA 9C, C2, A3, 0 2680 DATA 9D, C2, A5, 0 2690 DATA 9E, E2, 82, A7 2700 DATA 9F, C6, 92, 0 2710 DATA A0, C3, A1, 0 2720 DATA A1, C3, AD, 0 2730 DATA A2, C3, B3, 0 2740 DATA A3, C3, BA, 0 2750 DATA A4, C3, B1, 0 2760 DATA A5, C3, 91, 0 2770 DATA A6, C2, AA, 0 2780 DATA A7, C2, BA, 0 2790 DATA A8, C2, BF, 0 2800 DATA A9, E2, 8C, 90 2810 DATA AA, C2, AC, 0 2820 DATA AB, C2, BD, 0 2830 DATA AC, C2, BC, 0 2840 DATA AD, C2, A1, 0 2850 DATA AE, C2, AB, 0 2860 DATA AF, C2, BB, 0 2870 DATA B0, E2, 96, 91 2880 DATA B1, E2, 96, 92 2890 DATA B2, E2, 96, 93 2900 DATA B3, E2, 94, 82 2910 DATA B4, E2, 94, A4 2920 DATA B5, E2, 95, A1 2930 DATA B6, E2, 95, A2 2940 DATA B7, E2, 95, 96 2950 DATA B8, E2, 95, 95 2960 DATA B9, E2, 95, A3 2970 DATA BA, E2, 95, 91 2980 DATA BB, E2, 95, 97 2990 DATA BC, E2, 95, 9D 3000 DATA BD, E2, 95, 9C 3010 DATA BE, E2, 95, 9B 3020 DATA BF, E2, 94, 90 3030 DATA C0, E2, 94, 94 3040 DATA C1, E2, 94, B4 3050 DATA C2, E2, 94, AC 3060 DATA C3, E2, 94, 9C 3070 DATA C4, E2, 94, 80 3080 DATA C5, E2, 94, BC 3090 DATA C6, E2, 95, 9E 3100 DATA C7, E2, 95, 9F 3110 DATA C8, E2, 95, 9A 3120 DATA C9, E2, 95, 94 3130 DATA CA, E2, 95, A9 3140 DATA CB, E2, 95, A6 3150 DATA CC, E2, 95, A0 3160 DATA CD, E2, 95, 90 3170 DATA CE, E2, 95, AC 3180 DATA CF, E2, 95, A7 3190 DATA D0, E2, 95, A8 3200 DATA D1, E2, 95, A4 3210 DATA D2, E2, 95, A5 3220 DATA D3, E2, 95, 99 3230 DATA D4, E2, 95, 98 3240 DATA D5, E2, 95, 92 3250 DATA D6, E2, 95, 93 3260 DATA D7, E2, 95, AB 3270 DATA D8, E2, 95, AA 3280 DATA D9, E2, 94, 98 3290 DATA DA, E2, 94, 8C 3300 DATA DB, E2, 96, 88 3310 DATA DC, E2, 96, 84 3320 DATA DD, E2, 96, 8C 3330 DATA DE, E2, 96, 90 3340 DATA DF, E2, 96, 80 3350 DATA E0, CE, B1, 0 3360 DATA E1, CE, B2, 0 3370 DATA E2, CE, 93, 0 3380 DATA E3, CF, 80, 0 3390 DATA E4, CE, A3, 0 3400 DATA E5, CF, 83, 0 3410 DATA E6, C2, B5, 0 3420 DATA E7, CF, 84, 0 3430 DATA E8, CE, A6, 0 3440 DATA E9, CE, 98, 0 3450 DATA EA, CE, A9, 0 3460 DATA EB, CE, B4, 0 3470 DATA EC, E2, 88, 9E 3480 DATA ED, CF, 86, 0 3490 DATA EE, CE, B5, 0 3500 DATA EF, E2, 88, A9 3510 DATA F0, E2, 89, A1 3520 DATA F1, C2, B1, 0 3530 DATA F2, E2, 89, A5 3540 DATA F3, E2, 89, A4 3550 DATA F4, E2, 8C, A0 3560 DATA F5, E2, 8C, A1 3570 DATA F6, C3, B7, 0 3580 DATA F7, E2, 89, 88 3590 DATA F8, C2, B0, 0 3600 DATA F9, E2, 88, 99 3610 DATA FA, C2, B7, 0 3620 DATA FB, E2, 88, 9A 3630 DATA FC, E2, 81, BF 3640 DATA FD, C2, B2, 0 3650 DATA FE, E2, 96, A0 3660 DATA FF, C2, A0, 0