OSDN Git Service

[VM][LIBCPU_NEWDEV][i386] Fix FTBFS.
[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         DEVICE::initialize();
17         cpucore = new I386_OPS_BASE;
18         cpucore->cpu_init_i386();
19         cpucore->set_context_pic(d_pic);
20         cpucore->set_context_progmem(d_mem);
21         cpucore->set_context_io(d_io);
22         cpucore->set_shutdown_flag(0);
23 }
24
25 void I386_BASE::release()
26 {
27         cpucore->i386_vtlb_free();
28         cpucore->i386_free_state();
29         delete cpucore;
30 }
31
32 void I386_BASE::reset()
33 {
34         cpucore->cpu_reset_i386();
35 }
36
37 int I386_BASE::run(int cycles)
38 {
39         return cpucore->cpu_execute_i386(cycles);
40 }
41
42 void I386_BASE::write_signal(int id, uint32_t data, uint32_t mask)
43 {
44         if(id == SIG_CPU_NMI) {
45                 cpucore->i386_set_irq_line( INPUT_LINE_NMI, (data & mask) ? HOLD_LINE : CLEAR_LINE);
46         } else if(id == SIG_CPU_IRQ) {
47                 cpucore->i386_set_irq_line( INPUT_LINE_IRQ, (data & mask) ? HOLD_LINE : CLEAR_LINE);
48         } else if(id == SIG_CPU_BUSREQ) {
49                 cpucore->set_busreq(((data & mask) != 0));
50         } else if(id == SIG_I386_A20) {
51                 cpucore->i386_set_a20_line( data & mask);
52         }
53 }
54
55 void I386_BASE::set_intr_line(bool line, bool pending, uint32_t bit)
56 {
57         cpucore->i386_set_irq_line(INPUT_LINE_IRQ, line ? HOLD_LINE : CLEAR_LINE);
58 }
59
60 void I386_BASE::set_extra_clock(int cycles)
61 {
62         cpucore->set_extra_clock(cycles);
63 }
64
65 int I386_BASE::get_extra_clock()
66 {
67         return cpucore->get_extra_clock();
68 }
69
70 uint32_t I386_BASE::get_pc()
71 {
72         return cpucore->get_prev_pc();
73 }
74
75 uint32_t I386_BASE::get_next_pc()
76 {
77         return cpucore->get_pc();
78 }
79
80 void I386_BASE::set_address_mask(uint32_t mask)
81 {
82         cpucore->set_address_mask(mask);
83        
84         // TODO: how does A20M and the tlb interact
85         cpucore->vtlb_flush_dynamic();
86 }
87
88 uint32_t I386_BASE::get_address_mask()
89 {
90         return cpucore->get_address_mask();
91 }
92 void I386_BASE::set_shutdown_flag(int shutdown)
93 {
94         cpucore->set_shutdown_flag(shutdown);
95 }
96
97 int I386_BASE::get_shutdown_flag()
98 {
99         return cpucore->get_shutdown_flag();
100 }
101
102 void I386_BASE::set_context_mem(DEVICE* device)
103 {
104         d_mem = device;
105         if(cpucore != NULL) cpucore->set_context_progmem(d_mem);
106 }
107
108 void I386_BASE::set_context_io(DEVICE* device)
109 {
110         d_io = device;
111         if(cpucore != NULL) cpucore->set_context_io(d_io);
112 }
113
114 void I386_BASE::set_context_intr(DEVICE* device)
115 {
116         d_pic = device;
117         if(cpucore != NULL) cpucore->set_context_pic(d_pic);
118 }
119
120
121 #include "../../fileio.h"
122
123 #define STATE_VERSION   1
124
125 void I386_BASE::save_state(FILEIO* state_fio)
126 {
127         state_fio->FputUint32(STATE_VERSION);
128         state_fio->FputInt32(this_device_id);
129         cpucore->save_state(state_fio);
130 }
131
132 bool I386_BASE::load_state(FILEIO* state_fio)
133 {
134         if(state_fio->FgetUint32() != STATE_VERSION) {
135                 return false;
136         }
137         if(state_fio->FgetInt32() != this_device_id) {
138                 return false;
139         }
140         cpucore->load_state(state_fio);
141         
142         // post process
143         cpucore->set_context_pic(d_pic);
144         cpucore->set_context_progmem(d_mem);
145         cpucore->set_context_io(d_io);
146
147         return true;
148 }
149