diff --git a/gscats.2mg b/gscats.2mg index b8c1dfd..6adcf5e 100644 Binary files a/gscats.2mg and b/gscats.2mg differ diff --git a/player.s b/player.s index 4e3eaff..d33a454 100644 --- a/player.s +++ b/player.s @@ -13,7 +13,7 @@ playerData: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background .word 45 ; Angle in degrees from +X - .word 50 ; Power + .word 2 ; Power .word 100 ; Anger .byte 8,"SPROCKET " ; Name .word 0,0,0,0,0,0 ;Padding @@ -23,8 +23,8 @@ playerData: .word 0 ; Y pos in pixels (from bottom terrain edge) .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background - .word 45 ; Angle in degrees from +X - .word 50 ; Power + .word 135 ; Angle in degrees from +X + .word 3 ; Power .word 100 ; Anger .byte 8,"TINKER " ; Name .word 0,0,0,0,0,0 ;Padding diff --git a/projectile.s b/projectile.s index 33395fc..401b789 100644 --- a/projectile.s +++ b/projectile.s @@ -90,16 +90,36 @@ fireProjectile: asl sta projectileData+JD_PRECISEY,y + lda projectileParams+6 ; Convert power to 8.8 + asl + asl + asl + asl + asl + asl + asl + asl + sta projectileParams+6 + lda projectileParams+4 ; Convert angle to vector asl tax - lda angleToVectorX,x ; Velocity X + lda angleToVectorX,x ; Velocity X (unit vector) + + sta PARAML1 + lda projectileParams+6 ; Scale by power + sta PARAML0 + jsr mult88 sta projectileData+JD_VX,y lda projectileParams+4 ; Convert angle to vector asl tax - lda angleToVectorY,x ; Velocity Y + lda angleToVectorY,x ; Velocity Y (unit vector) + sta PARAML1 + lda projectileParams+6 ; Scale by power + sta PARAML0 + jsr mult88 sta projectileData+JD_VY,y RESTORE_AXY diff --git a/utility.s b/utility.s index f654a59..43441f2 100644 --- a/utility.s +++ b/utility.s @@ -61,6 +61,8 @@ intToStringSkipSingle: sta intToStringResult,y iny inx + cpx #3 + beq intToStringFinish ; Single digit number so we're done intToStringFullDigitsLoop: ; Remaining bytes all contain two digits @@ -83,6 +85,7 @@ intToStringFullDigitsLoop: cpx #3 bne intToStringFullDigitsLoop +intToStringFinish: ; Store final length and we're done dey sty intToStringResult @@ -94,3 +97,58 @@ intToStringDone: intToStringBCD: .byte 0,0,0 intToStringResult: .byte 0,0,0,0,0,0 + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; mult16 +; +; PARAML0 = Operand 1 (16 bits) +; PARAML1 = Operand 2 (16 bits) +; A => Op1 * Op2 (16 bits) +; Algorithm from https://apple2.gs/downloads/Programmanual.pdf +; Trashes X +; +mult16: + lda #0 ; Initialize result + +mult16L1: + ldx PARAML0 ; Get operand 1 + beq mult16Done ; If operand is zero, we're done + lsr PARAML0 ; Get low bit + bcc mult16L2 ; If clear, no additions to previous products + clc ; Otherwise add oeprand 2 to partial result + adc PARAML1 + +mult16L2: + asl PARAML1 ; Now shift operand 2 left for possible add next time + bra mult16L1 + +mult16Done: + rts + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; mult88 +; +; PARAML0 = Operand 1 (8.8 fixed point) +; PARAML1 = Operand 2 (8.8 fixed point) +; A => Op1 * Op2 (8.8 fixed point) +; Substantial precision loss occurs here, but it's usually good enough +; +mult88: + lda PARAML0 ; Convert operands to 12.4 + lsr + lsr + lsr + lsr + sta PARAML0 + + lda PARAML1 + lsr + lsr + lsr + lsr + sta PARAML1 + + jsr mult16 ; Result is 8.8 + rts