Previous 15994 Revisions Next

r2799 Sunday 1st June, 2008 at 16:48:53 UTC by Wilbert Pol
[POKEMINI] Cleaned up code a bit.
[src/mess/drivers]pokemini.c
[src/mess/includes]pokemini.h
[src/mess/machine]pokemini.c

src/mess/includes/pokemini.h
r2798r2799
1111/*----------- defined in machine/pokemini.c -----------*/
1212
1313extern UINT8 *pokemini_ram;
14extern MACHINE_RESET( pokemini );
15extern WRITE8_HANDLER( pokemini_hwreg_w );
16extern READ8_HANDLER( pokemini_hwreg_r );
17extern INTERRUPT_GEN( pokemini_int );
14MACHINE_RESET( pokemini );
15WRITE8_HANDLER( pokemini_hwreg_w );
16READ8_HANDLER( pokemini_hwreg_r );
1817
1918DEVICE_START( pokemini_cart );
2019DEVICE_IMAGE_LOAD( pokemini_cart );
2120
22
2321#endif /* POKEMINI_H */
src/mess/machine/pokemini.c
r2798r2799
1/**********************************************************************
2
3   Pokemini machine emulation.
4
5
6**********************************************************************/
7
8
19#include "driver.h"
210#include "includes/pokemini.h"
311#include "cpu/minx/minx.h"
r2798r2799
311
412
5struct VDP {
6   UINT8   colors_inverted;
7   UINT8   background_enabled;
8   UINT8   sprites_enabled;
9   UINT8   rendering_enabled;
10   UINT8   map_size;
11   UINT8   map_size_x;
12   UINT32   bg_tiles;
13   UINT32   spr_tiles;
13struct PRC
14{
15   UINT8      colors_inverted;
16   UINT8      background_enabled;
17   UINT8      sprites_enabled;
18   UINT8      copy_enabled;
19   UINT8      map_size;
20   UINT8      map_size_x;
21   UINT8      frame_count;
22   UINT8      max_frame_count;
23   UINT32      bg_tiles;
24   UINT32      spr_tiles;
25   UINT8      count;
26   emu_timer   *count_timer;
1427};
1528
16struct TIMERS {
17   UINT8      seconds_running;   /* Seconds timer running */
18   UINT32      seconds_counter;   /* Seconds timer counter */
29
30struct TIMERS
31{
1932   emu_timer   *seconds_timer;
20   UINT8      hz256_running;      /* 256Hz timer running */
21   UINT8      hz256_counter;      /* 256Hz timer counter */
2233   emu_timer   *hz256_timer;
23   UINT8      timers_enabled;      /* Timers 1 to 3 enabled */
24   UINT16      timer1_counter;
25   emu_timer   *timer1_timer;      /* Timer 1 */
26   UINT16      timer2_counter;
27   emu_timer   *timer2_timer;      /* Timer 2 */
28   UINT16      timer3_counter;
29   emu_timer   *timer3_timer;      /* Timer 3 */
34   emu_timer   *timer1;            /* Timer 1 low or 16bit */
35   emu_timer   *timer1_hi;            /* Timer 1 hi */
36   emu_timer   *timer2;            /* Timer 2 low or 16bit */
37   emu_timer   *timer2_hi;            /* Timer 2 high */
38   emu_timer   *timer3;            /* Timer 3 low or 16bit */
39   emu_timer   *timer3_hi;            /* Timer 3 high */
3040};
3141
42
3243UINT8   *pokemini_ram;
33
34static UINT8 pokemini_hwreg[0x100];
35static struct VDP vdp;
44static UINT8 pm_reg[0x100];
45static struct PRC prc;
3646static struct TIMERS timers;
3747
48
49static void pokemini_check_irqs( running_machine *machine )
50{
51   int irq_set[4] = { 1, 0, 0, 0 };
52   int prio, vector;
53
54   /* Check IRQ $03-$04 */
55   prio = ( pm_reg[0x20] >> 6 ) & 0x03;
56   if ( ! irq_set[prio] )
57   {
58      if ( pm_reg[0x23] & pm_reg[0x27] & 0x40 )
59         irq_set[prio] = 0x04;
60
61      if ( pm_reg[0x23] & pm_reg[0x27] & 0x80 )
62         irq_set[prio] = 0x03;
63   }
64
65   /* Check IRQ $05-$06 */
66   prio = ( pm_reg[0x20] >> 4 ) & 0x03;
67   if ( ! irq_set[prio] )
68   {
69      if ( pm_reg[0x23] & pm_reg[0x27] & 0x10 )
70         irq_set[prio] = 0x06;
71
72      if ( pm_reg[0x23] & pm_reg[0x27] & 0x20 )
73         irq_set[prio] = 0x05;
74   }
75
76   /* Check IRQ $07-$08 */
77   prio = ( pm_reg[0x20] >> 2 ) & 0x03;
78   if ( ! irq_set[prio] )
79   {
80      if ( pm_reg[0x23] & pm_reg[0x27] & 0x04 )
81         irq_set[prio] = 0x08;
82
83      if ( pm_reg[0x23] & pm_reg[0x27] & 0x08 )
84         irq_set[prio] = 0x07;
85   }
86
87   /* Check IRQ $09-$0A */
88   prio = ( pm_reg[0x20] >> 0 ) & 0x03;
89   if ( ! irq_set[prio] )
90   {
91      if ( pm_reg[0x23] & pm_reg[0x27] & 0x01 )
92         irq_set[prio] = 0x0A;
93
94      if ( pm_reg[0x23] & pm_reg[0x27] & 0x02 )
95         irq_set[prio] = 0x09;
96   }
97
98   /* Check IRQ $0B-$0E */
99   prio = ( pm_reg[0x21] >> 6 ) & 0x03;
100   if ( ! irq_set[prio] )
101   {
102      if ( pm_reg[0x24] & pm_reg[0x28] & 0x04 )
103         irq_set[prio] = 0x0E;
104
105      if ( pm_reg[0x24] & pm_reg[0x28] & 0x08 )
106         irq_set[prio] = 0x0D;
107
108      if ( pm_reg[0x24] & pm_reg[0x28] & 0x10 )
109         irq_set[prio] = 0x0C;
110
111      if ( pm_reg[0x24] & pm_reg[0x28] & 0x20 )
112         irq_set[prio] = 0x0B;
113   }
114
115   /* Check IRQ $0F-$10 */
116   prio = ( pm_reg[0x22] >> 0 ) & 0x03;
117   if ( ! irq_set[prio] )
118   {
119      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x40 )
120         irq_set[prio] = 0x10;
121
122      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x80 )
123         irq_set[prio] = 0x0F;
124   }
125
126   /* Check IRQ $13-$14 */
127   prio = ( pm_reg[0x21] >> 4 ) & 0x03;
128   if ( ! irq_set[prio] )
129   {
130      if ( pm_reg[0x24] & pm_reg[0x28] & 0x01 )
131         irq_set[prio] = 0x14;
132
133      if ( pm_reg[0x24] & pm_reg[0x28] & 0x02 )
134         irq_set[prio] = 0x13;
135   }
136
137   /* Check IRQ $15-$1C */
138   prio = ( pm_reg[0x21] >> 2 ) & 0x03;
139   if ( ! irq_set[prio] )
140   {
141      if ( pm_reg[0x25] & pm_reg[0x29] & 0x01 )
142         irq_set[prio] = 0x1C;
143
144      if ( pm_reg[0x25] & pm_reg[0x29] & 0x02 )
145         irq_set[prio] = 0x1B;
146
147      if ( pm_reg[0x25] & pm_reg[0x29] & 0x04 )
148         irq_set[prio] = 0x1A;
149
150      if ( pm_reg[0x25] & pm_reg[0x29] & 0x08 )
151         irq_set[prio] = 0x19;
152
153      if ( pm_reg[0x25] & pm_reg[0x29] & 0x10 )
154         irq_set[prio] = 0x18;
155
156      if ( pm_reg[0x25] & pm_reg[0x29] & 0x20 )
157         irq_set[prio] = 0x17;
158
159      if ( pm_reg[0x25] & pm_reg[0x29] & 0x40 )
160         irq_set[prio] = 0x16;
161
162      if ( pm_reg[0x25] & pm_reg[0x29] & 0x80 )
163         irq_set[prio] = 0x15;
164   }
165
166   /* Check IRQ $1D-$1F */
167   prio = ( pm_reg[0x21] >> 0 ) & 0x03;
168   if ( ! irq_set[prio] && ( pm_reg[0x26] & pm_reg[0x2A] & 0x07 ) )
169   {
170      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x01 )
171         irq_set[prio] = 0x1F;
172
173      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x02 )
174         irq_set[prio] = 0x1E;
175
176      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x04 )
177         irq_set[prio] = 0x1D;
178   }
179
180   /* Determine vector */
181   vector = 0;
182   if ( irq_set[1] )
183      vector = irq_set[1];
184   if ( irq_set[2] )
185      vector = irq_set[2];
186   if ( irq_set[3] )
187      vector = irq_set[3];
188
189   if ( vector )
190   {
191      logerror("Triggering IRQ with vector %02x\n", vector );
192      /* Trigger interrupt and set vector */
193      cpunum_set_input_line_and_vector( machine, 0, 0, ASSERT_LINE, vector );
194   }
195   else
196   {
197      cpunum_set_input_line( machine, 0, 0, CLEAR_LINE );
198   }
199}
200
201
38202static TIMER_CALLBACK(pokemini_seconds_timer_callback)
39203{
40   if ( timers.seconds_running ) {
41      timers.seconds_counter += 1;
204   if ( pm_reg[0x08] & 0x01 )
205   {
206      pm_reg[0x09] += 1;
207      if ( ! pm_reg[0x09] )
208      {
209         pm_reg[0x0A] += 1;
210         if ( ! pm_reg[0x0A] )
211         {
212            pm_reg[0x0B] += 1;
213         }
214      }
42215   }
43216}
44217
218
45219static TIMER_CALLBACK(pokemini_256hz_timer_callback)
46220{
47   if ( timers.hz256_running ) {
48      timers.hz256_counter += 1;
221   if ( pm_reg[0x40] & 0x01 )
222   {
223      pm_reg[0x41] += 1;
224      /* Check if the 32Hz IRQ should be triggered */
225      if ( ! ( pm_reg[0x41] & 0x07 ) )
226      {
227         pm_reg[0x28] |= 0x20;
228
229         /* Check if the 8Hz IRQ should be triggered */
230         if ( ! ( pm_reg[0x41] & 0x1F ) )
231         {
232            pm_reg[0x28] |= 0x10;
233
234            /* Check if the 2Hz IRQ should be triggered */
235            if ( ! ( pm_reg[0x41] & 0x7F ) )
236            {
237               pm_reg[0x28] |= 0x08;
238
239               /* Check if the 1Hz IRQ should be triggered */
240               if ( ! pm_reg[0x41] )
241               {
242                  pm_reg[0x28] |= 0x04;
243               }
244            }
245         }
246
247         pokemini_check_irqs( machine );
248      }
49249   }
50250}
51251
252
52253static TIMER_CALLBACK(pokemini_timer1_callback)
53254{
54   timers.timer1_counter -= 1;
255   pm_reg[0x36] -= 1;
55256   /* Check for underflow of timer */
56   if ( timers.timer1_counter == 0xFFFF ) {
57      /* TODO: Check for interrupt condition/generation */
58      timers.timer1_counter = ( pokemini_hwreg[0x33] << 8 ) | pokemini_hwreg[0x32];
257   if ( pm_reg[0x36] == 0xFF )
258   {
259      /* Check if timer1 is running in 16bit mode */
260      if ( pm_reg[0x30] & 0x80 )
261      {
262         pm_reg[0x37] -= 1;
263         if ( pm_reg[0x37] == 0xFF )
264         {
265            pm_reg[0x27] |= 0x08;
266            pokemini_check_irqs( machine );
267            pm_reg[0x36] = pm_reg[0x32];
268            pm_reg[0x37] = pm_reg[0x33];
269         }
270      }
271      else
272      {
273         pm_reg[0x27] |= 0x04;
274         pokemini_check_irqs( machine );
275         pm_reg[0x36] = pm_reg[0x32];
276      }
59277   }
60   pokemini_hwreg[0x37] = timers.timer1_counter >> 8;
61   if ( pokemini_hwreg[0x30] & 0x80 ) {
62      pokemini_hwreg[0x36] = timers.timer1_counter & 0xFF;
278}
279
280
281static TIMER_CALLBACK(pokemini_timer1_hi_callback)
282{
283   pm_reg[0x37] -= 1;
284   /* Check for underflow of timer */
285   if ( pm_reg[0x37] == 0xFF )
286   {
287      pm_reg[0x27] |= 0x08;
288      pokemini_check_irqs( machine );
289      pm_reg[0x37] = pm_reg[0x33];
63290   }
64291}
65292
293
66294static TIMER_CALLBACK(pokemini_timer2_callback)
67295{
68   timers.timer2_counter -= 1;
296   pm_reg[0x3E] -= 1;
69297   /* Check for underflow of timer */
70   if ( timers.timer2_counter == 0xFFFF ) {
71      /* TODO: Check for interrupt condition/generation */
72      timers.timer2_counter = ( pokemini_hwreg[0x3b] << 8 ) | pokemini_hwreg[0x3a];
298   if ( pm_reg[0x3E] == 0xFF )
299   {
300      /* Check if timer2 is running in 16bit mode */
301      if ( pm_reg[0x38] & 0x80 )
302      {
303         pm_reg[0x3F] -= 1;
304         if ( pm_reg[0x3F] == 0xFF )
305         {
306            pm_reg[0x27] |= 0x20;
307            pokemini_check_irqs( machine );
308            pm_reg[0x3E] = pm_reg[0x3A];
309            pm_reg[0x3F] = pm_reg[0x3B];
310         }
311      }
312      else
313      {
314         pm_reg[0x27] |= 0x10;
315         pokemini_check_irqs( machine );
316         pm_reg[0x3E] = pm_reg[0x3A];
317      }
73318   }
74   pokemini_hwreg[0x3f] = timers.timer2_counter >> 8;
75   if ( pokemini_hwreg[0x38] & 0x80 ) {
76      pokemini_hwreg[0x3e] = timers.timer2_counter & 0xFF;
319}
320
321
322static TIMER_CALLBACK(pokemini_timer2_hi_callback)
323{
324   pm_reg[0x3F] -= 1;
325   /* Check for underfow of timer */
326   if ( pm_reg[0x3F] == 0xFF )
327   {
328      pm_reg[0x27] |= 0x20;
329      pokemini_check_irqs( machine );
330      pm_reg[0x3F] = pm_reg[0x3B];
77331   }
78332}
79333
334
80335static TIMER_CALLBACK(pokemini_timer3_callback)
81336{
82   timers.timer3_counter -= 1;
337   pm_reg[0x4E] -= 1;
83338   /* Check for underflow of timer */
84   if ( timers.timer3_counter == 0xFFFF ) {
85      /* TODO: Check for interrupt condition/generation */
86      timers.timer3_counter = ( pokemini_hwreg[0x4b] << 8 ) | pokemini_hwreg[0x4a];
339   if ( pm_reg[0x4E] == 0xFF )
340   {
341      /* Check if timer3 is running in 16bit mode */
342      if ( pm_reg[0x48] & 0x80 )
343      {
344         pm_reg[0x4F] -= 1;
345         if ( pm_reg[0x4F] == 0xFF )
346         {
347            pm_reg[0x27] |= 0x02;
348            pokemini_check_irqs( machine );
349            pm_reg[0x4E] = pm_reg[0x4A];
350            pm_reg[0x4F] = pm_reg[0x4B];
351         }
352      }
353      else
354      {
355         pm_reg[0x4E] = pm_reg[0x4A];
356      }
87357   }
88   pokemini_hwreg[0x4f] = timers.timer3_counter >> 8;
89   if ( pokemini_hwreg[0x4e] & 0x80 ) {
90      pokemini_hwreg[0x4e] = timers.timer3_counter & 0xFF;
91   }
92358}
93359
94MACHINE_RESET( pokemini ) {
95   memset( &vdp, 0, sizeof(vdp) );
96   memset( &timers, 0, sizeof(timers) );
97   memset( pokemini_hwreg, 0, sizeof(pokemini_hwreg) );
98   timers.seconds_timer = timer_alloc( pokemini_seconds_timer_callback , NULL);
99   timers.hz256_timer = timer_alloc( pokemini_256hz_timer_callback , NULL);
100   timers.timer1_timer = timer_alloc( pokemini_timer1_callback , NULL);
101   timers.timer2_timer = timer_alloc( pokemini_timer2_callback , NULL);
102   timers.timer3_timer = timer_alloc( pokemini_timer3_callback , NULL);
360
361static TIMER_CALLBACK(pokemini_timer3_hi_callback)
362{
363   pm_reg[0x4F] -= 1;
364   /* Check for underflow of timer */
365   if ( pm_reg[0x4F] == 0xFF )
366   {
367      pm_reg[0x27] |= 0x02;
368      pokemini_check_irqs( machine );
369      pm_reg[0x4F] = pm_reg[0x4B];
370   }
103371}
104372
105WRITE8_HANDLER( pokemini_hwreg_w ) {
106   static const int timer_to_cycles[8] = { 2, 8, 32, 64, 128, 256, 1024, 4096 };
373
374WRITE8_HANDLER( pokemini_hwreg_w )
375{
376   static const int timer_to_cycles_fast[8] = { 2, 8, 32, 64, 128, 256, 1024, 4096 };
377   static const int timer_to_cycles_slow[8] = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384 };
378
107379   logerror( "%0X: Write to hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
108   switch( offset ) {
380
381   switch( offset )
382   {
109383   case 0x00:   /* start-up contrast
110384            Bit 0-1 R/W Must be 1(?)
r2798r2799
124398            Bit 1   W   Timer reset
125399            Bit 2-7     Unused
126400         */
127      if ( data & 0x01 ) {   /* enable timer */
128         if ( ! timers.seconds_running ) {
129            timer_adjust_oneshot(timers.seconds_timer, ATTOTIME_IN_SEC(1), 0);
130            timers.seconds_running = 1;
131         }
132      } else {      /* pause timer */
133         if ( timers.seconds_running ) {
134            timer_reset( timers.seconds_timer, attotime_never );
135            timers.seconds_running = 0;
136         }
137      }
138      if ( data & 0x02 ) {
139         timers.seconds_counter = 0;
401      if ( data & 0x02 )
402      {
403         pm_reg[0x09] = 0x00;
404         pm_reg[0x0A] = 0x00;
405         pm_reg[0x0B] = 0x00;
140406         data &= ~0x02;
141407      }
142408      break;
143   case 0x09:   /* Seconds-timer (low)
409   case 0x09:   /* Seconds-timer (low), read only
144410            Bit 0-7 R   Seconds timer bit 0-7
145411         */
146   case 0x0A:   /* Seconds-timer (mid)
412      return;
413   case 0x0A:   /* Seconds-timer (mid), read only
147414            Bit 0-7 R   Seconds timer bit 8-15
148415         */
149   case 0x0B:   /* Seconds-timer (high)
416      return;
417   case 0x0B:   /* Seconds-timer (high), read only
150418            Bit 0-7 R   Seconds timer bit 16-23
151419         */
152      /* ignore writes to these registers */
153      logerror( "%0X: Invalid write to seconds counter\n", activecpu_get_pc() );
154420      return;
155421   case 0x10:   /* Low power detector
156422            Bit 0-4 R/W Unknown
r2798r2799
160426      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
161427      break;
162428   case 0x18:   /* Timer 1 pre-scale + enable
163            Bit 0-2 R/W 000 - 2000000 Hz - 2 cycles
164                        001 -  500000 Hz - 8 cycles
165                        010 -  125000 Hz - 32 cycles
166                        011 -   62500 Hz - 64 cycles
167                        100 -   31250 Hz - 128 cycles
168                        101 -   15625 Hz - 256 cycles
169                        110 -    3906.25 Hz - 1024 cycles
170                        111 -     976.5625 Hz - 4096 cycles
171            Bit 3   R/W Enable counting
172            Bit 4-7 R/W Unused
429            Bit 0-2 R/W low timer 1 prescaler select
430                        000 - 2 or 128 cycles
431                        001 - 8 or 256 cycles
432                        010 - 32 or 512 cycles
433                        011 - 64 or 1024 cycles
434                        100 - 128 or 2048 cycles
435                        101 - 256 or 4096 cycles
436                        110 - 1024 or 8192 cycles
437                        111 - 4096 or 16384 cycles
438            Bit 3   R/W Enable low counting
439            Bit 4-6 R/W high timer 1 prescaler select
440            Bit 7   R/W Enable high counting
173441         */
174      if ( ( data & 0x07 ) != ( pokemini_hwreg[0x18] & 0x07 ) ) {
175         timer_adjust_periodic(timers.timer1_timer, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ), 0, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ));
442      /* Check for prescaler change for the low counter */
443      if ( ( data & 0x07 ) != ( pm_reg[0x18] & 0x07 ) )
444      {
445         int index = data & 0x07;
446         int cycles = ( pm_reg[0x19] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
447
448         timer_adjust_periodic(timers.timer1, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
176449      }
177      if ( ( data & 0x08 ) && timers.timers_enabled ) {
178         timer_enable( timers.timer1_timer, 1 );
179      } else {
180         timer_enable( timers.timer1_timer, 0 );
450
451      /* Check for prescaler change for the high counter */
452      if ( ( data & 0x70 ) != ( pm_reg[0x18] & 0x70 ) )
453      {
454         int index = ( data >> 4 ) & 0x07;
455         int cycles = ( pm_reg[0x19] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
456
457         timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
181458      }
459
460      /* Check if timer1 low should be enabled */
461      if ( ( data & 0x08 ) && ( pm_reg[0x30] & 0x04 ) &&
462           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) ||
463             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) ) )
464      {
465         timer_enable( timers.timer1, 1 );
466      }
467      else
468      {
469         timer_enable( timers.timer1, 0 );
470      }
471
472      /* Check if timer1 high should be enabled */
473      if ( ( data & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) &&
474           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ||
475             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ) )
476      {
477         timer_enable( timers.timer1_hi, 1 );
478      }
479      else
480      {
481         timer_enable( timers.timer1_hi, 0 );
482      }
182483      break;
183   case 0x19:   /* Timers 1 to 3 enabler
184            Bit 0   R/W SET IT TO "0"
185            Bit 1-3     Unused
186            Bit 4   R/W SET IT TO "0"
187            Bit 5   R/W Enable timers 1 to 3 circuits
484   case 0x19:   /* Timers 1 speed
485            Bit 0   R/W Select slow timer for timer 1 lo
486            Bit 1   R/W Select slow timer for timer 1 hi
487            Bit 2-3     Unused
488            Bit 4   R/W Enable slow timers
489            Bit 5   R/W Enable fast timers
188490            Bit 6-7     Unused
189491         */
190      timers.timers_enabled = ( data & 0x20 ) ? 1 : 0;
191      if ( timers.timers_enabled ) {
192         if ( pokemini_hwreg[0x18] & 0x08 ) {
193            timer_enable( timers.timer1_timer, 1 );
492      /* Check for prescaler change for the high counter */
493      if ( ( data & 0x01 ) != ( pm_reg[0x19] & 0x01 ) )
494      {
495         int index = pm_reg[0x18] & 0x07;
496         int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
497
498         timer_adjust_periodic(timers.timer1, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
499      }
500
501      /* Check for prescaler change for the low counter */
502      if ( ( data & 0x02 ) != ( pm_reg[0x19] & 0x02 ) )
503      {
504         int index = ( pm_reg[0x18] >> 4 ) & 0x07;
505         int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
506
507         timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
508      }
509
510      {
511         int timer1_enable = 0, timer1_hi_enable = 0;
512         int timer2_enable = 0, timer2_hi_enable = 0;
513         int timer3_enable = 0, timer3_hi_enable = 0;
514
515         /* Check which fast timers should be enabled */
516         if ( data & 0x20 )
517         {
518            if ( ( pm_reg[0x18] & 0x08 ) && ( pm_reg[0x30] & 0x04 ) && ! ( data & 0x01 ) )
519               timer1_enable = 1;
520
521            if ( ( pm_reg[0x18] & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ! ( data & 0x02 ) )
522               timer1_hi_enable = 1;
523
524            if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && ! ( pm_reg[0x1B] & 0x01 ) )
525               timer2_enable = 1;
526
527            if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ! ( pm_reg[0x1B] & 0x02 ) )
528               timer2_hi_enable = 1;
529
530            if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && ! ( pm_reg[0x1D] & 0x01 ) )
531               timer3_enable = 1;
532
533            if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ! ( pm_reg[0x1D] & 0x02 ) )
534               timer3_hi_enable = 1;
194535         }
195         if ( pokemini_hwreg[0x1A] & 0x08 ) {
196            timer_enable( timers.timer2_timer, 1 );
536
537         /* Check which slow timers should be enabled */
538         if ( data & 0x10 )
539         {
540            if ( ( pm_reg[0x18] & 0x08 ) && ( data & 0x01 ) )
541               timer1_enable = 1;
542
543            if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x1B] & 0x01 ) )
544               timer2_enable = 1;
545
546            if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x1D] & 0x01 ) )
547               timer3_enable = 1;
197548         }
198         if ( pokemini_hwreg[0x1C] & 0x08 ) {
199            timer_enable( timers.timer3_timer, 1 );
200         }
201      } else {
202         timer_enable( timers.timer1_timer, 0 );
203         timer_enable( timers.timer2_timer, 0 );
204         timer_enable( timers.timer3_timer, 0 );
549         timer_enable( timers.timer1, timer1_enable );
550         timer_enable( timers.timer1_hi, timer1_hi_enable );
551         timer_enable( timers.timer2, timer2_enable );
552         timer_enable( timers.timer2_hi, timer2_hi_enable );
553         timer_enable( timers.timer3, timer3_enable );
554         timer_enable( timers.timer3_hi, timer3_hi_enable );
205555      }
206556      break;
207557   case 0x1A:   /* Timer 2 pre-scale + enable
208            Bit 0-2 R/W 000 - 2000000 Hz - 2 cycles
209                        001 -  500000 Hz - 8 cycles
210                        010 -  125000 Hz - 32 cycles
211                        011 -   62500 Hz - 64 cycles
212                        100 -   31250 Hz - 128 cycles
213                        101 -   15625 Hz - 256 cycles
214                        110 -    3906.25 Hz - 1024 cycles
215                        111 -     976.5625 Hz - 4096 cycles
216            Bit 3   R/W Enable counting
217            Bit 4-7     Unused
558            Bit 0-2 R/W low timer 2 prescaler select
559                        000 - 2 or 128 cycles
560                        001 - 8 or 256 cycles
561                        010 - 32 or 512 cycles
562                        011 - 64 or 1024 cycles
563                        100 - 128 or 2048 cycles
564                        101 - 256 or 4096 cycles
565                        110 - 1024 or 8192 cycles
566                        111 - 4096 or 16384 cycles
567            Bit 3   R/W Enable low counting
568            Bit 4-6 R/W high timer 2 prescaler select
569            Bit 7   R/W Enable high counting
218570         */
219      if ( ( data & 0x07 ) != ( pokemini_hwreg[0x1A] & 0x07 ) ) {
220         timer_adjust_periodic(timers.timer2_timer, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ), 0, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ));
571      /* Check for prescaler change for the low counter */
572      if ( ( data & 0x07 ) != ( pm_reg[0x1A] & 0x07 ) )
573      {
574         int index = data & 0x07;
575         int cycles = ( pm_reg[0x1B] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
576
577         timer_adjust_periodic(timers.timer2, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
221578      }
222      if ( ( data & 0x08 ) && timers.timers_enabled ) {
223         timer_enable( timers.timer2_timer, 1 );
224      } else {
225         timer_enable( timers.timer2_timer, 0 );
579
580      /* Check for prescaler change for the high counter */
581      if ( ( data & 0x70 ) != ( pm_reg[0x1A] & 0x70 ) )
582      {
583         int index = ( data >> 4 ) & 0x07;
584         int cycles = ( pm_reg[0x1B] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
585
586         timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
226587      }
588
589      /* Check if timer2 low should be enabled */
590      if ( ( data & 0x08 ) && ( pm_reg[0x38] & 0x04 ) &&
591           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x01 ) ) ||
592             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x01 ) ) ) )
593      {
594         timer_enable( timers.timer2, 1 );
595      }
596      else
597      {
598         timer_enable( timers.timer2, 0 );
599      }
600
601      /* Check if timer2 high should be enabled */
602      if ( ( data & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) &&
603           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ||
604             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ) )
605      {
606         timer_enable( timers.timer2_hi, 1 );
607      }
608      else
609      {
610         timer_enable( timers.timer2_hi, 0 );
611      }
227612      break;
613   case 0x1B:   /* Timer 2 speeds
614            Bit 0   R/W Select slow timer for timer 2 lo
615            Bit 1   R/W Select slow timer for timer 2 hi
616         */
617      /* Check for prescaler change for the high counter */
618      if ( ( data & 0x01 ) != ( pm_reg[0x1B] & 0x01 ) )
619      {
620         int index = pm_reg[0x1A] & 0x07;
621         int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
622
623         timer_adjust_periodic(timers.timer2, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
624
625         if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) &&
626              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) ||
627                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) )
628         {
629            timer_enable( timers.timer2, 1 );
630         }
631         else
632         {
633            timer_enable( timers.timer2, 0 );
634         }
635      }
636
637      /* Check for prescaler change for the low counter */
638      if ( ( data & 0x02 ) != ( pm_reg[0x1B] & 0x02 ) )
639      {
640         int index = ( pm_reg[0x1A] >> 4 ) & 0x07;
641         int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
642
643         timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
644
645         if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) &&
646              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) ||
647                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) )
648         {
649            timer_enable( timers.timer2_hi, 1 );
650         }
651         else
652         {
653            timer_enable( timers.timer2_hi, 0 );
654         }
655      }
656      break;
228657   case 0x1C:   /* Timer 3 pre-scale + enable
229            Bit 0-2 R/W 000 - 2000000 Hz - 2 cycles
230                        001 -  500000 Hz - 8 cycles
231                        010 -  125000 Hz - 32 cycles
232                        011 -   62500 Hz - 64 cycles
233                        100 -   31250 Hz - 128 cycles
234                        101 -   15625 Hz - 256 cycles
235                        110 -    3906.25 Hz - 1024 cycles
236                        111 -     976.5625 Hz - 4096 cycles
237            Bit 3   R/W Enable counting
238            Bit 4-7     Unused
658            Bit 0-2 R/W low timer 3 prescaler select
659                        000 - 2 or 128 cycles
660                        001 - 8 or 256 cycles
661                        010 - 32 or 512 cycles
662                        011 - 64 or 1024 cycles
663                        100 - 128 or 2048 cycles
664                        101 - 256 or 4096 cycles
665                        110 - 1024 or 8192 cycles
666                        111 - 4096 or 16384 cycles
667            Bit 3   R/W Enable low counting
668            Bit 4-6 R/W high timer 3 prescaler select
669            Bit 7   R/W Enable high counting
239670         */
240      if ( ( data & 0x07 ) != ( pokemini_hwreg[0x1C] & 0x07 ) ) {
241         timer_adjust_periodic(timers.timer3_timer, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ), 0, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ));
671      /* Check for prescaler change for the low counter */
672      if ( ( data & 0x07 ) != ( pm_reg[0x1C] & 0x07 ) )
673      {
674         int index = data & 0x07;
675         int cycles = ( pm_reg[0x1D] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
676
677         timer_adjust_periodic(timers.timer3, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
242678      }
243      if ( ( data & 0x08 ) && timers.timers_enabled ) {
244         timer_enable( timers.timer3_timer, 1 );
245      } else {
246         timer_enable( timers.timer3_timer, 0 );
679
680      /* Check for prescaler change for the high counter */
681      if ( ( data & 0x70 ) != ( pm_reg[0x1C] & 0x70 ) )
682      {
683         int index = ( data >> 4 ) & 0x07;
684         int cycles = ( pm_reg[0x1D] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
685
686         timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
247687      }
688
689      /* Check if timer2 low should be enabled */
690      if ( ( data & 0x08 ) && ( pm_reg[0x48] & 0x04 ) &&
691           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) ||
692             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) ) )
693      {
694         timer_enable( timers.timer3, 1 );
695      }
696      else
697      {
698         timer_enable( timers.timer3, 0 );
699      }
700
701      /* Check if timer2 high should be enabled */
702      if ( ( data & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) &&
703           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ||
704             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ) )
705      {
706         timer_enable( timers.timer3_hi, 1 );
707      }
708      else
709      {
710         timer_enable( timers.timer3_hi, 0 );
711      }
248712      break;
249   case 0x20:   /* Event #1-#8 primary enable
713   case 0x1D:   /* Timer 3 speeds
714            Bit 0   R/W Select slow timer for timer 3 lo
715            Bit 1   R/W Select slow timer for timer 3 hi
716         */
717      /* Check for prescaler change for the high counter */
718      if ( ( data & 0x01 ) != ( pm_reg[0x1D] & 0x01 ) )
719      {
720         int index = pm_reg[0x1C] & 0x07;
721         int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
722
723         timer_adjust_periodic(timers.timer3, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
724
725         if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) &&
726              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) ||
727                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) )
728         {
729            timer_enable( timers.timer3, 1 );
730         }
731         else
732         {
733            timer_enable( timers.timer3, 0 );
734         }
735      }
736
737      /* Check for prescaler change for the low counter */
738      if ( ( data & 0x02 ) != ( pm_reg[0x1D] & 0x02 ) )
739      {
740         int index = ( pm_reg[0x1C] >> 4 ) & 0x07;
741         int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
742
743         timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 ));
744
745         if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) &&
746              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) ||
747                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) )
748         {
749            timer_enable( timers.timer3_hi, 1 );
750         }
751         else
752         {
753            timer_enable( timers.timer3_hi, 0 );
754         }
755      }
756      break;
757   case 0x20:   /* Event #1-#8 priority
250758            Bit 0-1 R/W Timer 3 overflow Interrupt #7-#8
251759            Bit 2-3 R/W Timer 1 overflow Interrupt #5-#6
252760            Bit 4-5 R/W Timer 2 overflow Interrupt #3-#4
253761            Bit 6-7 R/W VDraw/VBlank trigger Interrupt #1-#2
254762         */
763      pm_reg[0x20] = data;
764      pokemini_check_irqs( machine );
255765      break;
256   case 0x21:   /* Event #15-#22 primary enable
766   case 0x21:   /* Event #15-#22 priority
257767            Bit 0-1 R/W Unknown
258768            Bit 2-3 R/W All keypad interrupts - Interrupt #15-#22
259769            Bit 4-7 R/W Unknown
260770         */
771      pm_reg[0x21] = data;
772      pokemini_check_irqs( machine );
261773      break;
262   case 0x22:   /* Event #9-#14 primary enable
774   case 0x22:   /* Event #9-#14 priority
263775            Bit 0-1 R/W All #9 - #14 events - Interrupt #9-#14
264776            Bit 2-7     Unused
265777         */
778      pm_reg[0x22] = data;
779      pokemini_check_irqs( machine );
266780      break;
267   case 0x23:   /* Event #1-#8 secondary enable
781   case 0x23:   /* Event #1-#8 enable
268782            Bit 0   R/W Timer 3 overflow (mirror) - Enable Interrupt #8
269783            Bit 1   R/W Timer 3 overflow - Enable Interrupt #7
270784            Bit 2   R/W Not called... - Enable Interrupt #6
r2798r2799
274788            Bit 6   R/W V-Draw trigger - Enable Interrupt #2
275789            Bit 7   R/W V-Blank trigger - Enable Interrupt #1
276790         */
791      pm_reg[0x23] = data;
792      pokemini_check_irqs( machine );
277793      break;
278   case 0x24:   /* Event #9-#12 secondary enable
794   case 0x24:   /* Event #9-#12 enable
279795            Bit 0-5 R/W Unknown
280796            Bit 6-7     Unused
281797         */
798      pm_reg[0x24] = data;
799      pokemini_check_irqs( machine );
282800      break;
283   case 0x25:   /* Event #15-#22 secondary enable
801   case 0x25:   /* Event #15-#22 enable
284802            Bit 0   R/W Press key "A" event - Enable interrupt #22
285803            Bit 1   R/W Press key "B" event - Enable interrupt #21
286804            Bit 2   R/W Press key "C" event - Enable interrupt #20
r2798r2799
290808            Bit 6   R/W Press D-pad right key event - Enable interrupt #16
291809            Bit 7   R/W Press power button event - Enable interrupt #15
292810         */
811      pm_reg[0x25] = data;
812      pokemini_check_irqs( machine );
293813      break;
294   case 0x26:   /* Event #13-#14 secondary enable
814   case 0x26:   /* Event #13-#14 enable
295815            Bit 0-2 R/W Unknown
296816            Bit 3       Unused
297817            Bit 4-5 R/W Unknown
298818            Bit 6   R/W Shock detector trigger - Enable interrupt #14
299819            Bit 7   R/W IR receiver - low to high trigger - Enable interrupt #13
300820         */
821      pm_reg[0x26] = data;
822      pokemini_check_irqs( machine );
301823      break;
302   case 0x27:   /* Interrupt flag #1-#8
824   case 0x27:   /* Interrupt active flag #1-#8
303825            Bit 0       Timer 3 overflow (mirror) / Clear interrupt #8
304826            Bit 1       Timer 3 overflow / Clear interrupt #7
305827            Bit 2       Not called ... / Clear interrupt #6
r2798r2799
309831            Bit 6       VDraw trigger / Clear interrupt #2
310832            Bit 7       VBlank trigger / Clear interrupt #1
311833         */
312   case 0x28:   /* Interrupt flag #9-#12
834      pm_reg[0x27] &= ~data;
835      pokemini_check_irqs( machine );
836      return;
837   case 0x28:   /* Interrupt active flag #9-#12
313838            Bit 0-1     Unknown
314839            Bit 2       Unknown / Clear interrupt #12
315840            Bit 3       Unknown / Clear interrupt #11
r2798r2799
317842            Bit 5       Unknown / Clear interrupt #9
318843            Bit 6-7     Unknown
319844         */
320   case 0x29:   /* Interrupt flag #15-#22
845      pm_reg[0x28] &= ~data;
846      pokemini_check_irqs( machine );
847      return;
848   case 0x29:   /* Interrupt active flag #15-#22
321849            Bit 0       Press key "A" event / Clear interrupt #22
322850            Bit 1       Press key "B" event / Clear interrupt #21
323851            Bit 2       Press key "C" event / Clear interrupt #20
r2798r2799
327855            Bit 6       Press D-pad right key event / Clear interrupt #16
328856            Bit 7       Press power button event / Clear interrupt #15
329857         */
330   case 0x2A:   /* Interrupt flag #13-#14
858      pm_reg[0x29] &= ~data;
859      pokemini_check_irqs( machine );
860      return;
861   case 0x2A:   /* Interrupt active flag #13-#14
331862            Bit 0-5     Unknown
332863            Bit 6       Shock detector trigger / Clear interrupt #14
333864            Bit 7       Unknown / Clear interrupt #13
334865         */
335      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
336      break;
866      pm_reg[0x2A] &= ~data;
867      pokemini_check_irqs( machine );
868      return;
337869   case 0x30:   /* Timer 1 control 1
338870            Bit 0   R/W Unknown
339            Bit 1       Unused
340            Bit 2   W   Preset timer
341            Bit 3-6     Unused
342            Bit 7   R/W Enable timer 1 counting (this seems to unlock/lock register 0x36)
871            Bit 1   W   Reset low counter
872            Bit 2   R/W Enable high counter
873            Bit 3   R/W Unknown
874            Bit 4-6     Unused
875            Bit 7   R/W Enable 16bit mode
343876         */
344      if ( data & 0x04 ) {
345         timers.timer1_counter = ( pokemini_hwreg[0x33] << 8 ) | pokemini_hwreg[0x32];
346         pokemini_hwreg[0x36] = pokemini_hwreg[0x32];
347         pokemini_hwreg[0x37] = pokemini_hwreg[0x33];
877      if ( data & 0x02 )
878      {
879         pm_reg[0x36] = pm_reg[0x32];
880         data &= ~0x02;
348881      }
349      data &= ~0x04;
882
883      if ( ( data & 0x04 ) && ( pm_reg[0x18] & 0x08 ) &&
884           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) ||
885             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) ) )
886      {
887         timer_enable( timers.timer1, 1 );
888      }
889      else
890      {
891         timer_enable( timers.timer1, 0 );
892      }
893
894      if ( ( pm_reg[0x31] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x18] & 0x80 ) &&
895           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ||
896             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) )
897      {
898         timer_enable( timers.timer1_hi, 1 );
899      }
900      else
901      {
902         timer_enable( timers.timer1_hi, 0 );
903      }
350904      break;
351905   case 0x31:   /* Timer 1 control 2
352            Bit 0-2     Unused
906            Bit 0   R/W Unknown
907            Bit 1   W   Reset hi counter
908            Bit 2   R/W Enable high counter
353909            Bit 3   R/W Unknown
354910            Bit 4-7     Unused
355911         */
912      if ( data & 0x02 )
913      {
914         pm_reg[0x37] = pm_reg[0x33];
915         data &= ~0x02;
916      }
917
918      if ( ( data & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ( pm_reg[0x18] & 0x80 ) &&
919           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ||
920             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) )
921      {
922         timer_enable( timers.timer1_hi, 1 );
923      }
924      else
925      {
926         timer_enable( timers.timer1_hi, 0 );
927      }
928      break;
356929   case 0x32:   /* Timer 1 preset value (low)
357930            Bit 0-7 R/W Timer 1 preset value bit 0-7
358931         */
932      break;
359933   case 0x33:   /* Timer 1 preset value (high)
360934            Bit 0-7 R/W Timer 1 preset value bit 8-15
361935         */
936      break;
362937   case 0x34:   /* Timer 1 sound-pivot (low, unused)
363938         */
364939   case 0x35:   /* Timer 1 sound-pivot (high, unused)
365940         */
366   case 0x36:   /* Timer 1 counter (low)
367            Bit 0-7 R/W Timer 1 counter value bit 0-7
941      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
942      break;
943   case 0x36:   /* Timer 1 counter (low), read only
368944         */
369   case 0x37:   /* Timer 1 counter (high)
370            Bit 0-7 R/W Timer 1 counter value bit 8-15
945      return;
946   case 0x37:   /* Timer 1 counter (high), read only
371947         */
372      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
373      break;
948      return;
374949   case 0x38:   /* Timer 2 control 1
375950            Bit 0   R/W Unknown
376            Bit 1       Unused
377            Bit 2   W   Preset Timer
378            Bit 3-6     Unused
379            Bit 7   R/W Enable timer 2 counting (this seems to unlock/lock register 0x3E)
951            Bit 1   W   Reset low counter
952            Bit 2   R/W Enable high counter
953            Bit 3   R/W Unknown
954            Bit 4-6     Unused
955            Bit 7   R/W Enable 16bit mode
380956         */
381      if ( data & 0x04 ) {
382         timers.timer2_counter = ( pokemini_hwreg[0x3b] << 8 ) | pokemini_hwreg[0x3a];
383         pokemini_hwreg[0x3e] = pokemini_hwreg[0x3a];
384         pokemini_hwreg[0x3f] = pokemini_hwreg[0x3b];
385         data &= ~0x04;
957      if ( data & 0x02 )
958      {
959         pm_reg[0x3E] = pm_reg[0x3A];
960         data &= ~0x02;
386961      }
962
963      if ( ( data & 0x04 ) && ( pm_reg[0x1A] & 0x08 ) &&
964           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1A] & 0x01 ) ) ||
965             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1A] & 0x01 ) ) ) )
966      {
967         timer_enable( timers.timer2, 1 );
968      }
969      else
970      {
971         timer_enable( timers.timer2, 0 );
972      }
973      if ( ( pm_reg[0x39] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) &&
974           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ||
975             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) )
976      {
977         timer_enable( timers.timer2_hi, 1 );
978      }
979      else
980      {
981         timer_enable( timers.timer2_hi, 0 );
982      }
387983      break;
388984   case 0x39:   /* Timer 2 control 2
389            Bit 0-2     Unused
985            Bit 0   R/W Unknown
986            Bit 1   W   Reset hi counter
987            Bit 2   R/W Enable high counter
390988            Bit 3   R/W Unknown
391989            Bit 4-7     Unused
392990         */
991      if ( data & 0x02 )
992      {
993         pm_reg[0x3F] = pm_reg[0x3A];
994         data &= ~0x02;
995      }
996
997      if ( ( data & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) &&
998           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ||
999             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) )
1000      {
1001         timer_enable( timers.timer2_hi, 1 );
1002      }
1003      else
1004      {
1005         timer_enable( timers.timer2_hi, 0 );
1006      }
1007      break;
3931008   case 0x3A:   /* Timer 2 preset value (low)
3941009            Bit 0-7 R/W Timer 2 preset value bit 0-7
3951010         */
1011      break;
3961012   case 0x3B:   /* Timer 2 preset value (high)
3971013            Bit 0-7 R/W Timer 2 preset value bit 8-15
3981014         */
1015      break;
3991016   case 0x3C:   /* Timer 2 sound-pivot (low, unused)
4001017         */
4011018   case 0x3D:   /* Timer 2 sound-pivot (high, unused)
4021019         */
403   case 0x3E:   /* Timer 2 counter (low)
1020      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
1021      break;
1022   case 0x3E:   /* Timer 2 counter (low), read only
4041023            Bit 0-7 R/W Timer 2 counter value bit 0-7
4051024         */
406   case 0x3F:   /* Timer 2 counter (high)
1025      return;
1026   case 0x3F:   /* Timer 2 counter (high), read only
4071027            Bit 0-7 R/W Timer 2 counter value bit 8-15
4081028         */
409      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
410      break;
1029      return;
4111030   case 0x40:   /* 256Hz timer control
4121031            Bit 0   R/W Enable Timer
4131032            Bit 1   W   Reset Timer
4141033            Bit 2-7     Unused
4151034         */
416      if ( data & 0x01 ) {   /* enable timer */
417         if ( ! timers.hz256_running ) {
418            timer_adjust_oneshot(timers.hz256_timer, ATTOTIME_IN_HZ(256), 0);
419            timers.hz256_running = 1;
420         }
421      } else {      /* pause timer */
422         if ( timers.hz256_running ) {
423            timer_reset( timers.hz256_timer, attotime_never );
424            timers.hz256_running = 0;
425         }
426      }
427      if ( data & 0x02 ) {
428         timers.hz256_counter = 0;
1035      if ( data & 0x02 )
1036      {
1037         pm_reg[0x41] = 0;
4291038         data &= ~0x02;
4301039      }
4311040      break;
r2798r2799
4351044      return;
4361045   case 0x48:   /* Timer 3 control 1
4371046            Bit 0   R/W Unknown
438            Bit 1       Unused
439            Bit 2   W   Preset timer
440            Bit 3-6     Unused
441            Bit 7   R/W Enable timer 3 counting (this seems to unlock/lock register 0x4E)
1047            Bit 1   W   Reset low counter
1048            Bit 2   R/W Enable high counter
1049            Bit 3   R/W Unknown
1050            Bit 4-6     Unused
1051            Bit 7   R/W Enable 16bit mode
4421052         */
443      if ( data & 0x04 ) {
444         timers.timer3_counter = ( pokemini_hwreg[0x4f] << 8 ) | pokemini_hwreg[0x4e];
445         pokemini_hwreg[0x4a] = pokemini_hwreg[0x4e];
446         pokemini_hwreg[0x4b] = pokemini_hwreg[0x4f];
447         data &= ~0x04;
1053      if ( data & 0x02 )
1054      {
1055         pm_reg[0x4E] = pm_reg[0x4A];
1056         data &= ~0x02;
4481057      }
1058
1059      if ( ( data & 0x04 ) && ( pm_reg[0x1C] & 0x08 ) &&
1060           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) ||
1061             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) ) )
1062      {
1063         timer_enable( timers.timer3, 1 );
1064      }
1065      else
1066      {
1067         timer_enable( timers.timer3, 0 );
1068      }
1069      if ( ( pm_reg[0x49] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) &&
1070           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ||
1071             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) )
1072      {
1073         timer_enable( timers.timer3_hi, 1 );
1074      }
1075      else
1076      {
1077         timer_enable( timers.timer3_hi, 0 );
1078      }
4491079      break;
4501080   case 0x49:   /* Timer 3 control 2
451            Bit 0-2     Unused
1081            Bit 0   R/W Unknown
1082            Bit 1   W   Reset hi counter
1083            Bit 2   R/W Enable high counter
4521084            Bit 3   R/W Unknown
4531085            Bit 4-7     Unused
4541086         */
1087      if ( data & 0x02 )
1088      {
1089         pm_reg[0x4F] = pm_reg[0x4B];
1090         data &= ~0x02;
1091      }
1092
1093      if ( ( data & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) &&
1094           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ||
1095             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) )
1096      {
1097         timer_enable( timers.timer3_hi, 1 );
1098      }
1099      else
1100      {
1101         timer_enable( timers.timer3_hi, 0 );
1102      }
1103      break;
4551104   case 0x4A:   /* Timer 3 preset value (low)
4561105            Bit 0-7 R/W Timer 3 preset value bit 0-7
4571106         */
1107      break;
4581108   case 0x4B:   /* Timer 3 preset value (high)
4591109            Bit 0-7 R/W Timer 3 preset value bit 8-15
4601110         */
1111      break;
4611112   case 0x4C:   /* Timer 3 sound-pivot (low)
4621113            Bit 0-7 R/W Timer 3 sound-pivot value bit 0-7
4631114         */
r2798r2799
4691120            Pulse-Width of 50% = Half of preset-value
4701121            Pulse-Width of 100% = Same as preset-value
4711122         */
472   case 0x4E:   /* Timer 3 counter (low)
1123      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
1124      break;
1125   case 0x4E:   /* Timer 3 counter (low), read only
4731126            Bit 0-7 R/W Timer 3 counter value bit 0-7
4741127         */
475   case 0x4F:   /* Timer 3 counter (high)
1128      return;
1129   case 0x4F:   /* Timer 3 counter (high), read only
4761130            Bit 0-7 R/W Timer 3 counter value bit 8-15
4771131         */
478      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
479      break;
1132      return;
4801133   case 0x52:   /* Keypad status
4811134            Bit 0   R   Key "A"
4821135            Bit 1   R   Key "B"
r2798r2799
5231176            Bit 0   R/W Invert colors; 0 - normal, 1 - inverted
5241177            Bit 1   R/W Enable rendering of background
5251178            Bit 2   R/W Enable rendering of sprites
526            Bit 3   R/W Global rendering enable
1179            Bit 3   R/W Enable copy to LCD ram
5271180            Bit 4-5 R/W Map size
5281181                        00 - 12x16
5291182                        01 - 16x12
r2798r2799
5311184                        11 - 24x8 (prohibited code)
5321185           Bit 6-7      Unused
5331186         */
534      vdp.colors_inverted = ( data & 0x01 ) ? 1 : 0;
535      vdp.background_enabled = ( data & 0x02 ) ? 1 : 0;
536      vdp.sprites_enabled = ( data & 0x04 ) ? 1 : 0;
537      vdp.rendering_enabled = ( data & 0x08 ) ? 1 : 0;
538      vdp.map_size = ( data >> 4 ) & 0x03;
539      switch( vdp.map_size ) {
1187      prc.colors_inverted = ( data & 0x01 ) ? 1 : 0;
1188      prc.background_enabled = ( data & 0x02 ) ? 1 : 0;
1189      prc.sprites_enabled = ( data & 0x04 ) ? 1 : 0;
1190      prc.copy_enabled = ( data & 0x08 ) ? 1 : 0;
1191      prc.map_size = ( data >> 4 ) & 0x03;
1192      switch( prc.map_size )
1193      {
5401194      case 0:
541         vdp.map_size_x = 12; break;
1195         prc.map_size_x = 12; break;
5421196      case 1:
543         vdp.map_size_x = 16; break;
1197         prc.map_size_x = 16; break;
5441198      case 2:
5451199      case 3:
546         vdp.map_size_x = 24; break;
1200         prc.map_size_x = 24; break;
5471201      }
5481202      break;
5491203   case 0x81:   /* LCD render refresh rate
r2798r2799
5521206                        000 - 60Hz / 3 = 20Hz (0 - 2)
5531207                        001 - 60Hz / 6 = 10Hz (0 - 5)
5541208                        010 - 60Hz / 9 = 6,6Hz (0 - 8)
555                        011 - 60Hz / 12 = 5Hz (0 - 8)
1209                        011 - 60Hz / 12 = 5Hz (0 - B)
5561210                        100 - 60Hz / 2 = 30Hz (0 - 1)
5571211                        101 - 60Hz / 4 = 15Hz (0 - 3)
5581212                        110 - 60Hz / 6 = 10Hz (0 - 5)
5591213                        111 - 60Hz / 8 = 7,5Hz (0 - 7)
5601214            Bit 4-7 R   Divider position, when overflow the LCD is updated
5611215         */
562      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
1216      switch ( data & 0x0E )
1217      {
1218      case 0x00:   prc.max_frame_count = 3; break;
1219      case 0x02:   prc.max_frame_count = 6; break;
1220      case 0x04:   prc.max_frame_count = 9; break;
1221      case 0x06:   prc.max_frame_count = 12; break;
1222      case 0x08:   prc.max_frame_count = 2; break;
1223      case 0x0A:   prc.max_frame_count = 4; break;
1224      case 0x0C:   prc.max_frame_count = 6; break;
1225      case 0x0E:   prc.max_frame_count = 8; break;
1226      }
5631227      break;
5641228   case 0x82:   /* BG tile data memory offset (low)
5651229            Bit 0-2     Always "0"
5661230            Bit 3-7 R/W BG tile data memory offset bit 3-7
5671231         */
5681232      data &= 0xF8;
569      vdp.bg_tiles = ( vdp.bg_tiles & 0xFFFF00 ) | data;
1233      prc.bg_tiles = ( prc.bg_tiles & 0xFFFF00 ) | data;
5701234      break;
5711235   case 0x83:   /* BG tile data memory offset (mid)
5721236            Bit 0-7 R/W BG tile data memory offset bit 8-15
5731237         */
574      vdp.bg_tiles = ( vdp.bg_tiles & 0xFF00FF ) | ( data << 8 );
1238      prc.bg_tiles = ( prc.bg_tiles & 0xFF00FF ) | ( data << 8 );
5751239      break;
5761240   case 0x84:   /* BG tile data memory offset (high)
5771241            Bit 0-4 R/W BG tile data memory offset bit 16-20
5781242            Bit 5-7     Unused
5791243         */
5801244      data &= 0x1F;
581      vdp.bg_tiles = ( vdp.bg_tiles & 0x00FFFF ) | ( data << 16 );
1245      prc.bg_tiles = ( prc.bg_tiles & 0x00FFFF ) | ( data << 16 );
5821246      break;
5831247   case 0x85:   /* BG vertical move
5841248            Bit 0-6 R/W Move the background up, move range:
r2798r2799
6011265            Bit 6-7 R/W Sprite tile data memory offset bit 6-7
6021266         */
6031267      data &= 0xC0;
604      vdp.spr_tiles = ( vdp.spr_tiles & 0xFFFF00 ) | data;
1268      prc.spr_tiles = ( prc.spr_tiles & 0xFFFF00 ) | data;
6051269      break;
6061270   case 0x88:   /* Sprite tile data memory offset (med)
6071271            Bit 0-7 R/W Sprite tile data memory offset bit 8-15
6081272         */
609      vdp.spr_tiles = ( vdp.spr_tiles & 0xFF00FF ) | ( data << 8 );
1273      prc.spr_tiles = ( prc.spr_tiles & 0xFF00FF ) | ( data << 8 );
6101274      break;
6111275   case 0x89:   /* Sprite tile data memory offset (high)
6121276            Bit 0-4 R/W Sprite tile data memory offset bit 16-20
6131277            Bit 5-7     Unused
6141278         */
6151279      data &= 0x1F;
616      vdp.spr_tiles = ( vdp.spr_tiles & 0x00FFFF ) | ( data << 16 );
1280      prc.spr_tiles = ( prc.spr_tiles & 0x00FFFF ) | ( data << 16 );
6171281      break;
6181282   case 0x8A:   /* LCD status
6191283            Bit 0   R   Unknown
6201284            Bit 1   R   Unknown
6211285            Bit 2   R   Unknown
6221286            Bit 3   R   Unknown
623            Bit 4   R   LCD during V-Sync
1287            Bit 4   R   LCD during V-Sync / Rendering circuitry active or not ( 1 = not active)
6241288            Bit 5   R   Unknown
6251289            Bit 6-7     Unused
6261290         */
6271291   case 0xFE:   /* Direct LCD control / data
6281292            Bit 0-7 R/W Direct LCD command or data
6291293         */
1294//      lcd_command_w( data );
1295      break;
6301296   case 0xFF:   /* Direct LCD data
6311297            Bit 0-7 R/W Direct LCD data
6321298         */
1299//      lcd_data_w( data );
1300      break;
6331301   default:
6341302      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data );
6351303      break;
6361304   }
637   pokemini_hwreg[offset] = data;
1305   pm_reg[offset] = data;
6381306}
6391307
640READ8_HANDLER( pokemini_hwreg_r ) {
641   switch( offset ) {
642   case 0x09:   return timers.seconds_counter & 0xFF;
643   case 0x0A:   return ( timers.seconds_counter >> 8 ) & 0xFF;
644   case 0x0B:   return ( timers.seconds_counter >> 16 ) & 0xFF;
645   case 0x41:   return timers.hz256_counter;
1308READ8_HANDLER( pokemini_hwreg_r )
1309{
1310   switch( offset )
1311   {
6461312   case 0x52:   return input_port_read(machine, "INPUTS");
1313   case 0x81:   return ( pm_reg[offset] & 0x0F ) | ( prc.frame_count << 4 );
1314   case 0x8A:   return prc.count;
6471315   }
648   logerror( "%0X: Read from unknown hardware address: %02X\n", activecpu_get_pc(), offset );
649   return pokemini_hwreg[offset];
1316   return pm_reg[offset];
6501317}
6511318
652DEVICE_START( pokemini_cart ) {
1319DEVICE_START( pokemini_cart )
1320{
6531321}
6541322
655DEVICE_IMAGE_LOAD( pokemini_cart ) {
1323DEVICE_IMAGE_LOAD( pokemini_cart )
1324{
6561325   int   size = image_length( image );
6571326
6581327   /* Verify that the image is big enough */
659   if ( size <= 0x2100 ) {
1328   if ( size <= 0x2100 )
1329   {
6601330      image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid ROM image: ROM image is too small" );
6611331      return INIT_FAIL;
6621332   }
6631333
6641334   /* Verify that the image is not too big */
665   if ( size > 0x1FFFFF ) {
1335   if ( size > 0x1FFFFF )
1336   {
6661337      image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid ROM image: ROM image is too big" );
6671338      return INIT_FAIL;
6681339   }
r2798r2799
6711342   image_fseek( image, 0x2100, SEEK_SET );
6721343   size -= 0x2100;
6731344
674   if ( size != image_fread( image, memory_region(REGION_CPU1) + 0x2100, size ) ) {
1345   if ( size != image_fread( image, memory_region(REGION_CPU1) + 0x2100, size ) )
1346   {
6751347      image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Error occured while reading ROM image" );
6761348      return INIT_FAIL;
6771349   }
r2798r2799
6791351   return INIT_PASS;
6801352}
6811353
682static void pokemini_render( void ) {
683   if ( vdp.background_enabled ) {
684      int x, y;
685      for ( y = 0; y < 8; y++ ) {
686         for ( x = 0; x < 12; x++ ) {
687            UINT8 tile = pokemini_ram[ 0x360 + ( y * vdp.map_size_x ) + x ];
688            int i;
689            for( i = 0; i < 8; i++ ) {
690               pokemini_ram[ ( y * 96 ) + ( x * 8 ) + i ] = program_read_byte( vdp.bg_tiles + ( tile * 8 ) + i );
1354
1355static TIMER_CALLBACK( pokemini_prc_counter_callback )
1356{
1357   prc.count++;
1358
1359logerror("prc.count is %02x\n", prc.count);
1360   /* Check for overflow */
1361   if ( prc.count >= 0x42 )
1362   {
1363      prc.count = 0;
1364      prc.frame_count++;
1365
1366      if ( prc.frame_count >= prc.max_frame_count )
1367      {
1368         prc.frame_count = 0;
1369
1370         /* Check if the background should be drawn */
1371         if ( prc.background_enabled )
1372         {
1373            int x, y;
1374            for ( y = 0; y < 8; y++ ) {
1375               for ( x = 0; x < 12; x++ ) {
1376                  UINT8 tile = pokemini_ram[ 0x360 + ( y * prc.map_size_x ) + x ];
1377                  int i;
1378                  for( i = 0; i < 8; i++ ) {
1379                     pokemini_ram[ ( y * 96 ) + ( x * 8 ) + i ] = program_read_byte( prc.bg_tiles + ( tile * 8 ) + i );
1380                  }
1381               }
6911382            }
6921383         }
693      }
694   }
695}
6961384
697INTERRUPT_GEN( pokemini_int ) {
698   /* Check if drawing is enabled */
699   if ( vdp.rendering_enabled ) {
700      int   x, y;
1385         /* Check if the sprites should be drawn */
1386         if ( prc.sprites_enabled )
1387         {
1388         }
7011389
702      pokemini_render();
1390         /* Set PRC Render interrupt */
1391         pm_reg[0x27] |= 0x40;
1392         pokemini_check_irqs( machine );
7031393
704      for( y = 0; y < 64; y += 8 ) {
705         for( x = 0; x < 96; x++ ) {
706            UINT8 data = pokemini_ram[ ( y * 12 ) + x ];
707            *BITMAP_ADDR16(tmpbitmap, y + 0, x) = ( data & 0x01 ) ? 3 : 0;
708            *BITMAP_ADDR16(tmpbitmap, y + 1, x) = ( data & 0x02 ) ? 3 : 0;
709            *BITMAP_ADDR16(tmpbitmap, y + 2, x) = ( data & 0x04 ) ? 3 : 0;
710            *BITMAP_ADDR16(tmpbitmap, y + 3, x) = ( data & 0x08 ) ? 3 : 0;
711            *BITMAP_ADDR16(tmpbitmap, y + 4, x) = ( data & 0x10 ) ? 3 : 0;
712            *BITMAP_ADDR16(tmpbitmap, y + 5, x) = ( data & 0x20 ) ? 3 : 0;
713            *BITMAP_ADDR16(tmpbitmap, y + 6, x) = ( data & 0x40 ) ? 3 : 0;
714            *BITMAP_ADDR16(tmpbitmap, y + 7, x) = ( data & 0x80 ) ? 3 : 0;
1394         /* Check if the rendered data should be copied to the LCD */
1395         if ( prc.copy_enabled )
1396         {
1397            int   x, y;
1398
1399            for( y = 0; y < 64; y += 8 ) {
1400               for( x = 0; x < 96; x++ ) {
1401                  UINT8 data = pokemini_ram[ ( y * 12 ) + x ];
1402
1403                  *BITMAP_ADDR16(tmpbitmap, y + 0, x) = ( data & 0x01 ) ? 3 : 0;
1404                  *BITMAP_ADDR16(tmpbitmap, y + 1, x) = ( data & 0x02 ) ? 3 : 0;
1405                  *BITMAP_ADDR16(tmpbitmap, y + 2, x) = ( data & 0x04 ) ? 3 : 0;
1406                  *BITMAP_ADDR16(tmpbitmap, y + 3, x) = ( data & 0x08 ) ? 3 : 0;
1407                  *BITMAP_ADDR16(tmpbitmap, y + 4, x) = ( data & 0x10 ) ? 3 : 0;
1408                  *BITMAP_ADDR16(tmpbitmap, y + 5, x) = ( data & 0x20 ) ? 3 : 0;
1409                  *BITMAP_ADDR16(tmpbitmap, y + 6, x) = ( data & 0x40 ) ? 3 : 0;
1410                  *BITMAP_ADDR16(tmpbitmap, y + 7, x) = ( data & 0x80 ) ? 3 : 0;
1411               }
1412            }
7151413         }
1414
1415         /* Set PRC Copy interrupt */
1416         pm_reg[0x27] |= 0x80;
1417         pokemini_check_irqs( machine );
7161418      }
1419
1420      /* Set possible input irqs */
1421      pm_reg[0x29] |= ~ input_port_read( machine, "INPUTS" );
7171422   }
7181423}
7191424
7201425
1426MACHINE_RESET( pokemini )
1427{
1428   /* Clear internal structures */
1429   memset( &prc, 0, sizeof(prc) );
1430   memset( &timers, 0, sizeof(timers) );
1431   memset( pm_reg, 0, sizeof(pm_reg) );
1432
1433   /* Set up timers */
1434   timers.seconds_timer = timer_alloc( pokemini_seconds_timer_callback , NULL );
1435   timer_adjust_periodic( timers.seconds_timer, attotime_zero, 0, ATTOTIME_IN_SEC( 1 ) );
1436
1437   timers.hz256_timer = timer_alloc( pokemini_256hz_timer_callback , NULL );
1438   timer_adjust_periodic( timers.hz256_timer, attotime_zero, 0, ATTOTIME_IN_HZ( 256 ) );
1439
1440   timers.timer1 = timer_alloc( pokemini_timer1_callback , NULL );
1441   timers.timer1_hi = timer_alloc( pokemini_timer1_hi_callback, NULL );
1442   timers.timer2 = timer_alloc( pokemini_timer2_callback , NULL );
1443   timers.timer2_hi = timer_alloc( pokemini_timer2_hi_callback, NULL );
1444   timers.timer3 = timer_alloc( pokemini_timer3_callback , NULL );
1445   timers.timer3_hi = timer_alloc( pokemini_timer3_hi_callback, NULL );
1446
1447   /* Set up the PRC */
1448   prc.max_frame_count = 2;
1449   prc.count_timer = timer_alloc( pokemini_prc_counter_callback, NULL );
1450   timer_adjust_periodic( prc.count_timer, attotime_zero, 0, ATTOTIME_IN_CYCLES( 55640 / 65, 0 ) );
1451}
1452
src/mess/drivers/pokemini.c
r2798r2799
1212#include "cpu/minx/minx.h"
1313#include "devices/cartslot.h"
1414
15
1516static ADDRESS_MAP_START( pokemini_mem_map, ADDRESS_SPACE_PROGRAM, 8 )
1617   AM_RANGE( 0x000000, 0x000FFF )  AM_ROM                     /* bios */
1718   AM_RANGE( 0x001000, 0x001FFF )   AM_RAM AM_BASE( &pokemini_ram)            /* VRAM/RAM */
r2798r2799
1920   AM_RANGE( 0x002100, 0x1FFFFF )  AM_ROM                     /* cartridge area */
2021ADDRESS_MAP_END
2122
23
2224static INPUT_PORTS_START( pokemini )
2325   PORT_START_TAG("INPUTS")
2426   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("Button A")
r2798r2799
3133   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1) PORT_NAME("Power")
3234INPUT_PORTS_END
3335
34static PALETTE_INIT( pokemini ) {
35   static const unsigned char pokemini_pal[4][3] = {
36
37static PALETTE_INIT( pokemini )
38{
39   static const unsigned char pokemini_pal[4][3] =
40   {
3641      { 0xFF, 0xFB, 0x87 },
3742      { 0xB1, 0xAE, 0x4E },
3843      { 0x84, 0x80, 0x4E },
3944      { 0x4E, 0x4E, 0x4E }
4045   };
4146   int i;
42   for( i = 0; i < 4; i++ ) {
47   for( i = 0; i < 4; i++ )
48   {
4349      palette_set_color_rgb( machine, i, pokemini_pal[i][0], pokemini_pal[i][1], pokemini_pal[i][2] );
4450   }
4551}
4652
53
4754static MACHINE_DRIVER_START( pokemini )
4855   /* basic machine hardware */
4956   MDRV_CPU_ADD_TAG( "main", MINX, 4000000 )
r2798r2799
6471   MDRV_SCREEN_VISIBLE_AREA( 0, 95, 0, 63 )
6572   MDRV_PALETTE_LENGTH( 4 )
6673   MDRV_PALETTE_INIT( pokemini )
67   MDRV_SCREEN_REFRESH_RATE( 30 )
68   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
69   MDRV_CPU_VBLANK_INT("main", pokemini_int)
74   MDRV_SCREEN_REFRESH_RATE( 72 )
7075
7176   /* sound hardware */
7277#if 0   
r2798r2799
7681#endif
7782MACHINE_DRIVER_END
7883
79static void pokemini_cartslot_getinfo( const mess_device_class *devclass, UINT32 state, union devinfo *info ) {
80   switch( state ) {
84
85static void pokemini_cartslot_getinfo( const mess_device_class *devclass, UINT32 state, union devinfo *info )
86{
87   switch( state )
88   {
8189   case MESS_DEVINFO_INT_COUNT:         info->i = 1; break;
8290   case MESS_DEVINFO_INT_MUST_BE_LOADED:   info->i = 0; break;
8391   case MESS_DEVINFO_PTR_START:         info->start = DEVICE_START_NAME(pokemini_cart); break;
r2798r2799
8795   }
8896}
8997
98
9099SYSTEM_CONFIG_START( pokemini )
91100   CONFIG_DEVICE( pokemini_cartslot_getinfo )
92101SYSTEM_CONFIG_END
93102
103
94104ROM_START( pokemini )
95105   ROM_REGION( 0x200000, REGION_CPU1, 0 )
96106   ROM_LOAD( "bios.min", 0x0000, 0x1000, CRC(aed3c14d) SHA1(daad4113713ed776fbd47727762bca81ba74915f) )
97107ROM_END
98108
109
99110CONS( 1999, pokemini, 0, 0, pokemini, pokemini, 0, pokemini, "Nintendo", "Pokemon Mini", GAME_NOT_WORKING )
100111

Previous 15994 Revisions Next


© 1998-2018 The MESS Team