]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_imulround.s
Moved fixed point multiplication and rounding into an asm module.
[cc65] / libsrc / tgi / tgi_imulround.s
1 ;
2 ; Ullrich von Bassewitz, 2009-11-05
3 ;
4 ; Helper function for functions using sine/cosine: Multiply two values, one
5 ; being an 8.8 fixed point one, and return the rounded and scaled result.
6 ;
7
8
9         .export         _tgi_imulround
10         .import         popax, imul16x16r32
11
12         .include        "zeropage.inc"
13
14
15 ;----------------------------------------------------------------------------
16 ;
17
18 .code
19 .proc   _tgi_imulround
20
21 ; Get arguments
22
23         sta     ptr1
24         stx     ptr1+1                  ; Save lhs
25         jsr     popax                   ; Get rhs
26
27 ; Multiplicate
28
29         jsr     imul16x16r32
30
31 ; Round the result
32
33         cmp     #$80                    ; Frac(x) >= 0.5?
34         txa
35         ldy     sreg+1                  ; Check sign
36         bmi     @L1
37
38         adc     #$00
39         tay
40         lda     sreg
41         adc     #$00
42         tax
43         tya
44         rts
45
46 @L1:    sbc     #$00
47         tay
48         lda     sreg
49         sbc     #$00
50         tax
51         tya
52         rts
53
54 .endproc