Previous 199869 Revisions Next

r24759 Monday 5th August, 2013 at 21:31:00 UTC by Aaron Giles
Some cleanups of remaining machine->primary_screen references in drivers. Mostly
minor except for the megadriv stuff, where I made a first pass at removing some
of the legacy cruft.
[src/mame/drivers]dynax.c esripsys.c itech8.c m10.c segac2.c segas18.c taitotz.c tickee.c
[src/mame/includes]dynax.h esripsys.h itech8.h megadriv.h segas18.h
[src/mame/machine]irobot.c megadriv.c megavdp.c megavdp.h

trunk/src/mame/drivers/taitotz.c
r24758r24759
533533   VECTOR3 light;
534534};
535535
536class taitotz_renderer : public poly_manager<float, taitotz_polydata, 6, 50000>
537{
538public:
539   taitotz_renderer(running_machine &machine, int width, int height, UINT32 *texram)
540      : poly_manager<float, taitotz_polydata, 6, 50000>(machine)
541   {
542      m_zbuffer = auto_bitmap_ind32_alloc(machine, width, height);
543      m_texture = texram;
536class taitotz_renderer;
544537
545      m_diffuse_intensity = 224;
546      m_ambient_intensity = 32;
547      m_specular_intensity = 256;
548      m_specular_power = 20;
549   }
550
551   void set_fb(bitmap_rgb32 *fb) { m_fb = fb; }
552   void render_displaylist(running_machine &machine, const rectangle &cliprect);
553   void draw_object(running_machine &machine, UINT32 address, float scale, UINT8 alpha);
554   float line_plane_intersection(const vertex_t *v1, const vertex_t *v2, PLANE cp);
555   int clip_polygon(const vertex_t *v, int num_vertices, PLANE cp, vertex_t *vout);
556   void setup_viewport(int x, int y, int width, int height, int center_x, int center_y);
557   void draw_scanline_noz(INT32 scanline, const extent_t &extent, const taitotz_polydata &extradata, int threadid);
558   void draw_scanline(INT32 scanline, const extent_t &extent, const taitotz_polydata &extradata, int threadid);
559
560private:
561   enum
562   {
563      POLY_Z      = 0,
564      POLY_U      = 1,
565      POLY_V      = 2,
566      POLY_NX     = 3,
567      POLY_NY     = 4,
568      POLY_NZ     = 5,
569   };
570
571   //static const float ZBUFFER_MAX = 10000000000.0f;
572
573   bitmap_rgb32 *m_fb;
574   bitmap_ind32 *m_zbuffer;
575   UINT32 *m_texture;
576
577   PLANE m_clip_plane[6];
578   float m_matrix[4][3];
579
580   float m_diffuse_intensity;
581   float m_ambient_intensity;
582   float m_specular_intensity;
583   float m_specular_power;
584
585   int m_ambient_r;
586   int m_ambient_g;
587   int m_ambient_b;
588   int m_diffuse_r;
589   int m_diffuse_g;
590   int m_diffuse_b;
591   int m_specular_r;
592   int m_specular_g;
593   int m_specular_b;
594
595   float m_vp_center_x;
596   float m_vp_center_y;
597   float m_vp_focus;
598   float m_vp_x;
599   float m_vp_y;
600   float m_vp_mul;
601
602   UINT32 m_reg_100;
603   UINT32 m_reg_101;
604   UINT32 m_reg_102;
605
606   UINT32 m_reg_10000100;
607   UINT32 m_reg_10000101;
608};
609
610
611
612538class taitotz_state : public driver_device
613539{
614540public:
r24758r24759
701627   void init_taitotz_111a();
702628};
703629
630class taitotz_renderer : public poly_manager<float, taitotz_polydata, 6, 50000>
631{
632public:
633   taitotz_renderer(taitotz_state &state, int width, int height, UINT32 *texram)
634      : poly_manager<float, taitotz_polydata, 6, 50000>(state.machine()),
635        m_state(state)
636   {
637      m_zbuffer = auto_bitmap_ind32_alloc(state.machine(), width, height);
638      m_texture = texram;
639
640      m_diffuse_intensity = 224;
641      m_ambient_intensity = 32;
642      m_specular_intensity = 256;
643      m_specular_power = 20;
644   }
645
646   void set_fb(bitmap_rgb32 *fb) { m_fb = fb; }
647   void render_displaylist(running_machine &machine, const rectangle &cliprect);
648   void draw_object(running_machine &machine, UINT32 address, float scale, UINT8 alpha);
649   float line_plane_intersection(const vertex_t *v1, const vertex_t *v2, PLANE cp);
650   int clip_polygon(const vertex_t *v, int num_vertices, PLANE cp, vertex_t *vout);
651   void setup_viewport(int x, int y, int width, int height, int center_x, int center_y);
652   void draw_scanline_noz(INT32 scanline, const extent_t &extent, const taitotz_polydata &extradata, int threadid);
653   void draw_scanline(INT32 scanline, const extent_t &extent, const taitotz_polydata &extradata, int threadid);
654
655private:
656   enum
657   {
658      POLY_Z      = 0,
659      POLY_U      = 1,
660      POLY_V      = 2,
661      POLY_NX     = 3,
662      POLY_NY     = 4,
663      POLY_NZ     = 5,
664   };
665
666   //static const float ZBUFFER_MAX = 10000000000.0f;
667
668   taitotz_state &m_state;
669   bitmap_rgb32 *m_fb;
670   bitmap_ind32 *m_zbuffer;
671   UINT32 *m_texture;
672
673   PLANE m_clip_plane[6];
674   float m_matrix[4][3];
675
676   float m_diffuse_intensity;
677   float m_ambient_intensity;
678   float m_specular_intensity;
679   float m_specular_power;
680
681   int m_ambient_r;
682   int m_ambient_g;
683   int m_ambient_b;
684   int m_diffuse_r;
685   int m_diffuse_g;
686   int m_diffuse_b;
687   int m_specular_r;
688   int m_specular_g;
689   int m_specular_b;
690
691   float m_vp_center_x;
692   float m_vp_center_y;
693   float m_vp_focus;
694   float m_vp_x;
695   float m_vp_y;
696   float m_vp_mul;
697
698   UINT32 m_reg_100;
699   UINT32 m_reg_101;
700   UINT32 m_reg_102;
701
702   UINT32 m_reg_10000100;
703   UINT32 m_reg_10000101;
704};
705
706
707
704708/*
705709void taitotz_state::taitotz_exit()
706710{
r24758r24759
751755   m_texture_ram = auto_alloc_array(machine(), UINT32, 0x800000);
752756
753757   /* create renderer */
754   m_renderer = auto_alloc(machine(), taitotz_renderer(machine(), width, height, m_texture_ram));
758   m_renderer = auto_alloc(machine(), taitotz_renderer(*this, width, height, m_texture_ram));
755759
756760   //machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(taitotz_exit), &machine()));
757761}
r24758r24759
11581162
11591163void taitotz_renderer::draw_object(running_machine &machine, UINT32 address, float scale, UINT8 alpha)
11601164{
1161   taitotz_state *state = machine.driver_data<taitotz_state>();
1162   const rectangle& visarea = machine.primary_screen->visible_area();
1165   const rectangle& visarea = m_state.m_screen->visible_area();
11631166
1164   UINT32 *src = &state->m_screen_ram[address];
1167   UINT32 *src = &m_state.m_screen_ram[address];
11651168   taitotz_renderer::vertex_t v[10];
11661169
11671170
r24758r24759
13431346
13441347void taitotz_renderer::render_displaylist(running_machine &machine, const rectangle &cliprect)
13451348{
1346   taitotz_state *state = machine.driver_data<taitotz_state>();
1347
13481349   float zvalue = 0;//ZBUFFER_MAX;
13491350   m_zbuffer->fill(*(int*)&zvalue, cliprect);
13501351
1351   const rectangle& visarea = machine.primary_screen->visible_area();
1352   const rectangle& visarea = m_state.m_screen->visible_area();
13521353   vertex_t v[8];
13531354
1354   UINT32 *src = (UINT32*)&state->m_work_ram[0];
1355   UINT32 *src = (UINT32*)&m_state.m_work_ram[0];
13551356
13561357   UINT32 w[32];
13571358   int j;
13581359   int end = 0;
13591360
1360   UINT32 index = state->m_displist_addr / 4;
1361   UINT32 index = m_state.m_displist_addr / 4;
13611362
13621363   setup_viewport(0, 0, 256, 192, 256, 192);
13631364
r24758r24759
24262427
24272428WRITE8_MEMBER(taitotz_state::tlcs900_port_write)
24282429{
2429   //taitotz_state *state = device->machine().driver_data<taitotz_state>();
2430
24312430   switch (offset)
24322431   {
24332432      case 0x7:
r24758r24759
24382437      case 0x8:
24392438         if (data & 1)
24402439         {
2441            //state->m_mbox_ram[0x17] = 0x55;
2440            //m_mbox_ram[0x17] = 0x55;
24422441         }
24432442         break;
24442443
trunk/src/mame/drivers/itech8.c
r24758r24759
16501650 *
16511651 *************************************/
16521652
1653static void generate_interrupt(running_machine &machine, int state_num)
1653void itech8_state::static_generate_interrupt(running_machine &machine, int state_num) { machine.driver_data<itech8_state>()->generate_interrupt(state_num); }
1654void itech8_state::generate_interrupt(int state_num)
16541655{
1655   itech8_state *state = machine.driver_data<itech8_state>();
1656   state->itech8_update_interrupts(-1, state_num, -1);
1656   itech8_update_interrupts(-1, state_num, -1);
16571657
1658   if (FULL_LOGGING && state_num) logerror("------------ DISPLAY INT (%d) --------------\n", machine.primary_screen->vpos());
1658   if (FULL_LOGGING && state_num) logerror("------------ DISPLAY INT (%d) --------------\n", m_screen->vpos());
16591659}
16601660
16611661
r24758r24759
16631663{
16641664   8,                      /* VRAM address is (row << rowshift) | col */
16651665   0x40000,                /* size of video RAM */
1666   generate_interrupt      /* interrupt gen callback */
1666   &itech8_state::static_generate_interrupt      /* interrupt gen callback */
16671667};
16681668
16691669
trunk/src/mame/drivers/segas18.c
r24758r24759
12161216
12171217
12181218// are any of the VDP interrupt lines hooked up to anything?
1219void genesis_vdp_sndirqline_callback_segas18(running_machine &machine, bool state)
1219WRITE_LINE_MEMBER(segas18_state::genesis_vdp_sndirqline_callback_segas18)
12201220{
12211221}
12221222
1223void genesis_vdp_lv6irqline_callback_segas18(running_machine &machine, bool state)
1223WRITE_LINE_MEMBER(segas18_state::genesis_vdp_lv6irqline_callback_segas18)
12241224{
12251225}
12261226
1227void genesis_vdp_lv4irqline_callback_segas18(running_machine &machine, bool state)
1227WRITE_LINE_MEMBER(segas18_state::genesis_vdp_lv4irqline_callback_segas18)
12281228{
12291229}
12301230
r24758r24759
12591259
12601260   MCFG_DEVICE_ADD("gen_vdp", SEGA_GEN_VDP, 0)
12611261   MCFG_DEVICE_CONFIG( sms_vdp_ntsc_intf )
1262   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, genesis_vdp_sndirqline_callback_segas18);
1263   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, genesis_vdp_lv6irqline_callback_segas18);
1264   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, genesis_vdp_lv4irqline_callback_segas18);
1262   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, DEVCB2_WRITELINE(segas18_state, genesis_vdp_sndirqline_callback_segas18));
1263   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, DEVCB2_WRITELINE(segas18_state, genesis_vdp_lv6irqline_callback_segas18));
1264   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, DEVCB2_WRITELINE(segas18_state, genesis_vdp_lv4irqline_callback_segas18));
12651265   sega_genesis_vdp_device::set_genesis_vdp_alt_timing(*device, 1);
12661266   sega_genesis_vdp_device::set_genesis_vdp_palwrite_base(*device, 0x2000);
12671267
trunk/src/mame/drivers/esripsys.c
r24758r24759
235235   D7 = /FDONE
236236*/
237237
238static UINT8 rip_status_in(running_machine &machine)
238UINT8 esripsys_state::static_rip_status_in(running_machine &machine) { return machine.driver_data<esripsys_state>()->rip_status_in(); }
239UINT8 esripsys_state::rip_status_in()
239240{
240   esripsys_state *state = machine.driver_data<esripsys_state>();
241   int vpos =  machine.primary_screen->vpos();
241   int vpos =  m_screen->vpos();
242242   UINT8 _vblank = !(vpos >= ESRIPSYS_VBLANK_START);
243//  UINT8 _hblank = !machine.primary_screen->hblank();
243//  UINT8 _hblank = !m_screen->hblank();
244244
245245   return  _vblank
246         | (state->m_hblank << 1)
247         | (state->m_12sel << 2)
248         | (state->m_fbsel << 4)
246         | (m_hblank << 1)
247         | (m_12sel << 2)
248         | (m_fbsel << 4)
249249         | ((vpos & 1) << 5)
250         | (state->m_f_status & 0x80);
250         | (m_f_status & 0x80);
251251}
252252
253253/*************************************
r24758r24759
685685{
686686   fdt_rip_r,
687687   fdt_rip_w,
688   rip_status_in,
688   &esripsys_state::static_rip_status_in,
689689   esripsys_draw,
690690   "proms"
691691};
trunk/src/mame/drivers/dynax.c
r24758r24759
598598   m_hopper = data & 0x01;
599599}
600600
601static UINT8 hjingi_hopper_bit( running_machine &machine )
601UINT8 dynax_state::hjingi_hopper_bit()
602602{
603   dynax_state *state = machine.driver_data<dynax_state>();
604   return (state->m_hopper && !(machine.primary_screen->frame_number() % 10)) ? 0 : (1 << 6);
603   return (m_hopper && !(m_screen->frame_number() % 10)) ? 0 : (1 << 6);
605604}
606605
607606READ8_MEMBER(dynax_state::hjingi_keyboard_0_r)
608607{
609   return hanamai_keyboard_0_r(space, 0) | hjingi_hopper_bit(machine());
608   return hanamai_keyboard_0_r(space, 0) | hjingi_hopper_bit();
610609}
611610
612611READ8_MEMBER(dynax_state::hjingi_keyboard_1_r)
trunk/src/mame/drivers/segac2.c
r24758r24759
13081308
13091309
13101310// the main interrupt on C2 comes from the vdp line used to drive the z80 interrupt on a regular genesis(!)
1311void genesis_vdp_sndirqline_callback_segac2(running_machine &machine, bool state)
1311WRITE_LINE_MEMBER(segac2_state::genesis_vdp_sndirqline_callback_segac2)
13121312{
1313   segac2_state *drvstate = machine.driver_data<segac2_state>();
1314
1315   if (state==true)
1316      drvstate->m_maincpu->set_input_line(6, HOLD_LINE);
1313   if (state==ASSERT_LINE)
1314      m_maincpu->set_input_line(6, HOLD_LINE);
13171315}
13181316
13191317// the line usually used to drive irq6 is not connected
1320void genesis_vdp_lv6irqline_callback_segac2(running_machine &machine, bool state)
1318WRITE_LINE_MEMBER(segac2_state::genesis_vdp_lv6irqline_callback_segac2)
13211319{
13221320   //
13231321}
13241322
13251323// the scanline interrupt seems connected as usual
1326void genesis_vdp_lv4irqline_callback_segac2(running_machine &machine, bool state)
1324WRITE_LINE_MEMBER(segac2_state::genesis_vdp_lv4irqline_callback_segac2)
13271325{
1328   segac2_state *drvstate = machine.driver_data<segac2_state>();
1329   if (state==true)
1330      drvstate->m_maincpu->set_input_line(4, HOLD_LINE);
1326   if (state==ASSERT_LINE)
1327      m_maincpu->set_input_line(4, HOLD_LINE);
13311328   else
1332      drvstate->m_maincpu->set_input_line(4, CLEAR_LINE);
1329      m_maincpu->set_input_line(4, CLEAR_LINE);
13331330}
13341331
13351332static const sega315_5124_interface sms_vdp_ntsc_intf =
r24758r24759
13591356   MCFG_DEVICE_ADD("gen_vdp", SEGA_GEN_VDP, 0)
13601357   MCFG_VIDEO_SET_SCREEN("megadriv")
13611358   MCFG_DEVICE_CONFIG( sms_vdp_ntsc_intf )
1362   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, genesis_vdp_sndirqline_callback_segac2);
1363   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, genesis_vdp_lv6irqline_callback_segac2);
1364   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, genesis_vdp_lv4irqline_callback_segac2);
1359   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, DEVCB2_WRITELINE(segac2_state, genesis_vdp_sndirqline_callback_segac2));
1360   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, DEVCB2_WRITELINE(segac2_state, genesis_vdp_lv6irqline_callback_segac2));
1361   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, DEVCB2_WRITELINE(segac2_state, genesis_vdp_lv4irqline_callback_segac2));
13651362   sega_genesis_vdp_device::set_genesis_vdp_alt_timing(*device, 1);
13661363
13671364   MCFG_TIMER_ADD_SCANLINE("scantimer", megadriv_scanline_timer_callback_alt_timing, "megadriv", 0, 1)
trunk/src/mame/drivers/m10.c
r24758r24759
526526INTERRUPT_GEN_MEMBER(m10_state::m11_interrupt)
527527{
528528   device.execute().set_input_line(0, ASSERT_LINE);
529   //timer_set(machine.primary_screen->time_until_pos(IREMM10_VBEND), TIMER_INTERRUPT, -1);
529   //timer_set(m_screen->time_until_pos(IREMM10_VBEND), TIMER_INTERRUPT, -1);
530530}
531531
532532INTERRUPT_GEN_MEMBER(m10_state::m10_interrupt)
trunk/src/mame/drivers/tickee.c
r24758r24759
5454   int m_beamyadd;
5555   int m_palette_bank;
5656   UINT8 m_gunx[2];
57   void get_crosshair_xy(int player, int &x, int &y);
5758   DECLARE_WRITE16_MEMBER(rapidfir_transparent_w);
5859   DECLARE_READ16_MEMBER(rapidfir_transparent_r);
5960   DECLARE_WRITE16_MEMBER(tickee_control_w);
r24758r24759
8990 *
9091 *************************************/
9192
92INLINE void get_crosshair_xy(running_machine &machine, int player, int *x, int *y)
93inline void tickee_state::get_crosshair_xy(int player, int &x, int &y)
9394{
94   const rectangle &visarea = machine.primary_screen->visible_area();
95   const rectangle &visarea = m_screen->visible_area();
9596
96   *x = (((machine.root_device().ioport(player ? "GUNX2" : "GUNX1")->read() & 0xff) * visarea.width()) >> 8) + visarea.min_x;
97   *y = (((machine.root_device().ioport(player ? "GUNY2" : "GUNY1")->read() & 0xff) * visarea.height()) >> 8) + visarea.min_y;
97   x = (((ioport(player ? "GUNX2" : "GUNX1")->read() & 0xff) * visarea.width()) >> 8) + visarea.min_x;
98   y = (((ioport(player ? "GUNY2" : "GUNY1")->read() & 0xff) * visarea.height()) >> 8) + visarea.min_y;
9899}
99100
100101
r24758r24759
157158         return;
158159
159160   /* generate interrupts for player 1's gun */
160   get_crosshair_xy(machine(), 0, &beamx, &beamy);
161   get_crosshair_xy(0, beamx, beamy);
161162   timer_set(m_screen->time_until_pos(beamy + m_beamyadd, beamx + m_beamxadd), TIMER_TRIGGER_GUN_INTERRUPT, 0);
162163   timer_set(m_screen->time_until_pos(beamy + m_beamyadd + 1, beamx + m_beamxadd), TIMER_CLEAR_GUN_INTERRUPT, 0);
163164
164165   /* generate interrupts for player 2's gun */
165   get_crosshair_xy(machine(), 1, &beamx, &beamy);
166   get_crosshair_xy(1, beamx, beamy);
166167   timer_set(m_screen->time_until_pos(beamy + m_beamyadd, beamx + m_beamxadd), TIMER_TRIGGER_GUN_INTERRUPT, 1);
167168   timer_set(m_screen->time_until_pos(beamy + m_beamyadd + 1, beamx + m_beamxadd), TIMER_CLEAR_GUN_INTERRUPT, 1);
168169}
trunk/src/mame/machine/megavdp.c
r24758r24759
2020int megadrive_vblank_flag = 0;
2121
2222
23void genesis_vdp_sndirqline_callback_default(running_machine &machine, bool state)
24{
25   // if you haven't actually hooked this up....
26   fatalerror("m_genesis_vdp_sndirqline_callback should be connected to something!\n");
27}
28
29void genesis_vdp_lv6irqline_callback_default(running_machine &machine, bool state)
30{
31   // or this...
32   fatalerror("m_genesis_vdp_lv6irqline_callback should be connected to something!\n");
33}
34
35void genesis_vdp_lv4irqline_callback_default(running_machine &machine, bool state)
36{
37   // or this...
38   fatalerror("m_genesis_vdp_lv4irqline_callback should be connected to something!\n");
39}
40
4123const device_type SEGA_GEN_VDP = &device_creator<sega_genesis_vdp_device>;
4224
4325sega_genesis_vdp_device::sega_genesis_vdp_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
44   : sega315_5124_device( mconfig, SEGA315_5246, "Sega Genesis VDP", tag, owner, clock, SEGA315_5124_CRAM_SIZE, 0, true, "sega_genesis_vdp", __FILE__)
26   : sega315_5124_device( mconfig, SEGA315_5246, "Sega Genesis VDP", tag, owner, clock, SEGA315_5124_CRAM_SIZE, 0, true, "sega_genesis_vdp", __FILE__),
27    m_genesis_vdp_sndirqline_callback(*this),
28    m_genesis_vdp_lv6irqline_callback(*this),
29    m_genesis_vdp_lv4irqline_callback(*this)
4530{
46   m_genesis_vdp_sndirqline_callback = genesis_vdp_sndirqline_callback_default;
47   m_genesis_vdp_lv6irqline_callback = genesis_vdp_lv6irqline_callback_default;
48   m_genesis_vdp_lv4irqline_callback = genesis_vdp_lv4irqline_callback_default;
4931   m_use_alt_timing = 0;
5032   m_palwrite_base = -1;
5133}
r24758r24759
5335static TIMER_CALLBACK( megadriv_render_timer_callback )
5436{
5537   sega_genesis_vdp_device* vdp = (sega_genesis_vdp_device*)ptr;
56   vdp->genesis_render_scanline(machine);
38   vdp->genesis_render_scanline();
5739}
5840
59void sega_genesis_vdp_device::vdp_handle_irq6_on_timer_callback(running_machine &machine, int param)
41void sega_genesis_vdp_device::vdp_handle_irq6_on_timer_callback(int param)
6042{
6143// megadrive_irq6_pending = 1;
6244   if (MEGADRIVE_REG01_IRQ6_ENABLE)
63      m_genesis_vdp_lv6irqline_callback(machine, true);
45      m_genesis_vdp_lv6irqline_callback(true);
6446}
6547
6648static TIMER_CALLBACK( irq6_on_timer_callback )
6749{
6850   sega_genesis_vdp_device* vdp = (sega_genesis_vdp_device*)ptr;
69   vdp->vdp_handle_irq6_on_timer_callback(machine, param);
51   vdp->vdp_handle_irq6_on_timer_callback(param);
7052}
7153
72void sega_genesis_vdp_device::vdp_handle_irq4_on_timer_callback(running_machine &machine, int param)
54void sega_genesis_vdp_device::vdp_handle_irq4_on_timer_callback(int param)
7355{
74   m_genesis_vdp_lv4irqline_callback(machine, true);
56   m_genesis_vdp_lv4irqline_callback(true);
7557}
7658
7759static TIMER_CALLBACK( irq4_on_timer_callback )
7860{
7961   sega_genesis_vdp_device* vdp = (sega_genesis_vdp_device*)ptr;
80   vdp->vdp_handle_irq4_on_timer_callback(machine, param);
62   vdp->vdp_handle_irq4_on_timer_callback(param);
8163}
8264
8365
8466
8567
86void sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(device_t &device, genesis_vdp_sndirqline_callback_func callback)
87{
88   sega_genesis_vdp_device &dev = downcast<sega_genesis_vdp_device &>(device);
89   dev.m_genesis_vdp_sndirqline_callback = callback;
90}
91
92void sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(device_t &device, genesis_vdp_lv6irqline_callback_func callback)
93{
94   sega_genesis_vdp_device &dev = downcast<sega_genesis_vdp_device &>(device);
95   dev.m_genesis_vdp_lv6irqline_callback = callback;
96}
97
98void sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(device_t &device, genesis_vdp_lv4irqline_callback_func callback)
99{
100   sega_genesis_vdp_device &dev = downcast<sega_genesis_vdp_device &>(device);
101   dev.m_genesis_vdp_lv4irqline_callback = callback;
102}
103
10468void sega_genesis_vdp_device::set_genesis_vdp_alt_timing(device_t &device, int use_alt_timing)
10569{
10670   sega_genesis_vdp_device &dev = downcast<sega_genesis_vdp_device &>(device);
r24758r24759
11882
11983void sega_genesis_vdp_device::device_start()
12084{
85   m_genesis_vdp_sndirqline_callback.resolve_safe();
86   m_genesis_vdp_lv6irqline_callback.resolve_safe();
87   m_genesis_vdp_lv4irqline_callback.resolve_safe();
88
12189   m_vram  = auto_alloc_array(machine(), UINT16, 0x10000/2);
12290   m_cram  = auto_alloc_array(machine(), UINT16, 0x80/2);
12391   m_vsram = auto_alloc_array(machine(), UINT16, 0x80/2);
r24758r24759
270238   m_vdp_address &=0xffff;
271239}
272240
273void sega_genesis_vdp_device::write_cram_value(running_machine &machine, int offset, int data)
241void sega_genesis_vdp_device::write_cram_value(int offset, int data)
274242{
275243   m_cram[offset] = data;
276244
r24758r24759
283251      b = ((data >> 9)&0x07);
284252      if (m_palwrite_base != -1)
285253      {
286         palette_set_color_rgb(machine,offset + m_palwrite_base ,pal3bit(r),pal3bit(g),pal3bit(b));
287         palette_set_color_rgb(machine,offset + m_palwrite_base + 0x40 ,pal3bit(r>>1),pal3bit(g>>1),pal3bit(b>>1));
288         palette_set_color_rgb(machine,offset + m_palwrite_base + 0x80 ,pal3bit((r>>1)|0x4),pal3bit((g>>1)|0x4),pal3bit((b>>1)|0x4));
254         palette_set_color_rgb(machine(),offset + m_palwrite_base ,pal3bit(r),pal3bit(g),pal3bit(b));
255         palette_set_color_rgb(machine(),offset + m_palwrite_base + 0x40 ,pal3bit(r>>1),pal3bit(g>>1),pal3bit(b>>1));
256         palette_set_color_rgb(machine(),offset + m_palwrite_base + 0x80 ,pal3bit((r>>1)|0x4),pal3bit((g>>1)|0x4),pal3bit((b>>1)|0x4));
289257      }
290258      megadrive_vdp_palette_lookup[offset] = (b<<2) | (g<<7) | (r<<12);
291259      megadrive_vdp_palette_lookup_sprite[offset] = (b<<2) | (g<<7) | (r<<12);
r24758r24759
294262   }
295263}
296264
297void sega_genesis_vdp_device::vdp_cram_write(running_machine &machine, UINT16 data)
265void sega_genesis_vdp_device::vdp_cram_write(UINT16 data)
298266{
299267   int offset;
300268   offset = (m_vdp_address&0x7e)>>1;
301269
302   write_cram_value(machine, offset,data);
270   write_cram_value(offset,data);
303271
304272   m_vdp_address+=MEGADRIVE_REG0F_AUTO_INC;
305273
r24758r24759
307275}
308276
309277
310void sega_genesis_vdp_device::megadriv_vdp_data_port_w(running_machine &machine, int data)
278void sega_genesis_vdp_device::megadriv_vdp_data_port_w(int data)
311279{
312280   m_vdp_command_pending = 0;
313281
r24758r24759
375343            break;
376344
377345         case 0x0003:
378            vdp_cram_write(machine, data);
346            vdp_cram_write(data);
379347            break;
380348
381349         case 0x0004:
r24758r24759
402370
403371
404372
405void sega_genesis_vdp_device::megadrive_vdp_set_register(running_machine &machine, int regnum, UINT8 value)
373void sega_genesis_vdp_device::megadrive_vdp_set_register(int regnum, UINT8 value)
406374{
407375   m_vdp_regs[regnum] = value;
408376
r24758r24759
417385      if (megadrive_irq4_pending)
418386      {
419387         if (MEGADRIVE_REG0_IRQ4_ENABLE)
420            m_genesis_vdp_lv4irqline_callback(machine, true);
388            m_genesis_vdp_lv4irqline_callback(true);
421389         else
422            m_genesis_vdp_lv4irqline_callback(machine, false);
390            m_genesis_vdp_lv4irqline_callback(false);
423391      }
424392
425393      /* ??? Fatal Rewind needs this but I'm not sure it's accurate behavior
r24758r24759
434402      if (megadrive_irq6_pending)
435403      {
436404         if (MEGADRIVE_REG01_IRQ6_ENABLE )
437            m_genesis_vdp_lv6irqline_callback(machine, true);
405            m_genesis_vdp_lv6irqline_callback(true);
438406         else
439            m_genesis_vdp_lv6irqline_callback(machine, false);
407            m_genesis_vdp_lv6irqline_callback(false);
440408
441409      }
442410
r24758r24759
448416
449417
450418//  if (regnum == 0x0a)
451//      mame_printf_debug("Set HINT Reload Register to %d on scanline %d\n",value, genesis_get_scanline_counter(machine));
419//      mame_printf_debug("Set HINT Reload Register to %d on scanline %d\n",value, genesis_get_scanline_counter());
452420
453//  mame_printf_debug("%s: Setting VDP Register #%02x to %02x\n",machine.describe_context(), regnum,value);
421//  mame_printf_debug("%s: Setting VDP Register #%02x to %02x\n",machine().describe_context(), regnum,value);
454422}
455423
456424void sega_genesis_vdp_device::update_m_vdp_code_and_address(void)
r24758r24759
538506}
539507
540508/* Instant, but we pause the 68k a bit */
541void sega_genesis_vdp_device::megadrive_do_insta_68k_to_vram_dma(running_machine &machine, UINT32 source,int length)
509void sega_genesis_vdp_device::megadrive_do_insta_68k_to_vram_dma(UINT32 source,int length)
542510{
543511   int count;
544512
r24758r24759
549517
550518   for (count = 0;count<(length>>1);count++)
551519   {
552      vdp_vram_write(vdp_get_word_from_68k_mem(machine, source, *m_space68k));
520      vdp_vram_write(vdp_get_word_from_68k_mem(machine(), source, *m_space68k));
553521      source+=2;
554522      if (source>0xffffff) source = 0xe00000;
555523   }
r24758r24759
565533}
566534
567535
568void sega_genesis_vdp_device::megadrive_do_insta_68k_to_cram_dma(running_machine &machine,UINT32 source,UINT16 length)
536void sega_genesis_vdp_device::megadrive_do_insta_68k_to_cram_dma(UINT32 source,UINT16 length)
569537{
570538   int count;
571539
r24758r24759
575543   {
576544      //if (m_vdp_address>=0x80) return; // abandon
577545
578      write_cram_value(machine, (m_vdp_address&0x7e)>>1, vdp_get_word_from_68k_mem(machine, source, *m_space68k));
546      write_cram_value((m_vdp_address&0x7e)>>1, vdp_get_word_from_68k_mem(machine(), source, *m_space68k));
579547      source+=2;
580548
581549      if (source>0xffffff) source = 0xfe0000;
r24758r24759
593561
594562}
595563
596void sega_genesis_vdp_device::megadrive_do_insta_68k_to_vsram_dma(running_machine &machine,UINT32 source,UINT16 length)
564void sega_genesis_vdp_device::megadrive_do_insta_68k_to_vsram_dma(UINT32 source,UINT16 length)
597565{
598566   int count;
599567
r24758r24759
603571   {
604572      if (m_vdp_address>=0x80) return; // abandon
605573
606      m_vsram[(m_vdp_address&0x7e)>>1] = vdp_get_word_from_68k_mem(machine, source, *m_space68k);
574      m_vsram[(m_vdp_address&0x7e)>>1] = vdp_get_word_from_68k_mem(machine(), source, *m_space68k);
607575      source+=2;
608576
609577      if (source>0xffffff) source = 0xfe0000;
r24758r24759
621589}
622590
623591/* This can be simplified quite a lot.. */
624void sega_genesis_vdp_device::handle_dma_bits(running_machine &machine)
592void sega_genesis_vdp_device::handle_dma_bits()
625593{
626594#if 0
627595   if (m_vdp_code&0x20)
r24758r24759
630598      UINT16 length;
631599      source = (MEGADRIVE_REG15_DMASOURCE1 | (MEGADRIVE_REG16_DMASOURCE2<<8) | ((MEGADRIVE_REG17_DMASOURCE3&0xff)<<16))<<1;
632600      length = (MEGADRIVE_REG13_DMALENGTH1 | (MEGADRIVE_REG14_DMALENGTH2<<8))<<1;
633      mame_printf_debug("%s 68k DMAtran set source %06x length %04x dest %04x enabled %01x code %02x %02x\n", machine.describe_context(), source, length, m_vdp_address,MEGADRIVE_REG01_DMA_ENABLE, m_vdp_code,MEGADRIVE_REG0F_AUTO_INC);
601      mame_printf_debug("%s 68k DMAtran set source %06x length %04x dest %04x enabled %01x code %02x %02x\n", machine().describe_context(), source, length, m_vdp_address,MEGADRIVE_REG01_DMA_ENABLE, m_vdp_code,MEGADRIVE_REG0F_AUTO_INC);
634602   }
635603#endif
636604   if (m_vdp_code==0x20)
r24758r24759
648616
649617         /* The 68k is frozen during this transfer, it should be safe to throw a few cycles away and do 'instant' DMA because the 68k can't detect it being in progress (can the z80?) */
650618         //mame_printf_debug("68k->VRAM DMA transfer source %06x length %04x dest %04x enabled %01x\n", source, length, m_vdp_address,MEGADRIVE_REG01_DMA_ENABLE);
651         if (MEGADRIVE_REG01_DMA_ENABLE) megadrive_do_insta_68k_to_vram_dma(machine,source,length);
619         if (MEGADRIVE_REG01_DMA_ENABLE) megadrive_do_insta_68k_to_vram_dma(source,length);
652620
653621      }
654622      else if (MEGADRIVE_REG17_DMATYPE==0x2)
r24758r24759
682650
683651         /* The 68k is frozen during this transfer, it should be safe to throw a few cycles away and do 'instant' DMA because the 68k can't detect it being in progress (can the z80?) */
684652         //mame_printf_debug("68k->CRAM DMA transfer source %06x length %04x dest %04x enabled %01x\n", source, length, m_vdp_address,MEGADRIVE_REG01_DMA_ENABLE);
685         if (MEGADRIVE_REG01_DMA_ENABLE) megadrive_do_insta_68k_to_cram_dma(machine,source,length);
653         if (MEGADRIVE_REG01_DMA_ENABLE) megadrive_do_insta_68k_to_cram_dma(source,length);
686654      }
687655      else if (MEGADRIVE_REG17_DMATYPE==0x2)
688656      {
r24758r24759
709677
710678         /* The 68k is frozen during this transfer, it should be safe to throw a few cycles away and do 'instant' DMA because the 68k can't detect it being in progress (can the z80?) */
711679         //mame_printf_debug("68k->VSRAM DMA transfer source %06x length %04x dest %04x enabled %01x\n", source, length, m_vdp_address,MEGADRIVE_REG01_DMA_ENABLE);
712         if (MEGADRIVE_REG01_DMA_ENABLE) megadrive_do_insta_68k_to_vsram_dma(machine,source,length);
680         if (MEGADRIVE_REG01_DMA_ENABLE) megadrive_do_insta_68k_to_vsram_dma(source,length);
713681      }
714682      else if (MEGADRIVE_REG17_DMATYPE==0x2)
715683      {
r24758r24759
752720   }
753721}
754722
755void sega_genesis_vdp_device::megadriv_vdp_ctrl_port_w(running_machine &machine, int data)
723void sega_genesis_vdp_device::megadriv_vdp_ctrl_port_w(int data)
756724{
757725//  logerror("write to vdp control port %04x\n",data);
758726   m_vram_fill_pending = 0; // ??
r24758r24759
764732      m_vdp_command_part2 = data;
765733
766734      update_m_vdp_code_and_address();
767      handle_dma_bits(machine);
735      handle_dma_bits();
768736
769737      //logerror("VDP Write Part 2 setting Code %02x Address %04x\n",m_vdp_code, m_vdp_address);
770738
r24758r24759
778746
779747         if (regnum &0x20) mame_printf_debug("reg error\n");
780748
781         megadrive_vdp_set_register(machine, regnum&0x1f,value);
749         megadrive_vdp_set_register(regnum&0x1f,value);
782750         m_vdp_code = 0;
783751         m_vdp_address = 0;
784752      }
r24758r24759
809777            data = (data&0xff00) | data>>8;
810778         //  mame_printf_debug("8-bit write VDP data port access, offset %04x data %04x mem_mask %04x\n",offset,data,mem_mask);
811779         }
812         megadriv_vdp_data_port_w(space.machine(), data);
780         megadriv_vdp_data_port_w(data);
813781         break;
814782
815783      case 0x04:
816784      case 0x06:
817785         if ((!ACCESSING_BITS_8_15) || (!ACCESSING_BITS_0_7)) mame_printf_debug("8-bit write VDP control port access, offset %04x data %04x mem_mask %04x\n",offset,data,mem_mask);
818         megadriv_vdp_ctrl_port_w(space.machine(), data);
786         megadriv_vdp_ctrl_port_w(data);
819787         break;
820788
821789      case 0x08:
r24758r24759
831799      case 0x16:
832800      {
833801         // accessed by either segapsg_device or sn76496_device
834         sn76496_base_device *sn = space.machine().device<sn76496_base_device>(":snsnd");
802         sn76496_base_device *sn = machine().device<sn76496_base_device>(":snsnd");
835803         if (ACCESSING_BITS_0_7) sn->write(space, 0, data & 0xff);
836804         //if (ACCESSING_BITS_8_15) sn->write(space, 0, (data>>8) & 0xff);
837805         break;
r24758r24759
857825   return m_cram[(m_vdp_address&0x7e)>>1];
858826}
859827
860UINT16 sega_genesis_vdp_device::megadriv_vdp_data_port_r(running_machine &machine)
828UINT16 sega_genesis_vdp_device::megadriv_vdp_data_port_r()
861829{
862830   UINT16 retdata=0;
863831
864   //return machine.rand();
832   //return machine().rand();
865833
866834   m_vdp_command_pending = 0;
867835
r24758r24759
875843
876844      case 0x0001:
877845         logerror("Attempting to READ from DATA PORT in VRAM WRITE MODE\n");
878         retdata = machine.rand();
846         retdata = machine().rand();
879847         break;
880848
881849      case 0x0003:
882850         logerror("Attempting to READ from DATA PORT in CRAM WRITE MODE\n");
883         retdata = machine.rand();
851         retdata = machine().rand();
884852         break;
885853
886854      case 0x0004:
r24758r24759
901869
902870      default:
903871         logerror("Attempting to READ from DATA PORT in #UNDEFINED# MODE\n");
904         retdata = machine.rand();
872         retdata = machine().rand();
905873         break;
906874   }
907875
r24758r24759
974942
975943
976944
977UINT16 sega_genesis_vdp_device::megadriv_vdp_ctrl_port_r(running_machine &machine)
945UINT16 sega_genesis_vdp_device::megadriv_vdp_ctrl_port_r()
978946{
979947   /* Battletoads is very fussy about the vblank flag
980948      it wants it to be 1. in scanline 224 */
r24758r24759
996964   int fifo_empty = 1;
997965   int fifo_full = 0;
998966
999   UINT16 hpos = get_hposition(machine);
967   UINT16 hpos = get_hposition();
1000968
1001969   if (hpos>400) megadrive_hblank_flag = 1;
1002970   if (hpos>460) megadrive_hblank_flag = 0;
r24758r24759
11391107};
11401108
11411109
1142UINT16 sega_genesis_vdp_device::get_hposition(running_machine &machine)
1110UINT16 sega_genesis_vdp_device::get_hposition()
11431111{
11441112   UINT16 value4;
11451113
r24758r24759
11611129   }
11621130   else
11631131   {
1164      value4 = machine.primary_screen->hpos();
1132      value4 = m_screen->hpos();
11651133   }
11661134
11671135   return value4;
11681136}
11691137
1170int sega_genesis_vdp_device::genesis_get_scanline_counter(running_machine &machine)
1138int sega_genesis_vdp_device::genesis_get_scanline_counter()
11711139{
11721140   if (!m_use_alt_timing)
11731141      return m_scanline_counter;
11741142   else
1175      return machine.primary_screen->vpos();
1143      return m_screen->vpos();
11761144}
11771145
11781146
1179UINT16 sega_genesis_vdp_device::megadriv_read_hv_counters(running_machine &machine)
1147UINT16 sega_genesis_vdp_device::megadriv_read_hv_counters()
11801148{
11811149   /* Bubble and Squeek wants vcount=0xe0 */
11821150   /* Dracula is very sensitive to this */
11831151   /* Marvel Land is sensitive to this */
11841152
1185   int vpos = genesis_get_scanline_counter(machine);
1186   UINT16 hpos = get_hposition(machine);
1153   int vpos = genesis_get_scanline_counter();
1154   UINT16 hpos = get_hposition();
11871155
11881156//  if (hpos>424) vpos++; // fixes dracula, breaks road rash
11891157   if (hpos>460) vpos++; // when does vpos increase.. also on sms, check game gear manual..
r24758r24759
12231191      case 0x00:
12241192      case 0x02:
12251193         if ((!ACCESSING_BITS_8_15) || (!ACCESSING_BITS_0_7)) mame_printf_debug("8-bit VDP read data port access, offset %04x mem_mask %04x\n",offset,mem_mask);
1226         retvalue = megadriv_vdp_data_port_r(space.machine());
1194         retvalue = megadriv_vdp_data_port_r();
12271195         break;
12281196
12291197      case 0x04:
12301198      case 0x06:
12311199      //  if ((!ACCESSING_BITS_8_15) || (!ACCESSING_BITS_0_7)) mame_printf_debug("8-bit VDP read control port access, offset %04x mem_mask %04x\n",offset,mem_mask);
1232         retvalue = megadriv_vdp_ctrl_port_r(space.machine());
1233      //  retvalue = space.machine().rand();
1234      //  mame_printf_debug("%06x: Read Control Port at scanline %d hpos %d (return %04x)\n",space.device().safe_pc(),genesis_get_scanline_counter(machine), get_hposition(space.machine()),retvalue);
1200         retvalue = megadriv_vdp_ctrl_port_r();
1201      //  retvalue = machine().rand();
1202      //  mame_printf_debug("%06x: Read Control Port at scanline %d hpos %d (return %04x)\n",space.device().safe_pc(),genesis_get_scanline_counter(), get_hposition(),retvalue);
12351203         break;
12361204
12371205      case 0x08:
r24758r24759
12391207      case 0x0c:
12401208      case 0x0e:
12411209      //  if ((!ACCESSING_BITS_8_15) || (!ACCESSING_BITS_0_7)) mame_printf_debug("8-bit VDP read HV counter port access, offset %04x mem_mask %04x\n",offset,mem_mask);
1242         retvalue = megadriv_read_hv_counters(space.machine());
1243      //  retvalue = space.machine().rand();
1244      //  mame_printf_debug("%06x: Read HV counters at scanline %d hpos %d (return %04x)\n",space.device().safe_pc(),genesis_get_scanline_counter(machine), get_hposition(space.machine()),retvalue);
1210         retvalue = megadriv_read_hv_counters();
1211      //  retvalue = machine().rand();
1212      //  mame_printf_debug("%06x: Read HV counters at scanline %d hpos %d (return %04x)\n",space.device().safe_pc(),genesis_get_scanline_counter(), get_hposition(),retvalue);
12451213         break;
12461214
12471215      case 0x10:
r24758r24759
15611529
15621530   //mame_printf_debug("screenwidth %d\n",screenwidth);
15631531
1564   //base_w = Machine->rand()&0xff;
1532   //base_w = machine().rand()&0xff;
15651533
15661534   /* Calculate Exactly where we're going to draw the Window, and if the Window Bug applies */
15671535   window_is_bugged = 0;
r24758r24759
25092477
25102478
25112479/* This converts our render buffer to real screen colours */
2512void sega_genesis_vdp_device::genesis_render_videobuffer_to_screenbuffer(running_machine &machine, int scanline)
2480void sega_genesis_vdp_device::genesis_render_videobuffer_to_screenbuffer(int scanline)
25132481{
2514   sega_32x_device *_32xdev = machine.device<sega_32x_device>("sega32x"); // take this out of the VDP eventually
2482   sega_32x_device *_32xdev = machine().device<sega_32x_device>("sega32x"); // take this out of the VDP eventually
25152483   UINT16 *lineptr;
25162484
25172485   if (!m_use_alt_timing)
r24758r24759
25912559               case 0x1a000: // (sprite)shadow set, highlight set - not possible
25922560               case 0x1e000: // (sprite)shadow set, highlight set, normal set, not possible
25932561               default:
2594                  lineptr[x] = m_render_line_raw[x] |= (machine.rand() & 0x3f);
2562                  lineptr[x] = m_render_line_raw[x] |= (machine().rand() & 0x3f);
25952563                  break;
25962564            }
25972565         }
r24758r24759
26032571   }
26042572}
26052573
2606void sega_genesis_vdp_device::genesis_render_scanline(running_machine &machine)
2574void sega_genesis_vdp_device::genesis_render_scanline()
26072575{
2608   int scanline = genesis_get_scanline_counter(machine);
2576   int scanline = genesis_get_scanline_counter();
26092577
26102578   if (scanline >= 0 && scanline < m_visible_scanlines)
26112579   {
26122580      //if (MEGADRIVE_REG01_DMA_ENABLE==0) mame_printf_debug("off\n");
2613      genesis_render_spriteline_to_spritebuffer(genesis_get_scanline_counter(machine));
2581      genesis_render_spriteline_to_spritebuffer(genesis_get_scanline_counter());
26142582      genesis_render_videoline_to_videobuffer(scanline);
2615      genesis_render_videobuffer_to_screenbuffer(machine, scanline);
2583      genesis_render_videobuffer_to_screenbuffer(scanline);
26162584   }
26172585}
26182586
2619void sega_genesis_vdp_device::vdp_handle_scanline_callback(running_machine &machine, int scanline)
2587void sega_genesis_vdp_device::vdp_handle_scanline_callback(int scanline)
26202588{
26212589/* Compensate for some rounding errors
26222590
r24758r24759
26242592       to rounding errors in the timer calculation we're not quite there.  Let's assume we are
26252593       still in the previous scanline for now.
26262594    */
2627   sega_32x_device *_32xdev = machine.device<sega_32x_device>("sega32x"); // take this out of the VDP eventually
2595   sega_32x_device *_32xdev = machine().device<sega_32x_device>("sega32x"); // take this out of the VDP eventually
26282596
26292597
2630   if (genesis_get_scanline_counter(machine) != (megadrive_total_scanlines - 1))
2598   if (genesis_get_scanline_counter() != (megadrive_total_scanlines - 1))
26312599   {
26322600      if (!m_use_alt_timing) m_scanline_counter++;
2633//      mame_printf_debug("scanline %d\n",genesis_get_scanline_counter(machine));
2601//      mame_printf_debug("scanline %d\n",genesis_get_scanline_counter());
26342602      megadriv_render_timer->adjust(attotime::from_usec(1));
26352603
2636      if (genesis_get_scanline_counter(machine) == m_irq6_scanline)
2604      if (genesis_get_scanline_counter() == m_irq6_scanline)
26372605      {
2638      //  mame_printf_debug("x %d",genesis_get_scanline_counter(machine));
2606      //  mame_printf_debug("x %d",genesis_get_scanline_counter());
26392607         irq6_on_timer->adjust(attotime::from_usec(6));
26402608         megadrive_irq6_pending = 1;
26412609         megadrive_vblank_flag = 1;
r24758r24759
26502618      if (_32xdev) _32xdev->_32x_check_framebuffer_swap(m_scanline_counter >= m_irq6_scanline);
26512619
26522620
2653   //  if (genesis_get_scanline_counter(machine)==0) m_irq4counter = MEGADRIVE_REG0A_HINT_VALUE;
2621   //  if (genesis_get_scanline_counter()==0) m_irq4counter = MEGADRIVE_REG0A_HINT_VALUE;
26542622      // m_irq4counter = MEGADRIVE_REG0A_HINT_VALUE;
26552623
2656      if (genesis_get_scanline_counter(machine)<=224)
2624      if (genesis_get_scanline_counter()<=224)
26572625      {
26582626         m_irq4counter--;
26592627
r24758r24759
26672635            if (MEGADRIVE_REG0_IRQ4_ENABLE)
26682636            {
26692637               irq4_on_timer->adjust(attotime::from_usec(1));
2670               //mame_printf_debug("irq4 on scanline %d reload %d\n",genesis_get_scanline_counter(machine),MEGADRIVE_REG0A_HINT_VALUE);
2638               //mame_printf_debug("irq4 on scanline %d reload %d\n",genesis_get_scanline_counter(),MEGADRIVE_REG0A_HINT_VALUE);
26712639            }
26722640         }
26732641      }
r24758r24759
26772645         else m_irq4counter=MEGADRIVE_REG0A_HINT_VALUE;
26782646      }
26792647
2680      //if (genesis_get_scanline_counter(machine)==0) irq4_on_timer->adjust(attotime::from_usec(2));
2648      //if (genesis_get_scanline_counter()==0) irq4_on_timer->adjust(attotime::from_usec(2));
26812649
26822650
26832651      if (_32xdev) _32xdev->_32x_scanline_cb1(m_scanline_counter);
26842652
26852653
2686      if (genesis_get_scanline_counter(machine) == m_z80irq_scanline)
2654      if (genesis_get_scanline_counter() == m_z80irq_scanline)
26872655      {
2688         m_genesis_vdp_sndirqline_callback(machine, true);
2656         m_genesis_vdp_sndirqline_callback(true);
26892657      }
2690      if (genesis_get_scanline_counter(machine) == m_z80irq_scanline + 1)
2658      if (genesis_get_scanline_counter() == m_z80irq_scanline + 1)
26912659      {
2692         m_genesis_vdp_sndirqline_callback(machine, false);
2660         m_genesis_vdp_sndirqline_callback(false);
26932661      }
26942662   }
26952663   else /* pretend we're still on the same scanline to compensate for rounding errors */
r24758r24759
27022670
27032671
27042672
2705void sega_genesis_vdp_device::vdp_handle_eof(running_machine &machine)
2673void sega_genesis_vdp_device::vdp_handle_eof()
27062674{
2707   sega_32x_device *_32xdev = machine.device<sega_32x_device>("sega32x"); // take this out of the VDP eventually
2675   sega_32x_device *_32xdev = machine().device<sega_32x_device>("sega32x"); // take this out of the VDP eventually
27082676
27092677   rectangle visarea;
27102678   int scr_width = 320;
r24758r24759
27562724
27572725   visarea.set(0, scr_width - 1, 0, m_visible_scanlines - 1);
27582726
2759   machine.primary_screen->configure(480, megadrive_total_scanlines, visarea, machine.primary_screen->frame_period().attoseconds);
2727   m_screen->configure(480, megadrive_total_scanlines, visarea, m_screen->frame_period().attoseconds);
27602728
27612729
27622730   if(_32xdev) _32xdev->m_32x_hcount_compare_val = -1;
r24758r24759
27712739   if (!vdp->m_use_alt_timing)
27722740   {
27732741      timer.machine().scheduler().synchronize();
2774      vdp->vdp_handle_scanline_callback(timer.machine(), param);
2742      vdp->vdp_handle_scanline_callback(param);
27752743
27762744      megadriv_scanline_timer->adjust(attotime::from_hz(vdp->get_framerate()) / megadrive_total_scanlines);
27772745   }
27782746   else
27792747   {
2780      vdp->vdp_handle_scanline_callback(timer.machine(), param);
2748      vdp->vdp_handle_scanline_callback(param);
27812749   }
27822750}
27832751
r24758r24759
27902758      if (param==0)
27912759      {
27922760         //printf("where are we? %d %d\n", m_screen->vpos(), vdp->screen().hpos());
2793         vdp->vdp_handle_eof(timer.machine());
2761         vdp->vdp_handle_eof();
27942762         //vdp->vdp_clear_bitmap();
27952763      }
27962764
27972765
2798      vdp->vdp_handle_scanline_callback(timer.machine(), param);
2766      vdp->vdp_handle_scanline_callback(param);
27992767
28002768      int vpos = vdp->screen().vpos();
28012769      if (vpos > 0)
trunk/src/mame/machine/megavdp.h
r24758r24759
146146#define MEGADRIVE_REG17_UNUSED          ((m_vdp_regs[0x17]&0x3f)>>0)
147147
148148
149typedef void (*genesis_vdp_sndirqline_callback_func)(running_machine &machine, bool state);
150typedef void (*genesis_vdp_lv6irqline_callback_func)(running_machine &machine, bool state);
151typedef void (*genesis_vdp_lv4irqline_callback_func)(running_machine &machine, bool state);
152
153149TIMER_DEVICE_CALLBACK( megadriv_scanline_timer_callback_alt_timing );
154150
155151UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source, address_space & space68k);
r24758r24759
160156public:
161157   sega_genesis_vdp_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
162158
163   static void set_genesis_vdp_sndirqline_callback(device_t &device, genesis_vdp_sndirqline_callback_func callback);
164   static void set_genesis_vdp_lv6irqline_callback(device_t &device, genesis_vdp_lv6irqline_callback_func callback);
165   static void set_genesis_vdp_lv4irqline_callback(device_t &device, genesis_vdp_lv4irqline_callback_func callback);
159   template<class _Object> static devcb2_base &set_genesis_vdp_sndirqline_callback(device_t &device, _Object object) { return downcast<sega_genesis_vdp_device &>(device).m_genesis_vdp_sndirqline_callback.set_callback(object); }
160   template<class _Object> static devcb2_base &set_genesis_vdp_lv6irqline_callback(device_t &device, _Object object) { return downcast<sega_genesis_vdp_device &>(device).m_genesis_vdp_lv6irqline_callback.set_callback(object); }
161   template<class _Object> static devcb2_base &set_genesis_vdp_lv4irqline_callback(device_t &device, _Object object) { return downcast<sega_genesis_vdp_device &>(device).m_genesis_vdp_lv4irqline_callback.set_callback(object); }
166162   static void set_genesis_vdp_alt_timing(device_t &device, int use_alt_timing);
167163   static void set_genesis_vdp_palwrite_base(device_t &device, int palwrite_base);
168164
r24758r24759
173169   DECLARE_READ16_MEMBER( megadriv_vdp_r );
174170   DECLARE_WRITE16_MEMBER( megadriv_vdp_w );
175171
176   int genesis_get_scanline_counter(running_machine &machine);
172   int genesis_get_scanline_counter();
177173
178174
179   void genesis_render_scanline(running_machine &machine);
180   void vdp_handle_scanline_callback(running_machine &machine, int scanline);
181   void vdp_handle_irq6_on_timer_callback(running_machine &machine, int param);
182   void vdp_handle_irq4_on_timer_callback(running_machine &machine, int param);
183   void vdp_handle_eof(running_machine &machine);
175   void genesis_render_scanline();
176   void vdp_handle_scanline_callback(int scanline);
177   void vdp_handle_irq6_on_timer_callback(int param);
178   void vdp_handle_irq4_on_timer_callback(int param);
179   void vdp_handle_eof();
184180   void device_reset_old();
185181   void vdp_clear_irq6_pending(void) { megadrive_irq6_pending = 0; };
186182   void vdp_clear_irq4_pending(void) { megadrive_irq4_pending = 0; };
r24758r24759
209205   virtual void device_reset();
210206
211207   // called when we hit 240 and 241 (used to control the z80 irq line on genesis, or the main irq on c2)
212   genesis_vdp_sndirqline_callback_func m_genesis_vdp_sndirqline_callback;
213   genesis_vdp_lv6irqline_callback_func m_genesis_vdp_lv6irqline_callback;
214   genesis_vdp_lv6irqline_callback_func m_genesis_vdp_lv4irqline_callback;
208   devcb2_write_line m_genesis_vdp_sndirqline_callback;
209   devcb2_write_line m_genesis_vdp_lv6irqline_callback;
210   devcb2_write_line m_genesis_vdp_lv4irqline_callback;
215211
216212private:
217213
r24758r24759
257253   emu_timer* irq4_on_timer;
258254   emu_timer* megadriv_render_timer;
259255
260
261256   UINT16 vdp_vram_r(void);
262257   UINT16 vdp_vsram_r(void);
263258   UINT16 vdp_cram_r(void);
264259
265   void megadrive_do_insta_68k_to_cram_dma(running_machine &machine,UINT32 source,UINT16 length);
266   void megadrive_do_insta_68k_to_vsram_dma(running_machine &machine,UINT32 source,UINT16 length);
267   void megadrive_do_insta_68k_to_vram_dma(running_machine &machine, UINT32 source,int length);
260   void megadrive_do_insta_68k_to_cram_dma(UINT32 source,UINT16 length);
261   void megadrive_do_insta_68k_to_vsram_dma(UINT32 source,UINT16 length);
262   void megadrive_do_insta_68k_to_vram_dma(UINT32 source,int length);
268263   void megadrive_do_insta_vram_copy(UINT32 source, UINT16 length);
269264
270265   void vdp_vram_write(UINT16 data);
271   void vdp_cram_write(running_machine &machine, UINT16 data);
272   void write_cram_value(running_machine &machine, int offset, int data);
266   void vdp_cram_write(UINT16 data);
267   void write_cram_value(int offset, int data);
273268   void vdp_vsram_write(UINT16 data);
274269
275   void megadrive_vdp_set_register(running_machine &machine, int regnum, UINT8 value);
270   void megadrive_vdp_set_register(int regnum, UINT8 value);
276271
277   void handle_dma_bits(running_machine &machine);
272   void handle_dma_bits();
278273
279   UINT16 get_hposition(running_machine &machine);
280   UINT16 megadriv_read_hv_counters(running_machine &machine);
274   UINT16 get_hposition();
275   UINT16 megadriv_read_hv_counters();
281276
282   UINT16 megadriv_vdp_ctrl_port_r(running_machine &machine);
283   UINT16 megadriv_vdp_data_port_r(running_machine &machine);
284   void megadriv_vdp_data_port_w(running_machine &machine, int data);
285   void megadriv_vdp_ctrl_port_w(running_machine &machine, int data);
277   UINT16 megadriv_vdp_ctrl_port_r();
278   UINT16 megadriv_vdp_data_port_r();
279   void megadriv_vdp_data_port_w(int data);
280   void megadriv_vdp_ctrl_port_w(int data);
286281   void update_m_vdp_code_and_address(void);
287282
288283
289284   void genesis_render_spriteline_to_spritebuffer(int scanline);
290285   void genesis_render_videoline_to_videobuffer(int scanline);
291   void genesis_render_videobuffer_to_screenbuffer(running_machine &machine, int scanline);
286   void genesis_render_videobuffer_to_screenbuffer(int scanline);
292287
293288   /* variables used during emulation - not saved */
294289   UINT8* m_sprite_renderline;
trunk/src/mame/machine/megadriv.c
r24758r24759
913913
914914
915915// this comes from the VDP on lines 240 (on) 241 (off) and is connected to the z80 irq 0
916void genesis_vdp_sndirqline_callback_genesis_z80(running_machine &machine, bool state)
916WRITE_LINE_MEMBER(md_base_state::genesis_vdp_sndirqline_callback_genesis_z80)
917917{
918   md_base_state *md_state = machine.driver_data<md_base_state>();
919   if (md_state->m_z80snd)
918   if (m_z80snd)
920919   {
921      if (state == true)
920      if (state == ASSERT_LINE)
922921      {
923         megadriv_z80_hold(machine);
922         megadriv_z80_hold(machine());
924923      }
925      else if (state == false)
924      else if (state == CLEAR_LINE)
926925      {
927         megadriv_z80_clear(machine);
926         megadriv_z80_clear(machine());
928927      }
929928   }
930929}
931930
932931// this comes from the vdp, and is connected to 68k irq level 6 (main vbl interrupt)
933void genesis_vdp_lv6irqline_callback_genesis_68k(running_machine &machine, bool state)
932WRITE_LINE_MEMBER(md_base_state::genesis_vdp_lv6irqline_callback_genesis_68k)
934933{
935   md_base_state *md_state = machine.driver_data<md_base_state>();
936   if (state == true)
937      md_state->m_maincpu->set_input_line(6, HOLD_LINE);
934   if (state == ASSERT_LINE)
935      m_maincpu->set_input_line(6, HOLD_LINE);
938936   else
939      md_state->m_maincpu->set_input_line(6, CLEAR_LINE);
937      m_maincpu->set_input_line(6, CLEAR_LINE);
940938}
941939
942940// this comes from the vdp, and is connected to 68k irq level 4 (raster interrupt)
943void genesis_vdp_lv4irqline_callback_genesis_68k(running_machine &machine, bool state)
941WRITE_LINE_MEMBER(md_base_state::genesis_vdp_lv4irqline_callback_genesis_68k)
944942{
945   md_base_state *md_state = machine.driver_data<md_base_state>();
946   if (state == true)
947      md_state->m_maincpu->set_input_line(4, HOLD_LINE);
943   if (state == ASSERT_LINE)
944      m_maincpu->set_input_line(4, HOLD_LINE);
948945   else
949      md_state->m_maincpu->set_input_line(4, CLEAR_LINE);
946      m_maincpu->set_input_line(4, CLEAR_LINE);
950947}
951948
952949/* Callback when the 68k takes an IRQ */
r24758r24759
10121009   MCFG_DEVICE_ADD("gen_vdp", SEGA_GEN_VDP, 0)
10131010   MCFG_DEVICE_CONFIG( sms_vdp_ntsc_intf )
10141011   MCFG_VIDEO_SET_SCREEN("megadriv")
1015   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, genesis_vdp_sndirqline_callback_genesis_z80);
1016   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, genesis_vdp_lv6irqline_callback_genesis_68k);
1017   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, genesis_vdp_lv4irqline_callback_genesis_68k);
1012   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_sndirqline_callback_genesis_z80));
1013   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_lv6irqline_callback_genesis_68k));
1014   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_lv4irqline_callback_genesis_68k));
10181015
1019
1020
10211016   MCFG_SCREEN_ADD("megadriv", RASTER)
10221017   MCFG_SCREEN_REFRESH_RATE(60)
10231018   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) // Vblank handled manually.
r24758r24759
10661061   MCFG_DEVICE_ADD("gen_vdp", SEGA_GEN_VDP, 0)
10671062   MCFG_DEVICE_CONFIG( sms_vdp_pal_intf )
10681063   MCFG_VIDEO_SET_SCREEN("megadriv")
1069   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, genesis_vdp_sndirqline_callback_genesis_z80);
1070   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, genesis_vdp_lv6irqline_callback_genesis_68k);
1071   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, genesis_vdp_lv4irqline_callback_genesis_68k);
1064   sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_sndirqline_callback_genesis_z80));
1065   sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_lv6irqline_callback_genesis_68k));
1066   sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, DEVCB2_WRITELINE(md_base_state, genesis_vdp_lv4irqline_callback_genesis_68k));
10721067
10731068   MCFG_SCREEN_ADD("megadriv", RASTER)
10741069   MCFG_SCREEN_REFRESH_RATE(50)
r24758r24759
13051300   {
13061301      if (!m_vdp->m_use_alt_timing)
13071302      {
1308         m_vdp->vdp_handle_eof(machine());
1303         m_vdp->vdp_handle_eof();
13091304         megadriv_scanline_timer->adjust(attotime::zero);
13101305      }
13111306   }
trunk/src/mame/machine/irobot.c
r24758r24759
2222
2323#define DISASSEMBLE_MB_ROM      0       /* generate a disassembly of the mathbox ROMs */
2424
25#define IR_CPU_STATE(m) \
25#define IR_CPU_STATE() \
2626   logerror(\
27         "%s, scanline: %d\n", (m).describe_context(), (m).primary_screen->vpos())
27         "%s, scanline: %d\n", machine().describe_context(), m_screen->vpos())
2828
2929
3030READ8_MEMBER(irobot_state::irobot_sharedmem_r)
r24758r24759
6363WRITE8_MEMBER(irobot_state::irobot_statwr_w)
6464{
6565   logerror("write %2x ", data);
66   IR_CPU_STATE(machine());
66   IR_CPU_STATE();
6767
6868   m_combase = m_comRAM[data >> 7];
6969   m_combase_mb = m_comRAM[(data >> 7) ^ 1];
r24758r24759
8181         logerror("vg start ");
8282      else
8383         logerror("vg start [busy!] ");
84      IR_CPU_STATE(machine());
84      IR_CPU_STATE();
8585      m_irvg_timer->adjust(attotime::from_msec(10));
8686#endif
8787      m_irvg_running=1;
r24758r24759
206206   int d=0;
207207
208208   logerror("status read. ");
209   IR_CPU_STATE(machine());
209   IR_CPU_STATE();
210210
211211   if (!m_irmb_running) d |= 0x20;
212212   if (m_irvg_running) d |= 0x40;
r24758r24759
800800   {
801801      m_irmb_timer->adjust(attotime::from_hz(12000000) * icount);
802802      logerror("mb start ");
803      IR_CPU_STATE(machine());
803      IR_CPU_STATE();
804804   }
805805   else
806806   {
807807      logerror("mb start [busy!] ");
808      IR_CPU_STATE(machine());
808      IR_CPU_STATE();
809809      m_irmb_timer->adjust(attotime::from_hz(200) * icount);
810810   }
811811#else
trunk/src/mame/includes/megadriv.h
r24758r24759
128128   read8_delegate m_megadrive_io_read_data_port_ptr;
129129   write16_delegate m_megadrive_io_write_data_port_ptr;
130130
131   WRITE_LINE_MEMBER(genesis_vdp_sndirqline_callback_genesis_z80);
132   WRITE_LINE_MEMBER(genesis_vdp_lv6irqline_callback_genesis_68k);
133   WRITE_LINE_MEMBER(genesis_vdp_lv4irqline_callback_genesis_68k);
131134
132135   TIMER_CALLBACK_MEMBER( io_timeout_timer_callback );
133136   void megadrive_reset_io();
r24758r24759
256259   int m_segac2_sp_pal_lookup[4];
257260   void recompute_palette_tables();
258261
262   DECLARE_WRITE_LINE_MEMBER(genesis_vdp_sndirqline_callback_segac2);
263   DECLARE_WRITE_LINE_MEMBER(genesis_vdp_lv6irqline_callback_segac2);
264   DECLARE_WRITE_LINE_MEMBER(genesis_vdp_lv4irqline_callback_segac2);
265
259266   DECLARE_WRITE16_MEMBER( segac2_upd7759_w );
260267   DECLARE_READ16_MEMBER( palette_r );
261268   DECLARE_WRITE16_MEMBER( palette_w );
trunk/src/mame/includes/segas18.h
r24758r24759
101101   DECLARE_READ16_MEMBER( genesis_vdp_r );
102102   DECLARE_WRITE16_MEMBER( genesis_vdp_w );
103103
104   DECLARE_WRITE_LINE_MEMBER(genesis_vdp_sndirqline_callback_segas18);
105   DECLARE_WRITE_LINE_MEMBER(genesis_vdp_lv6irqline_callback_segas18);
106   DECLARE_WRITE_LINE_MEMBER(genesis_vdp_lv4irqline_callback_segas18);
104107
108
105109   // custom I/O
106110   DECLARE_READ16_MEMBER( ddcrew_custom_io_r );
107111   DECLARE_READ16_MEMBER( lghost_custom_io_r );
trunk/src/mame/includes/esripsys.h
r24758r24759
9595   DECLARE_WRITE8_MEMBER(frame_w);
9696   DECLARE_READ8_MEMBER(fdt_r);
9797   DECLARE_WRITE8_MEMBER(fdt_w);
98   static UINT8 static_rip_status_in(running_machine &machine);
99   UINT8 rip_status_in();
98100   DECLARE_WRITE8_MEMBER(g_iobus_w);
99101   DECLARE_READ8_MEMBER(g_iobus_r);
100102   DECLARE_WRITE8_MEMBER(g_ioadd_w);
trunk/src/mame/includes/itech8.h
r24758r24759
6565   UINT8 m_grmatch_palcontrol;
6666   UINT8 m_grmatch_xscroll;
6767   rgb_t m_grmatch_palette[2][16];
68   static void static_generate_interrupt(running_machine &machine, int state_num);
69   void generate_interrupt(int state_num);
6870   DECLARE_WRITE8_MEMBER(itech8_nmi_ack_w);
6971   DECLARE_WRITE8_MEMBER(blitter_w);
7072   DECLARE_WRITE8_MEMBER(rimrockn_bank_w);
trunk/src/mame/includes/dynax.h
r24758r24759
191191   DECLARE_WRITE8_MEMBER(hjingi_bank_w);
192192   DECLARE_WRITE8_MEMBER(hjingi_lockout_w);
193193   DECLARE_WRITE8_MEMBER(hjingi_hopper_w);
194   UINT8 hjingi_hopper_bit();
194195   DECLARE_READ8_MEMBER(hjingi_keyboard_0_r);
195196   DECLARE_READ8_MEMBER(hjingi_keyboard_1_r);
196197   DECLARE_WRITE8_MEMBER(yarunara_input_w);

Previous 199869 Revisions Next


© 1997-2024 The MAME Team