mirror of
https://github.com/cc65/cc65.git
synced 2024-11-03 10:07:02 +00:00
d1e4687540
git-svn-id: svn://svn.cc65.org/cc65/trunk@4464 b7a2c559-68d2-44c3-8de9-860c34a00d81
64 lines
1.2 KiB
ArmAsm
64 lines
1.2 KiB
ArmAsm
;
|
|
; Ullrich von Bassewitz, 2009-11-05
|
|
;
|
|
; Helper function for graphics functions: Multiply two values, one being
|
|
; 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
|
|
;
|
|
|
|
|
|
.export _tgi_imulround, tgi_imulround
|
|
.import popax, imul16x16r32
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
;
|
|
|
|
.code
|
|
|
|
; C callable entry point
|
|
_tgi_imulround:
|
|
|
|
; Get arguments
|
|
|
|
sta ptr1
|
|
stx ptr1+1 ; Save lhs
|
|
jsr popax ; Get rhs
|
|
|
|
; ASM callable entry point
|
|
tgi_imulround:
|
|
|
|
; Multiplicate
|
|
|
|
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
|
|
|
|
|