From 99e678f049f08b14a30d282d2b3e459673540bc4 Mon Sep 17 00:00:00 2001 From: LuigiBlood Date: Sat, 16 Dec 2017 17:52:35 +0100 Subject: [PATCH] [BS-X] Support for bigger SatData files --- bsx.cpp | 33 +++++++++++++++++++++++++-------- bsx.h | 1 + 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/bsx.cpp b/bsx.cpp index 37d41b4a..89814911 100644 --- a/bsx.cpp +++ b/bsx.cpp @@ -893,7 +893,7 @@ void S9xBSXSetStream1 (uint8 count) long str1size = BSX.sat_stream1.tellg(); BSX.sat_stream1.seekg(0, BSX.sat_stream1.beg); float QueueSize = str1size / 22.; - BSX.PPU[0x218A - BSXPPUBASE] = (uint8)(ceil(QueueSize)); + BSX.sat_stream1_queue = (uint16)(ceil(QueueSize)); BSX.PPU[0x218D - BSXPPUBASE] = 0; BSX.sat_stream1_first = TRUE; BSX.sat_stream1_loaded = TRUE; @@ -925,7 +925,7 @@ void S9xBSXSetStream2 (uint8 count) long str2size = BSX.sat_stream2.tellg(); BSX.sat_stream2.seekg(0, BSX.sat_stream2.beg); float QueueSize = str2size / 22.; - BSX.PPU[0x2190 - BSXPPUBASE] = (uint8)(ceil(QueueSize)); + BSX.sat_stream2_queue = (uint16)(ceil(QueueSize)); BSX.PPU[0x2193 - BSXPPUBASE] = 0; BSX.sat_stream2_first = TRUE; BSX.sat_stream2_loaded = TRUE; @@ -1005,7 +1005,7 @@ uint8 S9xGetBSXPPU (uint16 address) break; } - if (BSX.PPU[0x218A - BSXPPUBASE] <= 0) + if (BSX.sat_stream1_queue <= 0) { BSX.sat_stream1_count++; S9xBSXSetStream1(BSX.sat_stream1_count - 1); @@ -1018,7 +1018,14 @@ uint8 S9xGetBSXPPU (uint16 address) } if (BSX.sat_stream1_loaded) + { + //Lock at 0x7F for bigger packets + if (BSX.sat_stream1_queue >= 128) + BSX.PPU[0x218A - BSXPPUBASE] = 0x7F; + else + BSX.PPU[0x218A - BSXPPUBASE] = BSX.sat_stream1_queue; t = BSX.PPU[0x218A - BSXPPUBASE]; + } else t = 0; break; @@ -1042,9 +1049,9 @@ uint8 S9xGetBSXPPU (uint16 address) BSX.sat_stream1_first = FALSE; } - BSX.PPU[0x218A - BSXPPUBASE]--; + BSX.sat_stream1_queue--; - if (BSX.PPU[0x218A - BSXPPUBASE] == 0) + if (BSX.sat_stream1_queue == 0) { //Last packet temp |= 0x80; @@ -1116,7 +1123,7 @@ uint8 S9xGetBSXPPU (uint16 address) break; } - if (BSX.PPU[0x2190 - BSXPPUBASE] <= 0) + if (BSX.sat_stream2_queue <= 0) { BSX.sat_stream2_count++; S9xBSXSetStream2(BSX.sat_stream2_count - 1); @@ -1129,7 +1136,13 @@ uint8 S9xGetBSXPPU (uint16 address) } if (BSX.sat_stream2_loaded) + { + if (BSX.sat_stream2_queue >= 128) + BSX.PPU[0x2190 - BSXPPUBASE] = 0x7F; + else + BSX.PPU[0x2190 - BSXPPUBASE] = BSX.sat_stream2_queue; t = BSX.PPU[0x2190 - BSXPPUBASE]; + } else t = 0; break; @@ -1153,9 +1166,9 @@ uint8 S9xGetBSXPPU (uint16 address) BSX.sat_stream2_first = FALSE; } - BSX.PPU[0x2190 - BSXPPUBASE]--; + BSX.sat_stream2_queue--; - if (BSX.PPU[0x2190 - BSXPPUBASE] == 0) + if (BSX.sat_stream2_queue == 0) { //Last packet temp |= 0x80; @@ -1488,6 +1501,10 @@ void S9xResetBSX (void) BSX.MMC[0x07] = BSX.MMC[0x08] = 0x80; BSX.MMC[0x0E] = 0x80; + // default register values + BSX.PPU[0x2196 - BSXPPUBASE] = 0x10; + BSX.PPU[0x2197 - BSXPPUBASE] = 0x80; + // stream reset BSX.sat_pf_latch1_enable = BSX.sat_dt_latch1_enable = FALSE; BSX.sat_pf_latch2_enable = BSX.sat_dt_latch2_enable = FALSE; diff --git a/bsx.h b/bsx.h index 235e5beb..0bbf28c1 100644 --- a/bsx.h +++ b/bsx.h @@ -227,6 +227,7 @@ struct SBSX bool sat_stream1_loaded, sat_stream2_loaded; bool sat_stream1_first, sat_stream2_first; uint8 sat_stream1_count, sat_stream2_count; + uint16 sat_stream1_queue, sat_stream2_queue; }; extern struct SBSX BSX;