]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_imulround.s
Merge pull request #740 from laubzega/master
[cc65] / libsrc / tgi / tgi_imulround.s
1 ;
2 ; Ullrich von Bassewitz, 2009-11-05
3 ;
4 ; Helper function for graphics functions: Multiply two values, one being 
5 ; an 8.8 fixed point one, and return the rounded and scaled result.
6 ;
7 ; The module has two entry points: One is C callable and expects the
8 ; parameters in ax and the stack, the second is assembler callable and
9 ; expects the parameters in ax and ptr1
10 ;
11
12
13         .export         _tgi_imulround, tgi_imulround
14         .import         popax, imul16x16r32
15
16         .include        "zeropage.inc"
17
18
19 ;----------------------------------------------------------------------------
20 ;
21
22 .code
23
24 ; C callable entry point
25 _tgi_imulround:
26
27 ; Get arguments
28
29         sta     ptr1
30         stx     ptr1+1                  ; Save lhs
31         jsr     popax                   ; Get rhs
32
33 ; ASM callable entry point
34 tgi_imulround:
35
36 ; Multiplicate
37
38         jsr     imul16x16r32
39
40 ; Round the result
41
42         cmp     #$80                    ; Frac(x) >= 0.5?
43         txa
44         ldy     sreg+1                  ; Check sign
45         bmi     @L1
46
47         adc     #$00
48         tay
49         lda     sreg
50         adc     #$00
51         tax
52         tya
53         rts
54
55 @L1:    sbc     #$00
56         tay
57         lda     sreg
58         sbc     #$00
59         tax
60         tya
61         rts
62
63