home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / z3sys / calcrcp.z80 < prev    next >
Encoding:
Text File  |  1994-09-02  |  14.6 KB  |  906 lines

  1. ; CALCRCP.Z80 Version 1.0          
  2. ; October 31, 1986 by Carson Wilson.       
  3. ;
  4. ; Please leave any problems, comments, or suggestions at
  5. ; Lillipute Z-Node, Chicago, 312-649-1730 or 312-664-1730.
  6. ;
  7. ; This is a combination of elements from Paul Pomerleau's
  8. ; SLTRAP.LBR and Eric Meyer's HP.COM. When assembled into a
  9. ; Resident Command Package (RCP) for ZCPR3, it becomes a "pop-up"
  10. ; calculator modelled on the principles of Eric Meyer's HP+.COM
  11. ; for CP/M Plus.
  12. ;
  13. ; To use, first put this file and Z3BASE.LIB for your system on
  14. ; the current drive and assemble and load to CALC.RCP. Then load
  15. ; CALC.RCP with LDR.COM. Use the "H" command to display help on
  16. ; usage. The calculator won't become active until activated by
  17. ; the command "CALC" from your system's operating system prompt. 
  18. ; Thereafter, whenever a CONTROL-] is detected, the calculator
  19. ; will become active. The calculator can thus be activated from
  20. ; the middle of any program which tests for console input, which
  21. ; means any interactive program. 
  22.  
  23. ; WARNING: BECAUSE THIS RCP LINKS UP WITH YOUR SYSTEM'S BIOS, IT
  24. ; IS NECESSARY TO TURN IT OFF BY USING THE "CALC" COMMAND AGAIN
  25. ; BEFORE LOADING ANOTHER RCP. 
  26.  
  27. ; To make the CALC.RCP even more versatile, create an alias named
  28. ; RCP.COM which will respond to commands to automatically go to
  29. ; the proper directories, get the proper RCP and load it.
  30.  
  31. ; For example, my CALC.COM contains the following:
  32.  
  33. ; IF EX LOAD:$1.RCP
  34. ; ROOT:LDR LOAD:$1.RCP
  35. ; FI
  36. ; H
  37.  
  38. ; This enables me to type "RCP CALC," thereby commanding my
  39. ; system to get CALC.RCP from the proper directory, load it, and
  40. ; display its built-in help. When I'm through with CALC, I first type
  41. ; CALC to turn it off, then "RCP SYS" to reload my normal RCP. 
  42.  
  43. ; Like HP+.COM, this calculator may not work with a very few
  44. ; programs such as WordStar, which interact directly with the
  45. ; BIOS. See HP+.DOC for more on this. For information on how the
  46. ; calculator works, see HP.DOC by Eric Meyer. Both of these files
  47. ; are found in HP.LBR.
  48.  
  49. vers    equ    10  
  50. BDOS    equ    5
  51.  
  52. maclib    Z3Base.lib    ; use base addresses
  53.  
  54. ;
  55. ; System entry point
  56. ;
  57.     org    RCP        ; Passed from Z3Base
  58.     db    'Z3RCP'        ; Flag for package loader
  59.     db    04        ; How long each name is
  60. ctab:
  61.     db    'H   '    ; Help for RCP
  62.     dw    CList
  63.     db    'CALC'    ; Enable/Disable trigger key
  64.     dw    TrigOn
  65. ctab1:
  66.     db    0
  67. ;
  68. ;  Banner name of RCP:
  69. ;  Command list routine
  70. ;
  71. CList:
  72.     ld    de,RCP$name
  73.     jp    string
  74. ;
  75. ; Routines for trapping I/O.
  76. ;
  77. Trigger    equ    ']'-'@'    ; control-] is current trigger key
  78. ;
  79. TrigOn:    ld    a,(IsOn)
  80.     cp    1        ; key detection on?
  81.     jp    z,TrigOff    ; yes, turn off
  82.     ld    a,1        ; no, flip flag to ON
  83.     ld    (IsOn),a    ; & fall through  
  84. ;
  85. ; ENABLE Trigger Key Detection
  86. ;
  87. ; First, replace BIOS jump to its "console in" routine with jump
  88. ; to RCP routine, and save the addresses of the BIOS jump and the
  89. ; routine. 
  90. ;
  91.     ld    hl,(1)        ; Get boot location
  92.     ld    de,07h        ; Offset for location of "JP CONIN" in BIOS
  93.     add    hl,de        ; hl now holds BIOS "jump" location
  94.     ld    (JConIn),hl    ; Save location for BIOS jp to console in
  95.     ld    e,(hl)
  96.     inc    hl
  97.     ld    d,(hl)        ; Move to de
  98.     ld    (ConIn),de    ; Save BIOS ConIn routine address
  99.     ld    de,NewIn
  100.     ld    (hl),d        ; Replace BIOS "jump" with ours
  101.     dec    hl
  102.     ld    (hl),e        ; Fill our NewIn location in
  103. ;
  104. ; Now save the address of the BIOS conout routine.
  105. ;
  106.       ld    hl,(1)        ; Get boot location
  107.       ld    de,0ah        ; Offset for location of "JP CONOUT" in BIOS
  108.       add    hl,de        ; hl now holds BIOS "jump" location 
  109.       ld    e,(hl)
  110.       inc    hl
  111.      ld    d,(hl)        ; Move to de
  112.     ld    (con),de    ; Save BIOS ConOut routine address
  113. ;
  114.     ld    a,(on)        ; Is the calculator running?
  115.     or    a
  116.     ret    nz         ; Yes, don't print "Trigger Key Enabled" msg.
  117.     ld    de,OnMsg    ; Else tell user trigger key activated
  118.     jp    string
  119.     ret
  120. ;
  121. NewIn:    call    OrigIn        ; Bring key in
  122.           cp    Trigger        ; Is it the trigger key?
  123.     ret    nz        ; No - business as usual 
  124. ;
  125.     ld    (SavStk),sp    ; Yes, run calculator
  126.     ld    sp,newstk
  127. ;
  128.     push    ix
  129.     push    iy    
  130.     push    af
  131.     push    bc
  132.     push    de
  133.     push    hl    
  134. ;
  135.     ld    a,(on)
  136.     cpl    
  137.     ld    (on),a        ; Flip calculator running flag
  138. ;
  139.     call    TrigOff        ; Turn off trigger key detection
  140.                 ; and fall through to calculator
  141.  
  142. ;
  143. ; ********** Begin Calculator *********
  144. ;
  145. ; This is a modified disassembly of HP.COM by Eric Meyer.  In place
  146. ; of the HP prompt, I have substituted a more informative one. 
  147. ; Relative jumps are substituted for absolute ones where possible. 
  148. ; The exit and entry routines have been replaced by my own routines
  149. ; which appear immediately before and after the calculator routine.
  150. ; The exit key has been changed from ^C to ^] to maintain
  151. ; consistency with the trigger key.  Finally, direct BIOS calls
  152. ; replace BDOS calls to conin and conout, and a routine which
  153. ; replaces echoed characters from BDOS conin is no longer
  154. ; necessary (commented out).
  155. ;
  156.     jr    start
  157. signon:    db    0dh,'CALC-RCP (^] = Off)   '
  158.     db    '         ',0
  159.     ld    a,(de)
  160. start:    xor    a
  161.       ld    (r17),a
  162. s9:    ld    hl,signon
  163.     call    StrOut
  164.     call    s2
  165.     ld    hl,(r4)
  166.     call    s3
  167.     ld    hl,r5
  168.     ld    b,8        ; Print 8 spaces 
  169. prompt:    ld    (hl),' '
  170.     inc    hl
  171.     dec    b
  172.     jr    nz,prompt
  173.     ld    hl,r5        ; Print prompt "H>"
  174.     call    StrOut
  175.     xor    a
  176.     ld    (r3),a
  177. getin:    call    s4    ; Get input from BIOS 
  178.     cp    Trigger    ; RCP trigger key
  179.     jp    z,quit    ; End program
  180.     cp    1bh
  181.     jp    z,esc
  182.     cp    '+'
  183.     jp    z,plus
  184.     cp    '-'
  185.     jp    z,minus
  186.     cp    '*'
  187.     jp    z,times
  188.     cp    '^'
  189.     jp    z,exp
  190.     cp    '/'
  191.     jp    z,div
  192.     cp    '%'
  193.     jp    z,remain
  194.     cp    '&'
  195.     jp    z,bitand
  196.     cp    '|'
  197.     jp    z,bitor
  198.     cp    '~'
  199.     jp    z,negate
  200.     cp    0dh
  201.     jp    z,run
  202.     cp    8
  203.     jr    z,backsp
  204.     cp    '='
  205.     jp    z,equals
  206.     cp    18h    ; ^X
  207.     jr    z,clear
  208.     cp    'S'
  209.     jp    z,save
  210.     cp    's'
  211.     jp    z,save
  212.     cp    'R'
  213.     jp    z,recall
  214.     cp    'r'
  215.     jp    z,recall
  216.     cp    '!'        ; Space or control char?
  217.     jp    c,illegal    ; Yes - error
  218. s23:    ld    hl,r7
  219.     ld    de,r5
  220.     ld    bc,7
  221.     ldir
  222.     ld    (r8),a
  223.     ld    a,0ffh
  224.     ld    (r3),a
  225. s8:    ld    hl,signon    ; Reprint prompt
  226.     call    StrOut
  227.     call    s2
  228.     ld    hl,r5
  229.     call    StrOut
  230.     jp    getin        ; Get input
  231. backsp:    ld    a,(r3)
  232.     or    a
  233.     jr    z,s7
  234.     ld    hl,r9
  235.     ld    de,r8
  236.     ld    bc,7
  237.     lddr
  238.     ld    a,' '
  239.     ld    (r5),a
  240.     jr    s8
  241. s7:    ld    hl,0
  242.     ld    (r4),hl
  243.     ld    a,0ffh
  244.     ld    (r17),a
  245.     jp    s9
  246. clear:    ld    hl,r4        ; Clear registers 
  247.     ld    b,10h        ; (16 bytes)
  248. s10:    ld    (hl),0
  249.     inc    hl
  250.     dec    b
  251.     jr    nz,s10
  252.     jp    s9
  253. run:    call    s11
  254.     call    s12
  255.     ld    a,0ffh
  256.     ld    (r17),a
  257.     jp    s9
  258. equals:    call    s11
  259.     ld    hl,(r4)
  260.     ex    de,hl
  261.     ld    hl,(r10)
  262.     ex    de,hl
  263.     ld    (r10),hl
  264.     ex    de,hl
  265.     ld    (r4),hl
  266.     jp    start
  267. negate:    call    s11
  268.     ld    hl,(r4)
  269.     ld    a,h
  270.     cpl
  271.     ld    h,a
  272.     ld    a,l
  273.     cpl    
  274.     ld    l,a
  275.     inc    hl
  276.     ld    (r4),hl
  277.     jp    start    
  278. bitor:    call    s11
  279.     call    s14
  280.     ld    a,h
  281.     or    d
  282.     ld    h,a
  283.     ld    a,l
  284.     or    e
  285.     ld    l,a
  286. s16:    ld    (r10),hl
  287.     call    s15
  288.     jp    start
  289. bitand:    call    s11    ; bitwise and
  290.     call    s14
  291.     ld    a,h
  292.     and    d
  293.     ld    h,a
  294.     ld    a,l
  295.     and    e
  296.     ld    l,a
  297.     jr    s16
  298. remain:    call    s11    ; remainder
  299.     call    s14
  300.     call    s17
  301.     jp    c,s18
  302.     ex    de,hl
  303.     jr    s16
  304. div:    call    s11
  305.     call    s14
  306.     call    s17
  307.     jp    c,s18
  308.     jr    s16
  309. times:    call    s11
  310.     call    s14
  311.     call    s19
  312.     jp    c,s18
  313.     jr    s16
  314. exp:    call    s11
  315.     call    s14
  316.     ld    a,d
  317.     or    e
  318.     jr    nz,s20
  319.     ld    hl,1
  320.     jr    s16
  321. s20:    ld    b,d
  322.     ld    c,e
  323.     ld    d,h
  324.     ld    e,l
  325. s21:    dec    bc
  326.     ld    a,b
  327.     or    c
  328.     jr    z,s16
  329.     push    bc
  330.     push    de
  331.     call    s19
  332.     pop    de
  333.     pop    bc
  334.     jp    c,s18
  335.     jr    s21
  336. minus:    call    s11
  337.     call    s14
  338.     sbc    hl,de
  339.     jr    s16
  340. plus:    call    s11
  341.     call    s14
  342.     add    hl,de
  343.     jp    s16
  344. save:    call    s11
  345.     call    s4
  346.     cp    '4'    ; Legal register?
  347.     jp    nc,s18
  348.     sub    '1'    ; Legal register?
  349.     jp    c,s18
  350.     add    a,a
  351.     ld    e,a
  352.     ld    d,0
  353.     ld    hl,r11
  354.     add    hl,de
  355.     ld    a,(r4)
  356.     ld    (hl),a
  357.     inc    hl
  358.     ld    a,(r12)
  359.     ld    (hl),a
  360.     jp    start
  361. recall:    call    s11
  362.     call    s4
  363.     cp    '4'
  364.     jp    nc,s18
  365.     sub    '1'
  366.     jp    c,s18
  367.     add    a,a
  368.     ld    e,a
  369.     ld    d,0
  370.     ld    hl,r11
  371.     add    hl,de
  372.     ld    a,(r17)
  373.     or    a
  374.     jr    nz,s22
  375.     push    hl
  376.     call    s12
  377.     pop    hl
  378. s22:    ld    a,(hl)
  379.     ld    (r4),a
  380.     inc    hl
  381.     ld    a,(hl)
  382.     ld    (r12),a
  383.     jp    start
  384. chars:    db    '+-*^/%&~=|SsRr'    ; Legal commands
  385. esc:    call    s4
  386.     ld    hl,chars
  387.     ld    b,0eh
  388. s24:    cp    (hl)
  389.     jp    z,s23
  390.     inc    hl
  391.     dec    b
  392.     jr    nz,s24
  393.     and    5fh
  394.     push    af
  395.     call    s11
  396.     pop    af
  397.     cp    'H'    ; Switch to hex
  398.     jr    z,hex
  399.     cp    'D'    ; Switch to decimal 
  400.     jr    z,dec
  401.     cp    'B'    ; Switch to binary
  402.     jr    z,bin
  403.     cp    'C'    ; Switch to character
  404.     jr    z,char
  405.     jr    s18
  406. hex:    ld    hl,s25
  407.     ld    de,s26
  408.     jr    s27
  409. dec:    ld    hl,s28
  410.     ld    de,s29
  411.     jr    s27
  412. bin:    ld    hl,s30
  413.     ld    de,s31
  414.     jr    s27
  415. char:    ld    hl,s32
  416.     ld    de,s33
  417. s27:    ld    (r13),a
  418.     ld    (scale),hl    ; Store current scale = hex, dec, etc.
  419.     ex    de,hl
  420.     ld    (r14),hl
  421.     jp    start
  422. s14:    ld    hl,(r4)
  423.     ex    de,hl
  424.     ld    hl,(r10)
  425.     ret
  426. s11:    ld    a,(r3)
  427.     or    a
  428.     ret    z
  429.     ld    hl,r5
  430.     call    s35
  431.     jr    c,s36    ; Illegal - ring bell
  432.     ld    a,(r17)
  433.     or    a
  434.     jr    nz,s37
  435.     push    hl
  436.     call    s12
  437.     pop    hl
  438. s37:    ld    (r4),hl
  439.     xor    a
  440.     ld    (r17),a
  441.     ret
  442. s36:    pop    hl
  443. illegal:ld    a,7    ; Ring bell
  444.     call    CharOut
  445.     jp    s8
  446. s18:    ld    a,7
  447.     call    CharOut
  448.     jp    start
  449. s15:    ld    hl,r10
  450.     ld    de,r4
  451.     ld    bc,0eh
  452.     ldir
  453.     ret
  454. s12:    ld    hl,r15
  455.     ld    de,r16
  456.     ld    bc,0eh
  457.     lddr
  458.     ret
  459. s2:    ld    a,(r13)
  460.     call    CharOut
  461.     ld    a,'>'    ; Prompt
  462.     call    CharOut
  463.     ld    a,' '    ; Prompt: "H> "
  464.     call    CharOut
  465.     ret
  466. s19:    ld    c,l
  467.     ld    b,h
  468.     ld    hl,0
  469.     ld    a,0fh
  470. s40:    push    af
  471.     or    d
  472.     jp    p,s38
  473.     add    hl,bc
  474.     jp    c,s39
  475. s38:    add    hl,hl
  476.     jp    c,s39
  477.     ex    de,hl
  478.     add    hl,hl
  479.     ex    de,hl
  480.     pop    af
  481.     dec    a
  482.     jr    nz,s40
  483.     or    d
  484.     ret    p
  485.     add    hl,bc
  486.     ret
  487. s17:    ld    a,e
  488.     or    d
  489.     jp    z,s41
  490.     ld    c,l
  491.     ld    b,h
  492.     ld    hl,0
  493.     ld    a,10h
  494.     or    a
  495. s43:    ld    (r20),a
  496.     rl    c
  497.     rl    b
  498.     rl    l
  499.     rl    h
  500.     ld    (r21),hl
  501.     sbc    hl,de
  502.     ccf
  503.     jr    c,s42
  504.     ld    hl,(r21)
  505. s42:    ld    a,(r20)
  506.     dec    a
  507.     jr    nz,s43
  508.     ex    de,hl
  509.     rl    c
  510.     ld    l,c
  511.     rl    b
  512.     ld    h,b
  513.     or    a
  514.     ret
  515. s35:    push    hl
  516. s45:    ld    a,(hl)
  517.     or    a
  518.     jr    z,s44
  519.     cp    ' '
  520.     jr    nz,s44
  521.     ld    (hl),'0'
  522.     inc    hl
  523.     jr    s45
  524. s44:    pop    hl
  525.         db    0c3h    ; jp
  526. scale:    dw    s25    ; Current scale (hex default)
  527. s25:    ld    b,04h
  528.     call    s46
  529.     call    s47
  530.     ret    c
  531.     ld    d,a
  532.     inc    hl
  533.     call    s47
  534.     ret    c
  535.     ld    e,a
  536.     ex    de,hl
  537.     or    a
  538.     ret
  539. s47:    call    s48
  540.     ret    c
  541.     rlca
  542.     rlca
  543.     rlca
  544.     rlca
  545.     inc    hl
  546.     ld    e,a
  547.     call    s48
  548.     ret    c
  549.     add    a,e
  550.     or    a
  551.     ret
  552. s48:    ld    a,(hl)
  553.     and    7fh
  554.     cp    'A'
  555.     jr    c,s49
  556.     and    5fh
  557.     sub    7
  558. s49:    sub    '0'
  559.     jp    m,s41
  560.     cp    10h
  561.     jr    nc,s41
  562.     or    a
  563.     ret
  564. s39:    pop    bc
  565. s41:    scf
  566.     ret
  567. s46:    ld    a,(hl)
  568.     cp    '0'
  569.     jr    nz,s39
  570.     inc    hl
  571.     dec    b
  572.     jr    nz,s46
  573.     or    a
  574.     ret
  575. s28:    ld    b,3
  576.     call    s46
  577.     ld    de,0
  578.     ld    bc,2710h    ; constant
  579.     call    s50
  580.     ld    bc,03e8h
  581.     call    s50
  582.     ld    bc,64h
  583.     call    s50
  584.     ld    bc,0ah
  585.     call    s50
  586.     ld    bc,1
  587.     call    s50
  588.     ex    de,hl
  589.     or    a
  590.     ret
  591. s50:    ld    a,(hl)
  592.     cp    ':'
  593.     jr    nc,s39
  594.     sub    '0'
  595.     jp    m,s39
  596.     ex    de,hl
  597.     or    a
  598. s52:    jr    z,s51
  599.     add    hl,bc
  600.     jr    c,s39
  601.     dec    a
  602.     jr    s52
  603. s51:    ex    de,hl
  604.     inc    hl
  605.     ret
  606. s30:    ld    b,0
  607.     ld    c,80h
  608. s56:    ld    a,(hl)
  609.     inc    hl
  610.     cp    '0'
  611.     jr    z,s53
  612.     cp    '1'
  613.     jr    z,s54
  614.     jr    s41
  615. s54:    ld    a,b
  616.     or    c
  617.     ld    b,a
  618. s53:    ld    a,c
  619.     cp    1
  620.     jr    z,s55
  621.     rrca
  622.     ld    c,a
  623.     jr    s56
  624. s55:    ld    l,b
  625.     ld    h,0
  626.     or    a
  627.     ret
  628. s32:    ld    b,7
  629.     call    s46
  630.     ld    a,(hl)
  631.     and    7fh
  632.     ld    l,a
  633.     ld    h,0
  634.     or    a
  635.     ret
  636. s3:    db    0c3h    ; jp    
  637. r14:    dw    s26
  638. s26:    ld    b,4
  639.     call    s57
  640.     ld    a,h
  641.     call    s58
  642.     ld    a,l
  643.     call    s58
  644.     ret
  645. s58:    push    af
  646.     and    0f0h
  647.     rra
  648.     rra
  649.     rra
  650.     rra
  651.     call    hexout
  652.     pop    af
  653.     and    0fh
  654.     call    hexout
  655.     ret
  656. hexout:    add    a,'0'
  657.     cp    ':'        ; Arabic number output?
  658.     jp    c,CharOut    ; Yes
  659.     add    a,7        ; No - get char. A-F for hex output
  660.     jp    CharOut
  661. s57:    ld    a,' '
  662.     call    CharOut
  663.     dec    b
  664.     jr    nz,s57
  665.     ret
  666. s29:    ld    b,3
  667.     call    s57
  668.     ld    c,0
  669. s74:    ld    a,h
  670.     cp    ''''
  671.     jr    c,s60
  672.     jr    nz,s61
  673.     ld    a,l
  674.     cp    10h
  675.     jr    c,s60
  676. s61:    inc    c
  677.     ld    de,0d8f0h    ; Constant
  678.     add    hl,de
  679.     jr    s74
  680. s60:    ld    a,'0'
  681.     add    a,c
  682.     call    CharOut
  683.     ld    c,0
  684. s63:    ld    a,h
  685.     cp    3
  686.     jr    c,s62
  687.     jr    nz,s75
  688.     ld    a,l
  689.     cp    0e8h
  690.     jr    c,s62
  691. s75:    inc    c
  692.     ld    de,0fc18h    ; Constant
  693.     add    hl,de
  694.     jr    s63
  695. s62:    ld    a,'0'
  696.     add    a,c
  697.     call    CharOut
  698.     ld    c,0
  699. s66:    ld    a,h
  700.     or    a
  701.     jr    nz,s64
  702.     ld    a,l
  703.     cp    64h
  704.     jr    c,s65
  705. s64:    inc    c
  706.     ld    de,0ff9ch    ;Constant    
  707.     add    hl,de
  708.     jr    s66
  709. s65:    push    af
  710.     ld    a,'0'    ;30h
  711.     add    a,c
  712.     call    CharOut
  713.     pop    af
  714.     ld    c,0
  715. s68:    cp    0ah
  716.     jr    c,s67
  717.     inc    c
  718.     sub    0ah
  719.     jr    s68
  720. s67:    push    af
  721.     ld    a,'0'
  722.     add    a,c
  723.     call    CharOut
  724.     pop    af
  725.     add    a,'0'
  726.     call    CharOut
  727.     ret
  728. s31:    ld    c,80h
  729.     ld    b,l
  730. s70:    call    s69
  731.     ld    a,c
  732.     cp    1
  733.     ret    z
  734.     rrca
  735.     ld    c,a
  736.     jr    s70
  737. s69:    ld    a,b
  738.     and    c
  739.     ld    a,'0'
  740.     jr    z,s71
  741.     ld    a,'1'
  742. s71:    call    CharOut
  743.     ret
  744. s33:    ld    b,7
  745.     call    s57
  746.     ld    a,l
  747.     and    7fh
  748.     cp    7fh
  749.     jr    z,s72
  750.     cp    ' '
  751.     jr    nc,CharOut
  752.     or    '@'
  753.     jr    s73
  754. s72:    ld    a,'?'
  755. s73:    push    af
  756.     ld    a,8    ; Backspace
  757.     call    CharOut
  758.     ld    a,5eh
  759.     call    CharOut
  760.     pop    af
  761.     jr    CharOut
  762. CharOut:
  763.     push    bc
  764.     push    de
  765.     push    hl
  766.     ld    c,a    ; Put char. in C, and    
  767.     call    OrigOut    ; BIOS console out
  768.     pop    hl
  769.     pop    de
  770.     pop    bc
  771.     ret
  772. StrOut:    xor    a    ; Print string
  773.     add    a,(hl)
  774.     ret    z
  775.     push    hl
  776.     call    CharOut
  777.     pop    hl
  778.     inc    hl
  779.     jr    StrOut
  780. s4:    call    OrigIn
  781.     and    7fh    ; Strip high bit
  782. ;
  783. ; Since we are calling BIOS directly, characters are
  784. ; no longer echoed to the screen, so they needn't be erased
  785. ;
  786. ;    cp    '!'    ; printable character?
  787. ;    ret    c    ; yes 
  788. ;    push    af    ; no- delete present character
  789. ;    ld    a,8    ; backspace
  790. ;    call    CharOut
  791. ;    ld    a,' '    ; space
  792. ;    call    CharOut
  793. ;    pop    af
  794. ;
  795.     ret
  796. r4:    db    0    ; Registers cleared by "^X"
  797. r12:    db    0
  798. r10:    ds    11
  799. r15:    dw    0
  800. r16:    db    0
  801. ;
  802. r11:    ds    6
  803. r13:    db    'H'    ; Hex scale is default
  804. r5:    db    0
  805. r7:    db    0,0,0,0,0
  806. r9:    db    0
  807. r8:    dw    0
  808. r3:    db    0
  809. r17:    db    0
  810. r20:    db    0
  811. r18:    db    0
  812. r21:    dw    0
  813. ;
  814. ; ********* End Calculator *********
  815. ;
  816.  
  817. quit:    ; Turn off calculator
  818.  
  819.     ld    a,0dh
  820.     call    CharOut        ; Print carriage return to indicate
  821.                 ; Return to normal
  822.     call    TrigOn        ; Enable trigger key checking,
  823.                 ;  now that calculator no longer active.
  824. ;                ; "On" flag tells TrigOn to enable checking 
  825.     ld    a,(on)
  826.     cpl    
  827.     ld    (on),a        ; Flip calc. running flag to off
  828. ;
  829.     pop    hl    ; Restore registers 
  830.        pop    de
  831.     pop    bc
  832.     pop    af
  833.     pop    iy
  834.     pop    ix
  835. ;
  836.     ld    sp,(SavStk)    ; Restore stack pointer
  837. ;
  838.     jp    OrigIn        ; = Call BIOS ConIn, ret to transient program 
  839. ;
  840. ;
  841. TrigOff:    ; DISABLE trigger key detection 
  842.  
  843.     ld    a,(IsOn)    ; Is key detection off?
  844.     cp    0
  845.     jp    z,TrigOn    ; Yes, turn on
  846.     ld    a,0        ; No, flip flag and turn it off
  847.     ld    (IsOn),a
  848.     ld    hl,(JConIn)    ; Get place in BIOS to restore jump 
  849.     ld    de,(ConIn)    ; Get location of BIOS routine 
  850.     ld    (hl),e
  851.     inc    hl
  852.     ld    (hl),d        ; Put in a jp and the location
  853. ;
  854.     ld    a,(on)        ; Is calculator running?
  855.     or    a
  856.     ret    nz         ; Yes, just resume key detection,
  857.                 ;  don't tell user 
  858.     ld    de,OffMsg    ; Tell user trigger key de-activated
  859.     call    string
  860.     ret
  861.  
  862. string:    ld    c,9
  863.     jp    BDOS
  864. OnMsg:
  865.     db    'Trigger Key Enabled - Disable Before Re-loading RCP.$'
  866. OffMsg:
  867.     db    'Trigger Key Disabled.$'
  868. RCP$name:
  869.     db    'CALC-RCP ',(vers/10)+'0'
  870.     db    '.0',13,10    ;
  871.     db    'H',13,10
  872.     db    'CALC      - Enable/Disable Trigger Key',13,10
  873.     db    'Control-] - Calculator On/Off.$'
  874. OrigOut:
  875.     db    0c3h    ; Jp    
  876. con:    dw    0    ; Store BIOS console out routine address
  877. ;
  878. IsOn:    db    0    ; Trigger-key detection on flag
  879. ;
  880. OrigIn:
  881.     db    0c3h    ; jp
  882. ConIn:    dw    0    ; Store BIOS console in routine address  
  883. JConIn:    dw    0    ; Store BIOS jump to console in address
  884. ;
  885. on:    db    0    ; Calculator running flag
  886. ;
  887. SavStk:    ds    2    ; Save incoming stack pointer
  888. ;
  889.     ds    32
  890. NewStk    equ    $    ; Our own stack
  891.     
  892. ;
  893. ; Size error test
  894. ;
  895.     if    ($ gt (RCP+RCPs*128-1))
  896. SizErr    equ    novalue        ; RCP is too large for buffer
  897.     endif
  898. ;
  899.     end
  900.  
  901.     
  902. ;
  903. ; Size error test
  904. ;
  905.     if    ($ gt (RCP+RCPs*128-1))
  906. SizErr    equ    noval