~ubuntu-branches/ubuntu/precise/mame/precise-proposed

« back to all changes in this revision

Viewing changes to src/emu/cpu/i4004/i4004.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2010-08-01 23:18:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100801231831-9dj2qbsynutixsoe
Tags: 0.139-0ubuntu1
* New upstream release (LP: #612070)
* debian/contrib/manpages: removed, accepted upstream
* debian/patches/:
  - deprecated_gtk_macros: removed, fixed upstream
  - missing_newline.patch: removed, fixed upstream
  - typos.patch: removed, fixed upstream
* debian/rules: new variables SYMLEVEL and DUMPSYM
* mame-tools: ldplayer removed, possibly for good (FTBFS upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        UINT8   C; // Carry flag
32
32
        UINT8   TEST; // Test PIN status
33
33
        PAIR    PC; // It is in fact one of ADDR regs
 
34
        UINT8   flags; // used for I/O only
34
35
 
35
 
        running_device *device;
 
36
        legacy_cpu_device *device;
36
37
        const address_space *program;
37
38
        const address_space *data;
38
39
        const address_space *io;
39
 
        cpu_state_table         state;
40
40
        int                                     icount;
41
41
        int                             pc_pos; // PC possition in ADDR
42
42
        int                                     addr_mask;
48
48
#define GET_PC                                  (cpustate->ADDR[cpustate->pc_pos])
49
49
 
50
50
/***************************************************************************
51
 
    CPU STATE DESCRIPTION
52
 
***************************************************************************/
53
 
 
54
 
#define I4004_STATE_ENTRY(_name, _format, _member, _datamask, _flags) \
55
 
        CPU_STATE_ENTRY(I4004_##_name, #_name, _format, i4004_state, _member, _datamask, ~0, _flags)
56
 
 
57
 
static const cpu_state_entry state_array[] =
58
 
{
59
 
        I4004_STATE_ENTRY(PC,   "%03X", PC.w.l, 0x0fff, 0)
60
 
        I4004_STATE_ENTRY(GENPC,"%03X", PC.w.l, 0x0fff, CPUSTATE_NOSHOW)
61
 
        I4004_STATE_ENTRY(A,   "%01X", A, 0x0f, 0)
62
 
        I4004_STATE_ENTRY(R01, "%02X", R[0], 0xff, 0)
63
 
        I4004_STATE_ENTRY(R23, "%02X", R[1], 0xff, 0)
64
 
        I4004_STATE_ENTRY(R45, "%02X", R[2], 0xff, 0)
65
 
        I4004_STATE_ENTRY(R67, "%02X", R[3], 0xff, 0)
66
 
        I4004_STATE_ENTRY(R89, "%02X", R[4], 0xff, 0)
67
 
        I4004_STATE_ENTRY(RAB, "%02X", R[5], 0xff, 0)
68
 
        I4004_STATE_ENTRY(RCD, "%02X", R[6], 0xff, 0)
69
 
        I4004_STATE_ENTRY(REF, "%02X", R[7], 0xff, 0)
70
 
        I4004_STATE_ENTRY(ADDR1, "%03X", ADDR[0].w.l, 0x0fff, 0)
71
 
        I4004_STATE_ENTRY(ADDR2, "%03X", ADDR[1].w.l, 0x0fff, 0)
72
 
        I4004_STATE_ENTRY(ADDR3, "%03X", ADDR[2].w.l, 0x0fff, 0)
73
 
        I4004_STATE_ENTRY(ADDR4, "%03X", ADDR[3].w.l, 0x0fff, 0)
74
 
        I4004_STATE_ENTRY(RAM, "%03X", RAM.w.l, 0x0fff, 0)
75
 
};
76
 
 
77
 
static const cpu_state_table state_table_template =
78
 
{
79
 
        NULL,                                           /* pointer to the base of state (offsets are relative to this) */
80
 
        0,                                                      /* subtype this table refers to */
81
 
        ARRAY_LENGTH(state_array),      /* number of entries */
82
 
        state_array                                     /* array of entries */
83
 
};
84
 
 
85
 
/***************************************************************************
86
51
    INLINE FUNCTIONS
87
52
***************************************************************************/
88
53
 
89
54
INLINE i4004_state *get_safe_token(running_device *device)
90
55
{
91
56
        assert(device != NULL);
92
 
        assert(device->token != NULL);
93
 
        assert(device->type == CPU);
94
 
        assert(cpu_get_type(device) == CPU_I4004);
95
 
        return (i4004_state *)device->token;
 
57
        assert(device->type() == I4004);
 
58
        return (i4004_state *)downcast<legacy_cpu_device *>(device)->token();
96
59
}
97
60
 
98
61
INLINE UINT8 ROP(i4004_state *cpustate)
462
425
{
463
426
        i4004_state *cpustate = get_safe_token(device);
464
427
 
465
 
        cpustate->icount = cycles;
466
 
 
467
 
 
468
428
        do
469
429
        {
470
430
                debugger_instruction_hook(device, GET_PC.d);
471
431
                execute_one(cpustate, ROP(cpustate));
472
432
 
473
433
        } while (cpustate->icount > 0);
474
 
 
475
 
        return cycles - cpustate->icount;
476
434
}
477
435
 
478
436
/***************************************************************************
484
442
        i4004_state *cpustate = get_safe_token(device);
485
443
 
486
444
        /* set up the state table */
487
 
        cpustate->state = state_table_template;
488
 
        cpustate->state.baseptr = cpustate;
489
 
        cpustate->state.subtypemask = 1;
 
445
        {
 
446
                device_state_interface *state;
 
447
                device->interface(state);
 
448
                state->state_add(I4004_PC,    "PC",    cpustate->PC.w.l).mask(0x0fff);
 
449
                state->state_add(STATE_GENPC, "GENPC", cpustate->PC.w.l).mask(0x0fff).noshow();
 
450
                state->state_add(STATE_GENFLAGS, "GENFLAGS", cpustate->flags).mask(0x0f).callimport().callexport().noshow().formatstr("%4s");
 
451
                state->state_add(I4004_A,     "A",     cpustate->A).mask(0x0f);
 
452
 
 
453
                astring tempstr;
 
454
                for (int regnum = 0; regnum < 8; regnum++)
 
455
                        state->state_add(I4004_R01 + regnum, tempstr.format("R%X%X", regnum*2, regnum*2+1), cpustate->R[regnum]);
 
456
 
 
457
                for (int addrnum = 0; addrnum < 4; addrnum++)
 
458
                        state->state_add(I4004_ADDR1 + addrnum, tempstr.format("ADDR%d", addrnum + 1), cpustate->ADDR[addrnum].w.l).mask(0xfff);
 
459
 
 
460
                state->state_add(I4004_RAM,   "RAM",   cpustate->RAM.w.l).mask(0x0fff);
 
461
        }
490
462
 
491
463
        cpustate->device = device;
492
464
 
543
515
 
544
516
static CPU_IMPORT_STATE( i4004 )
545
517
{
 
518
        i4004_state *cpustate = get_safe_token(device);
 
519
 
 
520
        switch (entry.index())
 
521
        {
 
522
                case STATE_GENFLAGS:
 
523
                        cpustate->C = (cpustate->flags >> 1) & 1;
 
524
                        cpustate->TEST = (cpustate->flags >> 0) & 1;
 
525
                        break;
 
526
        }
546
527
}
547
528
 
548
529
static CPU_EXPORT_STATE( i4004 )
549
530
{
 
531
        i4004_state *cpustate = get_safe_token(device);
 
532
 
 
533
        switch (entry.index())
 
534
        {
 
535
                case STATE_GENFLAGS:
 
536
                        cpustate->flags = ((cpustate->A == 0) ? 0x04 : 0x00) |
 
537
                                                          (cpustate->C ? 0x02 : 0x00) |
 
538
                                                          (cpustate->TEST ? 0x01 : 0x00);
 
539
                        break;
 
540
        }
 
541
}
 
542
 
 
543
static CPU_EXPORT_STRING( i4004 )
 
544
{
 
545
        i4004_state *cpustate = get_safe_token(device);
 
546
 
 
547
        switch (entry.index())
 
548
        {
 
549
                case STATE_GENFLAGS:
 
550
                        string.printf(".%c%c%c",
 
551
                                (cpustate->A==0) ? 'Z':'.',
 
552
                                cpustate->C      ? 'C':'.',
 
553
                                cpustate->TEST   ? 'T':'.');
 
554
                        break;
 
555
        }
550
556
}
551
557
 
552
558
/***************************************************************************
562
568
 
563
569
CPU_GET_INFO( i4004 )
564
570
{
565
 
        i4004_state *cpustate = (device != NULL && device->token != NULL) ? get_safe_token(device) : NULL;
 
571
        i4004_state *cpustate = (device != NULL && device->token() != NULL) ? get_safe_token(device) : NULL;
566
572
        switch (state)
567
573
        {
568
574
                /* --- the following bits of info are returned as 64-bit signed integers --- */
597
603
                case CPUINFO_FCT_DISASSEMBLE:   info->disassemble = CPU_DISASSEMBLE_NAME(i4004);                break;
598
604
                case CPUINFO_FCT_IMPORT_STATE:  info->import_state = CPU_IMPORT_STATE_NAME(i4004);              break;
599
605
                case CPUINFO_FCT_EXPORT_STATE:  info->export_state = CPU_EXPORT_STATE_NAME(i4004);              break;
 
606
                case CPUINFO_FCT_EXPORT_STRING: info->export_string = CPU_EXPORT_STRING_NAME(i4004);    break;
600
607
 
601
608
                /* --- the following bits of info are returned as pointers --- */
602
609
                case CPUINFO_PTR_INSTRUCTION_COUNTER:                   info->icount = &cpustate->icount;               break;
603
 
                case CPUINFO_PTR_STATE_TABLE:                                   info->state_table = &cpustate->state;   break;
604
610
 
605
611
                /* --- the following bits of info are returned as NULL-terminated strings --- */
606
612
                case DEVINFO_STR_NAME:                                          strcpy(info->s, "4004");                                break;
608
614
                case DEVINFO_STR_VERSION:                                       strcpy(info->s, "1.0");                                 break;
609
615
                case DEVINFO_STR_SOURCE_FILE:                           strcpy(info->s, __FILE__);                              break;
610
616
                case DEVINFO_STR_CREDITS:                                       strcpy(info->s, "Copyright Miodrag Milanovic"); break;
611
 
 
612
 
                case CPUINFO_STR_FLAGS:
613
 
                        sprintf(info->s, ".%c%c%c",
614
 
                                (cpustate->A==0) ? 'Z':'.',
615
 
                                cpustate->C      ? 'C':'.',
616
 
                                cpustate->TEST   ? 'T':'.');
617
 
                        break;
618
617
        }
619
618
}
 
619
 
 
620
DEFINE_LEGACY_CPU_DEVICE(I4004, i4004);