@@ -73,8 +73,15 @@ Graphics::Graphics(std::string fontdata, PicoRam* memory) {
73
73
74
74
75
75
uint8_t * Graphics::GetP8FrameBuffer (){
76
- // TODO: replace with ram's screen buffer
77
- return _memory->screenBuffer ;
76
+ return _memory->hwState .screenDataMemMapping == 0
77
+ ? _memory->spriteSheetData
78
+ : _memory->screenBuffer ;
79
+ }
80
+
81
+ uint8_t * Graphics::GetP8SpriteSheetBuffer (){
82
+ return _memory->hwState .spriteSheetMemMapping == 0x60
83
+ ? _memory->screenBuffer
84
+ : _memory->spriteSheetData ;
78
85
}
79
86
80
87
uint8_t * Graphics::GetScreenPaletteMap (){
@@ -105,7 +112,7 @@ void Graphics::copySpriteToScreen(
105
112
106
113
auto &drawState = _memory->drawState ;
107
114
auto &hwState = _memory->hwState ;
108
- auto & screenBuffer = _memory-> screenBuffer ;
115
+ uint8_t * screenBuffer = GetP8FrameBuffer () ;
109
116
110
117
const uint8_t writeMask = hwState.colorBitmask & 15 ;
111
118
const uint8_t readMask = hwState.colorBitmask >> 4 ;
@@ -256,7 +263,7 @@ void Graphics::copyStretchSpriteToScreen(
256
263
257
264
auto &drawState = _memory->drawState ;
258
265
auto &hwState = _memory->hwState ;
259
- auto & screenBuffer = _memory-> screenBuffer ;
266
+ uint8_t * screenBuffer = GetP8FrameBuffer () ;
260
267
261
268
const uint8_t writeMask = hwState.colorBitmask & 15 ;
262
269
const uint8_t readMask = hwState.colorBitmask >> 4 ;
@@ -529,7 +536,7 @@ void Graphics::_setPixelFromSprite(int x, int y, uint8_t col) {
529
536
530
537
auto &drawState = _memory->drawState ;
531
538
auto &hwState = _memory->hwState ;
532
- auto & screenBuffer = _memory-> screenBuffer ;
539
+ uint8_t * screenBuffer = GetP8FrameBuffer () ;
533
540
534
541
// col = getDrawPalMappedColor(col);
535
542
col = drawState.drawPaletteMap [col & 0x0f ] & 0x0f ;
@@ -555,7 +562,7 @@ void Graphics::_setPixelFromPen(int x, int y) {
555
562
556
563
auto &drawState = _memory->drawState ;
557
564
auto &hwState = _memory->hwState ;
558
- auto & screenBuffer = _memory-> screenBuffer ;
565
+ uint8_t * screenBuffer = GetP8FrameBuffer () ;
559
566
560
567
uint8_t col = drawState.color ;
561
568
@@ -609,7 +616,7 @@ void Graphics::cls() {
609
616
void Graphics::cls (uint8_t color) {
610
617
color = color & 15 ;
611
618
uint8_t val = color << 4 | color;
612
- memset (_memory-> screenBuffer , val, sizeof (_memory->screenBuffer ));
619
+ memset (GetP8FrameBuffer () , val, sizeof (_memory->screenBuffer ));
613
620
614
621
_memory->drawState .text_x = 0 ;
615
622
_memory->drawState .text_y = 0 ;
@@ -638,7 +645,7 @@ uint8_t Graphics::pget(int x, int y){
638
645
applyCameraToPoint (&x, &y);
639
646
640
647
if (isOnScreen (x, y)){
641
- return getPixelNibble (x, y, _memory-> screenBuffer );
648
+ return getPixelNibble (x, y, GetP8FrameBuffer () );
642
649
}
643
650
644
651
return 0 ;
@@ -744,6 +751,7 @@ void Graphics::_private_h_line(int x1, int x2, int y){
744
751
void Graphics::_private_v_line (int y1, int y2, int x){
745
752
auto &drawState = _memory->drawState ;
746
753
auto &hwState = _memory->hwState ;
754
+ uint8_t * screenBuffer = GetP8FrameBuffer ();
747
755
748
756
if (!(x >= drawState.clip_xb && x < drawState.clip_xe )) {
749
757
return ;
@@ -776,7 +784,7 @@ void Graphics::_private_v_line (int y1, int y2, int x){
776
784
for (int16_t y = miny; y <= maxy; ++y)
777
785
{
778
786
int pixIdx = COMBINED_IDX (x, y);
779
- auto &data = _memory-> screenBuffer [pixIdx];
787
+ auto &data = screenBuffer[pixIdx];
780
788
data = (data & mask) | nibble;
781
789
}
782
790
}
@@ -1354,7 +1362,7 @@ void Graphics::spr(
1354
1362
int spr_y = (n / 16 ) * 8 ;
1355
1363
int16_t spr_w = (int16_t )(w * (fix32)8 );
1356
1364
int16_t spr_h = (int16_t )(h * (fix32)8 );
1357
- copySpriteToScreen (_memory-> spriteSheetData , x, y, spr_x, spr_y, spr_w, spr_h, flip_x, flip_y);
1365
+ copySpriteToScreen (GetP8SpriteSheetBuffer () , x, y, spr_x, spr_y, spr_w, spr_h, flip_x, flip_y);
1358
1366
}
1359
1367
1360
1368
void Graphics::sspr (
@@ -1369,7 +1377,7 @@ void Graphics::sspr(
1369
1377
bool flip_x = false ,
1370
1378
bool flip_y = false )
1371
1379
{
1372
- copyStretchSpriteToScreen (_memory-> spriteSheetData , sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
1380
+ copyStretchSpriteToScreen (GetP8SpriteSheetBuffer () , sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
1373
1381
}
1374
1382
1375
1383
bool Graphics::fget (uint8_t n, uint8_t f){
@@ -1394,11 +1402,11 @@ void Graphics::fset(uint8_t n, uint8_t v){
1394
1402
}
1395
1403
1396
1404
uint8_t Graphics::sget (uint8_t x, uint8_t y){
1397
- return getPixelNibble (x, y, _memory-> spriteSheetData );
1405
+ return getPixelNibble (x, y, GetP8SpriteSheetBuffer () );
1398
1406
}
1399
1407
1400
1408
void Graphics::sset (uint8_t x, uint8_t y, uint8_t c){
1401
- setPixelNibble (x, y, c, _memory-> spriteSheetData );
1409
+ setPixelNibble (x, y, c, GetP8SpriteSheetBuffer () );
1402
1410
}
1403
1411
1404
1412
std::tuple<int16_t , int16_t > Graphics::camera () {
@@ -1437,30 +1445,61 @@ std::tuple<uint8_t, uint8_t, uint8_t, uint8_t> Graphics::clip(int x, int y, int
1437
1445
}
1438
1446
1439
1447
1440
- // map methods heavily based on tac08 implementation
1441
1448
uint8_t Graphics::mget (int celx, int cely){
1442
- if (celx < 0 || celx >= 128 || cely < 0 || cely >= 64 )
1443
- return 0 ;
1449
+ const bool bigMap = _memory->hwState .mapMemMapping >= 0x80 ;
1450
+ const int mapW = _memory->hwState .widthOfTheMap ;
1451
+ const int idx = cely * mapW + celx;
1444
1452
1445
- if (cely < 32 ) {
1446
- return _memory-> mapData [cely * 128 + celx] ;
1453
+ if (idx < 0 ) {
1454
+ return 0 ;
1447
1455
}
1448
- else if (cely < 64 ){
1449
- return _memory->spriteSheetData [cely* 128 + celx];
1456
+
1457
+ if (bigMap){
1458
+ const int mapLocation = _memory->hwState .mapMemMapping << 8 ;
1459
+ const int mapSize = 0x10000 - mapLocation;
1460
+ if (idx >= mapSize){
1461
+ return 0 ;
1462
+ }
1463
+ const int offset = 0x8000 - mapSize;
1464
+ return _memory->userData [offset + idx];
1465
+ }
1466
+ else {
1467
+ if (idx < 4096 ) {
1468
+ return _memory->mapData [idx];
1469
+ }
1470
+ else if (idx < 8192 ){
1471
+ return _memory->spriteSheetData [idx];
1472
+ }
1450
1473
}
1451
1474
1452
1475
return 0 ;
1453
1476
}
1454
1477
1455
1478
void Graphics::mset (int celx, int cely, uint8_t snum){
1456
- if (celx < 0 || celx >= 128 || cely < 0 || cely >= 64 )
1479
+ const bool bigMap = _memory->hwState .mapMemMapping >= 0x80 ;
1480
+ const int mapW = _memory->hwState .widthOfTheMap ;
1481
+ const int idx = cely * mapW + celx;
1482
+
1483
+ if (idx < 0 ) {
1457
1484
return ;
1485
+ }
1458
1486
1459
- if (cely < 32 ) {
1460
- _memory->mapData [cely * 128 + celx] = snum;
1487
+ if (bigMap){
1488
+ const int mapLocation = _memory->hwState .mapMemMapping << 8 ;
1489
+ const int mapSize = 0x10000 - mapLocation;
1490
+ if (idx >= mapSize){
1491
+ return ;
1492
+ }
1493
+ const int offset = 0x8000 - mapSize;
1494
+ _memory->userData [offset + idx] = snum;
1461
1495
}
1462
- else if (cely < 64 ){
1463
- _memory->spriteSheetData [cely* 128 + celx] = snum;
1496
+ else {
1497
+ if (idx < 4096 ) {
1498
+ _memory->mapData [idx] = snum;
1499
+ }
1500
+ else if (idx < 8192 ) {
1501
+ _memory->spriteSheetData [idx] = snum;
1502
+ }
1464
1503
}
1465
1504
}
1466
1505
0 commit comments