home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / bbcmicro / bbcker.asm < prev    next >
Assembly Source File  |  2020-01-01  |  284KB  |  15,368 lines

  1. *******************************************************************************
  2. *
  3. * Kermit for BBC Micros version 1.45
  4. * ----------------------------------
  5. *
  6. * This file is a concatenation of the separate source file for BBC Kermit. In
  7. * order to assemble the source, you will need to split it into its separate
  8. * files: the split points are marked in this file with lines of the form
  9. *
  10. *     ****** File <name> *******************
  11. *
  12. * See file BBCKERMIT.DOC for details of how to arrange the separate files on
  13. * disc ready for assembly.
  14. *
  15. * This release can be assembled with either the commercially available ADE
  16. * assembler, or, for preference, the free assembler supplied with BBC Kermit.
  17. * See file BBCASM.ANN for details of this.
  18. *
  19. *****************************************************************************
  20.  
  21.  
  22. ****** File BBCMIT *************************************************************
  23.     SKP    H
  24. * BBCMIT: Updated 24/02/87 @ 1200
  25.  
  26. OFF    EQU    0    ;these are defined in case the Lancaster 65C02
  27. ON    EQU    1    ;assembler is used rather than ADE
  28.  
  29. MARK    EQU    1    ;mark number
  30. VERSION EQU    45    ;version number
  31. LEVEL    EQU    -1    ;development level (-1 for release version)
  32.  
  33.     LST    OFF
  34.  
  35. Y    EQU    -1    ;flags for IF
  36. N    EQU    0
  37. D    EQU    -1
  38. G    EQU    -1
  39. S    EQU    0
  40.  
  41. ADE    QUERY    'Using ADE (Y/N)'
  42.  
  43.     IF    ~ADE
  44.     SFCOND
  45.     FI
  46.  
  47. ROM    QUERY    'Build ROM version (Y/N)'
  48. RAM    EQU    ~ROM
  49.  
  50.  
  51. ONEDRV    QUERY    'All files on one disc surface (Y/N)'
  52.  
  53.     IF    ~ONEDRV
  54. DSDRIV    QUERY    '1 D/S drive (D) or 2 S/S (S)'
  55.     FI
  56.  
  57. LIST    QUERY    'Listing required (Y/N)'
  58.  
  59.     IF    LIST
  60. LFULL    QUERY    'Global or selective (G/S)'
  61.     LST    ON
  62.     IF    ADE
  63.     PAGE    88
  64.     ELSE
  65.     PAGE    88,132
  66.     FI
  67.     SYSVDU    1,15,1,27,1,48
  68.     IF    ROM
  69.     TTL    'BBC Kermit (ROM)'
  70.     ELSE
  71.     TTL    'BBC Kermit (RAM)'
  72.     FI
  73.     ELSE
  74. LFULL    EQU    N
  75.     FI
  76.  
  77.     IF    ~LFULL
  78.     LST    OFF
  79.     FI
  80.  
  81. *******************************************************************************
  82. *
  83. *            KERMIT FOR BBC MICRO
  84. *            ====================
  85. *
  86. * This program implements the KERMIT protocol for an Acorn BBC microcomputer,
  87. * and is compatible with models B, B+, B+128, Master 128 and Master Compact.
  88. * It is not Tube compatible, and any second processor attached must be turned
  89. * off.
  90. *
  91. * The source is written to be assembled with the Lancaster 65C02 Assembler,
  92. * supplied free with the Kermit files on disc or from the Lancaster Distribution
  93. * service. It can also be assembled with the commercially-available ADE system
  94. * (version 2.02 or later) which can be bought from SYSTEM, Collegiate Crescent,
  95. * Sheffield, UK (See Acorn User magazine for adverts). The User Guide gives
  96. * full details of the assembly process for both assemblers.
  97. *
  98. * This implementation, begun in February 1985, is by Alan Phillips of the 
  99. * Department of Computing, Lancaster University. Copyright is retained on the
  100. * program, but it is of course freely available under the standard terms for
  101. * distributing Kermit. You are encouraged to pass the source and compiled forms
  102. * on to others, but they must not be sold (other than to cover media and moderate
  103. * handling charges)
  104. *
  105. * We are always pleased to receive comments, suggestions and bug reports, and
  106. * we will produce bug-fix releases when necessary. The contact addresses are
  107. * given below.
  108. *
  109. * Lancaster University Computing Department also run the UK Kermit Distribution
  110. * Service, through which you can obtain copies of Kermit for over 200 different
  111. * machine/system combinations. Enquiries are welcome, but please note that,
  112. * apart from this BBC implementation, we do not supply any Kermits outside the
  113. * UK and Eire.
  114. *
  115. * Postal Address :    Kermit Distribution,
  116. *            Department of Computing,
  117. *            Computer Centre,
  118. *            Lancaster University,
  119. *            Lancaster LA1 4YW
  120. *
  121. * Telephone :        (0524) 65201 x 4881
  122. *
  123. * Electronic mail :    SYSKERMIT @ LANCS.VAX1
  124. *            (JANET address 000010404000.FTP.MAIL,
  125. *             PSS address   234252400101.000010404000.FTP.MAIL)
  126. *
  127. *                      (Note that these addresses use Grey Book X25 mail: we
  128. *                      have no Telecom Gold or Prestel mailboxes. We also
  129. *                      cannot respond to Telex messages)
  130. *
  131. *
  132. * Thanks are due to:
  133. *
  134. * Dave Osborne        University of Nottingham
  135. * Derek Dongray    University of Manchester
  136. * Alwyn Breame        AFRC Computer Centre
  137. * Bertil Schou        Loughborough University
  138. * Peter O'Kane        University College, Galway
  139. * Dave Morriss        Heriot-Watt University
  140. * Colin Allison
  141. * Mike Whitehead    Dundee University
  142. * Mario Palencia
  143. * Chris Kennington    University College London
  144. * Brian Robinson
  145. * Dan Shapiro
  146. * Barry Forde        Lancaster University
  147. * Neil Mercer        Lancaster ITEC
  148. * Andrew Cole        Leeds University
  149. * Tim Green        Warwick University
  150. * John Linn        Aberdeen University
  151. * Tom Wilson        UMRCC
  152. * Peter Hearne        Online Computer Supplies Ltd
  153. * Thomas Sippel-Dau    Imperial College
  154. * Icarus Sparry    Bath University
  155. * Ian O'Brien        Central London Polytechnic
  156. * Bob Dixon        Beaumont Hospital Lancaster
  157. * Peter Vince        BBC Telesoftware
  158. * Alan Baker        Viewfax Ramlink
  159. * Peter Vince        BBC Telesoftware
  160. * Mike Brudenell    Newcastle University
  161. *
  162. * and others for comments, contributions and suggestions. Apologies to those
  163. * whose names I have omitted.
  164. *
  165. * The KERMIT protocol is Copyright (C) The Trustees of Columbia University 1987
  166. *
  167. *
  168. * VERSION HISTORY
  169. * ---------------
  170. *
  171. * 1.45 Bug fixed to allow talking to servers when 8-bit-prefix is not in use
  172. *    ASCII version number placed in ROM header
  173. * 1.44 B7 stripped before terminal mode bytes displayed
  174. *    8th-bit-prefixing and quoting done correctly in C and G packets
  175. *    Wildcard search no longer sends sub-directories as files
  176. *    Command screen banner title altered to "BBC Micro Kermit"
  177. *    Password sent correctly in REM CWD
  178. * 1.43    Handles quote char correctly on 8 bit data path
  179. * 1.42 RAM version uses shadow mode on B+ and Master
  180. *    VT52 supported in RAM version on B+ and Master as default
  181. *    Master 128 keypad used in VT52 mode
  182. *    Code added for support of Terminal Extension ROM
  183. *    RAM version ORG moved to $1F00 for ADFS on B and B+
  184. *    DFS 2.24 "close all files" bug avoided
  185. *    VT52 graphics chars set with VDU 23 rather than block move
  186. *    File renaming adjusted for ADFS compatibility
  187. *    ROM header adjusted to be correct on Master
  188. *    Parallel printer no longer forced
  189. *    SET TERMINAL replaces SET VT52 and SET VDU-WIDTH
  190. *    Entry no longer closes all files, allowing !BOOT usage
  191. *    CLOSE command now closes all open files
  192. *    C introduced as explicit synonym for CONNECT
  193. *    Code adjusted to allow *EXEC files to be used cleanly
  194. *    User vectors removed
  195. *    Minor code corrections and compactions made
  196. *    CONTROL-BREAK now exits RAM version
  197. *    RAM version changes restart mode to 7 to stop self-corruption
  198. *    Received EOF(D) and ACK(X/Z) packets correctly handled
  199. *    File name generation uses length to suit current FS
  200. *    OSHWM set to point above RAM version image
  201. *    File name sent by remote can be used untranslated
  202. *    *HELP handling tidied up
  203. *    Code for sending line break rewritten
  204. *    TRANSMIT command allows raw upload of files to host
  205. *    Default timeouts changed to 15 seconds for MULTICS sites
  206. *    Long break function added in terminal mode
  207. *    Talks to servers that don't support I packets
  208. *    Table-size bug in FIX command cleared
  209. *    Sources made compatible with Lancaster 65C02 Assembler
  210. *    OSBYTE 3 calls for printer select/deselect corrected
  211. * 1.33    OS1.20 bug in reverse screen scroll circumvented
  212. *    VT52 ESCAPE codes echoed correctly in half-duplex mode
  213. *    Function keys reset correctly on OS command or EXIT
  214. *    Pad chars ignored before end-of-packet marker
  215. * 1.30    Conditionals added to build RAM-based version
  216. *    All VT52 keypad keys correctly emulated
  217. *    WIDTH command selects 40/80 byte command screen
  218. *    Status line added in 80 character teminal modes
  219. *    Function keys generate strings in terminal and command mode
  220. *    Cursor editing allowed in command mode
  221. *    Compilation facilities enhanced
  222. *    Messages tokenised and improved
  223. *    Command analyser error handling improved
  224. *    Pause key added in terminal mode
  225. *    Cursor edit mode added in terminal handler
  226. *    Code for talking to servers rewritten
  227. *    Init-info packets sent to servers
  228. *    REMOTE command added
  229. *    SET HANDSHAKE added to allow use with IBM systems
  230. *    Code extensively tidied up
  231. *    VT52 graphics characters supported
  232. *    SET RETRIES command added
  233. *    SET LOCAL-ESCAPE removed as obsolete
  234. *    Timer code rewritten
  235. *    File transfers can now be routed to printer
  236. *    Local filenames no longer forced to upper case 
  237. *    Printmaster interaction with events catered for
  238. *    Non-shadow mode selected if run on a B+
  239. * 1.02    CTS/RTS flow control now works
  240. *    FIX command added to save defaults in sideways RAM
  241. *    Help trigger character configurable with SET HELP-TRIGGER
  242. *    SET MUX-WAIT command added
  243. *    Comms routines directed via vectors
  244. *    VDU mode may ignore one specified character
  245. *    LF in terminal mode correctly sent to printer
  246. *    Terminal mode redesigned to use lower 24 lines for VT52
  247. *    *TV done before entering terminal mode, configurably
  248. *    VT52 escape handling tidied up
  249. *    Command tables re-ordered for neater autohelp display
  250. *    Wait-for-XON now does not stop IRQ
  251. *    Wildcard file search now works with NFS
  252. *    Error trapping changed in initialisation phase
  253. *    WAIT and DISPLAY commands added
  254. *    Text colour configurable for terminal mode
  255. *    Improved ways out of TAKE files
  256. *    Number of timeouts displayed
  257. *    Comms not lost when ESCAPE in OS command
  258. * 0.53    Initial release
  259. *
  260. * For up-to-the-minute news on BBC KERMIT see the bulletin files on the
  261. * Lancaster VAX 11/780. Bug reports and news of further releases will
  262. * be maintained there, as well as a total set of all
  263. * known KERMIT implementations. Contact the above for details.
  264. *
  265. ****************************************************************************
  266.  
  267.  
  268.  
  269. ***************************************
  270. *
  271. * MACRO DEFINITIONS
  272. * =================
  273. *
  274. ***************************************
  275.  
  276. * Macro to build entries in command/parameter tables
  277.  
  278.     IF    ADE
  279. CMD    MACRO
  280.     DFB    @1
  281.     ASC    @2
  282.     ENDM    
  283.     ELSE
  284. CMD    MACRO
  285.     DFB    @1
  286.     ASC    '@2'
  287.     ENDM
  288.     FI    
  289.  
  290. * Macro to chain to next source. Note that ADE bugs cause the
  291. * filename to be shown twice when this is used,
  292. * and the technique to fail if NOT in a macro!
  293. * It's OK on the Lancaster assembler.
  294.  
  295. NEXT    MACRO
  296.     IF    ONEDRV
  297.     CHN    @1
  298.     ELSE
  299.     IF    DSDRIVE
  300.     CHN    :2.@1
  301.     ELSE
  302.     CHN    :1.@1
  303.     FI
  304.     FI
  305.     ENDM
  306.  
  307. * Macro to start each file and set list level up
  308. * First parameter must be the last 3 characters of the filename
  309.  
  310. START    MACRO
  311.     IF    LFULL!LST@1&LIST
  312.     LST    ON
  313.     SKP    H
  314.     ELSE
  315.     LST    OFF
  316.     FI
  317.     ENDM
  318.  
  319. * Macro to build table for the high bytes
  320. * of message addresses. This exists as a
  321. * list of message numbers, each being the
  322. * first message in a new page, relative to
  323. * the page message 0 starts in. For
  324. * message n the call will be
  325. *    MTHE    n-1,n
  326.  
  327. MTHE    MACRO
  328.     IF    (<M@2)>(<M@1)
  329.     DFB    @2
  330.     FI
  331.     ENDM
  332.  
  333.  
  334. ***************************************
  335. *
  336. * LISTING CONTROL FLAGS
  337. * =====================
  338. *
  339. * For each file there must be one flag
  340. * of name "LST" followed by the last 3 bytes of
  341. * the filename. If selective listing is
  342. * selected, only those files with flags
  343. * set to 'Y' will be listed. Those with flags
  344. * set to 'N' will not be listed. Global
  345. * listing overrides all flags.
  346. *
  347. ***************************************
  348.  
  349. LSTDEF    EQU    N
  350. LSTWKS    EQU    N
  351. LSTMAI    EQU    N
  352. LSTCPR    EQU    N
  353. LSTCMD    EQU    N
  354. LSTGEN    EQU    N
  355. LSTST1    EQU    N
  356. LSTST2    EQU    N
  357. LSTSHW    EQU    N
  358. LSTREC    EQU    N
  359. LSTSND    EQU    N
  360. LSTCOM    EQU    N
  361. LSTTM1    EQU    N
  362. LSTTM2    EQU    N
  363. LSTPM1    EQU    N
  364. LSTPM2    EQU    N
  365. LSTPM3    EQU    N
  366. LSTFIL    EQU    N
  367. LSTSB1    EQU    N
  368. LSTSB2    EQU    N
  369. LSTSB3    EQU    N
  370. LSTSB4    EQU    N
  371. LSTTX1    EQU    N
  372. LSTTX2    EQU    N
  373.  
  374. LSTXXX    EQU    N    ;for symbol table
  375.  
  376.  
  377.     CHN    BBCDEF
  378. ****** File BBCCMD *************************************************************
  379.     START    CMD
  380. * BBCCMD: Updated 24/06/86 @ 1530
  381.  
  382. ***************************************
  383. *
  384. * RECEIVE
  385. * =======
  386. *
  387. * Waits for remote to give us a file
  388. *
  389. ***************************************
  390.  
  391. RECEIVE EQU    *
  392. *
  393. * Note this is RECEIVE and not GET
  394. *
  395.     LDA    #0
  396.     STA    WORK9
  397. *
  398. * Assume for a bit that no local name is given
  399. *
  400. K1RECV    EQU    *
  401.     LDA    #0
  402.     STA    LFGIVEN    ;assume not there for now
  403.     STA    WAY    ;set direction to RECEIVE
  404. *
  405. * Is destination FILE, MEMORY or PRINTER here?
  406. *
  407.     LDA    DESTIN
  408.     BEQ    REC100    ;j if FILE
  409.     JSR    LFDUMMY    ;else we fake local name
  410.     JMP    REC400    ;and no params allowed
  411. *
  412. * Here destination is FILE, so param 1 is optional local name
  413. *
  414. REC100    LDA    #33    ;select help text
  415.     JSR    GETFN    ;get param and check size
  416.     BCS    REC400    ;j if param not there
  417. *
  418. * User has given a local filename so copy to a buffer, adding a CR at the end
  419. *
  420.     INC    LFGIVEN    ;note local name given    
  421.     LDY    #0
  422. REC200    LDA    (CURPAR),Y ;get a byte
  423.     STA    LFNAME,Y ;store it
  424.     INY
  425.     CPY    CURLEN
  426.     BNE    REC200
  427.     LDA    #$0D    ;add a CR
  428.     STA    LFNAME,Y
  429. *
  430. * Make sure no more params given
  431. *
  432. REC400    JSR    CONFIRM
  433. *
  434. * Now put up the status screen and display the remote filename if we have one
  435. *
  436.     JSR    STATUS    ;also clears counts
  437.     LDA    #49
  438.     JSR    MESS    ;option is 'receive'
  439.     BIT    WORK9    ;are we RECEIVE?
  440.     BPL    REC420    ;j if so - no remote name yet
  441.     JSR    DISRFN    ;else display it
  442. *
  443. * And display the local name if we have one
  444. *
  445. REC420    LDA    LFGIVEN
  446.     BEQ    REC600    ;j if not given
  447.     JSR    DISLFN    ;else display it
  448. *
  449. * Then note no file is yet open
  450. *
  451.     LDA    #0
  452.     STA    FHAND
  453. *
  454. * Now we branch, depending on whether we're RECEIVE or GET
  455. *
  456. REC600    BIT    WORK9
  457.     BPL    REC620    ;j if RECEIVE - we just wait
  458. *
  459. * Here we're a GET command, so we send an R command to the server
  460. *
  461.     LDA    #'R'    ;packet type is R
  462.     JSR    INSCMD    ;prepare server command
  463.     LDA    WORK6    ;and set the real packet data legth up
  464.     STA    TXDLEN    ;as set by GET command processor
  465.     SEC        ;we want an 'I' packet exchange
  466.     JSR    SRV100    ;and fire it
  467.     JMP    REPORT    ;then report success
  468. *
  469. * Now the receive state switcher takes over to do the hard bits
  470. *
  471. REC620    LDA    #'R'    ;initial state is REC_INIT
  472.     JSR    RECSW    ;into the state handler
  473.     JMP    REPORT    ;and report success
  474. *
  475. * Here user gave no filename parameters, so he's not talking to a server.
  476. * The other end will be sending us a S command shortly
  477. *
  478. REC700    JSR    STATUS    ;put up status screen and clear counts
  479.     JMP    REC620    ;and enter state switcher
  480. *
  481. *
  482. * Side entries
  483. * ------------
  484. *
  485. RCVST    EQU    K1RECV
  486.  
  487.  
  488.  
  489. ***************************************
  490. *
  491. * SEND
  492. * ====
  493. *
  494. * Transmits a file to the remote system
  495. *
  496. ***************************************
  497.  
  498. SEND    LDA    #1
  499.     STA    WAY    ;note direction is SEND
  500.     IF    ROM
  501. *
  502. * Is the source FILE or MEMORY here?
  503. *
  504.     LDA    SOURCE
  505.     BEQ    SND020    ;j if FILE
  506. *
  507. * Source is MEMORY, so param 1 is mandatory remote name
  508. *
  509.     JSR    LFDUMMY    ;fake matching local name as <MEMORY>
  510.     LDA    #32    ;select help text
  511.     JSR    GETMPAR    ;get the parameter
  512.     JMP    SND280
  513.     FI
  514. *
  515. * Source is FILE here, so param 1 is mandatory local name
  516. *
  517. SND020    LDA    #33    ;select help text
  518.     JSR    GETMFN    ;get param and check size
  519. *
  520. * We have a name, so copy it to a buffer and add a CR to the end, watching for wildcards
  521. *
  522. SND060    LDY    #0
  523.     STY    WCLEN    ;assume no wildcards
  524. SND100    LDA    (CURPAR),Y ;get a byte
  525.     STA    LFNAME,Y ;note it
  526.     INY
  527.     CMP    #'*'    ;is it a multichar wildcard?
  528.     BEQ    SND110    ;j if it is
  529.     CMP    #'#'    ;is it a singlechar wildcard?
  530.     BNE    SND120    ;j if not
  531. SND110    STY    WCLEN    ;else note position    
  532. SND120    CPY    CURLEN    ;have we reached end?
  533.     BNE    SND100    ;j if not
  534.     LDA    #$0D    ;else add a CR
  535.     STA    LFNAME,Y
  536. *
  537. * Note the length for later use
  538. *
  539.     LDA    CURLEN
  540.     STA    LFNLEN
  541. *
  542. * If name was wildcarded, we'll take another copy for the catalog scanning
  543. * later on
  544. *
  545.     LDY    WCLEN
  546.     BEQ    SND250    ;j if no wildcards
  547. SND190    STA    WCLEN    ;else save length of name
  548.     LDY    #0
  549. SND200    LDA    LFNAME,Y ;else copy over
  550.     STA    WCNAME,Y
  551.     INY
  552.     CPY    WCLEN
  553.     BNE    SND200
  554. *
  555. * Then set up the control block for the OSGBPB call to scan the
  556. * catalog
  557. *
  558.     LDA    #0
  559.     STA    GNXBLK
  560.     STA    GNXBLK+9
  561.     STA    GNXBLK+10
  562.     STA    GNXBLK+11
  563.     STA    GNXBLK+12
  564. *
  565. * And see if we can find at least one file to match the wildcard name
  566. *
  567.     JSR    GNXTFIL
  568.     BCS    SND920    ;j if none - can't do a send
  569. *
  570. * Parameter 2 is optional and is the remote filename
  571. *
  572. SND250    LDA    #32    ;select help text
  573.     JSR    GETFN    ;get param and check size
  574.     BCS    SND400    ;j if absent
  575. *
  576. * Here the user has supplied a remote filename. Copy to our buffer and add a CR
  577. *
  578. SND280    LDY    #0
  579. SND300    LDA    (CURPAR),Y ;get a byte
  580.     STA    RFNAME,Y ;store it
  581.     INY
  582.     CPY    CURLEN
  583.     BNE    SND300
  584.     LDA    #$0D    ;and add a CR
  585.     STA    RFNAME,Y
  586. *
  587. * Then we go to do the display
  588. *
  589.     JSR    CONFIRM    ;no more parameters
  590.     JMP    SND500
  591. *
  592. * Here user didn't give a remote name, so we generate one.
  593. *
  594. SND400    LDY    LFNLEN    ;offset to final CR
  595.     JSR    MKRNAME
  596. *
  597. * Now put up the status screen and display the local filename
  598. *
  599. SND500    JSR    STATUS    ;also clears counts
  600.     LDA    #50
  601.     JSR    MESS    ;option is 'send'
  602.     JSR    DISLFN    ;display local file name
  603. SND520    JSR    DISRFN    ;display remote filename
  604. *
  605. * Now mark no files are open, and delay for the specified period
  606. * to let user set up the other end
  607. *
  608.     LDA    #0
  609.     STA    FHAND    ;no file open
  610.     LDA    #59
  611.     JSR    PRTSST    ;set status to 'pausing'
  612.     LDA    DELAY
  613.     JSR    WAIT    ;and wait a bit
  614. *
  615. * All ready, so off to the state switcher
  616. *        
  617.     JSR    SENDSW    ;into state switcher
  618.     JMP    REPORT    ;report the result
  619. *
  620. * Here no files satisfied the wildcard name
  621. *
  622. SND920    BRK
  623.     DFB    0
  624.     ASC    'No matches'
  625.     DFB    0
  626.  
  627.  
  628. ***************************************
  629. *
  630. * LOGGING
  631. * =======
  632. *
  633. * Starts/stops logging of terminal 
  634. * session
  635. *
  636. ***************************************
  637.  
  638. LOG    EQU    *
  639. *
  640. * First parameter must be ON or OFF
  641. *
  642.     JSR    ONOFPAR    ;get it in
  643.     CMP    #1
  644.     BEQ    LOG500    ;j if it's ON
  645. *
  646. * It's logging OFF, so tidy file if it's open
  647. *
  648.     JSR    CONFIRM    ;check no more parameters given
  649. LOG200    LDY    LHAND    ;get handle of file
  650.     BEQ    LOG900    ;j if not open - null call
  651. *
  652. * Make sure the buffer is written to the file
  653. *
  654.     LDA    LOGCNT    ;get count of bytes in it
  655.     BEQ    LOG400    ;j if buffer empty
  656.     JSR    WLOGB    ;else write to disc
  657. *
  658. * Then close the file
  659. *
  660. LOG400    LDA    #0
  661.     LDY    LHAND    ;else get the handle
  662.     STA    LHAND    ;clear it out
  663.     STA    LOGON    ;clear toggle too
  664.     JMP    OSFIND    ;close the file
  665. *
  666. * Here it's logging ON. Check not already logging
  667. *
  668. LOG500    LDY    LHAND    ;get handle of log file
  669.     BEQ    LOG600    ;j if not logging
  670.     BRK        ;else error
  671.     DFB    0    
  672.     ASC    'Already on'
  673.     DFB    0
  674. *
  675. * Not logging yet. Next parameter must be the file name
  676. *
  677. LOG600    LDA    #107    ;select help text
  678.     JSR    LSTMPAR    ;get param and check no more
  679. *
  680. * And open the file
  681. *
  682.     LDA    #0
  683.     STA    LOGON    ;clear toggle so don't log just yet
  684.     STA    LOGCNT    ;mark buffer empty
  685.     LDA    #$80    ;write mode please
  686.     JSR    OPNCUR    ;open file
  687.     STA    LHAND    ;note the handle
  688. LOG900    RTS
  689.  
  690.  
  691. ***************************************
  692. *
  693. * SAVE
  694. * ====
  695. *
  696. * Writes current SET values to file
  697. *
  698. ***************************************
  699.  
  700. SAVE    EQU    *
  701. *
  702. * First param is file name
  703. *
  704.     LDA    #113    ;select help text
  705.     JSR    LSTMPAR    ;get param and check no more
  706.     LDA    #$80
  707.     JSR    OPNCUR    ;open file for writing
  708. *
  709. * File is open. Write our ID string first
  710. *
  711.     TAY        ;handle into Y
  712.     LDX    #0
  713. SAV200    LDA    SAVID,X    ;get byte
  714.     JSR    OSBPUT    ;write it
  715.     INX
  716.     CPX    #4
  717.     BNE    SAV200    ;j till all done
  718. *
  719. * Then write the parameter block
  720. *
  721.     LDX    #0
  722. SAV300    LDA    DFBASE,X ;get byte
  723.     JSR    OSBPUT    ;write it
  724.     INX
  725.     CPX    #DFSIZE
  726.     BNE    SAV300    ;j till all done
  727. *
  728. * Then close the file and finish
  729. *
  730.     JMP    CLOSEY    ;handle in Y here
  731.  
  732. SAVID    ASC    'KMT'    ;id string for file
  733.     DFB    $00
  734.  
  735.  
  736. ***************************************
  737. *
  738. * LOAD
  739. * ====
  740. *
  741. * Loads SET params from file produced by
  742. * SAVE
  743. *
  744. ***************************************
  745.  
  746. LOAD    EQU    *
  747. *
  748. * First parameter is file name
  749. *
  750.     LDA    #113    ;select help text
  751.     JSR    LSTMPAR    ;get param and check no more
  752.     LDA    #$40
  753.     JSR    OPNCUR    ;open file for reading
  754. *
  755. * File is open. read id to check it's a KERMIT parameter file
  756. *
  757.     TAY        ;handle into Y
  758.     STY    CPTMP0    ;save for later, too
  759.     LDX    #0
  760. LOD200    JSR    OSBGET    ;read byte
  761.     BCS    LOD900    ;j if EOF hit
  762.     CMP    SAVID,X    ;is it what we expect?
  763.     BNE    LOD900    ;j if not
  764.     INX
  765.     CPX    #4
  766.     BNE    LOD200    ;j till 4 bytes checked
  767. *
  768. * File seems OK. Set current values to standard default
  769. * in case we don't like it
  770. *
  771.     JSR    DEFAULT    ;default params
  772. *
  773. * Then read values into the param block
  774. *
  775.     LDX    #0
  776.     LDY    CPTMP0    ;get file handle
  777. LOD300    JSR    OSBGET    ;get a byte
  778.     BCS    LOD600    ;j if EOF
  779.     STA    DFBASE,X ;save in the table
  780.     INX
  781.     CPX    #DFSIZE    ;this version's table full?
  782.     BCC    LOD300    ;j if not - carry on
  783. *
  784. * Read complete, so close file
  785. *
  786. LOD600    JSR    CLOSEY    ;handle in Y here
  787.     IF    RAM
  788. *
  789. * We're the RAM version, so eliminate any nasty values written from
  790. * the ROM version
  791. *
  792.     LDA    DESTIN    ;get data destination
  793.     CMP    #1    ;is it MEMORY?
  794.     BNE    LOD610    ;j if not
  795.     LDA    #0
  796.     STA    DESTIN    ;else change to FILE
  797. LOD610    EQU    *
  798.     FI
  799. *
  800. * Then process the new params to set up dependent values
  801. *
  802.     JMP    DEF500
  803. *
  804. * Here the file isn't a KERMIT parameter file
  805. *
  806. LOD900    JSR    CLOSEY    ;close the file
  807.     BRK        ;and error
  808.     DFB    0
  809.     ASC    'Not parameter file'
  810.     DFB    0
  811.  
  812.  
  813. ***************************************
  814. *
  815. * TAKE
  816. * ====
  817. *
  818. * Switches command input to be a file
  819. *
  820. ***************************************
  821.  
  822. TAKE    EQU    *
  823. *
  824. * Check TAKE file not already open
  825. *
  826.     LDA    TKHAND    ;is TAKE file open?
  827.     BEQ    TAK100    ;j if not
  828.     BRK        ;else error
  829.     DFB    0
  830.     ASC    'Already TAKEing'
  831.     DFB    0
  832. *
  833. * No TAKE file open. Next parameter is mandatory filename
  834. *
  835. TAK100    LDA    #117    ;select help text
  836.     JSR    LSTMPAR    ;get param and check no more
  837. *
  838. * Then open file and set up the handle
  839. *
  840.     LDA    #$40    ;read mode
  841.     JSR    OPNCUR    ;open it
  842.     STA    TKHAND    ;note the handle
  843.     STA    CSOURCE    ;and set it as command source
  844.     RTS
  845.  
  846.  
  847. ***************************************
  848. *
  849. * EXIT
  850. * ====
  851. *
  852. * Quits KERMIT for BASIC
  853. *
  854. ***************************************
  855.  
  856. EXIT    JSR    CONFIRM    ;check no parameters
  857. *
  858. * First we'll put the screen back to normal
  859. *
  860.     BIT    SHADOW    ;do we have shadow capability?
  861.     BPL    EXI200    ;j if not
  862.     LDA    #114
  863.     LDX    ENTSHAD
  864.     JSR    OBX0    ;else put it back as it was on entry
  865. EXI200    LDA    #22
  866.     JSR    OSWRCH    ;then change mode...
  867.     LDA    #7
  868.     JSR    OSWRCH    ;...back to mode 7
  869. *
  870. * Then we'll reset all the other bits and pieces
  871. *
  872.     JSR    ESCON    ;turn ESCAPE on
  873.     JSR    LOSEACIA ;return 6850 to system
  874.     JSR    LOSESYS    ;reset vectors
  875.     IF    RAM
  876.     JSR    NOBINT    ;lose BREAK intercept
  877.     LDA    #$B4
  878.     LDX    OLDHWM
  879.     JSR    OBX0    ;restore original OSHWM value
  880.     FI
  881. *
  882. * And then we can go back to BASIC
  883. *
  884.     LDX    #>BASIC    ;point to command
  885.     LDY    #<BASIC
  886.     JMP    OSCLI    ;do *BASIC
  887.  
  888. BASIC    STR    'B.'
  889.  
  890.  
  891. ***************************************
  892. *
  893. * RESET
  894. * =====
  895. *
  896. * Restores built-in parameter values
  897. *
  898. ***************************************
  899.  
  900. RESET    JSR    CONFIRM    ;check no parameters
  901.     JSR    DEFAULT    ;copy default values to active table
  902.     JMP    ADJTT    ;and adjust terminal type default to suit machine
  903.  
  904.  
  905. ***************************************
  906. *
  907. * DISPLAY
  908. * =======
  909. *
  910. * Displays message on screen
  911. *
  912. ***************************************
  913.  
  914. DISPLAY EQU    *
  915. *
  916. * Are we at end of command line already?
  917. *
  918.     LDA    #132    ;select help text
  919.     JSR    GETPAR    ;j if param - not at end of line
  920.     BCS    DPY900    ;...else no text to display
  921. *
  922. * Use current param pointer as start of text, and display to EOLN
  923. *
  924.     LDY    #0
  925. DPY100    LDA    (CURPAR),Y ;get byte
  926.     JSR    OSASCI    ;display it
  927.     INY
  928.     CMP    #$0D    ;was it CR?
  929.     BNE    DPY100    ;carry on if not
  930. *
  931. * All done
  932. *
  933. DPY900    RTS
  934.  
  935.  
  936.  
  937. ***************************************
  938. *
  939. * WTCMD
  940. * =====
  941. *
  942. * Delays for time or until keypress
  943. *
  944. ***************************************
  945.  
  946. WTCMD    EQU    *
  947. *
  948. * Next (optional) parameter is the wait time
  949. *
  950.     LDA    #130    ;select help text
  951.     JSR    GETPAR    ;look for parameter
  952.     BCS    WCM600    ;j if none there - indefinite wait
  953. *
  954. * Had a param, so wait for keypress or time up
  955. *
  956.     JSR    NUMPAR    ;convert to binary
  957.     JSR    CONFIRM    ;check no more params
  958.     PHA        ;save time
  959.     JSR    WCM800    ;tell user we're waiting
  960.     PLA        ;reget time
  961.     JMP    WAIT    ;and wait...
  962. *
  963. * Here we wait for ever until key is pressed
  964. *
  965. WCM600    JSR    WCM800    ;tell user we're waiting
  966.     JMP    WTKEY    ;and wait...
  967. *
  968. * Routine to tell user we're waiting
  969. *
  970. WCM800    LDA    #131
  971.     JMP    MESS
  972.  
  973.  
  974.     IF    ROM
  975. ***************************************
  976. *
  977. * FIX
  978. * ===
  979. *
  980. * Saves current parameters back to defaults
  981. * block if it is in sideways RAM
  982. *
  983. ***************************************
  984.  
  985. FIX    JSR    CONFIRM    ;check no parameters given
  986. *
  987. * Ask user if he really means it first
  988. *
  989. FIX100    LDA    #147
  990.     JSR    MESS    ;ask for Y/N
  991.     JSR    OSRDCH    ;get reply
  992.     JSR    UPPER    ;force upper case
  993.     PHA        ;save character
  994.     JSR    OSWRCH    ;echo it
  995.     JSR    OSNEWL    ;clear the line
  996.     PLA        ;and reload character
  997.     CMP    #'Y'
  998.     BEQ    FIX300    ;j if he said Y
  999.     CMP    #'N'
  1000.     BNE    FIX100    ;try again if not then N
  1001.     RTS        ;else we abort here
  1002. *
  1003. * User has confirmed. Check defaults block (and us) are in sideways RAM rather than
  1004. * a ROM
  1005. *
  1006. FIX300    LDY    FIXCHK    ;get byte from ROM space
  1007.     INC    FIXCHK    ;increment it
  1008.     INY        ;increment the copy too
  1009.     CPY    FIXCHK    ;both the same then?
  1010.     BEQ    FIX350    ;j if so - it's sideways RAM
  1011.     BRK        ;else we can't write
  1012.     DFB    0
  1013.     ASC    'No RAM'
  1014.     DFB    0
  1015. *
  1016. * All OK, so copy current settings to defaults block
  1017. *
  1018. FIX350    LDY    #DEFCNT-1
  1019. FIX380    LDA    DFBASE,Y
  1020.     STA    DEFTAB,Y
  1021.     DEY
  1022.     BPL    FIX380
  1023. *
  1024. * And finish
  1025. *
  1026.     RTS
  1027. *
  1028. * Test byte to see if we're RAM or ROM
  1029. *
  1030. FIXCHK    DFB    0    ;contents will change if RAM
  1031.     FI
  1032.  
  1033.  
  1034. ***************************************
  1035. *
  1036. * WIDTH
  1037. * =====
  1038. *
  1039. * Sets command-mode screen width
  1040. *
  1041. ***************************************
  1042.  
  1043. WIDTH    EQU    *
  1044.     IF    RAM
  1045.     JSR    CKSHAD    ;BRK if no shadow RAM
  1046.     FI
  1047.     JSR    WIDPAR    ;param is "40" or "80"
  1048.     STA    CWIDTH    ;note the setting
  1049.     LDA    #2    ;set mode to 2 so we'll change command
  1050.     STA    MODE    ;command screen mode in command processor
  1051.     RTS
  1052.  
  1053.  
  1054. ***************************************
  1055. *
  1056. * CLOSE
  1057. * =====
  1058. *
  1059. * Closes all open files
  1060. *
  1061. ***************************************
  1062.  
  1063. CLOSE    JSR    CONFIRM    ;check no parameters
  1064. *
  1065. * First we'll make sure any terminal log file is tidied up
  1066. *
  1067.     JSR    LOG200    
  1068. *
  1069. * Now we do the close. To avoid the bug in "close all files" in
  1070. * DFS 2.24 we close any file we know we're writing to by hand
  1071. *
  1072.     LDY    FHAND    ;transfer file open?
  1073.     BEQ    CLO300    ;j if not
  1074.     LDA    #0
  1075.     STA    FHAND    ;else clear handle
  1076.     JSR    OSFIND    ;and close it
  1077. *
  1078. * Rest of files we know of are read only, so do it the easy way
  1079. *
  1080. CLO300    LDA    #0
  1081.     STA    CSOURCE    ;clear TAKE handle
  1082.     STA    EXECH    ;clear EXEC handle
  1083.     STA    TXHAND    ;clear TRANSMIT handle
  1084.     TAY
  1085.     JMP    OSFIND    ;close all other files
  1086.  
  1087.  
  1088. ***************************************
  1089. *
  1090. * TRANSMIT
  1091. * ========
  1092. *
  1093. * Raw-sends a file to a host in terminal
  1094. * mode
  1095. *
  1096. ***************************************
  1097.  
  1098. TRANSMIT EQU    *
  1099. *
  1100. * Parameter is the file name
  1101. *
  1102.     LDA    #225    ;select help text
  1103.     JSR    LSTMPAR    ;get param and check no more
  1104.     LDA    #$40    ;select read mode
  1105.     JSR    OPNCUR    ;open the file
  1106. *
  1107. * Then set up handle and enter terminal mode. The I/O handlers will
  1108. * automatically read the file as input instead of the keyboard
  1109. *
  1110.     STA    TXHAND
  1111.     JMP    CONNECT
  1112.  
  1113.  
  1114. ***************************************
  1115. *
  1116. * JSR
  1117. * ===
  1118. *
  1119. * Enters user code with a JSR
  1120. *
  1121. ***************************************
  1122.  
  1123. JSRCMD    LDA    #227    ;select help text
  1124.     JSR    LSTMNP    ;get numeric address and check no more
  1125.     JMP    (NUM)    ;then enter user's code
  1126.  
  1127.  
  1128.     CHN    BBCGEN
  1129. ****** File BBCCOM *************************************************************
  1130.     START    COM
  1131. * BBCCOM: Updated 14/05/86 @ 1115
  1132.  
  1133. ***************************************
  1134. *
  1135. * TXBYTE
  1136. * ======
  1137. *
  1138. * Transmits a byte over the RS423 link
  1139. *
  1140. ***************************************
  1141.  
  1142. TXBYTE    PHA        ;save all registers
  1143.     TXA
  1144.     PHA
  1145.     TYA
  1146.     PHA
  1147. *
  1148. * Has transmit been held by an XOFF from the host?
  1149. *
  1150. TXB100    BIT    TXHOLD
  1151.     BMI    TXB100    ;j if so - wait for it to clear
  1152. *
  1153. * Clear to go, so send the byte
  1154. *
  1155.     TSX
  1156.     LDA    $103,X    ;get data byte from stack
  1157.     CLC        ;specify 'wait for TDRE'
  1158.     JSR    IOWRITE    ;and send the byte
  1159. *
  1160. * And that's it
  1161. *
  1162. TXB900    PLA
  1163.     TAY
  1164.     PLA
  1165.     TAX
  1166.     PLA
  1167.     RTS
  1168.  
  1169.  
  1170. ***************************************
  1171. *
  1172. * RXBYTE
  1173. * ======
  1174. *
  1175. * Reads a byte from the comms line or
  1176. * the keyboard
  1177. *
  1178. ***************************************
  1179.  
  1180. RXBYTE    PHA        ;save all registers
  1181.     TXA
  1182.     PHA
  1183.     TYA
  1184.     PHA
  1185. *
  1186. * Are we doing a raw upload of a TRANSMIT file in terminal mode?
  1187. *
  1188.     LDY    TXHAND    ;get TRANSMIT handle
  1189.     BNE    RXB230    ;j if doing raw upload
  1190. *
  1191. * Are we being a 'proper' terminal then?
  1192. *
  1193.     BIT    MODE
  1194.     BPL    RXB100    ;j if we are
  1195. *
  1196. * We're in transfer mode then. Do we want a byte timeout to run?
  1197. *
  1198.     LDA    TIMER    ;else are we using timeout?
  1199.     BEQ    RXB100    ;j if we're not....
  1200.     LDA    RTIME    ;...else get timeout period
  1201.     JSR    STCLCK    ;and start the clock
  1202. *
  1203. * Not doing raw upload, so we service keyboard
  1204. * and comms line. The keyboard has the higher priority
  1205. *
  1206. RXB100    JSR    INKEY    ;do INKEY(0)
  1207.     BCC    RXB350    ;j if we have a keypress
  1208.     JSR    RDCBUF    ;else look at comms input buffer
  1209.     BCS    RXB300    ;j if nothing there
  1210. RXB150    TSX
  1211.     STA    $103,X    ;else set byte to be in A on entry
  1212. RXB200    JMP    TXB900    ;and exit
  1213. *
  1214. * We're doing a raw send of a TRANSMIT file, so we read data from
  1215. * the file and the comms line, with the comms line having priority. We
  1216. * allow ESCAPE to terminate the upload
  1217. *
  1218. RXB230    JSR    INKEY    ;do INKEY(0)
  1219.     BCS    RXB250    ;j if no key is pressed
  1220.     CMP    #$1B    ;is it ESCAPE?
  1221.     BEQ    RXB280    ;j if it is
  1222. RXB250    JSR    RDCBUF    ;else look at comms input buffer
  1223.     BCC    RXB150    ;j if a byte has come in
  1224.     LDY    TXHAND
  1225.     JSR    OSBGET    ;else read the TRANSMIT file
  1226.     BCS    RXB280    ;j if EOF detected
  1227.     JMP    RXB910    ;else handle the byte
  1228. *
  1229. * EOF on TRANSMIT file or ESCAPE, so restore normal terminal operation
  1230. *
  1231. RXB280    JSR    CLTXF    ;close the file
  1232.     JMP    RXB100    ;and start at the top again
  1233. *
  1234. * Here we're in normal terminal or transfer mode, and there is no byte available
  1235. * from anywhere. If we're in transfer mode, see if we've now
  1236. * timed out
  1237. *
  1238. RXB300    LDA    MODE
  1239.     BPL    RXB100    ;j if not transfer mode
  1240.     LDA    TIMER    ;are we timing this?
  1241.     BEQ    RXB100    ;j if not
  1242.     LDA    TICKER    ;else have we timed out?
  1243.     BNE    RXB100    ;j if not
  1244.     LDA    #90
  1245.     JSR    DMESS    ;else log for debugging
  1246.     INC    TMOCNT    ;step count of timeouts
  1247.     BNE    RXB320
  1248.     INC    TMOCNT+1
  1249. RXB320    BIT    MODE    ;do we display it?
  1250.     BVC    RXB340    ;j if generic mode - no display
  1251.     LDA    #19
  1252.     JSR    MESS    ;else position cursor
  1253.     LDX    TMOCNT    ;get the value
  1254.     LDY    TMOCNT+1
  1255.     CLC        ;select 5 digit field
  1256.     JSR    PRDEC    ;and display the value
  1257. RXB340    JMP    RXB800    ;then return C=1
  1258. *
  1259. * Key pressed here. We respond to CR, CTRL-X, CTRL-Z
  1260. * CTRL-D and CTRL-E if not in terminal mode
  1261. *
  1262. RXB350    LDA    MODE
  1263.     CMP    #1
  1264.     BEQ    RXB900    ;j if terminal mode
  1265.     CPX    #$0D
  1266.     BEQ    RXB800    ;j if CR
  1267.     CPX    #CTRLX
  1268.     BEQ    RXB400    ;j if CTRL-X
  1269.     CPX    #CTRLD
  1270.     BEQ    RXB500    ;j if CTRL-D
  1271.     CPX    #CTRLE
  1272.     BEQ    RXB600    ;j if CTRL-E
  1273.     CPX    #CTRLZ
  1274.     BEQ    RXB390    ;j if CTRL-Z
  1275.     JMP    RXB100    ;else ignore the byte
  1276. *
  1277. * Here we had a CTRL-X or CTRL-Z. Note for higher level and carry on
  1278. *
  1279. RXB390    LDA    #%11000000 ;CTRL-Z
  1280.     BMI    RXB450
  1281. RXB400    LDA    #%10000000 ;CTRL-X
  1282. RXB450    STA    TFSTOP
  1283.     BIT    MODE    ;are we in generic mode for server command?
  1284.     BVS    RXB460    ;j if not
  1285.     JMP    RXB100    ;else no display
  1286. RXB460    TXA
  1287.     PHA        ;else save the character
  1288.     LDA    #42
  1289.     JSR    MESS    ;position on screen...
  1290.     LDA    #75
  1291.     JSR    MESS    ;print 'CTRL-'
  1292.     PLA        ;reload character
  1293.     EOR    #%01000000 ;make it character printable
  1294.     JSR    OSWRCH    ;print it
  1295.     JMP    RXB100    ;and carry on
  1296. *
  1297. * CTRL-D here : toggle debug flag if debugging on
  1298. *
  1299. RXB500    LDA    DEBUG
  1300.     BNE    RXB502    ;j if debug is on
  1301.     JMP    RXB100    ;else ignore it
  1302. RXB502    LDA    DEBTOG
  1303.     EOR    #1
  1304.     STA    DEBTOG    ;else toggle the flag
  1305.     JMP    RXB100
  1306. *
  1307. * CTRL-E here : Kick other side with an error packet
  1308. *
  1309. RXB600    BRK
  1310.     DFB    0
  1311.     ASC    'CTRL-E interrupt'
  1312.     DFB    0
  1313. *
  1314. * Here we had keyboard CR or timed out, so abort the read loop
  1315. *
  1316. RXB800    SEC
  1317.     JMP    TXB900
  1318. *
  1319. * Here we're in terminal mode, and we have a keyboard byte
  1320. *
  1321. RXB900    TXA        ;byte into A
  1322. RXB910    SEC        ;return C=1 on exit
  1323.     JMP    RXB150
  1324.  
  1325.  
  1326. ***************************************
  1327. *
  1328. * RDCBUF
  1329. * ======
  1330. *
  1331. * Extracts a character from the comms
  1332. * buffer and applies parity
  1333. *
  1334. ***************************************
  1335.  
  1336. RDCBUF    EQU    *
  1337. *
  1338. * Is anything there to extract?
  1339. *
  1340.     LDA    IOCNT
  1341.     BEQ    RDC900    ;j if not - return fail
  1342. *
  1343. * Data there, so let's take byte under our remove cursor
  1344. *
  1345.     SEI        ;stop input to it
  1346.     LDY    IOOUT    ;get remove pointer
  1347.     LDA    IOBUFF,Y
  1348.     AND    PARMSK    ;apply any parity needed
  1349.     PHA        ;save the data
  1350.     INC    IOOUT    ;step remove pointer
  1351.     DEC    IOCNT    ;decrease count of chars in buffer
  1352. *
  1353. * See if it's appropriate to start the host now
  1354. *
  1355.     LDX    IOSTOP    ;is he stopped at the moment?
  1356.     BEQ    RDC400    ;j if not - carry on
  1357.     LDA    IOCNT    ;else he is stopped, so we ask ourselves...
  1358.     CMP    #IOTHR2+1 ;is buffer empty enough?
  1359.     BCS    RDC400    ;j if not - leave him stopped
  1360.     JSR    HOSTON    ;else  start him
  1361. *
  1362. * We get here if we have a byte to return
  1363. *
  1364. RDC400    PLA        ;get data
  1365.     CLI        ;turn comms buffer on
  1366.     CLC
  1367.     RTS
  1368. *
  1369. * We come here if the buffer was empty
  1370. *
  1371. RDC900    CLI        ;turn comms bufer on
  1372.     SEC        ;and return fail
  1373.     RTS
  1374.  
  1375.  
  1376. ***************************************
  1377. *
  1378. * IRQENT
  1379. * ======
  1380. *
  1381. * Handles receive data interrupts from
  1382. * the 6850 and drives our comms buffer.
  1383. * For ROM version registers must be stacked before
  1384. * we are entered by JMP
  1385. *
  1386. ***************************************
  1387.  
  1388. IRQENT    EQU    *
  1389.     IF    RAM
  1390.     PHA        ;save registers
  1391.     TXA
  1392.     PHA
  1393.     TYA
  1394.     PHA
  1395.     FI
  1396. *
  1397. * Is this a 6850 interrupt?
  1398. *
  1399.     LDA    IOSTAT
  1400.     BPL    IRQ900    ;j if not 6850
  1401.     LSR    A    ;RDRF into carry
  1402.     BCC    IRQ900    ;j if not RDRF
  1403. *
  1404. * RDRF is set. Check for 6850 error (note status is shifted 1 bit right here!)
  1405. *
  1406.     AND    #%00111000 ;isolate error flags
  1407.     BEQ    IRQ200    ;j if no error
  1408.     LDA    IODATA    ;else clear data register too
  1409.     LDA    #'@'
  1410.     JSR    IOR400    ;return a dummy "@" data byte
  1411.     JMP    IRQ300
  1412. *
  1413. * No error, read the byte and insert into our comms buffer under the
  1414. * insert cursor
  1415. *
  1416. IRQ200    JSR    IOREAD
  1417. *
  1418. * Now let's see if we need to stop the host for a bit
  1419. *
  1420. IRQ300    LDA    IOSTOP    ;is he stopped already?
  1421.     BNE    IRQ800    ;j if so - he'll notice it sometime
  1422.     LDA    IOCNT    ;he's not stopped, so we ask...
  1423.     CMP    #IOTHR+1 ;is buffer past threshold now?
  1424.     BCC    IRQ800    ;j if not - let him carry on
  1425.     JSR    HOSTOFF    ;else stop him
  1426.     IF    RAM
  1427. *
  1428. * RAM version now goes to the old IRQ1 vector
  1429. *
  1430. IRQ800    EQU    *
  1431. IRQ900    PLA
  1432.     TAY
  1433.     PLA
  1434.     TAX
  1435.     PLA
  1436.     JMP    (OLDIRQ)
  1437.     ELSE
  1438. *
  1439. * ROM version adjusts stacked registers so A will be zero on exit since we've serviced the IRQ
  1440. *
  1441. IRQ800    LDA    #0    ;stop lower ROMs being given this IRQ as well
  1442.     TSX        ;or speed will be dreadful
  1443.     STA    $103,X
  1444. *
  1445. * All done, so restore registers and finish. The
  1446. * RTS here terminates our sideways ROM processing of
  1447. * "unrecognised IRQ" and goes back to the OS.
  1448. *
  1449. IRQ900    PLA
  1450.     TAY
  1451.     PLA
  1452.     TAX
  1453.     PLA
  1454.     RTS        ;back to OS
  1455.     FI
  1456.  
  1457.  
  1458. ***************************************
  1459. *
  1460. * HOSTON
  1461. * ======
  1462. *
  1463. * Starts the host with either an XON or
  1464. * by bringing RTS low, and clears any
  1465. * flow control the host has exerted
  1466. *
  1467. ***************************************
  1468.  
  1469. HOSTON    LDA    #0
  1470.     STA    TXHOLD    ;clear host's flow control
  1471.     BIT    SCROLL    ;is NOSCROLL set?
  1472.     BMI    HOS350    ;j if so - leave host alone
  1473.     LDA    FLOW    ;get the flow control in use
  1474.     BNE    HOS400    ;j if CTS/RTS
  1475. *
  1476. * We're using XON/XOFF, so send an XON
  1477. *
  1478.     LDA    #XON
  1479.     CLC        ;select 'wait for TDRE'
  1480.     JSR    IOWRITE    ;and send it
  1481. HOS300    LDA    #0
  1482.     STA    IOSTOP    ;note host not now XOFF'd
  1483. HOS350    RTS
  1484. *
  1485. * Here flow control is CTS/RTS, so reset the 6850 to bring rts low
  1486. *
  1487. HOS400    JSR    RAC100    ;reset the 6850 to normal with RTS low
  1488.     JMP    HOS300    ;and note host is started
  1489.  
  1490.  
  1491. ***************************************
  1492. *
  1493. * HOSTOFF
  1494. * =======
  1495. *
  1496. * Stops host with either an XOFF or with
  1497. * rts high
  1498. *
  1499. ***************************************
  1500.  
  1501. HOSTOFF LDA    FLOW    ;get flow control in use
  1502.     BEQ    HOF600    ;j if XON/XOFF
  1503. *
  1504. * We're using CTS/RTS, so put RTS high
  1505. *
  1506.     LDA    PARSET    ;get 6850 setting
  1507.     AND    #%10011111 ;change to rts high
  1508.     ORA    #%01000000
  1509.     TAX
  1510.     JSR    CHACIA    ;reset the 6850
  1511.     JMP    HOF650
  1512. *
  1513. * Here we're using XON/XOFF
  1514. *
  1515. HOF600    LDA    #XOFF    ;else we send an XOFF
  1516.     SEC        ;select 'no wait for TDRE'
  1517.     JSR    IOWRITE    ;and send the XOFF
  1518. HOF650    LDA    #1
  1519.     STA    IOSTOP    ;and note host is now stopped
  1520.     RTS
  1521.  
  1522.  
  1523. ***************************************
  1524. *
  1525. * WTTDRE
  1526. * ======
  1527. *
  1528. * Waits for TDRE on the 6850
  1529. *
  1530. ***************************************
  1531.  
  1532. WTTDRE    LDX    MUXWT    ;get the MUX delay period
  1533.     BEQ    WTT200    ;j if no delay needed
  1534.     LDY    TXBAUD    ;else get TX baud rate
  1535.     JSR    BYTEWT    ;and wait for n byte periods    
  1536. WTT200    LDA    IOSTAT    ;now look at the 6850 status
  1537.     AND    #%00000010 ;is TDRE set (and hence CTS low)?
  1538.     BEQ    WTT200    ;j if not - wait
  1539.     RTS
  1540.  
  1541.  
  1542. ***************************************
  1543. *
  1544. * FLUSH
  1545. * =====
  1546. *
  1547. * Empties comms buffer and ensures host
  1548. * is started
  1549. *
  1550. ***************************************
  1551.  
  1552. FLUSH    PHP        ;save IRQ state
  1553.     CLI        ;stop inward traffic for a moment
  1554. *
  1555. * Reset buffer controls
  1556. *
  1557.     LDA    #0
  1558.     STA    IOCNT    ;chars in buffer
  1559.     STA    IOIN    ;insert pointer
  1560.     STA    IOOUT    ;remove pointer
  1561.     STA    SCROLL    ;clear NOSCROLL setting
  1562. *
  1563. * If host is stopped, we'll start him
  1564. *
  1565.     LDX    IOSTOP
  1566.     BEQ    FLU900    ;j if he's not stopped
  1567.     STA    IOSTOP    ;note he's not any more
  1568.     JSR    RAC100    ;bring rts low regardless of flow control
  1569.     LDA    FLOW    ;are we coing XON/XOFF?
  1570.     BNE    FLU900    ;j if not
  1571.     LDA    #XON
  1572.     STA    IODATA    ;else also send XON, regardless of TDRE
  1573. *
  1574. * And finish
  1575. *
  1576. FLU900    PLP        ;restore old IRQ state
  1577.     RTS
  1578.  
  1579.  
  1580. ***************************************
  1581. *
  1582. * IOREAD
  1583. * ======
  1584. *
  1585. * Gets a data byte from the 6850 and
  1586. * inserts it into the comms buffer,
  1587. * handling XON/XOFF from the host
  1588. *
  1589. ***************************************
  1590.  
  1591. IOREAD    LDA    IODATA    ;read byte
  1592. *
  1593. * If flow control is XON/XOFF, check what the byte is
  1594. *
  1595.     LDY    FLOW
  1596.     BNE    IOR400    ;j if not XON/XOFF
  1597. *
  1598. * We're using XON/XOFF, so check for flow control from the host
  1599. *
  1600.     TAY        ;save input byte
  1601.     AND    #%01111111 ;lose parity setting
  1602.     CMP    #XON
  1603.     BEQ    IOR520    ;j if XON
  1604.     CMP    #XOFF
  1605.     BEQ    IOR500    ;j if XOFF
  1606.     TYA        ;else get original value back
  1607. *
  1608. * Byte is not a control, so put it into the buffer
  1609. *
  1610. IOR400    LDY    IOIN
  1611.     STA    IOBUFF,Y ;store it
  1612.     INC    IOIN    ;step insert pointer
  1613.     INC    IOCNT    ;step count of chars in buffer
  1614.     RTS
  1615. *
  1616. * Host has sent an XOFF, so inhibit the transmit loop
  1617. *
  1618. IOR500    LDA    #$FF
  1619. IOR510    STA    TXHOLD
  1620.     RTS
  1621. *
  1622. * Host has sent an XON, so clear the transmit hold
  1623. *
  1624. IOR520    LDA    #0
  1625.     BEQ    IOR510
  1626.  
  1627.  
  1628. ***************************************
  1629. *
  1630. * IOWRITE
  1631. * =======
  1632. *
  1633. * Writes a data byte to the 6850
  1634. *
  1635. ***************************************
  1636.  
  1637. IOWRITE PHP        ;save "wait on TDRE" flag
  1638. *
  1639. * Apply parity setting to the byte
  1640. *
  1641.     LDX    PARITY    ;get parity setting
  1642.     CPX    #2    ;is it MARK or SPACE?
  1643.     BCS    IOW100    ;j if not - 6850 does it
  1644.     DEX
  1645.     BEQ    IOW050    ;j if it's SPACE
  1646. *
  1647. * Parity wanted is MARK
  1648. *
  1649.     ORA    #%10000000
  1650.     BMI    IOW100
  1651. *
  1652. * Parity is SPACE
  1653. *
  1654. IOW050    AND    #%01111111
  1655. *
  1656. * Save data for a bit, and wait for TDRE if required
  1657. *
  1658. IOW100    PLP        ;get "wait" flag
  1659.     PHA        ;save data
  1660.     BCS    IOW200    ;j if we don't wait
  1661.     JSR    WTTDRE    ;else we wait
  1662. *
  1663. * Now look for RDRF, in case a byte has just come in. We might lose
  1664. * the RDRF interrupt if we write at such a moment
  1665. *
  1666. IOW200    PHP
  1667.     SEI        ;hold IRQ levels
  1668.     LDA    IOSTAT    ;get status byte
  1669.     LSR    A    ;RDRF into carry
  1670.     BCC    IOW300    ;j if no byte come in
  1671. *
  1672. * A byte has just come in, so read and store it. 
  1673. *
  1674.     JSR    IOREAD
  1675. IOW300    PLP        ;restore old IRQ state
  1676. *
  1677. * Now it's safe to send our data byte. If we did get an XOFF on the
  1678. * read above we'll notice it next time round
  1679. *
  1680.     PLA
  1681.     STA    IODATA
  1682. *
  1683. * And finish
  1684. *
  1685.     RTS 
  1686.  
  1687.  
  1688. ***************************************
  1689. *
  1690. * BRKLVL
  1691. * ======
  1692. *
  1693. * Sets 6850 to output a break level
  1694. *
  1695. ***************************************
  1696.  
  1697. BRKLVL    LDA    PARSET    ;get current 6850 setting
  1698.     ORA    #%01100000 ;add "break level" bits
  1699.     TAX
  1700.     JMP    CHACIA    ;and set it up
  1701.  
  1702.  
  1703. ***************************************
  1704. *
  1705. * SHTBRK
  1706. * ======
  1707. *
  1708. * Sends a short line break (240mS or so)
  1709. *
  1710. ***************************************
  1711.  
  1712. SHTBRK    JSR    BRKLVL    ;get 6850 sending break level
  1713.     JSR    TIMBRK    ;delay for 240mS
  1714.     BEQ    RAC100    ;and put 6850 back as it was
  1715.  
  1716.  
  1717. ***************************************
  1718. *
  1719. * LNGBRK
  1720. * ======
  1721. *
  1722. * Sends a long line break (3.5 S or so)
  1723. *
  1724. ***************************************
  1725.  
  1726. LNGBRK    LDA    #15
  1727.     STA    WORK0    ;set counter
  1728.     JSR    BRKLVL    ;get 6850 sending break level
  1729. LBK100    JSR    TIMBRK    ;wait for 240mS or so
  1730.     DEC    WORK0
  1731.     BNE    LBK100    ;keep waiting for about 3.5 S
  1732.     BEQ    RAC100    ;then put 6850 back as it was
  1733.  
  1734.  
  1735. ***************************************
  1736. *
  1737. * TIMBRK
  1738. * ======
  1739. *
  1740. * Waits 240mS while sending line break
  1741. *
  1742. ***************************************
  1743.  
  1744. TIMBRK    LDX    #188
  1745. TBR100    LDY    #0
  1746. TBR200    DEY
  1747.     NOP
  1748.     NOP
  1749.     BNE    TBR200
  1750.     DEX
  1751.     BNE    TBR100
  1752.     RTS
  1753.  
  1754.  
  1755. ***************************************
  1756. *
  1757. * CHACIA
  1758. * ======
  1759. *
  1760. * Writes the 6850 control register
  1761. *
  1762. ***************************************
  1763.  
  1764. CHACIA    LDA    #$9C
  1765.     JMP    OBX0
  1766.  
  1767.  
  1768. ***************************************
  1769. *
  1770. * SETACIA
  1771. * =======
  1772. *
  1773. * Sets 6850 baud rate and parity
  1774. *
  1775. ***************************************
  1776.  
  1777. SETACIA LDA    #7
  1778.     LDX    RXBAUD
  1779.     JSR    OSBYTE    ;set receive rate
  1780.     LDA    #8
  1781.     LDX    TXBAUD
  1782.     JSR    OSBYTE    ;set transmit rate
  1783. RSTACIA LDX    #%00010011
  1784.     JSR    CHACIA    ;master reset
  1785. RAC100    LDX    PARSET
  1786.     JMP    CHACIA    ;set parity, etc
  1787.  
  1788.  
  1789. ***************************************
  1790. *
  1791. * BYTEWT
  1792. * ======
  1793. *
  1794. * Wait [X] byte periods at baud rate [Y]
  1795. *
  1796. ***************************************
  1797.  
  1798. BYTEWT    LDA    BWTTBL,Y ;get 1000 micro second periods per byte
  1799.     STX    WORK7
  1800.     STA    WORK8    ;for this baud rate
  1801.     STA    WORK9
  1802. BWT100    JSR    BWT900    ;wait about 1000 micro seconds
  1803.     DEC    WORK9
  1804.     BPL    BWT100    ;repeat to wait for1 byte period
  1805.     LDA    WORK8    ;refresh counter
  1806.     STA    WORK9
  1807.     DEC    WORK7
  1808.     BPL    BWT100    ;repeat for n byte periods
  1809.     RTS
  1810. *
  1811. * Loop to wait for about 1000 micro seconds
  1812. *
  1813. BWT900    LDX    #10
  1814. BWT905    LDY    #26
  1815. BWT910    LDA    #0
  1816.     DEY
  1817.     BPL    BWT910
  1818.     DEX
  1819.     BPL    BWT905
  1820.     RTS
  1821. *
  1822. * Table of 1000 micro second intervals per byte period
  1823. *
  1824. BWTTBL    DFB    147    ;75 baud
  1825.     DFB    73    ;150
  1826.     DFB    37    ;300
  1827.     DFB    9    ;1200
  1828.     DFB    5    ;2400
  1829.     DFB    2    ;4800
  1830.     DFB    1    ;9600
  1831.  
  1832.  
  1833.     NEXT    BBCTM1
  1834. ****** File BBCCPR *************************************************************
  1835.     START    CPR
  1836. * BBCCPR: Updated 10/01/87 @ 1730
  1837.  
  1838. ***************************************
  1839. *
  1840. * SCANTAB
  1841. * =======
  1842. *
  1843. * Scans a command table for an entry
  1844. *
  1845. ***************************************
  1846.  
  1847. SCENT    EQU    CPTMP0
  1848. SCMTCH    EQU    CPTMP1
  1849. SCRSLT    EQU    CPTMP2
  1850. SCENTL    EQU    CPTMP3
  1851.  
  1852. SCANTAB PHP        ;note abbreviation flag
  1853.     LDY    #0
  1854.     STY    SCENT    ;start entry counter
  1855.     STY    SCMTCH    ;no matches yet
  1856. *
  1857. * Process the next entry. Are we at end of table?
  1858. *
  1859. SCT100    LDA    (CMDTBL),Y ;get length of entry
  1860.     BEQ    SCT800    ;j if at end of table
  1861.     STA    SCENTL    ;else note length
  1862. *
  1863. * Move table pointer to start of the entry and start scan pointer
  1864. *
  1865. SCT200    INC    CMDTBL
  1866.     BNE    SCT220
  1867.     INC    CMDTBL+1
  1868. SCT220    LDY    #0
  1869. *
  1870. * Compare the next two bytes
  1871. *
  1872. SCT240    LDA    (CURPAR),Y ;get from parameter
  1873.     JSR    UPPER    ;force upper case
  1874.     CMP    (CMDTBL),Y ;and compare
  1875.     BNE    SCT600    ;j if mismatch
  1876. *
  1877. * Bytes match, so move on if we can
  1878. *
  1879.     INY        ;step string offset
  1880.     CPY    CURLEN    ;at end of parameter?
  1881.     BEQ    SCT400    ;j if we are
  1882.     CPY    SCENTL    ;at end of entry string?
  1883.     BEQ    SCT600    ;j if so - this is a mismatch
  1884.     BNE    SCT240    ;else keep going
  1885. *
  1886. * We've matched to end of parameter. Are we at end of the table string too?
  1887. *
  1888. SCT400    CPY    SCENTL
  1889.     BEQ    SCT850    ;j if we are - exact match terminates scan
  1890.     PLP        ;else is an abbreviation OK here?
  1891.     PHP
  1892.     BCS    SCT600    ;j if not - mismatch
  1893. *
  1894. * Here we have a match. Make sure it's the first, or it's an error
  1895. *
  1896. SCT500    LDA    SCMTCH    ;get match counter
  1897.     BNE    SCT900    ;j if not the first
  1898.     INC    SCMTCH    ;else count this match
  1899.     LDA    SCENT
  1900.     STA    SCRSLT    ;note the entry number
  1901. *
  1902. * Now we move to the next entry in the table
  1903. *
  1904. SCT600    LDY    #0    ;restart string offset
  1905.     INC    SCENT    ;step entry counter    
  1906.     LDA    CMDTBL    ;add string length to current pointer, which here points
  1907.     CLC        ;the string, not the length byte
  1908.     ADC    SCENTL
  1909.     STA    CMDTBL
  1910.     BCC    SCT100    ;do next entry
  1911.     INC    CMDTBL+1
  1912.     BNE    SCT100    ;do next entry
  1913. *
  1914. * We've done the whole table, and got either no matches or one match
  1915. *
  1916. SCT800    LDA    SCMTCH    ;get match counter
  1917.     BEQ    SCT910    ;j if none - error
  1918.     PLP        ;else tidy the stack
  1919.     LDA    SCRSLT    ;pass match entry no to caller
  1920.     RTS
  1921. *
  1922. * Here we had an exact match so we search no further
  1923. *
  1924. SCT850    PLP        ;tidy the stack
  1925.     LDA    SCENT    ;return entry number
  1926.     RTS
  1927. *
  1928. * Here we had more than one match
  1929. *
  1930. SCT900    LDA    #183    ;select error text
  1931. SCT905    JMP    PARMERR    ;and report
  1932. *
  1933. * Here we had no matches at all
  1934. *
  1935. SCT910    LDA    #184    ;select error text
  1936.     BNE    SCT905    ;and report
  1937.  
  1938.  
  1939. ***************************************
  1940. *
  1941. * PARAM
  1942. * =====
  1943. *
  1944. * Locates the next parameter in a command
  1945. * line
  1946. *
  1947. ***************************************
  1948.  
  1949. PARAM    EQU    *
  1950. *
  1951. * Are we already at EOLN?
  1952. *
  1953.     LDY    CMDPTR    ;scan start offset
  1954.     LDA    CMDBUF,Y ;get command byte
  1955.     CMP    #$0D
  1956.     BEQ    PAR600    ;j if at EOLN
  1957.     DEY
  1958. *
  1959. * Scan for a space or CR as delimiter, or char for autohelp
  1960. *
  1961. PAR200    INY        ;move on a byte
  1962.     LDA    CMDBUF,Y
  1963.     CMP    #$0D
  1964.     BEQ    PAR400    ;j if EOLN
  1965.     CMP    #' '
  1966.     BEQ    PAR220    ;j if space
  1967.     CMP    HLPTRG
  1968.     BNE    PAR200    ;j if not autohelp char
  1969.     JMP    AUTOHLP    ;else do autohelp
  1970. *
  1971. * Here we've found a space. Set up details of the parameter, then move to the next
  1972. *
  1973. PAR220    JSR    PAR800    ;set up details
  1974.     JSR    SPSKIP    ;move to start of nxt
  1975. PAR240    LDA    CURLEN    ;return the length
  1976.     CLC
  1977.     RTS
  1978. *
  1979. * Here the parameter ends in CR
  1980. *
  1981. PAR400    JSR    PAR800    ;set up details
  1982.     JMP    PAR240    
  1983. *
  1984. * Here we were at EOLN on entry, so there's nothing
  1985. *
  1986. PAR600    SEC
  1987.     RTS
  1988. *
  1989. *
  1990. * Routine to set up details of a parameter
  1991. *
  1992. PAR800    TYA        ;offset to delimiter
  1993.     SEC
  1994.     SBC    CMDPTR    ;form the length
  1995.     STA    CURLEN
  1996.     LDA    CMDPTR    ;note offset to start of parameter
  1997.     STA    CURST    ;from strt of whole line
  1998.     LDA    #>CMDBUF ;get start address
  1999.     CLC
  2000.     ADC    CMDPTR
  2001.     STA    CURPAR
  2002.     LDA    #<CMDBUF
  2003.     ADC    #0
  2004.     STA    CURPAR+1
  2005.     STY    CMDPTR    ;update current position
  2006.     RTS
  2007.  
  2008.  
  2009. ***************************************
  2010. *
  2011. * MPARAM
  2012. * ======
  2013. *
  2014. * Locates the next parameter in a
  2015. * command line, erroring if none there
  2016. *
  2017. ***************************************
  2018.  
  2019. MPARAM    JSR    PARAM    ;anything there?
  2020.     BCC    SHL900    ;j if so
  2021. *
  2022. * No parameter, so error. Adjust the input line so we can retype it
  2023. * up to the end, with an added space
  2024. *
  2025.     LDY    CMDPTR    ;pointer to the CR byte
  2026.     LDA    #' '
  2027.     STA    CMDBUF,Y    ;put a space on the end
  2028.     INY
  2029.     STY    CURST    ;adjust place we retype up to
  2030.     LDA    #181    ;then select error text
  2031. MPA900    JMP    PARMERR    ;and report
  2032.  
  2033.  
  2034. ***************************************
  2035. *
  2036. * MALLPAR
  2037. * =======
  2038. *
  2039. * Returns all the rest of the line as
  2040. * next mandatory parameter
  2041. *
  2042. ***************************************
  2043.  
  2044. MALLPAR JSR    GETMPAR    ;find where it starts
  2045. MAP100    LDA    RDLPTR    ;get offset to final CR
  2046.     SEC
  2047.     SBC    CURST
  2048.     SBC    #1    ;calculate length to end of line
  2049.     STA    CURLEN    ;adjust parameter details
  2050.     RTS
  2051.  
  2052.  
  2053. ***************************************
  2054. *
  2055. * CONFIRM
  2056. * =======
  2057. *
  2058. * Checks command line has no excess
  2059. * parameters
  2060. *
  2061. ***************************************
  2062.  
  2063. CONFIRM PHA
  2064.     LDA    #38    ;select help text
  2065.     JSR    GETPAR    ;is parameter there?
  2066.     PLA
  2067.     BCS    SHL900    ;j if not - all OK
  2068.     LDA    #182    ;else select error text
  2069.     BNE    MPA900    ;and report
  2070.  
  2071.  
  2072. ***************************************
  2073. *
  2074. * PARMERR
  2075. * =======
  2076. *
  2077. * Reports parameter validation error and
  2078. * sets up for retyping
  2079. *
  2080. ***************************************
  2081.  
  2082. PARMERR PHA        ;save error text number
  2083.     LDA    #179
  2084.     JSR    MESS    ;say "ERROR"
  2085.     PLA
  2086.     JSR    MESS    ;then output the text
  2087.     JSR    OSNEWL    ;and tidy up
  2088.     JSR    OSNEWL
  2089. *
  2090. * Are we in a TAKE file?
  2091. *
  2092.     LDA    CSOURCE    ;get command source
  2093.     BNE    PER500    ;j if a TAKE file
  2094. *
  2095. * Are we in an EXEC file?
  2096. *
  2097.     JSR    RDEXH
  2098.     BNE    PER500    ;j if we are
  2099. *
  2100. * Command source is not a file, so restart command processor and retype up to the failed parameter
  2101. *
  2102.     LDY    CURST    ;offset to start of it
  2103.     JMP    AHL940    ;and restart
  2104. *
  2105. * We're in a TAKE or EXEC file, so close both and re-enter from the top
  2106. *
  2107. PER500    JSR    KBDSRC
  2108.     JMP    BRK500    ;use BRK code to restart
  2109.  
  2110.  
  2111.  
  2112. ***************************************
  2113. *
  2114. * SETHLP
  2115. * ======
  2116. *
  2117. * Selects the autohelp text for params
  2118. * that don't have tables
  2119. *
  2120. ***************************************
  2121.  
  2122. SETHLP    STA    CMDTBL
  2123.     LDA    #0
  2124.     STA    CMDTBL+1
  2125. SHL900    RTS
  2126.  
  2127.  
  2128. ***************************************
  2129. *
  2130. * SELTAB
  2131. * ======
  2132. *
  2133. * Selects a command table
  2134. *
  2135. ***************************************
  2136.  
  2137. SELTAB    STX    CMDTBL    ;note table base address
  2138.     STY    CMDTBL+1
  2139. *
  2140. * Now get the details from table header
  2141. *
  2142.     LDY    #0
  2143.     LDA    (CMDTBL),Y ;note action table base
  2144.     STA    JMPTBL
  2145.     INY
  2146.     LDA    (CMDTBL),Y
  2147.     STA    JMPTBL+1
  2148. *
  2149. * Then move address to base of the entries
  2150. *
  2151.     LDA    CMDTBL
  2152.     CLC
  2153.     ADC    #2
  2154.     STA    CMDTBL
  2155.     BCC    STB900
  2156.     INC    CMDTBL+1
  2157. *
  2158. * And finish
  2159. *
  2160. STB900    RTS
  2161.  
  2162.  
  2163. ***************************************
  2164. *
  2165. * ACTION
  2166. * ======
  2167. *
  2168. * Enters an action routine
  2169. *
  2170. ***************************************
  2171.  
  2172. ACTION    ASL    A
  2173.     TAY        ;form offset into address list
  2174.     LDA    (JMPTBL),Y ;set up address
  2175.     STA    ACTRTN
  2176.     INY
  2177.     LDA    (JMPTBL),Y
  2178.     STA    ACTRTN+1
  2179.     JMP    (ACTRTN) ;and enter the code
  2180.  
  2181.  
  2182. ***************************************
  2183. *
  2184. * AUTOHLP
  2185. * =======
  2186. *
  2187. * Gives help when user enters help trigger
  2188. * as a command line component
  2189. *
  2190. ***************************************
  2191.  
  2192. AHCLFT    EQU    CPTMP0
  2193. AHENTL    EQU    CPTMP1
  2194.  
  2195. AUTOHLP EQU    *
  2196. *
  2197. * Is this help a table dump or a text?
  2198. *
  2199.     LDA    CMDTBL+1
  2200.     BNE    AHL100    ;j if table dump
  2201.     LDA    CMDTBL    ;get text number
  2202.     JSR    MESS    ;and print it
  2203.     JSR    OSNEWL
  2204.     JMP    AHL920    ;and finish
  2205. *
  2206. * Here we do a table dump of the current command table
  2207. *
  2208. AHL100    LDA    #27
  2209.     JSR    MESS    ;print 'Options are..'
  2210.     JSR    AHL800    ;and start a print line
  2211. *
  2212. * Now sort out the length of the entry pointed by (CMDTBL)
  2213. *
  2214. AHL200    LDY    #0
  2215.     LDA    (CMDTBL),Y ;get string length
  2216.     BEQ    AHL900    ;j if zero - end of table
  2217.     STA    AHENTL    ;else save for later
  2218.     CMP    AHCLFT    ;will it fit on the line?
  2219.     BCC    AHL300    ;j if it will
  2220.     JSR    AHL800    ;else start a new line
  2221. *
  2222. * There's room on the line now, so print the entry
  2223. *
  2224. AHL300    INC    AHENTL    ;add 1 to string length
  2225.     LDY    #1    ;start string pointer    
  2226. AHL320    LDA    (CMDTBL),Y
  2227.     JSR    AHL820    ;print the byte
  2228.     INY
  2229.     CPY    AHENTL    ;at end of string?
  2230.     BNE    AHL320    ;j if not
  2231. *
  2232. * Entry is done, so either tab to next field or start a new line
  2233. *
  2234.     LDA    AHCLFT    ;get space left
  2235.     CMP    #8
  2236.     BEQ    AHL350    ;j if on start of last field
  2237.     BCS    AHL360    ;j if room to tab
  2238. AHL350    JSR    AHL800    ;else start a new line
  2239.     JMP    AHL400
  2240. AHL360    AND    #7    ;get distance to next field start
  2241.     BNE    AHL365    ;j if within a field
  2242.     LDA    #8    ;else move to next
  2243. AHL365    TAY
  2244.     LDA    #' '    ;and spacefill to it
  2245. AHL380    JSR    AHL820
  2246.     DEY
  2247.     BNE    AHL380
  2248. *
  2249. * Step the table pointer to the next entry
  2250. *
  2251. AHL400    LDA    CMDTBL
  2252.     CLC
  2253.     ADC    AHENTL
  2254.     STA    CMDTBL
  2255.     BCC    AHL200
  2256.     INC    CMDTBL+1
  2257.     BNE    AHL200
  2258. *
  2259. * Here we start a new output line
  2260. *
  2261. AHL800    LDY    CSCRLN
  2262.     INY
  2263.     STY    AHCLFT    ;set space left count
  2264.     JMP    OSNEWL
  2265. *
  2266. * Here we print a byte and count it
  2267. *
  2268. AHL820    DEC    AHCLFT
  2269.     JMP    OSWRCH
  2270. *
  2271. * Here it's all done, so tidy up and re-issue the prompt
  2272. *
  2273. AHL900    JSR    OSNEWL
  2274. AHL920    JSR    OSNEWL
  2275.     LDY    CMDPTR    ;set pointer for RDLINE's prompt
  2276. AHL940    LDX    STKHLP    ;wind the stack back
  2277.     TXS
  2278.     JMP    CMDRST    ;and restart command processor
  2279.  
  2280.  
  2281. ***************************************
  2282. *
  2283. * SPSKIP
  2284. * ======
  2285. *
  2286. * Skips to a non-space in the command
  2287. * line
  2288. *
  2289. ***************************************
  2290.  
  2291. SPSKIP    LDA    CMDBUF,Y ;get a byte
  2292.     CMP    #' '
  2293.     BNE    SPS900    ;j if non-space
  2294.     INY
  2295.     BNE    SPSKIP    ;else carry on
  2296. SPS900    STY    CMDPTR    ;note position of non-space
  2297.     RTS
  2298.     
  2299.  
  2300. ***************************************
  2301. *
  2302. * CMDMODE
  2303. * =======
  2304. *
  2305. * This is the routine that processes
  2306. * KERMIT command level
  2307. *
  2308. ***************************************
  2309.  
  2310. CMDMODE EQU    *
  2311. *
  2312. * Fake mode to $02, so first header screen goes out
  2313. *
  2314.     LDA    #$02
  2315.     STA    MODE
  2316. *
  2317. * Set up restart details and take over system
  2318. *
  2319.     TSX
  2320.     JSR    SETCRS    ;set restart details up
  2321.     JSR    GETSYS    ;take control of system
  2322. *
  2323. * Top of loop : note stack position and vector for BRK restart
  2324. * and set the autohelp stack point
  2325. *
  2326. CMO060    CLI        ;make sure IRQ is allowed
  2327.     TSX
  2328.     STX    STKHLP
  2329.     JSR    SETCRS
  2330. CMO100    JSR    GETEV    ;make sure we have event vector still    
  2331. *
  2332. * Make sure cursor is on, and set up function keys to their
  2333. * power on state
  2334. *
  2335.     JSR    CSRON    ;cursor on
  2336.     LDA    #4
  2337.     JSR    OB00    ;cursor keys are edit keys
  2338.     LDX    #>CMOTB1 ;point F key base values list
  2339.     LDY    #<CMOTB1
  2340.     JSR    SETKEY    ;and set them up
  2341.     LDX    #48
  2342.     JSR    SETPAD    ;return Master keypad to normal too
  2343. *
  2344. * Is command screen set up and in the right mode?
  2345. *
  2346.     LDA    MODE
  2347.     BEQ    CMO200    ;j if in command mode and screen up
  2348.     CMP    #%10000000
  2349.     BEQ    CMO200    ;j if in generic mode with screen up
  2350. *
  2351. * No command screen up, so output it
  2352. *
  2353.     LDA    CWIDTH    ;what width do we want?
  2354.     BNE    CMO120    ;j if 40 byte MODE 7 screen
  2355. *
  2356. * We want an 80 byte MODE 3 screen
  2357. *
  2358.     JSR    STMDE3    ;go to mode 3
  2359.     LDY    #79    ;last char on line is 79
  2360.     LDA    #128    ;get header text number
  2361.     LDX    #177    ;and prompt text number
  2362.     BNE    CMO130
  2363. *
  2364. * Here we want a 40 byte MODE 7 screen
  2365. *
  2366. CMO120    LDY    #39    ;last char on line is 39
  2367.     LDA    #110    ;get header text number
  2368.     LDX    #9    ;get prompt text number
  2369. CMO130    STY    CSCRLN    ;note chars on line
  2370.     STX    PMESS    ;note prompt number
  2371.     JSR    MESS    ;and put out the header
  2372. *
  2373. * Then, with the command screen up, ask any TXRs to say hello
  2374. *
  2375.     LDX    #$81
  2376.     JSR    DOKOSB
  2377. *
  2378. * Now note we're in command mode
  2379. *
  2380. CMO200    LDY    #0    ;mode and buffer start to zero
  2381.     STY    MODE
  2382. *
  2383. * Now prompt for a command and read it in
  2384. *
  2385. K1CMD    EQU    *
  2386.     STY    WORK0    ;save buffer start
  2387.     JSR    ESCON    ;make sure ESCAPE is on
  2388.     LDA    CSOURCE    ;get command source
  2389.     BNE    CMO300    ;j if it's from file
  2390. CMO280    LDA    PMESS    ;else get prompt text number
  2391.     JSR    MESS    ;and prompt for input from keyboard
  2392.     LDY    WORK0    ;reload buffer pointer
  2393.     JSR    RDLINE    ;read with echo
  2394.     JMP    CMO380
  2395. CMO300    LDA    TKECHO    ;source is file, so check TAKE echo
  2396.     BNE    CMO280    ;j if echo on
  2397.     JSR    RDLINX    ;else read without echo or prompt
  2398. *
  2399. * A holds first non-space byte, so see what sort of line we got
  2400. *
  2401. CMO380    CMP    #':'
  2402.     BEQ    CMO200    ;j if comment line
  2403.     CMP    #'*'
  2404.     BEQ    CMO400    ;j if it's an OS command
  2405.     CMP    #$0D
  2406.     BEQ    CMO200    ;j if null line
  2407. *
  2408. * It's a KERMIT command. Select the top level
  2409. * command table. We know line is not empty here
  2410. *
  2411.     LDX    #>MAINCMD
  2412.     LDY    #<MAINCMD
  2413.     JSR    GMPAS    ;get command and validate it
  2414.     PHA        ;it's OK so save the command number..
  2415.     JSR    ESCOFF    ;...turn ESCAPE off..
  2416.     PLA        ;get the number back...
  2417.     JSR    ACTION    ;...implement it....
  2418.     JMP    CMO060    ;...back to the top
  2419. *
  2420. * Here it's an OS command, so give it to the CLI
  2421. *
  2422. CMO400    JSR    LOSEACIA ;give up 6850 control
  2423.     JSR    LOSESYS    ;reset standard vectors...
  2424.     JSR    GETBRK    ;...but keep hold of the BRK vector!
  2425.     LDX    #>CMDBUF ;point to the line
  2426.     LDY    #<CMDBUF
  2427.     JSR    OSCLI    ;execute the command
  2428.     JSR    GETACIA    ;retake control of 6850
  2429.     JSR    GETSYS    ;retake vectors
  2430.     JSR    WHATFS    ;see if filing system has changed on us
  2431.     JMP    CMO060    ;and start again
  2432. *
  2433. *
  2434. * Side entries
  2435. * ============
  2436. *
  2437. CMDRST    EQU    K1CMD    ;autohelp re-entry point
  2438.  
  2439. CMOTB1    DFB    1,$80,$90,0 ;F Key base values
  2440.  
  2441.  
  2442. MAINCMD EQU    *
  2443.  
  2444.     DW    MAINJMP ;jump table address
  2445.     CMD    1,'C'
  2446.     CMD    7,'CONNECT'
  2447.     CMD    4,'SHOW'
  2448.     CMD    3,'SET'
  2449.     CMD    4,'SEND'
  2450.     CMD    7,'RECEIVE'
  2451.     CMD    3,'GET'
  2452.     CMD    3,'BYE'
  2453.     CMD    6,'FINISH'
  2454.     CMD    6,'REMOTE'
  2455.     CMD    7,'LOGGING'
  2456.     CMD    4,'LOAD'
  2457.     CMD    4,'SAVE'
  2458.     CMD    4,'TAKE'
  2459.     CMD    4,'EXIT'
  2460.     CMD    5,'RESET'
  2461.     CMD    7,'DISPLAY'
  2462.     CMD    4,'WAIT'
  2463.     CMD    5,'WIDTH'
  2464.     CMD    5,'CLOSE'
  2465.     IF    ROM
  2466.     CMD    3,'FIX'
  2467.     FI
  2468.     CMD    3,'JSR'
  2469.     CMD    8,'TRANSMIT'
  2470.     DFB    0
  2471.  
  2472.  
  2473. MAINJMP EQU    *
  2474.     DW    CONNECT    ;C
  2475.     DW    CONNECT    ;CONNECT
  2476.     DW    SHOW    ;SHOW
  2477.     DW    SET    ;SET
  2478.     DW    SEND    ;SEND
  2479.     DW    RECEIVE    ;RECEIVE
  2480.     DW    GET    ;GET
  2481.     DW    BYE    ;BYE
  2482.     DW    FINISH    ;FINISH
  2483.     DW    REMOTE    ;REMOTE
  2484.     DW    LOG    ;LOGGING
  2485.     DW    LOAD    ;LOAD
  2486.     DW    SAVE    ;SAVE
  2487.     DW    TAKE    ;TAKE
  2488.     DW    EXIT    ;EXIT
  2489.     DW    RESET    ;RESET
  2490.     DW    DISPLAY    ;DISPLAY
  2491.     DW    WTCMD    ;WAIT
  2492.     DW    WIDTH    ;WIDTH
  2493.     DW    CLOSE    ;CLOSE
  2494.     IF    ROM
  2495.     DW    FIX    ;FIX
  2496.     FI
  2497.     DW    JSRCMD    ;JSR
  2498.     DW    TRANSMIT ;TRANSMIT
  2499.  
  2500.  
  2501. ***************************************
  2502. *
  2503. * RDLINE/RDLINEX
  2504. * ==============
  2505. *
  2506. * Reads an input line with echo (RDLINE)
  2507. * or without echo (RDLINX)
  2508. *
  2509. ***************************************
  2510.  
  2511. RDLINE    SEC        ;echo required
  2512.     BCS    RDL050
  2513.  
  2514. RDLINX    CLC        ;echo not required
  2515. RDL050    PHP        ;save echo flag
  2516.     STY    RDLPTR    ;save buffer start offset
  2517. *
  2518. * Do we now re-issue existing buffer contents?
  2519. *
  2520.     LDY    RDLPTR    ;look at supplied offset
  2521.     BEQ    RDL130    ;j if not
  2522.     LDY    #0    ;else we output contents
  2523. RDL100    LDA    CMDBUF,Y
  2524.     JSR    OSWRCH
  2525.     INY
  2526.     CPY    RDLPTR
  2527.     BNE    RDL100
  2528. *
  2529. * Now we can read and stuff up the buffer
  2530. *
  2531. RDL130    LDY    CSOURCE    ;what's the command source?
  2532.     BNE    RDL132    ;j if it's take file
  2533.     JSR    OSRDCH    ;else read keyboard
  2534.     BCC    RDL150    ;j if not ESCAPE
  2535. RDL131    JSR    ACKESC    ;else ACK the condition
  2536.     BRK        ;and BRK
  2537.     DFB    0
  2538.     ASC    'Escape'
  2539.     DFB    0
  2540. *
  2541. * Command source is a TAKE file. We need to poll the ESCAPE bit before we read
  2542. *
  2543. RDL132    JSR    TSTESC    ;BRK if ESCAPE pending
  2544.     LDY    CSOURCE    ;else get TAKE handle
  2545.     JSR    OSBGET    ;and read the file
  2546.     BCC    RDL150    ;j if got a byte
  2547. *
  2548. * End of TAKE file reached, so close it and tack a CR on to what we got
  2549. *
  2550.     JSR    CLTAKE    ;close the file
  2551. RDL140    LDA    #$0D    ;and pretend we read a CR
  2552. *
  2553. * We have a character from somewhere: look for those control characters we allow
  2554. *
  2555. RDL150    AND    #%01111111 ;strip B7 input byte
  2556.     LDY    RDLPTR    ;get buffer pointer
  2557.     CMP    #$0D
  2558.     BEQ    RDL175    ;j if CR
  2559.     CMP    #CTRLU
  2560.     BEQ    RDL700    ;j if CTRL-U
  2561.     CMP    #$7F
  2562.     BEQ    RDL500    ;j if DEL
  2563.     CMP    #CTRLN
  2564.     BEQ    RDL180    ;j if CTRL-N
  2565.     CMP    #CTRLO
  2566.     BEQ    RDL180    ;j if CTRL-O
  2567. *
  2568. * Any other control character is ignored
  2569. *
  2570.     CMP    #32
  2571.     BCC    RDL130    ;j if control character
  2572. *
  2573. * For anything else, we need space in the buffer
  2574. *
  2575.     CPY    #MAXINP-2
  2576.     BEQ    RDL600    ;j if no space there
  2577. *
  2578. * There is room, so enter in buffer, echo if needed and step pointers
  2579. *
  2580. RDL175    STA    CMDBUF,Y
  2581.     INY
  2582.     STY    RDLPTR
  2583. RDL180    PLP
  2584.     PHP        ;get echo flag
  2585.     BCC    RDL187    ;j if echo off
  2586.     JSR    OSASCI    ;else write to screen
  2587. *
  2588. * Was the byte a CR?
  2589. *
  2590. RDL187    CMP    #$0D
  2591.     BEQ    RDL220    ;j if it was
  2592. *
  2593. * Not CR, so look for char which triggers autohelp
  2594. *
  2595.     CMP    HLPTRG    ;is this the help trigger?
  2596.     BNE    RDL130    ;j if not
  2597.     BEQ    RDL140    ;else pretend we read a CR
  2598. *
  2599. * Now we'll scan the line to see what we got
  2600. *
  2601. RDL220    LDY    #0
  2602.     JSR    SPSKIP    ;skip to non-space
  2603.     PLP        ;lose the echo flag from the stack
  2604.     RTS        ;and finish
  2605. *
  2606. * Here user pressed DEL
  2607. *
  2608. RDL500    CPY    #0    ;are we at start of buffer?
  2609.     BEQ    RDL610    ;j if we are
  2610.     DEY        ;else step pointer back
  2611.     STY    RDLPTR    ;and note new value
  2612.     JMP    RDL180    ;and echo DEL to VDU
  2613. *
  2614. * Here buffer is full. Bleep if keyboard input, error if TAKE file
  2615. *
  2616. RDL600    LDY    CSOURCE    ;get commnd source
  2617.     BEQ    RDL610    ;j if keyboard
  2618.     BRK        ;else we error
  2619.     DFB    0
  2620.     ASC    'Line too long'
  2621.     DFB    0
  2622. RDL610    LDA    #7    ;simply bleep if keyboard input
  2623.     BNE    RDL180    
  2624. *
  2625. * Here user pressed CTRL-U to abandon the line
  2626. *
  2627. RDL700    CPY    #0
  2628.     BNE    RDL705    ;j if got some input
  2629.     JMP    RDL130    ;j if line is empty
  2630. RDL705    LDA    #$7F    ;else DEL back to start
  2631. RDL720    JSR    OSWRCH
  2632.     DEY
  2633.     BNE    RDL720
  2634.     STY    RDLPTR
  2635.     JMP    RDL130    ;and start again
  2636.  
  2637.  
  2638.     CHN    BBCCMD
  2639. ****** File BBCDEF *************************************************************
  2640.     START    DEF
  2641. * BBCDEF: Updated 10/05/86 @ 1120
  2642.  
  2643. ***************************************
  2644. *
  2645. * OS ADDRESSES
  2646. * ============
  2647. *
  2648. ***************************************
  2649.  
  2650. OSFIND    EQU    $FFCE
  2651. OSGBPB    EQU    $FFD1
  2652. OSBPUT    EQU    $FFD4
  2653. OSBGET    EQU    $FFD7
  2654. OSARGS    EQU    $FFDA
  2655. OSFILE    EQU    $FFDD
  2656. OSRDCH    EQU    $FFE0
  2657. OSASCI    EQU    $FFE3
  2658. OSNEWL    EQU    $FFE7
  2659. OSWRCH    EQU    $FFEE
  2660. OSWORD    EQU    $FFF1
  2661. OSBYTE    EQU    $FFF4
  2662. OSCLI    EQU    $FFF7
  2663. OSWRSC    EQU    $FFB3
  2664. OSRDSC    EQU    $FFB9
  2665. OSEVEN    EQU    $FFBF
  2666. GSINIT    EQU    $FFC2
  2667. GSREAD    EQU    $FFC5
  2668.  
  2669.  
  2670. **************************************
  2671. *
  2672. * TELETEXT CONTROL CODES
  2673. * ======================
  2674. *
  2675. **************************************
  2676.  
  2677. RED    EQU    129
  2678. GREEN    EQU    130
  2679. YELLOW    EQU    131
  2680. BLUE    EQU    132
  2681. MAGENTA EQU    133
  2682. CYAN    EQU    134
  2683. WHITE    EQU    135
  2684. FLASH    EQU    136
  2685. STEADY    EQU    137
  2686. NORMHT    EQU    140
  2687. DOUBLE    EQU    141
  2688. BLKBG    EQU    156
  2689. NEWBG    EQU    157
  2690.  
  2691.  
  2692. **************************************
  2693. *
  2694. * HARDWARE ADDRESSES ON IO PROCESSOR
  2695. * ==================================
  2696. *
  2697. **************************************
  2698.  
  2699. IOSTAT    EQU    $FE08    ;6850 status register
  2700. IODATA    EQU    $FE09    ;     data register
  2701.  
  2702. UVT1CL    EQU    $FE64    ;User VIA C1 low
  2703. UVT1LL    EQU    $FE64    ;         T1 latch low
  2704. UVT1LH    EQU    $FE65    ;      T1 latch high
  2705. UVACR    EQU    $FE6B    ;      ACR
  2706. UVIFR    EQU    $FE6D    ;      IFR
  2707. UVIER    EQU    $FE6E    ;      IER
  2708.  
  2709.  
  2710. ***************************************
  2711. *
  2712. * COMMS CONTROL
  2713. * =============
  2714. *
  2715. ***************************************
  2716.  
  2717. IOBSIZ    EQU    256    ;size of comms buffer
  2718. IOTHR    EQU    200    ;stop threshold
  2719. IOTHR2    EQU    50    ;go threshold
  2720.  
  2721.  
  2722. ***************************************
  2723. *
  2724. * OS LOCATIONS
  2725. * ============
  2726. *
  2727. ***************************************
  2728.  
  2729. IRQ1V    EQU    $0204    ;IRQ1 vector
  2730. EVENTV    EQU    $0220    ;event vector
  2731. BRKV    EQU    $0202    ;break vector
  2732. USERV    EQU    $0200    ;user vector
  2733. BYTEV    EQU    $020A    ;OSBYTE vector
  2734.  
  2735. WSCPTR    EQU    $D6    ;pointer location used by OSWRSC
  2736. RSCPTR    EQU    $F6    ;pointer location used by OSRDSC
  2737.  
  2738. STDVLEN EQU    $FFB6    ;length of default vector table
  2739. STDVPTR EQU    $FFB7    ;position of the table
  2740.  
  2741.  
  2742. ***************************************
  2743. *
  2744. * MESSAGE SYSTEM TOKENS
  2745. * =====================
  2746. *
  2747. ***************************************
  2748.  
  2749. EOT    EQU    $FF    ;end of text
  2750. TXT    EQU    $FE    ;sub text expansion
  2751. RPT    EQU    $FD    ;multiple character escape
  2752. XCR    EQU    $FC    ;encoded CR byte
  2753. MTXT    EQU    $FB    ;multiple sub text expansion
  2754. MSP    EQU    $FA    ;multiple space
  2755. LIT    EQU    $F9    ;literal escape for next character
  2756.             ;this must be lowest number
  2757.  
  2758.  
  2759. ***************************************
  2760. *
  2761. * PAGE ZERO AREAS
  2762. * ===============
  2763. *
  2764. ***************************************
  2765.  
  2766.     DSECT
  2767.  
  2768.     ORG    $00
  2769.  
  2770. * The first block of entries are fixed
  2771. * in format and position. A TXR may read
  2772. * details from them, but should alter them
  2773. * only with care
  2774.  
  2775. DEFPTR    DW    0    ;address of SET values block
  2776. MODE    DFB    0    ;system mode
  2777. CWIDTH    DFB    0    ;command screen width (0=80,1=40)
  2778. PMESS    DFB    0    ;number of command mode prompt message
  2779. EVECTB    DW    0    ;address of extended vector table
  2780. STKRST    DFB    0    ;stack position for BRK restart
  2781. RESTART DW    0    ;address for BRK restart
  2782. IOIN    DFB    0    ;comms buffer insert pointer
  2783. IOOUT    DFB    0    ;          remove pointer
  2784. IOCNT    DFB    0    ;characters in buffer
  2785. IOSTOP    DFB    0    ;host stopped flag
  2786. TXHOLD    DFB    0    ;transmit stopped by host XOFF
  2787. SCROLL    DFB    0    ;scroll/noscroll status
  2788. PARSET    DFB    0    ;6850 control settings
  2789. PARMSK    DFB    0    ;mask for data parity
  2790. LOGCNT    DFB    0    ;bytes in terminal log buffer
  2791. LHAND    DFB    0    ;handle for logging file
  2792. LOGON    DFB    0    ;logging toggle
  2793. TXHAND    DFB    0    ;handle of TRANSMIT file
  2794. TICKER    DFB    0    ;1 second count down
  2795. TXRACT    DFB    0    ;0=local term;$FF=TXR doing it
  2796. OSTYPE    DFB    0    ;OS type, minus one
  2797. SHADOW    DFB    0    ;flag for shadow RAM in use
  2798. ENTSHAD DFB    0    ;shadow state on entry
  2799. CSOURCE DFB    0    ;command source (0=keyboard, else file handle)
  2800. TKHAND    DFB    0    ;handle of TAKE file
  2801. EXECH    DFB    0    ;handle of EXEC file
  2802. DEBTOG    DFB    0    ;debug toggle
  2803.  
  2804. * Entries from here to $8F contain no
  2805. * permanent data and may be freely used
  2806. * by a TXR for its own purposes. TXRs
  2807. * should use space starting from $8F
  2808. * down to leave a gap for expansion
  2809. * of the fixed section
  2810.  
  2811. PTR0    DW    0    ;general pointers
  2812. PTR1    DW    0
  2813. PTR2    DW    0
  2814. PTR3    DW    0
  2815.  
  2816. WORK0    DFB    0    ;general workspace
  2817. WORK1    DFB    0
  2818. WORK2    DFB    0
  2819. WORK3    DFB    0
  2820. WORK4    DFB    0
  2821. WORK5    DFB    0
  2822. WORK6    DFB    0
  2823. WORK7    DFB    0
  2824. WORK8    DFB    0
  2825. WORK9    DFB    0
  2826.  
  2827. MWORK0    DFB    0    ;message system work space
  2828. MPTR0    DW    0
  2829. MPTR1    DW    0
  2830. MSGPTR    DW    0    ;message system pointer
  2831.  
  2832. CPTMP0    DFB    0    ;command processor workspace
  2833. CPTMP1    DFB    0
  2834. CPTMP2    DFB    0
  2835. CPTMP3    DFB    0
  2836.  
  2837. PENDFLG DFB    0    ;char inject fglag for BUFEMP
  2838. PENDCHR DFB    0    ;char to inject
  2839. EORSEQ    DFB    0    ;EOR processing flag
  2840.  
  2841. FBUFF    DW    0    ;file buffer base pointer
  2842. FBPTR    DW    0    ;file buffer use pointer
  2843.  
  2844. CMDTBL    DW    0    ;command table pointer
  2845. JMPTBL    DW    0    ;action address table base
  2846. CURPAR    DW    0    ;current param pointer
  2847. CURST    DFB    0    ;start offset of current par in whole line
  2848. CSCRLN    DFB    0    ;no of last char in command mode line
  2849.  
  2850. RQUOTE    DFB    0    ;quote he's sending
  2851. EBQCHR    DFB    0    ;8 bit prefix we're using
  2852. EBQFLG    DFB    0    ;flag for using 8 bit prefix
  2853. STATE    DFB    0    ;protocol state
  2854. CHKSUM    DFB    0    ;checksum sent/received
  2855. CSTEMP    DFB    0    ;working checksum
  2856. NXTPAK    DFB    0    ;next-packet number
  2857. NUMTRY    DFB    0    ;retry counters
  2858. OLDTRY    DFB    0
  2859. SMAXD    DFB    0    ;max DATA length I send him
  2860. TFSTOP    DFB    0    ;flag for CTRL/X or CTRL/Z seen
  2861. BKASENT DFB    0    ;flag for ACK/Z ACK/X sent
  2862. WAY    DFB    0    ;transfer direction (0=R, 1=S)
  2863.  
  2864. CSRX    DFB    0    ;X-position of cursor
  2865. CSRY    DFB    0    ;Y-position
  2866. GRMODE    DFB    0    ;VT52 graphics mode flag
  2867. CHARIN    DW    0    ;character disposition vector
  2868. ESCYR    DFB    0    ;row value sent in ESC-Y sequence
  2869. LFSUPP    DFB    0    ;LF suppress flag for line-fold-bug
  2870. PRINTER DFB    0    ;copy-to-printer flag
  2871. VDUCNT    DFB    0    ;countdown to end of line
  2872. TABEND    DFB    0    ;posn of final tab stop in line
  2873. EDCRSR    DFB    0    ;cursor edit/VT52 mode
  2874. STCOPY    DW    0    ;address of status line copy
  2875.  
  2876. RXPTR    DFB    0    ;packet buffer pointers
  2877. TXPTR    DFB    0
  2878. TXDLEN    DFB    0    ;data size of packet to go
  2879. TXTYPE    DFB    0    ;type of packet to go
  2880. LPTYPE    DFB    0    ;type of packet last sent
  2881. PACNUM    DFB    0    ;packet number
  2882. PACTYP    DFB    0    ;    type
  2883. DATLEN    DFB    0    ;    length (DATA part only)
  2884. XSEOLN    DFB    0    ;EOLN I actually send now
  2885. XSPADC    DFB    0    ;pad char actually sending
  2886. XSNPAD    DFB    0    ;count of pads actually sending
  2887.  
  2888. CURLEN    DFB    0    ;size of current parameter
  2889. CMDPTR    DFB    0    ;analyser position in line
  2890. RDLPTR    DFB    0    ;RDLINE prompt pointer
  2891. NUM    DS    5    ;number converter workspace
  2892. ASCNUM    DS    2
  2893. ACTRTN    DW    0    ;address of action routine
  2894.  
  2895. BRKSRC    DFB    0    ;source of BRK (us/error packet)
  2896. STKHLP    DFB    0    ;stack marker for autohelp
  2897. BINWRN    DFB    0    ;flag for non-ASCII warning given
  2898.  
  2899. PKTCNT    DW    0    ;packet count for one file
  2900. RTRCNT    DW    0    ;retry count for one file
  2901. TMOCNT    DW    0    ;timeout count for one file
  2902. FCOUNT    DFB    0    ;files in wildcard group
  2903. KBYTET    DW    0    ;Kbytes transferred in group
  2904. KBYTEC    DW    0    ;Kbytes transferred in current file
  2905. BYTESC    DW    0    ;bytes countdown in current file
  2906.  
  2907.     IF    *>$90
  2908.     STOP    '*** Too much in page 0 ***'
  2909.     FI
  2910.  
  2911.     DEND
  2912.  
  2913.  
  2914.  
  2915. ***************************************
  2916. *
  2917. * KERMIT DEFINES
  2918. * ==============
  2919. *
  2920. ***************************************
  2921.  
  2922. MAXPAK    EQU    92    ;max size of packet DATA part
  2923. KOSBYT    EQU    70    ;OSBYTE call used to talk to TXR
  2924.  
  2925. ***************************************
  2926. *
  2927. * MISCELLANEOUS DEFINES
  2928. * =====================
  2929. *
  2930. ***************************************
  2931.  
  2932. XON    EQU    $11
  2933. XOFF    EQU    $13
  2934. CTRLD    EQU    $04
  2935. CTRLE    EQU    $05
  2936. CTRLN    EQU    $0E
  2937. CTRLO    EQU    $0F
  2938. CTRLU    EQU    $15
  2939. CTRLX    EQU    $18
  2940. CTRLZ    EQU    $1A
  2941.  
  2942. FKEY    EQU    128    ;base codes for function keys
  2943. SFKEY    EQU    FKEY+16
  2944. CFKEY    EQU    SFKEY+16
  2945. CSFKEY    EQU    CFKEY+16
  2946.  
  2947.  
  2948.  
  2949.     CHN    BBCWKS
  2950. ****** File BBCFIL *************************************************************
  2951.     START    FIL
  2952. * BBCFIL : Updated 10/01/87 @ 1730
  2953.  
  2954. ***************************************
  2955. *
  2956. * FOPEN
  2957. * =====
  2958. *
  2959. * Opens a file for read or write
  2960. *
  2961. ***************************************
  2962.  
  2963. FOPEN    PHA        ;save opening mode
  2964.     IF    ROM
  2965. *
  2966. * See if this is a dummy call, with real data being MEMORY
  2967. *
  2968.     CMP    #$80
  2969.     BEQ    FOP100    ;j if writing
  2970.     LDA    SOURCE    ;reading, so check source
  2971.     BPL    FOP110
  2972. FOP100    LDA    DESTIN    ;writing, so check destination
  2973. FOP110    BEQ    FOP120    ;j if FILE
  2974.     PLA        ;else tidy stack
  2975.     RTS        ;and do noting
  2976.     FI
  2977. *
  2978. * This is a real call. Set status display to 'opening file'
  2979. *
  2980. FOP120    LDA    #52
  2981.     JSR    PRTSST
  2982. *
  2983. * Turn on ESCAPE so user can interrupt wait for drive ready (if he's on
  2984. * DNFS, of course)
  2985. *
  2986.     JSR    ESCON
  2987. *
  2988. * Now we try to open the file
  2989. *
  2990.     PLA        ;reget opening mode
  2991.     LDX    #>LFNAME ;point to filename
  2992.     LDY    #<LFNAME
  2993.     JSR    OSFIND    ;open it
  2994.     BEQ    FOP800    ;j if we failed
  2995.     STA    FHAND    ;else save the handle
  2996. *
  2997. * And we can turn ESCAPE off again
  2998. *
  2999.     JSR    ESCOFF
  3000. *
  3001. * Now initialise the file buffer pointers and flags
  3002. *
  3003. FOP500    LDY    #1
  3004.     STY    EOB    ;buffer empty
  3005.     DEY
  3006.     STY    EOF    ;not at EOF
  3007.     LDA    FBUFF
  3008.     STA    FBPTR
  3009.     STA    FBTOP
  3010.     LDA    FBUFF+1
  3011.     STA    FBPTR+1
  3012.     STA    FBTOP+1
  3013.     RTS        ;and finish
  3014. *
  3015. * Here we failed to open the file
  3016. *
  3017. FOP800    JSR    ESCOFF    ;make sure ESCAPE is off
  3018.     BRK        ;then bang
  3019.     DFB    0
  3020.     ASC    'Not found'
  3021.     DFB    0
  3022.  
  3023.  
  3024. ***************************************
  3025. *
  3026. * FWRITE
  3027. * ======
  3028. *
  3029. * Writes from the file buffer to current
  3030. * file
  3031. *
  3032. ***************************************
  3033.  
  3034. FWRITE    PHA        ;save all registers
  3035.     TXA
  3036.     PHA
  3037.     TYA
  3038.     PHA
  3039. *
  3040. * Build most of the OSGBPB block
  3041. *
  3042.     JSR    MKGBPB
  3043. *
  3044. * Calculate data size and put into the block
  3045. *
  3046.     LDA    FBPTR
  3047.     SEC
  3048.     SBC    FBUFF
  3049.     STA    GBPBLK+5
  3050.     LDA    FBPTR+1
  3051.     SBC    FBUFF+1
  3052.     STA    GBPBLK+6
  3053. *
  3054. * Set status display to 'writing disc'
  3055. *
  3056.     LDA    #45
  3057.     JSR    PRTSST
  3058. *
  3059. * And do the write
  3060. *
  3061.     LDA    #2
  3062.     LDX    #>GBPBLK
  3063.     LDY    #<GBPBLK
  3064.     JSR    OSGBPB
  3065. *
  3066. * And finish
  3067. *
  3068.     PLA
  3069.     TAY
  3070.     PLA
  3071.     TAX
  3072.     PLA
  3073.     RTS
  3074.  
  3075.  
  3076. ***************************************
  3077. *
  3078. * FREAD
  3079. * =====
  3080. *
  3081. * Reads from current file into the file
  3082. * buffer
  3083. *
  3084. ***************************************
  3085.  
  3086. FREAD    PHA        ;save all registers
  3087.     TYA
  3088.     PHA
  3089.     TXA
  3090.     PHA
  3091. *
  3092. * Build a partial OSGBPB control block
  3093. *
  3094.     JSR    MKGBPB
  3095. *
  3096. * Specify a read size of the whole buffer
  3097. *
  3098.     LDA    FBSIZE
  3099.     STA    GBPBLK+5
  3100.     LDA    FBSIZE+1
  3101.     STA    GBPBLK+6
  3102. *
  3103. * Set status display to 'reading disc'
  3104. *
  3105.     LDA    #46
  3106.     JSR    PRTSST
  3107. *
  3108. * And do a read from the current file position
  3109. *
  3110.     LDA    #4
  3111.     LDX    #>GBPBLK
  3112.     LDY    #<GBPBLK
  3113.     JSR    OSGBPB
  3114. *
  3115. * Did we hit EOF on the way?
  3116. *
  3117.     BCC    FRD400    ;j if we did not
  3118. *
  3119. * We hit EOF, so note for later and close the file
  3120. *
  3121.     CLC        ;no buffer flush, of course
  3122.     JSR    FCLOSE    ;and close it
  3123.     LDA    #1
  3124.     STA    EOF    ;set flag
  3125. *
  3126. * Now set up the buffer-top pointer
  3127. *
  3128. FRD400    LDA    GBPBLK+1 ;ptr to byte past last one read
  3129.     STA    FBTOP
  3130.     LDA    GBPBLK+2
  3131.     STA    FBTOP+1
  3132. *
  3133. * And set up the buffer remove pointer
  3134. *
  3135.     LDA    FBUFF
  3136.     STA    FBPTR
  3137.     LDA    FBUFF+1
  3138.     STA    FBPTR+1
  3139. *
  3140. * Clear the 'end of buffer' flag
  3141. *
  3142.     LDA    #0
  3143.     STA    EOB
  3144. *
  3145. * And finish
  3146. *
  3147.     PLA
  3148.     TAX
  3149.     PLA
  3150.     TAY
  3151.     PLA
  3152.     RTS
  3153.  
  3154.  
  3155. ***************************************
  3156. *
  3157. * NEWFILE
  3158. * =======
  3159. *
  3160. * Creates a new file for output - although
  3161. * the "file" may be a memory buffer or
  3162. * a printer, unbeknownst to the caller.
  3163. *
  3164. ***************************************
  3165.  
  3166. NEWFILE EQU    *
  3167. *
  3168. * Clear the 'renamed' warning line out
  3169. *
  3170.     LDA    #20
  3171.     JSR    MESS    ;position cursor
  3172.     JSR    SPFILL    ;clear to EOLN
  3173. *
  3174. * Copy the filename the host has sent into the remote filename buffer
  3175. *
  3176.     LDY    DATLEN    ;get packet data length
  3177.     LDA    #$0D
  3178.     STA    RFNAME,Y ;put a CR at the back
  3179.     DEY
  3180.     STY    WORK8    ;save offset to last byte
  3181. NFL200    LDA    RXBUFF,Y ;get byte from packet
  3182.     STA    RFNAME,Y ;move it over
  3183.     DEY
  3184.     BPL    NFL200    ;j till all moved over
  3185. *
  3186. * And display it on the status screen
  3187. *
  3188.     JSR    DISRFN
  3189. *
  3190. * Did user give us an explicit local name for this file?
  3191. *
  3192.     LDA    LFGIVEN
  3193.     BNE    NFL600    ;j if he did
  3194. *
  3195. * No explicit local name, so we have to generate one in some way
  3196. *
  3197.     LDA    FNTYPE    ;get name translation mode
  3198.     BEQ    NFL270    ;j if we translate remote's name
  3199. *
  3200. * Here user has set UNTRANSLATED mode, so we use the name remote has sent us
  3201. * absolutely unchanged
  3202. *
  3203.     LDX    #0    ;copy from remote buffer to local
  3204. NFL260    LDA    RFNAME,X
  3205.     STA    LFNAME,X
  3206.     CMP    #$0D
  3207.     BEQ    NFL450    ;j if CR copied over at end
  3208.     INX
  3209.     BNE    NFL260    ;else carry on    
  3210. *
  3211. * Here user has set NORMAL name handling, so transkate what remote has sent us into
  3212. * an acceptable BBC filename. First work out how long a BBC name can be
  3213. *
  3214. NFL270    LDX    #7    ;assume we're other than ADFS for now
  3215.     LDA    FSNUM    ;get filing system number
  3216.     CMP    #8
  3217.     BNE    NFL290    ;j if not ADFS
  3218.     LDX    #10    ;else adjust length of name
  3219. NFL290    STX    FSNLEN    ;and note it
  3220. *
  3221. * Now let's amend the supplied name
  3222. *
  3223.     LDY    WORK8    ;offset to last byte
  3224. NFL300    LDA    RFNAME,Y ;get byte from name
  3225.     CMP    #'.'
  3226.     BEQ    NFL320    ;j if we find a "."
  3227.     DEY
  3228.     BPL    NFL300    ;j if not off the front yet
  3229.     BMI    NFL400    ;else there's only one component there
  3230. *
  3231. * We've located the "." before the last component. Scan backwards to see if we can
  3232. * find another "."
  3233. *
  3234. NFL320    STY    WORK9    ;note where we are now
  3235. NFL330    DEY        ;step back one byte
  3236.     BMI    NFL400    ;j if now off the front
  3237.     LDA    RFNAME,Y ;else get a byte in
  3238.     CMP    #'.'
  3239.     BNE    NFL330    ;j if it's not a "."
  3240. *
  3241. * Here we've found the start and end of the penultimate or only component,
  3242. * so move up to FSNLEN bytes as the local filename
  3243. *
  3244. NFL400    INY        ;move to first byte of component
  3245.     LDX    #0    ;start byte counter
  3246. NFL410    LDA    RFNAME,Y ;get a byte
  3247.     STA    LFNAME,Y ;and note it
  3248.     INY
  3249.     CPY    WORK9
  3250.     BEQ    NFL430    ;j if that was last byte of component
  3251.     INX
  3252.     CPX    FSNLEN
  3253.     BNE    NFL410    ;j if not had FSNLEN bytes yet
  3254.     DEX        ;else step count back one
  3255. *
  3256. * Add a CR to end of the name
  3257. *
  3258. NFL430    LDA    #$0D
  3259.     INX
  3260.     STA    LFNAME,X ;add a CR
  3261. NFL450    STX    LFNLEN    ;save pointer to the CR
  3262. *
  3263. * Then display the local name for the user
  3264. *
  3265.     JSR    DISLFN
  3266. NFL600    EQU    *
  3267. *
  3268. * If destination is FILE, we now try to actually open the file. If it's
  3269. * MEMORY or PRINTER, we've finished, as there isn't a file to open.
  3270. *
  3271.     LDA    DESTIN    ;get destination flag
  3272.     BNE    NFL900    ;j if not FILE
  3273. *
  3274. * We open a real file here. Does it exist already?
  3275. *
  3276. NFL610    JSR    FPROBE    ;have a look
  3277.     BCS    NFL800    ;j if doen't exist
  3278. *
  3279. * File exists. Do we trample it or change our name?
  3280. *
  3281.     LDA    FWARN    ;get warning flag
  3282.     BEQ    NFL620    ;j if we don't rename
  3283.     LDA    LFGIVEN    ;else did user give explicit local name?
  3284.     BEQ    NFL660    ;no -  we'll rename then
  3285. *
  3286. * Here we don't rename, but delete the existing file
  3287. *
  3288. NFL620    JSR    ODL100    ;delete it
  3289.     JMP    NFL800    ;then recreate it
  3290. *
  3291. * Here we must rename our file to miss the existing one. tell the user this
  3292. *
  3293. NFL660    LDA    #20
  3294.     JSR    MESS    ;position cursor
  3295.     LDA    #104
  3296.     JSR    MESS    ;tell user
  3297. *
  3298. * And try to change the name a bit
  3299. *
  3300. NFL670    DEC    LFNLEN    ;move change pointer back
  3301.     BMI    NFL680    ;j if nothing more we can change
  3302.     LDX    LFNLEN    ;else get pointer
  3303.     LDA    #'+'
  3304.     STA    LFNAME,X ;change character to '+'
  3305.     JSR    DISLFN    ;show him the new name
  3306. *
  3307. * Let's see if we now miss existing files
  3308. *
  3309.     JSR    FPROBE    ;file exist now?
  3310.     BCS    NFL800    ;no - off we go
  3311.     BCC    NFL670    ;ho hum change a bit more then
  3312. *
  3313. * Here we've changed all we can, and still can't form a unique name
  3314. *
  3315. NFL680    BRK
  3316.     DFB    0
  3317.     ASC    "Can't rename"
  3318.     DFB    0
  3319. *
  3320. * Here we can open the file for output
  3321. *
  3322. NFL800    LDA    #$80    ;select write mode
  3323.     JSR    FOPEN    ;open it
  3324. NFL900    RTS        ;and finish
  3325.  
  3326.  
  3327.  
  3328. ***************************************
  3329. *
  3330. * FPROBE
  3331. * ======
  3332. *
  3333. * Checks for file existence
  3334. *
  3335. ***************************************
  3336.  
  3337. FPROBE    LDX    #>LFNAME ;point to name
  3338.     LDY    #<LFNAME
  3339.     LDA    #$40    ;select read mode
  3340.     JSR    OSFIND    ;try an open on the file
  3341.     CMP    #0    ;did it work?
  3342.     BEQ    FPB900    ;no - file doesn't exist
  3343. *
  3344. * File exists, so close it up and return C=0
  3345. *
  3346.     TAY        ;handle into Y
  3347.     JSR    CLOSEY    ;close file
  3348.     CLC
  3349.     RTS
  3350. *
  3351. * File doesn't exists here
  3352. *
  3353. FPB900    SEC
  3354.     RTS
  3355.  
  3356.  
  3357. ***************************************
  3358. *
  3359. * FCLOSE
  3360. * ======
  3361. *
  3362. * Closes the current file
  3363. *
  3364. ***************************************
  3365.  
  3366. FCLOSE    EQU    *
  3367.     LDA    FHAND    ;is a file open?
  3368.     BEQ    FCL900    ;j if not - null call
  3369.     BCC    FCL400    ;j if no flush required
  3370.     JSR    FWRITE    ;else flush the buffer
  3371. *
  3372. * Set status display to 'closing file'
  3373. *
  3374. FCL400    LDA    #53
  3375.     JSR    PRTSST
  3376. *
  3377. * And close it
  3378. *
  3379.     LDA    #0    ;select 'close'
  3380.     LDY    FHAND    ;get the handle
  3381.     STA    FHAND    ;mark file is closed
  3382.     JSR    OSFIND    ;and close the file
  3383. FCL900    RTS
  3384.  
  3385.  
  3386. ***************************************
  3387. *
  3388. * GNXTFIL
  3389. * =======
  3390. *
  3391. * Searches for the next filename to
  3392. * match a wildcarded specification
  3393. *
  3394. ***************************************
  3395.  
  3396. GNXTFIL EQU    *
  3397. *
  3398. * Set up a block to use on OSFILE calls to find file type
  3399. *
  3400.     LDA    #>LFNAME ;just set up name pointer
  3401.     STA    GBPBLK
  3402.     LDA    #<LFNAME
  3403.     STA    GBPBLK+1
  3404. *
  3405. * Set up transfer address in our OSGBPB block
  3406. * And request one file name
  3407. *
  3408. GNX100    LDA    #>LFNLEN ;address
  3409.     STA    GNXBLK+1
  3410.     LDA    #<LFNLEN
  3411.     STA    GNXBLK+2
  3412.     LDY    #$FF
  3413.     STY    GNXBLK+3
  3414.     STY    GNXBLK+4
  3415.     INY
  3416.     STY    GNXBLK+6 ;one name wanted
  3417.     STY    GNXBLK+7
  3418.     STY    GNXBLK+8
  3419.     INY
  3420.     STY    GNXBLK+5
  3421. *
  3422. * Then see if there's another name. We check this by testing the
  3423. * 'names NOT transferred' count, since NFS does not return C=1 if no names are
  3424. * passed back, contrary to what the manulas imply.
  3425. *
  3426.     LDA    #8
  3427.     LDX    #>GNXBLK
  3428.     LDY    #<GNXBLK
  3429.     JSR    OSGBPB
  3430.     CMP    #0    ;does filing system support this call?
  3431.     BNE    GNX900    ;j if it doesn't
  3432.     LDA    GNXBLK+5 ;get count of names NOT transferred
  3433.     BEQ    GNX200    ;j if we did get one
  3434. *
  3435. * No more names, so return 'fail'
  3436. *
  3437.     SEC
  3438.     RTS
  3439. *
  3440. * We have another name. Adjust its length to remove trailing spaces
  3441. *
  3442. GNX200    LDY    LFNLEN    ;length returned in call
  3443. GNX220    LDA    LFNAME-1,Y ;get a byte
  3444.     CMP    #' '
  3445.     BNE    GNX240    ;j if byte not a space
  3446.     DEY
  3447.     BNE    GNX220
  3448. GNX240    STY    LFNLEN    ;note adjusted length
  3449. *
  3450. * Add a CR to the end in case we use this name
  3451. *
  3452.     LDA    #$0D
  3453.     STA    LFNAME,Y
  3454. *
  3455. * Start the scan pointers
  3456. *
  3457.     LDX    #0    ;wildcarded name
  3458.     LDY    #0    ;file name
  3459. *
  3460. * Get byte from wildcard name and see if it's a "*"
  3461. *
  3462. GNX250    LDA    WCNAME,Y
  3463.     CMP    #'*'
  3464.     BEQ    GNX500    ;j if it is a *
  3465. *
  3466. * Not a * wildcard, so see if it matches the filename. We allow
  3467. * a # wildcard to match one byte here
  3468. *
  3469.     CPX    LFNLEN    ;at end of filename?
  3470.     BEQ    GNX100    ;j if so - no match
  3471.     CMP    #'#'    ;is wildcard name byte a "#"?
  3472.     BEQ    GNX300    ;j if so - automatic match
  3473.     EOR    LFNAME,X ;else compare bytes
  3474.     AND    #%11011111 ;lose difference in case of chars
  3475.     BNE    GNX100    ;j if mismatch
  3476. *
  3477. * Bytes match, so move on and see if that's the lot
  3478. *
  3479. GNX300    INX
  3480.     INY
  3481.     CPY    WCLEN    ;at end of wildcard name?
  3482.     BNE    GNX250    ;j if not - keep going
  3483.     CPX    LFNLEN    ;at end of filename too?
  3484.     BNE    GNX100    ;j if not - mismatch
  3485. *
  3486. * We have a match, so see if it's a file or directory
  3487. *
  3488. GNX400    LDA    #5    ;select "read cat details"
  3489.     LDX    #>GBPBLK ;point control block
  3490.     LDY    #<GBPBLK
  3491.     JSR    OSFILE    ;file type now in A
  3492.     CMP    #1    ;is it a file?
  3493.     BNE    GNX100    ;j if not - ignore the entry
  3494. *
  3495. * We have a matching file, so display the local name
  3496. *
  3497.     JSR    DISLFN
  3498. *
  3499. * Then generate and display a remote name
  3500. *
  3501.     LDY    LFNLEN    ;get length of local name
  3502.     JSR    MKRNAME
  3503.     JSR    DISRFN
  3504. *
  3505. * And return success
  3506. *
  3507.     CLC
  3508. GNX480    RTS
  3509. *
  3510. * Here we met a wildcard in the wildcard name. Move to a non-wildcard
  3511. * in this name
  3512. *
  3513. GNX500    INY
  3514.     CPY    WCLEN    ;at end of wildcard name?
  3515.     BEQ    GNX400    ;j if so - match
  3516.     CMP    WCNAME,Y ;is next byte a "*"
  3517.     BEQ    GNX500    ;j if so - keep looking
  3518. *
  3519. * We've come to a non-wildcard now, so try to find this in
  3520. * the filename
  3521. *
  3522. GNX550    CPX    LFNLEN    ;at end of filename?
  3523.     BNE    GNX555    ;j if not - keep going
  3524.     JMP    GNX100    ;else it's a mismatch
  3525. GNX555    LDA    WCNAME,Y
  3526.     CMP    LFNAME,X ;else compare bytes
  3527.     BEQ    GNX300    ;j if they're the same
  3528.     INX
  3529.     BNE    GNX550    ;else keep looking
  3530. *
  3531. * Here the filing system does not support the OSGBPB call to
  3532. * read the directory
  3533. *
  3534. GNX900    BRK
  3535.     DFB    0
  3536.     ASC    'Cat scan not supported'
  3537.     DFB    0
  3538.  
  3539.  
  3540. ***************************************
  3541. *
  3542. * OPTDEL
  3543. * ======
  3544. *
  3545. * Deletes incoming file if incomplete
  3546. * and option is DELETE
  3547. *
  3548. ***************************************
  3549.  
  3550. OPTDEL    LDA    DESTIN    ;check current destination
  3551.     BNE    OCR900    ;j if not FILE
  3552.     LDA    FINCOM    ;else check the option
  3553.     BNE    GNX480    ;j if it's KEEP
  3554. *
  3555. * We do need to delete. Build a partial OSFILE block using the
  3556. * OSGBPB block as a handy place.
  3557. *
  3558. ODL100    LDA    #>LFNAME
  3559.     STA    GBPBLK
  3560.     LDA    #<LFNAME
  3561.     STA    GBPBLK+1
  3562. *
  3563. * And delete the file
  3564. *
  3565.     LDA    #6    ;delete action
  3566.     LDX    #>GBPBLK ;pointer to block
  3567.     LDY    #<GBPBLK
  3568.     JMP    OSFILE    ;delete the file
  3569.  
  3570.  
  3571. ***************************************
  3572. *
  3573. * OPNCUR
  3574. * ======
  3575. *
  3576. * Opens file whose name is current 
  3577. * command parameter
  3578. *
  3579. ***************************************
  3580.  
  3581. OPNCUR    STA    WORK5    ;save opening mode
  3582.     JSR    ESCON    ;allow ESCAPE to work
  3583. *
  3584. * Make sure name terminates with a CR
  3585. *
  3586.     LDY    CURLEN
  3587.     LDA    (CURPAR),Y ;get char past name
  3588.     PHA        ;save it
  3589.     LDA    #$0D
  3590.     STA    (CURPAR),Y ;change for a CR
  3591.     LDA    WORK5    ;get opening mode
  3592.     LDX    CURPAR    ;point to name
  3593.     LDY    CURPAR+1
  3594.     JSR    OSFIND    ;try to open the file
  3595. *
  3596. * Did it work?
  3597. *
  3598.     CMP    #0
  3599.     BNE    OCR600    ;j if it did
  3600.     JMP    FOP800    ;else break
  3601. *
  3602. * File is open, so restore command line to original
  3603. *
  3604. OCR600    STA    WORK5    ;save handle
  3605.     PLA        ;get trampled characer
  3606.     LDY    CURLEN
  3607.     STA    (CURPAR),Y ;put it back
  3608.     JSR    ESCOFF    ;turn ESCAPE off again
  3609.     LDA    WORK5    ;reload handle
  3610. OCR900    RTS        ;and finish
  3611.  
  3612.  
  3613.     NEXT    BBCSB1
  3614. ****** File BBCGEN *************************************************************
  3615.     START    GEN
  3616. * BBCGEN : Updated 28/01/87 @ 2020
  3617.  
  3618. ***************************************
  3619. *
  3620. * GET
  3621. * ===
  3622. *
  3623. * Pulls a file from a server
  3624. *
  3625. ***************************************
  3626.  
  3627. GET    EQU    *
  3628. *
  3629. * Parameter 1 is mandatory, and is the remote filename
  3630. *
  3631.     LDA    #32    ;select help text
  3632.     JSR    GETMFN    ;get param and check size
  3633. *
  3634. * Copy the filename to our buffer, and also build an R packet
  3635. *
  3636.     LDY    #0
  3637. GET100    LDA    (CURPAR),Y ;get a byte
  3638.     STA    RFNAME,Y ;into our buffer
  3639.     STA    SCBUFF,Y ;into the server command buffer
  3640.     INY
  3641.     CPY    CURLEN
  3642.     BNE    GET100    ;j till all moved
  3643. *
  3644. * Add a CR to the end of our copy
  3645. *
  3646.     LDA    #$0D
  3647.     STA    RFNAME,Y
  3648.     STY    WORK6    ;note size of packet data for later
  3649. *
  3650. * Note we're GET and not RECEIVE, and side enter the receive command code
  3651. *
  3652.     LDA    #$FF
  3653.     STA    WORK9
  3654.     JMP    RCVST
  3655.  
  3656.  
  3657. ***************************************
  3658. *
  3659. * BYE
  3660. * ===
  3661. *
  3662. * Sends a GL command to a server
  3663. *
  3664. ***************************************
  3665.  
  3666. BYE    JSR    CONFIRM    ;check no more parameters
  3667.     LDX    #'L'    ;command is 'L'
  3668. BYE100    LDA    #'G'    ;packet type is 'G'
  3669.     JSR    INSCMD    ;prepare command packet
  3670.     CLC        ;we don't want an I packet
  3671.     JMP    SRVCMD    ;and into state switcher
  3672.  
  3673.  
  3674. ***************************************
  3675. *
  3676. * FINISH
  3677. * ======
  3678. *
  3679. * Sends a GF command to a server
  3680. *
  3681. ***************************************
  3682.  
  3683. FINISH    JSR    CONFIRM    ;check no more parameters
  3684.     LDX    #'F'    ;command is 'F'
  3685.     BNE    BYE100
  3686.  
  3687.  
  3688. ***************************************
  3689. *
  3690. * REMOTE
  3691. * ======
  3692. *
  3693. * Handles the REMOTE command
  3694. *
  3695. ***************************************
  3696.  
  3697. REMOTE    LDX    #>REMOPT ;point to option table
  3698.     LDY    #<REMOPT
  3699.     JSR    GMPAS    ;get parameter and validate
  3700.     JMP    ACTION    ;and implement it
  3701.  
  3702. REMOPT    DW    REMJMP    ;address of jump table
  3703.     CMD    9,'DIRECTORY'
  3704.     CMD    3,'CWD'
  3705.     CMD    5,'SPACE'
  3706.     CMD    6,'DELETE'
  3707.     CMD    4,'TYPE'
  3708.     CMD    4,'HELP'
  3709.     CMD    4,'COPY'
  3710.     CMD    6,'RENAME'
  3711.     CMD    3,'WHO'
  3712.     CMD    4,'HOST'
  3713.     CMD    6,'STATUS'
  3714.     DFB    0
  3715.  
  3716. REMJMP    DW    RMDIR    ;DIRECTORY
  3717.     DW    RMCWD    ;CWD
  3718.     DW    RMSPACE    ;SPACE
  3719.     DW    RMDEL    ;DELETE
  3720.     DW    RMTYPE    ;TYPE
  3721.     DW    RMHELP    ;HELP
  3722.     DW    RMCOPY    ;COPY
  3723.     DW    RMREN    ;RENAME
  3724.     DW    RMWHO    ;WHO
  3725.     DW    RMHOST    ;HOST
  3726.     DW    RMSTAT    ;STATUS
  3727.  
  3728.  
  3729. ***************************************
  3730. *
  3731. * REMOTE WHO
  3732. * ==========
  3733. *
  3734. ***************************************
  3735.  
  3736. RMWHO    JSR    CONFIRM    ;check no more parameters
  3737.     LDX    #'W'    ;command is W
  3738. RWH100    LDA    #'G'    ;packet type is G
  3739.     JSR    INSCMD    ;prepare to send it
  3740.     SEC        ;I packet wanted
  3741.     JMP    SRVCMD    ;and into state switcher
  3742.  
  3743.  
  3744. ***************************************
  3745. *
  3746. * REMOTE STATUS
  3747. * =============
  3748. *
  3749. ***************************************
  3750.  
  3751. RMSTAT    JSR    CONFIRM    ;check no more parameters
  3752.     LDX    #'Q'    ;command is Q
  3753.     BNE    RWH100
  3754.  
  3755.  
  3756. ***************************************
  3757. *
  3758. * REMOTE HELP
  3759. * ===========
  3760. *
  3761. ***************************************
  3762.  
  3763. RMHELP    LDX    #'H'    ;command is H
  3764.     LDA    #'G'    ;packet type G
  3765.     JSR    INSCMD    ;prepare the packet
  3766. *
  3767. * We pass on the rest of the command line as the help argument
  3768. *
  3769.     LDA    #165    ;select help text
  3770.     JSR    GETPAR    ;see if there's a parameter
  3771.     BCS    RDR240    ;j if not
  3772.     JSR    MAP100    ;else take all of rest of line as value
  3773.     JMP    RDR200
  3774.  
  3775.  
  3776. ***************************************
  3777. *
  3778. * REMOTE DIRECTORY 
  3779. * ================
  3780. *
  3781. ***************************************
  3782.  
  3783. RMDIR    LDA    #'G'    ;packet type is G
  3784.     LDX    #'D'    ;command is D
  3785.     JSR    INSCMD    ;initialise the packet
  3786. *
  3787. * Optional parameter is a filespec
  3788. *
  3789.     LDA    #161    ;select help text
  3790. RDR100    JSR    LSTPAR    ;get param, check no more
  3791.     BCS    RDR240    ;j if no parameter
  3792. *
  3793. * Put parameter into the packet and send it
  3794. *
  3795. RDR200    JSR    PAKPRL
  3796. RDR230    SEC        ;request an I packet
  3797. RDR240    JMP    SRVCMD
  3798.  
  3799.  
  3800. ***************************************
  3801. *
  3802. * REMOTE CWD
  3803. * ==========
  3804. *
  3805. ***************************************
  3806.  
  3807. RMCWD    LDA    #'G'    ;packet type is G
  3808.     LDX    #'C'    ;command is C
  3809.     JSR    INSCMD    ;initialise the buffer
  3810. *
  3811. * Next parameter is optional directory name
  3812. *
  3813.     LDA    #197    ;select help text
  3814.     JSR    LSTPAR    ;look for param and check no more
  3815.     BCS    RCW500    ;j if no parameter there
  3816.     JSR    PAKPRL    ;else put into buffer
  3817. *
  3818. * User gave directory, so ask him for the password
  3819. *
  3820.     LDA    #204
  3821.     JSR    MESS    ;prompt him
  3822.     LDA    #0    ;force source to keyboard
  3823.     STA    CSOURCE
  3824.     TAY        ;set buffer pointer up
  3825.     JSR    RDLINX    ;read password without echoing
  3826.     JSR    OSNEWL    ;tidy the line up
  3827.     LDA    TKHAND    ;get TAKE handle or 0
  3828.     STA    CSOURCE    ;and restore command source
  3829. *
  3830. * Adjust things so the analyser thinks the inout line is one parameter
  3831. *
  3832.     LDA    #0
  3833.     STA    CURST    ;start offset pf param is 0
  3834.     LDA    #>CMDBUF ;set up start of parameter string
  3835.     STA    CURPAR
  3836.     LDA    #<CMDBUF
  3837.     STA    CURPAR+1
  3838.     JSR    MAP100    ;set up length to be whole line
  3839.     JMP    RDR200    ;and send it
  3840. *
  3841. * No directory, so don't ask for password
  3842. *
  3843. RCW500    SEC        ;I packet wanted
  3844.     JMP    SRVCMD
  3845.  
  3846.  
  3847. ***************************************
  3848. *
  3849. * REMOTE DELETE
  3850. * =============
  3851. *
  3852. ***************************************
  3853.  
  3854. RMDEL    LDX    #'E'    ;command is E
  3855. RDE100    LDA    #'G'    ;packet type is G
  3856.     JSR    INSCMD    ;prepare the packet
  3857. *
  3858. * Next parameter is the file name
  3859. *
  3860.     LDA    #32    ;select help text
  3861. RDE200    JSR    LSTMPAR    ;get param, check no more
  3862.     JMP    RDR200    ;then handle it
  3863.  
  3864.  
  3865. ***************************************
  3866. *
  3867. * REMOTE TYPE
  3868. * ===========
  3869. *
  3870. ***************************************
  3871.  
  3872. RMTYPE    LDX    #'T'    ;command is T
  3873.     BNE    RDE100
  3874.  
  3875.  
  3876. ***************************************
  3877. *
  3878. * REMOTE RENAME
  3879. * =============
  3880. *
  3881. ***************************************
  3882.  
  3883. RMREN    LDX    #'R'    ;command is R
  3884. RRN100    LDA    #'G'    ;packet type is G
  3885.     JSR    INSCMD    ;initialise packet
  3886. *
  3887. * First parameter is the old filename
  3888. *
  3889.     LDA    #162    ;select help text
  3890.     JSR    GETMPAR    ;get the parameter
  3891.     JSR    PAKPRL    ;put it into the packet
  3892. *
  3893. * Next parameter is the new filename
  3894. *
  3895.     LDA    #164    ;select help text
  3896.     BNE    RDE200    ;share code with REMOTE DELETE
  3897.  
  3898.  
  3899. ***************************************
  3900. *
  3901. * REMOTE COPY
  3902. * ===========
  3903. *
  3904. ***************************************
  3905.  
  3906. RMCOPY    LDX    #'K'    ;command is K
  3907.     BNE    RRN100
  3908.  
  3909.  
  3910. ***************************************
  3911. *
  3912. * REMOTE HOST
  3913. * ===========
  3914. *
  3915. ***************************************
  3916.  
  3917. RMHOST    LDA    #'C'    ;packet type is C
  3918.     JSR    INSCMD    ;initialise the packet
  3919.     LDA    #166    ;select help text
  3920.     JSR    MALLPAR    ;get rest of line as parameter
  3921.     JSR    PAKPAR    ;packet it with no length encoding
  3922.     JMP    RDR230    ;and send it
  3923.  
  3924.  
  3925. ***************************************
  3926. *
  3927. * REMOTE SPACE
  3928. * ============
  3929. *
  3930. ***************************************
  3931.  
  3932. RMSPACE LDA    #'G'    ;packet type is 'G'
  3933.     LDX    #'U'    ;command is U
  3934.     JSR    INSCMD    ;initialise packet
  3935.     LDA    #168    ;select help text
  3936.     JMP    RDR100    ;then act as REMOTE DIR
  3937.  
  3938.  
  3939. ***************************************
  3940. *
  3941. * INSCMD
  3942. * ======
  3943. *
  3944. * Initialises server command buffer, etc, for a
  3945. * server command packet of type A with command
  3946. * X
  3947. *
  3948. ***************************************
  3949.  
  3950. INSCMD    STA    TXTYPE    ;save packet type
  3951.     LDY    #0
  3952.     STY    TXPTR    ;start buffer pointer
  3953.     STY    TXDLEN    ;start packet data length
  3954.     CMP    #'G'    ;is packet type G?
  3955.     BNE    ICD900    ;j if not
  3956.     TXA
  3957.     STA    SCBUFF,Y ;else put command into packet
  3958.     INC    TXPTR    ;step buffer pointer
  3959.     INC    TXDLEN    ;and packet data length
  3960. ICD900    RTS
  3961.  
  3962.  
  3963. ***************************************
  3964. *
  3965. * SRVCMD
  3966. * ======
  3967. *
  3968. * Initiates sending a server command
  3969. *
  3970. ***************************************
  3971.  
  3972. SRVCMD    LDA    #%10000000 ;set mode to 'generic'
  3973.     STA    MODE
  3974. *
  3975. * If source is a TAKE file, do a brief delay in case we're
  3976. * talking to VAX/VMS which can't handle packets if they come too fast
  3977. *
  3978. SRV100    PHP        ;save I packet request
  3979.     JSR    TAKDEL    ;delay or not
  3980.     PLP
  3981. *
  3982. * Now go either to state I or state G
  3983. *
  3984.     BCC    SRV500    ;j if no I packet wanted
  3985.     LDA    #'I'    ;else set inital state to I
  3986.     BNE    SRV900
  3987. SRV500    LDA    #'G'    
  3988. SRV900    JMP    RECSW    ;and enter the receive switcher
  3989.  
  3990.  
  3991.     CHN    BBCST1
  3992. ****** File BBCMAI *************************************************************
  3993.     START    MAI
  3994. * BBCMAI: Updated 24/02/87 @ 1200
  3995.  
  3996.     IF    RAM
  3997. ****************************************
  3998. *
  3999. * RAM HEADER
  4000. * ==========
  4001. *
  4002. * This is the start of the RAM version.
  4003. * If you make patches to it, place them
  4004. * from PRGTOP upwards. You MUST then
  4005. * change the address stored here at
  4006. * PTPPTR to point the next byte after your
  4007. * patch, or the patch will be trampled
  4008. * by the file buffer.
  4009. ***************************************
  4010.  
  4011.     MSW    $FFFF    ;must run in i/o processor
  4012.     ORG    $1F00    ;avoid econet and such
  4013.  
  4014.     JMP    MAIN    ;JMP to make dehexer easy
  4015.     DFB    MARK    ;mark number
  4016.     DFB    VERSION    ;version number
  4017.     DW    DEFTAB    ;address of defaults block
  4018. PTPPTR    DW    PRGTOP    ;first byte past image and patches
  4019.  
  4020.     ASC    '(C)1987 CUCCA/Lancaster '
  4021.     ASC    'By A. Phillips'
  4022.  
  4023.     ELSE
  4024.  
  4025. ***************************************
  4026. *
  4027. * ROM HEADER
  4028. * ==========
  4029. *
  4030. * This is the start of the language
  4031. * ROM
  4032. *
  4033. ***************************************
  4034.  
  4035.     MSW    $FFFF    ;so we *LOAD to IO processor sideways RAM
  4036.     ORG    $8000
  4037.  
  4038.     JMP    MAIN    ;language entry point
  4039.     JMP    SENTRY    ;service entry point
  4040.     DFB    %11000010 ;ROM type byte
  4041.     DFB    CPRMES-$8000 ;copyright offset
  4042.     DFB    MARK    ;mark number
  4043. TITLE    ASC    'KERMIT' ;ROM title
  4044. ROMCLN    EQU    *-TITLE-1
  4045.     DFB    0
  4046.     DFB    MARK+$30
  4047.     DFB    '.'
  4048.     DFB    VERSION/10+$30
  4049.     DFB    (VERSION-(VERSION/10*10))+$30    
  4050. CPRMES    DFB    0
  4051.     ASC    '(C)1987 CUCCA/Lancaster'
  4052.     DFB    0
  4053.  
  4054.     DFB    MARK    ;mark number
  4055.     DFB    VERSION    ;version number
  4056.     DW    DEFTAB    ;address of defaults block
  4057.     DW    PRGTOP    ;first byte past image
  4058.  
  4059.     ASC    'By A. Phillips'
  4060.  
  4061.  
  4062. ***************************************
  4063. *
  4064. * SERVICE ENTRY
  4065. * =============
  4066. *
  4067. * We pick up service entry calls here
  4068. *
  4069. ***************************************
  4070.  
  4071. SENTRY    PHA        ;save registers
  4072.     TXA
  4073.     PHA
  4074.     TYA
  4075.     PHA
  4076.     TSX
  4077.     LDA    $103,X    ;reload original A
  4078. *
  4079. * We look for a type 4 entry, 'unrecognised command', or a 
  4080. * type 9, '*HELP', or type 5, 'interrupt'
  4081. *
  4082.     CMP    #5
  4083.     BEQ    SEN200    ;j if interrupt
  4084.     CMP    #4
  4085.     BEQ    SEN400    ;j if command
  4086.     CMP    #9
  4087.     BNE    SEN900    ;j if not then *HELP
  4088. *
  4089. * Here it's *HELP, so maybe we print our title
  4090. *
  4091. SEN100    LDA    ($F2),Y ;look at what's past the "*HELP"
  4092.     CMP    #' '
  4093.     BNE    SEN120    ;j if not a space
  4094.     INY
  4095.     BNE    SEN100    ;else keep looking
  4096. SEN120    CMP    #$0D    ;if non-space is not CR there's a sub-topic on
  4097.     BNE    SEN900    ;line, so we ignore the call
  4098.     LDA    #223
  4099.     JSR    MESS    ;else print our title
  4100.     JMP    SEN900
  4101. *
  4102. * Here it's an unrecognised interrupt. Service it if we are
  4103. * the current language ROM. Note that the clean way to tell if we are
  4104. * current language is with OSBYTE $FC, but it's too slow, so we have to look at the
  4105. * OS RAM table directly
  4106. *
  4107. SEN200    LDX    $F4    ;get our ROM number
  4108.     CPX    $28C    ;are we current language?
  4109.     BNE    SEN900    ;j if not - do nothing
  4110.     JMP    IRQENT    ;and into our interrupt handler
  4111. *
  4112. * Here it's an unrecognised command, so look for "*KERMIT"
  4113. *
  4114. SEN400    LDX    #0    ;pointer to our title
  4115. SEN420    LDA    ($F2),Y    ;get byte from command
  4116.     JSR    UPPER    ;force upper case
  4117.     CMP    TITLE,X
  4118.     BNE    SEN480    ;j if mismatch
  4119.     INX
  4120.     INY
  4121.     CPX    #ROMCLN
  4122.     BNE    SEN420    ;j if more to go
  4123. *
  4124. * Command is "KERMIT", so activate ourselves
  4125. *
  4126. SEN440    LDA    #$FF    ;set flag to show language entry
  4127.     STA    STARTUP
  4128.     LDA    #$8E
  4129.     LDX    $F4    ;then get our ROM number
  4130.     JMP    OSBYTE    ;and enter ourselves
  4131. *
  4132. * Input line mismatches search. If we've had at least one match,
  4133. * we'll take a "." as matching OK
  4134. *
  4135. SEN480    CPX    #0
  4136.     BEQ    SEN900    ;j if first char mismatched
  4137.     CMP    #'.'    ;else is current char a "."?
  4138.     BEQ    SEN440    ;j if so - call it a match
  4139. *
  4140. * All done, so return with registers intact
  4141. *
  4142. SEN900    PLA
  4143.     TAY
  4144.     PLA
  4145.     TAX
  4146.     PLA
  4147.     RTS
  4148.  
  4149.     FI
  4150.  
  4151. ***************************************
  4152. *
  4153. * MAIN
  4154. * ====
  4155. *
  4156. * This is the initialisation and control
  4157. * routine for KERMIT
  4158. *
  4159. ***************************************
  4160.  
  4161. MAIN    EQU    *
  4162.     IF    RAM
  4163.     LDA    #$FF    ;set flag to show first entry
  4164.     STA    STARTUP
  4165. MAI010    SEI        ;turn IRQ off if RAM to keep tidy
  4166.     FI
  4167.     LDX    #$FF
  4168.     TXS        ;set up the stack
  4169. *
  4170. * For now, point the BRK vector to a loop stop
  4171. *
  4172.     LDA    #>MAI900
  4173.     STA    BRKV
  4174.     LDA    #<MAI900
  4175.     STA    BRKV+1
  4176.     IF    ROM
  4177. *
  4178. * Make sure user isn't running us in a second processor
  4179. *
  4180.     LDA    #$EA
  4181.     JSR    RSYSVAL    ;read TUBE flag
  4182.     TXA
  4183.     BEQ    MAI050    ;j if TUBE not on
  4184.     BRK        ;else BRK and loop stop
  4185.     DFB    0
  4186.     ASC    'Not on TUBE'
  4187.     DFB    0
  4188.     ELSE
  4189. *
  4190. * Change start up mode to 7 in case user hits BREAK with it at something
  4191. * that may corrupt us
  4192. *
  4193.     LDA    #$FF
  4194.     LDY    #%11111000
  4195.     LDX    #7
  4196.     JSR    OSBYTE
  4197. *
  4198. * Then point the BREAK intercept to us
  4199. *
  4200.     JSR    NOBINT    ;remove the JMP while we do it
  4201.     LDA    #$F8    ;then set the address
  4202.     LDX    #>BREAK
  4203.     JSR    OBX0
  4204.     LDA    #$F9
  4205.     LDX    #<BREAK
  4206.     JSR    OBX0
  4207.     LDA    #$F7    ;and put the JMP in
  4208.     LDX    #$4C
  4209.     JSR    OBX0
  4210.     FI    
  4211. *
  4212. * Disable the ESCAPE key
  4213. *
  4214. MAI050    JSR    ESCOFF    ;now generates $1B
  4215. *
  4216. * Now see if we need to initialise the workspace
  4217. *
  4218.     BIT    STARTUP    ;test startup flag
  4219.     IF    RAM
  4220.     BPL    MAI300    ;j if restarted from BREAK
  4221.     ELSE
  4222.     BMI    MAI090    ;j if language entry
  4223.     JSR    RDBTYP    ;else look at BREAK type
  4224.     TXA
  4225.     BEQ    MAI300    ;j if soft BREAK
  4226.     FI
  4227. *
  4228. * Here we do need to clean up the workspace
  4229. *
  4230. MAI090    LDA    #0
  4231.     TAY
  4232. MAI100    STA    WKBASE,Y
  4233.     STA    WKBASE+$100,Y
  4234.     STA    WKBASE+$200,Y
  4235.     STA    WKBASE+$300,Y
  4236.     INY
  4237.     BNE    MAI100
  4238. *
  4239. * Also make sure page 0 from $00 to $8F is clear
  4240. *
  4241.     LDX    #0
  4242. MAI120    STA    $0,X
  4243.     INX
  4244.     CPX    #$90
  4245.     BNE    MAI120
  4246. *
  4247. * Set default values up
  4248. *
  4249.     JSR    DEFAULT
  4250. MAI300    JSR    FLUSH    ;clear the comms buffer
  4251.     JSR    GETACIA    ;take control of 6850
  4252.     JSR    SETACIA    ;and set it up as we need
  4253.     IF    ROM
  4254. *
  4255. * Now locate the system's extended vector table
  4256. *
  4257.     LDA    #$A8
  4258.     JSR    RSYSVAL    ;find where it is
  4259.     STX    EVECTB    ;save pointer to it
  4260.     STY    EVECTB+1
  4261.     FI
  4262. *
  4263. * Force vectors back to power on state
  4264. *
  4265.     JSR    STDVEC
  4266. *
  4267. * Note the type of OS (and hence the machine) in use
  4268. *
  4269.     LDA    #0
  4270.     JSR    OB10    ;get value in X
  4271.     DEX        ;scale to 0=model B
  4272.     STX    OSTYPE
  4273.     IF    RAM
  4274. *
  4275. * If RAM set the type flag to $FF
  4276. *
  4277.     LDA    #$FF
  4278.     STA    PTYPE
  4279. *
  4280. * If RAM and we're running in a B+ or Master, turn shadow mode on
  4281. *
  4282.     LDA    #0
  4283.     STA    SHADOW    ;assume no shadow capability
  4284.     LDX    OSTYPE
  4285.     BEQ    MAI350    ;j if model B (OS 1)
  4286.     LDA    #114
  4287.     JSR    OB00    ;else turn shadow on at next mode change
  4288.     STX    ENTSHAD ;and note what it was before
  4289.     DEC    SHADOW    ;note we have shadow capability
  4290.     ELSE
  4291. *
  4292. * If ROM and on a B+ or Master, turn shadow mode off
  4293. *
  4294.     LDA    #0
  4295.     STA    SHADOW    ;no shadow capability
  4296.     LDX    OSTYPE
  4297.     BEQ    MAI350    ;j if model B (OS 1)
  4298.     LDA    #114
  4299.     JSR    OB10    ;else turn shdow off at mode change
  4300.     STX    ENTSHAD    ;note what it was before
  4301.     FI
  4302. *
  4303. * Clear the flag that indicates a BRK is an error packet
  4304. *
  4305. MAI350    LDA    #0
  4306.     STA    BRKSRC
  4307. *
  4308. * Adjust terminal type to an appropriate one if it's on its
  4309. * "use default" setting after a cold start
  4310. *
  4311.     JSR    ADJTT
  4312. *
  4313. * Note the filing system current
  4314. *
  4315.     JSR    WHATFS
  4316.     IF    RAM
  4317. *
  4318. * Adjust OSHWM to be above the KERMIT program area and patches
  4319. *
  4320.     LDA    #$B4
  4321.     LDX    PTPPTR+1
  4322.     INX
  4323.     JSR    OBX0    ;change to new setting
  4324.     STX    OLDHWM    ;and note previous value
  4325.     FI
  4326. *
  4327. * Set up address of the SET block in case a TXR might want to know
  4328. *
  4329.     LDA    #>DFBASE
  4330.     STA    DEFPTR
  4331.     LDA    #<DFBASE
  4332.     STA    DEFPTR+1
  4333. *
  4334. * And finally enter the command mode routine which will enable IRQ
  4335. *
  4336. MAI600    LDA    #1    ;set command mode to use 40 byte screen
  4337.     STA    CWIDTH
  4338.     JMP    CMDMODE    ;and enter command processor
  4339. *
  4340. *
  4341. * Routine to handle BRK in initialisation phase
  4342. *
  4343. MAI900    JSR    BRKTXT    ;print the text
  4344. MAI910    JMP    MAI910    ;and loop-stop
  4345.  
  4346.  
  4347.     IF    RAM
  4348. ***************************************
  4349. *
  4350. * BREAK INTERCEPT
  4351. * ===============
  4352. *
  4353. * BREAK key is directed here
  4354. *
  4355. ***************************************
  4356.  
  4357. BREAK    BCC    BAK900    ;j if pre-init call
  4358. *
  4359. * If this was a CONTROL-BREAK we will not restart
  4360. *
  4361.     JSR    RDBTYP    ;read last BREAK type
  4362.     CPX    #2
  4363.     BNE    BAK200    ;j if not CONTROL-BREAK
  4364.     JMP    NOBINT    ;else lose BREAK intercept and finish
  4365. *
  4366. * Not a CONTROL-BREAK so we re-enter ourselves
  4367. *
  4368. BAK200    LDA    #$8F    ;issue sideways ROM call to restart the
  4369.     LDX    #$12    ;filing system that was there when we started
  4370.     LDY    FSNUM
  4371.     JSR    OSBYTE
  4372.     JMP    MAI010    ;and restart ourselves
  4373. BAK900    RTS
  4374.     FI
  4375.  
  4376.  
  4377. ***************************************
  4378. *
  4379. * OB00, OBX0
  4380. * ==========
  4381. *
  4382. * Does OSBYTE with X=0, Y=0 (OB00) or
  4383. * with Y=0 (OBX0)
  4384. *
  4385. ***************************************
  4386.  
  4387. OB00    LDX    #0
  4388. OBX0    LDY    #0
  4389.     JMP    OSBYTE
  4390.  
  4391.  
  4392. ***************************************
  4393. *
  4394. * OB10
  4395. * ====
  4396. *
  4397. * Does OSBYTE with X=1, Y=0
  4398. *
  4399. ***************************************
  4400.  
  4401. OB10    LDX    #1
  4402.     BNE    OBX0
  4403.  
  4404.  
  4405. ***************************************
  4406. *
  4407. * DOKOSB
  4408. * ======
  4409. *
  4410. * Does OSBYTE to talk to TXR with Y=0
  4411. *
  4412. ***************************************
  4413.  
  4414. DOKOSB    LDA    #KOSBYT
  4415.     BNE    OBX0
  4416.  
  4417.  
  4418.     IF    RAM
  4419. ***************************************
  4420. *
  4421. * NOBINT
  4422. * ======
  4423. *
  4424. * Clears the BREAK intercept
  4425. *
  4426. ***************************************
  4427.  
  4428. NOBINT    LDA    #$F7
  4429.     JMP    OB00    ;ensure a $00 where a $4C is expected
  4430.     FI
  4431.  
  4432.  
  4433. ***************************************
  4434. *
  4435. * RSYSVAL
  4436. * =======
  4437. *
  4438. * OSBYTE with X=0, Y=$FF to read value
  4439. *
  4440. ***************************************
  4441.  
  4442. RSYSVAL LDY    #$FF
  4443.     LDX    #0
  4444.     JMP    OSBYTE
  4445.  
  4446.  
  4447. ***************************************
  4448. *
  4449. * RDBTYP
  4450. * ======
  4451. *
  4452. * Reads type of last BREAK
  4453. *
  4454. **************************************
  4455.  
  4456. RDBTYP    LDA    #$FD
  4457.     BNE    RSYSVAL
  4458.  
  4459.  
  4460. **************************************
  4461. *
  4462. * DEFAULT VALUES
  4463. * ==============
  4464. *
  4465. * Initial protocol and control values
  4466. * are taken from this table
  4467. *
  4468. **************************************
  4469.  
  4470. DEFTAB    DFB    7    ;transmit baud rate 9600
  4471.     DFB    7    ;receive baud rate 9600
  4472.     DFB    0    ;local echo off
  4473.     DFB    0    ;obsolete byte (1.03)
  4474.     DFB    0    ;debug flag off
  4475.     DFB    0    ;obsolete byte (1.03)
  4476.     DFB    15    ;timeout he uses on me
  4477.     DFB    15    ;timeout I use on him
  4478.     DFB    0    ;timer is off
  4479.     DFB    0    ;pause after packet read
  4480.     DFB    30    ;delay after send
  4481.     DFB    0    ;obsolete byte (1.40)
  4482.     DFB    0    ;obsolete byte (1.40)
  4483.     DFB    0    ;keyclick off
  4484.     DFB    '#'    ;quote I send
  4485.     DFB    '&'    ;preferred 8 bit prefix
  4486.     DFB    $0D    ;EOLN I send
  4487.     DFB    $0D    ;EOLN he sends
  4488.     DFB    0    ;pad character I send
  4489.     DFB    0    ;number of them
  4490.     DFB    0    ;pad character he sends
  4491.     DFB    0    ;number of them
  4492.     DFB    1    ;parity SPACE
  4493.     DFB    0    ;file type ASCII
  4494.     DFB    0    ;EOR type LFCR
  4495.     DFB    0    ;data source FILE
  4496.     DW    0    ;source memory base
  4497.     DW    0    ;source memory top
  4498.     DFB    0    ;data destination FILE    
  4499.     DW    0    ;dest memory base
  4500.     DW    0    ;dest memory top
  4501.     DFB    $01    ;start of packet I send
  4502.     DFB    $01    ;start of packet he sends
  4503.     DFB    94    ;max packet length I want in
  4504.     DFB    16    ;file buffer is 16 pages
  4505.     DFB    1    ;file warning on
  4506.     DFB    0    ;incomplete file DELETE
  4507.     DFB    0    ;flow control XON/XOFF
  4508.     DFB    3    ;file suffix length
  4509.     ASC    'BBC     ' ;file suffix string
  4510.     DFB    1    ;TAKE echo on
  4511.     DFB    7    ;VDU text colour 7 (white)
  4512.     DFB    1    ;do *TV for terminal mode
  4513.     DFB    0    ;with parameters 0...
  4514.     DFB    1    ;...and 1
  4515.     DFB    0    ;VDU ignore character off
  4516.     DFB    0    ;space for char to ignore
  4517.     DFB    0    ;MUX wait 0 byte periods
  4518.     DFB    '?'    ;autohelp triggered by '?'
  4519.     DFB    5    ;max retries allowed
  4520.     DFB    0    ;no handshaking used
  4521.     DFB    $FF    ;set terminal to suit machine
  4522.     DFB    0    ;file name translation normal
  4523.  
  4524. DEFCNT    EQU    *-DEFTAB ;size of defaults table
  4525.  
  4526.     IF    DEFCNT-DFSIZE
  4527.     INFO    '** Default table size wrong **'
  4528.     FI
  4529.  
  4530.  
  4531. ***************************************
  4532. *
  4533. * BRKH
  4534. * ====
  4535. *
  4536. * This is the BRK handler
  4537. *
  4538. ***************************************
  4539.  
  4540. BRKH    EQU    *
  4541. *
  4542. * Make sure the system is nice and clean
  4543. *
  4544.     JSR    ACKESC    ;ACK any ESCAPE outstanding
  4545.     JSR    OPVDU    ;ensure VDU is selected
  4546.     JSR    PRTOFF    ;ensure printer if off
  4547.     JSR    GETACIA    ;take over 6850
  4548.     JSR    LOSESYS    ;set known state
  4549.     JSR    GETSYS    ;and take over
  4550. *
  4551. * If command source is a TAKE file, we close it
  4552. *
  4553.     JSR    CLTAKE
  4554. *
  4555. * Make sue any TRANSMIT file is closed
  4556. *
  4557.     JSR    CLTXF
  4558. *
  4559. * If terminal, transfer or generic mode we bleep
  4560. *
  4561. BRK100    LDA    MODE
  4562.     BEQ    BRK120    ;j if command mode
  4563.     LDA    #7
  4564.     JSR    OSWRCH    ;else toll the bell
  4565. *
  4566. * If command, terminal or generic mode, output goes on next line down
  4567. *
  4568. BRK120    LDA    MODE
  4569.     CMP    #%11000000
  4570.     BEQ    BRK600    ;j if transfer mode
  4571.     JSR    TIDYLN    ;else ensure we're on a clean line
  4572.     JSR    BRKTXT    ;print the text
  4573.     JSR    OSNEWL
  4574. *
  4575. * If this is generic mode, maybe we send an E packet to the other end
  4576. *
  4577.     BIT    MODE
  4578.     BMI    BRK615    ;j if generic mode
  4579. *
  4580. * It's command or terminal mode : if terminal mode, make sure the log file are closed
  4581. *
  4582.     LDA    MODE
  4583.     CMP    #1
  4584.     BNE    BRK400    ;j if not terminal mode
  4585.     LDY    LHAND    ;is log file open?
  4586.     BEQ    BRK400    ;j if not
  4587.     LDA    #0
  4588.     STA    LHAND    ;else clear out handle
  4589.     STA    LOGON    ;clear the log toggle
  4590.     JSR    OSFIND    ;and close the file
  4591. *
  4592. * Now wind stack back to restart point and jump to the
  4593. * restart vector
  4594. *
  4595. BRK400    LDA    #0    ;clear the error packet idicator
  4596.     STA    BRKSRC
  4597. BRK500    LDX    STKRST
  4598.     TXS
  4599.     JMP    (RESTART)
  4600. *
  4601. * Here we're in transfer mode, so status screen is up and the
  4602. * text goes to a specific place
  4603. *
  4604. BRK600    LDA    #12
  4605.     JSR    MESS    ;position and say 'fatal error'
  4606.     JSR    BRKTXT    ;and print the text
  4607. *
  4608. * Make sure any files open are closed. Because DFS 2.24 screws up
  4609. * on "close all files" we close the transfer file (which might be open for
  4610. * writing) explicitely first
  4611. *
  4612.     LDY    FHAND    ;do we have a transfer file?
  4613.     BEQ    BRK615    ;j if not
  4614.     LDA    #0
  4615.     JSR    OSFIND    ;else close it
  4616.     LDY    #0    ;then close all the rest
  4617.     JSR    CLOSEY
  4618. *
  4619. * Do we have to delete an incoming incomplet file now?
  4620. *
  4621.     LDA    FHAND    ;check handle
  4622.     BEQ    BRK615    ;j if no file open
  4623.     LDA    WAY    ;check transfer direction
  4624.     BNE    BRK615    ;j if we'1re SEND here
  4625. *
  4626. * Well, we are receiving, so we might have to
  4627. *
  4628.     JSR    OPTDEL    ;delete if needed    
  4629. *
  4630. * Do we now send this text as an error packet to the other end?
  4631. *
  4632. BRK615    LDA    BRKSRC    ;is text an error packet from other side?
  4633.     BNE    BRK900    ;j if so - don't send it back!
  4634. *
  4635. * BRK was issued by us, so send to the other end. Copy text to TXBUFF
  4636. *
  4637.     INC    $FD    ;point to start of text
  4638.     BNE    BRK620
  4639.     INC    $FE
  4640. BRK620    LDY    #0
  4641. BRK630    LDA    ($FD),Y    ;get a byte
  4642.     BEQ    BRK640    ;j if end of text
  4643.     STA    TXBUFF,Y ;else store it
  4644.     INY        ;move pointer on
  4645.     CPY    #81
  4646.     BNE    BRK630    ;j if packet not yet full
  4647. *
  4648. * And send the error packet
  4649. *
  4650. BRK640    STY    DATLEN    ;save size of data part
  4651.     LDA    #'E'    ;get type
  4652.     LDX    NXTPAK    ;and number
  4653.     JSR    SPACK    ;send it
  4654.     LDA    #51
  4655.     JSR    PRTSST    ;set screen status to "idle"
  4656. *
  4657. * If transfer mode we wait for a keypress and restart
  4658. *
  4659. BRK900    BIT    MODE
  4660.     BVC    BRK400    ;j if not transfer mode
  4661.     JSR    WTCMODE    ;else wait a bit
  4662.     JMP    BRK400
  4663.  
  4664.  
  4665. ***************************************
  4666. *
  4667. * EVENT
  4668. * =====
  4669. *
  4670. * This handles the timer event
  4671. *
  4672. ***************************************
  4673.  
  4674. EVENT    CMP    #5    ;timer event?
  4675.     BNE    EVE900    ;j if not - ignore
  4676. *
  4677. * We've had a one-second tick here
  4678. *
  4679.     PHA        ;save things
  4680.     TXA
  4681.     PHA
  4682.     TYA
  4683.     PHA
  4684.     LDA    TICKER    ;has timer expired?
  4685.     BEQ    EVE800    ;j if so
  4686.     DEC    TICKER    ;else step it down
  4687.     JSR    CLOCK    ;and reset the clock interval
  4688. *
  4689. * And finish
  4690. *
  4691. EVE800    PLA
  4692.     TAY
  4693.     PLA
  4694.     TAX
  4695.     PLA
  4696. EVE900    RTS
  4697.  
  4698.  
  4699.     CHN    BBCCPR
  4700. ****** File BBCPM1 *************************************************************
  4701.     START    PM1
  4702. * BBCPM1: Updated 12/08/86 @ 1500
  4703.  
  4704. ***************************************
  4705. *
  4706. * BUFEMP
  4707. * ======
  4708. *
  4709. * Takes bytes from a data packet and
  4710. * puts them into the file buffer or on
  4711. * the screen
  4712. *
  4713. ***************************************
  4714.  
  4715. BUFEMP    EQU    *
  4716. *
  4717. * Initialise pointers to the receive packet buffer and set up
  4718. * length counts, etc
  4719. *
  4720.     JSR    INIRPK    ;byte count in X now
  4721.     BEQ    BEM350    ;j if no data
  4722. *
  4723. * Get next byte from packet
  4724. *
  4725. BEM100    LDY    #0
  4726.     STY    WORK9    ;assume B7 will be clear later
  4727. BEM120    LDY    RXPTR    ;get remove pointer
  4728.     LDA    RXBUFF,Y ;get char from packet
  4729.     INC    RXPTR    ;step pointer for next time
  4730. *
  4731. * Is this character special?
  4732. *
  4733.     CMP    RQUOTE
  4734.     BEQ    BEM500    ;j if it's quote character
  4735.     BIT    EBQFLG    ;are we 8 bit prefixing?
  4736.     BPL    BEM150    ;j if not
  4737.     CMP    EBQCHR    ;else is char the prefix in use?
  4738.     BEQ    BEM400    ;j if it is
  4739. *
  4740. * We've got the char in A and the B7 setting in WORK9. Do we do still more?
  4741. *
  4742. BEM150    ORA    WORK9    ;set B7 up
  4743.     BMI    BEM260    ;j if set - no more to so
  4744.     LDY    FTYPE    ;else look at file type
  4745.     BNE    BEM260    ;j if binary - no more to do
  4746.     BIT    MODE    ;are we doing server command (generic mode)?
  4747.     BVC    BEM260    ;j if so -also no more to do
  4748. *
  4749. * File is ASCII, so we're on the look out for CRLF
  4750. *
  4751.     LDY    EORTYPE ;how do we do EOR here?
  4752.     CPY    #1
  4753.     BEQ    BEM260    ;we're CRLF too, so no action
  4754.     BIT    PENDFLG    ;else was last char a CR?
  4755.     BPL    BEM250    ;j if not
  4756. *
  4757. * Last char was a CR. Is this one an LF then?
  4758. *
  4759.     CMP    #$0A
  4760.     BNE    BEM180    ;j if not
  4761. *
  4762. * Host has sent CRLF, so translate this into the specified EOR sequence
  4763. *
  4764.     LDA    EOR
  4765.     JSR    TOFILE    ;always one byte
  4766.     LDA    EOR+1
  4767.     BEQ    BEM160    ;j if only one
  4768. BEM155    JSR    TOFILE    ;else write the second one too
  4769. BEM160    INC    PENDFLG    ;set flag to 0
  4770.     BEQ    BEM300    ;get next byte in from packet
  4771. *
  4772. * We had a CR last time, but this byte isn't LF
  4773. *
  4774. BEM180    PHA        ;save the byte
  4775.     LDA    #$0D    ;and put the CR into the file
  4776.     JSR    TOFILE
  4777.     PLA        ;reload data byte
  4778.     JMP    BEM155    ;and wrie it, too
  4779. *
  4780. * Previous character wasn't a CR. Is this one a CR then?
  4781. *
  4782. BEM250    CMP    #$0D
  4783.     BNE    BEM260    ;j if not
  4784.     DEC    PENDFLG    ;else set flag to $FF
  4785.     BMI    BEM300    ;and get next byte
  4786. BEM260    JSR    TOFILE    ;else write bye to file
  4787. *
  4788. * Move to next packet byte, if there is one
  4789. *
  4790. BEM300    DEX
  4791.     BNE    BEM100    ;j if more to do
  4792. BEM350    RTS        ;else finish
  4793. *
  4794. * Here we've met an 8-bit quote character
  4795. *
  4796. BEM400    LDA    #%10000000
  4797.     STA    WORK9    ;note B7 on for later
  4798.     DEX        ;decrement chars-left count
  4799.     JMP    BEM120    ;and do next char, noting it's got B7 set
  4800. *
  4801. * Here we met a quote character
  4802. *
  4803. BEM500    LDY    RXPTR
  4804.     LDA    RXBUFF,Y ;get following character
  4805.     INC    RXPTR    ;step get pointer past quoted char
  4806.     DEX        ;decrease count of bytes left
  4807.     BIT    EBQFLG    ;are we 8 bit prefixing?
  4808.     BPL    BEM520    ;j if not
  4809. *
  4810. * Is the quoted character the 8-bit-prefix in use? (here we know the
  4811. * character has B7 clear as we are actually doing 8-bit-prefixing..)
  4812. *
  4813.     CMP    EBQCHR
  4814.     BEQ    BEM150    ;j if it is
  4815. *
  4816. * Is the quoted character the quote itself? At this point we may have B7 set in the character,
  4817. * so be sure we check only ls 7 bits
  4818. *
  4819. BEM520    TAY        ;save character a moment
  4820.     AND    #%01111111 ;lose B7
  4821.     CMP    RQUOTE
  4822.     BNE    BEM600    ;j if B6-0 not the quote character
  4823.     TYA        ;else get original back
  4824.     JMP    BEM150    ;and output to file as is
  4825. *
  4826. * Here the quoted character isn't anything special, so just flip B6 and output it
  4827. *
  4828. BEM600    TYA        ;get original back
  4829.     EOR    #%01000000 ;flip B6
  4830.     JMP    BEM150    ;and output it
  4831.  
  4832.  
  4833. ***************************************
  4834. *
  4835. * TOFILE
  4836. * ======
  4837. *
  4838. * Writes a byte into the file buffer or
  4839. * to the screen, or to the printer
  4840. *
  4841. ***************************************
  4842.  
  4843. TOFILE    PHA        ;save registers
  4844.     TYA
  4845.     PHA
  4846.     TXA
  4847.     PHA
  4848.     TSX
  4849.     LDA    $103,X    ;get data byte back
  4850.     BIT    MODE    ;in generic mode for server command?
  4851.     BVC    TOF600    ;j if so
  4852. *
  4853. * It's a transfer, so is it to the printer directly?
  4854. *
  4855.     LDX    DESTIN    ;get destination flag
  4856.     CPX    #2
  4857.     BNE    TOF100    ;j if not to printer
  4858.     PHA        ;else save data byte
  4859.     JSR    OPPTR    ;select parallel printr
  4860.     PLA
  4861.     JSR    OSWRCH    ;print the character
  4862.     JSR    OPVDU    ;reselect VDU
  4863.     JSR    COUNTB    ;count this byte
  4864.     JMP    TOF900    ;and finish    
  4865. *
  4866. * Transfer is to file or memory, so put byte into the buffer
  4867. *
  4868. TOF100    LDY    #0    ;else put character into buffer
  4869.     STA    (FBPTR),Y
  4870.     JSR    COUNTB    ;count the byte
  4871. *
  4872. * Step buffer pointer and see if it's now full
  4873. *
  4874.     INC    FBPTR
  4875.     BNE    TOF200
  4876.     INC    FBPTR+1
  4877. TOF200    LDA    FBPTR+1
  4878.     CMP    FBMAX+1
  4879.     BNE    TOF500    ;j if not full
  4880.     LDA    FBPTR
  4881.     CMP    FBMAX
  4882.     BNE    TOF500    ;j if not full
  4883. *
  4884. * Buffer is full, so write and reset it
  4885. *
  4886.     LDA    #39
  4887.     JSR    DMESS    ;send diagnostic text
  4888. *
  4889. * If destination is memory, we error since that's all there's room for
  4890. *
  4891.     LDA    DESTIN
  4892.     BEQ    TOF300    ;j if to file
  4893.     BRK        ;else crunch
  4894.     DFB    0
  4895.     ASC    'Memory full'
  4896.     DFB    0
  4897. *
  4898. * Destination is file, so write buffer away
  4899. *
  4900. TOF300    JSR    FWRITE    ;write the buffer
  4901.     LDA    FBUFF    ;reset the pointer
  4902.     STA    FBPTR
  4903.     LDA    FBUFF+1
  4904.     STA    FBPTR+1
  4905. TOF500    JMP    TOF900    ;and finish
  4906. *
  4907. * Here we're doing a server command, so put the byte on the screen
  4908. *
  4909. TOF600    CMP    #$0D
  4910.     BEQ    TOF680    ;j if CR
  4911.     CMP    #$0A
  4912.     BEQ    TOF685    ;j if LF
  4913.     CMP    #$09
  4914.     BEQ    TOF690    ;j if TAB
  4915.     CMP    #$7F
  4916.     BEQ    TOF695    ;j if DEL
  4917.     CMP    #$08
  4918.     BEQ    TOF695    ;j if BS
  4919.     CMP    #$0C
  4920.     BEQ    TOF700    ;j if FF
  4921.     CMP    #32
  4922.     BCS    TOF650    ;j if not other control char
  4923.     JMP    TOF900    ;else ignore it
  4924. *
  4925. * Not control, so just print it
  4926. *
  4927. TOF650    JSR    CHROUT    ;print character
  4928.     JMP    TOF900
  4929. *
  4930. * Here it was a control character that we accept
  4931. *
  4932. TOF680    JSR    CROUT    ;CR
  4933.     JMP    TOF900
  4934. TOF685    JSR    LFOUT    ;LF
  4935.     JMP    TOF900
  4936. TOF690    JSR    TABOUT    ;TAB
  4937.     JMP    TOF900
  4938. TOF695    JSR    DELOUT    ;DEL or BS
  4939.     JMP    TOF900
  4940. TOF700    JSR    OSWRCH    ;FF
  4941.     JSR    VDUINI
  4942. *
  4943. * And exit
  4944. *
  4945. TOF900    PLA
  4946.     TAX
  4947.     PLA
  4948.     TAY
  4949.     PLA
  4950.     RTS
  4951.  
  4952.  
  4953. ***************************************
  4954. *
  4955. * BUFILL
  4956. * ======
  4957. *
  4958. * Takes bytes from the file buffer and
  4959. * builds packet data. SMAXD holds max
  4960. * DATA size remote wants, less 1 as we
  4961. * count from 0, less another 2 to make
  4962. * sure we don't split a quote sequence
  4963. * across packets. This is a rather conservative
  4964. * approach, but it saves having to do a
  4965. * look ahead, as the maximum length of a
  4966. * quote sequence is 3 (i.e. "&#<char>")
  4967. * and we will always have space available
  4968. * for it.
  4969. *
  4970. ***************************************
  4971.  
  4972. BUFILL    EQU    *
  4973. *
  4974. * Do we need to read data into the buffer first?
  4975. *
  4976.     IF    ROM
  4977.     LDA    SOURCE    ;is source MEMORY
  4978.     BNE    BUF020    ;j if so - no file to read
  4979.     FI
  4980.     LDA    EOB    ;look at buffer state flag
  4981.     BEQ    BUF020    ;j if not empty
  4982.     JSR    FREAD    ;else read some in
  4983. *
  4984. * Set up pointers to the transmit packet data buffer
  4985. *
  4986. BUF020    LDA    #0
  4987.     STA    TXPTR
  4988. *
  4989. * Is a byte pending from last time round?
  4990. *
  4991. BUF050    BIT    PENDFLG
  4992.     BPL    BUF060    ;j if not
  4993.     INC    PENDFLG    ;else clear flag to 0
  4994.     LDA    PENDCHR    ;get the pended character
  4995.     STA    WORK9    ;pretend we read it normally
  4996.     JMP    BUF300    ;and inject it
  4997. *
  4998. * OK, we need to get a byte
  4999. *
  5000. BUF060    EQU    *
  5001. *
  5002. * Gets bytes from the buffer. Have we exhausted it?
  5003. *
  5004.     LDA    FBPTR
  5005.     CMP    FBTOP
  5006.     BNE    BUF115    ;j if not
  5007.     LDA    FBPTR+1
  5008.     CMP    FBTOP+1
  5009.     BNE    BUF115    ;j if not
  5010. *
  5011. * Buffer is exhausted, so read some more from the file (if we have one)
  5012. *
  5013.     LDA    #40
  5014.     JSR    DMESS    ;log this
  5015.     IF    ROM
  5016.     LDA    SOURCE
  5017.     BNE    BUF100    ;j if source is MEMORY
  5018.     FI
  5019.     LDA    EOF    ;are we at EOF here?
  5020.     BNE    BUF100    ;j if so - no more data
  5021.     JSR    FREAD    ;else read the file
  5022.     JMP    BUF060    ;and process what we got, if anything
  5023. *
  5024. * EOF hit. Was last char we saw the star of an EOR sequence?
  5025. *
  5026. BUF100    INC    EORSEQ
  5027.     BEQ    BUF240    ;j if so - write it to packet
  5028. *
  5029. * Now back to caller, setting up length of the packet we've built
  5030. *
  5031. BUF105    LDY    TXPTR    ;get packet pointer
  5032.     BEQ    BUF110    ;j if packet empty
  5033.     STY    TXDLEN
  5034.     CLC        ;return 'packet built'
  5035.     RTS
  5036. *
  5037. * Here packet is empty, so tell caller
  5038. *
  5039. BUF110    SEC
  5040.     RTS
  5041. *
  5042. * Here we've not exhausted the buffer, so get a byte
  5043. *        
  5044. BUF115    JSR    COUNTB    ;count the byte
  5045.     LDY    #0
  5046.     LDA    (FBPTR),Y ;get the byte
  5047. *
  5048. * Make a note of the byte jusr obtained
  5049. *
  5050. BUF118    STA    WORK9    ;save it
  5051.     STY    WORK8    ;assume B7 clear at the end
  5052.     INC    FBPTR    ;move the pointer
  5053.     BNE    BUF120
  5054.     INC    FBPTR+1
  5055. *
  5056. * Do we need to watch for end-of-record?
  5057. *
  5058. BUF120    LDY    FTYPE    ;get type of file
  5059.     BNE    BUF300    ;j if binary - no action
  5060. *
  5061. * Yes we do. Is this char the first in the EOR sequence?
  5062. *
  5063.     CMP    EOR
  5064.     BNE    BUF220    ;j if not
  5065.     LDY    EOR+1    ;else is ther a second byte too?
  5066.     BEQ    BUF200    ;j if not - EOR is CR or LF
  5067.     DEC    EORSEQ    ;else set flag to $FF
  5068.     BNE    BUF060    ;and look at next byte
  5069. *
  5070. * We've found end of record, so send a CRLF
  5071. *
  5072. BUF200    LDA    #$0D
  5073.     STA    WORK9    ;change char to send to be a CR
  5074.     DEC    PENDFLG    ;set pending flag to $FF
  5075.     LDA    #$0A
  5076.     STA    PENDCHR    ;and pend an LF
  5077.     JMP    BUF500    ;and output the CR
  5078. *
  5079. * Byte wasn't the first in the EOR sequence. Are we looking for the second?
  5080. *
  5081. BUF220    BIT    EORSEQ
  5082.     BPL    BUF300    ;j if not - send the byte
  5083.     INC    EORSEQ    ;else clear the flag to 0
  5084.     CMP    EOR+1    ;is it the byte looked for?
  5085.     BEQ    BUF200    ;j if so - output CRLF
  5086. *
  5087. * We saw byte 0 of the EOR sequence, but not byte 1. Write the first byte to the
  5088. * packet and pend the current data byte
  5089. *
  5090. BUF240    STA    PENDCHR    ;pend the data in now
  5091.     DEC    PENDFLG    ;set pend flag to $FF
  5092.     LDA    EOR
  5093.     STA    WORK9    ;inject first byte of EOR sequence
  5094.     BNE    BUF500    ;j always
  5095. *
  5096. * Does the character need special treatment?
  5097. *
  5098. BUF300    LDA    WORK9    ;get it back
  5099.     BMI    BUF400    ;j if B7 is on
  5100. BUF320    CMP    SQUOTE
  5101.     BEQ    BUF550    ;j if it's the quote character
  5102. BUF325    CMP    #32
  5103.     BCC    BUF500    ;j if it's a control char
  5104.     CMP    #127
  5105.     BEQ    BUF500    ;j if it's DEL
  5106.     BIT    EBQFLG    ;are we 8 bit prefixing?
  5107.     BPL    BUF380    ;j if not - char isn't special
  5108.     CMP    EBQCHR    ;else is it the prefix in use?
  5109.     BEQ    BUF700    ;j if it is
  5110. *
  5111. * Character is non-controversial, so stuff it up the buffer
  5112. *
  5113. BUF380    ORA    WORK8    ;put B7 into it
  5114.     JSR    BUF800    ;into the buffer
  5115. *
  5116. * Is the packet buffer now full?
  5117. *
  5118.     BCS    BUF105    ;j if it is
  5119.     JMP    BUF050    ;j if not
  5120. *
  5121. * Character has B7 set, so we might 8-bit quote it
  5122. *
  5123. BUF400    BIT    EBQFLG
  5124.     BMI    BUF480    ;j if 8 bit prefix in use
  5125.     LDY    PARITY    ;else look at our parity
  5126.     CPY    #4
  5127.     BEQ    BUF490    ;j if NONE - can send 8 bits
  5128. *
  5129. * We can't send 8 bits and can't prefix, so warn user of loss
  5130. *
  5131.     BIT    BINWRN    ;warned already?
  5132.     BMI    BUF450    ;j if so
  5133.     DEC    BINWRN    ;else set flag to $FF
  5134.     LDA    #11
  5135.     JSR    MESS    ;and write warning out
  5136. *
  5137. * Now strip off B7 and packet the byte
  5138. *
  5139. BUF450    LDA    WORK9    ;get data back and lose B7
  5140. BUF455    AND    #%01111111
  5141.     STA    WORK9
  5142.     BPL    BUF320    ;and put into packet
  5143. *
  5144. * Here data is 8 bit, but we can prefix it
  5145. *
  5146. BUF480    LDA    EBQCHR    ;get prefix char
  5147.     JSR    BUF800    ;packet the prefix
  5148.     JMP    BUF450    ;send data character as 7 bits    
  5149. *
  5150. * Here data is 8 bit, and we can send it all (parity none)
  5151. *
  5152. BUF490    LDY    #$80
  5153.     STY    WORK8    ;note B7 on at the end
  5154.     BMI    BUF455    ;check ls 7 bits for specials
  5155. *
  5156. * Here the character is a control character, so quote it
  5157. *
  5158. BUF500    LDA    SQUOTE
  5159.     JSR    BUF800    ;output a quote
  5160.     LDA    WORK9    ;get the character back
  5161.     EOR    #%01000000 ;flip control bit
  5162.     JMP    BUF380    ;and put into buffer
  5163. *
  5164. * Here it's the quote character. Put it in the buffer twice
  5165. *
  5166. BUF550    JSR    BUF800
  5167.     JMP    BUF380
  5168. *
  5169. * Here char is the 8 bit prefix in use, so quote it
  5170. *
  5171. BUF700    PHA        ;save char
  5172.     LDA    SQUOTE
  5173.     JSR    BUF800    ;put a quote in the buffer
  5174.     PLA        ;reget character
  5175.     BNE    BUF380    ;and output it itself
  5176. *
  5177. *
  5178. *
  5179. * Routine to put character into packet data buffer
  5180. *
  5181. BUF800    LDY    TXPTR
  5182.     STA    TXBUFF,Y ;put char away
  5183.     INY
  5184.     STY    TXPTR    ;move pointer on
  5185.     CPY    SMAXD    ;see if past end point
  5186.     RTS
  5187.  
  5188.  
  5189. ***************************************
  5190. *
  5191. * INPARS
  5192. * ======
  5193. *
  5194. * Analyses remote's init params sent in
  5195. * response to ours
  5196. *
  5197. ***************************************
  5198.  
  5199.  
  5200. INPARS SEC        ;note we've sent ours
  5201.     JSR    RPAR    ;extract host's parameters
  5202. *
  5203. * Host may have defaulted some values, so check them
  5204. *
  5205.     LDA    XSEOLN
  5206.     BNE    IPR200    ;j if he gave his EOLN
  5207.     LDA    SEOLN    ;else get the SET value
  5208.     STA    XSEOLN    ;and use this
  5209. IPR200    LDA    RQUOTE
  5210.     BNE    IPR900    ;j if he gave his quote
  5211.     LDA    #'#'
  5212.     STA    RQUOTE    ;else set to "#"
  5213. IPR900    RTS        ;and finish
  5214.  
  5215.  
  5216.     NEXT    BBCPM2
  5217. ****** File BBCPM2 *************************************************************
  5218.     START    PM2
  5219. * BBCPM2: Updated 28/01/87 @ 2030
  5220.  
  5221. ***************************************
  5222. *
  5223. * RPACK
  5224. * =====
  5225. *
  5226. * Receives a packet
  5227. *
  5228. ***************************************
  5229.  
  5230. RPACK    EQU    *
  5231. *
  5232. * Send a diagnostic header if necessary
  5233. *
  5234.     LDA    #1
  5235.     JSR    DMESS
  5236. *
  5237. * Set status on screen to 'waiting'
  5238. *
  5239.     LDA    #23
  5240.     JSR    PRTSST
  5241.  
  5242. * Read data until we find start-of-packet
  5243. *
  5244. RPA100    JSR    RXBYTE
  5245.     BCC    RPA110    ;j if not keyboard CR or timeout
  5246.     JMP    RPA900
  5247. RPA110    CMP    RSOP
  5248.     BNE    RPA100    ;j if not SOP
  5249. *
  5250. * SOP seen, so set state on the screen to 'receiving'
  5251. *
  5252.     LDA    #25
  5253.     JSR    PRTSST
  5254. *
  5255. * Now we'll read the packet length byte in
  5256. *
  5257. RPA120    JSR    RXBYTE
  5258.     BCC    RPA130    ;j if not keyboard CR or timeout
  5259.     JMP    RPA900
  5260. RPA130    JSR    DBYTE    ;log the byte
  5261.     CMP    RSOP
  5262.     BNE    RPA140    ;j if byte is not SOP again
  5263.     JMP    RPA800
  5264. RPA140    CMP    REOLN
  5265.     BNE    RPA150    ;j if it's not sender's EOLN
  5266.     JMP    RPA820
  5267. RPA150    STA    CHKSUM    ;else start the checksum
  5268.     JSR    UNCHAR    ;de-char it
  5269.     STA    DATLEN    ;and save it
  5270. *
  5271. * Next comes the packet sequence number
  5272. *
  5273.     JSR    RXBYTE
  5274.     BCC    RPA200    ;j if not keyboard CR or timeout
  5275.     JMP    RPA900
  5276. RPA200    JSR    DBYTE    ;log it
  5277.     CMP    RSOP
  5278.     BNE    RPA220    ;j if it's not SOP again
  5279.     JMP    RPA800
  5280. RPA220    CMP    REOLN
  5281.     BNE    RPA240    ;j if not sender's EOLN
  5282.     JMP    RPA820
  5283. RPA240    PHA        ;else save it
  5284.     CLC
  5285.     ADC    CHKSUM
  5286.     STA    CHKSUM    ;and update checksum
  5287.     PLA        ;get byte back
  5288.     JSR    UNCHAR    ;de-char it
  5289.     STA    PACNUM    ;and note the value
  5290. *
  5291. * Next comes the packet type
  5292. *
  5293.     JSR    RXBYTE
  5294.     BCC    RPA260    ;j if not keyboard CR or timeout
  5295.     JMP    RPA900
  5296. RPA260    JSR    DBYTE    ;log it
  5297.     CMP    RSOP
  5298.     BNE    RPA280    ;j if it's not SOP again
  5299.     JMP    RPA800
  5300. RPA280    CMP    REOLN
  5301.     BNE    RPA290    ;j if not sender's EOLN
  5302.     JMP    RPA820
  5303. RPA290    STA    PACTYPE    ;else save it
  5304.     CLC
  5305.     ADC    CHKSUM
  5306.     STA    CHKSUM    ;and update checksum
  5307. *
  5308. * Now we read data until we hit the EOLN character
  5309. *
  5310.     LDY    #0    ;buffer pointer
  5311. RPA300    JSR    RXBYTE    ;read a byte in
  5312.     BCC    RPA320    ;j if not keyboard CR or timeout
  5313.     JMP    RPA900
  5314. RPA320    JSR    DBYTE    ;log it
  5315.     CMP    RSOP
  5316.     BNE    RPA330    ;j if not SOP again
  5317.     JMP    RPA800    ;else resync and start again
  5318. RPA330    CMP    REOLN
  5319.     BEQ    RPA400    ;j if it's sender's EOLN
  5320. *
  5321. * If there's still room in the receive buffer we note the byte,
  5322. * and if not we ignore it
  5323. *
  5324.     CPY    #MAXPAK+1
  5325.     BEQ    RPA300    ;j if buffer is full
  5326.     STA    RXBUFF,Y    ;else note the byte
  5327.     CLC
  5328.     ADC    CHKSUM
  5329.     STA    CHKSUM    ;update the checksum
  5330.     INY        ;step packet buffer pointer
  5331.     BNE    RPA300    ;get next character
  5332. *
  5333. * We've had sender's EOLN in. Do we wait on a handshake byte now?
  5334. *
  5335. RPA400    LDX    HSHAKE    ;get handshake type in use
  5336.     BEQ    RPA500    ;j if NONE
  5337. RPA410    JSR    RXBYTE    ;else read a byte in
  5338.     BCC    RPA420    ;j if had one from sender
  5339.     JMP    RPA900    ;else it was keyboard/timeout 
  5340. RPA420    CMP    RSOP    ;was it SOP again?
  5341.     BNE    RPA430    ;j if not
  5342.     JMP    RPA800
  5343. RPA430    CMP    SKTAB2,X ;was it the handshake byte?
  5344.     BNE    RPA410    ;j if not - ignore it
  5345. *
  5346. * Packet is now complete. Check we had at least one byte in (the checksum)
  5347. *
  5348. RPA500    JSR    DCLRLN    ;clear debug line
  5349.     CPY    #0
  5350.     BEQ    RPA830    ;j if short packet
  5351. *
  5352. * We added the checksum into the checksum just now, so we'll
  5353. * have to remove it
  5354. *
  5355.     LDA    CHKSUM
  5356.     SEC
  5357.     SBC    RXBUFF-1,Y
  5358. *
  5359. * Convert the value into a characterised checksum
  5360. *
  5361.     JSR    CSUM
  5362. *
  5363. * Does this now match the checksum we actually received?
  5364. *
  5365.     CMP    RXBUFF-1,Y
  5366.     BNE    RPA840    ;j if it doesn't
  5367. *
  5368. * Checksum is OK. Make sure packet isn't shorter than expected
  5369. *
  5370.     INY
  5371.     INY
  5372.     CPY    DATLEN
  5373.     BCC    RPA850    ;j if it is
  5374. *
  5375. * Adjust DATLEN so it realy is length of th DATA part only
  5376. *
  5377.     DEC    DATLEN
  5378.     DEC    DATLEN
  5379.     DEC    DATLEN
  5380. *
  5381. * Count the packet, then wait for PAUSE seconds in case other end's comms is a bit
  5382. * nadgered at high speed
  5383. *
  5384. RPA700    JSR    COUNTP    ;count packet
  5385.     LDA    PAUSE
  5386.     JSR    WAIT    ;and wait
  5387. *
  5388. * Now look at the packet type. If it's the same as the one we just
  5389. * sent, we've read an echo which we ignore
  5390. *
  5391.     LDA    PACTYPE
  5392.     CMP    LPTYPE    ;compare packet types
  5393.     BNE    RPA750    ;j if not same - all OK
  5394.     LDA    #116
  5395.     JSR    DMESS    ;else log this is an echo
  5396.     JMP    RPACK    ;and wait for next one to come along
  5397. *
  5398. * Not an echo, so pass packet type back to caller
  5399. *
  5400. RPA750    PHA        ;save packet type
  5401.     LDA    #208
  5402.     JSR    DMESS    ;print diagnostic text
  5403.     LDA    DATLEN
  5404.     JSR    DPRHEX    ;print packet data length
  5405.     PLA        ;reload packet type
  5406.     JSR    DBYTE    ;log it
  5407.     JSR    DCLRLN    ;clear diagnostic line    
  5408.     CLC        ;note packet read OK
  5409.     RTS
  5410. *
  5411. * Here we hit an unexpected SOP
  5412. *
  5413. RPA800    LDA    #2
  5414.     JSR    DMESS    ;log it
  5415.     JSR    FLUSH    ;clear comms buffer
  5416.     JMP    RPA120    ;restart
  5417. *
  5418. * Here we met sender's EOLN too early
  5419. *
  5420. RPA820    LDA    #3
  5421. RPA825    JSR    DMESS    ;log it
  5422.     JSR    FLUSH    ;clear comms buffer
  5423.     JMP    RPA900
  5424. *
  5425. * Here packet ended after the red tape bytes
  5426. *
  5427. RPA830    LDA    #4
  5428.     BNE    RPA825
  5429. *
  5430. * Here the checksum was wrong
  5431. *
  5432. RPA840    LDA    #6
  5433.     BNE    RPA825
  5434. *
  5435. * Here the length in PACLEN doesn't match the actual data
  5436. *
  5437. RPA850    LDA    #5
  5438.     BNE    RPA825
  5439. *
  5440. * Here user hit CR on the keyboard, or reception failed
  5441. *
  5442. RPA900    SEC
  5443.     RTS
  5444.  
  5445.  
  5446. ***************************************
  5447. *
  5448. * SPACK
  5449. * =====
  5450. *
  5451. * Transmits a packet
  5452. *
  5453. ***************************************
  5454.  
  5455. SPACK    STA    PACTYPE ;set packet type
  5456.     STX    PACNUM    ;and number
  5457. *
  5458. * First output the debug text
  5459. *
  5460.     LDA    #35
  5461.     JSR    DMESS
  5462. *
  5463. * Set status on screen to 'sending'
  5464. *
  5465.     LDA    #24
  5466.     JSR    PRTSST
  5467. *
  5468. * Then we send any pad characters the other end wants
  5469. *
  5470.     LDY    XSNPAD    ;get number to send
  5471.     BEQ    SPA200    ;j if none wanted
  5472.     LDA    XSPADC    ;else get the character
  5473. SPA100    JSR    TXBYTE    ;send it
  5474.     DEY
  5475.     BNE    SPA100    ;j till all pads sent
  5476. *
  5477. * Start packet off with a start-of-packet
  5478. *
  5479. SPA200    LDA    SSOP
  5480.     JSR    TXBYTE
  5481. *
  5482. * First send the packet length and start the checksum up
  5483. *
  5484.     LDA    DATLEN    ;get length of DATA portion
  5485.     CLC
  5486.     ADC    #3    ;form total packet length    
  5487.     JSR    TOCHAR    ;characterise it
  5488.     JSR    DBYTE    ;log the byte
  5489.     JSR    TXBYTE    ;send it
  5490.     STA    CHKSUM    ;start checksum
  5491. *
  5492. * Now send the packet sequence number
  5493. *
  5494.     LDA    PACNUM
  5495.     JSR    TOCHAR    ;characterise it
  5496.     JSR    DBYTE    ;log it
  5497.     JSR    TXBYTE    ;send it
  5498.     CLC
  5499.     ADC    CHKSUM
  5500.     STA    CHKSUM    ;update checksum
  5501. *
  5502. * Now send and note the packet type letter
  5503. *
  5504.     LDA    PACTYPE
  5505.     JSR    DBYTE    ;log it
  5506.     STA    LPTYPE    ;record it for receiver
  5507.     JSR    TXBYTE    ;and send it
  5508.     CLC
  5509.     ADC    CHKSUM
  5510.     STA    CHKSUM    ;update checksum
  5511. *
  5512. * Now prepare to send the data part
  5513. *
  5514.     LDA    DATLEN    ;get length of data part
  5515.     BEQ    SPA800    ;j if none
  5516.     TAX        ;else prepare counter
  5517. *
  5518. * Send the next data byte
  5519. *
  5520.     LDY    #0    ;TXBUFF pointer
  5521. SPA600    LDA    TXBUFF,Y ;get next byte
  5522.     JSR    DBYTE    ;log it
  5523.     JSR    TXBYTE    ;send it
  5524.     CLC
  5525.     ADC    CHKSUM
  5526.     STA    CHKSUM    ;update checksum
  5527. *
  5528. * Any more data to send?
  5529. *
  5530.     INY        ;step buffer pointer
  5531.     DEX
  5532.     BNE    SPA600    ;j if more to go
  5533. *
  5534. * All data sent, so now send the checksum value
  5535. *
  5536. SPA800    LDA    CHKSUM
  5537.     JSR    CSUM    ;form character value
  5538.     JSR    DBYTE    ;log it
  5539.     JSR    TXBYTE    ;and send it
  5540. *
  5541. * Then send the EOLN character
  5542. *
  5543.     LDA    XSEOLN
  5544.     JSR    DBYTE    ;log it
  5545.     JSR    TXBYTE    ;send it
  5546. *
  5547. * Finally clear the debug line and count the packet
  5548. *
  5549. SPA900    JSR    DCLRLN
  5550.     JMP    COUNTP
  5551.  
  5552.  
  5553. ***************************************
  5554. *
  5555. * PAKPAR/PAKPRL
  5556. * =============
  5557. *
  5558. * Puts current parameter into a packet
  5559. * for a server command with a field length
  5560. * (PAKPRL) or without one (PAKPAR). This
  5561. * routine may be called several times to
  5562. * build one packet: on entry TXPTR holds
  5563. * current place in SCBUFF where we're
  5564. * building the command and TXDLEN holds
  5565. * the current size of the command
  5566. *
  5567. ***************************************
  5568.  
  5569. PAKPRL    EQU    *
  5570. *
  5571. * Start with the parameter length
  5572. *
  5573.     LDA    CURLEN    ;get the length
  5574.     JSR    TOCHAR    ;characterise it
  5575.     JSR    PPR800    ;put into the packet
  5576. *
  5577. * Then the bulk of the parameter
  5578. *
  5579. PAKPAR    EQU    *
  5580. PPR100    LDA    CURLEN
  5581.     BEQ    PPR700    ;j if zero length parameter
  5582.     LDY    #0    ;else start pointer to take from paramete
  5583. *
  5584. * Process next character
  5585. *
  5586. PPR200    STY    WORK0    ;save pointe
  5587.     LDA    (CURPAR),Y ;get character
  5588.     JSR    PPR800    ;output it
  5589.     LDY    WORK0    ;reload pointer
  5590.     INY        ;step parameter pointer on
  5591.     CPY    CURLEN    ;got to the end?
  5592.     BNE    PPR200    ;j if not
  5593. *
  5594. * All done
  5595. *
  5596. PPR700    RTS
  5597. *
  5598. * Routine to put character into buffer
  5599. *
  5600. PPR800    LDY    TXPTR    ;ge buffer pointe
  5601.     CPY    #MAXPAK+1    ;is buffer full?
  5602.     BEQ    PPR890    ;j if so
  5603.     STA    SCBUFF,Y    ;else put character in
  5604.     INC    TXPTR    ;step buffer pointer
  5605.     INC    TXDLEN    ;step data size
  5606.     RTS
  5607. *
  5608. * Here packet is full. As we've not yet sent an I packet, we don't want to send an E packet
  5609. * to the server
  5610. *
  5611. PPR890    LDA    #0
  5612.     STA    MODE    ;fake 'command mode' to inhibit E packet
  5613. *
  5614. * And do a "long command" break
  5615. *
  5616. PPR900    BRK
  5617.     DFB    0
  5618.     ASC    'Command too long'
  5619.     DFB    0
  5620.  
  5621.  
  5622. ***************************************
  5623. *
  5624. * INIRPK
  5625. * ======
  5626. *
  5627. * Initialise to process received packet
  5628. *
  5629. ***************************************
  5630.  
  5631. INIRPK    LDA    #0
  5632.     STA    RXPTR    ;start pointer to buffer
  5633.     LDX    DATLEN    ;and length of data portion
  5634.     RTS
  5635.  
  5636.  
  5637.     NEXT    BBCPM3
  5638. ****** File BBCPM3 *************************************************************
  5639.     START    PM3
  5640. * BBCPM3 : Updated 11/06/86 @ 1110
  5641.  
  5642. ***************************************
  5643. *
  5644. * STDPAK
  5645. * ======
  5646. *
  5647. * Sends a standard packet with no data
  5648. *
  5649. ***************************************
  5650.  
  5651. STDPAK    LDY    #0    ;data size is 0
  5652. SPK100    STY    DATLEN
  5653.     JMP    SPACK    ;send it
  5654.  
  5655.  
  5656. ***************************************
  5657. *
  5658. * STDPKD
  5659. * ======
  5660. *
  5661. * Sends a standard packet with one data
  5662. * byte
  5663. *
  5664. ***************************************
  5665.  
  5666. STDPKD    STY    TXBUFF    ;set data byte
  5667.     LDY    #1    ;data size is 1
  5668.     BNE    SPK100
  5669.  
  5670.  
  5671. ***************************************
  5672. *
  5673. * STDBREAK
  5674. * ========
  5675. *
  5676. * Sends a 'B' packet
  5677. *
  5678. ***************************************
  5679.  
  5680. STDBREAK EQU    *
  5681.     LDA    #'B'
  5682. SBR100    LDX    NXTPAK    ;get sequence number
  5683.     JMP    STDPAK
  5684.  
  5685.  
  5686. ***************************************
  5687. *
  5688. * STDEOF
  5689. * ======
  5690. *
  5691. * Sends a 'Z' packet
  5692. *
  5693. ***************************************
  5694.  
  5695. STDEOF    LDA    #'Z'
  5696.     BNE    SBR100
  5697.  
  5698.  
  5699. ***************************************
  5700. *
  5701. * SDCEOF
  5702. * ======
  5703. *
  5704. * Sends an EOF/Z packet
  5705. *
  5706. ***************************************
  5707.  
  5708. SDCEOF    LDY    #'D'    ;data byte
  5709.     LDA    #'Z'    ;packet type
  5710. SDE100    LDX    NXTPAK    ;packet number
  5711.     JMP    STDPKD
  5712.  
  5713.  
  5714. ***************************************
  5715. *
  5716. * SBKACK
  5717. * ======
  5718. *
  5719. * Sends an ACK/Z or ACK/X
  5720. *
  5721. ***************************************
  5722.  
  5723. SBKACK    LDA    #'Y'    ;packet type 'y'
  5724.     BNE    SDE100
  5725.  
  5726.  
  5727. ***************************************
  5728. *
  5729. * STDNAK
  5730. * ======
  5731. *
  5732. * Sends a NAK packet
  5733. *
  5734. ***************************************
  5735.  
  5736. STDNAK    LDA    #'N'
  5737.     BNE     SBR100
  5738.  
  5739.  
  5740. ***************************************
  5741. *
  5742. * STDACK
  5743. * ======
  5744. *
  5745. * Sends a parameterless ACK packet
  5746. *
  5747. ***************************************
  5748.  
  5749. STDACK    LDA    #'Y'
  5750.     BNE    SBR100
  5751.  
  5752.  
  5753. ***************************************
  5754. *
  5755. * CSUM
  5756. * ====
  5757. *
  5758. * Converts the 8 bit value in A into a
  5759. * characterised checksum
  5760. *
  5761. ***************************************
  5762.  
  5763. CSUM    STA    CSTEMP    ;save the value
  5764.     CLC
  5765.     ROL    A
  5766.     ROL    A
  5767.     ROL    A
  5768.     AND     #%00000011 ;get top bits at bottom
  5769.     CLC
  5770.     ADC    CSTEMP    ;add original
  5771.     AND    #%00111111 ;lose top bits
  5772.     JMP    TOCHAR    ;and characterise it
  5773.  
  5774.  
  5775. ***************************************
  5776. *
  5777. * VALSEQ
  5778. * ======
  5779. *
  5780. * Checks that a packet has the expected
  5781. * sequence number
  5782. *
  5783. ***************************************
  5784.  
  5785. VALSEQ    LDA    NXTPAK
  5786.     CMP    PACNUM    ;sequence correct?
  5787.     BNE    VSQ900    ;j if not
  5788.     LDA    #0
  5789.     STA    NUMTRY    ;else clear retry count
  5790.     JSR    INCNXT    ;step next-packet number
  5791.     CLC
  5792.     RTS        ;return OK
  5793. *
  5794. * Sequence incorrect so return fail
  5795. *
  5796. VSQ900    SEC
  5797.     RTS
  5798.  
  5799.  
  5800. ***************************************
  5801. *
  5802. * VALNAK
  5803. * ======
  5804. *
  5805. * Checks whether a NAK is for the next
  5806. * packet to be sent
  5807. *
  5808. ***************************************
  5809.  
  5810. VALNAK    LDX    PACNUM
  5811.     DEX        ;step sequence number back
  5812.     BPL    VNK200
  5813.     LDX    #63    ;MOD 64
  5814. VNK200    CPX    NXTPAK    ;does it now match?
  5815.     BNE    VSQ900    ;j if not - retrun fail
  5816.     CLC        ;else OK
  5817.     RTS
  5818.  
  5819.  
  5820. ***************************************
  5821. *
  5822. * RPTACK
  5823. * ======
  5824. *
  5825. * Sees if it is appropriate to resend an
  5826. * ACK, and does so if it is
  5827. *
  5828. ***************************************
  5829.  
  5830. RPTACK    LDX    NXTPAK    ;step next-packet back by 1
  5831.     DEX
  5832.     BPL    RCK200
  5833.     LDX    #0
  5834. *
  5835. * Does this number now match that of the received packet?
  5836. *
  5837. RCK200    CPX    PACNUM
  5838.     BNE    RCK800
  5839. *
  5840. * Yes it does, so we assume host has lost an ACK
  5841. * which we will repeat
  5842. *
  5843.     LDA    #'Y'
  5844.     LDY    PACNUM    ;re-use packet number
  5845.     JSR    STDPAK    ;send it
  5846.     CLC        ;return OK
  5847.     RTS
  5848. *
  5849. * Not appropriate to resend, so return fail
  5850. *
  5851. RCK800    SEC
  5852.     RTS
  5853.  
  5854.  
  5855. ***************************************
  5856. *
  5857. * ERRPKT
  5858. * ======
  5859. *
  5860. * Handles an error packet received from
  5861. * the other end
  5862. *
  5863. ***************************************
  5864.  
  5865. ERRPKT    EQU    *
  5866. *
  5867. * We'll copy the text to the stack. First put in
  5868. * a BRK and a zero error number
  5869. *
  5870.     LDA    #0
  5871.     STA    $100
  5872.     STA    $101
  5873. *
  5874. * Copy the text from the receive packet buffer, with a zero at the end
  5875. *
  5876.     LDY    DATLEN    ;get data length
  5877.     STA    $102,Y    ;put in finishing 0 byte
  5878.     DEY        ;step to last byte of data
  5879. EPK200    LDA    RXBUFF,Y ;get byte in
  5880.     STA    $102,Y ;store it
  5881.     DEY
  5882.     BPL    EPK200    ;j till all moved
  5883. *
  5884. * Note that this is an error packet and not a locally
  5885. * generated BRK
  5886. *
  5887.     LDA    #1
  5888.     STA    BRKSRC
  5889. *
  5890. * And do a BRK to give break handler control
  5891. *
  5892.     JMP    $100
  5893.  
  5894.  
  5895. ***************************************
  5896. *
  5897. * SPAR
  5898. * ====
  5899. *
  5900. * Sets up a packet containing our
  5901. * parameters
  5902. *
  5903. ***************************************
  5904.  
  5905. SPAR    PHP        ;note 'send/receive' flag
  5906. *
  5907. * Put values into transmit packet buffer
  5908. *
  5909.     LDA    RMAXL ;max packet size I want
  5910.     JSR    TOCHAR
  5911.     STA    TXBUFF
  5912.     LDA    STIME    ;my timeout period
  5913.     JSR    TOCHAR
  5914.     STA    TXBUFF+1
  5915.     LDA    RNPAD    ;number of pad characters I want
  5916.     JSR    TOCHAR
  5917.     STA    TXBUFF+2
  5918.     LDA    RPADC    ;pad character I want
  5919.     EOR    #%01000000
  5920.     STA    TXBUFF+3
  5921.     LDA    REOLN    ;EOLN character I want
  5922.     JSR    TOCHAR
  5923.     STA    TXBUFF+4
  5924.     LDA    SQUOTE    ;quote character I will use
  5925.     STA    TXBUFF+5
  5926.     LDA    #'1'    ;always check type 1
  5927.     STA    TXBUFF+7
  5928. *
  5929. * Now the 8-bit prefixing bit. Am I doing a SEND?
  5930. *
  5931.     PLP        ;get the flag
  5932.     BCS    SPR600    ;j if I'm sending
  5933. *
  5934. * I'm receiving, so I've already had other side's ideas on this
  5935. *
  5936.     LDA    EBQCHR    ;get what he sent me
  5937.     BNE    SPR300    ;j if didn't default it
  5938. SPR210    JSR    EBQOFF    ;else tell user we won't do it
  5939. SPR220    LDA    #0
  5940.     STA    EBQCHR    ;kill it over here
  5941.     LDA    #'N'    ;and we'll send an N in the field
  5942.     BNE    SPR800
  5943. *
  5944. * Other side didn't default the field, so look at what he said
  5945. *
  5946. SPR300    CMP    #'Y'
  5947.     BEQ    SPR400    ;j if sent Y
  5948.     CMP    #'N'
  5949.     BEQ    SPR210    ;j if he sent N - we won't do it
  5950.     JSR    VALEBQ    ;else is it legal?
  5951.     BCS    SPR210    ;j if not legal
  5952. *
  5953. * He sent us a legal prefix, so we'll use it
  5954. *
  5955. SPR380    STA    EBQCHR    ;note for packet handlers
  5956.     JSR    EBQON    ;tell user we do it
  5957.     LDA    EBQCHR
  5958.     BNE    SPR800    ;and send the char back to him to confirm
  5959. *
  5960. * Here he sent a Y - he'll do it if we will
  5961. *
  5962. SPR400    LDA    PARITY    ;am I parity NONE?
  5963.     CMP    #4
  5964.     BEQ    SPR210    ;j if so - don't prefix
  5965.     LDA    CUREBQ
  5966.     BNE    SPR380    ;else we will
  5967. *
  5968. * Here I'm sending, so what I request for prefix depends on my parity setting
  5969. *
  5970. SPR600    LDA    PARITY
  5971.     CMP    #4    ;am I parity NONE?
  5972.     BNE    SPR620    ;j if not
  5973.     LDA    #'Y'
  5974.     BNE    SPR630    ;else I will if he will
  5975. SPR620    LDA    CUREBQ    ;not parity NONE, so I want to prefix
  5976. SPR630    STA    EBQCHR    ;so note my character
  5977. *
  5978. * And here I'm all set,and A contains the prefix field to send to him
  5979. *
  5980. SPR800    STA    TXBUFF+6 ;into packet
  5981.     LDA    #8    ;set packet data length
  5982.     STA    DATLEN    
  5983. *
  5984. * And finish
  5985. *
  5986.     RTS
  5987.  
  5988.  
  5989. ***************************************
  5990. *
  5991. * RPAR
  5992. * ====
  5993. *
  5994. * Reads the other end's parameters from
  5995. * an init packet
  5996. *
  5997. ***************************************
  5998.  
  5999. RPAR    PHP        ;save 'send/receive' flag
  6000. *
  6001. * First build a block of defaults in case he sent a short packet with some
  6002. * fields absent. Use the transmit buffer for this
  6003. *
  6004.     LDY    #6
  6005. RPR100    LDA    RPRTAB,Y
  6006.     STA    TXBUFF,Y
  6007.     DEY
  6008.     BPL    RPR100
  6009. *
  6010. * Now copy the stuff we had from him into the buffer
  6011. *
  6012.     LDY    DATLEN    ;get length of data part
  6013.     BEQ    RPR120    ;j if none at all
  6014. RPR110    DEY        ;step pointer back
  6015.     LDA    RXBUFF,Y ;get next byte
  6016.     STA    TXBUFF,Y ;move to our new buffer
  6017.     BNE    RPR110    ;j always
  6018. *
  6019. * Now analyse what we've just produced
  6020. *
  6021. RPR120    LDA    TXBUFF    ;max packet size he wants
  6022.     JSR    UNCHAR
  6023.     SEC
  6024.     SBC    #5    ;form max DATA size - 3 (see BUFILL for comments)
  6025.     STA    SMAXD
  6026.     LDA    TXBUFF+2 ;number of pad characters he wants
  6027.     JSR    UNCHAR
  6028.     STA    XSNPAD
  6029.     LDA    TXBUFF+3 ;pad character he wants
  6030.     EOR    #%01000000
  6031.     STA    XSPADC
  6032.     LDA    TXBUFF+4 ;end of line character I must send
  6033.     JSR    UNCHAR
  6034.     STA    XSEOLN
  6035.     LDA    TXBUFF+5 ;quote character he will send
  6036.     STA    RQUOTE
  6037. *
  6038. * Now the 8 bit prefix. Am I doing a send or a receive?
  6039. *
  6040.     PLP        ;get the flag
  6041.     BCS    RPR300    ;j if I'm sending
  6042.     LDA    TXBUFF+6 ;else see what he said
  6043.     STA    EBQCHR    ;note for SPAR in a minute
  6044.     RTS
  6045. *
  6046. * Now look at the 8bit prefix field
  6047. *
  6048. RPR300    LDA    TXBUFF+6 ;get what he sent
  6049.     CMP    #'N'
  6050.     BEQ    RPR500    ;j if he won't do it
  6051.     CMP    #'Y'
  6052.     BEQ    RPR360    ;j if he said yes to something
  6053. *
  6054. * He's sent me a prefix character. Did I send a Y or my own prefix?
  6055. *
  6056.     LDX    EBQCHR    ;get what I sent him
  6057.     CPX    #'Y'    ;was it a Y?
  6058.     BNE    RPR340    ;j if not
  6059. *
  6060. * I sent Y, he replied with a prefix, so do it
  6061. *
  6062.     STA    EBQCHR    ;note prefix to use
  6063. RPR330    JMP    EBQON    ;tell user we do it
  6064. *
  6065. * I sent a prefix, he replied with one. Is it the same one?
  6066. *
  6067. RPR340    CMP    EBQCHR
  6068.     BEQ    RPR330    ;j if it is - we do it
  6069.     BNE    RPR500    ;else we differ, so we don't    
  6070. *
  6071. * He's sent me a Y. Did I send Y or a prefix?
  6072. *
  6073. RPR360    LDA    EBQCHR    ;get what I sent him
  6074.     CMP    #'Y'
  6075.     BEQ    RPR500    ;we both sent Y, so don't do it
  6076.     JMP    EBQON    ;else tell user we will
  6077. *
  6078. * We disagree or don't want to, so we won't
  6079. *
  6080. RPR500    LDA    #0
  6081.     STA    EBQCHR    ;clear prefix character out
  6082.     JMP    EBQOFF    ;tell user it's off
  6083. *
  6084. * Default S packet contents
  6085. *
  6086. RPRTAB    DFB    80+' '    ;MAXL
  6087.     DFB    0+' '    ;TIME
  6088.     DFB    0+' '    ;NPAD
  6089.     DFB    0!%01000000 ;PADC
  6090.     DFB    $0D+' ' ;EOLN
  6091.     DFB    '#'    ;QCTL
  6092.     DFB    'N'    ;QBIN
  6093.  
  6094.  
  6095.     NEXT    BBCFIL
  6096. ****** File BBCREC *************************************************************
  6097.     START    REC
  6098. * BBCREC: Updated 24/02/87 @ 1200
  6099.  
  6100. ***************************************
  6101. *
  6102. * RECSW
  6103. * =====
  6104. *
  6105. * The state table switcher for receiving
  6106. * a file or the output of a server command.
  6107. * Initial state is in A on entry.
  6108. *
  6109. ***************************************
  6110.  
  6111. RECSW    STA    STATE    ;note initial stte
  6112. *
  6113. * Clear out the comms buffer
  6114. *
  6115.     JSR    FLUSH
  6116. *
  6117. * Set up receiving buffer for the current destination
  6118. *
  6119.     LDA    DESTIN    ;get destination
  6120.     LDX    #0    ;mode is receive
  6121.     JSR    FBINIT
  6122. *
  6123. * Initialise protocol values and counts
  6124. *
  6125.     JSR    KINIT
  6126. *
  6127. * Log new position and state
  6128. *
  6129. RSW050    LDA    #15    ;get text number
  6130.     JSR    LOGST    ;and log it
  6131. *
  6132. * Switch on our current state to the correct handler
  6133. *
  6134.     LDA    STATE
  6135.     CMP    #'R'
  6136.     BEQ    RSW100    ;j if REC_INIT
  6137.     CMP    #'F'
  6138.     BEQ    RSW200    ;j if REC_FILE
  6139.     CMP    #'D'
  6140.     BEQ    RSW300    ;j if REC_DATA
  6141.     CMP    #'C'
  6142.     BEQ    RSW400    ;j if COMPLETE
  6143.     CMP    #'I'
  6144.     BEQ    RSW500    ;j if SEND_SERVER_INIT
  6145.     CMP    #'G'
  6146.     BEQ    RSW600    ;j if SEND_GEN_CMD
  6147. *
  6148. * Here we're in an unknown state, so break
  6149. *
  6150. RSW090    BRK
  6151.     DFB    0
  6152.     ASC    'Bad protocol state'
  6153.     DFB    0
  6154. *
  6155. *
  6156. *
  6157. * State REC_INIT
  6158. * --------------
  6159. *
  6160. RSW100    JSR    RINIT
  6161.     JMP    RSW050
  6162. *
  6163. *
  6164. * State REC_FILE
  6165. * --------------
  6166. *
  6167. RSW200    JSR    RFILE
  6168.     JMP    RSW050
  6169. *
  6170. *
  6171. * State REC_DATA
  6172. * --------------
  6173. *
  6174. RSW300    JSR    RDATA
  6175.     JMP    RSW050
  6176. *
  6177. *
  6178. * State COMPLETE
  6179. * --------------
  6180. *
  6181. RSW400    RTS
  6182. *
  6183. *
  6184. * State SEND_SERVER_INIT
  6185. * ----------------------
  6186. *
  6187. RSW500    JSR    SVINIT
  6188.     JMP    RSW050
  6189. *
  6190. *
  6191. * State SEND_GEN_CMD
  6192. * ------------------
  6193. *
  6194. RSW600    JSR    SNDCMD
  6195.     JMP    RSW050
  6196.  
  6197.  
  6198.  
  6199. ***************************************
  6200. *
  6201. * STATE REC_INIT
  6202. * ==============
  6203. *
  6204. ***************************************
  6205.  
  6206. RINIT    JSR    CHKTRY    ;check retry limit
  6207. *
  6208. * Read packet from host
  6209. *
  6210.     JSR    RPACK
  6211.     BCC    RIN040    ;j if got it OK
  6212.     JMP    STDNAK    ;else send a NAK
  6213. *
  6214. * Branch on packet type
  6215. *
  6216. RIN040    CMP    #'S'
  6217.     BEQ    RIN100    ;j if S
  6218.     CMP    #'E'
  6219.     BEQ    RIN200    ;j if E
  6220. *
  6221. * Packet type invalid here, so abort
  6222. *
  6223. RIN050    JMP    ABORT
  6224. *
  6225. *
  6226. *
  6227. * S received
  6228. * ----------
  6229. *
  6230. RIN100    CLC        ;note we're receiving
  6231.     JSR    RPAR    ;read other side's parameters
  6232.     CLC        ;note we're receiving
  6233.     JSR    SPAR    ;set ours up
  6234.     LDA    #'Y'    ;select packet type Y
  6235.     LDX    NXTPAK    ;and get the number
  6236.     JSR    SPACK    ;and send our parameters
  6237.     LDA    NUMTRY
  6238.     STA    OLDTRY    ;save try counter
  6239.     LDA    #0
  6240.     STA    NUMTRY    ;reset the main counter
  6241.     STA    FCOUNT    ;clear file counter
  6242.     JSR    INCNXT    ;step next-packet number by 1
  6243.     LDA    #'F'
  6244.     STA    STATE    ;and go to state REC_FILE
  6245.     RTS
  6246. *
  6247. *
  6248. * ERROR received
  6249. * --------------
  6250. *
  6251. RIN200    JMP    ERRPKT
  6252.  
  6253.  
  6254. ***************************************
  6255. *
  6256. * STATE REC_FILE
  6257. * ==============
  6258. *
  6259. ***************************************
  6260.  
  6261. RFILE    JSR    CHKTRY    ;check retry limit
  6262. *
  6263. * Read a packet from the host
  6264. *
  6265.     JSR    RPACK
  6266.     BCC    RFI040    ;j if got it OK
  6267.     JMP    STDNAK    ;else NAK it
  6268. *
  6269. * Branch on packet type
  6270. *
  6271. RFI040    CMP    #'S'
  6272.     BEQ    RFI100    ;j if S
  6273.     CMP    #'Z'
  6274.     BEQ    RFI200    ;j if Z
  6275.     CMP    #'F'
  6276.     BEQ    RFI300    ;j if F
  6277.     CMP    #'B'
  6278.     BEQ    RFI400    ;j if B
  6279.     CMP    #'E'
  6280.     BEQ    RFI500    ;j if E
  6281.     CMP    #'X'
  6282.     BEQ    RFI600    ;j if X
  6283. *
  6284. * Packet type unknown here, so abort
  6285. *
  6286. RFI050    JMP    ABORT
  6287. *
  6288. *
  6289. *
  6290. * S Received
  6291. * ----------
  6292. *
  6293. * This implies host lost an ACK from us with
  6294. * the parameters, so maybe we'll resend them
  6295. *
  6296. RFI100    JSR    CHKOTRY
  6297.     CLC        ;mark we're sending
  6298.     JSR    SPAR    ;set our parameters up (C clear for receive here)
  6299.     LDA    #'Y'    ;packet type is Y
  6300.     LDX    PACNUM    ;use old number again
  6301.     JSR    SPACK    ;and send it once more
  6302. *
  6303. * Reset the try counter and stay in this state
  6304. *
  6305. RFI120    LDA    #0
  6306.     STA    NUMTRY
  6307.     RTS
  6308. *
  6309. *
  6310. *
  6311. * Z Received
  6312. * ----------
  6313. *
  6314. * This implies host lost an ACK from us
  6315. *
  6316. RFI200    JSR    CHKOTRY    ;check retry limit
  6317.     JSR    RPTACK    ;repeat the ACK if possible
  6318.     BCS    RFI050    ;j if not allowed here
  6319.     BCC    RFI120    ;else start again
  6320. *
  6321. *
  6322. *
  6323. * F received
  6324. * ----------
  6325. *
  6326. * This is a file header announcing a file
  6327. *
  6328. RFI300    LDA    NXTPAK
  6329.     CMP    PACNUM    ;is sequence OK?
  6330.     BNE    RFI050    ;abort if not
  6331. *
  6332. * Packet is ok. Try to open the file, or set up printer, etc
  6333. *
  6334.     JSR    NEWFILE
  6335. *
  6336. * Destination is ready, so we'll prepare ourselves and ACK the host
  6337. *
  6338.     JSR    STDACK    ;send an ACK
  6339.     LDA    NUMTRY
  6340.     STA    OLDTRY    ;copy try counter
  6341.     LDA    #0
  6342.     STA    NUMTRY    ;reset counter
  6343.     STA    PENDFLG    ;clear char inject flag
  6344.     STA    TFSTOP    ;and interrupt flag
  6345.     STA    BKASENT    ;and flag for ACK/X ACK/Z sent
  6346.     JSR    CLRINT    ;clear interrupt status line
  6347.     JSR    INCNXT    ;step next-packet number by 1
  6348.     JSR    COUNTF    ;add to file count
  6349.     JSR    CLRKBC    ;clear Kbyte count for current file
  6350. *
  6351. * Then switch to state REC_DATA
  6352. *
  6353. RFI380    LDA    #'D'
  6354. RFI385    STA    STATE
  6355.     RTS
  6356. *
  6357. *
  6358. * B received
  6359. * ----------
  6360. *
  6361. RFI400    LDA    NXTPAK
  6362.     CMP    PACNUM    ;is packet sequence OK?
  6363.     BNE    RFI050    ;abort if not
  6364.     JSR    STDACK    ;else send an ACK
  6365.     JSR    PRTOFF    ;and ensure printer is off
  6366. *
  6367. * If in generic mode for server output, make sure screen is tidy
  6368. *
  6369.     BIT    MODE
  6370.     BVS    RFI420    ;j if not generic mode
  6371.     JSR    TIDYLN    ;else tidy the line
  6372. *
  6373. * Then go to state COMPLETE
  6374. *
  6375. RFI420    LDA    #'C'
  6376.     BNE    RFI385
  6377. *
  6378. *
  6379. *
  6380. * ERROR received
  6381. * --------------
  6382. *
  6383. RFI500    JMP    ERRPKT
  6384. *
  6385. *
  6386. * X received
  6387. * ----------
  6388. *
  6389. * This is the header for bulk server output to screen
  6390. *
  6391. RFI600    LDA    NXTPAK    ;is sequence number OK
  6392.     CMP    PACNUM
  6393.     BNE    RFI050    ;j if not
  6394.     JSR    BUFEMP    ;else write packet data to screen
  6395.     JSR    TIDYLN    ;tidy up the output line
  6396.     JSR    STDACK    ;send an ACK
  6397.     JSR    INCNXT    ;step packet counter
  6398.     JSR    RXINIT    ;clear counts and flags
  6399.     JMP    RFI380    ;and go to state REC_DATA
  6400.  
  6401.  
  6402.  
  6403. ***************************************
  6404. *
  6405. * STATE REC_DATA
  6406. * ==============
  6407. *
  6408. ***************************************
  6409.  
  6410. RDATA    JSR    CHKTRY    ;check retry limit
  6411. *
  6412. * Get packet from host
  6413. *
  6414.     JSR    RPACK
  6415.     BCC    RDA040    ;j if got it OK
  6416.     JMP    STDNAK    ;else send a NAK
  6417. *
  6418. * Branch on packet type
  6419. *
  6420. RDA040    CMP    #'D'
  6421.     BEQ    RDA100    ;j if D
  6422.     CMP    #'F'
  6423.     BNE    RDA046    ;j if not F
  6424.     JMP    RDA200
  6425. RDA046    CMP    #'Z'
  6426.     BNE    RDA048    ;j if not Z
  6427.     JMP    RDA300
  6428. RDA048    CMP    #'X'
  6429.     BNE    RDA049    ;j if not X
  6430.     JMP    RDA200
  6431. RDA049    CMP    #'E'
  6432.     BNE    RDA050    ;j if not E
  6433.     JMP    RDA400
  6434. *
  6435. * Packet type unknown here, so abort
  6436. *
  6437. RDA050    JMP    ABORT
  6438. *
  6439. *
  6440. *
  6441. * D received
  6442. * ----------
  6443. *
  6444. RDA100    BIT    BKASENT    ;did we ACK/Z or ACK/X?
  6445.     BPL    RDA120    ;j if not
  6446. *
  6447. * Other side can't handle ACK/X or ACK/Z, so crash to a stop
  6448. *
  6449.     BIT    MODE    ;are we in genric mode for server command?
  6450.     BVC    RDA105    ;j if so - no file to close
  6451.     SEC
  6452.     JSR    FCLOSE    ;close file nicely first
  6453.     JSR    OPTDEL    ;delete it if nesessary
  6454. RDA105    BRK        ;then crunch bang pow zap splatt
  6455.     DFB    0
  6456.     ASC    'Interrupted'
  6457.     DFB    0
  6458. *
  6459. * Not interrupting, so process this
  6460. *
  6461. RDA120    LDA    PACNUM
  6462.     CMP    NXTPAK    ;is it the right sequence?
  6463.     BEQ    RDA160    ;j if it is
  6464. *
  6465. * Packet isn't the one expected.
  6466. *
  6467.     JSR    CHKOTRY    ;check retry limit not exceeded
  6468.     JSR    RPTACK    ;if OK, send an ACK if possible
  6469.     BCS    RDA050    ;abort if not possible
  6470. RDA140    LDA    #0    ;else reset our count
  6471.     STA    NUMTRY
  6472.     RTS
  6473. *
  6474. * Here the D packet is valid, so file it
  6475. *
  6476. RDA160    JSR    BUFEMP    ;this may go to disc
  6477. *
  6478. * Data is put away, possibly to disc, so it's clear to ACK now
  6479. *
  6480.     BIT    TFSTOP    ;had keyboard interrupt?
  6481.     BPL    RDA180    ;j if not
  6482. *
  6483. * User has done CTRL-X or CTRL-Z
  6484. *
  6485.     LDY    #'X'    ;assume CTRL-X
  6486.     BVC    RDA170    ;j if that's right
  6487.     LDY    #'Z'    ;else it's CTRL-Z
  6488. RDA170    JSR    SBKACK    ;send ACK/<char>
  6489.     LDA    #$FF
  6490.     STA    BKASENT    ;note we sent it
  6491.     BMI    RDA190
  6492. *
  6493. * No keyboard interrupt, so keep going
  6494. *
  6495. RDA180    JSR    STDACK    ;ordinary ACK
  6496. RDA190    LDA    NUMTRY
  6497.     STA    OLDTRY    ;save try counter
  6498.     LDA    #0
  6499.     STA    NUMTRY    ;reset it
  6500.     JSR    INCNXT    ;step next-packet number
  6501. *
  6502. * And make sure we're in state REC_DATA
  6503. *
  6504.     LDA    #'D'
  6505.     STA    STATE
  6506.     RTS
  6507. *
  6508. *
  6509. *
  6510. * F or X received
  6511. * ---------------
  6512. *
  6513. * This implies host has lost an ACK from us. Repeat it if we can
  6514. *
  6515. RDA200    JSR    RPTACK
  6516.     BCS    RDA050    ;abort if not appropriate
  6517.     BCC    RDA140    ;else reset counts
  6518. *
  6519. *
  6520. *
  6521. * Z received
  6522. * ----------
  6523. *
  6524. RDA300    LDA    NXTPAK
  6525.     CMP    PACNUM    ;is sequence correct?
  6526.     BNE    RDA050    ;j if not
  6527. *
  6528. * Are we receiving a file or server output?
  6529. *
  6530.     BIT    MODE    ;in for generic mode?
  6531.     BVC    RDA340    ;j if so - it's server output
  6532. *
  6533. * File send is over. We could have a character still to write to it
  6534. *
  6535.     BIT    PENDFLG    ;character pending?
  6536.     BPL    RDA320    ;j if we not
  6537.     LDA    PENDCHR
  6538.     JSR    TOFILE    ;else output pended character
  6539. RDA320    SEC        ;select 'flush buffer'
  6540.     JSR    FCLOSE    ;and close the file
  6541. *
  6542. * Did we or remote interrupt the transfer with CTRL-X or CTRL-Z?
  6543. *
  6544.     BIT    BKASENT
  6545.     BMI    RDA330    ;j if we interrupted
  6546.     LDA    DATLEN    ;else look at EOF packet data field
  6547.     BEQ    RDA340    ;j if there isn't one
  6548.     LDA    RXBUFF    ;else get first character
  6549.     CMP    #'D'
  6550.     BNE    RDA340    ;j if not EOF(D) - not interrupted
  6551. *
  6552. * We do have an interrupted transfer, so maybe delete incoming file
  6553. *
  6554. RDA330    JSR    OPTDEL
  6555. *
  6556. * Then send an ACK and prepare for the next bit
  6557. *
  6558. RDA340    JSR    STDACK
  6559.     JSR    INCNXT    ;step next-packet number
  6560.     JSR    STOTCT    ;clear counters
  6561.     LDA    #0
  6562.     STA    NUMTRY    ;clear the try counter
  6563.     LDA    #'F'
  6564.     STA    STATE    ;and go to state REC_FILE
  6565.     RTS
  6566. *
  6567. *
  6568. *
  6569. * ERROR received
  6570. * --------------
  6571. *
  6572. RDA400    JMP    ERRPKT
  6573.  
  6574.  
  6575. ***************************************
  6576. *
  6577. * STATE SEND_SERVER_INIT
  6578. * ======================
  6579. *
  6580. ***************************************
  6581.  
  6582. SVINIT    JSR    CHKTRY    ;check retry limit
  6583. *
  6584. * Build parameters and send an I packet
  6585. *
  6586.     SEC        ;we're sending here
  6587.     JSR    SPAR    ;build packet
  6588.     LDA    #'I'    ;type is I
  6589.     LDX    #0    ;sequence is 0
  6590.     JSR    SPACK    ;so send it
  6591. *
  6592. * Read the reply
  6593. *
  6594.     JSR    RPACK
  6595.     BCC    SVI040    ;j if OK
  6596.     RTS        ;else stay in this state
  6597. *
  6598. * Branch on packet type
  6599. *
  6600. SVI040    CMP    #'N'
  6601.     BEQ    SVI200    ;j if N
  6602.     CMP    #'Y'
  6603.     BEQ    SVI300    ;j if Y
  6604.     CMP    #'E'
  6605.     BEQ    SVI400    ;j if E
  6606. *
  6607. * Unknown packet type, so abort
  6608. *
  6609.     JMP    ABORT
  6610. *
  6611. *
  6612. * NAK received
  6613. * ------------
  6614. *
  6615. SVI200    RTS        ;stay in this state
  6616. *
  6617. *
  6618. * ACK received
  6619. * ------------
  6620. *
  6621. * This contains server's parameters
  6622. *
  6623. SVI300    JSR    VALSEQ    ;sequence OK?
  6624.     BCS    SVI200    ;j if not - stay in this state
  6625. SVI320    JSR    INPARS    ;else analyse the parameters
  6626.     LDA    #'G'
  6627.     STA    STATE    ;go to state SEND_GEN_CMD
  6628.     LDA    #0
  6629.     STA    NXTPAK    ;restart packet counter
  6630.     STA    NUMTRY    ;and try counter
  6631.     RTS
  6632. *
  6633. *
  6634. * ERROR received
  6635. * --------------
  6636. *
  6637. * This means server does not implement I packets so
  6638. * we assume he'll use default values
  6639. *
  6640. SVI400    LDA    #0    ;fake that we had a zero length ACK
  6641.     STA    DATLEN    ;so we'll use all defaults
  6642.     BEQ    SVI320    ;and go to state SEND_GEN_CMD
  6643.  
  6644.  
  6645. ***************************************
  6646. *
  6647. * STATE SEND_GEN_CMD
  6648. * ==================
  6649. *
  6650. ***************************************
  6651.  
  6652. SNDCMD    JSR    CHKTRY    ;check retry limit
  6653. *
  6654. * Copy the command to the transmit buffer. Here TXDLEN gives the number of
  6655. * bytes in the string, but we have yet to handle quoting and 8th-bit-prefixing.
  6656. * Set up some control values first
  6657. *
  6658.     LDX    #0    ;start pointer to take from string
  6659.     LDY    #0    ;start pointer to insert into transmit buffer
  6660. *
  6661. * Get a byte from the command string and see what we need to do
  6662. *
  6663. SCD010    LDA    SCBUFF,X    ;get the byte
  6664.     CMP    SQUOTE    ;is it the quote we send?
  6665.     BEQ    SCD030    ;j if it is
  6666.     BIT    EBQFLG    ;are we 8th-bit-prefixing?
  6667.     BPL    SCD020    ;j if not - move byte unchanged
  6668.     CMP    EBQCHR    ;else is it the 8-bit-prefix character?
  6669.     BNE    SCD020    ;j if not - move byte unchanged
  6670. *
  6671. * Byte is the 8-bit-prefix, so it has to be quoted
  6672. *
  6673.     LDA    SQUOTE    ;get the quote character
  6674.     JSR    SCD040    ;move it to the transmit buffer
  6675.     LDA    EBQCHR    ;then get the 8-bit-prefix char again
  6676. SCD020    JSR    SCD040    ;move that to the buffer
  6677. *
  6678. * Now see if there's any more to move
  6679. *
  6680. SCD025    INX        ;step remove pointer
  6681.     CPX    TXDLEN    
  6682.     BNE    SCD010    ;j if more to move
  6683. *
  6684. * All moved, so we now have the actual packet size in Y
  6685. *
  6686.     STY    DATLEN    ;set up the length
  6687.     BEQ    SCD045    ;and send the packet
  6688. *
  6689. * Here character is the quote, so we double it
  6690. *
  6691. SCD030    JSR    SCD040    ;output it to the buffer once...
  6692.     JSR    SCD040    ;...and once again
  6693.     JMP    SCD025    ;and round again
  6694. *
  6695. * Here we insert the character into the transmit buffer
  6696. *
  6697. SCD040    CPY    SMAXD    ;is buffer full?
  6698.     BCC    SCD042    ;j if not
  6699.     JMP    PPR900    ;else break
  6700. SCD042    STA    TXBUFF,Y    ;insert char into buffer
  6701.     INY        ;step buffer pointer
  6702.     RTS
  6703. *
  6704. * Here we send the packet that we've just built
  6705. *
  6706. SCD045    LDA    TXTYPE    ;get type
  6707.     LDX    #0    ;sequence is 0
  6708.     JSR    SPACK
  6709. *
  6710. * Then get the reply
  6711. *
  6712.     JSR    RPACK
  6713.     BCC    SCD050    ;j if OK
  6714.     RTS        ;else stay in this state
  6715. *
  6716. * Branch on packet type
  6717. *
  6718. SCD050    CMP    #'S'
  6719.     BEQ    SCD100    ;j if S
  6720.     CMP    #'Y'
  6721.     BEQ    SCD200    ;j if Y
  6722.     CMP    #'N'
  6723.     BEQ    SCD300    ;j if N
  6724.     CMP    #'X'
  6725.     BEQ    SCD400    ;j if X
  6726.     CMP    #'E'
  6727.     BEQ    SCD500    ;j if E
  6728. *
  6729. * Packet type unknown, so break
  6730. *
  6731.     JMP    ABORT
  6732. *
  6733. *
  6734. * S received
  6735. * ----------
  6736. *
  6737. SCD100    JMP    RIN100    ;process params and reply
  6738. *
  6739. *
  6740. * Y received
  6741. * ----------
  6742. *
  6743. * This may contain a message for the screen
  6744. *
  6745. SCD200    JSR    VALSEQ    ;sequence OK?
  6746.     BCS    SCD290    ;j if not - stay in this state
  6747.     JSR    VDUINI    ;else initialise VDU output values
  6748.     JSR    BUFEMP    ;and write data to sceen
  6749.     JSR    TIDYLN    ;make sure screen line is tidy
  6750.     LDA    #'C'
  6751. SCD240    STA    STATE    ;and go to state COMPLETE
  6752. SCD290    RTS
  6753. *
  6754. *
  6755. * N received
  6756. * ----------
  6757. *
  6758. SCD300    RTS        ;stay in this state
  6759. *
  6760. *
  6761. * X received
  6762. * ----------
  6763. *
  6764. SCD400    LDA    PACNUM    ;is sequence OK
  6765.     CMP    NXTPAK
  6766.     BNE    SCD300    ;j if not - stay in this state
  6767.     JSR    VDUINI    ;else initialise VDU output values
  6768.     JSR    BUFEMP    ;and copy packet data to screen
  6769.     JSR    TIDYLN    ;make sure screen line is tidy
  6770.     JSR    STDACK    ;then ACK it
  6771.     JSR    INCNXT    ;step packet number
  6772.     JSR    RXINIT    ;clear counts and flags
  6773.     LDA    #'D'
  6774.     BNE    SCD240    ;and go to state REC_DATA
  6775. *
  6776. *
  6777. * ERROR received
  6778. * --------------
  6779. *
  6780. SCD500    JMP    ERRPKT
  6781.  
  6782.  
  6783.     CHN    BBCSND
  6784. ****** File BBCSB1 *************************************************************
  6785.     START    SB1
  6786. * BBCSB1: Updated 07/07/86 @ 1500
  6787.  
  6788. ***************************************
  6789. *
  6790. * MESS
  6791. * ====
  6792. *
  6793. * Outputs a preset message text
  6794. *
  6795. ***************************************
  6796.  
  6797. MESS    EQU    *
  6798. *
  6799. * Work out start address of string. The lsb is a straight table
  6800. * look-up
  6801. *
  6802.     TAY        ;message number into Y
  6803.     PHA        ;and saved for later
  6804.     LDA    MSGTBL,Y ;get address lsb
  6805.     STA    MPTR0    ;and note it
  6806. *
  6807. * The msb is more complicated. We have a list that gives the number of the
  6808. * first message to start within each page, relative to the
  6809. * page that M0 starts in, so we scan back until we find which page our own
  6810. * message starts in
  6811. *
  6812.     PLA        ;get message number
  6813.     LDY    #MTHCNT+1 ;point past end of list
  6814. MES100    DEY        ;step back one element
  6815.     CMP    MSGTBH,Y ;check with list
  6816.     BCC    MES100    ;j if message in a lower page
  6817. *
  6818. * Y now gives the page number relative to M0 start, so add in the
  6819. * high byte of M0 to get the msb of the address
  6820. *
  6821.     TYA
  6822.     CLC
  6823.     ADC    #<M0
  6824.     STA    MPTR0+1    ;and save the address
  6825. *
  6826. * Now output text, looking for our control characters
  6827. *
  6828.     LDY    #0
  6829. MES200    LDA    (MPTR0),Y ;get character
  6830.     CMP    #LIT    ;is it a special?
  6831.     BCC    MES300    ;j if not
  6832. *
  6833. * Character is a special, so go to the relevant service routine
  6834. *
  6835.     TAX        ;get target address
  6836.     LDA    MSGT1L-LIT,X
  6837.     STA    MPTR1
  6838.     LDA    MSGT1H-LIT,X
  6839.     STA    MPTR1+1
  6840.     JMP    (MPTR1)    ;and into sercvice routine    
  6841. *
  6842. * Not a special character, so output it
  6843. *
  6844. MES300    JSR    OSASCI    ;output it
  6845. MES310    JSR    MES950    ;step pointer on
  6846.     JMP    MES200
  6847. *
  6848. * Here we have EOT for end-of-text
  6849. *
  6850. MES400    RTS        ;finish the routine
  6851. *
  6852. * Here we have LIT to force literal use of the next character
  6853. *
  6854. MES420    JSR    MES950    ;step pointer on
  6855.     LDA    (MPTR0),Y ;get next character
  6856.     JMP    MES300    ;output it
  6857. *
  6858. * Here we have RPT for multiple literal character expansion. This is
  6859. * followed by <count> and <character>
  6860. *
  6861. MES440    JSR    MES950    ;step to count value
  6862.     LDA    (MPTR0),Y ;pick value up
  6863.     TAX        ;save into X
  6864.     JSR    MES950    ;step to data character
  6865.     LDA    (MPTR0),Y ;get it
  6866. MES450    JSR    OSASCI    ;print it
  6867.     DEX
  6868.     BNE    MES450    ;until count expires
  6869.     JMP    MES310    ;then do next character
  6870. *
  6871. * Here we have TXT, which is followed by the text number
  6872. * we recurse into
  6873. *
  6874. MES460    JSR    MES950    ;move pointer on
  6875.     LDA    #1    ;fake a repeat count of 1
  6876.     STA    MWORK0    ;save it
  6877.     BNE    MES510    ;and use MTXT code
  6878. *
  6879. * Here we have XCR, so we output a $0D without conversion
  6880. * to LF-CR
  6881. *
  6882. MES480    LDA    #$0D
  6883.     JSR    OSWRCH
  6884.     JMP    MES310
  6885. *
  6886. * Here we have MTXT, for multiple sub-text
  6887. *
  6888. MES500    JSR    MES950    ;move to next character
  6889.     LDA    (MPTR0),Y ;get the repeat count
  6890.     STA    MWORK0    ;save for a moment
  6891.     JSR    MES950    ;move to text number
  6892. MES510    LDA    (MPTR0),Y ;get sub-text number
  6893. MES512    TAX        ;hold it in X
  6894.     PHA        ;and stack it
  6895.     LDA    MWORK0    ;get repeat count back
  6896.     PHA        ;and stck it
  6897.     TYA        ;stack the current offset
  6898.     PHA
  6899.     LDA    MPTR0    ;stack current text pointer
  6900.     PHA
  6901.     LDA    MPTR0+1
  6902.     PHA
  6903.     TXA        ;get sub-text number back
  6904.     JSR    MESS    ;recurse to do the sub-text
  6905.     PLA        ;then unstack old pointer
  6906.     STA    MPTR0+1
  6907.     PLA
  6908.     STA    MPTR0
  6909.     PLA        ;unstack offset
  6910.     TAY
  6911.     PLA        ;unstack repeat count
  6912.     SEC
  6913.     SBC    #1    ;decrement it
  6914.     BEQ    MES518    ;j if no more to do
  6915.     STA    MWORK0    ;else save it
  6916.     PLA        ;reload text number
  6917.     JMP    MES512    ;and do it again
  6918. MES518    PLA        ;all done so lose text number
  6919.     JMP    MES310    ;and carry on
  6920. *
  6921. * Here we have MSP for multiple space
  6922. *
  6923. MES520    JSR    MES950    ;move to repeat count
  6924.     LDA    (MPTR0),Y ;get the count
  6925.     TAX        ;hold it in X
  6926.     LDA    #' '    ;set up a space as repeated character
  6927.     BNE    MES450    ;and use RPT code
  6928. *
  6929. *
  6930. * Step text pointer
  6931. * -----------------
  6932. *
  6933. MES950    INY
  6934.     BNE    MES960    ;j if still in same page
  6935.     INC    MPTR0+1 ;else move on a page
  6936.     LDY    #0    ;and start offset again at zero
  6937. MES960    RTS        ;and finish
  6938. *
  6939. *
  6940. * Addresses for routines servicing $F0..$FF
  6941. *
  6942. MSGT1L    DFB    >MES420    ;$F9 - LIT
  6943.     DFB    >MES520    ;$FA - MSP
  6944.     DFB    >MES500    ;$FB - MTXT
  6945.     DFB    >MES480    ;$FC - XCR
  6946.     DFB    >MES440    ;$FD - RPT
  6947.     DFB    >MES460    ;$FE - TXT
  6948.     DFB    >MES400    ;$FF - EOT
  6949.  
  6950. MSGT1H    DFB    <MES420    ;$F9 - LIT
  6951.     DFB    <MES520    ;$FA - MSP
  6952.     DFB    <MES500    ;$FB - MTXT
  6953.     DFB    <MES480    ;$FC - XCR
  6954.     DFB    <MES440    ;$FD - RPT
  6955.     DFB    <MES460    ;$FE - TXT
  6956.     DFB    <MES400    ;$FF - EOT
  6957.  
  6958.  
  6959. ***************************************
  6960. *
  6961. * DMESS
  6962. * =====
  6963. *
  6964. * Sends a diagnostic text to parallel
  6965. * printer
  6966. *
  6967. ***************************************
  6968.  
  6969. DMESS    PHA
  6970.     LDA    DEBTOG    ;is debug on?
  6971.     BEQ    DME990    ;j if not - null call
  6972. *
  6973. * Debug is on, so let's do it
  6974. *
  6975.     TXA
  6976.     PHA
  6977.     TYA
  6978.     PHA
  6979. *
  6980. * Select parallel printer output
  6981. *
  6982.     JSR    OPPTR
  6983. *
  6984. * Then do a standard 'print text' call
  6985. *
  6986.     TSX
  6987.     LDA    $103,X    ;get text number
  6988.     JSR    MESS
  6989. *
  6990. * Reset output to VDU
  6991. *
  6992. DME800    JSR    OPVDU
  6993. *
  6994. * And finish
  6995. *
  6996. DME900    PLA
  6997.     TAY
  6998.     PLA
  6999.     TAX
  7000. DME990    PLA
  7001.     RTS
  7002.  
  7003.  
  7004. ***************************************
  7005. *
  7006. * DBYTE
  7007. * =====
  7008. *
  7009. * Outputs one byte to the parallel printer
  7010. * in ASCII if possible
  7011. *
  7012. ***************************************
  7013.  
  7014. DBYTE    PHA
  7015.     LDA    DEBTOG    ;is debug mode on?
  7016.     BEQ    DME990    ;j if not - null call
  7017. *
  7018. * Debug mode is on, so we print
  7019. *
  7020.     CLC        ;note ASCII wanted
  7021. DBY100    TXA
  7022.     PHA
  7023.     TYA
  7024.     PHA
  7025.     PHP        ;save ASCII/hex switch
  7026. *
  7027. * Output byte in required form
  7028. *
  7029.     JSR    OPPTR    ;select parallel printer
  7030.     TSX
  7031.     LDA    $104,X    ;pick up the byte
  7032.     PLP        ;ASCII or hex wanted?
  7033.     BCS    DBY400    ;j if hex wanted
  7034.     CMP    #32
  7035.     BCC    DBY400    ;j if control char
  7036.     CMP    #127
  7037.     BCS    DBY400    ;j if not printable
  7038. DBY300    JSR    OSASCII    ;else print it
  7039.     JMP    DME800    ;and finish
  7040. *
  7041. * Here byte isn't printable, so do it in hex
  7042. *
  7043. DBY400    PHA        ;save the byte
  7044.     LDA    #'<'    ;print '<'
  7045.     JSR    OSWRCH
  7046.     PLA        ;reget the byte
  7047.     JSR    PRHEX    ;print it in hex
  7048.     LDA    #'>'    ;then a '>'
  7049.     JSR    OSWRCH
  7050.     JMP    DME800    ;and end
  7051.  
  7052.  
  7053. ***************************************
  7054. *
  7055. * DPRHEX
  7056. * ======
  7057. *
  7058. * Outputs one byte to parallel printer
  7059. * in hex
  7060. *
  7061. ***************************************
  7062.  
  7063. DPRHEX    PHA
  7064.     LDA    DEBTOG    ;is debugging active?
  7065.     BEQ    DME990    ;j if not
  7066.     SEC        ;else select hex mode
  7067.     BCS    DBY100    ;and print the byte
  7068.  
  7069.  
  7070. ***************************************
  7071. *
  7072. * DCLRLN
  7073. * ======
  7074. *
  7075. * Tidies up the line on the parallel
  7076. * printer with a CR
  7077. *
  7078. ***************************************
  7079.  
  7080. DCLRLN    PHA
  7081.     LDA    DEBTOG    ;is debug on?
  7082.     BEQ    DME990    ;j if not - null call
  7083. *
  7084. * Debug is on, so save registers
  7085. *
  7086.     TXA
  7087.     PHA
  7088.     TYA
  7089.     PHA
  7090. *
  7091. * Select parallel printer output
  7092. *
  7093.     JSR    OPPTR
  7094. *
  7095. * And send a CR
  7096. *
  7097.     LDA    #$0D
  7098.     BNE    DBY300
  7099.  
  7100.  
  7101. ***************************************
  7102. *
  7103. * PRHEX
  7104. * =====
  7105. *
  7106. * Prints value in A in hex
  7107. *
  7108. ***************************************
  7109.  
  7110. PRHEX    PHA        ;save the value
  7111.     LSR    A    ;get top nibble
  7112.     LSR    A
  7113.     LSR    A
  7114.     LSR    A
  7115.     JSR    PRH500    ;print it
  7116.     PLA
  7117.     AND    #$0F    ;get bottom nibble
  7118. PRH500    CMP    #10
  7119.     BCC    PRH600    ;j if 0..9
  7120.     CLC
  7121.     ADC    #'A'-10    ;else form 'A'..'F'
  7122.     BCC    PRH650
  7123. PRH600    ADC    #'0'    ;scale to '0'..'9'
  7124. PRH650    JMP    OSWRCH    ;and print it
  7125.  
  7126.  
  7127. ***************************************
  7128. *
  7129. * PRWHEX
  7130. * ======
  7131. *
  7132. * Prints value in X,Y (low-high) in hex
  7133. *
  7134. ***************************************
  7135.  
  7136. PRWHEX    TXA
  7137.     PHA        ;save low byte
  7138.     TYA
  7139.     JSR    PRHEX    ;print high byte
  7140.     PLA        ;reload low byte
  7141.     JMP    PRHEX    ;print it
  7142.  
  7143.  
  7144. ***************************************
  7145. *
  7146. * INCNXT
  7147. * ======
  7148. *
  7149. * Steps the next-packet number by 1
  7150. *
  7151. ***************************************
  7152.  
  7153. INCNXT    LDX    NXTPAK
  7154.     INX
  7155.     CPX    #64
  7156.     BCC    INX900
  7157.     LDX    #0
  7158. INX900    STX    NXTPAK
  7159.     RTS
  7160.  
  7161.  
  7162. ***************************************
  7163. *
  7164. * OPVDU
  7165. * =====
  7166. *
  7167. * Directs output to the VDU drivers
  7168. *
  7169. ***************************************
  7170.  
  7171. OPVDU    LDX    #%00000000
  7172. OPV100    LDY    #0
  7173.     LDA    #3
  7174.     JMP    OSBYTE
  7175.  
  7176.  
  7177. ***************************************
  7178. *
  7179. * OPPTR
  7180. * =====
  7181. *
  7182. * Directs output to printer
  7183. *
  7184. ***************************************
  7185.  
  7186. OPPTR    LDX    #%00001010
  7187.     BNE    OPV100
  7188.  
  7189.  
  7190. ***************************************
  7191. *
  7192. * MKGBPB
  7193. * ======
  7194. *
  7195. * Partially fills an OSGBPB control 
  7196. * block
  7197. *
  7198. ***************************************
  7199.  
  7200. MKGBPB    LDA    FHAND    ;set handle as byte 0
  7201.     STA    GBPBLK
  7202. *
  7203. * Set transfer address to the base of the file buffer
  7204. *
  7205.     LDA    FBUFF
  7206.     STA    GBPBLK+1
  7207.     LDA    FBUFF+1
  7208.     STA    GBPBLK+2
  7209.     LDY    #$FF
  7210.     STY    GBPBLK+3
  7211.     STY    GBPBLK+4
  7212. *
  7213. * Set top two bytes of transfer size to 0
  7214. *
  7215.     INY
  7216.     STY    GBPBLK+7
  7217.     STY    GBPBLK+8
  7218. *
  7219. * Set sequential pointer to 0
  7220. *
  7221.     STY    GBPBLK+9
  7222.     STY    GBPBLK+10
  7223.     STY    GBPBLK+11
  7224.     STY    GBPBLK+12
  7225. *
  7226. * And that's it
  7227. *
  7228.     RTS
  7229.  
  7230.  
  7231. ***************************************
  7232. *
  7233. * TOCHAR
  7234. * ======
  7235. *
  7236. * Makes a control char printable
  7237. *
  7238. ***************************************
  7239.  
  7240. TOCHAR    CLC
  7241.     ADC    #' '
  7242.     RTS
  7243.  
  7244.  
  7245. ***************************************
  7246. *
  7247. * UNCHAR
  7248. * ======
  7249. *
  7250. * Reverses the action of TOCHAR
  7251. *
  7252. ***************************************
  7253.  
  7254. UNCHAR    SEC
  7255.     SBC    #' '
  7256.     RTS    
  7257.  
  7258.  
  7259. ***************************************
  7260. *
  7261. * FLSHKB
  7262. * ======
  7263. *
  7264. * Flushes the keyboard buffer
  7265. *
  7266. ***************************************
  7267.  
  7268. FLSHKB    LDA    #15
  7269.     JMP    OB10
  7270.  
  7271.  
  7272. ***************************************
  7273. *
  7274. * INKEY
  7275. * =====
  7276. *
  7277. * Does an INKEY(0) call
  7278. *
  7279. ***************************************
  7280.  
  7281. INKEY    JSR    SUSEXF    ;suspend any EXEC file
  7282.     LDX    #0
  7283. INK100    LDA    #$81
  7284.     JSR    OBX0    ;do INKEY(0)
  7285.     PHP        ;save status result
  7286.     TXA
  7287.     PHA        ;and the key code
  7288.     JSR    RSTEXF    ;reset any EXEC file
  7289.     PLA        ;and reset key code and status
  7290.     TAX
  7291.     PLP
  7292.     RTS
  7293.  
  7294.  
  7295. ***************************************
  7296. *
  7297. * HEXFLG
  7298. * ======
  7299. *
  7300. * Checks if a character is X, $ or &
  7301. *
  7302. ***************************************
  7303.  
  7304. HEXFLG    JSR    UPPER    ;into upper case
  7305.     CMP    #'X'
  7306.     BEQ    HFG800    ;j if X
  7307.     CMP    #'$'
  7308.     BEQ    HFG800    ;j if $
  7309.     CMP    #'&'
  7310.     BEQ    HFG800    ;j if &
  7311. *
  7312. * Not in the list
  7313. *
  7314.     SEC
  7315.     RTS
  7316. *
  7317. * In the list
  7318. *
  7319. HFG800    CLC
  7320.     RTS
  7321.  
  7322.  
  7323. ***************************************
  7324. *
  7325. * CHKFNL
  7326. * ======
  7327. *
  7328. * Checks if current param is too long
  7329. * to be a filename
  7330. *
  7331. ***************************************
  7332.  
  7333. CHKFNL    LDA    CURLEN
  7334.     CMP    #MAXFNL
  7335.     BCS    CFL900    ;j if too long
  7336.     RTS
  7337. *
  7338. * Parameter is too long
  7339. *
  7340. CFL900    LDA    #195    ;select error text
  7341.     JMP    PARMERR    ;and report
  7342.  
  7343.  
  7344. ***************************************
  7345. *
  7346. * TELLACT
  7347. * =======
  7348. *
  7349. * Reports if a toggle is on or off
  7350. *
  7351. ***************************************
  7352.  
  7353. TELLACT CMP    #$FF    ;check the toggle
  7354.     BEQ    TAC400    ;j if active
  7355.     LDA    #126    ;else say it's off
  7356.     BNE    TAC410
  7357. TAC400    LDA    #127    ;get text for 'on'
  7358. TAC410    JMP    MESS    ;print the text
  7359.  
  7360.  
  7361. ***************************************
  7362. *
  7363. * WHATFS
  7364. * ======
  7365. *
  7366. * Notes number of current filing system
  7367. *
  7368. ***************************************
  7369.  
  7370. WHATFS    LDA    #0
  7371.     TAY
  7372.     LDX    #>WORK0    ;point dummy control block
  7373.     JSR    OSARGS    ;get number in A
  7374.     STA    FSNUM    ;note the number
  7375.     RTS    
  7376.  
  7377.  
  7378. ***************************************
  7379. *
  7380. * LOGST
  7381. * =====
  7382. *
  7383. * Logs state of a state switcher
  7384. *
  7385. ***************************************
  7386.  
  7387. LOGST    JSR    DMESS    ;log heading
  7388.     LDA    STATE
  7389.     JSR    DBYTE    ;log the state letter
  7390.     JMP    DCLRLN    ;tidy up the line
  7391.  
  7392.  
  7393. ***************************************
  7394. *
  7395. * PRTON / PRTOFF
  7396. * ==============
  7397. *
  7398. * Turns printer on/off with VDU 2/3
  7399. *
  7400. ***************************************
  7401.  
  7402. PRTON    LDA    #2
  7403. PON100    JMP    OSWRCH
  7404.  
  7405. PRTOFF    LDA    #3
  7406.     BNE    PON100
  7407.  
  7408.  
  7409.     IF    RAM
  7410. ***************************************
  7411. *
  7412. * CKSHAD
  7413. * ======
  7414. *
  7415. * Errors if we do not have shadow screen
  7416. * capability
  7417. *
  7418. ***************************************
  7419.  
  7420. CKSHAD    BIT    SHADOW
  7421.     BPL    CKD900    ;j if shadow capability
  7422.     RTS        ;else OK
  7423. *
  7424. * No shadow capability, so we BRK
  7425. *
  7426. CKD900    BRK
  7427.     DFB    0
  7428.     ASC    'Not on BBC B'
  7429.     DFB    0
  7430.     FI
  7431.  
  7432. ***************************************
  7433. *
  7434. * GETACIA
  7435. * =======
  7436. *
  7437. * Masks 6850 IRQ from the system
  7438. *
  7439. ***************************************
  7440.  
  7441. GETACIA LDX    #0
  7442. GAC100    LDA    #$E8
  7443.     JMP    OBX0
  7444.  
  7445.  
  7446. ***************************************
  7447. *
  7448. * LOSEACIA
  7449. * ========
  7450. *
  7451. * Allows the system to see 6850 IRQ
  7452. *
  7453. ***************************************
  7454.  
  7455. LOSEACIA LDX    #$FF
  7456.     BMI    GAC100
  7457.  
  7458.  
  7459.     NEXT    BBCSB2
  7460. ****** File BBCSB2 *************************************************************
  7461.     START    SB2
  7462. * BBCSB2: Updated 10/05/86 @ 1900
  7463.  
  7464. ***************************************
  7465. *
  7466. * REPORT
  7467. * ======
  7468. *
  7469. * Reports termination of a transfer
  7470. *
  7471. ***************************************
  7472.  
  7473. REPORT    LDA    #17
  7474.     JSR    MESS    ;print "completed"
  7475.     LDA    #51    ;and set status on screen to "idle"
  7476.     JSR    PRTSST
  7477. *
  7478. * If command source is keyboard we wait for a CR
  7479. *
  7480.     LDA    CSOURCE    ;get source indicator
  7481.     BNE    REP600    ;j if source is TAKE file
  7482.     JMP    WTCMODE    ;else wait for CR
  7483. *
  7484. * Source is take file. Close it if CTRL-Z was used
  7485. *
  7486. REP600    BIT    TFSTOP    ;was transfer interrupted?
  7487.     BPL    REP800    ;j if not
  7488.     JMP    WAI900    ;else back to keyboard input
  7489. *
  7490. * Not interrupted, so just wait 2 seconds
  7491. *
  7492. REP800    LDA    #2
  7493.     JMP    WAIT
  7494.  
  7495.  
  7496. ***************************************
  7497. *
  7498. * UPPER
  7499. * =====
  7500. *
  7501. * Converts lower case to upper
  7502. *
  7503. ***************************************
  7504.  
  7505. UPPER    CMP    #'a'
  7506.     BCC    UPP900    ;j if not 'a'..'z'
  7507.     CMP    #'z'+1
  7508.     BCS    UPP900    ;j if not 'a'..'z'
  7509.     AND    #$DF    ;else convert to upper
  7510. UPP900    RTS
  7511.  
  7512.  
  7513. ***************************************
  7514. *
  7515. * ONOFPAR
  7516. * =======
  7517. *
  7518. * Gets a parameter and analyses it as
  7519. * ON or OFF
  7520. *
  7521. ***************************************
  7522.  
  7523. ONOFPAR EQU    *
  7524. *
  7525. * Select the commnd table and get the parameter
  7526. *
  7527.     LDX    #>ONOFTB
  7528.     LDY    #<ONOFTB
  7529.     JSR    SELTAB
  7530.     JSR    MPARAM    ;get parameter
  7531.     JMP    SCANTAB    ;validate it
  7532.  
  7533. ONOFTB    DW    0    ;no jump table
  7534.     CMD    3,'OFF'
  7535.     CMD    2,'ON'
  7536.     DFB    0
  7537.  
  7538.  
  7539. ***************************************
  7540. *
  7541. * BRKTXT
  7542. * ======
  7543. *
  7544. * Outputs the text for a BRK
  7545. *
  7546. ***************************************
  7547.  
  7548. BRKTXT    JSR    LOCATE    ;find where we are
  7549. *
  7550. * Now print the text, stopping at column 79 or end-of-text
  7551. *
  7552.     LDY    #1    ;start past error number
  7553. BTX100    LDA    ($FD),Y ;get a byte
  7554.     BEQ    BTX900    ;j if end-of-text
  7555.     JSR    OSWRCH    ;else print it
  7556.     INY
  7557.     INX
  7558.     CPX    #80
  7559.     BNE    BTX100    ;j if not at end of line now
  7560. *
  7561. * And finish
  7562. *
  7563. BTX900    RTS
  7564.  
  7565.  
  7566. ***************************************
  7567. *
  7568. * SPFILL
  7569. * ======
  7570. *
  7571. * Spacefills current line to the end
  7572. *
  7573. ***************************************
  7574.  
  7575. SPFILL    JSR    LOCATE    ;find where we are
  7576.     LDA    #28    ;and form window on the rest of
  7577.     JSR    OSWRCH    ;the line
  7578.     TXA
  7579.     JSR    OSWRCH    ;left X is where we are
  7580.     TYA
  7581.     JSR    OSWRCH    ;bottom Y is this line
  7582.     LDA    MODE    ;get system mode
  7583.     LSR    A
  7584.     BCC    SPF200    ;j if not terminal - screen is 40 wide
  7585.     LDX    TTYPE    ;else get terminal type
  7586.     LDA    SPFTB1,X ;get rh col from table
  7587.     BNE    SPF300
  7588. SPF200    LDA    #39    ;here it's not terminal
  7589. SPF300    JSR    OSWRCH    ;write rh X as rh of screen
  7590.     TYA
  7591.     JSR    OSWRCH    ;top Y is this line
  7592.     LDA    #62
  7593.     JSR    MESS    ;clear window and reset to full screen
  7594.     JMP    REPOSN    ;put cursor back where it was
  7595.  
  7596. SPFTB1    DFB    39,79,79
  7597.  
  7598.  
  7599. ***************************************
  7600. *
  7601. * DISFN
  7602. * =====
  7603. *
  7604. * Displays a filename
  7605. *
  7606. ***************************************
  7607.  
  7608. DISFN    STX    PTR3    ;save pointer to name
  7609.     STY    PTR3+1
  7610.     JSR    LOCATE    ;find where we are on screen
  7611. *
  7612. * Write text, stopping at a CR or column 39
  7613. *
  7614.     LDY    #0
  7615. DFN200    CPX    #40    ;off end of screen?
  7616.     BEQ    BTX900    ;j if so - stop her
  7617.     LDA    (PTR3),Y ;else get next byte
  7618.     CMP    #$0D
  7619.     BEQ    DFN900    ;j if CR
  7620.     JSR    OSWRCH
  7621.     INX
  7622.     INY
  7623.     BNE    DFN200    ;else carry on
  7624. *
  7625. * Then spacefill to end of line
  7626. *
  7627. DFN900    JMP    SPFILL
  7628.  
  7629.  
  7630. ***************************************
  7631. *
  7632. * WTCMODE
  7633. * =======
  7634. *
  7635. * Prompts and waits for key on return
  7636. * to command mode
  7637. *
  7638. ***************************************
  7639.  
  7640. WTCMODE LDA    #16
  7641.     JSR    MESS    ;prompt for a key
  7642.     JSR    FLSHKB    ;flush keyboard buffer
  7643.     JSR    KEYRD    ;and wait for a key, bypassing EXEC file
  7644. *
  7645. * Clear the screen and finish
  7646. *
  7647.     LDA    #$0C
  7648.     JMP    OSWRCH
  7649.  
  7650.  
  7651.  
  7652. **************************************
  7653. *
  7654. * PRDEC
  7655. * =====
  7656. *
  7657. * Print number in X,Y in decimal
  7658. *
  7659. **************************************
  7660.  
  7661. PRDEC    STX    ASCNUM    ;save original value
  7662.     STY    ASCNUM+1
  7663.     PHP        ;save 5/3 digit flag
  7664. *
  7665. * Clear output area to "00000"
  7666. *
  7667.     LDA    #'0'
  7668.     LDX    #4
  7669. PRD100    STA    NUM,X
  7670.     DEX
  7671.     BPL    PRD100
  7672. *
  7673. * Do a subtract loop for successive powers of 10
  7674. *
  7675.     LDX    #0    ;prepare subtract loop
  7676. PRD200    LDA    ASCNUM
  7677. PRD210    SEC
  7678.     SBC    TENL,X    ;subtract next power of 10
  7679.     PHA
  7680.     LDA    ASCNUM+1
  7681.     SBC    TENH,X
  7682.     BCC    PRD300    ;j if carry out
  7683. *
  7684. * No carry from this, so add one to this power of
  7685. * 10 in the output array
  7686. *
  7687.     INC    NUM,X
  7688.     STA    ASCNUM+1 ;and note new value
  7689.     PLA
  7690.     STA    ASCNUM
  7691.     JMP    PRD210
  7692. *
  7693. * Subtraction caused a carry, so no more left for this power of 10
  7694. *
  7695. PRD300    PLA        ;tidy the stack up
  7696.     INX
  7697.     CPX    #4
  7698.     BCC    PRD200    ;do next power of ten
  7699. *
  7700. * Now add in what's left in the original as the units figure
  7701. *
  7702.     LDA    ASCNUM
  7703.     CLC
  7704.     ADC    #'0'
  7705.     STA    NUM,X
  7706. *
  7707. * Now scan the output list to do zero suppression
  7708. *
  7709.     LDX    #0    ;assume we want 5 digits
  7710.     PLP        ;then look at flag
  7711.     BCC    PRD400    ;j if 5 wanted
  7712.     LDX    #2    ;else we send last 3 only
  7713. PRD400    LDA    NUM,X    ;get output digit
  7714.     CMP    #'0'
  7715.     BNE    PRD450    ;j if not '0' - end suppression
  7716.     LDA    #' '
  7717.     JSR    OSWRCH    ;else output a space instead
  7718.     INX
  7719.     CPX    #4
  7720.     BNE    PRD400
  7721. *
  7722. * Suppression ended here, so print digits unchanged
  7723. *
  7724. PRD430    LDA    NUM,X
  7725. PRD450    JSR    OSWRCH
  7726.     INX
  7727.     CPX    #5
  7728.     BNE    PRD430
  7729.     RTS
  7730.  
  7731. TENL    HEX    '10E8640A'
  7732. TENH    HEX    '27030000'
  7733.  
  7734.  
  7735. ***************************************
  7736. *
  7737. * CLRKBC
  7738. * ======
  7739. *
  7740. * Clears and displays the Kilobyte count
  7741. * for the current file
  7742. *
  7743. ***************************************
  7744.  
  7745. CLRKBC    LDA    #0
  7746.     STA    KBYTEC    ;clear count of Kbytes
  7747.     STA    KBYTEC+1
  7748.     STA    BYTESC    ;reset count down
  7749.     LDA    #4
  7750.     STA    BYTESC+1
  7751.     JMP    DISKBC    ;display cleared total
  7752.  
  7753.  
  7754. ***************************************
  7755. *
  7756. * STATUS
  7757. * ======
  7758. *
  7759. * Displays the status screen and
  7760. * selects transfer mode, clearing counts
  7761. *
  7762. ***************************************
  7763.  
  7764. STATUS    LDA    #%11000000
  7765.     STA    MODE    ;set transfer mode
  7766.     LDA    #10
  7767.     JSR    MESS    ;show status display
  7768.     JSR    CSROFF    ;turn off cursor
  7769. *
  7770. * Now clear some counters
  7771. *
  7772.     JSR    STOTCT    ;packets, etc
  7773.     LDA    #0
  7774.     STA    KBYTET    ;total Kbytes in group
  7775.     STA    KBYTET+1
  7776. *
  7777. * Now put up the current file type
  7778. *
  7779.     LDA    #72
  7780.     JSR    MESS    ;position cursor
  7781.     JMP    PRFTYPE    ;and output it
  7782.  
  7783.  
  7784. ***************************************
  7785. *
  7786. * STOTCT
  7787. * ======
  7788. *
  7789. * Initialises the packet total counters
  7790. *
  7791. ***************************************
  7792.  
  7793. STOTCT    LDA    #0
  7794.     STA    PKTCNT    ;total packet count
  7795.     STA    PKTCNT+1
  7796.     STA    RTRCNT    ;total retry count
  7797.     STA    RTRCNT+1
  7798.     STA    TMOCNT    ;timeout count
  7799.     STA    TMOCNT+1
  7800. STT900    RTS
  7801.  
  7802.  
  7803. ***************************************
  7804. *
  7805. * COUNTP
  7806. * ======
  7807. *
  7808. * Increments and displays the total
  7809. * packet count
  7810. *
  7811. ***************************************
  7812.  
  7813. COUNTP    INC    PKTCNT    ;step counter
  7814.     BNE    CTP400
  7815.     INC    PKTCNT+1
  7816. CTP400    BIT    MODE    ;are we in transfer or generic mode?
  7817.     BVC    STT900    ;j if generic - no display
  7818.     LDA    #36
  7819.     JSR    MESS    ;position cursor
  7820.     LDX    PKTCNT
  7821.     LDY    PKTCNT+1
  7822.     CLC        ;select 5 digit print
  7823.     JMP    PRDEC    ;print the value
  7824.  
  7825.  
  7826. ***************************************
  7827. *
  7828. * COUNTR
  7829. * ======
  7830. *
  7831. * Increments and displays the total
  7832. * retry count
  7833. *
  7834. ***************************************
  7835.  
  7836. COUNTR    INC    RTRCNT    ;step the value
  7837.     BNE    CTR400
  7838.     INC    RTRCNT+1
  7839. CTR400    BIT    MODE    ;are we in transfer or generic mode?
  7840.     BVC    STT900    ;j if generic - no display
  7841.     LDA    #37
  7842.     JSR    MESS    ;position cursor
  7843.     LDX    RTRCNT
  7844.     LDY    RTRCNT+1
  7845.     CLC        ;select 5 digit print
  7846.     JMP    PRDEC    ;and print the value
  7847.  
  7848.  
  7849. ***************************************
  7850. *
  7851. * COUNTB
  7852. * ======
  7853. *
  7854. * Increments the bytes transferred count
  7855. * and maintains display in Kilobytes
  7856. *
  7857. ***************************************
  7858.  
  7859. COUNTB    PHA        ;save registers
  7860.     TYA
  7861.     PHA
  7862.     TXA
  7863.     PHA
  7864.     DEC    BYTESC    ;step byte countdown
  7865.     BNE    CTB900    ;j if not expired
  7866.     DEC    BYTESC+1
  7867.     BNE    CTB900    ;j if not expired
  7868. *
  7869. * We've completed a kilobyte. Refresh countdown
  7870. *
  7871.     LDA    #4
  7872.     STA    BYTESC+1
  7873. *
  7874. * Step and display Kbyte count for whole group
  7875. *
  7876.     INC    KBYTET    ;step value
  7877.     BNE    CTB500
  7878.     INC    KBYTET+1
  7879. CTB500    LDA    #149
  7880.     JSR    MESS    ;position cursor
  7881.     LDX    KBYTET    ;pick up value
  7882.     LDY    KBYTET+1
  7883.     SEC        ;select 3 digit field
  7884.     JSR    PRDEC    ;print it
  7885. *
  7886. * Step and display Kbyte count for current file
  7887. *
  7888.     INC    KBYTEC    ;step value
  7889.     BNE    CTB600
  7890.     INC    KBYTEC+1
  7891. CTB600    JSR    DISKBC    ;and display it
  7892. *
  7893. * Restore registers and finish
  7894. *
  7895. CTB900    PLA
  7896.     TAX
  7897.     PLA
  7898.     TAY
  7899.     PLA
  7900.     RTS
  7901.  
  7902.  
  7903. ***************************************
  7904. *
  7905. * DISKBC
  7906. * ======
  7907. *
  7908. * Displays the kilobyte count for the
  7909. * current file
  7910. *
  7911. ***************************************
  7912.  
  7913. DISKBC    LDA    #145
  7914.     JSR    MESS    ;position cursor
  7915.     LDX    KBYTEC    ;get the value
  7916.     LDY    KBYTEC+1
  7917.     SEC        ;select 3 digit field
  7918.     JMP    PRDEC    ;print value
  7919.  
  7920.  
  7921. ***************************************
  7922. *
  7923. * ABORT
  7924. * =====
  7925. *
  7926. * Sets system into Abort state
  7927. *
  7928. ***************************************
  7929.  
  7930. ABORT    PHA        ;save the bad packet type
  7931.     LDA    #209
  7932.     JSR    DMESS    ;print diagnostic text
  7933.     PLA
  7934.     JSR    DBYTE    ;print bad packet type
  7935.     JSR    DCLRLN    ;clear diagnostic line
  7936.     LDA    #'A'
  7937.     STA    STATE    ;set new state
  7938.     BRK        ;and crunch
  7939.     DFB    0
  7940.     ASC    'Protocol error'
  7941.     DFB    0    
  7942.  
  7943.  
  7944. ***************************************
  7945. *
  7946. * DISLFN
  7947. * ======
  7948. *
  7949. * Displays the local filename
  7950. *
  7951. ***************************************
  7952.  
  7953. DISLFN    LDA    #29
  7954.     JSR    MESS    ;position cursor
  7955.     LDX    #>LFNAME ;point to buffer
  7956.     LDY    #<LFNAME
  7957.     JMP    DISFN    ;and display it
  7958.  
  7959.  
  7960. ***************************************
  7961. *
  7962. * DISRFN
  7963. * ======
  7964. *
  7965. * Displays the remote filename
  7966. *
  7967. ***************************************
  7968.  
  7969. DISRFN    LDA    #28
  7970.     JSR    MESS    ;position cursor
  7971.     LDX    #>RFNAME ;point to buffer
  7972.     LDY    #<RFNAME
  7973.     JMP    DISFN    ;and display it    
  7974.  
  7975.  
  7976. ***************************************
  7977. *
  7978. * CSRON
  7979. * =====
  7980. *
  7981. * Turns the cursor on
  7982. *
  7983. ***************************************
  7984.  
  7985. CSRON    LDA    #43
  7986.     JMP    MESS
  7987.  
  7988.  
  7989. ***************************************
  7990. *
  7991. * CSROFF
  7992. * ======
  7993. *
  7994. * Turns the cursor off
  7995. *
  7996. ***************************************
  7997.  
  7998. CSROFF    LDA    #44
  7999.     JMP    MESS
  8000.  
  8001.  
  8002. ***************************************
  8003. *
  8004. * ESCON/ESCOFF
  8005. * ============
  8006. *
  8007. * Controls whether ESCAPE generates a
  8008. * $1B or causes an ESCAPE condition
  8009. *
  8010. ***************************************
  8011.  
  8012. ESCON    LDA    #229
  8013.     JMP    OB00
  8014.  
  8015. ESCOFF    LDA    #229
  8016.     JMP    OB10
  8017.  
  8018.  
  8019. ***************************************
  8020. *
  8021. * SETCRS
  8022. * ======
  8023. *
  8024. * Sets BRK restart details for command
  8025. * mode loop
  8026. *
  8027. ***************************************
  8028.  
  8029. SETCRS    STX    STKRST    ;save stck point
  8030.     LDX    #>CMO100 ;declare restart vector
  8031.     STX    RESTART
  8032.     LDX    #<CMO100
  8033.     STX    RESTART+1
  8034.     RTS
  8035.  
  8036.  
  8037. ***************************************
  8038. *
  8039. * GETBRK
  8040. * ======
  8041. *
  8042. * Takes the BRK vector
  8043. *
  8044. ***************************************
  8045.  
  8046. GETBRK    LDA    #>BRKH    ;point it to our BRK handler
  8047.     STA    BRKV    ;it's easy since BRKV is non-extended
  8048.     LDA    #<BRKH
  8049.     STA    BRKV+1
  8050.     RTS
  8051.  
  8052.  
  8053. ***************************************
  8054. *
  8055. * WIDPAR
  8056. * ======
  8057. *
  8058. * Gets a "40"/"80" parameter and checks it's
  8059. * the last
  8060. *
  8061. ***************************************
  8062.  
  8063. WIDPAR    LDX    #>WIDTAB ;point to table
  8064.     LDY    #<WIDTAB
  8065.     JSR    MPARTAB    ;get the parameter
  8066.     CLC        ;allow abbreviations
  8067.     JSR    SCANTAB    ;and validate it
  8068.     JMP    CONFIRM    ;check no more params
  8069.  
  8070. WIDTAB    DW    0    ;no jump table
  8071.     CMD    2,'80'
  8072.     CMD    2,'40'
  8073.     DFB    0
  8074.  
  8075.  
  8076. ***************************************
  8077. *
  8078. * STMDE3
  8079. * ======
  8080. *
  8081. * Switches to MODE 3
  8082. *
  8083. ***************************************
  8084.  
  8085. STMDE3    LDA    TVFLAG    ;do we do a *TV?
  8086.     BEQ    SMD100    ;j if not
  8087.     LDA    #$90
  8088.     LDX    TVPAR1
  8089.     LDY    TVPAR2
  8090.     JSR    OSBYTE    ;else do the *TV
  8091. SMD100    LDA    #210
  8092.     JSR    MESS    ;go to MODE 3...
  8093. SMD200    LDA    #134
  8094.     JSR    MESS    ;...then VDU 19,1
  8095.     LDA    VDUCOL
  8096.     JSR    OSWRCH    ;output foreground colour
  8097.     LDA    #34
  8098.     JMP    MESS    ;and 0,0,0 to finish off
  8099.  
  8100.  
  8101. ***************************************
  8102. *
  8103. * KINIT
  8104. * =====
  8105. *
  8106. * Initialises protocol values and counts
  8107. *
  8108. ***************************************
  8109.  
  8110. KINIT    LDA    SPADC    ;pad character we send
  8111.     STA    XSPADC
  8112.     LDA    SNPAD    ;number of them
  8113.     STA    XSNPAD
  8114.     LDA    SEOLN    ;EOLN byte we send
  8115.     STA    XSEOLN
  8116.     LDA    #79    ;default packet DATA length + 1
  8117.     STA    SMAXD
  8118.     LDA    #0
  8119.     STA    NXTPAK    ;packet sequence
  8120.     STA    NUMTRY    ;try counter
  8121.     RTS
  8122.  
  8123.  
  8124. ***************************************
  8125. *
  8126. * SUSEXF
  8127. * ======
  8128. *
  8129. * Suspends an EXEC file, taking future
  8130. * input from keyboard
  8131. *
  8132. ***************************************
  8133.  
  8134. SUSEXF    LDA    #$C6
  8135.     JSR    OB00    ;reac EXEC handle and clear it
  8136.     STX    EXECH    ;save old value
  8137.     RTS
  8138.  
  8139.  
  8140. ***************************************
  8141. *
  8142. * RSTEXF
  8143. * ======
  8144. *
  8145. * Resets EXEC file handle to previous
  8146. * value
  8147. *
  8148. ***************************************
  8149.  
  8150. RSTEXF    PHA
  8151.     PHP
  8152.     LDA    #$C6
  8153.     LDX    EXECH
  8154.     JSR    OBX0
  8155.     PLP
  8156.     PLA
  8157. REX900    RTS
  8158.  
  8159.  
  8160. ***************************************
  8161. *
  8162. * SETPAD
  8163. * ======
  8164. *
  8165. * Sets base value for Master 128 keypad
  8166. *
  8167. ***************************************
  8168.  
  8169. SETPAD    LDA    #238
  8170.     JMP    OBX0
  8171.  
  8172.  
  8173. ***************************************
  8174. *
  8175. * CLTXF
  8176. * =====
  8177. *
  8178. * Closes TRANSMIT file
  8179. *
  8180. ***************************************
  8181.  
  8182. CLTXF    LDY    TXHAND
  8183.     BEQ    REX900    ;j if file not open
  8184.     LDA    #0
  8185.     STA    TXHAND    ;else clear the handle
  8186.     JMP    OSFIND    ;and close it
  8187.  
  8188.  
  8189.     NEXT    BBCSB3
  8190. ****** File BBCSB3 *************************************************************
  8191.     START    SB3
  8192. * BBCSB3: Updated 09/05/86 @ 1830
  8193.  
  8194. ***************************************
  8195. *
  8196. * CHKTRY
  8197. * ======
  8198. *
  8199. * Tests the NUMTRY counter
  8200. *
  8201. ***************************************
  8202.  
  8203. CHKTRY    LDA    NUMTRY    ;get the value
  8204.     INC    NUMTRY    ;increment it
  8205. CKT050    CMP    MAXTRY    ;has it reached limit?
  8206.     BCS    CKT900    ;j if reached limit
  8207. *
  8208. * Not at limit yet - is this first go or a retry?
  8209. *
  8210. CKT100    CMP    #0
  8211.     BEQ    CKT400    ;j if first time
  8212. CKT200    JMP    COUNTR    ;else step count of repeats
  8213. CKT400    RTS
  8214. *
  8215. * Retry limit reached, so error
  8216. *
  8217. CKT900    BRK
  8218.     DFB    0
  8219.     ASC    'Retry limit exceeded'
  8220.     DFB    0
  8221.  
  8222.  
  8223. ***************************************
  8224. *
  8225. * CHKOTRY
  8226. * =======
  8227. *
  8228. * Tests the OLDTRY counter
  8229. *
  8230. ***************************************
  8231.  
  8232. CHKOTRY LDA    OLDTRY    ;get the value
  8233.     INC    OLDTRY    ;increment it
  8234.     JMP    CKT050    ;and check for limit
  8235.  
  8236.  
  8237. ***************************************
  8238. *
  8239. * PRTSST
  8240. * ======
  8241. *
  8242. * Puts system status on status screen
  8243. *
  8244. ***************************************
  8245.  
  8246. PRTSST    BIT    MODE    ;are we in generic or transfer mode?
  8247.     BVC    CKT400    ;j if generic - no display
  8248.     PHA        ;else save message number
  8249.     LDA    #54
  8250.     JSR    MESS    ;position cursor
  8251.     PLA
  8252.     JMP    MESS    ;then send text
  8253.  
  8254.  
  8255. ***************************************
  8256. *
  8257. * NUMPAR
  8258. * ======
  8259. *
  8260. * Converts current parameter to binary
  8261. *
  8262. ***************************************
  8263.  
  8264. NUMPAR    LDY    #0    ;clear totals byte
  8265.     STY    NUM
  8266.     STY    NUM+1
  8267. *
  8268. * Look at first byte to see if number is in hex
  8269. *
  8270.     LDA    (CURPAR),Y ;get the byte
  8271.     JSR    HEXFLG    ;is it $, X or &?
  8272.     BCS    NPR210    ;j if not - value is decimal
  8273.     JMP    HXP800    ;else do it in hex
  8274. *
  8275. * Get next byte from param and check it's numeric
  8276. *
  8277. NPR200    LDA    (CURPAR),Y
  8278.     SEC
  8279. NPR210    SBC    #'0'    ;scale to "0"=0
  8280.     BMI    NPR900    ;j if not 0..9
  8281.     CMP    #10
  8282.     BCS    NPR900    ;j if not 0..9
  8283. *
  8284. * Multiply current total by 10 and add in new digit
  8285. *
  8286.     STA    NUM+1    ;save new digit
  8287.     LDA    NUM    ;get old total
  8288.     ASL    A
  8289.     STA    NUM    ;save total*2
  8290.     ASL    A
  8291.     ASL    A    ;form total*8
  8292.     CLC
  8293.     ADC    NUM    ;form total*10
  8294.     CLC
  8295.     ADC    NUM+1    ;add in new digit
  8296.     STA    NUM    ;save new total
  8297. *
  8298. * Carry on to end of parameter
  8299. *
  8300.     INY
  8301.     CPY    CURLEN
  8302.     BNE    NPR200    ;j if not at end
  8303. *
  8304. * Return the ls byte of the value
  8305. *
  8306.     LDA    NUM    
  8307.     CLC
  8308.     RTS
  8309. *
  8310. * Here a non-numeric byte was met
  8311. *
  8312. NPR900    LDA    #196    ;select error text
  8313.     JMP    PARMERR    ;and report
  8314.  
  8315.  
  8316. ***************************************
  8317. *
  8318. * MKRNAME
  8319. * =======
  8320. *
  8321. * Generates a remote filename from a 
  8322. * local one
  8323. *
  8324. ***************************************
  8325.  
  8326. MKRNAME    EQU    *
  8327. *
  8328. * Scan backwards, looking for a "."
  8329. *
  8330.     STY    WORK8    ;save offset to the CR
  8331.     DEY
  8332. MKR100    LDA    LFNAME,Y ;get a byte
  8333.     CMP    #'.'
  8334.     BEQ    MKR200    ;j if it's a "."
  8335.     DEY        ;else step back another
  8336.     BPL    MKR100    ;j if not at front yet
  8337. *
  8338. * Here we're pointing the byte before the last component. Copy this
  8339. * component to the remote name buffer
  8340. *
  8341. MKR200    INY
  8342.     LDX    #0    ;output pointer
  8343. MKR240    LDA    LFNAME,Y
  8344.     STA    RFNAME,X
  8345.     INX
  8346.     INY
  8347.     CPY    WORK8    ;all done yet?
  8348.     BNE    MKR240    ;j if not
  8349. *
  8350. * Then add the defined suffix to the name
  8351. *
  8352.     LDA    SUFLEN    ;get length of suffix
  8353.     BEQ    MKR600    ;j if null - nothing to add
  8354.     LDA    #'.'
  8355.     STA    RFNAME,X ;else add a "."
  8356.     INX
  8357.     LDY    #0    ;and then the suffix
  8358. MKR400    CPX    #MAXFNL-1 ;name now too long?
  8359.     BEQ    MKR600    ;j if so - take what we've got now
  8360.     LDA    SUFFIX,Y
  8361.     STA    RFNAME,X
  8362.     INX
  8363.     INY
  8364.     CPY    SUFLEN
  8365.     BNE    MKR400
  8366. *
  8367. * Round off the remote name with a CR
  8368. *
  8369. MKR600    LDA    #$0D
  8370.     STA    RFNAME,X    
  8371. *
  8372. * And that's it
  8373. *
  8374.     RTS
  8375.  
  8376.  
  8377.  
  8378. ***************************************
  8379. *
  8380. * CLRINT
  8381. * ======
  8382. *
  8383. * Clears interrupt status line
  8384. *
  8385. ***************************************
  8386.  
  8387. CLRINT    LDA    #42
  8388.     JSR    MESS    ;position cursor
  8389.     JMP    SPFILL    ;clear to end of line
  8390.  
  8391.  
  8392. ***************************************
  8393. *
  8394. * CHRPAR
  8395. * ======
  8396. *
  8397. * Checks current parameter is one byte
  8398. * only and picks it up
  8399. *
  8400. ***************************************
  8401.  
  8402. CHRPAR    LDY    CURLEN
  8403.     DEY
  8404.     BNE    CHP900    ;j if length not 1
  8405.     LDA    (CURPAR),Y ;else load the byte
  8406.     RTS
  8407. CHP900    LDA    #198    ;select error text
  8408.     JMP    PARMERR    ;and report
  8409.  
  8410.  
  8411. ***************************************
  8412. *
  8413. * LOCATE
  8414. * ------
  8415. *
  8416. * Returns cursor position
  8417. *
  8418. ***************************************
  8419.  
  8420. LOCATE    LDA    #$86
  8421.     JSR    OSBYTE    ;locate cursor
  8422.     STX    CSRX    ;note position
  8423.     STY    CSRY
  8424.     RTS
  8425.  
  8426.  
  8427. ***************************************
  8428. *
  8429. * REPOSN
  8430. * ======
  8431. *
  8432. * Puts cursor back to CSRX, CSRY
  8433. *
  8434. ***************************************
  8435.  
  8436. REPOSN    LDA    #31
  8437.     JSR    OSWRCH
  8438.     LDA    CSRX
  8439.     JSR    OSWRCH
  8440.     LDA    CSRY
  8441.     JMP    OSWRCH    
  8442.  
  8443.  
  8444. ***************************************
  8445. *
  8446. * HOME
  8447. * ----
  8448. *
  8449. * Homes cursor to top left
  8450. *
  8451. ***************************************
  8452.  
  8453. HOME    LDA    #30
  8454.     JMP    OSWRCH
  8455.  
  8456.  
  8457. ***************************************
  8458. *
  8459. * PRTSW
  8460. * =====
  8461. *
  8462. * Prints a setting from the ON/OFF
  8463. * option table
  8464. *
  8465. ***************************************
  8466.  
  8467. PRTSW    LDX    #>ONOFTB+2 ;select table
  8468.     LDY    #<ONOFTB+2
  8469.     JMP    PRTENT    ;and print it
  8470.  
  8471.  
  8472. ***************************************
  8473. *
  8474. * PRTSWF
  8475. * ======
  8476. *
  8477. * Prints an ON/OFF option in a field 
  8478. * size of 3
  8479. *
  8480. ***************************************
  8481.  
  8482. PRTSWF    STA    WORK0    ;save entry number
  8483.     LDA    #3
  8484.     JSR    SETPEF    ;set field width to 3
  8485.     LDX    #>ONOFTB+2 ;select table
  8486.     LDY    #<ONOFTB+2
  8487.     JMP    PEN100    ;side enter PRTENT
  8488.  
  8489.  
  8490.  
  8491. ***************************************
  8492. *
  8493. * PRBYTE
  8494. * ======
  8495. *
  8496. * Prints a byte in ASCII
  8497. *
  8498. ***************************************
  8499.  
  8500. PRBYTE    TAX
  8501.     LDY    #0
  8502.     SEC        ;select 3 digit print
  8503.     JMP    PRDEC
  8504.  
  8505.  
  8506. ***************************************
  8507. *
  8508. * PRTENT
  8509. * ======
  8510. *
  8511. * Prints a command table entry
  8512. *
  8513. ***************************************
  8514.  
  8515. PRTENT    STA    WORK0    ;save entry number
  8516.     LDA    #0    ;set free format
  8517.     STA    WORK1
  8518. PEN100    STX    PTR0    ;save pointer to table
  8519.     STY    PTR0+1
  8520.     LDY    #0    ;start table offset
  8521.     LDA    WORK0    ;get entry number
  8522.     BEQ    PEN400    ;j if we want entry 0
  8523. *
  8524. * Move to next entry and see if we've reached the one we want
  8525. *
  8526. PEN220    LDA    (PTR0),Y ;get entry length
  8527.     SEC        ;add 1 for length byte itself
  8528.     ADC    PTR0    ;step to next entry
  8529.     STA    PTR0
  8530.     BCC    PEN240
  8531.     INC    PTR0+1
  8532. PEN240    DEC    WORK0    ;decrease countdown
  8533.     BNE    PEN220    ;j if not there yte
  8534. *
  8535. * We've reached the entry, so print it in specifeid field width
  8536. *
  8537. PEN400    LDA    WORK1    ;get field width
  8538.     BEQ    PEN410    ;j if free format
  8539. *
  8540. * Not free format, so calculate spaces needed
  8541. *
  8542.     SEC
  8543.     SBC    (PTR0),Y ;field size - entry size
  8544.     BMI    PEN410    ;j if won't fit
  8545.     BEQ    PEN410    ;j if exact fit
  8546. *
  8547. * Specfill to where we start to print
  8548. *
  8549.     TAX        ;space coubt
  8550.     LDA    #' '
  8551. PEN405    JSR    OSWRCH
  8552.     DEX
  8553.     BNE    PEN405
  8554. *
  8555. * In right place now, so print the entry itself
  8556. *
  8557. PEN410    LDA    (PTR0),Y ;get length byte
  8558.     TAX
  8559.     LDY    #1    ;start offset
  8560. PEN420    LDA    (PTR0),Y ;get a byte
  8561.     JSR    OSWRCH    ;print it
  8562.     INY
  8563.     DEX
  8564.     BNE    PEN420    ;j if not at the end yet
  8565. *
  8566. * And finish
  8567. *
  8568.     RTS    
  8569.  
  8570.  
  8571. ***************************************
  8572. *
  8573. * SETPEF
  8574. * ======
  8575. *
  8576. * Sets up field width for call to PRTEF
  8577. *
  8578. ***************************************
  8579.  
  8580. SETPEF    STA    WORK1    ;save width
  8581. SPF900    RTS
  8582.  
  8583.  
  8584. ***************************************
  8585. *
  8586. * PRTEF
  8587. * =====
  8588. *
  8589. * Prints a table entry in a set field
  8590. * width
  8591. *
  8592. ***************************************
  8593.  
  8594. PRTEF    STA    WORK0    ;save entry number
  8595.     JMP    PEN100    ;side enter PRTENT
  8596.  
  8597.  
  8598. ***************************************
  8599. *
  8600. * EBQON / EBQOFF
  8601. * ==============
  8602. *
  8603. * Shows on status screen 8 bit
  8604. * prefixing state and sets the flag
  8605. *
  8606. ***************************************
  8607.  
  8608. EBQON    LDX    #$FF    ;get new flag state
  8609.     LDA    #26    ;get message number
  8610. EBQ100    STX    EBQFLG    ;set the flag
  8611.     BIT    MODE    ;are we in generic mode?
  8612.     BVC    SPF900    ;j if so - no display
  8613.     JMP    MESS    ;else tell user
  8614.  
  8615. EBQOFF    LDX    #0    ;get new flag state
  8616.     LDA    #22    ;get message number
  8617.     BNE    EBQ100
  8618.     
  8619.  
  8620. ***************************************
  8621. *
  8622. * WLOGB
  8623. * =====
  8624. *
  8625. * Writes the terminal log buffer to disc
  8626. *
  8627. ***************************************
  8628.  
  8629. WLOGB    STA    WORK1    ;save count of bytes to write
  8630.     LDX    #0    ;start pointer
  8631.     LDY    LHAND    ;get file handle
  8632. *
  8633. * Process the bytes
  8634. *
  8635. WLB100    LDA    LOGBUF,X ;get the byte
  8636.     JSR    OSBPUT    ;write the byte
  8637.     INX        ;step pointer
  8638.     CPX    WORK1    ;all done?
  8639.     BNE    WLB100    ;j if not
  8640. *
  8641. * All done
  8642. *
  8643. WLB900    RTS
  8644.  
  8645.  
  8646. ***************************************
  8647. *
  8648. * FNDTOP
  8649. * ======
  8650. *
  8651. * Gets address of top line of VDU
  8652. *
  8653. ***************************************
  8654.  
  8655. FNDTOP    LDA    #$A0    ;address is in VDU variables
  8656.     LDX    #$50    ;$50,$51
  8657.     JMP    OBX0
  8658.  
  8659.  
  8660. ***************************************
  8661. *
  8662. * TIDYLN
  8663. * ======
  8664. *
  8665. * Ensures cursor is at start of empty
  8666. * line
  8667. *
  8668. ***************************************
  8669.  
  8670. TIDYLN    JSR    LOCATE    ;find cursor position
  8671.     CPX    #0
  8672.     BEQ    WLB900    ;no action if at start of line
  8673.     JMP    OSNEWL    ;else start new line
  8674.  
  8675.  
  8676. ***************************************
  8677. *
  8678. * RXINIT
  8679. * ======
  8680. *
  8681. * Initialises values for a receive transfer
  8682. *
  8683. ***************************************
  8684.  
  8685. RXINIT    LDA    #0
  8686.     STA    NUMTRY    ;clear retry count
  8687.     STA    BKASENT    ;clear ACK/Z flag
  8688.     STA    TFSTOP    ;clear interrupt flag
  8689.     STA    PENDFLG    ;clear character-pending flag
  8690. RXI900    RTS
  8691.  
  8692.  
  8693. ***************************************
  8694. *
  8695. * TAKDEL
  8696. * ======
  8697. *
  8698. * Delays for 1/4 second if command source
  8699. * is a TAKE file.
  8700. *
  8701. ***************************************
  8702.  
  8703. TAKDEL    LDA    CSOURCE    ;get command source
  8704.     BEQ    RXI900    ;j if not file - null call
  8705.     JSR    FLSHKB    ;flush keyboard buffer
  8706.     LDA    #$81
  8707.     LDX    #25    ;select 25/100 second pause
  8708.     JMP    OBX0    ;do INKEY(25)
  8709.  
  8710.  
  8711. ***************************************
  8712. *
  8713. * KEYRD
  8714. * =====
  8715. *
  8716. * Reads key, bypassing any EXEC file
  8717. *
  8718. ***************************************
  8719.  
  8720. KEYRD    JSR    SUSEXF    ;suspend any EXEC file
  8721.     JSR    OSRDCH    ;read keyboard
  8722.     JMP    RSTEXF    ;put EXEC back as it was
  8723.  
  8724.  
  8725. ***************************************
  8726. *
  8727. * SETKEY
  8728. * ======
  8729. *
  8730. * Sets base values for function keys
  8731. *
  8732. ***************************************
  8733.  
  8734. SETKEY    STX    PTR3    ;save address of base values table
  8735.     STY    PTR3+1
  8736.     LDA    #228
  8737.     STA    WORK1    ;set first OSBYTE code to use
  8738.     LDA    #3
  8739.     STA    WORK0    ;and counter
  8740. *
  8741. * Set up next base value
  8742. *
  8743. SKY200    LDY    WORK0
  8744.     LDA    (PTR3),Y ;get value from table
  8745.     TAX
  8746.     LDA    WORK1    ;get OSBYTE call
  8747.     JSR    OBX0    ;and do it
  8748. *
  8749. * Then on to the next
  8750. *
  8751.     DEC    WORK1    ;step OSBYTE code back one
  8752.     DEC    WORK0    ;step count
  8753.     BPL    SKY200    ;j if more to do
  8754. SKY900    RTS
  8755.  
  8756.  
  8757. ***************************************
  8758. *
  8759. * ADJTT
  8760. * =====
  8761. *
  8762. * Adjusts terminal type to be a suitable
  8763. * default for the machine
  8764. *
  8765. ***************************************
  8766.  
  8767. ADJTT    BIT    TTYPE    ;is type still undecided?
  8768.     BPL    SKY900    ;j if not - do nothing
  8769.     IF    ROM
  8770. *
  8771. * ROM version assumes we'll use VT52
  8772. *
  8773.     LDA    #2
  8774.     STA    TTYPE    ;set VT52 type
  8775.     ELSE
  8776. *
  8777. * RAM version sets VT52 if we have shadow screen, else TT40
  8778. *
  8779.     BIT    SHADOW
  8780.     BMI    ATT300    ;j if we have shadow screen
  8781.     INC    TTYPE    ;else set TT40
  8782.     BEQ    ATT400
  8783. ATT300    LDA    #2
  8784.     STA    TTYPE    ;we have shadow so set VT52
  8785.     FI
  8786. *
  8787. * Then we ask any TXR fitted if we should change this
  8788. *
  8789. ATT400    LDX    #$80
  8790.     JSR    DOKOSB    ;ask a TXR
  8791.     BVS    SKY900    ;j if none there or it doesn't want to change
  8792.     STX    TTYPE    ;else use what it asks for
  8793.     RTS
  8794.  
  8795.  
  8796.     NEXT    BBCSB4
  8797. ****** File BBCSB4 *************************************************************
  8798.     START    SB4
  8799. * BBCSB4: Updated 05/05/86 @ 1800
  8800.  
  8801. ***************************************
  8802. *
  8803. * HEXPAR
  8804. * ======
  8805. *
  8806. * Converts current parameter from hex
  8807. * to binary
  8808. *
  8809. ***************************************
  8810.  
  8811. HEXPAR    LDY    #0    ;start pointer
  8812.     STY    NUM    ;and total value
  8813.     STY    NUM+1
  8814. *
  8815. * First byte could be $, X or &
  8816. *
  8817.     LDA    (CURPAR),Y ;get byte
  8818.     JSR    HEXFLG    ;check for X, $, &
  8819.     BCC    HXP800    ;j if one of them - step over it
  8820.     BCS    HXP120    ;else it's got to be a hex digit
  8821. *
  8822. * See if next byte is valid hex
  8823. *
  8824. HXP100    LDA    (CURPAR),Y
  8825.     JSR    UPPER    ;force upper case
  8826. HXP120    CMP    #'0'
  8827.     BCC    HXP900    ;j if illegal
  8828.     CMP    #'9'+1
  8829.     BCC    HXP200    ;j if '0'..'9'
  8830.     CMP    #'A'
  8831.     BCC    HXP900    ;j if illegal
  8832.     CMP    #'F'+1
  8833.     BCS    HXP900    ;j if illegal
  8834. *
  8835. * Byte is 'A'..'F'
  8836. *
  8837.     SEC
  8838.     SBC    #'A'-10    ;scale to 10..15
  8839.     BNE    HXP300
  8840. *
  8841. * Byte is '0'..'9'
  8842. *
  8843. HXP200    AND    #$0F    ;scale to 0..9
  8844. *
  8845. * Multiply total by 16 and add new byte in
  8846. *
  8847. HXP300    LDX    #3
  8848. HXP320    ASL    NUM
  8849.     ROL    NUM+1
  8850.     DEX
  8851.     BPL    HXP320
  8852.     ORA    NUM    ;put in new byte
  8853.     STA    NUM
  8854. *
  8855. * And carry on
  8856. *
  8857. HXP700    INY
  8858.     CPY    CURLEN
  8859.     BNE    HXP100    ;j if more to do
  8860.     RTS        ;else end
  8861. *
  8862. * Here first character is X, $ or &
  8863. *
  8864. HXP800    INY
  8865.     LDX    CURLEN    ;any more in string?
  8866.     DEX
  8867.     BNE    HXP100    ;j if so, else error
  8868. *
  8869. * Here digit is invalid
  8870. *
  8871. HXP900    JMP    NPR900
  8872.  
  8873.  
  8874. ***************************************
  8875. *
  8876. * CLOCK
  8877. * =====
  8878. *
  8879. * Resets the interval timer to 1 second
  8880. *
  8881. ***************************************
  8882.  
  8883. CLOCK    LDX    #>CBLK
  8884.     LDY    #<CBLK
  8885.     LDA    #4
  8886.     JMP    OSWORD    ;set time period
  8887.  
  8888. CBLK    HEX    '9CFFFFFFFF'
  8889.  
  8890.  
  8891. ***************************************
  8892. *
  8893. * STCLCK
  8894. * ======
  8895. *
  8896. * Starts the clock ticker running
  8897. *
  8898. ***************************************
  8899.  
  8900. STCLCK    SEI
  8901.     STA    TICKER    ;set interval wanted
  8902.     JSR    CLOCK    ;reset the timer period
  8903.     CLI
  8904.     RTS    
  8905.  
  8906.  
  8907. ***************************************
  8908. *
  8909. * PRFTYPE
  8910. * =======
  8911. *
  8912. * Prints the current file type
  8913. *
  8914. ***************************************
  8915.  
  8916. PRFTYPE    EQU    *
  8917. *
  8918. * First the type itself
  8919. *
  8920.     LDX    #>STYTAB+2 ;select table
  8921.     LDY    #<STYTAB+2
  8922.     LDA    FTYPE    ;get the type
  8923.     JSR    PRTENT    ;print it
  8924. *
  8925. * If ASCII, add end-of-record type
  8926. *
  8927.     LDA    FTYPE
  8928.     BNE    PFT900    ;j if not ASCII
  8929.     LDA    #' '
  8930.     JSR    OSWRCH    ;else print a space
  8931.     LDX    #>SASTAB+2 ;select table
  8932.     LDY    #<SASTAB+2
  8933.     LDA    EORTYPE    ;get EOR type
  8934.     JSR    PRTENT    ;print it
  8935. *
  8936. * And finish
  8937. *
  8938. PFT900    RTS    
  8939.  
  8940.  
  8941. ***************************************
  8942. *
  8943. * FBINIT
  8944. * ======
  8945. *
  8946. * Initialises the file transfer buffer
  8947. *
  8948. ***************************************
  8949.  
  8950. FBINIT    EQU    *
  8951.     IF    ROM
  8952. *
  8953. * For ROM version buffer could be for file or memory
  8954. *
  8955.     CMP    #0
  8956.     BEQ    FBI500    ;j if using for a file
  8957. *
  8958. * Buffer is for a MEMORY transfer - but which way?
  8959. *
  8960.     CPX    #0
  8961.     BEQ    FBI300    ;j if receiving
  8962. *
  8963. * Set buffer to send from MEMORY
  8964. *
  8965.     LDA    MSBASE    ;set base address
  8966.     STA    FBUFF
  8967.     LDA    MSBASE+1
  8968.     STA    FBUFF+1
  8969.     LDA    MSTOP    ;set limit address
  8970.     STA    FBMAX
  8971.     LDA    MSTOP+1
  8972.     STA    FBMAX+1
  8973.     JMP    FBI400    ;and compute size, etc
  8974. *
  8975. * Set up for receive into MEMORY
  8976. *
  8977. FBI300    LDA    MDBASE    ;set base pointer
  8978.     STA    FBUFF
  8979.     LDA    MDBASE+1
  8980.     STA    FBUFF+1
  8981.     LDA    MDTOP    ;and limit address
  8982.     STA    FBMAX
  8983.     LDA    MDTOP+1
  8984.     STA    FBMAX+1
  8985. *
  8986. * Compute size, etc, of memory buffer
  8987. *
  8988. FBI400    LDA    FBMAX    ;set limit as the high water mark
  8989.     STA    FBTOP
  8990.     LDA    FBMAX+1
  8991.     STA    FBTOP+1
  8992.     LDA    FBUFF    ;set base as the receive pointer
  8993.     STA    FBPTR
  8994.     LDA    FBUFF+1
  8995.     STA    FBPTR+1
  8996.     LDA    FBMAX    ;and get the size
  8997.     SEC
  8998.     SBC    FBUFF
  8999.     STA    FBSIZE
  9000.     LDA    FBMAX+1
  9001.     SBC    FBUFF+1
  9002.     STA    FBSIZE+1
  9003. *
  9004. * And finish
  9005. *
  9006.     RTS
  9007.     FI
  9008. *
  9009. * Here buffer will hold a real file
  9010. *
  9011. FBI500    EQU    *
  9012.     IF    ROM
  9013. *
  9014. * ROM version takes memory from OSHWM up
  9015. *
  9016.     LDA    #$B4    ;find OSHWM
  9017.     LDX    #0
  9018.     LDY    #$FF
  9019.     JSR    OSBYTE    ;ms byte is in X
  9020.     LDA    #0
  9021.     STA    FBUFF    ;set OSHWM as buffer start
  9022.     STX    FBUFF+1
  9023.     ELSE
  9024. *
  9025. * RAM version takes space above program and patches
  9026. *
  9027.     LDY    PTPPTR    ;set up base of buffer
  9028.     STY    FBUFF
  9029.     LDY    PTPPTR+1
  9030.     STY    FBUFF+1
  9031.     FI
  9032. *
  9033. * Size is as set by SET FILE BUFFER
  9034. *
  9035.     LDA    #0
  9036.     STA    FBSIZE
  9037.     IF    ROM
  9038.     LDA    FBPAGES
  9039.     ELSE
  9040.     LDA    #8
  9041.     FI
  9042.     STA    FBSIZE+1
  9043. *
  9044. * Then calculate last address in buffer + 1
  9045. *
  9046.     LDA    FBUFF
  9047.     CLC
  9048.     ADC    FBSIZE
  9049.     STA    FBMAX
  9050.     LDA    FBUFF+1
  9051.     ADC    FBSIZE+1
  9052.     STA    FBMAX+1
  9053. *
  9054. * And finish
  9055. *
  9056. FBI900    RTS
  9057.  
  9058.  
  9059.  
  9060. ***************************************
  9061. *
  9062. * LFDUMMY
  9063. * =======
  9064. *
  9065. * Sets up a fake local filename as
  9066. * <MEMORY> or <PRINTER>
  9067. *
  9068. ***************************************
  9069.  
  9070. LFDUMMY LSR    A    ;form 0=MEMORY,1=PRINTER
  9071.     TAX        ;point to dummy string
  9072.     LDA    LFDTBL,X
  9073.     STA    PTR0
  9074.     LDA    LFDTBH,X
  9075.     STA    PTR0+1
  9076. *
  9077. * Copy dummy string to local filename buffer
  9078. *
  9079.     LDY    #9
  9080. LFD300    LDA    (PTR0),Y
  9081.     STA    LFNAME,Y
  9082.     DEY
  9083.     BPL    LFD300
  9084. *
  9085. * Set "local name given" flag and finish
  9086. *
  9087.     LDY    #1
  9088.     STY    LFGIVEN
  9089.     RTS
  9090.  
  9091. LFDMEM    ASC    '<MEMORY> '
  9092.     DFB    $0D
  9093. LFDPRT    ASC    '<PRINTER>'
  9094.     DFB    $0D
  9095.  
  9096. LFDTBL    DFB    >LFDMEM
  9097.     DFB    >LFDPRT
  9098.  
  9099. LFDTBH    DFB    <LFDMEM
  9100.     DFB    <LFDPRT
  9101.  
  9102.  
  9103.  
  9104. ***************************************
  9105. *
  9106. * WAIT
  9107. * ====
  9108. *
  9109. * Waits for a given time or a keypress,
  9110. * whichever comes first
  9111. *
  9112. ***************************************
  9113.  
  9114. WAIT    CMP    #0
  9115.     BEQ    FBI900    ;null call if zero interval
  9116.     PHA        ;else save delay time
  9117.     JSR    FLSHKB    ;flush keyboard buffer
  9118.     PLA        ;get interval back
  9119.     JSR    STCLCK    ;start the clock
  9120. *
  9121. * Got a key press?
  9122. *
  9123. WAI200    JSR    INKEY    ;do INKEY(0)
  9124.     BCC    WAI800    ;j if key down
  9125. *
  9126. * No key down. Timer expired?
  9127. *
  9128.     LDA    TICKER
  9129.     BNE    WAI200    ;j if not
  9130. WAI700    RTS        ;else exit
  9131. *
  9132. * Had a keypress here.
  9133. *
  9134. WAI800    TXA
  9135. WAI820    CMP    #$1B    ;is it ESCAPE?
  9136.     BEQ    WAI900    ;j if it was
  9137.     RTS        ;ele we exit
  9138. *
  9139. * Had an ESCAPE key, so abort command, force input back to keyboard and exit
  9140. * Since ESCAPE here never generates an ESCAPE condition we'll close EXEC file
  9141. * by hand
  9142. *
  9143. WAI900    JSR    KBDSRC    ;close TAKE and EXEC files
  9144.     JMP    RDL131    ;and BRK
  9145.  
  9146.  
  9147. ***************************************
  9148. *
  9149. * WTKEY
  9150. * =====
  9151. *
  9152. * Waits indefinitely till key press,
  9153. * checking for ESCAPE
  9154. *
  9155. ***************************************
  9156.  
  9157. WTKEY    JSR    FLSHKB    ;clear keyboard buffer
  9158.     JSR    KEYRD    ;read character, bypassing EXEC file
  9159.     JMP    WAI820
  9160.  
  9161.  
  9162. ***************************************
  9163. *
  9164. * COUNTF
  9165. * ======
  9166. *
  9167. * Adds to count of filenames in a group
  9168. *
  9169. ***************************************
  9170.  
  9171. COUNTF    INC    FCOUNT    ;step counter
  9172.     LDA    #31
  9173.     JSR    MESS    ;position cursor
  9174.     LDA    FCOUNT
  9175.     JMP    PRBYTE    ;display it
  9176.  
  9177.  
  9178. ***************************************
  9179. *
  9180. * TSTESC
  9181. * ======
  9182. *
  9183. * Checks for ESCAPE and closes TAKE file
  9184. * if we find one
  9185. *
  9186. ***************************************
  9187.  
  9188. TSTESC    BIT    $FF    ;poll ESCAPE flag
  9189.     BPL    WAI700    ;j if not set
  9190.     JMP    WAI900    ;force TAKE and EXEC files to close and then BRK
  9191.  
  9192.  
  9193. ***************************************
  9194. *
  9195. * ACKESC
  9196. * ======
  9197. *
  9198. * Acknowledges an ESCAPE condition
  9199. *
  9200. ***************************************
  9201.  
  9202. ACKESC    LDA    #$7E
  9203.     JMP    OSBYTE
  9204.  
  9205.  
  9206. ***************************************
  9207. *
  9208. * CLTAKE
  9209. * ======
  9210. *
  9211. * Closes a TAKE file if one is open
  9212. *
  9213. ***************************************
  9214.  
  9215. CLTAKE    LDY    TKHAND    ;is TAKE file open?
  9216.     BEQ    CLT900    ;j if not
  9217.     JSR    CLOSEY    ;else close it
  9218.     LDA    #0
  9219.     STA    TKHAND    ;clear the handle out
  9220.     STA    CSOURCE    ;make command source keyboard
  9221. CLT900    RTS
  9222.  
  9223.  
  9224. ***************************************
  9225. *
  9226. * DEFAULT
  9227. * =======
  9228. *
  9229. * Returns SET values to their default
  9230. * state
  9231. *
  9232. ***************************************
  9233.  
  9234. DEFAULT LDY    #DEFCNT-1
  9235. DEF100    LDA    DEFTAB,Y ;copy from ROM table
  9236.     STA    DFBASE,Y
  9237.     DEY
  9238.     BPL    DEF100
  9239. *
  9240. * Then set dependant values
  9241. *
  9242. DEF500    JSR    SETEOR    ;end of record
  9243.     JMP    SETPTY    ;parity
  9244.  
  9245.  
  9246. ***************************************
  9247. *
  9248. * SETEOR
  9249. * ======
  9250. *
  9251. * Sets end-of-record values from the
  9252. * SET parameters
  9253. *
  9254. ***************************************
  9255.  
  9256. SETEOR    LDA    EORTYPE    ;get type of EOR
  9257.     JMP    SAS300    ;set dependencies
  9258.  
  9259.  
  9260. ***************************************
  9261. *
  9262. * SETPTY
  9263. * ======
  9264. *
  9265. * Sets up parity values, etc
  9266. *
  9267. ***************************************
  9268.  
  9269. SETPTY    LDY    PARITY    ;get the SET value
  9270.     JMP    SPY100    ;set things up
  9271.  
  9272.  
  9273. ***************************************
  9274. *
  9275. * VALEBQ
  9276. * ======
  9277. *
  9278. * Tests if a character is legal as an
  9279. * 8 bit prefix
  9280. *
  9281. ***************************************
  9282.  
  9283. VALEBQ    CMP    #'!'
  9284.     BCC    VAL900    ;j if not legal
  9285.     CMP    #'>'+1
  9286.     BCC    VAL800    ;j if legal
  9287.     CMP    #97
  9288.     BCC    VAL900    ;j if not legal
  9289.     CMP    #'~'+1
  9290.     BCS    VAL900    ;j if not legal
  9291. *
  9292. * Here it's legal
  9293. *
  9294. VAL800    CLC
  9295.     RTS
  9296. *
  9297. * Here it's not legal
  9298. *
  9299. VAL900    SEC
  9300.     RTS
  9301.  
  9302.  
  9303. ***************************************
  9304. *
  9305. * STDVEC
  9306. * ======
  9307. *
  9308. * Restores all OS vectors apart from
  9309. * those used by DFS to their default
  9310. * settings
  9311. *
  9312. ***************************************
  9313.  
  9314. STDVEC    PHP
  9315.     SEI
  9316. *
  9317. * Get pointer to the defaults table in the OS ROM
  9318. *
  9319.     LDA    STDVPTR
  9320.     STA    PTR0
  9321.     LDA    STDVPTR+1
  9322.     STA    PTR0+1
  9323. *
  9324. * Reset the low non-filing-system vectors first
  9325. * (USERV to RDCHV inclusive)
  9326. *
  9327.     LDY    #$11
  9328. STV200    LDA    (PTR0),Y ;copy byte down
  9329.     STA    $0200,Y
  9330.     DEY
  9331.     BPL    STV200    ;j till all done
  9332. *
  9333. * Now the high non-filing system vectors
  9334. * (EVENTV to IND3V inclusive)
  9335. *
  9336.     LDY    #$35
  9337. STV300    LDA    (PTR0),Y ;copy byte down
  9338.     STA    $0200,Y
  9339.     DEY
  9340.     CPY    #$1F
  9341.     BNE    STV300    ;j till all done
  9342. *
  9343. * And finish
  9344. *    
  9345.     PLP
  9346.     RTS
  9347.  
  9348.  
  9349.  
  9350. ***************************************
  9351. *
  9352. * GETSYS
  9353. * ======
  9354. *
  9355. * Sets up system control values
  9356. *
  9357. ***************************************
  9358.  
  9359.  
  9360. GETSYS    PHP
  9361.     SEI
  9362.     IF    ROM
  9363.     JSR    GETEV    ;take EVENT vector
  9364.     ELSE
  9365.     JSR    GETEV    ;take EVENT vector
  9366.     LDA    IRQ1V    ;take a copy of IRQ1
  9367.     STA    OLDIRQ
  9368.     LDA    IRQ1V+1
  9369.     STA    OLDIRQ+1
  9370.     LDA    #>IRQENT ;then point it to us
  9371.     STA    IRQ1V
  9372.     LDA    #<IRQENT
  9373.     STA    IRQ1V+1
  9374.     FI
  9375. *
  9376. * Take the BRK vector
  9377. *
  9378.     JSR    GETBRK
  9379. *
  9380. * Enable timer events
  9381. *
  9382.     LDA    #14
  9383.     LDX    #5
  9384.     JSR    OBX0    ;turn event on
  9385. *
  9386. * And finish
  9387. *
  9388.     PLP
  9389.     RTS
  9390.  
  9391.  
  9392. ***************************************
  9393. *
  9394. * LOSESYS
  9395. * =======
  9396. *
  9397. * Restores system to normal state
  9398. *
  9399. ***************************************
  9400.  
  9401. LOSESYS EQU    *
  9402. *
  9403. * Disable timer events
  9404. *
  9405.     LDA    #13
  9406.     LDX    #5
  9407.     JSR    OBX0
  9408. *
  9409. * Reset vectors to normal
  9410. *
  9411.     JMP    STDVEC
  9412.  
  9413.  
  9414. ***************************************
  9415. *
  9416. * LSTMPAR
  9417. * =======
  9418. *
  9419. * Gets mandatory parameter and checks
  9420. * it's the last
  9421. *
  9422. ***************************************
  9423.  
  9424. LSTMPAR JSR    SETHLP    ;set help text
  9425.     JSR    MPARAM    ;get parameter
  9426.     JMP    CONFIRM    ;check no more
  9427.  
  9428.  
  9429. ***************************************
  9430. *
  9431. * LSTMNP
  9432. * ======
  9433. *
  9434. * Gets mandatory numeric parameter and
  9435. * checks it's the last
  9436. *
  9437. ***************************************
  9438.  
  9439. LSTMNP    JSR    GETMPAR    ;get the parameter
  9440.     JSR    NUMPAR    ;convert to binary
  9441.     JMP    CONFIRM    ;check no more
  9442.  
  9443.  
  9444. ***************************************
  9445. *
  9446. * LSTPAR
  9447. * ======
  9448. *
  9449. * Gets optional parameter and checks there
  9450. * are no more
  9451. *
  9452. ***************************************
  9453.  
  9454. LSTPAR    JSR    GETPAR    ;see if param is there
  9455.     BCS    LPR900    ;j if not
  9456.     JSR    CONFIRM    ;else check no more
  9457.     CLC
  9458. LPR900    RTS
  9459.  
  9460.  
  9461. ***************************************
  9462. *
  9463. * GETPAR
  9464. * ======
  9465. *
  9466. * Gets optional parameter
  9467. *
  9468. ***************************************
  9469.  
  9470. GETPAR    JSR    SETHLP    ;set help text
  9471.     JMP    PARAM    ;see if param there
  9472.  
  9473.  
  9474. ***************************************
  9475. *
  9476. * GETMPAR
  9477. * =======
  9478. *
  9479. * Gets mandatory parameter
  9480. *
  9481. ***************************************
  9482.  
  9483. GETMPAR JSR    SETHLP    ;set help text
  9484.     JMP    MPARAM    ;get the parameter
  9485.  
  9486.  
  9487. ***************************************
  9488. *
  9489. * GMPAS
  9490. * =====
  9491. *
  9492. * Gets mandatory parameter and validates
  9493. * it
  9494. *
  9495. ***************************************
  9496.  
  9497. GMPAS    JSR    MPARTAB    ;get parameter
  9498.     CLC        ;allow abbreviations
  9499.     JMP    SCANTAB    ;and validate it
  9500.  
  9501.  
  9502. ***************************************
  9503. *
  9504. * GETMFN
  9505. * ======
  9506. *
  9507. * Gets mandatory filename parameter and
  9508. * checks the length
  9509. *
  9510. ***************************************
  9511.  
  9512. GETMFN    JSR    GETMPAR    ;get parameter
  9513.     JMP    CHKFNL    ;check the length is OK
  9514.  
  9515.  
  9516. ***************************************
  9517. *
  9518. * GETFN
  9519. * =====
  9520. *
  9521. * Gets optional filename parameter and
  9522. * checks the length
  9523. *
  9524. ***************************************
  9525.  
  9526. GETFN    JSR    GETPAR    ;is parameter there?
  9527.     BCS    GFN900    ;j if not
  9528.     JSR    CHKFNL    ;else validate length
  9529.     CLC
  9530. GFN900    RTS
  9531.  
  9532.  
  9533. ***************************************
  9534. *
  9535. * MPARTAB
  9536. * =======
  9537. *
  9538. * Gets mandatory parameter using an
  9539. * option table
  9540. *
  9541. ***************************************
  9542.  
  9543. MPARTAB JSR    SELTAB    ;set up the table
  9544.     JMP    MPARAM    ;get the parameter
  9545.  
  9546.  
  9547. ***************************************
  9548. *
  9549. * PARTAB
  9550. * ======
  9551. *
  9552. * Gets optional parameter using an
  9553. * option table
  9554. *
  9555. ***************************************
  9556.  
  9557. PARTAB    JSR    SELTAB    ;set up table
  9558.     JMP    PARAM    ;see if param is there
  9559.  
  9560.  
  9561. ***************************************
  9562. *
  9563. * LSTMSWP
  9564. * =======
  9565. *
  9566. * Gets mandatory ON/OFF parameter and
  9567. * checks there are no more
  9568. *
  9569. ***************************************
  9570.  
  9571. LSTMSWP JSR    ONOFPAR    ;get the parameter
  9572.     JMP    CONFIRM    ;check no more
  9573.  
  9574.  
  9575. ***************************************
  9576. *
  9577. * LSTMCP
  9578. * ======
  9579. *
  9580. * Gets a mandatory single-character
  9581. * parameter and checks it's the last
  9582. *
  9583. ***************************************
  9584.  
  9585. LSTMCP    JSR    GETMPAR    ;get parameter
  9586.     JSR    CHRPAR    ;check it's one character
  9587.     JMP    CONFIRM    ;check no more there
  9588.  
  9589.  
  9590. ***************************************
  9591. *
  9592. * CLOSEY
  9593. * ======
  9594. *
  9595. * Closes file whose handle is in Y
  9596. *
  9597. ***************************************
  9598.  
  9599. CLOSEY    LDA    #0
  9600.     JMP    OSFIND    
  9601.  
  9602.  
  9603. ***************************************
  9604. *
  9605. * GETEV
  9606. * =====
  9607. *
  9608. * Takes control of the EVENT vector
  9609. *
  9610. ***************************************
  9611.  
  9612. GETEV    PHP
  9613.     SEI
  9614.     IF    ROM
  9615.     LDA    #$FF    ;point $200 vector to extended area
  9616.     STA    EVENTV+1
  9617.     LDA    #3*(EVENTV-$200)/2
  9618.     STA    EVENTV
  9619.     LDY    #3*(EVENTV-$200)/2 ;point extended vector to us
  9620.     LDA    #>EVENT
  9621.     STA    (EVECTB),Y
  9622.     LDA    #<EVENT
  9623.     INY
  9624.     STA    (EVECTB),Y
  9625.     INY
  9626.     LDA    $F4    ;and put in our ROM number
  9627.     STA    (EVECTB),Y
  9628.     ELSE
  9629.     LDA    #>EVENT
  9630.     STA    EVENTV
  9631.     LDA    #<EVENT
  9632.     STA    EVENTV+1
  9633.     FI
  9634.     PLP
  9635.     RTS
  9636.  
  9637.  
  9638. ***************************************
  9639. *
  9640. * KBDSRC
  9641. * ======
  9642. *
  9643. * Closes any TAKE and EXEC files open
  9644. *
  9645. ***************************************
  9646.  
  9647. KBDSRC    LDA    #$77
  9648.     JSR    OSBYTE    ;close EXEC file
  9649.     JMP    CLTAKE    ;and TAKE file
  9650.  
  9651.  
  9652. ***************************************
  9653. *
  9654. * RDEXH
  9655. * =====
  9656. *
  9657. * Reads and checks EXEC file handle
  9658. *
  9659. ***************************************
  9660.  
  9661. RDEXH    PHA        ;save A
  9662.     LDA    #$C6
  9663.     JSR    RSYSVAL    ;read EXEC handle
  9664.     PLA        ;restore A
  9665.     CPX    #0    ;test EXEC handle
  9666.     RTS
  9667.  
  9668.  
  9669.     NEXT    BBCTX1
  9670. ****** File BBCSHW *************************************************************
  9671.     START    SHW
  9672. * BBCSHW: Updated 05/05/86 @ 1800
  9673.  
  9674. ***************************************
  9675. *
  9676. * SHOW
  9677. * ====
  9678. *
  9679. * Displays current parameters
  9680. *
  9681. ***************************************
  9682.  
  9683. SHOW    JSR    CONFIRM    ;check no more params
  9684. *
  9685. * SHOW output uses a MODE 7 screen, whether or not user has a MODE 3 screen
  9686. * selected
  9687. *
  9688.     LDA    #2    ;set system mode to 2 to force a
  9689.     STA    MODE    ;change back to original MODE at end
  9690.     LDA    #110
  9691.     JSR    MESS    ;put up the MODE 7 command screen
  9692. *
  9693. * GENERAL PARAMETERS
  9694. * ------------------
  9695. *
  9696.     LDA    #76
  9697.     JSR    MESS    ;first the header
  9698. *
  9699. * Receive baud rate
  9700. *
  9701.     LDX    #63    ;header text number
  9702.     LDA    RXBAUD    ;get the rate
  9703.     JSR    SHBAUD    ;print the entry (formatted)
  9704. *
  9705. * Transmit baud rate
  9706. *
  9707.     LDX    #30    ;header text number
  9708.     LDA    TXBAUD    ;get the value
  9709.     JSR    SHBAUD    ;print it
  9710. *
  9711. * Parity
  9712. *
  9713.     LDA    #66
  9714.     JSR    MESS    ;print header
  9715.     LDA    #5
  9716.     JSR    SETPEF    ;set field width of 5
  9717.     LDA    PARITY    ;get the value
  9718.     LDX    #>SPATB1+2
  9719.     LDY    #<SPATB1+2
  9720.     JSR    PRTEF    ;print table entry (formatted)
  9721. *
  9722. * Debugging
  9723. *
  9724.     LDX    #64    ;header text number
  9725.     LDA    DEBUG    ;get value
  9726.     JSR    SHSW    ;print OFF/ON
  9727. *
  9728. * Retry limit
  9729. *
  9730.     LDX    #67    ;header text number
  9731.     LDA    MAXTRY    ;get the value
  9732.     JSR    SHBYTE    ;print in decimal
  9733. *
  9734. * Timer switch
  9735. *
  9736.     LDX    #80    ;header text number
  9737.     LDA    TIMER    ;get value
  9738.     JSR    SHSW    ;print OFF/ON
  9739. *
  9740. * 8 bit prefix character
  9741. *
  9742.     LDX    #41    ;header text
  9743.     LDA    CUREBQ  ;get the character
  9744.     JSR    SHCHAR  ;print it
  9745. *
  9746. * Delay after SEND command
  9747. *
  9748.     LDX    #69    ;header text number
  9749.     LDA    DELAY    ;get the value
  9750.     JSR    SHBYTE    ;print in decimal
  9751. *
  9752. * Pause before packet send
  9753. *
  9754.     LDX    #68    ;header text number
  9755.     LDA    PAUSE    ;get value
  9756.     JSR    SHBYTE    ;print in decimal
  9757. *
  9758. * TAKE file echoing
  9759. *
  9760.     LDX    #118    ;header text number
  9761.     LDA    TKECHO    ;get the value
  9762.     JSR    SHSW    ;print as ON/OFF
  9763. *
  9764. * Help trigger
  9765. *
  9766.     LDX    #146    ;header text value
  9767.     LDA    HLPTRG    ;get the character
  9768.     JSR    SHCHAR    ;and print it
  9769. *
  9770. * Flow control
  9771. *
  9772.     LDA    #129    ;print header
  9773.     JSR    MESS
  9774.     LDA    #8
  9775.     JSR    SETPEF    ;select field width of 8
  9776.     LDA    FLOW    ;get the flow-control type
  9777.     LDX    #>SFCTAB+2 ;point command table
  9778.     LDY    #<SFCTAB+2
  9779.     JSR    PRTEF    ;print table entry (formatted)
  9780. *
  9781. * MUX wait period
  9782. *
  9783.     LDX    #57    ;header text number
  9784.     LDA    MUXWT    ;get the value
  9785.     JSR    SHBYTE    ;print in decimal
  9786. *
  9787. * Handshake type
  9788. *
  9789.     LDA    #55
  9790.     JSR    MESS    ;print the header
  9791.     LDA    #4
  9792.     JSR    SETPEF    ;select field width
  9793.     LDA    HSHAKE    ;get handshake type in use
  9794.     LDX    #>SKTAB+2 ;point to table
  9795.     LDY    #<SKTAB+2
  9796.     JSR    PRTEF    ;print table entry (formatted)
  9797. *
  9798. * RECEIVE PARAMETERS
  9799. * ------------------
  9800. *
  9801.     LDA    #77
  9802.     JSR    MESS    ;print the title
  9803. *
  9804. * Packet length
  9805. *
  9806.     LDX    #18    ;header text number
  9807.     LDA    RMAXL    ;get the value
  9808.     JSR    SHBYTE    ;print in decimal
  9809. *
  9810. * Pad character
  9811. *
  9812.     LDX    #82    ;header text number
  9813.     LDA    RPADC    ;get the character
  9814.     JSR    SHHEX    ;print in hex
  9815. *
  9816. * Start of packet marker
  9817. *
  9818.     LDX    #83    ;header text number
  9819.     LDA    RSOP    ;get the character
  9820.     JSR    SHHEX    ;print in hex
  9821. *
  9822. * Padding count
  9823. *
  9824.     LDX    #88    ;header text number
  9825.     LDA    RNPAD    ;get the value
  9826.     JSR    SHBYTE    ;print in decimal
  9827. *
  9828. * Timeout
  9829. *
  9830.     LDX    #89    ;header text number
  9831.     LDA    RTIME    ;get the value
  9832.     JSR    SHBYTE    ;print in decimal
  9833. *
  9834. * SEND PARAMETERS
  9835. * ---------------
  9836. *
  9837.     LDA    #78
  9838.     JSR    MESS    ;print the title
  9839. *
  9840. * Quote character
  9841. *
  9842.     LDX    #71    ;header text number
  9843.     LDA    SQUOTE    ;get the character
  9844.     JSR    SHCHAR    ;print it
  9845. *
  9846. * Pad character
  9847. *
  9848.     LDX    #82    ;header text number
  9849.     LDA    SPADC    ;get the character
  9850.     JSR    SHHEX    ;print in hex
  9851. *
  9852. * Start-of-packet marker
  9853. *
  9854.     LDX    #83    ;header text number
  9855.     LDA    SSOP    ;get the character
  9856.     JSR    SHHEX    ;print in hex
  9857. *
  9858. * Padding count
  9859. *
  9860.     LDX    #88    ;header text value
  9861.     LDA    SNPAD    ;get the value
  9862.     JSR    SHBYTE    ;print in decimal
  9863. *
  9864. * Timeout
  9865. *
  9866.     LDX    #89    ;header tet number
  9867.     LDA    STIME    ;get the value
  9868.     JSR    SHBYTE    ;print in decimal
  9869. *
  9870. *
  9871. * PAGE BREAK
  9872. * ----------
  9873. * Screen is full here, so wait for key
  9874. *
  9875.     LDA    #14
  9876.     JSR    MESS    ;tell user
  9877.     JSR    FLSHKB    ;flush keyboard buffer
  9878. SHW200    JSR    KEYRD    ;read a character, bypassing EXEC file
  9879.     CMP    #$0D
  9880.     BEQ    SHW205    ;j if CR - carry on
  9881.     CMP    #$1B
  9882.     BNE    SHW200    ;j if not ESCAPE - ignore
  9883. *
  9884. * ESCAPE pressed, so finish
  9885. *
  9886.     LDA    #$0C
  9887.     JSR    OSWRCH    ;clear screen
  9888.     RTS        ;and exit
  9889. *
  9890. * CR pressed, so clear screen and carry on
  9891. *
  9892. SHW205    LDA    #$0C
  9893.     JSR    OSWRCH    ;clear screen
  9894. *
  9895. *
  9896. * TERMINAL EMULATION PARAMETERS
  9897. * -----------------------------
  9898. *
  9899.     LDA    #79
  9900.     JSR    MESS    ;print the title
  9901. *
  9902. * Terminal type
  9903. *
  9904.     LDA    #70
  9905.     JSR    MESS    ;print header
  9906.     LDA    #6    ;select field width
  9907.     JSR    SETPEF
  9908.     LDX    #>STTAB+2 ;point to table
  9909.     LDY    #<STTAB+2
  9910.     LDA    TTYPE    ;get value
  9911.     JSR    PRTEF    ;print table entry (formatted)
  9912. *
  9913. * *TV paraneters
  9914. *
  9915.     LDA    #140
  9916.     JSR    MESS    ;print the header
  9917.     LDA    TVFLAG    ;is facility on?
  9918.     BEQ    SHW210    ;j if not
  9919.     LDA    TVPAR1
  9920.     JSR    PRBYTE    ;else print the first param
  9921.     LDA    #' '
  9922.     JSR    OSWRCH    ;then a space
  9923.     LDA    TVPAR2
  9924.     JSR    PRBYTE    ;print the second param
  9925.     JMP    SHW220
  9926. SHW210    JSR    OSNEWL    ;facility off, so end line here    
  9927. *
  9928. * Local echo
  9929. *
  9930. SHW220    LDX    #74    ;header text number
  9931.     LDA    ECHO
  9932.     JSR    SHSW    ;print OFF/ON
  9933. *
  9934. * Terminal session logging
  9935. *
  9936.     LDA    LHAND    ;get file handle
  9937.     BEQ    SHW240    ;j if no file open
  9938.     LDA    #1    ;else value is 1 for ON
  9939. SHW240    LDX    #112    ;header tet number
  9940.     JSR    SHSW    ;print as ON/OFF
  9941. *
  9942. * Key click
  9943. *
  9944.     LDX    #121    ;header text number
  9945.     LDA    CLICK    ;get value
  9946.     JSR    SHSW    ;print as ON/OFF
  9947. *
  9948. * Text colour
  9949. *
  9950.     LDA    #133    ;if we're ROM version...
  9951.     JSR    MESS    ;...print the header
  9952.     LDA    #7
  9953.     JSR    SETPEF    ;select field width of 7
  9954.     LDX    VDUCOL    ;get actual colour used
  9955.     DEX        ;one less for table entry
  9956.     TXA
  9957.     LDX    #>SVDCTB+2 ;point to table
  9958.     LDY    #<SVDCTB+2
  9959.     JSR    PRTEF    ;print entry (formatted)
  9960. *
  9961. * Ignore character
  9962. *
  9963.     LDA    #139
  9964.     JSR    MESS    ;print the header
  9965.     LDA    IGNFLG    ;is a character defined?
  9966.     BEQ    SHW260    ;j if not
  9967.     LDA    #'&'
  9968.     JSR    OSWRCH    ;else print an &
  9969.     LDA    IGNCHR    ;get the character
  9970.     JSR    PRHEX    ;print it in hex
  9971.     JMP    SHW290
  9972. SHW260    LDA    #' '    ;char not defined, so 3 spaces
  9973.     JSR    OSWRCH
  9974.     JSR    OSWRCH
  9975.     JSR    OSWRCH
  9976. *
  9977. * FILE PARAMETERS
  9978. * ---------------
  9979. *
  9980. SHW290    LDA    #84
  9981.     JSR    MESS    ;print the title
  9982. *
  9983. * File type
  9984. *
  9985.     LDA    #85
  9986.     JSR    MESS    ;print header
  9987.     LDA    #6
  9988.     JSR    SETPEF    ;select field of 6
  9989.     LDA    FTYPE    ;get value
  9990.     LDX    #>STYTAB+2 ;select table
  9991.     LDY    #<STYTAB+2
  9992.     JSR    PRTEF    ;print entry (formatted)
  9993. *
  9994. * End of record indicator
  9995. *
  9996.     LDA    #108
  9997.     JSR    MESS    ;print header
  9998.     LDA    FTYPE    ;look at file type
  9999.     BEQ    SHW300    ;j if ASCII
  10000.     JSR    OSNEWL    ;else leave entry blank
  10001.     JMP    SHW320
  10002. SHW300    LDA    #4    ;Type is ASCII, so set field of 4
  10003.     JSR    SETPEF
  10004.     LDA    EORTYPE    ;get the value
  10005.     LDX    #>SASTAB+2 ;select the table
  10006.     LDY    #<SASTAB+2
  10007.     JSR    PRTEF    ;print entry (formatted)
  10008. *
  10009. * Incomplete file disposition
  10010. *
  10011. SHW320    LDA    #105
  10012.     JSR    MESS    ;print the title
  10013.     LDA    #6
  10014.     JSR    SETPEF    ;select field width of 6
  10015.     LDA    FINCOM    ;get the action
  10016.     LDX    #>SITAB+2
  10017.     LDY    #<SITAB+2
  10018.     JSR    PRTEF    ;print entry (formatted)
  10019. *
  10020. * File warning
  10021. *
  10022.     LDX    #106    ;header text number
  10023.     LDA    FWARN    ;get the action
  10024.     JSR    SHSW    ;print as ON/OFF
  10025. *
  10026. * File buffer size
  10027. *
  10028.     LDX    #109    ;header text number
  10029.     IF    ROM
  10030.     LDA    FBPAGES ;get value
  10031.     ELSE
  10032.     LDA    #8
  10033.     FI
  10034.     JSR    SHBYTE    ;print in decimal
  10035. *
  10036. * File suffix
  10037. *
  10038.     LDA    #115
  10039.     JSR    MESS    ;print header
  10040.     LDA    #8
  10041.     SEC
  10042.     SBC    SUFLEN    ;calculate padding needed
  10043.     BEQ    SHW340    ;j if none
  10044.     TAY        ;else pad with spaces
  10045.     LDA    #' '
  10046. SHW330    JSR    OSWRCH
  10047.     DEY
  10048.     BNE    SHW330
  10049. SHW340    LDX    SUFLEN    ;look at suffix size
  10050.     BEQ    SHW360    ;j if null string
  10051.     LDY    #0    ;else print it
  10052. SHW350    LDA    SUFFIX,Y
  10053.     JSR    OSWRCH
  10054.     INY
  10055.     DEX
  10056.     BNE    SHW350
  10057. SHW360    EQU    *
  10058. *
  10059. * File name translation mode
  10060. *
  10061.     LDA    #215
  10062.     JSR    MESS    ;print header
  10063.     LDA    #12
  10064.     JSR    SETPEF    ;set field width of 12
  10065.     LDA    FNTYPE    ;get current value
  10066.     LDX    #>SFNTAB+2 ;point to table
  10067.     LDY    #<SFNTAB+2
  10068.     JSR    PRTEF    ;and print the value
  10069. *
  10070. *
  10071. * TRANSFER PARAMETERS
  10072. * -------------------
  10073. *
  10074.     LDA    #13
  10075.     JSR    MESS    ;print the title
  10076.     IF    ROM
  10077. *
  10078. * Data source
  10079. *
  10080.     LDA    #86
  10081.     JSR    MESS    ;print the header
  10082.     LDA    SOURCE    ;get the value
  10083.     LDX    #>SSRTAB+2
  10084.     LDY    #<SSRTAB+2
  10085.     JSR    PRTENT    ;print value in free format
  10086.     LDA    SOURCE
  10087.     BEQ    SHW600    ;j if FILE - no more here
  10088.     LDA    #' '
  10089.     JSR    OSWRCH    ;else print a space
  10090.     LDX    MSBASE    ;get the base address
  10091.     LDY    MSBASE+1
  10092.     JSR    PRWHEX    ;print in hex
  10093.     LDA    #' '
  10094.     JSR    OSWRCH    ;add a space
  10095.     LDX    MSTOP    ;get the top address
  10096.     LDY    MSTOP+1
  10097.     JSR    PRWHEX    ;print in hex
  10098.     FI
  10099. *
  10100. * Data destination
  10101. *
  10102. SHW600    LDA    #87
  10103.     JSR    MESS    ;print the header
  10104.     LDA    DESTIN    ;get the value
  10105.     IF    RAM
  10106.     BEQ    SHW610    ;if RAM, value 0 is OK
  10107.     LDA    #1    ;else convert 2 to 1 to match weird table
  10108. SHW610    EQU    *
  10109.     FI
  10110.     LDX    #>SDETAB+2
  10111.     LDY    #<SDETAB+2
  10112.     JSR    PRTENT    ;print entry in free format
  10113.     LDA    DESTIN
  10114.     CMP    #1
  10115.     BNE    SHW620    ;j if not MEMORY - no more to do
  10116.     LDA    #' '
  10117.     JSR    OSWRCH    ;else add a space
  10118.     LDX    MDBASE    ;get the base address
  10119.     LDY    MDBASE+1
  10120.     JSR    PRWHEX    ;print in hex
  10121. *
  10122. * Now wait for user to press a key
  10123. *
  10124. SHW620    LDA    #178
  10125.     JSR    MESS    ;prompt him
  10126.     JMP    WTKEY    ;and wait on key
  10127.  
  10128.  
  10129. ***************************************
  10130. *
  10131. * SHBAUD
  10132. * ======
  10133. *
  10134. * Outputs the entry for baud rate
  10135. *
  10136. **************************************
  10137.  
  10138. SHBAUD    PHA        ;save setting
  10139.     JSR    SHHDR    ;print header text
  10140.     LDA    #5
  10141.     JSR    SETPEF    ;select field width of 5
  10142.     PLA        ;reload setting
  10143.     TAX
  10144.     DEX        ;adjust to be table entry
  10145.     TXA
  10146.     LDX    #>SBATAB+2 ;point to table
  10147.     LDY    #<SBATAB+2
  10148.     JMP    PRTEF    ;print formatted entry
  10149.  
  10150.  
  10151. ***************************************
  10152. *
  10153. * SHSW
  10154. * ====
  10155. *
  10156. * Prints an ON/OFF setting
  10157. *
  10158. ***************************************
  10159.  
  10160. SHSW    JSR    SHHDR    ;print header text
  10161.     JMP    PRTSWF    ;and print it
  10162.  
  10163.  
  10164. ***************************************
  10165. *
  10166. * SHBYTE
  10167. * ======
  10168. *
  10169. * Prints a one-byte numeric value in decimal
  10170. *
  10171. ***************************************
  10172.  
  10173. SHBYTE    JSR    SHHDR    ;print header
  10174.     JMP    PRBYTE    ;print the value
  10175.  
  10176.  
  10177. ***************************************
  10178. *
  10179. * SHCHAR
  10180. * ======
  10181. *
  10182. * Prints a character value
  10183. *
  10184. ***************************************
  10185.  
  10186. SHCHAR    JSR    SHHDR    ;print header
  10187.     JMP    OSWRCH    ;then the character
  10188.  
  10189.  
  10190. ***************************************
  10191. *
  10192. * SHHEX
  10193. * =====
  10194. *
  10195. * Prints a one-byte value in hex
  10196. *
  10197. ***************************************
  10198.  
  10199. SHHEX    JSR    SHHDR    ;print header
  10200.     JMP    PRHEX    ;print the byte
  10201.  
  10202.  
  10203. ***************************************
  10204. *
  10205. * SHHDR
  10206. * =====
  10207. *
  10208. * Prints the header text whose number is
  10209. * in X
  10210. *
  10211. ***************************************
  10212.  
  10213. SHHDR    PHA
  10214.     TXA
  10215.     JSR    MESS
  10216.     PLA
  10217.     RTS
  10218.  
  10219.  
  10220.     CHN    BBCREC
  10221. ****** File BBCSND *************************************************************
  10222.     START    SND
  10223. * BBCSND: Updated 05/05/86 @ 2145
  10224.  
  10225. ***************************************
  10226. *
  10227. * SENDSW
  10228. * ======
  10229. *
  10230. * The state table switcher for file
  10231. * sending
  10232. *
  10233. ***************************************
  10234.  
  10235. SENDSW    EQU    *
  10236. *
  10237. * If source is a TAKE file, we do a short delay
  10238. *
  10239.     JSR    TAKDEL
  10240. *
  10241. * Initialise buffer for current source of data
  10242. *
  10243.     LDA    SOURCE    ;select source
  10244.     LDX    #1    ;mode is send
  10245.     JSR    FBINIT
  10246. *
  10247. * Set initial state to SEND_INIT
  10248. *
  10249.     LDA    #'S'
  10250.     STA    STATE
  10251. *
  10252. * Ensure comms buffer is clear
  10253. *
  10254.     JSR    FLUSH
  10255. *
  10256. * Initialise protocol values and counts
  10257. *
  10258.     JSR    KINIT
  10259. *
  10260. * Log new position and state
  10261. *
  10262. SSW050    LDA    #8    ;get text number
  10263.     JSR    LOGST    ;log it
  10264. *
  10265. * Switch on our current state to the correct handler
  10266. *
  10267.     LDA    STATE
  10268.     CMP    #'S'
  10269.     BEQ    SSW100    ;j if SEND_INIT
  10270.     CMP    #'F'
  10271.     BEQ    SSW200    ;j if SEND_FILE
  10272.     CMP    #'D'
  10273.     BEQ    SSW300    ;j if SEND_DATA
  10274.     CMP    #'Z'
  10275.     BEQ    SSW400    ;j if SEND_EOF
  10276.     CMP    #'B'
  10277.     BEQ    SSW500    ;j if SEND_BREAK
  10278.     CMP    #'C'
  10279.     BEQ    SSW600    ;j if COMPLETE
  10280. *
  10281. * Here we're in an unknown state, so break
  10282. *
  10283.     JMP    RSW090
  10284. *
  10285. *
  10286. *
  10287. * State SEND_INIT
  10288. * ---------------
  10289. *
  10290. SSW100    JSR    SINIT
  10291.     JMP    SSW050
  10292. *
  10293. *
  10294. * State SEND_FILE
  10295. * ---------------
  10296. *
  10297. SSW200    JSR    SFILE
  10298.     JMP    SSW050
  10299. *
  10300. *
  10301. * State SEND_DATA
  10302. * ---------------
  10303. *
  10304. SSW300    JSR    SDATA
  10305.     JMP    SSW050
  10306. *
  10307. *
  10308. * State SEND_EOF
  10309. * --------------
  10310. *
  10311. SSW400    JSR    SEOF
  10312.     JMP    SSW050
  10313. *
  10314. *
  10315. * State SEND_BREAK
  10316. * ----------------
  10317. *
  10318. SSW500    JSR    SBREAK
  10319.     JMP    SSW050
  10320. *
  10321. *
  10322. * State COMPLETE
  10323. * --------------
  10324. *
  10325. SSW600    RTS
  10326.  
  10327.  
  10328. ***************************************
  10329. *
  10330. * STATE SEND_INIT
  10331. * ---------------
  10332. *
  10333. ***************************************
  10334.  
  10335. SINIT    JSR    CHKTRY    ;check retry limit
  10336. *
  10337. * Build our parameters and send an S packet
  10338. *
  10339.     SEC        ;note we're sending
  10340.     JSR    SPAR    ;set up parameters
  10341.     LDA    #'S'    ;type is 'S'
  10342.     LDX    #0    ;sequence number 0
  10343.     JSR    SPACK    ;and send it
  10344. *
  10345. * Read the reply from the host
  10346. *
  10347.     JSR    RPACK
  10348.     BCC    SIN040    ;j if read it OK
  10349.     RTS        ;else stay in this state to re-send
  10350. *
  10351. * Branch on packet type
  10352. *
  10353. SIN040    CMP    #'N'
  10354.     BEQ    SIN200    ;j if N
  10355.     CMP    #'Y'
  10356.     BEQ    SIN300    ;j if Y
  10357.     CMP    #'E'
  10358.     BEQ    SIN400    ;j if E
  10359. *
  10360. * Packet type invalid here, so abort
  10361. *
  10362. SIN050    JMP    ABORT
  10363. *
  10364. *
  10365. * NAK received
  10366. * ------------
  10367. *
  10368. SIN200    RTS        ;stay in this state
  10369. *
  10370. *
  10371. * ACK received
  10372. * ------------
  10373. *
  10374. SIN300    JSR    VALSEQ    ;is it the expected one?
  10375.     BCS    SIN200    ;j if not - stay in this state
  10376.     JSR    INPARS    ;else analyse what host sent
  10377. *
  10378. * Clear count of files in group
  10379. *
  10380. SIN340    LDA    #0
  10381.     STA    FCOUNT
  10382. *
  10383. * Then we go to state SEND_FILE
  10384. *
  10385.     LDA    #'F'
  10386.     STA    STATE
  10387.     RTS
  10388. *
  10389. *
  10390. * ERROR received
  10391. * --------------
  10392. *
  10393. SIN400    JMP    ERRPKT
  10394.  
  10395.  
  10396. ***************************************
  10397. *
  10398. * STATE SEND_FILE
  10399. * ===============
  10400. *
  10401. ***************************************
  10402.  
  10403. SFILE    JSR    CHKTRY ;check retry limit
  10404. *
  10405. * Retries OK so far. Is a file open yet?
  10406. *
  10407.     LDA    FHAND
  10408.     BNE    SFI190    ;j if one is open
  10409. *
  10410. * File not yet open, so open it
  10411. *
  10412.     LDX    #>LFNAME ;point to name    
  10413.     LDY    #<LFNAME
  10414.     LDA    #$40    ;read mode
  10415.     JSR    FOPEN    ;try to open it
  10416. *
  10417. * Now build an F packet to send to the other end
  10418. *
  10419. SFI190    LDY    #0
  10420. SFI200    LDA    RFNAME,Y ;take name from remote name buffer
  10421.     CMP    #$0D
  10422.     BEQ    SFI220    ;stop when CR reached
  10423.     STA    TXBUFF,Y
  10424.     INY
  10425.     BNE    SFI200
  10426. *
  10427. * Y holds length of name now, so save as packet data size
  10428. *
  10429. SFI220    STY    DATLEN
  10430. *
  10431. * Now send the F packet
  10432. *
  10433.     LDA    #'F'    ;set type
  10434.     LDX    NXTPAK    ;and number
  10435.     JSR    SPACK
  10436. *
  10437. * Get the reply in
  10438. *
  10439.     JSR    RPACK
  10440.     BCC    SFI240    ;j if read it OK
  10441.     RTS        ;else stay in this state to resend
  10442. *
  10443. * Branch on packet type
  10444. *
  10445. SFI240    CMP    #'E'
  10446.     BEQ    SFI800    ;j if E
  10447.     CMP    #'Y'
  10448.     BEQ    SFI700    ;j if Y
  10449.     CMP    #'N'
  10450.     BEQ    SFI600    ;j if N
  10451. *
  10452. * Packet type not expected, so abort
  10453. *
  10454. SFI400    JMP    ABORT
  10455. *
  10456. *
  10457. *
  10458. * NAK received
  10459. * ------------
  10460. *
  10461. SFI600    JSR    VALNAK    ;can we take it as ACK?
  10462.     BCC    SFI705    ;j if we can
  10463. SFI620    RTS        ;no, so stay in current state
  10464. *
  10465. *
  10466. * ACK received
  10467. * ------------
  10468. *
  10469. SFI700    JSR    VALSEQ    ;see if it's expected ACK
  10470.     BCS    SFI620    ;j if not - stay in current state
  10471. *
  10472. * Clear flags out now
  10473. *
  10474.     LDA    #0
  10475.     STA    EORSEQ    ;not in EOR sequence
  10476.     STA    PENDFLG    ;no char to inject
  10477.     STA    TFSTOP    ;not interrupted
  10478. *
  10479. * Clear flag for 'non ASCII warning given'
  10480. *
  10481.     STA    BINWRN
  10482.     LDA    #97
  10483.     JSR    MESS    ;position cursor
  10484.     JSR    SPFILL    ;ensure text isn't on screen
  10485.     JSR    CLRINT    ;clear interrupt status line
  10486. *
  10487. * Count this file and clear current Kbyte count
  10488. *
  10489.     JSR    COUNTF
  10490.     JSR    CLRKBC
  10491. *
  10492. * So set up the first data packet from the file
  10493. *
  10494. SFI705    JSR    BUFILL    ;try to set up D packet
  10495.     BCS    SFI720    ;j if file is empty
  10496.     LDA    #'D'
  10497. SFI710    STA    STATE    ;else go to state SEND_DATA
  10498.     RTS        ;and exit
  10499. *
  10500. * File is empty, so go straight to state SEND_EOF
  10501. *
  10502. SFI720    LDA    #'Z'
  10503.     BNE    SFI710
  10504. *
  10505. *
  10506. * ERROR received
  10507. * --------------
  10508. *
  10509. SFI800    JMP    ERRPKT
  10510.  
  10511.  
  10512. ***************************************
  10513. *
  10514. * STATE SEND_DATA
  10515. * ===============
  10516. *
  10517. ***************************************
  10518.  
  10519. SDATA    JSR    CHKTRY    ;check retry limit
  10520. *
  10521. * Have we had CTRL-X or CTRL-Z on the keyboard?
  10522. *
  10523.     BIT    TFSTOP
  10524.     BPL    SDA020    ;j if not
  10525. SDA010    CLC        ;we have, so close file
  10526.     JSR    FCLOSE
  10527.     LDA    #0
  10528.     STA    NUMTRY    ;clear try counter again
  10529.     JMP    SDA780    ;go to state SEND_EOF
  10530. *
  10531. * OK to go ahead. Send the pre-built D packet
  10532. *
  10533. SDA020    LDA    #'D'    ;set type
  10534.     LDX    NXTPAK    ;and number
  10535.     LDY    TXDLEN    ;if retry, DATLEN has changed, so set it
  10536.     STY    DATLEN    ;up properly again
  10537.     JSR    SPACK
  10538. *
  10539. * Get the reply in
  10540. *
  10541.     JSR    RPACK
  10542.     BCC    SDA040    ;j if read OK
  10543.     RTS        ;else stay in this state to resend
  10544. *
  10545. * Branch on packet type
  10546. *
  10547. SDA040    CMP    #'N'
  10548.     BEQ    SDA600    ;j if N
  10549.     CMP    #'Y'
  10550.     BEQ    SDA700    ;j if Y
  10551.     CMP    #'E'
  10552.     BEQ    SDA800    ;j if E
  10553. *
  10554. * Packet type not expected, so abort
  10555. *
  10556. SDA050    JMP    ABORT
  10557. *
  10558. *
  10559. * NAK received
  10560. * ------------
  10561. *
  10562. SDA600    JSR    VALNAK    ;can we take it as ACK?
  10563.     BCC    SDA720    ;j if so
  10564. SDA620    RTS        ;else stay in this state
  10565. *
  10566. *
  10567. * ACK received
  10568. * ------------
  10569. *
  10570. SDA700    JSR    VALSEQ    ;is it the expected one?
  10571.     BCS    SDA620    ;j if not - stay in same state
  10572. *
  10573. * Is this an ACK/Z or ACK/X?
  10574. *
  10575.     LDA    DATLEN    ;get packet data size
  10576.     BEQ    SDA720    ;j if no data - ordinary ACK
  10577.     LDA    RXBUFF    ;else get the first data byte
  10578.     CMP    #'X'
  10579.     BEQ    SDA705    ;j if ACK/X
  10580.     CMP    #'Z'
  10581.     BNE    SDA720    ;j if not then ACK/Z
  10582. *
  10583. * Other end sent ACK/X or ACK/Z to interrupt us
  10584. *
  10585.     LDA    #%11000000
  10586.     STA    TFSTOP    ;ACK/Z
  10587.     BMI    SDA010
  10588. SDA705    LDA    #%10000000
  10589.     STA    TFSTOP    ;ACK/X
  10590.     BMI    SDA010
  10591. *
  10592. * Ordinary ACK from other end. Try to packet up some more data
  10593. *
  10594. SDA720    JSR    BUFILL    ;try to build a D packet
  10595.     BCS    SDA780    ;j if no more data in file
  10596.     LDA    #'D'
  10597. SDA760    STA    STATE    ;ensure we're in state SEND_DATA
  10598.     RTS        ;and finish
  10599. *
  10600. * Here file has reached EOF, so we've done
  10601. *
  10602. SDA780    LDA    #'Z'    ;go to state SEND_EOF
  10603.     BNE    SDA760
  10604. *
  10605. *
  10606. * ERROR received
  10607. * --------------
  10608. *
  10609. SDA800    JMP    ERRPKT
  10610.  
  10611.  
  10612. ***************************************
  10613. *
  10614. * STATE SEND_BREAK
  10615. * ================
  10616. *
  10617. ***************************************
  10618.  
  10619. SBREAK    JSR    CHKTRY    ;check retry limit
  10620. *
  10621. * Send the B packet
  10622. *
  10623.     JSR    STDBREAK
  10624. *
  10625. * Get the reply in
  10626. *
  10627.     JSR    RPACK
  10628.     BCC    SBR040    ;j if read OK
  10629.     RTS        ;else stay in this state to resend
  10630. *
  10631. * Branch on packet type
  10632. *
  10633. SBR040    CMP    #'N'
  10634.     BEQ    SBR600    ;j if N
  10635.     CMP    #'Y'
  10636.     BEQ    SBR700    ;j if Y
  10637.     CMP    #'E'
  10638.     BEQ    SBR800    ;j if E
  10639. *
  10640. * Packet type unexpected, so abort
  10641. *
  10642. SBR050    JMP    ABORT
  10643. *
  10644. *
  10645. *
  10646. * NAK received
  10647. * ------------
  10648. *
  10649. SBR600    JSR    VALNAK    ;can we treat as ACK?
  10650.     BCC    SBR700    ;j if we can
  10651. SBR620    RTS        ;else stay in this state
  10652. *
  10653. *
  10654. * ACK received
  10655. * ------------
  10656. *
  10657. SBR700    JSR    VALSEQ    ;is it the expected one?
  10658.     BCS    SBR620    ;j if not - stay in same state
  10659.     LDA    #'C'    ;else set state to COMPLETE
  10660.     STA    STATE
  10661.     RTS        ;and finish
  10662. *
  10663. *
  10664. * ERROR received
  10665. * --------------
  10666. *
  10667. SBR800    JMP    ERRPKT
  10668.  
  10669.  
  10670. ***************************************
  10671. *
  10672. * STATE SEND_EOF
  10673. * ==============
  10674. *
  10675. ***************************************
  10676.  
  10677. SEOF    JSR    CHKTRY    ;check retry limit
  10678. *
  10679. * Send a Z packet to the other end
  10680. *
  10681.     BIT    TFSTOP    ;want Z/D?
  10682.     BPL    SEF020    ;j if not
  10683.     JSR    SDCEOF    ;else Z/D
  10684.     JMP    SEF030
  10685. SEF020    JSR    STDEOF    ;Ordinary
  10686. *
  10687. * Read the reply  in
  10688. *
  10689. SEF030    JSR    RPACK
  10690.     BCC    SEF040    ;j if read OK
  10691.     RTS        ;else stay in this state to resend
  10692. *
  10693. * Branch on packet type
  10694. *
  10695. SEF040    CMP    #'N'
  10696.     BEQ    SEF300    ;j if N
  10697.     CMP    #'Y'
  10698.     BEQ    SEF400    ;j if Y
  10699.     CMP    #'E'
  10700.     BEQ    SEF500    ;j if E
  10701. *
  10702. * Packet type is invalid here, so abort
  10703. *
  10704. SEF050    JMP    ABORT
  10705. *
  10706. *
  10707. *
  10708. * NAK received
  10709. * ------------
  10710. *
  10711. SEF300    JSR    VALNAK    ;can we take it as ACK?
  10712.     BCC    SEF400    ;j if we can
  10713. SEF320    RTS        ;no, so stay in this state
  10714. *
  10715. *
  10716. * ACK received
  10717. * ------------
  10718. *
  10719. SEF400    JSR    VALSEQ    ;is it the expected one?
  10720.     BCS    SEF320    ;j if not
  10721. *
  10722. * That file is now done and closed. Are we sending a group?
  10723. *
  10724.     LDA    WCLEN
  10725.     BEQ    SEF480    ;j if name not wildcarded
  10726. *
  10727. * We're doing a group, so see if there's another to go
  10728. *
  10729.     BIT    TFSTOP    ;had CTRL-Z to stop group?
  10730.     BVS    SEF480    ;j if so - do no more
  10731.     JSR    GNXTFIL    ;else find next file
  10732.     BCS    SEF480    ;j if no more
  10733.     JSR    STOTCT    ;else clear counters
  10734.     LDA    #'F'
  10735.     BNE    SEF490    ;and go to state SEND_FILE
  10736. *
  10737. * We've finished
  10738. *
  10739. SEF480    LDA    #'B'    ;go to state SEND_BREAK
  10740. SEF490    STA    STATE
  10741.     RTS
  10742. *
  10743. *
  10744. * ERROR received
  10745. * --------------
  10746. *
  10747. SEF500    JMP    ERRPKT    
  10748.  
  10749.  
  10750.     NEXT    BBCCOM
  10751. ****** File BBCST1 *************************************************************
  10752.     START    ST1
  10753. * BBCST1 : Updated 09/05/86 @ 1730
  10754.  
  10755. ***************************************
  10756. *
  10757. * SET
  10758. * ===
  10759. *
  10760. * Implements the SET command
  10761. *
  10762. ***************************************
  10763.  
  10764. SET    EQU    *
  10765. *
  10766. * Select the table for the options and get the option parameter
  10767. *
  10768.     LDX    #>SETOPT ;point to table
  10769.     LDY    #<SETOPT
  10770.     JSR    GMPAS    ;get parameter and validate it
  10771.     JMP    ACTION    ;yes, so service it
  10772.  
  10773. SETOPT    DW    SETJMP    ;jump table address
  10774.     CMD    4,'BAUD'
  10775.     CMD    6,'PARITY'
  10776.     CMD    2,'TV'
  10777.     CMD    4,'FILE'
  10778.     CMD    4,'SEND'
  10779.     CMD    7,'RECEIVE'
  10780.     CMD    5,'TIMER'
  10781.     CMD    5,'DELAY'
  10782.     CMD    5,'PAUSE'
  10783.     CMD    6,'IGNORE'
  10784.     IF    ROM
  10785.     CMD    6,'SOURCE'
  10786.     FI
  10787.     CMD    11,'DESTINATION'
  10788.     CMD    7,'RETRIES'
  10789.     CMD    8,'MUX-WAIT'
  10790.     CMD    8,'TERMINAL'
  10791.     CMD    10,'LOCAL-ECHO'
  10792.     CMD    9,'DEBUGGING'
  10793.     CMD    9,'KEY-CLICK'
  10794.     CMD    9,'TAKE-ECHO'
  10795.     CMD    9,'HANDSHAKE'
  10796.     CMD    10,'VDU-COLOUR'
  10797.     CMD    10,'INCOMPLETE'
  10798.     CMD    12,'FLOW-CONTROL'
  10799.     CMD    12,'HELP-TRIGGER'
  10800.     CMD    16,'EIGHT-BIT-PREFIX'
  10801.     DFB    0
  10802.  
  10803. SETJMP    DW    SBAUD    ;SET BAUD
  10804.     DW    SPARIT    ;SET PARITY
  10805.     DW    STV    ;SET TV
  10806.     DW    STFILE    ;SET FILE
  10807.     DW    SSEND    ;SET SEND
  10808.     DW    SRECV    ;SET RECEIVE
  10809.     DW    STIMER    ;SET TIMER
  10810.     DW    SDELAY    ;SET DELAY
  10811.     DW    SPAUSE    ;SET PAUSE
  10812.     DW    SIGNRE    ;SET IGNORE
  10813.     IF    ROM
  10814.     DW    SSOURCE    ;SET SOURCE
  10815.     FI
  10816.     DW    SDEST    ;SET DESTINATION
  10817.     DW    SRTRY    ;SET RETRIES
  10818.     DW    SMUXWT    ;SET MUX-WAIT
  10819.     DW    STERM    ;SET TERMINAL
  10820.     DW    SLECHO    ;SET LOCAL-ECHO
  10821.     DW    SDEBUG    ;SET DEBUGGING
  10822.     DW    STKCLK    ;SET KEY-CLICK
  10823.     DW    STKECH    ;SET TAKE-ECHO
  10824.     DW    SHSHAK    ;SET HANDSHAKE
  10825.     DW    SVDCOL    ;SET VDU-COLOUR
  10826.     DW    SINCFD    ;SET INCOMPLETE
  10827.     DW    SFCON    ;SET FLOW-CONTROL
  10828.     DW    SHTRG    ;SET HELP-TRIGGER
  10829.     DW    SEBQ    ;SET EIGHT-BIT-PREFIX
  10830.  
  10831.  
  10832. ***************************************
  10833. *
  10834. * SET BAUD
  10835. * ========
  10836. *
  10837. * Sets baud rate for comms line
  10838. *
  10839. ***************************************
  10840.  
  10841. SBAUD    EQU    *
  10842. *
  10843. * Select the options table and get the next parameter
  10844. *
  10845.     LDX    #>SBATAB ;point to table
  10846.     LDY    #<SBATAB
  10847.     JSR    MPARTAB    ;get parameter
  10848. *
  10849. * Look for the string in the options table
  10850. *
  10851.     SEC        ;no abbreviations
  10852.     JSR    SCANTAB
  10853.     TAX
  10854.     INX        ;actual rate is value plus 1
  10855.     STX    WORK0    ;save baud rate setting
  10856. *
  10857. * Next (optional) parameter gives the direction we set for
  10858. *
  10859.     LDX    #>SBATB2 ;point to table
  10860.     LDY    #<SBATB2
  10861.     JSR    PARTAB    ;look for parameter
  10862.     BCS    SBA800    ;j if defaulted
  10863.     JSR    SCANTAB    ;else check it (C clear for abb. allowed)
  10864.     JSR    CONFIRM    ;check no more parameters
  10865.     JMP    ACTION    ;and handle it    
  10866. *
  10867. * Here we set the RECEIVE rate
  10868. *
  10869. SBA600    LDX    WORK0    ;reload value
  10870.     STX    RXBAUD    ;note it
  10871.     JMP    SBA900
  10872. *
  10873. * Here we set the TRANSMIT rate
  10874. *
  10875. SBA700    LDX    WORK0    ;reload value
  10876.     STX    TXBAUD    ;note it
  10877.     JMP    SBA900
  10878. *
  10879. * Here we set BOTH (the default case)
  10880. *
  10881. SBA800    LDX    WORK0    ;get value back
  10882.     STX    TXBAUD
  10883.     STX    RXBAUD
  10884. *
  10885. * Then reinitialise the 6850
  10886. *
  10887. SBA900    JMP    SETACIA
  10888.  
  10889. SBATAB    DW    0    ;no jump table
  10890.     CMD    2,'75'
  10891.     CMD    3,'150'
  10892.     CMD    3,'300'
  10893.     CMD    4,'1200'
  10894.     CMD    4,'2400'
  10895.     CMD    4,'4800'
  10896.     CMD    4,'9600'
  10897.     DFB    0
  10898.  
  10899. SBATB2    DW    SBATB3    ;jump table
  10900.     CMD    7,'RECEIVE'
  10901.     CMD    8,'TRANSMIT'
  10902.     CMD    4,'BOTH'
  10903.     DFB    0
  10904.  
  10905. SBATB3    DW    SBA600    ;RECEIVE
  10906.     DW    SBA700    ;TRANSMIT
  10907.     DW    SBA800    ;BOTH
  10908.  
  10909.  
  10910. ***************************************
  10911. *
  10912. * SET TIMER
  10913. * =========
  10914. *
  10915. * Enables/disables our timeout
  10916. *
  10917. ***************************************
  10918.  
  10919. STIMER    JSR    LSTMSWP ;get ON/OFF, check no more params
  10920.     STA    TIMER    ;note the value
  10921.     RTS
  10922.  
  10923.  
  10924. ***************************************
  10925. *
  10926. * SET DEBUGGING
  10927. * =============
  10928. *
  10929. * Turns debugging on or off
  10930. *
  10931. ***************************************
  10932.  
  10933. SDEBUG    JSR    LSTMSWP ;get ON/OFF, check no more params
  10934.     STA    DEBUG    ;set the flag
  10935.     STA    DEBTOG    ;and the toggle
  10936. SDB900    RTS
  10937.  
  10938.  
  10939. ***************************************
  10940. *
  10941. * SET LOCAL-ECHO
  10942. * ==============
  10943. *
  10944. * Turns terminal mode local echo on or
  10945. * off 
  10946. *
  10947. ***************************************
  10948.  
  10949. SLECHO    JSR    LSTMSWP ;get ON/OFF, check no more params
  10950.     STA    ECHO    ;set the flag
  10951. SEC900    RTS
  10952.  
  10953.  
  10954. ***************************************
  10955. *
  10956. * SET DELAY
  10957. * =========
  10958. *
  10959. * Sets wait interval after SEND command
  10960. * before we actually do anything
  10961. *
  10962. ***************************************
  10963.  
  10964. SDELAY    EQU    *
  10965. *
  10966. * Parameter is the delay in seconds
  10967. *
  10968.     LDA    #58    ;select help text
  10969.     JSR    LSTMNP    ;get numeric par, check no more
  10970.     STA    DELAY    ;save the value
  10971.     RTS
  10972.  
  10973.  
  10974. ***************************************
  10975. *
  10976. * SET EIGHT-BIT-PREFIX
  10977. * ====================
  10978. *
  10979. * Defines character we prefer to use for
  10980. * eight-bit prefix
  10981. *
  10982. ***************************************
  10983.  
  10984. SEBQ    EQU    *
  10985. *
  10986. * Next parameter is the character we use
  10987. *
  10988.     LDA    #125    ;select help text
  10989.     JSR    LSTMCP    ;get char param, check no more
  10990. *
  10991. * Check character is legal and doesn't clash with the
  10992. * quote character
  10993. *
  10994.     JSR    VALEBQ    ;is it valid?
  10995.     BCS    SBQ900    ;j if not
  10996.     CMP    SQUOTE    ;clash with quote?
  10997.     BEQ    SBQ920    ;j if it does
  10998. *
  10999. * Character is acceptable
  11000. *
  11001.     STA    CUREBQ    ;save it
  11002.     RTS
  11003. *
  11004. * Here character isn't a legal prefix
  11005. *
  11006. SBQ900    LDA    #186    ;get error text
  11007. SBQ902    JMP    PARMERR    ;and report
  11008. *
  11009. * Here it clashed with the quote character
  11010. *
  11011. SBQ920    LDA    #188    ;get error text
  11012.     BNE    SBQ902    ;and report
  11013.  
  11014.  
  11015. ***************************************
  11016. *
  11017. * SET PARITY
  11018. * ==========
  11019. *
  11020. * Sets the parity used on the comms line
  11021. *
  11022. ***************************************
  11023.  
  11024. SPARIT    EQU    *
  11025. *
  11026. * Parameter is the parity setting wanted
  11027. *
  11028.     LDX    #>SPATB1 ;point to table
  11029.     LDY    #<SPATB1
  11030.     JSR    GMPAS    ;get parameter and validate it
  11031.     JSR    CONFIRM    ;check no more params
  11032. *
  11033. * Save the setting value and note the corrseponding 6850 setting
  11034. * and inward byte mask
  11035. *
  11036.     STA    PARITY
  11037.     TAY
  11038. SPY100    LDA    SPATB2,Y
  11039.     STA    PARSET    ;6850 setting
  11040.     LDA    SPATB3,Y
  11041.     STA    PARMSK    ;inward byte mask
  11042. *
  11043. * Then put the 6850 to the new setting
  11044. *
  11045.     JMP    SETACIA
  11046.  
  11047. SPATB1    DW    0    ;no jump table
  11048.     CMD    4,'MARK'
  11049.     CMD    5,'SPACE'
  11050.     CMD    4,'EVEN'
  11051.     CMD    3,'ODD'
  11052.     CMD    4,'NONE'
  11053.     DFB    0
  11054.  
  11055. SPATB2    DFB    %10010010 ;MARK -use 8 bit
  11056.     DFB    %10010010 ;SPACE - use 8 bit
  11057.     DFB    %10000010 ;EVEN - use 7 bit
  11058.     DFB    %10000110 ;ODD - use 7 bit
  11059.     DFB    %10010010 ;NONE - use 8 bit
  11060.  
  11061. SPATB3    DFB    %01111111 ;MARK
  11062.     DFB    %01111111 ;SPACE
  11063.     DFB    %01111111 ;EVEN
  11064.     DFB    %01111111 ;ODD
  11065.     DFB    %11111111 ;NONE
  11066.  
  11067.  
  11068. ***************************************
  11069. *
  11070. * SET PAUSE
  11071. * =========
  11072. *
  11073. * Sets the wait interval on packet
  11074. * turnround
  11075. *
  11076. ***************************************
  11077.  
  11078. SPAUSE    EQU    *
  11079. *
  11080. * Parameter is the delay in seconds
  11081. *
  11082.     LDA    #60    ;select help text
  11083.     JSR    LSTMNP    ;get numeric par, check no more
  11084.     STA    PAUSE    ;save the value
  11085.     RTS
  11086.  
  11087.  
  11088. ***************************************
  11089. *
  11090. * SET FILE
  11091. * ========
  11092. *
  11093. * Entry to the SET FILE group of commands
  11094. *
  11095. ***************************************
  11096.  
  11097. STFILE    EQU    *
  11098. *
  11099. * First parameter gives what we set
  11100. *
  11101.     LDX    #>SFTAB    ;point to table
  11102.     LDY    #<SFTAB
  11103.     JSR    GMPAS    ;get the parameter and validate it
  11104.     JMP    ACTION    ;and execute it
  11105.  
  11106. SFTAB    DW    SFJMP
  11107.     CMD    4,'TYPE'
  11108.     CMD    4,'NAME'
  11109.     IF    ROM
  11110.     CMD    11,'BUFFER-SIZE'
  11111.     FI
  11112.     CMD    7,'WARNING'
  11113.     CMD    6,'SUFFIX'
  11114.     DFB    0
  11115.  
  11116. SFJMP    DW    SFTYPE    ;SET FILE TYPE
  11117.     DW    SFNAME    ;SET FILE NAME
  11118.     IF    ROM
  11119.     DW    SFBUFF    ;SET FILE BUFFER-SIZE
  11120.     FI
  11121.     DW    SFWARN    ;SET FILE WARNING
  11122.     DW    SFSUFF    ;SET FILE SUFFIX
  11123.  
  11124.  
  11125. ***************************************
  11126. *
  11127. * SET FILE TYPE
  11128. * =============
  11129. *
  11130. * Defines whether we treat files as
  11131. * binary or ASCII text
  11132. *
  11133. ***************************************
  11134.  
  11135. SFTYPE    EQU    *
  11136. *
  11137. * Next parameter is the type required
  11138. *
  11139.     LDX    #>STYTAB ;point to table
  11140.     LDY    #<STYTAB
  11141.     JSR    GMPAS    ;get parameter and validate it
  11142.     JMP    ACTION    ;and execute it
  11143.  
  11144. STYTAB    DW    STYJMP
  11145.     CMD    5,'ASCII'
  11146.     CMD    6,'BINARY'
  11147.     DFB    0
  11148.  
  11149. STYJMP    DW    SASCII    ;SET FILE TYPE ASCII
  11150.     DW    SBIN    ;SET FILE TYPE BINARY
  11151.  
  11152.  
  11153. ***************************************
  11154. *
  11155. * SET FILE TYPE ASCII
  11156. * ===================
  11157. *
  11158. * Sets files to be ASCII text and defines
  11159. * how end-of-record is to be held
  11160. *
  11161. ***************************************
  11162.  
  11163. SASCII    EQU    *
  11164. *
  11165. * Next parameter (optional) is the EOR type to use
  11166. *
  11167.     LDX    #>SASTAB
  11168.     LDY    #<SASTAB
  11169.     JSR    PARTAB    ;look for parameter
  11170.     BCS    SAS800    ;j if absent
  11171.     SEC        ;no abbreviations
  11172.     JSR    SCANTAB    ;look for it in the table
  11173. SAS100    JSR    CONFIRM    ;check no more params    
  11174. SAS120    STA    EORTYP    ;note the type selected
  11175.     LDX    #0
  11176.     STX    FTYPE    ;file type is ASCII
  11177. SAS300    ASL    A
  11178.     TAY        ;get table offset
  11179.     LDA    SASTB2,Y
  11180.     STA    EOR    ;note first byte in EOR sequence
  11181.     LDA    SASTB2+1,Y
  11182.     STA    EOR+1    ;...and the second
  11183.     RTS        ;and finish
  11184. *
  11185. * Here type is omitted, so default to LFCR
  11186. *
  11187. SAS800    LDA    #0
  11188.     BEQ    SAS120
  11189.  
  11190.  
  11191. SASTAB    DW    0    ;no jump table
  11192.     CMD    4,'LFCR'
  11193.     CMD    4,'CRLF'
  11194.     CMD    2,'LF'
  11195.     CMD    2,'CR'
  11196.     DFB    0
  11197.  
  11198. SASTB2    DFB    $0A,$0D    ;LFCR
  11199.     DFB    $0D,$0A    ;CRLF
  11200.     DFB    $0A,0    ;LF
  11201.     DFB    $0D,0    ;CR
  11202.  
  11203.  
  11204.  
  11205. ***************************************
  11206. *
  11207. * SET FILE TYPE BINARY
  11208. * ====================
  11209. *
  11210. * Sets files to be binary
  11211. *
  11212. ***************************************
  11213.  
  11214. SBIN    JSR    CONFIRM    ;no more parameters
  11215.     LDA    #1
  11216.     STA    FTYPE
  11217.     RTS
  11218.  
  11219.  
  11220. ***************************************
  11221. *
  11222. * SET FILE NAME
  11223. * =============
  11224. *
  11225. * Sets name translation mode to be used
  11226. *
  11227. ***************************************
  11228.  
  11229. SFNAME    LDX    #>SFNTAB ;point to table
  11230.     LDY    #<SFNTAB
  11231.     JSR    GMPAS    ;get parameter and validate it
  11232.     JSR    CONFIRM    ;check no more parameters
  11233.     STA    FNTYPE    ;and save the result
  11234.     RTS
  11235.  
  11236. SFNTAB    DW    0    ;no jump table
  11237.     CMD    6,'NORMAL'
  11238.     CMD    12,'UNTRANSLATED'
  11239.     DFB    0
  11240.  
  11241.  
  11242.     IF    ROM
  11243. ***************************************
  11244. *
  11245. * SET FILE BUFFER-SIZE
  11246. * ====================
  11247. *
  11248. * Specifies size of the buffer area used
  11249. *
  11250. ***************************************
  11251.  
  11252. SFBUFF    LDA    #103    ;select help text
  11253.     JSR    LSTMNP    ;get num par, check no more
  11254. *
  11255. * Value must be in range 1..64
  11256. *
  11257.     LDA    NUM    ;get value
  11258.     BEQ    SBF900    ;j if 0
  11259.     CMP    #65
  11260.     BCS    SBF900    ;j if > 64
  11261.     STA    FBPAGES    ;else note it
  11262.     RTS
  11263. *
  11264. * Parameter is out of range
  11265. *
  11266. SBF900    JMP    SRS900
  11267.     FI
  11268.  
  11269.  
  11270.  
  11271. ***************************************
  11272. *
  11273. * SET FILE WARNING
  11274. * ================
  11275. *
  11276. * Specifies action taken if file names
  11277. * clash on receive
  11278. *
  11279. ***************************************
  11280.  
  11281. SFWARN    JSR    LSTMSWP    ;get ON/OFF, check no more
  11282.     STA    FWARN    ;save the value
  11283.     RTS
  11284.  
  11285.  
  11286. ***************************************
  11287. *
  11288. * SET FILE SUFFIX
  11289. * ===============
  11290. *
  11291. * Defines string we add to make a remote
  11292. * filename
  11293. *
  11294. ***************************************
  11295.  
  11296. SFSUFF    EQU    *
  11297. *
  11298. * Next parameter is the optional suffix string
  11299. *
  11300.     LDA    #114    ;select help text
  11301.     JSR    LSTPAR    ;get param, check no more
  11302.     BCS    SFF800    ;j if not there
  11303. *
  11304. * Check size of the parameter
  11305. *
  11306.     LDY    CURLEN
  11307.     CPY    #9
  11308.     BCS    SFF900    ;j if too long
  11309. *
  11310. * Note size, and the string itself
  11311. *
  11312.     STY    SUFLEN    ;note size
  11313.     DEY
  11314. SFF200    LDA    (CURPAR),Y ;else copy string over
  11315.     STA    SUFFIX,Y
  11316.     DEY
  11317.     BPL    SFF200
  11318.     RTS        ;and finish
  11319. *
  11320. * Here parameter is null
  11321. *
  11322. SFF800    LDY    #0    ;mark size as zero
  11323.     STY    SUFLEN
  11324.     RTS
  11325. *
  11326. * Here string is too long
  11327. *
  11328. SFF900    LDA    #189    ;get error text
  11329.     JMP    PARMERR    ;and report
  11330.  
  11331.  
  11332. ***************************************
  11333. *
  11334. * SET FLOW-CONTROL
  11335. * ================
  11336. *
  11337. * Selects XON/XOFF or CTS/RTS control
  11338. *
  11339. ***************************************
  11340.  
  11341. SFCON    EQU    *
  11342. *
  11343. * Next parameter is the flow control type
  11344. *
  11345.     LDX    #>SFCTAB ;select option table
  11346.     LDY    #<SFCTAB
  11347.     JSR    GMPAS    ;get parameter and validate it
  11348.     JSR    CONFIRM    ;check it's the only one
  11349.     STA    FLOW    ;save the new value
  11350.     RTS
  11351.  
  11352. SFCTAB    DW    0    ;no jump table
  11353.     CMD    8,'XON/XOFF'
  11354.     CMD    7,'CTS/RTS'
  11355.     DFB    0
  11356.  
  11357.  
  11358. ***************************************
  11359. *
  11360. * SET KEY-CLICK
  11361. * =============
  11362. *
  11363. * Controls whether keys click in terminal
  11364. * mode
  11365. *
  11366. ***************************************
  11367.  
  11368. STKCLK    JSR    LSTMSWP    ;get ON/OFF, check no more
  11369.     STA    CLICK    ;and save the value
  11370.     RTS
  11371.  
  11372.  
  11373. ***************************************
  11374. *
  11375. * SET MUX-WAIT
  11376. * ============
  11377. *
  11378. * Defines delay before testing CTS when
  11379. * talking to a slow MUX system
  11380. *
  11381. ***************************************
  11382.  
  11383. SMUXWT    EQU    *
  11384. *
  11385. * Next parameter is time in byte periods
  11386. *
  11387.     LDA    #21    ;select help text
  11388.     JSR    LSTMNP    ;get num par, check no more
  11389.     STA    MUXWT    ;and save the value
  11390.     RTS
  11391.  
  11392.  
  11393. ***************************************
  11394. *
  11395. * SET HELP-TRIGGER
  11396. * ================
  11397. *
  11398. * Changes command line character that
  11399. * triggers autohelp output
  11400. *
  11401. ***************************************
  11402.  
  11403. SHTRG    EQU    *
  11404. *
  11405. * Next param is mandatory, and is the character
  11406. *
  11407.     LDX    #>SHTTB ;point to table
  11408.     LDY    #<SHTTB
  11409.     JSR    GMPAS    ;get parameter and validate it
  11410.     LDY    #0
  11411.     LDA    (CURPAR),Y ;get the actual character
  11412.     JSR    CONFIRM    ;check no more parameters
  11413.     STA    HLPTRG    ;save the new value
  11414.     RTS        ;and finish
  11415.  
  11416. SHTTB    DW    0    ;no jump table
  11417.     CMD    1,'?'
  11418.     CMD    1,'&'
  11419.     CMD    1,'/'
  11420.     CMD    1,'#'
  11421.     CMD    1,'@'
  11422.     DFB    0
  11423.  
  11424.  
  11425.  
  11426.     CHN    BBCST2
  11427. ****** File BBCST2 *************************************************************
  11428.     START    ST2
  11429. * BBCST2: Updated 09/05/86 @ 1730
  11430.  
  11431. ***************************************
  11432. *
  11433. * SET TERMINAL
  11434. * ============
  11435. *
  11436. * Selects terminal type
  11437. *
  11438. ***************************************
  11439.  
  11440. STERM    LDX    #>STTAB    ;point to table
  11441.     LDY    #<STTAB
  11442.     JSR    GMPAS    ;get parameter and validae it
  11443.     JSR    CONFIRM    ;check no more parameters
  11444.     STA    TTYPE    ;and note the new type
  11445.     RTS
  11446.  
  11447. STTAB    DW    0    ;no jump table
  11448.     CMD    4,'TT40' ;the first 5 entries must not be moved
  11449.     CMD    4,'TT80' ;or changed as the numbers and types are known
  11450.     CMD    4,'VT52' ;to TXRs
  11451.     CMD    5,'VT100'
  11452.     CMD    3,'TEK'
  11453.     CMD    1,'A'    ;change these names if you wish
  11454.     CMD    1,'B'
  11455.     DFB    0
  11456.  
  11457.  
  11458. ***************************************
  11459. *
  11460. * SET VDU-COLOUR
  11461. * ==============
  11462. *
  11463. * Selects text colour for 80 column VDU
  11464. * or 80 column command mode screens
  11465. *
  11466. ***************************************
  11467.  
  11468. SVDCOL    EQU    *
  11469.     IF    RAM
  11470.     JSR    CKSHAD    ;BRK if no shadow RAM
  11471.     FI
  11472. *
  11473. * Next parameter is the colour
  11474. *
  11475.     LDX    #>SVDCTB ;point to table
  11476.     LDY    #<SVDCTB
  11477.     JSR    GMPAS    ;get parameter and validate it
  11478.     JSR    CONFIRM    ;check no more
  11479. *
  11480. * Value is OK. Colour we store is table value plus 1 (since we
  11481. * don't allow colour 0 which is BLACK)
  11482. *
  11483.     TAX
  11484.     INX
  11485.     STX    VDUCOL
  11486. *
  11487. * We might be an 80 column command screen, so change colour now in case
  11488. *
  11489.     JMP    SMD200
  11490.  
  11491. SVDCTB    DW    0    ;no jump table
  11492.     CMD    3,'RED'
  11493.     CMD    5,'GREEN'
  11494.     CMD    6,'YELLOW'
  11495.     CMD    4,'BLUE'
  11496.     CMD    7,'MAGENTA'
  11497.     CMD    4,'CYAN'
  11498.     CMD    5,'WHITE'
  11499.     DFB    0
  11500.  
  11501.  
  11502.     IF    ROM
  11503. ***************************************
  11504. *
  11505. * SET SOURCE
  11506. * ==========
  11507. *
  11508. * Sets source of data we transmit
  11509. *
  11510. ***************************************
  11511.  
  11512. SSOURCE EQU    *
  11513. *
  11514. * Next parameter specifies the source
  11515. *
  11516.     LDX    #>SSRTAB ;point to table
  11517.     LDY    #<SSRTAB
  11518.     JSR    GMPAS    ;get the parameter and validate it
  11519.     JMP    ACTION    ;action it if it is
  11520.  
  11521. SSRTAB    DW    SSRJMP
  11522.     CMD    4,'FILE'
  11523.     CMD    6,'MEMORY'
  11524.     DFB    0
  11525.  
  11526. SSRJMP    DW    SSFILE    ;SET SOURCE FILE
  11527.     DW    SSMEM    ;SET SOURCE MEMORY
  11528.     FI
  11529.  
  11530.  
  11531.     IF    ROM
  11532. ***************************************
  11533. *
  11534. * SET SOURCE FILE
  11535. * ===============
  11536. *
  11537. * Sets data source for transmit to be 
  11538. * the filestore
  11539. *
  11540. ***************************************
  11541.  
  11542. SSFILE    JSR    CONFIRM    ;check no more params
  11543.     LDA    #0
  11544.     STA    SOURCE
  11545.     RTS
  11546.     FI
  11547.  
  11548.  
  11549.     IF    ROM
  11550. ***************************************
  11551. *
  11552. * SET SOURCE MEMORY
  11553. * =================
  11554. *
  11555. * Sets data source to main memory
  11556. *
  11557. ***************************************
  11558.  
  11559. SSMEM    EQU    *
  11560. *
  11561. * Next param is start address in hex
  11562. *
  11563.     LDA    #102    ;select help text
  11564.     JSR    GETMPAR    ;get parameter
  11565.     JSR    HEXPAR    ;convert to binary
  11566.     LDA    NUM
  11567.     STA    MSBASE    ;and note it
  11568.     LDA    NUM+1
  11569.     STA    MSBASE+1
  11570. *
  11571. * Then comes the address of last byte + 1
  11572. *
  11573.     JSR    MPARAM    ;is it there?
  11574.     JSR    HEXPAR    ;yes, so convert it
  11575.     JSR    CONFIRM    ;make sure no more params
  11576.     LDA    NUM    ;note the value
  11577.     STA    MSTOP
  11578.     LDA    NUM+1
  11579.     STA    MSTOP+1
  11580. *
  11581. * Note source is MEMORY
  11582. *
  11583.     LDA    #1
  11584.     STA    SOURCE
  11585.     RTS
  11586.     FI
  11587.  
  11588.  
  11589.  
  11590. ***************************************
  11591. *
  11592. * SET DESTINATION
  11593. * ===============
  11594. *
  11595. * Sets destination of data we receive
  11596. *
  11597. ***************************************
  11598.  
  11599. SDEST    EQU    *
  11600. *
  11601. * Next parameter specifies the source
  11602. *
  11603.     LDX    #>SDETAB ;point to table
  11604.     LDY    #<SDETAB
  11605.     JSR    GMPAS    ;get parameter and validate it
  11606.     JMP    ACTION    ;action it if it is
  11607.  
  11608. SDETAB    DW    SDEJMP
  11609.     CMD    4,'FILE'
  11610.     IF    ROM
  11611.     CMD    6,'MEMORY'
  11612.     FI
  11613.     CMD    7,'PRINTER'
  11614.     DFB    0
  11615.  
  11616. SDEJMP    DW    SDFILE    ;SET DESTINATION FILE
  11617.     IF    ROM
  11618.     DW    SDMEM    ;SET DESTINATION MEMORY
  11619.     FI
  11620.     DW    SDPRT    ;SET DESTINATION PRINTER
  11621.  
  11622.  
  11623. ***************************************
  11624. *
  11625. * SET DESTINATION FILE
  11626. * ====================
  11627. *
  11628. * Sets destination for received data to
  11629. * be the filestore
  11630. *
  11631. ***************************************
  11632.  
  11633. SDFILE    JSR    CONFIRM    ;check no more params
  11634.     LDA    #0
  11635. SDF200    STA    DESTIN
  11636.     RTS
  11637.  
  11638.  
  11639. ***************************************
  11640. *
  11641. * SET DESTINATION PRINTER
  11642. * =======================
  11643. *
  11644. * Routes data direct to parallel printer
  11645. *
  11646. ***************************************
  11647.  
  11648. SDPRT    JSR    CONFIRM    ;check no more parameters
  11649.     LDA    #2    ;and set flag
  11650.     BNE    SDF200
  11651.  
  11652.  
  11653.  
  11654.     IF    ROM
  11655. ***************************************
  11656. *
  11657. * SET DESTINATION MEMORY
  11658. * ======================
  11659. *
  11660. * Sets data destination to memory starting
  11661. * at the specified address
  11662. *
  11663. ***************************************
  11664.  
  11665. SDMEM    EQU    *
  11666. *
  11667. * next parameter is start address in hex
  11668. *
  11669.     LDA    #102    ;set help text
  11670.     JSR    GETMPAR    ;get the parameter
  11671.     JSR    HEXPAR    ;yes, so convert to hex
  11672.     JSR    CONFIRM    ;check no more params
  11673. *
  11674. * Set up start of buffer address
  11675. *
  11676.     LDA    NUM
  11677.     STA    MDBASE
  11678.     LDA    NUM+1
  11679.     STA    MDBASE+1
  11680. *
  11681. * Set top of buffer to the base of a MODE 7 screen
  11682. *
  11683.     LDX    #$7C
  11684.     STX    MDTOP+1
  11685.     LDX    #0
  11686.     STX    MDTOP
  11687. *
  11688. * Mark destination as MEMORY
  11689. *
  11690.     INX
  11691.     STX    DESTIN
  11692.     RTS    
  11693.     FI
  11694.  
  11695.  
  11696. ***************************************
  11697. *
  11698. * SET SEND
  11699. * ========
  11700. *
  11701. * Sets parameters affecting sending
  11702. *
  11703. ***************************************
  11704.  
  11705. SSEND    EQU    *
  11706. *
  11707. * Next parameter is the option to set
  11708. *
  11709.     LDX    #>SSNTAB ;point to table
  11710.     LDY    #<SSNTAB
  11711.     JSR    GMPAS    ;get parameter and validate it
  11712.     JMP    ACTION    ;and do it
  11713.  
  11714. SSNTAB    DW    SSNJMP
  11715.     CMD    15,'START-OF-PACKET'
  11716.     CMD    7,'PADCHAR'
  11717.     CMD    7,'PADDING'
  11718.     CMD    7,'TIMEOUT'
  11719.     CMD    5,'QUOTE'
  11720.     CMD    11,'END-OF-LINE'
  11721.     DFB    0
  11722.  
  11723. SSNJMP    DW    SSSOP    ;SET SEND START-OF-PACKET
  11724.     DW    SSPADC    ;SET SEND PADCHAR
  11725.     DW    SSNPAD    ;SET SEND PADDING
  11726.     DW    SSTIME    ;SET SEND TIMEOUT
  11727.     DW    SSQUOTE    ;SET SEND QUOTE
  11728.     DW    SSEOL    ;SET SEND END-OF-LINE
  11729.  
  11730.  
  11731. ***************************************
  11732. *
  11733. * SET SEND START-OF-PACKET
  11734. * ========================
  11735. *
  11736. * Defines value we send as start of 
  11737. * packet flag
  11738. *
  11739. ***************************************
  11740.  
  11741. SSSOP    LDA    #93    ;select help text
  11742.     JSR    LSTMNP    ;get num par, check no more
  11743.     CMP    #$20
  11744.     BCS    SSS900    ;j if > $1F
  11745.     STA    SSOP    ;else note it
  11746.     RTS
  11747. *
  11748. * Here parameter is out of range
  11749. *
  11750. SSS900    JMP    SRP900
  11751.  
  11752.  
  11753. ***************************************
  11754. *
  11755. * SET SEND TIMEOUT
  11756. * ================
  11757. *
  11758. * Defines timeout we ask remote to use
  11759. *
  11760. ***************************************
  11761.  
  11762. SSTIME    LDA    #101    ;select help text
  11763.     JSR    LSTMNP    ;get num par, check no more
  11764.     CMP    #95
  11765.     BCS    SSS900    ;j if not 0..94
  11766.     STA    STIME    ;else set it
  11767.     RTS
  11768.  
  11769.  
  11770. ***************************************
  11771. *
  11772. * SET SEND PADCHAR
  11773. * ================
  11774. *
  11775. * Defines the pad character we send
  11776. * initially
  11777. *
  11778. ***************************************
  11779.  
  11780. SSPADC    LDA    #94    ;select help text
  11781.     JSR    LSTMNP    ;get num par, check no more
  11782.     CMP    #32
  11783.     BCS    SSS900    ;j if not 0-31
  11784.     STA    SPADC    ;else save it
  11785.     RTS
  11786.  
  11787.  
  11788. ***************************************
  11789. *
  11790. * SET SEND PADDING
  11791. * ================
  11792. *
  11793. * Defines number of pads we send initially
  11794. *
  11795. ***************************************
  11796.  
  11797. SSNPAD    LDA    #95    ;select help text
  11798.     JSR    LSTMNP    ;get num par, check no more
  11799.     STA    SNPAD    ;note it
  11800.     RTS
  11801.  
  11802.  
  11803. ***************************************
  11804. *
  11805. * SET SEND QUOTE
  11806. * ==============
  11807. *
  11808. * Defines how we quote control characters
  11809. *
  11810. ***************************************
  11811.  
  11812. SSQUOTE LDA    #73    ;select help text
  11813.     JSR    LSTMCP    ;get char par, check no more
  11814. *
  11815. * Check character doesn't clash with the 8 bit prefix
  11816. *
  11817.     CMP    CUREBQ
  11818.     BEQ    SSQ900    ;j if it does
  11819.     STA    SQUOTE    ;else save the value
  11820.     RTS
  11821. *
  11822. * Here character clashes with the 8 bit prefix
  11823. *
  11824. SSQ900    LDA    #192    ;select error text
  11825.     JMP    PARMERR    ;and report
  11826.  
  11827.  
  11828. ***************************************
  11829. *
  11830. * SET SEND END-OF-LINE
  11831. * ====================
  11832. *
  11833. * Defines EOLN we use initially
  11834. *
  11835. ***************************************
  11836.  
  11837. SSEOL    LDA    #124    ;set help text
  11838.     JSR    LSTMNP    ;get num par, check no more
  11839.     CMP    #$20
  11840.     BCS    SSE900    ;j if not 0..31
  11841.     STA    SEOLN    ;else note new value
  11842.     RTS
  11843. SSE900    JMP    SRS900
  11844.  
  11845.  
  11846. ***************************************
  11847. *
  11848. * SET RECEIVE
  11849. * ===========
  11850. *
  11851. * Sets parameters affecting reception
  11852. *
  11853. ***************************************
  11854.  
  11855. SRECV    EQU    *
  11856. *
  11857. * Next parameter is the option to set
  11858. *
  11859.     LDX    #>SRCTAB ;point to table
  11860.     LDY    #<SRCTAB
  11861.     JSR    GMPAS    ;get parameter and validate it
  11862.     JMP    ACTION    ;and do it
  11863.  
  11864. SRCTAB    DW    SRCJMP
  11865.     CMD    15,'START-OF-PACKET'
  11866.     CMD    7,'PADCHAR'
  11867.     CMD    7,'PADDING'
  11868.     CMD    7,'TIMEOUT'
  11869.     CMD    13,'PACKET-LENGTH'
  11870.     CMD    11,'END-OF-LINE'
  11871.     DFB    0
  11872.  
  11873. SRCJMP    DW    SRSOP    ;SET RECEIVE START-OF-PACKET
  11874.     DW    SRPADC    ;SET RECEIVE PADCHAR
  11875.     DW    SRNPAD    ;SET RECEIVE PADDING
  11876.     DW    SRTIME    ;SET RECEIVE TIMEOUT
  11877.     DW    SRPLEN    ;SET RECEIVE PACKET-LENGTH
  11878.     DW    SREOL    ;SET RECEIVE END-OF-LINE
  11879.  
  11880.  
  11881. ***************************************
  11882. *
  11883. * SET RECEIVE START-OF-PACKET
  11884. * ===========================
  11885. *
  11886. * Defines value we receive as start of 
  11887. * packet flag
  11888. *
  11889. ***************************************
  11890.  
  11891. SRSOP    LDA    #98    ;select help text
  11892.     JSR    LSTMNP    ;get num par, check no more
  11893.     CMP    #$20
  11894.     BCS    SRS900    ;j if > $1F
  11895.     STA    RSOP    ;else note it
  11896.     RTS
  11897. *
  11898. * Here parameter is out of range
  11899. *
  11900. SRS900    LDA    #194    ;get error text
  11901.     JMP    PARMERR    ;and report
  11902.  
  11903.  
  11904. ***************************************
  11905. *
  11906. * SET RECEIVE TIMEOUT
  11907. * ===================
  11908. *
  11909. * Defines timeout we use on remote
  11910. * sending to us if TIMER is on
  11911. *
  11912. ***************************************
  11913.  
  11914. SRTIME    LDA    #92    ;select help text
  11915.     JSR    LSTMNP    ;get num par, check no more
  11916.     STA    RTIME    ;and set the value
  11917.     RTS
  11918.  
  11919.  
  11920. ***************************************
  11921. *
  11922. * SET RECEIVE PADCHAR
  11923. * ===================
  11924. *
  11925. * Defines the pad character we ask 
  11926. * other side to send
  11927. *
  11928. ***************************************
  11929.  
  11930. SRPADC    LDA    #99    ;select help text
  11931.     JSR    LSTMNP    ;get num par, check no more
  11932.     CMP    #32
  11933.     BCS    SRS900    ;j if not 0-31
  11934.     STA    RPADC    ;else save it
  11935.     RTS
  11936.  
  11937.  
  11938. ***************************************
  11939. *
  11940. * SET RECEIVE PADDING
  11941. * ===================
  11942. *
  11943. * Defines number of pads we ask other
  11944. * side to send
  11945. *
  11946. ***************************************
  11947.  
  11948. SRNPAD    LDA    #100    ;select help text
  11949.     JSR    LSTMNP    ;get num par, check no more
  11950.     CMP    #95
  11951.     BCS    SRS900    ;j if not 0..94
  11952.     STA    RNPAD    ;else note it
  11953.     RTS
  11954.  
  11955.  
  11956. ***************************************
  11957. *
  11958. * SET RECEIVE PACKET-LENGTH
  11959. * =========================
  11960. *
  11961. * Sets value we ask other end to use as
  11962. * maximum packet length
  11963. *
  11964. ****************************************
  11965.  
  11966. SRPLEN    LDA    #122    ;select help text
  11967.     JSR    LSTMNP    ;get num par, check no more
  11968.     CMP    #95
  11969.     BCS    SRP900    ;j if too big
  11970.     CMP    #35
  11971.     BCC    SRP900    ;j if too small
  11972.     STA    RMAXL    ;else note the value
  11973.     RTS
  11974. *
  11975. * Here value is out of range
  11976. *
  11977. SRP900    JMP    SRS900
  11978.  
  11979.  
  11980. ***************************************
  11981. *
  11982. * SET RECEIVE END-OF-LINE
  11983. * =======================
  11984. *
  11985. * Defines value we ask other end to use
  11986. * as end-of-line
  11987. *
  11988. ***************************************
  11989.  
  11990. SREOL    LDA    #123    ;select help text
  11991.     JSR    LSTMNP    ;get num par, check no more
  11992.     CMP    #$20    ;is value > 31?
  11993.     BCS    SRP900    ;j if not
  11994.     STA    REOLN    ;else note it
  11995.     RTS
  11996.  
  11997.  
  11998. ****************************************
  11999. *
  12000. * SET INCOMPLETE
  12001. * ==============
  12002. *
  12003. * Specifies fate of incomplete received
  12004. * files
  12005. *
  12006. ***************************************
  12007.  
  12008. SINCFD    EQU    *
  12009. *
  12010. * Next parameter is the action to take
  12011. *
  12012.     LDX    #>SITAB    ;select option table
  12013.     LDY    #<SITAB
  12014.     JSR    GMPAS    ;get parameter and validate it
  12015.     JSR    CONFIRM    ;check no more params
  12016.     STA    FINCOM    ;and save the value
  12017.     RTS
  12018.  
  12019. SITAB    DW    0    ;no jump table
  12020.     CMD    6,'DELETE'
  12021.     CMD    4,'KEEP'
  12022.     DFB    0
  12023.  
  12024.  
  12025. ***************************************
  12026. *
  12027. * SET TAKE-ECHO
  12028. * =============
  12029. *
  12030. * Controls whether TAKE file input is
  12031. * echoed to the screen or not
  12032. *
  12033. ***************************************
  12034.  
  12035. STKECH    JSR    LSTMSWP    ;get ON/OFF, check no more params
  12036.     STA    TKECHO    ;note the value
  12037.     RTS
  12038.  
  12039.  
  12040. ***************************************
  12041. *
  12042. * SET TV
  12043. * ======
  12044. *
  12045. * Selects/deselects auto *TV on entering
  12046. * terminal mode
  12047. *
  12048. ***************************************
  12049.  
  12050. STV    EQU    *
  12051. *
  12052. * Next parameter is optioanl, and is the first *TV param
  12053. *
  12054.     LDA    #143    ;select help text
  12055.     JSR    GETPAR    ;get parameter
  12056.     BCS    STV800    ;j if no param - turn facility off then
  12057.     JSR    NUMPAR    ;else convert to binary
  12058.     PHA        ;and save for a bit
  12059. *
  12060. * Next is the second *TV parameter, which is mandatory now
  12061. *
  12062.     LDA    #143    ;select help text
  12063.     JSR    LSTMNP    ;get num par, check no more
  12064. *
  12065. * Now save values in table and note we're to do a *TV
  12066. *
  12067.     STA    TVPAR2    ;save param 2
  12068.     PLA
  12069.     STA    TVPAR1    ;save param 1
  12070.     LDA    #1
  12071. STV700    STA    TVFLAG    ;note we do it
  12072.     RTS
  12073. *
  12074. * Here there were no parameters, so turn the facility off
  12075. *
  12076. STV800    LDA    #0
  12077.     BEQ    STV700
  12078.  
  12079.  
  12080. ***************************************
  12081. *
  12082. * SET IGNORE
  12083. * ==========
  12084. *
  12085. * Defines the incoming byte ignored in
  12086. * terminal mode
  12087. *
  12088. ***************************************
  12089.  
  12090. SIGNRE    EQU    *
  12091. *
  12092. * Next parameter is optional, and is the byte to ignore
  12093. *
  12094.     LDA    #141    ;select help text
  12095.     JSR    GETPAR    ;get parameter
  12096.     BCS    SGN400    ;j if not there - turn facility off
  12097. *
  12098. * Param is there, so note it
  12099. *
  12100.     JSR    NUMPAR    ;convert to binary
  12101.     JSR    CONFIRM    ;check no more parameters
  12102.     STA    IGNCHR    ;note character
  12103.     LDA    #$01
  12104. SGN300    STA    IGNFLG    ;note facility is on
  12105.     RTS
  12106. *
  12107. * Here there's no parameter, so turn the facility off
  12108. *
  12109. SGN400    LDA    #0
  12110.     BEQ    SGN300
  12111.  
  12112.  
  12113. ***************************************
  12114. *
  12115. * SET RETRIES
  12116. * ===========
  12117. *
  12118. * Sets max no of packet retransmissions
  12119. * allowed
  12120. *
  12121. ***************************************
  12122.  
  12123. SRTRY    EQU    *
  12124. *
  12125. * Next parameter is a number, 1..255
  12126. *
  12127.     LDA    #150    ;select help text
  12128.     JSR    LSTMNP    ;get num par, check no more
  12129.     CMP    #0
  12130.     BEQ    SRT900    ;j if value is 0
  12131.     STA    MAXTRY    ;else note it
  12132.     RTS
  12133. *
  12134. * Here value is out of range
  12135. *
  12136. SRT900    JMP    SRP900
  12137.  
  12138.  
  12139. ***************************************
  12140. *
  12141. * SET HANDSHAKE
  12142. * =============
  12143. *
  12144. * Sets the turnround character for some
  12145. * IBM systems
  12146. *
  12147. ***************************************
  12148.  
  12149. SHSHAK    EQU    *
  12150. *
  12151. * Parameter is the handshake type
  12152. *
  12153.     LDX    #>SKTAB    ;point to table
  12154.     LDY    #<SKTAB
  12155.     JSR    GMPAS    ;get parameter and validate it
  12156.     JSR    CONFIRM    ;make sure no more parameters
  12157.     STA    HSHAKE    ;and note the handshake type
  12158.     RTS
  12159.  
  12160. SKTAB    DW    0    ;no jump table
  12161.     CMD    4,'NONE'
  12162.     CMD    4,'BELL'
  12163.     CMD    2,'CR'
  12164.     CMD    2,'LF'
  12165.     CMD    3,'XON'
  12166.     CMD    4,'XOFF'
  12167.     DFB    0
  12168.  
  12169. SKTAB2    DFB    0,$07,$0D,$0A,XON,XOFF
  12170.  
  12171.  
  12172.     CHN    BBCSHW
  12173. ****** File BBCTM1 *************************************************************
  12174.     START    TM1
  12175. * BBCTM1: Updated 10/01/87 @ 1730
  12176.  
  12177. ***************************************
  12178. *
  12179. * TERMINAL EMULATION
  12180. * ==================
  12181. *
  12182. * This provides 40 byte and 80 byte 
  12183. * teletype modes, and VT52 mode.
  12184. *
  12185. ***************************************
  12186.  
  12187. CONNECT EQU    *
  12188. *
  12189. * Check there are no more command line parameters
  12190. *
  12191.     JSR    CONFIRM
  12192. *
  12193. * Do we support the selected terminal type in this program image?
  12194. *
  12195.     LDA    TTYPE    ;get the type code
  12196.     CMP    #3
  12197.     BCS    CON040    ;j if not type 0..2
  12198. *
  12199. * Type is 0..2, so we handle terminal ourselves
  12200. *
  12201.     IF    ROM
  12202. *
  12203. * ROM version always supports 0..2
  12204. *
  12205.     BCC    CON070    ;all of 0..2 OK in ROM version
  12206.     ELSE
  12207. *
  12208. * RAM version needs B+ or Master for 1 or 2
  12209. *
  12210.     CMP    #0
  12211.     BEQ    CON070    ;j if type 0 (TT40) - always OK
  12212.     BIT    SHADOW    ;else we need shadow RAM
  12213.     BMI    CON070    ;j if we've got it
  12214.     BPL    CON060    ;else error
  12215.     FI
  12216. *
  12217. * Type is not 0..2, so we need help from a TXR. We'll pass the job
  12218. * over and see if one picks it up
  12219. *
  12220. CON040    LDX    #$82
  12221.     JSR    DOKOSB    ;ask TXR to take over
  12222.     BVS    CON060    ;j if it didn't want to or wasn't there
  12223.     RTS        ;else all done
  12224. *
  12225. * No TXR fitted and we don't do this type ourselves, so error
  12226. *
  12227. CON060    BRK
  12228.     DFB    0
  12229.     ASC    'Terminal not supported'
  12230.     DFB    0
  12231. *
  12232. * Type is supported here, so note we're providing the terminal mode
  12233. *
  12234. CON070    LDX    #0
  12235.     STX    TXRACT    ;TXR not active
  12236. *
  12237. * Set cursor keys as function keys or edit keys
  12238. *
  12239.     LSR    A
  12240.     ASL    A    ;0=TT40 or TT80, 2=VT52
  12241.     TAX
  12242.     STA    EDCRSR    ;note as cursor state flag
  12243.     LDA    #4    ;set cursor keys so they are
  12244.     JSR    OBX0    ;function for VT52, edit for other
  12245. *
  12246. * Make function keys return codes
  12247. *
  12248.     LDX    #>CONTB1 ;point table of base values
  12249.     LDY    #<CONTB1
  12250.     JSR    SETKEY    ;and set them up
  12251.     LDX    #245    ;set Master keypad to give distinct code
  12252.     JSR    SETPAD
  12253. *
  12254. * Do we need to define graphics characters 128-159 and set things to
  12255. * handle VT52 graphics?
  12256. *
  12257.     LDA    TTYPE    ;get terminal type
  12258.     CMP    #2
  12259.     BNE    CON120    ;j if not VT52
  12260. *
  12261. * Yes we do. Define characters by VDU 23 - block copy to
  12262. * $C00 won't work on Master128
  12263. *
  12264.     LDY    #0
  12265.     STY    GRMODE    ;clear graphics mode flag first
  12266.     LDA    #128
  12267.     STA    WORK0    ;start character code value
  12268. CON080    LDA    #23
  12269.     JSR    OSWRCH    ;VDU 23...
  12270.     LDA    WORK0
  12271.     JSR    OSWRCH    ;..then character value
  12272.     LDX    #8    ;start count for 8 bytes of definition
  12273. CON085    LDA    GRCHAR,Y ;get byte from definition
  12274.     JSR    OSWRCH    ;add to VDU 23
  12275.     INY        ;step to next byte in block
  12276.     BEQ    CON130    ;j if totally finished
  12277.     DEX
  12278.     BNE    CON085    ;j if this character not finished
  12279.     INC    WORK0    ;step character value on
  12280.     BNE    CON080    ;j always
  12281. *
  12282. * If we're a 40 column screen we go to mode 7
  12283. *
  12284. CON120    LDA    TTYPE    ;get terminal type
  12285.     BNE    CON130    ;j if 80 column
  12286.     LDA    #211
  12287.     JSR    MESS    ;else set up MODE 7 screen
  12288.     JMP    CON150    ;and set up terminal
  12289. *
  12290. * Here we're going into MODE 3.
  12291. *
  12292. CON130    JSR    STMDE3    ;into MODE 3 (with *TV if needed)
  12293.     LDA    #135
  12294.     JSR    MESS    ;output the status line
  12295. *
  12296. * Now we need to snapshot the status line for the first
  12297. * time, so set up the pointer to where this goes
  12298. *
  12299.     LDA    #&84
  12300.     JSR    OSBYTE    ;read bottom of display RAM
  12301.     STX    STCOPY    ;lsb is OK as it
  12302.     TYA
  12303.     SEC
  12304.     SBC    #4
  12305.     STA    STCOPY+1 ;but lower msb by 4 pages
  12306.     JSR    SNAPSL    ;then snapshot it
  12307. *
  12308. * Now note we're in terminal mode
  12309. *
  12310. CON150    LDA    #1
  12311.     STA    MODE    ;and note we're a terminal now
  12312. *
  12313. * Note stack and address for a restart
  12314. *
  12315.     TSX
  12316.     STX    STKRST
  12317.     LDA    #>CON800
  12318.     STA    RESTART
  12319.     LDA    #<CON800
  12320.     STA    RESTART+1
  12321. *
  12322. * Set initial state to printer off, logging off, and noscroll clear
  12323. *
  12324. CON180    LDA    #0
  12325.     STA    SCROLL    ;clear noscroll
  12326.     STA    PRINTER    ;clear printer flag
  12327.     STA    LOGON    ;clear logging flag
  12328.     JSR    PRTOFF    ;ensure printer is off...
  12329.     JSR    HOSTON    ;..and host is on
  12330. *
  12331. * Initialise LF suppress flag and line counts
  12332. *
  12333.     JSR    VDUINI
  12334. *
  12335. * And set up the standard character disposition vector to handle incoming bytes
  12336. *
  12337.     JSR    INICDV
  12338. *
  12339. * Now the terminal loop. Is anything happening?
  12340. *
  12341.     JSR    FLSHKB    ;flush keyboard buffer first time in
  12342. CON200    JSR    RXBYTE    ;look at comms and keyboard
  12343.     BCC    CON230    ;j if from host
  12344.     JMP    CON400    ;else it's keyboard
  12345. *
  12346. * Byte is in from the host. Do we ignore it?
  12347. *
  12348. CON230    AND    #%01111111 ;remove B7 from received byte
  12349.     LDY    IGNFLG    ;look at the ignore flag
  12350.     BEQ    CON280    ;j if no ignore char defined
  12351.     CMP    IGNCHR    ;else check this character
  12352.     BEQ    CON200    ;j if we do ignore it
  12353. *
  12354. * Log byte to file if necessary
  12355. *
  12356. CON280    JSR    TXE500
  12357. *
  12358. * And go to where the character disposition vector points
  12359. *
  12360. CON300    JSR    CON310
  12361.     JMP    CON200    ;and round again
  12362. CON310    JMP    (CHARIN)
  12363. *
  12364. * Had a keypress. Shall we click discretely?
  12365. *
  12366. CON400    PHA        ;save the key
  12367.     LDA    CLICK    ;get click flag
  12368.     BEQ    CON420    ;j if not wanted
  12369.     LDA    #7
  12370.     LDX    #>CLKBLK
  12371.     LDY    #<CLKBLK
  12372.     JSR    OSWORD    ;else click
  12373. CON420    PLA        ;restore key code    
  12374. *
  12375. * Now check to see if code is from the Master keypad
  12376. *
  12377.     CMP    #$D2
  12378.     BCS    CON460    ;j if so
  12379. *
  12380. * Is it a CONTROL-F key then?
  12381. *
  12382.     CMP    #CFKEY
  12383.     BCC    CON450    ;j if not
  12384.     CMP    #CFKEY+10
  12385.     BCS    CON450    ;j if not
  12386.     SEC
  12387.     SBC    #CFKEY    ;else scale to 0..9
  12388.     LDX    #>CFJTAB ; point to jump table
  12389.     STX    JMPTBL
  12390.     LDX    #<CFJTAB
  12391.     STX    JMPTBL+1
  12392.     JSR    ACTION    ;handle the key
  12393.     JMP    CON200    ;and round for the next
  12394. *
  12395. * Not a CONTROL-F key, so check for F and SHIFT-F and CURSOR
  12396. *
  12397. CON450    CMP    #FKEY
  12398.     BCC    CON600    ;j if not
  12399. *
  12400. * It's either cursor key, F key, SHIFT-F key or keypad key
  12401. *
  12402. CON460    LDX    TTYPE    ;are we a VT52?
  12403.     CPX    #2
  12404.     BNE    CON465    ;j if not - ignore the key
  12405.     JSR    CFSF    ;else action it
  12406. CON465    JMP    CON200
  12407. *
  12408. * Here we're ready to send the byte to the host and maybe
  12409. * echo and log it
  12410. *
  12411. CON600    LDX    TXHAND    ;are we using a TRANSMIT file?
  12412.     BNE    CON650    ;j if we are
  12413.     JSR    TXECHO    ;else simply send the byte
  12414. CON630    JMP    CON200    ;and round again
  12415. *
  12416. * Here the byte is from a TRANSMIT file, so we have to look at what it is
  12417. *
  12418. CON650    CMP    #$0A
  12419.     BNE    CON670    ;j if not LF
  12420. *
  12421. * It's an LF from a TRANSMIT file - maybe we ignore this one
  12422. *
  12423.     LDX    FTYPE    ;otherwise, are we file type ASCII?
  12424.     BNE    CON670    ;j if not
  12425.     LDX    EORTYP    ;else are we ASCII CR?
  12426.     CPX    #3
  12427.     BEQ    CON630    ;j if we are - we ignore the LF
  12428. *
  12429. * We're OK to send the TRANSMIT file byte here
  12430. *
  12431. CON670    PHA        ;save it for a bit
  12432.     JSR    TXECHO    ;send it
  12433.     PLA        ;and get it back
  12434. *
  12435. * If we just sent a CR, pause for the host to catch up
  12436. *
  12437.     CMP    #$0D
  12438.     BNE    CON630    ;j if not CR
  12439.     JSR    TIMBRK    ;else wait about half a second
  12440.     JSR    TIMBRK
  12441.     BEQ    CON630    ;then carry on
  12442. *
  12443. * We come here after a BRK restart. Are we providing the terminal
  12444. * emulation ourselves?
  12445. *
  12446. CON800    BIT    TXRACT
  12447.     BMI    CON810    ;j if TXR is doing it
  12448.     JMP    CON180    ;else restart ourselves
  12449. *
  12450. * Here a TXR is doing the terminal emulation, so restart him
  12451. *
  12452. CON810    LDX    #$83
  12453.     JMP    DOKOSB
  12454.  
  12455. CLKBLK    DW    &11    ;click on channel 1 with flush
  12456.     DW    -8    ;amplitude -8
  12457.     DW    20    ;pitch 20
  12458.     DW    1    ;duration 1
  12459.  
  12460. CONTB1    DFB    FKEY,SFKEY,CFKEY,1 ;function key base values
  12461.  
  12462.  
  12463. ***************************************
  12464. *
  12465. * STDCHR
  12466. * ======
  12467. *
  12468. * Handles an incoming (or local echoed)
  12469. * character that isn't in an ESCAPE
  12470. * sequence
  12471. *
  12472. ***************************************
  12473.  
  12474. STDCHR    CMP    #$1B    ;is the character ESCAPE?
  12475.     BNE    SCR500    ;j if not
  12476.     LDY    TTYPE    ;else get terminal type
  12477.     CPY    #2
  12478.     BNE    SCR500    ;we're not VT52, so ignore ESCAPE
  12479.     LDA    #>ESC100 ;set up address of handler for next time
  12480.     STA    CHARIN
  12481.     LDA    #<ESC100
  12482.     STA    CHARIN+1
  12483.     RTS
  12484. *
  12485. * Not an ESCAPE, so echo to the screen
  12486. *
  12487. SCR500    JMP    ECHOCH
  12488.  
  12489.  
  12490.  
  12491. ***************************************
  12492. *
  12493. * TXECHO
  12494. * ======
  12495. *
  12496. * Transmits byte to host, maybe with
  12497. * echo and log
  12498. *
  12499. ***************************************
  12500.  
  12501. TXECHO    JSR    TXBYTE    ;send the byte to host
  12502.     LDX    ECHO
  12503.     BEQ    TXE900    ;j if not in local echo mode
  12504.     PHA        ;else save the byte
  12505.     JSR    CON310    ;put it through std character handler for echo
  12506.     PLA        ;reload the byte
  12507. TXE500    BIT    LOGON    ;is logging to disc on?
  12508.     BPL    TXE900    ;j if not
  12509.     JMP    TOLOG    ;else log the byte as well
  12510. TXE900    RTS
  12511.  
  12512.  
  12513.  
  12514. ***************************************
  12515. *
  12516. * ECHOCH
  12517. * ======
  12518. *
  12519. * Echoes character to the terminal screen
  12520. *
  12521. ***************************************
  12522.  
  12523. ECHOCH    CMP    #$0A
  12524.     BNE    ECH500    ;j if not LF
  12525. *
  12526. * It is LF. Don't display if suppression flag set
  12527. *
  12528.     JSR    LFOUT    ;output it if we need to
  12529.     BCS    ECH200    ;j if output was suppressed
  12530.     JMP    RFSHSL    ;refresh status line
  12531. *
  12532. * LF was suppressed on screen, so if printer is on we send
  12533. * it to there alone 
  12534. *
  12535. ECH200    BIT    PRINTER    ;printer on?
  12536.     BPL    ECH510    ;j if not
  12537.     LDA    #1
  12538.     JSR    OSWRCH    ;else VDU 1
  12539.     LDA    #$0A
  12540. ECH450    JMP    OSWRCH    ;and the LF
  12541. *
  12542. * Not an LF. Look for DEL, BEL, BS, CR, FF and TAB now
  12543. *
  12544. ECH500    CMP    #$7F
  12545.     BEQ    ECH520    ;j if DEL
  12546.     CMP    #$07
  12547.     BEQ    ECH450    ;j if BEL
  12548.     CMP    #$08
  12549.     BEQ    ECH520    ;j if BS
  12550.     CMP    #$0C
  12551.     BEQ    ECH560    ;j if FF
  12552.     CMP    #$0D
  12553.     BEQ    ECH540    ;j if CR
  12554.     CMP    #$09
  12555.     BEQ    ECH800    ;j if TAB
  12556. *
  12557. * Any other control characters are ignored
  12558. *
  12559.     CMP    #32
  12560.     BCS    ECH600    ;j if not contol char
  12561. ECH510    RTS
  12562. *
  12563. * Here character is DEL or BS
  12564. *
  12565. ECH520    JMP    DELOUT
  12566. *
  12567. * Here character is CR
  12568. *
  12569. ECH540    JMP    CROUT
  12570. *
  12571. * Here it's FF, so clear the screen
  12572. *
  12573. ECH560    LDX    TTYPE    ;get terminal type
  12574.     BNE    ECH580    ;j if 80 bytes wide
  12575.     JMP    FFOUT    ;for 40 byte terminal simply write $0C
  12576. *
  12577. * For 80 byte terminal we do it in a window
  12578. *
  12579. ECH580    LDA    #48
  12580.     JSR    MESS    ;set window and clear
  12581.     JMP    VDUINI    ;reset VDU counters
  12582. *
  12583. * Do we need to transform character into a VT52 graphics character?
  12584. *
  12585. ECH600    BIT    GRMODE    ;in VT52 graphics mode?
  12586.     BPL    ECH700    ;j if not
  12587.     CMP    #95    ;else check fro graphics character
  12588.     BCC    ECH700    ;j if not graphics
  12589.     CMP    #128
  12590.     BCS    ECH700    ;j if not graphics
  12591.     ADC    #33    ;else scale char to 128..159
  12592. *
  12593. * Character is now ready for output
  12594. *
  12595. ECH700    JSR    CHROUT    ;output it
  12596.     BEQ    ECH790    ;j if not last on line
  12597. ECH750    JSR    RFSHSL    ;else refresh status line
  12598. ECH790    RTS
  12599. *
  12600. * Here character was TAB
  12601. *
  12602. ECH800    JSR    TABOUT    ;handle it
  12603.     BCS    ECH750    ;j if new line was started
  12604.     RTS
  12605.  
  12606.  
  12607. ***************************************
  12608. *
  12609. * TOLOG
  12610. * =====
  12611. *
  12612. * Writes byte to terminal log file
  12613. *
  12614. ***************************************
  12615.  
  12616. TOLOG    EQU    *
  12617. *
  12618. * Put byte into buffer and see if it's full
  12619. *
  12620.     PHA        ;save the byte
  12621.     LDY    LOGCNT
  12622.     STA    LOGBUF,Y ;store byte
  12623.     INC    LOGCNT    ;move pointer
  12624.     BNE    TLG900    ;j if buffer not full
  12625. *
  12626. * Disc write needed, so ensure host is stopped
  12627. *
  12628.     LDA    IOSTOP    ;stopped already?
  12629.     STA    WORK6    ;note this
  12630.     BNE    TLG200    ;j if stopped
  12631.     JSR    HOSTOFF    ;else stop him
  12632. *
  12633. * Now delay to let bytes in transit trickle through
  12634. *
  12635. TLG200    LDX    #3    ;3 byte period delay
  12636.     LDY    RXBAUD    ;at receive baud rate
  12637.     JSR    BYTEWT
  12638. *
  12639. * We should be safe to write the disc now without missing any
  12640. * bytes in due to NMI
  12641. *
  12642.     LDA    #0    ;byte count is 256 (=0)
  12643.     JSR    WLOGB    ;write buffer to disc
  12644. *
  12645. * Restore host to the state it was in on entry now
  12646. *
  12647.     LDA    WORK6    ;get entry state
  12648.     BNE    TLG900    ;j if he was stopped
  12649.     JSR    HOSTON    ;else start him
  12650. TLG900    PLA        ;restore the byte we logged
  12651.     RTS
  12652.  
  12653.  
  12654. ***************************************
  12655. *
  12656. * RSTLIN
  12657. * ======
  12658. *
  12659. * Resets the count of characters on a
  12660. * line
  12661. *
  12662. ***************************************
  12663.  
  12664. RSTLIN    LDA    MODE
  12665.     BEQ    RSL500    ;j if command mode
  12666. *
  12667. * We're in terminal mode, so use the terminal width value
  12668. *
  12669.     LDY    TTYPE
  12670.     LDA    RSLTBL,Y ;get size of line
  12671. RSL100    STA    VDUCNT    ;save character count
  12672.     SEC
  12673.     SBC    #7
  12674.     STA    TABEND    ;save last tab position
  12675.     RTS
  12676. *
  12677. * Here we're in command mode
  12678. *
  12679. RSL500    LDA    CSCRLN
  12680.     BNE    RSL100
  12681.  
  12682. RSLTBL    DFB    39,79,79
  12683.  
  12684.  
  12685. ***************************************
  12686. *
  12687. * INICDV
  12688. * ======
  12689. *
  12690. * Sets up the default character
  12691. * disposition vector
  12692. *
  12693. ***************************************
  12694.  
  12695. INICDV    LDA    #>STDCHR
  12696.     STA    CHARIN
  12697.     LDA    #<STDCHR
  12698.     STA    CHARIN+1
  12699.     RTS
  12700.  
  12701.  
  12702. ***************************************
  12703. *
  12704. * TABOUT
  12705. * ======
  12706. *
  12707. * Outputs a TAB character
  12708. *
  12709. ***************************************
  12710.  
  12711. TABOUT    JSR    LOCATE    ;where are qe?
  12712.     CPY    TABEND
  12713.     BCC    DOT300    ;j if room to tab on this line
  12714.     JSR    OSNEWL    ;else atart new line
  12715.     SEC
  12716.     RTS
  12717. *
  12718. * Room to tab, so output spaces to next tab stop
  12719. *
  12720. DOT300    TXA
  12721.     AND    #%00000111
  12722.     EOR    #%00000111
  12723.     TAX        ;spaces needed less 1
  12724.     LDA    #' '
  12725. DOT350    JSR    OSWRCH    ;print a space
  12726.     DEC    VDUCNT    ;count it
  12727.     DEX
  12728.     BPL    DOT350
  12729. *
  12730. * No new line started, so ensure LF suppression is off
  12731. *
  12732.     JSR    NOLFSP
  12733.     CLC
  12734.     RTS
  12735.  
  12736.  
  12737. ***************************************
  12738. *
  12739. * NOLFSP
  12740. * ======
  12741. *
  12742. * Turns LF suppression flag off
  12743. *
  12744. ***************************************
  12745.  
  12746. NOLFSP    LDA    #0
  12747. NSP100    STA    LFSUPP
  12748.     RTS
  12749.  
  12750.  
  12751. ***************************************
  12752. *
  12753. * LFOUT
  12754. * =====
  12755. *
  12756. * Outputs an LF character
  12757. *
  12758. ***************************************
  12759.  
  12760. LFOUT    BIT    LFSUPP    ;is LF suppressed?
  12761.     BMI    LFT800    ;j if so
  12762.     JSR    OSWRCH    ;else print the LF
  12763.     CLC
  12764.     RTS
  12765. LFT800    JSR    NOLFSP    ;suppression was on, so clear it
  12766.     SEC
  12767.     RTS
  12768.  
  12769.  
  12770. ***************************************
  12771. *
  12772. * CHROUT
  12773. * ======
  12774. *
  12775. * Outputs a non-control character
  12776. *
  12777. ***************************************
  12778.  
  12779. CHROUT    JSR    OSWRCH    ;print the character
  12780.     DEC    VDUCNT    ;count it
  12781.     BPL    NOLFSP    ;j if it wasn't last on line
  12782. *
  12783. * BBC has done a CR-LF for us at end-of-line, so we suppress the
  12784. * next LF
  12785. *
  12786.     JSR    RSTLIN    ;reset character count
  12787.     LDA    #$FF
  12788.     BNE    NSP100    ;set LF suppression flag
  12789.  
  12790.  
  12791. ***************************************
  12792. *
  12793. * DELOUT
  12794. * ======
  12795. *
  12796. * Outputs a BS or DEL
  12797. *
  12798. ***************************************
  12799.  
  12800. DELOUT    JSR    OSWRCH
  12801.     INC    VDUCNT
  12802.     RTS
  12803.  
  12804.  
  12805. ***************************************
  12806. *
  12807. * CROUT
  12808. * =====
  12809. *
  12810. * Outputs a CR byte
  12811. *
  12812. ***************************************
  12813.  
  12814. CROUT    JSR    OSWRCH
  12815.     JMP    RSTLIN
  12816.  
  12817.  
  12818. ***************************************
  12819. *
  12820. * FFOUT
  12821. * =====
  12822. *
  12823. * Outputs a FF byte
  12824. *
  12825. ***************************************
  12826.  
  12827. FFOUT    JSR    OSWRCH    ;write the $0C
  12828.     JMP    VDUINI    ;reset VDU controls
  12829.  
  12830.  
  12831. ***************************************
  12832. *
  12833. * VDUINI
  12834. * ======
  12835. *
  12836. * Initialises counts and LF suppression
  12837. * flag
  12838. *
  12839. ***************************************
  12840.  
  12841. VDUINI    JSR    RSTLIN
  12842.     JMP    NOLFSP
  12843.  
  12844.  
  12845.     NEXT    BBCTM2
  12846. ****** File BBCTM2 *************************************************************
  12847.     START    TM2
  12848. * BBCTM2: Updated 13/05/86 @ 2000
  12849.  
  12850. ***************************************
  12851. *
  12852. * SNAPSL
  12853. * ======
  12854. *
  12855. * Copies the status line to our own
  12856. * RAM area
  12857. *
  12858. ***************************************
  12859.  
  12860. SNAPSL    JSR    FNDTOP    ;find address of top screen line
  12861.     STX    RSCPTR    ;save as source pointer
  12862.     STY    RSCPTR+1
  12863.     LDA    STCOPY    ;and set address of our copy area
  12864.     STA    PTR1    ;as destination
  12865.     LDA    STCOPY+1
  12866.     STA    PTR1+1
  12867. *
  12868. * Now move 640 bytes from screen to our copy area
  12869. *
  12870.     LDA    #5    ;start counts
  12871.     STA    WORK0
  12872. SPS200    LDA    #128
  12873.     STA    WORK1
  12874. *
  12875. * Pick up and copy next byte
  12876. *
  12877. SPS220    BIT    SHADOW    ;do we have a shadow screen?
  12878.     BPL    SPS500    ;j if not
  12879.     JSR    OSRDSC    ;else call OS to do it
  12880.     LDY    #0
  12881. SPS230    STA    (PTR1),Y ;and save it
  12882. *
  12883. * Step the destination pointer
  12884. *
  12885.     INC    PTR1
  12886.     BNE    SPS300
  12887.     INC    PTR1+1
  12888. *
  12889. * Step source pointe, handling the wrap at the end of the screen RAM area (note that
  12890. * even in shadow mode, a MODE 3 screen runs from $4000 to $7FFF - hardware maps
  12891. * this to the right place
  12892. *
  12893. SPS300    INC    RSCPTR    ;step lsb
  12894.     BNE    SPS400
  12895.     INC    RSCPTR+1 ;step msb
  12896.     BPL    SPS400    ;j if not reached $8000
  12897.     LDA    RSCPTR+1 ;else subtract $4000 from address
  12898.     SEC
  12899.     SBC    #$40
  12900.     STA    RSCPTR+1
  12901. *
  12902. * Any more to do?
  12903. *
  12904. SPS400    DEC    WORK1
  12905.     BNE    SPS220    ;j if so
  12906.     DEC    WORK0
  12907.     BNE    SPS200    ;j if so
  12908.     RTS        ;else finish
  12909. *
  12910. * Here we're ot in shadow mode, so get byte by hand
  12911. *
  12912. SPS500    LDY    #0
  12913.     LDA    (RSCPTR),Y
  12914.     JMP    SPS230
  12915.  
  12916.  
  12917. ***************************************
  12918. *
  12919. * RFSHSL
  12920. * ======
  12921. *
  12922. * Rewrites the status line to screen line
  12923. * zero
  12924. *
  12925. ***************************************
  12926.  
  12927. RFSHSL    LDA    TTYPE    ;get terminal type
  12928.     BEQ    RFS900    ;j if 40 byte screen - null call
  12929.     JSR    FNDTOP    ;X,Y point screen top line
  12930.     STX    WSCPTR    ;save as destination for move
  12931.     STY    WSCPTR+1
  12932.     LDA    STCOPY    ;set to move line from our copy area
  12933.     STA    PTR0
  12934.     LDA    STCOPY+1
  12935.     STA    PTR0+1
  12936. *
  12937. * Now move the data in 5 128-byte lumps (each lump is 16 display
  12938. * characters) as this minimises the times we check wrapround
  12939. *
  12940.     LDX    #5
  12941. RFS200    LDY    #127
  12942. *
  12943. * Move next 16 display characters
  12944. *
  12945. RFS210    LDA    (PTR0),Y ;get byte from copy area
  12946.     BIT    SHADOW    ;are we in shadow mode?
  12947.     BPL    RFS250    ;j if not
  12948.     JSR    OSWRSC    ;else let OS do it
  12949.     JMP    RFS280
  12950. *
  12951. * Not shadow mode, so we write byte by hand
  12952. *
  12953. RFS250    STA    (WSCPTR),Y
  12954. RFS280    DEY
  12955.     BPL    RFS210
  12956. *
  12957. * Increment source address
  12958. *
  12959.     LDA    PTR0
  12960.     CLC
  12961.     ADC    #128
  12962.     STA    PTR0
  12963.     BCC    RFS300
  12964.     INC    PTR0+1
  12965. *
  12966. * Increment destination, checking we don't fall off into the ROM area above $8000
  12967. *
  12968. RFS300    LDA    WSCPTR
  12969.     CLC
  12970.     ADC    #128
  12971.     STA    WSCPTR
  12972.     BCC    RFS380
  12973.     INC    WSCPTR+1
  12974. RFS350    BPL    RFS380    ;j if no wrap needed
  12975.     LDA    WSCPTR+1
  12976.     SBC    #$40    ;else move back into RAM (C set here)
  12977.     STA    WSCPTR+1
  12978. *
  12979. * And carry on till 80 display characters have gone
  12980. *
  12981. RFS380    DEX
  12982.     BNE    RFS200
  12983. RFS900    RTS        ;and that's it
  12984.  
  12985.  
  12986. ***************************************
  12987. *
  12988. * CONTROL-FUNCTION KEY HANDLERS
  12989. * =============================
  12990. *
  12991. * CF keys in terminal mode are handled here
  12992. *
  12993. ***************************************
  12994.  
  12995. CFJTAB    DW    CF0    ;CF0 - return to command mode
  12996.     DW    CF1    ;CF1 - disc toggle
  12997.     DW    CF2    ;CF2 - printer toggle
  12998.     DW    CF3    ;CF3 - scroll/noscroll
  12999.     DW    CF4    ;CF4 - cursor mode
  13000.     DW    NULLCF    ;CF5
  13001.     DW    NULLCF    ;CF6
  13002.     DW    NULLCF    ;CF7
  13003.     DW    LNGBRK    ;CF8 - long break
  13004.     DW    SHTBRK    ;CF9 - short break level
  13005.  
  13006.  
  13007. ***************************************
  13008. *
  13009. * CF0
  13010. * ---
  13011. *
  13012. * Return to command mode
  13013. *
  13014. ***************************************
  13015.  
  13016. CF0    PLA        ;lose link to this routine
  13017.     PLA
  13018.     RTS
  13019.  
  13020.  
  13021. ***************************************
  13022. *
  13023. * CF1
  13024. * ===
  13025. *
  13026. * Toggle disc logging
  13027. *
  13028. ***************************************
  13029.  
  13030. CF1    LDA    LHAND    ;is log file open?
  13031.     BEQ    CF1900    ;j if not
  13032.     LDA    LOGON
  13033.     EOR    #$FF
  13034.     STA    LOGON    ;else toggle flag
  13035.     TAY
  13036.     INY        ;form 0 or 1 from toggle
  13037.     LDA    CF1TAB,Y ;get letter for status line
  13038.     LDX    #76    ;column to use is 76
  13039. *
  13040. * Now update the status line
  13041. *
  13042. CF1400    PHA        ;save the output letter
  13043.     TXA        ;get column number into A
  13044.     PHA        ;save it
  13045.     JSR    PRTOFF    ;ensure printer is off
  13046.     PLA        ;reload column number
  13047.     LDY    TTYPE    ;are we 80 byte terminal?
  13048.     BNE    CF1420    ;j if we are
  13049. *
  13050. * We're a 40 byte terminal here, so poke character to screen
  13051. *
  13052.     SEC        ;move column back 40 bytes
  13053.     SBC    #40
  13054.     TAX
  13055.     PLA        ;get character back
  13056.     STA    $7C00,X    ;poke to screen
  13057.     BNE    CF1700
  13058. *
  13059. * Here we're 80 bytes wide
  13060. *
  13061. CF1420    PHA        ;save the column
  13062.     JSR    LOCATE    ;find where cursor is
  13063.     LDA    #31
  13064.     JSR    OSWRCH    ;start VDU 31
  13065.     PLA
  13066.     JSR    OSWRCH    ;select column
  13067.     LDA    #0
  13068.     JSR    OSWRCH    ;in BBC line 0
  13069.     LDA    #136
  13070.     JSR    MESS    ;go to inverse video
  13071.     PLA        ;get the letter we use
  13072.     JSR    OSWRCH    ;and write it
  13073.     LDA    #137
  13074.     JSR    MESS    ;and back to normal video    
  13075.     JSR    REPOSN    ;then put cursor back where it was
  13076. CF1700    BIT    PRINTER    ;should printer be on?
  13077.     BPL    CF1800    ;j if not
  13078.     JSR    PRTON    ;else turn it back on
  13079. *
  13080. * Now snapshot the updated status line if needed
  13081. *
  13082. CF1800    EQU    *
  13083.     LDA    TTYPE    ;get terminal type
  13084.     BEQ    CF1900    ;j if 40 byte terminal
  13085.     JSR    SNAPSL    ;else do the snapshot
  13086. NULLCF    EQU    *
  13087. CF1900    RTS
  13088.  
  13089. CF1TAB    ASC    'D '
  13090.  
  13091.  
  13092. ***************************************
  13093. *
  13094. * CF2
  13095. * ===
  13096. *
  13097. * Toggle printer logging
  13098. *
  13099. ***************************************
  13100.  
  13101. CF2    LDA    PRINTER    ;toggle the flag
  13102.     EOR    #$FF
  13103.     STA    PRINTER
  13104.     TAY
  13105.     INY        ;form 0 or 1 from toggle
  13106.     LDA    CF2TAB,Y ;get letter for status line
  13107.     LDX    #77    ;column is 77
  13108.     BNE    CF1400
  13109.  
  13110. CF2TAB    ASC    'P '
  13111.  
  13112.  
  13113. ***************************************
  13114. *
  13115. * CF3
  13116. * ===
  13117. *
  13118. * Scroll/noscroll toggle
  13119. *
  13120. ***************************************
  13121.  
  13122. CF3    LDA    SCROLL    ;toggle the setting
  13123.     EOR    #$FF
  13124.     STA    SCROLL
  13125.     BEQ    CF3300    ;j if now SCROLL
  13126.     JSR    HOSTOFF    ;else we stop host
  13127.     LDA    #'H'    ;letter in status line is "H"
  13128.     BNE    CF3600
  13129. *
  13130. * Here we're now in SCROLL state, so start the host up
  13131. *
  13132. CF3300    JSR    HOSTON
  13133.     LDA    #' '    ;get letter for status line
  13134. *
  13135. * Now do the status line
  13136. *
  13137. CF3600    LDX    #78    ;column is 78
  13138.     BNE    CF1400
  13139.  
  13140.  
  13141. ***************************************
  13142. *
  13143. * CF4
  13144. * ===
  13145. *
  13146. * Toggle cursor keys from VT52 to local
  13147. * edit mode
  13148. *
  13149. ***************************************
  13150.  
  13151. CF4    LDA    TTYPE    ;get terminal type
  13152.     CMP    #2
  13153.     BNE    CF4900    ;j if not VT52 - ignore the key
  13154.     LDA    EDCRSR
  13155.     EOR    #2
  13156.     STA    EDCRSR    ;else toggle mode from 0 to 2
  13157.     TAX
  13158.     LDA    #4
  13159.     JSR    OBX0    ;set up cursor keys
  13160.     LDA    EDCRSR    ;get mode back
  13161.     LSR    A
  13162.     TAY        ;form 0 or 1
  13163.     LDA    CF4TAB,Y ;get letter for status line
  13164.     LDX    #79    ;put it into column 79
  13165.     JMP    CF1400
  13166.  
  13167. CF4900    RTS
  13168.  
  13169. CF4TAB    ASC    'E '
  13170.  
  13171.  
  13172. ***************************************
  13173. *
  13174. * VT52 ESCAPE HANDLERS
  13175. * ====================
  13176. *
  13177. * VT52 mode ESCAPE sequences come to
  13178. * somewhere in here to be handled
  13179. *
  13180. ***************************************
  13181.  
  13182. ESC100    EQU    *
  13183. *
  13184. * Do we support the code just read?
  13185. *
  13186.     LDY    #ESQNUM
  13187. ESC120    CMP    ESCSEQ,Y ;look in the list
  13188.     BEQ    ESC140    ;j if there
  13189.     DEY
  13190.     BPL    ESC120
  13191. *
  13192. * Not supported, or it's done.
  13193. *
  13194. ESC130    JMP    INICDV    ;reset char disposition vector
  13195. *
  13196. * Here we do support the code, so enter its handler
  13197. *
  13198. ESC140    LDA    ESCADL,Y ;set up the address
  13199.     STA    CHARIN
  13200.     LDA    ESCADH,Y
  13201.     STA    CHARIN+1
  13202.     JMP    (CHARIN) ;and do it
  13203.  
  13204. ESCSEQ    ASC    'ABCDFGHIJKYZ=>'
  13205. ESQNUM    EQU    *-ESCSEQ-1
  13206.  
  13207. ESCADL    DFB    >ESCA
  13208.     DFB    >ESCB
  13209.     DFB    >ESCC
  13210.     DFB    >ESCD
  13211.     DFB    >ESCF
  13212.     DFB    >ESCG
  13213.     DFB    >ESCH
  13214.     DFB    >ESCI
  13215.     DFB    >ESCJ
  13216.     DFB    >ESCK
  13217.     DFB    >ESCY
  13218.     DFB    >ESCZ
  13219.     DFB    >ESCEQ
  13220.     DFB    >ESCGT
  13221.  
  13222. ESCADH    DFB    <ESCA
  13223.     DFB    <ESCB
  13224.     DFB    <ESCC
  13225.     DFB    <ESCD
  13226.     DFB    <ESCF
  13227.     DFB    <ESCG
  13228.     DFB    <ESCH
  13229.     DFB    <ESCI
  13230.     DFB    <ESCJ
  13231.     DFB    <ESCK
  13232.     DFB    <ESCY
  13233.     DFB    <ESCZ
  13234.     DFB    <ESCEQ
  13235.     DFB    <ESCGT
  13236.  
  13237.  
  13238. *
  13239. * ESC A : cursor up
  13240. * -----
  13241. *
  13242. ESCA    JSR    LOCATE    ;where are we?
  13243.     CPY    #1
  13244.     BEQ    ESC130    ;no action if on top row
  13245. ESCA20    LDA    #11
  13246. ESCA50    JSR    OSWRCH    ;else cursor up
  13247.     JMP    ESC130
  13248. *
  13249. *
  13250. * ESC B : Cursor down
  13251. * -----
  13252. *
  13253. ESCB    JSR    LOCATE    ;where are we?
  13254.     CPY    #24
  13255.     BEQ    ESC130    ;no action if on bottom line
  13256.     LDA    #10
  13257.     BNE    ESCA50    ;else cursor down
  13258. *
  13259. *
  13260. * ESC C : Cursor right
  13261. * -----
  13262. *
  13263. ESCC    JSR    LOCATE    ;where are we?
  13264.     CPX    #79
  13265.     BEQ    ESC130    ;no action if on far right
  13266.     DEC    VDUCNT    ;else decrease chars left in line
  13267.     JSR    NOLFSP    ;cancel lf suppression
  13268.     LDA    #9
  13269.     BNE    ESCA50    ;and cursor right
  13270. *
  13271. *
  13272. * ESC D : Cursor left
  13273. * -----
  13274. *
  13275. ESCD    JSR    LOCATE    ;where are we?
  13276.     CPX    #0
  13277.     BEQ    ESC130    ;no action if at far left
  13278.     INC    VDUCNT    ;else decrease chars left in line
  13279.     JSR    NOLFSP    ;cancel lf suppression
  13280.     LDA    #8
  13281.     BNE    ESCA50    ;and cursor left
  13282. *
  13283. *
  13284. * ESC F : Enter graphics mode
  13285. * -----
  13286. *
  13287. ESCF    LDA    #$FF
  13288. ESCF10    STA    GRMODE    ;set graphics flag
  13289.     JMP    ESC130
  13290. *
  13291. *
  13292. * ESC G : Exit graphics mode
  13293. * -----
  13294. *
  13295. ESCG    LDA    #0    ;clear the flag
  13296.     BEQ    ESCF10
  13297. *
  13298. *
  13299. * ESC H : Home cursor
  13300. * -----
  13301. *
  13302. ESCH    JSR    HOME
  13303. ESCH10    LDA    #$0A
  13304.     JSR    OSWRCH    ;come down to BBC line 1
  13305. ESCH20    JSR    VDUINI    ;reset VDU controls
  13306.     JMP    ESC130
  13307. *
  13308. *
  13309. * ESC I : Reverse linefeed
  13310. * -----
  13311. *
  13312. ESCI    JSR    LOCATE    ;find where we are now
  13313.     CPY    #1    ;are we on top line?
  13314.     BNE    ESCA20    ;j if not - just move cursor
  13315.     LDA    #206
  13316.     JSR    MESS    ;clear status line and scroll screen
  13317.     JSR    RFSHSL    ;rewrite status line
  13318. ESCI80    JSR    REPOSN    ;restore cursor position
  13319.     JMP    ESC130
  13320. *
  13321. *
  13322. * ESC J : Erase to end of screen
  13323. * -----
  13324. *
  13325. ESCJ    JSR    LOCATE    ;find where we are
  13326.     CPY    #1
  13327.     BNE    ESCJ10    ;j if not top line
  13328.     CPX    #0
  13329.     BNE    ESCJ10    ;j if not at top left
  13330.     LDA    #48
  13331.     JSR    MESS    ;else clear screen below status line
  13332.     JMP    ESCH20
  13333. *
  13334. * Not at top left, so clear to EOLN
  13335. *
  13336. ESCJ10    JSR    SPFILL    ;clear to EOLN
  13337.     LDA    CSRY    ;what row are we on?
  13338.     CMP    #24
  13339.     BNE    ESCJ20    ;j if not on bottom line
  13340.     JMP    ESC130    ;else that's all
  13341. *
  13342. * Then set a window and clear below us
  13343. *
  13344. ESCJ20    LDA    #61
  13345.     JSR    MESS    ;start window sequence
  13346.     LDY    CSRY
  13347.     INY
  13348.     TYA
  13349.     JSR    OSWRCH    ;add no of line below us
  13350.     LDA    #62
  13351.     JSR    MESS    ;clear and reset window
  13352.     JMP    ESCI80
  13353. *
  13354. *
  13355. * ESC K : Erase to EOLN
  13356. * -----
  13357. *
  13358. ESCK    JSR    SPFILL
  13359.     JMP    ESC130
  13360. *
  13361. *
  13362. * ESC Y : Position cursor
  13363. * -----
  13364. *
  13365. ESCY    LDA    #>ESCY10 ; note handler for the next byte
  13366.     STA    CHARIN
  13367.     LDA    #<ESCY10
  13368.     STA    CHARIN+1
  13369.     RTS
  13370. *
  13371. * Here the Y value has come in
  13372. *
  13373. ESCY10    SEC
  13374.     SBC    #31    ;form the row number
  13375.     STA    ESCYR    ;save it
  13376.     LDA    #>ESCY20 ;set address for the next byte
  13377.     STA    CHARIN
  13378.     LDA    #<ESCY20
  13379.     STA    CHARIN+1
  13380.     RTS
  13381. *
  13382. * Here the X value has come in
  13383. *
  13384. ESCY20    PHA        ;save it
  13385.     LDA    #31
  13386.     JSR    OSWRCH    ;start position sequence
  13387.     PLA
  13388.     SEC
  13389.     SBC    #32    ;form column number
  13390.     STA    WORK0    ;save the value
  13391.     JSR    OSWRCH
  13392.     LDA    ESCYR    ;get row number from last time
  13393.     JSR    OSWRCH
  13394. *
  13395. * Now calculate the characters left on this line
  13396. *
  13397.     LDA    #79
  13398.     SEC
  13399.     SBC    WORK0
  13400.     STA    VDUCNT    ;note new value
  13401.     JSR    NOLFSP    ;clear LF suppression
  13402.     JMP    ESC130
  13403. *
  13404. *
  13405. * ESC = and ESC > : Enter/exit keypad application mode
  13406. * ---------------
  13407. *
  13408. ESCEQ    EQU    *
  13409. ESCGT    JMP    ESC130    ;null command
  13410. *
  13411. *
  13412. * ESC Z : Identify terminal
  13413. * -----
  13414. *
  13415. ESCZ    JSR    TXESC    ;send ESCAPE
  13416.     LDA    #'/'
  13417.     JSR    TXECHO    ;then a "/"
  13418.     LDA    #'Z'
  13419.     JSR    TXECHO    ;then a "Z"
  13420.     JMP    ESC130
  13421.  
  13422.  
  13423. ***************************************
  13424. *
  13425. * CURSOR/F/SHIFT-F/KEYPAD HANDLER
  13426. * ===============================
  13427. *
  13428. * Sends the relevant ESCAPE sequence
  13429. * for these keys
  13430. *
  13431. ***************************************
  13432.  
  13433. CFSF    EQU    *
  13434. *
  13435. * Is this a Master keypad key?
  13436. *
  13437.     CMP    #$D2
  13438.     BCC    CFF180    ;j if not
  13439. *
  13440. * It's a keypad key, so translate it into a function key value
  13441. *
  13442.     LDY    #24
  13443. CFF120    CMP    CFFTB2,Y ;check in translate table
  13444.     BEQ    CFF190    ;j if found it
  13445.     DEY
  13446.     BPL    CFF120    ;j if more to check
  13447.     RTS        ;else not there, so ignore the key
  13448. *
  13449. * Scale key and get final byte of sequence we send
  13450. *
  13451. CFF180    SEC
  13452.     SBC    #FKEY
  13453.     TAY
  13454. CFF190    LDA    CFFTAB,Y ;get final byte
  13455.     BEQ    CFF900    ;j if no sequence for this key
  13456.     PHA        ;else save it for a moment
  13457. *
  13458. * First we send ESCAPE
  13459. *
  13460.     JSR    TXESC
  13461. *
  13462. * If final character of sequence is 'l'..'y' or 'M'  preced it with a '?'
  13463. *
  13464.     PLA        ;get final byte
  13465.     CMP    #'M'
  13466.     BEQ    CFF200    ;j if it's 'M'
  13467.     CMP    #'l'
  13468.     BCC    CFF300    ;j if not 'l'..'z'
  13469. CFF200    PHA        ;else resave character
  13470.     LDA    #'?'
  13471.     JSR    TXECHO    ;send the '?'
  13472.     PLA        ;reload character
  13473. *
  13474. * And send final byte of sequence
  13475. *
  13476. CFF300    JSR    TXECHO
  13477. CFF900    RTS
  13478.  
  13479.  
  13480. CFFTAB    DFB    'p'    ;F0  - keypad keys 0..9
  13481.     DFB    'q'    ;F1
  13482.     DFB    'r'    ;F2
  13483.     DFB    's'    ;F3
  13484.     DFB    't'    ;F4
  13485.     DFB    'u'    ;F5
  13486.     DFB    'v'    ;F6
  13487.     DFB    'w'    ;F7
  13488.     DFB    'x'    ;F8
  13489.     DFB    'y'    ;F9
  13490.     DFB    0    ;BREAK - not used
  13491.     DFB    0    ;COPY- not used
  13492.     DFB    'D'    ;LEFT
  13493.     DFB    'C'    ;RIGHT
  13494.     DFB    'B'    ;DOWN
  13495.     DFB    'A'    ;UP
  13496.     DFB    0    ;SF0 - not used
  13497.     DFB    'P'    ;SF1 - PF1
  13498.     DFB    'Q'    ;SF2 - PF2
  13499.     DFB    'R'    ;SF3 - PF3
  13500.     DFB    'S'    ;SF4 - PF4
  13501.     DFB    'm'    ;SF5 - MINUS
  13502.     DFB    'l'    ;SF6 - COMMA
  13503.     DFB    'n'    ;SF7 - PERIOD
  13504.     DFB    'M'    ;SF8 - ENTER
  13505.     DFB    0    ;SF9 - not used
  13506.  
  13507.  
  13508. * This table translates the key codes
  13509. * for master keypad keys to give the number
  13510. * of the matching function key. The table
  13511. * contains the key codes ordered in F-key
  13512. * order
  13513.  
  13514. CFFTB2    DFB    $F5    ;0
  13515.     DFB    $F6    ;1
  13516.     DFB    $F7    ;2
  13517.     DFB    $F8    ;3
  13518.     DFB    $F9    ;4
  13519.     DFB    $FA    ;5
  13520.     DFB    $FB    ;6
  13521.     DFB    $FC    ;7
  13522.     DFB    $FD    ;8
  13523.     DFB    $FE    ;9
  13524.     DFB    0,0,0,0,0,0,0 ;unused keys in the middle
  13525.     DFB    $F0    ;PF1 (key +)
  13526.     DFB    $F2    ;PF2 (key -)
  13527.     DFB    $F4    ;PF3 (key /)
  13528.     DFB    $EF    ;PF4 (key *)
  13529.     DFB    $E8    ;MINUS (key #)
  13530.     DFB    $F1    ;COMMA (key ,)
  13531.     DFB    $F3    ;PERIOD (key .)
  13532.     DFB    $D2    ;ENTER (key RETURN)
  13533.  
  13534.  
  13535. ***************************************
  13536. *
  13537. * TXESC
  13538. * =====
  13539. *
  13540. * Transmits ESCAPE
  13541. *
  13542. ***************************************
  13543.  
  13544. TXESC    LDA    #$1B
  13545.     JMP    TXECHO
  13546.  
  13547.  
  13548. ***************************************
  13549. *
  13550. * VT52 GRAPHICS CHARACTER SET
  13551. * ===========================
  13552. *
  13553. * These are the definitions for the
  13554. * VT52 Graphics Character set
  13555. *
  13556. ***************************************
  13557.  
  13558. GRCHAR    DFB    %00111100    ;graphics character 95
  13559.     DFB    %01000010
  13560.     DFB    %10011001
  13561.     DFB    %10100001
  13562.     DFB    %10100001
  13563.     DFB    %10011001
  13564.     DFB    %01000010
  13565.     DFB    %00111100
  13566.  
  13567.     DFB    %00011000    ;graphics character 96
  13568.     DFB    %00111100
  13569.     DFB    %01111110
  13570.     DFB    %11111111
  13571.     DFB    %01111110
  13572.     DFB    %00111100
  13573.     DFB    %00011000
  13574.     DFB    %00000000
  13575.  
  13576.     DFB    %11001100    ;graphics character 97
  13577.     DFB    %11001100
  13578.     DFB    %00110011
  13579.     DFB    %00110011
  13580.     DFB    %11001100
  13581.     DFB    %11001100
  13582.     DFB    %00110011
  13583.     DFB    %00110011
  13584.  
  13585.     DFB    %10010000    ;graphics character 98
  13586.     DFB    %10010000
  13587.     DFB    %11110000
  13588.     DFB    %10010000
  13589.     DFB    %10011111
  13590.     DFB    %00000100
  13591.     DFB    %00000100
  13592.     DFB    %00000100
  13593.  
  13594.     DFB    %11110000    ;graphics character 99
  13595.     DFB    %10000000
  13596.     DFB    %11110000
  13597.     DFB    %10001111
  13598.     DFB    %10001000
  13599.     DFB    %00001111
  13600.     DFB    %00001000
  13601.     DFB    %00001000
  13602.  
  13603.     DFB    %11110000    ;graphics character 100
  13604.     DFB    %10000000
  13605.     DFB    %10000000
  13606.     DFB    %11111100
  13607.     DFB    %00010010
  13608.     DFB    %00011100
  13609.     DFB    %00010100
  13610.     DFB    %00010010
  13611.  
  13612.     DFB    %10000000    ;graphics character 101
  13613.     DFB    %10000000
  13614.     DFB    %10000000
  13615.     DFB    %10001111
  13616.     DFB    %11111000
  13617.     DFB    %00001110
  13618.     DFB    %00001000
  13619.     DFB    %00001000
  13620.  
  13621.     DFB    %01111000    ;graphics character 102
  13622.     DFB    %11001100
  13623.     DFB    %11001100
  13624.     DFB    %01111000
  13625.     DFB    %00000000
  13626.     DFB    %00000000
  13627.     DFB    %00000000
  13628.     DFB    %00000000
  13629.  
  13630.     DFB    %00011000    ;graphics character 103
  13631.     DFB    %00011000
  13632.     DFB    %01111110
  13633.     DFB    %00011000
  13634.     DFB    %00011000
  13635.     DFB    %00000000
  13636.     DFB    %01111110
  13637.     DFB    %00000000
  13638.  
  13639.     DFB    %10010000    ;graphics character 104
  13640.     DFB    %11010000
  13641.     DFB    %10110000
  13642.     DFB    %10010000
  13643.     DFB    %00001000
  13644.     DFB    %00001000
  13645.     DFB    %00001000
  13646.     DFB    %00001111
  13647.  
  13648.     DFB    %10001000    ;graphics character 105
  13649.     DFB    %10001000
  13650.     DFB    %10001000
  13651.     DFB    %01010000
  13652.     DFB    %00111111
  13653.     DFB    %00000100
  13654.     DFB    %00000100
  13655.     DFB    %00000100
  13656.  
  13657.     DFB    %00011000    ;graphics character 106
  13658.     DFB    %00011000
  13659.     DFB    %00011000
  13660.     DFB    %11111000
  13661.     DFB    %11111000
  13662.     DFB    %00000000
  13663.     DFB    %00000000
  13664.     DFB    %00000000
  13665.  
  13666.     DFB    %00000000    ;graphics character 107
  13667.     DFB    %00000000
  13668.     DFB    %00000000
  13669.     DFB    %11111000
  13670.     DFB    %11111000
  13671.     DFB    %00011000
  13672.     DFB    %00011000
  13673.     DFB    %00011000
  13674.  
  13675.     DFB    %00000000    ;graphics character 108
  13676.     DFB    %00000000
  13677.     DFB    %00000000
  13678.     DFB    %00011111
  13679.     DFB    %00011111
  13680.     DFB    %00011000
  13681.     DFB    %00011000
  13682.     DFB    %00011000
  13683.  
  13684.     DFB    %00011000    ;graphics character 109
  13685.     DFB    %00011000
  13686.     DFB    %00011000
  13687.     DFB    %00011111
  13688.     DFB    %00011111
  13689.     DFB    %00000000
  13690.     DFB    %00000000
  13691.     DFB    %00000000
  13692.  
  13693.     DFB    %00011000    ;graphics character 110
  13694.     DFB    %00011000
  13695.     DFB    %00011000
  13696.     DFB    %11111111
  13697.     DFB    %11111111
  13698.     DFB    %00011000
  13699.     DFB    %00011000
  13700.     DFB    %00011000
  13701.  
  13702.     DFB    %11111111    ;graphics character 111
  13703.     DFB    %11111111
  13704.     DFB    %00000000
  13705.     DFB    %00000000
  13706.     DFB    %00000000
  13707.     DFB    %00000000
  13708.     DFB    %00000000
  13709.     DFB    %00000000
  13710.  
  13711.     DFB    %00000000    ;graphics character 112
  13712.     DFB    %11111111
  13713.     DFB    %11111111
  13714.     DFB    %00000000
  13715.     DFB    %00000000
  13716.     DFB    %00000000
  13717.     DFB    %00000000
  13718.     DFB    %00000000
  13719.  
  13720.     DFB    %00000000    ;graphics character 113
  13721.     DFB    %00000000
  13722.     DFB    %11111111
  13723.     DFB    %11111111
  13724.     DFB    %00000000
  13725.     DFB    %00000000
  13726.     DFB    %00000000
  13727.     DFB    %00000000
  13728.  
  13729.     DFB    %00000000    ;graphics character 114
  13730.     DFB    %00000000
  13731.     DFB    %00000000
  13732.     DFB    %00000000
  13733.     DFB    %11111111
  13734.     DFB    %11111111
  13735.     DFB    %00000000
  13736.     DFB    %00000000
  13737.  
  13738.     DFB    %00000000    ;graphics character 115
  13739.     DFB    %00000000
  13740.     DFB    %00000000
  13741.     DFB    %00000000
  13742.     DFB    %00000000
  13743.     DFB    %00000000
  13744.     DFB    %11111111
  13745.     DFB    %11111111
  13746.  
  13747.     DFB    %00011000    ;graphics character 116
  13748.     DFB    %00011000
  13749.     DFB    %00011000
  13750.     DFB    %00011111
  13751.     DFB    %00011111
  13752.     DFB    %00011000
  13753.     DFB    %00011000
  13754.     DFB    %00011000
  13755.  
  13756.     DFB    %00011000    ;graphics character 117
  13757.     DFB    %00011000
  13758.     DFB    %00011000
  13759.     DFB    %11111000
  13760.     DFB    %11111000
  13761.     DFB    %00011000
  13762.     DFB    %00011000
  13763.     DFB    %00011000
  13764.  
  13765.     DFB    %00011000    ;graphics character 118
  13766.     DFB    %00011000
  13767.     DFB    %00011000
  13768.     DFB    %11111111
  13769.     DFB    %11111111
  13770.     DFB    %00000000
  13771.     DFB    %00000000
  13772.     DFB    %00000000
  13773.  
  13774.     DFB    %00000000    ;graphics character 119
  13775.     DFB    %00000000
  13776.     DFB    %00000000
  13777.     DFB    %11111111
  13778.     DFB    %11111111
  13779.     DFB    %00011000
  13780.     DFB    %00011000
  13781.     DFB    %00011000
  13782.  
  13783.     DFB    %00011000    ;graphics character 120
  13784.     DFB    %00011000
  13785.     DFB    %00011000
  13786.     DFB    %00011000
  13787.     DFB    %00011000
  13788.     DFB    %00011000
  13789.     DFB    %00011000
  13790.     DFB    %00011000
  13791.  
  13792.     DFB    %00000110    ;graphics character 121
  13793.     DFB    %00011000
  13794.     DFB    %01100000
  13795.     DFB    %00011000
  13796.     DFB    %00000110
  13797.     DFB    %00000000
  13798.     DFB    %01111110
  13799.     DFB    %00000000
  13800.  
  13801.     DFB    %01100000    ;graphics character 122
  13802.     DFB    %00011000
  13803.     DFB    %00000110
  13804.     DFB    %00011000
  13805.     DFB    %01100000
  13806.     DFB    %00000000
  13807.     DFB    %01111110
  13808.     DFB    %00000000
  13809.  
  13810.     DFB    %00000000    ;graphics character 123
  13811.     DFB    %00000011
  13812.     DFB    %11111111
  13813.     DFB    %01100110
  13814.     DFB    %01100110
  13815.     DFB    %01100110
  13816.     DFB    %01100110
  13817.     DFB    %00000000
  13818.  
  13819.     DFB    %00000011    ;graphics character 124
  13820.     DFB    %00000110
  13821.     DFB    %11111111
  13822.     DFB    %00001100
  13823.     DFB    %00011000
  13824.     DFB    %11111111
  13825.     DFB    %01100000
  13826.     DFB    %11000000
  13827.  
  13828.     DFB    %00011100    ;graphics character 125
  13829.     DFB    %00110110
  13830.     DFB    %00110000
  13831.     DFB    %01111100
  13832.     DFB    %00110000
  13833.     DFB    %00110000
  13834.     DFB    %01111110
  13835.     DFB    %00000000
  13836.  
  13837.     DFB    %00000000    ;graphics character 126
  13838.     DFB    %00000000
  13839.     DFB    %00000000
  13840.     DFB    %00011000
  13841.     DFB    %00011000
  13842.     DFB    %00000000
  13843.     DFB    %00000000
  13844.     DFB    %00000000
  13845.  
  13846.  
  13847.     NEXT    BBCPM1
  13848. ****** File BBCTX1 *************************************************************
  13849.     START    TX1
  13850. * BBCTX1: Updated 10/01/87 @ 1730
  13851.  
  13852. ***************************************
  13853. *
  13854. * TEXTS
  13855. * -----
  13856. *
  13857. * These texts are output by the message
  13858. * system.
  13859. *
  13860. * Control bytes used are:
  13861. *
  13862. * TXT <n>    recurse to output text n
  13863. * MSP <n>    output n spaces
  13864. * RPT <n> <m>    output n copies of character m
  13865. * LIT <n>    output character n as is
  13866. * XCR        output byte value 13 without change to CR-LF
  13867. * MTXT <n> <m> recurse to output text m, n times
  13868. *
  13869. ***************************************
  13870.  
  13871. M0    DFB    3,22,7,TXT,151
  13872.     DFB    NORMHT,TXT,120 ;version string
  13873.     DFB    $0D,TXT,151,$0D
  13874.     DFB    GREEN
  13875.     DFB    TXT,119    ;'By Lancaster ....'
  13876.     DFB    EOT
  13877.  
  13878. M1    ASC    'RX:'
  13879.     DFB    EOT
  13880.  
  13881. M2    DFB    $0D
  13882.     ASC    'SOH!'
  13883.     DFB    $0D
  13884.     DFB    EOT
  13885.  
  13886. M3    DFB    $0D
  13887.     ASC    'Early EOLN'
  13888.     DFB    $0D
  13889.     DFB    EOT
  13890.  
  13891. M4    DFB    $0D
  13892.     ASC    'Short pkt'
  13893.     DFB    EOT
  13894.  
  13895. M5    DFB    $0D
  13896.     ASC    'Bad len'
  13897.     DFB    $0D
  13898.     DFB    EOT
  13899.  
  13900. M6    DFB    $0D
  13901.     ASC    'Bad c/s'
  13902.     DFB    $0D
  13903.     DFB    EOT
  13904.  
  13905. M7    DFB    $0D
  13906.     ASC    'BUF oflw'
  13907.     DFB    $0D
  13908.     DFB    EOT
  13909.  
  13910. M8    DFB    $0D
  13911.     ASC    'SENDSW'
  13912.     DFB    TXT,153    ;' : State '
  13913.     DFB    EOT
  13914.  
  13915. M9    DFB    YELLOW,TXT,158,WHITE ;'BBC>'
  13916.     DFB    EOT
  13917.  
  13918. M10    DFB    TXT,0    ;main header
  13919.     DFB    31,0,4,YELLOW
  13920.     ASC    'ACTION:'
  13921.     DFB    CYAN,31,21,4,YELLOW
  13922.     ASC    'STATUS  :'
  13923.     DFB    CYAN,$0D,YELLOW
  13924.     ASC    'F.TYPE:'
  13925.     DFB    CYAN,31,21,5,YELLOW
  13926.     ASC    '8BIT PFX:'
  13927.     DFB    CYAN,31,21,6,YELLOW
  13928.     ASC    'INTRPT  :'
  13929.     DFB    CYAN,31,0,10,YELLOW
  13930.     ASC    'FILENAMES'
  13931.     DFB    $0D,CYAN
  13932.     ASC    ' Remote:'
  13933.     DFB    GREEN,$0D,CYAN
  13934.     ASC    ' Local :'
  13935.     DFB    GREEN,31,0,15,YELLOW
  13936.     ASC    'COUNTERS'
  13937.     DFB    $0D,CYAN
  13938.     ASC    ' Packets'
  13939.     DFB    GREEN,31,14,16,'0',CYAN
  13940.     ASC    ' Files'
  13941.     DFB    GREEN
  13942.     ASC    '  0'
  13943.     DFB    CYAN
  13944.     ASC    ' Kbytes:'
  13945.     DFB    $0D
  13946.     DFB    CYAN
  13947.     ASC    ' Retries'
  13948.     DFB    GREEN,31,14,17,'0',CYAN
  13949.     DFB    31,29,17
  13950.     ASC    'Current'
  13951.     DFB    GREEN
  13952.     ASC    '  0'
  13953.     DFB    CYAN
  13954.     ASC    ' T/outs'
  13955.     DFB    GREEN,31,14,18,'0',CYAN
  13956.     DFB    31,29,18
  13957.     ASC    'Total  '
  13958.     DFB    GREEN
  13959.     ASC    '  0'
  13960.     DFB    EOT
  13961.  
  13962. M11    DFB    31,0,8,YELLOW,7,NEWBG,RED
  13963.     ASC    'WARNING : Non-ASCII data  '
  13964.     DFB    BLKBG
  13965.     DFB    EOT
  13966.  
  13967. M12    DFB    31,0,22
  13968.     DFB    TXT,138    ;'ERROR : '
  13969.     DFB    EOT
  13970.  
  13971. M13    DFB    $0D,$0D,YELLOW
  13972.     DFB    TXT,216    ;'TRANSFER'
  13973.     DFB    TXT,65    ;' PARAMETERS'
  13974.     DFB    EOT
  13975.  
  13976. M14    DFB    31,2,20,YELLOW,NEWBG,RED
  13977.     ASC    'RETURN for more; ESCAPE to quit  '
  13978.     DFB    BLKBG
  13979.     DFB    EOT
  13980.  
  13981. M15    DFB    $0D
  13982.     ASC    'RECSW'
  13983.     DFB    TXT,153    ;' : State '
  13984.     DFB    EOT
  13985.  
  13986. M16    DFB    31,0,24
  13987.     DFB    TXT,148    ;'Press any key to '
  13988.     ASC    'return'
  13989.     DFB    TXT,157    ;' to command mode'
  13990.     DFB    EOT
  13991.  
  13992. M17    DFB    31,0,20,FLASH,YELLOW
  13993.     ASC    '  *** '
  13994.     DFB    TXT,216    ;'TRANSFER'
  13995.     ASC    ' COMPLETED OK ***'
  13996.     DFB    EOT
  13997.  
  13998. M18    DFB    ' ',CYAN
  13999.     DFB    'P',TXT,217 ;'Packet size'
  14000.     DFB    MSP,3,GREEN
  14001.     DFB    EOT
  14002.  
  14003. M19    DFB    31,10,18
  14004.     DFB    EOT
  14005.  
  14006. M20    DFB    31,9,XCR
  14007.     DFB    EOT
  14008.  
  14009. M21    ASC    'Byte'
  14010.     DFB    TXT,221    ;' period'
  14011.     ASC    ' delay (0-255)'
  14012.     DFB    EOT
  14013.  
  14014. M22    DFB    31,32,5
  14015.     ASC    'Not used'
  14016.     DFB    EOT
  14017.  
  14018. M23    ASC    'Waiting '
  14019.     DFB    EOT
  14020.  
  14021. M24    ASC    'Transmit'
  14022.     DFB    EOT
  14023.  
  14024. M25    ASC    'Receive '
  14025.     DFB    EOT
  14026.  
  14027. M26    DFB    31,32,5
  14028.     ASC    'In use  '
  14029.     DFB    EOT
  14030.  
  14031. M27    DFB    $0D
  14032.     STR    'Options are :'
  14033.     DFB    EOT
  14034.  
  14035. M28    DFB    31,10,11
  14036.     DFB    EOT
  14037.  
  14038. M29    DFB    31,10,12
  14039.     DFB    EOT
  14040.  
  14041. M30    DFB    CYAN
  14042.     ASC    'TX baud'
  14043.     DFB    MSP,6,GREEN
  14044.     DFB    EOT
  14045.  
  14046. M31    DFB    31,23,16
  14047.     DFB    EOT
  14048.  
  14049. M32    DFB    TXT,154    ;'A filename on '
  14050.     DFB    TXT,163    ;' remote system'
  14051.     DFB    EOT
  14052.  
  14053. M33    DFB    TXT,154    ;'A filename on '
  14054.     ASC    ' the BBC'
  14055.     DFB    EOT
  14056.  
  14057. M34    DFB    0,0,0
  14058.     DFB    EOT
  14059.  
  14060. M35    ASC    'TX:'
  14061.     DFB    EOT
  14062.  
  14063. M36    DFB    31,10,16
  14064.     DFB    EOT
  14065.  
  14066. M37    DFB    31,10,17
  14067.     DFB    EOT
  14068.  
  14069. M38    ASC    'No more '
  14070.     DFB    TXT,180,'s'    ;' parameters'
  14071.     ASC    ' for this '
  14072.     DFB    TXT,169    ;'command'
  14073.     DFB    EOT
  14074.  
  14075. M39    DFB    $0D
  14076.     ASC    'FB full'
  14077.     DFB    $0D
  14078.     DFB    EOT
  14079.  
  14080. M40    DFB    $0D
  14081.     ASC    'FB out'
  14082.     DFB    $0D
  14083.     DFB    EOT
  14084.  
  14085. M41    DFB    ' ',CYAN
  14086.     ASC    '8bit '
  14087.     DFB    TXT,220    ;'prefix'
  14088.     DFB    MSP,5,GREEN
  14089.     DFB    EOT
  14090.  
  14091. M42    DFB    31,32,6
  14092.     DFB    EOT
  14093.  
  14094. M43    DFB    23,1,1,RPT,7,0
  14095.     DFB    EOT
  14096.  
  14097. M44    DFB    23,1,RPT,8,0
  14098.     DFB    EOT
  14099.  
  14100. M45    ASC    'Writing'
  14101.     DFB    EOT
  14102.  
  14103. M46    ASC    'Reading'
  14104.     DFB    EOT
  14105.  
  14106. M47    DFB    22,7
  14107.     DFB    EOT
  14108.  
  14109. M48    DFB    28,0,24,79,1,12,26,$0A
  14110.     DFB    EOT
  14111.  
  14112. M49    DFB    31,9,4
  14113.     ASC    'Receive'
  14114.     DFB    TXT,56    ;' file'
  14115.     DFB    EOT
  14116.  
  14117. M50    DFB    31,9,4
  14118.     ASC    'Send'
  14119.     DFB    TXT,56    ;' file'
  14120.     DFB    EOT
  14121.  
  14122. M51    ASC    'Idle'
  14123.     DFB    MSP,4
  14124.     DFB    EOT
  14125.  
  14126. M52    ASC    'Opening '
  14127.     DFB    EOT
  14128.  
  14129. M53    ASC    'Closing '
  14130.     DFB    EOT
  14131.  
  14132. M54    DFB    31,32,4
  14133.     DFB    EOT
  14134.  
  14135. M55    DFB    CYAN
  14136.     ASC    'Handshake'
  14137.     DFB    MSP,5,GREEN
  14138.     DFB    EOT
  14139.  
  14140. M56    ASC    ' file'
  14141.     DFB    EOT
  14142.  
  14143. M57    DFB    ' ',CYAN
  14144.     ASC    'MUX wait'
  14145.     DFB    MSP,6,GREEN
  14146.     DFB    EOT
  14147.  
  14148. M58    ASC    'Delay after SEND '
  14149.     DFB    TXT,169    ;'command'
  14150.     DFB    TXT,159    ;', in seconds'
  14151.     DFB    EOT
  14152.  
  14153. M59    ASC    'Pausing '
  14154.     DFB    EOT
  14155.  
  14156. M60    ASC    'Delay before '
  14157.     DFB    'p',TXT,218    ;'packet'    
  14158.     ASC    ' send'
  14159.     DFB    TXT,159    ;', in seconds'
  14160.     DFB    EOT
  14161.  
  14162. M61    DFB    28,0,24,79
  14163.     DFB    EOT
  14164.  
  14165. M62    DFB    12,26
  14166.     DFB    EOT
  14167.  
  14168. M63    DFB    ' ',CYAN
  14169.     ASC    'RX baud'
  14170.     DFB    MSP,5,GREEN
  14171.     DFB    EOT
  14172.  
  14173. M64    DFB    CYAN
  14174.     ASC    'Debugging'
  14175.     DFB    MSP,6,GREEN
  14176.     DFB    EOT
  14177.  
  14178. M65    STR    ' PARAMETERS'
  14179.     DFB    EOT
  14180.  
  14181. M66    DFB    ' ',CYAN
  14182.     ASC    'Parity'
  14183.     DFB    MSP,6,GREEN
  14184.     DFB    EOT
  14185.  
  14186. M67    DFB    ' ',CYAN
  14187.     ASC    'Retries'
  14188.     DFB    MSP,7,GREEN
  14189.     DFB    EOT
  14190.  
  14191. M68    DFB    ' ',CYAN
  14192.     ASC    'TX pause(s)'
  14193.     DFB    MSP,3,GREEN
  14194.     DFB    EOT
  14195.  
  14196. M69    DFB    CYAN
  14197.     ASC    'SEND delay(s)  '
  14198.     DFB    GREEN
  14199.     DFB    EOT
  14200.  
  14201. M70    DFB    ' ',CYAN
  14202.     DFB    'T',TXT,91,' ',' ' ;'Terminal   '
  14203.     DFB    GREEN
  14204.     DFB    EOT
  14205.  
  14206. M71    DFB    ' ',CYAN
  14207.     DFB    TXT,191,' '    ;'Quote character'
  14208.     DFB    GREEN
  14209.     DFB    EOT
  14210.  
  14211. M72    DFB    31,9,5
  14212.     DFB    EOT
  14213.  
  14214. M73    DFB    TXT,172    ;'Character'
  14215.     ASC    ' we use for control quoting'
  14216.     DFB    EOT
  14217.  
  14218. M74    DFB    ' ',CYAN
  14219.     ASC    'Local '
  14220.     DFB    TXT,219    ;'echo'
  14221.     DFB    MSP,4,GREEN
  14222.     DFB    EOT
  14223.  
  14224. M75    ASC    'CTRL-'
  14225.     DFB    EOT
  14226.  
  14227. M76    DFB    $0C,YELLOW
  14228.     ASC    'GENERAL'
  14229.     DFB    TXT,65    ;' PARAMETERS'
  14230.     DFB    EOT
  14231.  
  14232. M77    DFB    $0D,YELLOW
  14233.     ASC    'RECEIVE'
  14234.     DFB    TXT,65    ;' PARAMETERS'
  14235.     DFB    EOT
  14236.  
  14237. M78    DFB    $0D,$0D,YELLOW
  14238.     ASC    'SEND'
  14239.     DFB    TXT,65    ;' PARAMETERS'
  14240.     DFB    EOT
  14241.  
  14242. M79    DFB    YELLOW
  14243.     ASC    'TERMINAL'
  14244.     DFB    TXT,65    ;' PARAMETERS'
  14245.     DFB    EOT
  14246.  
  14247. M80    DFB    CYAN
  14248.     ASC    'Timer'
  14249.     DFB    MSP,10,GREEN
  14250.     DFB    EOT
  14251.  
  14252. M81    DFB    CYAN
  14253.     ASC    'End-of-line'
  14254.     DFB    MSP,4,GREEN,'X'
  14255.     DFB    EOT
  14256.  
  14257. M82    DFB    CYAN
  14258.     DFB    'P',TXT,174    ;'Pad character'
  14259.     DFB    MSP,2,GREEN,'&'
  14260.     DFB    EOT
  14261.  
  14262. M83    DFB    ' ',CYAN
  14263.     DFB    'P',TXT,218 ;'Packet'
  14264.     ASC    'start'
  14265.     DFB    MSP,2,GREEN,'&'
  14266.     DFB    EOT
  14267.  
  14268. M84    DFB    $0D,$0D,YELLOW
  14269.     ASC    'FILE'
  14270.     DFB    TXT,65    ;' PARAMETERS'
  14271.     DFB    EOT
  14272.  
  14273. M85    DFB    ' ',CYAN
  14274.     DFB    TXT,170    ;'File '
  14275.     ASC    'type'
  14276.     DFB    MSP,2,GREEN
  14277.     DFB    EOT
  14278.  
  14279. M86    DFB    ' ',CYAN
  14280.     ASC    'Data source'
  14281.     DFB    MSP,6,GREEN
  14282.     DFB    EOT
  14283.  
  14284. M87    EQU    *
  14285.     IF    ROM
  14286.     DFB    $0D
  14287.     FI
  14288.     DFB    ' ',CYAN
  14289.     ASC    'Data destination '
  14290.     DFB    GREEN
  14291.     DFB    EOT
  14292.  
  14293. M88    DFB    CYAN
  14294.     ASC    'Pad count'
  14295.     DFB    MSP,6,GREEN
  14296.     DFB    EOT
  14297.  
  14298. M89    DFB    ' ',CYAN
  14299.     DFB    TXT,205    ;'Timeout'
  14300.     ASC    '(s)'
  14301.     DFB    MSP,4,GREEN
  14302.     DFB    EOT
  14303.  
  14304. M90    DFB    TXT,205    ;'Timeout'
  14305.     DFB    $0D
  14306.     DFB    EOT
  14307.  
  14308. M91    ASC    'erminal '
  14309.     DFB    EOT            
  14310.  
  14311. M92    DFB    TXT,205    ;'Timeout'
  14312.     ASC    ' we use'
  14313.     DFB    TXT,159    ;', in seconds'
  14314.     DFB    EOT
  14315.  
  14316. M93    DFB    TXT,200    ;'Start-of-packet character'
  14317.     DFB    TXT,201    ;' we send to remote'
  14318.     DFB    TXT,202    ;' (0-31)'
  14319.     DFB    EOT
  14320.  
  14321. M94    DFB    'P',TXT,174    ;'Pad character'
  14322.     DFB    TXT,224    ;' we send'
  14323.     DFB    TXT,202    ;' (0-31)'
  14324.     DFB    EOT
  14325.  
  14326. M95    DFB    TXT,213    ;'Number of '
  14327.     DFB    'p',TXT,174,'s'    ;'pad characters'
  14328.     DFB    TXT,224    ;' we send'
  14329.     DFB    EOT
  14330.  
  14331. M96    DFB    TXT,203    ;'End-of-line character'
  14332.     DFB    TXT,201    ;' we send to remote'
  14333.     DFB    TXT,202    ;' (0-31)'
  14334.     DFB    EOT
  14335.  
  14336. M97    DFB    31,0,8
  14337.     DFB    EOT
  14338.  
  14339. M98    DFB    TXT,200    ;'Start-of-packet character'
  14340.     DFB    TXT,199    ;' we wish to receive'
  14341.     DFB    TXT,202    ;' (0-31)'
  14342.     DFB    EOT
  14343.  
  14344. M99    DFB    'P',TXT,174    ;'Pad character'
  14345.     DFB    TXT,160    ;' remote is to use'
  14346.     DFB    TXT,202    ;' (0-31)'
  14347.     DFB    EOT
  14348.  
  14349. M100    DFB    TXT,213    ;'Number of '
  14350.     DFB    'p',TXT,174,'s'    ;'pad characters'
  14351.     DFB    TXT,160    ;' remote is to use'
  14352.     ASC    ' (0-94)'
  14353.     DFB    EOT
  14354.  
  14355. M101    DFB    TXT,205    ;'Timeout'
  14356.     DFB    TXT,160    ;' remote is to use'
  14357.     DFB    TXT,159    ;', in seconds'
  14358.     DFB    EOT
  14359.  
  14360. M102    ASC    'Hex a'
  14361.     DFB    TXT,226    ;'ddress'
  14362.     DFB    EOT
  14363.  
  14364. M103    DFB    TXT,170    ;'File '
  14365.     DFB    'b',TXT,214    ;'buffer size'
  14366.     ASC    ' (pages)'
  14367.     DFB    EOT
  14368.  
  14369. M104    DFB    YELLOW,NEWBG,RED
  14370.     ASC    '(Renamed by BBC '
  14371.     DFB    TXT,156    ;'KERMIT'
  14372.     ASC    ')  '
  14373.     DFB    BLKBG
  14374.     DFB    EOT
  14375.  
  14376. M105    DFB    ' ',CYAN
  14377.     ASC    'Incomplete '
  14378.     DFB    GREEN
  14379.     DFB    EOT
  14380.  
  14381. M106    DFB    CYAN
  14382.     DFB    TXT,170    ;'File '
  14383.     ASC    'warning'
  14384.     DFB    MSP,3,GREEN
  14385.     DFB    EOT
  14386.  
  14387. M107    DFB    TXT,170    ;'File '
  14388.     ASC    'for t'
  14389.     DFB    TXT,212    ;'erminal log'
  14390.     DFB    $0D
  14391.     DFB    EOT
  14392.  
  14393. M108    DFB    CYAN
  14394.     ASC    'End of record '
  14395.     DFB    GREEN
  14396.     DFB    EOT
  14397.  
  14398. M109    DFB    ' ',CYAN
  14399.     DFB    'B',TXT,214    ;'Buffer size'
  14400.     ASC    '(p)'
  14401.     DFB    GREEN
  14402.     DFB    EOT
  14403.  
  14404. M110    DFB    TXT,0    ;main header
  14405.     DFB    28,0,24,39,4
  14406.     DFB    EOT
  14407.  
  14408. M111    DFB    31,36,0
  14409.     DFB    EOT
  14410.  
  14411. M112    DFB    CYAN
  14412.     DFB    'T',TXT,212    ;'Terminal log'
  14413.     DFB    MSP,3,GREEN
  14414.     DFB    EOT
  14415.  
  14416. M113    DFB    TXT,170    ;'File '
  14417.     ASC    'for '
  14418.     DFB    TXT,156    ;'KERMIT'
  14419.     DFB    ' ',TXT,180,'s' ;' parameters'
  14420.     DFB    EOT
  14421.  
  14422. M114    DFB    TXT,175    ;'Suffix '
  14423.     ASC    'added to remote filenames'
  14424.     DFB    EOT
  14425.  
  14426. M115    DFB    CYAN
  14427.     DFB    TXT,175    ;'Suffix '
  14428.     DFB    MSP,3,GREEN
  14429.     DFB    EOT
  14430.  
  14431. M116    DFB    TXT,219,$0D ;'echo'
  14432.     DFB    EOT
  14433.  
  14434. M117    DFB    TXT,170    ;'File '
  14435.     ASC    'of '
  14436.     DFB    TXT,156    ;'KERMIT'
  14437.     DFB    ' ',TXT,169,'s'    ;'commands'
  14438.     DFB    EOT
  14439.  
  14440. M118    DFB    CYAN
  14441.     ASC    'TAKE-'
  14442.     DFB    TXT,170    ;'File '
  14443.     DFB    TXT,219,' ' ;'echo '
  14444.     DFB    GREEN
  14445.     DFB    EOT
  14446.  
  14447. M119    ASC    'By Lancaster University Computing Dept'
  14448.     DFB    EOT
  14449.  
  14450. M120    EQU    *
  14451.     IF    ROM
  14452.     ASC    'ROM'
  14453.     ELSE
  14454.     ASC    'RAM'
  14455.     FI
  14456.     DFB    TXT,222    ;' Vm.vv'
  14457.     DFB    EOT        
  14458.  
  14459. M121    DFB    ' ',CYAN
  14460.     ASC    'Key clicks'
  14461.     DFB    MSP,4,GREEN
  14462.     DFB    EOT
  14463.  
  14464. M122    ASC    'Maximum '
  14465.     DFB    'p',TXT,217    ;'packet size'
  14466.     DFB    TXT,199    ;' we wish to receive'
  14467.     ASC    ' (35-94)'
  14468.     DFB    EOT
  14469.  
  14470. M123    DFB    TXT,203    ;'End-of-line character'
  14471.     DFB    TXT,201    ;' we send to remote'
  14472.     DFB    TXT,202    ;' (0-31)'
  14473.     DFB    EOT
  14474.  
  14475. M124    DFB    TXT,203    ;'End-of-line character'
  14476.     DFB    TXT,199    ;' we wish to receive'
  14477.     DFB    TXT,202    ;' (0-31)'
  14478.     DFB    EOT
  14479.  
  14480. M125    ASC    'Eight-bit-'
  14481.     DFB    TXT,220    ;'prefix'
  14482.     DFB    TXT,152    ;' character'
  14483.     DFB    EOT
  14484.  
  14485. M126    ASC    'ON'
  14486.     DFB    EOT
  14487.  
  14488. M127    ASC    'OFF'
  14489.     DFB    EOT
  14490.  
  14491. M128    DFB    TXT,207    ;'BBC Kermit'
  14492.     ASC    ': '
  14493.     DFB    TXT,119    ;'By Lancaster ... '
  14494.     DFB    MSP,9,TXT,120,$0D ;version string
  14495.     DFB    EOT    
  14496.     
  14497. M129    DFB    CYAN
  14498.     ASC    'Flow ctrl '
  14499.     DFB    GREEN
  14500.     DFB    EOT
  14501.  
  14502.  
  14503.     NEXT    BBCTX2
  14504. ****** File BBCTX2 *************************************************************
  14505.     START    TX2
  14506. * BBCTX2 : Updated 10/07/86 @ 1800
  14507.  
  14508. M130    ASC    'Wait'
  14509.     DFB    TXT,221    ;' period'
  14510.     DFB    TXT,159    ;', in seconds'
  14511.     DFB    EOT
  14512.  
  14513. M131    DFB    TXT,23,$0D ;'Waiting'
  14514.     DFB    EOT
  14515.  
  14516. M132    ASC    'Text to display'
  14517.     DFB    EOT
  14518.  
  14519. M133    DFB    CYAN
  14520.     ASC    'VDU colour '
  14521.     DFB    GREEN
  14522.     DFB    EOT
  14523.  
  14524. M134    DFB    19,1
  14525.     DFB    EOT
  14526.  
  14527. M135    DFB    TXT,136    ;inverse video
  14528.     ASC    'C-F||0=Exit||1=Disc||2=Prnt||3=Hold||4=Crsr||5='
  14529.     DFB    MSP,4
  14530.     ASC    '||6='
  14531.     DFB    MSP,4
  14532.     ASC    '||7='
  14533.     DFB    MSP,4
  14534.     ASC    '||8=Lbrk||9=Brk ||'
  14535.     DFB    MSP,6
  14536.     DFB    TXT,137    ;normal video
  14537.     DFB    EOT
  14538.  
  14539. M136    DFB    17,129,17,0
  14540.     DFB    EOT
  14541.  
  14542. M137    DFB    17,128,17,1
  14543.     DFB    EOT
  14544.  
  14545. M138    ASC    'ERROR : '
  14546.     DFB    EOT
  14547.  
  14548. M139    DFB    ' ',CYAN
  14549.     ASC    'Ignore char'
  14550.     DFB    MSP,3,GREEN
  14551.     DFB    EOT
  14552.  
  14553. M140    DFB    CYAN
  14554.     ASC    '*TV pars'
  14555.     DFB    MSP,3,GREEN
  14556.     DFB    EOT
  14557.  
  14558. M141    DFB    TXT,172    ;'Character'
  14559.     ASC    ' to ignore'
  14560.     DFB    EOT
  14561.  
  14562. M142    DFB    3,28,0,24,79,24,12,26,31,0,24,$0A
  14563.     DFB    EOT
  14564.  
  14565. M143    ASC    '*TV '
  14566.     DFB    TXT,180    ;'parameter'
  14567.     DFB    EOT
  14568.  
  14569. M144    ASC    'Address'
  14570.     DFB    EOT
  14571.  
  14572. M145    DFB    31,37,17
  14573.     DFB    EOT
  14574.  
  14575. M146    DFB    ' ',CYAN
  14576.     ASC    'Help trigger'
  14577.     DFB    MSP,4,GREEN
  14578.     DFB    EOT
  14579.  
  14580. M147    ASC    'Sure (Y/N)? '
  14581.     DFB    EOT
  14582.  
  14583. M148    ASC    'Press any key to '
  14584.     DFB    EOT
  14585.  
  14586. M149    DFB    31,37,18
  14587.     DFB    EOT
  14588.  
  14589. M150    ASC    'Retries allowed (1..255)'
  14590.     DFB    EOT
  14591.  
  14592. M151    DFB    YELLOW,NEWBG,DOUBLE,BLUE
  14593.     DFB    TXT,207    ;'CUCCA KERMIT (RxM) '
  14594.     DFB    EOT
  14595.  
  14596. M152    ASC    ' c'
  14597.     DFB    TXT,173    ;'haracter'
  14598.     DFB    EOT
  14599.  
  14600. M153    ASC    ' : State '
  14601.     DFB    EOT
  14602.  
  14603. M154    ASC    'A'
  14604.     DFB    TXT,171    ;' filename on'
  14605.     DFB    EOT
  14606.  
  14607. M155    DFB    MSP,4,TXT,75,'F' ;'CTRL-F'
  14608.     DFB    EOT
  14609.  
  14610. M156    ASC    'KERMIT'
  14611.     DFB    EOT
  14612.  
  14613. M157    ASC    ' to '
  14614.     DFB    TXT,169    ;'command'    
  14615.     ASC    ' mode'
  14616.     DFB    EOT
  14617.  
  14618. M158    ASC    'BBC>'
  14619.     DFB    EOT
  14620.  
  14621. M159    ASC    ', in seconds'
  14622.     DFB    EOT
  14623.  
  14624. M160    DFB    TXT,163 ;' remote system'
  14625.     ASC    ' is to use'
  14626.     DFB    EOT
  14627.  
  14628. M161    ASC    'Filespec for'
  14629.     DFB    TXT,163    ;' remote system'
  14630.     ASC    ' directory list'
  14631.     DFB    EOT
  14632.  
  14633. M162    ASC    'Old'
  14634.     DFB    TXT,171    ;' filename on'
  14635.     DFB    TXT,163    ;' remote system'
  14636.     DFB    EOT
  14637.  
  14638. M163    ASC    ' remote system'
  14639.     DFB    EOT
  14640.  
  14641. M164    ASC    'New'
  14642.     DFB    TXT,171    ;' filename on'
  14643.     DFB    TXT,163    ;' remote system'
  14644.     DFB    EOT
  14645.  
  14646. M165    ASC    'Topic on'
  14647.     DFB    TXT,163    ;' remote system'
  14648.     DFB    EOT
  14649.  
  14650. M166    ASC    'System '
  14651.     DFB    TXT,169    ;'command'
  14652.     ASC    ' on'
  14653.     DFB    TXT,163    ;' remote system'
  14654.     DFB    EOT
  14655.  
  14656. M167    ASC    'Not a '
  14657.     DFB    EOT
  14658.  
  14659. M168    ASC    'Disc area on'
  14660.     DFB    TXT,163    ;' remote system'
  14661.     DFB    EOT
  14662.  
  14663. M169    ASC    'command'
  14664.     DFB    EOT
  14665.  
  14666. M170    ASC    'File '
  14667.     DFB    EOT
  14668.  
  14669. M171    ASC    ' filename on'
  14670.     DFB    EOT
  14671.  
  14672. M172    ASC    'C'
  14673.     DFB    TXT,173    ;'haracter'
  14674.     DFB    EOT
  14675.  
  14676. M173    ASC    'haracter'
  14677.     DFB    EOT
  14678.  
  14679. M174    ASC    'ad'
  14680.     DFB    TXT,152    ;' character'
  14681.     DFB    EOT
  14682.  
  14683. M175    ASC    'Suffix '
  14684.     DFB    EOT
  14685.  
  14686. M176    ASC    ' logging  '
  14687.     DFB    EOT
  14688.  
  14689. M177    DFB    TXT,158,' ' ;'BBC> '
  14690.     DFB    EOT
  14691.  
  14692. M178    DFB    31,2,20,YELLOW,NEWBG,RED,' ',' '
  14693.     DFB    TXT,148    ;'Press any key to '
  14694.     ASC    'continue'
  14695.     DFB    MSP,6,BLKBG
  14696.     DFB    EOT
  14697.  
  14698. M179    DFB    $0D
  14699.     DFB    TXT,138    ;'ERROR : '
  14700.     DFB    EOT
  14701.  
  14702. M180    ASC    'parameter'
  14703.     DFB    EOT
  14704.  
  14705. M181    ASC    'Mandatory '
  14706.     DFB    TXT,180,'s' ;'parameters'
  14707.     ASC    ' missing'
  14708.     DFB    EOT
  14709.  
  14710. M182    ASC    'Too many '
  14711.     DFB    TXT,180,'s'    ;'paramaters'
  14712.     ASC    ' supplied'
  14713.     DFB    EOT
  14714.  
  14715. M183    ASC    'Ambiguous'
  14716.     DFB    TXT,185    ;' command or parameter'
  14717.     DFB    EOT
  14718.  
  14719. M184    ASC    'Unknown'
  14720.     DFB    TXT,185    ;' command or parameter'
  14721.     DFB    EOT
  14722.  
  14723. M185    DFB    ' ',TXT,169 ;' command'
  14724.     ASC    ' or '
  14725.     DFB    TXT,180    ;'parametr'
  14726.     DFB    EOT
  14727.  
  14728. M186    DFB    TXT,187    ;'Not a valid '
  14729.     DFB    TXT,125    ;'Eight-bit-prefix character'
  14730.     DFB    EOT
  14731.  
  14732. M187    DFB    TXT,167    ;'Not a '
  14733.     ASC    'valid '
  14734.     DFB    EOT
  14735.  
  14736. M188    DFB    TXT,125    ;'Eight-bit-prefix character'
  14737.     DFB    TXT,193    ;' cannot be same as '
  14738.     DFB    TXT,191    ;'Quote character'
  14739.     DFB    EOT
  14740.  
  14741. M189    DFB    TXT,175    ;'Suffix '
  14742.     ASC    'string'
  14743.     DFB    TXT,190    ;' is too long'
  14744.     DFB    EOT
  14745.  
  14746. M190    ASC    ' is too long'
  14747.     DFB    EOT
  14748.  
  14749. M191    ASC    'Quote'
  14750.     DFB    TXT,152    ;' character'
  14751.     DFB    EOT
  14752.  
  14753. M192    DFB    TXT,191    ;'Quote character'
  14754.     DFB    TXT,193    ;' cannot be same as '
  14755.     DFB    TXT,125    ;'Eight-bit-prefix character'
  14756.     DFB    EOT
  14757.  
  14758. M193    ASC    " can't be same as "
  14759.     DFB    EOT
  14760.  
  14761. M194    ASC    'Value is out of range'
  14762.     DFB    EOT
  14763.  
  14764. M195    DFB    TXT,170    ;'File '
  14765.     ASC    'name'
  14766.     DFB    TXT,190    ;' is too long'
  14767.     DFB    EOT
  14768.  
  14769. M196    DFB    TXT,187    ;'Not a valid '
  14770.     ASC    'number'
  14771.     DFB    EOT
  14772.  
  14773. M197    ASC    'Directory on'
  14774.     DFB    TXT,163    ;' remote system'
  14775.     DFB    EOT
  14776.  
  14777. M198    DFB    TXT,167    ;'Not a '
  14778.     ASC    'single'
  14779.     DFB    TXT,152    ;' character'
  14780.     DFB    EOT
  14781.  
  14782. M199    ASC    ' we wish to receive'
  14783.     DFB    EOT
  14784.  
  14785. M200    ASC    'Start-of-'
  14786.     DFB    'p',TXT,218 ;'packet'
  14787.     DFB    TXT,152    ;' character'
  14788.     DFB    EOT
  14789.  
  14790. M201    DFB    TXT,224    ;' we send'
  14791.     ASC    ' to'
  14792.     DFB    TXT,163 ;' remote system'
  14793.     DFB    EOT
  14794.  
  14795. M202    ASC    ' (0-31)'
  14796.     DFB    EOT
  14797.  
  14798. M203    ASC    'End-of-line'
  14799.     DFB    TXT,152    ;' character'
  14800.     DFB    EOT
  14801.  
  14802. M204    ASC    'Password?'
  14803.     DFB    EOT
  14804.  
  14805. M205    ASC    'Timeout'
  14806.     DFB    EOT
  14807.  
  14808. M206    DFB    28,0,0,79,0,12,26,11
  14809.     DFB    EOT
  14810.  
  14811. M207    ASC    '  BBC MICRO '
  14812.     DFB    TXT,156    ;'KERMIT'
  14813.     ASC    '  '
  14814.     DFB    EOT
  14815.  
  14816. M208    ASC    'DL/PT '
  14817.     DFB    EOT
  14818.  
  14819. M209    ASC    'Type? '
  14820.     DFB    EOT
  14821.  
  14822. M210    DFB    22,3
  14823.     DFB    EOT
  14824.  
  14825. M211    DFB    22,7
  14826.     DFB    YELLOW,NEWBG,RED
  14827.     ASC    'CF:0=Exi:1=Dsc:2=Prt:3=Hld:4='
  14828.     DFB    MSP,3,':',$0D
  14829.     DFB    YELLOW,NEWBG,RED
  14830.     ASC    '  :5='
  14831.     DFB    MSP,3
  14832.     ASC    ':6='
  14833.     DFB    MSP,3
  14834.     ASC    ':7='
  14835.     DFB    MSP,3
  14836.     ASC    ':8=Lbk:9=Brk:'
  14837.     DFB    28,0,24,39,2
  14838.     DFB    EOT
  14839.  
  14840. M212    DFB    TXT,91    ;'erminal '
  14841.     ASC    'log'
  14842.     DFB    EOT
  14843.  
  14844. M213    ASC    'Number of '
  14845.     DFB    EOT
  14846.  
  14847. M214    ASC    'uffer size'
  14848.     DFB    EOT
  14849.  
  14850. M215    DFB    ' ',CYAN
  14851.     ASC    'Name '
  14852.     DFB    GREEN
  14853.     DFB    EOT
  14854.  
  14855. M216    ASC    'TRANSFER'
  14856.     DFB    EOT
  14857.  
  14858. M217    DFB    TXT,218    ;'acket '
  14859.     ASC    'size'
  14860.     DFB    EOT
  14861.  
  14862. M218    ASC    'acket '
  14863.     DFB    EOT
  14864.  
  14865. M219    ASC    'echo'
  14866.     DFB    EOT
  14867.  
  14868. M220    ASC    'prefix'
  14869.     DFB    EOT
  14870.  
  14871. M221    ASC    ' period'
  14872.     DFB    EOT
  14873.  
  14874. M222    ASC    ' V'
  14875.     DFB    MARK+$30
  14876.     ASC    '.'
  14877.     DFB    VERSION/10+$30
  14878.     DFB    (VERSION-(VERSION/10*10))+$30
  14879.     IF    ~LEVEL
  14880.     DFB    LEVEL+'A'
  14881.     ELSE
  14882.     DFB    ' '
  14883.     FI
  14884.     DFB    EOT
  14885.  
  14886. M223    DFB    $0D,TXT,156 ;'KERMIT'
  14887.     DFB    TXT,222,$0D ;' Vm.vv'
  14888.     DFB    EOT
  14889.  
  14890. M224    ASC    ' we send'
  14891.     DFB    EOT
  14892.  
  14893. M225    DFB    TXT,170    ;'File '
  14894.     ASC    'to transmit'
  14895.     DFB    EOT
  14896.  
  14897. M226    ASC    'ddress'
  14898.     DFB    EOT
  14899.  
  14900. M227    DFB    'A',TXT,226 ;'Address'
  14901.     DFB    EOT
  14902.  
  14903.  
  14904. ***************************************
  14905. *
  14906. * MESSAGE ADDRESS TABLE
  14907. * =====================
  14908. *
  14909. * This defines the start address of each
  14910. * of the texts.
  14911. *
  14912. * The first table holds the low bytes of
  14913. * each address, one message per table byte
  14914. *
  14915. * The second table is built with the MTHE
  14916. * macro. It contains a list of message numbers,
  14917. * each being the first message to start
  14918. * within one page, relative to the page
  14919. * M0 is in. The macro takes two parameters,
  14920. * so for message n the call should be
  14921. *    MTHE    n-1,n
  14922. *
  14923. ***************************************
  14924.  
  14925. MSGTBL    DFB    >M0,>M1,>M2,>M3,>M4,>M5,>M6,>M7,>M8,>M9
  14926.     DFB    >M10,>M11,>M12,>M13,>M14,>M15,>M16,>M17,>M18,>M19
  14927.     DFB    >M20,>M21,>M22,>M23,>M24,>M25,>M26,>M27,>M28,>M29
  14928.     DFB    >M30,>M31,>M32,>M33,>M34,>M35,>M36,>M37,>M38,>M39
  14929.     DFB    >M40,>M41,>M42,>M43,>M44,>M45,>M46,>M47,>M48,>M49
  14930.     DFB    >M50,>M51,>M52,>M53,>M54,>M55,>M56,>M57,>M58,>M59
  14931.     DFB    >M60,>M61,>M62,>M63,>M64,>M65,>M66,>M67,>M68,>M69
  14932.     DFB    >M70,>M71,>M72,>M73,>M74,>M75,>M76,>M77,>M78,>M79
  14933.     DFB    >M80,>M81,>M82,>M83,>M84,>M85,>M86,>M87,>M88,>M89
  14934.     DFB    >M90,>M91,>M92,>M93,>M94,>M95,>M96,>M97,>M98,>M99
  14935.     DFB    >M100,>M101,>M102,>M103,>M104,>M105,>M106,>M107,>M108,>M109
  14936.     DFB    >M110,>M111,>M112,>M113,>M114,>M115,>M116,>M117,>M118,>M119
  14937.     DFB    >M120,>M121,>M122,>M123,>M124,>M125,>M126,>M127,>M128,>M129
  14938.     DFB    >M130,>M131,>M132,>M133,>M134,>M135,>M136,>M137,>M138,>M139
  14939.     DFB    >M140,>M141,>M142,>M143,>M144,>M145,>M146,>M147,>M148,>M149
  14940.     DFB    >M150,>M151,>M152,>M153,>M154,>M155,>M156,>M157,>M158,>M159
  14941.     DFB    >M160,>M161,>M162,>M163,>M164,>M165,>M166,>M167,>M168,>M169
  14942.     DFB    >M170,>M171,>M172,>M173,>M174,>M175,>M176,>M177,>M178,>M179
  14943.     DFB    >M180,>M181,>M182,>M183,>M184,>M185,>M186,>M187,>M188,>M189
  14944.     DFB    >M190,>M191,>M192,>M193,>M194,>M195,>M196,>M197,>M198,>M199
  14945.     DFB    >M200,>M201,>M202,>M203,>M204,>M205,>M206,>M207,>M208,>M209
  14946.     DFB    >M210,>M211,>M212,>M213,>M214,>M215,>M216,>M217,>M218,>M219
  14947.     DFB    >M220,>M221,>M222,>M223,>M224,>M225,>M226,>M227
  14948.  
  14949.  
  14950. MSGTBH    DFB    0    ;M0 starts page relative 0
  14951.     MTHE    0,1
  14952.     MTHE    1,2
  14953.     MTHE    2,3
  14954.     MTHE    3,4
  14955.     MTHE    4,5
  14956.     MTHE    5,6
  14957.     MTHE    6,7
  14958.     MTHE    7,8
  14959.     MTHE    8,9
  14960.     MTHE    9,10
  14961.     MTHE    10,11
  14962.     MTHE    11,12
  14963.     MTHE    12,13
  14964.     MTHE    13,14
  14965.     MTHE    14,15
  14966.     MTHE    15,16
  14967.     MTHE    16,17
  14968.     MTHE    17,18
  14969.     MTHE    18,19
  14970.     MTHE    19,20
  14971.     MTHE    20,21
  14972.     MTHE    21,22
  14973.     MTHE    22,23
  14974.     MTHE    23,24
  14975.     MTHE    24,25
  14976.     MTHE    25,26
  14977.     MTHE    26,27
  14978.     MTHE    27,28
  14979.     MTHE    28,29
  14980.     MTHE    29,30
  14981.     MTHE    30,31
  14982.     MTHE    31,32
  14983.     MTHE    32,33
  14984.     MTHE    33,34
  14985.     MTHE    34,35
  14986.     MTHE    35,36
  14987.     MTHE    36,37
  14988.     MTHE    37,38
  14989.     MTHE    38,39
  14990.     MTHE    39,40
  14991.     MTHE    40,41
  14992.     MTHE    41,42
  14993.     MTHE    42,43
  14994.     MTHE    43,44
  14995.     MTHE    44,45
  14996.     MTHE    45,46
  14997.     MTHE    46,47
  14998.     MTHE    47,48
  14999.     MTHE    48,49
  15000.     MTHE    49,50
  15001.     MTHE    50,51
  15002.     MTHE    51,52
  15003.     MTHE    52,53
  15004.     MTHE    53,54
  15005.     MTHE    54,55
  15006.     MTHE    55,56
  15007.     MTHE    56,57
  15008.     MTHE    57,58
  15009.     MTHE    58,59
  15010.     MTHE    59,60
  15011.     MTHE    60,61
  15012.     MTHE    61,62
  15013.     MTHE    62,63
  15014.     MTHE    63,64
  15015.     MTHE    64,65
  15016.     MTHE    65,66
  15017.     MTHE    66,67
  15018.     MTHE    67,68
  15019.     MTHE    68,69
  15020.     MTHE    69,70
  15021.     MTHE    70,71
  15022.     MTHE    71,72
  15023.     MTHE    72,73
  15024.     MTHE    73,74
  15025.     MTHE    74,75
  15026.     MTHE    75,76
  15027.     MTHE    76,77
  15028.     MTHE    77,78
  15029.     MTHE    78,79
  15030.     MTHE    79,80
  15031.     MTHE    80,81
  15032.     MTHE    81,82
  15033.     MTHE    82,83
  15034.     MTHE    83,84
  15035.     MTHE    84,85
  15036.     MTHE    85,86
  15037.     MTHE    86,87
  15038.     MTHE    87,88
  15039.     MTHE    88,89
  15040.     MTHE    89,90
  15041.     MTHE    90,91
  15042.     MTHE    91,92
  15043.     MTHE    92,93
  15044.     MTHE    93,94
  15045.     MTHE    94,95
  15046.     MTHE    95,96
  15047.     MTHE    96,97
  15048.     MTHE    97,98
  15049.     MTHE    98,99
  15050.     MTHE    99,100
  15051.     MTHE    100,101
  15052.     MTHE    101,102
  15053.     MTHE    102,103
  15054.     MTHE    103,104
  15055.     MTHE    104,105
  15056.     MTHE    105,106
  15057.     MTHE    106,107
  15058.     MTHE    107,108
  15059.     MTHE    108,109
  15060.     MTHE    109,110
  15061.     MTHE    110,111
  15062.     MTHE    111,112
  15063.     MTHE    112,113
  15064.     MTHE    113,114
  15065.     MTHE    114,115
  15066.     MTHE    115,116
  15067.     MTHE    116,117
  15068.     MTHE    117,118
  15069.     MTHE    118,119
  15070.     MTHE    119,120
  15071.     MTHE    120,121
  15072.     MTHE    121,122
  15073.     MTHE    122,123
  15074.     MTHE    123,124
  15075.     MTHE    124,125
  15076.     MTHE    125,126
  15077.     MTHE    126,127
  15078.     MTHE    127,128
  15079.     MTHE    128,129
  15080.     MTHE    129,130
  15081.     MTHE    130,131
  15082.     MTHE    131,132
  15083.     MTHE    132,133
  15084.     MTHE    133,134
  15085.     MTHE    134,135
  15086.     MTHE    135,136
  15087.     MTHE    136,137
  15088.     MTHE    137,138
  15089.     MTHE    138,139
  15090.     MTHE    139,140
  15091.     MTHE    140,141
  15092.     MTHE    141,142
  15093.     MTHE    142,143
  15094.     MTHE    143,144
  15095.     MTHE    144,145
  15096.     MTHE    145,146
  15097.     MTHE    146,147
  15098.     MTHE    147,148
  15099.     MTHE    148,149
  15100.     MTHE    149,150
  15101.     MTHE    150,151
  15102.     MTHE    151,152
  15103.     MTHE    152,153
  15104.     MTHE    153,154
  15105.     MTHE    154,155
  15106.     MTHE    155,156
  15107.     MTHE    156,157
  15108.     MTHE    157,158
  15109.     MTHE    158,159
  15110.     MTHE    159,160
  15111.     MTHE    160,161
  15112.     MTHE    161,162
  15113.     MTHE    162,163
  15114.     MTHE    163,164
  15115.     MTHE    164,165
  15116.     MTHE    165,166
  15117.     MTHE    166,167
  15118.     MTHE    167,168
  15119.     MTHE    168,169
  15120.     MTHE    169,170
  15121.     MTHE    170,171
  15122.     MTHE    171,172
  15123.     MTHE    172,173
  15124.     MTHE    173,174
  15125.     MTHE    174,175
  15126.     MTHE    175,176
  15127.     MTHE    176,177
  15128.     MTHE    177,178
  15129.     MTHE    178,179
  15130.     MTHE    179,180
  15131.     MTHE    180,181
  15132.     MTHE    181,182
  15133.     MTHE    182,183
  15134.     MTHE    183,184
  15135.     MTHE    184,185
  15136.     MTHE    185,186
  15137.     MTHE    186,187
  15138.     MTHE    187,188
  15139.     MTHE    188,189
  15140.     MTHE    189,190
  15141.     MTHE    190,191
  15142.     MTHE    191,192
  15143.     MTHE    192,193
  15144.     MTHE    193,194
  15145.     MTHE    194,195
  15146.     MTHE    195,196
  15147.     MTHE    196,197
  15148.     MTHE    197,198
  15149.     MTHE    198,199
  15150.     MTHE    199,200
  15151.     MTHE    200,201
  15152.     MTHE    201,202
  15153.     MTHE    202,203
  15154.     MTHE    203,204
  15155.     MTHE    204,205
  15156.     MTHE    205,206
  15157.     MTHE    206,207
  15158.     MTHE    207,208
  15159.     MTHE    208,209
  15160.     MTHE    209,210
  15161.     MTHE    210,211
  15162.     MTHE    211,212
  15163.     MTHE    212,213
  15164.     MTHE    213,214
  15165.     MTHE    214,215
  15166.     MTHE    215,216
  15167.     MTHE    216,217
  15168.     MTHE    217,218
  15169.     MTHE    218,219
  15170.     MTHE    219,220
  15171.     MTHE    220,221
  15172.     MTHE    221,222
  15173.     MTHE    222,223
  15174.     MTHE    223,224
  15175.     MTHE    224,225
  15176.     MTHE    225,226
  15177.     MTHE    226,227
  15178. MTHCNT    EQU    *-MSGTBH-1
  15179.  
  15180.     LST    ON
  15181.  
  15182. PRGTOP    EQU    *
  15183.  
  15184.     IF    LFULL!LSTXXX&LIST
  15185.     LST    ON
  15186.     ELSE
  15187.     LST    OFF
  15188.     FI
  15189.  
  15190.     IF    ROM
  15191.     DS    $C000-*
  15192.     IF    ~ADE
  15193.     DISP2    'ROM space free %D($C000-PRGTOP) bytes'
  15194.     FI
  15195.     FI
  15196. ****** File BBCWKS *************************************************************
  15197.     START    WKS
  15198. * BBCWKS: Updated 10/01/87 @ 1730
  15199.  
  15200. **************************************
  15201. *
  15202. * WORKSPACE
  15203. * =========
  15204. *
  15205. * This defines the non-page 0 areas
  15206. * to be used
  15207. *
  15208. **************************************
  15209.  
  15210.     DSECT
  15211.  
  15212.     ORG    $400
  15213.  
  15214. WKBASE    EQU    *
  15215.  
  15216. ***************************************
  15217. *
  15218. * Locations in this block are maintained
  15219. * by the main program but can be used
  15220. * by a TXR for the same purposes. Their
  15221. * location is fixed
  15222. *
  15223. ***************************************
  15224.  
  15225. PTYPE    DFB    0    ;0=ROM, $FF=RAM
  15226. IOBUFF    DS    IOBSIZ    ;comms buffer
  15227.  
  15228.  
  15229. ***************************************
  15230. *
  15231. * This block contains the current SET
  15232. * parameter values. A TXR may read them
  15233. * but should not really change them
  15234. * unless it is prepared to do any dependent
  15235. * changes involved as well. TXRs *must*
  15236. * access values as offsets from (DEFPTR)
  15237. * above, as this block may move. The
  15238. * offset values will not be changed.
  15239. *
  15240. * Also here are various odds and ends
  15241. * used by the main program - TXRs must
  15242. * not tamper with these
  15243. *
  15244. ***************************************
  15245.  
  15246. DFBASE    EQU    *
  15247.  
  15248. TXBAUD    DFB    0    ;transmit baud rate
  15249. RXBAUD    DFB    0    ;receive baud rate
  15250. ECHO    DFB    0    ;local echo
  15251.     DFB    0    ;obsolete byte (1.03)
  15252. DEBUG    DFB    0    ;debug mode
  15253.     DFB    0    ;obsolete byte (1.03)
  15254. STIME    DFB    0    ;timeout he uses on me
  15255. RTIME    DFB    0    ;timeout I use on him
  15256. TIMER    DFB    0    ;whether I do timing
  15257. PAUSE    DFB    0    ;pause after packet read
  15258. DELAY    DFB    0    ;delay after SEND command
  15259.     DFB    0    ;obsolete byte (1.40)
  15260.     DFB    0    ;obsolete byte (1.40)
  15261. CLICK    DFB    0    ;keyclick flag
  15262. SQUOTE    DFB    0    ;quote I will send
  15263. CUREBQ    DFB    0    ;8 bit prefix I want to use
  15264. SEOLN    DFB    0    ;EOLN I send to start
  15265. REOLN    DFB    0    ;EOLN I ask him to send
  15266. RPADC    DFB    0    ;pad char I ask him to send
  15267. RNPAD    DFB    0    ;pad char count I ask him to use
  15268. SPADC    DFB    0    ;pad character I send
  15269. SNPAD    DFB    0    ;number I send
  15270. PARITY    DFB    0    ;parity setting
  15271. FTYPE    DFB    0    ;file type
  15272. EORTYP    DFB    0    ;type of EOR in use
  15273. SOURCE    DFB    0    ;source of data (file/memory)
  15274. MSBASE    DW    0    ;source base for memory
  15275. MSTOP    DW    0    ;source top for memory
  15276. DESTIN    DFB    0    ;destination (file/memory)
  15277. MDBASE    DW    0    ;dest base for memory
  15278. MDTOP    DW    0    ;dest top for memory
  15279. SSOP    DFB    0    ;start of packet I will send
  15280. RSOP    DFB    0    ;start of packet I expect him to send
  15281. RMAXL    DFB    0    ;max size packet (data + red tape) I want from him
  15282. FBPAGES DFB    0    ;size of file buffer in pages
  15283. FWARN    DFB    0    ;file warning flag
  15284. FINCOM    DFB    0    ;incomplete file disposition
  15285. FLOW    DFB    0    ;flow control in use
  15286. SUFLEN    DFB    0    ;length of file suffix
  15287. SUFFIX    DS    8    ;file suffix (less the ".")
  15288. TKECHO    DFB    0    ;TAKE file echo
  15289. VDUCOL    DFB    0    ;VDU foreground colour
  15290. TVFLAG    DFB    0    ;flag for doing *TV
  15291. TVPAR1    DFB    0    ;first *TV parameter
  15292. TVPAR2    DFB    0    ;second *TV parameter
  15293. IGNFLG    DFB    0    ;flag for VDI ignore in use
  15294. IGNCHR    DFB    0    ;character to ignore
  15295. MUXWT    DFB    0    ;MUX wait in byte periods
  15296. HLPTRG    DFB    0    ;char triggering command autohelp
  15297. MAXTRY    DFB    0    ;max retries allowed
  15298. HSHAKE    DFB    0    ;handshake type in use
  15299. TTYPE    DFB    0    ;terminal type in use
  15300. FNTYPE    DFB    0    ;file name translation type
  15301.  
  15302. DFTOP    EQU    *
  15303. DFSIZE    EQU    *-DFBASE
  15304.  
  15305. OLDIRQ    DW    0    ;copy of old IRQ1 vector
  15306. EOR    DS    2    ;end-of-record bytes in use
  15307. FSNUM    DFB    0    ;number of filing system at start
  15308. FBSIZE    DW    0    ;size of buffer
  15309. OLDHWM    DFB    0    ;setting of OSHWM on entry
  15310. STARTUP DFB    0    ;startup flag
  15311.  
  15312. ***************************************
  15313. *
  15314. * Space from here to $7FF may be used
  15315. * freely by a TXR. Such ROMs should
  15316. * allocate space from $7FF down to
  15317. * allow for expansion in the tables
  15318. * above
  15319. *
  15320. ***************************************
  15321.  
  15322. TXBUFF    DS    MAXPAK    ;outgoing packet
  15323. RXBUFF    DS    MAXPAK    ;incoming packet
  15324. SCBUFF    DS    MAXPAK    ;buffer for building server command
  15325.  
  15326. MAXINP    EQU    120    ;max length of command line
  15327. CMDBUF    DS    MAXINP    ;input buffer
  15328.  
  15329. MAXFNL    EQU    64    ;max length of filename
  15330. FBTOP    DW    0    ;buffer high water mark
  15331. FBMAX    DW    0    ;pointer to byte past buffer
  15332. FHAND    DFB    0    ;file handle
  15333. EOB    DFB    0    ;buffer flags
  15334. EOF    DFB    0
  15335. GBPBLK    DS    18    ;OSGBPB block for I/O; also OSFILE use
  15336. GNXBLK    DS    13    ;          for directory scan
  15337. RFNAME    DS    MAXFNL    ;remote filename
  15338. LFNLEN    DFB    0    ;size of local name
  15339. LFNAME    DS    MAXFNL    ;local name - must follow LFNLEN
  15340. LFGIVEN DFB    0    ;flag for explicit local name
  15341. WCLEN    DFB    0    ;length of wildcarded name
  15342. WCNAME    DS    MAXFNL    ;wildcarded name
  15343. FSNLEN    DFB    0    ;size of name FS allows
  15344.  
  15345.     IF    *>$800
  15346.     STOP    '** Too much workspace **'
  15347.     FI
  15348.  
  15349.     DEND
  15350.  
  15351.  
  15352. ***************************************
  15353. *
  15354. * This area defines the buffer used for
  15355. * terminal mode logging. A TXR may use
  15356. * it as it wishes
  15357. *
  15358. ***************************************
  15359.  
  15360.     DSECT
  15361.     ORG    $A00
  15362. LOGBUF    DS    256
  15363.     DEND
  15364.  
  15365.  
  15366.     CHN    BBCMAI
  15367.