+ rts
+
+.endproc
+
+
+;----------------------------------------------------------------------------
+; Round a 16.8 fixed point value in eax
+
+.code
+.proc RoundFix
+
+ cmp #$80 ; frac(val) >= 0.5?
+ txa
+ ldx sreg
+ adc #$00
+ bcc @L1
+ inx
+@L1: rts
+
+.endproc
+
+;----------------------------------------------------------------------------
+; Get and process one coordinate value. The scale factor is passed in a/x
+
+.code
+.proc GetProcessedCoord
+
+; Save scale factor as left operand for multiplication
+
+ sta ptr1
+ stx ptr1+1
+
+; Load next operation value. This will set the flags for the value in A.
+
+ jsr GetOp
+
+; Since we know that the scale factor is always positive, we will remember
+; the sign of the coordinate offset, make it positive, do an unsigned mul
+; and negate the result if the vector was negative. This is faster than
+; relying on the signed multiplication, which will do the same, but for
+; both operands.
+
+ sta tmp1 ; Remember sign of vector offset
+ bpl :+
+ eor #$FF
+ clc
+ adc #$01 ; Negate
+: ldx #$00 ; High byte is always zero
+
+; Multiplicate with the scale factor.
+
+ jsr umul16x16r32 ; Multiplicate
+
+; The result is a 16.8 fixed point value. Round it.
+
+ jsr RoundFix
+
+; Check the sign and negate if necessary
+
+ bit tmp1 ; Check sign
+ bpl :+
+ jmp negax ; Negate result if necessary
+: rts
+
+.endproc