Previous 199869 Revisions Next

r36061 Sunday 22nd February, 2015 at 18:39:07 UTC by Fabio Priuli
(MESS) sms: improved the code for the Light Phaser, by simplifying the routines
and making them slightly faster. [Enik Land]
[/branches/kale/src/emu/bus/gamegear]ggext.c ggext.h smsctrladp.h
[/branches/kale/src/emu/bus/sega8]sega8_slot.c
[/branches/kale/src/emu/bus/sms_ctrl]lphaser.c
[/branches/kale/src/emu/video]315_5124.c 315_5124.h
[/branches/kale/src/mess/includes]sms.h
[/branches/kale/src/mess/machine]sms.c

branches/kale/src/emu/bus/gamegear/ggext.c
r244572r244573
11/**********************************************************************
22
33    Sega Game Gear EXT port emulation
4    Also known as Gear-to-Gear (or VS, in Japan) cable connector
45
56    Copyright MESS Team.
67    Visit http://mamedev.org for licensing and usage restrictions.
branches/kale/src/emu/bus/gamegear/ggext.h
r244572r244573
11/**********************************************************************
22
33    Sega Game Gear EXT port emulation
4    Also known as Gear-to-Gear (or VS, in Japan) cable connector
45
56    Copyright MESS Team.
67    Visit http://mamedev.org for licensing and usage restrictions.
branches/kale/src/emu/bus/gamegear/smsctrladp.h
r244572r244573
1616
1717#include "emu.h"
1818#include "ggext.h"
19#include "../sms_ctrl/smsctrl.h"
19#include "bus/sms_ctrl/smsctrl.h"
2020
2121
2222
branches/kale/src/emu/bus/sega8/sega8_slot.c
r244572r244573
253253   {
254254      if (!memcmp(&rom[0x7ff0], signatures[0], 16) || !memcmp(&rom[0x7ff0], signatures[1], 16))
255255         xoff = 26;
256
257      if (!memcmp(&rom[0x7ff0], signatures[2], 16))
256      else if (!memcmp(&rom[0x7ff0], signatures[2], 16))
258257         xoff = 36;
259
260      if (!memcmp(&rom[0x7ff0], signatures[3], 16))
258      else if (!memcmp(&rom[0x7ff0], signatures[3], 16))
261259         xoff = 32;
262
263      if (!memcmp(&rom[0x7ff0], signatures[4], 16))
260      else if (!memcmp(&rom[0x7ff0], signatures[4], 16))
264261         xoff = 30;
265
266      if (!memcmp(&rom[0x7ff0], signatures[5], 16))
262      else if (!memcmp(&rom[0x7ff0], signatures[5], 16))
267263         xoff = 39;
268
269      if (!memcmp(&rom[0x7ff0], signatures[6], 16))
264      else if (!memcmp(&rom[0x7ff0], signatures[6], 16))
270265         xoff = 38;
271266   }
272267
branches/kale/src/emu/bus/sms_ctrl/lphaser.c
r244572r244573
137137{
138138   const int r_x_r = LGUN_RADIUS * LGUN_RADIUS;
139139   const rectangle &visarea = m_screen->visible_area();
140   rectangle aim_area;
140141   int beam_x = m_screen->hpos();
141142   int beam_y = m_screen->vpos();
142   int dx, dy;
143   int result = 1;
144   int pos_changed = 0;
143   int beam_x_orig = beam_x;
144   int beam_y_orig = beam_y;
145   int dy, result = 1;
145146   double dx_radius;
147   bool new_check_point = false;
146148
147   while (1)
149   aim_area.min_y = MAX(lgun_y - LGUN_RADIUS, visarea.min_y);
150   aim_area.max_y = MIN(lgun_y + LGUN_RADIUS, visarea.max_y);
151
152   while (!new_check_point)
148153   {
149      /* If beam's y isn't at a line where the aim area is, change it
150         the next line it enters that area. */
151      dy = abs(beam_y - lgun_y);
152      if (dy > LGUN_RADIUS || beam_y < visarea.min_y || beam_y > visarea.max_y)
154      /* If beam's y doesn't point to a line where the aim area is,
155         change it to the first line where the beam enters that area. */
156      if (beam_y < aim_area.min_y || beam_y > aim_area.max_y)
153157      {
154         beam_y = lgun_y - LGUN_RADIUS;
155         if (beam_y < visarea.min_y)
156            beam_y = visarea.min_y;
157         dy = abs(beam_y - lgun_y);
158         pos_changed = 1;
158         beam_y = aim_area.min_y;
159159      }
160      dy = abs(beam_y - lgun_y);
160161
161162      /* Caculate distance in x of the radius, relative to beam's y distance.
162163         First try some shortcuts. */
r244572r244573
175176         dx_radius = ceil((float) sqrt((float) (r_x_r - (dy * dy))));
176177      }
177178
178      /* If beam's x isn't in the circular aim area, change it
179         to the next point it enters that area. */
180      dx = abs(beam_x - lgun_x);
181      if (dx > dx_radius || beam_x < visarea.min_x || beam_x > visarea.max_x)
179      aim_area.min_x = MAX(lgun_x - dx_radius, visarea.min_x);
180      aim_area.max_x = MIN(lgun_x + dx_radius, visarea.max_x);
181
182      while (!new_check_point)
182183      {
183         /* If beam's x has passed the aim area, advance to
184            next line and recheck y/x coordinates. */
185         if (beam_x > lgun_x)
184         /* If beam's x has passed the aim area, change it to the
185            next line and go back to recheck y/x coordinates. */
186         if (beam_x > aim_area.max_x)
186187         {
187            beam_x = 0;
188            beam_x = visarea.min_x;
188189            beam_y++;
189            continue;
190            break;
190191         }
191         beam_x = lgun_x - dx_radius;
192         if (beam_x < visarea.min_x)
193            beam_x = visarea.min_x;
194         pos_changed = 1;
195      }
196192
197      if (pos_changed)
198         break;
193         /* If beam's x isn't in the aim area, change it to the
194            next point where the beam enters that area. */
195         if (beam_x < aim_area.min_x)
196         {
197            beam_x = aim_area.min_x;
198         }
199199
200      if (m_sensor_last_state == 0) /* sensor is on */
201      {
202         /* keep sensor on until out of the aim area */
203         result = 0;
204      }
205      else
206      {
207         rgb_t color;
208         UINT8 brightness;
209         /* brightness of the lightgray color in the frame drawn by Light Phaser games */
210         const UINT8 sensor_min_brightness = 0x7f;
200         if (beam_x_orig != beam_x || beam_y_orig != beam_y)
201         {
202            /* adopt the new coordinates to adjust the timer */
203            new_check_point = true;
204            break;
205         }
211206
212         color = m_port->pixel_r();
207         if (m_sensor_last_state == 0)
208         {
209            /* sensor is already on */
210            /* keep sensor on until out of the aim area */
211            result = 0;
212         }
213         else
214         {
215            rgb_t color;
216            UINT8 brightness;
217            /* brightness of the lightgray color in the frame drawn by Light Phaser games */
218            const UINT8 sensor_min_brightness = 0x7f;
213219
214         /* reference: http://www.w3.org/TR/AERT#color-contrast */
215         brightness = (color.r() * 0.299) + (color.g() * 0.587) + (color.b() * 0.114);
216         //printf ("color brightness: %2X for x %d y %d\n", brightness, beam_x, beam_y);
220            color = m_port->pixel_r();
217221
218         result = (brightness >= sensor_min_brightness) ? 0 : 1;
219      }
222            /* reference: http://www.w3.org/TR/AERT#color-contrast */
223            brightness = (color.r() * 0.299) + (color.g() * 0.587) + (color.b() * 0.114);
224            //printf ("color brightness: %2X for x %d y %d\n", brightness, beam_x, beam_y);
220225
221      if (result == 0)
222      {
223         /* Set next check for when sensor will be off */
224         beam_x = lgun_x + dx_radius + 1;
225         if (beam_x > visarea.max_x)
226            beam_x = visarea.max_x + 1;
227         break;
226            result = (brightness >= sensor_min_brightness) ? 0 : 1;
227         }
228
229         if (result == 0) /* sensor on */
230         {
231            /* Set next check for when sensor will be off */
232            beam_x = aim_area.max_x + 1;
233
234            /* adopt the new coordinates to adjust the timer */
235            new_check_point = true;
236         }
237         else
238         {
239            /* Next check will happen after the minimum interval */
240            beam_x += LGUN_X_INTERVAL;
241         }
228242      }
229      else
230      {
231         /* Next check after the minimum interval */
232         beam_x += LGUN_X_INTERVAL;
233         pos_changed = 1;
234      }
235243   }
244
236245   timer->adjust(m_screen->time_until_pos(beam_y, beam_x));
237
238246   return result;
239247}
240248
branches/kale/src/emu/video/315_5124.c
r244572r244573
254254      }
255255   }
256256
257   set_frame_timing();
258   m_cram_dirty = 1;
259}
260
261
262void sega315_5124_device::set_frame_timing()
263{
257264   switch (m_y_pixels)
258265   {
259   case 192:
260      m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192;
261      break;
266      case 192:
267         m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192;
268         break;
262269
263   case 224:
264      m_frame_timing = (m_is_pal) ? pal_224 : ntsc_224;
265      break;
270      case 224:
271         m_frame_timing = (m_is_pal) ? pal_224 : ntsc_224;
272         break;
266273
267   case 240:
268      m_frame_timing = (m_is_pal) ? pal_240 : ntsc_240;
269      break;
274      case 240:
275         m_frame_timing = (m_is_pal) ? pal_240 : ntsc_240;
276         break;
270277   }
271   m_cram_dirty = 1;
272278}
273279
274280
r244572r244573
675681      case 2:     /* VDP register write */
676682         reg_num = data & 0x0f;
677683         m_reg[reg_num] = m_addr & 0xff;
678         //logerror("%s: %s: setting register %x to %02x\n", machine().describe_context(), tag(), reg_num, m_addr & 0xf );
684         //logerror("%s: %s: setting register %x to %02x\n", machine().describe_context(), tag(), reg_num, m_addr & 0xff);
679685
680686         switch (reg_num)
681687         {
r244572r244573
14411447{
14421448   int i;
14431449
1444   /* Exit if palette is has no changes */
1450   /* Exit if palette has no changes */
14451451   if (m_cram_dirty == 0)
14461452   {
14471453      return;
r244572r244573
14681474{
14691475   int i;
14701476
1471   /* Exit if palette is has no changes */
1477   /* Exit if palette has no changes */
14721478   if (m_cram_dirty == 0)
14731479   {
14741480      return;
r244572r244573
15571563
15581564void sega315_5124_device::vdp_postload()
15591565{
1560   switch (m_y_pixels)
1561   {
1562      case 192:
1563         m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192;
1564         break;
1565
1566      case 224:
1567         m_frame_timing = (m_is_pal) ? pal_224 : ntsc_224;
1568         break;
1569
1570      case 240:
1571         m_frame_timing = (m_is_pal) ? pal_240 : ntsc_240;
1572         break;
1573   }
1566   set_frame_timing();
15741567}
15751568
15761569void sega315_5124_device::device_start()
branches/kale/src/emu/video/315_5124.h
r244572r244573
9191
9292protected:
9393   void set_display_settings();
94   void set_frame_timing();
9495   virtual void update_palette();
9596   virtual void cram_write(UINT8 data);
9697   virtual void draw_scanline( int pixel_offset_x, int pixel_plot_y, int line );
branches/kale/src/mess/includes/sms.h
r244572r244573
1919#define CONTROL1_TAG   "ctrl1"
2020#define CONTROL2_TAG   "ctrl2"
2121
22#include "bus/sega8/sega8_slot.h"
23#include "bus/sms_exp/smsexp.h"
24#include "bus/sms_ctrl/smsctrl.h"
2225#include "bus/gamegear/ggext.h"
23#include "bus/sms_ctrl/smsctrl.h"
24#include "bus/sms_exp/smsexp.h"
25#include "bus/sega8/sega8_slot.h"
2626
2727
2828class sms_state : public driver_device
r244572r244573
3232      : driver_device(mconfig, type, tag),
3333      m_maincpu(*this, "maincpu"),
3434      m_vdp(*this, "sms_vdp"),
35      m_main_scr(*this, "screen"),
3536      m_ym(*this, "ym2413"),
36      m_main_scr(*this, "screen"),
37      m_region_maincpu(*this, "maincpu"),
3837      m_port_ctrl1(*this, CONTROL1_TAG),
3938      m_port_ctrl2(*this, CONTROL2_TAG),
4039      m_port_gg_ext(*this, "ext"),
r244572r244573
4544      m_port_scope(*this, "SEGASCOPE"),
4645      m_port_scope_binocular(*this, "SSCOPE_BINOCULAR"),
4746      m_port_persist(*this, "PERSISTENCE"),
47      m_region_maincpu(*this, "maincpu"),
4848      m_mainram(NULL),
4949      m_is_gamegear(0),
5050      m_is_gg_region_japan(0),
r244572r244573
6161   // devices
6262   required_device<cpu_device> m_maincpu;
6363   required_device<sega315_5124_device> m_vdp;
64   required_device<screen_device> m_main_scr;
6465   optional_device<ym2413_device> m_ym;
65   required_device<screen_device> m_main_scr;
66   required_memory_region m_region_maincpu;
6766   optional_device<sms_control_port_device> m_port_ctrl1;
6867   optional_device<sms_control_port_device> m_port_ctrl2;
6968   optional_device<gg_ext_port_device> m_port_gg_ext;
69
7070   optional_ioport m_port_gg_dc;
7171   optional_ioport m_port_pause;
7272   optional_ioport m_port_reset;
r244572r244573
7575   optional_ioport m_port_scope_binocular;
7676   optional_ioport m_port_persist;
7777
78   required_memory_region m_region_maincpu;
7879   address_space *m_space;
7980   UINT8 *m_mainram;
8081   UINT8 *m_BIOS;
r244572r244573
121122   UINT8 m_gg_sio[5];
122123   int m_paused;
123124
124   // Data needed for Light Phaser
125125   UINT8 m_ctrl1_th_state;
126126   UINT8 m_ctrl2_th_state;
127127   UINT8 m_ctrl1_th_latch;
128128   UINT8 m_ctrl2_th_latch;
129
130   // Data needed for Light Phaser
129131   int m_lphaser_x_offs;   /* Needed to 'calibrate' lphaser; set at cart loading */
130132
131133   // Data needed for SegaScope (3D glasses)
r244572r244573
160162   DECLARE_READ8_MEMBER(sms_input_port_dc_r);
161163   DECLARE_READ8_MEMBER(sms_input_port_dd_r);
162164   DECLARE_READ8_MEMBER(gg_input_port_00_r);
165   DECLARE_READ8_MEMBER(gg_sio_r);
163166   DECLARE_WRITE8_MEMBER(gg_sio_w);
164   DECLARE_READ8_MEMBER(gg_sio_r);
167   DECLARE_READ8_MEMBER(sms_fm_detect_r);
165168   DECLARE_WRITE8_MEMBER(sms_fm_detect_w);
166   DECLARE_READ8_MEMBER(sms_fm_detect_r);
167169   DECLARE_WRITE8_MEMBER(sms_ym2413_register_port_w);
168170   DECLARE_WRITE8_MEMBER(sms_ym2413_data_port_w);
169171   DECLARE_READ8_MEMBER(sms_sscope_r);
branches/kale/src/mess/machine/sms.c
r244572r244573
869869      // a bug in the program code. The only way this cartridge could have run
870870      // successfully on a real unit is if the RAM would be initialized with
871871      // a F0 pattern on power up; F0 = RET P.
872      // This initialization breaks the some Game Gear games though (e.g.
872      // This initialization breaks some Game Gear games though (e.g.
873873      // tempojr), suggesting that not all systems had the same initialization.
874      // This also breaks some homebrew software (e.g. Nine Pixels).
874875      // For the moment we apply this to systems that have the Japanese SMS
875876      // cartridge slot.
876877      if (m_has_jpn_sms_cart_slot)


Previous 199869 Revisions Next


© 1997-2024 The MAME Team