Skip to content

Commit 9d6af09

Browse files
committed
Fix random background
1 parent ffdf55c commit 9d6af09

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

Core/HdPackLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ void HdPackLoader::ProcessConditionTag(vector<string> &tokens, bool createInvert
658658
checkConstraint(_data->Version >= 106, "[HDPack] This feature requires version 106+ of HD Packs");
659659
checkConstraint(tokens.size() >= 3, "[HDPack] Condition tag should contain at least 3 parameters");
660660

661-
int32_t operandA;
661+
float operandA;
662662
operandA = std::stof(tokens[index++]);
663663

664664
((HdPackRandomBackgroundCondition*)condition.get())->Initialize(operandA);

Core/HdPpu.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void HdPpu::DrawPixel()
6868
tileInfo.EmphasisBits = _intensifyColorBits >> 6;
6969
tileInfo.Tile.PpuBackgroundColor = ReadPaletteRAM(0);
7070
tileInfo.Tile.BgColorIndex = backgroundColor;
71-
tileInfo.Tile.nameTableIdx = _state.VideoRamAddr;
71+
tileInfo.Tile.nameTableIdx = _state.bgTileAddr;
7272

7373
if(backgroundColor == 0) {
7474
tileInfo.Tile.BgColor = tileInfo.Tile.PpuBackgroundColor;
@@ -263,6 +263,13 @@ HdPpu::HdPpu(shared_ptr<Console> console, HdPackData * hdData) : PPU(console)
263263
_screenInfo[0] = new HdScreenInfo(isChrRamGame);
264264
_screenInfo[1] = new HdScreenInfo(isChrRamGame);
265265
_info = _screenInfo[0];
266+
267+
std::random_device rd;
268+
std::mt19937 mt(rd());
269+
std::uniform_real_distribution<> dist(0, 1);
270+
for (uint16_t i = 0; i < 0x1000; i++) {
271+
_nameTableRandVal[i] = dist(mt);
272+
}
266273
}
267274
}
268275

Core/PPU.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,12 @@ void PPU::LoadTileInfo()
666666

667667
_state.LowBitShift |= _nextTile.LowByte;
668668
_state.HighBitShift |= _nextTile.HighByte;
669+
_state.bgTileAddr = _nextTile.bgTileAddr;
669670

670671
uint8_t tileIndex = ReadVram(GetNameTableAddr());
671672
_nextTile.TileAddr = (tileIndex << 4) | (_state.VideoRamAddr >> 12) | _flags.BackgroundPatternAddr;
672673
_nextTile.OffsetY = _state.VideoRamAddr >> 12;
674+
_nextTile.bgTileAddr = _state.VideoRamAddr & 0x0FFF;
673675
break;
674676
}
675677

Core/Types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ struct PPUState
164164
uint16_t TmpVideoRamAddr;
165165
bool WriteToggle;
166166

167+
uint16_t bgTileAddr; //used by HD ppu
167168
uint16_t HighBitShift;
168169
uint16_t LowBitShift;
169170
};
@@ -177,6 +178,7 @@ struct TileInfo
177178

178179
int32_t AbsoluteTileAddr; //used by HD ppu
179180
uint8_t OffsetY; //used by HD ppu
181+
uint16_t bgTileAddr; //used by HD ppu
180182
};
181183

182184
struct SpriteInfo : TileInfo

0 commit comments

Comments
 (0)