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 "tests.h"
22 #include "vdp1.h"
23 
24 //////////////////////////////////////////////////////////////////////////////
25 
vdp1_test()26 void vdp1_test()
27 {
28    int choice;
29 
30    menu_item_struct vdp1_menu[] = {
31    { "Draw commands" , &vdp1_draw_test, },
32    { "Clip commands" , &vdp1_clip_test, },
33    { "Misc" , &vdp1_misc_test, },
34    { "\0", NULL }
35    };
36 
37    for (;;)
38    {
39       choice = gui_do_menu(vdp1_menu, &test_disp_font, 0, 0, "VDP1 Tests", MTYPE_CENTER, -1);
40       if (choice == -1)
41          break;
42    }
43 }
44 
45 //////////////////////////////////////////////////////////////////////////////
46 
vdp1_draw_test()47 void vdp1_draw_test()
48 {
49 }
50 
51 //////////////////////////////////////////////////////////////////////////////
52 
vdp1_clip_test()53 void vdp1_clip_test()
54 {
55    int gouraud_table_address = 0x40000;
56    u32 clipping_mode = 3;//outside
57 
58    u16* p = (u16 *)(0x25C00000 + gouraud_table_address);
59 
60    auto_test_sub_test_start("Clipping test");
61 
62    VDP1_REG_FBCR = 0;
63 
64    vdp_start_draw_list();
65 
66    sprite_struct quad;
67 
68    quad.x = 0;
69    quad.y = 0;
70 
71    vdp_local_coordinate(&quad);
72 
73    //system clipping
74    quad.x = 319 - 8;
75    quad.y = 223 - 8;
76 
77    vdp_system_clipping(&quad);
78 
79    //user clipping
80    quad.x = 8;
81    quad.y = 8;
82    quad.x2 = 319 - 16;
83    quad.y2 = 223 - 16;
84 
85    vdp_user_clipping(&quad);
86 
87    //fullscreen polygon
88    quad.x = 319;
89    quad.y = 0;
90    quad.x2 = 319;
91    quad.y2 = 223;
92    quad.x3 = 0;
93    quad.y3 = 223;
94    quad.x4 = 0;
95    quad.y4 = 0;
96 
97    quad.bank = RGB16(0x10, 0x10, 0x10);//gray
98 
99    quad.gouraud_addr = gouraud_table_address;
100 
101    quad.attr = (clipping_mode << 9) | 4;//use gouraud shading
102 
103    //red, green, blue, and white
104    p[0] = RGB16(31, 0, 0);
105    p[1] = RGB16(0, 31, 0);
106    p[2] = RGB16(0, 0, 31);
107    p[3] = RGB16(31, 31, 31);
108 
109    vdp_draw_polygon(&quad);
110 
111    vdp_end_draw_list();
112 
113    vdp_vsync();
114 
115    VDP1_REG_FBCR = 3;
116 
117    vdp_vsync();
118    vdp_vsync();
119 
120 #ifdef BUILD_AUTOMATED_TESTING
121 
122    auto_test_get_framebuffer();
123 
124 #else
125 
126    for (;;)
127    {
128       while (!(VDP2_REG_TVSTAT & 8))
129       {
130          ud_check(0);
131       }
132 
133       while (VDP2_REG_TVSTAT & 8)
134       {
135 
136       }
137 
138       if (per[0].but_push_once & PAD_A)
139       {
140          clipping_mode = 0; //clipping disabled
141       }
142       if (per[0].but_push_once & PAD_B)
143       {
144          clipping_mode = 2; //inside drawing mode
145       }
146       if (per[0].but_push_once & PAD_C)
147       {
148          clipping_mode = 3; //outside drawing mode
149       }
150 
151       if (per[0].but_push_once & PAD_START)
152          break;
153 
154       if (per[0].but_push_once & PAD_X)
155       {
156          ar_menu();
157       }
158 
159       if (per[0].but_push_once & PAD_Y)
160       {
161          reset_system();
162       }
163    }
164 
165 #endif
166 
167 }
168 
169 //////////////////////////////////////////////////////////////////////////////
170 
vdp1_misc_test()171 void vdp1_misc_test()
172 {
173 }
174 
175 //////////////////////////////////////////////////////////////////////////////
176 
vdp1_framebuffer_write_test()177 void vdp1_framebuffer_write_test()
178 {
179    volatile u16* framebuffer_ptr = (volatile u16*)0x25C80000;
180    int i;
181 
182    vdp_vsync();
183 
184    VDP1_REG_FBCR = 3;
185 
186    //we have to wait a little bit so we don't write to both framebuffers
187    vdp_wait_hblankout();
188 
189    for (i = 0; i < 128; i += 4)
190    {
191       framebuffer_ptr[i + 0] = 0xdead;
192       framebuffer_ptr[i + 1] = 0xbeef;
193       framebuffer_ptr[i + 2] = 0xfeed;
194       framebuffer_ptr[i + 3] = 0xcafe;
195    }
196 
197 #ifdef BUILD_AUTOMATED_TESTING
198 
199    auto_test_get_framebuffer();
200 
201 #else
202 
203    for (;;)
204    {
205       while (!(VDP2_REG_TVSTAT & 8))
206       {
207          ud_check(0);
208       }
209 
210       while (VDP2_REG_TVSTAT & 8) {}
211 
212       if (per[0].but_push_once & PAD_START)
213          break;
214 
215       if (per[0].but_push_once & PAD_X)
216       {
217          ar_menu();
218       }
219 
220       if (per[0].but_push_once & PAD_Y)
221       {
222          reset_system();
223       }
224    }
225 #endif
226 }
227 
228 //////////////////////////////////////////////////////////////////////////////
229 
vdp1_framebuffer_tests()230 void vdp1_framebuffer_tests()
231 {
232    auto_test_section_start("Vdp1 framebuffer tests");
233 
234    vdp1_clip_test();
235 
236    auto_test_section_end();
237 }
238 
239 //////////////////////////////////////////////////////////////////////////////
240