Previous 199869 Revisions Next

r32483 Wednesday 1st October, 2014 at 16:07:51 UTC by Osso
model1: moved most remaining functions into driver class (nw)
[src/mame/drivers]model1.c
[src/mame/includes]model1.h
[src/mame/machine]model1.c
[src/mame/video]model1.c

trunk/src/mame/drivers/model1.c
r32482r32483
747747{
748748   membank("bank1")->set_base(memregion("maincpu")->base() + 0x1000000);
749749   irq_init();
750   model1_tgp_reset(machine(), !strcmp(machine().system().name, "swa") || !strcmp(machine().system().name, "wingwar") || !strcmp(machine().system().name, "wingwaru") || !strcmp(machine().system().name, "wingwarj"));
750   tgp_reset(!strcmp(machine().system().name, "swa") || !strcmp(machine().system().name, "wingwar") || !strcmp(machine().system().name, "wingwaru") || !strcmp(machine().system().name, "wingwarj"));
751751   if (!strcmp(machine().system().name, "swa"))
752752   {
753753      m_sound_irq = 0;
r32482r32483
762762{
763763   membank("bank1")->set_base(memregion("maincpu")->base() + 0x1000000);
764764   irq_init();
765   model1_vr_tgp_reset(machine());
765   vr_tgp_reset();
766766   m_sound_irq = 3;
767767}
768768
trunk/src/mame/machine/model1.c
r32482r32483
88#include "cpu/v60/v60.h"
99#include "includes/model1.h"
1010
11#define TGP_FUNCTION(name) void name(running_machine &machine)
11#define TGP_FUNCTION(name) void name()
1212
1313
14static UINT32 fifoout_pop(address_space &space)
14UINT32 model1_state::fifoout_pop()
1515{
16   model1_state *state = space.machine().driver_data<model1_state>();
17   UINT32 v;
18   if(state->m_fifoout_wpos == state->m_fifoout_rpos) {
19      fatalerror("TGP FIFOOUT underflow (%x)\n", space.device().safe_pc());
16   if(m_fifoout_wpos == m_fifoout_rpos) {
17      fatalerror("TGP FIFOOUT underflow (%x)\n", safe_pc());
2018   }
21   v = state->m_fifoout_data[state->m_fifoout_rpos++];
22   if(state->m_fifoout_rpos == FIFO_SIZE)
23      state->m_fifoout_rpos = 0;
19   UINT32 v = m_fifoout_data[m_fifoout_rpos++];
20   if(m_fifoout_rpos == FIFO_SIZE)
21      m_fifoout_rpos = 0;
2422   return v;
2523}
2624
2725
28static void fifoout_push(model1_state *state, UINT32 data)
26void model1_state::fifoout_push(UINT32 data)
2927{
30   if(!state->m_puuu)
28   if(!m_puuu)
3129      logerror("TGP: Push %d\n", data);
3230   else
33      state->m_puuu = 0;
34   state->m_fifoout_data[state->m_fifoout_wpos++] = data;
35   if(state->m_fifoout_wpos == FIFO_SIZE)
36      state->m_fifoout_wpos = 0;
37   if(state->m_fifoout_wpos == state->m_fifoout_rpos)
31      m_puuu = 0;
32   m_fifoout_data[m_fifoout_wpos++] = data;
33   if(m_fifoout_wpos == FIFO_SIZE)
34      m_fifoout_wpos = 0;
35   if(m_fifoout_wpos == m_fifoout_rpos)
3836      logerror("TGP FIFOOUT overflow\n");
3937}
4038
41static void fifoout_push_f(model1_state *state, float data)
39void model1_state::fifoout_push_f(float data)
4240{
43   state->m_puuu = 1;
41   m_puuu = 1;
4442
4543   logerror("TGP: Push %f\n", data);
46   fifoout_push(state, f2u(data));
44   fifoout_push(f2u(data));
4745}
4846
49static UINT32 fifoin_pop(model1_state *state)
47UINT32 model1_state::fifoin_pop()
5048{
51   UINT32 v;
52   if(state->m_fifoin_wpos == state->m_fifoin_rpos)
49   if(m_fifoin_wpos == m_fifoin_rpos)
5350      logerror("TGP FIFOIN underflow\n");
54   v = state->m_fifoin_data[state->m_fifoin_rpos++];
55   if(state->m_fifoin_rpos == FIFO_SIZE)
56      state->m_fifoin_rpos = 0;
51   UINT32 v = m_fifoin_data[m_fifoin_rpos++];
52   if(m_fifoin_rpos == FIFO_SIZE)
53      m_fifoin_rpos = 0;
5754   return v;
5855}
5956
60static void fifoin_push(address_space &space, UINT32 data)
57void model1_state::fifoin_push(UINT32 data)
6158{
62   model1_state *state = space.machine().driver_data<model1_state>();
63   //  logerror("TGP FIFOIN write %08x (%x)\n", data, space.device().safe_pc());
64   state->m_fifoin_data[state->m_fifoin_wpos++] = data;
65   if(state->m_fifoin_wpos == FIFO_SIZE)
66      state->m_fifoin_wpos = 0;
67   if(state->m_fifoin_wpos == state->m_fifoin_rpos)
59   //  logerror("TGP FIFOIN write %08x (%x)\n", data, safe_pc());
60   m_fifoin_data[m_fifoin_wpos++] = data;
61   if(m_fifoin_wpos == FIFO_SIZE)
62      m_fifoin_wpos = 0;
63   if(m_fifoin_wpos == m_fifoin_rpos)
6864      logerror("TGP FIFOIN overflow\n");
69   state->m_fifoin_cbcount--;
70   if(!state->m_fifoin_cbcount)
71      state->m_fifoin_cb(space.machine());
65   m_fifoin_cbcount--;
66   if(!m_fifoin_cbcount)
67      (this->*m_fifoin_cb)();
7268}
7369
74static float fifoin_pop_f(model1_state *state)
70float model1_state::fifoin_pop_f()
7571{
76   return u2f(fifoin_pop(state));
72   return u2f(fifoin_pop());
7773}
7874
79static TGP_FUNCTION( function_get_vf );
80static TGP_FUNCTION( function_get_swa );
81
82static void next_fn(model1_state *state)
75void model1_state::next_fn()
8376{
84   state->m_fifoin_cbcount = 1;
85   state->m_fifoin_cb = state->m_swa ? function_get_swa : function_get_vf;
77   m_fifoin_cbcount = 1;
78   m_fifoin_cb = m_swa ? &model1_state::function_get_swa : &model1_state::function_get_vf;
8679}
8780
8881static float tcos(INT16 a)
r32482r32483
109102      return sin(a*(2*M_PI/65536.0));
110103}
111104
112static UINT16 ram_get_i(model1_state *state)
105UINT16 model1_state::ram_get_i()
113106{
114   return state->m_ram_data[state->m_ram_scanadr++];
107   return m_ram_data[m_ram_scanadr++];
115108}
116109
117static float ram_get_f(model1_state *state)
110float model1_state::ram_get_f()
118111{
119   return u2f(state->m_ram_data[state->m_ram_scanadr++]);
112   return u2f(m_ram_data[m_ram_scanadr++]);
120113}
121114
122static TGP_FUNCTION( fadd )
115TGP_FUNCTION( model1_state::fadd )
123116{
124   model1_state *state = machine.driver_data<model1_state>();
125   float a = fifoin_pop_f(state);
126   float b = fifoin_pop_f(state);
117   float a = fifoin_pop_f();
118   float b = fifoin_pop_f();
127119   float r = a+b;
128   logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, state->m_pushpc);
129   fifoout_push_f(state, r);
130   next_fn(state);
120   logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, m_pushpc);
121   fifoout_push_f(r);
122   next_fn();
131123}
132124
133static TGP_FUNCTION( fsub )
125TGP_FUNCTION( model1_state::fsub )
134126{
135   model1_state *state = machine.driver_data<model1_state>();
136   float a = fifoin_pop_f(state);
137   float b = fifoin_pop_f(state);
127   float a = fifoin_pop_f();
128   float b = fifoin_pop_f();
138129   float r = a-b;
139   state->m_dump = 1;
140   logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, state->m_pushpc);
141   fifoout_push_f(state, r);
142   next_fn(state);
130   m_dump = 1;
131   logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, m_pushpc);
132   fifoout_push_f(r);
133   next_fn();
143134}
144135
145static TGP_FUNCTION( fmul )
136TGP_FUNCTION( model1_state::fmul )
146137{
147   model1_state *state = machine.driver_data<model1_state>();
148   float a = fifoin_pop_f(state);
149   float b = fifoin_pop_f(state);
138   float a = fifoin_pop_f();
139   float b = fifoin_pop_f();
150140   float r = a*b;
151   logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, state->m_pushpc);
152   fifoout_push_f(state, r);
153   next_fn(state);
141   logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, m_pushpc);
142   fifoout_push_f(r);
143   next_fn();
154144}
155145
156static TGP_FUNCTION( fdiv )
146TGP_FUNCTION( model1_state::fdiv )
157147{
158   model1_state *state = machine.driver_data<model1_state>();
159   float a = fifoin_pop_f(state);
160   float b = fifoin_pop_f(state);
148   float a = fifoin_pop_f();
149   float b = fifoin_pop_f();
161150//  float r = !b ? 1e39 : a/b;
162151   float r = !b ? 0 : a * (1/b);
163   logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, state->m_pushpc);
164   fifoout_push_f(state, r);
165   next_fn(state);
152   logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, m_pushpc);
153   fifoout_push_f(r);
154   next_fn();
166155}
167156
168static TGP_FUNCTION( matrix_push )
157TGP_FUNCTION( model1_state::matrix_push )
169158{
170   model1_state *state = machine.driver_data<model1_state>();
171   if(state->m_mat_stack_pos != MAT_STACK_SIZE) {
172      memcpy(state->m_mat_stack[state->m_mat_stack_pos], state->m_cmat, sizeof(state->m_cmat));
173      state->m_mat_stack_pos++;
159   if(m_mat_stack_pos != MAT_STACK_SIZE) {
160      memcpy(m_mat_stack[m_mat_stack_pos], m_cmat, sizeof(m_cmat));
161      m_mat_stack_pos++;
174162   }
175   logerror("TGP matrix_push (depth=%d, pc=%x)\n", state->m_mat_stack_pos, state->m_pushpc);
176   next_fn(state);
163   logerror("TGP matrix_push (depth=%d, pc=%x)\n", m_mat_stack_pos, m_pushpc);
164   next_fn();
177165}
178166
179static TGP_FUNCTION( matrix_pop )
167TGP_FUNCTION( model1_state::matrix_pop )
180168{
181   model1_state *state = machine.driver_data<model1_state>();
182   if(state->m_mat_stack_pos) {
183      state->m_mat_stack_pos--;
184      memcpy(state->m_cmat, state->m_mat_stack[state->m_mat_stack_pos], sizeof(state->m_cmat));
169   if(m_mat_stack_pos) {
170      m_mat_stack_pos--;
171      memcpy(m_cmat, m_mat_stack[m_mat_stack_pos], sizeof(m_cmat));
185172   }
186   logerror("TGP matrix_pop (depth=%d, pc=%x)\n", state->m_mat_stack_pos, state->m_pushpc);
187   next_fn(state);
173   logerror("TGP matrix_pop (depth=%d, pc=%x)\n", m_mat_stack_pos, m_pushpc);
174   next_fn();
188175}
189176
190static TGP_FUNCTION( matrix_write )
177TGP_FUNCTION( model1_state::matrix_write )
191178{
192   model1_state *state = machine.driver_data<model1_state>();
193179   int i;
194180   for(i=0; i<12; i++)
195      state->m_cmat[i] = fifoin_pop_f(state);
181      m_cmat[i] = fifoin_pop_f();
196182   logerror("TGP matrix_write %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n",
197            state->m_cmat[0], state->m_cmat[1], state->m_cmat[2], state->m_cmat[3], state->m_cmat[4], state->m_cmat[5], state->m_cmat[6], state->m_cmat[7], state->m_cmat[8], state->m_cmat[9], state->m_cmat[10], state->m_cmat[11],
198            state->m_pushpc);
199   next_fn(state);
183            m_cmat[0], m_cmat[1], m_cmat[2], m_cmat[3], m_cmat[4], m_cmat[5], m_cmat[6], m_cmat[7], m_cmat[8], m_cmat[9], m_cmat[10], m_cmat[11],
184            m_pushpc);
185   next_fn();
200186}
201187
202static TGP_FUNCTION( clear_stack )
188TGP_FUNCTION( model1_state::clear_stack )
203189{
204   model1_state *state = machine.driver_data<model1_state>();
205   logerror("TGP clear_stack (%x)\n", state->m_pushpc);
206   state->m_mat_stack_pos = 0;
207   next_fn(state);
190   logerror("TGP clear_stack (%x)\n", m_pushpc);
191   m_mat_stack_pos = 0;
192   next_fn();
208193}
209194
210static TGP_FUNCTION( matrix_mul )
195TGP_FUNCTION( model1_state::matrix_mul )
211196{
212   model1_state *state = machine.driver_data<model1_state>();
213197   float m[12];
214   float a = fifoin_pop_f(state);
215   float b = fifoin_pop_f(state);
216   float c = fifoin_pop_f(state);
217   float d = fifoin_pop_f(state);
218   float e = fifoin_pop_f(state);
219   float f = fifoin_pop_f(state);
220   float g = fifoin_pop_f(state);
221   float h = fifoin_pop_f(state);
222   float i = fifoin_pop_f(state);
223   float j = fifoin_pop_f(state);
224   float k = fifoin_pop_f(state);
225   float l = fifoin_pop_f(state);
226   logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->m_pushpc);
227   m[0]  = a*state->m_cmat[0] + b*state->m_cmat[3] + c*state->m_cmat[6];
228   m[1]  = a*state->m_cmat[1] + b*state->m_cmat[4] + c*state->m_cmat[7];
229   m[2]  = a*state->m_cmat[2] + b*state->m_cmat[5] + c*state->m_cmat[8];
230   m[3]  = d*state->m_cmat[0] + e*state->m_cmat[3] + f*state->m_cmat[6];
231   m[4]  = d*state->m_cmat[1] + e*state->m_cmat[4] + f*state->m_cmat[7];
232   m[5]  = d*state->m_cmat[2] + e*state->m_cmat[5] + f*state->m_cmat[8];
233   m[6]  = g*state->m_cmat[0] + h*state->m_cmat[3] + i*state->m_cmat[6];
234   m[7]  = g*state->m_cmat[1] + h*state->m_cmat[4] + i*state->m_cmat[7];
235   m[8]  = g*state->m_cmat[2] + h*state->m_cmat[5] + i*state->m_cmat[8];
236   m[9]  = j*state->m_cmat[0] + k*state->m_cmat[3] + l*state->m_cmat[6] + state->m_cmat[9];
237   m[10] = j*state->m_cmat[1] + k*state->m_cmat[4] + l*state->m_cmat[7] + state->m_cmat[10];
238   m[11] = j*state->m_cmat[2] + k*state->m_cmat[5] + l*state->m_cmat[8] + state->m_cmat[11];
198   float a = fifoin_pop_f();
199   float b = fifoin_pop_f();
200   float c = fifoin_pop_f();
201   float d = fifoin_pop_f();
202   float e = fifoin_pop_f();
203   float f = fifoin_pop_f();
204   float g = fifoin_pop_f();
205   float h = fifoin_pop_f();
206   float i = fifoin_pop_f();
207   float j = fifoin_pop_f();
208   float k = fifoin_pop_f();
209   float l = fifoin_pop_f();
210   logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m_pushpc);
211   m[0]  = a*m_cmat[0] + b*m_cmat[3] + c*m_cmat[6];
212   m[1]  = a*m_cmat[1] + b*m_cmat[4] + c*m_cmat[7];
213   m[2]  = a*m_cmat[2] + b*m_cmat[5] + c*m_cmat[8];
214   m[3]  = d*m_cmat[0] + e*m_cmat[3] + f*m_cmat[6];
215   m[4]  = d*m_cmat[1] + e*m_cmat[4] + f*m_cmat[7];
216   m[5]  = d*m_cmat[2] + e*m_cmat[5] + f*m_cmat[8];
217   m[6]  = g*m_cmat[0] + h*m_cmat[3] + i*m_cmat[6];
218   m[7]  = g*m_cmat[1] + h*m_cmat[4] + i*m_cmat[7];
219   m[8]  = g*m_cmat[2] + h*m_cmat[5] + i*m_cmat[8];
220   m[9]  = j*m_cmat[0] + k*m_cmat[3] + l*m_cmat[6] + m_cmat[9];
221   m[10] = j*m_cmat[1] + k*m_cmat[4] + l*m_cmat[7] + m_cmat[10];
222   m[11] = j*m_cmat[2] + k*m_cmat[5] + l*m_cmat[8] + m_cmat[11];
239223
240   memcpy(state->m_cmat, m, sizeof(m));
241   next_fn(state);
224   memcpy(m_cmat, m, sizeof(m));
225   next_fn();
242226}
243227
244static TGP_FUNCTION( anglev )
228TGP_FUNCTION( model1_state::anglev )
245229{
246   model1_state *state = machine.driver_data<model1_state>();
247   float a = fifoin_pop_f(state);
248   float b = fifoin_pop_f(state);
249   logerror("TGP anglev %f, %f (%x)\n", a, b, state->m_pushpc);
230   float a = fifoin_pop_f();
231   float b = fifoin_pop_f();
232   logerror("TGP anglev %f, %f (%x)\n", a, b, m_pushpc);
250233   if(!b) {
251234      if(a>=0)
252         fifoout_push(state, 0);
235         fifoout_push(0);
253236      else
254         fifoout_push(state, (UINT32)-32768);
237         fifoout_push((UINT32)-32768);
255238   } else if(!a) {
256239      if(b>=0)
257         fifoout_push(state, 16384);
240         fifoout_push(16384);
258241      else
259         fifoout_push(state, (UINT32)-16384);
242         fifoout_push((UINT32)-16384);
260243   } else
261      fifoout_push(state, (INT16)(atan2(b, a)*32768/M_PI));
262   next_fn(state);
244      fifoout_push((INT16)(atan2(b, a)*32768/M_PI));
245   next_fn();
263246}
264247
265static TGP_FUNCTION( f11 )
248TGP_FUNCTION( model1_state::f11 )
266249{
267   model1_state *state = machine.driver_data<model1_state>();
268   float a = fifoin_pop_f(state);
269   float b = fifoin_pop_f(state);
270   float c = fifoin_pop_f(state);
271   float d = fifoin_pop_f(state);
272   float e = fifoin_pop_f(state);
273   float f = fifoin_pop_f(state);
274   float g = fifoin_pop_f(state);
275   float h = fifoin_pop_f(state);
276   float i = fifoin_pop_f(state);
250   float a = fifoin_pop_f();
251   float b = fifoin_pop_f();
252   float c = fifoin_pop_f();
253   float d = fifoin_pop_f();
254   float e = fifoin_pop_f();
255   float f = fifoin_pop_f();
256   float g = fifoin_pop_f();
257   float h = fifoin_pop_f();
258   float i = fifoin_pop_f();
277259   (void)a;
278260   (void)b;
279261   (void)c;
r32482r32483
283265   (void)g;
284266   (void)h;
285267   (void)i;
286   logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, state->m_pushpc);
287   fifoout_push_f(state, 0);
288   fifoout_push_f(state, 0);
289   fifoout_push_f(state, 0);
290   next_fn(state);
268   logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, m_pushpc);
269   fifoout_push_f(0);
270   fifoout_push_f(0);
271   fifoout_push_f(0);
272   next_fn();
291273}
292274
293static TGP_FUNCTION( normalize )
275TGP_FUNCTION( model1_state::normalize )
294276{
295   model1_state *state = machine.driver_data<model1_state>();
296   float a = fifoin_pop_f(state);
297   float b = fifoin_pop_f(state);
298   float c = fifoin_pop_f(state);
277   float a = fifoin_pop_f();
278   float b = fifoin_pop_f();
279   float c = fifoin_pop_f();
299280   float n = (a*a+b*b+c*c) / sqrt(a*a+b*b+c*c);
300   logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
301   fifoout_push_f(state, a/n);
302   fifoout_push_f(state, b/n);
303   fifoout_push_f(state, c/n);
304   next_fn(state);
281   logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, m_pushpc);
282   fifoout_push_f(a/n);
283   fifoout_push_f(b/n);
284   fifoout_push_f(c/n);
285   next_fn();
305286}
306287
307static TGP_FUNCTION( acc_seti )
288TGP_FUNCTION( model1_state::acc_seti )
308289{
309   model1_state *state = machine.driver_data<model1_state>();
310   INT32 a = fifoin_pop(state);
311   state->m_dump = 1;
312   logerror("TGP acc_seti %d (%x)\n", a, state->m_pushpc);
313   state->m_acc = a;
314   next_fn(state);
290   INT32 a = fifoin_pop();
291   m_dump = 1;
292   logerror("TGP acc_seti %d (%x)\n", a, m_pushpc);
293   m_acc = a;
294   next_fn();
315295}
316296
317static TGP_FUNCTION( track_select )
297TGP_FUNCTION( model1_state::track_select )
318298{
319   model1_state *state = machine.driver_data<model1_state>();
320   INT32 a = fifoin_pop(state);
321   logerror("TGP track_select %d (%x)\n", a, state->m_pushpc);
322   state->m_tgp_vr_select = a;
323   next_fn(state);
299   INT32 a = fifoin_pop();
300   logerror("TGP track_select %d (%x)\n", a, m_pushpc);
301   m_tgp_vr_select = a;
302   next_fn();
324303}
325304
326static TGP_FUNCTION( f14 )
305TGP_FUNCTION( model1_state::f14 )
327306{
328   model1_state *state = machine.driver_data<model1_state>();
329   state->m_tgp_vr_base[0] = fifoin_pop_f(state);
330   state->m_tgp_vr_base[1] = fifoin_pop_f(state);
331   state->m_tgp_vr_base[2] = fifoin_pop_f(state);
332   state->m_tgp_vr_base[3] = fifoin_pop_f(state);
307   m_tgp_vr_base[0] = fifoin_pop_f();
308   m_tgp_vr_base[1] = fifoin_pop_f();
309   m_tgp_vr_base[2] = fifoin_pop_f();
310   m_tgp_vr_base[3] = fifoin_pop_f();
333311
334   next_fn(state);
312   next_fn();
335313}
336314
337static TGP_FUNCTION( f15_swa )
315TGP_FUNCTION( model1_state::f15_swa )
338316{
339   model1_state *state = machine.driver_data<model1_state>();
340   logerror("TGP f15_swa (%x)\n", state->m_pushpc);
317   logerror("TGP f15_swa (%x)\n", m_pushpc);
341318
342   next_fn(state);
319   next_fn();
343320}
344321
345static TGP_FUNCTION( anglep )
322TGP_FUNCTION( model1_state::anglep )
346323{
347   model1_state *state = machine.driver_data<model1_state>();
348   float a = fifoin_pop_f(state);
349   float b = fifoin_pop_f(state);
350   float c = fifoin_pop_f(state);
351   float d = fifoin_pop_f(state);
352   logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, state->m_pushpc);
324   float a = fifoin_pop_f();
325   float b = fifoin_pop_f();
326   float c = fifoin_pop_f();
327   float d = fifoin_pop_f();
328   logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, m_pushpc);
353329   c = a - c;
354330   d = b - d;
355331   if(!d) {
356332      if(c>=0)
357         fifoout_push(state, 0);
333         fifoout_push(0);
358334      else
359         fifoout_push(state, (UINT32)-32768);
335         fifoout_push((UINT32)-32768);
360336   } else if(!c) {
361337      if(d>=0)
362         fifoout_push(state, 16384);
338         fifoout_push(16384);
363339      else
364         fifoout_push(state, (UINT32)-16384);
340         fifoout_push((UINT32)-16384);
365341   } else
366      fifoout_push(state, (INT16)(atan2(d, c)*32768/M_PI));
367   next_fn(state);
342      fifoout_push((INT16)(atan2(d, c)*32768/M_PI));
343   next_fn();
368344}
369345
370static TGP_FUNCTION( matrix_ident )
346TGP_FUNCTION( model1_state::matrix_ident )
371347{
372   model1_state *state = machine.driver_data<model1_state>();
373   logerror("TGP matrix_ident (%x)\n", state->m_pushpc);
374   memset(state->m_cmat, 0, sizeof(state->m_cmat));
375   state->m_cmat[0] = 1.0;
376   state->m_cmat[4] = 1.0;
377   state->m_cmat[8] = 1.0;
378   next_fn(state);
348   logerror("TGP matrix_ident (%x)\n", m_pushpc);
349   memset(m_cmat, 0, sizeof(m_cmat));
350   m_cmat[0] = 1.0;
351   m_cmat[4] = 1.0;
352   m_cmat[8] = 1.0;
353   next_fn();
379354}
380355
381static TGP_FUNCTION( matrix_read )
356TGP_FUNCTION( model1_state::matrix_read )
382357{
383   model1_state *state = machine.driver_data<model1_state>();
384358   int i;
385359   logerror("TGP matrix_read (%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n",
386            state->m_cmat[0], state->m_cmat[1], state->m_cmat[2], state->m_cmat[3], state->m_cmat[4], state->m_cmat[5], state->m_cmat[6], state->m_cmat[7], state->m_cmat[8], state->m_cmat[9], state->m_cmat[10], state->m_cmat[11], state->m_pushpc);
360            m_cmat[0], m_cmat[1], m_cmat[2], m_cmat[3], m_cmat[4], m_cmat[5], m_cmat[6], m_cmat[7], m_cmat[8], m_cmat[9], m_cmat[10], m_cmat[11], m_pushpc);
387361   for(i=0; i<12; i++)
388      fifoout_push_f(state, state->m_cmat[i]);
389   next_fn(state);
362      fifoout_push_f(m_cmat[i]);
363   next_fn();
390364}
391365
392static TGP_FUNCTION( matrix_trans )
366TGP_FUNCTION( model1_state::matrix_trans )
393367{
394   model1_state *state = machine.driver_data<model1_state>();
395   float a = fifoin_pop_f(state);
396   float b = fifoin_pop_f(state);
397   float c = fifoin_pop_f(state);
368   float a = fifoin_pop_f();
369   float b = fifoin_pop_f();
370   float c = fifoin_pop_f();
398371
399   state->m_cmat[ 9] += state->m_cmat[0]*a+state->m_cmat[3]*b+state->m_cmat[6]*c;
400   state->m_cmat[10] += state->m_cmat[1]*a+state->m_cmat[4]*b+state->m_cmat[7]*c;
401   state->m_cmat[11] += state->m_cmat[2]*a+state->m_cmat[5]*b+state->m_cmat[8]*c;
402   next_fn(state);
372   m_cmat[ 9] += m_cmat[0]*a+m_cmat[3]*b+m_cmat[6]*c;
373   m_cmat[10] += m_cmat[1]*a+m_cmat[4]*b+m_cmat[7]*c;
374   m_cmat[11] += m_cmat[2]*a+m_cmat[5]*b+m_cmat[8]*c;
375   next_fn();
403376}
404377
405static TGP_FUNCTION( matrix_scale )
378TGP_FUNCTION( model1_state::matrix_scale )
406379{
407   model1_state *state = machine.driver_data<model1_state>();
408   float a = fifoin_pop_f(state);
409   float b = fifoin_pop_f(state);
410   float c = fifoin_pop_f(state);
411   logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
412   state->m_cmat[0] *= a;
413   state->m_cmat[1] *= a;
414   state->m_cmat[2] *= a;
415   state->m_cmat[3] *= b;
416   state->m_cmat[4] *= b;
417   state->m_cmat[5] *= b;
418   state->m_cmat[6] *= c;
419   state->m_cmat[7] *= c;
420   state->m_cmat[8] *= c;
421   next_fn(state);
380   float a = fifoin_pop_f();
381   float b = fifoin_pop_f();
382   float c = fifoin_pop_f();
383   logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, m_pushpc);
384   m_cmat[0] *= a;
385   m_cmat[1] *= a;
386   m_cmat[2] *= a;
387   m_cmat[3] *= b;
388   m_cmat[4] *= b;
389   m_cmat[5] *= b;
390   m_cmat[6] *= c;
391   m_cmat[7] *= c;
392   m_cmat[8] *= c;
393   next_fn();
422394}
423395
424static TGP_FUNCTION( matrix_rotx )
396TGP_FUNCTION( model1_state::matrix_rotx )
425397{
426   model1_state *state = machine.driver_data<model1_state>();
427   INT16 a = fifoin_pop(state);
398   INT16 a = fifoin_pop();
428399   float s = tsin(a);
429400   float c = tcos(a);
430401   float t1, t2;
431   logerror("TGP matrix_rotx %d (%x)\n", a, state->m_pushpc);
432   t1 = state->m_cmat[3];
433   t2 = state->m_cmat[6];
434   state->m_cmat[3] = c*t1-s*t2;
435   state->m_cmat[6] = s*t1+c*t2;
436   t1 = state->m_cmat[4];
437   t2 = state->m_cmat[7];
438   state->m_cmat[4] = c*t1-s*t2;
439   state->m_cmat[7] = s*t1+c*t2;
440   t1 = state->m_cmat[5];
441   t2 = state->m_cmat[8];
442   state->m_cmat[5] = c*t1-s*t2;
443   state->m_cmat[8] = s*t1+c*t2;
444   next_fn(state);
402   logerror("TGP matrix_rotx %d (%x)\n", a, m_pushpc);
403   t1 = m_cmat[3];
404   t2 = m_cmat[6];
405   m_cmat[3] = c*t1-s*t2;
406   m_cmat[6] = s*t1+c*t2;
407   t1 = m_cmat[4];
408   t2 = m_cmat[7];
409   m_cmat[4] = c*t1-s*t2;
410   m_cmat[7] = s*t1+c*t2;
411   t1 = m_cmat[5];
412   t2 = m_cmat[8];
413   m_cmat[5] = c*t1-s*t2;
414   m_cmat[8] = s*t1+c*t2;
415   next_fn();
445416}
446417
447static TGP_FUNCTION( matrix_roty )
418TGP_FUNCTION( model1_state::matrix_roty )
448419{
449   model1_state *state = machine.driver_data<model1_state>();
450   INT16 a = fifoin_pop(state);
420   INT16 a = fifoin_pop();
451421   float s = tsin(a);
452422   float c = tcos(a);
453423   float t1, t2;
454424
455   logerror("TGP matrix_roty %d (%x)\n", a, state->m_pushpc);
456   t1 = state->m_cmat[6];
457   t2 = state->m_cmat[0];
458   state->m_cmat[6] = c*t1-s*t2;
459   state->m_cmat[0] = s*t1+c*t2;
460   t1 = state->m_cmat[7];
461   t2 = state->m_cmat[1];
462   state->m_cmat[7] = c*t1-s*t2;
463   state->m_cmat[1] = s*t1+c*t2;
464   t1 = state->m_cmat[8];
465   t2 = state->m_cmat[2];
466   state->m_cmat[8] = c*t1-s*t2;
467   state->m_cmat[2] = s*t1+c*t2;
468   next_fn(state);
425   logerror("TGP matrix_roty %d (%x)\n", a, m_pushpc);
426   t1 = m_cmat[6];
427   t2 = m_cmat[0];
428   m_cmat[6] = c*t1-s*t2;
429   m_cmat[0] = s*t1+c*t2;
430   t1 = m_cmat[7];
431   t2 = m_cmat[1];
432   m_cmat[7] = c*t1-s*t2;
433   m_cmat[1] = s*t1+c*t2;
434   t1 = m_cmat[8];
435   t2 = m_cmat[2];
436   m_cmat[8] = c*t1-s*t2;
437   m_cmat[2] = s*t1+c*t2;
438   next_fn();
469439}
470440
471static TGP_FUNCTION( matrix_rotz )
441TGP_FUNCTION( model1_state::matrix_rotz )
472442{
473   model1_state *state = machine.driver_data<model1_state>();
474   INT16 a = fifoin_pop(state);
443   INT16 a = fifoin_pop();
475444   float s = tsin(a);
476445   float c = tcos(a);
477446   float t1, t2;
478447
479   logerror("TGP matrix_rotz %d (%x)\n", a, state->m_pushpc);
480   t1 = state->m_cmat[0];
481   t2 = state->m_cmat[3];
482   state->m_cmat[0] = c*t1-s*t2;
483   state->m_cmat[3] = s*t1+c*t2;
484   t1 = state->m_cmat[1];
485   t2 = state->m_cmat[4];
486   state->m_cmat[1] = c*t1-s*t2;
487   state->m_cmat[4] = s*t1+c*t2;
488   t1 = state->m_cmat[2];
489   t2 = state->m_cmat[5];
490   state->m_cmat[2] = c*t1-s*t2;
491   state->m_cmat[5] = s*t1+c*t2;
492   next_fn(state);
448   logerror("TGP matrix_rotz %d (%x)\n", a, m_pushpc);
449   t1 = m_cmat[0];
450   t2 = m_cmat[3];
451   m_cmat[0] = c*t1-s*t2;
452   m_cmat[3] = s*t1+c*t2;
453   t1 = m_cmat[1];
454   t2 = m_cmat[4];
455   m_cmat[1] = c*t1-s*t2;
456   m_cmat[4] = s*t1+c*t2;
457   t1 = m_cmat[2];
458   t2 = m_cmat[5];
459   m_cmat[2] = c*t1-s*t2;
460   m_cmat[5] = s*t1+c*t2;
461   next_fn();
493462}
494463
495static TGP_FUNCTION( track_read_quad )
464TGP_FUNCTION( model1_state::track_read_quad )
496465{
497   model1_state *state = machine.driver_data<model1_state>();
498   const UINT32 *tgp_data = (const UINT32 *)state->memregion("user2")->base();
499   UINT32 a = fifoin_pop(state);
466   const UINT32 *tgp_data = (const UINT32 *)memregion("user2")->base();
467   UINT32 a = fifoin_pop();
500468   int offd;
501469
502   logerror("TGP track_read_quad %d (%x)\n", a, state->m_pushpc);
470   logerror("TGP track_read_quad %d (%x)\n", a, m_pushpc);
503471
504   offd = tgp_data[0x20+state->m_tgp_vr_select] + 16*a;
505   fifoout_push(state, tgp_data[offd]);
506   fifoout_push(state, tgp_data[offd+1]);
507   fifoout_push(state, tgp_data[offd+2]);
508   fifoout_push(state, tgp_data[offd+3]);
509   fifoout_push(state, tgp_data[offd+4]);
510   fifoout_push(state, tgp_data[offd+5]);
511   fifoout_push(state, tgp_data[offd+6]);
512   fifoout_push(state, tgp_data[offd+7]);
513   fifoout_push(state, tgp_data[offd+8]);
514   fifoout_push(state, tgp_data[offd+9]);
515   fifoout_push(state, tgp_data[offd+10]);
516   fifoout_push(state, tgp_data[offd+11]);
517   next_fn(state);
472   offd = tgp_data[0x20+m_tgp_vr_select] + 16*a;
473   fifoout_push(tgp_data[offd]);
474   fifoout_push(tgp_data[offd+1]);
475   fifoout_push(tgp_data[offd+2]);
476   fifoout_push(tgp_data[offd+3]);
477   fifoout_push(tgp_data[offd+4]);
478   fifoout_push(tgp_data[offd+5]);
479   fifoout_push(tgp_data[offd+6]);
480   fifoout_push(tgp_data[offd+7]);
481   fifoout_push(tgp_data[offd+8]);
482   fifoout_push(tgp_data[offd+9]);
483   fifoout_push(tgp_data[offd+10]);
484   fifoout_push(tgp_data[offd+11]);
485   next_fn();
518486}
519487
520static TGP_FUNCTION( f24_swa )
488TGP_FUNCTION( model1_state::f24_swa )
521489{
522   model1_state *state = machine.driver_data<model1_state>();
523   float a = fifoin_pop_f(state);
524   float b = fifoin_pop_f(state);
525   float c = fifoin_pop_f(state);
526   float d = fifoin_pop_f(state);
527   float e = fifoin_pop_f(state);
528   float f = fifoin_pop_f(state);
529   UINT32 g = fifoin_pop(state);
490   float a = fifoin_pop_f();
491   float b = fifoin_pop_f();
492   float c = fifoin_pop_f();
493   float d = fifoin_pop_f();
494   float e = fifoin_pop_f();
495   float f = fifoin_pop_f();
496   UINT32 g = fifoin_pop();
530497   (void)a;
531498   (void)b;
532499   (void)c;
r32482r32483
534501   (void)e;
535502   (void)f;
536503   (void)g;
537   logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, state->m_pushpc);
538   fifoout_push_f(state, 0);
539   next_fn(state);
504   logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, m_pushpc);
505   fifoout_push_f(0);
506   next_fn();
540507}
541508
542static TGP_FUNCTION( transform_point )
509TGP_FUNCTION( model1_state::transform_point )
543510{
544   model1_state *state = machine.driver_data<model1_state>();
545   float x = fifoin_pop_f(state);
546   float y = fifoin_pop_f(state);
547   float z = fifoin_pop_f(state);
548   logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, state->m_pushpc);
511   float x = fifoin_pop_f();
512   float y = fifoin_pop_f();
513   float z = fifoin_pop_f();
514   logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, m_pushpc);
549515
550   fifoout_push_f(state, state->m_cmat[0]*x+state->m_cmat[3]*y+state->m_cmat[6]*z+state->m_cmat[9]);
551   fifoout_push_f(state, state->m_cmat[1]*x+state->m_cmat[4]*y+state->m_cmat[7]*z+state->m_cmat[10]);
552   fifoout_push_f(state, state->m_cmat[2]*x+state->m_cmat[5]*y+state->m_cmat[8]*z+state->m_cmat[11]);
553   next_fn(state);
516   fifoout_push_f(m_cmat[0]*x+m_cmat[3]*y+m_cmat[6]*z+m_cmat[9]);
517   fifoout_push_f(m_cmat[1]*x+m_cmat[4]*y+m_cmat[7]*z+m_cmat[10]);
518   fifoout_push_f(m_cmat[2]*x+m_cmat[5]*y+m_cmat[8]*z+m_cmat[11]);
519   next_fn();
554520}
555521
556static TGP_FUNCTION( fcos_m1 )
522TGP_FUNCTION( model1_state::fcos_m1 )
557523{
558   model1_state *state = machine.driver_data<model1_state>();
559   INT16 a = fifoin_pop(state);
560   logerror("TGP fcos %d (%x)\n", a, state->m_pushpc);
561   fifoout_push_f(state, tcos(a));
562   next_fn(state);
524   INT16 a = fifoin_pop();
525   logerror("TGP fcos %d (%x)\n", a, m_pushpc);
526   fifoout_push_f(tcos(a));
527   next_fn();
563528}
564529
565static TGP_FUNCTION( fsin_m1 )
530TGP_FUNCTION( model1_state::fsin_m1 )
566531{
567   model1_state *state = machine.driver_data<model1_state>();
568   INT16 a = fifoin_pop(state);
569   logerror("TGP fsin %d (%x)\n", a, state->m_pushpc);
570   fifoout_push_f(state, tsin(a));
571   next_fn(state);
532   INT16 a = fifoin_pop();
533   logerror("TGP fsin %d (%x)\n", a, m_pushpc);
534   fifoout_push_f(tsin(a));
535   next_fn();
572536}
573537
574static TGP_FUNCTION( fcosm_m1 )
538TGP_FUNCTION( model1_state::fcosm_m1 )
575539{
576   model1_state *state = machine.driver_data<model1_state>();
577   INT16 a = fifoin_pop(state);
578   float b = fifoin_pop_f(state);
579   logerror("TGP fcosm %d, %f (%x)\n", a, b, state->m_pushpc);
580   fifoout_push_f(state, b*tcos(a));
581   next_fn(state);
540   INT16 a = fifoin_pop();
541   float b = fifoin_pop_f();
542   logerror("TGP fcosm %d, %f (%x)\n", a, b, m_pushpc);
543   fifoout_push_f(b*tcos(a));
544   next_fn();
582545}
583546
584static TGP_FUNCTION( fsinm_m1 )
547TGP_FUNCTION( model1_state::fsinm_m1 )
585548{
586   model1_state *state = machine.driver_data<model1_state>();
587   INT16 a = fifoin_pop(state);
588   float b = fifoin_pop_f(state);
589   state->m_dump = 1;
590   logerror("TGP fsinm %d, %f (%x)\n", a, b, state->m_pushpc);
591   fifoout_push_f(state, b*tsin(a));
592   next_fn(state);
549   INT16 a = fifoin_pop();
550   float b = fifoin_pop_f();
551   m_dump = 1;
552   logerror("TGP fsinm %d, %f (%x)\n", a, b, m_pushpc);
553   fifoout_push_f(b*tsin(a));
554   next_fn();
593555}
594556
595static TGP_FUNCTION( distance3 )
557TGP_FUNCTION( model1_state::distance3 )
596558{
597   model1_state *state = machine.driver_data<model1_state>();
598   float a = fifoin_pop_f(state);
599   float b = fifoin_pop_f(state);
600   float c = fifoin_pop_f(state);
601   float d = fifoin_pop_f(state);
602   float e = fifoin_pop_f(state);
603   float f = fifoin_pop_f(state);
604   logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, state->m_pushpc);
559   float a = fifoin_pop_f();
560   float b = fifoin_pop_f();
561   float c = fifoin_pop_f();
562   float d = fifoin_pop_f();
563   float e = fifoin_pop_f();
564   float f = fifoin_pop_f();
565   logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, m_pushpc);
605566   a -= d;
606567   b -= e;
607568   c -= f;
608   fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
609   next_fn(state);
569   fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
570   next_fn();
610571}
611572
612static TGP_FUNCTION( ftoi )
573TGP_FUNCTION( model1_state::ftoi )
613574{
614   model1_state *state = machine.driver_data<model1_state>();
615   float a = fifoin_pop_f(state);
616   logerror("TGP ftoi %f (%x)\n", a, state->m_pushpc);
617   fifoout_push(state, (int)a);
618   next_fn(state);
575   float a = fifoin_pop_f();
576   logerror("TGP ftoi %f (%x)\n", a, m_pushpc);
577   fifoout_push((int)a);
578   next_fn();
619579}
620580
621static TGP_FUNCTION( itof )
581TGP_FUNCTION( model1_state::itof )
622582{
623   model1_state *state = machine.driver_data<model1_state>();
624   INT32 a = fifoin_pop(state);
625   logerror("TGP itof %d (%x)\n", a, state->m_pushpc);
626   fifoout_push_f(state, a);
627   next_fn(state);
583   INT32 a = fifoin_pop();
584   logerror("TGP itof %d (%x)\n", a, m_pushpc);
585   fifoout_push_f(a);
586   next_fn();
628587}
629588
630static TGP_FUNCTION( acc_set )
589TGP_FUNCTION( model1_state::acc_set )
631590{
632   model1_state *state = machine.driver_data<model1_state>();
633   float a = fifoin_pop_f(state);
634   logerror("TGP acc_set %f (%x)\n", a, state->m_pushpc);
635   state->m_acc = a;
636   next_fn(state);
591   float a = fifoin_pop_f();
592   logerror("TGP acc_set %f (%x)\n", a, m_pushpc);
593   m_acc = a;
594   next_fn();
637595}
638596
639static TGP_FUNCTION( acc_get )
597TGP_FUNCTION( model1_state::acc_get )
640598{
641   model1_state *state = machine.driver_data<model1_state>();
642   logerror("TGP acc_get (%x)\n", state->m_pushpc);
643   fifoout_push_f(state, state->m_acc);
644   next_fn(state);
599   logerror("TGP acc_get (%x)\n", m_pushpc);
600   fifoout_push_f(m_acc);
601   next_fn();
645602}
646603
647static TGP_FUNCTION( acc_add )
604TGP_FUNCTION( model1_state::acc_add )
648605{
649   model1_state *state = machine.driver_data<model1_state>();
650   float a = fifoin_pop_f(state);
651   logerror("TGP acc_add %f (%x)\n", a, state->m_pushpc);
652   state->m_acc += a;
653   next_fn(state);
606   float a = fifoin_pop_f();
607   logerror("TGP acc_add %f (%x)\n", a, m_pushpc);
608   m_acc += a;
609   next_fn();
654610}
655611
656static TGP_FUNCTION( acc_sub )
612TGP_FUNCTION( model1_state::acc_sub )
657613{
658   model1_state *state = machine.driver_data<model1_state>();
659   float a = fifoin_pop_f(state);
660   logerror("TGP acc_sub %f (%x)\n", a, state->m_pushpc);
661   state->m_acc -= a;
662   next_fn(state);
614   float a = fifoin_pop_f();
615   logerror("TGP acc_sub %f (%x)\n", a, m_pushpc);
616   m_acc -= a;
617   next_fn();
663618}
664619
665static TGP_FUNCTION( acc_mul )
620TGP_FUNCTION( model1_state::acc_mul )
666621{
667   model1_state *state = machine.driver_data<model1_state>();
668   float a = fifoin_pop_f(state);
669   logerror("TGP acc_mul %f (%x)\n", a, state->m_pushpc);
670   state->m_acc *= a;
671   next_fn(state);
622   float a = fifoin_pop_f();
623   logerror("TGP acc_mul %f (%x)\n", a, m_pushpc);
624   m_acc *= a;
625   next_fn();
672626}
673627
674static TGP_FUNCTION( acc_div )
628TGP_FUNCTION( model1_state::acc_div )
675629{
676   model1_state *state = machine.driver_data<model1_state>();
677   float a = fifoin_pop_f(state);
678   logerror("TGP acc_div %f (%x)\n", a, state->m_pushpc);
679   state->m_acc /= a;
680   next_fn(state);
630   float a = fifoin_pop_f();
631   logerror("TGP acc_div %f (%x)\n", a, m_pushpc);
632   m_acc /= a;
633   next_fn();
681634}
682635
683static TGP_FUNCTION( f42 )
636TGP_FUNCTION( model1_state::f42 )
684637{
685   model1_state *state = machine.driver_data<model1_state>();
686   float a = fifoin_pop_f(state);
687   float b = fifoin_pop_f(state);
688   float c = fifoin_pop_f(state);
638   float a = fifoin_pop_f();
639   float b = fifoin_pop_f();
640   float c = fifoin_pop_f();
689641   (void)a;
690642   (void)b;
691643   (void)c;
692   logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
693   //  fifoout_push_f((machine.rand() % 1000) - 500);
694   fifoout_push_f(state, 0);
695   fifoout_push_f(state, 0);
696   fifoout_push_f(state, 0);
697   fifoout_push_f(state, 0);
698   fifoout_push_f(state, 0);
699   fifoout_push_f(state, 0);
700   next_fn(state);
644   logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, m_pushpc);
645   //  fifoout_push_f((machine().rand() % 1000) - 500);
646   fifoout_push_f(0);
647   fifoout_push_f(0);
648   fifoout_push_f(0);
649   fifoout_push_f(0);
650   fifoout_push_f(0);
651   fifoout_push_f(0);
652   next_fn();
701653}
702654
703655
704656// r = (x2 + y2 + z2)1/2,     f = tan-1(y/(x2+z2)1/2),     q = tan-1(z/x)
705657
706static TGP_FUNCTION( xyz2rqf )
658TGP_FUNCTION( model1_state::xyz2rqf )
707659{
708   model1_state *state = machine.driver_data<model1_state>();
709   float a = fifoin_pop_f(state);
710   float b = fifoin_pop_f(state);
711   float c = fifoin_pop_f(state);
660   float a = fifoin_pop_f();
661   float b = fifoin_pop_f();
662   float c = fifoin_pop_f();
712663   float norm;
713664   (void)a;
714665   (void)b;
715666   (void)c;
716   logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
717   fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
667   logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, m_pushpc);
668   fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
718669   norm = sqrt(a*a+c*c);
719670   if(!c) {
720671      if(a>=0)
721         fifoout_push(state, 0);
672         fifoout_push(0);
722673      else
723         fifoout_push(state, (UINT32)-32768);
674         fifoout_push((UINT32)-32768);
724675   } else if(!a) {
725676      if(c>=0)
726         fifoout_push(state, 16384);
677         fifoout_push(16384);
727678      else
728         fifoout_push(state, (UINT32)-16384);
679         fifoout_push((UINT32)-16384);
729680   } else
730      fifoout_push(state, (INT16)(atan2(c, a)*32768/M_PI));
681      fifoout_push((INT16)(atan2(c, a)*32768/M_PI));
731682
732683   if(!b)
733      fifoout_push(state, 0);
684      fifoout_push(0);
734685   else if(!norm) {
735686      if(b>=0)
736         fifoout_push(state, 16384);
687         fifoout_push(16384);
737688      else
738         fifoout_push(state, (UINT32)-16384);
689         fifoout_push((UINT32)-16384);
739690   } else
740      fifoout_push(state, (INT16)(atan2(b, norm)*32768/M_PI));
691      fifoout_push((INT16)(atan2(b, norm)*32768/M_PI));
741692
742   next_fn(state);
693   next_fn();
743694}
744695
745static TGP_FUNCTION( f43 )
696TGP_FUNCTION( model1_state::f43 )
746697{
747   model1_state *state = machine.driver_data<model1_state>();
748   float a = fifoin_pop_f(state);
749   float b = fifoin_pop_f(state);
750   float c = fifoin_pop_f(state);
751   float d = fifoin_pop_f(state);
752   float e = fifoin_pop_f(state);
753   float f = fifoin_pop_f(state);
698   float a = fifoin_pop_f();
699   float b = fifoin_pop_f();
700   float c = fifoin_pop_f();
701   float d = fifoin_pop_f();
702   float e = fifoin_pop_f();
703   float f = fifoin_pop_f();
754704   (void)a;
755705   (void)b;
756706   (void)c;
757707   (void)d;
758708   (void)e;
759709   (void)f;
760   logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->m_pushpc);
761   fifoout_push_f(state, 0);
762   fifoout_push_f(state, 0);
763   fifoout_push_f(state, 0);
764   fifoout_push_f(state, 0);
765   next_fn(state);
710   logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, m_pushpc);
711   fifoout_push_f(0);
712   fifoout_push_f(0);
713   fifoout_push_f(0);
714   fifoout_push_f(0);
715   next_fn();
766716}
767717
768static TGP_FUNCTION( f43_swa )
718TGP_FUNCTION( model1_state::f43_swa )
769719{
770   model1_state *state = machine.driver_data<model1_state>();
771   float a = fifoin_pop_f(state);
772   int b = fifoin_pop(state);
773   int c = fifoin_pop(state);
720   float a = fifoin_pop_f();
721   int b = fifoin_pop();
722   int c = fifoin_pop();
774723   (void)a;
775724   (void)b;
776725   (void)c;
777   logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, state->m_pushpc);
778   fifoout_push_f(state, 0);
779   fifoout_push_f(state, 0);
780   fifoout_push_f(state, 0);
781   next_fn(state);
726   logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, m_pushpc);
727   fifoout_push_f(0);
728   fifoout_push_f(0);
729   fifoout_push_f(0);
730   next_fn();
782731}
783732
784static TGP_FUNCTION( f44 )
733TGP_FUNCTION( model1_state::f44 )
785734{
786   model1_state *state = machine.driver_data<model1_state>();
787   float a = fifoin_pop_f(state);
735   float a = fifoin_pop_f();
788736   (void)a;
789   logerror("TGP f44 %f (%x)\n", a, state->m_pushpc);
790   fifoout_push_f(state, 0);
791   fifoout_push_f(state, 0);
792   fifoout_push_f(state, 0);
793   next_fn(state);
737   logerror("TGP f44 %f (%x)\n", a, m_pushpc);
738   fifoout_push_f(0);
739   fifoout_push_f(0);
740   fifoout_push_f(0);
741   next_fn();
794742}
795743
796static TGP_FUNCTION( matrix_sdir )
744TGP_FUNCTION( model1_state::matrix_sdir )
797745{
798   model1_state *state = machine.driver_data<model1_state>();
799   float a = fifoin_pop_f(state);
800   float b = fifoin_pop_f(state);
801   float c = fifoin_pop_f(state);
746   float a = fifoin_pop_f();
747   float b = fifoin_pop_f();
748   float c = fifoin_pop_f();
802749   float norm = sqrt(a*a+b*b+c*c);
803750   float t[9], m[9];
804   logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
751   logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, m_pushpc);
805752
806753   memset(t, 0, sizeof(t));
807754
r32482r32483
829776      t[5] /= norm;
830777   }
831778
832   m[0]  = t[0]*state->m_cmat[0] + t[1]*state->m_cmat[3] + t[2]*state->m_cmat[6];
833   m[1]  = t[0]*state->m_cmat[1] + t[1]*state->m_cmat[4] + t[2]*state->m_cmat[7];
834   m[2]  = t[0]*state->m_cmat[2] + t[1]*state->m_cmat[5] + t[2]*state->m_cmat[8];
835   m[3]  = t[3]*state->m_cmat[0] + t[4]*state->m_cmat[3] + t[5]*state->m_cmat[6];
836   m[4]  = t[3]*state->m_cmat[1] + t[4]*state->m_cmat[4] + t[5]*state->m_cmat[7];
837   m[5]  = t[3]*state->m_cmat[2] + t[4]*state->m_cmat[5] + t[5]*state->m_cmat[8];
838   m[6]  = t[6]*state->m_cmat[0] + t[7]*state->m_cmat[3] + t[8]*state->m_cmat[6];
839   m[7]  = t[6]*state->m_cmat[1] + t[7]*state->m_cmat[4] + t[8]*state->m_cmat[7];
840   m[8]  = t[6]*state->m_cmat[2] + t[7]*state->m_cmat[5] + t[8]*state->m_cmat[8];
779   m[0]  = t[0]*m_cmat[0] + t[1]*m_cmat[3] + t[2]*m_cmat[6];
780   m[1]  = t[0]*m_cmat[1] + t[1]*m_cmat[4] + t[2]*m_cmat[7];
781   m[2]  = t[0]*m_cmat[2] + t[1]*m_cmat[5] + t[2]*m_cmat[8];
782   m[3]  = t[3]*m_cmat[0] + t[4]*m_cmat[3] + t[5]*m_cmat[6];
783   m[4]  = t[3]*m_cmat[1] + t[4]*m_cmat[4] + t[5]*m_cmat[7];
784   m[5]  = t[3]*m_cmat[2] + t[4]*m_cmat[5] + t[5]*m_cmat[8];
785   m[6]  = t[6]*m_cmat[0] + t[7]*m_cmat[3] + t[8]*m_cmat[6];
786   m[7]  = t[6]*m_cmat[1] + t[7]*m_cmat[4] + t[8]*m_cmat[7];
787   m[8]  = t[6]*m_cmat[2] + t[7]*m_cmat[5] + t[8]*m_cmat[8];
841788
842   memcpy(state->m_cmat, m, sizeof(m));
789   memcpy(m_cmat, m, sizeof(m));
843790
844   next_fn(state);
791   next_fn();
845792}
846793
847static TGP_FUNCTION( f45 )
794TGP_FUNCTION( model1_state::f45 )
848795{
849   model1_state *state = machine.driver_data<model1_state>();
850   float a = fifoin_pop_f(state);
796   float a = fifoin_pop_f();
851797   (void)a;
852   logerror("TGP f45 %f (%x)\n", a, state->m_pushpc);
853   fifoout_push_f(state, 0);
854   next_fn(state);
798   logerror("TGP f45 %f (%x)\n", a, m_pushpc);
799   fifoout_push_f(0);
800   next_fn();
855801}
856802
857static TGP_FUNCTION( vlength )
803TGP_FUNCTION( model1_state::vlength )
858804{
859   model1_state *state = machine.driver_data<model1_state>();
860   float a = fifoin_pop_f(state) - state->m_tgp_vr_base[0];
861   float b = fifoin_pop_f(state) - state->m_tgp_vr_base[1];
862   float c = fifoin_pop_f(state) - state->m_tgp_vr_base[2];
863   logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
805   float a = fifoin_pop_f() - m_tgp_vr_base[0];
806   float b = fifoin_pop_f() - m_tgp_vr_base[1];
807   float c = fifoin_pop_f() - m_tgp_vr_base[2];
808   logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, m_pushpc);
864809
865810   a = (a*a+b*b+c*c);
866811   b = 1/sqrt(a);
867812   c = a * b;
868   c -= state->m_tgp_vr_base[3];
869   fifoout_push_f(state, c);
870   next_fn(state);
813   c -= m_tgp_vr_base[3];
814   fifoout_push_f(c);
815   next_fn();
871816}
872817
873static TGP_FUNCTION( f47 )
818TGP_FUNCTION( model1_state::f47 )
874819{
875   model1_state *state = machine.driver_data<model1_state>();
876   float a = fifoin_pop_f(state);
877   float b = fifoin_pop_f(state);
878   float c = fifoin_pop_f(state);
879   logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
880   fifoout_push_f(state, a+c);
881   fifoout_push_f(state, b+c);
882   next_fn(state);
820   float a = fifoin_pop_f();
821   float b = fifoin_pop_f();
822   float c = fifoin_pop_f();
823   logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, m_pushpc);
824   fifoout_push_f(a+c);
825   fifoout_push_f(b+c);
826   next_fn();
883827}
884828
885static TGP_FUNCTION( track_read_info )
829TGP_FUNCTION( model1_state::track_read_info )
886830{
887   model1_state *state = machine.driver_data<model1_state>();
888   const UINT32 *tgp_data = (const UINT32 *)state->memregion("user2")->base();
889   UINT16 a = fifoin_pop(state);
831   const UINT32 *tgp_data = (const UINT32 *)memregion("user2")->base();
832   UINT16 a = fifoin_pop();
890833   int offd;
891834
892   logerror("TGP track_read_info %d (%x)\n", a, state->m_pushpc);
835   logerror("TGP track_read_info %d (%x)\n", a, m_pushpc);
893836
894   offd = tgp_data[0x20+state->m_tgp_vr_select] + 16*a;
895   fifoout_push(state, tgp_data[offd+15]);
896   next_fn(state);
837   offd = tgp_data[0x20+m_tgp_vr_select] + 16*a;
838   fifoout_push(tgp_data[offd+15]);
839   next_fn();
897840}
898841
899static TGP_FUNCTION( colbox_set )
842TGP_FUNCTION( model1_state::colbox_set )
900843{
901   model1_state *state = machine.driver_data<model1_state>();
902   float a = fifoin_pop_f(state);
903   float b = fifoin_pop_f(state);
904   float c = fifoin_pop_f(state);
905   float d = fifoin_pop_f(state);
906   float e = fifoin_pop_f(state);
907   float f = fifoin_pop_f(state);
908   float g = fifoin_pop_f(state);
909   float h = fifoin_pop_f(state);
910   float i = fifoin_pop_f(state);
911   float j = fifoin_pop_f(state);
912   float k = fifoin_pop_f(state);
913   float l = fifoin_pop_f(state);
914   logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->m_pushpc);
915   state->m_tgp_vr_cbox[ 0] = a;
916   state->m_tgp_vr_cbox[ 1] = b;
917   state->m_tgp_vr_cbox[ 2] = c;
918   state->m_tgp_vr_cbox[ 3] = d;
919   state->m_tgp_vr_cbox[ 4] = e;
920   state->m_tgp_vr_cbox[ 5] = f;
921   state->m_tgp_vr_cbox[ 6] = g;
922   state->m_tgp_vr_cbox[ 7] = h;
923   state->m_tgp_vr_cbox[ 8] = i;
924   state->m_tgp_vr_cbox[ 9] = j;
925   state->m_tgp_vr_cbox[10] = k;
926   state->m_tgp_vr_cbox[11] = l;
927   next_fn(state);
844   float a = fifoin_pop_f();
845   float b = fifoin_pop_f();
846   float c = fifoin_pop_f();
847   float d = fifoin_pop_f();
848   float e = fifoin_pop_f();
849   float f = fifoin_pop_f();
850   float g = fifoin_pop_f();
851   float h = fifoin_pop_f();
852   float i = fifoin_pop_f();
853   float j = fifoin_pop_f();
854   float k = fifoin_pop_f();
855   float l = fifoin_pop_f();
856   logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m_pushpc);
857   m_tgp_vr_cbox[ 0] = a;
858   m_tgp_vr_cbox[ 1] = b;
859   m_tgp_vr_cbox[ 2] = c;
860   m_tgp_vr_cbox[ 3] = d;
861   m_tgp_vr_cbox[ 4] = e;
862   m_tgp_vr_cbox[ 5] = f;
863   m_tgp_vr_cbox[ 6] = g;
864   m_tgp_vr_cbox[ 7] = h;
865   m_tgp_vr_cbox[ 8] = i;
866   m_tgp_vr_cbox[ 9] = j;
867   m_tgp_vr_cbox[10] = k;
868   m_tgp_vr_cbox[11] = l;
869   next_fn();
928870}
929871
930static TGP_FUNCTION( colbox_test )
872TGP_FUNCTION( model1_state::colbox_test )
931873{
932   model1_state *state = machine.driver_data<model1_state>();
933   float a = fifoin_pop_f(state);
934   float b = fifoin_pop_f(state);
935   float c = fifoin_pop_f(state);
874   float a = fifoin_pop_f();
875   float b = fifoin_pop_f();
876   float c = fifoin_pop_f();
936877   (void)a;
937878   (void)b;
938879   (void)c;
939   logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
880   logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, m_pushpc);
940881
941882   // #### Wrong, need to check with the tgp_vr_cbox coordinates
942883   // Game only test sign, negative = collision
943   fifoout_push_f(state, -1);
944   next_fn(state);
884   fifoout_push_f(-1);
885   next_fn();
945886}
946887
947static TGP_FUNCTION( f49_swa )
888TGP_FUNCTION( model1_state::f49_swa )
948889{
949   model1_state *state = machine.driver_data<model1_state>();
950   float a = fifoin_pop_f(state);
951   float b = fifoin_pop_f(state);
952   float c = fifoin_pop_f(state);
953   float d = fifoin_pop_f(state);
954   float e = fifoin_pop_f(state);
955   float f = fifoin_pop_f(state);
890   float a = fifoin_pop_f();
891   float b = fifoin_pop_f();
892   float c = fifoin_pop_f();
893   float d = fifoin_pop_f();
894   float e = fifoin_pop_f();
895   float f = fifoin_pop_f();
956896   (void)a;
957897   (void)b;
958898   (void)c;
959899   (void)d;
960900   (void)e;
961901   (void)f;
962   logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->m_pushpc);
963   next_fn(state);
902   logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, m_pushpc);
903   next_fn();
964904}
965905
966static TGP_FUNCTION( f50_swa )
906TGP_FUNCTION( model1_state::f50_swa )
967907{
968   model1_state *state = machine.driver_data<model1_state>();
969   float a = fifoin_pop_f(state);
970   float b = fifoin_pop_f(state);
971   float c = fifoin_pop_f(state);
972   float d = fifoin_pop_f(state);
908   float a = fifoin_pop_f();
909   float b = fifoin_pop_f();
910   float c = fifoin_pop_f();
911   float d = fifoin_pop_f();
973912   (void)a;
974913   (void)b;
975914   (void)c;
976915   (void)d;
977   logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, state->m_pushpc);
978   fifoout_push_f(state, d);
979   next_fn(state);
916   logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, m_pushpc);
917   fifoout_push_f(d);
918   next_fn();
980919}
981920
982static TGP_FUNCTION( f52 )
921TGP_FUNCTION( model1_state::f52 )
983922{
984   model1_state *state = machine.driver_data<model1_state>();
985   logerror("TGP f52 (%x)\n", state->m_pushpc);
986   next_fn(state);
923   logerror("TGP f52 (%x)\n", m_pushpc);
924   next_fn();
987925}
988926
989static TGP_FUNCTION( matrix_rdir )
927TGP_FUNCTION( model1_state::matrix_rdir )
990928{
991   model1_state *state = machine.driver_data<model1_state>();
992   float a = fifoin_pop_f(state);
993   float b = fifoin_pop_f(state);
994   float c = fifoin_pop_f(state);
929   float a = fifoin_pop_f();
930   float b = fifoin_pop_f();
931   float c = fifoin_pop_f();
995932   float norm = sqrt(a*a+c*c);
996933   float t1, t2;
997934   (void)b;
998935
999   logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
936   logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, m_pushpc);
1000937
1001938   if(!norm) {
1002939      c = 1;
r32482r32483
1006943      a /= norm;
1007944   }
1008945
1009   t1 = state->m_cmat[6];
1010   t2 = state->m_cmat[0];
1011   state->m_cmat[6] = c*t1-a*t2;
1012   state->m_cmat[0] = a*t1+c*t2;
1013   t1 = state->m_cmat[7];
1014   t2 = state->m_cmat[1];
1015   state->m_cmat[7] = c*t1-a*t2;
1016   state->m_cmat[1] = a*t1+c*t2;
1017   t1 = state->m_cmat[8];
1018   t2 = state->m_cmat[2];
1019   state->m_cmat[8] = c*t1-a*t2;
1020   state->m_cmat[2] = a*t1+c*t2;
1021   next_fn(state);
946   t1 = m_cmat[6];
947   t2 = m_cmat[0];
948   m_cmat[6] = c*t1-a*t2;
949   m_cmat[0] = a*t1+c*t2;
950   t1 = m_cmat[7];
951   t2 = m_cmat[1];
952   m_cmat[7] = c*t1-a*t2;
953   m_cmat[1] = a*t1+c*t2;
954   t1 = m_cmat[8];
955   t2 = m_cmat[2];
956   m_cmat[8] = c*t1-a*t2;
957   m_cmat[2] = a*t1+c*t2;
958   next_fn();
1022959}
1023960
1024961// A+(B-A)*t1 + (C-A)*t2 = P
r32482r32483
1036973   *t2 = (bx*py-by*px)/d;
1037974}
1038975
1039static TGP_FUNCTION( track_lookup )
976TGP_FUNCTION( model1_state::track_lookup )
1040977{
1041   model1_state *state = machine.driver_data<model1_state>();
1042   const UINT32 *tgp_data = (const UINT32 *)state->memregion("user2")->base();
1043   float a = fifoin_pop_f(state);
1044   UINT32 b = fifoin_pop(state);
1045   float c = fifoin_pop_f(state);
1046   float d = fifoin_pop_f(state);
978   const UINT32 *tgp_data = (const UINT32 *)memregion("user2")->base();
979   float a = fifoin_pop_f();
980   UINT32 b = fifoin_pop();
981   float c = fifoin_pop_f();
982   float d = fifoin_pop_f();
1047983   int offi, offd, len;
1048984   float dist;
1049985   int i;
1050986   UINT32 entry;
1051987   float height;
1052988
1053   logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, state->m_pushpc);
989   logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, m_pushpc);
1054990
1055   offi = tgp_data[0x10+state->m_tgp_vr_select] + b;
1056   offd = tgp_data[0x20+state->m_tgp_vr_select];
991   offi = tgp_data[0x10+m_tgp_vr_select] + b;
992   offd = tgp_data[0x20+m_tgp_vr_select];
1057993
1058994   len = tgp_data[offi++];
1059995
r32482r32483
10881024      }
10891025   }
10901026
1091   state->m_ram_data[0x0000] = 0; // non zero = still computing
1092   state->m_ram_data[0x8001] = f2u(height);
1093   state->m_ram_data[0x8002] = entry;
1027   m_ram_data[0x0000] = 0; // non zero = still computing
1028   m_ram_data[0x8001] = f2u(height);
1029   m_ram_data[0x8002] = entry;
10941030
1095   next_fn(state);
1031   next_fn();
10961032}
10971033
1098static TGP_FUNCTION( f56 )
1034TGP_FUNCTION( model1_state::f56 )
10991035{
1100   model1_state *state = machine.driver_data<model1_state>();
1101   float a = fifoin_pop_f(state);
1102   float b = fifoin_pop_f(state);
1103   float c = fifoin_pop_f(state);
1104   float d = fifoin_pop_f(state);
1105   float e = fifoin_pop_f(state);
1106   float f = fifoin_pop_f(state);
1107   UINT32 g = fifoin_pop(state);
1036   float a = fifoin_pop_f();
1037   float b = fifoin_pop_f();
1038   float c = fifoin_pop_f();
1039   float d = fifoin_pop_f();
1040   float e = fifoin_pop_f();
1041   float f = fifoin_pop_f();
1042   UINT32 g = fifoin_pop();
11081043   (void)a;
11091044   (void)b;
11101045   (void)c;
r32482r32483
11131048   (void)f;
11141049   (void)g;
11151050
1116   logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, state->m_pushpc);
1117   fifoout_push(state, 0);
1118   next_fn(state);
1051   logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, m_pushpc);
1052   fifoout_push(0);
1053   next_fn();
11191054}
11201055
1121static TGP_FUNCTION( f57 )
1056TGP_FUNCTION( model1_state::f57 )
11221057{
1123   model1_state *state = machine.driver_data<model1_state>();
1124   logerror("TGP f57 (%x)\n", state->m_pushpc);
1125   fifoout_push_f(state, 0);
1126   fifoout_push_f(state, 0);
1127   fifoout_push_f(state, 0);
1128   next_fn(state);
1058   logerror("TGP f57 (%x)\n", m_pushpc);
1059   fifoout_push_f(0);
1060   fifoout_push_f(0);
1061   fifoout_push_f(0);
1062   next_fn();
11291063}
11301064
1131static TGP_FUNCTION( matrix_readt )
1065TGP_FUNCTION( model1_state::matrix_readt )
11321066{
1133   model1_state *state = machine.driver_data<model1_state>();
1134   logerror("TGP matrix_readt (%x)\n", state->m_pushpc);
1135   fifoout_push_f(state, state->m_cmat[9]);
1136   fifoout_push_f(state, state->m_cmat[10]);
1137   fifoout_push_f(state, state->m_cmat[11]);
1138   next_fn(state);
1067   logerror("TGP matrix_readt (%x)\n", m_pushpc);
1068   fifoout_push_f(m_cmat[9]);
1069   fifoout_push_f(m_cmat[10]);
1070   fifoout_push_f(m_cmat[11]);
1071   next_fn();
11391072}
11401073
1141static TGP_FUNCTION( acc_geti )
1074TGP_FUNCTION( model1_state::acc_geti )
11421075{
1143   model1_state *state = machine.driver_data<model1_state>();
1144   logerror("TGP acc_geti (%x)\n", state->m_pushpc);
1145   fifoout_push(state, (int)state->m_acc);
1146   next_fn(state);
1076   logerror("TGP acc_geti (%x)\n", m_pushpc);
1077   fifoout_push((int)m_acc);
1078   next_fn();
11471079}
11481080
1149static TGP_FUNCTION( f60 )
1081TGP_FUNCTION( model1_state::f60 )
11501082{
1151   model1_state *state = machine.driver_data<model1_state>();
1152   logerror("TGP f60 (%x)\n", state->m_pushpc);
1153   fifoout_push_f(state, 0);
1154   fifoout_push_f(state, 0);
1155   fifoout_push_f(state, 0);
1156   next_fn(state);
1083   logerror("TGP f60 (%x)\n", m_pushpc);
1084   fifoout_push_f(0);
1085   fifoout_push_f(0);
1086   fifoout_push_f(0);
1087   next_fn();
11571088}
11581089
1159static TGP_FUNCTION( col_setcirc )
1090TGP_FUNCTION( model1_state::col_setcirc )
11601091{
1161   model1_state *state = machine.driver_data<model1_state>();
1162   float a = fifoin_pop_f(state);
1163   float b = fifoin_pop_f(state);
1164   float c = fifoin_pop_f(state);
1165   logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
1166   state->m_tgp_vr_circx = a;
1167   state->m_tgp_vr_circy = b;
1168   state->m_tgp_vr_circrad = c;
1169   next_fn(state);
1092   float a = fifoin_pop_f();
1093   float b = fifoin_pop_f();
1094   float c = fifoin_pop_f();
1095   logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, m_pushpc);
1096   m_tgp_vr_circx = a;
1097   m_tgp_vr_circy = b;
1098   m_tgp_vr_circrad = c;
1099   next_fn();
11701100}
11711101
1172static TGP_FUNCTION( col_testpt )
1102TGP_FUNCTION( model1_state::col_testpt )
11731103{
1174   model1_state *state = machine.driver_data<model1_state>();
11751104   float x, y;
1176   float a = fifoin_pop_f(state);
1177   float b = fifoin_pop_f(state);
1178   logerror("TGP col_testpt %f, %f (%x)\n", a, b, state->m_pushpc);
1179   x = a - state->m_tgp_vr_circx;
1180   y = b - state->m_tgp_vr_circy;
1181   fifoout_push_f(state, ((x*x+y*y)/sqrt(x*x+y*y)) - state->m_tgp_vr_circrad);
1182   next_fn(state);
1105   float a = fifoin_pop_f();
1106   float b = fifoin_pop_f();
1107   logerror("TGP col_testpt %f, %f (%x)\n", a, b, m_pushpc);
1108   x = a - m_tgp_vr_circx;
1109   y = b - m_tgp_vr_circy;
1110   fifoout_push_f(((x*x+y*y)/sqrt(x*x+y*y)) - m_tgp_vr_circrad);
1111   next_fn();
11831112}
11841113
1185static TGP_FUNCTION( push_and_ident )
1114TGP_FUNCTION( model1_state::push_and_ident )
11861115{
1187   model1_state *state = machine.driver_data<model1_state>();
1188   if(state->m_mat_stack_pos != MAT_STACK_SIZE) {
1189      memcpy(state->m_mat_stack[state->m_mat_stack_pos], state->m_cmat, sizeof(state->m_cmat));
1190      state->m_mat_stack_pos++;
1116   if(m_mat_stack_pos != MAT_STACK_SIZE) {
1117      memcpy(m_mat_stack[m_mat_stack_pos], m_cmat, sizeof(m_cmat));
1118      m_mat_stack_pos++;
11911119   }
1192   logerror("TGP push_and_ident (depth=%d, pc=%x)\n", state->m_mat_stack_pos, state->m_pushpc);
1193   memset(state->m_cmat, 0, sizeof(state->m_cmat));
1194   state->m_cmat[0] = 1.0;
1195   state->m_cmat[4] = 1.0;
1196   state->m_cmat[8] = 1.0;
1197   next_fn(state);
1120   logerror("TGP push_and_ident (depth=%d, pc=%x)\n", m_mat_stack_pos, m_pushpc);
1121   memset(m_cmat, 0, sizeof(m_cmat));
1122   m_cmat[0] = 1.0;
1123   m_cmat[4] = 1.0;
1124   m_cmat[8] = 1.0;
1125   next_fn();
11981126}
11991127
1200static TGP_FUNCTION( catmull_rom )
1128TGP_FUNCTION( model1_state::catmull_rom )
12011129{
1202   model1_state *state = machine.driver_data<model1_state>();
1203   float a = fifoin_pop_f(state);
1204   float b = fifoin_pop_f(state);
1205   float c = fifoin_pop_f(state);
1206   float d = fifoin_pop_f(state);
1207   float e = fifoin_pop_f(state);
1208   float f = fifoin_pop_f(state);
1209   float g = fifoin_pop_f(state);
1210   float h = fifoin_pop_f(state);
1211   float i = fifoin_pop_f(state);
1212   float j = fifoin_pop_f(state);
1213   float k = fifoin_pop_f(state);
1214   float l = fifoin_pop_f(state);
1215   float m = fifoin_pop_f(state);
1130   float a = fifoin_pop_f();
1131   float b = fifoin_pop_f();
1132   float c = fifoin_pop_f();
1133   float d = fifoin_pop_f();
1134   float e = fifoin_pop_f();
1135   float f = fifoin_pop_f();
1136   float g = fifoin_pop_f();
1137   float h = fifoin_pop_f();
1138   float i = fifoin_pop_f();
1139   float j = fifoin_pop_f();
1140   float k = fifoin_pop_f();
1141   float l = fifoin_pop_f();
1142   float m = fifoin_pop_f();
12161143   float m2, m3;
12171144   float w1, w2, w3, w4;
12181145
1219   logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, state->m_pushpc);
1146   logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, m_pushpc);
12201147
12211148   m2 = m*m;
12221149   m3 = m*m*m;
r32482r32483
12261153   w3 = 0.5*(-3*m3+4*m2+m);
12271154   w4 = 0.5*(m3-m2);
12281155
1229   fifoout_push_f(state, a*w1+d*w2+g*w3+j*w4);
1230   fifoout_push_f(state, b*w1+e*w2+h*w3+k*w4);
1231   fifoout_push_f(state, c*w1+f*w2+i*w3+l*w4);
1232   next_fn(state);
1156   fifoout_push_f(a*w1+d*w2+g*w3+j*w4);
1157   fifoout_push_f(b*w1+e*w2+h*w3+k*w4);
1158   fifoout_push_f(c*w1+f*w2+i*w3+l*w4);
1159   next_fn();
12331160}
12341161
1235static TGP_FUNCTION( distance )
1162TGP_FUNCTION( model1_state::distance )
12361163{
1237   model1_state *state = machine.driver_data<model1_state>();
1238   float a = fifoin_pop_f(state);
1239   float b = fifoin_pop_f(state);
1240   float c = fifoin_pop_f(state);
1241   float d = fifoin_pop_f(state);
1242   logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, state->m_pushpc);
1164   float a = fifoin_pop_f();
1165   float b = fifoin_pop_f();
1166   float c = fifoin_pop_f();
1167   float d = fifoin_pop_f();
1168   logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, m_pushpc);
12431169   c -= a;
12441170   d -= b;
1245   fifoout_push_f(state, (c*c+d*d)/sqrt(c*c+d*d));
1246   next_fn(state);
1171   fifoout_push_f((c*c+d*d)/sqrt(c*c+d*d));
1172   next_fn();
12471173}
12481174
1249static TGP_FUNCTION( car_move )
1175TGP_FUNCTION( model1_state::car_move )
12501176{
1251   model1_state *state = machine.driver_data<model1_state>();
1252   INT16 a = fifoin_pop(state);
1253   float b = fifoin_pop_f(state);
1254   float c = fifoin_pop_f(state);
1255   float d = fifoin_pop_f(state);
1177   INT16 a = fifoin_pop();
1178   float b = fifoin_pop_f();
1179   float c = fifoin_pop_f();
1180   float d = fifoin_pop_f();
12561181   float dx, dy;
1257   logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, state->m_pushpc);
1182   logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, m_pushpc);
12581183
12591184   dx = b*tsin(a);
12601185   dy = b*tcos(a);
12611186
1262   fifoout_push_f(state, dx);
1263   fifoout_push_f(state, dy);
1264   fifoout_push_f(state, c+dx);
1265   fifoout_push_f(state, d+dy);
1266   next_fn(state);
1187   fifoout_push_f(dx);
1188   fifoout_push_f(dy);
1189   fifoout_push_f(c+dx);
1190   fifoout_push_f(d+dy);
1191   next_fn();
12671192}
12681193
1269static TGP_FUNCTION( cpa )
1194TGP_FUNCTION( model1_state::cpa )
12701195{
1271   model1_state *state = machine.driver_data<model1_state>();
12721196   float dv_x, dv_y, dv_z, dv2, dw_x, dw_y, dw_z, dt;
12731197
1274   float a = fifoin_pop_f(state);
1275   float b = fifoin_pop_f(state);
1276   float c = fifoin_pop_f(state);
1277   float d = fifoin_pop_f(state);
1278   float e = fifoin_pop_f(state);
1279   float f = fifoin_pop_f(state);
1280   float g = fifoin_pop_f(state);
1281   float h = fifoin_pop_f(state);
1282   float i = fifoin_pop_f(state);
1283   float j = fifoin_pop_f(state);
1284   float k = fifoin_pop_f(state);
1285   float l = fifoin_pop_f(state);
1286   logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->m_pushpc);
1198   float a = fifoin_pop_f();
1199   float b = fifoin_pop_f();
1200   float c = fifoin_pop_f();
1201   float d = fifoin_pop_f();
1202   float e = fifoin_pop_f();
1203   float f = fifoin_pop_f();
1204   float g = fifoin_pop_f();
1205   float h = fifoin_pop_f();
1206   float i = fifoin_pop_f();
1207   float j = fifoin_pop_f();
1208   float k = fifoin_pop_f();
1209   float l = fifoin_pop_f();
1210   logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m_pushpc);
12871211
12881212   dv_x = (b-a) - (d-c);
12891213   dv_y = (f-e) - (h-g);
r32482r32483
13071231   dv_z = (i-k)*(1-dt) + (j-l)*dt;
13081232   dv2 = dv_x*dv_x + dv_y*dv_y + dv_z*dv_z;
13091233
1310   fifoout_push_f(state, sqrt(dv2));
1311   next_fn(state);
1234   fifoout_push_f(sqrt(dv2));
1235   next_fn();
13121236}
13131237
1314static TGP_FUNCTION( vmat_store )
1238TGP_FUNCTION( model1_state::vmat_store )
13151239{
1316   model1_state *state = machine.driver_data<model1_state>();
1317   UINT32 a = fifoin_pop(state);
1240   UINT32 a = fifoin_pop();
13181241   if(a<21)
1319      memcpy(state->m_mat_vector[a], state->m_cmat, sizeof(state->m_cmat));
1242      memcpy(m_mat_vector[a], m_cmat, sizeof(m_cmat));
13201243   else
13211244      logerror("TGP ERROR bad vector index\n");
1322   logerror("TGP vmat_store %d (%x)\n", a, state->m_pushpc);
1323   next_fn(state);
1245   logerror("TGP vmat_store %d (%x)\n", a, m_pushpc);
1246   next_fn();
13241247}
13251248
1326static TGP_FUNCTION( vmat_restore )
1249TGP_FUNCTION( model1_state::vmat_restore )
13271250{
1328   model1_state *state = machine.driver_data<model1_state>();
1329   UINT32 a = fifoin_pop(state);
1251   UINT32 a = fifoin_pop();
13301252   if(a<21)
1331      memcpy(state->m_cmat, state->m_mat_vector[a], sizeof(state->m_cmat));
1253      memcpy(m_cmat, m_mat_vector[a], sizeof(m_cmat));
13321254   else
13331255      logerror("TGP ERROR bad vector index\n");
1334   logerror("TGP vmat_restore %d (%x)\n", a, state->m_pushpc);
1335   next_fn(state);
1256   logerror("TGP vmat_restore %d (%x)\n", a, m_pushpc);
1257   next_fn();
13361258}
13371259
1338static TGP_FUNCTION( vmat_mul )
1260TGP_FUNCTION( model1_state::vmat_mul )
13391261{
1340   model1_state *state = machine.driver_data<model1_state>();
1341   UINT32 a = fifoin_pop(state);
1342   UINT32 b = fifoin_pop(state);
1262   UINT32 a = fifoin_pop();
1263   UINT32 b = fifoin_pop();
13431264   if(a<21 && b<21) {
1344      state->m_mat_vector[b][0]  = state->m_mat_vector[a][ 0]*state->m_cmat[0] + state->m_mat_vector[a][ 1]*state->m_cmat[3] + state->m_mat_vector[a][ 2]*state->m_cmat[6];
1345      state->m_mat_vector[b][1]  = state->m_mat_vector[a][ 0]*state->m_cmat[1] + state->m_mat_vector[a][ 1]*state->m_cmat[4] + state->m_mat_vector[a][ 2]*state->m_cmat[7];
1346      state->m_mat_vector[b][2]  = state->m_mat_vector[a][ 0]*state->m_cmat[2] + state->m_mat_vector[a][ 1]*state->m_cmat[5] + state->m_mat_vector[a][ 2]*state->m_cmat[8];
1347      state->m_mat_vector[b][3]  = state->m_mat_vector[a][ 3]*state->m_cmat[0] + state->m_mat_vector[a][ 4]*state->m_cmat[3] + state->m_mat_vector[a][ 5]*state->m_cmat[6];
1348      state->m_mat_vector[b][4]  = state->m_mat_vector[a][ 3]*state->m_cmat[1] + state->m_mat_vector[a][ 4]*state->m_cmat[4] + state->m_mat_vector[a][ 5]*state->m_cmat[7];
1349      state->m_mat_vector[b][5]  = state->m_mat_vector[a][ 3]*state->m_cmat[2] + state->m_mat_vector[a][ 4]*state->m_cmat[5] + state->m_mat_vector[a][ 5]*state->m_cmat[8];
1350      state->m_mat_vector[b][6]  = state->m_mat_vector[a][ 6]*state->m_cmat[0] + state->m_mat_vector[a][ 7]*state->m_cmat[3] + state->m_mat_vector[a][ 8]*state->m_cmat[6];
1351      state->m_mat_vector[b][7]  = state->m_mat_vector[a][ 6]*state->m_cmat[1] + state->m_mat_vector[a][ 7]*state->m_cmat[4] + state->m_mat_vector[a][ 8]*state->m_cmat[7];
1352      state->m_mat_vector[b][8]  = state->m_mat_vector[a][ 6]*state->m_cmat[2] + state->m_mat_vector[a][ 7]*state->m_cmat[5] + state->m_mat_vector[a][ 8]*state->m_cmat[8];
1353      state->m_mat_vector[b][9]  = state->m_mat_vector[a][ 9]*state->m_cmat[0] + state->m_mat_vector[a][10]*state->m_cmat[3] + state->m_mat_vector[a][11]*state->m_cmat[6] + state->m_cmat[9];
1354      state->m_mat_vector[b][10] = state->m_mat_vector[a][ 9]*state->m_cmat[1] + state->m_mat_vector[a][10]*state->m_cmat[4] + state->m_mat_vector[a][11]*state->m_cmat[7] + state->m_cmat[10];
1355      state->m_mat_vector[b][11] = state->m_mat_vector[a][ 9]*state->m_cmat[2] + state->m_mat_vector[a][10]*state->m_cmat[5] + state->m_mat_vector[a][11]*state->m_cmat[8] + state->m_cmat[11];
1265      m_mat_vector[b][0]  = m_mat_vector[a][ 0]*m_cmat[0] + m_mat_vector[a][ 1]*m_cmat[3] + m_mat_vector[a][ 2]*m_cmat[6];
1266      m_mat_vector[b][1]  = m_mat_vector[a][ 0]*m_cmat[1] + m_mat_vector[a][ 1]*m_cmat[4] + m_mat_vector[a][ 2]*m_cmat[7];
1267      m_mat_vector[b][2]  = m_mat_vector[a][ 0]*m_cmat[2] + m_mat_vector[a][ 1]*m_cmat[5] + m_mat_vector[a][ 2]*m_cmat[8];
1268      m_mat_vector[b][3]  = m_mat_vector[a][ 3]*m_cmat[0] + m_mat_vector[a][ 4]*m_cmat[3] + m_mat_vector[a][ 5]*m_cmat[6];
1269      m_mat_vector[b][4]  = m_mat_vector[a][ 3]*m_cmat[1] + m_mat_vector[a][ 4]*m_cmat[4] + m_mat_vector[a][ 5]*m_cmat[7];
1270      m_mat_vector[b][5]  = m_mat_vector[a][ 3]*m_cmat[2] + m_mat_vector[a][ 4]*m_cmat[5] + m_mat_vector[a][ 5]*m_cmat[8];
1271      m_mat_vector[b][6]  = m_mat_vector[a][ 6]*m_cmat[0] + m_mat_vector[a][ 7]*m_cmat[3] + m_mat_vector[a][ 8]*m_cmat[6];
1272      m_mat_vector[b][7]  = m_mat_vector[a][ 6]*m_cmat[1] + m_mat_vector[a][ 7]*m_cmat[4] + m_mat_vector[a][ 8]*m_cmat[7];
1273      m_mat_vector[b][8]  = m_mat_vector[a][ 6]*m_cmat[2] + m_mat_vector[a][ 7]*m_cmat[5] + m_mat_vector[a][ 8]*m_cmat[8];
1274      m_mat_vector[b][9]  = m_mat_vector[a][ 9]*m_cmat[0] + m_mat_vector[a][10]*m_cmat[3] + m_mat_vector[a][11]*m_cmat[6] + m_cmat[9];
1275      m_mat_vector[b][10] = m_mat_vector[a][ 9]*m_cmat[1] + m_mat_vector[a][10]*m_cmat[4] + m_mat_vector[a][11]*m_cmat[7] + m_cmat[10];
1276      m_mat_vector[b][11] = m_mat_vector[a][ 9]*m_cmat[2] + m_mat_vector[a][10]*m_cmat[5] + m_mat_vector[a][11]*m_cmat[8] + m_cmat[11];
13561277   } else
13571278      logerror("TGP ERROR bad vector index\n");
1358   logerror("TGP vmat_mul %d, %d (%x)\n", a, b, state->m_pushpc);
1359   next_fn(state);
1279   logerror("TGP vmat_mul %d, %d (%x)\n", a, b, m_pushpc);
1280   next_fn();
13601281}
13611282
1362static TGP_FUNCTION( vmat_read )
1283TGP_FUNCTION( model1_state::vmat_read )
13631284{
1364   model1_state *state = machine.driver_data<model1_state>();
1365   UINT32 a = fifoin_pop(state);
1366   logerror("TGP vmat_read %d (%x)\n", a, state->m_pushpc);
1285   UINT32 a = fifoin_pop();
1286   logerror("TGP vmat_read %d (%x)\n", a, m_pushpc);
13671287   if(a<21) {
13681288      int i;
13691289      for(i=0; i<12; i++)
1370         fifoout_push_f(state, state->m_mat_vector[a][i]);
1290         fifoout_push_f(m_mat_vector[a][i]);
13711291   } else {
13721292      int i;
13731293      logerror("TGP ERROR bad vector index\n");
13741294      for(i=0; i<12; i++)
1375         fifoout_push_f(state, 0);
1295         fifoout_push_f(0);
13761296   }
1377   next_fn(state);
1297   next_fn();
13781298}
13791299
1380static TGP_FUNCTION( matrix_rtrans )
1300TGP_FUNCTION( model1_state::matrix_rtrans )
13811301{
1382   model1_state *state = machine.driver_data<model1_state>();
1383   logerror("TGP matrix_rtrans (%x)\n", state->m_pushpc);
1384   fifoout_push_f(state, state->m_cmat[ 9]);
1385   fifoout_push_f(state, state->m_cmat[10]);
1386   fifoout_push_f(state, state->m_cmat[11]);
1387   next_fn(state);
1302   logerror("TGP matrix_rtrans (%x)\n", m_pushpc);
1303   fifoout_push_f(m_cmat[ 9]);
1304   fifoout_push_f(m_cmat[10]);
1305   fifoout_push_f(m_cmat[11]);
1306   next_fn();
13881307}
13891308
1390static TGP_FUNCTION( matrix_unrot )
1309TGP_FUNCTION( model1_state::matrix_unrot )
13911310{
1392   model1_state *state = machine.driver_data<model1_state>();
1393   logerror("TGP matrix_unrot (%x)\n", state->m_pushpc);
1394   memset(state->m_cmat, 0, 9*sizeof(state->m_cmat[0]));
1395   state->m_cmat[0] = 1.0;
1396   state->m_cmat[4] = 1.0;
1397   state->m_cmat[8] = 1.0;
1398   next_fn(state);
1311   logerror("TGP matrix_unrot (%x)\n", m_pushpc);
1312   memset(m_cmat, 0, 9*sizeof(m_cmat[0]));
1313   m_cmat[0] = 1.0;
1314   m_cmat[4] = 1.0;
1315   m_cmat[8] = 1.0;
1316   next_fn();
13991317}
14001318
1401static TGP_FUNCTION( f80 )
1319TGP_FUNCTION( model1_state::f80 )
14021320{
1403   model1_state *state = machine.driver_data<model1_state>();
1404   logerror("TGP f80 (%x)\n", state->m_pushpc);
1405   //  state->m_cmat[9] = state->m_cmat[10] = state->m_cmat[11] = 0;
1406   next_fn(state);
1321   logerror("TGP f80 (%x)\n", m_pushpc);
1322   //  m_cmat[9] = m_cmat[10] = m_cmat[11] = 0;
1323   next_fn();
14071324}
14081325
1409static TGP_FUNCTION( vmat_save )
1326TGP_FUNCTION( model1_state::vmat_save )
14101327{
1411   model1_state *state = machine.driver_data<model1_state>();
1412   UINT32 a = fifoin_pop(state);
1328   UINT32 a = fifoin_pop();
14131329   int i;
1414   logerror("TGP vmat_save 0x%x (%x)\n", a, state->m_pushpc);
1330   logerror("TGP vmat_save 0x%x (%x)\n", a, m_pushpc);
14151331   for(i=0; i<16; i++)
1416      memcpy(state->m_ram_data+a+0x10*i, state->m_mat_vector[i], sizeof(state->m_cmat));
1417   next_fn(state);
1332      memcpy(m_ram_data+a+0x10*i, m_mat_vector[i], sizeof(m_cmat));
1333   next_fn();
14181334}
14191335
1420static TGP_FUNCTION( vmat_load )
1336TGP_FUNCTION( model1_state::vmat_load )
14211337{
1422   model1_state *state = machine.driver_data<model1_state>();
1423   UINT32 a = fifoin_pop(state);
1338   UINT32 a = fifoin_pop();
14241339   int i;
1425   logerror("TGP vmat_load 0x%x (%x)\n", a, state->m_pushpc);
1340   logerror("TGP vmat_load 0x%x (%x)\n", a, m_pushpc);
14261341   for(i=0; i<16; i++)
1427      memcpy(state->m_mat_vector[i], state->m_ram_data+a+0x10*i, sizeof(state->m_cmat));
1428   next_fn(state);
1342      memcpy(m_mat_vector[i], m_ram_data+a+0x10*i, sizeof(m_cmat));
1343   next_fn();
14291344}
14301345
1431static TGP_FUNCTION( ram_setadr )
1346TGP_FUNCTION( model1_state::ram_setadr )
14321347{
1433   model1_state *state = machine.driver_data<model1_state>();
1434   state->m_ram_scanadr = fifoin_pop(state) - 0x8000;
1435   logerror("TGP f0 ram_setadr 0x%x (%x)\n", state->m_ram_scanadr+0x8000, state->m_pushpc);
1436   next_fn(state);
1348   m_ram_scanadr = fifoin_pop() - 0x8000;
1349   logerror("TGP f0 ram_setadr 0x%x (%x)\n", m_ram_scanadr+0x8000, m_pushpc);
1350   next_fn();
14371351}
14381352
1439static TGP_FUNCTION( groundbox_test )
1353TGP_FUNCTION( model1_state::groundbox_test )
14401354{
1441   model1_state *state = machine.driver_data<model1_state>();
14421355   int out_x, out_y, out_z;
14431356   float x, /*y,*/ z;
1444   float a = fifoin_pop_f(state);
1445   float b = fifoin_pop_f(state);
1446   float c = fifoin_pop_f(state);
1357   float a = fifoin_pop_f();
1358   float b = fifoin_pop_f();
1359   float c = fifoin_pop_f();
14471360
1448   logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, state->m_pushpc);
1449   x = state->m_cmat[0]*a+state->m_cmat[3]*b+state->m_cmat[6]*c+state->m_cmat[9];
1450   //y = state->m_cmat[1]*a+state->m_cmat[4]*b+state->m_cmat[7]*c+state->m_cmat[10];
1451   z = state->m_cmat[2]*a+state->m_cmat[5]*b+state->m_cmat[8]*c+state->m_cmat[11];
1361   logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, m_pushpc);
1362   x = m_cmat[0]*a+m_cmat[3]*b+m_cmat[6]*c+m_cmat[9];
1363   //y = m_cmat[1]*a+m_cmat[4]*b+m_cmat[7]*c+m_cmat[10];
1364   z = m_cmat[2]*a+m_cmat[5]*b+m_cmat[8]*c+m_cmat[11];
14521365
1453   out_x = x < state->m_tgp_vf_xmin || x > state->m_tgp_vf_xmax;
1454   out_z = z < state->m_tgp_vf_zmin || z > state->m_tgp_vf_zmax;
1366   out_x = x < m_tgp_vf_xmin || x > m_tgp_vf_xmax;
1367   out_z = z < m_tgp_vf_zmin || z > m_tgp_vf_zmax;
14551368   out_y = 1; // Wrong, but untestable it seems.
14561369
1457   fifoout_push(state, out_x);
1458   fifoout_push(state, out_y);
1459   fifoout_push(state, out_z);
1460   next_fn(state);
1370   fifoout_push(out_x);
1371   fifoout_push(out_y);
1372   fifoout_push(out_z);
1373   next_fn();
14611374}
14621375
1463static TGP_FUNCTION( f89 )
1376TGP_FUNCTION( model1_state::f89 )
14641377{
1465   model1_state *state = machine.driver_data<model1_state>();
1466   UINT32 a = fifoin_pop(state);
1467   UINT32 b = fifoin_pop(state);
1468   UINT32 c = fifoin_pop(state);
1469   UINT32 d = fifoin_pop(state);
1378   UINT32 a = fifoin_pop();
1379   UINT32 b = fifoin_pop();
1380   UINT32 c = fifoin_pop();
1381   UINT32 d = fifoin_pop();
14701382   (void)a;
14711383   (void)b;
14721384   (void)c;
1473   logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, state->m_pushpc);
1474   state->m_list_length = d;
1475   next_fn(state);
1385   logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, m_pushpc);
1386   m_list_length = d;
1387   next_fn();
14761388}
14771389
1478static TGP_FUNCTION( f92 )
1390TGP_FUNCTION( model1_state::f92 )
14791391{
1480   model1_state *state = machine.driver_data<model1_state>();
1481   float a = fifoin_pop_f(state);
1482   float b = fifoin_pop_f(state);
1483   float c = fifoin_pop_f(state);
1484   float d = fifoin_pop_f(state);
1392   float a = fifoin_pop_f();
1393   float b = fifoin_pop_f();
1394   float c = fifoin_pop_f();
1395   float d = fifoin_pop_f();
14851396   (void)a;
14861397   (void)b;
14871398   (void)c;
14881399   (void)d;
1489   logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, state->m_pushpc);
1490   next_fn(state);
1400   logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, m_pushpc);
1401   next_fn();
14911402}
14921403
1493static TGP_FUNCTION( f93 )
1404TGP_FUNCTION( model1_state::f93 )
14941405{
1495   model1_state *state = machine.driver_data<model1_state>();
1496   float a = fifoin_pop_f(state);
1406   float a = fifoin_pop_f();
14971407   (void)a;
1498   logerror("TGP f93 %f (%x)\n", a, state->m_pushpc);
1499   next_fn(state);
1408   logerror("TGP f93 %f (%x)\n", a, m_pushpc);
1409   next_fn();
15001410}
15011411
1502static TGP_FUNCTION( f94 )
1412TGP_FUNCTION( model1_state::f94 )
15031413{
1504   model1_state *state = machine.driver_data<model1_state>();
1505   UINT32 a = fifoin_pop(state);
1414   UINT32 a = fifoin_pop();
15061415   (void)a;
1507   logerror("TGP f94 %d (%x)\n", a, state->m_pushpc);
1508   next_fn(state);
1416   logerror("TGP f94 %d (%x)\n", a, m_pushpc);
1417   next_fn();
15091418}
15101419
1511static TGP_FUNCTION( vmat_flatten )
1420TGP_FUNCTION( model1_state::vmat_flatten )
15121421{
1513   model1_state *state = machine.driver_data<model1_state>();
15141422   int i;
15151423   float m[12];
1516   logerror("TGP vmat_flatten (%x)\n", state->m_pushpc);
1424   logerror("TGP vmat_flatten (%x)\n", m_pushpc);
15171425
15181426   for(i=0; i<16; i++) {
1519      memcpy(m, state->m_mat_vector[i], sizeof(state->m_cmat));
1427      memcpy(m, m_mat_vector[i], sizeof(m_cmat));
15201428      m[1] = m[4] = m[7] = m[10] = 0;
15211429
1522      state->m_mat_vector[i][0]  = m[ 0]*state->m_cmat[0] + m[ 1]*state->m_cmat[3] + m[ 2]*state->m_cmat[6];
1523      state->m_mat_vector[i][1]  = m[ 0]*state->m_cmat[1] + m[ 1]*state->m_cmat[4] + m[ 2]*state->m_cmat[7];
1524      state->m_mat_vector[i][2]  = m[ 0]*state->m_cmat[2] + m[ 1]*state->m_cmat[5] + m[ 2]*state->m_cmat[8];
1525      state->m_mat_vector[i][3]  = m[ 3]*state->m_cmat[0] + m[ 4]*state->m_cmat[3] + m[ 5]*state->m_cmat[6];
1526      state->m_mat_vector[i][4]  = m[ 3]*state->m_cmat[1] + m[ 4]*state->m_cmat[4] + m[ 5]*state->m_cmat[7];
1527      state->m_mat_vector[i][5]  = m[ 3]*state->m_cmat[2] + m[ 4]*state->m_cmat[5] + m[ 5]*state->m_cmat[8];
1528      state->m_mat_vector[i][6]  = m[ 6]*state->m_cmat[0] + m[ 7]*state->m_cmat[3] + m[ 8]*state->m_cmat[6];
1529      state->m_mat_vector[i][7]  = m[ 6]*state->m_cmat[1] + m[ 7]*state->m_cmat[4] + m[ 8]*state->m_cmat[7];
1530      state->m_mat_vector[i][8]  = m[ 6]*state->m_cmat[2] + m[ 7]*state->m_cmat[5] + m[ 8]*state->m_cmat[8];
1531      state->m_mat_vector[i][9]  = m[ 9]*state->m_cmat[0] + m[10]*state->m_cmat[3] + m[11]*state->m_cmat[6] + state->m_cmat[9];
1532      state->m_mat_vector[i][10] = m[ 9]*state->m_cmat[1] + m[10]*state->m_cmat[4] + m[11]*state->m_cmat[7] + state->m_cmat[10];
1533      state->m_mat_vector[i][11] = m[ 9]*state->m_cmat[2] + m[10]*state->m_cmat[5] + m[11]*state->m_cmat[8] + state->m_cmat[11];
1430      m_mat_vector[i][0]  = m[ 0]*m_cmat[0] + m[ 1]*m_cmat[3] + m[ 2]*m_cmat[6];
1431      m_mat_vector[i][1]  = m[ 0]*m_cmat[1] + m[ 1]*m_cmat[4] + m[ 2]*m_cmat[7];
1432      m_mat_vector[i][2]  = m[ 0]*m_cmat[2] + m[ 1]*m_cmat[5] + m[ 2]*m_cmat[8];
1433      m_mat_vector[i][3]  = m[ 3]*m_cmat[0] + m[ 4]*m_cmat[3] + m[ 5]*m_cmat[6];
1434      m_mat_vector[i][4]  = m[ 3]*m_cmat[1] + m[ 4]*m_cmat[4] + m[ 5]*m_cmat[7];
1435      m_mat_vector[i][5]  = m[ 3]*m_cmat[2] + m[ 4]*m_cmat[5] + m[ 5]*m_cmat[8];
1436      m_mat_vector[i][6]  = m[ 6]*m_cmat[0] + m[ 7]*m_cmat[3] + m[ 8]*m_cmat[6];
1437      m_mat_vector[i][7]  = m[ 6]*m_cmat[1] + m[ 7]*m_cmat[4] + m[ 8]*m_cmat[7];
1438      m_mat_vector[i][8]  = m[ 6]*m_cmat[2] + m[ 7]*m_cmat[5] + m[ 8]*m_cmat[8];
1439      m_mat_vector[i][9]  = m[ 9]*m_cmat[0] + m[10]*m_cmat[3] + m[11]*m_cmat[6] + m_cmat[9];
1440      m_mat_vector[i][10] = m[ 9]*m_cmat[1] + m[10]*m_cmat[4] + m[11]*m_cmat[7] + m_cmat[10];
1441      m_mat_vector[i][11] = m[ 9]*m_cmat[2] + m[10]*m_cmat[5] + m[11]*m_cmat[8] + m_cmat[11];
15341442   }
1535   next_fn(state);
1443   next_fn();
15361444}
15371445
1538static TGP_FUNCTION( vmat_load1 )
1446TGP_FUNCTION( model1_state::vmat_load1 )
15391447{
1540   model1_state *state = machine.driver_data<model1_state>();
1541   UINT32 a = fifoin_pop(state);
1542   logerror("TGP vmat_load1 0x%x (%x)\n", a, state->m_pushpc);
1543   memcpy(state->m_cmat, state->m_ram_data+a, sizeof(state->m_cmat));
1544   next_fn(state);
1448   UINT32 a = fifoin_pop();
1449   logerror("TGP vmat_load1 0x%x (%x)\n", a, m_pushpc);
1450   memcpy(m_cmat, m_ram_data+a, sizeof(m_cmat));
1451   next_fn();
15451452}
15461453
1547static TGP_FUNCTION( ram_trans )
1454TGP_FUNCTION( model1_state::ram_trans )
15481455{
1549   model1_state *state = machine.driver_data<model1_state>();
1550   float a = ram_get_f(state);
1551   float b = ram_get_f(state);
1552   float c = ram_get_f(state);
1553   logerror("TGP ram_trans (%x)\n", state->m_pushpc);
1554   state->m_cmat[ 9] += state->m_cmat[0]*a+state->m_cmat[3]*b+state->m_cmat[6]*c;
1555   state->m_cmat[10] += state->m_cmat[1]*a+state->m_cmat[4]*b+state->m_cmat[7]*c;
1556   state->m_cmat[11] += state->m_cmat[2]*a+state->m_cmat[5]*b+state->m_cmat[8]*c;
1557   next_fn(state);
1456   float a = ram_get_f();
1457   float b = ram_get_f();
1458   float c = ram_get_f();
1459   logerror("TGP ram_trans (%x)\n", m_pushpc);
1460   m_cmat[ 9] += m_cmat[0]*a+m_cmat[3]*b+m_cmat[6]*c;
1461   m_cmat[10] += m_cmat[1]*a+m_cmat[4]*b+m_cmat[7]*c;
1462   m_cmat[11] += m_cmat[2]*a+m_cmat[5]*b+m_cmat[8]*c;
1463   next_fn();
15581464}
15591465
1560static TGP_FUNCTION( f98_load )
1466TGP_FUNCTION( model1_state::f98_load )
15611467{
1562   model1_state *state = machine.driver_data<model1_state>();
15631468   int i;
1564   for(i=0; i<state->m_list_length; i++) {
1565      float f = fifoin_pop_f(state);
1469   for(i=0; i<m_list_length; i++) {
1470      float f = fifoin_pop_f();
15661471      (void)f;
1567      logerror("TGP load list (%2d/%2d) %f (%x)\n", i, state->m_list_length, f, state->m_pushpc);
1472      logerror("TGP load list (%2d/%2d) %f (%x)\n", i, m_list_length, f, m_pushpc);
15681473   }
1569   next_fn(state);
1474   next_fn();
15701475}
15711476
1572static TGP_FUNCTION( f98 )
1477TGP_FUNCTION( model1_state::f98 )
15731478{
1574   model1_state *state = machine.driver_data<model1_state>();
1575   UINT32 a = fifoin_pop(state);
1479   UINT32 a = fifoin_pop();
15761480   (void)a;
1577   logerror("TGP load list start %d (%x)\n", a, state->m_pushpc);
1578   state->m_fifoin_cbcount = state->m_list_length;
1579   state->m_fifoin_cb = f98_load;
1481   logerror("TGP load list start %d (%x)\n", a, m_pushpc);
1482   m_fifoin_cbcount = m_list_length;
1483   m_fifoin_cb = &model1_state::f98_load;
15801484}
15811485
1582static TGP_FUNCTION( f99 )
1486TGP_FUNCTION( model1_state::f99 )
15831487{
1584   model1_state *state = machine.driver_data<model1_state>();
1585   logerror("TGP f99 (%x)\n", state->m_pushpc);
1586   next_fn(state);
1488   logerror("TGP f99 (%x)\n", m_pushpc);
1489   next_fn();
15871490}
15881491
1589static TGP_FUNCTION( f100 )
1492TGP_FUNCTION( model1_state::f100 )
15901493{
1591   model1_state *state = machine.driver_data<model1_state>();
15921494   int i;
1593   logerror("TGP f100 get list (%x)\n", state->m_pushpc);
1594   for(i=0; i<state->m_list_length; i++)
1595      fifoout_push_f(state, (machine.rand() % 1000)/100.0);
1596   next_fn(state);
1495   logerror("TGP f100 get list (%x)\n", m_pushpc);
1496   for(i=0; i<m_list_length; i++)
1497      fifoout_push_f((machine().rand() % 1000)/100.0);
1498   next_fn();
15971499}
15981500
1599static TGP_FUNCTION( groundbox_set )
1501TGP_FUNCTION( model1_state::groundbox_set )
16001502{
1601   model1_state *state = machine.driver_data<model1_state>();
1602   float a = fifoin_pop_f(state);
1603   float b = fifoin_pop_f(state);
1604   float c = fifoin_pop_f(state);
1605   float d = fifoin_pop_f(state);
1606   float e = fifoin_pop_f(state);
1607   float f = fifoin_pop_f(state);
1608   float g = fifoin_pop_f(state);
1609   logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, state->m_pushpc);
1610   state->m_tgp_vf_xmin = e;
1611   state->m_tgp_vf_xmax = d;
1612   state->m_tgp_vf_zmin = g;
1613   state->m_tgp_vf_zmax = f;
1614   state->m_tgp_vf_ygnd = b;
1615   state->m_tgp_vf_yflr = a;
1616   state->m_tgp_vf_yjmp = c;
1503   float a = fifoin_pop_f();
1504   float b = fifoin_pop_f();
1505   float c = fifoin_pop_f();
1506   float d = fifoin_pop_f();
1507   float e = fifoin_pop_f();
1508   float f = fifoin_pop_f();
1509   float g = fifoin_pop_f();
1510   logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, m_pushpc);
1511   m_tgp_vf_xmin = e;
1512   m_tgp_vf_xmax = d;
1513   m_tgp_vf_zmin = g;
1514   m_tgp_vf_zmax = f;
1515   m_tgp_vf_ygnd = b;
1516   m_tgp_vf_yflr = a;
1517   m_tgp_vf_yjmp = c;
16171518
1618   next_fn(state);
1519   next_fn();
16191520}
16201521
1621static TGP_FUNCTION( f102 )
1522TGP_FUNCTION( model1_state::f102 )
16221523{
1623   model1_state *state = machine.driver_data<model1_state>();
16241524   float px, py, pz;
1625   float a = fifoin_pop_f(state);
1626   float b = fifoin_pop_f(state);
1627   float c = fifoin_pop_f(state);
1628   float d = fifoin_pop_f(state);
1629   float e = fifoin_pop_f(state);
1630   UINT32 f = fifoin_pop(state);
1631   UINT32 g = fifoin_pop(state);
1632   UINT32 h = fifoin_pop(state);
1525   float a = fifoin_pop_f();
1526   float b = fifoin_pop_f();
1527   float c = fifoin_pop_f();
1528   float d = fifoin_pop_f();
1529   float e = fifoin_pop_f();
1530   UINT32 f = fifoin_pop();
1531   UINT32 g = fifoin_pop();
1532   UINT32 h = fifoin_pop();
16331533
1634   state->m_ccount++;
1534   m_ccount++;
16351535
1636   logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, state->m_ccount, state->m_pushpc);
1536   logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, m_ccount, m_pushpc);
16371537
1638   px = u2f(state->m_ram_data[state->m_ram_scanadr+0x16]);
1639   py = u2f(state->m_ram_data[state->m_ram_scanadr+0x17]);
1640   pz = u2f(state->m_ram_data[state->m_ram_scanadr+0x18]);
1538   px = u2f(m_ram_data[m_ram_scanadr+0x16]);
1539   py = u2f(m_ram_data[m_ram_scanadr+0x17]);
1540   pz = u2f(m_ram_data[m_ram_scanadr+0x18]);
16411541
1642   //  memset(state->m_cmat, 0, sizeof(state->m_cmat));
1643   //  state->m_cmat[0] = 1.0;
1644   //  state->m_cmat[4] = 1.0;
1645   //  state->m_cmat[8] = 1.0;
1542   //  memset(m_cmat, 0, sizeof(m_cmat));
1543   //  m_cmat[0] = 1.0;
1544   //  m_cmat[4] = 1.0;
1545   //  m_cmat[8] = 1.0;
16461546
16471547   px = c;
16481548   py = d;
16491549   pz = e;
16501550
16511551#if 1
1652   state->m_cmat[ 9] += state->m_cmat[0]*a+state->m_cmat[3]*b+state->m_cmat[6]*c;
1653   state->m_cmat[10] += state->m_cmat[1]*a+state->m_cmat[4]*b+state->m_cmat[7]*c;
1654   state->m_cmat[11] += state->m_cmat[2]*a+state->m_cmat[5]*b+state->m_cmat[8]*c;
1552   m_cmat[ 9] += m_cmat[0]*a+m_cmat[3]*b+m_cmat[6]*c;
1553   m_cmat[10] += m_cmat[1]*a+m_cmat[4]*b+m_cmat[7]*c;
1554   m_cmat[11] += m_cmat[2]*a+m_cmat[5]*b+m_cmat[8]*c;
16551555#else
1656   state->m_cmat[ 9] += px;
1657   state->m_cmat[10] += py;
1658   state->m_cmat[11] += pz;
1556   m_cmat[ 9] += px;
1557   m_cmat[10] += py;
1558   m_cmat[11] += pz;
16591559#endif
16601560
16611561   logerror("    f0 mve_calc %f, %f, %f\n", px, py, pz);
16621562
1663   fifoout_push_f(state, c);
1664   fifoout_push_f(state, d);
1665   fifoout_push_f(state, e);
1666   fifoout_push(state, f);
1667   fifoout_push(state, g);
1668   fifoout_push(state, h);
1563   fifoout_push_f(c);
1564   fifoout_push_f(d);
1565   fifoout_push_f(e);
1566   fifoout_push(f);
1567   fifoout_push(g);
1568   fifoout_push(h);
16691569
16701570
1671   next_fn(state);
1571   next_fn();
16721572}
16731573
1674static TGP_FUNCTION( f103 )
1574TGP_FUNCTION( model1_state::f103 )
16751575{
1676   model1_state *state = machine.driver_data<model1_state>();
1677   state->m_ram_scanadr = fifoin_pop(state) - 0x8000;
1678   logerror("TGP f0 mve_setadr 0x%x (%x)\n", state->m_ram_scanadr, state->m_pushpc);
1679   ram_get_i(state);
1680   next_fn(state);
1576   m_ram_scanadr = fifoin_pop() - 0x8000;
1577   logerror("TGP f0 mve_setadr 0x%x (%x)\n", m_ram_scanadr, m_pushpc);
1578   ram_get_i();
1579   next_fn();
16811580}
16821581
1683struct function {
1684   tgp_func cb;
1685   int count;
1686};
1582const struct model1_state::function model1_state::ftab_vf[] = {
1583   { &model1_state::fadd,            2 }, /* 0x00 */
1584   { &model1_state::fsub,            2 },
1585   { &model1_state::fmul,            2 },
1586   { &model1_state::fdiv,            2 },
1587   { NULL,                          0 },
1588   { &model1_state::matrix_push,     0 },
1589   { &model1_state::matrix_pop,      0 },
1590   { &model1_state::matrix_write,   12 },
1591   { &model1_state::clear_stack,     0 },
1592   { NULL,                         0 },
1593   { &model1_state::anglev,          2 },
1594   { NULL,                         0 },
1595   { NULL,                         0 },
1596   { &model1_state::track_select,    1 },
1597   { &model1_state::f14,             4 },
1598   { &model1_state::anglep,          4 },
16871599
1688static const struct function ftab_vf[] = {
1689   { fadd,            2 }, /* 0x00 */
1690   { fsub,            2 },
1691   { fmul,            2 },
1692   { fdiv,            2 },
1693   { NULL,            0 },
1694   { matrix_push,     0 },
1695   { matrix_pop,      0 },
1696   { matrix_write,   12 },
1697   { clear_stack,     0 },
1698   { NULL,            0 },
1699   { anglev,          2 },
1700   { NULL,            0 },
1701   { NULL,            0 },
1702   { track_select,    1 },
1703   { f14,             4 },
1704   { anglep,          4 },
1600   { &model1_state::matrix_ident,    0 },  /* 0x10 */
1601   { &model1_state::matrix_read,     0 },
1602   { &model1_state::matrix_trans,    3 },
1603   { &model1_state::matrix_scale,    3 },
1604   { &model1_state::matrix_rotx,     1 },
1605   { &model1_state::matrix_roty,     1 },
1606   { &model1_state::matrix_rotz,     1 },
1607   { NULL,                         0 },
1608   { &model1_state::track_read_quad, 1 },
1609   { NULL,                         0 },
1610   { &model1_state::transform_point, 3 },
1611   { &model1_state::fsin_m1,         1 },
1612   { &model1_state::fcos_m1,         1 },
1613   { &model1_state::fsinm_m1,        2 },
1614   { &model1_state::fcosm_m1,        2 },
1615   { &model1_state::distance3,       6 },
17051616
1706   { matrix_ident,    0 },  /* 0x10 */
1707   { matrix_read,     0 },
1708   { matrix_trans,    3 },
1709   { matrix_scale,    3 },
1710   { matrix_rotx,     1 },
1711   { matrix_roty,     1 },
1712   { matrix_rotz,     1 },
1713   { NULL,            0 },
1714   { track_read_quad, 1 },
1715   { NULL,            0 },
1716   { transform_point, 3 },
1717   { fsin_m1,         1 },
1718   { fcos_m1,         1 },
1719   { fsinm_m1,        2 },
1720   { fcosm_m1,        2 },
1721   { distance3,       6 },
1617   { NULL,                         0 },  /* 0x20 */
1618   { NULL,                         0 },
1619   { NULL,                         0 },
1620   { NULL,                         0 },
1621   { &model1_state::acc_set,         1 },
1622   { &model1_state::acc_get,         0 },
1623   { &model1_state::acc_add,         1 },
1624   { &model1_state::acc_sub,         1 },
1625   { &model1_state::acc_mul,         1 },
1626   { &model1_state::acc_div,         1 }, // not used ?
1627   { &model1_state::f42,             3 },
1628   { &model1_state::f43,             6 },
1629   { &model1_state::f44,             1 },
1630   { &model1_state::f45,             1 },
1631   { &model1_state::vlength,         3 },
1632   { NULL,                     0 },
17221633
1723   { NULL,            0 },  /* 0x20 */
1724   { NULL,            0 },
1725   { NULL,            0 },
1726   { NULL,            0 },
1727   { acc_set,         1 },
1728   { acc_get,         0 },
1729   { acc_add,         1 },
1730   { acc_sub,         1 },
1731   { acc_mul,         1 },
1732   { acc_div,         1 }, // not used ?
1733   { f42,             3 },
1734   { f43,             6 },
1735   { f44,             1 },
1736   { f45,             1 },
1737   { vlength,         3 },
1738   { NULL, 0 },
1634   { &model1_state::track_read_info, 1 },  /* 0x30 */
1635   { &model1_state::colbox_set,     12 },
1636   { &model1_state::colbox_test,     3 },
1637   { NULL,                         0 },
1638   { NULL,                         0 },
1639   { NULL,                         0 },
1640   { &model1_state::track_lookup,    4 },
1641   { NULL,                         0 },
1642   { NULL,                         0 },
1643   { NULL,                         0 },
1644   { NULL,                         0 },
1645   { NULL,                         0 },
1646   { NULL,                         0 },
1647   { NULL,                         0 },
1648   { NULL,                         0 },
1649   { NULL,                         0 },
17391650
1740   { track_read_info, 1 },  /* 0x30 */
1741   { colbox_set,     12 },
1742   { colbox_test,     3 },
1743   { NULL,            0 },
1744   { NULL,            0 },
1745   { NULL,            0 },
1746   { track_lookup,    4 },
1747   { NULL,            0 },
1748   { NULL,            0 },
1749   { NULL,            0 },
1750   { NULL,            0 },
1751   { NULL,            0 },
1752   { NULL,            0 },
1753   { NULL,            0 },
1754   { NULL,            0 },
1755   { NULL,            0 },
1651   { &model1_state::col_setcirc,     3 },  /* 0x40 */
1652   { &model1_state::col_testpt,      2 },
1653   { NULL,                         0 },
1654   { &model1_state::distance,        4 },
1655   { NULL,                         0 },
1656   { NULL,                         0 },
1657   { NULL,                         0 },
1658   { &model1_state::car_move,        4 },
1659   { &model1_state::cpa,            12 },
1660   { NULL,                         0 },
1661   { &model1_state::vmat_store,      1 },
1662   { &model1_state::vmat_restore,    1 },
1663   { NULL,                         0 },
1664   { &model1_state::vmat_mul,        2 },
1665   { &model1_state::vmat_read,       1 },
1666   { &model1_state::matrix_unrot,    0 },
17561667
1757   { col_setcirc,     3 },  /* 0x40 */
1758   { col_testpt,      2 },
1759   { NULL,            0 },
1760   { distance,        4 },
1761   { NULL,            0 },
1762   { NULL,            0 },
1763   { NULL,            0 },
1764   { car_move,        4 },
1765   { cpa,            12 },
1766   { NULL,            0 },
1767   { vmat_store,      1 },
1768   { vmat_restore,    1 },
1769   { NULL,            0 },
1770   { vmat_mul,        2 },
1771   { vmat_read,       1 },
1772   { matrix_unrot,    0 },
1668   { &model1_state::f80,             0 },  /* 0x50 */
1669   { NULL,                         0 },
1670   { &model1_state::matrix_rtrans,   0 },
1671   { NULL,                         0 },
1672   { &model1_state::vmat_save,       1 },
1673   { &model1_state::vmat_load,       1 },
1674   { &model1_state::ram_setadr,      1 },
1675   { &model1_state::groundbox_test,  3 },
1676   { NULL,                             0 },
1677   { &model1_state::f89,             4 },
1678   { NULL,                         0 },
1679   { NULL,                         0 },
1680   { &model1_state::f92,             4 },
1681   { &model1_state::f93,             1 },
1682   { &model1_state::f94,             1 },
1683   { &model1_state::vmat_flatten,    0 },
17731684
1774   { f80,             0 },  /* 0x50 */
1775   { NULL,            0 },
1776   { matrix_rtrans,   0 },
1777   { NULL,            0 },
1778   { vmat_save,       1 },
1779   { vmat_load,       1 },
1780   { ram_setadr,      1 },
1781   { groundbox_test,  3 },
1782   { NULL,            0 },
1783   { f89,             4 },
1784   { NULL,            0 },
1785   { NULL,            0 },
1786   { f92,             4 },
1787   { f93,             1 },
1788   { f94,             1 },
1789   { vmat_flatten,    0 },
1790
1791   { vmat_load1,      1 },  /* 0x60 */
1792   { ram_trans,       0 },
1793   { f98,             1 },
1794   { f99,             0 },
1795   { f100,            0 },
1796   { groundbox_set,   7 },
1797   { f102,            8 },
1798   { f103,            1 }
1685   { &model1_state::vmat_load1,      1 },  /* 0x60 */
1686   { &model1_state::ram_trans,       0 },
1687   { &model1_state::f98,             1 },
1688   { &model1_state::f99,             0 },
1689   { &model1_state::f100,            0 },
1690   { &model1_state::groundbox_set,   7 },
1691   { &model1_state::f102,            8 },
1692   { &model1_state::f103,            1 }
17991693};
18001694
18011695// Used in swa scene 1 and unemulated:
r32482r32483
18031697//   f49_swa
18041698//   f15_swa
18051699
1806static const struct function ftab_swa[] = {
1807   { fadd,            2 },  /* 0x00 */
1808   { fsub,            2 },
1809   { fmul,            2 },
1810   { fdiv,            2 },
1811   { NULL,            0 },
1812   { matrix_push,     0 },
1813   { matrix_pop,      0 },
1814   { matrix_write,   12 },
1815   { clear_stack,     0 },
1816   { matrix_mul,     12 },
1817   { anglev,          2 },
1818   { f11,             9 },
1819   { normalize,       3 },
1820   { acc_seti,        1 },
1821   { f14,             4 },
1822   { f15_swa,         0 },
1700const struct model1_state::function model1_state::ftab_swa[] = {
1701   { &model1_state::fadd,            2 },  /* 0x00 */
1702   { &model1_state::fsub,            2 },
1703   { &model1_state::fmul,            2 },
1704   { &model1_state::fdiv,            2 },
1705   { NULL,                       0 },
1706   { &model1_state::matrix_push,     0 },
1707   { &model1_state::matrix_pop,      0 },
1708   { &model1_state::matrix_write,   12 },
1709   { &model1_state::clear_stack,     0 },
1710   { &model1_state::matrix_mul,     12 },
1711   { &model1_state::anglev,          2 },
1712   { &model1_state::f11,             9 },
1713   { &model1_state::normalize,       3 },
1714   { &model1_state::acc_seti,        1 },
1715   { &model1_state::f14,             4 },
1716   { &model1_state::f15_swa,         0 },
18231717
1824   { matrix_ident,    0 }, /* 0x10 */
1825   { matrix_read,     0 },
1826   { matrix_trans,    3 },
1827   { matrix_scale,    3 },
1828   { matrix_rotx,     1 },
1829   { matrix_roty,     1 },
1830   { matrix_rotz,     1 },
1831   { NULL,            0 },
1832   { f24_swa,         7 },
1833   { NULL,            0 },
1834   { transform_point, 3 },
1835   { fsin_m1,         1 },
1836   { fcos_m1,         1 },
1837   { fsinm_m1,        2 },
1838   { fcosm_m1,        2 },
1839   { distance3,       6 },
1718   { &model1_state::matrix_ident,    0 }, /* 0x10 */
1719   { &model1_state::matrix_read,     0 },
1720   { &model1_state::matrix_trans,    3 },
1721   { &model1_state::matrix_scale,    3 },
1722   { &model1_state::matrix_rotx,     1 },
1723   { &model1_state::matrix_roty,     1 },
1724   { &model1_state::matrix_rotz,     1 },
1725   { NULL,                        0 },
1726   { &model1_state::f24_swa,         7 },
1727   { NULL,                          0 },
1728   { &model1_state::transform_point, 3 },
1729   { &model1_state::fsin_m1,         1 },
1730   { &model1_state::fcos_m1,         1 },
1731   { &model1_state::fsinm_m1,        2 },
1732   { &model1_state::fcosm_m1,        2 },
1733   { &model1_state::distance3,       6 },
18401734
1841   { NULL,            0 }, /* 0x20 */
1842   { NULL,            0 },
1843   { ftoi,            1 },
1844   { itof,            1 },
1845   { acc_set,         1 },
1846   { acc_get,         0 },
1847   { acc_add,         1 },
1848   { acc_sub,         1 },
1849   { acc_mul,         1 },
1850   { acc_div,         1 }, // not used ?
1851   { xyz2rqf,         3 },
1852   { f43_swa,         3 },
1853   { matrix_sdir,     3 },
1854   { f45,             1 },
1855   { vlength,         3 },
1856   { f47,             3 },
1735   { NULL,                          0 }, /* 0x20 */
1736   { NULL,                        0 },
1737   { &model1_state::ftoi,            1 },
1738   { &model1_state::itof,            1 },
1739   { &model1_state::acc_set,         1 },
1740   { &model1_state::acc_get,         0 },
1741   { &model1_state::acc_add,         1 },
1742   { &model1_state::acc_sub,         1 },
1743   { &model1_state::acc_mul,         1 },
1744   { &model1_state::acc_div,         1 }, // not used ?
1745   { &model1_state::xyz2rqf,         3 },
1746   { &model1_state::f43_swa,         3 },
1747   { &model1_state::matrix_sdir,     3 },
1748   { &model1_state::f45,             1 },
1749   { &model1_state::vlength,         3 },
1750   { &model1_state::f47,             3 },
18571751
1858   { NULL,            0 }, /* 0x30 */
1859   { f49_swa,         6 },
1860   { f50_swa,         4 },
1861   { NULL,            0 },
1862   { f52,             0 },
1863   { matrix_rdir,     3 },
1864   { NULL,            0 },
1865   { NULL,            0 },
1866   { f56,             7 },
1867   { f57,             0 },
1868   { matrix_readt,    0 },
1869   { acc_geti,        0 },
1870   { f60,             0 },
1871   { NULL,            0 },
1872   { NULL,            0 },
1873   { NULL,            0 },
1874   { NULL,            0 },
1752   { NULL,                          0 }, /* 0x30 */
1753   { &model1_state::f49_swa,         6 },
1754   { &model1_state::f50_swa,         4 },
1755   { NULL,                           0 },
1756   { &model1_state::f52,             0 },
1757   { &model1_state::matrix_rdir,     3 },
1758   { NULL,                          0 },
1759   { NULL,                          0 },
1760   { &model1_state::f56,             7 },
1761   { &model1_state::f57,             0 },
1762   { &model1_state::matrix_readt,    0 },
1763   { &model1_state::acc_geti,        0 },
1764   { &model1_state::f60,             0 },
1765   { NULL,                          0 },
1766   { NULL,                          0 },
1767   { NULL,                         0 },
1768   { NULL,                         0 },
18751769
1876   { push_and_ident,  0 }, /* 0x40 */
1877   { NULL,            0 },
1878   { catmull_rom,    13 }
1770   { &model1_state::push_and_ident,  0 }, /* 0x40 */
1771   { NULL,                         0 },
1772   { &model1_state::catmull_rom,    13 }
18791773};
18801774
18811775
1882static TGP_FUNCTION( dump )
1776TGP_FUNCTION( model1_state::dump )
18831777{
1884   model1_state *state = machine.driver_data<model1_state>();
1885   logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(state), state->m_pushpc);
1886   state->m_fifoin_cbcount = 1;
1887   state->m_fifoin_cb = dump;
1778   logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(), m_pushpc);
1779   m_fifoin_cbcount = 1;
1780   m_fifoin_cb = &model1_state::dump;
18881781}
18891782
1890static TGP_FUNCTION( function_get_vf )
1783TGP_FUNCTION( model1_state::function_get_vf )
18911784{
1892   model1_state *state = machine.driver_data<model1_state>();
1893   UINT32 f = fifoin_pop(state) >> 23;
1785   UINT32 f = fifoin_pop() >> 23;
18941786
1895   if(state->m_fifoout_rpos != state->m_fifoout_wpos) {
1896      int count = state->m_fifoout_wpos - state->m_fifoout_rpos;
1787   if(m_fifoout_rpos != m_fifoout_wpos) {
1788      int count = m_fifoout_wpos - m_fifoout_rpos;
18971789      if(count < 0)
18981790         count += FIFO_SIZE;
18991791      logerror("TGP function called with sizeout = %d\n", count);
19001792   }
19011793   if(ARRAY_LENGTH(ftab_vf) > f && NULL != ftab_vf[f].cb) {
1902      state->m_fifoin_cbcount = ftab_vf[f].count;
1903      state->m_fifoin_cb = ftab_vf[f].cb;
1904      //      logerror("TGP function %d request, %d parameters\n", f, state->m_fifoin_cbcount);
1905      if(!state->m_fifoin_cbcount)
1906         state->m_fifoin_cb(machine);
1794      m_fifoin_cbcount = ftab_vf[f].count;
1795      m_fifoin_cb = model1_state::ftab_vf[f].cb;
1796      //      logerror("TGP function %d request, %d parameters\n", f, m_fifoin_cbcount);
1797      if(!m_fifoin_cbcount)
1798         (this->*m_fifoin_cb)();
19071799   } else {
1908      logerror("TGP function %d unimplemented (%x)\n", f, state->m_pushpc);
1909      state->m_fifoin_cbcount = 1;
1910      state->m_fifoin_cb = dump;
1800      logerror("TGP function %d unimplemented (%x)\n", f, m_pushpc);
1801      m_fifoin_cbcount = 1;
1802      m_fifoin_cb = &model1_state::dump;
19111803   }
19121804}
19131805
1914static TGP_FUNCTION( function_get_swa )
1806TGP_FUNCTION( model1_state::function_get_swa )
19151807{
1916   model1_state *state = machine.driver_data<model1_state>();
1917   UINT32 f = fifoin_pop(state);
1808   UINT32 f = fifoin_pop();
19181809
1919   if(state->m_fifoout_rpos != state->m_fifoout_wpos) {
1920      int count = state->m_fifoout_wpos - state->m_fifoout_rpos;
1810   if(m_fifoout_rpos != m_fifoout_wpos) {
1811      int count = m_fifoout_wpos - m_fifoout_rpos;
19211812      if(count < 0)
19221813         count += FIFO_SIZE;
19231814      logerror("TGP function called with sizeout = %d\n", count);
19241815   }
19251816   if(ARRAY_LENGTH(ftab_swa) > f && NULL != ftab_swa[f].cb) {
1926      state->m_fifoin_cbcount = ftab_swa[f].count;
1927      state->m_fifoin_cb = ftab_swa[f].cb;
1928      //      logerror("TGP function %d request, %d parameters\n", f, state->m_fifoin_cbcount);
1929      if(!state->m_fifoin_cbcount)
1930         state->m_fifoin_cb(machine);
1817      m_fifoin_cbcount = ftab_swa[f].count;
1818      m_fifoin_cb = model1_state::ftab_swa[f].cb;
1819      //      logerror("TGP function %d request, %d parameters\n", f, m_fifoin_cbcount);
1820      if(!m_fifoin_cbcount)
1821         (this->*m_fifoin_cb)();
19311822   } else {
1932      logerror("TGP function %d unimplemented (%x)\n", f, state->m_pushpc);
1933      state->m_fifoin_cbcount = 1;
1934      state->m_fifoin_cb = dump;
1823      logerror("TGP function %d unimplemented (%x)\n", f, m_pushpc);
1824      m_fifoin_cbcount = 1;
1825      m_fifoin_cb = &model1_state::dump;
19351826   }
19361827}
19371828
19381829READ16_MEMBER(model1_state::model1_tgp_copro_r)
19391830{
19401831   if(!offset) {
1941      m_copro_r = fifoout_pop(space);
1832      m_copro_r = fifoout_pop();
19421833      return m_copro_r;
19431834   } else
19441835      return m_copro_r >> 16;
r32482r32483
19491840   if(offset) {
19501841      m_copro_w = (m_copro_w & 0x0000ffff) | (data << 16);
19511842      m_pushpc = space.device().safe_pc();
1952      fifoin_push(space, m_copro_w);
1843      fifoin_push(m_copro_w);
19531844   } else
19541845      m_copro_w = (m_copro_w & 0xffff0000) | data;
19551846}
r32482r32483
20061897   save_item(NAME(m_list_length));
20071898}
20081899
2009void model1_tgp_reset(running_machine &machine, int swa)
1900void model1_state::tgp_reset(int swa)
20101901{
2011   model1_state *state = machine.driver_data<model1_state>();
2012   state->m_ram_adr = 0;
2013   memset(state->m_ram_data, 0, 0x10000*4);
1902   m_ram_adr = 0;
1903   memset(m_ram_data, 0, 0x10000*4);
20141904
2015   state->m_fifoout_rpos = 0;
2016   state->m_fifoout_wpos = 0;
2017   state->m_fifoin_rpos = 0;
2018   state->m_fifoin_wpos = 0;
1905   m_fifoout_rpos = 0;
1906   m_fifoout_wpos = 0;
1907   m_fifoin_rpos = 0;
1908   m_fifoin_wpos = 0;
20191909
2020   state->m_acc = 0;
2021   state->m_mat_stack_pos = 0;
2022   memset(state->m_cmat, 0, sizeof(state->m_cmat));
2023   state->m_cmat[0] = 1.0;
2024   state->m_cmat[4] = 1.0;
2025   state->m_cmat[8] = 1.0;
1910   m_acc = 0;
1911   m_mat_stack_pos = 0;
1912   memset(m_cmat, 0, sizeof(m_cmat));
1913   m_cmat[0] = 1.0;
1914   m_cmat[4] = 1.0;
1915   m_cmat[8] = 1.0;
20261916
2027   state->m_dump = 0;
2028   state->m_swa = swa;
2029   next_fn(state);
1917   m_dump = 0;
1918   m_swa = swa;
1919   next_fn();
20301920}
20311921
20321922/*********************************** Virtua Racing ***********************************/
20331923
20341924
2035void model1_vr_tgp_reset( running_machine &machine )
1925void model1_state::vr_tgp_reset()
20361926{
2037   model1_state *state = machine.driver_data<model1_state>();
2038   state->m_ram_adr = 0;
2039   memset(state->m_ram_data, 0, 0x8000*4);
1927   m_ram_adr = 0;
1928   memset(m_ram_data, 0, 0x8000*4);
20401929
2041   state->m_copro_fifoout_rpos = 0;
2042   state->m_copro_fifoout_wpos = 0;
2043   state->m_copro_fifoout_num = 0;
2044   state->m_copro_fifoin_rpos = 0;
2045   state->m_copro_fifoin_wpos = 0;
2046   state->m_copro_fifoin_num = 0;
1930   m_copro_fifoout_rpos = 0;
1931   m_copro_fifoout_wpos = 0;
1932   m_copro_fifoout_num = 0;
1933   m_copro_fifoin_rpos = 0;
1934   m_copro_fifoin_wpos = 0;
1935   m_copro_fifoin_num = 0;
20471936}
20481937
20491938/* FIFO */
r32482r32483
20721961}
20731962
20741963
2075static void copro_fifoin_push(address_space &space, UINT32 data)
1964void model1_state::copro_fifoin_push(UINT32 data)
20761965{
2077   model1_state *state = space.machine().driver_data<model1_state>();
2078   if (state->m_copro_fifoin_num == FIFO_SIZE)
1966   if (m_copro_fifoin_num == FIFO_SIZE)
20791967   {
2080      fatalerror("Copro FIFOIN overflow (at %08X)\n", space.device().safe_pc());
1968      fatalerror("Copro FIFOIN overflow (at %08X)\n", safe_pc());
20811969   }
20821970
2083   state->m_copro_fifoin_data[state->m_copro_fifoin_wpos++] = data;
1971   m_copro_fifoin_data[m_copro_fifoin_wpos++] = data;
20841972
2085   if (state->m_copro_fifoin_wpos == FIFO_SIZE)
1973   if (m_copro_fifoin_wpos == FIFO_SIZE)
20861974   {
2087      state->m_copro_fifoin_wpos = 0;
1975      m_copro_fifoin_wpos = 0;
20881976   }
20891977
2090   state->m_copro_fifoin_num++;
1978   m_copro_fifoin_num++;
20911979}
20921980
2093static UINT32 copro_fifoout_pop(address_space &space)
1981UINT32 model1_state::copro_fifoout_pop()
20941982{
2095   model1_state *state = space.machine().driver_data<model1_state>();
2096   UINT32 r;
2097
2098   if (state->m_copro_fifoout_num == 0)
1983   if (m_copro_fifoout_num == 0)
20991984   {
21001985      // Reading from empty FIFO causes the v60 to enter wait state
2101      state->m_maincpu->stall();
1986      m_maincpu->stall();
21021987
2103      space.machine().scheduler().synchronize();
1988      machine().scheduler().synchronize();
21041989
21051990      return 0;
21061991   }
21071992
2108   r = state->m_copro_fifoout_data[state->m_copro_fifoout_rpos++];
1993   UINT32 r = m_copro_fifoout_data[m_copro_fifoout_rpos++];
21091994
2110   if (state->m_copro_fifoout_rpos == FIFO_SIZE)
1995   if (m_copro_fifoout_rpos == FIFO_SIZE)
21111996   {
2112      state->m_copro_fifoout_rpos = 0;
1997      m_copro_fifoout_rpos = 0;
21131998   }
21141999
2115   state->m_copro_fifoout_num--;
2000   m_copro_fifoout_num--;
21162001
21172002   return r;
21182003}
r32482r32483
22022087{
22032088   if (!offset)
22042089   {
2205      m_vr_r = copro_fifoout_pop(space);
2090      m_vr_r = copro_fifoout_pop();
22062091      return m_vr_r;
22072092   }
22082093   else
r32482r32483
22142099   if (offset)
22152100   {
22162101      m_vr_w = (m_vr_w & 0x0000ffff) | (data << 16);
2217      copro_fifoin_push(space, m_vr_w);
2102      copro_fifoin_push(m_vr_w);
22182103   }
22192104   else
22202105      m_vr_w = (m_vr_w & 0xffff0000) | data;
trunk/src/mame/includes/model1.h
r32482r32483
22#include "audio/segam1audio.h"
33#include "cpu/v60/v60.h"
44
5typedef void (*tgp_func)(running_machine &machine);
5#define DECLARE_TGP_FUNCTION(name) void name()
66
77enum {FIFO_SIZE = 256};
88enum {MAT_STACK_SIZE = 32};
r32482r32483
1616      m_m1audio(*this, "m1audio"),
1717      m_dsbz80(*this, DSBZ80_TAG),
1818      m_tgp(*this, "tgp"),
19      m_screen(*this, "screen"),
1920      m_mr2(*this, "mr2"),
2021      m_mr(*this, "mr"),
2122      m_display_list0(*this, "display_list0"),
r32482r32483
2829   required_device<segam1audio_device> m_m1audio;  // Model 1 standard sound board
2930   optional_device<dsbz80_device> m_dsbz80;    // Digital Sound Board
3031   optional_device<mb86233_cpu_device> m_tgp;
32   required_device<screen_device> m_screen;
3133
3234   required_shared_ptr<UINT16> m_mr2;
3335   required_shared_ptr<UINT16> m_mr;
3436   required_shared_ptr<UINT16> m_display_list0;
3537   required_shared_ptr<UINT16> m_display_list1;
3638   required_shared_ptr<UINT16> m_color_xlat;
37
39   
3840   struct view *m_view;
3941   struct point *m_pointdb;
4042   struct point *m_pointpt;
r32482r32483
5254   UINT32 m_fifoin_data[FIFO_SIZE];
5355   int m_swa;
5456   int m_fifoin_cbcount;
57   typedef void (model1_state::*tgp_func)();
5558   tgp_func m_fifoin_cb;
59   struct function
60   {
61      tgp_func cb;
62      int count;
63   };
64   static const struct function ftab_vf[];
65   static const struct function ftab_swa[];
5666   INT32 m_fifoout_rpos;
5767   INT32 m_fifoout_wpos;
5868   UINT32 m_fifoout_data[FIFO_SIZE];
r32482r32483
151161   DECLARE_READ_LINE_MEMBER(copro_fifoin_pop_ok);
152162   DECLARE_READ32_MEMBER(copro_fifoin_pop);
153163   DECLARE_WRITE32_MEMBER(copro_fifoout_push);
164   void vr_tgp_reset();
165   void tgp_reset(int swa);
166   void next_fn();
167   UINT32 fifoout_pop();
168   void fifoout_push(UINT32 data);
169   void fifoout_push_f(float data);
170   UINT32 fifoin_pop();
171   void fifoin_push(UINT32 data);
172   float fifoin_pop_f();
173   UINT16 ram_get_i();
174   float ram_get_f();
175   DECLARE_TGP_FUNCTION( fadd );
176   DECLARE_TGP_FUNCTION( fsub );
177   DECLARE_TGP_FUNCTION( fmul );
178   DECLARE_TGP_FUNCTION( fdiv );
179   DECLARE_TGP_FUNCTION( matrix_push );
180   DECLARE_TGP_FUNCTION( matrix_pop );
181   DECLARE_TGP_FUNCTION( matrix_write );
182   DECLARE_TGP_FUNCTION( clear_stack );
183   DECLARE_TGP_FUNCTION( matrix_mul );
184   DECLARE_TGP_FUNCTION( anglev );
185   DECLARE_TGP_FUNCTION( f11 );
186   DECLARE_TGP_FUNCTION( normalize );
187   DECLARE_TGP_FUNCTION( acc_seti );
188   DECLARE_TGP_FUNCTION( track_select );
189   DECLARE_TGP_FUNCTION( f14 );
190   DECLARE_TGP_FUNCTION( f15_swa );
191   DECLARE_TGP_FUNCTION( anglep );
192   DECLARE_TGP_FUNCTION( matrix_ident );
193   DECLARE_TGP_FUNCTION( matrix_read );
194   DECLARE_TGP_FUNCTION( matrix_trans );
195   DECLARE_TGP_FUNCTION( matrix_scale );
196   DECLARE_TGP_FUNCTION( matrix_rotx );
197   DECLARE_TGP_FUNCTION( matrix_roty );
198   DECLARE_TGP_FUNCTION( matrix_rotz );
199   DECLARE_TGP_FUNCTION( track_read_quad );
200   DECLARE_TGP_FUNCTION( f24_swa );
201   DECLARE_TGP_FUNCTION( transform_point );
202   DECLARE_TGP_FUNCTION( fcos_m1 );
203   DECLARE_TGP_FUNCTION( fsin_m1 );
204   DECLARE_TGP_FUNCTION( fcosm_m1 );
205   DECLARE_TGP_FUNCTION( fsinm_m1 );
206   DECLARE_TGP_FUNCTION( distance3 );
207   DECLARE_TGP_FUNCTION( ftoi );
208   DECLARE_TGP_FUNCTION( itof );
209   DECLARE_TGP_FUNCTION( acc_set );
210   DECLARE_TGP_FUNCTION( acc_get );
211   DECLARE_TGP_FUNCTION( acc_add );
212   DECLARE_TGP_FUNCTION( acc_sub );
213   DECLARE_TGP_FUNCTION( acc_mul );
214   DECLARE_TGP_FUNCTION( acc_div );
215   DECLARE_TGP_FUNCTION( f42 );
216   DECLARE_TGP_FUNCTION( xyz2rqf );
217   DECLARE_TGP_FUNCTION( f43 );
218   DECLARE_TGP_FUNCTION( f43_swa );
219   DECLARE_TGP_FUNCTION( f44 );
220   DECLARE_TGP_FUNCTION( matrix_sdir );
221   DECLARE_TGP_FUNCTION( f45 );
222   DECLARE_TGP_FUNCTION( vlength );
223   DECLARE_TGP_FUNCTION( f47 );
224   DECLARE_TGP_FUNCTION( track_read_info );
225   DECLARE_TGP_FUNCTION( colbox_set );
226   DECLARE_TGP_FUNCTION( colbox_test );
227   DECLARE_TGP_FUNCTION( f49_swa );
228   DECLARE_TGP_FUNCTION( f50_swa );
229   DECLARE_TGP_FUNCTION( f52 );
230   DECLARE_TGP_FUNCTION( matrix_rdir );
231   DECLARE_TGP_FUNCTION( track_lookup );
232   DECLARE_TGP_FUNCTION( f56 );
233   DECLARE_TGP_FUNCTION( f57 );
234   DECLARE_TGP_FUNCTION( matrix_readt );
235   DECLARE_TGP_FUNCTION( acc_geti );
236   DECLARE_TGP_FUNCTION( f60 );
237   DECLARE_TGP_FUNCTION( col_setcirc );
238   DECLARE_TGP_FUNCTION( col_testpt );
239   DECLARE_TGP_FUNCTION( push_and_ident );
240   DECLARE_TGP_FUNCTION( catmull_rom );
241   DECLARE_TGP_FUNCTION( distance );
242   DECLARE_TGP_FUNCTION( car_move );
243   DECLARE_TGP_FUNCTION( cpa );
244   DECLARE_TGP_FUNCTION( vmat_store );
245   DECLARE_TGP_FUNCTION( vmat_restore );
246   DECLARE_TGP_FUNCTION( vmat_mul );
247   DECLARE_TGP_FUNCTION( vmat_read );
248   DECLARE_TGP_FUNCTION( matrix_rtrans );
249   DECLARE_TGP_FUNCTION( matrix_unrot );
250   DECLARE_TGP_FUNCTION( f80 );
251   DECLARE_TGP_FUNCTION( vmat_save );
252   DECLARE_TGP_FUNCTION( vmat_load );
253   DECLARE_TGP_FUNCTION( ram_setadr );
254   DECLARE_TGP_FUNCTION( groundbox_test );
255   DECLARE_TGP_FUNCTION( f89 );
256   DECLARE_TGP_FUNCTION( f92 );
257   DECLARE_TGP_FUNCTION( f93 );
258   DECLARE_TGP_FUNCTION( f94 );
259   DECLARE_TGP_FUNCTION( vmat_flatten );
260   DECLARE_TGP_FUNCTION( vmat_load1 );
261   DECLARE_TGP_FUNCTION( ram_trans );
262   DECLARE_TGP_FUNCTION( f98_load );
263   DECLARE_TGP_FUNCTION( f98 );
264   DECLARE_TGP_FUNCTION( f99 );
265   DECLARE_TGP_FUNCTION( f100 );
266   DECLARE_TGP_FUNCTION( groundbox_set );
267   DECLARE_TGP_FUNCTION( f102 );
268   DECLARE_TGP_FUNCTION( f103 );
269   DECLARE_TGP_FUNCTION( dump );
270   DECLARE_TGP_FUNCTION( function_get_vf );
271   DECLARE_TGP_FUNCTION( function_get_swa );
272   void copro_fifoin_push(UINT32 data);
273   UINT32 copro_fifoout_pop();
274   void sort_quads();
275   void unsort_quads();
276   void draw_quads(bitmap_rgb32 &bitmap, const rectangle &cliprect);
277   void fclip_push_quad_next(int level, struct quad_m1 *q,   struct point *p1, struct point *p2, struct point *p3, struct point *p4);
278   void fclip_push_quad(int level, struct quad_m1 *q);
279   void push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size);
280   UINT16 *push_direct(UINT16 *list);
281   void draw_objects(bitmap_rgb32 &bitmap, const rectangle &cliprect);
282   UINT16 *draw_direct(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT16 *list);
283   UINT16 *get_list();
284   int get_list_number();
285   void end_frame();
286   void tgp_render(bitmap_rgb32 &bitmap, const rectangle &cliprect);
287   void tgp_scan();
154288};
155289
156290
157291/*----------- defined in machine/model1.c -----------*/
158292
159293ADDRESS_MAP_EXTERN( model1_vr_tgp_map, 32 );
160
161void model1_vr_tgp_reset( running_machine &machine );
162void model1_tgp_reset(running_machine &machine, int swa);
trunk/src/mame/video/model1.c
r32482r32483
6969   return u2f(readi(adr));
7070}
7171
72static void transform_point(struct view *view, struct point *p)
72static void _transform_point(struct view *view, struct point *p)
7373{
7474   struct point q = *p;
7575   float *trans = view->trans_mat;
r32482r32483
415415   return +1;
416416}
417417
418static void sort_quads(model1_state *state)
418void model1_state::sort_quads()
419419{
420   int count = state->m_quadpt - state->m_quaddb;
420   int count = m_quadpt - m_quaddb;
421421   int i;
422422   for(i=0; i<count; i++)
423      state->m_quadind[i] = state->m_quaddb+i;
424   qsort(state->m_quadind, count, sizeof(struct quad_m1 *), comp_quads);
423      m_quadind[i] = m_quaddb+i;
424   qsort(m_quadind, count, sizeof(struct quad_m1 *), comp_quads);
425425}
426426
427static void unsort_quads(model1_state *state)
427void model1_state::unsort_quads()
428428{
429   int count = state->m_quadpt - state->m_quaddb;
429   int count = m_quadpt - m_quaddb;
430430   int i;
431431   for(i=0; i<count; i++)
432      state->m_quadind[i] = state->m_quaddb+i;
432      m_quadind[i] = m_quaddb+i;
433433}
434434
435435
436static void draw_quads(model1_state *state, bitmap_rgb32 &bitmap, const rectangle &cliprect)
436void model1_state::draw_quads(bitmap_rgb32 &bitmap, const rectangle &cliprect)
437437{
438   struct view *view = state->m_view;
439   int count = state->m_quadpt - state->m_quaddb;
438   struct view *view = m_view;
439   int count = m_quadpt - m_quaddb;
440440   int i;
441441
442442   /* clip to the cliprect */
r32482r32483
450450   view->y2 = MIN(view->y2, cliprect.max_y);
451451
452452   for(i=0; i<count; i++) {
453      struct quad_m1 *q = state->m_quadind[i];
453      struct quad_m1 *q = m_quadind[i];
454454
455455      fill_quad(bitmap, view, q);
456456#if 0
r32482r32483
566566   { fclip_isc_right,  fclip_clip_right },
567567};
568568
569static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q);
570
571static void fclip_push_quad_next(model1_state *state, int level, struct quad_m1 *q,
569void model1_state::fclip_push_quad_next(int level, struct quad_m1 *q,
572570                           struct point *p1, struct point *p2, struct point *p3, struct point *p4)
573571{
574572   struct quad_m1 q2;
r32482r32483
579577   q2.p[2] = p3;
580578   q2.p[3] = p4;
581579
582   fclip_push_quad(state, level+1, &q2);
580   fclip_push_quad(level+1, &q2);
583581}
584582
585static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q)
583void model1_state::fclip_push_quad(int level, struct quad_m1 *q)
586584{
587   struct view *view = state->m_view;
585   struct view *view = m_view;
588586   int i, j;
589587   struct point *pt[4], *pi1, *pi2;
590588   int is_out[4], is_out2[4];
r32482r32483
595593      for(i=0; i<4; i++)
596594         LOG_TGP((" (%f, %f, %f)", q->p[i]->x, q->p[i]->y, q->p[i]->z));
597595      LOG_TGP(("\n"));
598      *state->m_quadpt = *q;
599      state->m_quadpt++;
596      *m_quadpt = *q;
597      m_quadpt++;
600598      return;
601599   }
602600
r32482r32483
610608
611609   // No clipping
612610   if(!is_out[0] && !is_out[1] && !is_out[2] && !is_out[3]) {
613      fclip_push_quad(state, level+1, q);
611      fclip_push_quad(level+1, q);
614612      return;
615613   }
616614
r32482r32483
634632   if(is_out2[1])
635633      if(is_out2[2]) {
636634         // pt 0,1,2 clipped out, one triangle left
637         fclip_point(view, state->m_pointpt, pt[2], pt[3]);
638         pi1 = state->m_pointpt++;
639         fclip_point(view, state->m_pointpt, pt[3], pt[0]);
640         pi2 = state->m_pointpt++;
641         fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2);
635         fclip_point(view, m_pointpt, pt[2], pt[3]);
636         pi1 = m_pointpt++;
637         fclip_point(view, m_pointpt, pt[3], pt[0]);
638         pi2 = m_pointpt++;
639         fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2);
642640      } else {
643641         // pt 0,1 clipped out, one quad left
644         fclip_point(view, state->m_pointpt, pt[1], pt[2]);
645         pi1 = state->m_pointpt++;
646         fclip_point(view, state->m_pointpt, pt[3], pt[0]);
647         pi2 = state->m_pointpt++;
648         fclip_push_quad_next(state, level, q, pi1, pt[2], pt[3], pi2);
642         fclip_point(view, m_pointpt, pt[1], pt[2]);
643         pi1 = m_pointpt++;
644         fclip_point(view, m_pointpt, pt[3], pt[0]);
645         pi2 = m_pointpt++;
646         fclip_push_quad_next(level, q, pi1, pt[2], pt[3], pi2);
649647      }
650648   else
651649      if(is_out2[2]) {
652650         // pt 0,2 clipped out, shouldn't happen, two triangles
653         fclip_point(view, state->m_pointpt, pt[0], pt[1]);
654         pi1 = state->m_pointpt++;
655         fclip_point(view, state->m_pointpt, pt[1], pt[2]);
656         pi2 = state->m_pointpt++;
657         fclip_push_quad_next(state, level, q, pi1, pt[1], pi2, pi2);
658         fclip_point(view, state->m_pointpt, pt[2], pt[3]);
659         pi1 = state->m_pointpt++;
660         fclip_point(view, state->m_pointpt, pt[3], pt[0]);
661         pi2 = state->m_pointpt++;
662         fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2);
651         fclip_point(view, m_pointpt, pt[0], pt[1]);
652         pi1 = m_pointpt++;
653         fclip_point(view, m_pointpt, pt[1], pt[2]);
654         pi2 = m_pointpt++;
655         fclip_push_quad_next(level, q, pi1, pt[1], pi2, pi2);
656         fclip_point(view, m_pointpt, pt[2], pt[3]);
657         pi1 = m_pointpt++;
658         fclip_point(view, m_pointpt, pt[3], pt[0]);
659         pi2 = m_pointpt++;
660         fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2);
663661      } else {
664662         // pt 0 clipped out, one decagon left, split in quad+tri
665         fclip_point(view, state->m_pointpt, pt[0], pt[1]);
666         pi1 = state->m_pointpt++;
667         fclip_point(view, state->m_pointpt, pt[3], pt[0]);
668         pi2 = state->m_pointpt++;
669         fclip_push_quad_next(state, level, q, pi1, pt[1], pt[2], pt[3]);
670         fclip_push_quad_next(state, level, q, pt[3], pi2, pi1, pi1);
663         fclip_point(view, m_pointpt, pt[0], pt[1]);
664         pi1 = m_pointpt++;
665         fclip_point(view, m_pointpt, pt[3], pt[0]);
666         pi2 = m_pointpt++;
667         fclip_push_quad_next(level, q, pi1, pt[1], pt[2], pt[3]);
668         fclip_push_quad_next(level, q, pt[3], pi2, pi1, pi1);
671669      }
672670}
673671
r32482r32483
724722   return 0;
725723}
726724
727static void push_object(running_machine &machine, UINT32 tex_adr, UINT32 poly_adr, UINT32 size)
725void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size)
728726{
729   model1_state *state = machine.driver_data<model1_state>();
730   struct view *view = state->m_view;
727   struct view *view = m_view;
731728   int i;
732729   UINT32 flags;
733730   struct point *old_p0, *old_p1, *p0, *p1;
r32482r32483
742739   float *poly_data;
743740
744741   if(poly_adr & 0x800000)
745      poly_data=(float *) state->m_poly_ram;
742      poly_data=(float *) m_poly_ram;
746743   else
747      poly_data=(float *) state->m_poly_rom;
744      poly_data=(float *) m_poly_rom;
748745
749746   poly_adr &= 0x7fffff;
750747#if 0
r32482r32483
773770   if(!size)
774771      size = 0xffffffff;
775772
776   old_p0 = state->m_pointpt++;
777   old_p1 = state->m_pointpt++;
773   old_p0 = m_pointpt++;
774   old_p1 = m_pointpt++;
778775
779776   old_p0->x = poly_data[poly_adr+0];
780777   old_p0->y = poly_data[poly_adr+1];
r32482r32483
782779   old_p1->x = poly_data[poly_adr+3];
783780   old_p1->y = poly_data[poly_adr+4];
784781   old_p1->z = poly_data[poly_adr+5];
785   transform_point(view, old_p0);
786   transform_point(view, old_p1);
782   _transform_point(view, old_p0);
783   _transform_point(view, old_p1);
787784   if(old_p0->z > 0)
788785      project_point(view, old_p0);
789786   else
r32482r32483
815812         tex_adr ++;
816813      lightmode=(flags>>17)&15;
817814
818      p0 = state->m_pointpt++;
819      p1 = state->m_pointpt++;
815      p0 = m_pointpt++;
816      p1 = m_pointpt++;
820817
821818      vn.x = poly_data[poly_adr+1];
822819      vn.y = poly_data[poly_adr+2];
r32482r32483
832829
833830      transform_vector(view, &vn);
834831
835      transform_point(view, p0);
836      transform_point(view, p1);
832      _transform_point(view, p0);
833      _transform_point(view, p1);
837834      if(p0->z > 0)
838835         project_point(view, p0);
839836      else
r32482r32483
896893#if 0
897894         float dif=mult_vector(&vn, &view->light);
898895         float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif);
899         cquad.col = scale_color(machine.pens[0x1000|(state->m_tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
900         cquad.col = scale_color(machine.pens[0x1000|(state->m_tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
896         cquad.col = scale_color(machine().pens[0x1000|(m_tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
897         cquad.col = scale_color(machine().pens[0x1000|(m_tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
901898#endif
902899         float dif=mult_vector(&vn, &view->light);
903900         float spec=compute_specular(&vn,&view->light,dif,lightmode);
904901         float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif) + spec;
905902         int lumval=255.0*MIN(1.0,ln);
906         int color=state->m_paletteram16[0x1000|(state->m_tgp_ram[tex_adr-0x40000] & 0x3ff)];
903         int color=m_paletteram16[0x1000|(m_tgp_ram[tex_adr-0x40000] & 0x3ff)];
907904         int r=(color>>0x0)&0x1f;
908905         int g=(color>>0x5)&0x1f;
909906         int b=(color>>0xA)&0x1f;
910907         lumval>>=2; //there must be a luma translation table somewhere
911908         if(lumval>0x3f) lumval=0x3f;
912909         else if(lumval<0) lumval=0;
913         r=(state->m_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
914         g=(state->m_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
915         b=(state->m_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
910         r=(m_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
911         g=(m_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
912         b=(m_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
916913         cquad.col=(pal5bit(r)<<16)|(pal5bit(g)<<8)|(pal5bit(b)<<0);
917914      }
918915
919916      if(flags & 0x00002000)
920917         cquad.col |= MOIRE;
921918
922      fclip_push_quad(state, 0, &cquad);
919      fclip_push_quad(0, &cquad);
923920
924921   next:
925922      poly_adr += 10;
r32482r32483
939936   }
940937}
941938
942static UINT16 *push_direct(model1_state *state, UINT16 *list)
939UINT16 *model1_state::push_direct(UINT16 *list)
943940{
944   struct view *view = state->m_view;
941   struct view *view = m_view;
945942   UINT32 flags;
946943   UINT32 tex_adr, lum; //, v1, v2;
947944   struct point *old_p0, *old_p1, *p0, *p1;
r32482r32483
953950//  v1      = readi(list+2);
954951//  v2      = readi(list+10);
955952
956   old_p0 = state->m_pointpt++;
957   old_p1 = state->m_pointpt++;
953   old_p0 = m_pointpt++;
954   old_p1 = m_pointpt++;
958955
959956   old_p0->x = readf(list+4);
960957   old_p0->y = readf(list+6);
r32482r32483
968965            old_p0->x, old_p0->y, old_p0->z,
969966            old_p1->x, old_p1->y, old_p1->z));
970967
971   //transform_point(view, old_p0);
972   //transform_point(view, old_p1);
968   //_transform_point(view, old_p0);
969   //_transform_point(view, old_p1);
973970   if(old_p0->z > 0)
974971      project_point_direct(view, old_p0);
975972   else
r32482r32483
995992      // list+4 is 0?
996993      // list+12 is z?
997994
998      p0 = state->m_pointpt++;
999      p1 = state->m_pointpt++;
995      p0 = m_pointpt++;
996      p1 = m_pointpt++;
1000997
1001998      lum   = readi(list+2);
1002999//      v1    = readi(list+4);
r32482r32483
10281025
10291026      link = (flags >> 8) & 3;
10301027
1031      //transform_point(view, p0);
1032      //transform_point(view, p1);
1028      //_transform_point(view, p0);
1029      //_transform_point(view, p1);
10331030      if(p0->z > 0)
10341031         project_point_direct(view, p0);
10351032      if(p1->z > 0)
r32482r32483
10611058      cquad.z    = z;
10621059      {
10631060         int lumval=((float) (lum>>24)) * 2.0;
1064         int color=state->m_paletteram16[0x1000|(state->m_tgp_ram[tex_adr-0x40000] & 0x3ff)];
1061         int color=m_paletteram16[0x1000|(m_tgp_ram[tex_adr-0x40000] & 0x3ff)];
10651062         int r=(color>>0x0)&0x1f;
10661063         int g=(color>>0x5)&0x1f;
10671064         int b=(color>>0xA)&0x1f;
10681065         lumval>>=2; //there must be a luma translation table somewhere
10691066         if(lumval>0x3f) lumval=0x3f;
10701067         else if(lumval<0) lumval=0;
1071         r=(state->m_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
1072         g=(state->m_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
1073         b=(state->m_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
1068         r=(m_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
1069         g=(m_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
1070         b=(m_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
10741071         cquad.col=(pal5bit(r)<<16)|(pal5bit(g)<<8)|(pal5bit(b)<<0);
10751072      }
1076      //cquad.col  = scale_color(machine.pens[0x1000|(state->m_tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0);
1073      //cquad.col  = scale_color(machine().pens[0x1000|(m_tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0);
10771074      if(flags & 0x00002000)
10781075         cquad.col |= MOIRE;
10791076
1080      fclip_push_quad(state, 0, &cquad);
1077      fclip_push_quad(0, &cquad);
10811078
10821079   next:
10831080      switch(link) {
r32482r32483
11191116   return list+2;
11201117}
11211118
1122static void draw_objects(model1_state *state, bitmap_rgb32 &bitmap, const rectangle &cliprect)
1119void model1_state::draw_objects(bitmap_rgb32 &bitmap, const rectangle &cliprect)
11231120{
1124   if(state->m_quadpt != state->m_quaddb) {
1121   if(m_quadpt != m_quaddb) {
11251122      LOG_TGP(("VIDEO: sort&draw\n"));
1126      sort_quads(state);
1127      draw_quads(state, bitmap, cliprect);
1123      sort_quads();
1124      draw_quads(bitmap, cliprect);
11281125   }
11291126
1130   state->m_quadpt = state->m_quaddb;
1131   state->m_pointpt = state->m_pointdb;
1127   m_quadpt = m_quaddb;
1128   m_pointpt = m_pointdb;
11321129}
11331130
1134static UINT16 *draw_direct(model1_state *state, bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT16 *list)
1131UINT16 *model1_state::draw_direct(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT16 *list)
11351132{
11361133   UINT16 *res;
11371134
11381135   LOG_TGP(("VIDEO:   draw direct %x\n", readi(list)));
11391136
1140   draw_objects(state, bitmap, cliprect);
1141   res = push_direct(state, list);
1142   unsort_quads(state);
1143   draw_quads(state, bitmap, cliprect);
1137   draw_objects(bitmap, cliprect);
1138   res = push_direct(list);
1139   unsort_quads();
1140   draw_quads(bitmap, cliprect);
11441141
1145   state->m_quadpt = state->m_quaddb;
1146   state->m_pointpt = state->m_pointdb;
1142   m_quadpt = m_quaddb;
1143   m_pointpt = m_pointdb;
11471144   return res;
11481145}
11491146
1150static UINT16 *get_list(model1_state *state)
1147UINT16 *model1_state::get_list()
11511148{
1152   if(!(state->m_listctl[0] & 4))
1153      state->m_listctl[0] = (state->m_listctl[0] & ~0x40) | (state->m_listctl[0] & 8 ? 0x40 : 0);
1154   return state->m_listctl[0] & 0x40 ? state->m_display_list1 : state->m_display_list0;
1149   if(!(m_listctl[0] & 4))
1150      m_listctl[0] = (m_listctl[0] & ~0x40) | (m_listctl[0] & 8 ? 0x40 : 0);
1151   return m_listctl[0] & 0x40 ? m_display_list1 : m_display_list0;
11551152}
11561153
1157static int get_list_number(model1_state *state)
1154int model1_state::get_list_number()
11581155{
1159   if(!(state->m_listctl[0] & 4))
1160      state->m_listctl[0] = (state->m_listctl[0] & ~0x40) | (state->m_listctl[0] & 8 ? 0x40 : 0);
1161   return state->m_listctl[0] & 0x40 ? 0 : 1;
1156   if(!(m_listctl[0] & 4))
1157      m_listctl[0] = (m_listctl[0] & ~0x40) | (m_listctl[0] & 8 ? 0x40 : 0);
1158   return m_listctl[0] & 0x40 ? 0 : 1;
11621159}
11631160
1164static void end_frame(running_machine &machine)
1161void model1_state::end_frame()
11651162{
1166   model1_state *state = machine.driver_data<model1_state>();
1167   if((state->m_listctl[0] & 4) && (machine.first_screen()->frame_number() & 1))
1168      state->m_listctl[0] ^= 0x40;
1163   if((m_listctl[0] & 4) && (m_screen->frame_number() & 1))
1164      m_listctl[0] ^= 0x40;
11691165}
11701166
11711167READ16_MEMBER(model1_state::model1_listctl_r)
r32482r32483
11821178   LOG_TGP(("VIDEO: control=%08x\n", (m_listctl[1]<<16)|m_listctl[0]));
11831179}
11841180
1185static void tgp_render(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
1181void model1_state::tgp_render(bitmap_rgb32 &bitmap, const rectangle &cliprect)
11861182{
1187   model1_state *state = machine.driver_data<model1_state>();
1188   struct view *view = state->m_view;
1189   state->m_render_done = 1;
1190   if((state->m_listctl[1] & 0x1f) == 0x1f) {
1191      UINT16 *list = get_list(state);
1183   struct view *view = m_view;
1184   m_render_done = 1;
1185   if((m_listctl[1] & 0x1f) == 0x1f) {
1186      UINT16 *list = get_list();
11921187      int zz = 0;
1193      LOG_TGP(("VIDEO: render list %d\n", get_list_number(state)));
1188      LOG_TGP(("VIDEO: render list %d\n", get_list_number()));
11941189
11951190      memset(view->trans_mat, 0, sizeof(view->trans_mat));
11961191      view->trans_mat[0] = 1.0;
r32482r32483
11991194
12001195      for(;;) {
12011196         int type = (list[1]<<16)|list[0];
1202         state->m_glist=list;
1197         m_glist=list;
12031198         switch(type & 15) {
12041199         case 0:
12051200            list += 2;
r32482r32483
12131208            // 6 = ??  draw object (57bd4, 387460, 2ad)
12141209
12151210            if(1 || zz >= 666)
1216               push_object(machine, readi(list+2), readi(list+4), readi(list+6));
1211               push_object(readi(list+2), readi(list+4), readi(list+6));
12171212            list += 8;
12181213            break;
12191214         case 2:
1220            list = draw_direct(state, bitmap, cliprect, list+2);
1215            list = draw_direct(bitmap, cliprect, list+2);
12211216            break;
12221217         case 3:
12231218            LOG_TGP(("VIDEO:   viewport (%d, %d, %d, %d, %d, %d, %d)\n",
r32482r32483
12251220                     readi16(list+4), readi16(list+6), readi16(list+8),
12261221                     readi16(list+10), readi16(list+12), readi16(list+14)));
12271222
1228            draw_objects(state, bitmap, cliprect);
1223            draw_objects(bitmap, cliprect);
12291224
12301225            view->xc = readi16(list+4);
12311226            view->yc = 383-(readi16(list+6)-39);
r32482r32483
12441239            int i;
12451240            LOG_TGP(("ZVIDEO:   color write, adr=%x, len=%x\n", adr, len));
12461241            for(i=0; i<len; i++)
1247               state->m_tgp_ram[adr-0x40000+i] = list[6+2*i];
1242               m_tgp_ram[adr-0x40000+i] = list[6+2*i];
12481243            list += 6+len*2;
12491244            break;
12501245         }
r32482r32483
12551250               int i;
12561251               for(i=0;i<len;++i)
12571252               {
1258                  state->m_poly_ram[adr-0x800000+i]=readi(list+2*i+6);
1253                  m_poly_ram[adr-0x800000+i]=readi(list+2*i+6);
12591254               }
12601255               list+=6+len*2;
12611256            }
r32482r32483
13321327         }
13331328      }
13341329   end:
1335      draw_objects(state, bitmap, cliprect);
1330      draw_objects(bitmap, cliprect);
13361331   }
13371332}
13381333
1339static void tgp_scan(running_machine &machine)
1334void model1_state::tgp_scan()
13401335{
1341   model1_state *state = machine.driver_data<model1_state>();
1342   struct view *view = state->m_view;
1336   struct view *view = m_view;
13431337#if 0
1344   if (machine.input().code_pressed_once(KEYCODE_F))
1338   if (machine().input().code_pressed_once(KEYCODE_F))
13451339      {
13461340      FILE *fp;
13471341      fp=fopen("tgp-ram.bin", "w+b");
13481342      if (fp)
13491343            {
1350         fwrite(state->m_tgp_ram, (0x100000-0x40000)*2, 1, fp);
1344         fwrite(m_tgp_ram, (0x100000-0x40000)*2, 1, fp);
13511345         fclose(fp);
13521346            }
13531347      exit(0);
13541348      }
13551349#endif
1356   if(!state->m_render_done && (state->m_listctl[1] & 0x1f) == 0x1f) {
1357      UINT16 *list = get_list(state);
1350   if(!m_render_done && (m_listctl[1] & 0x1f) == 0x1f) {
1351      UINT16 *list = get_list();
13581352      // Skip everything but the data uploads
1359      LOG_TGP(("VIDEO: scan list %d\n", get_list_number(state)));
1353      LOG_TGP(("VIDEO: scan list %d\n", get_list_number()));
13601354      for(;;) {
13611355         int type = (list[1]<<16)|list[0];
13621356         switch(type) {
r32482r32483
13781372            int i;
13791373            LOG_TGP(("ZVIDEO:   scan color write, adr=%x, len=%x\n", adr, len));
13801374            for(i=0; i<len; i++)
1381               state->m_tgp_ram[adr-0x40000+i] = list[6+2*i];
1375               m_tgp_ram[adr-0x40000+i] = list[6+2*i];
13821376            list += 6+len*2;
13831377            break;
13841378         }
r32482r32483
13891383               int i;
13901384               for(i=0;i<len;++i)
13911385               {
1392                  state->m_poly_ram[adr-0x800000+i]=readi(list+2*i+6);
1386                  m_poly_ram[adr-0x800000+i]=readi(list+2*i+6);
13931387               }
13941388               list+=6+len*2;
13951389            }
r32482r32483
14401434   end:
14411435      ;
14421436   }
1443   state->m_render_done = 0;
1437   m_render_done = 0;
14441438}
14451439
14461440VIDEO_START_MEMBER(model1_state,model1)
r32482r32483
15211515   tile->draw(screen, bitmap, cliprect, 2, 0, 0);
15221516   tile->draw(screen, bitmap, cliprect, 0, 0, 0);
15231517
1524   tgp_render(machine(), bitmap, cliprect);
1518   tgp_render(bitmap, cliprect);
15251519
15261520   tile->draw(screen, bitmap, cliprect, 7, 0, 0);
15271521   tile->draw(screen, bitmap, cliprect, 5, 0, 0);
r32482r32483
15361530   // on rising edge
15371531   if (state)
15381532   {
1539      tgp_scan(machine());
1540      end_frame(machine());
1533      tgp_scan();
1534      end_frame();
15411535      LOG_TGP(("TGP: vsync\n"));
15421536   }
15431537}

Previous 199869 Revisions Next


© 1997-2024 The MAME Team