Previous 15994 Revisions Next

r8305 Wednesday 23rd June, 2010 at 18:20:38 UTC by Wilbert Pol
[PV1000] Moved global variables into a driver state. Changed irq timing a bit.
[src/mess/drivers]pv1000.c

src/mess/drivers/pv1000.c
r8304r8305
1313#define SOUND_PV1000   DEVICE_GET_INFO_NAME(pv1000_sound)
1414
1515
16typedef struct _pvaudio_voice pvaudio_voice;
17struct _pvaudio_voice
18{
19   UINT32 count;
20   UINT16 period;
21   UINT8  val;
22};
16class d65010_state {
17public:
18   static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, d65010_state(machine)); }
19   d65010_state(running_machine &machine) { }
2320
21   UINT8   io_regs[8];
22   UINT8   fd_data;
23   struct
24   {
25      UINT32   count;
26      UINT16   period;
27      UINT8   val;
28   }      voice[4];
2429
25typedef struct _pvaudio_state pvaudio_state;
26struct _pvaudio_state
27{
28   sound_stream *pv1000_sh_channel;
30   sound_stream   *sh_channel;
31   emu_timer      *irq_on_timer;
32   emu_timer      *irq_off_timer;
2933
30   pvaudio_voice voice[4];
34   running_device *maincpu;
35   running_device *screen;
3136};
3237
3338
3439static UINT8 *pv1000_ram;
35static UINT8 pv1000_io_regs[8];
36static UINT8 pv1000_fd_data;
37static pvaudio_state g_audio;
3840
3941
40
4142static WRITE8_HANDLER( pv1000_io_w );
4243static READ8_HANDLER( pv1000_io_r );
4344static WRITE8_HANDLER( pv1000_gfxram_w );
r8304r8305
6768
6869static WRITE8_HANDLER( pv1000_io_w )
6970{
71   d65010_state *state = (d65010_state *)space->machine->driver_data;
7072
7173   switch ( offset )
7274   {
r8304r8305
7476   case 0x01:
7577   case 0x02:
7678      //logerror("pv1000_io_w offset=%02x, data=%02x (%03d)\n", offset, data , data);
77      g_audio.voice[offset].period=data;
79      state->voice[offset].period = data;
7880   break;
7981
8082   case 0x03:
r8304r8305
8284   break;
8385
8486   case 0x05:
85      pv1000_fd_data = 1;
87      state->fd_data = 1;
8688      break;
8789   }
8890
89   pv1000_io_regs[offset] = data;
91   state->io_regs[offset] = data;
9092}
9193
9294
9395static READ8_HANDLER( pv1000_io_r )
9496{
95   UINT8 data = pv1000_io_regs[offset];
97   d65010_state *state = (d65010_state *)space->machine->driver_data;
98   UINT8 data = state->io_regs[offset];
9699
97100//  logerror("pv1000_io_r offset=%02x\n", offset );
98101
r8304r8305
101104   case 0x04:
102105      /* Bit 1 = 1 => Data is available in port FD */
103106      /* Bit 0 = 1 => Buffer at port FD is empty */
104      data = pv1000_fd_data ? 0x02 : 0x01;
107      data = ( video_screen_get_vpos( state->screen ) >= 212 && video_screen_get_vpos( state->screen ) <= 220 ) ? 0x01 : 0x00;
108      data |= state->fd_data ? 0x02 : 0x00;
105109      break;
106110   case 0x05:
107111      data = 0;
108      if ( pv1000_io_regs[5] & 0x08 )
112      if ( state->io_regs[5] & 0x08 )
109113      {
110114         data = input_port_read( space->machine, "IN3" );
111115      }
112      if ( pv1000_io_regs[5] & 0x04 )
116      if ( state->io_regs[5] & 0x04 )
113117      {
114118         data = input_port_read( space->machine, "IN2" );
115119      }
116      if ( pv1000_io_regs[5] & 0x02 )
120      if ( state->io_regs[5] & 0x02 )
117121      {
118122         data = input_port_read( space->machine, "IN1" );
119123      }
120      if ( pv1000_io_regs[5] & 0x01 )
124      if ( state->io_regs[5] & 0x01 )
121125      {
122126         data = input_port_read( space->machine, "IN0" );
123127      }
124      pv1000_fd_data = 0;
128      state->fd_data = 0;
125129      break;
126130   }
127131
r8304r8305
208212
209213static VIDEO_UPDATE( pv1000 )
210214{
215   d65010_state *state = (d65010_state *)screen->machine->driver_data;
211216   int x, y;
212217
213218   for ( y = 0; y < 24; y++ )
r8304r8305
218223
219224         if ( tile < 0xe0 )
220225         {
221            tile += ( pv1000_io_regs[7] * 8 );
226            tile += ( state->io_regs[7] * 8 );
222227            drawgfx_opaque( bitmap, cliprect, screen->machine->gfx[0], tile, 0, 0, 0, x*8, y*8 );
223228         }
224229         else
r8304r8305
235240
236241/*
237242 plgDavid's audio implementation/analysis notes:
238
243
239244 Sound appears to be 3 50/50 pulse voices made by cutting the main clock by 1024,
240245 then by the value of the 6bit period registers.
241246 This creates a surprisingly accurate pitch range.
242
247
243248 Note: the register periods are inverted.
244249 */
245250
246251static STREAM_UPDATE( pv1000_sound_update )
247252{
253   d65010_state *state = (d65010_state *)device->machine->driver_data;
248254   stream_sample_t *buffer = outputs[0];
249255
250256   while ( samples > 0 )
r8304r8305
254260
255261      for (size_t i=0;i<3;i++)
256262      {
257         pvaudio_voice *v = &g_audio.voice[i];
258         UINT32 per = (0x3F-(v->period & 0x3f));
263         UINT32 per = (0x3F-(state->voice[i].period & 0x3f));
259264
260265         if( per != 0)//OFF!
261            *buffer += v->val * 8192;
266            *buffer += state->voice[i].val * 8192;
262267
263         v->count++;
268         state->voice[i].count++;
264269
265         if (v->count >= per)
270         if (state->voice[i].count >= per)
266271         {
267            v->count = 0;
268            v->val = !v->val;
272            state->voice[i].count = 0;
273            state->voice[i].val = !state->voice[i].val;
269274         }
270275      }
271276
r8304r8305
278283
279284static DEVICE_START( pv1000_sound )
280285{
281   g_audio.pv1000_sh_channel = stream_create( device, 0, 1, device->clock/1024, 0, pv1000_sound_update );
286   d65010_state *state = (d65010_state *)device->machine->driver_data;
287   state->sh_channel = stream_create( device, 0, 1, device->clock/1024, 0, pv1000_sound_update );
282288}
283289
284290
r8304r8305
296302}
297303
298304
299static TIMER_DEVICE_CALLBACK( pv1000_irq )
305/* Interrupt is triggering 16 times during vblank. */
306/* we have chosen to trigger on scanlines 195, 199, 203, 207, 211, 215, 219, 223, 227, 231, 235, 239, 243, 247, 251, 255 */
307static TIMER_CALLBACK( d65010_irq_on_cb )
300308{
301   running_device *cpu = devtag_get_device( timer->machine, "maincpu" );
302   cpu_set_input_line(cpu, 0, HOLD_LINE);
309   d65010_state *state = (d65010_state *)machine->driver_data;
310   int vpos = video_screen_get_vpos( state->screen );
311   int next_vpos = vpos + 12;
312
313   /* Set IRQ line and schedule release of IRQ line */
314   cpu_set_input_line( state->maincpu, 0, ASSERT_LINE );
315   timer_adjust_oneshot( state->irq_off_timer, video_screen_get_time_until_pos( state->screen, vpos, 380/2 ), 0 );
316
317   /* Schedule next IRQ trigger */
318   if ( vpos >= 255 )
319   {
320      next_vpos = 195;
321   }
322   timer_adjust_oneshot( state->irq_on_timer, video_screen_get_time_until_pos( state->screen, next_vpos, 0 ), 0 );
303323}
304324
305325
326static TIMER_CALLBACK( d65010_irq_off_cb )
327{
328   d65010_state *state = (d65010_state *)machine->driver_data;
329
330   cpu_set_input_line( state->maincpu, 0, CLEAR_LINE );
331}
332
333
334static MACHINE_START( pv1000 )
335{
336   d65010_state *state = (d65010_state *)machine->driver_data;
337
338   state->irq_on_timer = timer_alloc( machine, d65010_irq_on_cb, NULL );
339   state->irq_off_timer = timer_alloc( machine, d65010_irq_off_cb, NULL );
340   state->maincpu = devtag_get_device( machine, "maincpu" );
341   state->screen = devtag_get_device( machine, "screen" );
342}
343
344
306345static MACHINE_RESET( pv1000 )
307346{
308   pv1000_io_regs[5] = 0;
309   pv1000_fd_data = 0;
347   d65010_state *state = (d65010_state *)machine->driver_data;
348
349   state->io_regs[5] = 0;
350   state->fd_data = 0;
351   timer_adjust_oneshot( state->irq_on_timer, video_screen_get_time_until_pos( state->screen, 195, 0 ), 0 );
352   timer_adjust_oneshot( state->irq_off_timer, attotime_never, 0 );
310353}
311354
312355
r8304r8305
329372
330373
331374static MACHINE_DRIVER_START( pv1000 )
375   MDRV_DRIVER_DATA( d65010_state )
376
332377   MDRV_CPU_ADD( "maincpu", Z80, 17897725/5 )
333378   MDRV_CPU_PROGRAM_MAP( pv1000 )
334379   MDRV_CPU_IO_MAP( pv1000_io )
335380
336   MDRV_TIMER_ADD_PERIODIC("pv1000_irq", pv1000_irq, HZ(240))
337
381   MDRV_MACHINE_START( pv1000 )
338382   MDRV_MACHINE_RESET( pv1000 )
339383
340384   MDRV_SCREEN_ADD( "screen", RASTER )
341385   MDRV_SCREEN_FORMAT( BITMAP_FORMAT_INDEXED16 )
342   MDRV_SCREEN_REFRESH_RATE( 60 )
343   MDRV_SCREEN_SIZE(256, 192)
344   MDRV_SCREEN_VISIBLE_AREA( 0, 255, 0, 191 )
386   MDRV_SCREEN_RAW_PARAMS( 17897725/3, 380, 0, 256, 262, 0, 192 )
345387
346388   MDRV_PALETTE_LENGTH( 8 )
347389   MDRV_PALETTE_INIT( pv1000 )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team