Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: ben_g on May 11, 2011, 03:56:58 pm
-
Hi,
I've got an other problem: my routine clears the ram, and I don't know why...
from 'learn ti83plus asm in 28 Days', i know that ram clears usually appear when you used the stack incorrect, but I've counted all the pushes and pops of the routine, and there were as much pushes as pops. Further is the mem for all the vars stored in the program itself, so it can't be becouse i'm editing mem that shouldn't be edited.
It's just calculating with registers and vars, but i don't know how that can clear the ram.
anyway, here's my code3DTo2D:
ld a, 0
ld (valid), a
ld bc, (xpoint)
ld de, (xfrom)
call SubFP
ld (xpoint), de
ld bc, (ypoint)
ld de, (yfrom)
call SubFP
ld (ypoint), de
ld bc, (zpoint)
ld de, (zfrom)
call SubFP
ld (zpoint), de
ld hl, (xpoint)
ld bc, (xto)
call MulFP
push de ;1
ld hl, (ypoint)
ld bc, (yto)
call MulFP
pop hl ;0
add hl, de
push hl ;1
ld hl, (zpoint)
ld bc, (zto)
call MulFP
pop hl ;0
add hl, de
push hl ;1
ld a, l
ld c, a
ld a, (min_range)
ld b, a
ld a, c
cp b
jp c, Invalid
ld c, a
ld a, (max_range)
ld b, a
ld a, c
cp b
jp nc, Invalid
ld a, 1
ld (valid), a
ld hl, (xpoint)
ld bc, (xcross)
call MulFP
push de ;2
ld hl, (ypoint)
ld bc, (ycross)
call MulFP
pop hl ;1
add hl, de
push hl ;2
ld hl, (zpoint)
ld bc, (zcross)
call MulFP
pop hl ;1
add hl, de
pop de ;0
push de ;1
call DivFP
ld (screenx), hl
ld hl, (xpoint)
ld bc, (xup)
call MulFP
push de ;2
LD HL, (ypoint)
ld bc, (yup)
call MulFP
pop hl ;1
add hl, de
push hl ;2
ld hl, (zpoint)
ld bc, (zup)
call MulFP
pop hl ;1
add hl, bc
pop de ;0
call DivFP
ld (screeny), hl
ld hl, $0100
ld de, (screenx)
add hl, de
ld bc, $5F00
call MulFP
ld (screenx), de
ld hl, $0100
ld de, (screeny)
add hl, de
ld bc, $4100
call MulFP
ld (screeny), de
Invalid:
ret
btw: the commented numbers show the amount of items put on the stack by this routine.
-
Where are those calls going to?
-
Here's the full source code
-
I just made a few minor changes to the source so that it would assemble and WabbitEmu runs it fine. Not sure where your problem is, because I'm not getting a RAM clear.
Someone more experienced than myself might be able to identify it, though.
-
Well, the reason that the full program isn't crashing is because it never actually calls the routine in question. I just does clearGBuf, lineDraw, fastCopy and checks for quit.
I would call it myself, but I have no idea what to call.
-
just add 'call 3DTo2D' somewere on a part that is executed. You will get a ram clear
if you add 'call InitView' somewere, it doesn't couse a ram clear, but i don't know if it's working corectely as it should work together with 3DTo2D.
have written a simple 3D engine in GML and i try to rewrite it in asm. Maybe the GML code can help:// d3dto2d_init(xfrom,yfrom,zfrom,xto,yto,zto,xup,yup,zup,angle,aspect,znear,zfar)
var d;
global.d3dto2d_xfrom = argument0;
global.d3dto2d_yfrom = argument1;
global.d3dto2d_zfrom = argument2;
global.d3dto2d_xto = argument3-global.d3dto2d_xfrom;
global.d3dto2d_yto = argument4-global.d3dto2d_yfrom;
global.d3dto2d_zto = argument5-global.d3dto2d_zfrom;
d = sqrt(global.d3dto2d_xto*global.d3dto2d_xto+global.d3dto2d_yto*global.d3dto2d_yto+global.d3dto2d_zto*global.d3dto2d_zto);
global.d3dto2d_xto /= d;
global.d3dto2d_yto /= d;
global.d3dto2d_zto /= d;
global.d3dto2d_xup = argument6;
global.d3dto2d_yup = argument7;
global.d3dto2d_zup = argument8;
d = global.d3dto2d_xup*global.d3dto2d_xto+global.d3dto2d_yup*global.d3dto2d_yto+global.d3dto2d_zup*global.d3dto2d_zto;
global.d3dto2d_xup -= d*global.d3dto2d_xto;
global.d3dto2d_yup -= d*global.d3dto2d_yto;
global.d3dto2d_zup -= d*global.d3dto2d_zto;
d = tan(degtorad(argument9)/2)*sqrt(global.d3dto2d_xup*global.d3dto2d_xup+global.d3dto2d_yup*global.d3dto2d_yup+global.d3dto2d_zup*global.d3dto2d_zup);
global.d3dto2d_xup /= d;
global.d3dto2d_yup /= d;
global.d3dto2d_zup /= d;
global.d3dto2d_xcross = (global.d3dto2d_yup*global.d3dto2d_zto-global.d3dto2d_zup*global.d3dto2d_yto)/argument10;
global.d3dto2d_ycross = (global.d3dto2d_zup*global.d3dto2d_xto-global.d3dto2d_xup*global.d3dto2d_zto)/argument10;
global.d3dto2d_zcross = (global.d3dto2d_xup*global.d3dto2d_yto-global.d3dto2d_yup*global.d3dto2d_xto)/argument10;
global.d3dto2d_znear = argument11;
global.d3dto2d_zfar = argument12;
The 'aspect' variable won't be ust in the asm version.
// d3dto2d_point(x,y,z)
var xx,yy,zz,d;
xx = argument0-global.d3dto2d_xfrom;
yy = argument1-global.d3dto2d_yfrom;
zz = argument2-global.d3dto2d_zfrom;
d= xx*global.d3dto2d_xto+yy*global.d3dto2d_yto+zz*global.d3dto2d_zto;
if (d<global.d3dto2d_znear or d>global.d3dto2d_zfar){ Return = 0}else{Return = 1}
global.xx = (xx*global.d3dto2d_xcross+yy*global.d3dto2d_ycross+zz*global.d3dto2d_zcross)/d;
global.yy = (xx*global.d3dto2d_xup+yy*global.d3dto2d_yup+zz*global.d3dto2d_zup)/d;
return Return;
-
All of the calls made in the 3DTo2D part are also used in the InitView part. The number of pushes and pops are the same, and the vars are defined in the program memory, so I still don't know why it clears the ram.
Maybe my own math routines aren't really doing what they should do, so does enybody here have some code on their hard drive for 16bit 8.8 fixed point signed addition, substraction, multiplication and division?
EDIT: I double-checked all my routines, then tripple-checked them, then tested every routine on it's own, and I have found out that the code below clears the ram, but I still don't know why :(
3DTo2D:
ld a, 0
ld (valid), a
ld bc, (xpoint)
ld de, (xfrom)
call SubFP
ld (xpoint), de
ld bc, (ypoint)
ld de, (yfrom)
call SubFP
ld (ypoint), de
ld bc, (zpoint)
ld de, (zfrom)
call SubFP
ld (zpoint), de
ld hl, (xpoint)
ld bc, (xto)
call MulFP
push de ;1
ld hl, (ypoint)
ld bc, (yto)
call MulFP
pop hl ;0
add hl, de
push hl ;1
ld hl, (zpoint)
ld bc, (zto)
call MulFP
pop hl ;0
add hl, de
push hl ;1
ld a, l
ld c, a
ld a, (min_range)
ld b, a
ld a, c
cp b
ret c
ld c, a
ld a, (max_range)
ld b, a
ld a, c
cp b
ret nc
ld a, 1
ld (valid), a
ld hl, (xpoint)
ld bc, (xcross)
call MulFP
push de ;2
ld hl, (ypoint)
ld bc, (ycross)
call MulFP
pop hl ;1
add hl, de
push hl ;2
ld hl, (zpoint)
ld bc, (zcross)
call MulFP
pop hl ;1
add hl, de
pop de ;0
push de ;1
call DivFP
ld (screenx), hl
ld hl, (xpoint)
ld bc, (xup)
call MulFP
push de ;2
LD HL, (ypoint)
ld bc, (yup)
call MulFP
pop hl ;1
add hl, de
push hl ;2
ld hl, (zpoint)
ld bc, (zup)
call MulFP
pop hl ;1
add hl, bc
pop de ;0
call DivFP
ld (screeny), hl
ld hl, $0100
ld de, (screenx)
add hl, de
ld bc, $5F00
call MulFP
ld (screenx), de
ld hl, $0100
ld de, (screeny)
add hl, de
ld bc, $4100
call MulFP
ld (screeny), de
ret
I've tested every subroutine, and they all worked normally. The stack is also used correctelly (I think), So why is it clearing my ram?