f16tofreg.asm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include once <neg32.asm>
  2. #include once <u32tofreg.asm>
  3. ;
  4. __F16TOFREG: ; Converts a 16.16 signed fixed point (stored in DEHL)
  5. ; to a Floating Point Number returned in (C ED CB)
  6. ;- PROC
  7. ;- LOCAL __F16TOFREG2
  8. lda z80_d ;- ld a,d
  9. sta z80_a
  10. ora z80_a ;- or a ; Test sign
  11. jpl __F16TOFREG2 ;- jp p,__F16TOFREG2 ; It was positive, proceed as 32bit unsigned
  12. jsr __NEG32 ;- call __NEG32 ; Convert it to positive
  13. jsr __F16TOFREG2 ;- call __F16TOFREG2 ; Convert it to Floating point
  14. lda z80_e ;- set 7,e ; Put the sign bit (negative) in the 31bit of mantissa
  15. ora #$80
  16. sta z80_e
  17. rts ;- ret
  18. __F16TOFREG2: ; Converts an unsigned 32 bit integer (DEHL)
  19. ; to a Floating point number returned in C DE HL
  20. lda z80_d ;- ld a,d
  21. sta z80_a
  22. ora z80_e ;- or e
  23. ora z80_h ;- or h
  24. ora z80_l ;- or l
  25. lda z80_h ;- ld b,h
  26. sta z80_b
  27. lda z80_l ;- ld c,l
  28. sta z80_c
  29. bne *+3 ;- ret z ; Return 00 0000 0000 if 0
  30. rts
  31. lda z80_e ;- push de
  32. pha
  33. lda z80_d
  34. pha
  35. lda z80_l ;- push hl
  36. pha
  37. lda z80_h
  38. pha
  39. lda z80_c ;- exx
  40. ldx z80_cp
  41. stx z80_c
  42. sta z80_cp
  43. lda z80_b
  44. ldx z80_bp
  45. stx z80_b
  46. sta z80_bp
  47. lda z80_e
  48. ldx z80_ep
  49. stx z80_e
  50. sta z80_ep
  51. lda z80_d
  52. ldx z80_dp
  53. stx z80_d
  54. sta z80_dp
  55. lda z80_l
  56. ldx z80_lp
  57. stx z80_l
  58. sta z80_lp
  59. lda z80_h
  60. ldx z80_hp
  61. stx z80_h
  62. sta z80_hp
  63. pla ;- pop de ; Loads integer into B'C' D'E'
  64. sta z80_d
  65. pla
  66. sta z80_e
  67. pla ;- pop bc
  68. sta z80_b
  69. pla
  70. sta z80_c
  71. lda z80_c ;- exx
  72. ldx z80_cp
  73. stx z80_c
  74. sta z80_cp
  75. lda z80_b
  76. ldx z80_bp
  77. stx z80_b
  78. sta z80_bp
  79. lda z80_e
  80. ldx z80_ep
  81. stx z80_e
  82. sta z80_ep
  83. lda z80_d
  84. ldx z80_dp
  85. stx z80_d
  86. sta z80_dp
  87. lda z80_l
  88. ldx z80_lp
  89. stx z80_l
  90. sta z80_lp
  91. lda z80_h
  92. ldx z80_hp
  93. stx z80_h
  94. sta z80_hp
  95. lda #112 ;- ld l,112 ; Exponent
  96. sta z80_l
  97. lda #<0
  98. sta z80_c
  99. lda #>0
  100. sta z80_b
  101. lda z80_b ;- ld d,b
  102. sta z80_d
  103. lda z80_c ;- ld e,c
  104. sta z80_e
  105. jmp __U32TOFREG_LOOP ;- jp __U32TOFREG_LOOP ; Proceed as an integer
  106. ;- ENDP