Author Topic: my routine clears ram  (Read 3418 times)

0 Members and 1 Guest are viewing this topic.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
my routine clears ram
« 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 code
Code: [Select]
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
  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.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: my routine clears ram
« Reply #1 on: May 11, 2011, 04:11:29 pm »
Where are those calls going to?
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: my routine clears ram
« Reply #2 on: May 11, 2011, 04:25:16 pm »
Here's the full source code
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: my routine clears ram
« Reply #3 on: May 11, 2011, 04:48:36 pm »
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.
« Last Edit: May 11, 2011, 04:49:29 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: my routine clears ram
« Reply #4 on: May 11, 2011, 06:18:29 pm »
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.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: my routine clears ram
« Reply #5 on: May 12, 2011, 03:18:47 pm »
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:
Code: (d3dto2d_init) [Select]
// 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.
Code: (d3dto2dpoint) [Select]
// 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;
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: my routine clears ram
« Reply #6 on: May 16, 2011, 03:49:41 pm »
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 :(
Code: [Select]
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?
« Last Edit: May 19, 2011, 04:15:42 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated