ok, I wrote another vector calculation thingy. But this time I just had it display the cordinates and stuff. but now I get something mad funky come on the screen for the values.
Code: .nolist
#include "ion.inc"
#include "keys.inc"
#include "array.z80"
player_x = saferam1+1
player_y = saferam1+10
player_a = saferam1+20
player_m = saferam1+30
.list
;-------------Ion Header---------------------
#ifdef TI83P
.org progstart-2
.db $BB,$6D
#else
.org progstart
#endif
ret
jr nc,BEGIN
.db "NHL Hitz Vector 1",0
BEGIN:
ld a,0
ld (player_m),a
ld a,20
ld (player_y),a
ld (player_x),a
ld hl,90
ld (player_a),hl
keys:
bcall(_grbufclr)
call decplayerm
ld a,0FFh
out (1),a
ld a,$fd
out (1),a
in a,(1)
cp kclear
jp z,exitgame
ld a,$FE
out (1),a
in a,(1)
cp kup
call z,player_up
cp kdown
call z,player_down
cp kright
call z,player_right
cp kleft
call z,player_left
jp screen_update
player_up:
ld (player_a),hl
ld hl,90
ld (player_a),hl
ld a,(player_m)
inc a
ld (player_m),a
ret
player_down:
ld (player_a),hl
ld hl,270
ld (player_a),hl
ld a,(player_m)
inc a
ld (player_m),a
ret
player_left:
ld (player_a),hl
inc hl
ld (player_a),hl
ld a,(player_m)
inc a
ld (player_m),a
ret
player_right:
ld (player_a),hl
dec hl
ld (player_a),hl
ld a,(player_m)
inc a
ld (player_m),a
ret
decplayerm:
ld a,(player_m)
dec a
cp 0
call z,magnitude_fix
call m,magnitude_fix
ld (player_m),a
ret
magnitude_fix:
ld a,0
ret
screen_update:
ld hl,(player_x)
ld b,h
ld c,l
ld hl,(player_y)
ld d,h
ld e,l
ld hl,(player_m)
ld a,1
call pos_calc
ld (player_x),bc
ld (player_Y),de
bcall(_grbufclr)
ld a,1
ld (pencol),a
ld (penrow),a
ld hl,x_text
bcall(_vputs)
ld a,25
ld (pencol),a
ld a,1
ld (penrow),a
ld hl,(player_x)
ld de,op1
ld bc,9
ldir
ld a,8
bcall(_dispop1a)
ld a,7
ld (penrow),a
ld a,1
ld (pencol),a
ld hl,y_text
bcall(_vputs)
ld a,25
ld (pencol),a
ld a,7
ld (penrow),a
ld hl,(player_y)
ld de,op1
ld bc,9
ldir
ld a,8
bcall(_dispop1a)
ld a,14
ld (penrow),a
ld a,
ld (pencol),a
ld hl,angle_txt
bcall(_vputs)
ld a,25
ld (pencol),a
ld a,14
ld (penrow),a
ld hl,(player_a)
ld de,op1
ld bc,9
ldir
ld a,8
bcall(_dispop1a)
jp keys
exitgame:
bcall(_grbufclr)
ret
x_text:
.db "X-Cor:",0
y_text:
.db "Y-cor:",0
angle_txt:
.db "Angle:",0
;=============Vector Calculation routine===============
;inputs hl=angle
; a=magnitude
;
;outputs bc=value to add to x
; de=value to add to y
vector_calc:
;loads the angle into hl
push af
ld de,op1
ld bc,8
ldir
;gets the sin and cos of the angle
bcall(_Sin)
bcall(_int) ;rounds off the next value into an integer, this is the sin value
ld hl,op1
push hl ;stack: hl(sin),af
ld hl,op2 ;puts op2 into op1
ld de,op1
ld bc,8
ldir
bcall(_int) ;rounds off the next value into an integer, this is the cos value
ld hl,op1 ;loads the op1 into hl
ld b,h
ld c,l ;loads the cos value into bc
pop hl ;stack: af
ld d,h
ld e,l ;loads the sin value into de
;multiply it by the magnitude
pop af
ld h,b
ld l,c
ld b,a
magnitude_1:
add hl,hl
djnz magnitude_1
ld b,h
ld c,l
push bc;stack: bc
ld h,d
ld l,e
ld b,a
magnitude_2:
add hl,hl
djnz magnitude_1
ld d,h
ld e,l
pop bc
ret
;==============end of the vector calculation============
;==============Add Vector to current position x
;inputs hl=current x position
; bc=value to add to x
;outputs hl,new x position
x_vec_add:
add hl,bc
ret
;==============Add Vector to current position y
;inputs hl=current y position
; de=value to add to y
;outputs hl,new x position
y_vec_add:
add hl,de
ret
;================Complete position calculation===========
;inputs bc,current x
; de,current y
; hl,angle
; a,magnitude
;outputs bc,new x position
; de,new y position
pos_calc:
push de ;stack: de
push bc ;stack: bc,de
call vector_calc
pop hl ;pops the current xpos to hl, stack: de
call x_vec_add
ld b,h
ld c,l
pop hl ;pops the current ypos to hl, stack: -empty-
call y_vec_add
ld d,h
ld e,l
ret
.end
END
Last edited by Guest on 22 Dec 2003 05:14:59 pm; edited 1 time in total |