diff options
author | twinaphex | 2017-08-16 06:18:24 +0200 |
---|---|---|
committer | twinaphex | 2017-08-16 06:18:24 +0200 |
commit | 7a8802b9311099e5034054a69a309dcb17661dfa (patch) | |
tree | b78d6a0877c63dbc99148c52329dab2e0fc3d7c6 /source | |
parent | e2cffaea148cfb79cc3546642acb61245b96069e (diff) | |
download | snesemu-7a8802b9311099e5034054a69a309dcb17661dfa.tar.gz snesemu-7a8802b9311099e5034054a69a309dcb17661dfa.tar.bz2 snesemu-7a8802b9311099e5034054a69a309dcb17661dfa.zip |
Some C89 buildfixes
Diffstat (limited to 'source')
-rw-r--r-- | source/dma.c | 486 | ||||
-rw-r--r-- | source/gfx.c | 371 | ||||
-rw-r--r-- | source/memmap.c | 54 |
3 files changed, 467 insertions, 444 deletions
diff --git a/source/dma.c b/source/dma.c index 58aa2f1..7effb25 100644 --- a/source/dma.c +++ b/source/dma.c @@ -56,11 +56,11 @@ void S9xDoDMA(uint8_t Channel) } switch (d->BAddress) { - case 0x18: - case 0x19: - if (IPPU.RenderThisFrame) - FLUSH_REDRAW(); - break; + case 0x18: + case 0x19: + if (IPPU.RenderThisFrame) + FLUSH_REDRAW(); + break; } if (Settings.SDD1) { @@ -74,8 +74,8 @@ void S9xDoDMA(uint8_t Channel) in_ptr = GetBasePointer(((d->ABank << 16) | d->AAddress)); if (in_ptr) { - in_ptr += d->AAddress; - SDD1_decompress(sdd1_decode_buffer, in_ptr, d->TransferBytes); + in_ptr += d->AAddress; + SDD1_decompress(sdd1_decode_buffer, in_ptr, d->TransferBytes); } in_sdd1_dma = sdd1_decode_buffer; } @@ -84,14 +84,16 @@ void S9xDoDMA(uint8_t Channel) } if (Settings.SPC7110 && (d->AAddress == 0x4800 || d->ABank == 0x50)) { - int32_t c; + int32_t c, icount; spc7110_dma = &s7r.bank50[0]; + for(c = 0; c < count; c++) s7r.bank50[c] = spc7110dec_read(); - int32_t icount = (s7r.reg4809 | (s7r.reg480A << 8)) - count; - s7r.reg4809 = 0x00ff & icount; - s7r.reg480A = (0xff00 & icount) >> 8; - inc = 1; + + icount = (s7r.reg4809 | (s7r.reg480A << 8)) - count; + s7r.reg4809 = 0x00ff & icount; + s7r.reg480A = (0xff00 & icount) >> 8; + inc = 1; d->AAddress -= count; } if (d->BAddress == 0x18 && SA1.in_char_dma && (d->ABank & 0xf0) == 0x40) @@ -114,92 +116,92 @@ void S9xDoDMA(uint8_t Channel) switch (depth) { - case 2: - for (i = 0 ; i < count ; i += inc, base += char_line_bytes, inc = char_line_bytes, char_count = num_chars) - { - uint32_t j; - uint8_t* line = base + (num_chars - char_count) * 2; - for (j = 0 ; j < char_count && p - buffer < count ; j++, line += 2) + case 2: + for (i = 0 ; i < count ; i += inc, base += char_line_bytes, inc = char_line_bytes, char_count = num_chars) { - int32_t b, l; - uint8_t* q = line; - for (l = 0; l < 8; l++, q += bytes_per_line) + uint32_t j; + uint8_t* line = base + (num_chars - char_count) * 2; + for (j = 0 ; j < char_count && p - buffer < count ; j++, line += 2) { - for (b = 0; b < 2; b++) + int32_t b, l; + uint8_t* q = line; + for (l = 0; l < 8; l++, q += bytes_per_line) { - uint8_t r = *(q + b); - *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 2) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 3) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 6) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 7) & 1); + for (b = 0; b < 2; b++) + { + uint8_t r = *(q + b); + *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 2) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 3) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 6) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 7) & 1); + } + p += 2; } - p += 2; } } - } - break; - case 4: - for (i = 0 ; i < count ; i += inc, base += char_line_bytes, inc = char_line_bytes, char_count = num_chars) - { - uint32_t j; - uint8_t* line = base + (num_chars - char_count) * 4; - for (j = 0 ; j < char_count && p - buffer < count ; j++, line += 4) + break; + case 4: + for (i = 0 ; i < count ; i += inc, base += char_line_bytes, inc = char_line_bytes, char_count = num_chars) { - uint8_t* q = line; - int32_t b, l; - for (l = 0; l < 8; l++, q += bytes_per_line) + uint32_t j; + uint8_t* line = base + (num_chars - char_count) * 4; + for (j = 0 ; j < char_count && p - buffer < count ; j++, line += 4) { - for (b = 0; b < 4; b++) + uint8_t* q = line; + int32_t b, l; + for (l = 0; l < 8; l++, q += bytes_per_line) { - uint8_t r = *(q + b); - *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); - *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); - *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); - *(p + 16) = (*(p + 16) << 1) | ((r >> 6) & 1); - *(p + 17) = (*(p + 17) << 1) | ((r >> 7) & 1); + for (b = 0; b < 4; b++) + { + uint8_t r = *(q + b); + *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); + *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); + *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); + *(p + 16) = (*(p + 16) << 1) | ((r >> 6) & 1); + *(p + 17) = (*(p + 17) << 1) | ((r >> 7) & 1); + } + p += 2; } - p += 2; + p += 32 - 16; } - p += 32 - 16; } - } - break; - case 8: - for(i = 0 ; i < count ; i += inc, base += char_line_bytes, inc = char_line_bytes, char_count = num_chars) - { - uint8_t* line = base + (num_chars - char_count) * 8; - uint32_t j; - for(j = 0 ; j < char_count && p - buffer < count ; j++, line += 8) + break; + case 8: + for(i = 0 ; i < count ; i += inc, base += char_line_bytes, inc = char_line_bytes, char_count = num_chars) { - uint8_t* q = line; - int32_t b, l; - for (l = 0; l < 8; l++, q += bytes_per_line) + uint8_t* line = base + (num_chars - char_count) * 8; + uint32_t j; + for(j = 0 ; j < char_count && p - buffer < count ; j++, line += 8) { - for (b = 0; b < 8; b++) + uint8_t* q = line; + int32_t b, l; + for (l = 0; l < 8; l++, q += bytes_per_line) { - uint8_t r = *(q + b); - *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); - *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); - *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); - *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1); - *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1); - *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1); - *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1); + for (b = 0; b < 8; b++) + { + uint8_t r = *(q + b); + *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); + *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); + *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); + *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1); + *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1); + *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1); + *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1); + } + p += 2; } - p += 2; + p += 64 - 16; } - p += 64 - 16; } - } - break; + break; } } @@ -252,80 +254,80 @@ void S9xDoDMA(uint8_t Channel) { switch (d->BAddress) { - case 0x04: - do - { - Work = *(base + p); - REGISTER_2104(Work); - p += inc; - } while (--count > 0); - break; - case 0x18: - IPPU.FirstVRAMRead = true; - if (!PPU.VMA.FullGraphicCount) - { + case 0x04: do { Work = *(base + p); - REGISTER_2118_linear(Work); + REGISTER_2104(Work); p += inc; } while (--count > 0); - } - else - { + break; + case 0x18: + IPPU.FirstVRAMRead = true; + if (!PPU.VMA.FullGraphicCount) + { + do + { + Work = *(base + p); + REGISTER_2118_linear(Work); + p += inc; + } while (--count > 0); + } + else + { + do + { + Work = *(base + p); + REGISTER_2118_tile(Work); + p += inc; + } while (--count > 0); + } + break; + case 0x19: + IPPU.FirstVRAMRead = true; + if (!PPU.VMA.FullGraphicCount) + { + do + { + Work = *(base + p); + REGISTER_2119_linear(Work); + p += inc; + } while (--count > 0); + } + else + { + do + { + Work = *(base + p); + REGISTER_2119_tile(Work); + p += inc; + } while (--count > 0); + } + break; + case 0x22: do { Work = *(base + p); - REGISTER_2118_tile(Work); + REGISTER_2122(Work); p += inc; } while (--count > 0); - } - break; - case 0x19: - IPPU.FirstVRAMRead = true; - if (!PPU.VMA.FullGraphicCount) - { + break; + case 0x80: do { Work = *(base + p); - REGISTER_2119_linear(Work); + REGISTER_2180(Work); p += inc; } while (--count > 0); - } - else - { + break; + default: do { Work = *(base + p); - REGISTER_2119_tile(Work); + S9xSetPPU(Work, 0x2100 + d->BAddress); p += inc; } while (--count > 0); - } - break; - case 0x22: - do - { - Work = *(base + p); - REGISTER_2122(Work); - p += inc; - } while (--count > 0); - break; - case 0x80: - do - { - Work = *(base + p); - REGISTER_2180(Work); - p += inc; - } while (--count > 0); - break; - default: - do - { - Work = *(base + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - p += inc; - } while (--count > 0); - break; + break; } } else if (d->TransferMode == 1 || d->TransferMode == 5) @@ -462,79 +464,79 @@ void S9xDoDMA(uint8_t Channel) { switch (d->TransferMode) { - case 0: - case 2: - case 6: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - --count; - break; - case 1: - case 5: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - if (!--count) - break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - count--; - break; - case 3: - case 7: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - if (!--count) + case 0: + case 2: + case 6: + Work = S9xGetPPU(0x2100 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + --count; break; - - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - if (!--count) + case 1: + case 5: + Work = S9xGetPPU(0x2100 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU(0x2101 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - if (!--count) + case 3: + case 7: + Work = S9xGetPPU(0x2100 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU(0x2100 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU(0x2101 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU(0x2101 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - count--; - break; - case 4: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - if (!--count) + case 4: + Work = S9xGetPPU(0x2100 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU(0x2101 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU(0x2102 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU(0x2103 + d->BAddress); + S9xSetByte(Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - if (!--count) + default: + count = 0; break; - - Work = S9xGetPPU(0x2102 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - if (!--count) - break; - - Work = S9xGetPPU(0x2103 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - d->AAddress += inc; - count--; - break; - default: - count = 0; - break; } } while (count); } @@ -681,46 +683,46 @@ uint8_t S9xDoHDMA(uint8_t byte) switch (p->TransferMode) { - case 0: - CPU.Cycles += SLOW_ONE_CYCLE; - S9xSetPPU(*HDMAMemPointers [d]++, 0x2100 + p->BAddress); - break; - case 5: - CPU.Cycles += 2 * SLOW_ONE_CYCLE; - S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2101 + p->BAddress); - HDMAMemPointers [d] += 2; - /* fall through */ - case 1: - CPU.Cycles += 2 * SLOW_ONE_CYCLE; - S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2101 + p->BAddress); - HDMAMemPointers [d] += 2; - break; - case 2: - case 6: - CPU.Cycles += 2 * SLOW_ONE_CYCLE; - S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2100 + p->BAddress); - HDMAMemPointers [d] += 2; - break; - case 3: - case 7: - CPU.Cycles += 4 * SLOW_ONE_CYCLE; - S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2100 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 2), 0x2101 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 3), 0x2101 + p->BAddress); - HDMAMemPointers [d] += 4; - break; - case 4: - CPU.Cycles += 4 * SLOW_ONE_CYCLE; - S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2101 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 2), 0x2102 + p->BAddress); - S9xSetPPU(*(HDMAMemPointers [d] + 3), 0x2103 + p->BAddress); - HDMAMemPointers [d] += 4; - break; + case 0: + CPU.Cycles += SLOW_ONE_CYCLE; + S9xSetPPU(*HDMAMemPointers [d]++, 0x2100 + p->BAddress); + break; + case 5: + CPU.Cycles += 2 * SLOW_ONE_CYCLE; + S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2101 + p->BAddress); + HDMAMemPointers [d] += 2; + /* fall through */ + case 1: + CPU.Cycles += 2 * SLOW_ONE_CYCLE; + S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2101 + p->BAddress); + HDMAMemPointers [d] += 2; + break; + case 2: + case 6: + CPU.Cycles += 2 * SLOW_ONE_CYCLE; + S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2100 + p->BAddress); + HDMAMemPointers [d] += 2; + break; + case 3: + case 7: + CPU.Cycles += 4 * SLOW_ONE_CYCLE; + S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2100 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 2), 0x2101 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 3), 0x2101 + p->BAddress); + HDMAMemPointers [d] += 4; + break; + case 4: + CPU.Cycles += 4 * SLOW_ONE_CYCLE; + S9xSetPPU(*(HDMAMemPointers [d] + 0), 0x2100 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 1), 0x2101 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 2), 0x2102 + p->BAddress); + S9xSetPPU(*(HDMAMemPointers [d] + 3), 0x2103 + p->BAddress); + HDMAMemPointers [d] += 4; + break; } if (!p->HDMAIndirectAddressing) p->Address += HDMA_ModeByteCounts [p->TransferMode]; diff --git a/source/gfx.c b/source/gfx.c index 9d077ac..c47661a 100644 --- a/source/gfx.c +++ b/source/gfx.c @@ -59,6 +59,7 @@ extern uint8_t Mode7Depths [2]; (GFX.r2131 & 0x3f) #define FIX_INTERLACE(SCREEN, DO_DEPTH, DEPTH) \ + { \ uint32_t y; \ if (IPPU.DoubleHeightPixels && ((PPU.BGMode != 5 && PPU.BGMode != 6) || !IPPU.Interlace)) \ { \ @@ -75,6 +76,7 @@ extern uint8_t Mode7Depths [2]; GFX.PPLx2>>1); \ } \ } \ + } \ } #define BLACK BUILD_PIXEL(0,0,0) @@ -506,44 +508,44 @@ static INLINE void SelectTileRenderer(bool normal) { switch (GFX.r2131 & 0xC0) { - case 0x00: - DrawTilePtr = DrawTile16Add; - DrawClippedTilePtr = DrawClippedTile16Add; - DrawLargePixelPtr = DrawLargePixel16Add; - break; - case 0x40: - if (GFX.r2130 & 2) - { - DrawTilePtr = DrawTile16Add1_2; - DrawClippedTilePtr = DrawClippedTile16Add1_2; - } - else - { - /* Fixed colour addition */ - DrawTilePtr = DrawTile16FixedAdd1_2; - DrawClippedTilePtr = DrawClippedTile16FixedAdd1_2; - } - DrawLargePixelPtr = DrawLargePixel16Add1_2; - break; - case 0x80: - DrawTilePtr = DrawTile16Sub; - DrawClippedTilePtr = DrawClippedTile16Sub; - DrawLargePixelPtr = DrawLargePixel16Sub; - break; - case 0xC0: - if (GFX.r2130 & 2) - { - DrawTilePtr = DrawTile16Sub1_2; - DrawClippedTilePtr = DrawClippedTile16Sub1_2; - } - else - { - /* Fixed colour substraction */ - DrawTilePtr = DrawTile16FixedSub1_2; - DrawClippedTilePtr = DrawClippedTile16FixedSub1_2; - } - DrawLargePixelPtr = DrawLargePixel16Sub1_2; - break; + case 0x00: + DrawTilePtr = DrawTile16Add; + DrawClippedTilePtr = DrawClippedTile16Add; + DrawLargePixelPtr = DrawLargePixel16Add; + break; + case 0x40: + if (GFX.r2130 & 2) + { + DrawTilePtr = DrawTile16Add1_2; + DrawClippedTilePtr = DrawClippedTile16Add1_2; + } + else + { + /* Fixed colour addition */ + DrawTilePtr = DrawTile16FixedAdd1_2; + DrawClippedTilePtr = DrawClippedTile16FixedAdd1_2; + } + DrawLargePixelPtr = DrawLargePixel16Add1_2; + break; + case 0x80: + DrawTilePtr = DrawTile16Sub; + DrawClippedTilePtr = DrawClippedTile16Sub; + DrawLargePixelPtr = DrawLargePixel16Sub; + break; + case 0xC0: + if (GFX.r2130 & 2) + { + DrawTilePtr = DrawTile16Sub1_2; + DrawClippedTilePtr = DrawClippedTile16Sub1_2; + } + else + { + /* Fixed colour substraction */ + DrawTilePtr = DrawTile16FixedSub1_2; + DrawClippedTilePtr = DrawClippedTile16FixedSub1_2; + } + DrawLargePixelPtr = DrawLargePixel16Sub1_2; + break; } } } @@ -557,42 +559,42 @@ void S9xSetupOBJ(void) switch (PPU.OBJSizeSelect) { - case 0: - SmallWidth = SmallHeight = 8; - LargeWidth = LargeHeight = 16; - break; - case 1: - SmallWidth = SmallHeight = 8; - LargeWidth = LargeHeight = 32; - break; - case 2: - SmallWidth = SmallHeight = 8; - LargeWidth = LargeHeight = 64; - break; - case 3: - SmallWidth = SmallHeight = 16; - LargeWidth = LargeHeight = 32; - break; - case 4: - SmallWidth = SmallHeight = 16; - LargeWidth = LargeHeight = 64; - break; - default: - case 5: - SmallWidth = SmallHeight = 32; - LargeWidth = LargeHeight = 64; - break; - case 6: - SmallWidth = 16; - SmallHeight = 32; - LargeWidth = 32; - LargeHeight = 64; - break; - case 7: - SmallWidth = 16; - SmallHeight = 32; - LargeWidth = LargeHeight = 32; - break; + case 0: + SmallWidth = SmallHeight = 8; + LargeWidth = LargeHeight = 16; + break; + case 1: + SmallWidth = SmallHeight = 8; + LargeWidth = LargeHeight = 32; + break; + case 2: + SmallWidth = SmallHeight = 8; + LargeWidth = LargeHeight = 64; + break; + case 3: + SmallWidth = SmallHeight = 16; + LargeWidth = LargeHeight = 32; + break; + case 4: + SmallWidth = SmallHeight = 16; + LargeWidth = LargeHeight = 64; + break; + default: + case 5: + SmallWidth = SmallHeight = 32; + LargeWidth = LargeHeight = 64; + break; + case 6: + SmallWidth = 16; + SmallHeight = 32; + LargeWidth = 32; + LargeHeight = 64; + break; + case 7: + SmallWidth = 16; + SmallHeight = 32; + LargeWidth = LargeHeight = 32; + break; } /* OK, we have three cases here. Either there's no priority, priority is * normal FirstSprite, or priority is FirstSprite+Y. The first two are @@ -1718,15 +1720,15 @@ static void DrawBackground(uint32_t BGMode, uint32_t bg, uint8_t Z1, uint8_t Z2) } switch (BGMode) { - case 2: - case 4: /* Used by Puzzle Bobble */ - DrawBackgroundOffset(BGMode, bg, Z1, Z2); - return; - - case 5: - case 6: /* XXX: is also offset per tile. */ - DrawBackgroundMode5(bg, Z1, Z2); - return; + case 2: + case 4: /* Used by Puzzle Bobble */ + DrawBackgroundOffset(BGMode, bg, Z1, Z2); + return; + + case 5: + case 6: /* XXX: is also offset per tile. */ + DrawBackgroundMode5(bg, Z1, Z2); + return; } depths [0] = Z1; @@ -2360,6 +2362,7 @@ static void DrawBGMode7Background16Sub1_2(uint8_t * Screen, int32_t bg) GFX.Z1 = Mode7Depths [(b & GFX.Mode7PriorityMask) >> 7]; \ if (GFX.Z1 > *d && (b & GFX.Mode7Mask) ) \ { \ + TYPE theColor; \ uint32_t p1, p2, p3, p4; \ uint32_t Xdel, Ydel, XY, area1, area2, area3, area4, tempColor; \ /* X10 and Y01 are the X and Y coordinates of the next source point over. */ \ @@ -2399,8 +2402,8 @@ static void DrawBGMode7Background16Sub1_2(uint8_t * Screen, int32_t bg) (area2 * p2) + \ (area3 * p3) + \ (area4 * p4)) >> 5; \ - TYPE theColor = (tempColor & FIRST_THIRD_COLOR_MASK) | ((tempColor >> 16) & SECOND_COLOR_MASK); \ - *p = (FUNC) | ALPHA_BITS_MASK; \ + theColor = (tempColor & FIRST_THIRD_COLOR_MASK) | ((tempColor >> 16) & SECOND_COLOR_MASK); \ + *p = (FUNC) | ALPHA_BITS_MASK; \ *d = GFX.Z1; \ } \ } \ @@ -2609,98 +2612,98 @@ static void RenderScreen(uint8_t* Screen, bool sub, bool force_no_add, uint8_t D switch (PPU.BGMode) { - case 0: - case 1: - if (OB) - { - SelectTileRenderer(sub || !SUB_OR_ADD(4)); - DrawOBJS(!sub, D); - } - if (BG0) - { - SelectTileRenderer(sub || !SUB_OR_ADD(0)); - DrawBackground(PPU.BGMode, 0, D + 10, D + 14); - } - if (BG1) - { - SelectTileRenderer(sub || !SUB_OR_ADD(1)); - DrawBackground(PPU.BGMode, 1, D + 9, D + 13); - } - if (BG2) - { - SelectTileRenderer(sub || !SUB_OR_ADD(2)); - DrawBackground(PPU.BGMode, 2, D + 3, PPU.BG3Priority ? D + 17 : D + 6); - } - if (BG3 && PPU.BGMode == 0) - { - SelectTileRenderer(sub || !SUB_OR_ADD(3)); - DrawBackground(PPU.BGMode, 3, D + 2, D + 5); - } - break; - case 2: - case 3: - case 4: - case 5: - case 6: - if (OB) - { - SelectTileRenderer(sub || !SUB_OR_ADD(4)); - DrawOBJS(!sub, D); - } - if (BG0) - { - SelectTileRenderer(sub || !SUB_OR_ADD(0)); - DrawBackground(PPU.BGMode, 0, D + 5, D + 13); - } - if (BG1 && PPU.BGMode != 6) - { - SelectTileRenderer(sub || !SUB_OR_ADD(1)); - DrawBackground(PPU.BGMode, 1, D + 2, D + 9); - } - break; - case 7: - if (OB) - { - SelectTileRenderer(sub || !SUB_OR_ADD(4)); - DrawOBJS(!sub, D); - } - if (BG0 || ((Memory.FillRAM [0x2133] & 0x40) && BG1)) - { - int32_t bg; - - if ((Memory.FillRAM [0x2133] & 0x40) && BG1) + case 0: + case 1: + if (OB) { - GFX.Mode7Mask = 0x7f; - GFX.Mode7PriorityMask = 0x80; - Mode7Depths [0] = (BG0 ? 5 : 1) + D; - Mode7Depths [1] = 9 + D; - bg = 1; + SelectTileRenderer(sub || !SUB_OR_ADD(4)); + DrawOBJS(!sub, D); } - else + if (BG0) { - GFX.Mode7Mask = 0xff; - GFX.Mode7PriorityMask = 0; - Mode7Depths [0] = 5 + D; - Mode7Depths [1] = 5 + D; - bg = 0; + SelectTileRenderer(sub || !SUB_OR_ADD(0)); + DrawBackground(PPU.BGMode, 0, D + 10, D + 14); } - if (sub || !SUB_OR_ADD(0)) - DrawBGMode7Background16(Screen, bg); - else + if (BG1) + { + SelectTileRenderer(sub || !SUB_OR_ADD(1)); + DrawBackground(PPU.BGMode, 1, D + 9, D + 13); + } + if (BG2) + { + SelectTileRenderer(sub || !SUB_OR_ADD(2)); + DrawBackground(PPU.BGMode, 2, D + 3, PPU.BG3Priority ? D + 17 : D + 6); + } + if (BG3 && PPU.BGMode == 0) { - if (GFX.r2131 & 0x80) + SelectTileRenderer(sub || !SUB_OR_ADD(3)); + DrawBackground(PPU.BGMode, 3, D + 2, D + 5); + } + break; + case 2: + case 3: + case 4: + case 5: + case 6: + if (OB) + { + SelectTileRenderer(sub || !SUB_OR_ADD(4)); + DrawOBJS(!sub, D); + } + if (BG0) + { + SelectTileRenderer(sub || !SUB_OR_ADD(0)); + DrawBackground(PPU.BGMode, 0, D + 5, D + 13); + } + if (BG1 && PPU.BGMode != 6) + { + SelectTileRenderer(sub || !SUB_OR_ADD(1)); + DrawBackground(PPU.BGMode, 1, D + 2, D + 9); + } + break; + case 7: + if (OB) + { + SelectTileRenderer(sub || !SUB_OR_ADD(4)); + DrawOBJS(!sub, D); + } + if (BG0 || ((Memory.FillRAM [0x2133] & 0x40) && BG1)) + { + int32_t bg; + + if ((Memory.FillRAM [0x2133] & 0x40) && BG1) { - if (GFX.r2131 & 0x40) - DrawBGMode7Background16Sub1_2(Screen, bg); - else - DrawBGMode7Background16Sub(Screen, bg); + GFX.Mode7Mask = 0x7f; + GFX.Mode7PriorityMask = 0x80; + Mode7Depths [0] = (BG0 ? 5 : 1) + D; + Mode7Depths [1] = 9 + D; + bg = 1; } else { - if (GFX.r2131 & 0x40) - DrawBGMode7Background16Add1_2(Screen, bg); + GFX.Mode7Mask = 0xff; + GFX.Mode7PriorityMask = 0; + Mode7Depths [0] = 5 + D; + Mode7Depths [1] = 5 + D; + bg = 0; + } + if (sub || !SUB_OR_ADD(0)) + DrawBGMode7Background16(Screen, bg); + else + { + if (GFX.r2131 & 0x80) + { + if (GFX.r2131 & 0x40) + DrawBGMode7Background16Sub1_2(Screen, bg); + else + DrawBGMode7Background16Sub(Screen, bg); + } else - DrawBGMode7Background16Add(Screen, bg); + { + if (GFX.r2131 & 0x40) + DrawBGMode7Background16Add1_2(Screen, bg); + else + DrawBGMode7Background16Add(Screen, bg); } } } @@ -2713,6 +2716,8 @@ static void RenderScreen(uint8_t* Screen, bool sub, bool force_no_add, uint8_t D void S9xUpdateScreen(void) { int32_t x2 = 1; + uint32_t starty, endy, black; + GFX.S = GFX.Screen; GFX.r2131 = Memory.FillRAM [0x2131]; GFX.r212c = Memory.FillRAM [0x212c]; @@ -2736,8 +2741,8 @@ void S9xUpdateScreen(void) /* XXX: Check ForceBlank? Or anything else? */ PPU.RangeTimeOver |= GFX.OBJLines[GFX.EndY].RTOFlags; - uint32_t starty = GFX.StartY; - uint32_t endy = GFX.EndY; + starty = GFX.StartY; + endy = GFX.EndY; if (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.Interlace || IPPU.DoubleHeightPixels) { @@ -2773,18 +2778,19 @@ void S9xUpdateScreen(void) * too. */ if (IPPU.Interlace && !IPPU.DoubleHeightPixels) { - starty = GFX.StartY * 2; - endy = GFX.EndY * 2 + 1; - IPPU.RenderedScreenHeight = PPU.ScreenHeight << 1; - IPPU.DoubleHeightPixels = true; - GFX.Pitch2 = GFX.RealPitch; - GFX.Pitch = GFX.RealPitch * 2; - GFX.PPL = GFX.PPLx2 = GFX.RealPitch; + int32_t y; + starty = GFX.StartY * 2; + endy = GFX.EndY * 2 + 1; + IPPU.RenderedScreenHeight = PPU.ScreenHeight << 1; + IPPU.DoubleHeightPixels = true; + GFX.Pitch2 = GFX.RealPitch; + GFX.Pitch = GFX.RealPitch * 2; + GFX.PPL = GFX.RealPitch; + GFX.PPLx2 = GFX.RealPitch; /* The game has switched from non-interlaced to interlaced mode * part way down the screen. Scale everything. */ - int32_t y; for (y = (int32_t) GFX.StartY - 1; y >= 0; y--) { /* memmove converted: Same malloc, different addresses, and identical addresses at line 0 [Neb] @@ -2796,7 +2802,7 @@ void S9xUpdateScreen(void) } } - uint32_t black = BLACK | (BLACK << 16); + black = BLACK | (BLACK << 16); if (GFX.Pseudo) { @@ -2823,6 +2829,8 @@ void S9xUpdateScreen(void) uint32_t y; for (y = starty; y <= endy; y++) { + uint32_t c; + memset(GFX.SubZBuffer + y * GFX.ZPitch, 0, IPPU.RenderedScreenWidth); memset(GFX.ZBuffer + y * GFX.ZPitch, 0, IPPU.RenderedScreenWidth); @@ -2834,7 +2842,6 @@ void S9xUpdateScreen(void) *p++ = black; } - uint32_t c; for (c = 0; c < pClip->Count [5]; c++) { if (pClip->Right [c][5] > pClip->Left [c][5]) @@ -2915,15 +2922,16 @@ void S9xUpdateScreen(void) if (SUB_OR_ADD(5)) { + uint32_t y; uint32_t back = IPPU.ScreenColors [0]; uint32_t Left = 0; uint32_t Right = 256; uint32_t Count; pClip = &IPPU.Clip [0]; - uint32_t y; for (y = starty; y <= endy; y++) { + uint32_t b; if (!(Count = pClip->Count [5])) { Left = 0; @@ -2931,7 +2939,6 @@ void S9xUpdateScreen(void) Count = 1; } - uint32_t b; for (b = 0; b < Count; b++) { if (pClip->Count [5]) @@ -3158,13 +3165,13 @@ void S9xUpdateScreen(void) uint32_t y; for (y = starty; y <= endy; y++) { + uint32_t c; uint32_t* p = (uint32_t*)(GFX.Screen + y * GFX.Pitch2); uint32_t* q = (uint32_t*)((uint16_t*) p + IPPU.RenderedScreenWidth); while (p < q) *p++ = black; - uint32_t c; for (c = 0; c < IPPU.Clip [0].Count [5]; c++) { if (IPPU.Clip [0].Right [c][5] > IPPU.Clip [0].Left [c][5]) diff --git a/source/memmap.c b/source/memmap.c index 6f5b726..cfdc997 100644 --- a/source/memmap.c +++ b/source/memmap.c @@ -43,15 +43,19 @@ extern char* rom_filename; void S9xDeinterleaveType1(int32_t TotalFileSize, uint8_t* base) { int32_t i; - int32_t nblocks = TotalFileSize >> 16; uint8_t blocks [256]; + uint8_t *tmp = NULL; + int32_t nblocks = TotalFileSize >> 16; + for (i = 0; i < nblocks; i++) { blocks [i * 2] = i + nblocks; blocks [i * 2 + 1] = i; } + /* DS2 DMA notes: base may or may not be 32-byte aligned */ - uint8_t* tmp = (uint8_t*) malloc(0x8000); + tmp = (uint8_t*) malloc(0x8000); + if (tmp) { for (i = 0; i < nblocks * 2; i++) @@ -61,6 +65,8 @@ void S9xDeinterleaveType1(int32_t TotalFileSize, uint8_t* base) { if (blocks [j] == i) { + uint8_t b; + /* memmove converted: Different mallocs [Neb] */ memcpy(tmp, &base [blocks [j] * 0x8000], 0x8000); /* memmove converted: Different addresses, or identical for blocks[i] == blocks[j] [Neb] */ @@ -69,7 +75,7 @@ void S9xDeinterleaveType1(int32_t TotalFileSize, uint8_t* base) &base [blocks [i] * 0x8000], 0x8000); /* memmove converted: Different mallocs [Neb] */ memcpy(&base [blocks [i] * 0x8000], tmp, 0x8000); - uint8_t b = blocks [j]; + b = blocks [j]; blocks [j] = blocks [i]; blocks [i] = b; break; @@ -82,11 +88,13 @@ void S9xDeinterleaveType1(int32_t TotalFileSize, uint8_t* base) void S9xDeinterleaveGD24(int32_t TotalFileSize, uint8_t* base) { + uint8_t *tmp = NULL; if (TotalFileSize != 0x300000) return; /* DS2 DMA notes: base may or may not be 32-byte aligned */ - uint8_t* tmp = (uint8_t*) malloc(0x80000); + tmp = (uint8_t*) malloc(0x80000); + if (tmp) { /* memmove converted: Different mallocs [Neb] */ @@ -201,6 +209,8 @@ static char* Safe(const char* s) { static char* safe; static int32_t safe_len = 0; + int32_t i; + int32_t len; if (s == NULL) { @@ -211,7 +221,9 @@ static char* Safe(const char* s) } return NULL; } - int32_t len = strlen(s); + + len = strlen(s); + if (!safe || len + 1 > safe_len) { if (safe) @@ -219,7 +231,6 @@ static char* Safe(const char* s) safe = (char*) malloc(safe_len = len + 1); } - int32_t i; for (i = 0; i < len; i++) { if (s [i] >= 32 && s [i] < 127) @@ -284,6 +295,7 @@ bool S9xInitMemory(void) void S9xDeinitMemory(void) { + int t; if (Memory.RAM) { free(Memory.RAM); @@ -316,7 +328,6 @@ void S9xDeinitMemory(void) Memory.BSRAM = NULL; } - int t; for (t = 0; t < 2; t++) { if (IPPU.TileCache[t]) @@ -999,6 +1010,10 @@ void S9xDeinterleaveType2(bool reset) void InitROM(bool Interleaved) { + uint8_t* RomHeader; + uint32_t sum1 = 0; + uint32_t sum2 = 0; + SuperFX.nRomBanks = Memory.CalculatedSize >> 15; Settings.MultiPlayer5Master = Settings.MultiPlayer5; Settings.MouseMaster = Settings.Mouse; @@ -1017,7 +1032,6 @@ void InitROM(bool Interleaved) Settings.SETA = false; s7r.DataRomSize = 0; Memory.CalculatedChecksum = 0; - uint8_t* RomHeader; RomHeader = Memory.ROM + 0x7FB0; @@ -1236,20 +1250,19 @@ void InitROM(bool Interleaved) if (Settings.BS) Memory.ROMRegion = 0; - uint32_t sum1 = 0; - uint32_t sum2 = 0; if (!Memory.CalculatedChecksum) { + int32_t i; + uint32_t remainder; int32_t power2 = 0; + int32_t sub = 0; int32_t size = Memory.CalculatedSize; while (size >>= 1) power2++; - size = 1 << power2; - uint32_t remainder = Memory.CalculatedSize - size; - - int32_t i; + size = 1 << power2; + remainder = Memory.CalculatedSize - size; for (i = 0; i < size; i++) sum1 += Memory.ROM [i]; @@ -1257,7 +1270,6 @@ void InitROM(bool Interleaved) for (i = 0; i < (int32_t) remainder; i++) sum2 += Memory.ROM [size + i]; - int32_t sub = 0; if (Settings.BS && Memory.ROMType != 0xE5) { if (Memory.HiROM) @@ -1399,9 +1411,10 @@ void map_index(uint32_t bank_s, uint32_t bank_e, uint32_t addr_s, uint32_t addr_ void WriteProtectROM(void) { + int32_t c; + /* memmove converted: Different mallocs [Neb] */ memcpy(Memory.WriteMap, Memory.Map, sizeof(Memory.Map)); - int32_t c; for (c = 0; c < 0x1000; c++) if (Memory.BlockIsROM [c]) Memory.WriteMap [c] = (uint8_t*) MAP_NONE; @@ -1722,6 +1735,7 @@ void TalesROMMap(bool Interleaved) { int32_t c; int32_t i; + int32_t sum = 0; uint32_t OFFSET0 = 0x400000; uint32_t OFFSET1 = 0x400000; @@ -1788,7 +1802,6 @@ void TalesROMMap(bool Interleaved) Memory.ROMChecksum = *(Memory.Map[8] + 0xFFDE) + (*(Memory.Map[8] + 0xFFDF) << 8); Memory.ROMComplementChecksum = *(Memory.Map[8] + 0xFFDC) + (*(Memory.Map[8] + 0xFFDD) << 8); - int32_t sum = 0; for (i = 0x40; i < 0x80; i++) { uint8_t* bank_low = (uint8_t*)Memory.Map[i << 4]; @@ -2264,6 +2277,7 @@ void JumboLoROMMap(bool Interleaved) { int32_t c; int32_t i; + int32_t sum = 0, k, l; uint32_t OFFSET0 = 0x400000; uint32_t OFFSET2 = 0x000000; @@ -2343,7 +2357,6 @@ void JumboLoROMMap(bool Interleaved) } /* ROM type has to be 64 Mbit header! */ - int32_t sum = 0, k, l; for (k = 0; k < 256; k++) { uint8_t* bank = 0x8000 + Memory.Map[8 + (k << 4)]; /* use upper half of the banks, and adjust for LoROM. */ @@ -2359,6 +2372,7 @@ void SPC7110HiROMMap(void) { int32_t c; int32_t i; + int32_t sum = 0; /* Banks 00->3f and 80->bf */ for (c = 0; c < 0x400; c += 16) @@ -2421,7 +2435,6 @@ void SPC7110HiROMMap(void) } S9xSpc7110Init(); - int32_t sum = 0; for (i = 0; i < (int32_t)Memory.CalculatedSize; i++) sum += Memory.ROM[i]; @@ -3000,6 +3013,8 @@ void ParseSNESHeader(uint8_t* RomHeader) { if(Settings.BS) { + uint32_t size_count; + Memory.SRAMSize = 0x05; strncpy(Memory.ROMName, (char *) &RomHeader[0x10], 17); memset(&Memory.ROMName[0x11], 0, ROM_NAME_LEN - 1 - 17); @@ -3007,7 +3022,6 @@ void ParseSNESHeader(uint8_t* RomHeader) Memory.ROMType = 0xe5; Memory.ROMSize = 1; - uint32_t size_count; for(size_count = 0x800; size_count < Memory.CalculatedSize; size_count <<= 1, ++Memory.ROMSize); } else |