Previous 15994 Revisions Next

r9304 Saturday 2nd October, 2010 at 13:50:01 UTC by R. Belmont
[MAC] Preliminary PMU simulation for Portable and PowerBooks. Also added dep rules for Mac components.
[src/mess]mess.mak
[src/mess/drivers]mac.c
[src/mess/includes]mac.h
[src/mess/machine]mac.c

src/mess/machine/mac.c
r9303r9304
117117static TIMER_CALLBACK(mac_scanline_tick);
118118static TIMER_CALLBACK(mac_adb_tick);
119119static TIMER_CALLBACK(mac_6015_tick);
120static TIMER_CALLBACK(mac_pmu_tick);
120121static emu_timer *mac_scanline_timer, *mac_adb_timer;
121122static int scan_keyboard(running_machine *machine);
122123static TIMER_CALLBACK(inquiry_timeout_func);
r9303r9304
23232324   }
23242325}
23252326
2327static TIMER_CALLBACK(mac_pmu_tick)
2328{
2329   mac_state *mac = machine->driver_data<mac_state>();
2330
2331   #if LOG_ADB
2332   printf("PM: timer tick, lowering ACK\n");
2333   #endif
2334   mac->pm_ack &= ~2;   // lower ACK to handshake next step
2335}
2336
2337static void pmu_one_byte_reply(mac_state *mac, UINT8 result)
2338{
2339   mac->pm_out[0] = 1;   // length
2340   mac->pm_out[1] = result;
2341   mac->pm_slen = 2;
2342   timer_adjust_oneshot(mac->pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
2343}
2344
2345// 900c74, 901ba4, 901bd8
2346static void pmu_exec(mac_state *mac)
2347{
2348   mac->pm_sptr = 0;   // clear send pointer
2349   mac->pm_slen = 0;   // and send length
2350   mac->pm_dptr = 0;   // and recieve pointer
2351
2352   switch (mac->pm_cmd[0])
2353   {
2354      case 0x10:   // subsystem power and clock ctrl (no response)
2355         break;
2356
2357      case 0x32:   // write extended PRAM byte(s).  cmd[2] = address, cmd[3] = length, cmd[4...] = data
2358         if ((mac->pm_cmd[2] + mac->pm_cmd[3]) < 0x100)
2359         {
2360            int i;
2361
2362            for (i = 0; i < mac->pm_cmd[3]; i++)
2363            {
2364               mac->rtc_ram[mac->pm_cmd[2] + i] = mac->pm_cmd[4+i];
2365            }
2366
2367            // no reply?
2368         }
2369
2370      case 0x3a:   // read extended PRAM byte(s).  cmd[2] = address, cmd[3] = length
2371         if ((mac->pm_cmd[2] + mac->pm_cmd[3]) < 0x100)
2372         {
2373            int i;
2374
2375            mac->pm_out[0] = mac->pm_cmd[3];
2376            for (i = 0; i < mac->pm_cmd[3]; i++)
2377            {
2378               mac->pm_out[1 + i] = mac->rtc_ram[mac->pm_cmd[2] + i];
2379            }
2380            mac->pm_slen = mac->pm_cmd[3] + 1;
2381            timer_adjust_oneshot(mac->pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
2382         }
2383         break;
2384
2385      case 0x78:   // read interrupt flag
2386         pmu_one_byte_reply(mac, 0);
2387         break;
2388
2389      case 0xec:   // PMU self-test (send 1 count byte + reply)
2390         pmu_one_byte_reply(mac, 0);
2391         break;
2392
2393      default:
2394         fatalerror("PMU: Unhandled command %02x\n", mac->pm_cmd[0]);
2395         break;
2396   }
2397
2398   if (mac->pm_slen > 0)
2399   {
2400      mac->pm_state = 1;
2401   }
2402}
2403
23262404static void adb_vblank(running_machine *machine)
23272405{
23282406   mac_state *mac = machine->driver_data<mac_state>();
r9303r9304
24602538   {
24612539      case MODEL_MAC_PORTABLE:
24622540      case MODEL_MAC_PB100:
2463//          printf("Read PM data %x\n", mac->pm_data_recv);
2541         #if LOG_ADB
2542         printf("Read PM data %x\n", mac->pm_data_recv);
2543         #endif
24642544         return mac->pm_data_recv;
24652545
24662546      case MODEL_MAC_CLASSIC:
r9303r9304
25562636
25572637   if (mac->mac_model >= MODEL_MAC_PORTABLE && mac->mac_model <= MODEL_MAC_PB100)
25582638   {
2639      #if LOG_ADB
25592640      printf("%02x to PM\n", data);
2641      #endif
25602642      mac->pm_data_send = data;
25612643      return;
25622644   }
r9303r9304
26002682
26012683      sony_set_sel_line(fdc,(data & 0x20) >> 5);
26022684      mac->mac_drive_select = ((data & 0x10) >> 4);
2603//      printf("PM_REQ = %x, was %x\n", data & 1, mac->pm_req);
2685
2686      if ((data & 1) && !(mac->pm_req & 1))
2687      {
2688         #if LOG_ADB
2689         printf("PM: 68k dropping /REQ\n");
2690         #endif
2691
2692         if (mac->pm_state == 0)    // do this in receive state only
2693         {
2694            mac->pm_data_recv = 0xff;
2695            mac->pm_ack |= 2;
2696
2697            // check if length byte matches
2698            if ((mac->pm_dptr >= 2) && (mac->pm_cmd[1] == (mac->pm_dptr-2)))
2699            {
2700               pmu_exec(mac);
2701               #if LOG_ADB
2702               printf("PMU exec: command %02x length %d\n", mac->pm_cmd[0], mac->pm_cmd[1]);
2703               #endif
2704            }
2705         }
2706      }
2707      if (!(data & 1) && (mac->pm_req & 1))
2708      {
2709         if (mac->pm_state == 0)
2710         {
2711            #if LOG_ADB
2712            printf("PM: 68k asserting /REQ, clocking in byte [%d] = %02x\n", mac->pm_dptr, mac->pm_data_send);
2713            #endif
2714            mac->pm_ack &= ~2;   // clear, we're waiting for more bytes
2715            mac->pm_cmd[mac->pm_dptr++] = mac->pm_data_send;
2716         }
2717         else   // receiving, so this is different
2718         {
2719            mac->pm_data_recv = mac->pm_out[mac->pm_sptr++];
2720            mac->pm_slen--;
2721            mac->pm_ack |= 2;   // raise ACK to indicate available byte
2722            #if LOG_ADB
2723            printf("PM: sending byte %02x\n", mac->pm_data_recv);
2724            #endif
2725
2726            // another byte to send?
2727            if (mac->pm_slen)
2728            {
2729               timer_adjust_oneshot(mac->pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2730            }
2731            else
2732            {
2733               mac->pm_state = 0;   // back to receive state
2734            }
2735         }
2736      }
26042737      mac->pm_req = data & 1;
26052738      return;
26062739   }
r9303r9304
27862919   {
27872920      mac_adb_timer = timer_alloc(machine, mac_adb_tick, NULL);
27882921      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
2922
2923      // also allocate PMU timer
2924      if (ADB_IS_PM)
2925      {
2926         mac->pmu_send_timer = timer_alloc(machine, mac_pmu_tick, NULL);
2927         timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
2928      }
2929
27892930   }
27902931   mac_scanline_timer = timer_alloc(machine, mac_scanline_tick, NULL);
27912932   timer_adjust_oneshot(mac_scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0);
r9303r9304
27962937MACHINE_RESET(mac)
27972938{
27982939   mac_state *mac = machine->driver_data<mac_state>();
2799   mac_model_t model_save;
2800   emu_timer *timer_save;
28012940
28022941   // stop 60.15 Hz timer
28032942   timer_adjust_oneshot(mac->mac6015_timer, attotime_never, 0);
r9303r9304
28082947      timer_adjust_periodic(mac->mac6015_timer, ATTOTIME_IN_HZ(60.15), 0, ATTOTIME_IN_HZ(60.15));
28092948   }
28102949
2811   // clear mac state struct
2812   model_save = mac->mac_model;
2813   timer_save = mac->inquiry_timeout;
2814   mac->mac_model = model_save;
2815   mac->inquiry_timeout = timer_save;
2950   // clear PMU response timer
2951   if (ADB_IS_PM)
2952   {
2953      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
2954   }
28162955
28172956   last_taken_interrupt = -1;
28182957
r9303r9304
28613000   if (machine->device<cpu_device>("maincpu")->debug()) {
28623001      machine->device<cpu_device>("maincpu")->debug()->set_dasm_override(mac_dasm_override);
28633002   }
3003
3004   mac->mac_drive_select = 0;
3005   mac->mac_scsiirq_enable = 0;
3006   mac->mac_via2_vbl = 0;
3007   mac->mac_se30_vbl_enable = 0;
3008   mac->mac_nubus_irq_state = 0;
3009   mac->keyboard_reply = 0;
3010   mac->kbd_comm = 0;
3011   mac->kbd_receive = 0;
3012   mac->kbd_shift_reg = 0;
3013   mac->kbd_shift_count = 0;
3014   mac->mouse_bit_x = mac->mouse_bit_y = 0;
3015   mac->rtc_rTCEnb = 0;
3016   mac->rtc_rTCClk = 0;
3017   mac->rtc_bit_count = 0;
3018   mac->rtc_data_dir = 0;
3019   mac->rtc_data_out = 0;
3020   mac->rtc_cmd = 0;
3021   mac->rtc_write_protect = 0;
3022   mac->rtc_state = 0;
3023   mac->pm_data_send = mac->pm_data_recv = mac->pm_ack = mac->pm_req = mac->pm_dptr = 0;
3024   mac->pm_state = 0;
28643025}
28653026
28663027
src/mess/includes/mac.h
r9303r9304
256256   INT32 adb_streaming, adb_stream_ptr;
257257
258258   // Portable/PB100 Power Manager IC comms (chapter 4, "Guide to the Macintosh Family Hardware", second edition)
259   UINT8 pm_data_send, pm_data_recv, pm_ack, pm_req;
259   UINT8 pm_data_send, pm_data_recv, pm_ack, pm_req, pm_cmd[32], pm_out[32], pm_dptr, pm_sptr, pm_slen, pm_state;
260   emu_timer *pmu_send_timer;
260261
261   // Apple Sound Chip
262   UINT8 mac_asc_regs[0x2000];
263   INT16 xfersamples[0x800];
264
265262   // 60.15 Hz timer for RBV/V8/Sonora/Eagle/VASP/etc.
266263   emu_timer *mac6015_timer;
267264};
src/mess/mess.mak
r9303r9304
17481748            $(MESSSRC)/machine/nes_pcb.c \
17491749            $(MESSSRC)/machine/nes_unif.c \
17501750
1751$(MESS_AUDIO)/mac.o:      $(MESSSRC)/audio/mac.c \
1752            $(MESSSRC)/includes/mac.h
17511753
1754$(MESS_VIDEO)/mac.o:      $(MESSSRC)/video/mac.c \
1755            $(MESSSRC)/includes/mac.h
1756
1757$(MESS_MACHINE)/mac.o:      $(MESSSRC)/machine/mac.c \
1758            $(MESSSRC)/includes/mac.h
1759
1760$(MESS_DRIVERS)/mac.o:      $(MESSSRC)/drivers/mac.c \
1761            $(MESSSRC)/includes/mac.h
1762
17521763#-------------------------------------------------
17531764# layout dependencies
17541765#-------------------------------------------------
src/mess/drivers/mac.c
r9303r9304
542542   AM_RANGE(0xe80000, 0xefffff) AM_READWRITE(mac_via_r, mac_via_w)
543543   AM_RANGE(0xfffff0, 0xffffff) AM_READWRITE(mac_autovector_r, mac_autovector_w)
544544ADDRESS_MAP_END
545
545                 
546546static ADDRESS_MAP_START(macplus_map, ADDRESS_SPACE_PROGRAM, 16)
547547   AM_RANGE(0x580000, 0x5fffff) AM_READWRITE(macplus_scsi_r, macplus_scsi_w)
548548   AM_RANGE(0x800000, 0x9fffff) AM_READ(mac_scc_r)
r9303r9304
557557   AM_RANGE(0xf60000, 0xf6ffff) AM_READWRITE(mac_iwm_r, mac_iwm_w)
558558   AM_RANGE(0xf70000, 0xf7ffff) AM_READWRITE(mac_via_r, mac_via_w)
559559   AM_RANGE(0xf90000, 0xf9ffff) AM_READWRITE(macplus_scsi_r, macplus_scsi_w)
560//  AM_RANGE(0xfa0000, 0xfaffff) AM_RAM // video RAM? registers?
560   AM_RANGE(0xfa8000, 0xfaffff) AM_RAM   // VRAM
561561   AM_RANGE(0xfb0000, 0xfbffff) AM_READWRITE8(mac_asc_r, mac_asc_w, 0xffff)
562   AM_RANGE(0xfd0000, 0xfdffff) AM_READWRITE(mac_scc_r, mac_scc_w)
562   AM_RANGE(0xfd0000, 0xfdffff) AM_READWRITE(mac_scc_r, mac_scc_2_w)
563563   AM_RANGE(0xfffff0, 0xffffff) AM_READWRITE(mac_autovector_r, mac_autovector_w)
564564ADDRESS_MAP_END
565565

Previous 15994 Revisions Next


© 1998-2018 The MESS Team