home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY1 / CCTRAN.ZIP / COCOTRAN.BAS next >
BASIC Source File  |  1990-04-21  |  6KB  |  239 lines

  1. defint a-z
  2. dim tok$(128:224)
  3. dim extok$(128:167)
  4. tok$(128)=" FOR "
  5. tok$(129)=" GO"
  6. tok$(130)=" REM "
  7. tok$(131)=" '"
  8. tok$(132)=" ELSE "
  9. tok$(133)=" IF "
  10. tok$(134)=" DATA "
  11. tok$(135)=" PRINT "
  12. tok$(136)=" ON "
  13. tok$(137)=" INPUT "
  14. tok$(138)=" END "
  15. tok$(139)=" NEXT "
  16. tok$(140)=" DIM "
  17. tok$(141)=" READ "
  18. tok$(142)=" RUN "
  19. tok$(143)=" RESTORE "
  20. tok$(144)=" RETURN "
  21. tok$(145)=" STOP "
  22. tok$(146)=" POKE "
  23. tok$(147)=" CONT "
  24. tok$(148)=" LIST "
  25. tok$(149)=" CLEAR "
  26. tok$(150)=" NEW "
  27. tok$(151)=" CLOAD "
  28. tok$(152)=" CSAVE "
  29. tok$(153)=" OPEN "
  30. tok$(154)=" CLOSE "
  31. tok$(155)=" LLIST "
  32. tok$(156)=" SET "
  33. tok$(157)=" RESET "
  34. tok$(158)=" CLS "
  35. tok$(159)=" MOTOR "
  36. tok$(160)=" SOUND "
  37. tok$(161)=" AUDIO "
  38. tok$(162)=" EXEC "
  39. tok$(163)=" SKIPF "
  40. tok$(164)=" TAB("
  41. tok$(165)=" TO "
  42. tok$(166)="SUB "
  43. tok$(167)=" THEN "
  44. tok$(168)=" NOT "
  45. tok$(169)=" STEP "
  46. tok$(170)=" OFF "
  47. tok$(171)="+"
  48. tok$(172)="-"
  49. tok$(173)="*"
  50. tok$(174)="/"
  51. tok$(175)="^"
  52. tok$(176)=" AND "
  53. tok$(177)=" OR "
  54. tok$(178)=">"
  55. tok$(179)="="
  56. tok$(180)="<"
  57. tok$(181)=" DEL "
  58. tok$(182)=" EDIT "
  59. tok$(183)=" TRON "
  60. tok$(184)=" TROFF "
  61. tok$(185)=" DEF"
  62. tok$(186)=" LET "
  63. tok$(187)=" LINE "
  64. tok$(188)=" PCLS "
  65. tok$(189)=" PSET "
  66. tok$(190)=" PRESET "
  67. tok$(191)=" SCREEN "
  68. tok$(192)=" PCLEAR "
  69. tok$(193)=" COLOR "
  70. tok$(194)=" CIRCLE"
  71. tok$(195)=" PAINT"
  72. tok$(196)=" GET "
  73. tok$(197)=" PUT "
  74. tok$(198)=" DRAW "
  75. tok$(199)=" PCOPY "
  76. tok$(200)=" PMODE "
  77. tok$(201)=" PLAY "
  78. tok$(202)=" DLOAD "
  79. tok$(203)=" RENUM "
  80. tok$(204)=" FN "
  81. tok$(205)=" USING "
  82. tok$(206)=" DIR "
  83. tok$(207)=" DRIVE "
  84. tok$(208)=" FIELD "
  85. tok$(209)=" FILES "
  86. tok$(210)=" KILL "
  87. tok$(211)=" LOAD"
  88. tok$(212)=" LSET "
  89. tok$(213)=" MERGE "
  90. tok$(214)=" RENAME "
  91. tok$(215)=" RSET"
  92. tok$(216)=" SAVE"
  93. tok$(217)=" WRITE "
  94. tok$(218)=" VERIFY "
  95. tok$(219)=" UNLOAD "
  96. tok$(220)=" DSKINI "
  97. tok$(221)=" BACKUP "
  98. tok$(222)=" COPY "
  99. tok$(223)=" DSKI$ "
  100. tok$(224)=" DSKO$ "
  101.  
  102. extok$(128)=" SGN"
  103. extok$(129)=" INT"
  104. extok$(130)=" ABS"
  105. extok$(131)=" USR"
  106. extok$(132)=" RND"
  107. extok$(133)=" SIN"
  108. extok$(134)=" PEEK"
  109. extok$(135)=" LEN"
  110. extok$(136)=" STR$"
  111. extok$(137)=" VAL"
  112. extok$(138)=" ASC"
  113. extok$(139)=" CHR$"
  114. extok$(140)=" EOF"
  115. extok$(141)=" JOYSTK"
  116. extok$(142)=" LEFT$"
  117. extok$(143)=" RIGHT$"
  118. extok$(144)=" MID$"
  119. extok$(145)=" POINT"
  120. extok$(146)=" INKEY$"
  121. extok$(147)=" MEM"
  122. extok$(148)=" ATN"
  123. extok$(149)=" COS"
  124. extok$(150)=" TAN"
  125. extok$(151)=" EXP"
  126. extok$(152)=" FIX"
  127. extok$(152)=" LOG"
  128. extok$(154)=" POS"
  129. extok$(155)=" SQR"
  130. extok$(156)=" HEX$"
  131. extok$(157)=" VARPTR"
  132. extok$(158)=" INSTR"
  133. extok$(159)=" TIMER"
  134. extok$(160)=" PPOINT"
  135. extok$(161)=" STRING$"
  136. extok$(162)=" CVN "
  137. extok$(163)=" FREE "
  138. extok$(164)=" LOC "
  139. extok$(165)=" LOF "
  140. extok$(166)=" MKN$ "
  141. extok$(167)=" AS "
  142.  
  143. if command$="" then
  144.   input "File to translate: ";inf$
  145. else
  146.   sploc = instr(command$," ")
  147.   if sploc > 0 then
  148.     inf$ = left$(command$, sploc -1)
  149.     outf$ = mid$(command$,sploc + 1, len(command$) - sploc)
  150.   else
  151.     inf$ = command$
  152.     dot = instr(inf$,".")
  153.     outf$ = left$(inf$,dot)
  154.     outf$ = outf$ + "trn"
  155.   end if
  156. end if
  157. 'input "Output file name: ";outf$
  158. open inf$ for binary as 1
  159. get$ #1, 1, x$
  160. if ascii(x$) <> 255 then
  161.   print "'";inf$;"' is not a binary Color Computer BASIC file"
  162.   close
  163.   end
  164. end if
  165. cls
  166. print "Translating '";inf$;"' to ASCII.  Output will be in '";outf$;"'"
  167. open outf$ for output as 2
  168. 'open "c:\tmp\ok.txt" for append as 3
  169. 'print #3, inf$
  170. 'close 3
  171. get$ #1, 1, x$
  172. bytecount = 256 * ascii(x$)
  173. get$ #1, 1, x$
  174. bytecount = bytecount + ascii(x$)
  175. print "Approximate source file size is";bytecount;"bytes."
  176. bytesread = 0
  177. while not eof(1)
  178.   if csrlin > 22 then
  179.     cls
  180.     print "Translating '";inf$;"' to ASCII.  Output will be in '";outf$;"'"
  181.   end if
  182.   tline$ = ""
  183.   call getline
  184.   print tline$
  185.   print #2, tline$
  186. wend
  187. close
  188. end
  189.  
  190.  
  191. SUB getline
  192.   SHARED tok$(), extok$(), tline$, bytecount, inf$
  193.   STATIC oldline&, linenum&, bytesread
  194.   if linenum& > oldline& then oldline& = linenum&
  195.   get$ #1, 1, x$                     'get hi byte of load address
  196.   incr bytesread
  197.   if bytesread > bytecount then end
  198.   startaddr& = 256 * ascii(x$)        'compute
  199.   get$ #1, 1, x$                     'get lo byte
  200.   incr bytesread
  201.   if bytesread > bytecount then end
  202.   startaddr& = startaddr& + ascii(x$)  'compute
  203.   get$ #1, 1, x$                     'get hi byte of line number
  204.   incr bytesread
  205.   if bytesread > bytecount then end
  206.   linenum& = 256 * ascii(x$)         'compute
  207.   get$ #1, 1, x$                     'get lo byte
  208.   incr bytesread
  209.   if bytesread > bytecount then end
  210.   linenum& = linenum& + ascii(x$)    'compute
  211.   if linenum& < oldline& then        'binary data at end of file
  212.     print
  213.     print "Found unknown bytes in '";inf$;"' at location";bytesread -2
  214.     print
  215.     close
  216.     end
  217.   end if
  218.   tline$ = str$(linenum&) + " "      'start building string
  219.   while 1 > 0                        'do forever
  220.     get$ #1, 1, x$                   'read byte
  221.     incr bytesread
  222.     if bytesread > bytecount then exit loop
  223.     x = ascii(x$)                    'get value
  224.     if x = 0 then exit loop          'exit on null (end of line)
  225.     if x < 128 then                  'if not a token
  226.       tline$ = tline$ + x$           'append to string
  227.     else                             'otherwise process token
  228.       if x = 255 then                'if two byte token
  229.     get$ #1, 1, x$               'get next byte
  230.     incr bytesread
  231.     if bytesread > bytecount then exit loop
  232.     x = ascii(x$)                'convert
  233.     tline$ = tline$ + extok$(x)  'get string equivalent and add it
  234.       else                           'otherwise
  235.     tline$ = tline$ + tok$(x)    'get string equivalent and add it
  236.       end if
  237.     end if
  238.   wend                               'end of loop
  239. END SUB 'getline