Skip to content

Commit

Permalink
#5 support for rotation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
laoo committed Nov 4, 2021
1 parent b352631 commit f33b5b9
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 16 deletions.
3 changes: 3 additions & 0 deletions WinFelix/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ void Manager::reset()
{

mInstance = std::make_shared<Core>( mComLynxWire, mRenderer->getVideoSink(), mIntputSource, std::span<InputFile>{ inputs.data(), inputs.size() } );

mRenderer->setRotation( mInstance->rotation() );

if ( !mLogPath.empty() )
mInstance->setLog( mLogPath, mLogStartCycle );

Expand Down
119 changes: 108 additions & 11 deletions WinFelix/WinRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct RenderFrame

uint32_t RenderFrame::sId = 0;

WinRenderer::WinRenderer() : mInstance{ std::make_shared<Instance>() }, mHWnd{}, mSizeManager{}, mRefreshRate{}, mEncoder{}, mVScale{ ~0u }
WinRenderer::WinRenderer() : mInstance{ std::make_shared<Instance>() }, mHWnd{}, mSizeManager{}, mRefreshRate{}, mEncoder{}, mVScale{ ~0u }, mRotation{}
{
LARGE_INTEGER l;
QueryPerformanceCounter( &l );
Expand Down Expand Up @@ -196,9 +196,9 @@ bool WinRenderer::internalRender( Manager & config )
if ( ::GetClientRect( mHWnd, &r ) == 0 )
return false;

if ( mSizeManager.windowHeight() != r.bottom || ( mSizeManager.windowWidth() != r.right ) )
if ( mSizeManager.windowHeight() != r.bottom || ( mSizeManager.windowWidth() != r.right ) || mSizeManager.rotation() != mRotation )
{
mSizeManager = SizeManager{ r.right, r.bottom };
mSizeManager = SizeManager{ r.right, r.bottom, mRotation };

if ( !mSizeManager )
{
Expand Down Expand Up @@ -236,7 +236,12 @@ bool WinRenderer::internalRender( Manager & config )
updateSourceTexture( std::move( frame ) );
}

CBPosSize cbPosSize{ mSizeManager.xOff(), mSizeManager.yOff(), mSizeManager.scale(), mVScale };
CBPosSize cbPosSize{
mSizeManager.rotx1(), mSizeManager.rotx2(),
mSizeManager.roty1(), mSizeManager.roty2(),
mSizeManager.xOff(), mSizeManager.yOff(),
mSizeManager.scale(),
mVScale };
mImmediateContext->UpdateSubresource( mPosSizeCB.Get(), 0, NULL, &cbPosSize, 0, 0 );
mImmediateContext->CSSetConstantBuffers( 0, 1, mPosSizeCB.GetAddressOf() );
mImmediateContext->CSSetShaderResources( 0, 1, mSourceSRV.GetAddressOf() );
Expand Down Expand Up @@ -400,6 +405,9 @@ void WinRenderer::updateVscale( uint32_t vScale )
{
mVScale = vScale;

if ( mVScale == 0 )
return;

uint32_t width = 160 * std::max( 1u, mVScale );
uint32_t height = 102 * std::max( 1u, mVScale );

Expand Down Expand Up @@ -466,6 +474,11 @@ int WinRenderer::win32_WndProcHandler( HWND hWnd, UINT msg, WPARAM wParam, LPARA
return 0;
}

void WinRenderer::setRotation( ImageCart::Rotation rotation )
{
mRotation = rotation;
}

int WinRenderer::sizing( RECT & rect )
{
RECT wRect, cRect;
Expand Down Expand Up @@ -518,11 +531,22 @@ WinRenderer::SizeManager::SizeManager() : mWinWidth{}, mWinHeight{}, mScale{ 1 }
{
}

WinRenderer::SizeManager::SizeManager( int windowWidth, int windowHeight ) : mWinWidth{ windowWidth }, mWinHeight{ windowHeight }, mScale{ 1 }
WinRenderer::SizeManager::SizeManager( int windowWidth, int windowHeight, ImageCart::Rotation rotation ) : mWinWidth{ windowWidth }, mWinHeight{ windowHeight }, mScale{ 1 }, mRotation{ rotation }
{
int sx, sy;
sx = (std::max)( 1, mWinWidth / 160 );
sy = (std::max)( 1, mWinHeight / 102 );
switch ( mRotation )
{
case ImageCart::Rotation::LEFT:
case ImageCart::Rotation::RIGHT:
sx = (std::max)( 1, mWinWidth / 102 );
sy = (std::max)( 1, mWinHeight / 160 );
break;
default:
sx = (std::max)( 1, mWinWidth / 160 );
sy = (std::max)( 1, mWinHeight / 102 );
break;
}

mScale = (std::min)( sx, sy );
}

Expand All @@ -538,29 +562,102 @@ int WinRenderer::SizeManager::windowHeight() const

int WinRenderer::SizeManager::minWindowWidth() const
{
return 160;
return mRotation == ImageCart::Rotation::NORMAL ? 160 : 102;
}

int WinRenderer::SizeManager::minWindowHeight() const
{
return 102;
return mRotation == ImageCart::Rotation::NORMAL ? 102 : 160;
}

int WinRenderer::SizeManager::xOff() const
{
return ( mWinWidth - 160 * mScale ) / 2;
switch ( mRotation )
{
case ImageCart::Rotation::LEFT:
return ( mWinWidth + 102 * mScale ) / 2;
case ImageCart::Rotation::RIGHT:
return ( mWinWidth - 102 * mScale ) / 2;
default:
return ( mWinWidth - 160 * mScale ) / 2;
}
}

int WinRenderer::SizeManager::yOff() const
{
return ( mWinHeight - 102 * mScale ) / 2;
switch ( mRotation )
{
case ImageCart::Rotation::LEFT:
return ( mWinHeight - 160 * mScale ) / 2;
case ImageCart::Rotation::RIGHT:
return ( mWinHeight + 160 * mScale ) / 2;
default:
return ( mWinHeight - 102 * mScale ) / 2;
}
}

int WinRenderer::SizeManager::scale() const
{
return mScale;
}

int WinRenderer::SizeManager::rotx1() const
{
switch ( mRotation )
{
case ImageCart::Rotation::LEFT:
return 0; //mScale * cos( 90 )
case ImageCart::Rotation::RIGHT:
return 0; //mScale * cos( -90 )
default:
return mScale; //mScale * cos( 0 )
}
}

int WinRenderer::SizeManager::rotx2() const
{
switch ( mRotation )
{
case ImageCart::Rotation::LEFT:
return -mScale; //mScale * -sin( 90 )
case ImageCart::Rotation::RIGHT:
return mScale; //mScale * -sin( -90 )
default:
return 0; //mScale * -sin( 0 )
}
}

int WinRenderer::SizeManager::roty1() const
{
switch ( mRotation )
{
case ImageCart::Rotation::LEFT:
return mScale; //mScale * sin( 90 )
case ImageCart::Rotation::RIGHT:
return -mScale; //mScale * sin( -90 )
default:
return 0; //mScale * sin( 0 )
}
}

int WinRenderer::SizeManager::roty2() const
{
switch ( mRotation )
{
case ImageCart::Rotation::LEFT:
return 0; //mScale * cos( 90 )
case ImageCart::Rotation::RIGHT:
return 0; //mScale * cos( -90 )
default:
return mScale; //mScale * cos( 0 )
}
}

ImageCart::Rotation WinRenderer::SizeManager::rotation() const
{
return mRotation;
}

WinRenderer::SizeManager::operator bool() const
{
return mWinWidth != 0 && mWinHeight != 0;
Expand Down
17 changes: 15 additions & 2 deletions WinFelix/WinRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "IVideoSink.hpp"
#include "DisplayGenerator.hpp"
#include "ImageCart.hpp"

struct RenderFrame;
class WinImgui;
Expand All @@ -18,6 +19,7 @@ class WinRenderer
void setEncoder( std::shared_ptr<IEncoder> encoder );
void initialize( HWND hWnd, std::filesystem::path const& iniPath );
int win32_WndProcHandler( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
void setRotation( ImageCart::Rotation rotation );

std::shared_ptr<IVideoSink> getVideoSink() const;

Expand All @@ -28,7 +30,11 @@ class WinRenderer
{
int32_t posx;
int32_t posy;
int32_t scale;
int32_t rotx1;
int32_t rotx2;
int32_t roty1;
int32_t roty2;
int32_t size;
uint32_t vscale;
};

Expand Down Expand Up @@ -57,7 +63,7 @@ class WinRenderer
{
public:
SizeManager();
SizeManager( int windowWidth, int windowHeight );
SizeManager( int windowWidth, int windowHeight, ImageCart::Rotation rotation );

int windowWidth() const;
int windowHeight() const;
Expand All @@ -66,12 +72,18 @@ class WinRenderer
int xOff() const;
int yOff() const;
int scale() const;
int rotx1() const;
int rotx2() const;
int roty1() const;
int roty2() const;
ImageCart::Rotation rotation() const;
explicit operator bool() const;

private:
int mWinWidth;
int mWinHeight;
int mScale;
ImageCart::Rotation mRotation;
};

struct Instance : public IVideoSink
Expand Down Expand Up @@ -123,4 +135,5 @@ class WinRenderer
std::shared_ptr<IEncoder> mEncoder;
int64_t mLastRenderTimePoint;
uint32_t mVScale;
ImageCart::Rotation mRotation;
};
6 changes: 5 additions & 1 deletion WinFelix/render.csh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ float3 rgb2yuv( float3 rgb )

cbuffer cb : register( b0 )
{
int2 rotx;
int2 roty;
int2 off;
int size;
uint vsize;
Expand All @@ -29,7 +31,9 @@ void main( uint3 DT : SV_DispatchThreadID )
{
for ( int x = 0; x < size; ++x )
{
dst[off + DT.xy * size + int2( x, y )] = src[DT.xy];
int dtx = DT.x * rotx.x + DT.y * rotx.y;
int dty = DT.x * roty.x + DT.y * roty.y;
dst[off + int2( dtx, dty ) + int2( x, y )] = src[DT.xy];
}
}

Expand Down
6 changes: 6 additions & 0 deletions felix.sln
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Encoder", "Encoder\Encoder.
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libwav", "libwav.vcxproj", "{9EA01067-B994-4BBE-B340-E626EE249427}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{88B0A14D-5C01-4FA8-9C4A-E82A8998D508}"
ProjectSection(SolutionItems) = preProject
CHANGELOG.md = CHANGELOG.md
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down
5 changes: 5 additions & 0 deletions libFelix/Cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ void Cartridge::pokeRCART1( uint64_t tick, uint8_t value )
}
}

ImageCart::Rotation Cartridge::rotation() const
{
return mCart ? mCart->rotation() : ImageCart::Rotation{};
}

uint8_t Cartridge::peek( CartBank const & bank )
{
mTraceHelper->comment( "Cart read from ${:02x}:${:03x}.", mShiftRegister, mCounter );
Expand Down
2 changes: 2 additions & 0 deletions libFelix/Cartridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Cartridge
void pokeRCART0( uint64_t tick, uint8_t value );
void pokeRCART1( uint64_t tick, uint8_t value );

ImageCart::Rotation rotation() const;

private:
uint8_t peek( CartBank const& bank );

Expand Down
5 changes: 5 additions & 0 deletions libFelix/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@ int64_t Core::globalSamplesEmittedPerFrame() const
return mGlobalSamplesEmittedPerFrame;
}

ImageCart::Rotation Core::rotation() const
{
return mCartridge ? mCartridge->rotation() : ImageCart::Rotation{};
}

Cartridge & Core::getCartridge()
{
assert( mCartridge );
Expand Down
3 changes: 2 additions & 1 deletion libFelix/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "Utility.hpp"
#include "ComLynx.hpp"
#include "MemoryUnit.hpp"
#include "ImageCart.hpp"

class Mikey;
class CPU;
class Cartridge;
class InputFile;
class ImageBS93;
class ImageBIOS;
class ImageCart;
class IEscape;
class ComLynxWire;
class TraceHelper;
Expand All @@ -35,6 +35,7 @@ class Core

void enterMonitor();
int64_t globalSamplesEmittedPerFrame() const;
ImageCart::Rotation rotation() const;

//Not thread safe. Used only for monitoring
uint8_t sampleRam( uint16_t addr ) const;
Expand Down
7 changes: 6 additions & 1 deletion libFelix/ImageCart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ ImageCart::EEPROM ImageCart::eeprom() const
return mEEPROM;
}

ImageCart::Rotation ImageCart::rotation() const
{
return mRotation;
}

std::filesystem::path ImageCart::path() const
{
return mImagePath;
}

ImageCart::ImageCart( std::vector<uint8_t> data, std::filesystem::path path ) : mImagePath{ std::move( path ) }, mData { std::move( data ) },
mBank0{}, mBank0A{}, mBank1{}, mBank1A{}, mEEPROM{}
mBank0{}, mBank0A{}, mBank1{}, mBank1A{}, mEEPROM{}, mRotation{}
{
}

Expand Down
Loading

0 comments on commit f33b5b9

Please sign in to comment.