home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / k65src.zip / kermit65.m65 next >
Text File  |  1990-05-27  |  411KB  |  15,024 lines

  1. ; TITLE  KERMIT-65    KL10 Error-free Reciprocal Micro-interface Transfer
  2. ;
  3. ;    6502 version - Antonino N. J. Mione
  4. ;    Commodore 64 version converted from Apple version 1.1
  5. ;    By Dave Dermott  March, 1984
  6. ;    Additional improvements by Eric Lavitsky/Frank Prindle/
  7. ;    Michael Marchiondo/Ray Moody
  8. ;
  9. ;    Atari 800 version converted from Commodore version by 
  10. ;    John Dunning.
  11. ;
  12. ;    Version 3.7 
  13. ;
  14. ;.SBTTL    Revision History
  15.  
  16. ;
  17. ; Date        Description
  18. ; ------    -----------
  19. ; 4/87 - 7/87    By JRD.  Found the Commodore version and went at it with 
  20. ;        a meat cleaver.  Made changes too numerous to detail here;
  21. ;        replaced all io with calls to CIO; revamped screen handling
  22. ;        to use CTIA instead of VIC, cleaned up user interface, fixed
  23. ;        comm port handling to work with 850, ad nauseum.
  24. ;
  25. ; ------    v3.1 released here
  26. ;
  27. ; 8/10/87 - 8/17/87
  28. ;        Fixed binary mode.  Fixed eight-bit-quoting negotiation.
  29. ;        Make erase and rename ensure rs port closed.  Fix stupid
  30. ;        but insidious bug in terminal code that caused graphics
  31. ;        mode to be turned on spuriously when processing a BS
  32. ;        in column 15 (!)
  33. ;
  34. ; ------    v 3.2 released here
  35. ;
  36. ; 8/18/87 - 
  37. ;        Finish wildcard support in pathnames.  Fix file reader
  38. ;        to deal with Spartados not adhering to spec.  Fix all
  39. ;        parameter display/entry to use decimal where apropriate,
  40. ;        ie in timeout values.  Display values in 'Status' display
  41. ;        in decimal.  Implement Atari key (/|\) as input-suspend.
  42. ;        Fix bug in flow-control that caused it to wedge up
  43. ;        unexpectedly.  Clean up 80-column font per JHS's comments.
  44. ;        Removed Speedscript file type.  Fix stack-corruption
  45. ;        in terminal code.  Clean up some of the really obscure
  46. ;        cases in vt100 mode.
  47. ;        
  48. ; 4/11/90 - jrd
  49. ;        Fix bug in Spartados EOF handling.  Remove assumption
  50. ;        about screen width, to allow XEP80 to work.
  51. ;
  52. ; release v 3.6.
  53. ;
  54. ; 5/28/90 - jrd
  55. ;        Fix the stupid D8: bug again.
  56. ;
  57. ; release v 3.7.
  58. ;
  59. ;
  60. ;----------------------------------------------------------------
  61. ;
  62. ; Things that need doing:
  63. ;
  64. ; The telnet loop is a real mess, needs to be flushed and redone completely.
  65. ;
  66. ; Rip out old debugging code.
  67. ;
  68. ; Parameterize Serial io calls so that we can run smoother with interfaces 
  69. ; other than 850
  70. ;
  71. ; Finish making all the internal pathname hacking stuff really use 
  72. ; pathnames, not just strings.
  73. ;
  74. ; Implement 'Remote ... ' command.
  75. ;
  76. ; Implement some facility for defining function keys.
  77. ;
  78. ;+
  79.  
  80. ;
  81. ;----------------------------------------------------------------
  82. ;
  83. ; Defs for running this thing on an atari
  84. ;
  85. kbdchan    =    $10        ; keyboard IOCB
  86. scrchan =    $00        ; screen (E:) IOCB
  87. comchan =    $30        ; serial port
  88. dskchan =    $40        ; disk
  89. dirchan =    $50        ; special one for directory access
  90. ;
  91. ;.SBTTL    Jump to start of code
  92.  
  93. ;kst:    jmp    kstart        ; Go past the data to the beginning of the code
  94. ; on atari, just say where to start
  95.     *=    $2E0
  96.     .word    kstart
  97.  
  98. ;
  99. ;    now start at a reasonable place
  100. ;
  101.     *=    $2D20        ; about as low as reasonable on atari
  102. ;
  103. ;.SBTTL    Character and string definitions
  104. nul    =    $00        ; <null>
  105. soh    =    $01        ; <soh>
  106. bel    =    $07        ; c-g
  107. bs    =    $08        ; <bs>
  108. tab    =    $09        ; <tab> (ctrl/I)
  109. lf    =    $0A        ; <lf>
  110. ffd    =    $0C        ; Form feed
  111. cr    =    $0D        ; <cr>
  112. so    =    $0E        ; <shift-out>
  113. si    =    $0F        ; <shift-in>
  114. ctrlu    =    $15        ; <ctrl/U>
  115. ctrlx    =    $18        ; <ctrl/X>
  116. ctrly    =    $19        ; <ctrl/Y>
  117. esc    =    $1B        ; <esc>
  118. sp    =    $20        ; <space>
  119. space    =    $20        ; " "
  120. del    =    $7F        ; <del>
  121. quest    =    $3F        ; <?>
  122. ctrlw    =    $17        ; <ctrl/W>
  123. dquot    =    $22        ; '"'        ?
  124. quot    =    $27        ; "'"        ?
  125. slash    =    $2F        ; '/'        ?
  126. apos    =    quot        ; "'"        ?
  127. rabr    =    $3E        ; '>'        ?
  128. colon    =    $3A        ; ':'        ?
  129.  
  130. ;----------------------------------------------------------------
  131. ; Atari OS defs from SYSMAC.SML inserted here
  132. ;
  133.  
  134. ;    VECTOR TABLE
  135.  
  136. EDITRV    =$E400            ;EDITOR
  137. SCRENV    =$E410            ;TELEVISION SCREEN
  138. KEYBDV    =$E420            ;KEYBOARD
  139. PRINTV    =$E430            ;PRINTER
  140. CASETV    =$E440            ;CASSETTE
  141.  
  142. ;    JUMP VECTOR TABLE
  143.  
  144. DISKIV    =$E450            ;DISK INITIALIZATION
  145. DSKINV    =$E453            ;DISK INTERFACE
  146. CIOV    =$E456            ;CIO ROUTINE
  147. SIOV    =$E459            ;SIO ROUTINE
  148. SETVBV    =$E45C            ;SET VERTICAL BLANK VECTORS
  149. SYSVBV    =$E45F            ;SYSTEM VERTICAL BLANK ROUTINE
  150. XITVBV    =$E462            ;EXIT VERTICAL BLANK ROUTINE
  151. SIOINV    =$E465            ;SIO INIT
  152. SENDEV    =$E468            ;SEND ENABLE ROUTINE
  153. INTINV    =$E46B            ;INTERRUPT HANDLER INIT
  154. CIOINV    =$E46E            ;CIO INIT
  155. BLKBDV    =$E471            ;BLACKBOARD MODE
  156. WARMSV    =$E474            ;WARM START ENTRY POINT
  157. COLDSV    =$E477            ;COLD START ENTRY POINT
  158. RBLOKV    =$E47D            ;CASSETTE READ BLOCK VECTOR
  159. DSOPIV    =$E480            ;CASSETTE OPEN FOR INPUT VECTOR
  160.  
  161. ;    SOME USEFUL INTERNAL ROUTINES
  162.  
  163. ;KGETCH    =$F6E2            ;GET CHAR FROM KEYBOARD only on 800
  164. EOUTCH    =$F6A4            ;OUTPUT CHAR TO SCREEN
  165. PUTLIN    =$F385            ;OUTPUT LINE TO IOCB#0
  166.  
  167. ;    COMMAND CODES FOR IOCB
  168.  
  169. OPEN    =$03            ;OPEN FOR INPUT/OUTPUT
  170. GETREC    =$05            ;GET RECORD (TEXT)
  171. GETCHR    =$07            ;GET CHARACTER(S)
  172. PUTREC    =$09            ;PUT RECORD (TEXT)
  173. PUTCHR    =$0B            ;PUT CHARACTER(S)
  174. CLOSE    =$0C            ;CLOSE DEVICE
  175. STATIS    =$0D            ;STATUS REQUEST
  176. SPECIL    =$0E            ;SPECIAL ENTRY COMMANDS
  177.  
  178. ;    SPECIAL ENTRY COMMANDS
  179.  
  180. DRAWLN    =$11            ;DRAW LINE
  181. FILLIN    =$12            ;DRAW LINE WITH RIGHT FILL
  182. RENAME    =$20            ;RENAME DISK FILE
  183. DELETE    =$21            ;DELETE DISK FILE
  184. FORMAT    =$22            ;FORMAT DISK
  185. LOCKFL    =$23            ;LOCK FILE (READ ONLY)
  186. UNLOCK    =$24            ;UNLOCK FILE
  187. POINT    =$25            ;POINT SECTOR
  188. NOTE    =$26            ;NOTE SECTOR
  189.  
  190. CCIO    =$28            ;CONCURRENT I/O MODE
  191.  
  192. IOCFRE    =$FF            ;IOCB "FREE"
  193.  
  194. ;    AUX1 VALUES FOR OPEN
  195.  
  196. APPEND    =$01            ;OPEN FOR APPEND
  197. DIRECT    =$02            ;OPEN FOR DIRECTORY ACCESS
  198. OPNIN    =$04            ;OPEN FOR INPUT
  199. OPNOT    =$08            ;OPEN FOR OUTPUT
  200. OPNINO    =OPNIN!OPNOT        ;OPEN FOR INPUT/OUTPUT
  201. MXDMOD    =$10            ;OPEN FOR MIXED MODE
  202. INSCLR    =$20            ;OPEN WITHOUT CLEARING SCREEN
  203.  
  204. ; OS STATUS CODES
  205.  
  206. SUCCES    =$01            ;SUCCESSFUL OPERATION
  207. BRKABT    =$80            ;(128) BREAK KEY ABORT
  208. PRVOPN    =$81            ;(129) IOCB ALREADY OPEN
  209. NONDEV    =$82            ;(130) NON-EX DEVICE
  210. WRONLY    =$83            ;(131) IOCB OPENED FOR WRITE ONLY
  211. NVALID    =$84            ;(132) INVALID COMMAND
  212. NOTOPN    =$85            ;(133) DEVICE OR FILE NOT OPEN
  213. BADIOC    =$86            ;(134) INVALID IOCB NUMBER
  214. RDONLY    =$87            ;(135) IOCB OPENED FOR READ ONLY
  215. EOFERR    =$88            ;(136) END OF FILE
  216. TRNRCD    =$89            ;(137) TRUNCATED RECORD
  217. TIMOUT    =$8A            ;(138) DEVICE TIMEOUT
  218. DNACK    =$8B            ;(139) DEVICE DOES NOT ACK COMMAND
  219. FRMERR    =$8C            ;(140) SERIAL BUS FRAMING ERROR
  220. CRSROR    =$8D            ;(141) CURSOR OUT OF RANGE
  221. OVRRUN    =$8E            ;(142) SERIAL BUS DATA OVERRUN
  222. CHKERR    =$8F            ;(143) SERIAL BUS CHECKSUM ERROR
  223. DERROR    =$90            ;(144) DEVICE ERROR (OPERATION INCOMPLETE)
  224. BADMOD    =$91            ;(145) BAD SCREEN MODE NUMBER
  225. FNCNOT    =$92            ;(146) FUNCTION NOT IN HANDLER
  226. SCRMEM    =$93            ;(147) INSUFFICIENT MEMORY FOR SCREEN MODE
  227.  
  228. ;    PAGE 0 LOCATIONS
  229.  
  230. LINZBS    =$00            ;LINBUG STORAGE
  231.  
  232. ;  THESE LOCS ARE NOT CLEARED
  233.  
  234. CASINI    =$02            ;CASSETTE INIT LOC
  235. RAMLO    =$04            ;RAM POINTER FOR MEM TEST
  236. TRAMSZ    =$06            ;TEMP LOC FOR RAM SIZE
  237. TSTDAT    =$07            ;RAM TEST DATA LOC
  238.  
  239. ;  CLEARED ON COLDSTART ONLY
  240.  
  241. WARMST    =$08            ;WARM START FLAG
  242. BOOTQ    =$09            ;SUCCESSFUL BOOT FLAG
  243. DOSVEC    =$0A            ;DOS START VECTOR
  244. DOSINI    =$0C            ;DOS INIT ADDRESS
  245. APPMHI    =$0E            ;APPLICATION MEM HI LIMIT
  246.  
  247. ;  CLEARED ON COLD OR WARM START
  248.  
  249. INTZBS    =$10            ; START OF OS RAM CLEAR LOC => $7F
  250. POKMSK    =$10            ;SYSTEM MASK FOR POKEY IRQ ENABLE
  251. BRKKEY    =$11            ;BREAK KEY FLAG
  252. RTCLOK    =$12            ;REAL TIME CLOCK (60HZ OR 16.66666 MS)
  253.                 ; 3 bytes; hi order, medium, low
  254. BUFADR    =$15            ;INDIRECT BUFFER ADDRESS REG
  255. ICCOMT    =$17            ;COMMAND FOR VECTOR HANDLER
  256. DSKFMS    =$18            ;DISK FILE MANAGER POINTER
  257. DSKUTL    =$1A            ;DISK UTILITIES POINTER
  258. PTIMOT    =$1C            ;PRINTER TIME OUT REGISTER
  259. PBPNT    =$1D            ;PRINT BUFFER POINTER
  260. PBUFSZ    =$1E            ;PRINT BUFFER SIZE
  261. PTEMP    =$1F            ;TEMP REG
  262. ZIOCB    =$20            ;PAGE 0 I/O CONTROL BLOCK
  263. IOCBSZ    =16            ;NUMBER OF BYTES / IOCB
  264. MAXIOC    =8*IOCBSZ        ;LENGTH OF IOCB AREA
  265. IOCBAS    =ZIOCB
  266.  
  267. ICHIDZ    =$20            ;HANDLER INDEX NUMBER ($FF := IOCB FREE)
  268. ICDNOZ    =$21            ;DEVICE NUMBER (DRIVE NUMBER)
  269. ICCOMZ    =$22            ;COMMAND CODE
  270. ICSTAZ    =$23            ;STATUS OF LAST IOCB ACTION
  271. ICBALZ    =$24            ;BUFFER ADDRESS (LOW)
  272. ICBAHZ    =$25            ;  "       "    (HIGH)
  273. ICPTLZ    =$26            ;PUT BYTE ROUTINE ADDRESS - 1
  274. ICPTHZ    =$27
  275. ICBLLZ    =$28            ;BUFFER LENGTH (LOW)
  276. ICBLHZ    =$29            ;  "       "   (HIGH)
  277. ICAX1Z    =$2A            ;AUX INFO
  278. ICAX2Z    =$2B
  279. ICSPRZ    =$2C            ;SPARE BYTES (CIO LOCAL USE)
  280. ICIDNO    =ICSPRZ+2        ;IOCB LUMBER * 16
  281. CIOCHR    =ICSPRZ+3        ;CHARACTER BYTE FOR CURRENT OPERATION
  282.  
  283. STATUS    =$30            ;INTERNAL STATUS STORAGE
  284. CHKSUM    =$31            ;CHECKSUM (SINGLE BYTE SUM WITH CARRY)
  285. BUNRLO    =$32            ;POINTER TO DATA BUFFER (LO BYTE)
  286. BUFRHI    =$33            ;POINTER TO DATA BUFFER (HI BYTE)
  287. BFENLO    =$34            ;NEXT BYTE PAST END OF BUFFER (LO BYTE)
  288. BNENHI    =$35            ;NEXT BYTE PAST END OF BUFFER (HI BYTE)
  289. CRETRY    =$36            ;NUMBER OF COMMAND FRAM RETRIES
  290. DRETRY    =$39            ;NUMBER OF DEVICE RETRIES
  291. BUFRFL    =$38            ;DATA BUFFER FULL FLAG
  292. RECVDN    =$39            ;RECEIVE DONE FLAG
  293. XMTDON    =$3A            ;XMIT DONE FLAG
  294. CHKSNT    =$3B            ;CHECKSUM SENT FLAG
  295. NOCKSM    =$3C            ;NO CHECKSUM FOLLOWS DATA FLAG
  296.  
  297. BPTR    =$3D            ;BUFFER POINTER (CASSETTE)
  298. FTYPE    =$3E            ;FILE TYPE (SHORT IRG/LONG IRG)
  299. FEOF    =$3F            ;END OF FILE FLAG (CASSETTE)
  300. FREQ    =$40            ;FREQ COUNTER FOR CONSOLE SPEAKER
  301. SOUNDR    =$41            ;NOISY I/O FLAG. (ZERO IS QUIET)
  302. CRITIC    =$42            ;CRITICAL CODE IF NON-ZERO)
  303.  
  304. FMSZPG    =$43            ;DISK FILE MANAGER SYSTEM STORAGE (7 BYTES)
  305.  
  306. CKEY    =$4A            ;SET WHEN GAME START PRESSED
  307. CASSBT    =$4B            ;CASSETTE BOOT FLAG
  308. DSTAT    =$4C            ;DISPLAY STATUS
  309. ATRACT    =$4D            ;ATTRACT MODE FLAG
  310. DRKMSK    =$4E            ;DARK ATTRACT MASK
  311. COLRSH    =$4F            ;ATTRACT COLOR SHIFTER (XOR'D WITH PLAYFIELD)
  312.  
  313. TMPCHR    =$50            ;TEMP CHAR STORAGE (DISPLAY HANDLER)
  314. HOLD1    =$51            ;TEMP STG (DISPLAY HANDLER)
  315. LMARGN    =$52            ;LEFT MARGIN
  316. RMARGN    =$53            ;RIGHT MARGIN
  317. ROWCRS    =$54            ;CURSOR COUNTERS
  318. COLCRS    =$55
  319. DINDEX    =$57            ;DISPLAY INDEX (VARIOUS QUANTS)
  320. SAVMSC    =$58
  321. OLDROW    =$5A            ;PREVIOUS ROW/COL
  322. OLDCOL    =$5B
  323. OLDCHR    =$5D            ;DATA UNDER CURSOR
  324. OLDADR    =$5E
  325. NEWROW    =$60            ;POINT DRAWS TO HERE
  326. NEWCOL    =$61
  327. LOGCOL    =$63            ;POINTS AT COLUMN IN LOGICAL LINE
  328. ADRESS    =$64            ;INDIRECT POINTER
  329. MLTTMP    =$66            ;MULTIPLY TEMP
  330. OPNTMP    =MLTTMP            ;FIRST BYTE IS USED IN OPEN AS TEMP
  331. SAVADR    =$68
  332. RAMTOP    =$6A            ;RAM SIZE DEFINED BY POWER ON LOGIC
  333. BUFCNT    =$6B            ;BUFFER COUNT
  334. BUFSTR    =$6C            ;EDITOR GETCH POINTER
  335. BITMSK    =$6E            ;BIT MASK
  336. SHFAMT    =$6F            ;OUTCHR SHIFT
  337.  
  338. ROWAC    =$70            ;USED BY "DRAW"
  339. COLAC    =$72
  340. ENDPT    =$74
  341. DELTAR    =$76
  342. DELTAC    =$77
  343. ROWINC    =$79
  344. COLINC    =$7A
  345. SWPFLG    =$7B            ;NON-0 IF TXT AND RAM SWAPPED
  346. HOLDCH    =$7C            ;CH BEFORE CNTL & SHFT PROCESSING IN KGETCH
  347. INSDAT    =$7D            ;INSERT CHAR SAVE
  348. COUNTR    =$7E            ;DRAW COUNTER
  349.  
  350. ;;;    $80 TO $FF ARE RESERVED FOR USER APPLICATIONS
  351.  
  352. ;    PAGE 2 LOCATIONS
  353.  
  354. INTABS    =$200            ;INTERRUPT TABLE
  355. VDSLST    =$200            ;DISPLAY LIST NMI VECTOR
  356. VPRCED    =$202            ;PROCEED LINE IRQ VECTOR
  357. VINTER    =$204            ;INTERRUPT LINE IRQ VECTOR
  358. VBREAK    =$206            ;"BRK" VECTOR
  359. VKEYBD    =$208            ;POKEY KEYBOARD IRQ VECTOR
  360. VSERIN    =$20A            ;POKEY SERIAL INPUT READY
  361. VSEROR    =$20C            ;POKEY SERIAL OUTPUT READY
  362. VSEROC    =$20E            ;POKEY SERIAL OUTPUT DONE
  363. VTIMR1    =$210            ;POKEY TIMER 1 IRQ
  364. VTIMR2    =$212            ;POKEY TIMER 2 IRQ
  365. VTIMR4    =$214            ;POKEY TIMER 4 IRQ (DO NOT USE)
  366. VIMIRQ    =$216            ;IMMEDIATE IRQ VECTOR
  367. CDTMV1    =$218            ;COUNT DOWN TIMER 1
  368. CDTMV2    =$21A            ;COUNT DOWN TIMER 2
  369. CDTMV3    =$21C            ;COUNT DOWN TIMER 3
  370. CDTMV4    =$21E            ;COUNT DOWN TIMER 4
  371. CDTMV5    =$220            ;COUNT DOWN TIMER 5
  372. VVBLKI    =$222            ;IMMEDIATE VERTICAL BLANK NMI VECTOR
  373. VVBLKD    =$224            ;DEFERRED VERTICAL BLANK NMI VECTOR
  374. CDTMA1    =$226            ;COUNT DOWN TIMER 1 JSR ADDRESS
  375. CDTMA2    =$228            ;COUNT DOWN TIMER 2 JSR ADDRESS
  376. CDTMF3    =$22A            ;COUNT DOWN TIMER 3 FLAG
  377. SRTIMR    =$22B            ;SOFTWARE REPEAT TIMER
  378. CDTMF4    =$22C            ;COUNT DOWN TIMER 4 FLAG
  379. INTEMP    =$22D            ;IAN'S TEMP (???)
  380. CDTMF5    =$22E            ;COUNT DOWN TIMER 5 FLAG
  381. SDMCTL    =$22F            ;SAVE DMACTL REGISTER
  382. DMACTL    =$D400            ; the real DMA control reg
  383. SDLSTL    =$230            ;SAVE DISPLAY LIST (LOW)
  384. SDLSTH    =$231            ;SAVE DISPLAY LIST (HIGH)
  385. SSKCTL    =$232            ;SKCTL REGISTER RAM
  386.  
  387. LPENH    =$234            ;LIGHT PEN HORIZ VALUE
  388. LPENV    =$235            ;LIGHT PEN VERT VALUE
  389.                 ; ($236 - $239 SPARE)
  390. CDEVIC    =$23A            ;COMMAND FRAME BUFFER - DEVICE
  391. CCOMND    =$23B            ;COMMAND
  392. CAUX1    =$23C            ;COMMAND AUX BYTE 1
  393. CAUX2    =$23D            ;COMMAND AUX BYTE 2
  394. TEMP    =$23E            ;YES
  395. ERRFLG    =$23F            ;ERROR FLAG - ANY DEVICE ERROR EXCEPT TIMEOUT
  396.  
  397. DFLAGS    =$240            ;DISK FLAGS FROM SECTOR ONE
  398. DBSECT    =$241            ;NUMBER OF DISK BOOT SECTORS
  399. BOOTAD    =$242            ;ADDRESS FOR DISK BOOT LOADER
  400. COLDST    =$244            ;COLDSTART FLAG (1 = DOING COLDSTART)
  401.                 ;($245 SPARE)
  402. DSKTIM    =$246            ;DISK TIME OUT REG
  403. LINBUF    =$247            ;CHAR LINE BUFFER (40 BYTES)
  404.  
  405. GPRIOR    =$26F            ;GLOBAL PRIORITY CELL
  406. PADDL0    =$270            ;POT 0 SHADOW
  407. PADDL1    =$271            ;POT 1 SHADOW
  408. PADDL2    =$272            ;POT 2 SHADOW
  409. PADDL3    =$273            ;POT 3 SHADOW
  410. PADDL4    =$274            ;POT 4 SHADOW
  411. PADDL5    =$275            ;POT 5 SHADOW
  412. PADDL6    =$276            ;POT 6 SHADOW
  413. PADDL7    =$277            ;POT 7 SHADOW
  414. STICK0    =$278            ;JOYSTICK 0 SHADOW
  415. STICK1    =$279            ;JOYSTICK 1 SHADOW
  416. STICK2    =$27A            ;JOYSTICK 2 SHADOW
  417. STICK3    =$27B            ;JOYSTICK 3 SHADOW
  418. PTRIG0    =$27C            ;PADDLE 0 TRIGGER
  419. PTRIG1    =$27D            ;PADDLE 1 TRIGGER
  420. PTRIG2    =$27E            ;PADDLE 2 TRIGGER
  421. PTRIG3    =$27F            ;PADDLE 3 TRIGGER
  422. PTRIG4    =$280            ;PADDLE 4 TRIGGER
  423. PTRIG5    =$281            ;PADDLE 5 TRIGGER
  424. PTRIG6    =$282            ;PADDLE 6 TRIGGER
  425. PTRIG7    =$283            ;PADDLE 7 TRIGGER
  426. STRIG0    =$284            ;JOYSTICK 0 TRIGGER
  427. STRIG1    =$285            ;JOYSTICK 1 TRIGGER
  428. STRIG2    =$286            ;JOYSTICK 2 TRIGGER
  429. STRIG3    =$287            ;JOYSTICK 3 TRIGGER
  430.  
  431. CSTAT    =$288            ;(UNUSED)
  432. WMODE    =$289            ;R/W FLAG FOR CASSETTE
  433. BLIM    =$28A            ;BUFFER LIMIT (CASSETTE)
  434.                 ;($28B - $28F SPARE)
  435. TXTROW    =$290            ;TEXT ROWCRS
  436. TXTCOL    =$291            ;TEXT ROWCOL
  437. TINDEX    =$293            ;TEXT INDEX
  438. TXTMSC    =$294            ;FOOLS CONVRT INTO NEW MSC
  439. TXTOLD    =$296            ;OLDROW & OLDCOL FOR TEXT (AND THEN SOME)
  440. TMPX1    =$29C
  441. HOLD3    =$29D
  442. SUBTMP    =$29E
  443. HOLD2    =$29F
  444. DMASK    =$2A0
  445. TMPLBT    =$2A1
  446. ESCFLG    =$2A2            ;ESCAPE FLAG
  447. TABMAP    =$2A3            ;TAB BUFFER
  448. LOGMAP    =$2B2            ;LOGICAL LINE START BIT MAP
  449. INVFLG    =$2B6            ;INVERSE VIDEO FLAG (ATARI KEY)
  450. FILFLG    =$2B7            ;RIGHT FILL FLAG FOR DRAW
  451. TMPROW    =$2B8
  452. TMPCOL    =$2B9
  453. SCRFLG    =$2BB            ;SET IF SCROLL OCCURS
  454. HOLD4    =$2BC            ;MORE DRAW TEMPS
  455. HOLD5    =$2BD
  456. SHFLOK    =$2BE            ;SHIFT LOCK KEY
  457. BOTSCR    =$2BF            ;BOTTOM OF SCREEN (24 NORM, 4 SPLIT)
  458.  
  459. PCOLR0    =$2C0            ;P0 COLOR
  460. PCOLR1    =$2C1            ;P1 COLOR
  461. PCOLR2    =$2C2            ;P2 COLOR
  462. PCOLR3    =$2C3            ;P3 COLOR
  463. COLOR0    =$2C4            ;COLOR 0
  464. COLOR1    =$2C5
  465. COLOR2    =$2C6
  466. COLOR3    =$2C7
  467. COLOR4    =$2C8            ;BACKGROUND
  468.                 ;($2C9 - $2DF SPARE)
  469. GLBABS    =$2E0            ;GLOBAL VARIABLES
  470.                 ;($2E0 - $2E3 SPARE)
  471. RAMSIZ    =$2E4            ;RAM SIZE (HI BYTE ONLY)
  472. MEMTOP    =$2E5            ;TOP OF AVAILABLE MEMORY
  473. MEMLO    =$2E7            ;BOTTOM OF AVAILABLE MEMORY
  474.                 ;($2E9 SPARE)
  475. DVSTAT    =$2EA            ;STATUS BUFFER
  476. CBAUDL    =$2EE            ;CASSETTE BAUD RATE (LO BYTE)
  477. CBAUDH    =$2EF            ;   "      "    "   (HI BYTE)
  478. CRSINH    =$2F0            ;CURSOR INHIBIT (00 = CURSOR ON)
  479. KEYDEL    =$2F1            ;KEY DELAY
  480. CH1    =$2F2
  481. CHACT    =$2F3            ;CHACTL REGISTER (SHADOW)
  482. CHBAS    =$2F4            ;CHBAS REGISTER (SHADOW)
  483.                 ;($2F5 - $2F9 SPARE)
  484. CHAR    =$2FA
  485. ATACHR    =$2FB            ;ATASCII CHARACTER
  486. CH    =$2FC            ;GLOBAL VARIABLE FOR KEYBOARD
  487. FILDAT    =$2FD            ;RIGHT FILL DATA (DRAW)
  488. DSPFLG    =$2FE            ;DISPLAY FLAG: DISP CONTROLS IF NON-ZERO
  489. SSFLAG    =$2FF            ;START/STOP FLAG (CNTL-1) FOR PAGING
  490.  
  491. ;    PAGE 3 LOCATIONS
  492.  
  493. DCB    =$300            ;DEVICE CONTROL BLOCK
  494. DDEVIC    =$300            ;BUS I.D. NUMBER
  495. DUNIT    =$301            ;UNIT NUMBER
  496. DCOMND    =$302            ;BUS COMMAND
  497. DSTATS    =$303            ;COMMAND TYPE/STATUS RETURN
  498. DBUFLO    =$304            ;DATA BUFFER POINTER
  499. DBUFHI    =$305            ; ...
  500. DTIMLO    =$306            ;DEVICE TIME OUT IN 1 SEC. UNITS
  501. DUNUSE    =$307            ;UNUSED
  502. DBYTLO    =$308            ;BYTE COUNT
  503. DBYTHI    =$309            ; ...
  504. DAUX1    =$30A            ;COMMAND AUXILLARY BYTES
  505. DAUX2    =$30B            ; ...
  506.  
  507. TIMER1    =$30C            ;INITIAL TIMER VALUE
  508. ADDCOR    =$30E            ;ADDITION CORRECTION
  509. CASFLG    =$30F            ;CASSETTE MODE WHEN SET
  510. TIMER2    =$310            ;FINAL TIME VALUE (USED TO COMPUTE BAUD RATE)
  511. TEMP1    =$312            ;TEMP LOCATIONS
  512. TEMP2    =$314            ; ...
  513. TEMP3    =$315            ; ...
  514. SAVIO    =$316            ;SAVE SERIAL IN DATA PORT
  515. TIMFLG    =$317            ;TIME OUT FLAG FOR BAUD RATE CORRECTION
  516. STACKP    =$318            ;SIO STACK POINTER SAVE LOC
  517. TSTAT    =$319            ;TEMP STATUS LOC
  518.  
  519. HATABS    =$31A            ;HANDLER ADDRESS TABLE 
  520. MAXDEV    =$21            ;MAXIMUM HANDLER ADDRESS INDEX
  521.  
  522. ;    IOCB OFFSETS 
  523.  
  524. IOCB    =$340            ;I/O CONTROL BLOCKS
  525. ICHID    =$340            ;HANDLER INDEX ($FF = FREE)
  526. ICDNO    =$341            ;DEVICE NUMBER (DRIVE NUMBER)
  527. ICCOM    =$342            ;COMMAND CODE
  528. ICSTA    =$343            ;STATUS
  529. ICBAL    =$344            ;BUFFER ADDRESS
  530. ICBAH    =$345            ; ...
  531. ICPTL    =$346            ;PUT BYTE ROUTINE ADDRESS - 1
  532. ICPTH    =$347            ; ...
  533. ICBLL    =$348            ;BUFFER LENGTH
  534. ICBLH    =$349            ; ...
  535. ICAX1    =$34A            ;AUXILLARY INFO
  536. ICAX2    =$34B            ; ...
  537. ICSPR    =$34C            ;4 SPARE BYTES
  538.  
  539. PRNBUF    =$3C0            ;PRINTER BUFFER
  540.                 ;($3EA - $3FC SPARE)
  541.  
  542. ;    PAGE 4 LOCATIONS
  543.  
  544. CASBUF    =$3FD            ;CASSETTE BUFFER
  545.  
  546. ; USER AREA STARTS HERE AND GOES TO THE END OF PAGE 5
  547.  
  548. USAREA    =$480
  549.  
  550. ;
  551. ; Other random stuff
  552. ;
  553. CONSOL    =    $D01F        ; console switches start, select, option
  554. ;ATASCII CHARACTER DEFS
  555.  
  556. ATCLR    =$7D            ;CLEAR SCREEN CHARACTER
  557. ATRUB    =$7E            ;BACK SPACE (RUBOUT)
  558. ATTAB    =$7F            ;TAB
  559. ATEOL    =$9B            ;END-OF-LINE
  560. ATDELL    =$9C            ; Delete line
  561. ATBEL    =$FD            ;CONSOLE BELL
  562. ATURW    =$1C            ;UP-ARROW
  563. ATDRW    =$1D            ;DOWN-ARROW
  564. ATLRW    =$1E            ;LEFT-ARROW
  565. ATRRW    =$1F            ;RIGHT-ARROW
  566.  
  567. ; USEFUL VALUES
  568.  
  569. LEDGE    =2            ;LMARGN'S INITIAL VALUE
  570. REDGE    =39            ;RMARGN'S INITIAL VALUE
  571.  
  572. ZPC    =0        ;PC CODE FOR ZERO PAGE PC
  573. P6PC    =1        ;PC CODE FOR PAGE 6
  574. PPC    =2        ;PC CODE FOR PROGRAM MEMORY
  575.  
  576. ;INIT PC VALUES
  577.  
  578. CURPC    =0
  579. PC0    =0        ;PAGE ZERO
  580. PC1    =$600        ;PAGE 6 PC
  581. PC2    =$3800        ;PROGRAM PC
  582. ;
  583. ; End of SYSMAC.SML
  584. ;----------------------------------------------------------------
  585.  
  586. ;.SBTTL    Parser support
  587.  
  588. ;  Define storage for pointers into command buffer. They must be
  589. ;  on zero-page to take advantage of pre- and post-indexed indirect
  590. ;  and also the simulated indirect addressing mode.
  591.  
  592. saddr    =    $80        ; Saved string address - must be on page zero
  593. cm.rty  =    $82        ; Byte pointer to CTRL/R Text
  594. cm.bfp  =    $84        ; Byte pointer to start of text buffer
  595. cm.ptr  =    $86        ; Byte pointer to Next Input to be parsed
  596. cm.inc  =    $88        ; Number of characters left in buffer
  597. cm.cnt  =    $89        ; Space left in buffer
  598. cminf1  =    $8A        ; Information passed to comnd routines
  599. cminf2  =    $8C        ;        ...
  600. cmdptr    =    cminf2        ; Pointer to default for parse
  601. cmkptr  =    $8E        ; Pointer for Cmkeyw routine
  602. cmsptr  =    $90        ; Saved character pointer
  603. cmspt2  =    $92        ; Saved keyword table pointer
  604. cmspt3  =    $94        ; Saved buffer pointer
  605. cmhptr  =    $96        ; Ptr. to current help text
  606. cmptab  =    $98        ; Ptr. to beginning of current keyword table
  607. cmfcb    =    $9A        ; Pointer to FCB
  608. cmehpt    =    $9C        ; Pointer to help commands
  609. ;
  610. ;    other leftover pointers that have to be in page 0
  611. ;
  612. kerbf1  =    $A0        ; This always points to packet buffer
  613. kerbf2    =    $A2        ; This always points to data buffer
  614.  
  615. ;----------------------------------------------------------------
  616. ; pointers we need
  617. ;
  618. source    =    $A4        ;[19] indirect address to be read
  619. dest    =    $A6        ;[19] indirect address to be stored    
  620. strptr    =    $A8        ;[jrd] temp for pointing into strings
  621. count    =    $AC        ;[jrd] count for mbs
  622. tmpptr    =    $AE        ; [jrd] temp for strictly local pointer hacking
  623. ;
  624. ; pointers for pathname parsing stuff
  625. ;
  626. pndptr    =    $B0        ; pathname descriptor ptr
  627. pnddef    =    $B2        ; pathname target ptr, for merging
  628. pnptr    =    $B4        ; pathname txt ptr
  629. pncptr    =    $B6        ; pathname component pointer
  630. ;
  631. ; device names and other atari type data
  632. ;
  633. ;kbdname: .byte    "K:"        ; not used in new kbd driver
  634. ;    .byte    ATEOL
  635. scrname: .byte    "E:"
  636.     .byte    ATEOL
  637. comname: .byte    "R:"
  638.     .byte    ATEOL
  639. comopen: .byte    0        ; flag for com port open
  640. comstat: .byte    0        ; status of com port, from last status op
  641. compend: .word    0        ; count of pending chars from port
  642. ;
  643. ;----------------------------------------------------------------
  644.  
  645. char:    .byte    $00        ;[26] Character just read
  646. stat:    .byte    $00        ;[33] RS232 status byte
  647. lpcnt:    .byte    $00        ;[EL] cursor blink counter
  648. ;lineh:    .byte    $00        ;[19] hires cursor line number
  649. ;colh:    .byte    $00        ;[19] hires cursor column number
  650. ;hilo:    .byte    $F0        ;[19] hires nibble mask
  651. ;rvmask:    .byte    $00        ;[19] reverse video mask ($f=rev, $0=normal)
  652. ;cflag:    .byte    $FF        ;[19] 0 if char under cursor has been reversed
  653. ;cstate:    .byte    $00        ;[19] top nibble of char und. cursor if cflag=0
  654. ;flag79:    .byte    $00        ;[19] non-0 if previous char printed in col 79
  655. ;fla79:    .byte    $00        ;[19] one shot copy of previous flag79
  656. suspend: .byte    $00        ;[24] RS-232 reads suspended if non-zero
  657. fxoff:    .byte    $00        ;[24] Xoff has been sent if non-zero
  658. ;commflg: .byte    $00        ;[24] non-zero if commodore key is depressed
  659.  
  660. .SBTTL    Translation and Font Tables
  661.  
  662. ;    ASCII/ATASCII Translation Tables
  663. ;    These are used for translating file data
  664. ;
  665. ;    At2as:    atascii -> ascii
  666. ;at2as:    .byte    $00    ;[31] ^@ NUL
  667. ;    .byte    $01    ;[31] ^A SOH
  668. ;    .byte    $02    ;[31] ^B 
  669. ;    .byte    $03    ;[31] ^C 
  670. ;    .byte    $04    ;[31] ^D 
  671. ;    .byte    $05    ;[31] ^E 
  672. ;    .byte    $06    ;[31] ^F 
  673. ;    .byte    $07    ;[31] ^G BEL
  674. ;    .byte    $08    ;[31] ^H BS
  675. ;    .byte    $09    ;[31] ^I TAB
  676. ;    .byte    $0a    ;[31] ^J LF
  677. ;    .byte    $0b    ;[31] ^K 
  678. ;    .byte    $0c    ;[31] ^L FF
  679. ;    .byte    $0d    ;[31] ^M CR
  680. ;    .byte    $0e    ;[31] ^N 
  681. ;    .byte    $0f    ;[31] ^O 
  682. ;    .byte    $10    ;[31] ^P 
  683. ;    .byte    $11    ;[31] ^Q 
  684. ;    .byte    $12    ;[31] ^R 
  685. ;    .byte    $13    ;[31] ^S 
  686. ;    .byte    $14    ;[31] ^T
  687. ;    .byte    $15    ;[31] ^U 
  688. ;    .byte    $16    ;[31] ^V 
  689. ;    .byte    $17    ;[31] ^W 
  690. ;    .byte    $18    ;[31] ^X 
  691. ;    .byte    $19    ;[31] ^Y 
  692. ;    .byte    $1a    ;[31] ^Z 
  693. ;    .byte    $1b    ;[31] ^[ 
  694. ;    .byte    $1c    ;[31] ^\ 
  695. ;    .byte    $1d    ;[31] ^] 
  696. ;    .byte    $1e    ;[31] ^^ 
  697. ;    .byte    $1f    ;[31] ^_ 
  698. ;    .byte    $20    ;[31] SPACE
  699. ;    .byte    '!    ;[31] ! 
  700. ;    .byte    '"    ;[31] " 
  701. ;    .byte    '#    ;[31] # 
  702. ;    .byte    '$    ;[31] $ 
  703. ;    .byte    '%    ;[31] % 
  704. ;    .byte    '&    ;[31] & 
  705. ;    .byte    ''    ;[31] ' 
  706. ;    .byte    '(    ;[31] ( 
  707. ;    .byte    ')    ;[31] ) 
  708. ;    .byte    '*    ;[31] * 
  709. ;    .byte    '+    ;[31] + 
  710. ;    .byte    ',    ;[31] , 
  711. ;    .byte    '-    ;[31] - 
  712. ;    .byte    '.    ;[31] . 
  713. ;    .byte    '/    ;[31] / 
  714. ;    .byte    '0    ;[31] 0 
  715. ;    .byte    '1    ;[31] 1 
  716. ;    .byte    '2    ;[31] 2 
  717. ;    .byte    '3    ;[31] 3 
  718. ;    .byte    '4    ;[31] 4 
  719. ;    .byte    '5    ;[31] 5 
  720. ;    .byte    '6    ;[31] 6 
  721. ;    .byte    '7    ;[31] 7 
  722. ;    .byte    '8    ;[31] 8 
  723. ;    .byte    '9    ;[31] 9 
  724. ;    .byte    ':    ;[31] : 
  725. ;    .byte    ';    ;[31] ; 
  726. ;    .byte    '<    ;[31] < 
  727. ;    .byte    '=    ;[31] = 
  728. ;    .byte    '>    ;[31] > 
  729. ;    .byte    '?    ;[31] ? 
  730. ;    .byte    '@    ;[31] @ 
  731. ;    .byte    'A    ;[31] A
  732. ;    .byte    'B    ;[31] B
  733. ;    .byte    'C    ;[31] C
  734. ;    .byte    'D    ;[31] D 
  735. ;    .byte    'E    ;[31] E 
  736. ;    .byte    'F    ;[31] F 
  737. ;    .byte    'G    ;[31] G 
  738. ;    .byte    'H    ;[31] H 
  739. ;    .byte    'I    ;[31] I 
  740. ;    .byte    'J    ;[31] J 
  741. ;    .byte    'K    ;[31] K 
  742. ;    .byte    'L    ;[31] L 
  743. ;    .byte    'M    ;[31] M 
  744. ;    .byte    'N    ;[31] N 
  745. ;    .byte    'O    ;[31] O 
  746. ;    .byte    'P    ;[31] P 
  747. ;    .byte    'Q    ;[31] Q 
  748. ;    .byte    'R    ;[31] R 
  749. ;    .byte    'S    ;[31] S 
  750. ;    .byte    'T    ;[31] T 
  751. ;    .byte    'U    ;[31] U 
  752. ;    .byte    'V    ;[31] V 
  753. ;    .byte    'W    ;[31] W 
  754. ;    .byte    'X    ;[31] X 
  755. ;    .byte    'Y    ;[31] Y 
  756. ;    .byte    'Z    ;[31] Z 
  757. ;    .byte    '[    ;[31] [ 
  758. ;    .byte    '\    ;[31] \ 
  759. ;    .byte    ']    ;[31] ] 
  760. ;    .byte    '^    ;[31] ^ 
  761. ;    .byte    '_    ;[31] _
  762. ;    .byte    $60    ;[31] 
  763. ;    .byte    'a    ;[31] a 
  764. ;    .byte    'b    ;[31] b 
  765. ;    .byte    'c    ;[31] c 
  766. ;    .byte    'd    ;[31] d 
  767. ;    .byte    'e    ;[31] e 
  768. ;    .byte    'f    ;[31] f 
  769. ;    .byte    'g    ;[31] g 
  770. ;    .byte    'h    ;[31] h 
  771. ;    .byte    'i    ;[31] i 
  772. ;    .byte    'j    ;[31] j 
  773. ;    .byte    'k    ;[31] k 
  774. ;    .byte    'l    ;[31] l 
  775. ;    .byte    'm    ;[31] m 
  776. ;    .byte    'n    ;[31] n 
  777. ;    .byte    'o    ;[31] o 
  778. ;    .byte    'p    ;[31] p 
  779. ;    .byte    'q    ;[31] q 
  780. ;    .byte    'r    ;[31] r 
  781. ;    .byte    's    ;[31] s 
  782. ;    .byte    't    ;[31] t 
  783. ;    .byte    'u    ;[31] u 
  784. ;    .byte    'v    ;[31] v 
  785. ;    .byte    'w    ;[31] w 
  786. ;    .byte    'x    ;[31] x 
  787. ;    .byte    'y    ;[31] y 
  788. ;    .byte    'z    ;[31] z 
  789. ;    .byte    '{    ;[31] { 
  790. ;    .byte    '|    ;[31] | 
  791. ;    .byte    '}    ;[31] } 
  792. ;    .byte    '~    ;[31] ~ 
  793. ;    .byte    $7f    ;[31] DEL
  794. ;    .byte    '?    ;[31] illegal
  795. ;    .byte    '?    ;[31]
  796. ;    .byte    '?    ;[31]
  797. ;    .byte    '?    ;[31]
  798. ;    .byte    '?    ;[31]
  799. ;    .byte    '?    ;[31]
  800. ;    .byte    '?    ;[31]
  801. ;    .byte    '?    ;[31]
  802. ;    .byte    '?    ;[31]
  803. ;    .byte    '?    ;[31]
  804. ;    .byte    '?    ;[31]
  805. ;    .byte    '?    ;[31]
  806. ;    .byte    '?    ;[31]
  807. ;    .byte    '?    ;[31]
  808. ;    .byte    '?    ;[31] illegal
  809. ;    .byte    '?    ;[31] illegal
  810. ;    .byte    '?    ;[31] illegal
  811. ;    .byte    '?    ;[31] illegal
  812. ;    .byte    '?    ;[31] illegal
  813. ;    .byte    '?    ;[31] illegal
  814. ;    .byte    '?    ;[31] illegal
  815. ;    .byte    '?    ;[31] illegal
  816. ;    .byte    '?    ;[31] illegal
  817. ;    .byte    '?    ;[31] illegal
  818. ;    .byte    '?    ;[31] illegal
  819. ;    .byte    '?    ;[31] illegal
  820. ;    .byte    '?    ;[31] illegal
  821. ;    .byte    $0D    ; [jrd] atascii EOL -> CR
  822. ;    .byte    '?    ;[31] illegal
  823. ;    .byte    '?    ;[31] illegal
  824. ;    .byte    '?    ;[31] illegal
  825. ;    .byte    '?    ;[31] illegal
  826. ;    .byte    '?    ;[31] illegal
  827. ;    .byte    '?    ;[31] illegal
  828. ;    .byte    '?    ;[31] illegal
  829. ;    .byte    '?    ;[31] illegal
  830. ;    .byte    '?    ;[31] illegal
  831. ;    .byte    '?    ;[31] illegal
  832. ;    .byte    '?    ;[31] illegal
  833. ;    .byte    '?    ;[31] illegal
  834. ;    .byte    '?    ;[31] illegal
  835. ;    .byte    '?    ;[31] illegal
  836. ;    .byte    '?    ;[31] illegal
  837. ;    .byte    '?    ;[31] illegal
  838. ;    .byte    '?    ;[31] illegal
  839. ;    .byte    '?    ;[31] illegal
  840. ;    .byte    '?    ;[31] illegal
  841. ;    .byte    '?    ;[31] illegal
  842. ;    .byte    '?    ;[31] illegal
  843. ;    .byte    '?    ;[31] illegal
  844. ;    .byte    '?    ;[31] illegal
  845. ;    .byte    '?    ;[31] illegal
  846. ;    .byte    '?    ;[31] illegal
  847. ;    .byte    '?    ;[31] illegal
  848. ;    .byte    '?    ;[31] illegal
  849. ;    .byte    '?    ;[31] illegal
  850. ;    .byte    '?    ;[31] illegal
  851. ;    .byte    '?    ;[31] illegal
  852. ;    .byte    '?    ;[31] illegal
  853. ;    .byte    '?    ;[31] illegal
  854. ;    .byte    '?    ;[31] illegal
  855. ;    .byte    '?    ;[31] illegal
  856. ;    .byte    '?    ;[31] illegal
  857. ;    .byte    '?    ;[31] illegal
  858. ;    .byte    '?    ;[31] illegal
  859. ;    .byte    'A    ;[31] A from A key (dup)
  860. ;    .byte    'B    ;[31] B from B key (dup)
  861. ;    .byte    'C    ;[31] C from C key (dup)
  862. ;    .byte    'D    ;[31] D from D key (dup)
  863. ;    .byte    'E    ;[31] E from E key (dup)
  864. ;    .byte    'F    ;[31] F from F key (dup)
  865. ;    .byte    'G    ;[31] G from G key (dup)
  866. ;    .byte    'H    ;[31] H from H key (dup)
  867. ;    .byte    'I    ;[31] I from I key (dup)
  868. ;    .byte    'J    ;[31] J from J key (dup)
  869. ;    .byte    'K    ;[31] K from K key (dup)
  870. ;    .byte    'L    ;[31] L from L key (dup)
  871. ;    .byte    'M    ;[31] M from M key (dup)
  872. ;    .byte    'N    ;[31] N from N key (dup)
  873. ;    .byte    'O    ;[31] O from O key (dup)
  874. ;    .byte    'P    ;[31] P from P key (dup)
  875. ;    .byte    'Q    ;[31] Q from Q key (dup)
  876. ;    .byte    'R    ;[31] R from R key (dup)
  877. ;    .byte    'S    ;[31] S from S key (dup)
  878. ;    .byte    'T    ;[31] T from T key (dup)
  879. ;    .byte    'U    ;[31] U from U key (dup)
  880. ;    .byte    'V    ;[31] V from V key (dup)
  881. ;    .byte    'W    ;[31] W from W key (dup)
  882. ;    .byte    'X    ;[31] X from X key (dup)
  883. ;    .byte    'Y    ;[31] Y from Y key (dup)
  884. ;    .byte    'Z    ;[31] Z from Z key (dup)
  885. ;    .byte    '{    ;[31] { from SHIFT/+ key (dup)
  886. ;    .byte    '|    ;[31] | from ????? (dup)
  887. ;    .byte    '}    ;[31] } from SHIFT/- key (dup)
  888. ;    .byte    '~    ;[31] ~ from SHIFT/^ key (dup)
  889. ;    .byte    $7f    ;[31] DEL from ?????
  890. ;    .byte    $20    ;[31] SPACE from SHIFT/SPACE key (dup)
  891. ;    .byte    '?    ;[31] illegal
  892. ;    .byte    '?    ;[31] illegal
  893. ;    .byte    '?    ;[31] illegal
  894. ;    .byte    '?    ;[31] illegal
  895. ;    .byte    '?    ;[31] illegal
  896. ;    .byte    '?    ;[31] illegal
  897. ;    .byte    '?    ;[31] illegal
  898. ;    .byte    '?    ;[31] illegal
  899. ;    .byte    '?    ;[31] illegal
  900. ;    .byte    '?    ;[31] illegal
  901. ;    .byte    '?    ;[31] illegal
  902. ;    .byte    '?    ;[31] illegal
  903. ;    .byte    '?    ;[31] illegal
  904. ;    .byte    '?    ;[31] illegal
  905. ;    .byte    '?    ;[31] illegal
  906. ;    .byte    '?    ;[31] illegal
  907. ;    .byte    '?    ;[31] illegal
  908. ;    .byte    '?    ;[31] illegal
  909. ;    .byte    '?    ;[31] illegal
  910. ;    .byte    '?    ;[31] illegal
  911. ;    .byte    '?    ;[31] illegal
  912. ;    .byte    '?    ;[31] illegal
  913. ;    .byte    '?    ;[31] illegal
  914. ;    .byte    '?    ;[31] illegal
  915. ;    .byte    '?    ;[31] illegal
  916. ;    .byte    '?    ;[31] illegal
  917. ;    .byte    '?    ;[31] illegal
  918. ;    .byte    '?    ;[31] illegal
  919. ;    .byte    '?    ;[31] illegal
  920. ;    .byte    '?    ;[31] illegal
  921. ;    .byte    '?    ;[31] illegal
  922.  
  923. ;
  924. ; compressed form translate table
  925. ;
  926. xat2as:
  927.     .byte    ATEOL,cr        ; Atascii EOL -> cr
  928.     .byte    ATTAB,tab
  929.     .byte    ATBEL,bel
  930.     .byte    ATRUB,del
  931.     .byte    0
  932.  
  933. ;    As2at - ASCII to ATASCII
  934.  
  935. ;as2at:    .byte    $00    ;[31] NUL
  936. ;    .byte    $01    ;[31] ^A 
  937. ;    .byte    $02    ;[31] ^B 
  938. ;    .byte    $03    ;[31] ^C 
  939. ;    .byte    $04    ;[31] ^D 
  940. ;    .byte    $05    ;[31] ^E 
  941. ;    .byte    $06    ;[31] ^F 
  942. ;    .byte    $07    ;[31] BEL
  943. ;    .byte    $08    ;[31] BS
  944. ;    .byte    $09    ;[31] TAB
  945. ;    .byte    $0a    ;[31] NL
  946. ;    .byte    $0b    ;[31] ^K 
  947. ;    .byte    $0c    ;[31] ^L 
  948. ;    .byte    ATEOL    ;[31] CR 
  949. ;    .byte    $0e    ;[31] ^N 
  950. ;    .byte    $0f    ;[31] ^O 
  951. ;    .byte    $10    ;[31] ^P 
  952. ;    .byte    $11    ;[31] ^Q 
  953. ;    .byte    $12    ;[31] ^R 
  954. ;    .byte    $13    ;[31] ^S 
  955. ;    .byte    $14    ;[31] ^T 
  956. ;    .byte    $15    ;[31] ^U 
  957. ;    .byte    $16    ;[31] ^V 
  958. ;    .byte    $17    ;[31] ^W 
  959. ;    .byte    $18    ;[31] ^X 
  960. ;    .byte    $19    ;[31] ^Y 
  961. ;    .byte    $1a    ;[31] ^Z 
  962. ;    .byte    $1b    ;[31] ^[ 
  963. ;    .byte    $1c    ;[31] ^\ 
  964. ;    .byte    $1d    ;[31] ^] 
  965. ;    .byte    $1e    ;[31] ^^ 
  966. ;    .byte    $1f    ;[31] ^_ 
  967. ;    .byte    $20    ;[31] SPACE
  968. ;    .byte    $21    ;[31] ! 
  969. ;    .byte    $22    ;[31] " 
  970. ;    .byte    $23    ;[31] # 
  971. ;    .byte    $24    ;[31] $ 
  972. ;    .byte    $25    ;[31] % 
  973. ;    .byte    $26    ;[31] & 
  974. ;    .byte    $27    ;[31] ' 
  975. ;    .byte    $28    ;[31] ( 
  976. ;    .byte    $29    ;[31] ) 
  977. ;    .byte    $2a    ;[31] * 
  978. ;    .byte    $2b    ;[31] + 
  979. ;    .byte    $2c    ;[31] , 
  980. ;    .byte    $2d    ;[31] - 
  981. ;    .byte    $2e    ;[31] . 
  982. ;    .byte    $2f    ;[31] / 
  983. ;    .byte    $30    ;[31] 0 
  984. ;    .byte    $31    ;[31] 1 
  985. ;    .byte    $32    ;[31] 2 
  986. ;    .byte    $33    ;[31] 3 
  987. ;    .byte    $34    ;[31] 4 
  988. ;    .byte    $35    ;[31] 5 
  989. ;    .byte    $36    ;[31] 6 
  990. ;    .byte    $37    ;[31] 7 
  991. ;    .byte    $38    ;[31] 8 
  992. ;    .byte    $39    ;[31] 9 
  993. ;    .byte    $3a    ;[31] : 
  994. ;    .byte    $3b    ;[31] ; 
  995. ;    .byte    $3c    ;[31] < 
  996. ;    .byte    $3d    ;[31] = 
  997. ;    .byte    $3e    ;[31] > 
  998. ;    .byte    $3f    ;[31] ? 
  999. ;    .byte    '@     ;[31] @ 
  1000. ;    .byte    'A    ;[31] A
  1001. ;    .byte    'B    ;[31] B
  1002. ;    .byte    'C    ;[31] C
  1003. ;    .byte    'D    ;[31] D 
  1004. ;    .byte    'E    ;[31] E 
  1005. ;    .byte    'F    ;[31] F 
  1006. ;    .byte    'G    ;[31] G 
  1007. ;    .byte    'H    ;[31] H 
  1008. ;    .byte    'I    ;[31] I 
  1009. ;    .byte    'J    ;[31] J 
  1010. ;    .byte    'K    ;[31] K 
  1011. ;    .byte    'L    ;[31] L 
  1012. ;    .byte    'M    ;[31] M 
  1013. ;    .byte    'N    ;[31] N 
  1014. ;    .byte    'O    ;[31] O 
  1015. ;    .byte    'P    ;[31] P 
  1016. ;    .byte    'Q    ;[31] Q 
  1017. ;    .byte    'R    ;[31] R 
  1018. ;    .byte    'S    ;[31] S 
  1019. ;    .byte    'T    ;[31] T 
  1020. ;    .byte    'U    ;[31] U 
  1021. ;    .byte    'V    ;[31] V 
  1022. ;    .byte    'W    ;[31] W 
  1023. ;    .byte    'X    ;[31] X 
  1024. ;    .byte    'Y    ;[31] Y 
  1025. ;    .byte    'Z    ;[31] Z 
  1026. ;    .byte    $5b    ;[31] [ 
  1027. ;    .byte    $5c    ;[31] \ 
  1028. ;    .byte    $5d    ;[31] ] 
  1029. ;    .byte    $5e    ;[31] ^ 
  1030. ;    .byte    $5f    ;[31] _ 
  1031. ;    .byte    $60    ;[31][52]
  1032. ;    .byte    'a    ;[31] a 
  1033. ;    .byte    'b    ;[31] b 
  1034. ;    .byte    'c    ;[31] c 
  1035. ;    .byte    'd    ;[31] d 
  1036. ;    .byte    'e    ;[31] e 
  1037. ;    .byte    'f    ;[31] f 
  1038. ;    .byte    'g    ;[31] g 
  1039. ;    .byte    'h    ;[31] h 
  1040. ;    .byte    'i    ;[31] i 
  1041. ;    .byte    'j    ;[31] j 
  1042. ;    .byte    'k    ;[31] k 
  1043. ;    .byte    'l    ;[31] l 
  1044. ;    .byte    'm    ;[31] m 
  1045. ;    .byte    'n    ;[31] n 
  1046. ;    .byte    'o    ;[31] o 
  1047. ;    .byte    'p    ;[31] p 
  1048. ;    .byte    'q    ;[31] q 
  1049. ;    .byte    'r    ;[31] r 
  1050. ;    .byte    's    ;[31] s 
  1051. ;    .byte    't    ;[31] t 
  1052. ;    .byte    'u    ;[31] u 
  1053. ;    .byte    'v    ;[31] v 
  1054. ;    .byte    'w    ;[31] w 
  1055. ;    .byte    'x    ;[31] x 
  1056. ;    .byte    'y    ;[31] y 
  1057. ;    .byte    'z    ;[31] z 
  1058. ;    .byte    '[    ; [jrd] what to do with these on atari?
  1059. ;    .byte    '|    ;[31][52] | 
  1060. ;    .byte    ']    ;[31][52] }
  1061. ;    .byte    $60    ;[31][52] ~ 
  1062. ;    .byte    ATRUB    ;[31] DEL
  1063.  
  1064.  
  1065. ;
  1066. ; compressed form translate table
  1067. ;
  1068. xas2at:
  1069.     .byte    cr,ATEOL        ; cr -> Atascii EOL
  1070.     .byte    tab,ATTAB
  1071.     .byte    bel,ATBEL
  1072.     .byte    del,ATRUB
  1073.     .byte    0
  1074.  
  1075. ;
  1076. ;    These are used for translating to/from ascii in terminal rtn 
  1077. ;    To - ATASCII to ASCII
  1078. ;
  1079. ;attoas:    .byte    $00    ;[31] ^@ from ^@ key (NUL)
  1080. ;    .byte    $01    ;[31] ^A from ^A key
  1081. ;    .byte    $02    ;[31] ^B from ^B key
  1082. ;    .byte    $03    ; ^C from ^C key
  1083. ;    .byte    $04    ; ^D from ^D key
  1084. ;    .byte    $05    ; ^E from ^E key
  1085. ;    .byte    $06    ; ^F from ^F key
  1086. ;    .byte    $07    ; ^G from ^G key
  1087. ;    .byte    $08    ; ^H from ^H key
  1088. ;    .byte    $09    ; ^I from ^I key
  1089. ;    .byte    $0a    ; ^J from ^J key
  1090. ;    .byte    $0b    ; ^K from ^K key
  1091. ;    .byte    $0c    ; ^L from ^L key
  1092. ;    .byte    $0d    ; ^M from ^M and RETURN keys
  1093. ;    .byte    $0e    ; ^N from ^N key
  1094. ;    .byte    $0f    ; ^O from ^O key
  1095. ;    .byte    $10    ; ^P from ^P key
  1096. ;    .byte    $11    ; ^Q from ^Q and CURS DOWN keys
  1097. ;    .byte    $12    ; ^R from ^R key
  1098. ;    .byte    $13    ; ^S from ^S and HOME keys
  1099. ;    .byte    $14    ; DEL from ^T and DEL keys
  1100. ;    .byte    $15    ; ^U from ^U key
  1101. ;    .byte    $16    ; ^V from ^V key
  1102. ;    .byte    $17    ; ^W from ^W key
  1103. ;    .byte    $18    ; ^X from ^X key
  1104. ;    .byte    $19    ; ^Y from ^Y key
  1105. ;    .byte    $1A    ; ^Z from ^Z key
  1106. ;    .byte    $1B    ; ^[ from ^[ key
  1107. ;    .byte    $1C    ; atari up arrow
  1108. ;    .byte    $1D    ; down arrow
  1109. ;    .byte    $1E    ; left arrow
  1110. ;    .byte    $1F    ; right arrow
  1111. ;    .byte    $20    ; SPACE from SPACE bar
  1112. ;    .byte    '!    ; ! from ! key
  1113. ;    .byte    '"    ; " from " key
  1114. ;    .byte    '#    ; # from # key
  1115. ;    .byte    '$    ; $ from $ key
  1116. ;    .byte    '%    ; % from % key
  1117. ;    .byte    '&    ; & from & key
  1118. ;    .byte    ''    ; ' from ' key
  1119. ;    .byte    '(    ; ( from ( key
  1120. ;    .byte    ')    ; ) from ) key
  1121. ;    .byte    '*    ; * from * key
  1122. ;    .byte    '+    ; + from + key
  1123. ;    .byte    ',    ; , from , key
  1124. ;    .byte    '-    ; - from - key
  1125. ;    .byte    '.    ; . from . key
  1126. ;    .byte    '/    ; / from / key
  1127. ;    .byte    '0    ; 0 from 0 key
  1128. ;    .byte    '1    ; 1 from 1 key
  1129. ;    .byte    '2    ; 2 from 2 key
  1130. ;    .byte    '3    ; 3 from 3 key
  1131. ;    .byte    '4    ; 4 from 4 key
  1132. ;    .byte    '5    ; 5 from 5 key
  1133. ;    .byte    '6    ; 6 from 6 key
  1134. ;    .byte    '7    ; 7 from 7 key
  1135. ;    .byte    '8    ; 8 from 8 key
  1136. ;    .byte    '9    ; 9 from 9 key
  1137. ;    .byte    ':    ; : from : key
  1138. ;    .byte    ';    ; ; from ; key
  1139. ;    .byte    '<    ; < from < key
  1140. ;    .byte    '=    ; = from = key
  1141. ;    .byte    '>    ; > from > key
  1142. ;    .byte    '?    ; ? from ? key
  1143. ;    .byte    '@    ; @ from @ key
  1144. ;    .byte    'A    ; A from A key
  1145. ;    .byte    'B    ; B from B key
  1146. ;    .byte    'C    ; C from C key
  1147. ;    .byte    'D    ; D from D key
  1148. ;    .byte    'E    ; E from E key
  1149. ;    .byte    'F    ; F from F key
  1150. ;    .byte    'G    ; G from G key
  1151. ;    .byte    'H    ; H from H key
  1152. ;    .byte    'I    ; I from I key
  1153. ;    .byte    'J    ; J from J key
  1154. ;    .byte    'K    ; K from K key
  1155. ;    .byte    'L    ; L from L key
  1156. ;    .byte    'M    ; M from M key
  1157. ;    .byte    'N    ; N from N key
  1158. ;    .byte    'O    ; O from O key
  1159. ;    .byte    'P    ; P from P key
  1160. ;    .byte    'Q    ; Q from Q key
  1161. ;    .byte    'R    ; R from R key
  1162. ;    .byte    'S    ; S from S key
  1163. ;    .byte    'T    ; T from T key
  1164. ;    .byte    'U    ; U from U key
  1165. ;    .byte    'V    ; V from V key
  1166. ;    .byte    'W    ; W from W key
  1167. ;    .byte    'X    ; X from X key
  1168. ;    .byte    'Y    ; Y from Y key
  1169. ;    .byte    'Z    ; Z from Z key
  1170. ;    .byte    '[    ; [ from [ key
  1171. ;    .byte    '\    ; \ from POUND key
  1172. ;    .byte    ']    ; ] from ] key
  1173. ;    .byte    '^    ; ^ from ^ key (really UP ARROW)
  1174. ;    .byte    '_    ; _ from _ key
  1175. ;    .byte    $60    ;  SHIFT/* key
  1176. ;    .byte    'a    ; a from a key
  1177. ;    .byte    'b    ; b from b key
  1178. ;    .byte    'c    ; c from c key
  1179. ;    .byte    'd    ; d from d key
  1180. ;    .byte    'e    ; e from e key
  1181. ;    .byte    'f    ; f from f key
  1182. ;    .byte    'g    ; g from g key
  1183. ;    .byte    'h    ; h from h key
  1184. ;    .byte    'i    ; i from i key
  1185. ;    .byte    'j    ; j from j key
  1186. ;    .byte    'k    ; k from k key
  1187. ;    .byte    'l    ; l from l key
  1188. ;    .byte    'm    ; m from m key
  1189. ;    .byte    'n    ; n from n key
  1190. ;    .byte    'o    ; o from o key
  1191. ;    .byte    'p    ; p from p key
  1192. ;    .byte    'q    ; q from q key
  1193. ;    .byte    'r    ; r from r key
  1194. ;    .byte    's    ; s from s key
  1195. ;    .byte    't    ; t from t key
  1196. ;    .byte    'u    ; u from u key
  1197. ;    .byte    'v    ; v from v key
  1198. ;    .byte    'w    ; w from w key
  1199. ;    .byte    'x    ; x from x key
  1200. ;    .byte    'y    ; y from y key
  1201. ;    .byte    'z    ; z from z key
  1202. ;    .byte    '{    ; { from SHIFT/+ key
  1203. ;    .byte    '|    ; | from ?????
  1204. ;    .byte    '}    ; } from SHIFT/- key
  1205. ;    .byte    $7F    ; Atascii RUBOUT
  1206. ;    .byte    $09    ; Atascii TAB
  1207. ;    .byte    '?    ; illegal key
  1208. ;    .byte    '?    ; illegal key
  1209. ;    .byte    '?    ; illegal key
  1210. ;    .byte    '?    ; illegal key
  1211. ;    .byte    '?    ; illegal key
  1212. ;    .byte    '_    ; _ from F1 key
  1213. ;    .byte    $60    ;  F3 key
  1214. ;    .byte    '{    ; { from F5 key
  1215. ;    .byte    $08    ; ^H (BS) from F7 key
  1216. ;    .byte    '|    ; | from F2 key
  1217. ;    .byte    '~    ; ~ from F4 key
  1218. ;    .byte    '}    ; } from F6 key
  1219. ;    .byte    $14    ; ^T from F8 key
  1220. ;    .byte    $0a    ; NL from SHIFT/CR key
  1221. ;    .byte    '?    ; illegal key
  1222. ;    .byte    '?    ; illegal key
  1223. ;    .byte    '?    ; illegal key
  1224. ;    .byte    '?    ; illegal key
  1225. ;    .byte    '?    ; illegal key
  1226. ;    .byte    '?    ; illegal key
  1227. ;    .byte    '?    ; illegal key
  1228. ;    .byte    '?    ; illegal key
  1229. ;    .byte    '?    ; illegal key
  1230. ;    .byte    '?    ; illegal key
  1231. ;    .byte    '?    ; illegal key
  1232. ;    .byte    '?    ; illegal key
  1233. ;    .byte    '?    ; illegal key
  1234. ;    .byte    cr    ; Atascii EOL
  1235. ;    .byte    '?    ; illegal key
  1236. ;    .byte    '?    ; illegal key
  1237. ;    .byte    '?    ; illegal key
  1238. ;    .byte    '?    ; illegal key
  1239. ;    .byte    $20    ; SPACE from SHIFT/SPACE key
  1240. ;    .byte    '?    ; illegal key
  1241. ;    .byte    '?    ; illegal key
  1242. ;    .byte    '?    ; illegal key
  1243. ;    .byte    '?    ; illegal key
  1244. ;    .byte    '?    ; illegal key
  1245. ;    .byte    '?    ; illegal key
  1246. ;    .byte    '?    ; illegal key
  1247. ;    .byte    '?    ; illegal key
  1248. ;    .byte    '?    ; illegal key
  1249. ;    .byte    '?    ; illegal key
  1250. ;    .byte    '?    ; illegal key
  1251. ;    .byte    '?    ; illegal key
  1252. ;    .byte    '?    ; illegal key
  1253. ;    .byte    '?    ; illegal key
  1254. ;    .byte    '?    ; illegal key
  1255. ;    .byte    '?    ; illegal key
  1256. ;    .byte    '?    ; illegal key
  1257. ;    .byte    '?    ; illegal key
  1258. ;    .byte    '?    ; illegal key
  1259. ;    .byte    '?    ; illegal key
  1260. ;    .byte    '?    ; illegal key
  1261. ;    .byte    '?    ; illegal key
  1262. ;    .byte    '?    ; illegal key
  1263. ;    .byte    '?    ; illegal key
  1264. ;    .byte    '?    ; illegal key
  1265. ;    .byte    '?    ; illegal key
  1266. ;    .byte    '?    ; illegal key
  1267. ;    .byte    '?    ; illegal key
  1268. ;    .byte    '?    ; illegal key
  1269. ;    .byte    '?    ; illegal key
  1270. ;    .byte    '?    ; illegal key
  1271. ;    .byte    $60    ;  SHIFT/* key (dup)
  1272. ;    .byte    'A    ; A from A key (dup)
  1273. ;    .byte    'B    ; B from B key (dup)
  1274. ;    .byte    'C    ; C from C key (dup)
  1275. ;    .byte    'D    ; D from D key (dup)
  1276. ;    .byte    'E    ; E from E key (dup)
  1277. ;    .byte    'F    ; F from F key (dup)
  1278. ;    .byte    'G    ; G from G key (dup)
  1279. ;    .byte    'H    ; H from H key (dup)
  1280. ;    .byte    'I    ; I from I key (dup)
  1281. ;    .byte    'J    ; J from J key (dup)
  1282. ;    .byte    'K    ; K from K key (dup)
  1283. ;    .byte    'L    ; L from L key (dup)
  1284. ;    .byte    'M    ; M from M key (dup)
  1285. ;    .byte    'N    ; N from N key (dup)
  1286. ;    .byte    'O    ; O from O key (dup)
  1287. ;    .byte    'P    ; P from P key (dup)
  1288. ;    .byte    'Q    ; Q from Q key (dup)
  1289. ;    .byte    'R    ; R from R key (dup)
  1290. ;    .byte    'S    ; S from S key (dup)
  1291. ;    .byte    'T    ; T from T key (dup)
  1292. ;    .byte    'U    ; U from U key (dup)
  1293. ;    .byte    'V    ; V from V key (dup)
  1294. ;    .byte    'W    ; W from W key (dup)
  1295. ;    .byte    'X    ; X from X key (dup)
  1296. ;    .byte    'Y    ; Y from Y key (dup)
  1297. ;    .byte    'Z    ; Z from Z key (dup)
  1298. ;    .byte    '{    ; { from SHIFT/+ key (dup)
  1299. ;    .byte    '|    ; | from ????? (dup)
  1300. ;    .byte    '}    ; } from SHIFT/- key (dup)
  1301. ;    .byte    '~    ; ~ from SHIFT/^ key (dup)
  1302. ;    .byte    $7f    ; DEL from ?????
  1303. ;    .byte    $20    ; SPACE from SHIFT/SPACE key (dup)
  1304. ;    .byte    '?    ; illegal key
  1305. ;    .byte    '?    ; illegal key
  1306. ;    .byte    '?    ; illegal key
  1307. ;    .byte    '?    ; illegal key
  1308. ;    .byte    '?    ; illegal key
  1309. ;    .byte    '?    ; illegal key
  1310. ;    .byte    '?    ; illegal key
  1311. ;    .byte    '?    ; illegal key
  1312. ;    .byte    '?    ; illegal key
  1313. ;    .byte    '?    ; illegal key
  1314. ;    .byte    '?    ; illegal key
  1315. ;    .byte    '?    ; illegal key
  1316. ;    .byte    '?    ; illegal key
  1317. ;    .byte    '?    ; illegal key
  1318. ;    .byte    '?    ; illegal key
  1319. ;    .byte    '?    ; illegal key
  1320. ;    .byte    '?    ; illegal key
  1321. ;    .byte    '?    ; illegal key
  1322. ;    .byte    '?    ; illegal key
  1323. ;    .byte    '?    ; illegal key
  1324. ;    .byte    '?    ; illegal key
  1325. ;    .byte    '?    ; illegal key
  1326. ;    .byte    '?    ; illegal key
  1327. ;    .byte    '?    ; illegal key
  1328. ;    .byte    '?    ; illegal key
  1329. ;    .byte    '?    ; illegal key
  1330. ;    .byte    '?    ; illegal key
  1331. ;    .byte    '?    ; illegal key
  1332. ;    .byte    '?    ; illegal key
  1333. ;    .byte    '?    ; illegal key
  1334. ;    .byte    '~    ; ~ from SHIFT/^ key (dup)
  1335.  
  1336. ;
  1337. ;    From ASCII to ATASCII (Terminal routine)
  1338. ;
  1339. ;    just use as2at
  1340. ;
  1341. ;astoat:    .byte    $00    ;[31] NUL doesn't print
  1342. ;    .byte    $00    ;[31] ^A doesn't print
  1343. ;    .byte    $00    ;[31] ^B doesn't print
  1344. ;    .byte    $00    ;[31] ^C doesn't print
  1345. ;    .byte    $00    ;[31] ^D doesn't print
  1346. ;    .byte    $00    ;[31] ^E doesn't print
  1347. ;    .byte    $00    ; ^F doesn't print
  1348. ;    .byte    $FD    ; -> Atari bell.  Fix this to use beeper?
  1349. ;    .byte    ATLRW    ; BS prints as CURSOR LEFT
  1350. ;    .byte    ATTAB    ; TAB is special
  1351. ;    .byte    $0A    ; zzz ATDRW    ; NL prints as CURSOR DOWN
  1352. ;    .byte    $00    ; ^K doesn't print
  1353. ;    .byte    $0C    ; ^L doesn't print 
  1354. ;    .byte    ATEOL    ; CR is special
  1355. ;    .byte    $00    ; ^N doesn't print 
  1356. ;    .byte    $00    ; ^O doesn't print
  1357. ;    .byte    $00    ; ^P doesn't print
  1358. ;    .byte    $00    ; ^Q doesn't print
  1359. ;    .byte    $00    ; ^R doesn't print
  1360. ;    .byte    $00    ; ^S doesn't print
  1361. ;    .byte    $00    ; ^T doesn't print
  1362. ;    .byte    $00    ; ^U doesn't print
  1363. ;    .byte    $00    ; ^V doesn't print
  1364. ;    .byte    $00    ; ^W doesn't print
  1365. ;    .byte    $00    ; ^X doesn't print
  1366. ;    .byte    $00    ; ^Y doesn't print
  1367. ;    .byte    $00    ; ^Z doesn't print
  1368. ;    .byte    $1B    ; escape
  1369. ;    .byte    $00    ; ^\ doesn't print
  1370. ;    .byte    $00    ; ^] doesn't print
  1371. ;    .byte    $00    ; ^^ doesn't print
  1372. ;    .byte    $00    ; ^_ doesn't print
  1373. ;    .byte    $20    ; SPACE prints as SPACE 
  1374. ;    .byte    $21    ; ! prints as !
  1375. ;    .byte    $22    ; " prints as "
  1376. ;    .byte    $23    ; # prints as #
  1377. ;    .byte    $24    ; $ prints as $
  1378. ;    .byte    $25    ; % prints as %
  1379. ;    .byte    $26    ; & prints as &
  1380. ;    .byte    $27    ; ' prints as '
  1381. ;    .byte    $28    ; ( prints as (
  1382. ;    .byte    $29    ; ) prints as )
  1383. ;    .byte    $2a    ; * prints as *
  1384. ;    .byte    $2b    ; + prints as +
  1385. ;    .byte    $2c    ; , prints as ,
  1386. ;    .byte    $2d    ; - prints as -
  1387. ;    .byte    $2e    ; . prints as .
  1388. ;    .byte    $2f    ; / prints as /
  1389. ;    .byte    $30    ; 0 prints as 0
  1390. ;    .byte    $31    ; 1 prints as 1
  1391. ;    .byte    $32    ; 2 prints as 2
  1392. ;    .byte    $33    ; 3 prints as 3
  1393. ;    .byte    $34    ; 4 prints as 4
  1394. ;    .byte    $35    ; 5 prints as 5
  1395. ;    .byte    $36    ; 6 prints as 6
  1396. ;    .byte    $37    ; 7 prints as 7
  1397. ;    .byte    $38    ; 8 prints as 8
  1398. ;    .byte    $39    ; 9 prints as 9
  1399. ;    .byte    $3a    ; : prints as :
  1400. ;    .byte    $3b    ; ; prints as ;
  1401. ;    .byte    $3c    ; < prints as <
  1402. ;    .byte    $3d    ; = prints as =
  1403. ;    .byte    $3e    ; > prints as >
  1404. ;    .byte    $3f    ; ? prints as ?
  1405. ;    .byte    $40    ; @ prints as @
  1406. ;    .byte    $41    ; a prints as a
  1407. ;    .byte    $42    ; b prints as b
  1408. ;    .byte    $43    ; c prints as c
  1409. ;    .byte    $44    ; d prints as d
  1410. ;    .byte    $45    ; e prints as e
  1411. ;    .byte    $46    ; f prints as f
  1412. ;    .byte    $47    ; g prints as g
  1413. ;    .byte    $48    ; h prints as h
  1414. ;    .byte    $49    ; i prints as i
  1415. ;    .byte    $4a    ; j prints as j
  1416. ;    .byte    $4b    ; k prints as k
  1417. ;    .byte    $4c    ; l prints as l
  1418. ;    .byte    $4d    ; m prints as m
  1419. ;    .byte    $4e    ; n prints as n
  1420. ;    .byte    $4f    ; o prints as o
  1421. ;    .byte    $50    ; p prints as p
  1422. ;    .byte    $51    ; q prints as q
  1423. ;    .byte    $52    ; r prints as r
  1424. ;    .byte    $53    ; s prints as s
  1425. ;    .byte    $54    ; t prints as t
  1426. ;    .byte    $55    ; u prints as u
  1427. ;    .byte    $56    ; v prints as v
  1428. ;    .byte    $57    ; w prints as w
  1429. ;    .byte    $58    ; x prints as x
  1430. ;    .byte    $59    ; y prints as y
  1431. ;    .byte    $5a    ; z prints as z
  1432. ;    .byte    $5b    ; [ prints as [
  1433. ;    .byte    $5c    ; \ prints as \
  1434. ;    .byte    $5d    ; ] prints as ]
  1435. ;    .byte    $5e    ; ^ prints as ^
  1436. ;    .byte    $5f    ; _ prints as _
  1437. ;    .byte    $60    ; 
  1438. ;    .byte    $61    ; A prints as A
  1439. ;    .byte    $62    ; B prints as B
  1440. ;    .byte    $63    ; C prints as C
  1441. ;    .byte    $64    ; D prints as D
  1442. ;    .byte    $65    ; E prints as E
  1443. ;    .byte    $66    ; F prints as F
  1444. ;    .byte    $67    ; G prints as G
  1445. ;    .byte    $68    ; H prints as H
  1446. ;    .byte    $69    ; I prints as I
  1447. ;    .byte    $6a    ; J prints as J
  1448. ;    .byte    $6b    ; K prints as K
  1449. ;    .byte    $6c    ; L prints as L
  1450. ;    .byte    $6d    ; M prints as M
  1451. ;    .byte    $6e    ; N prints as N
  1452. ;    .byte    $6f    ; O prints as O
  1453. ;    .byte    $70    ; P prints as P
  1454. ;    .byte    $71    ; Q prints as Q
  1455. ;    .byte    $72    ; R prints as R
  1456. ;    .byte    $73    ; S prints as S
  1457. ;    .byte    $74    ; T prints as T
  1458. ;    .byte    $75    ; U prints as U
  1459. ;    .byte    $76    ; V prints as V
  1460. ;    .byte    $77    ; W prints as W
  1461. ;    .byte    $78    ; X prints as X
  1462. ;    .byte    $79    ; Y prints as Y
  1463. ;    .byte    $7a    ; Z prints as Z
  1464. ;    .byte    $7b    ; { prints as {
  1465. ;    .byte    $7c    ; | prints as |
  1466. ;    .byte    $7d    ; } prints as }
  1467. ;    .byte    $7e    ; ~ prints as ~
  1468. ;    .byte    ATRUB    ; -> atascii rubout
  1469.  
  1470. ;
  1471. ;    character translator.
  1472. ;
  1473. ;    calling sequence:
  1474. ;    char to xlate in A
  1475. ;    address of xlate tbl in X,Y
  1476. ;    returns:    xlated char in A
  1477. ;
  1478. xlchar:    .byte    0        ; temp for original byte
  1479. xlate:
  1480.     stx    tmpptr        ; set up xlate table ptr
  1481.     sty    tmpptr+1
  1482.     sta    xlchar        ; store the old data
  1483.     ldy    #0
  1484. xlate1:
  1485.     lda    (tmpptr),y    ; get a 'from' byte
  1486.     beq    xlate9        ; zero, we're done
  1487.     cmp    xlchar        ; match the one we're called with?
  1488.     beq    xlate2        ; yup, go translate it
  1489.     iny            ; bump y for next time
  1490.     iny            ; skip the wrong one
  1491.     jmp    xlate1
  1492. xlate2:
  1493.     iny            ; point at new one
  1494.     lda    (tmpptr),y    ; get get translated one
  1495.     rts            ; and go home
  1496. xlate9:
  1497.     lda    xlchar        ; no translation, just return the original
  1498.     rts
  1499. ;
  1500. ;----------------------------------------------------------------
  1501. ;
  1502. ; pathname parsing stuff.
  1503. ;
  1504. ; a pathname consists of optional device, name, and optional
  1505. ; extension.
  1506. ;
  1507. ; a pathname descriptor is a structure containing three fields,
  1508. ; each of which is a byte of max, a byte of length, and a (max) bytes
  1509. ; of data. they are:
  1510. ;    dev    device spec     (2 bytes)
  1511. ;    name    file name    (8 bytes)
  1512. ;    ext    file type    (3 bytes)
  1513. ;
  1514. ; equates for pathname descriptor block
  1515. ;
  1516. pnd.fl  =    0        ; flags byte
  1517. pnd.dm    =    1        ; dev max, 1 byte
  1518. pnd.ds    =    2        ; dev size, one byte
  1519. pnd.dt    =    3        ; dev text, two bytes
  1520. pnd.nm    =    5        ; name max, 1 byte
  1521. pnd.ns    =    6        ; name size, 1 byte
  1522. pnd.nt    =    7        ; name text, 8 bytes
  1523. pnd.em    =    15        ; ext max
  1524. pnd.es    =    16
  1525. pnd.et    =    17
  1526. pndsiz    =    20        ; total size
  1527. ;
  1528. ; generic component equates
  1529. ;
  1530. pnc.m    =    0        ; max this component
  1531. pnc.s    =    1        ; size this component
  1532. pnc.t    =    2        ; text this component
  1533. ;
  1534. ; bits in flag byte
  1535. ;
  1536. pnf.dp    =    $01        ; dev spec present
  1537. pnf.np    =    $02        ; name present
  1538. pnf.ep    =    $04        ; type present
  1539. pnf.wl    =    $08        ; wild card somewhere
  1540. ;
  1541. ; if we had macros, the macro for building one of these would
  1542. ; look like this:
  1543. ;
  1544. ;    .byte    0        ; flags
  1545. ;    .byte    2        ; dev max
  1546. ;    .byte    0
  1547. ;    .blkb    2
  1548. ;    .byte    8        ; name max
  1549. ;    .byte    0
  1550. ;    .blkb    8
  1551. ;    .byte    3
  1552. ;    .byte    0
  1553. ;    .blkb    3
  1554. ;
  1555. ppnt0:    .byte    0        ; temp for parse-pathname and friends
  1556. ppnt1:    .byte    0
  1557. ppnt2:    .byte    0
  1558. ;
  1559. ;    pncupc:        char-upcase char in A
  1560. ;
  1561. pncupc:
  1562.     cmp    #'a        ; >= 'a ?
  1563.     bcc    pncupc9        ; nope, leave
  1564.     cmp    #'z+1        ; < 'z?
  1565.     bcs    pncupc9        ; nope, leave
  1566.     sec
  1567.     sbc    #$20        ; shift to up case.  (carry's set)
  1568. pncupc9:
  1569.     rts
  1570. ;
  1571. ;    pnclgl:        char in a legal pathname char?
  1572. ;            returns carry set if not legal
  1573. ;
  1574. pnclgl:
  1575.     cmp    #':        ; colon's ok
  1576.     beq    pnclgl9
  1577.     cmp    #'.        ; dot's ok too
  1578.     beq    pnclgl9
  1579.     cmp    #'*        ; star is ok
  1580.     beq    pnclgl9
  1581.     cmp    #'?        ; q-mark is ok
  1582.     beq    pnclgl9
  1583.     cmp    #'0        ; 0..9 is ok
  1584.     bcc    pnclgl8        ;  less, no good
  1585.     cmp    #'9+1
  1586.     bcc    pnclgl9        ; less, ok
  1587.     cmp    #'A        ; alpha?
  1588.     bcc    pnclgl8        ; less is no good
  1589.     cmp    #'Z+1
  1590.     bcc    pnclgl9        ; A..Z's ok
  1591. pnclgl8:
  1592.     sec            ; error return
  1593.     rts
  1594. pnclgl9:
  1595.     clc            ; ok return
  1596.     rts
  1597. ;
  1598. ;    pnfindc:    find a character, in x, in (pnptr), starting
  1599. ;            at y.  returns idx or -1 in y, EQ if found, NEQ
  1600. ;            if not found.  Trashes A
  1601. ;
  1602. pnfindc:
  1603.     stx    ppnt1        ; save char
  1604. pnfindc1:
  1605.     lda    (pnptr),y    ; get a char
  1606.     beq    pnfindc8    ; 0? ok, stop here
  1607.     jsr    pncupc        ; upcase it
  1608.     jsr    pnclgl        ; legal pathname char?
  1609.     bcs    pnfindc8    ; nope, go error
  1610.     cmp    ppnt1        ; compare it
  1611.     beq    pnfindc9    ; got it, return
  1612.     iny            ; next!
  1613.     bne    pnfindc1
  1614. pnfindc8:
  1615.     ldy    #-1        ; return 'not found'
  1616. pnfindc9:
  1617.     rts
  1618. ;
  1619. ;    parsepn::
  1620. ;    grok a pathname string into a pathname descriptor.
  1621. ;    expects pathname string pointed to by x,y, desc in (pndptr).
  1622. ;    pathname string terminated by any non-pathname char.
  1623. ;
  1624. ; this routine copies in one component.  Initial idx in Y, terminating
  1625. ; character in X, component offset in desc in A
  1626. ;
  1627. ;ppndbg1: .byte    "Enter parsepn",ATEOL,0
  1628. ;ppndbg2: .byte    "Leave parsepn",ATEOL,0
  1629. ppnct:    .byte    0        ; terminator char
  1630. ppncf:    .byte    0        ; flags for pathname we're parsing
  1631. ppncpf:    .byte    0        ; flag to set in component we're on
  1632. ppncomp:
  1633.     stx    ppnct        ; save terminator
  1634.     clc            ; first calculate 
  1635.     adc    pndptr        ;  pointer to pathname
  1636.     sta    pncptr        ;  component
  1637.     lda    pndptr+1
  1638.     adc    #0
  1639.     sta    pncptr+1
  1640. ppncp1:
  1641.     lda    (pnptr),y    ; get a char
  1642. ; below?    iny            ; and bump the string idx
  1643.     beq    ppncp9        ; always terminate on nuls
  1644.     cmp    ppnct        ; hit terminator?
  1645.     beq    ppncp8        ; yes, stop this component
  1646.     cmp    #ATEOL        ; eol?
  1647.     beq    ppncp9        ; yes, always terminate on eols, too
  1648.     iny            ; and bump the string idx
  1649.     jsr    pncupc        ; upcase it
  1650.     jsr    pnclgl        ; legal char?
  1651.     bcs    ppncp9        ; nope, stop here
  1652.     cmp    #'*        ; is it one of the wild chars?
  1653.     beq    ppncp2        ; yes, flag it as such
  1654.     cmp    #'?
  1655.     bne    ppncp3
  1656. ppncp2:
  1657.     pha            ; save char
  1658.     lda    #pnf.wl        ; or in the 'wild' flag
  1659.     ora    ppncf
  1660.     sta    ppncf
  1661.     pla            ; get char back
  1662. ppncp3:
  1663.     sty    ppnt0        ; save y for a bit
  1664.     pha            ; save char
  1665.     ldy    #pnc.s        ; component size offset
  1666.     lda    (pncptr),y    ; get component size
  1667. ; check size
  1668.     ldy    #pnc.m        ; component max
  1669.     cmp    (pncptr),y    ; compare size to max
  1670.     bcs    ppncp6        ; too big! ignore this byte
  1671.     ldy    #pnc.s        ; idx for size again
  1672. ;
  1673.     pha            ; save size for later indexing
  1674.     clc            ; add one to it for
  1675.     adc    #1        ;  next time
  1676.     sta    (pncptr),y    ; put it back
  1677.     pla            ; get the old size (index) back
  1678.     clc            ; zap carry again, and
  1679.     adc    #pnc.t        ;  add dev text offset
  1680.     tay            ; into y
  1681.     pla            ; get char back
  1682.     sta    (pncptr),y    ; stuff into dev text
  1683.     lda    ppncpf        ; or in the flag corresponding to 
  1684.     ora    ppncf        ;  this component
  1685.     sta    ppncf
  1686.     jmp    ppncp7        ; and go back for more
  1687. ppncp6:
  1688.     pla            ; throw char away
  1689. ppncp7:
  1690.     ldy    ppnt0        ; get string idx back
  1691.     jmp    ppncp1
  1692. ppncp8:
  1693. ;
  1694. ; found terminator.  Skip it.
  1695.     iny
  1696. ;
  1697. ppncp9:
  1698.     rts
  1699. ;
  1700. ;    The main routine of the pathname parser.
  1701. ;
  1702. parsepn:
  1703.     stx    pnptr        ; set string pointer lo
  1704.     sty    pnptr+1        ;  and hi
  1705. ;zzz debug
  1706. ;    ldx    #ppndbg1\
  1707. ;    ldy    #ppndbg1^
  1708. ;    jsr    pstrnul
  1709. ;zzz
  1710.     lda    #0        ; first zap len flds in desc
  1711.     sta    ppncf        ; and flags in progress
  1712.     ldy    #pnd.ds        ; dev size
  1713.     sta    (pndptr),y    ; zap
  1714.     ldy    #pnd.ns
  1715.     sta    (pndptr),y
  1716.     ldy    #pnd.es
  1717.     sta    (pndptr),y
  1718.     ldy    #0        ; idx into name string
  1719. ppndev:
  1720.     ldx    #':        ; do we have a colon?
  1721.     jsr    pnfindc
  1722.     bmi    ppndev9        ; nope, skip this part
  1723.     lda    #pnf.dp        ; flag to set if we do it
  1724.     sta    ppncpf
  1725.     ldy    #0        ; start at zero please
  1726.     lda    #pnd.dm        ; do device component
  1727.     jsr    ppncomp
  1728.     jmp    ppnnam        ; go do the name
  1729. ppndev9:
  1730.     ldy    #0        ; reset string ptr
  1731. ppnnam:
  1732.     lda    #pnf.np        ; flag to set if we do it
  1733.     sta    ppncpf
  1734.     lda    #pnd.nm        ; do name component
  1735.     ldx    #'.        ; stop at dot
  1736.                 ; y's already set
  1737.     jsr    ppncomp
  1738.     lda    #pnf.ep        ; flag to set if we do it
  1739.     sta    ppncpf
  1740.     lda    #pnd.em        ; extension, please
  1741.     ldx    #ATEOL        ; sort of irrelevant, as we'll stop
  1742.                 ;  on any illegal char.
  1743.     jsr    ppncomp        ; y's already set.
  1744.     lda    ppncf        ; now put in accumulated flags
  1745.     ldy    #pnd.fl
  1746.     sta    (pndptr),y
  1747. ;zzz debug
  1748. ;    ldx    #ppndbg2\
  1749. ;    ldy    #ppndbg2^
  1750. ;    jsr    pstrnul
  1751. ;zzz
  1752.     rts            ; done!
  1753. ;
  1754. ;    pn2str:        (parsed) pathname to string.
  1755. ;            expects a pathname descriptor in (pndptr)
  1756. ;            and a string in X,Y.  Generates a namestring
  1757. ;            terminated by ATEOL, suitable for passing to
  1758. ;            CIO.  Note that it wants a fully qualified
  1759. ;            parsed pathname.
  1760. ;ppndbg3: .byte    "Enter pn2str",ATEOL,0
  1761. ;ppndbg4: .byte    "Leave pn2str",ATEOL,0
  1762. ;
  1763. ; this pushes one byte into output string
  1764. ;
  1765. pn2sp:
  1766.     sty    ppnt2        ; save y value for a bit
  1767.     ldy    ppnt0        ; get string idx
  1768.     sta    (pnptr),y    ; shove the char
  1769. ;zzz debug
  1770. ;    pha            ; save a
  1771. ;    txa            ; save x
  1772. ;    pha
  1773. ;    lda    (pnptr),y    ; get char back
  1774. ;    pha
  1775. ;    lda    #'|
  1776. ;    jsr    prchr
  1777. ;    pla
  1778. ;    jsr    prchr
  1779. ;    pla
  1780. ;    tax
  1781. ;    pla
  1782. ;zzz
  1783.     inc    ppnt0        ; bump the str idx
  1784.     ldy    ppnt2        ; get y back
  1785.     rts
  1786. ;
  1787. ; copy one component into outgoing string.
  1788. ; y contains offset into desc for component text, x contains size
  1789. ;
  1790. pn2scs:
  1791.     lda    (pndptr),y    ; get a char
  1792.     jsr    pn2sp        ; stuff it
  1793.     iny            ; bump dev text idx
  1794.     dex            ; dec size
  1795.     bne    pn2scs        ; back for more
  1796.     rts
  1797. ;
  1798. ; this inits regs, given an initial offset into the descriptor.
  1799. ; returns Z if length 0.
  1800. ;
  1801. pn2sin:
  1802.     lda    (pndptr),y    ; get the component size
  1803. ;zzz debug
  1804. ;    pha
  1805. ;    tya
  1806. ;    pha
  1807. ;    lda    #'#
  1808. ;    jsr    prchr
  1809. ;    pla            ; y val
  1810. ;    pha
  1811. ;    jsr    prbyte
  1812. ;    pla
  1813. ;    pha
  1814. ;    tay
  1815. ;    lda    (pndptr),y
  1816. ;    jsr    prbyte
  1817. ;    pla
  1818. ;    tay
  1819. ;    pla
  1820. ;zzz    
  1821.     iny            ; point y at text
  1822.     tax            ; save it as a counter, set Z for return
  1823.     rts
  1824. ;
  1825. ;    the main routine
  1826. ;
  1827. pn2str:
  1828.     stx    pnptr        ; set pathname string lo
  1829.     sty    pnptr+1        ;  and hi
  1830. ;zzz debug
  1831. ;    ldx    #ppndbg3\
  1832. ;    ldy    #ppndbg3^
  1833. ;    jsr    pstrnul
  1834. ;    lda    pnptr+1
  1835. ;    jsr    prbyte
  1836. ;    lda    pnptr
  1837. ;    jsr    prbyte
  1838. ;zzz
  1839.     ldy    #0        ; string idx
  1840.     sty    ppnt0
  1841.     ldy    #pnd.ds        ; dev component size
  1842.     jsr    pn2sin        ; set up regs
  1843.     beq    pn2str1        ; No dev???  ok, skip it
  1844.     jsr    pn2scs        ; copy a string
  1845.     lda    #':        ; get a colon
  1846.     jsr    pn2sp        ; push it in
  1847. ;
  1848. pn2str1:
  1849.     ldy    #pnd.ns        ; name component size
  1850.     jsr    pn2sin        ; set up
  1851.     beq    pn2str2        ; zero length name?? this should error ...
  1852.     jsr    pn2scs        ; copy it in
  1853. ;
  1854. pn2str2:
  1855.     lda    #'.        ; get a dot
  1856.     jsr    pn2sp        ; push it in
  1857. ;
  1858.     ldy    #pnd.es        ; name component size
  1859.     jsr    pn2sin
  1860.     beq    pn2str3        ; zero length ext?
  1861.     jsr    pn2scs        ; copy it in
  1862. pn2str3:
  1863.     lda    #ATEOL        ; get an eol
  1864.     jsr    pn2sp        ; push it in
  1865. ;zzz debug
  1866. ;    ldx    #ppndbg4\
  1867. ;    ldy    #ppndbg4^
  1868. ;    jsr    pstrnul
  1869. ;zzz
  1870.     rts            ; done!!!
  1871. ;
  1872. ;    pnmerge::    Merge two pathnames.  Move components from the
  1873. ;            first into missing components of the second, ie
  1874. ;        merge "D1:FOO.BAR","CRUD.BAZ" -> "D1:CRUD.BAZ"
  1875. ;
  1876. ;    wants pnddef pointing at pn1, pndptr at pn2
  1877. ;
  1878. pnmc:
  1879.     lda    (pndptr),y    ; get component size in target pathname
  1880.     bne    pnmc9        ; nonzero, try next
  1881.     lda    (pnddef),y    ; ok, get the one we're merging from
  1882.     beq    pnmc9        ; this one zero too?? ok, skip it
  1883.     tax            ; get size in x
  1884.     inx            ; inc to include size byte
  1885. pnmc1:
  1886.     lda    (pnddef),y    ; get a byte
  1887.     sta    (pndptr),y    ; put it in target
  1888.     iny            ; bump component ptr
  1889.     dex            ; dec count
  1890.     bne    pnmc1        ; round again
  1891. pnmc9:
  1892.     rts            ; done with this component
  1893.  
  1894. ;ppndbg5: .byte    "Enter pnmerge",ATEOL,0
  1895. ;ppndbg6: .byte    "Leave pnmerge",ATEOL,0
  1896.  
  1897. pnmerge:
  1898. ;zzz debug
  1899. ;    ldx    #ppndbg5\
  1900. ;    ldy    #ppndbg5^
  1901. ;    jsr    pstrnul
  1902. ;zzz
  1903.     ldy    #pnd.ds        ; look at dev component size
  1904.     jsr    pnmc        ; merge this component
  1905.     ldy    #pnd.ns        ; do name
  1906.     jsr    pnmc        ;  ...
  1907.     ldy    #pnd.es        ; and extension
  1908.     jsr    pnmc
  1909. ;zzz debug
  1910. ;    ldx    #ppndbg6\
  1911. ;    ldy    #ppndbg6^
  1912. ;    jsr    pstrnul
  1913. ;zzz
  1914.     rts            ; done!    
  1915. ;
  1916. ;
  1917. ;-----------------------------------------------------------------
  1918. ;
  1919.  
  1920. ;.SBTTL    Flag definitions
  1921.  
  1922. ;    The following are flags passed in the Y register
  1923.  
  1924. cmfehf    =    1        ;[EL] Extra help available
  1925. cmfdff    =    2        ;[EL] Default value present
  1926.  
  1927. ;.SBTTL    Parse types
  1928.  
  1929. ;    The following are different items to parse for
  1930.  
  1931. cmini    =    0        ; Token to indicate parser init
  1932. cmkey    =    1        ; Token to parse for keyword
  1933. cmifi    =    2        ; Token to parse for input file
  1934. cmofi    =    3        ; Token to parse for output file
  1935. cmcfm    =    4        ; Token to parse for confirm
  1936. cmnum    =    5        ; Token to parse for a number
  1937. cmswi    =    6        ; Token to parse for a switch
  1938. cmfls    =    7        ; Token to parse for a floating-point number
  1939. cmtxt    =    8        ; Token to parse for an unquoted string
  1940. cmtok    =    9        ; Token to parse for a single char token
  1941.  
  1942. ;.SBTTL    COMND package entry points
  1943.  
  1944. ;
  1945. ;    The following addresses are locations in a jump table which
  1946. ;    dispatch to appropriate routines in the Comnd package.
  1947. ;
  1948.  
  1949. mul16    =    comnd+3        ; 16-bit multiply routine
  1950. prcrlf    =    mul16+3        ; Routine to print a crelf
  1951. prstr    =    prcrlf+3    ; Routine to print an ASCIZ string
  1952. rskp    =    prstr+3        ; Routine to skip 3 bytes on return
  1953. setbrk    =    rskp+3        ; Routine to set a break char in brkwrd
  1954. rstbrk    =    setbrk+3    ; Routine to reset break char in brkwrd
  1955.  
  1956. .SBTTL    COMND JSYS routines
  1957.  
  1958. ;
  1959. ;    The following set of routines provides a user oriented way of parsing
  1960. ;    commands. It is similar to that of the COMND JSYS in TOPS-20. For
  1961. ;    convenience, a dispatch table is used.
  1962. ;
  1963.  
  1964. comnd:  jmp    comand        ;  Dispatch to main command routine
  1965.     jmp    ml16        ;  Dispatch to 16-bit multiply routine
  1966.     jmp    prcl.0        ;  Dispatch to Prcrlf
  1967.     jmp    prst.0        ;  Dispatch to Prstr
  1968.     jmp    rskp.0        ;  Dispatch to Rskp
  1969.     jmp    sbrk.0        ;  Dispatch to Setbrk
  1970.     jmp    rbrk.0        ;  Dispatch to Rstbrk
  1971.  
  1972. .SBTTL      Storage Declarations
  1973.  
  1974. ;
  1975. ;    Following is the storage decalarations for the Comnd routines
  1976. ;
  1977.  
  1978. ;cmbuf:  .blkb    $100        ; Input command buffer
  1979. cmbuf    =    scrmemlo    ; why not?
  1980. ;atmbuf:    .blkb    $100        ; Atombuffer, (for cmtxt and cmifil)
  1981. atmbuf    =    scrmemlo+$100
  1982. lenabf:    .byte            ; Length of atom in Atombuffer
  1983. brkwrd:    .blkb    $16        ; Break mask
  1984. savea:  .byte            ;
  1985. savex:  .byte            ;
  1986. savey:  .byte            ;
  1987. cmbase: .byte            ; Base of integer to be parsed
  1988. cmmres: .blkb    4        ; Return value from cmmult call
  1989. cmintg: .blkb    4        ; Return value for cminum call
  1990. cmfltp: .blkb    6        ; Return value for cmflot call
  1991. cmflen: .byte            ; Field length
  1992. ;cmcdrv: .byte            ; Current drive
  1993. cmostp: .word            ; Save area for stack pointer
  1994. cmrprs: .word            ; Reparse address
  1995. cmaflg: .byte            ; Non-zero when an action char has been found
  1996. cmcffl:    .byte            ; Non-Zero when previous command failed
  1997. cmfrcf:    .byte            ; Non-Zero when signif char has been seen
  1998. cmccnt: .byte            ; Non-zero if a significant char is found
  1999. cmocnt:    .byte            ; Saved length of command buffer
  2000. cmoptr:    .word            ; Saved ptr to command buffer for <ctrl/H>
  2001. cmsflg: .byte            ; Non-zero when the last char was a space
  2002. cmstat: .byte            ; Save area for parse type
  2003. cmprmx:    .byte            ; Hold area for Comnd parameters
  2004. cmprmy:    .byte            ; Hold area for Comnd flags
  2005. cmkyln: .byte            ; Keyword length
  2006. cmtlen: .byte            ; Test length (for ?-prompting)
  2007. cmscrs: .byte            ; Screen output switch
  2008. cmentr: .byte            ; Number of remaining entries in table
  2009. cmehix:    .byte            ; Index to extra help command buffer
  2010. keylen: .byte            ; Keyword length
  2011. cmwrk1: .byte            ; Command processing scratch area
  2012. cmwrk2: .byte            ;
  2013. cmwrk3: .byte            ;
  2014. cmwrk4: .byte            ;
  2015.  
  2016. ;----------------------------------------------------------------
  2017. ; Misc Atari support added here by jrd
  2018. ;
  2019.  
  2020. ;
  2021. ;    The new keyboard driver.
  2022. ;    This keyboard stuff is here because of two problems with the
  2023. ;    builtin K: driver; it can't generate all keycodes (the lack of
  2024. ;    a null is especially annoying) and there's no good way to get
  2025. ;    it to generate function key sequences.
  2026. ;    This stuff fixes both those things.  It's also arranged so that 
  2027. ;    returns ascii (not ATASCII) codes for everything.
  2028. ;
  2029. ;    Function key code equates.
  2030. ;
  2031. fnkurw    =    $80        ; up arrow
  2032. fnkdrw    =    $81        ; down arrow
  2033. fnklrw    =    $82        ; left arrow
  2034. fnkrrw    =    $83        ; right arrow
  2035. fnkpf1    =    $84        ; PF1
  2036. fnkpf2    =    $85
  2037. fnkpf3    =    $86
  2038. fnkpf4    =    $87
  2039. fnkk0    =    $88        ; keypad 0
  2040. fnkk1    =    $89
  2041. fnkk2    =    $8A
  2042. fnkk3    =    $8B
  2043. fnkk4    =    $8C
  2044. fnkk5    =    $8D
  2045. fnkk6    =    $8E
  2046. fnkk7    =    $8F
  2047. fnkk8    =    $90
  2048. fnkk9    =    $91
  2049. fnkkdot    =    $92        ; keypad dot
  2050. fnkkmin    =    $93        ; keypad minus
  2051. fnkkcom    =    $94        ; comma
  2052. fnkkent    =    $95        ; enter
  2053. ;
  2054. ; Special functions, handled internally
  2055. ;
  2056. fnksusp =    $C0        ; Suspend
  2057. fnkcpsl    =    $C1        ; Caps lock
  2058. fnkcpul    =    $C2        ; Caps unlock
  2059. ;
  2060. ;    The keypress to char translate table. Data for this is from OS man
  2061. ;    page 50.
  2062. ;
  2063. ;    The control-shift section of this table is used to generate
  2064. ;    function keys for VT100 emulation.  Character value is the
  2065. ;    function key code, above
  2066. ;
  2067. keyxl:
  2068. ; control = 0, shift = 0
  2069.     .byte    'l        ; (00)
  2070.     .byte    'j
  2071.     .byte    ';
  2072.     .byte    $FF        ; not used
  2073.     .byte    $FF        ; not used
  2074.     .byte    'k
  2075.     .byte    '+
  2076.     .byte    '*
  2077.     .byte    'o        ; (08)
  2078.     .byte    $FF        ; not used
  2079.     .byte    'p
  2080.     .byte    'u
  2081.     .byte    cr        ; NB! ascii cr, not ATEOL
  2082.     .byte    'i
  2083.     .byte    '-
  2084.     .byte    '=
  2085.     .byte    'v        ; (10)
  2086.     .byte    $FF        ; not used
  2087.     .byte    'c
  2088.     .byte    $FF        ; not used
  2089.     .byte    $FF        ; not used
  2090.     .byte    'b
  2091.     .byte    'x
  2092.     .byte    'z
  2093.     .byte    '4        ; (18)
  2094.     .byte    $FF        ; not used
  2095.     .byte    '3
  2096.     .byte    '6
  2097.     .byte    $1B
  2098.     .byte    '5
  2099.     .byte    '2
  2100.     .byte    '1
  2101.     .byte    ',        ; (20)
  2102.     .byte    $20
  2103.     .byte    '.
  2104.     .byte    'n
  2105.     .byte    $FF        ; not used
  2106.     .byte    'm
  2107.     .byte    '/
  2108.     .byte    fnksusp        ; atari key
  2109.     .byte    'r        ; (28)
  2110.     .byte    $FF        ; not used
  2111.     .byte    'e
  2112.     .byte    'y
  2113.     .byte    $09        ; tab.  Use ascii tab here
  2114.     .byte    't
  2115.     .byte    'w
  2116.     .byte    'q
  2117.     .byte    '9        ; (30)
  2118.     .byte    $FF        ; not used
  2119.     .byte    '0
  2120.     .byte    '7
  2121.     .byte    $7F        ; backspace. use ascii rubout
  2122.     .byte    '8
  2123.     .byte    '<
  2124.     .byte    '>
  2125.     .byte    'f        ; (38)
  2126.     .byte    'h
  2127.     .byte    'd
  2128.     .byte    $FF        ; not used
  2129.     .byte    fnkcpul        ; caps
  2130.     .byte    'g
  2131.     .byte    's
  2132.     .byte    'a
  2133. ; control = 0, shift = 1
  2134.     .byte    'L        ; (40)
  2135.     .byte    'J
  2136.     .byte    ':
  2137.     .byte    $FF        ; not used
  2138.     .byte    $FF        ; not used
  2139.     .byte    'K
  2140.     .byte    '\        ; sh-+
  2141.     .byte    '^        ; sh-*
  2142.     .byte    'O        ; (48)
  2143.     .byte    $FF        ; not used
  2144.     .byte    'P
  2145.     .byte    'U
  2146.     .byte    ATEOL        ; zzz maybe cr here?
  2147.     .byte    'I
  2148.     .byte    '_        ; sh--
  2149.     .byte    '|        ; sh-=
  2150.     .byte    'V        ; (50)
  2151.     .byte    $FF        ; not used
  2152.     .byte    'C
  2153.     .byte    $FF        ; not used
  2154.     .byte    $FF        ; not used
  2155.     .byte    'B
  2156.     .byte    'X
  2157.     .byte    'Z
  2158.     .byte    '$        ; (18) sh-4
  2159.     .byte    $FF        ; not used
  2160.     .byte    '#        ; sh-3
  2161.     .byte    '&        ; sh-6
  2162.     .byte    $1B        ; shift esc???
  2163.     .byte    '%        ; sh-5
  2164.     .byte    '"        ; sh-2
  2165.     .byte    '!        ; sh-1
  2166.     .byte    '[        ; (20)    sh-,
  2167.     .byte    $20        ; shift space?
  2168.     .byte    ']        ; sh-.
  2169.     .byte    'N
  2170.     .byte    $FF        ; not used
  2171.     .byte    'M
  2172.     .byte    '?        ; sh-/
  2173.     .byte    fnksusp        ; atari key
  2174.     .byte    'R        ; (68)
  2175.     .byte    $FF        ; not used
  2176.     .byte    'E
  2177.     .byte    'Y
  2178.     .byte    $09        ; tab.  Use ascii tab here
  2179.     .byte    'T
  2180.     .byte    'W
  2181.     .byte    'Q
  2182.     .byte    '(        ; (70) sh-9
  2183.     .byte    $FF        ; not used
  2184.     .byte    ')        ; sh-0
  2185.     .byte    ''        ; sh-7
  2186.     .byte    '~        ; backspace. Use this for tilde
  2187.     .byte    '@        ; sh-8
  2188.     .byte    '{        ; shift <
  2189.     .byte    '}        ; shift >
  2190.     .byte    'F        ; (78)
  2191.     .byte    'H
  2192.     .byte    'D
  2193.     .byte    $FF        ; not used
  2194.     .byte    fnkcpsl        ; shift caps
  2195.     .byte    'G
  2196.     .byte    'S
  2197.     .byte    'A
  2198. ; control = 1, shift = 0
  2199.     .byte    $0C        ; (80)    c-l
  2200.     .byte    $0A        ; c-j
  2201.     .byte    ';        ; ???
  2202.     .byte    $FF        ; not used
  2203.     .byte    $FF        ; not used
  2204.     .byte    $0B        ; c-k
  2205.     .byte    $1C        ; c-+ -> c-\
  2206.     .byte    $1E        ; c-* -> c-^
  2207.     .byte    $0F        ; (88) c-o
  2208.     .byte    $FF        ; not used
  2209.     .byte    $10        ; c-p
  2210.     .byte    $15        ; c-u
  2211.     .byte    ATEOL        ; zzz maybe cr here?
  2212.     .byte    $09        ; c-i
  2213.     .byte    $1F        ; c-- -> c-_
  2214.     .byte    $1D        ; c-= -> c-]
  2215.     .byte    $16        ; (90)    c-v
  2216.     .byte    $FF        ; not used
  2217.     .byte    $03        ; c-c
  2218.     .byte    $FF        ; not used
  2219.     .byte    $FF        ; not used
  2220.     .byte    $02        ; c-b
  2221.     .byte    $18        ; c-x
  2222.     .byte    $1A        ; c-z
  2223.     .byte    '4        ; (98) ???
  2224.     .byte    $FF        ; not used
  2225.     .byte    '3        ; ???
  2226.     .byte    '6        ; ???
  2227.     .byte    $1B        ; control esc?
  2228.     .byte    '5        ; ???
  2229.     .byte    '2        ; ???
  2230.     .byte    '1        ; ???
  2231.     .byte    ',        ; (A0)    ???
  2232.     .byte    $00        ; control sp
  2233.     .byte    '.        ; ???
  2234.     .byte    $0E        ; c-n
  2235.     .byte    $FF        ; not used
  2236.     .byte    cr        ; c-m
  2237.     .byte    '/        ; ???
  2238.     .byte    fnksusp        ; atari key
  2239.     .byte    $12        ; (A8)    c-r
  2240.     .byte    $FF        ; not used
  2241.     .byte    $05        ; c-e
  2242.     .byte    $19        ; c-y
  2243.     .byte    $09        ; tab.  Use ascii tab here
  2244.     .byte    $14        ; c-t
  2245.     .byte    $17        ; c-w
  2246.     .byte    $11        ; c-q
  2247.     .byte    '9        ; (B0) ???
  2248.     .byte    $FF        ; not used
  2249.     .byte    '0        ; ???
  2250.     .byte    $60        ; ^7 -> backquote
  2251.     .byte    $60        ; ^backspace -> backquote
  2252.     .byte    '8        ; ???
  2253.     .byte    $1B        ; ^< -> esc
  2254.     .byte    '>        ; ???
  2255.     .byte    $06        ; (B8)    c-f
  2256.     .byte    $08        ; c-h
  2257.     .byte    $04        ; c-d
  2258.     .byte    $FF        ; not used
  2259.     .byte    fnkcpul        ; caps
  2260.     .byte    bel        ; c-g
  2261.     .byte    $13        ; c-s
  2262.     .byte    $01        ; c-a
  2263. ; control = 1, shift = 1
  2264.     .byte    'l        ; (C0)
  2265.     .byte    'j
  2266.     .byte    ';
  2267.     .byte    $FF        ; not used
  2268.     .byte    $FF        ; not used
  2269.     .byte    'k
  2270.     .byte    fnklrw        ; c-sh-+ -> left arrow
  2271.     .byte    fnkrrw        ; c-sh-* -> right arrow
  2272.     .byte    'o        ; (08)
  2273.     .byte    $FF        ; not used
  2274.     .byte    'p
  2275.     .byte    'u
  2276.     .byte    fnkkent        ; c-sh-ret -> keypad enter
  2277.     .byte    'i
  2278.     .byte    fnkurw        ; c-sh-- -> up arrow
  2279.     .byte    fnkdrw        ; c-sh-= -> down arrow
  2280.     .byte    fnkkent        ; (10) c-sh-v -> enter
  2281.     .byte    $FF        ; not used
  2282.     .byte    fnkk3        ; c-sh-c -> kp3
  2283.     .byte    $FF        ; not used
  2284.     .byte    $FF        ; not used
  2285.     .byte    'b
  2286.     .byte    fnkk2        ; c-sh-x -> kp2
  2287.     .byte    fnkk1        ; c-sh-z -> kp1
  2288.     .byte    fnkk4        ; (18) c-sh-4
  2289.     .byte    $FF        ; not used
  2290.     .byte    fnkk3        ; c-sh-3
  2291.     .byte    fnkk6        ; c-sh-6
  2292.     .byte    $1B
  2293.     .byte    fnkk5        ; c-sh-5
  2294.     .byte    fnkk2        ; c-sh-2
  2295.     .byte    fnkk1        ; c-sh-1
  2296.     .byte    fnkkcom        ; (E0) c-sh-comma
  2297.     .byte    fnkk0        ; c-sh-space -> keypad 0
  2298.     .byte    fnkkdot        ; c-sh-.
  2299.     .byte    'n
  2300.     .byte    $FF        ; not used
  2301.     .byte    'm
  2302.     .byte    '/
  2303.     .byte    fnksusp        ; atari key
  2304.     .byte    fnkpf4        ; (E8) c-sh-r -> pf4
  2305.     .byte    $FF        ; not used
  2306.     .byte    fnkpf3        ; c-sh-e
  2307.     .byte    'y
  2308.     .byte    $09        ; tab.  Use ascii tab here
  2309.     .byte    't
  2310.     .byte    fnkpf2        ; c-sh-w
  2311.     .byte    fnkpf1        ; c-sh-q
  2312.     .byte    fnkk9        ; (F0) c-sh-9
  2313.     .byte    $FF        ; not used
  2314.     .byte    fnkk0        ; c-sh-0
  2315.     .byte    fnkk7        ; c-sh-7
  2316.     .byte    $08        ; backspace. use ascii backspace?
  2317.     .byte    fnkk8        ; c-sh-8
  2318.     .byte    fnklrw        ; c-sh-< left arrow
  2319.     .byte    fnkrrw        ; c-sh-> right arrow
  2320.     .byte    fnkkmin        ; (F8)
  2321.     .byte    'h
  2322.     .byte    fnkk6        ; c-sh-d kp6
  2323.     .byte    $FF        ; not used
  2324.     .byte    fnkcpsl        ; caps
  2325.     .byte    'g
  2326.     .byte    fnkk5        ; c-sh-s kp5
  2327.     .byte    fnkk4        ; c-sh-a kp4
  2328. ;
  2329. ; the code that uses the above table.
  2330. ;
  2331. ;    kbdget    -    get a char from keyboard, if any waiting.
  2332. ;            returns char in A
  2333. ;            returns Carry clear if got char, set if not
  2334. ;
  2335. kbdget:    lda    CH
  2336.     cmp    #$FF        ; no char pending?
  2337.     beq    kbdnone        ; nope, give up
  2338.     tax            ; get char in x
  2339.     lda    keyxl,x        ; translate it
  2340. ;
  2341. ; if >= $C0, handled internally, don't return anything
  2342. ;
  2343.     pha
  2344.     and    #$C0        ; mask to 2 hi bits
  2345.     tax            ; save that
  2346.     pla            ; get original back
  2347.     cpx    #$C0        ; internal code?
  2348.     beq    kbdspec        ; yes, handle specially
  2349.     clc
  2350.     jmp    kbdret        ; no, go return this one
  2351. kbdspec:
  2352.     cmp    #fnksusp    ; suspend?
  2353.     bne    kbdspec1    ; nope, ignore it
  2354.     lda    suspend        ; it is; toggle suspend flag
  2355.     eor    #$01
  2356.     sta    suspend
  2357.     jmp    kbdupds
  2358. kbdspec1:
  2359.     cmp    #fnkcpsl    ; caps lock?
  2360.     bne    kbdspec2    ; nope
  2361.     lda    #1
  2362.     sta    capslck        ; lock on
  2363.     jmp    kbdupds        ; update stat line
  2364. kbdspec2:
  2365.     cmp    #fnkcpul    ; caps unlock?
  2366.     bne    kbdnone        ; nope
  2367.     lda    #0
  2368.     sta    capslck        ; lock off
  2369. kbdupds:
  2370.     jsr    updstat        ; update stat line
  2371. kbdnone:
  2372.     sec            ; nope, none here
  2373.     lda    #0
  2374. kbdret:
  2375.     ldx    #$FF        ; zap CH
  2376.     stx    CH
  2377.     bcs    kbd999        ; if no char, just go home
  2378.     cmp    #0        ; function key?
  2379.     bmi    kbd998
  2380.     ldx    capslck        ; caps lock on?
  2381.     beq    kbd998        ; nope, return as is
  2382.     jsr    pncupc        ; borrow pathname rtn
  2383. kbd998:    clc            ; make sure carry clr
  2384. kbd999:    rts            ; and go home with it
  2385.  
  2386. ;
  2387. ;    Function key tables.  All these are 4 bytes long, zero padded,
  2388. ;    for ease of indexing
  2389. ;
  2390. vt100fk:
  2391.     .byte    "[A",0,0    ; up
  2392.     .byte    "[B",0,0    ; down
  2393.     .byte    "[D",0,0    ; left
  2394.     .byte    "[C",0,0    ; right
  2395.     .byte    "OP",0,0    ; pf1
  2396.     .byte    "OQ",0,0
  2397.     .byte    "OR",0,0
  2398.     .byte    "OS",0,0
  2399.     .byte    "Op",0,0    ; kp0
  2400.     .byte    "Oq",0,0
  2401.     .byte    "Or",0,0
  2402.     .byte    "Os",0,0
  2403.     .byte    "Ot",0,0
  2404.     .byte    "Ou",0,0
  2405.     .byte    "Ov",0,0
  2406.     .byte    "Ow",0,0
  2407.     .byte    "Ox",0,0
  2408.     .byte    "Oy",0,0    ; kp9
  2409.     .byte    "On",0,0    ; kp.
  2410.     .byte    "Om",0,0    ; kp-
  2411.     .byte    "Ol",0,0    ; kp,
  2412.     .byte    "OM",0,0    ; enter
  2413. vt52fk:
  2414. ; fill in later
  2415.  
  2416. ;
  2417. ;    fksend:        send an escape seq in terminal mode
  2418. ;            Code in A
  2419. ;            pointer to fk table in x,y
  2420. ;
  2421. fksend:
  2422.     stx    strptr        ; set up pointer to esc data
  2423.     sty    strptr+1
  2424.     and    #$1F        ; trim hi bits
  2425.     asl    A
  2426.     asl    A        ; * 4
  2427.     tay            ; get idx in y
  2428.     lda    #$1B        ; send an escape
  2429.     jsr    putrs
  2430. fksend1:
  2431.     lda    (strptr),y    ; get a char
  2432.     beq    fksend9
  2433.     jsr    putrs        ; send it
  2434.     iny
  2435.     jmp    fksend1        ; round again
  2436. fksend9:
  2437.     rts            ; done!
  2438. ;
  2439. ; end of new kbd code
  2440. ;
  2441.  
  2442. ;
  2443. ; Other handy IO routines
  2444. ;
  2445.  
  2446. ;
  2447. ;    Zap ax1, ax2
  2448. ;
  2449. iozax:    lda    #0
  2450.     sta    ICAX1,X
  2451.     sta    ICAX2,X
  2452.     rts
  2453. ;
  2454. ;    Set BA
  2455. ;
  2456. iosba:    sta    ICBAL,X
  2457.     tya
  2458.     sta    ICBAH,X
  2459.     rts
  2460. ;
  2461. ;    Set BL
  2462. ;
  2463. iosbl:    sta    ICBLL,X
  2464.     tya
  2465.     sta    ICBLH,X
  2466.     rts
  2467. ;
  2468. ; Read a char from IOCB in X
  2469. ;
  2470. chrin:    lda    #GETCHR        ; get raw bytes
  2471.     sta    ICCOM,X        ; in command code
  2472.     lda    #0
  2473.     tay
  2474.     jsr    iosba
  2475.     jsr    iosbl
  2476.     jsr    CIOV        ; go do it
  2477.     rts
  2478. ;
  2479. ; Write a char (in A) to port in X
  2480. ;
  2481. chrout:    pha            ; save the char
  2482.     lda    #PUTCHR        ; put raw bytes
  2483.     sta    ICCOM,X        ; in command code
  2484.     lda    #0
  2485.     tay
  2486.     jsr    iosba
  2487.     jsr    iosbl
  2488.     pla            ; get the char back
  2489.     jsr    CIOV        ; go do it
  2490.     rts
  2491. ;
  2492. ; OPEN a stream; iocb in X, name in A,Y.  Mode already set
  2493. ; return status in Y
  2494. ;
  2495. openiocb:
  2496.     jsr    iosba
  2497.     lda    #OPEN        ; open command
  2498.     sta    ICCOM,X        ; stuff it in
  2499.     lda    #0        ; zap buf len
  2500.     sta    ICBLL,X
  2501.     sta    ICBLH,X
  2502.     jmp    CIOV        ; go do it
  2503. ;
  2504. ; Open for input.  IOCB in X, name in A,Y
  2505. ;
  2506. opencin:
  2507.     pha            ; save name lo
  2508.     lda    #OPNIN        ; get input code
  2509.     sta    ICAX1,X        ; shove in aux 1
  2510.     lda    #0        ; clear 
  2511.     sta    ICAX2,X        ; aux2
  2512.     pla            ; get name ptr back
  2513.     jmp    openiocb    ; go open it
  2514. ;
  2515. ; Similar one for output
  2516. ;
  2517. opencout:
  2518.     pha            ; save name lo
  2519.     lda    #OPNOT        ; get output code
  2520.     sta    ICAX1,X        ; shove in aux 1
  2521.     lda    #0        ; clear 
  2522.     sta    ICAX2,X        ; aux2
  2523.     pla            ; get name ptr back
  2524.     jmp    openiocb    ; go open it
  2525. ;
  2526. ; Similar one for io
  2527. ;
  2528. opencio:
  2529.     pha            ; save name lo
  2530.     lda    #OPNINO        ; get IO code
  2531.     sta    ICAX1,X        ; shove in aux 1
  2532.     lda    #0        ; clear 
  2533.     sta    ICAX2,X        ; aux2
  2534.     pla            ; get name ptr back
  2535.     jmp    openiocb    ; go open it
  2536. ;
  2537. ; And one for dirlists
  2538. ;
  2539. opencdir:
  2540.     pha            ; save name lo
  2541.     lda    #OPNIN!DIRECT    ; get directory please
  2542.     sta    ICAX1,X        ; shove in aux 1
  2543.     lda    #0        ; clear 
  2544.     sta    ICAX2,X        ; aux2
  2545.     pla            ; get name ptr back
  2546.     jmp    openiocb    ; go open it
  2547. ;
  2548. ; Close IOCB, in X
  2549. ;
  2550. closec:
  2551.     lda    #CLOSE        ; close command code
  2552.     sta    ICCOM,X
  2553.     jmp    CIOV        ; go do it
  2554. ;
  2555. ; Open screen iocb to screen.
  2556. ;
  2557. openscr:
  2558.     ldx    #scrchan    ; screen iocb please
  2559.     cpx    #0        ; 0?
  2560.     beq    openscr9    ; yup, atari OS leaves 0 open to E:, so exit
  2561.     lda    #scrname\    ; E:
  2562.     ldy    #scrname^
  2563.     jsr    opencout    ; open for output.
  2564. openscr9:
  2565.     lda    SDLSTL        ; remember display list addr for when we change
  2566.     sta    scraedl
  2567.     lda    SDLSTH
  2568.     sta    scraedl+1
  2569.     rts
  2570. ;
  2571. ; Put a byte to the screen.  char in A.
  2572. ;
  2573. sputch:
  2574.     ldx    #scrchan
  2575.     jmp    chrout
  2576. ;
  2577. ; Out a string to screen, nul terminated.
  2578. ; string pointer in X,Y.  Uses strptr.  Saves all regs
  2579. ;
  2580.     .byte    0        ; temp for y
  2581. pstrnul:
  2582.     pha            ; Save A
  2583.     stx    strptr        ; store lo byte of pointer
  2584.     sty    strptr+1    ;  hi byte
  2585.     txa            ; save x
  2586.     pha
  2587.     tya            ; and y
  2588.     pha
  2589.     ldy    #0
  2590. pstrnul1:
  2591.     lda    (strptr),y    ; get a byte
  2592.     beq    pstrnul9    ; nul, go home
  2593.     sty    pstrnul-1    ; save y
  2594.     cmp    #ATEOL        ; special case these
  2595.     beq    pstrnul2
  2596.     and    #$7F        ; no reverse vid here
  2597.     cmp    #cr        ; special kludge for ascii cr
  2598.     bne    pstrnul2    ; nope, go ahead
  2599.     lda    #ATEOL        ; yup, substitute real EOL
  2600. pstrnul2:
  2601. ;    jsr    sputch        ; go put it out
  2602.     jsr    scrput        ; put it out, general case
  2603.     ldy    pstrnul-1    ; ignore status, get y back
  2604.     iny            ; bump to next char
  2605.     bne    pstrnul1    ; if zero...
  2606.     inc    strptr+1    ;  bump hi word of ptr
  2607.     jmp    pstrnul1
  2608. pstrnul9:
  2609.     pla            ; get y back
  2610.     tay
  2611.     pla            ; get x back
  2612.     tax
  2613.     pla            ; get A back
  2614.     rts            ; all done.
  2615.  
  2616. ;
  2617. ;    Pstreol        Simple-minded version for outputting 
  2618. ;            ATEOL terminated strings.  Doesn't print the EOL.
  2619. ;            string must be shorter than 256.
  2620. ;            Saves A, trashes X,Y
  2621. ;
  2622. pstreol:
  2623.     pha            ; save a
  2624.     stx    strptr        ; set string ptr
  2625.     sty    strptr+1
  2626.     ldy    #0        ; init idx
  2627. pstreol1:
  2628.     lda    (strptr),y    ; get a byte
  2629.     sty    pstrnul-1    ; use that temp, don't need another
  2630.     cmp    #ATEOL        ; eol?
  2631.     beq    pstreol9    ; yes, done
  2632. ;    jsr    sputch        ; out it
  2633.     jsr    scrput        ; put it out, general case
  2634.     ldy    pstrnul-1    ; get y back
  2635.     iny            ; bump
  2636.     bne    pstreol1    ; unless wrap, go back for more
  2637. pstreol9:
  2638.     pla            ; get a back
  2639.     rts            ; home!
  2640.     
  2641. ;
  2642. ;
  2643. ;----------------------------------------------------------------
  2644. .SBTTL    Prompt subroutine
  2645.  
  2646. ;
  2647. ;    This routine prints the prompt for the program and specifies the
  2648. ;    reparse address.
  2649. ;
  2650. ;        Inputs:        X - L.O. byte address of prompt
  2651. ;                Y - H.O. byte address of prompt
  2652. ;
  2653. ;        Outputs:
  2654. ;
  2655. ;        Registers destroyed:    A,X,Y
  2656. ;
  2657.  
  2658. prompt: pla            ; Get Low order byte of return address
  2659.     sta    cmrprs        ; Save that half of reparse address
  2660.     pla            ; Get High order byte
  2661.     sta    cmrprs+1    ; Save the half
  2662.     pha            ; Restore the return
  2663.     lda    cmrprs        ;  address to
  2664.     pha            ;    the stack
  2665.     clc            ; Clear the carry
  2666.     adc    #1        ; Increment this address since it is one
  2667.     sta    cmrprs        ;    short of the desired target.
  2668.     lda    cmrprs+1    ; Account for the carry, if any
  2669.     adc    #0        ;        ...
  2670.     sta    cmrprs+1    ;        ...
  2671.     stx    cm.rty        ; Save the address of the prompt in
  2672.     sty    cm.rty+1    ; pointer to the ctrl/r text
  2673.     tsx            ; Get the stack pointer
  2674.     stx    cmostp        ; Save it for later restoral
  2675.     lda    #cmbuf\        ; Get low order byte of buffer address
  2676.     sta    cm.bfp        ; Init start of text buffer
  2677.     sta    cm.ptr        ; Init next input to be parsed
  2678.     lda    #cmbuf^        ; Get high order byte of buffer address
  2679.     sta    cm.bfp+1    ; H.O. byte of text buffer pointer
  2680.     sta    cm.ptr+1    ; H.O. byte of next input pointer
  2681.     lda    #0        ; Clear AC
  2682.     sta    cmaflg        ; Clear the flags
  2683.     sta    cmccnt        ;
  2684.     sta    cmsflg        ;
  2685.     jsr    prcrlf        ; Print crlf
  2686.     ldx    cm.rty        ; Get L.O. byte of prompt address to be passed
  2687.     ldy    cm.rty+1    ; Get H.O. byte of prompt address
  2688.     jsr    prstr        ; Print the prompt
  2689.     rts            ; Return
  2690.  
  2691. .SBTTL    Repars routine
  2692.  
  2693. ;
  2694. ;    This routine sets stuff up to reparse the current command
  2695. ;    buffer.
  2696. ;
  2697. ;        Input:
  2698. ;
  2699. ;        Output:        Reinitialize comnd pointers and flags
  2700. ;
  2701. ;        Registers destroyed:    A,X
  2702. ;
  2703.  
  2704. repars: ldx    cmostp        ; Fetch old Stack pointer
  2705.     txs            ; Make it the current one
  2706.     lda    #cmbuf\        ; Get L.O. byte address of cmbuf
  2707.     sta    cm.ptr        ; Stuff it
  2708.     lda    #cmbuf^        ; Get H.O. byte address of cmbuf
  2709.     sta    cm.ptr+1    ; The buffer pointer is now reset
  2710.     lda    #0        ; Clear AC
  2711.     sta    cmsflg        ; Clear the space flag
  2712.     jmp    (cmrprs)    ; Jump at the reparse address
  2713.  
  2714. ;.SBTTL    Prserr routine
  2715.  
  2716. ;
  2717. ;    This routine is used when a parsing error occurs. It resets ALL
  2718. ;    of the pointers and flags and then goes to the reparse address.
  2719. ;
  2720. ;        Input:
  2721. ;
  2722. ;        Output:
  2723. ;
  2724. ;        Registers destroyed:
  2725. ;
  2726.  
  2727. prserr:    lda    cm.ptr        ; Store old command line pointer
  2728.     sta    cmoptr        ;        ...
  2729.     lda    cm.ptr+1    ;         ...
  2730.     sta    cmoptr+1    ;         ...
  2731.     lda    cmccnt        ; Store old character count
  2732.     sta    cmocnt        ;        ...
  2733.     lda    #$FF        ; Set the failure flag
  2734.     sta    cmcffl        ;        ...
  2735.     ldx    cmostp        ; Fetch the saved SP
  2736.     txs            ; Make it the current one
  2737.     lda    #cmbuf\        ; Set up the command buffer
  2738.     sta    cm.bfp        ;     address in both the
  2739.     sta    cm.ptr        ;     buffer pointer and the 
  2740.     lda    #cmbuf^        ;    next input pointer.
  2741.     sta    cm.bfp+1    ;        ...
  2742.     sta    cm.ptr+1    ;        ...
  2743.     lda    #0        ; Clear AC
  2744.     sta    cmaflg        ; Zero the action flag
  2745.     sta    cmccnt        ;    the character count
  2746.     sta    cmsflg        ;    and the space flag
  2747.     jsr    prcrlf        ; Print a crelf
  2748.     ldx    cm.rty        ;  Get the address of the prompt
  2749.     ldy    cm.rty+1    ;        ...
  2750.     jsr    prstr        ; Reprint the prompt
  2751.     jmp    (cmrprs)    ; Jump at the reparse address
  2752.  
  2753. .SBTTL    COMND - Entry point for command Jsys stuff
  2754.  
  2755. ;
  2756. ;    COMND routine - This routine checks the code in the AC for
  2757. ;    what parse type is wanted and then dispatches to an appropriate
  2758. ;    routine to look for it. Additional information is located in
  2759. ;    CMINF1 and CMINF2 on page zero.
  2760. ;
  2761. ;        Input:        A - parse type
  2762. ;                X,Y - optional parameters
  2763. ;
  2764. ;        Output:        A - +1 = success
  2765. ;                    +4 = failure (assumes JMP after call)
  2766. ;
  2767. ;        Registers destroyed:    A
  2768. ;
  2769.  
  2770. comand: sta    cmstat        ; Save what we are parsing
  2771.     stx    cmprmx        ; Save these parameters also
  2772.     sty    cmprmy        ;        ...
  2773.     cmp    #cmini        ; Initialize the world?
  2774.     bne    comn0        ; No, handle like a normal parse type
  2775.     jmp    prompt        ; Do the prompt routine to set things up
  2776. comn0:  jsr    cminbf        ; Get characters until action or erase
  2777.     cmp    #cmcfm        ; Parse a confirm?
  2778.     bne    comn1        ; Nope
  2779.     jmp    cmcfrm        ; Yes, try for the confirm
  2780. comn1:  cmp    #cmkey        ; Parse a keyword perhaps?
  2781.     bne    comn2        ; No, next item
  2782.     jmp    cmkeyw        ; Get the keyword
  2783. comn2:  cmp    #cmifi        ; Parse an input file?
  2784.     bne    comn3        ; No, try next one
  2785.     jmp    cmifil        ; Get the input file
  2786. comn3:  cmp    #cmofi        ; Parse an output file?
  2787.     bne    comn4        ; No, try next
  2788.     jmp    cmofil        ; Get the output file
  2789. comn4:  cmp    #cmswi        ; Parse a switch?
  2790.     bne    comn5        ; No, try next again
  2791.     jmp    cmswit        ; Yes, do a switch
  2792. comn5:  cmp    #cmnum        ; Parse an integer?
  2793.     bne    comn6        ; No, try next type
  2794.     jmp    cminum        ; Do the parse integer routine
  2795. comn6:  cmp    #cmfls        ; Parse a floating point?????
  2796.     bne    comn7        ; Nope, thats it for types
  2797.     jmp    cmflot        ; Yes, go get a floating point number
  2798. comn7:    cmp    #cmtxt        ;  Parse for an unquoted string?
  2799.     bne    comn8        ;  Nope, go try last type
  2800.     jmp    cmunqs        ;  Go parse the string
  2801. comn8:    cmp    #cmtok        ;  Parse for a single character?
  2802.     bne    comn9        ;  Nope, no more parse types
  2803.     jmp    cmtokn        ;  Go parse for char
  2804. comn9:  ldx    #cmer00\    ; Error 0 - Bad parse type
  2805.     ldy    #cmer00^
  2806.     jsr    prstr        ; Print the error text
  2807.     lda    #4        ; Fail
  2808.     rts            ; Return to caller
  2809.  
  2810. .SBTTL    Cmcfrm routine - get a confirm
  2811.  
  2812. ;
  2813. ;    This routine tries to get a confirm from the command input
  2814. ;    buffer.
  2815. ;
  2816. ;        Input:  Cm.ptr  - Beginning of next field to be parsed
  2817. ;
  2818. ;        Output: On success, routine skip returns
  2819. ;
  2820. ;        Registers destroyed:    A,X,Y
  2821. ;
  2822.  
  2823. cmcfrm: lda    cm.ptr        ; Save the current comand line pointer
  2824.     pha            ;    on the stack in case the user
  2825.     lda    cm.ptr+1    ;    wants to parse for an alternate item
  2826.     pha            ;
  2827. cmcfr0: jsr    cmgtch        ; Get a character
  2828.     cmp    #0        ; Is it negative?
  2829.     bpl    cmcfrr        ; No, fail
  2830.     and    #$7F        ; Yes, zero the sign bit
  2831.     cmp    #esc        ; An escape?
  2832.     bne    cmcfr2        ; No, continue
  2833.     jsr    bell        ; Sound bell, er
  2834.     lda    #0        ; Clear AC
  2835.     sta    cmaflg        ; Clear the action flag
  2836.     sec            ; Set carry for subtraction
  2837.     lda    cm.bfp        ; Get L.O. byte
  2838.     sbc    #1        ; Decrement it once
  2839.     sta    cm.bfp        ; Store it back
  2840.     sta    cm.ptr        ; Make this pointer look like the other one
  2841.     bcs    cmcfr1        ; If set, we don't have to do H.O. byte
  2842.     dec    cm.bfp+1    ; Adjust H.O. byte
  2843. cmcfr1: lda    cm.bfp+1    ; Move this to H.O. byte of the other pointer
  2844.     sta    cm.ptr+1
  2845.     dec    cmccnt        ; Decrement the character count
  2846.     jmp    cmcfr0        ; Try again.
  2847. cmcfr2: cmp    #'?        ; User need help??
  2848.     bne    cmcfr3        ; Nope
  2849.     jsr    cout        ; Print the '?'
  2850.     ldx    #cmin00\    ; Get address of some help info
  2851.     ldy    #cmin00^    ;
  2852.     jsr    prstr        ; Print it.
  2853.     jsr    prcrlf        ; Print the crelf
  2854.     ldx    cm.rty        ;  Get address of prompt
  2855.     ldy    cm.rty+1    ;
  2856.     jsr    prstr        ; Reprint the prompt
  2857.     lda    #0        ; Clear AC
  2858.     ldy    #0        ; Clear Y
  2859.     sta    (cm.ptr),y    ; Drop null at end of command buffer
  2860.     sec            ; Set carry for subtraction
  2861.     lda    cm.bfp        ; Get L.O. byte
  2862.     sbc    #1        ; Decrement it
  2863.     sta    cm.bfp        ; Store it back
  2864.     lda    cm.bfp+1    ; Now do H.O. byte
  2865.     sbc    #0        ;
  2866.     sta    cm.bfp+1    ;
  2867.     ldx    #cmbuf\        ; Get address of the command buffer
  2868.     ldy    #cmbuf^        ;
  2869.     jsr    prstr        ; Reprint the command line
  2870.     lda    #0        ; Clear AC
  2871.     sta    cmaflg        ; Action flag off
  2872.     jmp    repars        ; Go reparse the line
  2873. cmcfr3: cmp    #ffd        ; Is it a form feed?
  2874.     bne    cmcfr4        ; Nope
  2875.     jsr    scred2        ; Yes, blank the screen
  2876.     ldx    #0
  2877.     ldy    #0
  2878.     jsr    scrplt        ; and home the cursor
  2879. cmcfr4: pla            ; Since this succeeded, we can flush the
  2880.     pla            ;    old command line pointer
  2881.     lda    #0        ;  Reset the failure flag
  2882.     sta    cmcffl        ; 
  2883.     jmp    rskp        ; Do a return skip
  2884.  
  2885. cmcfrr: pla            ;  Restore the old comand line pointer
  2886.     sta    cm.ptr+1    ; 
  2887.     sta    cmoptr+1    ; 
  2888.     pla            ; 
  2889.     sta    cm.ptr        ; 
  2890.     sta    cmoptr        ; 
  2891.     lda    cmccnt        ;  Save count in case of <ctrl/H>
  2892.     sta    cmocnt        ; 
  2893.     lda    #$FF        ;  Set failure
  2894.     sta    cmcffl        ; 
  2895.     rts            ; Return
  2896.  
  2897. .SBTTL    Cmkeyw - Try to parse a keyword next
  2898.  
  2899. ;
  2900. ;    This routine tries to parse a keyword from the table
  2901. ;    pointed to by cminf1. The keywords must be in alphabetical
  2902. ;    order. The routine returns the two bytes of data associated
  2903. ;    with the keyword. The format of the table is as follows:
  2904. ;
  2905. ;    addr:    .byte    n    ; Where n is the # of entries in the table.
  2906. ;        .byte    m    ; m is the size of the next keyword
  2907. ;        .asciz  /string/; keyword ending in a null
  2908. ;        .byte    a,b    ; 16 bits of data related to keyword
  2909. ;
  2910. ;        Input:  Cminf1- Pointer to keyword table
  2911. ;
  2912. ;        Output: X-    byte a
  2913. ;            Y-    byte b
  2914. ;
  2915. ;        Registers destroyed:    A,X,Y
  2916. ;
  2917.  
  2918. cmkeyw: lda    cm.ptr        ; Save the old comand line pointer
  2919.     pha            ;
  2920.     lda    cm.ptr+1
  2921.     pha            ;
  2922.     lda    #0        ;  Clear the 'real character' flag
  2923.     sta    cmfrcf        ; 
  2924.     lda    cminf1        ; Copy to address of
  2925.     sta    cmptab        ;    the keyword table
  2926.     clc            ; Clear the carry
  2927.     adc    #1        ; Add one to the addr. (pass the table length)
  2928.     sta    cmkptr        ; Save the keyword pointer (L.O. byte)
  2929.     lda    cminf1+1    ; Get H.O. byte
  2930.     sta    cmptab+1    ; Save a copy of that
  2931.     bcc    cmkey1        ; Carry?
  2932.     adc    #0        ; Add in the carry for cmkptr
  2933. cmkey1: sta    cmkptr+1    ; Save it
  2934.     ldy    #0        ; Clear Y
  2935.     lda    (cmptab),y    ; Get the table length
  2936.     sta    cmentr        ; Save number of entries in the table
  2937. cmky10:    jsr    cmgtch        ; Get first character
  2938.     cmp    #0        ; Was the first character a terminator?
  2939.     bmi    cmky11        ; Yup, the saved pointer does not get decr.
  2940.     sec            ; Make sure saved buffer pointer is correct
  2941.     lda    cm.ptr        ; Now, reset it back one character for later
  2942.     sbc    #1        ;
  2943.     sta    cm.ptr        ;
  2944.     sta    cmsptr        ;
  2945.     lda    cm.ptr+1    ;
  2946.     sbc    #0        ;
  2947.     sta    cm.ptr+1    ;
  2948.     sta    cmsptr+1    ;
  2949.     jmp    cmkey2        ; Continue
  2950. cmky11: ldy    cm.ptr        ; Just move the pointer to the save area
  2951.     sty    cmsptr        ;
  2952.     ldy    cm.ptr+1    ;
  2953.     sty    cmsptr+1    ;
  2954.     and    #$7F        ;[EL] ????
  2955.     cmp    #esc        ;  Was the first terminator an escape?
  2956.     beq    cmky12        ;  Yes, handle this
  2957.     jmp    cmkey2        ;  No, continue
  2958. cmky12:    lda    #cmfdff        ;  Is there a default?
  2959.     bit    cmprmy        ;         ...
  2960.     bne    cmky13        ;  Yes, go copy it
  2961.     lda    #0        ;  Shut the action flag
  2962.     sta    cmaflg        ;         ...
  2963.     jsr    bell        ;  Yes, start by feeping terminal
  2964.     sec            ;  Set the carry bit for subtraction
  2965.     lda    cm.bfp        ;  Take L.O. byte of buffer pointer
  2966.     sbc    #1        ;  Decrement it (back up before escape)
  2967.     sta    cm.bfp        ;  Store it
  2968.     sta    cm.ptr        ;  And stuff it in next input char pointer
  2969.     bcs    cmkync        ;  If carry is clear, we are done
  2970.     dec    cm.bfp+1    ;  Do the carry on H.O. byte
  2971. cmkync:    lda    cm.bfp+1    ;  Copy this to next char to parse pointer
  2972.     sta    cm.ptr+1    ;         ...
  2973.     jmp    cmky10        ;  Continue by fetching a character again
  2974. cmky13:    lda    #0        ;  Zero the action flag
  2975.     sta    cmaflg        ;         ...
  2976.     jmp    cmcpdf        ;   Do the copy    
  2977. cmkey2: lda    cmentr        ; Get number of entries left
  2978.     cmp    #0        ; 0 entries left?
  2979.     bne    cmky21        ; No, go try next entry
  2980.     pla            ; Fetch back to previous comand line pointer
  2981.     sta    cm.ptr+1    ;        ...
  2982.     sta    cmoptr+1    ;        ...
  2983.     pla            ;        ...
  2984.     sta    cm.ptr        ;        ...
  2985.     sta    cmoptr        ;        ...
  2986.     lda    cmccnt        ; Save count in case of <ctrl/H>
  2987.     sta    cmocnt        ;        ...
  2988.     lda    #$FF        ; Set the command-failure flag
  2989.     sta    cmcffl        ;        ...
  2990.     rts
  2991. cmky21: ldy    #0        ; Clear Y
  2992.     lda    (cmkptr),y    ; Get length of keyword
  2993.     sta    keylen        ; Store it
  2994.     lda    cmkptr        ; Get the new table pointer
  2995.     sta    cmspt2        ;    and save it for later
  2996.     lda    cmkptr+1    ;        ...
  2997.     sta    cmspt2+1    ;        ...
  2998.     inc    cmkptr        ; Increment the L.O. byte once
  2999.     bne    cmkey3        ; If it didn't wrap, there is no carry
  3000.     inc    cmkptr+1    ; There was a carry, add it in.
  3001. cmkey3: dec    keylen        ; Decrement the number of chars. left
  3002.     lda    keylen        ; Get the remaining length
  3003.     cmp    #$FF        ; Have we passed the end
  3004.     bpl    cmk3a        ; No
  3005.     jmp    cmkey5        ; Yes
  3006. cmk3a:  jsr    cmgtch        ; Get a character
  3007.     cmp    #0        ; Is it a terminator?
  3008.     bmi    cmk3b        ; Yup, it is negative
  3009.     jmp    cmkey4        ; Nope, it's positive
  3010. cmk3b:  and    #$7F        ; Shut off the minus bit
  3011.     cmp    #'?        ; Need any help?
  3012.     bne    cmky31        ; Nope
  3013.     jsr    cout        ; And print the question mark
  3014.     lda    #0        ; Clear AC
  3015.     sta    cmaflg        ; Clear the action flag
  3016.     lda    cmstat        ; Get saved parse type
  3017.     cmp    #cmswi        ; Are we really doing a switch?
  3018.     beq    cmk3b1        ; Yes, give that message instead
  3019.     ldx    #cmin01\    ; L.O. byte addr of informational message
  3020.     ldy    #cmin01^    ; H.O. byte of addr
  3021.     jmp    cmk3b2        ; Go print the message
  3022. cmk3b1: ldx    #cmin02\    ; Load address of switch message
  3023.     ldy    #cmin02^    ;        ...
  3024. cmk3b2: jsr    prstr        ; Print the message
  3025.     jsr    prcrlf        ; Print a crelf
  3026.     jsr    cmktp        ;    and the valid entries in keyword table
  3027.     jsr    prcrlf        ; Print another crlf
  3028.     lda    #cmfehf        ;  Load extra help flag
  3029.     bit    cmprmy        ;  Test bit
  3030.     beq    cmk3b3        ;  No extra help
  3031.     jsr    cmehlp        ;  Go give extra help
  3032. cmk3b3:    ldx    cm.rty        ; Get  address of prompt
  3033.     ldy    cm.rty+1    ; 
  3034.     jsr    prstr        ; Reprint the prompt
  3035.     lda    #0        ; Clear AC
  3036.     ldy    #0        ; Clear Y
  3037.     sta    (cm.ptr),y    ; Stuff a null in the buffer at that point
  3038.     sec            ; Set the carry
  3039.     lda    cm.bfp        ; Get ready to decrement buffer pointer
  3040.     sbc    #1        ; Subtract it
  3041.     sta    cm.bfp        ; Store it
  3042.     bcs    cmky3a        ; Do we have to account for carry
  3043.     dec    cm.bfp+1    ; Decrement the H.O. byte
  3044. cmky3a: ldx    #cmbuf\        ; Get  address of buffer
  3045.     ldy    #cmbuf^        ;
  3046.     jsr    prstr        ; Reprint the command line
  3047.     jmp    repars        ; Go reparse all of it
  3048. cmky31: cmp    #esc        ; escape character?
  3049.     beq    cmk3c        ; Yup, process it
  3050.     jmp    cmky35        ; Nope.
  3051. cmk3c:  lda    #0        ; Clear AC
  3052.     sta    cmaflg        ; Clear action flag
  3053.     lda    keylen        ; Save on the stack, the
  3054.     pha            ;    keylength
  3055.     lda    cmentr        ;    number of entries left
  3056.     pha            ;        ...
  3057.     lda    cmkptr        ;    L.O. byte of keyword table pointer
  3058.     pha            ;        ...
  3059.     lda    cmkptr+1    ;    H.O. byte of keyword table pointer
  3060.     pha            ;        ...
  3061.     jsr    cmambg        ; Is it ambiguous?
  3062.      jmp    cmky32        ; Nope
  3063.     lda    #cmfdff        ;  Load the default-present flag
  3064.     bit    cmprmy        ;  Check against flags
  3065.     beq    cmk3d        ;  No, complain to user
  3066.     lda    cmfrcf        ;  Have we seen a real character yet?
  3067.     bne    cmk3d        ;  No, tell user
  3068.     jmp    cmcpdf        ;  Yes, go copy the default
  3069. cmk3d:    jsr    bell        ; Yes, start by feeping terminal
  3070.     sec            ; Set the carry bit for subtraction
  3071.     lda    cm.bfp        ; Take L.O. byte of buffer pointer
  3072.     sbc    #1        ; Decrement it (back up before escape)
  3073.     sta    cm.bfp        ; Store it
  3074.     sta    cm.ptr        ; And stuff it in next input char pointer
  3075.     bcs    cmky3b        ; If carry is clear, we are done
  3076.     dec    cm.bfp+1    ; Do the carry on H.O. byte
  3077. cmky3b: lda    cm.bfp+1    ; Copy this to the next char to parse pointer
  3078.     sta    cm.ptr+1    ;        ...
  3079.     dec    cmccnt        ; Decrement the character count
  3080.     pla            ;        ...
  3081.     sta    cmkptr+1    ; Restore the keyword table pointer
  3082.     pla            ;        ...
  3083.     sta    cmkptr        ;
  3084.     pla            ;
  3085.     sta    cmentr        ;    Number of entries left in table
  3086.     pla            ;        ...
  3087.     sta    keylen        ;    And the remaining keylength
  3088.     inc    keylen        ; Adjust the keylength to make it correct
  3089.     jmp    cmkey3        ; And go back to try again
  3090. cmky32: ldy    #0        ; Clear Y
  3091.     sec            ; Set the carry flag
  3092.     lda    cm.bfp        ; Move buffer pointer behind the escape
  3093.     sbc    #1        ;        ...
  3094.     sta    cm.bfp        ;        ...
  3095.     sta    cm.ptr        ;        ...
  3096.     bcs    cmk32c        ;        ...
  3097.     dec    cm.bfp+1    ; Have to adjust the H.O. byte
  3098. cmk32c: lda    cm.bfp+1    ;        ...
  3099.     sta    cm.ptr+1    ;        ...
  3100.     pla            ; Fetch the old keytable pointer
  3101.     sta    cmkptr+1    ;        ...
  3102.     pla            ;        ...
  3103.     sta    cmkptr        ;        ...
  3104.     pha            ; Now push it back on the stack
  3105.     lda    cmkptr+1    ;        ...
  3106.     pha            ;        ...
  3107. cmky33: lda    (cmkptr),y    ; Get next character
  3108.     cmp    #0        ; Done?
  3109.     beq    cmky34        ; Yes
  3110.     tax            ; No, hold on to the byte
  3111.     clc            ; Clear the carry flag
  3112.     lda    cmkptr        ; Adjust the keyword pointer up one place
  3113.     adc    #1        ; Do L.O. byte
  3114.     sta    cmkptr        ; Store it
  3115.     bcc    cmky3c        ; Carry?
  3116.     inc    cmkptr+1    ; Yes, increment H.O. byte
  3117. cmky3c: txa            ; Get the data
  3118.     sta    (cm.ptr),y    ; Stuff it in the buffer
  3119.     clc            ; Clear the carry flag again
  3120.     lda    cm.ptr        ; Get L.O byte of buffer pointer
  3121.     adc    #1        ; Increment it
  3122.     sta    cm.ptr        ; Store it
  3123.     bcc    cmky3d        ; Carry?
  3124.     inc    cm.ptr+1    ; Increment H.O. byte
  3125. cmky3d: inc    cmccnt        ; Increment character count
  3126.     jmp    cmky33        ; Get next character from table
  3127. cmky34: inc    cmccnt        ; Incrment the character count
  3128.     lda    #$A0        ; Clear AC (this is a terminator!)
  3129.     sta    (cm.ptr),y    ; Stuff a null in the buffer
  3130.     ldx    cm.bfp        ; Get L.O. byte of buffer pointer
  3131.     ldy    cm.bfp+1    ;    and H.O byte - save these for later
  3132.     clc            ; Clear carry
  3133.     lda    cm.ptr        ; Increment next char of input pointer
  3134.     adc    #1        ;        ...
  3135.     sta    cm.ptr        ;        ...
  3136.     sta    cm.bfp        ;        ...
  3137.     bcc    cmky3e        ; Carry?
  3138.     inc    cm.ptr+1    ; Do H.O. byte
  3139. cmky3e: lda    cm.ptr+1    ; Make buffer pointer match next char pointer
  3140.     sta    cm.bfp+1    ;        ...
  3141.     sty    savey        ; Hold y for a bit
  3142.     lda    #0        ; Put a null in the buffer to terminate string
  3143.     ldy    #0        ;        ...
  3144.     sta    (cm.ptr),y    ;        ...
  3145.     ldy    savey        ; Get Y value back
  3146.     jsr    prstr        ; Print remainder of keyword
  3147.     pla            ; Restore the
  3148.     sta    cmkptr+1    ;    H.O. byte of keyword table pointer
  3149.     pla            ;        ...
  3150.     sta    cmkptr        ;     L.O. byte of keyword table pointer
  3151.     pla            ;        ...
  3152.     sta    cmentr        ;    Number of entries left in table
  3153.     pla            ;        ...
  3154.     sta    keylen        ;    And the remaining keylength
  3155.     jmp    cmky37        ; Go get some data to return
  3156. cmky35: lda    cmkptr        ; Save on the stack the  keyword table pointer
  3157.     pha            ;
  3158.     lda    cmkptr+1    ;
  3159.     pha            ;        ...
  3160.     lda    keylen        ;    The keylength
  3161.     pha            ;        ...
  3162.     jsr    cmambg        ; Check for ambiguity
  3163.      jmp    cmky36        ; Not ambiguous
  3164.     ldx    #cmer01\    ; Get addr of ambiguous error
  3165.     ldy    #cmer01^    ;        ...
  3166.     jsr    prstr        ; Print the error message
  3167.     jmp    prserr        ; Go do parsing error stuff
  3168. cmky36: pla            ; Fetch off of the stack 
  3169.     sta    keylen        ;    remaining keylength
  3170.     pla            ;        ...
  3171.     sta    cmkptr+1    ;    H.O. byte of keyword table address
  3172.     pla            ;        ...
  3173.     sta    cmkptr        ;     L.O. byte of keyword table address
  3174. cmky37: inc    keylen        ; Adjust the remaining keylength
  3175.     inc    keylen        ;        ...
  3176.     clc            ; Clear the carry flag
  3177.     lda    cmkptr        ; Get the keyword table pointer
  3178.     adc    keylen        ; Add in remaining keylength
  3179.     sta    cmkptr        ; Store it
  3180.     bcc    cmky3f        ; Carry?
  3181.     inc    cmkptr+1    ; Yes, adjust H.O. byte
  3182. cmky3f: ldy    #0        ; Make sure Y is clear
  3183.     lda    (cmkptr),y    ; Get first data byte
  3184.     tax            ; Put it in X
  3185.     iny            ; Up the index once
  3186.     lda    (cmkptr),y    ; Get the second data byte
  3187.     tay            ; Put that in Y
  3188.     pla            ; Flush the old comand line pointer
  3189.     pla            ;        ...
  3190.     lda    #0        ; Reset the failure flag
  3191.     sta    cmcffl        ; 
  3192.     jmp    rskp        ; Return skip means it succeeds!
  3193. cmkey4: cmp    #$41        ; Check range for upper case
  3194.     bmi    cmky41        ;        ...
  3195.     cmp    #$5b        ;        ...
  3196.     bpl    cmky41        ;        ...
  3197.     ora    #$20        ; Cutesy way to convert to lower case
  3198. cmky41: sta    cmwrk3        ; Save the character
  3199.     lda    #$FF        ;  Set the 'real character' flag
  3200.     sta    cmfrcf        ; 
  3201.     ldy    #0        ; Clear Y again
  3202.     lda    (cmkptr),y    ; Get next keyword byte
  3203.     sta    cmwrk4        ; Hold that for now
  3204.     clc            ; Clear the carry flag
  3205.     lda    cmkptr        ; Get L.O. byte of keyword pointer
  3206.     adc    #1        ; Add one
  3207.     sta    cmkptr        ; Store it
  3208.     bcc    cmky4a        ; Need to do carry?
  3209.     inc    cmkptr+1    ; Yes, do H.O. byte
  3210. cmky4a: lda    cmwrk3        ; Get input character
  3211.     cmp    cmwrk4        ; Does it match keyword character?
  3212.     bne    cmkey5        ; No, advance to next keyword in table
  3213.     jmp    cmkey3        ; Yup, try next input byte
  3214. cmkey5: inc    keylen        ; Adjust keylength so that it is correct
  3215.     inc    keylen        ;        ...
  3216.     inc    keylen        ;        ...
  3217.     clc            ; Clear carry
  3218.     lda    cmkptr        ; Ok, get keyword pointer and
  3219.     adc    keylen        ; Add the remaining keylength
  3220.     sta    cmkptr        ; Store it
  3221.     bcc    cmky5a        ; See if we have to do carry
  3222.     inc    cmkptr+1    ; Yes, increment H.O. byte
  3223. cmky5a: dec    cmentr        ; Decrement the number of entries left
  3224.     lda    cmsptr        ; Get the saved buffer pointer and
  3225.     sta    cm.ptr        ;    restore it
  3226.     lda    cmsptr+1    ;        ...
  3227.     sta    cm.ptr+1    ;        ...
  3228.     jmp    cmkey2        ; Try to parse this keyword now
  3229.  
  3230. .SBTTL    Cmambg - check if keyword prefix is ambiguous
  3231.  
  3232. ;
  3233. ;    This routine looks at the next keyword in the table and
  3234. ;    determines if the prefix entered in the buffer is ambiguous
  3235. ;    or not. If it is ambiguous, it skip returns, otherwise it
  3236. ;    returns normally.
  3237. ;
  3238. ;        Input:  Cmentr- number of entries left in table
  3239. ;            Cmkptr- current keyword table pointer
  3240. ;            Keylen- remaining keyword length
  3241. ;
  3242. ;        Output: If ambiguous, does a skip return
  3243. ;
  3244. ;        Registers destroyed:    A,X,Y
  3245. ;
  3246.  
  3247. cmambg: dec    cmentr        ; Start by decrementing remaining entries
  3248.     bpl    cma1        ; We still have stuff left
  3249.     rts            ; Nothing left, it can't be ambiguous
  3250. cma1:    inc    keylen        ; Adjust this up by one
  3251.     lda    keylen        ; Save character count
  3252.     sta    cmwrk3        ;        ...
  3253.     clc            ; Clear the carry
  3254.     adc    #3        ; Adjust the keylength to include terminator
  3255.     sta    keylen        ;    and data bytes
  3256.     clc            ; Clear carry
  3257.     lda    cmkptr        ; Up the keyword table pointer
  3258.     adc    keylen        ;    by remaining keylength
  3259.     sta    cmkptr        ; Save it
  3260.     bcc    cma2        ; Need to adjust H.O byte?
  3261.     inc    cmkptr+1    ; Yes, do it
  3262. cma2:    ldy    #0        ; Clear Y
  3263.     lda    (cmkptr),y    ; Get keyword length
  3264.     sta    cmwrk4        ; Hold that byte
  3265.     clc            ; Clear carry
  3266.     lda    cmkptr        ; Advance keyword table pointer
  3267.     adc    #1        ;        ...
  3268.     sta    cmkptr        ;        ...
  3269.     bcc    cma3        ;        ...
  3270.     inc    cmkptr+1    ;        ...
  3271. cma3:    lda    (cmspt2),y    ; Get previous keyword length
  3272.     sec            ; Set carry
  3273.     sbc    cmwrk3        ; Subtract number of characters left
  3274.     beq    cmambs        ;  If test len is 0, don't bother trying
  3275.     sta    cmtlen        ; This is the testing length
  3276.     cmp    cmwrk4        ; Check this against length of new keyword
  3277.     bmi    cmamb0        ; This may be ambiguous
  3278.     rts            ; Test length is longer, cannot be ambiguous
  3279. cmamb0: ldy    #0        ; Clear Y
  3280. cmamb1: dec    cmtlen        ; Decrement the length to test
  3281.     bpl    cma4        ; Still characters left to check
  3282. cmambs:    jmp    rskp        ;  The whole thing matched, it is ambiguous
  3283. cma4:    lda    (cmkptr),y    ; Get next character of keyword
  3284.     sta    cmwrk3        ; Hold that for now
  3285.     lda    (cmsptr),y    ; Get next parsed character
  3286.     iny            ; Up the pointer once
  3287.     cmp    #$61        ; Check the range for lower case
  3288.     bmi    cmamb2        ;        ...
  3289.     cmp    #$7B        ;        ...
  3290.     bpl    cmamb2        ;        ...
  3291.     and    #$5F        ; Capitalize it
  3292. cmamb2:    and    #$7F        ; Reset the H.O. bit
  3293.     cmp    cmwrk3        ; Same as keyword table character
  3294.     beq    cmamb1        ; Yup, check next character
  3295.     rts            ; Nope, prefix is not ambiguous
  3296.  
  3297.  
  3298. .SBTTL    Cmktp - print entries in keyword table matching prefix
  3299.  
  3300. ;
  3301. ;    This routine steps through the keyword table passed to cmkeyw
  3302. ;    and prints all the keywords with the prefix currently in the
  3303. ;    command buffer. If there is no prefix, it issues an error.
  3304. ;
  3305. ;        Input:  Cmptab- ptr to beginning of table
  3306. ;            Cmsptr- saved buffer pointer
  3307. ;            Cm.ptr- current buffer pointer
  3308. ;
  3309. ;        Output: List of possible keywords to screen
  3310. ;
  3311. ;        Registers destroyed:    A,X,Y
  3312. ;
  3313.  
  3314. cmktp:  lda    cmptab        ; Get a copy of the pointer
  3315.     sta    cminf2        ;    to the beginning of
  3316.     lda    cmptab+1    ;    the current keyword table
  3317.     sta    cminf2+1    ;        ...
  3318.     ldy    #0        ; Clear Y
  3319.     sty    cmscrs        ; Clear the 'which half of screen' switch
  3320.     sty    cmwrk3        ; Clear the 'print any keywords?' switch
  3321.     lda    (cminf2),y    ; Get the table length
  3322.     sta    cmwrk1        ;    and save it in a safe place
  3323.     sec            ; Prepare for some subtracting
  3324.     lda    cm.ptr        ; Get difference between the current pointer
  3325.     sbc    cmsptr        ;    and pointer to beginning of keyword
  3326.     sta    cmtlen        ; That is how much we must test
  3327.     clc            ; Clear carry
  3328.     lda    cminf2        ; Increment the pointer to the table
  3329.     adc    #1        ;        ...
  3330.     sta    cminf2        ;        ...
  3331.     bcc    cmktp1        ; Need to increment H.O. byte?
  3332.     inc    cminf2+1    ; Yup
  3333. cmktp1: dec    cmwrk1        ; 1 less keyword to do
  3334.     lda    cmwrk1        ; Now...
  3335.     bmi    cmkdon        ; No keywords left, we are done
  3336.     lda    (cminf2),y    ; Get the keyword length
  3337.     sta    cmkyln        ;    and stuff it
  3338.     clc            ; Clear carry
  3339.     lda    cminf2        ; Increment pointer to table again
  3340.     adc    #1        ;        ...
  3341.     sta    cminf2        ;        ...
  3342.     bcc    cmktp2        ; Need to up the H.O. byte?
  3343.     inc    cminf2+1    ; Yup
  3344. cmktp2: lda    cmtlen        ; Get test length
  3345.     beq    cmktp3        ; If test length is zero, just print keyword
  3346. cmkp21: lda    (cminf2),y    ; Get character from table
  3347. ; zzz do case-insensitive compare here
  3348.     cmp    (cmsptr),y    ; Compare it to the buffer character
  3349.     bne    cmadk        ; Nope, advance to next keyword
  3350.     iny            ; Up the index
  3351.     cpy    cmtlen        ; Compare with the test length
  3352.     bmi    cmkp21        ; Not yet, do next character
  3353. cmktp3: jsr    cmprk        ; Print the keyword
  3354.  
  3355. cmadk:  inc    cmkyln        ; Adjust cmkyln to include terminator and data
  3356.     inc    cmkyln        ;        ...
  3357.     inc    cmkyln        ;        ...
  3358.     clc            ; Clear the carry
  3359.     lda    cminf2        ; Get the L.O. byte
  3360.     adc    cmkyln        ; Add in the keyword length
  3361.     sta    cminf2        ; Store it away
  3362.     bcc    cmadk2        ; Need to do the H.O. byte?
  3363.     inc    cminf2+1    ; Yup
  3364. cmadk2: ldy    #0        ; Zero the index
  3365.     jmp    cmktp1        ; Go back to the top of the loop
  3366.  
  3367. cmkdon: lda    cmwrk3        ; See if we printed anything
  3368.     bne    cmkdn2        ; Yup, go exit
  3369.     lda    cmstat        ; Are we parsing switches or keywords?
  3370.     cmp    #cmswi        ;        ...
  3371.     beq    cmkdse        ; The error should be for switches
  3372.     ldx    #cmer03\    ; Nope, get address of error message
  3373.     ldy    #cmer03^    ;        ...
  3374.     jmp    cmkdn1        ; Go print the message now
  3375. cmkdse: ldx    #cmer04\    ; Get address of switch error message
  3376.     ldy    #cmer04^    ;        ...
  3377. cmkdn1: jsr    prstr        ; Print error
  3378.     jsr    prcrlf        ; Print a crelf
  3379. cmkdn2: lda    cmscrs        ; Where did we end up?
  3380.     beq    cmkdn3        ; Beginning of line, good
  3381.     jsr    prcrlf        ; Print a crelf
  3382. cmkdn3: rts            ; Return
  3383.  
  3384. ;
  3385. ;    Cmprk - prints one keyword from the table. Consults the
  3386. ;        cmscrs switch to see which half of the line it
  3387. ;        is going to and acts accordingly.
  3388. ;
  3389. ;        Input:  Cmscrs- Which half of screen
  3390. ;            Cminf2- Pointer to string to print
  3391. ;
  3392. ;        Output: print keyword on screen
  3393. ;
  3394. ;        Registers destroyed:    A,X,Y
  3395. ;
  3396.  
  3397. cmprk:  lda    #on        ; Make sure to tell them we printed something
  3398.     sta    cmwrk3        ; Put it back
  3399.     lda    cmstat        ; Get saved parse type
  3400.     cmp    #cmswi        ; Is it a switch we are looking for?
  3401.     bne    cmpr2        ;
  3402.     lda    #'/        ; Yes, do not forget slash prefix
  3403.     jsr    cout        ; Print slash
  3404. cmpr2:  ldx    cminf2        ; L.O. byte of string pointer
  3405.     ldy    cminf2+1    ; H.O. byte of string pointer
  3406.     jsr    prstr        ; Print the keyword
  3407.     lda    cmscrs        ; Where were we?
  3408.     bne    cmprms        ; Mid screen
  3409.     jsr    screl0        ; Clear to end of line
  3410.     sec            ;[37] Get cursor coordinates
  3411.     jsr    ploth        ;[37]        ...
  3412. ;    ldy    #$14        ; Advance cursor to middle of screen
  3413.     ldx    #$14        ; Advance cursor to middle of screen
  3414.     clc            ;[DD]        ...
  3415.     jsr    ploth        ;[DD][26]    ...
  3416.     jmp    cmprdn        ; We are done
  3417. cmprms: jsr    prcrlf        ; Print a crelf
  3418. cmprdn: lda    cmscrs        ; Flip the switch now
  3419.     eor    #$01
  3420.     sta    cmscrs        ; Stuff it back
  3421.     rts            ; Return
  3422.  
  3423. .SBTTL    Cmswit - try to parse a switch next
  3424.  
  3425. ;
  3426. ;    This routine tries to parse a switch from the command buffer. It
  3427. ;    first looks for the / and then calls cmkeyw to handle the keyword
  3428. ;    lookup.
  3429. ;
  3430. ;        Input:  Cminf1- Address of keyword table
  3431. ;
  3432. ;        Output: X-    byte a
  3433. ;            Y-    byte b
  3434. ;
  3435. ;        Registers destroyed:    A,X,Y
  3436. ;
  3437. ; well, this is pretty gross.  This sucker appears never to be
  3438. ; called; undoubtedly cause this is a general purpose command parser
  3439. ; from elsewhere.  I'm leaving the code here, but commented out in
  3440. ; case anyone ever wants to use it;
  3441. cmswit: brk            ; [jrd] you better put it back before
  3442.                 ;  trying to use it
  3443. ;    lda    cm.ptr        ; Save the old comand line pointer
  3444. ;    pha            ;    user wants to try another item
  3445. ;    lda    cm.ptr+1    ;        ...
  3446. ;    pha            ;        ...
  3447. ;cmswi0: jsr    cmgtch        ; Go get a character
  3448. ;    cmp    #0        ; Action?
  3449. ;    bmi    cmswi1        ; Yes, process it
  3450. ;    jmp    cmswi3        ; No, it is a real character
  3451. ;cmswi1: and    #$7F        ; Turn off the minus
  3452. ;    cmp    #'?        ; Does the user need help?
  3453. ;    bne    cmsw12        ; No
  3454. ;    jsr    cout        ; And print the question mark
  3455. ;    lda    #0        ; Clear AC
  3456. ;    sta    cmaflg        ; Clear Action flag
  3457. ;    ldx    #cmin02\    ; Low order byte addr of info message
  3458. ;    ldy    #cmin02^    ; High order byte addr of info message
  3459. ;    jsr    prstr        ; Print the message
  3460. ;    jsr    prcrlf        ; Print a crelf
  3461. ;    jsr    cmktp        ; Any valid entries from keyword table
  3462. ;    jsr    prcrlf        ; And another crelf
  3463. ;    lda    #cmfehf        ;  Load extra help flag
  3464. ;    bit    cmprmy        ;  Test bit
  3465. ;    beq    cmsw10        ;  No extra help
  3466. ;    jsr    cmehlp        ;  Go give extra help
  3467. ;cmsw10:    ldx    cm.rty        ; Load the address of the prompt
  3468. ;    ldy    cm.rty+1    ;
  3469. ;    jsr    prstr        ; Reprint it
  3470. ;    lda    #0        ; Clear AC
  3471. ;    ldy    #0        ; Clear Y
  3472. ;    sta    (cm.ptr),y    ; Stuff a null at the end of the buffer
  3473. ;    sec            ; Set the carry flag
  3474. ;    lda    cm.bfp        ; Increment buffer pointer
  3475. ;    sbc    #1        ;        ...
  3476. ;    sta    cm.bfp        ;        ...
  3477. ;    bcs    cmsw1a        ; Borrow?
  3478. ;    dec    cm.bfp+1    ; Yup
  3479. ;cmsw1a: ldx    #cmbuf\        ; L.O. addr of command buffer
  3480. ;    ldy    #cmbuf^        ; H.O. byte
  3481. ;    jsr    prstr        ; Reprint the command line
  3482. ;    jmp    repars        ; Go reparse everything
  3483. ;cmsw12: cmp    #esc        ; Lazy??
  3484. ;    beq    cmsw2a        ; Yes, try to help
  3485. ;    jmp    cmswi2        ; No, this is something else
  3486. ;cmsw2a: lda    #0        ; Clear AC
  3487. ;    sta    cmaflg        ; Clear action flag
  3488. ;    lda    #cmfdff        ;  See if there is a default
  3489. ;    bit    cmprmy        ; 
  3490. ;    beq    cmswnd        ;  No help, tell user
  3491. ;    jmp    cmcpdf        ;  Go copy the default
  3492. ;cmswnd:    jsr    bell        ; Yes, it is ambiguous - ring bell
  3493. ;    sec            ; Set carry
  3494. ;    lda    cm.bfp        ; Decrement buffer pointer
  3495. ;    sbc    #1        ;        ...
  3496. ;    sta    cm.bfp        ;        ...
  3497. ;    sta    cm.ptr        ; Make this pointer point there too
  3498. ;    bcs    cmsw2b        ; No carry to handle
  3499. ;    dec    cm.bfp+1    ; Do H.O. byte
  3500. ;cmsw2b: lda    cm.bfp+1    ; Now make H.O. byte match
  3501. ;    sta    cm.ptr+1    ;        ...
  3502. ;    dec    cmccnt        ; Decrement the character count
  3503. ;    jmp    cmswi0        ; Try again
  3504. ;cmsw2c: lda    #'/        ; Load a slash
  3505. ;    jsr    cout        ; Print slash
  3506. ;    clc            ; Clear carry
  3507. ;    lda    cminf1        ; Set the keyword table pointer
  3508. ;    adc    #2        ;    to point at the beginning
  3509. ;    sta    cmkptr        ;    of the keyword and move it
  3510. ;    lda    cminf1+1    ;    to cmkptr
  3511. ;    bcc    cmsw2d        ;        ...
  3512. ;    adc    #0        ;        ...
  3513. ;cmsw2d: sta    cmkptr+1    ;        ...
  3514. ;    ldy    #0        ; Clear Y
  3515. ;    sec            ; Set carry
  3516. ;    lda    cm.bfp        ; Increment the buffer pointer
  3517. ;    sbc    #1        ;        ...
  3518. ;    sta    cm.bfp        ;        ...
  3519. ;    bcs    cmsw2e        ;        ...
  3520. ;    dec    cm.bfp+1    ;        ...
  3521. ;cmsw2e: lda    (cmkptr),y    ; Get next character
  3522. ;    cmp    #0        ; Done?
  3523. ;    beq    cmsw13        ; Yes
  3524. ;    tax            ; No, hold on to the byte
  3525. ;    clc            ;    while we increment the pointer
  3526. ;    lda    cmkptr        ; Do L.O. byte
  3527. ;    adc    #1        ;        ...
  3528. ;    sta    cmkptr        ;        ...
  3529. ;    bcc    cmsw2f        ; And, if neccesary
  3530. ;    inc    cmkptr+1    ;    the H.O. byte as well
  3531. ;cmsw2f: txa            ; Get the data
  3532. ;    sta    (cm.ptr),y    ; Stuff it in the buffer
  3533. ;    clc            ; Clear carry
  3534. ;    lda    cm.ptr        ; Increment the next character pointer
  3535. ;    adc    #1        ;        ...
  3536. ;    sta    cm.ptr        ;        ...
  3537. ;    bcc    cmsw2g        ;        ...
  3538. ;    inc    cm.ptr+1    ;        ...
  3539. ;cmsw2g: inc    cmccnt        ; Increment the character count
  3540. ;    jmp    cmsw2e        ; Get next character from table
  3541. ;cmsw13: inc    cmccnt        ; Increment the character count
  3542. ;    lda    #0        ; Clear AC
  3543. ;    sta    (cm.ptr),y    ; Stuff a null in the buffer
  3544. ;    ldx    cm.bfp        ; Hold on to this pointer
  3545. ;    ldy    cm.bfp+1    ;    for later printing of switch
  3546. ;    clc            ; Clear carry
  3547. ;    lda    cm.ptr        ; Now make both pointers look like
  3548. ;    adc    #1        ;    (cm.ptr)+1
  3549. ;    sta    cm.ptr        ;        ...
  3550. ;    sta    cm.bfp        ;        ...
  3551. ;    bcc    cmsw3a        ;        ...
  3552. ;    inc    cm.ptr+1    ;        ...
  3553. ;cmsw3a: lda    cm.ptr+1    ; Copy H.O. byte
  3554. ;    sta    cm.bfp+1    ;        ...
  3555. ;    jsr    prstr        ; Now print string with pointer saved earlier
  3556. ;;
  3557. ;; well this is ridiculous...
  3558. ;;    ldx    #1        ; Set up argument
  3559. ;;    jsr    prbl2        ; Print one blank
  3560. ;    lda    #space        ; [jrd] now isn't this 
  3561. ;    jsr    cout        ;  easier?
  3562. ;cmsw14: clc            ; Clear carry
  3563. ;    lda    cmkptr        ; Increment keyword pointer
  3564. ;    adc    #1        ; Past null terminator
  3565. ;    sta    cmkptr        ;        ...
  3566. ;    bcc    cmsw4a        ;        ...
  3567. ;    inc    cmkptr+1    ;        ...
  3568. ;cmsw4a: ldy    #0        ; Clear Y
  3569. ;    lda    (cmkptr),y    ; Get first data byte
  3570. ;    tax            ; Put it here
  3571. ;    iny            ; Up the index
  3572. ;    lda    (cmkptr),y    ; Get second data byte
  3573. ;    tay            ; Put that in Y
  3574. ;    pla            ; Flush the old comand line pointer
  3575. ;    pla            ;        ...
  3576. ;    lda    #0        ;  Clear the failure flag
  3577. ;    sta    cmcffl        ;         ...
  3578. ;    jmp    rskp        ; And give a skip return
  3579. ;cmswi2: ldy    #0        ; Clear Y
  3580. ;    lda    (cminf1),y    ; Get length of table
  3581. ;    cmp    #2        ; Greater than 1
  3582. ;    bmi    cmsw21        ; No, go fetch data
  3583. ;    ldx    #cmer01\    ; Yes, fetch pointer to error message
  3584. ;    ldy    #cmer01^    ;        ...
  3585. ;    jsr    prstr        ; Print the error
  3586. ;    jmp    prserr        ; And go handle the parser error
  3587. ;cmsw21: iny            ; Add one to the index
  3588. ;    lda    (cminf1),y    ; Get the length of the keyword
  3589. ;    sta    keylen        ; Save that
  3590. ;    lda    cminf1+1    ; Copy pointer to table
  3591. ;    sta    cmkptr+1    ;        ...
  3592. ;    clc            ; Get set to increment an address
  3593. ;    lda    cminf1        ; Do L.O. byte last for efficiency
  3594. ;    adc    keylen        ; Add in the keyword length
  3595. ;    adc    #2        ; Now account for table length and terminator
  3596. ;    sta    cmkptr        ; Save the new pointer
  3597. ;    bcc    cmsw22        ; If no carry, continue
  3598. ;    inc    cmkptr+1    ; Adjust H.O. byte
  3599. ;cmsw22: jmp    cmsw4a        ; Go to load data and skip return
  3600. ;cmswi3: cmp    #'/        ; Is the real character a slash?
  3601. ;    beq    cmswi4        ; Yes, go do the rest
  3602. ;    tax            ; Move the data byte
  3603. ;    lda    #0        ; Clear AC
  3604. ;    pla            ; Fetch back the old comand line pointer
  3605. ;    sta    cm.ptr+1    ;        ...
  3606. ;    sta    cmoptr+1    ;         ...
  3607. ;    pla            ;        ...
  3608. ;    sta    cm.ptr        ;        ...
  3609. ;    sta    cmoptr        ;        ...
  3610. ;    lda    cmccnt        ;  Save count in case of <ctrl/H>
  3611. ;    sta    cmocnt        ;  
  3612. ;    lda    #$FF        ;  Set failure  flag
  3613. ;    sta    cmcffl        ;         ...
  3614. ;    rts            ; Fail - non-skip return
  3615. ;cmswi4: jsr    cmkeyw        ; Let Keyw do the work for us
  3616. ;     jmp    cmswi5        ; We had problems, restore comand ptr and ret.
  3617. ;    pla            ; Flush the old comand pointer
  3618. ;    pla
  3619. ;    lda    #0        ;  Reset the failre flag
  3620. ;    sta    cmcffl        ; 
  3621. ;    jmp    rskp        ; Success - skip return!
  3622. ;cmswi5: pla            ; Fetch back the old comand line pointer
  3623. ;    sta    cm.ptr+1    ;        ...
  3624. ;    sta    cmoptr+1    ;         ...
  3625. ;    pla            ;        ...
  3626. ;    sta    cm.ptr        ;        ...
  3627. ;    sta    cmoptr        ;         ...
  3628. ;    lda    cmccnt        ;  Save count in case of <ctrl/H>
  3629. ;    sta    cmocnt        ; 
  3630. ;    lda    #$FF        ;  Set failure flag
  3631. ;    sta    cmcffl        ; 
  3632. ;    rts            ; Now return
  3633. ;
  3634. ; [jrd] end of commented out switch parser
  3635. ;
  3636.  
  3637. .SBTTL    Cmifil - try to parse an input file spec next
  3638.  
  3639. ;
  3640. ;    This routine attempts to parse an input file spec.
  3641. ;
  3642. ;        Input:  X - Max filename length
  3643. ;
  3644. ;        Output: Filename parsed is in buffer pointed to by X,Y
  3645. ;
  3646. ;        Registers destroyed:    A,X,Y
  3647. ;
  3648.  
  3649. cmifil: inx            ;  Increment max file length for tests
  3650.     stx    cmprmx        ;  Maximum filename length
  3651.     lda    cm.ptr        ; Save the old comand line pointer in case
  3652.     pha            ;
  3653.     lda    cm.ptr+1    ;
  3654.     pha            ;
  3655.     lda    #0        ; Zero the
  3656.     sta    lenabf        ;  length of the atom buffer
  3657. cmifl0: ldy    #0        ; Zero Y
  3658.     lda    #'            ; Blank the AC 
  3659.     ora    #$80        ; Make it look like a terminator
  3660. cmifi0: sta    atmbuf,y    ; Now zero the buffer
  3661.     iny            ;        ...
  3662.     cpy    cmprmx      ;  Done?
  3663.     bpl    cmifi1        ; Yes, start parsing
  3664.     jmp    cmifi0        ; No, continue blanking
  3665. cmifi1: jsr    cmgtch        ; Get a character from command buffer
  3666.     cmp    #0        ; Is it an action character?
  3667.     bmi    cmif10        ;  Yes, check it out
  3668.     jmp    cmifi2        ;  No , process it as a normal character
  3669. cmif10:    and    #$7F        ;  Yes, turn off the minus bit
  3670.     cmp    #'?        ; Does the user need help?
  3671.     bne    cmif12        ; Nope
  3672.     jsr    cout        ; And print the question mark
  3673.     ldy    #0        ; Yes
  3674.     sty    cmaflg        ; Clear the action flag
  3675.     ldx    #cmin03\    ; Now get set to give the 'file spec' message
  3676.     ldy    #cmin03^    ;        ...
  3677.     jsr    prstr        ; Print it
  3678.     jsr    prcrlf        ; Print a crelf
  3679.     lda    #cmfehf        ;  Load extra help flag
  3680.     bit    cmprmy        ;  Test bit
  3681.     beq    cmifnh        ;  No extra help
  3682.     jsr    cmehlp        ;  Go give extra help
  3683. cmifnh:    ldx    cm.rty        ;  Set up to reprint the prompt
  3684.     ldy    cm.rty+1    ;        ...
  3685.     jsr    prstr        ; Do it
  3686.     sec            ; Set the carry flag for subtraction
  3687.     lda    cm.bfp        ; Get the buffer pointer
  3688.     sbc    #1        ; Decrement it once
  3689.     sta    cm.bfp        ;        ...
  3690.     bcs    cmif11        ; If it's set, we need not do H.O. byte
  3691.     dec    cm.bfp+1    ; Adjust the H.O. byte
  3692. cmif11: dec    cmccnt        ; Decrement the character count
  3693.     ldy    #0        ; Clear Y
  3694.     lda    #0        ; Clear AC
  3695.     sta    (cm.bfp),y    ; Stuff a null at the end of the command buffer
  3696.     ldx    #cmbuf\        ; Now get the address of the command buffer
  3697.     ldy    #cmbuf^        ;        ...
  3698.     jsr    prstr        ; Reprint the command line
  3699.     jmp    cmifi1        ; Go back and continue
  3700. cmif12: cmp    #esc        ; Got an escape?
  3701.     bne    cmif13        ; No
  3702.     lda    #0        ; Yup, clear the action flag
  3703.     sta    cmaflg        ;        ...
  3704.     lda    #cmfdff        ;  Load default-present flag
  3705.     bit    cmprmy        ;  Test bit
  3706.     beq    cmifnd        ;  No default
  3707.     lda    lenabf        ;  Now check if user typed anything
  3708.     bne    cmifnd        ;  Yup, can't use default
  3709.     jmp    cmcpdf        ;  Go copy the default
  3710. cmifnd:    jsr    bell        ; Escape does not work here, ring the bell
  3711.     sec            ; Set carry for subtraction
  3712.     lda    cm.bfp        ; Decrement the buffer pointer
  3713.     sbc    #1        ;    once
  3714.     sta    cm.bfp        ;        ...
  3715.     sta    cm.ptr        ; Make both pointers look at the same spot
  3716.     lda    cm.bfp+1    ;        ...
  3717.     sbc    #0        ; H.O. byte adjustment
  3718.     sta    cm.bfp+1    ;        ...
  3719.     sta    cm.ptr+1    ;        ...
  3720.     dec    cmccnt        ; Decrement the character count
  3721.     jmp    repars        ;    and go reparse everything
  3722. cmif13: lda    lenabf        ;  Get the length of the buffer
  3723.     cmp    #0        ; Is it zero?
  3724.     bne    cmif14        ; No, continue
  3725.     jmp    cmifi9        ; Yes, this is not good
  3726. cmif14: cmp    cmprmx      ;  Are we over the maximum file length?
  3727.     bmi    cmif15        ; Not quite yet
  3728.     jmp    cmifi9        ; Yes, blow up
  3729. cmif15: ldy    lenabf        ;  Get the filename length
  3730.     lda    #nul        ;    and stuff a null at that point
  3731.     sta    atmbuf,y    ; 
  3732.     pla            ; Flush the old comand line pointer
  3733.     pla            ;        ...
  3734.     ldx    #atmbuf\    ;  Set up the atombuffer address
  3735.     ldy    #atmbuf^    ;        ...
  3736.     lda    #0        ;  Reset the failure flag
  3737.     sta    cmcffl        ; 
  3738.     lda    lenabf        ;  Load length into AC to be passed back
  3739.     jmp    rskp        ; No, we are successful
  3740. cmifi2: cmp    #sp        ;  Bad character?
  3741.     bmi    cmifi9        ; Yes, blow up
  3742.     cmp    #del        ; 
  3743.     bpl    cmifi9        ; This is bad, punt
  3744.     cmp    #$61        ; Lower case alphabetic?
  3745.     bmi    cmifi8        ; Don't capitalize if it's not alphabetic
  3746.     cmp    #$7B        ;        ...
  3747.     bpl    cmifi8        ;        ...
  3748.     and    #$5F        ; Capitalize
  3749. cmifi8: ldy    lenabf        ;  Set up length of buffer in Y
  3750.     sta    atmbuf,y    ;  Stuff character in FCB
  3751.     inc    lenabf        ;  Increment the length of the name
  3752.     jmp    cmifi1        ; Go back for the next character
  3753. cmifi9: pla            ; Restore the old comand line pointer
  3754.     sta    cm.ptr+1    ;  in case the user wants to parse
  3755.     sta    cmoptr+1    ;         ...
  3756.     pla            ;    for something else
  3757.     sta    cm.ptr        ;        ...
  3758.     sta    cmoptr        ;         ...
  3759.     lda    cmccnt        ;  Save count in case of <ctrl/H>
  3760.     sta    cmocnt        ;         ...
  3761.     lda    #$FF        ;  Set failure flag
  3762.     sta    cmcffl        ; 
  3763.     rts
  3764.  
  3765. .SBTTL    Cmofil - try to parse an output file spec
  3766.  
  3767. ;
  3768. ;    This routine attempts to parse an output file spec from the
  3769. ;    command buffer.
  3770. ;
  3771. ;        Input:  cminf1- Pointer to FCB
  3772. ;
  3773. ;        Output:
  3774. ;
  3775. ;        Registers destroyed:
  3776. ;
  3777.  
  3778. cmofil: jmp    cmifil        ; Same as parsing input file spec for now
  3779.  
  3780. .SBTTL    Cminum - Try to parse an integer number
  3781.  
  3782. ;
  3783. ;    This routine tries to parse an integer number in the base
  3784. ;    specified. It will return a 16-bit number in cmintg.
  3785. ;    Cmintg is formatted H.O. byte first!
  3786. ;
  3787. ;        Input:  X-    Base of integer (2<=x<=16)
  3788. ;
  3789. ;        Output: Cmintg- 16-bit integer
  3790. ;
  3791. ;        Registers destroyed:    A,X,Y
  3792. ;
  3793.  
  3794. cminum: lda    cm.ptr        ; Save the old comand line pointer
  3795.     pha            ;        ...
  3796.     lda    cm.ptr+1    ;        ...
  3797.     pha            ;        ...
  3798.     cpx    #$11        ; Are we within the proper range?
  3799.     bmi    cmin1        ; If so, check high range
  3800.     jmp    cmine1        ; No, tell them about it
  3801. cmin1:  cpx    #2        ; Too small of a base??
  3802.     bpl    cmin2        ; No, continue
  3803.     jmp    cmine1        ; Base too small, tell them about it
  3804. cmin2:  stx    cmbase        ; The base requested is good, store it
  3805.     lda    #0        ; Clear AC
  3806.     sta    cmmres        ;    and initialize these areas
  3807.     sta    cmmres+1    ;        ...
  3808.     sta    cmmres+2    ;        ...
  3809.     sta    cmmres+3    ;        ...
  3810.     sta    cmintg        ;        ...
  3811.     sta    cmintg+1    ;        ...
  3812.     sta    cmintg+2    ;        ...
  3813.     sta    cmintg+3    ;        ...
  3814. cminm1: jsr    cmgtch        ; Get next character from command buffer
  3815.     cmp    #0        ; Is this an action character
  3816.     bmi    cmin1a        ; Yes, handle it
  3817.     jmp    cminm4        ; No, look for a digit
  3818. cmin1a: and    #$7F        ; It is, turn off the H.O. bit
  3819.     cmp    #esc        ; Is it an escape?
  3820.     bne    cminm2        ; No, try something else
  3821.     lda    #cmfdff        ;  Load default-present flag
  3822.     bit    cmprmy        ;  Test bit
  3823.     beq    cminnd        ;  No, default
  3824.     lda    cmmres        ;  Check if user typed anything significant
  3825.     ora    cmmres+1    ;         ...
  3826.     bne    cminnd        ;  Yup, can't use default
  3827.     jmp    cmcpdf        ;  Go copy the default
  3828. cminnd:    jsr    bell        ; Yes, but escape is not allowed, ring bell
  3829.     lda    #0        ; Zero
  3830.     sta    cmaflg        ;    the action flag
  3831.     sec            ; Set the carry flag for subtraction
  3832.     lda    cm.bfp        ; Get the command buffer pointer
  3833.     sbc    #1        ; Decrement it once
  3834.     sta    cm.bfp        ; Store it away
  3835.     sta    cm.ptr        ; Make this pointer look like it also
  3836.     bcs    cmin11        ; If carry set don't adjust H.O. byte
  3837.     dec    cm.bfp+1    ; Adjust the H.O. byte
  3838. cmin11: lda    cm.bfp+1    ; Move a copy of this H.O. byte
  3839.     sta    cm.ptr+1    ;    to this pointer
  3840.     dec    cmccnt        ; Decrement the character count
  3841.     jmp    cminm1        ; Go try for another character
  3842. cminm2: cmp    #'?        ; Does the user need help?
  3843.     bne    cminm3        ; If not, back up the pointer and accept
  3844.     jsr    cout        ; And print the question mark
  3845.     ldx    #cmin05\    ; Set up the pointer to info message to be
  3846.     ldy    #cmin05^    ;    printed
  3847.     jsr    prstr        ; Print the text of the message
  3848.     lda    cmbase        ; Get the base of the integer number
  3849.     cmp    #$0A        ; Is it greater than decimal 10?
  3850.     bmi    cmin21        ; No, just print the L.O. digit
  3851.     clc            ; Clear the carry
  3852.     lda    #1        ; Print the H.O. digit as a 1
  3853.     adc    #$30        ; Make it printable
  3854.     jsr    cout        ; Print the '1'
  3855.     lda    cmbase        ; Get the base back
  3856.     sec            ; Set the carry flag for subtraction
  3857.     sbc    #$0A        ; Subtract off decimal 10
  3858. cmin21: clc            ; Clear carry for addition
  3859.     adc    #$30        ; Make it printable
  3860.     jsr    cout        ; Print the digit
  3861.     jsr    prcrlf        ; Print a crelf
  3862.     lda    #cmfehf        ;  Load extra help flag
  3863.     bit    cmprmy        ;  Test bit
  3864.     beq    cminnh        ;  No extra help
  3865.     jsr    cmehlp        ;  Go give extra help
  3866. cminnh:    ldx    cm.rty        ; Set up the pointer so we can print the prompt
  3867.     ldy    cm.rty+1    ;        ...
  3868.     jsr    prstr        ; Reprint the prompt
  3869.     lda    #0        ; Clear AC
  3870.     ldy    #0        ; Clear Y
  3871.     sta    (cm.ptr),y    ; Drop a null at the end of the command buffer
  3872.     sec            ; Set the carry flag for subtraction
  3873.     lda    cm.bfp        ; Get the L.O. byte of the address
  3874.     sbc    #1        ; Decrement it once
  3875.     sta    cm.bfp        ; Store it back
  3876.     bcs    cmin22        ; If carry set, don't adjust H.O. byte
  3877.     dec    cm.bfp+1    ; Adjust H.O. byte
  3878. cmin22: ldx    #cmbuf\        ; Get the address of the command buffer
  3879.     ldy    #cmbuf^        ;        ...
  3880.     jsr    prstr        ; Reprint the command buffer
  3881.     lda    #0        ; Clear the
  3882.     sta    cmaflg        ;    action flag
  3883.     jmp    repars        ; Reparse everything
  3884. cminm3: ldx    cmmres        ;  Move L.O. byte
  3885.     ldy    cmmres+1    ;  Move H.O. byte
  3886.     pla            ; Flush the old comand line pointer
  3887.     pla            ;        ...
  3888.     lda    #0        ;  Reset the failure flag
  3889.     sta    cmcffl        ; 
  3890.     jmp    rskp        ;
  3891. cminm4: cmp    #$60        ; Is this a letter?
  3892.     bmi    cmin41        ; Nope, skip this stuff
  3893.     sec            ; It is, bring it into the proper range
  3894.     sbc    #$27        ;        ...
  3895. cmin41: sec            ; Set carry for subtraction
  3896.     sbc    #$30        ; Make the number unprintable
  3897.     cmp    #0        ; Is the number in the proper range?
  3898.     bmi    cminm5        ; No, give an error
  3899.     cmp    cmbase        ;        ...
  3900.     bmi    cminm6        ; This number is good
  3901. cminm5: pla            ; Restore the old comand line pointer
  3902.     sta    cm.ptr+1    ;        ...
  3903.     sta    cmoptr        ;         ...
  3904.     pla            ;        ...
  3905.     sta    cm.ptr        ;        ...
  3906.     sta    cmoptr        ;         ...
  3907.     lda    cmccnt        ;  Save count in case of <ctrl/H>
  3908.     sta    cmocnt        ;         ...
  3909.     lda    #$FF        ;  Set failure flag
  3910.     sta    cmcffl        ;         ...
  3911.     rts            ; Then return
  3912. cminm6: pha            ; Save the number to add in
  3913.     lda    cmmres+1    ; Move the number to multiply
  3914.     pha            ;     onto the stack for 
  3915.     lda    cmmres        ;    call to mul16
  3916.     pha            ;        ...
  3917.     lda    #0        ; Move base onto the stack (H.O. byte first)
  3918.     pha            ;        ...
  3919.     lda    cmbase        ;        ...
  3920.     pha            ;        ...
  3921.     jsr    mul16        ; Multiply this out
  3922.     pla            ; Get L.O. byte of product
  3923.     sta    cmmres        ; Store it for now
  3924.     pla            ; Get H.O. byte of product
  3925.     sta    cmmres+1    ; Store that too
  3926.     pla            ; Get the digit to add in
  3927.     clc            ; Clear the carry for the add
  3928.     adc    cmmres        ; Add in L.O. byte of result
  3929.     sta    cmmres        ; Store it back
  3930.     lda    cmmres+1    ; Get the H.O. byte
  3931.     adc    #0        ; Add in the carry
  3932.     sta    cmmres+1    ; Save the H.O. byte
  3933.     bcs    cmine2        ; Wrong, we overflowed
  3934.     jmp    cminm1        ; Try for the next digit
  3935. cmine1: ldx    #cmer06\    ; Get the address of the error message
  3936.     ldy    #cmer06^    ;        ...
  3937.     jsr    prstr        ; Print the error
  3938.     jmp    prserr        ; Handle the parse error
  3939. cmine2: ldx    #cmer07\    ; Get the address of the error message
  3940.     ldy    #cmer07^    ;        ...
  3941.     jsr    prstr        ; Print the error message
  3942.     jmp    prserr        ; Handle the error
  3943.  
  3944. .SBTTL    Cmflot - Try to parse a floating point number
  3945.  
  3946. ;
  3947. ;    This routine tries to parse a floating point number in the
  3948. ;    format:
  3949. ;        sd-d.d-dEsddd
  3950. ;
  3951. ;        s is an optional sign bit
  3952. ;        d is a decimal digit
  3953. ;        E is the letter 'E'
  3954. ;        . is a decimal point
  3955. ;
  3956. ;        Input:
  3957. ;
  3958. ;        Output: Cmfltp- 6 byte floating point number
  3959. ;                4.5 byte signed mantissa
  3960. ;                1.5 byte signed exponent
  3961. ;
  3962. ;
  3963. ;        bit    0 1      35 36 37    47
  3964. ;
  3965. ;        Registers destroyed:    A,X,Y
  3966. ;
  3967.  
  3968. cmflot: rts
  3969.  
  3970. .SBTTL    Cmunqs - Try to parse an unquoted string
  3971.  
  3972. ;
  3973. ;    This routine tries to parse an unquoted string terminating
  3974. ;    with one of the break characters in brkwrd.
  3975. ;
  3976. ;        Input:    
  3977. ;
  3978. ;        Output:    X - L.O. byte address of ASCII string
  3979. ;            Y - H.O. byte address of ASCII string
  3980. ;            A - Length of string parsed
  3981. ;
  3982. ;        Registers destroyed:    A,X,Y
  3983. ;
  3984.  
  3985. cmunqs:    lda    cm.ptr        ; Save the command buffer pointer
  3986.     pha            ;        ...
  3987.     lda    cm.ptr+1    ;        ...
  3988.     pha            ;        ...
  3989.     lda    #0        ; Zero length of Atom buffer
  3990.     sta    lenabf        ;        ...
  3991. cmunq1:    jsr    cmgtch        ; Get a character
  3992.     jsr    chkbrk        ; Is it one of the break characters?
  3993.      jmp    cmunq3        ; Yes, handle that condition
  3994.     cmp    #0        ; No, is it an action character?
  3995.     bpl    cmunq2        ; No, handle it as normal text
  3996.     and    #$7F        ; We don't need the H.O. bit
  3997.     cmp    #'?        ; Does the user need help?
  3998.     bne    cmun13        ; Nope, try next possibility
  3999.     jsr    cout        ; Print '?'
  4000.     ldy    #0        ; Zero the action flag
  4001.     sty    cmaflg        ;        ...
  4002.     ldx    #cmin06\    ; Get the help message
  4003.     ldy    #cmin06^    ;        ...
  4004.     jsr    prstr        ;    and print it.
  4005.     jsr    prcrlf        ; Print a crelf after it
  4006.     lda    #cmfehf        ; Check for extra help.
  4007.     bit    cmprmy        ;        ...
  4008.     beq    cmun11        ; If no help, continue
  4009.     jsr    cmehlp        ; Process extra help
  4010. cmun11:    ldx    cm.rty        ; Go reprint prompt
  4011.     ldy    cm.rty+1    ;        ...
  4012.     jsr    prstr        ;        ...
  4013.     sec            ; Adjust buffer pointer
  4014.     lda    cm.bfp        ;        ...
  4015.     sbc    #1        ;        ...
  4016.     sta    cm.bfp        ;        ...
  4017.     bcs    cmun12        ;        ...
  4018.     dec    cm.bfp+1    ; Adjust H.O. byte
  4019. cmun12:    dec    cmccnt        ; Correct character count
  4020.     ldy    #0        ; Stuff a null at end of usable buffer
  4021.     lda    #0        ;        ...
  4022.     sta    (cm.bfp),y    ;        ...
  4023.     ldx    #cmbuf\        ; Reprint command line
  4024.     ldy    #cmbuf^        ;        ...
  4025.     jsr    prstr        ;        ...
  4026.     jmp    cmunq1        ; Go back for more characters
  4027. cmun13:    cmp    #esc        ; Did the user type <esc>?
  4028.     bne    cmunq2        ; No, just stuff the character and cont.
  4029.     lda    #0        ; Clear the action flag
  4030.     sta    cmaflg        ;        ...
  4031.     lda    #cmfdff        ; Check if there is a default value
  4032.     bit    cmprmy        ;        ...
  4033.     beq    cmun14        ; If not, the <esc> loses
  4034.     lda    lenabf        ; Ok, there is a default, but if
  4035.     bne    cmun14        ;    something has been typed, <esc> loses
  4036.     jmp    cmcpdf        ; Go copy default and reparse
  4037. cmun14:    jsr    bell        ; Feep at user
  4038.     sec            ;    and reset the buffer pointer
  4039.     lda    cm.bfp        ;        ...
  4040.     sbc    #1        ;        ...
  4041.     sta    cm.bfp        ;        ...
  4042.     sta    cm.ptr        ;        ...
  4043.     lda    cm.bfp+1    ;        ...
  4044.     sbc    #0        ;        ...
  4045.     sta    cm.bfp+1    ;        ...
  4046.     sta    cm.ptr+1    ;        ...
  4047.     dec    cmccnt        ; Adjust the character count
  4048.     jmp    repars        ;    and reparse the command line
  4049. cmunq2:    ldy    lenabf        ; Fetch where we are in atmbuf
  4050.     sta    atmbuf,y    ;    and store our character there
  4051.     inc    lenabf        ; Reflect increased length
  4052.     jmp    cmunq1        ; Go back for more characters
  4053. cmunq3:    lda    lenabf        ; Get the length
  4054.     beq    cmunqf        ; If we parsed a null string, fail
  4055.     pla            ; Flush old command line pointer
  4056.     pla            ;        ...
  4057.     ldx    #atmbuf\    ; Now, set up the return parameter
  4058.     ldy    #atmbuf^    ;        ...
  4059.     lda    #0        ; Reset the failure flag
  4060.     sta    cmcffl        ;        ...
  4061.     lda    lenabf        ; Set up atom length
  4062.     jmp    rskp        ; Return
  4063. cmunqf:    pla            ; Restore old command line pointer
  4064.     sta    cm.ptr+1    ;        ...
  4065.     sta    cmoptr+1    ;        ...
  4066.     pla            ;        ...
  4067.     sta    cm.ptr        ;        ...
  4068.     sta    cmoptr        ;        ...
  4069.     lda    cmccnt        ; Save count in case of <ctrl/H>
  4070.     sta    cmocnt        ;        ...
  4071.     lda    #$FF        ; Set failure flag
  4072.     sta    cmcffl        ;        ...
  4073.     rts            ; Return
  4074.  
  4075. .SBTTL    Cmtokn - Try to parse for a single character token
  4076.  
  4077. ;
  4078. ;    This routine tries to parse for the character in the X-register.
  4079. ;
  4080. ;        Input:    X - Character to be parsed    
  4081. ;
  4082. ;        Output: +1 - failed to find character
  4083. ;            +4 - success, found character
  4084. ;
  4085. ;        Registers destroyed:    A,X,Y
  4086. ;
  4087.  
  4088. cmtokn:    lda    cm.ptr        ; First, save the old command pointer
  4089.     pha            ;    on the stack
  4090.     lda    cm.ptr+1    ;        ...
  4091.     pha            ;        ...
  4092. cmtk0:    jsr    cmgtch        ; Fetch the next character
  4093.     bpl    cmtk3        ; Not an action character
  4094.     and    #$7F        ; It's an action character
  4095.     cmp    #esc        ; User trying to be lazy?
  4096.     bne    cmtk2        ; Nope, try next option
  4097.     jsr    bell        ; Yes, well, he's not allowed to be lazy
  4098.     lda    #0        ; Clear the action flag
  4099.     sta    cmaflg        ;        ...
  4100.     sec            ; Adjust the buffer pointer back once
  4101.     lda    cm.bfp        ;        ...
  4102.     sbc    #1        ;        ...
  4103.     sta    cm.bfp        ;        ...
  4104.     sta    cm.ptr        ; Copy it into command pointer
  4105.     bcs    cmtk1        ; Need to adjust H.O. byte?
  4106.     dec    cm.bfp+1    ; Yes, do it
  4107. cmtk1:    lda    cm.bfp+1    ; Copy it to command pointer
  4108.     sta    cm.ptr+1    ;        ...
  4109.     dec    cmccnt        ; Adjust the character count
  4110.     jmp    cmtk0        ;    and try again
  4111. cmtk2:    cmp    #'?        ; User need help?
  4112.     bne    cmtk4        ; No, go fail
  4113.     jsr    cout        ; Print it
  4114.     ldx    #cmin07\    ; Point to the information message
  4115.     ldy    #cmin07^    ;        ...
  4116.     jsr    prstr        ;    and print it
  4117.     lda    #dquot        ; Print the character we are looking for
  4118.     jsr    cout        ;    in between double quotes
  4119.     lda    cmprmx        ;        ...
  4120.     jsr    cout        ;        ...
  4121.     lda    #dquot        ;        ...
  4122.     jsr    cout        ;        ...
  4123.     jsr    prcrlf        ; End it with a crelf
  4124.     lda    #cmfehf        ; Load extra help flag
  4125.     bit    cmprmy        ; Test bit
  4126.     beq    cmtknh        ; No extra help
  4127.     jsr    cmehlp        ; Go give extra help
  4128. cmtknh:    ldx    cm.rty        ; Point to prompt
  4129.     ldy    cm.rty+1    ;        ...
  4130.     jsr    prstr        ;    and print it
  4131.     sec            ; Adjust the buffer pointer back one
  4132.     lda    cm.bfp        ;        ...
  4133.     sbc    #1        ;        ...
  4134.     sta    cm.bfp        ;        ...
  4135.     lda    cm.bfp+1    ;        ...
  4136.     sbc    #0        ;        ...
  4137.     sta    cm.bfp+1    ;        ...
  4138.     lda    #0        ; Stuff a null at the end of the buffer
  4139.     ldy    #0        ;        ...
  4140.     sta    (cm.ptr),y    ;        ...
  4141.     ldx    #cmbuf\        ; Point to command buffer
  4142.     ldy    #cmbuf^        ;        ...
  4143.     jsr    prstr        ;    and reprint it
  4144.     lda    #0        ; Clear action flag
  4145.     sta    cmaflg        ;        ...
  4146.     jmp    repars        ;    and go reparse
  4147. cmtk3:    cmp    cmprmx        ; Ok, this either is or is not the
  4148.     bne    cmtk4        ;    char we want. If not, go fail.
  4149.     pla            ; It is, flush the old address
  4150.     pla            ;        ...
  4151.     lda    #0        ; Reset the failure flag
  4152.     sta    cmcffl        ;        ...
  4153.     jmp    rskp        ;    and skip return
  4154. cmtk4:    pla            ; Restore old pointer
  4155.     sta    cm.ptr+1    ;        ...
  4156.     sta    cmoptr+1    ;        ...
  4157.     pla            ;        ...
  4158.     sta    cm.ptr        ;        ...
  4159.     sta    cmoptr        ;        ...
  4160.     lda    cmccnt        ; Save the count for <ctrl/H>
  4161.     sta    cmocnt        ;        ...
  4162.     lda    #$FF        ; Set failure flag
  4163.     sta    cmcffl        ;        ...
  4164.     rts            ; Return
  4165.  
  4166. .SBTTL    Cminbf - read characters from keyboard
  4167.  
  4168. ;
  4169. ;    This routine reads characters from the keyboard until
  4170. ;    an action or editing character comes up.
  4171. ;
  4172. ;        Input:
  4173. ;
  4174. ;        Output:        Cmbuf- characters from keyboard
  4175. ;
  4176. ;        Registers destroyed:
  4177. ;
  4178.  
  4179. cminbf: pha            ; Save the AC
  4180.     txa            ;    and X
  4181.     pha            ;        ...
  4182.     tya            ;    and Y
  4183.     pha            ;        ...
  4184.     php            ; Save the processor status
  4185.     ldy    #0        ; Clear Y
  4186.     lda    cmaflg        ; Fetch the action flag
  4187.     cmp    #0        ; Set??
  4188.     beq    cminb1        ; Nope
  4189.     jmp    cminb9        ; Yes, so leave
  4190. cminb1: inc    cmccnt        ; Up the character count once
  4191.     bne    cminb0        ;  If we are overflowing the command buffer
  4192.     jsr    bell        ;    Feep at the user and do Prserr
  4193.     dec    cmccnt        ;  Make sure this doesn't happen again
  4194.     jmp    prserr        ;    for same string
  4195. cminb0:    jsr    rdkey        ; Get next character from keyboard
  4196. ;    txa            ; [jrd] save x for a bit
  4197. ;    pha            ;  while we translate to ascii
  4198. ;    ldx    char
  4199. ;    lda    attoas,x    ; run it thru the keyboard table
  4200. ;    sta    char
  4201. ;    pla            ; get x back
  4202. ;    tax
  4203. ;    lda    char        ;[31]
  4204.     cmp    #esc        ; esc is a legal non-printing character
  4205.     beq    cminb8
  4206.     cmp    #cr        ; cr is a legal non-printing character
  4207.     beq    cminb8
  4208.     cmp    #lf        ; lf is a legal non-printing character
  4209.     beq    cminb8
  4210.     cmp    #tab        ; tab is a legal non-printing character
  4211.     beq    cminb8
  4212.     cmp    #ctrlu        ; ctrlu is a legal non-printing character
  4213.     beq    cminb8
  4214.     cmp    #ctrlw        ; ctrlw is a legal non-printing character
  4215.     beq    cminb8
  4216.     cmp    #ffd        ; form feed is a legal non-printing character
  4217.     beq    cminb8
  4218.     cmp    #del        ; del is a legal non-printing character
  4219.     beq    cminb8
  4220.     cmp    #bs        ; bs is a legal non-printing character
  4221.     beq    cminb8
  4222.     cmp    #$20        ; ignore non-printing characters
  4223.     bcc    cminb0
  4224.     cmp    #$20+96        ; ignore non-printing characters
  4225.     bcs    cminb0
  4226. cminb8:    cmp    #$7F        ;[46]
  4227.     beq    cmind        ;  Yes
  4228.     cmp    #bs        ;  Also a retry
  4229.     bne    cmnbnh        ;  No, go on
  4230. cmind:    ldx    cmccnt        ;  Check character count
  4231.     cpx    #1        ;  Is this the first character?
  4232.     bne    cmnbnh        ;  Nope, can't help him
  4233.     ldx    cmcffl        ;  Did the previous command fail?
  4234.     bpl    cmnbnh        ;  No, we can't reparse a good command
  4235.     lda    cmoptr        ;  Ok, get the old pointer and set up
  4236.     sta    cm.ptr        ;     the old command line again
  4237.     sta    cm.bfp        ;         ...
  4238.     lda    cmoptr+1    ;         ...
  4239.     sta    cm.ptr+1    ;         ...
  4240.     sta    cm.bfp+1    ;         ...
  4241.     lda    cmocnt        ;  Restore the character count
  4242.     sta    cmccnt        ;         ...
  4243.     lda    #0        ;  Zero this so we can safely use the
  4244.     sta    cmwrk2        ;     code that reprints a line after ^W
  4245.     jmp    cmnbna        ;  Go reprint the line
  4246. cmnbnh:    ldy    #0        ;        ...
  4247.     sta    (cm.bfp),y    ; Stuff it in buffer
  4248.     tax            ; Hold it here for a while
  4249.     clc            ; Clear the carry
  4250.     lda    cm.bfp        ; Increment the buffer pointer
  4251.     adc    #1        ;        ...
  4252.     sta    cm.bfp        ;        ...
  4253.     bcc    cmnb11        ; Carry?
  4254.     inc    cm.bfp+1    ; Yup, do H.O. byte
  4255. cmnb11: txa            ; Get the data back
  4256.     cmp    #ctrlu        ; Is it a ^U
  4257.     bne    cminb2        ; Nope
  4258. cmnb12: jsr    screl2        ; Yes, clear the whole line
  4259.     sec            ;[37] Get the cursor coordinates
  4260.     jsr    ploth        ;[37]        ...
  4261. ;    ldy    #0        ;[DD] Reset cursor position to beg. of line
  4262.     ldx    #0        ;[DD] Reset cursor position to beg. of line
  4263.     clc            ;[DD]        ...
  4264.     jsr    ploth        ;[DD][26]    ...
  4265.     ldx    cm.rty        ;  Get L.O. byte addr of prompt
  4266.     ldy    cm.rty+1    ;     and H.O. byte
  4267.     jsr    prstr        ; Reprint the prompt
  4268.     jsr    screl0        ; Get rid of garbage on that line
  4269.     lda    #cmbuf\        ; Now reset the buffer pointer
  4270.     sta    cm.bfp        ;     to the beginning of the buffer
  4271.     lda    #cmbuf^        ;        ...
  4272.     sta    cm.bfp+1    ;        ...
  4273.     lda    #0        ; Clear AC
  4274.     sta    cmccnt        ; Clear the character count
  4275.     jmp    repars        ; Reparse new line from beginning
  4276. cminb2: cmp    #bs        ; Is it a <bs>?
  4277.     beq    cminb3        ; Yes
  4278.     cmp    #del        ;[46]
  4279.     bne    cminb4        ; No
  4280. cminb3: jsr    scrl        ; move the cursor left
  4281.     jsr    screl0        ; Now clear from there to end of line
  4282.     dec    cmccnt        ; Decrement the character count
  4283.     dec    cmccnt        ;    twice.
  4284.     lda    cmccnt        ; Now fetch it
  4285.     cmp    #0        ; Did we back up too far??
  4286.     bpl    cmnb32        ; No, go on
  4287.     jsr    bell        ; Yes, ring the bell and
  4288.     jmp    cmnb12        ;    go reprint prompt and reparse line
  4289. cmnb32: sec            ; Set the carry
  4290.     lda    cm.bfp        ; Now decrement the buffer pointer
  4291.     sbc    #2        ;    twice.
  4292.     sta    cm.bfp        ; Store it
  4293.     bcs    cmnb33
  4294.     dec    cm.bfp+1    ; Decrement to account for the borrow
  4295. cmnb33: jmp    repars        ; Time to reparse everything
  4296. cminb4:    cmp    #ctrlw        ;  Delete a word?
  4297.     beq    cmnb41        ;  Yes, go take care of that
  4298.     jmp    cmib40        ;  Nope, continue
  4299. cmnb41:    lda    #3        ;  Set up negative offset count
  4300.     sta    cmwrk2        ;         ...
  4301.     sec            ;  Set up to adjust buffer pointer
  4302.     lda    cm.bfp        ;  Get the L.O. byte
  4303.     sbc    #3        ;  Adjust pointer down by 3
  4304.     sta    cm.bfp        ;  Store it back
  4305.     bcs    cmnb42        ;  Don't worry about H.O. byte
  4306.     dec    cm.bfp+1    ;  Adjust H.O. byte also
  4307. cmnb42:    lda    cmwrk2        ;  First, check the count
  4308.     cmp    cmccnt        ;  Cmwrk2 > cmccnt?
  4309.     bmi    cmints        ;  No, go test characters
  4310.     jmp    cmnb12        ;  Yes, go clear the whole line
  4311. cmints:    ldy    #0        ;  Zero Y
  4312.     lda    (cm.bfp),y    ;  Get previous character
  4313.     cmp    #lf        ;  Start to test ranges...
  4314.     bpl    cmits1        ;     Between <lf> and <cr>?
  4315.     jmp    cminac        ;  No, not in range at all
  4316. cmits1:    cmp    #cr+1        ;         ...
  4317.     bmi    cmnb43        ;  Yes, handle it
  4318.     cmp    #space        ;  Between <sp> and '"'?
  4319.     bpl    cmits2        ;  Possible, continue
  4320.     jmp    cminac        ;  No, advance to previous character
  4321. cmits2:    cmp    #dquot+1    ;         ...
  4322.     bmi    cmnb43        ;  Yes, delete back to there
  4323.     cmp    #apos        ;  Between Apostrophy and '/'?
  4324.     bpl    cmits3        ;  Could be, continue
  4325.     jmp    cminac        ;  Nope, advance character
  4326. cmits3:    cmp    #slash+1    ;         ...
  4327.     bmi    cmnb43        ;  Yup, found a delimiter
  4328.     cmp    #colon        ;  Between ':' and '>' perhaps?
  4329.     bpl    cmits4        ;  Maybe
  4330.     jmp    cminac        ;  Nope, advance to previous character    
  4331. cmits4:    cmp    #rabr+1     ;         ...
  4332.     bmi    cmnb43        ;  It is, go delete back to there
  4333.     cmp    #quot        ;  Is it a "'"?
  4334.     bne    cminac        ;  No, advance
  4335. cmnb43:    dec    cmwrk2        ;  Adjust this count
  4336.     clc            ;     and the buffer pointer
  4337.     lda    cm.bfp        ;         ...
  4338.     adc    #1        ;         ...
  4339.     sta    cm.bfp        ;         ...
  4340.     bcc    cmnb44        ;         ...
  4341.     inc    cm.bfp+1    ;         ...
  4342. cmnb44:    lda    cmccnt        ;  Get the command buffer length
  4343. cmnbcc:    sec            ;[37] Get the cursor coordinates
  4344.     jsr    ploth        ;[37]        ...
  4345. ;    sty    savey        ;[37] Save cursor position
  4346.     stx    savex        ;[37] Save cursor position
  4347. ;    cmp    savey        ;[37]  Check against horizontal cursor position
  4348.     cmp    savex        ;[37]  Check against horizontal cursor position
  4349.     bmi    cmnbna        ;  It's smaller, skip vert. cursor adjust
  4350. ;    dex            ;[37]  Adjust cursor vertical position
  4351.     dey            ;[37]  Adjust cursor vertical position
  4352.     pha            ; Save the AC across this call
  4353.     clc            ;[37] Set the cursor to the new position
  4354.     jsr    ploth        ;[26]        ...
  4355.     pla            ; Restore the AC
  4356.     sec            ;  Reflect this in number of characters
  4357.     sbc    #$28        ;     we skipped back over
  4358.     jmp    cmnbcc        ;  Go check again
  4359. cmnbna:    lda    #0        ;  Put a null at the end of the buffer
  4360.     ldy    #0        ;         ...
  4361.     sta    (cm.bfp),y    ;         ...
  4362.     jsr    screl2        ;  Clear current line
  4363.     sec            ;[37] Get the cursor position
  4364.     jsr    ploth        ;[37]        ...
  4365. ;    ldy    #0        ;[EL] Zero the column number
  4366.     ldx    #0        ;[EL] Zero the column number
  4367.     clc            ;[37]        ...
  4368.     jsr    ploth        ;[26]        ...
  4369.     ldx    cm.rty        ;  Reprint prompt
  4370.     ldy    cm.rty+1    ;         ...
  4371.     jsr    prstr        ;         ...
  4372.     ldx    #cmbuf\        ;  Reprint command buffer
  4373.     ldy    #cmbuf^        ;         ...
  4374.     jsr    prstr        ;         ...
  4375.     sec            ;  Now adjust the command character count
  4376.     lda    cmccnt        ;         ...
  4377.     sbc    cmwrk2        ;     by what we have accumulated
  4378.     sta    cmccnt        ;         ...
  4379.     jsr    screl0        ;  Clear to the end of this line
  4380.     jmp    repars        ;  Go reparse the command
  4381. cminac:    inc    cmwrk2        ;  Increment count of chars to back up
  4382.     sec            ;  Adjust the buffer pointer down again
  4383.     lda    cm.bfp        ;         ...
  4384.     sbc    #1        ;         ...
  4385.     sta    cm.bfp        ;         ...
  4386.     bcs    cmnb45        ;  If carry set, skip H.O. byte adjustment
  4387.     dec    cm.bfp+1    ;  Adjust this
  4388. cmnb45:    jmp    cmnb42        ;  Go around once again
  4389.  
  4390. cmib40:    cmp    #quest        ; Need help?
  4391.     beq    cminb6        ;        ...
  4392.     cmp    #esc        ; Is he lazy?
  4393.     beq    cminb6        ;        ...
  4394.     cmp    #cr        ; Are we at end of line?
  4395.     beq    cminb5        ;        ...
  4396.     cmp    #lf        ; End of line?
  4397.     beq    cminb5        ;        ...
  4398.     cmp    #ffd        ; Is it a form feed?
  4399.     bne    cminb7        ; None of the above
  4400.     jsr    scred2        ; clear the screen
  4401.     ldx    #0
  4402.     ldy    #0
  4403.     jsr    scrplt        ; and home the cursor
  4404. cminb5: lda    cmccnt        ; Fetch character count
  4405.     cmp    #1        ; Any characters yet?
  4406.     bne    cminb6        ; Yes
  4407.     jmp    prserr        ; No, parser error
  4408. cminb6: lda    #$FF        ; Go
  4409.     sta    cmaflg        ;    and set the action flag
  4410.     jmp    cminb9        ; Leave
  4411. cminb7:    cmp    #space        ; Is the character a space ?
  4412.     bne    cmnb71        ; No
  4413.     jsr    cout        ; Output the character
  4414.     jmp    cminb1        ; Yes, get another character
  4415. cmnb71:    cmp    #tab        ; Is it a <tab>?
  4416.     bne    cmnb72        ; No
  4417. ;    jsr    cout        ; Output the character
  4418.     jsr    prttab        ;[46]
  4419.     jmp    cminb1        ; Yes, get more characters 
  4420. cmnb72:    jsr    cout        ; Print the character on the screen
  4421.     jmp    cminb1        ; Get more characters
  4422. cminb9: dec    cmccnt        ; Decrement the count once
  4423.     plp            ; Restore the processor status
  4424.     pla            ;    the Y register
  4425.     tay            ;        ...
  4426.     pla            ;    the X register
  4427.     tax            ;        ...
  4428.     pla            ;    and the AC
  4429.     rts            ;    and return!
  4430.  
  4431.  
  4432. .SBTTL    Cmgtch - get a character from the command buffer
  4433.  
  4434. ;
  4435. ;    This routine takes the next character out of the command
  4436. ;    buffer, does some checking (action character, space, etc.)
  4437. ;    and then returns it to the calling program in the AC
  4438. ;
  4439. ;        Input:  NONE
  4440. ;
  4441. ;        Output: A-    Next character from command buffer
  4442. ;
  4443. ;        Registers destroyed:    A,X,Y
  4444. ;
  4445.  
  4446. cmgtch: ldy    #0        ; Y should always be zero here to index buffer
  4447.     lda    cmaflg        ; Fetch the action flag
  4448.     cmp    #0        ; Set??
  4449.     bne    cmgt1        ; Yes
  4450.     jsr    cminbf        ; No, go fetch some more input
  4451. cmgt1:  lda    (cm.ptr),y    ; Get the next character
  4452.     tax            ; Hold on to it here for a moment
  4453.     clc            ; Clear the carry flag
  4454.     lda    cm.ptr        ; Increment
  4455.     adc    #1        ;    the next character pointer
  4456.     sta    cm.ptr        ;        ...
  4457.     bcc    cmgt2        ;        ...
  4458.     inc    cm.ptr+1    ; Have carry, increment H.O. byte
  4459. cmgt2:  txa            ; Now, get the data
  4460.     cmp    #space        ; Space?
  4461.     beq    cmgtc2        ; Yes
  4462.     cmp    #tab        ; <tab>?
  4463.     bne    cmgtc3        ; Neither space nor <tab>
  4464. cmgtc2:    pha            ; Hold the character here till we need it
  4465.     lda    #cmtxt        ; Are we parsing a string?
  4466.     cmp    cmstat        ;         ...
  4467.     beq    cmgtis        ; Yes, ignore space flag test
  4468.     lda    #cmifi        ; Are we parsing a file name?
  4469.     cmp    cmstat        ;        ...
  4470.     beq    cmgtis        ; Yes, ignore the space flag test
  4471.     lda    cmsflg        ; Get the space flag
  4472.     cmp    #0        ; Was the last character a space?
  4473.     beq    cmgtis        ;  No, go set space flag
  4474.     pla            ;  Pop the character off
  4475.     jmp    cmgtch        ;  But ignore it and get another
  4476. cmgtis:    lda    #$FF        ; Set
  4477.     sta    cmsflg        ;    the space flag
  4478.     pla            ;  Restore the space or <tab>
  4479.     jmp    cmgtc5        ; Go return
  4480. cmgtc3: php            ; Save the processor status
  4481.     pha            ; Save this so it doesn't get clobbered
  4482.     lda    #0        ; Clear AC
  4483.     sta    cmsflg        ; Clear space flag
  4484.     pla            ; Restore old AC
  4485.     plp            ; Restore the processor status
  4486.     cmp    #esc        ; Escape?
  4487.     beq    cmgtc5        ;
  4488.     cmp    #quest        ; Need help?
  4489.     beq    cmgtc4        ;
  4490.     cmp    #cr        ; <cr>?
  4491.     beq    cmgtc4        ;
  4492.     cmp    #lf        ; <lf>?
  4493.     beq    cmgtc4        ;
  4494.     cmp    #ffd        ; <ff>?
  4495.     beq    cmgtc4        ;
  4496.     and    #$7F        ; Make sure the character is positive
  4497.     rts            ; Not an action character, just return
  4498. cmgtc4: tax            ; Hold the data
  4499.     sec            ; Set the carry flag
  4500.     lda    cm.ptr        ; Get the next character pointer
  4501.     sbc    #1        ;    and decrement it
  4502.     sta    cm.ptr        ;
  4503.     bcs    cmgtc5        ;
  4504.     dec    cm.ptr+1    ;
  4505. cmgtc5: txa            ; Now, fetch the data
  4506.     ora    #$80        ; Make it look like a terminator
  4507.     rts            ; Go back
  4508.  
  4509. .SBTTL    Prcrlf subroutine - print a crelf
  4510.  
  4511. ;
  4512. ;    This routine sets up a call to prstr pointing to the crlf
  4513. ;    string.
  4514. ;
  4515. ;        Registers destroyed:    A
  4516. ;
  4517. ;
  4518. prcl.0:    txa            ; save x
  4519.     pha
  4520.     tya            ; and y
  4521.     pha
  4522.     lda    #ATEOL        ; get an EOL
  4523. ;    jsr    sputch        ; out it goes
  4524.     jsr    scrput        ; general case, please
  4525.     pla            ; get
  4526.     tay            ;  our
  4527.     pla            ;   bags
  4528.     tax            ;    back
  4529.     rts
  4530. ;
  4531. .SBTTL    Prstr subroutine
  4532.  
  4533. ;
  4534. ;    This routine prints a string ending in a null.
  4535. ;
  4536. ;        Input:  X-    Low order byte address of string
  4537. ;            Y-    High order byte address of string
  4538. ;
  4539. ;        Output:        Prints string on screen
  4540. ;
  4541. ;        Registers destroyed:    A,X,Y
  4542. ;
  4543. ; superceeded by pstrnul 
  4544. ;
  4545. prst.0:    jmp    pstrnul
  4546.  
  4547. ;
  4548. ; jrd removed routine 'dely' (delay 2 ms) here cause it seemed not to 
  4549. ; be used anyplace 
  4550.  
  4551. .SBTTL    Mul16 - 16-bit multiply routine
  4552.  
  4553. ;
  4554. ;    This and the following four routines is math support for the
  4555. ;    Comnd package. These routines come from '6502 Assembly Language
  4556. ;    Subroutines' by Lance A. Leventhal. Refer to that source for
  4557. ;    more complete documentation.
  4558. ;
  4559.  
  4560. ml16:    pla            ; Save the return address
  4561.     sta    rtaddr        ;        ...
  4562.     pla            ;        ...
  4563.     sta    rtaddr+1    ;        ...
  4564.     pla            ; Get multiplier
  4565.     sta    mlier        ;        ...
  4566.     pla            ;        ...
  4567.     sta    mlier+1        ;        ...
  4568.     pla            ; Get multiplicand
  4569.     sta    mcand        ;        ...
  4570.     pla            ;        ...
  4571.     sta    mcand+1        ;        ...
  4572.     lda    #0        ; Zero
  4573.     sta    hiprod        ;    high word of product
  4574.     sta    hiprod+1    ;        ...
  4575.     ldx    #17        ; Number of bits in multiplier plus 1, the
  4576.                 ;    extra loop is to move the last carry
  4577.                 ;    into the product.
  4578.     clc            ; Clear carry for first time through the loop
  4579. mullp:  ror    hiprod+1    ; Shift the whole thing down
  4580.     ror    hiprod        ;        ...
  4581.     ror    mlier+1        ;        ...
  4582.     ror    mlier        ;        ...
  4583.     bcc    deccnt        ; Branch if next bit of multiplier is 0
  4584.     clc            ; next bit is 1 so add multiplicand to product
  4585.     lda    mcand        ;        ...
  4586.     adc    hiprod        ;        ...
  4587.     sta    hiprod        ;        ...
  4588.     lda    mcand+1        ;        ...
  4589.     adc    hiprod+1    ;        ...
  4590.     sta    hiprod+1    ; Carry = overflow from add
  4591. deccnt: dex            ;        ...
  4592.     bne    mullp        ; Continue until done
  4593.     lda    mlier+1        ; Get low word of product and push it
  4594.     pha            ;    onto the stack
  4595.     lda    mlier        ;        ...
  4596.     pha            ;        ...
  4597.     lda    rtaddr+1    ; Restore the return address
  4598.     pha            ;        ...
  4599.     lda    rtaddr        ;        ...
  4600.     pha            ;        ...
  4601.     rts            ; Return
  4602.  
  4603. mcand:    ;  .blkb    2        ; Multiplicand
  4604.     .word    0
  4605. mlier:  ;    .blkb    2        ; Multiplier and low word of product
  4606.     .word    0
  4607. hiprod: ;    .blkb    2        ; High word of product
  4608.     .word    0
  4609. rtaddr: ;    .blkb    2        ; Save area for return address
  4610.     .word    0
  4611.  
  4612. .SBTTL    Rskp - Do a skip return
  4613.  
  4614. ;
  4615. ;    This routine returns, skipping the instruction following the
  4616. ;    original call. It is assumed that the instruction following the
  4617. ;    call is a JMP.
  4618. ;
  4619. ;        Input:
  4620. ;
  4621. ;        Output:
  4622. ;
  4623. ;        Registers destroyed:    None
  4624. ;
  4625.  
  4626. rskp.0:    sta    savea        ; Save the registers
  4627.     stx    savex        ;
  4628.     sty    savey        ;
  4629.     pla            ; Get Low order byte of return address
  4630.     tax            ; Hold it
  4631.     pla            ; Get High order byte
  4632.     tay            ; Hold that
  4633.     txa            ; Get Low order byte
  4634.     clc            ; Clear the carry flag
  4635.     adc    #4        ; Add 4 to the address
  4636.     bcc    rskp2        ; No carry
  4637.     iny            ; Increment the high order byte
  4638. rskp2:  sta    saddr        ; Store L.O. byte
  4639.     sty    saddr+1        ; Store H.O. byte
  4640.     lda    savea        ;
  4641.     ldx    savex        ;
  4642.     ldy    savey        ;
  4643.     jmp    (saddr)        ; Jump at the new address
  4644.  
  4645. .SBTTL    Setbrk and Rstbrk
  4646.  
  4647. ;
  4648. ;    These routines are called from the user program to set or reset
  4649. ;    break characters to be used by Cmunqs. The byte to set or reset
  4650. ;    is located in the Accumulator. Rstbrk has the option to reset
  4651. ;    the entire break-word. This occurs if the H.O. bit of AC is on.
  4652. ;
  4653.  
  4654. sbrk.0:    and    #$7F        ; We don't want the H.O. bit
  4655.     ldy    #0        ; Set up Y to index the byte we want
  4656. sbrkts:    cmp    #8        ; Is the offset > 8
  4657.     bmi    sbrkfw        ; No, we are at the right byte now
  4658.     sec            ; Yes, adjust it down again
  4659.     sbc    #8        ;        ...
  4660.     iny            ; Advance index
  4661.     jmp    sbrkts        ;    and try again
  4662. sbrkfw:    tax            ; This is the remaining offset
  4663.     lda    #$80        ; Start with H.O. bit on
  4664. sbrklp:    cpx    #0        ; Is it necessary to shift down?
  4665.     beq    sbrkfb        ; No, we are done
  4666.     dex            ; Yes, adjust offset
  4667.     lsr    a        ; Shift bit down once
  4668.     jmp    sbrklp        ; Go back and try again
  4669. sbrkfb:    ora    brkwrd,y    ; We found the bit, use the byte offset
  4670.     sta    brkwrd,y    ;    from above, set the bit and resave
  4671.     rts            ; Return
  4672.  
  4673. rbrk.0:    asl    a        ; Check H.O. bit
  4674.     bcs    rbrkal        ; If that was on, Zero entire brkwrd
  4675.     lsr    a        ; Else shift back (H.O. bit is zeroed)
  4676. rbrkts:    cmp    #8        ; Are we in the right word?
  4677.     bmi    rbrkfw        ; Yes, go figure the rest of the offset
  4678.     sec            ; No, Adjust the offset down
  4679.     sbc    #8        ;        ...
  4680.     iny            ;    and the index up
  4681.     jmp    rbrkts        ; Try again
  4682. rbrkfw:    tax            ; Stuff the remaining offset in X
  4683.     lda    #$7F        ; Start with H.O. bit off
  4684. rbrklp:    cpx    #0        ; Do we need to offset some more?
  4685.     beq    rbrkfb        ; No, we have the correct bit
  4686.     dex            ; Yes, decrement the offset
  4687.     sec            ; Make sure carry is on
  4688.     ror    a        ;    and rotate a 1 bit into mask
  4689.     jmp    rbrklp        ; Go back and try again
  4690. rbrkfb:    and    brkwrd,y    ; We found the bit, now shut it off
  4691.     sta    brkwrd,y    ;        ...
  4692.     rts            ;    and return
  4693. rbrkal:    lda    #0        ; Go stuff zeros in the entire word
  4694.     ldy    #0        ;        ...
  4695. rbrksz:    sta    brkwrd,y    ; Stuff the zero
  4696.     iny            ; Up the index once
  4697.     cpy    #$10        ; Are we done?
  4698.     bmi    rbrksz        ; Not yet
  4699.     rts            ; Yes, return
  4700.  
  4701. .SBTTL    Chkbrk
  4702.  
  4703. ;
  4704. ;    Chkbrk - This routine looks for the flag in the break word
  4705. ;    which represents the character passed to it. If this bit is
  4706. ;    on, it is a break character and the routine will simply
  4707. ;    return. If it is not a break character, the routine skips..
  4708. ;
  4709.  
  4710. chkbrk:    sta    savea        ; Save byte to be checked
  4711.     and    #$7F        ; Shut H.O. bit
  4712.     ldy    #0        ; Zero this index
  4713. cbrkts:    cmp    #8        ; Are we at the right word?
  4714.     bmi    cbrkfw        ; Yes, go calculate bit position
  4715.     sec            ; No, adjust offset down
  4716.     sbc    #8        ;        ...
  4717.     iny            ; Increment the index
  4718.     jmp    cbrkts        ; Go back and test again
  4719. cbrkfw:    tax            ; Stuff the remaining offset in X
  4720.     lda    #$80        ; Set H.O. bit on for testing
  4721. cbrklp:    cpx    #0        ; Are we in position yet?
  4722.     beq    cbrkfb        ; Yes, go test the bit
  4723.     dex            ; No, decrement the offset
  4724.     lsr    a        ;    and adjust the bit position
  4725.     jmp    cbrklp        ; Go and try again
  4726. cbrkfb:    and    brkwrd,y    ; See if the bit is on
  4727.     bne    cbrkbc        ; It is a break character
  4728.     lda    savea        ; Restore the character
  4729.     jmp    rskp        ; Not a break character, skip return
  4730. cbrkbc:    lda    savea        ; Restore the character
  4731.     rts            ; Return
  4732.  
  4733. .SBTTL    Cmehlp - Do extra help on Question-mark prompting
  4734.  
  4735. ;
  4736. ;    Cmehlp - This routine uses a string of commands passed to it
  4737. ;    in order to display alternate valid parse types to the user.
  4738. ;
  4739. ;        Input:    Cmehpt-    Pointer to valid parse types (end in 00)
  4740. ;
  4741. ;        Output:    Display on screen, alternate parse types
  4742. ;
  4743. ;        Registers destroyed:    A,X,Y
  4744. ;
  4745.  
  4746. cmehlp:    lda    cmstat        ; We are going to need this so
  4747.     pha            ;    save it across the call
  4748.     ldy    #0        ; Zero out the help index
  4749.     sty    cmehix        ;        ...
  4750. cmehl1:    ldy    cmehix        ; Load the extra help index
  4751.     lda    (cmehpt),y    ; Fetch next type
  4752.     sta    cmstat        ; Store it here
  4753.     inc    cmehix        ; Increase the index by one
  4754.     cmp    #0        ; Is the type null?
  4755.     bne    cmeh0        ; No, continue
  4756.     jmp    cmehrt        ; Yes, terminate
  4757. cmeh0:    cmp    #cmtok+1    ; If the type is out of range, leave
  4758.     bmi    cmeh1        ;        ...
  4759.     jmp    cmehrt        ;        ...
  4760. cmeh1:    pha            ; Save the type across the call
  4761.     ldx    #cmors\        ; Set up address of 'OR ' string
  4762.     ldy    #cmors^        ;        ...
  4763.     jsr    prstr        ;    and print it
  4764.     pla            ; Restore AC
  4765.     cmp    #cmkey        ; Compare with keyword
  4766.     bne    cmeh2        ; No, try next type
  4767. cmeh10:    tax            ; Hold type in X register
  4768.     lda    cmsptr        ; Save these parms so they can be restored
  4769.     pha            ;        ...
  4770.     lda    cmsptr+1    ;        ...
  4771.     pha            ;        ...
  4772.     lda    cm.ptr        ; Copy the pointer to the saved pointer
  4773.     sta    cmsptr        ;    so the keyword print routine prints
  4774.     pha            ;    the entire table. Also, save it on
  4775.     lda    cm.ptr+1    ;    the stack so it can be restored later
  4776.     sta    cmsptr+1    ;        ...
  4777.     pha            ;        ...
  4778.     lda    cmptab        ; Save the table address also
  4779.     pha            ;        ...
  4780.     lda    cmptab+1    ;        ...
  4781.     pha            ;        ...
  4782.     txa            ; Restore type
  4783.     cmp    #cmkey        ; Keyword?
  4784.     bne    cmeh11        ; No, it must be a switch table
  4785.     ldx    #cmin01\    ; Set up address of message
  4786.     ldy    #cmin01^    ;        ...
  4787.     jmp    cmeh12        ; Go print the string
  4788. cmeh11:    ldx    #cmin02\    ; Set up address of 'switch' string
  4789.     ldy    #cmin02^    ;        ...
  4790. cmeh12:    jsr    prstr        ; Print the message
  4791.     ldy    cmehix        ; Get the index into help string
  4792.     lda    (cmehpt),y    ; Fetch L.O. byte of table address
  4793.     sta    cmptab        ; Set that up for Cmktp
  4794.     iny            ; Increment the index
  4795.     lda    (cmehpt),y    ; Get H.O. byte
  4796.     sta    cmptab+1    ; Set it up for Cmktp
  4797.     iny            ; Advance the index
  4798.     sty    cmehix        ;    and store it
  4799.     jsr    cmktp        ; Print the keyword table
  4800.     pla            ; Now restore all the stuff we saved before
  4801.     sta    cmptab+1    ;        ...
  4802.     pla            ;        ...
  4803.     sta    cmptab        ;        ...
  4804.     pla            ;        ...
  4805.     sta    cm.ptr+1    ;        ...
  4806.     pla            ;        ...
  4807.     sta    cm.ptr        ;        ...
  4808.     pla            ;        ...
  4809.     sta    cmsptr+1    ;        ...
  4810.     pla            ;        ...
  4811.     sta    cmsptr        ;        ...
  4812.     jmp    cmehl1        ; See if there is more to do
  4813. cmeh2:    cmp    #cmswi        ; Type is switch?
  4814.     bne    cmeh3        ; No, continue
  4815.     jmp    cmeh10        ; We can treat this just like a keyword
  4816. cmeh3:    cmp    #cmifi        ; Input file?
  4817.     bne    cmeh4        ; No, go on
  4818.     ldx    #cmin03\    ; Set up the message address
  4819.     ldy    #cmin03^    ;        ...
  4820.     jmp    cmehps        ; Go print it
  4821. cmeh4:    cmp    #cmofi        ; Output file?
  4822.     bne    cmeh5        ; Nope, try again
  4823.     ldx    #cmin04\    ; Set up message address
  4824.     ldy    #cmin04^    ;        ...
  4825.     jmp    cmehps        ; Go print the string
  4826. cmeh5:    cmp    #cmcfm        ; Confirm?
  4827.     bne    cmeh6        ; No
  4828.     ldx    #cmin00\    ; Set up address
  4829.     ldy    #cmin00^    ;        ...
  4830.     jmp    cmehps        ; Print the string
  4831. cmeh6:    cmp    #cmtxt        ; Unquoted string?
  4832.     bne    cmeh7        ; No, try next one
  4833.     ldx    #cmin06\    ; Set up address
  4834.     ldy    #cmin06^    ;        ...
  4835.     jmp    cmehps        ; Print
  4836. cmeh7:    cmp    #cmnum        ; Integer?
  4837.     bne    cmeh8        ; Try again
  4838.     ldx    #cmin05\    ; Set up message
  4839.     ldy    #cmin05^    ;        ...
  4840.     jsr    prstr        ; Print it
  4841.     ldy    cmehix        ; Get index
  4842.     inc    cmehix        ; Advance index
  4843.     lda    (cmehpt),y    ; Get base of integer
  4844.     cmp    #$0A        ; Is it greater than decimal 10?
  4845.     bmi    cmeh71        ; No, just print the L.O. digit
  4846.     lda    #$31        ; Print the H.O. digit as a 1
  4847.     jsr    cout        ; Print the '1'
  4848.     ldy    cmehix        ; Load index
  4849.     dey            ; Point back to last byte
  4850.     lda    (cmehpt),y    ; Get the base back
  4851.     sec            ; Set the carry flag for subtraction
  4852.     sbc    #$0A        ; Subtract off decimal 10
  4853. cmeh71:    clc            ; Clear carry for addition
  4854.     adc    #$30        ; Make it printable
  4855.     jsr    cout        ; Print the digit
  4856.     jsr    prcrlf        ; Print a crelf
  4857.     jsr    prbyte        ; Print the byte
  4858.     jmp    cmehl1        ; Go back for more
  4859. cmeh8:    ldx    #cmin07\    ; Assume it's a token
  4860.     ldy    #cmin07^    ;        ...
  4861. cmehps:    jsr    prstr        ; Print string
  4862.     jsr    prcrlf        ; Print a crelf
  4863.     jmp    cmehl1        ; Go back
  4864. cmehrt:    pla            ; Restore
  4865.     sta    cmstat        ;    current parse type
  4866.     rts
  4867.  
  4868. .SBTTL    Cmcpdf - Copy a default string into the command buffer
  4869.  
  4870. ;
  4871. ;    Cmcpdf - This routine copies a default for a field
  4872. ;    into the command buffer andreparses the string.
  4873. ;
  4874. ;        Input:    Cmdptr-    Pointer to default field value (asciz)
  4875. ;
  4876. ;        Output:
  4877. ;
  4878. ;        Registers destroyed:    A,X,Y
  4879. ;
  4880.  
  4881. cmcpdf:    sec            ; Reset the buffer pointer
  4882.     lda    cm.bfp        ;        ...
  4883.     sbc    #1        ;        ...
  4884.     sta    cm.bfp        ;        ...
  4885.     bcs    cmcpst        ; If carry set, don't adjust H.O. byte
  4886.     dec    cm.bfp+1    ;        ...
  4887. cmcpst:    dec    cmccnt        ; Adjust the character count
  4888.     ldy    #0        ; Zero the index
  4889. cmcplp:    lda    (cmdptr),y    ; Get byte
  4890.     beq    cmcpdn        ; Copy finished, leave
  4891.     ldx    cmccnt        ; Check character count
  4892.     inx            ; If it is just short of wrapping
  4893.     bne    cmcpl1        ;    then we are overflowing buffer
  4894.     jsr    bell        ; If that is the case, tell the user
  4895.     dec    cmccnt        ; Make sure it doesn't happen again
  4896.     jmp    prserr        ;    for same string.
  4897. cmcpl1:    
  4898.     ora    #$80        ; Be consistent, make sure H.O. bit is on
  4899.     sta    (cm.bfp),y    ; Stuff it in the buffer
  4900.     inc    cmccnt        ; Adjust character count
  4901.     iny            ; Up the buffer index
  4902.     jmp    cmcplp        ; Go to top of loop
  4903. cmcpdn:    lda    #space        ; Get a space
  4904.     sta    (cm.bfp),y    ;    and place it in buffer after keyword
  4905.     iny            ; Increment the buffer index
  4906.     lda    #nul        ; Get a null
  4907.     sta    (cm.bfp),y    ;    and stuff that at the end of buffer
  4908.     clc            ; Now recompute the end of usable buffer
  4909.     tya            ; Get the number of chars added
  4910.     adc    cm.bfp        ; Add that to the buffer pointer
  4911.     sta    cm.bfp        ;        ...
  4912.     lda    #0        ;        ...
  4913.     adc    cm.bfp+1    ;        ...
  4914.     sta    cm.bfp+1    ;        ...
  4915.     lda    #0        ; Reset the action flag
  4916.     sta    cmaflg        ;        ...
  4917.     sec            ; Now adjust the command pointer to the
  4918.     lda    cm.ptr        ;    beginning of the copied field
  4919.     sbc    #1        ;        ...
  4920.     tax            ; Set it up in X and Y so we can call Prstr
  4921.     lda    cm.ptr+1    ;        ...
  4922.     sbc    #0        ;        ...
  4923.     tay            ;        ...
  4924.     jsr    prstr        ; Print the added field
  4925.     jmp    repars        ; Now go reparse the whole command
  4926.  
  4927. .SBTTL    Comnd Jsys messages and table storage
  4928.  
  4929. cmer00: .byte    cr,"?program error:  invalid comnd call",0        ; [53]
  4930. cmer01: .byte    cr,"?ambiguous",0        ; [53]
  4931. cmer02: .byte    cr,"?illegal input file spec",0        ; [53]
  4932. cmer03: .byte    cr,"?no keywords match this prefix",0        ; [53]
  4933. cmer04: .byte    cr,"?no switches match this prefix",0        ; [53]
  4934. cmer05: .byte    cr,"?bad character in integer number",0        ; [53]
  4935. cmer06: .byte    cr,"?base of integer out of range",0        ; [53]
  4936. cmer07: .byte    cr,"?overflow while reading integer number",0        ; [53]
  4937.  
  4938. cmin00: .byte    " confirm with RETURN",0        ; [53]
  4939. cmin01: .byte    " keyword, one of:",0        ; [53]
  4940. cmin02: .byte    " switch, one of:",0        ; [53]
  4941. cmin03: .byte    " input file spec",0        ; [53]
  4942. cmin04: .byte    " output file spec",0        ; [53]
  4943. cmin05: .byte    " integer number in base ",0        ; [53]
  4944. cmin06:    .byte    " unquoted text string ",0        ; [53]
  4945. cmin07:    .byte    " single character token ",0        ; [53]
  4946.  
  4947. cmors:    .byte    " or ",0        ; [53]
  4948.  
  4949. .SBTTL    Kermit defaults for operational parameters
  4950.  
  4951. ;
  4952. ;    The following are the defaults which this Kermit uses for
  4953. ;    the protocol.
  4954. ;
  4955.  
  4956. dquote  =    '#        ; The quote character
  4957. dpakln  =    94        ; The packet length
  4958. dpadch  =    nul        ; The padding character
  4959. dpadln  =    0        ; The padding length
  4960. dmaxtr  =    20        ; The maximum number of tries
  4961. debq    =    '&        ; The eight-bit-quote character
  4962. ;dtime    =    15        ; The default time-out amount
  4963. dtime    =    5        ; [jrd] 5 sec ought to be ok
  4964. deol    =    cr        ; The end-of-line character
  4965.  
  4966. .SBTTL    Kermit data
  4967.  
  4968. ;
  4969. ;    The following is data storage used by Kermit
  4970. ;
  4971.  
  4972. mxpack  =    dpakln        ; Maximum packet size
  4973. mxfnl    =    16        ; Maximum file-name len, "Dn:FROBBOZZ.DAT"
  4974. eof    =    $01        ; This is the value for End-of-file
  4975. buflen  =    $FF        ; Buffer length for received data
  4976. true    =    $01        ; Symbol for true return code
  4977. false    =    $00        ; Symbol for false return code
  4978. on    =    $01        ; Symbol for value of 'on' keyword
  4979. off    =    $00        ; Symbol for value of 'off' keyword
  4980. yes    =    $01        ; Symbol for value of 'yes' keyword
  4981. no    =    $00        ; Symbol for value of 'no' keyword
  4982. terse    =    $01        ; Symbol for terse debug mode
  4983. verbose    =    $02        ; Symbol for verbose debug mode
  4984. xon    =    $11        ; Xon for Ibm-mode
  4985. fbsbit  =    $01        ; Value for SEVEN-BIT FILE-BYTE-SIZE
  4986. fbebit  =    $00        ; Value for EIGHT-BIT FILE-BYTE-SIZE
  4987. nparit    =    $00        ; Value for PARITY NONE
  4988. sparit    =    $01        ; Value for PARITY SPACE
  4989. mparit    =    $02        ; Value for PARITY MARK
  4990. oparit    =    $03        ; Value for PARITY ODD
  4991. eparit    =    $04        ; Value for PARITY EVEN
  4992. ;
  4993. ; NB! these values are internal codes, which should be
  4994. ;  sequential from 0.  The real values for the port are 
  4995. ;  in bdval, indexed by these values
  4996. ;
  4997. bd50    =    $00        ;[17] Value for BAUD 50
  4998. bd75    =    $01        ;[17]
  4999. bd110    =    $02        ;[17] Value for BAUD 110
  5000. bd150    =    $03        ;[17] Value for BAUD 150
  5001. bd300    =    $04        ;[17] Value for BAUD 300
  5002. bd1200    =    $05        ;[17] Value for BAUD 1200
  5003. bd1800    =    $06        ;[17] Value for BAUD 1800
  5004. bd2400    =    $07        ;[17] Value for BAUD 2400
  5005. bd4800    =    $08        ;[17] Value for BAUD 4800
  5006. bd9600    =    $09        ;[17] Value for BAUD 9600
  5007. ;
  5008. ; defs for values in errcod
  5009. ;
  5010. eprflg    =    $40        ;    'Error packet received' flag
  5011. edoflg    =    $80        ;    Dos error code
  5012. ;
  5013. errcri  =    $01        ; Error code - cannot receive init
  5014. errcrf  =    $02        ; Error code - cannot receive file-header
  5015. errcrd  =    $03        ; Error code - cannot receive data
  5016. errmrc  =    $04        ; Error code - maximum retry count exceeded
  5017. errbch  =    $05        ; Error code - bad checksum
  5018. errint    =    $06        ; [jrd] internal error
  5019. errfta    =    $07        ; [jrd] transfer aborted
  5020. errfal    =    $08        ; [jrd] filename alter error
  5021. errfae  =    $09        ; Error code - file already exists
  5022. errfde    =    $0A        ; [jrd] some DOS (typically disk) error
  5023. ;
  5024. ;emesln  =    $19        ; Standard error message length
  5025. kerrns  =    $1F        ; Routine name and action string length
  5026. ;kerdel  =    $15        ; Disk error length
  5027. kerems  =    $19        ; Error message size
  5028. kerfts    =    $08        ; Size of file-type strings (incl. term. nul)
  5029. kerdsz    =    $09        ; Length of debug mode strings
  5030. kerpsl    =    $06        ; Size of parity strings
  5031. kerbsl    =    $05        ;[17] Size of baud strings
  5032. keremu    =    $06        ; size of terminal emulation strings
  5033. kerfrm    =    cminf1        ; 'From string' pointer for Kercpy routine
  5034. kerto    =    cminf2        ; 'To string' pointer for Kercpy routine
  5035.  
  5036. errrkm:    .blkb    mxpack-2    ; Error message from remote Kermit
  5037. pdbuf:  .blkb    mxpack-2    ; Packet buffer
  5038. plnbuf: .blkb    $100        ;[DD] Port line buffer
  5039. pdlen:  .byte    0        ; Common area to place data length
  5040. ptype:  .byte    0        ; Common area to place current packet type
  5041. pnum:    .byte    0        ; Common area to put packet number received
  5042. pdtend: .byte    0        ; End of plnbuf pointer
  5043. pdtind: .byte    0        ; Index for plnbuf
  5044. rstat:  .byte    0        ; Return status
  5045. kerrta: .word    0        ; Save area for return address
  5046. datind: .byte    0        ; Data index into packet buffer
  5047. chebo:  .byte    0        ; Switch to tell if 8th-bit was on
  5048. escflg: .byte    0        ; Flag indicating we have seen an escape ($1b)
  5049. addlf:  .byte    0        ; Add a <lf> flag
  5050. dellf:  .byte    0        ; Flush a <lf> flag
  5051. jtaddr: .word    0        ; Jump table address hold area
  5052. ;hch:    .byte    0        ; Hold area for ch
  5053. ;hcv:    .byte    0        ; Hold area for cv
  5054. kwrk01: .byte    0        ; Work area for Kermit
  5055. kwrk02: .byte    0        ; Work area for Kermit
  5056. kertpc:    .byte    0        ; Hold area for parity check
  5057. ksavea:    .byte    0        ; Save area for accumulator
  5058. ksavex:    .byte    0        ; Save area for X reg
  5059. ksavey:    .byte    0        ; Save area for Y reg
  5060. kerchr: .byte    0        ; Current character read off port
  5061. kermbs: .word    0        ; Base address of message table
  5062. debchk: .byte    0        ; Checksum for debug routine
  5063. debinx: .byte    0        ; Debug routine action index
  5064. fld:    .byte    0        ; State of receive in rpak routine
  5065. retadr: .word    0        ; Hold area for return address
  5066. n:    .byte    0        ; Message #
  5067. numtry: .byte    0        ; Number of tries for this packet
  5068. oldtry: .byte    0        ; Number of tries for previous packet
  5069. maxtry: .byte    dmaxtr        ; Maximum tries allowed for a packet
  5070. state:  .byte    0        ; Current state of system
  5071. local:    .byte    0        ; Local/Remote switch
  5072. size:    .byte    0        ; Size of present data
  5073. chksum: .byte    0        ; Checksum for packet
  5074. rtot:    .word    0        ; Total number of characters received
  5075. stot:    .word    0        ; Total number of characters sent
  5076. rchr:    .word    0        ; Number characters received, current file
  5077. schr:    .word    0        ; Number of characters sent, current file
  5078. rovr:    .word    0        ; Number of overhead characters on receive
  5079. sovr:    .word    0        ; Number of overhead characters on send
  5080. tpak:    .word    0        ; Number of packets for this transfer
  5081. eofinp: .byte    0        ; End-of-file (no characters left to send)
  5082. eodind: .byte    0        ; End-of-data reached on disk
  5083. errcod: .byte    0        ; Error indicator
  5084. ;errrkm:    .blkb    mxpack-2    ; Error message from remote Kermit
  5085. kerosp: .byte    0        ; Save area for stack pointer
  5086. keresp:    .byte    0        ; [jrd] another one for exit time
  5087. kerret:    .word    0        ; [jrd] return address for exit in case
  5088.                 ;  stack trashed
  5089.  
  5090. ;
  5091. ; equates for terminal types
  5092. ;
  5093. ttnone    =    0        ; terminal type none, glass tty
  5094. tt52    =    1        ; vt52
  5095. tt100    =    2        ; vt100
  5096.  
  5097. ;
  5098. ; equates for character set designators.  See csg0, csg1 for use
  5099. ;
  5100. csascii    =    0        ; normal ascii font
  5101. csgraf    =    1        ; graphics font
  5102.  
  5103. ;
  5104. ; equates for file types.  NB! the code assumes all text types
  5105. ; are less than all binary types, and that "binary" is the first
  5106. ; binary type.
  5107. ;
  5108. ftstas    =    0        ; Standard ascii
  5109. ftatas    =    1        ; Atari ASCII
  5110. ftbin    =    2        ; binary
  5111.  
  5112. ;
  5113. ; equates for screen types
  5114. ;
  5115. scrae    =    0        ; Atari E:
  5116. scr40    =    1        ; 40 col visible, pannable to 80
  5117. scr80    =    2        ; 80 col, using highest res graphics
  5118. ;
  5119. scrtype: .byte    scrae        ; Use the Atari E: screen for starters
  5120. ;
  5121. ; This block of stuff (escp .. quote) gets saved and restored.
  5122. ;
  5123. escp:    .byte    $19        ; Character for escape from connection
  5124. ;fbsize: .byte    fbsbit        ; File-byte-size
  5125. capslck: .byte    0        ; [jrd] caps lock, default off
  5126. filmod: .byte    ftatas        ; Current file type, default atascii
  5127. usehdr: .byte    off        ; Switch - where to get filename (on=file-head)
  5128. lecho:  .byte    off        ; Local-echo switch
  5129. ibmmod: .byte    off        ; Ibm-mode switch
  5130. vtmod:  .byte    tt100        ; VT-52 Emulation mode switch, default off
  5131. conscrt: .byte    scr80        ; screen to use in terminal mode.  Default 80
  5132. parity: .byte    nparit        ; Parity setting
  5133. baud:    .byte    bd1200        ;[17] Baud setting
  5134. wrdsiz:    .byte    fbebit        ;[17] Word length setting
  5135. flowmo:    .byte    off        ;[24] Flow-Control switch
  5136. delay:  .byte    0        ; Amount of delay before first send
  5137. filwar: .byte    off        ; File-warning switch
  5138. debug:  .byte    off        ; Debug switch
  5139. ebqmod: .byte    off        ; Eight-bit-quoting mode
  5140. ; parameters for the XIO 36 (set baud rate etc] call in openrs
  5141. x36ax1:    .byte    $0A        ; [jrd] the AUX1 value for the XIO 36.  1200 bps default
  5142. x38ax1:    .byte    $00        ; [jrd] the AUX1 value for the XIO 38.  no parity default
  5143.  
  5144. ;
  5145. ;    These fields are set parameters and should be kept in this
  5146. ;    order to insure integrity when setting and showing values
  5147. ;
  5148.  
  5149. srind:  .byte            ; Switch to indicate which parm to print
  5150. ebq:    .byte    debq        ; Eight-bit quote character (rec. and send)
  5151.     .byte    debq        ;        ...
  5152. pad:    .byte    dpadln        ; Number of padding characters (rec. and send)
  5153.     .byte    dpadln        ;        ...
  5154. padch:  .byte    dpadch        ; Padding character (receive and send)
  5155.     .byte    dpadch
  5156. eol:    .byte    deol        ; End-of-line character (recevie and send)
  5157.     .byte    deol
  5158. psiz:    .byte    dpakln        ; Packet size (receive and send)
  5159.     .byte    dpakln
  5160. time:    .byte    dtime        ; Time-out interval (receive and send)
  5161.     .byte    dtime        ;
  5162. quote:  .byte    dquote        ; Quote character (receive and send)
  5163.     .byte    dquote        ;        ...
  5164.  
  5165. ;ttime:    .word    $0000        ;[49] Time out interval (receive and send)
  5166. ttime:    .word    $0000        ; [jrd] recv/send Timer expiration time, hi,lo
  5167.  
  5168. ;
  5169. ;    Some definitions to make life easier when referencing the above
  5170. ;    fields.
  5171. ;
  5172.  
  5173. rebq    =    ebq        ; Receive eight-bit-quote char
  5174. sebq    =    ebq+1        ; Send eight-bit-quote char
  5175. rpad    =    pad        ; Receive padding amount
  5176. spad    =    pad+1        ; Send padding amount
  5177. rpadch    =    padch        ; Receive padding character
  5178. spadch    =    padch+1        ; Send padding character
  5179. reol    =    eol        ; Receive end-of-line character
  5180. seol    =    eol+1        ; Send end-of-line character
  5181. rpsiz    =    psiz        ; Receive packet length
  5182. spsiz    =    psiz+1        ; Send packet length
  5183. rtime    =    time        ; Receive time out interval
  5184. stime    =    time+1        ; Send time out interval
  5185. rquote    =    quote        ; Receive quote character
  5186. squote    =    quote+1        ; Send quote character
  5187.  
  5188. .SBTTL    Kermit - CBM DOS support
  5189.  
  5190. ;
  5191. ;    The following definitions and storage will be used when setting
  5192. ;    up and executing calls to the DOS.
  5193. ;
  5194.  
  5195. fncrea  =    'R        ; Read function code
  5196. fncwrt  =    'W        ; Write function code
  5197. drdoll    =    '$        ;[40] Directory string
  5198. drcolo    =    ':        ;[40]
  5199. drstar    =    '*        ;[40]
  5200. ; [jrd] not here you don't
  5201. ;kerfcb    =    $1e        ; Pointer to FCB
  5202. ;buff    =    $200        ; Temp disk char read
  5203. ;buff:    .byte    0
  5204. ;fmrcod: .byte    0        ; Disk status return code
  5205. decnum:    .word            ; [54] Number being converted to decimal
  5206. ;dskers: .blkb    110        ; Storage for disk error messages
  5207. dosffm:    .byte    $00        ; 'First file modification done' switch
  5208. ;dosfni:    .byte    $00        ; Filename index
  5209. dosfvn:    .byte    $00        ; File version number for the alter routine
  5210. ;
  5211. ; pathname descriptors
  5212. ;
  5213. primfn: .blkb    mxfnl+mxfnl+1    ; File name for local opens
  5214.                 ;  double size for renames...
  5215.     .byte    0        ; sanity check...
  5216. fcb1:    .blkb    mxfnl+1        ; buffer for typing names into
  5217.     .byte    0        ; sanity check...
  5218. ;
  5219. ; the default pathname
  5220. ;
  5221. defpath:
  5222.     .byte    pnf.dp!pnf.np!pnf.ep ; contains, dev, name, and type
  5223.     .byte    2        ; dev max
  5224.     .byte    2,"D1"        ; dev size, text
  5225.     .byte    8        ; name max
  5226.     .byte    3,"FOO     "    ; name size, text
  5227.     .byte    3        ; ext max
  5228.     .byte    3,"DAT"        ; ext size, text
  5229. ;
  5230. wildfn:    .byte    "*.*",0        ; wild file name, for defaults in cp
  5231. ;
  5232. dsknum    =    defpath+4    ; address of the '1'
  5233. ;
  5234. ;path:    .blkb    pndsiz        ; one for random pathnames that come in
  5235. path:                ; one for random pathnames that come in
  5236.     .byte    0        ; flags
  5237.     .byte    2,0,0,0
  5238.     .byte    8,0,0,0,0,0,0,0,0,0
  5239.     .byte    3,0,0,0,0
  5240. ;
  5241. dirpath:            ; one for directory entries
  5242.     .byte    0        ; flags
  5243.     .byte    2,0,0,0
  5244.     .byte    8,0,0,0,0,0,0,0,0,0
  5245.     .byte    3,0,0,0,0
  5246. ;
  5247. dirplck: .byte    0        ; 'locked' flag for current dirpath
  5248. dirsect: .byte    "    ",ATEOL    ; buf for sector count strg
  5249. ;
  5250. ;
  5251. flsrw:  .byte    0        ; Switch for r(ead) or w(rite)
  5252. ;
  5253. prmt:    .byte    "Kermit-65>"    ; Prompting text
  5254.     .byte    0        ; [53]
  5255. lprmt    =    .-prmt        ; Length of prompting text
  5256. connec:    .byte    $00        ;[48] non-zero if in terminal mode
  5257.  
  5258.  
  5259. .SBTTL    Kermit initialization
  5260.  
  5261. ;
  5262. ;    The following code sets up Kermit-65 for normal operation.
  5263. ;    This is the main entry point.  There is currently no warmstart
  5264. ;    entry point.
  5265. ;
  5266. kstart:    
  5267.     pla            ; [jrd] save return address
  5268.     sta    kerret        ;  for exit time
  5269.     pla
  5270.     sta    kerret+1
  5271.     tsx            ; save SP too
  5272.     stx    keresp
  5273. ;
  5274.     jsr    openscr        ; [jrd] open screen, so we can talk to user.
  5275. ; [jrd]    jsr    clall        ;[] First close all open channels
  5276. ; [jrd]    jsr    ioinit        ;[16] Initialize I/O devices
  5277. ; [jrd]    jsr    restoi
  5278. ;     jsr    scrini        ; [jrd] zzz what should this be here?
  5279. ; [jrd]    lda    r6510        ;[17] Start by paging out BASIC ROM
  5280. ; [jrd]    and    #$fe        ;[17]        ...
  5281. ; [jrd]    sta    r6510        ;[17]        ...
  5282. ;
  5283.     jsr    restin        ; try to read and parse init file
  5284.  
  5285. init:
  5286. ;
  5287. ; fix margins
  5288. ;
  5289.     lda    #0
  5290.     sta    LMARGN
  5291. ;
  5292. ; 4/11/90 jrd.  Don't frob with right margin, so as not to screw up
  5293. ; XEP 80 support.  This means we'll lose big if something else has
  5294. ; screwed it up already.  BFD...
  5295. ;
  5296. ;    lda    #39
  5297. ;    sta    RMARGN
  5298. ;
  5299.     jsr    dopari        ;[]
  5300.     jsr    dobad        ;[]
  5301.     jsr    dowrd        ;[]
  5302.     ldx    #versio\    ;Get address of version message
  5303.     ldy    #versio^    ;        ...
  5304.     jsr    prstr        ;Print the version
  5305.     jsr    prcrlf        ;Print a crlf
  5306. ;    jsr    kermit        ;Go execute kermit
  5307.     jsr    kerm        ; [jrd] Go execute kermit
  5308.     jmp    exit1        ;[17] and reenter BASIC
  5309.  
  5310. ;
  5311. ; debug stack stuff
  5312. ;
  5313. ;dbgstk:
  5314. ;    jsr    prstr        ; print the string
  5315. ;    tsx
  5316. ;    stx    freemem        ; temp
  5317. ;    txa
  5318. ;    jsr    prbyte
  5319. ;    lda    #':
  5320. ;    jsr    prchr
  5321. ;    lda    #16
  5322. ;    sta    freemem+1
  5323. ;dbgstk1:
  5324. ;    ldx    freemem
  5325. ;    lda    $100,x
  5326. ;    inx
  5327. ;    stx    freemem
  5328. ;    jsr    prbyte
  5329. ;    lda    #space
  5330. ;    jsr    prchr
  5331. ;    dec    freemem+1
  5332. ;    bne    dbgstk1
  5333. ;    jsr    prcrlf
  5334. ;    rts
  5335.  
  5336. .SBTTL    Kermit - main routine
  5337.  
  5338. ;
  5339. ;    This routine is the main KERMIT loop. It prompts for commands
  5340. ;    and then it dispatches to the appropriate routine.
  5341. ;
  5342. ;kmtxt:    .byte    ATEOL,"Main ",0
  5343. kerm:                ; [jrd] kermit routine init
  5344.     tsx            ; Get the stack pointer
  5345.     stx    kerosp        ;    and save it in case of a fatal error
  5346. kermloop:             ; kermit main loop
  5347. ;    ldx    #kmtxt\
  5348. ;    ldy    #kmtxt^
  5349. ;    jsr    dbgstk
  5350.     ldx    #prmt\        ;  Fetch the address of the prompt
  5351.     ldy    #prmt^        ;        ...
  5352.     lda    #cmini        ; Argument for comnd call
  5353.     jsr    comnd        ; Set up the parser and print the prompt
  5354.     lda    #kercmd\    ; addr of command table
  5355.     sta    cminf1        ;        ...
  5356.     lda    #kercmd^    ;        ...
  5357.     sta    cminf1+1    ;        ...
  5358.     lda    #kerhlp\    ; Store address of help text
  5359.     sta    cmhptr        ;  in help pointer
  5360.     lda    #kerhlp^    ;        ...
  5361.     sta    cmhptr+1    ;        ...
  5362.     ldy    #$00        ;  No special flags needed
  5363.     lda    #cmkey        ; Set up for keyword parse
  5364.     jsr    comnd        ; Try to parse it
  5365.      jmp    kermt2        ; Failed
  5366. ;
  5367.     stx    jtaddr        ; x,y has vector
  5368.     sty    jtaddr+1    ; set it
  5369.     jmp    (jtaddr)    ; and go there
  5370.  
  5371. ;---
  5372. ;    lda    #kermtb\    ; Get address of jump table
  5373. ;    sta    jtaddr        ;        ...
  5374. ;    lda    #kermtb^    ;        ...
  5375. ;    sta    jtaddr+1    ;        ...
  5376. ;    txa            ; Offset to AC
  5377. ;---
  5378. ; still used in a few places...
  5379. jmpind: clc            ;[DD] Jump indexed
  5380.     adc    jtaddr        ; Add offset to low byte
  5381.     sta    jtaddr        ;        ...
  5382.     bcc    jmpin1        ;        ...
  5383.     inc    jtaddr+1    ; If carry inc high byte
  5384. jmpin1: jmp    (jtaddr)    ; Jump to address
  5385. ;---
  5386.  
  5387. ;
  5388. ;kermtb: jmp    telnet        ; Connect command
  5389. ;    jmp    exit        ; Exit command
  5390. ;    jmp    help        ; Help command
  5391. ;    jmp    log        ; Log command
  5392. ;    jmp    exit        ; Quit command
  5393. ;    jmp    receve        ; Receive command
  5394. ;    jmp    send        ; Send command
  5395. ;    jmp    setcom        ; Set command
  5396. ;    jmp    show        ; Show command
  5397. ;    jmp    status        ; Status command
  5398. ;    jmp    bye        ;[EL] Shut and logout remote server command
  5399. ;    jmp    finish        ;[EL] Shut remote server
  5400. ;    jmp    getfrs        ;[EL] Get file from remote server
  5401. ;    jmp    rename        ;[40] rename files(s)
  5402. ;    jmp    dirst        ;[40] Get directory
  5403. ;    jmp    savst        ;[47] Save parameters
  5404. ;    jmp    restst        ;[47] Restore parameters
  5405. ;    jmp    erase        ; [jrd] erase something
  5406. ;---
  5407. ;
  5408. kermt2: ldx    #ermes1\    ; L.O. byte of error message
  5409.     ldy    #ermes1^    ; H.O. byte of error message
  5410. ;    jsr    prstr        ; Print the error
  5411. ;    jmp    kermit        ; Go back
  5412.     jmp    kermzz        ; [jrd] use common error vector
  5413. ;
  5414. kermt3: ldx    #ermes3\    ; L.O. byte of error
  5415.     ldy    #ermes3^    ; H.O. byte of error
  5416. ;    jsr    prstr        ; Print it
  5417. ;    jmp    kermit        ; Try again
  5418.     jmp    kermzz        ; [jrd] use common error vector
  5419. ;
  5420. kermt4: ldx    #ermes4\    ; L.O. byte of error
  5421.     ldy    #ermes4^    ; H.O. byte of error
  5422. ;    jsr    prstr        ; Print the text
  5423. ;    jmp    kermit        ; Try again
  5424.     jmp    kermzz        ; [jrd] use common error vector
  5425. ;
  5426. kermt5: ldx    #ermes6\    ; L.O. byte of error
  5427.     ldy    #ermes6^    ; H.O. byte of error
  5428. ;    jsr    prstr        ; Print error text ('keyword')
  5429. ;    jmp    kermit        ; Start at the beginning again
  5430.     jmp    kermzz        ; [jrd] use common error vector
  5431. ;
  5432. kermt6: ldx    #ermes7\    ; L.O. byte of error
  5433.     ldy    #ermes7^    ; H.O. byte of error
  5434. ;    jsr    prstr        ; Print the error message ('file spec')
  5435. ;    jmp    kermit        ;    and try again
  5436.     jmp    kermzz        ; [jrd] use common error vector
  5437. ;
  5438. kermt7: ldx    #ermes8\    ; L.O. byte of error message text
  5439.     ldy    #ermes8^    ; H.O. byte of error
  5440. ;    jsr    prstr        ; Print it ('integer')
  5441. ;    jmp    kermit        ; Try for another command line
  5442.     jmp    kermzz        ; [jrd] use common error vector
  5443. ;
  5444. ;kermt8: ldx    #ermes9\    ; L.O. byte of error
  5445. ;    ldy    #ermes9^    ; H.O. byte of error
  5446. ;    jsr    prstr        ; Print the message ('switch')
  5447. ;    jmp    kermit        ; Try for another command line
  5448. ;    jmp    kermzz        ; [jrd] use common error vector
  5449. ;
  5450. kermt9: ldx    #ermesa\    ; L.O. byte of error message
  5451.     ldy    #ermesa^    ; H.O. byte of error message
  5452. ;    jsr    prstr        ; Print the message ('')
  5453. ;    jmp    kermit        ; Try for another command line
  5454.     jmp    kermzz        ; [jrd] use common error vector
  5455. ;
  5456. kermta:    ldx    #ermesb\    ; L.O. byte of error message
  5457.     ldy    #ermesb^    ; H.O. byte of error message
  5458. ;    jsr    prstr        ; Print the message ('text')
  5459. ;    jmp    kermit        ; Go back to top of loop
  5460. ;                ; [jrd] fall into error vector
  5461. ;
  5462. kermzz:                ; common error vector
  5463.     jsr    prstr        ; print the error msg
  5464. ;    jmp    kermit        ; restart the sucker
  5465. ; fall into warmstart rtn
  5466.  
  5467. ;
  5468. ;    Nonftl - handles non-fatal DOS errors. When Kermit does its
  5469. ;    initialization it points the error vector and the basic
  5470. ;    warmstart vector here.
  5471. ;
  5472.  
  5473. nonftl:
  5474. kermit:
  5475. ;    lda    fmrcod        ; Get the DOS return code
  5476. ;    ora    #$80        ;        ...
  5477. ;    sta    errcod        ; Save that here
  5478.     ldx    kerosp        ; Get the old stack pointer back
  5479.     txs            ; Restore it
  5480.     jmp    kermloop    ; Warmstart kermit
  5481.  
  5482. ;
  5483. ;    Fatal - closes and deletes a file on which a bad error
  5484. ;    has occured (most likely a 'disk full' error). It then
  5485. ;    restores the old stack pointer and warmstarts Kermit.
  5486. ;
  5487.  
  5488. fatal:
  5489. ;    lda    fmrcod        ; Get the DOS return code
  5490. ;    ora    #$80        ; Set H.O. bit to indicate DOS error
  5491. ;    sta    errcod        ; Store the error code
  5492.     jsr    closef        ; Close the file
  5493. ;    jsr    dosdel        ; Now, delete the useless file
  5494. ;    ldx    kerosp        ; Get the old stack pointer
  5495. ;    txs            ; Restore it
  5496.     jmp    kermit        ; Warmstart kermit
  5497.  
  5498. .SBTTL    Telnet routine
  5499.  
  5500. ;
  5501. ;    This routine handles the connect command. After connecting
  5502. ;    to a host system, this routine alternates calling routines
  5503. ;    which will pass input from the port to the screen and pass
  5504. ;    output from the keyboard to the port. This kermit will
  5505. ;    ignore all characters until it sees and assigned escape
  5506. ;    character.
  5507. ;
  5508. ;        Input:  RS232 parameters
  5509. ;
  5510. ;        Output: NONE
  5511. ;
  5512. ;        Registers destroyed:    A,X,Y
  5513. ;
  5514. telnet: jsr    prcfm        ; Parse and print a confirm
  5515.     jsr    vttini        ; init tab map
  5516.     lda    #0        ; zzz debug
  5517.     sta    altcs        ; getting set spuriously?
  5518.     lda    #true        ;[48]
  5519.     sta    connec        ;[48]
  5520.     jsr    scrext        ; [jrd] make sure we're set up for
  5521.                 ;  re-entering E:
  5522.     lda    conscrt        ; [jrd] get the screen type for connect
  5523.     sta    scrtype        ; set the current screen type
  5524.     jsr    scrini        ; do any required initializations
  5525.     lda    scrtype        ; using non-atari screen?
  5526.     bne    tn1        ; if not atari screen, use stat line
  5527.     ldx    #inf01a\    ; Get address of first half of message
  5528.     ldy    #inf01a^    ;        ...
  5529.     jsr    prstr        ; Print it out
  5530.     lda    escp        ; Get the 'break connection' character
  5531.     jsr    prchr        ; Print that as a special character
  5532.     ldx    #inf01b\    ; Get address of second half of message
  5533.     ldy    #inf01b^    ;        ...
  5534.     jsr    prstr        ; Print that
  5535.     jsr    prcrlf        ;    and a crelf
  5536.     jmp    tn2
  5537. tn1:
  5538.     jsr    telslm        ; go do message in stat line
  5539. tn2:
  5540.     jsr    openrs        ;[27]
  5541.  
  5542. chrlup:    
  5543. ; [jrd]    lda    ndx        ;[39] Check keyboard queue
  5544.     lda    CH        ; FF -> no key pending
  5545.     cmp    #$FF        ; anything there?
  5546.     bne    telcnc        ;[39] Keyboard has priority over RS232
  5547. telprc:    jsr    getrs        ; Check for a port character
  5548.     bne    telcnc        ; None available, check keyboard
  5549. ;
  5550. ; if debugging enough, log received characters
  5551. ;
  5552.     lda    debug        ; get debug flag
  5553.     cmp    #verbose    ; verbose debugging?
  5554.     bne    telprnd        ; nope, go on
  5555.     jsr    teldbg
  5556. telprnd:
  5557.     lda    char        ;[31] Get the character read from port
  5558.     and    #$7F        ;[31] Shut off the high order bit
  5559.     sta    char        ;[26][31] Store the character back
  5560.     ldx    escflg        ; Was previous character an escape?
  5561.     cpx    #on        ;        ...
  5562.     bne    telp2a        ; If not, skip vt52 emulation stuff
  5563.     ldy    vtmod        ; Are we in vt52 mode?
  5564.     jsr    case
  5565.     .word    telp2a        ; glass tty. skip vt52 emulation
  5566.     .word    dovt52        ; call vt52 and jmp to ttelprr
  5567.     .word    dovt100        ; call vt100 and jmp to ttelprr
  5568.  
  5569. dovt52:    jsr    vt52        ; process the character after the esc
  5570.     jmp    telprr
  5571.  
  5572. dovt100: jsr    vt100        ; process a character in an esc sequence
  5573.     jmp    telprr
  5574.  
  5575. telp2a:
  5576.     ldy    scrtype        ; kludge.  Only xlate to atascii
  5577.     bne    telp2b        ;  if using atari E: screen
  5578. ;
  5579. ;    tax            ; do the appropriate translation
  5580. ;    lda    astoat,x
  5581. ;
  5582.     ldx    #xas2at\    ; point at table
  5583.     ldy    #xas2at^
  5584.     jsr    xlate        ; translate it
  5585. ;
  5586.     sta    char
  5587. telp2b:
  5588.     cmp    #$20        ; if less than $20, not printable character
  5589.     bcc    telp3a
  5590. ;    cmp    #$20+95        ; one of the 96 printable characters?
  5591. ;    bcs    telp3a        ; nope
  5592. ;    jsr    cout        ; print the normal character
  5593.     jsr    scrput        ; [jrd]
  5594.     clc            ; repeat forever
  5595.     jmp    chrlup
  5596. telp3a:    jsr    telpr3        ; process it
  5597. telprr:    clc            ;[39] Repeat Main terminal loop
  5598.     jmp    chrlup        ;[39]        ...
  5599.  
  5600. telcnc:    jsr    getkey        ; Get a keyboard byte
  5601. ;    beq    telcrs        ; None available, return
  5602.     bcs    telcrs        ; None available, return
  5603. ;    tax            ; run the character through the table
  5604. ;    lda    attoas,x
  5605.     sta    char        ; save it
  5606.     bpl    tlcnc5        ; if pos, process it
  5607.     ldx    #vt100fk\    ; zzz for now, vt100 wired
  5608.     ldy    #vt100fk^
  5609.     jsr    fksend        ; send the fun key
  5610.     jmp    telcrs        ; finish terminal processing
  5611. tlcnc5:    cmp    escp        ; Is it the connect-escape character?
  5612.     bne    tlcnc6        ; If so, go handle the interupt character
  5613.     ldx    scrtype        ; [jrd] only do this if in atari scr
  5614. ;
  5615. ;zzz redo this loop, it's getting gross.
  5616. ;
  5617.     bne    tlcnc6        ; [jrd] nope, we don'use it here
  5618.     jmp    intchr
  5619. tlcnc6:    lda    char
  5620.     jsr    putrs        ;[39] Output the port character
  5621.     ldx    lecho        ; Is local-echo turned on?
  5622.     cpx    #on        ;        ...
  5623.     bne    telcrs        ; If not, we are done
  5624. ;    jsr    cout        ; Output a copy to the screen
  5625.     jsr    scrput        ; [jrd]
  5626. telcrs:
  5627.     jsr    scrfls        ;[EL] Go blink the cursor
  5628.     lda    scrtype        ; in 40 mode?
  5629.     beq    telcrs1        ; nope, repeat loop
  5630.     lda    #$08        ; sanity value, H/W man page III.15
  5631.     sta    CONSOL
  5632.     lda    CONSOL        ; read console switches
  5633.     eor    #$FF        ; reverse bits
  5634.     sta    strptr        ; save for a bit
  5635.     and    #$04        ; Option key down?
  5636.     beq    telcrs0        ; nope, see about panning
  5637.     jmp    intchr        ; go do an option
  5638. telcrs0:
  5639.     lda    scrtype        ; check screen type again
  5640.     cmp    #scr40
  5641.     bne    telcrs1
  5642.     lda    strptr        ; get original bits
  5643.     and    #$03        ; mask for start, select
  5644.     bne    telpan        ; something's set, pan
  5645. telcrs1:
  5646.     clc            ;[39] Repeat main terminal loop
  5647.     jmp    chrlup        ;[39]        ...
  5648. ;
  5649. telpan:
  5650.     and    #$01        ; start?
  5651.     beq    tlpl        ; nope, must be select, pan left
  5652.     inc    panval        ; bump pan offset
  5653.     lda    panval
  5654.     cmp    #40        ; better be less
  5655.     bcs    tlpr1        ; nope, leave it at 40
  5656.     jsr    pan40        ; go do it
  5657.     jmp    chrlup        ; go do terminal loop
  5658. tlpr1:    lda    #39
  5659.     sta    panval        ; reset it to something reasonable
  5660.     jmp    chrlup
  5661. tlpl:    dec    panval        ; dec panval by 1
  5662.     bmi    tlpl1        ; oops, too far
  5663.     jsr    pan40        ; do it
  5664.     jmp    chrlup
  5665. tlpl1:    lda    #0
  5666.     sta    panval
  5667.     jmp    chrlup
  5668.  
  5669. ;    Handle special input characters
  5670.  
  5671. telpr3:    cmp    #bel        ; Is it a ^G (bell)
  5672.     bne    tlpr3a        ; No
  5673.     jsr    bell        ; Ring bell
  5674.     rts            ;[39]
  5675. tlpr3a: cmp    #cr        ; Is it a ^M (cr) ?
  5676.     bne    tlpr3b        ; No
  5677.     jsr    scrcr        ; Go do a <cr>
  5678.     rts            ;[39]
  5679. tlpr3b:    cmp    #tab        ;[26] Is it a ^I (tab) ?
  5680.     bne    tlpr3c        ;[26] No
  5681. ;    jsr    prttab        ;[26] Print to the next tab stop
  5682.     jsr    vtnxtt        ; do a real tab
  5683.     rts            ;[39]
  5684. tlpr3c:    cmp    #esc        ; Was it an 'escape'?
  5685.     bne    tlpr3d        ; No
  5686.     lda    #on        ; Set the escape flag on
  5687.     sta    escflg        ;        ...
  5688.     lda    #0        ; zero pointers for vt100 emulation
  5689.     sta    vt100st        ; state is zero
  5690.     sta    vt100pt        ; parameter pointer is zero
  5691.     rts            ; Return
  5692. tlpr3d:    cmp    #lf        ; was it a line feed
  5693.     bne    tlpr3e
  5694.     jsr    scrlf        ; perform the line feed
  5695.     rts 
  5696. tlpr3e:    cmp    #bs        ; was it a backspace?
  5697.     bne    tlpr3f
  5698.     jsr    scrl        ; move the cursor left
  5699.     rts
  5700. tlpr3f: cmp    #so        ; SO?
  5701.     bne    tlpr3g        ; nope
  5702.     lda    #1        ; yes, set alt char set (G1)
  5703.     sta    altcs        ;  this isn't really right for vt52,
  5704.     rts            ;  but who cares?
  5705. tlpr3g: cmp    #si        ; SI?
  5706.     bne    tlpr3h        ; nope
  5707.     lda    #0        ; yes, clear alt char set flg
  5708.     sta    altcs
  5709. ;    rts
  5710. tlpr3h:
  5711.     rts
  5712.  
  5713. ;
  5714. ;    Intchr - processes the character which follows the interupt
  5715. ;    character and performs functions based on what that character
  5716. ;    is.
  5717. ;
  5718.  
  5719. intchr:    lda    #conm3\        ; prompt in status line
  5720.     ldy    #conm3^
  5721.     ldx    #0
  5722.     jsr    slput        ; display it
  5723.     jsr    rdkey        ; Get the next character
  5724.     lda    char        ;[31]
  5725.     sta    kerchr        ; Save a copy of it
  5726.     and    #$5F        ; Capitalize it
  5727.     cmp    #'C        ; Does user want the connection closed?
  5728.     bne    intch0        ; If not, try next option
  5729. ;
  5730. ; talk about your basic brain damage...
  5731. ;    pla            ;[39] Fix the stack
  5732. ;    pla            ;[39]
  5733. ;
  5734.     lda    #false        ;[48]
  5735.     sta    connec        ;[48]
  5736. ; zzz    jsr    scrrst        ; reset the screen to normal characterstics
  5737.     jsr    scrext
  5738.     lda    #scrae        ; go back to atari E: screen
  5739.     sta    scrtype
  5740.     jmp    kermit        ;[39]
  5741. intch0: cmp    #'S        ; Does the user want status?
  5742.     bne    intch1        ; Nope
  5743.     jsr    stat01        ;[EL] Give it to him
  5744.     jmp    intex        ; [jrd]
  5745. intch1: cmp    #'B        ;[DD] Send break?
  5746.     bne    intc1a        ; No
  5747.     jsr    sbreak        ; Yes, go send one
  5748.     jmp    intex        ; [jrd]
  5749. intc1a: lda    kerchr        ; Fetch back the original character
  5750.     and    #$7F        ; Get rid of the H.O. bit
  5751.     cmp    #'?        ; Does user need help?
  5752.     bne    intch2        ; If not, continue
  5753.     ldx    #inthlp\    ; Get the address of the proper help string
  5754.     ldy    #inthlp^    ;        ...
  5755.     jsr    prstr        ; Print the help stuff
  5756.     jmp    intchr        ; Get another option character
  5757. intch2: cmp    escp        ; Is it another connect-escape?
  5758. ;    bne    intch4        ;[39]
  5759.     bne    intex        ;[jrd]
  5760.     jsr    putrs        ; Stuff the character at the port
  5761.     jmp    intex        ;[39]
  5762. ;intch4:
  5763. ;    cmp    #'0        ;[39]
  5764. ;    bne    intch3        ;[39] Nope, this is an error
  5765. ;    lda    #$00        ;[39]
  5766. ;    jsr    putrs        ;[39]
  5767. ;    jmp    intex        ;[39]
  5768. intch3: jsr    bell        ; Sound bell at the user
  5769. ;
  5770. intex:                ; put the status line back
  5771.     jsr    telslm        ; do appropriate msg
  5772.     jmp    telcrs        ; and go back
  5773. ;
  5774. ;    Display appropriate msg in status line
  5775. ;
  5776. conm1:    .byte    "K65: Option",0
  5777. conm2:    .byte    ",Sel,Sta",0
  5778. conm3:    .byte    "Option (C,S,B,?)",0
  5779. telslm:
  5780.     lda    #conm1\        ; [jrd] point at stat line text
  5781.     ldy    #conm1^
  5782.     ldx    #0        ; offset in stat line
  5783.     jsr    slput        ; put it
  5784.     lda    scrtype
  5785.     cmp    #scr80        ; in 80-col?
  5786.     beq    telslm1        ; yes, go ahead and connect
  5787.     lda    #conm2\        ; no, print start/sel msg
  5788.     ldy    #conm2^
  5789.     jsr    slput
  5790. telslm1:
  5791.     jsr    updstat        ; update other stat line fields
  5792.     rts
  5793.  
  5794. ;
  5795. ; debug code.  Log char received into status line
  5796. ;
  5797. teldbg:
  5798.     ldy    #0        ; idx into stat line
  5799.     ldx    #18        ; move 18 bytes
  5800. teldbg1:
  5801.     lda    statline+3,y    ; get a byte
  5802.     sta    statline,y    ; more it over
  5803.     iny            ; bump idx
  5804.     dex            ; dec count
  5805.     bne    teldbg1        ; and go around
  5806.     lda    char        ; get the char
  5807.     lsr    a        ; shift it down
  5808.     lsr    a
  5809.     lsr    a
  5810.     lsr    a
  5811.     jsr    ny2hx        ; get a hex char
  5812.     sec
  5813.     sbc    #$20        ; offset for display
  5814.     sta    statline,y    ; shove it in
  5815.     iny
  5816.     lda    char        ; get char again
  5817.     and    #$0F        ; mask
  5818.     jsr    ny2hx
  5819.     sec
  5820.     sbc    #$20        ; offset for display
  5821.     sta    statline,y    ; this one into stat line
  5822.     iny
  5823.     lda    #0        ; display a space
  5824.     sta    statline,y
  5825.     rts
  5826.  
  5827. ;
  5828. ;    Vt52 - will carry out the equivalent of most of the vt52 functions
  5829. ;    available.
  5830. ;
  5831.  
  5832. vt52:    lda    #off        ; First, turn off the escape flag
  5833.     sta    escflg        ;        ...
  5834.     lda    char        ;[26] Get the character to check
  5835.     and    #$7F        ; Turn off the H.O. bit
  5836.     cmp    #'A        ; Is it greater than 'A' and less than
  5837.     bmi    vt52y        ;[26]    or equal to 'z'????
  5838.     cmp    #'z        ;[26]        ...
  5839.     bmi    vt52z        ;[26] If it isn't, ignore it
  5840. vt52y:    jmp    vtig        ;[26]
  5841. vt52z:
  5842. ; all obsolete?
  5843. ;    sec            ;[26] Get the cursor position
  5844. ;    jsr    ploth        ;[26] in X,Y
  5845. ;;    sty    hch        ;[39]
  5846. ;    stx    hch        ;[39]
  5847. ;;    stx    hcv        ;[39]
  5848. ;    sty    hcv        ;[39]
  5849.     cmp    #'A        ; It is, is it an 'A'?
  5850.     bne    vt52a        ; No, try next character
  5851.     jsr    scru        ; Go up one line
  5852.     rts            ; Return
  5853. vt52a:  cmp    #'B        ; Is it a 'B'?
  5854.     bne    vt52b        ; Next char
  5855.     jsr    scrd        ; Yes, go down one line
  5856.     rts            ;    and go back
  5857. vt52b:  cmp    #'C        ; 'C'?
  5858.     bne    vt52c        ; Nope
  5859.     jsr    scrr        ; Yes, go forward one space
  5860.     rts            ;    and return
  5861. vt52c:  cmp    #'D        ; 'D'?
  5862.     bne    vt52d        ; No
  5863.     jsr    scrl        ; Yes, do a back-space
  5864.     rts            ; Return
  5865. vt52d:  cmp    #'H        ; 'H'?
  5866.     bne    vt52e        ; No, try next character
  5867.     ldx    #0
  5868.     ldy    #0
  5869.     jsr    scrplt        ; Home cursor (no clear screen)
  5870.     rts            ;    then return
  5871. vt52e:  cmp    #'I        ; 'I'?
  5872.     bne    vt52f        ; Nope
  5873.     jsr    scrrlf        ;[39] Do a reverse line feed
  5874.     rts            ;  and return
  5875. vt52f:  cmp    #'J        ; 'J'?
  5876.     bne    vt52g        ; No
  5877.     jsr    scred0        ; Clear from where we are to end-of-page
  5878.     rts            ;    then return
  5879. vt52g:  cmp    #'K        ; 'K'?
  5880.     bne    vt52h        ; Try last option
  5881.     jsr    screl0        ; Clear to end-of-line
  5882.     rts            ; Return
  5883. vt52h:  cmp    #'Y        ; 'Y'
  5884.     bne    vt52i        ;[19]
  5885.     jsr    vtdca        ; Do direct cursor addressing
  5886.     rts            ;    then return
  5887. vt52i:    cmp    #'o        ;[19] 'o'
  5888.     bne    vt52j        ;[19]
  5889.     lda    #1
  5890.     sta    reverse        ; turn reverse on
  5891.     rts            ;[19] Return
  5892. vt52j:    cmp    #'n        ;[19] 'n'
  5893.     bne    vtig        ;[19] Must be an unimplemented fn, do vtig
  5894.     lda    #0
  5895.     sta    reverse        ; turn reverse off
  5896.     rts            ;[19]
  5897. vtig:    pha            ; Save a copy
  5898.     lda    #esc        ; Get an escape
  5899.     jsr    prchr        ; Print the special character
  5900.     pla            ; Fetch the other character back
  5901.     cmp    #esc        ; Is it a second escape?
  5902.     bne    vtig1        ; Nope, print it
  5903.     lda    #on        ; Set escflg on again for next time around
  5904.     sta    escflg        ;        ...
  5905.     rts            ;    and return
  5906. vtig1:  jsr    prchr        ; Print the character
  5907.     rts            ;    and return
  5908.  
  5909. vtdca:    jsr    getrs        ; Check for a character from the port
  5910.     bne    vtdca        ; Try again
  5911.     lda    char        ;[31]
  5912.     and    #$7F        ; Make sure H.O. bit is off
  5913.     sec            ; Subtract hex 30 (make it num from 0 to 23)
  5914.     sbc    #$20        ;        ...
  5915. vtdca2: pha            ; save it
  5916. vtdca3:    jsr    getrs        ; Check port for character
  5917.     bne    vtdca3        ;    go back and try again
  5918.     lda    char        ;[31]
  5919.     and    #$7F        ; Make sure h.o. bit is off
  5920.     sec            ; Subtract hex 20 (make it num from 0 to 23)
  5921.     sbc    #$20        ;        ...
  5922. vtdca5: tax            ; this is the horizontal position
  5923.     pla            ; remember the vertical position
  5924.     tay
  5925.     jsr    scrplt        ; move the cursor here
  5926.     jsr    scrpan        ; pan if needed
  5927.     rts            ;    and return
  5928.  
  5929.  
  5930. .SBTTL    VT100 Emulation Routines
  5931.  
  5932. ;
  5933. ;    vt100 - parse a character in a vt100 command sequence
  5934. ;
  5935. ;    Input - A character in the A-reg
  5936. ;
  5937. ;    This routine processes characters after an esc in VT100 mode.
  5938. ;    It parses the command and calls a routine to perform the requested
  5939. ;    function when the last character in the sequence has been received.
  5940. ;
  5941.  
  5942. vt100:    ldx    vt100st        ; state of the command parser
  5943. vt100d:    ldy    vt100ta,x    ; check the parser table
  5944.     beq    vt100b        ; esape sequence is illegal
  5945.     bpl    vt100a        ; is parameter expected?
  5946.     cmp    #1+'9        ; yes.  Was a digit received?
  5947.     bcs    vt100a        ; no, it is not a digit
  5948.     cmp    #'0
  5949.     bcc    vt100a        ; not a digit (carry set for next line)
  5950.     sbc    #'0        ; convert the digit to a value (0..9)
  5951.     pha            ; save it
  5952.     ldy    vt100pt        ; pointer into parameter list
  5953.     lda    freemem,y        ; get the current value
  5954.     asl    a        ; multiplied by 2
  5955.     pha            ; save that too
  5956.     asl    a        ; multiplied by 4
  5957.     asl    a        ; multiplied by 8
  5958.     sta    freemem,y
  5959.     pla
  5960.     clc
  5961.     adc    freemem,y    ; multiplied by 10
  5962.     sta    freemem,y
  5963.     pla
  5964.     clc
  5965.     adc    freemem,y    ; add in the digit
  5966.     sta    freemem,y    ; save the new value of the parameter
  5967.     rts            ; all done (for now. escflg still set)
  5968.  
  5969. vt100a:    cmp    vt100ta,x    ; found character in table?
  5970.     beq    vt100c        ; yes. go change state
  5971.     inx            ; skip to the next entry
  5972.     inx
  5973.     inx
  5974.     jmp    vt100d        ; check this character
  5975.  
  5976. vt100c:    lda    vt100ta+2,x    ; high order byte of routine to call
  5977.     beq    vt100e        ; $00 = state change
  5978.     sta    dest+1
  5979.     lda    vt100ta+1,x    ; low order byte of routine to call
  5980.     sta    dest
  5981.     lda    #0
  5982.     sta    escflg        ; this command is complete
  5983.     jmp    (dest)        ; perform requested function
  5984.  
  5985. vt100e:    ldy    vt100ta+1,x    ; state to change to
  5986.     sty    vt100st        ; change to it
  5987.     lda    vt100ta,y    ; is a parameter expected?
  5988.     bpl    vt100f        ; no.
  5989.     inc    vt100pt        ; make pointer point to next parameter
  5990.     ldy    vt100pt        ; and zero the parameter
  5991.     lda    #0
  5992.     sta    freemem,y
  5993. vt100f:    rts            ; all done (for now. escflg still set)
  5994.  
  5995. vt100b:    lda    #0        ; an error has occured.  abort processing
  5996.     sta    escflg
  5997.     rts            ; all done
  5998.  
  5999. ;
  6000. ;    vt100b1 - process the <esc> '['  integer 'J' vt100 sequence
  6001. ;
  6002. ;    This routine calls scred0, scred1, or scred2 depending on the
  6003. ;    value of the integer.
  6004. ;
  6005.  
  6006. vt100b1: ldy    freemem+1    ; what is the integer
  6007.     cpy    #3        ; check for strange vt100 sequences
  6008.     bcs    vt100er        ; this is a strange sequence
  6009.     jsr    case        ; call the proper routine
  6010.     .word    scred0        ; call scred0 if the integer is 0
  6011.     .word    scred1        ; call scred1 if the integer is 1
  6012.     .word    scred2        ; call scred2 if the integer is 2
  6013.  
  6014. ;
  6015. ;    vt100c1 - process the <esc> '[' integer 'K'
  6016. ;
  6017. ;    This routine calls screl0, screl1, or screl2 depending on the
  6018. ;    value of the integer.
  6019.  
  6020. vt100c1: ldy    freemem+1    ; what is the integer
  6021.     cpy    #3        ; check for strange vt100 sequences
  6022.     bcs    vt100er        ; this is a strange sequence
  6023.     jsr    case        ; call the proper routine
  6024.     .word    screl0        ; call screl0 if the integer is 0
  6025.     .word    screl1        ; call screl1 if the integer is 1
  6026.     .word    screl2        ; call screl2 if the integer is 2
  6027.  
  6028. ;
  6029. ;    vt100d1 - process the <esc> '[' integer ';' integer 'f' and
  6030. ;                 <esc> '[' integer ';' integer 'H' vt100 commands
  6031. ;
  6032. ;    This routine calls scrplt to put the cursor at the position indicated
  6033. ;    by the two integers.
  6034.  
  6035. vt100d1: ldx    #0        ; get the first integer
  6036.     ldy    #1        ; default value is 1
  6037.     jsr    vt100pa
  6038.     tay
  6039.     dey            ; solve the off-by-one problem
  6040.     cpy    #24        ; check it for reasonability
  6041.     bcc    vt100d2
  6042.     tay            ; if unreasonable, move cursor to bottom line
  6043. vt100d2: sty    dest        ; save y position
  6044.     ldx    #1        ; get the second integer
  6045.     ldy    #1        ; default value is 1
  6046.     jsr    vt100pa
  6047.     tax
  6048.     dex            ; solve the off-by-one problem
  6049.     jsr    rghchk        ; check it for reasconablilty
  6050.     bcc    vt100d3
  6051.     tax            ; if unreasonable, move cursor to far right
  6052. vt100d3: ldy    dest        ; get y position
  6053.     jsr    scrplt        ; finally move the cursor
  6054.     jsr    scrpan        ; pan if necessary
  6055.     rts            ; all done
  6056.  
  6057. ;
  6058. ;    vt100e1 - process the <esc> integer ';' integer 'r' sequence
  6059. ;
  6060. ;    This routine sets the top and bottom of the scrolling area.
  6061. ;
  6062.  
  6063. vt100e1: ldx    #0        ; get the first parameter
  6064.     ldy    #1        ; default value is one
  6065.     jsr    vt100pa
  6066.     tay
  6067.     dey            ; solve the off-by-one problem
  6068.     jsr    botchk        ; check it for reasonability
  6069.     bcs    vt100e2
  6070.     sty    dest        ; save top of screen
  6071.     tay            ; get default value for bottom (from botchk)
  6072.     iny            ; solve the off-by-one problem
  6073.     ldx    #1        ; get the second parameter
  6074.     jsr    vt100pa
  6075.     tay
  6076.     dey            ; solve the off-by-one problem
  6077.     jsr    botchk        ; check it for reasonablilty
  6078.     bcs    vt100e2
  6079.     cpy    dest        ; save it
  6080.     bcc    vt100e2        ; unreasonable
  6081.     sty    bot        ; set the bottom margin
  6082.     ldy    dest        ; set the tom margin
  6083.     sty    top
  6084. ;
  6085. ; zzz deal with origin mode here
  6086. ;
  6087.     ldy    #0        ; for now assume normal origin
  6088.     ldx    #0        ; move cursor to home position
  6089.     jsr    scrplt
  6090.  
  6091. vt100e2: rts
  6092.  
  6093. vt100er: jsr    beeplo
  6094.     rts
  6095.     
  6096. ;
  6097. ;    vt100f1 - process the <esc> '[' integer 'A' sequence
  6098. ;
  6099. ;    This routine moves the cursor up <integer> lines
  6100. ;
  6101.  
  6102. vt100f1: ldx    #0        ; get the parameter
  6103.     ldy    #1        ; default value is one
  6104.     jsr    vt100pa
  6105.     sec            ; cutsy way to subtract it form cursor pos
  6106.     eor    #$FF
  6107.     adc    ROWCRS
  6108.     tay
  6109.     bcc    vt100f3        ; gone past top of screen
  6110.     cpy    top        ; outside scrolling area
  6111.     bcs    vt100f2        ; no
  6112. vt100f3: ldy    top        ; move cursor to top
  6113. vt100f2: ldx    COLCRS
  6114.     jsr    scrplt        ; plot the cursor here
  6115.     rts
  6116.  
  6117. ;
  6118. ;    vt100g1 - process the <esc> '[' integer 'B' sequence
  6119. ;
  6120. ;    This routine moves the cursor down <integer> lines
  6121. ;
  6122.  
  6123. vt100g1: ldx    #0        ; get the parameter
  6124.     ldy    #1
  6125.     jsr    vt100pa
  6126.     clc            ; add the parameter to ROWCRS
  6127.     adc    ROWCRS
  6128.     tay
  6129.     cpy    bot        ; see if still in scrolling area
  6130.     beq    vt100g2
  6131.     bcc    vt100g2
  6132.     ldy    bot        ; nope. move the cursor to the bottom
  6133. vt100g2: ldx    COLCRS
  6134.     jsr    scrplt        ; plot the cursor here
  6135.     rts            ; all done
  6136.  
  6137. ;
  6138. ;    vt100h1 - process the <esc> '[' integer 'C' sequence
  6139. ;
  6140. ;    This routine moves the cursor right <integer> characters
  6141. ;
  6142.  
  6143. vt100h1: ldx    #0        ; get the parameter
  6144.     ldy    #1        ; default value in one
  6145.     jsr    vt100pa
  6146.     clc            ; add it into the current cursor position
  6147.     adc    COLCRS
  6148.     tax
  6149.     jsr    rghchk        ; check it for reasonability
  6150.     bcc    vt100h2        ; it is reasonable
  6151.     tax            ; if unreasonable, move cursor to far right
  6152. vt100h2: ldy    ROWCRS        ; plot the cursor here
  6153.     jsr    scrplt
  6154.     rts
  6155.  
  6156. ;
  6157. ;    vt100i1 - process the <esc>  '[' integer 'D' sequence
  6158. ;
  6159. ;    This routine moves the cursor left <integer> characters
  6160. ;
  6161.  
  6162. vt100i1: ldx    #0        ; get the parameter
  6163.     ldy    #1        ; default value is one
  6164.     jsr    vt100pa
  6165.     sec            ; cutsy way to subtract from COLCRS
  6166.     eor    #$FF
  6167.     adc    COLCRS
  6168.     bcs    vt100i2        ; check if gone past left margin
  6169.     lda    #0        ; if so, move to far left
  6170. vt100i2: tax
  6171.     ldy    ROWCRS        ; plot the cursor here
  6172.     jsr    scrplt
  6173.     rts
  6174.  
  6175. ;
  6176. ;    vt100j1 - process the <esc> '[' [  integer ';' ...] 'm' sequence
  6177. ;
  6178. ;    This routine sets the graphic rendition (reverse, alternate colors,
  6179. ;    underline and flashing) parameters.  Note that it may be passed
  6180. ;    0 or more parameters
  6181. ;
  6182.  
  6183. vt100j1: ldx    #0        ; start with the first parameter
  6184. vt100j5: ldy    #0        ; default value is zero
  6185.     jsr    vt100pa
  6186.     beq    vt100j3        ; if zero, clear everything
  6187.     tay
  6188.     cpy    #8
  6189.     bcs    vt100j4        ; unreasonable parameter!
  6190.     lda    #1        ; set the proper parameter
  6191.     sta    vt100gr-1,y
  6192.     bne    vt100j4        ; always taken
  6193. vt100j3: jsr    vt100j2        ; clear everything
  6194. vt100j4: inx            ; get the next parameter
  6195.     cpx    vt100pt        ; all done?
  6196.     bcc    vt100j5        ; nope.  Do some more
  6197.     rts            ; all done.
  6198.  
  6199. vt100j2: lda    #0        ; clear everything
  6200.     sta    alternt        ; alternate color (highlighting)
  6201.     sta    flash        ; flashing off
  6202.     sta    underln        ; dont underline
  6203.     sta    reverse        ; dont reverse
  6204.     rts            ; everything cleared.
  6205.  
  6206. ;
  6207. ;    vt100k1 - process the <esc>  '[' integer 'D' sequence
  6208. ;
  6209. ;    This routine deletes <integer> lines
  6210. ;
  6211.  
  6212. vt100k1: ldx    #0        ; get the parameter
  6213.     ldy    #1        ; default value is one
  6214.     jsr    vt100pa
  6215.     sta    tmpptr        ; [jrd] this should be safe...
  6216. vt100k2:
  6217.     dec    tmpptr        ; dec count
  6218.     bmi    vt100k3        ; if gone minus, stop
  6219.     jsr    scrdl        ; delete one
  6220.     jmp    vt100k2
  6221. vt100k3:            ; done
  6222.     rts
  6223.  
  6224. ;
  6225. ;    vt100l1 - process the <esc>  '[' integer 'D' sequence
  6226. ;
  6227. ;    This routine inserts <integer> lines
  6228. ;
  6229.  
  6230. vt100l1: ldx    #0        ; get the parameter
  6231.     ldy    #1        ; default value is one
  6232.     jsr    vt100pa
  6233.     sta    tmpptr        ; [jrd] this should be safe...
  6234. vt100l2:
  6235.     dec    tmpptr        ; dec count
  6236.     bmi    vt100l3        ; if gone minus, stop
  6237.     jsr    scril        ; insert one
  6238.     jmp    vt100l2
  6239. vt100l3:            ; done
  6240.     rts
  6241.  
  6242.  
  6243. ;
  6244. ;    botchk - check to see if y-reg is below bottom of screen
  6245. ;
  6246. ;    Output:    Carry flag set if past bottom of screen
  6247. ;        A-reg holds line number of screen bottom
  6248. ;
  6249. ;    This routine checks to see if the y-reg is greater than the bottom
  6250. ;    of the screen.
  6251.  
  6252. botchk:    lda    #23
  6253.     cpy    #24
  6254.     rts
  6255.  
  6256. ;
  6257. ;    rghchk - check to see if x-reg is past right margin of screen
  6258. ;
  6259. ;    Input:    scrtype
  6260. ;
  6261. ;    Output:    Carry flag set if past right margin of screen
  6262. ;        A-reg holds right margin of screen
  6263. ;
  6264. ;    This routine checks to see if the x-reg is greater than the bottom
  6265. ;    of the screen.
  6266.  
  6267. rghchk:    lda    scrtype        ; check to see if in 40-column mode
  6268.     beq    rghchk1        ; branch if it is
  6269.     lda    #79
  6270.     cpx    #80
  6271.     rts
  6272. rghchk1: lda    #39        ; only 40 columns available
  6273.     cpx    #40
  6274.     rts
  6275.  
  6276. ;
  6277. ;    vt100pa - get a parameter for vt100 emulation
  6278. ;
  6279. ;    Input:    X-reg - which parameter is desired (0..n)
  6280. ;        Y-reg - default value of this parameter
  6281. ;
  6282. ;    Output:    A-reg - value of this parameter
  6283. ;
  6284. ;    This routine returns the value of the requested parameter.  If
  6285. ;    the parameter is zero or undefined, it returns the default value.
  6286. ;
  6287.  
  6288. vt100pa: cpx    vt100pt        ; was the necessary number of params given
  6289.     bcs    vt100pb        ; no, use the default
  6290.     lda    freemem+1,x    ; get this parameter
  6291.     beq    vt100pb        ; if zero, use the default
  6292.     rts
  6293. vt100pb: tya            ; return the default
  6294.     rts
  6295.  
  6296. ;
  6297. ;     things to set char set slots in response to SCS esc sequences
  6298. ;
  6299. scsg0us:
  6300.     lda    #csascii    ; use char set ascii 
  6301.     sta    csg0        ;  for G0
  6302.     rts
  6303. scsg0gr:
  6304.     lda    #csgraf        ; use graphics set
  6305.     sta    csg0        ;  got G0
  6306.     rts
  6307. scsg1us:
  6308.     lda    #csascii    ; use ascii
  6309.     sta    csg1        ;  for G1
  6310.     rts
  6311. scsg1gr:
  6312.     lda    #csgraf        ; use graphics
  6313.     sta    csg1        ;  for G1
  6314.     rts
  6315.  
  6316. ;
  6317. ; set tab at current column
  6318. ;
  6319. vttset:
  6320.     ldx    COLCRS        ; get column
  6321.     lda    #1
  6322.     sta    tabstop,x    ; zap it
  6323.     rts
  6324.  
  6325. ;
  6326. ; clear tab at current col.
  6327. ;
  6328. vttclr:
  6329.     ldx    #0        ; parm 0 please
  6330.     ldy    #0        ; default 0
  6331.     jsr    vt100pa        ; get a parameter
  6332.     cmp    #3        ; clear all?
  6333.     beq    vttclra        ; yes, clear all
  6334.     ldx    COLCRS        ; get column
  6335.     lda    #0
  6336.     sta    tabstop,x    ; zap it
  6337.     rts
  6338. vttclra:
  6339.     ldx    #79
  6340.     lda    #0
  6341. vttcn:    sta    tabstop,x
  6342.     dex
  6343.     bpl    vttcn
  6344.     rts
  6345.  
  6346. vttini:
  6347.     jsr    vttclra        ; first clear all
  6348.     lda    #8
  6349. vtti1:
  6350.     tax
  6351.     lda    #1
  6352.     sta    tabstop,x
  6353.     txa
  6354.     clc
  6355.     adc    #8
  6356.     cmp    #80
  6357.     bcc    vtti1
  6358.     rts    
  6359.  
  6360. ;
  6361. ; next tab stop
  6362. ;
  6363. vtnxtt:
  6364.     ldx    COLCRS
  6365. vtnt1:
  6366.     inx
  6367.     cpx    #80
  6368.     bcs    vtnt8
  6369.     lda    tabstop,x
  6370.     beq    vtnt1
  6371.     bne    vtnt9
  6372. vtnt8:    ldx    #79
  6373. vtnt9:    ldy    ROWCRS
  6374.     jsr    scrplt
  6375.     rts
  6376.  
  6377. ;
  6378. ;    vt100ta - parser table for vt100 commands
  6379. ;
  6380. ;    the first byte of each entry is a character to expect.  If the
  6381. ;    character to expect is negative, it means to parse a parameter
  6382. ;    and remain in the current state.  If it is zero, that is the end
  6383. ;    of the entry.  If it is the character received,    the next word is looked
  6384. ;    at.  If it is less than $100, the parser changes into that state.  If
  6385. ;    it is greater or equal to $100, the routine at that address is called.
  6386. ;
  6387.  
  6388. vt100ta: .byte    '[
  6389.     .word    vt100a1-vt100ta
  6390.     .byte    'M        ; <esc> 'M'
  6391.     .word    scrrlf        ;        is reverse index
  6392.     .byte    'E        ; <esc> 'E'
  6393.     .word    scrlf        ;        is next line
  6394.     .byte    'D        ; <esc> 'D'
  6395.     .word    scrlf        ;        is index
  6396.     .byte    '7        ; <esc> '7'
  6397.     .word    scrsav        ;        means save cursor position
  6398.     .byte    '8        ; <esc> '8'
  6399.     .word    scrlod        ;        means load cursor position
  6400.     .byte    'H        ; <esc> 'H'
  6401.     .word    vttset        ;        set tab stop 
  6402. ;
  6403. ; added by jrd for SCS support. 
  6404. ;
  6405.     .byte    '(        ; <esc> '('
  6406.     .word    vt100a4-vt100ta    ; set a4 state, expecting g0 spec
  6407.     .byte    ')        ; <esc> ')'
  6408.     .word    vt100a5-vt100ta    ; set a5 state, expecting g1 spec
  6409. ;
  6410.     .byte    $00
  6411.  
  6412. vt100a1: .byte    $FF
  6413.     .word    0
  6414.     .byte    'J        ; <esc> '[' integer 'J'
  6415.     .word    vt100b1
  6416.     .byte    'K        ; <esc> '[' integer 'K'
  6417.     .word    vt100c1
  6418.     .byte    'A        ; <esc> '[' integer 'A'
  6419.     .word    vt100f1
  6420.     .byte    'B        ; <esc> '[' integer 'B'
  6421.     .word    vt100g1
  6422.     .byte    'C        ; <esc> '[' integer 'C'
  6423.     .word    vt100h1
  6424.     .byte    'D        ; <esc> '[' integer 'D'
  6425.     .word    vt100i1
  6426.     .byte    'm        ; <esc> '[' [integer ';']... 'm'
  6427.     .word    vt100j1
  6428. ;
  6429. ; added by jrd, for insert/delete line support
  6430. ;
  6431.     .byte    'M
  6432.     .word    vt100k1        ; delete line(s)
  6433.     .byte    'L
  6434.     .word    vt100l1        ; insert line(s)
  6435. ;
  6436.     .byte    ';
  6437.     .word    vt100a2-vt100ta
  6438.     .byte    'f        ; <esc> '[' 'f'
  6439.     .word    vt100d1
  6440.     .byte    'H        ; <esc> '[' 'H'
  6441.     .word    vt100d1
  6442.     .byte    'r        ; <esc> '[' 'r'
  6443.     .word    vt100e1
  6444.     .byte    '?        ; <esc> '[' '?'
  6445.     .word    vt100a3-vt100ta
  6446.     .byte    'g        ; <esc> '[' g
  6447.     .word    vttclr        ; clear tab stop
  6448.     .byte    $00
  6449.  
  6450. vt100a2: .byte    $FF
  6451.     .word    0
  6452.     .byte    'H
  6453.     .word    vt100d1        ; <esc> integer ';' integer 'H'
  6454.     .byte    'f
  6455.     .word    vt100d1        ; <esc> integer ';' integer 'f'
  6456.     .byte    'r
  6457.     .word    vt100e1        ; <esc> integer ';' integer 'r'
  6458.     .byte    'm
  6459.     .word    vt100j1        ; <esc> integer ';' integer... 'm'
  6460. ;
  6461. ; added by jrd.  is this necessary?
  6462. ;
  6463.     .byte    ';
  6464.     .word    vt100a2-vt100ta    ; ; means stay in this state
  6465. ;
  6466.     .byte    0
  6467.  
  6468. vt100a3: .byte    $FF
  6469.     .word    0
  6470.     .byte    'h        ; <esc> '[' '?' integer 'h'
  6471.     .word    anyrts        ; ignored (for now)
  6472.     .byte    'l        ; <esc> '[' '?' integer 'l'
  6473.     .word    anyrts        ; ignored (for now)
  6474.     .byte    ';
  6475.     .word    vt100a3-vt100ta
  6476.     .byte    0
  6477.  
  6478. ;
  6479. ; SCS support. Note that we only support the USASCII and Graphics sets,
  6480. ; others are ignored.
  6481. ;
  6482. vt100a4:             ; no parameters here
  6483.     .byte    'B        ; <esc> ( B
  6484.     .word    scsg0us        ; set us ascii as g0
  6485.     .byte    '0        ; <esc> ( 0
  6486.     .word    scsg0gr        ; set graphics as g0
  6487.     .byte    'A        ; <esc> ( A
  6488.     .word    scsg0us        ; should really be uk
  6489.     .byte    0
  6490.  
  6491. vt100a5: 
  6492.     .byte    'B        ; <esc> ) B
  6493.     .word    scsg1us
  6494.     .byte    '0
  6495.     .word    scsg1gr
  6496.     .byte    'A        ; <esc> ) A
  6497.     .word    scsg1us        ; should really be uk
  6498.     .byte    0
  6499.  
  6500.     .byte    *-vt100ta    ; abort assembly if table length > $100
  6501. .SBTTL    Exit routine
  6502.  
  6503. ;
  6504. ;    This routine exits properly from Kermit-65 and reenters
  6505. ;    Atari DOS
  6506. ;
  6507. ;        Input:  NONE
  6508. ;
  6509. ;        Output: NONE
  6510. ;
  6511. ;        Registers destroyed:    A,X
  6512. ;
  6513.  
  6514. ;exit:    lda    #cmcfm        ; Try to get a confirm
  6515. ;    jsr    comnd        ; Do it
  6516. ;     jmp    kermt3        ; Give '?not confirmed' message
  6517. ;
  6518. exit1:    jsr    restor        ;[36] Restore everything to its' default state
  6519. ;    lda    r6510        ;[17] Prepare to terminate
  6520. ;    ora    #1        ;[17]  by paging BASIC ROM in
  6521. ;    sta    r6510        ;[17]         ...
  6522. ;exit2:  jmp    (dos)        ; Now restart BASIC
  6523.     ldx    keresp        ; [jrd] Not here you don't.
  6524.     txs            ;    Get our stack back
  6525.     lda    kerret+1    ;    make sure ret addr is ok
  6526.     pha            ;    and...
  6527.     lda    kerret
  6528.     pha
  6529.     rts            ;   return
  6530.  
  6531. restor:
  6532. ; [jrd]    jsr    clall        ;[19][36] Close all channels
  6533.     jsr    scrext        ; restore screen hardward to its initial state
  6534.     rts            ;[36] Return
  6535.  
  6536. .SBTTL    Help routine
  6537.  
  6538. ;
  6539. ;    This routine prints help from the current help text
  6540. ;    area.
  6541. ;
  6542. ;        Input:  Cmhptr  - Pointer to the desired text to be printed
  6543. ;
  6544. ;        Output: ASCIZ string at Cmhptr is printed on screen
  6545. ;
  6546. ;        Registers destroyed:    A,X,Y
  6547. ;
  6548.  
  6549. help:    lda    #cmcfm        ; Try to get a confirm
  6550.     jsr    comnd        ; Go get it
  6551.      jmp    kermt3        ; Didn't find one? Give 'not confirmed' message
  6552. help2:  ldx    cmhptr        ; L.O. byte of current help text address
  6553.     ldy    cmhptr+1    ; H.O. byte of address
  6554. ;    jsr    prstr        ; Print it
  6555. ;    jmp    kermit        ; Return to main routine
  6556.     jmp    kermzz        ; [jrd] use common print vector
  6557. ;
  6558.  
  6559. .SBTTL    Log routine
  6560.  
  6561. ;
  6562. ;    This routine logs a session to a disk file.
  6563. ;
  6564. ;        Input:  NONE
  6565. ;
  6566. ;        Output: NONE
  6567. ;
  6568. ;        Registers destroyed:    NONE
  6569. ;
  6570.  
  6571. log:    jmp    kermit
  6572.  
  6573. .SBTTL    Bye routine
  6574.  
  6575. ;
  6576. ;    This routine terminates the remote server, logs out and terminates
  6577. ;    the local Kermit.
  6578. ;
  6579.  
  6580. bye:    jsr    prcfm        ; Go parse and print the confirm
  6581.     jsr    logo        ; Tell other Kermit to log out
  6582.      jmp    kermit        ; Don't exit if there was an error
  6583. quit:
  6584. ;    jmp    exit1        ; Leave
  6585.     rts            ; [jrd] let the main routine exit for us
  6586.  
  6587. ;
  6588. ;    Logo - This routine does the actual work to send the logout
  6589. ;    packet to the remote server
  6590. ;
  6591.  
  6592. logo:    jsr    openrs        ;[27] Reset the RS-232 channel
  6593.     lda    #0        ; Zero the number of tries
  6594.     sta    numtry        ;        ...
  6595.     sta    tpak        ;    and the total packet number
  6596.     sta    tpak+1        ;        ...
  6597.     lda    #pdbuf\        ;[29] Get the address of the packet buffer
  6598.     sta    kerbf1        ;[29]   and save it for Spak
  6599.     lda    #pdbuf^        ;[29]        ...
  6600.     sta    kerbf1+1    ;[29]        ...
  6601. logo1:    lda    numtry        ; Fetch the number of tries
  6602.     cmp    maxtry        ; Have we exceeded Maxtry?
  6603.     bmi    logo3        ; Not yet, go send the packet
  6604. logo2:    ldx    #ermesc\    ; Yes, give an error message
  6605.     ldy    #ermesc^    ;        ...
  6606.     jsr    prstr        ;        ...
  6607.     jsr    prcrlf        ;        ...
  6608.     rts            ;    and return
  6609. logo3:    inc    numtry        ; Increment the number of tries for packet
  6610.     lda    #0        ; Make it packet number 0
  6611.     sta    pnum        ;        ...
  6612.     lda    #1        ; Data length is only 1
  6613.     sta    pdlen        ;        ...
  6614.     lda    #'L        ; The 'Logout' command
  6615.     sta    pdbuf        ; Put that in first character of buffer
  6616.     lda    #'G        ; Generic command packet type
  6617.     sta    ptype        ;        ...
  6618.     jsr    flshin        ;[25] Flush the RS232 buffer
  6619.     jsr    spak        ; Send the packet
  6620.     jsr    rpak        ; Try to fetch an ACK
  6621.     cmp    #true        ; Did we receive successfully?
  6622.     bne    logo1        ; No, try to send the packet again
  6623.     lda    ptype        ; Get the type
  6624.     cmp    #'Y        ; An ACK?
  6625.     bne    logoce        ; No, go check for error
  6626.     jmp    rskp        ; Yes, skip return
  6627. logoce:    cmp    #'E        ; Error packet?
  6628.     bne    logo1        ; Nope, resend packet
  6629.     jsr    prcerp        ; Go display the error
  6630.     rts            ;    and return
  6631.  
  6632. .SBTTL    Finish routine
  6633.  
  6634. ;
  6635. ;    This routine terminates the remote server but does not log
  6636. ;    it out. It also keeps the local Kermit running.
  6637. ;
  6638.  
  6639. finish:    jsr    prcfm        ; Go parse and print the confirm
  6640.     jsr    openrs        ;[27] Reset the RS232 channel
  6641.     lda    #0        ; Zero the number of tries
  6642.     sta    numtry        ;        ...
  6643.     sta    tpak        ;    and the total packet number
  6644.     sta    tpak+1        ;        ...
  6645.     lda    #pdbuf\        ;[29] Get the address of the packet buffer
  6646.     sta    kerbf1        ;[29]   and save it for Spak
  6647.     lda    #pdbuf^        ;[29]        ...
  6648.     sta    kerbf1+1    ;[29]        ...
  6649. finsh1:    lda    numtry        ; Fetch the number of tries
  6650.     cmp    maxtry        ; Have we exceeded Maxtry?
  6651.     bmi    finsh3        ; Not yet, go send the packet
  6652. finsh2:    ldx    #ermesd\    ; Yes, give an error message
  6653.     ldy    #ermesd^    ;        ...
  6654.     jsr    prstr        ;        ...
  6655.     jsr    prcrlf        ;        ...
  6656.     jmp    kermit        ;    and go back for more commands
  6657. finsh3:    inc    numtry        ; Increment the number of tries for packet
  6658.     lda    #0        ; Make it packet number 0
  6659.     sta    pnum        ;        ...
  6660.     lda    #1        ; Data length is only 1
  6661.     sta    pdlen        ;        ...
  6662.     lda    #'F        ; The 'Finish' command
  6663.     sta    pdbuf        ; Put that in first character of buffer
  6664.     lda    #'G        ; Generic command packet type
  6665.     sta    ptype        ;        ...
  6666.     jsr    flshin        ;[25] Flush the RS232 buffer
  6667.     jsr    spak        ; Send the packet
  6668.     jsr    rpak        ; Try to fetch an ACK
  6669.     cmp    #true        ; Did we receive successfully?
  6670.     bne    finsh1        ; No, try to send the packet again
  6671.     lda    ptype        ; Get the type
  6672.     cmp    #'Y        ; An ACK?
  6673.     bne    fince        ; No, go check for error
  6674.     jmp    kermit        ; Yes, go back for more commands
  6675. fince:    cmp    #'E        ; Error packet?
  6676.     bne    finsh1        ; Nope, resend packet
  6677.     jsr    prcerp        ;; Go display the error
  6678.     jmp    kermit        ; Go back for more 
  6679.  
  6680. .SBTTL    Get routine
  6681.  
  6682. ;
  6683. ;    This routine accepts an unquoted string terminated by 
  6684. ;    <cr>,<lf>,<ff>, or <esc> and tries to fetch the file
  6685. ;    represented by that string from a remote server Kermit.
  6686. ;
  6687.  
  6688. getfrs:
  6689.     jsr    openrs        ;[27] Reset the RS232 channel
  6690.     lda    #yes        ; Make KERMIT use file headers
  6691.     sta    usehdr        ;    for file names
  6692.     lda    #mxfnl+1    ; The buffer size is one more than max
  6693.     sta    kwrk01        ;    file name length
  6694.     lda    #fcb1\        ; Point to the buffer
  6695.     sta    kerto        ;        ...
  6696.     lda    #fcb1^        ;        ...
  6697.     sta    kerto+1        ;        ...
  6698.     jsr    kerflm        ; Clear the buffer
  6699.     lda    #$80        ; Reset all break characters
  6700.     jsr    rstbrk        ;        ...
  6701.     lda    #cr        ;        ...
  6702.     jsr    setbrk        ;        ...
  6703.     lda    #lf        ;        ...
  6704.     jsr    setbrk        ;        ...
  6705.     lda    #ffd        ;        ...
  6706.     jsr    setbrk        ;        ...
  6707.     lda    #esc        ;        ...
  6708.     jsr    setbrk        ;        ...
  6709.     ldy    #0        ;        ...
  6710.     lda    #cmtxt        ; Parse for text
  6711.     jsr    comnd        ; Do it
  6712.      jmp    kermta        ; Found null string
  6713.     cmp    spsiz        ; Larger than the set packet size?
  6714.     bmi    getf1        ; No, continue
  6715.     lda    spsiz        ; Yes, it will have to be truncated
  6716. getf1:    sta    kwrk01        ; Store packet size for Kercpy
  6717.     sta    pdlen        ;    and Spak
  6718.     lda    #pdbuf\        ; Point to the data buffer as destination
  6719.     sta    kerto        ;        ...
  6720.     sta    kerbf1        ; Store L.O.B. here for Spak routine
  6721.     lda    #pdbuf^        ;        ...
  6722.     sta    kerto+1        ;        ...
  6723.     sta    kerbf1+1    ; Store H.O.B. here for Spak routine
  6724.     stx    kerfrm        ; Point to the atom buffer from Comnd
  6725.     sty    kerfrm+1    ;    as the source address
  6726.     txa            ; Save the 'from buffer' pointers for later
  6727.     pha            ;        ...
  6728.     tya            ;        ...
  6729.     pha            ;        ...
  6730.     jsr    kercpy        ; Copy the string
  6731.     pla            ; Restore these for the next move
  6732.     sta    kerfrm+1    ;        ...
  6733.     pla            ;        ...
  6734.     sta    kerfrm        ;        ...
  6735.     lda    #fcb1\        ; Set up the address of the target
  6736.     sta    kerto        ;        ...
  6737.     lda    #fcb1^        ;        ...
  6738.     sta    kerto+1        ;        ...
  6739.     jsr    clrfcb        ; Clear the fcb first
  6740.     jsr    kercpy        ; Go move the string
  6741.     jsr    prcfm        ; Go parse and print the confirm
  6742.     lda    #'R        ; Packet type is 'Receive-init'
  6743.     sta    ptype        ;        ...
  6744.     lda    #0        ; Packet number should be zero
  6745.     sta    pnum        ;        ...
  6746.     jsr    spak        ; Packet length was set above, 
  6747.     jsr    rswt        ;    so just call spak and try to receive
  6748.     lda    #0        ; [jrd] make sure file's
  6749.     jsr    closef        ;  closed in case of error
  6750.     jmp    kermit        ; Go back for more commands
  6751.  
  6752.  
  6753. .SBTTL    Receve routine
  6754.  
  6755. ;
  6756. ;    This routine receives a file from the remote kermit and
  6757. ;    writes it to a disk file.
  6758. ;
  6759. ;        Input:  Filename returned from comnd, if any
  6760. ;
  6761. ;        Output: If file transfer is good, file is output to disk
  6762. ;
  6763. ;        Registers destroyed:    A,X,Y
  6764. ;
  6765.  
  6766. receve:    jsr    openrs        ;[27] Reset the RS232 channel
  6767.     lda    #on        ; Set use file-header switch on in case we
  6768.     sta    usehdr        ;    don't parse a filename
  6769.     lda    #kerehr\    ; Point to extra help commands
  6770.     sta    cmehpt        ;        ...
  6771.     lda    #kerehr^    ;        ...
  6772.     sta    cmehpt+1    ;        ...
  6773.     ldx    #mxfnl        ; Longest length a filename may be
  6774.     ldy    #cmfehf        ; Tell Comnd about extra help
  6775.     lda    #cmifi        ; Load opcode for parsing input files
  6776.     jsr    comnd        ; Call comnd routine
  6777.      jmp    recev1        ; Continue, don't turn file-header switch off
  6778.     sta    kwrk01        ; Store length of file parsed
  6779.     stx    kerfrm        ; Save the from address (addr[atmbuf])
  6780.     sty    kerfrm+1    ;        ...
  6781.     lda    #fcb1\        ; Save the to address (Fcb1)
  6782.     sta    kerto        ;        ...
  6783.     lda    #fcb1^        ;        ...
  6784.     sta    kerto+1        ;        ...
  6785.     jsr    clrfcb        ; Clear the fcb
  6786.     jsr    kercpy        ; Copy the string
  6787.     lda    #off        ; We parsed a filename so we don't need the
  6788.     sta    usehdr        ;    info from the file-header
  6789. recev1: ;lda    #cmcfm        ; Get token for confirm
  6790.     ;jsr    comnd        ;    and try to parse that
  6791.     ; jmp    kermt3        ; Failed - give the error
  6792.     jsr    prcfm        ;[] Parse and print a confirm
  6793.     jsr    rswt        ; Perform send-switch routine
  6794.     jsr    closers        ; [jrd] close com port
  6795.     jmp    kermit        ; Go back to main routine
  6796. ;
  6797. rswt:    lda    #'R        ; The state is receive-init
  6798.     sta    state        ; Set that up
  6799.     lda    #0        ; Zero the packet sequence number
  6800.     sta    n        ;        ...
  6801.     sta    numtry        ;    Number of tries
  6802.     sta    oldtry        ;    Old number of tries
  6803.     sta    eofinp        ;    End of input flag
  6804.     sta    errcod        ;    Error indicator
  6805.     sta    rtot        ;    Total received characters
  6806.     sta    rtot+1        ;        ...
  6807.     sta    stot        ;    Total Sent characters
  6808.     sta    stot+1        ;        ...
  6809.     sta    rchr        ;    Received characters, current file
  6810.     sta    rchr+1        ;        ...
  6811.     sta    schr        ;    and Sent characters, current file
  6812.     sta    schr+1        ;        ...
  6813.     sta    tpak        ;    and the total packet number
  6814.     sta    tpak+1        ;        ...
  6815. rswt1:  lda    state        ; Fetch the current system state
  6816.     cmp    #'D        ; Are we trying to receive data?
  6817.     bne    rswt2        ; If not, try the next one
  6818.     jsr    rdat        ; Go try for the data packet
  6819.     jmp    rswt1        ; Go back to the top of the loop
  6820. rswt2:  cmp    #'F        ; Do we need a file header packet?
  6821.     bne    rswt3        ; If not, continue checking
  6822.     jsr    rfil        ; Go get the file-header
  6823.     jmp    rswt1        ; Return to top of loop
  6824. rswt3:  cmp    #'R        ; Do we need the init?
  6825.     bne    rswt4        ; No, try next state
  6826.     jsr    rini        ; Yes, go get it
  6827.     jmp    rswt1        ; Go back to top
  6828. rswt4:  cmp    #'C        ; Have we completed the transfer?
  6829.     bne    rswt5        ; No, we are out of states, fail
  6830.     lda    #true        ; Load AC for true return
  6831.     rts            ; Return
  6832. rswt5:  lda    errcod        ; [jrd] get the error code
  6833.     jsr    prerms        ; [jrd] print apropos message
  6834.     lda    #false        ; Set up AC for false return
  6835.     rts            ; Return
  6836.  
  6837. rini:    lda    #pdbuf\        ; Point kerbf1 at the packet data buffer
  6838.     sta    kerbf1        ;        ...
  6839.     lda    #pdbuf^        ;        ...
  6840.     sta    kerbf1+1    ;        ...
  6841.     lda    numtry        ; Get current number of tries
  6842.     inc    numtry        ; Increment it for next time
  6843.     cmp    maxtry        ; Have we tried this one enougth times
  6844.     beq    rini1        ; Not yet, go on
  6845.     bcs    rini1a        ; Yup, go abort this transfer
  6846. rini1:  jmp    rini2        ; Continue
  6847. rini1a: lda    #'A        ; Change state to 'abort'
  6848.     sta    state        ;        ...
  6849.     lda    #errcri        ; Fetch the error index
  6850.     sta    errcod        ;    and store it as the error code
  6851.     lda    #false        ; Load AC with false status
  6852.     rts            ;    and return
  6853. rini2:  jsr    rpak        ; Go try to receive a packet
  6854.     sta    rstat        ; Store the return status for later
  6855.     lda    ptype        ; Fetch the packet type we got
  6856.     cmp    #'S        ; Was it an 'Init'?
  6857.     bne    rini2a        ; No, check the return status
  6858.     jmp    rinici        ; Go handle the init case
  6859. rini2a: lda    rstat        ; Fetch the saved return status
  6860.     cmp    #false        ; Is it false?
  6861.     beq    rini2b        ; Yes, just return with same state
  6862.     lda    #errcri        ; No, fetch the error index
  6863.     sta    errcod        ;    and store it as the error code
  6864.     jsr    prcerp        ; Check for error packet and process it
  6865.     lda    #'A        ; Abort this transfer
  6866.     sta    state        ; State is now 'abort'
  6867.     lda    #false        ; Set return status to 'false'
  6868.     rts            ; Return
  6869. rini2b: lda    n        ; Get packet sequence number expected
  6870.     sta    pnum        ; Stuff that parameter at the Nakit routine
  6871.     jsr    nakit        ; Go send the Nak
  6872.     lda    #false        ; Set up failure return status
  6873.     rts            ;    and go back
  6874.  
  6875. rinici: lda    pnum        ; Get the packet number we received
  6876.     sta    n        ; Synchronize our packet numbers with this
  6877.     jsr    rpar        ; Load in the init stuff from packet buffer
  6878.     jsr    spar        ; Stuff our init info into the packet buffer
  6879.     lda    #'Y        ; Store the 'Ack' code into the packet type
  6880.     sta    ptype        ;        ...
  6881.     lda    n        ; Get sequence number
  6882.     sta    pnum        ; Stuff that parameter
  6883. ;
  6884. ; This batch of code depends on the fact that the 'Y that the other side sends
  6885. ; gets stuffed into sebq if he's merely saying 'Yes I can', not 'OK, I will'.
  6886. ; 'Y''s not a legal char, so that has the effect of turning ebqmod off.
  6887. ;
  6888.     lda    sebq        ; See what we got for an 8-bit quoting
  6889.     cmp    #$21        ; First check the character range
  6890.     bmi    rinicn        ; Not in range
  6891.     cmp    #$3F        ;        ...
  6892.     bmi    rinicy        ; Inrange
  6893.     cmp    #$60        ;        ...
  6894.     bmi    rinicn        ; Not in range
  6895.     cmp    #$7F        ;        ...
  6896.     bmi    rinicy        ; Inrange
  6897. rinicn: lda    #off        ; No, punt 8-bit quoting
  6898.     sta    ebqmod        ;        ...
  6899.     lda    #6        ; BTW, the data length is now only 6
  6900.     jmp    rinic1        ; Continue
  6901. rinicy: lda    #on        ; Make sure everything is on
  6902.     sta    ebqmod        ;        ...
  6903.     lda    #7        ; Data length for ack-init is 7
  6904. rinic1: sta    pdlen        ; Store packet data length
  6905.     jsr    spak        ; Send that packet
  6906.     lda    numtry        ; Move the number of tries for this packet
  6907.     sta    oldtry        ;    to prev packet try count
  6908.     lda    #0        ; Zero
  6909.     sta    numtry        ;    the number of tries for current packet
  6910.     jsr    incn        ; Increment the packet number once
  6911.     lda    #'F        ; Advance to 'File-header' state
  6912.     sta    state        ;        ...
  6913.     lda    #true        ; Set up return code
  6914.     rts            ; Return
  6915.  
  6916. rfil:    lda    numtry        ; Get number of tries for this packet
  6917.     inc    numtry        ; Increment it for next time around
  6918.     cmp    maxtry        ; Have we tried too many times?
  6919.     beq    rfil1        ; Not yet
  6920.     bcs    rfil1a        ; Yes, go abort the transfer
  6921. rfil1:  jmp    rfil2        ; Continue transfer
  6922. rfil1a: lda    #'A        ; Set state of system to 'abort'
  6923.     sta    state        ;        ...
  6924.     lda    #false        ; Return code should be 'false'
  6925.     rts            ; Return
  6926. rfil2:  jsr    rpak        ; Try to receive a packet
  6927.     sta    rstat        ; Save the return status
  6928.     lda    ptype        ; Get the packet type we found
  6929.     cmp    #'S        ; Was it an 'init' packet?
  6930.     bne    rfil2a        ; Nope, try next one
  6931.     jmp    rfilci        ; Handle the init case
  6932. rfil2a: cmp    #'Z        ; Is it an 'eof' packet??
  6933.     bne    rfil2b        ; No, try again
  6934.     jmp    rfilce        ; Yes, handle that case
  6935. rfil2b: cmp    #'F        ; Is it a 'file-header' packet???
  6936.     bne    rfil2c        ; Nope
  6937.     jmp    rfilcf        ; Handle file-header case
  6938. rfil2c: cmp    #'B        ; Break packet????
  6939.     bne    rfil2d        ; Wrong, go get the return status
  6940.     jmp    rfilcb        ; Handle a break packet
  6941. rfil2d: lda    rstat        ; Fetch the return status from Rpak
  6942.     cmp    #false        ; Was it a false return?
  6943.     beq    rfil2e        ; Yes, Nak it and return
  6944.     lda    #errcrf        ; No, fetch the error index
  6945.     sta    errcod        ;    and store it as the error code
  6946.     jsr    prcerp        ; Check for error packet and process it
  6947.     lda    #'A        ; Abort this transfer
  6948.     sta    state        ;        ...
  6949.     lda    #false        ; Set up failure return code
  6950.     rts            ;    and return
  6951. rfil2e: lda    n        ; Move the expected packet number
  6952.     sta    pnum        ;    into the spot for the parameter
  6953.     jsr    nakit        ; Nak the packet
  6954.     lda    #false        ; Do a false return but don't change state
  6955.     rts            ; Return
  6956. rfilci: lda    oldtry        ; Get number of tries for prev packet
  6957.     inc    oldtry        ; Increment it
  6958.     cmp    maxtry        ; Have we tried this one too much?
  6959.     beq    rfili1        ; Not quite yet
  6960.     bcs    rfili2        ; Yes, go abort this transfer
  6961. rfili1: jmp    rfili3        ; Continue
  6962. rfili2:
  6963. rfili5: lda    #'A        ; Move abort code
  6964.     sta    state        ;    to system state
  6965.     lda    #errcrf        ; Fetch the error index
  6966.     sta    errcod        ;    and store it as the error code
  6967.     lda    #false        ; Prepare failure return
  6968.     rts            ;    and go back
  6969. rfili3: lda    pnum        ; See if pnum=n-1
  6970.     clc            ;        ...
  6971.     adc    #1        ;        ...
  6972.     cmp    n        ;        ...
  6973.     beq    rfili4        ; If it does, than we are ok
  6974.     jmp    rfili5        ; Otherwise, abort
  6975. rfili4: jsr    spar        ; Set up the init parms in the packet buffer
  6976.     lda    #'Y        ; Set up the code for Ack
  6977.     sta    ptype        ; Stuff that parm
  6978.     lda    #6        ; Packet length for init
  6979.     sta    pdlen        ; Stuff that also
  6980.     jsr    spak        ; Send the ack
  6981.     lda    #0        ; Clear out
  6982.     sta    numtry        ;    the number of tries for current packet
  6983.     lda    #true        ; This is ok, return true with current state
  6984.     rts            ; Return
  6985. rfilce: lda    oldtry        ; Get number of tries for previous packet
  6986.     inc    oldtry        ; Up it for next time we have to do this
  6987.     cmp    maxtry        ; Too many times for this packet?
  6988.     beq    rfile1        ; Not yet, continue
  6989.     bcs    rfile2        ; Yes, go abort it
  6990. rfile1: jmp    rfile3        ;        ...
  6991. rfile2:
  6992. rfile5:    lda    #'A        ; Load abort code
  6993.     sta    state        ;    into current system state
  6994.     lda    #errcrf        ; Fetch the error index
  6995.     sta    errcod        ;    and store it as the error code
  6996.     lda    #false        ; Prepare failure return
  6997.     rts            ;    and return
  6998. rfile3:    lda    pnum        ; First, see if pnum=n-1
  6999.     clc            ;        ...
  7000.     adc    #1        ;        ...
  7001.     cmp    n        ;        ...
  7002.     beq    rfile4        ; If so, continue
  7003.     jmp    rfile5        ; Else, abort it
  7004. rfile4: lda    #'Y        ; Load 'ack' code
  7005.     sta    ptype        ; Stuff that in the packet type
  7006.     lda    #0        ; This packet will have a packet data length
  7007.     sta    pdlen        ;    of zero
  7008.     jsr    spak        ; Send the packet out
  7009.     lda    #0        ; Zero number of tries for current packet
  7010.     sta    numtry        ;        ...
  7011.     lda    #true        ; Set up successful return code
  7012.     rts            ;    and return
  7013. rfilcf: lda    pnum        ; Does pnum=n?
  7014.     cmp    n        ;        ...
  7015.     bne    rfilf1        ; If not, abort
  7016.     jmp    rfilf2        ; Else, we can continue
  7017. rfilf1:    lda    #'A        ; Load the abort code
  7018.     sta    state        ;    and stuff it as current system state
  7019.     lda    #errcrf        ; Fetch the error index
  7020.     sta    errcod        ;    and store it as the error code
  7021.     lda    #false        ; Prepare failure return
  7022.     rts            ;    and go back
  7023. rfilf2: jsr    getfil        ; Get the filename we are to use
  7024.     lda    #fncwrt        ; Tell the open routine we want to write
  7025.     jsr    openf        ; Open up the file
  7026.     jsr    logrcv        ; tell user what we're receiving
  7027.     lda    #'Y        ; Stuff code for 'ack'
  7028.     sta    ptype        ; Into packet type parm
  7029.     lda    #0        ; Stuff a zero in as the packet data length
  7030.     sta    pdlen        ;        ...
  7031.     jsr    spak        ; Ack the packet
  7032.     lda    numtry        ; Move current tries to previous tries
  7033.     sta    oldtry        ;        ...
  7034.     lda    #0        ; Clear the
  7035.     sta    numtry        ; Number of tries for current packet
  7036.     jsr    incn        ; Increment the packet sequence number once
  7037.     lda    #'D        ; Advance the system state to 'receive-data'
  7038.     sta    state        ;        ...
  7039.     lda    #true        ; Set up success return
  7040.     rts            ;    and go back
  7041. rfilcb: lda    pnum        ; Does pnum=n?
  7042.     cmp    n        ;        ...
  7043.     bne    rfilb1        ; If not, abort the transfer process
  7044.     jmp    rfilb2        ; Otherwise, we can continue
  7045. rfilb1:    lda    #'A        ; Code for abort
  7046.     sta    state        ; Stuff that into system state
  7047.     lda    #errcrf        ; Fetch the error index
  7048.     sta    errcod        ;    and store it as the error code
  7049.     lda    #false        ; Load failure return status
  7050.     rts            ;    and return
  7051. rfilb2: lda    #'Y        ; Set up 'ack' packet type
  7052.     sta    ptype        ;        ...
  7053.     lda    #0        ; Zero out
  7054.     sta    pdlen        ;    the packet data length
  7055.     jsr    spak        ; Send out this packet
  7056.     lda    #'C        ; Advance state to 'complete'
  7057.     sta    state        ;    since we are now done with the transfer
  7058.     lda    #true        ; Return a true
  7059.     rts            ;        ...
  7060.  
  7061. rdat:    lda    numtry        ; Get number of tries for current packet
  7062.     inc    numtry        ; Increment it for next time around
  7063.     cmp    maxtry        ; Have we gone beyond number of tries allowed?
  7064.     beq    rdat1        ; Not yet, so continue
  7065.     bcs    rdat1a        ; Yes, we have, so abort
  7066. rdat1:  jmp    rdat2        ;        ...
  7067. rdat1a: lda    #'A        ; Code for 'abort' state
  7068.     sta    state        ; Stuff that in system state
  7069.     lda    #errcrd        ; Fetch the error index
  7070.     sta    errcod        ;    and store it as the error code
  7071.     lda    #false        ; Set up failure return code
  7072.     rts            ;    and go back
  7073. rdat2:  jsr    rpak        ; Go try to receive a packet
  7074.     sta    rstat        ; Save the return status for later
  7075.     lda    ptype        ; Get the type of packet we just picked up
  7076.     cmp    #'D        ; Was it a data packet?
  7077.     bne    rdat2a        ; If not, try next type
  7078.     jmp    rdatcd        ; Handle a data packet
  7079. rdat2a: cmp    #'F        ; Is it a file-header packet?
  7080.     bne    rdat2b        ; Nope, try again
  7081.     jmp    rdatcf        ; Go handle a file-header packet
  7082. rdat2b: cmp    #'Z        ; Is it an eof packet???
  7083.     bne    rdat2c        ; If not, go check the return status from rpak
  7084.     jmp    rdatce        ; It is, go handle eof processing
  7085. rdat2c: lda    rstat        ; Fetch the return status
  7086.     cmp    #false        ; Was it a failure return?
  7087.     beq    rdat2d        ; If it was, Nak it
  7088.     lda    #errcrd        ; Fetch the error index
  7089.     sta    errcod        ;    and store it as the error code
  7090.     jsr    prcerp        ; Check for error packet and process it
  7091.     lda    #'A        ; Give up the whole transfer
  7092.     sta    state        ; Set system state to 'false'
  7093.     lda    #false        ; Set up a failure return
  7094.     rts            ;    and go back
  7095. rdat2d: lda    n        ; Get the expected packet number
  7096.     sta    pnum        ; Stuff that parameter for Nak routine
  7097.     jsr    nakit        ; Send a Nak packet
  7098.     lda    #false        ; Give failure return
  7099.     rts            ; Go back
  7100.  
  7101. rdatcd: lda    pnum        ; Is pnum the right sequence number?
  7102.     cmp    n        ;        ...
  7103.     bne    rdatd1        ; If not, try another approach
  7104.     jmp    rdatd7        ; Otherwise, everything is fine
  7105. rdatd1: lda    oldtry        ; Get number of tries for previous packet
  7106.     inc    oldtry        ; Increment it for next time we need it
  7107.     cmp    maxtry        ; Have we exceeded that limit?
  7108.     beq    rdatd2        ; Not just yet, continue
  7109.     bcs    rdatd3        ; Yes, go abort the whole thing
  7110. rdatd2: jmp    rdatd4        ; Just continue working on the thing
  7111. rdatd3:
  7112. rdatd6:    lda    #'A        ; Load 'abort' code into the
  7113.     sta    state        ;    current system state
  7114.     lda    #errcrd        ; Fetch the error index
  7115.     sta    errcod        ;    and store it as the error code
  7116.     lda    #false        ; Make this a failure return
  7117.     rts            ; Return
  7118. rdatd4: lda    pnum        ; Is pnum=n-1... Is the received packet
  7119.     clc            ;    the one previous to the currently
  7120.     adc    #1        ;    expected packet?
  7121.     cmp    n        ;        ...
  7122.     beq    rdatd5        ; Yes, continue transfer
  7123.     jmp    rdatd6        ; Nope, abort the whole thing
  7124. rdatd5: jsr    spar        ; Go set up init data
  7125.     lda    #'Y        ; Make it look like an ack to a send-init
  7126.     sta    ptype        ;        ...
  7127.     lda    #6        ;        ...
  7128.     sta    pdlen        ;        ...
  7129.     jsr    spak        ; Go send the ack
  7130.     lda    #0        ; Clear the
  7131.     sta    numtry        ;    number of tries for current packet
  7132.     lda    #true        ;        ...
  7133.     rts            ; Return (successful!)
  7134. rdatd7: 
  7135.     jsr    closers        ; [jrd] Close port while doing disk things
  7136.                 ;  spak or rpak will reopen it
  7137.     jsr    bufemp        ; Go empty the packet buffer
  7138. ;
  7139. ; [jrd]    if losing, send an abort
  7140. ;
  7141.     cmp    #true        ; [jrd] we win?
  7142.     bne    rdatd8        ; [jrd] nope, go abort xfer
  7143. ;
  7144.     lda    #'Y        ; Set up an ack packet
  7145.     sta    ptype        ;        ...
  7146.     lda    n        ;        ...
  7147.     sta    pnum        ;        ...
  7148.     lda    #0        ; Don't forget, there is no data
  7149.     sta    pdlen        ;        ...
  7150.     jsr    spak        ; Send it!
  7151.     lda    numtry        ; Move tries for current packet count to
  7152.     sta    oldtry        ;    tries for previous packet count
  7153.     lda    #0        ; Zero the
  7154.     sta    numtry        ;    number of tries for current packet
  7155.     jsr    incn        ; Increment the packet sequence number once
  7156.     lda    #'D        ; Advance the system state to 'receive-data'
  7157.     sta    state        ;        ...
  7158.     lda    #true        ;        ...
  7159.     rts            ; Return (successful)
  7160. ;
  7161. ; all this added by jrd
  7162. rdatd8:    lda    #'A        ; set packet type
  7163.     sta    ptype
  7164.     lda    #0        ; set data length
  7165.     sta    pdlen
  7166.     jsr    spak        ; send it
  7167.     lda    #'A        ; set
  7168.     sta    state        ;  rswt machine state
  7169.     lda    #0        ; Make CLOSEF see there are no errors
  7170.     jsr    closef        ; We are done with this file, so close it
  7171.     lda    #false        ; say we lost
  7172.     rts            ; and return
  7173. ;
  7174. rdatcf: lda    oldtry        ; Fetch number of tries for previous packet
  7175.     inc    oldtry        ; Increment it for when we need it again
  7176.     cmp    maxtry        ; Have we exceeded maximum tries allowed?
  7177.     beq    rdatf1        ; Not yet, go on
  7178.     bcs    rdatf2        ; Yup, we have to abort this thing
  7179. rdatf1: jmp    rdatf3        ; Just continue the transfer
  7180. rdatf2:
  7181. rdatf5:    lda    #'A        ; Move 'abort' code to current system state
  7182.     sta    state        ;        ...
  7183.     lda    #errcrd        ; Fetch the error index
  7184.     sta    errcod        ;    and store it as the error code
  7185.     lda    #false        ;        ...
  7186.     rts            ;    and return false
  7187. rdatf3: lda    pnum        ; Is this packet the one before the expected
  7188.     clc            ;    one?
  7189.     adc    #1        ;        ...
  7190.     and    #$3F        ; [jrd]
  7191.     cmp    n        ;        ...
  7192.     beq    rdatf4        ; If so, we can still ack it
  7193.     jmp    rdatf5        ; Otherwise, we should abort the transfer
  7194. rdatf4: lda    #'Y        ; Load 'ack' code
  7195.     sta    ptype        ; Stuff that parameter
  7196.     lda    #0        ; Use zero as the packet data length
  7197.     sta    pdlen        ;        ...
  7198.     jsr    spak        ; Send it!
  7199.     lda    #0        ; Zero the number of tries for current packet
  7200.     sta    numtry        ;        ...
  7201.     lda    #true        ;        ...
  7202.     rts            ; Return (successful)
  7203.  
  7204. rdatce: lda    pnum        ; Is this the packet we are expecting?
  7205.     cmp    n        ;        ...
  7206.     bne    rdate1        ; No, we should go abort
  7207.     jmp    rdate2        ; Yup, go handle it
  7208. rdate1:    lda    #'A        ; Load 'abort' code into
  7209.     sta    state        ;    current system state
  7210.     lda    #errcrd        ; Fetch the error index
  7211.     sta    errcod        ;    and store it as the error code
  7212.     lda    #false        ;        ...
  7213.     rts            ; Return (failure)
  7214. rdate2:
  7215. ;    lda    #fcb1\        ; Get the pointer to the fcb
  7216. ;    sta    kerfcb        ;    and store it where the close routine
  7217. ;    lda    #fcb1^        ;    can find it
  7218. ;    sta    kerfcb        ;        ...
  7219.     lda    #0        ; Make CLOSEF see there are no errors
  7220.     jsr    closef        ; We are done with this file, so close it
  7221. ; ?!?!    jsr    incn        ; Increment the packet number
  7222.     lda    #'Y        ; Get set up for the ack
  7223.     sta    ptype        ; Stuff the packet type
  7224.     lda    n        ;    packet number
  7225.     sta    pnum        ;        ...
  7226.     lda    #0        ;    and packet data length
  7227.     sta    pdlen        ;    parameters
  7228.     jsr    spak        ; Go send it!
  7229. ;
  7230. ; zzzzz try this here
  7231. ;
  7232.     jsr    incn        ; Increment the packet number
  7233.     lda    #'F        ; Advance system state to 'file-header'
  7234.     sta    state        ;    incase more files are coming
  7235.     lda    #true        ;        ...
  7236.     rts            ; Return (successful)
  7237.  
  7238. ;
  7239. ;    stuff for mapping ops over filenames.
  7240. ;
  7241. ;    state vars
  7242. ;
  7243. diropen: .byte    0        ; if directory in progress
  7244. direof:    .byte    0        ; if we've run out of files
  7245. dirspec: .byte    "                 " ; room for max pn + ATEOL
  7246. ;
  7247.  
  7248. ;    dirini:        init the directory stuff.  Expects a pathname 
  7249. ;            in path.
  7250. dirini:
  7251.     jsr    dircls        ; make sure dir closed first
  7252.     lda    #path\        ; point at the pathname struct
  7253.     sta    pndptr
  7254.     lda    #path^
  7255.     sta    pndptr+1
  7256.     ldx    #dirspec\    ; and point at the string
  7257.     ldy    #dirspec^
  7258.     jsr    pn2str        ; convert pathname to string
  7259. ;
  7260. dirrini:            ; entry pt for re-init
  7261.     lda    #dirspec\    ; get string addr
  7262.     ldy    #dirspec^
  7263.     ldx    #dirchan    ; get dir iocb
  7264.     jsr    opencdir    ; open directory
  7265.     cpy    #SUCCES        ; did we win?
  7266.     bne    dirini9        ; nope, go die
  7267.     lda    #1        ; say we've got it open
  7268.     sta    diropen
  7269.     lda    #0        ; and that it's not yet at eof
  7270.     sta    direof
  7271.     rts            ; done!
  7272. dirini9:
  7273.     lda    #0        ; say it's not open
  7274.     sta    diropen
  7275.     jsr    closec        ; make sure closed again
  7276.     rts
  7277. ;
  7278. ;    dircls:        Close the dir channel if it's open
  7279. ;
  7280. dircls:
  7281.     lda    diropen        ; open?
  7282.     beq    dircls9        ; nope, go home
  7283.     ldx    #dirchan    ; get the dir iocb
  7284.     jsr    closec        ; and close it
  7285.     lda    #0        ; say it's not open any more
  7286.     sta    diropen
  7287. dircls9:
  7288.     rts            ; home!
  7289. ;
  7290. ;    dirnxt:        Get next entry in the directory into dirpath.
  7291. ;            Returns carry clear if wins, carry set if lose
  7292. ;
  7293. dirnxt:
  7294.     lda    diropen        ; won't work if it's not open
  7295.     bne    dirnxt0        ; We're ok
  7296.     jmp    dirnxt9        ; Oops! No good
  7297. dirnxt0:
  7298.     ldx    #dirchan    ; get the dir iocb
  7299.     jsr    chrin        ; get a char
  7300.     sta    dirplck        ; save the 'locked' flag
  7301.     cmp    #space        ; good entries start with
  7302.     beq    dirnxt1        ;  space or star
  7303.     cmp    #'*
  7304.     bne    dirnxt8        ; end of dir, close up and leave
  7305. dirnxt1:
  7306.     jsr    chrin        ; skip this char
  7307.     ldy    #0        ; zap length of name fld
  7308.     sty    dirpath+pnd.ns    ; really should do something general...
  7309.     ldy    #8        ; length of name fld
  7310.     sty    source        ; used as temp
  7311. dirnxt2:
  7312.     jsr    chrin        ; get a byte
  7313.     cmp    #space        ; end of name?
  7314.     beq    dirnxt3        ; yup, don't push this one
  7315.     ldy    dirpath+pnd.ns    ; get name comp size
  7316.     sta    dirpath+pnd.nt,y    ; and shove the byte
  7317.     iny            ; bump size
  7318.     sty    dirpath+pnd.ns    ; and put it back
  7319. dirnxt3:
  7320.     dec    source        ; dec counter
  7321.     bne    dirnxt2        ; not done yet, go round again
  7322.     ldy    #0        ; zap length of ext fld
  7323.     sty    dirpath+pnd.es    ; really should do something general...
  7324.     ldy    #3        ; length of ext fld
  7325.     sty    source        ; used as temp
  7326. dirnxt4:
  7327.     jsr    chrin        ; get a byte
  7328.     cmp    #space        ; end of ext?
  7329.     beq    dirnxt5        ; yup, don't push this one
  7330.     ldy    dirpath+pnd.es    ; get ext comp size
  7331.     sta    dirpath+pnd.et,y    ; and shove the byte
  7332.     iny            ; bump size
  7333.     sty    dirpath+pnd.es    ; and put it back
  7334. dirnxt5:
  7335.     dec    source        ; dec counter
  7336.     bne    dirnxt4        ; not done yet, go round again
  7337. ;
  7338. ; done with name.  collect the sector count.
  7339. ;
  7340. dirnxt6:
  7341.     jsr    chrin        ; ignore this one
  7342.     jsr    chrin
  7343.     sta    dirsect
  7344.     jsr    chrin
  7345.     sta    dirsect+1
  7346.     jsr    chrin
  7347.     sta    dirsect+2
  7348. dirnxt6a:
  7349.     cmp    #ATEOL        ; shouldn't be the first time, but be safe
  7350.     beq    dirnxt7
  7351.     jsr    chrin
  7352.     jmp    dirnxt6a:
  7353. dirnxt7:
  7354.     
  7355. ;
  7356. ; set bits in name
  7357. ;
  7358.     lda    #pnf.np!pnf.ep
  7359.     sta    dirpath+pnd.fl
  7360.     clc            ; say we've got one
  7361.     rts            ; and return
  7362. dirnxt8:            ; copy rest of dir str someplace
  7363.                 ;  (primfn will do)
  7364.     sta    primfn        ; that's the first byte
  7365.     ldy    #1        ; that'll be the idx
  7366.     sty    strptr        ; temp
  7367. dirnxt8a:
  7368.     jsr    chrin        ; get a byte
  7369.     ldy    strptr        ; get idx back
  7370.     sta    primfn,y    ; store the byte
  7371.     iny            ; bump
  7372.     sty    strptr        ;  and save it
  7373.     cmp    #ATEOL        ; end of line?
  7374.     bne    dirnxt8a    ; nope, do some more
  7375.     jsr    dircls        ; done, close up
  7376. dirnxt9:
  7377.     sec            ; say we lose
  7378.     rts            ; and return
  7379.  
  7380. ;
  7381. ;.SBTTL    Send routine
  7382.  
  7383. ;
  7384. ;    This routine reads a file from disk and sends packets
  7385. ;    of data to the remote kermit.
  7386. ;
  7387. ;        Input:  Filename returned from Comnd routines
  7388. ;
  7389. ;        Output: File is sent over port
  7390. ;
  7391. ;        Registers destroyed:    A,X,Y
  7392. ;
  7393.  
  7394. send:
  7395. ;
  7396. ; old send startup code commented out while debugging wildcard stuff
  7397. ;    ldx    #mxfnl        ; Longest length a filename may be
  7398. ;    ldy    #0        ; No special flags needed
  7399. ;    lda    #cmifi        ; Load opcode for parsing input files
  7400. ;    jsr    comnd        ; Call comnd routine
  7401. ;     jmp    kermt6        ; Give the 'missing filespec' error
  7402. ;    sta    kwrk01        ; Store length of file parsed
  7403. ;    stx    kerfrm        ; Save the from address (addr[atmbuf])
  7404. ;    sty    kerfrm+1    ;        ...
  7405. ;    lda    #fcb1\        ; Save the to address (Fcb1)
  7406. ;    sta    kerto        ;        ...
  7407. ;    lda    #fcb1^        ;        ...
  7408. ;    sta    kerto+1        ;        ...
  7409. ;    jsr    clrfcb        ; Clear the fcb
  7410. ;    jsr    kercpy        ; Copy the string
  7411. ;    ldy    kwrk01        ; Get filename length
  7412. ;;zzzzz    lda    #nul        ; Fetch a null character
  7413. ;    lda    #ATEOL        ; terminate with eol zzz?
  7414. ;    sta    (kerto),y    ; Stuff a null at end-of-buffer
  7415. ;-----
  7416.     lda    #0        ; allow default of *.*
  7417.     jsr    enterpn        ;  and get a pathname
  7418.     jsr    prcfm        ; confirm it
  7419.     jsr    parsefcb    ; parse and merge the resultant filespec
  7420.     jsr    closers        ; make sure comm port's closed
  7421.     jsr    bldprm        ; [jrd] reformat it
  7422.     jsr    dirini
  7423.     lda    #0        ; zap
  7424.     sta    ssfidx        ;  the file idx
  7425.     jsr    ssfnxt        ; [jrd] get the first file
  7426.     bcs    send9        ; zzz print error if no match
  7427. ;----
  7428.     jsr    openrs        ;[27] Reset the RS232 channel
  7429.     jsr    sswt        ; Perform send-switch routine
  7430.     jsr    closers        ; [jrd] close comm port
  7431.     jsr    closef        ; make sure file closed
  7432. send9:
  7433.     jmp    kermit        ; Go back to main routine
  7434.  
  7435. ;
  7436. ; util for dealing with getting next file set up, etc.  Leaves
  7437. ; fcb1 with name.ext in it.  Returns carry set if fails.  Leaves 
  7438. ; directory stream closed, so as not to confuse OS by opening 
  7439. ; file while directory's open
  7440. ;
  7441. ssfidx:    .byte    0        ; how many files we've done
  7442. ssfnxt:
  7443.     jsr    closers        ; make sure comm's closed
  7444.     lda    ssfidx        ; get file nbr
  7445.     beq    ssfnx0        ; first time?  ok, just go ahead
  7446.     pha            ; save the old idx
  7447.     jsr    dirrini        ; reinit directory to value from last time
  7448. ssfnsk:                ; skip the next file entry
  7449.     jsr    dirnxt        ; get next entry
  7450.     bcc    ssfnsk1        ; more here...
  7451.     pla            ; oops! no more, flush dead val
  7452.     jmp    ssfnx9        ;  on stack and return error
  7453. ssfnsk1:
  7454.     dec    ssfidx        ; dec count of files we've done
  7455.     bne    ssfnsk        ; still more, keep skipping
  7456.     pla            ; get original count back
  7457.     sta    ssfidx        ; save it
  7458. ssfnx0:                ; done skipping, take the next one
  7459.     jsr    dirnxt        ; get one
  7460.     bcc    ssfnx1        ; succeeded, go ahead
  7461. ssfnx9:    jsr    dircls        ; failed, close up,
  7462.     sec            ; and return error
  7463.     rts
  7464. ssfnx1:
  7465.     lda    #dirpath\    ; point at the pathname struct
  7466.     sta    pndptr
  7467.     lda    #dirpath^
  7468.     sta    pndptr+1
  7469.     ldx    #fcb1\        ; and point at the string
  7470.     ldy    #fcb1^
  7471.     jsr    pn2str        ; convert pathname to string
  7472.     jsr    dircls        ; close dir so we can hack file
  7473.     inc    ssfidx        ; say we've done this one
  7474.     clc            ; return success code
  7475.     rts
  7476. ;
  7477. sswt:    lda    #'S        ; Set up state variable as
  7478.     sta    state        ;    Send-init
  7479.     lda    #0        ; Clear
  7480.     sta    eodind        ;    The End-of-Data indicator
  7481.     sta    n        ;    Packet number
  7482.     sta    numtry        ;    Number of tries
  7483.     sta    oldtry        ;    Old number of tries
  7484.     sta    eofinp        ;    End of input flag
  7485.     sta    errcod        ;    Error indicator
  7486.     sta    rtot        ;    Total received characters
  7487.     sta    rtot+1        ;        ...
  7488.     sta    stot        ;    Total Sent characters
  7489.     sta    stot+1        ;        ...
  7490.     sta    rchr        ;    Received characters, current file
  7491.     sta    rchr+1        ;        ...
  7492.     sta    schr        ;    and Sent characters, current file
  7493.     sta    schr+1        ;        ...
  7494.     sta    tpak        ;    and the total packet number
  7495.     sta    tpak+1        ;        ...
  7496.     lda    #pdbuf\        ; Set up the address of the packet buffer
  7497.     sta    saddr        ;    so that we can clear it out
  7498.     lda    #pdbuf^        ;        ...
  7499.     sta    saddr+1        ;        ...
  7500.     lda    #0        ; Clear AC
  7501.     ldy    #0        ; Clear Y
  7502. clpbuf: sta    (saddr),y    ; Step through buffer, clearing it out
  7503.     iny            ; Up the index
  7504.     cpy    #mxpack-4    ; Done?
  7505.     bmi    clpbuf        ; No, continue
  7506. sswt1:  lda    state        ; Fetch state of the system
  7507.     cmp    #'D        ; Do Send-data?
  7508.     bne    sswt2        ; No, try next one
  7509.     jsr    sdat        ; Yes, send a data packet
  7510.     jmp    sswt1        ; Go to the top of the loop
  7511. sswt2:  cmp    #'F        ; Do we want to send-file-header?
  7512.     bne    sswt3        ; No, continue
  7513.     jsr    sfil        ; Yes, send a file header packet
  7514.     jmp    sswt1        ; Return to top of loop
  7515. sswt3:  cmp    #'Z        ; Are we due for an Eof packet?
  7516.     bne    sswt4        ; Nope, try next state
  7517.     jsr    seof        ; Yes, do it
  7518.     jmp    sswt1        ; Return to top of loop
  7519. sswt4:  cmp    #'S        ; Must we send an init packet
  7520.     bne    sswt5        ; No, continue
  7521.     jsr    sini        ; Yes, go do it
  7522.     jmp    sswt1        ; And continue
  7523. sswt5:  cmp    #'B        ; Time to break the connection?
  7524.     bne    sswt6        ; No, try next state
  7525.     jsr    sbrk        ; Yes, go send a break packet
  7526.     jmp    sswt1        ; Continue from top of loop
  7527. sswt6:  cmp    #'C        ; Is the entire transfer complete?
  7528.     bne    sswt7        ; No, something is wrong, go abort
  7529.     lda    #true        ; Return true
  7530.     rts            ;        ...
  7531. sswt7:  lda    errcod        ; [jrd] get the error code
  7532.     jsr    prerms        ; [jrd] print apropos message
  7533.     lda    #false        ; Return false
  7534.     rts            ;        ...
  7535.  
  7536. sdat:    lda    numtry        ; Fetch the number for tries for current packet
  7537.     inc    numtry        ; Add one to it
  7538.     cmp    maxtry        ; Is it more than the maximum allowed?
  7539.     beq    sdat1        ; No, not yet
  7540.     bcs    sdat1a        ; If it is, go abort
  7541. sdat1:  jmp    sdat1b        ; Continue
  7542. sdat1a: lda    #'A        ; Load the 'abort' code
  7543.     sta    state        ; Stuff that in as current state
  7544.     lda    #false        ; Enter false return code
  7545.     rts            ;    and return
  7546. sdat1b: lda    #'D        ; Packet type will be 'Send-data'
  7547.     sta    ptype        ;        ...
  7548.     lda    n        ; Get packet sequence number
  7549.     sta    pnum        ; Store that parameter to Spak
  7550.     lda    size        ; This is the size of the data in the packet
  7551.     sta    pdlen        ; Store that where it belongs
  7552.     jsr    spak        ; Go send the packet
  7553. sdat2:  jsr    rpak        ; Try to get an ack
  7554.     sta    rstat        ; First, save the return status
  7555.     lda    ptype        ; Now get the packet type received
  7556.     cmp    #'N        ; Was it a NAK?
  7557.     bne    sdat2a        ; No, try for an ACK
  7558.     jmp    sdatcn        ; Go handle the nak case
  7559. sdat2a: cmp    #'Y        ; Did we get an ACK?
  7560.     bne    sdat2b        ; No, try checking the return status
  7561.     jmp    sdatca        ; Yes, handle the ack
  7562. sdat2b: lda    rstat        ; Fetch the return status
  7563.     cmp    #false        ; Failure return?
  7564.     beq    sdat2c        ; Yes, just return with current state
  7565.     jsr    prcerp        ; Check for error packet and process it
  7566.     lda    #'A        ; Stuff the abort code
  7567.     sta    state        ;    as the current system state
  7568.     lda    #false        ; Load failure return code
  7569. sdat2c: rts            ; Go back
  7570. sdatcn: dec    pnum        ; Decrement the packet sequence number
  7571.     lda    n        ; Get the expected packet sequence number
  7572.     cmp    pnum        ; If n=pnum-1 then this is like an ack
  7573.     bne    sdatn1        ; No, continue handling the nak
  7574.     jmp    sdata2        ; Jump to ack bypassing sequence check
  7575. sdata1:
  7576. sdatn1: lda    #false        ; Failure return
  7577.     rts            ;        ...
  7578. sdatca: lda    n        ; First check packet number
  7579.     cmp    pnum        ; Did he ack the correct packet?
  7580.     bne    sdata1        ; No, go give failure return
  7581. sdata2: lda    #0        ; Zero out number of tries for current packet
  7582.     sta    numtry        ;        ...
  7583.     jsr    incn        ; Increment the packet sequence number
  7584.     jsr    closers        ; [jrd] Close port while doing disk things.
  7585.                 ;  spak or rpak will re-open it
  7586.     jsr    bufill        ; Go fill the packet buffer with data
  7587.     sta    size        ; Save the data size returned
  7588.     lda    eofinp        ; Load end-of-file indicator
  7589.     cmp    #true        ; Was this set by Bufill?
  7590.     beq    sdatrz        ; If so, return state 'Z' ('Send-eof')
  7591.     jmp    sdatrd        ; Otherwise, return state 'D' ('Send-data')
  7592. sdatrz:    lda    #0        ; Clear
  7593.     sta    eofinp        ;    End of input flag
  7594. ;    lda    #fcb1\        ; Get the pointer to the fcb
  7595. ;    sta    kerfcb        ;    and store it where the close routine
  7596. ;    lda    #fcb1^        ;    can find it
  7597. ; zzz    sta    kerfcb        ;        ...
  7598.     lda    #0        ; Make CLOSEF see there are no errors
  7599.     jsr    closef        ; We are done with this file, so close it.  Closes rs
  7600.     lda    #'Z        ; Load the Eof code
  7601.     sta    state        ;    and make it the current system state
  7602.     lda    #true        ; We did succeed, so give a true return
  7603.     rts            ; Go back
  7604. sdatrd: lda    #'D        ; Load the Data code
  7605.     sta    state        ; Set current system state to that
  7606.     lda    #true        ; Set up successful return
  7607.     rts            ;    and go back
  7608.  
  7609. sfil:
  7610. sfil0:    lda    numtry        ; Fetch the current number of tries
  7611.     inc    numtry        ; Up it by one
  7612.     cmp    maxtry        ; See if we went up to too many
  7613.     beq    sfil1        ; Not yet
  7614.     bcs    sfil1a        ; Yes, go abort
  7615. sfil1:    jmp    sfil1b        ; If we are still ok, take this jump
  7616. sfil1a:    lda    #'A        ; Load code for abort
  7617.     sta    state        ;    and drop that in as the current state
  7618.     lda    #false        ; Load false for a return code
  7619.     rts            ;    and return
  7620. sfil1b:    ldy    #0        ; Clear Y
  7621. sfil1c:    lda    fcb1,y        ; Get a byte from the filename
  7622.     cmp    #0        ; Is it a null?
  7623.     beq    sfil1d        ; No, continue
  7624. ; zzz    cmp    #$20        ; <sp>?
  7625.     cmp    #ATEOL        ; end of file name in Atari-land?
  7626.     beq    sfil1d        ;[DD]
  7627.     sta    pdbuf,y        ; Move the byte to this buffer
  7628.     iny            ; Up the index once
  7629.     jmp    sfil1c        ; Loop and do it again
  7630. sfil1d:    sty    pdlen        ; This is the length of the filename
  7631.     lda    #'F        ; Load type ('Send-file')
  7632.     sta    ptype        ; Stuff that in as the packet type
  7633.     lda    n        ; Get packet number
  7634.     sta    pnum        ; Store that in its common area
  7635.     jsr    spak        ; Go send the packet
  7636. sfil2:    jsr    rpak        ; Go try to receive an ack
  7637.     sta    rstat        ; Save the return status
  7638.     lda    ptype        ; Get the returned packet type
  7639.     cmp    #'N        ; Is it a NAK?
  7640.     bne    sfil2a        ; No, try the next packet type
  7641.     jmp    sfilcn        ; Handle the case of a nak
  7642. sfil2a:    cmp    #'Y        ; Is it, perhaps, an ACK?
  7643.     bne    sfil2b        ; If not, go to next test
  7644.     jmp    sfilca        ; Go and handle the ack case
  7645. sfil2b:    lda    rstat        ; Get the return status
  7646.     cmp    #false        ; Is it a failure return?
  7647.     bne    sfil2c        ; No, just go abort the send
  7648.     rts            ; Return failure with current state
  7649. sfil2c:    jsr    prcerp        ; Check for error packet and process it
  7650.     lda    #'A        ; Set state to 'abort'
  7651.     sta    state        ; Stuff it in its place
  7652.     lda    #false        ; Set up a failure return code
  7653.     rts            ;    and go back
  7654. sfilcn:    dec    pnum        ; Decrement the receive packet number once
  7655.     lda    pnum        ; Load it into the AC
  7656.     cmp    n        ; Compare that with what we are looking for
  7657.     bne    sfiln1        ; If n=pnum-1 then this is like an ack, do it
  7658.     jmp    sfila2        ; This is like an ack
  7659. sfila1:    
  7660. sfiln1:    lda    #false        ; Load failure return code
  7661.     rts            ;    and return
  7662. sfilca:    lda    n        ; Get the packet number
  7663.     cmp    pnum        ; Is that the one that was acked?
  7664.     bne    sfila1        ; They are not equal
  7665. sfila2:    lda    #0        ; Clear AC
  7666.     sta    numtry        ; Zero the number of tries for current packet
  7667.     jsr    incn        ; Up the packet sequence number
  7668. ;    lda    #fcb1\        ; Load the fcb address into the pointer
  7669. ;    sta    kerfcb        ;    for the DOS open routine
  7670. ;    lda    #fcb1^        ;        ...
  7671. ; zzz    sta    kerfcb+1    ;        ...
  7672.     lda    #fncrea        ; Open for input
  7673.     jsr    openf        ; Open the file.  Closes rs
  7674.     jsr    logsnd        ; tell user what we're sending
  7675.     jsr    bufill        ; Go get characters from the file
  7676.     sta    size        ; Save the returned buffer size
  7677.     jsr    openrs        ; [jrd] now safe to use serial again
  7678.     lda    #'D        ; Set state to 'Send-data'
  7679.     sta    state        ;        ...
  7680.     lda    #true        ; Set up true return code
  7681.     rts            ;    and return
  7682.  
  7683. seof:    lda    numtry        ; Get the number of attempts for this packet
  7684.     inc    numtry        ; Now up it once for next time around
  7685.     cmp    maxtry        ; Are we over the allowed max?
  7686.     beq    seof1        ; Not quite yet
  7687.     bcs    seof1a        ; Yes, go abort
  7688. seof1:  jmp    seof1b        ; Continue sending packet
  7689. seof1a: lda    #'A        ; Load 'abort' code
  7690.     sta    state        ; Make that the state of the system
  7691.     lda    #errmrc        ; Fetch the error index
  7692.     sta    errcod        ;    and store it as the error code
  7693.     lda    #false        ; Return false
  7694.     rts            ;        ...
  7695. seof1b: lda    #'Z        ; Load the packet type 'Z' ('Send-eof')
  7696.     sta    ptype        ; Save that as a parm to Spak
  7697.     lda    n        ; Get the packet sequence number
  7698.     sta    pnum        ; Copy in that parm
  7699.     lda    #0        ; This is our packet data length (0 for EOF)
  7700.     sta    pdlen        ; Copy it
  7701.     jsr    spak        ; Go send out the Eof
  7702. seof2:  jsr    rpak        ; Try to receive an ack for it
  7703.     sta    rstat        ; Save the return status
  7704.     lda    ptype        ; Get the received packet type
  7705.     cmp    #'N        ; Was it a nak?
  7706.     bne    seof2a        ; If not, try the next packet type
  7707.     jmp    seofcn        ; Go take care of case nak
  7708. seof2a: cmp    #'Y        ; Was it an ack
  7709.     bne    seof2b        ; If it wasn't that, try return status
  7710.     jmp    seofca        ; Take care of the ack
  7711. seof2b: lda    rstat        ; Fetch the return status
  7712.     cmp    #false        ; Was it a failure?
  7713.     beq    seof2c        ; Yes, just fail return with current state
  7714.     jsr    prcerp        ; Check for error packet and process it
  7715.     lda    #'A        ; No, abort the whole thing
  7716.     sta    state        ; Set the state to that
  7717.     lda    #false        ; Get false return status
  7718. seof2c: rts            ; Return
  7719. seofcn: dec    pnum        ; Decrement the received packet sequence number
  7720.     lda    n        ; Get the expected sequence number
  7721.     cmp    pnum        ; If it's the same as pnum-1, it is like an ack
  7722.     bne    seofn1        ; It isn't, continue handling the nak
  7723.     jmp    seofa2        ; Switch to an ack but bypass sequence check
  7724. seofa1:
  7725. seofn1: lda    #false        ; Load failure return status
  7726.     rts            ;    and return
  7727. seofca: lda    n        ; Check sequence number expected against
  7728.     cmp    pnum        ;    the number we got.
  7729.     bne    seofa1        ; If not identical, fail and return curr. state
  7730. seofa2: lda    #0        ; Clear the number of tries for current packet
  7731.     sta    numtry        ;        ...
  7732.     jsr    incn        ; Up the packet sequence number
  7733.     jsr    getnfl        ; Call the routine to get the next file
  7734.     cmp    #eof        ; If it didn't find any more
  7735.     beq    seofrb        ;    then return state 'B' ('Send-Eot')
  7736.     jmp    seofrf        ; Otherwise, return 'F' ('Send-file')
  7737. seofrb: lda    #'B        ; Load Eot state code
  7738.     sta    state        ; Store that as the current state
  7739.     lda    #true        ; Give a success on the return
  7740.     rts            ;        ...
  7741. seofrf: lda    #'F        ; Load File-header state code
  7742.     sta    state        ; Make that the current system state
  7743.     lda    #true        ; Make success the return status
  7744.     rts            ;    and return
  7745.  
  7746. sini:    lda    #pdbuf\        ; Load the pointer to the
  7747.     sta    kerbf1        ;    packet buffer into its
  7748.     lda    #pdbuf^        ;    place on page zero
  7749.     sta    kerbf1+1    ;        ...
  7750.     jsr    spar        ; Go fill in the send init parms
  7751.     lda    numtry        ; If numtry > maxtry
  7752.     cmp    maxtry        ;        ...
  7753.     beq    sini1        ;        ...
  7754.     bcs    sini1a        ;    then we are in bad shape, go fail
  7755. sini1:  jmp    sini1b        ; Otherwise, we just continue
  7756. sini1a:    lda    #'A        ; Set state to 'abort'
  7757.     sta    state        ;        ...
  7758.     lda    #errmrc        ; Fetch the error index
  7759.     sta    errcod        ;    and store it as the error code
  7760.     lda    #0        ; Set return status (AC) to fail
  7761.     rts            ; Return
  7762. sini1b: inc    numtry        ; Increment the number of tries for this packet
  7763.     lda    #'S        ; Packet type is 'Send-init'
  7764.     sta    ptype        ; Store that
  7765. ;    lda    ebqmod        ; Do we want 8-bit quoting?
  7766. ;    cmp    #on        ;        ...
  7767. ;    beq    sini1c        ; If so, data length is 7
  7768. ;    lda    #$06        ; Else it is 6
  7769. ;    jmp    sini1d        ;        ...
  7770. sini1c: lda    #7        ; The length of data in a send-init is always 7
  7771. sini1d: sta    pdlen        ; Store that parameter
  7772.     lda    n        ; Get the packet number
  7773.     sta    pnum        ; Store that in its common area
  7774.     jsr    flshin        ;[25] Flush input buffer
  7775.     jsr    spak        ; Call the routine to ship the packet out
  7776.     jsr    rpak        ; Now go try to receive a packet
  7777.     sta    rstat        ; Hold the return status from that last routine
  7778. sinics: lda    ptype        ; Case statement, get the packet type
  7779.     cmp    #'Y        ; Was it an ACK?
  7780.     bne    sinic1        ; If not, try next type
  7781.     jmp    sinicy        ; Go handle the ack
  7782. sinic1: cmp    #'N        ; Was it a NAK?
  7783.     bne    sinic2        ; If not, try next condition
  7784.     jmp    sinicn        ; Handle a nak
  7785. sinic2: lda    rstat        ; Fetch the return status
  7786.     cmp    #false        ; Was this, perhaps false?
  7787.     bne    sinic3        ; Nope, do the 'otherwise' stuff
  7788.     jmp    sinicf        ; Just go and return
  7789. sinic3:    jsr    prcerp        ; Check for error packet and process it
  7790.     lda    #'A        ; Set state to 'abort'
  7791.     sta    state        ;        ...
  7792. sinicn:
  7793. sinicf: rts            ; Return
  7794.  
  7795. sinicy: ldy    #0        ; Clear Y
  7796.     lda    n        ; Get packet number
  7797.     cmp    pnum        ; Was the ack for that packet number?
  7798.     beq    siniy1        ; Yes, continue
  7799.     lda    #false        ; No, set false return status
  7800.     rts            ;    and go back
  7801. siniy1: jsr    rpar        ; Get parms from the ack packet
  7802.     lda    sebq        ; Check if other Kermit agrees to 8-bit quoting
  7803. ;    cmp    #'Y        ;        ...
  7804. ;    beq    siniy2        ; Yes!
  7805. ;    lda    #off        ; Shut it off
  7806. ;    sta    ebqmod        ;        ...
  7807.     cmp    #'N        ;[30]
  7808.     bne    siniy3        ;[30] Yes! Leave it alone
  7809.     lda    #off        ;[30] No .. Shut it off
  7810.     sta    ebqmod        ;[30]        ...
  7811. siniy2:
  7812. siniy3: lda    #'F        ; Load code for 'Send-file' into AC
  7813.     sta    state        ; Make that the new state
  7814.     lda    #0        ; Clear AC
  7815.     sta    numtry        ; Reset numtry to 0 for next send
  7816.     jsr    incn        ; Up the packet sequence number
  7817.     lda    #true        ; Return true
  7818.     rts
  7819.  
  7820. sbrk:    lda    numtry        ; Get the number of tries for this packet
  7821.     inc    numtry        ; Incrment it for next time
  7822.     cmp    maxtry        ; Have we exceeded the maximum
  7823.     beq    sbrk1        ; Not yet
  7824.     bcs    sbrk1a        ; Yes, go abort the whole thing
  7825. sbrk1:  jmp    sbrk1b        ; Continue send
  7826. sbrk1a:    lda    #'A        ; Load 'abort' code
  7827.     sta    state        ; Make that the system state
  7828.     lda    #errmrc        ; Fetch the error index
  7829.     sta    errcod        ;    and store it as the error code
  7830.     lda    #false        ; Load the failure return status
  7831.     rts            ;    and return
  7832. sbrk1b: lda    #'B        ; We are sending an Eot packet
  7833.     sta    ptype        ; Store that as the packet type
  7834.     lda    n        ; Get the current sequence number
  7835.     sta    pnum        ; Copy in that parameter
  7836.     lda    #0        ; The packet data length will be 0
  7837.     sta    pdlen        ; Copy that in
  7838.     jsr    spak        ; Go send the packet
  7839. sbrk2:  jsr    rpak        ; Try to get an ack
  7840.     sta    rstat        ; First, save the return status
  7841.     lda    ptype        ; Get the packet type received
  7842.     cmp    #'N        ; Was it a NAK?
  7843.     bne    sbrk2a        ; If not, try for the ack
  7844.     jmp    sbrkcn        ; Go handle the nak case
  7845. sbrk2a: cmp    #'Y        ; An ACK?
  7846.     bne    sbrk2b        ; If not, look at the return status
  7847.     jmp    sbrkca        ; Go handle the case of an ack
  7848. sbrk2b: lda    rstat        ; Fetch the return status from Rpak
  7849.     cmp    #false        ; Was it a failure?
  7850.     beq    sbrk2c        ; Yes, just return with current state
  7851.     jsr    prcerp        ; Check for error packet and process it
  7852.     lda    #'A        ; No, set up the 'abort' code
  7853.     sta    state        ;    as the system state
  7854.     lda    #false        ;    load the false return status
  7855. sbrk2c: rts            ;    and return
  7856. sbrkcn: dec    pnum        ; Decrement the received packet number once
  7857.     lda    n        ; Get the expected sequence number
  7858.     cmp    pnum        ; If =pnum-1 then this nak is like an ack
  7859.     bne    sbrkn1        ; No, this was no the case
  7860.     jmp    sbrka2        ; Yes! Go do the ack, but skip sequence check
  7861. sbrka1:
  7862. sbrkn1: lda    #false        ; Load failure return code
  7863.     rts            ;    and go back
  7864. sbrkca: lda    n        ; Get the expected packet sequence number
  7865.     cmp    pnum        ; Did we get what we expected?
  7866.     bne    sbrka1        ; No, return failure with current state
  7867. sbrka2: lda    #0        ; Yes, clear number of tries for this packet
  7868.     sta    numtry        ;        ...
  7869.     jsr    incn        ; Up the packet sequence number
  7870.     lda    #'C        ; The transfer is now complete, reflect this
  7871.     sta    state        ;    in the system state
  7872.     lda    #true        ; Return success!
  7873.     rts
  7874.  
  7875. .SBTTL    Setcom routine
  7876.  
  7877. ;
  7878. ;    This routine sets Kermit-65 parameters.
  7879. ;
  7880. ;        Input:  Parameters from command line
  7881. ;
  7882. ;        Output: NONE
  7883. ;
  7884. ;        Registers destroyed:    A,X,Y
  7885. ;
  7886.  
  7887. setcom: lda    #setcmd\    ; Load the address of the keyword table
  7888.     sta    cminf1        ;
  7889.     lda    #setcmd^    ;
  7890.     sta    cminf1+1    ;
  7891.     ldy    #0        ; No special flags needed
  7892.     lda    #cmkey        ; Comnd code for parse keyword
  7893.     jsr    comnd        ; Go get it
  7894.      jmp    kermt2        ; Give an error
  7895. ;---
  7896. ;    lda    #setcmb\    ; Get the address of jump table
  7897. ;    sta    jtaddr        ;
  7898. ;    lda    #setcmb^    ;
  7899. ;    sta    jtaddr+1    ;
  7900. ;    txa            ; Offset to AC
  7901. ;    jmp    jmpind        ;[DD] Jump
  7902. ;---
  7903.     stx    jtaddr        ; x,y has vector
  7904.     sty    jtaddr+1    ; set it
  7905.     jmp    (jtaddr)    ; and go there
  7906. ;
  7907. ;setcmb: jmp    stesc        ; Set escape character
  7908. ;    jmp    stibm        ; Set ibm-mode switch
  7909. ;    jmp    stle        ; Set local-echo switch
  7910. ;    jmp    strc        ; Set receive parameters
  7911. ;    jmp    stsn        ; Set send parameters
  7912. ;    jmp    stvt        ; Set vt52-emulation switch
  7913. ;    jmp    stfw        ; Set file-warning switch
  7914. ;    jmp    steb        ; Set Eight-bit quoting character
  7915. ;    jmp    stdb        ; Set debugging switch
  7916. ;    jmp    stmod        ; Set file-type mode
  7917. ;    jmp    stfbs        ; Set the file-byte-size for transfer
  7918. ;    jmp    stccr        ;[DD] Set rs232 registers 
  7919. ;    jmp    stpari        ; Set the parity for communication
  7920. ;    jmp    stbaud        ;[17] Set the baud rate for communication
  7921. ;    jmp    stwrd        ;[17] Set the word length for communication
  7922. ;    jmp    stflow        ;[24] Set flow control for communication
  7923. ;    jmp    stscre        ;[37] Set the screen size
  7924. ;    jmp    stdef        ; [jrd] set default disk
  7925.  
  7926. stesc:  ldx    #$10        ; Base should be hex
  7927.     ldy    #0        ; No special flags needed
  7928.     lda    #cmnum        ; Parse for integer
  7929.     jsr    comnd        ; Go!
  7930.      jmp    kermt4        ; Number is bad
  7931.     stx    ksavex        ; Hold the number across the next call
  7932.     sty    ksavey        ;        ...
  7933.     lda    #cmcfm        ; Parse for confirm
  7934.     jsr    comnd        ; Do it
  7935.      jmp    kermt3        ; Not confirmed
  7936.     lda    ksavey        ; If this isn't zero
  7937.     cmp    #0        ;    it's not an ASCII character
  7938.     beq    stesc1        ; It is, continue
  7939.     jmp    kermt4        ; Bad number, tell them
  7940. stesc1:    lda    ksavex        ; Get L.O. byte
  7941.     cmp    #$7F        ; It shouldn't be bigger than this
  7942.     bmi    stesc2        ; If it's less, it is ok
  7943.     jmp    kermt4        ; Tell the user it is bad
  7944. stesc2: sta    escp        ; Stuff it
  7945.     jmp    kermit
  7946.  
  7947. stibm:  jsr    prson        ; Try parsing an 'on' or 'off'
  7948.      jmp    kermt2        ; Bad keyword
  7949.     stx    ibmmod        ; Store value in the mode switch location
  7950.     stx    lecho        ; Also set local echo accordingly
  7951.     ldy    #nparit        ; Get ready to set the parity parameter
  7952.     lda    #fbebit        ;[17] Get ready to set the word-size parameter
  7953.     cpx    #on        ; Setting ibm mode on?
  7954.     bne    stibm1        ; Nope so set parity none/word-size eight-bit
  7955.     ldy    #mparit        ; Set mark parity
  7956.     lda    #fbsbit        ;[17] Set up for seven bit word size
  7957.     ldx    #off        ;[38] Turn off flow-control
  7958.     stx    flowmo        ;[38]        ...
  7959. stibm1:    sty    parity        ; Store the value
  7960.     sta    wrdsiz        ;[17]        ...
  7961.     lda    #cmcfm        ;[17] Parse for confirm
  7962.     jsr    comnd        ;[17] Do it
  7963.      jmp    kermt3        ;[17] Not confirmed, tell the user that
  7964.     jsr    dopari        ;[17] Really set the parity
  7965.     jsr    dowrd        ;[17] Really set the word size
  7966.     jmp    kermit        ;
  7967.  
  7968. stle:    jsr    prson        ; Try parsing an 'on' or 'off'
  7969.      jmp    kermt2        ; Bad keyword
  7970.     stx    lecho        ; Store value in the mode switch location
  7971.     lda    #cmcfm        ; Parse for confirm
  7972.     jsr    comnd        ; Do it
  7973.      jmp    kermt3        ; Not confirmed, tell the user that
  7974.     jmp    kermit
  7975.  
  7976. strc:    lda    #0        ; Set srind for receive parms
  7977.     sta    srind        ;        ...
  7978.     lda    #stscmd\    ; Load the address of the keyword table
  7979.     sta    cminf1        ; Save it for the keyword routine
  7980.     lda    #stscmd^    ;
  7981.     sta    cminf1+1    ;
  7982.     ldy    #0        ; No special flags needed
  7983.     lda    #cmkey        ; Comnd code for parse keyword
  7984.     jsr    comnd        ; Go get it
  7985.      jmp    kermt2        ; Give an error
  7986.     lda    #stcct\        ; Get addr. of jump table
  7987.     sta    jtaddr        ;
  7988.     lda    #stcct^        ;        ...
  7989.     sta    jtaddr+1    ;        ...
  7990.     txa            ; Offset to AC
  7991.     jmp    jmpind      ;[DD] Jump
  7992.  
  7993. stsn:    lda    #1        ; Set srind for send parms
  7994.     sta    srind        ;        ...
  7995.     lda    #stscmd\    ; Load the address of the keyword table
  7996.     sta    cminf1        ; Save it for the keyword routine
  7997.     lda    #stscmd^    ;        ...
  7998.     sta    cminf1+1    ;        ...
  7999.     ldy    #0        ; No special flags needed
  8000.     lda    #cmkey        ; Comnd code for parse keyword
  8001.     jsr    comnd        ; Go get it
  8002.      jmp    kermt2        ; Give an error
  8003.     lda    #stcct\        ; Get addr. of jump table
  8004.     sta    jtaddr        ;
  8005.     lda    #stcct^        ;
  8006.     sta    jtaddr+1    ;
  8007.     txa            ; offset to AC
  8008.     jmp    jmpind        ;[DD] Jump
  8009.  
  8010. stcct:  jmp    stpdc        ; Set send/rec padding character
  8011.     jmp    stpad        ; Set amount of padding on send/rec
  8012.     jmp    stebq        ; Set send/rec eight-bit-quoting character    
  8013.     jmp    steol        ; Set send/rec end-of-line
  8014.     jmp    stpl        ; Set send/rec packet length
  8015.     jmp    stqc        ; Set send/rec quote character
  8016.     jmp    sttim        ; Set send/rec timeout
  8017.  
  8018. stvt:    lda    #termemu\    ; parse for terminal emulation type
  8019.     sta    cminf1
  8020.     lda    #termemu^
  8021.     sta    cminf1+1
  8022.     ldy    #0        ; no special flags needed
  8023.     lda    #cmkey        ; parse for a keyword
  8024.     jsr    comnd        ; do it
  8025.      jmp    kermt2        ; go tell the user about the error
  8026.     stx    vtmod        ; Store value in the mode switch location
  8027.     lda    #cmcfm        ; Parse for confirm
  8028.     jsr    comnd        ; Do it
  8029.      jmp    kermt3        ; Not confirmed, tell the user that
  8030.     jmp    kermit
  8031.  
  8032. stfw:    jsr    prson        ; Try parsing an 'on' or 'off'
  8033.      jmp    kermt2        ; Bad keyword
  8034.     stx    filwar        ; Store value in the mode switch location
  8035.     lda    #cmcfm        ; Parse for confirm
  8036.     jsr    comnd        ; Do it
  8037.      jmp    kermt3        ; Not confirmed, tell the user that
  8038.     jmp    kermit
  8039.  
  8040. steb:    jsr    prson        ; Try parsing an 'on' or 'off'
  8041.      jmp    kermt2        ; Bad keyword
  8042.     stx    ebqmod        ; Store value in the mode switch location
  8043.     lda    #cmcfm        ; Parse for confirm
  8044.     jsr    comnd        ; Do it
  8045.      jmp    kermt3        ; Not confirmed, tell the user that
  8046.     jmp    kermit
  8047.  
  8048. stdb:    ldx    #debkey\    ;  Load the address of the keyword table
  8049.     ldy    #debkey^
  8050.     stx    cminf1        ;  Save it for the keyword routine
  8051.     sty    cminf1+1
  8052.     ldy    #0        ; No special flags needed
  8053.     lda    #cmkey        ; Comnd code for parse keyword
  8054.     jsr    comnd        ; Go get it
  8055.      jmp    kermt2        ; Give an error
  8056.     stx    debug        ; Stuff returned value into debug switch
  8057.     lda    #cmcfm        ; Parse for a confirm
  8058.     jsr    comnd        ; Do it
  8059.      jmp    kermt3        ; Not confirmed, tell the user that
  8060.     jmp    kermit
  8061.  
  8062.  
  8063. stebq:  ldx    #$10        ; Base for ASCII value
  8064.     ldy    #0        ; No special flags needed
  8065.     lda    #cmnum        ; Code for integer number
  8066.     jsr    comnd        ; Go do it
  8067.      jmp    kermt4        ; The number was bad
  8068.     tya            ; If this isn't zero
  8069.     cmp    #0        ;    it's not an ASCII character
  8070.     beq    steb1        ; It is, continue
  8071.     jmp    kermt4        ; Bad number, tell them
  8072. steb1:    txa            ; Get L.O. byte
  8073.     cmp    #$7F        ; It shouldn't be bigger than this
  8074.     bmi    steb2        ; If it's less, it is ok
  8075.     jmp    kermt4        ; Tell the user it is bad
  8076. steb2:  cmp    #$21        ; First check the character range
  8077.     bmi    steb4        ; Not in range
  8078.     cmp    #$3f        ;        ...
  8079.     bmi    steb3        ; Inrange
  8080.     cmp    #$60        ;        ...
  8081.     bmi    steb4        ; Not in range
  8082. steb3:  ldx    srind        ; Get index for receive or send parms
  8083.     sta    ebq,x        ; Stuff it
  8084.     lda    #cmcfm        ; Parse for confirm
  8085.     jsr    comnd        ; Do it
  8086.      jmp    kermt3        ; Not confirmed, tell the user that
  8087.     jmp    kermit        ;
  8088. steb4:  ldx    #ermes5\    ; Get error message
  8089.     ldy    #ermes5^    ;        ...
  8090.     jsr    prstr        ; Print the error
  8091.     jsr    prcfm        ; Go parse and print a confirm
  8092.     jmp    kermit        ; Go back
  8093.  
  8094. steol:  ldx    #$10        ; Base for ASCII value
  8095.     ldy    #0        ; No special flags needed
  8096.     lda    #cmnum        ; Code for integer number
  8097.     jsr    comnd        ; Go do it
  8098.      jmp    kermt4        ; The number was bad
  8099.     tya            ; If this isn't zero
  8100.     cmp    #0        ;    it's not an ASCII character
  8101.     beq    steo1        ; It is, continue
  8102.     jmp    kermt4        ; Bad number, tell them
  8103. steo1:    txa            ; Get L.O. byte
  8104.     cmp    #$7F        ; It shouldn't be bigger than this
  8105.     bmi    steo2        ; If it's less, it is ok
  8106.     jmp    kermt4        ; Tell the user it is bad
  8107. steo2:  ldx    srind        ; Fetch index for receive or send parms
  8108.     sta    eol,x        ; Stuff it
  8109.     jsr    prcfm        ; Go parse and print a confirm
  8110.     jmp    kermit        ; Go back
  8111.  
  8112. stpad:
  8113. ;    ldx    #$10        ; Base for ASCII value
  8114.     ldx    #10        ; decimal, please
  8115.     ldy    #0        ; No special flags needed
  8116.     lda    #cmnum        ; Code for integer number
  8117.     jsr    comnd        ; Go do it
  8118.      jmp    kermt4        ; The number was bad
  8119.     tya            ; If this isn't zero
  8120.     cmp    #0        ;    it's not an ASCII character
  8121.     beq    stpd1        ; It is, continue
  8122.     jmp    kermt4        ; Bad number, tell them
  8123. stpd1:    txa            ; Get L.O. byte
  8124.     cmp    #$7F        ; It shouldn't be bigger than this
  8125.     bmi    stpd2        ; If it's less, it is ok
  8126.     jmp    kermt4        ; Tell the user it is bad
  8127. stpd2:  ldx    srind        ; Get index (receive or send)
  8128.     sta    pad,x        ; Stuff it
  8129.     jsr    prcfm        ; Go parse and print a confirm
  8130.     jmp    kermit        ; Go back
  8131.  
  8132. stpdc:  ldx    #$10        ; Base for ASCII value
  8133.     ldy    #0        ; No special flags needed
  8134.     lda    #cmnum        ; Code for integer number
  8135.     jsr    comnd        ; Go do it
  8136.      jmp    kermt4        ; The number was bad
  8137.     tya            ; If this isn't zero
  8138.     cmp    #0        ;    it's not an ASCII character
  8139.     beq    stpc1        ; It is, continue
  8140.     jmp    kermt4        ; Bad number, tell them
  8141. stpc1:    txa            ; Get L.O. byte
  8142.     cmp    #$7F        ; It shouldn't be bigger than this
  8143.     bmi    stpc2        ; If it's less, it is ok
  8144.     jmp    kermt4        ; Tell the user it is bad
  8145. stpc2:  ldx    srind        ; Get index for parms
  8146.     sta    padch,x        ; Stuff it
  8147.     jsr    prcfm        ; Go parse and print a confirm
  8148.     jmp    kermit        ; Go back
  8149.  
  8150. stpl:
  8151. ;    ldx    #$10        ; Base for ASCII value
  8152.     ldx    #10        ; decimal, please
  8153.     ldy    #0        ; No special flags needed
  8154.     lda    #cmnum        ; Code for integer number
  8155.     jsr    comnd        ; Go do it
  8156.      jmp    kermt4        ; The number was bad
  8157.     tya            ; If this isn't zero
  8158.     cmp    #0        ;    it's not an ASCII character
  8159.     beq    stpl1        ; It is, continue
  8160.     jmp    kermt4        ; Bad number, tell them
  8161. stpl1:    txa            ; Get L.O. byte
  8162.     cmp    #mxpack        ; It shouldn't be bigger than this
  8163.     bmi    stpl2        ; If it's less, it is ok
  8164.     jmp    kermt4        ; Tell the user it is bad
  8165. stpl2:  ldx    srind        ; Get index
  8166.     sta    psiz,x        ; Stuff it
  8167.     jsr    prcfm        ; Go parse and print a confirm
  8168.     jmp    kermit        ; Go back
  8169.  
  8170. stqc:    ldx    #$10        ; Base for ASCII value
  8171.     ldy    #0        ; No special flags needed
  8172.     lda    #cmnum        ; Code for integer number
  8173.     jsr    comnd        ; Go do it
  8174.      jmp    kermt4        ; The number was bad
  8175.     tya            ; If this isn't zero
  8176.     cmp    #0        ;    it's not an ASCII character
  8177.     beq    stqc1        ; It is, continue
  8178.     jmp    kermt4        ; Bad number, tell them
  8179. stqc1:    txa            ; Get L.O. byte
  8180.     cmp    #$7F        ; It shouldn't be bigger than this
  8181.     bmi    stqc2        ; If it's less, it is ok
  8182.     jmp    kermt4        ; Tell the user it is bad
  8183. stqc2:  ldx    srind        ; Fetch index for receive or send parms
  8184.     sta    quote,x        ; Stuff it
  8185.     jsr    prcfm        ; Go parse and print a confirm
  8186.     jmp    kermit        ; Go back
  8187.  
  8188. sttim:
  8189. ;    ldx    #$10        ; Base for ASCII value
  8190.     ldx    #10        ; decimal, please
  8191.     ldy    #0        ; No special flags needed
  8192.     lda    #cmnum        ; Code for integer number
  8193.     jsr    comnd        ; Go do it
  8194.      jmp    kermt4        ; The number was bad
  8195.     tya            ; If this isn't zero
  8196.     cmp    #0        ;    it's not an ASCII character
  8197.     beq    sttm1        ; It is, continue
  8198.     jmp    kermt4        ; Bad number, tell them
  8199. sttm1:    txa            ; Get L.O. byte
  8200.     cmp    #$7F        ; It shouldn't be bigger than this
  8201.     bmi    sttm2        ; If it's less, it is ok
  8202.     jmp    kermt4        ; Tell the user it is bad
  8203. sttm2:  ldx    srind        ; Fetch index for receive or send parms
  8204.     sta    time,x        ; Stuff it
  8205.     jsr    prcfm        ; Go parse and print a confirm
  8206.     jmp    kermit        ; Go back
  8207.  
  8208. stmod:    lda    #ftcmd\        ; Load the address of the keyword table
  8209.     sta    cminf1        ;
  8210.     lda    #ftcmd^        ;
  8211.     sta    cminf1+1    ;
  8212.     lda    #ftcdef\    ; Load default address
  8213.     sta    cmdptr        ;        ...
  8214.     lda    #ftcdef^    ;        ...
  8215.     sta    cmdptr+1    ;        ...
  8216.     ldy    #cmfdff        ; Tell Comnd there is a default
  8217.     lda    #cmkey        ; Comnd code for parse keyword
  8218.     jsr    comnd        ; Go get it
  8219.      jmp    kermt2        ; Give an error
  8220.     stx    filmod        ; Save the file-type mode
  8221.     lda    #cmcfm        ; Parse for a confirm
  8222.     jsr    comnd        ; Do it
  8223.      jmp    kermt3        ; Not confirmed, tell the user that
  8224.     jmp    kermit
  8225.  
  8226. ;stfbs:    lda    #fbskey\    ; Load the address of the keyword table
  8227. ;    sta    cminf1        ;
  8228. ;    lda    #fbskey^    ;
  8229. ;    sta    cminf1+1    ;
  8230. ;    ldy    #0        ; No special flags needed
  8231. ;    lda    #cmkey        ; Comnd code for parse keyword
  8232. ;    jsr    comnd        ; Go get it
  8233. ;     jmp    kermt2        ; Give an error
  8234. ;    stx    fbsize        ; Stuff the returned value into file-byte-size
  8235. ;    lda    #cmcfm        ; Parse for a confirm
  8236. ;    jsr    comnd        ; Do it
  8237. ;     jmp    kermt3        ; Not confirmed, tell the user that
  8238. ;    jmp    kermit
  8239.  
  8240.  
  8241. stccr:  ldx    #$10        ;[DD] Base should be hex
  8242.     ldy    #0        ; No special flags needed
  8243.     lda    #cmnum        ;[DD] Parse for integer
  8244.     jsr    comnd        ;[DD] Go do it
  8245.      jmp    kermt4        ;[DD] The number was bad
  8246. stccr1:    stx    ksavex        ; Store it while we confirm
  8247.     sty    ksavey        ;        ...
  8248.     lda    #cmcfm        ; Set up to parse confirm
  8249.     jsr    comnd        ; Do it
  8250.      jmp    kermt3        ; Wasn't properly confirmed
  8251.     lda    ksavex        ; Fetch back L.O. byte
  8252.     sta    x36ax1        ;[DD][EL] To rs232 reg 0
  8253.     lda    ksavey        ;[18] Fetch back H.O. byte
  8254.     sta    x38ax1        ;[DD] To rs232 reg 1
  8255.     jmp    kermit        ;[DD] 
  8256.  
  8257. stpari:    lda    #parkey\    ; Load the address of the keyword table
  8258.     sta    cminf1        ; Save it for the keyword routine
  8259.     lda    #parkey^    ;        ...
  8260.     sta    cminf1+1    ;        ...
  8261.     ldy    #0        ; No special flags needed
  8262.     lda    #cmkey        ; Comnd code for parse keyword
  8263.     jsr    comnd        ; Go get it
  8264.      jmp    kermt2        ; Give an error
  8265.     stx    parity        ; Stuff returned value into parity
  8266.     lda    #cmcfm        ; Parse for a confirm
  8267.     jsr    comnd        ; Do it
  8268.      jmp    kermt3        ; Not confirmed, tell the user that
  8269.     jsr    dopari        ;[17] Now really set the parity
  8270.     jmp    kermit        ;
  8271.  
  8272. dopari:    lda    x38ax1        ;[17] Get the command register
  8273.     and    #$C0        ;[17] mask out in+out parity
  8274.     sta    x38ax1        ;[17] Store it back
  8275.     ldx    parity        ;[17] Get the index
  8276.     lda    parval,x    ;[17]    and the parity value from the table
  8277.     ora    x38ax1        ;[17]
  8278.     sta    x38ax1        ;[17] Store it back
  8279.     rts            ;[17] Return
  8280.  
  8281. stbaud:    lda    #bdkey\        ;[17] Load the address of the keyword table
  8282.     sta    cminf1        ;[17] Save it for the keyword routine
  8283.     lda    #bdkey^        ;[17]        ...
  8284.     sta    cminf1+1    ;[17]        ...
  8285.     ldy    #0        ;[17] No special flags needed
  8286.     lda    #cmkey        ;[17] Parse for a keyword
  8287.     jsr    comnd        ;[17] Do it
  8288.      jmp    kermt2        ;[17] Give an error
  8289.     stx    baud        ;[17] Stuff the returned value
  8290.     lda    #cmcfm        ;[17] Set up for a confirm
  8291.     jsr    comnd        ;[17] Do it
  8292.      jmp    kermt3        ;[17] Not confirmed
  8293.     jsr    dobad        ;[17] Really set the baud rate
  8294.     jmp    kermit        ;[17] 
  8295.  
  8296. dobad:    lda    x36ax1        ;[17] Get the control register
  8297.     and    #$F0        ;[17] Clear it
  8298.     sta    x36ax1        ;[17] Store it back
  8299.     ldx    baud        ;[17] Get the baud rate back
  8300.     lda    bdval,x        ;[17] Get the value from the table
  8301.     ora    x36ax1        ;[17] Set the baud rate
  8302.     sta    x36ax1        ;[17]  and store it
  8303.     rts            ;[17]
  8304.  
  8305. stwrd:    lda    #fbskey\    ;[17] Load the address of the keyword table
  8306.     sta    cminf1        ;[17] Save it for the keyword routine
  8307.     lda    #fbskey^    ;[17]        ...
  8308.     sta    cminf1+1    ;[17]        ...
  8309.     ldy    #0        ;[17] No special flags needed
  8310.     lda    #cmkey        ;[17] Comnd code for parse keyword
  8311.     jsr    comnd        ;[17] Go get it
  8312.      jmp    kermt2        ;[17] Give an error
  8313.     stx    wrdsiz        ;[17] Stuff the returned value into wrd len
  8314.     lda    #cmcfm        ;[17] Parse for a confirm
  8315.     jsr    comnd        ;[17] Do it
  8316.      jmp    kermt3        ;[17] Not confirmed, tell the user that
  8317.     jsr    dowrd        ;[17] Really set the word size
  8318.     jmp    kermit        ;[17]        ...
  8319.  
  8320. dowrd:    lda    x36ax1        ;[17] Get the control register
  8321.     and    #$8F        ;[17] mask for word size
  8322.     sta    x36ax1        ;[17] Store it back
  8323.     lda    wrdsiz        ;[17] Get the word size
  8324.     cmp    #fbsbit        ;[17] Is it seven-bit ?
  8325.     bne    dwrd1        ;[17] No, we have the value for eight-bit
  8326.                 ; NB, this depends on fbebit = 0
  8327.     lda    #$10        ;[17] Yes, get value for seven-bit word size
  8328. dwrd1:    ora    x36ax1        ;[17] Set it
  8329.     sta    x36ax1        ;[17] Store it
  8330.     rts            ;[17] Return
  8331.  
  8332. stflow: jsr    prson        ;[24] Try parsing an 'on' or 'off'
  8333.      jmp    kermt2        ;[24] Bad keyword
  8334.     stx    flowmo        ;[24] Store it
  8335.     lda    #cmcfm        ;[24] Parse for confirm
  8336.     jsr    comnd        ;[24] Do it
  8337.      jmp    kermt3        ;[24] Not confirmed, tell the user that
  8338.     jmp    kermit        ;[24]
  8339.  
  8340. stscre:    lda    #scrkey\    ;[37] Get the address of the screen mode table
  8341.     sta    cminf1        ;[37]        ...
  8342.     lda    #scrkey^    ;[37]        ...
  8343.     sta    cminf1+1    ;[37]        ...
  8344.     ldy    #0        ;[37] No special flags needed
  8345.     lda    #cmkey        ;[37] Comnd code for parse keyword
  8346.     jsr    comnd        ;[37] Go get it
  8347.      jmp    kermt2        ;[37] Give an error
  8348.     stx    kwrk01        ;[37] Stuff the returned value into kwrk01
  8349.     lda    #cmcfm        ;[37] Parse for a confirm
  8350.     jsr    comnd        ;[37] Do it
  8351.      jmp    kermt3        ;[37] Not confirmed, tell the user that
  8352.     lda    kwrk01        ;[37] Are we switching to 80 columns?
  8353. ;
  8354. ;get:
  8355. ;    pha            ; save the id of the screen driver we want
  8356. ;    jsr    scrext        ; exit the old screen driver
  8357. ;    pla
  8358. ; [jrd] no need to test, they're all here
  8359. ;    pha            ; keep the id of the screen driver on the stack
  8360. ;    jsr    scrtst        ; does this screen driver exist?
  8361. ;    pla            ; restore desired screen type
  8362. ;    bcc    get1
  8363. ;    lda    #1        ; if it does not exist, use 80-columns instead
  8364. ;get1:
  8365.     sta    conscrt        ; [jrd] use the slot that connect code uses
  8366. ;    jsr    scrent        ; enter the screen driver
  8367.     jmp    kermit        ; all done
  8368.  
  8369. ;
  8370. ; Set default disk
  8371. ;
  8372. stdef:  ldx    #$10        ; Base should be hex
  8373.     ldy    #0        ; No special flags needed
  8374.     lda    #cmnum        ; Parse for integer
  8375.     jsr    comnd        ; Go!
  8376.      jmp    kermt4        ; Number is bad
  8377.     stx    ksavex        ; save it for a bit
  8378.     sty    ksavey
  8379.     lda    #cmcfm        ; Set up to parse confirm
  8380.     jsr    comnd        ; Do it
  8381.      jmp    kermt3        ; Wasn't properly confirmed
  8382.     lda    ksavex        ; value back in A
  8383.     beq    stdefng        ; zero's no good
  8384.     bmi    stdefng        ; neg either
  8385.     cmp    #9        ; [jrd v3.7] between 1 and 8?
  8386.     bcs    stdefng        ; nope, lose
  8387.     adc    #$30        ; make into ascii; carry's clear
  8388.     sta    dsknum        ; stuff into the relevant place
  8389.     jmp    kermit        ; done!
  8390. stdefng: jmp    kermt4        ; error return    
  8391.  
  8392. .SBTTL    Show routine
  8393.  
  8394. ;
  8395. ;    This routine shows any of the operational parameters that
  8396. ;    can be altered with the set command.
  8397. ;
  8398. ;        Input:  Parameters from command line
  8399. ;
  8400. ;        Output: Display parameter values on screen
  8401. ;
  8402. ;        Registers destroyed:    A,X,Y
  8403. ;
  8404.  
  8405. show:    lda    #shocmd\    ; Load address of keyword table
  8406.     sta    cminf1        ;
  8407.     lda    #shocmd^    ;
  8408.     sta    cminf1+1    ;
  8409.     lda    #shodef\    ; Fetch default address
  8410.     sta    cmdptr        ;        ...
  8411.     lda    #shodef^    ;        ...
  8412.     sta    cmdptr+1    ;        ...
  8413.     ldy    #cmfdff        ; Indicate that there is a default
  8414.     lda    #cmkey        ; Comnd code to parse keyword
  8415.     jsr    comnd        ; Go parse the keyword
  8416.      jmp    kermt2        ; Bad keyword, go give an error
  8417. ;---
  8418. ;    lda    #shocmb\     ; Get addr. of jump table
  8419. ;    sta    jtaddr        ;
  8420. ;    lda    #shocmb^    ;
  8421. ;    sta    jtaddr+1    ;
  8422. ;    txa            ; Offset to AC
  8423. ;    jmp    jmpind        ;[DD] Jump
  8424. ;---
  8425.     stx    jtaddr        ; x,y has vector
  8426.     sty    jtaddr+1    ; set it
  8427. ;
  8428. ;the routines here are set up to be jsr-ed to, so we'll do it that way
  8429. ;rather than just jumping.  We'll jsr, the routine'll return, and we'll
  8430. ;continue execution after our jsr
  8431. ;
  8432.     jsr    show1        ; jsr to the dispatcher
  8433.     jmp    kermit        ; done!
  8434.  
  8435. show1:    jmp    (jtaddr)    ; go there.  He'll return
  8436.                 ; to our caller.
  8437. ;
  8438. ;shocmb: jsr    prcfm        ; Parse for confirm
  8439. ;    jsr    shall        ; Show all setable parameters
  8440. ;    jmp    kermit        ; Go to top of main loop
  8441. ;    jsr    prcfm        ; Parse for confirm
  8442. ;    jsr    shesc        ; Show escape character
  8443. ;    jmp    kermit        ; Go to top of main loop
  8444. ;    jsr    prcfm        ; Parse for confirm
  8445. ;    jsr    shibm        ; Show ibm-mode switch
  8446. ;    jmp    kermit        ; Go to top of main loop
  8447. ;    jsr    prcfm        ; Parse for confirm
  8448. ;    jsr    shle        ; Show local-echo switch
  8449. ;    jmp    kermit        ; Go to top of main loop
  8450. ;    nop            ; We should not parse for confirm
  8451. ;    nop            ;    since this routine parses for
  8452. ;    nop            ;    a keyword next
  8453. ;    jsr    shrc        ; Show receive parameters
  8454. ;    jmp    kermit        ; Go to top of main loop
  8455. ;    nop            ; We should not parse for confirm
  8456. ;    nop            ;    since this routine parses for
  8457. ;    nop            ;    a keyword next
  8458. ;    jsr    shsn        ; Show send parameters
  8459. ;    jmp    kermit        ; Go to top of main loop
  8460. ;    jsr    prcfm        ; Parse for confirm
  8461. ;    jsr    shvt        ; Show vt52-emulation mode switch
  8462. ;    jmp    kermit        ; Go to top of main loop
  8463. ;    jsr    prcfm        ; Parse for confirm
  8464. ;    jsr    shfw        ; Show file-warning switch
  8465. ;    jmp    kermit        ; Go to top of main loop
  8466. ;    jsr    prcfm        ; Parse for confirm
  8467. ;    jsr    sheb        ; Show eight-bit-quoting switch
  8468. ;    jmp    kermit        ; Go to top of main loop
  8469. ;    jsr    prcfm        ; Parse for confirm
  8470. ;    jsr    shdb        ; Show debugging mode switch
  8471. ;    jmp    kermit        ; Go to top of main loop
  8472. ;    jsr    prcfm        ; Parse for confirm
  8473. ;    jsr    shmod        ; Show File mode
  8474. ;    jmp    kermit        ; Go to top of main loop
  8475. ;    jsr    prcfm        ; Parse for confirm
  8476. ;    jsr    shfbs        ; Show the file-byte-size
  8477. ;    jmp    kermit        ; Go to top of main loop
  8478. ;    jsr    prcfm        ;[DD] Parse for confirm 
  8479. ;    jsr    shccr        ;[DD] Show rs232 regs.
  8480. ;    jmp    kermit        ;[DD] Go to top of main loop
  8481. ;    jsr    prcfm        ; Parse for confirm
  8482. ;    jsr    shpari        ; Show Parity
  8483. ;    jmp    kermit        ; Go to top of main loop
  8484. ;    jsr    prcfm        ;[17] Parse for a confirm
  8485. ;    jsr    shbad        ;[17] Show baud
  8486. ;    jmp    kermit        ;[17] Go to top of main loop
  8487. ;    jsr    prcfm        ;[17] Parse for a confirm
  8488. ;    jsr    shwrd        ;[17] Show word size
  8489. ;    jmp    kermit        ;[17] Go to top of main loop
  8490. ;    jsr    prcfm        ;[24] Parse for a confirm
  8491. ;    jsr    shflow        ;[24] Show flow-control
  8492. ;    jmp    kermit        ;[24] Go to top of main loop
  8493. ;
  8494. ; sho def.  Surely there's a better way to do this?
  8495. ;
  8496. ;    jsr    prcfm        ;[24] Parse for a confirm
  8497. ;    jsr    shdef        ;[24] show def
  8498. ;    jmp    kermit        ;[24] Go to top of main loop
  8499.  
  8500. ;
  8501. ; this is sort of a kludge.  Many of the things this calls
  8502. ; need to be callable separately; in the latter case they 
  8503. ; want to get a confirm, in this case, they don't as it's
  8504. ; done once for all of them.  For those cases, we call the
  8505. ; regular entry point + 3, skipping the call to prcfm.  Sigh.
  8506. ;
  8507. shall:
  8508.     jsr    prcfm        ; make sure confirmed
  8509.     jsr    shdb+3        ; Show debugging mode switch
  8510.     jsr    shvt+3        ; Show vt52-emulation mode switch
  8511.     jsr    shibm+3        ; Show ibm-mode switch
  8512.     jsr    shle+3        ; Show local-echo switch
  8513.     jsr    shbad+3        ;[17] Show baud rate
  8514.     jsr    shpari+3        ; Show parity setting
  8515.     jsr    shwrd+3        ;[17] Show word length
  8516.     jsr    shflow+3        ;[24] Show flow-control
  8517.     jsr    sheb+3        ; Show eight-bit-quoting switch
  8518.     jsr    shfw+3        ; Show file-warning switch
  8519.     jsr    shesc+3        ; Show the current escape character
  8520.     jsr    shmod+3        ; Show the file-type mode
  8521. ;    jsr    shfbs+3        ; Show the file-byte-size
  8522.     jsr    shdef+3        ; [jrd] show default drive
  8523.     jsr    shccr+3        ;[DD] Show rs232 regs.
  8524. ;
  8525. ; these last two don't needed the +3; they're only used here
  8526. ;
  8527.     jsr    shrcal        ; Show receive parameters
  8528.     jsr    shsnal        ; Show send parameters
  8529.     rts            ; Return
  8530.  
  8531. shdb:    jsr    prcfm        ; make sure confirmed
  8532.     ldx    #shin00\    ; Get address of message for this item
  8533.     ldy    #shin00^
  8534.     jsr    prstr        ; Print that message
  8535.     lda    debug        ; Get the switch value
  8536.     cmp    #3        ; Is it >= 3?
  8537.     bmi    shdb1        ; If not just get the string and print it
  8538.     lda    #0        ; This is index for debug mode we want
  8539. shdb1:    tax            ; Hold this index
  8540.     lda    #kerdms\    ; Get the address of the debug strings
  8541.     sta    kermbs        ; And stuff it here for genmad
  8542.     lda    #kerdms^    ;        ...
  8543.     sta    kermbs+1    ;        ...
  8544.     lda    #kerdsz        ; Get the string length
  8545.     pha            ; Push that
  8546.     txa            ; Fetch the index back
  8547.     pha            ; Push that parm then
  8548.     jsr    genmad        ;    call genmad
  8549.     jsr    prstr        ; Print the the string at that address
  8550.     jsr    prcrlf        ; Print a crelf after it
  8551.     rts
  8552.  
  8553. shvt:    jsr    prcfm        ; make sure confirmed
  8554.     ldx    #shin01\    ; Get address of message for this item
  8555.     ldy    #shin01^
  8556.     jsr    prstr        ; Print that message
  8557.     lda    #kertms\    ; get address of messages for this item
  8558.     sta    kermbs
  8559.     lda    #kertms^
  8560.     sta    kermbs+1
  8561.     lda    #keremu        ; length of the messages
  8562.     pha
  8563.     lda    vtmod        ; which message
  8564.     pha
  8565.     jsr    genmad        ; calculate address of selected message
  8566.     jsr    prstr        ; print selected message
  8567.     jsr    prcrlf        ; and a carriage return / line feed
  8568.     rts            ; all done
  8569.  
  8570. shibm:    jsr    prcfm        ; make sure confirmed
  8571.     ldx    #shin02\    ; Get address of message for this item
  8572.     ldy    #shin02^
  8573.     jsr    prstr        ; Print that message
  8574.     lda    ibmmod        ; Get the switch value
  8575.     jmp    pron        ; Go print the 'on' or 'off' string
  8576.  
  8577. shle:    jsr    prcfm        ; make sure confirmed
  8578.     ldx    #shin03\    ; Get address of message for this item
  8579.     ldy    #shin03^
  8580.     jsr    prstr        ; Print that message
  8581.     lda    lecho        ; Get the switch value
  8582.     jmp    pron        ; Go print the 'on' or 'off' string
  8583.  
  8584. sheb:    jsr    prcfm        ; make sure confirmed
  8585.     ldx    #shin04\    ; Get address of message for this item
  8586.     ldy    #shin04^
  8587.     jsr    prstr        ; Print that message
  8588.     lda    ebqmod        ; Get the switch value
  8589.     jmp    pron        ; Go print the 'on' or 'off' string
  8590.  
  8591. shfw:    jsr    prcfm        ; make sure confirmed
  8592.     ldx    #shin05\    ; Get address of message for this item
  8593.     ldy    #shin05^
  8594.     jsr    prstr        ; Print that message
  8595.     lda    filwar        ; Get the switch value
  8596.     jmp    pron        ; Go print the 'on' or 'off' string
  8597.  
  8598. shesc:    jsr    prcfm        ; make sure confirmed
  8599.     ldx    #shin06\    ; Get address of message
  8600.     ldy    #shin06^
  8601.     jsr    prstr        ; Print message
  8602.     lda    escp        ; Get the escape character
  8603.     jsr    prchr        ; Print the special character
  8604.     jsr    prcrlf        ; Print a crelf
  8605.     rts            ;    and return
  8606.  
  8607. shccr:    jsr    prcfm        ; make sure confirmed
  8608.     ldx    #shin18\    ;[DD][EL] Print rs232 registers x36ax1,x38ax1 
  8609.     ldy    #shin18^    ;[DD]
  8610.     jsr    prstr        ;[DD]
  8611.     lda    x38ax1        ;[DD] Print rs232 reg 1
  8612.     jsr    prbyte        ;[DD]
  8613.     lda    x36ax1        ;[DD] Print rs232 reg 0
  8614.     jsr    prbyte        ;[DD]
  8615.     jsr    prcrlf        ;[DD]    and a crlf
  8616.     rts            ;[DD]
  8617.  
  8618.  
  8619. shsn:    lda    #1        ; Set up index to be used later
  8620.     sta    srind
  8621.     lda    #stscmd\    ; Get the set option table address
  8622.     sta    cminf1        ;
  8623.     lda    #stscmd^    ;
  8624.     sta    cminf1+1    ;
  8625.     ldy    #0        ; No special flags needed
  8626.     lda    #cmkey        ; Code for keyword parse
  8627.     jsr    comnd        ; Try to parse it
  8628.      jmp    kermt2        ; Invalid keyword
  8629.     stx    kwrk01        ; Hold offset into jump table
  8630.     jsr    prcfm        ; Parse and print a confirm
  8631.     lda    #shcmb\      ; Get addr. of jump table
  8632.     sta    jtaddr        ;
  8633.     lda    #shcmb^        ;
  8634.     sta    jtaddr+1    ;
  8635.     lda    kwrk01        ; Get offset  back
  8636.     asl    a        ; Double it
  8637.     jmp    jmpind      ;[DD] Jump
  8638. ;
  8639. shrc:    lda    #0        ; Set up index to be used later
  8640.     sta    srind
  8641.     lda    #stscmd\    ; Get the set option table address
  8642.     sta    cminf1        ;
  8643.     lda    #stscmd^    ;
  8644.     sta    cminf1+1    ;
  8645.     ldy    #0        ; No special flags needed
  8646.     lda    #cmkey        ; Code for keyword parse
  8647.     jsr    comnd        ; Try to parse it
  8648.      jmp    kermt2        ; Invalid keyword
  8649.     stx    kwrk01        ; Hold offset into jump table
  8650.     jsr    prcfm        ; Parse and print a confirm
  8651.     lda    #shcmb\        ; Get addr. ofl jump table
  8652.     sta    jtaddr        ;
  8653.     lda    #shcmb^        ;
  8654.     sta    jtaddr+1    ;
  8655.     lda    kwrk01        ; Get offset  back
  8656.     asl    a        ; Double it
  8657.     jmp    jmpind        ;[DD] Jump
  8658.  
  8659. shcmb:  jsr    shpdc        ; Show send/rec padding character
  8660.     jmp    kermit        ; Go back
  8661.     jsr    shpad        ; Show amount of padding for send/rec
  8662.     jmp    kermit        ; Go back
  8663.     jsr    shebq        ; Show send/rec eight-bit-quoting character
  8664.     jmp    kermit        ; Go back
  8665.     jsr    sheol        ; Show send/rec end-of-line character
  8666.     jmp    kermit        ; Go back
  8667.     jsr    shpl        ; Show send/rec packet length
  8668.     jmp    kermit        ; Go back
  8669.     jsr    shqc        ; Show send/rec quote character
  8670.     jmp    kermit        ; Go back
  8671.     jsr    shtim        ; Show send/rec timeout
  8672.     jmp    kermit        ; Go back
  8673.  
  8674. shpdc:  ldx    #shin11\    ; Get address of 'pad char' string
  8675.     ldy    #shin11^
  8676.     jsr    prstr        ; Print that
  8677.     ldx    srind        ; Load index so we print correct parm
  8678.     lda    padch,x        ; If index is 1, this gets spadch
  8679.     jsr    prchr        ; Print the special character
  8680.     jsr    prcrlf        ; Print a crelf after it
  8681.     rts
  8682. shpad:  ldx    #shin12\    ; Get address of 'padding amount' string
  8683.     ldy    #shin12^
  8684.     jsr    prstr        ; Print that
  8685.     ldx    srind        ; Load index so we print correct parm
  8686.     lda    pad,x        ; If index is 1, this gets spad
  8687. ;    jsr    prbyte        ; Print the amount of padding
  8688.     tax            ; lo half
  8689.     lda    #0
  8690. ;    jsr    prntad        ; print it in decimal, please
  8691. ;    jsr    prcrlf        ; Print a crelf after it
  8692.     jsr    prntadnl    ; use combined rtn
  8693.     rts
  8694. shebq:  ldx    #shin08\    ; Get address of 'eight-bit-quote' string
  8695.     ldy    #shin08^
  8696.     jsr    prstr        ; Print that
  8697.     ldx    srind        ; Load index so we print correct parm
  8698.     lda    ebq,x        ; If index is 1, this gets sebq
  8699.     jsr    prchr        ; Print the special character
  8700.     jsr    prcrlf        ; Print a crelf after it
  8701.     rts
  8702. sheol:  ldx    #shin09\    ; Get address of 'end-of-line' string
  8703.     ldy    #shin09^
  8704.     jsr    prstr        ; Print that
  8705.     ldx    srind        ; Load index so we print correct parm
  8706.     lda    eol,x        ; If index is 1, this gets seol
  8707.     jsr    prchr        ; Print the special character
  8708.     jsr    prcrlf        ; Print a crelf after it
  8709.     rts
  8710. shpl:    ldx    #shin10\    ; Get address of 'packet length' string
  8711.     ldy    #shin10^
  8712.     jsr    prstr        ; Print that
  8713.     ldx    srind        ; Load index so we print correct parm
  8714.     lda    psiz,x        ; If index is 1, this gets spsiz
  8715. ;    jsr    prbyte        ; Print the packet length
  8716.     tax
  8717.     lda    #0
  8718. ;    jsr    prntad        ; print in decimal please
  8719. ;    jsr    prcrlf        ; Print a crelf after it
  8720.     jsr    prntadnl    ; use combined rtn
  8721.     rts            ;    and return
  8722. shqc:    ldx    #shin13\    ; Get address of 'quote-char' string
  8723.     ldy    #shin13^
  8724.     jsr    prstr        ; Print that
  8725.     ldx    srind        ; Load index so we print correct parm
  8726.     lda    quote,x        ; If index is 1, this gets squote
  8727.     jsr    prchr        ; Print the special character
  8728.     jsr    prcrlf        ; Print a crelf after it
  8729.     rts
  8730. shtim:  ldx    #shin14\    ; Get address of 'timeout' string
  8731.     ldy    #shin14^
  8732.     jsr    prstr        ; Print that
  8733.     ldx    srind        ; Load index so we print correct parm
  8734.     lda    time,x        ; If index is 1, this gets stime
  8735. ;---
  8736. ;    jsr    prbyte        ; Print the hex value
  8737.     tax            ; get it into x
  8738.     lda    #0
  8739. ;    jsr    prntad
  8740. ;---
  8741. ;    jsr    prcrlf        ; Print a crelf after it
  8742.     jsr    prntadnl    ; use combined rtn
  8743.     rts
  8744.  
  8745. shsnal: lda    #1        ; Set up index for show parms
  8746.     sta    srind        ;    and stuff it here
  8747.     ldx    #shin07\    ; Get address of 'send' string
  8748.     ldy    #shin07^    ;
  8749.     jsr    prstr        ; Print it
  8750.     jsr    prcrlf        ; Print a crelf
  8751.     jsr    shpdc        ; Show the padding character
  8752.     jsr    shpad        ; Show amount of padding
  8753.     jsr    shebq        ; Show eight-bit-quote character
  8754.     jsr    sheol        ; Show end-of-line character
  8755.     jsr    shpl        ; Show packet-length
  8756.     jsr    shqc        ; Show quote character
  8757.     jsr    shtim        ; Show timeout length
  8758.     rts
  8759.  
  8760. shrcal: lda    #0        ; Set up index for show parms
  8761.     sta    srind        ;    and stuff it here
  8762.     ldx    #shin15\    ; Get address of 'receive' string
  8763.     ldy    #shin15^
  8764.     jsr    prstr        ; Print it
  8765.     jsr    prcrlf        ; Print a crelf
  8766.     jsr    shpdc        ; Show the padding character
  8767.     jsr    shpad        ; Show amount of padding
  8768.     jsr    shebq        ; Show eight-bit-quote character
  8769.     jsr    sheol        ; Show end-of-line character
  8770.     jsr    shpl        ; Show packet-length
  8771.     jsr    shqc        ; Show quote character
  8772.     jsr    shtim        ; Show timeout length
  8773.     rts
  8774.  
  8775. shmod:    jsr    prcfm        ; make sure confirmed
  8776.     ldx    #shin16\    ; Get address of 'timeout' string
  8777.     ldy    #shin16^
  8778.     jsr    prstr        ; Print that
  8779.     lda    filmod        ; Get the file-type mode
  8780. ;    cmp    #4        ; Is it >= 4?
  8781.     cmp    #ftbin+1    ; Is it >= 3? [jrd] no Script
  8782.     bmi    shmod1        ; If not just get the string and print it
  8783.     lda    #ftatas        ; [jrd] This is the index to the file-type we want
  8784. shmod1: tax            ; Hold this index
  8785.     lda    #kerftp\    ; Get the address if the file type strings
  8786.     sta    kermbs        ;
  8787.     lda    #kerftp^    ;
  8788.     sta    kermbs+1    ;
  8789.     lda    #kerfts        ; Get the string length
  8790.     pha            ; Push that
  8791.     txa            ; Fetch the index back
  8792.     pha            ; Push that parm then
  8793.     jsr    genmad        ;    call genmad
  8794.     jsr    prstr        ; Print the the string at that address
  8795.     jsr    prcrlf        ; Print a crelf after it
  8796.     rts
  8797.  
  8798. ;shfbs:    jsr    prcfm        ; make sure confirmed
  8799. ;    ldx    #shin17\    ; Get address of 'file-byte-size' string
  8800. ;    ldy    #shin17^
  8801. ;    jsr    prstr        ; Print that
  8802. ;    lda    fbsize        ; Get the file-type mode
  8803. ;    beq    shfbse        ; It is in eight-bit mode
  8804. ;    ldx    #shsbit\    ; Get address of 'SEVEN-BIT' string
  8805. ;    ldy    #shsbit^    ;
  8806. ;    jsr    prstr        ; Print that
  8807. ;    jsr    prcrlf        ;    then a crelf
  8808. ;    rts            ;    and return
  8809. ;shfbse: ldx    #shebit\    ; Get the address of 'EIGHT-BIT' string
  8810. ;    ldy    #shebit^    ;
  8811. ;    jsr    prstr        ; Print the the string at that address
  8812. ;    jsr    prcrlf        ; Print a crelf after it
  8813. ;    rts
  8814.  
  8815. shpari:    jsr    prcfm        ; make sure confirmed
  8816.     ldx    #shin20\    ; Get address of 'parity' string
  8817.     ldy    #shin20^    ;        ...
  8818.     jsr    prstr        ; Print that
  8819.     lda    parity        ; Get the parity index
  8820.     cmp    #5        ; Is it >= 5?
  8821.     bmi    shpar1        ; If not just get the string and print it
  8822.     lda    #0        ; This is the index to the parity we want
  8823. shpar1:    tax            ; Hold this index
  8824.     lda    #kerprs\    ; Get address of the parity strings
  8825.     sta    kermbs        ; And stuff it here for genmad
  8826.     lda    #kerprs^    ;        ...
  8827.     sta    kermbs+1    ;        ...
  8828.     lda    #kerpsl        ; Get the string length
  8829.     pha            ; Push that
  8830.     txa            ; Fetch the index back
  8831.     pha            ; Push that parm then
  8832.     jsr    genmad        ;    call genmad
  8833.     jsr    prstr        ; Print the the string at that address
  8834.     jsr    prcrlf        ; Print a crelf after it
  8835.     rts
  8836.  
  8837. shbad:    jsr    prcfm        ; make sure confirmed
  8838.     ldx    #shin19\    ;[17] Get the address of the 'baud' string
  8839.     ldy    #shin19^    ;[17]         ...
  8840.     jsr    prstr        ;[17] Print it
  8841.     lda    baud        ;[17] Get the baud rate
  8842.     cmp    #$0A        ;[17] Is it >= 10?
  8843.     bmi    shbad1        ;[17] No, just print the string
  8844.     lda    #bd1200        ;[17] Use 1200 baud as default
  8845. shbad1:    tax            ;[17] Hold the index here
  8846.     lda    #kerbds\    ;[17] Get the address of
  8847.     sta    kermbs        ;[17]    the baud rate strings
  8848.     lda    #kerbds^    ;[17]        ...
  8849.     sta    kermbs+1    ;[17]        ...
  8850.     lda    #kerbsl        ;[17] Get the length of the baud rate strings
  8851.     pha            ;[17] Push that
  8852.     txa            ;[17]
  8853.     pha            ;[17]
  8854.     jsr    genmad        ;[17]
  8855.     jsr    prstr        ;[17]
  8856.     jsr    prcrlf        ;[17]
  8857.     rts            ;[17]
  8858.  
  8859. shwrd:    jsr    prcfm        ; make sure confirmed
  8860.     ldx    #shin21\    ;[17] Get the address of the 'wrod-size'
  8861.     ldy    #shin21^    ;[17]    message
  8862.     jsr    prstr        ;[17] Print that
  8863.     lda    wrdsiz        ;[17] Get the word-size
  8864.     beq    shwrde        ;[17] 
  8865.     ldx    #shsbit\    ;[17] Get address of 'SEVEN-BIT' string
  8866.     ldy    #shsbit^    ;[17]        ...
  8867.     jsr    prstr        ;[17] Print that
  8868.     jsr    prcrlf        ;[17]    then a crelf
  8869.     rts            ;[17]    and return
  8870. shwrde:    ldx    #shebit\    ;[17] Get address of 'EIGHT-BIT' string
  8871.     ldy    #shebit^    ;[17]        ...
  8872.     jsr    prstr        ;[17] Print that
  8873.     jsr    prcrlf        ;[17]    and a crelf
  8874.     rts            ;[17]    and return
  8875.  
  8876. shflow:    jsr    prcfm        ; make sure confirmed
  8877.     ldx    #shin22\    ;[24]
  8878.     ldy    #shin22^    ;[24]
  8879.     jsr    prstr        ;[24]
  8880.     lda    flowmo        ;[24]
  8881.     jmp    pron        ;[24]
  8882.  
  8883. ;
  8884. ; Show default disk
  8885. ;
  8886. shdef:    jsr    prcfm        ; make sure confirmed
  8887.     ldx    #shin23\    ;[jrd] default drive string
  8888.     ldy    #shin23^    ;[jrd]
  8889.     jsr    prstr        ;[jrd]
  8890.     lda    dsknum        ;[jrd]
  8891.     jsr    cout        ;[jrd]
  8892.     jsr    prcrlf
  8893.     rts
  8894.  
  8895. .SBTTL    Status routine
  8896.  
  8897. ;
  8898. ;    This routine shows the status of the most recent transmission
  8899. ;    session.
  8900. ;
  8901. ;        Input:  NONE
  8902. ;
  8903. ;        Output: Status of last transmission is sent to screen
  8904. ;
  8905. ;        Registers destroyed:    A,X,Y
  8906. ;
  8907.  
  8908. status: jsr    prcfm        ; Parse and print a confirm
  8909.     jsr    stat01        ;[45] Go Give the status
  8910.     jmp    kermit        ;[45]   and parse for more commands
  8911.  
  8912. stat01: ldx    #stin00\    ; Get address of first line of text
  8913.     ldy    #stin00^    ;        ...
  8914.     jsr    prstr        ; Print that
  8915.     ldx    schr        ; Get low order byte of character count
  8916.     lda    schr+1        ; Get high order byte
  8917. ;    jsr    prntax        ; Print that pair in hex
  8918. ;    jsr    prntad        ; no, print it in decimal
  8919. ;    jsr    prcrlf        ; Add a crelf at the end
  8920.     jsr    prntadnl    ; use combined rtn
  8921.     ldx    #stin01\    ; Get address of second line
  8922.     ldy    #stin01^    ;        ....
  8923.     jsr    prstr        ; Print it
  8924.     ldx    rchr        ; Get L.O. byte of char count
  8925.     lda    rchr+1        ; Get H.O. byte
  8926. ;    jsr    prntax        ; Print that count
  8927. ;    jsr    prntad        ; print it in decimal
  8928. ;    jsr    prcrlf        ; Add a crelf at the end
  8929.     jsr    prntadnl    ; use combined rtn
  8930.     ldx    #stin02\    ; Get L.O. address of message
  8931.     ldy    #stin02^    ;
  8932.     jsr    prstr        ; Print message
  8933.     ldx    stot        ; Get L.O. byte of count
  8934.     lda    stot+1        ; Get H.O. byte
  8935. ;    jsr    prntax        ; Print the count
  8936. ;    jsr    prntad        ; print it in decimal
  8937. ;    jsr    prcrlf        ; Add a crelf at the end
  8938.     jsr    prntadnl    ; use combined rtn
  8939.     ldx    #stin03\    ; Get address of next status item message
  8940.     ldy    #stin03^
  8941.     jsr    prstr        ; Print it
  8942.     ldx    rtot        ; Get the proper count (L.O. byte)
  8943.     lda    rtot+1        ; Get H.O. byte
  8944. ;    jsr    prntax        ; Print the 16-bit count
  8945. ;    jsr    prntad        ; print it in decimal
  8946. ;    jsr    prcrlf        ; Add a crelf at the end
  8947.     jsr    prntadnl    ; use combined rtn
  8948.     jsr    prcrlf        ; Add a crelf at the end
  8949.     ldx    #stin04\    ; Get address of overhead message
  8950.     ldy    #stin04^    ;
  8951.     jsr    prstr        ; Print that message
  8952.     sec            ; Get ready to calculate overhead amount
  8953.     lda    stot        ; Get total character count and
  8954.     sbc    schr        ;    subtract off data character count
  8955.     tax            ; Stuff that here for printing
  8956.     lda    stot+1
  8957.     sbc    schr+1
  8958. ;    jsr    prntax        ; Print it
  8959. ;    jsr    prntad        ; print it in decimal
  8960. ;    jsr    prcrlf        ; Add a crelf at the end
  8961.     jsr    prntadnl    ; use combined rtn
  8962.     ldx    #stin05\    ; Get address of next overhead message
  8963.     ldy    #stin05^    ;        ...
  8964.     jsr    prstr        ; Print that
  8965.     sec            ; Get ready to calculate overhead amount
  8966.     lda    rtot        ; Get total character count and
  8967.     sbc    rchr        ;    subtract off data character count
  8968.     tax            ; Stuff that here for printing
  8969.     lda    rtot+1        ;        ...
  8970.     sbc    rchr+1        ;        ...
  8971. ;    jsr    prntax        ; Print the count
  8972. ;    jsr    prntad        ; print it in decimal
  8973. ;    jsr    prcrlf        ; Add a crelf at the end
  8974.     jsr    prntadnl    ; use combined rtn
  8975.     jsr    prcrlf        ; Add a crelf at the end
  8976.     ldx    #stin06\      ; Get message for 'last error'
  8977.     ldy    #stin06^    ;        ...
  8978.     jsr    prstr        ; Print the message
  8979.     jsr    prcrlf        ; Print a crelf before the error message
  8980.     lda    #eprflg        ; [jrd] ???
  8981.     bit    errcod        ; Test for 'Error packet received' bit
  8982.     bvs    statpe        ; Go process an error packet
  8983. ;
  8984. ; all this old error stuff commented out til we write the error decoder
  8985. ; for atari.
  8986. ;
  8987. ;    lda    #kerems        ; Get the error message size
  8988. ;    pha            ; Push it
  8989. ;    lda    errcod        ; Get the error message offset in table
  8990. ;    bmi    stat02        ; If this is a DOS error, do extra adjusting    
  8991. ;    pha            ; Push that
  8992. ;    lda    #erms0a\    ; Put the base address in kermbs
  8993. ;    sta    kermbs        ;        ...
  8994. ;    lda    #erms0a^    ;        ...
  8995. ;    sta    kermbs+1    ;        ...
  8996. ;    jmp    statle        ; Go print the 'last error' encountered
  8997. ;stat02:    and    #$7f        ; Shut off H.O. bit
  8998. ;    beq    stat03        ; If it is zero, we are done adjusting
  8999. ;    sec            ; Decrement by one for the unused error code
  9000. ;    sbc    #1        ;        ...
  9001. ;stat03:    pha            ; Push that parameter
  9002. ; zzz    lda    #dskers\    ; Use 'dskers' as the base address
  9003. ;    sta    kermbs        ;        ...
  9004. ;    lda    #dskers^    ;        ...
  9005. ;    sta    kermbs+1    ;        ...
  9006. ;statle:
  9007. ;    jsr    genmad        ; Translate code to address of message
  9008. ;    jsr    prstr        ; Print the text of error message
  9009. ;    jsr    prcrlf        ; Add a crelf at the end
  9010. ;;    jmp    kermit        ; Start at the top
  9011.     lda    errcod        ; [jrd] get the error code
  9012.     jsr    prerms        ; [jrd] print appropriate msg
  9013.     jsr    prcrlf        ; [jrd] and a crlf
  9014.     rts            ;[45] Return to the caller
  9015. statpe:    ldx    #errrkm\    ; L.O. byte address of remote kermit error
  9016.     ldy    #errrkm^    ; H.O. byte address...
  9017.     jsr    prstr        ; Print the text from the error packet
  9018.     jsr    prcrlf        ; Print an extra crelf
  9019. ;    jmp    kermit        ; Start at the top again
  9020.     rts            ;[45] Return to the caller
  9021.  
  9022. ;
  9023. ;    Given error code in A, return message addr in X,Y.  Preserves A.
  9024. ;
  9025. ermadr:    pha
  9026.     and    #$0F        ; not more than 15 of them
  9027.     asl    A        ; mult by 2
  9028.     tax            ; get it in x
  9029.     lda    kerrv+1,x    ; get hi byte
  9030.     tay            ; get hi byte into y
  9031.     lda    kerrv,x        ; get lo byte
  9032.     tax            ; into x
  9033.     pla
  9034.     rts
  9035. ;
  9036. ;    Print message given error code in A.  Preserves A.
  9037. ;
  9038. prerms:
  9039.     cmp    #0        ; No error?
  9040.     beq    prerms9        ; give up
  9041.     pha            ; save it
  9042.     jsr    ermadr        ; get msg addr
  9043.     cpy    #0        ; no message?
  9044.     beq    prerms8        ; print code then
  9045.     jsr    prstr        ; and go print it
  9046.     pla            ; get a back
  9047.     rts
  9048. prerms8:
  9049.     ldx    #ermess\
  9050.     ldy    #ermess^
  9051.     jsr    prstr
  9052.     pla
  9053.     pha
  9054.     jsr    prbyte        ; print the hex
  9055.     pla            ; get a back
  9056. prerms9:
  9057.     rts            ; and return
  9058.  
  9059. ;
  9060. ; take error code in A, hexify into ermsdc
  9061. ;
  9062. logdoserr:
  9063.     pha
  9064.     lsr    a
  9065.     lsr    a
  9066.     lsr    a
  9067.     lsr    a
  9068.     jsr    ny2hx        ; hexify top nybble
  9069.     sta    ermsdc
  9070.     pla
  9071.     and    #$0F
  9072.     jsr    ny2hx
  9073.     sta    ermsdc+1    ; and bot nybble
  9074.     rts
  9075.  
  9076. .SBTTL    Packet routines - SPAK - send packet
  9077.  
  9078. ;
  9079. ;    This routine forms and sends out a complete packet in the
  9080. ;    following format:
  9081. ;
  9082. ;    <SOH><char(pdlen)><char(pnum)><ptype><data><char(chksum)><eol>
  9083. ;
  9084. ;        Input:  kerbf1- Pointer to packet buffer
  9085. ;            pdlen-  Length of data
  9086. ;            pnum-    Packet number
  9087. ;            ptype-  Packet type
  9088. ;
  9089. ;        Output: A-    True or False return code
  9090. ;
  9091.  
  9092. spak:
  9093.     jsr    openrsm        ; ensure rs port open
  9094. ;    jsr    scred2        ; clear the screen
  9095. ;    ldx    #0
  9096. ;    ldy    #0
  9097. ;    jsr    scrplt        ; home the cursor
  9098.     sec            ; get cursor pos
  9099.     jsr    ploth
  9100. ;    ldy    #0        ; set col to 0
  9101.     ldx    #0        ; set col to 0
  9102.     clc            ; and put it back
  9103.     jsr    ploth
  9104.     ldx    #snin01\    ; Give the user info on what we are doing
  9105.     ldy    #snin01^    ;        ...
  9106.     jsr    prstr        ; Print the information
  9107.     ldx    #false        ;[49]
  9108.     jsr    timerset    ;[49]
  9109. ;---
  9110. ;    lda    tpak+1        ; Get the total packets count
  9111. ;    jsr    prbyte        ;    and print that
  9112. ;    lda    tpak        ;        ...
  9113. ;    jsr    prbyte        ;        ...
  9114.     ldx    tpak
  9115.     lda    tpak+1
  9116.     jsr    prntad        ; print packet num in decimal
  9117. ;---
  9118. ;    jsr    prcrlf        ; Output a crelf
  9119.     lda    #0        ; Clear packet data index
  9120.     sta    pdtind        ;        ...
  9121. spaknd: lda    spadch        ; Get the padding character
  9122.     ldx    #0        ; Init counter
  9123. spakpd: cpx    spad        ; Are we done padding?
  9124.     bcs    spakst        ;  Yes, start sending packet
  9125.     inx            ; No, up the index and count by one
  9126.     jsr    putplc        ; Output a padding character
  9127.     jmp    spakpd        ; Go around again
  9128. spakst: lda    #soh        ; Get the start-of-header char into AC
  9129.     jsr    putplc        ; Send it
  9130.     lda    pdlen        ; Get the data length
  9131.     clc            ; Clear the carry
  9132.     adc    #3        ; Adjust it
  9133.     pha            ; Save this to be added into stot
  9134.     clc            ; Clear carry again
  9135.     adc    #sp        ; Make the thing a character
  9136.     sta    chksum        ; First item,  start off chksum with it
  9137.     jsr    putplc        ; Send the character
  9138.     pla            ; Fetch the pdlen and add it into the
  9139.     clc            ;    'total characters sent' counter
  9140.     adc    stot        ;        ...
  9141.     sta    stot        ;        ...
  9142.     lda    stot+1        ;        ...
  9143.     adc    #0        ;        ...
  9144.     sta    stot+1        ;        ...
  9145.     lda    pnum        ; Get the packet number
  9146.     clc            ;        ...
  9147.     adc    #sp        ; Char it
  9148.     pha            ; Save it in this condition
  9149.     clc            ; Clear carry
  9150.     adc    chksum        ; Add this to the checksum
  9151.     sta    chksum        ;        ...
  9152.     pla            ; Restore character
  9153.     jsr    putplc        ; Send it
  9154.     lda    ptype        ; Fetch the packet type
  9155.     and    #$7F        ; Make sure H.O. bit is off for chksum
  9156.     pha            ; Save it on stack
  9157.     clc            ; Add to chksum
  9158.     adc    chksum        ;        ...
  9159.     sta    chksum        ;        ...
  9160.     pla            ; Get the original character off stack
  9161.     jsr    putplc        ; Send packet type
  9162.     ldy    #0        ; Initialize data count
  9163.     sty    datind        ; Hold it here
  9164. spaklp: ldy    datind        ; Get the current index into the data
  9165.     cpy    pdlen        ; Check against packet data length, done?
  9166.     bmi    spakdc        ; Not yet, process another character
  9167.     jmp    spakch        ; Go do chksum calculations
  9168. spakdc: lda    (kerbf1),y    ; Fetch data from packet buffer
  9169.     clc            ; Add the character into the chksum
  9170.     adc    chksum        ;        ...
  9171.     sta    chksum        ;        ...
  9172.     lda    (kerbf1),y    ; Refetch data from packet buffer
  9173.     jsr    putplc        ; Send it
  9174.     inc    datind        ; Up the counter and index
  9175.     jmp    spaklp        ; Loop to do next character
  9176. spakch: lda    chksum        ; Now, adjust the chksum to fit in 6 bits
  9177.     and    #$C0        ; First, take bits 6 and 7
  9178.     lsr    a        ;    and shift them to the extreme right
  9179.     lsr    a        ;    side of the AC
  9180.     lsr    a        ;        ...
  9181.     lsr    a        ;        ...
  9182.     lsr    a        ;        ...
  9183.     lsr    a        ;        ...
  9184.     clc            ; Now add in the original chksum byte
  9185.     adc    chksum        ;        ...
  9186.     and    #$3F        ; All this should be mod decimal 64
  9187.     clc            ;        ...
  9188.     adc    #sp        ; Put it in printable range
  9189.     jsr    putplc        ;    and send it
  9190.     lda    seol        ; Fetch the eol character
  9191.     jsr    putplc        ; Send that as the last byte of the packet
  9192.     lda    pdtind        ; Set the end of buffer pointer
  9193.     sta    pdtend        ;        ...
  9194.     lda    #0        ; Set index to zero
  9195.     sta    pdtind        ;        ...
  9196.     lda    debug        ; Is the debug option turned on?
  9197.     cmp    #off        ;        ...
  9198.     beq    spaksp        ; Nope, go stuff packet at other kermit
  9199.     lda    #0        ; Option 0
  9200.     jsr    debg        ; Do it
  9201. spaksp: lda    #0        ; Zero the index
  9202.     sta    pdtind        ;        ...
  9203. spakdl: ldx    pdtind        ; Are we done?
  9204.     cpx    pdtend        ;        ...
  9205.     bpl    spakcd        ; Yes, go call debug again
  9206.     lda    plnbuf,x    ; Get the byte to send
  9207.     jsr    putrs        ; Ship it out
  9208.     inc    pdtind        ; Increment the index once
  9209.     jmp    spakdl        ; Go to top of data send loop
  9210. spakcd: lda    debug        ; Get debug switch
  9211.     cmp    #off        ; Do we have to do it?
  9212.     beq    spakcr        ; Nope, return
  9213.     lda    #1        ; Option 1
  9214.     jsr    debg        ; Do the debug stuff
  9215. spakcr: rts            ;    and return
  9216.  
  9217. .SBTTL    Packet routines - RPAK - receive a packet
  9218.  
  9219. ;
  9220. ;    This routine receives a standard Kermit packet and then breaks
  9221. ;    it apart returning the individuals components in their respective
  9222. ;    memory locations.
  9223. ;
  9224. ;        Input:
  9225. ;
  9226. ;        Output: kerbf1- Pointer to data from packet
  9227. ;            pdlen-  Length of data
  9228. ;            pnum-    Packet number
  9229. ;            ptype-  Packet type
  9230. ;
  9231.  
  9232. rpak:    jsr    gobble        ; Gobble a line up from the port
  9233.      jmp    rpkfls        ; Must have gotten a keyboard interupt, fail
  9234.     lda    ibmmod        ; Is ibm-mode on?
  9235.     cmp    #on        ;        ...
  9236.     bne    rpakst        ; If not, start working on the packet
  9237. rpakc0:    jsr    getc        ; Any characters yet?
  9238.      jmp    rpakst        ; Got one from the keyboard
  9239.     lda    char        ;[31]
  9240.     cmp    #xon        ; Is it an XON?
  9241.     bne    rpakc0        ; Nope, try again
  9242. rpakst:
  9243. ;    jsr    scred2        ; clear the screen
  9244. ;    ldx    #$00
  9245. ;    ldy    #$00
  9246. ;    jsr    scrplt        ; home the cursor
  9247.     sec            ; get cursor pos
  9248.     jsr    ploth
  9249. ;    ldy    #0        ; set col to 0
  9250.     ldx    #0        ; set col to 0
  9251.     clc            ; and put it back
  9252.     jsr    ploth
  9253.     ldx    #rcin01\     ; Give the user info on what we are doing
  9254.     ldy    #rcin01^    ;        ...
  9255.     jsr    prstr        ; Print the information
  9256.     ldx    #true        ;[49]
  9257.     jsr    timerset    ;[49] Set the timeout length
  9258. ;---
  9259. ;    lda    tpak+1        ; Get the total packets count
  9260. ;    jsr    prbyte        ;    and print that
  9261. ;    lda    tpak        ;        ...
  9262. ;    jsr    prbyte        ;        ...
  9263.     ldx    tpak
  9264.     lda    tpak+1
  9265.     jsr    prntad
  9266. ;---
  9267. ;    jsr    prcrlf        ; Output a crelf
  9268.     lda    debug        ; Is debugging on?
  9269.     cmp    #off        ;        ...
  9270.     beq    rpaknd        ;  Nope, no debugging, continue
  9271.     lda    #2        ; Option 2 <reflect the fact we are in rpak>
  9272.     jsr    debg        ; Do debug stuff
  9273. rpaknd: lda    #0        ; Clear the
  9274.     sta    chksum        ;    chksum
  9275.     sta    datind        ;    index into packet buffer
  9276.     sta    kerchr        ;    and the current character input
  9277. rpakfs: jsr    getplc        ; Get a char, find SOH
  9278.      jmp    rpkfls        ; Got a keyboard interupt instead
  9279.     sta    kerchr        ; Save it
  9280.     and    #$7F        ; Shut off H.O. bit
  9281.     cmp    #soh        ; Is it an SOH character?
  9282.     bne    rpakfs        ; Nope, try again
  9283.     lda    #1        ; Set up the switch for receive packet
  9284.     sta    fld        ;        ...
  9285. rpklp1: lda    fld        ; Get switch
  9286.     cmp    #6        ; Compare for <= 5
  9287.     bmi    rpklp2        ; If it still is, continue
  9288.     jmp    rpkchk        ; Otherwise, do the chksum calcs
  9289. rpklp2: cmp    #5        ; Check fld
  9290.     bne    rpkif1        ; If it is not 5, go check for SOH
  9291.     lda    datind        ; Fetch the data index
  9292.     cmp    #0        ; If the data index is not null
  9293.     bne    rpkif1        ;    do the same thing
  9294.     jmp    rpkif2        ; Go process the character
  9295. rpkif1: jsr    getplc        ; Get a char, find SOH
  9296.      jmp    rpkfls        ; Got a keyboard interupt instead
  9297.     sta    kerchr        ; Save that here
  9298.     and    #$7F        ; Make sure H.O. bit is off
  9299.     cmp    #soh        ; Was it another SOH?
  9300.     bne    rpkif2        ; If not, we don't have to resynch
  9301.     lda    #0        ; Yes, resynch
  9302.     sta    fld        ; Reset the switch
  9303. rpkif2: lda    fld        ; Get the field switch
  9304.     cmp    #4        ; Is it < = 3?
  9305.     bpl    rpkswt        ; No, go check the different cases now
  9306.     lda    kerchr        ; Yes, it was, get the character
  9307.     clc            ;    and add it into the chksum
  9308.     adc    chksum        ;        ...
  9309.     sta    chksum        ;        ...
  9310. rpkswt: lda    fld        ; Now check the different cases of fld
  9311.     cmp    #0        ; Case 0?
  9312.     bne    rpkc1        ; Nope, try next one
  9313.     lda    #0        ; Yes, zero the chksum
  9314.     sta    chksum        ;        ...
  9315.     jmp    rpkef        ;    and restart the loop
  9316. rpkc1:  cmp    #1        ; Is it case 1?
  9317.     bne    rpkc2        ; No, continue checking
  9318.     lda    kerchr        ; Yes, get the length of packet
  9319.     sec            ;        ...
  9320.     sbc    #sp        ; Unchar it
  9321.     sec            ;        ...
  9322.     sbc    #3        ; Adjust it down to data length
  9323.     sta    pdlen        ; That is the packet data length, put it there
  9324.     jmp    rpkef        ; Continue on to next item
  9325. rpkc2:  cmp    #2        ; Case 2 (packet number)?
  9326.     bne    rpkc3        ; If not, try case 3
  9327.     lda    kerchr        ; Fetch the character
  9328.     sec            ;        ...
  9329.     sbc    #sp        ; Take it down to what it really is
  9330.     sta    pnum        ; That is the packet number, save it
  9331.     jmp    rpkef        ; On to the next packet item
  9332. rpkc3:  cmp    #3        ; Is it case 3 (packet type)?
  9333.     bne    rpkc4        ; If not, try next one
  9334.     lda    kerchr        ; Get the character and
  9335.     sta    ptype        ;    stuff it as is into the packet type
  9336.     jmp    rpkef        ; Go on to next item
  9337. rpkc4:  cmp    #4        ; Is it case 4???
  9338.     bne    rpkc5        ; No, try last case
  9339.     ldy    #0        ; Set up the data index
  9340.     sty    datind        ;        ...
  9341. rpkchl: ldy    datind        ; Make sure datind is in Y
  9342.     cpy    pdlen        ; Compare to the packet data length, done?
  9343.     bmi    rpkif3        ; Not yet, process the character as data
  9344.     jmp    rpkef        ; Yes, go on to last field (chksum)
  9345. rpkif3: cpy    #0        ; Is this the first time through the data loop?
  9346.     beq    rpkacc        ; If so, SOH has been checked, skip it
  9347.     jsr    getplc        ; Get a char, find SOH
  9348.      jmp    rpkfls        ; Got a keyboard interupt instead
  9349.     sta    kerchr        ; Store it here
  9350.     and    #$7F        ; Shut H.O. bit
  9351.     cmp    #soh        ; Is it an SOH again?
  9352.     bne    rpkacc        ; No, go accumulate chksum
  9353.     lda    #$FF        ; Yup, SOH, go resynch packet input once again
  9354.     sta    fld        ;        ...
  9355.     jmp    rpkef        ;        ...
  9356. rpkacc: lda    kerchr        ; Get the character
  9357.     clc            ;        ...
  9358.     adc    chksum        ; Add it to the chksum
  9359.     sta    chksum        ;    and save new chksum
  9360.     lda    kerchr        ; Get the character again
  9361.     ldy    datind        ; Get our current data index
  9362.     sta    (kerbf1),y    ; Stuff the current character into the buffer
  9363.     inc    datind        ; Up the index once
  9364.     jmp    rpkchl        ; Go back and check if we have to do this again
  9365. rpkc5:  cmp    #5        ; Last chance, is it case 5?
  9366.     beq    rpkc51        ; Ok, continue
  9367.     jmp    rpkpe        ; Warn user about program error
  9368. rpkc51: lda    chksum        ; Do chksum calculations
  9369.     and    #$C0        ; Grab bits 6 and 7
  9370.     lsr    a        ; Shift them to the right (6 times)
  9371.     lsr    a        ;        ...
  9372.     lsr    a        ;        ...
  9373.     lsr    a        ;        ...
  9374.     lsr    a        ;        ...
  9375.     lsr    a        ;        ...
  9376.     clc            ; Clear carry for addition
  9377.     adc    chksum        ; Add this into original chksum
  9378.     and    #$3F        ; Make all of this mod decimal 64
  9379.     sta    chksum        ;    and resave it
  9380. rpkef:  inc    fld        ; Now increment the field switch
  9381.     jmp    rpklp1        ; And go check the next item
  9382. rpkchk: lda    kerchr        ; Get chksum from packet
  9383.     sec            ; Set carry for subtraction
  9384.     sbc    #sp        ; Unchar it
  9385.     cmp    chksum        ; Compare it to the one this Kermit generated
  9386.     beq    rpkret        ; We were successful, tell the caller that
  9387.     lda    #errbch        ; Store the error code
  9388.     sta    errcod        ;        ...
  9389.     ldx    #erms15\    ; Create pointer to error text
  9390.     ldy    #erms15^    ;
  9391.     jsr    prstr        ; Print the chksum error
  9392.     lda    kerchr        ; Print chksum from packet
  9393.     jsr    prbyte        ;        ...
  9394.     lda    #sp        ; Space things out a bit
  9395.     jsr    cout        ;        ...
  9396.     lda    chksum        ; Now get what we calculated
  9397.     jsr    prbyte        ;    and print that
  9398. rpkfls:    lda    #0        ; Zero the index for debug mode
  9399.     sta    pdtind        ;        ...
  9400.     lda    debug        ; Is debug switch on?
  9401.     cmp    #off        ;        ...
  9402.     beq    rpkfnd        ;  Return doing no debug stuff
  9403.     lda    #3        ; Option 3 <we are in rpkfls>
  9404.     jsr    debg        ; Output debug information
  9405. rpkfnd: lda    pdlen        ; Get the packet data length
  9406.     clc            ;    and add it into the
  9407.     adc    rtot        ;    'total characters received' counter
  9408.     sta    rtot        ;        ...
  9409.     lda    rtot+1        ;        ...
  9410.     adc    #0        ;        ...
  9411.     sta    rtot+1        ;        ...
  9412.     lda    #false        ; Set up failure return
  9413.     sta    ptype        ;[DD] Set packet type false
  9414.     rts            ;    and go back
  9415. rpkret:    lda    #0        ; Zero the index for debug mode
  9416.     sta    pdtind        ;        ...
  9417.     lda    debug        ; Check debug switch
  9418.     cmp    #off        ; Is it on?
  9419.     beq    rpkrnd        ; No, return with no debug
  9420.     lda    #4        ; Yes, use option 4 <we received a packet>
  9421.     jsr    debg        ; Print out the debug info
  9422. rpkrnd: lda    pdlen        ; Get the packet data length
  9423.     clc            ;    and add it into the
  9424.     adc    rtot        ;    'total characters received' counter
  9425.     sta    rtot        ;        ...
  9426.     lda    rtot+1        ;        ...
  9427.     adc    #0        ;        ...
  9428.     sta    rtot+1        ;        ...
  9429.     lda    #true        ; Show a successful return
  9430.     rts            ;    and return
  9431. rpkpe:  ldx    #erms16\    ; Set up pointer to error text
  9432.     ldy    #erms16^    ;        ...
  9433.     jsr    prstr        ; Print the error
  9434.     lda    #errint        ; Load error code and store in errcod
  9435.     sta    errcod        ;        ...
  9436.     jmp    rpkfls        ; Go give a false return
  9437.  
  9438. .SBTTL    Timerset and Timerexp
  9439.  
  9440. ;
  9441. ;    Routines to set and check for Kermit timeouts
  9442. ;
  9443.  
  9444. ;
  9445. ;    Timerset - Set the timeout for receive or send
  9446. ;
  9447. ;    Input:    X - True for receive, false for send
  9448. ;
  9449. ;    Registers Detsroyed: A
  9450. ;
  9451.  
  9452. timerset:    
  9453.     lda    stime        ; [jrd] assume sending
  9454.     cpx    #true        ;[49] Are we receiving?
  9455.     bne    timsst        ;[49] No
  9456.     lda    rtime        ; [jrd] ok, so we're receiving
  9457. timsst:
  9458.     ldx    #0        ; [jrd] zap 'lo' byte of timer
  9459.     stx    ttime+1        ;  ... remember it's byte flipped; hi, lo
  9460.     clc            ; [jrd] shift 8 bit time offset (secs) by
  9461.     ror    A        ;  2 into 16 bits, to get ticks.
  9462.     ror    ttime+1        ;  ...
  9463.     ror    A        ;  ...
  9464.     ror    ttime+1        ;  ...
  9465.     sta    ttime        ; [jrd] put low order byte in
  9466.     lda    RTCLOK+2    ; [jrd] atari's real time clock, lo order byte
  9467.     clc            ;[49]
  9468.     adc    ttime+1        ;[49] Add in the receive timeout
  9469.     sta    ttime+1        ;[49]     and store it
  9470.     lda    ttime        ;[49] Account for the carry if any
  9471.     adc    RTCLOK+1    ; [jrd] get mid order byte of clock
  9472.     sta    ttime        ;[49]    and store it
  9473.     rts            ;[49] Return
  9474.  
  9475. ;
  9476. ;    Timerexp - Check to see if we have exceeded the timeout limit.
  9477. ;
  9478. ;    Input:  Ttim - time to timeout at
  9479. ;        Clock+1 - current time
  9480. ;
  9481. ;    Registers Destroyed: A
  9482. ;
  9483.  
  9484. timerexp:    
  9485.     lda    RTCLOK+1    ; [jrd] Atari middle byte
  9486.     cmp    ttime        ;[49] Compare it to the old minutes
  9487.     bmi    timskp        ;[49] Still less
  9488.     lda    RTCLOK+2    ; [jrd] Atari?
  9489.     cmp    ttime+1        ;[49] Compare it to the old seconds
  9490.     bmi    timskp        ;[49] Still less 
  9491. timret:    rts            ;[49] We have timed out, return
  9492. timskp:    jmp    rskp        ;[49] No timeout, return with a skip
  9493.  
  9494. .SBTTL    DEBG - debugging output routines
  9495.  
  9496. ;
  9497. ;    When the debugging option is turned on, these routines periodically
  9498. ;    display information about what data is being sent or received.
  9499. ;
  9500. ;        Input:  A-    Action type
  9501. ;            Ptype-  Packet type sent or received
  9502. ;            Pnum-    Packet number sent or received
  9503. ;            Pdlen-  Packet data length
  9504. ;
  9505. ;        Output: Display info on current packet status
  9506. ;
  9507. ;        Registers destroyed:    A,X,Y
  9508. ;
  9509.  
  9510. debg:    pha            ; save a
  9511.     jsr    prcrlf        ; Output a crelf
  9512.     pla            ; get a back
  9513.     tax            ; Hold the action code here
  9514.     sta    debinx        ; Save it here
  9515.     lda    debug        ; Get the debug switch
  9516.     cmp    #terse        ; Is it terse
  9517.     bne    debgvr        ; Nope, must be Verbose mode
  9518.     jmp    debgtr        ; Yes, to terse debug output
  9519. debgvr:    lda    state        ; Check the current state
  9520.     cmp    #0        ; If we just started this thing
  9521.     beq    debgrf        ;    then we don't need debug output yet
  9522.     cmp    #'C        ; If the transmission state is 'complete'
  9523.     beq    debgrf        ;    we don't need debug output either
  9524.     lda    #kerrts\    ; Get base address of the routine name and
  9525.     sta    kermbs        ;    action table so that we can calculate
  9526.     lda    #kerrts^    ;        ...
  9527.     sta    kermbs+1    ;        ...
  9528.     lda    #kerrns        ; Load the routine name size
  9529.     pha            ; Push that
  9530.     txa            ; Fetch the offset for the one we want
  9531.     pha            ; And push that parameter
  9532.     jsr    genmad        ; Go generate the message address
  9533.     jsr    prstr        ; Now, go print the string
  9534.     lda    ptype        ; Get the current packet type
  9535.     pha            ; Save this accross the routine calls
  9536.     jsr    cout        ; Write that out
  9537.     jsr    prcrlf        ; Now write a crelf
  9538.     pla            ; Get back the packet type
  9539.     sta    debchk        ;    and start the checksum with that
  9540.     lda    debinx        ; Get the debug action index
  9541.     bne    debg1        ; If not 'sending', continue
  9542.     jsr    debprd        ; Yes, go do some extra output
  9543. debg1:  cmp    #4        ; Have we just received a packet?
  9544.     bne    debgrt        ; No, just return
  9545.     jsr    debprd        ; Print the packet info
  9546. debgrt:    jsr    prcrlf        ; Output a crelf
  9547.     lda    #true        ; Load true return code into AC
  9548.     rts            ;    and return
  9549. debgrf:    jsr    prcrlf        ; Output a crelf
  9550.     lda    #false        ; Set up failure return
  9551.     rts            ;    and go back
  9552.  
  9553. ;
  9554. ;    Debprd - does special information output including packet number,
  9555. ;    packet data length, the entire packet buffer, and the checksum
  9556. ;    of the packet as calculted by this routine.
  9557. ;
  9558.  
  9559. debprd: jsr    prcrlf        ; Start by giving us a new line
  9560.     ldx    #debms1\    ; Get the first info message address
  9561.     ldy    #debms1^    ;        ...
  9562.     jsr    prstr        ;    and print it
  9563.     jsr    prcrlf        ; New line
  9564.     ldx    #debms3\    ; Get address of message text
  9565.     ldy    #debms3^    ;        ...
  9566.     jsr    prstr        ; Print it
  9567.     inc    pdtind        ; Pass the SOH
  9568.     ldx    pdtind        ; Get the index
  9569.     lda    plnbuf,x    ; Get the data length
  9570.     sec            ; Uncharacter this value
  9571.     sbc    #$20        ;        ...
  9572.     jsr    prbyte        ; Print the hex value
  9573.     jsr    prcrlf        ; New line
  9574.     ldx    #debms2\    ; Get address of message text
  9575.     ldy    #debms2^    ;        ...
  9576.     jsr    prstr        ; Print it
  9577.     inc    pdtind        ; Next character is packet number
  9578.     ldx    pdtind        ;        ...
  9579.     lda    plnbuf,x    ; Load it
  9580.     sec            ; Uncharacter this value
  9581.     sbc    #$20        ;        ...
  9582.     jsr    prbyte        ; Print the hex value
  9583.     jsr    prcrlf        ; New line
  9584.     inc    pdtind        ; Bypass the packet type
  9585.     ldy    #$FF        ; Start counter at -1
  9586.     sty    kwrk02        ; Store it here
  9587. debprc:    inc    kwrk02        ; Increment the counter
  9588.     ldy    kwrk02        ; Get counter
  9589.     cpy    pdlen        ; Are we done printing the packet data?
  9590.     bpl    debdon        ; If so, go finish up
  9591.     inc    pdtind        ; Point to next character
  9592.     ldx    pdtind        ; Fetch the index
  9593.     lda    plnbuf,x    ; Get next byte from packet
  9594.     jsr    prchr        ; Go output special character
  9595.     lda    #space        ; Now print 1 space
  9596.     jsr    cout        ;        ...
  9597.     jmp    debprc        ; Go check next character
  9598. debdon:    jsr    prcrlf        ; Next line
  9599.     ldx    #debms4\    ; Get the address to the 'checksum' message
  9600.     ldy    #debms4^    ;        ...
  9601.     jsr    prstr        ; Print that message
  9602.     inc    pdtind        ; Get next byte, this is the checksum
  9603.     ldx    pdtind        ;        ...
  9604.     lda    plnbuf,x    ;        ...
  9605.     sec            ; Uncharacter this value
  9606.     sbc    #$20        ;        ...
  9607.     jsr    prbyte        ; Print the hex value of the checksum
  9608.     jsr    prcrlf        ; Print two(2) crelfs
  9609.     jsr    prcrlf        ;        ...
  9610.     rts            ;    and return
  9611.  
  9612. .SBTTL    Terse debug output
  9613.  
  9614. ;
  9615. ;    This routine does brief debug output. It prints only the contents
  9616. ;    of the packet with no identifying text.
  9617. ;
  9618.  
  9619. debgtr:    txa            ; Look at Option
  9620.     cmp    #0        ; Sending?
  9621.     beq    debgsn        ; Yes, output 'SENDING: '
  9622.     cmp    #3        ; Failed receive?
  9623.     beq    debgrc        ; Yes, output 'RECEIVED: '
  9624.     cmp    #4        ; Receive?
  9625.     beq    debgrc        ; Yes, output 'RECEIVED: '
  9626.     rts            ; Neither, just return
  9627. debgsn:    ldx    #sstrng\    ; Get ready to print the string
  9628.     ldy    #sstrng^    ;        ...
  9629.     jsr    prstr        ; Do it!
  9630.     jsr    prcrlf        ; Print a crelf
  9631.     jmp    debgdp        ; Go dump the packet
  9632. debgrc:    ldx    #rstrng\    ; Get ready to print the string
  9633.     ldy    #rstrng^    ;        ...
  9634.     jsr    prstr        ; Do it!
  9635.     jsr    prcrlf        ; Print a crelf
  9636. debgdp:    ldx    pdtind        ; Get index
  9637.     cpx    pdtend        ; Are we done?
  9638.     bpl    debgfn        ; Yes, return
  9639.     lda    plnbuf,x    ; Get the character
  9640.     jsr    prchr        ; Print it
  9641.     lda    #space        ; Print a space
  9642.     jsr    cout        ;        ...
  9643.     inc    pdtind        ; Advance the index
  9644.     jmp    debgdp        ; Do next character
  9645. debgfn:    jsr    prcrlf        ; Print a crelf then...
  9646.     rts            ;    Return
  9647.  
  9648. .SBTTL    Dos routines
  9649.  
  9650. ;
  9651. ;    These routines handle files and calls to the DOS
  9652. ;
  9653.  
  9654. ;
  9655. ;    Logrcv:    Tells the user what file we're receiving.
  9656. ;    Logsnd:    Similar one for transmits.
  9657. ;        these expect primfn to contain the pathname
  9658. ;        just opened, so use them AFTER open.
  9659. ;
  9660. logrcv:
  9661.     ldx    #logrcvm\    ; print "Receiving..." msg
  9662.     ldy    #logrcvm^
  9663.     jmp    logxr        ; use common thread
  9664. logsnd:
  9665.     ldx    #logsndm\    ; print "Sending..." msg
  9666.     ldy    #logsndm^
  9667. logxr:
  9668.     jsr    prstr
  9669.     ldx    #primfn\    ; print the pathname
  9670.     ldy    #primfn^
  9671.     jsr    pstreol
  9672.     jsr    prcrlf        ; and an eol
  9673.     rts
  9674.  
  9675. ;
  9676. ;    This routine opens a file for either input or output. If it
  9677. ;    opens it for output, and the file exists, and file-warning is
  9678. ;    on, the routine will issue a warning and attempt to modify
  9679. ;    the filename so that it is unique.
  9680. ;
  9681. ;        Input:    A- Fncrea - open for read
  9682. ;               Fncwrt - open for write
  9683. ;
  9684. ;        Output:    File is opened or error is issued
  9685. ;
  9686.  
  9687. openf:
  9688.     pha            ; [jrd] save r/w code
  9689.     jsr    closers        ; [jrd] make sure the rs port's closed
  9690.     pla            ; [jrd] get r/w code back
  9691.     cmp    #fncwrt        ; [jrd] open for writing?
  9692.     beq    openfo        ; [jrd] yup
  9693. ;
  9694. ; open for read
  9695. ;
  9696. ;    lda    #dsknam\    ; [jrd] file name lo
  9697. ;    ldy    #dsknam^    ; [jrd] file name hi
  9698. ;----
  9699.     jsr    parsefcb    ; [jrd] parse the pathname
  9700.     jsr    bldprm        ; [jrd] reformat it
  9701.     lda    #primfn\
  9702.     ldy    #primfn^
  9703. ;----
  9704.     ldx    #dskchan    ; [jrd] disk IOCB please
  9705.     jsr    opencin        ; [jrd] try to open it
  9706.     jmp    opnfi1        ; [jrd] go handle status etc
  9707. ;
  9708. openfo:
  9709.     jsr    parsefcb    ; [jrd] parse and merge pathname in fcb
  9710. ;    lda    flsrw        ;[23] Get the file mode
  9711. ;    cmp    #fncwrt        ;[23] Are we opening for output?
  9712. ;    bne    opnnlu        ;[23] No, no lookup needed
  9713.     lda    #on        ;[23] Yes, set the 'first mod' switch
  9714.     sta    dosffm        ;[23]    in case we have to alter the filename
  9715.     lda    filwar        ;[23] Get the file warning switch
  9716.     cmp    #on        ;[23] Is it on?
  9717.     bne    opnnlu        ;[23] If not, don't do the lookup
  9718. opnlu:    jsr    lookup        ;[23] Do the lookup
  9719.      jmp    opnnlu        ;[23] Suceeded, open the file
  9720. ;    lda    dosffm        ;[23] Is this the first time through?
  9721. ;    cmp    #on        ;[23]        ...
  9722. ;    bne    opnalt        ;[23] If not, continue
  9723. ; need this zzz
  9724. ;    jsr    prfn        ; [jrd] print the conflicting file name
  9725.     lda    #ATEOL
  9726. ;    jsr    sputch
  9727.     jsr    scrput
  9728.     ldx    #primfn\    ; name buffer addr
  9729.     ldy    #primfn^
  9730.     jsr    pstreol        ; print eol terminated string
  9731.     ldx    #erms1a\    ;[23] Otherwise, print an error message since
  9732.     ldy    #erms1a^    ;[23]    the file already exists
  9733.     jsr    prstr        ;[23]        ...
  9734. opnalt:    jsr    alterf        ;[23] No good, go alter the filename
  9735.     jmp    opnlu        ;[23] Try the lookup again
  9736. opnnlu:    jsr    bldprm        ;[23] Build the filename again
  9737.     ldx    #dskchan    ; [jrd] make sure it's still there
  9738.     lda    #primfn\    ; [jrd] file name lo    
  9739.     ldy    #primfn^    ; [jrd] file name hi
  9740.     jsr    opencout    ; [jrd] try to open it
  9741.                 ; [jrd] and fall thru to status handler
  9742.  
  9743. opnfi1:    
  9744.     cpy    #SUCCES        ; open succeed?
  9745.     bne      opfail         ;[DD] If not, error
  9746.     lda    #0
  9747.     sta    eodind        ;[DD] Clear end of dat flag
  9748. opnex:  lda    #true        ;[DD] The open worked, return true
  9749.     rts            ;[DD]        ...
  9750. opfail:
  9751.     tya            ; save error stat
  9752.     pha
  9753.     ldx    #opnflm1\    ; print the open failure message
  9754.     ldy    #opnflm1^
  9755.     jsr    prstr
  9756.     pla            ; get the code back
  9757.     jsr    prbyte
  9758.     ldx    #opnflm2\    ; print the next part
  9759.     ldy    #opnflm2^
  9760.     jsr    prstr
  9761.     ldx    #dskchan
  9762.     lda    ICAX1,X        ; get the aux value
  9763.     jsr    prbyte
  9764.     ldx    #opnflm3\    ; print the next part
  9765.     ldy    #opnflm3^
  9766.     jsr    prstr
  9767.     ldx    #dskchan
  9768.     ldy    ICBAH,X        ; get fn ptr hi
  9769.     lda    ICBAL,X        ;  and lo
  9770.     tax            ; into x...
  9771.     jsr    pstreol        ; and print it.
  9772. ;
  9773.     ldx    #opnflm4\    ; print last part
  9774.     ldy    #opnflm4^
  9775.     jsr    prstr
  9776. ;    
  9777.     jmp    fatal        ;[DD] Failed, go handle that
  9778. ;    rts            ;[DD]        ...
  9779.  
  9780. opnflm1: .byte    ATEOL,"Open failure ",0
  9781. opnflm2: .byte    " AUX1 ",0
  9782. opnflm3: .byte    " Name '",0
  9783. opnflm4: .byte    "'",ATEOL,0
  9784. ;
  9785. ;    Lookup - searches for a filename in a directory. It is used to
  9786. ;    support file warning during the opening of a file.
  9787. ;
  9788.  
  9789. lookup:    lda    #fncrea        ;[23] Get an 'R
  9790.     sta    flsrw        ;[23] Store it in the file mode switch
  9791.     jsr    locent        ;[23] Go try to locate that file
  9792.      jmp    locfnf        ;[23] File not found? We are in good shape
  9793.     lda    #errfae        ;[23] Store the error code
  9794.     sta    errcod        ;[23]        ...
  9795.     jmp    rskp        ;[23] Return with skip, have to alter filename
  9796. locfnf:    lda    #fncwrt        ;[23] Get a 'W
  9797.     sta    flsrw        ;[23] Store that
  9798.     rts            ;[23] Return without a skip
  9799.  
  9800. ;
  9801. ;    Alterf - changes a filename in the filename buffer to make it unique.
  9802. ;    It accomplishes this in the following manner.
  9803. ;
  9804. ;        1) First time through, it finds the last significant character
  9805. ;            in the filename and appends a '.0' to it.
  9806. ;
  9807. ;        2) Each succeeding time, it will increment the trailing integer
  9808. ;            that it inserted the first time through.
  9809. ;
  9810.  
  9811. alterf:    lda    dosffm        ;[23] Get the 'first mod' flag
  9812.     cmp    #on        ;[23] Is it on?
  9813.     bne    altsm        ;[23] If not, drop into regular loop
  9814. ;
  9815.     lda    #off        ;[23] Shut the 'first mod' flag off
  9816.     sta    dosffm        ;[23]        ...
  9817.     lda    #0        ; [jrd] set ver # to zero
  9818.     sta    dosfvn        ; and drop into normal code, to inc it
  9819.     jmp    altfm        ; first mod, skip inc code
  9820. ;
  9821. altsm:                ; nth mod...
  9822.     ldx    dosfvn        ;[23] Get the file version number
  9823.     inx            ;[23] Increment it
  9824.     stx    dosfvn        ;[23] Save the new version number
  9825.     txa            ;[23] Get the version number in the AC
  9826. ; no need    cmp    #0        ;[23] Is it 0 ?
  9827.     beq    altng        ;[23] Yes, cannot alter name
  9828. altfm:
  9829.     jsr    altstv        ;[23] Go store the version
  9830.     rts            ;[23] And return
  9831. ;
  9832. altng:    lda    #errfal        ;[23] Store the error code
  9833.     sta    errcod        ;[23]        ...
  9834.     ldx    kerosp        ;[23] Get the old stack pointer
  9835.     txs            ;[23]    and restore it
  9836.     jmp    kermit        ;[23] Go back to top of loop
  9837.  
  9838. ;
  9839. ;    Altstv - stores the version number passed to it into the filename
  9840. ;    buffer at whatever position dosfni is pointing to.
  9841. ;    Hexifies the version num, and sticks it in as the file type
  9842. ;    field.  zzz later, do this in decimal
  9843.  
  9844. altstv:    
  9845. ;---
  9846. ;    ldy    dosfni        ;[23] Get the filename index
  9847. ;---
  9848.     ldy    #pnd.es        ; [jrd] extension text size
  9849.     pha            ;[23] Save the value
  9850.     lda    #2        ; new ext is two bytes
  9851.     jsr    altdep        ; stuff it in
  9852.     pla            ; get value back again
  9853.     pha            ; save once more
  9854.     lsr    a        ;[23] Shift out the low order nibble
  9855.     lsr    a        ;[23]        ...
  9856.     lsr    a        ;[23]        ...
  9857.     lsr    a        ;[23]        ...
  9858.     jsr    altstf        ;[23] Stuff the character
  9859.     pla            ;[23] Grab back the original value
  9860.     and    #$0F        ;[23] Take the low order nibble
  9861.     jsr    altstf        ;[23] Stuff the next character
  9862. ;---
  9863. ;    iny            ; bump again
  9864. ;    lda    #ATEOL        ; get an EOL
  9865. ;    sta    fcb1,y        ;  to terminate file name
  9866. ;---
  9867.     rts            ;[23]    and return
  9868.  
  9869. altstf:    ora    #$30        ;[23] Make the character printable
  9870.     cmp    #$3A        ;[23] If it is less than '9'
  9871.     bcc    altdep        ;[23]    then go depisit the character
  9872.     adc    #6        ;[23] Put the character in the proper range
  9873. altdep:
  9874. ;---
  9875. ;    sta    fcb1,y        ;[23] Stuff the character
  9876. ;---
  9877.     sta    path,y
  9878.     iny            ; bump idx
  9879.     rts            ;[23]    and return
  9880.  
  9881. ;
  9882. ;    Locent -  Try to find a file 
  9883. ;
  9884.  
  9885. locent:    jsr    bldprm        ;[23]
  9886.     ldx    #dskchan    ; [jrd] disk iocb please
  9887.     lda    #primfn\    ; [jrd] file name lo
  9888.     ldy    #primfn^    ; [jrd] file name hi
  9889.     jsr    opencin        ; [jrd] try to open it
  9890. ;
  9891. ;    jsr    rddsk          ;[23] Get disk status
  9892. ;    cmp    #00        ;[23] Is it 0?
  9893.     cpy    #SUCCES        ; open succeed?
  9894.     bne      locok         ;[23] No, file doesn't exist
  9895. ;    lda    #8        ;[23] Fle exists, close the file
  9896. ;    jsr    close        ;[23]    commodore    ...
  9897.     jsr    closec        ; and atari version ...    
  9898.     jmp    rskp        ;[23] Return with a skip!
  9899. locok:
  9900. ;    lda    #8        ;[23] File doesn't exist, close the file
  9901. ;    jsr    close        ;[23]        ...
  9902.     jsr    closec        ; [jrd] just do this on atari
  9903.     rts            ;[23] Return
  9904.  
  9905. ;
  9906. ;    Bldprm - Build the primary filename
  9907. ;
  9908.  
  9909. bldprm:
  9910. ;
  9911. ;    we assume pathnames are all merged here, and the result is 
  9912. ;    in path
  9913. ;
  9914.     lda    #path\        ; point at the pathname struct
  9915.     sta    pndptr
  9916.     lda    #path^
  9917.     sta    pndptr+1
  9918.     ldx    #primfn\    ; and point at the string
  9919.     ldy    #primfn^
  9920.     jsr    pn2str        ; convert pathname to string
  9921. ;
  9922.     rts            ;[23] Return
  9923.  
  9924. ;
  9925. ;    Parsefcb:    parse-pathname of fcb1, and merge with
  9926. ;            default, leaving result in path.
  9927. ;            Intended to be used prior to bldprm.
  9928. ;
  9929. parsefcb:
  9930.     lda    #path\        ; point at the pathname struct
  9931.     sta    pndptr
  9932.     lda    #path^
  9933.     sta    pndptr+1
  9934.     ldx    #fcb1\        ; and point at the string
  9935.     ldy    #fcb1^
  9936. parsefxy:
  9937.     jsr    parsepn        ; parse fcb1 -> path
  9938.     lda    #defpath\    ; make sure
  9939.     sta    pnddef        ;  default is set
  9940.     lda    #defpath^    ;
  9941.     sta    pnddef+1    ;
  9942.     jsr    pnmerge        ; merge default -> pathname
  9943.     rts            ; done
  9944.  
  9945. ;
  9946. ;
  9947. ;    parseifn:    parse and merge the init file pathname,
  9948. ;            leaving the result in path.
  9949. ;
  9950. parseifn:
  9951.     lda    #path\        ; point at the pathname struct
  9952.     sta    pndptr
  9953.     lda    #path^
  9954.     sta    pndptr+1
  9955.     ldx    #inifil\    ; init file pathname lo
  9956.     ldy    #inifil^
  9957.     jmp    parsefxy    ; jump into middle of parsefcb
  9958.  
  9959.  
  9960. ;
  9961. ;    Closef - closes the file which was open for transfer. 
  9962. ;
  9963.  
  9964. closef:
  9965.     jsr    closers        ; [jrd] make sure rs port's closed
  9966.     ldx    #dskchan
  9967.     jsr    closec
  9968.     lda    #true        ; the close worked, return true
  9969.     rts            ;        ...
  9970.  
  9971. ;
  9972. ;    Dirst - Get a disk directory
  9973. ;
  9974. dirhrld1: .byte    "  File        Sectors",ATEOL,0
  9975. dirhrld2: .byte    " ------------ -------",ATEOL,0
  9976. direlck: .byte    "  locked",0
  9977. dirst:    
  9978.     lda    #0        ; allow default of *.*
  9979.     jsr    enterpn        ;  and get a pathname
  9980.     jsr    prcfm        ; confirm it
  9981.     jsr    parsefcb    ; parse and merge the resultant filespec
  9982.     jsr    closers        ; make sure comm port's closed
  9983. ;    jsr    prcrlf        ; cosmetics...
  9984. ;----
  9985. ;    jsr    parsefcb    ; [jrd] parse the pathname
  9986.     jsr    bldprm        ; [jrd] reformat it
  9987.     lda    #primfn\
  9988.     ldy    #primfn^
  9989. ;----
  9990.     ldx    #dirhrld1\    ; print the directory
  9991.     ldy    #dirhrld1^    ;  herald first line
  9992.     jsr    prstr
  9993.     ldx    #dirhrld2\    ; print the directory
  9994.     ldy    #dirhrld2^    ;  herald second line
  9995.     jsr    prstr
  9996.     jsr    dirini
  9997. xdir1:
  9998.     jsr    dirnxt        ; get one
  9999.     bcs    xdir9        ; failed
  10000.     lda    #dirpath\    ; point at the pathname struct
  10001.     sta    pndptr
  10002.     lda    #dirpath^
  10003.     sta    pndptr+1
  10004.     ldx    #primfn\    ; and point at the string
  10005.     ldy    #primfn^
  10006.     jsr    pn2str        ; convert pathname to string
  10007.     lda    #space
  10008.     jsr    cout        ; print a leading space
  10009.     ldx    #primfn\    ; get the resultant pathname
  10010.     ldy    #primfn^    ; and print that
  10011.     jsr    pstreol
  10012.     lda    #15        ; tab to col 15
  10013.     sta    COLCRS        ;  for the sector count
  10014.     lda    #space        ; zap temp slot to space
  10015.     sta    strptr        ; just a temp...
  10016.     ldy    #0        ; idx
  10017. xdir2:
  10018.     sty    strptr+1
  10019.     lda    dirsect,y    ; get a byte
  10020.     cmp    #'0        ; a zero?
  10021.     beq    xdir3        ; yup, alter it maybe
  10022.     pha            ; save it for a bit
  10023.     lda    #'0        ; make the altered char a 0
  10024.     sta    strptr
  10025.     pla            ; get it back
  10026.     jmp    xdir4
  10027. xdir3:
  10028.     lda    strptr        ; get the altered version
  10029. xdir4:
  10030.     jsr    cout        ; print it
  10031.     ldy    strptr+1    ; get idx
  10032.     iny            ; bump
  10033.     cpy    #3        ; done 3 yet?
  10034.     bcc    xdir2        ; nope, go on
  10035. ;    
  10036. ; see if the file's locked
  10037. ;
  10038.     lda    dirplck        ; get the flag byte
  10039.     cmp    #space
  10040.     beq    xdir5        ; space, so not locked
  10041.     ldx    #direlck\    ; point at the string
  10042.     ldy    #direlck^
  10043.     jsr    prstr        ; and print it
  10044. xdir5:
  10045.     jsr    prcrlf        ; end line
  10046.     jmp    xdir1        ; and go back for more
  10047. xdir9:
  10048.     ldx    #primfn\    ; free space string in primfn
  10049.     ldy    #primfn^
  10050.     jsr    pstreol
  10051.     jsr    dircls
  10052.     jmp    kermit
  10053. ;-------
  10054. ;
  10055. ;    ldx    #dskchan
  10056. ;    jsr    opencdir    ; get a dir list
  10057. ;    cpy    #SUCCES        ; winning?
  10058. ;    beq    dirs1        ; yup, go print it out
  10059. ;    jmp    opfail        ; go display the error
  10060. ;dirs1:
  10061. ;    ldx    #dskchan
  10062. ;    jsr    chrin
  10063. ;    cpy    #EOFERR        ; eof?
  10064. ;    beq    dirs9
  10065. ;    cpy    #SUCCES        ; ok?
  10066. ;    beq    dirs2
  10067. ;    jmp    opfail        ; go print the error
  10068. ;dirs2:
  10069. ;;    jsr    sputch        ; put it out
  10070. ;    jsr    scrput
  10071. ;    jmp    dirs1
  10072. ;dirs9:
  10073. ;    ldx    #dskchan
  10074. ;    jsr    closec
  10075. ;    jmp    kermit        ; return to command loop
  10076.  
  10077. ;
  10078. ;    Enterpn:    Util used in rename, delete.  Enter a string
  10079. ;            from command line, parse it into path.
  10080. ;    Input:    A zero ->     default of *.*
  10081. ;          non-zero -> no default allowed
  10082. ;            Returns carry set if ng, clear otherwise
  10083. ;
  10084. enterpn:
  10085.     pha            ; save default flag
  10086.     ldx    #wildfn\    ; [jrd] default is all wild
  10087.     stx    cmdptr        ; set default pointer
  10088.     ldy    #wildfn^    ; ...
  10089.     sty    cmdptr+1    ; ...
  10090.     lda    #3        ; length of wildfn
  10091.     jsr    cmd2fcb        ; copy it in ahead of time.  shouldn't
  10092.                 ;  be necessary, but cp appears to return
  10093.                 ;  no data even though default supplied
  10094.     lda    #kerehr\    ;[40] Point to the extra help commands
  10095.     sta    cmehpt        ;[40]        ...
  10096.     lda    #kerehr^    ;[40]        ...
  10097.     sta    cmehpt+1    ;[40]        ..
  10098.     ldx    #mxfnl        ;[40] Longest length a disk string may be
  10099.     pla            ; get default flag back
  10100.     cmp    #0        ; do we default to *.*?
  10101.     bne    enterpn1    ; nope, must enter one
  10102.     ldy    #cmfehf!cmfdff
  10103. ;    ldy    #cmfdff        ;[40] Tell Comnd about extra help and def
  10104.     jmp    enterpn2    ; go enter it
  10105. enterpn1:
  10106.     ldy    #cmfehf        ; no flags, must enter one
  10107. enterpn2:
  10108.     lda    #cmifi        ;[40] Load opcode for parsing file
  10109.     jsr    comnd        ;[40] Call Comnd routine
  10110.      jmp    enterpn9    ;[40] Continue, no string parsed
  10111.     jsr    cmd2fcb        ; [jrd] get it into fcb1
  10112.     ldx    #fcb1\        ; parse it
  10113.     ldy    #fcb1^
  10114.     jsr    parsepn
  10115.     clc
  10116.     rts
  10117. enterpn9:
  10118.     sec
  10119.     rts
  10120.  
  10121. ;
  10122. ;    Rename:        Rename file(s).
  10123. ;            Expects user to enter two filespecs; which
  10124. ;            may be wildcarded.  The two names are run thru
  10125. ;            the pathname parser and merger, checked for 
  10126. ;            reasonableness, and formatted as 
  10127. ;            "Dn:NAME.1,NAME.2" for the FMS's renamer.
  10128. ;
  10129. rename:
  10130.     lda    #$FF        ; no default, must enter one
  10131.     jsr    enterpn        ; get a pathname from cmd line
  10132.     bcs    rename9        ; oops!  bad/missing pathname
  10133.     jsr    parsefcb    ; [jrd] parse and merge it
  10134.     jsr    bldprm        ; [jrd] format it to output buf
  10135. ;
  10136. ;    now get the second one
  10137. ;
  10138.     lda    #$FF        ; no default, must enter one
  10139.     jsr    enterpn        ; enter a second pathname
  10140.     bcs    rename9        ; ng, quit
  10141.     jsr    prcfm        ; confirm the whole command
  10142. ;
  10143. ; zzz check to make sure no device was specified here???
  10144. ;
  10145. ;    now must append this pathname to the one already in
  10146. ;    primfn.  find the ATEOL, stuff a comma in its place, and
  10147. ;    compute the address of the byte following, then format
  10148. ;    pathname into there.
  10149. ;
  10150.     ldy    #0        ;start at beginning
  10151.     lda    #ATEOL        ; get an eol
  10152. rename1:
  10153.     cmp    primfn,y    ; this it?
  10154.     beq    rename2        ; yup, go fix it
  10155.     iny            ; try next
  10156.     bne    rename1
  10157. rename2:
  10158.     lda    #',        ; get a comma
  10159.     sta    primfn,y    ; stuff in in
  10160.     iny            ; bump idx
  10161.     tya            ; now compute buf addr for
  10162.     clc            ;  second pathname
  10163.     adc    #primfn\    ; add lo byte to offset
  10164.     tax            ; save result in x
  10165.     lda    #primfn^    ; get hi byte
  10166.     adc    #0        ; add carry
  10167.     tay            ; into y, top byte of addr
  10168.     jsr    pn2str        ; convert it to string
  10169. ;
  10170.     jsr    closers        ; make sure comm port's closed
  10171.     ldx    #dskchan
  10172.     lda    #RENAME        ; rename command code
  10173.     sta    ICCOM,X        ; store into iocb
  10174.     jsr    iozax        ; zap aux1, aux2
  10175.     lda    #primfn\    ; set up for call to CIO
  10176.     ldy    #primfn^
  10177.     jsr    iosba        ; set buf addr in iosb
  10178.     jsr    CIOV        ; do the rename
  10179. ;
  10180. ; check status...
  10181. ;
  10182.     cpy    #SUCCES        ; ok?
  10183.     beq    rename8        ; yup, go back
  10184.     jmp    opfail        ; nope, go gripe about the error
  10185. rename8:
  10186. ;    jmp    kermit        ;[40] Go back for more commands
  10187. rename9:            ; zzz maybe some kind of error?
  10188.     jmp    kermit
  10189.  
  10190. ;
  10191. ;    Erase:        Delete files(s) on the default disk.
  10192. ;            prompts for a pathname, which may be wildcarded,
  10193. ;            and does the FMS delete op on it.
  10194. erase:
  10195.     lda    #$FF        ; no default, must enter one
  10196.     jsr    enterpn        ; get a pathname from cmd line
  10197.     bcs    erase9        ; no good, stop
  10198.     jsr    prcfm        ; confirm
  10199.     jsr    parsefcb    ; [jrd] parse and merge it
  10200.     jsr    bldprm        ; [jrd] format it to output buf
  10201.     jsr    closers        ; make sure comm port's closed
  10202. ;
  10203.     ldx    #dskchan
  10204.     lda    #DELETE        ; rename command code
  10205.     sta    ICCOM,X        ; store into iocb
  10206.     jsr    iozax        ; zap aux1, aux2
  10207.     lda    #primfn\    ; set up for call to CIO
  10208.     ldy    #primfn^
  10209.     jsr    iosba        ; set buf addr in iosb
  10210.     jsr    CIOV        ; do the rename
  10211. ;
  10212. ; check status...
  10213. ;
  10214.     cpy    #SUCCES        ; ok?
  10215.     beq    erase8        ; yup, go back
  10216.     jmp    opfail        ; nope, go gripe about the error
  10217. erase8:
  10218. ;    jmp    kermit        ;[40] Go back for more commands
  10219. erase9:                ; zzz maybe some kind of error?
  10220.     jmp    kermit
  10221.  
  10222. ;
  10223. ;    Bufill - takes characters from the file, does any neccesary quoting,
  10224. ;    and then puts them in the packet data buffer. It returns the size
  10225. ;    of the data in the AC. If the size is zero and it hit end-of-file,
  10226. ;    it turns on eofinp.
  10227. ;
  10228.  
  10229. bufill:    lda    #0        ; Zero
  10230.     sta    datind        ;    the buffer index
  10231. bufil1:    jsr    fgetc        ; Get a character from the file
  10232.      jmp    bffchk        ; Go check for actual end-of-file
  10233.     sta    kerchr        ; Got a character, save it
  10234.     tax            ;[31] and a copy to X
  10235.     lda    filmod        ;[DD] Check if conversion necessary
  10236.     cmp    #ftatas        ;[DD] Is it ATTASCII?
  10237.     bne    bufcv1        ;[DD] No
  10238. ;
  10239. ;    lda    at2as,x        ;[31] Get ASCII equivalent
  10240. ;
  10241.     ldx    #xat2as\    ; point at xlate tab
  10242.     ldy    #xat2as^
  10243.     lda    kerchr        ; and get char to xlate
  10244.     jsr    xlate
  10245. ;
  10246.     sta    kerchr        ;
  10247. ;    jmp    bufcv2        ;[jrd] no need if 'script' not there
  10248. bufcv1:
  10249. ;    cmp    #3        ;[DD] Is it Speedscript?
  10250. ;    bne    bufcv2        ;[DD] No
  10251. ;    jsr    cvs2a        ;[DD] Conv. Speedscript to ASCII
  10252. bufcv2:
  10253. bufceb: lda    ebqmod        ; Check if 8-bit quoting is on
  10254.     cmp    #on        ;        ...
  10255.     beq    bufil2        ; If it is, see if we have to use it
  10256.     jmp    bffqc        ; Otherwise, check normal quoting only
  10257. bufil2: lda    kerchr        ; Get the character
  10258.     and    #$80        ; Mask everything off but H.O. bit
  10259.     beq    bffqc        ; H.O. bit was not on, so continue
  10260.     lda    sebq        ; H.O. bit was on, get 8-bit quote
  10261.     ldy    datind        ; Set up the data index
  10262.     sta    (kerbf1),y    ; Stuff the quote character in buffer
  10263.     iny            ; Up the data index
  10264.     sty    datind        ; And save it
  10265.     lda    kerchr        ; Get the original character saved
  10266.     and    #$7F        ; Shut H.O. bit, we don't need it
  10267.     sta    kerchr        ;        ...
  10268. bffqc:  lda    kerchr        ; Fetch the character
  10269.     and    #$7F        ; When checking for quoting, use only 7 bits
  10270. bffqc0: cmp    #sp        ; Is the character less than a space?
  10271.     bpl    bffqc1        ; If not, try next possibility
  10272.     ldx    filmod        ; Get the file-type
  10273.     cpx    #ftbin        ; [jrd] IF >= binary
  10274.     bcs    bffctl        ; If it is not text, ignore <cr> problem
  10275.     cmp    #cr        ; Do we have a <cr> here?
  10276.     bne    bffctl        ; Nope, continue processing
  10277.     ldx    #on        ; Set flag to add a <lf> next time through
  10278.     stx    addlf        ;        ...
  10279.     jmp    bffctl        ; This has to be controlified
  10280. bffqc1: cmp    #del        ; Is the character a del?
  10281.     bne    bffqc2        ; If not, try something else
  10282.     jmp    bffctl        ; Controlify it
  10283. bffqc2: cmp    squote        ; Is it the quote character?
  10284.     bne    bffqc3        ; If not, continue trying
  10285.     jmp    bffstq        ; It was, go stuff a quote in buffer
  10286. bffqc3: lda    ebqmod        ; Is 8-bit quoting turned on?
  10287.     cmp    #on        ;        ...
  10288.     bne    bffstf        ; If not, skip this junk
  10289.     lda    kerchr        ;    otherwise, check for 8-bit quote char.
  10290.     cmp    sebq        ; Is it an 8-bit quote?
  10291.     bne    bffstf        ; Nope, just stuff the character itself
  10292.     jmp    bffstq        ; Go stuff a quote in the buffer
  10293. bffctl: lda    kerchr        ; Get original character back
  10294.     eor    #$40        ; Ctl(AC)
  10295.     sta    kerchr        ; Save the character again
  10296. bffstq: lda    squote        ; Get the quote character
  10297.     ldy    datind        ;    and the index into the buffer
  10298.     sta    (kerbf1),y    ; Store it in the next location
  10299.     iny            ; Up the data index once
  10300.     sty    datind        ; Save the index again
  10301. bffstf: inc    schr        ; Increment the data character count
  10302.     bne    bffsdc        ;        ...
  10303.     inc    schr+1        ;        ...
  10304. bffsdc: lda    kerchr        ; Get the saved character
  10305.     ldy    datind        ;    and the data index
  10306.     sta    (kerbf1),y    ; This is the actual char we must store
  10307.     iny            ; Increment the index
  10308.     sty    datind        ; And resave it
  10309.     tya            ; Take this index, put it in AC
  10310.     clc            ; Clear carry for addition
  10311.     adc    #6        ; Adjust it so we can see if it
  10312.     cmp    spsiz        ;    is >= spsiz-6
  10313.     bpl    bffret        ; If it is, go return
  10314.     jmp    bufil1        ; Otherwise, go get more characters
  10315. bffret: lda    datind        ; Get the index, that will be the size
  10316.     rts            ; Return with the buffer size in AC
  10317. bffchk:    lda    datind        ;[21] Get the data index
  10318.     cmp    #0        ;[21] Is it zero?
  10319.     bne    bffne        ;[21] Nope, just return
  10320.     tay            ;[21] Yes, this means the entire file has
  10321.     lda    #true        ;     been transmitted so turn on
  10322.     sta    eofinp        ;    the eofinp flag
  10323.     tya            ;[21] Get back the size of zero
  10324. bffne:  rts            ; Return
  10325.  
  10326. ;
  10327. ;    Bufemp - takes a full data buffer, handles all quoting transforms
  10328. ;    and writes the reconstructed data out to the file using calls to
  10329. ;    FPUTC.
  10330. ;
  10331.  
  10332. bufemp:    lda    #0        ; Zero
  10333.     sta    datind        ;    the data index
  10334. bfetol: lda    datind        ; Get the data index
  10335.     cmp    pdlen        ; Is it >= the packet data length?
  10336.     bmi    bfemor        ; No, there is more to come
  10337.     lda    #true        ; [jrd] say we win
  10338.     rts            ; Yes, we emptied the buffer, return
  10339. bfemor: lda    #false        ; Reset the H.O.-bit-on flag to false
  10340.     sta    chebo        ;        ...
  10341.     ldy    datind        ; Get the current buffer index
  10342.     lda    (kerbf1),y    ; Fetch the character in that position
  10343.     sta    kerchr        ; Save it for the moment
  10344.     cmp    rebq        ; Is it the 8-bit quote?
  10345.     bne    bfeqc        ; No, go check for normal quoting
  10346.     lda    ebqmod        ; Is 8-bit quoting on?
  10347.     cmp    #on        ;        ...
  10348.     bne    bfeout        ; No quoting at all, place char in file
  10349.     lda    #true        ; Set H.O.-bit-on flag to true
  10350.     sta    chebo        ;        ...
  10351.     inc    datind        ; Increment the data index
  10352.     ldy    datind        ; Fetch it into Y
  10353.     lda    (kerbf1),y    ; Get the next character from buffer
  10354.     sta    kerchr        ; Save it
  10355. bfeqc:  cmp    rquote        ; Is it the normal quote character
  10356.     bne    bfeceb        ; No, pass this stuff up
  10357.     inc    datind        ; Increment the data index
  10358.     ldy    datind        ;    and fetch it in the Y-reg
  10359.     lda    (kerbf1),y    ; Get the next character from buffer
  10360.     sta    kerchr        ; Save it
  10361.     and    #$7F        ; Check only 7 bits for quote
  10362.     cmp    rquote        ; Were we quoting a quote?
  10363.     beq    bfeceb        ; Yes, nothing has to be done
  10364.     cmp    rebq        ; Check for eight-bit quote char as well
  10365.     beq    bfeceb        ; Skip the character adjustment
  10366.     lda    kerchr        ; Fetch back the original character
  10367.     eor    #$40        ; No, so controlify this again
  10368.     sta    kerchr        ; Resave it
  10369. bfeceb: lda    chebo        ; Is the H.O.-bit-on flag lit?
  10370.     cmp    #true        ;        ...
  10371.     bne    bfeout        ; Just output the character to the file
  10372.     lda    kerchr        ; Fetch the character
  10373.     ora    #$80        ; Light up the H.O. bit
  10374.     sta    kerchr        ; Resave it
  10375. bfeout: lda    filmod        ; Check if this is a text file
  10376.     cmp    #ftbin        ; [jrd] Filmod < 2 ?
  10377.     bcs    bfefpc        ; If not, continue normal processing
  10378.     lda    kerchr        ; Get a copy of the character
  10379.     and    #$7F        ; Make sure we test L.O. 7-bits only
  10380.     tax            ;[31] Put a copy in X
  10381.     cmp    #cr        ; Do we have a <cr>?
  10382.     bne    bfeclf        ; No, then check for <lf>
  10383.     lda    #on        ; Yes, set the 'Delete <lf>' flag
  10384.     sta    dellf        ;        ...
  10385.     jmp    bfefpc        ; And then continue
  10386. bfeclf: cmp    #lf        ; Do we have a <lf>?
  10387.     bne    bfenlf        ; Nope, We must go shut the Dellf flag.
  10388.     lda    dellf        ; We have a <lf>, is the flag on?
  10389.     cmp    #on        ;        ...
  10390.     bne    bfefpc        ; If not, continue normally
  10391.     lda    #off        ; Flag is on, <lf> follows <cr>, ignore it
  10392.     sta    dellf        ; Start by zeroing flag
  10393.     jmp    bfeou1        ; Now go to end of loop
  10394. bfenlf: lda    #off        ; Zero Dellf
  10395.     sta    dellf        ;        ...
  10396. bfefpc: lda    filmod        ;[DD] Get file type 
  10397.     cmp    #ftatas        ;[DD] Check ATTASCII
  10398.     bne    bfefp2        ;[DD]
  10399. ;
  10400. ;    lda    as2at,x        ;[31] Get ATASCII equivalent
  10401. ;
  10402.     ldx    #xas2at\    ; point at xlate tab
  10403.     ldy    #xas2at^
  10404.     lda    kerchr
  10405.     jsr    xlate
  10406. ;
  10407.     sta    kerchr        ;[31]
  10408. ;    jmp    bfefp3        ;[jrd] no need if no 'script'
  10409. bfefp2:
  10410. ;    cmp    #3        ;[DD] Check Speedscript
  10411. ;    bne    bfefp3        ;[DD]
  10412. ;    jsr    cva2s        ;[DD] Convert ASCII to Speedscript
  10413. bfefp3: lda    kerchr        ; Get the character once more
  10414.     jsr    fputc        ; Go write it to the file
  10415.      jmp    bfeerr        ; Check out the error
  10416.     inc    rchr        ; Increment the 'data characters receive' count
  10417.     bne    bfeou1        ;        ...
  10418.     inc    rchr+1        ;        ...
  10419. bfeou1: inc    datind        ; Up the buffer index once
  10420.     jmp    bfetol        ; Return to the top of the loop
  10421.  
  10422. bfeerr:
  10423. ;    and    #$7F        ; Shut off H.O. bit
  10424. ;    sta    errcod        ; Store the error code where it belongs
  10425. ; fputc stored the error code
  10426.     lda    #false        ; Indicate failure
  10427.     rts            ;    and return
  10428.  
  10429.  
  10430. ;
  10431. ;    Getnfl - returns the next filename to be transferred, in fcb1.
  10432. ;    Returns EOF if out of files
  10433. ;
  10434.  
  10435. getnfl:
  10436. ;
  10437. ; wildcard support added here by jrd
  10438. ;
  10439.     jsr    ssfnxt        ; set up next file name
  10440.     bcs    getnf1        ; cs means no more
  10441.     lda    #false        ; say we're not at end of file list
  10442.     rts            ; and return
  10443. getnf1:
  10444.     lda    #eof        ; No more files (return eof)
  10445.     rts
  10446.  
  10447. ;
  10448. ;    Getfil - gets the filename from the receive command if one was
  10449. ;    parsed. Otherwise, it returns the name in the file header packet.
  10450. ;
  10451.  
  10452. getfil: lda    usehdr        ; Get the use-header switch
  10453.     cmp    #on        ; Is it on
  10454.     bne    getfl1        ; If not, keep what we have in the fcb
  10455.     jsr    clrfcb        ;        ...
  10456.     ldy    #0        ; Initialize the y reg
  10457. ;    lda    pdlen        ; Copy the packet data length
  10458. ;    sec            ; Now subtract off the overhead
  10459. ;    sbc    #3        ;        ...
  10460. ;    sta    kwrk02        ;    into a work area
  10461. getfl0: lda    (kerbf1),y    ; Get a character from the packet buffer
  10462.     sta    fcb1,y        ; Stuff it in the fcb
  10463.     iny            ; Up the index once
  10464.     cpy    pdlen        ; Are we finished?
  10465.     bmi    getfl0        ; Nope, go do next byte
  10466. ;    lda    #0        ;
  10467. ;    sta    fcb1,y        ; Nul at end
  10468. getfl1: rts
  10469.  
  10470.  
  10471. ;
  10472. ;    Fgetc - returns the next character from the file in the AC. It
  10473. ;    handles all of the low level disk I/O. Whenever it successfully
  10474. ;    gets a character, it skips on return. If it does not get a
  10475. ;    character, it doesn't skip.
  10476. ;
  10477.  
  10478. fgetc:    lda    addlf        ; Get the 'add a lf' flag
  10479.     cmp    #on        ; Is it on?
  10480.     bne    fgetc1        ; No, continue with normal processing
  10481.     lda    #off        ; Zero the flag first
  10482.     sta    addlf        ;        ...
  10483.     lda    #lf        ; Get a <lf>
  10484.     jmp    fgtexi        ;   and return that as the next character
  10485. fgetc1: lda    eodind        ;[DD] Check end-of-data flag
  10486.     cmp    #off        ;[21] Is it on?
  10487.     beq    fgtc2a        ;[DD][21] No, get next character
  10488.     jmp    fgteof        ;[21] Yes, no data to read
  10489. fgtc2a:
  10490.     ldx    #dskchan    ; [jrd] Disk iocb please
  10491.     jsr    chrin        ; [jrd] get one byte please
  10492.     pha            ;[DD] Save it
  10493.     cpy    #SUCCES        ; [jrd] get one?
  10494.     beq    fgtgnc        ; Return
  10495.     lda    #1        ; [jrd] set eodind; any error -> eof
  10496.                 ;  zzz put some code in here to bitch
  10497.                 ;  about errors other than eof
  10498.     sta    eodind        ; say end of data for next time
  10499.     cpy    #3        ; EOF lookahead?
  10500.     beq    fgtgn0        ; yup, close and return it
  10501.     cpy    #EOFERR        ; a real eof?
  10502.     beq    fgteof0        ; yup, close it and don't return
  10503. ; debugging
  10504. ;    tya            ; save code for a sec
  10505. ;    pha
  10506. ;    ldx    #fgtdbg\
  10507. ;    ldy    #fgtdbg^
  10508. ;    jsr    prstr
  10509. ;    pla
  10510. ;    jsr    prbyte
  10511. ;    jsr    prcrlf
  10512. ;---
  10513.     tya            ; get code into a
  10514.     jsr    logdoserr
  10515.     lda    #errfde        ; say we got an io error
  10516.     sta    errcod
  10517. ;
  10518. ; what a crock! there's no way to return an error indication from this
  10519. ; thing.  Give up.  Print the error here, and go thru fatal error vect
  10520. ; to reset stack
  10521. ;
  10522.     jsr    prerms
  10523.     jmp    fatal
  10524. ;
  10525. fgtgn0:    jsr    closef        ;[DD] Eof so close but return
  10526. fgtgnc:    pla            ; Get back character
  10527. fgtgn1:
  10528. ; obsolete
  10529. ;    ldx    fbsize        ; Get the file-byte-size
  10530. ;    cpx    #fbsbit        ; Is it seven-bit?
  10531. ;    bne    fgtexi        ; If not, leave with character intact
  10532. ;    and    #$7f        ; Shut off the H.O. byte
  10533. fgtexi:    jmp    rskp          ; Return skip
  10534. ;
  10535. fgteof0:
  10536.     pla            ; [jrd, v3.6] pop dead char, to fix stack
  10537. fgteof:    jsr    closef        ; close the file
  10538.     lda    #0        ; Return null
  10539.     rts            ;        ... 
  10540. ;
  10541. ;fgtcan: jmp    fatal         ; Just go give an error
  10542. ;
  10543. ;fgtdbg:    .byte    "Fgetc error ",0
  10544. ;
  10545. ;
  10546. ;    Fputc - takes a character passed to it in the AC and writes it
  10547. ;    to the file being transferred in.
  10548. ;
  10549.  
  10550. fputc:
  10551.     ldx    #dskchan    ; [jrd] disk iocb please
  10552.     jsr    chrout        ;[DD] Write it to disk
  10553. ;    jsr    readst        ;[DD] Check for errors
  10554. ;    cmp    #00        ;[DD] Do we really need this?
  10555.     cpy    #SUCCES        ; [jrd] io succeed?
  10556.     beq    fputex        ;[DD] No error
  10557. ;    sta    errcod      ;[DD] If error
  10558. ;---
  10559. ;    sty    errcod
  10560. ;    ldx    #erms0a\    ;[DD] Get the address of the error message
  10561. ;    ldy    #erms0a^    ;[DD]        ...
  10562. ;    jsr    prstr       ;[DD] Print message
  10563. ;    lda    errcod        ;[DD]     and status
  10564. ;    jsr    prbyte      ;[DD]        ...
  10565. ;    jsr    prcrlf
  10566. ;---
  10567.     tya
  10568.     jsr    logdoserr    ; format the code into the msg
  10569.     lda    #errfde        ; say what we got
  10570.     sta    errcod
  10571. ;---
  10572. ; ???    jmp    fatal        ;[DD] Blow up
  10573.     rts            ; [jrd] return without skip, ie error
  10574. fputex: lda    #00        ; Return null
  10575.     jmp    rskp          ;     with a skip!
  10576.  
  10577. .SBTTL    Save and Restore Parameters
  10578.  
  10579. ;    The following routines will save and restore kermit 
  10580. ;    parameters in a file named 'KERMIT.INI'. Eventually 
  10581. ;    will add ability to specify file for save/restore.
  10582. ;
  10583.  
  10584. ;
  10585. ;    Savst - Save parameters
  10586. ;
  10587. ;    Registers Destroyed: A,X,Y
  10588. ;
  10589.  
  10590. savst:    jsr    closers
  10591.     jsr    prcfm        ;[47] Parse and print a confirm
  10592.     ldx    #inifil\    ; [jrd] point at file name
  10593.     ldy    #inifil^    ;  ...
  10594.     jsr    parseifn    ; parse init file pathname
  10595.     jsr    bldprm        ; [jrd] reformat it
  10596.     lda    #primfn\
  10597.     ldy    #primfn^
  10598.     ldx    #dskchan
  10599.     jsr    opencout    ; [jrd] try to open it
  10600.     cpy    #SUCCES        ; winning?
  10601.     beq    savst1        ; yup. go ahead and save
  10602.     jmp    opfail        ; nope, say why
  10603. savst1:
  10604.     ldy    #0        ;[47] Start with the escape character
  10605. savlop:    
  10606.     sty    strptr        ; [jrd] temp
  10607.     lda    escp,y        ;[47]        ...
  10608.     ldx    #dskchan
  10609.     jsr    chrout        ;[47] Write it to disk
  10610. ; zzz check status
  10611.     ldy    strptr        ; get idx back
  10612.     iny            ;[47]
  10613.     cpy    #quote+1-escp    ;[47] Are we at the end?
  10614.     bne    savlop        ;[47] No, do the next parameter
  10615.     jsr    closef
  10616.     jmp    kermit        ;[47]    and parse for more commands
  10617.  
  10618. ;
  10619. ;    Restst - Restore parameters
  10620. ;
  10621.  
  10622. restst:    jsr    prcfm        ;[47] Parse and print a confirm
  10623.     jsr    restin        ;[47] Go restore the parameters
  10624.     jmp    kermit        ;[47] Failed, restart kermit
  10625.  
  10626. restin:
  10627.     jsr    closers        ; make sure comm port's closed
  10628.     ldx    #inifil\    ; [jrd] point at file name
  10629.     ldy    #inifil^    ;  ...
  10630.     jsr    parseifn    ; parse init file pathname
  10631.     jsr    bldprm        ; [jrd] reformat it
  10632.     lda    #primfn\
  10633.     ldy    #primfn^
  10634.     ldx    #dskchan
  10635.     jsr    opencin        ; [jrd] try to open it
  10636.     cpy    #SUCCES        ; winning?
  10637. ; zzz check for file not found here
  10638.     bne    rsterr        ; nope, give up
  10639.     ldy    #0        ;[47] Start index at escp
  10640. rstlop:    sty    savey        ;[47] Save the current index
  10641.     ldx    #dskchan    ; [jrd] point at disk IOCB
  10642.     jsr    chrin        ;[47] Get a byte from the disk
  10643. ; zzz save status somewhere?
  10644.     ldy    savey        ;[47] Restore the index
  10645.     sta    escp,y        ;[47] Store the character away
  10646.     iny            ;[47] Increment the index
  10647.     cpy    #quote+1-escp    ;[47] Are we at the end of the parameter list?
  10648.     bne    rstlop        ;[47] No, get next parameter
  10649. ;    lda    scrtype        ; check if the new screen driver exists
  10650. ;    jsr    scrtst        ; [jrd] no need, they're all here
  10651. ;    bcc    rstlop1        ; no it doesnt
  10652. rsterr:    lda    #scr80        ; default to 80-columns
  10653.     sta    conscrt
  10654. rstlop1: 
  10655. ; not til connect time
  10656. ;     jsr    scrent        ; initilize the new screen package
  10657. ;    lda    #8        ;[47] Close the init file
  10658. ;    jsr    close        ;[47]        ...
  10659.     ldx    #dskchan
  10660.     jsr    closec
  10661.     rts            ; all done
  10662.  
  10663. inifil:    .byte    "KERMIT.INI",ATEOL    ; init file, eol terminated
  10664. ;
  10665. .SBTTL    Utility routines
  10666.  
  10667. ;
  10668. ;    The following routines are short low-level routines which help
  10669. ;    shorten the code and make it more readable
  10670. ;
  10671. ;
  10672. ;    Incn - increment the packet sequence number expected by this
  10673. ;    Kermit. Then take that number Mod $3f.
  10674. ;
  10675.  
  10676. incn:    pha            ; Save AC
  10677.     lda    n        ; Get the packet number
  10678.     clc            ; Clear the carry flag for the add
  10679.     adc    #1        ; Up the number by one
  10680.     and    #$3F        ; Do this Mod $3f!
  10681.     sta    n        ; Stuff the number where it belongs
  10682.     clc            ; Clear carry again
  10683.     lda    tpak        ; Increment lo byte
  10684.     adc    #1        ;    total packet count
  10685.     sta    tpak        ;        ...
  10686.     lda    tpak+1        ; Do H.O. byte
  10687.     adc    #0        ;        ...
  10688.     sta    tpak+1        ;        ...
  10689.     pla            ; Restore the AC
  10690.     rts            ;    and return
  10691.  
  10692. ;
  10693. ;    Prcerp - Process error packet. Moves the Remote Kermit error
  10694. ;    text into a save area, notes that there was an error received
  10695. ;    from the remote Kermit in Errcod (set H.O. bit), and displays
  10696. ;    the text on the screen.
  10697. ;
  10698.  
  10699. prcerp:    lda    ptype        ; Reload the packet type
  10700.     cmp    #'E        ; Is it an error packet?
  10701.     beq    prcer1        ; Yes, continue processing
  10702.     rts            ; No, return
  10703. prcer1:    lda    #pdbuf\        ; Set up from-address
  10704.     sta    kerfrm        ;        ...
  10705.     lda    #pdbuf^        ;        ...
  10706.     sta    kerfrm+1    ;        ...
  10707.     lda    #errrkm\    ; Set up the to-address
  10708.     sta    kerto        ;        ...
  10709.     lda    #errrkm^    ;        ...
  10710.     sta    kerto+1        ;        ...
  10711.     ldy    pdlen        ; Get packet data length
  10712.     sty    kwrk01        ; Store for the copy routine
  10713.     lda    #0        ; Start by storing a null at the end
  10714.     sta    (kerto),y    ;        ...
  10715.     jsr    kercpy        ; Copy the error text
  10716.     lda    errcod        ; Set the bit in the error code
  10717.     ora    #eprflg        ;    saying that the remote Kermit sent us
  10718.     sta    errcod        ;    an error packet.
  10719.     jsr    prcrlf        ; [jrd] leading crlf please
  10720.     ldx    #errrkm\    ; Finally, display the error packet
  10721.     ldy    #errrkm^    ;        ...
  10722.     jsr    prstr        ; Print string
  10723.     jsr    prcrlf        ; Make it look neat, add a crlf
  10724.     rts            ; Return to caller
  10725.  
  10726. ;
  10727. ;    Gobble - snarfs a line of characters from the port up to
  10728. ;    the receive end-of-line character. If it sees a keyboard
  10729. ;    interupt, it punts and does not skip.
  10730. ;
  10731.  
  10732. gobble:
  10733.     jsr    openrsm        ; ensure rs port open
  10734.     lda    #0        ; Zero the index pointing to end of line buffer
  10735.     sta    pdtend        ;        ...
  10736. ; zzz?    sta    ndx        ; Make sure no unwarranted keyboard intrpt
  10737. gobb:    jsr    getc        ; Get a character
  10738.      jmp    gobb2        ; Got a keyboard interupt
  10739.     lda    char        ;[31]
  10740.     cmp    #soh        ; Is it a start-of-header?
  10741.     bne    gobb        ; No, flush until first SOH
  10742.     jmp    gobbst        ; Ok, now we can start
  10743. gobb0:    jsr    getc        ; Get a character
  10744.      jmp    gobb2        ; Got a keyboard interupt
  10745.     lda    char        ;[31]
  10746.     cmp    #soh        ; If this not an SOH
  10747.     bne    gobb1        ;    continue here
  10748.     tax            ; Hold the character here
  10749.     lda    #0        ; Rezero the index pointing to end of buf
  10750.     sta    pdtend        ;        ...
  10751.     txa            ; Get the SOH back
  10752.     jmp    gobbdb        ; Go stuff the character in the buffer
  10753. gobb1:    cmp    reol        ; Is it the end-of-line character?
  10754.     beq    gobb3        ; Yes, finish up
  10755. gobbst:    ldx    pdtend        ; Get the index we need
  10756. gobbdb:    sta    plnbuf,x    ; Stuff the character at the buffer
  10757.     inc    pdtend        ; Increment the index once
  10758.     jmp    gobb0        ; Loop for another character
  10759. gobb2:    rts            ; Just return, no skip
  10760. gobb3:    ldx    pdtend        ; Get end pointer again
  10761.     sta    plnbuf,x    ; Store the End-of-line before we leave
  10762.     lda    #0        ; Zero the index, leave eob ptr where it is
  10763.     sta    pdtind        ;        ...
  10764.     jmp    rskp        ; Return with a skip!
  10765.  
  10766. ;
  10767. ;    Getplc - gets a character from the port line buffer and
  10768. ;    returns it. If the buffer is empty, it returns without
  10769. ;    skipping.
  10770. ;
  10771.  
  10772. getplc: ldx    pdtind        ; Get the current index
  10773.     cpx    pdtend        ; Less than the end buffer pointer?
  10774.     bmi    getpl1        ; If so, go return the next character
  10775.     rts            ; Return without a skip
  10776. getpl1: lda    plnbuf,x    ; Get the next character from the buffer
  10777.     inc    pdtind        ; Up the index once
  10778.     jmp    rskp        ; Return with a skip!
  10779.  
  10780. ;
  10781. ;
  10782. ;    Putplc - puts a character to the port line buffer.
  10783. ;
  10784.  
  10785. putplc: ldx    pdtind        ; Get the current index
  10786.     inx            ; Check if we are at end of buffer
  10787.     bne    putpl1        ; No, continue
  10788.     rts            ; Return without a skip
  10789. putpl1: dex            ; Set index back to what it was
  10790.     sta    plnbuf,x    ; Get the next character from the buffer
  10791.     inc    pdtind        ; Up the index once
  10792.     rts            ; Return
  10793.  
  10794. ;
  10795. ;    Getc - skip returns with a character from the port or does
  10796. ;    a normal return if a key from the keyboard is received first.
  10797. ;    If it skips, the character from the port is returned in the
  10798. ;    AC.
  10799. ;
  10800.  
  10801. getc:    jsr    getkey        ; Try and get a keyboard character
  10802. ;    bne    getcy        ;[] Got one
  10803.     bcc    getcy        ; [jrd] got one
  10804.     jmp    getc1        ;[] None available, try port
  10805. getcy:    lda    char        ;[31] Get the character read
  10806.     and    #$7F        ; Shut H.O. bit
  10807.     cmp    #ctrlx        ;[43] Was it an 'abort current file' interrupt?
  10808.     beq    getc3        ; Yes
  10809. getc2:    cmp    #ctrly        ;[43] Was it 'abort file group' interrupt ?
  10810.     bne    getc0        ;[43] Nope, continue
  10811. getc3:    lda    #errfta        ; Error code for 'file trans abort'
  10812.     sta    errcod        ; Stuff it here
  10813.     jsr    closef        ;[28] Close the current file
  10814. abo0:    lda    #0        ;[43] Send a 'Z' packet with a 'D' field
  10815.     sta    numtry        ;[43]
  10816.     sta    tpak        ;[43]
  10817.     sta    tpak+1        ;[43]
  10818.     lda    #pdbuf\        ;[43] Get the address of the packet buffer
  10819.     sta    kerbf1        ;[43]   and save it for Spak
  10820.     lda    #pdbuf^        ;[43]        ...
  10821.     sta    kerbf1+1    ;[43]        ...
  10822. abo1:    lda    numtry        ;[43] Fetch the number of tries
  10823.     cmp    maxtry        ;[43] Have we exceeded Maxtry?
  10824.     bmi    abo3        ;[43] Not yet, go send the packet
  10825. abo2:    ldx    #ermesc\    ;[43] Yes, give an error message
  10826.     ldy    #ermesc^    ;[43]        ...
  10827.     jsr    prstr        ;[43]        ...
  10828.     jsr    prcrlf        ;[43]        ...
  10829.     jmp    abo4        ;[43]    and restart kermit
  10830. abo3:    inc    numtry        ;[43] Increment the number of tries for packet
  10831.     lda    #0        ;[43] Make it packet number 0
  10832.     sta    pnum        ;[43]        ...
  10833.     lda    #1        ;[43] Data length is only 1
  10834.     sta    pdlen        ;[43]        ...
  10835.     lda    #'D        ;[43] The 'Discard' command
  10836.     sta    pdbuf        ;[43] Put that in first character of buffer
  10837.     lda    #'Z        ;[43] EOF command packet type
  10838.     sta    ptype        ;[43]        ...
  10839.     jsr    flshin        ;[43] Flush the RS232 buffer
  10840.     jsr    spak        ;[43] Send the packet
  10841.     ;jsr    rpak        ;[43] Try to fetch an ACK
  10842.     ;cmp    #true        ;[43] Did we receive successfully?
  10843.     ;bne    abo1        ;[43] No, try to send the packet again
  10844.     ;lda    ptype        ;[43] Get the type
  10845.     ;cmp    #'Y        ;[43] An ACK?
  10846.     ;bne    aboce        ;[43] No, go check for error
  10847.     jmp    abo4        ;[43] Yes, restart Kermit
  10848. aboce:    ;cmp    #'E        ;[43] Error packet?
  10849.     ;bne    abo1        ;[43] Nope, resend packet
  10850.     ;jsr    prcerp        ;[43] Go display the error
  10851.  
  10852. abo4:
  10853. ;    ldx    kerosp        ; Get the old stack pointer back
  10854. ;    txs            ; Restore it
  10855.     jmp    kermit        ; Warmstart kermit
  10856.  
  10857. getc0:  lda    #0        ;[EL] And reset the strobe
  10858. ; zzz?    sta    ndx        ;[EL]        ...
  10859.     rts            ; Keyboard interupt, return
  10860. getc1:    jsr    timerexp    ;[49] Have we timed out?
  10861.      jmp    getc0        ;[49] Yes return
  10862.     jsr    getrs        ; No, Check the port
  10863.     beq    getcn        ;[] Got a character
  10864.     jmp    getc        ;[] No char, go back to top of loop
  10865. getcn:    lda    char        ;[31] Get the character read
  10866.     jmp    rskp        ;    and return skip!
  10867.  
  10868. ;
  10869. ;    Prson - parses an 'on' or an 'off' keyword and passes
  10870. ;    the result back to the calling routine in the x-index
  10871. ;    register. If there is an error, it pops the return
  10872. ;    address off the stack and transfers control to kermt2
  10873. ;    to issue the error message.
  10874. ;
  10875.  
  10876. prson:  lda    #oncmd\        ; Command table address
  10877.     sta    cminf1        ;        ...
  10878.     lda    #oncmd^        ;        ...
  10879.     sta    cminf1+1    ;        ...
  10880.     lda    #shon\        ; Set up default string for parse
  10881.     sta    cmdptr        ;        ...
  10882.     lda    #shon^        ;        ...
  10883.     sta    cmdptr+1    ;        ...
  10884.     ldy    #cmfdff        ; Show there is a default
  10885.     lda    #cmkey        ; Code for keyword
  10886.     jsr    comnd        ; Go do it
  10887.      rts            ; The command was not recognized
  10888.      nop
  10889.      nop
  10890.     jmp    rskp        ; Good, skip return
  10891.  
  10892. ;
  10893. ;    prcfm - parses for a confirm, then transfers control directly
  10894. ;    to the top of the main loop
  10895. ;
  10896.  
  10897. prcfm:  lda    #cmcfm        ; Load token for confirm
  10898.     jsr    comnd        ; Parse a confirm
  10899.      jmp    kermt3        ; No confirm, give an error
  10900. ;    lda    #cr        ; Print a crlf
  10901. ;    jsr    cout        ;        ...
  10902.     jsr    prcrlf
  10903.     rts            ; Return
  10904.  
  10905. ;
  10906. ;    Pron - checks the value in the AC and prints either 'ON' or
  10907. ;    'OFF'. (on=1, off=0).
  10908. ;
  10909.  
  10910. pron:    cmp    #on        ; Should we print 'on'?
  10911.     bne    pron1        ; No, go print 'off'
  10912.     ldx    #shon\        ; Point to the 'on' string
  10913.     ldy    #shon^        ;        ...
  10914. pron0:  jsr    prstr        ; Print it
  10915.     jsr    prcrlf        ; Add a crelf at the end
  10916.     rts            ; And return
  10917. pron1:  ldx    #shoff\        ; Point to the 'off' string
  10918.     ldy    #shoff^        ;        ...
  10919.     jmp    pron0        ; Go print it
  10920.  
  10921. ;
  10922. ;    Clrfcb - clears the area FCB1 so the filename placed there
  10923. ;    will not be corrupted.
  10924. ;
  10925.  
  10926. clrfcb:    ldx    #mxfnl        ; Load max filename length
  10927.     lda    #ATEOL        ; [jrd] atari wants file name terminated by EOL
  10928. clrfc1:    sta    fcb1,x        ; Stuff the space
  10929.     dex            ; Decrement our pointer
  10930.     bpl    clrfc1        ; Not done, go back
  10931.     rts            ; Return
  10932.  
  10933. ;
  10934. ;    Kercpy - copies the string pointed to by Kerfrm to the
  10935. ;    block of memory pointed to by Kerto for Kwrk01 characters.
  10936. ;
  10937.  
  10938. kercpy:    ldy    kwrk01        ; Get the length of the string
  10939. kerclp:    dey            ; One character less
  10940.     bmi    kercrt        ; If this went negative, we're done
  10941.     lda    (kerfrm),y    ; Get the next character
  10942.     sta    (kerto),y    ; And put it where it belongs
  10943.     jmp    kerclp        ; Go back for next char
  10944. kercrt:    rts            ; Job is done, return
  10945.  
  10946. ;
  10947. ;    cmd2fcb:    Command buffer to fcb copier.
  10948. ;            Expects x,y pointing to buf,
  10949. ;            size in A.  (that's what comes back from
  10950. ;            the command parser when entering filenames)
  10951. ;            Copies that string into fcb1, terminated
  10952. ;            with an ATEOL.  Returns size in A
  10953. ;
  10954. cmd2fcb:
  10955.     stx    source        ; set source addr
  10956.     sty    source+1    ; ...
  10957.     pha            ; save size so we can return it
  10958.     ldy    #0        ; zero source idx
  10959.     tax            ; get size in x
  10960.     beq    cmd2fcb2    ; if zero left, exit
  10961. cmd2fcb1:
  10962.     lda    (source),y    ; get a byte
  10963.     sta    fcb1,y        ; stuff it in
  10964.     iny            ; bump idx
  10965.     dex            ; dec size
  10966.     bne    cmd2fcb1    ; back for more
  10967. cmd2fcb2:
  10968.     lda    #ATEOL        ; terminate it
  10969.     sta    fcb1,y
  10970.     pla            ; get original size back
  10971.     rts            ; done!
  10972.  
  10973. ;
  10974. ;    Kerflm - fills the buffer pointed to by Kerto with the
  10975. ;    character in kwrk02 for Kwrk01 characters.
  10976. ;
  10977.  
  10978. kerflm:    ldy    kwrk01        ; Get the length of the string
  10979. kerflp:    dey            ; One character less
  10980.     bmi    kerflr        ; If this went negative, we're done
  10981.     lda    kwrk02        ; Get the fill character
  10982.     sta    (kerto),y    ; And put it in the next position
  10983.     jmp    kerflp        ; Go back to do next char
  10984. kerflr:    rts            ; Job is done, return
  10985.  
  10986.  
  10987. ;
  10988. ;    Prchr - takes a character from the AC and prints it. It
  10989. ;    echos control characters as '^<chr>', and wierd atari chars
  10990. ;    in their graphics form.
  10991. ;
  10992.  
  10993. prchr:    pha            ; [jrd] save original
  10994.     and    #$7F        ; [jrd] for testing control-ness
  10995.     cmp    #$20        ; Less than escape??
  10996.     bpl    prchr1        ; If not, continue
  10997.     lda    #'^        ; Load the up-arrow for cntrl characters
  10998.     jsr    cout        ; Print the character
  10999.     pla            ; Get the character back
  11000.     clc            ; Clear carry for add
  11001.     adc    #$40        ; Put this in the alphabetic range
  11002.     jmp    prchr        ; [jrd] tail recurse...
  11003. ;
  11004. prchr1: lda    #esc        ; [jrd] 'quote' it with esc, in case
  11005.                 ;  of nasty screen hacking chars
  11006.     jsr    cout        ; put that
  11007.     pla            ; get original back
  11008.     jmp    cout        ;    and print it
  11009.  
  11010.  
  11011. ;
  11012. ;    Genmad - takes a message base, offset and size and calculates
  11013. ;    the address of the message leaving it in the X and Y registers
  11014. ;    ready for a call to PRSTR. The size and offset are taken from
  11015. ;    the stack and the base address is found in kermbs.
  11016. ;
  11017.  
  11018. genmad: pla            ; Get return address
  11019.     sta    kerrta        ;    and save it till later
  11020.     pla            ;
  11021.     sta    kerrta+1    ;
  11022.     pla            ; Get message offset
  11023.     tax            ; Hold it here for a while
  11024.     pla            ; Get the message length
  11025.     tay            ;    and put it here
  11026.     lda    #0        ; H.O. byte of message offset for mul16
  11027.     pha            ;
  11028.     txa            ; L.O. byte of message offset
  11029.     pha            ;
  11030.     lda    #0        ; H.O. byte of message size for mul16
  11031.     pha            ;
  11032.     tya            ; L.O. byte of message size
  11033.     pha            ;
  11034.     jsr    mul16        ; Calculate the actual offset in table
  11035.     pla            ; Get L.O. byte of result
  11036.     clc            ; Clear the carry for addition
  11037.     adc    kermbs        ; Add the L.O. byte of the base address
  11038.     tax            ; Put it in X for the return
  11039.     pla            ; Get the H.O. byte
  11040.     adc    kermbs+1    ; Add the H.O. byte of the base address w/carry
  11041.     tay            ; Stuff it here for the return
  11042.     lda    kerrta+1    ; Replace the return address on the stack
  11043.     pha            ;        ...
  11044.     lda    kerrta        ;        ...
  11045.     pha            ;        ...
  11046.     rts            ; Return
  11047.  
  11048.  
  11049. .SBTTL     Video Support Routines
  11050.  
  11051. ;
  11052. ;    Prttab - Go to next tab stop
  11053. ;
  11054.  
  11055. prttab:    sec            ;[26] Get the cursor coordinates
  11056.     jsr    ploth        ;[26]        ...
  11057. ;    tya            ;[26] Put the column in A
  11058.     txa            ;[26] Put the column in A
  11059.     lsr    a        ;[26] Divide column by 8
  11060.     lsr    a        ;[26]        ...
  11061.     lsr    a        ;[26]        ...
  11062. ;    tay            ;[26] Add one
  11063.     tax            ;[26] Add one
  11064. ;    iny            ;[26]        ...
  11065.     inx            ;[26]        ...
  11066. ;    tya            ;[26]        ...
  11067.     txa            ;[26]        ...
  11068.     asl    a        ;[26] Multiply by 8
  11069.     asl    a        ;[26]        ...
  11070.     asl    a        ;[26]        ...
  11071. ;    tay            ;[26] Put the new column in Y
  11072.     tax            ;[26] Put the new column in Y
  11073. ;    cpy    #80
  11074.     cpx    #80
  11075.     lda    scrtype
  11076.     bne    prttab1        ;[37]
  11077. ;    cpy    #40        ;[26] Is new column number 40?
  11078.     cpx    #40        ;[26] Is new column number 40?
  11079. prttab1: bcs    prttab2        ; at leftmost edge?
  11080.     jsr    ploth        ; carry already clear
  11081.     rts
  11082. prttab2: jsr    scrcr        ; at leftmost edge. perform a cr and lf
  11083.     jsr    scrlf
  11084.     rts
  11085.  
  11086. ;
  11087. ;    Ploth - Plot the cursor position
  11088. ;
  11089. ;    Input: Carry set to read cursor position
  11090. ;           Y-reg cursor y position            (if carry is set)
  11091. ;           X-reg cursor x position            (if carry is set)
  11092. ;
  11093. ;    Output:Y-reg is cursor y position        (if carry is clear)
  11094. ;           X-reg is cursor x position        (if carry is clear)
  11095. ;
  11096. ;    Registers Destroyed:  None            (if carry is set)
  11097. ;
  11098.  
  11099. ploth:    bcc    ploth1
  11100.     ldy    ROWCRS
  11101.     ldx    COLCRS
  11102.     cpx    #80        ; zzz check 40 col too
  11103.     bcc    ploth0
  11104.     ldx    #79
  11105. ploth0:    clc
  11106.     rts
  11107.  
  11108. ploth1:
  11109. ;    tya            ; swap a-reg and x-reg
  11110. ;    pha
  11111. ;    txa
  11112. ;    tay
  11113. ;    pla
  11114. ;    tax
  11115. ;    jsr    scrplt
  11116.     jmp    scrplt
  11117. ;    rts
  11118.  
  11119. ;    Print (X) spaces
  11120. ; obsolete
  11121. ;prbl2:  stx    savex        ;[DD] Save X
  11122. ;    lda    #sp        ;[DD] Get a space
  11123. ;    jsr    cout        ;[DD] Print it
  11124. ;    ldx    savex        ;[DD] Get back X
  11125. ;    dex            ;[DD] Decrement it
  11126. ;    bne    prbl2        ;[DD] If not 0, do more
  11127. ;    rts            ;[DD] Return
  11128.  
  11129. ; Print a reg as 2 hex nibbles
  11130.  
  11131. prbyte:             ;[DD] Output byte in hex
  11132. by2hx:  pha            ;[DD] Save byte
  11133.     lsr    a        ;[DD]
  11134.     lsr    a        ;[DD]
  11135.     lsr    a        ;[DD]
  11136.     lsr    a        ;[DD]
  11137.     jsr    ny2hx             ;[DD] High nyble
  11138.     tax                 ;[DD] to x
  11139.     pla                 ;[DD] Get back
  11140.     and    #$0F             ;[DD] Low nyble
  11141.     jsr    ny2hx        ;[DD] Translate to Hex
  11142.     pha            ;[DD] Save low nyble
  11143.     txa            ;[DD] Get high nyble
  11144.     jsr    cout        ;[DD] Print it
  11145.     pla            ;[DD] Get back low nyble
  11146.     jmp    cout        ;[DD] Print and return
  11147.  
  11148. ; Translate nyble to hex
  11149.  
  11150. ny2hx:    clc            ;[DD]
  11151.     adc    #$F6        ;[DD]
  11152.     bcc    ny2h2        ;[DD]
  11153.     adc    #6        ;[DD]
  11154. ny2h2:  adc    #$3A        ;[DD]
  11155.     rts            ;[DD]
  11156.  
  11157. ; Print hex of A,X
  11158. ; obsolete 
  11159. ;prntax: stx    savex        ;[DD] Save X
  11160. ;    jsr    prbyte        ;[DD] Print A first
  11161. ;    lda    savex        ;[DD] Get X into A
  11162. ;    jsr    prbyte        ;[DD] Print that next
  11163. ;    rts            ;[DD] Return
  11164.  
  11165. ;    Prntad - Print a number in base 10.  Leading zeros are skipped.
  11166. ;
  11167. ;    Input: A,X - Number to be printed
  11168. ;
  11169. ;    Registers Destroyed:    A,X,Y
  11170. ;
  11171. ;    This routine works by repeated subtraction.  10^X is subtracted
  11172. ;    until the result would be negative.  After each subtraction, Y
  11173. ;    is incremented. Y starts out at '0.  Thus, Y is the ascii value
  11174. ;    of the next digit.
  11175.  
  11176. prntad:
  11177.     stx    decnum        ; [54] Save the number to print
  11178.     sta    decnum+1    ; [54]
  11179.  
  11180.     ldx    #4        ; [54] Up to 5 digits (0..4)
  11181. prntad1: lda    decnum        ; [54] Compare with 10^x
  11182.     cmp    tens1,x        ; [54]
  11183.     lda    decnum+1    ; [54]
  11184.     sbc    tens2,x        ; [54]
  11185.     bcs    prntad2        ; [54] If greater, found first nonzero digit
  11186.     dex            ; [54] Skip the leading zero
  11187.     bne    prntad1        ; [54] Go test the next digit, unless last
  11188.  
  11189. prntad2: ldy    #'0        ; [54] Y is the ascii value to print
  11190. prntad3: lda    decnum        ; [54] Compare with 10^x
  11191.     cmp    tens1,x        ; [54]
  11192.     lda    decnum+1    ; [54]
  11193.     sbc    tens2,x        ; [54]
  11194.     bcc    prntad4        ; [54] Result would be negative.
  11195.  
  11196.     lda    decnum        ; [54] Now subtract 10^x
  11197.     sbc    tens1,x        ; [54] carry is already set
  11198.     sta    decnum        ; [54]
  11199.     lda    decnum+1    ; [54]
  11200.     sbc    tens2,x        ; [54]
  11201.     sta    decnum+1    ; [54]
  11202.     iny            ; [54] Keep track of the value of this digit
  11203.     bne    prntad3        ; [54] Always taken
  11204.  
  11205. prntad4: txa            ; [54] Save X
  11206.     pha            ; [54]
  11207.     tya            ; [54] Print the character in Y
  11208.     jsr    cout        ; [54]
  11209.     pla            ; [54] Restore X
  11210.     tax            ; [54]
  11211.     dex            ; [54] Print the next digit.
  11212.     bpl    prntad2        ; [54]
  11213.     rts
  11214. tens1    .byte    1\,10\,100\,1000\,10000\ ; [54] Powers of ten for prntad
  11215. tens2    .byte    1^,10^,100^,1000^,10000^
  11216.  
  11217. ;
  11218. ;    prntadnl    prntad followed by prcrlf
  11219. ;
  11220. prntadnl:
  11221.     jsr    prntad
  11222.     jmp    prcrlf
  11223.  
  11224. ;
  11225. ;    Cout - Print byte to screen
  11226. ;
  11227. ;    Input:    A - character to be printed
  11228. ;
  11229. ;    Output:
  11230. ;
  11231. ;    Registers Destroyed:    A,X,Y
  11232. ;
  11233.  
  11234. cout:
  11235. ; superceeded by sputch
  11236. ;    jmp    sputch        ; maybe not?
  11237. ;
  11238. ;    sta    source        ; Save A-reg
  11239. ;    pha            ; save A-reg again
  11240. ;    txa
  11241. ;    pha            ; save X-reg
  11242. ;    tya
  11243. ;    pha            ; save Y-reg
  11244. ;    lda    source
  11245. ;    jsr    scrput        ; print the character
  11246. ;    pla            ; restore Y-reg
  11247. ;    tay
  11248. ;    pla            ; restore X-reg
  11249. ;    tax
  11250. ;    pla            ; restore A-reg
  11251. ;    rts
  11252.     jmp    scrput        ; why go to all that trouble?
  11253.  
  11254. ;    Rdkey - Read keyboard until a byte appears
  11255. ;
  11256. ;    Input:
  11257. ;
  11258. ;    Output:
  11259. ;
  11260. ;    Registers Destroyed:
  11261. ;
  11262.  
  11263. rdkey:    jsr    getkey        ;[DD] Try and get a keyboard byte
  11264. ;    bne    rdret        ;[DD] None, try again
  11265.     bcc    rdret        ; [jrd] there's one, return it
  11266.     jsr    scrfls
  11267.     jmp    rdkey        ;[]
  11268. rdret:    rts            ;[DD]        ...
  11269.  
  11270. ;
  11271. ;    Getkey - Get byte from keyboard, blink cursor
  11272. ;
  11273. ;    Input:    None
  11274. ;
  11275. ;    Output: Character read in CHAR
  11276. ;        Carry set   -> character read
  11277. ;              clear -> no character read
  11278. ;
  11279. ;    Registers Destroyed: A,X,Y
  11280. ;
  11281.  
  11282. getkey:    lda    CH        ; any keys pending?
  11283.     cmp    #$FF
  11284.     beq    getkey1        ; nope, return 0
  11285. ;    jsr    kgetch        ; get one the old way
  11286.     jsr    kbdget        ; get one the new way
  11287.     bcs    getkey        ; false alarm
  11288. getrt:    sta    char        ;[31] Store it
  11289.     cmp    #0        ; [jrd] set other flags
  11290.     clc
  11291.     rts            ;[DD]        ...
  11292. getkey1: lda    #0        ; return nothing
  11293.     sec
  11294.     rts
  11295. ;
  11296. ;----------------------------------------------------------------
  11297. ;    Bell - flash border color - will be terminated next cursor blink
  11298. ;
  11299. ;    Input:    None
  11300. ;
  11301. ;    Output: None
  11302. ;
  11303. ;    Registers Destroyed: None
  11304. ;
  11305.  
  11306. bell:    pha            ;[EL] Save the AC
  11307. beephi:    lda    #$3A        ;some color or other
  11308.     jmp    beep        ;[33]        ...
  11309. beeplo:    pha            ;[33] Save the AC
  11310.     lda    #$AA        ;a different color
  11311. beep:
  11312. ;
  11313. ; this seems to completely fry POKEY; fucks over serial baud rate
  11314. ;
  11315. ;    sta    AUDF4        ;[EL]        ...
  11316. ;    lda    #$E8        ; Pure tone, medium volume
  11317. ;    sta    AUDC4
  11318. ;    lda    #$0f        ;[EL] Select fast attack, slow decay
  11319. ;    sta    attdec        ;[EL]        ...
  11320. ;    lda    #$12        ;[EL] Select sustain ...
  11321. ;    sta    susrel        ;[EL]        ...
  11322. ;    lda    #6        ;[EL] Select not-too-loud volume
  11323. ;    sta    vol        ;[EL]        ...
  11324. ;    lda    #$21        ;[EL] Select sawtooth wave
  11325. ;    sta    wave        ;[EL]        ...
  11326.     sta    COLOR4        ; flash it
  11327. ;    jsr    rdtim        ; remember when the flash started
  11328.     lda    RTCLOK+2
  11329.     sta    lpcnt        ;[EL]        ...
  11330.     pla            ;[EL] Restore the AC
  11331.     rts            ;[EL] Return
  11332.  
  11333. .SBTTL    RS232 Support Routines
  11334.  
  11335. ;    Debugging code.
  11336. ;
  11337. ;    Dump IOCB if ICSTA < 0
  11338. ;
  11339. dbgstr1: .byte    ATEOL,"RS error ",0
  11340. dbgstr2: .byte    " -> ",0
  11341. debugrs:
  11342.     lda    ICSTA,X        ; get status
  11343.     bpl    dbgrs9        ; positive is ok
  11344.     pha            ; save it temporarily
  11345.     lda    ICCOM,X        ; get op that failed
  11346.     pha            ; save that too
  11347.     ldx    #dbgstr1\    ; print debug msg
  11348.     ldy    #dbgstr1^
  11349.     jsr    prstr
  11350.     pla            ; get op back
  11351.     jsr    prbyte        ; print that
  11352.     ldx    #dbgstr2\    ; print second part of str
  11353.     ldy    #dbgstr2^
  11354.     jsr    prstr
  11355.     pla            ; get err back
  11356.     jsr    prbyte
  11357.     jsr    prcrlf        ; end line
  11358.     ldx    #comchan    ; point at rs232 iocb again
  11359. dbgrs9:    rts            ; and go home
  11360.     
  11361. ;
  11362. ;    Openrsm - Open the channel if it wasn't already
  11363. ;    Openrs - Open the RS-232 Channel
  11364. ;
  11365. ;    Input:    RS232 Parameters in x36ax1,x38ax1
  11366. ;
  11367. ;    Ouput:
  11368. ;
  11369. ;    Registers Destroyed: A
  11370. ;
  11371. openrsm:
  11372.     lda    comopen        ; already open?
  11373.     beq    openrs        ; no, go open it for real
  11374.     rts
  11375. openrs:    
  11376.     jsr    closers        ; close it first
  11377.     ldx    #comchan    ; [jrd] rs232 port iocb
  11378.     lda    #comname\    ; [jrd] name lo
  11379.     sta    ICBAL,X
  11380.     lda    #comname^    ; [jrd] name hi
  11381.     sta    ICBAH,X
  11382.      lda    #$0D        ; [jrd] mode in+out+concurrent
  11383.     sta    ICAX1,X
  11384.     lda    #0
  11385.     sta    ICAX2,X
  11386.     sta    ICBLL,X        ; zap buf len
  11387.     sta    ICBLH,X
  11388.     lda    #OPEN
  11389.     sta    ICCOM,X        ; open please
  11390.     jsr    CIOV        ; do it.
  11391. ;    jsr    debugrs        ; zzz debug
  11392. ;
  11393. ; Action code from that kermit
  11394. ;  CIOV(2, 34, 0, 0, 192+48, 0)
  11395. ;
  11396.     lda    #34        ; xio 34, set cts, dtr etc
  11397.     sta    ICCOM,X
  11398.     lda    #192+48+3    ; DTR on, RTS on, XMT on
  11399.     sta    ICAX1,X
  11400.     lda    #0
  11401. ;    sta    ICBLL,X
  11402. ;    sta    ICBLH,X
  11403.     sta    ICBAL,X
  11404.     sta    ICBAH,X
  11405. ;    sta    ICAX2,X
  11406.     jsr    CIOV
  11407. ;    jsr    debugrs        ; zzz debug
  11408. ;
  11409. ;  CIOV(2, 38, 0, 0, 32+PARITY*5, 0)
  11410. ;
  11411.     lda    #38        ; xio 38, translation and parity
  11412.     sta    ICCOM,X
  11413. ;    lda    #32        ; no translation, no parity
  11414.     lda    x38ax1
  11415.     sta    ICAX1,X
  11416. ;    lda    #0
  11417. ;    sta    ICBLL,X
  11418. ;    sta    ICBLH,X
  11419. ;    sta    ICBAL,X
  11420. ;    sta    ICBAH,X
  11421. ;    sta    ICAX2,X
  11422.     jsr    CIOV
  11423. ;    jsr    debugrs        ; zzz debug
  11424. ;
  11425. ;  CIOV(2, 36, 0, 0, 8+baud, 0)
  11426. ;
  11427.     lda    #36        ; xio 36, baud rate
  11428.     sta    ICCOM,X
  11429.     ldy    baud        ; get baud value
  11430.     lda    bdval,y        ; get real parameter for port
  11431.     sta    ICAX1,X
  11432. ;    lda    #0
  11433. ;    sta    ICBLL,X
  11434. ;    sta    ICBLH,X
  11435. ;    sta    ICBAL,X
  11436. ;    sta    ICBAH,X
  11437. ;    sta    ICAX2,X
  11438.     jsr    CIOV
  11439. ;    jsr    debugrs        ; zzz debug
  11440. ;
  11441. ;  CIOV(2, 40, 0, 0, 0, 0)
  11442. ;
  11443.     lda    #40        ; XIO 40, start concurrent IO
  11444.     sta    ICCOM,X
  11445.     lda    #0
  11446.     sta    ICBLL,X
  11447. ;    sta    ICBLH,X
  11448.     sta    ICBAL,X
  11449. ;    sta    ICBAH,X
  11450. ;    sta    ICAX1,X
  11451.     sta    ICAX2,X
  11452.     lda    #$06        ; use page 6 as iobuf
  11453.     sta    ICBAH,X
  11454.     lda    #$01        ; size 256
  11455.     sta    ICBLH,X
  11456.     lda    #$0D        ; value from 850 man, p62.  must be 0D?,
  11457.     sta    ICAX1,X        ;  or any non-zero?
  11458.     jsr    CIOV
  11459.     jsr    debugrs        ; zzz debug
  11460. ;
  11461.     lda    #1
  11462.     sta    comopen        ; com is now open for business
  11463.     jsr    comsta        ; refresh pending byte count
  11464. ; [jrd]
  11465.  
  11466. ;
  11467. ;    Alocrs - Subroutine - allocate the RS232 buffers
  11468. ;
  11469. ;    Input:    Buffer locations in RSOUT,RSIN
  11470. ;
  11471. ;    Output:
  11472. ;
  11473. ;    Registers Destroyed: A
  11474. ;
  11475.  
  11476. alocrs:
  11477. ; all obsolete ?
  11478. ;    lda    #rsout\        ;[24] Allocate the RS-232 buffers
  11479. ;    sta    robuf        ;[24]        ...
  11480. ;    lda    #rsout&$ff00^    ;[24]        ...
  11481. ;    sta    robuf+1        ;[24]        ...
  11482. ;    lda    #rsin\        ;[24]        ...
  11483. ;    sta    ribuf        ;[24]        ...
  11484. ;    lda    #rsin&$ff00^    ;[24]        ...
  11485. ;    sta    ribuf+1        ;[24]        ...
  11486.     rts            ;[24] Return
  11487.  
  11488. ;
  11489. ; Close comm port.  Added by jrd
  11490. ;
  11491. closers:
  11492.     lda    comopen        ; open?
  11493.     beq    closer9        ; nope, just return
  11494.     lda    #0
  11495.     sta    comopen        ; remember that it's closed
  11496.     sta    compend        ; no more pending
  11497.     sta    compend+1
  11498.     ldx    #comchan
  11499.     jmp    closec        ; just ignore status etc
  11500. closer9:
  11501.     rts
  11502. ;
  11503. ;    comsta - Update status of the comm port
  11504. ;
  11505. ;    updates pending byte count in compend.
  11506. ;    Trashes regs
  11507. ;
  11508. comsta:
  11509.     ldx    #comchan    ; [jrd] rs232 iosb please
  11510.     lda    #STATIS        ; [jrd] status request, returns bytes pending
  11511.     sta    ICCOM,X
  11512.     jsr    CIOV
  11513.     jsr    debugrs        ; zzz debugging
  11514.     lda    DVSTAT        ; get device status
  11515.     sta    comstat        ; save for future reference
  11516.     lda    DVSTAT+1    ; get byte count pending
  11517.     sta    compend
  11518.     lda    DVSTAT+2
  11519.     sta    compend+1
  11520.     lda    comstat        ; now check error bits
  11521.     beq    comsta9        ; none, ok
  11522.     lda    debug        ; oops!  error.  Display it?
  11523.     beq    comsta8        ; nope, just whack pending count
  11524.     ldx    comstm\        ; display the message
  11525.     ldy    comstm^
  11526.     jsr    prstr
  11527.     lda    comstat        ; display the status
  11528.     jsr    prbyte
  11529.     jsr    prcrlf
  11530. comsta8:
  11531.     lda    #0
  11532.     sta    compend        ; force a refresh next time
  11533.     sta    compend+1
  11534. comsta9:
  11535.     rts
  11536. comstm:    .byte    "Com err ",0
  11537. ;
  11538. ;    Getrs - Get byte from rs232 port
  11539. ;
  11540. ;    Input:    
  11541. ;
  11542. ;    Output:    Character read in CHAR
  11543. ;    Z set if character was read
  11544. ;
  11545. ;    Registers Destroyed: A,X,Y
  11546. ;
  11547.  
  11548. getrs:
  11549.     jsr    flowco        ;[24] Do flow control if necessary
  11550.     lda    suspend        ;[24] Is RS-232 reading suspended?
  11551.     bne    getr3        ; Yes, 
  11552. getr2:
  11553.     lda    compend        ; [jrd] anything pending?
  11554.     cmp    #0
  11555.     bne    getr2a        ; yup, go get one
  11556.     lda    compend+1    ; ?
  11557.     cmp    #0
  11558.     bne    getr2a
  11559.     jsr    comsta        ; go see if there's any since we looked
  11560.     lda    compend        ; now check byte count again
  11561.     cmp    #0
  11562.     bne    getr2a
  11563.     lda    compend+1
  11564.     cmp    #0
  11565.     bne    getr2a        ; there's something pending, go get it
  11566.     lda    #$FF        ; bogus value so we can...
  11567.     cmp    #0        ;  return NE
  11568.     rts
  11569. ;
  11570. getr2a:                ; dec pending count
  11571.     lda    compend        ; save it
  11572.     dec    compend        ; dec lo byte
  11573.     cmp    #0        ; was it 0?
  11574.     bne    getr2b        ; no, skip hi byte
  11575.     dec    compend+1    ; yes, dec hi byte
  11576. getr2b:    ldx    #comchan    ; now go read one    
  11577.     jsr    chrin        ; [jrd] get one
  11578.     ldx    wrdsiz        ; get word size value
  11579.     beq    getr2c        ; 8-bit = 0
  11580.     and    #$7F        ; if 7 bit, make sure
  11581. getr2c:
  11582.     sta    char        ;[31] Store it here
  11583.     sty    stat        ; [jrd]
  11584.     jsr    rserrs        ;[33] Check for RS232 errrors
  11585. ; bogus    bne    getr3        ;[33] If error, return no byte
  11586. ;    lda    stat        ;[33] Check stat to see if byte was read
  11587. ;    cmp    #1        ; [jrd] has effect of setting Z if 1
  11588.     lda    #0        ; debugging, always return Z
  11589.     cmp    #0
  11590. getr3:    rts            ;[DD] Return
  11591.  
  11592. ;
  11593. ;    Rserrs - Check for RS232 errors
  11594. ;
  11595. ;    Input:    Status in STAT
  11596. ;
  11597. ;    Output:
  11598. ;
  11599. ;    Registers Destroyed: A
  11600. ;
  11601. ; Atari 850 RS232 error bits that show up in DVSTAT
  11602. ;
  11603. RS850FE    =    $80        ; Framing error
  11604. RS850OE    =    $40        ; Receive overrun
  11605. RS850PE    =    $20        ; Parity error
  11606. RS850OV    =    $10        ; Buffer overflow
  11607. RS850IL    =    $08        ; Illegal option combination
  11608. RS850NR    =    $04        ; Device not ready
  11609. RS850BE    =    $02        ; Data block error, ie 850 didn't xcv right
  11610. RS850CE    =    $01        ; Command error
  11611. ;
  11612. ; corresponding messages.  All 8 bytes, for ease of indexing.
  11613. ;
  11614. rsetxt:
  11615.     .byte    "Framing",0
  11616.     .byte    "Overrun",0
  11617.     .byte    "Parity ",0
  11618.     .byte    "Buf Ofl",0
  11619.     .byte    "Bad Opt",0
  11620.     .byte    "Dev NR ",0
  11621.     .byte    "850 err",0
  11622.     .byte    "Cmd err",0
  11623. ;
  11624. rseokt:    .byte    "RS ok  ",0
  11625. rserrtim: .byte    0
  11626. ;
  11627. rserrs:    lda    comstat        ; [jrd] Get the status from last STATUS call
  11628.     beq    erret        ; no bits set, go home
  11629. ;
  11630. ; Display err in stat line.
  11631. ;
  11632.     ldx    #0        ; error bit number, left to right
  11633. rserrs1:
  11634.     rol    A        ; shift out a bit
  11635.     bcs    rserrs2        ; found one, go display it
  11636.     inx            ; bump count
  11637.     cpx    #7        ; done?
  11638.     bne    rserrs1        ; nope, try again
  11639.     jmp    erret
  11640. rserrs2:
  11641.     txa            ; get errnum into A
  11642.     asl    A
  11643.     asl    A
  11644.     asl    A        ; * 8
  11645. ; zzz fix this to work with atari screen, too
  11646.     clc
  11647.     adc    #rsetxt\    ; add base of err msgs
  11648.     pha            ; save for a bit
  11649.     lda    #rsetxt^    ; get hi addr
  11650.     adc    #0        ; add carry
  11651.     tay            ; into Y for statline rtn
  11652.     pla            ; get lo addr back
  11653.     ldx    #32        ; offset in stat line
  11654.     jsr    slput        ; show it
  11655.     jsr    beeplo        ;[33] Error, Feep!
  11656.     lda    RTCLOK+2    ; get time displayed
  11657.     adc    #128        ; set for 2 sec or so
  11658.     ora    #1        ; make sure nonzero
  11659.     sta    rserrtim    ; save it
  11660.     rts            ; done
  11661. erret:
  11662.     lda    rserrtim    ; zero?
  11663.     beq    erret8
  11664. ; this isn't very accurate, but it'll do
  11665.     sbc    RTCLOK+2    ; subtract time value
  11666.     bne    erret9        ; not ready to clear error msg
  11667. erret8:
  11668.     sta    rserrtim    ; zero flag
  11669.     lda    #rseokt\    ; get 'ok' msg
  11670.     ldy    #rseokt^
  11671.     ldx    #32        ; offset in stat line
  11672.     jsr    slput
  11673. erret9:
  11674.     rts            ;[33]
  11675.  
  11676. ;
  11677. ;    Flowco - perform RS-232 flow control
  11678. ;
  11679. ;    Input:
  11680. ;
  11681. ;    Output:
  11682. ;
  11683. ;    Registers Destroyed: A,X
  11684. ;
  11685.  
  11686. flowco:    lda    flowmo        ;[24] Get the flow control mode switch
  11687.     cmp    #on        ;[24] Is it on?
  11688.     bne    flowre        ;[24] No
  11689. ; all this stuff removed cause there's no good way to do it on atari
  11690. ;     lda    shflag        ;[24] Check commodore key
  11691. ;    and    #$02        ;[24] Is it depressed?
  11692. ;    beq    nocomm        ;[24] No
  11693. ;    lda    commflg        ;[24] Was it depressed before
  11694. ;    bne    flowch        ;[24] Yes, ignore it
  11695. ;    inc    commflg        ;[24] Set commodore key flag
  11696.     lda    suspend        ;[24] Currently suspended?
  11697.     beq    flowch        ;[24] No
  11698.     jsr    comsta        ; [jrd] yes, update pending count
  11699. ;    lda    #0        ;[24] Clear suspend flag
  11700. ;    sta    suspend        ;[24]        ...
  11701. ;    beq    flowch        ;[24]
  11702. ;notsus:    inc    suspend        ;[24] Set suspend flag
  11703. ;    bne    flowch        ;[24]
  11704. ;nocomm:    sta    commflg        ;[24] Clear commodore key flag
  11705.  
  11706. flowch:
  11707. ;    lda    ridbe        ;[24] Compute number of chars
  11708. ;    sec            ;[24]    in RS-232 buffer
  11709. ;     sbc    ridbs        ;[24]        ...
  11710. ;    lsr    a        ;[24] Divide count by 2 for accurate check
  11711.     ldx    fxoff        ;[24] Has an xoff already been sent
  11712.     bne    itsoff        ;[24] Yes
  11713.     lda    compend+1    ; more than 256?!?
  11714.     bne    flowch1        ; yup, shut it off
  11715.     lda    compend        ; check lo half
  11716.     bmi    flowch1        ; hi bit set, shut it off    
  11717.     cmp    #50        ;[24] Number chars in buffer reached 50?
  11718.     bcc    flowre        ;[24] No - no flow control necessary yet
  11719. flowch1:
  11720.     jsr    sxoff        ;[24] Send an xoff
  11721.     rts            ;[24] Return
  11722. itsoff: lda    compend+1    ; if > 256, leave it off
  11723.     bne    flowre
  11724.     lda    compend
  11725.     cmp    #20        ;[24] Has backlog dropped to 20 or less?
  11726.     bcs    flowre        ;[24] No - leave input suspended
  11727.     jsr    sxon        ;[24] Send an xon
  11728. flowre:    rts            ;[24] Return
  11729.  
  11730. ;
  11731. ;    Flshin - Flush the RS232 input buffer
  11732. ;
  11733. ;    Input:
  11734. ;
  11735. ;    Output:
  11736. ;
  11737. ;    Registers Destroyed: A
  11738.  
  11739. flshin:    
  11740.     txa            ; save some regs
  11741.     pha
  11742.     tya
  11743.     pha
  11744. flshin1:
  11745.     jsr    getrs        ;[25] Get from RS-232 buffer
  11746.     beq    flshin1        ;[33] No, get more
  11747.     pla
  11748.     tay
  11749.     pla
  11750.     tax
  11751.     rts            ;[25] Yes, finish
  11752.  
  11753. ;
  11754. ;    Putrs - Send byte to RS232
  11755. ;
  11756. ;    Input: Byte in A
  11757. ;
  11758. ;    Output:
  11759. ;
  11760. ;    Registers Destroyed:
  11761. ;
  11762.     .byte    0        ; [jrd] save x 
  11763.     .byte    0        ; [jrd] save y
  11764. putrs:    
  11765.     stx    putrs-2        ; [jrd] save x
  11766.     sty    putrs-1        ; [jrd] save y
  11767.     ldx    #comchan    ; [jrd]
  11768.     jsr    chrout        ;[DD] Send the character
  11769.     ldx    putrs-2        ; [jrd] get x back
  11770.     ldy    putrs-1        ; [jrd]  "  y
  11771.     rts            ;[DD] Return
  11772.  
  11773.  
  11774. ;
  11775. ;    Sbreak - Send a break signal
  11776. ;
  11777.  
  11778. sbreak:    jsr    closers        ; yes, we must
  11779.     ldx    #comchan
  11780.     lda    #192+48+2    ; DTR on, RTS on, XMT off
  11781.     sta    ICAX1,X
  11782.     lda    #34        ; xio 34, set cts, dtr etc
  11783.     sta    ICCOM,X
  11784.     lda    #comname\    ; [jrd] name lo
  11785.     sta    ICBAL,X
  11786.     lda    #comname^    ; [jrd] name hi
  11787.     sta    ICBAH,X
  11788.     lda    #0
  11789.     sta    ICAX2,X
  11790.     jsr    CIOV        ; go do it
  11791.     ldy    #250        ;[DD][28] Delay 250 ms.
  11792. sbdl1:  ldx    #250        ;[DD]        ...
  11793. sbdl2:  dex            ;[DD] Inner loop 1 ms.
  11794.     bne    sbdl2        ;[DD]        ...
  11795.     dey            ;[DD] Outer loop
  11796.     bne    sbdl1        ;[DD]        ...
  11797.     jsr    openrs        ; re open it
  11798.  
  11799. ;
  11800. ; diddle the state of the xmit line.  Expects A to contain
  11801. ; 2 for send-space, 3 for send-mark.
  11802. ;
  11803. hacktx:    jmp    CIOV
  11804.  
  11805. ;
  11806. ;    Subroutine - send out ^Q (xon) to remote host
  11807. ;
  11808.  
  11809. sxon:    lda    #0        ;[24] Clear xoff flag
  11810.     sta    fxoff        ;[24]        ...
  11811.     lda    #$11        ;[24] Transmit ^Q
  11812.     bne    xcom        ;[24]        ...
  11813.  
  11814. ;
  11815. ;    Subroutine - send out ^S (xoff) to remote host
  11816. ;
  11817.  
  11818. sxoff:    lda    #5        ;[24] Set xoff flag
  11819.     sta    fxoff        ;[24][32]    ...
  11820.     lda    #$13        ;[24]    then, transmit ^S
  11821. xcom:    jsr    putrs        ;[24]        ...
  11822.     jsr    updstat        ; [jrd] clean stat line
  11823.     rts            ;[24] Return
  11824.  
  11825. ;
  11826. ;
  11827. ;   Cva2s - Convert ASCII to Speedscript (word processor)
  11828. ;
  11829. ;    Input:    Character in KERCHR
  11830. ;
  11831. ;    Output:    Converted character in KERCHR
  11832. ;
  11833. ;    Registers Destroyed: A
  11834. ;
  11835. ; None of this appears to be necessary on Ataris -- jrd
  11836. ;cva2s:  lda    kerchr        ;[DD]
  11837. ;    and    #$7F        ;[DD]
  11838. ;    cmp    #cr        ;[DD]
  11839. ;    bne    cva2s1      ;[DD] Check cr
  11840. ;    lda    #$1F        ;[DD]
  11841. ;cva2s1: cmp    #$61        ;[DD]
  11842. ;    bcc    cva2s2        ;[DD]
  11843. ;    cmp    #$7B        ;[DD]
  11844. ;    bcs    cva2s2        ;[DD]
  11845. ;    and    #$1F        ;[DD] Convert lower case
  11846. ;cva2s2: cmp    #$5B        ;[DD]
  11847. ;    bcc    cva2s3        ;[DD]
  11848. ;    cmp    #$5F        ;[DD]
  11849. ;    bcs    cva2s3        ;[DD]
  11850. ;    and    #$1F        ;[DD]
  11851. ;cva2s3: sta    kerchr        ;[DD]
  11852. ;    rts            ;[DD]
  11853. ;;  Convert Seedscript (word processor) to ASCII
  11854. ;cvs2a:  lda    kerchr        ;[DD]
  11855. ;    and    #$7F        ;[DD]
  11856. ;cvs2a1: cmp    #$1B        ;[DD]
  11857. ;    bcs    cvs2a2      ;[DD] If <$1b
  11858. ;    ora    #$60        ;[DD] Convert to lc
  11859. ;cvs2a2: cmp    #$1F        ;[DD]
  11860. ;    bcs    cvs2a3        ;[DD]
  11861. ;    ora    #$40        ;[DD]
  11862. ;cvs2a3: bne    cvs2a4         ;[DD] If =$1f
  11863. ;    lda    #cr        ;[DD] cr
  11864. ;cvs2a4:    sta    kerchr        ;[DD]
  11865. ;    rts            ;[DD]
  11866.  
  11867. .SBTTL    Spar and Rpar routines
  11868.  
  11869. ;
  11870. ;    Spar - This routine loads the data buffer with the init parameters
  11871. ;    requested for this Kermit.
  11872. ;
  11873. ;        Input:  NONE
  11874. ;
  11875. ;        Output: @Kerbf1 - Operational parameters
  11876. ;
  11877. ;        Registers destroyed:    A,Y
  11878. ;
  11879.  
  11880. spar:    ldy    #0        ; Clear Y
  11881.     sty    datind        ; Clear datind
  11882.     lda    rpsiz        ; Fetch receive packet size
  11883.     clc            ; Clear the carry flag
  11884.     adc    #$20        ; Characterize it
  11885.     sta    (kerbf1),y    ; Stuff it in the packet buffer
  11886.     iny            ; Increment the buffer index
  11887.     lda    rtime        ; Get the timeout interval
  11888.     clc            ;        ...
  11889.     adc    #$20        ; Make that a printable character
  11890.     sta    (kerbf1),y    ;    and stuff it in the buffer
  11891.     iny            ; Advance the index
  11892.     lda    rpad        ; Get the amount of padding required
  11893.     clc            ;        ...
  11894.     adc    #$20        ; Make that printable
  11895.     sta    (kerbf1),y    ; Put it in the buffer
  11896.     iny            ; Advance index
  11897.     lda    rpadch        ; Get the padding character expected
  11898.     eor    #$40        ; Controlify it
  11899.     sta    (kerbf1),y    ; And stuff it
  11900.     iny            ; Up the packet buffer index
  11901.     lda    reol        ; Get the end-of-line expected
  11902.     clc            ;        ...
  11903.     adc    #$20        ; Characterize it
  11904.     sta    (kerbf1),y    ; Place that next in the buffer
  11905.     iny            ; Advance the index
  11906.     lda    rquote        ; Get the quote character expected
  11907.     sta    (kerbf1),y    ; Store it as-is last in the buffer
  11908.     iny            ; Advance index
  11909. ;    lda    #'Y        ;  Send 'Y' - I will support 8-bit quoting
  11910. ;    sta    (kerbf1),y    ; Stuff it into the data area
  11911.     lda    ebqmod        ;[30] Get eight-bit quoting
  11912.     cmp    #off        ;[30] Is it off?
  11913.     beq    spar1        ;[30] Yes...say we will do it if HE wants to
  11914. ;    lda    sebq        ;[30] Get eight-bit quote character
  11915.     lda    rebq        ;[jrd] Get RECEIVE eight-bit quote character
  11916.     sta    (kerbf1),y    ;[30] So other Kermit knows we are
  11917.     rts            ;[30]    requesting it
  11918. spar1:    lda    #'Y        ; Send 'Y' - I will support 8-bit quoting
  11919.     sta    (kerbf1),y    ; Stuff it into the data area
  11920.     rts            ;        ...
  11921.  
  11922. ;
  11923. ;
  11924. ;    Rpar - This routine sets operational parameters for the other kermit
  11925. ;    from the init packet data buffer.
  11926. ;
  11927. ;        Input:  @Kerbf1 - Operational parameters
  11928. ;
  11929. ;        Output: Operational parameters set
  11930. ;
  11931. ;        Registers destroyed:    A,Y
  11932. ;
  11933.  
  11934. rpar:    ldy    #0        ; Start the data index at 0!
  11935.     lda    (kerbf1),y    ; Start grabbing data from packet buffer
  11936.     sec            ; Uncharacterize it
  11937.     sbc    #$20        ;        ...
  11938.     sta    spsiz        ; That must be the packet size of other Kermit
  11939.     iny            ; Increment the buffer index
  11940.     lda    (kerbf1),y    ; Get the next item
  11941.     sec            ;        ...
  11942.     sbc    #$20        ; Uncharacterize that
  11943.     sta    stime        ; Other Kermit's timeout interval
  11944.     iny            ; Up the index once again
  11945.     lda    (kerbf1),y    ; Get next char
  11946.     sec            ;        ...
  11947.     sbc    #$20        ; Restore to original value
  11948.     sta    spad        ; This is the amount of padding he wants
  11949.     iny            ; Advnace index
  11950.     lda    (kerbf1),y    ; Next item
  11951.     eor    #$40        ; Uncontrolify this one
  11952.     sta    spadch        ; That is padding character for other Kermit
  11953.     iny            ; Advance index
  11954.     lda    (kerbf1),y    ; Get next item of data
  11955.     cmp    #0        ; If it is equal to zero
  11956.     beq    rpar2        ; Use <cr> as a default
  11957.     jmp    rpar3        ;        ...
  11958. rpar2:  lda    #cr        ; Get value of <cr>
  11959.     sta    seol        ; That will be the eol character
  11960.     jmp    rpar4        ; Continue
  11961. rpar3:  sec            ;        ...
  11962.     sbc    #$20        ; unchar the character
  11963.     sta    seol        ; That is the eol character other Kermit wants
  11964. rpar4:  iny            ; Advance the buffer index
  11965.     lda    (kerbf1),y    ; Get quoting character
  11966.     cmp    #0        ; If that is zero
  11967.     beq    rpar5        ; Use # sign as the quote character
  11968.     jmp    rpar6        ; Otherwise, give him what he wants
  11969. rpar5:  lda    #'#        ; Load # sign
  11970. rpar6:  sta    squote        ; Make that the other Kermit's quote character
  11971.     iny            ; Advance the index
  11972.     lda    pdlen        ; Check the data length to see
  11973.     cmp    #9        ;    if the 8-bit quote is there
  11974.     bmi    rparrt        ; If not, return
  11975.     lda    (kerbf1),y    ; Fetch the 8-bit quote
  11976.     cmp    #'N        ; Is it 'N'
  11977.     beq    rpar8        ; Yes, leave.(he doesn't support 8-bit)
  11978.     cmp    #'Y        ; Does he support 8-bit quoting?
  11979. ;    beq    rpar8        ; If so, leave. (we don't need it.)
  11980.     beq    rpar9        ; [jrd] yes, he supports it, using our 
  11981.                 ;  quote character if we asked.
  11982.     cmp    #'!        ; Now, it should be a real character
  11983.     bmi    rparrt        ;    Check if it is in range.
  11984.     cmp    #'?        ;    If so, we set the 8-bit quote char
  11985.     bmi    rpar7        ;    and set 8-bit quoting on.
  11986.     cmp    #$60        ;    If not, just leave.
  11987.     bmi    rparrt        ;        ...
  11988.     cmp    #del        ;        ...
  11989.     bpl    rparrt        ;        ...
  11990. rpar7:    sta    sebq        ; Stuff the character here
  11991.     lda    #on        ; Set 8-bit quoting on
  11992.     sta    ebqmod        ;        ...
  11993.     rts            ; Return
  11994. rpar8:
  11995.     sta    sebq        ; Make sure this parm is stored
  11996.     lda    #off        ;    AND that 8-bit quoting is off.
  11997.     sta    ebqmod        ;        ...
  11998.     rts
  11999. rpar9:    
  12000.     sta    sebq        ; save it, for now at least...
  12001.     lda    ebqmod        ; did we ask for it?
  12002.     cmp    #off
  12003.     beq    rparrt        ; no, just return.
  12004.     lda    rebq        ; we DID ask, and he agreed.  Get the
  12005.     sta    sebq        ;  char we asked for, and use it.
  12006. rparrt:    rts            ; Return
  12007.  
  12008. ;
  12009. ;
  12010. ;    Nakit - sends a standard NAK packet out to the other Kermit.
  12011. ;
  12012. ;        Input:  NONE
  12013. ;
  12014. ;        Output: NONE
  12015. ;
  12016.  
  12017. nakit:  lda    #0        ; Zero the packet data length
  12018.     sta    pdlen        ;        ...
  12019.     lda    #'N        ; Set up a nak packet type
  12020.     sta    ptype        ;        ...
  12021.     jsr    spak        ; Now, send it
  12022.     rts            ; Return
  12023.  
  12024.  
  12025. .SBTTL    Message text
  12026.  
  12027. versio: .byte    ATEOL
  12028.     .byte    "Atari 800 Kermit v 3.7"
  12029.     .byte    ATEOL
  12030.     .byte    "type ? for help"
  12031.     .byte    0        ; [53]
  12032.  
  12033.  
  12034. .SBTTL    Command tables and help text
  12035.  
  12036. ;
  12037. ; Top level command table.  The two values returned in x,y are a 
  12038. ; vector to the routine that matches the command.
  12039. ;
  12040. kercmd:
  12041. ;    .byte    $10        ;[DD][EL][40][] Table length 
  12042.     .byte    $11        ; Table length with Erase command installed
  12043. ;    .byte    $12        ; Table length with LOG command installed
  12044.     .byte    $03,"bye",0        ;,$1E,$1E
  12045.     .word    bye
  12046.     .byte    $07,"connect",0        ;,$00,$00
  12047.     .word    telnet
  12048.     .byte    $09,"directory",0    ;,$2A,$2A
  12049.     .word    dirst
  12050.     .byte    $05,"erase",0        ;,$33,$33
  12051.     .word    erase
  12052.     .byte    $04,"exit",0        ;,$03,$03
  12053.     .word    quit
  12054.     .byte    $06,"finish",0        ;,$21,$21
  12055.     .word    finish
  12056.     .byte    $03,"get",0        ;,$24,$24
  12057.     .word    getfrs
  12058.     .byte    $04,"help",0        ;,$06,$06
  12059.     .word    help
  12060. ;    .byte    $03,"log",0,0,0        ; not implemented
  12061.     .byte    $04,"quit",0        ;,$0C,$0C
  12062.     .word    quit
  12063.     .byte    $07,"receive",0        ;,$0F,$0F
  12064.     .word    receve
  12065.     .byte    $06,"rename",0        ;,$27,$27
  12066.     .word    rename
  12067.     .byte    $07,"restore",0        ;,$30,$30
  12068.     .word    restst
  12069.     .byte    $04,"save",0        ;,$2D,$2D
  12070.     .word    savst
  12071.     .byte    $04,"send",0        ;,$12,$12
  12072.     .word    send
  12073.     .byte    $03,"set",0        ;,$15,$15
  12074.     .word    setcom
  12075.     .byte    $04,"show",0        ;,$18,$18
  12076.     .word    show
  12077.     .byte    $06,"status",0        ;,$1B,$1B
  12078.     .word    status
  12079.  
  12080. ;
  12081. ; Command table for subcommands of "set".  Returned value 
  12082. ; is jump vector in x,y
  12083. ;
  12084. setcmd:
  12085. ;    .byte    $12        ; Table length with DEFAULT-DISK option in
  12086.     .byte    $11        ; without file-byte-size
  12087.     .byte    $06,"escape",0        ;,$00,$00
  12088.     .word    stesc
  12089.     .byte    $03,"ibm",0        ;,$03,$03        ; 
  12090.     .word    stibm
  12091.     .byte    $0A,"local-echo",0        ;,$06,$06
  12092.     .word    stle
  12093.     .byte    $07,"receive",0        ;,$09,$09
  12094.     .word    strc
  12095.     .byte    $04,"send",0        ;,$0C,$0C
  12096.     .word    stsn
  12097.     .byte    $12,"terminal-emulation",0        ;,$0F,$0F
  12098.     .word    stvt
  12099.     .byte    $0C,"file-warning",0        ;,$12,$12
  12100.     .word    stfw
  12101.     .byte    $11,"eight-bit-quoting",0        ;,$15,$15
  12102.     .word    steb
  12103.     .byte    $09,"debugging",0        ;,$18,$18
  12104.     .word    stdb
  12105.     .byte    $09,"file-type",0        ;,$1B,$1B
  12106.     .word    stmod
  12107. ;    .byte    $0E,"file-byte-size",0        ;,$1E,$1E
  12108. ;    .word    stfbs
  12109.     .byte    $0F,"rs232-registers",0        ;,$21,$21        ;[DD]
  12110.     .word    stccr
  12111.     .byte    $06,"parity",0        ;,$24,$24        ; 
  12112.     .word    stpari
  12113.     .byte    $04,"baud",0        ;,$27,$27        ;[17]
  12114.     .word    stbaud
  12115.     .byte    $09,"word-size",0        ;,$2a,$2a
  12116.     .word    stwrd
  12117.     .byte    $0C,"flow-control",0        ;,$2d,$2d        ;[24]
  12118.     .word    stflow
  12119.     .byte    $0D,"screen-driver",0        ;,$30,$30        ;[37]
  12120.     .word    stscre
  12121.     .byte    $0C,"default-disk",0        ;,$33,$33
  12122.     .word    stdef
  12123.  
  12124. ;    .byte    $05,"color",0,$36,$36
  12125.  
  12126.  
  12127. ;
  12128. ; This one too, values returned are jump vectors
  12129. ;
  12130. shocmd:
  12131. ;    .byte    $12        ; Table length with DEFAULT-DISK opt included
  12132.     .byte    $11        ; without file-byte-size
  12133.     .byte    $03
  12134. shodef:    .byte    "all",0            ;,$00,$00
  12135.     .word    shall
  12136.     .byte    $04,"baud",0        ;,$7e,$7e
  12137.     .word    shbad
  12138.     .byte    $09,"debugging",0        ;,$51,$51
  12139.     .word    shdb
  12140.     .byte    $0C,"default-disk",0        ;,$99,$99
  12141.     .word    shdef
  12142.     .byte    $11,"eight-bit-quoting",0        ;,$48,$48
  12143.     .word    sheb
  12144.     .byte    $06,"escape",0        ;,$09,$09
  12145.     .word    shesc
  12146. ;    .byte    $0E,"file-byte-size",0        ;,$63,$63
  12147. ;    .word    shfbs
  12148.     .byte    $09,"file-type",0        ;,$5A,$5A
  12149.     .word    shmod
  12150.     .byte    $0C,"file-warning",0        ;,$3F,$3F
  12151.     .word    shfw
  12152.     .byte    $0C,"flow-control",0        ;,$90,$90        ;[24]
  12153.     .word    shflow
  12154.     .byte    $03,"ibm",0        ;,$12,$12
  12155.     .word    shibm
  12156.     .byte    $0A,"local-echo",0        ;,$1B,$1B
  12157.     .word    shle
  12158.     .byte    $06,"parity",0        ;,$75,$75
  12159.     .word    shpari
  12160.     .byte    $07,"receive",0        ;,$24,$24
  12161.     .word    shrc
  12162.     .byte    $0F,"rs232-registers",0        ;,$6C,$6C            ;[DD]
  12163.     .word    shccr
  12164.     .byte    $04,"send",0        ;,$2D,$2D
  12165.     .word    shsn
  12166.     .byte    $12,"terminal-emulation",0        ;,$36,$36
  12167.     .word    shvt
  12168.     .byte    $09,"word-size",0        ;,$87,$87            ;[17]
  12169.     .word    shwrd
  12170.  
  12171. stscmd: .byte    $07
  12172.     .byte    $14,"eight-bit-quote-char",0,$06,$06
  12173.     .byte    $0B,"end-of-line",0,$09,$09
  12174.     .byte    $0D,"packet-length",0,$0C,$0C
  12175.     .byte    $08,"pad-char",0,$00,$00
  12176.     .byte    $07,"padding",0,$03,$03
  12177.     .byte    $0A,"quote-char",0,$0F,$0F
  12178.     .byte    $07,"timeout",0,$12,$12
  12179.  
  12180. ftcmd:
  12181. ;    .byte    $04                ; len with 'script' in
  12182.     .byte    3
  12183.     .byte    $07
  12184. ftcdef:    .byte    "atascii",0,ftatas,ftatas        ; defualt
  12185.     .byte    $05,"ascii",0,ftstas,ftstas
  12186.     .byte    $06,"binary",0,ftbin,ftbin
  12187. ;    .byte    $06,"script",0,$03,$03
  12188.  
  12189. parkey:    .byte    $05        ; LENGTH OF THIS TABLE IS 5
  12190.     .byte    $04,"even",0,$04,$04        ;
  12191.     .byte    $04,"mark",0,$02,$02        ;
  12192.     .byte    $04,"none",0,$00,$00        ;
  12193.     .byte    $03,"odd",0,$03,$03        ;
  12194.     .byte    $05,"space",0,$01,$01        ;
  12195.  
  12196. bdkey:    .byte    $0A        ;[17] Length of table
  12197.     .byte    2,"50",0,bd50,bd50
  12198.     .byte    2,"75",0,bd75,bd75
  12199.     .byte    3,"110",0,bd110,bd110
  12200.     .byte    3,"150",0,bd150,bd150
  12201.     .byte    3,"300",0,bd300,bd300
  12202.      .byte    4,"1200",0,bd1200,bd1200
  12203.     .byte    4,"1800",0,bd1800,bd1800
  12204.     .byte    4,"2400",0,bd2400,bd2400
  12205.     .byte    4,"4800",0,bd4800,bd4800
  12206.     .byte    4,"9600",0,bd9600,bd9600 
  12207.  
  12208. debkey:    .byte    $03        ; LENGTH OF THIS TABLE IS 3
  12209.     .byte    $03,"off",0,$00,$00        ;
  12210.     .byte    $05,"terse",0,$01,$01        ;
  12211.     .byte    $07,"verbose",0,$02,$02        ;
  12212.  
  12213. fbskey: .byte    $02
  12214.     .byte    $09,"eight-bit",0,$00,$00
  12215.     .byte    $09,"seven-bit",0,$01,$01
  12216.  
  12217. oncmd:  .byte    $02
  12218.      .byte    $02,"on",0,$01,$01
  12219.      .byte    $03,"off",0,$00,$00
  12220.  
  12221. yescmd: .byte    $02
  12222.     .byte    $02,"no",0,$00,$00
  12223.      .byte    $03,"yes",0,$01,$01
  12224.  
  12225. scrkey:    .byte    $03        ;[37]
  12226.     .byte    $05,"atari",0,scrae,scrae
  12227.     .byte    $0a,"40-columns",0,scr40,scr40
  12228.     .byte    $0a,"80-columns",0,scr80,scr80
  12229.  
  12230. termemu: .byte    $03        ;terminal emulation may be none, vt52 or vt100
  12231.     .byte    4,"none",0,ttnone,ttnone
  12232.     .byte    5,"vt100",0,tt100,tt100
  12233.     .byte    4,"vt52",0,tt52,tt52
  12234.  
  12235. ;ddskey:    .byte    $01
  12236.  
  12237. ;    .byte    $05
  12238. ;    .asciz    /DRIVE/
  12239. ;    .byte    $00,$00
  12240.  
  12241. kerehr:    .byte    cmcfm        ; tell them they can also confirm
  12242.     .byte    nul        ; end help command string
  12243.  
  12244. kereht:    .byte    cmtxt        ;[]
  12245.     .byte    nul
  12246.  
  12247. kerhlp: .byte    ATEOL
  12248.     .byte    "kermit commands for this version are:",ATEOL
  12249.     .byte    ATEOL
  12250.     .byte    "bye       shut  down  and  log  out  a",ATEOL
  12251.     .byte    "          remote  kermit server,  then",ATEOL
  12252.     .byte    "          exit.",ATEOL
  12253.     .byte    ATEOL
  12254.     .byte    "connect   allow user to talk to remote",ATEOL
  12255.     .byte    "          kermit directly.",ATEOL
  12256.     .byte    ATEOL
  12257.     .byte    "directory list disk directory",ATEOL
  12258.     .byte    ATEOL
  12259.     .byte    "rename    renames one or more files on",ATEOL
  12260.     .byte    "          the default drive.",ATEOL
  12261.     .byte    ATEOL
  12262.     .byte    "erase     deletes one or more files on",ATEOL
  12263.     .byte    "          the default drive.",ATEOL
  12264.     .byte    ATEOL
  12265.     .byte    "exit      exit  from  kermit  back  to",ATEOL
  12266.     .byte    "          the  host operating  system.",ATEOL
  12267.     .byte    ATEOL
  12268.     .byte    "finish    shut   down  remote   kermit",ATEOL
  12269.     .byte    "          server  but  do not  log out",ATEOL
  12270.     .byte    "          remote job. do not exit from",ATEOL
  12271.     .byte    "          local kermit.",ATEOL
  12272.     .byte    ATEOL
  12273.     .byte    "get       fetch  a file from a  remote",ATEOL
  12274.     .byte    "          server kermit.  the filename",ATEOL
  12275.     .byte    "          is  validated by  the remote",ATEOL
  12276.     .byte    "          server.",ATEOL
  12277.     .byte    ATEOL
  12278.     .byte    "help      print instructions on",ATEOL
  12279.     .byte    "          various  commands  available",ATEOL
  12280.     .byte    "          in kermit.",ATEOL
  12281.     .byte    ATEOL
  12282.     .byte    "quit      same as exit.",ATEOL
  12283.     .byte    ATEOL
  12284.     .byte    "receive   receive a file or file group",ATEOL
  12285.     .byte    "          from the remote host.",ATEOL
  12286.     .byte    ATEOL
  12287.     .byte    "restore   restore  kermit  parameters",ATEOL
  12288.     .byte    "          from file kermit.ini",ATEOL
  12289.     .byte    ATEOL
  12290.     .byte    "save      save  kermit  parameters in",ATEOL
  12291.     .byte    "          file kermit.ini",ATEOL
  12292.     .byte    ATEOL
  12293.     .byte    "send      sends a file from the  m6502",ATEOL
  12294.     .byte    "          based computer to the remote",ATEOL
  12295.     .byte    "          host.",ATEOL
  12296.     .byte    ATEOL
  12297.     .byte    "set       establish various parameters",ATEOL
  12298.     .byte    "          such as debugging mode,  eol",ATEOL
  12299.     .byte    "          character, and  transmission",ATEOL
  12300.     .byte    "          delay.",ATEOL
  12301.     .byte    ATEOL
  12302.     .byte    "show      display  various  parameters",ATEOL
  12303.     .byte    "          established   by   the   set",ATEOL
  12304.     .byte    "          command.",ATEOL
  12305.     .byte    ATEOL
  12306.     .byte    "status    give  information about  the",ATEOL
  12307.     .byte    "          last file transfer.",ATEOL
  12308.     .byte    nul
  12309.  
  12310. inthlp: .byte    "one of the following:",ATEOL
  12311.     .byte    "     ? - this help message.",ATEOL
  12312.     .byte    "     b - send a break signal.",ATEOL
  12313.     .byte    "     c - close the connection.",ATEOL
  12314.     .byte    "     s - status of connection.",ATEOL
  12315.     .byte    "     escape-char - transmit the escape character.",ATEOL,nul
  12316.  
  12317. .SBTTL    Message Text
  12318.  
  12319. ermes1: .byte    ATEOL,"?unrecognized command",0        ; [53]
  12320. ermes2: .byte    ATEOL,"?illegal character",0        ; [53]
  12321. ermes3: .byte    ATEOL,"?not confirmed",0        ; [53]
  12322. ermes4: .byte    ATEOL,"?integer out of range",0        ; [53]
  12323. ermes5: .byte    ATEOL,"?ascii character is not in proper range",0        ; [53]
  12324. ermes6: .byte    ATEOL,"?expecting keyword",0        ; [53]
  12325. ermes7: .byte    ATEOL,"?expecting file spec",0        ; [53]
  12326. ermes8: .byte    ATEOL,"?expecting integer",0        ; [53]
  12327. ;ermes9: .byte    ATEOL,"?expecting switch",0        ; [jrd] no switches
  12328. ermesa:    .byte    ATEOL,"?",0        ; [53]
  12329. ermesb:    .byte    ATEOL,"?null string found while looking for text",0    ; [53]
  12330. ermesc:    .byte    ATEOL,"?could not send generic logout packet",0        ; [53]
  12331. ermesd:    .byte    ATEOL,"?could not send generic finish packet",0        ; [53]
  12332. ermesf:    .byte    ATEOL,"?drive number out of range",0        ; [53]
  12333.  
  12334. erms0a: .byte    ATEOL,"disk error stat = "
  12335. ermsdc:    .byte    "??",0        ; [53]
  12336. erms10: .byte    ATEOL,"cannot receive init",0        ; [53]
  12337. erms11: .byte    ATEOL,"cannot receive file-head",0        ; [53]
  12338. erms12: .byte    ATEOL,"cannot receive data",0        ; [53]
  12339. erms14: .byte    ATEOL,"max retry count exceeded",0        ; [53]
  12340. erms15: .byte    ATEOL,"bad chksum:pack, actual ",0        ; [53]
  12341. erms16: .byte    ATEOL,"program error in rpak",0        ; [53]
  12342. erms17: .byte    ATEOL,"8-bit quoting refused",0        ; [53]
  12343. erms18: .byte    ATEOL,"transfer aborted by user",0        ; [53]
  12344. erms19: .byte    ATEOL,"cannot alter filename",0        ; [53]
  12345. erms1a: .byte    ATEOL," file already exists",0        ; [53]
  12346.  
  12347. ;
  12348. ; error message vectors, indexed by error numbers
  12349. ;
  12350. kerrv:    .word    0            ; padding
  12351.     .word    erms10            ; errcri 
  12352.     .word    erms11            ; errcrf
  12353.     .word    erms12            ; errcrd
  12354.     .word    erms14            ; errmrc
  12355.     .word    erms15            ; errbch
  12356.     .word    0            ; no internal error msg?
  12357.     .word    erms18            ; errfta
  12358.     .word    erms19            ; errfal
  12359.     .word    erms1a            ; errfae
  12360.     .word    erms0a            ; errfde
  12361. ;
  12362. ; general error code message
  12363. ;
  12364. ermess:    .byte    ATEOL,"Error ",0
  12365. ;
  12366.  
  12367. ; file types
  12368. kerftp: .byte    "ascii  ",0        ; [53]
  12369.     .byte    "atascii",0        ; [53]
  12370.     .byte    "binary ",0        ; [53]
  12371. ;    .byte    "script ",0        ; [53]
  12372.  
  12373. ; parity strings
  12374. kerprs:    .byte    "none ",0        ; [53]
  12375.     .byte    "space",0        ; [53]
  12376.     .byte    "mark ",0        ; [53]
  12377.     .byte    "odd  ",0        ; [53]
  12378.     .byte    "even ",0        ; [53]
  12379. ;
  12380. ; See 850 man pg 54 for these values.  All specify 'No translation'
  12381. parval:    .byte    $20        ;[17] None, ignore input, don't change output
  12382.     .byte    $2C        ;[17] Space, clear input, don't change output
  12383.     .byte    $2F        ;[17] Mark, clear input, set output 1
  12384.     .byte    $25        ;[17] Odd, check in odd, set out odd
  12385.     .byte    $2A        ;[17] Even, check in even, set out even
  12386.  
  12387. kerbds:    .byte    "50  ",0        ; [53]
  12388.     .byte    "75  ",0        ; [53]
  12389.     .byte    "110 ",0        ; [53]
  12390.     .byte    "150 ",0        ; [53]
  12391.     .byte    "300 ",0        ; [53]
  12392.     .byte    "1200",0        ; [53]
  12393.     .byte    "1800",0        ; [53]
  12394.     .byte    "2400",0        ; [53]
  12395.     .byte    "4800",0
  12396.     .byte    "9600",0
  12397.  
  12398. bdval:    .byte    $02        ;[17]   50
  12399.     .byte    $04        ;[17]   75
  12400.     .byte    $05        ;[17]  110
  12401.     .byte    $07        ;[17]  150
  12402.     .byte    $08        ;[17]  300 
  12403. bddef:    .byte    $0A        ;[17] 1200
  12404.     .byte    $0B        ;[17] 1800
  12405.     .byte    $0C        ;[17] 2400
  12406.     .byte    $0D        ; [jrd] 4800
  12407.     .byte    $0E        ; [jrd] 9600
  12408.  
  12409. kerdms:    .byte    "off     ",0    ; Debug mode strings
  12410.     .byte    "terse   ",0    ;
  12411.     .byte    "verbose ",0    ;
  12412.  
  12413. kertms:    .byte    "none ",0        ; terminal emulation strings
  12414.     .byte    "vt52 ",0
  12415.     .byte    "vt100",0
  12416.  
  12417. kerrts: .byte    "spak:     sending           - ",0
  12418.     .byte    "spakch:   send complete     - ",0
  12419.     .byte    "rpak:     trying to receive - ",0
  12420.     .byte    "rpkfls:   failed to receive - ",0
  12421.     .byte    "rpkret:   received          - ",0
  12422.     
  12423. debms1: .byte    "additional data",0
  12424. debms2: .byte    "     seq number           ",0
  12425. debms3: .byte    "     number of data chars ",0
  12426. debms4: .byte    "     packet checksum      ",0
  12427. snin01: .byte    "sending ..packet no. ",0
  12428. rcin01: .byte    "waiting ..packet no. ",0
  12429. logrcvm: .byte    ATEOL,"Receiving ",0
  12430. logsndm: .byte    ATEOL,"Sending ",0
  12431. shin00: .byte    "debugging is          ",0
  12432. shin01: .byte    "terminal emulation is ",0
  12433. shin02: .byte    "ibm-mode is           ",0
  12434. shin03: .byte    "local-echo is         ",0
  12435. shin04: .byte    "eight-bit-quoting is  ",0
  12436. shin05: .byte    "file-warning is       ",0
  12437. shin06: .byte    "escape character is   ",0
  12438. shin07: .byte    "send",0
  12439. shin08: .byte    "  eight-bit-quoting char is   ",0
  12440. shin09: .byte    "  end-of-line character is    ",0
  12441. shin10: .byte    "  packet-length is            ",0
  12442. shin11: .byte    "  padding character is        ",0
  12443. shin12: .byte    "  amount of padding is        ",0
  12444. shin13: .byte    "  quote character is          ",0
  12445. shin14: .byte    "  timeout (in seconds) is     ",0
  12446. shin15: .byte    "receive",0
  12447. shin16: .byte    "file-type mode is     ",0
  12448. shin17: .byte    "file-byte-size is     ",0
  12449. shin18: .byte    "rs232 registers =     $",0
  12450. shin19:    .byte    "baud rate is          ",0
  12451. shin20:    .byte    "parity is             ",0
  12452. shin21:    .byte    "word-size is          ",0
  12453. shin22:    .byte    "flow-control is       ",0
  12454. shin23:    .byte    "default-disk is       ",0
  12455.  
  12456. shon:    .byte    "on",0
  12457. shoff:  .byte    "off",0
  12458.  
  12459. shsbit: .byte    "seven-bit",0
  12460. shebit: .byte    "eight-bit",0
  12461.  
  12462. sstrng:    .byte    "sending: ",0
  12463. rstrng:    .byte    "received: ",0
  12464.  
  12465. stin00: .byte    "number of data chars sent is:     ",0
  12466. stin01: .byte    "number of data chars received is: ",0
  12467. stin02: .byte    "total no. of chars sent is:       ",0
  12468. stin03: .byte    "total no. of chars received is:   ",0
  12469. stin04: .byte    "overhead for send packets is:     ",0
  12470. stin05: .byte    "overhead for receive packets is:  ",0
  12471. stin06: .byte    "last error encountered is:        ",0
  12472.  
  12473. inf01a: .byte    "[connecting to host: type ",0
  12474. inf01b: .byte    " c to return]",0
  12475.  
  12476. .SBTTL    General Screen Manipulation Routines
  12477.  
  12478. ;
  12479. ;    These routines perform screen manipulation functions.  The usually
  12480. ;    call a screen driver, but some call lower-level manipulation routines.
  12481. ;
  12482. ;    These routines all turn the cursor off before calling the screen
  12483. ;    driver.
  12484. ;
  12485.  
  12486. ;
  12487. ;    scrini - call the screen drivers initilization code
  12488. ;
  12489. ;    Input:    None
  12490. ;    Output: Assorted screen parameters are set
  12491. ;
  12492. ;    Registers destroyed - A,X,Y
  12493. ;
  12494. ;    This routine initilizes some parameters and calls all of the screen
  12495. ;    drivers initilization code. The drivers should be called
  12496. ;    least_favorite_device first and most_favorite device last.
  12497. ;
  12498.  
  12499. scrini:
  12500.     lda    #0        ; wrap defaults on
  12501.     sta    wrap
  12502. ;    sta    line25        ; the 25th line is a status line
  12503. ;    jsr    scraeini
  12504. ;    jsr    scr40ini
  12505. ;    jsr    scr80ini
  12506.     jsr    scrent        ; enter the most_favorite screen driver
  12507.     rts
  12508.  
  12509. ;
  12510. ;    scrent - start up a screen driver
  12511. ;
  12512. ;    Input:    Screen type in scrtype
  12513. ;    Output: None
  12514. ;
  12515. ;    Registers destroyed - A,X,Y
  12516. ;
  12517. ;    This routine sets some parameters and then calls the screen driver to
  12518. ;    start it and set its parameters.  It then calls scred2 to erase the
  12519. ;    screen.
  12520. ;
  12521.  
  12522. scrent:    
  12523.     lda    #0        ; cursor starts at row 1, column 1
  12524.     sta    COLCRS
  12525.     sta    ROWCRS
  12526.     sta    curstat
  12527.     lda    #1        ; mark cursor flash as aborted
  12528.     sta    curabrt        ; cursor is off but supposed to be on
  12529. ;     jsr    rdtim        ; set cntdown to wait the usual amount of time
  12530.     lda    RTCLOK+2
  12531.     sta    cntdown
  12532.     jsr    scrent1        ; call the screen driver
  12533.     jsr    scrrst        ; reset parameters to normal values
  12534.     jsr    scred2        ; clear entire screen
  12535.     rts            ; all done
  12536.  
  12537. scrent1:
  12538.     ldy    scrtype
  12539.     jsr    case
  12540.     .word    scraeent
  12541.     .word    scr40ent
  12542.     .word    scr80ent
  12543.     rts
  12544.  
  12545. ;
  12546. ;    scrext - exit from the screen driver
  12547. ;
  12548. ;    Input:    Screen type in scrtype
  12549. ;    Output: None
  12550. ;
  12551. ;    Registers destroyed - A,X,Y
  12552. ;
  12553. ;    This routine calls the screen driver to exit.  The hardware is returned
  12554. ;    to the state it was left in before kermit started.
  12555. ;
  12556.  
  12557. scrext:    
  12558.     ldy    scrtype
  12559.     jsr    case
  12560.     .word    scraeext
  12561.     .word    scr40ext
  12562.     .word    scr80ext
  12563.  
  12564. ;
  12565. ;    scrrst - reset the screen parameters to normal values
  12566. ;
  12567. ;    Input:    None
  12568. ;    Output: Assorted parameters changed.
  12569. ;
  12570. ;    Registers destroyed - A
  12571. ;
  12572. ;    This routine sets reverse mode off, flashing off, the scrolling
  12573. ;    region to full size, and many other things
  12574. ;
  12575.  
  12576. scrrst:    lda    #0        ; top of scrolling area is line 1
  12577.     sta    top
  12578.     lda    #23        ; bottom of scrolling area is line 24
  12579.     sta    bot
  12580.     lda    #0
  12581.     sta    underln        ; underline is off
  12582.     sta    reverse        ; reverse is off
  12583.     sta    alternt        ; alternt colors are off
  12584.     sta    flash        ; flashing is disabled
  12585.     jsr    scrsav        ; make these the saved parameters
  12586.     rts            ; all done
  12587.  
  12588. ;
  12589. ;    scrput - put a character on the screen
  12590. ;
  12591. ;    Input:    Character to put in a-reg.
  12592. ;        Screen type in scrtype.
  12593. ;    Output: Screen ram, both color rams, and cursor position are changed.
  12594. ;
  12595. ;    Registers destroyed - A,X,Y
  12596. ;
  12597. ;    Assumption:  All screens are 80 columns, but the first (40 columns)
  12598. ;
  12599. ;    This routine puts a character on the screen.  It advances the cursor
  12600. ;    and scrolls the screen when necessary.  It handels a carriage
  12601. ;    return specially.  It prints a carriage return and line feed
  12602. ;
  12603.  
  12604. scrput:    cmp    #ATEOL        ; is it a carriage return?
  12605.     bne    scrput4        ; no go do usual stuff
  12606.     ldx    scrtype        ; on atari screen?
  12607.     beq    scrput3        ; yup, just go do it
  12608.     jsr    scrcr        ; no.  Do a general purpose ret and lf
  12609.     jsr    scrlf
  12610.     rts
  12611. scrput4:
  12612.     pha            ; save the character to put
  12613.     jsr    scroff        ; cant use screen driver while cursor blinks
  12614.     pla            ; restore the character to put
  12615.     ldy    #39        ; 40 is the funny row in 40 column mode
  12616.     ldx    scrtype        ; are we in 40 column mode?
  12617.     beq    scrput1        ; no.  we have an 80 column screen
  12618.     ldy    #79        ; 80 is the funny row in 80 column modes
  12619. scrput1: cpy    COLCRS        ; are we in the funny column?
  12620.     bcs    scrput2        ; no
  12621.     ldx    wrap        ; are we in wrap mode
  12622.     bne    scrput3        ; no. do not wrap
  12623.     pha            ; save the character to put
  12624.     jsr    scrcr        ; yes. do a carriage return
  12625.     jsr    scrlf        ; and a linefeed
  12626.     pla            ; restore the character to put
  12627. scrput2: jsr    scrput3        ; call the routine to put a character.
  12628. ;    inc    COLCRS
  12629.     rts    
  12630.  
  12631. scrput3: ldy    scrtype        ; call the screen driver
  12632.     jsr    case
  12633.     .word    scraeput
  12634.     .word    scr40put
  12635.     .word    scr80put
  12636.  
  12637. ;
  12638. ;    scrcr - perform a carriage return
  12639. ;
  12640. ;    Input:    Screen type in scrtype.
  12641. ;        Cursor position in COLCRS, ROWCRS
  12642. ;
  12643. ;    Output: New new cursor column in COLCRS.
  12644. ;
  12645. ;    Registers destroyed - A,X,Y
  12646. ;
  12647. ;    This routine performs a carriage return.
  12648. ;
  12649.  
  12650. scrcr:    ldy    ROWCRS
  12651.     ldx    #0        ; put cursor in column zero
  12652.     jsr    scrplt        ; move the cursor there
  12653.     rts            ; all done
  12654.  
  12655. ;
  12656. ;    scrlf - perform a line feed
  12657. ;
  12658. ;    Input:    screen type in scrtype
  12659. ;        cursor column in ROWCRS
  12660. ;        cursor row in COLCRS
  12661. ;    Output: New cursor position in COLCRS, ROWCRS.
  12662. ;
  12663. ;    Registers destroyed - A,X,Y
  12664. ;
  12665. ;    This routine performs a line feed.
  12666. ;
  12667.  
  12668. scrlf:    ldy    ROWCRS        ; check if bottom reached
  12669.     cpy    bot
  12670. ;    bcc    scrlf1        ; yes. scroll screen
  12671.     bne    scrlf1        ; yes. scroll screen
  12672.     jmp    scrind
  12673. scrlf1:    iny
  12674.     ldx    COLCRS
  12675.     jsr    scrplt        ; no. move the cursor down one line.
  12676.     rts
  12677. ;
  12678. ;    scrrlf - perform a reverse line feed with scrolling
  12679. ;
  12680. ;    Input:    Type of screen in scrtype
  12681. ;        Cursor coordinates in COLCRS, ROWCRS
  12682. ;
  12683. ;    Output: None
  12684. ;
  12685. ;    Registers Destroyed: A,X,Y
  12686. ;
  12687. ;    This routine performs a reverse line feed.  The cursor is moved up
  12688. ;    one line.  If the cursor reaches the top of the scrolling area, scrri
  12689. ;    is called to scroll the screen backwards.
  12690. ;
  12691.  
  12692. scrrlf:    ldy    ROWCRS
  12693.     cpy    top
  12694.     beq    scrrlf1        ; reached top of the screen?
  12695.     dey            ; no, just move the cursor up
  12696.     ldx    COLCRS
  12697.     jsr    scrplt
  12698.     rts
  12699. scrrlf1: jsr    scrri        ; yes, at top of screen.  Scroll backwards
  12700.     rts
  12701.  
  12702. ;
  12703. ;    scru - move the cursor up stopping at the top of the screen
  12704. ;
  12705. ;    Input:    Type of screen in scrtype
  12706. ;        Cursor coordinates in COLCRS, ROWCRS
  12707. ;
  12708. ;    Output: None
  12709. ;
  12710. ;    Registers Destroyed: A,X,Y
  12711. ;
  12712. ;    This routine moves the cursor up.  If the cursor reaches the top
  12713. ;    of the screen it stops.
  12714. ;
  12715.  
  12716. scru:    ldy    ROWCRS
  12717.     beq    scru1        ; at top of screen?
  12718.     dey
  12719.     ldx    COLCRS
  12720.     jsr    scrplt        ; move the cursor to its new position
  12721. scru1:    rts
  12722.  
  12723. ;
  12724. ;    scrd - move the cursor down stopping at the bottom of the screen
  12725. ;
  12726. ;    Input:    Type of screen in scrtype
  12727. ;        Cursor coordinates in COLCRS, ROWCRS
  12728. ;
  12729. ;    Output: None
  12730. ;
  12731. ;    Registers Destroyed: A,X,Y
  12732. ;
  12733. ;    This routine moves the cursor down.  If the cursor reaches the bottom
  12734. ;    of the screen it stops.
  12735. ;
  12736.  
  12737. scrd:    ldy    ROWCRS
  12738.     cpy    #23        ; 24th line is at the bottom
  12739.     bcc    scrd1        ; move the cursor if less that 24
  12740.     bne    scrd2        ; do not move the cursor if greater than 24
  12741. scrd1:    iny
  12742.     ldx    COLCRS
  12743.     jsr    scrplt        ; put the cursor at its new position
  12744. scrd2:    rts            ; all done
  12745.  
  12746. ;
  12747. ;    scrl - move the cursor left stopping at the left side of the screen
  12748. ;
  12749. ;    Input:    Type of screen in scrtype
  12750. ;        Cursor coordinates in COLCRS, ROWCRS
  12751. ;
  12752. ;    Output: New cursor coordinates in COLCRS, ROWCRS
  12753. ;
  12754. ;    Registers Destroyed: A,X,Y
  12755. ;
  12756. ;    This routine moves the cursor left.  If the cursor reaches the left
  12757. ;    most side of the display, it stops.
  12758. ;
  12759.  
  12760. scrl:    ldx    COLCRS
  12761.     beq    scrl1        ; at left side of screen?
  12762.     dex
  12763.     ldy    ROWCRS
  12764.     jsr    scrplt        ; move the cursor to its new position
  12765. scrl1:    rts
  12766.  
  12767. ;
  12768. ;    scrr - move the cursor right stopping at the right side of the screen
  12769. ;
  12770. ;    Input:    Type of screen in scrtype
  12771. ;        Cursor coordinates in COLCRS, ROWCRS
  12772. ;
  12773. ;    Output: New cursor coordinates in COLCRS, ROWCRS
  12774. ;
  12775. ;    Registers Destroyed: A,X,Y
  12776. ;
  12777. ;    This routine moves the cursor right.  If the cursor reaches the right
  12778. ;    side of the screen it stops.
  12779. ;
  12780.  
  12781. scrr:    ldx    COLCRS
  12782.     cpx    #40        ; check if past right side
  12783.     lda    scrtype        ; in 40 column mode?
  12784.     beq    scrr1
  12785.     cpx    #80        ; check if past right side
  12786. scrr1:    bcs    scrr2
  12787.     inx            ; move the cursor right
  12788.     ldy    ROWCRS
  12789.     jsr    scrplt        ; move the cursor to its new position
  12790. scrr2:    rts            ; all done
  12791.  
  12792. ;
  12793. ;    scred0 - perform the Erase Display #0 VT100 function
  12794. ;
  12795. ;    Input: Type of screen to erase in scrtype
  12796. ;
  12797. ;    Output: None
  12798. ;
  12799. ;    Registers Destroyed: A,X,Y
  12800. ;
  12801. ;    This routine clears from the cursor position to the end of the screen.
  12802. ;    This routine works in 40 column mode, 80 column mode, or Commodore 128
  12803. ;    mode.
  12804. ;
  12805.  
  12806. scred0:    lda    ROWCRS        ; save the cursor y position
  12807.     pha
  12808.     jsr    screl0        ; erase from the cursor to the line
  12809. scred0c: inc    ROWCRS        ; do the next line
  12810.     lda    ROWCRS
  12811.     cmp    #24        ; on line number 24?
  12812.     bcs    scred0b        ; past line 24?  if so, stop
  12813. scred0a: jsr    screl2        ; erase the entire line
  12814.     jmp    scred0c
  12815. scred0b: pla            ; restore cursor y position
  12816.     sta    ROWCRS
  12817.     rts            ; all done
  12818.  
  12819. ;
  12820. ;    scred1 - perform the Erase Display #2 VT100 function
  12821. ;
  12822. ;    Input: Type of screen to erase in scrtype
  12823. ;
  12824. ;    Output: None
  12825. ;
  12826. ;    Registers Destroyed: A,X,Y
  12827. ;
  12828. ;    This routine clears from the beginning of the screen to the cursor.
  12829. ;    This routine works for 40 column mode, 80 column mode, and commodore
  12830. ;    128 mode.
  12831. ;
  12832.  
  12833. scred1:    lda    ROWCRS        ; save the cursor y position
  12834.     pha
  12835.     lda    #0
  12836.     sta    ROWCRS
  12837. scred1b: pla            ; cursors real position
  12838.     pha            ; keep it on the stack
  12839.     cmp    ROWCRS        ; on last line to erase?
  12840.     beq    scred1a        ; yes, erase it specially
  12841.     jsr    screl2        ; erase the entire line
  12842.     inc    ROWCRS
  12843.     jmp    scred1b
  12844. scred1a: pla            ; restore cursor y position
  12845.     sta    ROWCRS
  12846.     jsr    screl1        ; erase from beginning of line to cursor
  12847.     rts            ; all done
  12848.  
  12849. ;
  12850. ;    scred2 - perform the Erase Display #2 VT100 function (clear screen)
  12851. ;
  12852. ;    Input: Type of screen to erase in scrtype
  12853. ;
  12854. ;    Output: None
  12855. ;
  12856. ;    Registers Destroyed: A,X,Y
  12857. ;
  12858. ;    This routine clears the entire screen in either 40 column mode,
  12859. ;    80 column mode, or c128 mode.  It calls screl2 to do the dirty work.
  12860. ;
  12861.  
  12862. scred2:
  12863.     ldy    scrtype        ; what screen are we clearing?
  12864.     bne    scred2z
  12865.     lda    #ATCLR        ; E:, just tell it to clear
  12866.     jmp    sputch        ;  do this
  12867. scred2z:
  12868.     lda    ROWCRS        ; save the cursor y position
  12869.     pha
  12870.     lda    #0        ; move the cursor to the top
  12871.     sta    ROWCRS
  12872. scred2a: jsr    screl2        ; erase the line
  12873.     inc    ROWCRS        ; do the next line
  12874.     lda    ROWCRS
  12875.     cmp    #24        ; on line number 24?
  12876.     bcs    scred2b        ; yup, done
  12877.     bcc    scred2a        ; not yet.  do another line
  12878. scred2b: pla            ; restore cursor y position
  12879.     sta    ROWCRS
  12880.     rts            ; all done
  12881.  
  12882. ;
  12883. ;    screl0 - Perform the VT100 Erase Line function #0
  12884. ;
  12885. ;    Input:    Line number to erase in ROWCRS
  12886. ;        Screen type in scrtyp
  12887. ;    Output: None
  12888. ;
  12889. ;    Registers destroyed - A,X,Y
  12890. ;
  12891. ;    This routine erases from the cursor to the end of the line
  12892. ;
  12893.  
  12894. screl0:    jsr    scroff        ; cant use screen driver while curosr blinks
  12895.     ldy    scrtype        ; which routine to use
  12896.     jsr    case
  12897.     .word    scraeel0
  12898.     .word    scr40el0
  12899.     .word    scr80el0
  12900.  
  12901. ;
  12902. ;    screl1 - Perform the VT100 Erase Line function #1
  12903. ;
  12904. ;    Input:    Line number to erase in ROWCRS
  12905. ;        Screen type in scrtyp
  12906. ;    Output: None
  12907. ;
  12908. ;    Registers destroyed - A,X,Y
  12909. ;
  12910. ;    This routine erases from the beginning of line to the cursor
  12911. ;
  12912.  
  12913. screl1:    jsr    scroff        ; cant use screen driver while curosr blinks
  12914.     ldy    scrtype        ; which routine to use
  12915.     jsr    case
  12916.     .word    scraeel1
  12917.     .word    scr40el1
  12918.     .word    scr80el1
  12919.  
  12920. ;
  12921. ;    screl2 - Perform the VT100 Erase Line function #2
  12922. ;
  12923. ;    Input:    Line number to erase in ROWCRS
  12924. ;        Type of screen in scrtype
  12925. ;    Output:    None
  12926. ;
  12927. ;    Registers destroyed - A,X,Y
  12928. ;
  12929. ;    This routine erases one line compleatly.
  12930. ;
  12931.  
  12932. screl2:    
  12933.     jsr    scroff        ; cant use screen driver while cursor blinks
  12934.     ldy    scrtype        ; which routine to use to erase
  12935.     jsr    case        ; go to proper routine
  12936.     .word    scraeel2        ; erase one line on 40 column screen
  12937.     .word    scr40el2        ; erase one line on 80 column screen
  12938.     .word    scr80el2        ; abort with much fanfair
  12939.  
  12940. ;
  12941. ;    scrind - perfrom the VT100 index function (Move the screen one line)
  12942. ;
  12943. ;    Input:    Screen type in scrtyp
  12944. ;    Output:    None
  12945. ;
  12946. ;    Registers destroyed - A,X,Y
  12947. ;
  12948. ;    This routine scrolls the screen down one line. It calls either scraeind,
  12949. ;    scr40ind, or scr80ind depending on the screen type.
  12950. ;
  12951.  
  12952. scrind:    jsr    scroff        ; cant use screen driver while cursor blinks
  12953.     ldy    scrtype
  12954.     jsr    case
  12955.     .word    scraeind
  12956.     .word    scr40ind
  12957.     .word    scr80ind
  12958.  
  12959. ;
  12960. ;    scrri - perfrom the VT100 reverse index function (scroll backwards)
  12961. ;
  12962. ;    Input:    Screen type in scrtyp
  12963. ;    Output: Screen and color rams are changed
  12964. ;
  12965. ;    Registers destroyed - A,X,Y
  12966. ;
  12967. ;    This routine scrolls the screen up one line. It calls either scraeri,
  12968. ;    scr40ri, or scr80ri depending on the screen type.
  12969. ;
  12970.  
  12971. scrri:    jsr    scroff        ; cant use screen driver while cursor blinks
  12972.     ldy    scrtype
  12973.     jsr    case
  12974.     .word    scraeri
  12975.     .word    scr40ri
  12976.     .word    scr80ri
  12977.  
  12978. ;
  12979. ;    scrdl - Delete line
  12980. ;
  12981. ;    input:    current line
  12982. ;    output:    current line of display zapped, rest of scrolling region moves up to
  12983. ;        fill
  12984. ;
  12985. ;    zzz should check to make sure inside scroll rgn here
  12986. ;
  12987. scrdl:
  12988.     lda    top        ; get current scrolling rgn top
  12989.     pha            ; save it
  12990.     lda    ROWCRS        ; get current row
  12991.     sta    top        ; make it top of scroll rgn temporarily
  12992.     jsr    scrind        ; do an 'index', squeezing out current line
  12993.     pla            ; get old top back
  12994.     sta    top
  12995.     rts
  12996.  
  12997. ;
  12998. ;    scril - Insert line
  12999. ;
  13000. ;    input:    current line
  13001. ;    output:    Bottom line of scroll rgn zapped, blank line inserted at current
  13002. ;        line
  13003. ;
  13004. ;    zzz should check to make sure inside scroll rgn here
  13005. ;
  13006. scril:
  13007.     lda    top        ; get current scrolling rgn top
  13008.     pha            ; save it
  13009.     lda    ROWCRS        ; get current row
  13010.     sta    top        ; make it top of scroll rgn temporarily
  13011.     jsr    scrri        ; do a 'reverse index', squeezing out bottom line
  13012.     pla            ; get old top back
  13013.     sta    top
  13014.     rts
  13015.     
  13016. ;
  13017. ;    scrsav - save screen attributes and cursor position
  13018. ;
  13019. ;    Input:    screen attributes and cursor position
  13020. ;
  13021. ;    Output:    save1, save2, save3, ... save6
  13022. ;
  13023. ;    This routine saves the screen attributes and cursor position
  13024. ;    
  13025.  
  13026. scrsav:    lda    COLCRS
  13027.     sta    save1
  13028.     lda    ROWCRS
  13029.     sta    save2
  13030.     lda    alternt
  13031.     sta    save3
  13032.     lda    underln
  13033.     sta    save4
  13034.     lda    flash
  13035.     sta    save5
  13036.     lda    reverse
  13037.     sta    save6
  13038.     rts
  13039.  
  13040. ;
  13041. ;    scrlod - load the saved screen attributes and cursor position
  13042. ;
  13043. ;    Input:    save1, save2, save3, ... save6
  13044. ;
  13045. ;    This routine restores the saved screen attributes and cursor position
  13046. ;
  13047.  
  13048. scrlod:    ldx    save1
  13049.     ldy    save2
  13050.     jsr    scrplt
  13051.     lda    save3
  13052.     sta    alternt
  13053.     lda    save4
  13054.     sta    underln
  13055.     lda    save5
  13056.     sta    flash
  13057.     lda    save6
  13058.     sta    reverse
  13059.     rts
  13060.  
  13061. ;
  13062. ;    scrplt - plot the cursor
  13063. ;
  13064. ;    Input:    Cursor X position in X-reg
  13065. ;        Cursor Y position in Y-reg
  13066. ;
  13067. ;    Output: COLCRS and ROWCRS are set.
  13068. ;
  13069. ;    Registers destroyed - A,X,Y
  13070. ;
  13071. ;    This routine puts the cursor at X,Y.  It checks to make sure the
  13072. ;    cursor is being moved to a valid location before it moves the cursor.
  13073. ;
  13074.  
  13075. scrplt:
  13076.     cpy    #24        ; cant be greater than or equal to 24
  13077.     bmi    scrplt1        ; oops.  it was
  13078.     ldy    #23        ; ok, make it 23
  13079. scrplt1:
  13080.     cpy    #0        ; better be >= 0
  13081.     bpl    scrplt2
  13082.     ldy    #0
  13083. scrplt2:
  13084. ;
  13085. ; kludge.  Because of the way the auto wrap stuff works, we have to
  13086. ; allow the column to get to 80 (40)
  13087. ;
  13088.     cpx    #41        ; cant be greater than or equal to 40...
  13089.     lda    scrtype        ; ... in 40 column mode
  13090.     beq    scrplt4
  13091.     cpx    #81        ; compare with 80 if not in 40 column mode
  13092. scrplt4:
  13093.     bcs    scrplt9        ; oops.  Greater than the current margin
  13094.     tya            ; save the new y position    
  13095.     pha
  13096.     txa            ; save the new x position
  13097.     pha        
  13098.     jsr    scroff        ; turn off the cursor
  13099.     pla            ; get the new x position
  13100.     sta    COLCRS
  13101.     pla            ; get the new y position
  13102.     sta    ROWCRS
  13103. scrplt9: rts            ; all done
  13104.  
  13105. ;
  13106. ;    scroff - disable the cursor.
  13107. ;
  13108. ;    Input:    COLCRS, ROWCRS, curstat, curabrt, scrtype
  13109. ;
  13110. ;    Output: curabrt
  13111. ;
  13112. ;    Registers destroyed - A,X,Y
  13113. ;
  13114. ;    This routine disables the cursor.  It calls the proper screen driver
  13115. ;    to do the dirty work.
  13116. ;
  13117.  
  13118. scroff:    lda    curabrt        ; is the cursor flash already aborted?
  13119.     bne    scroff1        ; yes.
  13120.     lda    curstat        ; cursor light?
  13121.     beq    scroff1        ; yes.
  13122.     sta    curabrt        ; mark cursor flash as aborted
  13123.     jsr    scrtgl        ; toggle the cursor
  13124. scroff1: rts            ; all done
  13125.  
  13126. ;
  13127. ;    scrfls - flash the screen and cursor
  13128. ;
  13129. ;    Input:    curstat - status of cursor (light or dark)
  13130. ;        curabrt - flag indicating if cursor flash was aborted early.
  13131. ;        scrtype - type of screen
  13132. ;
  13133. ;    Output: curstat - curstat is toggled if time
  13134. ;        curabrt - curabrt is always cleared
  13135. ;
  13136. ;    Registers destroyed - A,X,Y
  13137. ;
  13138. ;    This routine flashes the screen and toggles the cursor.  It also
  13139. ;    stops the sound of the bell 6 jiffys after it started.  This routine
  13140. ;    should be called a frequently as possible.
  13141. ;
  13142.  
  13143. scrfls:    lda    curabrt        ; was the cursor flash aborted early?
  13144.     beq    scrfls1        ; no.  No need to light it.
  13145.     jsr    scrtgl        ; toggle the cursor
  13146.     lda    #0        ; clear the abort flag
  13147.     sta    curabrt
  13148. scrfls1: 
  13149. ;     jsr    rdtim        ; check the time 
  13150.     lda    RTCLOK+2    ; [jrd] get lo order time value
  13151.     tay            ; save the time for later use
  13152.     sec
  13153.     sbc    lpcnt        ; subtract the time the bell started
  13154.     cmp    #6        ; been 6 jiffys since it started?
  13155.     bcc    scrfls3        ; nope.  Dont stop the bell yet
  13156. ;
  13157. ; This screws up POKEY
  13158. ;
  13159. ;    lda    #0
  13160. ;    sta    AUDC4        ; stop the bell
  13161.     lda    bordclr        ; unflash the border
  13162.     sta    COLOR4
  13163. scrfls3: tya            ; check timer value again
  13164.     sec
  13165.     sbc    cntdown
  13166.     cmp    #20        ; have  36 jiffies elapsed?
  13167.     bcs    scrfls2        ; yes they have
  13168.     rts            ; no they havent.  stop here
  13169. scrfls2: sty    cntdown        ; reset the countdown timerldy    
  13170.     jsr    scrtgl        ; toggle the cursor status
  13171.     ldy    scrtype        ; flash the flashing characters
  13172.     jsr    case
  13173.     .word    scraefls
  13174.     .word    scr40fls
  13175.     .word    scr80fls
  13176.  
  13177. ;
  13178. ;    scrtgl - Toggle the cursor
  13179. ;
  13180. ;    Input:    COLCRS - x coordinate of cursor
  13181. ;        ROWCRS - y coordinate of cursor
  13182. ;        Type of screen in scrtype
  13183. ;
  13184. ;    Output: None
  13185. ;
  13186. ;    Registers destroyed - A,X,Y
  13187. ;
  13188. ;    this routine calls the screen driver to toggle the cursor
  13189. ;
  13190.  
  13191. scrtgl:    lda    curstat        ; keep track if cursor is dark or light
  13192.     eor    #$01
  13193.     sta    curstat
  13194.     ldy    scrtype        ; call the screen driver
  13195.     jsr    case
  13196.     .word    scraetgl
  13197.     .word    scr40tgl
  13198.     .word    scr80tgl
  13199.  
  13200.  
  13201. .SBTTL    80 Column screen driver
  13202.  
  13203. ;
  13204. ;    These routines manipulate the screen in 80 column mode.
  13205. ;
  13206.  
  13207. ;
  13208. ;    scr40ini - initilize 40/80 column screen during powerup
  13209. ;
  13210. ;    Input:    None
  13211. ;    Output: scrtype set to use 80 columns
  13212. ;
  13213. ;    Registers destroyed - A
  13214. ;
  13215. ;    This routine does all of the powerup initilization necessary for
  13216. ;    80 columns that was not done in scraeini, and sets the screen type
  13217. ;    to 80 columns.
  13218. ;
  13219.  
  13220. scr40ini:
  13221.     lda    #scr40
  13222.     sta    scrtype
  13223.     rts
  13224.  
  13225. ;
  13226. ;    scr40ent - enter the 40/80 column screen driver
  13227. ;
  13228. ;    Input:    None
  13229. ;
  13230. ;    Output: None
  13231. ;
  13232. ;    Registers destroyed - A,X,Y
  13233. ;
  13234. ;    This routine starts the 40/80 column screen driver.
  13235. ;    well, sort of.  set the display list to point to ours, and build font40
  13236. ;
  13237.  
  13238. scr40ent:
  13239.     jsr    makedl40
  13240.     lda    scr40dl
  13241.     ldy    scr40dl+1
  13242.     jsr    setdlist
  13243.     lda    #scr40        ; we're now in 40/80 mode
  13244.     sta    scrtype
  13245. ;
  13246. ; now make up the font we want.  Copy the builtin one, and stuff in
  13247. ; braces, tilde, graphics
  13248. ;
  13249.     ldy    #0        ; zero the y-reg
  13250.     ldx    newchar,y    ; number of characters defined in this chunk
  13251. scr40ent1: iny
  13252.     lda    newchar,y    ; source of characters (lo order)
  13253.     sta    source
  13254.     iny
  13255.     lda    newchar,y    ; source of characters (hi order)
  13256.     sta    source+1
  13257.     iny
  13258.     lda    newchar,y    ; destination of characters (lo order)
  13259.     sta    dest
  13260.     iny
  13261.     lda    newchar,y    ; destination of characters (hi order)
  13262.     sta    dest+1
  13263.     iny
  13264.     tya            ; save y-reg across call to move8
  13265.     pha
  13266.     jsr    move8
  13267.     pla            ; restore y-reg
  13268.     tay
  13269.     ldx    newchar,y    ; number of characters in this chunk (0=end)
  13270.     bne    scr40ent1    ; loop until done
  13271.     lda    #font40^    ; now point CTIA at it
  13272.     sta    CHBAS
  13273.     rts
  13274.  
  13275. ;
  13276. ;    Newchar - character mapping table
  13277. ;
  13278. ;    This table is used to define the 40 column character set
  13279. ;    The format of this table is:
  13280. ;        Number of characters to copy    (byte)
  13281. ;        Source of characters        (word)
  13282. ;        Destination for characters    (word)
  13283. ;
  13284. newchar:
  13285.     .byte    128        ; the whole thing
  13286.     .word    $E000        ; atari builtin font
  13287.     .word    font40        ; our font table
  13288. ;
  13289. ; graphics characters
  13290. ;
  13291.     .byte    1
  13292.     .word    $E000+<84*8>    ; blot
  13293.     .word    font40+<64*8>
  13294.  
  13295.     .byte    9
  13296.     .word    charg97        ; square blot .. vt
  13297.     .word    font40+<65*8>
  13298.  
  13299.     .byte    2        ; 2 more chars
  13300.     .word    charg111    ;  for scan 1, scan3
  13301.     .word    font40+<79*8>
  13302.  
  13303.     .byte    2        ; and 2 more
  13304.     .word    charg114    ;  for scan 7, 9
  13305.     .word    font40+<82*8>
  13306.  
  13307.     .byte    1
  13308.     .word    $E000+<67*8>    ; down right corner
  13309.     .word    font40+<74*8>
  13310.  
  13311.     .byte    1
  13312.     .word    $E000+<69*8>    ; up right corner
  13313.     .word    font40+<75*8>
  13314.  
  13315.     .byte    1
  13316.     .word    $E000+<81*8>    ; up left
  13317.     .word    font40+<76*8>
  13318.  
  13319.     .byte    1
  13320.     .word    $E000+<90*8>    ; down left
  13321.     .word    font40+<77*8>
  13322.  
  13323.     .byte    1
  13324.     .word    $E000+<83*8>    ; center cross
  13325.     .word    font40+<78*8>
  13326.  
  13327.     .byte    1
  13328.     .word    $E000+<82*8>    ; scan 5
  13329.     .word    font40+<81*8>
  13330.  
  13331.     .byte    1
  13332.     .word    $E000+<124*8>    ; vert bar
  13333.     .word    font40+<88*8>
  13334.  
  13335.     .byte    1
  13336.     .word    $E000+<65*8>    ; left t
  13337.     .word    font40+<84*8>
  13338.  
  13339.     .byte    1
  13340.     .word    $E000+<68*8>    ; right t
  13341.     .word    font40+<85*8>
  13342.  
  13343.     .byte    1
  13344.     .word    $E000+<88*8>    ; bot t
  13345.     .word    font40+<86*8>
  13346.  
  13347.     .byte    1
  13348.     .word    $E000+<87*8>    ; top t
  13349.     .word    font40+<87*8>
  13350.  
  13351.  
  13352. ; more later zzz
  13353.     .byte    4        ; { | } ~
  13354.     .word    char123
  13355.     .word    font40+<123*8>
  13356.  
  13357.     .byte 0        ; end of table
  13358.  
  13359. ;
  13360. ;    charXXX - 40 column character definitions not available in rom
  13361. ;
  13362. charg97:
  13363.     .byte    $CC,$CC,$33,$33,$CC,$CC,$33,$33    ; square blot
  13364.     .byte    $90,$90,$F0,$90,$8E,$08,$08,$08    ; h/t
  13365.     .byte    $F0,$80,$E0,$9E,$90,$1C,$10,$10    ; f/f
  13366.     .byte    $30,$40,$40,$3C,$12,$12,$1C,$12    ; c/r
  13367.     .byte    $40,$40,$40,$7E,$10,$1C,$10,$10    ; l/f
  13368.     .byte    $18,$24,$24,$18,$00,$00,$00,$00    ; degrees
  13369.     .byte    $08,$08,$3E,$08,$08,$00,$3E,$00    ; plus/minus
  13370.     .byte    $48,$68,$58,$48,$40,$08,$0E,$00    ; n/l
  13371.     .byte    $44,$44,$28,$10,$3E,$08,$08,$08    ; v/t
  13372. charg111:
  13373.     .byte    $FF,$FF,$00,$00,$00,$00,$00,$00    ; scan 1
  13374.     .byte    $00,$FF,$FF,$00,$00,$00,$00,$00    ; scan 3
  13375. charg114:
  13376.     .byte    $00,$00,$00,$00,$00,$FF,$FF,$00    ; scan 7
  13377.     .byte    $00,$00,$00,$00,$00,$00,$FF,$FF    ; scan 9
  13378.  
  13379. char123:
  13380.     .byte    $0E,$18,$18,$78,$18,$18,$0E,$00    ; {
  13381.     .byte    $18,$18,$18,$18,$18,$18,$18,$00 ; |
  13382.     .byte    $70,$18,$18,$1E,$18,$18,$70,$00    ; }
  13383.     .byte    $00,$00,$3B,$6E,$00,$00,$00,$00    ; ~
  13384.  
  13385. ;
  13386. ;    scr40ext - exit the 80 column screen driver
  13387. ;
  13388. ;    Input:    None
  13389. ;    Output: None
  13390. ;
  13391. ;    Registers destroyed - A,X,Y
  13392. ;
  13393. ;    This routine exits the 40/80 column screen driver.
  13394. ;    for now, just use the E: one
  13395. ;
  13396.  
  13397. scr40ext:
  13398.     lda    #$E0        ; put font pointer back
  13399.     sta    CHBAS
  13400.     jmp    scraeent
  13401.  
  13402. ;
  13403. ;    scr40put - put a character at COLCRS, ROWCRS
  13404. ;
  13405. ;    Input:    character to put in a-reg (use funny ascii)
  13406. ;    Output: None
  13407. ;
  13408. ;    Registers destroyed - A,X,Y
  13409. ;
  13410. ;    This routine puts a character at screen position COLCRS,ROWCRS.  
  13411. ;    This routine does advance the cursor position.
  13412. ;
  13413. scr40put:
  13414.     pha            ; save the char code
  13415.     ldx    COLCRS        ; get col nbr
  13416.     ldy    ROWCRS        ; and row nbr
  13417.     jsr    scr40adrt    ; figure out character address
  13418.     pla            ; get the char back
  13419.     cmp    #$60        ; lower case?
  13420.     bcc    scr40p0        ; (blt) no, offset it
  13421. ;
  13422. ; handle graphics if necessary.  Look at the char set designator
  13423. ; in either csg0 or csg1 (if altcs is set).  If it's csgraf, sub
  13424. ; $20 from the char, to get graphics.  If it's csascii, leave the
  13425. ; char alone.
  13426. ;
  13427.     ldx    csg0        ; assume g0 for starters
  13428.     ldy    altcs        ; alt char set?
  13429.     beq    scr40px        ; no, use this one
  13430.     ldx    csg1        ; ok, use the alt one
  13431. scr40px:
  13432.     cpx    #csascii    ; ascii font?
  13433.     beq    scr40p1        ; yes, leave lc char the way it is
  13434. scr40p0:
  13435.     sec
  13436.     sbc    #$20        ; compensate for atari font layout
  13437. scr40p1:
  13438.     ldy    reverse        ; reverse vid?
  13439.     beq    scr40p2        ; nope, go ahead
  13440.     ora    #$80        ; or in hi bit for reverse vid.
  13441. scr40p2:
  13442.     ldy    #0
  13443.     sta    (dest),y    ; and shove it in screen mem
  13444.     inc    COLCRS        ; bump column
  13445.     jmp    scr40pan    ; and go make sure we're visible
  13446.  
  13447. ;
  13448. ;    Scrpan        call scr40pan if necessary
  13449. ;
  13450. scrpan:
  13451.     lda    scrtype        ; what do we have here?
  13452.     cmp    #scr40        ; 40 col pannable?
  13453.     beq    scr40pan    ; yup, go do it
  13454.     rts
  13455. ;
  13456. ;    Scr40pan    make the current cursor pos visible by
  13457. ;    panning left or right as needed
  13458. ;
  13459. scr40pan:
  13460.     lda    COLCRS        ; pan to make this column visible
  13461.     sec
  13462.     sbc    panval        ; subtract current pan value
  13463. ;
  13464. ; want adjusted (visible) column between 2 and 37, if possible
  13465. ;
  13466.     bmi    scr40pl        ; neg, pan left
  13467.     cmp    #2        ; < 2?
  13468.     bpl    scr40pr        ; nope, try right side
  13469. scr40pl:
  13470.     lda    COLCRS        ; yes, get real col
  13471.     sec
  13472.     sbc    #2        ; - 2
  13473.     jmp    scr40p4        ; and try to pan to there.
  13474. scr40pr:
  13475.     cmp    #37        ; > 37?
  13476.     bmi    scr40p9        ; nope, we're ok.  return
  13477.     lda    COLCRS        ; get real col
  13478.     sec
  13479.     sbc    #37        ; - 37
  13480.     jmp    scr40p5        ; and try to pan to there.
  13481. scr40p4:
  13482.     cmp    #0        ; only left to zero, please
  13483.     bpl    scr40p5
  13484.     lda    #0
  13485. scr40p5:
  13486.     cmp    #40        ; better be less...
  13487.     bmi    scr40p6        ; it is, ok
  13488.     lda    #40        ; max at 40
  13489. scr40p6:
  13490.     sta    panval
  13491.     jsr    pan40        ; make it happen
  13492. scr40p9:
  13493.     rts
  13494. ;
  13495. ;    Font80 - Character definitions
  13496. ;
  13497. ;    this defines the shape of the characters in 80 column mode
  13498. ;    this table is in ascii sequence, offset by $20, ei 'space' is
  13499. ;    the first thing here.  Graphics chars for VT100 line drawing
  13500. ;    mode are the last 32 chars worth.
  13501. ;
  13502. font80:
  13503.     .byte    $00,$00,$00,$00,$00,$00,$00,$00    ;    ' '
  13504.     .byte    $00,$44,$44,$44,$44,$00,$44,$00    ;    '!'
  13505.     .byte    $00,$AA,$AA,$00,$00,$00,$00,$00    ;    '"'
  13506.     .byte    $00,$AA,$EE,$AA,$EE,$AA,$00,$00    ;    '#'
  13507.     .byte    $44,$66,$88,$44,$22,$EE,$44,$00    ;    '$'
  13508.     .byte    $00,$99,$AA,$22,$55,$99,$00,$00    ;    '%'
  13509.     .byte    $00,$44,$AA,$44,$AA,$AA,$55,$00    ;    '&'
  13510.     .byte    $00,$22,$44,$00,$00,$00,$00,$00    ;    '''
  13511.     .byte    $00,$22,$44,$44,$44,$44,$22,$00    ;    '('
  13512.     .byte    $00,$44,$22,$22,$22,$22,$44,$00    ;    ')'
  13513.     .byte    $00,$99,$66,$FF,$66,$99,$00,$00    ;    '*'
  13514.     .byte    $00,$00,$44,$EE,$44,$00,$00,$00    ;    '+'
  13515.     .byte    $00,$00,$00,$00,$00,$22,$22,$44    ;    ','
  13516.     .byte    $00,$00,$00,$EE,$00,$00,$00,$00    ;    '-'
  13517.     .byte    $00,$00,$00,$00,$00,$00,$44,$00    ;    '.'
  13518.     .byte    $00,$22,$22,$44,$44,$88,$88,$00    ;    '/'
  13519.     .byte    $00,$44,$AA,$EE,$AA,$AA,$44,$00    ;    '0'
  13520.     .byte    $00,$44,$CC,$44,$44,$44,$EE,$00    ;    '1'
  13521.     .byte    $00,$44,$AA,$22,$44,$88,$EE,$00    ;    '2'
  13522.     .byte    $00,$EE,$22,$44,$22,$22,$CC,$00    ;    '3'
  13523.     .byte    $00,$AA,$AA,$AA,$EE,$22,$22,$00    ;    '4'
  13524.     .byte    $00,$EE,$88,$CC,$22,$22,$CC,$00    ;    '5'
  13525.     .byte    $00,$44,$88,$CC,$AA,$AA,$44,$00    ;    '6'
  13526.     .byte    $00,$EE,$22,$22,$44,$88,$88,$00    ;    '7'
  13527.     .byte    $00,$44,$AA,$44,$AA,$AA,$44,$00    ;    '8'
  13528.     .byte    $00,$44,$AA,$AA,$66,$44,$88,$00    ;    '9'
  13529.     .byte    $00,$00,$44,$00,$00,$44,$00,$00    ;    ':'
  13530.     .byte    $00,$00,$44,$00,$44,$44,$88,$00    ;    ';'
  13531.     .byte    $00,$22,$44,$88,$44,$22,$00,$00    ;    '<'
  13532.     .byte    $00,$00,$EE,$00,$EE,$00,$00,$00    ;    '='
  13533.     .byte    $00,$88,$44,$22,$44,$88,$00,$00    ;    '>'
  13534.     .byte    $00,$44,$AA,$22,$44,$00,$44,$00    ;    '?'
  13535.     .byte    $00,$44,$EE,$AA,$88,$66,$00,$00    ;    '@'
  13536.     .byte    $00,$44,$AA,$AA,$EE,$AA,$AA,$00    ;    'A'
  13537.     .byte    $00,$CC,$AA,$CC,$AA,$AA,$CC,$00    ;    'B'
  13538.     .byte    $00,$66,$88,$88,$88,$88,$66,$00    ;    'C'
  13539.     .byte    $00,$CC,$AA,$AA,$AA,$AA,$CC,$00    ;    'D'
  13540.     .byte    $00,$EE,$88,$CC,$88,$88,$EE,$00    ;    'E'
  13541.     .byte    $00,$EE,$88,$CC,$88,$88,$88,$00    ;    'F'
  13542.     .byte    $00,$44,$AA,$88,$AA,$AA,$44,$00    ;    'G'
  13543.     .byte    $00,$AA,$AA,$EE,$AA,$AA,$AA,$00    ;    'H'
  13544.     .byte    $00,$EE,$44,$44,$44,$44,$EE,$00    ;    'I'
  13545.     .byte    $00,$66,$22,$22,$22,$AA,$44,$00    ;    'J'
  13546.     .byte    $00,$AA,$AA,$CC,$AA,$AA,$AA,$00    ;    'K'
  13547.     .byte    $00,$88,$88,$88,$88,$88,$EE,$00    ;    'L'
  13548.     .byte    $00,$AA,$EE,$AA,$AA,$AA,$AA,$00    ;    'M'
  13549.     .byte    $00,$CC,$AA,$AA,$AA,$AA,$AA,$00    ;    'N'
  13550.     .byte    $00,$44,$AA,$AA,$AA,$AA,$44,$00    ;    'O'
  13551.     .byte    $00,$CC,$AA,$AA,$CC,$88,$88,$00    ;    'P'
  13552.     .byte    $00,$44,$AA,$AA,$AA,$AA,$44,$22    ;    'Q'
  13553.     .byte    $00,$CC,$AA,$AA,$CC,$AA,$AA,$00    ;    'R'
  13554.     .byte    $00,$66,$88,$44,$22,$22,$CC,$00    ;    'S'
  13555.     .byte    $00,$EE,$44,$44,$44,$44,$44,$00    ;    'T'
  13556.     .byte    $00,$AA,$AA,$AA,$AA,$AA,$EE,$00    ;    'U'
  13557.     .byte    $00,$AA,$AA,$AA,$AA,$AA,$44,$00    ;    'V'
  13558.     .byte    $00,$AA,$AA,$AA,$AA,$EE,$AA,$00    ;    'W'
  13559.     .byte    $00,$AA,$AA,$44,$AA,$AA,$AA,$00    ;    'X'
  13560.     .byte    $00,$AA,$AA,$AA,$44,$44,$44,$00    ;    'Y'
  13561.     .byte    $00,$EE,$22,$44,$88,$88,$EE,$00    ;    'Z'
  13562.     .byte    $00,$EE,$88,$88,$88,$88,$EE,$00    ;    '['
  13563.     .byte    $00,$88,$88,$44,$44,$22,$22,$00    ;    '\'
  13564.     .byte    $00,$EE,$22,$22,$22,$22,$EE,$00    ;    ']'
  13565.     .byte    $00,$44,$AA,$00,$00,$00,$00,$00    ;    '^'
  13566.     .byte    $00,$00,$00,$00,$00,$00,$00,$FF    ;    '_'
  13567.     .byte    $00,$44,$22,$00,$00,$00,$00,$00    ;    '`'
  13568.     .byte    $00,$00,$CC,$22,$66,$AA,$EE,$00    ;    'a'
  13569.     .byte    $00,$88,$CC,$AA,$AA,$AA,$CC,$00    ;    'b'
  13570.     .byte    $00,$00,$66,$88,$88,$88,$66,$00    ;    'c'
  13571.     .byte    $00,$22,$66,$AA,$AA,$AA,$66,$00    ;    'd'
  13572.     .byte    $00,$00,$44,$AA,$EE,$88,$66,$00    ;    'e'
  13573.     .byte    $00,$66,$88,$CC,$88,$88,$88,$00    ;    'f'
  13574.     .byte    $00,$00,$44,$AA,$AA,$66,$22,$CC    ;    'g'
  13575.     .byte    $00,$88,$CC,$AA,$AA,$AA,$AA,$00    ;    'h'
  13576.     .byte    $00,$44,$00,$44,$44,$44,$44,$00    ;    'i'
  13577.     .byte    $00,$22,$00,$22,$22,$22,$AA,$44    ;    'j'
  13578.     .byte    $00,$88,$AA,$AA,$CC,$AA,$AA,$00    ;    'k'
  13579.     .byte    $00,$CC,$44,$44,$44,$44,$EE,$00    ;    'l'
  13580.     .byte    $00,$00,$AA,$EE,$AA,$AA,$AA,$00    ;    'm'
  13581.     .byte    $00,$00,$CC,$AA,$AA,$AA,$AA,$00    ;    'n'
  13582.     .byte    $00,$00,$44,$AA,$AA,$AA,$44,$00    ;    'o'
  13583.     .byte    $00,$00,$CC,$AA,$AA,$CC,$88,$88    ;    'p'
  13584.     .byte    $00,$00,$44,$AA,$AA,$66,$22,$33    ;    'q'
  13585. ;    .byte    $00,$00,$66,$88,$88,$88,$88,$00    ;    'r'
  13586.     .byte    $00,$00,$CC,$AA,$88,$88,$88,$00    ;    'r', experimental
  13587.     .byte    $00,$00,$66,$88,$44,$22,$CC,$00    ;    's'
  13588.     .byte    $00,$44,$EE,$44,$44,$44,$66,$00    ;    't'
  13589.     .byte    $00,$00,$AA,$AA,$AA,$AA,$EE,$00    ;    'u'
  13590.     .byte    $00,$00,$AA,$AA,$AA,$AA,$44,$00    ;    'v'
  13591.     .byte    $00,$00,$AA,$AA,$AA,$EE,$AA,$00    ;    'w'
  13592.     .byte    $00,$00,$AA,$AA,$44,$AA,$AA,$00    ;    'x'
  13593.     .byte    $00,$00,$AA,$AA,$AA,$66,$22,$CC    ;    'y'
  13594.     .byte    $00,$00,$EE,$22,$44,$88,$EE,$00    ;    'z'
  13595.     .byte    $66,$44,$44,$CC,$44,$44,$66,$00    ;    '{'
  13596.     .byte    $44,$44,$44,$44,$44,$44,$44,$00    ;    '|'
  13597.     .byte    $66,$22,$22,$33,$22,$22,$66,$00    ;    '}'
  13598.     .byte    $00,$55,$AA,$00,$00,$00,$00,$00    ;    '~'
  13599.     .byte    $00,$00,$00,$00,$00,$00,$00,$00    ; space after tilde?
  13600. ;
  13601. ;    graphics, chars $60 thru $7f
  13602. ;
  13603.     .byte    $00,$44,$44,$EE,$EE,$44,$44,$00    ; blot
  13604.     .byte    $AA,$55,$AA,$55,$AA,$55,$AA,$55    ; square blot
  13605.     .byte    $00,$AA,$EE,$AA,$77,$22,$22,$00    ; h/t
  13606.     .byte    $00,$EE,$CC,$88,$77,$66,$44,$00    ; f/f
  13607.     .byte    $00,$CC,$88,$EE,$55,$66,$55,$00    ; c/r
  13608.     .byte    $00,$88,$88,$EE,$77,$66,$44,$00    ; l/f
  13609.     .byte    $00,$EE,$AA,$EE,$00,$00,$00,$00    ; degrees
  13610.     .byte    $00,$00,$44,$EE,$44,$44,$EE,$00    ; plus/minus
  13611.     .byte    $00,$AA,$EE,$AA,$44,$44,$77,$00    ; n/l
  13612.     .byte    $00,$AA,$AA,$44,$77,$22,$22,$00    ; v/t
  13613.     .byte    $44,$44,$44,$CC,$00,$00,$00,$00    ; down right corner
  13614.     .byte    $00,$00,$00,$CC,$44,$44,$44,$44    ; up right corner
  13615.     .byte    $00,$00,$00,$77,$44,$44,$44,$44    ; up left corner
  13616.     .byte    $44,$44,$44,$77,$00,$00,$00,$00    ; down left corner
  13617.     .byte    $44,$44,$44,$FF,$44,$44,$44,$44    ; center cross
  13618.     .byte    $FF,$00,$00,$00,$00,$00,$00,$00    ; scan 1
  13619.     .byte    $00,$FF,$00,$00,$00,$00,$00,$00 ; scan 3 (really 2)
  13620.     .byte    $00,$00,$00,$FF,$00,$00,$00,$00 ; scan 5 (really 4)
  13621.     .byte    $00,$00,$00,$00,$00,$FF,$00,$00    ; scan 7 (really 6)
  13622.     .byte    $00,$00,$00,$00,$00,$00,$00,$FF    ; scan 9 (really 8)
  13623.     .byte    $44,$44,$44,$77,$44,$44,$44,$44    ; left t
  13624.     .byte    $44,$44,$44,$CC,$44,$44,$44,$44    ; right t
  13625.     .byte    $44,$44,$44,$FF,$00,$00,$00,$00    ; bottom t
  13626.     .byte    $00,$00,$00,$FF,$44,$44,$44,$44    ; top t
  13627.     .byte    $44,$44,$44,$44,$44,$44,$44,$44    ; vert bar
  13628.     .byte    $00,$22,$44,$88,$44,$22,$EE,$00    ; <=
  13629.     .byte    $00,$88,$44,$22,$44,$88,$EE,$00    ; >=
  13630.     .byte    $00,$00,$00,$EE,$AA,$AA,$AA,$00    ; pi
  13631.     .byte    $00,$22,$EE,$44,$EE,$88,$00,$00    ; not equal
  13632.     .byte    $00,$CC,$88,$CC,$88,$88,$EE,$00    ; lbs Sterling
  13633.     .byte    $00,$00,$00,$66,$66,$00,$00,$00    ; center dot
  13634. ; $7f ever used?  if so, it goes here
  13635.  
  13636. ;
  13637. ;    scr40el0 - Perform the vt100 erase line function #0 on 80 column screen
  13638. ;
  13639. ;    Input:    number of line to erase in rowcrs
  13640. ;    Output: None
  13641. ;
  13642. ;    Registers destroyed - A,X,Y
  13643. ;
  13644. ;    This routine erases from the cursor to the end of the line
  13645. ;
  13646.  
  13647. scr40el0:
  13648.     ldy    ROWCRS
  13649.     ldx    COLCRS
  13650.     jsr    scr40adrt    ; figure out where to start
  13651.     ldy    #0
  13652.     lda    #80        ; subtract current col to get count
  13653.     sec
  13654.     sbc    COLCRS
  13655.     beq    scr40el0z    ; done!
  13656.     tax
  13657.     lda    #0        ; space minus offset
  13658.     jsr    fillx        ; fill x many with (a)
  13659. scr40el0z:
  13660.     rts            ; all done
  13661.  
  13662. ;
  13663. ;    scr40el1 - Perform the VT100 Erase Line function #1 on 80 column screen
  13664. ;
  13665. ;    Input:    Number of line to erase in ROWCRS
  13666. ;    Output: None
  13667. ;
  13668. ;    Registers destroyed - A,X,Y
  13669. ;
  13670. ;    This routine erases from the beginning of line to cursor
  13671. ;
  13672.  
  13673. scr40el1:
  13674.     ldy    ROWCRS
  13675.     ldx    #0
  13676.     jsr    scr40adrt    ; compute the cursors address
  13677.     ldy    #0        ; index from start in screen mem
  13678.     ldx    COLCRS        ; this many
  13679.     beq    scr40el1z
  13680.     lda    #0        ; space minue offset
  13681.     jsr    fillx        ; fill x many
  13682. scr40el1z:
  13683.     rts            ; all done
  13684.  
  13685. ;
  13686. ;    scr40el2 - Perform the VT100 Erase Line function #2 on 40/80 column screen
  13687. ;
  13688. ;    Input:    Number of line to erase in ROWCRS
  13689. ;    Output: None
  13690. ;
  13691. ;    Registers destroyed - A,X,Y
  13692. ;
  13693. ;    This routine erases one line compleatly from the 40/80 column display.
  13694. ;
  13695.  
  13696. scr40el2:
  13697.     lda    COLCRS
  13698.     pha            ; save cursor temporarily
  13699.     lda    #0
  13700.     sta    COLCRS
  13701.     jsr    scr40el0    ; whack from temp cursor to eol
  13702.     pla
  13703.     sta    COLCRS        ; put it back
  13704.     rts
  13705.  
  13706. ;
  13707. ;    scr40ind - perform the VT100 index function (scroll the screen)
  13708. ;
  13709. ;    Input:    None
  13710. ;    Output: None
  13711. ;
  13712. ;    Registers destroyed - A,X,Y
  13713. ;
  13714. ;    This routine scrolls the screen in 40/80 column mode.  Only the area
  13715. ;    in the scrolling region is changed.
  13716. ;
  13717.  
  13718. scr40ind:
  13719.     lda    top        ; get top row to scroll
  13720.     sta    strptr        ; we'll use that as row counter
  13721. scr40ind1:
  13722.     tay            ; get row into y
  13723.     iny            ; top + 1
  13724.     ldx    #0        ; col 1 again
  13725.     jsr    scr40adrt
  13726.     lda    dest        ; this wants
  13727.     sta    source        ;  to be the
  13728.     lda    dest+1        ;   source addr
  13729.     sta    source+1
  13730.     ldy    strptr        ; get row again
  13731.     ldx    #0        ; col 1
  13732.     jsr    scr40adrt    ; find address
  13733.     ldx    #80        ; byte count
  13734.     jsr    movex        ; move x many
  13735.     inc    strptr        ; bump row counter
  13736.     lda    strptr        ; get it
  13737.     cmp    bot        ; we there yet?
  13738.     bcc    scr40ind1    ; less than, go back for more
  13739.  
  13740.     ldx    #0
  13741.     ldy    bot        ; clear bottom line
  13742.     jsr    scr40adrt
  13743.     ldx    #80        ; byte count
  13744.     lda    #0        ; space minus offset
  13745.     jsr    fillx        ; fill x many
  13746.     rts            ; go home
  13747.  
  13748. ;
  13749. ;    scr40ri - perform the VT100 reverse index function (scroll backwards)
  13750. ;
  13751. ;    Input:    None
  13752. ;    Output: None
  13753. ;
  13754. ;    Registers destroyed - A,X,Y
  13755. ;
  13756. ;    This routine scrolls the screen in 80 column mode.  Only the area
  13757. ;    in the scrolling region is changed.
  13758. ;
  13759. scr40ri:
  13760.     lda    bot        ; bottom row
  13761.     sta    strptr        ; handy temp row counter
  13762. scr40ri1:
  13763.     tay            ; get it into Y
  13764.     dey            ; bot - 1
  13765.     ldx    #0        ; col 1 again
  13766.     jsr    scr40adrt
  13767.     lda    dest        ; this wants
  13768.     sta    source        ;  to be the
  13769.     lda    dest+1        ;   source addr
  13770.     sta    source+1
  13771.     ldy    strptr        ; row again
  13772.     ldx    #0        ; col 1
  13773.     jsr    scr40adrt    ; find address
  13774.     ldx    #80        ; byte count
  13775.     jsr    movex
  13776.     dec    strptr        ; dec row index
  13777.     lda    strptr        ; get it
  13778.     cmp    top        ; we there yet?
  13779.     bne    scr40ri1    ; nope, do anoter one
  13780.  
  13781.     ldx    #0
  13782.     ldy    top        ; clear bottom line
  13783.     jsr    scr40adrt
  13784.     ldx    #80
  13785.     lda    #0        ; space minus offset
  13786.     jsr    fillx
  13787.     rts            ; go home
  13788.  
  13789. ;
  13790. ;    scr40fls - flash the screen and cursor in 80 column mode
  13791. ;
  13792. ;    Input:    None
  13793. ;    Output: None
  13794. ;
  13795. ;    Registers destroyed - A,X,Y
  13796. ;
  13797. ;    This routine flashes the screen in 40/80 column mode
  13798. ;    No op on Atari...
  13799. ;
  13800.  
  13801. scr40fls: rts
  13802.  
  13803. ;
  13804. ;    scr40tgl - toggle the cursor in 40/80 column mode
  13805. ;
  13806. ;    Input:    None
  13807. ;    Output: None
  13808. ;
  13809. ;    Registers destroyed - A,X,Y
  13810. ;
  13811. ;    This routine toggles the cursor in 80 column mode.
  13812. ;
  13813.  
  13814. scr40tgl:
  13815. ;    ldy    ROWCRS        ; compute cursor address
  13816. ;    ldx    COLCRS
  13817.     sec
  13818.     jsr    ploth        ; filter for rightmost col
  13819.     jsr    scr40adrt
  13820.     ldy    #0
  13821.     lda    (dest),y    ; get old character value
  13822.     eor    #$80        ; toggle hi bit
  13823.     sta    (dest),y    ; stick it back
  13824. scr40tgl1: rts
  13825.  
  13826.  
  13827. ;
  13828. ;    scr40adr - calculate 80*y+x
  13829. ;
  13830. ;    Input:    numbers in x-reg and y-reg
  13831. ;    Output: dest
  13832. ;
  13833. ;    Registers destroyed - A,Y
  13834. ;
  13835. ;    This routine calculates 80*y+x and puts the result in dest.  If x > 80,
  13836. ;    one is subtracted first.  This will happen after a character is printed
  13837. ;    on the last character on a line.  This routine is for calculating
  13838. ;    screen addresses.
  13839. ;
  13840.  
  13841. scr40adr:
  13842.     sty    dest        ; put y-reg in dest
  13843.     lda    #0        ; zero extend
  13844.     sta    dest+1
  13845.     asl    dest        ; multiplied by 2
  13846.     rol    dest+1
  13847.     asl    dest        ; multiplied by 4
  13848.     rol    dest+1
  13849.     tya            ; add in y to get 5*y
  13850.     adc    dest        ; carry is clear
  13851.     sta    dest
  13852.     bcc    scr40adr1
  13853.     inc    dest+1
  13854. scr40adr1: asl    dest        ; multiplied by 10
  13855.     rol    dest+1
  13856.     asl    dest        ; multiplied by 20
  13857.     rol    dest+1
  13858.     asl    dest        ; multiplied by 40
  13859.     rol    dest+1
  13860.     asl    dest        ; multiplied by 80
  13861.     rol    dest+1
  13862.     cpx    #80        ; are we in the funny col?
  13863.     bcc    scr40adr2    ; no
  13864.     ldx    #79
  13865. scr40adr2: txa            ; add in x-reg
  13866.     clc
  13867.     adc    dest
  13868.     sta    dest
  13869.     bcc    scr40adr3
  13870.     inc    dest+1
  13871. scr40adr3: rts            ; all done
  13872.  
  13873. ;
  13874. ;    scr40adrt - calculate address of a text character for 40/80 column mode
  13875. ;
  13876. ;    Input:    x coordinate in x-reg
  13877. ;        y coordinate in y-reg
  13878. ;    Output: dest
  13879. ;
  13880. ;    Registers destroyed - A,X,Y
  13881. ;
  13882. ;    This routine calculates the address of a character at x,y in 40/80
  13883. ;    column mode.  It uses scr40adr to set things up and adds scrmem base
  13884. ;
  13885.  
  13886. scr40adrt:
  13887.     jsr    scr40adr        ; freak out scraeadr
  13888.     lda    #scrmemlo\        ; add base addr
  13889.     clc
  13890.     adc    dest
  13891.     sta    dest
  13892.     lda    #scrmemlo^
  13893.     adc    dest+1
  13894.     sta    dest+1
  13895.     rts
  13896. ;
  13897. ; Stuff for panning the screen in 40/80 mode
  13898. ;
  13899.  
  13900. ;
  13901. ;    Pan40    frobnicate the display list pointers to point
  13902. ;    wherever they normally would plus panval.
  13903. ;
  13904. pan40:
  13905.     lda    ROWCRS        ; save cursor
  13906.     pha            ;  coords thru this
  13907.     lda    COLCRS
  13908.     pha
  13909.     lda    #0        ; now zap them to zero
  13910.     sta    ROWCRS
  13911.     sta    COLCRS
  13912.     lda    #dlist+3\    ; addr of line 0 display list inst
  13913.     sta    source
  13914.     lda    #dlist+3^
  13915.     sta    source+1
  13916. pan40a:
  13917.     ldx    COLCRS
  13918.     ldy    ROWCRS
  13919.     jsr    scr40adrt    ; figure out base address
  13920.     lda    ROWCRS        ; get offset into display list
  13921.     clc
  13922.     adc    ROWCRS        ; they're 3 bytes long
  13923.     adc    ROWCRS
  13924.     tay            ; into y
  13925.     iny            ; point at addr lo byte in DL
  13926.     lda    dest        ; stuff in screen mem ptr lo
  13927.     clc
  13928.     adc    panval        ; plus pan value
  13929.     sta    (source),y
  13930.     lda    dest+1        ; get hi byte
  13931.     adc    #0        ; plus carry
  13932.     iny
  13933.     sta    (source),y
  13934.     inc    ROWCRS        ; next line please
  13935.     lda    ROWCRS
  13936.     cmp    #24        ; off the end?
  13937.     bne    pan40a
  13938.     pla            ; get cursor back
  13939.     sta    COLCRS
  13940.     pla
  13941.     sta    ROWCRS
  13942.     rts            ; done!
  13943.  
  13944. ;
  13945. ; frob for updating status line flds that change on the fly.
  13946. ;
  13947. updstat:
  13948.     lda    #$1D+$40    ; internal code for down arrow
  13949.     sec
  13950.     sbc    capslck        ; buys up-arrow if set
  13951.     sta    statline+26
  13952. ;
  13953.     lda    fxoff        ; him x'ed off?
  13954.     beq    updsxon        ; no, he's on
  13955.     lda    #'--$20
  13956.     bne    updsx
  13957. updsxon:
  13958.     lda    #'+-$20
  13959. updsx:    sta    statline+22
  13960. ;
  13961.     lda    suspend        ; suspended?
  13962.     beq    updss        ; nope, display the 0, shows up as space
  13963.     lda    #$14+$40    ; display a blot
  13964.     ldx    scrtype        ; what kind of screen are we using?
  13965.     cpx    #scr40        ; a 40-col one?
  13966.     bne    updss        ; nope, it's ok
  13967.     lda    #$00+$40    ; blot in 40-col font
  13968. updss:    sta    statline+24
  13969. ; zzz more later
  13970.     rts 
  13971.  
  13972. ;
  13973. ; Make a display list preamble, for both 40/80 and graphics screens
  13974. ;
  13975. makedlp:
  13976.     lda    #dlist\        ; start of display list mem
  13977.     sta    dest
  13978.     lda    #dlist^
  13979.     sta    dest+1
  13980.     ldy    #0
  13981.     lda    #$70        ; 8 blank lines
  13982.     sta    (dest),y
  13983.     iny
  13984.     sta    (dest),y    ; 8 more
  13985.     iny
  13986.     lda    #$20        ; 3 blank lines
  13987.     sta    (dest),y
  13988.     iny
  13989.     lda    #scrmemlo\    ; set source up to point at screen mem
  13990.     sta    source
  13991.     lda    #scrmemlo^
  13992.     sta    source+1
  13993.     rts
  13994.  
  13995. ;
  13996. ; Make the common postamble
  13997. ;
  13998. makedlx:
  13999.     lda    #$42        ; character mode please
  14000.     sta    (dest),y
  14001.     iny
  14002.     lda    #statline\    ; point at status line
  14003.     sta    (dest),y
  14004.     iny
  14005.     lda    #statline^
  14006.     sta    (dest),y
  14007.     iny
  14008.     lda    #$41        ; jump and wait for Vsync
  14009.     sta    (dest),y
  14010.     iny
  14011.     lda    #dlist\        ; back to beginning of list
  14012.     sta    (dest),y
  14013.     iny
  14014.     lda    #dlist^
  14015.     sta    (dest),y    ; done!
  14016.     rts    
  14017. ;
  14018. ; Make a display list for the 40/80 pannable screen
  14019. ;
  14020. makedl40:
  14021.     jsr    makedlp        ; do the preamble
  14022.     ldx    #24        ; 24 lines like this
  14023. mkdl40a:
  14024.     lda    #$42        ; load scan pointer, char mode instruction
  14025.     sta    (dest),y
  14026.     iny
  14027.     lda    source        ; get pointer to block of mem
  14028.     sta    (dest),y
  14029.     iny
  14030.     clc            ; bump it by 80 while we're at it, for next pass
  14031.     adc    #80
  14032.     sta    source
  14033.     lda    source+1    ; get hi byte
  14034.     sta    (dest),y    ; into display list
  14035.     iny
  14036.     adc    #0        ; add carry from lo byte
  14037.     sta    source+1
  14038.     dex            ; dec counter
  14039.     bne    mkdl40a        ; more lines, go do them
  14040.     jsr    makedlx        ; make the postamble
  14041.     rts
  14042.  
  14043. ;
  14044. ; Make a display list for the 80 column graphics screen
  14045. ;
  14046. makedl80:
  14047.     jsr    makedlp        ; do the preamble
  14048.     lda    #$4F        ; hi-res graphics please, 
  14049.     sta    (dest),y
  14050.     iny
  14051.     lda    #scrmemlo\    ; starting at screen mem
  14052.     sta    (dest),y
  14053.     iny
  14054.     lda    #scrmemlo^
  14055.     sta    (dest),y
  14056.     iny
  14057.     jsr    mkdl80z        ; make 95 rasters worth
  14058.     lda    #$4F        ; hi-res graphics please, 
  14059.     sta    (dest),y
  14060.     iny
  14061.     lda    #scrmemhi\    ; starting at screen mem
  14062.     sta    (dest),y
  14063.     iny
  14064.     lda    #scrmemhi^
  14065.     sta    (dest),y
  14066.     iny
  14067.     jsr    mkdl80z        ; make another 95 rasters worth
  14068.     jsr    makedlx        ; make the postamble
  14069.     rts            ; done!
  14070.  
  14071. mkdl80z:
  14072.     ldx    #95        ; 95 more rasters of hi-res graphics
  14073.     lda    #$0F
  14074. mkdl80a:
  14075.     sta    (dest),y
  14076.     iny
  14077.     dex
  14078.     bne    mkdl80a
  14079.     rts
  14080.  
  14081. .SBTTL    40 Column screen driver
  14082.  
  14083. ;
  14084. ;    These routines manipulate the screen in 40 column mode.
  14085. ;
  14086.  
  14087. ;
  14088. ;    scraeini - initilize the 40 column screen
  14089. ;
  14090. ;    Input:    None
  14091. ;
  14092. scraeini:
  14093.     rts            ; all done
  14094.  
  14095. ;
  14096. ;    scraeent - enter the 40 column screen driver
  14097. ;
  14098. ;    Input:    None
  14099. ;    Output: None
  14100. ;
  14101. ;    Registers destroyed - A,X,Y
  14102. ;
  14103. ;    This routine starts the 40 column screen driver.
  14104. ;    these days, that's just resetting the real display list to the one we
  14105. ;    got when we opened the screen, turning off wrap, 
  14106. ;    and resetting the colors
  14107. ;
  14108.  
  14109. scraeent:
  14110.     lda    scraedl
  14111.     ldy    scraedl+1
  14112.     jsr    setdlist    ; go set it safely (?)
  14113.     lda    scraec1        ; get color1 value
  14114.     sta    COLOR1
  14115.     lda    scraec2
  14116.     sta    COLOR2
  14117.     lda    scraec4
  14118.     sta    COLOR4
  14119.     lda    scraer        ; get orig row value
  14120.     sta    ROWCRS
  14121.     lda    #$FF        ; wrap off, please
  14122.     sta    wrap
  14123.     lda    #scrae        ; go back to atari E: screen
  14124.     sta    scrtype
  14125.     rts            ; all done
  14126.  
  14127. ;
  14128. ;    scraeext - exit the E: screen driver
  14129. ;    Not really.  Just here for compatibility
  14130.  
  14131. ;    Input:    None
  14132. ;    Output: None
  14133. ;
  14134. ;    Registers destroyed - A,X,Y
  14135. ;
  14136. ;    This routine exits from the 40 column screen driver.
  14137. ;
  14138.  
  14139. scraeext:
  14140.     lda    SDLSTL        ; remember display list addr for when we change
  14141.     sta    scraedl
  14142.     lda    SDLSTH
  14143.     sta    scraedl+1
  14144.     lda    COLOR1        ; remember color settings
  14145.     sta    scraec1
  14146.     lda    COLOR2
  14147.     sta    scraec2
  14148.     lda    COLOR4
  14149.     sta    scraec4
  14150.     lda    ROWCRS
  14151.     sta    scraer        ; remember row value
  14152.     rts            ; all done
  14153.  
  14154. ;    scraeput - put a character at COLCRS, ROWCRS
  14155. ;
  14156. ;    Input:    character to put in a-reg (use funny ascii)
  14157. ;    Output: None
  14158. ;
  14159. ;    Registers destroyed - A,X,Y
  14160. ;
  14161. ;    This routine puts a character at screen position COLCRS,ROWCRS.  
  14162. ;    This routine does advance the cursor position.
  14163. ;
  14164.  
  14165. scraeput:
  14166.     jsr    sputch        ; put it using the builting E: driver
  14167. ;    dec    COLCRS        ; put column counter back
  14168. ;    bpl    scraeput4    ; should be pos
  14169. ;    lda    #0        ; no? ok zap it
  14170. ;    sta    COLCRS
  14171. scraeput4: rts            ; all done.
  14172.  
  14173. ;
  14174. ;    scraeel0 - Perform the VT100 Erase Line function #0 on 40 column screen
  14175. ;
  14176. ;    Input:    Number of line to erase in ROWCRS
  14177. ;    Output: None
  14178. ;
  14179. ;    Registers destroyed - A,X,Y
  14180. ;
  14181. ;    This routine erases from the cursor to the end of the line
  14182. ;
  14183.  
  14184. scraeel0:
  14185.     lda    COLCRS        ; get column
  14186.     pha            ; save it
  14187. scrael01:
  14188.     lda    #39        ; at eol yet?
  14189.     cmp    COLCRS
  14190.     beq    scrael02    ; yup, go home
  14191.     lda    #space        ; get a space
  14192.     jsr    sputch        ; shove it out
  14193.     jmp    scrael01    ; go around again
  14194. scrael02:
  14195.     pla            ; get column back
  14196.     sta    COLCRS
  14197.     rts
  14198.  
  14199. ;
  14200. ;    scraeel1 - Perform the VT100 Erase Line function #1 on 40 column screen
  14201. ;
  14202. ;    Input:    Number of line to erase in ROWCRS
  14203. ;    Output: None
  14204. ;
  14205. ;    Registers destroyed - A,X,Y
  14206. ;
  14207. ;    This routine erases from the beginning of line to cursor
  14208. ;
  14209.  
  14210. scraeel1:
  14211.     lda    COLCRS        ; get col
  14212.     pha            ; save it
  14213.     lda    #0        ; and zap it
  14214.     sta    COLCRS
  14215. scrael11:
  14216.     pla            ; get original col back
  14217.     cmp    COLCRS        ; are we home yet?
  14218.     beq    scrael12    ; yup, go home
  14219.     pha            ; nope, save it again
  14220.     lda    #space        ; get a space
  14221.     jsr    sputch        ; shove it out
  14222.     jmp    scrael11    ; go around again
  14223. scrael12:
  14224.     rts
  14225.  
  14226. ;
  14227. ;    scraeel2 - Perform the VT100 Erase Line function #2 on 40 column screen
  14228. ;
  14229. ;    Input:    Number of line to erase in ROWCRS
  14230. ;    Output: None
  14231. ;
  14232. ;    Registers destroyed - A,X,Y
  14233. ;
  14234. ;    This routine erases one line compleatly from the 40 column display.
  14235. ;
  14236.  
  14237. scraeel2:
  14238.     lda    COLCRS        ; save column
  14239.     pha
  14240.     lda    #0        ; zap it to 0
  14241.     sta    COLCRS
  14242.     jsr    scraeel0    ; zap to eol
  14243.     pla            ; get it back
  14244.     sta    COLCRS
  14245.     rts            ; all done
  14246.  
  14247. ;
  14248. ;    scraeind - perform the VT100 index function (scroll the screen)
  14249. ;
  14250. ;    Input:    None
  14251. ;    Output: None
  14252. ;
  14253. ;    Registers destroyed - A,X,Y
  14254. ;
  14255. ;    Can't do this in E: device, so it's a no-op
  14256. ;
  14257. ;
  14258.  
  14259. scraeind: 
  14260.     rts
  14261.     
  14262. ;
  14263. ;    scraeri - perform the VT100 reverse index function (scroll backwards)
  14264. ;
  14265. ;    Input:    None
  14266. ;    Output: None
  14267. ;
  14268. ;    Registers destroyed - A,X,Y
  14269. ;
  14270. ;    This one too.
  14271. ;
  14272.  
  14273. scraeri: rts            ; zzz can we do this?
  14274.     
  14275. ;
  14276. ;    scraefls - flash the screen in 40 column mode
  14277. ;    No-op
  14278. ;
  14279.  
  14280. scraefls:
  14281.     rts            ; all done
  14282.  
  14283. ;
  14284. ;    scraetgl - toggle the cursor in ae column mode
  14285. ;    This is really only useful for making the cursor show up
  14286. ;    in the right place.
  14287. ;
  14288.  
  14289. scraetgl:
  14290.     lda    #$1F        ; go right a char
  14291.     jsr    sputch
  14292.     lda    #$1E        ; go left a char.  Sigh
  14293.     jsr    sputch
  14294.     rts
  14295.  
  14296. ;
  14297. ; 80-col stuff
  14298. ;
  14299.  
  14300. ;
  14301. ;    Scr80ent.    Enter the 80-column graphics screen
  14302. ;
  14303. scr80ent:
  14304.     jsr    makedl80
  14305.     lda    scr80dl
  14306.     ldy    scr80dl+1
  14307.     jsr    setdlist
  14308.     lda    backclr        ; grey, hi luminance
  14309.     sta    COLOR2        ;  shows up on 0 bits
  14310.     lda    foreclr        ; grey, lo luminance (only lum counts)
  14311.     sta    COLOR1        ;  shows up on 1 bits
  14312.     lda    bordclr        ; make background like 0 bits, a little
  14313.     sta    COLOR4        ;  dimmer
  14314.     lda    #scr80        ; we're now in graphics mode
  14315.     sta    scrtype
  14316.     rts
  14317.  
  14318. ;
  14319. ;    Scr80ext.    Exit the 80-col graphics screen
  14320. ;
  14321. scr80ext:
  14322.     jmp    scraeent    ; back to atari mode
  14323.     
  14324. ;
  14325. ;    scr80adr - calculate int(x/2) and x%2
  14326. ;
  14327. ;    Input:    number in x-reg
  14328. ;    Output: evenodd = $0f if x is odd, $f0 if x is even
  14329. ;        x-reg = x-reg/2
  14330. ;
  14331. ;    Registers destroyed - A,X
  14332. ;
  14333. ;    This routine calculated int(x/2) and x % 2.  It is used to freak
  14334. ;    scraeadr into calculating addresses for 80 column mode.  Real
  14335. ;    funny things happen if the x-reg is the funny column (81).
  14336. ;
  14337.  
  14338. scr80adr:
  14339.     cpx    #80        ; is the cursor in the funny column?
  14340.     bcc    scr80adr2        ; no
  14341.     ldx    #81        ; 81 % 2 = 1
  14342. scr80adr2:
  14343.     txa            ; divide x by two
  14344.     lsr    a
  14345.     tax            ; put result back in x-reg
  14346.     lda    #$0F        ; put $0f in evenodd if odd
  14347.     bcs    scr80adr1        ; is odd
  14348.     lda    #$F0        ; put $f0 in evenodd if even
  14349. scr80adr1:
  14350.     sta    evenodd
  14351.     rts
  14352.  
  14353. ;
  14354. ;     scr80adrt.  compute (y * 320) + (x / 2) + scrmem, leave it in dest
  14355. ;     actually, mem is split, but we hide all that in here
  14356. ;
  14357. scr80adrt:
  14358.     tya            ; save this value
  14359.     pha
  14360.     cmp    #12        ; which half?
  14361.     bcc    s80a1        ; lo half, leave it
  14362.     sbc    #12        ; sub 12, carry's set
  14363. s80a1:
  14364.     sta    dest
  14365.     lda    #0
  14366.     sta    dest+1        ; zap top half
  14367.     jsr    scr80adr    ; do the even/odd stuff
  14368.     asl    dest        ; * 2
  14369.     lda    dest        ; we'll need this in a sec
  14370.     asl    dest        ; * 4
  14371.     asl    dest        ; * 8
  14372.     adc    dest        ; carry's clear, from shifts
  14373.     sta    dest        ; * 10
  14374.     asl    dest
  14375.     rol    dest+1        ; * 20
  14376.     asl    dest
  14377.     rol    dest+1        ; * 40
  14378.     asl    dest
  14379.     rol    dest+1        ; * 80
  14380.     asl    dest
  14381.     rol    dest+1        ; * 160
  14382.     asl    dest
  14383.     rol    dest+1        ; * 320
  14384.     txa            ; x has col / 2 in it
  14385.     adc    dest        ; carry's clear from shifts
  14386.     sta    dest
  14387.     lda    dest+1
  14388.     adc    #0        ; add carry to hi byte
  14389.     sta    dest+1
  14390.     pla            ; now add lo or hi mem base
  14391.     cmp    #12
  14392.     bcs    s80a2        ; hi half
  14393.     lda    dest        ; now add screen mem lo
  14394.     adc    #scrmemlo\
  14395.     sta    dest
  14396.     lda    dest+1
  14397.     adc    #scrmemlo^
  14398.     sta    dest+1
  14399.     rts
  14400. s80a2:
  14401.     clc
  14402.     lda    dest        ; now add screen mem lo
  14403.     adc    #scrmemhi\
  14404.     sta    dest
  14405.     lda    dest+1
  14406.     adc    #scrmemhi^
  14407.     sta    dest+1
  14408.     rts
  14409. ;
  14410. ; Put a byte in 80-col graphics mode
  14411. ;
  14412. scr80put:
  14413.     and    #$7F        ; seven bits only, here
  14414. ;
  14415. ; first figure out if we're doing graphics
  14416. ;
  14417.     cmp    #$60        ; lower case?
  14418.     bcc    scr80p1        ; nope, do the subtract
  14419.     ldx    csg0        ; default, G0
  14420.     ldy    altcs        ; using alternate instead?
  14421.     beq    scr80p0        ; nope, use this one
  14422.     ldx    csg1        ; ok, use G1
  14423. scr80p0:
  14424.     cpx    #csascii    ; using ascii?
  14425.     bne    scr80p2        ; no, skip the subtract, for graphics
  14426. scr80p1:
  14427.     sec
  14428.     sbc    #$20        ; offset for font80
  14429. scr80p2:
  14430.     pha            ; save character put
  14431.     sta    source        ; compute character*8+font80
  14432.     lda    #0
  14433.     sta    source+1
  14434.     asl    source        ; multiplied by 2
  14435.     rol    source+1
  14436.     asl    source        ; multiplied by 4
  14437.     rol    source+1
  14438.     asl    source        ; multiplied by 8
  14439.     rol    source+1
  14440.     lda    source        ; now add in font80
  14441.     adc    #font80\    ; carry is clear
  14442.     sta    source
  14443.     lda    source+1
  14444.     adc    #font80^
  14445.     sta    source+1
  14446.     ldy    ROWCRS        ; compute the address to store at
  14447.     ldx    COLCRS
  14448.     jsr    scr80adrt        
  14449.     ldy    #0        ; index into font
  14450. scr80put1:
  14451.     ldx    #0        ; to index thru dest
  14452.     lda    (dest,x)    ; select hi or low half      abcdefgh
  14453.     eor    (source),y    ;                 ABCDEFGH
  14454.     and    evenodd        ;                 xxxx0000
  14455.     eor    (dest,x)    ;                 ABCDefgh
  14456.     cpy    #7        ; on row 7?
  14457.     bne    scr80put8    ; nope, don't check for underlining
  14458.     ldx    underln        ; underlining?
  14459.     beq    scr80put8    ; nope
  14460.     ora    evenodd        ; yes, set all bits this row
  14461. scr80put8:
  14462.     ldx    reverse        ; $01 is reverse on, $00 is reverse off
  14463.     beq    scr80put7
  14464.     eor    evenodd        ; reverse the character
  14465. scr80put7:
  14466.     ldx    #0        ; for indexing again
  14467.     sta    (dest,x)    ; finally put it back
  14468.     lda    dest        ; bump dest by 40
  14469.     clc
  14470.     adc    #40
  14471.     sta    dest
  14472.     lda    dest+1
  14473.     adc    #0
  14474.     sta    dest+1
  14475.     iny
  14476.     cpy    #8        ; off end of font yet?
  14477.     bcc    scr80put1    ; put in the entire character (8bytes)
  14478.     jmp    scr80put2
  14479. scr80put6:
  14480. ;    ldy    #$07
  14481. ;    lda    evenodd
  14482. ;    eor    #$ff
  14483. ;    and    (dest),y
  14484. ;    sta    (dest),y
  14485. scr80put2:
  14486. ; not round here...
  14487.     pla            ; check to see if color must be updated
  14488. ;    bne    scr80put3        ; if character is not a space, update
  14489. ;    lda    reverse        ; if reverse on, update
  14490. ;    bne    scr80put3
  14491. ;    lda    underln        ; if underline on, update
  14492. ;    beq    scr80put4
  14493. scr80put3:
  14494. ;    ldy    ROWCRS        ; calculate primary color address
  14495. ;    ldx    COLCRS
  14496. ;    jsr    scr80adrp
  14497. ;    ldx    alternt        ; 1=alternate color, 0=normal color
  14498. ;    lda    foreclr,x    ; get proper foreground color
  14499. ;    asl    a        ; put in high nybble
  14500. ;    asl    a
  14501. ;    asl    a
  14502. ;    asl    a
  14503. ;    ora    backclr        ; or in background color
  14504. ;    ldy    #0
  14505. ;    sta    (dest),y    ; adjust primary color ram
  14506. ;    pha            ; save for future use
  14507. ;    ldy    ROWCRS        ; compute alternate color address
  14508. ;    ldx    COLCRS
  14509. ;    jsr    scr80adra
  14510. ;    pla            ; restore colors used for primary color
  14511. ;    ldx    flash        ; can we use it?
  14512. ;    beq    scr80put5        ; yes.
  14513. ;    lda    backclr        ; no. screen is flashing.
  14514. ;    asl    a        ; use background color for forground
  14515. ;    asl    a
  14516. ;    asl    a
  14517. ;    asl    a
  14518. ;    ora    backclr
  14519. scr80put5:
  14520. ;    ldy    #0
  14521. ;    sta    (dest),y    ; adjust alternate color ram
  14522. scr80put4:
  14523.     inc    COLCRS        ; bump column
  14524.     rts            ; all done.
  14525.  
  14526. ; stubs
  14527. scr80fls: rts
  14528.  
  14529. scr80tgl:
  14530. ;    ldx    COLCRS        ; figure out where we are
  14531. ;    ldy    ROWCRS
  14532.     sec
  14533.     jsr    ploth        ; filter for rightmost col
  14534.     jsr    scr80adrt
  14535.     ldx    #8        ; do 8 slots
  14536.     ldy    #0
  14537. scr80t1:
  14538.     lda    (dest),y    ; get screen data
  14539.     eor    evenodd        ; toggle the proper half
  14540.     sta    (dest),y    ; put it back
  14541.     lda    dest        ; bump pointer by 40
  14542.     clc
  14543.     adc    #40
  14544.     sta    dest
  14545.     bcc    scr80t2        ; no carry, don't bother with top
  14546.     inc    dest+1
  14547. scr80t2:
  14548.     dex            ; dec raster counter
  14549.     bne    scr80t1        ; go back for another raster
  14550.     rts
  14551.  
  14552. ;
  14553. ;    Scr80el0:    Erase from cursor to EOL in 80-col mode
  14554. ;
  14555. scr80el0: 
  14556.     ldx    COLCRS        ; get col,
  14557.     ldy    ROWCRS        ; and row,
  14558.     jsr    scr80adrt    ; and figure out where we are
  14559.     stx    strptr+1    ; x still has col / 2 in it
  14560.     lda    #8        ; init raster counter
  14561.     sta    strptr        ; handy temp
  14562. scr80e0a:
  14563.     ldy    #0        ; start index
  14564.     lda    #40        ; line length, bytes
  14565.     ldx    evenodd        ; $0F if on odd col
  14566.     bmi    scr80e0b    ; $F0, even col, so go ahead
  14567.     lda    #$F0        ; make a mask for the col we want
  14568.     and    (dest),y    ; mask it
  14569.     sta    (dest),y    ; and put it back
  14570.     iny            ; skip this byte
  14571.     lda    #39        ; and count will be one less
  14572. scr80e0b:
  14573.     sec
  14574.     sbc    strptr+1    ; remaining byte count
  14575.     beq    scr80e0d    ; zero? ok, already at eol
  14576.     tax            ; back to x
  14577.     lda    #0
  14578. scr80e0c:
  14579.     sta    (dest),y    ; clear rest of raster
  14580.     iny
  14581.     dex
  14582.     bne    scr80e0c
  14583. scr80e0d:
  14584.     lda    dest        ; get byte pointer
  14585.     clc
  14586.     adc    #40        ; next row please
  14587.     sta    dest
  14588.     lda    dest+1
  14589.     adc    #0
  14590.     sta    dest+1
  14591.     dec    strptr        ; next raster
  14592.     bne    scr80e0a    ; done!
  14593.     rts
  14594.  
  14595. ;
  14596. ;    Scr80el1    zap from beginning of line to cursor
  14597. ;
  14598. scr80el1: 
  14599.     ldx    #0        ; get col,
  14600.     cpx    COLCRS        ; already at 0?
  14601.     beq    scr80e1z    ; yup, quit here
  14602.     ldy    ROWCRS        ; and row,
  14603.     jsr    scr80adrt    ; and figure out where we are
  14604.     ldx    COLCRS
  14605.     jsr    scr80adr    ; figure out even/odd of this coll
  14606.     stx    strptr+1    ; x has col / 2 in it
  14607.     lda    #8        ; init raster counter
  14608.     sta    strptr        ; handy temp
  14609. scr80e1a:
  14610.     lda    evenodd        ; $0F if on odd col
  14611.     bpl    scr80e1b    ; odd col, clear up to it
  14612.     ldy    strptr+1    ; get the byte pos
  14613.     and    (dest),y    ; mask it
  14614.     sta    (dest),y    ; and put it back
  14615. scr80e1b:
  14616.     ldx    strptr+1    ; remaining byte count
  14617.     beq    scr80e1d    ; zero? ok, done
  14618.     lda    #0
  14619.     jsr    fillx        ; fill that many
  14620. scr80e1d:
  14621.     lda    dest        ; get byte pointer
  14622.     clc
  14623.     adc    #40        ; next row please
  14624.     sta    dest
  14625.     lda    dest+1
  14626.     adc    #0
  14627.     sta    dest+1
  14628.     dec    strptr        ; next raster
  14629.     bne    scr80e1a    ; done!
  14630. scr80e1z:
  14631.     rts
  14632. ;    scr80el2 - zap current line
  14633. ;
  14634. scr80el2: 
  14635.     ldx    #0
  14636.     ldy    ROWCRS
  14637.     jsr    scr80adrt    ; get base addr of this row
  14638.     lda    #320\        ; clear 320 bytes
  14639.     sta    count
  14640.     lda    #320^
  14641.     sta    count+1
  14642.     jsr    clearn
  14643.     rts
  14644.  
  14645. scr80ind: 
  14646.     lda    top        ; init row counter
  14647.     sta    strptr        ; use this as a temp
  14648. scr80i1:
  14649.     jsr    comsta        ; this is slow, so make sure we
  14650.     jsr    flowco        ; pay attention to line
  14651.     ldx    #0        ; compute
  14652.     ldy    strptr        ;  row start addr
  14653.     iny
  14654.     jsr    scr80adrt
  14655.     lda    dest
  14656.     sta    source
  14657.     lda    dest+1
  14658.     sta    source+1
  14659.     ldx    #0
  14660.     ldy    strptr
  14661.     jsr    scr80adrt    ; and target row start addr
  14662.     lda    #320\        ; 320 bytes per row
  14663.     sta    count
  14664.     lda    #320^
  14665.     sta    count+1
  14666.     jsr    moven        ; move some
  14667.     inc    strptr        ; bump row counter
  14668.     lda    strptr
  14669.     cmp    bot        ; end yet?
  14670.     bcc    scr80i1        ; nope, do another row
  14671.     lda    ROWCRS        ; save row
  14672.     pha
  14673.     lda    bot
  14674.     sta    ROWCRS
  14675.     jsr    scr80el2    ; zap this line
  14676.     pla
  14677.     sta    ROWCRS        ; put row back
  14678.     rts
  14679.  
  14680. scr80ri:
  14681.     lda    bot        ; init row counter
  14682.     sta    strptr        ; use this as a temp
  14683. scr80r1:
  14684.     jsr    comsta        ; this is slow, so make sure we
  14685.     jsr    flowco        ; pay attention to line
  14686.     ldx    #0        ; compute
  14687.     ldy    strptr        ;  row start addr
  14688.     dey            ; row above's source
  14689.     jsr    scr80adrt
  14690.     lda    dest
  14691.     sta    source
  14692.     lda    dest+1
  14693.     sta    source+1
  14694.     ldx    #0
  14695.     ldy    strptr
  14696.     jsr    scr80adrt    ; and target row start addr
  14697.     lda    #320\        ; 320 bytes per row
  14698.     sta    count
  14699.     lda    #320^
  14700.     sta    count+1
  14701.     jsr    moven        ; move some
  14702.     dec    strptr        ; dec row counter
  14703.     lda    strptr        ; at top row yet?
  14704.     cmp    top
  14705.     bne    scr80r1        ; nope, do another row
  14706.     lda    ROWCRS        ; save row
  14707.     pha
  14708.     lda    top
  14709.     sta    ROWCRS
  14710.     jsr    scr80el2    ; zap this line
  14711.     pla
  14712.     sta    ROWCRS        ; put row back
  14713.     rts
  14714.  
  14715. ;
  14716. ;    slput:    put a string in the status line.  A,Y point to string.
  14717. ;        X is initial offset in status line
  14718. ;        terminates on EOL or nul. clears to end of stat line
  14719. ;
  14720. slput:
  14721.     sta    strptr        ; set up the string pointer
  14722.     sty    strptr+1
  14723.     ldy    #0
  14724. slp1:    lda    (strptr),y    ; get a byte
  14725.     beq    slp8        ; done!
  14726.     cmp    #ATEOL        ; eol?
  14727.     beq    slp9        ; yup, done
  14728.     cmp    #$60        ; lower case?
  14729.     bcs    slp2        ; yes, leave it alone
  14730.     sec
  14731.     sbc    #$20        ; offset into font
  14732. slp2:    sta    statline,x    ; stuff it in
  14733.     inx
  14734.     iny            ; next!
  14735.     jmp    slp1
  14736. slp8:
  14737.     txa            ; save x
  14738.     pha
  14739.     lda    #0        ; space, sort of
  14740. slp9:    sta    statline,x
  14741.     inx
  14742.     cpx    #40
  14743.     bcc    slp9
  14744.     pla
  14745.     tax
  14746.     rts            ; home
  14747.  
  14748. .SBTTL    Miscellaneous routines
  14749.  
  14750. ;
  14751. ;    These are miscellaneous routines used in many different places
  14752. ;
  14753.  
  14754. ;
  14755. ;    Moven - move (source) to (dest) for (count) bytes
  14756. ;
  14757. ;    Input: (count) - byte count to move
  14758. ;           (source) - address of source of memory move
  14759. ;           (dest) - address of destination of memory move
  14760. ;
  14761. ;    Output: Memory is moved
  14762. ;
  14763. ;    Registers Destroyed: A,X,Y
  14764. ;
  14765. moven:
  14766.     lda    count+1        ; more 256 byte chunks?
  14767.     beq    moven1        ; nope, go get the rest
  14768.     jsr    move256
  14769.     inc    source+1
  14770.     inc    dest+1
  14771.     dec    count+1
  14772.     bne    moven        ; try for more
  14773. moven1:
  14774.     ldx    count        ; any left?
  14775.     beq    moven2        ; nope, done
  14776.     jsr    movex        ; move that many
  14777. moven2:
  14778.     rts
  14779. ;
  14780. ; Move 256 bytes (source) to (dest)
  14781. ;
  14782. move256:
  14783.     ldy    #0
  14784. mov256a:
  14785.     lda    (source),y    ; move 1
  14786.     sta    (dest),y
  14787.     iny            ; bump
  14788.     bne    mov256a        ; if not wrapped, go back
  14789.     rts            ; done
  14790. ;
  14791. ; Move X bytes (source) to (dest)
  14792. ;
  14793. movex:
  14794.     ldy    #0
  14795. movexa:
  14796.     lda    (source),y    ; move 1
  14797.     sta    (dest),y
  14798.     iny            ; bump
  14799.     dex            ; dec count
  14800.     bne    movexa        ; non zero, go back for more
  14801.     rts
  14802. ;
  14803. ;    Move 8 * (x) bytes
  14804. ;    
  14805. move8:
  14806.     stx    count        ; lo byte of count
  14807.     lda    #0
  14808.     sta    count+1
  14809.     asl    count
  14810.     rol    count+1
  14811.     asl    count
  14812.     rol    count+1
  14813.     asl    count
  14814.     rol    count+1
  14815.     jmp    moven
  14816.  
  14817. ;
  14818. ;    clearn - clear (dest) for (count)
  14819. ;
  14820. ;    Input: (count) - byte count to fill
  14821. ;           (dest) - address of destination of memory move
  14822. ;
  14823. ;    Output: Memory is cleared
  14824. ;
  14825. ;    Registers Destroyed: A,X,Y
  14826. ;
  14827.  
  14828. clearn:    lda #0            ; clear memory by filling with $00
  14829.     jsr filln
  14830.     rts
  14831.     
  14832. ;
  14833. ;    Filln - fill (dest) for (count) with what's in A
  14834. ;
  14835. ;    Input: (count) - byte count to fill
  14836. ;           A - Byte to fill memory with
  14837. ;           (dest) - address of destination of memory move
  14838. ;
  14839. ;    Output: Memory is filled
  14840. ;
  14841. ;    Registers Destroyed: A,X,Y
  14842. ;
  14843. filln:
  14844.     ldx    count+1        ; more 256 byte chunks?
  14845.     beq    filln1        ; nope, go get the rest
  14846.     jsr    fill256
  14847.     inc    source+1
  14848.     inc    dest+1
  14849.     dec    count+1
  14850.     bne    filln        ; try for more
  14851. filln1:
  14852.     ldx    count        ; any left?
  14853.     beq    filln2        ; nope, done
  14854.     jsr    fillx        ; move that many
  14855. filln2:
  14856.     rts
  14857.  
  14858. ;
  14859. ; fill 256 bytes (dest)
  14860. ;
  14861. fill256:
  14862.     ldy    #0
  14863. fil256a:
  14864.     sta    (dest),y
  14865.     iny            ; bump
  14866.     bne    fil256a        ; if not wrapped, go back
  14867.     rts            ; done
  14868. ;
  14869. ; fill X bytes (dest)
  14870. ;
  14871. fillx:
  14872.     ldy    #0
  14873. fillxa:
  14874.     sta    (dest),y
  14875.     iny            ; bump
  14876.     dex            ; dec count
  14877.     bne    fillxa        ; non zero, go back for more
  14878.     rts
  14879.  
  14880. ;
  14881. ;    Case - Pascal like case function
  14882. ;
  14883. ;    Input: Y - Case statement to select
  14884. ;               The addresses of the routines to select are compiled inline
  14885. ;
  14886. ;    Registers Destroyed: X, Y
  14887. ;
  14888. ;    this routine transfers controll to a routine selected by the X register
  14889. ;
  14890.  
  14891. case:    tax            ; preserve a-reg across case statement
  14892.     pla            ; get lo bype of case list
  14893.     sta source        ; save it
  14894.     pla            ; get hi byte of case list
  14895.     sta source+1        ; save it
  14896.     tya            ; put case selector into a-reg
  14897.     sec            ; add one half
  14898.     rol a            ; and multiply by two
  14899.     tay            ; put (2*case_selector)+1 into y-reg
  14900.     lda (source),y        ; get lo byte of routine to go to
  14901.     sta dest        ; save it
  14902.     iny            ; prepare to get hi byte of routines address
  14903.     lda (source),y        ; get hi byte of routines address
  14904.     sta dest+1        ; save it
  14905.     txa            ; preserve a-reg across case statement
  14906.     jmp (dest)        ; go to appropriate
  14907.  
  14908. anyrts:    rts            ; a handy return from subroutine instruction
  14909. anybrk:    brk            ; a handy break instruction
  14910.  
  14911.     
  14912. ;
  14913. ; Set the OS's display list cells.
  14914. ; This may need to be done without interrupts or something zzz
  14915. ;
  14916. setdlist:
  14917.     ldx    #1
  14918.     stx    CRITIC        ; say we're doing something critical
  14919.     ldx    SDMCTL        ; get old DMACTL value
  14920.     stx    dest        ; save it here for a bit
  14921.     ldx    #0
  14922.     stx    DMACTL        ; and whack the real one while
  14923.     sta    SDLSTL        ;  we indulge in some sleight of hand
  14924.     sty    SDLSTH
  14925.     ldx    dest        ; get old dma ctrl value back
  14926.     stx    DMACTL
  14927.     dec    CRITIC
  14928.     rts
  14929. ;
  14930.  
  14931. ;end.asm: =    *
  14932. .SBTTL    Data for the screen package
  14933.  
  14934. scraedl: .word    0    ; the original display list addr for E:
  14935. scraec1: .byte    0    ; original color1 value
  14936. scraec2: .byte    0    ; original color2 value
  14937. scraec4: .byte    0    ; original color4 (background) value
  14938. scraer:    .byte    0    ; original cursor row value
  14939. scr40dl: .word    dlist    ; display list addr for 40/80 col screen
  14940. scr80dl: .word    dlist    ; display list addr for 80 col
  14941.  
  14942. panval:    .byte    0    ; pan offset for 40/80 mode
  14943.  
  14944. backclr: .byte    $0A    ; background color, grey, hi lum
  14945. foreclr: .byte    $02    ; foreground color, grey lo lum
  14946. ;altclr:    .byte    $ff    ; alternate color
  14947. bordclr: .byte    $08    ; border color, grey, med lum
  14948. ;
  14949. top:    .byte    $FF    ; top of scrolling area
  14950. bot:    .byte    $FF    ; bottom of scrolling area
  14951. vt100gr    =    *    ; graphic rendition params for vt100 emulation
  14952. alternt: .byte    $FF    ; $00=normal color, $01=alternate color
  14953.     .byte    $FE    ; filer for vt100 emulation
  14954.     .byte    $FE    ; filer for vt100 emulation
  14955. underln: .byte    $FF    ; $00=underline off, $ff=underline on
  14956. flash:    .byte    $FF    ; $00=normal text, $01=flashing text
  14957.     .byte    $FE    ; filler for vtt100 emulation
  14958. reverse: .byte    $FF    ; $00=reverse off, $ff=reverse on
  14959. wrap:    .byte    $FF    ; $01=no automatic wrapping, $00=use wrapping
  14960. altcs:    .byte    0    ; [jrd] alternate char set switch for vt100
  14961. csg0:    .byte    csascii    ; [jrd] G0 is normal ascii
  14962. csg1:    .byte    csgraf    ; [jrd] G1 is graphics
  14963. cntdown: .byte    $FF    ; countdown timer
  14964. curabrt: .byte    $FF    ; $00=cursor disabled.  Incremented & decremented.
  14965. curstat: .byte    $FF    ; $00=cursor light now, $01=cursor dark now
  14966. evenodd: .byte    $FF    ; $f0=cursor on even column, $0f=cursor on odd column
  14967. save1:    .byte    $FF    ; screen save area #1
  14968. save2:    .byte    $FF    ; screen save area #2
  14969. save3:    .byte    $FF    ; screen save area #3
  14970. save4:    .byte    $FF    ; screen save area #4
  14971. save5:    .byte    $FF    ; screen save area #5
  14972. save6:    .byte    $FF    ; screen save area #6
  14973.  
  14974. ;.SBTTL    Data for the vt100 emulation package
  14975.  
  14976. vt100st: .byte    $FF    ; parser state
  14977. vt100pt: .byte    $FF    ; parameter pointer
  14978.  
  14979. ;
  14980. ; Screen mem chunks must be on a 4k bound.  
  14981. ; Given the size of this thing, the best we can do is to end up
  14982. ; with scrmemlo at $9000. If it's higher than that, we'll clobber
  14983. ; the OS.  Beware when adding things to this code!
  14984. ;
  14985.  
  14986.     *=    *|$FFF+1    ; go to next 4k bound
  14987. scrmemlo: .blkb    3840        ; lo half of graphics screen
  14988. ;
  14989. ; the display list area for 40/80 col mode.  max size is 3 (preamble) + 
  14990. ;  3 (first graphics) + 95 (rest of graphics first half) + 
  14991. ;  3 + 95 + 3 (status line) + 3 (branch back)
  14992. ;
  14993. dlist:    .blkb    256        ; room for disp list, gets us to next 4k
  14994. scrmemhi: .blkb    3840        ; hi half of screen mem
  14995. statline: .blkb    40    ; status line for terminal screens
  14996. ;
  14997. ; vt100 tabstop map
  14998. ;
  14999. tabstop: .blkb    80
  15000. ;
  15001. ; scratch area for vt100 stuff
  15002. ;
  15003. freemem: .blkb    $20
  15004. ;
  15005. ; Storage for font mem in 40/80 mode
  15006. ;
  15007. font40    =    scrmemhi
  15008. ;
  15009. ; that's it!
  15010. ;
  15011.