1 // license:BSD-3-Clause
2 // copyright-holders:R. Belmont
3 /****************************************************************************
4
5 drivers/macpwrbk030.cpp
6 Mac PowerBooks with a 68030 CPU and M50753 PMU
7 By R. Belmont
8
9 These are basically late-period Mac IIs without NuBus and with
10 Egret/Cuda replaced with the PMU.
11
12 ****************************************************************************/
13
14 #include "emu.h"
15
16 #include "machine/macrtc.h"
17 #include "cpu/m68000/m68000.h"
18 #include "machine/6522via.h"
19 #include "machine/applefdc.h"
20 #include "machine/ram.h"
21 #include "machine/sonydriv.h"
22 #include "machine/swim.h"
23 #include "machine/timer.h"
24 #include "machine/z80scc.h"
25 #include "machine/macadb.h"
26 #include "machine/ncr5380.h"
27 #include "bus/scsi/scsi.h"
28 #include "bus/scsi/scsihd.h"
29 #include "sound/asc.h"
30 #include "formats/ap_dsk35.h"
31
32 #include "emupal.h"
33 #include "screen.h"
34 #include "softlist.h"
35 #include "speaker.h"
36
37 #define C7M (7833600)
38 #define C15M (C7M*2)
39 #define C32M (C15M*2)
40
41 class macpb030_state : public driver_device
42 {
43 public:
macpb030_state(const machine_config & mconfig,device_type type,const char * tag)44 macpb030_state(const machine_config &mconfig, device_type type, const char *tag) :
45 driver_device(mconfig, type, tag),
46 m_maincpu(*this, "maincpu"),
47 m_via1(*this, "via1"),
48 m_via2(*this, "via2"),
49 m_macadb(*this, "macadb"),
50 m_ncr5380(*this, "ncr5380"),
51 m_ram(*this, RAM_TAG),
52 m_iwm(*this, "fdc"),
53 m_screen(*this, "screen"),
54 m_palette(*this, "palette"),
55 m_asc(*this, "asc"),
56 m_scc(*this, "scc"),
57 m_vram(*this, "vram")
58 {
59 }
60
61 void macpb140(machine_config &config);
62 void macpb145(machine_config &config);
63 void macpb160(machine_config &config);
64 void macpb170(machine_config &config);
65 void macpb180(machine_config &config);
66 void macpb180c(machine_config &config);
67 void macpd210(machine_config &config);
68 void macpb140_map(address_map &map);
69 void macpb160_map(address_map &map);
70 void macpb165c_map(address_map &map);
71 void macpd210_map(address_map &map);
72
73 void init_macpb140();
74 void init_macpb160();
75
76 private:
77 required_device<m68030_device> m_maincpu;
78 required_device<via6522_device> m_via1;
79 required_device<via6522_device> m_via2;
80 required_device<macadb_device> m_macadb;
81 required_device<ncr5380_device> m_ncr5380;
82 required_device<ram_device> m_ram;
83 required_device<applefdc_base_device> m_iwm;
84 required_device<screen_device> m_screen;
85 required_device<palette_device> m_palette;
86 required_device<asc_device> m_asc;
87 required_device<z80scc_device> m_scc;
88 required_shared_ptr<u32> m_vram;
89
90 virtual void machine_start() override;
91 virtual void machine_reset() override;
92
93 u32 screen_update_macpb140(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
94 u32 screen_update_macpb160(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
95 u32 screen_update_macpbwd(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
96
97 u32 *m_ram_ptr, *m_rom_ptr;
98 u32 m_ram_mask, m_ram_size, m_rom_size;
99
100 emu_timer *m_6015_timer;
101
WRITE_LINE_MEMBER(adb_irq_w)102 WRITE_LINE_MEMBER(adb_irq_w) { m_adb_irq_pending = state; }
103 int m_adb_irq_pending;
104
105 u16 mac_via_r(offs_t offset);
106 void mac_via_w(offs_t offset, u16 data, u16 mem_mask);
107 u16 mac_via2_r(offs_t offset);
108 void mac_via2_w(offs_t offset, u16 data, u16 mem_mask);
109 u8 mac_via_in_a();
110 u8 mac_via_in_b();
111 void mac_via_out_a(u8 data);
112 void mac_via_out_b(u8 data);
113 u8 mac_via2_in_a();
114 u8 mac_via2_in_b();
115 void mac_via2_out_a(u8 data);
116 void mac_via2_out_b(u8 data);
117 void field_interrupts();
118 DECLARE_WRITE_LINE_MEMBER(via_irq_w);
119 DECLARE_WRITE_LINE_MEMBER(via2_irq_w);
120 TIMER_CALLBACK_MEMBER(mac_6015_tick);
WRITE_LINE_MEMBER(via_cb2_w)121 WRITE_LINE_MEMBER(via_cb2_w) { m_macadb->adb_data_w(state); }
122 int m_via_cycles, m_via_interrupt, m_via2_interrupt, m_scc_interrupt, m_asc_interrupt, m_last_taken_interrupt;
123 int m_irq_count, m_ca1_data, m_ca2_data;
124
125 u32 rom_switch_r(offs_t offset);
126 bool m_overlay;
127
128 u16 scsi_r(offs_t offset, u16 mem_mask);
129 void scsi_w(offs_t offset, u16 data, u16 mem_mask);
130 uint32_t scsi_drq_r(offs_t offset, uint32_t mem_mask = ~0);
131 void scsi_drq_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
mac_scc_r(offs_t offset)132 u16 mac_scc_r(offs_t offset)
133 {
134 u16 result = m_scc->dc_ab_r(offset);
135 return (result << 8) | result;
136 }
mac_scc_2_w(offs_t offset,u16 data)137 void mac_scc_2_w(offs_t offset, u16 data) { m_scc->dc_ab_w(offset, data >> 8); }
138
mac_iwm_r(offs_t offset,u16 mem_mask)139 u16 mac_iwm_r(offs_t offset, u16 mem_mask)
140 {
141 u16 result = m_iwm->read(offset >> 8);
142 return (result << 8) | result;
143 }
mac_iwm_w(offs_t offset,u16 data,u16 mem_mask)144 void mac_iwm_w(offs_t offset, u16 data, u16 mem_mask)
145 {
146 if (ACCESSING_BITS_0_7)
147 m_iwm->write((offset >> 8), data & 0xff);
148 else
149 m_iwm->write((offset >> 8), data>>8);
150 }
151
152 u32 buserror_r();
153
DECLARE_WRITE_LINE_MEMBER(asc_irq_w)154 DECLARE_WRITE_LINE_MEMBER(asc_irq_w)
155 {
156 m_asc_interrupt = state;
157 field_interrupts();
158 }
159
160 // ID for PowerBook Duo 210
pd210_id_r()161 u32 pd210_id_r() { return 0xa55a1004; }
162
163 uint8_t mac_gsc_r(offs_t offset);
164 void mac_gsc_w(uint8_t data);
165 void macgsc_palette(palette_device &palette) const;
166
167 uint32_t macwd_r(offs_t offset, uint32_t mem_mask = ~0);
168 void macwd_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
169
170 u32 m_colors[3], m_count, m_clutoffs, m_wd_palette[256];
171 };
172
173 // 4-level grayscale
macgsc_palette(palette_device & palette) const174 void macpb030_state::macgsc_palette(palette_device &palette) const
175 {
176 palette.set_pen_color(0, 0xff, 0xff, 0xff);
177 palette.set_pen_color(1, 0x7f, 0x7f, 0x7f);
178 palette.set_pen_color(2, 0x3f, 0x3f, 0x3f);
179 palette.set_pen_color(3, 0x00, 0x00, 0x00);
180 }
181
buserror_r()182 u32 macpb030_state::buserror_r()
183 {
184 m_maincpu->set_input_line(M68K_LINE_BUSERROR, ASSERT_LINE);
185 m_maincpu->set_input_line(M68K_LINE_BUSERROR, CLEAR_LINE);
186 return 0;
187 }
188
field_interrupts()189 void macpb030_state::field_interrupts()
190 {
191 int take_interrupt = -1;
192
193 if (m_scc_interrupt)
194 {
195 take_interrupt = 4;
196 }
197 else if (m_via2_interrupt)
198 {
199 take_interrupt = 2;
200 }
201 else if (m_via_interrupt)
202 {
203 take_interrupt = 1;
204 }
205
206 if (m_last_taken_interrupt > -1)
207 {
208 m_maincpu->set_input_line(m_last_taken_interrupt, CLEAR_LINE);
209 m_last_taken_interrupt = -1;
210 }
211
212 if (take_interrupt > -1)
213 {
214 m_maincpu->set_input_line(take_interrupt, ASSERT_LINE);
215 m_last_taken_interrupt = take_interrupt;
216 }
217 }
218
machine_start()219 void macpb030_state::machine_start()
220 {
221 m_ram_ptr = (u32*)m_ram->pointer();
222 m_ram_size = m_ram->size()>>1;
223 m_ram_mask = m_ram_size - 1;
224 m_rom_ptr = (u32*)memregion("bootrom")->base();
225 m_rom_size = memregion("bootrom")->bytes();
226 m_via_cycles = -50;
227 m_via_interrupt = m_via2_interrupt = m_scc_interrupt = m_asc_interrupt = 0;
228 m_last_taken_interrupt = -1;
229 m_irq_count = m_ca1_data = m_ca2_data = 0;
230
231 m_6015_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(macpb030_state::mac_6015_tick),this));
232 m_6015_timer->adjust(attotime::never);
233 }
234
machine_reset()235 void macpb030_state::machine_reset()
236 {
237 m_overlay = true;
238 m_via_interrupt = m_via2_interrupt = m_scc_interrupt = m_asc_interrupt = 0;
239 m_last_taken_interrupt = -1;
240 m_irq_count = m_ca1_data = m_ca2_data = 0;
241
242 // put ROM mirror at 0
243 address_space& space = m_maincpu->space(AS_PROGRAM);
244 const u32 memory_size = std::min((u32)0x3fffff, m_rom_size);
245 const u32 memory_end = memory_size - 1;
246 offs_t memory_mirror = memory_end & ~(memory_size - 1);
247
248 space.unmap_write(0x00000000, memory_end);
249 space.install_read_bank(0x00000000, memory_end & ~memory_mirror, memory_mirror, "bank1");
250 membank("bank1")->set_base(m_rom_ptr);
251
252 // start 60.15 Hz timer
253 m_6015_timer->adjust(attotime::from_hz(60.15), 0, attotime::from_hz(60.15));
254 }
255
init_macpb140()256 void macpb030_state::init_macpb140()
257 {
258 }
259
init_macpb160()260 void macpb030_state::init_macpb160()
261 {
262 }
263
screen_update_macpb140(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)264 u32 macpb030_state::screen_update_macpb140(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
265 {
266 u16 const *const video_ram = (const uint16_t *)m_vram.target();
267
268 for (int y = 0; y < 400; y++)
269 {
270 u16 *const line = &bitmap.pix(y);
271
272 for (int x = 0; x < 640; x += 16)
273 {
274 uint16_t const word = video_ram[((y * 640) / 16) + ((x / 16) ^ 1)];
275 for (int b = 0; b < 16; b++)
276 {
277 line[x + b] = (word >> (15 - b)) & 0x0001;
278 }
279 }
280 }
281 return 0;
282 }
283
screen_update_macpb160(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)284 u32 macpb030_state::screen_update_macpb160(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
285 {
286 u8 const *const vram8 = (uint8_t *)m_vram.target();
287
288 for (int y = 0; y < 400; y++)
289 {
290 u16 *line = &bitmap.pix(y);
291
292 for (int x = 0; x < 640 / 4; x++)
293 {
294 uint8_t const pixels = vram8[(y * 160) + (BYTE4_XOR_BE(x))];
295
296 *line++ = ((pixels >> 6) & 3);
297 *line++ = ((pixels >> 4) & 3);
298 *line++ = ((pixels >> 2) & 3);
299 *line++ = (pixels & 3);
300 }
301 }
302 return 0;
303 }
304
screen_update_macpbwd(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)305 u32 macpb030_state::screen_update_macpbwd(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) /* Color PowerBooks using an off-the-shelf WD video chipset */
306 {
307 u8 const *vram8 = (uint8_t *)m_vram.target();
308
309 // vram8 += 0x40000;
310
311 for (int y = 0; y < 480; y++)
312 {
313 u32 *scanline = &bitmap.pix(y);
314 for (int x = 0; x < 640; x++)
315 {
316 uint8_t const pixels = vram8[(y * 640) + (BYTE4_XOR_BE(x))];
317 *scanline++ = m_wd_palette[pixels];
318 }
319 }
320
321 return 0;
322 }
323
mac_via_r(offs_t offset)324 u16 macpb030_state::mac_via_r(offs_t offset)
325 {
326 u16 data;
327
328 offset >>= 8;
329 offset &= 0x0f;
330
331 data = m_via1->read(offset);
332
333 m_maincpu->adjust_icount(m_via_cycles);
334
335 return (data & 0xff) | (data << 8);
336 }
337
mac_via_w(offs_t offset,u16 data,u16 mem_mask)338 void macpb030_state::mac_via_w(offs_t offset, u16 data, u16 mem_mask)
339 {
340 offset >>= 8;
341 offset &= 0x0f;
342
343 if (ACCESSING_BITS_0_7)
344 m_via1->write(offset, data & 0xff);
345 if (ACCESSING_BITS_8_15)
346 m_via1->write(offset, (data >> 8) & 0xff);
347
348 m_maincpu->adjust_icount(m_via_cycles);
349 }
350
mac_via2_r(offs_t offset)351 uint16_t macpb030_state::mac_via2_r(offs_t offset)
352 {
353 int data;
354
355 offset >>= 8;
356 offset &= 0x0f;
357
358 data = m_via2->read(offset);
359 return (data & 0xff) | (data << 8);
360 }
361
mac_via2_w(offs_t offset,uint16_t data,uint16_t mem_mask)362 void macpb030_state::mac_via2_w(offs_t offset, uint16_t data, uint16_t mem_mask)
363 {
364 offset >>= 8;
365 offset &= 0x0f;
366
367 if (ACCESSING_BITS_0_7)
368 m_via2->write(offset, data & 0xff);
369 if (ACCESSING_BITS_8_15)
370 m_via2->write(offset, (data >> 8) & 0xff);
371 }
372
WRITE_LINE_MEMBER(macpb030_state::via_irq_w)373 WRITE_LINE_MEMBER(macpb030_state::via_irq_w)
374 {
375 m_via_interrupt = state;
376 field_interrupts();
377 }
378
WRITE_LINE_MEMBER(macpb030_state::via2_irq_w)379 WRITE_LINE_MEMBER(macpb030_state::via2_irq_w)
380 {
381 m_via2_interrupt = state;
382 field_interrupts();
383 }
384
rom_switch_r(offs_t offset)385 u32 macpb030_state::rom_switch_r(offs_t offset)
386 {
387 // disable the overlay
388 if (m_overlay)
389 {
390 address_space& space = m_maincpu->space(AS_PROGRAM);
391 const u32 memory_end = m_ram->size() - 1;
392 void *memory_data = m_ram->pointer();
393 offs_t memory_mirror = memory_end & ~memory_end;
394
395 space.install_readwrite_bank(0x00000000, memory_end & ~memory_mirror, memory_mirror, "bank1");
396 membank("bank1")->set_base(memory_data);
397 m_overlay = false;
398 }
399
400 //printf("rom_switch_r: offset %08x ROM_size -1 = %08x, masked = %08x\n", offset, m_rom_size-1, offset & ((m_rom_size - 1)>>2));
401
402 return m_rom_ptr[offset & ((m_rom_size - 1)>>2)];
403 }
404
TIMER_CALLBACK_MEMBER(macpb030_state::mac_6015_tick)405 TIMER_CALLBACK_MEMBER(macpb030_state::mac_6015_tick)
406 {
407 /* signal VBlank on CA1 input on the VIA */
408 m_ca1_data ^= 1;
409 m_via1->write_ca1(m_ca1_data);
410
411 if (++m_irq_count == 60)
412 {
413 m_irq_count = 0;
414
415 m_ca2_data ^= 1;
416 /* signal 1 Hz irq on CA2 input on the VIA */
417 m_via1->write_ca2(m_ca2_data);
418 }
419 }
420
scsi_r(offs_t offset,u16 mem_mask)421 u16 macpb030_state::scsi_r(offs_t offset, u16 mem_mask)
422 {
423 int reg = (offset >> 3) & 0xf;
424
425 // logerror("macplus_scsi_r: offset %x mask %x\n", offset, mem_mask);
426
427 if ((reg == 6) && (offset == 0x130))
428 {
429 reg = R5380_CURDATA_DTACK;
430 }
431
432 return m_ncr5380->ncr5380_read_reg(reg) << 8;
433 }
434
scsi_w(offs_t offset,u16 data,u16 mem_mask)435 void macpb030_state::scsi_w(offs_t offset, u16 data, u16 mem_mask)
436 {
437 int reg = (offset >> 3) & 0xf;
438
439 // logerror("macplus_scsi_w: data %x offset %x mask %x\n", data, offset, mem_mask);
440
441 if ((reg == 0) && (offset == 0x100))
442 {
443 reg = R5380_OUTDATA_DTACK;
444 }
445
446 m_ncr5380->ncr5380_write_reg(reg, data);
447 }
448
scsi_drq_r(offs_t offset,uint32_t mem_mask)449 uint32_t macpb030_state::scsi_drq_r(offs_t offset, uint32_t mem_mask)
450 {
451 switch (mem_mask)
452 {
453 case 0xff000000:
454 return m_ncr5380->ncr5380_read_reg(R5380_CURDATA_DTACK)<<24;
455
456 case 0xffff0000:
457 return (m_ncr5380->ncr5380_read_reg(R5380_CURDATA_DTACK)<<24) | (m_ncr5380->ncr5380_read_reg(R5380_CURDATA_DTACK)<<16);
458
459 case 0xffffffff:
460 return (m_ncr5380->ncr5380_read_reg(R5380_CURDATA_DTACK)<<24) | (m_ncr5380->ncr5380_read_reg(R5380_CURDATA_DTACK)<<16) | (m_ncr5380->ncr5380_read_reg(R5380_CURDATA_DTACK)<<8) | m_ncr5380->ncr5380_read_reg(R5380_CURDATA_DTACK);
461
462 default:
463 logerror("scsi_drq_r: unknown mem_mask %08x\n", mem_mask);
464 }
465
466 return 0;
467 }
468
scsi_drq_w(offs_t offset,uint32_t data,uint32_t mem_mask)469 void macpb030_state::scsi_drq_w(offs_t offset, uint32_t data, uint32_t mem_mask)
470 {
471 switch (mem_mask)
472 {
473 case 0xff000000:
474 m_ncr5380->ncr5380_write_reg(R5380_OUTDATA_DTACK, data>>24);
475 break;
476
477 case 0xffff0000:
478 m_ncr5380->ncr5380_write_reg(R5380_OUTDATA_DTACK, data>>24);
479 m_ncr5380->ncr5380_write_reg(R5380_OUTDATA_DTACK, data>>16);
480 break;
481
482 case 0xffffffff:
483 m_ncr5380->ncr5380_write_reg(R5380_OUTDATA_DTACK, data>>24);
484 m_ncr5380->ncr5380_write_reg(R5380_OUTDATA_DTACK, data>>16);
485 m_ncr5380->ncr5380_write_reg(R5380_OUTDATA_DTACK, data>>8);
486 m_ncr5380->ncr5380_write_reg(R5380_OUTDATA_DTACK, data&0xff);
487 break;
488
489 default:
490 logerror("scsi_drq_w: unknown mem_mask %08x\n", mem_mask);
491 break;
492 }
493 }
494
mac_gsc_r(offs_t offset)495 uint8_t macpb030_state::mac_gsc_r(offs_t offset)
496 {
497 if (offset == 1)
498 {
499 return 5;
500 }
501
502 return 0;
503 }
504
mac_gsc_w(uint8_t data)505 void macpb030_state::mac_gsc_w(uint8_t data)
506 {
507 }
508
macwd_r(offs_t offset,uint32_t mem_mask)509 uint32_t macpb030_state::macwd_r(offs_t offset, uint32_t mem_mask)
510 {
511 switch (offset)
512 {
513 case 0xf6:
514 if (m_screen->vblank())
515 {
516 return 0xffffffff;
517 }
518 else
519 {
520 return 0;
521 }
522
523 default:
524 // printf("macwd_r: @ %x, mask %08x (PC=%x)\n", offset, mem_mask, m_maincpu->pc());
525 break;
526 }
527 return 0;
528 }
529
macwd_w(offs_t offset,uint32_t data,uint32_t mem_mask)530 void macpb030_state::macwd_w(offs_t offset, uint32_t data, uint32_t mem_mask)
531 {
532 switch (offset)
533 {
534 case 0xf2:
535 if (mem_mask == 0xff000000) // DAC control
536 {
537 m_clutoffs = data >> 24;
538 m_count = 0;
539 }
540 else if (mem_mask == 0x00ff0000) // DAC data
541 {
542 m_colors[m_count++] = (data >> 16) & 0xff;
543 if (m_count == 3)
544 {
545 // printf("RAMDAC: color %d = %02x %02x %02x\n", m_rbv_clutoffs, m_rbv_colors[0], m_rbv_colors[1], m_rbv_colors[2]);
546 m_wd_palette[m_clutoffs] = rgb_t(m_colors[0], m_colors[1], m_colors[2]);
547 m_clutoffs++;
548 m_count = 0;
549 }
550 }
551 else
552 {
553 printf("macwd: Unknown DAC write, data %08x, mask %08x\n", data, mem_mask);
554 }
555 break;
556
557 default:
558 // printf("macwd_w: %x @ %x, mask %08x (PC=%x)\n", data, offset, mem_mask, m_maincpu->pc());
559 break;
560 }
561 }
562
563 /***************************************************************************
564 ADDRESS MAPS
565 ****************************************************************************/
566
567 // ROM detects the "Jaws" ASIC by checking for I/O space mirrored at 0x01000000 boundries
macpb140_map(address_map & map)568 void macpb030_state::macpb140_map(address_map &map)
569 {
570 map(0x40000000, 0x400fffff).r(FUNC(macpb030_state::rom_switch_r)).mirror(0x0ff00000);
571
572 map(0x50000000, 0x50001fff).rw(FUNC(macpb030_state::mac_via_r), FUNC(macpb030_state::mac_via_w)).mirror(0x01f00000);
573 map(0x50002000, 0x50003fff).rw(FUNC(macpb030_state::mac_via2_r), FUNC(macpb030_state::mac_via2_w)).mirror(0x01f00000);
574 map(0x50004000, 0x50005fff).rw(FUNC(macpb030_state::mac_scc_r), FUNC(macpb030_state::mac_scc_2_w)).mirror(0x01f00000);
575 map(0x50006000, 0x50007fff).rw(FUNC(macpb030_state::scsi_drq_r), FUNC(macpb030_state::scsi_drq_w)).mirror(0x01f00000);
576 map(0x50010000, 0x50011fff).rw(FUNC(macpb030_state::scsi_r), FUNC(macpb030_state::scsi_w)).mirror(0x01f00000);
577 map(0x50012060, 0x50012063).r(FUNC(macpb030_state::scsi_drq_r)).mirror(0x01f00000);
578 map(0x50014000, 0x50015fff).rw(m_asc, FUNC(asc_device::read), FUNC(asc_device::write)).mirror(0x01f00000);
579 map(0x50016000, 0x50017fff).rw(FUNC(macpb030_state::mac_iwm_r), FUNC(macpb030_state::mac_iwm_w)).mirror(0x01f00000);
580 map(0x50024000, 0x50027fff).r(FUNC(macpb030_state::buserror_r)).mirror(0x01f00000); // bus error here to make sure we aren't mistaken for another decoder
581
582 map(0xfee08000, 0xfeffffff).ram().share("vram");
583 }
584
macpb160_map(address_map & map)585 void macpb030_state::macpb160_map(address_map &map)
586 {
587 map(0x40000000, 0x400fffff).r(FUNC(macpb030_state::rom_switch_r)).mirror(0x0ff00000);
588
589 map(0x50f00000, 0x50f01fff).rw(FUNC(macpb030_state::mac_via_r), FUNC(macpb030_state::mac_via_w));
590 map(0x50f02000, 0x50f03fff).rw(FUNC(macpb030_state::mac_via2_r), FUNC(macpb030_state::mac_via2_w));
591 map(0x50f04000, 0x50f05fff).rw(FUNC(macpb030_state::mac_scc_r), FUNC(macpb030_state::mac_scc_2_w));
592 map(0x50f06000, 0x50f07fff).rw(FUNC(macpb030_state::scsi_drq_r), FUNC(macpb030_state::scsi_drq_w));
593 map(0x50f10000, 0x50f11fff).rw(FUNC(macpb030_state::scsi_r), FUNC(macpb030_state::scsi_w));
594 map(0x50f12060, 0x50f12063).r(FUNC(macpb030_state::scsi_drq_r));
595 map(0x50f14000, 0x50f15fff).rw(m_asc, FUNC(asc_device::read), FUNC(asc_device::write));
596 map(0x50f16000, 0x50f17fff).rw(FUNC(macpb030_state::mac_iwm_r), FUNC(macpb030_state::mac_iwm_w));
597 map(0x50f20000, 0x50f21fff).rw(FUNC(macpb030_state::mac_gsc_r), FUNC(macpb030_state::mac_gsc_w));
598 map(0x50f24000, 0x50f27fff).r(FUNC(macpb030_state::buserror_r)); // bus error here to make sure we aren't mistaken for another decoder
599
600 map(0x60000000, 0x6001ffff).ram().share("vram").mirror(0x0ffe0000);
601 }
602
macpb165c_map(address_map & map)603 void macpb030_state::macpb165c_map(address_map &map)
604 {
605 map(0x40000000, 0x400fffff).r(FUNC(macpb030_state::rom_switch_r)).mirror(0x0ff00000);
606
607 map(0x50f00000, 0x50f01fff).rw(FUNC(macpb030_state::mac_via_r), FUNC(macpb030_state::mac_via_w));
608 map(0x50f02000, 0x50f03fff).rw(FUNC(macpb030_state::mac_via2_r), FUNC(macpb030_state::mac_via2_w));
609 map(0x50f04000, 0x50f05fff).rw(FUNC(macpb030_state::mac_scc_r), FUNC(macpb030_state::mac_scc_2_w));
610 map(0x50f06000, 0x50f07fff).rw(FUNC(macpb030_state::scsi_drq_r), FUNC(macpb030_state::scsi_drq_w));
611 map(0x50f10000, 0x50f11fff).rw(FUNC(macpb030_state::scsi_r), FUNC(macpb030_state::scsi_w));
612 map(0x50f12060, 0x50f12063).r(FUNC(macpb030_state::scsi_drq_r));
613 map(0x50f14000, 0x50f15fff).rw(m_asc, FUNC(asc_device::read), FUNC(asc_device::write));
614 map(0x50f16000, 0x50f17fff).rw(FUNC(macpb030_state::mac_iwm_r), FUNC(macpb030_state::mac_iwm_w));
615 map(0x50f20000, 0x50f21fff).r(FUNC(macpb030_state::buserror_r)); // bus error here to detect we're not the grayscale 160/165/180
616 map(0x50f24000, 0x50f27fff).r(FUNC(macpb030_state::buserror_r)); // bus error here to make sure we aren't mistaken for another decoder
617
618 // on-board color video on 165c/180c
619 map(0xfc000000, 0xfc07ffff).ram().share("vram").mirror(0x00380000); // 512k of VRAM
620 map(0xfc400000, 0xfcefffff).rw(FUNC(macpb030_state::macwd_r), FUNC(macpb030_state::macwd_w));
621 // fc4003c8 = DAC control, fc4003c9 = DAC data
622 // fc4003da bit 3 is VBL
623 map(0xfcff8000, 0xfcffffff).rom().region("vrom", 0x0000);
624 }
625
macpd210_map(address_map & map)626 void macpb030_state::macpd210_map(address_map &map)
627 {
628 map(0x40000000, 0x400fffff).r(FUNC(macpb030_state::rom_switch_r)).mirror(0x0ff00000);
629
630 map(0x50f00000, 0x50f01fff).rw(FUNC(macpb030_state::mac_via_r), FUNC(macpb030_state::mac_via_w));
631 map(0x50f02000, 0x50f03fff).rw(FUNC(macpb030_state::mac_via2_r), FUNC(macpb030_state::mac_via2_w));
632 map(0x50f04000, 0x50f05fff).rw(FUNC(macpb030_state::mac_scc_r), FUNC(macpb030_state::mac_scc_2_w));
633 map(0x50f06000, 0x50f07fff).rw(FUNC(macpb030_state::scsi_drq_r), FUNC(macpb030_state::scsi_drq_w));
634 map(0x50f10000, 0x50f11fff).rw(FUNC(macpb030_state::scsi_r), FUNC(macpb030_state::scsi_w));
635 map(0x50f12060, 0x50f12063).r(FUNC(macpb030_state::scsi_drq_r));
636 map(0x50f14000, 0x50f15fff).rw(m_asc, FUNC(asc_device::read), FUNC(asc_device::write));
637 map(0x50f16000, 0x50f17fff).rw(FUNC(macpb030_state::mac_iwm_r), FUNC(macpb030_state::mac_iwm_w));
638 map(0x50f20000, 0x50f21fff).rw(FUNC(macpb030_state::mac_gsc_r), FUNC(macpb030_state::mac_gsc_w));
639 map(0x50f24000, 0x50f27fff).r(FUNC(macpb030_state::buserror_r)); // bus error here to make sure we aren't mistaken for another decoder
640
641 map(0x5ffffffc, 0x5fffffff).r(FUNC(macpb030_state::pd210_id_r));
642
643 map(0x60000000, 0x6001ffff).ram().share("vram").mirror(0x0ffe0000);
644 }
645
mac_via_in_a()646 u8 macpb030_state::mac_via_in_a()
647 {
648 return 0x81 | 0x12;
649 }
650
mac_via_in_b()651 u8 macpb030_state::mac_via_in_b()
652 {
653 int val = 0;
654 // TODO: is this valid for VIA2 PMU machines?
655 /* video beam in display (! VBLANK && ! HBLANK basically) */
656
657 if (m_screen->vpos() >= 480)
658 val |= 0x40;
659
660 // printf("%s VIA1 IN_B = %02x\n", machine().describe_context().c_str(), val);
661
662 return val;
663 }
664
mac_via_out_a(u8 data)665 void macpb030_state::mac_via_out_a(u8 data)
666 {
667 sony_set_sel_line(m_iwm.target(), (data & 0x20) >> 5);
668 }
669
mac_via_out_b(u8 data)670 void macpb030_state::mac_via_out_b(u8 data)
671 {
672 }
673
mac_via2_in_a()674 u8 macpb030_state::mac_via2_in_a()
675 {
676 return m_macadb->get_pm_data_recv();
677 }
678
mac_via2_in_b()679 u8 macpb030_state::mac_via2_in_b()
680 {
681 if (m_macadb->get_pm_ack() == 2)
682 {
683 return 0xcf;
684 }
685 else
686 {
687 return 0xcd;
688 }
689 }
690
mac_via2_out_a(u8 data)691 void macpb030_state::mac_via2_out_a(u8 data)
692 {
693 m_macadb->set_pm_data_send(data);
694 }
695
mac_via2_out_b(u8 data)696 void macpb030_state::mac_via2_out_b(u8 data)
697 {
698 m_macadb->pmu_req_w((data >> 2) & 1);
699 }
700
701 /***************************************************************************
702 DEVICE CONFIG
703 ***************************************************************************/
704
705 static const applefdc_interface mac_iwm_interface =
706 {
707 sony_set_lines,
708 sony_set_enable_lines,
709
710 sony_read_data,
711 sony_write_data,
712 sony_read_status
713 };
714
715 static const floppy_interface mac_floppy_interface =
716 {
717 FLOPPY_STANDARD_3_5_DSHD,
718 LEGACY_FLOPPY_OPTIONS_NAME(apple35_mac),
719 "floppy_3_5"
720 };
721
INPUT_PORTS_START(macadb)722 static INPUT_PORTS_START( macadb )
723 INPUT_PORTS_END
724
725 /***************************************************************************
726 MACHINE DRIVERS
727 ***************************************************************************/
728
729 void macpb030_state::macpb140(machine_config &config)
730 {
731 M68030(config, m_maincpu, C15M);
732 m_maincpu->set_addrmap(AS_PROGRAM, &macpb030_state::macpb140_map);
733
734 SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
735 m_screen->set_refresh_hz(60.15);
736 m_screen->set_vblank_time(ATTOSECONDS_IN_USEC(1260));
737 m_screen->set_video_attributes(VIDEO_UPDATE_BEFORE_VBLANK);
738 m_screen->set_size(700, 480);
739 m_screen->set_visarea(0, 639, 0, 399);
740 m_screen->set_palette(m_palette);
741 m_screen->set_screen_update(FUNC(macpb030_state::screen_update_macpb140));
742
743 PALETTE(config, m_palette, palette_device::MONOCHROME_INVERTED);
744
745 MACADB(config, m_macadb, C15M);
746 m_macadb->set_pmu_mode(true);
747 m_macadb->set_pmu_is_via1(false);
748
749 LEGACY_IWM(config, m_iwm, &mac_iwm_interface);
750 sonydriv_floppy_image_device::legacy_2_drives_add(config, &mac_floppy_interface);
751
752 scsi_port_device &scsibus(SCSI_PORT(config, "scsi"));
753 scsibus.set_slot_device(1, "harddisk", SCSIHD, DEVICE_INPUT_DEFAULTS_NAME(SCSI_ID_6));
754 scsibus.set_slot_device(2, "harddisk", SCSIHD, DEVICE_INPUT_DEFAULTS_NAME(SCSI_ID_5));
755
756 NCR5380(config, m_ncr5380, C7M);
757 m_ncr5380->set_scsi_port("scsi");
758
759 SCC85C30(config, m_scc, C7M);
760 // m_scc->intrq_callback().set(FUNC(macpb030_state::set_scc_interrupt));
761
762 VIA6522(config, m_via1, C7M/10);
763 m_via1->readpa_handler().set(FUNC(macpb030_state::mac_via_in_a));
764 m_via1->readpb_handler().set(FUNC(macpb030_state::mac_via_in_b));
765 m_via1->writepa_handler().set(FUNC(macpb030_state::mac_via_out_a));
766 m_via1->writepb_handler().set(FUNC(macpb030_state::mac_via_out_b));
767 m_via1->irq_handler().set(FUNC(macpb030_state::via_irq_w));
768 m_via1->cb2_handler().set(FUNC(macpb030_state::via_cb2_w));
769
770 VIA6522(config, m_via2, C7M/10);
771 m_via2->readpa_handler().set(FUNC(macpb030_state::mac_via2_in_a));
772 m_via2->readpb_handler().set(FUNC(macpb030_state::mac_via2_in_b));
773 m_via2->writepa_handler().set(FUNC(macpb030_state::mac_via2_out_a));
774 m_via2->writepb_handler().set(FUNC(macpb030_state::mac_via2_out_b));
775 m_via2->irq_handler().set(FUNC(macpb030_state::via2_irq_w));
776
777 SPEAKER(config, "lspeaker").front_left();
778 SPEAKER(config, "rspeaker").front_right();
779 ASC(config, m_asc, C15M, asc_device::asc_type::ASC);
780 m_asc->irqf_callback().set(FUNC(macpb030_state::asc_irq_w));
781 m_asc->add_route(0, "lspeaker", 1.0);
782 m_asc->add_route(1, "rspeaker", 1.0);
783
784 /* internal ram */
785 RAM(config, m_ram);
786 m_ram->set_default_size("2M");
787 m_ram->set_extra_options("4M,6M,8M");
788
789 SOFTWARE_LIST(config, "flop35_list").set_original("mac_flop");
790 }
791
792 // PowerBook 145 = 140 @ 25 MHz (still 2MB RAM - the 145B upped that to 4MB)
macpb145(machine_config & config)793 void macpb030_state::macpb145(machine_config &config)
794 {
795 macpb140(config);
796 m_maincpu->set_clock(25000000);
797
798 m_ram->set_default_size("4M");
799 m_ram->set_extra_options("6M,8M");
800 }
801
802 // PowerBook 170 = 140 @ 25 MHz with an active-matrix LCD (140/145/145B were passive)
macpb170(machine_config & config)803 void macpb030_state::macpb170(machine_config &config)
804 {
805 macpb140(config);
806 m_maincpu->set_clock(25000000);
807
808 m_ram->set_default_size("4M");
809 m_ram->set_extra_options("6M,8M");
810 }
811
macpb160(machine_config & config)812 void macpb030_state::macpb160(machine_config &config)
813 {
814 M68030(config, m_maincpu, 25000000);
815 m_maincpu->set_addrmap(AS_PROGRAM, &macpb030_state::macpb160_map);
816
817 SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
818 m_screen->set_refresh_hz(60.15);
819 m_screen->set_vblank_time(ATTOSECONDS_IN_USEC(1260));
820 m_screen->set_video_attributes(VIDEO_UPDATE_BEFORE_VBLANK);
821 m_screen->set_size(700, 480);
822 m_screen->set_visarea(0, 639, 0, 399);
823 m_screen->set_palette(m_palette);
824 m_screen->set_screen_update(FUNC(macpb030_state::screen_update_macpb160));
825
826 PALETTE(config, m_palette, FUNC(macpb030_state::macgsc_palette), 16);
827
828 MACADB(config, m_macadb, C15M);
829 m_macadb->set_pmu_mode(true);
830 m_macadb->set_pmu_is_via1(false);
831
832 LEGACY_IWM(config, m_iwm, &mac_iwm_interface);
833 sonydriv_floppy_image_device::legacy_2_drives_add(config, &mac_floppy_interface);
834
835 scsi_port_device &scsibus(SCSI_PORT(config, "scsi"));
836 scsibus.set_slot_device(1, "harddisk", SCSIHD, DEVICE_INPUT_DEFAULTS_NAME(SCSI_ID_6));
837 scsibus.set_slot_device(2, "harddisk", SCSIHD, DEVICE_INPUT_DEFAULTS_NAME(SCSI_ID_5));
838
839 NCR5380(config, m_ncr5380, C7M);
840 m_ncr5380->set_scsi_port("scsi");
841
842 SCC85C30(config, m_scc, C7M);
843 // m_scc->intrq_callback().set(FUNC(macpb030_state::set_scc_interrupt));
844
845 VIA6522(config, m_via1, C7M / 10);
846 m_via1->readpa_handler().set(FUNC(macpb030_state::mac_via_in_a));
847 m_via1->readpb_handler().set(FUNC(macpb030_state::mac_via_in_b));
848 m_via1->writepa_handler().set(FUNC(macpb030_state::mac_via_out_a));
849 m_via1->writepb_handler().set(FUNC(macpb030_state::mac_via_out_b));
850 m_via1->irq_handler().set(FUNC(macpb030_state::via_irq_w));
851 m_via1->cb2_handler().set(FUNC(macpb030_state::via_cb2_w));
852
853 VIA6522(config, m_via2, C7M / 10);
854 m_via2->readpa_handler().set(FUNC(macpb030_state::mac_via2_in_a));
855 m_via2->readpb_handler().set(FUNC(macpb030_state::mac_via2_in_b));
856 m_via2->writepa_handler().set(FUNC(macpb030_state::mac_via2_out_a));
857 m_via2->writepb_handler().set(FUNC(macpb030_state::mac_via2_out_b));
858 m_via2->irq_handler().set(FUNC(macpb030_state::via2_irq_w));
859
860 SPEAKER(config, "lspeaker").front_left();
861 SPEAKER(config, "rspeaker").front_right();
862 ASC(config, m_asc, C15M, asc_device::asc_type::ASC);
863 m_asc->irqf_callback().set(FUNC(macpb030_state::asc_irq_w));
864 m_asc->add_route(0, "lspeaker", 1.0);
865 m_asc->add_route(1, "rspeaker", 1.0);
866
867 /* internal ram */
868 RAM(config, m_ram);
869 m_ram->set_default_size("2M");
870 m_ram->set_extra_options("4M,6M,8M");
871
872 SOFTWARE_LIST(config, "flop35_list").set_original("mac_flop");
873 }
874
macpb180(machine_config & config)875 void macpb030_state::macpb180(machine_config &config)
876 {
877 macpb160(config);
878 m_maincpu->set_clock(33000000);
879 }
880
macpb180c(machine_config & config)881 void macpb030_state::macpb180c(machine_config &config)
882 {
883 macpb160(config);
884 m_maincpu->set_clock(33000000);
885 m_maincpu->set_addrmap(AS_PROGRAM, &macpb030_state::macpb165c_map);
886
887 m_screen->set_size(800, 525);
888 m_screen->set_visarea(0, 640 - 1, 0, 480 - 1);
889 m_screen->set_screen_update(FUNC(macpb030_state::screen_update_macpbwd));
890 m_screen->set_no_palette();
891 }
892
macpd210(machine_config & config)893 void macpb030_state::macpd210(machine_config &config)
894 {
895 macpb160(config);
896 m_maincpu->set_addrmap(AS_PROGRAM, &macpb030_state::macpd210_map);
897
898 m_ram->set_extra_options("8M,12M,16M,20M,24M");
899 }
900
901 ROM_START(macpb140)
902 ROM_REGION32_BE(0x100000, "bootrom", 0)
903 ROM_LOAD("420dbff3.rom", 0x000000, 0x100000, CRC(88ea2081) SHA1(7a8ee468d16e64f2ad10cb8d1a45e6f07cc9e212))
904
905 ROM_REGION(0x1800, "pmu", 0)
906 ROM_LOAD("pmuv2.bin", 0x000000, 0x001800, CRC(1a32b5e5) SHA1(7c096324763cfc8d2024893b3e8493b7729b3a92))
907 ROM_END
908
909 ROM_START(macpb145)
910 ROM_REGION32_BE(0x100000, "bootrom", 0)
911 ROM_LOAD("420dbff3.rom", 0x000000, 0x100000, CRC(88ea2081) SHA1(7a8ee468d16e64f2ad10cb8d1a45e6f07cc9e212))
912
913 ROM_REGION(0x1800, "pmu", 0)
914 ROM_LOAD("pmuv2.bin", 0x000000, 0x001800, CRC(1a32b5e5) SHA1(7c096324763cfc8d2024893b3e8493b7729b3a92))
915 ROM_END
916
917 ROM_START(macpb145b)
918 ROM_REGION32_BE(0x100000, "bootrom", 0)
919 ROM_LOAD("420dbff3.rom", 0x000000, 0x100000, CRC(88ea2081) SHA1(7a8ee468d16e64f2ad10cb8d1a45e6f07cc9e212))
920
921 ROM_REGION(0x1800, "pmu", 0)
922 ROM_LOAD("pmuv2.bin", 0x000000, 0x001800, CRC(1a32b5e5) SHA1(7c096324763cfc8d2024893b3e8493b7729b3a92))
923 ROM_END
924
925 ROM_START(macpb170)
926 ROM_REGION32_BE(0x100000, "bootrom", 0)
927 ROM_LOAD("420dbff3.rom", 0x000000, 0x100000, CRC(88ea2081) SHA1(7a8ee468d16e64f2ad10cb8d1a45e6f07cc9e212))
928
929 ROM_REGION(0x1800, "pmu", 0)
930 ROM_LOAD("pmuv2.bin", 0x000000, 0x001800, CRC(1a32b5e5) SHA1(7c096324763cfc8d2024893b3e8493b7729b3a92))
931 ROM_END
932
933 ROM_START(macpb160)
934 ROM_REGION32_BE(0x100000, "bootrom", 0)
935 ROM_LOAD("e33b2724.rom", 0x000000, 0x100000, CRC(536c60f4) SHA1(c0510682ae6d973652d7e17f3c3b27629c47afac))
936
937 ROM_REGION(0x1800, "pmu", 0)
938 ROM_LOAD("pmuv3.bin", 0x000000, 0x001800, CRC(f2df696c) SHA1(fc312cbfd407c6f0248c6463910e41ad6b5b0daa))
939 ROM_END
940
941 ROM_START(macpb180)
942 ROM_REGION32_BE(0x100000, "bootrom", 0)
943 ROM_LOAD("e33b2724.rom", 0x000000, 0x100000, CRC(536c60f4) SHA1(c0510682ae6d973652d7e17f3c3b27629c47afac))
944
945 ROM_REGION(0x1800, "pmu", 0)
946 ROM_LOAD("pmuv3.bin", 0x000000, 0x001800, CRC(f2df696c) SHA1(fc312cbfd407c6f0248c6463910e41ad6b5b0daa))
947 ROM_END
948
949 ROM_START(macpb180c)
950 ROM_REGION32_BE(0x100000, "bootrom", 0)
951 ROM_LOAD("e33b2724.rom", 0x000000, 0x100000, CRC(536c60f4) SHA1(c0510682ae6d973652d7e17f3c3b27629c47afac))
952
953 ROM_REGION32_BE(0x8000, "vrom", 0)
954 ROM_LOAD("pb180cvrom.bin", 0x0000, 0x8000, CRC(810c75ad) SHA1(3a936e97dee5ceeb25e50197ef504e514ae689a4))
955
956 ROM_REGION(0x1800, "pmu", 0)
957 ROM_LOAD("pmuv3.bin", 0x000000, 0x001800, CRC(f2df696c) SHA1(fc312cbfd407c6f0248c6463910e41ad6b5b0daa))
958 ROM_END
959
960 ROM_START(macpd210)
961 ROM_REGION32_BE(0x100000, "bootrom", 0)
962 ROM_LOAD("ecfa989b.rom", 0x000000, 0x100000, CRC(b86ed854) SHA1(ed1371c97117a5884da4a6605ecfc5abed48ae5a))
963 ROM_END
964
965 COMP(1991, macpb140, 0, 0, macpb140, macadb, macpb030_state, init_macpb140, "Apple Computer", "Macintosh PowerBook 140", MACHINE_NOT_WORKING)
966 COMP(1991, macpb170, macpb140, 0, macpb170, macadb, macpb030_state, init_macpb140, "Apple Computer", "Macintosh PowerBook 170", MACHINE_NOT_WORKING)
967 COMP(1992, macpb145, macpb140, 0, macpb145, macadb, macpb030_state, init_macpb140, "Apple Computer", "Macintosh PowerBook 145", MACHINE_NOT_WORKING)
968 COMP(1992, macpb145b, macpb140, 0, macpb170, macadb, macpb030_state, init_macpb140, "Apple Computer", "Macintosh PowerBook 145B", MACHINE_NOT_WORKING)
969 COMP(1992, macpb160, 0, 0, macpb160, macadb, macpb030_state, init_macpb160, "Apple Computer", "Macintosh PowerBook 160", MACHINE_NOT_WORKING)
970 COMP(1992, macpb180, macpb160, 0, macpb180, macadb, macpb030_state, init_macpb160, "Apple Computer", "Macintosh PowerBook 180", MACHINE_NOT_WORKING)
971 COMP(1992, macpb180c, macpb160, 0, macpb180c,macadb, macpb030_state, init_macpb160, "Apple Computer", "Macintosh PowerBook 180c", MACHINE_NOT_WORKING)
972
973 // PowerBook Duos (may or may not belong in this driver ultimately)
974 COMP( 1992, macpd210, 0, 0, macpd210, macadb, macpb030_state, init_macpb160, "Apple Computer", "Macintosh PowerBook Duo 210", MACHINE_NOT_WORKING )
975