Previous 15994 Revisions Next

r1047 Friday 28th September, 2007 at 18:17:21 UTC by Firewave
removed obsolete files
[src/emu]palette.c palette.h
[src/emu/cpu/z80]z80dasm.h
[src/mame/audio]ultratnk.c
[src/mame/drivers]leprechn.c segasyse.c vp906iii.c
[src/mame/includes]bfm_sc2.h clayshoo.h leprechn.h micro3d.h sprint4.h
[src/mame/machine]astrocde.c berzerk.c clayshoo.c lamps.c lamps.h leprechn.c mpu4.c neogeo.c spiders.c vacfdisp.c vacfdisp.h
[src/mame/video]astrof.c berzerk.c dorachan.c leprechn.c micro3d.c nyny.c ppu2c03b.c ppu2c03b.h res_net.c res_net.h snowbros.c spiders.c
[src/osd/windows]d3d_extra.h
[src/tools]file2str.c png2bdc.c

src/mame/audio/ultratnk.c
r1046r1047
1/*************************************************************************
2
3    audio\ultratnk.c
4
5*************************************************************************/
6#include "driver.h"
7#include "ultratnk.h"
8#include "sound/discrete.h"
9
10
11/************************************************************************/
12/* ultratnk Sound System Analog emulation                               */
13/************************************************************************/
14
15const discrete_lfsr_desc ultratnk_lfsr={
16   DISC_CLK_IS_FREQ,
17   16,         /* Bit Length */
18   0,         /* Reset Value */
19   0,         /* Use Bit 0 as XOR input 0 */
20   14,         /* Use Bit 14 as XOR input 1 */
21   DISC_LFSR_XNOR,      /* Feedback stage1 is XNOR */
22   DISC_LFSR_OR,      /* Feedback stage2 is just stage 1 output OR with external feed */
23   DISC_LFSR_REPLACE,   /* Feedback stage3 replaces the shifted register contents */
24   0x000001,      /* Everything is shifted into the first bit only */
25   0,         /* Output is not inverted */
26   15         /* Output bit */
27};
28
29/* Nodes - Sounds */
30#define ULTRATNK_MOTORSND1      NODE_10
31#define ULTRATNK_MOTORSND2      NODE_11
32#define ULTRATNK_EXPLOSIONSND   NODE_12
33#define ULTRATNK_FIRESND1      NODE_13
34#define ULTRATNK_FIRESND2      NODE_14
35#define ULTRATNK_NOISE         NODE_15
36#define ULTRATNK_FINAL_MIX      NODE_16
37
38DISCRETE_SOUND_START(ultratnk_discrete_interface)
39   /************************************************/
40   /* Ultratnk sound system: 5 Sound Sources       */
41   /*                     Relative Volume          */
42   /*    1/2) Motor           77.72%               */
43   /*      2) Explosion      100.00%               */
44   /*    4/5) Fire            29.89%               */
45   /* Relative volumes calculated from resitor     */
46   /* network in combiner circuit                  */
47   /*                                              */
48   /************************************************/
49
50   /************************************************/
51   /* Input register mapping for ultratnk           */
52   /************************************************/
53   /*                   NODE                      GAIN    OFFSET  INIT */
54   DISCRETE_INPUT_LOGIC(ULTRATNK_FIRE1_EN)
55   DISCRETE_INPUT_LOGIC(ULTRATNK_FIRE2_EN)
56   DISCRETE_INPUTX_DATA(ULTRATNK_MOTOR1_DATA, -1, 0x0f, 0)
57   DISCRETE_INPUTX_DATA(ULTRATNK_MOTOR2_DATA, -1, 0x0f, 0)
58   DISCRETE_INPUTX_DATA(ULTRATNK_EXPLOSION_DATA, 1000.0/15.0, 0,  0.0)
59   DISCRETE_INPUT_LOGIC(ULTRATNK_ATTRACT_EN)
60
61   /************************************************/
62   /* Motor sound circuit is based on a 556 VCO    */
63   /* with the input frequency set by the MotorSND */
64   /* latch (4 bit). This freqency is then used to */
65   /* driver a modulo 12 counter, with div6, 4 & 3 */
66   /* summed as the output of the circuit.         */
67   /* VCO Output is Sq wave = 27-382Hz             */
68   /*  F1 freq - (Div6)                            */
69   /*  F2 freq = (Div4)                            */
70   /*  F3 freq = (Div3) 33.3% duty, 33.3 deg phase */
71   /* To generate the frequency we take the freq.  */
72   /* diff. and /15 to get all the steps between   */
73   /* 0 - 15.  Then add the low frequency and send */
74   /* that value to a squarewave generator.        */
75   /* Also as the frequency changes, it ramps due  */
76   /* to a 2.2uf capacitor on the R-ladder.        */
77   /* Note the VCO freq. is controlled by a 250k   */
78   /* pot.  The freq. used here is for the pot set */
79   /* to 125k.  The low freq is allways the same.  */
80   /* This adjusts the high end.                   */
81   /* 0k = 214Hz.   250k = 4416Hz                  */
82   /************************************************/
83   DISCRETE_RCFILTER(NODE_20, 1, ULTRATNK_MOTOR1_DATA, 123000, 2.2e-6)
84   DISCRETE_ADJUSTMENT_TAG(NODE_21, 1, (214.0-27.0)/12/15, (4416.0-27.0)/12/15, DISC_LOGADJ, "MOTOR1")
85   DISCRETE_MULTIPLY(NODE_22, 1, NODE_20, NODE_21)
86
87   DISCRETE_MULTADD(NODE_23, 1, NODE_22, 2, 27.0/6)   /* F1 = /12*2 = /6 */
88   DISCRETE_SQUAREWAVE(NODE_24, 1, NODE_23, (777.2/3), 50.0, 0, 0)
89   DISCRETE_RCFILTER(NODE_25, 1, NODE_24, 10000, 1e-7)
90
91   DISCRETE_MULTADD(NODE_26, 1, NODE_22, 3, 27.0/4)   /* F2 = /12*3 = /4 */
92   DISCRETE_SQUAREWAVE(NODE_27, 1, NODE_26, (777.2/3), 50.0, 0, 0)
93   DISCRETE_RCFILTER(NODE_28, 1, NODE_27, 10000, 1e-7)
94
95   DISCRETE_MULTADD(NODE_29, 1, NODE_22, 4, 27.0/3)   /* F3 = /12*4 = /3 */
96   DISCRETE_SQUAREWAVE(NODE_30, 1, NODE_29, (777.2/3), 100.0/3, 0, 360.0/3)
97   DISCRETE_RCFILTER(NODE_31, 1, NODE_30, 10000, 1e-7)
98
99   DISCRETE_ADDER3(ULTRATNK_MOTORSND1, ULTRATNK_ATTRACT_EN, NODE_25, NODE_28, NODE_31)
100
101   /************************************************/
102   /* Tank2 motor sound is basically the same as   */
103   /* Tank1.  But I shifted the frequencies up for */
104   /* it to sound different from Tank1.            */
105   /************************************************/
106   DISCRETE_RCFILTER(NODE_40, 1, ULTRATNK_MOTOR2_DATA, 123000, 2.2e-6)
107   DISCRETE_ADJUSTMENT_TAG(NODE_41, 1, (214.0-27.0)/12/15, (4416.0-27.0)/12/15, DISC_LOGADJ, "MOTOR2")
108   DISCRETE_MULTIPLY(NODE_42, 1, NODE_40, NODE_41)
109
110   DISCRETE_MULTADD(NODE_43, 1, NODE_42, 2, 27.0/6)   /* F1 = /12*2 = /6 */
111   DISCRETE_SQUAREWAVE(NODE_44, 1, NODE_43, (777.2/3), 50.0, 0, 0)
112   DISCRETE_RCFILTER(NODE_45, 1, NODE_44, 10000, 1e-7)
113
114   DISCRETE_MULTADD(NODE_46, 1, NODE_42, 3, 27.0/4)   /* F2 = /12*3 = /4 */
115   DISCRETE_SQUAREWAVE(NODE_47, 1, NODE_46, (777.2/3), 50.0, 0, 0)
116   DISCRETE_RCFILTER(NODE_48, 1, NODE_47, 10000, 1e-7)
117
118   DISCRETE_MULTADD(NODE_49, 1, NODE_42, 4, 27.0/3)   /* F3 = /12*4 = /3 */
119   DISCRETE_SQUAREWAVE(NODE_50, 1, NODE_49, (777.2/3), 100.0/3, 0, 360.0/3)
120   DISCRETE_RCFILTER(NODE_51, 1, NODE_50, 10000, 1e-7)
121
122   DISCRETE_ADDER3(ULTRATNK_MOTORSND2, ULTRATNK_ATTRACT_EN, NODE_45, NODE_48, NODE_51)
123
124   /************************************************/
125   /* Explosion circuit is built around a noise    */
126   /* generator built from 2 shift registers that  */
127   /* are clocked by the 2V signal.                */
128   /* 2V = HSYNC/4                                 */
129   /*    = 15750/4                                 */
130   /* Output is binary weighted with 4 bits of     */
131   /* crash volume.                                */
132   /************************************************/
133   DISCRETE_LFSR_NOISE(ULTRATNK_NOISE, ULTRATNK_ATTRACT_EN, ULTRATNK_ATTRACT_EN, 15750.0/4, 1.0, 0, 0, &ultratnk_lfsr)
134
135   DISCRETE_MULTIPLY(NODE_60, 1, ULTRATNK_NOISE, ULTRATNK_EXPLOSION_DATA)
136   DISCRETE_RCFILTER(ULTRATNK_EXPLOSIONSND, 1, NODE_60, 545, 1e-7)
137
138   /************************************************/
139   /* Fire circuits takes the noise output from    */
140   /* the crash circuit and applies +ve feedback   */
141   /* to cause oscillation. There is also an RC    */
142   /* filter on the input to the feedback circuit. */
143   /* RC is 1K & 10uF                              */
144   /* Feedback cct is modelled by using the RC out */
145   /* as the frequency input on a VCO,             */
146   /* breadboarded freq range as:                  */
147   /*  0 = 940Hz, 34% duty                         */
148   /*  1 = 630Hz, 29% duty                         */
149   /*  the duty variance is so small we ignore it  */
150   /************************************************/
151   DISCRETE_INVERT(NODE_70, ULTRATNK_NOISE)
152   DISCRETE_MULTADD(NODE_71, 1, NODE_70, 940.0-630.0, ((940.0-630.0)/2)+630.0)
153   DISCRETE_RCFILTER(NODE_72, 1, NODE_71, 1000, 1e-5)
154   DISCRETE_SQUAREWAVE(NODE_73, 1, NODE_72, 407.8, 31.5, 0, 0.0)
155   DISCRETE_ONOFF(ULTRATNK_FIRESND1, ULTRATNK_FIRE1_EN, NODE_73)
156   DISCRETE_ONOFF(ULTRATNK_FIRESND2, ULTRATNK_FIRE2_EN, NODE_73)
157
158   /************************************************/
159   /* Combine all 5 sound sources.                 */
160   /* Add some final gain to get to a good sound   */
161   /* level.                                       */
162   /************************************************/
163   DISCRETE_ADDER3(NODE_90, 1, ULTRATNK_MOTORSND1, ULTRATNK_EXPLOSIONSND, ULTRATNK_FIRESND1)
164   DISCRETE_ADDER3(NODE_91, 1, NODE_90, ULTRATNK_MOTORSND2, ULTRATNK_FIRESND2)
165
166   DISCRETE_OUTPUT(NODE_91, 65534.0/(777.2+777.2+1000.0+298.9+298.9))
167DISCRETE_SOUND_END
src/mame/machine/astrocde.c
r1046r1047
1/**************************************************************************
2
3    Interrupt System Hardware for Bally/Midway games
4
5    Mike@Dissfulfils.co.uk
6
7**************************************************************************/
8
9#include "driver.h"
10#include "includes/astrocde.h"
11
12static UINT8 *gorf_timer_ram;
13
14READ8_HANDLER( gorf_timer_r )
15{
16   static int Skip=0;
17   int stage = program_read_byte(0x5a93);
18
19   if ((stage==160) || (stage==4))             /* INVADERS AND    */
20   {                                    /* GALAXIAN SCREEN */
21      if (activecpu_get_pc()==0x3086)
22      {
23          if(--Skip==-1)
24         {
25            Skip=2;
26         }
27      }
28
29         return Skip;
30   }
31   else
32   {
33      return gorf_timer_ram[0];
34   }
35
36}
37
38
39/****************************************************************************
40 * Seawolf Controllers
41 ****************************************************************************/
42
43/*
44 * Seawolf2 uses rotary controllers on input ports 10 + 11
45 * each controller responds 0-63 for reading, with bit 7 as
46 * fire button.
47 *
48 * The controllers look like they returns Grays binary,
49 * so I use a table to translate my simple counter into it!
50 */
51
52static const UINT8 ControllerTable[64] = {
53   0  , 1  , 3  , 2  , 6  , 7  , 5  , 4  ,
54   12 , 13 , 15 , 14 , 10 , 11 , 9  , 8  ,
55   24 , 25 , 27 , 26 , 30 , 31 , 29 , 28 ,
56   20 , 21 , 23 , 22 , 18 , 19 , 17 , 16 ,
57   48 , 49 , 51 , 50 , 54 , 55 , 53 , 52 ,
58   60 , 61 , 63 , 62 , 58 , 59 , 57 , 56 ,
59   40 , 41 , 43 , 42 , 46 , 47 , 45 , 44 ,
60   36 , 37 , 39 , 38 , 34 , 35 , 33 , 32
61};
62
63READ8_HANDLER( seawolf2_controller1_r )
64{
65   return (input_port_0_r(0) & 0xc0) + ControllerTable[input_port_0_r(0) & 0x3f];
66}
67
68READ8_HANDLER( seawolf2_controller2_r )
69{
70   return (input_port_1_r(0) & 0xc0) + ControllerTable[input_port_1_r(0) & 0x3f];
71}
72
73
74static UINT8 ebases_trackball_select = 0;
75
76WRITE8_HANDLER( ebases_trackball_select_w )
77{
78   ebases_trackball_select = data;
79}
80
81READ8_HANDLER( ebases_trackball_r )
82{
83   int ret = readinputport(3 + ebases_trackball_select);
84#ifdef VERBOSE
85   logerror("Port %d = %d\n", ebases_trackball_select, ret);
86#endif
87   return ret;
88}
89
90static UINT8 ram_write_enable = 0;
91UINT8 *wow_protected_ram;
92
93WRITE8_HANDLER( wow_ramwrite_enable_w )
94{
95   ram_write_enable = 1;
96}
97
98READ8_HANDLER( wow_protected_ram_r )
99{
100   ram_write_enable = 0;
101   return wow_protected_ram[offset];
102}
103
104/* protection is disabled by strapping of X33 */
105WRITE8_HANDLER( wow_protected_ram_w )
106{
107#if 0
108   if (offset < 0x400)
109   {
110      if (ram_write_enable)
111#endif
112         wow_protected_ram[offset] = data;
113#if 0
114   }
115   else
116   {
117      wow_protected_ram[offset] = data;
118   }
119#endif
120   ram_write_enable = 0;
121}
122
123READ8_HANDLER( robby_nvram_r )
124{
125   ram_write_enable = 0;
126   return generic_nvram[offset];
127}
128
129WRITE8_HANDLER( robby_nvram_w )
130{
131   if (offset >= 0x400 || ram_write_enable)
132      generic_nvram[offset] = data;
133
134   ram_write_enable = 0;
135}
136
137/* Simple for demndrgn */
138READ8_HANDLER( demndrgn_nvram_r )
139{
140   return generic_nvram[offset];
141}
142
143WRITE8_HANDLER( demndrgn_nvram_w )
144{
145   /* I can't seem to find the enable for now */
146   if (offset >= 0x200 || 1/*ram_write_enable*/)
147      generic_nvram[offset] = data;
148
149   ram_write_enable = 0;
150}
151
152READ8_HANDLER( profpac_nvram_r )
153{
154   ram_write_enable = 0;
155   return generic_nvram[offset];
156}
157
158WRITE8_HANDLER( profpac_nvram_w )
159{
160   if (offset >= 0x200 || ram_write_enable)
161      generic_nvram[offset] = data;
162
163   ram_write_enable = 0;
164}
165
166
167READ8_HANDLER( profpac_blank_r )
168{
169   return 0xff;
170}
171
172WRITE8_HANDLER( profpac_banksw_w )
173{
174   /* Note: There is a jumper which could map them from 0xa8-0xb6 instead */
175   if (data >= 0x80) /* 0x80-0xa7 maps x1-x40 */
176   {
177      if (data < 0x8e)
178      {
179         /* 640K eprom board bank handling */
180         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x7fff, 0, 0, MRA8_BANK1);
181         memory_set_bank(1, data-0x80);
182      }
183      else
184      {
185         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x7fff, 0, 0, profpac_blank_r);
186      }
187      memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x8000, 0xbfff, 0, 0, MRA8_BANK2);
188      memory_set_bank(2, 0);
189   }
190   else
191   {
192      data &= 0xe0;
193      if (data == 0x00)
194      {
195         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x7fff, 0, 0, astrocde_videoram_r);
196         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x8000, 0xbfff, 0, 0, MRA8_BANK2);
197         memory_set_bank(2, 0);
198      }
199      else if (data == 0x20)
200      {
201         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x7fff, 0, 0, MRA8_BANK1);
202         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x8000, 0xbfff, 0, 0, MRA8_BANK2);
203         memory_set_bank(1, 14);
204         memory_set_bank(2, 1);
205      }
206      else if (data == 0x40)
207      {
208         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x7fff, 0, 0, MRA8_BANK1);
209         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x8000, 0xbfff, 0, 0, MRA8_BANK2);
210         memory_set_bank(1, 15);
211         memory_set_bank(2, 2);
212      }
213      else if (data == 0x60)
214      {
215         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x7fff, 0, 0, MRA8_BANK1);
216         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x8000, 0xbfff, 0, 0, MRA8_BANK2);
217         memory_set_bank(1, 16);
218         memory_set_bank(2, 3);
219      }
220      else
221      {
222         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x7fff, 0, 0, profpac_blank_r);
223         memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0x8000, 0xbfff, 0, 0, profpac_blank_r);
224      }
225   }
226}
227
228READ8_HANDLER( spacezap_io_r )
229{
230   UINT8 cc1 = (offset>>8)&1;
231   UINT8 cc2 = (offset>>9)&1;
232
233   coin_counter_w(0,cc1);
234   coin_counter_w(1,cc2);
235   return input_port_3_r(offset & 0xff);
236}
237
238WRITE8_HANDLER( ebases_io_w )
239{
240   coin_counter_w(0,data&1);
241}
242
243static UINT8 demndrgn_ad_select = 0;
244
245READ8_HANDLER( demndrgn_io_r )
246{
247   if(offset & 0x0100) coin_counter_w(0,1); else coin_counter_w(0,0);
248   if(offset & 0x0200) coin_counter_w(1,1); else coin_counter_w(1,0);
249   if(offset & 0x0400) set_led_status(0,1); else set_led_status(0,0);
250   if(offset & 0x0800) set_led_status(1,1); else set_led_status(1,0);
251   demndrgn_ad_select = offset >> 12;
252
253   if(demndrgn_ad_select > 1)
254   {
255      logerror("demndrgn_ad_select = %d\n",demndrgn_ad_select);
256   }
257   return 0;
258}
259
260READ8_HANDLER( demndrgn_move_r )
261{
262   if (demndrgn_ad_select == 0)
263      return input_port_2_r(0) ^ 0x80;
264   else if (demndrgn_ad_select == 1)
265      return input_port_3_r(0) ^ 0x80;
266   return 0;
267}
268
269/* We use a digital joystick to fake the analog input   */
270/* This is ok, because the original controler did this  */
271
272READ8_HANDLER( demndrgn_fire_x_r )
273{
274   UINT8 value = input_port_1_r(0);
275
276   if (value & 0x04)
277      return 0xff;
278
279   if (value & 0x08)
280      return 0x00;
281
282   return 0x80;
283}
284
285READ8_HANDLER( demndrgn_fire_y_r )
286{
287   UINT8 value = input_port_1_r(0);
288
289   if (value & 0x01)
290      return 0xff;
291
292   if (value & 0x02)
293      return 0x00;
294
295   return 0x80;
296}
297
298
299WRITE8_HANDLER( demndrgn_sound_w )
300{
301   logerror("Trigger sound sample 0x%02x\n",data);
302}
303
304MACHINE_START( astrocde )
305{
306   astrocade_state_save_register_main();
307
308   state_save_register_global(ebases_trackball_select);
309   state_save_register_global(ram_write_enable);
310   state_save_register_global(demndrgn_ad_select);
311
312   return 0;
313}
314
315MACHINE_START( profpac )
316{
317   state_save_register_global(ram_write_enable);
318
319   if (memory_region(REGION_USER1))
320      memory_configure_bank(1, 0,  14, memory_region(REGION_USER1), 0x4000);
321   memory_configure_bank(1, 14, 3,  memory_region(REGION_CPU1) + 0x14000, 0x8000);
322   memory_configure_bank(2, 0,  1,  memory_region(REGION_CPU1) + 0x8000, 0);
323   memory_configure_bank(2, 1,  1,  memory_region(REGION_CPU1) + 0x18000, 0);
324   memory_configure_bank(2, 2,  1,  memory_region(REGION_CPU1) + 0x20000, 0);
325   memory_configure_bank(2, 3,  1,  memory_region(REGION_CPU1) + 0x28000, 0);
326
327   return 0;
328}
src/mame/machine/vacfdisp.c
r1046r1047
1////////////////////////////////////////////////////////////////////////////
2//                                                                        //
3// vacfdisp.c: Vacuum Fluorescent Display and Controller emulation        //
4//                                                                        //
5// emulated displays: BFM BD1 vfd display, OKI MSC1937                    //
6//                                                                        //
7// 05-03-2004: Re-Animator, last updated 09-04-2007 J. Wallace            //
8//                                                                        //
9// Theory: VFD controllers have a built in character table, which converts//
10// the displayable characters into on/off signals for the various segments//
11// However, each controller has its own way of assigning the segments,    //
12// making standardisation a problem.                                      //
13// Currently, the model used by the OKIMSC1937 is considered as a standard//
14// with the BD1 model converted to it at drawing time.                    //
15//                                                                        //
16// TODO: - BFM sys85 seems to use a slightly different vfd to OKI MSC1937 //
17//       - Add 'skew' to display - characters usually slope 20 degrees    //
18//       - Implement display flashing (need precise rate figures)         //
19//       - Make display better (convert to segment shapes like LED)       //
20//                                                                        //
21////////////////////////////////////////////////////////////////////////////
22
23#include "driver.h"
24#include "vacfdisp.h"
25
26static struct
27{
28   UINT8   type,            // type of alpha display
29                        // VFDTYPE_BFMBD1 or VFDTYPE_MSC1937
30         reversed,         // Allows for the data being written from right to left, not left to right.
31
32         changed,         // flag <>0, if vfd contents are changed
33         window_start,      // display window start pos 0-15
34         window_end,         // display window end   pos 0-15
35         window_size,      // window  size
36         pad;            // unused align byte
37
38   INT8   pcursor_pos,      // previous cursor pos
39         cursor_pos;         // current cursor pos
40
41   UINT16  brightness;         // display brightness level 0-31 (31=MAX)
42
43   UINT16  user_def,         // user defined character state
44         user_data;         // user defined character data (16 bit)
45
46   UINT8   scroll_active,      // flag <>0, scrolling active
47         display_mode,      // display scroll   mode, 0/1/2/3
48         display_blanking,   // display blanking mode, 0/1/2/3
49         flash_rate,         // flash rate 0-F
50         flash_control;      // flash control 0/1/2/3
51
52   UINT8   string[18];         // text buffer
53   UINT32  segments[16],      // segments
54         outputs[16];      // standardised outputs
55
56   UINT8   count,            // bit counter
57         data;            // receive register
58
59} vfds[MAX_VFDS];
60
61
62// local prototypes ///////////////////////////////////////////////////////
63
64static void ScrollLeft( int id);
65static int  BD1_setdata(int id, int segdata, int data);
66
67// local vars /////////////////////////////////////////////////////////////
68
69//
70// Bellfruit BD1 charset to ASCII conversion table
71//
72static const char BFM2ASCII[] =
73//0123456789ABCDEF0123456789ABC DEF01 23456789ABCDEF0123456789ABCDEF
74 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ ?\"#$%%'()*+.-./0123456789&%<=>?"\
75 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ ?\"#$%%'()*+.-./0123456789&%<=>?"\
76 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ ?\"#$%%'()*+.-./0123456789&%<=>?";
77
78//
79// OKI MSC1937 charset to ASCII conversion table
80//
81static const char OKI1937ASCII[]=
82//0123456789ABCDEF0123456789ABC DEF01 23456789ABCDEF0123456789ABCDEF
83 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ ?\"#$%%'()*+;-./0123456789&%<=>?"\
84 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ ?\"#$%%'()*+;-./0123456789&%<=>?"\
85 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ ?\"#$%%'()*+;-./0123456789&%<=>?";
86
87/*
88   BD1 14 segment charset lookup table
89        2
90    ---------
91   |\   |3  /|
92 0 | \6 |  /7| 1
93   |  \ | /  |
94    -F-- --E-
95   |  / | \  |
96 D | /4 |A \B| 5
97   |/   |   \|
98    ---------  C
99        9
100
101  */
102
103static UINT16 BFMcharset[]=
104{           // FEDC BA98 7654 3210
105   0xA626, // 1010 0110 0010 0110 @.
106   0xE027, // 1110 0000 0010 0111 A.
107   0x462E, // 0100 0110 0010 1110 B.
108   0x2205, // 0010 0010 0000 0101 C.
109   0x062E, // 0000 0110 0010 1110 D.
110   0xA205, // 1010 0010 0000 0101 E.
111   0xA005, // 1010 0000 0000 0101 F.
112   0x6225, // 0110 0010 0010 0101 G.
113   0xE023, // 1110 0000 0010 0011 H.
114   0x060C, // 0000 0110 0000 1100 I.
115   0x2222, // 0010 0010 0010 0010 J.
116   0xA881, // 1010 1000 1000 0001 K.
117   0x2201, // 0010 0010 0000 0001 L.
118   0x20E3, // 0010 0000 1110 0011 M.
119   0x2863, // 0010 1000 0110 0011 N.
120   0x2227, // 0010 0010 0010 0111 O.
121   0xE007, // 1110 0000 0000 0111 P.
122   0x2A27, // 0010 1010 0010 0111 Q.
123   0xE807, // 1110 1000 0000 0111 R.
124   0xC225, // 1100 0010 0010 0101 S.
125   0x040C, // 0000 0100 0000 1100 T.
126   0x2223, // 0010 0010 0010 0011 U.
127   0x2091, // 0010 0000 1001 0001 V.
128   0x2833, // 0010 1000 0011 0011 W.
129   0x08D0, // 0000 1000 1101 0000 X.
130   0x04C0, // 0000 0100 1100 0000 Y.
131   0x0294, // 0000 0010 1001 0100 Z.
132   0x2205, // 0010 0010 0000 0101 [.
133   0x0840, // 0000 1000 0100 0000 \.
134   0x0226, // 0000 0010 0010 0110 ].
135   0x0810, // 0000 1000 0001 0000 ^.
136   0x0200, // 0000 0010 0000 0000 _
137   0x0000, // 0000 0000 0000 0000
138   0xC290, // 1100 0010 1001 0000 POUND.
139   0x0009, // 0000 0000 0000 1001 ".
140   0xC62A, // 1100 0110 0010 1010 #.
141   0xC62D, // 1100 0110 0010 1101 $.
142   0x0100, // 0000 0000 0000 0000 flash ?
143   0x0000, // 0000 0000 0000 0000 not defined
144   0x0040, // 0000 0000 1000 0000 '.
145   0x0880, // 0000 1000 1000 0000 (.
146   0x0050, // 0000 0000 0101 0000 ).
147   0xCCD8, // 1100 1100 1101 1000 *.
148   0xC408, // 1100 0100 0000 1000 +.
149   0x1000, // 0001 0000 0000 0000 .
150   0xC000, // 1100 0000 0000 0000 -.
151   0x1000, // 0001 0000 0000 0000 ..
152   0x0090, // 0000 0000 1001 0000 /.
153   0x22B7, // 0010 0010 1011 0111 0.
154   0x0408, // 0000 0100 0000 1000 1.
155   0xE206, // 1110 0010 0000 0110 2.
156   0x4226, // 0100 0010 0010 0110 3.
157   0xC023, // 1100 0000 0010 0011 4.
158   0xC225, // 1100 0010 0010 0101 5.
159   0xE225, // 1110 0010 0010 0101 6.
160   0x0026, // 0000 0000 0010 0110 7.
161   0xE227, // 1110 0010 0010 0111 8.
162   0xC227, // 1100 0010 0010 0111 9.
163   0xFFFF, // 0000 0000 0000 0000 user defined, can be replaced by main program
164   0x0000, // 0000 0000 0000 0000 dummy
165   0x0290, // 0000 0010 1001 0000 <.
166   0xC200, // 1100 0010 0000 0000 =.
167   0x0A40, // 0000 1010 0100 0000 >.
168   0x4406, // 0100 0100 0000 0110 ?
169};
170
171/*
172   MSC1937 16 segment charset lookup table
173     0     1
174    ---- ----
175   |\   |   /|
176 7 | \F |8 /9| 2
177   |  \ | /  |
178    -E-- --A-
179   |  / | \  |
180 6 | /D |C \B| 3
181   |/   |   \|
182    ---- ----  .11
183      5    4   ,10
184
185In 14 segment mode, 0 represents the whole top line,
186and 5 the bottom line, allowing both modes to share
187a charset.
188
189Note that, although we call this a 16 segment display,
190we actually have 18 segments, including the semicolon portions.
191This means our segment maths needs to be more than 16-bit to work!
192*/
193
194static UINT32 OKIcharset[]=
195{           // 11 10 FEDC BA98 7654 3210
196   0x0507F, //  0  0 0101 0000 0111 1111 @.
197   0x044CF, //  0  0 0100 0100 1100 1111 A.
198   0x0153F, //  0  0 0001 0101 0011 1111 B.
199   0x000F3, //  0  0 0000 0000 1111 0011 C.
200   0x0113F, //  0  0 0001 0001 0011 1111 D.
201   0x040F3, //  0  0 0100 0000 1111 0011 E.
202   0x040C3, //  0  0 0100 0000 1100 0011 F.
203   0x004FB, //  0  0 0000 0100 1111 1011 G.
204   0x044CC, //  0  0 0100 0100 1100 1100 H.
205   0x01133, //  0  0 0001 0001 0011 0011 I.
206   0x0007C, //  0  0 0000 0000 0111 1100 J.
207   0x04AC0, //  0  0 0100 1010 1100 0000 K.
208   0x000F0, //  0  0 0000 0000 1111 0000 L.
209   0x082CC, //  0  0 1000 0010 1100 1100 M.
210   0x088CC, //  0  0 1000 1000 1100 1100 N.
211   0x000FF, //  0  0 0000 0000 1111 1111 O.
212   0x044C7, //  0  0 0100 0100 1100 0111 P.
213   0x008FF, //  0  0 0000 1000 1111 1111 Q.
214   0x04CC7, //  0  0 0100 1100 1100 0111 R.
215   0x044BB, //  0  0 0100 0100 1011 1011 S.
216   0x01103, //  0  0 0001 0001 0000 0011 T.
217   0x000FC, //  0  0 0000 0000 1111 1100 U.
218   0x022C0, //  0  0 0010 0010 1100 0000 V.
219   0x028CC, //  0  0 0010 1000 1100 1100 W.
220   0x0AA00, //  0  0 1010 1010 0000 0000 X.
221   0x09200, //  0  0 1001 0010 0000 0000 Y.
222   0x02233, //  0  0 0010 0010 0011 0011 Z.
223   0x000E1, //  0  0 0000 0000 1110 0001 [.
224   0x08800, //  0  0 1000 1000 0000 0000 \.
225   0x0001E, //  0  0 0000 0000 0001 1110 ].
226   0x02800, //  0  0 0010 1000 0000 0000 ^.
227   0x00030, //  0  0 0000 0000 0011 0000 _.
228   0x00000, //  0  0 0000 0000 0000 0000 dummy.
229   0x08121, //  0  0 1000 0001 0010 0001 Unknown symbol.
230   0x00180, //  0  0 0000 0001 1000 0000 ".
231   0x0553C, //  0  0 0101 0101 0011 1100 #.
232   0x055BB, //  0  0 0101 0101 1011 1011 $.
233   0x07799, //  0  0 0111 0111 1001 1001 %.
234   0x0C979, //  0  0 1100 1001 0111 1001 &.
235   0x00200, //  0  0 0000 0010 0000 0000 '.
236   0x00A00, //  0  0 0000 1010 0000 0000 (.
237   0x0A050, //  0  0 1010 0000 0000 0000 ).
238   0x0FF00, //  0  0 1111 1111 0000 0000 *.
239   0x05500, //  0  0 0101 0101 0000 0000 +.
240   0x30000, //  1  1 0000 0000 0000 0000 ;.
241   0x04400, //  0  0 0100 0100 0000 0000 --.
242   0x20000, //  1  0 0000 0000 0000 0000 . .
243   0x02200, //  0  0 0010 0010 0000 0000 /.
244   0x022FF, //  0  0 0010 0010 1111 1111 0.
245   0x01100, //  0  0 0001 0001 0000 0000 1.
246   0x04477, //  0  0 0100 0100 0111 0111 2.
247   0x0443F, //  0  0 0100 0100 0011 1111 3.
248   0x0448C, //  0  0 0100 0100 1000 1100 4.
249   0x044BB, //  0  0 0100 0100 1011 1011 5.
250   0x044FB, //  0  0 0100 0100 1111 1011 6.
251   0x0000E, //  0  0 0000 0000 0000 1110 7.
252   0x044FF, //  0  0 0100 0100 1111 1111 8.
253   0x044BF, //  0  0 0100 0100 1011 1111 9.
254   0x00021, //  0  0 0000 0000 0010 0001 -
255            //                           -.
256   0x02001, //  0  0 0010 0000 0000 0001 -
257          //                           /.
258   0x02430, //  0  0 0010 0100 0011 0000 <.
259   0x04430, //  0  0 0100 0100 0011 0000 =.
260   0x08830, //  0  0 1000 1000 0011 0000 >.
261   0x01407, //  0  0 0001 0100 0000 0111 ?.
262};
263
264static const int poslut1937[]=
265{
266   1,//0
267   2,
268   3,
269   4,
270   5,
271   6,
272   7,
273   8,
274   9,
275   10,
276   11,
277   12,
278   13,
279   14,
280   15,
281   0//15
282};
283
284///////////////////////////////////////////////////////////////////////////
285
286void vfd_init(int id, int type ,int reversed)
287{
288   memset( &vfds[id], 0, sizeof(vfds[0]));
289
290   vfds[id].type = type;
291   vfds[id].reversed = reversed;
292
293   vfd_reset(id);
294}
295
296///////////////////////////////////////////////////////////////////////////
297
298void vfd_reset(int id)
299{
300   if ( id > 2 || id < 0 ) return;
301
302   vfds[id].window_end  = 15;
303   vfds[id].window_size = (vfds[id].window_end - vfds[id].window_start)+1;
304   memset(vfds[id].string, ' ', 16);
305
306   vfds[id].brightness = 31;
307   vfds[id].count      = 0;
308
309   vfds[id].changed |= 1;
310}
311
312///////////////////////////////////////////////////////////////////////////
313
314UINT32 *vfd_get_segments(int id)
315{
316   return vfds[id].segments;
317}
318
319///////////////////////////////////////////////////////////////////////////
320
321UINT32 *vfd_get_outputs(int id)
322{
323   return vfds[id].outputs;
324}
325
326///////////////////////////////////////////////////////////////////////////
327
328UINT32 *vfd_set_outputs(int id)
329{
330   int cursor;
331   switch ( vfds[id].type )
332   {
333      case VFDTYPE_MSC1937:
334      {
335         for (cursor = 0; cursor < 16; cursor++)
336         {
337            if (!vfds[id].reversed)//Output to the screen is naturally backwards, so we need to invert it
338            {
339               vfds[id].outputs[cursor] = vfd_get_segments(id)[15-cursor];
340            }
341            else
342            {
343               //If the controller is reversed, things look normal.
344               vfds[id].outputs[cursor] = vfd_get_segments(id)[cursor];
345            }
346         }
347      }
348      break;
349      case VFDTYPE_BFMBD1:
350      {
351         for (cursor = 0; cursor < 16; cursor++)
352         {
353            if ( vfd_get_segments(id)[cursor] & 0x01 )   vfds[id].outputs[cursor] |=  0x0080;
354            else                                    vfds[id].outputs[cursor] &= ~0x0080;
355            if ( vfd_get_segments(id)[cursor] & 0x02 )   vfds[id].outputs[cursor] |=  0x0004;
356            else                                    vfds[id].outputs[cursor] &= ~0x0004;
357            if ( vfd_get_segments(id)[cursor] & 0x04 )   vfds[id].outputs[cursor] |=  0x0001;
358            else                                    vfds[id].outputs[cursor] &= ~0x0001;
359            if ( vfd_get_segments(id)[cursor] & 0x08 )   vfds[id].outputs[cursor] |=  0x0100;
360            else                                    vfds[id].outputs[cursor] &= ~0x0100;
361            if ( vfd_get_segments(id)[cursor] & 0x10 )   vfds[id].outputs[cursor] |=  0x2000;
362            else                                    vfds[id].outputs[cursor] &= ~0x2000;
363            if ( vfd_get_segments(id)[cursor] & 0x20 )   vfds[id].outputs[cursor] |=  0x0008;
364            else                                    vfds[id].outputs[cursor] &= ~0x0008;
365            if ( vfd_get_segments(id)[cursor] & 0x40 )   vfds[id].outputs[cursor] |=  0x8000;
366            else                                    vfds[id].outputs[cursor] &= ~0x8000;
367            if ( vfd_get_segments(id)[cursor] & 0x80 )   vfds[id].outputs[cursor] |=  0x0200;
368            else                                    vfds[id].outputs[cursor] &= ~0x0200;
369
370            //Flashing ? Set an unused pin as a control
371            if ( vfd_get_segments(id)[cursor] & 0x100 )   vfds[id].outputs[cursor] |=  0x40000;
372            else                                    vfds[id].outputs[cursor] &= ~0x40000;
373
374            if ( vfd_get_segments(id)[cursor] & 0x200 )   vfds[id].outputs[cursor] |=  0x0020;
375            else                                    vfds[id].outputs[cursor] &= ~0x0020;
376            if ( vfd_get_segments(id)[cursor] & 0x400 )   vfds[id].outputs[cursor] |=  0x1000;
377            else                                    vfds[id].outputs[cursor] &= ~0x1000;
378            if ( vfd_get_segments(id)[cursor] & 0x800 )   vfds[id].outputs[cursor] |=  0x0800;
379            else                                    vfds[id].outputs[cursor] &= ~0x0800;
380            if ( vfd_get_segments(id)[cursor] & 0x1000 )vfds[id].outputs[cursor] |=  0x20000;
381            else                                    vfds[id].outputs[cursor] &= ~0x20000;
382            if ( vfd_get_segments(id)[cursor] & 0x2000 )vfds[id].outputs[cursor] |=  0x0040;
383            else                                    vfds[id].outputs[cursor] &= ~0x0040;
384            if ( vfd_get_segments(id)[cursor] & 0x4000 )vfds[id].outputs[cursor] |=  0x0400;
385            else                                    vfds[id].outputs[cursor] &= ~0x0400;
386            if ( vfd_get_segments(id)[cursor] & 0x8000 )vfds[id].outputs[cursor] |=  0x4000;
387            else                                    vfds[id].outputs[cursor] &= ~0x4000;
388         }
389      }
390   }
391   return 0;
392}
393///////////////////////////////////////////////////////////////////////////
394
395char  *vfd_get_string( int id)
396{
397   return (char *)vfds[id].string;
398}
399
400///////////////////////////////////////////////////////////////////////////
401
402void vfd_shift_data(int id, int data)
403{
404   if ( id > 2 || id < 0 ) return;
405
406   vfds[id].data <<= 1;
407
408   if ( !data ) vfds[id].data |= 1;
409
410   if ( ++vfds[id].count >= 8 )
411   {
412      if ( vfd_newdata(id, vfds[id].data) )
413      {
414         vfds[id].changed |= 1;
415      }
416   //logerror("vfd %3d -> %02X \"%s\"\n", id, vfds[id].data, vfds[id].string);
417
418   vfds[id].count = 0;
419   vfds[id].data  = 0;
420  }
421}
422
423///////////////////////////////////////////////////////////////////////////
424
425int vfd_newdata(int id, int data)
426{
427   int change = 0;
428   int cursor;
429
430   switch ( vfds[id].type )
431   {
432      case VFDTYPE_BFMBD1:
433
434      if ( vfds[id].user_def )
435      {
436         vfds[id].user_def--;
437
438         vfds[id].user_data <<= 8;
439         vfds[id].user_data |= data;
440
441         if ( vfds[id].user_def )
442         {
443            return 0;
444         }
445
446      data = '@';
447      change = BD1_setdata(id, vfds[id].user_def, data);
448      }
449      else
450      {
451      }
452
453      switch ( data & 0xF0 )
454      {
455         case 0x80:   // 0x80 - 0x8F Set display blanking
456
457         vfds[id].display_blanking = data & 0x0F;
458         change = 1;
459         break;
460
461         case 0x90:   // 0x90 - 0x9F Set cursor pos
462
463         vfds[id].cursor_pos = data & 0x0F;
464
465         vfds[id].scroll_active = 0;
466         if ( vfds[id].display_mode == 2 )
467         {
468            if ( vfds[id].cursor_pos >= vfds[id].window_end) vfds[id].scroll_active = 1;
469         }
470         break;
471
472         case 0xA0:   // 0xA0 - 0xAF Set display mode
473
474         vfds[id].display_mode = data &0x03;
475         break;
476
477         case 0xB0:   // 0xB0 - 0xBF Clear display area
478
479         switch ( data & 0x03 )
480         {
481            case 0x00:   // clr nothing
482            break;
483
484            case 0x01:   // clr inside window
485
486            if ( vfds[id].window_size > 0 )
487               {
488                  memset( vfds[id].string+vfds[id].window_start, ' ',vfds[id].window_size );
489               }
490               break;
491
492            case 0x02:   // clr outside window
493
494            if ( vfds[id].window_size > 0 )
495               {
496                  if ( vfds[id].window_start > 0 )
497                  {
498                     memset( vfds[id].string, ' ', vfds[id].window_start);
499                     for (cursor = 0; cursor < vfds[id].window_start; cursor++)
500                     {
501                        vfds[id].segments[cursor] = 0x0000;
502                     }
503                  }
504
505                  if (vfds[id].window_end < 15 )
506                  {
507                     memset( vfds[id].string+vfds[id].window_end, ' ', 15-vfds[id].window_end);
508                     for (cursor = vfds[id].window_end; cursor < 15-vfds[id].window_end; cursor++)
509                     {
510                        vfds[id].segments[cursor] = 0x0000;
511                     }
512
513                  }
514               }
515            case 0x03:   // clr entire display
516
517            memset(vfds[id].string, ' ' , 16);
518            for (cursor = 0; cursor < 16; cursor++)
519            {
520            vfds[id].segments[cursor] = 0x0000;
521            }
522            break;
523         }
524         change = 1;
525         break;
526
527         case 0xC0:   // 0xC0 - 0xCF Set flash rate
528
529         vfds[id].flash_rate = data & 0x0F;
530         break;
531
532         case 0xD0:   // 0xD0 - 0xDF Set Flash control
533
534         vfds[id].flash_control = data & 0x03;
535         break;
536
537         case 0xE0:   // 0xE0 - 0xEF Set window start pos
538
539         vfds[id].window_start = data &0x0F;
540         vfds[id].window_size  = (vfds[id].window_end - vfds[id].window_start)+1;
541         break;
542
543         case 0xF0:   // 0xF0 - 0xFF Set window end pos
544
545         vfds[id].window_end   = data &0x0F;
546         vfds[id].window_size  = (vfds[id].window_end - vfds[id].window_start)+1;
547
548         vfds[id].scroll_active = 0;
549         if ( vfds[id].display_mode == 2 )
550         {
551            if ( vfds[id].cursor_pos >= vfds[id].window_end)
552            {
553               vfds[id].scroll_active = 1;
554               vfds[id].cursor_pos    = vfds[id].window_end;
555            }
556         }
557         break;
558
559         default:   // normal character
560
561         change = BD1_setdata(id, BFMcharset[data & 0x3F], data);
562         break;
563      }
564      break;
565
566      case VFDTYPE_MSC1937:
567
568      if ( data & 0x80 )
569      { // Control data received
570         if ( (data & 0xF0) == 0xA0 ) // 1010 xxxx
571         { // 1010 xxxx Buffer Pointer control
572            vfds[id].cursor_pos = poslut1937[data & 0x0F];
573         }
574         else if ( (data & 0xF0) == 0xC0 ) // 1100 xxxx
575            { // 1100 xxxx Set number of digits
576               data &= 0x07;
577
578               if ( data == 0 ) vfds[id].window_size = 16;
579               else             vfds[id].window_size = data+8;
580               vfds[id].window_start = 0;
581               vfds[id].window_end   = vfds[id].window_size-1;
582            }
583         else if ( (data & 0xE0) == 0xE0 ) // 111x xxxx
584            { // 111x xxxx Set duty cycle ( brightness )
585               vfds[id].brightness = (data & 0xF)*2;
586               change = 1;
587            }
588         else if ( (data & 0xE0) == 0x80 ) // 100x ---
589            { // 100x xxxx Test mode
590            }
591      }
592      else
593      { // Display data
594         data &= 0x3F;
595         change = 1;
596
597         switch ( data )
598         {
599            case 0x2C: // ;
600            vfds[id].segments[vfds[id].pcursor_pos] |= (1<<17);//.
601            vfds[id].segments[vfds[id].pcursor_pos] |= (1<<18);//,
602            break;
603            case 0x2E: //
604            vfds[id].segments[vfds[id].pcursor_pos] |= (1<<17);//.
605            break;
606            default :
607            vfds[id].pcursor_pos = vfds[id].cursor_pos;
608            vfds[id].string[ vfds[id].cursor_pos ] = OKI1937ASCII[data];
609            vfds[id].segments[vfds[id].cursor_pos] = OKIcharset[data & 0x3F];
610
611            vfds[id].cursor_pos++;
612            if (  vfds[id].cursor_pos > vfds[id].window_end )
613               {
614                  vfds[id].cursor_pos = 0;
615               }
616         }
617      }
618      break;
619   }
620
621   return change;
622}
623
624///////////////////////////////////////////////////////////////////////////
625
626static void ScrollLeft(int id)
627{
628   int i = vfds[id].window_start;
629
630   while ( i < vfds[id].window_end )
631   {
632      vfds[id].string[ i ] = vfds[id].string[ i+1 ];
633      vfds[id].segments[i] = vfds[id].segments[i+1];
634      i++;
635   }
636}
637
638///////////////////////////////////////////////////////////////////////////
639
640static int BD1_setdata(int id, int segdata, int data)
641{
642   int change = 0, move = 0;
643
644   switch ( data )
645   {
646      case 0x25:   // flash
647      move++;
648      break;
649
650      case 0x26:  // undefined
651      break;
652
653      case 0x2C:  // semicolon
654      case 0x2E:  // decimal point
655
656      vfds[id].segments[vfds[id].pcursor_pos] |= (1<<12);
657      change++;
658      break;
659
660      case 0x3B:   // dummy char
661      move++;
662      break;
663
664      case 0x3A:
665      vfds[id].user_def = 2;
666      break;
667
668      default:
669      move   = 1;
670      change = 1;
671   }
672
673   if ( move )
674   {
675      int mode = vfds[id].display_mode;
676
677      vfds[id].pcursor_pos = vfds[id].cursor_pos;
678
679      if ( vfds[id].window_size <= 0 || (vfds[id].window_size > 16))
680         { // no window selected default to rotate mode
681              if ( mode == 2 )      mode = 0;
682            else if ( mode == 3 ) mode = 1;
683            //mode &= -2;
684   }
685
686   switch ( mode )
687   {
688      case 0: // rotate left
689
690      vfds[id].cursor_pos &= 0x0F;
691
692      if ( change )
693      {
694         vfds[id].string[vfds[id].cursor_pos]   = BFM2ASCII[data];
695         vfds[id].segments[vfds[id].cursor_pos] = segdata;
696      }
697      vfds[id].cursor_pos++;
698      if ( vfds[id].cursor_pos >= 16 ) vfds[id].cursor_pos = 0;
699      break;
700
701
702      case 1: // Rotate right
703
704      vfds[id].cursor_pos &= 0x0F;
705
706      if ( change )
707      {
708         vfds[id].string[vfds[id].cursor_pos]   = BFM2ASCII[data];
709         vfds[id].segments[vfds[id].cursor_pos] = segdata;
710      }
711      vfds[id].cursor_pos--;
712      if ( vfds[id].cursor_pos < 0  ) vfds[id].cursor_pos = 15;
713      break;
714
715      case 2: // Scroll left
716
717      if ( vfds[id].cursor_pos < vfds[id].window_end )
718      {
719         vfds[id].scroll_active = 0;
720         if ( change )
721         {
722            vfds[id].string[vfds[id].cursor_pos]   = BFM2ASCII[data];
723            vfds[id].segments[vfds[id].cursor_pos] = segdata;
724         }
725         if ( move ) vfds[id].cursor_pos++;
726      }
727      else
728      {
729         if ( move )
730         {
731            if   ( vfds[id].scroll_active ) ScrollLeft(id);
732            else                            vfds[id].scroll_active = 1;
733         }
734
735         if ( change )
736         {
737            vfds[id].string[vfds[id].window_end]   = BFM2ASCII[data];
738            vfds[id].segments[vfds[id].cursor_pos] = segdata;
739           }
740         else
741         {
742            vfds[id].string[vfds[id].window_end]   = ' ';
743            vfds[id].segments[vfds[id].cursor_pos] = 0;
744         }
745      }
746      break;
747
748      case 3: // Scroll right
749
750      if ( vfds[id].cursor_pos > vfds[id].window_start )
751         {
752            if ( change )
753            {
754               vfds[id].string[vfds[id].cursor_pos]   = BFM2ASCII[data];
755               vfds[id].segments[vfds[id].cursor_pos] = segdata;
756            }
757            vfds[id].cursor_pos--;
758         }
759         else
760         {
761            int i = vfds[id].window_end;
762
763            while ( i > vfds[id].window_start )
764            {
765               vfds[id].string[ i ] = vfds[id].string[ i-1 ];
766               vfds[id].segments[i] = vfds[id].segments[i-1];
767               i--;
768            }
769
770            if ( change )
771            {
772               vfds[id].string[vfds[id].window_start]   = BFM2ASCII[data];
773               vfds[id].segments[vfds[id].window_start] = segdata;
774            }
775         }
776         break;
777      }
778   }
779   return change;
780}
781
782static void plot_vfd(mame_bitmap *bitmap,int vfd,int segs,int color, int col_off )
783{
784   int cursor;
785   int   curwidth = 288/16;
786   vfd_set_outputs(vfd);
787
788   for (cursor = 0; cursor < 16; cursor++)
789   {
790      switch (segs)
791      {
792         case 14:
793         {
794            plot_box(bitmap, 1+(curwidth*cursor), 0, 11, 2, (vfd_get_outputs(vfd)[cursor] & 0x0001) ? color : col_off);//0
795            plot_box(bitmap, 1+(curwidth*cursor), 27, 11, 2, (vfd_get_outputs(vfd)[cursor] & 0x0020) ? color : col_off);//5
796            break;
797         }
798         case 16:
799         {
800            plot_box(bitmap, 1+(curwidth*cursor), 0, 5, 2, (vfd_get_outputs(vfd)[cursor] & 0x0001) ? color : col_off);//0
801            plot_box(bitmap, 7+(curwidth*cursor), 0, 5, 2, (vfd_get_outputs(vfd)[cursor] & 0x0002) ? color : col_off);//1
802            plot_box(bitmap, 7+(curwidth*cursor), 27, 5, 2, (vfd_get_outputs(vfd)[cursor] & 0x0010) ? color : col_off);//4
803            plot_box(bitmap, 1+(curwidth*cursor), 27, 5, 2, (vfd_get_outputs(vfd)[cursor] & 0x0020) ? color : col_off);//5
804            break;
805         }
806      }
807
808      plot_box(bitmap, 12+(curwidth*cursor), 2, 2, 12, (vfd_get_outputs(vfd)[cursor] & 0x0004) ? color : col_off);//2
809      plot_box(bitmap, 12+(curwidth*cursor), 16, 2, 12, (vfd_get_outputs(vfd)[cursor] & 0x0008) ? color : col_off);//3
810      plot_box(bitmap, (curwidth*cursor), 16, 2, 12, (vfd_get_outputs(vfd)[cursor] & 0x0040) ? color : col_off);//6
811      plot_box(bitmap, (curwidth*cursor), 2, 2, 12, (vfd_get_outputs(vfd)[cursor] & 0x0080) ? color : col_off);//7
812      plot_box(bitmap, 7+(curwidth*cursor), 2, 2, 12, (vfd_get_outputs(vfd)[cursor] & 0x0100) ? color : col_off);//8
813
814      plot_box(bitmap, 10+(curwidth*cursor), 9, 2, 2, (vfd_get_outputs(vfd)[cursor] & 0x0200) ? color : col_off);//9?
815      plot_box(bitmap, 9+(curwidth*cursor), 10, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x0200) ? color : col_off);//9?
816      plot_box(bitmap, 10+(curwidth*cursor), 5, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x0200) ? color : col_off);//9?
817
818      plot_box(bitmap, 7+(curwidth*cursor), 14, 7, 2, (vfd_get_outputs(vfd)[cursor] & 0x0400) ? color : col_off);//10
819
820      plot_box(bitmap, 10+(curwidth*cursor),21, 2, 2, (vfd_get_outputs(vfd)[cursor] & 0x0800) ? color : col_off);//11?
821      plot_box(bitmap, 9+(curwidth*cursor), 17, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x0800) ? color : col_off);//11?
822      plot_box(bitmap, 10+(curwidth*cursor), 22, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x0800) ? color : col_off);//11?
823
824      plot_box(bitmap, 7+(curwidth*cursor), 16, 2, 11, (vfd_get_outputs(vfd)[cursor] & 0x1000) ? color : col_off);//12
825
826      plot_box(bitmap, 3+(curwidth*cursor), 21, 2, 2, (vfd_get_outputs(vfd)[cursor] & 0x2000) ? color : col_off);//13?
827      plot_box(bitmap, 4+(curwidth*cursor), 17, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x2000) ? color : col_off);//13? first step
828      plot_box(bitmap, 3+(curwidth*cursor), 22, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x2000) ? color : col_off);//13? second step
829
830      plot_box(bitmap, (curwidth*cursor), 14, 7, 2, (vfd_get_outputs(vfd)[cursor] & 0x4000) ? color : col_off);//14
831
832      plot_box(bitmap, 3+(curwidth*cursor), 9, 2, 2, (vfd_get_outputs(vfd)[cursor] & 0x8000) ? color : col_off);//15?
833      plot_box(bitmap, 4+(curwidth*cursor), 10, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x8000) ? color : col_off);//15? first step
834      plot_box(bitmap, 3+(curwidth*cursor), 5, 2, 4, (vfd_get_outputs(vfd)[cursor] & 0x8000) ? color : col_off);//15? second step
835
836      switch (vfds[vfd].type)
837      {
838         case VFDTYPE_BFMBD1:
839         {
840            plot_box(bitmap, 15+(curwidth*cursor), 22, 1, 3, (vfd_get_outputs(vfd)[cursor] & 0x20000) ? color : col_off);//18
841            plot_box(bitmap, 16+(curwidth*cursor), 23, 1, 7, (vfd_get_outputs(vfd)[cursor] & 0x20000) ? color : col_off);//18
842            plot_box(bitmap, 17+(curwidth*cursor), 27, 1, 6, (vfd_get_outputs(vfd)[cursor] & 0x20000) ? color : col_off);//18
843            plot_box(bitmap, 18+(curwidth*cursor), 31, 1, 1, (vfd_get_outputs(vfd)[cursor] & 0x20000) ? color : col_off);//18
844            break;
845         }
846
847         case VFDTYPE_MSC1937:
848         {
849
850            plot_box(bitmap, 15+(curwidth*cursor), 27, 1, 6, (vfd_get_outputs(vfd)[cursor] & 0x10000) ? color : col_off);//17
851            plot_box(bitmap, 16+(curwidth*cursor), 27, 1, 3, (vfd_get_outputs(vfd)[cursor] & 0x10000) ? color : col_off);//17
852            plot_box(bitmap, 15+(curwidth*cursor), 23, 2, 2, (vfd_get_outputs(vfd)[cursor] & 0x20000) ? color : col_off);//18
853
854            break;
855         }
856
857         if (vfd_get_outputs(vfd)[cursor] & 0x40000)
858            {
859               //activate flashing (unimplemented, just toggle on and off)
860            }
861         else
862            {
863               //deactivate flashing (unimplemented)
864            }
865      }
866   }
867}
868static void vfd_draw(mame_bitmap *bitmap,int vfd,int segs,int col_on, int col_off )
869{
870   int cycle,color;
871   if (vfds[vfd].type == VFDTYPE_BFMBD1)
872   {
873      if (segs != 14)
874      {
875         logerror("BD1 controller only supports 14 segments - defaulting to 14 seg mode \n");
876         segs = 14;
877      }
878
879      color = col_on;
880      plot_vfd(bitmap,vfd,segs,color,col_off );
881   }
882   if (vfds[vfd].type == VFDTYPE_MSC1937)
883   {
884      for (cycle = 0; cycle < 32; cycle++)
885      {
886         if ((vfds[vfd].brightness < cycle)||(vfds[vfd].brightness == cycle))
887         {
888            color = col_on;
889            plot_vfd(bitmap,vfd,segs,color,col_off );
890         }
891         else
892         {
893            color = col_off;
894            plot_vfd(bitmap,vfd,segs,color,col_off );
895         }
896      }
897   }
898}
899//Helper functions
900void vfd_draw_16seg(mame_bitmap *bitmap,int vfd, int col_on, int col_off )
901{
902   vfd_draw(bitmap,vfd,16,col_on,col_off );
903}
904void vfd_draw_14seg(mame_bitmap *bitmap,int vfd, int col_on, int col_off )
905{
906   vfd_draw(bitmap,vfd,14,col_on,col_off );
907}
src/mame/machine/vacfdisp.h
r1046r1047
1#ifndef VACFDISP
2#define VACFDISP
3
4#define MAX_VFDS  3     // max number of vfd displays emulated
5
6#define VFDTYPE_BFMBD1   0 // Bellfruit BD1 display
7#define VFDTYPE_MSC1937 1 // OKI MSC1937   display
8#define REVERSED 1 // display is reversed
9
10void   vfd_init(  int id, int type, int reversed );      // setup a vfd
11
12void   vfd_reset( int id);               // reset the vfd
13
14void   vfd_shift_data(int id, int data);   // clock in a bit of data
15
16int      vfd_newdata(   int id, int data);   // clock in 8 bits of data (scorpion2 vfd interface)
17
18UINT32   *vfd_get_segments(int id);         // get current segments displayed
19UINT32  *vfd_set_outputs(int id);         // convert segments to standard for display
20UINT32  *vfd_get_outputs(int id);         // get converted segments
21
22char   *vfd_get_string( int id);         // get current string   displayed (not as accurate)
23
24void vfd_draw_16seg(mame_bitmap *bitmap,int vfd, int col_on, int col_off );
25void vfd_draw_14seg(mame_bitmap *bitmap,int vfd, int col_on, int col_off );
26#endif
27
src/mame/machine/leprechn.c
r1046r1047
1#include "driver.h"
2#include "cpu/m6502/m6502.h"
3#include "machine/6522via.h"
4#include "includes/leprechn.h"
5
6
7static UINT8 input_port_select;
8
9static WRITE8_HANDLER( leprechn_input_port_select_w )
10{
11    input_port_select = data;
12}
13
14static READ8_HANDLER( leprechn_input_port_r )
15{
16    switch (input_port_select)
17    {
18    case 0x01:
19        return input_port_0_r(0);
20    case 0x02:
21        return input_port_2_r(0);
22    case 0x04:
23        return input_port_3_r(0);
24    case 0x08:
25        return input_port_1_r(0);
26    case 0x40:
27        return input_port_5_r(0);
28    case 0x80:
29        return input_port_4_r(0);
30    }
31
32    return 0xff;
33}
34
35
36static WRITE8_HANDLER( leprechn_coin_counter_w )
37{
38   coin_counter_w(offset, !data);
39}
40
41
42static WRITE8_HANDLER( leprechn_sh_w )
43{
44    soundlatch_w(offset,data);
45    cpunum_set_input_line(1,M6502_IRQ_LINE,HOLD_LINE);
46}
47
48
49
50static struct via6522_interface leprechn_via_0_interface =
51{
52   /*inputs : A/B         */ 0, leprechn_videoram_r,
53   /*inputs : CA/B1,CA/B2 */ 0, 0, 0, 0,
54   /*outputs: A/B         */ leprechn_videoram_w, leprechn_graphics_command_w,
55   /*outputs: CA/B1,CA/B2 */ 0, 0, 0, 0,
56   /*irq                  */ 0
57};
58
59static struct via6522_interface leprechn_via_1_interface =
60{
61   /*inputs : A/B         */ leprechn_input_port_r, 0,
62   /*inputs : CA/B1,CA/B2 */ 0, 0, 0, 0,
63   /*outputs: A/B         */ 0, leprechn_input_port_select_w,
64   /*outputs: CA/B1,CA/B2 */ 0, 0, 0, leprechn_coin_counter_w,
65   /*irq                  */ 0
66};
67
68static struct via6522_interface leprechn_via_2_interface =
69{
70   /*inputs : A/B         */ 0, 0,
71   /*inputs : CA/B1,CA/B2 */ 0, 0, 0, 0,
72   /*outputs: A/B         */ leprechn_sh_w, 0,
73   /*outputs: CA/B1,CA/B2 */ 0, 0, 0, 0,
74   /*irq                  */ 0
75};
76
77
78DRIVER_INIT( leprechn )
79{
80   via_config(0, &leprechn_via_0_interface);
81   via_config(1, &leprechn_via_1_interface);
82   via_config(2, &leprechn_via_2_interface);
83
84   via_reset();
85}
86
87
88READ8_HANDLER( leprechn_sh_0805_r )
89{
90    return 0xc0;
91}
src/mame/machine/mpu4.c
r1046r1047
1/**********************************************************************
2
3    Motorola 6850 ACIA interface and emulation
4
5    This function is a simple emulation of a pair of MC6850
6    Asynchronous Communications Interface Adapters.
7    This has largely been stolen from the Sente SAC-1 driver
8    by Aaron Giles
9
10**********************************************************************/
11
12#include "driver.h"
13
14#define LOGM4(x)   logerror x
15#define LOGMV(x)   logerror x
16
17/* 68k 6850 states */
18static UINT8 m6850_status;
19static UINT8 m6850_control;
20static UINT8 m6850_input;
21static UINT8 m6850_output;
22static UINT8 m6850_output_temp;
23static UINT8 m6850_data_ready;
24
25/* 6809 CPU 6850 states */
26static UINT8 m6850_mpu4_status;
27static UINT8 m6850_mpu4_control;
28static UINT8 m6850_mpu4_input;
29static UINT8 m6850_mpu4_output;
30static UINT8 m6850_mpu4_output_temp;
31static UINT8 m6850_mpu4_data_ready;
32
33UINT8 m6850_irq_state; // referenced from drivers/mpu4.c
34void update_mpu68_interrupts(void); // referenced from drivers/mpu4.c
35
36void cpu0_irq(int state);
37/*************************************
38 *
39 *  6850 UART communications
40 *
41 *************************************/
42
43static void m6850_update_io(void)
44{
45   UINT8 new_state;
46
47   /* mpu4 -> main CPU communications */
48   if (m6850_mpu4_data_ready)
49   {
50      /* set the overrun bit if the data in the destination hasn't been read yet */
51      if (m6850_status & 0x01)
52         m6850_status |= 0x20;
53
54      /* copy the mpu4's output to our input */
55      m6850_input = m6850_mpu4_output;
56      LOGMV(("VID ACIA INPUT = %x \n",m6850_input));
57
58      /* set the receive register full bit */
59      m6850_status |= 0x01;
60
61      /* set the mpu4's transmitter register empty bit */
62      m6850_mpu4_status |= 0x02;
63      m6850_mpu4_data_ready = 0;
64   }
65
66   /* main -> mpu4 CPU communications */
67   if (m6850_data_ready)
68   {
69      /* set the overrun bit if the data in the destination hasn't been read yet */
70      if (m6850_mpu4_status & 0x01)
71         m6850_mpu4_status |= 0x20;
72
73      /* copy the main CPU's output to our input */
74      m6850_mpu4_input = m6850_output;
75      LOGM4(("MPU4 ACIA INPUT = %x \n",m6850_mpu4_input));
76      /* set the receive register full bit */
77      m6850_mpu4_status |= 0x01;
78
79      /* set the main CPU's trasmitter register empty bit */
80      m6850_status |= 0x02;
81      m6850_data_ready = 0;
82   }
83
84   /* check for reset states */
85   if ((m6850_control & 3) == 3)
86   {
87      m6850_status = 0x02;
88   }
89   if ((m6850_mpu4_control & 3) == 3)
90      m6850_mpu4_status = 0x02;
91
92   /* check for transmit/receive IRQs on the main CPU */
93   new_state = 0;
94   if ((m6850_control & 0x80) && (m6850_status & 0x21)) new_state = 1;
95   if ((m6850_control & 0x60) == 0x20 && (m6850_status & 0x02)) new_state = 1;
96
97   /* apply the change */
98   if (new_state && !(m6850_status & 0x80))
99   {
100      m6850_irq_state = 1;
101      update_mpu68_interrupts();
102      m6850_status |= 0x80;
103   }
104   else if (!new_state && (m6850_status & 0x80))
105   {
106      m6850_irq_state = 0;
107      update_mpu68_interrupts();
108      m6850_status &= ~0x80;
109   }
110
111   /* check for transmit/receive IRQs on the mpu4 CPU */
112   new_state = 0;
113   if ((m6850_mpu4_control & 0x80) && (m6850_mpu4_status & 0x21)) new_state = 1;
114   if ((m6850_mpu4_control & 0x60) == 0x20 && (m6850_mpu4_status & 0x02)) new_state = 1;
115
116   /* apply the change */
117   if (new_state && !(m6850_mpu4_status & 0x80))
118   {
119      cpu0_irq(1);
120      m6850_mpu4_status |= 0x80;
121   }
122   else if (!new_state && (m6850_mpu4_status & 0x80))
123   {
124      cpu0_irq(0);
125      m6850_mpu4_status &= ~0x80;
126   }
127}
128
129/*************************************
130 *
131 *  6850 UART (main CPU)
132 *
133 *************************************/
134
135READ16_HANDLER( vidcard_uart_rx_r )
136{
137   int result;
138//  offset = (offset << 8 | 0x00ff);
139
140   /* status register is at offset 0 */
141   if (offset == 0)
142   {
143      result = m6850_status;
144      LOGMV(("MPU4 ACIA STAT = %x \n",m6850_status));
145   }
146
147   /* input register is at offset 1 */
148   else
149   {
150      result = m6850_input;
151
152      /* clear the overrun and receive buffer full bits */
153      m6850_status &= ~0x21;
154      m6850_update_io();
155   }
156   return ((result << 8) | 0x00ff);
157}
158
159
160static void m6850_data_ready_callback(int param)
161{
162   /* set the output data byte and indicate that we're ready to go */
163   m6850_output = param;
164   m6850_data_ready = 1;
165   m6850_update_io();
166}
167
168static void m6850_mpu4_data_ready_callback(int param)
169{
170   /* set the output data byte and indicate that we're ready to go */
171   m6850_mpu4_output = param;
172   m6850_mpu4_data_ready = 1;
173   m6850_update_io();
174}
175
176
177static void m6850_w_callback(int param)
178{
179   /* indicate that the transmit buffer is no longer empty and update the I/O state */
180   m6850_status &= ~0x02;
181   m6850_output_temp = param;
182   m6850_update_io();
183
184   /* set a timer for 500usec later to actually transmit the data */
185//  timer_set(TIME_IN_USEC(500), param, m6850_data_ready_callback);
186}
187
188static void m6850_mpu4_w_callback(int param)
189{
190   /* indicate that the transmit buffer is no longer empty and update the I/O state */
191   m6850_mpu4_status &= ~0x02;
192   m6850_mpu4_output_temp = param;
193   m6850_update_io();
194
195   /* set a timer for 500usec later to actually transmit the data */
196//  timer_set(TIME_IN_USEC(500), param, m6850_data_ready_callback);
197}
198
199WRITE16_HANDLER( vidcard_uart_tx_w )
200{
201//  offset = (offset << 8 | 0x00ff);
202   /* control register is at offset 0 */
203   if (offset == 0)
204   {
205      m6850_control = (data & 0xff);
206      LOGMV(("VID ACIA CTRL = %x \n",m6850_control));
207
208      /* re-update since interrupt enables could have been modified */
209      m6850_update_io();
210   }
211
212   /* output register is at offset 1; set a timer to synchronize the CPUs */
213   else
214      timer_set(TIME_NOW, (data & 0xff), m6850_w_callback);
215      LOGMV(("VID ACIA SENDING = %x \n",data&0xff));
216}
217
218
219
220/*************************************
221 *
222 *  6850 UART (mpu4 CPU)
223 *
224 *************************************/
225
226READ8_HANDLER( mpu4_uart_rx_r )
227{
228   int result;
229
230   /* status register is at offset 0 */
231   if (offset == 0)
232   {
233      result = m6850_mpu4_status;
234      LOGM4(("MPU4 ACIA STAT = %x \n",m6850_mpu4_status));
235   }
236
237   /* input register is at offset 1 */
238   else
239   {
240      result = m6850_mpu4_input;
241
242      /* clear the overrun and receive buffer full bits */
243      m6850_mpu4_status &= ~0x21;
244      m6850_update_io();
245   }
246
247   return result;
248}
249
250
251WRITE8_HANDLER( mpu4_uart_tx_w )
252{
253   /* control register is at offset 0 */
254   if (offset == 0)
255   {
256      m6850_mpu4_control = data;
257      LOGM4(("MPU4 ACIA CTRL = %x \n",m6850_mpu4_control));
258   }
259   /* output register is at offset 1 */
260   else
261   {
262//      m6850_mpu4_output_temp = data;
263//      m6850_mpu4_status &= ~0x02;
264      timer_set(TIME_NOW, (data), m6850_mpu4_w_callback);
265      LOGM4(("MPU4 ACIA SENDING = %x \n",data));
266   }
267
268   /* re-update since interrupt enables could have been modified */
269   m6850_update_io();
270}
271
src/mame/machine/neogeo.c
r1046r1047
1#include "driver.h"
2#include "machine/pd4990a.h"
3#include "neogeo.h"
4#include "sound/2610intf.h"
5
6
7extern INT32 neogeo_sram_locked;
8
9extern INT32 neogeo_rng;
10extern INT32 neogeo_prot_data;
11
12UINT16 *neogeo_ram16;
13UINT16 *neogeo_sram16;
14
15
16/***************** MEMCARD GLOBAL VARIABLES ******************/
17UINT8 *neogeo_memcard;      /* Pointer to 2kb RAM zone */
18
19UINT8 *neogeo_game_vectors;
20
21static void neogeo_register_sub_savestate(void);
22
23
24/* This function is called on every reset */
25MACHINE_RESET( neogeo )
26{
27   mame_system_time systime;
28
29
30   /* Reset variables & RAM */
31   memset (neogeo_ram16, 0, 0x10000);
32
33
34
35   mame_get_base_datetime(Machine, &systime);
36
37   pd4990a.seconds = ((systime.local_time.second/10)<<4) + (systime.local_time.second%10);
38   pd4990a.minutes = ((systime.local_time.minute/10)<<4) + (systime.local_time.minute%10);
39   pd4990a.hours = ((systime.local_time.hour/10)<<4) + (systime.local_time.hour%10);
40   pd4990a.days = ((systime.local_time.mday/10)<<4) + (systime.local_time.mday%10);
41   pd4990a.month = (systime.local_time.month + 1);
42   pd4990a.year = ((((systime.local_time.year - 1900) %100)/10)<<4) + ((systime.local_time.year - 1900)%10);
43   pd4990a.weekday = systime.local_time.weekday;
44
45   neogeo_rng = 0x2345;   /* seed for the protection RNG in KOF99 onwards */
46
47   /* it boots up with the BIOS vectors selected - see fatfury3 which has a corrupt vector in the game cart */
48   neogeo_select_bios_vectors(0,0,0); // data doesn't matter
49
50   /* not ideal having these here, but they need to be checked every reset at least */
51   /* the rom banking is tied directly to the dipswitch?, or is there a bank write somewhere? */
52   if (!strcmp(machine->gamedrv->name,"svcpcb"))
53   {
54      int harddip3 = readinputportbytag("HARDDIP")&1;
55      memcpy(memory_region( REGION_USER1 ),memory_region( REGION_USER1 )+0x20000+harddip3*0x20000, 0x20000);
56   }
57   /* a jumper pad on th PCB acts as a ROM overlay and is used to select the game language as opposed to the BIOS */
58   if (!strcmp(machine->gamedrv->name,"kog"))
59   {
60      int jumper = readinputportbytag("JUMPER");
61      memory_region(REGION_CPU1)[0x1FFFFC/2] = jumper;
62   }
63
64   neogeo_start_timers();
65}
66
67
68/* This function is only called once per game. */
69DRIVER_INIT( neogeo )
70{
71   extern struct YM2610interface neogeo_ym2610_interface;
72   UINT16 *mem16 = (UINT16 *)memory_region(REGION_CPU1);
73   int tileno,numtiles;
74
75   numtiles = memory_region_length(REGION_GFX3)/128;
76   for (tileno = 0;tileno < numtiles;tileno++)
77   {
78      unsigned char swap[128];
79      UINT8 *gfxdata;
80      int x,y;
81      unsigned int pen;
82
83      gfxdata = &memory_region(REGION_GFX3)[128 * tileno];
84
85      memcpy(swap,gfxdata,128);
86
87      for (y = 0;y < 16;y++)
88      {
89         UINT32 dw;
90
91         dw = 0;
92         for (x = 0;x < 8;x++)
93         {
94            pen  = ((swap[64 + 4*y + 3] >> x) & 1) << 3;
95            pen |= ((swap[64 + 4*y + 1] >> x) & 1) << 2;
96            pen |= ((swap[64 + 4*y + 2] >> x) & 1) << 1;
97            pen |=   (swap[64 + 4*y     ] >> x) & 1;
98            dw |= pen << 4*x;
99         }
100         *(gfxdata++) = dw>>0;
101         *(gfxdata++) = dw>>8;
102         *(gfxdata++) = dw>>16;
103         *(gfxdata++) = dw>>24;
104
105         dw = 0;
106         for (x = 0;x < 8;x++)
107         {
108            pen  = ((swap[4*y + 3] >> x) & 1) << 3;
109            pen |= ((swap[4*y + 1] >> x) & 1) << 2;
110            pen |= ((swap[4*y + 2] >> x) & 1) << 1;
111            pen |=   (swap[4*y    ] >> x) & 1;
112            dw |= pen << 4*x;
113         }
114         *(gfxdata++) = dw>>0;
115         *(gfxdata++) = dw>>8;
116         *(gfxdata++) = dw>>16;
117         *(gfxdata++) = dw>>24;
118      }
119   }
120
121   if (memory_region(REGION_SOUND2))
122   {
123      logerror("using memory region %d for Delta T samples\n",REGION_SOUND2);
124      neogeo_ym2610_interface.pcmromb = REGION_SOUND2;
125   }
126   else
127   {
128      logerror("using memory region %d for Delta T samples\n",REGION_SOUND1);
129      neogeo_ym2610_interface.pcmromb = REGION_SOUND1;
130   }
131
132   /* Allocate ram banks */
133   neogeo_ram16 = auto_malloc (0x10000);
134   memory_set_bankptr(1, neogeo_ram16);
135
136   /* Set the biosbank */
137   memory_set_bankptr(3, memory_region(REGION_USER1));
138
139   /* Set the 2nd ROM bank */
140   if (memory_region_length(REGION_CPU1) > 0x100000)
141      neogeo_set_cpu1_second_bank(0x100000);
142   else
143      neogeo_set_cpu1_second_bank(0x000000);
144
145   /* Set the sound CPU ROM banks */
146   neogeo_init_cpu2_setbank();
147
148   /* Allocate and point to the memcard - bank 5 */
149   neogeo_memcard = auto_malloc(0x800);
150   memset(neogeo_memcard, 0, 0x800);
151
152   mem16 = (UINT16 *)memory_region(REGION_USER1);
153
154
155   /* irritating maze uses a trackball */
156   if (!strcmp(machine->gamedrv->name,"irrmaze"))
157      neogeo_has_trackball = 1;
158   else
159      neogeo_has_trackball = 0;
160
161
162   { /* info from elsemi, this is how nebula works, is there a better way in mame? */
163      UINT8* gamerom = memory_region(REGION_CPU1);
164      neogeo_game_vectors = auto_malloc (0x80);
165      memcpy( neogeo_game_vectors, gamerom, 0x80 );
166   }
167}
168
169MACHINE_START( neogeo )
170{
171   neogeo_create_timers();
172
173   /* register state save */
174   neogeo_register_main_savestate();
175   neogeo_register_sub_savestate();
176}
177
178
179/******************************************************************************/
180
181WRITE16_HANDLER (neogeo_select_bios_vectors)
182{
183   UINT8* gamerom = memory_region(REGION_CPU1);
184   UINT8* biosrom = memory_region(REGION_USER1);
185
186   memcpy( gamerom, biosrom, 0x80 );
187}
188
189WRITE16_HANDLER (neogeo_select_game_vectors)
190{
191   UINT8* gamerom = memory_region(REGION_CPU1);
192   memcpy( gamerom, neogeo_game_vectors, 0x80 );
193}
194
195/******************************************************************************/
196
197
198
199NVRAM_HANDLER( neogeo )
200{
201   if (read_or_write)
202   {
203      /* Save the SRAM settings */
204      mame_fwrite(file,neogeo_sram16,0x2000);
205   }
206   else
207   {
208      /* Load the SRAM settings for this game */
209      if (file)
210         mame_fread(file,neogeo_sram16,0x2000);
211      else
212         memset(neogeo_sram16,0,0x10000);
213   }
214}
215
216
217
218/*
219    INFORMATION:
220
221    Memory card is a 2kb battery backed RAM.
222    It is accessed thru 0x800000-0x800FFF.
223    Even bytes are always 0xFF
224    Odd bytes are memcard data (0x800 bytes)
225
226    Status byte at 0x380000: (BITS ARE ACTIVE *LOW*)
227
228    0 PAD1 START
229    1 PAD1 SELECT
230    2 PAD2 START
231    3 PAD2 SELECT
232    4 --\  MEMORY CARD
233    5 --/  INSERTED
234    6 MEMORY CARD WRITE PROTECTION
235    7 UNUSED (?)
236*/
237
238
239
240
241/********************* MEMCARD ROUTINES **********************/
242READ16_HANDLER( neogeo_memcard16_r )
243{
244   if (memcard_present() != -1)
245      return neogeo_memcard[offset] | 0xff00;
246   else
247      return ~0;
248}
249
250WRITE16_HANDLER( neogeo_memcard16_w )
251{
252   if (ACCESSING_LSB)
253   {
254      if (memcard_present() != -1)
255         neogeo_memcard[offset] = data & 0xff;
256   }
257}
258
259MEMCARD_HANDLER( neogeo )
260{
261   char buf[0x800];
262
263   switch (action)
264   {
265      case MEMCARD_CREATE:
266         memset(buf, 0, sizeof(buf));
267         mame_fwrite(file, neogeo_memcard, 0x800);
268         break;
269
270      case MEMCARD_INSERT:
271         mame_fread(file, neogeo_memcard, 0x800);
272         break;
273
274      case MEMCARD_EJECT:
275         mame_fwrite(file, neogeo_memcard, 0x800);
276         break;
277   }
278}
279
280/******************************************************************************/
281
282static void neogeo_register_sub_savestate(void)
283{
284   UINT8* gamevector = memory_region(REGION_CPU1);
285
286   state_save_register_global(neogeo_sram_locked);
287   state_save_register_global_pointer(neogeo_ram16, 0x10000/2);
288   state_save_register_global_pointer(neogeo_memcard, 0x800);
289   state_save_register_global_pointer(gamevector, 0x80);
290   state_save_register_global(neogeo_prot_data);
291}
src/mame/machine/lamps.c
r1046r1047
1///////////////////////////////////////////////////////////////////////////
2//                                                                       //
3// lamps.c: module to keep track of lamp brightness                      //
4//                                                                       //
5//    05-03-2004: Re-Animator                                            //
6//                                                                       //
7// TODO: add a lamppanel interface for getting on/off info quickly       //
8//       without having to go through a list of lamps                    //
9//                                                                       //
10//       think of a mechanism to check if lamps / lamp panels need       //
11//       to be refreshed                                                 //
12//                                                                       //
13// Any fixes for this driver should be forwarded to AGEMAME HQ           //
14// (http://www.mameworld.net/agemame/)                                   //
15///////////////////////////////////////////////////////////////////////////
16
17#include "driver.h"
18#include "lamps.h"
19
20// local vars /////////////////////////////////////////////////////////////
21
22static UINT8 lamps[MAX_LAMPS];
23static int   number_lamps;
24
25
26///////////////////////////////////////////////////////////////////////////
27
28void Lamps_init(int number)
29{
30  if ( number > MAX_LAMPS ) number = MAX_LAMPS;
31
32  number_lamps = number;
33}
34
35///////////////////////////////////////////////////////////////////////////
36
37int Lamps_GetNumberLamps(void)
38{
39  return number_lamps;
40}
41
42///////////////////////////////////////////////////////////////////////////
43
44void Lamps_SetBrightness( int start_id, int count, UINT8 *bright )
45{
46  int id = start_id;
47
48  while ( id < number_lamps && count-- )
49  {
50   lamps[id++] = *bright++;
51  }
52}
53
54///////////////////////////////////////////////////////////////////////////
55
56int  Lamps_GetBrightness(int lamp)
57{
58  return ( lamp < number_lamps )? lamps[lamp] : 0;
59}
src/mame/machine/lamps.h
r1046r1047
1// Any fixes for this driver should be forwarded to AGEMAME HQ (http://www.mameworld.net/agemame/)
2
3#ifndef INC_LAMPS
4#define INC_LAMPS
5
6#define MAX_LAMPS 512
7
8
9void Lamps_init(int number);
10
11int  Lamps_GetNumberLamps(void);
12
13void Lamps_SetBrightness(int start_id, int count, UINT8 *bright );
14
15int  Lamps_GetBrightness(int id);
16
17#endif
src/mame/machine/berzerk.c
r1046r1047
1/***************************************************************************
2
3  machine.c
4
5  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
6  I/O ports)
7
8***************************************************************************/
9
10#include "driver.h"
11#include "cpu/z80/z80.h"
12#include "includes/berzerk.h"
13
14
15static int irq_enabled;
16static int nmi_enabled;
17static int int_count;
18
19
20MACHINE_RESET( berzerk )
21{
22   irq_enabled = 0;
23   nmi_enabled = 0;
24   int_count = 0;
25}
26
27
28WRITE8_HANDLER( berzerk_irq_enable_w )
29{
30   irq_enabled = data;
31}
32
33WRITE8_HANDLER( berzerk_nmi_enable_w )
34{
35   nmi_enabled = 1;
36}
37
38WRITE8_HANDLER( berzerk_nmi_disable_w )
39{
40   nmi_enabled = 0;
41}
42
43READ8_HANDLER( berzerk_nmi_enable_r )
44{
45   nmi_enabled = 1;
46   return 0;
47}
48
49READ8_HANDLER( berzerk_nmi_disable_r )
50{
51   nmi_enabled = 0;
52   return 0;
53}
54
55READ8_HANDLER( berzerk_led_on_r )
56{
57   set_led_status(0,1);
58
59   return 0;
60}
61
62READ8_HANDLER( berzerk_led_off_r )
63{
64   set_led_status(0,0);
65
66   return 0;
67}
68
69INTERRUPT_GEN( berzerk_interrupt )
70{
71   int_count++;
72
73   if (int_count & 0x03)
74   {
75      if (nmi_enabled) cpunum_set_input_line(0, INPUT_LINE_NMI, PULSE_LINE);
76   }
77   else
78   {
79      if (irq_enabled) cpunum_set_input_line_and_vector(0, 0, HOLD_LINE, 0xfc);
80   }
81}
82
src/mame/machine/spiders.c
r1046r1047
1/***************************************************************************
2
3  machine/spiders.c
4
5  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
6  I/O ports)
7
8***************************************************************************/
9
10#include "driver.h"
11#include "spiders.h"
12#include "machine/6821pia.h"
13#include "cpu/m6800/m6800.h"
14#include "cpu/m6809/m6809.h"
15
16
17
18/* Declare inividual irq handlers, may be able to combine later */
19/* Main CPU */
20static void spiders_irq0a(int state) { cpunum_set_input_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
21static void spiders_irq0b(int state) { cpunum_set_input_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
22static void spiders_irq1a(int state) { cpunum_set_input_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
23static void spiders_irq1b(int state) { cpunum_set_input_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
24static void spiders_irq2a(int state) { cpunum_set_input_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
25static void spiders_irq2b(int state) { cpunum_set_input_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
26
27/* Sound CPU */
28static void spiders_irq3a(int state) { cpunum_set_input_line(1,M6802_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
29
30static WRITE8_HANDLER( spiders_soundcmd_w )
31{
32   pia_set_input_a(3, data & 0xf8);
33   pia_set_input_ca1(3,data  & 0x80 ? 1 : 0);
34}
35
36
37/* Function prototypes */
38
39static WRITE8_HANDLER( spiders_flip_w );
40static WRITE8_HANDLER( spiders_vrif_w );
41static READ8_HANDLER( spiders_vrom_r );
42
43
44/* Declare PIA structure */
45
46/* PIA 1, main CPU */
47static const pia6821_interface pia_0_intf =
48{
49   /*inputs : A/B,CA/B1,CA/B2 */ input_port_0_r, input_port_1_r, 0, 0, 0, 0,
50   /*outputs: A/B,CA/B2       */ 0, 0, 0, 0,
51   /*irqs   : A/B             */ spiders_irq0a, spiders_irq0b
52};
53
54/* PIA 2, main CPU */
55static const pia6821_interface pia_1_intf =
56{
57   /*inputs : A/B,CA/B1,CA/B2 */ spiders_vrom_r, 0, input_port_5_r, 0, 0, 0,
58   /*outputs: A/B,CA/B2       */ 0, spiders_vrif_w, 0, spiders_flip_w,
59   /*irqs   : A/B             */ spiders_irq1a, spiders_irq1b
60};
61
62/* PIA 3, main CPU */
63static const pia6821_interface pia_2_intf =
64{
65   /*inputs : A/B,CA/B1,CA/B2 */ 0, 0, 0, 0, 0, 0,
66   /*outputs: A/B,CA/B2       */ spiders_soundctrl_w, spiders_soundcmd_w, 0, 0,
67   /*irqs   : A/B             */ spiders_irq2a, spiders_irq2b
68};
69
70/* PIA, sound CPU */
71static const pia6821_interface pia_3_intf =
72{
73   /*inputs : A/B,CA/B1,CA/B2 */ 0, 0, 0, 0, 0, 0,
74   /*outputs: A/B,CA/B2       */ spiders_sounda_w, spiders_soundb_w, 0, 0,
75   /*irqs   : A/B             */ spiders_irq3a, 0
76};
77
78
79/***************************************************************************
80
81    Spiders Machine initialisation
82
83***************************************************************************/
84
85MACHINE_START( spiders )
86{
87   pia_config(0, PIA_STANDARD_ORDERING, &pia_0_intf);
88   pia_config(1, PIA_ALTERNATE_ORDERING, &pia_1_intf);
89   pia_config(2, PIA_STANDARD_ORDERING, &pia_2_intf);
90   pia_config(3, PIA_STANDARD_ORDERING, &pia_3_intf);
91   return 0;
92}
93
94
95MACHINE_RESET( spiders )
96{
97   pia_reset();
98}
99
100
101
102/***************************************************************************
103
104    Timed interrupt handler - Updated PIA input ports
105
106***************************************************************************/
107
108INTERRUPT_GEN( spiders_timed_irq )
109{
110   /* Update CA1 on PIA1 - copy of PA1 (COIN1) */
111   pia_0_ca1_w(0 , input_port_0_r(0)&0x02);
112
113   /* Update CA2 on PIA1 - copy of PA0 (SERVICE1) */
114   pia_0_ca2_w(0 , input_port_0_r(0)&0x01);
115
116   /* Update CB1 on PIA1 - (Crosshatch) */
117   pia_0_cb1_w(0 , input_port_6_r(0));
118
119   /* Update CB2 on PIA1 - NOT CONNECTED */
120}
121
122
123/***************************************************************************
124
125    Video access port definition (On PIA 2)
126
127    Bit 7 6 5 4 3 2 1 0
128        X                Mode Setup/Read 1/0
129            X X          Latch select (see below)
130                X X X X  Data nibble
131
132    When in setup mode data is clocked into the latch by a read from port a.
133    When in read mode the read from port a auto increments the address.
134
135    Latch 0 - Low byte low nibble
136          1 - Low byte high nibble
137          2 - High order low nibble
138          3 - High order high nibble
139
140***************************************************************************/
141
142static int vrom_address;
143static int vrom_ctrl_mode;
144static int vrom_ctrl_latch;
145static int vrom_ctrl_data;
146
147UINT8 spiders_video_flip=0;
148
149static WRITE8_HANDLER( spiders_flip_w )
150{
151   spiders_video_flip=data;
152}
153
154static WRITE8_HANDLER( spiders_vrif_w )
155{
156   vrom_ctrl_mode=(data&0x80)>>7;
157   vrom_ctrl_latch=(data&0x30)>>4;
158   vrom_ctrl_data=15-(data&0x0f);
159}
160
161static READ8_HANDLER( spiders_vrom_r )
162{
163   int retval;
164   unsigned char *RAM = memory_region(REGION_GFX1);
165
166   if(vrom_ctrl_mode)
167   {
168      retval=RAM[vrom_address];
169      vrom_address++;
170   }
171   else
172   {
173      switch(vrom_ctrl_latch)
174      {
175         case 0:
176            vrom_address&=0xfff0;
177            vrom_address|=vrom_ctrl_data;
178            break;
179         case 1:
180            vrom_address&=0xff0f;
181            vrom_address|=vrom_ctrl_data<<4;
182            break;
183         case 2:
184            vrom_address&=0xf0ff;
185            vrom_address|=vrom_ctrl_data<<8;
186            break;
187         case 3:
188            vrom_address&=0x0fff;
189            vrom_address|=vrom_ctrl_data<<12;
190            break;
191         default:
192            break;
193      }
194      retval=0;
195   }
196   return retval;
197}
198
src/mame/machine/clayshoo.c
r1046r1047
1/***************************************************************************
2
3    Atari Clay Shoot hardware
4
5    driver by Zsolt Vasvari
6
7****************************************************************************/
8
9#include "driver.h"
10#include "machine/8255ppi.h"
11#include "includes/clayshoo.h"
12
13
14static UINT8 input_port_select;
15static UINT8 analog_port_val;
16
17
18/*************************************
19 *
20 *  Digital control handling functions
21 *
22 *************************************/
23
24static WRITE8_HANDLER( input_port_select_w )
25{
26   input_port_select = data;
27}
28
29
30static UINT8 difficulty_input_port_r(int bit)
31{
32   UINT8 ret = 0;
33
34   /* read fake port and remap the buttons to 2 bits */
35   UINT8   raw = readinputportbytag("FAKE");
36
37   if (raw & (1 << (bit + 1)))
38      ret = 0x03;      /* expert */
39   else if (raw & (1 << (bit + 2)))
40      ret = 0x01;      /* pro */
41   else
42      ret = 0x00;      /* amateur otherwise */
43
44   return ret;
45}
46
47
48static READ8_HANDLER( input_port_r )
49{
50   UINT8 ret = 0;
51
52
53   switch (input_port_select)
54   {
55   case 0x01:   ret = readinputportbytag("IN0"); break;
56   case 0x02:   ret = readinputportbytag("IN1"); break;
57   case 0x04:   ret = (readinputportbytag("IN2") & 0xf0) |
58                  difficulty_input_port_r(0) |
59                 (difficulty_input_port_r(3) << 2); break;
60   case 0x08:   ret = readinputportbytag("IN3"); break;
61   case 0x10:
62   case 0x20:   break;   /* these two are not really used */
63   default: logerror("Unexpected port read: %02X\n", input_port_select);
64   }
65
66   return ret;
67}
68
69
70static ppi8255_interface ppi8255_intf =
71{
72   2,                      /* 2 chips */
73   { 0, 0 },               /* Port A read */
74   { 0, input_port_r },      /* Port B read */
75   { 0, 0 },               /* Port C read */
76   { 0, input_port_select_w },   /* Port A write */
77   { 0, 0 },               /* Port B write */
78   { 0, 0 /* sound effects */},/* Port C write */
79};
80
81
82MACHINE_RESET( clayshoo )
83{
84   ppi8255_init(&ppi8255_intf);
85}
86
87
88
89/*************************************
90 *
91 *  Analog control handling functions
92 *
93 *************************************/
94
95static void reset_analog_bit(int bit)
96{
97   analog_port_val &= ~bit;
98}
99
100
101static double compute_duration(int analog_pos)
102{
103   /* the 58 comes from the length of the loop used to
104       read the analog position */
105   return TIME_IN_CYCLES(58*analog_pos, 0);
106}
107
108
109WRITE8_HANDLER( clayshoo_analog_reset_w )
110{
111   /* reset the analog value, and start two times that will fire
112       off in a short period proportional to the position of the
113       analog control and set the appropriate bit. */
114
115   analog_port_val = 0xff;
116
117   timer_set(compute_duration(readinputportbytag("AN1")), 0x02, reset_analog_bit);
118   timer_set(compute_duration(readinputportbytag("AN2")), 0x01, reset_analog_bit);
119}
120
121
122READ8_HANDLER( clayshoo_analog_r )
123{
124   return analog_port_val;
125}
src/mame/includes/micro3d.h
r1046r1047
1#include "cpu/tms34010/tms34010.h"
2
3/*----------- defined in drivers/micro3d.c -----------*/
4
5extern UINT16 *micro3d_sprite_vram;
6extern UINT16 dpyadr;
7extern int dpyadrscan;
8
9/*----------- defined in video/micro3d.c -----------*/
10
11WRITE16_HANDLER( paletteram16_BBBBBRRRRRGGGGGG_word_w );
12
13VIDEO_START(micro3d);
14void micro3d_scanline_update(running_machine *machine, int screen, mame_bitmap *bitmap, int scanline, const tms34010_display_params *params);
15
src/mame/includes/bfm_sc2.h
r1046r1047
1#ifndef INC_BFMSC2
2#define INC_BFMSC2
3
4/*----------- defined in drivers/bfm_sc2.c -----------*/
5
6extern void on_scorpion2_reset(void);
7extern void send_to_sc2(int data);
8extern int  read_from_sc2(void);
9extern void send_to_adder(int data);
10extern int  receive_from_adder(void);
11
12extern void Scorpion2_SetSwitchState(int strobe, int data, int state);
13extern int Scorpion2_GetSwitchState(int strobe, int data);
14
15extern int  get_adder2_uart_status(void);
16
17extern int adder2_data_from_sc2;   // data available for adder from sc2
18extern int adder2_sc2data;         // data
19extern int sc2_data_from_adder;      // data available for sc2 from adder
20extern int sc2_adderdata;         // data
21
22extern int sc2_show_door;        // flag <>0, display door state
23extern int sc2_door_state;        // door state to display
24
25#endif
src/mame/includes/leprechn.h
r1046r1047
1/*************************************************************************
2
3    Leprechaun/Pot of Gold
4
5*************************************************************************/
6
7/*----------- defined in machine/leprechn.c -----------*/
8
9DRIVER_INIT( leprechn );
10READ8_HANDLER( leprechn_sh_0805_r );
11
12
13/*----------- defined in video/leprechn.c -----------*/
14
15PALETTE_INIT( leprechn );
16VIDEO_START( leprechn );
17
18WRITE8_HANDLER( leprechn_graphics_command_w );
19READ8_HANDLER( leprechn_videoram_r );
20WRITE8_HANDLER( leprechn_videoram_w );
src/mame/includes/sprint4.h
r1046r1047
1/***************************************************************************
2
3Atari Sprint 4 + Ultra Tank driver
4
5***************************************************************************/
6
7#include "sound/discrete.h"
8
9/* discrete sound input nodes */
10#define SPRINT4_SKID1_EN        NODE_01
11#define SPRINT4_SKID2_EN        NODE_02
12#define SPRINT4_SKID3_EN        NODE_03
13#define SPRINT4_SKID4_EN        NODE_04
14#define SPRINT4_MOTOR1_DATA     NODE_05
15#define SPRINT4_MOTOR2_DATA     NODE_06
16#define SPRINT4_MOTOR3_DATA     NODE_07
17#define SPRINT4_MOTOR4_DATA     NODE_08
18#define SPRINT4_CRASH_DATA      NODE_09
19#define SPRINT4_ATTRACT_EN      NODE_10
20
21/*----------- defined in audio/sprint4.c -----------*/
22
23extern discrete_sound_block sprint4_discrete_interface[];
24
25
26/*----------- defined in video/sprint4.c -----------*/
27
28extern UINT8* sprint4_videoram;
29extern int sprint4_collision[4];
30
31extern PALETTE_INIT( sprint4 );
32extern PALETTE_INIT( ultratnk );
33
34extern VIDEO_EOF( sprint4 );
35extern VIDEO_EOF( ultratnk );
36extern VIDEO_START( sprint4 );
37extern VIDEO_START( ultratnk );
38extern VIDEO_UPDATE( sprint4 );
39extern VIDEO_UPDATE( ultratnk );
40
41extern WRITE8_HANDLER( sprint4_video_ram_w );
src/mame/includes/clayshoo.h
r1046r1047
1/***************************************************************************
2
3    Atari Clay Shoot hardware
4
5    driver by Zsolt Vasvari
6
7****************************************************************************/
8
9/*----------- defined in machine/clayshoo.c -----------*/
10
11MACHINE_RESET( clayshoo );
12WRITE8_HANDLER( clayshoo_analog_reset_w );
13READ8_HANDLER( clayshoo_analog_r );
src/mame/video/snowbros.c
r1046r1047
1/***************************************************************************
2
3  Snow Brothers by ToaPlan - GFX driver.
4  GFX processor - PX79C480FP-3 (KANEKO, Pandora-Chip)
5
6***************************************************************************/
7
8#include "driver.h"
9
10
11WRITE16_HANDLER( snowbros_flipscreen_w )
12{
13   if (ACCESSING_MSB)
14      flip_screen_set(~data & 0x8000);
15}
16
17
18VIDEO_UPDATE( snowbros )
19{
20   int sx=0, sy=0, x=0, y=0, offs;
21
22
23   /*
24     * Sprite Tile Format
25     * ------------------
26     *
27     * Byte | Bit(s)   | Use
28     * -----+-76543210-+----------------
29     *  0-5 | -------- | ?
30     *  6   | -------- | ?
31     *  7   | xxxx.... | Palette Bank
32     *  7   | .......x | XPos - Sign Bit
33     *  9   | xxxxxxxx | XPos
34     *  7   | ......x. | YPos - Sign Bit
35     *  B   | xxxxxxxx | YPos
36     *  7   | .....x.. | Use Relative offsets
37     *  C   | -------- | ?
38     *  D   | xxxxxxxx | Sprite Number (low 8 bits)
39     *  E   | -------- | ?
40     *  F   | ....xxxx | Sprite Number (high 4 bits)
41     *  F   | x....... | Flip Sprite Y-Axis
42     *  F   | .x...... | Flip Sprite X-Axis
43     */
44
45   /* This clears & redraws the entire screen each pass */
46
47   fillbitmap(bitmap,0xf0,&machine->screen[0].visarea);
48
49   for (offs = 0;offs < spriteram_size/2;offs += 8)
50   {
51      int dx = spriteram16[offs+4] & 0xff;
52      int dy = spriteram16[offs+5] & 0xff;
53      int tilecolour = spriteram16[offs+3];
54      int attr = spriteram16[offs+7];
55      int flipx =   attr & 0x80;
56      int flipy =  (attr & 0x40) << 1;
57      int tile  = ((attr & 0x3f) << 8) + (spriteram16[offs+6] & 0xff);
58
59      if (tilecolour & 1) dx = -1 - (dx ^ 0xff);
60      if (tilecolour & 2) dy = -1 - (dy ^ 0xff);
61      if (tilecolour & 4)
62      {
63         x += dx;
64         y += dy;
65      }
66      else
67      {
68         x = dx;
69         y = dy;
70      }
71
72      if (x > 511) x &= 0x1ff;
73      if (y > 511) y &= 0x1ff;
74
75      if (flip_screen)
76      {
77         sx = 240 - x;
78         sy = 240 - y;
79         flipx = !flipx;
80         flipy = !flipy;
81      }
82      else
83      {
84         sx = x;
85         sy = y;
86      }
87
88      drawgfx(bitmap,machine->gfx[0],
89            tile,
90            (tilecolour & 0xf0) >> 4,
91            flipx, flipy,
92            sx,sy,
93            &machine->screen[0].visarea,TRANSPARENCY_PEN,0);
94   }
95   return 0;
96}
97
98VIDEO_UPDATE( honeydol )
99{
100   int sx=0, sy=0, x=0, y=0, offs;
101   /* sprites clip on left / right edges when scrolling, but it seems correct,
102       no extra sprite attribute bits are set during this time, the sprite co-ordinates
103       are simply set to 0 */
104
105   /* not standard snowbros video */
106
107   fillbitmap(bitmap,0xf0,&machine->screen[0].visarea);
108
109   for (offs = 0x0000/2;offs < 0x2000/2;offs += 8)
110   {
111      int dx,dy,tilecolour,attr,flipx,flipy,tile;
112
113      /* 8bpp gfx */
114      dx = (spriteram16[offs+4]>>8) & 0xff;
115      dy = (spriteram16[offs+5]>>8) & 0xff;
116      tilecolour = (spriteram16[offs+3]>>8)&3;
117      attr = spriteram16[offs+7]>>8;
118      flipx =   attr & 0x80;
119      flipy =  (attr & 0x40) << 1;
120      tile  = ((attr & 0x3f)<<8) + ((spriteram16[offs+6]>>8) & 0xff);
121
122      x = dx;
123      y = dy;
124
125      if (flip_screen)
126      {
127         sx = 240 - x;
128         sy = 240 - y;
129         flipx = !flipx;
130         flipy = !flipy;
131      }
132      else
133      {
134         sx = x;
135         sy = y;
136      }
137
138      drawgfx(bitmap,machine->gfx[1],
139            tile,
140            tilecolour,
141            flipx, flipy,
142            sx,sy,
143            &machine->screen[0].visarea,TRANSPARENCY_PEN,0);
144
145      /* second list interleaved with first (4bpp) ??? */
146      dx = spriteram16[offs+4] & 0xff;
147      dy = spriteram16[offs+5] & 0xff;
148      tilecolour = spriteram16[offs+3];
149      attr = spriteram16[offs+7];
150      flipx =   attr & 0x80;
151      flipy =  (attr & 0x40) << 1;
152      tile  = ((attr & 0x3f) << 8) + (spriteram16[offs+6] & 0xff);
153
154      x = dx;
155      y = dy;
156
157      if (flip_screen)
158      {
159         sx = 240 - x;
160         sy = 240 - y;
161         flipx = !flipx;
162         flipy = !flipy;
163      }
164      else
165      {
166         sx = x;
167         sy = y;
168      }
169
170      tilecolour = (tilecolour&0x03f0) >> 4;
171      tilecolour ^=0x3f; // unusual, but correct..
172
173      drawgfx(bitmap,machine->gfx[0],
174            tile,
175            tilecolour,
176            flipx, flipy,
177            sx,sy,
178            &machine->screen[0].visarea,TRANSPARENCY_PEN,0);
179   }
180   return 0;
181}
182
183
184VIDEO_UPDATE( twinadv )
185{
186   int sx=0, sy=0, x=0, y=0, offs;
187   /* sprites clip on left / right edges when scrolling, but it seems correct,
188       no extra sprite attribute bits are set during this time, the sprite co-ordinates
189       are simply set to 0 */
190
191   /* not standard snowbros video */
192
193   fillbitmap(bitmap,0xf0,&machine->screen[0].visarea);
194
195   for (offs = 0x0000/2;offs < 0x2000/2;offs += 8)
196   {
197      int dx,dy,tilecolour,attr,flipx,flipy,tile;
198
199      /* Similar to Honey Doll, but no 8bpp list / gfx */
200
201      dx = spriteram16[offs+4] & 0xff;
202      dy = spriteram16[offs+5] & 0xff;
203      tilecolour = spriteram16[offs+3];
204      attr = spriteram16[offs+7];
205      flipx =   attr & 0x80;
206      flipy =  (attr & 0x40) << 1;
207      tile  = ((attr & 0x3f) << 8) + (spriteram16[offs+6] & 0xff);
208
209      x = dx;
210      y = dy;
211
212      if (flip_screen)
213      {
214         sx = 240 - x;
215         sy = 240 - y;
216         flipx = !flipx;
217         flipy = !flipy;
218      }
219      else
220      {
221         sx = x;
222         sy = y;
223      }
224
225      tilecolour = (tilecolour&0x00f0) >> 4;
226      tilecolour ^=0xf; // unusual, but correct..
227
228      drawgfx(bitmap,machine->gfx[0],
229            tile,
230            tilecolour,
231            flipx, flipy,
232            sx,sy,
233            &machine->screen[0].visarea,TRANSPARENCY_PEN,0);
234   }
235   return 0;
236}
237
238
239VIDEO_UPDATE( wintbob )
240{
241   int offs;
242
243   fillbitmap(bitmap,get_black_pen(machine),&machine->screen[0].visarea);
244
245   for (offs = 0;offs < spriteram_size/2;offs += 8)
246   {
247      int xpos  = spriteram16[offs] & 0xff;
248      int ypos  = spriteram16[offs+4] & 0xff;
249/*      int unk1  = spriteram16[offs+1] & 0x01;*/  /* Unknown .. Set for the Bottom Left part of Sprites */
250      int disbl = spriteram16[offs+1] & 0x02;
251/*      int unk2  = spriteram16[offs+1] & 0x04;*/  /* Unknown .. Set for most things */
252      int wrapr = spriteram16[offs+1] & 0x08;
253      int colr  = (spriteram16[offs+1] & 0xf0) >> 4;
254      int tilen = (spriteram16[offs+2] << 8) + (spriteram16[offs+3] & 0xff);
255      int flipx = spriteram16[offs+2] & 0x80;
256      int flipy = (spriteram16[offs+2] & 0x40) << 1;
257
258      if (wrapr == 8) xpos -= 256;
259
260      if (flip_screen)
261      {
262         xpos = 240 - xpos;
263         ypos = 240 - ypos;
264         flipx = !flipx;
265         flipy = !flipy;
266      }
267
268      if ((xpos > -16) && (ypos > 0) && (xpos < 256) && (ypos < 240) && (disbl !=2))
269      {
270         drawgfx(bitmap,machine->gfx[0],
271               tilen,
272               colr,
273               flipx, flipy,
274               xpos,ypos,
275               &machine->screen[0].visarea,TRANSPARENCY_PEN,0);
276      }
277   }
278   return 0;
279}
280
281
282VIDEO_UPDATE( snowbro3 )
283{
284
285   int sx=0, sy=0, x=0, y=0, offs;
286
287   /*
288     * Sprite Tile Format
289     * ------------------
290     *
291     * Byte | Bit(s)   | Use
292     * -----+-76543210-+----------------
293     *  0-5 | -------- | ?
294     *  6   | -------- | ?
295     *  7   | xxxx.... | Palette Bank
296     *  7   | .......x | XPos - Sign Bit
297     *  9   | xxxxxxxx | XPos
298     *  7   | ......x. | YPos - Sign Bit
299     *  B   | xxxxxxxx | YPos
300     *  7   | .....x.. | Use Relative offsets
301     *  C   | -------- | ?
302     *  D   | xxxxxxxx | Sprite Number (low 8 bits)
303     *  E   | -------- | ?
304     *  F   | ....xxxx | Sprite Number (high 4 bits)
305     *  F   | x....... | Flip Sprite Y-Axis
306     *  F   | .x...... | Flip Sprite X-Axis
307     */
308
309   /* This clears & redraws the entire screen each pass */
310
311   fillbitmap(bitmap,get_black_pen(machine),&machine->screen[0].visarea);
312
313   for (offs = 0;offs < spriteram_size/2;offs += 8)
314   {
315      gfx_element *gfx = machine->gfx[0];
316      int dx = spriteram16[offs+4] & 0xff;
317      int dy = spriteram16[offs+5] & 0xff;
318      int tilecolour = spriteram16[offs+3];
319      int attr = spriteram16[offs+7];
320      int flipx =   attr & 0x80;
321      int flipy =  (attr & 0x40) << 1;
322      int tile  = ((attr & 0xff) << 8) + (spriteram16[offs+6] & 0xff);
323
324      if (tilecolour & 1) dx = -1 - (dx ^ 0xff);
325      if (tilecolour & 2) dy = -1 - (dy ^ 0xff);
326      if (tilecolour & 4)
327      {
328         x += dx;
329         y += dy;
330      }
331      else
332      {
333         x = dx;
334         y = dy;
335      }
336
337      if (x > 511) x &= 0x1ff;
338      if (y > 511) y &= 0x1ff;
339
340      if (flip_screen)
341      {
342         sx = 240 - x;
343         sy = 240 - y;
344         flipx = !flipx;
345         flipy = !flipy;
346      }
347      else
348      {
349         sx = x;
350         sy = y;
351      }
352
353      if (offs < 0x800) /* i guess this is the right way */
354      {
355         gfx = machine->gfx[1];
356         tilecolour = 0x10;
357      }
358
359   drawgfx(bitmap,gfx,
360            tile,
361            (tilecolour & 0xf0) >> 4,
362            flipx, flipy,
363            sx,sy,
364            &machine->screen[0].visarea,TRANSPARENCY_PEN,0);
365   }
366   return 0;
367}
368
src/mame/video/ppu2c03b.c
r1046r1047
1/******************************************************************************
2
3    Nintendo 2C03B PPU emulation.
4
5    Written by Ernesto Corvi.
6    This code is heavily based on Brad Oliver's MESS implementation.
7
8******************************************************************************/
9
10#include <math.h>
11#include "video/ppu2c03b.h"
12#include "profiler.h"
13
14/* constant definitions */
15#define BOTTOM_VISIBLE_SCANLINE   239      /* The bottommost visible scanline */
16#define NMI_SCANLINE           243      /* Triggered at the beginning of this scanline */
17#define VISIBLE_SCREEN_WIDTH   (32*8)   /* Visible screen width */
18#define VISIBLE_SCREEN_HEIGHT   (30*8)   /* Visible screen height */
19#define VIDEORAM_SIZE         0x4000   /* videoram size */
20#define SPRITERAM_SIZE         0x100   /* spriteram size */
21#define SPRITERAM_MASK         (0x100-1)   /* spriteram size */
22#define CHARGEN_NUM_CHARS      512      /* max number of characters handled by the chargen */
23
24/* default monochromatic colortable */
25static const pen_t default_colortable_mono[] =
26{
27   0,1,2,3,
28   0,1,2,3,
29   0,1,2,3,
30   0,1,2,3,
31   0,1,2,3,
32   0,1,2,3,
33   0,1,2,3,
34   0,1,2,3,
35};
36
37/* our chip state */
38typedef struct {
39   mame_bitmap      *bitmap;            /* target bitmap */
40   UINT8               *videoram;            /* video ram */
41   UINT8               *spriteram;            /* sprite ram */
42   pen_t               *colortable_mono;      /* monochromatic color table modified at run time */
43   UINT8               *dirtychar;            /* an array flagging dirty characters */
44   int                  chars_are_dirty;      /* master flag to check if theres any dirty character */
45   void                *scanline_timer;      /* scanline timer */
46   int                  scanline;            /* scanline count */
47   ppu2c03b_scanline_cb   scanline_callback_proc;   /* optional scanline callback */
48   ppu2c03b_vidaccess_cb   vidaccess_callback_proc;/* optional video access callback */
49   int                  has_videorom;         /* whether we access a video rom or not */
50   int                  videorom_banks;         /* number of banks in the videorom (if available) */
51   int                  regs[PPU_MAX_REG];      /* registers */
52   int                  refresh_data;         /* refresh-related */
53   int                  refresh_latch;         /* refresh-related */
54   int                  x_fine;               /* refresh-related */
55   int                  toggle;               /* used to latch hi-lo scroll */
56   int                  add;               /* vram increment amount */
57   int                  videoram_addr;         /* videoram address pointer */
58   int                  videoram_addr_latch;   /* videoram address latch */
59   int                  videoram_data_latch;   /* latched videoram data */
60   int                  tile_page;            /* current tile page */
61   int                  sprite_page;         /* current sprite page */
62   int                  back_color;            /* background color */
63   UINT8               *ppu_page[4];         /* ppu pages */
64   int                  nes_vram[8];         /* keep track of 8 .5k vram pages to speed things up */
65   int                  scan_scale;            /* scan scale */
66   int                  scanlines_per_frame;   /* number of scanlines per frame */
67} ppu2c03b_chip;
68
69/* our local copy of the interface */
70static ppu2c03b_interface *intf;
71
72/* chips state - allocated at init time */
73static ppu2c03b_chip *chips = 0;
74
75static void scanline_callback( int num );
76
77void (*ppu_latch)( offs_t offset );
78
79
80/*************************************
81 *
82 *  PPU Palette Initialization
83 *
84 *************************************/
85void ppu2c03b_init_palette( int first_entry ) {
86
87   /* This routine builds a palette using a transformation from */
88   /* the YUV (Y, B-Y, R-Y) to the RGB color space */
89
90   /* The NES has a 64 color palette                        */
91   /* 16 colors, with 4 luminance levels for each color     */
92   /* The 16 colors circle around the YUV color space,      */
93
94   int i,j;
95
96   double R, G, B;
97
98   double tint = .6;
99   double hue = 332.0;
100   double bright_adjust = 1.0;
101
102   static const double brightness[3][4] =
103   {
104      { 0.50, 0.75, 1.0, 1.0 },
105      { 0.29, 0.45, 0.73, 0.9 },
106      { 0, 0.24, 0.47, 0.77 }
107   };
108
109   static const double angle[16] = { 0, 240, 210, 180, 150, 120, 90, 60, 30, 0, 330, 300, 270, 0, 0, 0 };
110
111   /* loop through the 4 intensities */
112   for (i = 0; i < 4; i++)
113   {
114      /* loop through the 16 colors */
115      for (j = 0; j < 16; j++)
116      {
117         double sat;
118         double y;
119         double rad;
120
121         switch (j)
122         {
123            case 0:
124               sat = 0;
125               y = brightness[0][i];
126            break;
127
128            case 13:
129               sat = 0;
130               y = brightness[2][i];
131            break;
132
133            case 14:
134            case 15:
135               sat = 0; y = 0;
136            break;
137
138            default:
139               sat = tint;
140               y = brightness[1][i];
141            break;
142         }
143
144         rad = M_PI * ((angle[j] + hue) / 180.0);
145
146         y *= bright_adjust;
147
148         /* Transform to RGB */
149         R = ( y + sat * sin( rad ) ) * 255.0;
150         G = ( y - ( 27 / 53 ) * sat * sin( rad ) + ( 10 / 53 ) * sat * cos( rad ) ) * 255.0;
151         B = ( y - sat * cos( rad ) ) * 255.0;
152
153         /* Clipping, in case of saturation */
154         if ( R < 0 )
155            R = 0;
156         if ( R > 255 )
157            R = 255;
158         if ( G < 0 )
159            G = 0;
160         if ( G > 255 )
161            G = 255;
162         if ( B < 0 )
163            B = 0;
164         if ( B > 255 )
165            B = 255;
166
167         /* Round, and set the value */
168         palette_set_color(Machine,first_entry++, floor(R+.5), floor(G+.5), floor(B+.5));
169      }
170   }
171
172   /* color tables are modified at run-time, and are initialized on 'ppu2c03b_reset' */
173}
174
175/* the charlayout we use for the chargen */
176static gfx_layout ppu_charlayout =
177{
178   8,8,   /* 8*8 characters */
179   512,   /* 512 characters - modified at runtime */
180   2,      /* 2 bits per pixel */
181   { 8*8, 0 },   /* the two bitplanes are separated */
182   { 0, 1, 2, 3, 4, 5, 6, 7 },
183   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
184   16*8   /* every char takes 16 consecutive bytes */
185};
186
187/*************************************
188 *
189 *  PPU Initialization and Disposal
190 *
191 *************************************/
192void ppu2c03b_init( const ppu2c03b_interface *interface )
193{
194   int i;
195
196   /* keep a local copy of the interface */
197   intf = auto_malloc(sizeof(*interface));
198   memcpy(intf, interface, sizeof(*interface));
199
200   /* safety check */
201   assert_always(intf->num >= 1, "Invalid PPU count\n");
202
203   chips = auto_malloc( intf->num * sizeof( ppu2c03b_chip ) );
204
205   /* intialize our virtual chips */
206   for( i = 0; i < intf->num; i++ )
207   {
208      /* initialize the scanline handling portion */
209      chips[i].scanline_timer = mame_timer_alloc(scanline_callback);
210      chips[i].scanline = 0;
211      chips[i].scan_scale = 1;
212
213      /* allocate a screen bitmap, videoram and spriteram, a dirtychar array and the monochromatic colortable */
214      chips[i].bitmap = auto_bitmap_alloc( VISIBLE_SCREEN_WIDTH, VISIBLE_SCREEN_HEIGHT, Machine->screen[0].format );
215      chips[i].videoram = auto_malloc( VIDEORAM_SIZE );
216      chips[i].spriteram = auto_malloc( SPRITERAM_SIZE );
217      chips[i].dirtychar = auto_malloc( CHARGEN_NUM_CHARS );
218      chips[i].colortable_mono = auto_malloc( sizeof( default_colortable_mono ) );
219
220      /* clear videoram & spriteram */
221      memset( chips[i].videoram, 0, VIDEORAM_SIZE );
222      memset( chips[i].spriteram, 0, SPRITERAM_SIZE );
223
224      /* set all characters dirty */
225      memset( chips[i].dirtychar, 1, CHARGEN_NUM_CHARS );
226
227      /* initialize the video ROM portion, if available */
228      if ( ( intf->vrom_region[i] != REGION_INVALID ) && ( memory_region( intf->vrom_region[i] ) != 0 ) )
229      {
230         /* mark that we have a videorom */
231         chips[i].has_videorom = 1;
232
233         /* find out how many banks */
234         chips[i].videorom_banks = memory_region_length( intf->vrom_region[i] ) / 0x2000;
235
236         /* tweak the layout accordingly */
237         ppu_charlayout.total = chips[i].videorom_banks * CHARGEN_NUM_CHARS;
238      }
239      else
240      {
241         chips[i].has_videorom = chips[i].videorom_banks = 0;
242
243         /* we need to reset this in case of mame running multisession */
244         ppu_charlayout.total = CHARGEN_NUM_CHARS;
245      }
246
247      /* now create the gfx region */
248      {
249         UINT8 *src = chips[i].has_videorom ? memory_region( intf->vrom_region[i] ) : chips[i].videoram;
250         Machine->gfx[intf->gfx_layout_number[i]] = allocgfx( &ppu_charlayout );
251         decodegfx( Machine->gfx[intf->gfx_layout_number[i]], src, 0, Machine->gfx[intf->gfx_layout_number[i]]->total_elements );
252
253         if ( Machine->remapped_colortable )
254            Machine->gfx[intf->gfx_layout_number[i]]->colortable = &Machine->remapped_colortable[intf->color_base[i]];
255
256         Machine->gfx[intf->gfx_layout_number[i]]->total_colors = 8;
257      }
258
259      /* setup our videoram handlers based on mirroring */
260      ppu2c03b_set_mirroring( i, intf->mirroring[i] );
261   }
262}
263
264static void draw_background( const int num, UINT8 *line_priority )
265{
266   /* cache some values locally */
267   mame_bitmap *bitmap = chips[num].bitmap;
268   const int *ppu_regs = &chips[num].regs[0];
269   const int scanline = chips[num].scanline;
270   const int refresh_data = chips[num].refresh_data;
271   const int gfx_bank = intf->gfx_layout_number[num];
272   const int total_elements = Machine->gfx[gfx_bank]->total_elements;
273   const int *nes_vram = &chips[num].nes_vram[0];
274   const int tile_page = chips[num].tile_page;
275   const int char_modulo = Machine->gfx[gfx_bank]->char_modulo;
276   const int line_modulo = Machine->gfx[gfx_bank]->line_modulo;
277   UINT8 *gfx_data = Machine->gfx[gfx_bank]->gfxdata;
278   UINT8 **ppu_page = chips[num].ppu_page;
279   int   start_x = ( chips[num].x_fine ^ 0x07 ) - 7;
280   UINT16 back_pen;
281   UINT16 *dest;
282
283   UINT8 scroll_x_coarse, scroll_y_coarse, scroll_y_fine, color_mask;
284   int x, tile_index, start, i;
285
286   const pen_t *color_table;
287   const pen_t *paldata;
288   const UINT8 *sd;
289
290   int tilecount=0;
291
292   /* setup the color mask and colortable to use */
293   if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO )
294   {
295      color_mask = 0xf0;
296      color_table = chips[num].colortable_mono;
297   }
298   else
299   {
300      color_mask = 0xff;
301      color_table = Machine->gfx[gfx_bank]->colortable;
302   }
303
304   /* cache the background pen */
305   back_pen = Machine->pens[(chips[num].back_color & color_mask)+intf->color_base[num]];
306
307   /* determine where in the nametable to start drawing from */
308   /* based on the current scanline and scroll regs */
309   scroll_x_coarse = refresh_data & 0x1f;
310   scroll_y_coarse = ( refresh_data & 0x3e0 ) >> 5;
311   scroll_y_fine = ( refresh_data & 0x7000 ) >> 12;
312
313   x = scroll_x_coarse;
314
315   /* get the tile index */
316   tile_index = ( ( refresh_data & 0xc00 ) | 0x2000 ) + scroll_y_coarse * 32;
317
318   /* set up dest */
319   dest = ((UINT16 *) bitmap->base) + (bitmap->rowpixels * scanline) + start_x;
320
321   /* draw the 32 or 33 tiles that make up a line */
322   while ( tilecount <34)
323   {
324      int color_byte;
325      int color_bits;
326      int pos;
327      int index1;
328      int page, page2, address;
329      int index2;
330      UINT16 pen;
331
332      index1 = tile_index + x;
333
334      /* Figure out which byte in the color table to use */
335      pos = ( ( index1 & 0x380 ) >> 4 ) | ( ( index1 & 0x1f ) >> 2 );
336      page = (index1 & 0x0c00) >> 10;
337      address = 0x3c0 + pos;
338      color_byte = ppu_page[page][address];
339
340      /* figure out which bits in the color table to use */
341      color_bits = ( ( index1 & 0x40 ) >> 4 ) + ( index1 & 0x02 );
342
343      address = index1 & 0x3ff;
344      page2 = ppu_page[page][address];
345      index2 = nes_vram[ ( page2 >> 6 ) | tile_page ] + ( page2 & 0x3f );
346
347      //27/12/2002
348      if( ppu_latch )
349      {
350         (*ppu_latch)(( tile_page << 10 ) | ( page2 << 4 ));
351      }
352
353      if(start_x < VISIBLE_SCREEN_WIDTH )
354      {
355         paldata = &color_table[ 4 * ( ( ( color_byte >> color_bits ) & 0x03 ) ) ];
356         start = ( index2 % total_elements ) * char_modulo + scroll_y_fine * line_modulo;
357         sd = &gfx_data[start];
358
359         /* render the pixel */
360         for( i = 0; i < 8; i++ )
361         {
362            if ( ( start_x+i ) >= 0 && ( start_x+i ) < VISIBLE_SCREEN_WIDTH )
363            {
364               if ( sd[i] )
365               {
366                  pen = paldata[sd[i]];
367                  line_priority[ start_x+i ] |= 0x02;
368               }
369               else
370               {
371                  pen = back_pen;
372               }
373               *dest = pen;
374            }
375            dest++;
376         }
377
378         start_x += 8;
379
380         /* move to next tile over and toggle the horizontal name table if necessary */
381         x++;
382         if ( x > 31 )
383         {
384            x = 0;
385            tile_index ^= 0x400;
386         }
387      }
388      tilecount++;
389   }
390   /* if the left 8 pixels for the background are off, blank 'em */
391   if ( !( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND_L8 ) )
392   {
393      dest = ((UINT16 *) bitmap->base) + (bitmap->rowpixels * scanline);
394      for( i = 0; i < 8; i++ )
395      {
396         *(dest++) = back_pen;
397         line_priority[ i ] ^= 0x02;
398      }
399   }
400   /* done updating, whew */
401}
402
403static void draw_sprites( const int num, UINT8 *line_priority )
404{
405   /* cache some values locally */
406   mame_bitmap *bitmap = chips[num].bitmap;
407   const int scanline = chips[num].scanline;
408   const int gfx_bank = intf->gfx_layout_number[num];
409   const int total_elements = Machine->gfx[gfx_bank]->total_elements;
410   const int sprite_page = chips[num].sprite_page;
411   const int char_modulo = Machine->gfx[gfx_bank]->char_modulo;
412   const int line_modulo = Machine->gfx[gfx_bank]->line_modulo;
413   const UINT8 *sprites = chips[num].spriteram;
414   pen_t *color_table = Machine->gfx[gfx_bank]->colortable;
415   UINT8 *gfx_data = Machine->gfx[gfx_bank]->gfxdata;
416   int *ppu_regs = &chips[num].regs[0];
417
418   int x,y, i;
419   int tile, index1, page;
420   int pri;
421
422   int flipx, flipy, color;
423   int size;
424   int spriteCount = 0;
425   int sprite_line;
426   int drawn;
427   int start;
428
429   int first_pixel;
430
431   const pen_t *paldata;
432   const UINT8 *sd;
433
434   /* determine if the sprites are 8x8 or 8x16 */
435   size = ( ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_SPRITE_SIZE ) ? 16 : 8;
436
437   first_pixel= (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES_L8)? 0: 8;
438
439   for( i = 0; i < SPRITERAM_SIZE; i += 4 ) {
440      y = sprites[i] + 1;
441
442      /* if the sprite isn't visible, skip it */
443      if ( ( y + size <= scanline ) || ( y > scanline ) )
444         continue;
445
446      /* clear our drawn flag */
447      drawn = 0;
448
449      x = sprites[i+3];
450      tile = sprites[i+1];
451      color = ( sprites[i+2] & 0x03 ) + 4;
452      pri = sprites[i+2] & 0x20;
453      flipx = sprites[i+2] & 0x40;
454      flipy = sprites[i+2] & 0x80;
455
456      if ( size == 16 ) {
457         /* if it's 8x16 and odd-numbered, draw the other half instead */
458         if ( tile & 0x01 )
459         {
460            tile &= ~0x01;
461            tile |= 0x100;
462         }
463         /* note that the sprite page value has no effect on 8x16 sprites */
464         page = tile >> 6;
465      } else
466         page = ( tile >> 6 ) | sprite_page;
467
468
469      index1 = chips[num].nes_vram[page] + ( tile & 0x3f );
470
471      //27/12/2002
472      if ( ppu_latch )
473         (*ppu_latch)(( sprite_page << 10 ) | ( (tile & 0xff) << 4 ));
474
475      /* compute the character's line to draw */
476      sprite_line = scanline - y;
477
478      if ( flipy )
479         sprite_line = ( size - 1 ) - sprite_line;
480
481      paldata = &color_table[4 * color];
482      start = ( index1 % total_elements ) * char_modulo + sprite_line * line_modulo;
483      sd = &gfx_data[start];
484
485      if ( pri )
486      {
487         /* draw the low-priority sprites */
488         int j;
489
490         if ( flipx )
491         {
492            for ( j = 0; j < 8; j++ )
493            {
494               /* is this pixel non-transparent? */
495               if ( sd[7-j] && ((x+j)>= first_pixel))
496               {
497                  /* has the background (or another sprite) already been drawn here? */
498                  if ( !line_priority[ x + j ] )
499                  {
500                     /* no, draw */
501                     if ( ( x + j ) < VISIBLE_SCREEN_WIDTH )
502                        *BITMAP_ADDR16(bitmap, scanline, x + j) = paldata[ sd[7-j] ];
503                     drawn = 1;
504                  }
505                  /* indicate that a sprite was drawn at this location, even if it's not seen */
506                  if ( ( x + j ) < VISIBLE_SCREEN_WIDTH )
507                     line_priority[ x + j ] |= 0x01;
508
509                  /* set the "sprite 0 hit" flag if appropriate */
510                  if ( i == 0 && ((x+j)<255) && ( line_priority[ x + j ] & 0x02 ))
511                     ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
512               }
513            }
514         }
515         else
516         {
517            for ( j = 0; j < 8; j++ )
518            {
519               /* is this pixel non-transparent? */
520               if ( sd[j] && ((x+j)>= first_pixel))
521               {
522                  /* has the background (or another sprite) already been drawn here? */
523                  if ( !line_priority[ x + j ] )
524                  {
525                     /* no, draw */
526                     if ( ( x + j ) < VISIBLE_SCREEN_WIDTH )
527                        *BITMAP_ADDR16(bitmap, scanline, x + j) = paldata[ sd[j] ];
528                     drawn = 1;
529                  }
530                  /* indicate that a sprite was drawn at this location, even if it's not seen */
531                  if ( ( x + j ) < VISIBLE_SCREEN_WIDTH )
532                     line_priority[ x + j ] |= 0x01;
533
534                  /* set the "sprite 0 hit" flag if appropriate */
535                  if ( i == 0 && ((x+j)<255) && ( line_priority[ x + j ] & 0x02 ))
536                     ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
537               }
538            }
539         }
540      }
541      else
542      {
543         /* draw the high-priority sprites */
544         int j;
545
546         if ( flipx )
547         {
548            for ( j = 0; j < 8; j++ )
549            {
550               /* is this pixel non-transparent? */
551               if ( sd[7-j] && ((x+j)>= first_pixel))
552               {
553                  /* has another sprite been drawn here? */
554                  if ( !( line_priority[ x + j ] & 0x01 ) )
555                  {
556                     /* no, draw */
557                     if ( ( x + j ) < VISIBLE_SCREEN_WIDTH )
558                     {
559                        *BITMAP_ADDR16(bitmap, scanline, x + j) = paldata[ sd[7-j] ];
560                        line_priority[ x + j ] |= 0x01;
561                     }
562                     drawn = 1;
563                  }
564
565                  /* set the "sprite 0 hit" flag if appropriate */
566                  if ( ( i == 0 ) && ((x+j)<255) && ( line_priority[ x + j ] & 0x02 ) )
567                     ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
568               }
569            }
570         }
571         else
572         {
573            for ( j = 0; j < 8; j++ )
574            {
575               /* is this pixel non-transparent? */
576               if ( sd[j] && ((x+j)>= first_pixel))
577               {
578                  /* has another sprite been drawn here? */
579                  if ( !( line_priority[ x + j ] & 0x01 ) )
580                  {
581                     /* no, draw */
582                     if ( ( x + j ) < VISIBLE_SCREEN_WIDTH )
583                     {
584                        *BITMAP_ADDR16(bitmap, scanline, x + j) = paldata[ sd[j] ];
585                        line_priority[ x + j ] |= 0x01;
586                     }
587                     drawn = 1;
588                  }
589
590                  /* set the "sprite 0 hit" flag if appropriate */
591                  if ( ( i == 0 ) && ((x+j)<255) && ( line_priority[ x + j ] & 0x02 ) )
592                     ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
593               }
594            }
595         }
596      }
597
598      if ( drawn )
599      {
600         /* if there are more than 8 sprites on this line, set the flag */
601         spriteCount++;
602         if ( spriteCount == 8 )
603         {
604            ppu_regs[PPU_STATUS] |= PPU_STATUS_8SPRITES;
605            logerror ("> 8 sprites, scanline: %d\n", scanline);
606
607            /* the real NES only draws up to 8 sprites - the rest should be invisible */
608            break;
609         }
610      }
611   }
612}
613
614/*************************************
615 *
616 *  Scanline Rendering and Update
617 *
618 *************************************/
619static void render_scanline( int num )
620{
621   UINT8   line_priority[VISIBLE_SCREEN_WIDTH];
622   int      *ppu_regs = &chips[num].regs[0];
623//  int     i;
624   int      refresh_data = chips[num].refresh_data;
625
626   /* lets see how long it takes */
627   profiler_mark(PROFILER_USER1+num);
628
629   /* clear the line priority for this scanline */
630   memset( line_priority, 0, VISIBLE_SCREEN_WIDTH );
631
632   /* clear the sprite count for this line */
633   ppu_regs[PPU_STATUS] &= ~PPU_STATUS_8SPRITES;
634
635   /* see if we need to render the background */
636   if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND )
637      draw_background( num, line_priority );
638
639   /* if sprites are on, draw them */
640   if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES )
641      draw_sprites( num, line_priority );
642
643   /* increment the fine y-scroll */
644   refresh_data += 0x1000;
645
646   /* if it's rolled, increment the coarse y-scroll */
647   if ( refresh_data & 0x8000 )
648   {
649      UINT16 tmp;
650      tmp = ( refresh_data & 0x03e0 ) + 0x20;
651      refresh_data &= 0x7c1f;
652      /* handle bizarro scrolling rollover at the 30th (not 32nd) vertical tile */
653      if ( tmp == 0x03c0 )
654      {
655         refresh_data ^= 0x0800;
656      }
657      else
658      {
659         refresh_data |= ( tmp & 0x03e0 );
660      }
661    }
662
663    chips[num].refresh_data = refresh_data;
664
665    /* done updating, whew */
666   profiler_mark(PROFILER_END);
667}
668
669static void update_scanline( int num )
670{
671   int scanline = chips[num].scanline;
672   int *ppu_regs = &chips[num].regs[0];
673
674   if ( scanline <= BOTTOM_VISIBLE_SCANLINE ) {
675      /* If background or sprites are enabled, copy the ppu address latch */
676      if ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) )
677      {
678         /* Copy only the scroll x-coarse and the x-overflow bit */
679         chips[num].refresh_data &= ~0x041f;
680         chips[num].refresh_data |= ( chips[num].refresh_latch & 0x041f );
681      }
682
683#if 0   /* hmm... this only goes if we implement the osd_skip_this_frame functionality */
684
685      /* check for sprite 0 hit */
686      if ( ( scanline == spriteram[0] + 7 ) && ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES ) )
687         ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
688
689#endif
690
691      /* Render this scanline if appropriate */
692      if ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) )
693         render_scanline( num );
694   }
695
696   /* Note: this routine is called at the _end_ of each scanline */
697   if ( scanline == BOTTOM_VISIBLE_SCANLINE )
698   {
699      /* We just entered VBLANK */
700      ppu_regs[PPU_STATUS] |= PPU_STATUS_VBLANK;
701   }
702
703   /* If NMI's are set to be triggered, go for it */
704   if ( ( scanline == NMI_SCANLINE-1 ) && ( ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_NMI ) )
705   {
706      if ( intf->nmi_handler[num] )
707         (*intf->nmi_handler[num])( num, ppu_regs );
708   }
709}
710
711static void scanline_callback( int num )
712{
713   int *ppu_regs = &chips[num].regs[0];
714   int i;
715   int blanked = ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) ) == 0;
716   int vblank = ( ppu_regs[PPU_STATUS] & PPU_STATUS_VBLANK ) ? 1 : 0;
717
718/*  logerror("SCANLINE CALLBACK %d\n",chips[num].scanline); */
719
720   /* if a callback is available, call it */
721   if ( chips[num].scanline_callback_proc )
722      (*chips[num].scanline_callback_proc)( num, chips[num].scanline, vblank, blanked );
723
724   /* update the scanline that just went by */
725   update_scanline( num );
726
727   /* increment our scanline count */
728   chips[num].scanline++;
729
730   /* decode any dirty chars if we're using vram */
731
732   /* first, check the master dirty char flag */
733   if ( !chips[num].has_videorom && chips[num].chars_are_dirty )
734   {
735      /* cache some values */
736      UINT8 *dirtyarray = chips[num].dirtychar;
737      UINT8 *vram = chips[num].videoram;
738      gfx_element *gfx = Machine->gfx[intf->gfx_layout_number[num]];
739
740      /* then iterate and decode */
741      for( i = 0; i < CHARGEN_NUM_CHARS; i++ )
742      {
743         if ( dirtyarray[i] )
744         {
745            decodechar( gfx, i, vram, &ppu_charlayout);
746            dirtyarray[i] = 0;
747         }
748      }
749
750      chips[num].chars_are_dirty = 0;
751   }
752
753   /* see if we rolled */
754   if ( chips[num].scanline >= chips[num].scanlines_per_frame )
755   {
756      /* clear the vblank & sprite hit flag */
757      ppu_regs[PPU_STATUS] &= ~( PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT );
758
759      /* if background or sprites are enabled, copy the ppu address latch */
760      if ( !blanked )
761         chips[num].refresh_data = chips[num].refresh_latch;
762
763      /* reset the scanline count */
764      chips[num].scanline = 0;
765   }
766
767   /* setup our next stop here */
768   mame_timer_adjust(chips[num].scanline_timer, video_screen_get_time_until_pos(0, chips[num].scanline * chips[num].scan_scale, 0), num, 0);
769}
770
771/*************************************
772 *
773 *  PPU Reset
774 *
775 *************************************/
776void ppu2c03b_reset( int num, int scan_scale )
777{
778   int i;
779
780   /* check bounds */
781   if ( num >= intf->num )
782   {
783      logerror( "PPU(reset): Attempting to access an unmapped chip\n" );
784      return;
785   }
786
787   /* reset the scanline count */
788   chips[num].scanline = 0;
789
790   /* set the scan scale (this is for dual monitor vertical setups) */
791   chips[num].scan_scale = scan_scale;
792
793   /* allocate the scanline timer - start at scanline 0 */
794   mame_timer_adjust(chips[num].scanline_timer, video_screen_get_time_until_pos(0, 0, 0), num, 0);
795
796   /* reset the callbacks */
797   chips[num].scanline_callback_proc = 0;
798   chips[num].vidaccess_callback_proc = 0;
799
800   for( i = 0; i < PPU_MAX_REG; i++ )
801      chips[num].regs[i] = 0;
802
803   /* initialize the rest of the members */
804   chips[num].refresh_data = 0;
805   chips[num].refresh_latch = 0;
806   chips[num].x_fine = 0;
807   chips[num].toggle = 0;
808   chips[num].add = 1;
809   chips[num].videoram_addr = 0;
810   chips[num].videoram_addr_latch = 0;
811   chips[num].videoram_data_latch = 0;
812   chips[num].tile_page = 0;
813   chips[num].sprite_page = 0;
814   chips[num].back_color = 0;
815   chips[num].chars_are_dirty = 1;
816   chips[num].scanlines_per_frame = 262;   /* default */
817
818   /* initialize the color tables */
819   {
820      int color_base = intf->color_base[num];
821
822      for( i = 0; i < ( sizeof( default_colortable_mono ) / sizeof( default_colortable_mono[0] ) ); i++ )
823      {
824         /* monochromatic table */
825         chips[num].colortable_mono[i] = Machine->pens[default_colortable_mono[i] + color_base];
826
827         /* color table */
828         Machine->gfx[intf->gfx_layout_number[num]]->colortable[i] = Machine->pens[default_colortable_mono[i] + color_base];
829      }
830   }
831
832   /* set the vram bank-switch values to the default */
833   for( i = 0; i < 8; i++ )
834      chips[num].nes_vram[i] = i * 64;
835
836   if ( chips[num].has_videorom )
837      ppu2c03b_set_videorom_bank( num, 0, 8, 0, 512 );
838}
839
840
841/*************************************
842 *
843 *  PPU Registers Read
844 *
845 *************************************/
846int ppu2c03b_r( int num, int offset )
847{
848   int ret = 0;
849
850   /* check bounds */
851   if ( num >= intf->num )
852   {
853      logerror( "PPU %d(r): Attempting to access an unmapped chip\n", num );
854      return 0;
855   }
856
857   if ( offset >= PPU_MAX_REG )
858   {
859      logerror( "PPU %d(r): Attempting to read past the chip\n", num );
860
861      offset &= PPU_MAX_REG - 1;
862/*      return 0; */
863   }
864
865   /* now, see wich register to read */
866   switch( offset & 7 )
867   {
868      case PPU_STATUS:
869         ret = chips[num].regs[PPU_STATUS];
870
871         /* this is necessary */
872         chips[num].toggle = 0;
873
874         /* note that we don't clear the vblank flag - this is correct. */
875      break;
876
877      case PPU_SPRITE_DATA:
878         ret = chips[num].spriteram[chips[num].regs[PPU_SPRITE_ADDRESS]];
879      break;
880
881      case PPU_DATA:
882         if (  chips[num].videoram_addr >= 0x3f00  )
883            ret = chips[num].videoram[chips[num].videoram_addr&0x3F1F];
884         else ret = chips[num].videoram_data_latch;
885
886         //27/12/2002
887         if ( ppu_latch )
888            (*ppu_latch)( chips[num].videoram_addr & 0x3fff );
889
890         //was 3fef, but if it's trying palette ram compensation, it should have been 3eff, and the actual filling of the latch would be wrong...?
891         if ( ( chips[num].videoram_addr >= 0x2000 ) && ( chips[num].videoram_addr <= 0x3fff ) )
892            chips[num].videoram_data_latch = chips[num].ppu_page[ ( chips[num].videoram_addr & 0xc00) >> 10][ chips[num].videoram_addr & 0x3ff ];
893         else
894            chips[num].videoram_data_latch = chips[num].videoram[ chips[num].videoram_addr & 0x3fff ];
895
896         chips[num].videoram_addr += chips[num].add;
897      break;
898
899      default:
900         /* ignore other register reads */
901      break;
902   }
903
904   return ret;
905}
906
907
908/*************************************
909 *
910 *  PPU Registers Write
911 *
912 *************************************/
913void ppu2c03b_w( int num, int offset, int data )
914{
915
916   /* check bounds */
917   if ( num >= intf->num )
918   {
919      logerror( "PPU(w): Attempting to access an unmapped chip\n" );
920      return;
921   }
922
923   if ( offset >= PPU_MAX_REG )
924   {
925      logerror( "PPU: Attempting to write past the chip\n" );
926
927      offset &= PPU_MAX_REG - 1;
928/*      return; */
929   }
930
931   switch( offset & 7 )
932   {
933      case PPU_CONTROL0:
934         chips[num].regs[PPU_CONTROL0] = data;
935
936         /* update the name table number on our refresh latches */
937         chips[num].refresh_latch &= ~0x0c00;
938         chips[num].refresh_latch |= ( data & 3 ) << 10;
939
940         /* the char ram bank points either 0x0000 or 0x1000 (page 0 or page 4) */
941         chips[num].tile_page = ( data & PPU_CONTROL0_CHR_SELECT ) >> 2;
942         chips[num].sprite_page = ( data & PPU_CONTROL0_SPR_SELECT ) >> 1;
943
944         chips[num].add = ( data & PPU_CONTROL0_INC ) ? 32 : 1;
945      break;
946
947      case PPU_CONTROL1:
948         /* if color intensity has changed, change all the pens */
949         if ( ( data & 0xe0 ) != ( chips[num].regs[PPU_CONTROL1] & 0xe0 ) )
950         {
951            /* TODO? : maybe add support for COLOR_INTENSITY later? */
952         }
953
954         chips[num].regs[PPU_CONTROL1] = data;
955      break;
956
957      case PPU_SPRITE_ADDRESS:
958         chips[num].regs[PPU_SPRITE_ADDRESS] = data & 0xff;
959      break;
960
961      case PPU_SPRITE_DATA:
962         chips[num].spriteram[chips[num].regs[PPU_SPRITE_ADDRESS]] = data;
963         chips[num].regs[PPU_SPRITE_ADDRESS] = ( chips[num].regs[PPU_SPRITE_ADDRESS] + 1 ) & 0xff;
964      break;
965
966      case PPU_SCROLL:
967         if ( chips[num].toggle )
968         {
969            /* second write */
970            chips[num].refresh_latch &= ~0x03e0;
971            chips[num].refresh_latch |= ( data & 0xf8 ) << 2;
972
973            chips[num].refresh_latch &= ~0x7000;
974            chips[num].refresh_latch |= ( data & 0x07 ) << 12;
975         }
976         else
977         {
978            /* first write */
979            chips[num].refresh_latch &= ~0x1f;
980            chips[num].refresh_latch |= (data & 0xf8) >> 3;
981
982            chips[num].x_fine = data & 7;
983         }
984
985         chips[num].toggle ^= 1;
986      break;
987
988      case PPU_ADDRESS:
989         if ( chips[num].toggle )
990         {
991            /* second write */
992            chips[num].videoram_addr = ( chips[num].videoram_addr_latch << 8 ) | ( data & 0xff );
993
994            chips[num].refresh_latch &= ~0x00ff;
995            chips[num].refresh_latch |= data & 0xff;
996            chips[num].refresh_data = chips[num].refresh_latch;
997         }
998         else
999         {
1000            /* first write */
1001            chips[num].videoram_addr_latch = data & 0xff;
1002
1003            if ( data != 0x3f ) /* TODO: remove this hack! */
1004            {
1005               chips[num].refresh_latch &= ~0xff00;
1006               chips[num].refresh_latch |= ( data & 0x3f ) << 8;
1007            }
1008         }
1009
1010         chips[num].toggle ^= 1;
1011      break;
1012
1013      case PPU_DATA:
1014         {
1015            int tempAddr = chips[num].videoram_addr & 0x3fff;
1016
1017            //27/12/2002
1018            if ( ppu_latch )
1019               (*ppu_latch)( tempAddr );
1020
1021            /* if there's a callback, call it now */
1022            if ( chips[num].vidaccess_callback_proc )
1023               data = (*chips[num].vidaccess_callback_proc)( num, tempAddr, data );
1024
1025            /* see if it's on the chargen portion */
1026            if ( tempAddr < 0x2000 )
1027            {
1028               /* if we have a videorom mapped there, dont write and log the problem */
1029               if ( chips[num].has_videorom )
1030               {
1031                  /* if there is a vidaccess callback, assume it coped up with it */
1032                  if ( chips[num].vidaccess_callback_proc == 0 )
1033                     logerror( "PPU: Attempting to write to the chargen, when there's a ROM there!\n" );
1034               }
1035               else
1036               {
1037                  /* store the data */
1038                  chips[num].videoram[tempAddr] = data;
1039
1040                  /* setup the master dirty switch */
1041                  chips[num].chars_are_dirty = 1;
1042
1043                  /* mark the char dirty */
1044                  chips[num].dirtychar[tempAddr >> 4] = 1;
1045               }
1046
1047               /* increment the address */
1048               chips[num].videoram_addr += chips[num].add;
1049
1050               /* and be gone */
1051               break;
1052            }
1053
1054            /* the only valid background colors are writes to 0x3f00 and 0x3f10         */
1055            /* and even then, they are mirrors of each other. as usual, some games      */
1056            /* attempt to write values > the number of colors so we must mask the data. */
1057            if ( tempAddr >= 0x3f00 )
1058            {
1059               int color_base = intf->color_base[num];
1060
1061               /* store the data */
1062               if(tempAddr&0x3)
1063                  chips[num].videoram[tempAddr&0x3F1F] = data;
1064               else
1065               {
1066                  chips[num].videoram[0x3F10+(tempAddr&0xF)] = data;
1067                  chips[num].videoram[0x3F00+(tempAddr&0xF)] = data;
1068               }
1069
1070               data &= 0x3f;
1071
1072               if ( tempAddr & 0x03 )
1073               {
1074                  Machine->gfx[intf->gfx_layout_number[num]]->colortable[ tempAddr & 0x1f ] = Machine->pens[color_base+data];
1075                  chips[num].colortable_mono[tempAddr & 0x1f] = Machine->pens[color_base+(data & 0xf0)];
1076               }
1077
1078               if ( ( tempAddr & 0x0f ) == 0 )
1079               {
1080                  int i;
1081
1082                  chips[num].back_color = data;
1083                  for( i = 0; i < 32; i += 4 )
1084                  {
1085                     Machine->gfx[intf->gfx_layout_number[num]]->colortable[ i ] = Machine->pens[color_base+data];
1086                     chips[num].colortable_mono[i] = Machine->pens[color_base+(data & 0xf0)];
1087                  }
1088               }
1089
1090               /* increment the address */
1091               chips[num].videoram_addr += chips[num].add;
1092
1093               /* and be gone */
1094               break;
1095            }
1096
1097            /* everything else */
1098            /* writes to $3000-$3eff are mirrors of $2000-$2eff */
1099            {
1100               int page = ( tempAddr & 0x0c00) >> 10;
1101               int address = tempAddr & 0x3ff;
1102
1103               chips[num].ppu_page[page][address] = data;
1104
1105               /* increment the address */
1106               chips[num].videoram_addr += chips[num].add;
1107
1108               /* fall through */
1109            }
1110         }
1111      break;
1112
1113      default:
1114         /* ignore other registers writes */
1115      break;
1116   }
1117}
1118
1119/*************************************
1120 *
1121 *  Sprite DMA
1122 *
1123 *************************************/
1124void ppu2c03b_spriteram_dma(const UINT8 page )
1125{
1126   int i;
1127   int address=page<<8;
1128   //should last 513 CPU cycles.
1129
1130   for(i=0;i<SPRITERAM_SIZE;i++)
1131   {
1132      UINT8 t=program_read_byte_8(address+i);
1133      program_write_byte_8(0x2000+PPU_SPRITE_DATA, t);
1134   }
1135   activecpu_adjust_icount(-513);
1136}
1137
1138/*************************************
1139 *
1140 *  PPU Rendering
1141 *
1142 *************************************/
1143void ppu2c03b_render( int num, mame_bitmap *bitmap, int flipx, int flipy, int sx, int sy )
1144{
1145   /* check bounds */
1146   if ( num >= intf->num )
1147   {
1148      logerror( "PPU(render): Attempting to access an unmapped chip\n" );
1149      return;
1150   }
1151
1152/*  logerror("PPU %d:VBLANK HIT (scanline %d)\n",num, chips[num].scanline); */
1153
1154   copybitmap( bitmap, chips[num].bitmap, flipx, flipy, sx, sy, 0, TRANSPARENCY_NONE, 0 );
1155}
1156
1157/*************************************
1158 *
1159 *  PPU VideoROM banking
1160 *
1161 *************************************/
1162void ppu2c03b_set_videorom_bank( int num, int start_page, int num_pages, int bank, int bank_size )
1163{
1164   int i;
1165
1166   /* check bounds */
1167   if ( num >= intf->num )
1168   {
1169      logerror( "PPU(set vrom bank): Attempting to access an unmapped chip\n" );
1170      return;
1171   }
1172
1173   if ( !chips[num].has_videorom )
1174   {
1175      logerror( "PPU(set vrom bank): Attempting to switch videorom banks and no rom is mapped\n" );
1176      return;
1177   }
1178
1179   bank &= ( chips[num].videorom_banks * ( CHARGEN_NUM_CHARS / bank_size ) ) - 1;
1180
1181   for( i = start_page; i < ( start_page + num_pages ); i++ )
1182      chips[num].nes_vram[i] = bank * bank_size + 64 * ( i - start_page );
1183
1184   {
1185      int vram_start = start_page * 0x400;
1186      int count = num_pages * 0x400;
1187      int rom_start = bank * bank_size * 16;
1188
1189      memcpy( &chips[num].videoram[vram_start], &memory_region( intf->vrom_region[num] )[rom_start], count );
1190   }
1191}
1192
1193/*************************************
1194 *
1195 *  Utility functions
1196 *
1197 *************************************/
1198int ppu2c03b_get_pixel( int num, int x, int y )
1199{
1200   /* check bounds */
1201   if ( num >= intf->num )
1202   {
1203      logerror( "PPU(get_pixel): Attempting to access an unmapped chip\n" );
1204      return 0;
1205   }
1206
1207   if ( x >= VISIBLE_SCREEN_WIDTH )
1208      x = VISIBLE_SCREEN_WIDTH - 1;
1209
1210   if ( y >= VISIBLE_SCREEN_HEIGHT )
1211      y = VISIBLE_SCREEN_HEIGHT - 1;
1212
1213   return *BITMAP_ADDR16(chips[num].bitmap, y, x);
1214}
1215
1216int ppu2c03b_get_colorbase( int num )
1217{
1218   /* check bounds */
1219   if ( num >= intf->num )
1220   {
1221      logerror( "PPU(get_colorbase): Attempting to access an unmapped chip\n" );
1222      return 0;
1223   }
1224
1225   return intf->color_base[num];
1226}
1227
1228void ppu2c03b_set_mirroring( int num, int mirroring )
1229{
1230   /* check bounds */
1231   if ( num >= intf->num )
1232   {
1233      logerror( "PPU(get_colorbase): Attempting to access an unmapped chip\n" );
1234      return;
1235   }
1236
1237   /* setup our videoram handlers based on mirroring */
1238   switch( mirroring )
1239   {
1240      case PPU_MIRROR_VERT:
1241         chips[num].ppu_page[0] = &(chips[num].videoram[0x2000]);
1242         chips[num].ppu_page[1] = &(chips[num].videoram[0x2400]);
1243         chips[num].ppu_page[2] = &(chips[num].videoram[0x2000]);
1244         chips[num].ppu_page[3] = &(chips[num].videoram[0x2400]);
1245      break;
1246
1247      case PPU_MIRROR_HORZ:
1248         chips[num].ppu_page[0] = &(chips[num].videoram[0x2000]);
1249         chips[num].ppu_page[1] = &(chips[num].videoram[0x2000]);
1250         chips[num].ppu_page[2] = &(chips[num].videoram[0x2400]);
1251         chips[num].ppu_page[3] = &(chips[num].videoram[0x2400]);
1252      break;
1253
1254      case PPU_MIRROR_HIGH:
1255         chips[num].ppu_page[0] = &(chips[num].videoram[0x2400]);
1256         chips[num].ppu_page[1] = &(chips[num].videoram[0x2400]);
1257         chips[num].ppu_page[2] = &(chips[num].videoram[0x2400]);
1258         chips[num].ppu_page[3] = &(chips[num].videoram[0x2400]);
1259      break;
1260
1261      case PPU_MIRROR_LOW:
1262         chips[num].ppu_page[0] = &(chips[num].videoram[0x2000]);
1263         chips[num].ppu_page[1] = &(chips[num].videoram[0x2000]);
1264         chips[num].ppu_page[2] = &(chips[num].videoram[0x2000]);
1265         chips[num].ppu_page[3] = &(chips[num].videoram[0x2000]);
1266      break;
1267
1268      case PPU_MIRROR_NONE:
1269      default:
1270         chips[num].ppu_page[0] = &(chips[num].videoram[0x2000]);
1271         chips[num].ppu_page[1] = &(chips[num].videoram[0x2400]);
1272         chips[num].ppu_page[2] = &(chips[num].videoram[0x2800]);
1273         chips[num].ppu_page[3] = &(chips[num].videoram[0x2c00]);
1274      break;
1275   }
1276}
1277
1278void ppu2c03b_set_nmi_callback( int num, ppu2c03b_nmi_cb cb )
1279{
1280   /* check bounds */
1281   if ( num >= intf->num )
1282   {
1283      logerror( "PPU(set_nmi_callback): Attempting to access an unmapped chip\n" );
1284      return;
1285   }
1286
1287   intf->nmi_handler[num] = cb;
1288}
1289
1290void ppu2c03b_set_scanline_callback( int num, ppu2c03b_scanline_cb cb )
1291{
1292   /* check bounds */
1293   if ( num >= intf->num )
1294   {
1295      logerror( "PPU(set_scanline_callback): Attempting to access an unmapped chip\n" );
1296      return;
1297   }
1298
1299   chips[num].scanline_callback_proc = cb;
1300}
1301
1302void ppu2c03b_set_vidaccess_callback( int num, ppu2c03b_vidaccess_cb cb )
1303{
1304   /* check bounds */
1305   if ( num >= intf->num )
1306   {
1307      logerror( "PPU(set_vidaccess_callback): Attempting to access an unmapped chip\n" );
1308      return;
1309   }
1310
1311   chips[num].vidaccess_callback_proc = cb;
1312}
1313
1314void ppu2c03b_set_scanlines_per_frame( int num, int scanlines )
1315{
1316   /* check bounds */
1317   if ( num >= intf->num )
1318   {
1319      logerror( "PPU(set_scanlines_per_frame): Attempting to access an unmapped chip\n" );
1320      return;
1321   }
1322
1323   chips[num].scanlines_per_frame = scanlines;
1324}
1325
1326/*************************************
1327 *
1328 *  Accesors
1329 *
1330 *************************************/
1331
1332READ8_HANDLER( ppu2c03b_0_r )
1333{
1334   return ppu2c03b_r( 0, offset );
1335}
1336
1337READ8_HANDLER( ppu2c03b_1_r )
1338{
1339   return ppu2c03b_r( 1, offset );
1340}
1341
1342WRITE8_HANDLER( ppu2c03b_0_w )
1343{
1344   ppu2c03b_w( 0, offset, data );
1345}
1346
1347WRITE8_HANDLER( ppu2c03b_1_w )
1348{
1349   ppu2c03b_w( 1, offset, data );
1350}
src/mame/video/ppu2c03b.h
r1046r1047
1/******************************************************************************
2
3    Nintendo 2C03B PPU emulation.
4
5    Written by Ernesto Corvi.
6    This code is heavily based on Brad Oliver's MESS implementation.
7
8******************************************************************************/
9#ifndef __PPU_2C03B_H__
10#define __PPU_2C03B_H__
11
12#include "driver.h"
13
14/* increment to use more chips */
15#define MAX_PPU 2
16
17/* mirroring types */
18#define PPU_MIRROR_NONE      0
19#define PPU_MIRROR_VERT      1
20#define PPU_MIRROR_HORZ      2
21#define PPU_MIRROR_HIGH      3
22#define PPU_MIRROR_LOW      4
23
24/* registers definition */
25enum {
26   PPU_CONTROL0 = 0,
27   PPU_CONTROL1,
28   PPU_STATUS,
29   PPU_SPRITE_ADDRESS,
30   PPU_SPRITE_DATA,
31   PPU_SCROLL,
32   PPU_ADDRESS,
33   PPU_DATA,
34   PPU_MAX_REG
35};
36
37/* bit definitions for (some of) the registers */
38enum {
39   PPU_CONTROL0_INC         = 0x04,
40   PPU_CONTROL0_SPR_SELECT      = 0x08,
41   PPU_CONTROL0_CHR_SELECT      = 0x10,
42   PPU_CONTROL0_SPRITE_SIZE   = 0x20,
43   PPU_CONTROL0_NMI         = 0x80,
44
45   PPU_CONTROL1_DISPLAY_MONO   = 0x01,
46   PPU_CONTROL1_BACKGROUND_L8   = 0x02,
47   PPU_CONTROL1_SPRITES_L8      = 0x04,
48   PPU_CONTROL1_BACKGROUND      = 0x08,
49   PPU_CONTROL1_SPRITES      = 0x10,
50
51   PPU_STATUS_8SPRITES         = 0x20,
52   PPU_STATUS_SPRITE0_HIT      = 0x40,
53   PPU_STATUS_VBLANK         = 0x80
54};
55
56/* callback datatypes */
57typedef void (*ppu2c03b_scanline_cb)( int num, int scanline, int vblank, int blanked );
58typedef void (*ppu2c03b_nmi_cb)( int num, int *ppu_regs );
59typedef int  (*ppu2c03b_vidaccess_cb)( int num, int address, int data );
60
61typedef struct _ppu2c03b_interface ppu2c03b_interface;
62struct _ppu2c03b_interface
63{
64   int            num;                     /* number of chips ( 1 to MAX_PPU ) */
65   int            vrom_region[MAX_PPU];         /* region id of gfx vrom (or REGION_INVALID if none) */
66   int            gfx_layout_number[MAX_PPU];      /* gfx layout number used by each chip */
67   int            color_base[MAX_PPU];         /* color base to use per ppu */
68   int            mirroring[MAX_PPU];            /* mirroring options (PPU_MIRROR_* flag) */
69   ppu2c03b_nmi_cb   nmi_handler[MAX_PPU];         /* NMI handler */
70};
71
72/* routines */
73void ppu2c03b_init_palette( int first_entry );
74void ppu2c03b_init( const ppu2c03b_interface *interface );
75
76void ppu2c03b_reset( int num, int scan_scale );
77void ppu2c03b_set_videorom_bank( int num, int start_page, int num_pages, int bank, int bank_size );
78void ppu2c03b_spriteram_dma(const UINT8 page );
79void ppu2c03b_render( int num, mame_bitmap *bitmap, int flipx, int flipy, int sx, int sy );
80int ppu2c03b_get_pixel( int num, int x, int y );
81int ppu2c03b_get_colorbase( int num );
82void ppu2c03b_set_mirroring( int num, int mirroring );
83void ppu2c03b_set_scanline_callback( int num, ppu2c03b_scanline_cb cb );
84void ppu2c03b_set_vidaccess_callback( int num, ppu2c03b_vidaccess_cb cb );
85void ppu2c03b_set_scanlines_per_frame( int num, int scanlines );
86
87//27/12/2002
88extern void (*ppu_latch)( offs_t offset );
89
90void ppu2c03b_w( int num, int offset, int data );
91int ppu2c03b_r( int num, int offset );
92
93/* accesors */
94READ8_HANDLER( ppu2c03b_0_r );
95READ8_HANDLER( ppu2c03b_1_r );
96
97WRITE8_HANDLER( ppu2c03b_0_w );
98WRITE8_HANDLER( ppu2c03b_1_w );
99
100#endif /* __PPU_2C03B_H__ */
src/mame/video/astrof.c
r1046r1047
1/***************************************************************************
2
3  video.c
4
5  Functions to emulate the video hardware of Astro Fighter hardware games.
6
7  Lee Taylor 28/11/1997
8
9***************************************************************************/
10
11#include "driver.h"
12#include "includes/astrof.h"
13
14
15UINT8 *tomahawk_protection;
16UINT8 *astrof_color;
17
18static UINT8 palette_bank, red_on;
19
20
21/***************************************************************************
22
23  The palette PROMs are connected to the RGB output this way:
24
25  bit 0 -- RED
26        -- RED
27        -- GREEN
28        -- GREEN
29        -- BLUE
30  bit 5 -- BLUE
31
32  I couldn't really determine the resistances, (too many resistors and capacitors)
33  so the value below might be off a tad. But since there is also a variable
34  resistor for each color gun, this is one of the concievable settings
35
36***************************************************************************/
37
38static void get_pens(pen_t *pens)
39{
40   offs_t i;
41
42   for (i = 0; i < memory_region_length(REGION_PROMS); i++)
43   {
44      UINT8 bit0, bit1, r, g, b;
45
46      UINT8 data = memory_region(REGION_PROMS)[i];
47
48      bit0 = ((data >> 0) & 0x01) | red_on;
49      bit1 = ((data >> 1) & 0x01) | red_on;
50      r = 0xc0 * bit0 + 0x3f * bit1;
51
52      bit0 = ( data >> 2) & 0x01;
53      bit1 = ( data >> 3) & 0x01;
54      g = 0xc0 * bit0 + 0x3f * bit1;
55
56      bit0 = ( data >> 4) & 0x01;
57      bit1 = ( data >> 5) & 0x01;
58      b = 0xc0 * bit0 + 0x3f * bit1;
59
60      pens[i] = MAKE_RGB(r, g, b);
61   }
62}
63
64
65/***************************************************************************
66
67  Start the video hardware emulation.
68
69***************************************************************************/
70
71VIDEO_START( astrof )
72{
73   colorram = auto_malloc(videoram_size);
74
75   palette_bank = 0;
76   red_on = 0;
77
78   return 0;
79}
80
81
82
83WRITE8_HANDLER( astrof_videoram_w )
84{
85   // Astro Fighter's palette is set in astrof_video_control2_w, D0 is unused
86   videoram[offset] = data;
87   colorram[offset] = *astrof_color & 0x0e;
88}
89
90
91WRITE8_HANDLER( tomahawk_videoram_w )
92{
93   // Tomahawk's palette is set per byte
94   videoram[offset] = data;
95   colorram[offset] = (*astrof_color & 0x0e) | ((*astrof_color & 0x01) << 4);
96}
97
98
99WRITE8_HANDLER( astrof_video_control1_w )
100{
101   // Video control register 1
102   //
103   // Bit 0     = Flip screen
104   // Bit 1     = Shown in schematics as what appears to be a screen clear
105   //             bit, but it's always zero in Astro Fighter
106   // Bit 2     = Not hooked up in the schematics, but at one point the game
107   //             sets it to 1.
108   // Bit 3-7   = Not hooked up
109
110   if (input_port_2_r(0) & 0x02) /* Cocktail mode */
111   {
112      flip_screen_set(data & 0x01);
113   }
114}
115
116
117// Video control register 2
118//
119// Bit 0     = Hooked up to a connector called OUT0, don't know what it does
120// Bit 1     = Hooked up to a connector called OUT1, don't know what it does
121// Bit 2     = Palette select in Astro Fighter, unused in Tomahawk
122// Bit 3     = Turns on RED color gun regardless of what the value is
123//             in the color PROM
124// Bit 4-7   = Not hooked up
125
126WRITE8_HANDLER( astrof_video_control2_w )
127{
128   palette_bank = (data >> 2) & 0x01;
129
130   red_on = (data >> 3) & 0x01;
131}
132
133
134WRITE8_HANDLER( tomahawk_video_control2_w )
135{
136   palette_bank = 0;
137
138   red_on = (data >> 3) & 0x01;
139
140   video_screen_update_partial(0, video_screen_get_vpos(0));
141}
142
143
144READ8_HANDLER( tomahawk_protection_r )
145{
146   /* flip the byte */
147
148   return BITSWAP8(*tomahawk_protection,0,1,2,3,4,5,6,7);
149}
150
151
152VIDEO_UPDATE( astrof )
153{
154   pen_t pens[0x100];
155   offs_t offs;
156
157   get_pens(pens);
158
159   for (offs = 0; offs < videoram_size; offs++)
160   {
161      int i;
162
163      UINT8 data = videoram[offs];
164      UINT8 color = colorram[offs];
165
166      pen_t back_pen = pens[(palette_bank << 4) | color | 0x00];
167      pen_t fore_pen = pens[(palette_bank << 4) | color | 0x01];
168
169      UINT8 y = ~offs;
170      UINT8 x = offs >> 8 << 3;
171
172      for (i = 0; i < 8; i++)
173      {
174         pen_t pen = (data & 0x01) ? fore_pen : back_pen;
175
176         if (flip_screen)
177            *BITMAP_ADDR32(bitmap, 255 - y, 255 - x) = pen;
178         else
179            *BITMAP_ADDR32(bitmap, y, x) = pen;
180
181         x = x + 1;
182         data = data >> 1;
183      }
184   }
185
186   return 0;
187}
src/mame/video/nyny.c
r1046r1047
1/***************************************************************************
2
3  video.c
4
5  Functions to emulate the video hardware of the machine.
6
7***************************************************************************/
8
9#include "driver.h"
10
11extern UINT8 *nyny_videoram ;
12extern UINT8 *nyny_colourram ;
13
14static mame_bitmap *tmpbitmap1;
15static mame_bitmap *tmpbitmap2;
16
17
18/* used by nyny and spiders */
19PALETTE_INIT( nyny )
20{
21   int i;
22
23   for (i = 0;i < machine->drv->total_colors;i++)
24   {
25      palette_set_color_rgb(machine,i,pal1bit(i >> 0),pal1bit(i >> 1),pal1bit(i >> 2));
26   }
27}
28
29
30/***************************************************************************
31
32  Start the video hardware emulation.
33
34***************************************************************************/
35
36VIDEO_START( nyny )
37{
38   tmpbitmap1 = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
39   tmpbitmap2 = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
40
41   nyny_videoram = auto_malloc(0x4000);
42   nyny_colourram = auto_malloc(0x4000);
43}
44
45/***************************************************************************
46  Stop the video hardware emulation.
47***************************************************************************/
48
49WRITE8_HANDLER( nyny_flipscreen_w )
50{
51   flip_screen_set(data);
52}
53
54READ8_HANDLER( nyny_videoram0_r )
55{
56   return( nyny_videoram[offset] ) ;
57}
58
59READ8_HANDLER( nyny_videoram1_r )
60{
61   return( nyny_videoram[offset+0x2000] ) ;
62}
63
64READ8_HANDLER( nyny_colourram0_r )
65{
66   return( nyny_colourram[offset] ) ;
67}
68
69READ8_HANDLER( nyny_colourram1_r )
70{
71   return( nyny_colourram[offset+0x2000] ) ;
72}
73
74WRITE8_HANDLER( nyny_colourram0_w )
75{
76   int x,y,z,d,v,c;
77   nyny_colourram[offset] = data;
78   v = nyny_videoram[offset] ;
79
80   x = offset & 0x1f ;
81   y = offset >> 5 ;
82
83   d = data & 7 ;
84   for ( z=0; z<8; z++ )
85   {
86      c = v & 1 ;
87      *BITMAP_ADDR16(tmpbitmap1, y, x*8+z) = Machine->pens[c*d];
88      v >>= 1 ;
89   }
90}
91
92WRITE8_HANDLER( nyny_videoram0_w )
93{
94   int x,y,z,c,d;
95   nyny_videoram[offset] = data;
96   d = nyny_colourram[offset] & 7 ;
97
98   x = offset & 0x1f ;
99   y = offset >> 5 ;
100
101   for ( z=0; z<8; z++ )
102   {
103      c = data & 1 ;
104      *BITMAP_ADDR16(tmpbitmap1, y, x*8+z) = Machine->pens[c*d];
105      data >>= 1 ;
106   }
107}
108
109WRITE8_HANDLER( nyny_colourram1_w )
110{
111   int x,y,z,d,v,c;
112   nyny_colourram[offset+0x2000] = data;
113   v = nyny_videoram[offset+0x2000] ;
114
115   x = offset & 0x1f ;
116   y = offset >> 5 ;
117
118   d = data & 7 ;
119   for ( z=0; z<8; z++ )
120   {
121      c = v & 1 ;
122      *BITMAP_ADDR16(tmpbitmap2, y, x*8+z) = Machine->pens[c*d];
123      v >>= 1 ;
124   }
125
126}
127
128WRITE8_HANDLER( nyny_videoram1_w )
129{
130   int x,y,z,c,d;
131   nyny_videoram[offset+0x2000] = data;
132   d = nyny_colourram[offset+0x2000] & 7 ;
133
134   x = offset & 0x1f ;
135   y = offset >> 5 ;
136
137   for ( z=0; z<8; z++ )
138   {
139      c = data & 1 ;
140      *BITMAP_ADDR16(tmpbitmap2, y, x*8+z) = Machine->pens[c*d];
141      data >>= 1 ;
142   }
143}
144
145VIDEO_UPDATE( nyny )
146{
147   copybitmap(bitmap,tmpbitmap2,flip_screen,flip_screen,0,0,&machine->screen[0].visarea,TRANSPARENCY_NONE,0);
148   copybitmap(bitmap,tmpbitmap1,flip_screen,flip_screen,0,0,&machine->screen[0].visarea,TRANSPARENCY_COLOR,0);
149   return 0;
150}
src/mame/video/berzerk.c
r1046r1047
1/***************************************************************************
2
3  video.c
4
5  Functions to emulate the video hardware of the machine.
6
7***************************************************************************/
8
9#include "driver.h"
10#include "includes/berzerk.h"
11#include "machine/74181.h"
12#include "machine/74153.h"
13
14#define LS181_12C ( 0 )
15#define LS181_10C ( 1 )
16
17#define LS153_7A ( 0 )
18#define LS153_8A ( 1 )
19#define LS153_10A ( 2 )
20#define LS153_11A ( 3 )
21#define LS153_9A ( 4 )
22#define LS153_11B ( 5 )
23#define LS153_10B ( 6 )
24#define LS153_9B ( 7 )
25#define LS153_8B ( 8 )
26
27static UINT8 latch_7c = 0x7f;
28static UINT8 intercept = 0;
29
30
31PALETTE_INIT( berzerk )
32{
33   int i;
34
35   /* Simple 1-bit RGBI palette */
36   for (i = 0; i < 16; i++)
37   {
38      int bk = (i & 8) ? 0x40 : 0x00;
39      int r = (i & 1) ? 0xff : bk;
40      int g = (i & 2) ? 0xff : bk;
41      int b = (i & 4) ? 0xff : bk;
42
43      palette_set_color(machine,i,r,g,b);
44   }
45}
46
47
48static void shifters_init( void )
49{
50   TTL74153_config( LS153_7A, 0 );
51   TTL74153_enable_w( LS153_7A, 0, 0 );
52   TTL74153_enable_w( LS153_7A, 1, 0 );
53
54   TTL74153_config( LS153_8A, 0 );
55   TTL74153_enable_w( LS153_8A, 0, 0 );
56   TTL74153_enable_w( LS153_8A, 1, 0 );
57
58   TTL74153_config( LS153_10A, 0 );
59   TTL74153_enable_w( LS153_10A, 0, 0 );
60   TTL74153_enable_w( LS153_10A, 1, 0 );
61
62   TTL74153_config( LS153_11A, 0 );
63   TTL74153_enable_w( LS153_11A, 0, 0 );
64   TTL74153_enable_w( LS153_11A, 1, 0 );
65
66   TTL74153_config( LS153_9A, 0 );
67   TTL74153_enable_w( LS153_9A, 0, 0 );
68   TTL74153_enable_w( LS153_9A, 1, 0 );
69}
70
71
72static void shifters_setup( int a, int b )
73{
74   TTL74153_a_w( LS153_7A, a );
75   TTL74153_b_w( LS153_7A, b );
76   TTL74153_a_w( LS153_8A, a );
77   TTL74153_b_w( LS153_8A, b );
78   TTL74153_a_w( LS153_10A, a );
79   TTL74153_b_w( LS153_10A, b );
80   TTL74153_a_w( LS153_11A, a );
81   TTL74153_b_w( LS153_11A, b );
82   TTL74153_a_w( LS153_9A, a );
83   TTL74153_b_w( LS153_9A, b );
84}
85
86
87static UINT16 shifters_update( UINT8 data )
88{
89   TTL74153_input_line_w( LS153_7A, 0, 3, ( data >> 0 ) & 1 );
90   TTL74153_input_line_w( LS153_7A, 0, 2, ( data >> 2 ) & 1 );
91   TTL74153_input_line_w( LS153_7A, 0, 1, ( data >> 4 ) & 1 );
92   TTL74153_input_line_w( LS153_7A, 0, 0, ( data >> 6 ) & 1 );
93   TTL74153_input_line_w( LS153_7A, 1, 3, ( data >> 1 ) & 1 );
94   TTL74153_input_line_w( LS153_7A, 1, 2, ( data >> 3 ) & 1 );
95   TTL74153_input_line_w( LS153_7A, 1, 1, ( data >> 5 ) & 1 );
96   TTL74153_input_line_w( LS153_7A, 1, 0, ( data >> 7 ) & 1 );
97   TTL74153_update( LS153_7A );
98
99   TTL74153_input_line_w( LS153_8A, 0, 3, ( data >> 2 ) & 1 );
100   TTL74153_input_line_w( LS153_8A, 0, 2, ( data >> 4 ) & 1 );
101   TTL74153_input_line_w( LS153_8A, 0, 1, ( data >> 6 ) & 1 );
102   TTL74153_input_line_w( LS153_8A, 0, 0, ( latch_7c >> 0 ) & 1 );
103   TTL74153_input_line_w( LS153_8A, 1, 3, ( data >> 3 ) & 1 );
104   TTL74153_input_line_w( LS153_8A, 1, 2, ( data >> 5 ) & 1 );
105   TTL74153_input_line_w( LS153_8A, 1, 1, ( data >> 7 ) & 1 );
106   TTL74153_input_line_w( LS153_8A, 1, 0, ( latch_7c >> 1 ) & 1 );
107   TTL74153_update( LS153_8A );
108
109   TTL74153_input_line_w( LS153_10A, 0, 3, ( data >> 4 ) & 1 );
110   TTL74153_input_line_w( LS153_10A, 0, 2, ( data >> 6 ) & 1 );
111   TTL74153_input_line_w( LS153_10A, 0, 1, ( latch_7c >> 0 ) & 1 );
112   TTL74153_input_line_w( LS153_10A, 0, 0, ( latch_7c >> 2 ) & 1 );
113   TTL74153_input_line_w( LS153_10A, 1, 3, ( data >> 5 ) & 1 );
114   TTL74153_input_line_w( LS153_10A, 1, 2, ( data >> 7 ) & 1 );
115   TTL74153_input_line_w( LS153_10A, 1, 1, ( latch_7c >> 1 ) & 1 );
116   TTL74153_input_line_w( LS153_10A, 1, 0, ( latch_7c >> 3 ) & 1 );
117   TTL74153_update( LS153_10A );
118
119   TTL74153_input_line_w( LS153_11A, 0, 3, ( data >> 6 ) & 1 );
120   TTL74153_input_line_w( LS153_11A, 0, 2, ( latch_7c >> 0 ) & 1 );
121   TTL74153_input_line_w( LS153_11A, 0, 1, ( latch_7c >> 2 ) & 1 );
122   TTL74153_input_line_w( LS153_11A, 0, 0, ( latch_7c >> 4 ) & 1 );
123   TTL74153_input_line_w( LS153_11A, 1, 3, ( data >> 7 ) & 1 );
124   TTL74153_input_line_w( LS153_11A, 1, 2, ( latch_7c >> 1 ) & 1 );
125   TTL74153_input_line_w( LS153_11A, 1, 1, ( latch_7c >> 3 ) & 1 );
126   TTL74153_input_line_w( LS153_11A, 1, 0, ( latch_7c >> 5 ) & 1 );
127   TTL74153_update( LS153_11A );
128
129   TTL74153_input_line_w( LS153_9A, 0, 3, ( latch_7c >> 0 ) & 1 );
130   TTL74153_input_line_w( LS153_9A, 0, 2, ( latch_7c >> 2 ) & 1 );
131   TTL74153_input_line_w( LS153_9A, 0, 1, ( latch_7c >> 4 ) & 1 );
132   TTL74153_input_line_w( LS153_9A, 0, 0, ( latch_7c >> 6 ) & 1 );
133   TTL74153_update( LS153_9A );
134
135   return ( TTL74153_output_r( LS153_7A, 0 ) << 0 ) |
136      ( TTL74153_output_r( LS153_7A, 1 ) << 1 ) |
137      ( TTL74153_output_r( LS153_8A, 0 ) << 2 ) |
138      ( TTL74153_output_r( LS153_8A, 1 ) << 3 ) |
139      ( TTL74153_output_r( LS153_10A, 0 ) << 4 ) |
140      ( TTL74153_output_r( LS153_10A, 1 ) << 5 ) |
141      ( TTL74153_output_r( LS153_11A, 0 ) << 6 ) |
142      ( TTL74153_output_r( LS153_11A, 1 ) << 7 ) |
143      ( TTL74153_output_r( LS153_9A, 0 ) << 8 );
144}
145
146
147static void shifters_and_floppers_init( void )
148{
149   TTL74153_config( LS153_11B, 0 );
150   TTL74153_enable_w( LS153_11B, 0, 0 );
151   TTL74153_enable_w( LS153_11B, 1, 0 );
152
153   TTL74153_config( LS153_10B, 0 );
154   TTL74153_enable_w( LS153_10B, 0, 0 );
155   TTL74153_enable_w( LS153_10B, 1, 0 );
156
157   TTL74153_config( LS153_9B, 0 );
158   TTL74153_enable_w( LS153_9B, 0, 0 );
159   TTL74153_enable_w( LS153_9B, 1, 0 );
160
161   TTL74153_config( LS153_8B, 0 );
162   TTL74153_enable_w( LS153_8B, 0, 0 );
163   TTL74153_enable_w( LS153_8B, 1, 0 );
164}
165
166
167static void shifters_and_floppers_setup( int a, int b )
168{
169   TTL74153_a_w( LS153_11B, a );
170   TTL74153_b_w( LS153_11B, b );
171   TTL74153_a_w( LS153_10B, a );
172   TTL74153_b_w( LS153_10B, b );
173   TTL74153_a_w( LS153_9B, a );
174   TTL74153_b_w( LS153_9B, b );
175   TTL74153_a_w( LS153_8B, a );
176   TTL74153_b_w( LS153_8B, b );
177}
178
179
180static UINT8 shifters_and_floppers_update( UINT16 data )
181{
182   TTL74153_input_line_w( LS153_11B, 0, 3, ( data >> 0 ) & 1 );
183   TTL74153_input_line_w( LS153_11B, 0, 2, ( data >> 1 ) & 1 );
184   TTL74153_input_line_w( LS153_11B, 0, 1, ( data >> 7 ) & 1 );
185   TTL74153_input_line_w( LS153_11B, 0, 0, ( data >> 8 ) & 1 );
186   TTL74153_input_line_w( LS153_11B, 1, 3, ( data >> 1 ) & 1 );
187   TTL74153_input_line_w( LS153_11B, 1, 2, ( data >> 2 ) & 1 );
188   TTL74153_input_line_w( LS153_11B, 1, 1, ( data >> 6 ) & 1 );
189   TTL74153_input_line_w( LS153_11B, 1, 0, ( data >> 7 ) & 1 );
190   TTL74153_update( LS153_11B );
191
192   TTL74153_input_line_w( LS153_10B, 0, 3, ( data >> 2 ) & 1 );
193   TTL74153_input_line_w( LS153_10B, 0, 2, ( data >> 3 ) & 1 );
194   TTL74153_input_line_w( LS153_10B, 0, 1, ( data >> 5 ) & 1 );
195   TTL74153_input_line_w( LS153_10B, 0, 0, ( data >> 6 ) & 1 );
196   TTL74153_input_line_w( LS153_10B, 1, 3, ( data >> 3 ) & 1 );
197   TTL74153_input_line_w( LS153_10B, 1, 2, ( data >> 4 ) & 1 );
198   TTL74153_input_line_w( LS153_10B, 1, 1, ( data >> 4 ) & 1 );
199   TTL74153_input_line_w( LS153_10B, 1, 0, ( data >> 5 ) & 1 );
200   TTL74153_update( LS153_10B );
201
202   TTL74153_input_line_w( LS153_9B, 0, 3, ( data >> 4 ) & 1 );
203   TTL74153_input_line_w( LS153_9B, 0, 2, ( data >> 5 ) & 1 );
204   TTL74153_input_line_w( LS153_9B, 0, 1, ( data >> 3 ) & 1 );
205   TTL74153_input_line_w( LS153_9B, 0, 0, ( data >> 4 ) & 1 );
206   TTL74153_input_line_w( LS153_9B, 1, 3, ( data >> 5 ) & 1 );
207   TTL74153_input_line_w( LS153_9B, 1, 2, ( data >> 6 ) & 1 );
208   TTL74153_input_line_w( LS153_9B, 1, 1, ( data >> 2 ) & 1 );
209   TTL74153_input_line_w( LS153_9B, 1, 0, ( data >> 3 ) & 1 );
210   TTL74153_update( LS153_9B );
211
212   TTL74153_input_line_w( LS153_8B, 0, 3, ( data >> 6 ) & 1 );
213   TTL74153_input_line_w( LS153_8B, 0, 2, ( data >> 7 ) & 1 );
214   TTL74153_input_line_w( LS153_8B, 0, 1, ( data >> 1 ) & 1 );
215   TTL74153_input_line_w( LS153_8B, 0, 0, ( data >> 2 ) & 1 );
216   TTL74153_input_line_w( LS153_8B, 1, 3, ( data >> 7 ) & 1 );
217   TTL74153_input_line_w( LS153_8B, 1, 2, ( data >> 8 ) & 1 );
218   TTL74153_input_line_w( LS153_8B, 1, 1, ( data >> 0 ) & 1 );
219   TTL74153_input_line_w( LS153_8B, 1, 0, ( data >> 1 ) & 1 );
220   TTL74153_update( LS153_8B );
221
222   return ( TTL74153_output_r( LS153_11B, 0 ) << 0 ) |
223      ( TTL74153_output_r( LS153_11B, 1 ) << 1 ) |
224      ( TTL74153_output_r( LS153_10B, 0 ) << 2 ) |
225      ( TTL74153_output_r( LS153_10B, 1 ) << 3 ) |
226      ( TTL74153_output_r( LS153_9B, 0 ) << 4 ) |
227      ( TTL74153_output_r( LS153_9B, 1 ) << 5 ) |
228      ( TTL74153_output_r( LS153_8B, 0 ) << 6 ) |
229      ( TTL74153_output_r( LS153_8B, 1 ) << 7 );
230}
231
232
233static void alu_init( void )
234{
235   TTL74181_init( LS181_12C );
236   TTL74181_write( LS181_12C, TTL74181_INPUT_M, 1, 1 );
237
238   TTL74181_init( LS181_10C );
239   TTL74181_write( LS181_10C, TTL74181_INPUT_M, 1, 1 );
240}
241
242
243static void alu_setup( int s )
244{
245   TTL74181_write( LS181_12C, TTL74181_INPUT_S0, 4, s );
246   TTL74181_write( LS181_10C, TTL74181_INPUT_S0, 4, s );
247}
248
249
250static UINT8 alu_update( UINT8 a, UINT8 b )
251{
252   TTL74181_write( LS181_12C, TTL74181_INPUT_A0, 4, a >> 0 );
253   TTL74181_write( LS181_10C, TTL74181_INPUT_A0, 4, a >> 4 );
254
255   TTL74181_write( LS181_12C, TTL74181_INPUT_B0, 4, b >> 0 );
256   TTL74181_write( LS181_10C, TTL74181_INPUT_B0, 4, b >> 4 );
257
258   return ( TTL74181_read( LS181_12C, TTL74181_OUTPUT_F0, 4 ) << 0 ) |
259      ( TTL74181_read( LS181_10C, TTL74181_OUTPUT_F0, 4 ) << 4 );
260}
261
262
263VIDEO_START( berzerk )
264{
265   shifters_init();
266   shifters_and_floppers_init();
267   alu_init();
268
269   return video_start_generic_bitmapped(machine);
270}
271
272
273INLINE void copy_byte(UINT8 x, UINT8 y, UINT8 data, UINT8 col)
274{
275   pen_t fore, back;
276
277   fore  = Machine->pens[col >> 4];
278   back  = Machine->pens[0];
279
280   *BITMAP_ADDR16(tmpbitmap, y, x+0) = (data & 0x80) ? fore : back;
281   *BITMAP_ADDR16(tmpbitmap, y, x+1) = (data & 0x40) ? fore : back;
282   *BITMAP_ADDR16(tmpbitmap, y, x+2) = (data & 0x20) ? fore : back;
283   *BITMAP_ADDR16(tmpbitmap, y, x+3) = (data & 0x10) ? fore : back;
284
285   fore  = Machine->pens[col & 0x0f];
286
287   *BITMAP_ADDR16(tmpbitmap, y, x+4) = (data & 0x08) ? fore : back;
288   *BITMAP_ADDR16(tmpbitmap, y, x+5) = (data & 0x04) ? fore : back;
289   *BITMAP_ADDR16(tmpbitmap, y, x+6) = (data & 0x02) ? fore : back;
290   *BITMAP_ADDR16(tmpbitmap, y, x+7) = (data & 0x01) ? fore : back;
291}
292
293
294WRITE8_HANDLER( berzerk_videoram_w )
295{
296   offs_t coloroffset;
297   UINT8 x, y;
298
299   videoram[offset] = data;
300
301   /* Get location of color RAM for this offset */
302   coloroffset = ((offset & 0xff80) >> 2) | (offset & 0x1f);
303
304   y = offset >> 5;
305   x = offset << 3;
306
307   copy_byte(x, y, data, colorram[coloroffset]);
308}
309
310
311WRITE8_HANDLER( berzerk_colorram_w )
312{
313   int i;
314   UINT8 x, y;
315
316   colorram[offset] = data;
317
318   /* Need to change the affected pixels' colors */
319   y = (offset >> 3) & 0xfc;
320   x = offset << 3;
321
322   for (i = 0; i < 4; i++, y++)
323   {
324      UINT8 byte = videoram[(y << 5) | (x >> 3)];
325
326      copy_byte(x, y, byte, data);
327   }
328}
329
330
331WRITE8_HANDLER( berzerk_magicram_w )
332{
333   /* shift data towards lsb by 0, 2, 4 or 6. msb bits are filled by data from latch_7c. */
334   UINT16 shifters_output = shifters_update( data );
335
336   /* shift data towards lsb by 0 or 1 & optionally reverse the order of bits. */
337   UINT8 shifters_and_floppers_output = shifters_and_floppers_update( shifters_output );
338
339   UINT8 rd = videoram[ offset ];
340
341   UINT8 alu_output = alu_update( shifters_and_floppers_output, rd );
342
343   berzerk_videoram_w( offset, alu_output ^ 0xff );
344
345   /* collision detection. */
346   if ( ( shifters_and_floppers_output & rd ) != 0 )
347   {
348      intercept |= 0x80;
349   }
350
351   /* save data for next time. */
352   latch_7c = data & 0x7f;
353}
354
355
356WRITE8_HANDLER( berzerk_magicram_control_w )
357{
358   shifters_setup( ( ~data >> 1 ) & 1, ( ~data >> 2 ) & 1 );
359   shifters_and_floppers_setup( ( ~data >> 0 ) & 1, ( ~data >> 3 ) & 1 );
360   alu_setup( data >> 4 );
361
362   latch_7c = 0;
363   intercept = 0;
364}
365
366
367READ8_HANDLER( berzerk_port_4e_r )
368{
369   return input_port_3_r(0) | intercept;
370}
src/mame/video/spiders.c
r1046r1047
1/***************************************************************************
2
3  video.c
4
5  Functions to emulate the video hardware of the machine.
6
7***************************************************************************/
8
9#include "driver.h"
10#include "spiders.h"
11#include "video/crtc6845.h"
12
13static UINT8 bitflip[256];
14static int *screenbuffer;
15
16#define SCREENBUFFER_SIZE   0x2000
17
18/***************************************************************************
19
20  Start the video hardware emulation.
21
22***************************************************************************/
23VIDEO_START( spiders )
24{
25   int loop;
26
27   // Use a temp bitmap so user change (dip switches, etc.) does not effect the bitmap
28   tmpbitmap = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
29
30   for(loop=0;loop<256;loop++)
31   {
32      bitflip[loop]=(loop&0x01)?0x80:0x00;
33      bitflip[loop]|=(loop&0x02)?0x40:0x00;
34      bitflip[loop]|=(loop&0x04)?0x20:0x00;
35      bitflip[loop]|=(loop&0x08)?0x10:0x00;
36      bitflip[loop]|=(loop&0x10)?0x08:0x00;
37      bitflip[loop]|=(loop&0x20)?0x04:0x00;
38      bitflip[loop]|=(loop&0x40)?0x02:0x00;
39      bitflip[loop]|=(loop&0x80)?0x01:0x00;
40   }
41   screenbuffer = auto_malloc(SCREENBUFFER_SIZE*sizeof(int));
42   memset(screenbuffer,1,SCREENBUFFER_SIZE*sizeof(int));
43   return 0;
44}
45
46/***************************************************************************
47
48  Draw the game screen in the given mame_bitmap.
49  Do NOT call osd_update_display() from this function, it will be called by
50  the main emulation engine.
51
52***************************************************************************/
53VIDEO_UPDATE( spiders )
54{
55   int loop,data0,data1,data2,col;
56
57   size_t crtc6845_mem_size;
58   int video_addr,increment;
59
60   crtc6845_mem_size=crtc6845.horiz_disp*crtc6845.vert_disp*8;
61
62   video_addr=crtc6845.start_addr & 0x7f;
63
64   if(spiders_video_flip)
65   {
66      video_addr+=crtc6845_mem_size-1;
67      increment=-1;
68   }
69   else
70   {
71      increment=1;
72   }
73
74   // Access bank1
75   if(crtc6845.page_flip)
76      video_addr+=0x2000;
77
78   for(loop=0;loop<crtc6845_mem_size;loop++)
79   {
80      int i,x,y,combo;
81
82      if(spiders_video_flip)
83      {
84         data0=bitflip[spiders_ram[0x0000+video_addr]];
85         data1=bitflip[spiders_ram[0x4000+video_addr]];
86         data2=bitflip[spiders_ram[0x8000+video_addr]];
87      }
88      else
89      {
90         data0=spiders_ram[0x0000+video_addr];
91         data1=spiders_ram[0x4000+video_addr];
92         data2=spiders_ram[0x8000+video_addr];
93      }
94      combo=data0|(data1<<8)|(data2<<16);
95
96        // Check if we need to update the bitmap or the bitmap already has the right colour
97      if(screenbuffer[loop]!=combo)
98      {
99         y=loop/0x20;
100
101         for(i=0;i<8;i++)
102         {
103            x=((loop%0x20)<<3)+i;
104            col=((data2&0x01)<<2)+((data1&0x01)<<1)+(data0&0x01);
105
106            *BITMAP_ADDR16(tmpbitmap, y, x) = machine->pens[col];
107
108            data0 >>= 1;
109            data1 >>= 1;
110            data2 >>= 1;
111         }
112         screenbuffer[loop]=combo;
113      }
114      video_addr+=increment;
115   }
116   /* Now copy the temp bitmap to the screen */
117    copybitmap(bitmap,tmpbitmap,0,0,0,0,&machine->screen[0].visarea,TRANSPARENCY_NONE,0);
118   return 0;
119}
src/mame/video/leprechn.c
r1046r1047
1/***************************************************************************
2
3  video.c
4
5  Functions to emulate the video hardware of the machine.
6
7***************************************************************************/
8
9#include "driver.h"
10#include "machine/6522via.h"
11#include "includes/leprechn.h"
12
13
14static UINT8 x,y,color;
15static UINT8 graphics_command;
16static int pending;
17
18
19/* RGBI palette. Is it correct? */
20PALETTE_INIT( leprechn )
21{
22   int i;
23
24   for (i = 0; i < 16; i++)
25   {
26      int bk = (i & 8) ? 0x40 : 0x00;
27      int r = (i & 1) ? 0xff : bk;
28      int g = (i & 2) ? 0xff : bk;
29      int b = (i & 4) ? 0xff : bk;
30
31      palette_set_color(machine,i,r,g,b);
32   }
33}
34
35
36
37VIDEO_START( leprechn )
38{
39   videoram_size = machine->screen[0].width * machine->screen[0].height;
40
41   /* allocate our own dirty buffer */
42   videoram = auto_malloc(videoram_size);
43
44   return video_start_generic_bitmapped(machine);
45}
46
47
48WRITE8_HANDLER( leprechn_graphics_command_w )
49{
50    graphics_command = data & 0x38;
51}
52
53
54
55static void clear_screen_done_callback(int param)
56{
57   // Indicate that the we are done
58   via_0_ca1_w(0, 0);
59}
60
61
62WRITE8_HANDLER( leprechn_videoram_w )
63{
64   int sx,sy;
65
66   if (pending)
67   {
68      *BITMAP_ADDR16(tmpbitmap, y, x) = Machine->pens[color];
69        videoram[y * Machine->screen[0].width + x] = color;
70
71        pending = 0;
72      }
73
74    switch (graphics_command)
75    {
76    case 0x00:   // Move and plot
77
78        color = data & 0x0f;
79
80      if (data & 0x10)
81      {
82         if (data & 0x40)
83            x--;
84         else
85            x++;
86      }
87
88      if (data & 0x20)
89      {
90         if (data & 0x80)
91            y--;
92         else
93            y++;
94      }
95
96      pending = 1;
97
98      break;
99
100    case 0x08:  // X position write
101        x = data;
102        break;
103
104    case 0x10:  // Y position write
105        y = data;
106        break;
107
108    case 0x18:  // Clear bitmap
109
110      // Indicate that the we are busy
111      via_0_ca1_w(0, 1);
112
113        memset(videoram, data, videoram_size);
114
115        for (sx = 0; sx < Machine->screen[0].width; sx++)
116        {
117           for (sy = 0; sy < Machine->screen[0].height; sy++)
118           {
119            *BITMAP_ADDR16(tmpbitmap, sy, sx) = Machine->pens[data];
120         }
121      }
122
123      // Set a timer for an arbitrarily short period.
124      // The real time it takes to clear to screen is not
125      // significant for the software.
126      timer_set(TIME_NOW, 0, clear_screen_done_callback);
127
128        break;
129
130   default:
131       // Doesn't seem to happen.
132       logerror("Unknown Graphics Command #%2X at %04X\n", graphics_command, activecpu_get_pc());
133    }
134}
135
136
137READ8_HANDLER( leprechn_videoram_r )
138{
139    return videoram[y * Machine->screen[0].width + x];
140}
src/mame/video/micro3d.c
r1046r1047
1/*====================================================================*/
2/*                         'micro3d.c'                                */
3/*               Microprose 3D Hardware MAME driver                   */
4/*                        Video Emulation                             */
5/*                     Philip J Bennett 2004                          */
6/*====================================================================*/
7
8#include "driver.h"
9#include "cpu/tms34010/tms34010.h"
10#include "cpu/tms34010/34010ops.h"
11#include "includes/micro3d.h"
12
13
14static UINT16 dpyadr, dudate, dumask;
15//extern UINT16 *m68681_base;
16
17#if 0
18extern struct {
19
20UINT16 MR1A;
21UINT16 MR2A;
22UINT16 SRA;
23UINT16 CSRA;
24UINT16 CRA;
25UINT16 RBA;
26UINT16 TBA;
27UINT16 IPCR;
28UINT16 ACR;
29UINT16 ISR;
30UINT16 IMR;
31UINT16 CUR;
32UINT16 CTUR;
33UINT16 CLR;
34UINT16 CTLR;
35UINT16 MR1B;
36UINT16 MR2B;
37UINT16 SRB;
38UINT16 CSRB;
39UINT16 CRB;
40UINT16 RBB;
41UINT16 TBB;
42UINT16 IVR;
43UINT16 IPORT;
44UINT16 OPCR;
45UINT16 OPR;
46
47int MRA_ptr;
48int MRB_ptr;
49
50}M68681;
51#endif
52
53extern UINT8 ti_uart[8];
54
55
56static void changecolor_BBBBBRRRRRGGGGGG(pen_t color,int data)
57{
58   palette_set_color_rgb(Machine,color,pal5bit(data >> 6),pal5bit(data >> 1),pal5bit(data >> 11));
59}
60
61WRITE16_HANDLER( paletteram16_BBBBBRRRRRGGGGGG_word_w )
62{
63   COMBINE_DATA(&paletteram16[offset]);
64   changecolor_BBBBBRRRRRGGGGGG(offset,paletteram16[offset]);
65}
66
67VIDEO_START(micro3d)
68{
69}
70
71void micro3d_scanline_update(running_machine *machine, int screen, mame_bitmap *bitmap, int scanline, const tms34010_display_params *params)
72{
73   UINT16 *src = &micro3d_sprite_vram[(params->rowaddr << 8) & 0x7fe00];
74   UINT16 *dest = BITMAP_ADDR16(bitmap, scanline, 0);
75   int coladdr = params->coladdr;
76   int x;
77
78   /* copy the non-blanked portions of this scanline */
79   for (x = params->heblnk; x < params->hsblnk; x += 2)
80   {
81      UINT16 pix = src[coladdr++ & 0x1ff];
82
83      if (pix & 0x80)
84         dest[x + 0] = (pix & 0x7f) + 0xf00;
85      else
86         dest[x + 0] = 0;   /* 3D data */
87
88      pix >>= 8;
89      if (pix & 0x80)
90         dest[x + 1] = (pix & 0x7f) + 0xf00;
91      else
92         dest[x + 1] = 0;   /* 3D data */
93   }
94}
95
96
97VIDEO_UPDATE( micro3d )
98{
99
100UINT16 *asrc;
101//UINT16 dudate, dumask;
102int x,y;
103static UINT32 offset=0x1e00;
104
105/*
106static int bank=0;
107
108       offset = (bank ? 0x1e00 : 0x37a00);
109       bank=!bank;
110*/
111
112/*
113
114if(keyboard_pressed(KEYCODE_F1))
115{
116  UINT8 transmit=0;
117                mame_pause(Machine, 1);
118
119                do
120            {
121        InputCode code;
122
123                  update_video_and_audio();
124
125        if (input_ui_pressed(IPT_UI_CANCEL))
126            break;
127
128        code = code_read_async();
129        if (code == KEYCODE_F1) code = code_read_async();
130
131        if (code != CODE_NONE)
132        {
133            if (code >= KEYCODE_A && code <= KEYCODE_Z)
134            transmit = code+97;
135            if (code >= KEYCODE_0 && code <= KEYCODE_9)
136            transmit = code+22;
137                        if (code == KEYCODE_ENTER)
138                        transmit = 13;
139                        if (code == KEYCODE_MINUS)
140                        transmit = 63;
141                        if (code == KEYCODE_OPENBRACE)
142                        transmit = 91;
143                        if (code == KEYCODE_CLOSEBRACE)
144                        transmit = 93;
145                        if (code == KEYCODE_COMMA)
146                        transmit = 46;
147                        if (code == KEYCODE_SPACE)
148                        transmit = 32;
149
150        }
151    }
152    while (!transmit);
153
154
155    ti_uart[0]=transmit;
156    ti_uart[2]|=2;
157
158      M68681.RBA=transmit<<8;
159      M68681.SRA|=0x100;
160
161    mame_pause(Machine, 0);
162    return 0;
163}
164*/
165
166   /* If the display is blanked, fill with black */
167   if (tms34010_io_display_blanked(0))
168   {
169      fillbitmap(bitmap, Machine->pens[0], cliprect);
170      return 0;
171   }
172
173        /* fetch current scanline advance and column offset values */
174   cpuintrf_push_context(0);
175   dudate = (tms34010_io_register_r(REG_DPYCTL, 0) & 0x03fc) << 4;
176   dumask = dudate - 1;
177   cpuintrf_pop_context();
178
179   /* compute the offset */
180   offset = (dpyadr << 4);
181
182   /* adjust for when DPYADR was written */
183//  if (cliprect->min_y > dpyadrscan)
184//      offset += (cliprect->min_y - dpyadrscan) * dudate;
185//mame_printf_debug("DPYADR = %04X DPYTAP = %04X (%d-%d)\n", dpyadr, dpytap, cliprect->min_y, cliprect->max_y);
186
187// 7-bits per pixel for the TI 2D, it would seem.
188// Bit 8 selects 2D or 3D.
189
190   for (y = cliprect->min_y; y <= cliprect->max_y; y++)
191   {
192      UINT16 scanline[576];                             // Was 577
193                asrc = &micro3d_sprite_vram[offset + (512 * (y - Machine->screen[0].visarea.min_y))];     // Correct - there are 1024 bytes per line
194
195         for (x = 0; x < 576; x+=2)               //Number of pixels.
196         {
197            UINT16 adata = *asrc++;
198            if(adata&0x0080)
199                            {
200                                    scanline[x] = ((adata & 0x007f))+0xf00;
201                            }
202                            else
203                            {
204                                        scanline[x] = 0;           // Blank - for 3D
205                            }
206                                if(adata&0x8000)
207                            {
208                                    scanline[x+1] = ((adata & 0x7f00)>>8)+0xf00;
209                            }
210                            else
211                            {
212                                    scanline[x+1] = 0;         // Blank - for 3D
213                            }
214                        }
215      /* Draw the scanline */
216      draw_scanline16(bitmap, cliprect->min_x, y, cliprect->max_x - cliprect->min_x, &scanline[cliprect->min_x], Machine->pens, -1);
217   }
218   return 0;
219}
src/mame/video/res_net.c
r1046r1047
1/* res_net.c */
2
3/*****************************************************************************
4
5 Compute weights for resistors networks.
6
7 Function can evaluate from one to three networks at a time.
8
9 The output weights can either be scaled with automatically calculated scaler
10 or scaled with a 'scaler' provided on entry.
11
12 On entry
13 --------
14
15 'minval','maxval' specify the range of output signals (sum of weights).
16 'scaler'          if negative, function will calculate proper scaler,
17                   otherwise it will use the one provided here.
18 'count_x'         is the number of resistors in this network
19 'resistances_x'   is the pointer to a table containing the resistances
20 'weights_x'       is the pointer to a table to be filled with the weights
21                   (it can contain negative values if 'minval' is below zero).
22 'pulldown_x'      is the resistance of a pulldown resistor (0 means there's no pulldown resistor)
23 'pullup_x'        is the resistance of a pullup resistor (0 means there's no pullup resistor)
24
25
26 Return value
27 ------------
28
29 The value of the scaler that was used for fitting the output within the expected range.
30 Note that if you provide your own scaler on entry it will be returned here.
31
32
33 All resistances are expected in Ohms.
34
35
36 Hint
37 ----
38
39 If there is no need to calculate all three networks at a time, just specify '0'
40 for the 'count_x' for unused network(s).
41
42*****************************************************************************/
43
44
45#include "res_net.h"
46#include "driver.h"
47
48double compute_resistor_weights(
49   int minval, int maxval, double scaler,
50   int count_1, const int * resistances_1, double * weights_1, int pulldown_1, int pullup_1,
51   int count_2, const int * resistances_2, double * weights_2, int pulldown_2, int pullup_2,
52   int count_3, const int * resistances_3, double * weights_3, int pulldown_3, int pullup_3 )
53{
54
55   int networks_no;
56
57   int rescount[MAX_NETS];      /* number of resistors in each of the nets */
58   double r[MAX_NETS][MAX_RES_PER_NET];      /* resistances */
59   double w[MAX_NETS][MAX_RES_PER_NET];      /* calulated weights */
60   double ws[MAX_NETS][MAX_RES_PER_NET];   /* calulated, scaled weights */
61   int r_pd[MAX_NETS];         /* pulldown resistances */
62   int r_pu[MAX_NETS];         /* pullup resistances */
63
64   double max_out[MAX_NETS];
65   double * out[MAX_NETS];
66
67   int i,j,n;
68   double scale;
69   double max;
70
71   /* parse input parameters */
72
73   networks_no = 0;
74   for (n = 0; n < MAX_NETS; n++)
75   {
76      int count, pd, pu;
77      const int * resistances;
78      double * weights;
79
80      switch(n){
81      case 0:
82            count      = count_1;
83            resistances   = resistances_1;
84            weights      = weights_1;
85            pd         = pulldown_1;
86            pu         = pullup_1;
87            break;
88      case 1:
89            count      = count_2;
90            resistances   = resistances_2;
91            weights      = weights_2;
92            pd         = pulldown_2;
93            pu         = pullup_2;
94            break;
95      case 2:
96      default:
97            count      = count_3;
98            resistances   = resistances_3;
99            weights      = weights_3;
100            pd         = pulldown_3;
101            pu         = pullup_3;
102            break;
103      }
104
105      /* parameters validity check */
106      if (count > MAX_RES_PER_NET)
107      {
108         logerror(" ERROR: res_net.h: compute_resistor_weights(): too many resistors in net #%i. The maximum allowed is %i, the number requested was: %i\n",n, MAX_RES_PER_NET, count);
109         /* quit */
110         return (0.0);
111      }
112
113
114      if (count > 0)
115      {
116         rescount[networks_no] = count;
117         for (i=0; i < count; i++)
118         {
119            r[networks_no][i] = 1.0 * resistances[i];
120         }
121         out[networks_no] = weights;
122         r_pd[networks_no] = pd;
123         r_pu[networks_no] = pu;
124         networks_no++;
125      }
126   }
127   if (networks_no < 1)
128   {
129      /* error - no networks to anaylse */
130      logerror(" ERROR: res_net.h: compute_resistor_weights(): no input data\n");
131      return (0.0);
132   }
133
134   /* calculate outputs for all given networks */
135   for( i = 0; i < networks_no; i++ )
136   {
137      double R0, R1, Vout, dst;
138
139      /* of n resistors */
140      for(n = 0; n < rescount[i]; n++)
141      {
142         R0 = ( r_pd[i] == 0 ) ? 1.0/1e12 : 1.0/r_pd[i];
143         R1 = ( r_pu[i] == 0 ) ? 1.0/1e12 : 1.0/r_pu[i];
144
145         for( j = 0; j < rescount[i]; j++ )
146         {
147            if( j==n )   /* only one resistance in the network connected to Vcc */
148            {
149               if (r[i][j] != 0.0)
150                  R1 += 1.0/r[i][j];
151            }
152            else
153               if (r[i][j] != 0.0)
154                  R0 += 1.0/r[i][j];
155         }
156
157         /* now determine the voltage */
158         R0 = 1.0/R0;
159         R1 = 1.0/R1;
160         Vout = (maxval - minval) * R0 / (R1 + R0) + minval;
161
162         /* and convert it to a destination value */
163         dst = (Vout < minval) ? minval : (Vout > maxval) ? maxval : Vout;
164
165         w[i][n] = dst;
166      }
167   }
168
169   /* calculate maximum outputs for all given networks */
170   j = 0;
171   max = 0.0;
172   for( i = 0; i < networks_no; i++ )
173   {
174      double sum = 0.0;
175
176      /* of n resistors */
177      for( n = 0; n < rescount[i]; n++ )
178         sum += w[i][n];   /* maximum output, ie when each resistance is connected to Vcc */
179
180      max_out[i] = sum;
181      if (max < sum)
182      {
183         max = sum;
184         j = i;
185      }
186   }
187
188
189   if (scaler < 0.0)   /* use autoscale ? */
190      /* calculate the output scaler according to the network with the greatest output */
191      scale = ((double)maxval) / max_out[j];
192   else            /* use scaler provided on entry */
193      scale = scaler;
194
195   /* calculate scaled output and fill the output table(s)*/
196   for(i = 0; i < networks_no;i++)
197   {
198      for (n = 0; n < rescount[i]; n++)
199      {
200         ws[i][n] = w[i][n]*scale;   /* scale the result */
201         (out[i])[n] = ws[i][n];      /* fill the output table */
202      }
203   }
204
205/* debug code */
206#ifdef MAME_DEBUG
207   logerror("compute_resistor_weights():  scaler = %15.10f\n",scale);
208   logerror("min val :%i  max val:%i  Total number of networks :%i\n", minval, maxval, networks_no );
209
210   for(i = 0; i < networks_no;i++)
211   {
212      double sum = 0.0;
213
214      logerror(" Network no.%i=>  resistances: %i", i, rescount[i] );
215      if (r_pu[i] != 0)
216         logerror(", pullup resistor: %i Ohms",r_pu[i]);
217      if (r_pd[i] != 0)
218         logerror(", pulldown resistor: %i Ohms",r_pd[i]);
219      logerror("\n  maximum output of this network:%10.5f (scaled to %15.10f)\n", max_out[i], max_out[i]*scale );
220      for (n = 0; n < rescount[i]; n++)
221      {
222         logerror("   res %2i:%9.1f Ohms  weight=%10.5f (scaled = %15.10f)\n", n, r[i][n], w[i][n], ws[i][n] );
223         sum += ws[i][n];
224      }
225      logerror("                              sum of scaled weights = %15.10f\n", sum  );
226   }
227#endif
228/* debug end */
229
230   return (scale);
231
232}
233
234
235double compute_resistor_net_outputs(
236   int minval, int maxval, double scaler,
237   int count_1, const int * resistances_1, double * outputs_1, int pulldown_1, int pullup_1,
238   int count_2, const int * resistances_2, double * outputs_2, int pulldown_2, int pullup_2,
239   int count_3, const int * resistances_3, double * outputs_3, int pulldown_3, int pullup_3 )
240{
241
242   int networks_no;
243
244   int rescount[MAX_NETS];      /* number of resistors in each of the nets */
245   double r[MAX_NETS][MAX_RES_PER_NET];      /* resistances */
246   double *o;               /* calulated outputs */
247   double *os;               /* calulated, scaled outputss */
248   int r_pd[MAX_NETS];         /* pulldown resistances */
249   int r_pu[MAX_NETS];         /* pullup resistances */
250
251   double max_out[MAX_NETS];
252   double min_out[MAX_NETS];
253   double * out[MAX_NETS];
254
255   int i,j,n;
256   double scale;
257   double min;
258   double max;
259
260   /* parse input parameters */
261
262   o  = malloc_or_die( sizeof(double) * (1<<MAX_RES_PER_NET) *  MAX_NETS);
263   os = malloc_or_die( sizeof(double) * (1<<MAX_RES_PER_NET) *  MAX_NETS);
264
265   networks_no = 0;
266   for (n = 0; n < MAX_NETS; n++)
267   {
268      int count, pd, pu;
269      const int * resistances;
270      double * weights;
271
272      switch(n){
273      case 0:
274            count      = count_1;
275            resistances   = resistances_1;
276            weights      = outputs_1;
277            pd         = pulldown_1;
278            pu         = pullup_1;
279            break;
280      case 1:
281            count      = count_2;
282            resistances   = resistances_2;
283            weights      = outputs_2;
284            pd         = pulldown_2;
285            pu         = pullup_2;
286            break;
287      case 2:
288      default:
289            count      = count_3;
290            resistances   = resistances_3;
291            weights      = outputs_3;
292            pd         = pulldown_3;
293            pu         = pullup_3;
294            break;
295      }
296
297      /* parameters validity check */
298      if (count > MAX_RES_PER_NET)
299      {
300         logerror(" ERROR: res_net.h: compute_resistor_net_outputs(): too many resistors in net #%i. The maximum allowed is %i, the number requested was: %i\n",n, MAX_RES_PER_NET, count);
301         /* quit */
302         free(o);
303         free(os);
304         return (0.0);
305      }
306
307      if (count > 0)
308      {
309         rescount[networks_no] = count;
310         for (i=0; i < count; i++)
311         {
312            r[networks_no][i] = 1.0 * resistances[i];
313         }
314         out[networks_no] = weights;
315         r_pd[networks_no] = pd;
316         r_pu[networks_no] = pu;
317         networks_no++;
318      }
319   }
320
321   if (networks_no<1)
322   {
323      /* error - no networks to anaylse */
324      logerror(" ERROR: res_net.h: compute_resistor_net_outputs(): no input data\n");
325      free(o);
326      free(os);
327      return (0.0);
328   }
329
330   /* calculate outputs for all given networks */
331   for( i = 0; i < networks_no; i++ )
332   {
333      double R0, R1, Vout, dst;
334
335      /* of n resistors, generating 1<<n possible outputs */
336      for(n = 0; n < (1<<rescount[i]); n++)
337      {
338         R0 = ( r_pd[i] == 0 ) ? 1.0/1e12 : 1.0/r_pd[i];
339         R1 = ( r_pu[i] == 0 ) ? 1.0/1e12 : 1.0/r_pu[i];
340
341         for( j = 0; j < rescount[i]; j++ )
342         {
343            if( (n & (1<<j)) == 0 )/* only when this resistance in the network connected to GND */
344               if (r[i][j] != 0.0)
345                  R0 += 1.0/r[i][j];
346         }
347
348         /* now determine the voltage */
349         R0 = 1.0/R0;
350         R1 = 1.0/R1;
351         Vout = (maxval - minval) * R0 / (R1 + R0) + minval;
352
353         /* and convert it to a destination value */
354         dst = (Vout < minval) ? minval : (Vout > maxval) ? maxval : Vout;
355
356         o[i*(1<<MAX_RES_PER_NET)+n] = dst;
357      }
358   }
359
360   /* calculate minimum outputs for all given networks */
361   j = 0;
362   min = maxval;
363   max = minval;
364   for( i = 0; i < networks_no; i++ )
365   {
366      double val = 0.0;
367      double max_tmp = minval;
368      double min_tmp = maxval;
369
370      for (n = 0; n < (1<<rescount[i]); n++)
371      {
372         if (min_tmp > o[i*(1<<MAX_RES_PER_NET)+n])
373            min_tmp = o[i*(1<<MAX_RES_PER_NET)+n];
374         if (max_tmp < o[i*(1<<MAX_RES_PER_NET)+n])
375            max_tmp = o[i*(1<<MAX_RES_PER_NET)+n];
376      }
377
378      max_out[i] = max_tmp;   /* maximum output */
379      min_out[i] = min_tmp;   /* minimum output */
380
381      val = min_out[i];   /* minimum output of this network */
382      if (min > val)
383      {
384         min = val;
385      }
386      val = max_out[i];   /* maximum output of this network */
387      if (max < val)
388      {
389         max = val;
390      }
391   }
392
393
394   if (scaler < 0.0)   /* use autoscale ? */
395      /* calculate the output scaler according to the network with the smallest output */
396      scale = ((double)maxval) / (max-min);
397   else            /* use scaler provided on entry */
398      scale = scaler;
399
400   /* calculate scaled output and fill the output table(s) */
401   for(i = 0; i < networks_no; i++)
402   {
403      for (n = 0; n < (1<<rescount[i]); n++)
404      {
405         os[i*(1<<MAX_RES_PER_NET)+n] = (o[i*(1<<MAX_RES_PER_NET)+n] - min) * scale;   /* scale the result */
406         (out[i])[n] = os[i*(1<<MAX_RES_PER_NET)+n];      /* fill the output table */
407      }
408   }
409
410/* debug code */
411#ifdef MAME_DEBUG
412   logerror("compute_resistor_net_outputs():  scaler = %15.10f\n",scale);
413   logerror("min val :%i  max val:%i  Total number of networks :%i\n", minval, maxval, networks_no );
414
415   for(i = 0; i < networks_no;i++)
416   {
417      logerror(" Network no.%i=>  resistances: %i", i, rescount[i] );
418      if (r_pu[i] != 0)
419         logerror(", pullup resistor: %i Ohms",r_pu[i]);
420      if (r_pd[i] != 0)
421         logerror(", pulldown resistor: %i Ohms",r_pd[i]);
422      logerror("\n  maximum output of this network:%10.5f", max_out[i] );
423      logerror("\n  minimum output of this network:%10.5f\n", min_out[i] );
424      for (n = 0; n < rescount[i]; n++)
425      {
426         logerror("   res %2i:%9.1f Ohms\n", n, r[i][n]);
427      }
428      for (n = 0; n < (1<<rescount[i]); n++)
429      {
430         logerror("   combination %2i  out=%10.5f (scaled = %15.10f)\n", n, o[i*(1<<MAX_RES_PER_NET)+n], os[i*(1<<MAX_RES_PER_NET)+n] );
431      }
432   }
433#endif
434/* debug end */
435
436   free(o);
437   free(os);
438   return (scale);
439
440}
src/mame/video/res_net.h
r1046r1047
1#ifndef _res_net_h_
2#define _res_net_h_
3
4
5double compute_resistor_weights(
6   int minval, int maxval, double scaler,
7   int count_1, const int * resistances_1, double * weights_1, int pulldown_1, int pullup_1,
8   int count_2, const int * resistances_2, double * weights_2, int pulldown_2, int pullup_2,
9   int count_3, const int * resistances_3, double * weights_3, int pulldown_3, int pullup_3 );
10
11#define combine_8_weights(tab,w0,w1,w2,w3,w4,w5,w6,w7)   ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4) + (tab)[5]*(w5) + (tab)[6]*(w6) + (tab)[7]*(w7)) + 0.5))
12#define combine_7_weights(tab,w0,w1,w2,w3,w4,w5,w6)      ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4) + (tab)[5]*(w5) + (tab)[6]*(w6)) + 0.5))
13#define combine_6_weights(tab,w0,w1,w2,w3,w4,w5)      ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4) + (tab)[5]*(w5)) + 0.5))
14#define combine_5_weights(tab,w0,w1,w2,w3,w4)         ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4)) + 0.5))
15#define combine_4_weights(tab,w0,w1,w2,w3)            ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3)) + 0.5))
16#define combine_3_weights(tab,w0,w1,w2)               ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2)) + 0.5))
17#define combine_2_weights(tab,w0,w1)               ((int)(((tab)[0]*(w0) + (tab)[1]*(w1)) + 0.5))
18
19
20
21/* this should be moved to one of the core files */
22
23#define MAX_NETS 3
24#define MAX_RES_PER_NET 18
25
26
27
28
29/* for the open collector outputs PROMs */
30
31double compute_resistor_net_outputs(
32   int minval, int maxval, double scaler,
33   int count_1, const int * resistances_1, double * outputs_1, int pulldown_1, int pullup_1,
34   int count_2, const int * resistances_2, double * outputs_2, int pulldown_2, int pullup_2,
35   int count_3, const int * resistances_3, double * outputs_3, int pulldown_3, int pullup_3 );
36
37
38
39#endif /*_res_net_h_*/
src/mame/video/dorachan.c
r1046r1047
1#include "driver.h"
2
3const static int fakecols[]= /* fake color map , based on screenshots */
4{
50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
67,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
72,2,2,2,2,2,2,2,2,2,5,5,5,5,5,5,5,5,5,5,5,3,3,3,3,3,3,3,3,3,3,3,
87,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
97,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
107,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
117,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
127,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
137,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
141,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
156,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
166,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
176,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
186,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
196,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
206,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
213,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
223,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
233,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
243,3,3,3,3,3,3,3,3,3,3,3,2,2,1,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
253,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
263,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,3,3,3,3,3,
273,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,3,3,3,3,3,
287,7,7,7,7,7,2,2,2,2,2,7,7,7,7,7,7,7,7,7,7,7,2,2,1,2,2,7,7,7,7,7,
297,7,7,7,7,7,2,2,2,2,2,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
307,7,7,7,7,7,2,2,1,2,2,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
317,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
327,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
337,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
343,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
354,4,4,4,4,4,4,4,7,7,7,7,7,7,7,7,7,1,1,1,1,1,7,7,7,7,7,7,2,2,2,2,
367,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
37};
38
39int dorachan_ctrl; /* bit 6 - screen flip */
40
41WRITE8_HANDLER( dorachan_videoram_w )
42{
43   if (videoram[offset] != data)
44   {
45      int i,x,y,col;
46      videoram[offset] = data;
47      x=((offset>>3)&31)<<3;
48      y=((offset>>8)<<3)^0xff;
49      col=(dorachan_ctrl&0x40)?fakecols[((31-(y>>3))<<5)+31-(x>>3)]:fakecols[((y>>3)<<5)+(x>>3)];
50      x+=offset&7;
51      for (i = 0; i < 8; i++)
52      {
53         *BITMAP_ADDR16(tmpbitmap, 255-x, y) = (data&1)?Machine->pens[col]:Machine->pens[0];
54         y--;
55         data >>= 1;
56      }
57   }
58}
src/mame/drivers/leprechn.c
r1046r1047
1/***************************************************************************
2
3 Leprechaun/Pot of Gold
4
5 driver by Zsolt Vasvari
6
7 Hold down F2 while pressing F3 to enter test mode. Hit Advance (F1) to
8 cycle through test and hit F2 to execute.
9
10
11 TODO:
12 -----
13
14 - Is the 0800-081e range on the sound board mapped to a VIA?
15   I don't think so, but needs to be checked.
16
17 - The following VIA lines appear to be used but aren't mapped:
18
19   VIA #0 CA2
20   VIA #0 IRQ
21   VIA #2 CB2 - This is probably a sound CPU halt or reset.  See potogold $8a5a
22
23 ***************************************************************************/
24
25#include "driver.h"
26#include "cpu/m6502/m6502.h"
27#include "machine/6522via.h"
28#include "leprechn.h"
29#include "sound/ay8910.h"
30
31
32
33static ADDRESS_MAP_START( readmem, ADDRESS_SPACE_PROGRAM, 8 )
34    AM_RANGE(0x0000, 0x03ff) AM_READ(MRA8_RAM)
35   AM_RANGE(0x2000, 0x200f) AM_READ(via_0_r)
36   AM_RANGE(0x2800, 0x280f) AM_READ(via_1_r)
37   AM_RANGE(0x3000, 0x300f) AM_READ(via_2_r)
38    AM_RANGE(0x8000, 0xffff) AM_READ(MRA8_ROM)
39ADDRESS_MAP_END
40
41static ADDRESS_MAP_START( writemem, ADDRESS_SPACE_PROGRAM, 8 )
42    AM_RANGE(0x0000, 0x03ff) AM_WRITE(MWA8_RAM)
43   AM_RANGE(0x2000, 0x200f) AM_WRITE(via_0_w)
44   AM_RANGE(0x2800, 0x280f) AM_WRITE(via_1_w)
45   AM_RANGE(0x3000, 0x300f) AM_WRITE(via_2_w)
46    AM_RANGE(0x8000, 0xffff) AM_WRITE(MWA8_ROM)
47ADDRESS_MAP_END
48
49
50static ADDRESS_MAP_START( sound_readmem, ADDRESS_SPACE_PROGRAM, 8 )
51    AM_RANGE(0x0000, 0x01ff) AM_READ(MRA8_RAM)
52    AM_RANGE(0x0800, 0x0800) AM_READ(soundlatch_r)
53    AM_RANGE(0x0804, 0x0804) AM_READ(MRA8_RAM)   // ???
54    AM_RANGE(0x0805, 0x0805) AM_READ(leprechn_sh_0805_r)   // ???
55    AM_RANGE(0x080c, 0x080c) AM_READ(MRA8_RAM)   // ???
56    AM_RANGE(0xa001, 0xa001) AM_READ(AY8910_read_port_0_r) // ???
57    AM_RANGE(0xf000, 0xffff) AM_READ(MRA8_ROM)
58ADDRESS_MAP_END
59
60static ADDRESS_MAP_START( sound_writemem, ADDRESS_SPACE_PROGRAM, 8 )
61    AM_RANGE(0x0000, 0x01ff) AM_WRITE(MWA8_RAM)
62    AM_RANGE(0x0801, 0x0803) AM_WRITE(MWA8_RAM)   // ???
63    AM_RANGE(0x0806, 0x0806) AM_WRITE(MWA8_RAM)   // ???
64    AM_RANGE(0x081e, 0x081e) AM_WRITE(MWA8_RAM)   // ???
65    AM_RANGE(0xa000, 0xa000) AM_WRITE(AY8910_control_port_0_w)
66    AM_RANGE(0xa002, 0xa002) AM_WRITE(AY8910_write_port_0_w)
67    AM_RANGE(0xf000, 0xffff) AM_WRITE(MWA8_ROM)
68ADDRESS_MAP_END
69
70
71INPUT_PORTS_START( leprechn )
72    // All of these ports are read indirectly through a VIA mapped at 0x2800
73    PORT_START      /* Input Port 0 */
74    PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_TILT ) // This is called "Slam" in the game
75    PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME( DEF_STR( Service_Mode )) PORT_CODE(KEYCODE_F2)
76    PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Advance") PORT_CODE(KEYCODE_F1)
77    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN2 )
78    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN1 )
79    PORT_BIT( 0x23, IP_ACTIVE_LOW, IPT_UNUSED )
80
81    PORT_START      /* Input Port 1 */
82    PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_UNUSED )
83    PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
84    PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
85    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
86    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
87
88    PORT_START      /* Input Port 2 */
89    PORT_BIT( 0x5f, IP_ACTIVE_LOW, IPT_UNUSED )
90    PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
91    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )
92
93    PORT_START      /* Input Port 3 */
94    PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_UNUSED )
95    PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
96    PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
97    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
98    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
99
100    PORT_START      /* DSW #1 */
101    PORT_DIPNAME( 0x09, 0x09, DEF_STR( Coin_B ) )
102    PORT_DIPSETTING(    0x09, DEF_STR( 1C_1C ) )
103    PORT_DIPSETTING(    0x01, DEF_STR( 1C_5C ) )
104    PORT_DIPSETTING(    0x08, DEF_STR( 1C_6C ) )
105    PORT_DIPSETTING(    0x00, DEF_STR( 1C_7C ) )
106    PORT_DIPNAME( 0x22, 0x22, "Max Credits" )
107    PORT_DIPSETTING(    0x22, "10" )
108    PORT_DIPSETTING(    0x20, "20" )
109    PORT_DIPSETTING(    0x02, "30" )
110    PORT_DIPSETTING(    0x00, "40" )
111    PORT_DIPNAME( 0x04, 0x04, DEF_STR( Cabinet ) )
112    PORT_DIPSETTING(    0x04, DEF_STR( Upright ) )
113    PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
114    PORT_DIPNAME( 0x10, 0x10, DEF_STR( Free_Play ) )
115    PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
116    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
117    PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_A ) )
118    PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) )
119    PORT_DIPSETTING(    0x40, DEF_STR( 1C_2C ) )
120    PORT_DIPSETTING(    0x80, DEF_STR( 1C_3C ) )
121    PORT_DIPSETTING(    0x00, DEF_STR( 1C_4C ) )
122
123    PORT_START      /* DSW #2 */
124    PORT_DIPNAME( 0x01, 0x00, DEF_STR( Demo_Sounds ) )
125    PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
126    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
127    PORT_DIPNAME( 0x08, 0x08, DEF_STR( Lives ) )
128    PORT_DIPSETTING(    0x08, "3" )
129    PORT_DIPSETTING(    0x00, "4" )
130    PORT_DIPNAME( 0xc0, 0x40, DEF_STR( Bonus_Life ) )
131    PORT_DIPSETTING(    0x40, "30000" )
132    PORT_DIPSETTING(    0x80, "60000" )
133    PORT_DIPSETTING(    0x00, "90000" )
134    PORT_DIPSETTING(    0xc0, DEF_STR( None ) )
135    PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
136    PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
137    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
138    PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
139    PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
140    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
141    PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
142    PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
143    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
144    PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
145    PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
146    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
147INPUT_PORTS_END
148
149
150INPUT_PORTS_START( piratetr )
151    // All of these ports are read indirectly through a VIA mapped at 0x2800
152    PORT_START      /* Input Port 0 */
153    PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_TILT ) // This is called "Slam" in the game
154    PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME( DEF_STR( Service_Mode )) PORT_CODE(KEYCODE_F2)
155    PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Advance") PORT_CODE(KEYCODE_F1)
156    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN2 )
157    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN1 )
158    PORT_BIT( 0x23, IP_ACTIVE_LOW, IPT_UNUSED )
159
160    PORT_START      /* Input Port 1 */
161    PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_UNUSED )
162    PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
163    PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
164    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
165    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
166
167    PORT_START      /* Input Port 2 */
168    PORT_BIT( 0x5f, IP_ACTIVE_LOW, IPT_UNUSED )
169    PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
170    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )
171
172    PORT_START      /* Input Port 3 */
173    PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_UNUSED )
174    PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
175    PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
176    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
177    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
178
179    PORT_START      /* DSW #1 */
180    PORT_DIPNAME( 0x09, 0x09, DEF_STR( Coin_B ) )
181    PORT_DIPSETTING(    0x09, DEF_STR( 1C_1C ) )
182    PORT_DIPSETTING(    0x01, DEF_STR( 1C_5C ) )
183    PORT_DIPSETTING(    0x08, DEF_STR( 1C_6C ) )
184    PORT_DIPSETTING(    0x00, DEF_STR( 1C_7C ) )
185    PORT_DIPNAME( 0x22, 0x22, "Max Credits" )
186    PORT_DIPSETTING(    0x22, "10" )
187    PORT_DIPSETTING(    0x20, "20" )
188    PORT_DIPSETTING(    0x02, "30" )
189    PORT_DIPSETTING(    0x00, "40" )
190    PORT_DIPNAME( 0x04, 0x04, DEF_STR( Cabinet ) )
191    PORT_DIPSETTING(    0x04, DEF_STR( Upright ) )
192    PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
193    PORT_DIPNAME( 0x10, 0x10, DEF_STR( Free_Play ) )
194    PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
195    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
196    PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_A ) )
197    PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) )
198    PORT_DIPSETTING(    0x40, DEF_STR( 1C_2C ) )
199    PORT_DIPSETTING(    0x80, DEF_STR( 1C_3C ) )
200    PORT_DIPSETTING(    0x00, DEF_STR( 1C_4C ) )
201
202    PORT_START      /* DSW #2 */
203    PORT_DIPNAME( 0x01, 0x00, DEF_STR( Demo_Sounds ) )
204    PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
205    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
206    PORT_DIPNAME( 0x02, 0x02, "Stringing Check" )
207    PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
208    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
209    PORT_DIPNAME( 0x08, 0x08, DEF_STR( Lives ) )
210    PORT_DIPSETTING(    0x08, "3" )
211    PORT_DIPSETTING(    0x00, "4" )
212    PORT_DIPNAME( 0xc0, 0x40, DEF_STR( Bonus_Life ) )
213    PORT_DIPSETTING(    0x40, "30000" )
214    PORT_DIPSETTING(    0x80, "60000" )
215    PORT_DIPSETTING(    0x00, "90000" )
216    PORT_DIPSETTING(    0xc0, DEF_STR( None ) )
217    PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
218    PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
219    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
220    PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
221    PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
222    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
223    PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
224    PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
225    PORT_DIPSETTING(    0x00, DEF_STR( On ) )
226INPUT_PORTS_END
227
228
229static MACHINE_DRIVER_START( leprechn )
230
231   /* basic machine hardware */
232   // A good test to verify that the relative CPU speeds of the main
233   // and sound are correct, is when you finish a level, the sound
234   // should stop before the display switches to the name of the
235   // next level
236   MDRV_CPU_ADD(M6502, 1250000)    /* 1.25 MHz ??? */
237   MDRV_CPU_PROGRAM_MAP(readmem,writemem)
238   MDRV_CPU_VBLANK_INT(irq0_line_hold,1)
239
240   MDRV_CPU_ADD(M6502, 1500000)
241   /* audio CPU */    /* 1.5 MHz ??? */
242   MDRV_CPU_PROGRAM_MAP(sound_readmem,sound_writemem)
243
244   MDRV_SCREEN_REFRESH_RATE(57)
245   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)
246
247   /* video hardware */
248   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
249   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
250   MDRV_SCREEN_SIZE(256, 256)
251   MDRV_SCREEN_VISIBLE_AREA(0, 256-1, 0, 256-1)
252   MDRV_PALETTE_LENGTH(16)
253
254   MDRV_PALETTE_INIT(leprechn)
255   MDRV_VIDEO_START(leprechn)
256   MDRV_VIDEO_UPDATE(generic_bitmapped)
257
258   /* sound hardware */
259   MDRV_SPEAKER_STANDARD_MONO("mono")
260
261   MDRV_SOUND_ADD(AY8910, 14318000/8)
262   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
263MACHINE_DRIVER_END
264
265
266/***************************************************************************
267
268  Game driver(s)
269
270***************************************************************************/
271
272ROM_START( leprechn )
273   ROM_REGION( 0x10000, REGION_CPU1, 0 )  /* 64k for the main CPU */
274   ROM_LOAD( "lep1",         0x8000, 0x1000, CRC(2c4a46ca) SHA1(28a157c1514bc9f27cc27baddb83cf1a1887f3d1) )
275   ROM_LOAD( "lep2",         0x9000, 0x1000, CRC(6ed26b3e) SHA1(4ee5d09200d9e8f94ae29751c8ee838faa268f15) )
276   ROM_LOAD( "lep3",         0xa000, 0x1000, CRC(a2eaa016) SHA1(be992ee787766137fd800ec59529c98ef2e6991e) )
277   ROM_LOAD( "lep4",         0xb000, 0x1000, CRC(6c12a065) SHA1(2acae6a5b94cbdcc550cee88a7be9254fdae908c) )
278   ROM_LOAD( "lep5",         0xc000, 0x1000, CRC(21ddb539) SHA1(b4dd0a1916adc076fa6084c315459fcb2522161e) )
279   ROM_LOAD( "lep6",         0xd000, 0x1000, CRC(03c34dce) SHA1(6dff202e1a3d0643050f3287f6b5906613d56511) )
280   ROM_LOAD( "lep7",         0xe000, 0x1000, CRC(7e06d56d) SHA1(5f68f2047969d803b752a4cd02e0e0af916c8358) )
281   ROM_LOAD( "lep8",         0xf000, 0x1000, CRC(097ede60) SHA1(5509c41167c066fa4e7f4f4bd1ce9cd00773a82c) )
282
283   ROM_REGION( 0x10000, REGION_CPU2, 0 )  /* 64k for the audio CPU */
284   ROM_LOAD( "lepsound",     0xf000, 0x1000, CRC(6651e294) SHA1(ce2875fc4df61a30d51d3bf2153864b562601151) )
285ROM_END
286
287ROM_START( potogold )
288   ROM_REGION( 0x10000, REGION_CPU1, 0 )  /* 64k for the main CPU */
289   ROM_LOAD( "pog.pg1",      0x8000, 0x1000, CRC(9f1dbda6) SHA1(baf20e9a0793c0f1529396f95a820bd1f9431465) )
290   ROM_LOAD( "pog.pg2",      0x9000, 0x1000, CRC(a70e3811) SHA1(7ee306dc7d75a7d3fd497870ec92bef9d86535e9) )
291   ROM_LOAD( "pog.pg3",      0xa000, 0x1000, CRC(81cfb516) SHA1(12732707e2a51ec39563f2d1e898cc567ab688f0) )
292   ROM_LOAD( "pog.pg4",      0xb000, 0x1000, CRC(d61b1f33) SHA1(da024c0776214b8b5a3e49401c4110e86a1bead1) )
293   ROM_LOAD( "pog.pg5",      0xc000, 0x1000, CRC(eee7597e) SHA1(9b5cd293580c5d212f8bf39286070280d55e4cb3) )
294   ROM_LOAD( "pog.pg6",      0xd000, 0x1000, CRC(25e682bc) SHA1(085d2d553ec10f2f830918df3a7fb8e8c1e5d18c) )
295   ROM_LOAD( "pog.pg7",      0xe000, 0x1000, CRC(84399f54) SHA1(c90ba3e3120adda2785ab5abd309e0a703d39f8b) )
296   ROM_LOAD( "pog.pg8",      0xf000, 0x1000, CRC(9e995a1a) SHA1(5c525e6c161d9d7d646857b27cecfbf8e0943480) )
297
298   ROM_REGION( 0x10000, REGION_CPU2, 0 )  /* 64k for the audio CPU */
299   ROM_LOAD( "pog.snd",      0xf000, 0x1000, CRC(ec61f0a4) SHA1(26944ecc3e7413259928c8b0a74b2260e67d2c4e) )
300ROM_END
301
302ROM_START( leprechp )
303   ROM_REGION( 0x10000, REGION_CPU1, 0 )  /* 64k for the main CPU */
304   ROM_LOAD( "lep1",         0x8000, 0x1000, CRC(2c4a46ca) SHA1(28a157c1514bc9f27cc27baddb83cf1a1887f3d1) )
305   ROM_LOAD( "lep2",         0x9000, 0x1000, CRC(6ed26b3e) SHA1(4ee5d09200d9e8f94ae29751c8ee838faa268f15) )
306   ROM_LOAD( "3u15.bin",     0xa000, 0x1000, CRC(b5f79fd8) SHA1(271f7b55ecda5bb99f40687264256b82649e2141) )
307   ROM_LOAD( "lep4",         0xb000, 0x1000, CRC(6c12a065) SHA1(2acae6a5b94cbdcc550cee88a7be9254fdae908c) )
308   ROM_LOAD( "lep5",         0xc000, 0x1000, CRC(21ddb539) SHA1(b4dd0a1916adc076fa6084c315459fcb2522161e) )
309   ROM_LOAD( "lep6",         0xd000, 0x1000, CRC(03c34dce) SHA1(6dff202e1a3d0643050f3287f6b5906613d56511) )
310   ROM_LOAD( "lep7",         0xe000, 0x1000, CRC(7e06d56d) SHA1(5f68f2047969d803b752a4cd02e0e0af916c8358) )
311   ROM_LOAD( "lep8",         0xf000, 0x1000, CRC(097ede60) SHA1(5509c41167c066fa4e7f4f4bd1ce9cd00773a82c) )
312
313   ROM_REGION( 0x10000, REGION_CPU2, 0 )  /* 64k for the audio CPU */
314   ROM_LOAD( "lepsound",     0xf000, 0x1000, CRC(6651e294) SHA1(ce2875fc4df61a30d51d3bf2153864b562601151) )
315ROM_END
316
317ROM_START( piratetr )
318   ROM_REGION( 0x10000, REGION_CPU1, 0 )  /* 64k for the main CPU */
319   ROM_LOAD( "1u13.bin",     0x8000, 0x1000, CRC(4433bb61) SHA1(eee0d7f356118f8595dd7533541db744a63a8176) )
320   ROM_LOAD( "2u14.bin",     0x9000, 0x1000, CRC(9bdc4b77) SHA1(ebaab8b3024efd3d0b76647085d441ca204ad5d5) )
321   ROM_LOAD( "3u15.bin",     0xa000, 0x1000, CRC(ebced718) SHA1(3a2f4385347f14093360cfa595922254c9badf1a) )
322   ROM_LOAD( "4u16.bin",     0xb000, 0x1000, CRC(f494e657) SHA1(83a31849de8f4f70d7547199f229079f491ddc61) )
323   ROM_LOAD( "5u17.bin",     0xc000, 0x1000, CRC(2789d68e) SHA1(af8f334ce4938cd75143b729c97cfbefd68c9e13) )
324   ROM_LOAD( "6u18.bin",     0xd000, 0x1000, CRC(d91abb3a) SHA1(11170e69686c2a1f2dc31d41516f44b612f99bad) )
325   ROM_LOAD( "7u19.bin",     0xe000, 0x1000, CRC(6e8808c4) SHA1(d1f76fd37d8f78552a9d53467073cc9a571d96ce) )
326   ROM_LOAD( "8u20.bin",     0xf000, 0x1000, CRC(2802d626) SHA1(b0db688500076ee73e0001c00089a8d552c6f607) )
327
328   ROM_REGION( 0x10000, REGION_CPU2, 0 )  /* 64k for the audio CPU */
329   ROM_LOAD( "su31.bin",     0xf000, 0x1000, CRC(2fe86a11) SHA1(aaafe411b9cb3d0221cc2af73d34ad8bb74f8327) )
330ROM_END
331
332
333GAME( 1982, leprechn, 0,        leprechn, leprechn, leprechn, ROT0, "Tong Electronic", "Leprechaun", 0 )
334GAME( 1982, potogold, leprechn, leprechn, leprechn, leprechn, ROT0, "GamePlan", "Pot of Gold", 0 )
335GAME( 1982, leprechp, leprechn, leprechn, leprechn, leprechn, ROT0, "Tong Electronic", "Leprechaun (Pacific Polytechnical license)", 0 )
336GAME( 1982, piratetr, 0,        leprechn, piratetr, leprechn, ROT0, "Tong Electronic", "Pirate Treasure", 0 )
src/mame/drivers/vp906iii.c
r1046r1047
1/*
2
3    Jack Potten's Poker (?)
4    Omega 1981 (?)
5
6    I'm not sure of the name because the board is not working, i guessed the name
7    by looking inside the roms.
8
9    Dumped by ShinobiZ (Thierry) and Coy (Gerald) on 26/12/1998.
10
11    CPU: SY6502
12    SND: SY6545 + AY-3-8912
13    OSC: 10.000
14
15    ROM:
16
17    Program roms are roms 23*.*, on the board, there is a number near each roms
18    looks to be the address of the rom :
19
20            23-91   1800
21            23-92   2000
22            23-93   2800
23            23-94   3000
24            23-9    3800
25
26    Graphics are in roms CG*.*, there is no type indication on these rams, i hope
27    i read them correctly.
28
29    There is also 3 sets of switches on the board :
30
31            SW1     1       300     SW2     1       OPT1
32                    2       600             2       OPT2
33                    3       1200            3       OPT3
34                    4       2400            4       OPT4
35                    5       4800            5       OPT5
36                    6       9600            6       DIS
37                    7       -               7       +VPOL
38                    8       -               8       +HPOL
39
40            SW3     no indications on the board
41
42    The color prom is included (82s129).
43
44    The sound rom is missing on the board :(
45
46    There is also two big chips (same size as the 6502) they are "SY6520/SY6820"
47
48    more infos -> coydumps@hotmail.com
49
50    ---
51
52    http://www.acedistribuslots.com/casino_electronics_inc.htm
53
54    ---
55
56    AGEMAME Driver by Curt Coder
57
58Any fixes for this driver should be forwarded to the AGEMAME forum at (http://www.mameworld.info)
59
60*/
61
62#include "driver.h"
63#include "sound/ay8910.h"
64
65static tilemap *bg_tilemap;
66
67PALETTE_INIT( vp906iii )
68{
69   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
70
71   int i;
72
73   for (i = 0; i < 0x100; i++)
74   {
75      COLOR(0, i) = (*color_prom) & 0x0f;
76      color_prom++;
77   }
78
79#if 0
80   for (i = 0; i < machine->drv->total_colors; i++)
81   {
82      int bit0, bit1, bit2, bit3, r, g, b;
83
84      // red component
85
86      bit0 = (*color_prom >> 0) & 0x01;
87      bit1 = (*color_prom >> 1) & 0x01;
88      bit2 = (*color_prom >> 2) & 0x01;
89      bit3 = (*color_prom >> 3) & 0x01;
90
91      r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
92
93      color_prom++;
94
95      // green component
96
97      bit0 = (*color_prom >> 0) & 0x01;
98      bit1 = (*color_prom >> 1) & 0x01;
99      bit2 = (*color_prom >> 2) & 0x01;
100      bit3 = (*color_prom >> 3) & 0x01;
101
102      g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
103
104      color_prom++;
105
106      // blue component
107
108      bit0 = (*color_prom >> 0) & 0x01;
109      bit1 = (*color_prom >> 1) & 0x01;
110      bit2 = (*color_prom >> 2) & 0x01;
111      bit3 = (*color_prom >> 3) & 0x01;
112
113      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
114
115      color_prom++;
116
117      palette_set_color(machine, i, r, g, b);
118   }
119#endif
120}
121
122WRITE8_HANDLER( vp906iii_videoram_w )
123{
124   if (videoram[offset] != data)
125   {
126      videoram[offset] = data;
127      tilemap_mark_tile_dirty(bg_tilemap, offset);
128   }
129}
130
131WRITE8_HANDLER( vp906iii_colorram_w )
132{
133   if (colorram[offset] != data)
134   {
135      colorram[offset] = data;
136      tilemap_mark_tile_dirty(bg_tilemap, offset);
137   }
138}
139
140static void get_bg_tile_info(int tile_index)
141{
142   int attr = colorram[tile_index];
143   int code = videoram[tile_index];
144   int color = attr & 0xff;
145
146   SET_TILE_INFO(0, code, color, 0)
147}
148
149VIDEO_START(vp906iii)
150{
151   bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
152      TILEMAP_OPAQUE, 8, 8, 32, 32);
153
154   return 0;
155}
156
157VIDEO_UPDATE(vp906iii)
158{
159   tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
160   return 0;
161}
162
163static ADDRESS_MAP_START( vp906iii_map, ADDRESS_SPACE_PROGRAM, 8 )
164   AM_RANGE(0x0000, 0x07ff) AM_RAM
165   AM_RANGE(0x0880, 0x0880) AM_WRITE(AY8910_control_port_0_w)
166   AM_RANGE(0x0881, 0x0881) AM_WRITE(AY8910_write_port_0_w)
167   AM_RANGE(0x08c4, 0x08c4) AM_READ(input_port_0_r) AM_WRITENOP // ???
168   AM_RANGE(0x08c5, 0x08c5) AM_WRITENOP // ???
169   AM_RANGE(0x08c6, 0x08c6) AM_READ(input_port_1_r) AM_WRITENOP // ???
170   AM_RANGE(0x08c7, 0x08c7) AM_WRITENOP // ???
171   AM_RANGE(0x08c8, 0x08c8) AM_READ(input_port_2_r) AM_WRITENOP // ???
172   AM_RANGE(0x08c9, 0x08c9) AM_WRITENOP // ???
173   AM_RANGE(0x08ca, 0x08ca) AM_READ(input_port_3_r) AM_WRITENOP // ???
174   AM_RANGE(0x08cb, 0x08cb) AM_WRITENOP // ???
175   AM_RANGE(0x1000, 0x13ff) AM_RAM AM_WRITE(vp906iii_videoram_w) AM_BASE(&videoram)
176   AM_RANGE(0x1400, 0x17ff) AM_RAM AM_WRITE(vp906iii_colorram_w) AM_BASE(&colorram)
177   AM_RANGE(0xd800, 0xffff) AM_ROM
178ADDRESS_MAP_END
179
180INPUT_PORTS_START( vp906iii )
181   PORT_START_TAG("IN0")
182   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 0") PORT_CODE(KEYCODE_Q)
183   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 1") PORT_CODE(KEYCODE_W)
184   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 2") PORT_CODE(KEYCODE_E)
185   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 3") PORT_CODE(KEYCODE_R)
186   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 4") PORT_CODE(KEYCODE_T)
187   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 5") PORT_CODE(KEYCODE_Y)
188   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 6") PORT_CODE(KEYCODE_U)
189   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 7") PORT_CODE(KEYCODE_I)
190
191   PORT_START_TAG("IN1")
192   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 0") PORT_CODE(KEYCODE_A)
193   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 1") PORT_CODE(KEYCODE_S)
194   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 2") PORT_CODE(KEYCODE_D)
195   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 3") PORT_CODE(KEYCODE_F)
196   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 4") PORT_CODE(KEYCODE_G)
197   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 5") PORT_CODE(KEYCODE_H)
198   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 6") PORT_CODE(KEYCODE_J)
199   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bit 7") PORT_CODE(KEYCODE_K)
200
201   PORT_START_TAG("DSW0")
202   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
203   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
204   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
205   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
206   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
207   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
208   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
209   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
210   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
211   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
212   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
213   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
214   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
215   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
216   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
217   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
218   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
219   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
220   PORT_DIPNAME( 0x40, 0x40, "Set max bet to 40")
221   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
222   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
223   PORT_DIPNAME( 0x80, 0x80, "Set max bet to 10")
224   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
225   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
226
227   PORT_START_TAG("DSW1")
228   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
229   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
230   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
231   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
232   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
233   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
234   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
235   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
236   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
237   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
238   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
239   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
240   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
241   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
242   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
243   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
244   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
245   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
246   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
247   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
248   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
249   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
250   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
251   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
252INPUT_PORTS_END
253
254static const gfx_layout charlayout =
255{
256   8, 8,
257   1024,
258   1,
259   { 0 },
260   { 0, 1, 2, 3, 4, 5, 6, 7 },
261   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
262   8*8
263};
264
265static const gfx_decode gfxdecodeinfo[] =
266{
267   { REGION_GFX1, 0x0000, &charlayout,      0, 64 },
268   { -1 }
269};
270
271
272static MACHINE_DRIVER_START( vp906iii )
273   // basic machine hardware
274   MDRV_CPU_ADD(M6502, 10000000/12)   // ???
275   MDRV_CPU_PROGRAM_MAP(vp906iii_map, 0)
276   MDRV_CPU_VBLANK_INT(irq0_line_hold, 1)
277
278   MDRV_SCREEN_REFRESH_RATE(60)
279   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)
280
281   // video hardware
282   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
283   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
284   MDRV_SCREEN_SIZE(32*8, 32*8)
285   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 0*8, 32*8-1)
286
287   MDRV_GFXDECODE(gfxdecodeinfo)
288   MDRV_PALETTE_LENGTH(16)
289   MDRV_COLORTABLE_LENGTH(256)
290
291   MDRV_PALETTE_INIT(vp906iii)
292   MDRV_VIDEO_START(vp906iii)
293   MDRV_VIDEO_UPDATE(vp906iii)
294
295   // sound hardware
296   MDRV_SPEAKER_STANDARD_MONO("mono")
297
298   MDRV_SOUND_ADD(AY8910, 10000000/12)
299   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
300
301MACHINE_DRIVER_END
302
303ROM_START( vp906iii )
304   ROM_REGION( 0x10000, REGION_CPU1, 0 )
305   ROM_LOAD( "23-91.u5",    0xd800, 0x0800, CRC(b49035e2) SHA1(b94a0245ca64d15b1496d1b272ffc0ce80f85526) )
306   ROM_LOAD( "23-92.u6",    0xe000, 0x0800, CRC(d9ffaa73) SHA1(e39d10121e16f89cd8d30a5391a14dc3d4b13a46) )
307   ROM_LOAD( "23-93.u7",    0xe800, 0x0800, CRC(f4e44280) SHA1(a03e5f03ed86c8ad7900fab0ef6a71c76eba3232) )
308   ROM_LOAD( "23-94.u8",    0xf000, 0x0800, CRC(8372f4d0) SHA1(de289b65cbe30c92b46fa87b9262ff7f9cfa0431) )
309   ROM_LOAD( "23-9.u9",    0xf800, 0x0800, CRC(bfcb934d) SHA1(b7cfa049bdd773368cb8326bcdfabbf474d15bb4) )
310
311   ROM_REGION( 0x18000, REGION_GFX1, ROMREGION_DISPOSE )
312   ROM_LOAD( "cg-0.u67",    0x0000, 0x0800, CRC(b626ad89) SHA1(551b75f4559d11a4f8f56e38982114a21c77d4e7) )
313   ROM_LOAD( "cg-2a.u68",    0x0800, 0x0800, CRC(6e3e9b1d) SHA1(14eb8d14ce16719a6ad7d13db01e47c8f05955f0) )
314   ROM_LOAD( "cg-2b.u69",    0x1000, 0x0800, CRC(6bbb1e2d) SHA1(51ee282219bf84218886ad11a24bc6a8e7337527) )
315   ROM_LOAD( "cg-2c.u70",    0x1800, 0x0800, CRC(f2f94661) SHA1(f37f7c0dff680fd02897dae64e13e297d0fdb3e7) )
316
317   ROM_REGION( 0x10000, REGION_CPU2, 0 )
318   ROM_LOAD( "sound.rom",    0x0000, 0x0800, NO_DUMP ) // sound rom is missing according to readme info
319
320   ROM_REGION( 0x100, REGION_PROMS, 0 )
321   ROM_LOAD( "82s129n.u28", 0x0000, 0x0100, CRC(6db5a344) SHA1(5f1a81ac02a2a74252decd3bb95a5436cc943930) )
322ROM_END
323
324GAME( 1985, vp906iii, 0, vp906iii, vp906iii, 0, ROT0, "Casino Electronics Inc.", "906III Video Poker", GAME_NOT_WORKING )
src/mame/drivers/segasyse.c
r1046r1047
1/* THIS DRIVER IS OBSOLETE, BUT A FEW OTHERS STILL DEPEND ON VARIOUS BITS
2 once the megatech / megaplay etc. drivers have been rewritten this should
3 be removed.
4
5 System E emulation is now in src\mame\drivers\segae.c
6*/
7
8/*******************************************************************************
9 Sega System E (834-5803) Driver (drivers/segasyse.c)
10********************************************************************************
11 driver by David Haywood
12
13 Special Thanks to:
14
15 Charles Macdonald - for docmentation of the SMS VDP Chip used on this system,
16 visit his homepage (cgfm2.emuviews.com) for some excellent documents, and other
17 interesting bits and pieces
18
19 Mike Beaver - Mimic, although not used as a reference, it was used as an
20 inspiration & motivation :p
21
22 Stephane Humbert - Dipswitch Information, Z80 Help, Lots of Notes of ROP, help
23 with the controller for ROP, and generally being an all round great guy to
24 work with.
25
26********************************************************************************
27
28 Sega System 'E' is a piece of hardware used for a couple of Arcade Games
29 produced by Sega in the Mid 80's, its roughly based on their Sega Master System
30 home console unit, using the same '315-5124' VDP (actually in this case 2 of
31 them)
32
33 An interesting feature of the system is that the CPU is contained on the ROM
34 board, the MAIN System E board contains the Graphics processor, this opens the
35 possibility for using processors other than the Standard Z80 to run the main
36 game code on, an option which they appear to have made use of for a couple of
37 the titles unless of course the roms are simply bad dumps.
38
39 Also interesting is each VDP has double the Video RAM found on the SMS console
40 this is banked through Port Writes, the System also allows for the Video RAM
41 to be written directly, bypassing the usual procedure of writing to it via the
42 '315-5124' data port, it can not however be read directly, the same area used
43 for writing is used to access banked ROMs when reading
44
45 Pretty much everything on this hardware is done through port accesses, the
46 main memory map consists of simply ROM, BANKED ROM / BANKED RAM, RAM
47
48********************************************************************************
49
50    ROMs + CPU Board (32kb ROMs)
51
52    IC 07 (Good)    IC 05 (Good)
53    IC 04 (Good)    IC 03 (Good)
54    IC 02 (Good)
55
56    (834-5803) MAIN Board (8kb RAMs)
57
58    IC 49 (Good)    IC 55 (Good)    System RAM (0xc000 - 0xffff)
59    IC 03 (Good)    IC 07 (Good)    Front Layer VRAM (Bank 1)   Port F7 -0------
60    IC 04 (Good)    IC 08 (Good)    Front Layer VRAM (Bank 2)   Port F7 -1------
61    IC 01 (Good)    IC 05 (Good)    Back Layer VRAM (Bank 1)    Port F7 0-------
62    IC 02 (Good)    IC 06 (Good)    Back Layer VRAM (Bank 2)    Port F7 1-------
63    (or at least this is how it appears from HangOnJr's RAMs Test)
64
65    2x (315-5124)'s here too, these are the VDP chips
66
67    PORTS (to be completed)
68
69    0xba - 0xbb r/w     Back Layer VDP
70    0xbe - 0xbf r/w     Front Layer VDP
71
72    0xf7 w/o            Banking Controls
73
74    0xe0 r/o            Inputs (Coins, Start Btns)
75    0xe1 r/o            Controls (Transformer)
76
77    0xf2 - 0xf3 r/o     Dipswitches
78
79    0xf8 r/o            Analog Input (Hang On Jr)
80
81    0x7e r/o            V Counter (vertical beam pos in scanlines)
82    0x7f r/o            H Counter (horizontal beam pos in 'pixel clock cycles')
83
84********************************************************************************
85
86Sega System E Hardware Overview
87Sega, 1985-1988
88
89This PCB is essentially a Sega Master System home console unit, but using
90two '315-5124' VDPs and extra RAM.
91The CPU is located on a plug-in board that also holds all of the EPROMs.
92
93The games that run on this hardware include....
94Hang-On Jr.             1985
95Transformer/Astro Flash 1986
96Riddle of Pythagoras    1986
97Opa Opa                 1987
98Fantasy Zone 2          1988
99Tetris                  1988
100
101PCB Layout
102----------
103834-5803 (C)Sega 1985
104|-----------------------------------------------------|
105|         D4168      D4168      D4168       D4168     |
106|                                                     |
107|         D4168      D4168      D4168       D4168     |
108|                                                     |
109|                                                     |
110|    SW1                                              |
111|CN1                                                  |
112|    SW2                                              |
113|                                                     |
114|   LED            |---|             |---|            |
115|                  | 3 |             | 3 |            |
116|                  | 1 |             | 1 |            |
117|                  | 5 |             | 5 |            |
118|                  | | |             | | |         CN3|
119|                  | 5 |             | 5 |     8255   |
120|CN4               | 1 |             | 1 |            |
121|                  | 2 |             | 2 |            |
122|                  | 4 |             | 4 |            |
123|                  |---|             |---|            |
124|               |--------ROM-BOARD-(above)---------|  |
125|               |                                  |  |
126|               |CN2                   10.7386MHz  |  |
127|               |         D4168                    |  |
128|  VOL          |         D4168                    |  |
129| LA4460        |----------------------------------|  |
130|-----------------------------------------------------|
131Notes:
132      315-5124 VDP clock - 10.7386MHz
133      SN76496 clock      - 3.579533MHz [10.7386/3]
134      D4168              - 8k x8 SRAM
135      VSync              - 60Hz
136      HSync              - 15.58kHz
137      CN1                - Connector used for standard controls
138      CN2                - connector for CPU/ROM PCB
139      CN3                - Connector used for special controls (via a small plug-in interface PCB)
140      CN4                - Connector for power
141
142ROM Daughterboard
143-----------------
144834-6592-01
145|--------------------------------------------|
146|                                            |
147|    |---|                                   |
148|C   |   |                           IC6     |
149|N   |Z80|                                   |
150|2   |   |                                   |
151|    |   |   IC2   IC3   IC4   IC5        IC7|
152|    |---|                                   |
153|     IC1             PAD1 PAD2     PAD3 PAD4|
154|--------------------------------------------|
155Notes:
156       IC1: Z80 clock - 5.3693MHz [10.7386/2]
157            On some games this is replaced with a NEC MC-8123 Encrypted CPU Module.
158            The clock speed is the same. The MC-8123 contains a Z80 core, plus a RAM chip
159            and battery. When the battery dies, the program can no longer be decrypted
160            and the PCB does not boot up at all. The battery can not be changed because the
161            MC-8123 is sealed, so there is no way to access it.
162
163 IC2 - IC5: 27C256 EPROM (DIP28)
164
165       IC6: 74LS139
166
167       IC7: 27C256 EPROM (DIP28)
168
169    PAD1-4: These are jumper pads used to configure the ROM board for use with the
170            Z80 or with the MC8123 CPU.
171            PAD1 - Ties Z80 pin 24 (WAIT) to pin1 of the EPROMs at IC2, 3, 4 & 5
172            PAD2 - Ties CN2 pin B21 to pin1 of the EPROMs at IC2, 3, 4 & 5
173            PAD3 - Ties CN2 pin B21 to pin 2 of the 74LS139 @ IC6
174            PAD4 - Ties Z80 pin 24 (WAIT) to pin 2 of the 74LS139 @ IC6
175
176            The pads are configured like this..... (U=Upper, L=Lower)
177
178                                                 |----|      |----|
179                                                 |IC6 |      |IC7 |
180                                                 |  12|------|22  |
181                                                 |    |      |    |
182                       IC2   IC3    IC4   IC5    |   1|------|27  |
183                       PIN1  PIN1   PIN1  PIN1   |   2|--|   |    |
184                        O-----O--+---O------O    |----|  |   |----|
185                                 |                       |
186                                 |         |----|        |
187                              O--+----O    |    O    |---O
188            CN2    Z80      PAD1U   PAD2U  |  PAD3U  | PAD4U
189            B21    PIN24    PAD1L   PAD2L  |  PAD3L  | PAD4L
190             O       O--4.7k--O       O----|    O----|   O
191             |                |       |                  |
192             |                |-------|------------------|
193             |                        |
194             |------------------------|
195
196            When using a regular Z80B (and thus, unencrypted code):
197            PAD1 - Open
198            PAD2 - Open
199            PAD3 - Shorted
200            PAD4 - Open
201
202            When using an encrypted CPU module (MC-8123):
203            PAD1 - Open
204            PAD2 - Shorted
205            PAD3 - Open
206            PAD4 - Open
207            Additionally, a wire must be tied from CN2 pin B22 to the side
208            of PAD3 nearest IC6 (i.e. PAD3U).
209
210ROMs:
211-----
212
213Game                     IC2         IC3         IC4         IC5         IC7
214---------------------------------------------------------------------------------
215Hang-On Jr.              EPR-?       EPR-?       EPR-?       EPR-?       EPR-?     Hello, Sega Part Numbers....!?
216Transformer              EPR-7350    EPR-?       EPR-7348    EPR-7347    EPR-?     Ditto
217           /Astro Flash  EPR-7350    EPR-7349    EPR-7348    EPR-7347    EPR-7723
218Riddle of Pythagoras     EPR-10422   EPR-10423   EPR-10424   EPR-10425   EPR-10426
219Opa Opa                  EPR-11220   EPR-11221   EPR-11222   EPR-11223   EPR-11224
220Fantasy Zone 2           EPR-11412   EPR-11413   EPR-11414   EPR-11415   EPR-11416
221Tetris                   -           -           EPR-12211   EPR-12212   EPR-12213
222
223A System E PCB can run all of the games simply by swapping the EPROMs plus CPU.
224Well, in theory anyway. To run the not-encrypted games, just swap EPROMs and they will work.
225
226To run the encrypted games, use a double sized EPROM in IC7 (i.e. a 27C512)
227and program the decrypted opcodes to the lower half and the decrypted data to the upper half,
228then connect the highest address pin of the EPROM (A15 pin 1) to the M1 pin on the Z80.
229This method has been tested and does not actually work. An update on this may follow....
230
231
232System E PCB Pinout
233-------------------
234
235CN1
236---
237
238+12V             1A  1B  Coin switch 1
239Coin switch 2    2A  2B  Test switch
240Service switch   3A  3B
241                 4A  4B  1P start
2422P start         5A  5B  1P up
2431P down          6A  6B  1P left
2441P right         7A  7B  1P button 1
2451P button 2      8A  8B
246                 9A  9B  2P up
2472P down          10A 10B 2P left
2482P RIGHT         11A 11B 2P button 1
2492P button 2      12A 12B
250                 13A 13B Video RED
251                 14A 14B Video GREEN
252                 15A 15B Video BLUE
253                 16A 16B Video SYNC
254                 17A 17B
255                 18A 18B
256Speaker [+]      19A 19B
257Speaker [-]      20A 20B
258Coin counter GND 21A 21B
259GND              22A 22B Coin counter 1
260                 23A 23B Coin counter 2
261                 24A 24B
262                 25A 25B
263CN4
264---
265
266+5V  1A 1B +5V
267+5V  2A 2B +5V
268     3A 3B
269GND  4A 4B GND
270GND  5A 5B GND
271+12V 6A 6B +12V
272+12V 7A 7B +12V
273GND  8A 8B GND
274
275********************************************************************************
276
277 Change Log:
278 18 Aug 2004 | DH - Added Tetris System E
279 14 Jun 2001 | Stephh added the dipswitches to ROP (and coinage to the others
280             | I added Save State support
281 14 Jun 2001 | Nicola improved the Controls for Riddle, stephh added a New
282             | SEGASYSE_COINAGE macro and fixed sorted out the dips in ROP
283 13 Jun 2001 | After A Lot of Messing about, Hair Pulling out etc. Riddle is
284             | now playable :p
285 12 Jun 2001 | First Submitted Version, still a couple of things need doing,
286             | Riddle isn't playable at this stage
287 12 Jun 2001 | Cleaned Up The Code (removed a lot of now redundant stuff in the
288             | interrupt functions, rendering code (dirty tile marking etc.))
289 12 Jun 2001 | Major Updates made, Sound Added, Controls, Sprites, Raster
290             | Corrected, Horizontal Scrolling Corrected, Colours Corrected,
291             | Transformer is now Fully Playable, HangOn-Jr Likewise with
292             | minor gfx glitches in places.
293 11 Jun 2001 | Progressing Nicely, Improvements to the Banking, inc. Writes to
294             | the 0x8000+ range, Raster Interrupts hooked up and sort of
295             | working (looks ok in Transformer, not in Hang-On Jr
296 07 Jun 2001 | Big Clean-Up of Driver so far, lots of things moved around to
297             | make it easier to follow and develop
298 06 Jun 2001 | Improved the Banking a bit, based on what the program seems to be
299             | trying to do as it goes through its RAM/ROM tests, still some
300             | bits of Port 0xF7 writes remain unclear however.
301 05 Jun 2001 | Put in place some very crude rendering code, the RAM / ROM checks
302             | of transfrm now display on the screen
303 04 Jun 2001 | transfrm (Transformer) is showing signs of life, the RAM / ROM
304             | check info can clearly be seen in VRAM, now to try and get some
305             | rendering code working.  Tiles (SEGA logo, Font etc, now also
306             | appear in VRAM)
307 03 Jun 2001 | Driver Rewritten from Scratch after a long period of inactivity,
308             | the VDP core now seems to be running correctly, valid colours can
309             | be seen in CRAM
310
311********************************************************************************
312
313 To Do:
314 - Improve Riddle of Pythagoras, doesn't like the sprite code much...
315 - Fix Vertical Scrolling, needed for Hang-On Jr. Score Screen
316 - Find Register which does the Left column blank, seems to be missing from the
317   docs..
318 - hook up dsw's in riddle, stephh kindly worked them out (see notes below,
319   they just need adding to the input ports
320 - Fix Astro Flash service mode (it works in Transformer)
321
322********************************************************************************
323 Game Notes:
324 Riddle of Pythagoras is interesting, it looks like Sega might have planned it
325 as a two player game, there is prelimiary code for 2 player support which
326 never gets executed, see code around 0x0E95.  Theres also quite a bit of
327 pointless code here and there.  Some Interesting Memory Locations
328
329 C000 : level - value (00-0x32)
330 C001 : level - display (00-0x50, BCD coded)
331 C003 : credits (00-0x99, BCD coded)
332 C005 : DSWA put here (coinage, left and right nibbles for left and right slot
333        - freeplay when 0x0f or 0xf0)
334 C006 : DSWB put here
335  bits 0 and 1 : lives ("02", "03", "04", "98")
336  bit 3 : difficulty
337  bits 5 and 6 : bonus lives ("50K, 100K, 200K, 500K", "100K, 200K, 500K", "100K,
338                               200K, 500K, 99999999", "none")
339 C009 : lives (for player 1)
340 C00A : lives (for player 2)
341 C00B : bonus lives counter
342
343 E20B-E20E : score (00000000-0x99999999, BCD coded)
344 E215-E218 : hi-score (00000000-0x99999999, BCD coded)
345
346 E543 : bit 0 : ON = player 1 one still has lives
347        bit 1 : ON = player 2 one still has lives
348        bit 2 : ON = player 1 is the current player - OFF = player 2 is the
349         current player
350
351 E572 : table with L. slot infos (5 bytes wide)
352 E577 : table with R. slot infos (5 bytes wide)
353*******************************************************************************/
354
355
356#include "driver.h"
357#include "cpu/z80/z80.h"
358#include "machine/segacrpt.h"
359#include "machine/mc8123.h"
360#include "sound/sn76496.h"
361
362/*-- Variables --*/
363
364static UINT8 segae_8000bank;   /* Current VDP Bank Selected for 0x8000 - 0xbfff writes */
365static UINT8 port_fa_last;      /* Last thing written to port 0xfa (control related) */
366static UINT8 hintcount;         /* line interrupt counter, decreased each scanline */
367UINT8 segae_vintpending;      /* vertical interrupt pending flag */
368UINT8 segae_hintpending;      /* scanline interrupt pending flag */
369
370/*- in (video/segasyse.c) -*/
371extern UINT8 segae_vdp_vrambank[];   /* vdp's vram bank */
372extern UINT8 *segae_vdp_vram[];      /* pointer to start of vdp's vram */
373extern UINT8 *segae_vdp_regs[];      /* pointer to vdp's registers */
374
375/*-- Prototypes --*/
376
377static WRITE8_HANDLER (segae_mem_8000_w);
378
379static WRITE8_HANDLER (segae_port_f7_w);
380static READ8_HANDLER (segae_port_7e_7f_r);
381
382static READ8_HANDLER (segae_port_ba_bb_r);
383static READ8_HANDLER (segae_port_be_bf_r);
384
385static WRITE8_HANDLER (segae_port_ba_bb_w);
386static WRITE8_HANDLER (segae_port_be_bf_w);
387
388/*- in (video/segasyse.c) -*/
389
390VIDEO_START( segae );
391VIDEO_UPDATE( segae );
392
393UINT8 segae_vdp_ctrl_r ( UINT8 chip );
394UINT8 segae_vdp_data_r ( UINT8 chip );
395void segae_vdp_ctrl_w ( UINT8 chip, UINT8 data );
396void segae_vdp_data_w ( UINT8 chip, UINT8 data );
397void segae_drawscanline(int line, int chips, int blank);
398
399/*******************************************************************************
400 Port & Memory Maps
401********************************************************************************
402 most things on this hardware are done via port writes, including reading of
403 controls dipswitches, reads and writes to the vdp's etc.  see notes at top of
404 file, the most noteworthy thing is the use of the 0x8000 - 0xbfff region, reads
405 are used to read ram, writes are used as a secondary way of writing to VRAM
406*******************************************************************************/
407
408/*-- Memory --*/
409
410static ADDRESS_MAP_START( segae_readmem, ADDRESS_SPACE_PROGRAM, 8 )
411   AM_RANGE(0x0000, 0x7fff) AM_READ(MRA8_ROM)            /* Fixed ROM */
412   AM_RANGE(0x8000, 0xbfff) AM_READ(MRA8_BANK1)            /* Banked ROM */
413   AM_RANGE(0xc000, 0xffff) AM_READ(MRA8_RAM)            /* Main RAM */
414ADDRESS_MAP_END
415
416static ADDRESS_MAP_START( segae_writemem, ADDRESS_SPACE_PROGRAM, 8 )
417   AM_RANGE(0x0000, 0x7fff) AM_WRITE(MWA8_ROM)            /* Fixed ROM */
418   AM_RANGE(0x8000, 0xbfff) AM_WRITE(segae_mem_8000_w)      /* Banked VRAM */
419   AM_RANGE(0xc000, 0xffff) AM_WRITE(MWA8_RAM)            /* Main RAM */
420ADDRESS_MAP_END
421
422/*-- Ports --*/
423
424static ADDRESS_MAP_START( segae_readport, ADDRESS_SPACE_IO, 8 )
425   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
426   AM_RANGE(0x7e, 0x7f) AM_READ(segae_port_7e_7f_r)         /* Vertical / Horizontal Beam Position Read */
427   AM_RANGE(0xba, 0xbb) AM_READ(segae_port_ba_bb_r)         /* Back Layer VDP */
428   AM_RANGE(0xbe, 0xbf) AM_READ(segae_port_be_bf_r)         /* Front Layer VDP */
429   AM_RANGE(0xe0, 0xe0) AM_READ(input_port_2_r) /* Coins + Starts */
430   AM_RANGE(0xe1, 0xe1) AM_READ(input_port_3_r) /* Controls */
431   AM_RANGE(0xf2, 0xf2) AM_READ(input_port_0_r) /* DSW0 */
432   AM_RANGE(0xf3, 0xf3) AM_READ(input_port_1_r) /* DSW1 */
433ADDRESS_MAP_END
434
435static ADDRESS_MAP_START( segae_writeport, ADDRESS_SPACE_IO, 8 )
436   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
437   AM_RANGE(0x7b, 0x7b) AM_WRITE(SN76496_0_w) /* Not sure which chip each is on */
438   AM_RANGE(0x7f, 0x7f) AM_WRITE(SN76496_1_w) /* Not sure which chip each is on */
439   AM_RANGE(0xba, 0xbb) AM_WRITE(segae_port_ba_bb_w)         /* Back Layer VDP */
440   AM_RANGE(0xbe, 0xbf) AM_WRITE(segae_port_be_bf_w)         /* Front Layer VDP */
441   AM_RANGE(0xf7, 0xf7) AM_WRITE(segae_port_f7_w)         /* Banking Control */
442ADDRESS_MAP_END
443
444/*******************************************************************************
445 Read / Write Handlers
446********************************************************************************
447 the ports 0xf8, 0xf9, 0xfa appear to be in some way control related, their
448 behavior is not fully understood, however for HangOnJr it appears that we
449 need to read either the accelerator or angle from port 0xf8 depending on the
450 last write to port 0xfa, this yields a playable game,
451
452 For Riddle of Pythagoras it doesn't seem so simple, the code we have here
453 seems to general do the job but it could probably do with looking at a bit
454 more
455*******************************************************************************/
456
457/*-- Memory -- */
458
459static WRITE8_HANDLER (segae_mem_8000_w)
460{
461   /* write the data the non-selected VRAM bank of the opposite number VDP chip stored in segae_8000bank */
462   segae_vdp_vram [1-segae_8000bank][offset + (0x4000-(segae_vdp_vrambank[1-segae_8000bank] * 0x4000))] = data;
463}
464
465/*-- Ports --*/
466
467/***************************************
468 WRITE8_HANDLER (segae_port_f7_w)
469****************************************
470 writes here control the banking of
471 ROM and RAM
472
473 bit:
474  7 - Back Layer VDP (0) Vram Bank Select
475  6 - Front Layer VDP (1) Vram Bank Select
476  5 - Select 0x8000 write location (1 = Back Layer VDP RAM, 0 = Front Layer VDP RAM)
477        *writes are to the non-selected bank*
478  4 - unknown
479  3 - \
480  2 - |
481  1 - | Rom Bank Select for 0x8000 -
482  0 - |                 0xbfff reads
483
484***************************************/
485
486static UINT8 rombank;
487
488void segae_bankswitch (void)
489{
490   memory_set_bank(1, rombank);
491}
492
493
494static WRITE8_HANDLER (segae_port_f7_w)
495{
496   segae_vdp_vrambank[0] = (data & 0x80) >> 7; /* Back  Layer VDP (0) VRAM Bank */
497   segae_vdp_vrambank[1] = (data & 0x40) >> 6; /* Front Layer VDP (1) VRAM Bank */
498   segae_8000bank        = (data & 0x20) >> 5; /* 0x8000 Write Select */
499   rombank              =  data & 0x0f;      /* Rom Banking */
500
501   segae_bankswitch();
502}
503
504/*- Beam Position -*/
505
506static READ8_HANDLER (segae_port_7e_7f_r)
507{
508   UINT8 temp = 0;
509   UINT16 sline;
510
511   switch (offset)
512   {
513      case 0: /* port 0x7e, Vert Position (in scanlines) */
514         sline = 261 - cpu_getiloops();
515         if (sline > 0xDA) sline -= 6;
516         temp = sline-1 ;
517         break;
518      case 1: /* port 0x7f, Horz Position (in pixel clock cycles)  */
519         /* unhandled for now */
520         break;
521   }
522   return temp;
523}
524
525/*- VDP Related -*/
526
527static READ8_HANDLER (segae_port_ba_bb_r)
528{
529   /* These Addresses access the Back Layer VDP (0) */
530   UINT8 temp = 0;
531
532   switch (offset)
533   {
534      case 0: /* port 0xba, VDP 0 DATA Read */
535         temp = segae_vdp_data_r(0); break;
536      case 1: /* port 0xbb, VDP 0 CTRL Read */
537         temp = segae_vdp_ctrl_r(0); break;
538   }
539   return temp;
540}
541
542static READ8_HANDLER (segae_port_be_bf_r)
543{
544   /* These Addresses access the Front Layer VDP (1) */
545   UINT8 temp = 0;
546
547   switch (offset)
548   {
549      case 0: /* port 0xbe, VDP 1 DATA Read */
550         temp = segae_vdp_data_r(1); break ;
551      case 1: /* port 0xbf, VDP 1 CTRL Read */
552         temp = segae_vdp_ctrl_r(1); break ;
553   }
554   return temp;
555}
556
557static WRITE8_HANDLER (segae_port_ba_bb_w)
558{
559   /* These Addresses access the Back Layer VDP (0) */
560   switch (offset)
561   {
562      case 0: /* port 0xba, VDP 0 DATA Write */
563         segae_vdp_data_w(0, data); break;
564      case 1: /* port 0xbb, VDP 0 CTRL Write */
565         segae_vdp_ctrl_w(0, data); break;
566   }
567}
568
569static WRITE8_HANDLER (segae_port_be_bf_w)
570{
571   /* These Addresses access the Front Layer VDP (1) */
572   switch (offset)
573   {
574      case 0: /* port 0xbe, VDP 1 DATA Write */
575         segae_vdp_data_w(1, data); break;
576      case 1: /* port 0xbf, VDP 1 CTRL Write */
577         segae_vdp_ctrl_w(1, data); break;
578   }
579}
580
581/*- Hang On Jr. Specific -*/
582
583static READ8_HANDLER (segae_hangonjr_port_f8_r)
584{
585   UINT8 temp;
586
587   temp = 0;
588
589   if (port_fa_last == 0x08)  /* 0000 1000 */ /* Angle */
590      temp = readinputport(4);
591
592   if (port_fa_last == 0x09)  /* 0000 1001 */ /* Accel */
593      temp = readinputport(5);
594
595   return temp;
596}
597
598static WRITE8_HANDLER (segae_hangonjr_port_fa_w)
599{
600   /* Seems to write the same pattern again and again bits ---- xx-x used */
601   port_fa_last = data;
602}
603
604/*- Riddle of Pythagoras Specific -*/
605
606static int port_to_read,last1,last2,diff1,diff2;
607
608static READ8_HANDLER (segae_ridleofp_port_f8_r)
609{
610   switch (port_to_read)
611   {
612      default:
613      case 0:   return diff1 & 0xff;
614      case 1:   return diff1 >> 8;
615      case 2:   return diff2 & 0xff;
616      case 3:   return diff2 >> 8;
617   }
618}
619
620static WRITE8_HANDLER (segae_ridleofp_port_fa_w)
621{
622   /* 0x10 is written before reading the dial (hold counters?) */
623   /* 0x03 is written after reading the dial (reset counters?) */
624
625   port_to_read = (data & 0x0c) >> 2;
626
627   if (data & 1)
628   {
629      int curr = readinputport(4);
630      diff1 = ((curr - last1) & 0x0fff) | (curr & 0xf000);
631      last1 = curr;
632   }
633   if (data & 2)
634   {
635      int curr = readinputport(5) & 0x0fff;
636      diff2 = ((curr - last2) & 0x0fff) | (curr & 0xf000);
637      last2 = curr;
638   }
639}
640
641
642/*******************************************************************************
643 Interrupt Function
644********************************************************************************
645 Lines 0 - 191 | Dislay
646 Lines 0 - 261 | Non-Display / VBlank Period
647
648 VDP1 Seems to be in Charge of Line Interrupts at Least
649
650 Interrupt enable bits etc are a bit uncertain
651*******************************************************************************/
652
653 INTERRUPT_GEN( segae_interrupt )
654{
655   int sline;
656   sline = 261 - cpu_getiloops();
657
658   if (sline ==0) {
659      hintcount = segae_vdp_regs[1][10];
660   }
661
662   if (sline <= 192) {
663
664      if (sline != 192) segae_drawscanline(sline,1,1);
665
666      if (sline == 192)
667         segae_vintpending = 1;
668
669      if (hintcount == 0) {
670         hintcount = segae_vdp_regs[1][10];
671         segae_hintpending = 1;
672
673         if  ((segae_vdp_regs[1][0] & 0x10)) {
674            cpunum_set_input_line(0, 0, HOLD_LINE);
675            return;
676         }
677
678      } else {
679         hintcount--;
680      }
681   }
682
683   if (sline > 192) {
684      hintcount = segae_vdp_regs[1][10];
685
686      if ( (sline<0xe0) && (segae_vintpending) ) {
687         cpunum_set_input_line(0, 0, HOLD_LINE);
688      }
689   }
690}
691
692/*******************************************************************************
693 General Init
694********************************************************************************
695 for Save State support
696*******************************************************************************/
697
698static MACHINE_START( segasyse )
699{
700   memory_configure_bank(1, 0, 16, memory_region(REGION_CPU1) + 0x10000, 0x4000);
701
702   state_save_register_global(segae_8000bank);
703   state_save_register_global(segae_vintpending);
704   state_save_register_global(segae_hintpending);
705   state_save_register_global(rombank);
706   state_save_register_func_postload(segae_bankswitch);
707}
708
src/tools/png2bdc.c
r1046r1047
1/***************************************************************************
2
3    Super-simple PNG to BDC file generator
4
5    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8****************************************************************************
9
10    Format of PNG data:
11
12    Multiple rows of characters. A black pixel means "on". All other colors
13    mean "off". Each row looks like this:
14
15    * 8888  ***    *
16    * 4444 *   *  **
17    * 2222 *   *   *
18    * 1111 *   *   *
19    *      *   *   *
20    **      ***   ***
21    *
22    *
23
24           ****** ****
25
26    The column of pixels on the left-hand side (column 0) indicates the
27    character cell height. This column must be present on each row and
28    the height must be consistent for each row.
29
30    Protruding one pixel into column 1 is the baseline indicator. There
31    should only be one row with a pixel in column 1 for each line, and
32    that pixel row index should be consistent for each row.
33
34    In columns 2-5 are a 4-hex-digit starting character index number. This
35    is encoded as binary value. Each column is 4 pixels tall and represents
36    one binary digit. The character index number is the unicode character
37    number of the first character encoded in this row; subsequent
38    characters in the row are at increasing character indices.
39
40    Starting in column 6 and beyond are the actual character bitmaps.
41    Below them, in the second row after the last row of the character,
42    is a solid line that indicates the width of the character, and also
43    where the character bitmap begins and ends.
44
45***************************************************************************/
46
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50#include <ctype.h>
51#include "osdcore.h"
52#include "png.h"
53
54
55/***************************************************************************
56    CONSTANTS & DEFINES
57***************************************************************************/
58
59#define CACHED_CHAR_SIZE      12
60#define CACHED_HEADER_SIZE      16
61
62
63
64/***************************************************************************
65    TYPE DEFINITIONS
66***************************************************************************/
67
68/* a render_font contains information about a single character in a font */
69typedef struct _render_font_char render_font_char;
70struct _render_font_char
71{
72   INT32            width;            /* width from this character to the next */
73   INT32            xoffs, yoffs;      /* X and Y offset from baseline to top,left of bitmap */
74   INT32            bmwidth, bmheight;   /* width and height of bitmap */
75   bitmap_t *         bitmap;            /* pointer to the bitmap containing the raw data */
76};
77
78
79/* a render_font contains information about a font */
80typedef struct _render_font render_font;
81struct _render_font
82{
83   int               height;            /* height of the font, from ascent to descent */
84   int               yoffs;            /* y offset from baseline to descent */
85   render_font_char    chars[65536];      /* array of characters */
86};
87
88
89
90/***************************************************************************
91    INLINE FUNCTIONS
92***************************************************************************/
93
94INLINE int pixel_is_set(bitmap_t *bitmap, int y, int x)
95{
96   return (*BITMAP_ADDR32(bitmap, y, x) & 0xffffff) == 0;
97}
98
99
100
101/***************************************************************************
102    MAIN
103***************************************************************************/
104
105static int render_font_save_cached(render_font *font, const char *filename, UINT32 hash)
106{
107   file_error filerr;
108   render_font_char *ch;
109   UINT32 bytes_written;
110   UINT8 *tempbuffer;
111   UINT8 *chartable;
112   core_file *file;
113   int numchars;
114   UINT8 *dest;
115   int tableindex;
116   int chnum;
117
118   /* attempt to open the file */
119   filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
120   if (filerr != FILERR_NONE)
121      return 1;
122
123   /* determine the number of characters */
124   numchars = 0;
125   for (chnum = 0; chnum < 65536; chnum++)
126      if (font->chars[chnum].width > 0)
127         numchars++;
128
129   /* allocate an array to hold the character data */
130   chartable = malloc(numchars * CACHED_CHAR_SIZE);
131
132   /* allocate a temp buffer to compress into */
133   tempbuffer = malloc(65536);
134   if (chartable == NULL || tempbuffer == NULL)
135      goto error;
136
137   memset(chartable, 0, numchars * CACHED_CHAR_SIZE);
138
139   /* write the header */
140   dest = tempbuffer;
141   *dest++ = 'f';
142   *dest++ = 'o';
143   *dest++ = 'n';
144   *dest++ = 't';
145   *dest++ = hash >> 24;
146   *dest++ = hash >> 16;
147   *dest++ = hash >> 8;
148   *dest++ = hash & 0xff;
149   *dest++ = font->height >> 8;
150   *dest++ = font->height & 0xff;
151   *dest++ = font->yoffs >> 8;
152   *dest++ = font->yoffs & 0xff;
153   *dest++ = numchars >> 24;
154   *dest++ = numchars >> 16;
155   *dest++ = numchars >> 8;
156   *dest++ = numchars & 0xff;
157   bytes_written = core_fwrite(file, tempbuffer, dest - tempbuffer);
158   if (bytes_written != dest - tempbuffer)
159      goto error;
160
161   /* write the empty table to the beginning of the file */
162   bytes_written = core_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE);
163   if (bytes_written != numchars * CACHED_CHAR_SIZE)
164      goto error;
165
166   /* loop over all characters */
167   tableindex = 0;
168   for (chnum = 0; chnum < 65536; chnum++)
169   {
170      ch = &font->chars[chnum];
171      if (ch->width > 0)
172      {
173         UINT8 accum, accbit;
174         int x, y;
175
176         /* write out a bit-compressed bitmap if we have one */
177         if (ch->bitmap != NULL)
178         {
179            /* write the data to the tempbuffer */
180            dest = tempbuffer;
181            accum = 0;
182            accbit = 7;
183
184            /* bit-encode the character data */
185            for (y = 0; y < ch->bmheight; y++)
186            {
187               int desty = y + font->height + font->yoffs - ch->yoffs - ch->bmheight;
188               const UINT32 *src = (desty >= 0 && desty < font->height) ? BITMAP_ADDR32(ch->bitmap, desty, 0) : NULL;
189               for (x = 0; x < ch->bmwidth; x++)
190               {
191                  if (src != NULL && src[x] != 0)
192                     accum |= 1 << accbit;
193                  if (accbit-- == 0)
194                  {
195                     *dest++ = accum;
196                     accum = 0;
197                     accbit = 7;
198                  }
199               }
200            }
201
202            /* flush any extra */
203            if (accbit != 7)
204               *dest++ = accum;
205
206            /* write the data */
207            bytes_written = core_fwrite(file, tempbuffer, dest - tempbuffer);
208            if (bytes_written != dest - tempbuffer)
209               goto error;
210
211            /* free the bitmap and texture */
212            bitmap_free(ch->bitmap);
213            ch->bitmap = NULL;
214         }
215
216         /* compute the table entry */
217         dest = &chartable[tableindex++ * CACHED_CHAR_SIZE];
218         *dest++ = chnum >> 8;
219         *dest++ = chnum & 0xff;
220         *dest++ = ch->width >> 8;
221         *dest++ = ch->width & 0xff;
222         *dest++ = ch->xoffs >> 8;
223         *dest++ = ch->xoffs & 0xff;
224         *dest++ = ch->yoffs >> 8;
225         *dest++ = ch->yoffs & 0xff;
226         *dest++ = ch->bmwidth >> 8;
227         *dest++ = ch->bmwidth & 0xff;
228         *dest++ = ch->bmheight >> 8;
229         *dest++ = ch->bmheight & 0xff;
230      }
231   }
232
233   /* seek back to the beginning and rewrite the table */
234   core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET);
235   bytes_written = core_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE);
236   if (bytes_written != numchars * CACHED_CHAR_SIZE)
237      goto error;
238
239   /* all done */
240   core_fclose(file);
241   free(tempbuffer);
242   free(chartable);
243   return 0;
244
245error:
246   core_fclose(file);
247   osd_rmfile(filename);
248   free(tempbuffer);
249   free(chartable);
250   return 1;
251}
252
253
254/*-------------------------------------------------
255    bitmap_to_chars - convert a bitmap to
256    characters in the given font
257-------------------------------------------------*/
258
259static int bitmap_to_chars(bitmap_t *bitmap, render_font *font)
260{
261   int rowstart = 0;
262   int x, y;
263
264   /* loop over rows */
265   while (rowstart < bitmap->height)
266   {
267      int rowend, baseline, colstart;
268      int chstart;
269
270      /* find the top of the row */
271      for ( ; rowstart < bitmap->height; rowstart++)
272         if (pixel_is_set(bitmap, rowstart, 0))
273            break;
274      if (rowstart >= bitmap->height)
275         break;
276
277      /* find the bottom of the row */
278      for (rowend = rowstart + 1; rowend < bitmap->height; rowend++)
279         if (!pixel_is_set(bitmap, rowend, 0))
280         {
281            rowend--;
282            break;
283         }
284
285      /* find the baseline */
286      for (baseline = rowstart; baseline <= rowend; baseline++)
287         if (pixel_is_set(bitmap, baseline, 1))
288            break;
289      if (baseline > rowend)
290      {
291         fprintf(stderr, "No baseline found between rows %d-%d\n", rowstart, rowend);
292         break;
293      }
294
295      /* set or confirm the height */
296      if (font->height == 0)
297      {
298         font->height = rowend - rowstart + 1;
299         font->yoffs = baseline - rowend;
300      }
301      else
302      {
303         if (font->height != rowend - rowstart + 1)
304         {
305            fprintf(stderr, "Inconsistent font height at rows %d-%d\n", rowstart, rowend);
306            break;
307         }
308         if (font->yoffs != baseline - rowend)
309         {
310            fprintf(stderr, "Inconsistent baseline at rows %d-%d\n", rowstart, rowend);
311            break;
312         }
313      }
314
315      /* decode the starting character */
316      chstart = 0;
317      for (x = 0; x < 4; x++)
318         for (y = 0; y < 4; y++)
319            chstart = (chstart << 1) | pixel_is_set(bitmap, rowstart + y, 2 + x);
320
321      /* print info */
322//      printf("Row %d-%d, baseline %d, character start %X\n", rowstart, rowend, baseline, chstart);
323
324      /* scan the column to find characters */
325      colstart = 0;
326      while (colstart < bitmap->width)
327      {
328         render_font_char *ch = &font->chars[chstart];
329         int colend;
330
331         /* find the start of the character */
332         for ( ; colstart < bitmap->width; colstart++)
333            if (pixel_is_set(bitmap, rowend + 2, colstart))
334               break;
335         if (colstart >= bitmap->width)
336            break;
337
338         /* find the end of the character */
339         for (colend = colstart + 1; colend < bitmap->width; colend++)
340            if (!pixel_is_set(bitmap, rowend + 2, colend))
341            {
342               colend--;
343               break;
344            }
345
346         /* print info */
347//          printf("  Character %X - width = %d\n", chstart, colend - colstart + 1);
348
349         /* allocate a bitmap */
350         ch->bitmap = bitmap_alloc(colend - colstart + 1, font->height, BITMAP_FORMAT_ARGB32);
351         if (ch->bitmap == NULL)
352         {
353            fprintf(stderr, "Error allocating character bitmap (%dx%d)\n", colend - colstart + 1, font->height);
354            continue;
355         }
356
357         /* plot the character */
358         for (y = rowstart; y <= rowend; y++)
359            for (x = colstart; x <= colend; x++)
360               *BITMAP_ADDR32(ch->bitmap, y - rowstart, x - colstart) = pixel_is_set(bitmap, y, x) ? 0xffffffff : 0x00000000;
361
362         /* set the character parameters */
363         ch->width = colend - colstart + 1;
364         ch->xoffs = 0;
365         ch->yoffs = font->yoffs;
366         ch->bmwidth = ch->bitmap->width;
367         ch->bmheight = ch->bitmap->height;
368
369         /* next character */
370         chstart++;
371         colstart = colend + 1;
372      }
373
374      /* next row */
375      rowstart = rowend + 1;
376   }
377
378   /* return non-zero (TRUE) if we errored */
379   return (rowstart < bitmap->height);
380}
381
382
383/*-------------------------------------------------
384    main - main entry point
385-------------------------------------------------*/
386
387int main(int argc, char *argv[])
388{
389   const char *bdcname;
390   render_font *font;
391   int error = FALSE;
392   int curarg;
393
394   /* validate arguments */
395    if (argc < 3)
396    {
397       fprintf(stderr, "Usage:\npng2bdf <input.png> [<input2.png> [...]] <output.bdc>\n");
398       return 1;
399    }
400    bdcname = argv[argc - 1];
401
402   /* allocate a font */
403   font = malloc(sizeof(*font));
404   if (font == NULL)
405      return 1;
406   memset(font, 0, sizeof(*font));
407
408   /* iterate over input files */
409   for (curarg = 1; curarg < argc - 1; curarg++)
410   {
411      const char *pngname = argv[curarg];
412      file_error filerr;
413      png_error pngerr;
414      bitmap_t *bitmap;
415      core_file *file;
416
417       /* load the png file */
418      filerr = core_fopen(pngname, OPEN_FLAG_READ, &file);
419      if (filerr != FILERR_NONE)
420       {
421          fprintf(stderr, "Error %d attempting to open PNG file\n", filerr);
422          error = TRUE;
423          break;
424       }
425      pngerr = png_read_bitmap(file, &bitmap);
426      core_fclose(file);
427      if (pngerr != PNGERR_NONE)
428      {
429         fprintf(stderr, "Error %d reading PNG file\n", pngerr);
430         error = TRUE;
431         break;
432      }
433
434      /* parse the PNG into characters */
435      error = bitmap_to_chars(bitmap, font);
436      bitmap_free(bitmap);
437      if (error)
438         break;
439   }
440
441   /* write out the resulting font */
442   if (!error)
443      render_font_save_cached(font, bdcname, 0);
444
445   /* cleanup after ourselves */
446   free(font);
447    return error;
448}
src/tools/file2str.c
r1046r1047
1/***************************************************************************
2
3    file2str.c
4
5    Simple file to string converter.
6
7    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12#include <stdio.h>
13#include "osdcore.h"
14
15
16/*-------------------------------------------------
17    main - primary entry point
18-------------------------------------------------*/
19
20int main(int argc, char *argv[])
21{
22   const char *srcfile, *dstfile, *varname, *type;
23   FILE *src, *dst;
24   UINT8 *buffer;
25   int bytes, offs;
26   int terminate = 1;
27
28   /* needs at least three arguments */
29   if (argc < 4)
30   {
31      fprintf(stderr,
32         "Usage:\n"
33         "  laytostr <source.lay> <output.h> <varname> [<type>]\n"
34         "\n"
35         "The default <type> is char, with an assumed NULL terminator\n"
36      );
37      return 0;
38   }
39
40   /* extract arguments */
41   srcfile = argv[1];
42   dstfile = argv[2];
43   varname = argv[3];
44   type = (argc >= 5) ? argv[4] : "char";
45   if (argc >= 5)
46      terminate = 0;
47
48   /* open source file */
49   src = fopen(srcfile, "rb");
50   if (src == NULL)
51   {
52      fprintf(stderr, "Unable to open source file '%s'\n", srcfile);
53      return 1;
54   }
55
56   /* determine file size */
57   fseek(src, 0, SEEK_END);
58   bytes = ftell(src);
59   fseek(src, 0, SEEK_SET);
60
61   /* allocate memory */
62   buffer = malloc(bytes + 1);
63   if (buffer == NULL)
64   {
65      fprintf(stderr, "Out of memory allocating %d byte buffer\n", bytes);
66      return 1;
67   }
68
69   /* read the source file */
70   fread(buffer, 1, bytes, src);
71   buffer[bytes] = 0;
72   fclose(src);
73
74   /* open dest file */
75   dst = fopen(dstfile, "w");
76   if (dst == NULL)
77   {
78      fprintf(stderr, "Unable to open output file '%s'\n", dstfile);
79      return 1;
80   }
81
82   /* write the initial header */
83   fprintf(dst, "const %s %s[] =\n{\n\t", type, varname);
84
85   /* write out the data */
86   for (offs = 0; offs < bytes + terminate; offs++)
87   {
88      fprintf(dst, "0x%02x%s", buffer[offs], (offs != bytes + terminate - 1) ? "," : "");
89      if (offs % 16 == 15)
90         fprintf(dst, "\n\t");
91   }
92   fprintf(dst, "\n};\n");
93
94   /* close the files */
95   fclose(dst);
96   return 0;
97}
src/osd/windows/d3d_extra.h
r1046r1047
1
2// versions of the standard vertex structures with an extra set of texture coordinates
3
4typedef struct _D3DTLVERTEX2 {
5   union { D3DVALUE sx; D3DVALUE dvSX; };
6   union { D3DVALUE sy; D3DVALUE dvSY; };
7   union { D3DVALUE sz; D3DVALUE dvSZ; };
8   union { D3DVALUE rhw; D3DVALUE dvRHW; };
9   union { D3DCOLOR color; D3DCOLOR dcColor; };
10   union { D3DCOLOR specular; D3DCOLOR dcSpecular; };
11   union { D3DVALUE tu; D3DVALUE dvTU; };
12   union { D3DVALUE tv; D3DVALUE dvTV; };
13   union { D3DVALUE tu1; D3DVALUE dvTU1; };
14   union { D3DVALUE tv1; D3DVALUE dvTV1; };
15#if(DIRECT3D_VERSION >= 0x0500)
16 #if (defined __cplusplus) && (defined D3D_OVERLOADS)
17   _D3DTLVERTEX2() { }
18   _D3DTLVERTEX2(const D3DVECTOR& v, float _rhw, D3DCOLOR _color, D3DCOLOR _specular, float _tu, float _tv, float _tu1, float _tv1)
19   {
20      sx = v.x; sy = v.y; sz = v.z; rhw = _rhw;
21      color = _color; specular = _specular;
22      tu = _tu; tv = _tv;
23      tu1 = _tu1; tv1 = _tv1;
24   }
25 #endif
26#endif
27} D3DTLVERTEX2, *LPD3DTLVERTEX2;
28
29#define D3DFVF_TLVERTEX2 ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) )
30
31typedef struct _D3DLVERTEX2 {
32   union { D3DVALUE x; D3DVALUE dvX; };
33   union { D3DVALUE y; D3DVALUE dvY; };
34   union { D3DVALUE z; D3DVALUE dvZ; };
35    DWORD dwReserved;
36   union { D3DCOLOR color; D3DCOLOR dcColor; };
37   union { D3DCOLOR specular; D3DCOLOR dcSpecular; };
38   union { D3DVALUE tu; D3DVALUE dvTU; };
39   union { D3DVALUE tv; D3DVALUE dvTV; };
40   union { D3DVALUE tu1; D3DVALUE dvTU1; };
41   union { D3DVALUE tv1; D3DVALUE dvTV1; };
42#if(DIRECT3D_VERSION >= 0x0500)
43 #if (defined __cplusplus) && (defined D3D_OVERLOADS)
44   _D3DLVERTEX2() { }
45   _D3DLVERTEX2(const D3DVECTOR& v, D3DCOLOR _color, D3DCOLOR _specular, float _tu, float _tv, float _tu1, float _tv1)
46   {
47      x = v.x; y = v.y; z = v.z; dwReserved = 0;
48      color = _color; specular = _specular;
49      tu = _tu; tv = _tv;
50      tu1 = _tu1; tv1 = _tv1;
51   }
52 #endif
53#endif
54} D3DLVERTEX2, *LPD3DLVERTEX2;
55
56#define D3DFVF_LVERTEX2 ( D3DFVF_XYZ | D3DFVF_RESERVED1 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) )
57
58typedef struct _D3DVERTEX2 {
59   union { D3DVALUE x; D3DVALUE dvX; };
60   union { D3DVALUE y; D3DVALUE dvY; };
61   union { D3DVALUE z; D3DVALUE dvZ; };
62    union { D3DVALUE nx; D3DVALUE dvNX; };
63    union { D3DVALUE ny; D3DVALUE dvNY; };
64    union { D3DVALUE nz; D3DVALUE dvNZ; };
65   union { D3DVALUE tu; D3DVALUE dvTU; };
66   union { D3DVALUE tv; D3DVALUE dvTV; };
67   union { D3DVALUE tu1; D3DVALUE dvTU1; };
68   union { D3DVALUE tv1; D3DVALUE dvTV1; };
69#if(DIRECT3D_VERSION >= 0x0500)
70 #if (defined __cplusplus) && (defined D3D_OVERLOADS)
71    _D3DVERTEX2() { }
72    _D3DVERTEX2(const D3DVECTOR& v, const D3DVECTOR& n, float _tu, float _tv, float _tu1, float _tv1)
73        {
74         x = v.x; y = v.y; z = v.z;
75         nx = n.x; ny = n.y; nz = n.z;
76         tu = _tu; tv = _tv;
77         tu1 = _tu1; tv1 = _tv1;
78        }
79 #endif
80#endif
81} D3DVERTEX2, *LPD3DVERTEX2;
82
83#define D3DFVF_VERTEX2 ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) )
84
src/emu/palette.c
r1046r1047
1/******************************************************************************
2
3    palette.c
4
5    Palette handling functions.
6
7    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10******************************************************************************/
11
12#include "driver.h"
13#include <math.h>
14
15#define VERBOSE 0
16
17
18/***************************************************************************
19    CONSTANTS
20***************************************************************************/
21
22#define PEN_BRIGHTNESS_BITS      8
23#define MAX_PEN_BRIGHTNESS      (4 << PEN_BRIGHTNESS_BITS)
24#define MAX_SHADOW_PRESETS       4
25
26
27
28/***************************************************************************
29    TYPE DEFINITIONS
30***************************************************************************/
31
32typedef struct _callback_item callback_item;
33struct _callback_item
34{
35   callback_item *   next;
36   void *         param;
37   void          (*notify)(void *param, int index, rgb_t newval);
38};
39
40
41/* typedef struct _palette_private palette_private; */
42struct _palette_private
43{
44   rgb_t *raw_color;
45   rgb_t *adjusted_color;
46
47   UINT16 *pen_brightness;
48
49   UINT16 shadow_factor, highlight_factor;
50
51   pen_t total_colors;
52   pen_t total_colors_with_ui;
53
54   pen_t black_pen, white_pen;
55
56   callback_item *notify_callback_list;
57
58   UINT32 *shadow_table_base[MAX_SHADOW_PRESETS];
59   int shadow_dr[MAX_SHADOW_PRESETS];
60   int shadow_dg[MAX_SHADOW_PRESETS];
61   int shadow_db[MAX_SHADOW_PRESETS];
62   int shadow_noclip[MAX_SHADOW_PRESETS];
63};
64
65
66/*
67
68    Machine->drv->total_colors = reported colors
69
70    palette->total_colors =
71        Machine->drv->total_colors
72        + Machine->drv->total_colors (if shadows)
73        + Machine->drv->total_colors (if highlights)
74
75    palette->total_colors_with_ui =
76        palette->total_colors
77
78    raw_color[palette->total_colors + 2]
79    adjusted_color[palette->total_colors + 2]
80
81    machine->pens[palette->total_colors]
82    palette->pen_brightness[palette->total_colors]
83
84    machine->game_colortable[Machine->drv->color_table_len]
85    machine->remapped_colortable[Machine->drv->color_table_len] (or -> machine->pens)
86
87    palette->shadow_table_base[MAX_SHADOW_PRESETS]
88        - contains array mapping pens to shadow pens
89        - by default, tables 0 and 2 point to shadows, tables 1 and 3 point to hilights
90        - shadows go from Machine->drv->total_colors to 2*Machine->drv->total_colors
91        - hilights go from 2*Machine->drv->total_colors to 3*Machine->drv->total_colors
92
93
94
95    palette_alloc strategy:
96
97        palette->total_colors = machine->drv->total_colors;
98        if (shadows && !rgb_direct) palette->total_colors += machine->drv->total_colors;
99        if (hilights && !rgb_direct) palette->total_colors += machine->drv->total_colors;
100        palette->total_colors_with_ui = palette->total_colors;
101
102        max_total_colors = palette->total_colors + 2;
103
104        Allocate palette->raw_color[max_total_colors]
105            - initialize to RGB defaults
106
107        Allocate palette->adjusted_color[max_total_colors]
108            - initialize equal to palette->raw_color
109
110        if (!rgb_direct) Notify_pen_changed for max_total_colors
111
112        if (palette->total_colors > 0)
113
114            Allocate machine->pens[palette->total_colors]
115                - initialize 1:1
116
117            Allocate palette_pen_brightness[machine->drv->total_colors]
118                - initialize to 1.0
119
120        if (machine->drv->color_table_len > 0)
121
122            Allocate machine->game_colortable[machine->drv->color_table_len]
123                - initialize to i % palette->total_colors
124
125            Allocate machine->remapped_colortable[machine->drv->color_table_len]
126                - not initialized
127
128        if (shadows)
129
130            Allocate shadow_table[0]/[2]
131
132            if (!rgb_direct)
133                table[i] = (i < machine->drv->total_colors) ? (i + machine->drv->total_colors) : i
134
135            else
136                table[i] = shadow(RGB555(i))
137
138        if (hilights)
139
140            Allocate shadow_table[1]/[3]
141
142            if (!rgb_direct)
143                table[i] = (i < machine->drv->total_colors) ? (i + 2 * machine->drv->total_colors) : i
144
145            else
146                table[i] = shadow(RGB555(i))
147
148        machine->shadow_table = shadow_table[0]
149
150
151
152    palette_config strategy:
153
154        recompute_adjusted_colors
155            - for all pens, internal_modify_pen with current palette->raw_color and palette->pen_brightness
156            - updates palette->raw_color and palette->adjusted_color
157            - if (!rgb_direct) updates machine->pens
158
159*/
160
161
162/***************************************************************************
163    FUNCTION PROTOTYPES
164***************************************************************************/
165
166static void configure_rgb_shadows(running_machine *machine, int mode, float factor);
167static void palette_exit(running_machine *machine);
168static void palette_alloc(running_machine *machine, palette_private *palette);
169static void palette_reset(void);
170static void recompute_adjusted_colors(running_machine *machine);
171static void internal_modify_pen(running_machine *machine, palette_private *palette, pen_t pen, rgb_t color, int pen_bright);
172
173
174
175/***************************************************************************
176    INLINE FUNCTIONS
177***************************************************************************/
178
179/*-------------------------------------------------
180    clamp_rgb_component - clamp an RGB component
181    to 0-255
182-------------------------------------------------*/
183
184INLINE UINT8 clamp_rgb_component(INT32 value)
185{
186   if (value < 0)
187      return 0;
188   if (value > 255)
189      return 255;
190   return value;
191}
192
193
194
195/*-------------------------------------------------
196    rgb_to_direct15 - convert an RGB triplet to
197    a 15-bit OSD-specified RGB value
198-------------------------------------------------*/
199
200INLINE UINT16 rgb_to_direct15(rgb_t rgb)
201{
202   return ((RGB_RED(rgb) >> 3) << 10) | ((RGB_GREEN(rgb) >> 3) << 5) | ((RGB_BLUE(rgb) >> 3) << 0);
203}
204
205
206
207/*-------------------------------------------------
208    adjust_palette_entry - adjust a palette
209    entry for brightness and gamma
210-------------------------------------------------*/
211
212INLINE rgb_t adjust_palette_entry(rgb_t entry, int pen_bright)
213{
214   int r = (RGB_RED(entry) * pen_bright) >> PEN_BRIGHTNESS_BITS;
215   int g = (RGB_GREEN(entry) * pen_bright) >> PEN_BRIGHTNESS_BITS;
216   int b = (RGB_BLUE(entry) * pen_bright) >> PEN_BRIGHTNESS_BITS;
217   return MAKE_RGB(r,g,b);
218}
219
220
221
222/*-------------------------------------------------
223    notify_pen_changed - call all registered
224    notifiers that a pen has changed
225-------------------------------------------------*/
226
227INLINE void notify_pen_changed(palette_private *palette, int pen, rgb_t newval)
228{
229   callback_item *cb;
230   for (cb = palette->notify_callback_list; cb; cb = cb->next)
231      (*cb->notify)(cb->param, pen, newval);
232}
233
234
235
236/*-------------------------------------------------
237    palette_init - palette initialization that
238    takes place before the display is created
239-------------------------------------------------*/
240
241void palette_init(running_machine *machine)
242{
243   palette_private *palette = auto_malloc(sizeof(*palette));
244   int format = machine->screen[0].format;
245
246   /* request cleanup */
247   machine->palette_data = palette;
248   add_exit_callback(machine, palette_exit);
249
250   /* reset all our data */
251   memset(palette, 0, sizeof(*palette));
252   palette->shadow_factor = (int)(PALETTE_DEFAULT_SHADOW_FACTOR * (double)(1 << PEN_BRIGHTNESS_BITS));
253   palette->highlight_factor = (int)(PALETTE_DEFAULT_HIGHLIGHT_FACTOR * (double)(1 << PEN_BRIGHTNESS_BITS));
254
255   /* determine the color mode */
256   switch (format)
257   {
258      case BITMAP_FORMAT_INDEXED16:
259         /* indexed modes are fine for everything */
260         break;
261
262      case BITMAP_FORMAT_RGB15:
263      case BITMAP_FORMAT_RGB32:
264         /* RGB modes can't use color tables */
265         assert(machine->drv->color_table_len == 0);
266         break;
267
268      case BITMAP_FORMAT_INVALID:
269         /* invalid format means no palette - or at least it should */
270         assert(machine->drv->total_colors == 0);
271         assert(machine->drv->color_table_len == 0);
272         return;
273
274      default:
275         fatalerror("Unsupported screen bitmap format!");
276         break;
277   }
278
279   /* compute the total colors, including shadows and highlights */
280   palette->total_colors = machine->drv->total_colors;
281   if ((machine->drv->video_attributes & VIDEO_HAS_SHADOWS) && format == BITMAP_FORMAT_INDEXED16)
282      palette->total_colors += machine->drv->total_colors;
283   if ((machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS) && format == BITMAP_FORMAT_INDEXED16)
284      palette->total_colors += machine->drv->total_colors;
285   palette->total_colors_with_ui = palette->total_colors;
286
287   /* make sure we still fit in 16 bits */
288   assert_always(palette->total_colors <= 65536, "Error: palette has more than 65536 colors.");
289
290   /* allocate all the data structures */
291   palette_alloc(machine, palette);
292
293   /* set up save/restore of the palette */
294   if (machine->drv->total_colors > 0)
295   {
296      state_save_register_global_pointer(palette->raw_color, palette->total_colors);
297      state_save_register_global_pointer(palette->pen_brightness, machine->drv->total_colors);
298      state_save_register_func_postload(palette_reset);
299   }
300}
301
302
303/*-------------------------------------------------
304    palette_exit - free any allocated memory
305-------------------------------------------------*/
306
307static void palette_exit(running_machine *machine)
308{
309   palette_private *palette = machine->palette_data;
310
311   /* free the list of notifiers */
312   while (palette->notify_callback_list != NULL)
313   {
314      callback_item *temp = palette->notify_callback_list;
315      palette->notify_callback_list = palette->notify_callback_list->next;
316      free(temp);
317   }
318}
319
320
321/*-------------------------------------------------
322    palette_alloc - allocate memory for palette
323    structures
324-------------------------------------------------*/
325
326static void palette_alloc(running_machine *machine, palette_private *palette)
327{
328   int format = machine->screen[0].format;
329   int max_total_colors = palette->total_colors + 2;
330   int i;
331
332   /* allocate memory for the raw game palette */
333   palette->raw_color = auto_malloc(max_total_colors * sizeof(palette->raw_color[0]));
334   for (i = 0; i < max_total_colors; i++)
335      palette->raw_color[i] = MAKE_RGB((i & 1) * 0xff, ((i >> 1) & 1) * 0xff, ((i >> 2) & 1) * 0xff);
336
337   /* allocate memory for the adjusted game palette */
338   palette->adjusted_color = auto_malloc(max_total_colors * sizeof(palette->adjusted_color[0]));
339   for (i = 0; i < max_total_colors; i++)
340      palette->adjusted_color[i] = palette->raw_color[i];
341
342   /* for 16bpp, notify that all pens have changed */
343   if (format == BITMAP_FORMAT_INDEXED16)
344      for (i = 0; i < max_total_colors; i++)
345         notify_pen_changed(palette, i, palette->adjusted_color[i]);
346
347   /* allocate memory for the pen table */
348   if (palette->total_colors > 0)
349   {
350      machine->pens = auto_malloc(palette->total_colors * sizeof(machine->pens[0]));
351      for (i = 0; i < palette->total_colors; i++)
352         machine->pens[i] = i;
353
354      /* allocate memory for the per-entry brightness table */
355      palette->pen_brightness = auto_malloc(machine->drv->total_colors * sizeof(palette->pen_brightness[0]));
356      for (i = 0; i < machine->drv->total_colors; i++)
357         palette->pen_brightness[i] = 1 << PEN_BRIGHTNESS_BITS;
358   }
359   else
360   {
361      /* this driver does not use a palette */
362      machine->pens = NULL;
363      palette->pen_brightness = NULL;
364   }
365
366   /* allocate memory for the colortables, if needed */
367   if (machine->drv->color_table_len)
368   {
369      /* first for the raw colortable */
370      machine->game_colortable = auto_malloc(machine->drv->color_table_len * sizeof(machine->game_colortable[0]));
371      for (i = 0; i < machine->drv->color_table_len; i++)
372         machine->game_colortable[i] = i % palette->total_colors;
373
374      /* then for the remapped colortable */
375      machine->remapped_colortable = auto_malloc(machine->drv->color_table_len * sizeof(machine->remapped_colortable[0]));
376   }
377
378   /* otherwise, keep the game_colortable NULL and point the remapped_colortable to the pens */
379   else
380   {
381      machine->game_colortable = NULL;
382      machine->remapped_colortable = machine->pens;   /* straight 1:1 mapping from palette to colortable */
383   }
384
385   /* if we have shadows, allocate shadow tables */
386   if (machine->drv->video_attributes & VIDEO_HAS_SHADOWS)
387   {
388      pen_t *table = auto_malloc(65536 * sizeof(*table));
389
390      /* palettized mode gets a single 64k table in slots 0 and 2 */
391      if (format == BITMAP_FORMAT_INDEXED16)
392      {
393         palette->shadow_table_base[0] = palette->shadow_table_base[2] = table;
394         for (i = 0; i < 65536; i++)
395            table[i] = (i < machine->drv->total_colors) ? (i + machine->drv->total_colors) : i;
396         palette_set_shadow_factor(machine, PALETTE_DEFAULT_SHADOW_FACTOR);
397      }
398
399      /* RGB mode gets two 32k tables in slots 0 and 2 */
400      else
401      {
402         palette->shadow_table_base[0] = table;
403         palette->shadow_table_base[2] = table + 32768;
404         configure_rgb_shadows(machine, 0, PALETTE_DEFAULT_SHADOW_FACTOR);
405      }
406   }
407
408   /* if we have hilights, allocate shadow tables */
409   if (machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS)
410   {
411      pen_t *table = auto_malloc(65536 * sizeof(*table));
412
413      /* palettized mode gets a single 64k table in slots 1 and 3 */
414      if (format == BITMAP_FORMAT_INDEXED16)
415      {
416         palette->shadow_table_base[1] = palette->shadow_table_base[3] = table;
417         for (i = 0; i < 65536; i++)
418            table[i] = (i < machine->drv->total_colors) ? (i + 2 * machine->drv->total_colors) : i;
419         palette_set_highlight_factor(machine, PALETTE_DEFAULT_HIGHLIGHT_FACTOR);
420      }
421
422      /* RGB mode gets two 32k tables in slots 1 and 3 */
423      else
424      {
425         palette->shadow_table_base[1] = table;
426         palette->shadow_table_base[3] = table + 32768;
427         configure_rgb_shadows(machine, 1, PALETTE_DEFAULT_HIGHLIGHT_FACTOR);
428      }
429   }
430
431   /* set the default table */
432   machine->shadow_table = palette->shadow_table_base[0];
433}
434
435
436/*-------------------------------------------------
437    palette_config - palette initialization that
438    takes place after the display is created
439-------------------------------------------------*/
440
441void palette_config(running_machine *machine)
442{
443   palette_private *palette = machine->palette_data;
444   int i;
445
446   /* recompute the default palette and initalize the color correction table */
447   recompute_adjusted_colors(machine);
448
449   /* now let the driver modify the initial palette and colortable */
450   if (machine->drv->init_palette)
451      (*machine->drv->init_palette)(machine, machine->game_colortable, memory_region(REGION_PROMS));
452
453   /* switch off the color mode */
454   switch (machine->screen[0].format)
455   {
456      /* 16-bit paletteized case */
457      case BITMAP_FORMAT_INDEXED16:
458      {
459         /* refresh the palette to support shadows in static palette games */
460         for (i = 0; i < machine->drv->total_colors; i++)
461            palette_set_color(machine, i, palette->raw_color[i]);
462
463         /* map the UI pens */
464         if (palette->total_colors_with_ui <= 65534)
465         {
466            palette->total_colors_with_ui += 2;
467            palette->black_pen = palette->total_colors + 0;
468            palette->white_pen = palette->total_colors + 1;
469         }
470         else
471         {
472            palette->black_pen = 0;
473            palette->white_pen = 65535;
474         }
475         notify_pen_changed(palette, palette->black_pen, palette->raw_color[palette->black_pen] = palette->adjusted_color[palette->black_pen] = MAKE_RGB(0x00,0x00,0x00));
476         notify_pen_changed(palette, palette->white_pen, palette->raw_color[palette->white_pen] = palette->adjusted_color[palette->white_pen] = MAKE_RGB(0xff,0xff,0xff));
477         break;
478      }
479
480      /* 15-bit direct case */
481      case BITMAP_FORMAT_RGB15:
482      {
483         /* remap the game palette into direct RGB pens */
484         for (i = 0; i < palette->total_colors; i++)
485            machine->pens[i] = rgb_to_direct15(palette->raw_color[i]);
486
487         /* map the UI pens */
488         palette->black_pen = rgb_to_direct15(MAKE_RGB(0x00,0x00,0x00));
489         palette->white_pen = rgb_to_direct15(MAKE_RGB(0xff,0xff,0xff));
490         break;
491      }
492
493      /* 32-bit direct case */
494      case BITMAP_FORMAT_RGB32:
495      {
496         /* remap the game palette into direct RGB pens */
497         for (i = 0; i < palette->total_colors; i++)
498            machine->pens[i] = palette->raw_color[i];
499
500         /* map the UI pens */
501         palette->black_pen = MAKE_RGB(0x00,0x00,0x00);
502         palette->white_pen = MAKE_RGB(0xff,0xff,0xff);
503         break;
504      }
505
506      /* screenless case */
507      case BITMAP_FORMAT_INVALID:
508         break;
509
510      default:
511         fatalerror("Unhandled bitmap format!");
512         break;
513   }
514
515   /* now compute the remapped_colortable */
516   for (i = 0; i < machine->drv->color_table_len; i++)
517   {
518      pen_t color = machine->game_colortable[i];
519
520      /* check for invalid colors set by machine->drv->init_palette */
521      assert(color < palette->total_colors);
522      machine->remapped_colortable[i] = machine->pens[color];
523   }
524}
525
526
527/*-------------------------------------------------
528    palette_add_notifier - request a callback on
529    changing of a palette entry
530-------------------------------------------------*/
531
532void palette_add_notifier(running_machine *machine, void (*callback)(void *, int, rgb_t), void *param)
533{
534   palette_private *palette = machine->palette_data;
535   callback_item *cb;
536
537   assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call palette_add_notifier at init time!");
538
539   /* allocate memory */
540   cb = malloc_or_die(sizeof(*cb));
541
542   /* add us to the head of the list */
543   cb->notify = callback;
544   cb->param = param;
545   cb->next = palette->notify_callback_list;
546   palette->notify_callback_list = cb;
547}
548
549
550/*-------------------------------------------------
551    palette_add_notifier - request a callback on
552    changing of a palette entry
553-------------------------------------------------*/
554
555rgb_t *palette_get_raw_colors(running_machine *machine)
556{
557   palette_private *palette = machine->palette_data;
558   return palette->raw_color;
559}
560
561
562/*-------------------------------------------------
563    palette_add_notifier - request a callback on
564    changing of a palette entry
565-------------------------------------------------*/
566
567rgb_t *palette_get_adjusted_colors(running_machine *machine)
568{
569   palette_private *palette = machine->palette_data;
570   return palette->adjusted_color;
571}
572
573
574/*-------------------------------------------------
575
576    palette_set_shadow_mode(mode)
577
578        mode: 0 = use preset 0 (default shadow)
579              1 = use preset 1 (default highlight)
580              2 = use preset 2 *
581              3 = use preset 3 *
582
583    * Preset 2 & 3 work independently under 32bpp,
584      supporting up to four different types of
585      shadows at one time. They mirror preset 1 & 2
586      in lower depth settings to maintain
587      compatibility.
588
589
590    palette_set_shadow_dRGB32(mode, dr, dg, db, noclip)
591
592        mode:    0 to   3 (which preset to configure)
593
594          dr: -255 to 255 ( red displacement )
595          dg: -255 to 255 ( green displacement )
596          db: -255 to 255 ( blue displacement )
597
598        noclip: 0 = resultant RGB clipped at 0x00/0xff
599                1 = resultant RGB wraparound 0x00/0xff
600
601
602    * Color shadows only work under 32bpp.
603      This function has no effect in lower color
604      depths where
605
606        palette_set_shadow_factor() or
607        palette_set_highlight_factor()
608
609      should be used instead.
610
611    * 32-bit shadows are lossy. Even with zero RGB
612      displacements the affected area will still look
613      slightly darkened.
614
615      Drivers should ensure all shadow pens in
616      gfx_drawmode_table[] are set to DRAWMODE_NONE
617      when RGB displacements are zero to avoid the
618      darkening effect.
619
620-------------------------------------------------*/
621
622static void configure_rgb_shadows(running_machine *machine, int mode, float factor)
623{
624   int format = machine->screen[0].format;
625   palette_private *palette = machine->palette_data;
626   pen_t *table = palette->shadow_table_base[mode];
627   int ifactor = (int)(factor * 256.0f);
628   int i;
629
630   /* only applies to RGB direct modes */
631   assert(format != BITMAP_FORMAT_INDEXED16);
632   assert(table != NULL);
633
634   #if VERBOSE
635      popmessage("shadow %d recalc %d %d %d %02x", mode, dr, dg, db, noclip);
636   #endif
637
638   /* regenerate the table */
639   for (i = 0; i < 32768; i++)
640   {
641      UINT8 r = clamp_rgb_component((pal5bit(i >> 10) * ifactor) >> 8);
642      UINT8 g = clamp_rgb_component((pal5bit(i >> 5) * ifactor) >> 8);
643      UINT8 b = clamp_rgb_component((pal5bit(i >> 0) * ifactor) >> 8);
644      pen_t final = MAKE_RGB(r, g, b);
645
646      /* store either 16 or 32 bit */
647      if (format == BITMAP_FORMAT_RGB32)
648         table[i] = final;
649      else
650         table[i] = rgb_to_direct15(final);
651   }
652}
653
654
655void palette_set_shadow_mode(running_machine *machine, int mode)
656{
657   palette_private *palette = machine->palette_data;
658   assert(mode >= 0 && mode < MAX_SHADOW_PRESETS);
659   machine->shadow_table = palette->shadow_table_base[mode];
660}
661
662
663void palette_set_shadow_dRGB32(running_machine *machine, int mode, int dr, int dg, int db, int noclip)
664{
665   int format = machine->screen[0].format;
666   palette_private *palette = machine->palette_data;
667   pen_t *table = palette->shadow_table_base[mode];
668   int i;
669
670   /* only applies to RGB direct modes */
671   assert(format != BITMAP_FORMAT_INDEXED16);
672   assert(table != NULL);
673
674   /* clamp the deltas (why?) */
675   if (dr < -0xff) dr = -0xff; else if (dr > 0xff) dr = 0xff;
676   if (dg < -0xff) dg = -0xff; else if (dg > 0xff) dg = 0xff;
677   if (db < -0xff) db = -0xff; else if (db > 0xff) db = 0xff;
678
679   /* early exit if nothing changed */
680   if (dr == palette->shadow_dr[mode] && dg == palette->shadow_dg[mode] && db == palette->shadow_db[mode] && noclip == palette->shadow_noclip[mode])
681      return;
682   palette->shadow_dr[mode] = dr;
683   palette->shadow_dg[mode] = dg;
684   palette->shadow_db[mode] = db;
685   palette->shadow_noclip[mode] = noclip;
686
687   #if VERBOSE
688      popmessage("shadow %d recalc %d %d %d %02x", mode, dr, dg, db, noclip);
689   #endif
690
691   /* regenerate the table */
692   for (i = 0; i < 32768; i++)
693   {
694      int r = pal5bit(i >> 10) + dr;
695      int g = pal5bit(i >> 5) + dg;
696      int b = pal5bit(i >> 0) + db;
697      pen_t final;
698
699      /* apply clipping */
700      if (!noclip)
701      {
702         r = clamp_rgb_component(r);
703         g = clamp_rgb_component(g);
704         b = clamp_rgb_component(b);
705      }
706      final = MAKE_RGB(r, g, b);
707
708      /* store either 16 or 32 bit */
709      if (format == BITMAP_FORMAT_RGB32)
710         table[i] = final;
711      else
712         table[i] = rgb_to_direct15(final);
713   }
714}
715
716
717
718/*-------------------------------------------------
719    palette_get_total_colors_with_ui - returns
720    the total number of palette entries including
721    UI
722-------------------------------------------------*/
723
724int palette_get_total_colors_with_ui(running_machine *machine)
725{
726   int format = machine->screen[0].format;
727   int result = machine->drv->total_colors;
728   if (machine->drv->video_attributes & VIDEO_HAS_SHADOWS && format == BITMAP_FORMAT_INDEXED16)
729      result += machine->drv->total_colors;
730   if (machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS && format == BITMAP_FORMAT_INDEXED16)
731      result += machine->drv->total_colors;
732   if (result <= 65534 && format != BITMAP_FORMAT_INVALID)
733      result += 2;
734   return result;
735}
736
737
738
739/*-------------------------------------------------
740    internal_modify_single_pen - change a single
741    pen and recompute its adjusted RGB value
742-------------------------------------------------*/
743
744static void internal_modify_single_pen(running_machine *machine, palette_private *palette, pen_t pen, rgb_t color, int pen_bright)
745{
746   rgb_t adjusted_color;
747
748   /* skip if out of bounds or not ready */
749   if (pen >= palette->total_colors)
750      return;
751
752   /* update the raw palette */
753   palette->raw_color[pen] = color;
754
755   /* now update the adjusted color if it's different */
756   adjusted_color = adjust_palette_entry(color, pen_bright);
757   if (adjusted_color != palette->adjusted_color[pen])
758   {
759      /* change the adjusted palette entry */
760      palette->adjusted_color[pen] = adjusted_color;
761
762      /* update the pen value */
763      switch (machine->screen[0].format)
764      {
765         /* 16-bit palettized */
766         case BITMAP_FORMAT_INDEXED16:
767            notify_pen_changed(palette, pen, adjusted_color);
768            break;
769
770         /* 15/32-bit direct: update the machine->pens array */
771         case BITMAP_FORMAT_RGB15:
772            machine->pens[pen] = rgb_to_direct15(adjusted_color);
773            break;
774
775         case BITMAP_FORMAT_RGB32:
776            machine->pens[pen] = adjusted_color;
777            break;
778
779         /* other formats unexpected */
780         default:
781            fatalerror("Unhandled bitmap format!");
782            break;
783      }
784   }
785}
786
787
788
789/*-------------------------------------------------
790    internal_modify_pen - change a pen along with
791    its corresponding shadow/highlight
792-------------------------------------------------*/
793
794static void internal_modify_pen(running_machine *machine, palette_private *palette, pen_t pen, rgb_t color, int pen_bright) //* new highlight operation
795{
796   /* first modify the base pen */
797   internal_modify_single_pen(machine, palette, pen, color, pen_bright);
798
799   /* see if we need to handle shadow/highlight */
800   if (pen < machine->drv->total_colors)
801   {
802      /* check for shadows */
803      if (machine->drv->video_attributes & VIDEO_HAS_SHADOWS)
804         internal_modify_single_pen(machine, palette, pen + machine->drv->total_colors, color, (pen_bright * palette->shadow_factor) >> PEN_BRIGHTNESS_BITS);
805
806      /* check for highlights */
807      if (machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS)
808         internal_modify_single_pen(machine, palette, pen + 2*machine->drv->total_colors, color, (pen_bright * palette->highlight_factor) >> PEN_BRIGHTNESS_BITS);
809   }
810}
811
812
813
814/*-------------------------------------------------
815    recompute_adjusted_colors - recompute the
816    entire palette after some major event
817-------------------------------------------------*/
818
819static void recompute_adjusted_colors(running_machine *machine)
820{
821   palette_private *palette = machine->palette_data;
822   int i;
823
824   /* now update all the palette entries */
825   for (i = 0; i < machine->drv->total_colors; i++)
826      internal_modify_pen(machine, palette, i, palette->raw_color[i], palette->pen_brightness[i]);
827}
828
829
830/*-------------------------------------------------
831    palette_reset - called after restore to
832    actually update the palette
833-------------------------------------------------*/
834
835static void palette_reset(void)
836{
837   /* recompute everything */
838   recompute_adjusted_colors(Machine);
839}
840
841
842/*-------------------------------------------------
843    palette_set_color - set a single palette
844    entry
845-------------------------------------------------*/
846
847void palette_set_color(running_machine *machine, pen_t pen, rgb_t rgb)
848{
849   palette_private *palette = machine->palette_data;
850   assert(pen < palette->total_colors);
851   internal_modify_pen(machine, palette, pen, rgb, palette->pen_brightness[pen]);
852}
853
854
855/*-------------------------------------------------
856    palette_get_color - return a single palette
857    entry
858-------------------------------------------------*/
859
860rgb_t palette_get_color(running_machine *machine, pen_t pen)
861{
862   palette_private *palette = machine->palette_data;
863
864   /* record the result from the game palette */
865   if (pen < palette->total_colors)
866      return palette->raw_color[pen];
867
868   /* special case the black pen */
869   else if (pen == palette->black_pen)
870      return MAKE_RGB(0,0,0);
871
872   /* special case the white pen (crosshairs) */
873   else if (pen == palette->white_pen)
874      return MAKE_RGB(255,255,255);
875
876   else
877      popmessage("palette_get_color() out of range");
878   return 0;
879}
880
881
882/*-------------------------------------------------
883    palette_set_brightness - set the per-pen
884    brightness factor
885-------------------------------------------------*/
886
887void palette_set_brightness(running_machine *machine, pen_t pen, double bright)
888{
889   palette_private *palette = machine->palette_data;
890
891   /* compute the integral brightness value */
892   int brightval = (int)(bright * (double)(1 << PEN_BRIGHTNESS_BITS));
893   if (brightval > MAX_PEN_BRIGHTNESS)
894      brightval = MAX_PEN_BRIGHTNESS;
895
896   /* if it changed, update the array and the adjusted palette */
897   if (palette->pen_brightness[pen] != brightval)
898   {
899      palette->pen_brightness[pen] = brightval;
900      internal_modify_pen(machine, palette, pen, palette->raw_color[pen], brightval);
901   }
902}
903
904
905/*-------------------------------------------------
906    palette_set_shadow_factor - set the global
907    shadow brightness factor
908-------------------------------------------------*/
909
910void palette_set_shadow_factor(running_machine *machine, double factor)
911{
912   palette_private *palette = machine->palette_data;
913
914   /* compute the integral shadow factor value */
915   int factorval = (int)(factor * (double)(1 << PEN_BRIGHTNESS_BITS));
916   if (factorval > MAX_PEN_BRIGHTNESS)
917      factorval = MAX_PEN_BRIGHTNESS;
918
919   /* if it changed, update the entire palette */
920   if (palette->shadow_factor != factorval)
921   {
922      palette->shadow_factor = factorval;
923      recompute_adjusted_colors(machine);
924   }
925}
926
927
928/*-------------------------------------------------
929    palette_set_highlight_factor - set the global
930    highlight brightness factor
931-------------------------------------------------*/
932
933void palette_set_highlight_factor(running_machine *machine, double factor)
934{
935   palette_private *palette = machine->palette_data;
936
937   /* compute the integral highlight factor value */
938   int factorval = (int)(factor * (double)(1 << PEN_BRIGHTNESS_BITS));
939   if (factorval > MAX_PEN_BRIGHTNESS)
940      factorval = MAX_PEN_BRIGHTNESS;
941
942   /* if it changed, update the entire palette */
943   if (palette->highlight_factor != factorval)
944   {
945      palette->highlight_factor = factorval;
946      recompute_adjusted_colors(machine);
947   }
948}
949
950
951/*-------------------------------------------------
952    get_black_pen - use this if you need to
953    fillbitmap() the background with black
954-------------------------------------------------*/
955
956pen_t get_black_pen(running_machine *machine)
957{
958   palette_private *palette = machine->palette_data;
959   return palette->black_pen;
960}
961
962pen_t get_white_pen(running_machine *machine)
963{
964   palette_private *palette = machine->palette_data;
965   return palette->white_pen;
966}
967
968
969/*-------------------------------------------------
970    palette_normalize_range - normalize a range
971    of palette entries
972-------------------------------------------------*/
973
974void palette_normalize_range(running_machine *machine, int start, int end, int lum_min, int lum_max)
975{
976   palette_private *palette = machine->palette_data;
977   UINT32 ymin = 1000 * 255, ymax = 0;
978   UINT32 tmin, tmax;
979   int pen;
980
981   assert(end >= start);
982   assert(end < palette->total_colors);
983
984   /* find the minimum and maximum brightness of all the pens in the range */
985   for (pen = start; pen <= end; pen++)
986   {
987      rgb_t rgb = palette->raw_color[pen];
988      UINT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
989      ymin = MIN(ymin, y);
990      ymax = MAX(ymax, y);
991   }
992
993   /* determine target minimum/maximum */
994   tmin = (lum_min < 0) ? ((ymin + 500) / 1000) : lum_min;
995   tmax = (lum_max < 0) ? ((ymax + 500) / 1000) : lum_max;
996
997   /* now normalize the palette */
998   for (pen = start; pen <= end; pen++)
999   {
1000      rgb_t rgb = palette->raw_color[pen];
1001      UINT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
1002      UINT32 target = tmin + ((y - ymin) * (tmax - tmin + 1)) / (ymax - ymin);
1003      UINT8 r = (y == 0) ? 0 : clamp_rgb_component(RGB_RED(rgb) * 1000 * target / y);
1004      UINT8 g = (y == 0) ? 0 : clamp_rgb_component(RGB_GREEN(rgb) * 1000 * target / y);
1005      UINT8 b = (y == 0) ? 0 : clamp_rgb_component(RGB_BLUE(rgb) * 1000 * target / y);
1006      internal_modify_pen(machine, palette, pen, MAKE_RGB(r, g, b), palette->pen_brightness[pen]);
1007   }
1008}
src/emu/palette.h
r1046r1047
1/******************************************************************************
2
3    palette.c
4
5    Palette handling functions.
6
7    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10    There are several levels of abstraction in the way MAME handles the palette,
11    and several display modes which can be used by the drivers.
12
13    Palette
14    -------
15    Note: in the following text, "color" refers to a color in the emulated
16    game's virtual palette. For example, a game might be able to display 1024
17    colors at the same time. If the game uses RAM to change the available
18    colors, the term "palette" refers to the colors available at any given time,
19    not to the whole range of colors which can be produced by the hardware. The
20    latter is referred to as "color space".
21    The term "pen" refers to one of the maximum MAX_PENS colors that can be
22    used to generate the display.
23
24    So, to summarize, the three layers of palette abstraction are:
25
26    P1) The game virtual palette (the "colors")
27    P2) MAME's MAX_PENS colors palette (the "pens")
28    P3) The OS specific hardware color registers (the "OS specific pens")
29
30    The array Machine->pens[] is a lookup table which maps game colors to OS
31    specific pens (P1 to P3). When you are working on bitmaps at the pixel level,
32    *always* use Machine->pens to map the color numbers. *Never* use constants.
33    For example if you want to make pixel (x,y) of color 3, do:
34    *BITMAP_ADDR(bitmap, <type>, y, x) = Machine->pens[3];
35
36
37    Lookup table
38    ------------
39    Palettes are only half of the story. To map the gfx data to colors, the
40    graphics routines use a lookup table. For example if we have 4bpp tiles,
41    which can have 256 different color codes, the lookup table for them will have
42    256 * 2^4 = 4096 elements. For games using a palette RAM, the lookup table is
43    usually a 1:1 map. For games using PROMs, the lookup table is often larger
44    than the palette itself so for example the game can display 256 colors out
45    of a palette of 16.
46
47    The palette and the lookup table are initialized to default values by the
48    main core, but can be initialized by the driver using the function
49    MachineDriver->vh_init_palette(). For games using palette RAM, that
50    function is usually not needed, and the lookup table can be set up by
51    properly initializing the color_codes_start and total_color_codes fields in
52    the GfxDecodeInfo array.
53    When vh_init_palette() initializes the lookup table, it maps gfx codes
54    to game colors (P1 above). The lookup table will be converted by the core to
55    map to OS specific pens (P3 above), and stored in Machine->remapped_colortable.
56
57
58    Display modes
59    -------------
60    The available display modes can be summarized in three categories:
61    1) Static palette. Use this for games which use PROMs for color generation.
62        The palette is initialized by palette_init(), and never changed
63        again.
64    2) Dynamic palette. Use this for games which use RAM for color generation.
65        The palette can be dynamically modified by the driver using the function
66        palette_set_color().
67    3) Direct mapped 16-bit or 32-bit color. This should only be used in special
68        cases, e.g. to support alpha blending.
69        MachineDriver->video_attributes must contain VIDEO_RGB_DIRECT.
70
71
72    Shadows(Highlights) Quick Reference
73    -----------------------------------
74
75    1) declare MDRV_VIDEO_ATTRIBUTES( ... VIDEO_HAS_SHADOWS | VIDEO_HAS_HIGHLIGHTS ... )
76
77    2) set gfx_drawmode_table[0-n] to DRAWMODE_NONE, DRAWMODE_SOURCE or DRAWMODE_SHADOW
78
79    3) (optional) set shadow darkness or highlight brightness by
80        palette_set_shadow_factor(0.0-1.0) or
81        palette_set_highlight_factor(1.0-n.n)
82
83    4) before calling drawgfx use
84        palette_set_shadow_mode(0) to arm shadows or
85        palette_set_shadow_mode(1) to arm highlights
86
87    5) call drawgfx with the TRANSPARENCY_PEN_TABLE flag
88        drawgfx( ..., cliprect, TRANSPARENCY_PEN_TABLE, transparent_color )
89
90******************************************************************************/
91
92#pragma once
93
94#ifndef __PALETTE_H__
95#define __PALETTE_H__
96
97#include "memory.h"
98
99
100/***************************************************************************
101    CONSTANTS
102***************************************************************************/
103
104#define PALETTE_DEFAULT_SHADOW_FACTOR (0.6)
105#define PALETTE_DEFAULT_HIGHLIGHT_FACTOR (1/PALETTE_DEFAULT_SHADOW_FACTOR)
106
107
108
109/***************************************************************************
110    MACROS
111***************************************************************************/
112
113#define MAKE_RGB(r,g,b)    ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff))
114#define MAKE_ARGB(a,r,g,b)   (MAKE_RGB(r,g,b) | (((a) & 0xff) << 24))
115#define RGB_ALPHA(rgb)      (((rgb) >> 24) & 0xff)
116#define RGB_RED(rgb)      (((rgb) >> 16) & 0xff)
117#define RGB_GREEN(rgb)      (((rgb) >> 8) & 0xff)
118#define RGB_BLUE(rgb)      ((rgb) & 0xff)
119
120#define RGB_BLACK         (MAKE_RGB(0,0,0))
121#define RGB_WHITE         (MAKE_RGB(255,255,255))
122
123
124
125/***************************************************************************
126    FUNCTION PROTOTYPES
127***************************************************************************/
128
129void palette_init(running_machine *machine);
130void palette_config(running_machine *machine);
131void palette_add_notifier(running_machine *machine, void (*callback)(void *, int, rgb_t), void *param);
132int palette_get_total_colors_with_ui(running_machine *machine);
133
134rgb_t *palette_get_raw_colors(running_machine *machine);
135rgb_t *palette_get_adjusted_colors(running_machine *machine);
136
137void palette_set_color(running_machine *machine, pen_t pen, rgb_t rgb);
138rgb_t palette_get_color(running_machine *machine, pen_t pen);
139
140void palette_set_brightness(running_machine *machine, pen_t pen, double bright);
141void palette_set_shadow_factor(running_machine *machine, double factor);
142void palette_set_highlight_factor(running_machine *machine, double factor);
143
144void palette_set_shadow_mode(running_machine *machine, int mode);
145void palette_set_shadow_dRGB32(running_machine *machine, int mode, int dr, int dg, int db, int noclip);
146
147pen_t get_black_pen(running_machine *machine);
148pen_t get_white_pen(running_machine *machine);
149
150/* normalize the palette
151 *
152 * Calling this function will normalize the palette,
153 * mapping the minimum brightness/luminance to lum_min
154 * and the maximum brightness to lum_max.
155 * If lum_min is less than 0, the minimum luminance is
156 * preserved, if lum_max is less than 0, the maximum luminance
157 * is preserved.
158 *
159 * start and end denote the range of palette entries to be normalized.
160 */
161
162void palette_normalize_range(running_machine *machine, int start, int end, int lum_min, int lum_max);
163
164
165
166/***************************************************************************
167    INLINE FUNCTIONS
168***************************************************************************/
169
170/*-------------------------------------------------
171    palette_set_color_rgb - set a single palette
172    entry with individual R,G,B components
173-------------------------------------------------*/
174
175INLINE void palette_set_color_rgb(running_machine *machine, pen_t pen, UINT8 r, UINT8 g, UINT8 b)
176{
177   palette_set_color(machine, pen, MAKE_RGB(r, g, b));
178}
179
180
181/*-------------------------------------------------
182    palette_set_colors - set multiple palette
183    entries from an array of rgb_t values
184-------------------------------------------------*/
185
186INLINE void palette_set_colors(running_machine *machine, pen_t color_base, const rgb_t *colors, int color_count)
187{
188   while (color_count--)
189      palette_set_color(machine, color_base++, *colors++);
190}
191
192
193/*-------------------------------------------------
194    pal1bit - convert a 1-bit value to 8 bits
195-------------------------------------------------*/
196
197INLINE UINT8 pal1bit(UINT8 bits)
198{
199   return (bits & 1) ? 0xff : 0x00;
200}
201
202
203/*-------------------------------------------------
204    pal2bit - convert a 2-bit value to 8 bits
205-------------------------------------------------*/
206
207INLINE UINT8 pal2bit(UINT8 bits)
208{
209   bits &= 3;
210   return (bits << 6) | (bits << 4) | (bits << 2) | bits;
211}
212
213
214/*-------------------------------------------------
215    pal3bit - convert a 3-bit value to 8 bits
216-------------------------------------------------*/
217
218INLINE UINT8 pal3bit(UINT8 bits)
219{
220   bits &= 7;
221   return (bits << 5) | (bits << 2) | (bits >> 1);
222}
223
224
225/*-------------------------------------------------
226    pal4bit - convert a 4-bit value to 8 bits
227-------------------------------------------------*/
228
229INLINE UINT8 pal4bit(UINT8 bits)
230{
231   bits &= 0xf;
232   return (bits << 4) | bits;
233}
234
235
236/*-------------------------------------------------
237    pal5bit - convert a 5-bit value to 8 bits
238-------------------------------------------------*/
239
240INLINE UINT8 pal5bit(UINT8 bits)
241{
242   bits &= 0x1f;
243   return (bits << 3) | (bits >> 2);
244}
245
246
247/*-------------------------------------------------
248    pal6bit - convert a 6-bit value to 8 bits
249-------------------------------------------------*/
250
251INLINE UINT8 pal6bit(UINT8 bits)
252{
253   bits &= 0x3f;
254   return (bits << 2) | (bits >> 4);
255}
256
257
258/*-------------------------------------------------
259    pal7bit - convert a 7-bit value to 8 bits
260-------------------------------------------------*/
261
262INLINE UINT8 pal7bit(UINT8 bits)
263{
264   bits &= 0x7f;
265   return (bits << 1) | (bits >> 6);
266}
267
268
269#endif   /* __PALETTE_H__ */
src/emu/cpu/z80/z80dasm.h
r1046r1047
1extern int DasmZ80(char *buffer, int PC);
2

Previous 15994 Revisions Next


© 1998-2018 The MESS Team