home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / hp9000basic / hpbker.bas < prev    next >
BASIC Source File  |  2020-01-01  |  207KB  |  5,758 lines

  1. 1! re-store "/KERMIT/HPKERM02"
  2. 2  !
  3. 3  ! Special Revision: No CSUBS. Requires user to
  4. 4  !                   LOADSUB ALL FROM "PHYREC"
  5. 5  !
  6. 7  !  KERMIT For Hewlett-Packard Co.
  7. 8  !  Family 9000 - Series 200/300
  8. 9  !  HP-BASIC (RMB) Workstations
  9. 10 !==========================================================================
  10. 11 ! Revision History:
  11. 12 !------------------------
  12. 13 ! Revision 1.0
  13. 14 ! Original Release Mar 1 1989
  14. 15 !---------------------------------------------------------
  15. 16 ! Revision 1.01  -  Mar 20 1989
  16. 17 ! Two errors in Kreceive decoding &#& and &## Binary Sequences
  17. 18 ! Implemented PROG file transfers
  18. 19 ! Problem with modem disconnecting before Send or Receive
  19. 20 ! Trap for no serial ports found
  20. 21 ! Terminal leaving stray cursors on screen
  21. 22 ! Error Check on remote S packet - non-numeric sent for blk chk type
  22. 23 ! BUGS:
  23. 24 ! Need Trap - SRM looks like 98628 Card
  24. 25 !---------------------------------------------------------
  25. 26 ! Revision 1.02  -  Apr 3 1989
  26. 27 ! Fixed prob with path msi$ not DIM long enough
  27. 28 ! removed pause when remote switch is set on serial card
  28. 29 ! removed trap preventing receive of PROG file type
  29. 30 ! added trap to detect and ignore SRM interfaces
  30. 31 ! added ability to specify any filetype in CONVERT
  31. 32 !==========================================================================
  32. 33 !  To obtain a copy of this software contact:
  33. 34 !
  34. 35 !  |  KERMIT Distributon
  35. 36 !  |  Columbia University
  36. 37 !  |  Center For Computing Activities
  37. 38 !  |  612 W. 115 St.
  38. 39 !  |  New York, N.Y.     10025
  39. 40 ! or
  40. 41 !  |  INTEREX - HP Users Group
  41. 42 !  |  680 Almanor Ave
  42. 43 !  |  Sunnyvale, CA.   94086-3513
  43. 44 !-----------------------------------------------
  44. 45 ! Written By:
  45. 46 ! Andrew Campagnola
  46. 47 ! Hewlett-Packard Co.
  47. 48 ! Mesurement Systems Operation
  48. 49 ! P.O. Box 301
  49. 50 ! Loveland, Colorado  80539-0301
  50. 51 !
  51. 52 ! You're encouraged to write with comments, suggestions,
  52. 53 ! and bug reports.
  53. 54 !==========================================================================
  54. 55  ! KERMIT   Copyright (C) 1981,1988
  55. 56  ! Trustees of Columbia University, New York City, N.Y.
  56. 57  ! Permission is granted to any individual or institution to use, copy or
  57. 58  ! redistribute this software provided it is not sold, and this copyright
  58. 59  ! is retained.
  59. 60  !==========================================================================
  60. 61  ! DISCLAIMER:
  61. 62  ! This software is provided as is.
  62. 63  ! No warantee is made of any kind with respect to this program including,
  63. 64  ! but not limited to, implied warantees of merchantability or fitness for
  64. 65  ! a particular purpose.
  65. 66  ! Neither Hewlett-Packard nor the author shall be liable for errors or
  66. 67  ! incidental damages in connection with the use of this material.
  67. 68 !==========================================================================
  68. 69    CONTROL KBD,3;4,40        ! speed up keyboard
  69. 70    COM Version$[80],K$[180],Setup$[80]
  70. 71    COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  71. 72    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  72. 73    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  73. 74    COM /Frame/ Baud,Data_bits,Stop_bits,On_off$[3],Parity_type$[4]
  74. 75    COM /Frame/ Flow$[10],Hshake$[10]
  75. 76    COM /Portsc/ Sports(1:10)
  76. 77    !========================================================================
  77. 78 Version:Version$="HP-9000  Kermit-RMB  
  78. Release 1.02   3 Apr 1989
  79. "
  80. 79    Active=0
  81. 80    In_term=0
  82. 81    CONTROL CRT,21;1   ! Reset CRT
  83. 82    PRINTER IS CRT
  84. 83    GRAPHICS ON
  85. 84    WINDOW 0,80,26,0
  86. 85    CSIZE 3.5
  87. 86    KEY LABELS OFF
  88. 87   !------------------------------
  89. 88    CLEAR ERROR
  90. 89    GOSUB Config
  91. 90    CALL Kermit
  92. 91   !------------------------------
  93. 92    CONTROL CRT,21;1
  94. 93    KEY LABELS ON
  95. 94    MASS STORAGE IS Cur_msi$
  96. 95    PRINT TABXY(1,Crt_lines);"KERMIT DONE."
  97. 96    CONTROL KBD,3;6,60        ! restore kbd speed
  98. 97    STOP
  99. 98!======================================================================
  100. 99 Config: !
  101. 100   COM /Crt/ Crt_lines,Crt_width
  102. 101   STATUS CRT,9;Crt_width
  103. 102   STATUS CRT,13;Crt_lines
  104. 103   Crt_lines=Crt_lines-7
  105. 104   No_com_ports=0
  106. 105   Com_card=0
  107. 106 !
  108. 107 ! Check For BIN Files Loaded
  109. 108 !
  110. 109   Sbin=0
  111. 110   Dbin=0
  112. 111   Sbin=VAL(SYSTEM$("VERSION: SERIAL"))
  113. 112   Dbin=VAL(SYSTEM$("VERSION: DCOMM "))
  114. 113   IF Sbin=0 OR Dbin=0 THEN 
  115. 114     BEEP 2000,.05
  116. 115     WAIT .05
  117. 116     BEEP 2000,.05
  118. 117   END IF
  119. 118   IF Sbin=0 THEN PRINT "SERIAL BIN not Loaded, LOAD BIN or Continue (F2)"
  120. 119   IF Dbin=0 THEN PRINT "DCOMM  BIN not Loaded, LOAD BIN or Continue (F2)"
  121. 120   IF Dbin=0 OR Sbin=0 THEN PAUSE
  122. 121 !
  123. 122 ! Identify the Com Ports installed
  124. 123 !
  125. 124   ON ERROR GOSUB Sc_err
  126. 125   FOR Sc=8 TO 31
  127. 126     RESET Sc
  128. 127     STATUS Sc,0;Id
  129. 128     SELECT Id
  130. 129     CASE 2
  131. 130       Com_port=Sc
  132. 131       No_com_ports=No_com_ports+1
  133. 132       Com_card=98626              ! COULD BE 98644 IF JUMPER IS CUT
  134. 133       Sports(No_com_ports)=Sc
  135. 134     CASE 52                       ! 98628 or SRM
  136. 135       STATUS Sc,3;Com_protocol   ! SRM=3 Datacomm=1,2
  137. 136       IF Com_protocol<3 THEN     ! Not an SRM Card
  138. 137         Com_port=Sc
  139. 138         No_com_ports=No_com_ports+1
  140. 139         Com_card=98628
  141. 140         Sports(No_com_ports)=Sc
  142. 141       END IF
  143. 142     CASE 66
  144. 143       Com_port=Sc
  145. 144       No_com_ports=No_com_ports+1
  146. 145       Com_card=98644
  147. 146       Sports(No_com_ports)=Sc
  148. 147     CASE 180
  149. 148       BEEP 2000,.05
  150. 149       PRINT "Remote Switch is set on Serial Port ";Sc;" - Port can't be used"
  151. 150     END SELECT
  152. 151   NEXT Sc
  153. 152   OFF ERROR 
  154. 153   IF No_com_ports=0 THEN 
  155. 154     BEEP 
  156. 155     PRINT TABXY(1,Crt_lines);"No Serial Ports Found "
  157. 156   ELSE
  158. 157     REDIM Sports(1:No_com_ports)
  159. 158   END IF
  160. 159   IF No_com_ports>1 THEN 
  161. 160     PRINT USING "////"
  162. 161     PRINT "Serial Ports Found at Select Codes ";
  163. 162     FOR P=1 TO No_com_ports
  164. 163       PRINT Sports(P);
  165. 164     NEXT P
  166. 165     Com_port=Sports(1)
  167. 166     PRINT 
  168. 167     PRINT "Active Port is Select Code  ";Com_port
  169. 168     PRINT "Use Kermit SET PORT Command to Change"
  170. 169   END IF
  171. 170 !
  172. 171 ! Identify Card Model
  173. 172 !
  174. 173   IF No_com_ports>0 THEN 
  175. 174     STATUS Com_port,0;Id
  176. 175     SELECT Id
  177. 176     CASE 2
  178. 177       Com_card=98626              ! COULD BE 98644 IF JUMPER IS CUT
  179. 178     CASE 52
  180. 179       Com_card=98628
  181. 180     CASE 66
  182. 181       Com_card=98644
  183. 182     CASE ELSE
  184. 183       BEEP 
  185. 184       DISP "Unknown Card Type, Reporting Card ID as: ";Id
  186. 185       PAUSE
  187. 186     END SELECT
  188. 187 !
  189. 188 ! Reset the Serial Interface
  190. 189 !
  191. 190     CALL Reset_port
  192. 191   END IF
  193. 192   RETURN 
  194. 193 !------------------------------------------
  195. 194 Sc_err:  !
  196. 195   Id=0
  197. 196   CLEAR ERROR
  198. 197   ERROR RETURN
  199. 198  !-----------------------------------------
  200. 199   END
  201. 200 !=========================================================================
  202. 201 Kinit:SUB Kermit_com_init
  203. 202 Kci:  !
  204. 203     OPTION BASE 1
  205. 204     DIM Misc$[100]
  206. 205     ON ERROR GOSUB Kci_err
  207. 206    !
  208. 207    ! Initialize all constants here
  209. 208    !
  210. 209     COM /Kerm/ INTEGER Maxp,Maxtry,Mypad,Mytmo,Mypchar,Myeol,Myquote
  211. 210     Maxp=94
  212. 211     Maxtry=10
  213. 212     Mypad=0
  214. 213     Mytmo=8                ! my timeout period
  215. 214     Mypchar=0
  216. 215     Myeol=NUM("
  217. ")          ! LF
  218. 216     Myquote=NUM("#")
  219. 217    !
  220. 218     COM /Kerm/ INTEGER Size,Rpsiz,Spsiz,Pad,Capas
  221. 219     Size=0
  222. 220     Rpsiz=94
  223. 221     Spsiz=94
  224. 222     Pad=0
  225. 223     Ptmo=8
  226. 224     Capas=0     ! extended capabilities off
  227. 225    !
  228. 226     COM /Kerm/ INTEGER Image,Parflg,Pktdeb
  229. 227     Remote=0
  230. 228     Image=0
  231. 229     Parflg=0
  232. 230     Turn=0
  233. 231     Lecho=0
  234. 232     Debug=0
  235. 233     Pktdeb=0
  236. 234     Display=8     ! Shut Off Send and receive Packets
  237. 235    !
  238. 236     COM /Kerm/ INTEGER Filnamcnv,Blk_chk,Quote,Eol
  239. 237     Filnamcnv=0
  240. 238     Filecount=0
  241. 239     Timer=1
  242. 240     Quote=NUM("#")
  243. 241     Eol=NUM("
  244. ")
  245. 242     Blk_chk=1
  246. 243    !
  247. 244     COM /Kerm2/ State$[1],Cchksum$[1],Eof_mode$[10],INTEGER Eof_mode,Timer,Ptmo
  248. 245     State$="S"
  249. 246     Eof_mode$="CTRL-Z ON"
  250. 247     Eof_mode=1
  251. 248    !
  252. 249    ! Other COM areas
  253. 250    !
  254. 251     COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  255. 252     COM /Frame/ Baud,Data_bits,Stop_bits,On_off$,Parity_type$
  256. 253     COM /Frame/ Flow$,Hshake$
  257. 254     COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  258. 255     COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  259. 256     COM /Term/ Term_type$[10],S_log,D_log,Filewarn,Discard,@S_log,@D_log
  260. 257     COM /Term/ Kerm_esc$[2],S_log$[80],D_log$[80],INTEGER Remote,Lecho,Turn,Display
  261. 258     COM /Term/ Term_mode$[10]
  262. 259     COM /Path/ Cur_msi$[256],S_path$[256],S_msi$[256],D_path$[256],D_msi$[256]
  263. 260     COM /Mode/ Mode_line,Newline
  264. 261  !
  265. 262  !  Initialize Serial Port
  266. 263     Newline=1           ! Auto append Lf in terminal after Cr
  267. 264     Mode_line=1         ! baud and parity indicator line in terminal on|off
  268. 265     Lecho=1
  269. 266     Baud=9600
  270. 267     Flow$="NONE"
  271. 268     Hshake$="NONE"
  272. 269     Term_type$="VT100"
  273. 270     Term_mode$="NUMERIC"
  274. 271     Data_bits=8
  275. 272     Stop_bits=1
  276. 273     On_off$="OFF"
  277. 274     Parity_type$="NONE"
  278. 275     Filewarn=1
  279. 276   !
  280. 277     REPEAT
  281. 278       Bad_msi=1
  282. 279       Cur_msi$=SYSTEM$("MSI")
  283. 280       MASS STORAGE IS Cur_msi$
  284. 281     UNTIL Bad_msi
  285. 282     Misc=POS(Cur_msi$,"CS80")
  286. 283     IF Misc THEN Cur_msi$=Cur_msi$[1,Misc-1]&Cur_msi$[Misc+4]
  287. 284     Misc$=Cur_msi$
  288. 285     S_msi$=Misc$[POS(Misc$,":")]
  289. 286     D_msi$=Misc$[POS(Misc$,":")]
  290. 287     IF POS(Misc$,"/") THEN          ! get  d_path$
  291. 288       D_path$=Misc$[1,POS(Misc$,":")-1]&"/"
  292. 289       S_path$=Misc$[1,POS(Misc$,":")-1]&"/"
  293. 290     ELSE
  294. 291       D_path$=""
  295. 292       S_path$=""
  296. 293     END IF
  297. 294   !
  298. 295     S_log$=D_path$&"SES_LOG"&D_msi$
  299. 296     D_log$=D_path$&"PKT_LOG"&D_msi$
  300. 297     S_log=0
  301. 298     D_log=0
  302. 299     !
  303. 300     Remote=0
  304. 301     Kermit_exit=0
  305. 302     Kerm_esc$="C" ! CTRL-] C
  306. 303     SUBEXIT    !-----------------------------------------------------
  307. 304 Kci_err:  !
  308. 305     SELECT ERRN
  309. 306     CASE 90! mass storage system error
  310. 307       RESET 7
  311. 308     CASE 76,72,52   ! bad unit code in msi, drive not found
  312. 309       DISP "Mass Storage Volume not On-line please enter a valid MSI "
  313. 310       OUTPUT KBD;Cur_msi$;" H";
  314. 311       ENTER KBD;Cur_msi$
  315. 312       DISP 
  316. 313       Bad_msi=0
  317. 314       ERROR RETURN
  318. 315     CASE 163,167
  319. 316       CLEAR ERROR
  320. 317       ERROR RETURN
  321. 318     CASE ELSE
  322. 319       DISP ERRM$
  323. 320       PAUSE
  324. 321     END SELECT
  325. 322     RETURN 
  326. 323   SUBEND
  327. 324    !================  End of  Kermit Com Init ============================
  328. 325 Kermit:SUB Kermit
  329. 326     IF NOT Active THEN CALL Kermit_com_init
  330. 327     OPTION BASE 1
  331. 328     COM Version$,K$,Setup$
  332. 329     COM /Crt/ Crt_lines,Crt_width
  333. 330     COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  334. 331     COM /Port/ @Out_buff,@Com_out,Output_buffer$ BUFFER
  335. 332     COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$ BUFFER,Com_card
  336. 333     COM /Frame/ Baud,Data_bits,Stop_bits,On_off$,Parity_type$
  337. 334     COM /Frame/ Flow$,Hshake$
  338. 335     COM /Kerm/ INTEGER Maxp,Maxtry,Mypad,Mytmo,Mypchar,Myeol,Myquote
  339. 336     COM /Kerm/ INTEGER Size,Rpsiz,Spsiz,Pad,Capas
  340. 337     COM /Kerm/ INTEGER Image,Parflg,Pktdeb
  341. 338     COM /Kerm/ INTEGER Filnamcnv,Blk_chk,Quote,Eol
  342. 339     COM /Kerm2/ State$,Cchksum$,Eof_mode$,INTEGER Eof_mode,Timer,Ptmo
  343. 340     COM /Term/ Term_type$,S_log,D_log,Filewarn,Discard,@S_log,@D_log
  344. 341     COM /Term/ Kerm_esc$[2],S_log$,D_log$,INTEGER Remote,Lecho,Turn,Display
  345. 342     COM /Term/ Term_mode$
  346. 343     COM /Path/ Cur_msi$,S_path$,S_msi$,D_path$,D_msi$
  347. 344     COM /Mode/ Mode_line,Newline
  348. 345     COM /Def/ Define$(5,10)[30],No_define
  349. 346     COM /Portsc/ Sports(1:10)
  350. 347    !
  351. 348     DIM Kl$[300],Cmds$(1:80)[50]
  352. 349     DIM Init_cmd$[300],Cat$(1:1)[80]
  353. 350     DIM Def_cmd$[30],Filename$[256]
  354. 351     DIM F$[80],F_path$[80],F_msi$[80],Fp$[80],Fm$[80]
  355. 352     DIM Line$[512],Misc$[80],Msg$[80],Misc2$[80],Misc3$[80]
  356. 353     INTEGER Rc,Bdat_item
  357. 354  !
  358. 355  !  Initialize Serial Port
  359. 356     CALL Set_frame(Baud)  ! Other values passed in COM
  360. 357  !
  361. 358     CONTROL CRT,10;1
  362. 359     IF NOT Active THEN    ! Look for HPK_INIT File
  363. 360       Active=1
  364. 361       PRINT TABXY(1,Crt_lines-1)
  365. 362       PRINT Version$
  366. 363       PRINT "? For Help"
  367. 364       PRINT 
  368. 365       Init_file=0
  369. 366       ASSIGN @File TO "HPK_INIT";RETURN Rc
  370. 367       IF NOT Rc THEN Init_file=1
  371. 368     END IF
  372. 369     Remote=0
  373. 370     Kermit_exit=0
  374. 371     Prompt$="KERMIT-RMB>"
  375. 372     DISP 
  376. 373     IF Init_file THEN 
  377. 374       PRINT "KERMIT Initialization: "
  378. 375       PRINT 
  379. 376       Cmds$(1)="TAKE"
  380. 377       Cmds$(2)="HPK_INIT"
  381. 378       GOTO Kermit_exec
  382. 379     END IF
  383. 380     REPEAT     ! Until Exit or Quit Command is given
  384. 381       ON ERROR GOSUB K_error
  385. 382 Parse1:  !
  386. 383       REPEAT   ! Until Kermit Command is Entered
  387. 384         OUTPUT KBD;Prompt$&Kl$;      ! kl$ may have errored kermit line
  388. 385         ENTER KBD;Kl$
  389. 386         Parse_kl(Kl$,Cmds$(*),No_cmds,Prompt$)  ! return Kl$ as Kl$(2..)
  390. 387       UNTIL No_cmds>0
  391. 388       DISP 
  392. 389       Msg$=" Not Recognized         "
  393. 390     !
  394. 391 Kermit_exec:  !
  395. 392  !
  396. 393  ! Notes on Kermit Shell:
  397. 394  !
  398. 395  ! Error Levels  1,2,3,4         That command is not a kermit command
  399. 396  ! Error Levels  20,30,40        That parameter is missing
  400. 397  ! Ni=1                          Valid Kermit Command Not Implemented
  401. 398  ! Err_level     -1              Print Msg$
  402. 399  !
  403. 400       ON ERROR GOSUB K_error
  404. 401       SELECT Cmds$(1)             ! Do a Select on the Kermit Command
  405. 402  !--------------------------------
  406. 403 A:    CASE ""
  407. 404 B:    CASE "BYE"
  408. 405         Ni=1
  409. 406 C:    CASE "CLEAR","CLR"       ! Clear Serial Buffer, cycle transfers
  410. 407         Shutdown
  411. 408         Startup
  412. 409       CASE "CLS"
  413. 410         CLEAR SCREEN
  414. 411       CASE "CLOSE","CLO"
  415. 412         SELECT Cmds$(2)
  416. 413         CASE "PACKET","PAC","P"
  417. 414           D_log=0                 ! Close  PKT_LOG
  418. 415           OUTPUT @D_log;END
  419. 416           ASSIGN @D_log TO *
  420. 417         CASE "SESSION","SES","S"
  421. 418           S_log=0                 ! Close  SES_LOG
  422. 419           OUTPUT @S_log;END
  423. 420           ASSIGN @S_log TO *
  424. 421         CASE ELSE
  425. 422           Err_level=2
  426. 423         END SELECT
  427. 424       CASE "COMMENT","COM"
  428. 425         Ni=1
  429. 426       CASE "CONNECT","C","CON"
  430. 427         IF Cmds$(1)="C" THEN Cmds$(1)="CONNECT"
  431. 428         Remote=1
  432. 429         CALL Terminal
  433. 430         PRINTER IS CRT
  434. 431         PRINT TABXY(1,Crt_lines);
  435. 432       CASE "CONVERT"               ! Unique Command
  436. 433         Misc$=Cmds$(2)    ! filename to convert
  437. 434         IF Cmds$(3)="TO" THEN 
  438. 435           New_type$=Cmds$(4)
  439. 436           IF LEN(Cmds$(5)) THEN Flen=VAL(Cmds$(5))
  440. 437         ELSE
  441. 438           New_type$=Cmds$(3)
  442. 439           IF LEN(Cmds$(4)) THEN Flen=VAL(Cmds$(4))
  443. 440         END IF
  444. 441         IF NOT LEN(New_type$) THEN 
  445. 442           PRINT "Usage:  CONVERT  <Filename> [TO] <Filetype> [Secors]"
  446. 443           PRINT "<Filetype>  -nnnn | ASCII | HPUX | BDAT | PROG "
  447. 444           Supress_echo=1
  448. 445         ELSE
  449. 446           IF Flen THEN 
  450. 447             CALL Convert(Misc$,New_type$,Rc,Flen)
  451. 448           ELSE
  452. 449             CALL Convert(Misc$,New_type$,Rc)
  453. 450           END IF
  454. 451         END IF
  455. 452       CASE "COPY"
  456. 453         IF Cmds$(3)="TO" THEN 
  457. 454           Cmds$(3)=Cmds$(4)      ! Normalize to cmds$(3)=destination
  458. 455         END IF
  459. 456         IF Cmds$(3)[1,1]=":" THEN   ! Add name to msi
  460. 457           Misc$=Cmds$(2)
  461. 458           Parse_filename(Misc$,F_msi$,F_path$)
  462. 459           Misc2$=Misc$      ! save filename
  463. 460           Misc$=Cmds$(3)
  464. 461           Parse_filename(Misc$,F_msi$,F_path$)
  465. 462           Cmds$(3)=F_path$&Misc2$&F_msi$
  466. 463         END IF
  467. 464 !
  468. 465         COPY Cmds$(2) TO Cmds$(3)
  469. 466       CASE "MSI","CD"
  470. 467         ON ERROR GOTO Nocwd
  471. 468         MASS STORAGE IS Cmds$(2)
  472. 469         GOTO Cwdok
  473. 470 Nocwd:  !
  474. 471         Msg$="Can't access: "&Cmds$(2)
  475. 472         Err_level=-1
  476. 473 Cwdok:  ON ERROR GOSUB K_error
  477. 474 D:    CASE "DEFINE","DEF"   ! Define a command macro
  478. 475       !
  479. 476       ! determine if macro is being defined or purged
  480. 477       !
  481. 478         Def_id=0
  482. 479         FOR I=1 TO No_define
  483. 480           IF Define$(I,1)=Cmds$(2) THEN   ! macro exists
  484. 481             Def_id=I
  485. 482             IF No_cmds=2 THEN      ! purge macro
  486. 483               FOR X=1 TO 10
  487. 484                 Define$(Def_id,X)=""
  488. 485               NEXT X
  489. 486               Def_id=-1
  490. 487             END IF
  491. 488           END IF
  492. 489         NEXT I
  493. 490         IF Def_id=0 THEN    ! create a new macro
  494. 491           No_define=No_define+1
  495. 492           Def_id=No_define
  496. 493           Define$(Def_id,1)=Cmds$(2)
  497. 494        !
  498. 495        ! need to pack commands up to comma
  499. 496        !
  500. 497           I=3
  501. 498           Def_cmd=2
  502. 499           REPEAT
  503. 500             IF Cmds$(I)="," THEN 
  504. 501               Define$(Def_id,Def_cmd)=Def_cmd$
  505. 502               Def_cmd=Def_cmd+1
  506. 503               Def_cmd$=""
  507. 504             ELSE
  508. 505               Def_cmd$=Def_cmd$&Cmds$(I)&" "
  509. 506             END IF
  510. 507             I=I+1
  511. 508           UNTIL I=No_cmds+1
  512. 509           Define$(Def_id,Def_cmd)=Def_cmd$
  513. 510           Def_cmd$=""
  514. 511         END IF! define macro
  515. 512        !
  516. 513       CASE "DELETE","DEL","PURGE"
  517. 514         PURGE Cmds$(2)
  518. 515         PRINT "Purged ";Cmds$(2)
  519. 516         Supress_echo=1
  520. 517       CASE "DIAL"           ! Call Terminal and Dial a Modem
  521. 518         Remote=1
  522. 519         Modem_init$="AT L2 C1"
  523. 520         CALL Terminal(Cmds$(2),Modem_init$,"HAYES")
  524. 521       CASE "DO"
  525. 522         Do=0
  526. 523         FOR I=1 TO No_define
  527. 524           IF Cmds$(2)=Define$(I,1) THEN Do=I
  528. 525         NEXT I
  529. 526         IF Do THEN 
  530. 527           PRINT "Executing Macro ";Define$(Do,1)
  531. 528           Shell=1
  532. 529           FOR I=2 TO 10
  533. 530             IF LEN(Define$(Do,I)) THEN 
  534. 531               PRINT "<exec> ";Define$(Do,I)
  535. 532               Kl$=Prompt$&Define$(Do,I)
  536. 533               Parse_kl(Kl$,Cmds$(*),No_cmds,Prompt$)! return Kl$ as Kl$(2..)
  537. 534               GOSUB Kermit_exec
  538. 535             END IF
  539. 536           NEXT I
  540. 537           Shell=0
  541. 538         ELSE
  542. 539           PRINT "Macro: ";Cmds$(2);"  not defined"
  543. 540         END IF
  544. 541       CASE "DUMP"                     ! Unique command to RMB
  545. 542         ON ERROR GOTO No_hexedit
  546. 543         CALL Hex_edit(Cmds$(2))
  547. 544         Supress_echo=1
  548. 545         GOTO Dump_exit
  549. 546 No_hexedit:!
  550. 547         ON ERROR GOSUB No_hexedit_file
  551. 548         Misc$="HPK_MISC"
  552. 549         DISP "Loading Hex Editor, Please Wait ..."
  553. 550         LOADSUB Hex_edit FROM Misc$
  554. 551         DISP 
  555. 552         CALL Hex_edit(Cmds$(2))
  556. 553         GOTO Dump_exit
  557. 554 No_hexedit_file: !
  558. 555         DISP "Cant load Hex Editor  - file: HPK_MISC not found - plese enter path and MSI  "
  559. 556         OUTPUT KBD;Misc$&Source_msi$;
  560. 557         ENTER KBD;Misc$
  561. 558         DISP 
  562. 559         ON ERROR GOTO Dump_exit
  563. 560         RETURN 
  564. 561 Dump_exit:  !
  565. 562       CASE "CAT","DIR"
  566. 563         IF LEN(Cmds$(2)) THEN 
  567. 564           CAT Cmds$(2)
  568. 565         ELSE
  569. 566           CAT 
  570. 567         END IF
  571. 568         Supress_echo=1
  572. 569 E:    CASE "ECHO"                     ! Macro Command
  573. 570         PRINT Kl$
  574. 571         Supress_echo=1
  575. 572       CASE "EDIT"                     ! Unique command to RMB
  576. 573         GOTO No_edit_yet
  577. 574         ON ERROR GOTO Load_editor
  578. 575         Parse_filename(Cmds$(2),F_msi$,F_path$)
  579. 576         IF NOT (LEN(F_msi$)) THEN F_msi$=S_msi$
  580. 577         IF NOT (LEN(F_path$)) THEN F_path$=S_path$
  581. 578         Filename$=F_path$&Cmds$(2)&F_mai$
  582. 579         CALL Edit(Filename$)
  583. 580         GOTO Edit_there
  584. 581 Load_editor:ON ERROR GOSUB K_error
  585. 582         LOADSUB ALL FROM "HPK_EDIT"
  586. 583         CALL Edit(Cmds$(2),S_msi$,S_path$)
  587. 584 Edit_there:  !
  588. 585 No_edit_yet:!
  589. 586         Ni=1
  590. 587       CASE "EXIT"
  591. 588         Kermit_exit=1
  592. 589         PRINTER IS CRT;EOL CHR$(10)
  593. 590 F:    CASE "FINISH"       ! Suspend Remote Server
  594. 591         Ni=1
  595. 592 G:    CASE "GET"          ! Receive file via Server
  596. 593         Ni=1
  597. 594 H:    CASE "HANGUP"             ! Disconnect Modem (lower DTR)
  598. 595         SELECT Com_card
  599. 596         CASE 98626,98644
  600. 597           STATUS Com_port,5;C5
  601. 598           CONTROL Com_port,5;BINAND(C5,254)
  602. 599         CASE 98628
  603. 600         CASE ELSE
  604. 601           DISP "UNKNOWN COM CARD ";Com_card
  605. 602         END SELECT
  606. 603       CASE "HELP","?"               ! ? as first command involkes full help
  607. 604         Kh=0
  608. 605         Help_filename$="HPK_HELP"
  609. 606         REPEAT
  610. 607           ON ERROR GOTO No_help
  611. 608           CALL Kermit_help(Cmds$(*),No_cmds,Kl$)
  612. 609           Kh=1
  613. 610           GOTO Khdone
  614. 611 No_help:  OFF ERROR 
  615. 612           ON ERROR GOTO No_help_file
  616. 613           DISP "Loading Help File"
  617. 614           LOADSUB ALL FROM Help_filename$
  618. 615           GOTO Khdone
  619. 616           DISP 
  620. 617 No_help_file:OFF ERROR 
  621. 618           Help_found=0
  622. 619           DISP "Can't Find File - Give MSI "
  623. 620           OUTPUT KBD;Help_filename$;
  624. 621           ENTER KBD;Help_filename$
  625. 622           IF NOT POS(Help_filename$,":") THEN Kh=1
  626. 623           DISP 
  627. 624 Khdone:        !
  628. 625         UNTIL Kh
  629. 626         Supress_echo=1
  630. 627       CASE "HOST"          ! Send command for HOST execution
  631. 628         Ni=1
  632. 629 I:    CASE "INPUT"         ! Wait on COM Port for this ascii string
  633. 630         Ni=1
  634. 631 L:    CASE "LOCAL"         ! Execute a local BASIC command
  635. 632         ON ERROR GOTO Local_err   !Warning - doesn't trap kbd line execution
  636. 633         OUTPUT KBD;Kl$;" E";
  637. 634         GOTO Local_exit
  638. 635 Local_err: !
  639. 636         PRINT ERRM$
  640. 637 Local_exit:OFF ERROR 
  641. 638         CLEAR LINE
  642. 639       CASE "LOG"        ! Session Log Commands
  643. 640         ON ERROR GOSUB K_error
  644. 641         Slog_try=0      ! Attemps to open file
  645. 642         Dlog_try=0
  646. 643         SELECT Cmds$(2)
  647. 644         CASE "SESSION","S","SES"          ! Activate session logging
  648. 645           S_log=1
  649. 646           IF S_log THEN 
  650. 647             IF LEN(Cmds$(3)) THEN 
  651. 648               Misc$=Cmds$(3)
  652. 649               Parse_filename(Misc$,Misc2$,Misc3$)
  653. 650               IF NOT LEN(Misc$) THEN Misc$="SES_LOG"
  654. 651               IF NOT LEN(Misc2$) THEN Misc2$=D_msi$
  655. 652               IF NOT LEN(Misc3$) THEN Misc3$=D_path$
  656. 653               S_log$=Misc3$&Misc$&Misc2$
  657. 654             END IF
  658. 655           END IF
  659. 656  !
  660. 657           REPEAT
  661. 658             Slog_try=Slog_try+1
  662. 659             ASSIGN @S_log TO S_log$;FORMAT ON,RETURN Rc
  663. 660             IF Rc THEN CREATE S_log$,10000
  664. 661             IF NOT Rc THEN Slog_open=1
  665. 662             IF Rc=76 THEN 
  666. 663               Slog_open=0
  667. 664               Slog_try=4
  668. 665             END IF
  669. 666           UNTIL (NOT Rc) OR (Slog_try>3)
  670. 667           IF Slog_try>3 THEN 
  671. 668             PRINT "CAN'T OPEN ";S_log$
  672. 669             S_log=0
  673. 670           ELSE
  674. 671             PRINT "Session Logging on to ";S_log$
  675. 672           END IF
  676. 673       !
  677. 674         CASE "PACKET","PAC","P"        ! Open Packet (debug) logging
  678. 675           D_log=1
  679. 676           IF D_log THEN 
  680. 677             IF LEN(Cmds$(3)) THEN 
  681. 678               Misc$=Cmds$(3)
  682. 679               Parse_filename(Misc$,Misc2$,Misc3$)
  683. 680               IF NOT LEN(Misc$) THEN Misc$="PKT_LOG"
  684. 681               IF NOT LEN(Misc2$) THEN Misc2$=D_msi$
  685. 682               IF NOT LEN(Misc3$) THEN Misc3$=D_path$
  686. 683               D_log$=Misc3$&Misc$&Misc2$
  687. 684             END IF
  688. 685           END IF
  689. 686         !
  690. 687           REPEAT
  691. 688             Dlog_try=Dlog_try+1
  692. 689             ASSIGN @D_log TO D_log$;RETURN Rc
  693. 690             IF Rc THEN CREATE ASCII D_log$,100
  694. 691             IF NOT Rc THEN Dlog_open=1
  695. 692             IF Rc=76 THEN 
  696. 693               Dlog_open=0
  697. 694               Dlog_try=4
  698. 695             END IF
  699. 696           UNTIL (NOT Rc) OR (Dlog_try>3)
  700. 697           IF Dlog_try>3 THEN PRINT "CAN'T OPEN ";D_log$
  701. 698           IF Dlog_try>3 THEN D_log=0
  702. 699         END SELECT
  703. 700         OFF ERROR 
  704. 701 M:    CASE "MU"
  705. 702         PRINT "Available Memory: ";SYSTEM$("AVAILABLE MEMORY")
  706. 703         Supress_echo=1
  707. 704 N: !
  708. 705 O:    CASE "OUTPUT","OUT"                  ! Pipe Output to Com Port
  709. 706         OUTPUT @Out_buff;Kl$
  710. 707 P:    CASE "PAUSE"                         !Macro command
  711. 708         WAIT VAL(Cmds$(2))
  712. 709       CASE "PRINT","TYPE","MORE"           ! (filename) [device]
  713. 710         Filename$=Cmds$(2)
  714. 711         IF Cmds$(1)[1,1]="T" THEN 
  715. 712           Pdev=CRT
  716. 713         ELSE  ! PRINT COMMAND
  717. 714           IF No_cmds>2 THEN 
  718. 715             Pdev=VAL(Cmds$(3))
  719. 716           ELSE
  720. 717             Pdev=701
  721. 718           END IF
  722. 719         END IF
  723. 720         CALL More(Filename$,Pdev,Cmds$(1))
  724. 721       CASE "PROGRAM","PRO"
  725. 722         Ni=1
  726. 723       CASE "PUSH"  ! NA
  727. 724         Ni=1
  728. 725 Q:    CASE "QUIT","Q","QUI"
  729. 726         Kermit_exit=1
  730. 727 R:    CASE "RECEIVE","REC"      ! RECeive  <Filetype> <FILENAME | , >
  731. 728         SELECT Cmds$(2)
  732. 729         CASE "HP-UX","HPUX","ASCII","BDAT","PROG","SYSTM","BIN",""
  733. 730           Filetype$=Cmds$(2)
  734. 731           F$=Cmds$(3)    ! Filename, MSI, and Path are all part of
  735. 732           F_msi$=""      ! Cmds$(3)
  736. 733           F_path$=""
  737. 734           Rec=0          ! will be sent as "0" if not
  738. 735           Recl=0         ! specified in the command
  739. 736      !
  740. 737           IF No_cmds>3 THEN 
  741. 738             IF Cmds$(4)="," THEN 
  742. 739               Rec=0
  743. 740             ELSE
  744. 741               Rec=VAL(Cmds$(4))
  745. 742             END IF
  746. 743           END IF
  747. 744           IF No_cmds>4 THEN Recl=VAL(Cmds$(5))
  748. 745      !
  749. 746      ! RULES For Filespec:
  750. 747      !
  751. 748      ! 1. If Filename is given only then USE D_msi and D_path.
  752. 749      ! 2. If MSI is given with Filename then DON'T USE D_path.
  753. 750      ! 3. If PATH is given then use it with D_MSI
  754. 751      ! 4. If all three are given use all three.
  755. 752      !
  756. 753      !  Process Filename, MSI, and Path
  757. 754      !
  758. 755           IF LEN(F$) AND F$<>"," THEN 
  759. 756             CALL Parse_filename(F$,F_msi$,F_path$)
  760. 757           END IF
  761. 758      !
  762. 759           IF NOT (LEN(F_msi$)) THEN    ! msi given - invalidate path
  763. 760             F_msi$=D_msi$
  764. 761             F_path$=D_path$
  765. 762           END IF
  766. 763           IF Debug THEN DISP F$,F_msi$,F_path$
  767. 764           CALL K_receive(F$,F_msi$,F_path$,Filetype$,Recl,Rec)
  768. 765         CASE ELSE
  769. 766           PRINT "Syntax:  RECeive   [<Filetype>] [<FILENAME> | , ]  [File Length] "
  770. 767           PRINT "         RECeive    <BDAT>  [<FILENAME> | , ]  [# Records | , ] [Recl] "
  771. 768         END SELECT
  772. 769     !-------------------------------------------------------------
  773. 770         Supress_echo=1
  774. 771       CASE "REMOTE","REM"
  775. 772         Ni=1
  776. 773       CASE "RENAME","REN"
  777. 774         IF Cmds$(3)="TO" THEN 
  778. 775           Cmds$(3)=Cmds$(4)
  779. 776         END IF
  780. 777         RENAME Cmds$(2) TO Cmds$(3)
  781. 778       CASE "RUN"
  782. 779         Ni=1
  783. 780 S:    CASE "SEND","SEN"
  784. 781         IF NOT (LEN(Cmds$(2))) THEN Cmds$(2)="?"
  785. 782         SELECT Cmds$(2)
  786. 783         CASE "?"   ! Syntax Help
  787. 784           PRINT "usage:  SEND  <[Path] Filename [MSI]> [Bdat Item]"
  788. 785           PRINT "Bdat Item: <INTEGER | REAL>"
  789. 786           PRINT 
  790. 787         CASE ELSE
  791. 788           F$=Cmds$(2)
  792. 789           SELECT Cmds$(3)
  793. 790           CASE ""
  794. 791             Bdat_item=0  ! Not specified
  795. 792           CASE "INTEGER","INT","INTEGERS"
  796. 793             Bdat_item=1
  797. 794           CASE "REAL","REALS"
  798. 795             Bdat_item=2
  799. 796           CASE ELSE
  800. 797             Bdat_item=3
  801. 798           END SELECT
  802. 799           CALL K_send(F$,Bdat_item)
  803. 800         END SELECT
  804. 801         Supress_echo=1
  805. 802  !
  806. 803       CASE "SCRIPT","SCR"
  807. 804         Ni=1
  808. 805       CASE "SERVER","SER"
  809. 806         Ni=1
  810. 807  !
  811. 808 Set:  !----------------------------    SET COMMANDS   ---------------------
  812. 809  !
  813. 810       CASE "SET","S"
  814. 811         Cmds$(1)="SET"
  815. 812     !
  816. 813     !  Check for proper number of params ??
  817. 814     !
  818. 815         IF No_cmds=4 THEN          ! make sure all parms exist
  819. 816           ON ERROR GOSUB Valerr_4
  820. 817         ELSE
  821. 818           ON ERROR GOSUB Valerr_3
  822. 819         END IF
  823. 820      !
  824. 821         SELECT Cmds$(2)
  825. 822         CASE "?"
  826. 823           PRINT "BAUD     DEBUG       DEStination (DES)      SOURCE       DISPLAY"
  827. 824           PRINT "DUPLEX   ECHO        HandShake (HS)         ESCAPE       FILE   "
  828. 825           PRINT "FLOW     EOF         INComplete (ON=KEEP)   PORT         MARK   "
  829. 826           PRINT "REMOTE   RETRY       SEND        TAKE       TERM         TIMER     "
  830. 827           PRINT 
  831. 828           PRINT 
  832. 829         CASE ""
  833. 830           Err_level=20                      ! missing second parm
  834. 831         CASE "BAUD","SPEED","B"             ! set baud (rate)
  835. 832           IF POS(Kl$,"B ") THEN Kl$="BAUD"&Kl$[(POS(Kl$,"B"))+1]
  836. 833           Req_baud=VAL(Cmds$(3))
  837. 834           IF NOT Err_level THEN CALL Set_frame(Req_baud)
  838. 835         CASE "BLOCK-CHECK"
  839. 836           Ni=1
  840. 837         CASE "DEBUG"                        ! set debug (on|off)
  841. 838           Debug=1
  842. 839           IF Cmds$(3)="OFF" THEN Debug=0
  843. 840         CASE "DEFAULT","DEF"
  844. 841           Msg$="Use SET SOURCE or SET DESTINATION commands"
  845. 842           Err_level=-1
  846. 843         CASE "DELAY"                ! My Delay before "S" init packet
  847. 844           Sdelay=Sval
  848. 845 Set_destination: !
  849. 846         CASE "DESTINATION","DES"   !(disc drive)
  850. 847           IF NOT LEN(Cmds$(3)) THEN 
  851. 848             Misc$=SYSTEM$("MSI")
  852. 849             Parse_filename(Misc$,D_msi$,D_path$)
  853. 850             D_path$=D_path$&Misc$
  854. 851           ELSE
  855. 852             REPEAT! strip off quotes from msvs
  856. 853               Qp=POS(Cmds$(3),"""""") ! check for quotes in string
  857. 854               IF Qp THEN Cmds$(3)[Qp,Qp]=""
  858. 855             UNTIL Qp=0
  859. 856             Misc$=Cmds$(3)
  860. 857             IF POS(Misc$,"/") THEN  ! get  d_path$
  861. 858               D_path$=Misc$[1,POS(Misc$,":")-1]&"/"
  862. 859               D_msi$=Misc$[POS(Misc$,":")]
  863. 860             ELSE
  864. 861               D_path$=""
  865. 862               D_msi$=Misc$[POS(Misc$,":")]
  866. 863             END IF
  867. 864             ON ERROR GOTO Nodmsi
  868. 865             MASS STORAGE IS D_path$&D_msi$
  869. 866             MASS STORAGE IS Cur_msi$
  870. 867             GOTO Dmsiok
  871. 868 Nodmsi:     PRINT TABXY(1,Crt_lines);"Can't Access: ";D_path$&D_msi$;RPT$(" ",20)
  872. 869 Dmsiok:     OFF ERROR 
  873. 870           END IF
  874. 871 Set_source:      !
  875. 872         CASE "SOURCE"
  876. 873           IF NOT LEN(Cmds$(3)) THEN       ! SYNC WITH SYSTEM$("MSI")
  877. 874             Misc$=SYSTEM$("MSI")
  878. 875             Parse_filename(Misc$,S_msi$,S_path$)
  879. 876             IF LEN(S_path$) THEN S_path$=S_path$&Misc$&"/"
  880. 877           ELSE
  881. 878             REPEAT! strip off quotes from msvs
  882. 879               Qp=POS(Cmds$(3),"""""") ! check for quotes in string
  883. 880               IF Qp THEN Cmds$(3)[Qp,Qp]=""
  884. 881             UNTIL Qp=0
  885. 882             Misc$=Cmds$(3)
  886. 883             Parse_filename(Misc$,S_msi$,S_path$)
  887. 884             IF LEN(S_path$) THEN S_path$=S_path$&Misc$&"/"
  888. 885             ON ERROR GOTO Nosmsi
  889. 886             Cur_msi$=SYSTEM$("MSI")
  890. 887             MASS STORAGE IS S_path$&S_msi$!  check for ms on line
  891. 888             MASS STORAGE IS Cur_msi$
  892. 889             GOTO Smsiok
  893. 890 Nosmsi:     PRINT TABXY(1,Crt_lines);"Can't Access: ";S_path$&S_msi$;RPT$(" ",20)
  894. 891 Smsiok:     OFF ERROR 
  895. 892           END IF
  896. 893         CASE "DISPLAY"          ! Set Display for kermit or terminal
  897. 894           SELECT Cmds$(3)
  898. 895           CASE "OFF"
  899. 896             Display=0           ! Turn off display during file transfer
  900. 897           CASE "ON","8","8 BIT"
  901. 898             Display=8           ! Show control chars on terminal screen
  902. 899           CASE "7","7 BIT"
  903. 900             Display=7
  904. 901           CASE ELSE
  905. 902             Err_level=3
  906. 903           END SELECT
  907. 904         CASE "DUPLEX"               ! Set-Duplex-(HALF|FULL)
  908. 905           Duplex$="FULL"
  909. 906           SELECT Cmds$(3)
  910. 907           CASE "ON","FULL"
  911. 908             Duplex$="FULL"
  912. 909           CASE "OFF","HALF"
  913. 910             Duplex$="HALF"
  914. 911             Ni=1
  915. 912           END SELECT
  916. 913 Se:     CASE "ECHO","LOCAL-ECHO"            ! set echo (local | remote)
  917. 914           Lecho=1
  918. 915           SELECT Cmds$(3)
  919. 916           CASE "OFF","REMOTE"
  920. 917             Lecho=0
  921. 918           CASE "ON","LOCAL",""
  922. 919             Lecho=1
  923. 920           CASE ELSE
  924. 921             Err_level=3
  925. 922           END SELECT
  926. 923         CASE "EOF"                        ! Set-EndOfFile-(CTRL-Z|NONE)
  927. 924           SELECT Cmds$(3)
  928. 925           CASE "CTRL-Z","Z","ON"
  929. 926             Eof_mode$="CTRL-Z"            ! Append ^Z at end of ascii file
  930. 927             Eof_mode=1
  931. 928           CASE "NONE","OFF","NO CTRL-Z"
  932. 929             Eof_mode$="NONE"
  933. 930             Eof_mode=0
  934. 931           CASE ELSE
  935. 932             Err_level=3
  936. 933           END SELECT
  937. 934         CASE "ESCAPE","ESC"                 ! set escape
  938. 935           Kerm_esc$[1,1]=TRIM$(UPC$(Cmds$(3)[1,1]))
  939. 936 Sfi:    CASE "FILE","F"                     ! set file (parameters)
  940. 937           SELECT Cmds$(3)   ![1,3]
  941. 938           CASE "?"
  942. 939             PRINT "NAME     MODE     WARNING (WARN)   SUPERCEDE (SUP)"
  943. 940             PRINT 
  944. 941             PRINT 
  945. 942           CASE "NAME","NAM"            ! Set-File-Name
  946. 943           CASE "TYPE","T","MODE"        ! Set-File-Type
  947. 944             IMAGE=0
  948. 945             SELECT Cmds$(4)
  949. 946             CASE "BINARY","BIN","IMAGE","B"
  950. 947               Image=1
  951. 948             CASE ELSE
  952. 949               Image=0
  953. 950             END SELECT
  954. 951           CASE "WARNING","WARN"         ! Set-File-Warning
  955. 952             Filewarn=1
  956. 953             IF Cmds$(4)="OFF" THEN Filewarn=0
  957. 954           CASE "SUPERCEDE","SUP"        ! Set-File-Supercede
  958. 955             Ni=1
  959. 956           CASE ELSE
  960. 957             Err_level=3
  961. 958           END SELECT
  962. 959         CASE "FLOW-CONTROL","FLOW","FC"  !  Set-FlowControl
  963. 960           SELECT Cmds$(3)
  964. 961           CASE "XON","XOFF","X"
  965. 962             Flow$="XON/XOFF"
  966. 963           CASE "ENQ","ENQ/ACK"
  967. 964             Flow$="ENQ/ACK"
  968. 965           CASE "NONE","OFF"
  969. 966             Flow$="NONE"
  970. 967           CASE ELSE
  971. 968             Err_level=3
  972. 969           END SELECT
  973. 970 Sh:     CASE "HANDSHAKE","HS"   ! TURNAROUND CHAR
  974. 971           Hshake$="NONE"
  975. 972           IF Cmds$(3)="ON" THEN Hshake$="ON"
  976. 973         CASE "IBM"
  977. 974           Ni=1
  978. 975         CASE "INCOMPLETE","INC" ! Set-Incomplete  (KEEP|DISCARD)
  979. 976           Discard=0
  980. 977           SELECT Cmds$(3)
  981. 978           CASE "OFF","DISCARD","DIS"
  982. 979             Discard=1
  983. 980           CASE "ON","KEEP","K"
  984. 981             Discard=0
  985. 982           CASE ELSE
  986. 983             Err_level=3
  987. 984           END SELECT
  988. 985         CASE "INPUT","INP"
  989. 986           Ni=1
  990. 987         CASE "KEY"
  991. 988           Ni=1
  992. 989 Sl:  !
  993. 990 Setport:CASE "PORT","LINE","LIN","POR","P"   ! set port number
  994. 991           IF POS(Kl$,"P ") THEN Kl$="PORT"&Kl$[(POS(Kl$,"P"))+1]
  995. 992           IF Cmds$(3)="?" THEN 
  996. 993             PRINT "Serial Ports:  ";Sports(*)
  997. 994             PRINT USING "//"
  998. 995           ELSE
  999. 996             Shutdown
  1000. 997             Com_port=VAL(Cmds$(3))
  1001. 998             STATUS Com_port,0;Id
  1002. 999             SELECT Id
  1003. 1000            CASE 2
  1004. 1001              Com_card=98626      ! COULD BE 98644 IF JUMPER IS CUT
  1005. 1002            CASE 52
  1006. 1003              Com_card=98628
  1007. 1004            CASE 66
  1008. 1005              Com_card=98644
  1009. 1006            CASE 180
  1010. 1007              BEEP 
  1011. 1008              INPUT "98628 - REMOTE SW IS SET - PLEASE CORRECT ",Dum$
  1012. 1009            END SELECT
  1013. 1010            CALL Reset_port
  1014. 1011          END IF
  1015. 1012          Startup
  1016. 1013 Sm:    CASE "MARKER","MAR","MARK"        ! set start-of-packet character
  1017. 1014          SELECT LEN(Cmds$(3))
  1018. 1015          CASE 1
  1019. 1016            Smark$=Cmds$(3)[1,1]
  1020. 1017          CASE 2
  1021. 1018            Smark$=CHR$(FNCtl(Cmds$(3)[2,2]))
  1022. 1019          CASE >2
  1023. 1020            Err_level=3
  1024. 1021          END SELECT
  1025. 1022        CASE "MODE-LINE","ML"
  1026. 1023          SELECT Cmds$(3)
  1027. 1024          CASE "OFF"
  1028. 1025            Mode_line=0
  1029. 1026          CASE "ON"
  1030. 1027            Mode_line=1
  1031. 1028          END SELECT
  1032. 1029        CASE "MODEM","MOD"
  1033. 1030          SELECT Cmds$(3)
  1034. 1031          CASE "VT100"
  1035. 1032            Term$="VT100"
  1036. 1033          CASE ELSE
  1037. 1034            Err_level=3
  1038. 1035          END SELECT
  1039. 1036 Sn:    CASE "NEWLINE","NL"
  1040. 1037          Newline=1
  1041. 1038          SELECT Cmds$(3)
  1042. 1039          CASE "ON"
  1043. 1040            Newline=1
  1044. 1041          CASE "OFF"
  1045. 1042            Newline=0
  1046. 1043          END SELECT
  1047. 1044 Sp:    CASE "PARITY","PAR"
  1048. 1045          SELECT Cmds$(3)
  1049. 1046          CASE "ODD","EVEN","ZERO","MARK","SPACE","ONE"
  1050. 1047            Parity_type$=Cmds$(3)
  1051. 1048            Data_bits=7
  1052. 1049            On_off$="ON"
  1053. 1050          CASE "NONE"
  1054. 1051            Parity_type$=Cmds$(3)
  1055. 1052            Data_bits=8
  1056. 1053            On_off$="OFF"
  1057. 1054          CASE ""
  1058. 1055            Err_level=30
  1059. 1056          CASE ELSE
  1060. 1057            Err_level=4
  1061. 1058          END SELECT
  1062. 1059     !  CASE "PORT"                       ! same as LINE
  1063. 1060        CASE "PROMPT"
  1064. 1061          Prompt$=Cmds$(3)&">"
  1065. 1062     !
  1066. 1063     !  SET - REMOTE (receive)  KERMIT PARAMETERS
  1067. 1064     !
  1068. 1065 Sr:    CASE "RECEIVE","REC","REMOTE","REM"   ! SET  RECEIVE PARAMETERS
  1069. 1066          ON ERROR GOSUB Valerr_4  ! CMDS$(4) MAY NEED TO BE A VALID NUMBER
  1070. 1067          SELECT Cmds$(3)
  1071. 1068          CASE ""
  1072. 1069            Err_level=30
  1073. 1070          CASE "?"
  1074. 1071            PRINT "END-OF-PACKET (EOP)        PACKET-LENGTH (PL)"
  1075. 1072            PRINT "PAD-CHARACTER (PC)         PADDING (PAD)"
  1076. 1073            PRINT "START-OF-PACKET (MARK)     TIMEOUT (TMO)"
  1077. 1074            PRINT 
  1078. 1075        !
  1079. 1076          CASE "END-OF-PACKET","EOP","EOL"
  1080. 1077          CASE "PACKET-LENGTH","PL"    ! Set-Receive-PacketLength
  1081. 1078            Rpsiz=VAL(Cmds$(4))
  1082. 1079          CASE "PAD-CHARACTER","PC"    ! Set-Receive-PadChar
  1083. 1080            Padchar$=Cmds$(4)
  1084. 1081            Padchar=NUM(Padchar$)
  1085. 1082          CASE "PADDING","PAD"
  1086. 1083            Pad=VAL(Cmds$(4))
  1087. 1084          CASE "PAUSE"
  1088. 1085          CASE "START-OF-PACKET","SOP","MARK"
  1089. 1086            Smark$=Cmds$(4)
  1090. 1087          CASE "TIMEOUT","TMO"                   ! set receive timeout
  1091. 1088            Ptmo=VAL(Cmds$(4))
  1092. 1089          CASE ELSE
  1093. 1090            Err_level=3
  1094. 1091          END SELECT
  1095. 1092          OFF ERROR 
  1096. 1093    !   End Of SET - RECEIVE commands
  1097. 1094    !
  1098. 1095        CASE "RETRY","RET"          ! Set the max retry limit
  1099. 1096          Maxtry=VAL(Cmds$(3))
  1100. 1097        CASE "SERVER"            ! Set Server (Timeout, etc)
  1101. 1098          Ni=1
  1102. 1099     !
  1103. 1100     !  SET - LOCAL (SEND) KERMIT PARAMETERS ============
  1104. 1101     !
  1105. 1102 Ss:    CASE "SEND","SEN"          ! SET-SEND-[Parameter]-[value]
  1106. 1103          ON ERROR GOSUB Valerr_4
  1107. 1104          SELECT Cmds$(3)
  1108. 1105          CASE ""
  1109. 1106            Err_level=30
  1110. 1107          CASE "AT","ATTRIB","ATTRIBUTE"
  1111. 1108            Send_at=1
  1112. 1109            IF POS(Cmds$(4),"OFF") THEN Send_at=0
  1113. 1110          CASE "END-OF-PACKET","EOP","EOL"     ! SET-SEND-EOP
  1114. 1111            Myeol$=Cmds$(4)
  1115. 1112          CASE "PACKET-LENGTH","PL","LEN"      ! Set-Send-Packet Length
  1116. 1113            Spsiz=VAL(Cmds$(4))
  1117. 1114          CASE "PAD-CHARACTER","PC"
  1118. 1115            Padchar$=Cmds$(4)
  1119. 1116          CASE "PADDING","PAD"
  1120. 1117            Mypad=VAL(Cmds$(4))
  1121. 1118          CASE "PAUSE"
  1122. 1119            Ni=1
  1123. 1120          CASE "PREFIX"               ! set-send-prefix-[type]
  1124. 1121            SELECT Cmds$(4)
  1125. 1122            CASE "CONTROL"
  1126. 1123              Myquote$=Cmds$(5)
  1127. 1124            CASE "8BIT"
  1128. 1125              Myprefix$=Cmds$(5)
  1129. 1126            CASE "REPEAT","REP"
  1130. 1127              Myrepeat$=Cmds$(5)
  1131. 1128            END SELECT
  1132. 1129          CASE "TIMEOUT","TIM"       ! set-send-timeout-[value]
  1133. 1130            Mytmo=VAL(Cmds$(4))
  1134. 1131          CASE "START-OF-PACKET","SOP"
  1135. 1132          END SELECT !   SET - SEND options
  1136. 1133    !
  1137. 1134    !  END OF SET-SEND PARAMETERS =====================
  1138. 1135    !
  1139. 1136 St:    CASE "TAKE","TAKE-ECHO"
  1140. 1137          Take_echo=1
  1141. 1138          IF Cmds$(3)="OFF" THEN Take_echo=0
  1142. 1139          IF Cmds$(3)<>"ON" AND Cmds$(3)<>"OFF" THEN Err_level=3
  1143. 1140        CASE "TERMINAL","TERM","T"               ! Set-Terminal
  1144. 1141          Term_type$="VT100"
  1145. 1142          SELECT Cmds$(3)
  1146. 1143          CASE "VT100"
  1147. 1144            Term_type$="VT100"
  1148. 1145          CASE "VT102"
  1149. 1146            Term_type$="VT102"
  1150. 1147          CASE "MODE"
  1151. 1148            SELECT Cmds$(4)
  1152. 1149            CASE "APPL","APPLICATION"
  1153. 1150              Term_mode$="APPL"
  1154. 1151            CASE "NUM","NUMERIC"
  1155. 1152              Term_mode$="NUMERIC"
  1156. 1153            CASE ELSE
  1157. 1154              PRINT "Syntax:  SET TERM MODE <APPL | NUMERIC>"
  1158. 1155              Err_level=4
  1159. 1156            END SELECT
  1160. 1157          CASE ELSE
  1161. 1158            PRINT TABXY(1,Crt_lines);"Terminal Type ";Cmds$(3);"  Not Implemented - How would you like to write one ?"
  1162. 1159          END SELECT
  1163. 1160        CASE "TIMER","TIM"                       ! Set-Timer (ON|OFF)
  1164. 1161          Timer=1
  1165. 1162          IF Cmds$(3)="OFF" THEN Timer=0
  1166. 1163        CASE "TRANSLATION","TRA","TRANS"
  1167. 1164          Ni=1
  1168. 1165        CASE "WINDOW","WIN"
  1169. 1166          Ni=1
  1170. 1167        CASE ELSE
  1171. 1168          Err_level=2
  1172. 1169        END SELECT     ! KERMIT SET COMMAND
  1173. 1170        OFF ERROR 
  1174. 1171   !=======================================================================
  1175. 1172   !            END  OF  SET  COMMANDS
  1176. 1173   !=======================================================================
  1177. 1174 Sz:!
  1178. 1175 Show:CASE "SHOW","SHO"     ! SHOW THE SET PARAMETERS
  1179. 1176        PRINT 
  1180. 1177        SELECT Cmds$(2)
  1181. 1178        CASE "COMMUNICATIONS","COM","COMM","TERMINAL","TERM"
  1182. 1179          PRINT "TERMINAL TYPE",TAB(35);Term_type$
  1183. 1180          PRINT "BAUD RATE",TAB(35);Baud
  1184. 1181          PRINT "COM PORT",TAB(35);Com_port
  1185. 1182          PRINT "LOCAL ECHO",TAB(35);Local_echo
  1186. 1183          PRINT "HANDSHAKE",TAB(35);Hshake$
  1187. 1184          PRINT "PARITY",TAB(35);Parity_type$,On_off$
  1188. 1185          PRINT "FLOW CONTROL",TAB(35);Flow$
  1189. 1186          PRINT "DEBUG",TAB(35);Debug
  1190. 1187          PRINT "MODEM LINES ACTIVE:  ";TAB(35);
  1191. 1188          STATUS Com_port,11;Ml
  1192. 1189          IF BIT(Ml,4) THEN PRINT "CTS  ";
  1193. 1190          IF BIT(Ml,5) THEN PRINT "DSR  ";
  1194. 1191          IF BIT(Ml,6) THEN PRINT "RI  ";
  1195. 1192          IF BIT(Ml,7) THEN PRINT "CD  ";
  1196. 1193          PRINT 
  1197. 1194          PRINT "TERMINAL LINES ACTIVE:  ";TAB(35);
  1198. 1195          STATUS Com_port,5;Ml
  1199. 1196          IF BIT(Ml,0) THEN PRINT "RTS  ";
  1200. 1197          IF BIT(Ml,1) THEN PRINT "DTR  ";
  1201. 1198          PRINT 
  1202. 1199        CASE "FILE"
  1203. 1200          PRINT "CURRENT MSI",TAB(35);Cur_msi$
  1204. 1201          PRINT "DEFAULT MSI",TAB(35);D_path$,D_msi$
  1205. 1202          PRINT "EOF MODE",TAB(35);Eof_mode$
  1206. 1203          PRINT "INCOMPLETE FILE",TAB(35);Discard
  1207. 1204          PRINT "FILE OVERWRITE",TAB(35);File_warn
  1208. 1205          PRINT "TAKE ECHO",TAB(35);Take_echo
  1209. 1206          PRINT "ATTRIBUTE PACKETS",TAB(35);Att_on
  1210. 1207        CASE "LOGGING","LOG"
  1211. 1208          PRINT "PACKET LOGGING",TAB(35);D_log
  1212. 1209          PRINT "PACKET LOG FILE",TAB(35);D_log$
  1213. 1210          PRINT "SESSION LOGGING",TAB(35);S_log
  1214. 1211          PRINT "SESSION LOG FILE",TAB(35);S_log$
  1215. 1212        CASE "MACRO","MAC"
  1216. 1213          IF No_define THEN 
  1217. 1214            PRINT USING VAL$(No_define)&"(10(K,2(X)),/)";Define$(*)
  1218. 1215          ELSE
  1219. 1216            PRINT "No MACROs currently defined"
  1220. 1217          END IF
  1221. 1218        CASE "MODEM"
  1222. 1219          PRINT "NOT IMPLEMENTED"
  1223. 1220        CASE "PROTOCOL"
  1224. 1221          CALL Kstatus
  1225. 1222        CASE "SERVER"
  1226. 1223          PRINT "NOT IMPLEMENTED"
  1227. 1224        CASE ELSE
  1228. 1225          PRINT "Syntax:  COMM , TERMINAL , FILE , LOG , MODEM , MACRO , PROTOCOL "
  1229. 1226        END SELECT
  1230. 1227        PRINT 
  1231. 1228        Supress_echo=1
  1232. 1229     !
  1233. 1230      CASE "SPACE","SPA"
  1234. 1231        IF NOT LEN(Cmds$(2)) THEN Cmds$(2)=D_msi$
  1235. 1232        Disc_space(Cmds$(2),Total,Largest_hole,Hole_sum,Format$)
  1236. 1233        Cmds$(2)=":"&Cmds$(2)[POS(Cmds$(2),",")]
  1237. 1234        CLEAR SCREEN
  1238. 1235        PRINT TABXY(1,Crt_lines);
  1239. 1236        PRINT "Volume:        ";Cmds$(2)
  1240. 1237        PRINT "Format:        ";Format$
  1241. 1238        PRINT "Space:         ";Total;TAB(35);Total*256
  1242. 1239        PRINT "Frags:         ";Hole_sum;TAB(35);Hole_sum*256
  1243. 1240        PRINT "Largest Hole:  ";Largest_hole;TAB(35);Largest_hole*256
  1244. 1241        PRINT 
  1245. 1242        Supress_echo=1
  1246. 1243      CASE "STATISTICS"
  1247. 1244        Ni=1
  1248. 1245      CASE "STATUS","STAT"       !
  1249. 1246        CALL Kstatus
  1250. 1247        Supress_echo=1
  1251. 1248      CASE "SUBMIT","SUB"    ! BATCH PROCESS
  1252. 1249        Ni=1
  1253. 1250 T:   CASE "TAKE","TAK"             ! execute a command file
  1254. 1251        ASSIGN @File TO Cmds$(2);RETURN Rc
  1255. 1252        IF Rc THEN GOTO Take_done
  1256. 1253        Init_file=1
  1257. 1254        Shell=1
  1258. 1255        IF NOT Init_file THEN PRINT TABXY(1,Crt_lines);"KERMIT Initialization File"
  1259. 1256        REPEAT
  1260. 1257          Init_cmd$=""
  1261. 1258          ENTER @File;Init_cmd$
  1262. 1259          Init_cmd$=UPC$(Init_cmd$)
  1263. 1260          Init_cmd$=Init_cmd$[POS(Init_cmd$,"!")+1]
  1264. 1261          Cmt=POS(Init_cmd$,"!")
  1265. 1262          IF Cmt THEN Init_cmd$=Init_cmd$[1,POS(Init_cmd$,"!")-1]      ! extract from line comment
  1266. 1263          IF NOT LEN(TRIM$(Init_cmd$)) THEN GOTO Skip_cmd
  1267. 1264          IF POS(Init_cmd$,"STOP") THEN 
  1268. 1265            Init_file=0
  1269. 1266            Kl$=""
  1270. 1267          ELSE
  1271. 1268            Cmt=POS(Init_cmd$,"COMMENT")
  1272. 1269            IF NOT Cmt THEN 
  1273. 1270              Kl$=Prompt$&Init_cmd$
  1274. 1271              Parse_kl(Kl$,Cmds$(*),No_cmds,Prompt$)! return Kl$ as Kl$(2..)
  1275. 1272              PRINT Cmds$(1)&" ";Kl$
  1276. 1273              GOSUB Kermit_exec
  1277. 1274            END IF
  1278. 1275          END IF
  1279. 1276 Skip_cmd:       !
  1280. 1277        UNTIL Init_file=0
  1281. 1278        Shell=0
  1282. 1279        Supress_echo=1
  1283. 1280 Take_done:DISP 
  1284. 1281      CASE "TRANSMIT","TRANS"     ! Transmit <filename> [format on/off]
  1285. 1282        IF NOT LEN(Cmds$(3)) THEN 
  1286. 1283          IF Cmds$(3)<>"OFF" AND Cmds$(3)<>"ON" THEN 
  1287. 1284            INPUT "Read File with Format ON or OFF ? ",Cmds$(3)
  1288. 1285            Cmds$(3)=UPC$(Cmds$(3))
  1289. 1286          END IF
  1290. 1287          CALL Transmit(Cmds$(2),Cmds$(3))
  1291. 1288        ELSE
  1292. 1289          CALL Transmit(Cmds$(2))
  1293. 1290        END IF
  1294. 1291   !  CASE "TYPE"  ! same as  PRINT
  1295. 1292 V:   CASE "VER","VERSION"
  1296. 1293        PRINT TABXY(1,Crt_lines);Version$
  1297. 1294 W:   CASE "WHO"
  1298. 1295        Ni=1
  1299. 1296 X:   CASE "XYZZY"
  1300. 1297        Msg$="I see no cave here."
  1301. 1298        Err_level=-1
  1302. 1299      CASE ELSE
  1303. 1300 Y:     Err_level=1   ! invalid kermit command
  1304. 1301 Z:!
  1305. 1302      END SELECT  ! KERMIT COMMANDS
  1306. 1303 !-------------------------------------------------------------------------
  1307. 1304   !
  1308. 1305   ! Process Err_level or echo command
  1309. 1306   !
  1310. 1307      SELECT Err_level
  1311. 1308      CASE 0   ! Valid command - check if implemented before echoing
  1312. 1309        IF Ni THEN 
  1313. 1310          PRINT Cmds$(1)&"  "&Kl$&"  NOT IMPLEMENTED"
  1314. 1311        ELSE
  1315. 1312          IF (Display AND (NOT Init_file)) OR (Init_file AND Take_echo) THEN 
  1316. 1313            IF (NOT In_term) AND (NOT Supress_echo) THEN 
  1317. 1314              PRINT Cmds$(1)&" "&Kl$&RPT$(" ",80)! command executed OK
  1318. 1315            END IF
  1319. 1316          END IF
  1320. 1317        END IF
  1321. 1318        Kl$=""
  1322. 1319      CASE -1
  1323. 1320        PRINT Msg$
  1324. 1321      CASE 1
  1325. 1322        PRINT CHR$(129);Cmds$(Err_level);CHR$(128);" not a KERMIT command"
  1326. 1323      CASE 2,3,4
  1327. 1324        Line$=""
  1328. 1325        FOR I=1 TO Err_level-1
  1329. 1326          Line$=Line$&Cmds$(I)&" "
  1330. 1327        NEXT I
  1331. 1328        PRINT Line$&CHR$(129);Cmds$(Err_level);CHR$(128);" ";Msg$
  1332. 1329      CASE 20,30,40
  1333. 1330        Err_level=Err_level/10
  1334. 1331        PRINT "Parameter # ";Err_level;"  Required"
  1335. 1332      CASE ELSE
  1336. 1333      END SELECT
  1337. 1334  !
  1338. 1335      IF Err_level THEN 
  1339. 1336        IF Err_level>1 THEN Kl$=Cmds$(1)&" "
  1340. 1337        IF Err_level>2 THEN Kl$=Kl$&Cmds$(2)&" "
  1341. 1338        IF Err_level>3 THEN Kl$=Kl$&Cmds$(3)&" "
  1342. 1339        IF Err_level=1 THEN 
  1343. 1340          Kl$=""
  1344. 1341        END IF
  1345. 1342        Err_level=0
  1346. 1343      END IF
  1347. 1344      Ni=0
  1348. 1345      Supress_echo=0
  1349. 1346      IF Shell THEN RETURN     ! recursive gosub to kermit command parser
  1350. 1347    UNTIL Remote OR Kermit_exit
  1351. 1348    SUBEXIT
  1352. 1349 !---------------------------------
  1353. 1350 Valerr_4:  ! BAD VALUE IN SET-RECEIVE
  1354. 1351    Err_level=4
  1355. 1352    IF NOT LEN(Cmds$(4)) THEN Err_level=40
  1356. 1353    ERROR RETURN
  1357. 1354    RETURN 
  1358. 1355 !------------------------------------
  1359. 1356 Valerr_3:!
  1360. 1357    Err_level=3
  1361. 1358    IF NOT LEN(Cmds$(3)) THEN Err_level=30  ! missing third parameter
  1362. 1359    ERROR RETURN
  1363. 1360    RETURN 
  1364. 1361 !------------------------------------------
  1365. 1362 K_error: !
  1366. 1363    SELECT ERRN
  1367. 1364    CASE 76        ! INCORRECT MSVS
  1368. 1365      PRINT ERRM$
  1369. 1366      Rc=76
  1370. 1367      ERROR RETURN
  1371. 1368    CASE 59        ! EOF
  1372. 1369      Init_file=0
  1373. 1370      PRINT "End OF File"
  1374. 1371      ERROR RETURN
  1375. 1372    CASE ELSE
  1376. 1373      PRINT "KERMIT: ";ERRM$
  1377. 1374      ERROR RETURN
  1378. 1375    END SELECT
  1379. 1376    RETURN 
  1380. 1377 !-----------------------------------------
  1381. 1378  SUBEND
  1382. 1379 ! =====================================================================
  1383. 1380 Parser:SUB Parse_kl(Kl$,Cmds$(*),No_cmds,Prompt$)
  1384. 1381 Parse:!
  1385. 1382    Kl$=TRIM$(UPC$(Kl$))
  1386. 1383    DIM Kl_return$[100]
  1387. 1384    MAT Cmds$= ("")
  1388. 1385    Begin_cmd=POS(Kl$,Prompt$)+LEN(Prompt$)
  1389. 1386    IF Begin_cmd=LEN(Prompt$) THEN SUBEXIT
  1390. 1387    Kl$=TRIM$(Kl$[Begin_cmd,LEN(Kl$)])   ! SEPARATE OFF PROMPT
  1391. 1388    I=0
  1392. 1389    REPEAT
  1393. 1390      I=I+1
  1394. 1391      Cmd_end=POS(Kl$," ")
  1395. 1392      IF Cmd_end=0 THEN      ! IF NO BLANKS THEN KL$= LAST COMMAND
  1396. 1393        Cmds$(I)=Kl$[1,80]
  1397. 1394        No_cmds=I
  1398. 1395        Parse_done=1
  1399. 1396      ELSE
  1400. 1397        Cmds$(I)=Kl$[1,Cmd_end-1]
  1401. 1398      END IF
  1402. 1399      IF I=2 THEN Kl_return$=Kl$         ! No, Return Null if single cmd
  1403. 1400      Kl$=TRIM$(Kl$[Cmd_end+1])          ! TRUNCATE KL$
  1404. 1401    !
  1405. 1402    ! Return the argument line (cmd 2-end) as Kl$
  1406. 1403    !
  1407. 1404   !
  1408. 1405   ! Eliminate any Quote Marks in Command
  1409. 1406   !
  1410. 1407      REPEAT
  1411. 1408        Qm=POS(Cmds$(I),"""")
  1412. 1409        IF Qm THEN Cmds$(I)[Qm,Qm]=" "
  1413. 1410      UNTIL Qm=0
  1414. 1411      Cmds$(I)=TRIM$(Cmds$(I))
  1415. 1412   !
  1416. 1413    UNTIL Parse_done
  1417. 1414    Kl$=Kl_return$
  1418. 1415  SUBEND
  1419. 1416 !=========================================================================
  1420. 1417 Transmit:SUB Transmit(Filename$,OPTIONAL Fmt$)
  1421. 1418 Tr:!
  1422. 1419    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  1423. 1420    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$ BUFFER,Com_card
  1424. 1421    DIM Line$[256],Out_buff$[512] BUFFER,K$[80],A$[1]
  1425. 1422    REAL Real_no
  1426. 1423    INTEGER Int_no,Slow,Abort_txmit
  1427. 1424  !
  1428. 1425  ! PRINTER IS CRT;EOL ("
  1429. "),WIDTH OFF
  1430. 1426    ON ERROR GOSUB Txmit_err
  1431. 1427    Fmt_onoff$="ON"
  1432. 1428    IF NPAR>1 THEN Fmt_onoff$=Fmt$
  1433. 1429    REPEAT
  1434. 1430      IF Fmt_onoff$="OFF" THEN 
  1435. 1431        ASSIGN @File TO Filename$;FORMAT OFF,RETURN Rc
  1436. 1432      ELSE
  1437. 1433        ASSIGN @File TO Filename$;FORMAT ON,RETURN Rc
  1438. 1434      END IF
  1439. 1435      IF Rc<>0 THEN  ! File Couldn't Be Opened
  1440. 1436        DISP "Can't open file:  ";Filename$;"  (blank name to abort)"
  1441. 1437        OUTPUT KBD;Filename$;" H";
  1442. 1438        ENTER KBD;Filename$
  1443. 1439        Filename$=TRIM$(Filename$)
  1444. 1440        DISP 
  1445. 1441        IF NOT (LEN(Filename$)) THEN SUBEXIT
  1446. 1442      END IF
  1447. 1443    UNTIL Rc=0
  1448. 1444  !
  1449. 1445    DISP "Transmitting FILE: ";Filename$;"   CTRL-C to Exit   CTRL-S  Screen"
  1450. 1446 Get_type:STATUS @File,1;File_type
  1451. 1447    SELECT File_type
  1452. 1448    CASE 2    ! BDAT
  1453. 1449      INPUT "ASCII / INTEGERS / REALS  ?  [ A / I / R ] ",Data_type$
  1454. 1450    CASE 3    ! ASCII
  1455. 1451      Data_type$="ASCII"
  1456. 1452    CASE 4    ! HPUX
  1457. 1453      Data_type$="ASCII"
  1458. 1454    END SELECT
  1459. 1455    ON END @File GOTO Txmit_done
  1460. 1456    ON KBD,2 GOSUB K_serve
  1461. 1457    Startup
  1462. 1458    Scr_echo=1
  1463. 1459    LOOP
  1464. 1460    EXIT IF Abort_txmit=1
  1465. 1461      SELECT UPC$(Data_type$[1,1])
  1466. 1462      CASE "A"
  1467. 1463        ENTER @File;Line$   ! Enter the line and convert to Ascii
  1468. 1464        OUTPUT @Out_buff;Line$     ! Line Used for DMA Transmit
  1469. 1465        IF Scr_echo THEN PRINT Line$
  1470. 1466      CASE "R"
  1471. 1467        DISP "Transmitting REALS from FILE: ";File_name$
  1472. 1468        LOOP
  1473. 1469          ENTER @File;Real_no
  1474. 1470          DISP "TRANSMITTING RECORD # ";Rec,Line$
  1475. 1471          OUTPUT @Out_buff;Real_no   ! This Will Convert REAL to Ascii
  1476. 1472          IF Scr_echo THEN PRINT Real_no
  1477. 1473        END LOOP
  1478. 1474      CASE "I"
  1479. 1475        ENTER @File;Int_no
  1480. 1476        OUTPUT @Out_buff;Int_no
  1481. 1477        IF Scr_echo THEN PRINT Int_no
  1482. 1478      CASE ELSE
  1483. 1479        BEEP 
  1484. 1480        INPUT "BAD DATA TYPE - INPUT AGAIN ",Data_type$
  1485. 1481      END SELECT
  1486. 1482      Rec=Rec+1
  1487. 1483      GOSUB Response
  1488. 1484    END LOOP
  1489. 1485 Txmit_done:  !
  1490. 1486    INPUT "Enter any End-of-file mark to send: ",Endofile$
  1491. 1487    IF LEN(Endofile$) THEN 
  1492. 1488      OUTPUT @Out_buff;Endofile$
  1493. 1489    END IF
  1494. 1490    DISP "File Transfer Complete "
  1495. 1491    ASSIGN @File TO *
  1496. 1492    OFF ERROR 
  1497. 1493    OFF KBD
  1498. 1494    Shutdown
  1499. 1495    SUBEXIT    ! Return to Kermit
  1500. 1496 !-----------------------------------------------------------------------
  1501. 1497 Response:!
  1502. 1498    DISABLE 
  1503. 1499    IF Com_card=98628 THEN 
  1504. 1500      STATUS Com_port,5;In_length
  1505. 1501    ELSE
  1506. 1502      STATUS @In_buff,4;In_length
  1507. 1503    END IF
  1508. 1504  !
  1509. 1505    WHILE In_length
  1510. 1506      ENTER @In_buff USING "#,A";A$
  1511. 1507      Char=NUM(A$)
  1512. 1508 Handle_char: !
  1513. 1509      SELECT Char
  1514. 1510      CASE 32 TO 126      ! sp to ~
  1515. 1511        PRINT A$;
  1516. 1512    !-----------------------------------------
  1517. 1513    ! SELECTED CONTROL CHARACTERS
  1518. 1514    !-----------------------------------------
  1519. 1515      CASE 5                        !""         ! ENQ/ACK
  1520. 1516        OUTPUT @Out_buff;CHR$(6);
  1521. 1517      CASE 10
  1522. 1518        PRINT "
  1523. ";
  1524. 1519      CASE 13
  1525. 1520        PRINT "";
  1526. 1521      CASE 7
  1527. 1522        BEEP 800,.1
  1528. 1523      CASE 8                          !     Backspace
  1529. 1524        STATUS CRT,0;Cx
  1530. 1525        CONTROL CRT,0;MAX(Cx-1,1)
  1531. 1526      CASE 17    !
  1532. 1527        K$=KBD$
  1533. 1528        ENABLE 
  1534. 1529        RETURN 
  1535. 1530      CASE ELSE
  1536. 1531        WAIT .3
  1537. 1532      END SELECT
  1538. 1533 Skip_cp:   !
  1539. 1534      IF Com_card=98628 THEN 
  1540. 1535        STATUS Com_port,5;In_length
  1541. 1536      ELSE
  1542. 1537        STATUS @In_buff,4;In_length
  1543. 1538      END IF
  1544. 1539    END WHILE
  1545. 1540    ENABLE 
  1546. 1541    RETURN 
  1547. 1542 !--------------------------------------
  1548. 1543 Txmit_err:  !
  1549. 1544    BEEP 
  1550. 1545    DISP ERRM$&"  PAUSED "
  1551. 1546    PAUSE
  1552. 1547    RETURN 
  1553. 1548!---------------------------------------
  1554. 1549 K_serve: !
  1555. 1550    K$=KBD$
  1556. 1551    SELECT K$
  1557. 1552    CASE " E","  E"
  1558. 1553      Abort_txmit=0
  1559. 1554    CASE ""            ! CTRL-S
  1560. 1555      IF Scr_echo THEN 
  1561. 1556        Scr_echo=0
  1562. 1557      ELSE
  1563. 1558        Scr_echo=1
  1564. 1559      END IF
  1565. 1560    CASE ELSE
  1566. 1561      Abort_txmit=1
  1567. 1562    END SELECT
  1568. 1563    Ok_cont=1
  1569. 1564    RETURN 
  1570. 1565  SUBEND
  1571. 1566! ======================================================================
  1572. 1567  SUB Terminal(OPTIONAL Phone$,Modinit$,Modem$)
  1573. 1568    OPTION BASE 1
  1574. 1569    COM Version$,K$,Setup$
  1575. 1570    COM /Crt/ Crt_lines,Crt_width
  1576. 1571    COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  1577. 1572    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  1578. 1573    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$ BUFFER,Com_card
  1579. 1574    COM /Frame/ Baud,Data_bits,Stop_bits,On_off$[3],Parity_type$[4]
  1580. 1575    COM /Frame/ Flow$,Hshake$
  1581. 1576    COM /Term/ Term_type$[10],S_log,D_log,Filewarn,Discard,@S_log,@D_log
  1582. 1577    COM /Term/ Kerm_esc$[2],S_log$,D_log$,INTEGER Remote,Lecho,Turn,Display
  1583. 1578    COM /Term/ Term_mode$
  1584. 1579    COM /Path/ Cur_msi$,S_path$,S_msi$,D_path$,D_msi$
  1585. 1580    COM /Mode/ Mode_line,Newline
  1586. 1581 !
  1587. 1582    DIM A$[80],Hlchar$[1],File_buff$[256],Esc_seq$[5]
  1588. 1583    DIM Key1$[1],Key2$[1],Key3$[1]
  1589. 1584    INTEGER Cc,Cl,Cx,Cy,Hl,Hlx,Hly,Ie,If,Il
  1590. 1585    INTEGER Key1,Key2,Key3,Oe,Of,Ol,Pn
  1591. 1586    INTEGER Max_buff
  1592. 1587    Max_buff=MAXLEN(File_buff$)
  1593. 1588    DIM Line$[256]
  1594. 1589    DIM Dial_ext$[80]
  1595. 1590 Term:!
  1596. 1591    Blink=.2                               ! cursor speed
  1597. 1592    In_term=1                       ! In-Terminal Flag
  1598. 1593    SYSTEM PRIORITY 0               ! In case terminal is accidentally
  1599. 1594                                    ! entered recursively form kermit
  1600. 1595    !-------------------------------]
  1601. 1596    ! Interrupt Levels for TERM:
  1602. 1597    !
  1603. 1598    ! 1- Idle Loop - Receive Char
  1604. 1599    !    ON TIMEOUT - Com_port
  1605. 1600    !    ON CYCLE Blink Cursor
  1606. 1601    ! 3- ON KBD Send Character KBD
  1607. 1602    ! 4-
  1608. 1603    ! 5- ON INTR COM_PORT
  1609. 1604    !--------------------------------
  1610. 1605    PRINTER IS CRT;EOL (CHR$(10)),WIDTH OFF
  1611. 1606    CONTROL CRT,21;1                     ! clear screen and color map
  1612. 1607    IF NOT Debug THEN CONTROL CRT,10;0   ! CURSOR OFF
  1613. 1608    CONTROL CRT,0;1,1                    ! home cursor
  1614. 1609    Hlx=1                                ! cursor highlight position
  1615. 1610    Hly=1
  1616. 1611   !------------------  SET  ON-EVENTs  Before TRANSFER starts
  1617. 1612    CALL Shutdown        !shutoff transfers if on
  1618. 1613    SELECT Com_card
  1619. 1614    CASE 98626,98644
  1620. 1615      CONTROL Com_port,5;1+2            ! Force DTR and RTS Active
  1621. 1616      IF Hshake$="NONE" THEN            ! Disable Modem HS Lines
  1622. 1617        CONTROL Com_port,12;128+32+16   ! 128=DTR  32=RTS  16=CTS
  1623. 1618      ELSE
  1624. 1619        CONTROL Com_port,12;0       ! Enable Modem HS Lines
  1625. 1620      END IF
  1626. 1621      ENABLE INTR Com_port;8+4
  1627. 1622    CASE 98628
  1628. 1623      CONTROL Com_port,8;1+2        ! RTS  DTR  Set Active
  1629. 1624      CONTROL Com_port,13;164       ! INT MASK  UART/lost car/break
  1630. 1625    ! CONTROL 23; for HS Lines
  1631. 1626    END SELECT
  1632. 1627   !----------------------------------
  1633. 1628    ON INTR Com_port,5 GOSUB Term_intr
  1634. 1629    ON ERROR GOSUB Term_err
  1635. 1630    ON KBD,3 GOSUB Send_char
  1636. 1631    ON TIMEOUT Com_port,10 GOSUB Com_tmo
  1637. 1632    IF NOT Debug THEN ON CYCLE Blink,1 GOSUB Blink
  1638. 1633    CALL Startup
  1639. 1634    GOSUB Disp_modeline
  1640. 1635    IF NPAR THEN GOSUB Dial_modem
  1641. 1636   !
  1642. 1637    REPEAT
  1643. 1638      SELECT Com_card
  1644. 1639      CASE 98626,98644
  1645. 1640        STATUS @In_buff,3;Fp,In_length,Ep
  1646. 1641      CASE 98628
  1647. 1642        STATUS Com_port,5;In_length
  1648. 1643      END SELECT
  1649. 1644      IF Debug THEN 
  1650. 1645        IF Com_card=98628 THEN 
  1651. 1646        ELSE
  1652. 1647          STATUS @Out_buff,4;Out_length
  1653. 1648          DISP "INBOUND: ";In_length,"OUTBOUND:  ";Out_length
  1654. 1649        END IF
  1655. 1650      END IF
  1656. 1651     !
  1657. 1652      IF In_length THEN 
  1658. 1653        GOSUB Receive_char
  1659. 1654      END IF
  1660. 1655    UNTIL Remote=0             ! terminal escape seq trapped in Send_char
  1661. 1656    CONTROL CRT,10;1           ! restore system cursor
  1662. 1657    IF Hl THEN GOSUB Blink     ! remove cursor turds
  1663. 1658    In_term=0                  ! notify Kermit we're out
  1664. 1659    SUBEXIT
  1665. 1660 !========================================================================
  1666. 1661 Disp_modeline:!
  1667. 1662    GCLEAR
  1668. 1663    IF Mode_line THEN 
  1669. 1664      WINDOW 0,80,26,0
  1670. 1665      MOVE 0,26
  1671. 1666      CSIZE 3
  1672. 1667      Kesc_char$=CHR$(NUM(Kerm_esc$[1,1])+64)
  1673. 1668      LABEL "ESC: ^";Kesc_char$;"C  ";Baud;Data_bits;Parity_type$;"  ";On_off$
  1674. 1669    END IF
  1675. 1670    RETURN 
  1676. 1671 !-------------------------------------------------------------------------
  1677. 1672 Term_intr: !
  1678. 1673    CALL Com_interrupt
  1679. 1674 !
  1680. 1675 ! ON INTR BRANCHES Must be setup with transfers off
  1681. 1676 !
  1682. 1677    Shutdown
  1683. 1678!   ON INTR Com_port,5 GOSUB Term_intr  !????????????????????????
  1684. 1679    SELECT Com_card
  1685. 1680    CASE 98628
  1686. 1681      CONTROL Com_port,13;164      ! MASK  4=UART  32=lost carr 128=break
  1687. 1682    CASE 98626,98644
  1688. 1683      ON INTR Com_port,1 GOSUB Term_intr
  1689. 1684      ENABLE INTR Com_port;8+4
  1690. 1685    END SELECT
  1691. 1686    ON ERROR GOSUB Term_err
  1692. 1687    Startup
  1693. 1688    RETURN 
  1694. 1689 !----------------------------------------------------------------------
  1695. 1690 Blink:!
  1696. 1691    IF NOT Hl THEN 
  1697. 1692      IF B THEN PAUSE
  1698. 1693   !
  1699. 1694   ! Produce underscore at current print position
  1700. 1695   !
  1701. 1696   !-----------
  1702. 1697   !
  1703. 1698   ! Establish the current (legal) print position
  1704. 1699   ! And read the crt character at that position
  1705. 1700   !
  1706. 1701      DISABLE        ! disable kbd interrupt
  1707. 1702      STATUS CRT,0;Hlx,Hly
  1708. 1703      Hly=MAX(Hly,1)
  1709. 1704      IF Hly>Crt_lines THEN 
  1710. 1705        Need_scroll=1
  1711. 1706        Hly=MIN(Crt_lines,Hly)    ! hlx=20 after CR on line 19
  1712. 1707      END IF
  1713. 1708    !
  1714. 1709      IF Hlx>80 THEN          ! fixes bug with pos 81 printing in pos 80
  1715. 1710        Hlx=80
  1716. 1711        Wrap=1
  1717. 1712        CONTROL CRT,0;Hlx,Hly ! move to 80
  1718. 1713        IF Hly<=Crt_lines THEN ENTER CRT USING "#,K";Hlchar$
  1719. 1714      ELSE
  1720. 1715        ! leave cx and cy where they are
  1721. 1716        IF Hly<=Crt_lines THEN ENTER CRT USING "#,K";Hlchar$
  1722. 1717      END IF
  1723. 1718    !
  1724. 1719    ! If crt char is null then make it a space
  1725. 1720    !
  1726. 1721      IF Hlchar$="" THEN Hlchar$=" "
  1727. 1722      STATUS CRT,4;Dfm   ! Check Display Functions Mode
  1728. 1723      IF NOT Dfm THEN    ! Don't display CHR$(132) with Display functions on
  1729. 1724    !
  1730. 1725    ! Draw (or redraw) the character with an underscore
  1731. 1726    !
  1732. 1727        PRINT TABXY(Hlx,Hly);CHR$(132);Hlchar$;CHR$(128);
  1733. 1728      END IF
  1734. 1729    !
  1735. 1730    ! Wrap flag indicates that the cursor has moved to a new line
  1736. 1731    !
  1737. 1732      IF Need_scroll THEN 
  1738. 1733        PRINT 
  1739. 1734        Need_scroll=0
  1740. 1735      END IF
  1741. 1736  !
  1742. 1737      IF Wrap THEN              ! wrap around, but leave hlx,hly at 81,hly
  1743. 1738        CONTROL CRT,0;1,Hly+1
  1744. 1739        Wrap=0
  1745. 1740      ELSE
  1746. 1741        CONTROL CRT,0;Hlx,Hly   ! highlighting pushes cursor ahead 1 pos
  1747. 1742      END IF
  1748. 1743    !
  1749. 1744      Hl=1
  1750. 1745      ENABLE 
  1751. 1746  ! END IF
  1752. 1747  !
  1753. 1748    ELSE      !============================================================
  1754. 1749 Unblink: !
  1755. 1750 Ub:!
  1756. 1751  ! Un-blink, remove the underscore
  1757. 1752  !
  1758. 1753      DISABLE 
  1759. 1754      IF Bld THEN PAUSE
  1760. 1755  !
  1761. 1756  !  Record current print position
  1762. 1757  !  Move to underscore highlight
  1763. 1758  !
  1764. 1759      STATUS CRT,0;Cx,Cy      ! remember current cursor
  1765. 1760      IF Ub THEN PAUSE
  1766. 1761      !
  1767. 1762      IF Cy>Crt_lines THEN 
  1768. 1763        Need_scroll=1
  1769. 1764  !  Cy=Crt_lines                 ! leave cy=20
  1770. 1765  !   Cy=MIN(Crt_lines,Cy)
  1771. 1766      END IF
  1772. 1767      CONTROL CRT,0;Hlx,Hly   ! locate to old cursor position
  1773. 1768  !
  1774. 1769  ! Enter the crt char at the old underscore
  1775. 1770  !
  1776. 1771      IF Hly<=Crt_lines THEN ENTER CRT USING "#,K";Hlchar$  ! #A doesn't enter null
  1777. 1772  !
  1778. 1773  ! The underscore can't be a null (remove this code)
  1779. 1774  !
  1780. 1775  ! CRT space characters get entered as nulls ???
  1781. 1776  !
  1782. 1777      IF Hlchar$="" THEN 
  1783. 1778        Hlchar$=" "                                ! avoid null
  1784. 1779      ELSE  ! we have just cleared a character at the end of the line - move
  1785. 1780        IF Cx=80 THEN     ! wrap around
  1786. 1781          IF Hlx=80 THEN 
  1787. 1782            Cy=MIN(Crt_lines,Cy+1)
  1788. 1783            Cx=1
  1789. 1784          END IF
  1790. 1785        END IF
  1791. 1786      END IF
  1792. 1787   !
  1793. 1788   ! redraw the character without the underscore
  1794. 1789   !
  1795. 1790      STATUS CRT,4;Dfm
  1796. 1791      IF NOT Dfm THEN 
  1797. 1792        PRINT TABXY(Hlx,Hly);CHR$(128);Hlchar$;        ! unhighlight
  1798. 1793      END IF
  1799. 1794   !
  1800. 1795   ! Restore the current print position
  1801. 1796   !
  1802. 1797      IF Need_scroll THEN 
  1803. 1798        PRINT 
  1804. 1799        Need_scroll=0
  1805. 1800      END IF
  1806. 1801   !
  1807. 1802      CONTROL CRT,0;Cx,Cy
  1808. 1803      Hl=0
  1809. 1804      ENABLE 
  1810. 1805    END IF  ! hl on or not
  1811. 1806    IF Debug THEN ON CYCLE Blink,1 GOSUB Blink
  1812. 1807    RETURN 
  1813. 1808 !-----------------------------------------------------------------------
  1814. 1809 Dial_modem:!
  1815. 1810    STATUS Com_port,10;Uart
  1816. 1811 !  Dial_ext$=",,,add your phone card # here "
  1817. 1812    IF NPAR>1 THEN 
  1818. 1813      OUTPUT @Out_buff;Modinit$
  1819. 1814    ELSE
  1820. 1815      OUTPUT @Out_buff;"AT L2 C1 "
  1821. 1816    END IF
  1822. 1817    WAIT .5
  1823. 1818    OUTPUT @Out_buff;"ATDT"&Phone$&Dial_ext$
  1824. 1819    RETURN 
  1825. 1820  !------------------------------------------------
  1826. 1821 Send_char:!
  1827. 1822 Sc:!
  1828. 1823    K$=KBD$
  1829. 1824 K: LOOP
  1830. 1825      IF NOT LEN(K$) THEN 
  1831. 1826        GOSUB Receive_char
  1832. 1827        K$=KBD$  ! Check For any keys pressed during Receive_char
  1833. 1828        IF NOT LEN(K$) THEN RETURN 
  1834. 1829      END IF
  1835. 1830 !
  1836. 1831 ! Process K$
  1837. 1832 !----------------------------
  1838. 1833 ! Fumction Key           >
  1839. 1834 ! CTRL-Function Key       >
  1840. 1835 ! Ascii Key             a-Z
  1841. 1836 ! CTRL-Ascii Key        -
  1842. 1837 !----------------------------
  1843. 1838      Key1$=K$[1,1]
  1844. 1839      Key1=NUM(Key1$)
  1845. 1840      K$=K$[2]
  1846. 1841      IF Key1=255 THEN         ! Function Key
  1847. 1842        Key2=NUM(K$)
  1848. 1843        Key2$=CHR$(Key2)
  1849. 1844        K$=K$[2]
  1850. 1845  !
  1851. 1846        IF Key2=255 THEN        ! CTRL + Function Key
  1852. 1847          Key3=NUM(K$)
  1853. 1848          Key3$=CHR$(Key3)
  1854. 1849          K$=K$[2]
  1855. 1850          SELECT Key3$
  1856. 1851          ! Not using any CTRL-Function Keys
  1857. 1852          CASE "E"   ! E
  1858. 1853            IF Term_mode$="APPL" THEN OUTPUT @Out_buff;"OM";
  1859. 1854          END SELECT
  1860. 1855        ELSE                             ! Function Key    >
  1861. 1856          SELECT Key2$
  1862. 1857          CASE "E","X"                   ! ENTER
  1863. 1858            IF Newline THEN 
  1864. 1859              OUTPUT @Out_buff;"
  1865. ";  ! CR-LF
  1866. 1860              IF Lecho THEN 
  1867. 1861                IF Hl THEN GOSUB Blink
  1868. 1862                PRINT "
  1869. ";
  1870. 1863              END IF
  1871. 1864            ELSE
  1872. 1865              OUTPUT @Out_buff;"";
  1873. 1866              IF Lecho THEN PRINT "";
  1874. 1867            END IF
  1875. 1868 !-----------------------------------------------------------
  1876. 1869 Vt100:! vt-100 Esc Sequences implemented here                         VT100
  1877. 1870 !-----------------------------------------------------------
  1878. 1871          CASE "B"                       ! Backspace (Del)
  1879. 1872            OUTPUT @Out_buff;CHR$(8);
  1880. 1873            IF Lecho THEN PRINT "";
  1881. 1874          CASE "<"                       ! Left Arrow
  1882. 1875            OUTPUT @Out_buff;"D";
  1883. 1876            STATUS CRT,0;Px,Py
  1884. 1877            CONTROL CRT,0;MAX(1,Px-1),Py
  1885. 1878          CASE ">"                       ! Right Arrow
  1886. 1879            OUTPUT @Out_buff;"C";
  1887. 1880            STATUS CRT,0;Px,Py
  1888. 1881            CONTROL CRT,0;MIN(Crt_width,Px+1),Py
  1889. 1882          CASE "^"
  1890. 1883            OUTPUT @Out_buff;"A";
  1891. 1884            STATUS CRT,0;Px,Py
  1892. 1885            CONTROL CRT,0;Px,MAX(1,Py-1)
  1893. 1886          CASE "V"                          ! Down Arrow
  1894. 1887            OUTPUT @Out_buff;"B";
  1895. 1888            STATUS CRT,0;Px,Py
  1896. 1889            CONTROL CRT,0;Px,Py+1
  1897. 1890          CASE "\"                             ! home
  1898. 1891            OUTPUT @Out_buff;"H";
  1899. 1892            CONTROL CRT,0;1,1
  1900. 1893          CASE "%"                             ! clr-end
  1901. 1894            OUTPUT @Out_buff;"";
  1902. 1895            IF Lecho THEN 
  1903. 1896              STATUS CRT,9;Crt_width
  1904. 1897              STATUS CRT,0;Cx
  1905. 1898              PRINT RPT$(" ",Crt_width-Cx)
  1906. 1899            END IF
  1907. 1900          CASE "#"                             ! clr-line
  1908. 1901            OUTPUT @Out_buff;"";
  1909. 1902            IF Lecho THEN 
  1910. 1903              CONTROL CRT,0;1
  1911. 1904              STATUS CRT,9;Crt_width
  1912. 1905              PRINT RPT$(" ",Crt_width)
  1913. 1906            END IF
  1914. 1907          CASE "K"                             ! cls
  1915. 1908            OUTPUT @Out_buff;""
  1916. 1909            IF Lecho THEN CLEAR SCREEN
  1917. 1910          CASE "U"                             ! caps lock
  1918. 1911            STATUS KBD,0;Capstat
  1919. 1912            IF Capstat THEN 
  1920. 1913              CONTROL KBD,0;0
  1921. 1914            ELSE
  1922. 1915              CONTROL KBD,0;1
  1923. 1916            END IF
  1924. 1917         !  OUTPUT KBD;" U E";
  1925. 1918          CASE ELSE
  1926. 1919            BEEP 300,.01     ! this function key not implemented
  1927. 1920          END SELECT
  1928. 1921        END IF   ! CTRL - Function Key
  1929. 1922      END IF     ! Fuunction Key
  1930. 1923 !
  1931. 1924 !----------------   Ascii and  CTRL-Ascii Processing     a-Z -
  1932. 1925 !
  1933. 1926 Ak:!
  1934. 1927      SELECT Key1
  1935. 1928 Kesc:CASE NUM(Kerm_esc$[1,1])           !  KERMIT Escape  CTRL-]
  1936. 1929        DISP "C: Exit  B:Break  K:Kermit Q:Stop Log  R:Resume Log  M: Modeline E: Echo"
  1937. 1930        Esc_seq$=K$[1,1]
  1938. 1931        WHILE LEN(Esc_seq$)<1    ! Wait for Kermit Escape Completion
  1939. 1932          K$=KBD$
  1940. 1933          Esc_seq$=K$[1,1]
  1941. 1934        END WHILE
  1942. 1935        SELECT UPC$(Esc_seq$)    ! Second Sequence of Kermit Escape
  1943. 1936        CASE "C"                                ! cancel - exit
  1944. 1937          Remote=0
  1945. 1938          OFF KBD
  1946. 1939          IF Mode_line THEN GCLEAR
  1947. 1940          CLEAR SCREEN
  1948. 1941        CASE "B"                                ! send break
  1949. 1942          IF Com_card=98628 THEN 
  1950. 1943            BREAK Com_port
  1951. 1944          ELSE
  1952. 1945            Shutdown
  1953. 1946            BREAK Com_port
  1954. 1947            Startup
  1955. 1948          END IF
  1956. 1949          OUTPUT @Out_buff;""     ! work around for FIDO Bulletin Board
  1957. 1950        CASE "S"                                ! stat
  1958. 1951        CASE "Q"                                ! stop logging
  1959. 1952          IF S_log THEN 
  1960. 1953            OUTPUT @S_log;File_buff$;END
  1961. 1954            File_buff$=""
  1962. 1955          END IF
  1963. 1956          S_log=0
  1964. 1957        CASE "R"                                ! resume logging
  1965. 1958          S_log=1
  1966. 1959        CASE "O","0"                            ! transmit null
  1967. 1960          OUTPUT @Out_buff;"";
  1968. 1961        CASE "?"                                ! help
  1969. 1962        CASE "K"                                ! Kermit Shell
  1970. 1963          PRINTER IS CRT
  1971. 1964          CALL Kermit
  1972. 1965          Remote=1      ! (stay in emulator)
  1973. 1966          Kermit_exit=0
  1974. 1967          CONTROL CRT,10;0
  1975. 1968          PRINTER IS CRT;EOL (CHR$(10)),WIDTH OFF
  1976. 1969          GOSUB Disp_modeline
  1977. 1970        CASE "E"
  1978. 1971          IF Lecho THEN 
  1979. 1972            Lecho=0
  1980. 1973          ELSE
  1981. 1974            Lecho=1
  1982. 1975          END IF
  1983. 1976        CASE "M"          ! Toggle Mode Line
  1984. 1977          IF Mode_line THEN 
  1985. 1978            Mode_line=0
  1986. 1979          ELSE
  1987. 1980            Mode_line=1
  1988. 1981          END IF
  1989. 1982          GOSUB Disp_modeline
  1990. 1983        CASE ELSE
  1991. 1984        END SELECT         ! second char of kermit terminal escape
  1992. 1985        DISP 
  1993. 1986    !----------------------------------------------
  1994. 1987 Text:CASE 32 TO 126                            ! printable
  1995. 1988        IF Lecho THEN PRINT Key1$;              ! ascii character
  1996. 1989        OUTPUT @Out_buff;Key1$;
  1997. 1990    !----------------------------------------------
  1998. 1991      CASE 0 TO 31
  1999. 1992        IF Term_mode$="APPL" THEN    ! vt100 keypad
  2000. 1993          OUTPUT @Out_buff;"O"&CHR$(Key1+96);
  2001. 1994        ELSE
  2002. 1995          OUTPUT @Out_buff;Key1$;
  2003. 1996          IF Lecho THEN 
  2004. 1997            DISPLAY FUNCTIONS ON
  2005. 1998            PRINT Key1$;
  2006. 1999            DISPLAY FUNCTIONS OFF
  2007. 2000          END IF
  2008. 2001        END IF
  2009. 2002      END SELECT
  2010. 2003   !------------------------------------------------
  2011. 2004    EXIT IF Remote=0
  2012. 2005      K$=KBD$            ! flush keyboard buffer
  2013. 2006    END LOOP
  2014. 2007    RETURN 
  2015. 2008!======================================================================
  2016. 2009 Receive_char: !
  2017. 2010 Rc:!
  2018. 2011    GOSUB Get_inlength     ! find In_length of Inbound Buffer
  2019. 2012  !
  2020. 2013    WHILE In_length
  2021. 2014      ENTER @In_buff USING "#,A";A$
  2022. 2015      Char=NUM(A$)
  2023. 2016      IF S_log THEN 
  2024. 2017        File_buff$=File_buff$&A$
  2025. 2018        IF Char=13 AND Newline THEN File_buff$=File_buff$&"
  2026. "
  2027. 2019        Fblen=LEN(File_buff$)
  2028. 2020        IF (Char=13 AND Fblen>=Max_buff-80) OR (Fblen>=Max_buff-10) THEN 
  2029. 2021          DISP CHR$(129);" ";CHR$(128)
  2030. 2022          OUTPUT @S_log;File_buff$;
  2031. 2023          File_buff$=""
  2032. 2024        END IF
  2033. 2025      END IF
  2034. 2026 Handle_char: !
  2035. 2027      SELECT Char
  2036. 2028      CASE 32 TO 126      ! sp to ~
  2037. 2029        PRINT A$;
  2038. 2030    !-----------------------------------------
  2039. 2031    ! SELECTED CONTROL CHARACTERS
  2040. 2032    !-----------------------------------------
  2041. 2033      CASE 127     ! backspace "del"
  2042. 2034        STATUS CRT,0;Cx,Cy
  2043. 2035        IF Cx>1 THEN 
  2044. 2036          CONTROL CRT,0;Cx-1,Cy
  2045. 2037          OUTPUT CRT;" ";
  2046. 2038          CONTROL CRT,0;Cx-1,Cy
  2047. 2039        END IF
  2048. 2040      CASE 5                        !""         ! ENQ/ACK
  2049. 2041        OUTPUT @Out_buff;CHR$(6);
  2050. 2042        IF Flow$="ENQ/ACK" THEN 
  2051. 2043          OUTPUT @Out_buff;CHR$(6);
  2052. 2044        END IF
  2053. 2045      CASE 10                       ! LF
  2054. 2046        IF Hl THEN GOSUB Blink
  2055. 2047        PRINT "
  2056. ";
  2057. 2048        IF S_log THEN OUTPUT @S_log;File_buff$
  2058. 2049        File_buff$=""
  2059. 2050      CASE 13
  2060. 2051        PRINT "";
  2061. 2052      CASE 7
  2062. 2053        BEEP 800,.1
  2063. 2054      CASE 8                          !     Backspace
  2064. 2055        STATUS CRT,0;Cx
  2065. 2056        CONTROL CRT,0;MAX(Cx-1,1)
  2066. 2057      CASE 17 TO 20
  2067. 2058     !  DISP " RESPONSE ? "
  2068. 2059     !  ENTER KBD;Line$
  2069. 2060     !  IF LEN(TRIM$(Line$)) THEN OUTPUT @Out_buff;Line$
  2070. 2061      CASE 27                         !     Escape
  2071. 2062     !------------------------
  2072. 2063     !    VT-100  SEQUENCES
  2073. 2064     !------------------------
  2074. 2065     !  need to check for buffer length here to avoid end of buffer
  2075. 2066        REPEAT
  2076. 2067          GOSUB Get_inlength
  2077. 2068        UNTIL In_length
  2078. 2069        ENTER @In_buff USING "#,A";A$
  2079. 2070        IF A$="[" THEN  ! vt100 escape
  2080. 2071          !
  2081. 2072          ! The next char is either an argument or numeric
  2082. 2073          !
  2083. 2074          ! A  or  A
  2084. 2075          !
  2085. 2076 Wait_esc:!
  2086. 2077          SELECT Com_card
  2087. 2078          CASE 98628
  2088. 2079            STATUS Com_port,5;In_length
  2089. 2080          CASE ELSE
  2090. 2081            STATUS @In_buff,4;In_length
  2091. 2082          END SELECT
  2092. 2083          IF NOT In_length THEN GOTO Wait_esc
  2093. 2084          ENTER @In_buff USING "#,A";A$
  2094. 2085          Pn=NUM(A$)
  2095. 2086          SELECT Pn
  2096. 2087          CASE 48 TO 57    ! 0 to 9
  2097. 2088            Pn=VAL(A$)
  2098. 2089          CASE ELSE
  2099. 2090            Pn=0
  2100. 2091            STATUS CRT,0;Cc,Cl            ! current cursor
  2101. 2092            SELECT A$
  2102. 2093            CASE "A"
  2103. 2094              CONTROL CRT,0;MAX(1,Cc),MAX(1,Cl-1)
  2104. 2095            CASE "B"
  2105. 2096              CONTROL CRT,0;MAX(1,Cc),MAX(1,Cl+1)
  2106. 2097            CASE "C"
  2107. 2098              CONTROL CRT,0;MAX(1,Cc+1),MAX(1,Cl)
  2108. 2099            CASE "D"
  2109. 2100              CONTROL CRT,0;MAX(1,Cc-1),MAX(1,Cl)
  2110. 2101            CASE "H"
  2111. 2102              CONTROL CRT,0;1,1
  2112. 2103            CASE "J"
  2113. 2104              SELECT Pn
  2114. 2105               !
  2115. 2106               ! Need to know number of lines on screen
  2116. 2107               !
  2117. 2108              CASE 0     ! erase to end of scr
  2118. 2109              CASE 1     ! erase up to cursor
  2119. 2110              CASE 2     ! CLS
  2120. 2111                CLEAR SCREEN
  2121. 2112              END SELECT
  2122. 2113            CASE "K"
  2123. 2114              SELECT Pn
  2124. 2115              CASE 0     ! clear to end
  2125. 2116                OUTPUT CRT;" %";            ! clr-end
  2126. 2117              CASE 1                        ! clr to cursor
  2127. 2118              CASE 2                        ! clr line
  2128. 2119                OUTPUT CRT;" #";
  2129. 2120              END SELECT
  2130. 2121            CASE "x"     ! request report frame (parity,data bits etc)
  2131. 2122          !  IF Pn=0 THEN
  2132. 2123          !  IF Pn=1 THEN
  2133. 2124            CASE "n"     ! request report on terminal status
  2134. 2125              IF Pn=5 THEN OUTPUT @Out_buff;"n"
  2135. 2126              IF Pn=6 THEN 
  2136. 2127                STATUS CRT,0;Cc,Cl
  2137. 2128                OUTPUT @Out_buff;""&VAL$(Cc)&","&VAL$(Cl)&","&"R"
  2138. 2129              END IF
  2139. 2130            CASE "?"  ! shift numeric keypad to application/numeric mode
  2140. 2131              Misc$=""
  2141. 2132              REPEAT
  2142. 2133                GOSUB Get_inlength
  2143. 2134              UNTIL In_length>=2
  2144. 2135              ENTER @In_buff USING "#,2A";Misc$
  2145. 2136              IF Misc$="1h" OR Misc$="1l" THEN 
  2146. 2137                IF Term_mode$="APPL" THEN 
  2147. 2138                  Term_mode$="NUMERIC"
  2148. 2139                ELSE
  2149. 2140                  Term_mode$="APPL"
  2150. 2141                END IF
  2151. 2142              END IF
  2152. 2143            CASE ELSE
  2153. 2144            END SELECT        ! of esc-VT100 argument
  2154. 2145          END SELECT          ! VT-100 NUMERIC OR COMMAND
  2155. 2146        ELSE   ! not an  sequence
  2156. 2147          DISPLAY FUNCTIONS ON
  2157. 2148          PRINT "";A$;
  2158. 2149          DISPLAY FUNCTIONS OFF
  2159. 2150        END IF           !  - vt100 sequence
  2160. 2151     !-------------------------------------------------------------------
  2161. 2152     !              END  VT-100  SEQUENCES
  2162. 2153     !-------------------------------------------------------------------
  2163. 2154      CASE 0 TO 31       ! Control Char
  2164. 2155        IF Debug THEN 
  2165. 2156          PRINT "^"&CHR$(NUM(A$)+32);
  2166. 2157        END IF
  2167. 2158      CASE 128 TO 255
  2168. 2159        IF Debug THEN 
  2169. 2160          PRINT "^&"&CHR$(NUM(A$)-128);
  2170. 2161        END IF
  2171. 2162      CASE ELSE
  2172. 2163        IF Debug THEN PRINT A$;
  2173. 2164      END SELECT
  2174. 2165  !
  2175. 2166      GOSUB Get_inlength
  2176. 2167    END WHILE
  2177. 2168    RETURN 
  2178. 2169 Rc2: !
  2179. 2170 !-------------------------------------------
  2180. 2171 Get_inlength:!
  2181. 2172    IF Com_card=98628 THEN 
  2182. 2173      STATUS Com_port,5;In_length
  2183. 2174    ELSE
  2184. 2175      STATUS @In_buff,4;In_length
  2185. 2176    END IF
  2186. 2177    RETURN 
  2187. 2178 !-------------------------------------------
  2188. 2179 Com_tmo:!
  2189. 2180    DISP "COMM PORT TIMEOUT : PAUSED "
  2190. 2181    PAUSE
  2191. 2182    DISP 
  2192. 2183    RETURN 
  2193. 2184 !-------------------------------------------
  2194. 2185 Term_err:!
  2195. 2186    PRINT ERRM$
  2196. 2187    SELECT ERRN
  2197. 2188    CASE 167 ! IO STATUS ERROR
  2198. 2189      GOSUB Term_intr
  2199. 2190    CASE 314  ! RECEIVE BUFFER OVERFLOW
  2200. 2191      BEEP 
  2201. 2192      DISP ERRM$,"PAUSED IN  TERM_ERR"
  2202. 2193      PAUSE
  2203. 2194      DISP 
  2204. 2195    CASE ELSE
  2205. 2196      BEEP 
  2206. 2197      DISP ERRM$,"PAUSED"
  2207. 2198      PAUSE
  2208. 2199      DISP 
  2209. 2200    END SELECT
  2210. 2201    RETURN 
  2211. 2202 !--------------------------------------------------------------------
  2212. 2203  SUBEND
  2213. 2204 ! ====================================================================
  2214. 2205 Kstatus:SUB Kstatus
  2215. 2206    OPTION BASE 1
  2216. 2207    COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  2217. 2208    COM /Frame/ Baud,Data_bits,Stop_bits,On_off$[3],Parity_type$[4]
  2218. 2209    COM /Frame/ Flow$,Hshake$
  2219. 2210    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  2220. 2211    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  2221. 2212    COM /Kerm/ INTEGER Maxp,Maxtry,Mypad,Mytmo,Mypchar,Myeol,Myquote
  2222. 2213    COM /Kerm/ INTEGER Size,Rpsiz,Spsiz,Pad,Capas
  2223. 2214    COM /Kerm/ INTEGER Image,Parflg,Pktdeb
  2224. 2215    COM /Kerm/ INTEGER Filnamcnv,Blk_chk,Quote,Eol
  2225. 2216    COM /Kerm2/ State$[1],Cchksum$[1],Eof_mode$,INTEGER Eof_mode,Timer,Ptmo
  2226. 2217    COM /Term/ Term_type$[10],S_log,D_log,Filewarn,Discard,@S_log,@D_log
  2227. 2218    COM /Term/ Kerm_esc$[2],S_log$,D_log$,INTEGER Remote,Lecho,Turn,Display
  2228. 2219    COM /Term/ Term_mode$
  2229. 2220    COM /Path/ Cur_msi$,S_path$,S_msi$,D_path$,D_msi$
  2230. 2221    DIM D_log_stat$[40],S_log_stat$[40]
  2231. 2222    PRINT RPT$("=",15)&" S T A T U S "&RPT$("=",15)
  2232. 2223    !
  2233. 2224    PRINT CHR$(132);"COMMUNICATIONS PORT";CHR$(128);
  2234. 2225    PRINT TAB(50);CHR$(132);"TERMINAL";CHR$(128)
  2235. 2226    !
  2236. 2227    PRINT "Baud Rate ";TAB(20);Baud;
  2237. 2228    PRINT TAB(50);"Terminal Type ";TAB(70);Term_type$
  2238. 2229    !
  2239. 2230    PRINT "COM Port ";TAB(20);Com_port;
  2240. 2231    PRINT TAB(50);"          ";TAB(70);"    "
  2241. 2232    !
  2242. 2233    PRINT "Parity ";TAB(20);Parity_type$;
  2243. 2234    PRINT TAB(50);CHR$(132);"LOCAL TRANSFER PARAMETERS";CHR$(128)
  2244. 2235    !
  2245. 2236    Lecho$="REMOTE"
  2246. 2237    IF Lecho THEN Lecho$="LOCAL"
  2247. 2238    PRINT "ECHO       ";TAB(20);Lecho$;
  2248. 2239    PRINT TAB(50);"Packet Timeout ";TAB(70);Mytmo
  2249. 2240    !
  2250. 2241    PRINT "Flow Control";TAB(20);Flow$;
  2251. 2242    PRINT TAB(50);"Control Quote";TAB(70);CHR$(Myquote)
  2252. 2243    !
  2253. 2244    PRINT "Handshake  ";TAB(20);Hshake$;
  2254. 2245    PRINT TAB(50);"Packet Size ";TAB(70);Spsiz
  2255. 2246    !
  2256. 2247    PRINT "Source  MSI  ";TAB(20);S_path$&S_msi$;
  2257. 2248    PRINT TAB(50);"Padding Character";
  2258. 2249    DISPLAY FUNCTIONS ON
  2259. 2250    PRINT TAB(70);CHR$(Mypad);
  2260. 2251    DISPLAY FUNCTIONS OFF
  2261. 2252    PRINT 
  2262. 2253    !
  2263. 2254    PRINT "Destination  MSI ";TAB(20);D_path$&D_msi$;
  2264. 2255    PRINT TAB(50);"             ";TAB(70);"   "
  2265. 2256    !
  2266. 2257    Filewarn$="OVERWRITE"
  2267. 2258    IF Filewarn THEN Filewarn$="AVOID OVERWRITE"
  2268. 2259    PRINT "Overwrite  Warn.   ";TAB(20);Filewarn$;
  2269. 2260    PRINT TAB(50);CHR$(132);"REMOTE TRANSFER PARAMETERS";CHR$(128)
  2270. 2261    !
  2271. 2262    Discard$="KEEP     "
  2272. 2263    IF Discard THEN Discard$="DISCARD"
  2273. 2264    PRINT "Incomplete File    ";TAB(20);Discard$;
  2274. 2265    PRINT TAB(50);"Packet Timeout";TAB(70);Ptmo
  2275. 2266    !
  2276. 2267    PRINT "EOF Mode  ";TAB(20);Eof_mode$;
  2277. 2268    PRINT TAB(50);"Packet Size ";TAB(70);Rpsiz
  2278. 2269    !
  2279. 2270    S_log_stat$="OFF          "
  2280. 2271    IF S_log THEN S_log_stat$=S_log$
  2281. 2272    PRINT "Session Log  ";TAB(20);S_log_stat$;
  2282. 2273    !
  2283. 2274    PRINT TAB(50);"Padding Character";
  2284. 2275    DISPLAY FUNCTIONS ON
  2285. 2276    PRINT TAB(70);CHR$(Pad);
  2286. 2277    DISPLAY FUNCTIONS OFF
  2287. 2278    PRINT 
  2288. 2279    !
  2289. 2280    D_log_stat$="OFF"
  2290. 2281    IF D_log THEN D_log_stat$=D_log$
  2291. 2282    PRINT "Packet  Log ";TAB(20);D_log_stat$;
  2292. 2283    PRINT TAB(50);"Control Quote ";TAB(70);CHR$(Quote)
  2293. 2284    !
  2294. 2285    Timeron$="ON"
  2295. 2286    IF NOT Timer THEN Timeron$="OFF"
  2296. 2287    PRINT "Timer        ";TAB(20);Timeron$;
  2297. 2288    PRINT TAB(50);"EOL Char      ";
  2298. 2289    DISPLAY FUNCTIONS ON
  2299. 2290    PRINT TAB(70);CHR$(Eol);
  2300. 2291    DISPLAY FUNCTIONS OFF
  2301. 2292    PRINT 
  2302. 2293    !
  2303. 2294    Debug$="OFF"
  2304. 2295    IF Debug THEN Debug$="ON         "
  2305. 2296    PRINT "Debug Mode   ";TAB(20);Debug$;
  2306. 2297    PRINT TAB(50);"Pkt. Retry  Limit  ";TAB(70);Maxtry
  2307. 2298    !
  2308. 2299    PRINT "Kermit Escape ";
  2309. 2300    PRINT TAB(20);"^"&CHR$(NUM(Kerm_esc$[1,1])+64)&Kerm_esc$[2,2];
  2310. 2301    PRINT TAB(50);"Block Check Type  ";TAB(70);Blk_chk
  2311. 2302    !
  2312. 2303    Filetype$="ASCII"
  2313. 2304    IF Image THEN Filetype$="BINARY"
  2314. 2305    PRINT "File Mode    ";TAB(20);Filetype$;
  2315. 2306    PRINT TAB(50);"                   ";TAB(70)
  2316. 2307    PRINT 
  2317. 2308  SUBEND
  2318. 2309  ! =======================================================================
  2319. 2310  DEF FNTochar$(INTEGER C)
  2320. 2311    RETURN CHR$(C+32)        ! +" "
  2321. 2312  FNEND
  2322. 2313  !------------------------------------------------------------------------
  2323. 2314  DEF FNUnchar(C$)
  2324. 2315    RETURN NUM(C$)-32
  2325. 2316  FNEND
  2326. 2317  !------------------------------------------------------------------------
  2327. 2318  DEF FNCtl(C$)
  2328. 2319    C=NUM(C$)
  2329. 2320    C=BINEOR(C,64)  ! toggle bit 7
  2330. 2321    RETURN C
  2331. 2322  FNEND
  2332. 2323  ! ----------------------------------------------------------------------
  2333. 2324 Ksend:SUB K_send(F$,OPTIONAL INTEGER Bdat_item)
  2334. 2325  !
  2335. 2326  ! Kermit Send File Protocol
  2336. 2327  !
  2337. 2328    OPTION BASE 1
  2338. 2329    COM Version$,K$,Setup$
  2339. 2330    COM /Crt/ Crt_lines,Crt_width
  2340. 2331    COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  2341. 2332    COM /Kerm/ INTEGER Maxp,Maxtry,Mypad,Mytmo,Mypchar,Myeol,Myquote
  2342. 2333    COM /Kerm/ INTEGER Size,Rpsiz,Spsiz,Pad,Capas
  2343. 2334    COM /Kerm/ INTEGER Image,Parflg,Pktdeb
  2344. 2335    COM /Kerm/ INTEGER Filnamcnv,Blk_chk,Quote,Eol
  2345. 2336    COM /Kerm2/ State$[1],Cchksum$[1],Eof_mode$,INTEGER Eof_mode,Timer,Ptmo
  2346. 2337    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  2347. 2338    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  2348. 2339    COM /Frame/ Baud,Data_bits,Stop_bits,On_off$[3],Parity_type$[4]
  2349. 2340    COM /Frame/ Flow$,Hshake$
  2350. 2341    COM /Term/ Term_type$[10],S_log,D_log,Filewarn,Discard,@S_log,@D_log
  2351. 2342    COM /Term/ Kerm_esc$[2],S_log$,D_log$,INTEGER Remote,Lecho,Turn,Display
  2352. 2343    COM /Term/ Term_mode$
  2353. 2344    COM /Path/ Cur_msi$,S_path$,S_msi$,D_path$,D_msi$
  2354. 2345  !
  2355. 2346    INTEGER Chksum,Rc,Plen,Dlen,Cchksum,Qbin,Rep_ch
  2356. 2347    INTEGER Ftype,Volnum,Prot,Recsize,Sec_data(1:256),Lsb,Msb
  2357. 2348    INTEGER Npak,Numtry,Oldtry,Rseq
  2358. 2349    INTEGER Com_err,User_break
  2359. 2350    INTEGER Spacks,Fpacks,Apacks,Dpacks,Zpacks,Bpacks,Epacks
  2360. 2351    INTEGER Atl
  2361. 2352    INTEGER Bdat_int
  2362. 2353    REAL File_st,F_sec,File_length,At_rec,At_recl,At_len
  2363. 2354    DIM Misc$[80],Filename$[80]
  2364. 2355    DIM A$[1],File_buff$[1024],File_get$[256],Wmsg$[80],Emsg$[80]
  2365. 2356    DIM Myquote$[1],Qbin$[1]
  2366. 2357    DIM File_eol$[2],Cat$(10)[80],Cat_entry$[80],Sav_msi$[256]
  2367. 2358  !
  2368. 2359    Sav_msi$=SYSTEM$("MSI")
  2369. 2360    File_eol$=CHR$(13)&CHR$(10)
  2370. 2361    ALLOCATE Rcvpkt$[Maxp],Sndpkt$[Spsiz+2],Packet$[Spsiz+2],Rdata$[Maxp]
  2371. 2362    Com_err=0
  2372. 2363    Shutdown         ! Shut off transfers while doing ON-EVENTS
  2373. 2364    SELECT Com_card
  2374. 2365    CASE 98626,98644
  2375. 2366      CONTROL Com_port,12;128+32+16          ! ELIMINATE HANDSHAKE
  2376. 2367      CONTROL Com_port,5;1+2                 ! force dtr,rts
  2377. 2368    CASE 98628
  2378. 2369      CONTROL Com_port,13;164     ! INT MASK  4=UART  32=lost car 128=break
  2379. 2370    END SELECT
  2380. 2371    ON ERROR GOSUB Send_err
  2381. 2372    ON INTR Com_port,15 GOSUB Send_intr
  2382. 2373    Startup
  2383. 2374  !
  2384. 2375    CLEAR SCREEN
  2385. 2376    IF Display THEN 
  2386. 2377      PRINT TABXY(1,2);Version$
  2387. 2378      PRINT TABXY(15,5);"Filename: ";F$                 ! LINE 5
  2388. 2379      PRINT TAB(6);"Bytes Transferred: ";TAB(25);Kbx    ! 6
  2389. 2380      PRINT TAB(6);"    % Transferred: ";TAB(25);Kbx    ! 7
  2390. 2381      PRINT TAB(16);"SENDING: In Progress           "   ! 8
  2391. 2382      PRINT                                             ! 9
  2392. 2383      PRINT TAB(6);"Number of Packets: ";TAB(25);Npak   ! 10
  2393. 2384      PRINT TAB(6);"Number of Retries: ";TAB(25);Oldtry ! 11
  2394. 2385      PRINT TAB(13);"Last Error: "                      ! 12
  2395. 2386      PRINT TAB(11);"Last Message: "                    ! 13
  2396. 2387                                                        ! 14 blank
  2397. 2388      IF Debug THEN 
  2398. 2389        PRINT TABXY(11,15);"REC. PACKET : "                  ! 15
  2399. 2390        PRINT TABXY(11,16);"SEND PACKET : "                  ! 16
  2400. 2391      END IF
  2401. 2392    ELSE
  2402. 2393      DISP "Sending ";F$;" ... "
  2403. 2394    END IF
  2404. 2395    !--------------------------------------------------------------------
  2405. 2396    ! The filename in whatever form is passed in as F$
  2406. 2397    !
  2407. 2398    ! 1. If msi not specified then
  2408. 2399    !       use Source Msi
  2409. 2400    !       use source path
  2410. 2401    !
  2411. 2402    ! 2. If msi is specified dont use source path
  2412. 2403    !
  2413. 2404    IF NOT POS(F$,":") THEN 
  2414. 2405      F_msi$=S_msi$
  2415. 2406      IF NOT POS(F$,"/") THEN F_path$=S_path$
  2416. 2407      F$=F_path$&F$&F_msi$
  2417. 2408    END IF
  2418. 2409    Parse_filename(F$,F_msi$,F_path$)
  2419. 2410    Filename$=F_path$&F$&F_msi$
  2420. 2411    IF F_path$&F$="/T" THEN GOTO Test_send
  2421. 2412  !
  2422. 2413  ! Catalog File entry on F_path$ and F_msi$
  2423. 2414  ! Get File's parameters  Cat_entry$,At_length,At_type$
  2424. 2415  !
  2425. 2416    GOSUB Get_file_entry    ! F$,F_msi$,F_path$,File_found,Cat_entry$,Filetype$
  2426. 2417  !
  2427. 2418  ! If a ramdisc is required call init_ramdisc
  2428. 2419  !
  2429. 2420    IF At_type$="PROG" OR At_type$="BIN" OR At_type$="SYSTM" THEN 
  2430. 2421      Image=1
  2431. 2422  !
  2432. 2423  ! PROG Files must use a ramdisc
  2433. 2424  ! Create one now in case we need it later
  2434. 2425  !
  2435. 2426      Ram_msi$=":,0,0"
  2436. 2427      GOSUB Check_for_rdisc  ! set ramdisc flag
  2437. 2428      IF NOT Ramdisc THEN 
  2438. 2429        CALL Init_ramdisc(Kbytes)     ! Init_ramdisc sizes the Kbytes
  2439. 2430        IF Kbytes THEN Ramdisc=1
  2440. 2431      ELSE                            ! Existing one large enough ?
  2441. 2432        IF Kbytes<(File_length/1000) THEN 
  2442. 2433          Avm=VAL(SYSTEM$("AVAILABLE MEMORY"))
  2443. 2434          Avl_kbytes=(Avm-100000)/1000
  2444. 2435          IF Avl_kbytes>(File_length/1000) THEN  ! can recreate
  2445. 2436            DISP "Can I re-create the Ram Disc ?"
  2446. 2437            OUTPUT KBD;"Y";" H";
  2447. 2438            ENTER KBD;Ans$
  2448. 2439            IF POS(UPC$(Ans$),"Y") THEN 
  2449. 2440              CALL Init_ramdisc(Kbytes)
  2450. 2441            END IF
  2451. 2442          END IF
  2452. 2443        END IF
  2453. 2444      END IF
  2454. 2445  !
  2455. 2446      IF Kbytes<(File_length/1000) THEN 
  2456. 2447        BEEP 
  2457. 2448        PRINT TABXY(1,Crt_lines);"Cannot create sufficient ramdisc - aborting SEND"
  2458. 2449        SUBEXIT
  2459. 2450      END IF
  2460. 2451  !
  2461. 2452      DISP "copying image file to ramdisc... "
  2462. 2453  !
  2463. 2454  ! Try to assign to a PROG type file - if file exists error 58 will result
  2464. 2455  !
  2465. 2456      ASSIGN @Test TO F$&Ram_msi$;RETURN Rc
  2466. 2457      IF Rc=0 THEN Rc=58
  2467. 2458      SELECT Rc
  2468. 2459      CASE 0
  2469. 2460      ! File was assignable - This is probably the second time
  2470. 2461      ! trying to send this PROG file - It's already on the ram disc
  2471. 2462      ! Rc is set to 58 to prompt for purging of existing file
  2472. 2463      CASE 58             ! improper filetype error - file exists
  2473. 2464        Prompt("Overwrite File On Ramdisc ? ","Y",Ans$,Flag)
  2474. 2465        IF Flag THEN 
  2475. 2466          ASSIGN @Test TO *
  2476. 2467          PURGE F$&Ram_msi$
  2477. 2468          COPY Filename$ TO F$&Ram_msi$
  2478. 2469        END IF
  2479. 2470      CASE ELSE    ! file not found
  2480. 2471        COPY Filename$ TO F$&Ram_msi$
  2481. 2472      END SELECT  ! file is on ramdisc or not
  2482. 2473      F_path$=""
  2483. 2474      F_msi$=Ram_msi$
  2484. 2475      Convert(F$&Ram_msi$,"HP-UX",Rc)
  2485. 2476      GOSUB Get_file_entry         ! update file attributes
  2486. 2477    END IF      ! if file is un-assignable (PROG or BIN)
  2487. 2478   !-----------------------------------------------------
  2488. 2479    Filename$=F_path$&F$&F_msi$
  2489. 2480  !
  2490. 2481    SELECT Bdat_item
  2491. 2482    CASE 0
  2492. 2483      ASSIGN @File TO Filename$;FORMAT ON
  2493. 2484    CASE ELSE
  2494. 2485      ASSIGN @File TO Filename$;FORMAT OFF
  2495. 2486    END SELECT
  2496. 2487    STATUS @File,1;File_type
  2497. 2488 Test_send:   !
  2498. 2489   !-------------------------------------    send  init
  2499. 2490    Spacks=0         ! retry counters
  2500. 2491    Fpacks=0
  2501. 2492    Apacks=0
  2502. 2493    Dpacks=0
  2503. 2494    Zpacks=0
  2504. 2495    Bpacks=0
  2505. 2496    Oldtry=0
  2506. 2497    File_buff$=""    ! file buffer to be quoted
  2507. 2498    File_get$=""     ! file enter buffer
  2508. 2499    Sdata_done=0     ! sending data done
  2509. 2500    At_eof=0         ! EOF reached on file read
  2510. 2501    Max_buff=MAXLEN(File_buff$)
  2511. 2502 !------------------------------------------------------------------------
  2512. 2503 Ksends:State$="S"
  2513. 2504    REPEAT
  2514. 2505      SELECT State$
  2515. 2506      CASE "S"
  2516. 2507        GOSUB Spar                       ! Set our Init Parameters
  2517. 2508        Spack(Packet$,State$,Npak,Sndpkt$)
  2518. 2509        IF NOT Spacks THEN PRINT TABXY(25,13);"Exchanging Initialization Packets"
  2519. 2510        OUTPUT @Out_buff;Sndpkt$
  2520. 2511        IF Debug THEN PRINT TABXY(25,16);Sndpkt$&RPT$(" ",100)
  2521. 2512        IF D_log THEN OUTPUT @D_log;Sndpkt$
  2522. 2513  !
  2523. 2514        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Spacks,User_break,Emsg$)
  2524. 2515        IF Debug THEN PRINT TABXY(25,15);Rcvpkt$&"                "
  2525. 2516        IF D_log THEN OUTPUT @D_log;Rcvpkt$
  2526. 2517        SELECT Pktype$
  2527. 2518        CASE "N"
  2528. 2519        CASE "Y"
  2529. 2520          GOSUB Rpar     ! Decode remote parameters
  2530. 2521          State$="F"
  2531. 2522          Oldtry=Oldtry+Spacks
  2532. 2523        CASE "E"
  2533. 2524          Emsg$=Rdata$
  2534. 2525          State$="E"
  2535. 2526        CASE "T"
  2536. 2527          Wmsg$="Packet Timeout"
  2537. 2528        CASE "Q"
  2538. 2529          Wmsg$="Bad Checksum  or Sequence"
  2539. 2530  !
  2540. 2531  ! If Pktype$="X" then local Kermit interrupted file sending.  User_break
  2541. 2532  ! flag is set to determine which side is erroring (in case of ^E).
  2542. 2533  ! Rdata$ can be used to determine ^X or ^Z.
  2543. 2534  !
  2544. 2535        CASE "X"
  2545. 2536          State$="Z"  ! jump to end of file
  2546. 2537          Wmsg$="User abort of Send File"
  2547. 2538        CASE ELSE
  2548. 2539          Wmsg$="Unknown Packet Type: "&Pktype$
  2549. 2540        END SELECT
  2550. 2541    !
  2551. 2542        IF Pktype$="Y" THEN 
  2552. 2543          Npak=Npak+1
  2553. 2544        ELSE
  2554. 2545          Spacks=Spacks+1
  2555. 2546        END IF
  2556. 2547   !
  2557. 2548        IF Spacks>Maxtry THEN 
  2558. 2549          State$="E"
  2559. 2550          Emsg$="Can't Receive (S) Ack from Host"
  2560. 2551        END IF
  2561. 2552   !
  2562. 2553        PRINT TABXY(25,10);Npak
  2563. 2554        PRINT TABXY(25,11);Oldtry+Spacks
  2564. 2555        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  2565. 2556        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  2566. 2557        IF State$<>"S" THEN Oldtry=Oldtry+Spacks
  2567. 2558    !--------------------------------------------------------------------
  2568. 2559 Ksendf:CASE "F"      ! Send File Header  'F'
  2569. 2560      !
  2570. 2561        Packet$=F$    ! just send filename part
  2571. 2562        Spack(Packet$,State$,Npak,Sndpkt$)
  2572. 2563        PRINT TABXY(25,13);"Sending Filename"&RPT$(" ",28)
  2573. 2564        OUTPUT @Out_buff;Sndpkt$
  2574. 2565        PRINT TABXY(25,10);Npak
  2575. 2566        PRINT TABXY(25,11);Oldtry+Fpacks
  2576. 2567  !
  2577. 2568        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Fpacks,User_break,Emsg$)
  2578. 2569        IF Debug THEN 
  2579. 2570          PRINT TABXY(25,15);Rcvpkt$&"                "
  2580. 2571          PRINT TABXY(25,16);Sndpkt$&"                "
  2581. 2572        END IF
  2582. 2573        IF D_log THEN OUTPUT @D_log;Sndpkt$,Rcvpkt$
  2583. 2574  !
  2584. 2575        SELECT Pktype$
  2585. 2576        CASE "N"
  2586. 2577        CASE "Y"
  2587. 2578          Npak=Npak+1
  2588. 2579          Oldtry=Oldtry+Fpacks
  2589. 2580          IF R_capas THEN       ! if remote can use attribute packets
  2590. 2581            State$="A"
  2591. 2582          ELSE
  2592. 2583            State$="D"
  2593. 2584          END IF
  2594. 2585        CASE "E"
  2595. 2586          Emsg$=Rdata$
  2596. 2587          State$="E"
  2597. 2588        CASE "T"
  2598. 2589          Wmsg$="Packet Timeout"
  2599. 2590        CASE "Q"
  2600. 2591          Wmsg$="Bad Checksum or Sequence"
  2601. 2592        CASE "X"
  2602. 2593          State$="Z"  ! jump to end of file
  2603. 2594          Wmsg$="User abort of Send File"
  2604. 2595        CASE ELSE
  2605. 2596          Wmsg$="Unknown Packet Type: "&Pktype$
  2606. 2597        END SELECT
  2607. 2598  !
  2608. 2599        IF Pktype$="N" THEN 
  2609. 2600          Fpacks=Fpacks+1
  2610. 2601          IF Fpacks>Maxtry THEN 
  2611. 2602            Emsg$="Can't Receive (F) Ack from Host"
  2612. 2603            State$="E"
  2613. 2604          END IF
  2614. 2605        END IF
  2615. 2606        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  2616. 2607        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  2617. 2608        PRINT TABXY(25,5);Filename$
  2618. 2609        IF State$="D" THEN Ft_start=TIMEDATE  ! START SEND CLOCK
  2619. 2610    !------------------------------------------------------
  2620. 2611 Ksenda:CASE "A"
  2621. 2612        IF Debug THEN PRINT TABXY(47,8);State$
  2622. 2613        Packet$=""
  2623. 2614        GOSUB Set_at             ! Form  Attribute Data into Packet$
  2624. 2615        Spack(Packet$,State$,Npak,Sndpkt$)
  2625. 2616        PRINT TABXY(25,13);"Sending File Attributes"&RPT$(" ",32)
  2626. 2617        OUTPUT @Out_buff;Sndpkt$
  2627. 2618        IF D_log THEN OUTPUT @D_log;Sndpkt$
  2628. 2619  !
  2629. 2620        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Apacks,User_break,Emsg$)
  2630. 2621        PRINT TABXY(25,10);Npak
  2631. 2622        PRINT TABXY(25,11);Oldtry+Apacks
  2632. 2623        IF Debug THEN 
  2633. 2624          PRINT TABXY(25,15);Rcvpkt$&"                "
  2634. 2625          PRINT TABXY(25,16);Sndpkt$&"                "
  2635. 2626        END IF
  2636. 2627        IF D_log THEN OUTPUT @D_log;Rcvpkt$
  2637. 2628  !
  2638. 2629        SELECT Pktype$
  2639. 2630        CASE "N"
  2640. 2631        CASE "Y"
  2641. 2632          Npak=Npak+1
  2642. 2633          State$="D"
  2643. 2634        CASE "E"
  2644. 2635          Emsg$=Rdata$
  2645. 2636          State$="E"
  2646. 2637        CASE "T"
  2647. 2638          Wmsg$="Packet Timeout"
  2648. 2639        CASE "Q"
  2649. 2640          Wmsg$="Bad Checksum  or Sequence"
  2650. 2641        CASE "X"
  2651. 2642          State$="Z"  ! jump to end of file
  2652. 2643          Wmsg$="User abort of Send File"
  2653. 2644        CASE ELSE
  2654. 2645          Wmsg$="Unknown Packet Type: "&Pktype$
  2655. 2646        END SELECT
  2656. 2647  !
  2657. 2648        IF Pktype$="Y" THEN 
  2658. 2649        ELSE
  2659. 2650          Apacks=Apacks+1
  2660. 2651          IF Apacks>Maxtry THEN 
  2661. 2652            Emsg$="Can't Receive (A) Ack from Host"
  2662. 2653            State$="E"
  2663. 2654          END IF
  2664. 2655        END IF
  2665. 2656        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  2666. 2657        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  2667. 2658        IF State$<>"A" THEN Oldtry=Oldtry+Apacks
  2668. 2659        IF State$="D" THEN Ft_start=TIMEDATE  ! START SEND CLOCK
  2669. 2660    !--------------------------------------------------------------------
  2670. 2661 Ksendd:CASE "D"      ! Send File Data    'D'
  2671. 2662     !
  2672. 2663     ! The way in which characters are fed into the File_buff$ variable
  2673. 2664     ! is dependent on file type (At_type$), and the value of Image flag.
  2674. 2665     !
  2675. 2666     ! ASCII:  Image is ignored and interpreted as Image=0
  2676. 2667     ! HP-UX:  Image=1 transmits file as is.
  2677. 2668     !         Image=0 appends Cr-Lf on each text line
  2678. 2669     ! BDAT:   Image=1 transmits as-is
  2679. 2670     !  ***    Image=0 Kermit tries to read file and covert # to ascii
  2680. 2671     !
  2681. 2672        IF NOT Dstate_init THEN 
  2682. 2673          ON END @File GOTO At_eof
  2683. 2674          Dstate_init=1
  2684. 2675          PRINT TABXY(25,13);"Sending File Data"&RPT$(" ",27)
  2685. 2676        END IF
  2686. 2677    !
  2687. 2678 Fill_buff: !
  2688. 2679        Bl=LEN(File_buff$)        ! Bl Buffer Length
  2689. 2680        Fg=LEN(File_get$)         ! Fg = File Get (buffer)
  2690. 2681     !
  2691. 2682     ! First Append Residue File_get$ and refresh File_get$
  2692. 2683     !
  2693. 2684        IF (Bl<Spsiz) AND (NOT At_eof) AND (Bl+Fg<Max_buff) THEN 
  2694. 2685     !
  2695. 2686     ! If Bl<Spsiz [not enough in buffer to fill a packet] AND
  2696. 2687     ! Bl+Fg<Max_buff [if adding Fget to buffer wont overflow] THEN
  2697. 2688     ! append Fget to buffer.
  2698. 2689     !
  2699. 2690          IF Fg THEN ! Otherwise DON'T Because EOL gets stuffed Each Loop
  2700. 2691            IF Image THEN 
  2701. 2692              File_buff$=File_buff$&File_get$ ! IMAGE FILL
  2702. 2693            ELSE
  2703. 2694              File_buff$=File_buff$&File_get$&File_eol$
  2704. 2695            END IF
  2705. 2696            File_get$=""
  2706. 2697          END IF
  2707. 2698      !
  2708. 2699      ! Then refill File_get$
  2709. 2700      !
  2710. 2701      ! #,-K   Fills File_get$ to dimensioned length, or EOF
  2711. 2702      !
  2712. 2703          REPEAT             ! Until Buff_full
  2713. 2704            SELECT File_type
  2714. 2705 Bdat:      CASE 2             !bdat
  2715. 2706              IF Image THEN 
  2716. 2707                ENTER @File USING "#,-K";File_get$   ! Enter bytes
  2717. 2708              ELSE
  2718. 2709              !
  2719. 2710              ! **  Enter:   INTEGER
  2720. 2711              !              REAL
  2721. 2712              !              STRING (w/Format Off)
  2722. 2713              !
  2723. 2714              ! Bdat_item spec as OPTIONAL parameter
  2724. 2715              !
  2725. 2716                REPEAT
  2726. 2717                  Bdat_item_ok=1
  2727. 2718                  SELECT Bdat_item
  2728. 2719                  CASE 1          ! integer
  2729. 2720                !   DISP "Converting Integers to Ascii"
  2730. 2721                    ENTER @File;Bdat_int
  2731. 2722                    File_get$=VAL$(Bdat_int)
  2732. 2723                  CASE 2          ! reals
  2733. 2724                !   DISP "Converting Reals to Ascii"
  2734. 2725                    ENTER @File;Bdat_real
  2735. 2726                    File_get$=VAL$(Bdat_real)
  2736. 2727                  CASE ELSE   ! not spec - best effort
  2737. 2728                    ENTER @File;File_get$
  2738. 2729                  END SELECT
  2739. 2730                UNTIL Bdat_item_ok
  2740. 2731              END IF
  2741. 2732            CASE 4         ! hp-ux
  2742. 2733              IF Image THEN 
  2743. 2734                ENTER @File USING "#,-K";File_get$
  2744. 2735              ELSE
  2745. 2736                PAUSE
  2746. 2737              !
  2747. 2738                ENTER @File;File_get$
  2748. 2739              END IF
  2749. 2740            CASE 3             ! ascii
  2750. 2741              ENTER @File;File_get$
  2751. 2742            CASE ELSE
  2752. 2743              BEEP 
  2753. 2744              DISP "FILE TYPE = ";File_type;"  Not implemented "
  2754. 2745              PAUSE
  2755. 2746            END SELECT
  2756. 2747            DISP 
  2757. 2748            GOTO Fill_it
  2758. 2749 !-------------------------------------------------------------------
  2759. 2750 ! Enter here ON END @File ...
  2760. 2751 ! If EOF then combine last file_get$ to buffer and set buff_full
  2761. 2752 ! Prog wont return to this loop because at_eof is set.
  2762. 2753 !
  2763. 2754 At_eof:    At_eof=1
  2764. 2755            IF Debug THEN PRINT TABXY(1,Crt_lines);"AT EOF","BUFF LEN = ";LEN(File_buff$)
  2765. 2756            Buff_full=1     ! avoid looping and appending CR-LF
  2766. 2757            IF Image THEN 
  2767. 2758              File_buff$=File_buff$&File_get$
  2768. 2759            ELSE
  2769. 2760              File_buff$=File_buff$&File_get$&File_eol$
  2770. 2761            END IF
  2771. 2762            File_get$=""
  2772. 2763            GOTO Full
  2773. 2764 !-------------------------------------------------------------------
  2774. 2765 Fill_it:!
  2775. 2766            Bl=LEN(File_buff$)
  2776. 2767            Fg=LEN(File_get$)
  2777. 2768            IF Bl+Fg+2>Max_buff THEN 
  2778. 2769              Buff_full=1                 ! leave File_get$ in tact
  2779. 2770            ELSE
  2780. 2771              IF Image THEN 
  2781. 2772                File_buff$=File_buff$&File_get$
  2782. 2773              ELSE
  2783. 2774                File_buff$=File_buff$&File_get$&File_eol$    !<<<<<<<<< WILL CORRUPT A BINARY FILE
  2784. 2775              END IF
  2785. 2776              File_get$=""
  2786. 2777            END IF
  2787. 2778 Full:    UNTIL Buff_full
  2788. 2779          DISP 
  2789. 2780        END IF                  ! buffer smaller than next packet   Bl<Spsiz
  2790. 2781    !-------------------------------------------------------------------
  2791. 2782        Buff_full=0             ! allow buffer to fill next time
  2792. 2783        Bl=LEN(File_buff$)      ! file buffer length
  2793. 2784    !
  2794. 2785    ! Debug: Buffer should not get to this point unless it contains at
  2795. 2786    ! least a packet full of data (if not EOF)
  2796. 2787      ! IF (Bl<Spsiz) AND (NOT At_eof) THEN
  2797. 2788      !   BEEP
  2798. 2789      !   DISP "BUFFER IS ";Bl;"  LONG","SPSIZ = ";Spsiz
  2799. 2790      ! END IF
  2800. 2791    !----------------------------------------------------------------------
  2801. 2792        IF State$="E" THEN GOTO Ksendd_exit
  2802. 2793        B=1                              ! because buff has been truncated
  2803. 2794        P=1                              ! new packet
  2804. 2795        Packet$=""        ! flush packet
  2805. 2796        Pack_full=0
  2806. 2797 Encode_pack:  !
  2807. 2798        Bytes_a=LEN(File_buff$)
  2808. 2799        Encode_pack(File_buff$,Packet$,Myquote,Qbin,Rep_ch,Spsiz)
  2809. 2800        Bytes_b=LEN(File_buff$)
  2810. 2801        Bytes_x=Bytes_x+(Bytes_a-Bytes_b)
  2811. 2802        Bytes_old=Bytes_x
  2812. 2803        IF At_eof AND (LEN(File_buff$)=0) THEN Sdata_done=1
  2813. 2804   !
  2814. 2805        Spack(Packet$,State$,Npak,Sndpkt$)
  2815. 2806        IF Debug THEN 
  2816. 2807          PRINT TABXY(25,6);Bytes_old,INT(Bytes_x/(TIMEDATE-Ft_start));"  B/SEC"
  2817. 2808        ELSE
  2818. 2809          PRINT TABXY(25,6);Bytes_old
  2819. 2810        END IF
  2820. 2811        PRINT TABXY(25,7);INT((Bytes_x/File_length)*100)
  2821. 2812        PRINT TABXY(25,10);Npak
  2822. 2813        PRINT TABXY(25,11);Oldtry+Dpacks
  2823. 2814      !
  2824. 2815      ! Send Packet Until Ack
  2825. 2816      !
  2826. 2817        REPEAT
  2827. 2818          OUTPUT @Out_buff;Sndpkt$
  2828. 2819          Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Dpacks,User_break,Emsg$)
  2829. 2820          IF Debug THEN 
  2830. 2821            PRINT TABXY(25,15);Rcvpkt$&"                "
  2831. 2822            PRINT TABXY(25,16);Sndpkt$&"                "
  2832. 2823          END IF
  2833. 2824          IF D_log THEN OUTPUT @D_log;Sndpkt$,Rcvpkt$
  2834. 2825  !
  2835. 2826          SELECT Pktype$
  2836. 2827          CASE "N"
  2837. 2828          CASE "Y"
  2838. 2829            Npak=Npak+1
  2839. 2830            IF Sdata_done THEN 
  2840. 2831              State$="Z"
  2841. 2832              PRINT TABXY(25,13);"Sending End of File"&RPT$(" ",27)
  2842. 2833            END IF
  2843. 2834          CASE "E"
  2844. 2835            Emsg$=Rdata$
  2845. 2836            State$="E"
  2846. 2837          CASE "T"
  2847. 2838            Wmsg$="Packet Timeout"
  2848. 2839          CASE "Q"
  2849. 2840            Wmsg$="Bad Checksum or Sequence"
  2850. 2841          CASE "X"
  2851. 2842            State$="Z"! jump to end of file
  2852. 2843            Wmsg$="User abort of Send File"
  2853. 2844          CASE ELSE
  2854. 2845            Wmsg$="Unknown Packet Type  "&Pktype$
  2855. 2846          END SELECT
  2856. 2847 Ksendd_exit:  ! File access errors jump and exit here
  2857. 2848          PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  2858. 2849          PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  2859. 2850             !
  2860. 2851          IF Pktype$="Y" THEN 
  2861. 2852            Old_try=Old_try+Dpacks
  2862. 2853          ELSE
  2863. 2854            Dpacks=Dpacks+1
  2864. 2855            IF Dpacks>Maxtry THEN 
  2865. 2856              State$="E"
  2866. 2857              Emsg$="Can't Receive (D) Ack from Host"
  2867. 2858            END IF
  2868. 2859          END IF
  2869. 2860     !
  2870. 2861        UNTIL Pktype$="Y" OR State$="E"
  2871. 2862    !----------------------------------------------------------------------
  2872. 2863 Ksendz:CASE "Z"
  2873. 2864  !
  2874. 2865  ! This state might be entered from local user interrruption.
  2875. 2866  ! Check User_break to determine. Rdata$= "X" or "Z" depending on intr.
  2876. 2867  ! Packet$="D" for user break discard.
  2877. 2868  !
  2878. 2869        IF Debug THEN PRINT TABXY(47,8);State$
  2879. 2870        IF User_break THEN 
  2880. 2871          Packet$="D"
  2881. 2872        ELSE
  2882. 2873          Packet$=""
  2883. 2874        END IF
  2884. 2875        IF NOT POS(Rdata$,"^C") THEN   ! Ok to notify host
  2885. 2876          Spack(Packet$,State$,Npak,Sndpkt$)
  2886. 2877          OUTPUT @Out_buff;Sndpkt$
  2887. 2878          IF Debug THEN PRINT TABXY(25,16);Sndpkt$&"                "
  2888. 2879          Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Zpacks,User_break,Emsg$)
  2889. 2880        ELSE
  2890. 2881         ! fall thru and process State$="X" for ^C event
  2891. 2882        END IF
  2892. 2883        IF Debug THEN PRINT TABXY(25,15);Rcvpkt$&"                "
  2893. 2884        IF D_log THEN OUTPUT @D_log;Sndpkt$,Rcvpkt$
  2894. 2885        SELECT Pktype$
  2895. 2886        CASE "N"
  2896. 2887        CASE "Y"
  2897. 2888          Npak=Npak+1
  2898. 2889          State$="B"
  2899. 2890        CASE "E"
  2900. 2891          Emsg$=Rdata$
  2901. 2892          State$="E"
  2902. 2893        CASE "T"
  2903. 2894          Wmsg$="Packet Timeout"
  2904. 2895        CASE "Q"
  2905. 2896          Wmsg$="Bad Checksum"
  2906. 2897        CASE "X"
  2907. 2898          State$="B"
  2908. 2899          IF Rdata$="^C" THEN 
  2909. 2900            State$="X"  ! Dont notify host just exit
  2910. 2901          END IF
  2911. 2902        CASE ELSE
  2912. 2903          Wmsg$="Unknown  Packet Type "
  2913. 2904        END SELECT
  2914. 2905  !
  2915. 2906        IF Pktype$="Y" THEN 
  2916. 2907        ELSE
  2917. 2908          Zpacks=Zpacks+1
  2918. 2909          IF Zpacks>Maxtry THEN 
  2919. 2910            State$="E"
  2920. 2911            Emsg$="Can't receive (Z) Acknowledge from host"
  2921. 2912          END IF
  2922. 2913        END IF
  2923. 2914        PRINT TABXY(25,10);Npak
  2924. 2915        PRINT TABXY(25,11);Oldtry+Zpacks
  2925. 2916        IF State$<>"Z" THEN Oldtry=Oldtry+Zpacks
  2926. 2917  !---------------------------------------------------------------------
  2927. 2918 Ksendb:CASE "B"
  2928. 2919        IF Debug THEN PRINT TABXY(47,8);State$
  2929. 2920        Packet$=""
  2930. 2921        Spack(Packet$,State$,Npak,Sndpkt$)
  2931. 2922        PRINT TABXY(25,10);Npak
  2932. 2923        PRINT TABXY(25,11);Oldtry
  2933. 2924        PRINT TABXY(25,13);RPT$(" ",55)
  2934. 2925        OUTPUT @Out_buff;Sndpkt$
  2935. 2926        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Bpacks,User_break,Emsg$)
  2936. 2927        IF Debug THEN 
  2937. 2928          PRINT TABXY(25,16);Sndpkt$&"                "
  2938. 2929          PRINT TABXY(25,15);Rcvpkt$&"                "
  2939. 2930        END IF
  2940. 2931        IF D_log THEN OUTPUT @D_log;Sndpkt$
  2941. 2932        IF D_log THEN OUTPUT @D_log;Rcvpkt$
  2942. 2933  !
  2943. 2934        SELECT Pktype$
  2944. 2935        CASE "N"
  2945. 2936        CASE "Y"
  2946. 2937          Oldtry=Oldtry+Bpacks
  2947. 2938          Npak=Npak+1
  2948. 2939          State$="C"
  2949. 2940        CASE "E"
  2950. 2941          Emsg$=Rdata$
  2951. 2942          State$="E"
  2952. 2943        CASE "T"
  2953. 2944          Wmsg$="Packet Timeout"
  2954. 2945        CASE "Q"
  2955. 2946          Wmsg$="Bad Checksum or Sequence"
  2956. 2947        CASE "X"
  2957. 2948        CASE ELSE
  2958. 2949          Wmsg$="Unknown Packet Type"
  2959. 2950        END SELECT
  2960. 2951  !
  2961. 2952        IF Pktype$="Y" THEN 
  2962. 2953        ELSE
  2963. 2954          Bpacks=Bpacks+1
  2964. 2955          IF Bpacks>Maxtry THEN 
  2965. 2956            State$="E"
  2966. 2957            Emsg$="Can't receive (B) Acknowledge from host"
  2967. 2958          END IF
  2968. 2959        END IF
  2969. 2960        PRINT TABXY(25,10);Npak
  2970. 2961        PRINT TABXY(25,11);Oldtry+Bpacks
  2971. 2962        IF State$<>"B" THEN Oldtry=Oldtry+Bpacks
  2972. 2963  !------------------------------------------------------------------------
  2973. 2964 Ksende:CASE "E"    !
  2974. 2965   !
  2975. 2966   ! Need to know if this is a local error or host error
  2976. 2967   ! User_break=Local Error
  2977. 2968   !
  2978. 2969        IF User_break THEN 
  2979. 2970          Packet$=Emsg$
  2980. 2971          Spack(Packet$,State$,Npak,Sndpkt$)
  2981. 2972          OUTPUT @Out_buff;Sndpkt$
  2982. 2973          IF D_log THEN OUTPUT @D_log;Sndpkt$
  2983. 2974          IF Debug THEN PRINT TABXY(25,16);Sndpkt$&"                "
  2984. 2975        ELSE! host error
  2985. 2976        END IF
  2986. 2977   !
  2987. 2978        PRINT TABXY(25,10);Npak
  2988. 2979        PRINT TABXY(25,11);Oldtry
  2989. 2980        State$="X"
  2990. 2981      END SELECT
  2991. 2982  !---------------------------------------------------------------------
  2992. 2983    UNTIL State$="C" OR State$="X"      ! Complete or Abort
  2993. 2984    PRINT TABXY(1,Crt_lines);RPT$(" ",80)
  2994. 2985    IF State$="C" THEN 
  2995. 2986      PRINT "SEND FILE COMPLETE"
  2996. 2987    ELSE
  2997. 2988      IF State$="X" THEN 
  2998. 2989        PRINT "User Abort"
  2999. 2990      ELSE
  3000. 2991        PRINT "SEND FILE FAILED - Host Error";Emsg$
  3001. 2992      END IF
  3002. 2993    END IF
  3003. 2994    MASS STORAGE IS Sav_msi$
  3004. 2995    SUBEXIT
  3005. 2996  !========================================================================
  3006. 2997 Check_for_rdisc:!
  3007. 2998    Ramdisc=1
  3008. 2999 Check_rdisc:MASS STORAGE IS ":,0,0"     ! err 76 incorrect unit code ?
  3009. 3000    RETURN 
  3010. 3001 !--------------------------------------------------------------------------
  3011. 3002 Get_file_entry: !
  3012. 3003    REPEAT
  3013. 3004      Get_cat_entry(F$,F_msi$,F_path$,Filename$,File_found,Cat_entry$)
  3014. 3005      IF NOT File_found THEN 
  3015. 3006        DISP "File not Found - reenter file spec - blank to abort "
  3016. 3007        OUTPUT KBD;Filename$;" H";
  3017. 3008        ENTER KBD;Misc$
  3018. 3009        DISP 
  3019. 3010        IF NOT LEN(Misc$) THEN SUBEXIT
  3020. 3011        Parse_filename(Misc$,F_msi$,F_path$)
  3021. 3012        F$=Misc$
  3022. 3013        Filename$=F_path$&F$&F_msi$
  3023. 3014      END IF
  3024. 3015    UNTIL File_found
  3025. 3016    IF NOT File_found THEN SUBEXIT
  3026. 3017    At_file$=TRIM$(Cat_entry$[1,21])
  3027. 3018    At_type$=TRIM$(Cat_entry$[32,36])
  3028. 3019    At_rec=VAL(Cat_entry$[37,45])
  3029. 3020    At_recl=VAL(Cat_entry$[46,54])
  3030. 3021    At_time$=TRIM$(Cat_entry$[56,71])
  3031. 3022    File_length=At_rec*At_recl*1.00
  3032. 3023    RETURN 
  3033. 3024  !------------------------------------------------------------------------
  3034. 3025 Set_at: !   FORM FILE ATTRIBUTES PACKET DATA
  3035. 3026   !
  3036. 3027   ! Put File Attributes for F$ into Packet$
  3037. 3028   ! Packet$ is in form:  ATTRIBUTE(char), LENGTH(unchar), DATA(char)
  3038. 3029     !
  3039. 3030     ! ! or 1    File length (Bytes)
  3040. 3031     ! "         Data Type
  3041. 3032     ! #         Creation Date
  3042. 3033     ! .         Machine and OS
  3043. 3034     ! /         Format Of Data          File_format$,File_type,File_delim$
  3044. 3035     !
  3045. 3036  ! CAT F_path$&F_msi$ TO Cat$(*);SELECT F$  ! FILE IS ELMENT 8
  3046. 3037   !
  3047. 3038   ! LIF:    TYPE  32-36  [5]
  3048. 3039   !         REC   37-45  [9]
  3049. 3040   !         RECL  46-54  [9]
  3050. 3041   !         TIME  56-71  [22]
  3051. 3042   !
  3052. 3043    At_length$=VAL$(File_length)        ! BYTES
  3053. 3044    At_os$="H4"                         !  Machine and OS !  H4=hp9000 RMB
  3054. 3045    SELECT At_type$
  3055. 3046    CASE "HP-UX"    ! w/ format on
  3056. 3047      At_fmt$="A"
  3057. 3048    CASE "ASCII"
  3058. 3049      At_fmt$="D"
  3059. 3050    CASE "BDAT"      ! w/ format off       ! M=recl  status reg 4
  3060. 3051      At_fmt$="F"
  3061. 3052      STATUS @File,4;At_recl
  3062. 3053    END SELECT
  3063. 3054   !------------  start attribute packet
  3064. 3055    Next_at=1
  3065. 3056    Packet$[Next_at;1]="1"                !1  file length (bytes)
  3066. 3057    Atl=LEN(At_length$)
  3067. 3058    Packet$[Next_at+1;1]=FNTochar$(Atl)
  3068. 3059    Packet$[Next_at+2;Atl]=At_length$
  3069. 3060    Next_at=Next_at+2+Atl
  3070. 3061   !
  3071. 3062   ! Data Format  (use file type)
  3072. 3063   !
  3073. 3064    Packet$[Next_at;1]=""""               !"    file (data) type
  3074. 3065    Atl=LEN(At_type$)
  3075. 3066    Packet$[Next_at+1;1]=FNTochar$(Atl)
  3076. 3067    Packet$[Next_at+2;Atl]=At_type$
  3077. 3068    Next_at=Next_at+2+Atl
  3078. 3069   !
  3079. 3070    Packet$[Next_at;1]="/"                !/    data format  on/off
  3080. 3071    Atl=LEN(At_fmt$)
  3081. 3072    Packet$[Next_at+1;1]=FNTochar$(Atl)
  3082. 3073    Packet$[Next_at+2;Atl]=At_fmt$
  3083. 3074    Next_at=Next_at+2+Atl
  3084. 3075  !
  3085. 3076                                  ! Creation Date [yy]yymmdd[  hh:mm[ :ss]
  3086. 3077    Packet$[Next_at;1]="#"        !#    timedate
  3087. 3078    Atl=LEN(At_time$)
  3088. 3079    Packet$[Next_at+1;1]=FNTochar$(Atl)
  3089. 3080    Packet$[Next_at+2;Atl]=At_time$
  3090. 3081    Next_at=Next_at+2+Atl
  3091. 3082   !
  3092. 3083    Packet$[Next_at;1]="."        !.    Machine and Operating System
  3093. 3084    Atl=LEN(At_os$)
  3094. 3085    Packet$[Next_at+1;1]=FNTochar$(Atl)
  3095. 3086    Packet$[Next_at+2;Atl]=At_os$
  3096. 3087    Next_at=Next_at+2+Atl
  3097. 3088   !
  3098. 3089    RETURN 
  3099. 3090   !-----------------------------------------------------------------------
  3100. 3091 Send_intr: !      ! COMM PORT INTERRUPT HANDLER
  3101. 3092    CALL Com_interrupt
  3102. 3093    Shutdown
  3103. 3094    ON INTR Com_port,15 GOSUB Send_intr
  3104. 3095    SELECT Com_card
  3105. 3096    CASE 98628
  3106. 3097      CONTROL Com_port,13;164      ! MASK  4=UART  32=lost carr 128=break
  3107. 3098    CASE 98626,98644
  3108. 3099      ENABLE INTR Com_port;4
  3109. 3100    END SELECT
  3110. 3101    ON ERROR GOSUB Send_err
  3111. 3102    Startup
  3112. 3103    RETURN 
  3113. 3104  !-----------------------------------------------
  3114. 3105 Send_err:  !
  3115. 3106    SELECT ERRN
  3116. 3107    CASE 29   ! illegal floating point number
  3117. 3108      Wmsg$="Illegal Floating Point Number"
  3118. 3109      Emsg$="File I/O Error - cannot continue"
  3119. 3110      State$="E"
  3120. 3111      User_break=1
  3121. 3112      ERROR RETURN
  3122. 3113    CASE 52,73,76 ! Improper MSVS,device type,Unit Number
  3123. 3114    !
  3124. 3115    ! Checking for existance of Ramdisc
  3125. 3116    !
  3126. 3117      IF ERRL(Check_rdisc) THEN 
  3127. 3118        Ramdisc=0
  3128. 3119        ERROR RETURN
  3129. 3120      ELSE
  3130. 3121        DISP ERRM$
  3131. 3122      END IF
  3132. 3123    CASE 53        ! improper filename
  3133. 3124      DISP "Improper filename, please correct "
  3134. 3125      OUTPUT KBD;Filename$;" H";
  3135. 3126      ENTER KBD;F$
  3136. 3127      Parse_filename(F$,F_msi$,F_path$)
  3137. 3128      Filename$=F_path$&F$&F_msi$
  3138. 3129      DISP 
  3139. 3130    CASE 54   ! Duplicate File Name
  3140. 3131      ASSIGN @Test TO *
  3141. 3132      PRINT TABXY(25,13);"Purged and Overwrite ";F$&Ram_msi$
  3142. 3133      PURGE F$&Ram_msi$
  3143. 3134    CASE 56   ! Filename Undefined
  3144. 3135      DISP "Cannot Access FILE  -  blank Filename will exit"
  3145. 3136      OUTPUT KBD;Filename$;
  3146. 3137      ENTER KBD;F$
  3147. 3138      Parse_filename(F$,F_msi$,F_path$)
  3148. 3139      DISP 
  3149. 3140      IF NOT LEN(F$) THEN SUBEXIT
  3150. 3141      Filename$=F_path$&F$&F_msi$
  3151. 3142    CASE 58   ! Improper File Type
  3152. 3143      DISP "Improper filename, please correct "
  3153. 3144      OUTPUT KBD;Filename$;" H";
  3154. 3145      ENTER KBD;Misc$
  3155. 3146      Parse_filename(Misc$,F_msi$,F_path$)
  3156. 3147      F_path$=F_path$&Misc$
  3157. 3148      DISP 
  3158. 3149    CASE 90   ! Mass Storage System Error
  3159. 3150      RESET 7
  3160. 3151    CASE 157  ! No ENTER Terminator found
  3161. 3152    !
  3162. 3153    ! If sending BDAT files, exit
  3163. 3154    ! if the ascii terminator not found
  3164. 3155    !
  3165. 3156      IF NOT Image THEN 
  3166. 3157        Wmsg$="File contents not ASCII"
  3167. 3158        Emsg$="File I/O Error - cannot continue"
  3168. 3159        State$="E"
  3169. 3160        User_break=1
  3170. 3161        ERROR RETURN
  3171. 3162      END IF
  3172. 3163    CASE 167,168
  3173. 3164      CALL Com_interrupt              ! Trap previous activity at com port
  3174. 3165    CASE ELSE
  3175. 3166      BEEP 
  3176. 3167      DISP ERRM$&"  PAUSED"
  3177. 3168      PAUSE
  3178. 3169    END SELECT
  3179. 3170   !
  3180. 3171    DISP 
  3181. 3172    RETURN 
  3182. 3173 !-------------------------------------------------------------------------
  3183. 3174 Spar:  !  Form Initialization Packet
  3184. 3175  !
  3185. 3176  ! Packet$=", S~(  *#&1 *"
  3186. 3177  !
  3187. 3178    Packet$=""                         !    PACKET MARK
  3188. 3179                                       ! ,   44-32=12   PKT LENGTH
  3189. 3180                                       ! sp  32-32=0    SEQUENCE
  3190. 3181                                       ! S   PACKET TYPE (INIT)
  3191. 3182    Packet$[1,1]=FNTochar$(Maxp)       ! ~   126-32=94
  3192. 3183    Packet$[2,2]=FNTochar$(Mytmo)      ! (    40-32=8
  3193. 3184    Packet$[3,3]=FNTochar$(Mypad)      ! sp   32-32=0
  3194. 3185    Packet$[4,4]=FNTochar$(Mypchar)    ! sp   32-32=0
  3195. 3186    Packet$[5,5]=FNTochar$(Myeol)      ! *    42-32=10
  3196. 3187    Packet$[6,6]=CHR$(Myquote)         ! #    CONTROL QUOTE (0-31)
  3197. 3188    Packet$[7,7]="&"                   ! &    8TH BIT PREFIX
  3198. 3189    Packet$[8,8]="1"                   ! 1    CHECK TYPE
  3199. 3190    Packet$[9,9]=" "                   ! sp   NO REPEAT COUNT PROCESS
  3200. 3191    Packet$[10,10]="*"                 ! FNTochar$(Capas)
  3201. 3192   !-----------------------------------!------------------------------
  3202. 3193  ! EXTENDED PACKET SIZE               ! sp sp ~
  3203. 3194    RETURN 
  3204. 3195  !------------------------------------------------------------------------
  3205. 3196 Rpar:  ! Receive Packet Initialization FROM REMOTE
  3206. 3197        ! Rdata$[] DATA STRIPPED FROM INCOMING PACKET
  3207. 3198    Rpsiz=FNUnchar(Rdata$[1])
  3208. 3199    Ptmo=FNUnchar(Rdata$[2])
  3209. 3200    Pad=FNUnchar(Rdata$[3])
  3210. 3201    Padchar=FNUnchar(Rdata$[4])
  3211. 3202    Eol=FNUnchar(Rdata$[5])
  3212. 3203    IF Eol=0 THEN Eol=Myeol
  3213. 3204    Myquote=NUM(Rdata$[6,6])
  3214. 3205    Myquote$=CHR$(Myquote)
  3215. 3206    IF LEN(Rdata$)>6 THEN Qbin=NUM(Rdata$[7,7])
  3216. 3207    Qbin$=CHR$(Qbin)
  3217. 3208    IF Qbin=89 THEN Qbin=38     ! 89=Y , 38=&
  3218. 3209    IF Qbin=0 THEN Qbin=38
  3219. 3210    IF LEN(Rdata$)>7 THEN R_bchk=VAL(Rdata$[8,8])
  3220. 3211    IF LEN(Rdata$)>8 THEN Rep_char=NUM(Rdata$[9,9])
  3221. 3212    IF LEN(Rdata$)>9 THEN R_capas=FNUnchar(Rdata$[10,10])
  3222. 3213    IF BIT(R_capas,1) THEN    ! extended length packets
  3223. 3214      Rcap_lp=1
  3224. 3215      R_windo=FNUnchar(Rdata$[11,11])
  3225. 3216      R_maxl1=FNUnchar(Rdata$[12,12])
  3226. 3217      R_maxl2=FNUnchar(Rdata$[13,13])
  3227. 3218      R_maxl=R_maxl1*95+R_maxl2
  3228. 3219    END IF
  3229. 3220    IF BIT(R_capas,3) THEN Rcap_a=1
  3230. 3221    RETURN 
  3231. 3222  !-----------------------------------------------------------------
  3232. 3223  SUBEND                          ! END OF KERMIT SEND
  3233. 3224  ! =======================================================================
  3234. 3225  SUB Set_frame(Req_baud)
  3235. 3226 Sf: !
  3236. 3227  !
  3237. 3228  ! Resets HW and SW Handshake registers, does not reset INT MASK
  3238. 3229  !
  3239. 3230    COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  3240. 3231    COM /Frame/ Baud,Data_bits,Stop_bits,On_off$[3],Parity_type$[4]
  3241. 3232    COM /Frame/ Flow$,Hshake$
  3242. 3233    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  3243. 3234    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  3244. 3235    INTEGER Transfer_on
  3245. 3236  !
  3246. 3237    SELECT Req_baud
  3247. 3238    CASE <301
  3248. 3239      Baud=300
  3249. 3240    CASE <1201
  3250. 3241      Baud=1200
  3251. 3242    CASE <2401
  3252. 3243      Baud=2400
  3253. 3244    CASE <4801
  3254. 3245      Baud=4800
  3255. 3246    CASE <9601
  3256. 3247      Baud=9600
  3257. 3248    CASE ELSE
  3258. 3249      Baud=19200
  3259. 3250    END SELECT
  3260. 3251    IF Active THEN 
  3261. 3252      Shutdown(Transfer_on)
  3262. 3253    END IF
  3263. 3254    SELECT Com_card
  3264. 3255    CASE 98626,98644
  3265. 3256      GOSUB Sf26
  3266. 3257    CASE 98628
  3267. 3258      GOSUB Sf28
  3268. 3259    CASE ELSE
  3269. 3260      BEEP 
  3270. 3261      DISP "com card = ";Com_card,"unknown (paused)"
  3271. 3262      PAUSE
  3272. 3263    END SELECT
  3273. 3264    IF Transfer_on THEN 
  3274. 3265      Startup
  3275. 3266    END IF
  3276. 3267    SUBEXIT
  3277. 3268  !----------------------
  3278. 3269 Sf28:  !  SET FRAME ON 98628 DATACOMM CARD
  3279. 3270    SELECT Baud
  3280. 3271    CASE 300
  3281. 3272      Bd=7
  3282. 3273    CASE 1200
  3283. 3274      Bd=9
  3284. 3275    CASE 2400
  3285. 3276      Bd=11
  3286. 3277    CASE 4800
  3287. 3278      Bd=13
  3288. 3279    CASE 9600
  3289. 3280      Bd=14
  3290. 3281    CASE 19200
  3291. 3282      Bd=15
  3292. 3283    CASE ELSE
  3293. 3284      BEEP 
  3294. 3285      DISP "BAUD RATE: ";Baud;"  NOT IMPLEMENTED "
  3295. 3286      PAUSE
  3296. 3287    END SELECT
  3297. 3288    SELECT Data_bits
  3298. 3289    CASE 7
  3299. 3290      B=2
  3300. 3291    CASE 8
  3301. 3292      B=3
  3302. 3293    END SELECT
  3303. 3294    SELECT Stop_bits
  3304. 3295    CASE 1
  3305. 3296      S=0
  3306. 3297    CASE 2
  3307. 3298      S=2
  3308. 3299    END SELECT
  3309. 3300    SELECT TRIM$(UPC$(On_off$))
  3310. 3301    CASE "ON"
  3311. 3302      Pt=5
  3312. 3303    CASE "OFF"
  3313. 3304      Pt=0
  3314. 3305    END SELECT
  3315. 3306 Set_pt: !
  3316. 3307    IF Pt THEN                ! IF PARITY IS ON THEN
  3317. 3308      SELECT UPC$(Parity_type$)
  3318. 3309      CASE "NONE","OFF"
  3319. 3310        Pt=0
  3320. 3311      CASE "ODD"
  3321. 3312        Pt=1
  3322. 3313      CASE "EVEN"
  3323. 3314        Pt=2
  3324. 3315      CASE "MARK","1"
  3325. 3316        Pt=4
  3326. 3317      CASE "SPACE","0"
  3327. 3318        Pt=3
  3328. 3319      END SELECT
  3329. 3320    END IF
  3330. 3321    IF Pt>4 THEN 
  3331. 3322      BEEP 
  3332. 3323      INPUT "WHAT PARITY TYPE ? [NONE,ODD,EVEN,1,0] ",Parity_type$
  3333. 3324      IF TRIM$(UPC$(Parity_type$))="NONE" THEN Pt=0
  3334. 3325      GOTO Set_pt
  3335. 3326    END IF
  3336. 3327    CONTROL Com_port,20;Bd       ! SET BAUD RATE
  3337. 3328    CONTROL Com_port,21;Bd       ! SET Rec  RATE
  3338. 3329    CONTROL Com_port,34;B,S,Pt   ! SET DATA BITS, STOP, PARITY
  3339. 3330    CONTROL Com_port,8;1+2       ! RTS  DTR  Set Active
  3340. 3331    CONTROL Com_port,22;0    ! Protocol (sw) off  2:enq/ack  5/XON-XOFF
  3341. 3332    CONTROL Com_port,23;0    ! Handshake Off
  3342. 3333    RETURN 
  3343. 3334    !----------------------------------
  3344. 3335 Sf26:   !     SET FRAME FOR 98626/98644
  3345. 3336    SELECT Data_bits
  3346. 3337    CASE 7
  3347. 3338      B=2
  3348. 3339    CASE 8
  3349. 3340      B=3
  3350. 3341    END SELECT
  3351. 3342    SELECT Stop_bits
  3352. 3343    CASE 1
  3353. 3344      S=0
  3354. 3345    CASE 2
  3355. 3346      S=4
  3356. 3347    END SELECT
  3357. 3348    SELECT TRIM$(UPC$(On_off$))
  3358. 3349    CASE "ON"
  3359. 3350      P=8
  3360. 3351    CASE "OFF"
  3361. 3352      P=0
  3362. 3353    END SELECT
  3363. 3354    SELECT UPC$(Parity_type$)
  3364. 3355    CASE "ODD"
  3365. 3356      Pt=0
  3366. 3357    CASE "EVEN"
  3367. 3358      Pt=16
  3368. 3359    CASE "MARK","1"
  3369. 3360      Pt=32
  3370. 3361    CASE "SPACE","0"
  3371. 3362      Pt=48
  3372. 3363    END SELECT
  3373. 3364    CONTROL Com_port,3;Baud,B+S+P+Pt   ! set reg 3 and 4
  3374. 3365    CONTROL Com_port,5;1+2             ! set RTS and DTR
  3375. 3366    CONTROL Com_port,12;128+32+16      ! Ignore CTS,DSR,CD
  3376. 3367    RETURN 
  3377. 3368 !--------------------------
  3378. 3369  SUBEND
  3379. 3370 ! ========================================================================
  3380. 3371 Ci:SUB Com_interrupt         ! transfers may be running
  3381. 3372   !
  3382. 3373    OPTION BASE 1
  3383. 3374    DISP CHR$(129);"CI"
  3384. 3375  ! uses:
  3385. 3376  ! Com_card, Com_port, Debug
  3386. 3377  !
  3387. 3378  !
  3388. 3379  !
  3389. 3380    COM /Crt/ Crt_lines,Crt_width
  3390. 3381    COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  3391. 3382  ! COM /Frame/ Baud,Data_bits,Stop_bits,On_off$,Parity_type$
  3392. 3383  ! COM /Frame/ Flow$,Hshake$
  3393. 3384    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  3394. 3385    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  3395. 3386  !
  3396. 3387    ON ERROR GOSUB Local_err
  3397. 3388    Errno=ERRN
  3398. 3389    IF Errno=0 THEN 
  3399. 3390      Errno=167                 ! INCASE THIS IS A REAL INTERRUPT NOT ERROR
  3400. 3391    END IF
  3401. 3392    GOSUB Local_err             ! PROCESS ERROR 167 - UART
  3402. 3393    DISP CHR$(128)
  3403. 3394    SUBEXIT
  3404. 3395  !-------------------------------------
  3405. 3396 Local_err: !
  3406. 3397    SELECT Errno
  3407. 3398    CASE 167                    ! process interrupt as error 167
  3408. 3399      SELECT Com_card
  3409. 3400      CASE 98644,98626
  3410. 3401        GOSUB Com_intr_26
  3411. 3402      CASE 98628
  3412. 3403        GOSUB Com_intr_28
  3413. 3404      CASE ELSE
  3414. 3405      END SELECT
  3415. 3406    CASE 163     ! io interace driver not present
  3416. 3407      DISP ERRM$
  3417. 3408      PAUSE
  3418. 3409    CASE 59        ! end of buffer found
  3419. 3410    ! do nothing -
  3420. 3411      CLEAR ERROR
  3421. 3412    CASE ELSE
  3422. 3413      DISP ERRM$;" Com_interrupt  "
  3423. 3414      PAUSE
  3424. 3415    END SELECT
  3425. 3416  !-----------------------------------------------------------------------
  3426. 3417 Com_intr_26: !
  3427. 3418   !
  3428. 3419   ! Reg. 9:  Bit 0      Set when all conditions are clear
  3429. 3420   !          Bit 1,2    Interrupt Cuase
  3430. 3421   !
  3431. 3422    STATUS Com_port,9;Int_cause
  3432. 3423    REPEAT
  3433. 3424      Ic=BINAND(Int_cause,7)   ! Look at bits 0-1-2
  3434. 3425      SELECT Ic
  3435. 3426      CASE 0                      ! change in modem status lines
  3436. 3427        STATUS Com_port,11;Mc     ! Modem Change
  3437. 3428        IF (BIT(Mc,4)) OR (BIT(Mc,5)) OR (BIT(Mc,6)) OR (BIT(Mc,7)) THEN 
  3438. 3429          IF Debug THEN PRINT TABXY(1,Crt_lines);"Serial Interrupt: Modem Line Disconnect"
  3439. 3430        ELSE
  3440. 3431          IF Debug THEN PRINT TABXY(1,Crt_lines);"Serial Interrupt: Modem Line Change "
  3441. 3432        END IF
  3442. 3433      CASE 2
  3443. 3434      CASE 4
  3444. 3435        IF Debug THEN PRINT "RECEIVE BUFFER FULL"
  3445. 3436        STATUS Com_port,6;Rec     ! Clear Interrupt
  3446. 3437      CASE 6                      ! UART Error
  3447. 3438        STATUS Com_port,10;Uart_err  ! Clear UART Interrupt
  3448. 3439        IF Debug THEN 
  3449. 3440          PRINT "UART ERROR: ";Uart_err
  3450. 3441          IF BIT(Uart_err,0) THEN PRINT "REC. BUFF FULL";   ! (1)
  3451. 3442          IF BIT(Uart_err,1) THEN PRINT "BUFF OVERRUN";     ! (2)
  3452. 3443          IF BIT(Uart_err,2) THEN PRINT "PARITY ";          ! (4)
  3453. 3444          IF BIT(Uart_err,3) THEN PRINT "Framing Error";    ! (8)
  3454. 3445          IF BIT(Uart_err,4) THEN PRINT "Break Received ";  ! (16)
  3455. 3446          IF BIT(Uart_err,5) THEN PRINT "Trans. Hold. Reg ";! (32)
  3456. 3447          IF BIT(Uart_err,6) THEN PRINT "Trans. Shift Reg ";! (64)
  3457. 3448          PRINT 
  3458. 3449        END IF
  3459. 3450      END SELECT
  3460. 3451      STATUS Com_port,9;Int_cause    ! BIT 0= SET when all intr are clear
  3461. 3452    UNTIL Int_cause=1
  3462. 3453    RETURN 
  3463. 3454 !======================================================================
  3464. 3455 Com_intr_28: !
  3465. 3456 Rc28: !
  3466. 3457 !
  3467. 3458    STATUS Com_port,4;Int_bits      ! RESET INTERRUPT
  3468. 3459    IF Debug THEN 
  3469. 3460      PRINT "INTERRUPT CAUSE:  "
  3470. 3461      IF BIT(Int_bits,0) THEN PRINT "DATA";
  3471. 3462      IF BIT(Int_bits,1) THEN PRINT "PROMPT REC.";
  3472. 3463      IF BIT(Int_bits,2) THEN PRINT "PARITY ERROR ";
  3473. 3464      IF BIT(Int_bits,3) THEN PRINT "MODEM LINE CHANGE ";
  3474. 3465      IF BIT(Int_bits,4) THEN PRINT "NO ACTIVITY TIMEOUT ";
  3475. 3466      IF BIT(Int_bits,5) THEN PRINT "LOST CARRIER ";
  3476. 3467      IF BIT(Int_bits,6) THEN PRINT "EOL RECEIVED ";
  3477. 3468      IF BIT(Int_bits,7) THEN PRINT "BREAK RECEIVED ";
  3478. 3469      PRINT 
  3479. 3470    END IF
  3480. 3471    RETURN 
  3481. 3472  SUBEND          ! Comm Interrupt-98628
  3482. 3473  ! ======================================================================
  3483. 3474 Krec:SUB K_receive(Filename$,F_msi$,F_path$,Ftype$,Recl,File_length)
  3484. 3475  !
  3485. 3476  ! Kermit Receive  File Protocol
  3486. 3477  !
  3487. 3478  ! File_length:     Bytes    if Filetype HPUX
  3488. 3479  !                  Records  if Filetype BDAT
  3489. 3480  !                  Sectors  if Filetype ASCII,SYSTM,BIN,PROG
  3490. 3481  !
  3491. 3482  ! Recl             Record length (BDAT ONLY)
  3492. 3483  !
  3493. 3484    OPTION BASE 1
  3494. 3485    COM Version$,K$,Setup$
  3495. 3486    COM /Crt/ Crt_lines,Crt_width
  3496. 3487    COM /Flags/ Kermit_exit,INTEGER Active,Debug,In_term
  3497. 3488    COM /Kerm/ INTEGER Maxp,Maxtry,Mypad,Mytmo,Mypchar,Myeol,Myquote
  3498. 3489    COM /Kerm/ INTEGER Size,Rpsiz,Spsiz,Pad,Capas
  3499. 3490    COM /Kerm/ INTEGER Image,Parflg,Pktdeb
  3500. 3491    COM /Kerm/ INTEGER Filnamcnv,Blk_chk,Quote,Eol
  3501. 3492    COM /Kerm2/ State$[1],Cchksum$[1],Eof_mode$,INTEGER Eof_mode,Timer,Ptmo
  3502. 3493    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  3503. 3494    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  3504. 3495    COM /Frame/ Baud,Data_bits,Stop_bits,On_off$[3],Parity_type$[4]
  3505. 3496    COM /Frame/ Flow$,Hshake$
  3506. 3497    COM /Term/ Term_type$[10],S_log,D_log,Filewarn,Discard,@S_log,@D_log
  3507. 3498    COM /Term/ Kerm_esc$[2],S_log$,D_log$,INTEGER Remote,Lecho,Turn,Display
  3508. 3499    COM /Term/ Term_mode$
  3509. 3500    COM /Path/ Cur_msi$,S_path$,S_msi$,D_path$,D_msi$
  3510. 3501  !
  3511. 3502  ! Local Vars
  3512. 3503  !
  3513. 3504    INTEGER Qbin,Rep_ch   ! not in kermit COM
  3514. 3505    INTEGER Chksum,Rc,Plen,Dlen,Cchksum,Rseq
  3515. 3506    INTEGER Ftype,Volnum,Prot,Recsize,Sec_data(1:256),Sectors
  3516. 3507    INTEGER File_open
  3517. 3508    INTEGER Npak,Oldtry,Spacks,Fpacks,Apacks,Dpacks,Zpacks,Bpacks,Epacks
  3518. 3509    INTEGER R_maxl1,R_maxl2,R_maxl
  3519. 3510    INTEGER User_break,Spillfile
  3520. 3511    REAL File_st,F_sec
  3521. 3512    ALLOCATE Rcvpkt$[1024],Sndpkt$[Spsiz],Rdata$[1024],A$[1],Packet$[Spsiz]
  3522. 3513    ALLOCATE File_buff$[4096],Sector$[256]
  3523. 3514    DIM Emsg$[100],Wmsg$[100],Pkt$[1]                 !,Cat$(10)[80]
  3524. 3515    DIM Asc_eol$[2]
  3525. 3516    DIM F$[80],Sav_msi$[256]
  3526. 3517  !--------------------------------------------
  3527. 3518    ON ERROR GOSUB Rec_err
  3528. 3519    Spillfile=0      ! indicates that a spillfile was needed
  3529. 3520    Asc_eol$=CHR$(13)&CHR$(10)
  3530. 3521    Buff_len=MAXLEN(File_buff$)
  3531. 3522    Sav_msi$=SYSTEM$("MSI")
  3532. 3523    Ramdisc=0
  3533. 3524 Check_ramdisc:MASS STORAGE IS ":,0,0"   ! check in rec_err
  3534. 3525    IF Kbytes=0 THEN 
  3535. 3526      Disc_space(":,0,0",Total,Largest_hole,Hole_sum,Format$)
  3536. 3527      IF Largest_hole>0 THEN Ramdisc=1
  3537. 3528      Kbytes=Largest_hole*256
  3538. 3529    END IF
  3539. 3530    CALL Shutdown
  3540. 3531   !
  3541. 3532   ! 98626 overrun error cannot be trapped during transfers - therefore
  3542. 3533   ! they only show up as error 167 IO status error
  3543. 3534   !
  3544. 3535    SELECT Com_card
  3545. 3536    CASE 98626,98644
  3546. 3537  !   CALL Reset_port             ! Accidentally  Disconnects Modem
  3547. 3538      ENABLE INTR Com_port;8+4               ! 8=modem   4=UART or Overrun
  3548. 3539    CASE 98628                               ! 2=tx reg  1=rec buff full
  3549. 3540  !   CALL Reset_port
  3550. 3541      CONTROL Com_port,13;164     ! INT MASK  4=UART  32=lost car 128=break
  3551. 3542    END SELECT
  3552. 3543  !
  3553. 3544    ON INTR Com_port,5 GOSUB Rec_intr
  3554. 3545    ON TIMEOUT 7,.5 GOSUB No_printer
  3555. 3546    ON KBD,3 GOSUB Kbr_int
  3556. 3547    CLEAR SCREEN
  3557. 3548    IF Display THEN 
  3558. 3549      PRINT TABXY(1,2);Version$
  3559. 3550      PRINT TABXY(15,5);"Filename: "                    ! LINE 5
  3560. 3551      PRINT TAB(6);"Bytes Transferred: ";TAB(25);Kbx   ! 6
  3561. 3552      PRINT 
  3562. 3553      PRINT TAB(16);"RECEIVE: In Progress"              ! 8
  3563. 3554      PRINT                                             ! 9
  3564. 3555      PRINT TAB(6);"Number of Packets: ";TAB(25);Npak   ! 10
  3565. 3556      PRINT TAB(6);"Number of Retries: ";TAB(25);Oldtry ! 11
  3566. 3557      PRINT TAB(13);"Last Error: "                      ! 12
  3567. 3558      PRINT TAB(11);"Last Warning: "                    ! 13
  3568. 3559                                                        ! 14
  3569. 3560      IF Debug THEN 
  3570. 3561        PRINT TABXY(11,15);"SPACK:        "             ! 15
  3571. 3562        PRINT TABXY(11,16);"RPACK:        "             ! 16
  3572. 3563      END IF
  3573. 3564    END IF
  3574. 3565    CALL Startup     ! re-activate transfers
  3575. 3566 Krecs:    !-------------------------------------  Receive
  3576. 3567    Input_buffer$=""
  3577. 3568    Npak=0
  3578. 3569    State$="S"
  3579. 3570  !
  3580. 3571  !------------------------  Receive  Sequence  --------------------------
  3581. 3572  !
  3582. 3573    REPEAT   ! Until State$="X","C"   receive done
  3583. 3574      SELECT State$         ! state switcher
  3584. 3575      CASE "S"
  3585. 3576 Sinit:  !
  3586. 3577        Packet$=""   ! Packet Data
  3587. 3578        Pkt$="N"     ! Nak unless expected packet arives
  3588. 3579        PRINT TABXY(25,13);"Exchanging Initialization Packets"
  3589. 3580        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Spacks,User_break,Emsg$)
  3590. 3581        IF (Debug) THEN PRINT TABXY(20,16);Rcvpkt$&RPT$(" ",20)
  3591. 3582        IF D_log THEN OUTPUT @D_log;"rpack: ";Rcvpkt$
  3592. 3583        SELECT Pktype$
  3593. 3584        CASE "S"
  3594. 3585          GOSUB Rrpar         ! Get remote Parameters
  3595. 3586          GOSUB Rspar         ! Form Packet$ with our parameters
  3596. 3587          Pkt$="Y"
  3597. 3588          State$="F"
  3598. 3589        CASE "E"            ! Either received or user abort E
  3599. 3590          IF NOT User_break THEN Emsg$=Rdata$
  3600. 3591          State$="E"
  3601. 3592        CASE "T"
  3602. 3593          Wmsg$="Packet Timeout"
  3603. 3594        CASE "Q"
  3604. 3595          Wmsg$="Bad Checksum"
  3605. 3596        CASE "F","A","D"
  3606. 3597          ! just Nak the expected packet number
  3607. 3598        CASE "Z","B"
  3608. 3599          State$=Pktype$         ! jump to eof or break state
  3609. 3600        CASE "X"            ! User Quit
  3610. 3601          Pkt$="Y"
  3611. 3602          Packet$=Rdata$    ! X or Z in ack packet will abort sender
  3612. 3603          State$="Z"        ! let Z state process closure
  3613. 3604        END SELECT
  3614. 3605      !
  3615. 3606        Spack(Packet$,Pkt$,Npak,Sndpkt$)
  3616. 3607        OUTPUT @Out_buff;Sndpkt$
  3617. 3608      !
  3618. 3609        IF Spacks>Maxtry THEN 
  3619. 3610          State$="E"
  3620. 3611          User_break=1
  3621. 3612          Emsg$="Unable to receive initiate"
  3622. 3613          Packet$=Emsg$
  3623. 3614        END IF
  3624. 3615        IF Pkt$="Y" THEN 
  3625. 3616     !    State$="F"            ! could  be X if aborting
  3626. 3617          Npak=Npak+1
  3627. 3618          Oldtry=Oldtry+Spacks
  3628. 3619        ELSE
  3629. 3620          Spacks=Spacks+1
  3630. 3621        END IF
  3631. 3622      !
  3632. 3623        PRINT TABXY(25,10);Npak
  3633. 3624        PRINT TABXY(25,11);Oldtry+Spacks
  3634. 3625        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  3635. 3626        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  3636. 3627        IF Debug THEN PRINT TABXY(20,15);Sndpkt$&RPT$(" ",60-(LEN(Sndpkt$)))
  3637. 3628        IF D_log THEN OUTPUT @D_log;"Spack: ";Sndpkt$
  3638. 3629    !-----------------------------------     Receive File Header (F)
  3639. 3630 Krecf:CASE "F"      ! Enter Npak=1
  3640. 3631        Packet$=""
  3641. 3632        IF Debug THEN PRINT TABXY(25,4);State$
  3642. 3633        Pkt$="N"
  3643. 3634        PRINT TABXY(25,13);"Receiving Filename"&RPT$(" ",26)
  3644. 3635        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Fpacks,User_break,Emsg$)
  3645. 3636        IF Debug THEN PRINT TABXY(20,16);Rcvpkt$&RPT$(" ",80-LEN(Rcvpkt$))
  3646. 3637        IF D_log THEN OUTPUT @D_log;"rpack: ";Rcvpkt$
  3647. 3638        SELECT Pktype$
  3648. 3639        CASE "S"
  3649. 3640          OUTPUT @Out_buff;Sndpkt$   !  S Packet Sndpkt$ still in tact
  3650. 3641          IF D_log THEN OUTPUT @D_log;"Spack: ";Sndpkt$
  3651. 3642        CASE "E"
  3652. 3643          Emsg$=Rdata$
  3653. 3644          State$="E"
  3654. 3645        CASE "T"
  3655. 3646          Wmsg$="Packet Timeout"
  3656. 3647        CASE "Q"
  3657. 3648          Wmsg$="Bad Checksum"
  3658. 3649        CASE "A","D"
  3659. 3650        ! Just Nak               ! probably should abort here
  3660. 3651        CASE "Z","B"
  3661. 3652          State$=Pktype$
  3662. 3653        CASE "X"
  3663. 3654          Pkt$="Y"
  3664. 3655          Packet$=Rdata$
  3665. 3656          State$="Z"
  3666. 3657        CASE "F"
  3667. 3658          Pkt$="Y"
  3668. 3659          Oldtry=Oldtry+Spacks
  3669. 3660          IF Rcap_a THEN            ! Attribute Packets in use
  3670. 3661            State$="A"
  3671. 3662          ELSE
  3672. 3663            State$="D"
  3673. 3664          END IF
  3674. 3665          GOSUB Verify_fname        ! Create F_path$, F_msi$, Filename$
  3675. 3666        END SELECT
  3676. 3667        Spack(Packet$,Pkt$,Npak,Sndpkt$)
  3677. 3668        OUTPUT @Out_buff;Sndpkt$
  3678. 3669      !
  3679. 3670        IF Debug THEN PRINT TABXY(20,15);Sndpkt$&RPT$(" ",60-LEN(Sndpkt$))
  3680. 3671        IF D_log THEN OUTPUT @D_log;"Spack: ";Sndpkt$
  3681. 3672        IF Fpacks>Maxtry THEN 
  3682. 3673          State$="E"
  3683. 3674          User_break=1
  3684. 3675          Packet$="Unable to receive filename"
  3685. 3676        END IF
  3686. 3677        PRINT TABXY(25,10);Npak
  3687. 3678        PRINT TABXY(25,11);Oldtry+Fpacks
  3688. 3679        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  3689. 3680        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  3690. 3681      !
  3691. 3682        IF Pkt$="Y" THEN 
  3692. 3683          Npak=Npak+1
  3693. 3684        ELSE
  3694. 3685          Fpacks=Fpacks+1
  3695. 3686        END IF
  3696. 3687    !--------------------------------------  File Attributes
  3697. 3688      CASE "A"
  3698. 3689 Kreca:  !
  3699. 3690        Packet$=""
  3700. 3691        IF Debug THEN PRINT TABXY(25,4);State$
  3701. 3692        Pkt$="N"
  3702. 3693        PRINT TABXY(25,13);"Receiving File Attributes"&RPT$(" ",19)
  3703. 3694        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Apacks,User_break,Emsg$)
  3704. 3695        IF Debug THEN PRINT TABXY(20,16);Rcvpkt$&RPT$(" ",60-LEN(Rcvpkt$))
  3705. 3696        IF D_log THEN OUTPUT @D_log;"rpack: ";Rcvpkt$
  3706. 3697        SELECT Pktype$
  3707. 3698        CASE "A"
  3708. 3699          GOSUB Get_at
  3709. 3700          Pkt$="Y"
  3710. 3701          IF File_length THEN 
  3711. 3702            PRINT TABXY(10,7);"% Transferred:"
  3712. 3703          END IF
  3713. 3704          State$="D"
  3714. 3705        CASE "Z","B"
  3715. 3706          State$=Pktype$
  3716. 3707        CASE "E"
  3717. 3708          Emsg$=Rdata$
  3718. 3709          State$="E"
  3719. 3710        CASE "T"
  3720. 3711          Wmsg$="Packet Timeout"
  3721. 3712        CASE "Q"
  3722. 3713          Wmsg$="Bad Checksum"
  3723. 3714        CASE "X"
  3724. 3715          Pkt$="Y"
  3725. 3716          Packet$=Rdata$
  3726. 3717          State$="Z"
  3727. 3718        END SELECT
  3728. 3719      !
  3729. 3720        Spack(Packet$,Pkt$,Npak,Sndpkt$)
  3730. 3721        OUTPUT @Out_buff;Sndpkt$
  3731. 3722        IF Debug THEN PRINT TABXY(20,15);Sndpkt$&RPT$(" ",60-LEN(Sndpkt$))
  3732. 3723        IF D_log THEN OUTPUT @D_log;"Spack: ";Sndpkt$
  3733. 3724        PRINT TABXY(25,10);Npak
  3734. 3725        PRINT TABXY(25,11);Oldtry+Apacks
  3735. 3726        IF Apacks>Maxtry THEN 
  3736. 3727          State$="E"
  3737. 3728          User_break=1
  3738. 3729          Packet$="Unable to receive attribute packet"
  3739. 3730        END IF
  3740. 3731        IF Pkt$="Y" THEN 
  3741. 3732          Npak=Npak+1
  3742. 3733          Oldtry=Oldtry+Spacks
  3743. 3734        ELSE
  3744. 3735          Apacks=Apacks+1
  3745. 3736        END IF
  3746. 3737        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  3747. 3738        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  3748. 3739    !--------------------------------------  Receive File Data  "D"
  3749. 3740      CASE "D"
  3750. 3741 Krecd: !
  3751. 3742        Packet$=""
  3752. 3743        Rdata$=""
  3753. 3744        Pkt$="N"
  3754. 3745     !
  3755. 3746        IF NOT Dinit THEN 
  3756. 3747          PRINT TABXY(25,13);"Receiving File Data"&RPT$(" ",25)
  3757. 3748          Dinit=1
  3758. 3749        END IF
  3759. 3750        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Dpacks,User_break,Emsg$)
  3760. 3751        IF Debug THEN PRINT TABXY(20,16);Rcvpkt$&RPT$(" ",20)
  3761. 3752        IF D_log THEN OUTPUT @D_log;"rpack: ";Rcvpkt$
  3762. 3753        SELECT Pktype$
  3763. 3754        CASE "F","S","A"
  3764. 3755          Emsg$="Packets out of sequence"
  3765. 3756          State$="E"
  3766. 3757          User_break=1
  3767. 3758        CASE "Z","B"         ! Process State Z here
  3768. 3759          PRINT TABXY(25,13);"Receiving End of File"&RPT$(" ",25)
  3769. 3760       !
  3770. 3761       ! Write Remaining File Lines
  3771. 3762       !
  3772. 3763          IF File_open THEN 
  3773. 3764            SELECT Filetype$
  3774. 3765            CASE "ASCII"
  3775. 3766              OUTPUT @File;File_buff$
  3776. 3767            CASE "HPUX","BDAT"
  3777. 3768              OUTPUT @File USING "#,K";File_buff$
  3778. 3769            CASE ELSE
  3779. 3770              OUTPUT @File;File_buff$;
  3780. 3771            END SELECT
  3781. 3772            OUTPUT @File;END
  3782. 3773            ASSIGN @File TO *
  3783. 3774            File_open=0
  3784. 3775          END IF! file open
  3785. 3776          Pkt$="Y"
  3786. 3777          State$="B"              ! Skip over Z state (done here )
  3787. 3778          Oldtry=Oldtry+Spacks
  3788. 3779        CASE "E"
  3789. 3780          Emsg$=Rdata$
  3790. 3781          State$="E"
  3791. 3782        CASE "T"
  3792. 3783          Wmsg$="Packet Timeout"
  3793. 3784        CASE "Q"
  3794. 3785          Wmsg$="Bad Checksum or Sequence"
  3795. 3786        CASE "X"
  3796. 3787          Pkt$="Y"
  3797. 3788          Packet$=Rdata$
  3798. 3789          State$="Z"
  3799. 3790          User_break=1
  3800. 3791     !---------------------------------------  File Data Received
  3801. 3792        CASE "D"
  3802. 3793          Pkt$="Y"
  3803. 3794        CASE ELSE
  3804. 3795        END SELECT
  3805. 3796    !
  3806. 3797        Spack(Packet$,Pkt$,Npak,Sndpkt$)
  3807. 3798        OUTPUT @Out_buff;Sndpkt$
  3808. 3799        IF Debug THEN PRINT TABXY(20,15);Sndpkt$&RPT$(" ",60-LEN(Sndpkt$))
  3809. 3800        IF D_log THEN OUTPUT @D_log;"Spack: ";Sndpkt$
  3810. 3801        PRINT TABXY(25,10);Npak
  3811. 3802        PRINT TABXY(25,11);Oldtry+Dpacks
  3812. 3803        IF Dpacks>Maxtry THEN 
  3813. 3804          State$="E"
  3814. 3805          User_break=1
  3815. 3806          Packet$="Unable to receive file data packet"
  3816. 3807        END IF
  3817. 3808      !
  3818. 3809        IF Pkt$="Y" THEN 
  3819. 3810          Npak=Npak+1
  3820. 3811        ELSE
  3821. 3812          Dpacks=Dpacks+1
  3822. 3813        END IF
  3823. 3814        IF Display THEN 
  3824. 3815          PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  3825. 3816          PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  3826. 3817        END IF
  3827. 3818        IF (User_break) OR (State$<>"D") THEN GOTO Krecd_exit
  3828. 3819     !
  3829. 3820        IF Pkt$="Y" THEN            !- PACKET IS "Y" - RECEIVE DATA
  3830. 3821          IF User_break THEN GOTO Krecd_exit   ! Avoid Data Packet
  3831. 3822          DISABLE 
  3832. 3823 Of: ! ---- Create and Open File
  3833. 3824          IF NOT File_open THEN 
  3834. 3825          !
  3835. 3826            IF NOT (LEN(Ftype$)) THEN Ftype$="HPUX"
  3836. 3827       !
  3837. 3828       ! Process Filelength
  3838. 3829       !
  3839. 3830            IF File_length=0 THEN   ! Attribute Packet Not Used
  3840. 3831              SELECT Ftype$
  3841. 3832              CASE "HPUX","PROG"
  3842. 3833                IF Hfs_disc THEN 
  3843. 3834                  File_length=1
  3844. 3835                ELSE
  3845. 3836                  IF Ramfile THEN File_length=Kbytes
  3846. 3837                  IF NOT Ramfile THEN File_length=50000  ! bytes
  3847. 3838                END IF
  3848. 3839              CASE ELSE
  3849. 3840                IF Hfs_disc THEN 
  3850. 3841                  File_length=1
  3851. 3842                ELSE
  3852. 3843                  IF Ramfile THEN File_length=Kbytes
  3853. 3844                  IF NOT Ramfile THEN File_length=50000
  3854. 3845                END IF
  3855. 3846              END SELECT
  3856. 3847            ELSE           ! file length spec in attribute packet
  3857. 3848              IF Ramdisc THEN 
  3858. 3849                IF File_length>(Kbytes*1000) THEN  ! ramdisc too small
  3859. 3850                  Wmsg$="File larger than Mass Storage"
  3860. 3851                  Emsg$="Mass Storage Overflow"
  3861. 3852                  State$="E"
  3862. 3853                  User_break=1
  3863. 3854                  GOTO Krecd_exit
  3864. 3855                END IF
  3865. 3856              END IF
  3866. 3857            END IF        ! File Length = 0
  3867. 3858        !
  3868. 3859        ! Code to check for residual file not working add an extra sector
  3869. 3860        !
  3870. 3861        !   Res=File_length MOD 256
  3871. 3862        !   IF NOT Res THEN
  3872. 3863        !   Sectors=MAX(1,INT(File_length/256))
  3873. 3864        !   ELSE
  3874. 3865            Sectors=MAX(1,INT(File_length/256)+1)
  3875. 3866        !   END IF
  3876. 3867        !
  3877. 3868            SELECT Ftype$
  3878. 3869            CASE "HP-UX","HPUX"
  3879. 3870              CREATE F_path$&Filename$&F_msi$,File_length+1
  3880. 3871            CASE "BDAT"
  3881. 3872              IF Recl>0 THEN 
  3882. 3873                CREATE BDAT F_path$&Filename$&F_msi$,Sectors,Recl
  3883. 3874              ELSE
  3884. 3875                CREATE BDAT F_path$&Filename$&F_msi$,Sectors
  3885. 3876              END IF
  3886. 3877            CASE "ASCII"
  3887. 3878              CREATE ASCII F_path$&Filename$&F_msi$,Sectors
  3888. 3879            CASE ELSE    ! "SYSTM","BIN","PROG"
  3889. 3880              CREATE F_path$&Filename$&F_msi$,File_length   ! Use HP-UX then convert later
  3890. 3881            END SELECT
  3891. 3882          !
  3892. 3883            IF State$="E" THEN               ! Mass Storage Overflow ?
  3893. 3884              User_break=1
  3894. 3885              GOTO Krecd_exit
  3895. 3886            END IF
  3896. 3887            ASSIGN @File TO F_path$&Filename$&F_msi$;FORMAT OFF
  3897. 3888            File_open=1
  3898. 3889          ! ---------------------------------  Init Process Rdata$
  3899. 3890            P=1         ! packet contents pointer
  3900. 3891            Qon=0       ! quoting on flag
  3901. 3892            Biton=0     ! 8 bit prefixing flag
  3902. 3893            Rept=0      ! repeat prefix flag
  3903. 3894          END IF  ! file not open
  3904. 3895        END IF    !   D Packet and File Not open
  3905. 3896     !---------------------------------------------  Pack File_buff$(*)
  3906. 3897 Decode: !
  3907. 3898        IF Pktype$="D" THEN 
  3908. 3899                                    ! strip parity bits here  ????????????
  3909. 3900          CALL Decode_pack(Rdata$,Quote,Qbin,Rep_ch)
  3910. 3901          File_buff$=File_buff$&Rdata$
  3911. 3902          Pl=LEN(Rdata$)            ! Pl = Packet Length
  3912. 3903          P=P+Pl                    ! P  = Buffer Pointer (File_buff$)
  3913. 3904        END IF   ! D Packet
  3914. 3905      !
  3915. 3906        Kbx=Kbx+Pl                  ! Kbx = Bytes Transferred
  3916. 3907        PRINT TABXY(25,6);Kbx           !INT(Kbx/1000)
  3917. 3908        IF At_filelength THEN 
  3918. 3909          PRINT TABXY(25,7);INT((Kbx*100)/File_length);"%"
  3919. 3910        END IF
  3920. 3911      !
  3921. 3912      ! Check Buffer Length and write File
  3922. 3913      !
  3923. 3914        IF P>Buff_len-100 THEN               !write file
  3924. 3915          IF Debug THEN DISP "Writing File ";F_path$&Filename$&F_msi$
  3925. 3916          SELECT Ftype$
  3926. 3917          CASE "ASCII"
  3927. 3918        !
  3928. 3919        ! The File_buff$ is parsed for CR-LF (Ascii_eol$)
  3929. 3920        ! The Eol$ is removed, and each line is written to the Ascii
  3930. 3921        ! File creating Length-header delimited data.
  3931. 3922        !
  3932. 3923            Ascii_eol$="
  3933. "
  3934. 3924            Eol_l=LEN(Ascii_eol$)
  3935. 3925            REPEAT
  3936. 3926              Eolpos=POS(File_buff$,Ascii_eol$)
  3937. 3927              IF Eolpos THEN 
  3938. 3928                Sector$=File_buff$[1,Eolpos]
  3939. 3929              ELSE    ! the last fragment has no eol in the packet
  3940. 3930                Sector$=File_buff$
  3941. 3931              END IF
  3942. 3932              OUTPUT @File;Sector$;
  3943. 3933              File_buff$=File_buff$[Eolpos+Eol_l]  ! truncate and remove eol
  3944. 3934            UNTIL Eolpos=0
  3945. 3935          CASE ELSE
  3946. 3936            OUTPUT @File USING "#,K";File_buff$      ! supress <null> eol
  3947. 3937          END SELECT
  3948. 3938          File_buff$=""
  3949. 3939          P=0
  3950. 3940        END IF
  3951. 3941 Krecd_exit: !ENABLE
  3952. 3942    !----------------------------------------------------------------------
  3953. 3943 Krecz:CASE "Z"
  3954. 3944     !
  3955. 3945     !  State Z is normally processed in D State Handling -
  3956. 3946     !  Rdata$ in tact
  3957. 3947     !---------------------------------------------------------------------
  3958. 3948     !  This state is entered in 2 situations -
  3959. 3949     !
  3960. 3950     ! 1. Sender sends a Z packet prematurely
  3961. 3951     ! 2. User (receiver) abort
  3962. 3952     !  This state may be entered forom a user-abort sequence ^X  ^Z
  3963. 3953     !  If so, then the user_break flag will be set, and Rdata$ will be
  3964. 3954     !  X if ^X was invoked, or Z if ^Z was invoked.
  3965. 3955     !--------------------------------------------------------------------
  3966. 3956     ! Variables set after user break conditions
  3967. 3957  !
  3968. 3958  !          Pktype$     Rdata$    State$
  3969. 3959  !   ^X       X           X        --
  3970. 3960  !   ^Z       X           Z        --
  3971. 3961  !   ^E       E          --        E
  3972. 3962  !   ^C       X          ^C        X   (unless changed in other states)
  3973. 3963  !
  3974. 3964  !
  3975. 3965        IF User_break THEN 
  3976. 3966          IF NOT POS(Rdata$,"^C") THEN             ! Ok to notify host
  3977. 3967          !
  3978. 3968          ! ^X and ^Z:  send ack with X or Z in data field
  3979. 3969          !
  3980. 3970            Packet$=Rdata$
  3981. 3971            Spack(Packet$,State$,Npak,Sndpkt$)
  3982. 3972            OUTPUT @Out_buff;Sndpkt$
  3983. 3973            IF Debug THEN PRINT TABXY(25,16);Sndpkt$&"                "
  3984. 3974            Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Zpacks,User_break,Emsg$)
  3985. 3975          ELSE   ! ^C processing just abort
  3986. 3976           ! fall thru to check pktype
  3987. 3977          END IF
  3988. 3978        ELSE
  3989. 3979          Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Bpacks,User_break,Emsg$)
  3990. 3980        END IF
  3991. 3981        IF Debug THEN PRINT TABXY(20,16);Rcvpkt$&RPT$(" ",60-LEN(Rcvpkt$))
  3992. 3982        IF D_log THEN OUTPUT @D_log;"rpack: ";Rcvpkt$
  3993. 3983        Pkt$="N"
  3994. 3984 Check_z:!
  3995. 3985        SELECT Pktype$
  3996. 3986        CASE "Z"
  3997. 3987       ! ** Should inspect Rdata$ for a "D)iscard" instruction"
  3998. 3988       ! if Rdata$="D" then discard file.
  3999. 3989       !
  4000. 3990       ! Write Remaining File Lines **
  4001. 3991       !
  4002. 3992          IF Rdata$="D" THEN 
  4003. 3993       ! discard file here
  4004. 3994            DISP "Received Abort from Sender and signal to discard file - purge file ? "
  4005. 3995            OUTPUT KBD;"Y";" H";
  4006. 3996            ENTER KBD;Ans$
  4007. 3997            DISP 
  4008. 3998            IF UPC$(Ans$)="Y" THEN 
  4009. 3999              DISP "Purging File: ";Filename$
  4010. 4000              PURGE Filename$
  4011. 4001            END IF
  4012. 4002          ELSE     ! close file normally
  4013. 4003            IF File_open THEN 
  4014. 4004              Bl=LEN(File_buff$)
  4015. 4005              SELECT Filetype$
  4016. 4006              CASE "HPUX","BDAT"
  4017. 4007                OUTPUT @File;File_buff$;END
  4018. 4008                PRINT File_buff$
  4019. 4009              CASE "ASCII"
  4020. 4010                OUTPUT @File;File_buff$;END
  4021. 4011              END SELECT
  4022. 4012              ASSIGN @File TO *
  4023. 4013              File_open=0
  4024. 4014              DISP 
  4025. 4015            ELSE
  4026. 4016              Wmsg$="(Z) File not Open "
  4027. 4017            END IF! file open
  4028. 4018          END IF
  4029. 4019          Pkt$="Y"
  4030. 4020          State$="B"
  4031. 4021          Oldtry=Oldtry+Zpacks
  4032. 4022        CASE "B"
  4033. 4023          State$="C"              ! File Transfer Complete
  4034. 4024          Pkt$="Y"
  4035. 4025        CASE "E"
  4036. 4026          Emsg$=Rdata$
  4037. 4027          State$="E"
  4038. 4028        CASE "T"
  4039. 4029          Wmsg$="Packet Timeout"
  4040. 4030        CASE "Q"
  4041. 4031          Wmsg$="Bad Checksum"
  4042. 4032        CASE "X"
  4043. 4033          State$="X"    ! abort
  4044. 4034        END SELECT
  4045. 4035    !
  4046. 4036        Spack(Packet$,Pkt$,Npak,Sndpkt$)   !?????????????????????
  4047. 4037        OUTPUT @Out_buff;Sndpkt$
  4048. 4038        IF Debug THEN PRINT TABXY(20,15);Sndpkt$&RPT$(" ",60-LEN(Sndpkt$))
  4049. 4039        IF D_log THEN OUTPUT @D_log;"Spack: ";Sndpkt$
  4050. 4040      !
  4051. 4041        IF Zpacks>Maxtry THEN 
  4052. 4042          State$="E"
  4053. 4043          User_break=1
  4054. 4044          Packet$="Unable to receive EOF (Z)  packet"
  4055. 4045          Emsg$="Unable to receive EOF (Z)  packet"
  4056. 4046        END IF
  4057. 4047      !
  4058. 4048        IF Pkt$="Y" THEN 
  4059. 4049          Npak=Npak+1
  4060. 4050        ELSE
  4061. 4051          Zpacks=Zpacks+1
  4062. 4052        END IF
  4063. 4053      !
  4064. 4054 Krecz_exit:!
  4065. 4055        PRINT TABXY(25,10);Npak
  4066. 4056        PRINT TABXY(25,11);Oldtry+Bpacks
  4067. 4057        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  4068. 4058        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  4069. 4059  !---------------------------------------------------------------------
  4070. 4060 Krecb:CASE "B"
  4071. 4061     !
  4072. 4062        Packet$=""
  4073. 4063        IF Debug THEN PRINT TABXY(25,4);State$
  4074. 4064        Pkt$="N"
  4075. 4065        PRINT TABXY(25,13);RPT$(" ",55)
  4076. 4066        Rpack(Pktype$,Rdata$,Rseq,Rcvpkt$,Sndpkt$,Npak,Bpacks,User_break,Emsg$)
  4077. 4067        IF Debug THEN PRINT TABXY(20,16);Rcvpkt$&RPT$(" ",60-LEN(Rcvpkt$))
  4078. 4068        IF D_log THEN OUTPUT @D_log;"rpack: ";Rcvpkt$
  4079. 4069        SELECT Pktype$
  4080. 4070        CASE "Z"
  4081. 4071          Pkt$="Y"
  4082. 4072          State$="B"              ! Skip over Z state (done here )
  4083. 4073          Oldtry=Oldtry+Zpacks
  4084. 4074        CASE "B"
  4085. 4075          State$="C"              ! File Transfer Complete
  4086. 4076          Pkt$="Y"
  4087. 4077        CASE "E"
  4088. 4078          Emsg$=Rdata$
  4089. 4079          State$="E"
  4090. 4080        CASE "T"
  4091. 4081          Wmsg$="Packet Timeout"
  4092. 4082        CASE "Q"
  4093. 4083          Wmsg$="Bad Checksum"
  4094. 4084        CASE "X"
  4095. 4085        END SELECT
  4096. 4086    !
  4097. 4087        Spack(Packet$,Pkt$,Npak,Sndpkt$)
  4098. 4088        OUTPUT @Out_buff;Sndpkt$
  4099. 4089        IF Debug THEN PRINT TABXY(20,15);Sndpkt$&RPT$(" ",60-LEN(Sndpkt$))
  4100. 4090        IF D_log THEN OUTPUT @D_log;"Spack: ";Sndpkt$
  4101. 4091        PRINT TABXY(25,10);Npak
  4102. 4092        PRINT TABXY(25,11);Oldtry+Bpacks
  4103. 4093      !
  4104. 4094        IF Bpacks>Maxtry THEN 
  4105. 4095          State$="E"
  4106. 4096          User_break=1
  4107. 4097          Packet$="Unable to receive break packet"
  4108. 4098          Emsg$="Unable to receive break packet"
  4109. 4099        END IF
  4110. 4100      !
  4111. 4101        IF Pkt$="Y" THEN 
  4112. 4102          IF User_break THEN 
  4113. 4103            State$="X"
  4114. 4104          ELSE
  4115. 4105            State$="C"
  4116. 4106          END IF
  4117. 4107          Npak=Npak+1
  4118. 4108        ELSE ! pkt$="N"
  4119. 4109          Bpacks=Bpacks+1
  4120. 4110        END IF
  4121. 4111      !
  4122. 4112        PRINT TABXY(25,10);Npak
  4123. 4113        PRINT TABXY(25,11);Oldtry+Bpacks
  4124. 4114        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  4125. 4115        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  4126. 4116  !
  4127. 4117        IF Ftype$="PROG" THEN 
  4128. 4118          CALL Convert(F_path$&Filename$&F_msi$,"PROG",Rc)
  4129. 4119          PRINT TABXY(1,18);"PROG File exists on Ram Disc - Copy file to disc before leaving Kermit"
  4130. 4120        END IF
  4131. 4121  !------------------------------------------------------------------------
  4132. 4122 Krece:CASE "E"    !
  4133. 4123   !
  4134. 4124   !  Enter E state on:
  4135. 4125   !
  4136. 4126   ! 1. Received E  Packet from Host    (User_break=0)
  4137. 4127   !    Erm$ (and Rdata$) contains the host error message
  4138. 4128   ! 2. User Abort - User_break=1
  4139. 4129   ! Packet$ (rdata$  ? )contains the error message being sent
  4140. 4130   !
  4141. 4131   ! Emsg$ must contain data mesage for packet
  4142. 4132   !
  4143. 4133        BEEP 
  4144. 4134        IF User_break THEN      ! User abort
  4145. 4135          Pkt$="E"   ! Nak unless expected packet arives
  4146. 4136          Packet$=Emsg$
  4147. 4137          Spack(Packet$,Pkt$,Npak,Sndpkt$)
  4148. 4138          OUTPUT @Out_buff;Sndpkt$
  4149. 4139          IF D_log THEN OUTPUT @D_log;"SPACK: ";Sndpkt$
  4150. 4140          State$="X"              ! indicate User Abort
  4151. 4141        ELSE   ! Host Error - E packet  Received
  4152. 4142          State$="X"
  4153. 4143        END IF
  4154. 4144        PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  4155. 4145        PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  4156. 4146        PRINT TABXY(1,Crt_lines);
  4157. 4147       !----------------------------------------------------------------
  4158. 4148      END SELECT    ! Receive State Switch
  4159. 4149    UNTIL (State$="X") OR (State$="C")     ! Don't put "E" here !
  4160. 4150   !========================================================================
  4161. 4151    IF D_log THEN ASSIGN @D_log TO *
  4162. 4152    ASSIGN @File TO *
  4163. 4153   !
  4164. 4154    IF Com_card=98628 THEN 
  4165. 4155     ! Do Nothing
  4166. 4156    ELSE  ! 98626
  4167. 4157      REPEAT
  4168. 4158        STATUS @Out_buff,4;Bl     ! Finish sending last packet
  4169. 4159      UNTIL Bl=0
  4170. 4160    !
  4171. 4161      STATUS @In_buff,4;Bl
  4172. 4162      WHILE Bl
  4173. 4163        OUTPUT @Out_buff;"
  4174. "
  4175. 4164        IF Bl THEN ENTER @In_buff;Misc$
  4176. 4165        IF Debug THEN PRINT Misc$
  4177. 4166        STATUS @In_buff,4;Bl     ! Finish sending last packet
  4178. 4167      END WHILE
  4179. 4168   !  CALL Shutdown      ! << this could be screwing things
  4180. 4169    END IF
  4181. 4170   !
  4182. 4171 Krec_exit:  !
  4183. 4172   !
  4184. 4173    PRINTER IS CRT
  4185. 4174    PRINT TABXY(1,16);
  4186. 4175    SELECT State$
  4187. 4176    CASE "C"
  4188. 4177      PRINT TABXY(16,8);"RECEIVE: Completed  "              ! 8
  4189. 4178    CASE "X"
  4190. 4179      IF NOT User_break THEN 
  4191. 4180        PRINT TABXY(16,8);"RECEIVE: Aborted by host "       ! 8
  4192. 4181      ELSE
  4193. 4182        PRINT TABXY(16,8);"RECEIVE: Aborted by user "       ! 8
  4194. 4183     !  PRINT Emsg$
  4195. 4184      END IF
  4196. 4185   ! process incomplete file here - save or discard
  4197. 4186      IF Discard THEN 
  4198. 4187        DISP "Discard File: ";F_path$&Filename$&F_msi$;"  ?"
  4199. 4188        OUTPUT KBD;"Yes";
  4200. 4189        ENTER KBD;Ans$
  4201. 4190        DISP 
  4202. 4191        ON ERROR GOTO No_discard
  4203. 4192        IF POS(UPC$(Ans$),"Y") THEN PURGE F_path$&Filename$&F_msi$
  4204. 4193 No_discard:DISP ERRM$
  4205. 4194        OFF ERROR 
  4206. 4195      END IF
  4207. 4196    END SELECT
  4208. 4197    PRINT TABXY(1,Crt_lines);
  4209. 4198    MASS STORAGE IS Sav_msi$
  4210. 4199    SUBEXIT
  4211. 4200 !-----------------------------------------------------------------------
  4212. 4201 Verify_fname: !   called from State "F"
  4213. 4202 Vf: !
  4214. 4203      ! 1. If filename was not specified locally, then use the incomming
  4215. 4204      !    filename. Make sure name is legal and < 10 chars
  4216. 4205      ! 2. Check for :MSI. If none specified, then append the
  4217. 4206      !    local default_msi$. If Ramdisc make sure it exists.
  4218. 4207      ! 3. Parse filename and create F_path$, F_msi$, Filename$
  4219. 4208      ! 4. If PROG Filetype then make F_msi$=ram disc
  4220. 4209      !
  4221. 4210    IF NOT LEN(Filename$) OR Filename$="," THEN    !use incomming file name.
  4222. 4211      IF Debug THEN DISP "Using the incomming filename"
  4223. 4212      Filename$=TRIM$(Rdata$)
  4224. 4213      Sav_filename$=Filename$
  4225. 4214      CALL Parse_filename(Filename$,F_msi$,F_path$)
  4226. 4215      IF NOT LEN(Filename$) THEN Filename$="K_DEFAULT"
  4227. 4216      IF Filnamcnv THEN Filename$=UPC$(Filename$)
  4228. 4217    END IF
  4229. 4218      !
  4230. 4219      ! Check Filename Length =  10 characters or less
  4231. 4220      !
  4232. 4221    WHILE LEN(Filename$)>10
  4233. 4222      DISP "filename too long - shorten "
  4234. 4223      OUTPUT KBD;Filename$;" H";
  4235. 4224      ENTER KBD;Filename$
  4236. 4225      DISP 
  4237. 4226    END WHILE
  4238. 4227     !
  4239. 4228     !   Check if ramdisc msi and if ramdisc is available. If not
  4240. 4229     !   Change :MSI to a physical disc.
  4241. 4230     !
  4242. 4231    IF Filetype$="PROG" THEN F_msi$=":,0,0"
  4243. 4232    IF (POS(F_msi$,":,0") OR POS(F_msi$,":MEMORY")) AND (Ramdisc=1) THEN 
  4244. 4233      Ramfile=1
  4245. 4234      IF Debug THEN PRINT "using ramdisc"
  4246. 4235    ELSE
  4247. 4236      IF POS(F_msi$,":,0") AND (Ramdisc=0) THEN 
  4248. 4237        BEEP 
  4249. 4238        DISP "Change MSI - Ramdisc not available"
  4250. 4239        OUTPUT KBD;F_path$&Filename$&F_msi$;
  4251. 4240        ENTER KBD;Filename$
  4252. 4241        CALL Parse_filename(Filename$,F_msi$,F_path$)
  4253. 4242      END IF
  4254. 4243    END IF
  4255. 4244    PRINT TABXY(25,5);" As  ";F_path$&Filename$&F_msi$
  4256. 4245    RETURN 
  4257. 4246  !------------------------------------------------------------------------
  4258. 4247 Create_unique: !    ! Filewarn=1 Don't Purge File - create a unique name
  4259. 4248    F$=Filename$
  4260. 4249    Unq_made=0
  4261. 4250  !
  4262. 4251  ! Get a catalog of a duplicate filenames upto "_" character
  4263. 4252  !
  4264. 4253  !
  4265. 4254    IF LEN(F$)<9 THEN 
  4266. 4255      Find$=F$&"_"
  4267. 4256    ELSE
  4268. 4257      Find$=F$[1,8]&"_"
  4269. 4258    END IF
  4270. 4259    ALLOCATE Cat$(30)[80]
  4271. 4260    CAT F_msi$ TO Cat$(*);SELECT Find$,COUNT Dupnames,NO HEADER
  4272. 4261  !---------------------------------------------
  4273. 4262  ! Find the next unique suffix
  4274. 4263  ! Find$ = The base filename without sufix
  4275. 4264  !
  4276. 4265    IF Dupnames THEN       ! INCR NEXT_UNIQUE UNTIL UNIQUE
  4277. 4266      Next_unique=47       ! STARTING PLACE IN ASCII TABLE "0"
  4278. 4267      REPEAT
  4279. 4268        Next_unique=Next_unique+1
  4280. 4269        IF (Next_unique>57) AND (Next_unique<65) THEN Next_unique=65
  4281. 4270        IF (Next_unique>90) AND (Next_unique<97) THEN Next_unique=97
  4282. 4271        IF Next_unique>126 THEN 
  4283. 4272          DISP "Can't Create a unique name - all ascii chars used"
  4284. 4273          PAUSE
  4285. 4274        END IF
  4286. 4275      !
  4287. 4276        Nu_found=1
  4288. 4277        FOR Df=1 TO Dupnames
  4289. 4278          IF POS(Cat$(Df),Find$&CHR$(Next_unique)) THEN     ! UNIQUE
  4290. 4279            Nu_found=0
  4291. 4280          END IF
  4292. 4281        NEXT Df
  4293. 4282      UNTIL Nu_found
  4294. 4283    ELSE
  4295. 4284      Next_unique=48    ! IF NO DUPES THEN - DEFAULT TO 48   "_0"
  4296. 4285    END IF
  4297. 4286    DEALLOCATE Cat$(*)
  4298. 4287  !---------------------------------------------
  4299. 4288    REPEAT                    ! until a unique name is made
  4300. 4289    !
  4301. 4290    ! Make sure filename is unique
  4302. 4291    !
  4303. 4292      Ftest$=Find$&CHR$(Next_unique)
  4304. 4293      ASSIGN @Test TO F_path$&Ftest$&F_msi$;RETURN Rc
  4305. 4294      IF Rc THEN     ! assume filename is unique
  4306. 4295        Unq_made=1
  4307. 4296        Next_unique=(Next_unique+1) MOD 10
  4308. 4297        F$=Ftest$
  4309. 4298      ELSE
  4310. 4299        DISP "Unique name not obtained "
  4311. 4300        PAUSE
  4312. 4301        Next_unique=Next_unique+1
  4313. 4302      END IF
  4314. 4303    UNTIL Unq_made
  4315. 4304  !
  4316. 4305    Filename$=F$
  4317. 4306    Wmsg$="Changed filename to "&Filename$
  4318. 4307    PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  4319. 4308    PRINT TABXY(25,5);" As  ";F_path$&Filename$&F_msi$
  4320. 4309    RETURN 
  4321. 4310 !----------------------------------------------
  4322. 4311 Get_at:  !   Decode File Attribute Packet
  4323. 4312     !
  4324. 4313     ! Rdata$ is in form:  ATTRIBUTE(char), LENGTH(unchar), DATA(char)
  4325. 4314     ! Returns:
  4326. 4315     !
  4327. 4316     ! ! or 1    File length (Bytes)     File_length
  4328. 4317     ! "
  4329. 4318     ! #         Creation Date           File_date$
  4330. 4319     ! .         Machine and OS          File_os$
  4331. 4320     ! /         Format Of Data          File_format$,File_type,File_delim$
  4332. 4321     !
  4333. 4322    I=1   ! data pointer
  4334. 4323    REPEAT
  4335. 4324      Attrib$=Rdata$[I,I]
  4336. 4325      Dl=FNUnchar(Rdata$[I+1,I+1])
  4337. 4326      SELECT Attrib$
  4338. 4327      CASE "!"  ! Length (Kb)
  4339. 4328        IF NOT At_filelength THEN 
  4340. 4329          File_length=VAL(Rdata$[I+2;Dl])
  4341. 4330          IF Attrib$="!" THEN File_length=(File_length+1)*1000
  4342. 4331          At_filelength=1
  4343. 4332        END IF
  4344. 4333      CASE "1" ! Exact File Length
  4345. 4334        File_length=VAL(Rdata$[I+2;Dl])
  4346. 4335        IF Attrib$="!" THEN File_length=(File_length+1)*1000
  4347. 4336        At_filelength=1
  4348. 4337      CASE """"       ! Data Type
  4349. 4338      CASE "#"        ! Creation Date [yy]yymmdd[  hh:mm[ :ss]
  4350. 4339        File_date$=Rdata$[I+2;Dl]
  4351. 4340      CASE "."        ! Machine and OS !  H4=hp9000 RMB
  4352. 4341        File_os$=Rdata$[I+2;Dl]        !  U8=DOS
  4353. 4342      CASE "/"        ! Format of data
  4354. 4343        File_format$=Rdata$[I+2;Dl]
  4355. 4344        SELECT File_format$[1,1]
  4356. 4345        CASE "A"     ! Var Length Delim Records - HP-UX FORMAT ON
  4357. 4346          File_delim$=File_format$[2;Dl-1]
  4358. 4347          File_type=4
  4359. 4348        CASE "D"     ! Var Len Undelim Records - ASCII File $
  4360. 4349          File_type=3
  4361. 4350        CASE "F"     ! Fix Len Undelim Records - BDAT FORMAT OFF
  4362. 4351          File_type=2
  4363. 4352        CASE "R"     ! Record Oriented Placement of record
  4364. 4353        CASE "M"     ! Maximum Rec Length for above record
  4365. 4354        END SELECT
  4366. 4355      END SELECT
  4367. 4356      I=I+Dl+2
  4368. 4357      IF Debug THEN PRINT "file_attribute ";Attrib$
  4369. 4358    UNTIL I>LEN(Rdata$)
  4370. 4359    RETURN 
  4371. 4360  !-----------------------------------------------------------------------
  4372. 4361 Kbr_int: !(k receive)
  4373. 4362    ! Cancels:  ^X (file)  ^Z (Batch) ^E (Protocol) ^C(Quit) <ent> Retry
  4374. 4363    !
  4375. 4364   ! To Interrupt File Receive:
  4376. 4365   !
  4377. 4366   !  ACK Packet with:   X in data field to abort single file
  4378. 4367   !                     Z in data field to abort entire batch
  4379. 4368   !  E   Packet with    Error Msg if Sender doesn't recognize file interruption.
  4380. 4369   !
  4381. 4370    User_break=1
  4382. 4371    K$=KBD$
  4383. 4372    SELECT K$[1,1]
  4384. 4373    CASE "",""    ! ?
  4385. 4374      PRINT TABXY(1,Crt_lines);
  4386. 4375      PRINT "Cancels:  ^X (file)  ^Z (Batch) ^E (Protocol) ^C(Quit) <Ent> Retry"
  4387. 4376    CASE "" ! ^X   ! Cancel File
  4388. 4377      Pktype$="X"
  4389. 4378      Rdata$="X"    ! discard file
  4390. 4379      Emsg$="Single File Cancelled by Client"
  4391. 4380      RETURN 
  4392. 4381    CASE CHR$(26)  !^Z   ! No Batch Process Yet (wildcard send/rec ?)
  4393. 4382      Pktype$="X"
  4394. 4383      Rdata$="Z"
  4395. 4384      Emsg$="Batch Receive  Cancelled by Client"
  4396. 4385      RETURN 
  4397. 4386    CASE ""  ! ^E   ! Goto Error (Abort)  State
  4398. 4387      State$="E"
  4399. 4388      Pktype$="E"
  4400. 4389      Emsg$="File Aborted by Client (E Packet)"
  4401. 4390      RETURN 
  4402. 4391    CASE "" ! ^C   ! Quit without Notifying Remote Kermit
  4403. 4392      State$="X"
  4404. 4393      Pktype$="X"
  4405. 4394      Rdata$=""
  4406. 4395      Emsg$="Transfer Aborted by Client - Host Not Notified"
  4407. 4396      RETURN 
  4408. 4397    CASE " "          ! CTRL-ENTER  resend - no abort
  4409. 4398      User_break=0
  4410. 4399      SELECT K$[2,2]
  4411. 4400      CASE "E"
  4412. 4401        OUTPUT @Out_buff;Sndpkt$
  4413. 4402        Retry_count=Retry_count+1
  4414. 4403        PRINT TABXY(25,11);Retry_count
  4415. 4404      END SELECT
  4416. 4405    CASE ELSE
  4417. 4406      User_break=0
  4418. 4407    END SELECT
  4419. 4408    ON KBD,2 GOSUB Kbr_int
  4420. 4409    RETURN 
  4421. 4410  !----------------------------------------------------------------------
  4422. 4411 Rec_err:  !             Error Handling for Kermit Receive
  4423. 4412    IF Debug THEN DISP ERRM$
  4424. 4413    SELECT ERRN
  4425. 4414    CASE 53   ! improper filename - probably a . in the name
  4426. 4415      Xd=POS(Filename$,".")
  4427. 4416      IF Xd THEN Filename$[Xd,Xd]="_"
  4428. 4417      IF LEN(Filename$)>10 THEN Filename$=Filename$[1,10]
  4429. 4418    CASE 76,52  ! INVALID DRIVE
  4430. 4419      IF ERRL(Check_ramdisc) THEN 
  4431. 4420        Init_ramdisc(Kbytes)
  4432. 4421        IF NOT Kbytes THEN 
  4433. 4422          DISP "Not enough memory for ramdisc"
  4434. 4423          WAIT 1
  4435. 4424          DISP 
  4436. 4425          ERROR RETURN
  4437. 4426        ELSE
  4438. 4427          Ramdisc=1
  4439. 4428        END IF
  4440. 4429      ELSE
  4441. 4430        DISP ERRM$&"  - Change MSI "
  4442. 4431        OUTPUT KBD;F_msi$;" H";
  4443. 4432        ENTER KBD;F_msi$
  4444. 4433        DISP 
  4445. 4434      END IF
  4446. 4435    CASE 64       ! Mass Storage Medium Overflow
  4447. 4436      Emsg$="Err 64: Mass Storage Medium Overflow"
  4448. 4437      State$="E"
  4449. 4438      ERROR RETURN
  4450. 4439    CASE 54       ! Duplicate File Name
  4451. 4440      IF Filewarn THEN                   ! create a unique filename
  4452. 4441        GOSUB Create_unique
  4453. 4442      ELSE       ! filewarn=0   - overwrite file
  4454. 4443        ASSIGN @File TO *
  4455. 4444        PURGE Filename$
  4456. 4445        Wmsg$="Overwriting file "&Filename$
  4457. 4446      END IF
  4458. 4447      CLEAR ERROR
  4459. 4448    CASE 167,168
  4460. 4449      CALL Com_interrupt         ! Serial Port Erro
  4461. 4450    CASE 59   ! END OF FILE FOUND  @FILE - Filename$
  4462. 4451      ASSIGN @File TO *
  4463. 4452      Spillfile=Spillfile+1
  4464. 4453      Filename$="SPILLFILE"&VAL$(Spillfile)
  4465. 4454      F$=F_path$&Filename$&F_msi$
  4466. 4455      ASSIGN @File TO F$;FORMAT ON,RETURN Rc
  4467. 4456      IF Rc THEN 
  4468. 4457        SELECT Filetype$
  4469. 4458        CASE "ASCII"
  4470. 4459          CREATE ASCII F$,200        ! 51 Kb
  4471. 4460          ASSIGN @File TO F$;FORMAT OFF
  4472. 4461        CASE "HPUX"
  4473. 4462          CREATE F$,50000
  4474. 4463          ASSIGN @File TO F$;FORMAT OFF
  4475. 4464        CASE ELSE
  4476. 4465          CREATE BDAT F$,200
  4477. 4466          ASSIGN @File TO F$;FORMAT OFF
  4478. 4467        END SELECT
  4479. 4468      END IF
  4480. 4469      Wmsg$="File Overflow - Spillfile Created"
  4481. 4470    CASE ELSE
  4482. 4471      DISP ERRM$&"  Paused in  Rec_err"
  4483. 4472      PAUSE
  4484. 4473    END SELECT
  4485. 4474   !
  4486. 4475    DISP 
  4487. 4476    ON ERROR GOSUB Rec_err
  4488. 4477    PRINT TABXY(25,12);Emsg$&RPT$(" ",55-LEN(Emsg$))
  4489. 4478    PRINT TABXY(25,13);Wmsg$&RPT$(" ",55-LEN(Wmsg$))
  4490. 4479    RETURN 
  4491. 4480  !----------------------------------------------
  4492. 4481 Rec_intr: !      ! COMM PORT INTERRUPT HANDLER
  4493. 4482    CALL Com_interrupt
  4494. 4483    Shutdown
  4495. 4484    ON INTR Com_port,15 GOSUB Rec_intr
  4496. 4485    SELECT Com_card
  4497. 4486    CASE 98628
  4498. 4487      CONTROL Com_port,13;164      ! MASK  4=UART  32=lost carr 128=break
  4499. 4488    CASE 98626,98644
  4500. 4489      ENABLE INTR Com_port;4
  4501. 4490    END SELECT
  4502. 4491    ON ERROR GOSUB Rec_err
  4503. 4492    Startup
  4504. 4493    RETURN 
  4505. 4494  !-----------------------------------------------
  4506. 4495 No_printer:RETURN 
  4507. 4496 Flush_buff: !
  4508. 4497    RETURN 
  4509. 4498  !---------------------------------------------
  4510. 4499 Rspar:  !  Form Initialization Packet
  4511. 4500    Packet$=""
  4512. 4501    Packet$[1]=FNTochar$(Maxp)
  4513. 4502    Packet$[2]=FNTochar$(Mytmo)
  4514. 4503    Packet$[3]=FNTochar$(Mypad)
  4515. 4504    Packet$[4]=FNTochar$(Mypchar)
  4516. 4505    Packet$[5]=FNTochar$(Myeol)
  4517. 4506    Packet$[6]=CHR$(Myquote)
  4518. 4507    Packet$[7]="&"                    ! 8TH BIT PREFIX
  4519. 4508    Packet$[8]="1"                    ! CHECK TYPE
  4520. 4509    Packet$[9]=" "                    ! NO REPEAT COUNT PROCESS
  4521. 4510    IF Rptflag THEN 
  4522. 4511      Packet$[9,9]=CHR$(Rep_char)
  4523. 4512    END IF
  4524. 4513   !
  4525. 4514    IF Rcap_a THEN 
  4526. 4515      Capas=IVAL("001000",2)          ! File attributes = (8)
  4527. 4516      Packet$[10]=FNTochar$(Capas)    ! CAPAS MASK
  4528. 4517    END IF
  4529. 4518    !
  4530. 4519    ! Extended Length Packets  (m=desired length - <= 9024)
  4531. 4520    ! If bit 1 of capas is set:  000010
  4532. 4521    !
  4533. 4522    IF Rcap_lp THEN 
  4534. 4523      Packet$[11,11]=FNTochar$(0)       ! Windo - not used
  4535. 4524      Packet$[12,12]=FNTochar$(R_maxl1)
  4536. 4525      Packet$[13,13]=FNTochar$(R_maxl2)
  4537. 4526    END IF
  4538. 4527  !
  4539. 4528    RETURN 
  4540. 4529  !================================
  4541. 4530 Rrpar:  ! Receive Packet Initialization
  4542. 4531        ! Rdata$[] DATA STRIPPED FROM INCOMING PACKET
  4543. 4532    IF Debug THEN DISP "INIT REc len = ";LEN(Rdata$)
  4544. 4533    FOR S=1 TO LEN(Rdata$)
  4545. 4534      SELECT S
  4546. 4535      CASE 1
  4547. 4536        Rpsiz=FNUnchar(Rdata$[1])       ! remote  packet size
  4548. 4537      CASE 2
  4549. 4538        Ptmo=FNUnchar(Rdata$[2])        ! remote packet timeout
  4550. 4539      CASE 3
  4551. 4540        Pad=FNUnchar(Rdata$[3])         ! remote    padding
  4552. 4541      CASE 4
  4553. 4542        Padchar=FNUnchar(Rdata$[4])     ! padding char to use
  4554. 4543      CASE 5
  4555. 4544        Eol=FNUnchar(Rdata$[5])
  4556. 4545        IF Eol=0 THEN Eol=Myeol         ! eol to use
  4557. 4546      CASE 6
  4558. 4547        Quote=NUM(Rdata$[6,6])          ! remote quote char
  4559. 4548      CASE 7
  4560. 4549        Qbin=NUM(Rdata$[7,7])
  4561. 4550        IF Qbin=89 THEN Qbin=38 ! 89=Y , 38=&  ! Y= Yes I do it
  4562. 4551      CASE 8
  4563. 4552        R_bchk=NUM(Rdata$[8,8])         ! remote block check type
  4564. 4553        R_bchk=R_bchk-48                ! 1=49 2=50 3=51
  4565. 4554        IF R_bchk<1 OR R_bchk>3 THEN 
  4566. 4555          R_bchk=1
  4567. 4556        END IF
  4568. 4557      CASE 9
  4569. 4558        Rep_char=NUM(Rdata$[9,9])
  4570. 4559      CASE 10
  4571. 4560        R_capas=FNUnchar(Rdata$[10,10])
  4572. 4561        IF BIT(R_capas,1) THEN ! extended length packets
  4573. 4562          Rcap_lp=1
  4574. 4563          R_windo=FNUnchar(Rdata$[11,11])
  4575. 4564          R_maxl1=FNUnchar(Rdata$[12,12])
  4576. 4565          R_maxl2=FNUnchar(Rdata$[13,13])
  4577. 4566          R_maxl=R_maxl1*95+R_maxl2
  4578. 4567        END IF
  4579. 4568   !
  4580. 4569        IF BIT(R_capas,3) THEN Rcap_a=1
  4581. 4570      END SELECT
  4582. 4571    NEXT S
  4583. 4572    RETURN 
  4584. 4573  SUBEND
  4585. 4574  !======================================================================
  4586. 4575  SUB Rpack(Pktype$,Rdata$,INTEGER Rseq,Rcvpkt$,Sndpkt$,INTEGER Npak,Retry_count,User_break,Emsg$)
  4587. 4576 Rpack: !
  4588. 4577  ! Pktype$    Packet Type  S,A,F,D,Z,B   N,Y
  4589. 4578  ! Rdata$     Packet Data Area. or User Abort Message
  4590. 4579  ! Rseq       Incomming Packet Sequence Number
  4591. 4580  ! Rcvpkt$    Raw Packet Received
  4592. 4581  ! Sndpkt$    Previous Packet Sent - required for resend on kbd interrupt
  4593. 4582  ! Npak       Expected packet sequence number
  4594. 4583  ! Retry_count
  4595. 4584  ! user_break=1 if user client interrupts file transfer
  4596. 4585  ! Emsg$      Error Msg created by receive packet, or client interrupt
  4597. 4586  !
  4598. 4587    OPTION BASE 1
  4599. 4588    COM /Crt/ Crt_lines,Crt_width
  4600. 4589    COM /Port/ @Out_buff,@Com_out,Output_buffer$ BUFFER
  4601. 4590    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$ BUFFER,Com_card
  4602. 4591    COM /Kerm2/ State$,Cchksum$,Eof_mode$,INTEGER Eof_mode,Timer,Ptmo
  4603. 4592  !
  4604. 4593    DIM A$[1],K$[256],Rcvchksum$[20],Misc$[80]
  4605. 4594    INTEGER Chksum,Rc,Plen,Dlen,Cchksum
  4606. 4595    INTEGER Endl,Chkpos,Chk
  4607. 4596  !------------------------------------------------------------------------
  4608. 4597    ON ERROR GOSUB Rp_err
  4609. 4598    K$=""
  4610. 4599    ENABLE 
  4611. 4600    ON KBD,2 GOSUB Kbd_int
  4612. 4601 Get_packet: !
  4613. 4602    IF Timer THEN ON DELAY Ptmo,10 GOTO R_tmo
  4614. 4603    Rdata$=""
  4615. 4604    Rcvpkt$=""
  4616. 4605   !
  4617. 4606    REPEAT                       ! Until a Packet Header (mark) is found
  4618. 4607      IF Com_card=98628 THEN 
  4619. 4608        STATUS Com_port,5;B_len
  4620. 4609      ELSE
  4621. 4610        STATUS @In_buff,4;B_len
  4622. 4611      END IF
  4623. 4612      IF B_len THEN ENTER @In_buff USING "#,K";A$
  4624. 4613      IF LEN(A$) THEN A$=CHR$(BINAND(NUM(A$),127))    ! strip parity
  4625. 4614    UNTIL A$=""
  4626. 4615    Rcvpkt$[1,1]=A$            ! store packet mark
  4627. 4616  !
  4628. 4617  ! MARK FOUND - ENTER THE REST OF THE PACKET
  4629. 4618  !
  4630. 4619  ! ## If Comm Interrupt Occurs and buffer is flushed, an end of buffer occurs here
  4631. 4620  !
  4632. 4621  !
  4633. 4622    I=2
  4634. 4623    LOOP
  4635. 4624      ENTER @In_buff USING "#,K";A$
  4636. 4625      Rcvpkt$[I,I]=A$
  4637. 4626      IF I=2 THEN 
  4638. 4627        Plen=FNUnchar(Rcvpkt$[2,2])! Packet Length
  4639. 4628      END IF
  4640. 4629      I=I+1
  4641. 4630    EXIT IF I>Plen+3             ! mark+len+plen+eol = plen+3
  4642. 4631    END LOOP
  4643. 4632    OFF DELAY
  4644. 4633   !
  4645. 4634   ! Kermit Packet Received ----------------------
  4646. 4635   !
  4647. 4636    Beginl=POS(Rcvpkt$,"")
  4648. 4637    Rcvpkt$=Rcvpkt$[Beginl]
  4649. 4638    Endl=POS(Rcvpkt$,"")
  4650. 4639    IF (Endl=0) THEN Endl=POS(Rcvpkt$,"
  4651. ")     ! if no CR then use LF
  4652. 4640    IF NOT Endl THEN 
  4653. 4641      Endl=LEN(Rcvpkt$)
  4654. 4642    END IF
  4655. 4643    Rcvpkt$=Rcvpkt$[Beginl,Endl]
  4656. 4644    Plen=FNUnchar(Rcvpkt$[2,2]) ! Packet Length
  4657. 4645    Dlen=Plen-3                 ! Data Length
  4658. 4646    Chkpos=Plen+2               ! Position of checksum char
  4659. 4647    Rseq=FNUnchar(Rcvpkt$[3,3]) ! Rec Sequence Number
  4660. 4648    Pktype$=Rcvpkt$[4,4]        ! Packet Type
  4661. 4649   !
  4662. 4650   ! Check Sequence
  4663. 4651   ! If Local Kermit was paused, there could be multiple packets
  4664. 4652   ! buffered with a sequence number < the current Npak.
  4665. 4653   !
  4666. 4654   ! Check buffer - if there is a packet, go get it, else ack this packet
  4667. 4655   ! and force the next packet to be sent.
  4668. 4656   !
  4669. 4657    IF (Rseq<Npak MOD 64) THEN   ! loop back and receive next packet
  4670. 4658   !
  4671. 4659   !  PRINT TABXY(1,Crt_lines);"Rseq<Npak:  Loop to get another packet "
  4672. 4660      IF Com_card=98628 THEN 
  4673. 4661        STATUS Com_port,5;B_len
  4674. 4662      ELSE
  4675. 4663        STATUS @In_buff,4;B_len
  4676. 4664      END IF
  4677. 4665   !
  4678. 4666      IF B_len THEN 
  4679. 4667        GOTO Get_packet
  4680. 4668      ELSE
  4681. 4669   !    PRINT TABXY(1,Crt_lines);"Acking packet=Rseq (rseq<npak) to force next packet: rseq=npak"
  4682. 4670        Spack("","Y",Rseq,Sndpkt$)    ! ack current (Rseq) packet
  4683. 4671        OUTPUT @Out_buff;Sndpkt$
  4684. 4672        GOTO Get_packet               ! Go get expected (Npak) packet
  4685. 4673      END IF
  4686. 4674    END IF
  4687. 4675  !
  4688. 4676    PRINT TABXY(1,Crt_lines);RPT$(" ",80)
  4689. 4677    IF Rseq>Npak THEN   ! exit rpack with a "Q" pktype$
  4690. 4678      Pktype$="Q"
  4691. 4679      PRINT TABXY(1,Crt_lines);"Packet out of sequence - ahead of expected packet ";Rseq,Npak,"subexit"
  4692. 4680      SUBEXIT
  4693. 4681    END IF
  4694. 4682   !-------------------------------------------------------------------
  4695. 4683   ! A good packet in the required sequence has been received
  4696. 4684   ! Flush the input buffer
  4697. 4685   !
  4698. 4686    IF Com_card=98628 THEN 
  4699. 4687      STATUS Com_port,5;B_len
  4700. 4688      WHILE B_len
  4701. 4689        ENTER @In_buff;Misc$
  4702. 4690        STATUS Com_port,5;B_len
  4703. 4691      END WHILE
  4704. 4692    ELSE
  4705. 4693      STATUS @In_buff,3;Fp
  4706. 4694   !  CONTROL @In_buff,5;Fp   ! Set empty pointer to fill pointer
  4707. 4695    END IF
  4708. 4696   !
  4709. 4697   ! Extract Data from Packet into Rdata$
  4710. 4698   !
  4711. 4699    IF Dlen THEN                   ! If Packet Has Data
  4712. 4700      ON ERROR GOTO Nodl
  4713. 4701      Rdata$[1,Dlen]=Rcvpkt$[5,Plen+1]
  4714. 4702      GOTO Dldone
  4715. 4703 Nodl:OFF ERROR 
  4716. 4704      FOR I=1 TO Dlen
  4717. 4705        Rdata$[I,I]=Rcvpkt$[4+I]
  4718. 4706      NEXT I
  4719. 4707    END IF
  4720. 4708 Dldone:OFF ERROR 
  4721. 4709    !
  4722. 4710    ! Check for Good Packet Checksum
  4723. 4711    !
  4724. 4712    Chk=0
  4725. 4713    FOR I=2 TO Plen+1
  4726. 4714      Chk=Chk+NUM(Rcvpkt$[I,I])
  4727. 4715    NEXT I
  4728. 4716    Cchksum=BINAND(Chk+(BINAND(Chk,192)/64),63)   ! Computed Checksum
  4729. 4717    Cchksum$=FNTochar$(Cchksum)
  4730. 4718    Rcvchksum$=Rcvpkt$[Chkpos;1]
  4731. 4719    IF Rcvchksum$<>Cchksum$ THEN Pktype$="Q"
  4732. 4720    SUBEXIT
  4733. 4721  !---------------------------------
  4734. 4722 R_tmo: !
  4735. 4723    BEEP 2000,.01
  4736. 4724    OFF DELAY
  4737. 4725    OFF TIMEOUT 
  4738. 4726    Pktype$="T"
  4739. 4727    DISP 
  4740. 4728    SUBEXIT
  4741. 4729  !---------------------------------
  4742. 4730 Kbd_int: !(rpack)
  4743. 4731    ! Cancels:  ^X (file)  ^Z (Batch) ^E (Err Quit) ^C(Quit) <ent> Retry
  4744. 4732   !
  4745. 4733   ! To Interrupt File Receive:
  4746. 4734   !
  4747. 4735   !  ACK Packet with:   X in data field to abort single file
  4748. 4736   !                     Z in data field to abort entire batch
  4749. 4737   !  E   Packet with    Error Msg if Sender doesn't recognize file interruption.
  4750. 4738   !
  4751. 4739    BEEP 300,.02
  4752. 4740    User_break=1
  4753. 4741    K$=KBD$
  4754. 4742    SELECT K$[1,1]
  4755. 4743    CASE "",""    ! ^?
  4756. 4744      PRINT TABXY(1,Crt_lines);
  4757. 4745      PRINT "Cancels:  ^X (file)  ^Z (Batch) ^E (Protocol) ^C(Quit) <Ent> Retry"
  4758. 4746    CASE "" ! ^X   ! Cancel File
  4759. 4747      Pktype$="X"
  4760. 4748      Rdata$="X"    ! discard file
  4761. 4749      Emsg$="Single File Cancelled by Client"
  4762. 4750      SUBEXIT
  4763. 4751    CASE CHR$(26)  ! ^Z   ! No Batch Process Yet (wildcard send/rec ?)
  4764. 4752      Pktype$="X"
  4765. 4753      Rdata$="Z"
  4766. 4754      Emsg$="Batch Receive  Cancelled by Client"
  4767. 4755      SUBEXIT
  4768. 4756    CASE ""  ! ^E   ! Goto Error (Abort)  State
  4769. 4757      State$="E"
  4770. 4758      Pktype$="E"
  4771. 4759      Emsg$="File Aborted by Client (E Packet)"
  4772. 4760      SUBEXIT
  4773. 4761    CASE "" ! ^C   ! Quit without Notifying Remote Kermit
  4774. 4762      State$="X"
  4775. 4763      Pktype$="X"
  4776. 4764      Rdata$="^C"   ! Notify sendz not to notify host
  4777. 4765      Emsg$="Transfer Aborted by Client - Host Not Notified"
  4778. 4766      SUBEXIT
  4779. 4767    CASE " "          ! CTRL-ENTER  resend - no abort
  4780. 4768      User_break=0
  4781. 4769      SELECT K$[2,2]
  4782. 4770      CASE "E"
  4783. 4771        OUTPUT @Out_buff;Sndpkt$
  4784. 4772      ! Retry_count=Retry_count+1   ! gets incr if SUBEXIT is used
  4785. 4773        PRINT TABXY(25,11);Retry_count
  4786. 4774        SUBEXIT
  4787. 4775      CASE ELSE
  4788. 4776     !  OUTPUT KBD;K$&" E"
  4789. 4777      END SELECT
  4790. 4778    CASE ELSE
  4791. 4779      User_break=0
  4792. 4780    END SELECT
  4793. 4781    RETURN 
  4794. 4782  !--------------------------------------
  4795. 4783 Rp_err: !
  4796. 4784    SELECT ERRN
  4797. 4785    CASE 59    ! end of buffer found
  4798. 4786  ! DISP "end of buffer error in Rpak - calling CI "
  4799. 4787      Pktype$="T"
  4800. 4788      SUBEXIT
  4801. 4789  !   CALL Com_interrupt
  4802. 4790    CASE ELSE
  4803. 4791      DISP ERRM$
  4804. 4792      PAUSE
  4805. 4793    END SELECT
  4806. 4794    RETURN 
  4807. 4795  !------------------------------------------
  4808. 4796  SUBEND
  4809. 4797  !=======================================================================
  4810. 4798 Init_ramdisc:SUB Init_ramdisc(Kbytes,OPTIONAL Clear$,Sectors)
  4811. 4799  !
  4812. 4800  ! This routine cannot check for existance of a RAM Disc before
  4813. 4801  ! initializing because of nested ON ERROR conflicts. If this routine
  4814. 4802  ! is called from an ON ERROR routine,then an error in this routine
  4815. 4803  ! cannot be trapped.
  4816. 4804  !
  4817. 4805! Initialize Ram Disc
  4818. 4806!
  4819. 4807    DIM Sav_msi$[256]
  4820. 4808    Cat_msi$=":,0,0"
  4821. 4809    INTEGER Sector(1:128)
  4822. 4810    Sav_msi$=SYSTEM$("MSI")
  4823. 4811    INITIALIZE ":,0,0",0                 ! destroy any existing ram disc
  4824. 4812    DISP "Creating RAM Volume - please wait"
  4825. 4813    Avm=VAL(SYSTEM$("AVAILABLE MEMORY"))
  4826. 4814    Bytes=Avm-100000                      ! SAVE 100 KB
  4827. 4815    Kbytes=Bytes/1000
  4828. 4816    Kbytes=MAX(Kbytes,0)
  4829. 4817    Kbytes=MIN(Kbytes,3000)               ! 3 Mb Max
  4830. 4818    IF Kbytes>0 THEN 
  4831. 4819      Size=INT(Kbytes*4)                       ! 4 sectors PER kB
  4832. 4820      INITIALIZE ":,0,0",Size
  4833. 4821 !------------------------------------------
  4834. 4822      IF NPAR>1 THEN 
  4835. 4823        IF Clear$="CLEAR" THEN 
  4836. 4824          MASS STORAGE IS ":,0,0"
  4837. 4825          Get_volinfo(Dir_st,Dir_len,Vol_lbl$)
  4838. 4826          Cl_sect=Size
  4839. 4827          IF NPAR>2 THEN Cl_sect=MIN(Sectors,500)
  4840. 4828          DISP "Clearing";Cl_sect;" Disc Sectors"
  4841. 4829          FOR Sect=Dir_st+Dir_len-1 TO Cl_sect
  4842. 4830            Phywrite(Sect,Sector(*))
  4843. 4831          NEXT Sect
  4844. 4832        END IF
  4845. 4833      END IF
  4846. 4834    END IF
  4847. 4835    MASS STORAGE IS Sav_msi$
  4848. 4836    DISP 
  4849. 4837  SUBEND
  4850. 4838  !-----------------------------------------------------------------------
  4851. 4839 Shutdown:SUB Shutdown(OPTIONAL INTEGER Transfer_on)       ! Shutdown Serial Transfers
  4852. 4840  !
  4853. 4841    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  4854. 4842    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  4855. 4843  !
  4856. 4844    IF Com_card=98628 THEN SUBEXIT
  4857. 4845  !
  4858. 4846    STATUS Com_port,10;Uart    !       clear frame errors
  4859. 4847  !
  4860. 4848  ! Check if transfer is running
  4861. 4849  !
  4862. 4850    STATUS @Out_buff,0;O_stat     ! IS PATH VALID ?
  4863. 4851    IF O_stat<3 THEN 
  4864. 4852      IF NPAR THEN Transfer_on=0
  4865. 4853      SUBEXIT
  4866. 4854    END IF
  4867. 4855  !
  4868. 4856    STATUS @Out_buff,11;O_stat
  4869. 4857    IF BIT(O_stat,6) THEN 
  4870. 4858      IF NPAR THEN Transfer_on=1
  4871. 4859      CONTROL @Out_buff,9;0     ! non-continuous
  4872. 4860      WAIT FOR EOT @Com_out     ! normal transfer shutoff
  4873. 4861    END IF
  4874. 4862  !
  4875. 4863    STATUS @In_buff,10;I_stat
  4876. 4864    IF BIT(I_stat,6) THEN 
  4877. 4865      CONTROL @In_buff,8;0      ! non-continuous
  4878. 4866      ABORTIO @Com_in           ! shutoff
  4879. 4867    END IF
  4880. 4868    STATUS Com_port,10;Uart    ! clear any frame errors
  4881. 4869  SUBEND
  4882. 4870  !-----------------------------------------------------------------------
  4883. 4871  SUB Startup
  4884. 4872 Startup: !
  4885. 4873  !
  4886. 4874  !
  4887. 4875    COM /Port/ @Out_buff,@Com_out,Output_buffer$[2048] BUFFER
  4888. 4876    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$[2048] BUFFER,Com_card
  4889. 4877  !
  4890. 4878    ON ERROR GOSUB Startup_err
  4891. 4879    ON TIMEOUT Com_port,.5 GOSUB Startup_err
  4892. 4880  !
  4893. 4881  ! CHECK IF TRANSFERS RUNNING
  4894. 4882  !
  4895. 4883 Retry_xfer: !
  4896. 4884    STATUS @In_buff,0;Valid_path
  4897. 4885    IF Valid_path=3 THEN  ! buffer
  4898. 4886      STATUS @In_buff,10;I_stat
  4899. 4887      IF BIT(I_stat,6) THEN 
  4900. 4888        CALL Shutdown
  4901. 4889      END IF
  4902. 4890    END IF
  4903. 4891  !
  4904. 4892  !
  4905. 4893    IF Com_card=98628 THEN 
  4906. 4894      ASSIGN @Out_buff TO Com_port      ! no xfer buffers required
  4907. 4895      ASSIGN @In_buff TO Com_port
  4908. 4896      SUBEXIT
  4909. 4897    ELSE
  4910. 4898      STATUS Com_port,10;Dummy          ! CLEAR ERRORS
  4911. 4899      ASSIGN @Com_in TO Com_port
  4912. 4900      ASSIGN @Com_out TO Com_port
  4913. 4901      ASSIGN @In_buff TO BUFFER Input_buffer$
  4914. 4902      ASSIGN @Out_buff TO BUFFER Output_buffer$
  4915. 4903    END IF
  4916. 4904    !
  4917. 4905    ! START OUTBOUND TRANSFER FIRST
  4918. 4906    !
  4919. 4907    STATUS Com_port,10;Uart    ! clear errors - prevent error 167
  4920. 4908    TRANSFER @Out_buff TO @Com_out;CONT
  4921. 4909    REPEAT
  4922. 4910      STATUS @Out_buff,11;Out_status
  4923. 4911    UNTIL BIT(Out_status,6)=1
  4924. 4912    !
  4925. 4913    OUTPUT @Out_buff;"";    ! kickstart transfer
  4926. 4914    !
  4927. 4915    ! Inbound may receive buffer overrun error 167 - io status error
  4928. 4916    ! due to an abortive interrupt (ie buff overrun) in the interface.
  4929. 4917    ! An abortive interrupt will shut off a transfer.
  4930. 4918    !
  4931. 4919    TRANSFER @Com_in TO @In_buff;CONT
  4932. 4920    REPEAT
  4933. 4921      STATUS @In_buff,10;Inb_status
  4934. 4922    UNTIL BIT(Inb_status,6)=1
  4935. 4923  !
  4936. 4924  ! CHECK FOR ANY TRANSFER ERROR
  4937. 4925  !
  4938. 4926    STATUS @In_buff,10;I_stat
  4939. 4927    STATUS @Out_buff,11;O_stat
  4940. 4928  !
  4941. 4929    IF (BIT(I_stat,4)) OR (BIT(O_sta,4)) THEN 
  4942. 4930      GOTO Retry_xfer
  4943. 4931    END IF
  4944. 4932    SUBEXIT
  4945. 4933  !=-------------------------------
  4946. 4934 Startup_err: !
  4947. 4935    SELECT ERRN
  4948. 4936    CASE 167,168,0            ! IO Status Error
  4949. 4937      CALL Com_interrupt
  4950. 4938      STATUS Com_port,10;Uart  ! clear errors - prevent error 167
  4951. 4939   !  DISP "UART: ";Uart,"startup"
  4952. 4940      ON ERROR GOSUB Startup_err
  4953. 4941      ON TIMEOUT Com_port,.5 GOSUB Startup_err
  4954. 4942    CASE ELSE
  4955. 4943      BEEP 
  4956. 4944      DISP ERRM$
  4957. 4945      PAUSE
  4958. 4946    END SELECT
  4959. 4947    RETURN 
  4960. 4948  SUBEND
  4961. 4949  !-----------------------------------------------------------------------
  4962. 4950  SUB Reset_port
  4963. 4951 Reset_port: !
  4964. 4952  !
  4965. 4953    COM /Port/ @Out_buff,@Com_out,Output_buffer$ BUFFER
  4966. 4954    COM /Port/ Com_port,@In_buff,@Com_in,Input_buffer$ BUFFER,Com_card
  4967. 4955    COM /Frame/ Baud,Data_bits,Stop_bits,On_off$,Parity_type$
  4968. 4956    COM /Frame/ Flow$,Hshake$
  4969. 4957  !
  4970. 4958    SELECT Com_card
  4971. 4959    CASE 98626
  4972. 4960      STATUS Com_port,10;Uart         ! clear any frame errors
  4973. 4961      CONTROL Com_port,0;1       ! RESET PORT - DISCONNECT MODEM
  4974. 4962      CONTROL Com_port,5;1+2          ! force dtr,rts active
  4975. 4963      CONTROL Com_port,12;128+32+16   ! Disable modem handshake
  4976. 4964    CASE 98628
  4977. 4965      CONTROL Com_port,0;1  ! Reset and read config switches
  4978. 4966      CONTROL Com_port,3;1  ! async protocol after next reset
  4979. 4967 ! control Com_port,5;0     ! terminate trans and turnaround if half-duplex
  4980. 4968 ! control Com_port,6;1     ! BREAK
  4981. 4969      CONTROL Com_port,8;1+2! RTS  DTR  Set Active
  4982. 4970 ! CONTROL Com_port,12;2    ! 2 = start autodial  1=connect (dtr,rts)
  4983. 4971      CONTROL Com_port,13;164     ! INT MASK  4=UART  32=lost car 128=break
  4984. 4972      CONTROL Com_port,14;0 ! Control Blocks Disabled  (queued with data)
  4985. 4973      CONTROL Com_port,15;0 ! MODEM INT MASK
  4986. 4974 ! CONTROL Com_port,16;25   ! Connect Timeout (reset=25 sec)
  4987. 4975 ! CONTROL Com_port,17;10   ! No activity Timeout (reset=10 min )
  4988. 4976 ! CONTROL Com_port,18;40   ! Lost Carrier Timeout 10xMS (reset=40)
  4989. 4977 ! CONTROL Com_port,19;10   ! CTS (send)   Timeout (reset=10 sec)
  4990. 4978 !    CONTROL Com_port,20;9 ! BAUD RATE  9=1200 11=2400 14=9600
  4991. 4979 !    CONTROL Com_port,21;9 ! REC  RATE  9=1200 11=2400 14=9600
  4992. 4980 !
  4993. 4981      SELECT Flow$
  4994. 4982      CASE "NONE"              ! Protocol (SW) Handshake
  4995. 4983        CONTROL Com_port,22;0  ! 0:none 1:enq-host 2:enq-term
  4996. 4984      CASE "XON/XOFF"          ! 3-5: xon/off host/term/both
  4997. 4985        CONTROL Com_port,22;5
  4998. 4986      CASE "ENQ/ACK"
  4999. 4987        CONTROL Com_port,22;2
  5000. 4988      CASE ELSE
  5001. 4989        CONTROL Com_port,22;0
  5002. 4990      END SELECT
  5003. 4991  !
  5004. 4992      IF Hshake$="ON" THEN 
  5005. 4993        CONTROL Com_port,23;3! HDWR HNDSHK:  0=off/non-modem 1:full
  5006. 4994      ELSE                  !               2=hlf dup mod 3=CTS/DCD
  5007. 4995        CONTROL Com_port,23;0
  5008. 4996      END IF
  5009. 4997      CONTROL Com_port,24;127! Control Char Mask: pass null,eol,proto,del,rub
  5010. 4998                            ! change uart err to underscore (127-pass all)
  5011. 4999      CONTROL Com_port,26;17! First Protocol Hndshk  6=ack  (17=dc1/XON)
  5012. 5000      CONTROL Com_port,27;19! First Protocol Hndshk  5=enq  (19=dc3/XOFF)
  5013. 5001      CONTROL Com_port,28;1 ! length of inbound EOL  (reset=2)
  5014. 5002      CONTROL Com_port,29;13! first EOL (13=Cr)
  5015. 5003      CONTROL Com_port,30;10! second EOL (10=Lf)
  5016. 5004 ! CONTROL Com_port,31;1    ! prompt$ length (1)
  5017. 5005 ! CONTROL Com_port,32;17   ! first prompt$ char (17=dc1)
  5018. 5006 ! CONTROL Com_port,33;0    ! second prompt$ char (0=null)
  5019. 5007  !
  5020. 5008  !   CONTROL Com_port,34;3 ! frame length (databits=card dip switch)
  5021. 5009                            ! 2=7  3=8 (parity must be none,even,odd)
  5022. 5010  !   CONTROL Com_port,35;0 ! Stop Bits: (0=1) 1=1.5  2=2
  5023. 5011  !   CONTROL Com_port,36;0 ! Parity 0=none  1=odd 2=even 3="0" 4="1"
  5024. 5012      CONTROL Com_port,37;0 ! Inter-char time gap (0=none)  <255 char times
  5025. 5013      CONTROL Com_port,39;4 ! Set BREAK char time (4)  2-255
  5026. 5014      CALL Set_frame(Baud)
  5027. 5015    END SELECT
  5028. 5016  !-------------------------
  5029. 5017  SUBEND
  5030. 5018  !========================================================================
  5031. 5019  SUB Parse_filename(F$,F_msi$,F_path$)
  5032. 5020 Parse_filename: !
  5033. 5021  ! F$ is consumed and filename is returned in its place
  5034. 5022  !
  5035. 5023    DIM Misc$[256]
  5036. 5024    INTEGER Sl_pos
  5037. 5025  !
  5038. 5026    IF LEN(F_msi$) THEN 
  5039. 5027      IF NOT POS(F$,":") THEN F$=F$&F_msi$
  5040. 5028    END IF
  5041. 5029  !
  5042. 5030    Filename$=""
  5043. 5031    F_msi$=""
  5044. 5032    F_path$=""
  5045. 5033  !
  5046. 5034  ! If MSI exists strip it off of F$
  5047. 5035  !
  5048. 5036    IF POS(F$,":") THEN              ! MSI SPECIFIED
  5049. 5037      F_msi$=F$[POS(F$,":")]
  5050. 5038      F$=F$[1,POS(F$,":")-1]         ! Strip MSI
  5051. 5039    END IF
  5052. 5040  !
  5053. 5041  !  Strip PATH from F$,     keep last slash on pathname
  5054. 5042  !
  5055. 5043    IF POS(F$,"/") THEN 
  5056. 5044      Misc$=REV$(F$)
  5057. 5045      Sl_pos=POS(Misc$,"/")          ! SLASH POSITION
  5058. 5046      F$=REV$(Misc$[1,Sl_pos-1])
  5059. 5047      F_path$=REV$(Misc$[Sl_pos])
  5060. 5048    END IF
  5061. 5049  SUBEND
  5062. 5050 !=========================================================================
  5063. 5051  SUB Get_volinfo(Dir_st,Dir_len,Vol_lbl$)
  5064. 5052 Gvi: !
  5065. 5053 ! Returns the starting sector of the volume directory, its length
  5066. 5054 !
  5067. 5055    INTEGER I,Msb,Lsb,X
  5068. 5056    Dir_st=0
  5069. 5057    Dir_len=0
  5070. 5058    Vol_lbl$=""
  5071. 5059    COM /Sctr/ INTEGER Sctr(0:127)
  5072. 5060    Phyread(0,Sctr(*))                   ! read LIF Volume Header
  5073. 5061    Dir_st=(Sctr(4)*2^16)+Sctr(5)
  5074. 5062    Dir_len=(Sctr(8)*2^16)+Sctr(9)
  5075. 5063  ! DISP "DIR START: ";Dir_st,"DIR LENGTH :  ";Dir_len
  5076. 5064    FOR I=1 TO 3
  5077. 5065      Temp=Sctr(I)
  5078. 5066      IF Sctr(I)<0 THEN Temp=Sctr(I)+65536
  5079. 5067      Msb=Temp DIV 256
  5080. 5068      Lsb=Temp MOD 256
  5081. 5069      Vol_lbl$=Vol_lbl$&CHR$(Msb)&CHR$(Lsb)
  5082. 5070    NEXT I
  5083. 5071 Done:!
  5084. 5072  SUBEND
  5085. 5073 !-------------------------------------------------------------------------
  5086. 5074  SUB Get_fileinfo(Filename$,REAL Fs,Fl,Dir_entry_sec,Dir_entry,OPTIONAL INTEGER T,V,P,R)
  5087. 5075 Gfi: !
  5088. 5076  ! Pass-in Parameters:
  5089. 5077  ! Filename$            File Name Only - no msi
  5090. 5078  !
  5091. 5079  ! Return Parameters
  5092. 5080  !
  5093. 5081  ! Fs              Start Sector of File
  5094. 5082  ! Fl              Number of sectors in file
  5095. 5083  ! Dir_entry_sec   Directory Sector Containing File Entry
  5096. 5084  ! Dir_entry       Dir Entry Number in that Sector (0-7 per sector)
  5097. 5085  ! T               File Type Number
  5098. 5086  ! V               Volume number
  5099. 5087  ! P,R             Protection Numbers
  5100. 5088  !----------------------------------------------
  5101. 5089    INTEGER I,Fword,Msb,Lsb,X
  5102. 5090    COM /Sctr/ INTEGER Sctr(0:127)
  5103. 5091    DIM Entryname$[10],Vol_lbl$[6]
  5104. 5092    Get_volinfo(Ds,Dl,Lbl$)          ! Get  Dir Start, Dir Length, Vol Label
  5105. 5093    !
  5106. 5094    IF POS(Filename$,":") THEN CALL Parse_filename(Filename$,F_msi$,F_path$)
  5107. 5095    FOR Sector=Ds TO Ds+Dl-1         ! Search Directory for File Match
  5108. 5096      Phyread(Sector,Sctr(*))
  5109. 5097      FOR Entry=0 TO 7               ! 8 File entries per sector
  5110. 5098        Entryname$=""
  5111. 5099        Fword=Entry*16
  5112. 5100        IF Sctr(Fword+5)=-1 THEN 
  5113. 5101          Next_open_entry=Entry     ! Gives Next open Dir entry
  5114. 5102          Next_open_sec=Sector
  5115. 5103          GOTO Done_find
  5116. 5104        END IF
  5117. 5105        IF Sctr(Fword+5)=0 THEN Nexte         !  0 = null entry
  5118. 5106        FOR I=0 TO 4                 ! 5 words = 10 Char Name
  5119. 5107          Word_2char(Sctr(Fword+I),Msb,Lsb)
  5120. 5108          Entryname$=Entryname$&CHR$(Msb)&CHR$(Lsb)
  5121. 5109        NEXT I
  5122. 5110        IF TRIM$(Entryname$)=TRIM$(Filename$) THEN 
  5123. 5111          Dir_entry_sec=Sector                       ! dir entry position
  5124. 5112          Dir_entry=Entry
  5125. 5113      !   PRINT Dir_entry_sec,Dir_entry,Fword,Filename$
  5126. 5114          GOTO Found_it
  5127. 5115        END IF
  5128. 5116 Nexte:NEXT Entry
  5129. 5117    NEXT Sector
  5130. 5118 Done_find:S=-1
  5131. 5119    GOTO Done
  5132. 5120    !
  5133. 5121 Found_it:  !
  5134. 5122  ! PRINT USING "8(K,X),/";Sctr(*)
  5135. 5123    Fs=(Sctr(Fword+6)*2^16)+Sctr(Fword+7)    ! S=Start sector of file
  5136. 5124    Fl=(Sctr(Fword+8)*2^16)+Sctr(Fword+9)    ! L=Number of sectors
  5137. 5125 !
  5138. 5126    IF NPAR>5 THEN T=Sctr(Fword+5)  ! File Type
  5139. 5127    IF NPAR>8 THEN V=Sctr(Fword+13) ! Volume Number
  5140. 5128    IF NPAR>9 THEN P=Sctr(Fword+14) ! Protect Code for file
  5141. 5129    IF NPAR>10 THEN R=Sctr(Fword+15)!
  5142. 5130 Done:!
  5143. 5131  SUBEND
  5144. 5132  !------------------------------------------------------------------------
  5145. 5133  SUB Word_2char(INTEGER N,Msb,Lsb)
  5146. 5134  !
  5147. 5135  ! Extracts 2 Character Bytes from an integer (word)
  5148. 5136  ! Returns the characters as Msb and Lsb integers
  5149. 5137  !
  5150. 5138  !
  5151. 5139    Temp=N
  5152. 5140    IF N<0 THEN Temp=N+65536
  5153. 5141    Msb=Temp DIV 256
  5154. 5142    Lsb=Temp MOD 256
  5155. 5143  SUBEND
  5156. 5144  !----------------------------------------------------------------------
  5157. 5145 Convert:SUB Convert(Sf$,Type$,INTEGER Rc,OPTIONAL Flen,Df$)
  5158. 5146  !
  5159. 5147  ! Sf$:  complete filespec for source file to change
  5160. 5148  ! Df$:  Filespec or destination msi$ for converted file
  5161. 5149  ! Convert Sf$ to the Type$ specified and copy result to D_msi$
  5162. 5150  !
  5163. 5151    COM /Crt/ Crt_width,Crt_lines
  5164. 5152    Debug=1
  5165. 5153    ON ERROR GOSUB Cnvt_err
  5166. 5154    REAL S,L,Dir_entry_sec
  5167. 5155    INTEGER T,V,R,P,Asector(0:127)
  5168. 5156    DIM Filename$[80],Sav_msi$[256],S_msi$[256]
  5169. 5157  !
  5170. 5158    Sav_msi$=SYSTEM$("MSI")
  5171. 5159    Parse_filename(Sf$,S_msi$,S_path$)
  5172. 5160    Filename$=S_path$&Sf$&S_msi$
  5173. 5161    IF FNHfs_disc(S_msi$) THEN          ! HFS - must copy to ramdisc
  5174. 5162      S_path$=""
  5175. 5163      IF S_msi$=":,0,0" THEN 
  5176. 5164        ! file already on ramdisc
  5177. 5165      ELSE
  5178. 5166        Init_ramdisc(Kbytes)
  5179. 5167        S_msi$=":,0,0"
  5180. 5168        DISP "Copying ";Filename$;" TO ";Sf$&S_msi$
  5181. 5169        COPY Filename$ TO Sf$&S_msi$
  5182. 5170      END IF
  5183. 5171    END IF
  5184. 5172  !
  5185. 5173    Filename$=S_path$&Sf$&S_msi$
  5186. 5174    MASS STORAGE IS S_msi$
  5187. 5175    Pcode=32*256+32          ! protect code for non-ascii files
  5188. 5176    Get_fileinfo(Sf$,S,L,Dir_entry_sec,Dir_entry,T,V,P,R)
  5189. 5177    IF Dir_entry_sec=0 THEN 
  5190. 5178      DISP "Cant find ";Sf$;"  In Disc Directory "
  5191. 5179      SUBEXIT
  5192. 5180    END IF
  5193. 5181  !
  5194. 5182    Phyread(Dir_entry_sec,Asector(*))
  5195. 5183    Fword=Dir_entry*16
  5196. 5184    Cur_type=Asector(Fword+5)          ! File Type
  5197. 5185   !
  5198. 5186    SELECT Cur_type
  5199. 5187    CASE 1
  5200. 5188      Cur_type$="ASCII"
  5201. 5189    CASE -5791
  5202. 5190      Cur_type$="BDAT"
  5203. 5191    CASE -5808
  5204. 5192      Cur_type$="PROG"
  5205. 5193    CASE -5813
  5206. 5194      Cur_type$="HP-UX"
  5207. 5195    CASE -5775
  5208. 5196      Cur_type$="BIN"
  5209. 5197    CASE -5822
  5210. 5198      Cur_type$="SYSTM"
  5211. 5199    CASE ELSE       ! Pascal ?
  5212. 5200      Cur_type$="FOREIGN"
  5213. 5201    END SELECT
  5214. 5202  ! DISP "Current file type is ";Cur_type$
  5215. 5203    New_type$=Type$
  5216. 5204 Get_type_num: !
  5217. 5205    SELECT New_type$
  5218. 5206    CASE "ASCII"
  5219. 5207      New_type=1
  5220. 5208    CASE "BDAT"
  5221. 5209      New_type=-5791
  5222. 5210    CASE "PROG"
  5223. 5211      New_type=-5808
  5224. 5212    CASE "HP-UX","HPUX"
  5225. 5213      New_type=-5813
  5226. 5214    CASE "BIN"
  5227. 5215      New_type=-5775
  5228. 5216    CASE "SYSTM","SYSTEM"
  5229. 5217      New_type=-5822
  5230. 5218    CASE ELSE
  5231. 5219      New_type=VAL(New_type$)
  5232. 5220      DISP "Change Type to ";New_type
  5233. 5221      OUTPUT KBD;"Y";" H";
  5234. 5222      ENTER KBD;Ans$
  5235. 5223      IF UPC$(Ans$[1,1])="Y" THEN 
  5236. 5224      ELSE
  5237. 5225        SUBEXIT
  5238. 5226      END IF
  5239. 5227    END SELECT
  5240. 5228   !
  5241. 5229    DISP "Changing File Type to ";New_type$,New_type
  5242. 5230    WAIT .5
  5243. 5231    Asector(Fword+5)=New_type
  5244. 5232  !
  5245. 5233    IF New_type$<>"ASCII" THEN Asector(Fword+14)=Pcode
  5246. 5234    IF New_type$="BDAT" THEN Asector(Fword+15)=128   ! 128=256 Bytes per rec
  5247. 5235    IF New_type$="PROG" THEN 
  5248. 5236      GOTO Skip_adj_prog
  5249. 5237   !
  5250. 5238   ! Make sure EOF is on a sector boundary (256 byte)
  5251. 5239   ! Therefore the low-byte should always be 00x
  5252. 5240   !
  5253. 5241      Hibyte=Asector(Fword+6)
  5254. 5242      Lobyte=Asector(Fword+7)
  5255. 5243      IF Lobyte>0 THEN 
  5256. 5244        DISP "Adjusting EOF to a sector boundary"
  5257. 5245        PAUSE
  5258. 5246        Asector(Fword+6)=Hibyte+1
  5259. 5247        Asector(Fword+7)=0
  5260. 5248      END IF
  5261. 5249 Skip_adj_prog:   !
  5262. 5250   !
  5263. 5251   ! Set Record size to 0080x for PROG Files
  5264. 5252   !
  5265. 5253      Asector(Fword+15)=128                               ! x0080
  5266. 5254    END IF
  5267. 5255 !
  5268. 5256    IF NPAR>3 THEN   ! File-length Flen was specified
  5269. 5257      IF New_type$="PROG" THEN 
  5270. 5258        Asector(Fword+8)=INT(Flen/256)
  5271. 5259        Asector(Fword+9)=Flen MOD 256
  5272. 5260      END IF
  5273. 5261    END IF
  5274. 5262    Phywrite(Dir_entry_sec,Asector(*))
  5275. 5263    Rc=1
  5276. 5264  !
  5277. 5265    IF New_type$="HP-UX" THEN      ! Reset EOF pointer
  5278. 5266      ASSIGN @T TO Filename$
  5279. 5267      STATUS @T,3;Defr
  5280. 5268      CONTROL @T,7;Defr
  5281. 5269    END IF
  5282. 5270  !
  5283. 5271    IF Napr>4 THEN 
  5284. 5272      Df$=D_msi$
  5285. 5273      Parse_filename(Df$,D_msi$,D_path$)
  5286. 5274      IF NOT LEN(Df$) THEN Df$=Sf$
  5287. 5275      COPY Filename$ TO D_path$&Df$&D_msi$
  5288. 5276    END IF
  5289. 5277    MASS STORAGE IS Sav_msi$
  5290. 5278    DISP 
  5291. 5279    SUBEXIT  !-------------------------------------------------------------
  5292. 5280 Cnvt_err: !
  5293. 5281    DISP ERRM$
  5294. 5282    SELECT ERRN
  5295. 5283    CASE 54          ! duplicate filename
  5296. 5284      DISP "Purging: ";Sf$&S_msi$
  5297. 5285      PURGE Sf$&S_msi$
  5298. 5286      WAIT 1
  5299. 5287      DISP 
  5300. 5288    CASE ELSE
  5301. 5289      DISP ERRM$;"  in Convert"
  5302. 5290    END SELECT
  5303. 5291    RETURN 
  5304. 5292  SUBEND
  5305. 5293  !========================================================================
  5306. 5294  DEF FNHfs_disc(Msi$)
  5307. 5295    ALLOCATE Cat$(0:3)[80] ! 0:MSI  1:LABEL  2:FORMAT  3:SPACE
  5308. 5296    IF NOT LEN(Msi$) THEN Msi$=SYSTEM$("MSI")
  5309. 5297    CAT Msi$ TO Cat$(*)
  5310. 5298    IF POS(Cat$(2),"HFS") THEN 
  5311. 5299      RETURN 1
  5312. 5300    ELSE
  5313. 5301      RETURN 0
  5314. 5302    END IF
  5315. 5303  FNEND
  5316. 5304  !------------------------------------------------------------------------
  5317. 5305 Disc_space:SUB Disc_space(Msi$,Total,Largest_hole,Hole_sum,Format$)
  5318. 5306  !
  5319. 5307  ! Format$  HFS,LIF
  5320. 5308  ! All amounts in Sectors
  5321. 5309  !
  5322. 5310    INTEGER Recsz,Num_files,Cat_size
  5323. 5311    REAL Flen
  5324. 5312  !
  5325. 5313    Cat_size=150
  5326. 5314    ALLOCATE Cat$(1:Cat_size)[80] ! 1:MSI  2:LABEL  3:FORMAT  4:SPACE
  5327. 5315    ON ERROR GOSUB Space_err
  5328. 5316    CAT Msi$ TO Cat$(*);COUNT Num_files ! 7 LINE HEADER
  5329. 5317    REDIM Cat$(1:Num_files)
  5330. 5318    Num_files=Num_files-7
  5331. 5319    ENTER Cat$(4);Total                          ! SECTORS
  5332. 5320    Format$=TRIM$(Cat$(3)[POS(Cat$(3),":")+1])
  5333. 5321    Hole_sum=0
  5334. 5322    Hole=0
  5335. 5323    Largest_hole=0
  5336. 5324  !
  5337. 5325    DEALLOCATE Cat$(*)
  5338. 5326    IF Num_files>=Cat_size THEN GOSUB Get_count
  5339. 5327    IF Num_files=0 THEN 
  5340. 5328      Largest_hole=Total
  5341. 5329      SUBEXIT
  5342. 5330    END IF
  5343. 5331    IF NOT POS(Format$,"HFS") THEN 
  5344. 5332      ALLOCATE Cat$(1:Num_files)[80]
  5345. 5333      CAT Msi$ TO Cat$(*);NO HEADER,EXTEND
  5346. 5334      FOR I=1 TO Num_files-1
  5347. 5335        Start_sec=VAL(Cat$(I)[40,47])
  5348. 5336        Flen=VAL(Cat$(I)[20,28])
  5349. 5337        Recsz=VAL(Cat$(I)[33,39])
  5350. 5338        IF Recsz=1 THEN Flen=Flen/256
  5351. 5339        Next_sec=VAL(Cat$(I+1)[40,47])
  5352. 5340        Del_sec=Next_sec-Start_sec
  5353. 5341        Hole=Del_sec-Flen
  5354. 5342        Hole_sum=Hole_sum+Hole
  5355. 5343        IF Hole>Largest_hole THEN 
  5356. 5344          Largest_hole=Hole
  5357. 5345        END IF
  5358. 5346      NEXT I
  5359. 5347      Last_contig=Total-Hole_sum
  5360. 5348      IF Last_contig>Largest_hole THEN Largest_hole=Last_contig
  5361. 5349    ELSE
  5362. 5350      Largest_hole=Total
  5363. 5351    END IF
  5364. 5352    SUBEXIT !---------------------------------------------------
  5365. 5353 Get_count:   !
  5366. 5354    Num_try=100
  5367. 5355    REPEAT
  5368. 5356      Num_try=Num_try+25
  5369. 5357      ALLOCATE Cat$(1:Num_try)[80]
  5370. 5358      CAT Msi$ TO Cat$(*);NAMES,COUNT Num_files,NO HEADER   ! HEADER NOT INC
  5371. 5359      DEALLOCATE Cat$(*)
  5372. 5360    UNTIL Num_files<Num_try
  5373. 5361    RETURN 
  5374. 5362   !---------------------------
  5375. 5363 Space_err: !
  5376. 5364    SELECT ERRN
  5377. 5365    CASE 76      ! INCORRECT UNIT CODE
  5378. 5366      SUBEXIT
  5379. 5367    CASE ELSE
  5380. 5368      DISP ERRM$
  5381. 5369      PAUSE
  5382. 5370    END SELECT
  5383. 5371    RETURN 
  5384. 5372  SUBEND
  5385. 5373  !------------------------------------------------------------------------
  5386. 5374  SUB Get_cat_entry(F$,F_msi$,F_path$,Filename$,File_found,Cat_entry$)
  5387. 5375 Get_cat_entry: !
  5388. 5376    ON ERROR GOSUB Gce_err
  5389. 5377    ALLOCATE Cat$(1:50)[80],Misc$[256]
  5390. 5378    File_found=0
  5391. 5379    REPEAT
  5392. 5380      DISP "Checking File Access"
  5393. 5381    !
  5394. 5382    ! Warning, CAT;SELECT may  find more than one file
  5395. 5383    !
  5396. 5384      CAT F_path$&F_msi$ TO Cat$(*);SELECT F$,COUNT Num_files        !FILE IS ELMENT 8
  5397. 5385      FOR I=8 TO Num_files
  5398. 5386        IF POS(Cat$(I),F$) THEN 
  5399. 5387          Cat_entry$=Cat$(I)
  5400. 5388          Misc$=TRIM$(Cat_entry$[1,21])
  5401. 5389          IF Misc$=F$ THEN 
  5402. 5390            File_found=1
  5403. 5391            I=Num_files
  5404. 5392          END IF
  5405. 5393        END IF
  5406. 5394      NEXT I
  5407. 5395      IF NOT File_found THEN 
  5408. 5396        GOSUB Get_filename
  5409. 5397      END IF
  5410. 5398    UNTIL File_found>0
  5411. 5399    DISP 
  5412. 5400    SUBEXIT
  5413. 5401 Get_filename:!
  5414. 5402    DISP "File not found in catalog - please check name &  path, (blank to abort) "
  5415. 5403    OUTPUT KBD;F_path$&F$&F_msi$;" H";
  5416. 5404    ENTER KBD;Filename$
  5417. 5405    IF NOT LEN(TRIM$(Filename$)) THEN SUBEXIT
  5418. 5406    F$=Filename$
  5419. 5407    Parse_filename(F$,F_msi$,F_path$)
  5420. 5408    Filename$=F_path$&F$&F_msi$
  5421. 5409    RETURN 
  5422. 5410 !--------------------------------------
  5423. 5411 Gce_err: !
  5424. 5412    SELECT ERRN
  5425. 5413    CASE 53    ! improper file name
  5426. 5414      GOSUB Get_filename
  5427. 5415    CASE ELSE
  5428. 5416    END SELECT
  5429. 5417    File_found=0
  5430. 5418    RETURN 
  5431. 5419  SUBEND
  5432. 5420  !-----------------------------------------------------------------------
  5433. 5421 Prompt:SUB Prompt(Prompt$,Init$,Ans$,Flag)
  5434. 5422    DISP Prompt$
  5435. 5423    OUTPUT KBD;Init$;" H";
  5436. 5424    ENTER KBD;Ans$
  5437. 5425    DISP 
  5438. 5426    Ans$=TRIM$(UPC$(Ans$))
  5439. 5427    A_len=LEN(Ans$)
  5440. 5428    IF NOT A_len THEN Flag=0
  5441. 5429    IF A_len=1 AND Ans$="N" THEN Flag=0
  5442. 5430    IF A_len=1 AND Ans$="Y" THEN Flag=1
  5443. 5431    IF POS(Ans$,"YES") THEN Flag=1
  5444. 5432    IF POS(Ans$,"NO") THEN Flag=0
  5445. 5433  SUBEND
  5446. 5434  !------------------------------------------------------------------------
  5447. 5435 More:SUB More(Filename$,Pdev,Cmds$)
  5448. 5436   !
  5449. 5437    OPTION BASE 1
  5450. 5438    DIM Line$[256],Misc$[256],K$[256]
  5451. 5439    INTEGER Pline,Paging,Rc,File_type,Crt_lines,Print_abort
  5452. 5440 !-------------------------------------------------------
  5453. 5441    Sav_prt$=SYSTEM$("PRINTER IS")
  5454. 5442    PRINTER IS CRT
  5455. 5443    REPEAT
  5456. 5444      ASSIGN @File TO Filename$;FORMAT ON,RETURN Rc
  5457. 5445      IF (NOT LEN(Filename$)) OR (Rc) THEN 
  5458. 5446        BEEP 150,.1
  5459. 5447        DISP "Print Which File ?  - Blank to Exit"
  5460. 5448        OUTPUT KBD;Filename$;
  5461. 5449        ENTER KBD;Filename$
  5462. 5450        IF TRIM$(Filename$)="" THEN GOTO Exit_print
  5463. 5451      END IF
  5464. 5452    UNTIL NOT Rc
  5465. 5453    PRINT USING "/,5(K),/";Cmds$;" FILE: ";Filename$;"  To  Device: ";Pdev
  5466. 5454    ON ERROR GOTO Print_err
  5467. 5455    STATUS @File,1;File_type
  5468. 5456    ON END @File GOTO Exit_print
  5469. 5457    ON KBD,2 GOSUB Kbd_abort
  5470. 5458    DISP "Space Bar: Pause/Continue   P: Toggle Paging     Esc: Quit"
  5471. 5459    Print_wait=0
  5472. 5460    STATUS CRT,13;Crt_lines
  5473. 5461    Crt_lines=Crt_lines-7
  5474. 5462    Paging=1
  5475. 5463    One_line=0
  5476. 5464    !--------------------------------
  5477. 5465    LOOP
  5478. 5466      SELECT File_type
  5479. 5467      CASE 1       !
  5480. 5468      CASE 2       ! Bdat
  5481. 5469        ENTER @File;Line$
  5482. 5470      CASE 3       ! Ascii
  5483. 5471        ENTER @File;Line$
  5484. 5472      CASE 4       ! hp-ux
  5485. 5473        ENTER @File USING "#,K";Line$
  5486. 5474      END SELECT
  5487. 5475       !
  5488. 5476      Pline=Pline+1                       ! paging
  5489. 5477      IF Debug THEN DISP Pline,Crt_lines
  5490. 5478      IF Pdev=1 AND Paging=1 THEN 
  5491. 5479        IF Pline>=Crt_lines THEN 
  5492. 5480          OUTPUT KBD;" ";                ! simulate a "space bar press"
  5493. 5481          GOSUB Kbd_abort
  5494. 5482          Pline=1
  5495. 5483        END IF
  5496. 5484      END IF
  5497. 5485      !
  5498. 5486      IF Pdev>1 THEN 
  5499. 5487        OUTPUT Pdev;Line$                    ! to printer
  5500. 5488        DISP "printer: ",Pdev
  5501. 5489      END IF
  5502. 5490      !
  5503. 5491      IF POS(Line$," ") THEN                 ! avoid FF to screen
  5504. 5492        Line$[(POS(Line$," "));1]=" "
  5505. 5493      END IF
  5506. 5494      PRINT Line$
  5507. 5495      IF One_line THEN 
  5508. 5496        OUTPUT KBD;" ";
  5509. 5497        GOSUB Kbd_abort
  5510. 5498      END IF
  5511. 5499       !
  5512. 5500      WAIT Print_wait
  5513. 5501    EXIT IF Print_abort=1
  5514. 5502    END LOOP
  5515. 5503 Print_err:DISP ERRM$
  5516. 5504 Exit_print:!
  5517. 5505    OFF ERROR 
  5518. 5506    OFF KBD
  5519. 5507    ASSIGN @File TO *
  5520. 5508    PRINTER IS VAL(Sav_prt$)
  5521. 5509    DISP 
  5522. 5510    SUBEXIT
  5523. 5511 Kbd_abort:!       Routine to interrupt TYPE/PRINT of file
  5524. 5512    Misc$=SYSTEM$("KBD LINE")
  5525. 5513    K$=KBD$
  5526. 5514    CLEAR LINE        ! clear KBD LINE
  5527. 5515    One_line=0        ! clear single line mode
  5528. 5516 Ka_2:!
  5529. 5517    IF NOT LEN(K$) THEN K$=Misc$
  5530. 5518    K$=UPC$(K$)
  5531. 5519    Misc$=KBD$
  5532. 5520    ON KBD,3 GOTO Exit_abort
  5533. 5521    SELECT K$[1,1]
  5534. 5522    CASE " "
  5535. 5523      LOOP  ! wait here for next space bar
  5536. 5524      END LOOP
  5537. 5525    CASE ""                   !   =  Abort
  5538. 5526      Print_abort=1
  5539. 5527    CASE "P"                   ! P  =  Toggle Paging Breaks
  5540. 5528      IF Paging THEN 
  5541. 5529        Paging=0
  5542. 5530        DISP "paging off"
  5543. 5531      ELSE
  5544. 5532        Paging=1
  5545. 5533        DISP "paging on "
  5546. 5534      END IF
  5547. 5535      K$=" "
  5548. 5536      WAIT .1         ! dwell to lift finger
  5549. 5537    CASE " "
  5550. 5538      SELECT K$[2,2]
  5551. 5539      CASE "^"            ! faster
  5552. 5540        BEEP 300,.01
  5553. 5541        Print_wait=MAX(0,Print_wait-.1)
  5554. 5542      CASE "V"            ! slower
  5555. 5543        BEEP 300,.01
  5556. 5544        Print_wait=Print_wait+.1
  5557. 5545      CASE "E"                    ! <ENTER>  One Line Feed
  5558. 5546        One_line=1
  5559. 5547      END SELECT
  5560. 5548      IF Debug THEN DISP Print_wait
  5561. 5549    END SELECT
  5562. 5550 Exit_abort:ON KBD,2 GOSUB Kbd_abort
  5563. 5551    K$=KBD$
  5564. 5552    IF LEN(K$) THEN 
  5565. 5553      K$=UPC$(K$)
  5566. 5554      IF NOT (K$[1,1]=" ") THEN GOTO Ka_2
  5567. 5555    END IF
  5568. 5556    RETURN 
  5569. 5557  SUBEND
  5570. 5558  !=====================  END OF HPKERMIT
  5571. 5560  SUB Decode_pack(Rdata$,INTEGER Quote,Qbin,Rep_ch)
  5572. 5561 Decode_pack: !
  5573. 5562 Dp: !
  5574. 5563  !
  5575. 5564  ! Receive Rdata$ (Kermit Packet)
  5576. 5565  ! Decode all &,#,~ and stuff results into Rdata$
  5577. 5566  !
  5578. 5567    INTEGER B,P,Stuff,Qon,Biton,Reps
  5579. 5568  !
  5580. 5569    ALLOCATE File_buff$[100]            ! use file_buff$ as a local here
  5581. 5570  !------------------------------------------------------------------
  5582. 5571    P=1
  5583. 5572    FOR B=1 TO LEN(Rdata$)
  5584. 5573      Stuff$=Rdata$[B,B]             ! get next  byte
  5585. 5574      Stuff=NUM(Stuff$)
  5586. 5575      IF Debug THEN DISP "P= ";P,"B= ";B,Stuff$,File_buff$[1,P]
  5587. 5576      SELECT Stuff
  5588. 5577      CASE Quote                          ! Control Quoting #
  5589. 5578        IF Qon=1 THEN 
  5590. 5579          IF (NOT Biton) THEN 
  5591. 5580            File_buff$[P,P]=Stuff$              ! ## = #
  5592. 5581          ELSE
  5593. 5582            File_buff$[P,P]=CHR$(Stuff+128)      ! &## = '#
  5594. 5583            Biton=0
  5595. 5584          END IF
  5596. 5585          P=P+1
  5597. 5586          Qon=0
  5598. 5587        ELSE
  5599. 5588          Qon=1
  5600. 5589        END IF
  5601. 5590      CASE Qbin                   ! 8 bit prefix  &    (Biton)
  5602. 5591        IF Qon=1 THEN 
  5603. 5592          IF Biton=1 THEN 
  5604. 5593            File_buff$[P,P]=CHR$(Stuff+128)     ! &#& = '&
  5605. 5594            P=P+1
  5606. 5595            Biton=0
  5607. 5596          ELSE
  5608. 5597            File_buff$[P,P]=Stuff$              ! #& = &
  5609. 5598            P=P+1
  5610. 5599          END IF
  5611. 5600          Qon=0
  5612. 5601        ELSE
  5613. 5602          Biton=1
  5614. 5603        END IF
  5615. 5604      CASE Rep_ch                 ! Repeat Processing  ~
  5616. 5605        IF (NOT Qon) AND (NOT Biton) THEN 
  5617. 5606          BEEP 
  5618. 5607          DISP "Repeat Process";Rdata$[B-1;4]
  5619. 5608          B=B+1
  5620. 5609          Reps=FNUnchar(Rdata$[B,B])           ! number of repeats this char
  5621. 5610          B=B+1
  5622. 5611          IF NUM(Rdata$[B,B])=Quote THEN             ! ~#()
  5623. 5612            Qon=1
  5624. 5613            B=B+1
  5625. 5614          END IF
  5626. 5615           !
  5627. 5616          IF NUM(Rdata$[B,B])=Qbin THEN              ! ~&()
  5628. 5617            Biton=1
  5629. 5618            B=B+1
  5630. 5619          END IF
  5631. 5620           !
  5632. 5621          Ch2rep=NUM(Rdata$[B,B])                 ! Char to Repeat
  5633. 5622          IF Qon THEN Ch2rep=Ch2rep-64
  5634. 5623          IF Biton THEN Ch2rep=Ch2rep+128
  5635. 5624          Ch2rep$=CHR$(Ch2rep)
  5636. 5625          File_buff$[P;Reps]=RPT$(Ch2rep$,Reps)
  5637. 5626          P=P+Reps
  5638. 5627        ELSE        ! #~
  5639. 5628          IF Biton THEN Stuff=Stuff+128
  5640. 5629          IF Qon THEN Stuff=Stuff-64
  5641. 5630          File_buff$[P,P]=CHR$(Stuff)
  5642. 5631          P=P+1
  5643. 5632        END IF
  5644. 5633             !
  5645. 5634      CASE 32 TO 127               ! printable characters
  5646. 5635        IF (Qon) AND (Biton) THEN                 ! &#()  Binary File
  5647. 5636          File_buff$[P,P]=CHR$(FNCtl(Stuff$)+128)
  5648. 5637          P=P+1
  5649. 5638        END IF
  5650. 5639               !
  5651. 5640        IF (Biton) AND (NOT Qon) THEN             ! &
  5652. 5641          File_buff$[P,P]=CHR$(NUM(Stuff$)+128)
  5653. 5642          P=P+1
  5654. 5643        END IF
  5655. 5644              !
  5656. 5645        IF (Qon) AND (NOT Biton) THEN             ! #
  5657. 5646          File_buff$[P,P]=CHR$(FNCtl(Stuff$))
  5658. 5647          P=P+1
  5659. 5648        END IF
  5660. 5649        IF (NOT Qon) AND (NOT Biton) THEN           ! normal char
  5661. 5650          File_buff$[P,P]=Stuff$
  5662. 5651          P=P+1
  5663. 5652        END IF
  5664. 5653           !
  5665. 5654        Qon=0
  5666. 5655        Biton=0
  5667. 5656           !
  5668. 5657      CASE 128 TO 255
  5669. 5658        PRINT TABXY(25,12);"Invalid Char: Extended Ascii # ";Stuff
  5670. 5659      END SELECT
  5671. 5660    NEXT B
  5672. 5661    Rdata$=File_buff$
  5673. 5662  SUBEND
  5674. 5663  !------------------------------------------------------------------------
  5675. 5670  SUB Encode_pack(File_buff$,Packet$,INTEGER Myquote,Qbin,Rep_ch,Spsiz)
  5676. 5671 Encode_pack_s: !
  5677. 5672 Ep: !
  5678. 5673  !
  5679. 5674    DIM Stuff$[1],Myquote$[1],Qbin$[1]
  5680. 5675    INTEGER Pack_full,P,B,Sdata_done,Bl
  5681. 5676  !
  5682. 5677    Myquote$=CHR$(Myquote)
  5683. 5678    Qbin$=CHR$(Qbin)
  5684. 5679    Bl=LEN(File_buff$)
  5685. 5680    Pack_full=0
  5686. 5681    P=1
  5687. 5682    B=1
  5688. 5683  !------------------------------------------------------
  5689. 5684    REPEAT                           ! Until Pack_full=1
  5690. 5685 Stuff:Stuff$=File_buff$[B,B]
  5691. 5686      Stuff=NUM(Stuff$)
  5692. 5687      SELECT Stuff
  5693. 5688      CASE 0 TO 31,127 TO 255,Myquote,Qbin          ! ,Rep_ch !add quoting
  5694. 5689        SELECT Stuff
  5695. 5690        CASE 0 TO 31                               ! # Prefix.  (38=& 35=#)
  5696. 5691          Packet$[P;2]=Myquote$&CHR$(FNCtl(Stuff$))
  5697. 5692          P=P+2
  5698. 5693        CASE Myquote,Qbin
  5699. 5694          Packet$[P;2]=Myquote$&Stuff$
  5700. 5695          P=P+2
  5701. 5696        CASE 127              ! #?
  5702. 5697          Packet$[P;2]=Myquote$&CHR$(Stuff-64)
  5703. 5698          P=P+2
  5704. 5699        CASE 128 TO 159                       ! &# prefixing
  5705. 5700          Packet$[P;3]=Qbin$&Myquote$&CHR$(Stuff-64)
  5706. 5701          P=P+3
  5707. 5702        CASE 128+35,128+38
  5708. 5703          Packet$[P;3]=Qbin$&Myquote$&CHR$(Stuff)
  5709. 5704          P=P+3
  5710. 5705        CASE 160 TO 254                       ! & Prefixing
  5711. 5706          Packet$[P;2]=Qbin$&CHR$(Stuff-128)
  5712. 5707          P=P+2
  5713. 5708        CASE 255              ! &#?
  5714. 5709          Packet$[P;3]=Qbin$&Myquote$&"?"
  5715. 5710          P=P+3
  5716. 5711        END SELECT
  5717. 5712      CASE ELSE           ! printable -  no quoting is needed
  5718. 5713        Packet$[P,P]=Stuff$
  5719. 5714        P=P+1
  5720. 5715      END SELECT
  5721. 5716     !
  5722. 5717      IF P>=Spsiz-4 THEN Pack_full=1
  5723. 5718   !  IF At_eof AND B=Bl THEN
  5724. 5719      IF B=Bl THEN 
  5725. 5720        Pack_full=1
  5726. 5721      END IF
  5727. 5722      B=B+1
  5728. 5723    UNTIL Pack_full
  5729. 5724     !
  5730. 5725    File_buff$=File_buff$[B]                  ! truncate
  5731. 5726    B=1
  5732. 5727  SUBEND
  5733. 5728  !------------------------------------------------------------------------
  5734. 5730 Spack:SUB Spack(Packet$,Pkt$,INTEGER Npak,Sndpkt$)
  5735. 5731 Sspack: ! Form Send Packet Contents from Packet$ data
  5736. 5732         ! IN
  5737. 5733         !  Packet$[],Pkt$,Npak
  5738. 5734         ! OUT
  5739. 5735         !  Sndpkt$[]
  5740. 5736    INTEGER Plen,Cchksum
  5741. 5737    Sndpkt$=""
  5742. 5738    Dlen=LEN(Packet$)
  5743. 5739    Plen=LEN(Packet$)+3
  5744. 5740    Ckpos=Plen+2
  5745. 5741    Sndpkt$[1;1]=""             ! packet mark  ^A
  5746. 5742    Sndpkt$[2;1]=FNTochar$(Plen)   ! length
  5747. 5743    Sndpkt$[3;1]=FNTochar$(Npak MOD 64)      ! packet sequence
  5748. 5744    Sndpkt$[4;1]=Pkt$            ! packet type
  5749. 5745    Sndpkt$[5;LEN(Packet$)]=Packet$  ! Stuff Data
  5750. 5746    Chk=0
  5751. 5747    FOR Ch=2 TO Plen+1
  5752. 5748      Chk=Chk+NUM(Sndpkt$[Ch,Ch])
  5753. 5749    NEXT Ch
  5754. 5750    Cchksum=BINAND(Chk+(BINAND(Chk,192)/64),63)   ! Computed Checksum
  5755. 5751    Sndpkt$[Ckpos;1]=FNTochar$(Cchksum)
  5756. 5755  SUBEND
  5757. 5756  !=======================================================================
  5758.