1 /* Copyright 2013 Theo Berkau
2
3 This file is part of YabauseUT
4
5 YabauseUT is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 YabauseUT is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with YabauseUT; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include <iapetus.h>
21 #include "cdb.h"
22 #include "cart.h"
23 #include "m68k.h"
24 #include "mpeg.h"
25 #include "scsp.h"
26 #include "scu.h"
27 #include "slavesh.h"
28 #include "sh2.h"
29 #include "smpc.h"
30 #include "vdp1.h"
31 #include "vdp2.h"
32 #include "main.h"
33 #include "tests.h"
34
35 menu_item_struct main_menu[] = {
36 { "SH2 Test" , &sh2_test, },
37 { "Slave SH2 Test" , &slavesh2_test, },
38 { "SCU Test", &scu_test, },
39 { "CD Block Test" , &cdb_test, },
40 { "MPEG Card Test" , &mpeg_test, },
41 { "Cartridge Test" , &cart_test, }, // Could almost autodetect the cart type
42 { "68k Test" , &m68k_test, },
43 { "SCSP Test" , &scsp_test, },
44 { "SMPC Test" , &smpc_test, },
45 { "VDP1 Test" , &vdp1_test, },
46 { "VDP2 Test" , &vdp2_test, },
47 { "Run all tests" , &all_test, },
48 { "Reset System" , &reset_system, },
49 { "Goto AR Menu" , &ar_menu, },
50 { "Goto CD Player" , &cd_player },
51 { "\0", NULL }
52 };
53
54 screen_settings_struct test_disp_settings;
55 font_struct test_disp_font;
56
all_test()57 void all_test()
58 {
59 }
60
reset_system()61 void reset_system()
62 {
63 smpc_issue_command(SMPC_CMD_SYSRES);
64 }
65
ar_menu()66 void ar_menu()
67 {
68 void (*ar)() = (void (*)())0x02000100;
69
70 ar();
71 }
72
cd_player()73 void cd_player()
74 {
75 bios_run_cd_player();
76 }
77
yabauseut_init()78 void yabauseut_init()
79 {
80 int i;
81
82 bios_change_scu_interrupt_mask(0xFFFFFFFF, 0xFFFFFFFF);
83 interrupt_set_level_mask(0);
84
85 // Wait a bit
86 for (i = 0; i < 200000; i++) {}
87
88 interrupt_set_level_mask(0xF);
89
90 bios_set_scu_interrupt(0x40, 0);
91 bios_set_scu_interrupt(0x41, 0);
92 bios_set_scu_interrupt(0x42, 0);
93 bios_set_scu_interrupt(0x43, 0);
94 bios_set_scu_interrupt(0x44, 0);
95 bios_set_scu_interrupt(0x45, 0);
96 bios_set_scu_interrupt(0x46, 0);
97 bios_set_scu_interrupt(0x47, 0);
98 bios_set_scu_interrupt(0x48, 0);
99 bios_set_scu_interrupt(0x49, 0);
100 bios_set_scu_interrupt(0x4A, 0);
101 bios_set_scu_interrupt(0x4B, 0);
102 bios_set_scu_interrupt(0x4C, 0);
103 bios_set_scu_interrupt(0x4D, 0);
104 bios_set_scu_interrupt(0x50, 0);
105
106 init_iapetus(RES_320x224);
107
108 // Setup a screen for us draw on
109 test_disp_settings.is_bitmap = TRUE;
110 test_disp_settings.bitmap_size = BG_BITMAP512x256;
111 test_disp_settings.transparent_bit = 0;
112 test_disp_settings.color = BG_256COLOR;
113 test_disp_settings.special_priority = 0;
114 test_disp_settings.special_color_calc = 0;
115 test_disp_settings.extra_palette_num = 0;
116 test_disp_settings.map_offset = 0;
117 test_disp_settings.rotation_mode = 0;
118 test_disp_settings.parameter_addr = 0x25E60000;
119 vdp_rbg0_init(&test_disp_settings);
120
121 // Use the default palette
122 vdp_set_default_palette();
123
124 // Setup an 8x8 1BPP font
125 test_disp_font.data = font_8x8;
126 test_disp_font.width = 8;
127 test_disp_font.height = 8;
128 test_disp_font.bpp = 1;
129 test_disp_font.out = (u8 *)0x25E00000;
130 vdp_set_font(SCREEN_RBG0, &test_disp_font, 1);
131
132 // Print messages and cursor
133 vdp_disp_on();
134 }
135
136 #ifdef BUILD_AUTOMATED_TESTING
137
138 void (*auto_tests[])() =
139 {
140 //sh2
141 sh2_test,
142 //sh2 slave
143 slavesh2_test,
144 //scu
145 scu_register_test,
146 scu_int_test,
147 scu_dma_test,
148 scu_dsp_test,
149 //cd block
150 //mpeg card
151 //cartridge
152 //68k
153 //scsp
154 scsp_timing_test,
155 scsp_misc_test,
156 scsp_dsp_test,
157 //smpc
158 //vdp1
159 vdp1_framebuffer_tests,
160 //vdp2
161 vdp2_auto_tests,
162 auto_test_all_finished
163 };
164
165 #endif
166
167 //by resetting the system inbetween tests, tests can't cause other tests to
168 //fail due to incomplete system state cleanup
169
auto_test_get_selection()170 int auto_test_get_selection()
171 {
172 #ifdef BUILD_AUTOMATED_TESTING
173 volatile u8* ptr = (volatile u8 *)VDP2_RAM;
174 return ptr[AUTO_TEST_SELECT_ADDRESS];
175 #endif
176 return 0;
177 }
178
auto_test_do_selected_test(int selection)179 void auto_test_do_selected_test(int selection)
180 {
181 #ifdef BUILD_AUTOMATED_TESTING
182 (*auto_tests[selection])();
183 #endif
184 }
185
main()186 int main()
187 {
188 int choice;
189
190 int auto_test_selection = auto_test_get_selection();
191
192 yabauseut_init();
193
194 auto_test_do_selected_test(auto_test_selection);
195
196 // Display Main Menu
197 for(;;)
198 {
199 vdp_printf(&test_disp_font, 0 * 8, 27 * 8, 0xF, "Build Time: %s %s", __DATE__, __TIME__);
200 choice = gui_do_menu(main_menu, &test_disp_font, 0, 0, "YabauseUT v0.1", MTYPE_CENTER, -1);
201 gui_clear_scr(&test_disp_font);
202 }
203 }