Previous 15994 Revisions Next

r6440 Monday 23rd November, 2009 at 08:26:30 UTC by Miodrag Milanović
Added Intel 8008 and National Semiconductor SC/MP CPU cores (sync with MAME core)
[src/emu/cpu]cpu.mak
[src/emu/cpu/i8008]8008dasm.c* i8008.c* i8008.h*
[src/emu/cpu/scmp]scmp.c* scmp.h* scmpdasm.c*
[src/mame]mame.mak
[src/tools]unidasm.c

src/mame/mame.mak
r6439r6440
116116CPUS += I4004
117117CPUS += SUPERFX
118118CPUS += Z8
119CPUS += I8008
120CPUS += SCMP
119121
120122
121123#-------------------------------------------------
src/tools/unidasm.c
r6439r6440
113113CPU_DISASSEMBLE( h8 );
114114CPU_DISASSEMBLE( hd6309 );
115115CPU_DISASSEMBLE( i4004 );
116CPU_DISASSEMBLE( i8008 );
116117CPU_DISASSEMBLE( i8085 );
117118CPU_DISASSEMBLE( x86_16 );
118119CPU_DISASSEMBLE( x86_32 );
r6439r6440
170171CPU_DISASSEMBLE( s2650 );
171172CPU_DISASSEMBLE( saturn );
172173CPU_DISASSEMBLE( sc61860 );
174CPU_DISASSEMBLE( scmp );
173175CPU_DISASSEMBLE( se3208 );
174176CPU_DISASSEMBLE( sh2 );
175177CPU_DISASSEMBLE( sh4 );
r6439r6440
234236   { "hd6309",      _8bit,  0, CPU_DISASSEMBLE_NAME(hd6309) },
235237   { "i386",      _8bit,  0, CPU_DISASSEMBLE_NAME(x86_32) },
236238   { "i4004",      _8bit,  0, CPU_DISASSEMBLE_NAME(i4004) },
239   { "i8008",      _8bit,  0, CPU_DISASSEMBLE_NAME(i8008) },
237240   { "i8085",      _8bit,  0, CPU_DISASSEMBLE_NAME(i8085) },
238241   { "i80286",      _8bit,  0, CPU_DISASSEMBLE_NAME(x86_16) },
239242   { "i8086",      _8bit,  0, CPU_DISASSEMBLE_NAME(x86_16) },
r6439r6440
293296   { "s2650",      _8bit,  0, CPU_DISASSEMBLE_NAME(s2650) },
294297   { "saturn",     _8bit,  0, CPU_DISASSEMBLE_NAME(saturn) },
295298   { "sc61860",    _8bit,  0, CPU_DISASSEMBLE_NAME(sc61860) },
299   { "scmp",       _8bit,  0, CPU_DISASSEMBLE_NAME(scmp) },
296300   { "se3208",     _16le,  0, CPU_DISASSEMBLE_NAME(se3208) },
297301   { "sh2",        _16be,  0, CPU_DISASSEMBLE_NAME(sh2) },
298302   { "sh4",        _16le,  0, CPU_DISASSEMBLE_NAME(sh4) },
src/emu/cpu/cpu.mak
r6439r6440
544544                     $(CPUSRC)/i4004/i4004.h
545545
546546
547#-------------------------------------------------
548# Intel 8008
549#-------------------------------------------------
547550
551ifneq ($(filter I8008,$(CPUS)),)
552OBJDIRS += $(CPUOBJ)/i8008
553CPUOBJS += $(CPUOBJ)/i8008/i8008.o
554DASMOBJS += $(CPUOBJ)/i8008/8008dasm.o
555endif
556
557$(CPUOBJ)/i8008/i8008.o:   $(CPUSRC)/i8008/i8008.c \
558                     $(CPUSRC)/i8008/i8008.h
559
548560#-------------------------------------------------
561#  National Semiconductor SC/MP
562#-------------------------------------------------
563
564ifneq ($(filter SCMP,$(CPUS)),)
565OBJDIRS += $(CPUOBJ)/scmp
566CPUOBJS += $(CPUOBJ)/scmp/scmp.o
567DASMOBJS += $(CPUOBJ)/scmp/scmpdasm.o
568endif
569
570$(CPUOBJ)/scmp/scmp.o:      $(CPUSRC)/scmp/scmp.c \
571                     $(CPUSRC)/scmp/scmp.h
572
573
574#-------------------------------------------------
549575# Intel 8080/8085A
550576#-------------------------------------------------
551577
src/emu/cpu/scmp/scmp.c
r0r6440
1/*****************************************************************************
2 *
3 *   scmp.c
4 *
5 *   National Semiconductor SC/MP CPU Disassembly
6 *
7 *   Initial version by Miodrag Milanovic
8 *
9 *****************************************************************************/
10
11#include "debugger.h"
12#include "scmp.h"
13
14#define VERBOSE 0
15
16#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
17
18/***************************************************************************
19    TYPE DEFINITIONS
20***************************************************************************/
21
22typedef struct _scmp_state scmp_state;
23struct _scmp_state
24{
25   scmp_config       config;
26   PAIR   PC;
27   PAIR   P1;
28   PAIR   P2;
29   PAIR   P3;
30   UINT8   AC;
31   UINT8   ER;
32   UINT8   SR;
33
34   const device_config *device;
35   const address_space *program;
36   const address_space *io;
37   cpu_state_table    state;
38   int               icount;
39
40   devcb_resolved_write8      flag_out_func;
41   devcb_resolved_write_line   sout_func;
42   devcb_resolved_read_line   sin_func;
43   devcb_resolved_read_line   sensea_func;
44   devcb_resolved_read_line   senseb_func;
45   devcb_resolved_write_line   halt_func;
46};
47
48/***************************************************************************
49    MACROS
50***************************************************************************/
51
52/***************************************************************************
53    CPU STATE DESCRIPTION
54***************************************************************************/
55
56#define SCMP_STATE_ENTRY(_name, _format, _member, _datamask, _flags) \
57   CPU_STATE_ENTRY(SCMP_##_name, #_name, _format, scmp_state, _member, _datamask, ~0, _flags)
58
59static const cpu_state_entry state_array[] =
60{
61   SCMP_STATE_ENTRY(PC,   "%04X", PC.w.l, 0xffff, 0)
62   SCMP_STATE_ENTRY(GENPC,"%04X", PC.w.l, 0xffff, CPUSTATE_NOSHOW)
63   SCMP_STATE_ENTRY(P1,   "%04X", P1.w.l, 0xffff, 0)
64   SCMP_STATE_ENTRY(P2,   "%04X", P2.w.l, 0xffff, 0)
65   SCMP_STATE_ENTRY(P3,   "%04X", P3.w.l, 0xffff, 0)
66   SCMP_STATE_ENTRY(AC,   "%02X", AC, 0xff, 0)
67   SCMP_STATE_ENTRY(ER,   "%02X", ER, 0xff, 0)
68   SCMP_STATE_ENTRY(SR,   "%02X", SR, 0xff, 0)
69
70};
71
72static const cpu_state_table state_table_template =
73{
74   NULL,                  /* pointer to the base of state (offsets are relative to this) */
75   0,                     /* subtype this table refers to */
76   ARRAY_LENGTH(state_array),   /* number of entries */
77   state_array               /* array of entries */
78};
79
80/***************************************************************************
81    INLINE FUNCTIONS
82***************************************************************************/
83
84INLINE scmp_state *get_safe_token(const device_config *device)
85{
86   assert(device != NULL);
87   assert(device->token != NULL);
88   assert(device->type == CPU);
89   assert(cpu_get_type(device) == CPU_SCMP);
90   return (scmp_state *)device->token;
91}
92
93INLINE UINT16 ADD12(UINT16 addr, INT8 val)
94{
95   return ((addr + val) & 0x0fff) | (addr & 0xf000);
96}
97
98INLINE UINT8 ROP(scmp_state *cpustate)
99{
100   UINT16 pc = cpustate->PC.w.l;
101   cpustate->PC.w.l = ADD12(cpustate->PC.w.l,1);
102   return memory_decrypted_read_byte(cpustate->program,  pc);
103}
104
105INLINE UINT8 ARG(scmp_state *cpustate)
106{
107   UINT16 pc = cpustate->PC.w.l;
108   cpustate->PC.w.l = ADD12(cpustate->PC.w.l,1);
109   return memory_raw_read_byte(cpustate->program, pc);
110}
111
112INLINE UINT8 RM(scmp_state *cpustate,UINT32 a)
113{
114   return memory_read_byte_8le(cpustate->program, a);
115}
116
117INLINE void WM(scmp_state *cpustate,UINT32 a, UINT8 v)
118{
119   memory_write_byte_8le(cpustate->program, a, v);
120}
121
122INLINE void illegal(scmp_state *cpustate,UINT8 opcode)
123{
124#if VERBOSE
125   UINT16 pc = cpustate->PC.w.l;
126   LOG(("SC/MP illegal instruction %04X $%02X\n", pc-1, opcode));
127#endif
128}
129
130INLINE PAIR *GET_PTR_REG(scmp_state *cpustate, int num)
131{
132   switch(num) {
133      case 1: return &cpustate->P1;
134      case 2: return &cpustate->P2;
135      case 3: return &cpustate->P3;
136      default :
137            return &cpustate->PC;
138   }
139}
140
141INLINE void BIN_ADD(scmp_state *cpustate, UINT8 val)
142{
143   UINT16 tmp = cpustate->AC + val + ((cpustate->SR >> 7) & 1);
144   UINT8 ov = (((cpustate->AC & 0x80)==(val & 0x80)) && ((cpustate->AC & 0x80)!=(tmp & 0x80))) ? 0x40 : 0x00;
145
146   cpustate->AC = tmp & 0xff;
147   cpustate->SR &= 0x3f; // clear CY/L and OV flag
148   cpustate->SR |= (tmp & 0x100) ? 0x80 : 0x00; // set CY/L
149   cpustate->SR |= ov;
150}
151
152INLINE void DEC_ADD(scmp_state *cpustate, UINT8 val)
153{
154   UINT16 tmp = cpustate->AC + val + ((cpustate->SR >> 7) & 1);
155   if ((tmp & 0x0f) > 9) tmp +=6;
156   cpustate->AC = tmp % 0xa0;
157   cpustate->SR &= 0x7f; // clear CY/L flag
158   cpustate->SR |= (tmp > 0x99) ? 0x80 : 0x00;
159}
160
161INLINE UINT16 GET_ADDR(scmp_state *cpustate, UINT8 code)
162{
163   UINT16 addr = 0;
164   INT8 offset = 0;
165   UINT16 retVal = 0;
166   UINT16 ptr = GET_PTR_REG(cpustate,code & 0x03)->w.l;
167
168   UINT8 arg = ARG(cpustate);
169   if (arg == 0x80) {
170      offset = cpustate->ER;
171   } else {
172      if (arg & 0x80) {
173         offset = (INT8)arg;
174      } else {
175         offset = arg;
176      }
177   }
178
179   addr = ADD12(ptr,offset);
180
181   if (code & 0x04) {
182      if (code & 0x03) {
183         // Auto-indexed
184         if (offset < 0) {
185            // pre decrement
186            GET_PTR_REG(cpustate,code & 0x03)->w.l = addr;
187            retVal = addr;
188         } else {
189            // post increment
190            retVal = ptr;
191            GET_PTR_REG(cpustate,code & 0x03)->w.l = addr;
192         }
193      } else {
194         // Immediate
195      }
196   } else {
197      // Indexed
198      retVal = addr;
199   }
200   return retVal;
201}
202
203static void execute_one(scmp_state *cpustate, int opcode)
204{
205   UINT8 tmp;
206   UINT8 ptr = opcode & 3;
207   if (BIT(opcode,7)) {
208      // two bytes instructions
209      switch (opcode)
210      {
211         // Memory Reference Instructions
212         case 0xc0 : case 0xc1 : case 0xc2 : case 0xc3 :
213         case 0xc5 : case 0xc6 : case 0xc7 :
214                  //LD
215                  cpustate->icount -= 18;
216                  cpustate->AC = RM(cpustate,GET_ADDR(cpustate,opcode));
217                  break;
218         case 0xc8 : case 0xc9 : case 0xca : case 0xcb :
219         case 0xcd : case 0xce : case 0xcf :
220                  // ST
221                  cpustate->icount -= 18;
222                  WM(cpustate,GET_ADDR(cpustate,opcode),cpustate->AC);
223                  break;
224         case 0xd0 : case 0xd1 : case 0xd2 : case 0xd3 :
225                  case 0xd5 : case 0xd6 : case 0xd7 :
226                  // AND
227                  cpustate->icount -= 18;
228                  cpustate->AC &= RM(cpustate,GET_ADDR(cpustate,opcode));
229                  break;
230         case 0xd8 : case 0xd9 : case 0xda : case 0xdb :
231                  case 0xdd : case 0xde : case 0xdf :
232                  //OR
233                  cpustate->icount -= 18;
234                  cpustate->AC |= RM(cpustate,GET_ADDR(cpustate,opcode));
235                  break;
236         case 0xe0 : case 0xe1 : case 0xe2 : case 0xe3 :
237                  case 0xe5 : case 0xe6 : case 0xe7 :
238                  // XOR
239                  cpustate->icount -= 18;
240                  cpustate->AC ^= RM(cpustate,GET_ADDR(cpustate,opcode));
241                  break;
242         case 0xe8 : case 0xe9 : case 0xea : case 0xeb :
243                  case 0xed : case 0xee : case 0xef :
244                  // DAD
245                  cpustate->icount -= 23;
246                  DEC_ADD(cpustate,RM(cpustate,GET_ADDR(cpustate,opcode)));
247                  break;
248         case 0xf0 : case 0xf1 : case 0xf2 : case 0xf3 :
249                  case 0xf5 : case 0xf6 : case 0xf7 :
250                  // ADD
251                  cpustate->icount -= 19;
252                  BIN_ADD(cpustate,RM(cpustate,GET_ADDR(cpustate,opcode)));
253                  break;
254         case 0xf8 : case 0xf9 : case 0xfa : case 0xfb :
255                  case 0xfd : case 0xfe : case 0xff :
256                  // CAD
257                  cpustate->icount -= 20;
258                  BIN_ADD(cpustate,~RM(cpustate,GET_ADDR(cpustate,opcode)));
259                  break;
260         // Memory Increment/Decrement Instructions
261         case 0xa8 : case 0xa9 : case 0xaa : case 0xab :
262                  // IDL
263                  {
264                     UINT16 addr = GET_ADDR(cpustate,opcode);
265                     cpustate->icount -= 22;
266                     cpustate->AC = RM(cpustate,addr) + 1;
267                     WM(cpustate,addr,cpustate->AC);
268                  }
269                  break;
270         case 0xb8 : case 0xb9 : case 0xba : case 0xbb :
271                  // DLD
272                  {
273                     UINT16 addr = GET_ADDR(cpustate,opcode);
274                     cpustate->icount -= 22;
275                     cpustate->AC = RM(cpustate,addr) - 1;
276                     WM(cpustate,addr,cpustate->AC);
277                  }
278                  break;
279         // Immediate Instructions
280         case 0xc4 : // LDI
281                  cpustate->icount -= 10;
282                  cpustate->AC = ARG(cpustate);
283                  break;
284         case 0xd4 : // ANI
285                  cpustate->icount -= 10;
286                  cpustate->AC &= ARG(cpustate);
287                  break;
288         case 0xdc : // ORI
289                  cpustate->icount -= 10;
290                  cpustate->AC |= ARG(cpustate);
291                  break;
292         case 0xe4 : // XRI
293                  cpustate->icount -= 10;
294                  cpustate->AC ^= ARG(cpustate);
295                  break;
296         case 0xec : // DAI
297                  cpustate->icount -= 15;
298                  DEC_ADD(cpustate,ARG(cpustate));
299                  break;
300         case 0xf4 : // ADI
301                  cpustate->icount -= 11;
302                  BIN_ADD(cpustate,ARG(cpustate));
303                  break;
304         case 0xfc : // CAI
305                  cpustate->icount -= 12;
306                  BIN_ADD(cpustate,~ARG(cpustate));
307                  break;
308         // Transfer Instructions
309         case 0x90 : case 0x91 : case 0x92 : case 0x93 :// JMP
310                  cpustate->icount -= 11;
311                  cpustate->PC.w.l = ADD12(GET_PTR_REG(cpustate,ptr)->w.l,(INT8)ARG(cpustate));
312                  break;
313         case 0x94 : case 0x95 : case 0x96 : case 0x97 :
314                  // JP
315                  cpustate->icount -= 9;
316                  tmp = ARG(cpustate);
317                  if (!cpustate->AC & 0x80) {
318                     cpustate->PC.w.l = ADD12(GET_PTR_REG(cpustate,ptr)->w.l,(INT8)tmp);
319                     cpustate->icount -= 2;
320                  }
321                  break;
322         case 0x98 : case 0x99 : case 0x9a : case 0x9b :
323                  // JZ
324                  cpustate->icount -= 9;
325                  tmp = ARG(cpustate);
326                  if (!cpustate->AC) {
327                     cpustate->PC.w.l = ADD12(GET_PTR_REG(cpustate,ptr)->w.l,(INT8)tmp);
328                     cpustate->icount -= 2;
329                  }
330                  break;
331         case 0x9c : case 0x9d : case 0x9e : case 0x9f :
332                  // JNZ
333                  cpustate->icount -= 9;
334                  tmp = ARG(cpustate);
335                  if (cpustate->AC) {
336                     cpustate->PC.w.l = ADD12(GET_PTR_REG(cpustate,ptr)->w.l,(INT8)tmp);
337                     cpustate->icount -= 2;
338                  }
339                  break;
340         // Double-Byte Miscellaneous Instructions
341         case 0x8f:    // DLY
342                  tmp = ARG(cpustate);
343                  cpustate->icount -= 13 + (cpustate->AC * 2) + (((UINT32)tmp) << 1) + (((UINT32)tmp) << 9);
344                  cpustate->AC = 0xff;
345                  break;
346         // Others are illegal
347         default :    cpustate->icount -= 1;
348                  illegal (cpustate,opcode);
349                  break;
350      }
351   } else {
352      // one byte instructions
353      switch (opcode)
354      {
355         // Extension Register Instructions
356         case 0x40:    // LDE
357                  cpustate->icount -= 6;
358                  cpustate->AC = cpustate->ER;
359                  break;
360         case 0x01:    // XAE
361                  cpustate->icount -= 7;
362                  tmp = cpustate->AC;
363                  cpustate->AC = cpustate->ER;
364                  cpustate->ER = tmp;
365                  break;
366         case 0x50:    // ANE
367                  cpustate->icount -= 6;
368                  cpustate->AC &= cpustate->ER;
369                  break;
370         case 0x58:    // ORE
371                  cpustate->icount -= 6;
372                  cpustate->AC |= cpustate->ER;
373                  break;
374         case 0x60:    // XRE
375                  cpustate->icount -= 6;
376                  cpustate->AC ^= cpustate->ER;
377                  break;
378         case 0x68:    // DAE
379                  cpustate->icount -= 11;
380                  DEC_ADD(cpustate,cpustate->ER);
381                  break;
382         case 0x70:    // ADE
383                  cpustate->icount -= 7;
384                  BIN_ADD(cpustate,cpustate->ER);
385                  break;
386         case 0x78:    // CAE
387                  cpustate->icount -= 8;
388                  BIN_ADD(cpustate,~cpustate->ER);
389                  break;
390         // Pointer Register Move Instructions
391         case 0x30: case 0x31: case 0x32: case 0x33:   // XPAL
392                  cpustate->icount -= 8;
393                  tmp = cpustate->AC;
394                  cpustate->AC = GET_PTR_REG(cpustate,ptr)->b.l;
395                  GET_PTR_REG(cpustate,ptr)->b.l = tmp;
396                  break;
397         case 0x34:    case 0x35 :case 0x36: case 0x37:
398                  // XPAH
399                  cpustate->icount -= 8;
400                  tmp = cpustate->AC;
401                  cpustate->AC = GET_PTR_REG(cpustate,ptr)->b.h;
402                  GET_PTR_REG(cpustate,ptr)->b.h = tmp;
403                  break;
404         case 0x3c:    case 0x3d :case 0x3e: case 0x3f:
405                  // XPPC
406                  {
407                     UINT16 tmp = ADD12(cpustate->PC.w.l,-1); // Since PC is incremented we need to fix it
408                     cpustate->icount -= 7;
409                     cpustate->PC.w.l = GET_PTR_REG(cpustate,ptr)->w.l;
410                     GET_PTR_REG(cpustate,ptr)->w.l = tmp;
411                     // After exchange CPU increment PC
412                     cpustate->PC.w.l = ADD12(cpustate->PC.w.l,1);
413                  }
414                  break;
415         // Shift, Rotate, Serial I/O Instructions
416         case 0x19:    // SIO
417                  cpustate->icount -= 5;
418                  devcb_call_write_line(&cpustate->sout_func, cpustate->ER & 0x01);
419                  cpustate->ER >>= 1;
420                  cpustate->ER |= devcb_call_read_line(&cpustate->sin_func) ? 0x80 : 0x00;
421                  break;
422         case 0x1c:    // SR
423                  cpustate->icount -= 5;
424                  cpustate->AC >>= 1;
425                  break;
426         case 0x1d:    // SRL
427                  cpustate->icount -= 5;
428                  cpustate->AC >>= 1;
429                  cpustate->AC |= cpustate->SR & 0x80; // add C/L flag
430                  break;
431         case 0x1e:    // RR
432                  cpustate->icount -= 5;
433                  cpustate->AC =  (cpustate->AC >> 1) | ((cpustate->AC & 0x01) << 7);
434                  break;
435         case 0x1f:    // RRL
436                  cpustate->icount -= 5;
437                  tmp = (cpustate->AC & 0x01) << 7;
438                  cpustate->AC =  (cpustate->AC >> 1) | (cpustate->SR & 0x80);
439                  cpustate->SR = (cpustate->SR & 0x7f) | tmp;
440                  break;
441         // Single Byte Miscellaneous Instructions
442         case 0x00:    // HALT
443                  cpustate->icount -= 8;
444                  devcb_call_write_line(&cpustate->halt_func, 1);
445                  devcb_call_write_line(&cpustate->halt_func, 0);
446                  break;
447         case 0x02:    // CCL
448                  cpustate->icount -= 5;
449                  cpustate->SR &= 0x7f;
450                  break;
451         case 0x03:    // SCL
452                  cpustate->icount -= 5;
453                  cpustate->SR |= 0x80;
454                  break;
455         case 0x04:    // DINT
456                  cpustate->icount -= 6;
457                  cpustate->SR &= 0xf7;
458                  break;
459         case 0x05:    // IEN
460                  cpustate->icount -= 6;
461                  cpustate->SR |= 0x08;
462                  break;
463         case 0x06:    // CSA
464                  cpustate->icount -= 5;
465                  cpustate->SR &= 0xcf; // clear SA and SB flags
466                  cpustate->SR |= devcb_call_read_line(&cpustate->sensea_func) ? 0x10 : 0x00;
467                  cpustate->SR |= devcb_call_read_line(&cpustate->senseb_func) ? 0x20 : 0x00;
468                  cpustate->AC = cpustate->SR;
469                  break;
470         case 0x07:    // CAS
471                  cpustate->icount -= 6;
472                  cpustate->SR = cpustate->AC;
473                  devcb_call_write8(&cpustate->flag_out_func, 0, cpustate->SR & 0x07);
474                  break;
475         case 0x08:    // NOP
476                  cpustate->icount -= 5;
477                  break;
478         // Others are illegal
479         default :    cpustate->icount -= 1;
480                  illegal (cpustate,opcode);
481                  break;
482      }
483   }
484}
485
486
487/***************************************************************************
488    COMMON EXECUTION
489***************************************************************************/
490static void take_interrupt(scmp_state *cpustate)
491{
492   UINT16 tmp = ADD12(cpustate->PC.w.l,-1); // We fix PC so at return it goes to current location
493   cpustate->SR &= 0xf7; // clear IE flag
494
495   cpustate->icount -= 8; // assumption
496   // do XPPC 3
497   cpustate->PC.w.l = GET_PTR_REG(cpustate,3)->w.l;
498   GET_PTR_REG(cpustate,3)->w.l = tmp;
499   // After exchange CPU increment PC
500   cpustate->PC.w.l = ADD12(cpustate->PC.w.l,1);
501}
502
503static CPU_EXECUTE( scmp )
504{
505   scmp_state *cpustate = get_safe_token(device);
506
507   cpustate->icount = cycles;
508
509   do
510   {
511      if ((cpustate->SR & 0x08) && (devcb_call_read_line(&cpustate->sensea_func))) {
512         take_interrupt(cpustate);
513      }
514      debugger_instruction_hook(device, cpustate->PC.d);
515      execute_one(cpustate, ROP(cpustate));
516
517   } while (cpustate->icount > 0);
518
519   return cycles - cpustate->icount;
520}
521
522/***************************************************************************
523    CORE INITIALIZATION
524***************************************************************************/
525
526static CPU_INIT( scmp )
527{
528   scmp_state *cpustate = get_safe_token(device);
529
530   if (device->static_config != NULL)
531      cpustate->config = *(scmp_config *)device->static_config;
532   /* set up the state table */
533   cpustate->state = state_table_template;
534   cpustate->state.baseptr = cpustate;
535   cpustate->state.subtypemask = 1;
536
537   cpustate->device = device;
538
539   cpustate->program = memory_find_address_space(device, ADDRESS_SPACE_PROGRAM);
540
541   /* resolve callbacks */
542   devcb_resolve_write8(&cpustate->flag_out_func, &cpustate->config.flag_out_func, device);
543   devcb_resolve_write_line(&cpustate->sout_func, &cpustate->config.sout_func, device);
544   devcb_resolve_read_line(&cpustate->sin_func, &cpustate->config.sin_func, device);
545   devcb_resolve_read_line(&cpustate->sensea_func, &cpustate->config.sensea_func, device);
546   devcb_resolve_read_line(&cpustate->senseb_func, &cpustate->config.senseb_func, device);
547   devcb_resolve_write_line(&cpustate->halt_func, &cpustate->config.halt_func, device);
548
549   state_save_register_device_item(device, 0, cpustate->PC);
550   state_save_register_device_item(device, 0, cpustate->P1);
551   state_save_register_device_item(device, 0, cpustate->P2);
552   state_save_register_device_item(device, 0, cpustate->P3);
553   state_save_register_device_item(device, 0, cpustate->AC);
554   state_save_register_device_item(device, 0, cpustate->ER);
555   state_save_register_device_item(device, 0, cpustate->SR);
556}
557
558
559
560/***************************************************************************
561    COMMON RESET
562***************************************************************************/
563
564static CPU_RESET( scmp )
565{
566   scmp_state *cpustate = get_safe_token(device);
567
568   cpustate->PC.d = 0;
569   cpustate->P1.d = 0;
570   cpustate->P2.d = 0;
571   cpustate->P3.d = 0;
572   cpustate->AC = 0;
573   cpustate->ER = 0;
574   cpustate->SR = 0;
575}
576
577
578
579/***************************************************************************
580    COMMON STATE IMPORT/EXPORT
581***************************************************************************/
582
583static CPU_IMPORT_STATE( scmp )
584{
585}
586
587static CPU_EXPORT_STATE( scmp )
588{
589}
590
591/***************************************************************************
592    COMMON SET INFO
593***************************************************************************/
594static CPU_SET_INFO( scmp )
595{
596}
597
598/***************************************************************************
599    SCMP GET INFO
600***************************************************************************/
601
602CPU_GET_INFO( scmp )
603{
604   scmp_state *cpustate = (device != NULL && device->token != NULL) ? get_safe_token(device) : NULL;
605   switch (state)
606   {
607      /* --- the following bits of info are returned as 64-bit signed integers --- */
608      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(scmp_state);         break;
609      case CPUINFO_INT_INPUT_LINES:               info->i = 0;                     break;
610      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:         info->i = 0;                     break;
611      case DEVINFO_INT_ENDIANNESS:               info->i = ENDIANNESS_LITTLE;         break;
612      case CPUINFO_INT_CLOCK_MULTIPLIER:            info->i = 1;                     break;
613      case CPUINFO_INT_CLOCK_DIVIDER:               info->i = 1;                     break;
614      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 1;                     break;
615      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 2;                     break;
616      case CPUINFO_INT_MIN_CYCLES:               info->i = 5;                     break;
617      case CPUINFO_INT_MAX_CYCLES:               info->i = 131593;                  break; // DLY instruction max time
618
619      case CPUINFO_INT_DATABUS_WIDTH_PROGRAM:         info->i = 8;                     break;
620      case CPUINFO_INT_ADDRBUS_WIDTH_PROGRAM:       info->i = 16;                     break;
621      case CPUINFO_INT_ADDRBUS_SHIFT_PROGRAM:       info->i = 0;                     break;
622
623      case CPUINFO_INT_DATABUS_WIDTH_DATA:         info->i = 0;                     break;
624      case CPUINFO_INT_ADDRBUS_WIDTH_DATA:          info->i = 0;                     break;
625      case CPUINFO_INT_ADDRBUS_SHIFT_DATA:          info->i = 0;                     break;
626
627      case CPUINFO_INT_DATABUS_WIDTH_IO:            info->i = 0;                     break;
628      case CPUINFO_INT_ADDRBUS_WIDTH_IO:             info->i = 0;                     break;
629      case CPUINFO_INT_ADDRBUS_SHIFT_IO:             info->i = 0;                     break;
630
631      /* --- the following bits of info are returned as pointers to functions --- */
632      case CPUINFO_FCT_SET_INFO:      info->setinfo = CPU_SET_INFO_NAME(scmp);            break;
633      case CPUINFO_FCT_INIT:         info->init = CPU_INIT_NAME(scmp);                  break;
634      case CPUINFO_FCT_RESET:         info->reset = CPU_RESET_NAME(scmp);                  break;
635      case CPUINFO_FCT_EXECUTE:      info->execute = CPU_EXECUTE_NAME(scmp);               break;
636      case CPUINFO_FCT_DISASSEMBLE:   info->disassemble = CPU_DISASSEMBLE_NAME(scmp);         break;
637      case CPUINFO_FCT_IMPORT_STATE:   info->import_state = CPU_IMPORT_STATE_NAME(scmp);      break;
638      case CPUINFO_FCT_EXPORT_STATE:   info->export_state = CPU_EXPORT_STATE_NAME(scmp);      break;
639
640      /* --- the following bits of info are returned as pointers --- */
641      case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &cpustate->icount;      break;
642      case CPUINFO_PTR_STATE_TABLE:               info->state_table = &cpustate->state;   break;
643
644      /* --- the following bits of info are returned as NULL-terminated strings --- */
645      case DEVINFO_STR_NAME:                  strcpy(info->s, "SC/MP");            break;
646      case DEVINFO_STR_FAMILY:               strcpy(info->s, "National Semiconductor SC/MP");         break;
647      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.0");               break;
648      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);            break;
649      case DEVINFO_STR_CREDITS:               strcpy(info->s, "Copyright Miodrag Milanovic"); break;
650
651      case CPUINFO_STR_FLAGS:
652          sprintf(info->s, "%c%c%c%c%c%c%c%c",
653           (cpustate->SR & 0x80) ? 'C' : '.',
654           (cpustate->SR & 0x40) ? 'V' : '.',
655           (cpustate->SR & 0x20) ? 'B' : '.',
656           (cpustate->SR & 0x10) ? 'A' : '.',
657           (cpustate->SR & 0x08) ? 'I' : '.',
658           (cpustate->SR & 0x04) ? '2' : '.',
659           (cpustate->SR & 0x02) ? '1' : '.',
660           (cpustate->SR & 0x01) ? '0' : '.');
661         break;
662   }
663}
src/emu/cpu/scmp/scmp.h
r0r6440
1#ifndef __SCMP_H__
2#define __SCMP_H__
3
4#include "cpuintrf.h"
5#include "devcb.h"
6
7/***************************************************************************
8    CONSTANTS
9***************************************************************************/
10
11enum
12{
13   SCMP_PC, SCMP_P1, SCMP_P2, SCMP_P3, SCMP_AC, SCMP_ER, SCMP_SR,
14   SCMP_GENPC = REG_GENPC,
15   SCMP_GENSP = REG_GENSP,
16   SCMP_GENPCBASE = REG_GENPCBASE
17};
18
19/***************************************************************************
20    TYPE DEFINITIONS
21***************************************************************************/
22typedef struct _scmp_config scmp_config;
23struct _scmp_config
24{
25   devcb_write8      flag_out_func;
26   devcb_write_line   sout_func;
27   devcb_read_line      sin_func;
28   devcb_read_line      sensea_func;
29   devcb_read_line      senseb_func;
30   devcb_write_line   halt_func;
31};
32#define SCMP_CONFIG(name) const scmp_config (name) =
33
34/***************************************************************************
35    FUNCTION PROTOTYPES
36***************************************************************************/
37
38CPU_GET_INFO( scmp );
39#define CPU_SCMP CPU_GET_INFO_NAME( scmp )
40
41CPU_DISASSEMBLE( scmp );
42
43#endif
src/emu/cpu/scmp/scmpdasm.c
r0r6440
1/*****************************************************************************
2 *
3 *   scmpdasm.c
4 *
5 *   National Semiconductor SC/MP CPU Disassembly
6 *
7 *   Initial version by Miodrag Milanovic
8 *
9 *****************************************************************************/
10
11#include "cpuintrf.h"
12
13#define OP(A)   oprom[(A) - PC]
14#define ARG(A)  opram[(A) - PC]
15
16CPU_DISASSEMBLE( scmp )
17{
18   unsigned PC = pc;
19   UINT8 op = OP(pc++);
20   UINT8 ptr = op & 3;
21
22   if (BIT(op,7)) {
23      // two bytes instructions
24      char as[10];
25      char aspr[10];
26      UINT8 arg = ARG(pc); pc++;
27      if (arg==0x80) {
28         sprintf(as,"E");
29      } else {
30         if (arg & 0x80) {
31            sprintf(as,"-$%02x",0x100-arg);
32         } else {
33            sprintf(as,"+$%02x",arg);
34         }
35      }
36      sprintf(aspr,"%s(%d)",as,ptr);
37
38      switch (op)
39      {
40         // Memory Reference Instructions
41         case 0xc0 : sprintf (buffer,"ld %s",as); break;
42         case 0xc1 : case 0xc2 : case 0xc3 :
43                  sprintf (buffer,"ld %s",aspr);break;
44         case 0xc5 : case 0xc6 : case 0xc7 :
45                  sprintf (buffer,"ld @%s",aspr); break;
46         case 0xc8 : sprintf (buffer,"st %s",as); break;
47         case 0xc9 : case 0xca : case 0xcb :
48                  sprintf (buffer,"st %s",aspr);break;
49         case 0xcd : case 0xce : case 0xcf :
50                  sprintf (buffer,"st @%s",aspr); break;
51         case 0xd0 : sprintf (buffer,"and %s",as); break;
52         case 0xd1 : case 0xd2 : case 0xd3 :
53                  sprintf (buffer,"and %s",aspr);break;
54         case 0xd5 : case 0xd6 : case 0xd7 :
55                  sprintf (buffer,"and @%s",aspr); break;
56         case 0xd8 : sprintf (buffer,"or %s",as); break;
57         case 0xd9 : case 0xda : case 0xdb :
58                  sprintf (buffer,"or %s",aspr);break;
59         case 0xdd : case 0xde : case 0xdf :
60                  sprintf (buffer,"or @%s",aspr); break;
61         case 0xe0 : sprintf (buffer,"xor %s",as); break;
62         case 0xe1 : case 0xe2 : case 0xe3 :
63                  sprintf (buffer,"xor %s",aspr);break;
64         case 0xe5 : case 0xe6 : case 0xe7 :
65                  sprintf (buffer,"xor @%s",aspr); break;
66         case 0xe8 : sprintf (buffer,"dad %s",as); break;
67         case 0xe9 : case 0xea : case 0xeb :
68                  sprintf (buffer,"dad %s",aspr);break;
69         case 0xed : case 0xee : case 0xef :
70                  sprintf (buffer,"dad @%s",aspr); break;
71         case 0xf0 : sprintf (buffer,"add %s",as); break;
72         case 0xf1 : case 0xf2 : case 0xf3 :
73                  sprintf (buffer,"add %s",aspr);break;
74         case 0xf5 : case 0xf6 : case 0xf7 :
75                  sprintf (buffer,"add @%s",aspr); break;
76         case 0xf8 : sprintf (buffer,"cad %s",as); break;
77         case 0xf9 : case 0xfa : case 0xfb :
78                  sprintf (buffer,"cad %s",aspr);break;
79         case 0xfd : case 0xfe : case 0xff :
80                  sprintf (buffer,"cad @%s",aspr); break;
81         // Memory Increment/Decrement Instructions
82         case 0xa8 : case 0xa9 : case 0xaa : case 0xab :
83                  sprintf (buffer,"ild %s",aspr); break;
84         case 0xb8 : case 0xb9 : case 0xba : case 0xbb :
85                  sprintf (buffer,"dld %s",aspr); break;
86         // Immediate Instructions
87         case 0xc4 : sprintf (buffer,"ldi $%02x",arg); break;
88         case 0xd4 : sprintf (buffer,"ani $%02x",arg); break;
89         case 0xdc : sprintf (buffer,"ori $%02x",arg); break;
90         case 0xe4 : sprintf (buffer,"xri $%02x",arg); break;
91         case 0xec : sprintf (buffer,"dai $%02x",arg); break;
92         case 0xf4 : sprintf (buffer,"adi $%02x",arg); break;
93         case 0xfc : sprintf (buffer,"cai $%02x",arg); break;
94         // Transfer Instructions
95         case 0x90 : sprintf (buffer,"jmp %s",as);break;
96         case 0x91 : case 0x92 : case 0x93 :
97                  sprintf (buffer,"jmp %s",aspr);break;
98         case 0x94 : sprintf (buffer,"jp %s",as); break;
99         case 0x95 : case 0x96 : case 0x97 :
100                  sprintf (buffer,"jp %s",aspr); break;
101         case 0x98 : sprintf (buffer,"jz %s",as); break;
102         case 0x99 : case 0x9a : case 0x9b :
103                  sprintf (buffer,"jz %s",aspr); break;
104         case 0x9c : sprintf (buffer,"jnz %s",as); break;
105         case 0x9d : case 0x9e : case 0x9f :
106                  sprintf (buffer,"jnz %s",aspr); break;
107         // Double-Byte Miscellaneous Instructions
108         case 0x8f:    sprintf (buffer,"dly $%02x",arg); break;
109         // Others are illegal
110         default : sprintf (buffer,"illegal"); pc--; break; // Illegal we consider without param
111      }
112   } else {
113      // one byte instructions
114      switch (op)
115      {
116         // Extension Register Instructions
117         case 0x40:    sprintf (buffer,"lde"); break;
118         case 0x01:    sprintf (buffer,"xae"); break;
119         case 0x50:    sprintf (buffer,"ane"); break;
120         case 0x58:    sprintf (buffer,"ore"); break;
121         case 0x60:    sprintf (buffer,"xre"); break;
122         case 0x68:    sprintf (buffer,"dae"); break;
123         case 0x70:    sprintf (buffer,"ade"); break;
124         case 0x78:    sprintf (buffer,"cae"); break;
125         // Pointer Register Move Instructions
126         case 0x30:    case 0x31 :case 0x32: case 0x33:
127                  sprintf (buffer,"xpal %d",ptr); break;
128         case 0x34:    case 0x35 :case 0x36: case 0x37:
129                  sprintf (buffer,"xpah %d",ptr); break;
130         case 0x3c:    case 0x3d :case 0x3e: case 0x3f:
131                  sprintf (buffer,"xppc %d",ptr); break;
132         // Shift, Rotate, Serial I/O Instructions
133         case 0x19:    sprintf (buffer,"sio"); break;
134         case 0x1c:    sprintf (buffer,"sr"); break;
135         case 0x1d:    sprintf (buffer,"srl"); break;
136         case 0x1e:    sprintf (buffer,"rr"); break;
137         case 0x1f:    sprintf (buffer,"rrl"); break;
138         // Single Byte Miscellaneous Instructions
139         case 0x00:    sprintf (buffer,"halt"); break;
140         case 0x02:    sprintf (buffer,"ccl"); break;
141         case 0x03:    sprintf (buffer,"scl"); break;
142         case 0x04:    sprintf (buffer,"dint"); break;
143         case 0x05:    sprintf (buffer,"ien"); break;
144         case 0x06:    sprintf (buffer,"csa"); break;
145         case 0x07:    sprintf (buffer,"cas"); break;
146         case 0x08:    sprintf (buffer,"nop"); break;
147         // Others are illegal
148         default : sprintf (buffer,"illegal"); break;
149      }
150   }
151
152   return (pc - PC);
153}
src/emu/cpu/i8008/8008dasm.c
r0r6440
1/*****************************************************************************
2 *
3 *   8008dasm.c
4 *
5 *   Intel 8008 CPU Disassembly
6 *
7 *   Initial version by Miodrag Milanovic
8 *
9 *****************************************************************************/
10
11#include "cpuintrf.h"
12
13#define OP(A)   oprom[(A) - PC]
14#define ARG(A)  opram[(A) - PC]
15
16static char reg[] = { 'a', 'b', 'c', 'd', 'e', 'h', 'l', 'm' };
17static char flag_names[] = { 'c', 'z', 's', 'p' };
18
19CPU_DISASSEMBLE( i8008 )
20{
21   UINT32 flags = 0;
22   unsigned PC = pc;
23   UINT8 op = OP(pc++);
24   switch (op >> 6)
25   {
26      case 0x03:    // starting with 11
27                  if (op==0xff) {
28                  sprintf (buffer,"hlt");
29               } else {
30                     sprintf (buffer,"l%c%c",reg[(op >> 3) & 7],reg[op & 7]);
31                  }
32                  break;
33      case 0x00:    // starting with 00
34               switch(op & 7) {
35                  case 0 :   if(((op >> 3) & 7)==0) {
36                                sprintf (buffer,"hlt");
37                           } else {
38                              if(((op >> 3) & 7)==7) {
39                                 sprintf (buffer,"illegal");
40                              } else {
41                                 sprintf (buffer,"in%c",reg[(op >> 3) & 7]);
42                              }
43                           }
44                           break;
45                  case 1 :   if(((op >> 3) & 7)==0) {
46                                sprintf (buffer,"hlt");
47                           } else {
48                              if(((op >> 3) & 7)==7) {
49                                 sprintf (buffer,"illegal");
50                              } else {
51                                 sprintf (buffer,"dc%c",reg[(op >> 3) & 7]);
52                              }
53                           }
54                           break;
55                  case 2 :   {
56                              switch((op >> 3) & 7) {
57                                 case 0 :   sprintf (buffer,"rlc"); break;
58                                 case 1 :   sprintf (buffer,"rrc"); break;
59                                 case 2 :   sprintf (buffer,"ral"); break;
60                                 case 3 :   sprintf (buffer,"rar"); break;
61                                 default :    sprintf (buffer,"illegal"); break;
62                              }
63                           }
64                           break;
65                  case 3 :   sprintf (buffer,"r%c%c",(BIT(op,5) ? 't' : 'f'),flag_names[(op>>3)&3]); break;
66                  case 4 :   {
67                              switch((op >> 3) & 7) {
68                                 case 0 :   sprintf (buffer,"adi %02x",ARG(pc)); pc++; break;
69                                 case 1 :   sprintf (buffer,"aci %02x",ARG(pc)); pc++; break;
70                                 case 2 :   sprintf (buffer,"sui %02x",ARG(pc)); pc++; break;
71                                 case 3 :   sprintf (buffer,"sbi %02x",ARG(pc)); pc++; break;
72                                 case 4 :   sprintf (buffer,"ndi %02x",ARG(pc)); pc++; break;
73                                 case 5 :   sprintf (buffer,"xri %02x",ARG(pc)); pc++; break;
74                                 case 6 :   sprintf (buffer,"ori %02x",ARG(pc)); pc++; break;
75                                 case 7 :   sprintf (buffer,"cpi %02x",ARG(pc)); pc++; break;
76                              }
77                           }
78                           break;
79                  case 5 :   sprintf (buffer,"rst %02x",(op>>3) & 7); break;
80                  case 6 :    sprintf (buffer,"l%ci %02x",reg[(op >> 3) & 7],ARG(pc)); pc++; break;
81                  case 7 :   sprintf (buffer,"ret"); break;
82               }
83                  break;
84      case 0x01:    // starting with 01
85               switch(op & 7) {
86                  case 0 :   sprintf (buffer,"j%c%c %02x%02x",(BIT(op,5)? 't' : 'f'),flag_names[(op>>3)&3], ARG(pc+1) & 0x3f,ARG(pc)); pc+=2; break;
87                  case 2 :   sprintf (buffer,"c%c%c %02x%02x",(BIT(op,5)? 't' : 'f'),flag_names[(op>>3)&3], ARG(pc+1) & 0x3f,ARG(pc)); pc+=2; break;
88                  case 4 :   sprintf (buffer,"jmp %02x%02x",ARG(pc+1) & 0x3f,ARG(pc)); pc+=2; break;
89                  case 6 :    sprintf (buffer,"cal %02x%02x",ARG(pc+1) & 0x3f,ARG(pc)); pc+=2; break;
90                  case 1 :
91                  case 3 :
92                  case 5 :
93                  case 7 :   if (((op>>4)&3)==0) {
94                              sprintf (buffer,"inp %02x",(op >> 1) & 0x07);
95                           } else {
96                              sprintf (buffer,"out %02x",(op >> 1) & 0x1f);
97                           }
98                           break;
99               }
100                  break;
101      case 0x02:    // starting with 10
102               switch((op >> 3) & 7) {
103                  case 0 :   sprintf (buffer,"ad%c",reg[op & 7]); break;
104                  case 1 :   sprintf (buffer,"ac%c",reg[op & 7]); break;
105                  case 2 :   sprintf (buffer,"su%c",reg[op & 7]); break;
106                  case 3 :   sprintf (buffer,"sb%c",reg[op & 7]); break;
107                  case 4 :   sprintf (buffer,"nd%c",reg[op & 7]); break;
108                  case 5 :   sprintf (buffer,"xr%c",reg[op & 7]); break;
109                  case 6 :   sprintf (buffer,"or%c",reg[op & 7]); break;
110                  case 7 :   sprintf (buffer,"cp%c",reg[op & 7]); break;
111               }
112                  break;
113   }
114   return (pc - PC) | flags | DASMFLAG_SUPPORTED;
115}
src/emu/cpu/i8008/i8008.c
r0r6440
1/*****************************************************************************
2 *
3 *   i8008.c
4 *
5 *   Intel 8008 CPU
6 *
7 *   Initial version by Miodrag Milanovic
8 *
9 *****************************************************************************/
10#include "debugger.h"
11#include "i8008.h"
12
13#define VERBOSE 1
14
15#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
16
17static UINT8 PARITY[256];
18
19/***************************************************************************
20    TYPE DEFINITIONS
21***************************************************************************/
22
23typedef struct _i8008_state i8008_state;
24struct _i8008_state
25{
26   UINT8   A,B,C,D,E,H,L;
27   PAIR   PC; // It is in fact one of ADDR regs
28   PAIR   ADDR[8]; // Address registers
29   UINT8   CF; // Carry flag
30   UINT8   ZF; // Zero flag
31   UINT8   SF; // Sign flag
32   UINT8   PF; // Parity flag
33   UINT8    HALT;
34   const device_config *device;
35   const address_space *program;
36   const address_space *io;
37   cpu_state_table    state;
38   int               icount;
39   int             pc_pos; // PC possition in ADDR
40
41   cpu_irq_callback irq_callback;
42   UINT8         irq_state;
43};
44
45/***************************************************************************
46    MACROS
47***************************************************************************/
48#define REG_1               ((opcode >> 3) & 7)
49#define REG_2               (opcode & 7)
50#define GET_PC               (cpustate->ADDR[cpustate->pc_pos])
51
52/***************************************************************************
53    CPU STATE DESCRIPTION
54***************************************************************************/
55
56#define I8008_STATE_ENTRY(_name, _format, _member, _datamask, _flags) \
57   CPU_STATE_ENTRY(I8008_##_name, #_name, _format, i8008_state, _member, _datamask, ~0, _flags)
58
59static const cpu_state_entry state_array[] =
60{
61   I8008_STATE_ENTRY(PC,   "%04X", PC.w.l, 0x3fff, 0)
62   I8008_STATE_ENTRY(GENPC,"%04X", PC.w.l, 0x3fff, CPUSTATE_NOSHOW)
63   I8008_STATE_ENTRY(A,   "%02X", A, 0xff, 0)
64   I8008_STATE_ENTRY(B,   "%02X", B, 0xff, 0)
65   I8008_STATE_ENTRY(C,   "%02X", C, 0xff, 0)
66   I8008_STATE_ENTRY(D,   "%02X", D, 0xff, 0)
67   I8008_STATE_ENTRY(E,   "%02X", E, 0xff, 0)
68   I8008_STATE_ENTRY(H,   "%02X", H, 0xff, 0)
69   I8008_STATE_ENTRY(L,   "%02X", L, 0xff, 0)
70   I8008_STATE_ENTRY(ADDR1, "%04X", ADDR[0].w.l, 0x0fff, 0)
71   I8008_STATE_ENTRY(ADDR2, "%04X", ADDR[1].w.l, 0x0fff, 0)
72   I8008_STATE_ENTRY(ADDR3, "%04X", ADDR[2].w.l, 0x0fff, 0)
73   I8008_STATE_ENTRY(ADDR4, "%04X", ADDR[3].w.l, 0x0fff, 0)
74   I8008_STATE_ENTRY(ADDR5, "%04X", ADDR[4].w.l, 0x0fff, 0)
75   I8008_STATE_ENTRY(ADDR6, "%04X", ADDR[5].w.l, 0x0fff, 0)
76   I8008_STATE_ENTRY(ADDR7, "%04X", ADDR[6].w.l, 0x0fff, 0)
77   I8008_STATE_ENTRY(ADDR8, "%04X", ADDR[7].w.l, 0x0fff, 0)
78};
79
80static const cpu_state_table state_table_template =
81{
82   NULL,                  /* pointer to the base of state (offsets are relative to this) */
83   0,                     /* subtype this table refers to */
84   ARRAY_LENGTH(state_array),   /* number of entries */
85   state_array               /* array of entries */
86};
87
88/***************************************************************************
89    INLINE FUNCTIONS
90***************************************************************************/
91
92INLINE i8008_state *get_safe_token(const device_config *device)
93{
94   assert(device != NULL);
95   assert(device->token != NULL);
96   assert(device->type == CPU);
97   assert(cpu_get_type(device) == CPU_I8008);
98   return (i8008_state *)device->token;
99}
100
101INLINE void PUSH_STACK(i8008_state *cpustate)
102{
103   cpustate->pc_pos = (cpustate->pc_pos + 1) & 7;
104}
105
106INLINE void POP_STACK(i8008_state *cpustate)
107{
108   cpustate->ADDR[cpustate->pc_pos].d = 0;
109   cpustate->pc_pos = (cpustate->pc_pos - 1) & 7;
110}
111
112INLINE UINT8 ROP(i8008_state *cpustate)
113{
114   UINT8 retVal = memory_decrypted_read_byte(cpustate->program, GET_PC.w.l);
115   GET_PC.w.l = (GET_PC.w.l + 1) & 0x3fff;
116   cpustate->PC = GET_PC;
117   return retVal;
118}
119
120INLINE UINT8 GET_REG(i8008_state *cpustate,UINT8 reg)
121{
122   UINT8 retVal;
123   switch(reg) {
124      case 0 : retVal = cpustate->A; break;
125      case 1 : retVal = cpustate->B; break;
126      case 2 : retVal = cpustate->C; break;
127      case 3 : retVal = cpustate->D; break;
128      case 4 : retVal = cpustate->E; break;
129      case 5 : retVal = cpustate->H; break;
130      case 6 : retVal = cpustate->L; break;
131      default: retVal = memory_read_byte_8le(cpustate->program, (cpustate->H << 8) + cpustate->L); break;
132   }
133   return retVal;
134}
135
136INLINE void SET_REG(i8008_state *cpustate,UINT8 reg, UINT8 val)
137{
138   switch(reg) {
139      case 0 : cpustate->A = val; break;
140      case 1 : cpustate->B = val; break;
141      case 2 : cpustate->C = val; break;
142      case 3 : cpustate->D = val; break;
143      case 4 : cpustate->E = val; break;
144      case 5 : cpustate->H = val; break;
145      case 6 : cpustate->L = val; break;
146      default: memory_write_byte_8le(cpustate->program, (cpustate->H << 8) + cpustate->L, val); break;
147   }
148}
149
150INLINE UINT8 ARG(i8008_state *cpustate)
151{
152   UINT8 retVal = memory_raw_read_byte(cpustate->program, GET_PC.w.l);
153   GET_PC.w.l = (GET_PC.w.l + 1) & 0x3fff;
154   cpustate->PC = GET_PC;
155   return retVal;
156}
157
158INLINE void UPDATE_FLAGS(i8008_state *cpustate,UINT8 val)
159{
160   cpustate->ZF = (val == 0) ? 1 : 0;
161   cpustate->SF = (val & 0x80) ? 1 : 0;
162   cpustate->PF = PARITY[val];
163}
164
165INLINE UINT8 DO_CONDITION(i8008_state *cpustate, UINT8 val)
166{
167   UINT8 v = (val >> 5) & 1;
168   UINT8 cond = 0;
169   switch((val>> 3) & 0x03) {
170      case 0 :
171            if (cpustate->CF==v) cond = 1;
172            break;
173      case 1 :
174            if (cpustate->ZF==v) cond = 1;
175            break;
176      case 2 :
177            if (cpustate->SF==v) cond = 1;
178            break;
179      case 3 :
180            if (cpustate->PF==v) cond = 1;
181            break;
182   }
183   return cond;
184}
185
186INLINE UINT16 GET_ADDR(i8008_state *cpustate)
187{
188   UINT8 lo = ARG(cpustate);
189   UINT8 hi = ARG(cpustate);
190   return ((hi & 0x3f) << 8) + lo;
191}
192
193INLINE void illegal(i8008_state *cpustate,UINT8 opcode)
194{
195#if VERBOSE
196   UINT16 pc = cpustate->PC.w.l;
197   LOG(("I8008 illegal instruction %04X $%02X\n", pc, opcode));
198#endif
199}
200
201static void execute_one(i8008_state *cpustate, int opcode)
202{
203   UINT16 tmp;
204
205   switch (opcode >> 6)
206   {
207      case 0x03:    // starting with 11
208                  if (opcode==0xff) {
209                  // HLT
210                  cpustate->icount -= 4;
211                  GET_PC.w.l = GET_PC.w.l - 1;
212                  cpustate->PC = GET_PC;
213                  cpustate->HALT = 1;
214               } else {
215                  // Lrr
216                  cpustate->icount -= 5;
217                  if (REG_1==7) cpustate->icount -= 2;
218                  if (REG_2==7) cpustate->icount -= 3;
219                  SET_REG(cpustate,REG_1, GET_REG(cpustate,REG_2));
220                  }
221                  break;
222      case 0x00:    // starting with 00
223               switch(opcode & 7) {
224                  case 0 :   if(((opcode >> 3) & 7)==0) {
225                                // HLT
226                              cpustate->icount -= 4;
227                              GET_PC.w.l = GET_PC.w.l - 1;
228                              cpustate->PC = GET_PC;
229                              cpustate->HALT = 1;
230                           } else {
231                              if(((opcode >> 3) & 7)==7) {
232                                 // ILLEGAL
233                                 cpustate->icount -= 5;
234                                 illegal(cpustate,opcode);
235                              } else {
236                                 // INr
237                                 cpustate->icount -= 5;
238                                 tmp = GET_REG(cpustate,REG_1) + 1;
239                                 SET_REG(cpustate,REG_1, tmp & 0xff);
240                                 UPDATE_FLAGS(cpustate,tmp & 0xff);
241                              }
242                           }
243                           break;
244                  case 1 :   if(((opcode >> 3) & 7)==0) {
245                                // HLT
246                              cpustate->icount -= 4;
247                              GET_PC.w.l = GET_PC.w.l - 1;
248                              cpustate->PC = GET_PC;
249                              cpustate->HALT = 1;
250                           } else {
251                              if(((opcode >> 3) & 7)==7) {
252                                 // ILLEGAL
253                                 cpustate->icount -= 5;
254                                 illegal(cpustate,opcode);
255                              } else {
256                                 // DCr
257                                 cpustate->icount -= 5;
258                                 tmp = GET_REG(cpustate,REG_1) - 1;
259                                 SET_REG(cpustate,REG_1, tmp & 0xff);
260                                 UPDATE_FLAGS(cpustate,tmp & 0xff);
261                              }
262                           }
263                           break;
264                  case 2 :   {
265                              // All instuction from this group have same timing
266                              cpustate->icount -= 5;
267                              switch((opcode >> 3) & 7) {
268                                 case 0 :
269                                    // RLC
270                                    tmp = cpustate->A;
271                                    cpustate->A = (cpustate->A << 1) | BIT(tmp,7);
272                                    cpustate->CF = BIT(tmp,7);
273                                    break;
274                                 case 1 :
275                                    // RRC
276                                    tmp = cpustate->A;
277                                    cpustate->A = (cpustate->A >> 1) | (BIT(tmp,0) ? 0x80 : 0x00);
278                                    cpustate->CF = BIT(tmp,0);
279                                    break;
280                                 case 2 :
281                                    // RAL
282                                    tmp = cpustate->A;
283                                    cpustate->A = (cpustate->A << 1) | cpustate->CF;
284                                    cpustate->CF = BIT(tmp,7);
285                                    break;
286                                 case 3 :
287                                    // RAR
288                                    tmp = cpustate->A;
289                                    cpustate->A = (cpustate->A >> 1) | (cpustate->CF ? 0x80 : 0x00);
290                                    cpustate->CF = BIT(tmp,0);
291                                    break;
292                                 default :
293                                    // ILLEGAL
294                                    illegal(cpustate,opcode);
295                                    break;
296                              }
297                           }
298                           break;
299                  case 3 :
300                           // Rcc
301                           {
302                              cpustate->icount -= 3;
303                              if (DO_CONDITION(cpustate,opcode)==1) {
304                                 cpustate->icount -= 2;
305                                 POP_STACK(cpustate);
306                                 cpustate->PC = GET_PC;
307                              }
308                           }
309                           break;
310                  case 4 :   {
311                              cpustate->icount -= 8;
312                              switch((opcode >> 3) & 7) {
313                                 case 0 :
314                                    // ADI
315                                    tmp = GET_REG(cpustate,0) + ARG(cpustate);
316                                    SET_REG(cpustate,0,tmp & 0xff);
317                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
318                                    cpustate->CF = (tmp >> 8) & 1;
319                                    break;
320                                 case 1 :
321                                    // ACI
322                                    tmp = GET_REG(cpustate,0) + ARG(cpustate) + cpustate->CF;
323                                    SET_REG(cpustate,0,tmp & 0xff);
324                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
325                                    cpustate->CF = (tmp >> 8) & 1;
326                                    break;
327                                 case 2 :
328                                    // SUI
329                                    tmp = GET_REG(cpustate,0) - ARG(cpustate);
330                                    SET_REG(cpustate,0,tmp & 0xff);
331                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
332                                    cpustate->CF = (tmp >> 8) & 1;
333                                    break;
334                                 case 3 :
335                                    // SBI
336                                    tmp = GET_REG(cpustate,0) - ARG(cpustate) - cpustate->CF;
337                                    SET_REG(cpustate,0,tmp & 0xff);
338                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
339                                    cpustate->CF = (tmp >> 8) & 1;
340                                    break;
341                                 case 4 :
342                                    // NDI
343                                    tmp = GET_REG(cpustate,0) & ARG(cpustate);
344                                    SET_REG(cpustate,0,tmp & 0xff);
345                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
346                                    break;
347                                 case 5 :
348                                    // XRI
349                                    tmp = GET_REG(cpustate,0) ^ ARG(cpustate);
350                                    SET_REG(cpustate,0,tmp & 0xff);
351                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
352                                    break;
353                                 case 6 :
354                                    // ORI
355                                    tmp = GET_REG(cpustate,0) | ARG(cpustate);
356                                    SET_REG(cpustate,0,tmp & 0xff);
357                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
358                                    break;
359                                 case 7 :
360                                    // CPI
361                                    tmp = GET_REG(cpustate,0) - ARG(cpustate);
362                                    UPDATE_FLAGS(cpustate,tmp & 0xff);
363                                    cpustate->CF = (tmp >> 8) & 1;
364                                    break;
365                              }
366                           }
367                           break;
368                  case 5 :   // RST
369                           cpustate->icount -= 5;
370                           PUSH_STACK(cpustate);
371                           GET_PC.w.l = opcode & 0x38;
372                           cpustate->PC = GET_PC;
373                           break;
374                  case 6 :    // LrI
375                           cpustate->icount -= 8;
376                           if (REG_1==7) cpustate->icount -= 1; // LMI
377                           SET_REG(cpustate,REG_1, ARG(cpustate)); break;
378                  case 7 :   // RET
379                           cpustate->icount -= 5;
380                           POP_STACK(cpustate);
381                           cpustate->PC = GET_PC;
382                     break;
383               }
384                  break;
385
386      case 0x01:    // starting with 01
387               switch(opcode & 7) {
388                  case 0 :
389                     // Jcc
390                     cpustate->icount -= 9;
391                     tmp = GET_ADDR(cpustate);
392                     if (DO_CONDITION(cpustate,opcode)==1) {
393                        cpustate->icount -= 2;
394                        GET_PC.w.l = tmp;
395                        cpustate->PC = GET_PC;
396                     }
397                     break;
398                  case 2 :
399                     // Ccc
400                     cpustate->icount -= 9;
401                     tmp = GET_ADDR(cpustate);
402                     if (DO_CONDITION(cpustate,opcode)==1) {
403                        cpustate->icount -= 2;
404                        PUSH_STACK(cpustate);
405                        GET_PC.w.l = tmp;
406                        cpustate->PC = GET_PC;
407                     }
408                     break;
409                  case 4 :
410                     // JMP
411                     cpustate->icount -= 11;
412                     GET_PC.w.l = GET_ADDR(cpustate);
413                     cpustate->PC = GET_PC;
414                     break;
415                  case 6 :
416                     // CAL
417                     cpustate->icount -= 11;
418                     tmp = GET_ADDR(cpustate);
419                     PUSH_STACK(cpustate);
420                     GET_PC.w.l = tmp;
421                     cpustate->PC = GET_PC;
422                     break;
423                  default :
424                     if (((opcode>>4)&3)==0) {
425                        // INP
426                        cpustate->icount -= 8;
427                        cpustate->A = memory_read_byte_8le(cpustate->io, (opcode >> 1) & 0x1f);
428                     } else {
429                        // OUT
430                        cpustate->icount -= 6;
431                        memory_write_byte_8le(cpustate->io, (opcode >> 1) & 0x1f, cpustate->A);
432                     }
433                     break;
434               }
435                  break;
436      case 0x02:    // starting with 10
437               cpustate->icount -= 5;
438               if ((opcode & 7)==7) cpustate->icount -= 3; // operations with memory
439               switch((opcode >> 3) & 7) {
440                  case 0 :
441                     // ADx
442                     tmp = GET_REG(cpustate,0) + GET_REG(cpustate,opcode & 7);
443                     SET_REG(cpustate,0,tmp & 0xff);
444                     UPDATE_FLAGS(cpustate,tmp & 0xff);
445                     cpustate->CF = (tmp >> 8) & 1;
446                     break;
447                  case 1 :
448                     // ACx
449                     tmp = GET_REG(cpustate,0) + GET_REG(cpustate,opcode & 7) + cpustate->CF;
450                     SET_REG(cpustate,0,tmp & 0xff);
451                     UPDATE_FLAGS(cpustate,tmp & 0xff);
452                     cpustate->CF = (tmp >> 8) & 1;
453                     break;
454                  case 2 :
455                     // SUx
456                     tmp = GET_REG(cpustate,0) - GET_REG(cpustate,opcode & 7);
457                     SET_REG(cpustate,0,tmp & 0xff);
458                     UPDATE_FLAGS(cpustate,tmp & 0xff);
459                     cpustate->CF = (tmp >> 8) & 1;
460                     break;
461                  case 3 :
462                     // SBx
463                     tmp = GET_REG(cpustate,0) - GET_REG(cpustate,opcode & 7) - cpustate->CF;
464                     SET_REG(cpustate,0,tmp & 0xff);
465                     UPDATE_FLAGS(cpustate,tmp & 0xff);
466                     cpustate->CF = (tmp >> 8) & 1;
467                     break;
468                  case 4 :
469                     // NDx
470                     tmp = GET_REG(cpustate,0) & GET_REG(cpustate,opcode & 7);
471                     SET_REG(cpustate,0,tmp & 0xff);
472                     UPDATE_FLAGS(cpustate,tmp & 0xff);
473                     break;
474                  case 5 :
475                     // XRx
476                     tmp = GET_REG(cpustate,0) ^ GET_REG(cpustate,opcode & 7);
477                     SET_REG(cpustate,0,tmp & 0xff);
478                     UPDATE_FLAGS(cpustate,tmp & 0xff);
479                     break;
480                  case 6 :
481                     // ORx
482                     tmp = GET_REG(cpustate,0) | GET_REG(cpustate,opcode & 7);
483                     SET_REG(cpustate,0,tmp & 0xff);
484                     UPDATE_FLAGS(cpustate,tmp & 0xff);
485                     break;
486                  case 7 :
487                     // CPx
488                     tmp = GET_REG(cpustate,0) - GET_REG(cpustate,opcode & 7);
489                     UPDATE_FLAGS(cpustate,tmp & 0xff);
490                     cpustate->CF = (tmp >> 8) & 1;
491                     break;
492               }
493                  break;
494   }
495}
496
497
498/***************************************************************************
499    COMMON EXECUTION
500***************************************************************************/
501static void take_interrupt(i8008_state *cpustate)
502{
503   if (cpustate->HALT) {
504      GET_PC.w.l = (GET_PC.w.l + 1) & 0x3fff;
505      cpustate->PC = GET_PC;
506      cpustate->HALT = 0;
507   }
508   // For now only support one byte operation to be executed
509   execute_one(cpustate,(*cpustate->irq_callback)(cpustate->device, 0));
510}
511
512static CPU_EXECUTE( i8008 )
513{
514   i8008_state *cpustate = get_safe_token(device);
515
516   cpustate->icount = cycles;
517
518   do
519   {
520      if (cpustate->irq_state != CLEAR_LINE) {
521         take_interrupt(cpustate);
522      }
523      debugger_instruction_hook(device, cpustate->PC.d);
524      execute_one(cpustate, ROP(cpustate));
525
526   } while (cpustate->icount > 0);
527
528   return cycles - cpustate->icount;
529}
530
531/***************************************************************************
532    CORE INITIALIZATION
533***************************************************************************/
534static void init_tables (void)
535{
536   int i;
537   UINT8 p;
538   for (i = 0; i < 256; i++)
539   {
540      p = 0;
541      if (BIT(i,0)) p++;
542      if (BIT(i,1)) p++;
543      if (BIT(i,2)) p++;
544      if (BIT(i,3)) p++;
545      if (BIT(i,4)) p++;
546      if (BIT(i,5)) p++;
547      if (BIT(i,6)) p++;
548      if (BIT(i,7)) p++;
549      PARITY[i] = ((p&1) ? 0 : 1);
550   }
551}
552
553static CPU_INIT( i8008 )
554{
555   i8008_state *cpustate = get_safe_token(device);
556
557   /* set up the state table */
558   cpustate->state = state_table_template;
559   cpustate->state.baseptr = cpustate;
560   cpustate->state.subtypemask = 1;
561
562   cpustate->device = device;
563
564   cpustate->program = memory_find_address_space(device, ADDRESS_SPACE_PROGRAM);
565   cpustate->io = memory_find_address_space(device, ADDRESS_SPACE_IO);
566
567   cpustate->irq_callback = irqcallback;
568
569   init_tables();
570
571   state_save_register_device_item(device, 0, cpustate->PC);
572   state_save_register_device_item(device, 0, cpustate->A);
573   state_save_register_device_item(device, 0, cpustate->B);
574   state_save_register_device_item(device, 0, cpustate->C);
575   state_save_register_device_item(device, 0, cpustate->D);
576   state_save_register_device_item(device, 0, cpustate->E);
577   state_save_register_device_item(device, 0, cpustate->H);
578   state_save_register_device_item(device, 0, cpustate->L);
579   state_save_register_device_item(device, 0, cpustate->CF);
580   state_save_register_device_item(device, 0, cpustate->SF);
581   state_save_register_device_item(device, 0, cpustate->ZF);
582   state_save_register_device_item(device, 0, cpustate->PF);
583   state_save_register_device_item(device, 0, cpustate->pc_pos);
584   state_save_register_device_item(device, 0, cpustate->ADDR[0]);
585   state_save_register_device_item(device, 0, cpustate->ADDR[1]);
586   state_save_register_device_item(device, 0, cpustate->ADDR[2]);
587   state_save_register_device_item(device, 0, cpustate->ADDR[3]);
588   state_save_register_device_item(device, 0, cpustate->ADDR[4]);
589   state_save_register_device_item(device, 0, cpustate->ADDR[5]);
590   state_save_register_device_item(device, 0, cpustate->ADDR[6]);
591   state_save_register_device_item(device, 0, cpustate->ADDR[7]);
592   state_save_register_device_item(device, 0, cpustate->HALT);
593   state_save_register_device_item(device, 0, cpustate->irq_state);
594}
595
596
597
598/***************************************************************************
599    COMMON RESET
600***************************************************************************/
601
602static CPU_RESET( i8008 )
603{
604   i8008_state *cpustate = get_safe_token(device);
605
606   cpustate->CF = cpustate->SF = cpustate->ZF = cpustate->PF = 0;
607   cpustate->A = cpustate->B = cpustate->C = cpustate->D = cpustate->E = cpustate->H = cpustate->L = 0;
608   cpustate->PC.d = 0;
609   cpustate->pc_pos = 0;
610   cpustate->HALT = 0;
611   cpustate->irq_state = CLEAR_LINE;
612   memset(cpustate->ADDR,0,sizeof(cpustate->ADDR));
613
614}
615
616/****************************************************************************
617 * Set IRQ line state
618 ****************************************************************************/
619static void set_irq_line(i8008_state *cpustate, int irqline, int state)
620{
621   cpustate->irq_state = state;
622}
623
624/***************************************************************************
625    COMMON STATE IMPORT/EXPORT
626***************************************************************************/
627
628static CPU_IMPORT_STATE( i8008 )
629{
630}
631
632static CPU_EXPORT_STATE( i8008 )
633{
634}
635
636/***************************************************************************
637    COMMON SET INFO
638***************************************************************************/
639static CPU_SET_INFO( i8008 )
640{
641   i8008_state *cpustate = get_safe_token(device);
642   switch (state)
643   {
644      /* --- the following bits of info are set as 64-bit signed integers --- */
645      case CPUINFO_INT_INPUT_STATE + 0:               set_irq_line(cpustate, 0, info->i);            break;
646   }
647}
648
649/***************************************************************************
650    8008 GET INFO
651***************************************************************************/
652
653CPU_GET_INFO( i8008 )
654{
655   i8008_state *cpustate = (device != NULL && device->token != NULL) ? get_safe_token(device) : NULL;
656   switch (state)
657   {
658      /* --- the following bits of info are returned as 64-bit signed integers --- */
659      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(i8008_state);         break;
660      case CPUINFO_INT_INPUT_LINES:               info->i = 0;                     break;
661      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:         info->i = 0;                     break;
662      case DEVINFO_INT_ENDIANNESS:               info->i = ENDIANNESS_LITTLE;         break;
663      case CPUINFO_INT_CLOCK_MULTIPLIER:            info->i = 1;                     break;
664      case CPUINFO_INT_CLOCK_DIVIDER:               info->i = 1;                     break;
665      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 1;                     break;
666      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 3;                     break;
667      case CPUINFO_INT_MIN_CYCLES:               info->i = 8;                     break;
668      case CPUINFO_INT_MAX_CYCLES:               info->i = 16;                     break;
669
670      case CPUINFO_INT_DATABUS_WIDTH_PROGRAM:         info->i = 8;                     break;
671      case CPUINFO_INT_ADDRBUS_WIDTH_PROGRAM:       info->i = 14;                     break;
672      case CPUINFO_INT_ADDRBUS_SHIFT_PROGRAM:       info->i = 0;                     break;
673
674      case CPUINFO_INT_DATABUS_WIDTH_DATA:         info->i = 0;                     break;
675      case CPUINFO_INT_ADDRBUS_WIDTH_DATA:          info->i = 0;                     break;
676      case CPUINFO_INT_ADDRBUS_SHIFT_DATA:          info->i = 0;                     break;
677
678      case CPUINFO_INT_DATABUS_WIDTH_IO:            info->i = 8;                     break;
679      case CPUINFO_INT_ADDRBUS_WIDTH_IO:             info->i = 8;                     break;
680      case CPUINFO_INT_ADDRBUS_SHIFT_IO:             info->i = 0;                     break;
681
682      /* --- the following bits of info are returned as pointers to functions --- */
683      case CPUINFO_FCT_SET_INFO:      info->setinfo = CPU_SET_INFO_NAME(i8008);            break;
684      case CPUINFO_FCT_INIT:         info->init = CPU_INIT_NAME(i8008);                  break;
685      case CPUINFO_FCT_RESET:         info->reset = CPU_RESET_NAME(i8008);               break;
686      case CPUINFO_FCT_EXECUTE:      info->execute = CPU_EXECUTE_NAME(i8008);            break;
687      case CPUINFO_FCT_DISASSEMBLE:   info->disassemble = CPU_DISASSEMBLE_NAME(i8008);      break;
688      case CPUINFO_FCT_IMPORT_STATE:   info->import_state = CPU_IMPORT_STATE_NAME(i8008);      break;
689      case CPUINFO_FCT_EXPORT_STATE:   info->export_state = CPU_EXPORT_STATE_NAME(i8008);      break;
690
691      /* --- the following bits of info are returned as pointers --- */
692      case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &cpustate->icount;      break;
693      case CPUINFO_PTR_STATE_TABLE:               info->state_table = &cpustate->state;   break;
694
695      /* --- the following bits of info are returned as NULL-terminated strings --- */
696      case DEVINFO_STR_NAME:                  strcpy(info->s, "8008");            break;
697      case DEVINFO_STR_FAMILY:               strcpy(info->s, "Intel 8008");         break;
698      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.0");               break;
699      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);            break;
700      case DEVINFO_STR_CREDITS:               strcpy(info->s, "Copyright Miodrag Milanovic"); break;
701
702      case CPUINFO_STR_FLAGS:
703         sprintf(info->s, "%c%c%c%c",
704            cpustate->CF ? 'C':'.',
705            cpustate->ZF ? 'Z':'.',
706            cpustate->SF ? 'S':'.',
707            cpustate->PF ? 'P':'.');
708         break;
709   }
710}
src/emu/cpu/i8008/i8008.h
r0r6440
1#ifndef __I8008_H__
2#define __I8008_H__
3
4#include "cpuintrf.h"
5
6
7/***************************************************************************
8    CONSTANTS
9***************************************************************************/
10
11enum
12{
13   I8008_PC,
14   I8008_A,I8008_B,I8008_C,I8008_D,I8008_E,I8008_H,I8008_L,
15   I8008_ADDR1,I8008_ADDR2,I8008_ADDR3,I8008_ADDR4,I8008_ADDR5,I8008_ADDR6,I8008_ADDR7,I8008_ADDR8,
16   I8008_GENPC = REG_GENPC,
17   I8008_GENSP = REG_GENSP,
18   I8008_GENPCBASE = REG_GENPCBASE
19};
20
21/***************************************************************************
22    TYPE DEFINITIONS
23***************************************************************************/
24
25/***************************************************************************
26    FUNCTION PROTOTYPES
27***************************************************************************/
28
29CPU_GET_INFO( i8008 );
30#define CPU_I8008 CPU_GET_INFO_NAME( i8008 )
31
32CPU_DISASSEMBLE( i8008 );
33#endif

Previous 15994 Revisions Next


© 1998-2018 The MESS Team