modf16.asm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ; Computes A % B for fixed values
  2. ;
  3. #include once <divf16.asm>
  4. #include once <mulf16.asm>
  5. ;
  6. __MODF16:
  7. ; 16.16 Fixed point Division (signed)
  8. ; DE.HL = Divisor, Stack Top = Divider
  9. ; A = Dividend, B = Divisor => A % B
  10. PROC
  11. LOCAL TEMP
  12. TEMP EQU 23698 ; MEMBOT
  13. pla ;- pop bc ; ret addr
  14. sta z80_b
  15. pla
  16. sta z80_c
  17. lda z80_c ;- ld (TEMP),bc ; stores it on MEMBOT temporarily
  18. sta TEMP
  19. lda z80_b
  20. sta TEMP+1
  21. lda z80_l ;- ld (TEMP+2),hl ; stores HP of divider
  22. sta TEMP+2
  23. lda z80_h
  24. sta TEMP+2+1
  25. lda z80_e ;- ld (TEMP+4),de ; stores DE of divider
  26. sta TEMP+4
  27. lda z80_d
  28. sta TEMP+4+1
  29. jsr __DIVF16 ;- call __DIVF16
  30. ;- rlc d ; Sign into carry
  31. ;- sbc a, a ; a register = -1 sgn(DE), or 0
  32. lda z80_a ;- ld d,a
  33. sta z80_d
  34. lda z80_a ;- ld e,a ; DE = 0 if it was positive or 0; -1 if it was negative
  35. sta z80_e
  36. lda TEMP+4 ;- ld bc,(TEMP + 4) ; Pushes original divider into the stack
  37. sta z80_c
  38. lda TEMP+4+1
  39. sta z80_b
  40. lda z80_c ;- push bc
  41. pha
  42. lda z80_b
  43. pha
  44. lda TEMP+2 ;- ld bc,(TEMP+2)
  45. sta z80_c
  46. lda TEMP+2+1
  47. sta z80_b
  48. lda z80_c ;- push bc
  49. pha
  50. lda z80_b
  51. pha
  52. ;- ld bc, (TEMP) ; recovers return address
  53. lda z80_c ;- push bc
  54. pha
  55. lda z80_b
  56. pha
  57. jmp __MULF16 ;- jp __MULF16 ; multiplies and return from there
  58. ;- ENDP