MAMEWorld Central >> EmuChat
View all threads Index   Flat Mode Flat  

dkongjr
MAME Fan
Reged: 03/25/16
Posts: 45
Send PM
Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation
03/29/16 06:24 PM


I should mention I'm working on MAME 114 as I had that already set up and the latest build didn't want to compile for some reason I couldn't bother to look into, but I don't think that's going to be an issue for now. I will move to 171 as soon as I manage to compile, probably just need to download the latest building tools. Ok, here we go...


1. To disable collision detection I consulted MAME 113 where there is none and borrowed some code from it:

Code:

static void fdiv(void)
{
float a = fifoin_pop_f();
float b = fifoin_pop_f();

//use this old one, even if wrong
float r = !b ? 1e39 : a/b;
// float r = !b ? 0 : a * (1/b);

fifoout_push_f(r);
next_fn();
}

static void vlength(void)
{
float a = fifoin_pop_f();
float b = fifoin_pop_f();
float c = fifoin_pop_f();

fifoout_push_f(sqrt(a*a+b*b+c*c));
next_fn();
}


This vlength implementation also makes more sense to me than the new one. I think it's used by collision detection to calculate distance from own ship to various environment objects. I don't think there needs to be any coordinate subtraction as own ship could very well be set at the origin for the whole collision detection calculation, and also they could have made it to receive six arguments if they wanted to calculate distances between two arbitrary points, plus such function already exist: "distance3". Out value has to be minimum 20,000 in order not to lock in constant collision at the beginning of the 1st stage, so this would do just as well: fifoout_push_f(20000); BUT not for the 2nd stage!


2. Grab X,Y,Z rotation angles of own ship/camera: INT16 QrotX, QrotY, QrotZ. I could not find a better way to obtain those angles than to hack them out of matrix_rot functions. For that I needed to know when one frame ends and the next one begins, then wait for the second call to matrix_rot after f14 function is called the first time. So I have counters: extern int QQ and int QZ. In ../video/model1.c function end_frame I reset QQ counter:


Code:

static void end_frame(void)
{
unsigned long i;
if((listctl[0] & 4) && (cpu_getcurrentframe() & 1))
listctl[0] ^= 0x40;

QQ= 0;
}


Then back in ../machine/model1.c function f14 I reset QZ counter and start counting calls to f14 with QQ counter:


Code:

static void f14(void)
{
float a = fifoin_pop_f();
float b = fifoin_pop_f();
float c = fifoin_pop_f();
float d = fifoin_pop_f();

QQ++;
QZ= 0;

next_fn();
}


Now, matrix_rot functions for this particular call to set up own ship/camera rotation are accessed in this order: _roty, _rotx, _rotz, therefore I increase QZ counter in _roty and finish grab operation with _rotz:


Code:

static void matrix_roty(void)
{
INT16 a;
float s;
float c;
float t1, t2;

a = fifoin_pop();

QZ++;
if(QQ == 1 && QZ == 2) QrotY= a;

s = tsin(a);
c = tcos(a);
t1 = cmat[6];
t2 = cmat[0];
cmat[6] = c*t1-s*t2;
cmat[0] = s*t1+c*t2;
t1 = cmat[7];
t2 = cmat[1];
cmat[7] = c*t1-s*t2;
cmat[1] = s*t1+c*t2;
t1 = cmat[8];
t2 = cmat[2];
cmat[8] = c*t1-s*t2;
cmat[2] = s*t1+c*t2;

next_fn();
}

static void matrix_rotx(void)
{
INT16 a;
float s;
float c;
float t1, t2;

a = fifoin_pop();

if(QQ == 1 && QZ == 2) QrotX= a;

s = tsin(a);
c = tcos(a);
t1 = cmat[3];
t2 = cmat[6];
cmat[3] = c*t1-s*t2;
cmat[6] = s*t1+c*t2;
t1 = cmat[4];
t2 = cmat[7];
cmat[4] = c*t1-s*t2;
cmat[7] = s*t1+c*t2;
t1 = cmat[5];
t2 = cmat[8];
cmat[5] = c*t1-s*t2;
cmat[8] = s*t1+c*t2;

next_fn();
}

static void matrix_rotz(void)
{
INT16 a;
float s;
float c;
float t1, t2;

a = fifoin_pop();

if(QQ == 1 && QZ == 2)
{
QrotZ= a;

//finish it here like this as there are more calls to
//_rotx and _rotz before QQ/QZ counters change
QZ= 99;
}

s = tsin(a);
c = tcos(a);
t1 = cmat[0];
t2 = cmat[3];
cmat[0] = c*t1-s*t2;
cmat[3] = s*t1+c*t2;
t1 = cmat[1];
t2 = cmat[4];
cmat[1] = c*t1-s*t2;
cmat[4] = s*t1+c*t2;
t1 = cmat[2];
t2 = cmat[5];
cmat[2] = c*t1-s*t2;
cmat[5] = s*t1+c*t2;

next_fn();
}


3. Finally, having now stored these three angles in QrotX, QrotY, and QrotZ, we can make function f15_swa like this (rotating backwards z->x->y is important in order to avoid "gimbal lock" type of problem):


Code:

static void f15_swa(void)
{
int i;
INT16 a;
float s;
float c;
float t1, t2;

// -- rot identity: reset rotation matrix,
//but leave position (cmat[9],cmat[10],cmat[11])
for(i=0; i < 9; i++)
cmat[i]= 0;

cmat[0] = 1.0;
cmat[4] = 1.0;
cmat[8] = 1.0;


// -- Z rotation
a = -QrotZ;

s = tsin(a);
c = tcos(a);
t1 = cmat[0];
t2 = cmat[3];
cmat[0] = c*t1-s*t2;
cmat[3] = s*t1+c*t2;
t1 = cmat[1];
t2 = cmat[4];
cmat[1] = c*t1-s*t2;
cmat[4] = s*t1+c*t2;
t1 = cmat[2];
t2 = cmat[5];
cmat[2] = c*t1-s*t2;
cmat[5] = s*t1+c*t2;

// -- X rotation
a= -QrotX;

s = tsin(a);
c = tcos(a);
t1 = cmat[3];
t2 = cmat[6];
cmat[3] = c*t1-s*t2;
cmat[6] = s*t1+c*t2;
t1 = cmat[4];
t2 = cmat[7];
cmat[4] = c*t1-s*t2;
cmat[7] = s*t1+c*t2;
t1 = cmat[5];
t2 = cmat[8];
cmat[5] = c*t1-s*t2;
cmat[8] = s*t1+c*t2;

// -- Y rotation
a= -QrotY;

s = tsin(a);
c = tcos(a);
t1 = cmat[6];
t2 = cmat[0];
cmat[6] = c*t1-s*t2;
cmat[0] = s*t1+c*t2;
t1 = cmat[7];
t2 = cmat[1];
cmat[7] = c*t1-s*t2;
cmat[1] = s*t1+c*t2;
t1 = cmat[8];
t2 = cmat[2];
cmat[8] = c*t1-s*t2;
cmat[2] = s*t1+c*t2;

next_fn();
}


That's it. I think you will agree it's a very nice improvement and hope it will give you motivation to solve the rest of the issues together. I also hope you, or someone, should be able to figure out how to obtain those rotation angles in more elegant way, perhaps by somehow locating where the call to those matrix_rot functions originates and then work out something from there. I tried reading inputs and outputs of many of those TGP functions but could not find any that would compare to those angles. I have more to say and lot more to ask, but I have to leave it at this for now.


By the way, I'm trying to make "tiny" compile with just those four model1 games, and get this message: "swa uses non-present CPU". This is what I have in tiny.mak:

Code:


CPUS += Z80
CPUS += V60
CPUS += 68000

SOUNDS += YM3438
SOUNDS += MULTIPCM
SOUNDS += DAC
SOUNDS += YM2151


...what CPU am I missing?







Entire thread
Subject Posted by Posted on
* Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr 03/25/16 01:15 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/20/16 12:08 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Roman  04/20/16 12:55 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/20/16 01:23 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/20/16 04:06 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation SailorSat  06/25/16 09:03 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation John IV  04/20/16 05:24 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/20/16 09:15 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation jonwil  04/08/16 02:23 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation jonwil  04/05/16 01:28 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/05/16 05:15 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation AaronGiles  04/05/16 06:59 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/05/16 02:33 PM
. * May the Force be with you SmitdoggAdministrator  03/30/16 03:27 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/26/16 04:40 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation drewcifer  03/27/16 09:19 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/27/16 02:35 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation gregf  03/27/16 07:55 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  03/28/16 10:31 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/29/16 03:28 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  03/29/16 03:13 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/29/16 06:24 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  03/29/16 06:35 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Osso1  03/29/16 06:43 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/30/16 07:15 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation MooglyGuy  03/30/16 08:28 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/30/16 09:23 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  03/30/16 04:46 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  03/30/16 09:59 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/30/16 12:30 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  03/30/16 03:11 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  03/31/16 12:22 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Traso  04/07/16 05:37 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/02/16 06:52 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/04/16 02:53 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  04/04/16 05:37 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/04/16 09:26 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/04/16 10:55 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/05/16 07:15 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/05/16 10:39 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/06/16 05:57 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/06/16 07:48 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/07/16 11:42 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  04/07/16 05:28 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/07/16 09:04 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/07/16 11:16 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/08/16 06:32 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/08/16 07:05 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/08/16 11:22 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/09/16 12:03 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/10/16 07:50 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  04/11/16 07:45 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/11/16 08:36 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  04/11/16 08:50 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/11/16 10:42 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/15/16 03:50 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/15/16 11:35 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/19/16 07:39 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/20/16 12:49 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Haze  04/20/16 01:00 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/20/16 04:38 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/20/16 09:35 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/20/16 10:20 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/21/16 12:39 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/28/16 10:35 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/28/16 04:26 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation uman  04/29/16 01:12 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation lettuce  05/02/16 04:14 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation terminento  05/10/16 05:29 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation MooglyGuy  05/10/16 05:52 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation terminento  05/10/16 06:07 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Artman99  06/15/16 05:48 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  06/15/16 07:36 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  06/16/16 07:28 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  06/16/16 07:47 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Artman99  06/16/16 02:44 AM
. * Hi Bart Simo *nt* MooglyGuy  06/16/16 06:19 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  06/16/16 05:14 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Artman99  06/16/16 08:24 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation gamez fan  05/11/16 12:28 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation MooglyGuy  05/10/16 06:27 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation terminento  05/10/16 07:01 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation terminento  05/10/16 11:48 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  05/11/16 05:49 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  05/11/16 04:14 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  05/11/16 05:37 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation DarthMarino  05/11/16 02:57 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation terminento  05/11/16 02:18 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Anonymous  05/11/16 01:19 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  05/12/16 04:52 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation terminento  05/14/16 04:10 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Vas Crabb  05/11/16 04:25 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Anonymous  05/11/16 07:16 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Envisaged0ne  05/11/16 06:55 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Anonymous  05/11/16 07:34 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation terminento  05/11/16 08:36 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/22/16 05:16 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation LensLarque  04/15/16 11:47 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/11/16 09:40 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/13/16 07:40 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/13/16 09:33 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/13/16 10:34 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation R. Belmont  04/14/16 05:02 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/14/16 05:57 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation MooglyGuy  04/14/16 01:41 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/14/16 06:22 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Master O  04/14/16 04:44 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ziggy100  04/15/16 10:23 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Master O  04/15/16 11:42 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation joey35car  04/12/16 12:46 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/08/16 12:10 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/08/16 08:17 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/08/16 01:11 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/05/16 11:17 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  04/05/16 11:45 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/05/16 11:53 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/05/16 11:45 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/05/16 03:21 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  04/05/16 07:00 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/05/16 11:18 AM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Ville Linde  04/05/16 01:23 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  04/05/16 02:46 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation MooglyGuy  04/04/16 03:41 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation Olivier Galibert  03/25/16 02:17 PM
. * Re: Star Wars Arcade (SEGA, 1993): fixing model1 emulation dkongjr  03/25/16 06:18 PM

Extra information Permissions
Moderator:  redk9258, URherenow, Tafoid 
1 registered and 41 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 14297