From 9ec142daa892182a0e29fb15f050a8d729ae926c Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-UVBJEGH\\Cloud" Date: Fri, 8 Jun 2018 17:45:10 +0800 Subject: [PATCH 1/5] Add header guard --- src/common/cstdint.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/cstdint.h b/src/common/cstdint.h index 7fecbbaf..bb2e0ce0 100644 --- a/src/common/cstdint.h +++ b/src/common/cstdint.h @@ -1,3 +1,6 @@ +#ifndef CSTDINT_H +#define CSTDINT_H + #if defined(__has_include) # if __has_include() # include @@ -11,3 +14,5 @@ #else # include #endif + +#endif // CSTDINT_H From 27aeb6dc672a6857ea431446d10b5e5598d8873e Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Fri, 8 Jun 2018 20:14:45 +0800 Subject: [PATCH 2/5] Re-add Types.h, remove some more #ifdef --- src/System.h | 7 +------ src/common/Patch.h | 6 +----- src/common/Port.h | 6 +----- src/gb/gbGlobals.cpp | 2 +- src/gb/gbGlobals.h | 2 +- src/gb/gbMemory.h | 2 +- src/gba/BreakpointStructures.h | 6 +----- src/gba/EEprom.h | 8 +------- src/gba/Flash.h | 7 +------ src/gba/GBA.h | 7 +------ src/gba/GBASockClient.h | 6 +----- src/gba/Sram.h | 6 +----- src/sdl/filters.h | 3 +-- 13 files changed, 13 insertions(+), 55 deletions(-) diff --git a/src/System.h b/src/System.h index 27b9409c..37f76053 100644 --- a/src/System.h +++ b/src/System.h @@ -1,12 +1,7 @@ #ifndef SYSTEM_H #define SYSTEM_H -#ifndef __LIBRETRO__ -#include -#include "common/cstdint.h" -#else -#include -#endif +#include "common/Types.h" #define winlog log diff --git a/src/common/Patch.h b/src/common/Patch.h index a8b496d9..1e69eb4f 100644 --- a/src/common/Patch.h +++ b/src/common/Patch.h @@ -1,11 +1,7 @@ #ifndef PATCH_H #define PATCH_H -#ifndef __LIBRETRO__ -#include "cstdint.h" -#else -#include -#endif +#include "Types.h" bool applyPatch(const char *patchname, uint8_t **rom, int *size); diff --git a/src/common/Port.h b/src/common/Port.h index baef9003..6e84f1ef 100644 --- a/src/common/Port.h +++ b/src/common/Port.h @@ -1,11 +1,7 @@ #ifndef PORT_H #define PORT_H -#ifndef __LIBRETRO__ -#include "cstdint.h" -#else -#include -#endif +#include "Types.h" #ifdef __CELLOS_LV2__ /* PlayStation3 */ diff --git a/src/gb/gbGlobals.cpp b/src/gb/gbGlobals.cpp index 5610cb80..bf057679 100644 --- a/src/gb/gbGlobals.cpp +++ b/src/gb/gbGlobals.cpp @@ -1,5 +1,5 @@ #include -#include "../common/cstdint.h" +#include "../common/Types.h" uint8_t* gbMemoryMap[16]; diff --git a/src/gb/gbGlobals.h b/src/gb/gbGlobals.h index c4ecff19..9867b99b 100644 --- a/src/gb/gbGlobals.h +++ b/src/gb/gbGlobals.h @@ -1,7 +1,7 @@ #ifndef GBGLOBALS_H #define GBGLOBALS_H -#include "../common/cstdint.h" +#include "../common/Types.h" extern int gbRomSizeMask; extern int gbRomSize; diff --git a/src/gb/gbMemory.h b/src/gb/gbMemory.h index 235ee2ae..e6d4a559 100644 --- a/src/gb/gbMemory.h +++ b/src/gb/gbMemory.h @@ -1,7 +1,7 @@ #ifndef GBMEMORY_H #define GBMEMORY_H -#include "../common/cstdint.h" +#include "../common/Types.h" #include struct mapperMBC1 { diff --git a/src/gba/BreakpointStructures.h b/src/gba/BreakpointStructures.h index 1e857097..3222f65e 100644 --- a/src/gba/BreakpointStructures.h +++ b/src/gba/BreakpointStructures.h @@ -1,11 +1,7 @@ #ifndef VBA_BKS_H #define VBA_BKS_H -#ifndef __LIBRETRO__ -#include "../common/cstdint.h" -#else -#include -#endif +#include "../common/Types.h" #define readWord(addr) \ ((map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]) + ((map[(addr + 1) >> 24].address[(addr + 1) & map[(addr + 1) >> 24].mask]) << 8) + ((map[(addr + 2) >> 24].address[(addr + 2) & map[(addr + 2) >> 24].mask]) << 16) + ((map[(addr + 3) >> 24].address[(addr + 3) & map[(addr + 3) >> 24].mask]) << 24)) diff --git a/src/gba/EEprom.h b/src/gba/EEprom.h index 2bd24226..54abeb2c 100644 --- a/src/gba/EEprom.h +++ b/src/gba/EEprom.h @@ -1,13 +1,7 @@ #ifndef EEPROM_H #define EEPROM_H -#ifndef __LIBRETRO__ -#include "../common/cstdint.h" -#else -#include -#endif - -#include +#include "../common/Types.h" #ifdef __LIBRETRO__ extern void eepromSaveGame(uint8_t*& data); diff --git a/src/gba/Flash.h b/src/gba/Flash.h index 362f8775..f17a827d 100644 --- a/src/gba/Flash.h +++ b/src/gba/Flash.h @@ -1,12 +1,7 @@ #ifndef FLASH_H #define FLASH_H -#ifndef __LIBRETRO__ -#include "../common/cstdint.h" -#include -#else -#include -#endif +#include "../common/Types.h" #define FLASH_128K_SZ 0x20000 diff --git a/src/gba/GBA.h b/src/gba/GBA.h index b4a8348e..61adcdc1 100644 --- a/src/gba/GBA.h +++ b/src/gba/GBA.h @@ -1,12 +1,7 @@ #ifndef GBA_H #define GBA_H -#ifndef __LIBRETRO__ -#include "../common/cstdint.h" -#else -#include -#endif - +#include "../common/Types.h" #include "../System.h" const uint64_t TICKS_PER_SECOND = 16777216; diff --git a/src/gba/GBASockClient.h b/src/gba/GBASockClient.h index c6c3713e..1c6c769d 100644 --- a/src/gba/GBASockClient.h +++ b/src/gba/GBASockClient.h @@ -1,10 +1,6 @@ #pragma once -#ifndef __LIBRETRO__ -#include "../common/cstdint.h" -#else -#include -#endif +#include "../common/Types.h" #include diff --git a/src/gba/Sram.h b/src/gba/Sram.h index 2f549480..50754da5 100644 --- a/src/gba/Sram.h +++ b/src/gba/Sram.h @@ -1,11 +1,7 @@ #ifndef SRAM_H #define SRAM_H -#ifndef __LIBRETRO__ -#include "../common/cstdint.h" -#else -#include -#endif +#include "../common/Types.h" uint8_t sramRead(uint32_t address); void sramWrite(uint32_t address, uint8_t byte); diff --git a/src/sdl/filters.h b/src/sdl/filters.h index 04aed5f2..1b29ca73 100644 --- a/src/sdl/filters.h +++ b/src/sdl/filters.h @@ -19,8 +19,7 @@ #ifndef VBA_SDL_FILTERS_H #define VBA_SDL_FILTERS_H -#include "../common/cstdint.h" - +#include "../common/Types.h" #include "../System.h" // From 57dc0c25ff483e599a4733796457fe2aa236b67b Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Fri, 8 Jun 2018 20:56:39 +0800 Subject: [PATCH 3/5] Move gfxDrawTextScreen() into GBAGfx.cpp --- src/gba/GBA.cpp | 227 -------------------------------------------- src/gba/GBAGfx.cpp | 229 +++++++++++++++++++++++++++++++++++++++++++++ src/gba/GBAGfx.h | 2 +- 3 files changed, 230 insertions(+), 228 deletions(-) diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index 588b957e..25a376f8 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -4190,233 +4190,6 @@ void CPULoop(int ticks) #endif } -#ifdef TILED_RENDERING -union uint8_th { - struct - { - /* 0*/ unsigned lo : 4; - /* 4*/ unsigned hi : 4; - } __attribute__((packed)); - uint8_t val; -}; - -union TileEntry { - struct - { - /* 0*/ unsigned tileNum : 10; - /*12*/ unsigned hFlip : 1; - /*13*/ unsigned vFlip : 1; - /*14*/ unsigned palette : 4; - }; - uint16_t val; -}; - -struct TileLine { - uint32_t pixels[8]; -}; - -typedef const TileLine (*TileReader)(const uint16_t*, const int, const uint8_t*, uint16_t*, const uint32_t); - -static inline void gfxDrawPixel(uint32_t* dest, const uint8_t color, const uint16_t* palette, const uint32_t prio) -{ - *dest = color ? (READ16LE(&palette[color]) | prio) : 0x80000000; -} - -inline const TileLine gfxReadTile(const uint16_t* screenSource, const int yyy, const uint8_t* charBase, uint16_t* palette, const uint32_t prio) -{ - TileEntry tile; - tile.val = READ16LE(screenSource); - - int tileY = yyy & 7; - if (tile.vFlip) - tileY = 7 - tileY; - TileLine tileLine; - - const uint8_t* tileBase = &charBase[tile.tileNum * 64 + tileY * 8]; - - if (!tile.hFlip) { - gfxDrawPixel(&tileLine.pixels[0], tileBase[0], palette, prio); - gfxDrawPixel(&tileLine.pixels[1], tileBase[1], palette, prio); - gfxDrawPixel(&tileLine.pixels[2], tileBase[2], palette, prio); - gfxDrawPixel(&tileLine.pixels[3], tileBase[3], palette, prio); - gfxDrawPixel(&tileLine.pixels[4], tileBase[4], palette, prio); - gfxDrawPixel(&tileLine.pixels[5], tileBase[5], palette, prio); - gfxDrawPixel(&tileLine.pixels[6], tileBase[6], palette, prio); - gfxDrawPixel(&tileLine.pixels[7], tileBase[7], palette, prio); - } else { - gfxDrawPixel(&tileLine.pixels[0], tileBase[7], palette, prio); - gfxDrawPixel(&tileLine.pixels[1], tileBase[6], palette, prio); - gfxDrawPixel(&tileLine.pixels[2], tileBase[5], palette, prio); - gfxDrawPixel(&tileLine.pixels[3], tileBase[4], palette, prio); - gfxDrawPixel(&tileLine.pixels[4], tileBase[3], palette, prio); - gfxDrawPixel(&tileLine.pixels[5], tileBase[2], palette, prio); - gfxDrawPixel(&tileLine.pixels[6], tileBase[1], palette, prio); - gfxDrawPixel(&tileLine.pixels[7], tileBase[0], palette, prio); - } - - return tileLine; -} - -inline const TileLine gfxReadTilePal(const uint16_t* screenSource, const int yyy, const uint8_t* charBase, uint16_t* palette, const uint32_t prio) -{ - TileEntry tile; - tile.val = READ16LE(screenSource); - - int tileY = yyy & 7; - if (tile.vFlip) - tileY = 7 - tileY; - palette += tile.palette * 16; - TileLine tileLine; - - const uint8_th* tileBase = (uint8_th*)&charBase[tile.tileNum * 32 + tileY * 4]; - - if (!tile.hFlip) { - gfxDrawPixel(&tileLine.pixels[0], tileBase[0].lo, palette, prio); - gfxDrawPixel(&tileLine.pixels[1], tileBase[0].hi, palette, prio); - gfxDrawPixel(&tileLine.pixels[2], tileBase[1].lo, palette, prio); - gfxDrawPixel(&tileLine.pixels[3], tileBase[1].hi, palette, prio); - gfxDrawPixel(&tileLine.pixels[4], tileBase[2].lo, palette, prio); - gfxDrawPixel(&tileLine.pixels[5], tileBase[2].hi, palette, prio); - gfxDrawPixel(&tileLine.pixels[6], tileBase[3].lo, palette, prio); - gfxDrawPixel(&tileLine.pixels[7], tileBase[3].hi, palette, prio); - } else { - gfxDrawPixel(&tileLine.pixels[0], tileBase[3].hi, palette, prio); - gfxDrawPixel(&tileLine.pixels[1], tileBase[3].lo, palette, prio); - gfxDrawPixel(&tileLine.pixels[2], tileBase[2].hi, palette, prio); - gfxDrawPixel(&tileLine.pixels[3], tileBase[2].lo, palette, prio); - gfxDrawPixel(&tileLine.pixels[4], tileBase[1].hi, palette, prio); - gfxDrawPixel(&tileLine.pixels[5], tileBase[1].lo, palette, prio); - gfxDrawPixel(&tileLine.pixels[6], tileBase[0].hi, palette, prio); - gfxDrawPixel(&tileLine.pixels[7], tileBase[0].lo, palette, prio); - } - - return tileLine; -} - -static inline void gfxDrawTile(const TileLine& tileLine, uint32_t* line) -{ - memcpy(line, tileLine.pixels, sizeof(tileLine.pixels)); -} - -static inline void gfxDrawTileClipped(const TileLine& tileLine, uint32_t* line, const int start, int w) -{ - memcpy(line, tileLine.pixels + start, w * sizeof(uint32_t)); -} - -template -static void gfxDrawTextScreen(uint16_t control, uint16_t hofs, uint16_t vofs, - uint32_t* line) -{ - uint16_t* palette = (uint16_t*)paletteRAM; - uint8_t* charBase = &vram[((control >> 2) & 0x03) * 0x4000]; - uint16_t* screenBase = (uint16_t*)&vram[((control >> 8) & 0x1f) * 0x800]; - uint32_t prio = ((control & 3) << 25) + 0x1000000; - int sizeX = 256; - int sizeY = 256; - switch ((control >> 14) & 3) { - case 0: - break; - case 1: - sizeX = 512; - break; - case 2: - sizeY = 512; - break; - case 3: - sizeX = 512; - sizeY = 512; - break; - } - - int maskX = sizeX - 1; - int maskY = sizeY - 1; - - bool mosaicOn = (control & 0x40) ? true : false; - - int xxx = hofs & maskX; - int yyy = (vofs + VCOUNT) & maskY; - int mosaicX = (MOSAIC & 0x000F) + 1; - int mosaicY = ((MOSAIC & 0x00F0) >> 4) + 1; - - if (mosaicOn) { - if ((VCOUNT % mosaicY) != 0) { - mosaicY = VCOUNT - (VCOUNT % mosaicY); - yyy = (vofs + mosaicY) & maskY; - } - } - - if (yyy > 255 && sizeY > 256) { - yyy &= 255; - screenBase += 0x400; - if (sizeX > 256) - screenBase += 0x400; - } - - int yshift = ((yyy >> 3) << 5); - - uint16_t* screenSource = screenBase + 0x400 * (xxx >> 8) + ((xxx & 255) >> 3) + yshift; - int x = 0; - const int firstTileX = xxx & 7; - - // First tile, if clipped - if (firstTileX) { - gfxDrawTileClipped(readTile(screenSource, yyy, charBase, palette, prio), &line[x], firstTileX, 8 - firstTileX); - screenSource++; - x += 8 - firstTileX; - xxx += 8 - firstTileX; - - if (xxx == 256 && sizeX > 256) { - screenSource = screenBase + 0x400 + yshift; - } else if (xxx >= sizeX) { - xxx = 0; - screenSource = screenBase + yshift; - } - } - - // Middle tiles, full - while (x < 240 - firstTileX) { - gfxDrawTile(readTile(screenSource, yyy, charBase, palette, prio), &line[x]); - screenSource++; - xxx += 8; - x += 8; - - if (xxx == 256 && sizeX > 256) { - screenSource = screenBase + 0x400 + yshift; - } else if (xxx >= sizeX) { - xxx = 0; - screenSource = screenBase + yshift; - } - } - - // Last tile, if clipped - if (firstTileX) { - gfxDrawTileClipped(readTile(screenSource, yyy, charBase, palette, prio), &line[x], 0, firstTileX); - } - - if (mosaicOn) { - if (mosaicX > 1) { - int m = 1; - for (int i = 0; i < 239; i++) { - line[i + 1] = line[i]; - m++; - if (m == mosaicX) { - m = 1; - i++; - } - } - } - } -} - -void gfxDrawTextScreen(uint16_t control, uint16_t hofs, uint16_t vofs, uint32_t* line) -{ - if (control & 0x80) // 1 pal / 256 col - gfxDrawTextScreen(control, hofs, vofs, line); - else // 16 pal / 16 col - gfxDrawTextScreen(control, hofs, vofs, line); -} -#endif - struct EmulatedSystem GBASystem = { // emuMain CPULoop, diff --git a/src/gba/GBAGfx.cpp b/src/gba/GBAGfx.cpp index 8049a57c..6d1b164b 100644 --- a/src/gba/GBAGfx.cpp +++ b/src/gba/GBAGfx.cpp @@ -1,3 +1,5 @@ +#include +#include "GBAGfx.h" #include "../System.h" int coeff[32] = { @@ -24,3 +26,230 @@ int gfxBG2Y = 0; int gfxBG3X = 0; int gfxBG3Y = 0; int gfxLastVCOUNT = 0; + +#ifdef TILED_RENDERING +union uint8_th { + struct + { + /* 0*/ unsigned lo : 4; + /* 4*/ unsigned hi : 4; + } __attribute__((packed)); + uint8_t val; +}; + +union TileEntry { + struct + { + /* 0*/ unsigned tileNum : 10; + /*12*/ unsigned hFlip : 1; + /*13*/ unsigned vFlip : 1; + /*14*/ unsigned palette : 4; + }; + uint16_t val; +}; + +struct TileLine { + uint32_t pixels[8]; +}; + +typedef const TileLine (*TileReader)(const uint16_t*, const int, const uint8_t*, uint16_t*, const uint32_t); + +static inline void gfxDrawPixel(uint32_t* dest, const uint8_t color, const uint16_t* palette, const uint32_t prio) +{ + *dest = color ? (READ16LE(&palette[color]) | prio) : 0x80000000; +} + +inline const TileLine gfxReadTile(const uint16_t* screenSource, const int yyy, const uint8_t* charBase, uint16_t* palette, const uint32_t prio) +{ + TileEntry tile; + tile.val = READ16LE(screenSource); + + int tileY = yyy & 7; + if (tile.vFlip) + tileY = 7 - tileY; + TileLine tileLine; + + const uint8_t* tileBase = &charBase[tile.tileNum * 64 + tileY * 8]; + + if (!tile.hFlip) { + gfxDrawPixel(&tileLine.pixels[0], tileBase[0], palette, prio); + gfxDrawPixel(&tileLine.pixels[1], tileBase[1], palette, prio); + gfxDrawPixel(&tileLine.pixels[2], tileBase[2], palette, prio); + gfxDrawPixel(&tileLine.pixels[3], tileBase[3], palette, prio); + gfxDrawPixel(&tileLine.pixels[4], tileBase[4], palette, prio); + gfxDrawPixel(&tileLine.pixels[5], tileBase[5], palette, prio); + gfxDrawPixel(&tileLine.pixels[6], tileBase[6], palette, prio); + gfxDrawPixel(&tileLine.pixels[7], tileBase[7], palette, prio); + } else { + gfxDrawPixel(&tileLine.pixels[0], tileBase[7], palette, prio); + gfxDrawPixel(&tileLine.pixels[1], tileBase[6], palette, prio); + gfxDrawPixel(&tileLine.pixels[2], tileBase[5], palette, prio); + gfxDrawPixel(&tileLine.pixels[3], tileBase[4], palette, prio); + gfxDrawPixel(&tileLine.pixels[4], tileBase[3], palette, prio); + gfxDrawPixel(&tileLine.pixels[5], tileBase[2], palette, prio); + gfxDrawPixel(&tileLine.pixels[6], tileBase[1], palette, prio); + gfxDrawPixel(&tileLine.pixels[7], tileBase[0], palette, prio); + } + + return tileLine; +} + +inline const TileLine gfxReadTilePal(const uint16_t* screenSource, const int yyy, const uint8_t* charBase, uint16_t* palette, const uint32_t prio) +{ + TileEntry tile; + tile.val = READ16LE(screenSource); + + int tileY = yyy & 7; + if (tile.vFlip) + tileY = 7 - tileY; + palette += tile.palette * 16; + TileLine tileLine; + + const uint8_th* tileBase = (uint8_th*)&charBase[tile.tileNum * 32 + tileY * 4]; + + if (!tile.hFlip) { + gfxDrawPixel(&tileLine.pixels[0], tileBase[0].lo, palette, prio); + gfxDrawPixel(&tileLine.pixels[1], tileBase[0].hi, palette, prio); + gfxDrawPixel(&tileLine.pixels[2], tileBase[1].lo, palette, prio); + gfxDrawPixel(&tileLine.pixels[3], tileBase[1].hi, palette, prio); + gfxDrawPixel(&tileLine.pixels[4], tileBase[2].lo, palette, prio); + gfxDrawPixel(&tileLine.pixels[5], tileBase[2].hi, palette, prio); + gfxDrawPixel(&tileLine.pixels[6], tileBase[3].lo, palette, prio); + gfxDrawPixel(&tileLine.pixels[7], tileBase[3].hi, palette, prio); + } else { + gfxDrawPixel(&tileLine.pixels[0], tileBase[3].hi, palette, prio); + gfxDrawPixel(&tileLine.pixels[1], tileBase[3].lo, palette, prio); + gfxDrawPixel(&tileLine.pixels[2], tileBase[2].hi, palette, prio); + gfxDrawPixel(&tileLine.pixels[3], tileBase[2].lo, palette, prio); + gfxDrawPixel(&tileLine.pixels[4], tileBase[1].hi, palette, prio); + gfxDrawPixel(&tileLine.pixels[5], tileBase[1].lo, palette, prio); + gfxDrawPixel(&tileLine.pixels[6], tileBase[0].hi, palette, prio); + gfxDrawPixel(&tileLine.pixels[7], tileBase[0].lo, palette, prio); + } + + return tileLine; +} + +static inline void gfxDrawTile(const TileLine& tileLine, uint32_t* line) +{ + memcpy(line, tileLine.pixels, sizeof(tileLine.pixels)); +} + +static inline void gfxDrawTileClipped(const TileLine& tileLine, uint32_t* line, const int start, int w) +{ + memcpy(line, tileLine.pixels + start, w * sizeof(uint32_t)); +} + +template +static void gfxDrawTextScreen(uint16_t control, uint16_t hofs, uint16_t vofs, + uint32_t* line) +{ + uint16_t* palette = (uint16_t*)paletteRAM; + uint8_t* charBase = &vram[((control >> 2) & 0x03) * 0x4000]; + uint16_t* screenBase = (uint16_t*)&vram[((control >> 8) & 0x1f) * 0x800]; + uint32_t prio = ((control & 3) << 25) + 0x1000000; + int sizeX = 256; + int sizeY = 256; + switch ((control >> 14) & 3) { + case 0: + break; + case 1: + sizeX = 512; + break; + case 2: + sizeY = 512; + break; + case 3: + sizeX = 512; + sizeY = 512; + break; + } + + int maskX = sizeX - 1; + int maskY = sizeY - 1; + + bool mosaicOn = (control & 0x40) ? true : false; + + int xxx = hofs & maskX; + int yyy = (vofs + VCOUNT) & maskY; + int mosaicX = (MOSAIC & 0x000F) + 1; + int mosaicY = ((MOSAIC & 0x00F0) >> 4) + 1; + + if (mosaicOn) { + if ((VCOUNT % mosaicY) != 0) { + mosaicY = VCOUNT - (VCOUNT % mosaicY); + yyy = (vofs + mosaicY) & maskY; + } + } + + if (yyy > 255 && sizeY > 256) { + yyy &= 255; + screenBase += 0x400; + if (sizeX > 256) + screenBase += 0x400; + } + + int yshift = ((yyy >> 3) << 5); + + uint16_t* screenSource = screenBase + 0x400 * (xxx >> 8) + ((xxx & 255) >> 3) + yshift; + int x = 0; + const int firstTileX = xxx & 7; + + // First tile, if clipped + if (firstTileX) { + gfxDrawTileClipped(readTile(screenSource, yyy, charBase, palette, prio), &line[x], firstTileX, 8 - firstTileX); + screenSource++; + x += 8 - firstTileX; + xxx += 8 - firstTileX; + + if (xxx == 256 && sizeX > 256) { + screenSource = screenBase + 0x400 + yshift; + } else if (xxx >= sizeX) { + xxx = 0; + screenSource = screenBase + yshift; + } + } + + // Middle tiles, full + while (x < 240 - firstTileX) { + gfxDrawTile(readTile(screenSource, yyy, charBase, palette, prio), &line[x]); + screenSource++; + xxx += 8; + x += 8; + + if (xxx == 256 && sizeX > 256) { + screenSource = screenBase + 0x400 + yshift; + } else if (xxx >= sizeX) { + xxx = 0; + screenSource = screenBase + yshift; + } + } + + // Last tile, if clipped + if (firstTileX) { + gfxDrawTileClipped(readTile(screenSource, yyy, charBase, palette, prio), &line[x], 0, firstTileX); + } + + if (mosaicOn) { + if (mosaicX > 1) { + int m = 1; + for (int i = 0; i < 239; i++) { + line[i + 1] = line[i]; + m++; + if (m == mosaicX) { + m = 1; + i++; + } + } + } + } +} + +void gfxDrawTextScreen(uint16_t control, uint16_t hofs, uint16_t vofs, uint32_t* line) +{ + if (control & 0x80) // 1 pal / 256 col + gfxDrawTextScreen(control, hofs, vofs, line); + else // 16 pal / 16 col + gfxDrawTextScreen(control, hofs, vofs, line); +} +#endif // TILED_RENDERING diff --git a/src/gba/GBAGfx.h b/src/gba/GBAGfx.h index 6f25d0d0..5d3768c5 100644 --- a/src/gba/GBAGfx.h +++ b/src/gba/GBAGfx.h @@ -216,7 +216,7 @@ static inline void gfxDrawTextScreen(uint16_t control, uint16_t hofs, uint16_t v } } } -#endif +#endif // !__TILED_RENDERING static inline void gfxDrawRotScreen(uint16_t control, uint16_t x_l, uint16_t x_h, uint16_t y_l, uint16_t y_h, uint16_t pa, uint16_t pb, uint16_t pc, uint16_t pd, int& currentX, int& currentY, int changed, From edf939e96bc1dba7699c46a08c306c3452407740 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Fri, 8 Jun 2018 21:18:32 +0800 Subject: [PATCH 4/5] Gfx: Add #ifdef _MSC_VER, fix tiled rendering on windows This only affects when using TILED_RENDERING --- src/gba/GBAGfx.cpp | 65 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/src/gba/GBAGfx.cpp b/src/gba/GBAGfx.cpp index 6d1b164b..957b2f56 100644 --- a/src/gba/GBAGfx.cpp +++ b/src/gba/GBAGfx.cpp @@ -28,24 +28,57 @@ int gfxBG3Y = 0; int gfxLastVCOUNT = 0; #ifdef TILED_RENDERING -union uint8_th { - struct - { - /* 0*/ unsigned lo : 4; - /* 4*/ unsigned hi : 4; - } __attribute__((packed)); - uint8_t val; +#ifdef _MSC_VER +union uint8_th +{ + __pragma( pack(push, 1)); + struct + { +#ifdef MSB_FIRST + /* 4*/ unsigned char hi:4; + /* 0*/ unsigned char lo:4; +#else + /* 0*/ unsigned char lo:4; + /* 4*/ unsigned char hi:4; +#endif + } + __pragma(pack(pop)); + uint8_t val; }; +#else // !_MSC_VER +union uint8_th +{ + struct + { +#ifdef MSB_FIRST + /* 4*/ unsigned char hi:4; + /* 0*/ unsigned char lo:4; +#else + /* 0*/ unsigned char lo:4; + /* 4*/ unsigned char hi:4; +#endif + } __attribute__ ((packed)); + uint8_t val; +}; +#endif -union TileEntry { - struct - { - /* 0*/ unsigned tileNum : 10; - /*12*/ unsigned hFlip : 1; - /*13*/ unsigned vFlip : 1; - /*14*/ unsigned palette : 4; - }; - uint16_t val; +union TileEntry +{ + struct + { +#ifdef MSB_FIRST + /*14*/ unsigned palette:4; + /*13*/ unsigned vFlip:1; + /*12*/ unsigned hFlip:1; + /* 0*/ unsigned tileNum:10; +#else + /* 0*/ unsigned tileNum:10; + /*12*/ unsigned hFlip:1; + /*13*/ unsigned vFlip:1; + /*14*/ unsigned palette:4; +#endif + }; + uint16_t val; }; struct TileLine { From bc0e169d238ff3e1669444f819c6740ac7843567 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-UVBJEGH\\Cloud" Date: Fri, 8 Jun 2018 23:05:23 +0800 Subject: [PATCH 5/5] Add missing file --- src/common/Types.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/common/Types.h diff --git a/src/common/Types.h b/src/common/Types.h new file mode 100644 index 00000000..bbb53e76 --- /dev/null +++ b/src/common/Types.h @@ -0,0 +1,28 @@ +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2008 VBA-M development team + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or(at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#ifndef __VBA_TYPES_H__ +#define __VBA_TYPES_H__ + +#ifdef __LIBRETRO__ +#include +#else +#include +#include "cstdint.h" +#endif + +#endif // __VBA_TYPES_H__