Ok, once again I'm back for some good old help. I've been trying to write a series of routines that will allow me to draw the puck in motion as its shot. Pretty much in a straigt line, but everything I try to write messes up. So if anyone could help me on this one it would be a great help.
Heres the idea. I take the first 2 x and y cor's and the second x and y cor's. What I want to do is draw the puck following that line. So I tried to do some math that would give me intervals at which to change the x and y along the way. I think I did that right. Heres the code:
Code: ;inputs b,c (first x and y)
;inputs d,e (2nd x and y)
;outputs b (horizonal number of intervals)
;outputs c (the actual value of the horizontal interval)
;outputs d (virtical number of intervals)
;outputs e (the actual value of the virtical interval)
Motionpath:
ld a,b
ld (motionx1),a
ld a,c
ld (motiony1),a
ld a,d
ld (motionx2),a
ld a,e
ld (motiony2),a
ld a,(motionx1)
ld b,a
ld a,(motionx2)
sub b
ld (finalx),a
ld a,(motiony1)
ld b,a
ld a,(motiony2)
sub b
ld (finaly),a
motion_xintv:
ld hl,(finalx)
ld a,(finaly)
ld d,a
call divide
ld (xintv),hl
ld hl,(finalx)
ld a,(xintv)
ld d,a
call divide
ld (xintervalue),hl
motion_yintv:
ld hl,(finaly)
ld a,(finalx)
ld d,a
call divide
ld (yintv),hl
ld hl,(finaly)
ld a,(yintv)
ld d,a
call divide
ld (yintervalue),hl
motion_output:
ld a,(xintv)
ld b,a
ld a,(xintervalue)
ld c,a
ld a,(yintv)
ld d,a
ld a,(yintervalue)
ld e,a
ret
motionx1:
.db 0,0
motionx2:
.db 0,0
motiony1:
.db 0,0
motiony2:
.db 0,0
finalx:
.db 0,0
finaly:
.db 0,0
xintv:
.db 0,0
xintervalue:
.db 0,0
yintv:
.db 0,0
yintervalue:
.db 0,0
;-----------------Multiplication-------------------
;inputs b=Number to multiply by
;inputs de=number being multiplied
;output de
multiply:
ex de,hl
ld de,0
multiply2:
add ix,de
djnz multiply2
ret
;-----------------inreger Division-----------------
; HL = HL รท D, A = remainder
;divide from 28 days tutorials
divide:
XOR A; Clear upper eight bits of AHL
LD B,16; Sixteen bits in dividend
Loop:
ADD HL,HL; Do a SLA AHL
RLA ; This moves the upper bits of the dividend into A
CP D; Check if we can subtract the divisor
JR C,Skip; Carry means D > A
SUB D; Do subtraction for real this time
INC L; Set bit 0 of quotient
Skip:
DJNZ Loop
RET
I think that one is pretty good for the idea. The harder part is getting it to draw it along the line. I tried a bunch of things and nothing worked right completely. Heres the last one I created.
Code: interval_change:
ld a,(puckshoty2)
ld b,a
ld a,(puck_y)
add a,b
ld (puck_y),a
ld a,(puckshotx2)
ld b,a
ld a,(puck_x)
add a,b
ld (puck_x),a
ret
This was a basic as I got because when I tried to get it to draw each interval it went pretty slow and it never seemed to work right. The problem I've had with all of them is when I get to the right or left side of the place its going, instead of from just straight above it just goes hay-wire.
Hopefully someone can help me bc right now I feel like smacking my computer bc its fustraighting me that I can't get it to work. So I'm gonna step away now so that I will have a computer to work with again tomarrow.
Donald |