Previous 199869 Revisions Next

r29618 Sunday 13th April, 2014 at 19:32:24 UTC by Fabio Priuli
moved more model3 code into the driver class. nw.
[src/mame/drivers]model3.c
[src/mame/includes]model3.h
[src/mame/machine]model3.c
[src/mame/video]model3.c

trunk/src/mame/machine/model3.c
r29617r29618
1919 * 167 of the 3D-RAM manual.
2020 */
2121
22#define NEXT(new_state) fsm[state->m_tap_state][new_state]
22#define NEXT(new_state) fsm[m_tap_state][new_state]
2323
2424static const INT32 fsm[][2] = {
2525                     {  1,  0 },  // 0  Test-Logic/Reset
r29617r29618
6464 * Inserts a 32-bit ID code into the ID bit field.
6565 */
6666
67static void insert_id(model3_state *state, UINT32 id, INT32 start_bit)
67void model3_state::insert_id(UINT32 id, INT32 start_bit)
6868{
69   INT32 i;
70
71   for (i = 31; i >= 0; i--)
72      insert_bit(state->m_id_data, start_bit++, (id >> i) & 1);
69   for (int i = 31; i >= 0; i--)
70      insert_bit(m_id_data, start_bit++, (id >> i) & 1);
7371}
7472
7573/*
r29617r29618
122120 *      TDO.
123121 */
124122
125int model3_tap_read(running_machine &machine)
123int model3_state::tap_read()
126124{
127   model3_state *state = machine.driver_data<model3_state>();
128   return state->m_tdo;
125   return m_tdo;
129126}
130127
131128/*
r29617r29618
141138 *      trst = Reset.
142139 */
143140
144void model3_tap_write(running_machine &machine, int tck, int tms, int tdi, int trst)
141void model3_state::tap_write(int tck, int tms, int tdi, int trst)
145142{
146   model3_state *state = machine.driver_data<model3_state>();
147143   if (!tck)
148144      return;
149145
150   state->m_tap_state = NEXT(tms);
146   m_tap_state = NEXT(tms);
151147
152   switch (state->m_tap_state)
148   switch (m_tap_state)
153149   {
154150   case 3:     // Capture-DR
155151
r29617r29618
175171       * data on TAP reset and when the instruction is issued.
176172       */
177173
178      if (state->m_m3_step == 0x10)
174      if (m_m3_step == 0x10)
179175      {
180         insert_id(state, 0x116C7057, 1 + 0 * 32);
181         insert_id(state, 0x216C3057, 1 + 1 * 32);
182         insert_id(state, 0x116C4057, 1 + 2 * 32);
183         insert_id(state, 0x216C5057, 1 + 3 * 32);
184         insert_id(state, 0x116C6057, 1 + 4 * 32 + 1);
185         insert_id(state, 0x116C6057, 1 + 5 * 32 + 1);
176         insert_id(0x116C7057, 1 + 0 * 32);
177         insert_id(0x216C3057, 1 + 1 * 32);
178         insert_id(0x116C4057, 1 + 2 * 32);
179         insert_id(0x216C5057, 1 + 3 * 32);
180         insert_id(0x116C6057, 1 + 4 * 32 + 1);
181         insert_id(0x116C6057, 1 + 5 * 32 + 1);
186182      }
187      else if (state->m_m3_step == 0x15)
183      else if (m_m3_step == 0x15)
188184      {
189         insert_id(state, 0x316C7057, 1 + 0 * 32);
190         insert_id(state, 0x316C3057, 1 + 1 * 32);
191         insert_id(state, 0x216C4057, 1 + 2 * 32);      // Lost World may to use 0x016C4057
192         insert_id(state, 0x316C5057, 1 + 3 * 32);
193         insert_id(state, 0x216C6057, 1 + 4 * 32 + 1);
194         insert_id(state, 0x216C6057, 1 + 5 * 32 + 1);
185         insert_id(0x316C7057, 1 + 0 * 32);
186         insert_id(0x316C3057, 1 + 1 * 32);
187         insert_id(0x216C4057, 1 + 2 * 32);      // Lost World may to use 0x016C4057
188         insert_id(0x316C5057, 1 + 3 * 32);
189         insert_id(0x216C6057, 1 + 4 * 32 + 1);
190         insert_id(0x216C6057, 1 + 5 * 32 + 1);
195191      }
196      else if (state->m_m3_step >= 0x20)
192      else if (m_m3_step >= 0x20)
197193      {
198         insert_id(state, 0x416C7057, 1 + 0 * 32);
199         insert_id(state, 0x416C3057, 1 + 1 * 32);
200         insert_id(state, 0x316C4057, 1 + 2 * 32);
201         insert_id(state, 0x416C5057, 1 + 3 * 32);
202         insert_id(state, 0x316C6057, 1 + 4 * 32 + 1);
203         insert_id(state, 0x316C6057, 1 + 5 * 32 + 1);
194         insert_id(0x416C7057, 1 + 0 * 32);
195         insert_id(0x416C3057, 1 + 1 * 32);
196         insert_id(0x316C4057, 1 + 2 * 32);
197         insert_id(0x416C5057, 1 + 3 * 32);
198         insert_id(0x316C6057, 1 + 4 * 32 + 1);
199         insert_id(0x316C6057, 1 + 5 * 32 + 1);
204200      }
205201
206202      break;
207203
208204   case 4:     // Shift-DR
209205
210      state->m_tdo = shift(state->m_id_data, state->m_id_size);
206      m_tdo = shift(m_id_data, m_id_size);
211207      break;
212208
213209   case 10:    // Capture-IR
r29617r29618
216212       * Load lower 2 bits with 01 as per IEEE 1149.1-1990
217213       */
218214
219      state->m_ir = 1;
215      m_ir = 1;
220216      break;
221217
222218   case 11:    // Shift-IR
r29617r29618
225221       * Shift IR towards output and load in new data from TDI
226222       */
227223
228      state->m_tdo = state->m_ir & 1;   // shift LSB to output
229      state->m_ir >>= 1;
230      state->m_ir |= ((UINT64) tdi << 45);
224      m_tdo = m_ir & 1;   // shift LSB to output
225      m_ir >>= 1;
226      m_ir |= ((UINT64) tdi << 45);
231227      break;
232228
233229   case 15:    // Update-IR
r29617r29618
237233       * TCK)
238234       */
239235
240      state->m_ir &= U64(0x3fffffffffff);
236      m_ir &= U64(0x3fffffffffff);
241237      break;
242238
243239   default:
r29617r29618
252248 * Resets the TAP (simulating a power up or SCAN_RST signal.)
253249 */
254250
255void model3_tap_reset(running_machine &machine)
251void model3_state::tap_reset()
256252{
257   model3_state *state = machine.driver_data<model3_state>();
258   state->m_id_size = 197;  // 197 bits
259
260   state->m_tap_state = 0;  // test-logic/reset
253   m_id_size = 197;  // 197 bits
254   m_tap_state = 0;  // test-logic/reset
261255}
262256
263/*
264 * void model3_machine_init(int step)
265 *
266 * step = BCD hardware rev.  0x10 for 1.0, 0x15 for 1.5, 0x20 for 2.0, etc.
267 *
268 */
269
270void model3_machine_init(running_machine &machine, int step)
271{
272   model3_state *state = machine.driver_data<model3_state>();
273   state->m_m3_step = step;
274}
275
276257/*****************************************************************************/
277258/* Epson RTC-72421 */
278259
trunk/src/mame/includes/model3.h
r29617r29618
3131      m_dsbz80(*this, DSBZ80_TAG),
3232      m_soundram(*this, "soundram") { }
3333
34   struct TRIANGLE
35   {
36      poly_vertex v[3];
37      UINT8 texture_x, texture_y;
38      UINT8 texture_width, texture_height;
39      UINT8 transparency;
40      UINT8 texture_format, param;
41      int intensity;
42      UINT32 color;
43   };
44     
3445   required_device<cpu_device> m_maincpu;
3546   optional_device<lsi53c810_device> m_lsi53c810;
3647   required_device<cpu_device> m_audiocpu;
r29617r29618
219230   LSI53C810_IRQ_CB(scsi_irq_callback);
220231   void update_irq_state();
221232   void set_irq_line(UINT8 bit, int line);
233   void model3_init(int step);
234   // video
235   void draw_tile_4bit(bitmap_ind16 &bitmap, int tx, int ty, int tilenum);
236   void draw_tile_8bit(bitmap_ind16 &bitmap, int tx, int ty, int tilenum);
237   void draw_layer(bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int bitdepth);
238   void invalidate_texture(int page, int texx, int texy, int texwidth, int texheight);
239   cached_texture *get_texture(int page, int texx, int texy, int texwidth, int texheight, int format);
240   inline void write_texture16(int xpos, int ypos, int width, int height, int page, UINT16 *data);
241   void real3d_upload_texture(UINT32 header, UINT32 *data);
242   void init_matrix_stack();
243   void get_top_matrix(MATRIX *out);
244   void push_matrix_stack();
245   void pop_matrix_stack();
246   void multiply_matrix_stack(MATRIX matrix);
247   void translate_matrix_stack(float x, float y, float z);
248   void render_one(TRIANGLE *tri);
249   void draw_model(UINT32 addr);
250   UINT32 *get_memory_pointer(UINT32 address);
251   void load_matrix(int matrix_num, MATRIX *out);
252   void traverse_list4(int lod_num, UINT32 address);
253   void traverse_list(UINT32 address);
254   inline void process_link(UINT32 address, UINT32 link);
255   void draw_block(UINT32 address);
256   void draw_viewport(int pri, UINT32 address);
257   void real3d_traverse_display_list();
258#ifdef UNUSED_FUNCTION
259   inline void write_texture8(int xpos, int ypos, int width, int height, int page, UINT16 *data);
260   void draw_texture_sheet(bitmap_ind16 &bitmap, const rectangle &cliprect);
261   void copy_screen(bitmap_ind16 &bitmap, const rectangle &cliprect);
262#endif
222263   void real3d_display_list_end();
223264   void real3d_display_list1_dma(UINT32 src, UINT32 dst, int length, int byteswap);
224265   void real3d_display_list2_dma(UINT32 src, UINT32 dst, int length, int byteswap);
225266   void real3d_vrom_texture_dma(UINT32 src, UINT32 dst, int length, int byteswap);
226267   void real3d_texture_fifo_dma(UINT32 src, int length, int byteswap);
227268   void real3d_polygon_ram_dma(UINT32 src, UINT32 dst, int length, int byteswap);
269   // machine
270   void insert_id(UINT32 id, INT32 start_bit);
271   int tap_read();
272   void tap_write(int tck, int tms, int tdi, int trst);
273   void tap_reset();
228274};
229
230/*----------- defined in machine/model3.c -----------*/
231
232void model3_machine_init(running_machine &machine, int step);
233int model3_tap_read(running_machine &machine);
234void model3_tap_write(running_machine &machine, int tck, int tms, int tdi, int trst);
235void model3_tap_reset(running_machine &machine);
236
trunk/src/mame/video/model3.c
r29617r29618
99#define pv  p[2]
1010
1111
12
13
14
15struct TRIANGLE
16{
17   poly_vertex v[3];
18   UINT8 texture_x, texture_y;
19   UINT8 texture_width, texture_height;
20   UINT8 transparency;
21   UINT8 texture_format, param;
22   int intensity;
23   UINT32 color;
24};
25
2612struct cached_texture
2713{
2814   cached_texture *next;
r29617r29618
5238#define MAX_TRIANGLES       131072
5339
5440
55/* forward declarations */
56static void real3d_traverse_display_list(running_machine &machine);
57static void draw_model(running_machine &machine, UINT32 addr);
58static void init_matrix_stack(running_machine &machine);
59static void get_top_matrix(model3_state *state, MATRIX *out);
60static void push_matrix_stack(model3_state *state);
61static void pop_matrix_stack(model3_state *state);
62static void multiply_matrix_stack(model3_state *state, MATRIX matrix);
63static void translate_matrix_stack(model3_state *state, float x, float y, float z);
64static void traverse_list(running_machine &machine, UINT32 address);
65static void draw_block(running_machine &machine, UINT32 address);
66static void draw_viewport(running_machine &machine, int pri, UINT32 address);
67static void invalidate_texture(running_machine &machine, int page, int texx, int texy, int texwidth, int texheight);
68
6941/*****************************************************************************/
7042
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
8843/* matrix stack */
8944#define MATRIX_STACK_SIZE   256
9045
r29617r29618
10762
10863void model3_state::model3_exit()
10964{
110   invalidate_texture(machine(), 0, 0, 0, 6, 5);
111   invalidate_texture(machine(), 1, 0, 0, 6, 5);
65   invalidate_texture(0, 0, 0, 6, 5);
66   invalidate_texture(1, 0, 0, 6, 5);
11267   poly_free(m_poly);
11368}
11469
r29617r29618
148103   m_viewport_region_width = 496;
149104   m_viewport_region_height = 384;
150105
151   init_matrix_stack(machine());
106   init_matrix_stack();
152107}
153108
154static void draw_tile_4bit(running_machine &machine, bitmap_ind16 &bitmap, int tx, int ty, int tilenum)
109void model3_state::draw_tile_4bit(bitmap_ind16 &bitmap, int tx, int ty, int tilenum)
155110{
156   model3_state *state = machine.driver_data<model3_state>();
157111   int x, y;
158   UINT8 *tile_base = (UINT8*)state->m_m3_char_ram;
112   UINT8 *tile_base = (UINT8*)m_m3_char_ram;
159113   UINT8 *tile;
160114
161115   int data = (BYTE_REVERSE16(tilenum));
r29617r29618
172126         UINT16 pix0, pix1;
173127         tile0 = *tile >> 4;
174128         tile1 = *tile & 0xf;
175         pix0 = state->m_pal_lookup[c + tile0];
176         pix1 = state->m_pal_lookup[c + tile1];
129         pix0 = m_pal_lookup[c + tile0];
130         pix1 = m_pal_lookup[c + tile1];
177131         if((pix0 & 0x8000) == 0)
178132         {
179133            d[x+0] = pix0;
r29617r29618
187141   }
188142}
189143
190static void draw_tile_8bit(running_machine &machine, bitmap_ind16 &bitmap, int tx, int ty, int tilenum)
144void model3_state::draw_tile_8bit(bitmap_ind16 &bitmap, int tx, int ty, int tilenum)
191145{
192   model3_state *state = machine.driver_data<model3_state>();
193146   int x, y;
194   UINT8 *tile_base = (UINT8*)state->m_m3_char_ram;
147   UINT8 *tile_base = (UINT8*)m_m3_char_ram;
195148   UINT8 *tile;
196149
197150   int data = (BYTE_REVERSE16(tilenum));
r29617r29618
208161         UINT8 tile0;
209162         UINT16 pix;
210163         tile0 = tile[xx^4];
211         pix = state->m_pal_lookup[c + tile0];
164         pix = m_pal_lookup[c + tile0];
212165         if((pix & 0x8000) == 0)
213166         {
214167            d[x] = pix;
r29617r29618
219172   }
220173}
221174#ifdef UNUSED_FUNCTION
222static void draw_texture_sheet(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect)
175void model3_state::draw_texture_sheet(bitmap_ind16 &bitmap, const rectangle &cliprect)
223176{
224   model3_state *state = machine.driver_data<model3_state>();
225177   int x,y;
226178   for(y = cliprect.min_y; y <= cliprect.max_y; y++)
227179   {
228180      UINT16 *d = &bitmap.pix16(y);
229181      int index = (y*2)*2048;
230182      for(x = cliprect.min_x; x <= cliprect.max_x; x++) {
231         UINT16 pix = state->m_texture_ram[0][index];
183         UINT16 pix = m_texture_ram[0][index];
232184         index+=4;
233185         if(pix != 0) {
234186            d[x] = pix;
r29617r29618
238190}
239191#endif
240192
241static void draw_layer(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int bitdepth)
193void model3_state::draw_layer(bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int bitdepth)
242194{
243   model3_state *state = machine.driver_data<model3_state>();
244195   int x, y;
245196   int tile_index = 0;
246   UINT16 *tiles = (UINT16*)&state->m_m3_tile_ram[layer * 0x400];
197   UINT16 *tiles = (UINT16*)&m_m3_tile_ram[layer * 0x400];
247198
248199   //logerror("Layer %d: X: %d, Y: %d\n", layer, x1, y1);
249200
250201   if(layer > 1) {
251      int modr = (state->m_layer_modulate2 >> 8) & 0xff;
252      int modg = (state->m_layer_modulate2 >> 16) & 0xff;
253      int modb = (state->m_layer_modulate2 >> 24) & 0xff;
202      int modr = (m_layer_modulate2 >> 8) & 0xff;
203      int modg = (m_layer_modulate2 >> 16) & 0xff;
204      int modb = (m_layer_modulate2 >> 24) & 0xff;
254205      if(modr & 0x80) {
255         state->m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
206         m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
256207      } else {
257         state->m_layer_modulate_r = (modr & 0x7f) << 10;
208         m_layer_modulate_r = (modr & 0x7f) << 10;
258209      }
259210      if(modg & 0x80) {
260         state->m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
211         m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
261212      } else {
262         state->m_layer_modulate_g = (modr & 0x7f) << 5;
213         m_layer_modulate_g = (modr & 0x7f) << 5;
263214      }
264215      if(modb & 0x80) {
265         state->m_layer_modulate_b = -(0x7f - (modr & 0x7f));
216         m_layer_modulate_b = -(0x7f - (modr & 0x7f));
266217      } else {
267         state->m_layer_modulate_b = (modr & 0x7f);
218         m_layer_modulate_b = (modr & 0x7f);
268219      }
269220   } else {
270      int modr = (state->m_layer_modulate1 >> 8) & 0xff;
271      int modg = (state->m_layer_modulate1 >> 16) & 0xff;
272      int modb = (state->m_layer_modulate1 >> 24) & 0xff;
221      int modr = (m_layer_modulate1 >> 8) & 0xff;
222      int modg = (m_layer_modulate1 >> 16) & 0xff;
223      int modb = (m_layer_modulate1 >> 24) & 0xff;
273224      if(modr & 0x80) {
274         state->m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
225         m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
275226      } else {
276         state->m_layer_modulate_r = (modr & 0x7f) << 10;
227         m_layer_modulate_r = (modr & 0x7f) << 10;
277228      }
278229      if(modg & 0x80) {
279         state->m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
230         m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
280231      } else {
281         state->m_layer_modulate_g = (modr & 0x7f) << 5;
232         m_layer_modulate_g = (modr & 0x7f) << 5;
282233      }
283234      if(modb & 0x80) {
284         state->m_layer_modulate_b = -(0x7f - (modr & 0x7f));
235         m_layer_modulate_b = -(0x7f - (modr & 0x7f));
285236      } else {
286         state->m_layer_modulate_b = (modr & 0x7f);
237         m_layer_modulate_b = (modr & 0x7f);
287238      }
288239   }
289240
r29617r29618
294245         tile_index = ((y/8) * 64);
295246         for (x = cliprect.min_x; x <= cliprect.max_x; x+=8) {
296247            UINT16 tile = tiles[tile_index ^ 0x2];
297            draw_tile_4bit(machine, bitmap, x, y, tile);
248            draw_tile_4bit(bitmap, x, y, tile);
298249            ++tile_index;
299250         }
300251      }
r29617r29618
306257         tile_index = ((y/8) * 64);
307258         for (x = cliprect.min_x; x <= cliprect.max_x; x+=8) {
308259            UINT16 tile = tiles[tile_index ^ 0x2];
309            draw_tile_8bit(machine, bitmap, x, y, tile);
260            draw_tile_8bit(bitmap, x, y, tile);
310261            ++tile_index;
311262         }
312263      }
r29617r29618
314265}
315266
316267#ifdef UNUSED_FUNCTION
317static void copy_screen(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect)
268static void copy_screen(bitmap_ind16 &bitmap, const rectangle &cliprect)
318269{
319   model3_state *state = machine.driver_data<model3_state>();
320270   int x,y;
321271   for(y=cliprect.min_y; y <= cliprect.max_y; y++) {
322272      UINT16 *d = &bitmap.pix16(y);
323      UINT16 *s = &state->m_bitmap3d.pix16(y);
273      UINT16 *s = &m_bitmap3d.pix16(y);
324274      for(x=cliprect.min_x; x <= cliprect.max_x; x++) {
325275         UINT16 pix = s[x];
326276         if(!(pix & 0x8000)) {
r29617r29618
374324   bitmap.fill(0, cliprect);
375325
376326   if (!(m_debug_layer_disable & 0x8))
377      draw_layer(machine(), bitmap, cliprect, 3, (m_layer_enable >> 3) & 0x1);
327      draw_layer(bitmap, cliprect, 3, (m_layer_enable >> 3) & 0x1);
378328
379329   if (!(m_debug_layer_disable & 0x4))
380      draw_layer(machine(), bitmap, cliprect, 2, (m_layer_enable >> 2) & 0x1);
330      draw_layer(bitmap, cliprect, 2, (m_layer_enable >> 2) & 0x1);
381331
382332   if( !(m_debug_layer_disable & 0x10) )
383333   {
r29617r29618
385335      if(m_real3d_display_list) {
386336         m_zbuffer.fill(0, cliprect);
387337         m_bitmap3d.fill(0x8000, cliprect);
388         real3d_traverse_display_list(machine());
338         real3d_traverse_display_list();
389339      }
390340#endif
391341      copybitmap_trans(bitmap, m_bitmap3d, 0, 0, 0, 0, cliprect, 0x8000);
392342   }
393343
394344   if (!(m_debug_layer_disable & 0x2))
395      draw_layer(machine(), bitmap, cliprect, 1, (m_layer_enable >> 1) & 0x1);
345      draw_layer(bitmap, cliprect, 1, (m_layer_enable >> 1) & 0x1);
396346
397347   if (!(m_debug_layer_disable & 0x1))
398      draw_layer(machine(), bitmap, cliprect, 0, (m_layer_enable >> 0) & 0x1);
348      draw_layer(bitmap, cliprect, 0, (m_layer_enable >> 0) & 0x1);
399349
400350   //copy_screen(bitmap, cliprect);
401351
r29617r29618
495445        1024 pixels / 32 pixel resolution vertically
496446        2048 pixels / 32 pixel resolution horizontally
497447*/
498static void invalidate_texture(running_machine &machine, int page, int texx, int texy, int texwidth, int texheight)
448void model3_state::invalidate_texture(int page, int texx, int texy, int texwidth, int texheight)
499449{
500   model3_state *state = machine.driver_data<model3_state>();
501450   int wtiles = 1 << texwidth;
502451   int htiles = 1 << texheight;
503   int x, y;
504452
505   for (y = 0; y < htiles; y++)
506      for (x = 0; x < wtiles; x++)
507         while (state->m_texcache[page][texy + y][texx + x] != NULL)
453   for (int y = 0; y < htiles; y++)
454      for (int x = 0; x < wtiles; x++)
455         while (m_texcache[page][texy + y][texx + x] != NULL)
508456         {
509            cached_texture *freeme = state->m_texcache[page][texy + y][texx + x];
510            state->m_texcache[page][texy + y][texx + x] = freeme->next;
511            auto_free(machine, freeme);
457            cached_texture *freeme = m_texcache[page][texy + y][texx + x];
458            m_texcache[page][texy + y][texx + x] = freeme->next;
459            auto_free(machine(), freeme);
512460         }
513461}
514462
515static cached_texture *get_texture(running_machine &machine, int page, int texx, int texy, int texwidth, int texheight, int format)
463cached_texture *model3_state::get_texture(int page, int texx, int texy, int texwidth, int texheight, int format)
516464{
517   model3_state *state = machine.driver_data<model3_state>();
518   cached_texture *tex = state->m_texcache[page][texy][texx];
465   cached_texture *tex = m_texcache[page][texy][texx];
519466   int pixheight = 32 << texheight;
520467   int pixwidth = 32 << texwidth;
521468   UINT32 alpha = ~0;
522469   int x, y;
523470
524471   /* if we have one already, validate it */
525   for (tex = state->m_texcache[page][texy][texx]; tex != NULL; tex = tex->next)
472   for (tex = m_texcache[page][texy][texx]; tex != NULL; tex = tex->next)
526473      if (tex->width == texwidth && tex->height == texheight && tex->format == format)
527474         return tex;
528475
529476   /* create a new texture */
530   tex = (cached_texture *)auto_alloc_array(machine, UINT8, sizeof(cached_texture) + (2 * pixwidth * 2 * pixheight) * sizeof(rgb_t));
477   tex = (cached_texture *)auto_alloc_array(machine(), UINT8, sizeof(cached_texture) + (2 * pixwidth * 2 * pixheight) * sizeof(rgb_t));
531478   tex->width = texwidth;
532479   tex->height = texheight;
533480   tex->format = format;
534481
535482   /* set the new texture */
536   tex->next = state->m_texcache[page][texy][texx];
537   state->m_texcache[page][texy][texx] = tex;
483   tex->next = m_texcache[page][texy][texx];
484   m_texcache[page][texy][texx] = tex;
538485
539486   /* decode it */
540487   for (y = 0; y < pixheight; y++)
541488   {
542      const UINT16 *texsrc = &state->m_texture_ram[page][(texy * 32 + y) * 2048 + texx * 32];
489      const UINT16 *texsrc = &m_texture_ram[page][(texy * 32 + y) * 2048 + texx * 32];
543490      rgb_t *dest = tex->data + 2 * pixwidth * y;
544491
545492      switch (format)
r29617r29618
660607   50, 51, 54, 55, 58, 59, 62, 63
661608};
662609
663INLINE void write_texture16(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data)
610inline void model3_state::write_texture16(int xpos, int ypos, int width, int height, int page, UINT16 *data)
664611{
665612   int x,y,i,j;
666613
r29617r29618
668615   {
669616      for(x=xpos; x < xpos+width; x+=8)
670617      {
671         UINT16 *texture = &state->m_texture_ram[page][y*2048+x];
618         UINT16 *texture = &m_texture_ram[page][y*2048+x];
672619         int b = 0;
673620         for(j=y; j < y+8; j++) {
674621            for(i=x; i < x+8; i++) {
r29617r29618
683630}
684631
685632#ifdef UNUSED_FUNCTION
686INLINE void write_texture8(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data)
633inline void model3_state::write_texture8(int xpos, int ypos, int width, int height, int page, UINT16 *data)
687634{
688635   int x,y,i,j;
689636   UINT16 color = 0x7c00;
r29617r29618
692639   {
693640      for(x=xpos; x < xpos+width; x+=8)
694641      {
695         UINT16 *texture = &state->m_texture_ram[page][y*2048+x];
642         UINT16 *texture = &m_texture_ram[page][y*2048+x];
696643         for(j=y; j < y+4; j++) {
697644            for(i=x; i < x+8; i++) {
698645               *texture = color;
r29617r29618
705652}
706653#endif
707654
708static void real3d_upload_texture(running_machine &machine, UINT32 header, UINT32 *data)
655void model3_state::real3d_upload_texture(UINT32 header, UINT32 *data)
709656{
710   model3_state *state = machine.driver_data<model3_state>();
711657   int width   = 32 << ((header >> 14) & 0x7);
712658   int height  = 32 << ((header >> 17) & 0x7);
713659   int xpos    = (header & 0x3f) * 32;
r29617r29618
719665   {
720666      case 0x00:      /* Texture with mipmaps */
721667         //if(bitdepth) {
722            write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data);
723            invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
668            write_texture16(xpos, ypos, width, height, page, (UINT16*)data);
669            invalidate_texture(page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
724670         //} else {
725671            /* TODO: 8-bit textures are weird. need to figure out some additional bits */
726672            //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header);
r29617r29618
729675         break;
730676      case 0x01:      /* Texture without mipmaps */
731677         //if(bitdepth) {
732            write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data);
733            invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
678            write_texture16(xpos, ypos, width, height, page, (UINT16*)data);
679            invalidate_texture(page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
734680         //} else {
735681            /* TODO: 8-bit textures are weird. need to figure out some additional bits */
736682            //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header);
r29617r29618
757703      {
758704         int length = (m_texture_fifo[i] / 2) + 2;
759705         UINT32 header = m_texture_fifo[i+1];
760         real3d_upload_texture(machine(), header, &m_texture_fifo[i+2]);
706         real3d_upload_texture(header, &m_texture_fifo[i+2]);
761707         i += length;
762708      };
763709   }
764710   m_texture_fifo_pos = 0;
765711   m_zbuffer.fill(0);
766712   m_bitmap3d.fill(0x8000);
767   real3d_traverse_display_list(machine());
768   //state->m_real3d_display_list = 1;
713   real3d_traverse_display_list();
714   //m_real3d_display_list = 1;
769715}
770716
771717void model3_state::real3d_display_list1_dma(UINT32 src, UINT32 dst, int length, int byteswap)
r29617r29618
815761         address = space.read_dword((src+0));
816762         header = space.read_dword((src+4));
817763      }
818      real3d_upload_texture(space.machine(), header, (UINT32*)&m_vrom[address]);
764      real3d_upload_texture(header, (UINT32*)&m_vrom[address]);
819765   }
820766}
821767
r29617r29618
897843   memcpy(out, &tmp, sizeof(MATRIX));
898844}
899845
900static void init_matrix_stack(running_machine &machine)
846void model3_state::init_matrix_stack()
901847{
902   model3_state *state = machine.driver_data<model3_state>();
903848   MATRIX *matrix_stack;
904   matrix_stack = state->m_matrix_stack = auto_alloc_array_clear(machine, MATRIX, MATRIX_STACK_SIZE);
849   matrix_stack = m_matrix_stack = auto_alloc_array_clear(machine(), MATRIX, MATRIX_STACK_SIZE);
905850
906851   /* initialize the first matrix as identity */
907852   matrix_stack[0][0][0] = 1.0f;
r29617r29618
921866   matrix_stack[0][3][2] = 0.0f;
922867   matrix_stack[0][3][3] = 1.0f;
923868
924   state->m_matrix_stack_ptr = 0;
869   m_matrix_stack_ptr = 0;
925870}
926871
927static void get_top_matrix(model3_state *state, MATRIX *out)
872void model3_state::get_top_matrix(MATRIX *out)
928873{
929   memcpy( out, &state->m_matrix_stack[state->m_matrix_stack_ptr], sizeof(MATRIX));
874   memcpy(out, &m_matrix_stack[m_matrix_stack_ptr], sizeof(MATRIX));
930875}
931876
932static void push_matrix_stack(model3_state *state)
877void model3_state::push_matrix_stack()
933878{
934   state->m_matrix_stack_ptr++;
935   if (state->m_matrix_stack_ptr >= MATRIX_STACK_SIZE)
879   m_matrix_stack_ptr++;
880   if (m_matrix_stack_ptr >= MATRIX_STACK_SIZE)
936881      fatalerror("push_matrix_stack: matrix stack overflow\n");
937882
938   memcpy( &state->m_matrix_stack[state->m_matrix_stack_ptr], &state->m_matrix_stack[state->m_matrix_stack_ptr-1], sizeof(MATRIX));
883   memcpy(&m_matrix_stack[m_matrix_stack_ptr], &m_matrix_stack[m_matrix_stack_ptr - 1], sizeof(MATRIX));
939884}
940885
941static void pop_matrix_stack(model3_state *state)
886void model3_state::pop_matrix_stack()
942887{
943   state->m_matrix_stack_ptr--;
944   if (state->m_matrix_stack_ptr < 0)
888   m_matrix_stack_ptr--;
889   if (m_matrix_stack_ptr < 0)
945890      fatalerror("pop_matrix_stack: matrix stack underflow\n");
946891}
947892
948static void multiply_matrix_stack(model3_state *state, MATRIX matrix)
893void model3_state::multiply_matrix_stack(MATRIX matrix)
949894{
950   matrix_multiply(matrix, state->m_matrix_stack[state->m_matrix_stack_ptr], &state->m_matrix_stack[state->m_matrix_stack_ptr]);
895   matrix_multiply(matrix, m_matrix_stack[m_matrix_stack_ptr], &m_matrix_stack[m_matrix_stack_ptr]);
951896}
952897
953static void translate_matrix_stack(model3_state *state, float x, float y, float z)
898void model3_state::translate_matrix_stack(float x, float y, float z)
954899{
955900   MATRIX tm;
956901
r29617r29618
959904   tm[2][0] = 0.0f;    tm[2][1] = 0.0f;    tm[2][2] = 1.0f;    tm[2][3] = 0.0f;
960905   tm[3][0] = x;       tm[3][1] = y;       tm[3][2] = z;       tm[3][3] = 1.0f;
961906
962   matrix_multiply(tm, state->m_matrix_stack[state->m_matrix_stack_ptr], &state->m_matrix_stack[state->m_matrix_stack_ptr]);
907   matrix_multiply(tm, m_matrix_stack[m_matrix_stack_ptr], &m_matrix_stack[m_matrix_stack_ptr]);
963908}
964909
965910/*****************************************************************************/
r29617r29618
1037982   return clip_verts;
1038983}
1039984
1040static void render_one(running_machine &machine, TRIANGLE *tri)
985void model3_state::render_one(TRIANGLE *tri)
1041986{
1042   model3_state *state = machine.driver_data<model3_state>();
1043   poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(state->m_poly);
987   poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(m_poly);
1044988   poly_draw_scanline_func callback = NULL;
1045989
1046990   tri->v[0].pz = 1.0f / tri->v[0].pz;
1047991   tri->v[1].pz = 1.0f / tri->v[1].pz;
1048992   tri->v[2].pz = 1.0f / tri->v[2].pz;
1049993
1050   extra->zbuffer = &state->m_zbuffer;
994   extra->zbuffer = &m_zbuffer;
1051995   if (tri->param & TRI_PARAM_TEXTURE_ENABLE)
1052996   {
1053997      tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * 256.0f;
r29617r29618
10571001      tri->v[2].pu = tri->v[2].pu * tri->v[2].pz * 256.0f;
10581002      tri->v[2].pv = tri->v[2].pv * tri->v[2].pz * 256.0f;
10591003
1060      extra->texture = get_texture(machine, (tri->param & TRI_PARAM_TEXTURE_PAGE) ? 1 : 0, tri->texture_x, tri->texture_y, tri->texture_width, tri->texture_height, tri->texture_format);
1004      extra->texture = get_texture((tri->param & TRI_PARAM_TEXTURE_PAGE) ? 1 : 0, tri->texture_x, tri->texture_y, tri->texture_width, tri->texture_height, tri->texture_format);
10611005      extra->texture_param        = tri->param;
10621006      extra->polygon_transparency = tri->transparency;
10631007      extra->polygon_intensity    = tri->intensity;
r29617r29618
10681012         callback = (tri->transparency >= 32) ? draw_scanline_normal : draw_scanline_trans;
10691013      else
10701014         callback = draw_scanline_alpha;
1071      poly_render_triangle(state->m_poly, &state->m_bitmap3d, state->m_clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]);
1015      poly_render_triangle(m_poly, &m_bitmap3d, m_clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]);
10721016   }
10731017   else
10741018   {
r29617r29618
10761020      extra->polygon_intensity    = tri->intensity;
10771021      extra->color                = tri->color;
10781022
1079      poly_render_triangle(state->m_poly, &state->m_bitmap3d, state->m_clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]);
1023      poly_render_triangle(m_poly, &m_bitmap3d, m_clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]);
10801024   }
10811025}
10821026
1083static void draw_model(running_machine &machine, UINT32 addr)
1027void model3_state::draw_model(UINT32 addr)
10841028{
1085   model3_state *state = machine.driver_data<model3_state>();
1086   UINT32 *model = (addr >= 0x100000) ? &state->m_vrom[addr] :  &state->m_polygon_ram[addr];
1029   UINT32 *model = (addr >= 0x100000) ? &m_vrom[addr] :  &m_polygon_ram[addr];
10871030   UINT32 header[7];
10881031   int index = 0;
10891032   int last_polygon = FALSE, first_polygon = TRUE, back_face = FALSE;
r29617r29618
10971040   MATRIX transform_matrix;
10981041   float center_x, center_y;
10991042
1100   if(state->m_step < 0x15) {  /* position coordinates are 17.15 fixed-point in Step 1.0 */
1043   if(m_step < 0x15) {  /* position coordinates are 17.15 fixed-point in Step 1.0 */
11011044      fixed_point_fraction = 1.0f / 32768.0f;
11021045   } else {                    /* 13.19 fixed-point in other Steps */
11031046      fixed_point_fraction = 1.0f / 524288.0f;
11041047   }
11051048
1106   get_top_matrix(state, &transform_matrix);
1049   get_top_matrix(&transform_matrix);
11071050
11081051   /* current viewport center coordinates on screen */
1109   center_x = (float)(state->m_viewport_region_x + (state->m_viewport_region_width / 2));
1110   center_y = (float)(state->m_viewport_region_y + (state->m_viewport_region_height / 2));
1052   center_x = (float)(m_viewport_region_x + (m_viewport_region_width / 2));
1053   center_y = (float)(m_viewport_region_y + (m_viewport_region_height / 2));
11111054
11121055   memset(prev_vertex, 0, sizeof(prev_vertex));
11131056
r29617r29618
12241167            (normal[1] * transform_matrix[1][2]) +
12251168            (normal[2] * transform_matrix[2][2]);
12261169
1227      sn[0] *= state->m_coordinate_system[0][1];
1228      sn[1] *= state->m_coordinate_system[1][2];
1229      sn[2] *= state->m_coordinate_system[2][0];
1170      sn[0] *= m_coordinate_system[0][1];
1171      sn[1] *= m_coordinate_system[1][2];
1172      sn[2] *= m_coordinate_system[2][0];
12301173
12311174      /* TODO: depth bias */
12321175      /* transform vertices */
r29617r29618
12431186         matrix_multiply_vector(transform_matrix, vect, &p[i]);
12441187
12451188         /* apply coordinate system */
1246         clip_vert[i].x = p[i][0] * state->m_coordinate_system[0][1];
1247         clip_vert[i].y = p[i][1] * state->m_coordinate_system[1][2];
1248         clip_vert[i].pz = p[i][2] * state->m_coordinate_system[2][0];
1189         clip_vert[i].x = p[i][0] * m_coordinate_system[0][1];
1190         clip_vert[i].y = p[i][1] * m_coordinate_system[1][2];
1191         clip_vert[i].pz = p[i][2] * m_coordinate_system[2][0];
12491192         clip_vert[i].pu = vertex[i].pu * texture_coord_scale;
12501193         clip_vert[i].pv = vertex[i].pv * texture_coord_scale;
12511194      }
12521195
12531196      /* clip against view frustum */
1254      num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[0], clip_vert);
1255      num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[1], clip_vert);
1256      num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[2], clip_vert);
1257      num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[3], clip_vert);
1258      num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[4], clip_vert);
1197      num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[0], clip_vert);
1198      num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[1], clip_vert);
1199      num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[2], clip_vert);
1200      num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[3], clip_vert);
1201      num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[4], clip_vert);
12591202
12601203      /* backface culling */
12611204      if( (header[6] & 0x800000) && (!(header[1] & 0x0010)) ) {
r29617r29618
12711214         /* homogeneous Z-divide, screen-space transformation */
12721215         for(i=0; i < num_vertices; i++) {
12731216            float ooz = 1.0f / clip_vert[i].pz;
1274            clip_vert[i].x = ((clip_vert[i].x * ooz) * state->m_viewport_focal_length) + center_x;
1275            clip_vert[i].y = ((clip_vert[i].y * ooz) * state->m_viewport_focal_length) + center_y;
1217            clip_vert[i].x = ((clip_vert[i].x * ooz) * m_viewport_focal_length) + center_x;
1218            clip_vert[i].y = ((clip_vert[i].y * ooz) * m_viewport_focal_length) + center_y;
12761219         }
12771220
12781221         // lighting
12791222         if ((header[6] & 0x10000) == 0)
12801223         {
1281            dot = dot_product3(sn, state->m_parallel_light);
1282            intensity = ((dot * state->m_parallel_light_intensity) + state->m_ambient_light_intensity) * 256.0f;
1224            dot = dot_product3(sn, m_parallel_light);
1225            intensity = ((dot * m_parallel_light_intensity) + m_ambient_light_intensity) * 256.0f;
12831226            if (intensity > 256)
12841227            {
12851228               intensity = 256;
r29617r29618
13161259            tri.param   |= (header[2] & 0x1) ? TRI_PARAM_TEXTURE_MIRROR_V : 0;
13171260            tri.param   |= (header[6] & 0x80000000) ? TRI_PARAM_ALPHA_TEST : 0;
13181261
1319            render_one(machine, &tri);
1262            render_one(&tri);
13201263         }
13211264      }
13221265   }
r29617r29618
13261269/*****************************************************************************/
13271270/* display list parser */
13281271
1329static UINT32 *get_memory_pointer(model3_state *state, UINT32 address)
1272UINT32 *model3_state::get_memory_pointer(UINT32 address)
13301273{
13311274   if (address & 0x800000)
13321275   {
13331276      if (address >= 0x840000) {
13341277         fatalerror("get_memory_pointer: invalid display list memory address %08X\n", address);
13351278      }
1336      return &state->m_display_list_ram[address & 0x7fffff];
1279      return &m_display_list_ram[address & 0x7fffff];
13371280   }
13381281   else
13391282   {
13401283      if (address >= 0x100000) {
13411284         fatalerror("get_memory_pointer: invalid node ram address %08X\n", address);
13421285      }
1343      return &state->m_culling_ram[address];
1286      return &m_culling_ram[address];
13441287   }
13451288}
13461289
1347static void load_matrix(model3_state *state, int matrix_num, MATRIX *out)
1290void model3_state::load_matrix(int matrix_num, MATRIX *out)
13481291{
1349   float *matrix = (float *)get_memory_pointer(state, state->m_matrix_base_address + matrix_num * 12);
1292   float *matrix = (float *)get_memory_pointer(m_matrix_base_address + matrix_num * 12);
13501293
13511294   (*out)[0][0] = matrix[3];   (*out)[0][1] = matrix[6];   (*out)[0][2] = matrix[9];   (*out)[0][3] = 0.0f;
13521295   (*out)[1][0] = matrix[4];   (*out)[1][1] = matrix[7];   (*out)[1][2] = matrix[10];  (*out)[1][3] = 0.0f;
r29617r29618
13541297   (*out)[3][0] = matrix[0];   (*out)[3][1] = matrix[1];   (*out)[3][2] = matrix[2];   (*out)[3][3] = 1.0f;
13551298}
13561299
1357static void traverse_list4(running_machine &machine, int lod_num, UINT32 address)
1300void model3_state::traverse_list4(int lod_num, UINT32 address)
13581301{
1359   model3_state *state = machine.driver_data<model3_state>();
1360
13611302   /* does something with the LOD selection */
1362   UINT32 *list = get_memory_pointer(state, address);
1303   UINT32 *list = get_memory_pointer(address);
13631304   UINT32 link = list[0];
13641305
1365   draw_model(machine, link & 0xffffff);
1306   draw_model(link & 0xffffff);
13661307}
13671308
1368static void traverse_list(running_machine &machine, UINT32 address)
1309void model3_state::traverse_list(UINT32 address)
13691310{
1370   model3_state *state = machine.driver_data<model3_state>();
1371   UINT32 *list = get_memory_pointer(state, address);
1311   UINT32 *list = get_memory_pointer(address);
13721312   int list_ptr = 0;
13731313
1374   if (state->m_list_depth > 2)
1314   if (m_list_depth > 2)
13751315      return;
13761316
1377   state->m_list_depth++;
1317   m_list_depth++;
13781318
13791319   /* find the end of the list */
13801320   while (1)
r29617r29618
13951335      address = list[--list_ptr] & 0xffffff;
13961336      if (address != 0 && address != 0x800800)
13971337      //if (address != 0)
1398         draw_block(machine, address);
1338         draw_block(address);
13991339   }
14001340
1401   state->m_list_depth--;
1341   m_list_depth--;
14021342}
14031343
1404INLINE void process_link(running_machine &machine, UINT32 address, UINT32 link)
1344inline void model3_state::process_link(UINT32 address, UINT32 link)
14051345{
14061346   if (link != 0 && link != 0x0fffffff && link != 0x00800800 && link != 0x01000000)
14071347   {
14081348      switch (link >> 24)
14091349      {
14101350         case 0x00:      /* link to another node */
1411            draw_block(machine, link & 0xffffff);
1351            draw_block(link & 0xffffff);
14121352            break;
14131353
14141354         case 0x01:
14151355         case 0x03:      /* both of these link to models, is there any difference ? */
1416            draw_model(machine, link & 0xffffff);
1356            draw_model(link & 0xffffff);
14171357            break;
14181358
14191359         case 0x04:      /* list of links */
1420            traverse_list(machine, link & 0xffffff);
1360            traverse_list(link & 0xffffff);
14211361            break;
14221362
14231363         default:
r29617r29618
14271367   }
14281368}
14291369
1430static void draw_block(running_machine &machine, UINT32 address)
1370void model3_state::draw_block(UINT32 address)
14311371{
1432   model3_state *state = machine.driver_data<model3_state>();
1433   const UINT32 *node = get_memory_pointer(state, address);
1372   const UINT32 *node = get_memory_pointer(address);
14341373   UINT32 link;
14351374   int node_matrix;
14361375   float x, y, z;
14371376   MATRIX matrix;
14381377   int offset;
14391378
1440   offset = (state->m_step < 0x15) ? 2 : 0;
1379   offset = (m_step < 0x15) ? 2 : 0;
14411380   link = node[7 - offset];
14421381
14431382   /* apply matrix and translation */
14441383   node_matrix = node[3 - offset] & 0xfff;
1445   load_matrix(state, node_matrix, &matrix);
1384   load_matrix(node_matrix, &matrix);
14461385
1447   push_matrix_stack(state);
1386   push_matrix_stack();
14481387
14491388   if (node[0] & 0x10)
14501389   {
14511390      x = *(float *)&node[4 - offset];
14521391      y = *(float *)&node[5 - offset];
14531392      z = *(float *)&node[6 - offset];
1454      translate_matrix_stack(state, x, y, z);
1393      translate_matrix_stack(x, y, z);
14551394   }
14561395   else if (node_matrix != 0)
1457      multiply_matrix_stack(state, matrix);
1396      multiply_matrix_stack(matrix);
14581397
14591398   /* bit 0x08 of word 0 indicates a pointer list */
14601399   if (node[0] & 0x08)
1461      traverse_list4(machine, (node[3 - offset] >> 12) & 0x7f, link & 0xffffff);
1400      traverse_list4((node[3 - offset] >> 12) & 0x7f, link & 0xffffff);
14621401   else
1463      process_link(machine, address, link);
1402      process_link(address, link);
14641403
1465   pop_matrix_stack(state);
1404   pop_matrix_stack();
14661405
14671406   /* handle the second link */
14681407   link = node[8 - offset];
1469   process_link(machine, address, link);
1408   process_link(address, link);
14701409}
14711410
1472static void draw_viewport(running_machine &machine, int pri, UINT32 address)
1411void model3_state::draw_viewport(int pri, UINT32 address)
14731412{
1474   model3_state *state = machine.driver_data<model3_state>();
1475   const UINT32 *node = get_memory_pointer(state, address);
1413   const UINT32 *node = get_memory_pointer(address);
14761414   UINT32 link_address;
14771415   float /*viewport_left, viewport_right, */viewport_top, viewport_bottom;
14781416   float /*fov_x,*/ fov_y;
r29617r29618
14841422   /* traverse to the link node before drawing this viewport */
14851423   /* check this is correct as this affects the rendering order */
14861424   if (link_address != 0x01000000)
1487      draw_viewport(machine, pri, link_address);
1425      draw_viewport(pri, link_address);
14881426
14891427   /* skip if this isn't the right priority */
14901428   if (pri != ((node[0] >> 3) & 3))
14911429      return;
14921430
14931431   /* set viewport parameters */
1494   state->m_viewport_region_x      = (node[26] & 0xffff) >> 4;         /* 12.4 fixed point */
1495   state->m_viewport_region_y      = ((node[26] >> 16) & 0xffff) >> 4;
1496   state->m_viewport_region_width  = (node[20] & 0xffff) >> 2;         /* 14.2 fixed point */
1497   state->m_viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2;
1432   m_viewport_region_x      = (node[26] & 0xffff) >> 4;         /* 12.4 fixed point */
1433   m_viewport_region_y      = ((node[26] >> 16) & 0xffff) >> 4;
1434   m_viewport_region_width  = (node[20] & 0xffff) >> 2;         /* 14.2 fixed point */
1435   m_viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2;
14981436
14991437   /* frustum plane angles */
15001438   //viewport_left         = RADIAN_TO_DEGREE(asin(*(float *)&node[12]));
r29617r29618
15031441   viewport_bottom         = RADIAN_TO_DEGREE(asin(*(float *)&node[18]));
15041442
15051443   /* build clipping planes */
1506   state->m_clip_plane[0].x = *(float *)&node[13]; state->m_clip_plane[0].y = 0.0f;        state->m_clip_plane[0].z = *(float *)&node[12]; state->m_clip_plane[0].d = 0.0f;
1507   state->m_clip_plane[1].x = *(float *)&node[17]; state->m_clip_plane[1].y = 0.0f;        state->m_clip_plane[1].z = *(float *)&node[16]; state->m_clip_plane[1].d = 0.0f;
1508   state->m_clip_plane[2].x = 0.0f;        state->m_clip_plane[2].y = *(float *)&node[15]; state->m_clip_plane[2].z = *(float *)&node[14]; state->m_clip_plane[2].d = 0.0f;
1509   state->m_clip_plane[3].x = 0.0f;        state->m_clip_plane[3].y = *(float *)&node[19]; state->m_clip_plane[3].z = *(float *)&node[18]; state->m_clip_plane[3].d = 0.0f;
1510   state->m_clip_plane[4].x = 0.0f;        state->m_clip_plane[4].y = 0.0f;        state->m_clip_plane[4].z = 1.0f;        state->m_clip_plane[4].d = 1.0f;
1444   m_clip_plane[0].x = *(float *)&node[13]; m_clip_plane[0].y = 0.0f;        m_clip_plane[0].z = *(float *)&node[12]; m_clip_plane[0].d = 0.0f;
1445   m_clip_plane[1].x = *(float *)&node[17]; m_clip_plane[1].y = 0.0f;        m_clip_plane[1].z = *(float *)&node[16]; m_clip_plane[1].d = 0.0f;
1446   m_clip_plane[2].x = 0.0f;        m_clip_plane[2].y = *(float *)&node[15]; m_clip_plane[2].z = *(float *)&node[14]; m_clip_plane[2].d = 0.0f;
1447   m_clip_plane[3].x = 0.0f;        m_clip_plane[3].y = *(float *)&node[19]; m_clip_plane[3].z = *(float *)&node[18]; m_clip_plane[3].d = 0.0f;
1448   m_clip_plane[4].x = 0.0f;        m_clip_plane[4].y = 0.0f;        m_clip_plane[4].z = 1.0f;        m_clip_plane[4].d = 1.0f;
15111449
15121450   /* compute field of view */
15131451   //fov_x = viewport_left + viewport_right;
15141452   fov_y = viewport_top + viewport_bottom;
1515   state->m_viewport_focal_length = (state->m_viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f );
1453   m_viewport_focal_length = (m_viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f );
15161454
1517   state->m_matrix_base_address = node[22];
1455   m_matrix_base_address = node[22];
15181456   /* TODO: where does node[23] point to ? LOD table ? */
15191457
15201458   /* set lighting parameters */
1521   state->m_parallel_light[0] = -*(float *)&node[5];
1522   state->m_parallel_light[1] = *(float *)&node[6];
1523   state->m_parallel_light[2] = *(float *)&node[4];
1524   state->m_parallel_light_intensity = *(float *)&node[7];
1525   state->m_ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f;
1459   m_parallel_light[0] = -*(float *)&node[5];
1460   m_parallel_light[1] = *(float *)&node[6];
1461   m_parallel_light[2] = *(float *)&node[4];
1462   m_parallel_light_intensity = *(float *)&node[7];
1463   m_ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f;
15261464
15271465   /* set coordinate system matrix */
1528   load_matrix(state, 0, &state->m_coordinate_system);
1466   load_matrix(0, &m_coordinate_system);
15291467
15301468   /* process a link */
1531   process_link(machine, link_address, node[2]);
1469   process_link(link_address, node[2]);
15321470}
15331471
15341472
1535static void real3d_traverse_display_list(running_machine &machine)
1473void model3_state::real3d_traverse_display_list()
15361474{
1537   model3_state *state = machine.driver_data<model3_state>();
1538   int pri;
1475   init_matrix_stack();
15391476
1540   init_matrix_stack(machine);
1477   for (int pri = 0; pri < 4; pri++)
1478      draw_viewport(pri, 0x800000);
15411479
1542   for (pri = 0; pri < 4; pri++)
1543      draw_viewport(machine, pri, 0x800000);
1544
1545   poly_wait(state->m_poly, "real3d_traverse_display_list");
1480   poly_wait(m_poly, "real3d_traverse_display_list");
15461481}
trunk/src/mame/drivers/model3.c
r29617r29618
12231223   m_sound_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(model3_state::model3_sound_timer_tick),this));
12241224}
12251225
1226static void model3_init(running_machine &machine, int step)
1226void model3_state::model3_init(int step)
12271227{
1228   model3_state *state = machine.driver_data<model3_state>();
1229   state->m_step = step;
1228   m_step = step;
12301229
1231   state->m_sound_irq_enable = 0;
1232   state->m_sound_timer->adjust(attotime::never);
1230   m_sound_irq_enable = 0;
1231   m_sound_timer->adjust(attotime::never);
12331232
1234   state->membank("bank1")->set_base(state->memregion( "user1" )->base() + 0x800000 ); /* banked CROM */
1233   membank("bank1")->set_base(memregion( "user1" )->base() + 0x800000 ); /* banked CROM */
12351234
1236   state->membank("bank4")->set_base(state->memregion("samples")->base() + 0x200000);
1237   state->membank("bank5")->set_base(state->memregion("samples")->base() + 0x600000);
1235   membank("bank4")->set_base(memregion("samples")->base() + 0x200000);
1236   membank("bank5")->set_base(memregion("samples")->base() + 0x600000);
12381237
12391238   // copy the 68k vector table into RAM
1240   memcpy(state->m_soundram, state->memregion("audiocpu")->base()+0x80000, 16);
1241   machine.device("audiocpu")->reset();
1239   memcpy(m_soundram, memregion("audiocpu")->base()+0x80000, 16);
1240   machine().device("audiocpu")->reset();
12421241
1243   model3_machine_init(machine, step); // step 1.5
1244   model3_tap_reset(machine);
1242   m_m3_step = step; // step = BCD hardware rev.  0x10 for 1.0, 0x15 for 1.5, 0x20 for 2.0, etc.
1243   tap_reset();
12451244
1246   if(step < 0x20) {
1247      if( core_stricmp(machine.system().name, "vs215") == 0 ||
1248         core_stricmp(machine.system().name, "vs29815") == 0 ||
1249         core_stricmp(machine.system().name, "bass") == 0 )
1245   if (step < 0x20) {
1246      if( core_stricmp(machine().system().name, "vs215") == 0 ||
1247         core_stricmp(machine().system().name, "vs29815") == 0 ||
1248         core_stricmp(machine().system().name, "bass") == 0 )
12501249      {
1251         mpc106_init(machine);
1250         mpc106_init(machine());
12521251      }
12531252      else
12541253      {
1255         mpc105_init(machine);
1254         mpc105_init(machine());
12561255      }
1257      state->m_real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
1256      m_real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
12581257   }
12591258   else {
1260      mpc106_init(machine);
1259      mpc106_init(machine());
12611260      // some step 2+ games need the older PCI ID (obvious symptom:
12621261      // vbl is enabled briefly then disabled so the game hangs)
1263      if (core_stricmp(machine.system().name, "magtruck") == 0 ||
1264         core_stricmp(machine.system().name, "von254g") == 0)
1262      if (core_stricmp(machine().system().name, "magtruck") == 0 ||
1263         core_stricmp(machine().system().name, "von254g") == 0)
12651264      {
1266         state->m_real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
1265         m_real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
12671266      }
12681267      else
12691268      {
1270         state->m_real3d_device_id = 0x178611db; /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */
1269         m_real3d_device_id = 0x178611db; /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */
12711270      }
12721271   }
12731272}
12741273
1275MACHINE_RESET_MEMBER(model3_state,model3_10){ model3_init(machine(), 0x10); }
1276MACHINE_RESET_MEMBER(model3_state,model3_15){ model3_init(machine(), 0x15); }
1277MACHINE_RESET_MEMBER(model3_state,model3_20){ model3_init(machine(), 0x20); }
1278MACHINE_RESET_MEMBER(model3_state,model3_21){ model3_init(machine(), 0x21); }
1274MACHINE_RESET_MEMBER(model3_state,model3_10){ model3_init(0x10); }
1275MACHINE_RESET_MEMBER(model3_state,model3_15){ model3_init(0x15); }
1276MACHINE_RESET_MEMBER(model3_state,model3_20){ model3_init(0x20); }
1277MACHINE_RESET_MEMBER(model3_state,model3_21){ model3_init(0x21); }
12791278
12801279
12811280READ64_MEMBER(model3_state::model3_ctrl_r)
r29617r29618
14661465      case 0x10/8:
14671466         if (ACCESSING_BITS_56_63)
14681467         {
1469            UINT64 res = model3_tap_read(machine());
1468            UINT64 res = tap_read();
14701469
14711470            return res<<61;
14721471         }
r29617r29618
15451544         if (ACCESSING_BITS_24_31)
15461545         {
15471546            data >>= 24;
1548            model3_tap_write(machine(),
1549               (data >> 6) & 1,// TCK
1547            tap_write((data >> 6) & 1,// TCK
15501548               (data >> 2) & 1,// TMS
15511549               (data >> 5) & 1,// TDI
15521550               (data >> 7) & 1 // TRST

Previous 199869 Revisions Next


© 1997-2024 The MAME Team