home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / GEOSApps / RPN128-SRC.SFX / rpnroutines (.txt) < prev    next >
GEOS ConVerT  |  1990-02-12  |  23KB  |  952 lines

  1. RPNroutines
  2. SEQ formatted GEOS file V1.0
  3. Star NX-10
  4. OP V2.0 or higher
  5. ;"RPNconst
  6. BLASTER'S CONVERTER V2.5
  7. geosSym.RPN
  8. geosMac
  9. Write Image V2.1
  10. geoWrite    V2.0
  11. 0Event routines for RPN 64.
  12. d +# k" t
  13. .noeqin
  14.      @.include    geosSym
  15. .include    RPNconst
  16.      @include    geosMac
  17. graphicsMode  ==    $003f
  18. config    ==    $ff00
  19. .eqin
  20. Number:    
  21.         ;DEAL WITH ALL NUMBERS
  22.     CmpBI    INVFLG,true
  23.     bne    5$
  24. Number:    
  25.         ;DEAL WITH ALL NUMBERS
  26.     CmpBI    INVFLG,true
  27.     bne    5$
  28.     jsr    Inverse    ;Turn off INVFLG -- Inverse has no effect here
  29. 5$    MoveB    r0L,CurNumE    ;number of the icon pressed
  30.     CmpBI    F_ENTRY,true
  31.     beq    10$    ;If already within an entry, jump over init. code
  32.     LoadB    F_ENTRY,true    ;If no entry yet, Set the Entry Flag
  33.     LoadB    EnterStr,' '    ;Put space at start of EnterStr     (for "-" if needed)
  34.     LoadB    EnterPos,1    ;Set EnterStr pointer--- set other things
  35.     LoadB    ManDigits,$00    ; start with 0 digits in mantissa
  36.     sta    ExDigits    ; 0 digits in exponent
  37.     LoadB    F_FRACTION,false    ; no decimal point yet
  38.     sta    F_EXPON    ; no E yet
  39.     sta    F_NEG    ; start positive
  40.     sta    F_NEGE    ; exponent isn't negative
  41.     LoadW    TextXpos,$8000+DATA_LEFT*8+7  ;set the Text Prompt
  42.     LoadB    TextYpos,ENTRY_TOP*8+4
  43.     lda    #$08
  44.     jsr    InitTextPrompt
  45.     MoveW    TextXpos,stringX
  46.     MoveB    TextYpos,stringY
  47.     jsr    PromptOn
  48.     AddVB    $08,TextYpos
  49. 10$    CmpBI    F_EXPON,false    ;Check to see if on Exponent
  50.     beq    20$
  51.     CmpBI    ExDigits,$01    ;Make sure not too many exponent digits
  52.     beq    15$    ;If 1 digit, go to 1 digit handling routine
  53.     bcs    90$    ;If >1 digits, don't add another!
  54.     bra    25$    ;Otherwise, process digit
  55. 15$    ldy    EnterPos    ;If already 1 digit, make sure abs(exp) < 38
  56.     lda    EnterStr,y
  57.     sub    #$30    ;Convert to a number
  58.     sta    temp
  59.     asl    a
  60.     asl    a
  61.     asl    a
  62.     add    temp
  63.     adc    temp    ;a=10*a
  64.     adc    CurNumE    ;a=Exponent
  65.     adc    IPdigs    ;Add number of digits in integer part of Mantissa
  66.     cmp    #$28    ;Total must be less than 39
  67.     bcs    90$
  68.     bra    25$
  69. 20$    CmpBI    ManDigits,$0a    ;Make sure not too many mantissa digits
  70.     bcs    90$
  71.     beq    90$
  72. 25$    lda    CurNumE    ;Stick ASCII number to EnterStr
  73.     add    #$30
  74.     ldy    EnterPos
  75.     sta    EnterStr,y
  76.     inc    EnterPos
  77.     CmpBI    F_EXPON,false    ;Increment appropriate length pointer
  78.     beq    40$
  79.     inc    ExDigits
  80.     bra    50$
  81. 40$    inc    ManDigits
  82. 50$    lda    EnterStr,y
  83.     jsr    PrintA
  84.      @rts
  85. DecimalPoint:
  86.     CmpBI    INVFLG,true
  87.     bne    5$
  88.      @jmp    pi_R1
  89. 5$    CmpBI    F_ENTRY,true    ;If not an entry yet, do a 0
  90.     beq    10$
  91.     LoadB    r0L,$00
  92.     jsr    Number
  93.     bra    20$
  94. 10$    CmpBI    F_FRACTION,true    ;If there already is a ".", don't add another
  95.     bne    15$
  96.      @rts
  97. 15$    CmpBI    F_EXPON,true    ;No decimal points in the exponent!
  98.     bne    20$
  99.      @rts
  100. 20$    LoadB    F_FRACTION,true
  101.     lda    #'.'
  102.     ldy    EnterPos    ;stick a '.' in the string
  103.     sta    EnterStr,y
  104.     inc    EnterPos
  105.     jsr    PrintA
  106.      @rts
  107. Scinot:            
  108. ;Scientific Notation -- handler for E icon
  109.     CmpBI    INVFLG,true
  110.     bne    5$
  111.     jsr    Inverse    ;Just turn off Inverse Flag
  112. 5$    CmpBI    F_ENTRY,true    ;If not working on an entry, E does nothing
  113.     beq    10$
  114.      @rts
  115. 10$    CmpBI    F_EXPON,true    ;Check if already have an exponent
  116.     bne    20$
  117.      @rts
  118. 20$    LoadB    F_EXPON,true
  119.     LoadB    ExDigits,0
  120.     lda    #'E'
  121.     ldy    EnterPos    ;stick a 'E' in the string
  122.     sta    EnterStr,y
  123.     inc    EnterPos
  124.     jsr    PrintA
  125.     MoveW    TextXpos,EsignX    ;Save this position for placing sign on exponent
  126.     MoveB    EnterPos,Epos
  127.     lda    #' '    ;and a space (for negative)
  128.     ldy    EnterPos
  129.     sta    EnterStr,y
  130.     inc    EnterPos
  131.     jsr    PrintA
  132.     ldy    #$00
  133. 30$    iny
  134.     lda    EnterStr,y
  135.     cmp    #'.'
  136.     beq    40$
  137.     cmp    #'E'
  138.     beq    40$
  139.     bra    30$
  140. 40$    sty    IPdigs    ;Number of digits in integer part of mantissa...
  141.      @rts
  142. AddNums:
  143.      @jsr    INVENT
  144.     ;Deal with INVFLG and F_ENTRY
  145.     jsr    R1_F1    ;Move F.P. Reg #1 to FAC1
  146.      @jsr    GETBASIC
  147.     lda    #<Reg2
  148.     ldy    #>Reg2
  149.     jsr    fadd
  150.      @jsr    FLUSHBASIC
  151.     jsr    F1_R2    ;Move FAC1 to F
  152. AddNums:
  153.      @jsr    INVENT
  154.     ;Deal with INVFLG and F_ENTRY
  155.     jsr    R1_F1    ;Move F.P. Reg #1 to FAC1
  156.      @jsr    GETBASIC
  157.     lda    #<Reg2
  158.     ldy    #>Reg2
  159.     jsr    fadd
  160.      @jsr    FLUSHBASIC
  161.     jsr    F1_R2    ;Move FAC1 to F.P. Reg #2
  162.     jsr    Raise    ;Move each F.P. Reg up
  163.      @    jmp    PostOPrint
  164.     ;Print out Registers (Post-Operation)
  165. SubNums:
  166.      @jsr    INVENT
  167.     jsr    R1_F1
  168.      @jsr    GETBASIC
  169.     lda    #<Reg2
  170.     ldy    #>Reg2
  171.     jsr    fsub
  172.      @jsr    FLUSHBASIC
  173.     jsr    F1_R2
  174.     jsr    Raise
  175.      @    jmp    PostOPrint
  176. MultNums:
  177.      @jsr    INVENT
  178.     jsr    R1_F1
  179.     LoadW    a0,Reg2    ;Point to Reg2
  180.      @jsr    Do_Mult
  181.     ;Does the multiplication, checks overflow
  182.     CmpBI    temp,$00    ;non-0 indicates overflow error
  183.     beq    10$
  184.      @jmp    OvFloErr
  185. 10$    jsr    F1_R2
  186.     jsr    Raise
  187.      @jmp    PostOPrint
  188. DivNums:
  189.      @jsr    INVENT
  190.     jsr    R1_F1
  191.      @jsr    GETBASIC
  192.     jsr    fsgna    ;Check to make sure R1<>0
  193.     cmp    #$00
  194.     bne    10$
  195.      @jsr    FLUSHBASIC
  196.     jmp    ErrorMess
  197. 10$    lda    #<Reg2
  198.     ldy    #>Reg2
  199.     jsr    fdiv
  200.      @jsr    FLUSHBASIC
  201.     jsr    F1_R2
  202.     jsr    Raise
  203.      @    jmp    PostOPrint
  204. Expo:            
  205. ;R2^R1
  206.      @jsr    INVENT
  207.     jsr    R2_F1    ;Check that R2 is positive
  208.      @jsr    GETBASIC
  209.     jsr    fsgna    ;Find sign of FAC1
  210.     cmp    #$01
  211.     beq    10$    ;Continue if positiv
  212. Expo:            
  213. ;R2^R1
  214.      @jsr    INVENT
  215.     jsr    R2_F1    ;Check that R2 is positive
  216.      @jsr    GETBASIC
  217.     jsr    fsgna    ;Find sign of FAC1
  218.     cmp    #$01
  219.     beq    10$    ;Continue if positive
  220.      @    jsr    FLUSHBASIC
  221.      @    jmp    ErrorMess
  222. jsr    flog
  223.     LoadW    a0,Reg1
  224.     jsr    Do_Mult    ;Fac1 = Reg1*log(Reg2)   [will flush BASIC for us]
  225.     CmpBI    temp,$00
  226.     beq    20$
  227.      @jmp    OvFloErr
  228. 20$    jsr    Do_AntiLog    ;Fac1 = Exp(Reg1*log(Reg2)) = Reg2 ^ Reg1
  229.     CmpBI    temp,$00
  230.     beq    30$
  231.      @jmp    OvFloErr
  232. 30$    jsr    F1_R2
  233.     jsr    Raise
  234.      @    jmp    PostOPrint
  235.      Hpi_R1:
  236.      @jsr    Inverse
  237.     ;turn off inverse
  238.     CmpBI    F_ENTRY,true
  239.     bne    5$
  240.      @jsr    Do_Enter
  241. 5$    jsr    Sink    ;Move 1-7 down
  242.      @jsr    GETBASIC
  243.     lda    #<fpi
  244.     ldy    #>fpi
  245.     jsr    memfac1
  246.     ldx    #<Reg1
  247.     ldy    #>Reg1
  248.     jsr    fac1mem    ;Copy pi to Reg1
  249.      @jsr    FLUSHBASIC
  250.     jmp    PrintRegs
  251.     ;Print all registers    
  252.      @INVENT:            
  253. ;Routine that checks for Inverse, does nothing
  254.             ;Checks for Entry, does an "Enter" if necessary
  255.      @INVENT:            
  256. ;Routine that checks for Inverse, does nothing
  257.             ;Checks for Entry, does an "Enter" if necessary
  258.     CmpBI    INVFLG,true
  259.     bne    5$
  260.      @jmp    Inverse
  261.     ;INV/whatever is nothing
  262. 5$    CmpBI    F_ENTRY,true
  263.     bne    10$
  264.     LoadB    oprint,false
  265.      @jmp    Do_Enter
  266. 10$    LoadB    oprint,true
  267.      @rts
  268. PostOPrint:        
  269. ;Support routine, print appropriate regs after operation
  270.     CmpBI    oprint,true
  271.     bne    10$
  272.      @jmp    PrintRegs
  273.      @jmp    PrintR1
  274. Delete:
  275.     CmpBI    INVFLG,true
  276.     bne    5$
  277.     jsr    Inverse
  278. 5$    CmpBI    F_ENTRY,true
  279.     bne    80$
  280. 10$    CmpBI    F_EXPON,false
  281.     beq    20$
  282.     lda    ExDigits    ;Subtract 1 from current digit counter
  283.     beq    80$    ;(Skip if ExDigits=0)
  284.     sub    #$01
  285.     sta    ExDigits
  286.     bra    30$
  287. 20$    lda    ManDigits
  288.     beq    80$    ;(Skip if ManDigits=0)
  289.     sub    #$01
  290.     sta    ManDigits
  291.     bra    30$
  292.      @80$    jmp    end_Delete
  293. 30$    ldy    EnterPos    ;First, blank last character of string, dec. pointer
  294.     sty    EnterPos
  295.     lda    EnterStr,y
  296.     tax        ;save identity of character in x
  297.     cmp    #'.'    ;(Check for decimal point)
  298.     bne    40$
  299.     inc    ManDigits    ;If a decimal point, we aren't removing a digit!
  300.     LoadB    F_FRACTION,false    ;We just deleted the decimal point
  301. 40$    lda    #$00
  302.     sta    EnterStr,y
  303.     txa        ;Blank space on screen- draw rect. of char's width
  304.     jsr    GetCharWidth
  305.     sta    temp
  306.     lda    #$00
  307.     sta    temp2    ;High byte of temp = 0
  308.     jsr    SetPattern    ;Set for clearing
  309.     LoadB    r2L,ENTRY_TOP*8+1
  310.     LoadB    r2H,(ENTRY_TOP+2)*8-2
  311.     MoveW    TextXpos,r4
  312.     SubW    temp,TextXpos    ;Subtract the width from TextXpos
  313.     MoveW    TextXpos,r3
  314.     jsr    Rectangle    ;Do the clear
  315.     MoveW    TextXpos,stringX    ;Reset Prompt position back
  316.     lda    TextYpos
  317.     sub    #$08
  318.     sta    stringY
  319.     jsr    PromptOn
  320.      @end_Delete: rts
  321.      @end_Delete: rts
  322. Number of digits in integer part of mantissa...
  323. Enter:
  324.     CmpBI    INVFLG,true
  325.     bne    5$
  326.     jmp    PrintInfo
  327. 5$    CmpBI    F_ENTRY,true
  328.     beq    10$
  329.      @jmp    Duplicate
  330. 10$    jsr    Do_Enter
  331.     jsr    PrintRegs    ;Print all F.P. Registers
  332.      @rts
  333.      @Do_Enter:
  334.     ldy    EnterPos
  335.     lda    #$00    ;Make sure EnterStr is 0 terminated
  336.     sta    EnterStr,y
  337. LoadW    PPDBtxt,befSink
  338. jsr    PausePrint
  339.     jsr    Sink    ;Move Regs down
  340.     LoadW    PPDBtxt,aftSink
  341. ;    jsr    PausePrint
  342.     ldx    #$09
  343. 10$    lda    EnterStr,x    ;Move Enter String to System String
  344.     sta    systring,x
  345.     bpl    10$
  346.     jsr    ASCIIDEC    ;translate the system string to fac1
  347. LoadW    PPDBtxt,aftASC
  348. ;    jsr    PausePrint
  349.     jsr    F1_R1    ;copy fac1 to reg1
  350. LoadW    PPDBtxt,aftF1R1
  351. ;    jsr    PausePrint
  352.     jsr    ClrEntry    ;Clear enterline, EnterStr, EnterPos
  353. LoadW    PPDBtxt,aftClrE
  354. ;    jsr    PausePrint
  355.     LoadB    F_ENTRY,false
  356.      @rts
  357. befSink:    .byte    "Before Sink",0
  358. aftSink:    .byte    "After Sink",0
  359. aftASC:    .byte    "After ASCIIDEC",0
  360. ;aftF1R1:    .byte    "After F1_R1",0
  361. ;aftClrE:    .byte    "After ClrEntry",0
  362. Duplicate:
  363.         ;ENTER when no entry in progress is a DUP -- copy
  364.     jsr    Sink    ; Reg1 to Reg2, move 2-3, 3-4 etc.
  365.     jsr    PrintRegs
  366.      @rts
  367. PrintInfo:
  368. jsr    ClearData    ;Clear the Data 
  369. PrintInfo:
  370. jsr    ClearData    ;Clear the Data Screen
  371.     LoadW    leftMargin,$8000+DATA_LEFT*8+4
  372.     jsr    i_PutString
  373. screen1:    .word    $8000+DATA_LEFT*8+4
  374.     .byte    DATA_TOP*8+12
  375.     .byte    24,"Hints:",27,13,13,"INV-SWAP is ROLL"
  376.     .byte    13,"INV-DROP is ROLLD"
  377.     .byte    13,"INV-Min is MR"
  378.     .byte    13,"INV-. is pi"
  379.     .byte    13,13,"(Click to continue)",0
  380. 10$    CmpBI    mouseData,%10000000    ;Wait for click
  381.     bne    20$
  382.     bra    10$
  383. 20$    jsr    ClearData
  384.     LoadW    leftMargin,$8000+DATA_LEFT*8+4
  385.     jsr    i_PutString
  386. screen2:    .word    $8000+DATA_LEFT*8+4
  387.     .byte    DATA_TOP*8+12
  388.     .byte    24,"Key Shortcuts:",27,13,13
  389.     .byte    "Return -- Enter",13,"f1 -- Inverse",13
  390.     .byte    "f3 -- Swap",13,"f5 -- Drop",13
  391.     .byte    "f7 -- +/-",13,"m -- Mem. In.",13,"q -- quit",13,13
  392.     .byte    "(Click to Continue)",0
  393. 30$    CmpBI    mouseData,%10000000    ;Wait for click
  394.     bne    40$
  395.     bra    30$
  396. 40$    jsr    ClearData
  397.     LoadW    leftMargin,$8000+DATA_LEFT*8+4
  398.     jsr    i_PutString
  399. screen3:    .word    $8000+DATA_LEFT*8+4
  400.     .byte    DATA_TOP*8+12
  401.     .byte    24,"Key Shortcuts:",27,13,13
  402.     .byte    "s -- sin",13,"c -- cos",13,"t -- tan",13
  403.     .byte    "v -- Sqr. Root",13,"r -- 1/x",13
  404.     .byte    "l -- ln",13,13
  405.     .byte    "(Click to continue)",0
  406. 42$    CmpBI    mouseData,%10000000    ;Wait for click
  407.     bne    47$
  408.     bra    42$
  409. 47$    jsr    ClearData
  410.     LoadW    leftMargin,$8000+DATA_LEFT*8+4
  411.     jsr    i_PutString
  412. screen4:    .word    $8000+DATA_LEFT*8+4
  413.     .byte    DATA_TOP*8+12
  414.     .byte    13,13,"The Masked Nerd",13,"Was Here!",0
  415. 50$    CmpBI    mouseData,%10000000
  416.     bne    60$
  417.     bra    50$
  418. 60$    LoadW    leftMargin,#$00
  419.     jsr    ClearData
  420.     jsr    PrintRegs
  421.      @jmp    Inverse
  422.     ;Jump to Inverse to turn off the Inverse Flag
  423. SignChange:
  424.     CmpBI    INVFLG,true
  425.     bne    5$
  426.     jsr    Inverse
  427. 5$    CmpBI    F_ENTRY,tr
  428. SignChange:
  429.     CmpBI    INVFLG,true
  430.     bne    5$
  431.     jsr    Inverse
  432. 5$    CmpBI    F_ENTRY,true
  433.     beq    10$    ;If no entry, change sign of Reg. 1
  434.      @jmp    screg1
  435.     ;Rest of this routine deals with Enter String
  436. 10$    CmpBI    F_EXPON,true    ;Check to see if we change sign of exponent
  437.     beq    30$
  438.     CmpBI    F_NEG,true
  439.     beq    15$
  440.     LoadB    F_NEG,true
  441.     lda    #'-'
  442.     bra    20$
  443. 15$    LoadB    F_NEG,false
  444.     lda    #' '
  445. 20$    MoveW    TextXpos,tmpblk    ;Save cursor position
  446.     LoadW    TextXpos,$8000+DATA_LEFT*8+4
  447.     pla        ;Character of sign was pushed on stack
  448.     sta    EnterStr
  449.     jsr    PrintA
  450.     MoveW    tmpblk,TextXpos    ;Restore cursor position
  451.      @rts
  452. 30$    CmpBI    F_NEGE,true
  453.     beq    40$
  454.     LoadB    F_NEGE,true
  455.     lda    #'-'
  456.     bra    50$
  457. 40$    LoadB    F_NEGE,false
  458.     lda    #' '
  459. 50$    MoveW    TextXpos,tmpblk
  460.     MoveW    EsignX,TextXpos
  461.     ldy    Epos
  462.     sta    EnterStr,y
  463.     jsr    PrintA
  464.     MoveW    tmpblk,TextXpos
  465.      @rts
  466.      @screg1:
  467.         ;Sign Change on Register 1
  468.     lda    Reg1+1
  469.     eor    #%10000000    ;Flip sign bit
  470.     sta    Reg1+1    ;Save mauled top byte of m
  471.      @screg1:
  472.         ;Sign Change on Register 1
  473.     lda    Reg1+1
  474.     eor    #%10000000    ;Flip sign bit
  475.     sta    Reg1+1    ;Save mauled top byte of mantissa
  476.     jsr    PrintR1    ;Print out mauled register
  477.      @rts
  478.      @;END OF SIGNCHANGE
  479.     CmpBI    INVFLG,true    ;Check inverse- if set, jump to inverse of function
  480.     bne    10$
  481.      @jmp    ArcSin
  482.      @jsr    PreFunc
  483.     ;Do general Pre-Function setup subroutine
  484.     jsr    R1_F1
  485.      @jsr    GETBASIC
  486.     jsr    fsin
  487.      @jsr    FLUSHBASIC
  488.     jsr    F1_R1
  489.      @    jmp    PostOPrint
  490.     ;Post-operation print-F.P. Regs routine
  491.     CmpBI    INVFLG,true
  492.     bne    10$
  493.      @jmp    ArcCos
  494.      @jsr    PreFunc
  495.     jsr    R1_F1
  496.      @jsr    GETBASIC
  497.     jsr    fcos
  498.      @jsr    FLUSHBASIC
  499.     jsr    F1_R1
  500.      @    jmp    PostOPrint
  501. 5$    CmpBI    F_ENTRY,true
  502.     bne    10byte    $80+PADLEFT+7
  503.     .byte    (DA_TOP+7)*8
  504.     .byte    $80+Ia    keytable,y    ;put routine vector @ temp (lb) & temp2 (hb)
  505.     sta    temp
  506.     lda    keytable,y
  507. 8!8%9
  508.     CmpBI    INVFLG,true
  509.     bne    10$
  510.      @jmp    ArcTan
  511.      @jsr    PreFunc
  512.      @jsr    GETBASIC
  513.     lda    #<fpi
  514.     ldy    #>fpi
  515.     jsr    memfac1
  516.     lda    #<fhalf
  517.     ldy    #>fhalf
  518.     jsr    fmult
  519.     lda    #<Reg1
  520.     ldy    #>Reg1
  521.     jsr    fsub    ;Fac1 = Reg1 - pi/2
  522.     lsr    facsgn    ;Fac1 = |Reg1 - pi/2|   (clear bit 7)
  523.     ldx    #<fvar
  524.     ldy    #>fvar
  525.     jsr    fac1mem
  526.     lda    #<fpi
  527.     ldy    #>fpi
  528.     jsr    memfac1
  529.     lda    #<fvar
  530.     ldy    #>fvar
  531.     jsr    fdiv    ;Divide |Reg1-pi/2|/pi
  532.     ldx    #<fvar
  533.     ldy    #>fvar
  534.     jsr    fac1mem
  535.     jsr    fint
  536.     lda    #<fvar
  537.     ldy    #>fvar
  538.     jsr    fcompare    ;Check to see if fac1 = int(fac1)
  539.     cmp    #$00    ;a=0 indicates fac1 is an integer... thus error!
  540.     bne    20$
  541.      @    jsr    FLUSHBASIC
  542.     jmp    ErrorMess
  543. 20$    lda    #<Reg1
  544.     ldy    #>Reg1
  545.     jsr    memfac1
  546.     jsr    ftan
  547.      @jsr    FLUSHBASIC
  548.     jsr    F1_R1
  549.      @    jmp    PostOPrint
  550. Sqrt:
  551.     CmpBI    INVFLG,true
  552.     bne    10$
  553.      @jmp    Square
  554.      @jsr    PreFunc
  555.     jsr    R1_F1
  556.      @jsr    GETBASIC
  557.     jsr    fsgna    ;Check sign of R1
  558.     cmp    #$ff
  559.     bne    20$    ;Continue if not negative
  560.      @    jsr    FLUSHBASIC
  561.     jmp    ErrorMess
  562. 20$    jsr    fsqrt
  563.      @jsr    FLUSHBASIC
  564.     jsr    F1_R1
  565.      @    jmp    PostOPrint
  566. Recip:
  567.             ;1/x
  568.     CmpBI    INVFLG,true
  569.     bne    10$
  570.      @jsr    Inverse
  571.     ;Just turn off Inverse
  572. Recip:
  573.             ;1/x
  574.     CmpBI    INVFLG,true
  575.     bne    10$
  576.      @jsr    Inverse
  577.     ;Just turn off Inverse
  578.      @jsr    PreFunc
  579.     jsr    R1_F1
  580.     CmpBI    stofac1,#$00    ;BASIC is out, so look at exponent of 
  581. stofac1
  582.     bne    20$    ;If facexp is 0, this is an error (1/0)
  583.      @    jmp    ErrorMess
  584.      @jsr    GETBASIC
  585. lda    #<fone
  586.     ldy    #>fone
  587.     jsr    fdiv
  588.      @    jsr    FLUSHBASIC
  589.     jsr    F1_R1
  590.      @jsr    PostOPrint
  591.     CmpBI    INVFLG,true
  592.     bne    10$
  593.      @jmp    AntiLog
  594.      @jsr    PreFunc
  595.     jsr    R1_F1
  596.      @jsr    GETBASIC
  597. jsr    fsgna    ;Check that R1>0
  598.     cmp    #$01
  599.     beq    20$    ;if R1>0, ok to continue
  600.      @jsr    FLUSHBASIC
  601.     jmp    ErrorMess
  602. 20$    jsr    flog
  603.      @jsr    FLUSHBASIC
  604.     jsr    F1_R1
  605.      @    jmp    PostOPrint
  606. ArcSin:
  607.             ;ASIN(X)=ATN(X/SQRT(-X*X+1))
  608.      @    jsr    Inverse
  609.     jsr    PreFunc
  610.     jsr    FunkyAtan    ;Calculates the ASIN
  611.     CmpBI    temp,#$00    ;temp has error return status
  612.     beq    10$
  613.      @jmp    ErrorMess
  614.      @jmp    PostOPrint
  615. ArcCos:
  616.             ;ACOS(X)=-ATN(X/SQR(-X*X+1))+PI/2 = -ASIN(X)+PI/2
  617.      @jsr    Inverse
  618.     jsr    PreFunc
  619.     jsr    FunkyAtan
  620.     CmpBI    temp,#$00    ;temp has error return status
  621.     beq    10$
  622.      @jmp    ErrorMess
  623. 10$    lda    Reg1+1
  624.     eor    #%10000000
  625.     sta    Reg1+1
  626.     LoadW    r5,Reg1
  627.     LoadW    r6,fvar
  628.     ldx    #r5
  629.     ldy    #r6
  630.     lda    #$05
  631.     jsr    CopyFString    ;Copy Reg1 to tmpblk
  632.      @jsr    GETBASIC
  633.     lda    #<fpi
  634.     ldy    #>fpi
  635.     jsr    memfac1
  636.     lda    #<fhalf
  637.     ldy    #>fhalf
  638.     jsr    fmult    ;Faci = 0.5*pi
  639.     lda    #<fvar
  640.     ldy    #>fvar
  641.     jsr    fadd
  642.      @jsr    FLUSHBASIC
  643.     jsr    F1_R1
  644.      @    jmp    PostOPrint
  645. ArcTan:
  646.      @jsr    Inverse
  647.     ;turn off Inverse
  648.      @jsr    PreFunc
  649.     jsr    R1_F1
  650.      @jsr    GETBASIC
  651.     jsr    fatan
  652.      @jsr    FLUSHBASIC
  653.     jsr    F1_R1
  654.      @jmp    PostOPrint
  655.      @FunkyAtan:
  656.      @FunkyAtan:
  657.         ;Calculates the ATN used in both ASIN and ACOS
  658.     jsr    R1_F1
  659.      @jsr    GETBASIC
  660.     lsr    facsgn    ;Take absoulute value of FAC1
  661.     lda    #<fone
  662.     ldy    #>fone
  663.     jsr    fcompare    ;Compare 1 to fac1 ( |R1| )
  664.     cmp    #$ff    ;$ff indicates 1 > fac1
  665.     beq    10$    ;If |R1|>1, arcsin or arccos won't work!
  666.      @jsr    FLUSHBASIC
  667.     LoadB    temp,$ff    ;$ff in temp Indicates an error
  668.      @    rts
  669. 10$    LoadB    temp,$00    ;no error if we are continuing
  670.     lda    #<Reg1
  671.     ldy    #>Reg1
  672.     jsr    memfac1
  673.     lda    #<Reg1
  674.     ldy    #>Reg1
  675.     jsr    fmult    ;R1*R1
  676.     lda    facsgn
  677.     eor    #$ff    ;Flip the sign bit
  678.     sta    facsgn
  679.     lda    #<fone
  680.     ldy    #>fone
  681.     jsr    fadd    ;add 1
  682.     jsr    fsqrt
  683.     lda    #<Reg1
  684.     ldy    #>Reg1
  685.     jsr    fdiv    ;X/Fac1 = X/SQRT(-X*X+1)
  686.     jsr    fatan
  687.      @jsr    FLUSHBASIC
  688.     jsr    F1_R1
  689.      @    rts
  690.      @PreFunc:
  691.             ;Pre-function general setup routine
  692.     CmpBI    F_ENTRY,true
  693.     bne    10$
  694.     LoadB    oprint,true
  695.      @jmp    Do_Enter
  696. 10$    LoadB    oprint,false
  697.      @    rts
  698. Square:
  699.     jsr    Inverse    ;turn off inverse flag
  700.      @    jsr    PreFunc
  701. Square:
  702.     jsr    Inverse    ;turn off inverse flag
  703.      @    jsr    PreFunc
  704.     jsr    R1_F1
  705.     LoadW    a0,Reg1
  706.     jsr    Do_Mult    ;Does the multiplication and checks for overflow
  707.     lda    temp
  708.     beq    10$
  709.      @    jmp    OvFloErr
  710. 10$    jsr    F1_R1
  711.      @    jmp    PostOPrint
  712. AntiLog:
  713.     jsr    Inverse    ;turn off inverse flag
  714.      @jsr    PreFunc
  715.     jsr    R1_F1
  716.     jsr    Do_AntiLog
  717.     lda    temp
  718.     beq    10$
  719.      @jmp    OvFloErr
  720. 10$    jsr    F1_R1
  721.      @jmp    PostOPrint
  722.     ldy    #>Reg1
  723.     jsr    memfac1
  724.     lda    #<Reg1
  725.     ldy    
  726.      @Do_Mult:
  727.             ;Multiplies FAC1 * (a0) ; returns $ff in temp
  728.                 ; if overflow
  729.      @jsr    GETBASIC
  730.     ldy    #$00
  731.     lda    (a0),y
  732.     add    facexp
  733.     bcc    50$    ;If carry is clear, no overflow
  734.     and    #%10000000
  735.     cmp    #$00
  736.     beq    50$    ;If carry set, high bit clear, no overflow
  737.     LoadB    temp,$ff
  738.     bra    60$
  739. 50$    LoadB    temp,$00
  740.     lda    a0L
  741.     ldy    a0H
  742.     jsr    fmult
  743.      @jsr    FLUSHBASIC
  744. Do_AntiLog:
  745.     jsr    GETBASIC
  746.     ldx    #<fvar
  747.     ldy    #>fvar
  748.     jsr    fac1mem
  749.     lda    #$00
  750.     ldy    #$58    ;$58=88; exp(88) is the highest possible
  751.     jsr    givayf    ;(actually 88.03, but 88 is close enough)
  752.     lda    #<fvar
  753.     ldy    #>fvar
  754.     jsr    fcompare
  755.     cmp    #$ff    ;$ff indicates fvar>88
  756.     bne    10$
  757.     LoadB    temp,$ff
  758.     bra    20$
  759. 10$    LoadB    temp,$00
  760.     lda    #<fvar
  761.     ldy    #>fvar
  762.     jsr    memfac1
  763.     jsr    fe_to
  764.      @    jsr    FLUSHBASIC
  765.     CmpBI    INVFLG,true
  766.     bne    5$
  767.      @    jmp    Roll
  768.     ;INV-Swap is Roll 8
  769. 5$    CmpBI    F_ENTRY,true
  770.     bne    10$
  771.      @jsr    Do_Enter
  772. 10$    LoadW    r5,Reg1    ;Reg1 -> fvar
  773.     LoadW    r6,fvar
  774.     ldx    #r5
  775.     ldy    #r6
  776.     lda    #$05
  777.     CmpBI    INVFLG,true
  778.     bne    5$
  779.      @    jmp    Roll
  780.     ;INV-Swap is Roll 8
  781. 5$    CmpBI    F_ENTRY,true
  782.     bne    10$
  783.      @jsr    Do_Enter
  784. 10$    ldx    #$04    ;Copy 5 bytes
  785. 15$    lda    Reg1,x    ;Reg1->tempororay
  786.     sta    r0L
  787.     lda    Reg2,x    ;Reg2->Reg1
  788.     sta    Reg1,x
  789.     lda    r0L    ;temporary->Reg2
  790.     sta    Reg2,x
  791.     bpl    15$
  792. ;    LoadW    r5,Reg1    ;Reg1 -> fvar
  793. ;    LoadW    r6,fvar
  794. ;    ldx    #r5
  795. ;    ldy    #r6
  796. ;    lda    #$05
  797. ;    jsr    CopyFString
  798. ;    LoadW    r5,Reg2    ;Reg2 -> Reg1
  799. ;    LoadW    r6,Reg1
  800. ;    ldx    #r5
  801. ;    ldy    #r6
  802. ;    lda    #$05
  803. ;    jsr    CopyFString
  804. ;    LoadW    r5,fvar    ;fvar -> Reg2
  805. ;    LoadW    r6,Reg2
  806. ;    ldx    #r5
  807. ;    ldy    #r6
  808. ;    lda    #$05
  809. ;    jsr    CopyFString
  810.     jsr    PrintRegs    ;Print out all registers
  811.      @rts
  812. Drop:
  813.     CmpBI    INVFLG,true
  814.     bne    5$
  815.      @jmp    RollDown
  816.     ;INV-Drop is RollDown 8
  817. 5$    CmpBI    F_ENTRY,true
  818.     bne    10$
  819.     jsr    ClrEntry
  820.     LoadB    F_ENTRY,false
  821.      @rts
  822. 10$    jsr    Raise
  823.     jsr    PrintRegs
  824.      @rts
  825. Do_Enter
  826. 10$    LoadB    oprint,false
  827.      @    rts
  828. r    FLUSHBASIC
  829.     jsr    F1_R1
  830.      @jmp    PostOPrint
  831.      @    jsr    FLUSHBASIC
  832.     jmp    ErrorMess
  833. 20$    js
  834. Roll:
  835.     jsr    Inverse    ;turn off inverse
  836.     CmpBI    F_ENTRY,true
  837.     bne    10$
  838.      @jsr    Do_Enter
  839. 10$    LoadW    r5,Reg8    ;Reg8 -> fvar
  840.     LoadW    r6,fvar
  841.     ldx    #r5
  842.     ldy    #r6
  843.     lda    #$05
  844.     jsr    CopyFString
  845.     jsr    Sink    ;Move Regs down
  846.     LoadW    r5,fvar    ;fvar -> Reg1
  847.     LoadW    r6,Reg1
  848.     ldx    #r5
  849.     ldy    #r6
  850.     lda    #$05
  851.     jsr    CopyFString
  852.     jsr    PrintRegs
  853.      @rts
  854. RollDown:
  855.     jsr    Inverse    ;turn off inverse
  856.     CmpBI    F_ENTRY,true
  857.     bne    10$
  858.      @jsr    Do_Enter
  859. 10$    LoadW    r5,Reg1    ;Reg1 -> fvar
  860.     LoadW    r6,fvar
  861.     ldx    #r5
  862.     ldy    #r6
  863.     lda    #$05
  864.     jsr    CopyFString
  865.     jsr    Raise    ;Move Regs up
  866.     LoadW    r5,fvar    ;fvar -> Reg8
  867.     LoadW    r6,Reg8
  868.     ldx    #r5
  869.     ldy    #r6
  870.     lda    #$05
  871.     jsr    CopyFString
  872.     jsr    PrintRegs
  873.      @rts
  874. Memin:
  875.     CmpBI    INVFLG,true
  876.     bne    
  877. Memin:
  878.     CmpBI    INVFLG,true
  879.     bne    10$
  880.      @jmp    MemRec
  881. 10$    CmpBI    F_ENTRY,true
  882.     bne    20$
  883.      @jsr    Enter    
  884. ;Do a full-blown Enter
  885. 20$    LoadW    r5,Reg1
  886.     LoadW    r6,RegMem
  887.     ldx    #r5
  888.     ldy    #r6
  889.     lda    #$05
  890.     jsr    CopyFString
  891.      @rts
  892. MemRec:
  893.     CmpBI    F_ENTRY,true
  894.     bne    10$
  895.     jsr    Do_Enter
  896. 10$    jsr    Sink
  897.     LoadW    r5,RegMem
  898.     LoadW    r6,Reg1
  899.     ldx    #r5
  900.     ldy    #r6
  901.     lda    #$05
  902.     jsr    CopyFString
  903.     jsr    PrintRegs
  904.      @jmp    Inverse
  905. Inverse:
  906.     CmpBI    INVFLG
  907. Inverse:
  908.     CmpBI    INVFLG,true
  909.     beq    10$
  910.     LoadB    INVFLG,true
  911.     jsr    i_BitmapUp    ;Draw indicator
  912.     .word    INVpic
  913.     .byte    $80+L_INV_IND
  914.     .byte    T_INV_IND*8
  915.     .byte    $80+2
  916.     .byte    8
  917.      @rts
  918. 10$    LoadB    INVFLG,false
  919.     lda    #$00
  920.     jsr    SetPattern    ;Set pattern to white
  921.     jsr    i_Rectangle    ;clear indicator
  922.     .byte    T_INV_IND*8
  923.     .byte    (T_INV_IND+1)*8-1
  924.     .word    $8000+L_INV_IND*8
  925.     .word    $8000+(L_INV_IND+2)*8   ;(This clears one extra pixel- so what?)
  926.      @rts
  927. INVpic:
  928.      HQuitRPN:
  929.     jsr    i_MoveData    ;Restore applications's zero page space
  930.     .word    appzpage
  931.     .word    $0061
  932.     .word    $009e
  933.      @jmp    RstrAppl
  934.     ;return to application!
  935.      @;Nous avons fini !!!!
  936. @jmp    RstrAppl
  937.     ;return to application!
  938.      @;Nous avons fini !!!!
  939. $    CmpBI    F_E
  940.     CmpBI    temp,#$00    ;temp has error return status
  941.     beq    10$
  942.      @jmp    ErrorMess
  943.      @jmp    PostOPrint
  944. ArcCos:
  945.             ;ACOS
  946.     CmpBI    temp,#$00    ;temp has error return status
  947.     beq    10$
  948.      @jmp    ErrorMess
  949.      @jmp    PostOPrint
  950. ArcCos:
  951.             ;ACOS(X)=-ATN(X/SQR(-X*X+1))+PI/2 = -
  952.