Skip to content

Commit 757749e

Browse files
authored
Merge pull request #3 from scooterpsu/rg300-ctrls
Add IPU check, use software scaling if not present
2 parents 8d60182 + 7fb5993 commit 757749e

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ add_library(devilution STATIC
219219
Source/wave.cpp)
220220

221221
set(devilutionx_SRCS
222+
SourceX/utils.cpp
222223
SourceX/dx.cpp
223224
SourceX/miniwin/ddraw.cpp
224225
SourceX/miniwin/misc.cpp

SourceX/dx.cpp

+28-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "miniwin/com_macro.h"
55
#include <SDL.h>
66

7+
#include "utils.h"
8+
79
namespace dvl {
810

911
int sgdwLockCount;
@@ -182,17 +184,33 @@ void BltFast(DWORD dwX, DWORD dwY, LPRECT lpSrcRect)
182184
static_cast<decltype(SDL_Rect().y)>(lpSrcRect->top),
183185
w, h
184186
};
185-
SDL_Rect dst_rect = {
186-
static_cast<decltype(SDL_Rect().x)>(dwX),
187-
static_cast<decltype(SDL_Rect().y)>(dwY),
188-
w, h
189-
};
190-
191-
// Convert from 8-bit to 32-bit
192-
if (SDL_BlitSurface(pal_surface, &src_rect, GetOutputSurface(), &dst_rect) <= -1) {
193-
ErrSdl();
187+
188+
if (GFX_IsRetroFW20()) {
189+
SDL_Rect dst_rect = {
190+
static_cast<decltype(SDL_Rect().x)>(dwX),
191+
static_cast<decltype(SDL_Rect().y)>(dwY),
192+
w, h
193+
};
194+
195+
// Convert from 8-bit to 32-bit
196+
if (SDL_BlitSurface(pal_surface, &src_rect, GetOutputSurface(), &dst_rect) <= -1) {
197+
ErrSdl();
198+
}
199+
200+
} else {
201+
SDL_Rect dst_rect = {
202+
static_cast<decltype(SDL_Rect().x)>(dwX) / 2,
203+
static_cast<decltype(SDL_Rect().y)>(dwY),
204+
w / 2, h
205+
};
206+
// Convert from 8-bit to 32-bit
207+
SDL_Surface *tmp = SDL_ConvertSurface(pal_surface, GetOutputSurface()->format, 0);
208+
if (SDL_BlitScaled(tmp, &src_rect, GetOutputSurface(), &dst_rect) <= -1) {
209+
SDL_FreeSurface(tmp);
210+
ErrSdl();
211+
}
212+
SDL_FreeSurface(tmp);
194213
}
195-
196214
bufferUpdated = true;
197215
}
198216

SourceX/miniwin/misc.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#define strncasecmp _strnicmp
1313
#endif
1414

15+
#include "utils.h"
16+
1517
namespace dvl {
1618

1719
DWORD last_error;
@@ -149,7 +151,11 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight)
149151
if (fullscreen)
150152
flags |= SDL_FULLSCREEN;
151153
SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME);
152-
SDL_SetVideoMode(nWidth, nHeight, /*bpp=*/0, flags);
154+
if (GFX_IsRetroFW20()) {
155+
SDL_SetVideoMode(nWidth, nHeight, /*bpp=*/0, flags);
156+
} else {
157+
SDL_SetVideoMode(320, 480, /*bpp=*/0, flags); // LDK Hack
158+
}
153159
window = SDL_GetVideoSurface();
154160
if (grabInput)
155161
SDL_WM_GrabInput(SDL_GRAB_ON);

SourceX/storm/storm.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "DiabloUI/diabloui.h"
1616

17+
#include "utils.h"
18+
1719
namespace dvl {
1820

1921
DWORD nLastError = 0;
@@ -706,13 +708,25 @@ BOOL SVidPlayContinue(void)
706708
}
707709
const int scaledW = SVidWidth * factor;
708710
const int scaledH = SVidHeight * factor;
711+
712+
int newX;
713+
int newW;
714+
715+
if (GFX_IsRetroFW20()) {
716+
newX = (SCREEN_WIDTH - scaledW) / 2;
717+
newW = scaledW;
718+
} else {
719+
newX = (SCREEN_WIDTH - scaledW) / 2 / 2;
720+
newW = scaledW / 2;
721+
}
709722

710723
SDL_Rect pal_surface_offset = {
711-
static_cast<decltype(SDL_Rect().x)>((SCREEN_WIDTH - scaledW) / 2),
724+
static_cast<decltype(SDL_Rect().x)>(newX),
712725
static_cast<decltype(SDL_Rect().y)>((SCREEN_HEIGHT - scaledH) / 2),
713-
static_cast<decltype(SDL_Rect().w)>(scaledW),
726+
static_cast<decltype(SDL_Rect().w)>(newW),
714727
static_cast<decltype(SDL_Rect().h)>(scaledH)
715728
};
729+
716730
#ifdef USE_SDL1
717731
SDL_Surface *tmp = SDL_ConvertSurface(SVidSurface, window->format, 0);
718732
// NOTE: Consider resolution switching instead if video doesn't play

SourceX/utils.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <sys/types.h>
2+
#include <sys/stat.h>
3+
#include <fcntl.h>
4+
5+
bool GFX_IsRetroFW20(void)
6+
{
7+
struct stat buffer;
8+
9+
return (stat("/proc/jz/ipu_ratio", &buffer) == 0);
10+
}

SourceX/utils.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bool GFX_IsRetroFW20(void);

0 commit comments

Comments
 (0)