• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revision9c91e6c424bcd3f12bf377eef4f4c9821731ab7f (tree)
Zeit2022-11-28 00:15:10
AutorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[VM][BUBCOM80] Apply new VM APIs.

Ändern Zusammenfassung

Diff

--- a/source/src/vm/bubcom80/bubcom80.cpp
+++ b/source/src/vm/bubcom80/bubcom80.cpp
@@ -50,7 +50,7 @@ using BUBCOM80::RTC;
5050 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
5151 {
5252 // create devices
53- first_device = last_device = NULL;
53+ //first_device = last_device = NULL;
5454 dummy = new DEVICE(this, emu); // must be 1st device
5555 event = new EVENT(this, emu); // must be 2nd device
5656
@@ -148,11 +148,9 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
148148
149149 // initialize all devices
150150 #if defined(__GIT_REPO_VERSION)
151- strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
151+ set_git_repo_version(__GIT_REPO_VERSION);
152152 #endif
153- for(DEVICE* device = first_device; device; device = device->next_device) {
154- device->initialize();
155- }
153+ initialize_devices();
156154
157155 for(int i = 0; i < MAX_DRIVE; i++) {
158156 fdc->set_drive_type(i, DRIVE_TYPE_2HD); // 8inch 2D
@@ -163,23 +161,9 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
163161 VM::~VM()
164162 {
165163 // delete all devices
166- for(DEVICE* device = first_device; device;) {
167- DEVICE *next_device = device->next_device;
168- device->release();
169- delete device;
170- device = next_device;
171- }
164+ release_devices();
172165 }
173166
174-DEVICE* VM::get_device(int id)
175-{
176- for(DEVICE* device = first_device; device; device = device->next_device) {
177- if(device->this_device_id == id) {
178- return device;
179- }
180- }
181- return NULL;
182-}
183167
184168 // ----------------------------------------------------------------------------
185169 // drive virtual machine
@@ -188,9 +172,8 @@ DEVICE* VM::get_device(int id)
188172 void VM::reset()
189173 {
190174 // reset all devices
191- for(DEVICE* device = first_device; device; device = device->next_device) {
192- device->reset();
193- }
175+ VM_TEMPLATE::reset();
176+
194177 ctc->write_io8(0, 0x07); // default frequency for beep
195178 ctc->write_io8(0, 0xef);
196179 pcm->write_signal(SIG_PCM1BIT_ON, 0, 0); // beep off
@@ -198,12 +181,17 @@ void VM::reset()
198181
199182 void VM::run()
200183 {
201- event->drive();
184+ if(event != nullptr) {
185+ event->drive();
186+ }
202187 }
203188
204189 double VM::get_frame_rate()
205190 {
206- return event->get_frame_rate();
191+ if(event != nullptr) {
192+ return event->get_frame_rate();
193+ }
194+ return VM_TEMPLATE::get_frame_rate();
207195 }
208196
209197 // ----------------------------------------------------------------------------
@@ -226,7 +214,9 @@ DEVICE *VM::get_cpu(int index)
226214
227215 void VM::draw_screen()
228216 {
229- display->draw_screen();
217+ if(display != nullptr) {
218+ display->draw_screen();
219+ }
230220 }
231221
232222 // ----------------------------------------------------------------------------
@@ -236,31 +226,45 @@ void VM::draw_screen()
236226 void VM::initialize_sound(int rate, int samples)
237227 {
238228 // init sound manager
239- event->initialize_sound(rate, samples);
229+ if(event != nullptr) {
230+ event->initialize_sound(rate, samples);
231+ }
240232
241233 // init sound gen
242- pcm->initialize_sound(rate, 8000);
234+ if(pcm != nullptr) {
235+ pcm->initialize_sound(rate, 8000);
236+ }
243237 }
244238
245239 uint16_t* VM::create_sound(int* extra_frames)
246240 {
247- return event->create_sound(extra_frames);
241+ if(event != nullptr) {
242+ return event->create_sound(extra_frames);
243+ }
244+ return VM_TEMPLATE::create_sound(extra_frames);
248245 }
249246
250247 int VM::get_sound_buffer_ptr()
251248 {
252- return event->get_sound_buffer_ptr();
249+ if(event != nullptr) {
250+ return event->get_sound_buffer_ptr();
251+ }
252+ return VM_TEMPLATE::get_sound_buffer_ptr();
253253 }
254254
255255 #ifdef USE_SOUND_VOLUME
256256 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
257257 {
258258 if(ch == 0) {
259- pcm->set_volume(0, decibel_l, decibel_r);
259+ if(pcm != nullptr) {
260+ pcm->set_volume(0, decibel_l, decibel_r);
261+ }
260262 } else if(ch == 1) {
261- fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
262- fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
263- fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
263+ if(fdc != nullptr) {
264+ fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
265+ fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
266+ fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
267+ }
264268 }
265269 }
266270 #endif
@@ -271,52 +275,73 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
271275
272276 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
273277 {
274- fdc->open_disk(drv, file_path, bank);
278+ if(fdc != nullptr) {
279+ fdc->open_disk(drv, file_path, bank);
280+ }
275281 }
276282
277283 void VM::close_floppy_disk(int drv)
278284 {
279- fdc->close_disk(drv);
285+ if(fdc != nullptr) {
286+ fdc->close_disk(drv);
287+ }
280288 }
281289
282290 bool VM::is_floppy_disk_inserted(int drv)
283291 {
284- return fdc->is_disk_inserted(drv);
292+ if(fdc != nullptr) {
293+ return fdc->is_disk_inserted(drv);
294+ }
295+ return false;
285296 }
286297
287298 void VM::is_floppy_disk_protected(int drv, bool value)
288299 {
289- fdc->is_disk_protected(drv, value);
300+ if(fdc != nullptr) {
301+ fdc->is_disk_protected(drv, value);
302+ }
290303 }
291304
292305 bool VM::is_floppy_disk_protected(int drv)
293306 {
294- return fdc->is_disk_protected(drv);
307+ if(fdc != nullptr) {
308+ return fdc->is_disk_protected(drv);
309+ }
310+ return false;
295311 }
296312
297313 uint32_t VM::is_floppy_disk_accessed()
298314 {
299- return fdc->read_signal(0);
315+ if(fdc != nullptr) {
316+ return fdc->read_signal(0);
317+ }
318+ return 0;
300319 }
301320
302321 void VM::play_tape(int drv, const _TCHAR* file_path)
303322 {
323+ if(cmt == nullptr) return;
304324 cmt->play_tape(file_path);
305325 }
306326
307327 void VM::rec_tape(int drv, const _TCHAR* file_path)
308328 {
329+ if(cmt == nullptr) return;
309330 cmt->rec_tape(file_path);
310331 }
311332
312333 void VM::close_tape(int drv)
313334 {
335+ if(cmt == nullptr) return;
314336 cmt->close_tape();
315337 }
316338
317339 bool VM::is_tape_inserted(int drv)
318340 {
319- return cmt->is_tape_inserted();
341+ if(cmt != nullptr) {
342+ return cmt->is_tape_inserted();
343+ }
344+ return false;
320345 }
321346
322347 void VM::open_bubble_casette(int drv, const _TCHAR *path, int bank)
@@ -358,58 +383,36 @@ void VM::is_bubble_casette_protected(int drv, bool flag)
358383
359384 bool VM::is_frame_skippable()
360385 {
361- return event->is_frame_skippable();
362-}
363-
364-void VM::update_config()
365-{
366- for(DEVICE* device = first_device; device; device = device->next_device) {
367- device->update_config();
386+ if(event != nullptr) {
387+ return event->is_frame_skippable();
368388 }
389+ return false;
369390 }
370391
392+
371393 double VM::get_current_usec()
372394 {
373- if(event == NULL) return 0.0;
374- return event->get_current_usec();
395+ if(event != nullptr) {
396+ return event->get_current_usec();
397+ }
398+ return VM_TEMPLATE::get_current_usec();
375399 }
376400
377401 uint64_t VM::get_current_clock_uint64()
378402 {
379- if(event == NULL) return (uint64_t)0;
403+ if(event != nullptr) {
380404 return event->get_current_clock_uint64();
405+ }
406+ return VM_TEMPLATE::get_current_clock_uint64();
381407 }
382408
383409 #define STATE_VERSION 1
384410
385411 bool VM::process_state(FILEIO* state_fio, bool loading)
386412 {
387- if(!state_fio->StateCheckUint32(STATE_VERSION)) {
388- return false;
389- }
390- for(DEVICE* device = first_device; device; device = device->next_device) {
391- const _TCHAR *name = char_to_tchar(typeid(*device).name() + 6); // skip "class "
392- int len = (int)_tcslen(name);
393-
394- if(!state_fio->StateCheckInt32(len)) {
395- if(loading) {
396- printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
397- }
398- return false;
399- }
400- if(!state_fio->StateCheckBuffer(name, len, 1)) {
401- if(loading) {
402- printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
403- }
404- return false;
405- }
406- if(!device->process_state(state_fio, loading)) {
407- if(loading) {
408- printf("Data loading Error: DEVID=%d\n", device->this_device_id);
409- }
410- return false;
411- }
412- }
413+ if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
414+ return false;
415+ }
413416 // Machine specified.
414417 if(loading) {
415418 update_config();
--- a/source/src/vm/bubcom80/bubcom80.h
+++ b/source/src/vm/bubcom80/bubcom80.h
@@ -116,48 +116,47 @@ public:
116116 // ----------------------------------------
117117
118118 // drive virtual machine
119- void reset();
120- void run();
121- double get_frame_rate();
119+ void reset() override;
120+ void run() override;
121+ double get_frame_rate() override;
122122
123123 #ifdef USE_DEBUGGER
124124 // debugger
125- DEVICE *get_cpu(int index);
125+ DEVICE *get_cpu(int index) override;
126126 #endif
127127
128128 // draw screen
129- void draw_screen();
129+ void draw_screen() override;
130130
131131 // sound generation
132- void initialize_sound(int rate, int samples);
133- uint16_t* create_sound(int* extra_frames);
134- int get_sound_buffer_ptr();
132+ void initialize_sound(int rate, int samples) override;
133+ uint16_t* create_sound(int* extra_frames) override;
134+ int get_sound_buffer_ptr() override;
135135 #ifdef USE_SOUND_VOLUME
136- void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
136+ void set_sound_device_volume(int ch, int decibel_l, int decibel_r) override;
137137 #endif
138138
139139 // user interface
140- void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
141- void close_floppy_disk(int drv);
142- bool is_floppy_disk_inserted(int drv);
143- void is_floppy_disk_protected(int drv, bool value);
144- bool is_floppy_disk_protected(int drv);
145- uint32_t is_floppy_disk_accessed();
146- void play_tape(int drv, const _TCHAR* file_path);
147- void rec_tape(int drv, const _TCHAR* file_path);
148- void close_tape(int drv);
149- bool is_tape_inserted(int drv);
150- void open_bubble_casette(int drv, const _TCHAR *path, int bank);
151- void close_bubble_casette(int drv);
152- bool is_bubble_casette_inserted(int drv);
153- bool is_bubble_casette_protected(int drv);
154- void is_bubble_casette_protected(int drv, bool flag);
155- bool is_frame_skippable();
140+ void open_floppy_disk(int drv, const _TCHAR* file_path, int bank) override;
141+ void close_floppy_disk(int drv) override;
142+ bool is_floppy_disk_inserted(int drv) override;
143+ void is_floppy_disk_protected(int drv, bool value) override;
144+ bool is_floppy_disk_protected(int drv) override;
145+ uint32_t is_floppy_disk_accessed() override;
146+ void play_tape(int drv, const _TCHAR* file_path) override;
147+ void rec_tape(int drv, const _TCHAR* file_path) override;
148+ void close_tape(int drv) override;
149+ bool is_tape_inserted(int drv) override;
150+ void open_bubble_casette(int drv, const _TCHAR *path, int bank) override;
151+ void close_bubble_casette(int drv) override;
152+ bool is_bubble_casette_inserted(int drv) override;
153+ bool is_bubble_casette_protected(int drv) override;
154+ void is_bubble_casette_protected(int drv, bool flag) override;
155+ bool is_frame_skippable() override;
156156
157- double get_current_usec();
158- uint64_t get_current_clock_uint64();
157+ double get_current_usec() override;
158+ uint64_t get_current_clock_uint64() override;
159159
160- void update_config();
161160 bool process_state(FILEIO* state_fio, bool loading);
162161
163162 // ----------------------------------------
@@ -165,7 +164,7 @@ public:
165164 // ----------------------------------------
166165
167166 // devices
168- DEVICE* get_device(int id);
167+ //DEVICE* get_device(int id) override;
169168 //DEVICE* dummy;
170169 //DEVICE* first_device;
171170 //DEVICE* last_device;
Show on old repository browser