home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pub / ucsdappleii / remdriver.text < prev    next >
Text File  |  2020-01-01  |  18KB  |  483 lines

  1. ;>>>>>>>>>>>>>>>>>>>>>>> REMDRIVER.TEXT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2. ;
  3. ; For an introduction see the file REMDR.DOC.TEXT
  4. ;
  5. ;----------------------------------------------------------------------
  6. ;
  7. ; Serial card driver for Kermit-UCSD  RUG/PT V1.0
  8. ;
  9. ;----------------------------------------------------------------------
  10. ;
  11. ; LABEL DEFINITIONS
  12. ;
  13. SLOT      .EQU 20          ; various slot 2 labels
  14. SLT2MSB   .EQU 0C2
  15. SLOT2ADR  .EQU 0C200
  16. ;
  17.                            ; addresses of the offset bytes to calculate :
  18. FSTATUS   .EQU SLOT2ADR+10 ; entry point for a serial firmware card status
  19. FREAD     .EQU SLOT2ADR+0E ;   "     "    "  "   "       "      "   read
  20. ;
  21. DUMMY     .EQU 0FFFF       ; dummy address. will be filled in at cold boot.
  22. ;
  23. AP2COMM   .EQU 0C08E+SLOT  ; IBS AP2 serial card (6551 acia) command register.
  24. AP2STREG  .EQU 0C08D+SLOT  ;  "   "    "     "     "    "    status     "
  25. AP2IOREG  .EQU 0C08C+SLOT  ;  "   "    "     "     "    "    I/O        "
  26. ;
  27. COMSTREG  .EQU 0C08E+SLOT  ; Apple Com Card (6850 acia) status register.
  28. COMIOREG  .EQU 0C08F+SLOT  ;   "    "    "    "    "    I/O      "
  29. ;
  30. HAYSTREG  .EQU 0C086+SLOT  ; Hayes Micromodem (6850 acia) status register.
  31. HAYIOREG  .EQU 0C087+SLOT  ;   "       "        "    "    I/O      "
  32.                            ; (Com Card registers may also work.)
  33. SPEAKER   .EQU 0C030
  34. SPCHAR    .EQU 0BF1C       ; system location for special keyboard character
  35.                            ; checking.
  36. SLT2TYP   .EQU 0BF27+2     ; system location with serial card type
  37.                            ; 0 = no card.
  38.                            ; 1 = not recognized by system.
  39.                            ; 3 = Apple Com card
  40.                            ;     California 7710 ASI1 card
  41.                            ;     Hayes Micromodem card?
  42.                            ; 4 = serial card ( IBS AP2 )
  43.                            ; 6 = Firmware card ( Super Serial Card )
  44. ;
  45. NUMSERID  .EQU 02-1        ; number(-1) of serial cards this driver checks.
  46. ;
  47. ACJVAFOLD .EQU 0E2         ; pointer to attached copy of BIOS jump vector.
  48. JVAFOLD   .EQU 0EE         ; pointer to BIOS jump vector.
  49. ;
  50. CONCK     .EQU DUMMY       ; address of BIOS keyboard check routine.
  51. RINIT     .EQU DUMMY       ; address of BIOS Remote Init routine.
  52. INPORTSTAT.EQU DUMMY       ; address of this driver's Remote status routine.
  53. ;
  54. STATREC   .EQU 00          ; temp. zero page pointer to status record.
  55. ;
  56. ;----------------------------------------------------------------------
  57. ;
  58.           .PROC REMDRIVER
  59. ;
  60. ;----------------------------------------------------------------------
  61.           JMP CONCKHDL     ; The first 3 instructions of CONCK will
  62.                            ; be patched by SYSTEM.ATTACH to point here.
  63. ;----------------------------------------------------------------------
  64. ;
  65. ; Calls to REMREAD, REMSTATUS and REMINIT will be handled here :
  66. ;
  67.           TXA              ; X=0 : Remote Read request.
  68.           BEQ REMREAD
  69.           CMP #004         ; X=4 : Remote Status request.
  70.           BEQ REMSTATUS
  71.           CMP #002
  72.           BNE ERROR        ; X=2 : Remote Init request.
  73.           ;----------------
  74.           ;
  75.           ; Remote Init routine :
  76.           ;
  77.           LDX REMRPTR      ; Empty remote input buffer.
  78.           STX REMWPTR      ; ( read-pointer = write-pointer )
  79.           LDX #000         ; zero buffer counter.
  80.           STX BUFCOUNT
  81. PATCH3    JMP ONCERINIT    ; if called for the first time ( cold boot ) then
  82.                            ; do the cold boot init routine. This routine
  83.                            ; patches the JMP instruction to NOP,NOP,NOP so
  84.                            ; later init calls (warm boot) will only empty the
  85.                            ; remin buffer.
  86.           RTS
  87.           ;----------------
  88. ERROR     LDX #003         ; for any other request return error code.
  89.           RTS
  90. ;----------------------------------------------------------------------
  91. ;
  92. ; Remote read routine ( reads only the remin buffer ).
  93. ;
  94. REMREAD   JSR CONCKHDL     ; check keyboard and remote input port.
  95.           LDX REMRPTR      ; if remin buffer is empty : keep checking remote
  96.           CPX REMWPTR      ; input port until something arrives.
  97.           BEQ REMREAD
  98.           INX              ; read char from remin buffer, bump read-pointer
  99.           STX REMRPTR      ; decrease buffer count and put char in accu.
  100.           DEC BUFCOUNT
  101.           LDA REMBUF,X
  102. READY     LDX #000         ; no error.
  103.           RTS
  104. ;----------------------------------------------------------------------
  105. ;
  106. ; Remote status routine ( implements UNITSTATUS. see KERM.DOC2.TEXT )
  107. ;
  108. REMSTATUS JSR CONCKHDL     ; check keyboard and remote input port.
  109.           PLA              ; save return address.
  110.           STA RETURN
  111.           PLA
  112.           STA RETURN+1
  113.           ;------------
  114.           PLA              ; save address of statusrecord on zero page.
  115.           STA STATREC
  116.           PLA
  117.           STA STATREC+1
  118.           ;------------
  119.           PLA              ; save controlword.
  120.           STA CONTROLW
  121.           PLA
  122.           STA CONTROLW+1
  123.           ;------------
  124.           LDA RETURN+1     ; push return address back on stack.
  125.           PHA
  126.           LDA RETURN
  127.           PHA
  128.           ;----------------------------------
  129. REMINSTAT LDX #000         ; zero registers.
  130.           LDY #000
  131.           ;----------------
  132.           ;
  133.           ; Decipher Controlword.
  134.           ;
  135.           LDA CONTROLW     ; if bit 1 = 0 then the purpose is statusrequest.
  136.           AND #002         ; if bit 1 = 1 then the purpose is controlrequest.
  137.                            ; bit 0 (direction) is not checked.
  138.           BNE REMCNTROL
  139.           LDA CONTROLW+1   ; if bit 13 = 0 then a "normal" request.
  140.           AND #020
  141.           BNE PEEK         ; if bit 13 = 1 then a "special" request.
  142.           ;----------------
  143.           ;
  144.           ; Normal Status Request: load in statusrecord ( 2 bytes ) the number
  145.           ; of characters currently in the remin buffer.
  146.           ;
  147.           LDA BUFCOUNT
  148. LOAD      STA @STATREC,Y
  149.           LDA #00
  150.           INY
  151.           STA @STATREC,Y
  152.           RTS
  153.           ;---------------
  154.           ;
  155.           ; Special Status Request: statusrecord first to bytes contain an
  156.           ; address. Return in statusrecord last 2 bytes the value of the
  157.           ; requested location.
  158.           ;
  159. PEEK      LDA @STATREC,Y
  160.           STA ADR1+1
  161.           INY
  162.           LDA @STATREC,Y
  163.           STA ADR1+2
  164. ADR1      LDA DUMMY        ; DUMMY will be changed to the requested address.
  165.           INY
  166.           BNE LOAD         ; value returned is a Pascal Integer!
  167.           ;----------------
  168.           ;
  169.           ; Control Requests :
  170.           ;
  171. REMCNTROL LDA CONTROLW+1   ; if bit 13 = 0 then a normal controlrequest.
  172.           AND #020
  173.           BNE POKE
  174.           ;----------------
  175.           ; Normal Control Request
  176.           ;
  177.           ; first byte of statusrecord contains
  178.           ; 0..3 : store this byte in SPCHAR.
  179.           ; SPCHAR=0 : CONCK checks class 1 and class 2 special chars.
  180.           ; SPCHAR=1 :   "     "    only        class 2    "     "
  181.           ; SPCHAR=2 :   "     "    only        class 1    "     "
  182.           ; SPCHAR=3 :   "     "           no              "     "
  183.           ; ( see KERM.DOC2.TEXT )
  184.           ;
  185.           ; first byte of statusrecord contains
  186.           ; 4  :  7 bit characters in remin buffer.
  187.           ; 5  :  8 bit      "     "    "    "
  188.           ;
  189.           LDA @STATREC,Y
  190.           CMP #004
  191.           BCS BIT78
  192.           STA SPCHAR
  193.           RTS
  194.           ;-----------------
  195.           ;
  196.           ; Special Control Request : statusrecord first 2 bytes contain a
  197.           ; address. Statusrecord third byte contains the value the location
  198.           ; should contain.
  199.           ;
  200. POKE      LDA @STATREC,Y
  201.           STA ADR2+1
  202.           INY
  203.           LDA @STATREC,Y
  204.           STA ADR2+2
  205.           INY
  206.           LDA @STATREC,Y
  207. ADR2      STA DUMMY        ; DUMMY will be filled in at run time.
  208.           RTS
  209.           ;----------------
  210. BIT78     CMP #005         ; set the flag LOCALPAR for the remin input routine.
  211.           BEQ EIGHTBIT     ; default startup setting is seven bit remin chars.
  212.           LDA #000
  213.           BEQ SETLOCPAR
  214. EIGHTBIT  LDA #080
  215. SETLOCPAR STA LOCALPAR
  216.           RTS
  217. ;----------------------------------------------------------------------
  218. ;
  219. ; Calls to the system CONCK routine come here. A call to this
  220. ; driver's remin check routine is inserted so that every time the system
  221. ; does any I/O call both the keyboard and the remote input port will be checked.
  222. ;
  223. CONCKHDL  PHP           ; repeat first 6 instructions of CONCK.
  224.           PHA
  225.           TXA
  226.           PHA
  227.           TYA
  228.           PHA
  229.           JSR REMINCK   ; check the remote input port.
  230. PATCH2    JMP CONCK     ; enter CONCK at start+6 and return from there to
  231.                         ; system. The 2 bytes after the JMP will be filled
  232.                         ; in at first initialization of this driver.
  233. ;----------------------------------------------------------------------
  234. ;
  235. ; REMINCK  : checks remote input port. If it finds a char, it will put it
  236. ;            in the remin buffer.
  237. ;
  238. REMINCK   JSR INPORTST  ; checks remote inputport. Carry is set when a char
  239.                         ; is waiting. Returns with char in accu.
  240.                         ; The address INPORTST will be filled in at cold boot
  241.                         ; initialization time to point at the correct status
  242.                         ; routine.
  243.           BCC EMPTY
  244.           BIT LOCALPAR  ; depending on LOCALPAR : strip bit 8 of incomimg char.
  245.           BMI NOCHANGE
  246.           AND #07F
  247. NOCHANGE  LDX REMWPTR   ; bump writepointer.
  248.           INX
  249.           CPX REMRPTR   ; if writepointer = readpointer then buffer is full!
  250.           BNE BUFOK
  251.           ;----------
  252.           PHA           ; in case of buffer overflow :
  253.           TXA           ; give a high pitched bell sound.
  254.           PHA
  255. BELL      LDY #060
  256. BELL1     LDX #020
  257. BELL2     DEX
  258.           BNE BELL2
  259.           LDA SPEAKER
  260.           DEY
  261.           BNE BELL1
  262.           LDA #0FF      ; set buffer count to -1.
  263.           STA BUFCOUNT  ; buffer will thus be emptied.
  264.           PLA
  265.           TAX
  266.           PLA
  267.           ;------------
  268. BUFOK     STX REMWPTR   ; save new writepointer.
  269.           INC BUFCOUNT  ; bump buffer count and
  270.           STA REMBUF,X  ; store received char in buffer.
  271. EMPTY     RTS
  272. ;-----------------------------------------------------------------------
  273. ;
  274. ;   Remote status routines for different serial cards.
  275. ;   Only one of these is active after cold boot initialization.
  276. ;
  277. ;   The status routine returns with the received character (if any) in accu
  278. ;   and with the carry set if a character was received.
  279. ;
  280. ;-----------------------------------------------------------------------
  281. ;
  282. ;   Status routine for an IBS AP2 serial card with a 6551 acia.
  283. ;
  284. AP2STAT   LDA AP2COMM
  285.           ORA #008
  286.           STA AP2COMM
  287.           LDA AP2STREG
  288.           CLC
  289.           AND #028
  290.           EOR #008
  291.           BNE NOTHING1
  292.           SEC
  293.           LDA AP2IOREG
  294. NOTHING1  PHA
  295.           LDA AP2COMM
  296.           AND #0F3
  297.           STA AP2COMM
  298.           PLA
  299.           RTS
  300. ;----------------------------------------------------------------------
  301. ;
  302. ;   Status routine for Hayes Micromodem Card with a 6850 acia.
  303. ;   ( Identical to Apple Com Card. Can probably be replaced by Com Card routine
  304. ;     if Hayes card is also recognized by the Pascal system as an Apple Com
  305. ;     card. )
  306. ;
  307. HAYESTAT  LDA HAYSTREG
  308.           LSR A
  309.           BCC NOTHING2
  310.           LDA HAYIOREG
  311. NOTHING2  RTS
  312. ;-----------------------------------------------------------------------
  313. ;
  314. ;   Status routine for an Apple Communications Card or California 7710
  315. ;   ASI1 card , both with a 6850 acia.
  316. ;
  317. COMSTAT   LDA COMSTREG
  318.           LSR A
  319.           BCC NOTHING3
  320.           LDA COMIOREG
  321. NOTHING3  RTS
  322. ;-----------------------------------------------------------------------
  323. ;
  324. ;   Status routine for a "firmware" card like the Apple Super Serial Card.
  325. ;   Firmware cards have there own status and read routines in ROM.
  326. ;   The final addresses of the status and read routines will be calculated
  327. ;   at cold boot initialization and filled in directly here at PATCH4 and
  328. ;   PATCH5.
  329. ;
  330. FIRMSTAT  LDX #SLT2MSB   ; do the required initialization.
  331.           LDY #SLOT
  332.           STY 06F8
  333.           STA 0CFFF
  334.           LDA SLOT2ADR
  335.           LDA #001
  336. PATCH4    JSR FSTATUS
  337.           BCC NOTHING
  338.           LDX #SLT2MSB
  339. PATCH5    JSR FREAD      ; returns with char in accu.
  340.           SEC
  341. NOTHING   RTS
  342. ;------------------------
  343. ;
  344. ; If you have extended FINDSER to recognize more serial cards then insert
  345. ; here the code for the new serial card's status routine.
  346. ;
  347. ;----------------------------------------------------------------------------
  348. ;
  349. ;  Local variables
  350. ;
  351. RETURN    .WORD 00
  352. LOCALPAR  .BYTE 00
  353. REMRPTR   .BYTE 00
  354. REMWPTR   .BYTE 00
  355. CONTROLW  .WORD 00
  356. BUFCOUNT  .BYTE 00
  357. ;
  358. ;
  359. ;----------------------------------------------------------------------------
  360. ;----------------------------------------------------------------------------
  361. ;
  362. ;          START OF THE REMIN BUFFER AREA
  363. ;
  364. ;          Contains cold boot initialization code.
  365. ;
  366. REMBUF   .BYTE 00
  367. ;----------------------------------------------------------------------------
  368. ;
  369. PBOTABLE .BYTE 01.,02.,04.,05.,07.,08.,28.,29.,43.,44. ; offset bytes to patch
  370.                                                        ; back the BIOS jump
  371.                                                        ; vector.
  372. AP2STPTR .WORD AP2STAT     ; pointers to the various status routines.
  373. COMSTPTR .WORD COMSTAT
  374. HAYESTPTR.WORD HAYESTAT
  375. FIRMSTPTR.WORD FIRMSTAT
  376. ;
  377. OFFSET1  .BYTE 04E,01A     ; offset and identification bytes to recognize
  378. OFFSET2  .BYTE 065,02A     ; different serial cards :
  379. IDBYTE1  .BYTE 04D,09C     ; first row = IBS AP2 serial card.
  380. IDBYTE2  .BYTE 0A3,051     ; second row = Hayes Micromodem card.
  381. ;
  382. ; Insert more offset and Id-bytes for other serial cards here.
  383. ; Adjust NUMSERID correspondingly.
  384. ;
  385. ;-------------------------
  386. ONCERINIT LDX #009         ; cold boot init jumps here.
  387. PATCHBACK LDA PBOTABLE,X   ; get normal BIOS addresses from the attached copy
  388.           TAY              ; and patch back the BIOS jump vector, except
  389.           LDA @ACJVAFOLD,Y ; remote status, read and init.
  390.           STA @JVAFOLD,Y
  391.           DEX
  392.           BPL PATCHBACK
  393. ;--------------------------
  394.           CLC              ; get address of CONCK, add 6 to it and patch
  395.           LDY #055.        ; this code.
  396.           LDA @ACJVAFOLD,Y
  397.           ADC #006
  398.           STA PATCH2+1
  399.           INY
  400.           LDA @ACJVAFOLD,Y
  401.           ADC #000
  402.           STA PATCH2+2
  403. ;--------------------------
  404.           LDY #031.        ; get address of Remote INIT and patch this code.
  405.           LDA @ACJVAFOLD,Y
  406.           STA PATCH1+1
  407.           INY
  408.           LDA @ACJVAFOLD,Y
  409.           STA PATCH1+2
  410. ;--------------------------
  411.           LDA #0EA         ; patch the instruction JMP ONCERINIT to NOP(3x).
  412.           STA PATCH3       ; ONCERINIT will be done only once.
  413.           STA PATCH3+1
  414.           STA PATCH3+2
  415. ;--------------------------
  416. ;--------------------------
  417.           LDA SLT2TYP      ; find out which serial card there is in slot 2.
  418.           CMP #003
  419.           BNE NXTTYP2
  420.           LDX COMSTPTR     ; Apple Com Card : save pointer to status routine
  421.           LDY COMSTPTR+1   ; in X and Y registers.
  422.           BNE TORINIT
  423. NXTTYP2   CMP #006
  424.           BNE NXTTYP3
  425.           LDA FSTATUS      ; firmware card : get offset bytes from card's ROM
  426.           STA PATCH4+1     ; and patch the status and read routine entry
  427.           LDA FREAD        ; points in the FIRMSTAT routine.
  428.           STA PATCH5+1
  429.           LDX FIRMSTPTR
  430.           LDY FIRMSTPTR+1
  431.           BNE TORINIT
  432. NXTTYP3   CMP #004
  433.           BNE NOTKNOWN
  434.           JSR FINDSER      ; if it is a serial card try to recognize it.
  435.           BMI NOTKNOWN     ; FINDSER returns with minus flag on if card was
  436.           TYA              ; not recognized. Y = ID number of serial card.
  437.           BEQ AP2SER       ; Y=0 : IBS AP2 card.
  438. HAYSER    CMP #001         ; Y=1 : Hayes micromodem card.
  439.                            ; If Hayes card is already recognized as an Apple
  440.                            ; Com card (I don't know), then this part can be
  441.                            ; deleted.
  442.           BNE NOTKNOWN     ; If FINDSER recognizes more serial cards then
  443.                            ; insert here extra code for other cards.
  444.           LDX HAYESTPTR
  445.           LDY HAYESTPTR+1
  446.           BNE TORINIT
  447. AP2SER    LDX AP2STPTR
  448.           LDY AP2STPTR+1
  449. ;--------------------------
  450. TORINIT   STX REMINCK+1    ; Patch INPORTSTAT to point to the adress of status
  451.           STY REMINCK+2    ; routine.
  452. PATCH1    JMP RINIT        ; Initialize once the serial card according to the
  453.                            ; card's normal init routine.
  454. NOTKNOWN  LDX #009         ; If card was not recognized then return to system
  455.           LDY #SLOT        ; with error code 9 ( volume not found ).
  456.           RTS
  457. ;-------------------------------------------------------------------------
  458. ;
  459. ;  Serial card recognition routine.
  460. ;
  461. ;  Checks two unique bytes in the cards ROM space ( C200-C2FF ).
  462. ;
  463. FINDSER   LDY #NUMSERID
  464. FNDNEXT1  LDA OFFSET1,Y
  465.           TAX
  466.           LDA SLOT2ADR,X
  467.           CMP IDBYTE1,Y
  468.           BEQ CONFIRM
  469. FNDNEXT2  DEY
  470.           BPL FNDNEXT1
  471.           RTS
  472. CONFIRM   LDA OFFSET2,Y
  473.           TAX
  474.           LDA SLOT2ADR,X
  475.           CMP IDBYTE2,Y
  476.           BNE FNDNEXT2
  477. CODEND    RTS
  478. ;---------------------------------------------------------------------------
  479.           .BLOCK 256.+REMBUF-CODEND,00  ; adjusts buffer if init codelength
  480.                                         ; is changed.
  481. ;---------------------------------------------------------------------------
  482.           .END
  483.