16
16
17
17
#include "common.h"
18
18
#include "../../gpulib/gpu_timing.h"
19
+ #include "../../gpulib/gpu.h"
19
20
20
21
#ifndef command_lengths
21
22
const u8 command_lengths [256 ] =
@@ -245,12 +246,27 @@ static void do_fill(psx_gpu_struct *psx_gpu, u32 x, u32 y,
245
246
#define SET_Ex (r , v )
246
247
#endif
247
248
249
+ static void textured_sprite (psx_gpu_struct * psx_gpu , const u32 * list ,
250
+ s32 width , s32 height , u32 * cpu_cycles_sum , u32 * cpu_cycles )
251
+ {
252
+ s32 x = sign_extend_11bit (list [1 ] + psx_gpu -> offset_x );
253
+ s32 y = sign_extend_11bit ((list [1 ] >> 16 ) + psx_gpu -> offset_y );
254
+ u8 v = (list [2 ] >> 8 ) & 0xff ;
255
+ u8 u = list [2 ] & 0xff ;
256
+
257
+ set_clut (psx_gpu , list [2 ] >> 16 );
258
+
259
+ render_sprite (psx_gpu , x , y , u , v , & width , & height , list [0 ] >> 24 , list [0 ]);
260
+ gput_sum (* cpu_cycles_sum , * cpu_cycles , gput_sprite (width , height ));
261
+ }
262
+
248
263
u32 gpu_parse (psx_gpu_struct * psx_gpu , u32 * list , u32 size ,
249
264
s32 * cpu_cycles_sum_out , s32 * cpu_cycles_last , u32 * last_command )
250
265
{
251
266
vertex_struct vertexes [4 ] __attribute__((aligned (16 ))) = {};
252
267
u32 current_command = 0 , command_length ;
253
268
u32 cpu_cycles_sum = 0 , cpu_cycles = * cpu_cycles_last ;
269
+ u32 siplified_prim [4 * 4 ];
254
270
255
271
u32 * list_start = list ;
256
272
u32 * list_end = list + (size / 4 );
@@ -328,8 +344,19 @@ u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
328
344
329
345
case 0x2C ... 0x2F :
330
346
{
331
- set_clut (psx_gpu , list_s16 [5 ]);
332
- set_texture (psx_gpu , list_s16 [9 ]);
347
+ u32 i , simplified_count ;
348
+ set_texture (psx_gpu , list [4 ] >> 16 );
349
+ if ((simplified_count = prim_try_simplify_quad_t (siplified_prim , list )))
350
+ {
351
+ for (i = 0 ; i < simplified_count ; i ++ ) {
352
+ const u32 * list_ = & siplified_prim [i * 4 ];
353
+ textured_sprite (psx_gpu , list_ , list_ [3 ] & 0x3FF ,
354
+ (list_ [3 ] >> 16 ) & 0x1FF , & cpu_cycles_sum , & cpu_cycles );
355
+ }
356
+ break ;
357
+ }
358
+
359
+ set_clut (psx_gpu , list [2 ] >> 16 );
333
360
set_triangle_color (psx_gpu , list [0 ] & 0xFFFFFF );
334
361
335
362
get_vertex_data_xy_uv (0 , 2 );
@@ -383,8 +410,19 @@ u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
383
410
384
411
case 0x3C ... 0x3F :
385
412
{
386
- set_clut (psx_gpu , list_s16 [5 ]);
387
- set_texture (psx_gpu , list_s16 [11 ]);
413
+ u32 i , simplified_count ;
414
+ set_texture (psx_gpu , list [5 ] >> 16 );
415
+ if ((simplified_count = prim_try_simplify_quad_gt (siplified_prim , list )))
416
+ {
417
+ for (i = 0 ; i < simplified_count ; i ++ ) {
418
+ const u32 * list_ = & siplified_prim [i * 4 ];
419
+ textured_sprite (psx_gpu , list_ , list_ [3 ] & 0x3FF ,
420
+ (list_ [3 ] >> 16 ) & 0x1FF , & cpu_cycles_sum , & cpu_cycles );
421
+ }
422
+ break ;
423
+ }
424
+
425
+ set_clut (psx_gpu , list [2 ] >> 16 );
388
426
389
427
get_vertex_data_xy_uv_rgb (0 , 0 );
390
428
get_vertex_data_xy_uv_rgb (1 , 6 );
@@ -525,23 +563,12 @@ u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
525
563
gput_sum (cpu_cycles_sum , cpu_cycles , gput_sprite (width , height ));
526
564
break ;
527
565
}
528
-
529
- case 0x64 ... 0x67 :
530
- {
531
- u32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
532
- u32 y = sign_extend_11bit (list_s16 [3 ] + psx_gpu -> offset_y );
533
- u32 uv = list_s16 [4 ];
534
- s32 width = list_s16 [6 ] & 0x3FF ;
535
- s32 height = list_s16 [7 ] & 0x1FF ;
536
-
537
- set_clut (psx_gpu , list_s16 [5 ]);
538
566
539
- render_sprite ( psx_gpu , x , y , uv & 0xFF , ( uv >> 8 ) & 0xFF ,
540
- & width , & height , current_command , list [0 ]);
541
- gput_sum ( cpu_cycles_sum , cpu_cycles , gput_sprite ( width , height ) );
567
+ case 0x64 ... 0x67 :
568
+ textured_sprite ( psx_gpu , list , list [ 3 ] & 0x3FF , ( list [3 ] >> 16 ) & 0x1FF ,
569
+ & cpu_cycles_sum , & cpu_cycles );
542
570
break ;
543
- }
544
-
571
+
545
572
case 0x68 ... 0x6B :
546
573
{
547
574
s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
@@ -565,22 +592,11 @@ u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
565
592
gput_sum (cpu_cycles_sum , cpu_cycles , gput_sprite (width , height ));
566
593
break ;
567
594
}
568
-
569
- case 0x74 ... 0x77 :
570
- {
571
- s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
572
- s32 y = sign_extend_11bit (list_s16 [3 ] + psx_gpu -> offset_y );
573
- u32 uv = list_s16 [4 ];
574
- s32 width = 8 , height = 8 ;
575
595
576
- set_clut (psx_gpu , list_s16 [5 ]);
577
-
578
- render_sprite (psx_gpu , x , y , uv & 0xFF , (uv >> 8 ) & 0xFF ,
579
- & width , & height , current_command , list [0 ]);
580
- gput_sum (cpu_cycles_sum , cpu_cycles , gput_sprite (width , height ));
596
+ case 0x74 ... 0x77 :
597
+ textured_sprite (psx_gpu , list , 8 , 8 , & cpu_cycles_sum , & cpu_cycles );
581
598
break ;
582
- }
583
-
599
+
584
600
case 0x78 ... 0x7B :
585
601
{
586
602
s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
@@ -594,19 +610,8 @@ u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
594
610
}
595
611
596
612
case 0x7C ... 0x7F :
597
- {
598
- s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
599
- s32 y = sign_extend_11bit (list_s16 [3 ] + psx_gpu -> offset_y );
600
- u32 uv = list_s16 [4 ];
601
- s32 width = 16 , height = 16 ;
602
-
603
- set_clut (psx_gpu , list_s16 [5 ]);
604
-
605
- render_sprite (psx_gpu , x , y , uv & 0xFF , (uv >> 8 ) & 0xFF ,
606
- & width , & height , current_command , list [0 ]);
607
- gput_sum (cpu_cycles_sum , cpu_cycles , gput_sprite (width , height ));
613
+ textured_sprite (psx_gpu , list , 16 , 16 , & cpu_cycles_sum , & cpu_cycles );
608
614
break ;
609
- }
610
615
611
616
#ifdef PCSX
612
617
case 0x1F : // irq?
@@ -1155,12 +1160,31 @@ static void do_sprite_enhanced(psx_gpu_struct *psx_gpu, int x, int y,
1155
1160
}
1156
1161
#endif
1157
1162
1163
+ static void textured_sprite_enh (psx_gpu_struct * psx_gpu , const u32 * list ,
1164
+ s32 width , s32 height , u32 * cpu_cycles_sum , u32 * cpu_cycles )
1165
+ {
1166
+ s32 x = sign_extend_11bit (list [1 ] + psx_gpu -> offset_x );
1167
+ s32 y = sign_extend_11bit ((list [1 ] >> 16 ) + psx_gpu -> offset_y );
1168
+ s32 width_b = width , height_b = height ;
1169
+ u8 v = (list [2 ] >> 8 ) & 0xff ;
1170
+ u8 u = list [2 ] & 0xff ;
1171
+
1172
+ set_clut (psx_gpu , list [2 ] >> 16 );
1173
+
1174
+ render_sprite (psx_gpu , x , y , u , v , & width , & height , list [0 ] >> 24 , list [0 ]);
1175
+ gput_sum (* cpu_cycles_sum , * cpu_cycles , gput_sprite (width , height ));
1176
+
1177
+ if (check_enhanced_range (psx_gpu , x , x + width ))
1178
+ do_sprite_enhanced (psx_gpu , x , y , u , v , width_b , height_b , list [0 ]);
1179
+ }
1180
+
1158
1181
u32 gpu_parse_enhanced (psx_gpu_struct * psx_gpu , u32 * list , u32 size ,
1159
1182
s32 * cpu_cycles_sum_out , s32 * cpu_cycles_last , u32 * last_command )
1160
1183
{
1161
1184
vertex_struct vertexes [4 ] __attribute__((aligned (16 ))) = {};
1162
1185
u32 current_command = 0 , command_length ;
1163
1186
u32 cpu_cycles_sum = 0 , cpu_cycles = * cpu_cycles_last ;
1187
+ u32 siplified_prim [4 * 4 ];
1164
1188
1165
1189
u32 * list_start = list ;
1166
1190
u32 * list_end = list + (size / 4 );
@@ -1265,8 +1289,19 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
1265
1289
1266
1290
case 0x2C ... 0x2F :
1267
1291
{
1268
- set_clut (psx_gpu , list_s16 [5 ]);
1269
- set_texture (psx_gpu , list_s16 [9 ]);
1292
+ u32 i , simplified_count ;
1293
+ set_texture (psx_gpu , list [4 ] >> 16 );
1294
+ if ((simplified_count = prim_try_simplify_quad_t (siplified_prim , list )))
1295
+ {
1296
+ for (i = 0 ; i < simplified_count ; i ++ ) {
1297
+ const u32 * list_ = & siplified_prim [i * 4 ];
1298
+ textured_sprite_enh (psx_gpu , list_ , list_ [3 ] & 0x3FF ,
1299
+ (list_ [3 ] >> 16 ) & 0x1FF , & cpu_cycles_sum , & cpu_cycles );
1300
+ }
1301
+ break ;
1302
+ }
1303
+
1304
+ set_clut (psx_gpu , list [2 ] >> 16 );
1270
1305
set_triangle_color (psx_gpu , list [0 ] & 0xFFFFFF );
1271
1306
1272
1307
get_vertex_data_xy_uv (0 , 2 );
@@ -1318,8 +1353,19 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
1318
1353
1319
1354
case 0x3C ... 0x3F :
1320
1355
{
1321
- set_clut (psx_gpu , list_s16 [5 ]);
1322
- set_texture (psx_gpu , list_s16 [11 ]);
1356
+ u32 i , simplified_count ;
1357
+ set_texture (psx_gpu , list [5 ] >> 16 );
1358
+ if ((simplified_count = prim_try_simplify_quad_gt (siplified_prim , list )))
1359
+ {
1360
+ for (i = 0 ; i < simplified_count ; i ++ ) {
1361
+ const u32 * list_ = & siplified_prim [i * 4 ];
1362
+ textured_sprite_enh (psx_gpu , list_ , list_ [3 ] & 0x3FF ,
1363
+ (list_ [3 ] >> 16 ) & 0x1FF , & cpu_cycles_sum , & cpu_cycles );
1364
+ }
1365
+ break ;
1366
+ }
1367
+
1368
+ set_clut (psx_gpu , list [2 ] >> 16 );
1323
1369
1324
1370
get_vertex_data_xy_uv_rgb (0 , 0 );
1325
1371
get_vertex_data_xy_uv_rgb (1 , 6 );
@@ -1475,30 +1521,12 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
1475
1521
}
1476
1522
break ;
1477
1523
}
1478
-
1479
- case 0x64 ... 0x67 :
1480
- {
1481
- u32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
1482
- u32 y = sign_extend_11bit (list_s16 [3 ] + psx_gpu -> offset_y );
1483
- u8 u = list_s16 [4 ];
1484
- u8 v = list_s16 [4 ] >> 8 ;
1485
- s32 width = list_s16 [6 ] & 0x3FF ;
1486
- s32 height = list_s16 [7 ] & 0x1FF ;
1487
-
1488
- set_clut (psx_gpu , list_s16 [5 ]);
1489
1524
1490
- render_sprite (psx_gpu , x , y , u , v ,
1491
- & width , & height , current_command , list [0 ]);
1492
- gput_sum (cpu_cycles_sum , cpu_cycles , gput_sprite (width , height ));
1493
-
1494
- if (check_enhanced_range (psx_gpu , x , x + width )) {
1495
- width = list_s16 [6 ] & 0x3FF ;
1496
- height = list_s16 [7 ] & 0x1FF ;
1497
- do_sprite_enhanced (psx_gpu , x , y , u , v , width , height , list [0 ]);
1498
- }
1525
+ case 0x64 ... 0x67 :
1526
+ textured_sprite_enh (psx_gpu , list , list [3 ] & 0x3FF , (list [3 ] >> 16 ) & 0x1FF ,
1527
+ & cpu_cycles_sum , & cpu_cycles );
1499
1528
break ;
1500
- }
1501
-
1529
+
1502
1530
case 0x68 ... 0x6B :
1503
1531
{
1504
1532
s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
@@ -1528,26 +1556,11 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
1528
1556
do_sprite_enhanced (psx_gpu , x , y , 0 , 0 , 8 , 8 , list [0 ]);
1529
1557
break ;
1530
1558
}
1531
-
1532
- case 0x74 ... 0x77 :
1533
- {
1534
- s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
1535
- s32 y = sign_extend_11bit (list_s16 [3 ] + psx_gpu -> offset_y );
1536
- u8 u = list_s16 [4 ];
1537
- u8 v = list_s16 [4 ] >> 8 ;
1538
- s32 width = 8 , height = 8 ;
1539
1559
1540
- set_clut (psx_gpu , list_s16 [5 ]);
1541
-
1542
- render_sprite (psx_gpu , x , y , u , v ,
1543
- & width , & height , current_command , list [0 ]);
1544
- gput_sum (cpu_cycles_sum , cpu_cycles , gput_sprite (width , height ));
1545
-
1546
- if (check_enhanced_range (psx_gpu , x , x + 8 ))
1547
- do_sprite_enhanced (psx_gpu , x , y , u , v , 8 , 8 , list [0 ]);
1560
+ case 0x74 ... 0x77 :
1561
+ textured_sprite_enh (psx_gpu , list , 8 , 8 , & cpu_cycles_sum , & cpu_cycles );
1548
1562
break ;
1549
- }
1550
-
1563
+
1551
1564
case 0x78 ... 0x7B :
1552
1565
{
1553
1566
s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
@@ -1562,25 +1575,10 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
1562
1575
do_sprite_enhanced (psx_gpu , x , y , 0 , 0 , 16 , 16 , list [0 ]);
1563
1576
break ;
1564
1577
}
1565
-
1566
- case 0x7C ... 0x7F :
1567
- {
1568
- s32 x = sign_extend_11bit (list_s16 [2 ] + psx_gpu -> offset_x );
1569
- s32 y = sign_extend_11bit (list_s16 [3 ] + psx_gpu -> offset_y );
1570
- u8 u = list_s16 [4 ];
1571
- u8 v = list_s16 [4 ] >> 8 ;
1572
- s32 width = 16 , height = 16 ;
1573
1578
1574
- set_clut (psx_gpu , list_s16 [5 ]);
1575
-
1576
- render_sprite (psx_gpu , x , y , u , v ,
1577
- & width , & height , current_command , list [0 ]);
1578
- gput_sum (cpu_cycles_sum , cpu_cycles , gput_sprite (width , height ));
1579
-
1580
- if (check_enhanced_range (psx_gpu , x , x + 16 ))
1581
- do_sprite_enhanced (psx_gpu , x , y , u , v , 16 , 16 , list [0 ]);
1579
+ case 0x7C ... 0x7F :
1580
+ textured_sprite_enh (psx_gpu , list , 16 , 16 , & cpu_cycles_sum , & cpu_cycles );
1582
1581
break ;
1583
- }
1584
1582
1585
1583
case 0x80 ... 0x9F : // vid -> vid
1586
1584
case 0xA0 ... 0xBF : // sys -> vid
0 commit comments