Advertisement
Zeda

setXXXOP1

Aug 2nd, 2015
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. setXXX:
  2. ;;Inputs: A is the unsigned int
  3. ;;        HL is where to write the TI float
  4. ;;Destroys:All
  5. ;;334cc+13a+63b (or 144cc if A=0)
  6. ;;average: a=99/255, b=29/255
  7. ;;346.2117647cc average
  8. ;;75 bytes
  9.     ld c,0
  10.     ld (hl),c
  11.     inc hl
  12.     ld (hl),83h
  13.     ld d,h
  14.     ld e,l
  15.     inc hl \ ld (hl),c
  16.     inc hl \ ld (hl),c
  17.     inc hl \ ld (hl),c
  18.     inc hl \ ld (hl),c
  19.     inc hl \ ld (hl),c
  20.     inc hl \ ld (hl),c
  21.     inc hl \ ld (hl),c
  22.    
  23.     or a \ ret z    ;If A is zero, exit early. +227cc
  24.     ld l,a          ;\
  25.     ld h,c          ; |
  26.     add hl,hl       ; |Start converting A to BCD
  27.     add hl,hl       ; |
  28.     add hl,hl       ; |
  29.     add hl,hl       ; |
  30.     ld a,h \ daa  \ rl l    ; |Finish converting A to BCD
  31.     adc a,a \ daa \ rl l    ; |Number is in LA
  32.     adc a,a \ daa \ rl l    ; |
  33.     adc a,a \ daa \ rl l    ; |
  34.     adc a,a \ daa \ rl l    ;/ +132cc
  35.     ex de,hl
  36.     jr nz,$+6 \ ld e,a \ xor a \ ld (hl),81h    ;+(21+4/85)cc
  37.     inc hl
  38.     ld (hl),e
  39.     inc hl
  40.     ld (hl),a
  41.     ld a,e
  42.     and $F0
  43.     ret nz      ;+48cc
  44.     rld         ;\ Rotate up 1 digit
  45.     dec hl      ; |
  46.     rld         ; |
  47.     dec hl      ; |
  48.     dec (hl)    ; |Decrement exponent
  49.     ret         ; /+63(29/255)cc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement