Previous 15994 Revisions Next

r4195 Monday 26th January, 2009 at 02:55:28 UTC by R. Belmont
[A310] Splitting out Acorn custom chips to share with MAME.
[src/mame/includes]archimds.h*
[src/mame/machine]archimds.c*
[src/mess]mess.mak
[src/mess/drivers]a310.c

src/mame/machine/archimds.c
r0r4195
1/******************************************************************************
2 *
3 *  Acorn Archimedes custom chips (IOC, MEMC, VIDC)
4 *
5 *      Memory map (from http://b-em.bbcmicro.com/arculator/archdocs.txt)
6 *
7 *  0000000 - 1FFFFFF - logical RAM (32 meg)
8 *  2000000 - 2FFFFFF - physical RAM (supervisor only - max 16MB - requires quad MEMCs)
9 *  3000000 - 33FFFFF - IOC (IO controllers - supervisor only)
10 *  3310000 - FDC - WD1772
11 *  33A0000 - Econet - 6854
12 *  33B0000 - Serial - 6551
13 *  3240000 - 33FFFFF - internal expansion cards
14 *  32D0000 - hard disc controller (not IDE) - HD63463
15 *  3350010 - printer
16 *  3350018 - latch A
17 *  3350040 - latch B
18 *  3270000 - external expansion cards
19 *
20 *  3400000 - 3FFFFFF - ROM (read - 12 meg - Arthur and RiscOS 2 512k, RiscOS 3 2MB)
21 *  3400000 - 37FFFFF - Low ROM  (4 meg, I think this is expansion ROMs)
22 *  3800000 - 3FFFFFF - High ROM (main OS ROM)
23 *
24 *  3400000 - 35FFFFF - VICD10 (write - supervisor only)
25 *  3600000 - 3FFFFFF - MEMC (write - supervisor only)
26 *
27 *****************************************************************************/
28
29#include "driver.h"
30#include "machine/wd17xx.h"
31#include "cpu/arm/arm.h"
32#include "sound/dac.h"
33#include "includes/archimds.h"
34
35static const int page_sizes[4] = { 4096, 8192, 16384, 32768 };
36
37UINT32 *memc_physmem;
38static UINT32 memc_pagesize;
39static int memc_latchrom;
40static INT16 memc_pages[(32*1024*1024)/(4096)];   // the logical RAM area is 32 megs, and the smallest page size is 4k
41static UINT32 vidc_regs[256];
42static UINT8 ioc_regs[0x80/4];
43static UINT32 ioc_timercnt[4], ioc_timerout[4];
44static UINT32 vidc_sndstart, vidc_sndend, vidc_sndcur;
45
46static emu_timer *vbl_timer, *timer[4], *snd_timer;
47
48void archimedes_request_irq_a(running_machine *machine, int mask)
49{
50   ioc_regs[4] |= mask;
51
52   if (ioc_regs[6] & mask)
53   {
54      cpu_set_input_line(machine->cpu[0], ARM_IRQ_LINE, ASSERT_LINE);
55   }
56}
57
58void archimedes_request_irq_b(running_machine *machine, int mask)
59{
60   ioc_regs[8] |= mask;
61
62   if (ioc_regs[10] & mask)
63   {
64      cpu_set_input_line(machine->cpu[0], ARM_IRQ_LINE, PULSE_LINE);
65   }
66}
67
68void archimedes_request_fiq(running_machine *machine, int mask)
69{
70   ioc_regs[12] |= mask;
71
72   if (ioc_regs[14] & mask)
73   {
74      cpu_set_input_line(machine->cpu[0], ARM_FIRQ_LINE, PULSE_LINE);
75   }
76}
77
78void archimedes_clear_irq_a(running_machine *machine, int mask)
79{
80   ioc_regs[4] &= ~mask;
81}
82
83void archimedes_clear_irq_b(running_machine *machine, int mask)
84{
85   ioc_regs[8] &= ~mask;
86}
87
88void archimedes_clear_fiq(running_machine *machine, int mask)
89{
90   ioc_regs[12] &= ~mask;
91}
92
93static TIMER_CALLBACK( vidc_vblank )
94{
95   archimedes_request_irq_a(machine, ARCHIMEDES_IRQA_VBL);
96
97   // set up for next vbl
98   timer_adjust_oneshot(vbl_timer, video_screen_get_time_until_pos(machine->primary_screen, vidc_regs[0xb4], 0), 0);
99}
100
101static TIMER_CALLBACK( a310_audio_tick )
102{
103   vidc_sndcur++;
104
105   if (vidc_sndcur >= vidc_sndend)
106   {
107      archimedes_request_irq_b(machine, ARCHIMEDES_IRQB_SOUND_EMPTY);
108   }
109}
110
111static void a310_set_timer(int tmr)
112{
113   double freq = 2000000.0 / (double)ioc_timercnt[tmr];
114
115//  logerror("IOC: starting timer %d, %d ticks, freq %f Hz\n", tmr, ioc_timercnt[tmr], freq);
116
117   timer_adjust_oneshot(timer[tmr], ATTOTIME_IN_HZ(freq), tmr);
118}
119
120// param
121static TIMER_CALLBACK( ioc_timer )
122{
123   // all timers always run
124   a310_set_timer(param);
125
126   // but only timers 0 and 1 generate IRQs
127   switch (param)
128   {
129      case 0:
130         archimedes_request_irq_a(machine, ARCHIMEDES_IRQA_TIMER0);
131         break;
132
133      case 1:
134         archimedes_request_irq_a(machine, ARCHIMEDES_IRQA_TIMER1);
135         break;
136   }
137}
138
139void archimedes_reset(running_machine *machine)
140{
141   int i;
142
143   memc_latchrom = 1;         // map in the boot ROM
144
145   // kill all memc mappings
146   for (i = 0; i < (32*1024*1024)/(4096); i++)
147   {
148      memc_pages[i] = -1;      // indicate unmapped
149   }
150}
151
152void archimedes_init(running_machine *machine)
153{
154   memc_pagesize = 0;
155
156   vbl_timer = timer_alloc(machine, vidc_vblank, NULL);
157   timer_adjust_oneshot(vbl_timer, attotime_never, 0);
158
159   timer[0] = timer_alloc(machine, ioc_timer, NULL);
160   timer[1] = timer_alloc(machine, ioc_timer, NULL);
161   timer[2] = timer_alloc(machine, ioc_timer, NULL);
162   timer[3] = timer_alloc(machine, ioc_timer, NULL);
163   timer_adjust_oneshot(timer[0], attotime_never, 0);
164   timer_adjust_oneshot(timer[1], attotime_never, 0);
165   timer_adjust_oneshot(timer[2], attotime_never, 0);
166   timer_adjust_oneshot(timer[3], attotime_never, 0);
167
168   snd_timer = timer_alloc(machine, a310_audio_tick, NULL);
169   timer_adjust_oneshot(snd_timer, attotime_never, 0);
170}
171
172READ32_HANDLER(memc_logical_r)
173{
174   UINT32 page, poffs;
175
176   // are we mapping in the boot ROM?
177   if (memc_latchrom)
178   {
179      UINT32 *rom;
180
181      rom = (UINT32 *)memory_region(space->machine, "main");
182
183      return rom[offset & 0x1fffff];
184   }
185   else
186   {
187      // figure out the page number and offset in the page
188      page = (offset<<2) / page_sizes[memc_pagesize];
189      poffs = (offset<<2) % page_sizes[memc_pagesize];
190
191//      printf("Reading offset %x (addr %x): page %x (size %d %d) offset %x ==> %x %x\n", offset, offset<<2, page, memc_pagesize, page_sizes[memc_pagesize], poffs, memc_pages[page], memc_pages[page]*page_sizes[memc_pagesize]);
192
193      if (memc_pages[page] != -1)
194      {
195         return memc_physmem[((memc_pages[page] * page_sizes[memc_pagesize]) + poffs)>>2];
196      }
197      else
198      {
199         printf("ARCHIMEDES_MEMC: Reading unmapped page, what do we do?\n");
200      }
201   }
202
203   return 0;
204}
205
206WRITE32_HANDLER(memc_logical_w)
207{
208   UINT32 page, poffs;
209
210   // if the boot ROM is mapped, ignore writes
211   if (memc_latchrom)
212   {
213      return;
214   }
215   else
216   {
217      // figure out the page number and offset in the page
218      page = (offset<<2) / page_sizes[memc_pagesize];
219      poffs = (offset<<2) % page_sizes[memc_pagesize];
220
221//      printf("Writing offset %x (addr %x): page %x (size %d %d) offset %x ==> %x %x\n", offset, offset<<2, page, memc_pagesize, page_sizes[memc_pagesize], poffs, memc_pages[page], memc_pages[page]*page_sizes[memc_pagesize]);
222
223      if (memc_pages[page] != -1)
224      {
225         COMBINE_DATA(&memc_physmem[((memc_pages[page] * page_sizes[memc_pagesize]) + poffs)>>2]);
226      }
227      else
228      {
229         printf("ARCHIMEDES_MEMC: Writing unmapped page, what do we do?\n");
230      }
231   }
232}
233
234static DIRECT_UPDATE_HANDLER( a310_setopbase )
235{
236   // if we're not in logical memory, MAME can do the right thing
237   if (address > 0x1ffffff)
238   {
239      return address;
240   }
241
242   // if the boot ROM is mapped in, do some trickery to make it show up
243   if (memc_latchrom)
244   {
245      direct->bytemask = 0x1fffff;
246      direct->bytestart = 0;
247      direct->byteend = 0x1fffff;
248      direct->raw = direct->decrypted = memory_region(space->machine, "main");
249   }
250   else   // executing from logical memory
251   {
252      UINT32 page = address / page_sizes[memc_pagesize];
253
254      direct->bytemask = page_sizes[memc_pagesize]-1;
255      direct->bytestart = page * page_sizes[memc_pagesize];
256      direct->byteend = direct->bytestart + direct->bytemask;
257      direct->raw = direct->decrypted = (UINT8 *)&memc_physmem[(memc_pages[page] * page_sizes[memc_pagesize])>>2];
258   }
259
260   return ~0;
261}
262
263void archimedes_driver_init(running_machine *machine)
264{
265   memory_set_direct_update_handler( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), a310_setopbase);
266}
267
268static const char *const ioc_regnames[] =
269{
270   "(rw) Control",               // 0
271   "(read) Keyboard receive (write) keyboard send",   // 1
272   "?",
273   "?",
274   "(read) IRQ status A",               // 4
275   "(read) IRQ request A (write) IRQ clear",   // 5
276   "(rw) IRQ mask A",            // 6
277   "?",
278   "(read) IRQ status B",      // 8
279   "(read) IRQ request B",      // 9
280   "(rw) IRQ mask B",      // 10
281   "?",
282   "(read) FIQ status",      // 12
283   "(read) FIQ request",      // 13
284   "(rw) FIQ mask",      // 14
285   "?",
286   "(read) Timer 0 count low (write) Timer 0 latch low",      // 16
287   "(read) Timer 0 count high (write) Timer 0 latch high",      // 17
288   "(write) Timer 0 go command",               // 18
289   "(write) Timer 0 latch command",            // 19
290   "(read) Timer 1 count low (write) Timer 1 latch low",      // 20
291   "(read) Timer 1 count high (write) Timer 1 latch high",      // 21
292   "(write) Timer 1 go command",               // 22
293   "(write) Timer 1 latch command",            // 23
294   "(read) Timer 2 count low (write) Timer 2 latch low",      // 24
295   "(read) Timer 2 count high (write) Timer 2 latch high",      // 25
296   "(write) Timer 2 go command",               // 26
297   "(write) Timer 2 latch command",            // 27
298   "(read) Timer 3 count low (write) Timer 3 latch low",      // 28
299   "(read) Timer 3 count high (write) Timer 3 latch high",      // 29
300   "(write) Timer 3 go command",               // 30
301   "(write) Timer 3 latch command"               // 31
302};
303
304static void latch_timer_cnt(int tmr)
305{
306   double time = attotime_to_double(timer_timeelapsed(timer[tmr]));
307   time *= 2000000.0;   // find out how many 2 MHz ticks have gone by
308   ioc_timerout[tmr] = ioc_timercnt[tmr] - (UINT32)time;
309}
310
311READ32_HANDLER(ioc_r)
312{
313   #ifdef MESS
314   device_config *fdc = (device_config*)devtag_get_device(space->machine, WD1772, "wd1772");
315   #endif
316   if (offset >= 0x80000 && offset < 0xc0000)
317   {
318      switch (offset & 0x1f)
319      {
320         case 1:   // keyboard read
321            archimedes_request_irq_b(space->machine, ARCHIMEDES_IRQB_KBD_XMIT_EMPTY);
322            break;
323
324         case 16:   // timer 0 read
325            return ioc_timerout[0]&0xff;
326         case 17:
327            return (ioc_timerout[0]>>8)&0xff;
328         case 20:   // timer 1 read
329            return ioc_timerout[1]&0xff;
330         case 21:
331            return (ioc_timerout[1]>>8)&0xff;
332         case 24:   // timer 2 read
333            return ioc_timerout[2]&0xff;
334         case 25:
335            return (ioc_timerout[2]>>8)&0xff;
336         case 28:   // timer 3 read
337            return ioc_timerout[3]&0xff;
338         case 29:
339            return (ioc_timerout[3]>>8)&0xff;
340      }
341
342      logerror("IOC: R %s = %02x (PC=%x)\n", ioc_regnames[offset&0x1f], ioc_regs[offset&0x1f], cpu_get_pc( space->cpu ));
343      return ioc_regs[offset&0x1f];
344   }
345   #ifdef MESS
346   else if (offset >= 0xc4000 && offset <= 0xc4010)
347   {
348      logerror("17XX: R @ addr %x mask %08x\n", offset*4, mem_mask);
349      return wd17xx_data_r(fdc, offset&0xf);
350   }
351   #endif
352   else
353   {
354      logerror("IOC: R @ %x (mask %08x)\n", (offset*4)+0x3000000, mem_mask);
355   }
356
357
358   return 0;
359}
360
361WRITE32_HANDLER(ioc_w)
362{
363   #ifdef MESS
364   device_config *fdc = (device_config*)devtag_get_device(space->machine, WD1772, "wd1772");
365   #endif
366   if (offset >= 0x80000 && offset < 0xc0000)
367   {
368//      logerror("IOC: W %02x @ reg %s (PC=%x)\n", data&0xff, ioc_regnames[offset&0x1f], cpu_get_pc( space->cpu ));
369
370      switch (offset&0x1f)
371      {
372         case 0:   // I2C bus control
373            logerror("IOC I2C: CLK %d DAT %d\n", (data>>1)&1, data&1);
374            break;
375
376         case 5:    // IRQ clear A
377            ioc_regs[4] &= ~(data&0xff);
378
379            // if that did it, clear the IRQ
380            if (ioc_regs[4] == 0)
381            {
382               cpu_set_input_line(space->machine->cpu[0], ARM_IRQ_LINE, CLEAR_LINE);
383            }
384            break;
385
386         case 16:
387         case 17:
388            ioc_regs[offset&0x1f] = data & 0xff;
389            break;
390
391         case 20:
392         case 21:
393            ioc_regs[offset&0x1f] = data & 0xff;
394            break;
395
396         case 24:
397         case 25:
398            ioc_regs[offset&0x1f] = data & 0xff;
399            break;
400
401         case 28:
402         case 29:
403            ioc_regs[offset&0x1f] = data & 0xff;
404            break;
405
406         case 19:   // Timer 0 latch
407            latch_timer_cnt(0);
408            break;
409
410         case 23:   // Timer 1 latch
411            latch_timer_cnt(1);
412            break;
413
414         case 27:   // Timer 2 latch
415            latch_timer_cnt(2);
416            break;
417
418         case 31:   // Timer 3 latch
419            latch_timer_cnt(3);
420            break;
421
422         case 18:   // Timer 0 start
423            ioc_timercnt[0] = ioc_regs[17]<<8 | ioc_regs[16];
424            a310_set_timer(0);
425            break;
426
427         case 22:   // Timer 1 start
428            ioc_timercnt[1] = ioc_regs[21]<<8 | ioc_regs[20];
429            a310_set_timer(1);
430            break;
431
432         case 26:   // Timer 2 start
433            ioc_timercnt[2] = ioc_regs[25]<<8 | ioc_regs[24];
434            a310_set_timer(2);
435            break;
436
437         case 30:   // Timer 3 start
438            ioc_timercnt[3] = ioc_regs[29]<<8 | ioc_regs[28];
439            a310_set_timer(3);
440            break;
441
442         default:
443            ioc_regs[offset&0x1f] = data & 0xff;
444            break;
445      }
446   }
447   #ifdef MESS
448   else if (offset >= 0xc4000 && offset <= 0xc4010)
449   {
450      logerror("17XX: %x to addr %x mask %08x\n", data, offset*4, mem_mask);
451      wd17xx_data_w(fdc, offset&0xf, data&0xff);
452   }
453   else if (offset == 0xd40006)
454   {
455      // latch A
456      if (data & 1)
457      {
458         wd17xx_set_drive(fdc,0);
459      }
460      if (data & 2)
461      {
462         wd17xx_set_drive(fdc,1);
463      }
464      if (data & 4)
465      {
466         wd17xx_set_drive(fdc,2);
467      }
468      if (data & 8)
469      {
470         wd17xx_set_drive(fdc,3);
471      }
472
473      wd17xx_set_side(fdc,(data & 0x10)>>4);
474
475   }
476   else if (offset == 0xd40010)
477   {
478      // latch B
479      wd17xx_set_density(fdc,(data & 2) ? DEN_MFM_LO : DEN_MFM_HI);
480   }
481   #endif
482   else
483   {
484      logerror("I/O: W %x @ %x (mask %08x)\n", data, (offset*4)+0x3000000, mem_mask);
485   }
486}
487
488READ32_HANDLER(vidc_r)
489{
490   return 0;
491}
492
493WRITE32_HANDLER(vidc_w)
494{
495   UINT32 reg = data>>24;
496   UINT32 val = data & 0xffffff;
497   #ifdef DEBUG
498   static const char *const vrnames[] =
499   {
500      "horizontal total",
501      "horizontal sync width",
502      "horizontal border start",
503      "horizontal display start",
504      "horizontal display end",
505      "horizontal border end",
506      "horizontal cursor start",
507      "horizontal interlace",
508      "vertical total",
509      "vertical sync width",
510      "vertical border start",
511      "vertical display start",
512      "vertical display end",
513      "vertical border end",
514      "vertical cursor start",
515      "vertical cursor end",
516   };
517   #endif
518
519   if (reg >= 0x80 && reg <= 0xbc)
520   {
521      #ifdef DEBUG
522      logerror("VIDC: %s = %d\n", vrnames[(reg-0x80)/4], val>>12);
523      #endif
524
525      if ((reg == 0xb0) & ((val>>12) != 0))
526      {
527         rectangle visarea;
528
529         visarea.min_x = 0;
530         visarea.min_y = 0;
531         visarea.max_x = vidc_regs[0x94] - vidc_regs[0x88];
532         visarea.max_y = vidc_regs[0xb4] - vidc_regs[0xa8];
533
534         logerror("Configuring: htotal %d vtotal %d vis %d,%d\n",
535            vidc_regs[0x80], vidc_regs[0xa0],
536            visarea.max_x, visarea.max_y);
537
538         video_screen_configure(space->machine->primary_screen, vidc_regs[0x80], vidc_regs[0xa0], &visarea, video_screen_get_frame_period(space->machine->primary_screen).attoseconds);
539
540         // slightly hacky: fire off a VBL right now.  the BIOS doesn't wait long enough otherwise.
541         timer_adjust_oneshot(vbl_timer, attotime_zero, 0);
542      }
543
544      vidc_regs[reg] = val>>12;
545   }
546   else
547   {
548      logerror("VIDC: %x to register %x\n", val, reg);
549      vidc_regs[reg] = val&0xffff;
550   }
551}
552
553READ32_HANDLER(memc_r)
554{
555   return 0;
556}
557
558WRITE32_HANDLER(memc_w)
559{
560   // is it a register?
561   if ((data & 0x0fe00000) == 0x03600000)
562   {
563      switch ((data >> 17) & 7)
564      {
565         case 4:   /* sound start */
566            vidc_sndstart = ((data>>2)&0x7fff)*16;
567            break;
568
569         case 5: /* sound end */
570            vidc_sndend = ((data>>2)&0x7fff)*16;
571            break;
572
573         case 7:   /* Control */
574            memc_pagesize = ((data>>2) & 3);
575
576            logerror("MEMC: %x to Control (page size %d, %s, %s)\n", data & 0x1ffc, page_sizes[memc_pagesize], ((data>>10)&1) ? "Video DMA on" : "Video DMA off", ((data>>11)&1) ? "Sound DMA on" : "Sound DMA off");
577
578            if ((data>>11)&1)
579            {
580               double sndhz;
581
582               sndhz = 250000.0 / (double)((vidc_regs[0xc0]&0xff)+2);
583
584               logerror("MEMC: Starting audio DMA at %f Hz, buffer from %x to %x\n", sndhz, vidc_sndstart, vidc_sndend);
585
586               vidc_sndcur = vidc_sndstart;
587
588               timer_adjust_periodic(snd_timer, ATTOTIME_IN_HZ(sndhz), 0, ATTOTIME_IN_HZ(sndhz));
589            }
590            else
591            {
592               timer_adjust_oneshot(snd_timer, attotime_never, 0);
593               dac_signed_data_w(0, 0x80);
594            }
595            break;
596
597         default:
598            logerror("MEMC: %x to Unk reg %d\n", data&0x1ffff, (data >> 17) & 7);
599            break;
600      }
601   }
602   else
603   {
604      logerror("MEMC non-reg: W %x @ %x (mask %08x)\n", data, offset, mem_mask);
605   }
606}
607
608/*
609      22 2222 1111 1111 1100 0000 0000
610          54 3210 9876 5432 1098 7654 3210
6114k  page: 11 1LLL LLLL LLLL LLAA MPPP PPPP
6128k  page: 11 1LLL LLLL LLLM LLAA MPPP PPPP
61316k page: 11 1LLL LLLL LLxM LLAA MPPP PPPP
61432k page: 11 1LLL LLLL LxxM LLAA MPPP PPPP
615       3   8    2   9    0    f    f
616
617L - logical page
618P - physical page
619A - access permissions
620M - MEMC number (for machines with multiple MEMCs)
621
622The logical page is encoded with bits 11+10 being the most significant bits
623(in that order), and the rest being bit 22 down.
624
625The physical page is encoded differently depending on the page size :
626
6274k  page:   bits 6-0 being bits 6-0
6288k  page:   bits 6-1 being bits 5-0, bit 0 being bit 6
62916k page:   bits 6-2 being bits 4-0, bits 1-0 being bits 6-5
63032k page:   bits 6-3 being bits 4-0, bit 0 being bit 4, bit 2 being bit 5, bit
631            1 being bit 6
632*/
633
634WRITE32_HANDLER(memc_page_w)
635{
636   UINT32 log, phys, memc, perms;
637
638   perms = (data & 0x300)>>8;
639   log = phys = memc = 0;
640
641   switch (memc_pagesize)
642   {
643      case 0:
644         phys = data & 0x7f;
645         log = (data & 0xc00)>>10;
646         log <<= 23;
647         log |= (data & 0x7ff000);
648         memc = (data & 0x80) ? 1 : 0;
649         break;
650
651      case 1:
652         phys = ((data & 0x7f) >> 1) | (data & 1) ? 0x40 : 0;
653         log = (data & 0xc00)>>10;
654         log <<= 23;
655         log |= (data & 0x7fe000);
656         memc = ((data & 0x80) ? 1 : 0) | ((data & 0x1000) ? 2 : 0);
657         break;
658
659      case 2:
660         phys = ((data & 0x7f) >> 2) | ((data & 3) << 5);
661         log = (data & 0xc00)>>10;
662         log <<= 23;
663         log |= (data & 0x7fc000);
664         memc = ((data & 0x80) ? 1 : 0) | ((data & 0x1000) ? 2 : 0);
665         break;
666
667      case 3:
668         phys = ((data & 0x7f) >> 3) | (data & 1)<<4 | (data & 2) << 5 | (data & 4)<<3;
669         log = (data & 0xc00)>>10;
670         log <<= 23;
671         log |= (data & 0x7f8000);
672         memc = ((data & 0x80) ? 1 : 0) | ((data & 0x1000) ? 2 : 0);
673         break;
674   }
675
676   log >>= (12 + memc_pagesize);
677
678   // always make sure ROM mode is disconnected when this occurs
679   memc_latchrom = 0;
680
681   // now go ahead and set the mapping in the page table
682   memc_pages[log] = phys * memc;
683
684//  printf("MEMC_PAGE(%d): W %08x: log %x to phys %x, MEMC %d, perms %d\n", memc_pagesize, data, log, phys, memc, perms);
685}
686
src/mame/includes/archimds.h
r0r4195
1/******************************************************************************
2 *
3 *  Acorn Archimedes custom chips (IOC, MEMC, VIDC)
4 *
5 *****************************************************************************/
6
7#ifndef _ARCHIMEDES_H_
8#define _ARCHIMEDES_H_
9
10// interrupt definitions.  these are for the real Archimedes computer - arcade
11// and gambling knockoffs likely are a bit different.
12
13#define ARCHIMEDES_IRQA_PRINTER_BUSY (0x01)
14#define ARCHIMEDES_IRQA_SERIAL_RING  (0x02)
15#define ARCHIMEDES_IRQA_PRINTER_ACK  (0x04)
16#define ARCHIMEDES_IRQA_VBL          (0x08)
17#define ARCHIMEDES_IRQA_RESET        (0x10)
18#define ARCHIMEDES_IRQA_TIMER0       (0x20)
19#define ARCHIMEDES_IRQA_TIMER1       (0x40)
20#define ARCHIMEDES_IRQA_ALWAYS       (0x80)
21
22#define ARCHIMEDES_IRQB_PODULE_FIQ   (0x01)
23#define ARCHIMEDES_IRQB_SOUND_EMPTY  (0x02)
24#define ARCHIMEDES_IRQB_SERIAL       (0x04)
25#define ARCHIMEDES_IRQB_HDD          (0x08)
26#define ARCHIMEDES_IRQB_DISC_CHANGE  (0x10)
27#define ARCHIMEDES_IRQB_PODULE_IRQ   (0x20)
28#define ARCHIMEDES_IRQB_KBD_XMIT_EMPTY  (0x40)
29#define ARCHIMEDES_IRQB_KBD_RECV_FULL   (0x80)
30
31#define ARCHIMEDES_FIQ_FLOPPY_DRQ    (0x01)
32#define ARCHIMEDES_FIQ_FLOPPY        (0x02)
33#define ARCHIMEDES_FIQ_ECONET        (0x04)
34#define ARCHIMEDES_FIQ_PODULE        (0x40)
35#define ARCHIMEDES_FIQ_FORCE         (0x80)
36
37extern UINT32 *memc_physmem;
38
39void archimedes_init(running_machine *machine);         // call at MACHINE_INIT
40void archimedes_reset(running_machine *machine);      // call at MACHINE_RESET
41void archimedes_driver_init(running_machine *machine);      // call at DRIVER_INIT
42
43void archimedes_request_irq_a(running_machine *machine, int mask);
44void archimedes_request_irq_b(running_machine *machine, int mask);
45void archimedes_request_fiq(running_machine *machine, int mask);
46void archimedes_clear_irq_a(running_machine *machine, int mask);
47void archimedes_clear_irq_b(running_machine *machine, int mask);
48void archimedes_clear_fiq(running_machine *machine, int mask);
49
50extern READ32_HANDLER(memc_logical_r);
51extern WRITE32_HANDLER(memc_logical_w);
52extern READ32_HANDLER(memc_r);
53extern WRITE32_HANDLER(memc_w);
54extern WRITE32_HANDLER(memc_page_w);
55extern READ32_HANDLER(ioc_r);
56extern WRITE32_HANDLER(ioc_w);
57extern READ32_HANDLER(vidc_r);
58extern WRITE32_HANDLER(vidc_w);
59
60#endif   // _ARCHIMEDES_H_
src/mess/mess.mak
r4194r4195
10111011   $(MESS_DRIVERS)/bbc.o        \
10121012   $(MESS_DRIVERS)/bbcbc.o        \
10131013   $(MESS_DRIVERS)/a310.o    \
1014   $(MAME_MACHINE)/archimds.o \
10141015   $(MESS_DRIVERS)/z88.o        \
10151016   $(MESS_VIDEO)/z88.o      \
10161017   $(MESS_VIDEO)/atom.o    \
src/mess/drivers/a310.c
r4194r4195
3434#include "devices/basicdsk.h"
3535#include "cpu/arm/arm.h"
3636#include "sound/dac.h"
37#include "includes/archimds.h"
3738
38
39// interrupt register stuff
40#define A310_IRQA_PRINTER_BUSY (0x01)
41#define A310_IRQA_SERIAL_RING  (0x02)
42#define A310_IRQA_PRINTER_ACK  (0x04)
43#define A310_IRQA_VBL          (0x08)
44#define A310_IRQA_RESET        (0x10)
45#define A310_IRQA_TIMER0       (0x20)
46#define A310_IRQA_TIMER1       (0x40)
47#define A310_IRQA_ALWAYS       (0x80)
48
49#define A310_IRQB_PODULE_FIQ   (0x01)
50#define A310_IRQB_SOUND_EMPTY  (0x02)
51#define A310_IRQB_SERIAL       (0x04)
52#define A310_IRQB_HDD          (0x08)
53#define A310_IRQB_DISC_CHANGE  (0x10)
54#define A310_IRQB_PODULE_IRQ   (0x20)
55#define A310_IRQB_KBD_XMIT_EMPTY  (0x40)
56#define A310_IRQB_KBD_RECV_FULL   (0x80)
57
58#define A310_FIQ_FLOPPY_DRQ    (0x01)
59#define A310_FIQ_FLOPPY        (0x02)
60#define A310_FIQ_ECONET        (0x04)
61#define A310_FIQ_PODULE        (0x40)
62#define A310_FIQ_FORCE         (0x80)
63
64static const int page_sizes[4] = { 4096, 8192, 16384, 32768 };
65
66static UINT32 *a310_physmem;
67static UINT32 a310_pagesize;
68static int a310_latchrom;
69static INT16 a310_pages[(32*1024*1024)/(4096)];   // the logical RAM area is 32 megs, and the smallest page size is 4k
70static UINT32 a310_vidregs[256];
71static UINT8 a310_iocregs[0x80/4];
72static UINT32 a310_timercnt[4], a310_timerout[4];
73static UINT32 a310_sndstart, a310_sndend, a310_sndcur;
74
75static emu_timer *vbl_timer, *timer[4], *snd_timer;
76
7739static VIDEO_START( a310 )
7840{
7941}
r4194r4195
8345   return 0;
8446}
8547
86static void a310_request_irq_a(running_machine *machine, int mask)
87{
88   a310_iocregs[4] |= mask;
89
90   if (a310_iocregs[6] & mask)
91   {
92      cpu_set_input_line(machine->cpu[0], ARM_IRQ_LINE, ASSERT_LINE);
93   }
94}
95
96static void a310_request_irq_b(running_machine *machine, int mask)
97{
98   a310_iocregs[8] |= mask;
99
100   if (a310_iocregs[10] & mask)
101   {
102      cpu_set_input_line(machine->cpu[0], ARM_IRQ_LINE, PULSE_LINE);
103   }
104}
105
106static void a310_request_fiq(running_machine *machine, int mask)
107{
108   a310_iocregs[12] |= mask;
109
110   if (a310_iocregs[14] & mask)
111   {
112      cpu_set_input_line(machine->cpu[0], ARM_FIRQ_LINE, PULSE_LINE);
113   }
114}
115
116static TIMER_CALLBACK( a310_audio_tick )
117{
118   a310_sndcur++;
119
120   if (a310_sndcur >= a310_sndend)
121   {
122      a310_request_irq_b(machine, A310_IRQB_SOUND_EMPTY);
123   }
124}
125
126static TIMER_CALLBACK( a310_vblank )
127{
128   a310_request_irq_a(machine, A310_IRQA_VBL);
129
130   // set up for next vbl
131   timer_adjust_oneshot(vbl_timer, video_screen_get_time_until_pos(machine->primary_screen, a310_vidregs[0xb4], 0), 0);
132}
133
134static void a310_set_timer(int tmr)
135{
136   double freq = 2000000.0 / (double)a310_timercnt[tmr];
137
138//  logerror("IOC: starting timer %d, %d ticks, freq %f Hz\n", tmr, a310_timercnt[tmr], freq);
139
140   timer_adjust_oneshot(timer[tmr], ATTOTIME_IN_HZ(freq), tmr);
141}
142
143// param
144static TIMER_CALLBACK( a310_timer )
145{
146   // all timers always run
147   a310_set_timer(param);
148
149   // but only timers 0 and 1 generate IRQs
150   switch (param)
151   {
152      case 0:
153         a310_request_irq_a(machine, A310_IRQA_TIMER0);
154         break;
155
156      case 1:
157         a310_request_irq_a(machine, A310_IRQA_TIMER1);
158         break;
159   }
160}
161
162static void a310_memc_reset(void)
163{
164   int i;
165
166   a310_latchrom = 1;         // map in the boot ROM
167
168   // kill all memc mappings
169   for (i = 0; i < (32*1024*1024)/(4096); i++)
170   {
171      a310_pages[i] = -1;      // indicate unmapped
172   }
173}
174
175static MACHINE_RESET( a310 )
176{
177   a310_memc_reset();
178}
179
18048static WD17XX_CALLBACK ( a310_wd177x_callback )
18149{
18250   switch (state)
18351   {
18452      case WD17XX_IRQ_CLR:
185         a310_iocregs[12] &= ~A310_FIQ_FLOPPY;
53         archimedes_clear_fiq(device->machine, ARCHIMEDES_FIQ_FLOPPY);
18654         break;
18755
18856      case WD17XX_IRQ_SET:
189         a310_request_fiq(device->machine, A310_FIQ_FLOPPY);
57         archimedes_request_fiq(device->machine, ARCHIMEDES_FIQ_FLOPPY);
19058         break;
19159
19260      case WD17XX_DRQ_CLR:
193         a310_iocregs[12] &= ~A310_FIQ_FLOPPY_DRQ;
61         archimedes_clear_fiq(device->machine, ARCHIMEDES_FIQ_FLOPPY_DRQ);
19462         break;
19563
19664      case WD17XX_DRQ_SET:
197         a310_request_fiq(device->machine, A310_FIQ_FLOPPY_DRQ);
65         archimedes_request_fiq(device->machine, ARCHIMEDES_FIQ_FLOPPY_DRQ);
19866         break;
19967   }
20068}
20169
70static DRIVER_INIT(a310)
71{
72   archimedes_driver_init(machine);
73}
20274
20375static MACHINE_START( a310 )
20476{
205   a310_pagesize = 0;
77   archimedes_init(machine);
20678
207   vbl_timer = timer_alloc(machine, a310_vblank, NULL);
208   timer_adjust_oneshot(vbl_timer, attotime_never, 0);
209
210   timer[0] = timer_alloc(machine, a310_timer, NULL);
211   timer[1] = timer_alloc(machine, a310_timer, NULL);
212   timer[2] = timer_alloc(machine, a310_timer, NULL);
213   timer[3] = timer_alloc(machine, a310_timer, NULL);
214   timer_adjust_oneshot(timer[0], attotime_never, 0);
215   timer_adjust_oneshot(timer[1], attotime_never, 0);
216   timer_adjust_oneshot(timer[2], attotime_never, 0);
217   timer_adjust_oneshot(timer[3], attotime_never, 0);
218
219   snd_timer = timer_alloc(machine, a310_audio_tick, NULL);
220   timer_adjust_oneshot(snd_timer, attotime_never, 0);
221
22279   // reset the DAC to centerline
22380   dac_signed_data_w(0, 0x80);
22481}
22582
226static READ32_HANDLER(logical_r)
83static MACHINE_RESET( a310 )
22784{
228   UINT32 page, poffs;
229
230   // are we mapping in the boot ROM?
231   if (a310_latchrom)
232   {
233      UINT32 *rom;
234
235      rom = (UINT32 *)memory_region(space->machine, "main");
236
237      return rom[offset & 0x1fffff];
238   }
239   else
240   {
241      // figure out the page number and offset in the page
242      page = (offset<<2) / page_sizes[a310_pagesize];
243      poffs = (offset<<2) % page_sizes[a310_pagesize];
244
245//      printf("Reading offset %x (addr %x): page %x (size %d %d) offset %x ==> %x %x\n", offset, offset<<2, page, a310_pagesize, page_sizes[a310_pagesize], poffs, a310_pages[page], a310_pages[page]*page_sizes[a310_pagesize]);
246
247      if (a310_pages[page] != -1)
248      {
249         return a310_physmem[((a310_pages[page] * page_sizes[a310_pagesize]) + poffs)>>2];
250      }
251      else
252      {
253         printf("A310_MEMC: Reading unmapped page, what do we do?\n");
254      }
255   }
256
257   return 0;
85   archimedes_reset(machine);
25886}
25987
260static WRITE32_HANDLER(logical_w)
261{
262   UINT32 page, poffs;
263
264   // if the boot ROM is mapped, ignore writes
265   if (a310_latchrom)
266   {
267      return;
268   }
269   else
270   {
271      // figure out the page number and offset in the page
272      page = (offset<<2) / page_sizes[a310_pagesize];
273      poffs = (offset<<2) % page_sizes[a310_pagesize];
274
275//      printf("Writing offset %x (addr %x): page %x (size %d %d) offset %x ==> %x %x\n", offset, offset<<2, page, a310_pagesize, page_sizes[a310_pagesize], poffs, a310_pages[page], a310_pages[page]*page_sizes[a310_pagesize]);
276
277      if (a310_pages[page] != -1)
278      {
279         COMBINE_DATA(&a310_physmem[((a310_pages[page] * page_sizes[a310_pagesize]) + poffs)>>2]);
280      }
281      else
282      {
283         printf("A310_MEMC: Writing unmapped page, what do we do?\n");
284      }
285   }
286}
287
288static DIRECT_UPDATE_HANDLER( a310_setopbase )
289{
290   // if we're not in logical memory, MAME can do the right thing
291   if (address > 0x1ffffff)
292   {
293      return address;
294   }
295
296   // if the boot ROM is mapped in, do some trickery to make it show up
297   if (a310_latchrom)
298   {
299      direct->bytemask = 0x1fffff;
300      direct->bytestart = 0;
301      direct->byteend = 0x1fffff;
302      direct->raw = direct->decrypted = memory_region(space->machine, "main");
303   }
304   else   // executing from logical memory
305   {
306      UINT32 page = address / page_sizes[a310_pagesize];
307
308      direct->bytemask = page_sizes[a310_pagesize]-1;
309      direct->bytestart = page * page_sizes[a310_pagesize];
310      direct->byteend = direct->bytestart + direct->bytemask;
311      direct->raw = direct->decrypted = (UINT8 *)&a310_physmem[(a310_pages[page] * page_sizes[a310_pagesize])>>2];
312   }
313
314   return ~0;
315}
316
317static DRIVER_INIT(a310)
318{
319   memory_set_direct_update_handler( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), a310_setopbase);
320}
321
322static const char *const ioc_regnames[] =
323{
324   "(rw) Control",               // 0
325   "(read) Keyboard receive (write) keyboard send",   // 1
326   "?",
327   "?",
328   "(read) IRQ status A",               // 4
329   "(read) IRQ request A (write) IRQ clear",   // 5
330   "(rw) IRQ mask A",            // 6
331   "?",
332   "(read) IRQ status B",      // 8
333   "(read) IRQ request B",      // 9
334   "(rw) IRQ mask B",      // 10
335   "?",
336   "(read) FIQ status",      // 12
337   "(read) FIQ request",      // 13
338   "(rw) FIQ mask",      // 14
339   "?",
340   "(read) Timer 0 count low (write) Timer 0 latch low",      // 16
341   "(read) Timer 0 count high (write) Timer 0 latch high",      // 17
342   "(write) Timer 0 go command",               // 18
343   "(write) Timer 0 latch command",            // 19
344   "(read) Timer 1 count low (write) Timer 1 latch low",      // 20
345   "(read) Timer 1 count high (write) Timer 1 latch high",      // 21
346   "(write) Timer 1 go command",               // 22
347   "(write) Timer 1 latch command",            // 23
348   "(read) Timer 2 count low (write) Timer 2 latch low",      // 24
349   "(read) Timer 2 count high (write) Timer 2 latch high",      // 25
350   "(write) Timer 2 go command",               // 26
351   "(write) Timer 2 latch command",            // 27
352   "(read) Timer 3 count low (write) Timer 3 latch low",      // 28
353   "(read) Timer 3 count high (write) Timer 3 latch high",      // 29
354   "(write) Timer 3 go command",               // 30
355   "(write) Timer 3 latch command"               // 31
356};
357
358static void latch_timer_cnt(int tmr)
359{
360   double time = attotime_to_double(timer_timeelapsed(timer[tmr]));
361   time *= 2000000.0;   // find out how many 2 MHz ticks have gone by
362   a310_timerout[tmr] = a310_timercnt[tmr] - (UINT32)time;
363}
364
365static READ32_HANDLER(ioc_r)
366{
367   device_config *fdc = (device_config*)devtag_get_device(space->machine, WD1772, "wd1772");
368   if (offset >= 0x80000 && offset < 0xc0000)
369   {
370      switch (offset & 0x1f)
371      {
372         case 1:   // keyboard read
373            a310_request_irq_b(space->machine, A310_IRQB_KBD_XMIT_EMPTY);
374            break;
375
376         case 16:   // timer 0 read
377            return a310_timerout[0]&0xff;
378         case 17:
379            return (a310_timerout[0]>>8)&0xff;
380         case 20:   // timer 1 read
381            return a310_timerout[1]&0xff;
382         case 21:
383            return (a310_timerout[1]>>8)&0xff;
384         case 24:   // timer 2 read
385            return a310_timerout[2]&0xff;
386         case 25:
387            return (a310_timerout[2]>>8)&0xff;
388         case 28:   // timer 3 read
389            return a310_timerout[3]&0xff;
390         case 29:
391            return (a310_timerout[3]>>8)&0xff;
392      }
393
394      logerror("IOC: R %s = %02x (PC=%x)\n", ioc_regnames[offset&0x1f], a310_iocregs[offset&0x1f], cpu_get_pc( space->cpu ));
395      return a310_iocregs[offset&0x1f];
396   }
397   else if (offset >= 0xc4000 && offset <= 0xc4010)
398   {
399      logerror("17XX: R @ addr %x mask %08x\n", offset*4, mem_mask);
400      return wd17xx_data_r(fdc, offset&0xf);
401   }
402   else
403   {
404      logerror("I/O: R @ %x (mask %08x)\n", (offset*4)+0x3000000, mem_mask);
405   }
406
407
408   return 0;
409}
410
411static WRITE32_HANDLER(ioc_w)
412{
413   device_config *fdc = (device_config*)devtag_get_device(space->machine, WD1772, "wd1772");
414   if (offset >= 0x80000 && offset < 0xc0000)
415   {
416//      logerror("IOC: W %02x @ reg %s (PC=%x)\n", data&0xff, ioc_regnames[offset&0x1f], cpu_get_pc( space->cpu ));
417
418      switch (offset&0x1f)
419      {
420         case 0:   // control
421            logerror("IOC I2C: CLK %d DAT %d\n", (data>>1)&1, data&1);
422            break;
423
424         case 5:    // IRQ clear A
425            a310_iocregs[4] &= ~(data&0xff);
426
427            // if that did it, clear the IRQ
428            if (a310_iocregs[4] == 0)
429            {
430               cpu_set_input_line(space->machine->cpu[0], ARM_IRQ_LINE, CLEAR_LINE);
431            }
432            break;
433
434         case 16:
435         case 17:
436            a310_iocregs[offset&0x1f] = data & 0xff;
437            break;
438
439         case 20:
440         case 21:
441            a310_iocregs[offset&0x1f] = data & 0xff;
442            break;
443
444         case 24:
445         case 25:
446            a310_iocregs[offset&0x1f] = data & 0xff;
447            break;
448
449         case 28:
450         case 29:
451            a310_iocregs[offset&0x1f] = data & 0xff;
452            break;
453
454         case 19:   // Timer 0 latch
455            latch_timer_cnt(0);
456            break;
457
458         case 23:   // Timer 1 latch
459            latch_timer_cnt(1);
460            break;
461
462         case 27:   // Timer 2 latch
463            latch_timer_cnt(2);
464            break;
465
466         case 31:   // Timer 3 latch
467            latch_timer_cnt(3);
468            break;
469
470         case 18:   // Timer 0 start
471            a310_timercnt[0] = a310_iocregs[17]<<8 | a310_iocregs[16];
472            a310_set_timer(0);
473            break;
474
475         case 22:   // Timer 1 start
476            a310_timercnt[1] = a310_iocregs[21]<<8 | a310_iocregs[20];
477            a310_set_timer(1);
478            break;
479
480         case 26:   // Timer 2 start
481            a310_timercnt[2] = a310_iocregs[25]<<8 | a310_iocregs[24];
482            a310_set_timer(2);
483            break;
484
485         case 30:   // Timer 3 start
486            a310_timercnt[3] = a310_iocregs[29]<<8 | a310_iocregs[28];
487            a310_set_timer(3);
488            break;
489
490         default:
491            a310_iocregs[offset&0x1f] = data & 0xff;
492            break;
493      }
494   }
495   else if (offset >= 0xc4000 && offset <= 0xc4010)
496   {
497      logerror("17XX: %x to addr %x mask %08x\n", data, offset*4, mem_mask);
498      wd17xx_data_w(fdc, offset&0xf, data&0xff);
499   }
500   else if (offset == 0xd40006)
501   {
502      // latch A
503      if (data & 1)
504      {
505         wd17xx_set_drive(fdc,0);
506      }
507      if (data & 2)
508      {
509         wd17xx_set_drive(fdc,1);
510      }
511      if (data & 4)
512      {
513         wd17xx_set_drive(fdc,2);
514      }
515      if (data & 8)
516      {
517         wd17xx_set_drive(fdc,3);
518      }
519
520      wd17xx_set_side(fdc,(data & 0x10)>>4);
521
522   }
523   else if (offset == 0xd40010)
524   {
525      // latch B
526      wd17xx_set_density(fdc,(data & 2) ? DEN_MFM_LO : DEN_MFM_HI);
527   }
528   else
529   {
530      logerror("I/O: W %x @ %x (mask %08x)\n", data, (offset*4)+0x3000000, mem_mask);
531   }
532}
533
534static READ32_HANDLER(vidc_r)
535{
536   return 0;
537}
538
539static WRITE32_HANDLER(vidc_w)
540{
541   UINT32 reg = data>>24;
542   UINT32 val = data & 0xffffff;
543   static const char *const vrnames[] =
544   {
545      "horizontal total",
546      "horizontal sync width",
547      "horizontal border start",
548      "horizontal display start",
549      "horizontal display end",
550      "horizontal border end",
551      "horizontal cursor start",
552      "horizontal interlace",
553      "vertical total",
554      "vertical sync width",
555      "vertical border start",
556      "vertical display start",
557      "vertical display end",
558      "vertical border end",
559      "vertical cursor start",
560      "vertical cursor end",
561   };
562
563   if (reg >= 0x80 && reg <= 0xbc)
564   {
565      logerror("VIDC: %s = %d\n", vrnames[(reg-0x80)/4], val>>12);
566
567      if ((reg == 0xb0) & ((val>>12) != 0))
568      {
569         rectangle visarea;
570
571         visarea.min_x = 0;
572         visarea.min_y = 0;
573         visarea.max_x = a310_vidregs[0x94] - a310_vidregs[0x88];
574         visarea.max_y = a310_vidregs[0xb4] - a310_vidregs[0xa8];
575
576         logerror("Configuring: htotal %d vtotal %d vis %d,%d\n",
577            a310_vidregs[0x80], a310_vidregs[0xa0],
578            visarea.max_x, visarea.max_y);
579
580         video_screen_configure(space->machine->primary_screen, a310_vidregs[0x80], a310_vidregs[0xa0], &visarea, video_screen_get_frame_period(space->machine->primary_screen).attoseconds);
581
582         // slightly hacky: fire off a VBL right now.  the BIOS doesn't wait long enough otherwise.
583         timer_adjust_oneshot(vbl_timer, attotime_zero, 0);
584      }
585
586      a310_vidregs[reg] = val>>12;
587   }
588   else
589   {
590      logerror("VIDC: %x to register %x\n", val, reg);
591      a310_vidregs[reg] = val&0xffff;
592   }
593}
594
595static READ32_HANDLER(memc_r)
596{
597   return 0;
598}
599
600static WRITE32_HANDLER(memc_w)
601{
602   // is it a register?
603   if ((data & 0x0fe00000) == 0x03600000)
604   {
605      switch ((data >> 17) & 7)
606      {
607         case 4:   /* sound start */
608            a310_sndstart = ((data>>2)&0x7fff)*16;
609            break;
610
611         case 5: /* sound end */
612            a310_sndend = ((data>>2)&0x7fff)*16;
613            break;
614
615         case 7:   /* Control */
616            a310_pagesize = ((data>>2) & 3);
617
618            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");
619
620            if ((data>>11)&1)
621            {
622               double sndhz;
623
624               sndhz = 250000.0 / (double)((a310_vidregs[0xc0]&0xff)+2);
625
626               logerror("MEMC: Starting audio DMA at %f Hz, buffer from %x to %x\n", sndhz, a310_sndstart, a310_sndend);
627
628               a310_sndcur = a310_sndstart;
629
630               timer_adjust_periodic(snd_timer, ATTOTIME_IN_HZ(sndhz), 0, ATTOTIME_IN_HZ(sndhz));
631            }
632            else
633            {
634               timer_adjust_oneshot(snd_timer, attotime_never, 0);
635               dac_signed_data_w(0, 0x80);
636            }
637            break;
638
639         default:
640            logerror("MEMC: %x to Unk reg %d\n", data&0x1ffff, (data >> 17) & 7);
641            break;
642      }
643   }
644   else
645   {
646      logerror("MEMC non-reg: W %x @ %x (mask %08x)\n", data, offset, mem_mask);
647   }
648}
649
650/*
651      22 2222 1111 1111 1100 0000 0000
652          54 3210 9876 5432 1098 7654 3210
6534k  page: 11 1LLL LLLL LLLL LLAA MPPP PPPP
6548k  page: 11 1LLL LLLL LLLM LLAA MPPP PPPP
65516k page: 11 1LLL LLLL LLxM LLAA MPPP PPPP
65632k page: 11 1LLL LLLL LxxM LLAA MPPP PPPP
657       3   8    2   9    0    f    f
658
659L - logical page
660P - physical page
661A - access permissions
662M - MEMC number (for machines with multiple MEMCs)
663
664The logical page is encoded with bits 11+10 being the most significant bits
665(in that order), and the rest being bit 22 down.
666
667The physical page is encoded differently depending on the page size :
668
6694k  page:   bits 6-0 being bits 6-0
6708k  page:   bits 6-1 being bits 5-0, bit 0 being bit 6
67116k page:   bits 6-2 being bits 4-0, bits 1-0 being bits 6-5
67232k page:   bits 6-3 being bits 4-0, bit 0 being bit 4, bit 2 being bit 5, bit
673            1 being bit 6
674*/
675
676static WRITE32_HANDLER(memc_page_w)
677{
678   UINT32 log, phys, memc, perms;
679
680   perms = (data & 0x300)>>8;
681   log = phys = memc = 0;
682
683   switch (a310_pagesize)
684   {
685      case 0:
686         phys = data & 0x7f;
687         log = (data & 0xc00)>>10;
688         log <<= 23;
689         log |= (data & 0x7ff000);
690         memc = (data & 0x80) ? 1 : 0;
691         break;
692
693      case 1:
694         phys = ((data & 0x7f) >> 1) | (data & 1) ? 0x40 : 0;
695         log = (data & 0xc00)>>10;
696         log <<= 23;
697         log |= (data & 0x7fe000);
698         memc = ((data & 0x80) ? 1 : 0) | ((data & 0x1000) ? 2 : 0);
699         break;
700
701      case 2:
702         phys = ((data & 0x7f) >> 2) | ((data & 3) << 5);
703         log = (data & 0xc00)>>10;
704         log <<= 23;
705         log |= (data & 0x7fc000);
706         memc = ((data & 0x80) ? 1 : 0) | ((data & 0x1000) ? 2 : 0);
707         break;
708
709      case 3:
710         phys = ((data & 0x7f) >> 3) | (data & 1)<<4 | (data & 2) << 5 | (data & 4)<<3;
711         log = (data & 0xc00)>>10;
712         log <<= 23;
713         log |= (data & 0x7f8000);
714         memc = ((data & 0x80) ? 1 : 0) | ((data & 0x1000) ? 2 : 0);
715         break;
716   }
717
718   log >>= (12 + a310_pagesize);
719
720   // always make sure ROM mode is disconnected when this occurs
721   a310_latchrom = 0;
722
723   // now go ahead and set the mapping in the page table
724   a310_pages[log] = phys * memc;
725
726//  printf("MEMC_PAGE(%d): W %08x: log %x to phys %x, MEMC %d, perms %d\n", a310_pagesize, data, log, phys, memc, perms);
727}
728
72988static ADDRESS_MAP_START( a310_mem, ADDRESS_SPACE_PROGRAM, 32 )
730   AM_RANGE(0x00000000, 0x01ffffff) AM_READWRITE(logical_r, logical_w)
731   AM_RANGE(0x02000000, 0x02ffffff) AM_RAM AM_BASE(&a310_physmem) /* physical RAM - 16 MB for now, should be 512k for the A310 */
89   AM_RANGE(0x00000000, 0x01ffffff) AM_READWRITE(memc_logical_r, memc_logical_w)
90   AM_RANGE(0x02000000, 0x02ffffff) AM_RAM AM_BASE(&memc_physmem) /* physical RAM - 16 MB for now, should be 512k for the A310 */
73291   AM_RANGE(0x03000000, 0x033fffff) AM_READWRITE(ioc_r, ioc_w)
73392   AM_RANGE(0x03400000, 0x035fffff) AM_READWRITE(vidc_r, vidc_w)
73493   AM_RANGE(0x03600000, 0x037fffff) AM_READWRITE(memc_r, memc_w)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team