Previous 15994 Revisions Next

r1344 Wednesday 28th November, 2007 at 02:08:27 UTC by Nathan Woods
Miscellaneous cleanups; thanks to Michael Zapf for raising these issues
[src/mess/machine]kc.c nes.c
[src/mess/tools/imgtool/modules]ti99.c

src/mess/tools/imgtool/modules/ti99.c
r1343r1344
10241024      /* check information */
10251025      if ((totphysrecs != (l1_img->geometry.secspertrack * l1_img->geometry.cylinders * l1_img->geometry.heads))
10261026            || (totphysrecs < 2)
1027            || memcmp(vib->id, "DSK", 3) || (! strchr(" P", vib->id[3]))
1027            || memcmp(vib->id, "DSK", 3) || (! strchr(" P", vib->protection))
10281028            || (((img_format == if_mess) || (img_format == if_v9t9))
10291029               && (stream_size(file_handle) != totphysrecs*256)))
10301030         return IMGTOOLERR_CORRUPTIMAGE;
r1343r1344
50225022      /* delete parent catalog entry */
50235023      for (i=catalog_index; i<113; i++)
50245024         catalog.subdirs[i] = catalog.subdirs[i+1];
5025      catalog.subdirs[114].dir_ptr = 0;
5025      catalog.subdirs[113].dir_ptr = 0;
50265026      catalog.num_subdirs--;
50275027
50285028      /* update parent VIB/DDR */
src/mess/machine/nes.c
r1343r1344
1111
1212
1313
14/* Uncomment this to dump info about the inputs to the errorlog */
15//#define LOG_JOY
14/***************************************************************************
15    CONSTANTS
16***************************************************************************/
1617
17/* Uncomment this to generate prg chunk files when the cart is loaded */
18//#define SPLIT_PRG
18/* Set to dump info about the inputs to the errorlog */
19#define LOG_JOY      0
1920
21/* Set to generate prg chunk files when the cart is loaded */
22#define SPLIT_PRG   0
23
2024#define BATTERY_SIZE 0x2000
25
26
27
28/***************************************************************************
29    TYPE DEFINITIONS
30***************************************************************************/
31
32typedef struct _nes_input nes_input;
33struct _nes_input
34{
35   UINT32 shift;
36   UINT32 i0, i1, i2;
37};
38
39
40
41/***************************************************************************
42    GLOBAL VARIABLES
43***************************************************************************/
44
2145UINT8 battery_data[BATTERY_SIZE];
2246
2347struct nes_struct nes;
2448struct fds_struct nes_fds;
2549
26static UINT32 in_0[3];
27static UINT32 in_1[3];
28static UINT32 in_0_shift;
29static UINT32 in_1_shift;
50static nes_input in_0;
51static nes_input in_1;
3052
31/* local prototypes */
53
54
55/***************************************************************************
56    FUNCTION PROTOTYPES
57***************************************************************************/
58
3259static void init_nes_core(void);
3360static void nes_machine_stop(running_machine *machine);
3461
62
63
64/***************************************************************************
65    FUNCTIONS
66***************************************************************************/
67
3568static mess_image *cartslot_image(void)
3669{
3770   return image_from_devtype_and_index(IO_CARTSLOT, 0);
r1343r1344
144177   mapper_reset (nes.mapper);
145178
146179   /* Reset the serial input ports */
147   in_0_shift = 0;
148   in_1_shift = 0;
180   in_0.shift = 0;
181   in_1.shift = 0;
149182}
150183
151184MACHINE_START( nes )
r1343r1344
173206
174207
175208
176static int zapper_hit_pixel(const UINT32 *input)
209static int zapper_hit_pixel(const nes_input *input)
177210{
178211   UINT16 pix = 0;
179212   rgb_t col;
r1343r1344
181214   extern mame_bitmap *nes_zapper_hack;
182215
183216   if (nes_zapper_hack)
184      pix = *BITMAP_ADDR16(nes_zapper_hack, input[2], input[1]);
217      pix = *BITMAP_ADDR16(nes_zapper_hack, input->i2, input->i1);
185218
186219   col = palette_get_color(Machine, pix);
187220   r = (UINT8) (col >> 16);
r1343r1344
202235   /* in the unused upper 3 bits, so typically a read from $4016 leaves 0x40 there. */
203236   retVal = 0x40;
204237
205   retVal |= ((in_0[0] >> in_0_shift) & 0x01);
238   retVal |= ((in_0.i0 >> in_0.shift) & 0x01);
206239
207240   /* Check the configuration to see what's connected */
208241   cfg = readinputport(PORT_CONFIG1);
r1343r1344
210243   if (((cfg & 0x000f) == 0x0002) || ((cfg & 0x000f) == 0x0003))
211244   {
212245      /* If button 1 is pressed, indicate the light gun trigger is pressed */
213      retVal |= ((in_0[0] & 0x01) << 4);
246      retVal |= ((in_0.i0 & 0x01) << 4);
214247
215248      /* Look at the screen and see if the cursor is over a bright pixel */
216      if (zapper_hit_pixel(in_0))
249      if (zapper_hit_pixel(&in_0))
217250         retVal &= ~0x08; /* sprite hit */
218251      else
219252         retVal |= 0x08;  /* no sprite hit */
220253   }
221254
222#ifdef LOG_JOY
223   logerror ("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", retVal, activecpu_get_pc(), in_0_shift, in_0[0]);
224#endif
255   if (LOG_JOY)
256      logerror ("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", retVal, activecpu_get_pc(), in_0.shift, in_0.i0);
225257
226   in_0_shift ++;
258   in_0.shift ++;
227259   return retVal;
228260}
229261
r1343r1344
237269   retVal = 0x40;
238270
239271   /* Handle data line 0's serial output */
240   retVal |= ((in_1[0] >> in_1_shift) & 0x01);
272   retVal |= ((in_1.i0 >> in_1.shift) & 0x01);
241273
242274   /* Check the fake dip to see what's connected */
243275   cfg = readinputport(PORT_CONFIG1);
r1343r1344
246278   {
247279      /* zapper */
248280      /* If button 1 is pressed, indicate the light gun trigger is pressed */
249      retVal |= ((in_1[0] & 0x01) << 4);
281      retVal |= ((in_1.i0 & 0x01) << 4);
250282
251283      /* Look at the screen and see if the cursor is over a bright pixel */
252      if (zapper_hit_pixel(in_1))
284      if (zapper_hit_pixel(&in_1))
253285         retVal &= ~0x08; /* sprite hit */
254286      else
255287         retVal |= 0x08;  /* no sprite hit */
r1343r1344
258290   {
259291      /* arkanoid dial */
260292      /* Handle data line 2's serial output */
261      retVal |= ((in_1[2] >> in_1_shift) & 0x01) << 3;
293      retVal |= ((in_1.i2 >> in_1.shift) & 0x01) << 3;
262294
263295      /* Handle data line 3's serial output - bits are reversed */
264//      retVal |= ((in_1[3] >> in_1_shift) & 0x01) << 4;
265      retVal |= ((in_1[3] << in_1_shift) & 0x80) >> 3;
296      /* NPW 27-Nov-2007 - there is no third subscript! commenting out */
297      /* retVal |= ((in_1[3] >> in_1.shift) & 0x01) << 4; */
298      /* retVal |= ((in_1[3] << in_1.shift) & 0x80) >> 3; */
266299   }
267300
268#ifdef LOG_JOY
269   logerror ("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", retVal, activecpu_get_pc(), in_1_shift, in_1[0]);
270#endif
301   if (LOG_JOY)
302      logerror ("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", retVal, activecpu_get_pc(), in_1.shift, in_1.i0);
271303
272   in_1_shift ++;
304   in_1.shift ++;
273305   return retVal;
274306}
275307
276308
277309
278static void nes_read_input_device(int cfg, UINT32 *vals, int pad_port,
310static void nes_read_input_device(int cfg, nes_input *vals, int pad_port,
279311   int supports_zapper, int paddle_port)
280312{
281   vals[0] = 0;
282   vals[1] = 0;
283   vals[2] = 0;
313   vals->i0 = 0;
314   vals->i1 = 0;
315   vals->i2 = 0;
284316   
285317   switch(cfg & 0x0f)
286318   {
287319      case 0x01:   /* gamepad */
288320         if (pad_port >= 0)
289            vals[0] = readinputport(pad_port);
321            vals->i0 = readinputport(pad_port);
290322         break;
291323
292324      case 0x02:   /* zapper 1 */
293325         if (supports_zapper)
294326         {
295            vals[0] = readinputport(PORT_ZAPPER0_T);
296            vals[1] = readinputport(PORT_ZAPPER0_X);
297            vals[2] = readinputport(PORT_ZAPPER0_Y);
327            vals->i0 = readinputport(PORT_ZAPPER0_T);
328            vals->i1 = readinputport(PORT_ZAPPER0_X);
329            vals->i2 = readinputport(PORT_ZAPPER0_Y);
298330         }
299331         break;
300332
301333      case 0x03:   /* zapper 2 */
302334         if (supports_zapper)
303335         {
304            vals[0] = readinputport(PORT_ZAPPER1_T);
305            vals[1] = readinputport(PORT_ZAPPER1_X);
306            vals[2] = readinputport(PORT_ZAPPER1_Y);
336            vals->i0 = readinputport(PORT_ZAPPER1_T);
337            vals->i1 = readinputport(PORT_ZAPPER1_X);
338            vals->i2 = readinputport(PORT_ZAPPER1_Y);
307339         }
308340         break;
309341
310342      case 0x04:   /* arkanoid paddle */
311343         if (paddle_port >= 0)
312            vals[0] = (UINT8) ((UINT8) readinputport (paddle_port) + (UINT8)0x52) ^ 0xff;
344            vals->i0 = (UINT8) ((UINT8) readinputport (paddle_port) + (UINT8)0x52) ^ 0xff;
313345         break;
314346   }
315347}
r1343r1344
319351WRITE8_HANDLER ( nes_IN0_w )
320352{
321353   int cfg;
322   UINT32 in_2[3];
323   UINT32 in_3[3];
354   nes_input in_2;
355   nes_input in_3;
324356
325357   if (data & 0x01) return;
326#ifdef LOG_JOY
327   logerror ("joy 0 bits read: %d\n", in_0_shift);
328#endif
329358
359   if (LOG_JOY)
360      logerror ("joy 0 bits read: %d\n", in_0.shift);
361
330362   /* Toggling bit 0 high then low resets both controllers */
331   in_0_shift = 0;
332   in_1_shift = 0;
363   in_0.shift = 0;
364   in_1.shift = 0;
333365
334366   /* Check the configuration to see what's connected */
335367   cfg = readinputport(PORT_CONFIG1);
336368
337369   /* Read the input devices */
338   nes_read_input_device(cfg >>  0, in_0, PORT_PAD0,  TRUE, -1);
339   nes_read_input_device(cfg >>  4, in_1, PORT_PAD1,  TRUE, PORT_PADDLE1);
340   nes_read_input_device(cfg >>  8, in_2, PORT_PAD2, FALSE, -1);
341   nes_read_input_device(cfg >> 12, in_3, PORT_PAD3, FALSE, -1);
370   nes_read_input_device(cfg >>  0, &in_0, PORT_PAD0,  TRUE, -1);
371   nes_read_input_device(cfg >>  4, &in_1, PORT_PAD1,  TRUE, PORT_PADDLE1);
372   nes_read_input_device(cfg >>  8, &in_2, PORT_PAD2, FALSE, -1);
373   nes_read_input_device(cfg >> 12, &in_3, PORT_PAD3, FALSE, -1);
342374
343375   if (cfg & 0x0f00)
344      in_0[0] |= (in_2[0] << 8) | (0x08 << 16);
376      in_0.i0 |= (in_2.i0 << 8) | (0x08 << 16);
345377   if (cfg & 0xf000)
346      in_1[0] |= (in_3[0] << 8) | (0x04 << 16);
378      in_1.i0 |= (in_3.i0 << 8) | (0x04 << 16);
347379}
348380
349381
r1343r1344
472504   else
473505      image_fread (image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks);
474506
475#ifdef SPLIT_PRG
476{
477   FILE *prgout;
478   char outname[255];
507#if SPLIT_PRG
508   {
509      FILE *prgout;
510      char outname[255];
479511
480   for (i = 0; i < nes.prg_chunks; i ++)
481   {
482      sprintf (outname, "%s.p%d", battery_name, i);
483      prgout = fopen (outname, "wb");
484      if (prgout)
512      for (i = 0; i < nes.prg_chunks; i ++)
485513      {
486         fwrite (&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
487         fclose (prgout);
514         sprintf (outname, "%s.p%d", battery_name, i);
515         prgout = fopen (outname, "wb");
516         if (prgout)
517         {
518            fwrite (&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
519            fclose (prgout);
520         }
488521      }
489522   }
490}
491#endif
523#endif /* SPLIT_PRG */
492524
493525   logerror("**\n");
494526   logerror("Mapper: %d\n", nes.mapper);
src/mess/machine/kc.c
r1343r1344
918918   z80pio_bstb_w(0,0);
919919
920920
921   for (i=0; i<KC_KEYBOARD_NUM_LINES; i++)
921   for (i=0; i<KC_KEYBOARD_NUM_LINES-1; i++)
922922   {
923923      /* read input port */
924924      kc_previous_keyboard[i] = readinputport(i);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team