Previous 15994 Revisions Next

r832 Friday 17th August, 2007 at 04:17:49 UTC by R. Belmont
[A310] First pass at video, audio, timer, and interrupt controller. BIOS gets farther.
[src/mess/drivers]a310.c

src/mess/drivers/a310.c
r831r832
3333#include "machine/wd17xx.h"
3434#include "video/generic.h"
3535#include "devices/basicdsk.h"
36#include "cpu/arm/arm.h"
37#include "sound/dac.h"
3638#include "image.h"
3739
3840#ifndef VERBOSE
r831r832
4547#define LOG(x)   /* x */
4648#endif
4749
50// interrupt register stuff
51#define A310_IRQA_PRINTER_BUSY (0x01)
52#define A310_IRQA_SERIAL_RING  (0x02)
53#define A310_IRQA_PRINTER_ACK  (0x04)
54#define A310_IRQA_VBL          (0x08)
55#define A310_IRQA_RESET        (0x10)
56#define A310_IRQA_TIMER0       (0x20)
57#define A310_IRQA_TIMER1       (0x40)
58#define A310_IRQA_ALWAYS       (0x80)
59
60#define A310_IRQB_PODULE_FIQ   (0x01)
61#define A310_IRQB_SOUND_EMPTY  (0x02)
62#define A310_IRQB_SERIAL       (0x04)
63#define A310_IRQB_HDD          (0x08)
64#define A310_IRQB_DISC_CHANGE  (0x10)
65#define A310_IRQB_PODULE_IRQ   (0x20)
66#define A310_IRQB_KBD_XMIT_EMPTY  (0x40)
67#define A310_IRQB_KBD_RECV_FULL   (0x80)
68
69#define A310_FIQ_FLOPPY_DRQ    (0x01)
70#define A310_FIQ_FLOPPY        (0x02)
71#define A310_FIQ_ECONET        (0x04)
72#define A310_FIQ_PODULE        (0x40)
73#define A310_FIQ_FORCE         (0x80)
74
4875static int page_sizes[4] = { 4096, 8192, 16384, 32768 };
4976
5077static UINT32 *a310_physmem;
5178static UINT32 a310_pagesize;
5279static int a310_latchrom;
5380static INT16 a310_pages[(32*1024*1024)/(4096)];   // the logical RAM area is 32 megs, and the smallest page size is 4k
54UINT32 a310_vidregs[256], a310_iocregs[0x80/4];
81static UINT32 a310_vidregs[256];
82static UINT8 a310_iocregs[0x80/4];
83static UINT32 a310_timercnt[4];
84static UINT32 a310_sndstart, a310_sndend, a310_sndcur;
5585
86static mame_timer *vbl_timer, *timer[4], *snd_timer;
87
5688VIDEO_START( a310 )
5789{
5890}
r831r832
6294   return 0;
6395}
6496
97static void a310_request_irq_a(int mask)
98{
99   a310_iocregs[4] |= mask;
100
101   if (a310_iocregs[6] & mask)
102   {
103      cpunum_set_input_line(0, ARM_IRQ_LINE, ASSERT_LINE);
104   }
105}
106
107static void a310_request_irq_b(int mask)
108{
109   a310_iocregs[8] |= mask;
110
111   if (a310_iocregs[10] & mask)
112   {
113      cpunum_set_input_line(0, ARM_IRQ_LINE, PULSE_LINE);
114   }
115}
116
117static TIMER_CALLBACK( a310_audio_tick )
118{
119   a310_sndcur++;
120
121   if (a310_sndcur >= a310_sndend)
122   {
123      a310_request_irq_b(A310_IRQB_SOUND_EMPTY);
124   }   
125}
126
127static TIMER_CALLBACK( a310_vblank )
128{
129   a310_request_irq_a(A310_IRQA_VBL);
130
131   // set up for next vbl
132   mame_timer_adjust(vbl_timer, video_screen_get_time_until_pos(0, a310_vidregs[0xb4], 0), 0, time_never);
133}
134
135static void a310_set_timer(int tmr)
136{
137   double freq = 2000000.0 / (double)a310_timercnt[tmr];
138
139//   logerror("IOC: starting timer %d, %d ticks, freq %f Hz\n", tmr, a310_timercnt[tmr], freq);
140
141   mame_timer_adjust(timer[tmr], MAME_TIME_IN_HZ(freq), tmr, time_never);
142}
143
144// param
145static TIMER_CALLBACK( a310_timer )
146{
147   // all timers always run
148   a310_set_timer(param);
149
150   // but only timers 0 and 1 generate IRQs   
151   switch (param)
152   {
153      case 0:
154         a310_request_irq_a(A310_IRQA_TIMER0);
155         break;
156
157      case 1:
158         a310_request_irq_a(A310_IRQA_TIMER1);
159         break;
160   }   
161}
162
65163static void a310_memc_reset(void)
66164{
67165   int i;
r831r832
84182{
85183}
86184
185
87186static MACHINE_START( a310 )
88187{
89188   a310_pagesize = 0;
90189   wd17xx_init(WD_TYPE_177X, a310_wd177x_callback, NULL);
190
191   vbl_timer = mame_timer_alloc(a310_vblank);
192   mame_timer_adjust(vbl_timer, time_never, 0, time_never);
193
194   timer[0] = mame_timer_alloc(a310_timer);
195   timer[1] = mame_timer_alloc(a310_timer);
196   timer[2] = mame_timer_alloc(a310_timer);
197   timer[3] = mame_timer_alloc(a310_timer);
198   mame_timer_adjust(timer[0], time_never, 0, time_never);
199   mame_timer_adjust(timer[1], time_never, 0, time_never);
200   mame_timer_adjust(timer[2], time_never, 0, time_never);
201   mame_timer_adjust(timer[3], time_never, 0, time_never);
202
203   snd_timer = mame_timer_alloc(a310_audio_tick);
204   mame_timer_adjust(snd_timer, time_never, 0, time_never);
205
206   // reset the DAC to centerline
207   DAC_signed_data_w(0, 0x80);
91208}
92209
93210static READ32_HANDLER(logical_r)
r831r832
186303   memory_set_opbase_handler(0, a310_setopbase);
187304}
188305
306static const char *ioc_regnames[] =
307{
308   "(rw) Control",               // 0
309   "(read) Keyboard receive (write) keyboard send",   // 1
310   "?",
311   "?",
312   "(read) IRQ status A",               // 4
313   "(read) IRQ request A (write) IRQ clear",   // 5
314   "(rw) IRQ mask A",            // 6
315   "?",
316   "(read) IRQ status B",      // 8
317   "(read) IRQ request B",      // 9
318   "(rw) IRQ mask B",      // 10
319   "?",
320   "(read) FIQ status",      // 12
321   "(read) FIQ request",      // 13
322   "(rw) FIQ mask",      // 14
323   "?",
324   "(read) Timer 0 count low (write) Timer 0 latch low",      // 16
325   "(read) Timer 0 count high (write) Timer 0 latch high",      // 17
326   "(write) Timer 0 go command",               // 18
327   "(write) Timer 0 latch command",            // 19
328   "(read) Timer 1 count low (write) Timer 1 latch low",      // 20
329   "(read) Timer 1 count high (write) Timer 1 latch high",      // 21
330   "(write) Timer 1 go command",               // 22
331   "(write) Timer 1 latch command",            // 23
332   "(read) Timer 2 count low (write) Timer 2 latch low",      // 24
333   "(read) Timer 2 count high (write) Timer 2 latch high",      // 25
334   "(write) Timer 2 go command",               // 26
335   "(write) Timer 2 latch command",            // 27
336   "(read) Timer 3 count low (write) Timer 3 latch low",      // 28
337   "(read) Timer 3 count high (write) Timer 3 latch high",      // 29
338   "(write) Timer 3 go command",               // 30
339   "(write) Timer 3 latch command"               // 31
340};
341
342static void update_timer_cnt(int tmr)
343{
344   double time;
345   UINT32 cnt;
346
347   time = mame_time_to_double(mame_timer_timeelapsed(timer[tmr]));
348   time *= 2000000.0;   // find out how many 2 MHz ticks have gone by
349   cnt = a310_timercnt[tmr] - (UINT32)time;
350   a310_iocregs[16+(4*tmr)] = cnt&0xff;
351   a310_iocregs[17+(4*tmr)] = (cnt>>8)&0xff;
352}
353
189354static READ32_HANDLER(ioc_r)
190355{
191
192356   if (offset >= 0x80000 && offset < 0xc0000)
193357   {
194      logerror("IOC: R reg %x (mask %08x)\n", (offset*4)&0x7c, mem_mask);
195      return a310_iocregs[offset];
358      switch (offset & 0x1f)
359      {
360         case 1:   // keyboard read
361            a310_request_irq_b(A310_IRQB_KBD_XMIT_EMPTY);
362            break;
363
364         case 16:   // timer 0 read
365         case 17:
366            update_timer_cnt(0);
367            break;
368         case 20:   // timer 1 read
369         case 21:
370            update_timer_cnt(1);
371            break;
372         case 24:   // timer 2 read
373         case 25:
374            update_timer_cnt(2);
375            break;
376         case 28:   // timer 3 read
377         case 29:
378            update_timer_cnt(3);
379            break;
380      }
381
382      logerror("IOC: R %s = %02x (PC=%x)\n", ioc_regnames[offset&0x1f], a310_iocregs[offset&0x1f], activecpu_get_pc());
383      return a310_iocregs[offset&0x1f];
196384   }
197385   else
198386   {
r831r832
207395{
208396   if (offset >= 0x80000 && offset < 0xc0000)
209397   {
210      logerror("IOC: W %x @ reg %x (mask %08x)\n", data, (offset*4)&0x7c, mem_mask);
211      COMBINE_DATA(&a310_iocregs[offset]);
398      logerror("IOC: W %02x @ reg %s (PC=%x)\n", data&0xff, ioc_regnames[offset&0x1f], activecpu_get_pc());
399
400      switch (offset&0x1f)
401      {
402         case 5:    // IRQ clear A
403            a310_iocregs[4] &= ~(data&0xff);
404
405            // if that did it, clear the IRQ
406            if (a310_iocregs[4] == 0)
407            {
408               cpunum_set_input_line(0, ARM_IRQ_LINE, CLEAR_LINE);
409            }
410            break;
411
412         case 16:
413         case 17:
414            a310_iocregs[offset&0x1f] = data & 0xff;
415            a310_timercnt[0] = a310_iocregs[17]<<8 | a310_iocregs[16];
416            break;
417
418         case 20:
419         case 21:
420            a310_iocregs[offset&0x1f] = data & 0xff;
421            a310_timercnt[1] = a310_iocregs[21]<<8 | a310_iocregs[20];
422            break;
423
424         case 24:
425         case 25:
426            a310_iocregs[offset&0x1f] = data & 0xff;
427            a310_timercnt[2] = a310_iocregs[25]<<8 | a310_iocregs[24];
428            break;
429
430         case 28:
431         case 29:
432            a310_iocregs[offset&0x1f] = data & 0xff;
433            a310_timercnt[3] = a310_iocregs[29]<<8 | a310_iocregs[28];
434            break;
435
436         case 19:   // Timer 0 latch
437            a310_timercnt[0] = a310_iocregs[17]<<8 | a310_iocregs[16];
438            break;
439
440         case 23:   // Timer 1 latch
441            a310_timercnt[1] = a310_iocregs[21]<<8 | a310_iocregs[20];
442            break;
443
444         case 27:   // Timer 2 latch
445            a310_timercnt[2] = a310_iocregs[25]<<8 | a310_iocregs[24];
446            break;
447
448         case 31:   // Timer 3 latch
449            a310_timercnt[3] = a310_iocregs[29]<<8 | a310_iocregs[28];
450            break;
451
452         case 18:   // Timer 0 start
453            a310_set_timer(0);
454            break;
455
456         case 22:   // Timer 1 start
457            a310_set_timer(1);
458            break;
459
460         case 26:   // Timer 2 start
461            a310_set_timer(2);
462            break;
463
464         case 30:   // Timer 3 start
465            a310_set_timer(3);
466            break;
467
468         default:
469            a310_iocregs[offset&0x1f] = data & 0xff;
470            break;
471      }
212472   }
213473   else
214474   {
r831r832
248508   if (reg >= 0x80 && reg <= 0xbc)
249509   {
250510      logerror("VIDC: %s = %d\n", vrnames[(reg-0x80)/4], val>>12);
511
512      if ((reg == 0xb0) & ((val>>12) != 0))
513      {
514         rectangle visarea;
515
516         visarea.min_x = 0;
517         visarea.min_y = 0;
518         visarea.max_x = a310_vidregs[0x94] - a310_vidregs[0x88];
519         visarea.max_y = a310_vidregs[0xb4] - a310_vidregs[0xa8];
520
521         logerror("Configuring: htotal %d vtotal %d vis %d,%d\n",
522            a310_vidregs[0x80], a310_vidregs[0xa0],
523            visarea.max_x, visarea.max_y);
524
525         video_screen_configure(0, a310_vidregs[0x80], a310_vidregs[0xa0], &visarea, Machine->screen[0].refresh);
526
527         // slightly hacky: fire off a VBL right now.  the BIOS doesn't wait long enough otherwise.
528         mame_timer_adjust(vbl_timer, time_zero, 0, time_never);
529      }
530   
531      a310_vidregs[reg] = val>>12;
251532   }
252533   else
253534   {
254535      logerror("VIDC: %x to register %x\n", val, reg);
536      a310_vidregs[reg] = val&0xffff;
255537   }
256
257   a310_vidregs[reg] = val;
258538}
259539
260540static READ32_HANDLER(memc_r)
r831r832
269549   {
270550      switch ((data >> 17) & 7)
271551      {
272         
552         case 4:   /* sound start */
553            a310_sndstart = ((data>>2)&0x7fff)*16;
554            break;
273555
556         case 5: /* sound end */
557            a310_sndend = ((data>>2)&0x7fff)*16;
558            break;
559
274560         case 7:   /* Control */
275561            a310_pagesize = ((data>>2) & 3);
276562
277563            logerror("MEMC: %x to Control (page size %d, %s, %s)\n", data & 0x1ffc, page_sizes[a310_pagesize], ((data>>10)&1) ? "Video DMA on" : "Video DMA off", ((data>>11)&1) ? "Sound DMA on" : "Sound DMA off");
564
565            if ((data>>11)&1)
566            {
567               double sndhz;
568
569               sndhz = 250000.0 / (double)((a310_vidregs[0xc0]&0xff)+2);
570
571               logerror("MEMC: Starting audio DMA at %f Hz, buffer from %x to %x\n", sndhz, a310_sndstart, a310_sndend);
572
573               a310_sndcur = a310_sndstart;
574
575               mame_timer_adjust(snd_timer, MAME_TIME_IN_HZ(sndhz), 0, MAME_TIME_IN_HZ(sndhz));
576            }
577            else
578            {
579               mame_timer_adjust(snd_timer, time_never, 0, time_never);
580               DAC_signed_data_w(0, 0x80);
581            }
278582            break;
279583
280584         default:
r831r832
508812
509813   MDRV_VIDEO_START(a310)
510814   MDRV_VIDEO_UPDATE(a310)
815
816   MDRV_SPEAKER_STANDARD_MONO("a310")
817   MDRV_SOUND_ADD(DAC, 0)
818   MDRV_SOUND_ROUTE(0, "a310", 1.00)
511819MACHINE_DRIVER_END
512820
513821

Previous 15994 Revisions Next


© 1998-2018 The MESS Team