Advertisement
Guest User

Dump a Turbo Pascal 2/3 terminal data file

a guest
May 9th, 2024
15
0
166 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | Source Code | 0 0
  1.  
  2. Dump a Turbo Pascal 2/3 terminal data file
  3.  
  4. empty forth definitions decimal application
  5. warning on
  6.  
  7. : TITLE ." DTADMP version 1.2 2024-05-09" cr ;
  8.  
  9. cr .( Compiling: ) title 2 load
  10.  
  11. cr .( Save to disk? ) y/n [if]
  12. \ tally @ pad + #256 + limit s0 @ - + set-limit
  13. turnkey program DTADMP
  14. [then]
  15.  
  16. variable TALLY 0 tally ! \ run-time memory tally
  17. defer ?STOP ' noop is ?stop \ user abort check
  18. defer CON-IO ' bios-io is con-io \ default console i/o mode
  19. defer ONERROR ' noop is onerror \ reset on-error handler
  20. defer ONSTART ' noop is onstart \ startup initialization
  21.  
  22. blk @ 1+ #screens 1- thru \ load electives & application
  23.  
  24. ' ?stopkey is ?stop \ enable user abort
  25. ' dos-io is con-io \ enable console redirection
  26. \ ' delout +is onerror \ delete outfile on error
  27. \ wrtchk off \ disable overwrite check
  28.  
  29. 1 fload DOSLIB \ DOSLIB library
  30. _Errors \ error handler
  31. _Inout1 \ number output
  32. \ _Inout2 \
  33. \ _Compare1 \ basic compare
  34. _String1 \ basic strings
  35. \ _String2 \ extra strings
  36. _Parse1 \ cmdline parsing
  37. \ _Parse2 \ cmdline extra
  38. _Files \ default files
  39. \ _Bread \ buffer read char
  40. \ _Bread2 \ buffer read data/text
  41. _Bwrite \ buffer write char
  42. \ _Bwrite2 \ buffer write data/text
  43.  
  44. : HELP ( -- ) dos-io cr cr title
  45. cr ." Use: DTADMP file[.DTA] [file[.DMP]]" cr
  46. cr ." -D Disk output"
  47. cr
  48. cr ." Dump a Turbo Pascal terminal data file."
  49. con-io abort ;
  50.  
  51. integer #TERM ( -- u ) \ # terminals in DTA file
  52. integer TSIZE ( -- u ) \ size of each terminal entry
  53. integer TBASE ( -- a ) \ terminals base addr
  54. integer CTERM ( -- a ) \ current terminal addr
  55. integer #DATUM ( -- u ) \ # fields in each terminal entry
  56. integer CONOUT ( -- f ) \ console output flag
  57.  
  58. \ Set EMIT to OFILE
  59. : DISK ( -- )
  60. ['] writechr [ sys-vec 4 + ] literal ! ;
  61.  
  62. \ Set options
  63. :noname ( a u char -- a' u' )
  64. upcase
  65. [char] D of false to conout end
  66. .bad ; is setopt
  67.  
  68. \ Parse filenames
  69. :noname ( -- )
  70. argv 0= if help then
  71. s" DTA" +ext ifile !fname
  72. conout if end
  73. argv 0= if ifile @fname -path -ext then
  74. s" DMP" +ext ofile !fname
  75. ; is parsefn
  76.  
  77. \ Fetch & increment
  78. : @+ ( a -- a' x ) dup cell+ swap @ ;
  79.  
  80. \ Move to column
  81. : TAB ( col# -- ) out @ - spaces ;
  82.  
  83. \ Output
  84. : DB. ( c -- ) 0 .r ;
  85. : HB. ( c -- ) (hb.) type [char] h emit ;
  86.  
  87. : .D ( a -- ) c@ db. ;
  88. : .H ( a -- ) c@ hb. ;
  89.  
  90. integer QUOTE ( -- f ) \ quote mode
  91.  
  92. : !Q ( f -- ) to quote [char] ' emit ;
  93. : +Q ( -- ) quote if end [char] , emit true !q ;
  94. : -Q ( -- ) quote if false !q then ;
  95.  
  96. : QUOTABLE? ( c -- f )
  97. dup $20 $7F within swap [char] ' <> and ;
  98.  
  99. : .$ ( a -- )
  100. false to quote count dup db. bounds ?do
  101. i c@ dup quotable? if +q emit
  102. else -q [char] , emit hb. then
  103. loop -q ;
  104.  
  105. \ table of offsets to data
  106. create OFFSET ( -- a ) hex
  107. 00 c, 15 c, 16 c, 26 c, 36 c, 46 c, 47 c, 48 c,
  108. 49 c, 4A c, 4B c, 4D c, 53 c, 59 c, 5B c, 61 c,
  109. 67 c, 69 c, 6F c, 75 c, 7B c, 7C c, 7D c, 7E c,
  110. 7F c, 80 c, 86 c, 8C c, 92 c, 93 c, 94 c,
  111. decimal here offset - to #datum
  112.  
  113. \ corresponding data actions
  114. create ACTION ( -- a )
  115. ] .$ .h .$ .$ .$ .d .d .d
  116. .d .d .d .$ .$ .d .$ .$
  117. .d .$ .$ .$ .d .d .d .d
  118. .h .$ .$ .$ .d .d .h [
  119.  
  120. \ Convert index to offset
  121. : >OFFSET ( idx -- offs ) offset + c@ ;
  122.  
  123. \ Show data - byte or string
  124. : .DATATYPE ( idx -- )
  125. dup >offset cterm + ( idx a )
  126. swap cells action + @execute ;
  127.  
  128. create NAMES ( -- a )
  129. ( 00) ," Terminal name"
  130. ( 15) ," ???"
  131. ( 16) ," Init string"
  132. ( 26) ," Exit string"
  133. ( 36) ," Cursor motion template"
  134. ( 46) ," 0=decimal 1=binary"
  135. ( 47) ," col offset in cm template"
  136. ( 48) ," row offset in cm template"
  137. ( 49) ," offset added to column"
  138. ( 4A) ," offset added to row"
  139. ( 4B) ," delay after cursor motion"
  140. ( 4D) ," clear screen"
  141.  
  142. ( 53) ," home cursor"
  143. ( 59) ," delay after cls, delete line"
  144. ( 5B) ," hilite video"
  145. ( 61) ," normal video"
  146. ( 67) ," delay after clear-to-EOL, hilite"
  147. ( 69) ," clear-to-EOL"
  148. ( 6F) ," insert line"
  149. ( 75) ," delete line"
  150. ( 7B) ," screen columns"
  151. ( 7C) ," screen rows"
  152. ( 7D) ," init string flag"
  153. ( 7E) ," exit string flag"
  154. ( 7F) ," ???"
  155.  
  156. ( 80) ," cursor lead-in"
  157. ( 86) ," string sent between row/col"
  158. ( 8C) ," string sent after row/col"
  159. ( 92) ," 1=column first 0=row first"
  160. ( 93) ," # col/row digits in cm template"
  161. ( 94) ," ???"
  162.  
  163. : NAME ( idx -- adr len )
  164. names swap 0 ?do count + loop count ;
  165.  
  166. \ Show description
  167. : .NAME ( idx -- ) space 30 tab name type ;
  168.  
  169. \ Show offset
  170. : .OFFSET ( idx -- ) >offset hb. space ;
  171.  
  172. \ Show one field
  173. : .FIELD ( idx -- )
  174. cr dup .offset dup .datatype .name ;
  175.  
  176. \ Show one terminal
  177. : .TERMINAL ( a -- )
  178. to cterm #datum 0 ?do i .field loop cr cr ;
  179.  
  180. \ Dump all terminals
  181. : .ALL ( -- )
  182. tbase #term 0 ?do dup .terminal tsize + loop drop ;
  183.  
  184. \ Read DTA file into memory
  185. : GETDTA ( -- )
  186. here unused read ( a u) allot ( a)
  187. @+ to #term \ number of terminals in file
  188. @+ to tsize \ size of each terminal
  189. to tbase \ base address of terminals
  190. tsize $95 - if
  191. cr ." Not a TP2/3 terminal DTA file" .abort
  192. then ;
  193.  
  194. : OPENFILES ( -- )
  195. cr ." i: " .ifile r/o openin
  196. conout not if
  197. cr ." o: " .ofile r/w makeout
  198. then
  199. cr
  200. ;
  201.  
  202. \ Run application
  203. : (RUN) ( -- )
  204. openfiles
  205. getdta
  206. conout not if disk then
  207. .all
  208. console
  209. closefiles
  210. ;
  211.  
  212. \ Set application defaults
  213. : DEFAULTS ( -- )
  214. true to conout
  215. ;
  216.  
  217. defaults
  218.  
  219. \ Run application with error handling
  220. : RUN ( -- )
  221. ['] (run) catch ?dup if >r onerror r> throw then ;
  222.  
  223. \ Main
  224. : PROGRAM ( -- )
  225. onstart \ startup initialization
  226. con-io \ default console mode
  227. defaults \ set defaults
  228. cr title \ show application name
  229. cmdtail parsecmd \ process command-line
  230. run \ run application
  231. cr ." done" \ show success
  232. ;
  233.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement