home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / appleii / appssc.m65 < prev    next >
Text File  |  2020-01-01  |  19KB  |  661 lines

  1. .TITLE    KERMIT-65 Super serial com card - interupt driven
  2. .SBTTL    6502 version - Ted Medin
  3.  
  4. ;    Version 1.0
  5. ;    Warning interupts must be allowed by card.
  6. ;    This means sw2-6 MUST be on.
  7.  
  8. ;    Based on the KERMIT Protocol.
  9.  
  10. ;    $Header: appssc.m65,v 1.15 90/10/15 14:27:07 medin Locked $
  11. .SBTTL    Define start address for assembly
  12.  
  13.        .=$1003            ;[39] Start assembly here
  14.  
  15. debug    =    0        ;[1] debug flag - when 0 will not add debug code
  16. .SBTTL    Revision History
  17.  
  18. ;
  19. ; Edit #    Description
  20. ; ------    -----------
  21. ;    
  22.     .ifne    0        ; get around the revisions
  23. ; DONT FORGET TO UPDATE THE VERSION
  24. ;$Log:    appssc.m65,v $
  25. Revision 1.15  90/10/15  14:27:07  medin
  26. new org of $7f00 for 3.87
  27. version 1.15
  28.  
  29. ;Revision 1.14  88/12/22  09:13:22  medin
  30. ;verison 1.14 changes for time count, input buffer now $900 and
  31. ;it now drops line via dtr.
  32.  
  33. ;Revision 1.13  88/08/16  16:24:17  medin
  34. ;fix break so it doesnt drop dtr
  35.  
  36. ;Revision 1.12  88/04/27  18:11:45  medin
  37. ;Shut off interupts when exiting kermit
  38.  
  39. ;Revision 1.11  88/01/15  08:40:25  medin
  40. ;New origin for 3.81
  41.  
  42. ;Revision 1.10  87/12/10  10:38:18  medin
  43. ;Polish code thats all.
  44.  
  45. ;Revision 1.9  87/06/29  09:51:39  medin
  46. ; Change org to work with 3.78 & change wait rtn to handle apple rom rtn
  47.  
  48. ;Revision 1.8  87/05/13  18:12:38  medin
  49. ; Change org to correspond with 3.76
  50.  
  51. ;Revision 1.7  87/02/20  23:18:59  medin
  52. ; Put version number in the herald which is displayed by the main
  53. ;routine. Thanks to Rhoda for that idea.
  54.  
  55. ;Revision 1.6  87/02/17  08:39:23  medin
  56. ; Clean up code for //c interupts. Debug turned off.
  57.  
  58. ;Revision 1.5  87/01/28  08:24:38  medin
  59. ;Redo the driver so that the //c will operate correctly. The output 
  60. ;interupt is always left on thus the //c will give the driver bith
  61. ;interupts without any special memory locations. 
  62.  
  63. ;Revision 1.4  87/01/08  11:39:41  medin
  64. ;Paul Close's changes to allow the super serial with interupts to
  65. ;work on a //c. Some slight changes to lock out interupts in critical
  66. ;phases.
  67.  
  68. ;Revision 1.3  86/12/09  13:22:13  medin
  69. ; Slight change to the initialization for the //e+ & //c.
  70. ;The stack would get corrupted in case there were multiple interupts
  71. ;and we had to pass an interupt to the next requester.
  72. ;
  73. ;Revision 1.2  86/10/31  10:30:13  medin
  74. ; Add debug code which may be optionaly generated.
  75. ;Change the flow control commands to wait till the xon/xoff actually
  76. ;is sent down the line.
  77. ;
  78. ;Revision 1.1  86/10/28  10:20:03  medin
  79. ;Initial revision
  80.     .endc
  81. ;
  82. ;
  83. ;    Vector for com cards starts here
  84. ;        location $1003 for data
  85. ;        location $1020 for routine jumps
  86. ;        location $1040 for main routines
  87. ;
  88. sscdbd:    .blkb    1  ;[54]contains baud index(ala super serial card) used by init
  89.             ;        6 - 300 baud
  90.             ;        7 - 600
  91.             ;        etc
  92.     .blkb    1    ;
  93. crdnam:    .word    herld    ;[54] null terminated string of who we are
  94. kersli:    .blkb    1    ;[54] com slot $n0
  95. kerins:    .blkb    1    ;[54] force initialization flag-when 0
  96. endker:    .blkb    2    ;[54] address of end of main kermit
  97. flowfg:    .blkb    1    ;[57] flow flag for xon/xoff controll b7=1 yes
  98. tl0end    .word    endcom    ;[1.11] end of this routine
  99. timect    .blkb    1    ;[1.14] time constant for rom wait rtn
  100.     .=sscdbd+29        ;[54] future expansion
  101. tlinit:    jmp    tl2int        ;[54] initialize com card
  102. tl0cmd:    jmp    tl2cmd        ;[54] command in A reg
  103.             ;
  104.             ;[54] 0 - hang up
  105.             ;[54] $0b - set baud
  106.             ;[54] $0c - set break on the line
  107.             ;[57] $91 - turn remote on (xon)
  108.             ;[57] $93 - turn remote off(xoff)
  109.             ;
  110.             ;[54] routine will return false(0) if unable
  111. tl0cp:    jmp    tl2cp        ;[54] check for input ch ready-0 false
  112. tl0gpc:    jmp    tl2gpc        ;[54] get input ch
  113. tl0ppc:    jmp    tl2ppc        ;[54] put output character
  114. tl0exi:    jmp    tl2exi        ;[54] reset card and restore initialized
  115.     .=sscdbd+29+32        ;[54] futures
  116. ;[1.9]wait:    .blkb    3    ;[54] wait routine-a reg contains milliseconds
  117. wait:    .blkb    3    ;[1.9] wait routine-use rom wait 220=125ms 25=2ms
  118. prstr:    .blkb    3    ;[54] print string x=lsb,y=msb x&y->null terminated string
  119. rdkey:    .blkb    3    ;[54] read keyboard
  120. prcrlf:    .blkb    3    ;[54] print cr and lf
  121. telcnc:    .blkb    3    ;[54] check for keyboard character
  122. telspa:    .blkb    3    ;[57] set character parity
  123. prbyte    =     $fdda          ; Routine - Print A-reg as 2 hex nibbles
  124.  
  125.     .=$7f00    ;[1.15][1.11][1.9][1.8] place to start com card assembly
  126. start    =    .        ;need a label at begining
  127. kr2pch    =    $c088        ;[22] Port character base (Super Serial card)
  128. kr2pst    =    $c089        ;[22] Port strobe base (Super Serial card)
  129. kr2pcr    =    $c08a        ;[41] Base for prot control register (SSC)
  130. kr2pcc    =    $c08b    ;[47] Com control
  131. mncinb    =    $18    ;[47] Control port init(8 bit,no par,1-stop,1200 baud)
  132. mnminb    =    $5    ;[51] Master port init(DTR, IRQ interups) & output interupts
  133. mnint    =    1    ;[1.14] input interupt only
  134. mssinb    =    $8    ;[51] status bit for input ready
  135. mssoub    =    $10    ; status bit for output ready
  136. mssodb    =    4    ;[1.8] overrun detected bit =1 then yes
  137. moutb    =    $c    ;[51] mask for the output bits of command
  138. moutnt    =    $4    ;[51] command to start output with interupts
  139. true    =    1    ; a true response
  140. false    =    0    ; a false  "
  141. inptr    .byte    0    ;[51] input q pointer
  142. pinptr    .byte    0    ;[51] p "
  143. outptr    .byte    0    ;[51] output q pointer
  144. poutpt    .byte    0    ;[51] p "
  145. hdirq    .word        ;[51] hold area for dos IRQ
  146. xon:    .byte    0    ;[57] flow controll
  147. xoff:    .byte    0    ;[57] "
  148. kwrk01    .byte    0    ;[1.14]
  149.     .ifne    debug    ;[1] conditional assembly
  150. xofcnt    .byte    0    ;count of times buffer overran
  151. cixon    .byte    0    ;[1] count of input xon request
  152. cixoff    .byte    0    ;[1]         "      xoff  "
  153. cinixn    .byte    0    ; count of input no interupt xon
  154. cinixf    .byte    0    ;              "             xoff
  155. coxon    .byte    0    ;[1] count of ouput xon requests
  156. coxoff    .byte    0    ;[1]         "      xoff   "
  157. caixon    .byte    0    ;[1] count of actual input xon sent
  158. caixof    .byte    0    ;[1]         "             xoff "
  159.     .endc        ;[1]
  160. hxon    =    $91    ;^Q with high bit on
  161. hxoff    =    $93    ;^S  "
  162. null    =    0    ;null com character
  163. ctrlq    =    $11    ;xon ^Q
  164. ctrls    =    $13    ;xoff ^S
  165. irqsva    =    $45    ;place dos saves a reg
  166. dirq    =    $3fe    ;[51] interupt address
  167. tcps    =    $4f8    ; //c port status + slot
  168. sscstp    =    $578    ;[47] +slot,bit 7 on turns off commands to ssc
  169. herld    nasc    <SSC V1.15> 1    ;tell who we are
  170. bad    nasc    <COM RTN ASM TOO LOW> 1
  171. bcom    .byte   '<
  172.         nasc    <- BAD COM CMD> 1
  173.  
  174. ;
  175. ;    Super Serial Card I/O Device support - These routines support the
  176. ;        Apple Super Serial Card.
  177. ;
  178. tl2nts:    pla        ;[51] restore x
  179.     tax        ;[51]
  180.     jmp    (hdirq)    ;[51] and pass it on sans a reg
  181.  
  182. tl2rpt:         ;[51] a is already saved in irqsva
  183.     txa        ;[51] save x
  184.     pha        ;[51]
  185. tl2rpe            ;[67] enhanced // has all regs saved
  186.     lda    kr2pst    ;[51] get status
  187.     bpl    tl2nts    ;[51] not our interupt
  188.     .ifne    debug    ;[1.8]
  189.     pha        ;[1.8]
  190.     and    #mssodb    ;[1.8] overrun detected?
  191.     beq    .+3    ;[1.8] no
  192.     brk        ;[1.8] yes cataclismic but it does the job
  193.     pla        ;[1.8] restore input ch
  194.     .endc        ;[1.8]
  195.     and    #mssinb    ;[51] look at input bit,since output may be stalled
  196.     bne    tl2inp    ;[51] this is input ready
  197. tl2out:
  198.     bit    flowfg    ;[57] is flow controll on?
  199.     bpl    tl2xfs    ;[57] no
  200.     bvs    tl2jcm    ;[59] yes, is output ctlr S on?, yes
  201.     lda    xoff    ;[57] have we given the ^S ?
  202.     beq    tl2ou0    ;[57] maybe
  203.     lda    xon    ;[57] yes
  204.     bne    tl2xfs    ;[57] is it time to give the xoff ?
  205.     .ifne    debug    ;[1]
  206.     inc    caixof    ;[1] bump count of actual input xoffs given
  207.     .endc        ;[1]
  208.     lda    #ctrls    ;[57] yes
  209.     sta    xon    ;[57] tatle
  210. ;[1.14]    jmp    tl2ou2    ;[1][57] always jump
  211.     bne    tl2ou2    ;[1.14] always jump
  212. tl2ou0:    lda    xon    ;[57] how about giving the xon ?
  213.     beq    tl2xfs    ;[57] no
  214.     .ifne    debug    ;[1]
  215.     inc    caixon    ;[1] bump count of actual input xons given
  216.     .endc        ;[1]
  217.     lda    #0    ;[57] turn off xoff
  218.     sta    xoff    ;[57]
  219.     sta    xon    ;[57]
  220.     lda    #ctrlq    ;[57] now for the xon
  221. tl2ou2:    jsr    telspa    ;[57] set parity correctly x reg clobbered
  222. tl2oup    sta    kr2pch    ;[57] stop this flood
  223. tl2jcm    jmp    tl2com    ; thats all
  224. tl2xfs    
  225.     lda    outptr    ;[51] see if any to output
  226.     cmp    poutpt    ;[51]
  227. ;[1.14]    beq    tl2noo    ;[51] no more to output
  228.     beq    tl2ou7    ;[1.14] no more to output
  229.     inc    poutpt    ;tell we have output one
  230.     cmp    poutpt    ; now cmp
  231. ;[1.14]    beq    tl2com    ; thats all
  232.     beq    tl2ou7    ;[1.14] thats all
  233.     ldx    poutpt    ;[51] pointer to next ch to output
  234.     lda    outbuf,x    ;[51] get next ch
  235. tl2rpp    sta    kr2pch    ;[51] give it to card
  236.     jmp    tl2com    ;[51] common return
  237. tl2ou7    jsr    tl2noi    ;[1.14] turn off output
  238.     jmp    tl2noo    ;[1.14]
  239. tl2inp:    lda    kr2pch    ;[51] we have an input character
  240.     ldx    pinptr    ;[51] pointer to next input character
  241. store            ;[1.14] this is where we store the input chs
  242.     sta    inbuf,x    ;[51] save ch
  243. ;[1.14]    inc    pinptr    ;[51] ready for next input
  244.     bit    flowfg    ;[57] are we flow controll
  245.     bpl    tl2icm    ;[57] no we may overun the buffers
  246. ;    bvc    tl2in2    ;[59] are we already stoped?, yes
  247. ;[1.14]    lda    inbuf,x    ;[59] is host telling us stop ? bit doesnt des a reg
  248.     and    #$7f    ;[59] ignore parity
  249.     cmp    #ctrlq    ;[59] do we have a continue
  250.     bne    tl2in2    ;[59] no
  251.     lda    #$bf    ;[59] yes, now turn on flow
  252.     and    flowfg    ;[59]
  253.     sta     flowfg    ;[59]
  254.     jsr    tl2suo    ;[1.14] start up output
  255.     .ifne    debug    ;[1]
  256.     inc    coxon    ;[1] bump count of output xons given
  257.     .endc        ;[1]
  258. ;[1.14]    dec    pinptr    ;[59] and ignore this character
  259. ;[1.14]    jmp    tl2icm    ;[59] and carry on
  260.     jmp    tl2noo    ;[1.14] skip the increment
  261. tl2in2    cmp    #ctrls    ;[59] do we have a stop?
  262.     bne    tl2in4    ;[59]
  263.     .ifne    debug    ;[1]
  264.     inc    coxoff    ;[1] bump count of output xoffs given
  265.     .endc        ;[1]
  266.     lda    #$40    ;[59] yes tell all
  267.     ora    flowfg    ;[59] would you believe the remote
  268.     sta    flowfg    ;[59] has asked us to stop!
  269.     jsr    tl2suo    ;[1.14] start up output
  270. ;[1.14]    dec    pinptr    ;[59] ignore this character
  271. ;[1.14]    jmp    tl2icm    ;[1] thats all
  272.     jmp    tl2noo    ;[1.14] skip the increment
  273. tl2in4            ;[59] place to hang ones hat
  274. ;[1.14]    lda    xoff    ;[57] have we already asked for ^S ?
  275. ;[1.14]    bne    tl2icm    ;[57] yes no need for another
  276. ;[1.14]    txa        ;[59] lets try stoping when half full
  277. ;[1.14]    clc        ;[59]
  278. ;[1.8]    adc    #7    ;[1]
  279. ;[1.14]    adc    #128    ;[1.8]
  280. ;[1.14]    cmp    inptr    ;[59] are we filling up ?
  281. ;[1.14]    bne    tl2icm    ;[57] no
  282. ;[1.14]    inc    xoff    ;[57] turn on xoff(non 0)
  283. ;[1.14]    .ifne    debug
  284. ;[1.14]    inc    xofcnt    ;just for debug
  285. ;[1.14]    .endc
  286. tl2icm    
  287.     inc    pinptr    ;[1.14] now bump the ptr
  288.     bne    tl2noo    ;[1.14] thats all
  289.     ldx    store+2    ;[1.14] now for the msb
  290.     inx        ;[1.14]
  291.     cpx    #outbuf^    ;[1.14] too far?
  292.     bne    tl2ic0    ;[1.14] no
  293.     ldx    #inbuf^    ;[1.14] yes
  294. tl2ic0    stx    store+2    ;[1.14] update the msb
  295. tl2noo
  296. tl2xor    
  297. tl2com:    pla        ;[51] get x
  298.     tax        ;[51]
  299. tl2eac    lda    irqsva    ;[51] get a
  300. tl2rti    rti        ;[51] return from interupt
  301.  
  302. tl2noi    lda    #mnint    ; input interupts only
  303. tl2no7    sta    kr2pcr    ; give the command
  304.     rts        ;
  305. tl2suo    lda    #mnminb    ; both interupts
  306.     bne    tl2no7    ; common code    
  307.  
  308. tl2int:    sei        ; lock out interupts may be required for the //c
  309. ;[1.14]    lda    hdirq    ;see if we already saved
  310. ;[1.14]    bne    init0    ;yes
  311.     lda    hdirq+1    ;maybe
  312.     bne    init0    ;sure thing
  313.     lda    dirq    ;[51] save dos IR for exit
  314.     sta    hdirq    ;[51]
  315.     lda    dirq+1    ;[51]
  316.     sta    hdirq+1    ;[51]
  317.     lda    #start^
  318.     cmp    endker+1    ;are we loaded above main
  319.     beq    dontno        ;cant tell yet
  320.     bcc    trble        ;yes we are in trouble
  321.     bcs    setnm        ;ok
  322. dontno    lda    #start\        ;well lets check 16 bits
  323.     cmp    endker
  324. ;[1.14]    beq    setnm        ;whee just exactly right
  325.     bcs    setnm        ;ok
  326. trble    ldx    #bad\        ;got to tell someone
  327.     ldy    #bad^
  328.     jsr    tl2prn        ;print the message
  329. setnm:
  330. init0:    lda    kerins        ;[47] initialize slot
  331.     beq    init1
  332.     cli        ;[47] already initialized return
  333.     rts
  334.  
  335. ;     apple machine id
  336. ;rom-->    $fbb3             $fbc0
  337. ; II    $38
  338. ; II+    $ea
  339. ; //e    $06        $ea
  340. ; //e+            $e0    enhanced
  341. ; //c    $06        $00
  342. ;prodos-->    $bf98
  343. ; II,II+,//e    bit 3 = 0
  344. ; others    bit 3 = 1
  345. ; //c        bits 7,6 = 10
  346.  
  347. ;setc    ldx    #tecome-tecoms    ; size of the end of interupt
  348. ;setcl    lda    tecoms-1,x    ; move to the end
  349. ;    sta    tl2com-1,x
  350. ;    dex            ; are we thru
  351. ;    bne    setcl        ; no
  352. ;    lda    kersli        ; change from $n0 -> $0n
  353. ;    lsr    a
  354. ;    lsr    a
  355. ;    lsr    a
  356. ;    lsr    a
  357. ;    sta    tecome+1        ; make it short
  358. ;    ldx    #terpte-tecome    ; size of start of interupt
  359. ;setcl1    lda    tecome-1,x    ; move to the start
  360. ;    sta    tl2c-1,x
  361. ;    dex            ; thru ?
  362. ;    bne    setcl1        ; no
  363. ;    lda    #tl2c\        ; now for the interupt vector
  364. ;    sta    dirq
  365. ;    lda    #tl2c^
  366. ;    jmp    seten1        ; now for the common code        
  367. setc                ;[1.14]
  368.     lda    #$60        ;[1.14] its a rts
  369.     sta    tl2suo        ;[1.14] ignore this for //c
  370.     sta    tl2noi        ;[1.14]
  371.     bne    setenh        ;[1.14]
  372. init1    lda    $fbc0        
  373.     beq    setc        ; this is a //c
  374.     cmp    #$e0        ; is this an enhanced 2e?
  375.     bne    init3        ; no
  376. ;[1.14]setc
  377. setenh    lda    tl2rti        ; yes
  378.     sta    tl2com
  379.     lda    #tl2rpe\    ;[67][51]
  380.     sta    dirq    ;[67][51] setup inturpt address
  381.     lda    #tl2rpe^    ;[67][51]
  382. seten1    sta    dirq+1    ;[67][51]
  383.     ldx    #0        ; now set the stack straight
  384. seten2    lda    tl2nts+2,x    ; in case its not our interupt
  385.     sta    tl2nts,x
  386.     inx
  387.     cpx    #3        ; are we thru?
  388.     bne    seten2        ; no    
  389.     ldx    #0        ; now set up the ram banks for interupts
  390.     bit    $c011
  391.     bmi    .+4        ;hate to do this
  392.     ldx    #8
  393.     bit    $c012
  394.     bpl    .+4        ;ssigh!
  395.     inx
  396.     inx
  397.     bit    $c081
  398.     bit    $c081
  399.     phx            ;save the current state for later
  400. ;    .byte    $da
  401.     lda    $c016        ;how about it
  402.     asl    a
  403.     ldy    #1
  404. tl2ilp    lda    $fffe,y
  405.     sta    $c009        ;set alt card
  406.     sta    $fffe,y
  407.     sta    $c008        ;now for main ram
  408.     sta    $fffe,y
  409.     dey
  410.     bpl    tl2ilp
  411.     bcc    .+5        ;have we switch out the wrong one?
  412.     sta    $c009        ;yes
  413.     plx
  414. ;    .byte    $fa
  415.     bit    $c081,x
  416. ;    .byte    $3c,$81,$c0
  417.     bit    $c081,x
  418. ;    .byte    $3c,$81,$c0
  419.     jmp    init4        ;[67]
  420. init3
  421.      lda    #tl2rpt\    ;[67][51]
  422.     sta    dirq    ;[67][51] setup inturpt address
  423.     lda    #tl2rpt^    ;[67][51]
  424.     sta    dirq+1    ;[67][51]
  425. init4            ;[67]
  426.     lda    #0    ;[51] clear pointers etc
  427.     sta    inptr    ;[51]
  428.     sta    pinptr    ;[51]
  429.     sta    outptr    ;[51]
  430.     sta    poutpt    ;[51]
  431.     lda    #inbuf^    ;[1.14] and the msb also
  432.     sta    store+2    ;[1.14]
  433.     sta    get+2    ;[1.14]
  434.     ldx    kersli    ;[47] get slot number
  435.     stx    kerins    ;[67] tell weve been here
  436.     clc
  437. ;[1.14]    lda    status
  438.     lda    #kr2pst\    ;[1.14] easy way - status
  439.     adc    kersli    ; calculate proper address for status
  440.     sta    tl2rpe+1    ; and set interupt rtn
  441.     sta    cwsou1+1    ; [75] this was a tough bug to find
  442.     clc
  443. ;[1.14]    lda    getput
  444.     lda    #kr2pch\    ;[1.14] data
  445.     adc    kersli    ; calulate proper address for ld & st
  446.     sta    tl2rpp+1    ; and set interupt rtn
  447.     sta    tl2inp+1
  448.     sta    tl2oup+1
  449.     sta    cwsou2+1    ;[75] tough to find
  450.     sta    tl2pp7+1    ;[1.14]
  451.     lda    #kr2pcr\    ;[1.14] command
  452.     clc            ;[1.14]
  453.     adc    kersli        ;[1.14]
  454.     sta    tl2no7+1    ;[1.14]
  455.     lda    #mnminb    ;[47] Master port init
  456. ;[1.14]    sta    kr2pst,x    ;[47] Com port status
  457.     sta    kr2pcr,x    ;[47] Com master port
  458.     lda    #mncinb    ;[47] Control port init
  459.     and    #$f0    ;[47] drop baud
  460.     ora    sscdbd    ;[47] and add default baud
  461.     sta    kr2pcc,x    ;[47]
  462. tl2prr:    
  463.     cli        ;[51] allow the interurpts to happen
  464.     rts            ;[22] Return
  465. ;[1.14]status    .word    kr2pst    ; status port for ssc
  466. ;[1.14]getput    .word    kr2pch    ; read write port for ssc
  467.  
  468. tl2cp:    sei        ;[51] lockout inturpts
  469.     lda    inptr    ;[51] check input for chs
  470.     cmp    pinptr    ;[51]
  471.     bne    tl2cp3    ;[1.14] how about msb, no
  472.     lda    store+2    ;[1.14] yes check that also
  473.     cmp    get+2    ;[1.14]
  474. tl2cp3            ;[1.14]
  475.     cli        ;[51] allow interupts
  476.     rts            ;[22]        ...
  477.  
  478. tl2gpc:    sei        ;[51] lockout interupts
  479.     ldx    inptr    ;[51] get input character
  480. get            ;[1.14]
  481.     lda    inbuf,x    ;[51]
  482.     inc    inptr    ;[51] bump in pointer
  483.     bne    tl2gp0    ;[1.14]
  484.     ldy    get+2    ;[1.14] bump msb also
  485.     iny        ;[1.14]
  486.     cpy    #outbuf^    ;[1.14] too far?
  487.     bne    tl2gp7    ;[1.14] no
  488.     ldy    #inbuf^    ;[1.14] yes, circle those wagons
  489. tl2gp7    sty    get+2    ;[1.14] msb
  490. ;[1.14]    ldy    xon    ;[57] are we flow controlling ?
  491. ;[1.14]    beq    tl2gp0    ;[57] no
  492. ;[1.14]    inx        ;[57]
  493. ;[1.14]    inx        ;[57]
  494. ;[1.14]    inx        ;[57]
  495. ;[1.14]    cpx    pinptr    ;[57] have we about caught up ?
  496. ;[1.14]    bne    tl2gp0    ;[57] no
  497. ;[1.14]    pha        ;[1.8]
  498. ;[1.14]    lda    #ctrlq    ;[1.14] bug pure and simple
  499. ;[1.14]    jsr    cwsout    ;[1.8]
  500. ;[1.14]    beq    tl2gp4    ;[1.8] depend on acc of 0
  501. ;[1.14]    lda    #0    ;[1.8]
  502. ;[1.14]    sta    xon    ;[1.8]
  503. ;[1.14]tl2gp4    sta    xoff    ;[1.8]
  504. ;[1.14]    pla        ;[1.8]    
  505. ;    pha        ;[57] save ch
  506. ;[1.8]    ldy    #0    ;[57] turn off xon
  507. ;[1.8]    sty    xoff    ;[57]
  508. ;    pla        ;[57] restore ch
  509. tl2gp0:
  510.     cli        ;[51] allow interupts
  511. tl2rtc:    rts            ;[22]    and return
  512.  
  513. tl2ppc:                ;[22] Hold the byte to send
  514.     sei        ;[51] lockout interupts
  515.     ldx    outptr    ;[51] get output pointer
  516.     sta    outbuf,x    ;[51] save in buffer for interupt
  517.     cpx    poutpt    ; has output stalled ?
  518.     bne    tl2pp2    ; no were still busy outputing
  519. ;[1.14]    ldx    kersli    ; get slot
  520. ;[1.14]    sta    kr2pch,x    ; and give ssc the ch
  521. tl2pp7    sta    kr2pch        ;[1.14]
  522.     jsr    tl2suo        ;[1.14] start up output
  523. tl2pp2
  524.     inc    outptr    ;[51] ready for next output
  525.     cli        ;[51] allow interupts
  526.     rts            ;[22]    and return
  527.  
  528. tl2exi:    sei        ;lockout interupts
  529. ;[1.10]    lda    hdirq    ;have we alredy done this?
  530. ;[1.10]    bne    exit0    ;nope
  531.     lda    hdirq+1    ;maybe
  532.     beq    exit9    ;definitly
  533. exit0:    lda    hdirq    ;[51] restore dos IRQ address
  534.     sta    dirq    ;[51]
  535.     lda    hdirq+1    ;[51]
  536.     sta    dirq+1    ;[51]
  537.     lda    #0    ;tell we did this
  538. ;[1.10]    sta     hdirq
  539.     sta    hdirq+1
  540.     ldx    kersli    ;[47] get slot number
  541.     sta    kr2pst,x    ;shut it down
  542.     sta    kr2pcr,x    
  543. ;[1.12]exit9:    cli        ;allow the interupts
  544. exit9:    ;[1.12]cli        ;allow the interupts
  545.     rts
  546. cwsout    ;ldx    kersli    ; see if we can start up output
  547.     tax        ; save the output ch
  548. cwsou1    lda    kr2pst    ; get the status
  549.     and    #mssoub    ; is the output bit 1?
  550.     beq    cwsou3    ; no sigh!
  551.     txa        ; get the ch to output
  552.     and    #$7f    ; drop parity
  553.     jsr    telspa    ; set parity correctly x reg clobbered
  554. cwsou2    sta    kr2pch    ; send the ch
  555.     jsr    tl2suo    ;[1.14]
  556.     lda    #true    ; say we did it
  557. cwsou3    rts        ; bye
  558. tl2cmd:            ;find out what command
  559. ;[1.14]    beq    tl2rts    ;its drop line and we cant
  560.     beq    tl2exi    ;[1.14]its drop line
  561.     cmp    #$0c
  562.     beq    break    ;its a break command
  563.     cmp    #$0b
  564.     beq    baud       ;its a set baud command
  565.     cmp    #hxon    
  566.     beq    txon    ;its a turn xon
  567.     cmp    #hxoff
  568.     beq    txoff    ;its a turn xoff
  569.     jsr    prbyte    ;print command
  570.     ldx    #bcom\    ;and tell all
  571.     ldy    #bcom^
  572. tl2prn    jsr    prstr
  573.     jsr    prcrlf
  574. tl2fls:            ;a false return
  575. tl2rts:            ;tell that we cant
  576.     lda    #0    ;unknown command
  577.     rts        ;return
  578. txon:    ;bit    flowfg    ;do we have flow control
  579. ;    bpl    tl2fls    ;no can do
  580.     sei        ;protect ourselves from interupts
  581.     .ifne    debug    ;[1]
  582.     inc    cixon    ;[1] bump count of xon requests
  583.     .endc        ;[1]
  584.     jsr    cwsout    ; can we start up output?
  585.     beq    txon3    ; no do the interupt thing
  586.     lda    #0    ; yes, tell its all done
  587.     sta    xoff
  588.     sta    xon
  589.     .ifne    debug    ;[1]
  590.     inc    cinixn    ;[1] bump count of xon requests without interupts
  591.     .endc        ;[1]
  592.     lda    #true    ; tell its ok
  593.     cli        ; allow interupts
  594.     rts        ; thats all
  595. txon3            ; do the interupt flow control
  596.     lda    #0    
  597.     sta    xoff    ;tell interupt to start up
  598.     cli
  599. ltxon    lda    xon    ;[1] got to wait for ch to be sent
  600.     bne    ltxon    ;[1] its called true syncronization
  601.     lda    #true    ;give a true return
  602.     rts
  603. txoff:    ;bit    flowfg    ;do we have flow control ?
  604. ;    bpl    tl2fls    ;no
  605.     sei
  606.     .ifne    debug    ;[1]
  607.     inc    cixoff    ;[1] bump count of xoff requests
  608.     .endc        ;[1]
  609.     jsr    cwsout    ; can we send output
  610.     beq    txoff3    ; no sigh!
  611.     .ifne    debug    ;[1]
  612.     inc    cinixf    ;[1] bump count of xoff requests without interupt
  613.     .endc        ;[1]
  614.     lda    #true    ; just in case we have to xon via interupts
  615.     sta    xon
  616.     sta    xoff
  617.     cli        ; allow interupts
  618.     rts
  619. txoff3            ; do it durring interupt
  620.     lda    #true    ;we need xoff
  621.     sta    xoff    ;this also gives a true return
  622.     cli
  623. ltxoff    lda    xon    ;[1] wait for it to be sent
  624.     beq    ltxoff    ;[1] are we syncronized? no
  625.     rts
  626. baud:    ldx    kersli    ;[47] get slot number
  627.     sei        ;protect ourselves
  628.     lda    kr2pcc,x    ;[47] get com control
  629.     and    #$f0    ;[47] and clear baud
  630.     ora    sscdbd    ;[47] enter
  631.     sta    kr2pcc,x    ;[47] and set new baud rate
  632.     cli        ; now its ok
  633.     rts        ;return true(non 0)
  634. break:
  635.     sei        ;lock out interupts
  636.     ldy    kersli        ;[47] ss card routine is not on
  637. ;[1.13]    lda    #$c        ;[47]
  638.     lda    kr2pcr,y    ;[1.13] get current command
  639.     ora    #$c        ;[1.13] now for the break
  640.     sta    kr2pcr,y    ;[47] start the break
  641. ;[1.9]    lda    #233        ;[47] for 233 millseconds
  642. ;[1.9]    jsr    wait        ;[47] the y reg is not clobered
  643. ;[1.14]    lda    #220        ;[1.9] wait 125 ms
  644.     lda    #233        ;[1.9] wait 233 ms
  645.     sta    kwrk01        ;[1.14]
  646. break3    lda    timect        ;[1.14] 1 ms at a time
  647.     jsr    wait        ;[1.9] only the a reg is clobered
  648.     dec    kwrk01        ;[1.14]
  649.     bne    break3        ;[1.14]
  650. ;[1.14]    lda    #206        ;[1.9] how about 108 ms
  651. ;[1.14]    jsr    wait        ;[1.9] only the a reg is clobered
  652.     lda    #mnminb        ; start up the port again
  653.     sta    kr2pcr,y    ;[47]
  654.     cli        ;allow interupts
  655.     lda    #true    ;return true
  656.     rts
  657. ;[1.14]inbuf    .blkb    256    ;input buffer
  658. inbuf    .blkb    $900    ;[1.14]input buffer ***** inbuf & outbuf no separations
  659. outbuf    .blkb    256    ;output buffer
  660. endcom            ;[1.11]
  661.