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

  1. .SBTTL    65816 version - Ted Medin & Mark Johnson
  2.  
  3. ;    Version 1.0
  4.  
  5. ;    Based on the KERMIT Protocol.
  6.  
  7. ;    $Header: appgs.m65,v 1.7 90/10/15 14:21:04 medin Locked $
  8. .SBTTL    Define start address for assembly
  9.  
  10.        .=$1003            ; Start assembly at hex 1003
  11.  
  12. debug    =    1        ;[1.4] debug flag - when 0 will not add debug code
  13.  
  14. .SBTTL    Revision History
  15.  
  16. ;
  17. ; Edit #    Description
  18. ; ------    -----------
  19. ;
  20.  
  21. ; $Log:    appgs.m65,v $
  22. Revision 1.7  90/10/15  14:21:04  medin
  23. new org for 3.87 of $7f00
  24. version 1.6
  25.  
  26. ;Revision 1.6  89/11/06  11:42:28  medin
  27. ; Use xon/xoff or dtr but not both
  28.  
  29. ;Revision 1.5  89/01/30  11:39:24  medin
  30. ; Version 1.4 add drop dtr and correct some debug problems.
  31.  
  32. ;Revision 1.4  88/01/15  08:43:21  medin
  33. ;New origin for 3.81
  34.  
  35.  
  36.  
  37. ; DONT FORGET TO UPDATE THE VERSION
  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.3] end of this routine
  57. timect    .blkb    1    ;[1.4] 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.2]wait:    .blkb    3    ; wait routine-a reg contains milliseconds
  75. wait:    .blkb    3    ; wait routine-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.     .=$7f00    ; place to start com card assembly
  83. start    =    .        ;need a label at begining
  84. true    =    1        ; true is non zero
  85. false    =    0        ; but not false
  86. irqsva    =    $45    ;place dos saves a reg
  87. hctrlq    =    $91    ;^Q with high bit on
  88. hctrls    =    $93    ;^S "
  89. cr    =    $d    ;^M carrage rtn
  90. ctrlq    =    $11    ;[59] ^Q
  91. ctrls    =    $13    ;[59] ^S
  92. dirq    =    $3fe    ; interupt address
  93. sscstp    =    $5f8    ; +slot,bit 7 on turns off commands to ssc
  94. comnd    =    1    ; command to start with
  95. prntax    =    $f941    ; print hex bytes in a & x
  96. prbyte    =    $fdda    ; print hex byte in a
  97. herld    nasc    <//GS SERIAL PORT V1.6> 1    ;[1.1]tell who we are
  98. bad    nasc    <*****ERROR***** COM ROUTINES ASSEMBLED TOO LOW IN MEMORY> 1
  99. statms    nasc    <<- STATUS ERROR ON COM CALL FROM - > 1
  100. temp    .byte        ;[1.1] index to init array
  101. binita    .byte    comnd,'F,' ,'D        ;[1.1] disable keyboard
  102.     .byte    comnd,'0,'D        ;[1.1] 8 data bits 1 stop bit
  103.     .byte    comnd,'0,'P        ;[1.1] no parity
  104.     .byte    comnd,'B,'E        ;[1.1] enable buffering
  105.     .byte    comnd,'C,'D        ;[1.1] disable line feed after cr
  106. ;[1.5]    .byte    comnd,'X,'D        ;[1.1] disable xon/xoff
  107.     .byte    comnd,'L,'D        ;[1.1] disable auto line feed
  108.     .byte    comnd,'E,'D        ;[1.1] disable echo to screen
  109.     .byte    comnd,'M,'D        ;[1.1] disable mask line feed
  110.     .byte    comnd,'A,'D        ;[1.1] disable basic tabs
  111.     .byte    comnd,'Z,0        ;[1.1] the last in the list
  112. bbrka    .byte    comnd,'T        ;[1.1] go to terminal mode
  113.     .byte    comnd,'S        ;[1.1] now for the break
  114.     .byte    comnd,'Q        ;[1.1] now exit terminal mode
  115.     .byte    comnd,'Z,0        ;[1.1] last of the list
  116. saveac    .byte        ; next input ch
  117. gmb    .byte    3    ; # parameters
  118. gmbc    .byte    0    ; command 0=read 1=write $14=flush-in $15=flush-out
  119. gmbr    .word        ; result
  120. gmbd    .byte        ; 7-0 bit image
  121.     .byte        ; 15-8
  122. gmbz    .byte        ; 23-16
  123.     .byte        ; 31-24
  124.  
  125. ;
  126. ;    Apple //gs  serial interface support
  127. ;
  128.  
  129. prerst    cpx    #0        ; first see if there is an error
  130.     beq    prersa        ; no
  131. ;[1.4]    jsr    prbyte        ;
  132. preree                ;[1.4]
  133.     jsr    prntax        ;[1.4]
  134.     ldx    #statms\    ; tell what we got
  135.     ldy    #statms^
  136.     jsr    prstr    
  137.     pla            ; get low byte of call address
  138.     tax
  139.     pla            ; and the high byte
  140.     tay
  141.     pha
  142.     txa
  143.     pha            ; now it back correct
  144.     tya            ; put the high byte in a
  145.     jsr    prntax        ; and print them
  146.     jmp    prcrlf        ; on a line by itself, & let prcrlf do the rts
  147. prersa    rts
  148. alowcm
  149.     sei            ; lock out interupts
  150.     lda    #3        ; 3 for param count
  151.     sta    gmb
  152.     lda    #0
  153.     sta    gmbc        ; make the command get
  154.     jsr    dmb        ; send the request
  155.     lda    gmbz        ; get the command ignore byte
  156.     and    #$7f        ; make the bit 0
  157.     sta    gmbz        ; and set it in the list
  158.     lda    gmbd        ; now turn off dtr/dsr
  159. ;[1.4]    and    #$fb
  160.     ora    #4        ;[1.4] turn on dtr/dsr handshake
  161.     and    #$df        ;[1.5] turn off xon/xoff handshake
  162.     bit    flowfg        ;[1.5] see if we should xon/xoff
  163.     bpl    alow3        ;[1.5] no
  164.     ora    #$20        ;[1.5] tell firmware abt xon/xoff
  165.     and    #$fb        ;[1.5] turn off dtr
  166. alow3                ;[1.5]
  167.     sta    gmbd
  168.     lda    #1        ; make the command set
  169.     sta    gmbc
  170.     jsr    dmb
  171.     cli            ; now allow interupts
  172.     rts
  173. ;[1.1]flush
  174. ;[1.1]    sei            ; lock out interupts
  175. ;[1.1]    lda    #2        ; 2 for param count
  176. ;[1.1]    sta    gmb
  177. ;[1.1]    lda    #$14        ; flush input queue
  178. ;[1.1]    sta    gmbc
  179. ;[1.1]    jsr    dmb        ; do it
  180. ;[1.1]    lda    #$15        ; flush output queue
  181. ;[1.1]    sta    gmbc
  182. ;[1.1]    jsr    dmb    
  183. ;[1.1]    cli            ; now allow interupts
  184. ;[1.1]    rts            ; thats all folks
  185. dmb    
  186.     .byte    $8b        ; should be PHB (push bank on stack)
  187.     ply            ; and put it in y
  188.     ldx    #gmb^        ; middle of the 3 bytes of address
  189.     lda    #gmb\        ; and low
  190. cnsta5    jsr    $c000        ; call the extended interface
  191.     .ifne    debug    ;[1.4] conditional assembly
  192. ; till apple fixes the bug    bcc    dmbr        ;[1.4] was it good, yes
  193.     lda    gmbr+1        ;[1.4] see if we have an error
  194.     ora    gmbr        ;[1.4]
  195.     beq    dmbr        ;[1.4] nope
  196.     lda    gmbr+1        ;[1.4] should be something here
  197.     ldx    gmbr        ;[1.4] ***** debug hope this is the right byte
  198.     jmp    preree        ;[1.4] tattle and let it do the rts
  199.     .endc        ;[1.4]
  200. dmbr    rts
  201.  
  202. tl2int:
  203.     lda    #start^
  204.     cmp    endker+1    ;are we loaded above main
  205.     beq    dontno        ;cant tell yet
  206.     bcc    trble        ;yes we are in trouble
  207.     bcs    setnm        ;ok 
  208. dontno    lda    #start\        ;well lets check 16 bits
  209.     cmp    endker
  210.     beq    setnm        ;whee just exactly right
  211.     bcs    setnm        ;ok
  212. trble    ldx    #bad\        ;got to tell someone
  213.     ldy    #bad^
  214.     jsr    prstr        ;print the message
  215.     jsr    prcrlf        ;and terminate it properly
  216. setnm:
  217.     lda    kerins
  218.     bne    prersa        ; already initialized
  219.     lda    kersli        ; first generate the $cn
  220.     lsr    a        ;
  221.     lsr    a        ;
  222.     lsr    a        ;
  223.     lsr    a        ;
  224.     ora    #$c0        ; finally $cn
  225.     sta    cnstat+2    ; this sets up the high byte to $cn
  226.     sta    cnsta1+2    ;
  227.     sta    cnsta2+2    ;
  228.     sta    cnsta3+2    ;
  229.     sta    cnsta4+2    ;
  230.     sta    tl2cp1+2    ;
  231.     sta    tl2gc1+2    ;
  232.     sta    tl2pc1+2    ;
  233.     sta    tl2pc2+2    ;
  234.     sta    cnsta5+2
  235.     sta    cnsta0+2
  236. cnsta0    lda    $c012        ; the extended offset
  237.     sta    cnsta5+1    ; now the jsr should all be correct
  238.     jsr    alowcm        ; allow commands
  239. cnstat    lda    $c00d        ; get the init offset from $cn0d
  240.     sta    cnsta1+1    ; now set the low byte address
  241.     ldy    kersli        ; y=$n0
  242.     ldx    cnsta1+2    ; x=$cn
  243. cnsta1    jsr    $c000        ; init
  244.     jsr    prerst        ; check for errors
  245. cnsta2    lda    $c00e        ; get the read offset
  246.     sta    tl2gc1+1    ; and set up the get ch call
  247. cnsta3    lda    $c00f        ; get the write offset
  248.     sta    tl2pc1+1    ; and set up the put ch call
  249. cnsta4    lda    $c010        ; get the status offset
  250.     sta    tl2cp1+1    ; and set up the read status call
  251.     sta    tl2pc2+1    ; and set up the write status call
  252. ;[1.1]    lda    #comnd
  253. ;[1.1]    jsr    tl2ppf
  254. ;[1.1]    lda    #'F        ;  no keyboard
  255. ;[1.1]    jsr    tl2ppf
  256. ;[1.1]    lda    #' 
  257. ;[1.1]    jsr    tl2ppf
  258. ;[1.1]    lda    #'D
  259. ;[1.1]    jsr    finis
  260.     lda    #comnd        ; start of the command string
  261.     jsr    tl2ppf        ; send it
  262.     lda    sscdbd        ; first the baud
  263.     cmp    #9        ; hex and dec 
  264.     bcc    tl2inz
  265.     pha            ; going to need this
  266.     lda    #'1        ; power of 10 sigh
  267.     jsr    tl2ppf
  268.     pla
  269.     sec            ; now take away the 10
  270.     sbc    #10
  271. tl2inz    clc            ; make it ascii
  272.     adc    #$30        ; that should do it
  273.     jsr    tl2ppf
  274.     lda    #'B        ; that says baud
  275. ;[1.1]    jsr    finis
  276.     jsr    tl2ppf        ;[1.1] dont send cr
  277. ;[1.1]    lda    #comnd
  278. ;[1.1]    jsr    tl2ppf
  279. ;[1.1]    lda    #'0        ; 8 data bits 1 stop bit
  280. ;[1.1]    jsr    tl2ppf
  281. ;[1.1]    lda    #'D
  282. ;[1.1]    jsr    finis
  283. ;[1.1]    lda    #comnd
  284. ;[1.1]    jsr    tl2ppf
  285. ;[1.1]    lda    #'0        ; how about no parity
  286. ;[1.1]    jsr    tl2ppf
  287. ;[1.1]    lda    #'P
  288. ;[1.1]    jsr    finis
  289. ;[1.1]    lda    #comnd
  290. ;[1.1]    jsr    tl2ppf
  291. ;[1.1]    lda    #'B        ; enable buffering
  292. ;[1.1]    jsr    tl2ppf
  293. ;[1.1]    lda    #'E
  294. ;[1.1]    jsr    finis
  295. ;[1.1]    lda    #comnd
  296. ;[1.1]    jsr    tl2ppf
  297. ;[1.1]    lda    #'C        ; disable line formating
  298. ;[1.1]    jsr    tl2ppf
  299. ;[1.1]    lda    #'D
  300. ;[1.1]    jsr    finis
  301. ;[1.1]    lda    #comnd
  302. ;[1.1]    jsr    tl2ppf
  303. ;[1.1]    lda    #'X        ; disable xon xoff
  304. ;[1.1]    jsr    tl2ppf
  305. ;[1.1]    lda    #'D
  306. ;[1.1]    jsr    finis
  307. ;[1.1]    lda    #comnd
  308. ;[1.1]    jsr    tl2ppf
  309. ;[1.1]    lda    #'L        ; disable auto line feed
  310. ;[1.1]    jsr    tl2ppf
  311. ;[1.1]    lda    #'D
  312. ;[1.1]    jsr    finis
  313. ;[1.1]    lda    #comnd
  314. ;[1.1]    jsr    tl2ppf
  315. ;[1.1]    lda    #'E        ; disable echo to screen
  316. ;[1.1]    jsr    tl2ppf
  317. ;[1.1]    lda    #'D
  318. ;[1.1]    jsr    finis
  319. ;[1.1]    lda    #comnd
  320. ;[1.1]    jsr    tl2ppf
  321. ;[1.1]    lda    #'M        ; disable mask line feed
  322. ;[1.1]    jsr    tl2ppf
  323. ;[1.1]    lda    #'D
  324. ;[1.1]    jsr    finis
  325. ;[1.1]    lda    #comnd
  326. ;[1.1]    jsr    tl2ppf
  327. ;[1.1]    lda    #'A        ; disable basic tabs
  328. ;[1.1]    jsr    tl2ppf
  329. ;[1.1]    lda    #'D
  330. ;[1.1]    jsr    finis
  331. ;[1.1]    jsr    flush        ; now that baud is set flush previous
  332. ;[1.1]    lda    #comnd
  333. ;[1.1]    jsr    tl2ppf
  334. ;[1.1]    lda    #'Z        ; no more commands, accept all chs
  335. ;[1.1]    jsr    finis
  336.     stz    temp        ;[1.1] starting index
  337. tl2iny    ldx    temp        ;[1.1]
  338.     lda    binita,x    ;[1.1] get initialization ch
  339.     beq    tl2inx        ;[1.1] are we thru? yes
  340.     jsr    tl2ppf        ;[1.1] no send the ch
  341.     inc    temp        ;[1.1] ready for next
  342.     jmp    tl2iny        ;[1.1]
  343. tl2inx                ;[1.1] thats all
  344.     lda    #true
  345.     rts            ; say its ok
  346. ;[1.1]finis    jsr    tl2ppf        ; send a out
  347. ;[1.1]    lda    #cr        ; and terminate the command
  348. ;[1.1]    jmp    tl2ppf        ; let tl2ppc do the rtn also
  349.  
  350. tl2cp:    ldx    tl2cp1+2    ; x needs $cn
  351.     ldy    kersli        ; y needs $n0
  352.     lda    #1        ; input ready?
  353. tl2cp1    jsr    $c000        ; status call
  354.     bcs    tl2cp5        ; *********** debug
  355.     jsr    prerst        ; *********** debug
  356. tl2cp2    lda    #false        ; ready for no
  357.     rts
  358. tl2cp5    ldx    tl2gc1+2    ; x needs $cn
  359.     ldy    kersli        ; y needs $n0
  360. tl2gc1    jsr    $c000        ; get a ch, tl2cp said we had one
  361.     jsr    prerst        ; check for error, let prerst do the rts
  362.     sta    saveac        ; save the a for tl2gpc
  363.     ldy    flowfg    ;[57] are we flow controll
  364.     bpl    tl2cp6    ;[57] no dont worry about stopping output
  365.     and    #$7f    ;[59] ignore parity
  366.     cmp    #ctrlq    ;[59] do we have a continue
  367.     bne    tl2in2    ;[59] no
  368.     lda    #$bf    ;[59] yes, now turn on flow
  369.     and    flowfg    ;[59]
  370.     sta     flowfg    ;[59]
  371.     jmp    tl2cp2    ;[59] and carry on
  372. tl2in2    cmp    #ctrls    ;[59] do we have a stop?
  373.     bne    tl2cp6    ;[59]
  374.     lda    #$40    ;[59] yes tell all
  375.     ora    flowfg    ;[59] would you believe the remote
  376.     sta    flowfg    ;[59] has asked us to stop!
  377.     jmp    tl2cp2    ; return false
  378. tl2cp6    lda    #true        ; hooray we have one ready
  379. tl2cp3    rts            ;return with false(0) or true(non 0)
  380.  
  381. tl2gpc:    lda    saveac        
  382.     rts            
  383. tl2ppc:    pha            ; Hold the byte to send
  384. tl2pc0    bit    flowfg        ; is output on hold?
  385.     bvc    tl2pcl        ; no
  386.     jsr    tl2cp        ; yes wait for ^q
  387.     jmp    tl2pc0        ; throw away everything else
  388. tl2pcl    ldx    tl2pc2+2    ; x needs $cn
  389.     ldy    kersli        ; y needs $n0
  390.     lda    #0        ; ask about outputing a ch
  391. tl2pc2    jsr    $c000        ; status call
  392.     bcs    tl2pc7        ; *********** debug
  393.     jsr    prerst        ; *********** debug
  394.     jmp    tl2pcl        ; ready?,no try again
  395. tl2pc7    pla            ; get the ch back
  396. tl2ppf    ldx    tl2pc1+2    ; $cn again
  397.     ldy    kersli        ; $n0 again
  398. tl2pc1    jsr    $c000        ; put the ch
  399.     jmp    prerst        ; let prerst do the rts
  400.  
  401. tl2exi:
  402.     lda    #0    ;tell we did this
  403.     sta    kerins        ;just in case init gets called
  404.     lda    #true        ; say its ok
  405. exit9:    rts
  406.  
  407. tl2drp                ;[1.4]
  408.     sei            ;[1.4] lock out interupts
  409.     lda    #3        ;[1.4] 3 for param count
  410.     sta    gmb        ;[1.4]
  411.     lda    #$a        ;[1.4] get dtr stuff
  412.     sta    gmbc        ;[1.4] make the command get
  413.     jsr    dmb        ;[1.4] send the request
  414.     lda    gmbd        ;[1.4] now turn off dtr/dsr
  415.     ora    #$80        ;[1.4]
  416.     sta    gmbd        ;[1.4]
  417.     lda    #$b        ;[1.4] set dtr
  418.     sta    gmbc        ;[1.4]
  419.     jsr    dmb        ;[1.4]
  420.     cli            ;[1.4] now allow interupts
  421.     lda    #true        ;[1.4] hope hope
  422.     rts            ;[1.4]
  423. tl2cmd:            ;find out what command
  424. ;[1.4]    beq    tl2rts    ;its drop line and we cant
  425.     beq    tl2drp    ;[1.4] its drop line and we shall see
  426.     cmp    #$0c
  427.     beq    break    ;its a break command
  428.     cmp    #$0b
  429.     beq    baud       ;its a set baud command
  430.     cmp    #hctrlq
  431.     beq    tl2sac    ;its a xon command
  432.     cmp    #hctrls
  433.     beq    tl2sac    ;its a xoff command
  434. tl2fls:    lda    #false    ;unknown command
  435. tl2rts:    rts        ;que passo ? return false(0)
  436. tl2sac:
  437.     and    #$7f    ;drop high bit and send the ch
  438.     jsr    telspa    ;set parity
  439.     jsr    tl2ppc    ;output the ch
  440.     lda    #1    ;set true return
  441.     rts
  442. baud:    lda    #0    ; force an initialization
  443.     sta    kerins    ; that will reset baud
  444.     lda    #true        ;
  445.     rts        ;return 
  446. break:
  447.     jsr    alowcm        ; allow commands again
  448. ;[1.1]    lda    #comnd        ; start of command string
  449. ;[1.1]    jsr    tl2ppf
  450. ;[1.1]    lda    #'T        ; terminal mode
  451. ;[1.1]    jsr    finis
  452. ;[1.1]    lda    #comnd        ; start of command string
  453. ;[1.1]    jsr    tl2ppf
  454. ;[1.1]    lda    #'S        ; break
  455. ;[1.1]    jsr    finis
  456. ;[1.1]    lda    #comnd        ; start of command string
  457. ;[1.1]    jsr    tl2ppf
  458. ;[1.1]    lda    #'Q        ; exit terminal mode
  459. ;[1.1]    jsr    finis
  460. ;[1.1]    lda    #comnd        ; start of command string
  461. ;[1.1]    jsr    tl2ppf
  462. ;[1.1]    lda    #'Z        ; now shut off looking
  463. ;[1.1]    jsr    finis
  464.     stz    temp        ;[1.1]
  465. break2    ldx    temp        ;[1.1] index into break array
  466.     lda    bbrka,x        ;[1.1] next ch
  467.     beq    break5        ;[1.1] are we thru? yes
  468.     jsr    tl2ppf        ;[1.1] no send the ch to rom
  469.     inc    temp        ;[1.1] ready for next
  470.     jmp    break2        ;[1.1]
  471. break5                ;[1.1] thats all    
  472.     lda    #true        ; and tell we did it ok
  473.     rts
  474. endcom            ;[1.3]
  475.