home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / modem / mxh-am14.z80 < prev    next >
Encoding:
Text File  |  1994-09-02  |  24.8 KB  |  869 lines

  1.  
  2.     .Z80
  3.     ASEG
  4.  
  5. ; MXH-AMNZ.Z80
  6. ; MEX+ overlay for the Ampro Little Board computer
  7.  
  8. ; Version 1.4: 06 Feb 1990
  9. ;     * Added routine to send 300ms BREAK using T-mode-esc-@     
  10. ;                                                 Bruce McIntosh
  11.  
  12.  
  13. ; Version 1.3: 28 Jan 1990
  14. ;     * Renamed to be assemblable by SLR assembler
  15. ;     * Made overlay compatible with MEX+ as per instructions 
  16. ;       in -READ.ME on MEX+ distribution disk 
  17. ;     * DCD and ring routines Z80-fied copies of similar
  18. ;       routines in Bob Connelly's MXH-AM11.ASM
  19. ;     * Slightly modified code that finds address of real
  20. ;       BIOS to correct a couple of incorrect offsets
  21. ;                                                 Bruce McIntosh
  22.  
  23. ; MXO-AMxx.ASM
  24. ; MEX overlay for the Ampro Little Board Computer
  25.  
  26. ; Version 1.2: 23 Jul 1988
  27. ;    added routine to allow this overlay to find original
  28. ;    bios under manually installed or nz-com system.
  29. ;                        al grabauskas
  30.  
  31. ; Version 1.1:  1 Oct 1986
  32. ;     ( added support for dropping DTR for those modems that
  33. ;       support it.  -Marc Wilson                            )
  34. ;
  35. ; Version 1.0: 28 Nov 1984  
  36.  
  37. REV    EQU    14        ; Overlay revision level
  38.  
  39.  
  40. ; This is a MEX overlay file for the Ampro Computer.  It is designed
  41. ; to work with the modem connected to serial port 'B'.  It also       
  42. ; requires the CTC and SIO parameter tables at the front of the
  43. ; Ampro bios, as well as the I/O initialization routine in the
  44. ; Ampro bios.  This is a non-standard bios call and if not present
  45. ; in the bios it must be duplicated in this overlay.
  46.  
  47. ; Note that all overlays may freely use memory up to 0CFFH.  If the
  48. ; overlay must work with the MEX Smartmodem overlay (MXO-SMxx.ASM),
  49. ; the physical modem overlay should terminate by 0AFFH.
  50.     
  51. ;------------------------------------------------------------
  52.  
  53. ; Misc equates
  54.  
  55. NO    EQU    0
  56. YES    EQU    0FFH
  57. TPA    EQU    100H
  58. CR    EQU    13
  59. LF    EQU    10
  60. TAB    EQU    9
  61.  
  62. ; Ampro definitions
  63.  
  64. IOINT    EQU    57        ; BIOS call of initialization routine
  65. SIOB    EQU    52H        ; Relative location in bios
  66. SIOB1    EQU    53H
  67. SIOB3    EQU    55H        ; Z80DART write register 5
  68. SIOB5    EQU    57H        ; Z80DART write register 3
  69. CT1    EQU    42H
  70.  
  71. ; port definitions
  72.  
  73. MODCTL    EQU    8CH        ; Modem control port B
  74. MODDAT    EQU    88H        ; Modem data port B
  75.  
  76. ; bit definitions
  77.  
  78. MDRCVB    EQU    01H        ; Modem receive bit (DAV)
  79. MDRCVR    EQU    01H        ; Modem receive ready
  80. MDSNDB    EQU    04H        ; Modem send bit
  81. MDSNDR    EQU    04H        ; Modem send ready bit
  82.  
  83. ; MEX service processor stuff ... MEX supports an overlay service
  84. ; processor, located at 0D00H (and maintained at this address from
  85. ; version to version).  If your overlay needs to call BDOS for any
  86. ; reason, it should call MEX instead; function calls below about
  87. ; 240 are simply passed on to the BDOS (console and list I/O calls
  88. ; are specially handled to allow modem port queueing, which is why
  89. ; you should call MEX instead of BDOS).  MEX uses function calls
  90. ; above about 244 for special overlay services (described below).
  91.  
  92. ; Some sophisticated overlays may need to do file I/O; if so, use
  93. ; the PARSFN MEX call with a pointer to the FCB in DE to parse out
  94. ; the name.  This FCB should support a spare byte immediately pre-
  95. ; ceeding the actual FCB (to contain user # information).  If you've
  96. ; used MEX-10 for input instead of BDOS-10 (or you're parsing part
  97. ; of a SET command line that's already been input), then MEX will
  98. ; take care of DU specs, and set up the FCB accordingly.  There-
  99. ; after all file I/O calls done through the MEX service processor
  100. ; will handle drive and user with no further effort necessary on
  101. ; the part of the programmer.
  102.  
  103. MEX    EQU    0D00H        ; Address of the service processor
  104. INMDM    EQU    255        ; Get char from port to A, CY=no more in 100 ms
  105. TIMER    EQU    254        ; Delay 100ms * reg B
  106. TMDINP    EQU    253        ; B=# secs to wait for char, cy=no char
  107. CHEKCC    EQU    252        ; Check for ^C from KBD, Z=present
  108. SNDRDY    EQU    251        ; Test for modem-send ready
  109. RCVRDY    EQU    250        ; Test for modem-receive ready
  110. SNDCHR    EQU    249        ; Send a character to the modem (after sndrdy)
  111. RCVCHR    EQU    248        ; Recv a char from modem (after rcvrdy)
  112. LOOKUP    EQU    247        ; Table search: see CMDTBL comments for info
  113. PARSFN    EQU    246        ; Parse filename from input stream
  114. BDPARS    EQU    245        ; Parse baud-rate from input stream
  115. SBLANK    EQU    244        ; Scan input stream to next non-blank
  116. EVALA    EQU    243        ; Evaluate numeric from input stream
  117. LKAHED    EQU    242        ; Get nxt char w/o removing from input
  118. GNC    EQU    241        ; Get char from input, cy=1 if none
  119. ILP    EQU    240        ; Inline print
  120. DECOUT    EQU    239        ; Decimal output
  121. PRBAUD    EQU    238        ; Print baud rate
  122.  
  123. CONOUT    EQU    2        ; Simulated BDOS function 2: console char out
  124. PRINT    EQU    9        ; Simulated BDOS function 9: print string
  125. INBUF    EQU    10        ; Input buffer, same structure as BDOS 10
  126.  
  127.     ORG    TPA        ; We begin
  128.  
  129. ; Changed DS 3 per -READ.ME to flag overlay as LOADable by MEX+
  130.  
  131.     DB    0C3H        ; mark overlay as LOADable
  132.     DS    2        ; space for JP START address in MEX
  133.  
  134. ; The following variables are located at the beginning of the program
  135. ; to facilitate modification without the need of re-assembly. They will
  136. ; be moved in MEX 2.0.
  137.  
  138. PMODEM:    DB    NO        ; Yes=PMMI modem \ / These 2 locations are not
  139. SMODEM:    DB    NO         ; Yes=Smartmodem / \ referenced by MEX
  140. TPULSE:    DB    'T'        ; T=touch, P=pulse (not referenced by MEX)
  141. CLOCK:    DB    40        ; Clock speed x .1, up to 25.5 mhz.
  142. MSPEED:    DB    6        ; Sets display time for sending a file
  143.                 ; 0=110    1=300  2=450  3=600  4=710
  144.                 ; 5=1200 6=2400 7=4800 8=9600 9=19200
  145. BYTDLY:    DB    5        ; Default time to send character in
  146.                 ; Terminal mode file transfer (0-9)
  147.                 ; 0=0 delay, 1=10 ms, 5=50 ms, 9=90 ms
  148. CRDLY:    DB    5        ; End-of-line delay after CRLF in terminal
  149.                 ; Mode file transfer for slow BBS systems
  150.                 ; 0=0 delay, 1=100 ms, 5=500 ms, 9=900 ms
  151. COLUMS:    DB    5        ; Number of directory columns
  152. SETFL:    DB    YES        ; Yes=user-defined SET command
  153. SCRTST:    DB    YES        ; Yes=if home cursor and clear screen
  154.                 ; Routine at CLRSCRN
  155.     DB    0        ; Was once ACKNAK, now spare
  156. BAKFLG:    DB    NO        ; Yes=make .BAK file
  157. CRCDFL:    DB    YES        ; Yes=default to CRC checking
  158.                 ; No=default to Checksum checking
  159. TOGCRC:    DB    YES        ; Yes=allow toggling of Checksum to CRC
  160. CVTBS:    DB    NO        ; Yes=convert backspace to rub
  161. TOGLBK:    DB    YES        ; Yes=allow toggling of bksp to rub
  162. ADDLF:    DB    NO        ; No=no LF after CR to send file in
  163.                 ; Terminal mode (added by remote echo)
  164. TOGLF:    DB    YES        ; Yes=allow toggling of LF after CR
  165. TRNLOG:    DB    YES        ; Yes=allow transmission of logon
  166.                 ; Write logon sequence at location LOGON
  167. SAVCCP:    DB    YES        ; Yes=do not overwrite CCP
  168. LOCNXT:    DB    NO        ; Yes=local cmd if EXTCHR precedes
  169.                 ; No=not local cmd if EXTCHR precedes
  170. TOGLOC:    DB    YES        ; Yes=allow toggling of LOCNXTCHR
  171. LSTTST:    DB    YES        ; Yes=allow toggling of printer on/off
  172.                 ; In terminal mode. Set to no if using
  173.                 ; The printer port for the modem
  174. XOFTST:    DB    YES        ; Yes=allow testing of XOFF from remote
  175.                 ; While sending a file in terminal mode
  176. XONWT:    DB    NO        ; Yes=wait for XON after sending CR while
  177.                 ; Transmitting a file in terminal mode    
  178. TOGXOF:    DB    YES        ; Yes=allow toggling of XOFF testing
  179. IGNCTL:    DB    NO         ; Yes=do not send control characters
  180.                 ; Above CTL-M to CRT in terminal mode
  181.                 ; No=send any incoming CTL-char to CRT
  182. EXTRA1:    DB    0        ; For future expansion
  183. EXTRA2:    DB    0        ; For future expansion
  184. BRKCHR:    DB    '@'-40H        ; ^@ = Send a 300 ms. break tone
  185. NOCONN:    DB    'N'-40H        ; ^N = Disconnect from phone line
  186. LOGCHR:    DB    'L'-40H        ; ^L = Send logon
  187. LSTCHR:    DB    'P'-40H        ; ^P = Toggle printer
  188. UNSVCH:    DB    'R'-40H        ; ^R = Close input text buffer
  189. TRNCHR:    DB    'T'-40H        ; ^T = Transmit file to remote
  190. SAVCHR:    DB    'Y'-40H        ; ^Y = Open input text buffer
  191. EXTCHR:    DB    '^'-40H        ; ^^ = Send next character
  192.  
  193.     DS    2        ; Make addresses right
  194.  
  195. ; Low-level modem I/O routines: this will be replaced with
  196. ; a jump table in MEX 2.0 (you can insert jumps here to longer
  197. ; routines if you'd like ... I'd recommend NOT putting part of
  198. ; a routine in this area, then jumping to the rest of the routine
  199. ; in the non-fixed area; that will complicate the 2.0 conversion)
  200.  
  201. INCTL1:    IN    A,(MODCTL)    ; In modem control port
  202.     RET
  203.     DB    0,0,0,0,0,0,0    ; Spares if needed for non-PMMI
  204.  
  205. OTDATA:    OUT    (MODDAT),A    ; Out modem data port
  206.     RET
  207.     DB    0,0,0,0,0,0,0    ; Spares if needed for non=PMMI
  208.  
  209. INPORT:    IN    A,(MODDAT)    ; In modem data port
  210.     RET
  211.     DB    0,0,0,0,0,0,0    ; Spares if needed for non-PMMI
  212.  
  213. ; Bit-test routines.  These will be merged with the above
  214. ; routines in MEX 2.0 to provide a more reasonable format
  215.  
  216. MASKR:    AND    MDRCVB
  217.     RET            ; Bit to test for receive ready
  218. TESTR:    CP    MDRCVR
  219.     RET            ; Value of receive bit when ready
  220. MASKS:    AND    MDSNDB
  221.     RET            ; Bit to test for send ready
  222. TESTS:    CP    MDSNDR
  223.     RET            ; Value of send bit when ready
  224.  
  225. ; Unused area: was once used for special PMMI functions,
  226. ; Now used only to retain compatibility with MDM overlays.
  227. ; You may use this area for any miscellaneous storage you'd
  228. ; like but the length of the area *must* be 12 bytes.
  229.  
  230. ; Added jumps to DCD and ring detect routines for MEX+ at 0157H.
  231. ; DS 3 pads keep length 12 bytes, as required in comments above.
  232.  
  233.     DS    3      
  234. DCDTST: JP    DCDVEC        ; DCD test routine
  235. RNGTST: JP    RNGVEC        ; ring test routine
  236.     DS    3
  237.  
  238. ; Special modem function jump table: if your overlay cannot handle
  239. ; some of these, change the jump to "DS 3", so the code present in
  240. ; MEX will be retained.  Thus, if your modem can't dial, change the
  241. ; JMP PDIAL at DIALV to DS 3, and MEX will print a "not-implemented"
  242. ; diagnostic for any commands that require dialing.
  243.  
  244. ; DIALV  dials the digit in A. See the comments at PDIAL for specs.
  245.  
  246. ; DISCV  disconnects the modem
  247.  
  248. ; GOODBV is called just before MEX exits to CP/M.  If your overlay
  249. ;        requires some exit cleanup, do it here.
  250.  
  251. ; INMODV is called when MEX starts up; use INMODV to initialize the modem.
  252.  
  253. ; NEWBDV is used for phone-number baud rates and is called with a baud-rate
  254. ;        code in the A register, value as follows:
  255.  
  256. ;     A=0:   110 baud       A=1:   300 baud      A=2:   450 baud
  257. ;     A=3:   600 baud       A=4:   710 baud      A=5:  1200 baud
  258. ;     A=6:  2400 baud       A=7:  4800 baud      A=8: 19200 baud
  259.  
  260. ;        If your overlay supports the passed baud rate, it should store the
  261. ;     value passed in A at MSPEED (107H), and set the requested rate. If
  262. ;     the value passed is not supported, you should simply return (with-
  263. ;     out modifying MSPEED) -or- optionally request a baud-rate from the
  264. ;     user interactively.
  265.  
  266. ; NOPARV is called at the end of each file transfer; your overlay may simply
  267. ;     return here, or you may want to restore parity if you set no-parity
  268. ;     in the following vector (this is the case with the PMMI overlay).
  269.     
  270. ; PARITV is called at the start of each file transfer; your overlay may simply
  271. ;     return here, or you may want to enable parity detection (this is the
  272. ;     case with the PMMI overlay).
  273.  
  274. ; SETUPV is the user-defined command ... to use this routine to build your own
  275. ;     MEX command, set the variable SETFL (117H) non-zero, and add your SET
  276. ;     code.  You can use the routine presented in the PMMI overlay as a 
  277. ;     guide for parsing, table lookup, etc.
  278.  
  279. ; SPMENU is provided only for MDM compatibility, and is not used by MEX 1.0 for
  280. ;     any purpose (it will be gone in MEX 2).
  281.  
  282. ; VERSNV is called immediately after MEX prints its sign-on message at cold
  283. ;     startup -- use this to identify your overlay in the sign-on message
  284. ;     (include overlay version number in the line).
  285. ; BREAKV is provided for sending a BREAK (<ESC>-B in terminal mode).  If your
  286. ;     modem doesn't support BREAK, or you don't care to code a BREAK rou-
  287. ;     tine, you may simply execute a RET instruction.
  288.  
  289. LOGON:    DS    2        ; Needed for MDM compat, not ref'd by MEX
  290. DIALV:    DS    3        ; Dial digit in A (see info at PDIAL)
  291. DISCV:    JP    HANGUP        ; Disconnect the modem
  292. GOODBV:    DS    3        ; Called before exit to CP/M
  293. INMODV:    JP    NITMOD        ; Initialization. Called at cold-start
  294. NEWBDV:    JP    PBAUD        ; Set baud rate
  295. NOPARV:    JP    NOPAR        ; Set modem for no-parity
  296. PARITV:    JP    PARITY        ; Set modem parity
  297. SETUPV:    JP    SETCMD        ; SET cmd: jump to a RET if you don't write SET
  298. SPMENV:    DS    3        ; Not used with MEX
  299. VERSNV:    JP    SYSVER        ; Overlay's voice in the sign-on message
  300. BREAKV:    JP    SNDBRK        ; Send a break
  301.  
  302. ; The following jump vector provides the overlay with access to special
  303. ; routines in the main program (retained and supported in the main pro-
  304. ; gram for MDM overlay compatibility). These should not be modified by
  305. ; the overlay.
  306.  
  307. ; Note that for MEX 2.0 compatibility, you should not try to use these
  308. ; routines, since this table will go away with MEX 2.0 (use the MEX
  309. ; service call processor instead).
  310.  
  311. ILPRTV:    DS    3        ; Replace with MEX function 9
  312. INBUFV:    DS    3        ; Replace with MEX function 10
  313. ILCMPV:    DS    3        ; Replace with table lookup funct. 247
  314. INMDMV:    DS    3        ; Replace with MEX function 255
  315. NXSCRV:    DS    3        ; Not supported by MEX (returns w/no action)
  316. TIMERV:    DS    3        ; Replace with MEX function 254
  317.  
  318. ; Clear/screen and clear/end-of-screen. Each routine must use the
  319. ; full 9 bytes alloted (may be padded with nulls).
  320.  
  321. ; These routines (and other screen routines that MEX 2.0 will sup-
  322. ; port) will be accessed through a jump table in 2.0, and will be
  323. ; located in an area that won't tie the screen functions to the
  324. ; modem overlay (as the MDM format does).
  325.  
  326. CLREOS:    LD    DE,EOSMSG
  327.     LD    C,PRINT
  328.     CALL    MEX
  329.     RET
  330.  
  331. CLS:    LD    DE,CLSMSG    ; Null unless patched
  332.     LD    C,PRINT
  333.     CALL    MEX
  334.      RET
  335.  
  336. ; The following ORG is required because MEX+ reserves all space
  337. ; after the CLS routine above up to 200H (1A7-200).
  338.  
  339.     ORG    0200H
  340.  
  341. EOSMSG:    DB    00,00,0,0,0,'$'
  342. CLSMSG:    DB    00,00,0,0,0,'$'
  343.  
  344. NOPAR:    RET
  345.  
  346. PARITY:    RET
  347.  
  348. ;------------------------------------------------------------------
  349. ;
  350. ; This routine sets DTR and RTS low for 1 second to disconnect the phone.
  351. ; This code comes from I2AM-1D.ASM.
  352. ;
  353. ;HANGUP:
  354. ;    MVI    B,'S'-40H    ; X-off to stop host if needed
  355. ;    CALL    OUTDATA
  356. ;    MVI    B,1        ; Wait a moment to let it react
  357. ;       MVI     C,TIMER
  358. ;    CALL    MEX
  359. HANGUP:    LD    A,5
  360.     OUT    (MODCTL),A    ; Send to the status port
  361.     LD    A,068H        ; Turn off DTR, RTS, send break*
  362.                                 ; *(According to Z80DART data sheet,
  363.                                 ;   xxx1xxxx sends break, so 068H
  364.                                 ;   actually does NOT send break)
  365.     OUT    (MODCTL),A
  366.     LD    B,10        ; Wait 1 second
  367.     LD    C,TIMER
  368.     CALL    MEX
  369.     LD    A,5
  370.     OUT    (MODCTL),A
  371.     LD    A,0EAH        ; Restore normal, 8 bits, RTS on, etc.
  372.     OUT    (MODCTL),A
  373.     RET
  374.  
  375. ; DCD and ring detect routines, Z80-fied from Bob Connelly's 
  376. ; MXH-AMNZ.ASM.  Added code to save/restore 16bit registers.
  377.  
  378. DCDVEC: PUSH    BC
  379.     PUSH    DE
  380.     PUSH    HL
  381.     LD    A,010H
  382.     OUT    (MODCTL),A
  383.     IN    A,(MODCTL)
  384.     AND    020H        ; modem DCD must be tied to LB CTS 
  385.     POP    HL
  386.     POP    DE
  387.     POP    BC
  388.     RET    Z        ; return 00 if DCD low
  389.     OR    0FFH        ; return FF if DCD high
  390.     RET
  391.  
  392. ; Ring routine is pointless on LB, as RI lines on Z80DART are
  393. ; used on the board for something else.  So, return 00.
  394.  
  395. RNGVEC: XOR    A
  396.     RET
  397.  
  398. SNDBRK: PUSH    AF        ; save everything
  399.     PUSH    BC
  400.     PUSH    DE
  401.     PUSH    HL
  402.     LD    A,5        ; tell DART to get ready for WR5
  403.     OUT    (MODCTL),A
  404.     LD    HL,(BIOSADDR)    ; get BIOS address
  405.     LD    L,SIOB3        ; point to Write register 5 data
  406.     LD    A,(HL)        ; get WR5 data
  407.     OR    10H        ; start sending break
  408.     OUT    (MODCTL),A
  409.     LD    B,3        ; wait 300ms
  410.     LD    C,TIMER
  411.     CALL    MEX
  412.     LD    A,5        ; tell DART to get ready for WR5
  413.     OUT    (MODCTL),A
  414.     LD    HL,(BIOSADDR)    ; get BIOS address
  415.     LD    L,SIOB3        ; point to WR5 data
  416.     LD    A,(HL)        ; get WR5 data
  417.     OUT    (MODCTL),A    ; stop sending break
  418.     POP    HL        ; restore everything
  419.     POP    DE
  420.     POP    BC
  421.     POP    AF
  422.     RET
  423.  
  424. ;--------------------------------------------------------------
  425. ;
  426.  
  427. NITMOD:    LD    A,6        ; Initialize to 2400 baud.  No other
  428.                 ; Parameters changed... fall thru
  429.  
  430.     CALL    GRABBIOS    ; get bios address, whether nz-com
  431.                 ;   or not. returned in "biosaddr:"
  432.  
  433. PBAUD:    PUSH    HL        ; Don't alter anybody
  434.     PUSH    DE
  435.     PUSH    BC
  436.     LD    E,A        ; Code to DE
  437.     LD    D,0
  438.     LD    HL,BAUDTB    ; Offset into table
  439.     ADD    HL,DE
  440.     LD    A,(HL)        ; Fetch code
  441.     OR    A        ; 0? (means unsupported code)
  442.     SCF            ; Return error for STBAUD caller
  443.     JP    Z,PBEXIT    ; Exit if so
  444.     LD    (BSAVE1),A    ; Save it
  445.     LD    A,E        ; Get speed code back
  446.     LD    (MSPEED),A    ; Make it current
  447.     LD    HL,BAUDTX    ; Offset into second table
  448.     ADD    HL,DE
  449.     LD    A,(HL)        ; Get second value
  450.     LD    (BSAVE2),A    ; Save it also
  451.     LD    HL,(BIOSADDR)    ; Get location of bios
  452.     LD    L,CT1        ; Add 42 to reach CT1 in i/o table
  453.     LD    A,47H
  454.     LD    (HL),A
  455.     INC    HL        ; Move to next location
  456.     LD    A,(BSAVE1)    ; Get first table value
  457.     LD    (HL),A        ; Store it
  458.     LD    A,(BSAVE2)    ; Get second table value
  459.     LD    B,A        ; And save it
  460.     LD    L,SIOB1        ; Move ahead to siob+1 values
  461.     LD    A,(HL)        ; Get current value
  462.     AND    3FH
  463.     OR    B        ; Or it with second value
  464.     LD    (HL),A        ; Store it in work table
  465.     INC    HL
  466.     INC    HL
  467.     LD    A,(HL)        ; Get last value and make
  468.     OR    80H        ; Sure msb is set
  469.     LD    (HL),A        ; Put it back in working table
  470.     CALL    IOINIT        ; Do the initialization
  471.     SCF
  472.     CCF            ; Return no error for STBAUD
  473. PBEXIT:    POP    BC        ; All done
  474.     POP    DE
  475.     POP    HL
  476.     RET
  477.  
  478. IOINIT:    LD    A,IOINT        ; Offset into bios jump table
  479.     LD    HL,(BIOSADDR)    ; Address of bios in HL
  480.     LD    L,A        ; Add offset
  481.     JP    GOHL        ; And go there with auto return
  482.  
  483. ; table of baud rate divisors for supported rates
  484.  
  485. BAUDTB:    DB    0,208,139,208,0,104 ; 110,300,450,600,710,1200
  486.     DB    52,26,13,0    ; 2400,4800,9600,19200
  487.  
  488. BAUDTX:    DB    0,80H,80H,40H,0,40H
  489.     DB    40H,40H,40H,0
  490.  
  491. BSAVE1:    DB    0        ; Current setting from
  492. BSAVE2:    DB    0        ; Tables - uninitialized
  493.  
  494. ; Sign-on message
  495.  
  496. SYSVER:    LD    DE,SOMESG
  497.     LD    C,PRINT
  498.     CALL    MEX
  499.     RET
  500.  
  501. SOMESG:    DB    'Ampro Overlay Version '
  502.     DB    REV/10+'0'
  503.     DB    '.'
  504.     DB    REV MOD 10+'0'
  505.     DB    ' (nz-com compatible)'
  506.     DB    CR,LF,'$'
  507.  
  508. ; Newline on console
  509.  
  510. CRLF:    LD    A,CR
  511.     CALL    TYPE
  512.     LD    A,LF        ; Fall into TYPE
  513.  
  514. ; type char in A on console
  515.  
  516. TYPE:    PUSH    HL        ; Save 'em
  517.     PUSH    DE
  518.     PUSH    BC
  519.     LD    E,A        ; Align output character
  520.     LD    C,CONOUT    ; Print via MEX
  521.     CALL    MEX
  522.     POP    BC
  523.     POP    DE
  524.     POP    HL
  525.     RET
  526.  
  527. ; Data area
  528.  
  529. ;------------------------------------------------------------
  530.  
  531. ; The remainder of this overlay implements a very versatile
  532. ; SET command -- if you prefer not to write a SET for your
  533. ; modem, you may delete the code from here to the END statement.
  534.  
  535. ; Control is passed here after MEX parses a SET command.
  536.  
  537. SETCMD:    LD    C,SBLANK    ; Any arguments?
  538.     CALL    MEX
  539.     JP    C,SETSHO    ; If not, go print out values
  540.     LD    DE,CMDTBL    ; Parse command
  541.     CALL    TSRCH        ; From table
  542.     PUSH    HL        ; Any address on stack
  543.     RET    NC        ; If we have one, execute it
  544.     POP    HL        ; Nope, fix stack
  545. SETERR:    LD    DE,SETEMS    ; Print error
  546.     LD    C,PRINT
  547.     CALL    MEX
  548.     RET
  549.  
  550. SETEMS:    DB    CR,LF,'SET command error',CR,LF,'$'
  551.  
  552. ; SET command table ... note that tables are constructed of command-
  553. ; name (terminated by high bit=1) followed by word-data-value returned
  554. ; in HL by MEX service processor LOOKUP.  Table must be terminated by
  555. ; a binary zero.
  556.  
  557. ; Note that LOOKUP attempts to find the next item in the input stream
  558. ; in the table passed to it in HL ... if found, the table data item is
  559. ; returned in HL; if not found, LOOKUP returns carry set.
  560.  
  561. CMDTBL:    DB    '?'+80H        ; "set ?"
  562.     DW    STHELP
  563.     DB    'BAU','D'+80H    ; "set baud"
  564.     DW    STBAUD
  565.     DB    'BIT','S'+80H    ; "set bits"
  566.     DW    STBITS
  567.     DB    'PARIT','Y'+80H    ; "set parity"
  568.     DW    STPAR
  569.     DB    'STO','P'+80H    ; "set stop"
  570.     DW    STSTOP
  571.     DB    'SHAK','E'+80H    ; "set shake"
  572.     DW    STSHAK
  573.  
  574.     DB    0        ; <<=== table terminator
  575.  
  576. ; SET <no-args>: print current statistics
  577.  
  578. SETSHO:    LD    HL,SHOTBL    ; Get table of SHOW subroutines
  579. SETSLP:    LD    E,(HL)        ; Get table address
  580.     INC    HL
  581.     LD    D,(HL)
  582.     INC    HL
  583.     LD    A,D        ; End of table?
  584.     OR    E
  585.     RET    Z        ; Exit if so
  586.     PUSH    HL        ; Save table pointer
  587.     EX    DE,HL        ; Adrs to HL
  588.     CALL    GOHL        ; Do it
  589.     CALL    CRLF        ; Print newline
  590.     LD    C,CHEKCC    ; Check for console abort
  591.     CALL    MEX
  592.     POP    HL        ; It's done
  593.     JP    NZ,SETSLP    ; Continue if no abort
  594.     RET
  595.  
  596. GOHL:    JP    (HL)
  597.  
  598. ; table of SHOW subroutines
  599.  
  600. SHOTBL:    DW    BDSHOW
  601.     DW    BITSH
  602.     DW    PARSH
  603.     DW    STPSH
  604.     DW    SHKSH
  605.     DW    0        ; <<== table terminator
  606.  
  607. ; SET ?  processor
  608.  
  609. STHELP:    LD    DE,HLPMSG
  610.     LD    C,PRINT
  611.     CALL    MEX
  612.     RET
  613.  
  614. ; The help message
  615.  
  616. HLPMSG:    DB    CR,LF,'SET command, Ampro version:',CR,LF
  617.     DB    CR,LF,'  >SET BAUD 300, 450, 600, 1200, 2400, 4800, or 9600.'
  618.     DB    CR,LF,'  >SET BITS 5, 6, 7, or 8.'
  619.     DB    CR,LF,'  >SET PARITY ODD, EVEN, or NONE.'
  620.     DB    CR,LF,'  >SET STOP 1, or 2.'
  621.     DB    CR,LF,'  >SET SHAKE ON, or OFF.'
  622.     DB    CR,LF,CR,LF,'$'
  623.  
  624. ; SET BAUD processor
  625.  
  626. STBAUD:    LD    C,BDPARS    ; Function code
  627.     CALL    MEX        ; Let MEX look up code
  628.     JP    C,SETERR    ; Invalid code
  629.     CALL    PBAUD        ; No, try to set it
  630.     JP    C,SETERR    ; Not-supported code
  631. BDSHOW:    CALL    ILPRT        ; Display baud
  632.     DB    '  Baud rate: ',0
  633.     LD    A,(MSPEED)
  634.     LD    C,PRBAUD    ; Use MEX routine
  635.     CALL    MEX
  636.     RET
  637.  
  638. ; SET BITS processor
  639.  
  640. STBITS:    LD    DE,BITTBL    ; Load lookup table
  641.     CALL    TSRCH        ; Look for 7 or 8
  642.     JP    C,SETERR    ; If not found
  643.     LD    C,L        ; Save selection value
  644.     LD    HL,(BIOSADDR)    ; Get bios address
  645.     LD    L,SIOB3        ; Move to siob+3
  646.     LD    A,(HL)        ; Wr5 info 
  647.     AND    9FH        ; Mask
  648.     OR    C        ; Add selection
  649.     LD    (HL),A        ; Store it
  650.     LD    A,C        ; Get selection
  651.     RLA
  652.     LD    C,A        ; Shift selection left
  653.     LD    L,SIOB5        ; Move to siob+5
  654.     LD    A,(HL)        ; Wr3 info
  655.     AND    3FH        ; Mask
  656.     OR    C
  657.     LD    (HL),A        ; Store it
  658.     CALL    IOINIT        ; Do it.
  659.  
  660. BITSH:    CALL    ILPRT
  661.     DB    '  Data bits: ',0
  662.     LD    HL,(BIOSADDR)    ; Get bios location
  663.      LD    L,SIOB3        ; Move to siob+3
  664.     LD    A,(HL)        ; Get current value
  665.     AND    60H
  666.     CP    60H
  667.     JP    Z,BITSH8
  668.     CP    20H
  669.     JP    Z,BITSH7
  670.     CP    40H
  671.     JP    Z,BITSH6
  672.     CALL    ILPRT
  673.     DB    '5',0        ; Show a 5
  674.     RET
  675. BITSH6:    CALL    ILPRT
  676.     DB    '6',0        ; Show a 6
  677.     RET
  678. BITSH7:    CALL    ILPRT
  679.     DB    '7',0        ; Show a 7
  680.     RET
  681. BITSH8:    CALL    ILPRT
  682.     DB    '8',0
  683.     RET
  684.  
  685. BITTBL:    DB    '5'+80H
  686.     DW    00H
  687.     DB    '6'+80H
  688.     DW    40H
  689.     DB    '7'+80H
  690.     DW    20H
  691.     DB    '8'+80H
  692.     DW    60H
  693.     DB    0
  694. ;
  695. STPAR:    LD    DE,PARTBL
  696.     CALL    TSRCH
  697.     JP    C,SETERR
  698.     LD    C,L
  699.     LD    HL,(BIOSADDR)    ; Get bios address
  700.     LD    L,SIOB1        ; Go to siob+1
  701.     LD    A,(HL)
  702.     AND    0FCH
  703.     OR    C
  704.     LD    (HL),A
  705.     CALL    IOINIT
  706.  
  707. PARSH:    CALL    ILPRT
  708.     DB    '     Parity: ',0
  709.     LD    HL,(BIOSADDR)    ; Get bios address
  710.     LD    L,SIOB1
  711.     LD    A,(HL)
  712.     AND    03H        ; Mask
  713.     CP    01H        ; Check for none
  714.     JP    Z,PARSHO
  715.     CP    03H
  716.     JP    Z,PARSHE
  717.  
  718.     CALL    ILPRT
  719.     DB    'none',0
  720.     RET
  721.  
  722. PARSHO:    CALL    ILPRT
  723.     DB    'odd',0
  724.     RET
  725. PARSHE:    CALL    ILPRT
  726.     DB    'even',0
  727.     RET
  728.  
  729. PARTBL:    DB    'OD','D'+80H
  730.     DW    01H
  731.     DB    'EVE','N'+80H
  732.     DW    03H
  733.     DB    'NON','E'+80H
  734.     DW    00H
  735.     DB    0
  736.  
  737. STSTOP:    LD    DE,STPTBL
  738.     CALL    TSRCH
  739.     JP    C,SETERR
  740.     LD    C,L
  741.     LD    HL,(BIOSADDR)    ; Get bios address
  742.     LD    L,53H        ; Shift to bios+1
  743.     LD    A,(HL)
  744.     AND    0F3H
  745.     OR    C
  746.     LD    (HL),A
  747.     CALL    IOINIT
  748.  
  749. STPSH:    CALL    ILPRT
  750.     DB    '  Stop bits: ',0
  751.     LD    HL,(BIOSADDR)    ; Get bios address
  752.     LD    L,53H        ; Shift to bios+1
  753.     LD    A,(HL)
  754.     AND    0CH
  755.     CP    0CH
  756.     JP    Z,STPSH2
  757.     CALL    ILPRT
  758.     DB    '1',0
  759.     RET
  760. STPSH2:    CALL    ILPRT
  761.     DB    '2',0
  762.     RET
  763. STPTBL:    DB    '1'+80H
  764.     DW    04H
  765.     DB    '2'+80H
  766.     DW    0CH
  767.     DB    0
  768.  
  769. STSHAK:    LD    DE,SHKTBL    ; Get handshake table
  770.     CALL    TSRCH        ; Search it for parameter
  771.     JP    C,SETERR    ; If not found
  772.     LD    C,L        ; Temp store value in C
  773.     LD    HL,(BIOSADDR)    ; Get location of BIOS
  774.     LD    L,6DH        ; Location of HSB in bios
  775.     LD    (HL),C        ; Put new value in it
  776.  
  777. SHKSH:    CALL    ILPRT
  778.     DB    ' Hand Shake: ',0
  779.     LD    HL,(BIOSADDR)    ; Get bios location
  780.     LD    L,6DH        ; Location of HSB in bios
  781.     LD    A,(HL)        ; Get current value
  782.     CP    1
  783.     JP    Z,SHKSHY    ; Show a yes
  784.     CALL    ILPRT
  785.     DB    'off',0
  786.     RET
  787. SHKSHY:    CALL    ILPRT
  788.     DB    'on',0
  789.     RET
  790.  
  791. SHKTBL:    DB    'OF','F'+80H
  792.     DW    0
  793.     DB    'O','N'+80H
  794.     DW    1
  795.     DB    0
  796.  
  797. ;----------------------------------------------------------
  798.  
  799. ; Compare next input-stream item in table @DE; CY=1
  800. ; if not found, else HL=matched data item
  801.  
  802. TSRCH:    LD    C,LOOKUP    ; Get function code
  803.     JP    MEX        ; Pass to MEX processor
  804.  
  805. ; Print in-line message ... blows away C register
  806.  
  807. ILPRT:    LD    C,ILP        ; Get function code
  808.     JP    MEX        ; Go do it
  809.  
  810. ;------------------------------------------------------------
  811. ; This is a callable routine that locates the bios address
  812. ; whether nz-com is running or not and saves it in the word
  813. ; at "biosaddr:". It gets run once at mex initialization.
  814. ; All points in the code that used to get this address from
  815. ; location one now get it from the located and saved address.
  816.  
  817. GRABBIOS:
  818.     PUSH    HL        ; save time
  819.     PUSH    DE
  820.     PUSH    BC
  821.     PUSH    AF
  822.     LD    HL,(1)        ; this is SOME bios address..
  823.     LD    DE,57H        ; ptr to "NZ-COM" eyecatcher
  824.     ADD    HL,DE        ; look for expected eyecatcher here
  825.     LD    DE,NZCEYE    ; ptr to another copy of it
  826.     LD    B,6        ; length
  827.  
  828. NZCKLOOP:
  829.     LD    A,(DE)        ; get a char
  830.     CP    (HL)        ; compare to char at hl
  831.     JR    NZ,NONZC    ; no nz-com
  832.     INC    HL        ; bump ptr
  833.     INC    DE        ; bump ptr
  834.     DEC    B        ; decrement length
  835.     JR    NZ,NZCKLOOP    ; repeat if apropos
  836.  
  837.     LD    HL,(1)        ; pick up bios pointer again
  838.     LD    DE,84H        ; offset to BIOS page address in
  839.                 ; first entry in NZ-COM's 
  840.                 ; second-level jump table
  841.     ADD    HL,DE
  842.     LD    A,(HL)        ; get bios page
  843.     JR    RETBIOS        ; and return bios addr in biosaddr
  844.  
  845. NONZC:
  846.     LD    A,(2)        ; get original page number
  847.  
  848. RETBIOS:
  849.     LD    (BIOSADDR+1),A    ; save page
  850.     POP    AF        ; restore regs
  851.     POP    BC
  852.     POP    DE
  853.     POP    HL
  854.     RET
  855.  
  856. NZCEYE:
  857.     DB    'NZ-COM'    ; eyecather to match
  858.  
  859. BIOSADDR:
  860.     DW    3        ; just need to set page
  861.  
  862. ;------------------------------------------------------------
  863.  
  864. ; End of AMPRO MEX modem overlay
  865.  
  866. ;------------------------------------------------------------
  867.  
  868.     END
  869.