home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / mex / mxm-mm3.asm < prev    next >
Encoding:
Assembly Source File  |  1994-07-13  |  30.4 KB  |  904 lines

  1. ; MXM-MM3.ASM
  2. ;
  3. REV     EQU     30              ;overlay revision level
  4. ;
  5. ; MEX Micromodem II/IIe overlay for the APPLE II/II+/IIe;
  6. ;       written 09/04/84 by Joe Patterson (70235,460)
  7. ;               adapted from
  8. ;
  9. ; MEX Apple Super Serial Card / Novation J-Cat overlay
  10. ;       written 05/18/84 by D. W. Walker
  11. ;       ALS bank-switching adapted from
  12. ;       an overlay by James M. Scardelis
  13. ;
  14. ; Revn: 1.0  04 Sept 84 -- Modified MXO-AP.21 to produce this
  15. ;                           overlay.
  16. ;       2.0  09 SEPT 84 -- ADDED TOUCH-TONE DIALING FOR THE
  17. ;                          MICROMODEM IIE (ONLY)
  18. ;                       -- RENAMED TO MXMM-2.ASM FROM MXO-MM10.ASM
  19. ;                       -- ADDED CONTROL PORT 3 JUMP FOR THE
  20. ;                          SOFTCARD (COULD NOT USE MMIIE ON 
  21. ;                          SOFTCARD OTHERWISE);
  22. ;       3.0  05 Nov  84 -- ADDED "SET ANSWER" COMMAND TO ENABLE
  23. ;                          MICROMODEM TO AUTO-ANSWER
  24. ;                       -- ADDED SUPPORT FOR THE PCPI APPLICARD
  25. ;
  26. ;
  27. ; This overlay is for the MEX--- series of modem programs. It is
  28. ;   adapted from MXO-AP.21 to work with the APPLE II and the
  29. ;   Hayes Micromodem II and IIe with either the ALS CP/M CARD
  30. ;   or the Microsoft Softcard. Data format is 8 bits, no parity,
  31. ;   1 stop bit. If you have the Micromodem IIe then answer YES
  32. ;   to --BOTH-- equates MM and MM2e to turn the speaker on when
  33. ;   dialing and off when connected. If you have the Micromodem II
  34. ;   then you must --NOT-- answer yes to the MM2e equate as the
  35. ;   program will probably bomb out if you do.
  36. ;
  37. ; Revision 2.0 now supports touch-tone dialing on the Micromodem
  38. ;   IIe (ONLY) if you answer YES to the MM2E equate. When using
  39. ;   touch-tone, the comma (,) feature is supported. Inserting a
  40. ;   comma in the number being dialed, causes a 2 second delay for
  41. ;   each one used. For example, 555-12,34 causes dialing to pause
  42. ;   for 2 seconds between digits 2 and 3. This is especially useful
  43. ;   when waiting for an outside line or a second dial tone. Multiple
  44. ;   commas can be used.
  45. ;
  46. ; Revision 3.0 now supports Auto-Answer with the Micromodem (II or IIe).
  47. ;  Using the SET ANSWER command, will put the Micromodem directly in
  48. ;  answer mode. At this point, the modem is waiting for the phone to
  49. ;  ring. When it does ring the modem will answer and listen for a 
  50. ;  carrier from the other end. If no carrier is detected within 15
  51. ;  seconds, the it will hang up and wait for another call. If a
  52. ;  carrier is detected, you will be put back in the MEX command
  53. ;  mode. To drop into terminal mode after the modem has detected a
  54. ;  carrier type SET ANSWER;T. The Auto-Answer mode is quite useful for
  55. ;  unattended operation. Using the READ command, you can put the modem
  56. ;  in Auto-Answer mode and when a connection is made the rest of the
  57. ;  commands in the READ file are executed.
  58. ;
  59. ; This revision (3.0) also supports the PCPI APPLICARD. All features
  60. ;  of the Micromodem are available.
  61. ;
  62. ; I have tested this overlay and it seems to work ok, but, if
  63. ;   anyone finds any let me know and I will try to correct them
  64. ;   as soon as possible.
  65. ;
  66. ;
  67. ; The SET WAIT command adjusts the time that the dialing
  68. ;   routines will wait for a connection (carrier), from
  69. ;   0 to 25 seconds.
  70. ; NOTE: Most of the comments from Ron Fowler's MXO-PM10.ASM
  71. ;   have been omitted here to save space.  A copy of that file
  72. ;   will be very helpful in understanding what's going on here. 
  73. ;
  74. ;------------------------------------------------------------
  75. ;
  76. ; Misc equates
  77. ;
  78. NO      EQU     0
  79. YES     EQU     0FFH
  80. TPA     EQU     100H
  81. CR      EQU     13
  82. LF      EQU     10
  83. BELL    EQU     7
  84. TAB     EQU     9
  85. ESC     EQU     27
  86. ;         
  87. MM      EQU     YES     ;YES FOR HAYES MICROMODEM II
  88. MM2E    EQU     NO      ;YES FOR MM2E ONLY (FOR TOUCH-TONE & SPEAKER)
  89.                         ;MUST BE NO IF YOU HAVE THE MICROMODEM II
  90. SFTCRD  EQU     YES     ;YES for Microsoft Softcard } choose
  91. ALSCRD  EQU     NO      ;YES for ALS CP/M+ card     } one only
  92. APPCRD  EQU     NO      ;YES FOR PCPI APPLICARD     }
  93.         IF SFTCRD
  94. POFF    EQU     2000H   ;Softcard address offset
  95. RATE    EQU     20
  96.         ENDIF
  97. ;
  98. ; IF YOU ARE USING THE APPLICARD BE SURE TO CHANGE THE RATE EQUATE
  99. ; TO REFLECT YOUR CARD'S SPEED. EX. 60=6MHZ, 40=4MHZ.
  100. ;
  101.         IF ALSCRD OR APPCRD
  102. POFF    EQU     0
  103. RATE    EQU     60
  104.         ENDIF
  105. ;
  106.         IF      MM
  107. SLOT    EQU     20H             ;SLOT FOR MICROMODEM X 10
  108. PORT    EQU     0C086H+POFF+SLOT  ;BASE CTL/STAT PORT FOR MM
  109. MODDAT  EQU     PORT+1          ;MM DATA PORT
  110. MODSTT  EQU     PORT            ;MM STATUS PORT
  111. MODCTL  EQU     PORT            ;MM CTL PORT 1
  112. BAUDRP  EQU     PORT-1          ;MM CTL PORT 2
  113. MODCTL3:EQU     PORT-3          ;MM2e CONTROL PORT 3
  114. ;
  115. ;
  116. MDRCVB  EQU     01H     ;MM RECIEVE BIT
  117. MDRCVR  EQU     01H     ;MM RECIEVE READY BIT
  118. MDSNDB  EQU     02H     ;MM SEND BIT
  119. MDSNDR  EQU     02H     ;MM SEND READY BIT
  120. ;
  121. DTR     EQU     8FH             ;TRANS ENABLE, ORIG., 300 BAUD
  122. OFFHK   EQU     80H             ;OFF-HOOK
  123. ONHK    EQU     0               ;ON-HOOK
  124. SPKRON  EQU     00100000B       ;MMIIe SPEAKER ON
  125. SPKROFF EQU     00000000B       ;MMIIe SPEAKER OFF
  126. ;
  127. CTSMSK  EQU     00000000B         ;MASK TO TEST FOR CARRIER
  128. BRKMSK  EQU     60H               ;MASK TO SET BREAK
  129. ONHOOK  EQU     0C085H+POFF+SLOT  ;ADDRESS FOR ONHOOK SET
  130. OFFHOOK EQU     ONHOOK            ;OFFHOOK ADDRESS
  131.         ENDIF   ;MM
  132. ;
  133. ;
  134. ;
  135. ; MEX service processor stuff ... See MXO-PM10.ASM
  136. ;
  137. MEX     EQU     0D00H           ;address of the service processor
  138. INMDM   EQU     255             ;get char from port to A, CY=no more in 100 ms
  139. TIMER   EQU     254             ;delay 100ms * reg B
  140. TMDINP  EQU     253             ;B=# secs to wait for char, cy=no char
  141. CHEKCC  EQU     252             ;check for ^C from KBD, Z=present
  142. SNDRDY  EQU     251             ;test for modem-send ready
  143. RCVRDY  EQU     250             ;test for modem-receive ready
  144. SNDCHR  EQU     249             ;send a character to the modem (after sndrdy)
  145. RCVCHR  EQU     248             ;recv a char from modem (after rcvrdy)
  146. LOOKUP  EQU     247             ;table search: see CMDTBL comments for info
  147. PARSFN  EQU     246             ;parse filename from input stream
  148. BDPARS  EQU     245             ;parse baud-rate from input stream
  149. SBLANK  EQU     244             ;scan input stream to next non-blank
  150. EVALA   EQU     243             ;evaluate numeric from input stream
  151. LKAHED  EQU     242             ;get nxt char w/o removing from input
  152. GNC     EQU     241             ;get char from input, cy=1 if none
  153. ILP     EQU     240             ;inline print
  154. DECOUT  EQU     239             ;decimal output
  155. PRBAUD  EQU     238             ;print baud rate
  156. ;
  157. ;
  158. CONOUT  EQU     2               ;simulated BDOS function 2: console char out
  159. PRINT   EQU     9               ;simulated BDOS function 9: print string
  160. INBUF   EQU     10              ;input buffer, same structure as BDOS 10
  161. ;
  162.         ORG     TPA             ;we begin
  163. ;
  164. ;
  165.         DS      3               ;MEX has a JMP START here
  166. ;
  167. ; The following variables are located at the beginning of the program
  168. ; to facilitate modification without the need of re-assembly. They will
  169. ; be moved in MEX 2.0.
  170. ;
  171. PMODEM: DB      YES             ;yes=PMMI modem \ / These 2 locations are not
  172. SMODEM: DB      NO              ;yes=Smartmodem / \ referenced by MEX
  173. TPULSE: DB      'P'             ;T=touch, P=pulse (not referenced by MEX)
  174. CLOCK:  DB      RATE            ;clock speed x .1, up to 25.5 mhz.
  175. MSPEED: DB      1               ;sets display time for sending a file
  176.                                 ;0=110  1=300  2=450  3=600  4=710
  177.                                 ;5=1200 6=2400 7=4800 8=9600 9=19200
  178. BYTDLY: DB      5               ;default time to send character in
  179.                                 ;terminal mode file transfer (0-9)
  180.                                 ;0=0 delay, 1=10 ms, 5=50 ms, 9=90 ms
  181. CRDLY:  DB      3               ;end-of-line delay after CRLF in terminal
  182.                                 ;mode file transfer for slow BBS systems
  183.                                 ;0=0 delay, 1=100 ms, 5=500 ms, 9=900 ms
  184. COLUMS: DB      5               ;number of directory columns
  185. SETFL:  DB      YES             ;yes=user-defined SET command
  186. SCRTST: DB      YES             ;yes=if home cursor and clear screen
  187.                                 ;routine at CLRSCRN
  188.         DB      0               ;was once ACKNAK, now spare
  189. BAKFLG: DB      NO              ;yes=make .BAK file
  190. CRCDFL: DB      YES             ;yes=default to CRC checking
  191.                                 ;no=default to Checksum checking
  192. TOGCRC: DB      YES             ;yes=allow toggling of Checksum to CRC
  193. CVTBS:  DB      NO              ;yes=convert backspace to rub
  194. TOGLBK: DB      YES             ;yes=allow toggling of bksp to rub
  195. ADDLF:  DB      NO              ;no=no LF after CR to send file in
  196.                                 ;terminal mode (added by remote echo)
  197. TOGLF:  DB      YES             ;yes=allow toggling of LF after CR
  198. TRNLOG: DB      NO              ;yes=allow transmission of logon
  199.                                 ;write logon sequence at location LOGON
  200. SAVCCP: DB      YES             ;yes=do not overwrite CCP
  201. LOCNXT: DB      NO              ;yes=local cmd if EXTCHR precedes
  202.                                 ;no=not local cmd if EXTCHR precedes
  203. TOGLOC: DB      YES             ;yes=allow toggling of LOCNXTCHR
  204. LSTTST: DB      YES             ;yes=allow toggling of printer on/off
  205.                                 ;in terminal mode. Set to no if using
  206.                                 ;the printer port for the modem
  207. XOFTST: DB      NO              ;yes=allow testing of XOFF from remote
  208.                                 ;while sending a file in terminal mode
  209. XONWT:  DB      NO              ;yes=wait for XON after sending CR while
  210.                                 ;transmitting a file in terminal mode   
  211. TOGXOF: DB      YES             ;yes=allow toggling of XOFF testing
  212. IGNCTL: DB      YES             ;yes=do not send control characters
  213.                                 ;above CTL-M to CRT in terminal mode
  214.                                 ;no=send any incoming CTL-char to CRT
  215. EXTRA1: DB      0               ;for future expansion
  216. EXTRA2: DB      0               ;for future expansion
  217. BRKCHR: DB      '@'-40H         ;^@ = Send a 300 ms. break tone
  218. NOCONN: DB      'N'-40H         ;^N = Disconnect from phone line
  219. LOGCHR: DB      'L'-40H         ;^L = Send logon
  220. LSTCHR: DB      'P'-40H         ;^P = Toggle printer
  221. UNSVCH: DB      'R'-40H         ;^R = Close input text buffer
  222. TRNCHR: DB      'T'-40H         ;^T = Transmit file to remote
  223. SAVCHR: DB      'Y'-40H         ;^Y = Open input text buffer
  224. EXTCHR: DB      '^'-40H         ;^^ = Send next character
  225. ;
  226.         DS      2
  227. ;
  228. INCTL1: CALL    XSTTIN          ;in modem status port
  229.         RET
  230.         DB      0,0,0,0,0,0     ;spares if needed
  231. ;                   
  232. OTDATA: CALL    XDATOUT         ;out modem data port
  233.         RET
  234.         DB      0,0,0,0,0,0     ;spares if needed
  235. ;
  236. INPORT: CALL    XDATIN          ;in modem data port
  237.         RET
  238.         DB      0,0,0,0,0,0     ;spares if needed
  239. ;
  240. MASKR:  ANI MDRCVB ! RET        ;bit to test for receive ready
  241. TESTR:  CPI MDRCVR ! RET        ;value of receive bit when ready
  242. MASKS:  ANI MDSNDB ! RET        ;bit to test for send ready
  243. TESTS:  CPI MDSNDR ! RET        ;value of send bit when ready
  244. ;
  245. ;
  246.         DS      12
  247. ;
  248. ;
  249. LOGON:  DS      2               ;needed for MDM compat, not ref'd by MEX
  250. DIALV:  JMP     PDIAL           ;dial digit in A (see info at PDIAL)
  251. DISCV:  JMP     PDISC           ;disconnect the modem
  252. GOODBV: JMP     DUMMY           ;called before exit to CP/M
  253. INMODV: JMP     NITMOD          ;initialization. Called at cold-start
  254. NEWBDV: JMP     PBAUD           ;set baud rate
  255. NOPARV: DS      3               ;set modem for no-parity
  256. PARITV: DS      3               ;set modem parity
  257. SETUPV: JMP     SETCMD          ;SET cmd: jump to a RET if you don't write SET
  258. SPMENV: DS      3               ;not used with MEX
  259. VERSNV: JMP     SYSVER          ;Overlay's voice in the sign-on message
  260. BREAKV: JMP     PBREAK          ;send a break
  261. ;
  262. ;
  263. ILPRTV: DS      3               ;replace with MEX function 9
  264. INBUFV: DS      3               ;replace with MEX function 10
  265. ILCMPV: DS      3               ;replace with table lookup funct. 247
  266. INMDMV: DS      3               ;replace with MEX function 255
  267. NXSCRV: DS      3               ;not supported by MEX (returns w/no action)
  268. TIMERV: DS      3               ;replace with MEX function 254
  269. ;
  270. CLREOS: LXI     D,EOSMSG
  271.         MVI     C,PRINT
  272.         CALL    MEX
  273.         RET
  274. ;
  275. CLS:    LXI     D,CLSMSG
  276.         MVI     C,PRINT
  277.         CALL    MEX
  278.         RET
  279. ;
  280. ;------------------------------------------------------------
  281. ;
  282. ;       *** END OF FIXED FORMAT AREA ***
  283. ;
  284. ;------------------------------------------------------------
  285. ;
  286. ; MICROMODEM AND ALS CARD INITIALIZATION
  287. ;
  288. NITMOD: 
  289.         IF ALSCRD
  290.         LHLD    1               ;get WBOOT vector
  291.         LXI     D,60H           ;offset for 32 entries
  292.         DAD     D               ;BIOS "read Apple address"
  293.         SHLD    AR0+1           ;patch read vector
  294.         INX     H
  295.         INX     H
  296.         INX     H               ;BIOS "write Apple address"
  297.         SHLD    AW0+1           ;patch write vector
  298.         ENDIF
  299.  
  300. ;
  301.         IF      MM
  302.         MVI     A,03H
  303.         CALL    XCTLOUT         ;RESET MICROMODEM
  304.         MVI     A,15H           ;8 DATA BITS 1 STOP NO PARITY
  305.         CALL    XCTLOUT
  306.         RET
  307.         ENDIF   ;MM
  308. ;
  309. ; Micromodem send-break routine
  310. ;
  311. PBREAK: CALL    XCTLIN          ;get control register
  312.         PUSH    PSW             ;save it
  313.         ORI     BRKMSK          ;set break bits
  314.         CALL    XCTLOUT         ;break line
  315.         PUSH    B
  316.         LXI     B,233           ;wait 233 msec
  317.         CALL    DELAY
  318.         POP     B
  319.         POP     PSW
  320.         CALL    XCTLOUT         ;restore control register 
  321.         RET
  322. ;
  323. ; disconnect the Micromodem (and turn off MMIIe speaker)
  324. ;
  325. PDISC:  PUSH    B
  326. ;
  327.         IF      MM2E
  328.         MVI     A,SPKROFF
  329.         CALL    XCTL3           ;SPEAKER OFF
  330.         ENDIF                   ;MM2E
  331. ;
  332.         MVI     A,ONHK
  333.         CALL    XONHOOK         ;hang up
  334.         LXI     B,25            ;for 25 msec
  335.         CALL    DELAY
  336.         MVI     A,OFFHK
  337.         CALL    XOFFHK          ;pick up again
  338.         LXI     B,20            ;for 20 msec
  339.         CALL    DELAY
  340.         MVI     A,ONHK
  341.         CALL    XONHOOK         ;hang up for good
  342.         POP     B
  343.         RET
  344. ;
  345. ; wait for BC milliseconds
  346. ;
  347. DELAY:  PUSH    D
  348.         INR     B
  349. DELAY1: LXI     D,3*RATE        ;count for 1 msec
  350. DELAY2: DCX     D               ;..may need some tweaking
  351.         MOV     A,E
  352.         ORA     D
  353.         JNZ     DELAY2          ;delay 1 msec
  354.         DCR     C
  355.         JNZ     DELAY1          ;delay another
  356.         DCR     B
  357.         JNZ     DELAY1
  358.         POP     D               ;done, restore DE
  359.         RET
  360. ;
  361. ; exit routine
  362. ;
  363. DUMMY:  RET                     ;we don't need one
  364. ;
  365. ;
  366. ;------------------------------------------------------------
  367. ;
  368. ;   MICROMODEM DIALING ROUTINES (PULSE AND TOUCH-TONE)
  369. ;
  370. ;------------------------------------------------------------
  371. ;
  372. PDIAL:  CPI     254             ;start-dial?
  373.         JZ      STDIAL
  374.         CPI     255             ;end-dial
  375.         JZ      ENDIAL
  376. ;
  377.         CPI     ','             ;SEE IF DIGIT IS ','
  378.         JZ      DIALCM          ;YES
  379.         CPI     '9'+1           ;digits are 0-9
  380.         RNC                     ;too big...
  381.         SUI     '0'
  382.         RC                      ;too small....
  383.         JNZ     DIALIT          ;just right...
  384.         MVI     A,10            ;convert zero to 10 pulses
  385. ;
  386. ; Pulse phone "digit" times
  387. ;
  388.         IF      NOT MM2E
  389. DIALIT: MOV     E,A             ;save the digit
  390.         PUSH    B
  391. DIGLP:  MVI     A,ONHK
  392.         CALL    XONHOOK
  393.         LXI     B,65            ;for 65 msec
  394.         CALL    DELAY
  395.         MVI     A,OFFHK
  396.         CALL    XOFFHK          ;connect line
  397.         LXI     B,42            ;for 42 msec
  398.         CALL    DELAY
  399.         DCR     E               ;pulse again?
  400.         JNZ     DIGLP           ;yes, do it
  401.         MVI     B,3             ;300 MSEC BETWEEN DIGITS
  402.         MVI     C,TIMER
  403.         CALL    MEX
  404.         POP     B               ;no, exit
  405.         RET
  406.         ENDIF                   ;MM
  407. ;
  408. ;
  409.         IF      MM2E
  410. DIALIT: ADI     30H             ;ADD 30H TO DIGIT TO KEEP SPEAKER -
  411.         PUSH    B               ;ON AND SEND TONE
  412. DIGLP:  CALL    XCTL3           ;SEND DIGIT
  413.         LXI     B,120           ;NUMBER OF MSEC FOR EACH TONE
  414.         CALL    DELAY
  415.         MVI     A,20H           ;TURN OFF TONE
  416.         CALL    XCTL3
  417.         MVI     B,1             ;100 MSEC BTWEEN DIGITS
  418.         MVI     C,TIMER
  419.         CALL    MEX
  420.         POP     B
  421.         RET
  422.         ENDIF                   ;ENDIF MM2E
  423. ;
  424. ;
  425. ; THIS ROUTINE CONVERTS THE COMMA (,) TO IT'S MICROMODEM DECIMAL
  426. ;   EQUIVALENT. THE COMMA CAUSES A TWO (2) SECOND DELAY IN
  427. ;   DIALING BETWEEN ANY 2 DIGITS.
  428. ;
  429. ;
  430. DIALCM: MVI     B,20            ;DIGIT IS COMMA - SO WAIT 2 SEC.
  431.         MVI     C,TIMER
  432.         CALL    MEX
  433.         RET
  434. ;
  435. ;
  436. ; END OF SPECIAL DIALING CONVERSION ROUTINE
  437. ;
  438. ;
  439. ; Start-dial sequence: connect, wait for dial-tone
  440. ;
  441. STDIAL: CALL    ILPRT
  442.         DB      'Wait...',0
  443.         MVI     B,25            ;wait 2.5 sec
  444.         MVI     C,TIMER
  445.         CALL    MEX
  446.         MVI     A,DTR           ;enable modem
  447.         CALL    XBDOUT
  448.         ;
  449.         IF      MM2E
  450.         MVI     A,SPKRON
  451.         CALL    XCTL3           ;TURN ON MMIIE SPEAKER
  452.         ENDIF                   ;MM2E
  453.         ;
  454.         MVI     A,OFFHK
  455.         CALL    XOFFHK          ;connect phone
  456.         MVI     B,20            ;wait 2 sec
  457.         MVI     C,TIMER
  458.         CALL    MEX             ;for dial tone
  459.         ORA     A
  460.         RET
  461. ;
  462. ; End-dial sequence
  463. ;
  464. ENDIAL: MVI     E,150           ;SET WAIT TIME TO 15 SEC.
  465.         MVI     A,8DH           ;ENABLE MODEM (OFF-HOOK,ORIG.,300 BD)
  466.         CALL    XBDOUT
  467. WAITTM  EQU     $-1             ;patch with SET WAIT command
  468.         CALL    WAIT
  469.         ORA     A               ;successfully connected?
  470.         PUSH    PSW             ;save the error code
  471.         JNZ     NOTCNK          ;no, disconnect
  472.         MVI     A,DTR
  473.         CALL    XBDOUT          ;RE-ENABLE MODEM
  474.         ;
  475.         IF      MM2E
  476.         MVI     A,SPKROFF       ;MMIIE SPEAKER OFF
  477.         CALL    XCTL3
  478.         ENDIF                   ;MM2E
  479.         ;
  480.         JMP     DIALXIT 
  481. NOTCNK: CALL    PDISC           ;shut down the modem
  482. DIALXIT:POP     PSW
  483.         RET
  484. ;
  485. ; Time-out routine.  Must be called with mask in D reg.
  486. ; and number of seconds (times 10) in E reg.
  487. ;
  488. WAIT:   MVI     B,1             ;100 ms
  489.         MVI     C,TIMER 
  490.         CALL    MEX
  491.         CALL    XDATIN          ;READ DATA PORT (SET-UP CARR. DET.)
  492.         CALL    XSTTIN          ;IS CARRIER LOST SINCE LAST DATA READ?
  493.         ANI     4               ;4=NO CARRIER, 0=CARRIER
  494.         RZ                      ;active low, so return on 0
  495.         MVI     C,CHEKCC        ;not yet, check for console-abort
  496.         CALL    MEX             ;abort?
  497.         MVI     A,3             ;set error code 3 if abort active
  498.         STC
  499.         RZ                      ;return if aborted
  500.         DCR     E               ;nope, downcount
  501.         JNZ     WAIT
  502.         DCR     A               ;set error=2 (timed out); cy already set
  503.         RET
  504.  
  505. ;------------------------------------------------------------
  506. ;       END OF MICROMODEM DIALING ROUTINES
  507. ;------------------------------------------------------------
  508. ;
  509. ; Only 300 baud is supported for the Micromodem
  510. ;
  511. ;
  512.         IF      MM
  513. PBAUD:  RET
  514.         ENDIF   ;MM
  515. ;
  516. ;
  517. ; Control is passed here after MEX parses a SET command.
  518. ;
  519. SETCMD: MVI     C,SBLANK        ;any arguments?
  520.         CALL    MEX
  521.         JC      SETSHO          ;if not, go print out values
  522.         LXI     D,CMDTBL        ;parse command
  523.         CALL    TSRCH           ;from table
  524.         PUSH    H               ;any address on stack
  525.         RNC                     ;if we have one, execute it
  526.         POP     H               ;nope, fix stack
  527. SETERR: LXI     D,SETEMS        ;print error
  528.         MVI     C,PRINT
  529.         CALL    MEX
  530.         RET
  531. ;
  532. SETEMS: DB      CR,LF,BELL,'SET command error',CR,LF,'$'
  533. ;
  534. ; SET command table ... note that tables are constructed of command-
  535. ; name (terminated by high bit=1) followed by word-data-value returned
  536. ; in HL by MEX service processor LOOKUP.  Table must be terminated by
  537. ; a binary zero.
  538. ;
  539. ; Note that LOOKUP attempts to find the next item in the input stream
  540. ; in the table passed to it in HL ... if found, the table data item is
  541. ; returned in HL; if not found, LOOKUP returns carry set.
  542. ;
  543. CMDTBL: DB      '?'+80H                 ;"set ?"
  544.         DW      STHELP
  545.         DB      'BAU','D'+80H           ;"set baud"
  546.         DW      STBAUD
  547.         DB      'WAI','T'+80H           ;"set wait time"
  548.         DW      STWAIT
  549.         DB      'ANSWE','R'+80H         ;"set answer"
  550.         DW      ANSWER
  551.         DB      0               ;<<=== table terminator
  552. ;
  553. ; SET <no-args>: print current statistics
  554. ;
  555. SETSHO: CALL    CARRSH          ;show carrier present/not present
  556.         LXI     H,SHOTBL        ;get table of SHOW subroutines
  557. SETSLP: MOV     E,M             ;get table address
  558.         INX     H
  559.         MOV     D,M
  560.         INX     H
  561.         MOV     A,D             ;end of table?
  562.         ORA     E
  563.         RZ                      ;exit if so
  564.         PUSH    H               ;save table pointer
  565.         XCHG                    ;adrs to HL
  566.         CALL    GOHL            ;do it
  567.         CALL    CRLF            ;print newline
  568.         MVI     C,CHEKCC        ;check for console abort
  569.         CALL    MEX
  570.         POP     H               ;it's done
  571.         JNZ     SETSLP          ;continue if no abort
  572.         RET
  573. ;
  574. GOHL:   PCHL
  575. ;
  576. ; table of SHOW subroutines
  577. ;
  578. SHOTBL: DW      BDSHOW
  579.         DW      WTSHOW
  580.         DW      0               ;<<== table terminator
  581. ;
  582. ; SET ?  processor
  583. ;
  584. STHELP: LXI     D,HLPMSG
  585.         MVI     C,PRINT
  586.         CALL    MEX
  587.         RET
  588. ;
  589. ; The help message
  590. ;
  591. HLPMSG: DB      CR,LF,'SET command, MICROMODEM II/IIE version:',CR,LF
  592.         DB      CR,LF,TAB,'Set Answer - <use CTL-C to abort>'
  593.         DB      CR,LF,TAB,'Only 300 baud supported'
  594.         DB      CR,LF,TAB,'Set Wait 0..25 seconds'
  595.         DB      CR,LF,'$'
  596. ;
  597. ; SET BAUD processor
  598. ;
  599. STBAUD: MVI     C,BDPARS        ;function code
  600.         CALL    MEX             ;let MEX look up code
  601.         JC      SETERR          ;invalid code
  602.         CALL    PBAUD           ;no, try to set it
  603.         JC      SETERR          ;not-supported code
  604. BDSHOW: CALL    ILPRT           ;display baud
  605.         DB      'Baud rate: ',TAB,0
  606.         LDA     MSPEED
  607.         MVI     C,PRBAUD        ;use MEX routine
  608.         CALL    MEX
  609.         RET           
  610. ;
  611. ; SET ANSWER processor
  612. ;
  613. ANSWER: CALL    ILPRT
  614.         DB      CR,LF,'Micromodem awaiting call........',0
  615. ANSWER1:MVI     A,09H           ;get ready to answer phone
  616.         CALL    XBDOUT
  617. ANSWER2:MVI     C,CHEKCC        ;check for console abort
  618.         CALL    MEX
  619.         RZ                      ;return if aborted
  620.         CALL    XBDIN           ;see if phone is ringing
  621.         ANI     80H
  622.         JNZ     ANSWER2         ;it isn't so, continue to listen
  623.         CALL    ILPRT           ;print "modem answering"
  624.         DB      BELL,CR,LF,'Micromodem answering.......',0
  625.         MVI     A,8BH           ;go off-hook and send answer tone
  626.         CALL    XBDOUT
  627.         MVI     E,150           ;wait 15s for carrier on other end
  628. PICKUP: MVI     B,1             ;100ms
  629.         MVI     C,TIMER
  630.         CALL    MEX
  631.         CALL    XDATIN          ;dummy data read
  632.         CALL    XSTTIN          ;is there a tone on the other end ?
  633.         ANI     4
  634.         JZ      CDET            ;jump to "cdet" if carrier detected
  635.         MVI     C,CHEKCC        ;check for console abort
  636.         CALL    MEX
  637.         RZ                      ;if abort
  638.         DCR     E               ;nope, countdown
  639.         JNZ     PICKUP
  640.         CALL    ILPRT           ;print "no carrier"
  641.         DB      CR,LF,'No carrier - waiting for another call.....',0
  642.         JMP     ANSWER1         ;continue waiting for a call
  643. CDET:   CALL    ILPRT
  644.         DB      BELL,CR,LF,'Carrier detected......',0
  645.         RET
  646. ;
  647. ;
  648. ; SET WAIT processor
  649. ;
  650. STWAIT: MVI     C,EVALA         ;get new time from input
  651.         CALL    MEX
  652.         MOV     A,H             ;check for valid input
  653.         ORA     A
  654.         JNZ     SETERR
  655.         MOV     A,L
  656.         CPI     26
  657.         JNC     SETERR          ;25 is maximum wait
  658.         RLC                     ;x 2
  659.         MOV     C,A
  660.         RLC                     ;x 4
  661.         RLC                     ;x 8
  662.         ADD     C               ;x 10
  663.         STA     WAITTM
  664. WTSHOW: CALL    ILPRT
  665.         DB      'Wait time: ',TAB,0
  666.         MVI     A,0             ;clear HL
  667.         MOV     L,A
  668.         MOV     H,A
  669.         LDA     WAITTM
  670. SBLOOP: SUI     10              ;div. by 10
  671.         JC      WTDSP
  672.         INR     L
  673.         JMP     SBLOOP
  674. WTDSP:  MVI     C,DECOUT
  675.         CALL    MEX
  676.         CALL    ILPRT
  677.         DB      ' seconds',CR,LF,0
  678. ;
  679. ; Compare next input-stream item in table @DE; CY=1
  680. ; if not found, else HL=matched data item
  681. ;
  682. TSRCH:  MVI     C,LOOKUP        ;get function code
  683.         JMP     MEX             ;pass to MEX processor
  684. ;
  685. ; Print in-line message ... blows away C register
  686. ;
  687. ILPRT:  MVI     C,ILP           ;get function code
  688.         JMP     MEX             ;go do it
  689.  
  690. ;
  691. ; Sign-on message
  692. ;
  693. SYSVER: CALL    NITMOD
  694.         LXI     D,SOMESG
  695.         MVI     C,PRINT
  696.         CALL    MEX
  697. CARRSH: LXI     D,NOMESG                ;tell about carrier
  698.         CALL    CARRCK                  ;check for it
  699.         MVI     C,PRINT
  700.         CNZ     MEX                     ;print the "NO" if no carrier
  701.         LXI     D,CARMSG                ;print "carrier present"
  702.         MVI     C,PRINT
  703.         CALL    MEX
  704.         RET
  705. ;
  706. ;
  707.         IF      SFTCRD
  708. SOMESG: DB      'Apple II w/Microsoft Softcard',CR,LF
  709.         ENDIF   ;SFTCRD
  710. ;
  711. ;
  712.         IF      ALSCRD
  713. SOMESG: DB      'Apple II w/ALS CP/M 3.0 Card',CR,LF
  714.         ENDIF   ;ALSCRD
  715. ;
  716.         IF      APPCRD
  717. SOMESG: DB      'Apple II w/PCPI Applicard',CR,LF
  718.         ENDIF   ;APPCRD
  719. ;
  720.         IF      MM2E
  721.         DB      'and Hayes Micromodem IIe',CR,LF,'$'
  722.         ENDIF   ;MM2E
  723. ;
  724.         IF NOT  MM2E
  725.         DB      'and Hayes Micromodem II',CR,LF,'$'
  726.         ENDIF   ;NOT MM2E
  727. NOMESG: DB      'no $'
  728. CARMSG: DB      'carrier present',CR,LF,'$'
  729. ;
  730. ; CHECK THE MICROMODEM FOR CARRIER PRESENT (NZ=NO)
  731. ;
  732. CARRCK: CALL    XDATIN
  733.         CALL    XSTTIN
  734.         ANI     4
  735.         RET
  736. ;
  737. ; Newline on console
  738. ;
  739. CRLF:   MVI     A,CR
  740.         CALL    TYPE
  741.         MVI     A,LF            ;fall into TYPE
  742. ;
  743. ; type char in A on console
  744. ;
  745. TYPE:   PUSH    H               ;save 'em
  746.         PUSH    D
  747.         PUSH    B
  748.         MOV     E,A             ;align output character
  749.         MVI     C,CONOUT        ;print via MEX
  750.         CALL    MEX
  751.         POP     B
  752.         POP     D
  753.         POP     H
  754.         RET                        
  755. ;
  756. ; strings to clear-to-end-of-screen, and clear-screen
  757. ;
  758. EOSMSG: DB      ESC,'Y$'        ;clear to end-of-screen
  759. CLSMSG: DB      ESC,'*$'        ;clear whole screen
  760.  
  761. ;-------------------------------------------------------
  762. ; Apple I/O 
  763. ;-------------------------------------------------------
  764.  
  765.         IF      SFTCRD
  766.  
  767. XDATOUT STA     MODDAT ! RET
  768. XCTLOUT STA     MODCTL ! RET
  769. XBDOUT  STA     BAUDRP ! RET
  770. XONHOOK STA     ONHOOK ! RET
  771. XOFFHK  STA     OFFHOOK ! RET
  772. XCTL3   STA     MODCTL3 ! RET
  773.  
  774. XSTTIN  LDA     MODSTT ! RET
  775. XDATIN  LDA     MODDAT ! RET
  776. XCTLIN  LDA     MODCTL ! RET
  777. XBDIN   LDA     BAUDRP ! RET
  778.  
  779.         ENDIF   
  780.  
  781.         IF ALSCRD
  782. ;
  783. ; ALS card routines require assembly with MAC
  784. ; (supplied with the ALS CP/M card)
  785. PUT     MACRO   ADDR
  786.         PUSH    H
  787.         LXI     H,ADDR
  788.         JMP     APWRT
  789.         ENDM
  790.            
  791. XDATOUT PUT     MODDAT
  792. XCTLOUT PUT     MODCTL
  793. XBDOUT  PUT     BAUDRP
  794. XONHOOK PUT     ONHOOK
  795. XOFFHK  PUT     OFFHOOK
  796. XCTL3   PUT     MODCTL3
  797.  
  798. APWRT:  PUSH    D
  799.         PUSH    B
  800. AW0:    CALL    $-$     ; patch vector here
  801.         POP     B
  802.         POP     D
  803.         POP     H
  804.         RET
  805.  
  806. GET     MACRO   ADDR
  807.         PUSH    H
  808.         LXI     H,ADDR
  809.         JMP     APRD
  810.         ENDM
  811.  
  812. XSTTIN  GET     MODSTT
  813. XDATIN  GET     MODDAT
  814. XCTLIN  GET     MODCTL
  815. XBDIN   GET     BAUDRP
  816.  
  817. APRD:   PUSH    D
  818.         PUSH    B
  819. AR0:    CALL    $-$     ; patch vector here
  820.         POP     B
  821.         POP     D
  822.         POP     H
  823.         RET
  824.  
  825.         ENDIF
  826. ;
  827. ; PCPI Applicard I/O routines
  828. ;
  829.         IF      APPCRD
  830. ;
  831. RDBYTE: EQU     0FFE0H          ;read 1 byte from apple (A=byte)
  832. WRBYTE: EQU     0FFE3H          ;write 1 byte to apple (C=byte)
  833. RDWORD: EQU     0FFE6H          ;read 2 bytes from apple (DE=word)
  834. WRWORD: EQU     0FFE9H          ;write 2 bytes to apple (DE=word)
  835. PEEK:   EQU     6               ;command
  836. POKE:   EQU     7               ;command
  837. ;
  838. XDATOUT:PUSH    D
  839.         LXI     D,MODDAT
  840.         JMP     APWRT
  841. ;
  842. XCTLOUT:PUSH    D
  843.         LXI     D,MODCTL
  844.         JMP     APWRT
  845. ;
  846. XBDOUT: PUSH    D
  847.         LXI     D,BAUDRP
  848.         JMP     APWRT
  849. ;
  850. XONHOOK:PUSH    D
  851.         LXI     D,ONHOOK
  852.         JMP     APWRT
  853. ;
  854. XOFFHK: PUSH    D
  855.         LXI     D,OFFHOOK
  856.         JMP     APWRT
  857. ;
  858. XCTL3:  PUSH    D
  859.         LXI     D,MODCTL3
  860. ;
  861. APWRT:  PUSH    B
  862.         MOV     B,A
  863.         MVI     C,POKE
  864.         CALL    WRBYTE
  865.         CALL    WRWORD
  866.         MOV     C,B
  867.         CALL    WRBYTE
  868.         POP     B
  869.         POP     D
  870.         RET
  871. ;
  872. XSTTIN: PUSH    D
  873.         LXI     D,MODSTT
  874.         JMP     APRD
  875. ;
  876. XDATIN: PUSH    D
  877.         LXI     D,MODDAT
  878.         JMP     APRD
  879. ;
  880. XCTLIN: PUSH    D
  881.         LXI     D,MODCTL
  882.         JMP     APRD
  883. ;
  884. XBDIN:  PUSH    D
  885.         LXI     D,BAUDRP
  886. ;
  887. APRD:   PUSH    B
  888.         MVI     C,PEEK
  889.         CALL    WRBYTE
  890.         CALL    WRWORD
  891.         CALL    RDBYTE
  892.         POP     B
  893.         POP     D
  894.         RET
  895. ;
  896.         ENDIF                   ;Applicard
  897. ;
  898. ;------------------------------------------------------------
  899. ;
  900.         END
  901.