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

  1. .TITLE    KERMIT-65 Mountain Hardware CPS card
  2. .SBTTL    6502 version - Alan Thomson
  3.  
  4. ;    Version 1.0
  5. ;    Supports only the serial part of the card
  6. ;    Does not use interrupts
  7.  
  8. ;    Based on the KERMIT Protocol.
  9.  
  10. ;    $Header: appcps.m65,v 1.5 90/10/15 14:19:59 medin Locked $
  11. .SBTTL    Define start address for assembly
  12.  
  13.        .=$1003            ; Start assembly at hex 1003
  14.  
  15. .SBTTL    Revision History
  16.  
  17. ;
  18. ; Edit #    Description
  19. ; ------    -----------
  20. ;
  21.  
  22. ;$Log:    appcps.m65,v $
  23. Revision 1.5  90/10/15  14:19:59  medin
  24. new org for 3.87 of $7f00
  25. version 1.4
  26.  
  27. ;Revision 1.4  88/12/22  09:25:02  medin
  28. ;use the time constant for the wait routine
  29.  
  30. ;Revision 1.3  88/01/15  08:42:03  medin
  31. ;New origin for 3.81
  32.  
  33. ;Revision 1.2  87/06/29  11:02:31  medin
  34. ; Change wait rtn to use apple rom rtn, change org for 3.78
  35.  
  36. ;Revision 1.1  87/06/29  09:26:27  medin
  37. ;Initial revision
  38.  
  39. ;
  40. ;
  41. ;    Vector for com cards starts here 
  42. ;        location $1003 for data
  43. ;        location $1020 for routine jumps
  44. ;        location $1040 for main routines
  45. ;
  46. sscdbd:    .blkb    1  ;contains baud index(ala super serial card) used by init
  47.             ;        6 - 300 baud
  48.             ;        7 - 600 
  49.             ;        etc
  50.     .blkb    1    
  51. crdnam:    .word    herld    ; null terminated string of who we are
  52. kersli:    .blkb    1    ; com slot $n0
  53. kerins:    .blkb    1    ; force initialization flag-when 0
  54. endker:    .blkb    2    ; address of end of main kermit
  55. flowfg:    .blkb    1    ; flow flag for xon/xoff controll b7=1 yes
  56. tl0end    .word    endcom    ;[1.2] end of this routine
  57. timect    .blkb    1    ;[1.3] 1 ms delay via rom wait rtn
  58.     .=$1020        ; future expansion
  59. tlinit:    jmp    tl2int        ; initialize com card
  60. tl0cmd:    jmp    tl2cmd        ; command for ACIA in A
  61.             ;
  62.             ; 0 - hang up 
  63.             ; $0b - set baud
  64.             ; $0c - set break on the line
  65.             ; $91 - xon
  66.             ; $93 - xoff
  67.             ;
  68.             ; routine will return false(0) if unable
  69. tl0cp:    jmp    tl2cp        ; check for input ch ready-0 false
  70. tl0gpc:    jmp    tl2gpc        ; get input ch
  71. tl0ppc:    jmp    tl2ppc        ; put output character
  72. tl0exi:    jmp    tl2exi        ; reset card and restore initialized
  73.     .=$1040        ; futures
  74. ;[1.1]wait:    .blkb    3    ; wait routine-a reg contains milliseconds
  75. wait:    .blkb    3    ;[1.1] wait routine-use apple rom rtn 220=125ms,206=108ms,25=2ms
  76. prstr:    .blkb    3    ; print string x=lsb,y=msb x&y->null terminated string
  77. rdkey:    .blkb    3    ; read keyboard
  78. prcrlf:    .blkb    3    ; print cr and lf
  79. telcnc:    .blkb    3    ; check for keyboard character
  80. telspa:    .blkb    3    ; set character parity
  81.  
  82. ;[1.1]    .=$6c00    ; place to start com card assembly
  83.     .=$7f00    ;[1.4][1.2] place to start com card assembly
  84. start    =    .        ;need a label at begining
  85. data    =    $C0FA        ;data port
  86. mode    =    $C0FA        ;mode reg
  87. status    =    $C0FB        ;status port
  88. command    =    $C0FB        ;command port
  89. control    =    $C0FE        ;control port
  90. initbd    =    $35    ; Baud init (300 baud)
  91. framing    =    $4E    ; Framing init (8bit, no par. , 1 stop, 16x)
  92. rcvst    =    $C2    ; status bit for input ready
  93. xmitst    =    $C1    ; status for output ready
  94. xmitcmd    =    $27    ; transmit command
  95. pinptr:    .byte        ; input buffer pointer
  96. inptr:    .byte        ; input buffer pointer for get
  97. poutpt    .byte        ; output buffer pointer
  98. outptr    .byte        ;   "       "     "    for put
  99. kwrk01    .byte        ;[1.3]
  100. scrlo    =    $0    ; sets control bit low
  101. scrhi    =    $80    ; sets control bit high
  102. irqsva    =    $45    ;place dos saves a reg
  103. hctrlq    =    $91    ;^Q with high bit on
  104. hctrls    =    $93    ;^S "
  105. ctrlq    =    $11    ; ^Q
  106. ctrls    =    $13    ; ^S
  107. dirq    =    $3fe    ; interupt address
  108. herld    nasc    <MOUNTAIN HARDWARE CPS V1.4> 1    ;tell who we are
  109. bad    nasc    <*****ERROR***** COM ROUTINES ASSEMBLED TOO LOW IN MEMORY> 1
  110.  
  111. ;
  112. ;    CPS serial interface support
  113. ;
  114. chkwst    lda    #xmitcmd    ;Wait for vacant transmit reg.
  115.     jsr    setcmd        ;set transmit command
  116. chk1    lda    status        ;get status reg
  117.     and    #xmitst        ;mask unwanted bits
  118.     cmp    #xmitst        ;is transmit reg clear?
  119.     bne    chk1        ;no it isn't, go back
  120.     rts            ;yes it is 
  121.  
  122.  
  123. setcmd    pha            ;save acc
  124.     lda    #scrhi        ;set bit
  125. v1    sta    control        ;set control for command access
  126.     pla            ;recover acc
  127. v2    sta    command        ;write command
  128.     lda    #scrlo        ;unset bit
  129. v3    sta    control        ;reset control reg
  130.     rts
  131.  
  132.  
  133. tl2int:
  134.     lda    #start^
  135.     cmp    endker+1    ;are we loaded above main
  136.     beq    dontno        ;cant tell yet
  137.     bcc    trble        ;yes we are in trouble
  138.     bcs    setnm        ;ok 
  139. dontno    lda    #start\        ;well lets check 16 bits
  140.     cmp    endker
  141.     beq    setnm        ;whee just exactly right
  142.     bcs    setnm        ;ok
  143. trble    ldx    #bad\        ;got to tell someone
  144.     ldy    #bad^
  145.     jsr    prstr        ;print the message
  146.     jsr    prcrlf        ;and terminate it properly
  147. setnm:
  148.     lda    kerins
  149.     bne    tl2prr    ; already initialized
  150.     lda    #0    ; clear pointers etc
  151.     sta    pinptr    ; buffer starts at 0
  152.     sta    inptr    ; buffer starts at 0
  153.     sta    poutpt    ;    "
  154.     sta    outptr    ;    "
  155.     lda    kersli    ;now for the slot $n0
  156.     lsr    a    ;rotate acc 4bits
  157.     lsr    a
  158.     lsr    a
  159.     lsr    a
  160.     and    #$0f    ;isolate bottom bits
  161.     ora    #$c0    ;create address
  162.     jsr    setslot    ;and store in relevant locs
  163.     lda    #scrhi    ;set bit
  164. v4    sta    control    ;set control for mode access
  165.     lda    #framing
  166. v5    sta    mode    ;write framing
  167.     lda    sscdbd    ;get baud code
  168.     cmp    #$0a    ;is it 9 or less?
  169.     bmi    baudx    ;yes it is
  170.     sec        ;no it isnt
  171.     bcs    baudy    ;always taken
  172. baudx    clc
  173. baudy    lda    #initbd    ;get baud initialisation
  174.     and    #$f0    ;drop baud
  175.     ora    sscdbd    ;add new baud
  176.     sbc    #$0    ;reduce by 1 if baud code <=9
  177. v6    sta    mode    ;set baud rate
  178.     lda    #scrlo    ;unset bit
  179. v7    sta    control    ;reset control
  180.     lda    #xmitcmd    ;set for transmit
  181.     jsr    setcmd    ;and set
  182.     lda    #$01
  183.     sta    kerins    ;set init done reg
  184. tl2prr    rts        ;return
  185.  
  186. tl2cp:    lda     status        ; Try for a character
  187.     and    #rcvst        ; mask out bits
  188.     cmp    #rcvst        ; is receive reg full?
  189.     bne    tl2cp7        ; no we dont have a ch
  190. v8    lda    data        ; yes get ch
  191.     ldy    pinptr        ; where to put it in buf
  192.     sta    inbuf,y        ; save it
  193.     inc    pinptr        ; ready for next ch
  194.     bit    flowfg        ; how about flow control
  195.     bpl    tl2cp7        ; no
  196.     lda    inbuf,y        ; get input ch
  197.     and    #$7f        ; drop parity etc
  198. ;    bvc    tl2cp4        ; yes,how about ^S received?, no
  199.     cmp    #ctrlq        ; is this continue(start up outputing)
  200.     bne    tl2cp4        ; no, check for ^S
  201.     lda    flowfg        ; tattle about the continue
  202.     and    #$bf        ; 
  203.     sta    flowfg        ; 
  204.     dec    pinptr        ; forget about this character
  205. tl2cp2    ldy    outptr        ; see if any to output
  206.     cpy    poutpt        ; well?
  207.     beq    tl2cp7        ; no more we have put all
  208. tl2cp3    jsr    chkwst        ; check status for output
  209.     lda    outbuf,y    ; output ch
  210. v9    sta    data        ; bye
  211.     inc    outptr        ; ready for next
  212.     jmp    tl2cp2        ; 
  213. tl2cp4    cmp    #ctrls        ; is this stop?
  214.     bne    tl2cp7        ; no
  215.     lda    #$40        ; yes, tattle
  216.     ora    flowfg        ; 
  217.     sta    flowfg        ; now everyone knows
  218.     dec    pinptr        ; forget about the ^S character
  219. tl2cp7:
  220.     lda    pinptr
  221.     cmp    inptr
  222.     rts            ;return with false(0) or true(non 0)
  223.  
  224. tl2gpc:    ldx    inptr        ; get where it is in buf
  225.     lda    inbuf,x        ; get the ch
  226.     inc    inptr        ; ready for next get
  227. tl2rtc:    rts            ;    and return
  228.  
  229. tl2ppc:    pha            ; Hold the byte to send
  230. tl2pp1:    lda    #xmitcmd    ; load command
  231.     jsr    setcmd        ; send it
  232. v10    lda    status        ; Get the status byte
  233.     and    #xmitst        ; Isolate the bits we want
  234.     cmp    #xmitst        ;is it empty
  235.     bne    tl2pp2        ; Transmit register is NOT empty, try again
  236.     bit    flowfg        ; flow control?
  237.     bpl    tl2pp0        ; no
  238.     bvc    tl2pp0        ; should we stop outputing?,no
  239.     ldy    poutpt        ; yes, save this ch in buffer
  240.     pla            ; 
  241.     sta    outbuf,y    ; 
  242.     inc    poutpt        ; tell how many
  243.     rts            ; thats all
  244. tl2pp0                ; 
  245.     pla            ; Fetch the data byte off the stack
  246. v11    sta    data        ; Stuff it at the proper loc to send it
  247.     rts            ;    and return
  248. tl2pp2:    jsr    tl2cp        ; see if there is an input ch
  249.     jmp    tl2pp1        ;and try again
  250.  
  251. tl2exi:
  252.     lda    #0        ;tell we did this
  253.     sta    kerins        ;just in case init gets called
  254. exit9:    rts
  255. tl2cmd:            ;find out what command
  256.     beq    tl2rts    ;its drop line and we cant
  257.     cmp    #$0c
  258.     beq    break    ;its a break command
  259.     cmp    #$0b
  260.     beq    baud       ;its a set baud command
  261.     cmp    #hctrlq
  262.     beq    tl2sac    ;its a xon command
  263.     cmp    #hctrls
  264.     beq    tl2sac    ;its a xoff command
  265. tl2fls:    lda    #0    ;unknown command
  266. tl2rts:    rts        ;que passo ? return false(0)
  267. tl2sac:    ldx    flowfg    ;do we have flow control
  268.     bpl    tl2fls    ;no return false
  269.     and    #$7f    ;drop high bit and send the ch
  270.     jsr    telspa    ;set parity
  271.     jsr    tl2ppc    ;output the ch
  272.     lda    #1    ;set true return
  273.     rts
  274. baud:    lda    #scrhi    ;set bit
  275. v12    sta    control    ;set control for mode access
  276.     lda    #framing
  277. v13    sta    mode    ;write framing
  278.     lda    sscdbd    ;get baud code
  279.     cmp    #$0a    ;is it 9 or less?
  280.     bmi    baudx1    ;yes it is
  281.     sec        ;no it isnt
  282.     bcs    baudy1    ;always taken
  283. baudx1    clc
  284. baudy1    lda    #initbd    ;get baud initialisation
  285.     and    #$f0    ;drop baud
  286.     ora    sscdbd    ;add new baud
  287.     sbc    #$0    ;reduce by 1 if baud code <=9
  288. v14    sta    mode    ;set baud rate
  289.     lda    #scrlo    ;unset bit
  290. v15    sta    control    ;reset control
  291.     lda    #xmitcmd
  292.     jsr    setcmd    ;set for transmit
  293.     lda    #xmitst
  294.     rts        ;return true(non 0)
  295. break:
  296.     lda    #scrhi        ; set bit
  297. v16    sta    control        ; select command reg
  298. v17    lda    command        ; get current command
  299.     pha            ;
  300.     lda    #$08        ;
  301. v18    sta    command        ; start the break
  302. ;[1.1]    lda    #233        ; for 233 millseconds
  303. ;[1.1]    jsr    wait        ; the y reg is not clobered
  304. ;[1.3]    lda    #220        ;[1.1] 125ms
  305.     lda    #233        ;[1.3] 233 ms
  306.     sta    kwrk01        ;[1.3] 1 ms at a time
  307. break3    lda    timect        ;[1.3]
  308.     jsr    wait        ;[1.1]
  309.     dec    kwrk01        ;[1.3]
  310.     bne    break3        ;[1.3]
  311. ;    lda    #206        ;[1.1] 108ms
  312. ;    jsr    wait        ;[1.1] for a grand total of 233ms
  313.     pla            ; restore command
  314. v19    sta    command        ; rewrite
  315.     lda    #scrlo        ; unset bit
  316. v20    sta    control        ; do it
  317.     lda    #1        ;return true
  318.     rts
  319. ;
  320. setslot    sta    tl2cp+2        ;Stores correct ioslot in the various
  321.     sta    chk1+2        ;io instructions
  322.     sta    v1+2
  323.     sta    v2+2
  324.     sta    v3+2
  325.     sta    v4+2
  326.     sta    v5+2
  327.     sta    v6+2
  328.     sta    v7+2
  329.     sta    v8+2
  330.     sta    v9+2
  331.     sta    v10+2
  332.     sta    v11+2
  333.     sta    v12+2
  334.     sta    v13+2
  335.     sta    v14+2
  336.     sta    v15+2
  337.     sta    v16+2
  338.     sta    v17+2
  339.     sta    v18+2
  340.     sta    v19+2
  341.     sta    v20+2
  342.     rts
  343.  
  344. inbuf    .blkb    256        ;input buffer
  345. outbuf    .blkb    256        ;output  "
  346. endcom            ;[1.2]
  347.