home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / newfrac.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  4.1 KB  |  186 lines

  1. ;  newFrac v1.0 by Keith Batten
  2. ;
  3. ;    Input:
  4. ;     store the real you want to conver into 'inFrac'
  5. ;    Output:
  6. ;     'Ans' holds 0 if failed or 1 if successful
  7. ;     'num' holds the numberator if successful
  8. ;     'den' holds the denominator if successful
  9. ;
  10.  
  11. #include "asm86.h"
  12. #include "Ti86asm.inc"
  13. #include "Ti86ops.inc"
  14. #include "ti86abs.inc"
  15. #include "ti86math.inc"
  16.  
  17. _ioPrompt                 equ         0C324h
  18. _PTempCnt                 equ         0D293h
  19. _CLEANTMP                 equ         0D295h
  20. _ASAP_IND                 equ         0D623h
  21.  
  22. .org _asm_exec_ram
  23.  
  24.    nop
  25.    jp    Start
  26.    .dw   0000h
  27.    .dw   Description          ; set the description for a shell
  28. Description:
  29.    .db   $05,"NewFrac v1.0 KWB",0
  30.  
  31. Start:
  32.  
  33. checkfor_inFrac:
  34.    ld    hl, inFrac_op        ; check for 'inFrac' variable
  35.    rst   20h                  ; ld (op1) with (hl)
  36.    call  _FINDSYM             ; is there a variable 'inFrac'?
  37.    jp    c, nofrac            ; no, so quit
  38.  
  39.    ex de, hl
  40.    ld a, b
  41.    call _SET_ABS_SRC_ADDR
  42.  
  43.    ld hl, _OP2
  44.    xor a
  45.    call _SET_ABS_DEST_ADDR
  46.    ld hl, 10
  47.    xor a
  48.    call _SET_MM_NUM_BYTES
  49.    call _mm_ldir
  50.  
  51. write_vars:
  52.    ld    hl, num_op           ; check for 'num' variable
  53.    rst   20h                  ; ld (op1) with (hl)
  54.    call  _FINDSYM             ; is there a variable 'num'?
  55.    jr    c, check_den         ; no, so continue
  56.    call  _delvar              ; delete 'num' using data from _FINDSYM
  57.    jr    check_den
  58.  
  59. check_den:
  60.    ld    hl, den_op           ; check for 'den' variable
  61.    rst   20h                  ; ld (op1) with (hl)
  62.    call  _FINDSYM             ; is there a variable 'den'?
  63.    jr    c, continue          ; no, so continue
  64.    call  _delvar              ; delete 'den' using data from _FINDSYM
  65.    jr    continue
  66.  
  67. continue:
  68. ; /begin prompt/
  69. ;   ld      de,_ioPrompt
  70. ;   ld      hl,str_prmpt
  71. ;   call    _mov10B            ; move prompt to prompt buffer , 21 max
  72.  
  73. ;   LD      HL,(_CLEANTMP)
  74. ;   PUSH    HL              ; SAVE CURRENT CLEANTMP VALUE
  75. ;   LD      HL,(_PTempCnt)
  76. ;   LD      (_CLEANTMP),HL     ; CLEANTMP=PTEMPCNT
  77.                                ;SO INPUT ERRORS SAVE TMP VAR
  78.  
  79. ;   ld      a,0Dh              ; set for 'input'
  80. ;   ld      (_ASAP_IND),a
  81.  
  82. ;   call    _exec_pg3          ; get input, op1 = var containing input
  83.  
  84. ;   POP     HL              ; HL=PREVIOUS CLEANTMP
  85. ;   ld      (_CLEANTMP),hl
  86. ; /end prompt/
  87.  
  88.    call  _OP2TOOP1
  89.  
  90. ; check if number is a real
  91.    ld    a, (_OP1)
  92.    cp    $80
  93.    jr    z, frac
  94.    cp    $0
  95.    jr    z, frac
  96.  
  97.    jp    nofrac
  98.  
  99. ; check if number will have denominator of 1
  100.  
  101. frac:
  102.    call  _OP1TOOP3
  103.    call  _FRAC
  104.    call  $449B                ; cp op1, 0
  105.    jr    nz, setops
  106.    call  _OP3SET1
  107.    call  _OP3TOOP5
  108.    call  _OP2TOOP3
  109.    jr    checkforfrac
  110.  
  111. ; ld  op3 with numerator
  112. ; ld  op5 with denominator
  113.  
  114. setops:
  115.    call  _OP3TOOP1
  116.    call  $4b93
  117.    call  _OP1TOOP3
  118.    call  _OP2TOOP5
  119.  
  120. checkforfrac:
  121.    call  _OP3TOOP1
  122.    call  _FRAC
  123.    call  $449B
  124.    jr    nz, nofrac
  125.  
  126. loadvars:
  127.    ld    hl, num_op
  128.    rst   20h                  ; ld (op1) with (hl)
  129.    call  _CREATEREAL          ; create real variable 'num'
  130.  
  131.    ex de, hl
  132.    ld a, b
  133.    call _SET_ABS_DEST_ADDR
  134.  
  135.    ld hl, _OP3
  136.    xor a
  137.    call _SET_ABS_SRC_ADDR
  138.    ld hl, 10
  139.    xor a
  140.    call _SET_MM_NUM_BYTES
  141.    call _mm_ldir
  142.  
  143.    ld    hl, den_op
  144.    rst   20h                  ; ld (op1) with (hl)
  145.    call  _CREATEREAL          ; create real variable 'den'
  146.  
  147.    ex de,hl
  148.    ld a,b
  149.    call _SET_ABS_DEST_ADDR
  150.  
  151.    ld hl, _OP5
  152.    xor a
  153.    call _SET_ABS_SRC_ADDR
  154.    ld hl,10
  155.    xor a
  156.    call _SET_MM_NUM_BYTES
  157.    call _mm_ldir
  158.  
  159.    call  _op1set1             ; store float 0 into op1
  160.  
  161. exit:
  162.    call  _stoans              ; return answer 0=failed, 1=successful
  163.    ret
  164.    jp    $409c                ; clean exit
  165.  
  166.  
  167. nofrac:
  168.    call  _OP1SET0
  169.    jr    exit
  170.  
  171. num_op:
  172.    .db   $12,$3
  173.    .db   "num",0
  174. den_op:
  175.    .db   $12,$3
  176.    .db   "den",0
  177. inFrac_op:
  178.    .db   $12,$6
  179.    .db   "inFrac",0
  180.  
  181.  
  182. str_prmpt:
  183. ;    .db      "Prompt = ",0
  184.  
  185. .end
  186.