2009-11-05 20:16:43 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2009-11-05
|
|
|
|
;
|
2022-04-17 14:06:22 +00:00
|
|
|
; Helper function for graphics functions: Multiply two values, one being
|
2009-11-12 18:00:17 +00:00
|
|
|
; an 8.8 fixed point one, and return the rounded and scaled result.
|
|
|
|
;
|
|
|
|
; The module has two entry points: One is C callable and expects the
|
|
|
|
; parameters in ax and the stack, the second is assembler callable and
|
|
|
|
; expects the parameters in ax and ptr1
|
2009-11-05 20:16:43 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
2009-11-12 18:00:17 +00:00
|
|
|
.export _tgi_imulround, tgi_imulround
|
2009-11-05 20:16:43 +00:00
|
|
|
.import popax, imul16x16r32
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
|
|
|
|
.code
|
2009-11-12 18:00:17 +00:00
|
|
|
|
|
|
|
; C callable entry point
|
|
|
|
_tgi_imulround:
|
2009-11-05 20:16:43 +00:00
|
|
|
|
|
|
|
; Get arguments
|
|
|
|
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1 ; Save lhs
|
|
|
|
jsr popax ; Get rhs
|
|
|
|
|
2009-11-12 18:00:17 +00:00
|
|
|
; ASM callable entry point
|
|
|
|
tgi_imulround:
|
|
|
|
|
2022-02-21 20:44:31 +00:00
|
|
|
; Multiply
|
2009-11-05 20:16:43 +00:00
|
|
|
|
|
|
|
jsr imul16x16r32
|
|
|
|
|
|
|
|
; Round the result
|
|
|
|
|
|
|
|
cmp #$80 ; Frac(x) >= 0.5?
|
|
|
|
txa
|
|
|
|
ldy sreg+1 ; Check sign
|
|
|
|
bmi @L1
|
|
|
|
|
|
|
|
adc #$00
|
|
|
|
tay
|
|
|
|
lda sreg
|
|
|
|
adc #$00
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
rts
|
|
|
|
|
|
|
|
@L1: sbc #$00
|
|
|
|
tay
|
|
|
|
lda sreg
|
|
|
|
sbc #$00
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
rts
|
|
|
|
|
2022-04-17 14:06:22 +00:00
|
|
|
|