Previous 15994 Revisions Next

r3179 Friday 5th September, 2008 at 15:50:20 UTC by Firewave
Removed more obsolete files
[src/mame/audio]system16.c
[src/mame/drivers]hal21.c jcross.c marvins.c sgladiat.c
[src/mame/video]jcross.c marvins.c
[src/tools]makemeta.c

src/mame/audio/system16.c
r3178r3179
1// system 16 - 7751 emulation, based on monster bash code.
2#include "driver.h"
3#include "cpu/i8039/i8039.h"
4#include "sound/dac.h"
5
6static UINT32 port_8255_c03 = 0;
7static UINT32 port_8255_c47 = 0;
8static UINT32 port_7751_p27 = 0;
9static UINT32 rom_offset = 0;
10static UINT32 rom_base = 0;
11static UINT32 rom_bank = 0;
12
13static TIMER_CALLBACK( trigger_7751_sound )
14{
15   int data = param;
16
17   /* I think this is correct for 128k sound roms,
18         it's OK for smaller roms */
19   if((data&0xf) == 0xc) rom_bank=0;
20   else if((data&0xf) == 0xd) rom_bank=0x4000;
21   else if((data&0xf) == 0xb) rom_bank=0xc000;
22   else if((data&0xf) == 0xa) rom_bank=0x8000;
23
24   else if((data&0xf) == 0xf) rom_bank=0x1c000;
25   else if((data&0xf) == 0xe) rom_bank=0x18000;
26   else if((data&0xf) == 0x7) rom_bank=0x14000;
27   else if((data&0xf) == 0x6) rom_bank=0x10000;
28
29   port_8255_c03 = (data>>5);
30
31   cpunum_set_input_line(machine, 2, 0, PULSE_LINE);
32}
33
34// I'm sure this must be wrong, but it seems to work for quartet music.
35WRITE8_HANDLER( sys16_7751_audio_8255_w )
36{
37   logerror("7751: %4x %4x\n",data,data^0xff);
38
39   if ((data & 0x0f) != 8)
40   {
41      cpunum_set_input_line(machine, 2, INPUT_LINE_RESET, PULSE_LINE);
42      timer_set(ATTOTIME_IN_USEC(300), NULL, data, trigger_7751_sound);
43   }
44}
45
46
47READ8_HANDLER( sys16_7751_audio_8255_r )
48{
49   // Only PC4 is hooked up
50   /* 0x00 = BUSY, 0x10 = NOT BUSY */
51   return (port_8255_c47 & 0x10);
52}
53
54/* read from BUS */
55READ8_HANDLER( sys16_7751_sh_rom_r )
56{
57   UINT8 *sound_rom = memory_region(machine, REGION_SOUND1);
58
59   return sound_rom[rom_offset+rom_base];
60}
61
62/* read from T1 */
63READ8_HANDLER( sys16_7751_sh_t1_r )
64{
65   // Labelled as "TEST", connected to ground
66   return 0;
67}
68
69/* read from P2 */
70READ8_HANDLER( sys16_7751_sh_command_r )
71{
72   // 8255's PC0-2 connects to 7751's S0-2 (P24-P26 on an 8048)
73   return ((port_8255_c03 & 0x07) << 4) | port_7751_p27;
74}
75
76/* write to P1 */
77WRITE8_HANDLER( sys16_7751_sh_dac_w )
78{
79   dac_data_w(0,data);
80}
81
82/* write to P2 */
83WRITE8_HANDLER( sys16_7751_sh_busy_w )
84{
85   port_8255_c03 = (data & 0x70) >> 4;
86   port_8255_c47 = (data & 0x80) >> 3;
87   port_7751_p27 = data & 0x80;
88   rom_base = rom_bank;
89}
90
91/* write to P4 */
92WRITE8_HANDLER( sys16_7751_sh_offset_a0_a3_w )
93{
94   rom_offset = (rom_offset & 0xFFF0) | (data & 0x0F);
95}
96
97/* write to P5 */
98WRITE8_HANDLER( sys16_7751_sh_offset_a4_a7_w )
99{
100   rom_offset = (rom_offset & 0xFF0F) | ((data & 0x0F) << 4);
101}
102
103/* write to P6 */
104WRITE8_HANDLER( sys16_7751_sh_offset_a8_a11_w )
105{
106   rom_offset = (rom_offset & 0xF0FF) | ((data & 0x0F) << 8);
107}
108
109/* write to P7 */
110WRITE8_HANDLER( sys16_7751_sh_rom_select_w )
111{
112   rom_offset = (rom_offset & 0x0FFF) | ((0x4000 + ((data&0xf) << 12)) & 0x3000);
113
114}
115
src/mame/video/marvins.c
r3178r3179
1#include "driver.h"
2#include "cpu/z80/z80.h"
3#include "snk.h"
4
5int marvins_gamegroup;
6
7static int flipscreen, sprite_flip_adjust;
8static tilemap *fg_tilemap, *bg_tilemap, *tx_tilemap;
9static UINT8 bg_color, fg_color, old_bg_color, old_fg_color;
10static rectangle tilemap_clip;
11static int video_bank = 0;
12
13/***************************************************************************
14**
15**  Palette Handling:
16**
17**  Each color entry is encoded by 12 bits in color proms
18**
19**  There are sixteen 8-color sprite palettes
20**  sprite palette is selected by a nibble of spriteram
21**
22**  There are eight 16-color text layer character palettes
23**  character palette is determined by character_number
24**
25**  Background and Foreground tilemap layers each have eight 16-color
26**  palettes.  A palette bank select register is associated with the whole
27**  layer.
28**
29***************************************************************************/
30
31WRITE8_HANDLER( marvins_palette_bank_w )
32{
33   bg_color = data>>4;
34   fg_color = data&0xf;
35}
36
37static void stuff_palette( running_machine *machine, int source_index, int dest_index, int num_colors )
38{
39   UINT8 *color_prom = memory_region(machine, "proms") + source_index;
40   int i;
41   for( i=0; i<num_colors; i++ )
42   {
43      int bit0=0,bit1,bit2,bit3;
44      int red, green, blue;
45
46      bit0 = (color_prom[0x800] >> 2) & 0x01; // ?
47      bit1 = (color_prom[0x000] >> 1) & 0x01;
48      bit2 = (color_prom[0x000] >> 2) & 0x01;
49      bit3 = (color_prom[0x000] >> 3) & 0x01;
50      red = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
51
52      bit0 = (color_prom[0x800] >> 1) & 0x01; // ?
53      bit1 = (color_prom[0x400] >> 2) & 0x01;
54      bit2 = (color_prom[0x400] >> 3) & 0x01;
55      bit3 = (color_prom[0x000] >> 0) & 0x01;
56      green = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
57
58      bit0 = (color_prom[0x800] >> 0) & 0x01; // ?
59      bit1 = (color_prom[0x800] >> 3) & 0x01; // ?
60      bit2 = (color_prom[0x400] >> 0) & 0x01;
61      bit3 = (color_prom[0x400] >> 1) & 0x01;
62      blue = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
63
64      palette_set_color( machine, dest_index++, MAKE_RGB(red, green, blue) );
65      color_prom++;
66   }
67
68   for (i=0; i<=5; i++) gfx_drawmode_table[i] = DRAWMODE_SOURCE;
69
70   gfx_drawmode_table[6] = DRAWMODE_SHADOW;
71   gfx_drawmode_table[7] = DRAWMODE_NONE;
72}
73
74static void update_palette(running_machine *machine, int type )
75{
76   if( bg_color!=old_bg_color )
77   {
78      stuff_palette( machine, 256+16*(bg_color&0x7), (0x11-type)*16, 16 );
79      old_bg_color = bg_color;
80   }
81
82   if( fg_color!=old_fg_color )
83   {
84      stuff_palette( machine, 128+16*(fg_color&0x7), (0x10+type)*16, 16 );
85      old_fg_color = fg_color;
86   }
87}
88
89/***************************************************************************
90**
91**  Memory Handlers
92**
93***************************************************************************/
94
95#ifdef UNUSED_FUNCTION
96WRITE8_HANDLER( marvins_spriteram_w )
97{
98   spriteram[offset] = data;
99}
100#endif
101
102WRITE8_HANDLER( marvins_foreground_ram_w )
103{
104   spriteram_2[offset] = data;
105   if (offset < 0x800 && !video_bank) tilemap_mark_tile_dirty(fg_tilemap,offset);
106   else if (offset >= 0x800 && video_bank) tilemap_mark_tile_dirty(fg_tilemap,offset - 0x800);
107}
108
109WRITE8_HANDLER( marvins_background_ram_w )
110{
111   spriteram_3[offset] = data;
112   if (offset < 0x800 && !video_bank) tilemap_mark_tile_dirty(bg_tilemap,offset);
113   else if (offset >= 0x800 && video_bank) tilemap_mark_tile_dirty(bg_tilemap,offset - 0x800);
114}
115
116WRITE8_HANDLER( marvins_text_ram_w )
117{
118   videoram[offset] = data;
119   if (offset < 0x400) tilemap_mark_tile_dirty(tx_tilemap,offset);
120}
121
122/***************************************************************************
123**
124**  Callbacks for Tilemap Manager
125**
126***************************************************************************/
127
128static TILE_GET_INFO( get_bg_tilemap_info )
129{
130   SET_TILE_INFO(
131         2,
132         spriteram_3[tile_index + video_bank * 0x800],
133         0,
134         0);
135}
136
137static TILE_GET_INFO( get_fg_tilemap_info )
138{
139   SET_TILE_INFO(
140         1,
141         spriteram_2[tile_index + video_bank * 0x800],
142         0,
143         0);
144}
145
146static TILE_GET_INFO( get_tx_tilemap_info )
147{
148   int tile_number = videoram[tile_index];
149   SET_TILE_INFO(
150         0,
151         tile_number,
152         (tile_number>>5),
153         0);
154}
155
156/***************************************************************************
157**
158**  Video Initialization
159**
160***************************************************************************/
161
162VIDEO_START( marvins )
163{
164   flipscreen = -1; old_bg_color = old_fg_color = -1;
165
166   stuff_palette( machine, 0, 0, 16*8 ); /* load sprite colors */
167   stuff_palette( machine, 16*8*3, 16*8, 16*8 ); /* load text colors */
168
169   fg_tilemap = tilemap_create(get_fg_tilemap_info,tilemap_scan_cols,8,8,64,32);
170   bg_tilemap = tilemap_create(get_bg_tilemap_info,tilemap_scan_cols,8,8,64,32);
171   tx_tilemap = tilemap_create(get_tx_tilemap_info,tilemap_scan_cols,8,8,32,32);
172
173   {
174      tilemap_clip = *video_screen_get_visible_area(machine->primary_screen);
175      if (marvins_gamegroup != 1) // not Mad Crasher
176      {
177         tilemap_clip.max_x-=16;
178         tilemap_clip.min_x+=16;
179      }
180
181      tilemap_set_transparent_pen(fg_tilemap,0xf);
182      tilemap_set_transparent_pen(bg_tilemap,0xf);
183      tilemap_set_transparent_pen(tx_tilemap,0xf);
184
185      switch (marvins_gamegroup)
186      {
187         case 0:   // Marvin's Maze
188            tilemap_set_scrolldx( bg_tilemap, 271, 287  );
189            tilemap_set_scrolldy( bg_tilemap,   0,  -40  );
190
191            tilemap_set_scrolldx( fg_tilemap,  15, 13+18 );
192            tilemap_set_scrolldy( fg_tilemap,   0, -40   );
193
194            tilemap_set_scrolldx( tx_tilemap,  16, 16    );
195            tilemap_set_scrolldy( tx_tilemap,   0, 0     );
196
197            sprite_flip_adjust = 256+182+1;
198         break;
199
200         case 1:   // Mad Crasher
201            tilemap_set_scrolldx( bg_tilemap, 256, 0     );
202            tilemap_set_scrolldy( bg_tilemap,  12, 0     );
203
204            tilemap_set_scrolldx( fg_tilemap,   0, 0     );
205            tilemap_set_scrolldy( fg_tilemap,   6, -24   );
206
207            tilemap_set_scrolldx( tx_tilemap,  16, 16    );
208            tilemap_set_scrolldy( tx_tilemap,   0, +8    );
209         break;
210
211         case 2:   // VanguardII
212            tilemap_set_scrolldx( bg_tilemap,   7, +14   );
213            tilemap_set_scrolldy( bg_tilemap, -20, -60   );
214
215            tilemap_set_scrolldx( fg_tilemap,  15, +32   );
216            tilemap_set_scrolldy( fg_tilemap,   0, -40   );
217
218            tilemap_set_scrolldx( tx_tilemap,  16, 16    );
219            tilemap_set_scrolldy( tx_tilemap,   0, 0     );
220
221            sprite_flip_adjust = 256+182;
222         break;
223      }
224   }
225}
226
227/***************************************************************************
228**
229**  Screen Refresh
230**
231***************************************************************************/
232
233static void draw_status(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect )
234{
235   const UINT8 *base = videoram+0x400;
236   const gfx_element *gfx = machine->gfx[0];
237   int row;
238   if (!flipscreen)
239      for( row=0; row<4; row++ )
240      {
241         int sy,sx = (row&1)*8;
242         const UINT8 *source = base + (row&1)*32;
243         if( row>1 )
244         {
245            sx+=256+16;
246         }
247         else
248         {
249            source+=30*32;
250         }
251
252         for( sy=0; sy<256; sy+=8 )
253         {
254            int tile_number = *source++;
255            drawgfx( bitmap, gfx,
256                tile_number, tile_number>>5,
257                0,0,
258                sx,sy,
259                cliprect,
260                TRANSPARENCY_NONE, 0xf );
261         }
262      }
263   else
264      for( row=0; row<4; row++ )
265      {
266         int sy,sx = (row&1)*8;
267         const UINT8 *source = base + 30*32 + 32 - (row&1)*32;
268         if( row>1 )
269         {
270            sx+=256+16;
271         }
272         else
273         {
274            source-=30*32;
275         }
276
277         for( sy=255; sy>=0; sy-=8 )
278         {
279            int tile_number = *source++;
280            drawgfx( bitmap, gfx,
281                tile_number, tile_number>>5,
282                1,1,
283                sx,sy-5*8,
284                cliprect,
285                TRANSPARENCY_NONE, 0xf );
286         }
287      }
288}
289
290static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int scrollx, int scrolly,
291      int priority, UINT8 sprite_partition )
292{
293   const gfx_element *gfx = machine->gfx[3];
294   const UINT8 *source, *finish;
295
296   if( sprite_partition>0x64 ) sprite_partition = 0x64;
297
298   if( priority )
299   {
300      source = spriteram + sprite_partition;
301      finish = spriteram + 0x64;
302   }
303   else
304   {
305      source = spriteram;
306      finish = spriteram + sprite_partition;
307   }
308
309   while( source<finish )
310   {
311      int attributes = source[3]; /* Y?F? CCCC */
312      int tile_number = source[1];
313      int sy = source[0] - scrolly;
314      int sx = source[2] - scrollx + ((attributes&0x80)?256:0);
315      int color = attributes&0xf;
316      int flipy = (attributes&0x20);
317      int flipx = 0;
318
319      if( flipscreen )
320      {
321         if( flipy )
322         {
323             flipx = 1; flipy = 0;
324         }
325         else
326         {
327             flipx = flipy = 1;
328         }
329         sx = sprite_flip_adjust-sx;
330         sy = 246-sy;
331      }
332
333      sx = (256-sx) & 0x1ff;
334      sy = sy & 0xff;
335      if (sx > 512-16) sx -= 512;
336      if (sy > 256-16) sy -= 256;
337
338      drawgfx( bitmap,gfx,
339         tile_number,
340         color,
341         flipx, flipy,
342         sx, sy,
343         cliprect,TRANSPARENCY_PEN_TABLE,7);
344
345      source+=4;
346   }
347}
348
349VIDEO_UPDATE( marvins )
350{
351   cpuintrf_push_context(0);
352   {
353      UINT8 sprite_partition = program_read_byte(0xfe00);
354
355      int attributes = program_read_byte(0x8600); /* 0x20: normal, 0xa0: video flipped */
356      int scroll_attributes = program_read_byte(0xff00);
357      int sprite_scrolly = program_read_byte(0xf800);
358      int sprite_scrollx = program_read_byte(0xf900);
359
360      int bg_scrolly = program_read_byte(0xfa00);
361      int bg_scrollx = program_read_byte(0xfb00);
362      int fg_scrolly = program_read_byte(0xfc00);
363      int fg_scrollx = program_read_byte(0xfd00);
364
365      rectangle finalclip = tilemap_clip;
366      sect_rect(&finalclip, cliprect);
367
368      if(video_bank != ((attributes & 8) >> 3))
369      {
370         video_bank = ((attributes & 8) >> 3);
371
372         tilemap_mark_all_tiles_dirty(bg_tilemap);
373         tilemap_mark_all_tiles_dirty(fg_tilemap);
374      }
375
376      if( (scroll_attributes & 4)==0 ) bg_scrollx += 256;
377      if( scroll_attributes & 1 ) sprite_scrollx += 256;
378      if( scroll_attributes & 2 ) fg_scrollx += 256;
379
380      /* palette bank for background/foreground is set by a memory-write handler */
381      update_palette(screen->machine, 0);
382
383      if( flipscreen != (attributes&0x80) )
384      {
385         flipscreen = attributes&0x80;
386         tilemap_set_flip( ALL_TILEMAPS, flipscreen?TILEMAP_FLIPY|TILEMAP_FLIPX:0);
387      }
388
389      tilemap_set_scrollx( bg_tilemap,    0, bg_scrollx );
390      tilemap_set_scrolly( bg_tilemap,    0, bg_scrolly );
391      tilemap_set_scrollx( fg_tilemap,    0, fg_scrollx );
392      tilemap_set_scrolly( fg_tilemap,    0, fg_scrolly );
393      tilemap_set_scrollx( tx_tilemap,    0, 0 );
394      tilemap_set_scrolly( tx_tilemap,    0, 0 );
395
396      tilemap_draw(bitmap,&finalclip,fg_tilemap,TILEMAP_DRAW_OPAQUE ,0);
397      draw_sprites(screen->machine,bitmap,cliprect, sprite_scrollx+29+1, sprite_scrolly+16, 0, sprite_partition );
398      tilemap_draw(bitmap,&finalclip,bg_tilemap,0 ,0);
399      draw_sprites(screen->machine,bitmap,cliprect, sprite_scrollx+29+1, sprite_scrolly+16, 1, sprite_partition );
400      tilemap_draw(bitmap,&finalclip,tx_tilemap,0 ,0);
401      draw_status(screen->machine,bitmap,cliprect );
402   }
403   cpuintrf_pop_context();
404   return 0;
405}
406
407VIDEO_UPDATE( madcrash )
408{
409/***************************************************************************
410**
411**  Game Specific Initialization
412**
413**  madcrash_vreg defines an offset for the video registers which is
414**  different in Mad Crasher and Vanguard II.
415**
416**  init_sound defines the location of the polled sound CPU busy bit,
417**  which also varies across games.
418**
419***************************************************************************/
420
421   cpuintrf_push_context(0);
422   {
423      int madcrash_vreg = (marvins_gamegroup == 1) ? 0x00 : 0xf1; // Mad Crasher=0x00, VanguardII=0xf1
424
425      UINT8 sprite_partition = program_read_byte(0xfa00);
426
427      int attributes = program_read_byte(0x8600+madcrash_vreg); /* 0x20: normal, 0xa0: video flipped */
428      int bg_scrolly = program_read_byte(0xf800+madcrash_vreg);
429      int bg_scrollx = program_read_byte(0xf900+madcrash_vreg);
430      int scroll_attributes = program_read_byte(0xfb00+madcrash_vreg);
431      int sprite_scrolly = program_read_byte(0xfc00+madcrash_vreg);
432      int sprite_scrollx = program_read_byte(0xfd00+madcrash_vreg);
433      int fg_scrolly = program_read_byte(0xfe00+madcrash_vreg);
434      int fg_scrollx = program_read_byte(0xff00+madcrash_vreg);
435
436      rectangle finalclip = tilemap_clip;
437      sect_rect(&finalclip, cliprect);
438
439      if(video_bank != ((attributes & 8) >> 3))
440      {
441         video_bank = ((attributes & 8) >> 3);
442
443         tilemap_mark_all_tiles_dirty(bg_tilemap);
444         tilemap_mark_all_tiles_dirty(fg_tilemap);
445      }
446
447      if( (scroll_attributes & 4)==0 ) bg_scrollx += 256;
448      if( scroll_attributes & 1 ) sprite_scrollx += 256;
449      if( scroll_attributes & 2 ) fg_scrollx += 256;
450
451      marvins_palette_bank_w(screen->machine, 0, program_read_byte(0xc800+madcrash_vreg));
452      update_palette(screen->machine, 1);
453
454      if( flipscreen != (attributes&0x80) )
455      {
456         flipscreen = attributes&0x80;
457         tilemap_set_flip( ALL_TILEMAPS, flipscreen?TILEMAP_FLIPY|TILEMAP_FLIPX:0);
458      }
459      tilemap_set_scrollx( bg_tilemap,  0, bg_scrollx );
460      tilemap_set_scrolly( bg_tilemap,  0, bg_scrolly );
461      tilemap_set_scrollx( fg_tilemap,  0, fg_scrollx );
462      tilemap_set_scrolly( fg_tilemap,  0, fg_scrolly );
463      tilemap_set_scrollx( tx_tilemap,  0, 0 );
464      tilemap_set_scrolly( tx_tilemap,  0, 0 );
465
466
467      tilemap_draw(bitmap,&finalclip,bg_tilemap,TILEMAP_DRAW_OPAQUE ,0);
468      draw_sprites(screen->machine,bitmap,cliprect, sprite_scrollx+29, sprite_scrolly+17, 0, sprite_partition );
469      tilemap_draw(bitmap,&finalclip,fg_tilemap,0 ,0);
470      draw_sprites(screen->machine,bitmap,cliprect, sprite_scrollx+29, sprite_scrolly+17, 1, sprite_partition );
471      tilemap_draw(bitmap,&finalclip,tx_tilemap,0 ,0);
472      draw_status(screen->machine,bitmap,cliprect );
473   }
474   cpuintrf_pop_context();
475   return 0;
476}
src/mame/video/jcross.c
r3178r3179
1#include "driver.h"
2#include "cpu/z80/z80.h"
3
4static int flipscreen;
5static tilemap *bg_tilemap,  *tx_tilemap;
6static UINT8 fg_color, old_fg_color;
7
8extern UINT8 *jcr_textram;
9
10
11int jcross_vregs[5];
12
13WRITE8_HANDLER( jcross_palettebank_w )
14{
15   fg_color = data&0xf;
16}
17
18
19static void stuff_palette( running_machine *machine, int source_index, int dest_index, int num_colors )
20{
21   UINT8 *color_prom = memory_region(machine, "proms") + source_index;
22   int i;
23   for( i=0; i<num_colors; i++ )
24   {
25      int bit0=0,bit1,bit2,bit3;
26      int red, green, blue;
27
28      bit0 = (color_prom[0x800] >> 2) & 0x01; // ?
29      bit1 = (color_prom[0x000] >> 1) & 0x01;
30      bit2 = (color_prom[0x000] >> 2) & 0x01;
31      bit3 = (color_prom[0x000] >> 3) & 0x01;
32      red = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
33
34      bit0 = (color_prom[0x800] >> 1) & 0x01; // ?
35      bit1 = (color_prom[0x400] >> 2) & 0x01;
36      bit2 = (color_prom[0x400] >> 3) & 0x01;
37      bit3 = (color_prom[0x000] >> 0) & 0x01;
38      green = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
39
40      bit0 = (color_prom[0x800] >> 0) & 0x01; // ?
41      bit1 = (color_prom[0x800] >> 3) & 0x01; // ?
42      bit2 = (color_prom[0x400] >> 0) & 0x01;
43      bit3 = (color_prom[0x400] >> 1) & 0x01;
44      blue = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
45
46      palette_set_color( machine, dest_index++, MAKE_RGB(red, green, blue) );
47      color_prom++;
48   }
49}
50
51static void update_palette(running_machine *machine, int type )
52{
53   if( fg_color!=old_fg_color )
54   {
55      stuff_palette(machine, 128+16*(fg_color&0x7), (0x10+type)*16, 16 );
56      old_fg_color = fg_color;
57   }
58}
59
60WRITE8_HANDLER( jcross_background_ram_w )
61{
62   videoram[offset]=data;
63   tilemap_mark_tile_dirty(bg_tilemap,offset);
64}
65
66WRITE8_HANDLER( jcross_text_ram_w )
67{
68   jcr_textram[offset]=data;
69   tilemap_mark_tile_dirty(tx_tilemap,offset);
70}
71
72
73static TILE_GET_INFO( get_bg_tilemap_info )
74{
75   SET_TILE_INFO(
76         1,
77         videoram[tile_index],
78         0,
79         0);
80}
81
82static TILE_GET_INFO( get_tx_tilemap_info )
83{
84   int tile_number = jcr_textram[tile_index];
85   SET_TILE_INFO(
86         0,
87         tile_number,
88         0,
89         0);
90}
91
92VIDEO_START( jcross )
93{
94   flipscreen = -1;  old_fg_color = -1;
95
96   stuff_palette( machine, 0, 0, 16*8 );
97   stuff_palette( machine, 16*8*3, 16*8, 16*8 );
98
99   bg_tilemap = tilemap_create(get_bg_tilemap_info,tilemap_scan_cols,8,8,64,64);
100   tx_tilemap = tilemap_create(get_tx_tilemap_info,tilemap_scan_cols,8,8,32,32);
101
102   tilemap_set_transparent_pen(tx_tilemap,0xf);
103   tilemap_set_scrolldx( bg_tilemap,   16, 22 );
104}
105
106/***************************************************************************
107**
108**  Screen Refresh
109**
110***************************************************************************/
111
112static void draw_status(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect )
113{
114   const UINT8 *base =  jcr_textram + 0x400;
115   const gfx_element *gfx = machine->gfx[0];
116   int row;
117   for( row=0; row<4; row++ )
118   {
119      int sy,sx = (row&1)*8;
120      const UINT8 *source = base + (row&1)*32;
121      if( row>1 )
122         sx+=256+16;
123      else
124         source+=30*32;
125
126      for( sy=0; sy<256; sy+=8 )
127      {
128         int tile_number = *source++;
129         drawgfx( bitmap, gfx,
130             tile_number, tile_number>>5,
131             0,0,
132             sx,sy,
133             cliprect,
134             TRANSPARENCY_NONE, 0xf );
135      }
136   }
137}
138
139static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int scrollx, int scrolly )
140{
141   const gfx_element *gfx = machine->gfx[3];
142   const UINT8 *source, *finish;
143   source = spriteram;
144   finish = spriteram + 0x64;
145
146   while( source<finish )
147   {
148      int attributes = source[3];
149      int tile_number = source[1];
150      int sy = source[0] + ((attributes&0x10)?256:0);
151      int sx = source[2] + ((attributes&0x80)?256:0);
152      int color = attributes&0xf;
153      int flipy = (attributes&0x20);
154      int flipx = 0;
155
156      sy=(sy-scrolly)&0x1ff;
157      sx=(sx-scrollx)&0x1ff;
158
159      drawgfx( bitmap,gfx,
160         tile_number,
161         color,
162         flipx, flipy,
163         (256-sx)&0x1ff,sy-16,
164         cliprect,TRANSPARENCY_PEN,7);
165
166      source+=4;
167   }
168}
169
170
171VIDEO_UPDATE( jcross )
172{
173   int scroll_attributes = jcross_vregs[0];
174   int sprite_scrolly = jcross_vregs[1];
175   int sprite_scrollx = jcross_vregs[2];
176   int bg_scrolly = jcross_vregs[3];
177   int bg_scrollx = jcross_vregs[4];
178
179   if( scroll_attributes & 1 ) sprite_scrollx += 256;
180   if( scroll_attributes & 2 ) bg_scrollx += 256;
181
182   if( scroll_attributes & 8 ) sprite_scrolly += 256;
183   if( scroll_attributes & 0x10 ) bg_scrolly += 256;
184   update_palette(screen->machine, 1);
185
186
187   tilemap_set_scrollx( bg_tilemap, 0, bg_scrollx );
188   tilemap_set_scrolly( bg_tilemap, 0, bg_scrolly );
189   tilemap_draw(bitmap,cliprect,bg_tilemap,0 ,0);
190   draw_sprites(screen->machine, bitmap,cliprect, sprite_scrollx+23, sprite_scrolly+1 );
191   tilemap_draw(bitmap,cliprect,tx_tilemap,0 ,0);
192   draw_status(screen->machine, bitmap,cliprect );
193   return 0;
194}
src/mame/drivers/marvins.c
r3178r3179
1/*
2various early SNK games (1983-1985)
3- Marvin's Maze
4- Vanguard II
5- Mad Crasher
6
7driver by Phil Stroffolino
8
9Known Issues:
10    Mad Crasher fails the ROM test, but ROMs are verified to be good (reason's unknown)
11    Mad Crasher sound effects aren't being played (fixed)
12
13
14Change Log
15----------
16
17AT08XX03:
18 - added shadows
19 - fixed Mad Crasher bad background, sound effects and foreground priority.
20   (great now I can fall under the skyway like I did at Chuck'n Cheese;)
21 - fixed Vanguard2 scroll offsets
22 - tuned music tempo and wavegen frequency
23
242008.04.04: Small note regarding DipSwitches. Locations and values have been
25verified with the manual for both Marvin's Maze and Mad Crasher. Vanguard II
26DIPs have been checked against jammaboards diplist, no manual available ATM.
27DSW2:7 in madcrash is listed as Difficulty, but it's not clear how it affects
28the gameplay difficulty
29
30*/
31
32#include "driver.h"
33#include "deprecat.h"
34#include "cpu/z80/z80.h"
35#include "snk.h"
36#include "sound/ay8910.h"
37#include "sound/namco.h"
38
39#define CREDITS "Phil Stroffolino\nTim Lindquist\nCarlos A. Lozano"
40
41extern int marvins_gamegroup;
42
43// FIXME this is definitely wrong, schematics clearly show that vblank triggers interrupt
44// on both CPU at the same time.
45static int snk_irq_delay = 1500;
46
47// see IRQ notes in drivers\marvins.c
48static TIMER_CALLBACK( irq_trigger_callback ) { cpunum_set_input_line(machine, param, 0, HOLD_LINE); }
49
50static INTERRUPT_GEN( snk_irq_BA )
51{
52   cpunum_set_input_line(machine, 1, 0, HOLD_LINE);
53   timer_set(ATTOTIME_IN_USEC(snk_irq_delay), NULL, 0, irq_trigger_callback);
54}
55
56
57/***************************************************************************
58**
59**  CPUA and CPUB communicate through shared RAM.
60**
61***************************************************************************/
62
63extern WRITE8_HANDLER( marvins_background_ram_w );
64extern WRITE8_HANDLER( marvins_foreground_ram_w );
65extern WRITE8_HANDLER( marvins_text_ram_w );
66extern WRITE8_HANDLER( marvins_spriteram_w );
67
68
69/***************************************************************************
70**
71** Video Driver
72**
73***************************************************************************/
74
75extern VIDEO_START( marvins );
76extern VIDEO_UPDATE( marvins );
77extern VIDEO_UPDATE( madcrash );
78
79extern WRITE8_HANDLER( marvins_palette_bank_w );
80
81
82/***************************************************************************
83**
84**  Interrupt Handling
85**
86**  CPUA can trigger an interrupt on CPUB, and CPUB can trigger an interrupt
87**  on CPUA.  Each CPU must re-enable interrupts on itself.
88**
89***************************************************************************/
90
91// see drivers\snk.c
92
93
94/***************************************************************************
95**
96**  Sound System
97**
98**  The sound CPU is a slave, with communication.
99**
100**  Sound Chips: PSGX2 + "Wave Generater"
101**
102**  The Custom Wave Generator is controlled by 6 bytes
103**
104**  The first pair of registers (0x8002, 0x8003) appear to define frequency
105**  as a fraction: RAM[0x8003]/RAM[0x8002].
106**
107**  (0x8004, 0x8005, 0x8006, 0x8007) are currently unmapped.  Probably they
108**  control the shape of the wave being played.
109**
110**  snkwave_interface is currently implemented with the "namco" sound component.
111**
112***************************************************************************/
113
114static int sound_cpu_busy;
115
116static const namco_interface snkwave_interface =
117{
118   1,            /* number of voices */
119   0            /* stereo */
120};
121
122static WRITE8_HANDLER( sound_command_w )
123{
124   sound_cpu_busy = 0x01;
125   soundlatch_w(machine, 0, data);
126   cpunum_set_input_line(machine, 2, 0, HOLD_LINE);
127}
128
129static READ8_HANDLER( sound_command_r )
130{
131   sound_cpu_busy = 0;
132   return(soundlatch_r(machine,0));
133}
134
135static READ8_HANDLER( sound_nmi_ack_r )
136{
137   cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, CLEAR_LINE);
138   return 0;
139}
140
141static CUSTOM_INPUT( sound_status_r )
142{
143   return sound_cpu_busy;
144}
145
146static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 )
147   AM_RANGE(0x0000, 0x3fff) AM_ROM AM_BASE(&namco_wavedata)   /* silly hack - this shouldn't be here */
148   AM_RANGE(0x4000, 0x4000) AM_READ(sound_command_r)
149   AM_RANGE(0x8000, 0x8000) AM_WRITE(ay8910_control_port_0_w)
150   AM_RANGE(0x8001, 0x8001) AM_WRITE(ay8910_write_port_0_w)
151   AM_RANGE(0x8002, 0x8007) AM_WRITE(snkwave_w)
152   AM_RANGE(0x8008, 0x8008) AM_WRITE(ay8910_control_port_1_w)
153   AM_RANGE(0x8009, 0x8009) AM_WRITE(ay8910_write_port_1_w)
154   AM_RANGE(0xa000, 0xa000) AM_READ(sound_nmi_ack_r)
155   AM_RANGE(0xe000, 0xe7ff) AM_RAM
156ADDRESS_MAP_END
157
158static ADDRESS_MAP_START( sound_portmap, ADDRESS_SPACE_IO, 8 )
159   ADDRESS_MAP_GLOBAL_MASK(0xff)
160   AM_RANGE(0x00, 0x00) AM_READNOP
161ADDRESS_MAP_END
162
163
164/***************************************************************************
165**
166**  Memory Maps for CPUA, CPUB
167**
168**  Shared RAM is shuffled in Mad Crasher/Vanguard II compared to
169**  Marvin's Maze.
170**
171**  A few ports are mapped differently for each game.
172**
173***************************************************************************/
174
175static ADDRESS_MAP_START( marvins_cpuA_map, ADDRESS_SPACE_PROGRAM, 8 )
176   AM_RANGE(0x0000, 0x5fff) AM_ROM
177   AM_RANGE(0x6000, 0x6000) AM_WRITE(marvins_palette_bank_w)
178   AM_RANGE(0x8000, 0x8000) AM_READ_PORT("SYSTEM")
179   AM_RANGE(0x8100, 0x8100) AM_READ_PORT("P1")
180   AM_RANGE(0x8200, 0x8200) AM_READ_PORT("P2")
181   AM_RANGE(0x8300, 0x8300) AM_WRITE(sound_command_w)
182   AM_RANGE(0x8400, 0x8400) AM_READ_PORT("DSW1")
183   AM_RANGE(0x8500, 0x8500) AM_READ_PORT("DSW2")
184   AM_RANGE(0x8600, 0x8600) AM_RAM                  /* video attribute */
185   AM_RANGE(0x8700, 0x8700) AM_READWRITE(snk_cpuB_nmi_trigger_r, snk_cpuA_nmi_ack_w)
186   AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE(&spriteram) AM_SHARE(1)
187   AM_RANGE(0xd000, 0xdfff) AM_RAM_WRITE(marvins_background_ram_w) AM_SHARE(2) AM_BASE(&spriteram_3)
188   AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(marvins_foreground_ram_w) AM_SHARE(3) AM_BASE(&spriteram_2)
189   AM_RANGE(0xf000, 0xffff) AM_RAM_WRITE(marvins_text_ram_w) AM_SHARE(4) AM_BASE(&videoram)
190ADDRESS_MAP_END
191
192static ADDRESS_MAP_START( marvins_cpuB_map, ADDRESS_SPACE_PROGRAM, 8 )
193   AM_RANGE(0x0000, 0x5fff) AM_ROM
194   AM_RANGE(0x8700, 0x8700) AM_READWRITE(snk_cpuA_nmi_trigger_r, snk_cpuB_nmi_ack_w)
195   AM_RANGE(0xc000, 0xcfff) AM_RAM AM_SHARE(1)
196   AM_RANGE(0xd000, 0xdfff) AM_RAM_WRITE(marvins_background_ram_w) AM_SHARE(2)
197   AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(marvins_foreground_ram_w) AM_SHARE(3)
198   AM_RANGE(0xf000, 0xffff) AM_RAM_WRITE(marvins_text_ram_w) AM_SHARE(4)
199ADDRESS_MAP_END
200
201
202static ADDRESS_MAP_START( madcrash_cpuA_map, ADDRESS_SPACE_PROGRAM, 8 )
203   AM_RANGE(0x0000, 0x7fff) AM_ROM
204   AM_RANGE(0x8000, 0x8000) AM_READ_PORT("SYSTEM")
205   AM_RANGE(0x8100, 0x8100) AM_READ_PORT("P1")
206   AM_RANGE(0x8200, 0x8200) AM_READ_PORT("P2")
207   AM_RANGE(0x8300, 0x8300) AM_WRITE(sound_command_w)
208   AM_RANGE(0x8400, 0x8400) AM_READ_PORT("DSW1")
209   AM_RANGE(0x8500, 0x8500) AM_READ_PORT("DSW2")
210   AM_RANGE(0x8600, 0x86ff) AM_RAM                  /* video attribute */
211   AM_RANGE(0x8700, 0x8700) AM_READWRITE(snk_cpuB_nmi_trigger_r, snk_cpuA_nmi_ack_w)
212//  AM_RANGE(0xc800, 0xc800) AM_WRITE(marvins_palette_bank_w)   // palette bank switch (c8f1 for Vanguard)
213   AM_RANGE(0xc800, 0xc8ff) AM_RAM
214   AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE(&spriteram) AM_SHARE(1)
215   AM_RANGE(0xd000, 0xdfff) AM_RAM_WRITE(marvins_background_ram_w) AM_SHARE(2) AM_BASE(&spriteram_3)
216   AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(marvins_foreground_ram_w) AM_SHARE(3) AM_BASE(&spriteram_2)
217   AM_RANGE(0xf000, 0xffff) AM_RAM_WRITE(marvins_text_ram_w) AM_SHARE(4) AM_BASE(&videoram)
218ADDRESS_MAP_END
219
220static ADDRESS_MAP_START( madcrash_cpuB_map, ADDRESS_SPACE_PROGRAM, 8 )
221   AM_RANGE(0x8700, 0x8700) AM_WRITE(snk_cpuB_nmi_ack_w)   /* Vangaurd II */
222   AM_RANGE(0x0000, 0x9fff) AM_ROM
223   AM_RANGE(0xa000, 0xa000) AM_WRITE(snk_cpuB_nmi_ack_w)   /* Mad Crasher */
224   AM_RANGE(0xc000, 0xcfff) AM_RAM_WRITE(marvins_foreground_ram_w) AM_SHARE(3)
225   AM_RANGE(0xd000, 0xdfff) AM_RAM_WRITE(marvins_text_ram_w) AM_SHARE(4)
226   AM_RANGE(0xe000, 0xefff) AM_RAM AM_SHARE(1)
227   AM_RANGE(0xf000, 0xffff) AM_RAM_WRITE(marvins_background_ram_w) AM_SHARE(2)
228ADDRESS_MAP_END
229
230
231static INPUT_PORTS_START( marvins )
232   PORT_START("SYSTEM")
233   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
234   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
235   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SERVICE1 )
236   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_START1 )
237   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_START2 )
238   PORT_BIT( 0x20, IP_ACTIVE_LOW,  IPT_UNKNOWN )
239   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(sound_status_r, NULL) /* sound CPU status */
240   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN )
241
242   PORT_START("P1")
243   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
244   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
245   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
246   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
247   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
248   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
249   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
250
251   PORT_START("P2")
252   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
253   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
254   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
255   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
256   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
257   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
258   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
259
260   PORT_START("DSW1")
261   PORT_DIPNAME( 0x03, 0x02, DEF_STR( Lives ) )      PORT_DIPLOCATION("SW1:1,2")
262   PORT_DIPSETTING(    0x00, "1" )
263   PORT_DIPSETTING(    0x01, "2" )
264   PORT_DIPSETTING(    0x02, "3" )
265   PORT_DIPSETTING(    0x03, "5" )
266   PORT_DIPNAME(0x04,  0x04, "Infinite Lives (Cheat)")   PORT_DIPLOCATION("SW1:3")
267   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
268   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
269   PORT_DIPNAME( 0x38, 0x00, DEF_STR( Coinage ) )      PORT_DIPLOCATION("SW1:4,5,6")
270   PORT_DIPSETTING(    0x38, DEF_STR( 5C_1C ) )
271   PORT_DIPSETTING(    0x30, DEF_STR( 3C_1C ) )
272   PORT_DIPSETTING(    0x28, DEF_STR( 2C_1C ) )
273   PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ) )
274   PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
275   PORT_DIPSETTING(    0x10, DEF_STR( 1C_3C ) )
276   PORT_DIPSETTING(    0x18, DEF_STR( 1C_5C ) )
277   PORT_DIPSETTING(    0x20, DEF_STR( 1C_6C ) )
278   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Free_Play ) )   PORT_DIPLOCATION("SW1:7")
279   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
280   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
281   PORT_DIPNAME( 0x80, 0x80, "Freeze" )            PORT_DIPLOCATION("SW1:8")
282   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
283   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
284
285   PORT_START("DSW2")
286   PORT_DIPNAME( 0x07, 0x00, "1st Bonus Life" )      PORT_DIPLOCATION("SW2:1,2,3")
287   PORT_DIPSETTING(    0x00, "10000" )
288   PORT_DIPSETTING(    0x01, "20000" )
289   PORT_DIPSETTING(    0x02, "30000" )
290   PORT_DIPSETTING(    0x03, "40000" )
291   PORT_DIPSETTING(    0x04, "50000" )
292   PORT_DIPSETTING(    0x05, "60000" )
293   PORT_DIPSETTING(    0x06, "70000" )
294   PORT_DIPSETTING(    0x07, "80000" )
295   PORT_DIPNAME( 0x18, 0x08, "2nd Bonus Life" )      PORT_DIPLOCATION("SW2:4,5")
296   PORT_DIPSETTING(    0x08, "1st bonus*2" )
297   PORT_DIPSETTING(    0x10, "1st bonus*3" )
298   PORT_DIPSETTING(    0x18, "1st bonus*4" )
299   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
300   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Demo_Sounds ) )   PORT_DIPLOCATION("SW2:6")
301   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
302   PORT_DIPSETTING(    0x20, DEF_STR( On ) )
303   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Cabinet ) )      PORT_DIPLOCATION("SW2:7")
304   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
305   PORT_DIPSETTING(    0x40, DEF_STR( Cocktail ) )
306   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Flip_Screen ) )   PORT_DIPLOCATION("SW2:8")
307   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
308   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
309INPUT_PORTS_END
310
311
312static INPUT_PORTS_START( vangrd2 )
313   PORT_START("SYSTEM")
314   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
315   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN )
316   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN )
317   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_START1 )
318   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_START2 )
319   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(sound_status_r, NULL) /* sound CPU status */
320   PORT_BIT( 0x40, IP_ACTIVE_LOW,  IPT_UNKNOWN )
321   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN )
322
323   PORT_START("P1")
324   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
325   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
326   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
327   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
328   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 )
329   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 )
330   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
331
332   PORT_START("P2")
333   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
334   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
335   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
336   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
337   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
338   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
339   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
340
341   PORT_START("DSW1")
342   PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coinage ) )         PORT_DIPLOCATION("SW1:1,2,3")
343   PORT_DIPSETTING(    0x00, DEF_STR( 6C_1C ) )
344   PORT_DIPSETTING(    0x01, DEF_STR( 5C_1C ) )
345   PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
346   PORT_DIPSETTING(    0x03, DEF_STR( 2C_1C ) )
347   PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
348   PORT_DIPSETTING(    0x06, DEF_STR( 1C_2C ) )
349   PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
350   PORT_DIPSETTING(    0x04, DEF_STR( 1C_5C ) )
351   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Bonus_Life ) )      PORT_DIPLOCATION("SW1:4,5,6")
352   PORT_DIPSETTING(    0x38, "30000" )
353   PORT_DIPSETTING(    0x30, "40000" )
354   PORT_DIPSETTING(    0x28, "50000" )
355   PORT_DIPSETTING(    0x20, "60000" )
356   PORT_DIPSETTING(    0x18, "70000" )
357   PORT_DIPSETTING(    0x10, "80000" )
358   PORT_DIPSETTING(    0x08, "90000" )
359   PORT_DIPSETTING(    0x00, "100000" )
360   PORT_DIPNAME( 0xc0, 0x80, DEF_STR( Lives ) )         PORT_DIPLOCATION("SW1:7,8")
361   PORT_DIPSETTING(    0x00, "1" )
362   PORT_DIPSETTING(    0x40, "2" )
363   PORT_DIPSETTING(    0x80, "3" )
364   PORT_DIPSETTING(    0xc0, "5" )
365
366   PORT_START("DSW2")
367   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Demo_Sounds ) )      PORT_DIPLOCATION("SW2:1")
368   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
369   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
370   PORT_DIPNAME( 0x02, 0x02, "Freeze" )               PORT_DIPLOCATION("SW2:2")
371   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
372   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
373   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Cabinet ) )         PORT_DIPLOCATION("SW2:3")
374   PORT_DIPSETTING(    0x04, DEF_STR( Upright ) )
375   PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
376   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Language ) )         PORT_DIPLOCATION("SW2:4")
377   PORT_DIPSETTING(    0x08, DEF_STR( English ) )
378   PORT_DIPSETTING(    0x00, DEF_STR( Japanese ) )
379   PORT_DIPNAME( 0x10, 0x00, "Bonus Life Occurence" )      PORT_DIPLOCATION("SW2:5")
380   PORT_DIPSETTING(    0x00, "Every bonus" )
381   PORT_DIPSETTING(    0x10, "Bonus only" )
382   PORT_DIPNAME( 0x20, 0x20, "Infinite Lives (Cheat)")      PORT_DIPLOCATION("SW2:6")
383   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
384   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
385   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Free_Play ) )      PORT_DIPLOCATION("SW2:7")
386   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
387   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
388   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Flip_Screen ) )      PORT_DIPLOCATION("SW2:8")
389   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
390   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
391INPUT_PORTS_END
392
393
394static INPUT_PORTS_START( madcrash )
395   PORT_START("SYSTEM")
396   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
397   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
398   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN3 )
399   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_START1 )
400   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_START2 )
401   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(sound_status_r, NULL) /* sound CPU status */
402   PORT_BIT( 0x40, IP_ACTIVE_LOW,  IPT_UNKNOWN )
403   PORT_SERVICE( 0x80, IP_ACTIVE_LOW )
404
405   PORT_START("P1")
406   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
407   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
408   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
409   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
410   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 )
411   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 )
412   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
413
414   PORT_START("P2")
415   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
416   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
417   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
418   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
419   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
420   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
421   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
422
423   PORT_START("DSW1")
424   PORT_DIPUNUSED_DIPLOC(0x01, IP_ACTIVE_LOW, "SW1:1")   /* Listed as Unused */
425   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Cabinet ) )      PORT_DIPLOCATION("SW1:2")
426   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
427   PORT_DIPSETTING(    0x02, DEF_STR( Cocktail ) )
428   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Lives ) )      PORT_DIPLOCATION("SW1:3")
429   PORT_DIPSETTING(    0x04, "3" )
430   PORT_DIPSETTING(    0x00, "5" )
431   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coinage ) )      PORT_DIPLOCATION("SW1:4,5,6")
432//  PORT_DIPSETTING(    0x08, DEF_STR( 5C_1C ) )
433   PORT_DIPSETTING(    0x10, DEF_STR( 5C_1C ) )
434   PORT_DIPSETTING(    0x20, DEF_STR( 3C_1C ) )
435   PORT_DIPSETTING(    0x18, DEF_STR( 2C_1C ) )
436   PORT_DIPSETTING(    0x38, DEF_STR( 1C_1C ) )
437   PORT_DIPSETTING(    0x30, DEF_STR( 1C_2C ) )
438   PORT_DIPSETTING(    0x28, DEF_STR( 1C_3C ) )
439   PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
440   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Bonus_Life ) )   PORT_DIPLOCATION("SW1:7,8")
441   PORT_DIPSETTING(    0xc0, "20000 60000" )
442   PORT_DIPSETTING(    0x80, "40000 90000" )
443   PORT_DIPSETTING(    0x40, "50000 120000" )
444   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
445
446   PORT_START("DSW2")
447   PORT_DIPNAME( 0x01, 0x00, "Bonus Life Occurence" )      PORT_DIPLOCATION("SW2:1")
448   PORT_DIPSETTING(    0x01, "1st, 2nd, then every 2nd" )   /* Check the "Non Bugs" page */
449   PORT_DIPSETTING(    0x00, "1st and 2nd only" )
450   PORT_DIPNAME( 0x06, 0x04, "Scroll Speed" )            PORT_DIPLOCATION("SW2:2,3")
451   PORT_DIPSETTING(    0x06, "Slow" )//DEF_STR( Easy ) )
452   PORT_DIPSETTING(    0x04, DEF_STR( Normal ) )
453   PORT_DIPSETTING(    0x02, "Fast" )//DEF_STR( Hard ) )
454   PORT_DIPSETTING(    0x00, "Faster" )
455   PORT_DIPNAME( 0x18, 0x10, "Game mode" )               PORT_DIPLOCATION("SW2:4,5")
456   PORT_DIPSETTING(    0x18, "Demo Sounds Off" )
457   PORT_DIPSETTING(    0x10, "Demo Sounds On" )
458   PORT_DIPSETTING(    0x08, "Infinite Lives (Cheat)")
459   PORT_DIPSETTING(    0x00, "Freeze" )
460   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Flip_Screen ) )      PORT_DIPLOCATION("SW2:6")
461   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
462   PORT_DIPSETTING(    0x00, DEF_STR( On ) )            /* Check the "Non Bugs" page */
463   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Difficulty ) )      PORT_DIPLOCATION("SW2:7")
464   PORT_DIPSETTING(    0x40, DEF_STR( Easy ) )
465   PORT_DIPSETTING(    0x00, DEF_STR( Hard ) )
466   PORT_DIPUNKNOWN_DIPLOC(0x80, IP_ACTIVE_LOW, "SW2:8")   /* Listed as Unused, it is actually tested in many places */
467INPUT_PORTS_END
468
469
470/***************************************************************************
471**
472**  Graphics Layout
473**
474***************************************************************************/
475
476static const gfx_layout sprite_layout =
477{
478   16,16,
479   0x100,
480   3,
481   { 0,0x2000*8,0x4000*8 },
482   {
483      7,6,5,4,3,2,1,0,
484      15,14,13,12,11,10,9,8
485   },
486   {
487      0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
488      8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16
489   },
490   256
491};
492
493static const gfx_layout tile_layout =
494{
495   8,8,
496   0x100,
497   4,
498   { 0, 1, 2, 3 },
499   { 4, 0, 12, 8, 20, 16, 28, 24},
500   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
501   256
502};
503
504static GFXDECODE_START( marvins )
505   GFXDECODE_ENTRY( "gfx1", 0, tile_layout,   0x080, 8  ) /* text layer */
506   GFXDECODE_ENTRY( "gfx2", 0, tile_layout,   0x110, 1  ) /* background */
507   GFXDECODE_ENTRY( "gfx3", 0, tile_layout,   0x100, 1  ) /* foreground */
508   GFXDECODE_ENTRY( "gfx4", 0, sprite_layout,   0x000, 16 ) /* sprites */
509GFXDECODE_END
510
511
512/***************************************************************************
513**
514**  Machine Driver
515**
516***************************************************************************/
517
518static MACHINE_DRIVER_START( marvins )
519
520   /* basic machine hardware */
521   MDRV_CPU_ADD("main", Z80, 3360000)   /* 3.36 MHz */
522   MDRV_CPU_PROGRAM_MAP(marvins_cpuA_map,0)
523   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
524
525   MDRV_CPU_ADD("sub", Z80, 3360000)   /* 3.36 MHz */
526   MDRV_CPU_PROGRAM_MAP(marvins_cpuB_map,0)
527   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
528
529   MDRV_CPU_ADD("audio", Z80, 4000000)   /* 4.0 MHz */
530   MDRV_CPU_PROGRAM_MAP(sound_map,0)
531   MDRV_CPU_IO_MAP(sound_portmap,0)
532   MDRV_CPU_PERIODIC_INT(nmi_line_assert, 244)   // schematics show a separate 244Hz timer
533
534   MDRV_INTERLEAVE(100)
535
536   /* video hardware */
537   MDRV_VIDEO_ATTRIBUTES(VIDEO_HAS_SHADOWS)
538
539   MDRV_SCREEN_ADD("main", RASTER)
540   MDRV_SCREEN_REFRESH_RATE(60.606060)
541   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */)
542   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
543   MDRV_SCREEN_SIZE(256+32, 224)
544   MDRV_SCREEN_VISIBLE_AREA(0, 255+32,0, 223)
545
546   MDRV_GFXDECODE(marvins)
547   MDRV_PALETTE_LENGTH((16+2)*16)
548
549   MDRV_VIDEO_START(marvins)
550   MDRV_VIDEO_UPDATE(marvins)
551
552   /* sound hardware */
553   MDRV_SPEAKER_STANDARD_MONO("mono")
554
555   MDRV_SOUND_ADD("ay1", AY8910, 2000000)
556   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
557
558   MDRV_SOUND_ADD("ay2", AY8910, 2000000)
559   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
560
561   MDRV_SOUND_ADD("namco", NAMCO, 8000000/256)
562   MDRV_SOUND_CONFIG(snkwave_interface)
563   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
564MACHINE_DRIVER_END
565
566
567static MACHINE_DRIVER_START( vangrd2 )
568
569   /* basic machine hardware */
570   MDRV_CPU_ADD("main", Z80, 3360000)   /* 3.36 MHz */
571   MDRV_CPU_PROGRAM_MAP(madcrash_cpuA_map,0)
572   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
573
574   MDRV_CPU_ADD("sub", Z80, 3360000)   /* 3.36 MHz */
575   MDRV_CPU_PROGRAM_MAP(madcrash_cpuB_map,0)
576   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
577
578   MDRV_CPU_ADD("audio", Z80, 4000000)   /* 4.0 MHz */
579   MDRV_CPU_PROGRAM_MAP(sound_map,0)
580   MDRV_CPU_IO_MAP(sound_portmap,0)
581   MDRV_CPU_PERIODIC_INT(nmi_line_assert, 244)
582
583   MDRV_INTERLEAVE(100)
584
585   /* video hardware */
586   MDRV_VIDEO_ATTRIBUTES(VIDEO_HAS_SHADOWS)
587
588   MDRV_SCREEN_ADD("main", RASTER)
589   MDRV_SCREEN_REFRESH_RATE(60.606060)
590   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */)
591   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
592   MDRV_SCREEN_SIZE(256+32, 224)
593   MDRV_SCREEN_VISIBLE_AREA(0, 255+32,0, 223)
594
595   MDRV_GFXDECODE(marvins)
596   MDRV_PALETTE_LENGTH((16+2)*16)
597
598   MDRV_VIDEO_START(marvins)
599   MDRV_VIDEO_UPDATE(madcrash)
600
601   /* sound hardware */
602   MDRV_SPEAKER_STANDARD_MONO("mono")
603
604   MDRV_SOUND_ADD("ay1", AY8910, 2000000)
605   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
606
607   MDRV_SOUND_ADD("ay2", AY8910, 2000000)
608   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
609
610   MDRV_SOUND_ADD("namco", NAMCO, 8000000/256)
611   MDRV_SOUND_CONFIG(snkwave_interface)
612   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
613MACHINE_DRIVER_END
614
615
616static MACHINE_DRIVER_START( madcrash )
617
618   /* basic machine hardware */
619   MDRV_IMPORT_FROM( vangrd2 )
620
621   MDRV_CPU_MODIFY("main")
622   MDRV_CPU_VBLANK_INT_HACK(0, 0)
623
624   MDRV_CPU_MODIFY("sub")
625   MDRV_CPU_VBLANK_INT("main", snk_irq_BA)
626
627   MDRV_INTERLEAVE(300)
628
629   /* video hardware */
630   MDRV_SCREEN_MODIFY("main")
631   MDRV_SCREEN_VISIBLE_AREA(16, 16+256-1, 0, 0+216-1)
632MACHINE_DRIVER_END
633
634
635/***************************************************************************
636**
637**  ROM Loading
638**
639**  note:
640**      Mad Crasher doesn't pass its internal checksum
641**      Also, some of the background graphics look to be incorrect.
642**
643***************************************************************************/
644
645ROM_START( marvins )
646   ROM_REGION( 0x10000, "main", 0 )   /* 64k for CPUA code */
647   ROM_LOAD( "pa1",   0x0000, 0x2000, CRC(0008d791) SHA1(6ffb174b2d680314f74efeef83da9f3ee3e0c753) )
648   ROM_LOAD( "pa2",   0x2000, 0x2000, CRC(9457003c) SHA1(05ecd5c638a12163e2a65bdfcc09875618f792e1) )
649   ROM_LOAD( "pa3",   0x4000, 0x2000, CRC(54c33ecb) SHA1(cfbf9ffc125fbc51f2abef180f36781f9e748bbd) )
650
651   ROM_REGION( 0x10000, "sub", 0 )   /* 64k for CPUB code */
652   ROM_LOAD( "pb1",   0x0000, 0x2000, CRC(3b6941a5) SHA1(9c29870196eaed87f34456fdb06bf7b69c8f489d) )
653
654   ROM_REGION( 0x10000, "audio", 0 )   /* 64k for sound code */
655   ROM_LOAD( "m1",    0x0000, 0x2000, CRC(2314c696) SHA1(1b84a0c82a4dcff648752f53aa1f0abf5357c5d1) )
656   ROM_LOAD( "m2",    0x2000, 0x2000, CRC(74ba5799) SHA1(c278b0e5c4134f6077d4ae7b51e3c5cba28af1a8) )
657
658   ROM_REGION( 0x2000, "gfx1", ROMREGION_DISPOSE )
659   ROM_LOAD( "s1",    0x0000, 0x2000, CRC(327f70f3) SHA1(078dcc6b4697617d4d833ccd59c6a543b2a88d9e) )   /* characters */
660
661   ROM_REGION( 0x2000, "gfx2", ROMREGION_DISPOSE )
662   ROM_LOAD( "b1",    0x0000, 0x2000, CRC(e528bc60) SHA1(3365ac7cbc57739054bc11e68831be87c0c1a97a) )   /* background tiles */
663
664   ROM_REGION( 0x2000, "gfx3", ROMREGION_DISPOSE )
665   ROM_LOAD( "b2",    0x0000, 0x2000, CRC(e528bc60) SHA1(3365ac7cbc57739054bc11e68831be87c0c1a97a) )   /* foreground tiles */
666
667   ROM_REGION( 0x6000, "gfx4", ROMREGION_DISPOSE )
668   ROM_LOAD( "f3",    0x0000, 0x2000, CRC(e55c9b83) SHA1(04b0d99955e4b11820015b7721ac6399a3d5a829) )   /* sprites */
669   ROM_LOAD( "f2",    0x2000, 0x2000, CRC(8fc2b081) SHA1(fb345965375cb62ec1b947d6c6d071380dc0f395) )
670   ROM_LOAD( "f1",    0x4000, 0x2000, CRC(0bd6b4e5) SHA1(c56747ff2135db734f1b5f6c2906de5ac8f53bbc) )
671
672   ROM_REGION( 0x0c00, "proms", 0 )
673   ROM_LOAD( "marvmaze.j1",  0x000, 0x400, CRC(92f5b06d) SHA1(97979ffb6fb065d9c99da43173180fefb2de1886) )
674   ROM_LOAD( "marvmaze.j2",  0x400, 0x400, CRC(d2b25665) SHA1(b913b8b9c5ee0a29b5a115b2432c5706979059cf) )
675   ROM_LOAD( "marvmaze.j3",  0x800, 0x400, CRC(df9e6005) SHA1(8f633f664c3f8e4f6ca94bee74a68c8fda8873e3) )
676ROM_END
677
678ROM_START( madcrash )
679   ROM_REGION( 0x10000, "main", 0 )   /* 64k for CPUA code */
680   ROM_LOAD( "p8",    0x0000, 0x2000, CRC(ecb2fdc9) SHA1(7dd79fbbe286a9f18ed2cae45b1bfab765e549a1) )
681   ROM_LOAD( "p9",    0x2000, 0x2000, CRC(0a87df26) SHA1(327710452bdc5dbb931abc853957225814f224c5) )
682   ROM_LOAD( "p10",   0x4000, 0x2000, CRC(6eb8a87c) SHA1(375377df22b331175aaf1f9eb8d8ad83e8e146f6) )
683
684   ROM_REGION( 0x10000, "sub", 0 )   /* 64k for CPUB code */
685   ROM_LOAD( "p4",   0x0000, 0x2000, CRC(5664d699) SHA1(5bfa57a0f8d718d522003da6513a70d7ca3a87a3) )
686   ROM_LOAD( "p5",   0x2000, 0x2000, CRC(dea2865a) SHA1(0807281e35159ee29fbe2d1aa087b57804f1a14f) )
687   ROM_LOAD( "p6",   0x4000, 0x2000, CRC(e25a9b9c) SHA1(26853611e3898907239e15f1a00f62290889f89b) )
688   ROM_LOAD( "p7",   0x6000, 0x2000, CRC(55b14a36) SHA1(7d5566a6ba285af92ddf560efda60a79f1da84c2) )
689   ROM_LOAD( "p3",   0x8000, 0x2000, CRC(e3c8c2cb) SHA1(b3e39eacd2609ff0fa0f511bff0fc83e6b3970d4) )
690
691   ROM_REGION( 0x10000, "audio", 0 )   /* 64k for sound code */
692   ROM_LOAD( "p1",   0x0000, 0x2000, CRC(2dcd036d) SHA1(4da42ab1e502fff57f5d5787df406289538fa484) )
693   ROM_LOAD( "p2",   0x2000, 0x2000, CRC(cc30ae8b) SHA1(ffedc747b9e0b616a163ff8bb1def318e522585b) )
694
695   ROM_REGION( 0x2000, "gfx1", ROMREGION_DISPOSE )
696   ROM_LOAD( "p13",    0x0000, 0x2000, CRC(48c4ade0) SHA1(3628abb4f425b8c9d8659c8e4082735168b0f3e9) )   /* characters */
697
698   ROM_REGION( 0x2000, "gfx2", ROMREGION_DISPOSE )
699   ROM_LOAD( "p11",    0x0000, 0x2000, CRC(67174956) SHA1(65a921176294212971c748932a9010f45e1fb499) )   /* background tiles */
700
701   ROM_REGION( 0x2000, "gfx3", ROMREGION_DISPOSE )
702   ROM_LOAD( "p12",    0x0000, 0x2000, CRC(085094c1) SHA1(5c5599d1ed7f8a717ada54bbd28383a22e09a8fe) )   /* foreground tiles */
703
704   ROM_REGION( 0x6000, "gfx4", ROMREGION_DISPOSE )
705   ROM_LOAD( "p14",    0x0000, 0x2000, CRC(07e807bc) SHA1(f651d3a5394ced8e0a1b2be3aa52b3e5a5d84c37) )   /* sprites */
706   ROM_LOAD( "p15",    0x2000, 0x2000, CRC(a74149d4) SHA1(e8011a8d4d1a98a0ffe67fc28ea9fa192ca80321) )
707   ROM_LOAD( "p16",    0x4000, 0x2000, CRC(6153611a) SHA1(b352f92b233761122f74830e46913cc4df800259) )
708
709   ROM_REGION( 0x0c00, "proms", 0 )
710   ROM_LOAD( "m3-prom.j3",  0x000, 0x400, CRC(d19e8a91) SHA1(b21fbdb8ed8d0b27c3ec78cf2e115624f69c67e0) )
711   ROM_LOAD( "m2-prom.j4",  0x400, 0x400, CRC(9fc325af) SHA1(a180662f168ba001376f25f5d9205cb119c1ffee) )
712   ROM_LOAD( "m1-prom.j5",  0x800, 0x400, CRC(07678443) SHA1(267951886d8b031dd633dc4823d9bd862a585437) )
713ROM_END
714
715ROM_START( vangrd2 )
716   ROM_REGION( 0x10000, "main", 0 )
717   ROM_LOAD( "p1.9a",  0x0000, 0x2000, CRC(bc9eeca5) SHA1(5a737e0f0aa1a3a5296d1e1fec13b34aee970609) )
718   ROM_LOAD( "p3.11a", 0x2000, 0x2000, CRC(3970f69d) SHA1(b0ef7494888804ab5b4002730fb0232a7fd6797b) )
719   ROM_LOAD( "p2.12a", 0x4000, 0x2000, CRC(58b08b58) SHA1(eccc85191d678a0115a113002a43203afd857a5b) )
720   ROM_LOAD( "p4.14a", 0x6000, 0x2000, CRC(a95f11ea) SHA1(8007efb4ad948c8768e474fc77134f3ce52da1d2) )
721
722   ROM_REGION( 0x10000, "sub", 0 )
723   ROM_LOAD( "p5.4a", 0x0000, 0x2000, CRC(e4dfd0ba) SHA1(12d45ff147f3ea9c9e898c3831874cd7c1a071b7) )
724   ROM_LOAD( "p6.6a", 0x2000, 0x2000, CRC(894ff00d) SHA1(1c66f327d8e94dc6ac386e11fcc5eb17c9081434) )
725   ROM_LOAD( "p7.7a", 0x4000, 0x2000, CRC(40b4d069) SHA1(56c464bd055125ffc2da02d70137aa5efe5cd8f6) )
726
727   ROM_REGION( 0x10000, "audio", 0 )   /* 64k for sound code */
728   ROM_LOAD( "p8.6a", 0x0000, 0x2000, CRC(a3daa438) SHA1(4e659ac7e3ebaf85bc3ce5c9946fcf0af23083b4) )
729   ROM_LOAD( "p9.8a", 0x2000, 0x2000, CRC(9345101a) SHA1(b99ad1c2a79df50b0a60fdd43ca466f6cb38445b) )
730
731   ROM_REGION( 0x2000, "gfx1", ROMREGION_DISPOSE )
732   ROM_LOAD( "p15.1e", 0x0000, 0x2000, CRC(85718a41) SHA1(4c9aa1f8b229410414cd67bac8cb10a14bea12f4) )   /* characters */
733
734   ROM_REGION( 0x2000, "gfx2", ROMREGION_DISPOSE )
735   ROM_LOAD( "p13.1a", 0x0000, 0x2000, CRC(912f22c6) SHA1(5042edc80b58f77b3576b5e6eb8c6460c8a35494) )   /* background tiles */
736
737   ROM_REGION( 0x2000, "gfx3", ROMREGION_DISPOSE )
738   ROM_LOAD( "p9",     0x0000, 0x2000, CRC(7aa0b684) SHA1(d52670ec50b1a07d6c2c537f67922063deacdeea) )   /* foreground tiles */
739
740   ROM_REGION( 0x6000, "gfx4", ROMREGION_DISPOSE )
741   ROM_LOAD( "p12.1kl", 0x0000, 0x2000, CRC(8658ea6c) SHA1(d5ea9be2c1776b11abc77c944a653eeb73b27fc8) )   /* sprites */
742   ROM_LOAD( "p11.3kl", 0x2000, 0x2000, CRC(620cd4ec) SHA1(a2fcc3d24d0d3c7cc601620ae7a709f46b613c0f) )
743   ROM_LOAD( "p10.4kl", 0x4000, 0x2000, CRC(5bfc04c0) SHA1(4eb152fdf39cb0024f71d5bdf1bfc79c2b8c2329) )
744
745   ROM_REGION( 0x0c00, "proms", 0 )
746   ROM_LOAD( "mb7054.3j", 0x000, 0x400, CRC(506f659a) SHA1(766f1a0dd462eba64546c514004e6542e200d7c3) )
747   ROM_LOAD( "mb7054.4j", 0x400, 0x400, CRC(222133ce) SHA1(109a63c8c44608a8ad9183e7b5d269765cc5f067) )
748   ROM_LOAD( "mb7054.5j", 0x800, 0x400, CRC(2e21a79b) SHA1(1956377c799e0bbd127bf4fae016adc148efe007) )
749ROM_END
750
751
752/*******************************************************************************************/
753
754static DRIVER_INIT( marvins )
755{
756   sound_cpu_busy = 0;
757   marvins_gamegroup = 0;
758}
759
760static DRIVER_INIT( madcrash )
761{
762/*
763    The following lines patch out the ROM test (which fails - probably
764    because of bit rot, so the rest of the test mode (what little there
765    is) can be explored.
766
767    UINT8 *mem = memory_region(machine, "main");
768    mem[0x3a5d] = 0; mem[0x3a5e] = 0; mem[0x3a5f] = 0;
769*/
770   sound_cpu_busy = 0;
771   marvins_gamegroup = 1;
772   snk_irq_delay = 1700;
773}
774
775static DRIVER_INIT( vangrd2 )
776{
777   sound_cpu_busy = 0;
778   marvins_gamegroup = 2;
779}
780
781
782GAME( 1983, marvins,  0, marvins,  marvins,  marvins,  ROT270, "SNK", "Marvin's Maze", 0 )
783GAME( 1984, madcrash, 0, madcrash, madcrash, madcrash, ROT0,   "SNK", "Mad Crasher", GAME_IMPERFECT_GRAPHICS )
784GAME( 1984, vangrd2,  0, vangrd2,  vangrd2,  vangrd2,  ROT270, "SNK", "Vanguard II", 0 )
src/mame/drivers/sgladiat.c
r3178r3179
1/*
2    "Gladiator"
3    (C) 1984 SNK
4
5
6    known issues:
7    sound/music doesn't sound good (but it might be correct)
8    cocktail support is missing
9
10Change Log
11----------
12
13AT08XX03:
14 - fixed music tempo, shadows and reduced sprite lag
15
16   The chips should be in good sync but quite a bit of lag
17   remains without overclocking CPUB. I guess you can't beat
18   a game with barrel-rolling bad guys in plate armors who
19   can outrun a horse.
20*/
21
22#include "driver.h"
23#include "cpu/z80/z80.h"
24#include "snk.h"
25#include "sound/ay8910.h"
26
27extern UINT8 *snk_rambase;
28
29static const gfx_layout tile_layout =
30{
31   8,8,
32   256,
33   4,
34   { 0, 1, 2, 3 },
35   { 4, 0, 12, 8, 20, 16, 28, 24},
36   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
37   256
38};
39
40static const gfx_layout sprite_layout =
41{
42   16,16,
43   256,
44   3,
45   { 2*0x2000*8,1*0x2000*8,0*0x2000*8},
46   { 7,6,5,4,3,2,1,0, 15,14,13,12,11,10,9,8 },
47   { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
48      8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
49   256
50};
51
52static GFXDECODE_START( tnk3 )
53   GFXDECODE_ENTRY( "gfx1", 0x0, tile_layout,   128*3,  8 )
54   GFXDECODE_ENTRY( "gfx2", 0x0, tile_layout,   128*1, 16 )
55   GFXDECODE_ENTRY( "gfx3", 0x0, sprite_layout,   128*0, 16 )
56GFXDECODE_END
57
58/************************************************************************/
59
60static WRITE8_HANDLER( sgladiat_soundlatch_w )
61{
62   snk_sound_busy_bit = 0x20;
63   soundlatch_w( machine, offset, data );
64
65   /* trigger NMI on sound CPU */
66   cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, PULSE_LINE);   // safer because NMI can be lost in rare occations
67}
68
69static READ8_HANDLER( sgladiat_soundlatch_r )
70{
71   snk_sound_busy_bit = 0;
72   return(soundlatch_r(machine,0));
73}
74
75static READ8_HANDLER( sgladiat_sound_nmi_ack_r )
76{
77//  cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, CLEAR_LINE);
78   return 0;
79}
80
81/************************************************************************/
82
83static READ8_HANDLER( sgladiat_inp0_r )
84{
85   return(input_port_read(machine, "IN0") | snk_sound_busy_bit);
86}
87
88static WRITE8_HANDLER( sglatiat_flipscreen_w )
89{
90   /* 0xa006 */
91   /* x------- screen is flipped */
92}
93
94static ADDRESS_MAP_START( sgladiat_cpuA_map, ADDRESS_SPACE_PROGRAM, 8 )
95   AM_RANGE(0x0000, 0x9fff) AM_ROM
96   AM_RANGE(0xa000, 0xa000) AM_READ(sgladiat_inp0_r)
97   AM_RANGE(0xa100, 0xa100) AM_READ(input_port_1_r) /* joy1 */
98   AM_RANGE(0xa200, 0xa200) AM_READ(input_port_2_r) /* joy2 */
99   AM_RANGE(0xa300, 0xa300) AM_WRITE(sgladiat_soundlatch_w)
100   AM_RANGE(0xa400, 0xa400) AM_READ(input_port_3_r) /* dsw1 */
101   AM_RANGE(0xa500, 0xa500) AM_READ(input_port_4_r) /* dsw2 */
102   AM_RANGE(0xa600, 0xa600) AM_WRITE(sglatiat_flipscreen_w)
103   AM_RANGE(0xa700, 0xa700) AM_READWRITE(snk_cpuB_nmi_trigger_r, snk_cpuA_nmi_ack_w)
104   AM_RANGE(0xd000, 0xd7ff) AM_RAM AM_SHARE(3) AM_BASE(&snk_rambase)
105//      AM_RANGE(0xd200, 0xd200) AM_WRITE(SMH_RAM) /* ?0x24 */
106//      AM_RANGE(0xd300, 0xd300) AM_WRITE(SMH_RAM) /* ------xx: msb scrollx */
107//      AM_RANGE(0xd400, 0xd400) AM_WRITE(SMH_RAM) /* xscroll (sprite) */
108//      AM_RANGE(0xd500, 0xd500) AM_WRITE(SMH_RAM) /* yscroll (sprite) */
109//      AM_RANGE(0xd600, 0xd600) AM_WRITE(SMH_RAM) /* xscroll (bg) */
110//      AM_RANGE(0xd700, 0xd700) AM_WRITE(SMH_RAM) /* yscroll (bg) */
111   AM_RANGE(0xd800, 0xdfff) AM_RAM AM_BASE(&spriteram) AM_SHARE(1)
112   AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_BASE(&videoram) AM_SHARE(2)
113   AM_RANGE(0xe800, 0xefff) AM_RAM
114   AM_RANGE(0xf000, 0xf7ff) AM_RAM AM_SHARE(4)
115ADDRESS_MAP_END
116
117static ADDRESS_MAP_START( sgladiat_cpuB_map, ADDRESS_SPACE_PROGRAM, 8 )
118   AM_RANGE(0x0000, 0x9fff) AM_ROM
119   AM_RANGE(0xa000, 0xa000) AM_READWRITE(snk_cpuA_nmi_trigger_r, snk_cpuB_nmi_ack_w)
120   AM_RANGE(0xa600, 0xa600) AM_WRITE(sglatiat_flipscreen_w)
121   AM_RANGE(0xc000, 0xc7ff) AM_RAM AM_BASE(&spriteram) AM_SHARE(1)
122   AM_RANGE(0xc800, 0xcfff) AM_RAM AM_BASE(&videoram) AM_SHARE(2)
123   AM_RANGE(0xd800, 0xdfff) AM_RAM AM_SHARE(3)
124   AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_SHARE(4)
125ADDRESS_MAP_END
126
127static ADDRESS_MAP_START( sgladiat_sound_map, ADDRESS_SPACE_PROGRAM, 8 )
128   AM_RANGE(0x0000, 0x3fff) AM_ROM
129   AM_RANGE(0x8000, 0x87ff) AM_RAM
130   AM_RANGE(0xa000, 0xa000) AM_READ(sgladiat_soundlatch_r)
131   AM_RANGE(0xc000, 0xc000) AM_READ(sgladiat_sound_nmi_ack_r)
132   AM_RANGE(0xe000, 0xe000) AM_WRITE(ay8910_control_port_0_w)
133   AM_RANGE(0xe001, 0xe001) AM_WRITE(ay8910_write_port_0_w)
134   AM_RANGE(0xe002, 0xe003) AM_WRITE(SMH_NOP)   // leftover wave generator ports?
135   AM_RANGE(0xe004, 0xe004) AM_WRITE(ay8910_control_port_1_w)
136   AM_RANGE(0xe005, 0xe005) AM_WRITE(ay8910_write_port_1_w)
137ADDRESS_MAP_END
138
139static ADDRESS_MAP_START( sgladiat_sound_portmap, ADDRESS_SPACE_IO, 8 )
140   ADDRESS_MAP_GLOBAL_MASK(0xff)
141   AM_RANGE(0x00, 0x00) AM_READNOP
142ADDRESS_MAP_END
143
144static MACHINE_DRIVER_START( sgladiat )
145
146   /* basic machine hardware */
147   MDRV_CPU_ADD("main", Z80, 4000000)
148   MDRV_CPU_PROGRAM_MAP(sgladiat_cpuA_map,0)
149//  MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
150
151   MDRV_CPU_ADD("sub", Z80, 5000000)
152   MDRV_CPU_PROGRAM_MAP(sgladiat_cpuB_map,0)
153   MDRV_CPU_VBLANK_INT("main", snk_irq_BA)
154
155   MDRV_CPU_ADD("audio", Z80, 4000000)
156   MDRV_CPU_PROGRAM_MAP(sgladiat_sound_map,0)
157   MDRV_CPU_IO_MAP(sgladiat_sound_portmap,0)
158   MDRV_CPU_PERIODIC_INT(irq0_line_hold, 244)   // Marvin's frequency, sounds ok
159
160   MDRV_INTERLEAVE(300)
161
162   /* video hardware */
163   MDRV_VIDEO_ATTRIBUTES(VIDEO_HAS_SHADOWS)
164
165   MDRV_SCREEN_ADD("main", RASTER)
166   MDRV_SCREEN_REFRESH_RATE(60.606060)
167   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */)
168   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
169   MDRV_SCREEN_SIZE(36*8, 28*8)
170   MDRV_SCREEN_VISIBLE_AREA(0*8+16, 36*8-1-16, 1*8, 28*8-1)
171
172   MDRV_GFXDECODE(tnk3)
173   MDRV_PALETTE_LENGTH(1024)
174
175   MDRV_PALETTE_INIT(aso)
176   MDRV_VIDEO_START(sgladiat)
177   MDRV_VIDEO_UPDATE(sgladiat)
178
179   /* sound hardware */
180   MDRV_SPEAKER_STANDARD_MONO("mono")
181
182   MDRV_SOUND_ADD("ay1", AY8910, 2000000)
183   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
184
185   MDRV_SOUND_ADD("ay2", AY8910, 2000000)
186   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
187MACHINE_DRIVER_END
188
189ROM_START( sgladiat )
190   ROM_REGION( 0x10000, "main", 0 )   /* 64k for cpuA code */
191   ROM_LOAD( "glad.005",   0x0000, 0x4000, CRC(4bc60f0b) SHA1(19baf7533b8fc6bab372f1d35603068a6b93627c) )
192   ROM_LOAD( "glad.004",   0x4000, 0x4000, CRC(db557f46) SHA1(dc3565096c95a20d2c64dd4f5d0b465fbd85e041) )
193   ROM_LOAD( "glad.003",   0x8000, 0x2000, CRC(55ce82b4) SHA1(703f017a8501e4dd5166b5717b244aa6b1e7dc0a) )
194
195   ROM_REGION( 0x10000, "sub", 0 )   /* 64k for cpuB code */
196   ROM_LOAD( "glad.002",   0x0000, 0x4000, CRC(8350261c) SHA1(046099128d5d941b3a37dce559ff5f0aa7f61683) )
197   ROM_LOAD( "glad.001",   0x4000, 0x4000, CRC(5ee9d3fb) SHA1(6c8d8db7a966d3d3a2e8c46fd779e12e1f1e3716) )
198
199   ROM_REGION( 0x10000, "audio", 0 )   /* 64k for sound code */
200   ROM_LOAD( "glad.007",  0x0000, 0x2000, CRC(c25b6731) SHA1(519c6844bfec958b9bb65f148b3527b41fe38b99) )
201   ROM_LOAD( "glad.006",  0x2000, 0x2000, CRC(2024d716) SHA1(6ff069fc53524d13c386e8e714ba3056509adc4d) )
202
203   ROM_REGION( 0x2000, "gfx1", ROMREGION_DISPOSE )
204   ROM_LOAD( "glad.011",   0x0000, 0x2000, CRC(305bb294) SHA1(e148571a581b12ff9502a65ec428e4d19bc757cb) ) /* foreground tiles */
205
206   ROM_REGION( 0x2000, "gfx2", ROMREGION_DISPOSE ) /* background tiles */
207   ROM_LOAD( "glad.012",   0x0000, 0x2000, CRC(b7dd519f) SHA1(7bd760e54712648105d1049e678fa6b9effa600b) )
208
209   ROM_REGION( 0x6000, "gfx3", ROMREGION_DISPOSE ) /* 16x16 sprites */
210   ROM_LOAD( "glad.008", 0x0000, 0x2000, CRC(bcf42587) SHA1(1546fe903fbc6dc0b410c83ab51887c33c91ec2d) )
211   ROM_LOAD( "glad.009", 0x2000, 0x2000, CRC(912a20e0) SHA1(9621b955bc00b7c52ed8363bb441b568efb55863) )
212   ROM_LOAD( "glad.010", 0x4000, 0x2000, CRC(8b1db3a5) SHA1(5ca403d40071ab13deb7fdb04cb0e055e6b30b05) )
213
214   ROM_REGION( 0xc00, "proms", 0 )
215   ROM_LOAD( "82s137.001",  0x000, 0x400, CRC(d9184823) SHA1(455c6a437d54c29673dddb8248ca78d000c7f354) )
216   ROM_LOAD( "82s137.002",  0x400, 0x400, CRC(1a6b0953) SHA1(552ac2897abe507f2fd9ca11c8128a0314af215c) )
217   ROM_LOAD( "82s137.003",  0x800, 0x400, CRC(c0e70308) SHA1(d7dbc500bc9991c2d1b95850f3723a2a224fbfbb) )
218ROM_END
219
220static INPUT_PORTS_START( sgladiat )
221   PORT_START("IN0")
222   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN2 )
223   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
224   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN1 )
225   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
226   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 )
227   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* sound CPU status */
228   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
229   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
230
231   PORT_START("IN1")
232   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
233   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
234   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
235   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
236   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
237   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
238   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
239   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
240
241   PORT_START("IN2")
242   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_COCKTAIL
243   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_COCKTAIL
244   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_COCKTAIL
245   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_COCKTAIL
246   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
247   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
248   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
249   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
250
251   PORT_START("DSW1")   /* Copied from TNK3! */
252   PORT_DIPNAME( 0x01,  0x01, "Walk everywhere (Cheat)")
253   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
254   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
255   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Cabinet ) )
256   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
257   PORT_DIPSETTING(    0x02, DEF_STR( Cocktail ) )
258   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Lives ) )
259   PORT_DIPSETTING(    0x04, "3" )
260   PORT_DIPSETTING(    0x00, "5" )
261   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coinage ) )
262   PORT_DIPSETTING(    0x20, DEF_STR( 3C_1C ) )
263   PORT_DIPSETTING(    0x18, DEF_STR( 2C_1C ) )
264   PORT_DIPSETTING(    0x38, DEF_STR( 1C_1C ) )
265   PORT_DIPSETTING(    0x30, DEF_STR( 1C_2C ) )
266   PORT_DIPSETTING(    0x28, DEF_STR( 1C_3C ) )
267   PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
268   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Bonus_Life ) )
269   PORT_DIPSETTING(    0xc0, "20k 60k" )
270   PORT_DIPSETTING(    0x80, "40k 90k" )
271   PORT_DIPSETTING(    0x40, "50k 120k" )
272   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
273
274   PORT_START("DSW2")   /* Copied from TNK3!  */
275   PORT_DIPNAME( 0x01, 0x01, "Bonus Occurrence" )
276   PORT_DIPSETTING(    0x01, "1st & every 2nd" )
277   PORT_DIPSETTING(    0x00, "1st & 2nd only" )
278   PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) )
279   PORT_DIPSETTING(    0x06, "Easy?" )
280   PORT_DIPSETTING(    0x04, "Normal?" )
281   PORT_DIPSETTING(    0x02, "Hard?" )
282   PORT_DIPSETTING(    0x00, "Hardest?" )
283   PORT_DIPNAME( 0x18, 0x10, "Game Mode" )
284   PORT_DIPSETTING(    0x18, "Demo Sounds Off" )
285   PORT_DIPSETTING(    0x10, "Demo Sounds On" )
286   PORT_DIPSETTING(    0x00, "Freeze" )
287   PORT_DIPSETTING(    0x08, "Infinite Lives (Cheat)")
288   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Flip_Screen ) )
289   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
290   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
291   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
292   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
293   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
294   PORT_DIPNAME( 0x80, 0x00, DEF_STR( Allow_Continue ) )
295   PORT_DIPSETTING(    0x80, DEF_STR( No ) )
296   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
297INPUT_PORTS_END
298
299static DRIVER_INIT( sgladiat )
300{
301   snk_irq_delay = 2000;
302}
303
304GAME( 1984, sgladiat, 0, sgladiat, sgladiat, sgladiat, 0, "SNK", "Gladiator 1984", GAME_NO_COCKTAIL )
src/mame/drivers/jcross.c
r3178r3179
1/*
2Jumping Cross - (c) 1984 SNK
3driver by Tomasz Slanina
4
5Based on marvin's maze driver
6
7Todo:
8- problems with sprites - strange movement in attract mode,
9- $c800-$d7ff - unknown read (related with ^^^ )
10- verify dipswitches
11- verify colors (is palette banking correct ?)
12- unused tileset (almost identical to txt layer tiles ,  few (3?) chars are different)
13- cocktail mdoe/screen flipping
14
15Could be bad dump ('final' romset is made of two sets marked as 'bad' )
16
17*/
18
19#include "driver.h"
20#include "cpu/z80/z80.h"
21#include "snk.h"
22#include "sound/ay8910.h"
23#include "sound/namco.h"
24
25UINT8 *jcr_textram;
26
27READ8_HANDLER( jcross_background_ram_r );
28WRITE8_HANDLER( jcross_background_ram_w );
29
30READ8_HANDLER( jcross_text_ram_r );
31WRITE8_HANDLER( jcross_text_ram_w );
32
33extern VIDEO_START( jcross );
34extern VIDEO_UPDATE( jcross );
35extern int jcross_vregs[5];
36WRITE8_HANDLER( jcross_palettebank_w );
37
38static int sound_cpu_busy=0;
39
40#ifdef UNUSED_FUNCTION
41UINT8 *jcr_sharedram;
42static READ8_HANDLER(sharedram_r){   return jcr_sharedram[offset];}
43static WRITE8_HANDLER(sharedram_w){   jcr_sharedram[offset]=data;}
44#endif
45
46static const namco_interface snkwave_interface =
47{
48   1,
49   0               /* stereo */
50};
51
52static WRITE8_HANDLER( sound_command_w )
53{
54   sound_cpu_busy = 1;
55   soundlatch_w(machine, 0, data);
56   cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, PULSE_LINE);
57}
58
59static READ8_HANDLER( sound_command_r )
60{
61   sound_cpu_busy = 0;
62   return(soundlatch_r(machine,0));
63}
64
65static READ8_HANDLER( sound_nmi_ack_r )
66{
67   cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, CLEAR_LINE);
68   return 0;
69}
70
71static CUSTOM_INPUT( sound_status_r )
72{
73   return sound_cpu_busy;
74}
75
76static WRITE8_HANDLER(jcross_vregs0_w){jcross_vregs[0]=data;}
77static WRITE8_HANDLER(jcross_vregs1_w){jcross_vregs[1]=data;}
78static WRITE8_HANDLER(jcross_vregs2_w){jcross_vregs[2]=data;}
79static WRITE8_HANDLER(jcross_vregs3_w){jcross_vregs[3]=data;}
80static WRITE8_HANDLER(jcross_vregs4_w){jcross_vregs[4]=data;}
81
82
83static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 )
84   AM_RANGE(0x0000, 0x3fff) AM_ROM AM_BASE(&namco_wavedata)
85   AM_RANGE(0x8000, 0x87ff) AM_RAM
86   AM_RANGE(0xa000, 0xa000) AM_READ(sound_command_r)
87   AM_RANGE(0xc000, 0xc000) AM_READ(sound_nmi_ack_r)
88   AM_RANGE(0xe000, 0xe000) AM_WRITE(ay8910_control_port_0_w)
89   AM_RANGE(0xe001, 0xe001) AM_WRITE(ay8910_write_port_0_w)
90   AM_RANGE(0xe002, 0xe007) AM_WRITE(snkwave_w)
91   AM_RANGE(0xe008, 0xe008) AM_WRITE(ay8910_control_port_1_w)
92   AM_RANGE(0xe009, 0xe009) AM_WRITE(ay8910_write_port_1_w)
93ADDRESS_MAP_END
94
95static ADDRESS_MAP_START( sound_portmap, ADDRESS_SPACE_IO, 8 )
96   ADDRESS_MAP_GLOBAL_MASK(0xff)
97   AM_RANGE(0x00, 0x00) AM_READNOP
98ADDRESS_MAP_END
99
100static ADDRESS_MAP_START( cpuA_map, ADDRESS_SPACE_PROGRAM, 8 )
101   AM_RANGE(0x0000, 0x9fff) AM_ROM
102   AM_RANGE(0xa000, 0xa000) AM_READ_PORT("IN0")
103   AM_RANGE(0xa100, 0xa100) AM_READ_PORT("IN1")
104   AM_RANGE(0xa200, 0xa200) AM_READ_PORT("IN2")
105   AM_RANGE(0xa300, 0xa300) AM_WRITE(sound_command_w)
106   AM_RANGE(0xa400, 0xa400) AM_READ_PORT("DSW1")
107   AM_RANGE(0xa500, 0xa500) AM_READ_PORT("DSW2")
108   AM_RANGE(0xa600, 0xa600) AM_WRITE(jcross_palettebank_w)
109   AM_RANGE(0xa700, 0xa700) AM_READWRITE(snk_cpuB_nmi_trigger_r, snk_cpuA_nmi_ack_w)
110   AM_RANGE(0xd300, 0xd300) AM_WRITE(jcross_vregs0_w)
111   AM_RANGE(0xd400, 0xd400) AM_WRITE(jcross_vregs1_w)
112   AM_RANGE(0xd500, 0xd500) AM_WRITE(jcross_vregs2_w)
113   AM_RANGE(0xd600, 0xd600) AM_WRITE(jcross_vregs3_w)
114   AM_RANGE(0xd700, 0xd700) AM_WRITE(jcross_vregs4_w)
115    AM_RANGE(0xd800, 0xdfff) AM_RAM AM_SHARE(1) AM_BASE(&spriteram)
116   AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(jcross_background_ram_w) AM_SHARE(2) AM_BASE(&videoram)
117   AM_RANGE(0xf000, 0xf3ff) AM_RAM_WRITE(jcross_text_ram_w) AM_BASE(&jcr_textram)
118   AM_RANGE(0xf400, 0xffff) AM_RAM
119ADDRESS_MAP_END
120
121static ADDRESS_MAP_START( cpuB_map, ADDRESS_SPACE_PROGRAM, 8 )
122   AM_RANGE(0x0000, 0x7fff) AM_ROM
123   AM_RANGE(0xa700, 0xa700) AM_READWRITE(snk_cpuA_nmi_trigger_r, snk_cpuB_nmi_ack_w)
124     AM_RANGE(0xc000, 0xc7ff) AM_RAM AM_SHARE(1)
125   AM_RANGE(0xc800, 0xd7ff) AM_RAM AM_SHARE(2) /* unknown ??? */
126ADDRESS_MAP_END
127
128
129static INPUT_PORTS_START( jcross )
130   PORT_START("IN0")
131   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
132   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
133   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN3 )
134   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_START1 )
135   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_START2 )
136   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(sound_status_r, NULL) /* sound CPU status */
137
138
139   PORT_START("IN1")
140   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
141   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
142   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
143   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
144   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 )
145   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 )
146
147
148   PORT_START("IN2")
149   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
150   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
151   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
152   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
153   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
154   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
155   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
156
157   PORT_START("DSW1")
158   PORT_DIPNAME( 0x01, 0x01, "Unknown SW 1-0" )
159   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
160   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
161   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Cabinet ) )
162   PORT_DIPSETTING(    0x02, DEF_STR( Upright ) )
163   PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
164
165   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Lives ) )
166   PORT_DIPSETTING(    0x04, "3" )
167   PORT_DIPSETTING(    0x00, "5" )
168   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coinage ) )
169   /* PORT_DIPSETTING(    0x10,  )  ???? 'insert more coin'*/
170   PORT_DIPSETTING(    0x28, DEF_STR( 3C_1C ) )
171   PORT_DIPSETTING(    0x30, DEF_STR( 2C_1C ) )
172   PORT_DIPSETTING(    0x38, DEF_STR( 1C_1C ) )
173   PORT_DIPSETTING(    0x18, DEF_STR( 1C_2C ) )
174   PORT_DIPSETTING(    0x20, DEF_STR( 1C_3C ) )
175   PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
176   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Bonus_Life ) )
177   PORT_DIPSETTING(    0xc0, "20000 60000" )
178   PORT_DIPSETTING(    0x80, "40000 90000" )
179   PORT_DIPSETTING(    0x40, "50000 120000" )
180   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
181
182   PORT_START("DSW2")
183   PORT_DIPNAME( 0x01, 0x00, "Bonus Life Occurence" ) /* not verified */
184   PORT_DIPSETTING(    0x01, "1st, 2nd, then every 2nd" )
185   PORT_DIPSETTING(    0x00, "1st and 2nd only" )
186   PORT_DIPNAME( 0x06, 0x04, "scrolling speed" )
187   PORT_DIPSETTING(    0x06, "Slow" )
188   PORT_DIPSETTING(    0x04, DEF_STR( Normal ) )
189   PORT_DIPSETTING(    0x02, "Fast" )
190   PORT_DIPSETTING(    0x00, "Fastest" )
191   PORT_DIPNAME( 0x18, 0x10, "Game mode" )
192   PORT_DIPSETTING(    0x18, "Demo Sounds Off" )
193   PORT_DIPSETTING(    0x10, "Demo Sounds On" )
194   PORT_DIPSETTING(    0x08, "Infinite Lives (Cheat)" )
195   PORT_DIPSETTING(    0x00, "Freeze" )
196   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Flip_Screen ) )
197   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
198   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
199   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Difficulty ) )
200   PORT_DIPSETTING(    0x40, DEF_STR( Easy ) )
201   PORT_DIPSETTING(    0x00, DEF_STR( Hard ) )
202   PORT_DIPNAME( 0x80, 0x80, "BG Collisions" )
203   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
204   PORT_DIPSETTING(    0x80, DEF_STR( On ) )
205
206INPUT_PORTS_END
207
208
209
210/***************************************************************************
211**
212**  Graphics Layout
213**
214***************************************************************************/
215
216static const gfx_layout sprite_layout =
217{
218   16,16,
219   RGN_FRAC(1,3),
220   3,
221   { 0,0x2000*8,0x4000*8 },
222   {
223      7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8
224   },
225   {
226      0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
227      8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16
228   },
229   256
230};
231
232static const gfx_layout tile_layout =
233{
234   8,8,
235   RGN_FRAC(1,1),
236   4,
237   { 0, 1, 2, 3 },
238   { 4, 0, 12, 8, 20, 16, 28, 24},
239   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
240   256
241};
242
243static GFXDECODE_START( jcross )
244   GFXDECODE_ENTRY( "gfx1", 0, tile_layout,   0x080, 8  )
245   GFXDECODE_ENTRY( "gfx2", 0, tile_layout,   0x110, 1  )
246   GFXDECODE_ENTRY( "gfx3", 0, tile_layout,   0x100, 1  )
247   GFXDECODE_ENTRY( "gfx4", 0, sprite_layout,   0x000, 16 ) /* sprites */
248GFXDECODE_END
249
250
251/***************************************************************************
252**
253**  Machine Driver
254**
255***************************************************************************/
256
257static MACHINE_DRIVER_START( jcross )
258
259   MDRV_CPU_ADD("main", Z80, 3360000)
260   MDRV_CPU_PROGRAM_MAP(cpuA_map,0)
261   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
262
263   MDRV_CPU_ADD("sub", Z80, 3360000)
264   MDRV_CPU_PROGRAM_MAP(cpuB_map,0)
265   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
266
267   MDRV_CPU_ADD("audio", Z80, 4000000)
268   MDRV_CPU_PROGRAM_MAP(sound_map,0)
269   MDRV_CPU_IO_MAP(sound_portmap,0)
270   MDRV_CPU_PERIODIC_INT(irq0_line_hold, 244)
271
272   MDRV_INTERLEAVE(100)
273
274   /* video hardware */
275   MDRV_SCREEN_ADD("main", RASTER)
276   MDRV_SCREEN_REFRESH_RATE(61)
277   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */)
278   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
279   MDRV_SCREEN_SIZE(512, 512)
280   MDRV_SCREEN_VISIBLE_AREA(0, 255,0, 223)
281
282   MDRV_GFXDECODE(jcross)
283   MDRV_PALETTE_LENGTH((16+2)*16)
284   MDRV_VIDEO_START(jcross)
285   MDRV_VIDEO_UPDATE(jcross)
286
287   /* sound hardware */
288   MDRV_SPEAKER_STANDARD_MONO("mono")
289
290   MDRV_SOUND_ADD("ay1", AY8910, 2000000)
291   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.35)
292
293   MDRV_SOUND_ADD("ay2", AY8910, 2000000)
294   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.35)
295
296   MDRV_SOUND_ADD("namco", NAMCO, 24000)
297   MDRV_SOUND_CONFIG(snkwave_interface)
298   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.08)
299MACHINE_DRIVER_END
300
301
302ROM_START( jcross )
303   ROM_REGION( 0x10000, "main", 0 )
304   ROM_LOAD( "jcrossa0.10b",  0x0000, 0x2000, CRC(0e79bbcd) SHA1(7088a8effd30080529b797991e24e9807bf90475) )
305   ROM_LOAD( "jcrossa1.12b",  0x2000, 0x2000, CRC(999b2bcc) SHA1(e5d13c9c11a82cedee15777341e6424639ecf2f5) )
306   ROM_LOAD( "jcrossa2.13b",  0x4000, 0x2000, CRC(ac89e49c) SHA1(9b9a0eec8ad341ce7af58bffe55f10bec696af62) )
307   ROM_LOAD( "jcrossa3.14b",  0x6000, 0x2000, CRC(4fd7848d) SHA1(870aea0b8e027616814df87afd24418fd140f736) )
308   ROM_LOAD( "jcrossa4.15b",  0x8000, 0x2000, CRC(8500575d) SHA1(b8751b86508de484f2eb8a6702c63a47ec882036) )
309
310   ROM_REGION( 0x10000, "sub", 0 )
311   ROM_LOAD( "jcrossb0.15a",  0x0000, 0x2000, CRC(77ed51e7) SHA1(56b457846f71f442da6f99889231d4b71d5fcb6c) )
312   ROM_LOAD( "jcrossb1.14a",  0x2000, 0x2000, CRC(23cf0f70) SHA1(f258e899f332a026eeb0db92330fd60c478218af) )
313   ROM_LOAD( "jcrossb2.13a",  0x4000, 0x2000, CRC(5bed3118) SHA1(f105ca55223a4bfbc8e2d61c365c76cf2153254c) )
314   ROM_LOAD( "jcrossb3.12a",  0x6000, 0x2000, CRC(cd75dc95) SHA1(ef03d2b0f66f30fad5132e7b6aee9ec978650b53) )
315
316   ROM_REGION( 0x10000, "audio", 0 )
317   ROM_LOAD( "jcrosss0.f1",   0x0000, 0x2000, CRC(9ae8ea93) SHA1(1d824302305a41bf5c354c36e2e11981d1aa5ea4) )
318   ROM_LOAD( "jcrosss1.h2",   0x2000, 0x2000, CRC(83785601) SHA1(cd3d484ef5464090c4b543b1edbbedcc52b15071) )
319
320   ROM_REGION( 0x2000, "gfx1", ROMREGION_DISPOSE )
321   ROM_LOAD( "jcrosss.d2",    0x0000, 0x2000, CRC(3ebb5beb) SHA1(de0a1f0fdb5b08b76dab9fa64d9ae3047c4ff84b) )
322
323   ROM_REGION( 0x2000, "gfx2", ROMREGION_DISPOSE )
324   ROM_LOAD( "jcrossb1.a2",   0x0000, 0x2000, CRC(ea3dfbc9) SHA1(eee56acd1c9dbc6c3ecdee4ffe860273e65cc09b) )
325
326   ROM_REGION( 0x2000, "gfx3", ROMREGION_DISPOSE )
327   ROM_LOAD( "jcrossb4.10a",  0x0000, 0x2000, CRC(08ad93fe) SHA1(04baf2d9735b0d794b114abeced5a6b899958ce7) )
328
329   ROM_REGION( 0x6000, "gfx4", ROMREGION_DISPOSE )
330   ROM_LOAD( "jcrossf2.j2",    0x0000, 0x2000, CRC(42a12b9d) SHA1(9f2bdb1f84f444442282cf0fc1f7b3c7f9a9bf48) )
331   ROM_LOAD( "jcrossf1.k2",    0x2000, 0x2000, CRC(70d219bf) SHA1(9ff9f88221edd141e8204ac810434b4290db7cff) )
332   ROM_LOAD( "jcrossf0.l2",  0x4000, 0x2000, CRC(4532509b) SHA1(c99f87e2b06b94d815e6099bccb2aee0edf8c98d) )
333
334   ROM_REGION( 0x0c00, "proms", 0 )
335   ROM_LOAD( "jcrossp2.j7",  0x000, 0x400, CRC(b72a96a5) SHA1(20d40e4b6a2652e61dc3ad0c4afaec04e3c7cf74) )
336   ROM_LOAD( "jcrossp1.j8",  0x400, 0x400, CRC(35650448) SHA1(17e4a661ff304c093bb0253efceaf4e9b2498924) )
337   ROM_LOAD( "jcrossp0.j9",  0x800, 0x400, CRC(99f54d48) SHA1(9bd20eaa9706d28eaca9f5e195204d89e302272f) )
338ROM_END
339
340GAME( 1984, jcross, 0, jcross, jcross, 0, ROT270,   "SNK", "Jumping Cross",GAME_NO_COCKTAIL|GAME_IMPERFECT_GRAPHICS)
src/mame/drivers/hal21.c
r3178r3179
1/*
2    Hal21
3
4
5Change Log
6----------
7
8AT08XX03:
9
10[Common]
11 - added shadows and highlights
12
13 * Cocktail mode involves changing tile offsets and sprite
14   coordinates and is still unsupported.
15
16 * Manuals show both boards have noise filters to smooth out
17   rings and scratches which are especially audible in HAL21.
18
19[HAL21]
20 - installed NMI scheduler to prevent music trashing
21
22[TODO]
23 - verify color effects
24*/
25
26#include "driver.h"
27#include "cpu/z80/z80.h"
28#include "snk.h"
29#include "sound/ay8910.h"
30#include "sound/3812intf.h"
31
32static UINT8 *hal21_vreg, *hal21_sndfifo;
33static UINT8 *textram;
34static int color[2];
35static int snk_blink_parity;   // FIXME likely wrong
36static int snk_sound_busy_bit;
37
38/**************************************************************************/
39
40static void hal21_sound_scheduler(running_machine *machine, int mode, int data)
41{
42   static int busy, hold, ffcount, ffhead, fftail;
43
44   switch (mode)
45   {
46      case 0: // init
47         fftail = ffhead = ffcount = hold = busy = 0;
48      return;
49
50      case 1: // cut-through or capture
51         if (data & ~0x1f) busy = 1; else
52         if (data && busy)
53         {
54            if (ffcount < 16)
55            {
56               ffcount++;
57               hal21_sndfifo[ffhead] = data;
58               ffhead = (ffhead + 1) & 15;
59            }
60            return;
61         }
62      break;
63
64      case 2: // acknowledge
65         if (busy) { busy = 0; hold = 4; }
66      return;
67
68      case 3: // release
69         if (!busy)
70         {
71            if (hold) hold--; else
72            if (ffcount)
73            {
74               ffcount--;
75               data = hal21_sndfifo[fftail];
76               fftail = (fftail + 1) & 15;
77               break;
78            }
79         }
80      return;
81   }
82
83   snk_sound_busy_bit = 0x01;
84   soundlatch_w(machine, 0, data);
85   cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, PULSE_LINE);
86}
87
88/**************************************************************************/
89
90static WRITE8_HANDLER( hal21_vreg0_w ){ hal21_vreg[0] = data; }
91static WRITE8_HANDLER( hal21_vreg1_w ){ hal21_vreg[1] = data; }
92static WRITE8_HANDLER( hal21_vreg2_w ){ hal21_vreg[2] = data; }
93static WRITE8_HANDLER( hal21_vreg3_w ){ hal21_vreg[3] = data; }
94static WRITE8_HANDLER( hal21_vreg4_w ){ hal21_vreg[4] = data; }
95static WRITE8_HANDLER( hal21_vreg5_w ){ hal21_vreg[5] = data; }
96
97
98PALETTE_INIT( aso )
99{
100   int i;
101   int num_colors = 1024;
102
103   /*
104        palette format is RRRG GGBB B??? the three unknown bits are used but
105        I'm not sure how, I'm currently using them as least significant bit but
106        that's most likely wrong.
107    */
108   for( i=0; i<num_colors; i++ )
109   {
110      int bit0=0,bit1,bit2,bit3,r,g,b;
111
112      bit0 = (color_prom[i + 2*num_colors] >> 2) & 0x01;
113      bit1 = (color_prom[i] >> 1) & 0x01;
114      bit2 = (color_prom[i] >> 2) & 0x01;
115      bit3 = (color_prom[i] >> 3) & 0x01;
116      r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
117
118      bit0 = (color_prom[i + 2*num_colors] >> 1) & 0x01;
119      bit1 = (color_prom[i + num_colors] >> 2) & 0x01;
120      bit2 = (color_prom[i + num_colors] >> 3) & 0x01;
121      bit3 = (color_prom[i] >> 0) & 0x01;
122      g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
123
124      bit0 = (color_prom[i + 2*num_colors] >> 0) & 0x01;
125      bit1 = (color_prom[i + 2*num_colors] >> 3) & 0x01;
126      bit2 = (color_prom[i + num_colors] >> 0) & 0x01;
127      bit3 = (color_prom[i + num_colors] >> 1) & 0x01;
128      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
129
130      palette_set_color(machine,i,MAKE_RGB(r,g,b));
131   }
132
133   /* prepare shadow draw table */
134   for (i=0; i<=5; i++) gfx_drawmode_table[i] = DRAWMODE_SOURCE;
135
136   gfx_drawmode_table[6] = DRAWMODE_SHADOW;
137   gfx_drawmode_table[7] = DRAWMODE_NONE;
138}
139
140static VIDEO_START( hal21 )
141{
142   snk_blink_parity = 0;
143}
144
145
146static VIDEO_RESET( aso )
147{
148   color[0] = 8;
149   color[1] = 8;
150}
151
152
153static void hal21_draw_background(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int scrollx, int scrolly, int attrs,
154                        const gfx_element *gfx )
155{
156   int bankbase, c, x, y, offsx, offsy, dx, dy, sx, sy, offs, tile_number;
157
158   bankbase = attrs<<3 & 0x100;
159   c = attrs & 0x0f;
160   if (c > 11) { fillbitmap(bitmap,(c<<4)+8, cliprect); return; }
161   if (c<8 || color[0]<14 || bankbase)
162   {
163      c ^= 0x08;
164      color[0] = c;
165      color[1] = (c & 0x08) ? c : 8;
166   }
167
168   offsx = ((scrollx>>3) + 0) & 0x3f;
169   dx = -(scrollx & 7) + 0;
170   offsy = ((scrolly>>3) + 0) & 0x3f;
171   dy = -(scrolly & 7) + 0;
172
173   for (x=2; x<35; x++)
174      for (y=0; y<28; y++)
175      {
176         offs = (((offsx+x)&0x3f)<<6) + ((offsy+y)&0x3f);
177         sx = (x<<3) + dx;
178         sy = (y<<3) + dy;
179         tile_number = bankbase + videoram[offs];
180         c = (tile_number & ~0x3f) ? color[0] : color[1];
181
182         drawgfx(bitmap, gfx,
183            tile_number, c,
184            0, 0,
185            sx, sy,
186            cliprect, TRANSPARENCY_NONE, 0);
187      }
188}
189
190static void hal21_draw_sprites(bitmap_t *bitmap, const rectangle *cliprect, int scrollx, int scrolly,
191                        const gfx_element *gfx )
192{
193   UINT8 *sprptr, *endptr;
194   int attrs, tile, x, y, color, fy;
195
196   sprptr = spriteram;
197   endptr = spriteram + 0x100;
198
199   for (; sprptr<endptr; sprptr+=4)
200   {
201      if (*(UINT32*)sprptr == 0 || *(UINT32*)sprptr == -1) continue;
202
203      attrs = sprptr[3];
204      tile  = sprptr[1] + (attrs<<2 & 0x100);
205      color = attrs & 0x0f;
206      fy    = attrs & 0x20;
207      y     = (sprptr[0] + (attrs<<4 & 0x100) - scrolly) & 0x1ff;
208      x     = (0x100 - (sprptr[2] + (attrs<<1 & 0x100) - scrollx)) & 0x1ff;
209      if (y > 512-16) y -= 512;
210      if (x > 512-16) x -= 512;
211
212      drawgfx(bitmap, gfx,
213            tile, color,
214            0, fy,
215            x, y,
216            cliprect, TRANSPARENCY_PEN, 7);
217   }
218}
219
220static void tnk3_draw_text(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int bank, UINT8 *source )
221{
222   const gfx_element *gfx = machine->gfx[0];
223
224   int tile_number, color, sx, sy;
225   int x, y;
226
227   for(x=0; x<32; x++) for(y=0; y<32; y++)
228   {
229      tile_number = source[(x<<5)+y];
230
231      if(tile_number == 0x20 || tile_number == 0xff) continue;
232
233      if(bank == -1) color = 8;
234      else
235      {
236         color = tile_number >> 5;
237         tile_number |= bank << 8;
238      }
239      sx = (x+2) << 3;
240      sy = (y+1) << 3;
241
242      drawgfx(bitmap,gfx,tile_number,color,0,0,sx,sy,cliprect,TRANSPARENCY_PEN,15);
243   }
244}
245
246static void tnk3_draw_status_main(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int bank, UINT8 *source, int start )
247{
248   const gfx_element *gfx = machine->gfx[0];
249
250   int tile_number, color, sx, sy;
251   int x, y;
252
253   for(x = start; x < start+2; x++) for(y = 0; y < 32; y++)
254   {
255      tile_number = source[(x<<5)+y];
256
257      if(bank == -1) color = 8;
258      else
259      {
260          color = tile_number >> 5;
261         tile_number |= (bank << 8);
262      }
263      sx = ((x+34)&0x3f) << 3;
264      sy = (y+1) << 3;
265
266      drawgfx(bitmap,gfx,tile_number,color,0,0,sx,sy,cliprect,TRANSPARENCY_NONE,0);
267   }
268}
269
270static void tnk3_draw_status(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int bank, UINT8 *source )
271{
272   tnk3_draw_status_main(machine,bitmap,cliprect,bank,source, 0);
273   tnk3_draw_status_main(machine,bitmap,cliprect,bank,source,30);
274}
275
276static VIDEO_UPDATE( hal21 )
277{
278   int attr, msbs, spsy, spsx, bgsy, bgsx, bank, i;
279
280   attr = (int)hal21_vreg[0];
281   msbs = (int)hal21_vreg[1];
282   spsy = (int)hal21_vreg[2] + (msbs<<5 & 0x100) + 9;
283   spsx = (int)hal21_vreg[3] + (msbs<<8 & 0x100) + 30;
284   bgsy = (int)hal21_vreg[4] + (msbs<<4 & 0x100) - 8;
285   bgsx = (int)hal21_vreg[5] - 16;
286
287   hal21_draw_background(screen->machine, bitmap, cliprect, bgsx+(msbs<<7 & 0x100), bgsy, attr, screen->machine->gfx[1]);
288
289   attr = snk_blink_parity;
290   snk_blink_parity ^= 0xdf;
291   for (i=6; i<0x80; i+=8) { palette_set_color(screen->machine, i, MAKE_RGB(attr, attr, attr)); }
292
293   hal21_draw_sprites(bitmap, cliprect, spsx, spsy, screen->machine->gfx[2]);
294
295   bank = msbs>>6 & 1;
296   tnk3_draw_text(screen->machine, bitmap, cliprect, bank, &textram[0]);
297   tnk3_draw_status(screen->machine, bitmap, cliprect, bank, &textram[0x400]);
298   return 0;
299}
300
301
302static CUSTOM_INPUT( sound_status_r )
303{
304   return snk_sound_busy_bit;
305}
306
307
308static INPUT_PORTS_START( hal21 )
309   PORT_START("SYSTEM")
310   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
311   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
312   PORT_BIT( 0x04, IP_ACTIVE_LOW,  IPT_SERVICE1 )
313   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_START1 )
314   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_START2 )
315   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(sound_status_r, NULL) /* sound CPU status */
316   PORT_BIT( 0x40, IP_ACTIVE_LOW,  IPT_UNKNOWN )
317   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN )
318
319   PORT_START("P1")
320   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
321   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
322   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
323   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
324   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
325   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
326   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
327
328   PORT_START("P2")
329   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
330   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
331   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
332   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
333   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
334   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
335   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
336
337   PORT_START("DSW1")
338   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unused ) )
339   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
340   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
341   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unused ) )
342   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
343   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
344   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Lives ) )
345   PORT_DIPSETTING(    0x04, "3" )
346   PORT_DIPSETTING(    0x00, "5" )
347   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coinage ) )
348   PORT_DIPSETTING(    0x20, DEF_STR( 3C_1C ) )
349   PORT_DIPSETTING(    0x18, DEF_STR( 2C_1C ) )
350   PORT_DIPSETTING(    0x38, DEF_STR( 1C_1C ) )
351   PORT_DIPSETTING(    0x30, DEF_STR( 1C_2C ) )
352   PORT_DIPSETTING(    0x28, DEF_STR( 1C_3C ) )
353   PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
354   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Bonus_Life ) )
355   PORT_DIPSETTING(    0xc0, "20000 60000" )
356   PORT_DIPSETTING(    0x80, "40000 90000" )
357   PORT_DIPSETTING(    0x40, "50000 120000" )
358   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
359
360   PORT_START("DSW2")
361   PORT_DIPNAME( 0x01, 0x01, "Bonus Type" )
362   PORT_DIPSETTING(    0x01, "Every Bonus Set" )
363   PORT_DIPSETTING(    0x00, "Second Bonus Set" )
364   PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) )
365   PORT_DIPSETTING(    0x06, DEF_STR( Easy ) )
366   PORT_DIPSETTING(    0x04, "2" )
367   PORT_DIPSETTING(    0x02, "3" )
368   PORT_DIPSETTING(    0x00, "4" )
369   PORT_DIPNAME( 0x18, 0x18, "Special" )
370   PORT_DIPSETTING(    0x18, DEF_STR( Normal ) )
371   PORT_DIPSETTING(    0x10, DEF_STR( Demo_Sounds) )
372   PORT_DIPSETTING(    0x08, "Infinite Lives" )
373   PORT_DIPSETTING(    0x00, "Freeze" )
374   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Flip_Screen ) ) // 0x20 -> fe65
375   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
376   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
377   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
378   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
379   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
380   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
381   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
382   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
383INPUT_PORTS_END
384
385/**************************************************************************/
386
387static const gfx_layout char256 = {
388   8,8,
389   0x100,
390   4,
391   { 0, 1, 2, 3 },
392   { 4, 0, 12, 8, 20, 16, 28, 24},
393   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
394   256
395};
396
397static const gfx_layout char1024 = {
398   8,8,
399   0x400,
400   4,
401   { 0, 1, 2, 3 },
402   { 4, 0, 12, 8, 20, 16, 28, 24},
403   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
404   256
405};
406
407static const gfx_layout sprite1024 = {
408   16,16,
409   0x400,
410   3,
411   { 2*1024*256,1*1024*256,0*1024*256 },
412   {
413      7,6,5,4,3,2,1,0,
414      15,14,13,12,11,10,9,8
415   },
416   {
417      0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
418      8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16
419   },
420   256
421};
422
423static GFXDECODE_START( aso )
424   /* colors 512-1023 are currently unused, I think they are a second bank */
425   GFXDECODE_ENTRY( "gfx1", 0, char256,    128*3,  8 ) /* colors 384..511 */
426   GFXDECODE_ENTRY( "gfx2", 0, char1024,   128*1, 16 ) /* colors 128..383 */
427   GFXDECODE_ENTRY( "gfx3", 0, sprite1024, 128*0, 16 ) /* colors   0..127 */
428GFXDECODE_END
429
430/**************************************************************************/
431
432static READ8_HANDLER( CPUC_ready_r ) { snk_sound_busy_bit = 0; return 0; }
433
434static WRITE8_HANDLER( hal21_soundcommand_w ) { hal21_sound_scheduler(machine, 1, data); }
435static WRITE8_HANDLER( hal21_soundack_w ) { hal21_sound_scheduler(machine,2, data); }
436
437static READ8_HANDLER( hal21_soundcommand_r )
438{
439   int data = soundlatch_r(machine, 0);
440   soundlatch_clear_w(machine, 0, 0);
441   return data;
442}
443
444static INTERRUPT_GEN( hal21_sound_interrupt )
445{
446   hal21_sound_scheduler(machine, 3, 0);
447}
448
449/**************************************************************************/
450
451static ADDRESS_MAP_START( hal21_sound_map, ADDRESS_SPACE_PROGRAM, 8 )
452   AM_RANGE(0x0000, 0x3fff) AM_ROM
453   AM_RANGE(0x8000, 0x87ff) AM_RAM
454   AM_RANGE(0xa000, 0xa000) AM_READ(hal21_soundcommand_r)
455   AM_RANGE(0xc000, 0xc000) AM_READ(CPUC_ready_r)
456   AM_RANGE(0xe000, 0xe000) AM_WRITE(ay8910_control_port_0_w)
457   AM_RANGE(0xe001, 0xe001) AM_WRITE(ay8910_write_port_0_w)
458   AM_RANGE(0xe002, 0xe002) AM_WRITE(hal21_soundack_w) // bitfielded(0-5) acknowledge write, details unknown
459   AM_RANGE(0xe008, 0xe008) AM_WRITE(ay8910_control_port_1_w)
460   AM_RANGE(0xe009, 0xe009) AM_WRITE(ay8910_write_port_1_w)
461ADDRESS_MAP_END
462
463static ADDRESS_MAP_START( hal21_sound_portmap, ADDRESS_SPACE_IO, 8 )
464   ADDRESS_MAP_GLOBAL_MASK(0xff)
465   AM_RANGE(0x0000, 0x0000) AM_NOP            // external sound ROM detection?
466ADDRESS_MAP_END
467
468/**************************** HAL21 *************************/
469
470static ADDRESS_MAP_START( hal21_cpuA_map, ADDRESS_SPACE_PROGRAM, 8 )
471   AM_RANGE(0x0000, 0x7fff) AM_ROM
472   AM_RANGE(0xc000, 0xc000) AM_READ_PORT("SYSTEM")
473   AM_RANGE(0xc100, 0xc100) AM_READ_PORT("P1")
474   AM_RANGE(0xc200, 0xc200) AM_READ_PORT("P2")
475   AM_RANGE(0xc300, 0xc300) AM_WRITE(hal21_soundcommand_w)
476   AM_RANGE(0xc400, 0xc400) AM_READ_PORT("DSW1")
477   AM_RANGE(0xc500, 0xc500) AM_READ_PORT("DSW2")
478   AM_RANGE(0xc600, 0xc600) AM_WRITE(hal21_vreg0_w)
479   AM_RANGE(0xc700, 0xc700) AM_READWRITE(snk_cpuB_nmi_trigger_r, snk_cpuA_nmi_ack_w)
480   AM_RANGE(0xd300, 0xd300) AM_WRITE(hal21_vreg1_w)
481   AM_RANGE(0xd400, 0xd400) AM_WRITE(hal21_vreg2_w)
482   AM_RANGE(0xd500, 0xd500) AM_WRITE(hal21_vreg3_w)
483   AM_RANGE(0xd600, 0xd600) AM_WRITE(hal21_vreg4_w)
484   AM_RANGE(0xd700, 0xd700) AM_WRITE(hal21_vreg5_w)
485   AM_RANGE(0xe000, 0xefff) AM_RAM AM_SHARE(2) AM_BASE(&spriteram)
486   AM_RANGE(0xf000, 0xffff) AM_RAM AM_SHARE(1)
487   AM_RANGE(0xf800, 0xffff) AM_RAM AM_BASE(&textram)
488ADDRESS_MAP_END
489
490static ADDRESS_MAP_START( hal21_cpuB_map, ADDRESS_SPACE_PROGRAM, 8 )
491   AM_RANGE(0x0000, 0x9fff) AM_ROM
492   AM_RANGE(0xa000, 0xa000) AM_WRITE(snk_cpuB_nmi_ack_w)
493   AM_RANGE(0xc000, 0xcfff) AM_RAM AM_SHARE(2)
494   AM_RANGE(0xd000, 0xdfff) AM_RAM AM_BASE(&videoram)
495   AM_RANGE(0xe000, 0xefff) AM_RAM AM_SHARE(1)
496ADDRESS_MAP_END
497
498/**************************************************************************/
499
500static DRIVER_INIT( hal21 )
501{
502   hal21_vreg = auto_malloc(24);
503   hal21_sndfifo = hal21_vreg + 8;
504}
505
506static MACHINE_RESET( aso )
507{
508   memset(hal21_vreg, 0, 8);
509   hal21_sound_scheduler(machine, 0, 0);
510   snk_sound_busy_bit = 0;
511}
512
513static MACHINE_DRIVER_START( hal21 )
514
515   /* basic machine hardware */
516   MDRV_CPU_ADD("main", Z80, 4000000)
517   MDRV_CPU_PROGRAM_MAP(hal21_cpuA_map,0)
518   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
519
520   MDRV_CPU_ADD("sub", Z80, 4000000)
521   MDRV_CPU_PROGRAM_MAP(hal21_cpuB_map,0)
522   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
523
524   MDRV_CPU_ADD("audio", Z80, 4000000)
525   MDRV_CPU_PROGRAM_MAP(hal21_sound_map,0)
526   MDRV_CPU_IO_MAP(hal21_sound_portmap,0)
527   MDRV_CPU_VBLANK_INT("main", hal21_sound_interrupt)
528   MDRV_CPU_PERIODIC_INT(irq0_line_hold, 220) // music tempo, hand tuned
529
530   MDRV_INTERLEAVE(100)
531
532   /* video hardware */
533   MDRV_VIDEO_ATTRIBUTES(VIDEO_HAS_HIGHLIGHTS)
534
535   MDRV_SCREEN_ADD("main", RASTER)
536   MDRV_SCREEN_REFRESH_RATE(60)
537   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */)
538   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
539   MDRV_SCREEN_SIZE(36*8, 28*8)
540   MDRV_SCREEN_VISIBLE_AREA(0*8, 36*8-1, 1*8, 28*8-1)
541
542   MDRV_GFXDECODE(aso)
543   MDRV_PALETTE_LENGTH(1024)
544
545   MDRV_MACHINE_RESET(aso)
546
547   MDRV_PALETTE_INIT(aso)
548   MDRV_VIDEO_START(hal21)
549   MDRV_VIDEO_RESET(aso)
550   MDRV_VIDEO_UPDATE(hal21)
551
552   /* sound hardware */
553   MDRV_SPEAKER_STANDARD_MONO("mono")
554
555   MDRV_SOUND_ADD("ay1", AY8910, 1500000)
556   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
557
558   MDRV_SOUND_ADD("ay2", AY8910, 1500000)
559   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
560MACHINE_DRIVER_END
561
562/**************************************************************************/
563
564ROM_START( hal21 )
565   ROM_REGION( 0x10000, "main", 0 )   /* 64k for CPUA code */
566   ROM_LOAD( "hal21p1.bin",    0x0000, 0x2000, CRC(9d193830) SHA1(8e4e9c8bc774d7c7c0b68a5fa5cabdc6b5cfa41b) )
567   ROM_LOAD( "hal21p2.bin",    0x2000, 0x2000, CRC(c1f00350) SHA1(8709455a980931565ccca60162a04c6c3133099b) )
568   ROM_LOAD( "hal21p3.bin",    0x4000, 0x2000, CRC(881d22a6) SHA1(4b2a65dc18620f7f77532f791212fccfe1f0b245) )
569   ROM_LOAD( "hal21p4.bin",    0x6000, 0x2000, CRC(ce692534) SHA1(e1d8e6948578ec9d0b6dc2aff17ad23b8ce46d6a) )
570
571   ROM_REGION( 0x10000, "sub", 0 )   /* 64k for CPUB code */
572   ROM_LOAD( "hal21p5.bin",    0x0000, 0x2000, CRC(3ce0684a) SHA1(5e76770a3252d5565a8f11a79ac3a9a6c31a43e2) )
573   ROM_LOAD( "hal21p6.bin",    0x2000, 0x2000, CRC(878ef798) SHA1(0aae152947c9c6733b77dd1ac14f2f6d6bfabeaa) )
574   ROM_LOAD( "hal21p7.bin",    0x4000, 0x2000, CRC(72ebbe95) SHA1(b1f7dc535e7670647500391d21dfa971d5e342a2) )
575   ROM_LOAD( "hal21p8.bin",    0x6000, 0x2000, CRC(17e22ad3) SHA1(0e10a3c0f2e2ec284f4e0f1055397a8ccd1ff0f7) )
576   ROM_LOAD( "hal21p9.bin",    0x8000, 0x2000, CRC(b146f891) SHA1(0b2db3e14b0401a7914002c6f7c26933a1cba162) )
577
578   ROM_REGION( 0x10000, "audio", 0 )   /* 64k for sound code */
579   ROM_LOAD( "hal21p10.bin",   0x0000, 0x4000, CRC(916f7ba0) SHA1(7b8bcd59d768c4cd226de96895d3b9755bb3ba79) )
580
581   ROM_REGION( 0x2000, "gfx1", ROMREGION_DISPOSE )
582   ROM_LOAD( "hal21p12.bin", 0x0000, 0x2000, CRC(9839a7cd) SHA1(d3f9d964263a64aa3648faf5eb2e4fa532ae7852) ) /* char */
583
584   ROM_REGION( 0x8000, "gfx2", ROMREGION_DISPOSE ) /* background tiles */
585   ROM_LOAD( "hal21p11.bin", 0x0000, 0x4000, CRC(24abc57e) SHA1(1d7557a62adc059fb3fe20a09be18c2f40441581) )
586
587   ROM_REGION( 0x18000, "gfx3", ROMREGION_DISPOSE ) /* 16x16 sprites */
588   ROM_LOAD( "hal21p13.bin", 0x00000, 0x4000, CRC(052b4f4f) SHA1(032eb5771d33defce86e222f3e7aa22bc37db6db) )
589   ROM_RELOAD(               0x04000, 0x4000 )
590   ROM_LOAD( "hal21p14.bin", 0x08000, 0x4000, CRC(da0cb670) SHA1(1083bdd3488dfaa5094a2ef52cfc4206f35c9612) )
591   ROM_RELOAD(               0x0c000, 0x4000 )
592   ROM_LOAD( "hal21p15.bin", 0x10000, 0x4000, CRC(5c5ea945) SHA1(f9ce206cab4fad1f6478d731d4b096ec33e7b99f) )
593   ROM_RELOAD(               0x14000, 0x4000 )
594
595   ROM_REGION( 0x0c00, "proms", 0 )
596   ROM_LOAD( "hal21_3.prm",  0x000, 0x400, CRC(605afff8) SHA1(94e80ebd574b1580dac4a2aebd57e3e767890c0d) )
597   ROM_LOAD( "hal21_2.prm",  0x400, 0x400, CRC(c5d84225) SHA1(cc2cd32f81ed7c1bcdd68e91d00f8081cb706ce7) )
598   ROM_LOAD( "hal21_1.prm",  0x800, 0x400, CRC(195768fc) SHA1(c88bc9552d57d52fb4b030d118f48fedccf563f4) )
599ROM_END
600
601ROM_START( hal21j )
602   ROM_REGION( 0x10000, "main", 0 )   /* 64k for CPUA code */
603   ROM_LOAD( "hal21p1.bin",    0x0000, 0x2000, CRC(9d193830) SHA1(8e4e9c8bc774d7c7c0b68a5fa5cabdc6b5cfa41b) )
604   ROM_LOAD( "hal21p2.bin",    0x2000, 0x2000, CRC(c1f00350) SHA1(8709455a980931565ccca60162a04c6c3133099b) )
605   ROM_LOAD( "hal21p3.bin",    0x4000, 0x2000, CRC(881d22a6) SHA1(4b2a65dc18620f7f77532f791212fccfe1f0b245) )
606   ROM_LOAD( "hal21p4.bin",    0x6000, 0x2000, CRC(ce692534) SHA1(e1d8e6948578ec9d0b6dc2aff17ad23b8ce46d6a) )
607
608   ROM_REGION( 0x10000, "sub", 0 )   /* 64k for CPUB code */
609   ROM_LOAD( "hal21p5.bin",    0x0000, 0x2000, CRC(3ce0684a) SHA1(5e76770a3252d5565a8f11a79ac3a9a6c31a43e2) )
610   ROM_LOAD( "hal21p6.bin",    0x2000, 0x2000, CRC(878ef798) SHA1(0aae152947c9c6733b77dd1ac14f2f6d6bfabeaa) )
611   ROM_LOAD( "hal21p7.bin",    0x4000, 0x2000, CRC(72ebbe95) SHA1(b1f7dc535e7670647500391d21dfa971d5e342a2) )
612   ROM_LOAD( "hal21p8.bin",    0x6000, 0x2000, CRC(17e22ad3) SHA1(0e10a3c0f2e2ec284f4e0f1055397a8ccd1ff0f7) )
613   ROM_LOAD( "hal21p9.bin",    0x8000, 0x2000, CRC(b146f891) SHA1(0b2db3e14b0401a7914002c6f7c26933a1cba162) )
614
615   ROM_REGION( 0x10000, "audio", 0 )   /* 64k for sound code */
616   ROM_LOAD( "hal21-10.bin",   0x0000, 0x4000, CRC(a182b3f0) SHA1(b76eff97a58a96467e9f3a74125a0a770e7678f8) )
617
618   ROM_REGION( 0x2000, "gfx1", ROMREGION_DISPOSE )
619   ROM_LOAD( "hal21p12.bin", 0x0000, 0x2000, CRC(9839a7cd) SHA1(d3f9d964263a64aa3648faf5eb2e4fa532ae7852) ) /* char */
620
621   ROM_REGION( 0x8000, "gfx2", ROMREGION_DISPOSE ) /* background tiles */
622   ROM_LOAD( "hal21p11.bin", 0x0000, 0x4000, CRC(24abc57e) SHA1(1d7557a62adc059fb3fe20a09be18c2f40441581) )
623
624   ROM_REGION( 0x18000, "gfx3", ROMREGION_DISPOSE ) /* 16x16 sprites */
625   ROM_LOAD( "hal21p13.bin", 0x00000, 0x4000, CRC(052b4f4f) SHA1(032eb5771d33defce86e222f3e7aa22bc37db6db) )
626   ROM_RELOAD(               0x04000, 0x4000 )
627   ROM_LOAD( "hal21p14.bin", 0x08000, 0x4000, CRC(da0cb670) SHA1(1083bdd3488dfaa5094a2ef52cfc4206f35c9612) )
628   ROM_RELOAD(               0x0c000, 0x4000 )
629   ROM_LOAD( "hal21p15.bin", 0x10000, 0x4000, CRC(5c5ea945) SHA1(f9ce206cab4fad1f6478d731d4b096ec33e7b99f) )
630   ROM_RELOAD(               0x14000, 0x4000 )
631
632   ROM_REGION( 0x0c00, "proms", 0 )
633   ROM_LOAD( "hal21_3.prm",  0x000, 0x400, CRC(605afff8) SHA1(94e80ebd574b1580dac4a2aebd57e3e767890c0d) )
634   ROM_LOAD( "hal21_2.prm",  0x400, 0x400, CRC(c5d84225) SHA1(cc2cd32f81ed7c1bcdd68e91d00f8081cb706ce7) )
635   ROM_LOAD( "hal21_1.prm",  0x800, 0x400, CRC(195768fc) SHA1(c88bc9552d57d52fb4b030d118f48fedccf563f4) )
636ROM_END
637
638
639
640
641GAME( 1985, hal21,    0,     hal21, hal21, hal21, ROT270, "SNK", "HAL21", GAME_IMPERFECT_COLORS | GAME_NO_COCKTAIL )
642GAME( 1985, hal21j,   hal21, hal21, hal21, hal21, ROT270, "SNK", "HAL21 (Japan)", GAME_IMPERFECT_COLORS | GAME_NO_COCKTAIL )
src/tools/makemeta.c
r3178r3179
1/***************************************************************************
2
3    makemeta.c
4
5    Laserdisc metadata generator.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10****************************************************************************
11
12    Metadata format (12 bytes/field):
13
14      Offset   Description
15      ------   ------------------------------------------
16         0   = version (currently 2)
17         1   = internal flags:
18                bit 0 = previous field is the same frame
19                bit 1 = next field is the same frame
20         2   = white flag (from line 11)
21        3-5  = line 16 Philips code
22        6-8  = line 17 Philips code
23        9-11 = line 18 Philips code
24
25***************************************************************************/
26
27#include <stdio.h>
28#include <ctype.h>
29#include "aviio.h"
30#include "bitmap.h"
31#include "vbiparse.h"
32
33
34
35/***************************************************************************
36    CONSTANTS
37***************************************************************************/
38
39#define INSERT_FRAME_CODE      0xff000000
40#define INSERT_FRAME_CODE_INC   0xff000001
41#define INVALID_CODE         0xffffffff
42
43
44
45/***************************************************************************
46    TYPE DEFINITIONS
47***************************************************************************/
48
49typedef struct _pattern_data pattern_data;
50struct _pattern_data
51{
52   pattern_data *next;
53   UINT32 line16, line17, line18;
54   int white;
55};
56
57
58
59/***************************************************************************
60    IMPLEMENTATION
61***************************************************************************/
62
63/*-------------------------------------------------
64    output_meta - output a line of metadata
65-------------------------------------------------*/
66
67static void output_meta(UINT8 flags, UINT8 white, UINT32 line16, UINT32 line17, UINT32 line18, UINT32 framenum, UINT32 chapternum)
68{
69   /* start with the raw metadata, followed by a comment */
70   printf("02%02X%02X%06X%06X%06X   ; ",
71      flags, white, line16, line17, line18);
72
73   /* separate comments for leadin/leadout */
74   if (line17 == 0x88ffff)
75      printf("leadin\n");
76   else if (line17 == 0x80eeee)
77      printf("leadout\n");
78
79   /* otherwise, display the frame and chapter, and indicate white flag/stop code */
80   else
81   {
82      printf("frame %05x ch %02x", framenum, chapternum);
83      if (white)
84         printf(" (white)");
85      if (line16 == 0x82cfff)
86         printf(" (stop)");
87      printf("\n");
88   }
89}
90
91
92/*-------------------------------------------------
93    generate_from_avi - generate the data from
94    an AVI file
95-------------------------------------------------*/
96
97static int generate_from_avi(const char *aviname)
98{
99   UINT32 line16 = 0, line17 = 0, line18 = 0, framenum = 0, chapternum = 0;
100   const avi_movie_info *info;
101   bitmap_t *bitmap;
102   avi_error avierr;
103   avi_file *avi;
104   int white = 0;
105   int frame;
106
107   /* open the file */
108   avierr = avi_open(aviname, &avi);
109   if (avierr != AVIERR_NONE)
110   {
111      fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr));
112      return 1;
113   }
114
115   /* extract movie info */
116   info = avi_get_movie_info(avi);
117   fprintf(stderr, "%dx%d - %d frames total\n", info->video_width, info->video_height, info->video_numsamples);
118   if (info->video_height < 22*2)
119   {
120      fprintf(stderr, "Unknown VBI capture format: expected at least 44 rows\n");
121      return 1;
122   }
123
124   /* allocate a bitmap to hold it */
125   bitmap = bitmap_alloc(info->video_width, info->video_height, BITMAP_FORMAT_YUY16);
126   if (bitmap == NULL)
127   {
128      fprintf(stderr, "Out of memory allocating %dx%d bitmap\n", info->video_width, info->video_height);
129      return 1;
130   }
131
132   /* loop over frames */
133   for (frame = 0; frame < info->video_numsamples; frame++)
134   {
135      int field;
136      UINT8 bits[24];
137
138      /* read the frame */
139      avierr = avi_read_video_frame_yuy16(avi, frame, bitmap);
140      if (avierr != AVIERR_NONE)
141      {
142         fprintf(stderr, "Error reading AVI frame %d: %s\n", frame, avi_error_string(avierr));
143         break;
144      }
145
146      /* loop over two fields */
147      for (field = 0; field < 2; field++)
148      {
149         int prevwhite = white;
150         int i;
151
152         /* line 11 contains the white flag */
153         white = vbi_parse_white_flag(BITMAP_ADDR16(bitmap, 11*2 + field, 0), bitmap->width, 8);
154
155         /* output metadata for *previous* field */
156         if (frame > 0 || field > 0)
157         {
158            int flags = 0;
159
160            if (!prevwhite) flags |= 0x01;
161            if (!white) flags |= 0x02;
162            output_meta(flags, prevwhite, line16, line17, line18, framenum, chapternum);
163         }
164
165         /* line 16 contains stop code and other interesting bits */
166         line16 = 0;
167         if (vbi_parse_manchester_code(BITMAP_ADDR16(bitmap, 16*2 + field, 0), bitmap->width, 8, 24, bits) == 24)
168            for (i = 0; i < 24; i++)
169               line16 = (line16 << 1) | bits[i];
170
171         /* line 17 and 18 contain frame/chapter/lead in/out encodings */
172         line17 = 0;
173         if (vbi_parse_manchester_code(BITMAP_ADDR16(bitmap, 17*2 + field, 0), bitmap->width, 8, 24, bits) == 24)
174            for (i = 0; i < 24; i++)
175               line17 = (line17 << 1) | bits[i];
176
177         line18 = 0;
178         if (vbi_parse_manchester_code(BITMAP_ADDR16(bitmap, 18*2 + field, 0), bitmap->width, 8, 24, bits) == 24)
179            for (i = 0; i < 24; i++)
180               line18 = (line18 << 1) | bits[i];
181
182         /* the two lines must match */
183//          if (line17 != 0 && line18 != 0 && line17 != line18)
184//              line17 = line18 = 0;
185
186         /* is this a frame number? */
187         if ((line17 & 0xf00000) == 0xf00000)
188            framenum = line17 & 0x7ffff;
189         if ((line17 & 0xf00fff) == 0x800ddd)
190            chapternum = (line17 >> 12) & 0x7f;
191      }
192   }
193
194   /* output metadata for *previous* field */
195   {
196      int flags = 0;
197
198      if (!white) flags |= 0x01;
199      output_meta(flags, white, line16, line17, line18, framenum, chapternum);
200   }
201
202   bitmap_free(bitmap);
203   return 0;
204}
205
206
207/*-------------------------------------------------
208    parse_philips_code - parse a single Philips
209    code from a string, stopping at the given
210    end characters
211-------------------------------------------------*/
212
213static UINT32 parse_philips_code(char **argptr, const char *endchars)
214{
215   char *arg = *argptr;
216   UINT32 value = 0;
217
218   /* look for special chars first */
219   if (*arg == '+')
220   {
221      *argptr = arg + 1;
222      return INSERT_FRAME_CODE_INC;
223   }
224   else if (*arg == '@')
225   {
226      *argptr = arg + 1;
227      return INSERT_FRAME_CODE;
228   }
229
230   /* parse the rest as hex digits */
231   for ( ; *arg != 0 && strchr(endchars, *arg) == NULL; arg++)
232   {
233      if (*arg >= '0' && *arg <= '9')
234         value = (value << 4) + (*arg - '0');
235      else if (*arg >= 'a' && *arg <= 'f')
236         value = (value << 4) + 10 + (*arg - 'a');
237      else if (*arg >= 'A' && *arg <= 'F')
238         value = (value << 4) + 10 + (*arg - 'A');
239      else
240         return INVALID_CODE;
241   }
242
243   /* if we're too big, we're invalid */
244   if (value > 0xffffff)
245      return INVALID_CODE;
246
247   *argptr = arg;
248   return value;
249}
250
251
252/*-------------------------------------------------
253    parse_pattern - parse a pattern into a series
254    of pattern_data structs
255-------------------------------------------------*/
256
257static pattern_data *parse_pattern(char *arg, int *countptr)
258{
259   pattern_data *head = NULL;
260   pattern_data **tailptr = &head;
261   int count = 0;
262
263   /* first parse the count */
264   for ( ; *arg != 0 && *arg != '*'; arg++)
265   {
266      if (!isdigit(*arg))
267         return NULL;
268      count = count * 10 + (*arg - '0');
269   }
270   if (*arg == 0)
271      return NULL;
272   arg++;
273   *countptr = count;
274
275   /* loop until we hit the end */
276   while (*arg != 0)
277   {
278      pattern_data *pat;
279
280      /* allocate a new structure */
281      pat = malloc(sizeof(*pat));
282      if (pat == NULL)
283         return NULL;
284      memset(pat, 0, sizeof(*pat));
285
286      /* bang at the beginning means white flag */
287      if (*arg == '!')
288      {
289         arg++;
290         pat->white = 1;
291      }
292
293      /* parse line16 until we hit a period or comma */
294      pat->line16 = parse_philips_code(&arg, ".,");
295      if (pat->line16 == INVALID_CODE)
296         return NULL;
297      if (*arg != '.' && *arg != ',' && *arg != 0)
298         return NULL;
299      if (*arg == '.')
300         arg++;
301
302      /* parse line17 until we hit a period */
303      pat->line17 = parse_philips_code(&arg, ".,");
304      if (pat->line17 == INVALID_CODE)
305         return NULL;
306      if (*arg != '.' && *arg != ',' && *arg != 0)
307         return NULL;
308      if (*arg == '.')
309         arg++;
310
311      /* parse line18 until we hit a comma */
312      pat->line18 = parse_philips_code(&arg, ",");
313      if (pat->line18 == INVALID_CODE)
314         return NULL;
315      if (*arg != ',' && *arg != 0)
316         return NULL;
317      if (*arg == ',')
318         arg++;
319
320      /* append to the end */
321      *tailptr = pat;
322      tailptr = &pat->next;
323   }
324
325   return head;
326}
327
328
329/*-------------------------------------------------
330    generate_from_pattern - generate metadata
331    from a pattern
332-------------------------------------------------*/
333
334static int generate_from_pattern(pattern_data *pattern, int patcount)
335{
336   pattern_data *curpat = pattern;
337   int framenum = 0, bcdframenum = 0;
338
339   /* loop until we exceed the pattern frame count */
340   while (1)
341   {
342      UINT32 line16, line17, line18;
343      int flags = 0;
344
345      /* handle special codes for line 16 */
346      line16 = curpat->line16;
347      if (line16 == INSERT_FRAME_CODE_INC)
348      {
349         framenum++;
350         bcdframenum = (((framenum / 10000) % 10) << 16) | (((framenum / 1000) % 10) << 12) | (((framenum / 100) % 10) << 8) | (((framenum / 10) % 10) << 4) | (framenum % 10);
351      }
352      if (line16 == INSERT_FRAME_CODE || line16 == INSERT_FRAME_CODE_INC)
353         line16 = 0xf80000 | bcdframenum;
354
355      /* handle special codes for line 17 */
356      line17 = curpat->line17;
357      if (line17 == INSERT_FRAME_CODE_INC)
358      {
359         framenum++;
360         bcdframenum = (((framenum / 10000) % 10) << 16) | (((framenum / 1000) % 10) << 12) | (((framenum / 100) % 10) << 8) | (((framenum / 10) % 10) << 4) | (framenum % 10);
361      }
362      if (line17 == INSERT_FRAME_CODE || line17 == INSERT_FRAME_CODE_INC)
363         line17 = 0xf80000 | bcdframenum;
364
365      /* handle special codes for line 18 */
366      line18 = curpat->line18;
367      if (line18 == INSERT_FRAME_CODE_INC)
368      {
369         framenum++;
370         bcdframenum = (((framenum / 10000) % 10) << 16) | (((framenum / 1000) % 10) << 12) | (((framenum / 100) % 10) << 8) | (((framenum / 10) % 10) << 4) | (framenum % 10);
371      }
372      if (line18 == INSERT_FRAME_CODE || line18 == INSERT_FRAME_CODE_INC)
373         line18 = 0xf80000 | bcdframenum;
374
375      /* bail if we passed the end */
376      if (framenum > patcount)
377         break;
378
379      /* if we don't have a white flag, the previous frame must match us */
380      if (!curpat->white) flags |= 0x01;
381
382      /* advance to the next pattern piece */
383      curpat = curpat->next;
384      if (curpat == NULL)
385         curpat = pattern;
386
387      /* if the new field doesn't have a white flag, it must match our current frame */
388      if (!curpat->white) flags |= 0x02;
389
390      /* output the result */
391      output_meta(flags, curpat->white, line16, line17, line18, bcdframenum, 0);
392   }
393   return 0;
394}
395
396
397/*-------------------------------------------------
398    usage - display program usage
399-------------------------------------------------*/
400
401static int usage(void)
402{
403   fprintf(stderr, "Usage: \n");
404   fprintf(stderr, "  makemeta [avifile.avi] [<option> [<option> [...]]]\n");
405   fprintf(stderr, "\n");
406   fprintf(stderr, "Options:\n");
407   fprintf(stderr, "  -leadin <count> -- prepend <count> fields of leadin codes\n");
408   fprintf(stderr, "  -leadout <count> -- append <count> fields of leadout codes\n");
409   fprintf(stderr, "  -pattern <frames>*<pat0>[,<pat1>[,...]] -- repeat Philips code pattern\n");
410   fprintf(stderr, "      in place of AVI. <pat0>, <pat1>, etc. are of the form: \n");
411   fprintf(stderr, "      [!]A[.B[.C]][,<pattern>] where A,B,C are either hexadecimal\n");
412   fprintf(stderr, "      values one of these special codes:\n");
413   fprintf(stderr, "          ! -- at the start of a pattern sets the white flag\n");
414   fprintf(stderr, "          + -- increments frame number and inserts frame code\n");
415   fprintf(stderr, "          @ -- inserts repeat of most recent frame code\n");
416   fprintf(stderr, "      non-present values are assumed to be 0\n");
417   fprintf(stderr, "\n");
418   fprintf(stderr, "Examples:\n");
419   fprintf(stderr, "  makemeta -pattern 54000*!8da01e.+.@,8da01e,!8da01e.+.@,8da01e,8da01e\n");
420   fprintf(stderr, "    generates the following pattern of Philips codes:\n");
421   fprintf(stderr, "        8da01e f80001 f80001 (white)\n");
422   fprintf(stderr, "        8da01e 000000 000000\n");
423   fprintf(stderr, "        8da01e f80002 f80002 (white)\n");
424   fprintf(stderr, "        8da01e 000000 000000\n");
425   fprintf(stderr, "        8da01e 000000 000000\n");
426   fprintf(stderr, "        <repeat until frame is 54000>\n");
427   return 1;
428}
429
430
431/*-------------------------------------------------
432    main - main entry point
433-------------------------------------------------*/
434
435int main(int argc, char *argv[])
436{
437   int leadin = 0, leadout = 0;
438   const char *avifile = NULL;
439   pattern_data *pattern = NULL;
440   int patcount = 0;
441   int arg;
442   int i;
443
444   /* iterate over arguments */
445   for (arg = 1; arg < argc; arg++)
446   {
447      /* assume anything without a - is a filename */
448      if (argv[arg][0] != '-')
449      {
450         if (avifile != NULL || pattern != NULL)
451            return usage();
452         avifile = argv[arg];
453      }
454
455      /* look for options */
456      else if (strcmp(argv[arg], "-leadin") == 0)
457      {
458         if (++arg >= argc)
459            return usage();
460         leadin = atoi(argv[arg]);
461      }
462      else if (strcmp(argv[arg], "-leadout") == 0)
463      {
464         if (++arg >= argc)
465            return usage();
466         leadout = atoi(argv[arg]);
467      }
468      else if (strcmp(argv[arg], "-pattern") == 0)
469      {
470         if (avifile != NULL || pattern != NULL)
471            return usage();
472         if (++arg >= argc)
473            return usage();
474         pattern = parse_pattern(argv[arg], &patcount);
475         if (pattern == NULL)
476            return usage();
477      }
478   }
479
480   /* must have an AVI file or a pattern */
481   if (avifile == NULL && pattern == NULL)
482      return usage();
483
484   /* output header and leadin */
485   printf("chdmeta 12\n");
486   for (i = 0; i < leadin; i++)
487   {
488      int flags = (i == 0) ? 0x02 : (i == leadin - 1) ? 0x01 : 0x03;
489      printf("02%02X%02X00000088FFFF88FFFF\n", flags, (i % 2));
490   }
491
492   /* if we got a file, output it */
493   if (avifile != NULL)
494      generate_from_avi(avifile);
495   else if (pattern != NULL)
496      generate_from_pattern(pattern, patcount);
497
498   /* output leadout */
499   for (i = 0; i < leadout; i++)
500   {
501      int flags = (i == 0) ? 0x02 : (i == leadout - 1) ? 0x01 : 0x03;
502      printf("02%02X%02X00000080EEEE80EEEE\n", flags, (i % 2));
503   }
504
505   return 0;
506}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team