Common Source Code Project for Qt (a.k.a for FM-7).
Revision | bae0d67985f7e093591809d0222981108e1dda3c (tree) |
---|---|
Zeit | 2022-11-28 00:58:18 |
Autor | K.Ohta <whatisthis.sowhat@gmai...> |
Commiter | K.Ohta |
[VM][FMTOWNS] Apply NEW APIs.
@@ -125,7 +125,7 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu) | ||
125 | 125 | */ |
126 | 126 | |
127 | 127 | // create devices |
128 | - first_device = last_device = NULL; | |
128 | + //first_device = last_device = nullptr; | |
129 | 129 | dummy = new DEVICE(this, emu); // must be 1st device |
130 | 130 | event = new EVENT(this, emu); // must be 2nd device |
131 | 131 | #if defined(_USE_QT) |
@@ -188,7 +188,7 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu) | ||
188 | 188 | scsi_host = new SCSI_HOST(this, emu); |
189 | 189 | |
190 | 190 | for(int i = 0; i < 7; i++) { |
191 | - scsi_hdd[i] = NULL; | |
191 | + scsi_hdd[i] = nullptr; | |
192 | 192 | } |
193 | 193 | #if defined(USE_HARD_DISK) |
194 | 194 | for(int i = 0; i < USE_HARD_DISK; i++) { |
@@ -215,7 +215,7 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu) | ||
215 | 215 | #if 0 |
216 | 216 | iccard2 = new TOWNS_ICCARD(this, emu); |
217 | 217 | #else |
218 | - iccard2 = NULL; | |
218 | + iccard2 = nullptr; | |
219 | 219 | #endif |
220 | 220 | for(int i = 0; i < 2; i++) { |
221 | 221 | joypad_2btn[i] = new JOYPAD_2BTN(this, emu); |
@@ -458,7 +458,7 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu) | ||
458 | 458 | cpu->set_context_io(io); |
459 | 459 | cpu->set_context_intr(pic); |
460 | 460 | cpu->set_context_dma(dma); |
461 | - cpu->set_context_bios(NULL); | |
461 | + cpu->set_context_bios(nullptr); | |
462 | 462 | cpu->set_context_extreset(memory, SIG_FMTOWNS_NOTIFY_RESET, 0xffffffff); |
463 | 463 | #ifdef USE_DEBUGGER |
464 | 464 | cpu->set_context_debugger(new DEBUGGER(this, emu)); |
@@ -652,7 +652,7 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu) | ||
652 | 652 | // Vram allocation may be before initialize(). |
653 | 653 | // initialize all devices |
654 | 654 | #if defined(__GIT_REPO_VERSION) |
655 | - strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1); | |
655 | + set_git_repo_version(__GIT_REPO_VERSION); | |
656 | 656 | #endif |
657 | 657 | // ToDo : Use config framework |
658 | 658 | int exram_size = config.current_ram_size; |
@@ -688,71 +688,53 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu) | ||
688 | 688 | cpu->device_model = INTEL_80386; |
689 | 689 | #endif |
690 | 690 | |
691 | - for(DEVICE* device = first_device; device; device = device->next_device) { | |
692 | - device->initialize(); | |
693 | - } | |
691 | + initialize_devices(); | |
694 | 692 | // cpu->set_address_mask(0xffffffff); |
695 | 693 | } |
696 | 694 | |
697 | 695 | VM::~VM() |
698 | 696 | { |
699 | 697 | // delete all devices |
700 | - for(DEVICE* device = first_device; device;) { | |
701 | - DEVICE *next_device = device->next_device; | |
702 | -// printf("DEVID=%d\n", device->this_device_id); | |
703 | - device->release(); | |
704 | - delete device; | |
705 | - device = next_device; | |
706 | - } | |
707 | -} | |
708 | - | |
709 | -DEVICE* VM::get_device(int id) | |
710 | -{ | |
711 | - for(DEVICE* device = first_device; device; device = device->next_device) { | |
712 | - if(device->this_device_id == id) { | |
713 | - return device; | |
714 | - } | |
715 | - } | |
716 | - return NULL; | |
698 | + release_devices(); | |
717 | 699 | } |
718 | 700 | |
719 | 701 | void VM::set_machine_type(uint16_t machine_id, uint16_t cpu_id) |
720 | 702 | { |
721 | - if(memory != NULL) { | |
703 | + if(memory != nullptr) { | |
722 | 704 | memory->set_cpu_id(cpu_id); |
723 | 705 | memory->set_machine_id(machine_id); |
724 | 706 | } |
725 | - if(crtc != NULL) { | |
707 | + if(crtc != nullptr) { | |
726 | 708 | crtc->set_cpu_id(cpu_id); |
727 | 709 | crtc->set_machine_id(machine_id); |
728 | 710 | } |
729 | - if(timer != NULL) { | |
711 | + if(timer != nullptr) { | |
730 | 712 | timer->set_cpu_id(cpu_id); |
731 | 713 | timer->set_machine_id(machine_id); |
732 | 714 | } |
733 | - if(cdrom != NULL) { | |
715 | + if(cdrom != nullptr) { | |
734 | 716 | cdrom->set_cpu_id(cpu_id); |
735 | 717 | cdrom->set_machine_id(machine_id); |
736 | 718 | } |
737 | - if(scsi != NULL) { | |
719 | + if(scsi != nullptr) { | |
738 | 720 | scsi->set_cpu_id(cpu_id); |
739 | 721 | scsi->set_machine_id(machine_id); |
740 | 722 | } |
741 | - if(serialrom != NULL) { | |
723 | + if(serialrom != nullptr) { | |
742 | 724 | serialrom->set_cpu_id(cpu_id); |
743 | 725 | serialrom->set_machine_id(machine_id); |
744 | 726 | } |
745 | - if(floppy != NULL) { | |
727 | + if(floppy != nullptr) { | |
746 | 728 | floppy->set_cpu_id(cpu_id); |
747 | 729 | floppy->set_machine_id(machine_id); |
748 | 730 | } |
749 | 731 | #if defined(HAS_20PIX_FONTS) |
750 | - if(fontrom_20pix != NULL) { | |
732 | + if(fontrom_20pix != nullptr) { | |
751 | 733 | fontrom_20pix->set_cpu_id(cpu_id); |
752 | 734 | fontrom_20pix->set_machine_id(machine_id); |
753 | 735 | } |
754 | 736 | #endif |
755 | - if(vram != NULL) { | |
737 | + if(vram != nullptr) { | |
756 | 738 | vram->set_cpu_id(cpu_id); |
757 | 739 | vram->set_machine_id(machine_id); |
758 | 740 | } |
@@ -768,28 +750,38 @@ void VM::reset() | ||
768 | 750 | { |
769 | 751 | // reset all devices |
770 | 752 | boot_seq = false; |
771 | - for(DEVICE* device = first_device; device; device = device->next_device) { | |
772 | - device->reset(); | |
773 | - } | |
753 | + VM_TEMPLATE::reset(); | |
774 | 754 | // cpu->set_address_mask(0xffffffff); |
775 | 755 | } |
776 | 756 | |
777 | 757 | void VM::special_reset(int num) |
778 | 758 | { |
779 | - // reset all devices | |
780 | 759 | boot_seq = true; |
781 | - | |
782 | - for(DEVICE* device = first_device; device; device = device->next_device) { | |
783 | - device->reset(); | |
784 | - } | |
785 | - keyboard->special_reset(num); | |
786 | 760 | |
787 | -// cpu->set_address_mask(0xffffffff); | |
761 | + // reset all devices | |
762 | + VM_TEMPLATE::reset(); | |
763 | + // cpu->set_address_mask(0xffffffff); | |
764 | + if(keyboard != nullptr) { | |
765 | + keyboard->special_reset(num); | |
766 | + } | |
788 | 767 | } |
789 | 768 | |
790 | 769 | void VM::run() |
791 | 770 | { |
792 | - event->drive(); | |
771 | + if(event != nullptr) { | |
772 | + event->drive(); | |
773 | + } | |
774 | +} | |
775 | +void VM::process_boot_sequence(uint32_t val) | |
776 | +{ | |
777 | + if(boot_seq) { | |
778 | + if(val != 0) { | |
779 | + if(keyboard != nullptr) { | |
780 | + keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff); | |
781 | + } | |
782 | + boot_seq = false; | |
783 | + } | |
784 | + } | |
793 | 785 | } |
794 | 786 | |
795 | 787 | // ---------------------------------------------------------------------------- |
@@ -802,7 +794,7 @@ DEVICE *VM::get_cpu(int index) | ||
802 | 794 | if(index == 0) { |
803 | 795 | return cpu; |
804 | 796 | } |
805 | - return NULL; | |
797 | + return nullptr; | |
806 | 798 | } |
807 | 799 | #endif |
808 | 800 |
@@ -812,28 +804,19 @@ DEVICE *VM::get_cpu(int index) | ||
812 | 804 | |
813 | 805 | void VM::draw_screen() |
814 | 806 | { |
815 | - crtc->draw_screen(); | |
816 | -} | |
817 | - | |
818 | -uint32_t VM::is_floppy_disk_accessed() | |
819 | -{ | |
820 | - uint32_t val = fdc->read_signal(0); | |
821 | - if(boot_seq) { | |
822 | - if(val != 0) { | |
823 | - keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff); | |
824 | - boot_seq = false; | |
825 | - } | |
807 | + if(crtc != nullptr) { | |
808 | + crtc->draw_screen(); | |
826 | 809 | } |
827 | - return val; | |
828 | 810 | } |
829 | 811 | |
812 | + | |
830 | 813 | // ---------------------------------------------------------------------------- |
831 | 814 | // soud manager |
832 | 815 | // ---------------------------------------------------------------------------- |
833 | 816 | |
834 | 817 | void VM::initialize_sound(int rate, int samples) |
835 | 818 | { |
836 | - emu->lock_vm(); | |
819 | +// emu->lock_vm(); | |
837 | 820 | // init sound manager |
838 | 821 | event->initialize_sound(rate, samples); |
839 | 822 |
@@ -864,21 +847,29 @@ void VM::initialize_sound(int rate, int samples) | ||
864 | 847 | line_in_ch = event->add_sound_in_source(rate, samples, 2); |
865 | 848 | mixer->set_context_line_in(line_in_ch, rate, samples); |
866 | 849 | #endif |
867 | - emu->unlock_vm(); | |
850 | +// emu->unlock_vm(); | |
868 | 851 | } |
869 | 852 | |
870 | 853 | uint16_t* VM::create_sound(int* extra_frames) |
871 | 854 | { |
872 | - return event->create_sound(extra_frames); | |
855 | + if(event != nullptr) { | |
856 | + return event->create_sound(extra_frames); | |
857 | + } | |
858 | + return VM_TEMPLATE::create_sound(extra_frames); | |
873 | 859 | } |
874 | 860 | |
875 | 861 | int VM::get_sound_buffer_ptr() |
876 | 862 | { |
877 | - return event->get_sound_buffer_ptr(); | |
863 | + if(event != nullptr) { | |
864 | + return event->get_sound_buffer_ptr(); | |
865 | + } | |
866 | + return VM_TEMPLATE::get_sound_buffer_ptr(); | |
878 | 867 | } |
879 | 868 | |
880 | 869 | void VM::clear_sound_in() |
881 | 870 | { |
871 | + if(event == nullptr) return; | |
872 | + | |
882 | 873 | event->clear_sound_in_source(adc_in_ch); |
883 | 874 | event->clear_sound_in_source(mic_in_ch); |
884 | 875 | event->clear_sound_in_source(line_in_ch); |
@@ -887,7 +878,7 @@ void VM::clear_sound_in() | ||
887 | 878 | |
888 | 879 | int VM::get_sound_in_data(int ch, int32_t* dst, int expect_samples, int expect_rate, int expect_channels) |
889 | 880 | { |
890 | - if(dst == NULL) return 0; | |
881 | + if(dst == nullptr) return 0; | |
891 | 882 | if(expect_samples <= 0) return 0; |
892 | 883 | int n_ch = -1; |
893 | 884 | switch(ch) { |
@@ -902,7 +893,10 @@ int VM::get_sound_in_data(int ch, int32_t* dst, int expect_samples, int expect_r | ||
902 | 893 | break; |
903 | 894 | } |
904 | 895 | if(n_ch < 0) return 0; |
905 | - int samples = event->get_sound_in_data(n_ch, dst, expect_samples, expect_rate, expect_channels); | |
896 | + int samples = 0; | |
897 | + if(event != nullptr) { | |
898 | + samples = event->get_sound_in_data(n_ch, dst, expect_samples, expect_rate, expect_channels); | |
899 | + } | |
906 | 900 | return samples; |
907 | 901 | } |
908 | 902 |
@@ -925,11 +919,10 @@ int VM::sound_in(int ch, int32_t* src, int samples) | ||
925 | 919 | if(n_ch < 0) return 0; |
926 | 920 | |
927 | 921 | int ss = 0; |
928 | - { | |
922 | + if(event != nullptr) { | |
929 | 923 | emu->lock_vm(); |
930 | 924 | ss = event->write_sound_in_buffer(n_ch, src, samples); |
931 | 925 | emu->unlock_vm(); |
932 | - | |
933 | 926 | } |
934 | 927 | return ss; |
935 | 928 | } |
@@ -938,7 +931,7 @@ int VM::sound_in(int ch, int32_t* src, int samples) | ||
938 | 931 | void VM::open_hard_disk(int drv, const _TCHAR* file_path) |
939 | 932 | { |
940 | 933 | if((drv < USE_HARD_DISK) && (drv < 8) && (drv >= 0)) { |
941 | - if(scsi_hdd[drv] != NULL) { | |
934 | + if(scsi_hdd[drv] != nullptr) { | |
942 | 935 | scsi_hdd[drv]->open(0, file_path, 512); |
943 | 936 | } |
944 | 937 | } |
@@ -947,7 +940,7 @@ void VM::open_hard_disk(int drv, const _TCHAR* file_path) | ||
947 | 940 | void VM::close_hard_disk(int drv) |
948 | 941 | { |
949 | 942 | if((drv < USE_HARD_DISK) && (drv < 8) && (drv >= 0)) { |
950 | - if(scsi_hdd[drv] != NULL) { | |
943 | + if(scsi_hdd[drv] != nullptr) { | |
951 | 944 | scsi_hdd[drv]->close(0); |
952 | 945 | } |
953 | 946 | } |
@@ -956,7 +949,7 @@ void VM::close_hard_disk(int drv) | ||
956 | 949 | bool VM::is_hard_disk_inserted(int drv) |
957 | 950 | { |
958 | 951 | if((drv < USE_HARD_DISK) && (drv < 8) && (drv >= 0)) { |
959 | - if(scsi_hdd[drv] != NULL) { | |
952 | + if(scsi_hdd[drv] != nullptr) { | |
960 | 953 | return scsi_hdd[drv]->mounted(0); |
961 | 954 | } |
962 | 955 | } |
@@ -968,46 +961,41 @@ uint32_t VM::is_hard_disk_accessed() | ||
968 | 961 | uint32_t status = 0; |
969 | 962 | |
970 | 963 | for(int drv = 0; drv < USE_HARD_DISK; drv++) { |
971 | - if(scsi_hdd[drv] != NULL) { | |
964 | + if(scsi_hdd[drv] != nullptr) { | |
972 | 965 | if(scsi_hdd[drv]->accessed(0)) { |
973 | 966 | status |= 1 << drv; |
974 | 967 | } |
975 | 968 | } |
976 | 969 | } |
977 | - if(boot_seq) { | |
978 | - if(status != 0) { | |
979 | - keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff); | |
980 | - boot_seq = false; | |
981 | - } | |
982 | - } | |
970 | + process_boot_sequence(1); | |
983 | 971 | return status; |
984 | 972 | } |
985 | 973 | #endif // USE_HARD_DISK |
986 | 974 | |
987 | 975 | void VM::open_compact_disc(int drv, const _TCHAR* file_path) |
988 | 976 | { |
989 | - cdrom->open(file_path); | |
977 | + if(cdrom != nullptr) { | |
978 | + cdrom->open(file_path); | |
979 | + } | |
990 | 980 | } |
991 | 981 | |
992 | 982 | void VM::close_compact_disc(int drv) |
993 | 983 | { |
994 | - cdrom->close(); | |
984 | + if(cdrom != nullptr) { | |
985 | + cdrom->close(); | |
986 | + } | |
995 | 987 | } |
996 | 988 | |
997 | 989 | bool VM::is_compact_disc_inserted(int drv) |
998 | 990 | { |
991 | + if(cdrom == nullptr) return false; | |
999 | 992 | return cdrom->mounted(); |
1000 | 993 | } |
1001 | 994 | |
1002 | 995 | uint32_t VM::is_compact_disc_accessed() |
1003 | 996 | { |
1004 | 997 | uint32_t status = cdrom->accessed(); |
1005 | - if(boot_seq) { | |
1006 | - if(status != 0) { | |
1007 | - keyboard->write_signal(SIG_KEYBOARD_BOOTSEQ_END, 0xffffffff, 0xffffffff); | |
1008 | - boot_seq = false; | |
1009 | - } | |
1010 | - } | |
998 | + process_boot_sequence(1); | |
1011 | 999 | return status; |
1012 | 1000 | } |
1013 | 1001 |
@@ -1027,28 +1015,38 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r) | ||
1027 | 1015 | // if(ch >= 10) ch++; |
1028 | 1016 | #endif |
1029 | 1017 | if(ch == 0) { // BEEP |
1030 | - beep->set_volume(0, decibel_l, decibel_r); | |
1018 | + if(beep != nullptr) { | |
1019 | + beep->set_volume(0, decibel_l, decibel_r); | |
1020 | + } | |
1031 | 1021 | } |
1032 | 1022 | else if(ch == 1) { // CD-ROM |
1033 | 1023 | if(e_volumes[1] != nullptr) { |
1034 | 1024 | e_volumes[1]->set_volumes(0, decibel_l, 1, decibel_r); |
1035 | - } else { | |
1025 | + } else if(cdrom != nullptr) { | |
1036 | 1026 | cdrom->set_volume(0, decibel_l, decibel_r); |
1037 | 1027 | } |
1038 | 1028 | } |
1039 | 1029 | else if(ch == 2) { // OPN2 |
1040 | - opn2->set_volume(0, decibel_l, decibel_r); | |
1030 | + if(opn2 != nullptr) { | |
1031 | + opn2->set_volume(0, decibel_l, decibel_r); | |
1032 | + } | |
1041 | 1033 | } |
1042 | 1034 | else if(ch == 3) { // ADPCM |
1043 | - rf5c68->set_volume(0, decibel_l, decibel_r); | |
1035 | + if(rf5c68 != nullptr) { | |
1036 | + rf5c68->set_volume(0, decibel_l, decibel_r); | |
1037 | + } | |
1044 | 1038 | } |
1045 | 1039 | else if(ch == 4) { // SEEK, HEAD UP / DOWN |
1046 | - seek_sound->set_volume(0, decibel_l, decibel_r); | |
1047 | - head_up_sound->set_volume(0, decibel_l, decibel_r); | |
1048 | - head_down_sound->set_volume(0, decibel_l, decibel_r); | |
1040 | + if(seek_sound != nullptr) { | |
1041 | + seek_sound->set_volume(0, decibel_l, decibel_r); | |
1042 | + } | |
1043 | + if(head_up_sound != nullptr) { | |
1044 | + head_up_sound->set_volume(0, decibel_l, decibel_r); | |
1045 | + } | |
1046 | + if(head_down_sound != nullptr) { | |
1047 | + head_down_sound->set_volume(0, decibel_l, decibel_r); | |
1048 | + } | |
1049 | 1049 | } |
1050 | - | |
1051 | - | |
1052 | 1050 | } |
1053 | 1051 | #endif |
1054 | 1052 |
@@ -1058,12 +1056,16 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r) | ||
1058 | 1056 | |
1059 | 1057 | void VM::key_down(int code, bool repeat) |
1060 | 1058 | { |
1061 | - keyboard->key_down(code); | |
1059 | + if(keyboard != nullptr) { | |
1060 | + keyboard->key_down(code); | |
1061 | + } | |
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | void VM::key_up(int code) |
1065 | 1065 | { |
1066 | - keyboard->key_up(code); | |
1066 | + if(keyboard != nullptr) { | |
1067 | + keyboard->key_up(code); | |
1068 | + } | |
1067 | 1069 | } |
1068 | 1070 | |
1069 | 1071 | // ---------------------------------------------------------------------------- |
@@ -1073,12 +1075,12 @@ void VM::open_cart(int drv, const _TCHAR* file_path) | ||
1073 | 1075 | { |
1074 | 1076 | switch(drv) { |
1075 | 1077 | case 0: |
1076 | - if(iccard1 != NULL) { | |
1078 | + if(iccard1 != nullptr) { | |
1077 | 1079 | iccard1->open_cart(file_path); |
1078 | 1080 | } |
1079 | 1081 | break; |
1080 | 1082 | case 1: |
1081 | - if(iccard2 != NULL) { | |
1083 | + if(iccard2 != nullptr) { | |
1082 | 1084 | iccard2->open_cart(file_path); |
1083 | 1085 | } |
1084 | 1086 | break; |
@@ -1089,12 +1091,12 @@ void VM::close_cart(int drv) | ||
1089 | 1091 | { |
1090 | 1092 | switch(drv) { |
1091 | 1093 | case 0: |
1092 | - if(iccard1 != NULL) { | |
1094 | + if(iccard1 != nullptr) { | |
1093 | 1095 | iccard1->close_cart(); |
1094 | 1096 | } |
1095 | 1097 | break; |
1096 | 1098 | case 1: |
1097 | - if(iccard2 != NULL) { | |
1099 | + if(iccard2 != nullptr) { | |
1098 | 1100 | iccard2->close_cart(); |
1099 | 1101 | } |
1100 | 1102 | break; |
@@ -1105,12 +1107,12 @@ bool VM::is_cart_inserted(int drv) | ||
1105 | 1107 | { |
1106 | 1108 | switch(drv) { |
1107 | 1109 | case 0: |
1108 | - if(iccard1 != NULL) { | |
1110 | + if(iccard1 != nullptr) { | |
1109 | 1111 | return iccard1->is_cart_inserted(); |
1110 | 1112 | } |
1111 | 1113 | break; |
1112 | 1114 | case 1: |
1113 | - if(iccard2 != NULL) { | |
1115 | + if(iccard2 != nullptr) { | |
1114 | 1116 | return iccard2->is_cart_inserted(); |
1115 | 1117 | } |
1116 | 1118 | break; |
@@ -1121,89 +1123,88 @@ bool VM::is_cart_inserted(int drv) | ||
1121 | 1123 | void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank) |
1122 | 1124 | { |
1123 | 1125 | |
1124 | - fdc->open_disk(drv, file_path, bank); | |
1125 | - floppy->change_disk(drv); | |
1126 | + if(fdc != nullptr) { | |
1127 | + fdc->open_disk(drv, file_path, bank); | |
1128 | + floppy->change_disk(drv); | |
1129 | + } | |
1126 | 1130 | } |
1127 | 1131 | |
1128 | 1132 | void VM::close_floppy_disk(int drv) |
1129 | 1133 | { |
1130 | - fdc->close_disk(drv); | |
1131 | -// floppy->change_disk(drv); | |
1134 | + if(fdc != nullptr) { | |
1135 | + fdc->close_disk(drv); | |
1136 | + // floppy->change_disk(drv); | |
1137 | + } | |
1138 | +} | |
1139 | +uint32_t VM::is_floppy_disk_accessed() | |
1140 | +{ | |
1141 | + uint32_t val = fdc->read_signal(0); | |
1142 | + process_boot_sequence(val); | |
1143 | + return val; | |
1132 | 1144 | } |
1133 | 1145 | |
1134 | 1146 | bool VM::is_floppy_disk_inserted(int drv) |
1135 | 1147 | { |
1136 | - return fdc->is_disk_inserted(drv); | |
1148 | + if(fdc != nullptr) { | |
1149 | + return fdc->is_disk_inserted(drv); | |
1150 | + } | |
1151 | + return VM_TEMPLATE::is_floppy_disk_inserted(drv); | |
1137 | 1152 | } |
1138 | 1153 | |
1139 | 1154 | void VM::is_floppy_disk_protected(int drv, bool value) |
1140 | 1155 | { |
1141 | - fdc->is_disk_protected(drv, value); | |
1156 | + if(fdc != nullptr) { | |
1157 | + fdc->is_disk_protected(drv, value); | |
1158 | + } | |
1142 | 1159 | } |
1143 | 1160 | |
1144 | 1161 | bool VM::is_floppy_disk_protected(int drv) |
1145 | 1162 | { |
1146 | - return fdc->is_disk_protected(drv); | |
1163 | + if(fdc != nullptr) { | |
1164 | + return fdc->is_disk_protected(drv); | |
1165 | + } | |
1166 | + return VM_TEMPLATE::is_floppy_disk_protected(drv); | |
1147 | 1167 | } |
1148 | 1168 | |
1149 | 1169 | bool VM::is_frame_skippable() |
1150 | 1170 | { |
1151 | - return event->is_frame_skippable(); | |
1152 | -} | |
1153 | - | |
1154 | -void VM::update_config() | |
1155 | -{ | |
1156 | - for(DEVICE* device = first_device; device; device = device->next_device) { | |
1157 | - device->update_config(); | |
1171 | + if(event != nullptr) { | |
1172 | + return event->is_frame_skippable(); | |
1158 | 1173 | } |
1174 | + return VM_TEMPLATE::is_frame_skippable(); | |
1159 | 1175 | } |
1160 | 1176 | |
1177 | + | |
1161 | 1178 | double VM::get_current_usec() |
1162 | 1179 | { |
1163 | - if(event == NULL) return 0.0; | |
1164 | - return event->get_current_usec(); | |
1180 | + if(event != nullptr) { | |
1181 | + return event->get_current_usec(); | |
1182 | + } | |
1183 | + return VM_TEMPLATE::get_current_usec(); | |
1165 | 1184 | } |
1166 | 1185 | |
1167 | 1186 | uint64_t VM::get_current_clock_uint64() |
1168 | 1187 | { |
1169 | - if(event == NULL) return (uint64_t)0; | |
1188 | + if(event != nullptr) { | |
1170 | 1189 | return event->get_current_clock_uint64(); |
1190 | + } | |
1191 | + return VM_TEMPLATE::get_current_clock_uint64(); | |
1171 | 1192 | } |
1172 | 1193 | |
1173 | 1194 | #define STATE_VERSION 4 |
1174 | 1195 | |
1175 | 1196 | bool VM::process_state(FILEIO* state_fio, bool loading) |
1176 | 1197 | { |
1177 | - if(!state_fio->StateCheckUint32(STATE_VERSION)) { | |
1178 | - return false; | |
1179 | - } | |
1180 | - for(DEVICE* device = first_device; device; device = device->next_device) { | |
1181 | - const _TCHAR *name = char_to_tchar(typeid(*device).name() + 6); // skip "class " | |
1182 | - int len = (int)_tcslen(name); | |
1183 | - | |
1184 | - if(!state_fio->StateCheckInt32(len)) { | |
1185 | - if(loading) { | |
1186 | - printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name); | |
1187 | - } | |
1188 | - return false; | |
1189 | - } | |
1190 | - if(!state_fio->StateCheckBuffer(name, len, 1)) { | |
1191 | - if(loading) { | |
1192 | - printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name); | |
1193 | - } | |
1194 | - return false; | |
1195 | - } | |
1196 | - if(!device->process_state(state_fio, loading)) { | |
1197 | - if(loading) { | |
1198 | - printf("Data loading Error: DEVID=%d\n", device->this_device_id); | |
1199 | - } | |
1200 | - return false; | |
1201 | - } | |
1202 | - } | |
1198 | + if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) { | |
1199 | + return false; | |
1200 | + } | |
1201 | + | |
1203 | 1202 | // Machine specified. |
1204 | - | |
1205 | 1203 | state_fio->StateValue(boot_seq); |
1206 | 1204 | |
1205 | + if(loading) { | |
1206 | + update_config(); | |
1207 | + } | |
1207 | 1208 | return true; |
1208 | 1209 | } |
1209 | 1210 |
@@ -454,6 +454,7 @@ protected: | ||
454 | 454 | scrntype_t *d_renderbuffer[2][2]; // [bank][layer] |
455 | 455 | uint32_t renderbuffer_size[2][2]; |
456 | 456 | */ |
457 | + virtual void process_boot_sequence(uint32_t val); | |
457 | 458 | public: |
458 | 459 | // ---------------------------------------- |
459 | 460 | // initialize |
@@ -467,64 +468,62 @@ public: | ||
467 | 468 | // ---------------------------------------- |
468 | 469 | |
469 | 470 | // drive virtual machine |
470 | - void reset(); | |
471 | - void special_reset(int num); | |
472 | - void run(); | |
471 | + void reset() override; | |
472 | + void special_reset(int num) override; | |
473 | + void run() override; | |
473 | 474 | |
474 | 475 | #ifdef USE_DEBUGGER |
475 | 476 | // debugger |
476 | - DEVICE *get_cpu(int index); | |
477 | + DEVICE *get_cpu(int index) override; | |
477 | 478 | #endif |
478 | 479 | |
479 | 480 | // draw screen |
480 | - void draw_screen(); | |
481 | + void draw_screen() override; | |
481 | 482 | |
482 | 483 | // sound generation |
483 | - void initialize_sound(int rate, int samples); | |
484 | - uint16_t* create_sound(int* extra_frames); | |
485 | - int get_sound_buffer_ptr(); | |
484 | + void initialize_sound(int rate, int samples) override; | |
485 | + uint16_t* create_sound(int* extra_frames) override; | |
486 | + int get_sound_buffer_ptr() override; | |
486 | 487 | #ifdef USE_SOUND_VOLUME |
487 | - void set_sound_device_volume(int ch, int decibel_l, int decibel_r); | |
488 | + void set_sound_device_volume(int ch, int decibel_l, int decibel_r) override; | |
488 | 489 | #endif |
489 | 490 | |
490 | 491 | // notify key |
491 | - void key_down(int code, bool repeat); | |
492 | - void key_up(int code); | |
492 | + void key_down(int code, bool repeat) override; | |
493 | + void key_up(int code) override; | |
493 | 494 | |
494 | 495 | // user interface |
495 | 496 | // CARTs are IC CARD.Will implement something :-) |
496 | - void open_cart(int drv, const _TCHAR* file_path); | |
497 | - void close_cart(int drv); | |
498 | - bool is_cart_inserted(int drv); | |
497 | + void open_cart(int drv, const _TCHAR* file_path) override; | |
498 | + void close_cart(int drv) override; | |
499 | + bool is_cart_inserted(int drv) override; | |
499 | 500 | |
500 | - void open_floppy_disk(int drv, const _TCHAR* file_path, int bank); | |
501 | - void close_floppy_disk(int drv); | |
502 | - uint32_t is_floppy_disk_accessed(); | |
503 | - bool is_floppy_disk_inserted(int drv); | |
504 | - void is_floppy_disk_protected(int drv, bool value); | |
505 | - bool is_floppy_disk_protected(int drv); | |
506 | - bool is_frame_skippable(); | |
507 | - | |
508 | - void open_compact_disc(int drv, const _TCHAR* file_path); | |
509 | - void close_compact_disc(int drv); | |
510 | - bool is_compact_disc_inserted(int drv); | |
511 | - uint32_t is_compact_disc_accessed(); | |
501 | + void open_floppy_disk(int drv, const _TCHAR* file_path, int bank) override; | |
502 | + void close_floppy_disk(int drv) override; | |
503 | + uint32_t is_floppy_disk_accessed() override; | |
504 | + bool is_floppy_disk_inserted(int drv) override; | |
505 | + void is_floppy_disk_protected(int drv, bool value) override; | |
506 | + bool is_floppy_disk_protected(int drv) override; | |
507 | + bool is_frame_skippable() override; | |
508 | + | |
509 | + void open_compact_disc(int drv, const _TCHAR* file_path) override; | |
510 | + void close_compact_disc(int drv) override; | |
511 | + bool is_compact_disc_inserted(int drv) override; | |
512 | + uint32_t is_compact_disc_accessed() override; | |
512 | 513 | #if defined(USE_HARD_DISK) |
513 | - void open_hard_disk(int drv, const _TCHAR* file_path); | |
514 | - void close_hard_disk(int drv); | |
515 | - bool is_hard_disk_inserted(int drv); | |
516 | - uint32_t is_hard_disk_accessed(); | |
514 | + void open_hard_disk(int drv, const _TCHAR* file_path) override; | |
515 | + void close_hard_disk(int drv) override; | |
516 | + bool is_hard_disk_inserted(int drv) override; | |
517 | + uint32_t is_hard_disk_accessed() override; | |
517 | 518 | #endif |
518 | 519 | void set_machine_type(uint16_t machine_id, uint16_t cpu_id); |
519 | - | |
520 | 520 | void clear_sound_in(); |
521 | 521 | int get_sound_in_data(int ch, int32_t* dst, int expect_samples, int expect_rate, int expect_channels); |
522 | 522 | int sound_in(int ch, int32_t* src, int samples); |
523 | 523 | |
524 | - double get_current_usec(); | |
525 | - uint64_t get_current_clock_uint64(); | |
524 | + double get_current_usec() override; | |
525 | + uint64_t get_current_clock_uint64() override; | |
526 | 526 | |
527 | - void update_config(); | |
528 | 527 | bool process_state(FILEIO* state_fio, bool loading); |
529 | 528 | |
530 | 529 | // ---------------------------------------- |
@@ -532,9 +531,8 @@ public: | ||
532 | 531 | // ---------------------------------------- |
533 | 532 | |
534 | 533 | // devices |
535 | - DEVICE* get_device(int id); | |
534 | + //DEVICE* get_device(int id); | |
536 | 535 | //DEVICE* dummy; |
537 | 536 | //DEVICE* first_device; |
538 | 537 | //DEVICE* last_device; |
539 | 538 | }; |
540 | - |