Common Source Code Project for Qt (a.k.a for FM-7).
Revision | 9372f40d88ac2108c55adb0564d2c6c48bc9cebf (tree) |
---|---|
Zeit | 2022-11-27 15:24:20 |
Autor | K.Ohta <whatisthis.sowhat@gmai...> |
Commiter | K.Ohta |
[VM][FM7] Apply before commit for VM_TEMPLATE.
@@ -318,14 +318,14 @@ VM::VM(EMU_TEMPLATE* parent_emu): VM_TEMPLATE(parent_emu) | ||
318 | 318 | if(uart[0] != nullptr) { |
319 | 319 | uart[0]->set_device_name(_T("RS-232C BOARD(I8251 SIO)")); |
320 | 320 | } |
321 | -# if defined(CAPABLE_JCOMMCARD) | |
321 | +#if defined(CAPABLE_JCOMMCARD) | |
322 | 322 | if((config.dipswitch & FM7_DIPSW_JSUBCARD_ON) != 0) { |
323 | 323 | if(uart[0] != nullptr) uart[0]->set_device_name(_T("J.COMM BOARD RS-232C(I8251 SIO)")); |
324 | 324 | } |
325 | -# elif defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV20EX) || \ | |
325 | +#elif defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV20EX) || \ | |
326 | 326 | defined(_FM77AV40EX) || defined(_FM77AV40SX) || defined(_FM8) |
327 | 327 | if(uart[0] != nullptr) uart[0]->set_device_name(_T("RS-232C(I8251 SIO)")); |
328 | -# endif | |
328 | +#endif | |
329 | 329 | |
330 | 330 | if(uart[1] != nullptr) { |
331 | 331 | uart[1]->set_device_name(_T("MODEM BOARD(I8251 SIO)")); |
@@ -336,28 +336,28 @@ VM::VM(EMU_TEMPLATE* parent_emu): VM_TEMPLATE(parent_emu) | ||
336 | 336 | |
337 | 337 | // basic devices |
338 | 338 | // I/Os |
339 | -# if defined(_FM8) | |
339 | +#if defined(_FM8) | |
340 | 340 | psg->set_device_name(_T("AY-3-8910 PSG")); |
341 | -# else | |
341 | +#else | |
342 | 342 | opn[0]->set_device_name(_T("YM2203 OPN")); |
343 | 343 | opn[1]->set_device_name(_T("YM2203 WHG")); |
344 | 344 | opn[2]->set_device_name(_T("YM2203 THG")); |
345 | -# if !defined(_FM77AV_VARIANTS) | |
345 | + #if !defined(_FM77AV_VARIANTS) | |
346 | 346 | psg->set_device_name(_T("AY-3-8910 PSG")); |
347 | -# endif | |
347 | + #endif | |
348 | 348 | pcm1bit->set_device_name(_T("BEEP")); |
349 | 349 | printer->set_device_name(_T("PRINTER I/F")); |
350 | -# if defined(_FM77AV_VARIANTS) | |
350 | + #if defined(_FM77AV_VARIANTS) | |
351 | 351 | keyboard_beep->set_device_name(_T("BEEP(KEYBOARD)")); |
352 | -# endif | |
352 | + #endif | |
353 | 353 | if(kanjiclass1 != nullptr) kanjiclass1->set_device_name(_T("KANJI ROM CLASS1")); |
354 | -# ifdef CAPABLE_KANJI_CLASS2 | |
354 | + #ifdef CAPABLE_KANJI_CLASS2 | |
355 | 355 | if(kanjiclass2 != nullptr) kanjiclass2->set_device_name(_T("KANJI ROM CLASS2")); |
356 | -# endif | |
357 | -# if defined(_FM8) | |
356 | + #endif | |
357 | + #if defined(_FM8) | |
358 | 358 | bubble_casette[0]->set_device_name(_T("BUBBLE CASETTE #0")); |
359 | 359 | bubble_casette[1]->set_device_name(_T("BUBBLE CASETTE #1")); |
360 | -# endif | |
360 | + #endif | |
361 | 361 | #endif |
362 | 362 | # if defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV20EX) || defined(_FM77AV40EX) || defined(_FM77AV40SX) |
363 | 363 | g_rs232c_dtr->set_device_name(_T("RS232C DTR(AND)")); |
@@ -381,12 +381,7 @@ VM::VM(EMU_TEMPLATE* parent_emu): VM_TEMPLATE(parent_emu) | ||
381 | 381 | VM::~VM() |
382 | 382 | { |
383 | 383 | // delete all devices |
384 | - for(DEVICE* device = first_device; device;) { | |
385 | - DEVICE *next_device = device->next_device; | |
386 | - device->release(); | |
387 | - delete device; | |
388 | - device = next_device; | |
389 | - } | |
384 | + release_devices(); | |
390 | 385 | } |
391 | 386 | |
392 | 387 | void VM::connect_bus(void) |
@@ -470,9 +465,9 @@ void VM::connect_bus(void) | ||
470 | 465 | event->set_context_sound(opn[0]); |
471 | 466 | event->set_context_sound(opn[1]); |
472 | 467 | event->set_context_sound(opn[2]); |
473 | -# if !defined(_FM77AV_VARIANTS) | |
468 | + #if !defined(_FM77AV_VARIANTS) | |
474 | 469 | event->set_context_sound(psg); |
475 | -# endif | |
470 | + #endif | |
476 | 471 | event->set_context_sound(drec); |
477 | 472 | if(fdc != nullptr) { |
478 | 473 | event->set_context_sound(fdc->get_context_noise_seek()); |
@@ -491,9 +486,9 @@ void VM::connect_bus(void) | ||
491 | 486 | event->set_context_sound(drec->get_context_noise_stop()); |
492 | 487 | event->set_context_sound(drec->get_context_noise_fast()); |
493 | 488 | } |
494 | -# if defined(_FM77AV_VARIANTS) | |
489 | + #if defined(_FM77AV_VARIANTS) | |
495 | 490 | event->set_context_sound(keyboard_beep); |
496 | -# endif | |
491 | + #endif | |
497 | 492 | #endif |
498 | 493 | #if !defined(_FM77AV_VARIANTS) && !defined(_FM77L4) |
499 | 494 | //event->register_vline_event(display); |
@@ -634,9 +629,9 @@ void VM::connect_bus(void) | ||
634 | 629 | #if defined(_FM8) |
635 | 630 | mainio->set_context_psg(psg); |
636 | 631 | #else |
637 | -# if !defined(_FM77AV_VARIANTS) | |
632 | + #if !defined(_FM77AV_VARIANTS) | |
638 | 633 | mainio->set_context_psg(psg); |
639 | -# endif | |
634 | + #endif | |
640 | 635 | opn[0]->set_context_irq(mainio, FM7_MAINIO_OPN_IRQ, 0xffffffff); |
641 | 636 | mainio->set_context_opn(opn[0], 0); |
642 | 637 | joystick->set_context_opn(opn[0]); |
@@ -675,14 +670,14 @@ void VM::connect_bus(void) | ||
675 | 670 | #ifdef USE_DEBUGGER |
676 | 671 | maincpu->set_context_debugger(new DEBUGGER(this, emu)); |
677 | 672 | subcpu->set_context_debugger(new DEBUGGER(this, emu)); |
678 | -# ifdef WITH_Z80 | |
673 | + #ifdef WITH_Z80 | |
679 | 674 | if(z80cpu != nullptr) z80cpu->set_context_debugger(new DEBUGGER(this, emu)); |
680 | -# endif | |
681 | -# if defined(CAPABLE_JCOMMCARD) | |
675 | + #endif | |
676 | + #if defined(CAPABLE_JCOMMCARD) | |
682 | 677 | if(jsubcpu != nullptr) { |
683 | 678 | jsubcpu->set_context_debugger(new DEBUGGER(this, emu)); |
684 | 679 | } |
685 | -# endif | |
680 | + #endif | |
686 | 681 | #endif |
687 | 682 | #if defined(__GIT_REPO_VERSION) |
688 | 683 | set_git_repo_version(__GIT_REPO_VERSION); |
@@ -735,19 +730,18 @@ void VM::update_config() | ||
735 | 730 | void VM::reset() |
736 | 731 | { |
737 | 732 | // reset all devices |
738 | - for(DEVICE* device = first_device; device; device = device->next_device) { | |
739 | - device->reset(); | |
740 | - } | |
733 | + VM_TEMPLATE::reset(); | |
734 | + | |
741 | 735 | #if !defined(_FM77AV_VARIANTS) || defined(_FM8) |
742 | -# if defined(USE_AY_3_8910_AS_PSG) | |
736 | + #if defined(USE_AY_3_8910_AS_PSG) | |
743 | 737 | psg->set_reg(0x27, 0); // set prescaler |
744 | 738 | psg->set_reg(0x2e, 0); // set prescaler |
745 | 739 | psg->write_signal(SIG_AY_3_891X_MUTE, 0x00, 0x01); // Okay? |
746 | -# else | |
740 | + #else | |
747 | 741 | psg->set_reg(0x27, 0); // stop timer |
748 | 742 | psg->set_reg(0x2e, 0); // set prescaler |
749 | 743 | psg->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay? |
750 | -#endif | |
744 | + #endif | |
751 | 745 | #endif |
752 | 746 | #if !defined(_FM8) |
753 | 747 | for(int i = 0; i < 3; i++) { |
@@ -780,7 +774,9 @@ void VM::special_reset(int num) | ||
780 | 774 | |
781 | 775 | void VM::run() |
782 | 776 | { |
783 | - event->drive(); | |
777 | + if(event != nullptr) { | |
778 | + event->drive(); | |
779 | + } | |
784 | 780 | } |
785 | 781 | |
786 | 782 | double VM::get_frame_rate() |
@@ -800,14 +796,18 @@ void VM::set_vm_frame_rate(double fps) | ||
800 | 796 | |
801 | 797 | double VM::get_current_usec() |
802 | 798 | { |
803 | - if(event == NULL) return 0.0; | |
804 | - return event->get_current_usec(); | |
799 | + if(event != nullptr) { | |
800 | + return event->get_current_usec(); | |
801 | + } | |
802 | + return VM_TEMPLATE::get_current_usec(); | |
805 | 803 | } |
806 | 804 | |
807 | 805 | uint64_t VM::get_current_clock_uint64() |
808 | 806 | { |
809 | - if(event == NULL) return (uint64_t)0; | |
807 | + if(event != nullptr) { | |
810 | 808 | return event->get_current_clock_uint64(); |
809 | + } | |
810 | + return VM_TEMPLATE::get_current_clock_uint64(); | |
811 | 811 | } |
812 | 812 | |
813 | 813 |
@@ -824,27 +824,27 @@ DEVICE *VM::get_cpu(int index) | ||
824 | 824 | } else if(index == 1) { |
825 | 825 | return subcpu; |
826 | 826 | } |
827 | -#if defined(WITH_Z80) | |
827 | + #if defined(WITH_Z80) | |
828 | 828 | else if(index == 2) { |
829 | -# if defined(CAPABLE_JCOMMCARD) | |
829 | + #if defined(CAPABLE_JCOMMCARD) | |
830 | 830 | if(z80cpu == nullptr) { |
831 | 831 | return jsubcpu; |
832 | 832 | } |
833 | -# endif | |
833 | + #endif | |
834 | 834 | return z80cpu; |
835 | 835 | } |
836 | -# if defined(CAPABLE_JCOMMCARD) | |
836 | + #if defined(CAPABLE_JCOMMCARD) | |
837 | 837 | else if(index == 3) { |
838 | 838 | return jsubcpu; |
839 | 839 | } |
840 | -# endif | |
841 | -#else | |
842 | -# if defined(CAPABLE_JCOMMCARD) | |
840 | + #endif | |
841 | + #else | |
842 | + #if defined(CAPABLE_JCOMMCARD) | |
843 | 843 | else if(index == 2) { |
844 | 844 | return jsubcpu; |
845 | 845 | } |
846 | -# endif | |
847 | -#endif | |
846 | + #endif | |
847 | + #endif | |
848 | 848 | return nullptr; |
849 | 849 | } |
850 | 850 | #endif |
@@ -861,43 +861,63 @@ void VM::draw_screen() | ||
861 | 861 | void VM::initialize_sound(int rate, int samples) |
862 | 862 | { |
863 | 863 | // init sound manager |
864 | - event->initialize_sound(rate, samples); | |
864 | + if(event != nullptr) { | |
865 | + event->initialize_sound(rate, samples); | |
866 | + } | |
865 | 867 | // init sound gen |
866 | 868 | #if defined(_FM8) |
867 | - psg->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
868 | -#else | |
869 | - opn[0]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
870 | - opn[1]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
871 | - opn[2]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
872 | -# if !defined(_FM77AV_VARIANTS) | |
873 | - psg->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
874 | -# if defined(USE_AY_3_8910_AS_PSG) | |
875 | - psg->set_low_pass_filter_freq(4500); | |
876 | - psg->set_high_pass_filter_freq(50); | |
877 | -# endif | |
878 | -# endif | |
879 | -# if defined(_FM77AV_VARIANTS) | |
880 | - keyboard_beep->initialize_sound(rate, 2400.0, 512); | |
881 | -# endif | |
882 | -#endif | |
883 | - pcm1bit->initialize_sound(rate, 8000); | |
884 | - pcm1bit->set_high_pass_filter_freq(10); | |
885 | - pcm1bit->set_low_pass_filter_freq(1500); | |
886 | - | |
887 | - | |
869 | + if(psg != nullptr) { | |
870 | + psg->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
871 | + } | |
872 | +#else | |
873 | + if(opn[0] != nullptr) { | |
874 | + opn[0]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
875 | + } | |
876 | + if(opn[1] != nullptr) { | |
877 | + opn[1]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
878 | + } | |
879 | + if(opn[2] != nullptr) { | |
880 | + opn[2]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
881 | + } | |
882 | + # if !defined(_FM77AV_VARIANTS) | |
883 | + if(psg != nullptr) { | |
884 | + psg->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0); | |
885 | + #if defined(USE_AY_3_8910_AS_PSG) | |
886 | + psg->set_low_pass_filter_freq(4500); | |
887 | + psg->set_high_pass_filter_freq(50); | |
888 | + #endif | |
889 | + } | |
890 | + #endif | |
891 | + #if defined(_FM77AV_VARIANTS) | |
892 | + if(keyboard_beep != nullptr) { | |
893 | + keyboard_beep->initialize_sound(rate, 2400.0, 512); | |
894 | + } | |
895 | + # endif | |
896 | +#endif | |
897 | + if(pcm1bit != nullptr) { | |
898 | + pcm1bit->initialize_sound(rate, 8000); | |
899 | + pcm1bit->set_high_pass_filter_freq(10); | |
900 | + pcm1bit->set_low_pass_filter_freq(1500); | |
901 | + } | |
888 | 902 | //drec->initialize_sound(rate, 0); |
889 | 903 | } |
890 | 904 | |
891 | 905 | uint16_t* VM::create_sound(int* extra_frames) |
892 | 906 | { |
893 | - uint16_t* p = event->create_sound(extra_frames); | |
894 | - return p; | |
907 | + if(event != nullptr) { | |
908 | + uint16_t* p = event->create_sound(extra_frames); | |
909 | + return p; | |
910 | + } | |
911 | + return VM_TEMPLATE::create_sound(extra_frames); | |
895 | 912 | } |
896 | 913 | |
897 | 914 | int VM::get_sound_buffer_ptr() |
898 | 915 | { |
899 | - int pos = event->get_sound_buffer_ptr(); | |
900 | - return pos; | |
916 | + if(event != nullptr) { | |
917 | + int pos = event->get_sound_buffer_ptr(); | |
918 | + return pos; | |
919 | + } | |
920 | + return VM_TEMPLATE::get_sound_buffer_ptr(); | |
901 | 921 | } |
902 | 922 | |
903 | 923 | #ifdef USE_SOUND_VOLUME |
@@ -905,33 +925,53 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r) | ||
905 | 925 | { |
906 | 926 | #if !defined(_FM77AV_VARIANTS) |
907 | 927 | if(ch-- == 0) { |
908 | - psg->set_volume(0, decibel_l, decibel_r); | |
909 | - psg->set_volume(1, decibel_l, decibel_r); | |
928 | + if(psg != nullptr) { | |
929 | + psg->set_volume(0, decibel_l, decibel_r); | |
930 | + psg->set_volume(1, decibel_l, decibel_r); | |
931 | + } | |
910 | 932 | } else |
911 | 933 | #endif |
912 | 934 | #if !defined(_FM8) |
913 | 935 | if(ch-- == 0) { |
914 | - opn[0]->set_volume(0, decibel_l, decibel_r); | |
936 | + if(opn[0] != nullptr) { | |
937 | + opn[0]->set_volume(0, decibel_l, decibel_r); | |
938 | + } | |
915 | 939 | } else if(ch-- == 0) { |
916 | - opn[0]->set_volume(1, decibel_l, decibel_r); | |
940 | + if(opn[0] != nullptr) { | |
941 | + opn[0]->set_volume(1, decibel_l, decibel_r); | |
942 | + } | |
917 | 943 | } else if(ch-- == 0) { |
918 | - opn[1]->set_volume(0, decibel_l, decibel_r); | |
944 | + if(opn[1] != nullptr) { | |
945 | + opn[1]->set_volume(0, decibel_l, decibel_r); | |
946 | + } | |
919 | 947 | } else if(ch-- == 0) { |
920 | - opn[1]->set_volume(1, decibel_l, decibel_r); | |
948 | + if(opn[1] != nullptr) { | |
949 | + opn[1]->set_volume(1, decibel_l, decibel_r); | |
950 | + } | |
921 | 951 | } else if(ch-- == 0) { |
922 | - opn[2]->set_volume(0, decibel_l, decibel_r); | |
952 | + if(opn[2] != nullptr) { | |
953 | + opn[2]->set_volume(0, decibel_l, decibel_r); | |
954 | + } | |
923 | 955 | } else if(ch-- == 0) { |
924 | - opn[2]->set_volume(1, decibel_l, decibel_r); | |
956 | + if(opn[2] != nullptr) { | |
957 | + opn[2]->set_volume(1, decibel_l, decibel_r); | |
958 | + } | |
925 | 959 | } else |
926 | 960 | #endif |
927 | 961 | if(ch-- == 0) { |
928 | - pcm1bit->set_volume(0, decibel_l, decibel_r); | |
962 | + if(pcm1bit != nullptr) { | |
963 | + pcm1bit->set_volume(0, decibel_l, decibel_r); | |
964 | + } | |
929 | 965 | } else if(ch-- == 0) { |
930 | - if(drec != nullptr) drec->set_volume(0, decibel_l, decibel_r); | |
966 | + if(drec != nullptr) { | |
967 | + drec->set_volume(0, decibel_l, decibel_r); | |
968 | + } | |
931 | 969 | } |
932 | 970 | #if defined(_FM77AV_VARIANTS) |
933 | 971 | else if(ch-- == 0) { |
934 | - keyboard_beep->set_volume(0, decibel_l, decibel_r); | |
972 | + if(keyboard_beep != nullptr) { | |
973 | + keyboard_beep->set_volume(0, decibel_l, decibel_r); | |
974 | + } | |
935 | 975 | } |
936 | 976 | #endif |
937 | 977 | else if(ch-- == 0) { |
@@ -966,6 +1006,7 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r) | ||
966 | 1006 | |
967 | 1007 | void VM::key_down(int code, bool repeat) |
968 | 1008 | { |
1009 | + if(keyboard == nullptr) return; | |
969 | 1010 | if(!repeat) { |
970 | 1011 | keyboard->key_down(code); |
971 | 1012 | } |
@@ -973,22 +1014,26 @@ void VM::key_down(int code, bool repeat) | ||
973 | 1014 | |
974 | 1015 | void VM::key_up(int code) |
975 | 1016 | { |
1017 | + if(keyboard == nullptr) return; | |
976 | 1018 | keyboard->key_up(code); |
977 | 1019 | } |
978 | 1020 | |
979 | 1021 | bool VM::get_caps_locked() |
980 | 1022 | { |
1023 | + if(keyboard == nullptr) return false; | |
981 | 1024 | return keyboard->get_caps_locked(); |
982 | 1025 | } |
983 | 1026 | |
984 | 1027 | bool VM::get_kana_locked() |
985 | 1028 | { |
1029 | + if(keyboard == nullptr) return false; | |
986 | 1030 | return keyboard->get_kana_locked(); |
987 | 1031 | } |
988 | 1032 | |
989 | 1033 | // Get INS status.Important with FM-7 series (^_^; |
990 | 1034 | uint32_t VM::get_led_status() |
991 | 1035 | { |
1036 | + if(keyboard == nullptr) return 0; | |
992 | 1037 | return keyboard->read_signal(SIG_FM7KEY_LED_STATUS); |
993 | 1038 | } |
994 | 1039 |