home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / zcat / zbye12z.mac < prev    next >
Text File  |  1994-07-13  |  40KB  |  1,604 lines

  1.     .sall 
  2.     .sfcond 
  3. ; Program:   ZBYE 
  4. ; Author:    Jay Denebeim 
  5. ; Assembler: M80 Version 3.44 or greater. (SLRMAC    ETB)
  6. version    equ    12 
  7. rev    equ    'Z' 
  8. ;                                 ZCPR Bye RCP 
  9. ;  This program implements BYE as an RCP under ZCPR3.  It handles all modem 
  10. ; IO by replacing the console routines.  All other functions are passed to 
  11. ; the ZCPR CCP for execution.  Where BYE normally uses equates, I.E. password 
  12. ; connection, carrier lost commands, etc., ZBYE passes command lines to ZCPR. 
  13. ; This should reduce the bugs introduced by tons of conditional assemblies 
  14. ; that has plagued the recent versions of BYE.  It has also allowed room to 
  15. ; do more functions than BYE normally has done in the past.  Please folks, 
  16. ; lets keep the conditional assemblies down to a minimum. 
  17. ;  There are several new features in this program: 
  18. ;      Since its an RCP BYE can remain resident while the SYSOP is using 
  19. ;    the computer locally.  ZBye will answer the phone while in this mode,  
  20. ;    and allow the operator to accept the call while in another program. 
  21. ;      A chat mode has been implemented, this allows either single way, or 
  22. ;    two way communication between the sysop and the caller. 
  23. ;      It will also allow changes of the Maximum drive and user area 
  24. ;    without disabling the modem IO. 
  25. ;  The function key descriptions: 
  26. ;    ^L - Toggle Local only IO.  This toggles the modem IO on and off. 
  27. ;    ^O - Toggle Open access.  This switches the wheel, maxdrive, and 
  28. ;        maxuser bytes of ZCPR3.  NOTE: this is the location your 
  29. ;        BBS, XMODEM, and whatever else should check.  Its no longer 
  30. ;        in the BYE header.  Also, be sure to watch the user while 
  31. ;        he's on in this mode, either disable the modem, or be ready 
  32. ;        with the ^N. 
  33. ;    ^N - Nerdkey, Hang up on the bozo 
  34. ;    ^Q - Query the user, (CHAT mode), end with ^C.  This is a very 
  35. ;        rudimentrary chat.  If local only, he can't type back, 
  36. ;        but if not, its two way.  Be sure to announce yourself 
  37. ;        'cause ZBYE doesn't anounce when its going into chat mode. 
  38. ;        the only editing commands implimented are expansion of 
  39. ;        <cr> to <cr><lf>. 
  40. ;  To install this program, install your terminal dependent code following 
  41. ; the .8080 psudo-op.  ZBYE was set up to use MBYE overlays, these are either 
  42. ; very similar, or identical to BYE2.x or 3.x overlays.  Remember that 
  43. ; EQUates can't have :'s in front of them for M80, so you'll probably have 
  44. ; to do a global replace of :^IEQU with ^IEQU.  I'd really appreciate it if 
  45. ; you would send me a copy of your overlay when you finish it. 
  46. ;      You will also have to change the terminal dependent cursor 
  47. ; functions to match your own system. 
  48. ;  This program is the first in a series of ZCPR RCPM software.  Look for 
  49. ; ZBBS, ZXMODEM, ZDIR, and ZCHAT at a RCPM near you. 
  50. ;  Copyright 1985, by Jay Denebeim.  This program is released to the public 
  51. ; domain.  It can be freely given, but under no circumstances will this 
  52. ; software be charged for, except a copying fee not to exceed the price of 
  53. ; the media copied to. 
  54. ;  I hope you enjoy using this program as much as I enjoyed writing it. 
  55. ;  If you make any modifications to this program, or have any suggestions, 
  56. ; please feel free to contact me. 
  57. ;  Thanks a bunch, 
  58. ;  Jay Denebeim 
  59. ;  1800 Williamsburg Rd Apt 13-E    <- NOTE: Address and phone number new. 
  60. ;  Durham, NC  27707 
  61. ;  (919) 489-1785 (voice) 
  62. ;  (919) 489-6737 (data) 
  63. ;----------------------------------------------------------------------- 
  64. ; Revision History: 
  65. ;
  66. ; 1.2Z    Extensive revisions to accomodate a dumb UART which cannot detect
  67. ;    carrier or cause the modem to answer or hangup.  Code reorganized
  68. ;    to place all UART code in one place where it can be handled as
  69. ;    an overlay, all modem code in another overlay (smart or dumb)
  70. ;    and all terminal code in another overlay (25th line for status
  71. ;    or not).  Added conditional code generation to prevent meddling
  72. ;    with the wheel byte if z3whl=0.
  73. ;                    Earl T. Boone 
  74. ; 1.2A        *** Release Version ***        Fourth public release. 
  75. ;    Implemented answer routines for a dumb modem.  Set the equate 
  76. ;    DUMB to yes and baud rate will be set by carriage return 
  77. ;    sence.  Also moved initializing modem message to the right place. 
  78. ;                        Jay Denebeim 09/08/85 
  79. ; 1.1F    Added equates for most major functions of this program.  Also moved 
  80. ;    the command lines to the top of the file so they're easier to find. 
  81. ;    Please, when adding functions, make sure they turn all the way off 
  82. ;    CREF is great for finding code that isn't used when functions are 
  83. ;    turned off.                Jay Denebeim 09/14/85 
  84. ; 1.1E  Added KILCALR equate.  This switches on routines that will kill 
  85. ;    the caller if the byte at 0 is not equal to C3.  NOTE: this brought 
  86. ;    the size over the limit on my system.  The dumb modem routines 
  87. ;    are enough smaller that this will fit in dumb mode. 
  88. ;                        Jay Denebeim 09/09/85 
  89. ; 1.1D    Added an equate to allow the printer to be enabled by the wheel. 
  90. ;    Set the LSTDEV equate to YES if you want the printer available 
  91. ;    while ZBye is running.  Do be careful with this, most CP/M systems 
  92. ;    lock up if the printer is not on-line during an attempt to print. 
  93. ;    Don't run any programs that print remotely unless you're sure the 
  94. ;    printer is on-line.            Jay Denebeim 08/19/85 
  95. ; 1.1C        *** Release Version ***        Third public release. 
  96. ;    While modifing LUX4.0 to 4.1, I was reminded that time outs are 
  97. ;    very similar to carrier losses.  So, the carrier loss interupt 
  98. ;    also means time out.  To the program running under ZBYE, the reason 
  99. ;    for the loss of user isn't important.    Jay Denebeim 02/15/85 
  100. ; 1.1B    Made Wheel on status line follow what the wheel was actually 
  101. ;    set to.  Input Timed out msg was in the wrong place, and was erased 
  102. ;    when bye ran again.            Jay Denebeim 02/02/85 
  103. ; 1.1A        *** Release Version ***        Second public release. 
  104. ;    Cleaned up the comments, and stripped out the modem dependent 
  105. ;    routines.                Jay Denebeim 01/11/85 
  106. ; 1.0G    Changed carrier lost routine to restart # 30 so that programs 
  107. ;    could do their own thing on CLOSS.  Added check for wheel change 
  108. ;    so the sysop drives would follow the wheel. 
  109. ;                        Jay Denebeim 01/11/85 
  110. ; 1.0F    Moved BYE initialization routines into low memory.  This freed 
  111. ;    up some memory, and allowed another bit to implement another 
  112. ;    routine.  This routine runs a set of programs before hanging 
  113. ;    the modem up                Jay Denebeim 01/10/85 
  114. ; 1.0E    Moved local char status, and bye mode bytes into low memory 
  115. ;    so they will be available for other programs. 
  116. ;                        Jay Denebeim 01/09/85 
  117. ; 1.0D    If wrong characters typed during local mode answer, the caller 
  118. ;        would get hung up on.        Jay Denebeim 01/09/85 
  119. ; 1.0C    Reduced the size of the program.  RCP was overflowing. 
  120. ;                        Jay Denebeim 01/08/85 
  121. ; 1.0B    Answer phone while in local mode.    Jay Denebeim 01/07/85 
  122. ; 1.0A    First public release.  by - Jay Denebeim  12/23/84 
  123. ;----------------------------------------------------------------------- 
  124. ; Equates for this program 
  125.     .xlist 
  126.     maclib    E:Z3BASE.LIB 
  127.     .list 
  128. no    equ    0 
  129. yes    equ    not no 
  130. cr    equ    0dh     ; carriage return
  131. lf    equ    0ah     ; line feed
  132. bdos    equ    5 
  133. bios    equ    0 
  134. mhz    equ    20    ; CPU speed times 10 
  135. closs    equ    1    ; Number of seconds to wait after loss of carrier 
  136. clrou    equ    30h    ; Routine to call on loss of carrier 
  137. jump    equ    0c3h    ; 8080/Z80 jump instruction 
  138. ; Conditional assembly macros.  Use these to switch functions on and 
  139. ;  off. 
  140. ;
  141. etb    equ    yes    ; Special functions for Earl T Boone
  142. obye    equ    no    ; Emulate BYE3.x ? 
  143. dumb    equ    no    ; Is this system running under a dumb modem? 
  144. lstdev    equ    no    ; Enable printer when wheel is set? 
  145. kilcalr    equ    yes    ; Kill the caller if memory location 0 <> C3 
  146. timeout    equ    yes    ; yes, auto logout for sleepy callers 
  147. tomins    equ    2    ; minutes to auto logout 
  148. tmins    equ    ((tomins*mhz)+5)/10    ;(don't change this one...) 
  149. statln    equ    no    ; display the status on line 25
  150.             ; (see terminal dependent section)
  151. chatf    equ    yes    ; provide chat function 
  152. lclans    equ    yes    ; answer modem while in local mode 
  153. cdrive    equ    'E'-'@'    ; Callers Maximum Drive 
  154. cuser    equ    31    ; Callers Maximum User Area 
  155. lclst    equ    003bh    ; Local Console generated character flag 
  156. bymode    equ    003fh    ; Bye control byte 
  157. ;
  158. ;   The BYE mode byte is bit mapped and has the following attributes: 
  159. ;
  160. bymmio    equ    80h    ; 7 = Modem IO enable 
  161. bymcio    equ    40h    ; 6 = Console IO enable 
  162. bymica    equ    20h    ; 5 = Ignore Carrier 
  163. bymncc    equ    10h    ; 4 = Next Caller Commands Running 
  164. bymclc    equ    08h    ; 3 = Carrier Lost Commands Running 
  165. bymnor    equ    04h    ; 2 = Normal Mode Commands Running 
  166. bymaoc    equ    02h    ; 1 = Alert Operator on Call 
  167. bymphu    equ    01h    ; 0 = Pre-Hangup Commands Running 
  168. ;----------------------------------------------------------------------- 
  169. ;  Global Macros 
  170. cmdln    macro    cmd 
  171.     local    cmdst,msg,cmdend 
  172. cmdst:    dw    z3cl+msg-cmdst 
  173.     db    z3cls,0 
  174. msg:    db    cmd 
  175.     db    0 
  176. cmdend: 
  177.     endm 
  178. ;----------------------------------------------------------------------- 
  179. ;  Command line macros 
  180. byecl    macro    ; Executed during initialization 
  181.     cmdln    'BYE' 
  182.     endm 
  183. gbcl    macro    ; Executed before normal disconnection 
  184.     cmdln    'BYE' 
  185.     endm 
  186. nccl    macro    ; Executed between calls 
  187. ;    cmdln    'A0:;LDR RCPM.NDR;PATH A0:;BYE' ; JD's original
  188.     cmdln    'A0:;PATH E0: A0: A15: E0:;BYE' ; ETB's revision
  189.     endm 
  190. nmcl    macro    ; Executed upon connection 
  191. ;    cmdln    'A0:;RBBS;MENU'         ; JD's original
  192.     cmdln    'E0:;LDSK B:;LDSK C:'         ; ETB's revision
  193.     endm 
  194. clcl    macro    ; Executed if carrier lost 
  195.     cmdln    'BYE' 
  196.     endm 
  197. tocl    macro    ; Executed if timed out 
  198.     cmdln    'BYE' 
  199.     endm 
  200. kccl    macro    ; Executed if call killed by higher process 
  201.     cmdln    'BYE' 
  202.     endm 
  203. ;----------------------------------------------------------------------- 
  204. ;                            TPA starts here 
  205. ;----------------------------------------------------------------------- 
  206. ; Lets get this show on the road 
  207.     MACLIB    Z80
  208.     aseg 
  209.     org    100h 
  210. ; Lets see if BYE is already resident. 
  211.     lxi    h,rcp        ; Point to RCP area 
  212.     lxi    d,bybeg        ; Point to RCP's name 
  213.     lxi    b,5        ; Length of name 
  214. chbye1:    ldax    d        ; Get next char 
  215.     cci            ; Is it the same? 
  216.     jrnz    nbye        ; Nope, re-locate the RCP 
  217.     jpo    ybye        ; If done, its there 
  218.     inx    d        ; Point to next char 
  219.     jr    chbye1        ; Do it again 
  220. nbye:    mvi    c,9 
  221.     lxi    d,nbst 
  222.     call    5 
  223.     xra    a 
  224.     sta    lclst        ; Clear out local status 
  225.     sta    bymode        ; and Bye's operating mode 
  226.     lxi    h,bybeg 
  227.     lxi    d,rcp 
  228.     lxi    b,byend-bybeg 
  229.     ldir            ; Re-Locate BYE 
  230.     mvi    a,jump        ; load A with JUMP instruction 
  231.     sta    clrou        ; and put in restart 
  232.     lxi    h,lostit    ; do the same 
  233.     shld    clrou+1        ; with original closs command line 
  234.     call    byeini 
  235.     jmp    ybye 
  236. nbst:    db    'ZBye version ' 
  237.     db    '0'+(version/10), '.', '0'+(version mod 10), rev 
  238.     db    ' - By Jay Denebeim  Copyright (C) 1985',cr,lf 
  239.     db    'Making BYE',cr,lf,'$' 
  240. ybye:    lxi    h,bye 
  241.     lxi    d,z3cl 
  242.     lxi    b,byelen 
  243.     ldir            ; Load 'BYE' into command line 
  244.     jmp    0 
  245. bye:    byecl 
  246. byelen    equ    $-bye 
  247. byeini:    lda    z3env+2ch    ; store away, sysop's Highest drive 
  248.     sta    sdrive
  249.     lda    z3env+2dh    ; and user area. 
  250.     sta    suser
  251.     lda    fstprv        ; Store first letter of private 
  252.     sta    prvlet        ; commands 
  253.     call    newbio 
  254.     call    clrbuf 
  255.     call    modini 
  256.     mvi    a,bymmio+bymcio+bymica+bymclc 
  257.     sta    bymode
  258.     ret 
  259. ;
  260. ; The folowing code should logically be located in the UART and MODEM
  261. ; hardware specific overlay area of the code. It is located here
  262. ; to save space in the RCP by doing these initialization functions
  263. ; (only executed once) in the TPA.
  264. ; Initialize the UART (interface to modem) 
  265. modini:
  266.     call    mdinit        ; Initialize serial port 
  267.     mvi    b,3 
  268.     call    ldelay        ; delay .3 sec 
  269.     call    mdansw        ; raise dtr 
  270.     call    delay 
  271.     call    set1200        ; 1200 baud 
  272.     call    delay 
  273.     mvi    a,bymmio+bymica 
  274.     sta    bymode        ; enable modem io 
  275.      if    not dumb
  276.     call    prinlo        ; reset modem 
  277.     db    'ATZ',cr+80h     ; at this point we don't know
  278.                 ; whether the command will be echoed
  279.                 ; or whether the status will be
  280.                 ; numeric or verbal
  281.     call    l2char        ; is it status
  282.     cnz    l2char        ; if not - try again
  283. ;
  284. ; the next command will echo or not based strictly on the physical
  285. ; switches on the modem itself
  286. ;
  287.     call    prinlo        ; set our way 
  288.     db    'ATS0=0'    ; never answer
  289.     db    'V0'        ; numeric status codes
  290.     db    'E0'        ; no command echo
  291.     db    'X1'        ; extended status
  292.     db    'M1',cr+80h    ; speaker off at connect time 
  293.     call    l2char        ; get echo
  294.     cnz    l2char        ; get status
  295.     jnz    modini        ; status ok?
  296.      endif    ; dumb
  297.     ret
  298. ;----------------------------------------------------------------------
  299. ;                            RCP starts here 
  300. ;----------------------------------------------------------------------
  301. bybeg: 
  302.     .phase    rcp 
  303.     db    'ZBYE '        ; RCP's name for ZCPR 
  304.     db    3        ; Command name length 
  305. fstcmd:    db    'BYE' 
  306.     dw    start 
  307. fstprv:    db    'OFF' 
  308.     dw    byeoff 
  309.     db    0 
  310. start: 
  311.     pop    h        ; Get ZCPR3's return address 
  312.     shld    z3ret        ; Save it 
  313.     lxi    h,bymode 
  314.     bit    0,m 
  315.     jnz    prophu        ; Process pre-hangup commands 
  316.     bit    1,m 
  317.     jnz    prolcl        ; Process a local exit 
  318.     bit    2,m 
  319.     jnz    pronor        ; Process a normal exit 
  320.     bit    3,m 
  321.     jnz    proclc        ; Carrier lost commands finished 
  322.     bit    4,m 
  323.     jnz    proncc        ; Next caller commands finished 
  324.     call    prinpl 
  325.     db    'Invalid BYE mode!  BYE terminating',7,cr,lf+80h 
  326.     jr    byeof1 
  327. byeoff:
  328.     pop    h        ; Get ZCPR3's return address 
  329.     shld    z3ret        ; Save it 
  330. byeof1:    call    oldbio 
  331.     mvi    a,0 
  332.     sta    rcp        ; Disable RCP recognition 
  333.     sta    fstcmd        ; and for the CCP 
  334.     lxi    h,bymode 
  335.     res    7,m        ; Turn off modem IO 
  336.      if statln 
  337.     call    prinlc 
  338.     enab25    no 
  339.     cls    yes        ; enable 25th line and clear screen 
  340.      endif    ; statln 
  341.     call    prinpl 
  342.     db    'Bye is gone',cr,lf+80h 
  343.     jmp    exit 
  344. ; Local storage initialized by loader 
  345. sdrive:    db    0         ; sysop's max drive
  346. suser:    db    0         ; sysop's max user
  347. prvlet:    db    0         ; priviledged letter
  348. ; Process pre-hangup commands 
  349. prophu:    mvi    a,bymcio+bymmio+bymnor    ;con enab, modem enab, normal caller 
  350.     sta    bymode
  351.     lxi    h,gbcmd        ; Load next command string 
  352.     lxi    b,gblen 
  353.     lxi    d,z3cl 
  354.     ldir 
  355.     jmp    exit 
  356. gbcmd:    gbcl 
  357. gblen    equ    $-gbcmd 
  358. ; Process a local exit, actually a modified normal answer, but must check 
  359. ;    for carrier present. 
  360. prolcl:    call    mdcarck 
  361.     jrz    prolc1        ; If no carrier, just get ready for next call 
  362.     mvi    a,0ffh        ; set flag 
  363.     sta    prlct1
  364.     jr    prolc2        ; get ready for next caller 
  365. prlct1:    ds    1 
  366. ; Process a normal exit.  This routine runs any programs to end the 
  367. ;    session, says Bye, hangs up the modem, turns off the modem IO,  
  368. ;    then runs the routines to get ready for the next caller. 
  369. pronor:    call    prinpl 
  370.     db    'Goodbye, call again soon!',cr,lf+80h 
  371. prolc1:
  372.     call    prtsta
  373.     db    60,,13 
  374. ;
  375. ; If carrier lost, no point in printing msg 
  376. proclc:
  377.     call    mdinit 
  378. prolc2:    mvi    a,bymcio+bymncc    ;con enab, nxt calr mode 
  379.     sta    bymode
  380.     call    clrbuf 
  381.     call    ressec 
  382.     lxi    h,nccmd        ; Load next command string 
  383.     lxi    d,z3cl 
  384.     lxi    b,nclen 
  385.     ldir 
  386.     jmp    exit 
  387. nccmd:    nccl 
  388. nclen    equ    $-nccmd 
  389. ; Ready for next caller.  Set secure mode, then wait for arrival. 
  390. proncc:
  391.     call    cursoff        ; turn off cursor
  392.     call    prtsta
  393.     db    40,,19
  394.     call    clrscr        ; clear screen
  395.     call    setsec 
  396.     mvi    a,bymcio+bymphu 
  397.     sta    bymode
  398.     lda    prlct1        ; ending local mode ? 
  399.     cpi    0ffh 
  400.     push    psw 
  401.     xra    a 
  402.     sta    prlct1        ; zero it anyway 
  403.     pop    psw 
  404.     jrz    pronc2 
  405.     call    nxtcal 
  406. pronc1:    call    modans 
  407.     call    mdcarck        ; No Carrier? 
  408.     jrz    pronc1        ; Then loop 
  409. pronc2:
  410.     call    curson        ; turn cursor on
  411.     call    prtsta
  412.     db    60,'Connected',0
  413.     lxi    h,bymode 
  414.     setb    7,m        ; Make sure modem is on 
  415.     res    5,m        ; and carrier significant 
  416.     call    prinpl 
  417.     db    'Welcome to ZBoard',cr,lf 
  418.     db    'You are now running under ZBYE version ' 
  419.     db    '0'+(version/10), '.', '0'+(version mod 10), rev, cr, lf+80h 
  420.     lxi    h,nmcmd    ; Load normal entry command string 
  421.     lxi    d,z3cl 
  422.     lxi    b,nmlen 
  423.     ldir 
  424.     jmp    exit 
  425. nmcmd:    nmcl 
  426. nmlen    equ    $-nmcmd 
  427. ; Set ZCPR into a secure mode 
  428.      if    z3whl
  429. setsec:    call    usrdru 
  430.     xra    a 
  431.     sta    z3whl        ; Clear the wheel 
  432.     sta    fstprv        ; And private commands 
  433.     ret 
  434. ; Set highest drive and user area for caller. 
  435. usrdru:    mvi    a,cdrive    ; Set Caller's highest drive 
  436.     sta    z3env+2ch
  437.     mvi    a,cuser 
  438.     sta    z3env+2dh    ; and user area. 
  439.     push    psw 
  440.     push    h 
  441.     call    prtsta
  442.     db    40,'Not Wheel',0
  443.     pop    h 
  444.     pop    psw 
  445.     ret 
  446.      else
  447. setsec:    ret            ; not a secure system
  448.      endif    ;z3whl
  449. ; Set ZCPR into sysop mode 
  450.      if    z3whl
  451. ressec:    call    sysdru 
  452.     xra    a 
  453.     cma 
  454.     sta    z3whl        ; Set the wheel 
  455.     lda    prvlet        ; and private commands 
  456.     sta    fstprv
  457.     ret
  458. ; Set highest drive and user area for SysOp. 
  459. sysdru:    lda    sdrive        ; Set Sysop's highest drive 
  460.     sta    z3env+2ch
  461.     lda    suser 
  462.     sta    z3env+2dh    ; and user area. 
  463.     call    prtsta
  464.     dc    40,'    Wheel',0
  465.     ret 
  466.      else
  467. ressec:    ret            ; not a secure system
  468.      endif    ;z3whl 
  469. ; Clear ZCPR's internal buffers 
  470. clrbuf:    xra    a 
  471.      if    z3env 
  472.     lxi    h,z3env+80h    ; Clear TCAP area 
  473.     lxi    d,z3env+81h 
  474.     lxi    b,7eh        ; TCAP length-1 (always?) 
  475.     mov    m,a 
  476.     ldir 
  477.      endif    ;z3env 
  478.      if    shstk 
  479.     lxi    h,shstk        ; Clear Shell Stack 
  480.     lxi    d,shstk+1 
  481.     lxi    b,shstks*shsize-1 
  482.     mov    m,a 
  483.     ldir 
  484.      endif    ;shstk 
  485.      if    z3msg 
  486.     lxi    h,z3msg        ; Clear Message Buffers 
  487.     lxi    d,z3msg+1 
  488.     lxi    b,4eh        ; Message buffer length -1 
  489.     mov    m,a 
  490.     ldir 
  491.      endif    ;z3msg 
  492.     ret 
  493. ; Answer modem and wait for carrier.  Set baud as appropriate. 
  494. modans:
  495.     call    prtsta
  496.     db    30,'Awaiting Call',0
  497. mdans00    call    modans0
  498.     rz
  499.     cpi    'C'-'@'        ; Control C from console? 
  500.     jnz    mdans00        ; Nope 
  501.     lxi    h,bymode 
  502.     bit    1,m        ; if in local bye active mode 
  503.     jnz    mdans00        ; then forget the console 
  504.     res    7,m        ; inhibit modem IO 
  505.     setb    1,m        ; go into local bye active mode 
  506.     res    0,m        ; make sure not in pre-hangup 
  507.     call    ressec
  508.     call    curson        ; turn on cursor
  509.     call    prtsta
  510.     db    60,'Local',7
  511.      if    lclans 
  512.     jmp    exit 
  513.      else 
  514.     jmp    byeof1 
  515.      endif    ; lclans 
  516. ;  Get ready for next caller 
  517. nxtcal:
  518.      if    timeout 
  519.     xra    a        ; Clear timeout 
  520.     sta    tocnt
  521.     sta    tocnt+1
  522.     mvi    a,tmins 
  523.     sta    toval
  524.      endif    ;timeout 
  525.     call    mdinit        ; drop DTR 
  526.     mvi    b,3 
  527.     call    ldelay        ; wait awhile 
  528.     call    mdansw        ; raise it 
  529.     call    delay 
  530.     call    set1200 
  531.     call    delay 
  532.     call    sync        ; synchronize modem
  533.      if    lclans 
  534. ;    Check for call coming in during local mode.  If so, answer it. 
  535. chkcal:    lda    chkt1 
  536.     ora    a 
  537.     rnz            ; return if already doing function 
  538.     call    mdcarck        ; check for call still in progress 
  539.     jrnz    chkca4        ; yup 
  540.     xra    a 
  541.     sta    chkt2        ; he's gone 
  542. chkca4:    lda    chkt2 
  543.     ora    a        ; if this function already run 
  544.     rnz            ; return to caller 
  545.     mov    a,m        ; Get BYMODE 
  546.     sta    chkt1        ; indicate function running 
  547.     push    psw 
  548.     res    6,m        ; Turn off console 
  549.     setb    7,m        ; Turn on modem 
  550.     setb    5,m        ; Ignore Carrier 
  551.     call    incmcl        ; check for incoming call
  552.     jz    chkca1
  553.     call    mdcarck        ; Got carrier? 
  554.     jz    chkca1        ; Nope 
  555.     lxi    h,bymode 
  556.     res    6,m 
  557.     push    h 
  558.     call    prinpl 
  559.     db    cr,lf,'Asking SYSOP if you can get on.',cr,lf+80h 
  560.     call    mdcarck        ; Hung up? 
  561.     jz    chkca1        ; Oh well 
  562. chkca2:    call    oconst 
  563.     jrz    chkca3 
  564.     call    conin 
  565.     jr    chkca2        ; Eat console characters if any 
  566. chkca3:     if    statln 
  567.     call    go25 
  568.     call    prinlc 
  569.     curpos    0,24,no
  570.      else
  571.     call    prinlc 
  572.      endif    ; statln 
  573.     dc    'Caller, let on ? ' 
  574.     call    oconin 
  575.     sta    chkt1
  576.      if    statln 
  577.     call    no25 
  578.      endif    ; statln 
  579.     call    mdcarck        ; Still with us? 
  580.     pop    h 
  581.     jrz    chkca1        ; Nope, his loss 
  582.     setb    7,m 
  583.     res    6,m        ; Set for remote IO 
  584.     lda    chkt1 
  585.     ani    'Y' 
  586.     cpi    'Y' 
  587.     jrz    letliv        ; If Y or y let him on 
  588.     call    prinpl 
  589.     db    'Sorry, try again later',cr,lf+80h 
  590.     call    nxtcal 
  591.     jr    chkca1 
  592. letliv:    call    prinpl 
  593.     db    'He will let you on soon, please hold',cr,lf+80h 
  594.     mvi    a,0ffh 
  595.     sta    chkt2        ; indicate call in progress 
  596. chkca1:    xra    a 
  597.     sta    chkt1        ; zero out storage 
  598.     pop    psw        ; Get original BYMODE 
  599.     sta    bymode
  600.     ret 
  601. chkt1:    ds    1 
  602. chkt2:    ds    1 
  603.      endif    ; lclans 
  604. ; Check for carrier available.  If not there, return with zero flag set. 
  605. carok:    push    h        ; Do we care? 
  606.     lxi    h,bymode 
  607.     bit    5,m 
  608.     pop    h 
  609.     rnz            ; Nope 
  610.     push    b 
  611.     mvi    b,closs*10 
  612. carok1:    call    mdcarck        ; Got carrier? 
  613.     jrnz    carok2        ; Yup, great 
  614.     call    delay        ; nope, wait awhile 
  615.     djnz    carok1        ; try again 
  616. carok2:    pop    b 
  617.     ret 
  618. ; Carrier lost.  Drop Dead. 
  619. lostit:    lda    clgat 
  620.     ora    a 
  621.     jrnz    lstit1        ; Check for no status gate 
  622.     call    prtsta
  623.     db    60,'Carrier Lost',0
  624.     mvi    a,bymcio+bymclc 
  625.     sta    bymode
  626.     lxi    h,clcmd        ; this is what we want to do 
  627.     lxi    d,z3cl        ; point to zcpr's command line 
  628.     lxi    b,cllen 
  629.     ldir 
  630. lstit1:
  631.     mvi    a,jump        ; just to be safe
  632.     sta    0
  633.     xra    a 
  634.     sta    clgat        ; Clear no status gate 
  635.     jmp    0        ; Gotta exit this way 
  636. clcmd:    clcl 
  637. cllen    equ    $-clcmd 
  638. clgat:    db    0        ; gate for carrier lost command 
  639.      if    timeout 
  640. ; Must be too late at night.  He's asleep. 
  641. ; Input timed out. 
  642. timout:
  643.      if    etb
  644.     mvi    a,0
  645.     sta    carion        ; mark 'carrier off'
  646.      endif
  647.     mvi    a,0ffh 
  648.     sta    clgat        ; Flag the timeout 
  649.     call    prinpl 
  650.     db    'Input timed out',7,cr,lf+80h 
  651.     call    prtsta
  652.     db    60,'Timed Out',3
  653.     mvi    a,bymcio+bymclc 
  654.     sta    bymode
  655.     lxi    h,tocmd        ; this is what we want to do 
  656.     lxi    d,z3cl        ; point to zcpr's command line 
  657.     lxi    b,tolng 
  658.     ldir 
  659.     rst    clrou/8        ; Do a CLOSS restart 
  660. tocmd:    tocl 
  661. tolng    equ    $-tocmd 
  662.      endif    ;timeout 
  663.      if    kilcalr        ; allow programs to commit suicide 
  664. ;  Memory Location 0 not C3H program abort 
  665. ;    If the base of memory is not a jump instruction, this routine will 
  666. ;    be executed.  It is similar to a carrier lost, or timeout routine. 
  667. ;    Any program which changes the byte will cause the caller to be 
  668. ;    dropped unceremoniously. 
  669. kilcal:    mvi    a,0ffh 
  670.     sta    clgat        ; Set the gate 
  671.     mvi    a,jump 
  672.     sta    0        ; replace the jump instruction 
  673.     call    prtsta
  674.     db    60,'Call Killed',1
  675.     mvi    a,bymcio+bymclc 
  676.     sta    bymode
  677.     lxi    h,kccmd        ; this is what we want to do 
  678.     lxi    d,z3cl        ; point to zcpr's command line 
  679.     lxi    b,kclng 
  680.     ldir 
  681. ;    rst    clrou        ; Do a CLOSS restart 
  682.     rst    clrou/8        ; assembler uses other syntax
  683. kccmd:    kccl 
  684. kclng    equ    $-kccmd 
  685.      endif    ; kilcalr 
  686. ;  Routines which process local function keys. 
  687. ;    Here are the descriptions 
  688. ;    ^L - Toggle Local IO 
  689. ;    ^O - Toggle Open access 
  690. ;    ^N - Nerdkey, Hang up on the bozo 
  691. ;    ^Q - Query the user, (CHAT mode) 
  692. fkeys:    lxi    h,bymode    ; BYE in inactive state? 
  693.     bit    1,m 
  694.     rnz            ; Yes, return 
  695.     cpi    'L'-'@'        ; Control-L ? 
  696.     jrz    toglcl        ; if so, toggle local mode 
  697.     cpi    'O'-'@'        ; Control-O ? 
  698.     jrz    togope        ; Yes? Toggle security 
  699.     cpi    'N'-'@'        ; Control-N ? 
  700.     jz    twitem        ; Goodbye bozo 
  701.      if    chatf 
  702.     cpi    'Q'-'@'        ; Control-Q 
  703.     jz    bychat        ; Go into Chat Mode 
  704.      endif    ;chatf 
  705.     ret            ; Not a BYE function Key 
  706. ;  Toggle Local IO Mode 
  707. toglcl:    bit    7,m 
  708.     jrz    toglc1        ; If set, reset it. 
  709.     res    7,m 
  710.     call    prtsta
  711.     db    51,'Local Disabled',0
  712.     jr    endfun 
  713. toglc1:    setb    7,m 
  714.     call    prtsta
  715.     db    51,'Local',8
  716.     jr    endfun 
  717. ;  Toggle Security 
  718. togope:    lda    fstprv 
  719.     ora    a        ; Secure? 
  720.     jrz    togop1        ; If so, remove it 
  721.     call    setsec        ; Turn on security 
  722.     jr    endfun 
  723. togop1:    call    ressec        ; Turn it off 
  724.     jr    endfun 
  725. ;  Hang up on the bum. 
  726. twitem:
  727.     call    curson
  728.     call    prtsta
  729.     db    60,'Twitted off',0
  730.     jmp    proclc        ; Same as Carrier loss 
  731. ;  End Function Key routines 
  732. endfun:    xra    a        ; No character entered 
  733.     ret 
  734.      if    chatf 
  735. ;  Bye's Chat Mode 
  736. bychat:
  737.     call    conin        ; pitch out the ^Q 
  738.     call    prtsta
  739.     db    46,'Chat',0
  740.     call    prinpl
  741.     dc    'Chat',cr,lf
  742. bycha2:    call    conin        ; end on control c 
  743.     cpi    'C'-'@' 
  744.     jrz    bycha3 
  745. bycha1:    push    psw 
  746.     push    h 
  747.     push    b 
  748.     mov    c,a 
  749.     call    conout 
  750.     pop    b 
  751.     pop    h 
  752.     pop    psw 
  753.     push    psw 
  754.     bit    7,m 
  755.     cz    mconout        ; print it to modem if not enabled 
  756.     pop    psw 
  757.     cpi    'M'-'@' 
  758.     jrnz    bycha2        ; Loop if not a carriage return 
  759.     mvi    a,'J'-'@' 
  760.     jr    bycha1        ; And append linefeed if there 
  761. bycha3:
  762.     call    prinpl
  763.     dc    'End Chat',cr,lf
  764.     call    prtsta
  765.     db    46,,4 
  766.     jmp    endfun 
  767.      endif    ; chatf 
  768. exit: 
  769. z3ret    equ    $+1        ; point to code to modify 
  770.     jmp    $-$        ; ZCPR's return address 
  771. prinlc:    lda    bymode        ; Get current Mode 
  772.     sta    pritmp        ; Save it 
  773.     res    7,a        ; turn off modem IO 
  774.     setb    6,a        ; turn on lcl IO 
  775.     sta    bymode
  776.     xtix            ; print the string 
  777.     call    print 
  778.     xtix    
  779.     lda    pritmp        ; restore mode 
  780.     sta    bymode
  781.     ret 
  782. pritmp:    db    0 
  783. prinpl:    xtix            ; Get string starting address 
  784.     call    print        ; Print it 
  785.     xtix            ; Since we're pointing to next code location 
  786.     ret            ; Go there! 
  787. prinlo:    xtix            ; Get string starting address 
  788.     call    print        ; Print it 
  789. ;    call    delay        ; My modem is too d**n slow 
  790.     xtix            ; Since we're pointing to next code location 
  791.     ret            ; Go there! 
  792. print:    ldx    a,0        ; Get next char 
  793.     bit    7,a        ; Check for Carry 
  794.     push    psw 
  795.     res    7,a        ; Mask Carry Bit 
  796.     mov    c,a 
  797.     call    conout        ; Print it 
  798.     inxix            ; point to next char 
  799.     pop    psw 
  800.     rnz    
  801.     jr    print 
  802. ;.1 sec delay routine 
  803. delay:    push    b 
  804.     lxi    b,4167*(mhz/10)+417*(mhz mod 10) ; constant * MHz10x 
  805. delay1:    dcx    b 
  806.     mov    a,b 
  807.     ora    c 
  808.     jrnz    delay1 
  809.     pop    b 
  810.     ret 
  811. ;.001 sec delay routine 
  812. sdelay:    push    b 
  813.     lxi    b,42*(mhz/10)+4*(mhz mod 10) ; constant * MHz10x 
  814.     jr    delay1 
  815. ; Long delay routine, B contains # of .1 sec delays 
  816. ldelay:    call    delay 
  817.     dcr    b 
  818.     jrnz    ldelay 
  819.     ret 
  820. newbio:    lhld    bios+1        ; Point to bios start 
  821.     mvi    l,0 
  822.     lxi    d,tolst        ; Point to storage table 
  823.     lxi    b,tolen-tolst    ; table length 
  824.     ldir            ; Save old jump table 
  825.     lxi    h,tnlst        ; Point to new jump table 
  826.     lded    bios+1 
  827.     mvi    e,0 
  828.     lxi    b,tnlen-tnlst 
  829.     ldir            ; We are now running under BYE 
  830.     ret 
  831. oldbio:    lxi    h,tolst        ; Put things back the way they were 
  832.     lded    bios+1 
  833.     mvi    e,0 
  834.     lxi    b,tolen-tolst 
  835.     ldir 
  836.     ret 
  837. tolst: 
  838. ocboot:        jmp    0 
  839. owboot:        jmp    0    ; This will hold the BIOS routines 
  840. oconst:        jmp    0    ;  BYE will modify 
  841. oconin:        jmp    0 
  842. oconout:    jmp    0 
  843. olist:        jmp    0 
  844. opunch:        jmp    0 
  845. oreader:    jmp    0 
  846. tolen: 
  847. tnlst: 
  848. cboot: 
  849.          if    obye    ; Emulate Old BYE? 
  850.         jmp    fakeit 
  851.          else 
  852.         jmp    0 
  853.          endif 
  854. wboot:        jmp    owboot    ; Here is the new jump table 
  855. const:        jmp    bconst 
  856. conin:        jmp    bconin 
  857. conout:        jmp    bconout 
  858.          if    lstdev    ; retain printer for sysop? 
  859. list:        jmp    whlst 
  860.          else 
  861. list:        jmp    mconout 
  862.          endif    ; lstdev 
  863. punch:        jmp    bconout 
  864. reader:        jmp    bconin 
  865. tnlen: 
  866. ;  Structure to look like the old byes 
  867.      if obye 
  868. fakeit:    ds    15 
  869.     dw    oconout 
  870.     db    'BYE' 
  871.      endif 
  872. ;  Routines patched in by BYE 
  873. bconst:
  874.      if    z3whl
  875.     lda    z3whl 
  876.     lxi    h,owheel    ; check for wheel change 
  877.     cmp    m 
  878.     jrz    bcst3 
  879.     sta    owheel
  880.     ora    a        ; wheel set? 
  881.     cz    usrdru        ; then set remote dru 
  882.     cnz    sysdru        ; else set sysop dru 
  883.      endif    ;z3whl
  884. bcst3:    lxi    h,bymode    ; local console enabled? 
  885.     bit    6,m 
  886.     jrz    bcst1        ; nope, don't check 
  887.     push    h        ; used later 
  888.      if    lclans 
  889.     bit    1,m        ; In local mode ? 
  890.     cnz    chkcal        ; check for a caller 
  891.      endif    ; lclans 
  892.     lda    lchar        ; got an uneaten one? 
  893.     ora    a 
  894.     jrnz    bcst2        ; Yup, still have it 
  895.     call    oconst        ; check con status 
  896.     ora    a 
  897.     pop    h 
  898.     sta    lchar        ; flag local char 
  899.     sta    lclst
  900.     jrz    bcst1        ; no char 
  901.     push    h 
  902.     call    oconin        ; get local char 
  903.     call    fkeys        ; check and process local function keys 
  904. bcst2:    pop    h 
  905.     sta    lchar        ; store away char 
  906.     ora    a        ; make flags follow a 
  907.     ret 
  908. bcst1:    bit    7,m        ; Modem enabled? 
  909.     rz            ; Nope, don't bother 
  910.      if    kilcalr        ; Kill caller if loc 0 <> jump 
  911.     lda    0 
  912.     cpi    jump 
  913.     jnz    kilcal        ; Kill him if instructed by higher program 
  914.      endif    ; kilcalr 
  915.     call    carok        ; Check for carrier 
  916.     jz    clrou        ; Fool dropped carrier on us 
  917.     call    mdinst        ; Check for modem status 
  918.     rnz            ; Everything's hunkey dory 
  919.      if    timeout 
  920.     push    h 
  921.     lxi    h,bymode 
  922.     bit    5,m        ; Paying attention to carrier 
  923.     jrnz    ndata 
  924.     lxi    h,tocnt        ;No data, incr. timeout counter 
  925.     inr    m
  926.     jrnz    ndata        ;don't timeout yet 
  927.     inx    h 
  928.     inr    m        ;next byte of counter 
  929.     jrnz    ndata 
  930.     lxi    h,toval        ;1 "minute", no data 
  931.     dcr    m
  932.     jrnz    ndata        ;still not timed out... 
  933.     jmp    timout        ;finally... timed out... 
  934. ndata: 
  935.     xra    a        ;no character for sure 
  936.     pop    h 
  937.      endif    ; Timeout 
  938.     ret 
  939. toval:    ds    1 
  940. tocnt:    ds    2 
  941. lchar:    db    0 
  942. owheel:    db    0 
  943. bconin:    call    bconst        ; Wait for char avail 
  944.     ora    a 
  945.     jrz    bconin 
  946.      if    timeout 
  947.     xra    a        ; Clear timeout 
  948.     sta    tocnt
  949.     sta    tocnt+1
  950.     mvi    a,tmins 
  951.     sta    toval
  952.      endif    ;timeout 
  953.     lxi    h,bymode    ; local con enabled? 
  954.     bit    6,m 
  955.     jrz    bcin1        ; Nope, skip 
  956.     lda    lchar        ; Get local status 
  957.     ora    a 
  958.     jrz    bcin1        ; it was not local 
  959.     push    psw 
  960.     xra    a        ; clear local character 
  961.     sta    lchar        ; hit. 
  962.     pop    psw 
  963.     ret 
  964. bcin1:    jmp    mdinp 
  965. bconout: 
  966.     lxi    h,bymode    ; local con enabled? 
  967.     bit    7,m        ; remote con enabled? 
  968.     jrz    bcou1        ; nope, skip 
  969.     push    h 
  970.     push    b        ; in case of trashed char 
  971.     call    carok        ; Check for carrier 
  972.     jz    clrou        ; Fool dropped carrier on us 
  973.     call    mconout 
  974.     pop    b 
  975.     pop    h 
  976. bcou1:    bit    6,m 
  977.     rz            ; nope, done 
  978.     call    oconout        ; print it 
  979.     ret 
  980.      if    lstdev 
  981. ;  Wheel check for List Device 
  982. whlst:    sta    wlst        ; better to be safe than sorry. 
  983.     lda    z3whl 
  984.     ora    a        ; is wheel set? 
  985.     lda    wlst 
  986.     jz    mconout        ; nope, hope they like double characters. 
  987.     jmp    olist        ; let's hope there's a printer out there. 
  988. wlst:    ds    1 
  989.      endif    ; lstdev 
  990. ;  Modem Conout routine 
  991. mconout: 
  992.     call    mdoutst 
  993.     jrz    mconout        ; wait till we can do it 
  994.     mov    a,c 
  995.     call    mdoutp        ; do it 
  996.     ret 
  997. ;---------------- Modem dependent routines start here ---------------------- 
  998. ;
  999. ; This should really be done as two entirely independent overlays -
  1000. ; one for smart (Hayes compatible) modems and one for dumb.  Then there
  1001. ; would be no need for the if-else-endif.
  1002. ;
  1003.      if    not dumb     ; smart "Hayes" modem
  1004. modans0    call    conin         ; wait for a character
  1005.     mov    b,a
  1006.     lda    lclst 
  1007.     ora    a        ; Was it a local char? 
  1008.     mov    a,b
  1009.     rnz            ; yes - return with nz flag
  1010.     lxi    h,bymode    ; We're probably going to set a mode soon 
  1011.     cpi    '2'        ; Is it a RING? 
  1012.     jrz    mdans1 
  1013.     cpi    '1'        ; How 'bout connect 300? 
  1014.     jrz    mdans3 
  1015.     cpi    '5'        ; connect 1200? 
  1016.     jrz    mdans4 
  1017.     cpi    '3'        ; No Carrier 
  1018.     jrnz    modans0
  1019.      if    etb
  1020.     xra    a        ; set z flag
  1021.     sta    carion        ; assume carrier on
  1022.      endif
  1023.     ret
  1024. mdans1:    res    6,m        ; turn off local console
  1025.     push    h 
  1026.     call    prinlo 
  1027.     db    'ATA',cr+80h    ; answer the phone 
  1028.     pop    h 
  1029.     setb    6,m        ; turn on local console
  1030.     jr    modans0 
  1031. mdans3:    call    set300 
  1032.     jrnz    mdans7
  1033.     jr    mdans5 
  1034. mdans4:    call    set1200
  1035.     jrnz    mdans7 
  1036. mdans5:    call    delay 
  1037.     res    5,m        ; Carrier enabled 
  1038.      if    etb
  1039.     mvi    a,0ffh
  1040.     sta    carion        ; mark 'carrier on'
  1041. ; If hardware carrier detect is available leave this in else remove it
  1042.     mvi    b,10        ; Check carrier for 1.0 seconds 
  1043. mdans6:    call    carok 
  1044.     jrz    mdans7 
  1045.     call    delay 
  1046.     djnz    mdans6 
  1047.      endif    ; etb
  1048.     ret 
  1049. mdans7:    lxi    h,bymode 
  1050.     call    nxtcal
  1051.     setb    5,m 
  1052.     xra    a
  1053.     ret 
  1054. ;
  1055. sync:    lxi    h,bymode 
  1056.     setb    7,m 
  1057.     setb    5,m        ; ignore carrier 
  1058.     setb    6,m        ; turn dual io on 
  1059.     ret
  1060. ;
  1061. ; check for incoming call
  1062. ;
  1063. incmcl:    call    bconst        ; char avail from modem? 
  1064.     rz            ; nope, continue
  1065. incmcl1    call    bconin        ; Get modem char 
  1066.     cpi    '2'        ; RING? 
  1067.     jrz    incmcl2
  1068.     xra    a        ; set z flag
  1069.     ret
  1070. incmcl2    lxi    h,bymode 
  1071.     setb    1,m 
  1072.     call    mdans1        ; Answer the phone 
  1073.     ori    0ffh        ; set nz flag
  1074.     ret
  1075. ;.............. this is the dumb modem overlay .....................
  1076.      else                 ; dumb modem
  1077. modans0    call    const 
  1078.     jrz     mdansC        ; got a character? 
  1079.     call    conin 
  1080.     mov    b,a
  1081.     lda    lclst 
  1082.     ora    a        ; Was it a local char? 
  1083.     mov    a,b
  1084.     rnz            ; yes 
  1085. mdansC    call    mdcarck        ; someone here? 
  1086.     jrz    modans0        ; if so, set baud 
  1087. mdans8:    mvi    b,5        ; five tries to get baud right 
  1088.     lxi    h,bymode 
  1089.     setb    6,m        ; enable console IO 
  1090.     setb    7,m        ; enable modem IO 
  1091. mdans9:    call    mdcarck        ; did they drop carrier? 
  1092.     rz    
  1093. ;
  1094.     push    b        ; save 'em 
  1095.     call    set300         ; try 300 baud
  1096.     call    conin 
  1097.     pop    b
  1098.     cpi    cr        ; did we get a CR? 
  1099.     rz
  1100. ;
  1101.     push    b
  1102.     call    set1200     ; try 1200 baud
  1103.     call    conin 
  1104.     pop    b
  1105.     cpi    cr        ; did we get a CR? 
  1106.     rz
  1107. ;
  1108.     djnz    mdans9 
  1109.     call    nxtcal        ; somethings confused, hang up on 'em 
  1110.     xra    a        ; set z flag
  1111.     ret 
  1112. ;
  1113. sync:    ret             ; just return if dumb modem
  1114. ;
  1115. incmcl:                ; check for incoming call
  1116.     call    mdcarck        ; someone on the line? 
  1117.     rz            ; nope
  1118.     call    mdans8        ; set up for dumb remote caller 
  1119.     ori    0ffh        ; set nz flag
  1120.     ret
  1121.      endif    ; dumb 
  1122. ;
  1123. ; If you can put the phone on-hook and off-hook via the UART then this
  1124. ; label and appropriate code should be in the UART overlay.
  1125. ;
  1126. ; The following code uses "smart" modem capabilities to compensate for
  1127. ; the fact that my UART is so dumb.   ETB
  1128. ;
  1129. mdansw
  1130.     lxi    h,bymode    ; save bymode
  1131.     mov    a,m
  1132.     push    psw
  1133.     setb    7,m        ; modem on
  1134.     res    6,m        ; console off
  1135.     setb    5,m
  1136.     mvi    b,15
  1137.     call    ldelay        ; wait 1.5 sec before +++
  1138.     call    prinlo
  1139.     db    '++','+'+80h    ; switch modem to command mode
  1140.     mvi    b,15
  1141.     call    ldelay        ; wait 1.5 sec after +++
  1142.     call    prinlo
  1143.     db    'ATH',cr+80h    ; hang up phone
  1144.     call    l2char        ; get echo (if any)
  1145.     call    l2char        ; get status
  1146.      if    etb
  1147.     lxi    h,carion
  1148.     mvi    m,0        ; set 'carrier off'
  1149.      endif
  1150.     lxi    h,bymode
  1151.     pop    psw        ; restore bymode
  1152.     mov    m,a
  1153.     ret
  1154. ;
  1155. ; .................................................................
  1156. ;
  1157. getc:    lxi    b,80*mhz    ; nr times to try
  1158.                 ; to get char from modem
  1159. ; the nr of times to try is sensitive to the speed of the const function
  1160. ; if zbye won't get started try raising the 80 to 160 or more.  The only
  1161. ; adverse effect should be to slow the program down some.
  1162. getc3    push    b
  1163.     call    const        ; check status
  1164.     pop    b
  1165.     ora    a
  1166.     jrnz    getc2        ; char avail?
  1167.     dcx    b        ; no - count tries
  1168.     mov    a,b
  1169.     ora    c
  1170.     jrnz    getc3        ; try again?
  1171.     stc            ; i'm exhausted, lets quit
  1172.     ret
  1173. getc2    call    conin        ; get the character
  1174.     ora    a        ; clear carry
  1175.     ret
  1176. ;
  1177. ; get characters from modem till it times out then test the last 2 chars
  1178. ; to see if they are '0' and car ret.
  1179. ;
  1180. l2char    lxi    h,0        ; get last 2 chars from modem
  1181. l2c2    push    h
  1182.     call    getc
  1183.     pop    h
  1184.     jrc    l2c1        ; no chars left
  1185.     mov    h,l
  1186.     mov    l,a
  1187.     jr    l2c2
  1188. l2c1
  1189.     mov    a,h
  1190.     cpi    '0'
  1191.     rnz
  1192.     mov    a,l
  1193.     cpi    cr
  1194.     ret
  1195. ;
  1196. ;------------------- Start of UART dependent routines ------------------ 
  1197. ; the following code is specific for ETB's modem port and would have
  1198. ; to be extensively modified for anyone else.
  1199. ;
  1200. dport    equ    0e3f8h        ; modem data port
  1201. sport    equ    dport+1        ; modem status port
  1202. ;
  1203. dav    equ    4        ; data available bit
  1204. tbmt    equ    8        ; transmit bufr empty bit
  1205. err    equ    13h        ; overrun, framing, and parity error bits
  1206. ;
  1207. ; This routine is supposed to "turn off everyting on the modem, hang it up,
  1208. ; and get it ready to wait for a RING. (DTR off)" but most of this is
  1209. ; either impossible or undesireable on mys system. ETB
  1210. ;
  1211. mdinit                ; initialize port
  1212.     lda    dport        ; discard existing data
  1213.     ret
  1214. ;
  1215. set300:                ; 300 baud not supported
  1216.     ori    0ffh
  1217.     ret
  1218. ;
  1219. set1200                ; set 1200 baud
  1220.     ora    a    
  1221.     ret
  1222. ;
  1223. ; The following uses software 'carrier detect' because ETB's system
  1224. ; does not provide hardware carrier detect.
  1225. ;
  1226. mdcarck
  1227.     lda    carion        ; is carrier on?
  1228.     ora    a
  1229.     ret
  1230. carion    db    0ffh        ; software 'carrier on' switch
  1231. ;
  1232. mdinst                ; modem input status
  1233.     lda    sport
  1234.     cma            ; invert bits
  1235.     mov    b,a        ; save status
  1236.     ani    dav        ; data available?
  1237.     rz            ; no
  1238.     mov    a,b        ; get stat back
  1239.     ani    err        ; check for errors
  1240.     jrz    mdinst1        ; noerror
  1241.     lda    dport        ; discard data
  1242.     xra    a        ; clear status
  1243.     ret
  1244. mdinst1    ori    0ffh        ; data avail
  1245.     ret
  1246. ;
  1247. mdinp                ; modem input 
  1248.     lda    dport        ; get data
  1249.     cma            ; invert bits
  1250.     ani    7fh        ; delete hi bit
  1251.     ret
  1252. ;
  1253. mdoutst                ; modem output status
  1254.     lda    sport        ; get status
  1255.     cma            ; invert bits
  1256.     ani    tbmt        ; buffer empty?
  1257.     ret
  1258. ;
  1259. mdoutp                ; modem output
  1260.     cma            ; invert bits
  1261.     sta    dport        ; send data
  1262.     ret
  1263. ;
  1264. ;----------------- Start of Terminal dependent routines-------------------
  1265. ; There are essentially 3 options available for printing status info on
  1266. ; the local console;
  1267. ;
  1268. ; 1) print it on the "25th line" where it will not scroll. This is obtained
  1269. ; by setting "statln equ yes" and then seeing to it that the code below
  1270. ; corresponds to your particular terminal configuration.
  1271. ;
  1272. ; 2) print it just like any other info and let it scroll. This is obtained
  1273. ; by setting "statln equ no".  This option makes absolutely no unusual
  1274. ; demands on the terminal and should run on any system.
  1275. ;
  1276. ; 3) don't print it at all.  This is obtained by converting the subroutine
  1277. ; prtsta into a dummy (ret instruction).  If desired you may then discard
  1278. ; most if not all of this overlay.
  1279. ;
  1280. ; These macros indicate the characters sequences to cause the specified
  1281. ; action on a specific terminal. You will probably have to change the 
  1282. ; data below if you wish to use "line 25". 
  1283. ;
  1284.      if    statln
  1285. curpos    macro    x,y,last    ; Position Cursor to X,Y (0 offset) 
  1286.     db    1bh,'=',' '+y,' '+x+(80h and last) 
  1287.     endm 
  1288. enab25    macro    last        ; Enable 25th line 
  1289.     db    1bh,'C','7'+(80h and last) 
  1290.     endm 
  1291. disab25    macro    last        ; Disable 25th line 
  1292.     db    1bh,'B','7'+(80h and last) 
  1293.     endm 
  1294. pucu    macro    last        ; Push cursor 
  1295.     db    1bh,'B','6'+(80h and last) 
  1296.     endm 
  1297. pocu    macro    last        ; Pop cursor 
  1298.     db    1bh,'C','6'+(80h and last) 
  1299.     endm 
  1300. cls    macro    last        ; Clear Screen 
  1301.     db    1ah+(80h and last) 
  1302.     endm 
  1303. curof    macro    last        ; Cursor off 
  1304.     db    1bh,'C','4'+(80h and last) 
  1305.     endm 
  1306. curon    macro    last        ; Cursor on 
  1307.     db    1bh,'B','4'+(80h and last) 
  1308.     endm 
  1309.      endif    ; statln
  1310. ;
  1311. ; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  1312. ;
  1313. ;
  1314. ; Print status information on the local terminal.  The calling sequence
  1315. ; is    call    prtsta
  1316. ;    db    m,string,n
  1317. ; where m is the column number on the screen where string is to be printed
  1318. ; followed by n blanks.
  1319. ;
  1320. prtsta:
  1321. ;    ret            ; to turn off all status reports
  1322.                 ; activate this ret instruction
  1323.     xthl
  1324.     mov    a,m        ; get ptr to column
  1325.     inx    h
  1326.     xthl
  1327.      if    statln        ; fancy terminal
  1328.     adi    ' '+80h
  1329.     sta    prtstax
  1330.     call    prinlc
  1331.     enab25    no        ; enable line 25
  1332.     pucu    no        ; push cursor
  1333.     curpos    0,24,yes    ; move cursor
  1334. prtstax    equ    $-1
  1335.      else            ; plain terminal
  1336.     mov    b,a
  1337.     ora    a        ; column 0?
  1338.     cnz    tab        ; print blanks til col is reached
  1339.      endif    ; statln
  1340. ;
  1341.     xthl            ; point to string
  1342. prtstas    mov    a,m        ; get next char in string
  1343.     inx    h        ; increment ptr
  1344.     cpi    32        ; end of string?
  1345.     jrc    prtsta2
  1346.     mov    c,a
  1347.     push    h
  1348.     call    oconout        ; print char on console
  1349.     pop    h
  1350.     jr    prtstas
  1351. prtsta2    xthl            ; return adr
  1352.     mov    b,a        ; nr blanks to print
  1353.     ora    a
  1354.     cnz    tab        ; print them
  1355. ;
  1356.      if    statln
  1357.     call    no25
  1358.      else
  1359.     call    prinlc
  1360.     dc    cr,lf
  1361.      endif    ;statln
  1362.     ret
  1363. ;
  1364. go25:
  1365.      if    statln
  1366.     call    prinlc 
  1367.     enab25    no         ; enable 25th line
  1368.     pucu    yes         ; push cursor
  1369.      endif    ; statln
  1370.     ret 
  1371. ;
  1372. no25:
  1373.      if    statln
  1374.     call    prinlc 
  1375.     pocu    no         ; pop cursor
  1376.     disab25    yes         ; disable 25th line
  1377.      endif    ; statln 
  1378.     ret
  1379. ;
  1380. cursoff:
  1381.      if    statln
  1382.     call    prinlc
  1383.     curoff    yes        ; cursor off
  1384.      endif    ; statln
  1385.     ret
  1386. ;
  1387. curson:
  1388.      if    statln
  1389.     call    prinlc
  1390.     curon    yes        ; cursor on
  1391.      endif    ; statln
  1392.     ret
  1393. ;
  1394. clrscr:
  1395.      if    statln
  1396.     call    prinlc        ; clear screen
  1397.     cls    yes
  1398.      endif    ; statln
  1399.     ret
  1400. ; Print (on local console) number of spaces contained in B register. 
  1401. tab:
  1402.     push    b 
  1403.     mvi    c,' ' 
  1404.     call    oconout 
  1405.     pop    b 
  1406.     djnz    tab 
  1407.     ret 
  1408. ;
  1409. ;-------------------- End of terminal dependent routines ---------------------
  1410. ;
  1411. ;    .z80 
  1412. ;     if2    ; this is turned off because I use a one pass assembler ETB 
  1413.      if    $ ge (rcp+rcps*128) 
  1414.     .printx ->This RCP is too large, don't try to run it.<- 
  1415.      endif 
  1416. ;     endif 
  1417.     .dephase 
  1418. byend: 
  1419.     end 
  1420. cp+rcps*128) 
  1421.     .