home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BYE5 / B5AN-1.IQS / B5AN-1.INS
Text File  |  2000-06-30  |  12KB  |  493 lines

  1. ; B5AN-1.ASM - Apple // with PCPI Applicard and MTN CPS Serial Card
  2. ;
  3. ;        2651 with internal baudrate generator
  4. ;
  5. ; This insert version is for the Apple ][+ with the Mountain Computer
  6. ; CPS Serial Interface Card and PCPI Applicard. Additional routines
  7. ; are included to support the TIME routines in BYE5nn.
  8. ;
  9. ; Thanks to Norman Beeler for previous versions of this insert.
  10. ;
  11. ;-----------------------------------------------------------------------
  12. ;
  13. ; 12/23/85  Written for BYE5        - H. Middlebrook
  14. ;
  15. ;-----------------------------------------------------------------------
  16. ;
  17. ;             BYE5xx Insert Information
  18. ;
  19. ; The following information regarding BYE5xx inserts is included for
  20. ; reference purposes and may be removed and saved in a separate file.
  21. ;
  22. ; HARDWARE (Serial I/O) --
  23. ;
  24. ; BYE5 program calls a number of hardware routines, listed below:
  25. ;
  26. ; MODEM Specific --
  27. ;
  28. ; If IMODEM is set true in BYE5nn, then MDINIT and MDQUIT routines
  29. ; should should call IMxxxx routines in BYE5xx core program.
  30. ;
  31. ; USEFUL BYE ROUTINES --
  32. ;
  33. ;    DELAY:      100 msec delay routine (uses BC and A registers)
  34. ;    KDELAY:   1 msec delay routine (uses BC and A registers)
  35. ;
  36. ; ROUTINES called from BYE core program code --
  37. ;
  38. ;    ** Routines may use A register but must preserve all others
  39. ;       (if used).  Flags must be set as indicated for status
  40. ;       routines.
  41. ;
  42. ; MDCARCK    Carrier check.
  43. ;        Flags:    Set Zero if No Carrier is present
  44. ;
  45. ; MDQUIT    Leaving BYE...reset modem.  Called when SYSOP types
  46. ;        Ctrl-C.  If IMODEM is TRUE then call IMQUIT and
  47. ;        fall through to MDSTOP; else just fall through to
  48. ;        MDSTOP.
  49. ;
  50. ; MDSTOP    Drop DTR permanently.
  51. ;        Disable DTR...MDINIT and SETnnnn will re-enable DTR.
  52. ;
  53. ; MDINIT    Initialize modem (serial I/O).
  54. ;        For CPS card, drop then raise DTR, set PSW = 8N1,
  55. ;        and set baud to current HSnnnn. If IMODEM is TRUE,
  56. ;        then CALL IMINIT after initializing CPS card.
  57. ;
  58. ; MDINP     Receive character from serial (modem) interface.
  59. ;        Regs:    A = Character received
  60. ;
  61. ; MDOUTP    Send character to serial (modem) interface.
  62. ;        Regs:    A = Character to send to modem
  63. ;
  64. ; MDOUTST    Output status of serial (modem) interface.
  65. ;        Flags:    Set Zero if I/O not ready for character
  66. ;
  67. ; MDINST    Input status of serial (modem) interface.
  68. ;        Flags:    Set Zero if I/O does not have character
  69. ;        Regs:    A = 00H if I/O does not have character
  70. ;        This routine requires that both A = 00H and zero
  71. ;        set if a character is not available.  Your routine
  72. ;        should clear zero and return with A = 0FFH if
  73. ;        character is available.
  74. ;
  75. ; MDCRDL    Carrier check with 2 second delay.  Returns with
  76. ;        carrier status ON or BEFORE about a 2 second delay.
  77. ;        This routine may be required for modems which are
  78. ;        slow in returning carrier status after ATA command.
  79. ;        Replace the following code in BYE502:
  80. ;
  81. ;    Was --        FINISH: CALL    MDCARCK
  82. ;
  83. ;    Now --        FINISH: CALL    MDCRDL
  84. ;
  85. ; SETnnnn    Set serial I/O to specified baud rate.    Only one
  86. ;        routine is called depending on HSnnnn EQUATE in
  87. ;        BYE core.  Should init CPS card to PSW=8N1 and
  88. ;        Baud = nnnn.
  89. ;
  90. ;
  91. ;-----------------------------------------------------------------------
  92. ;
  93. ;        CPS Serial Interface Routines
  94. ;
  95. SLOT    EQU    2            ; CPS card slot number
  96. ;
  97. ;
  98. ; CPS Serial Port and Register Equates
  99. ;
  100. DATREG    EQU    0C0FAH + SLOT *    100H    ;Serial Data Register
  101. STAREG    EQU    0C0FBH + SLOT *    100H    ;Serial Status Register
  102. SCRCTL    EQU    0C0FEH + SLOT *    100H    ;CPS Serial Ctl Register
  103. CLKREG    EQU    0C0F9H + SLOT *    100H    ;CPS Clock Data Register
  104. ;
  105. RDBYTEAPPL    EQU    0FFE0H        ;Read byte from Apple
  106. WRBYTEAPPL    EQU    0FFE3H        ;Write byte to Apple
  107. RDWORD        EQU    0FFE6H        ;Read 2 bytes  (DE = Bytes)
  108. WRWORD        EQU    0FFE9H        ;Write 2 bytes (DE = Bytes)
  109. ;
  110. PEEK1BYTE    EQU    6        ;Command to Peek 1 byte to Apple
  111. POKE1BYTE    EQU    7        ;Command to Poke 1 byte to Apple
  112. ;
  113. ;
  114. ; The following routines communicate with hardware in Apple Slots
  115. ; directly from Applicard.
  116. ;
  117. ; Read the UART Status Register
  118. ;
  119. RD$STAREG:
  120.     PUSH    D
  121.     LXI    D,STAREG
  122.     CALL    PEEK
  123.     POP    D
  124.     RET
  125. ;.....
  126. ;
  127. ;
  128. ; Write to the UART Status Register
  129. ;
  130. WR$STAREG:
  131.     PUSH    D
  132.     LXI    D,STAREG
  133.     CALL    POKE
  134.     POP    D
  135.     RET
  136. ;.....
  137. ;
  138. ;
  139. ; Write to the UART Command Port
  140. ;
  141. WR$SCRCTL:
  142.     PUSH    D
  143.     LXI    D,SCRCTL
  144.     CALL    POKE
  145.     POP    D
  146.     RET
  147. ;.....
  148. ;
  149. ;
  150. ; Read the UART Data Register
  151. ;
  152. RD$DATREG:
  153.     PUSH    D
  154.     LXI    D,DATREG
  155.     CALL    PEEK
  156.     POP    D
  157.     RET
  158. ;.....
  159. ;
  160. ;
  161. ; Write to the UART Data Register
  162. ;
  163. WR$DATREG: PUSH    D
  164.     LXI    D,DATREG
  165.     CALL    POKE
  166.     POP    D
  167.     RET
  168. ;.....
  169. ;
  170. ;
  171. ; Read a byte from CPS clock register
  172. ;
  173. RD$CLKDATA:
  174.     PUSH    D
  175.     LXI    D,CLKREG    ; Select clock data
  176.     CALL    PEEK
  177.     POP    D
  178.     RET
  179. ;.....
  180. ;
  181. ;
  182. ; PEEK at 1 byte in Apple address space
  183. ;    ENTRY  DE = Address in 6502 RAM/ROM
  184. ;    EXIT   A  = Data from 6502
  185. ;
  186. PEEK:    PUSH    B
  187.     MVI    C,PEEK1BYTE
  188.     CALL    WRBYTEAPPL
  189.     CALL    WRWORD
  190.     CALL    RDBYTEAPPL
  191.     POP    B
  192.     RET
  193. ;.....
  194. ;
  195. ;
  196. ; POKE 1 byte to Apple address space
  197. ;    ENTRY  DE = Address in 6502 RAM/ROM
  198. ;    EXIT   A  = data to 6502
  199. ;
  200. POKE:    PUSH    B
  201.     MOV    B,A
  202.     MVI    C,POKE1BYTE
  203.     CALL    WRBYTEAPPL
  204.     CALL    WRWORD
  205.     MOV    C,B
  206.     CALL    WRBYTEAPPL
  207.     POP    B
  208.     RET
  209. ;.....
  210. ;
  211. ;
  212. ;----------------------------------------------------------------------
  213. ;
  214. ; This routine intializes Serial Port of CPS card and (optionally)
  215. ; initializes ASCII commanded modem.  NOTE: PSW and BAUD must be set
  216. ; by two sequential writes to DATREG with SCRCTL access open.
  217. ;
  218. MDINIT:    MVI    A,80H
  219.     CALL    WR$SCRCTL
  220.     MVI    A,15H        ; Drop DTR and reset serial I/O
  221.     CALL    WR$STAREG
  222.     MVI    B,20
  223. ;
  224. MDDLOP:    CALL    DELAY        ; 2 second delay
  225.     DCR    B
  226.     JNZ    MDDLOP
  227.     MVI    A,27H        ; Now re-enable serial port
  228.     CALL    WR$STAREG
  229.     MVI    A,4EH        ; Set PSW = 8N1  (1st DATREG write)
  230.     CALL    WR$DATREG
  231.     MVI    A,03AH        ; Default to 2400 baud
  232. ;
  233.      IF    HS1200
  234.     MVI    A,037H
  235.      ENDIF            ; HS1200
  236. ;
  237.      IF    HS300
  238.     MVI    A,035H
  239.      ENDIF            ; HS300
  240. ;
  241.     CALL    WR$DATREG    ; Set baud (2nd DATREG write)
  242.     XRA    A        ; Close BAUD/PSW access
  243.     CALL    WR$SCRCTL
  244. ;
  245.      IF    IMODEM
  246.     CALL    IMINIT        ; Initialize smartmodem
  247.      ENDIF            ; IMODEM
  248. ;
  249.     RET
  250. ;.....
  251. ;
  252. ;
  253. ; This routine is called when BYE is to go off the air
  254. ;
  255. MDQUIT:     IF    IMODEM
  256.     CALL    IMQUIT
  257.      ENDIF            ; IMODEM
  258. ;
  259. ;
  260. ; This routine will shut everything down permanently.
  261. ;
  262. MDSTOP:    MVI    A,80H        ; Enable UART command register
  263.     CALL    WR$SCRCTL
  264.     MVI    A,05H        ; Disable DTR and RTS (UART Cmd Reg)
  265.     CALL    WR$STAREG
  266.     XRA    A        ; Enable CPS status register
  267.     CALL    WR$SCRCTL
  268.     CALL    DELAY        ; 100 msec delay
  269.     RET
  270. ;.....
  271. ;
  272. ;
  273. ; The following is a routine to determine if there is a character wait-
  274. ; ing to be received.  If none are there, the Zero flag will be set,
  275. ; otherwise, 255 will be returned in register A.
  276. ;
  277. MDINST:    CALL    RD$STAREG    ; Read UART command register
  278.     ANI    02H        ; Mask everything but RxRDY, char ready?
  279.     RZ            ; No, then return
  280.     ORI    0FFH        ; Yes, be sure to set flag and A reg
  281.     RET
  282. ;.....
  283. ;
  284. ;
  285. ; The following is a routine to determine if the transmit buffer is
  286. ; empty.  If it is empty, it will return with the Zero flag clear.  If
  287. ; the transmitter is busy, then it will return with the Zero flag set.
  288. ;
  289. ;
  290. MDOUTST:CALL    RD$STAREG    ; Read status register
  291.     ANI    01H        ; Mask everything but TxRDY and...
  292.     RET            ; Return with flags set
  293. ;.....
  294. ;
  295. ;
  296. ; The following is a routine that will check to make sure we still have
  297. ; carrier.  If there is no carrier, it will return with the Zero flag
  298. ; set.    There are two entry points to this section: the 1st MDCRDL delays
  299. ; for 2 seconds or until carrier is detected.  The second is the normal
  300. ; entry for carrier check.
  301. ;
  302. MDCRDL:    PUSH    B
  303.     MVI    B,20        ; Set for 2 sec delay max
  304. ;
  305. MDCK2:    CALL    DELAY        ; Wait 100 msecs
  306.     CALL    MDCARCK
  307.     JNZ    MDCK1        ; If carrier, then return
  308.     DCR    B
  309.     JNZ    MDCK2        ; If not 2 secs, then continue timing
  310. ;
  311. MDCK1:    POP    B        ; When done fall thru to carrier check
  312. ;
  313. ;
  314. ; This is normal carrier check routine.
  315. ;
  316. MDCARCK:CALL    RD$STAREG    ; Read status register
  317.     ANI    080H        ; Use DSR bit instead of DTR bit
  318.     RET
  319. ;.....
  320. ;
  321. ;
  322. ; The following is a routine that will input one character from the
  323. ; CPS UART register.
  324. ;
  325. MDINP:    CALL    RD$DATREG    ; Get character
  326.     RET
  327. ;.....
  328. ;
  329. ;
  330. ; The following is a routine that will output one character in register
  331. ; A to the CPS UART data register.
  332. ;
  333. MDOUTP:    CALL    WR$DATREG    ; Send character to CPS UART
  334.     RET
  335. ;.....
  336. ;
  337. ;
  338. ; The following routines set the CPS card to a specified baud rate. A
  339. ; common setup routine is jumped to after baud setup byte in local
  340. ; storage.
  341. ;
  342. SET300:    MVI    A,35H        ; 300 baud setup byte
  343.     STA    MBSET
  344.     JMP    BPSET        ; Jump to psw/baud set routine
  345. ;
  346. SET1200:MVI    A,37H        ; 1200 bps byte
  347.     STA    MBSET
  348.     JMP    BPSET
  349. ;
  350. SET2400:MVI    A,3AH        ; 2400 bps byte
  351.     STA    MBSET
  352. ;
  353. BPSET:    MVI    A,80H        ; Open command register
  354.     CALL    WR$SCRCTL    ; By storing 80H in SCRCTL
  355.     MVI    A,27H        ; Initialize the serial chip
  356.     CALL    WR$STAREG    ; By storing 27H in STAREG
  357.     MVI    A,4EH        ; Set default format 8N1
  358.     CALL    WR$DATREG
  359.     LDA    MBSET        ; Get baud rate byte from local storage
  360.     CALL    WR$DATREG
  361.     XRA    A
  362.     CALL    WR$SCRCTL    ; Close command port by storing 0
  363.     RET
  364. ;.....
  365. ;
  366. ;
  367. MBSET:    DB    0        ; Storage for baud setup byte
  368. ;.....
  369. ;
  370. ;
  371. ;-----------------------------------------------------------------------
  372. ;
  373. ; WARNING:  This section uses code in the PORT insert above.  Use care
  374. ;        care if altering it or if you change the code above.
  375. ;
  376. ; This TIME routine is adapted from TIME14.ASM (Nov 85 - HMM).    The
  377. ; routine uses a burst read of time from CPS clock chip (OKI 5832).
  378. ; The raw data is stored in CLKBUF then assembled and placed into
  379. ; RTCBUF in BYE.
  380. ;
  381. ; Real-Time clock buffer is organized as HH:MM:SS  YYYY/MM/DD
  382. ;
  383. ;RTCBUF:DB    99H,99H,99H    ;HH:MM:SS (BCD 24hr) 00:00:00-23:59:59
  384. ;    DB    19H,84H,01H,31H ;YYYY/MM/DD  (BCD ISO DATE)
  385. ;
  386. ;
  387. ; BYE5 save and restores registers before/after calling TIME.
  388. ;
  389.      IF    CLOCK OR RSPEED
  390. TIME:    MVI    A,040H        ; Get byte to stop clock
  391.     CALL    WR$SCRCTL    ; Send to CPS card
  392.     LXI    D,CLKBUF    ; Put CLKBUF address in DE
  393.     MVI    B,0        ; Set clock index to 0
  394. ;
  395. TMLOOP:    MVI    A,050H        ; Get byte to read clock
  396.     ORA    B        ; Add clock index to read (50H - 5CH)
  397.     CALL    WR$SCRCTL    ; Send to CPS card
  398.     CALL    RD$CLKDATA    ; Read clock (SEC1 --> YEAR10)
  399.     ANI    0FH        ; Mask garbage in high nibble
  400.     STAX    D        ; Save value read in CLKBUF
  401.     INX    D        ; Bump CLKBUF address value in DE
  402.     INR    B        ; Bump clock index in BC
  403.     MVI    A,0DH        ; Fetch table length + 1
  404.     CMP    B        ; Are we beyond end of table...
  405.     JNZ    TMLOOP        ; No, then go back again
  406.     XRA    A        ; Yes, then zero A reg to turn on clock
  407.     CALL    WR$SCRCTL
  408. ;
  409. ;
  410. ; Now move data from CLKBUF to RTCBUF.
  411. ;
  412. FIXRTC:    LDA    CLKBUF+1    ; Seconds
  413.     ANI    7
  414.     MOV    B,A
  415.     LDA    CLKBUF+0
  416.     CALL    SHFTIT
  417.     STA    RTCBUF+2
  418.     LDA    CLKBUF+3    ; Minutes
  419.     ANI    7
  420.     MOV    B,A
  421.     LDA    CLKBUF+2
  422.     CALL    SHFTIT
  423.     STA    RTCBUF+1
  424.     LDA    CLKBUF+5    ; Hours
  425.     ANI    3
  426.     MOV    B,A
  427.     LDA    CLKBUF+4
  428.     CALL    SHFTIT
  429.     STA    RTCBUF+0
  430.     MVI    A,19H        ; Century
  431.     STA    RTCBUF+3
  432.     LDA    CLKBUF+12    ; Year
  433.     MOV    B,A
  434.     LDA    CLKBUF+11
  435.     CALL    SHFTIT
  436.     STA    RTCBUF+4
  437.     LDA    CLKBUF+10    ; Month
  438.     ANI    1
  439.     MOV    B,A
  440.     LDA    CLKBUF+9
  441.     CALL    SHFTIT
  442.     STA    RTCBUF+5
  443.     LDA    CLKBUF+8    ; Day
  444.     ANI    3
  445.     MOV    B,A
  446.     LDA    CLKBUF+7
  447.     CALL    SHFTIT
  448.     STA    RTCBUF+6
  449.     LDA    RTCBUF        ; Put current hour
  450.     CALL    BCDBIN
  451.     STA    CCHOUR        ; And minute into CCHOUR
  452.     LDA    RTCBUF+1
  453.     CALL    BCDBIN        ; And CCMIN in Binary
  454.     STA    CCMIN
  455.     RET            ; To BYE
  456. ;
  457. SHFTIT:    PUSH    PSW        ; Routine to put A & B registers
  458.     MOV    A,B        ; Together (low order nibbles)
  459.     RLC
  460.     RLC            ; Return with result in A.
  461.     RLC
  462.     RLC
  463.     MOV    B,A
  464.     POP    PSW
  465.     ANI    0FH
  466.     ORA    B
  467.     RET
  468. ;.....
  469. ;
  470. ;
  471. ; The CLKBUF is fixed, initialized area used to store time as
  472. ; read from CPS clock hardware.  Must be DB 0 for proper relocation
  473. ; when using BYE.
  474. ;
  475. CLKBUF:    DB    0        ; S1
  476.     DB    0        ; S10
  477.     DB    0        ; MIN1
  478.     DB    0        ; MIN10
  479.     DB    0        ; H1
  480.     DB    0        ; H10
  481.     DB    0        ; Day of Week (not used here in BYE)
  482.     DB    0        ; D1
  483.     DB    0        ; D10
  484.     DB    0        ; MON1
  485.     DB    0        ; MON10
  486.     DB    0        ; Y1
  487.     DB    0        ; Y10
  488.      ENDIF            ; CLOCK OR RSPEED
  489. ;.....
  490. ;
  491. ;                   end
  492. ;-----------------------------------------------------------------------
  493.