OSDN Git Service

Merge branch 'master' of github.com:Artanejp/common_source_project-fm7
[csp-qt/common_source_project-fm7.git] / source / src / vm / libcpu_newdev / i386_base.cpp
1 /*
2         Skelton for retropc emulator
3
4         Origin : MAME i386 core
5         Author : Takeda.Toshiya
6         Date  : 2009.06.08-
7
8         [ i386/i486/Pentium/MediaGX ]
9 */
10
11 #include "i386_base.h"
12 #include "libcpu_i386/i386_opdef.h"
13
14 void I386_BASE::initialize()
15 {
16         cpucore = new I386_OPS_BASE;
17         cpucore->cpu_init_i386();
18         cpucore->set_context_pic(d_pic);
19         cpucore->set_context_progmem(d_mem);
20         cpucore->set_context_io(d_io);
21         cpucore->set_shutdown_flag(0);
22 }
23
24 void I386_BASE::release()
25 {
26         cpucore->i386_vtlb_free();
27         cpucore->i386_free_state();
28         delete cpucore;
29 }
30
31 void I386_BASE::reset()
32 {
33         cpucore->cpu_reset_i386();
34 }
35
36 int I386_BASE::run(int cycles)
37 {
38         return cpucore->cpu_execute_i386(cycles);
39 }
40
41 void I386_BASE::write_signal(int id, uint32_t data, uint32_t mask)
42 {
43         if(id == SIG_CPU_NMI) {
44                 cpucore->i386_set_irq_line( INPUT_LINE_NMI, (data & mask) ? HOLD_LINE : CLEAR_LINE);
45         } else if(id == SIG_CPU_IRQ) {
46                 cpucore->i386_set_irq_line( INPUT_LINE_IRQ, (data & mask) ? HOLD_LINE : CLEAR_LINE);
47         } else if(id == SIG_CPU_BUSREQ) {
48                 cpucore->set_busreq(((data & mask) != 0));
49         } else if(id == SIG_I386_A20) {
50                 cpucore->i386_set_a20_line( data & mask);
51         }
52 }
53
54 void I386_BASE::set_intr_line(bool line, bool pending, uint32_t bit)
55 {
56         cpucore->i386_set_irq_line(INPUT_LINE_IRQ, line ? HOLD_LINE : CLEAR_LINE);
57 }
58
59 void I386_BASE::set_extra_clock(int cycles)
60 {
61         cpucore->set_extra_clock(cycles);
62 }
63
64 int I386_BASE::get_extra_clock()
65 {
66         return cpucore->get_extra_clock();
67 }
68
69 uint32_t I386_BASE::get_pc()
70 {
71         return cpucore->get_prev_pc();
72 }
73
74 uint32_t I386_BASE::get_next_pc()
75 {
76         return cpucore->get_pc();
77 }
78
79 void I386_BASE::set_address_mask(uint32_t mask)
80 {
81         cpucore->set_address_mask(mask);
82 }
83
84 uint32_t I386_BASE::get_address_mask()
85 {
86         return cpucore->get_address_mask();
87 }
88 void I386_BASE::set_shutdown_flag(int shutdown)
89 {
90         cpucore->set_shutdown_flag(shutdown);
91 }
92
93 int I386_BASE::get_shutdown_flag()
94 {
95         return cpucore->get_shutdown_flag();
96 }
97
98 void I386_BASE::set_context_mem(DEVICE* device)
99 {
100         d_mem = device;
101         if(cpucore != NULL) cpucore->set_context_progmem(d_mem);
102 }
103
104 void I386_BASE::set_context_io(DEVICE* device)
105 {
106         d_io = device;
107         if(cpucore != NULL) cpucore->set_context_io(d_io);
108 }
109
110 void I386_BASE::set_context_intr(DEVICE* device)
111 {
112         d_pic = device;
113         if(cpucore != NULL) cpucore->set_context_pic(d_pic);
114 }
115
116
117 #include "../../fileio.h"
118
119 #define STATE_VERSION   1
120
121 void I386_BASE::save_state(FILEIO* state_fio)
122 {
123         state_fio->FputUint32(STATE_VERSION);
124         state_fio->FputInt32(this_device_id);
125         cpucore->save_state(state_fio);
126 }
127
128 bool I386_BASE::load_state(FILEIO* state_fio)
129 {
130         if(state_fio->FgetUint32() != STATE_VERSION) {
131                 return false;
132         }
133         if(state_fio->FgetInt32() != this_device_id) {
134                 return false;
135         }
136         cpucore->load_state(state_fio);
137         
138         // post process
139         cpucore->set_context_pic(d_pic);
140         cpucore->set_context_progmem(d_mem);
141         cpucore->set_context_io(d_io);
142
143         return true;
144 }
145