Previous 15994 Revisions Next

r6604 Friday 11th December, 2009 at 08:18:38 UTC by Fabio Priuli
[SMS] Added Reset button to SMS1 and improved Lightgun behavior based on "Color & Switch Test". [Enik Land]
[docs]messnew.txt
[src/mess/drivers]sms.c
[src/mess/machine]sms.c
[src/mess/video]smsvdp.c smsvdp.h

src/mess/video/smsvdp.c
r6603r6604
12891289}
12901290
12911291
1292static UINT8 color_brightness(rgb_t color)
1293{
1294   /* reference: http://www.w3.org/TR/AERT#color-contrast */
1295   UINT8 brightness = (RGB_RED(color) * 0.299) + (RGB_GREEN(color) * 0.587) + (RGB_BLUE(color) * 0.114);
1296   //printf ("color brightness: %2X\n", brightness);
1297   return brightness;
1298}
1299
1300
1301UINT8 sms_vdp_area_brightness(const device_config *device, int x, int y, int x_range, int y_range)
1302{
1303   int beam_x, beam_y;
1304   int dx, dy;
1305   int vint_line;
1306   smsvdp_t *smsvdp;
1307
1308   if (x < LBORDER_START + LBORDER_X_PIXELS || x >= LBORDER_START + LBORDER_X_PIXELS + 256)
1309   {
1310      return 0x00;
1311   }
1312
1313   smsvdp = get_safe_token(device);
1314
1315   beam_x = video_screen_get_hpos(device->machine->primary_screen);
1316   beam_y = video_screen_get_vpos(device->machine->primary_screen);
1317   dx = x - beam_x;
1318   dy = y - beam_y;
1319
1320   if (abs(dy) <= y_range && abs(dx) <= x_range)
1321   {
1322      rgb_t color = *BITMAP_ADDR32(smsvdp->tmpbitmap, beam_y, beam_x);
1323      return color_brightness(color);
1324   }
1325
1326   /* Color & Switch Test ROM check TH after the line where VINT    */
1327   /* occurs (237 for NTSC/192 mode). Until details are not figured */
1328   /* out, calculate VINT line and use it for this special case.    */
1329   vint_line = smsvdp->sms_frame_timing[VERTICAL_BLANKING] + smsvdp->sms_frame_timing[TOP_BLANKING]
1330             + smsvdp->sms_frame_timing[TOP_BORDER] + smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]
1331             + 1;
1332
1333   if (beam_y == vint_line + 1 && abs(dx) <= x_range)
1334   {
1335      rgb_t color = *BITMAP_ADDR32(smsvdp->tmpbitmap, y, x);
1336      return color_brightness(color);
1337   }
1338
1339   return 0x00;
1340}
1341
1342
12921343static void sms_update_palette( smsvdp_t *smsvdp )
12931344{
12941345   int i;
r6603r6604
14051456
14061457   /* Make temp bitmap for rendering */
14071458   smsvdp->tmpbitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED32);
1408
14091459   smsvdp->prev_bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED32);
14101460
1411
14121461   smsvdp->smsvdp_display_timer = timer_alloc(device->machine, smsvdp_display_callback, smsvdp);
14131462   timer_adjust_periodic(smsvdp->smsvdp_display_timer, video_screen_get_time_until_pos(screen, 0, 0), 0, video_screen_get_scan_period(screen));
14141463
r6603r6604
14291478   state_save_register_device_item(device, 0, smsvdp->prev_bitmap_saved);
14301479   state_save_register_device_item_array(device, 0, smsvdp->reg);
14311480   state_save_register_device_item_array(device, 0, smsvdp->current_palette);
1481   state_save_register_device_item_pointer(device, 0, smsvdp->line_buffer, 256 * 5);
1482   state_save_register_device_item_pointer(device, 0, smsvdp->collision_buffer, SMS_X_PIXELS);
1483   state_save_register_device_item_bitmap(device, 0, smsvdp->tmpbitmap);
1484   state_save_register_device_item_bitmap(device, 0, smsvdp->prev_bitmap);
14321485}
14331486
14341487static DEVICE_RESET( smsvdp )
src/mess/video/smsvdp.h
r6603r6604
8888READ8_DEVICE_HANDLER( sms_vdp_ctrl_r );
8989WRITE8_DEVICE_HANDLER( sms_vdp_ctrl_w );
9090void sms_vdp_set_ggsmsmode( const device_config *device, int mode );
91UINT8 sms_vdp_area_brightness( const device_config *device, int x, int y, int x_range, int y_range );
9192
9293#endif /* __SMSVDP_H__ */
src/mess/machine/sms.c
r6603r6604
6767   
6868   /* Data needed for Light Phaser */
6969   UINT16 lphaser_latch;
70   UINT16 lphaser_1_x;
71   UINT16 lphaser_1_y;
72   UINT16 lphaser_2_x;
73   UINT16 lphaser_2_y;
7470   int lphaser_x_offs;   /* Needed to 'calibrate' lphaser; set at cart loading */
7571
7672   /* Data needed for SegaScope (3D glasses) */
r6603r6604
188184static UINT8 sms_vdp_hcount( running_machine *machine )
189185{
190186   UINT8 tmp;
191   UINT64 calc_cycles;
192   attotime time_end;
193187   const device_config *screen = video_screen_first(machine->config);
188   int hpos = video_screen_get_hpos(screen);
194189
195   //int hpos = video_screen_get_hpos(screen);
190   /* alternative method: pass HCounter test, but some others fail */
191   //int hpos_tmp = hpos;
192   //if ((hpos + 2) % 6 == 0) hpos_tmp--;
193   //tmp = ((hpos_tmp - 46) >> 1) & 0xff;
194
195   UINT64 calc_cycles;
196   attotime time_end;
196197   int vpos = video_screen_get_vpos(screen);
197   int width = video_screen_get_width(screen);
198   
199   /* this is simpler and independent of other clocks */
200   //tmp = ((hpos - 46) >> 1) & 0xff;
201   
202   /* ... but this is closer to the behavior described by Flubba */
203   /* and makes use of his equation posted at SMSPower forum.    */
204   time_end = video_screen_get_time_until_pos(screen, vpos, width - 1);
198   int max_hpos = video_screen_get_width(screen) - 1;
199
200   if (hpos == max_hpos)
201      time_end = attotime_zero;
202   else
203      time_end = video_screen_get_time_until_pos(screen, vpos, max_hpos);
205204   calc_cycles = cpu_attotime_to_clocks(cputag_get_cpu(machine, "maincpu"), time_end);
205
206   /* equation got from SMSPower forum, posted by Flubba. */
206207   tmp = ((590 - (calc_cycles * 3)) / 4) & 0xff;
207   
208
208209   //printf ("sms_vdp_hcount: hpos %3d => hcount %2X\n", hpos, tmp);
209210   return tmp;
210211}
r6603r6604
218219   sms_vdp_hcount_latch_w(smsvdp, 0, value);
219220}
220221
221static int lphaser_sensor_is_on( running_machine *machine, int x, int y )
222{
223   const device_config *screen = video_screen_first(machine->config);
224   int dx, dy;
225   //const int r_x_r = 20 * 20; /* radius^2 */
226   int hpos, vpos;
227   
228   if (x < LBORDER_START + LBORDER_X_PIXELS || x >= LBORDER_START + LBORDER_X_PIXELS + 256)
229   {
230      sms_state.lphaser_latch = 0;
231      return 0;
232   }
233   
234   hpos = video_screen_get_hpos(screen);
235   vpos = video_screen_get_vpos(screen);
236   
237   /* some offset seems needed for sms_vdp_hcount_latch() */
238   //hpos -= 44;
239   
240   dx = x - hpos;
241   dy = y - vpos;
242   
243   //printf ("Light Phaser polling at %3d x %3d for shot %3d x %3d\n", hpos, vpos, x, y);
244   
245   /* SMSPower Wiki: the Light Phaser sensor "sees" a circular portion of the screen */
246   //if ( (dx * dx) + (dy * dy) - (r_x_r) <= 0 )
247   if (abs(dy) <= 5 && abs(dx) <= 60) /* simpler method used by SMSPlus-GX */
248   {
249      /* avoid latching hcount more than once in a line */
250      if (sms_state.lphaser_latch == 0)
251      {
252         sms_state.lphaser_latch = 1;
253         //sms_vdp_hcount_latch(screen);
254         /* FIXME: sms_vdp_hcount_lphaser() is a hack necessary while normal latch gives too inconstant shot positions */
255         x += sms_state.lphaser_x_offs;
256         sms_vdp_hcount_lphaser(machine, x);
257      }
258222
259      return 1;
260   }
261   else
262   {
263      sms_state.lphaser_latch = 0;
264      return 0;
265   }
266}
267
268
269223static UINT16 screen_hpos_nonscaled( const device_config *screen, int scaled_hpos )
270224{
271225   const rectangle *visarea = video_screen_get_visible_area(screen);
r6603r6604
282236}
283237
284238
239static int lphaser_sensor_is_on( running_machine *machine, const char *tag_x, const char *tag_y )
240{
241   int x = screen_hpos_nonscaled(machine->primary_screen, input_port_read(machine, tag_x));
242   int y = screen_vpos_nonscaled(machine->primary_screen, input_port_read(machine, tag_y));
243
244   if (sms_vdp_area_brightness(devtag_get_device(machine, "sms_vdp"), x, y, 60, 5) >= 0x7f)
245   {
246      /* avoid latching hcount more than once in a line */
247      if (sms_state.lphaser_latch == 0)
248      {
249         sms_state.lphaser_latch = 1;
250         //sms_vdp_hcount_latch(machine);
251         /* FIXME: sms_vdp_hcount_lphaser() is a hack necessary while normal latch gives too inconstant shot positions */
252         x += sms_state.lphaser_x_offs;
253         sms_vdp_hcount_lphaser(machine, x);
254      }
255      return 1;
256   }
257
258   sms_state.lphaser_latch = 0;
259   return 0;
260}
261
262
285263static void sms_get_inputs( const address_space *space )
286264{
287265   UINT8 data = 0x00;
288   UINT8 data_x = 0x00;
289   UINT8 data_y = 0x00;
290266   UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu);
291267   running_machine *machine = space->machine;
292268
r6603r6604
324300      {
325301         if (input_port_read(machine, "RFU") & 0x01)
326302            data |= sms_state.rapid_fire_state_1 & 0x10;
327
328         data_x = input_port_read(machine, "LPHASER0");
329         data_y = input_port_read(machine, "LPHASER1");
330
331         sms_state.lphaser_1_x = screen_hpos_nonscaled(machine->primary_screen, data_x);
332         sms_state.lphaser_1_y = screen_vpos_nonscaled(machine->primary_screen, data_y);
333303      }
334304      /* just consider the button (trigger) bit */
335305      data |= ~0x10;
r6603r6604
392362      {
393363         if (input_port_read(machine, "RFU") & 0x04)
394364            data |= sms_state.rapid_fire_state_2 & 0x04;
395
396         data_x = input_port_read(machine, "LPHASER2");
397         data_y = input_port_read(machine, "LPHASER3");
398
399         sms_state.lphaser_2_x = screen_hpos_nonscaled (machine->primary_screen, data_x);
400         sms_state.lphaser_2_y = screen_vpos_nonscaled (machine->primary_screen, data_y);
401365      }
402366      /* just consider the button (trigger) bit */
403367      data |= ~0x04;
r6603r6604
544508      return 0xff;
545509   
546510   sms_get_inputs(space);
511
512   /* Reset Button */
513   sms_state.input_port1 = (sms_state.input_port1 & 0xef) | (input_port_read_safe(space->machine, "RESET", 0x01) & 0x01) << 4;
547514   
548515   /* Do region detection if TH of ports A and B are set to output (0) */
549516   if (!(sms_state.ctrl_reg & 0x0a))
r6603r6604
555522      if (sms_state.is_region_japan)
556523         sms_state.input_port1 ^= 0xc0;
557524   }
558   else if (sms_state.ctrl_reg & 0x02 && lphaser_sensor_is_on(space->machine, sms_state.lphaser_1_x, sms_state.lphaser_1_y))
525   else
559526   {
560      sms_state.input_port1 &= ~0x40;
527      if (sms_state.ctrl_reg & 0x02
528          && (input_port_read_safe(space->machine, "CTRLSEL", 0x00) & 0x0f) == 0x01
529          && lphaser_sensor_is_on(space->machine, "LPHASER0", "LPHASER1"))
530      {
531         sms_state.input_port1 &= ~0x40;
532      }
533      if (sms_state.ctrl_reg & 0x08
534          && (input_port_read_safe(space->machine, "CTRLSEL", 0x00) & 0xf0) == 0x10
535          && lphaser_sensor_is_on(space->machine, "LPHASER2", "LPHASER3"))
536      {   
537         sms_state.input_port1 &= ~0x80;
538      }   
561539   }
562   else if (sms_state.ctrl_reg & 0x08 && lphaser_sensor_is_on(space->machine, sms_state.lphaser_2_x, sms_state.lphaser_2_y))
563   {   
564      sms_state.input_port1 &= ~0x80;
565   }   
566     
540
567541   return sms_state.input_port1;
568542}
569543   
r6603r6604
14871461   sms_state.sports_pad_2_y = 0;
14881462
14891463   sms_state.lphaser_latch = 0;
1490   sms_state.lphaser_1_x = 0;
1491   sms_state.lphaser_1_y = 0;
1492   sms_state.lphaser_2_x = 0;
1493   sms_state.lphaser_2_x = 0;
14941464
14951465   sms_state.sscope_state = 0;
14961466
src/mess/drivers/sms.c
r6603r6604
171171   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_CATEGORY(20) PORT_PLAYER(2)
172172   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED ) /* Software Reset bit */
173173   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
174   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
175   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
174   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED ) /* Port A TH */
175   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED ) /* Port B TH */
176176
177177   PORT_START("PAUSE")
178178   PORT_BIT( 0x7f, IP_ACTIVE_LOW, IPT_UNUSED )
r6603r6604
246246static INPUT_PORTS_START( sms1 )
247247   PORT_INCLUDE( sms )
248248
249   PORT_START("RESET")
250   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("Reset Button")
251
249252   PORT_START("SEGASCOPE")
250253   PORT_CONFNAME( 0x01, 0x00, "SegaScope (3-D Glasses)" )
251254   PORT_CONFSETTING( 0x00, DEF_STR( Off ) )
docs/messnew.txt
r6603r6604
22
33New System Drivers Supported:
44-----------------------------
5- Consul 2717 with PMD-32 [Miodrag Milanovic]
56- Elektor SC/MP [Miodrag Milanovic]
67- Hawthorne Technologies TinyGiant HT68k [Miodrag Milanovic]
78- Hector MX40c [JJ Stacino]
89- Hector MX80c [JJ Stacino]
910- Microsystems International Limited MOD-8 [Miodrag Milanovic]
11- MITS Altair 8800bt [Miodrag Milanovic]
12- Robotron K1003 [Miodrag Milanovic]
1013- Science of Cambridge MK-14 [Miodrag Milanovic]
11- Robotron K1003 [Miodrag Milanovic]
12- MITS Altair 8800bt [Miodrag Milanovic]
13- Consul 2717 with PMD-32 [Miodrag Milanovic]
1414
15
16
1517Systems Promoted from GAME_NOT_WORKING:
1618---------------------------------------
1719- Ausbaufähiger Mikrocomputer mit dem U 880 (Huebler/Everts) [Curt Coder]
r6603r6604
2527
2628Skeleton drivers:
2729-----------------
30- Callan Unistar Terminal
31- Dual Systems 68000
2832- Exelvision Exeltel
29- Sharp PC-E220
3033- Hewlett-Packard HP16500b [R. Belmont]
34- Indiana University 68030 board
35- Intel SDK-85
36- Intel RPC 86
37- Intel iSBC 86/12A
38- Intel iSBC 286
39- Intel iSBC 286-10
40- MCS Basic 52
41- MCS Basic 31
3142- Micronic 1000 [Curt Coder]
3243- MITS Altair 680b
33- MCS Basic 52
34- MCS Basic 31
35- Sun-1
44- Morrow Designs Micro Decision MD-2 and MD-3
45- Morrow Tricep
46- NorthStar Horizon
3647- Plan-80
37- SAPI-1 ZPS 2
38- SAPI-1 ZPS 3
3948- Protec Pro-80
4049- PIMPS
4150- Sage II
42- NorthStar Horizon
51- SAPI-1 ZPS 2
52- SAPI-1 ZPS 3
53- Sharp PC-E220
54- Sun-1
55- SWTPC 68000
4356- Vector Graphic Vector 1+
44- Morrow Tricep
45- Indiana University 68030 board
4657- Vector Graphics - Vector 4
47- Callan Unistar Terminal
48- Dual Systems 68000
49- Intel SDK-85
50- Intel RPC 86
51- Intel iSBC 86/12A
52- Intel iSBC 286
53- Intel iSBC 286-10
54- Morrow Designs Micro Decision MD-2 and MD-3
55- SWTPC 68000
5658
59
60
5761System Driver Changes:
5862----------------------
5963- [BETA] Fixed display flickering. [Curt Coder]
r6603r6604
8690  Once enabled, remappable controls will also appear in the Input (this
8791  System) menu. [Fabio Priuli]
8892
93- [SMS] Added Reset button to SMS1 and improved Lightgun behavior based
94  on "Color & Switch Test". [Enik Land]
95
8996- [TI81] Added v1.6K BIOS dump. [critor]
9097
9198- [TI85/TI86] Converted the serial interface to a device. [Wilbert Pol]

Previous 15994 Revisions Next


© 1998-2018 The MESS Team