OSDN Git Service

[VM][FMTOWNS] Add FONT ROMS, MSDOS ROM, SYSTEM ROM and SERIAL ROM.
[csp-qt/common_source_project-fm7.git] / source / src / vm / huc6280.cpp
1 /*
2         Skelton for retropc emulator
3
4         Origin : MESS 0.147
5         Author : Takeda.Toshiya
6         Date   : 2012.10.23-
7
8         [ HuC6280 ]
9 */
10
11 #include "huc6280.h"
12 #ifdef USE_DEBUGGER
13 #include "debugger.h"
14 #endif
15
16 /* ----------------------------------------------------------------------------
17         MAME h6280
18 ---------------------------------------------------------------------------- */
19
20 #define INLINE inline
21 #define PAIR pair32_t
22 #define offs_t UINT16
23
24 /*****************************************************************************/
25 /* src/emu/devcpu.h */
26
27 // CPU interface functions
28 #define READ8_HANDLER(name)                     UINT8 name(h6280_Regs *cpustate, offs_t offset)
29 #define WRITE8_HANDLER(name)                    void name(h6280_Regs *cpustate, offs_t offset, UINT8 data)
30
31 #include "mame/emu/cpu/h6280/h6280.h"
32 //#include "mame/emu/cpu/h6280/h6280.c"
33 //#ifdef USE_DEBUGGER
34 //#include "mame/emu/cpu/h6280/6280dasm.c"
35 //#endif
36
37
38 void HUC6280::initialize()
39 {
40         HUC6280_BASE::initialize();
41         
42 #ifdef USE_DEBUGGER
43         h6280_Regs *cpustate = (h6280_Regs *)opaque;
44         cpustate->emu = emu;
45         cpustate->debugger = d_debugger;
46         cpustate->program_stored = d_mem;
47         cpustate->io_stored = d_io;
48         
49         d_debugger->set_context_mem(d_mem);
50         d_debugger->set_context_io(d_io);
51 #endif
52 }
53
54 void HUC6280::release()
55 {
56         free(opaque);
57 }
58
59 void HUC6280::reset()
60 {
61         HUC6280_BASE::reset();
62 #ifdef USE_DEBUGGER
63         h6280_Regs *cpustate = (h6280_Regs *)opaque;
64         cpustate->emu = emu;
65         cpustate->debugger = d_debugger;
66         cpustate->program_stored = d_mem;
67         cpustate->io_stored = d_io;
68 #endif
69 }
70
71 int HUC6280::run(int clock)
72 {
73         h6280_Regs *cpustate = (h6280_Regs *)opaque;
74         
75         if(clock == -1) {
76                 if(busreq) {
77                         // don't run cpu!
78 #ifdef USE_DEBUGGER
79                         total_icount += 1;
80 #endif
81                         return 1;
82                 } else {
83                         // run only one opcode
84                         return run_one_opecode();
85                 }
86         } else {
87                 icount += clock;
88                 int first_icount = icount;
89                 
90                 // run cpu while given clocks
91                 while(icount > 0 && !busreq) {
92                         icount -= run_one_opecode();
93                 }
94                 // if busreq is raised, spin cpu while remained clock
95                 if(icount > 0 && busreq) {
96 #ifdef USE_DEBUGGER
97                         total_icount += icount;
98 #endif
99                         icount = 0;
100                 }
101                 return first_icount - icount;
102         }
103 }
104
105
106 int HUC6280::run_one_opecode()
107 {
108         h6280_Regs *cpustate = (h6280_Regs *)opaque;
109 #ifdef USE_DEBUGGER
110         d_debugger->add_cpu_trace(cpustate->pc.w.l);
111 #endif
112         int passed_icount = HUC6280_BASE::run_one_opecode();
113 #ifdef USE_DEBUGGER
114         total_icount += passed_icount;
115 #endif
116         return passed_icount;
117 }
118
119 #define STATE_VERSION   5
120
121 bool HUC6280::process_state(FILEIO* state_fio, bool loading)
122 {
123         h6280_Regs *cpustate = (h6280_Regs *)opaque;
124         
125         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
126                 return false;
127         }
128         if(!state_fio->StateCheckInt32(this_device_id)) {
129                 return false;
130         }
131         state_fio->StateValue(cpustate->ICount);
132         state_fio->StateValue(cpustate->ppc);
133         state_fio->StateValue(cpustate->pc);
134         state_fio->StateValue(cpustate->sp);
135         state_fio->StateValue(cpustate->zp);
136         state_fio->StateValue(cpustate->ea);
137         state_fio->StateValue(cpustate->a);
138         state_fio->StateValue(cpustate->x);
139         state_fio->StateValue(cpustate->y);
140         state_fio->StateValue(cpustate->p);
141         state_fio->StateArray(cpustate->mmr, sizeof(cpustate->mmr), 1);
142         state_fio->StateValue(cpustate->irq_mask);
143         state_fio->StateValue(cpustate->timer_status);
144         state_fio->StateValue(cpustate->timer_ack);
145         state_fio->StateValue(cpustate->clocks_per_cycle);
146         state_fio->StateValue(cpustate->timer_value);
147         state_fio->StateValue(cpustate->timer_load);
148         state_fio->StateValue(cpustate->nmi_state);
149         state_fio->StateArray(cpustate->irq_state, sizeof(cpustate->irq_state), 1);
150         state_fio->StateValue(cpustate->irq_pending);
151 #if LAZY_FLAGS
152         state_fio->StateValue(cpustate->NZ);
153 #endif
154 #ifdef USE_DEBUGGER
155         state_fio->StateValue(total_icount);
156 #endif
157         state_fio->StateValue(icount);
158         state_fio->StateValue(busreq);
159         
160 #ifdef USE_DEBUGGER
161         if(loading) {
162                 prev_total_icount = total_icount;
163         }
164 #endif
165         return true;
166 }
167
168