Skip to content

Commit

Permalink
Fixed the issue with smooth scrolling with negative offset.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Tremblay committed May 27, 2022
1 parent 08cff96 commit f3cd22a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Main/Display/Gpu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ private unsafe void DrawTiles(int* p, bool gammaCorrection, byte TextColumns, in

int tileSize = (smallTiles ? 8 : 16);
int strideLine = tileSize * 16;
byte scrollMask = (byte)(smallTiles ? 7 : 15);

int tilemapWidth = VICKY.ReadWord(addrTileCtrlReg + 4) & 0x3FF; // 10 bits
//int tilemapHeight = VICKY.ReadWord(addrTileCtrlReg + 6) & 0x3FF; // 10 bits
Expand All @@ -656,31 +657,29 @@ private unsafe void DrawTiles(int* p, bool gammaCorrection, byte TextColumns, in
// direction is bit 15.
int tilemapWindowX = VICKY.ReadWord(addrTileCtrlReg + 8);
bool dirLeft = (tilemapWindowX & 0x8000) != 0;
byte scrollX = (byte)(((tilemapWindowX & scrollMask) * (dirLeft ? -1 : 1)) & scrollMask);
if (smallTiles)
{
tilemapWindowX = (((tilemapWindowX & 0x3FF0) >> 1) + tilemapWindowX & 7);
tilemapWindowX *= (dirLeft ? -1 : 1);
tilemapWindowX = ((tilemapWindowX & 0x3FF0) >> 1) + scrollX;
}
else
{
tilemapWindowX &= (0x3FFF);
tilemapWindowX *= (dirLeft ? -1 : 1);
tilemapWindowX = (tilemapWindowX & 0x3FF0) + scrollX;
}
int tileXOffset = tilemapWindowX % tileSize;

// the tilemapWindowY is 10 bits and the scrollY is the lower 4 bits. The IDE combines them.
// direction is bit 15.
int tilemapWindowY = VICKY.ReadWord(addrTileCtrlReg + 10);
bool dirUp = (tilemapWindowY & 0x8000) != 0;
byte scrollY = (byte)(((tilemapWindowY & scrollMask) * (dirUp ? -1 : 1)) & scrollMask);
if (smallTiles)
{
tilemapWindowY = (((tilemapWindowY & 0x3FF0) >> 1) + tilemapWindowY & 7);
tilemapWindowY *= (dirUp ? -1 : 1);
tilemapWindowY = ((tilemapWindowY & 0x3FF0) >> 1) + scrollY;
}
else
{
tilemapWindowY &= 0x3FFF;
tilemapWindowY *= (dirUp ? -1 : 1);
tilemapWindowY = tilemapWindowY & 0x3FF0 + scrollY;
}

int tileRow = ( line + tilemapWindowY ) / tileSize;
Expand Down
Binary file modified bin/Release/FoenixIDE.exe
Binary file not shown.

0 comments on commit f3cd22a

Please sign in to comment.