*/
// create devices
- first_device = last_device = NULL;
+ //first_device = last_device = nullptr;
dummy = new DEVICE(this, emu); // must be 1st device
event = new EVENT(this, emu); // must be 2nd device
#if defined(_USE_QT)
scsi_host = new SCSI_HOST(this, emu);
for(int i = 0; i < 7; i++) {
- scsi_hdd[i] = NULL;
+ scsi_hdd[i] = nullptr;
}
#if defined(USE_HARD_DISK)
for(int i = 0; i < USE_HARD_DISK; i++) {
#if 0
iccard2 = new TOWNS_ICCARD(this, emu);
#else
- iccard2 = NULL;
+ iccard2 = nullptr;
#endif
for(int i = 0; i < 2; i++) {
joypad_2btn[i] = new JOYPAD_2BTN(this, emu);
cpu->set_context_io(io);
cpu->set_context_intr(pic);
cpu->set_context_dma(dma);
- cpu->set_context_bios(NULL);
+ cpu->set_context_bios(nullptr);
cpu->set_context_extreset(memory, SIG_FMTOWNS_NOTIFY_RESET, 0xffffffff);
#ifdef USE_DEBUGGER
cpu->set_context_debugger(new DEBUGGER(this, emu));
// Vram allocation may be before initialize().
// initialize all devices
#if defined(__GIT_REPO_VERSION)
- strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
+ set_git_repo_version(__GIT_REPO_VERSION);
#endif
// ToDo : Use config framework
int exram_size = config.current_ram_size;
cpu->device_model = INTEL_80386;
#endif
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->initialize();
- }
+ initialize_devices();
// cpu->set_address_mask(0xffffffff);
}
VM::~VM()
{
// delete all devices
- for(DEVICE* device = first_device; device;) {
- DEVICE *next_device = device->next_device;
-// printf("DEVID=%d\n", device->this_device_id);
- device->release();
- delete device;
- device = next_device;
- }
-}
-
-DEVICE* VM::get_device(int id)
-{
- for(DEVICE* device = first_device; device; device = device->next_device) {
- if(device->this_device_id == id) {
- return device;
- }
- }
- return NULL;
+ release_devices();
}
void VM::set_machine_type(uint16_t machine_id, uint16_t cpu_id)
{
- if(memory != NULL) {
+ if(memory != nullptr) {
memory->set_cpu_id(cpu_id);
memory->set_machine_id(machine_id);
}
- if(crtc != NULL) {
+ if(crtc != nullptr) {
crtc->set_cpu_id(cpu_id);
crtc->set_machine_id(machine_id);
}
- if(timer != NULL) {
+ if(timer != nullptr) {
timer->set_cpu_id(cpu_id);
timer->set_machine_id(machine_id);
}
- if(cdrom != NULL) {
+ if(cdrom != nullptr) {
cdrom->set_cpu_id(cpu_id);
cdrom->set_machine_id(machine_id);
}
- if(scsi != NULL) {
+ if(scsi != nullptr) {
scsi->set_cpu_id(cpu_id);
scsi->set_machine_id(machine_id);
}
- if(serialrom != NULL) {
+ if(serialrom != nullptr) {
serialrom->set_cpu_id(cpu_id);
serialrom->set_machine_id(machine_id);
}
- if(floppy != NULL) {
+ if(floppy != nullptr) {
floppy->set_cpu_id(cpu_id);
floppy->set_machine_id(machine_id);
}
#if defined(HAS_20PIX_FONTS)
- if(fontrom_20pix != NULL) {
+ if(fontrom_20pix != nullptr) {
fontrom_20pix->set_cpu_id(cpu_id);
fontrom_20pix->set_machine_id(machine_id);
}
#endif
- if(vram != NULL) {
+ if(vram != nullptr) {
vram->set_cpu_id(cpu_id);
vram->set_machine_id(machine_id);
}
{
// reset all devices
boot_seq = false;
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->reset();
- }
+ VM_TEMPLATE::reset();
// cpu->set_address_mask(0xffffffff);
}
void VM::special_reset(int num)
{
- // reset all devices
boot_seq = true;
-
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->reset();
- }
- keyboard->special_reset(num);
-// cpu->set_address_mask(0xffffffff);
+ // reset all devices
+ VM_TEMPLATE::reset();
+ // cpu->set_address_mask(0xffffffff);
+ if(keyboard != nullptr) {
+ keyboard->special_reset(num);
+ }
}
void VM::run()
{
- event->drive();
+ if(event != nullptr) {
+ event->drive();
+ }
+}
+void VM::process_boot_sequence(uint32_t val)
+{
+ if(boot_seq) {
+ if(val != 0) {
+ if(keyboard != nullptr) {
+ keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff);
+ }
+ boot_seq = false;
+ }
+ }
}
// ----------------------------------------------------------------------------
if(index == 0) {
return cpu;
}
- return NULL;
+ return nullptr;
}
#endif
void VM::draw_screen()
{
- crtc->draw_screen();
-}
-
-uint32_t VM::is_floppy_disk_accessed()
-{
- uint32_t val = fdc->read_signal(0);
- if(boot_seq) {
- if(val != 0) {
- keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff);
- boot_seq = false;
- }
+ if(crtc != nullptr) {
+ crtc->draw_screen();
}
- return val;
}
+
// ----------------------------------------------------------------------------
// soud manager
// ----------------------------------------------------------------------------
void VM::initialize_sound(int rate, int samples)
{
- emu->lock_vm();
+// emu->lock_vm();
// init sound manager
event->initialize_sound(rate, samples);
line_in_ch = event->add_sound_in_source(rate, samples, 2);
mixer->set_context_line_in(line_in_ch, rate, samples);
#endif
- emu->unlock_vm();
+// emu->unlock_vm();
}
uint16_t* VM::create_sound(int* extra_frames)
{
- return event->create_sound(extra_frames);
+ if(event != nullptr) {
+ return event->create_sound(extra_frames);
+ }
+ return VM_TEMPLATE::create_sound(extra_frames);
}
int VM::get_sound_buffer_ptr()
{
- return event->get_sound_buffer_ptr();
+ if(event != nullptr) {
+ return event->get_sound_buffer_ptr();
+ }
+ return VM_TEMPLATE::get_sound_buffer_ptr();
}
void VM::clear_sound_in()
{
+ if(event == nullptr) return;
+
event->clear_sound_in_source(adc_in_ch);
event->clear_sound_in_source(mic_in_ch);
event->clear_sound_in_source(line_in_ch);
int VM::get_sound_in_data(int ch, int32_t* dst, int expect_samples, int expect_rate, int expect_channels)
{
- if(dst == NULL) return 0;
+ if(dst == nullptr) return 0;
if(expect_samples <= 0) return 0;
int n_ch = -1;
switch(ch) {
break;
}
if(n_ch < 0) return 0;
- int samples = event->get_sound_in_data(n_ch, dst, expect_samples, expect_rate, expect_channels);
+ int samples = 0;
+ if(event != nullptr) {
+ samples = event->get_sound_in_data(n_ch, dst, expect_samples, expect_rate, expect_channels);
+ }
return samples;
}
if(n_ch < 0) return 0;
int ss = 0;
- {
+ if(event != nullptr) {
emu->lock_vm();
ss = event->write_sound_in_buffer(n_ch, src, samples);
emu->unlock_vm();
-
}
return ss;
}
void VM::open_hard_disk(int drv, const _TCHAR* file_path)
{
if((drv < USE_HARD_DISK) && (drv < 8) && (drv >= 0)) {
- if(scsi_hdd[drv] != NULL) {
+ if(scsi_hdd[drv] != nullptr) {
scsi_hdd[drv]->open(0, file_path, 512);
}
}
void VM::close_hard_disk(int drv)
{
if((drv < USE_HARD_DISK) && (drv < 8) && (drv >= 0)) {
- if(scsi_hdd[drv] != NULL) {
+ if(scsi_hdd[drv] != nullptr) {
scsi_hdd[drv]->close(0);
}
}
bool VM::is_hard_disk_inserted(int drv)
{
if((drv < USE_HARD_DISK) && (drv < 8) && (drv >= 0)) {
- if(scsi_hdd[drv] != NULL) {
+ if(scsi_hdd[drv] != nullptr) {
return scsi_hdd[drv]->mounted(0);
}
}
uint32_t status = 0;
for(int drv = 0; drv < USE_HARD_DISK; drv++) {
- if(scsi_hdd[drv] != NULL) {
+ if(scsi_hdd[drv] != nullptr) {
if(scsi_hdd[drv]->accessed(0)) {
status |= 1 << drv;
}
}
}
- if(boot_seq) {
- if(status != 0) {
- keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff);
- boot_seq = false;
- }
- }
+ process_boot_sequence(1);
return status;
}
#endif // USE_HARD_DISK
void VM::open_compact_disc(int drv, const _TCHAR* file_path)
{
- cdrom->open(file_path);
+ if(cdrom != nullptr) {
+ cdrom->open(file_path);
+ }
}
void VM::close_compact_disc(int drv)
{
- cdrom->close();
+ if(cdrom != nullptr) {
+ cdrom->close();
+ }
}
bool VM::is_compact_disc_inserted(int drv)
{
+ if(cdrom == nullptr) return false;
return cdrom->mounted();
}
uint32_t VM::is_compact_disc_accessed()
{
uint32_t status = cdrom->accessed();
- if(boot_seq) {
- if(status != 0) {
- keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff);
- boot_seq = false;
- }
- }
+ process_boot_sequence(1);
return status;
}
// if(ch >= 10) ch++;
#endif
if(ch == 0) { // BEEP
- beep->set_volume(0, decibel_l, decibel_r);
+ if(beep != nullptr) {
+ beep->set_volume(0, decibel_l, decibel_r);
+ }
}
else if(ch == 1) { // CD-ROM
if(e_volumes[1] != nullptr) {
e_volumes[1]->set_volumes(0, decibel_l, 1, decibel_r);
- } else {
+ } else if(cdrom != nullptr) {
cdrom->set_volume(0, decibel_l, decibel_r);
}
}
else if(ch == 2) { // OPN2
- opn2->set_volume(0, decibel_l, decibel_r);
+ if(opn2 != nullptr) {
+ opn2->set_volume(0, decibel_l, decibel_r);
+ }
}
else if(ch == 3) { // ADPCM
- rf5c68->set_volume(0, decibel_l, decibel_r);
+ if(rf5c68 != nullptr) {
+ rf5c68->set_volume(0, decibel_l, decibel_r);
+ }
}
else if(ch == 4) { // SEEK, HEAD UP / DOWN
- seek_sound->set_volume(0, decibel_l, decibel_r);
- head_up_sound->set_volume(0, decibel_l, decibel_r);
- head_down_sound->set_volume(0, decibel_l, decibel_r);
+ if(seek_sound != nullptr) {
+ seek_sound->set_volume(0, decibel_l, decibel_r);
+ }
+ if(head_up_sound != nullptr) {
+ head_up_sound->set_volume(0, decibel_l, decibel_r);
+ }
+ if(head_down_sound != nullptr) {
+ head_down_sound->set_volume(0, decibel_l, decibel_r);
+ }
}
-
-
}
#endif
void VM::key_down(int code, bool repeat)
{
- keyboard->key_down(code);
+ if(keyboard != nullptr) {
+ keyboard->key_down(code);
+ }
}
void VM::key_up(int code)
{
- keyboard->key_up(code);
+ if(keyboard != nullptr) {
+ keyboard->key_up(code);
+ }
}
// ----------------------------------------------------------------------------
{
switch(drv) {
case 0:
- if(iccard1 != NULL) {
+ if(iccard1 != nullptr) {
iccard1->open_cart(file_path);
}
break;
case 1:
- if(iccard2 != NULL) {
+ if(iccard2 != nullptr) {
iccard2->open_cart(file_path);
}
break;
{
switch(drv) {
case 0:
- if(iccard1 != NULL) {
+ if(iccard1 != nullptr) {
iccard1->close_cart();
}
break;
case 1:
- if(iccard2 != NULL) {
+ if(iccard2 != nullptr) {
iccard2->close_cart();
}
break;
{
switch(drv) {
case 0:
- if(iccard1 != NULL) {
+ if(iccard1 != nullptr) {
return iccard1->is_cart_inserted();
}
break;
case 1:
- if(iccard2 != NULL) {
+ if(iccard2 != nullptr) {
return iccard2->is_cart_inserted();
}
break;
void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
{
- fdc->open_disk(drv, file_path, bank);
- floppy->change_disk(drv);
+ if(fdc != nullptr) {
+ fdc->open_disk(drv, file_path, bank);
+ floppy->change_disk(drv);
+ }
}
void VM::close_floppy_disk(int drv)
{
- fdc->close_disk(drv);
-// floppy->change_disk(drv);
+ if(fdc != nullptr) {
+ fdc->close_disk(drv);
+ // floppy->change_disk(drv);
+ }
+}
+uint32_t VM::is_floppy_disk_accessed()
+{
+ uint32_t val = fdc->read_signal(0);
+ process_boot_sequence(val);
+ return val;
}
bool VM::is_floppy_disk_inserted(int drv)
{
- return fdc->is_disk_inserted(drv);
+ if(fdc != nullptr) {
+ return fdc->is_disk_inserted(drv);
+ }
+ return VM_TEMPLATE::is_floppy_disk_inserted(drv);
}
void VM::is_floppy_disk_protected(int drv, bool value)
{
- fdc->is_disk_protected(drv, value);
+ if(fdc != nullptr) {
+ fdc->is_disk_protected(drv, value);
+ }
}
bool VM::is_floppy_disk_protected(int drv)
{
- return fdc->is_disk_protected(drv);
+ if(fdc != nullptr) {
+ return fdc->is_disk_protected(drv);
+ }
+ return VM_TEMPLATE::is_floppy_disk_protected(drv);
}
bool VM::is_frame_skippable()
{
- return event->is_frame_skippable();
-}
-
-void VM::update_config()
-{
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->update_config();
+ if(event != nullptr) {
+ return event->is_frame_skippable();
}
+ return VM_TEMPLATE::is_frame_skippable();
}
+
double VM::get_current_usec()
{
- if(event == NULL) return 0.0;
- return event->get_current_usec();
+ if(event != nullptr) {
+ return event->get_current_usec();
+ }
+ return VM_TEMPLATE::get_current_usec();
}
uint64_t VM::get_current_clock_uint64()
{
- if(event == NULL) return (uint64_t)0;
+ if(event != nullptr) {
return event->get_current_clock_uint64();
+ }
+ return VM_TEMPLATE::get_current_clock_uint64();
}
#define STATE_VERSION 4
bool VM::process_state(FILEIO* state_fio, bool loading)
{
- if(!state_fio->StateCheckUint32(STATE_VERSION)) {
- return false;
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- const _TCHAR *name = char_to_tchar(typeid(*device).name() + 6); // skip "class "
- int len = (int)_tcslen(name);
-
- if(!state_fio->StateCheckInt32(len)) {
- if(loading) {
- printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
- }
- return false;
- }
- if(!state_fio->StateCheckBuffer(name, len, 1)) {
- if(loading) {
- printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
- }
- return false;
- }
- if(!device->process_state(state_fio, loading)) {
- if(loading) {
- printf("Data loading Error: DEVID=%d\n", device->this_device_id);
- }
- return false;
- }
- }
+ if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
+ return false;
+ }
+
// Machine specified.
-
state_fio->StateValue(boot_seq);
+ if(loading) {
+ update_config();
+ }
return true;
}
scrntype_t *d_renderbuffer[2][2]; // [bank][layer]
uint32_t renderbuffer_size[2][2];
*/
+ virtual void process_boot_sequence(uint32_t val);
public:
// ----------------------------------------
// initialize
// ----------------------------------------
// drive virtual machine
- void reset();
- void special_reset(int num);
- void run();
+ void reset() override;
+ void special_reset(int num) override;
+ void run() override;
#ifdef USE_DEBUGGER
// debugger
- DEVICE *get_cpu(int index);
+ DEVICE *get_cpu(int index) override;
#endif
// draw screen
- void draw_screen();
+ void draw_screen() override;
// sound generation
- void initialize_sound(int rate, int samples);
- uint16_t* create_sound(int* extra_frames);
- int get_sound_buffer_ptr();
+ void initialize_sound(int rate, int samples) override;
+ uint16_t* create_sound(int* extra_frames) override;
+ int get_sound_buffer_ptr() override;
#ifdef USE_SOUND_VOLUME
- void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
+ void set_sound_device_volume(int ch, int decibel_l, int decibel_r) override;
#endif
// notify key
- void key_down(int code, bool repeat);
- void key_up(int code);
+ void key_down(int code, bool repeat) override;
+ void key_up(int code) override;
// user interface
// CARTs are IC CARD.Will implement something :-)
- void open_cart(int drv, const _TCHAR* file_path);
- void close_cart(int drv);
- bool is_cart_inserted(int drv);
+ void open_cart(int drv, const _TCHAR* file_path) override;
+ void close_cart(int drv) override;
+ bool is_cart_inserted(int drv) override;
- void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
- void close_floppy_disk(int drv);
- uint32_t is_floppy_disk_accessed();
- bool is_floppy_disk_inserted(int drv);
- void is_floppy_disk_protected(int drv, bool value);
- bool is_floppy_disk_protected(int drv);
- bool is_frame_skippable();
-
- void open_compact_disc(int drv, const _TCHAR* file_path);
- void close_compact_disc(int drv);
- bool is_compact_disc_inserted(int drv);
- uint32_t is_compact_disc_accessed();
+ void open_floppy_disk(int drv, const _TCHAR* file_path, int bank) override;
+ void close_floppy_disk(int drv) override;
+ uint32_t is_floppy_disk_accessed() override;
+ bool is_floppy_disk_inserted(int drv) override;
+ void is_floppy_disk_protected(int drv, bool value) override;
+ bool is_floppy_disk_protected(int drv) override;
+ bool is_frame_skippable() override;
+
+ void open_compact_disc(int drv, const _TCHAR* file_path) override;
+ void close_compact_disc(int drv) override;
+ bool is_compact_disc_inserted(int drv) override;
+ uint32_t is_compact_disc_accessed() override;
#if defined(USE_HARD_DISK)
- void open_hard_disk(int drv, const _TCHAR* file_path);
- void close_hard_disk(int drv);
- bool is_hard_disk_inserted(int drv);
- uint32_t is_hard_disk_accessed();
+ void open_hard_disk(int drv, const _TCHAR* file_path) override;
+ void close_hard_disk(int drv) override;
+ bool is_hard_disk_inserted(int drv) override;
+ uint32_t is_hard_disk_accessed() override;
#endif
void set_machine_type(uint16_t machine_id, uint16_t cpu_id);
-
void clear_sound_in();
int get_sound_in_data(int ch, int32_t* dst, int expect_samples, int expect_rate, int expect_channels);
int sound_in(int ch, int32_t* src, int samples);
- double get_current_usec();
- uint64_t get_current_clock_uint64();
+ double get_current_usec() override;
+ uint64_t get_current_clock_uint64() override;
- void update_config();
bool process_state(FILEIO* state_fio, bool loading);
// ----------------------------------------
// ----------------------------------------
// devices
- DEVICE* get_device(int id);
+ //DEVICE* get_device(int id);
//DEVICE* dummy;
//DEVICE* first_device;
//DEVICE* last_device;
};
-