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

  1. .TITLE    KERMIT-65 Hayes micro modem
  2. .SBTTL    6502 version - Ted Medin
  3.  
  4. ;    Version 1.0
  5.  
  6. ;    Based on the KERMIT Protocol.
  7.  
  8. ;    $Header: apphmm.m65,v 1.8 90/10/15 14:23:32 medin Locked $
  9. .SBTTL    Define start address for assembly
  10.  
  11.        .=$1003            ;[39] Start assembly at hex 1003
  12.  
  13. .SBTTL    Revision History
  14.  
  15. ;
  16. ; Edit #    Description
  17. ; ------    -----------
  18. ;
  19.  
  20. ;$Log:    apphmm.m65,v $
  21. Revision 1.8  90/10/15  14:23:32  medin
  22. new org of $7f00 for 3.87
  23. version 1.8
  24.  
  25. ;Revision 1.7  88/12/22  09:26:51  medin
  26. ;use the time constant for the wait routine
  27.  
  28. ;Revision 1.6  88/02/06  21:41:04  medin
  29. ; Correct bug in checking status for output ready. Happens only when
  30. ;host has asked us to stop flow.
  31. ;Change output routine to check for input ch ready before exiting.
  32.  
  33. ;Revision 1.5  88/01/15  08:41:26  medin
  34. ;New origin for 3.81
  35.  
  36. ;Revision 1.4  87/06/29  10:39:29  medin
  37. ; Change wait routine to use apple rom wait, change org to work with 3.78.
  38.  
  39. ;Revision 1.3  87/05/13  18:11:36  medin
  40. ; Change org to correspond with 3.76
  41.  
  42. ;Revision 1.2  87/02/21  00:01:58  medin
  43. ;Put the version in the hearld so we can keep track  of the com drivers
  44. ;also. Thanks Rhoda.
  45.  
  46. ;DONT FORGET TO UPDATE THE VERSION
  47. ;Revision 1.1  86/10/28  10:32:10  medin
  48. ;Initial revision
  49.  
  50. ;
  51. ;
  52. ;    Vector for com cards starts here 
  53. ;        location $1003 for data
  54. ;        location $1020 for routine jumps
  55. ;        location $1040 for main routines
  56. ;
  57. sscdbd:    .blkb    1  ;[54]contains baud index(ala super serial card) used by init
  58.             ;        6 - 300 baud
  59.             ;        7 - 600 
  60.             ;        etc
  61.     .blkb    1    ;
  62. crdnam:    .word    herld    ;[54] null terminated string of who we are
  63. kersli:    .blkb    1    ;[54] com slot $n0
  64. kerins:    .blkb    1    ;[54] force initialization flag-when 0
  65. endker:    .blkb    2    ;[54] address of end of main kermit
  66. flowfg:    .blkb    1    ;flow control (xon xoff) flag true when hi bit set
  67. tl0end    .word    endcom    ;[1.5] end of this routine
  68. timect    .blkb    1    ;[1.7] 1 ms of delay via rom wait rtn
  69.     .=sscdbd+29        ;[54] future expansion
  70.     jmp    tl2int        ;[54] initialize com card
  71.     jmp    tl2cmd        ;[54] command for ACIA in A
  72.             ;
  73.             ; 0 - hang up 
  74.             ; $0b - set baud
  75.             ; $0c - set break on the line
  76.             ; $91 - xon
  77.             ; $93 - xoff
  78.             ;
  79.             ;[54] routine will return false(0) if unable
  80.     jmp    tl2cp        ;[54] check for input ch ready-0 false
  81.     jmp    tl2gpc        ;[54] get input ch
  82.     jmp    tl2ppc        ;[54] put output character
  83.     jmp    tl2exi        ;[54] reset card and restore initialized
  84.     .=sscdbd+29+32        ;[54] futures
  85. ;[1.4]wait:    .blkb    3    ;[54] wait routine-a reg contains milliseconds
  86. wait:    .blkb    3    ;[1.4] apple rom wait rtn 220=125ms,206=108ms,25=2ms
  87. prstr:    .blkb    3    ;[54] print string-x=lsb,y=msb of null terminated string
  88. urdkey:    .blkb    3    ;[54] read keyboard
  89. prcrlf:    .blkb    3    ;[54] print cr and lf
  90. telcnc    .blkb    3    ;check for keyboard character
  91. telspa    .blkb    3    ;set character parity
  92.  
  93. ;[1.4]    .=$7200    ;[54] place to start com card assembly
  94.     .=$7f00    ;[1.8][1.5] place to start com card assembly
  95. start    =    .        ;need a label at begining
  96. kr0pch    =    $c087        ;[12] Base for port char location (DC Hayes)
  97. kr0pst    =    $c086        ;[12] Base for port strobe locations (DC Hayes)
  98. kr0pcr    =    $c086        ;[41] Base for prot control register (DC Hayes)
  99. kr0pcc    =    $c085    ;[48] Modem control port
  100. kbd    =    $c000        ; Keyboard character input location
  101. cr    =    $d        ; <cr>
  102. apinc1    =    3    ;[48] first init char for 6850 acia
  103. apinc2    =    $11    ;[48] second init (8-bits)
  104. hctrlq    =    $91    ;^Q with high bit set
  105. hctrls    =    $93    ;^S  "
  106. hctrlz    =    $9a    ;^Z  "
  107. ctrlq    =    $11    ;[59] ^Q
  108. ctrls    =    $13    ;[59] ^S
  109. setio2    =    $fe93    ; place for pr#0
  110. cswl    =    $36
  111. cswh    =    $37
  112. rdkey    =    $fd0c    ; read a ch from current input device
  113. cout    =    $fded    ; print a ch to current output device
  114. kwrk01    .byte        ;[1.7]
  115. temp    .byte        ;[48] work space for dial
  116. pinptr    .byte        ; input buffer pointer
  117. inptr    .byte        ; input buffer pointer for get
  118. poutpt    .byte        ;[59]  output buffer pointer
  119. outptr    .byte        ;[59]     "       "     "    for put
  120. ksli    .byte        ; com slot $0n
  121. dch.cr    =    $7f8        ;[41] Save area for Control register
  122. herld    nasc    <HAYES MICRO MODEM V1.8> 1    ;tell who we are
  123. bad    nasc    <COM ROUTINES ASM TOO LOW IN MEMORY> 1
  124. dialms:    nasc    <NUMBER TO DIAL:> 1    ;[48]
  125. dialm2:    nasc    <AWAITING CARRIER...ANY KEY ABORTS> 1    ;[48]
  126. dialm3:    nasc    <CONNECTED.> 1    ;[48]
  127. dialm4    nasc    <THERE WILL BE A 35 SEC DELAY> 1
  128.  
  129.  
  130. ;
  131. ;    D. C. Hayes I/O Device support - These routines support the
  132. ;        D. C. Hayes Micromodem.
  133. ;
  134.  
  135.  
  136. tlini9:    lda    #1        ;[59] give true return
  137.     rts        ;[48] only way to reach this
  138.  
  139. tl2int:    
  140.     lda    #start^
  141.     cmp    endker+1    ;are we loaded above main
  142.     beq    dontno        ;cant tell yet
  143.     bcc    trble        ;yes we are in trouble
  144.     bcs    setnm        ;ok 
  145. dontno    lda    #start\        ;well lets check 16 bits
  146.     cmp    endker
  147.     beq    setnm        ;whee just exactly right
  148.     bcs    setnm        ;ok
  149. trble    ldx    #bad\        ;got to tell someone
  150.     ldy    #bad^
  151.     jsr    prstr        ;print the message
  152.     jsr    prcrlf        ;and terminate it properly
  153. setnm:
  154. init0:    
  155.  
  156. tlinit:            ;[48]
  157.     ldx    kersli    ;[48] get device slot
  158.     lda    kr0pch,x    ;[48] access data
  159.     lda    kr0pst,x    ;[48] now for the status
  160.     and    #4    ;[48] do we have a carrier?
  161.     beq     tlini9    ;[48] yes,carry on
  162.     txa        ; calculate $0n from $n0
  163.     lsr    a
  164.     lsr    a
  165.     lsr    a
  166.     lsr    a
  167.     sta     ksli    ; now we have $0slot
  168.     ldx    #dialm4\    ; tell about the delay
  169.     ldy    #dialm4^
  170.     jsr    prstr
  171.     jsr    prcrlf        ;and make it look nice
  172.     lda    cswl    ; save output hooks
  173.     pha
  174.     lda    cswh
  175.     pha
  176.     lda    ksli    ; now make it pr#slot
  177.     jsr    setio2+2
  178.     lda    #hctrlq    ; ^q starts dialing
  179.     jsr    cout
  180.     lda    #cr+$80    ; ^m end of dialing wait for carrier
  181.     jsr    cout
  182.     lda    #hctrlz    ; ^z hang up
  183.     jsr    cout
  184. ;[1.4]    lda    #10
  185.     lda    #20    ;[1.4]
  186.     sta    temp    ; wait for 2.5 sec, slow phone co
  187. ;[1.4]tlini0    lda    #250
  188. ;[1.4]    jsr    wait    ; .250 sec at a time
  189. ;[1.7]tlini0    lda    #220    ;[1.4] 125 ms
  190. tlini0    lda    #125    ;[1.7] 125 ms
  191.     sta    kwrk01    ;[1.7]
  192. tlinii    lda    timect    ;[1.7] 1 ms at a time
  193.     jsr    wait    ;[1.4]
  194.     dec    kwrk01    ;[1.7]
  195.     bne    tlinii    ;[1.7]
  196.     dec    temp
  197.     bne    tlini0
  198.     pla        ; we are now thru so restore output
  199.     sta    cswh
  200.     pla    
  201.     sta    cswl
  202.     lda    #$8d    ;[48] go offhook to dial
  203.     ldx    kersli    ;[48] get slot again and again and again ...
  204.     sta    kr0pcc,x    ;[48]
  205.     lda    #apinc1        ;[48] init acia ch 1
  206.     sta    kr0pch,x    ;[48]
  207.     lda    #apinc2        ;[48] init acia ch 2
  208.     sta    kr0pch,x    ;[48]
  209. ;[1.4]    lda    #10    ;[48] now to wait 2.5 sec
  210.     lda    #20    ;[1.4] now to wait 2.5 sec 125ms at a time
  211.     sta    temp    ;[48]
  212. ;[1.4]tlini2: lda    #250    ;[48] 250 ms.
  213. ;[1.7]tlini2: lda    #220    ;[1.4] 125 ms.
  214. tlini2: lda    #125    ;[1.7] 125 ms.
  215. ;[1.4]    jsr    wait    ;[48] there goes x again
  216.     sta    kwrk01    ;[1.7] 1 ms at a time
  217. tlinih    lda    timect    ;[1.7]    
  218.     jsr    wait    ;[1.4]
  219.     dec    kwrk01    ;[1.7]
  220.     bne    tlinih    ;[1.7]
  221.     dec    temp    ;[48]
  222.     bne    tlini2    ;[48] all 2.5 sec? no
  223.     ldx    #dialms\    ;[48] now for the dial message
  224.     ldy    #dialms^    ;[48]
  225.     jsr    prstr    ;[48] print it
  226. tlini5:    jsr    rdkey    ;[48] get a ch from keyboard
  227.     jsr    cout    ; and print it
  228.     and    #$7f    ;[48] drop high bit
  229.     cmp    #'0    ;[48] you can never tell what one types
  230.     bmi    notnum    ;[48] its not in the number range fro ascii
  231.     cmp    #$3a    ;[48] well it may be a number
  232.     bpl    notnum    ;[48] no, its too big
  233.     and    #$f    ;[48] get the digits
  234.     bne    tlini3    ;[48] is it a zero
  235.     lda    #10    ;[48] yes, thats 10 pulses
  236. tlini3:    sta    temp    ;[48] thats the count of pulses
  237. tlini4:    lda    #$d    ;[48] go on hook
  238.     ldx    kersli    ;[48] the slot again
  239.     sta    kr0pcc,x    ;[48] tell the chip
  240. ;[1.4]    lda    #61    ;[48] this is a 61 ms delay
  241. ;[1.7]    lda    #154    ;[1.4] this is a 61 ms delay
  242.     lda    #61    ;[1.7] this is a 61 ms delay
  243.     sta    kwrk01    ;[1.7]
  244. tlinib    lda    timect    ;[1.7] 1 ms at a time
  245.     jsr     wait    ;[48]
  246.     dec    kwrk01    ;[1.7]
  247.     bne    tlinib    ;[1.7]
  248.     lda    #$8d    ;[48] off hook
  249.     ldx    kersli    ;[48] you know what this is by now
  250.     sta    kr0pcc,x    ;[48] tell
  251. ;[1.4]    lda    #39    ;[48] now for a 39 ms delay
  252. ;[1.7]    lda    #123    ;[1.4] now for a 39 ms delay
  253.     lda    #39    ;[1.7] now for a 39 ms delay
  254.     sta    kwrk01    ;[1.7]
  255. tlinif    lda    timect    ;[1.7] 1 ms at a time
  256.     jsr    wait    ;[48]
  257.     dec    kwrk01    ;[1.7]
  258.     bne    tlinif    ;[1.7]
  259.     dec    temp    ;[48] all the pulses ?
  260.     bne    tlini4    ;[48] no, keep on
  261. ;[1.4]    lda    #3    ;[48] wait for 600 ms
  262.     lda    #6    ;[1.4] wait for 600 ms
  263.     sta    temp    ;[48]
  264. ;[1.4]tlini6:    lda    #200    ;[48]
  265. ;[1.7]tlini6:    lda    #198    ;[48] 100ms
  266. tlini6:    lda    #100    ;[1.7] 100ms
  267.     sta    kwrk01    ;[1.7]
  268. tlinig    lda    timect    ;[1.7] 1 ms at a tiime
  269.     jsr    wait    ;[48]
  270.     dec    kwrk01    ;[1.7]
  271.     bne    tlinig    ;[1.7]
  272.     dec    temp    ;[48]
  273.     bne    tlini6    ;[48]
  274.     jmp    tlini5    ;[48] get the next number
  275. notnum:    cmp    #cr    ;[48] is this the end
  276.     bne    tlini5    ;[48] nope try for a number
  277.     jsr    prcrlf    ;[48] make the screen look nice
  278.     ldx    #dialm2\    ;[48] now for the waiting msg
  279.     ldy    #dialm2^    ;[48]
  280.     jsr    prstr    ;[48] print it
  281.     ldx    kersli    ;[48] the slot again
  282. tlini8:    bit    kbd    ;[48] do we have a ch from the keyboard
  283.     bpl    tlini7    ;[48] no, try for carrier
  284.     jsr    rdkey    ; lets do this right
  285.     lda    #0    ;[48]
  286.     ldx    kersli    ;[48] the slot again
  287.     sta    kr0pcc,x    ;[48] hang up and give up
  288.     lda    #0    ; give a false return (0)
  289.     rts        ;[48]give a false return (0)
  290. tlini7:    lda    kr0pch,x    ;[48] the data
  291.     lda    kr0pst,x    ;[48] and now the status
  292.     and    #4    ;[48] carrier?
  293.     bne    tlini8    ;[48] not yet try again
  294.     lda    #$8f    ;[48] originate mode+ap300+apoffh
  295.     sta    kr0pcc,x    ;[48] tell
  296.     jsr    prcrlf    ;[48]
  297.     ldx    #dialm3\    ;[48] tell we got carrier
  298.     ldy    #dialm3^    ;[48]
  299.     jsr    prstr    ;[48]
  300.     jsr    prcrlf    ;[48]
  301.     lda    #0    ;start the buffer at 0
  302.     sta    pinptr    
  303.     sta    inptr    
  304.     sta    poutpt    ;[59]    "
  305.     sta    outptr    ;[59]    "
  306.     lda    #1    ; give a true return (non 0)
  307.     rts        ;[48] finally
  308.  
  309. tl2cp:
  310.     ldx    kersli        ;[12] Offset into I/O locations
  311. tl0cp1:    lda    kr0pst,x    ;[12] Try for a character
  312.     and    #$01        ;[12] Check for receive register full
  313.     beq    tl0cp7
  314.     lda    kr0pch,x    ; get ch
  315.     ldy    pinptr        ; get place to store
  316.     sta    inbuf,y        ; in buf
  317.     inc    pinptr        ; ready for next
  318.     bit    flowfg        ;[59] how about flow control
  319.     bpl    tl0cp7        ;[59] no
  320.     lda    inbuf,y        ;[59] get input ch
  321.     and    #$7f        ;[59] drop parity etc
  322. ;    bvc    tl2cp4        ;[59] yes,how about ^S received?, no
  323.     cmp    #ctrlq        ;[59] is this continue(start up outputing)
  324.     bne    tl2cp4        ;[59] no, check for ^S
  325.     lda    flowfg        ;[59] tattle about the continue
  326.     and    #$bf        ;[59]
  327.     sta    flowfg        ;[59]
  328.     dec    pinptr        ;[59] forget about this character
  329. tl2cp2    ldy    outptr        ;[59] see if any to output
  330.     cpy    poutpt        ;[59] well?
  331.     beq    tl0cp7        ;[59] no more we have put all
  332. tl2cp3    lda    kr0pst,x    ;[59] check status for output
  333. ;[1.6]    and    #$10        ;[59] ready?
  334.     and    #2        ;[1.6] ready?
  335.     beq    tl2cp3        ;[59] no, spin
  336.     lda    outbuf,y    ;[59] output ch
  337.     sta    kr0pch,x    ;[59] bye
  338.     inc    outptr        ;[59] ready for next
  339.     jmp    tl2cp2        ;[59] 
  340. tl2cp4    cmp    #ctrls        ;[59] is this stop?
  341.     bne    tl0cp7        ;[59] no
  342.     lda    #$40        ;[59] yes, tattle
  343.     ora    flowfg        ;[59]
  344.     sta    flowfg        ;[59] now everyone knows
  345.     dec    pinptr        ;[59] forget about the ^S character
  346. tl0cp7:
  347.     lda    pinptr
  348.     cmp    inptr
  349.                 ;[12] No character, return false(zero)
  350.                 ;[12] Successful return, return true(non 0)
  351.     rts            ;[12]        ...
  352.  
  353. tl2gpc:
  354.     ldx    inptr        ;get where the ch is
  355.     lda    inbuf,x        ;get ch
  356.     inc    inptr
  357. tl0rtc:    rts            ;[12]    and return
  358.  
  359. tl2ppc:
  360.     pha            ;[12] Hold the byte to send
  361.     ldx    kersli        ;[12] Get I/O location offset
  362. tl0pp1:    lda    kr0pst,x    ;[12] Get the status byte
  363.     and    #$02        ;[12] Isolate the flag we want (TRE)
  364.     beq    tl0pp2        ;[12] Transmit register is NOT empty, try again
  365.     bit    flowfg        ;[59] flow control?
  366.     bpl    tl2pp0        ;[59] no
  367.     bvc    tl2pp0        ;[59] should we stop outputing?,no
  368.     ldy    poutpt        ;[59] yes, save this ch in buffer
  369.     pla            ;[59]
  370.     sta    outbuf,y    ;[59]
  371.     inc    poutpt        ;[59] tell how many
  372. ;[1.6]    rts            ;[59] thats all
  373.     jmp    tl0cp1        ;[1.6] check for input and return
  374. tl2pp0                ;[59]
  375.     pla            ;[12] Fetch the data byte off the stack
  376.     sta    kr0pch,x    ;[12] Stuff it at the proper loc to send it
  377. ;[1.6]    rts            ;[59] thats all
  378.     jmp    tl0cp1        ;[1.6] check for input and return
  379.  
  380. tl0pp2:    jsr    tl0cp1        ;go check for an input ch
  381.     jmp    tl0pp1        ;try output again
  382.  
  383. tl2exi:
  384.     lda    #0    ;tell we did this
  385.     ldx    kersli    ;[47] get slot number
  386.     sta    kr0pcc,x    ;shut it down
  387. exit9:    rts
  388.  
  389. tl2cmd:            ;find out what command
  390.     beq    tl0drp    ;its drop line 
  391.     cmp    #$0c
  392.     beq    break    ;its a break command
  393.     cmp    #$0b
  394.     beq    tl2rts     ;its a set baud command and we cant
  395.     cmp    #hctrlq
  396.     beq    tl2sac    ;its a xon command
  397.     cmp    #hctrls
  398.     beq    tl2sac    ;its a xoff command
  399. tl2fls:    lda    #0    ;unknown command
  400. tl2rts:    rts        ;que passo ? return false(0)
  401. tl2sac:    ldx    flowfg    ;do we have flow control
  402.     bpl    tl2fls    ;no return false
  403.     and    #$7f    ;drop high bit
  404.     jsr    telspa    ;set parity
  405.     jsr    tl2ppc    ;output the ch
  406.     lda    #1    ;return a true
  407.     rts
  408. tl0drp:
  409.     ldx    kersli    ;[47] get slot number
  410.     sta    kr0pcc,x    ;shut it down
  411.     lda    #1    ;[54] true return
  412.     rts
  413. break:
  414.     ldy    kersli        ;[41] Get slot index,form = $n0
  415.     ldx     ksli        ; and $0n where n = slot
  416.     lda    dch.cr,x    ;[41] Get saved Control Register
  417.     ora    #$60        ;[41] Set appropriate flags for break
  418.     sta    kr0pcr,y    ;[41] Start break signal
  419. ;[1.4]    lda    #233        ;[41] Wait for 233 ms.
  420. ;[1.4]    jsr    wait        ;[41] Do it, say goodby to x
  421. ;[1.7]    lda    #220        ;[1.4] Wait for 125 ms.
  422.     lda    #233        ;[1.7] Wait for 233 ms.
  423.     sta    kwrk01        ;[1.7]
  424. break3    lda    timect        ;[1.7] 1 ms at a time
  425.     jsr    wait        ;[1.4]
  426.     dec    kwrk01        ;[1.7]
  427.     bne    break3        ;[1.7]
  428. ;[1.7]    lda    #206        ;[1.4] Wait for 108 ms a total of 233ms.
  429. ;[1.7]    jsr    wait        ;[1.4]
  430. ;[1.7]    ldx    ksli        ; restore x
  431.     lda    dch.cr,x    ;[41] Get saved Control reg
  432.     and    #$9f        ;[41] Reset flags
  433. ;[1.7]    ldy    kersli        ;[41] Get slot index
  434.     sta    kr0pcr,y    ;[41] Stop break signal
  435.     rts            ;[41]  and return
  436. inbuf    .blkb    256    ;input buffer 
  437. outbuf    .blkb    256        ;[59] output  "
  438. endcom            ;[1.5]
  439.