Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port to original Xbox using nxdk #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add port to original Xbox using nxdk #1

wants to merge 2 commits into from

Conversation

JayFoxRox
Copy link
Owner

@JayFoxRox JayFoxRox commented Apr 3, 2020

Rudimentary spite-port that was created after ModernVintageGamer announced that he'd be releasing HODE for Xbox built using the proprietary Xbox Development Kit that is (typically) illegally obtained.

In response, I challenged myself to create a port (within an hour or so) using the open-source and legally obtainable nxdk toolchain. In the end, it took about 3 hours (including some fine-tuning).

Heart of Darkness running in XQEMU (Original Xbox emulator)

  • The port loads game files from the DVD drive / D: folder (that's typically the folder where the default.xbe is).
  • The port contains some native Windows support, too (intended to support more Windows toolchains).
  • The button layout tries to recreate what was documented in some Playstation guide.
  • The game stores savegames in E:/UDATA/hode (in case you want to move savegames around manually).

Requires XboxDev/nxdk-sdl#20.

(Last tested on XboxDev/nxdk@d42400d with XboxDev/nxdk-sdl@0ae8796)

#ifndef NXDK
#include <stdlib.h>
#else
#define _MAX_PATH 200 //FIXME: Get real value for Xbox?
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: This should be fixed upstream so we no longer need this different code-path


void __cdecl operator delete(void *ptr) {
free(ptr);
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: new and delete should be from libcxx. Why don't we seem to have those?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires NXDK_CXX = y in Makefile. Not fixed yet.


extern "C" {
extern uint8_t* _fb;
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: This works around a bug in nxdk video.h

memset(_fb, 0x00, fb_size);
#define _PCRTC_START 0xFD600800
*(unsigned int*)(_PCRTC_START) = (unsigned int)_fb & 0x03FFFFFF;
#endif
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: This works around a bug in nxdk video.h

#if defined(NXDK)
// Set display mode (16bpp to save memory)
//FIXME: Temporarily switched to 32bpp, as I got weird issues at 16bpp
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: Check wether game works on all refresh rates? Also switch to 16bpp mode?

} else if (strcmp(name, "gamma") == 0) {
g_system->setGamma(atof(value));
#endif
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: nxdk lacks atof

@JayFoxRox JayFoxRox force-pushed the nxdk branch 5 times, most recently from 3e7f3ca to 6c39619 Compare April 4, 2020 03:06
resource.cpp screenshot.cpp sound.cpp staticres.cpp system_sdl2.cpp \
util.cpp video.cpp

SCALERS := scaler_nearest.cpp #FIXME: scaler_xbr.cpp is broken in nxdk
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: The XBR scaler is broken; the linker will throw a warning and the result XBE will not launch. I assume cxbe can't handle files with dllexports?

@JayFoxRox
Copy link
Owner Author

I got a crash / hang after about 20 minutes. I'm not sure where or how it crashed.
We previously had known that my SDL audio code isn't the most stable, so that might be why?

Could also be running out of memory or something? This needs more stress testing.

@JayFoxRox
Copy link
Owner Author

JayFoxRox commented Apr 4, 2020

I had a crash (or assert?) during the loadscreen. I previously got such crashes when my strcasecmp was wrong. The assert back then was this one https://github.com/JayFoxRox/hode/blob/master/resource.h#L523 because it opens the wrong file. Someone should valgrind my new functions, too.

@tuxuser
Copy link

tuxuser commented Apr 10, 2020

Suggestion for fs_win32.cpp

 	char filePath[_MAX_PATH];
 	WIN32_FIND_DATAA de;
 	snprintf(filePath, sizeof(filePath), "%s\\*", dir);
 	HANDLE d = FindFirstFileA(filePath, &de);
 	if (d != INVALID_HANDLE_VALUE) {
 		BOOL found = TRUE;
-		while (1) {
-			if (de.cFileName[0] == '.') {
+		do
+		{
+			if (de.cFileName[0] == '.')
+			{
 				continue;
 			}
 			snprintf(filePath, sizeof(filePath), "%s\\%s", dir, de.cFileName);
 			if (de.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
 				listFiles(filePath);
-			} else if (matchGameData(filePath)) {
-				addFilePath(filePath);
 			}
-			if(!FindNextFileA(d, &de)) {
-				break;
+			else if (matchGameData(filePath)) {
+				addFilePath(filePath);
 			}
-		}
-		CloseHandle(d);
+		} while (FindNextFileA(d, &de) != 0);
+		FindClose(d);
 	}
 }

Previously with

        HANDLE d = FindFirstFileA(filePath, &de);
 	if (d != INVALID_HANDLE_VALUE) {
 		BOOL found = TRUE;
		while (1) {
			if (de.cFileName[0] == '.') {
 				continue;
 			}
                        // add files and skip to next one with
                        // FindNextFile
                 }

when it encountered a filename starting with . it would have ended in an infinite loop cause FindNextFile never got called.

@JayFoxRox
Copy link
Owner Author

Thanks for the report. I'll eventually fix it (if nobody else does it before this file hits upstream - which hopefully happens). For now I have too many other projects to care for HODE. Our Xbox toolchain also needs bugs fixed before this is worth more of my time.

I believe your code still wouldn't run the statement at the end of the while loop?
I'm not sure about semantics in C, but would it really do that step for a continue?

I'm more tempted to rewrite this function with more nesting or a goto.

@JayFoxRox
Copy link
Owner Author

Demon27248 wrote:
For the record, audio was present. By "broken", I meant it was out of sync with what was happening on screen (and there might have been sound effects missing but I wasn't sure). https://files.catbox.moe/j3jsqb.mp4

I'm confused about which revisions you used. Might have had a bad combination of submodules.

Video delay

For now, I assume that the video-capture device added the delay. It's highly unusual to have video lagging behind audio. The game has no room in memory to buffer video frames, and audio is only started when the animation also plays. If there was a latency issue we'd expect the audio to be lagging behind the video.

Crash near end

The early crash at the end of the video is unfortunate. I never had a crash this early. It might be something related to specific Xbox revisions, temperature, signal noise, uninitialized memory or something.

break;
}
}
CloseHandle(d);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug; from MSDN:

When the search handle is no longer needed, close it by using the FindClose function, not CloseHandle.

CC @tuxuser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants