Skip to content

Commit

Permalink
0.2.0-alpha
Browse files Browse the repository at this point in the history
- Switch to 64-bit executable:
	- it allows to add support for modern (64-bit) emulators, without relying on WOW64 API,
	- add support for `BizHawk 2.3.x` emulator
- Drop ***Unicode*** support. Not needed in practice,
- Replace `sprintf` with the safe version: `sprintf_s`,
- Introduce unified custom type system, inspired by the ***Rust*** data-types:
	`i8, u8, i16, u16, i32, u32, i64, u64, usize, f32, f64`,
- Move types and structs definitions into a separate header file `vst_types.h`,
- Move global varibales into a separate header file `vst_init.h`,
- Update the file storing the current play-time only if needed, instead of writing to it on every loop iteration,
- Display proper location message while the game is loading
- Tweak/refine some structs: `location`, `player_stats`, `item_info`,
- Replace custom `NELEMS` macro with existing `_countof` macro,
- Fix indexing bug for the `AccessoriesList` array: first element is at index 97 instead of 0 or 1.
  • Loading branch information
tomasz-rozanski committed Nov 12, 2019
1 parent fc521e5 commit b34a2d4
Show file tree
Hide file tree
Showing 18 changed files with 1,658 additions and 1,296 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

# Visual Studio Stuff
*.sln
*.filters
*.user
*.vcxproj

# Files built by Visual Studio
*_i.c
Expand Down Expand Up @@ -99,5 +102,9 @@ debug/
shell.bat
setup.bat
log.bat
sub.bat
build.bat

# Misc
changes.md
TODO.md
changes.txt
3 changes: 2 additions & 1 deletion build-nodebug.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@echo off
cl main.c /Fe: vstrack-release /nologo /link user32.lib psapi.lib
cl main.c /Fe: vstrack-release /nologo /link user32.lib psapi.lib Wtsapi32.lib Advapi32.lib

2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
cl main.c /Fe: vstrack /nologo /Zi /link user32.lib psapi.lib
cl main.c /Fe: vstrack /nologo /Zi /link user32.lib psapi.lib Wtsapi32.lib Advapi32.lib
38 changes: 19 additions & 19 deletions includes/vst_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
COORD coordScreen, coord;
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hStdout, hStdin, hStderr, hBackBuffer;
SHORT conSizeX, conSizeY;
SHORT conMinSizeX, conMinSizeY;
SHORT conMaxSizeX, conMaxSizeY;
i16 conSizeX, conSizeY;
i16 conMinSizeX, conMinSizeY;
i16 conMaxSizeX, conMaxSizeY;
CONSOLE_CURSOR_INFO cciOldCursor, cciNewCursor;
TCHAR szBuffer[1024];
DWORD dwBytesWritten;
char szBuffer[1024];
u32 BytesWritten;

// Double-buffering structs
SMALL_RECT srctReadRect;
Expand All @@ -23,7 +23,7 @@ COORD coordLargestWindowSize;
BOOL fSuccess;

void *
AllocateBackBuffer(SHORT conMaxSizeX, SHORT conMaxSizeY)
AllocateBackBuffer(i16 conMaxSizeX, i16 conMaxSizeY)
{
void *chiBuffer =
(void *) malloc(sizeof(CHAR_INFO) * conMaxSizeX * conMaxSizeY);
Expand All @@ -46,19 +46,19 @@ SetConsoleHandles()
}

void
SetCursorPosition(HANDLE hConsole, DWORD PositionX, DWORD PositionY)
SetCursorPosition(HANDLE hConsole, u32 PositionX, u32 PositionY)
{
COORD coordPosition;

coordPosition.X = (SHORT) PositionX;
coordPosition.Y = (SHORT) PositionY;
coordPosition.X = (i16) PositionX;
coordPosition.Y = (i16) PositionY;

SetConsoleCursorPosition(hConsole, coordPosition);
}

void
GetConsoleWindowSize(HANDLE hConsole, SHORT *conSizeX, SHORT *conSizeY,
SHORT *conMaxSizeX, SHORT *conMaxSizeY)
GetConsoleWindowSize(HANDLE hConsole, i16 *conSizeX, i16 *conSizeY,
i16 *conMaxSizeX, i16 *conMaxSizeY)
{
GetConsoleScreenBufferInfo(hConsole, &csbi);

Expand Down Expand Up @@ -87,7 +87,7 @@ HideConsoleCursor(HANDLE hConsole, CONSOLE_CURSOR_INFO *cciOldCursor,
void
WriteToBackBuffer(void)
{
WriteConsole(hBackBuffer, szBuffer, lstrlen(szBuffer), &dwBytesWritten, NULL);
WriteConsole(hBackBuffer, szBuffer, strlen(szBuffer), &BytesWritten, NULL);
}

void
Expand Down Expand Up @@ -117,7 +117,7 @@ CopyFromBackBuffer()

if (!fSuccess)
{
printf("ReadConsoleOutput failed - (%d)\n", GetLastError());
fprintf(stderr, "ReadConsoleOutput failed - (%d)\n", GetLastError());
return;
}

Expand All @@ -136,7 +136,7 @@ CopyFromBackBuffer()

if (!fSuccess)
{
printf("WriteConsoleOutput failed - (%d)\n", GetLastError());
fprintf(stderr, "WriteConsoleOutput failed - (%d)\n", GetLastError());
return;
}
}
Expand All @@ -145,9 +145,9 @@ void
cls(HANDLE hConsole)
{
COORD coordScreen = { 0, 0 }; // home for the cursor
DWORD cCharsWritten;
u32 cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
u32 dwConSize;

// Get the number of character cells in the current buffer.
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
Expand Down Expand Up @@ -193,16 +193,16 @@ cls(HANDLE hConsole)
void
ClearLine()
{
sprintf(szBuffer, "%*s\r", conSizeX - 1, "");
sprintf_s(szBuffer, _countof(szBuffer), "%*s\r", conSizeX - 1, "");
WriteToBackBuffer();
}

void
WriteDebugMessage(HANDLE hConsole)
{
SetCursorPosition(hConsole, 0, conSizeY - 1);
sprintf(szBuffer, "Debug mode is %s. Press \"D\" to toggle.\n",
DEBUG ? "ON" : "OFF");
sprintf_s(szBuffer, _countof(szBuffer),
"Debug mode is %s. Press \"D\" to toggle.\n", DEBUG ? "ON" : "OFF");
WriteToBackBuffer();
}

Expand Down
13 changes: 7 additions & 6 deletions includes/vst_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
void
WriteDebugInfo(void)
{
TCHAR szBuffer[1024];
char szBuffer[1024];

processBaseAddress = GetModuleDllBase(processID, szModuleName);
sprintf(szBuffer, "processBaseAddress: 0x%08x\n", processBaseAddress);
sprintf_s(szBuffer, _countof(szBuffer), "processBaseAddress: 0x%016llx\n",
processBaseAddress);
WriteDebugLog(szBuffer);

// Maximum window dimensions
sprintf(
szBuffer, "conMaxSizeX: %i, conMaxSizeY: %i\n", conMaxSizeX, conMaxSizeY);
sprintf_s(szBuffer, _countof(szBuffer), "conMaxSizeX: %i, conMaxSizeY: %i\n",
conMaxSizeX, conMaxSizeY);
WriteDebugLog(szBuffer);

// Pointer to the back-buffer memory
sprintf(szBuffer, "chiBuffer address: 0x%08p\n", chiBuffer);
sprintf_s(
szBuffer, _countof(szBuffer), "chiBuffer address: 0x%08p\n", chiBuffer);
WriteDebugLog(szBuffer);
}

Expand Down
10 changes: 5 additions & 5 deletions includes/vst_emulation.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef _VST_EMULATION_H
#define _VST_EMULATION_H

// #define PSX_TO_EPSXE_1900 0x7F5A8660
#define PSX_TO_EPSXE_1900 0x7F9A8660
// The formula:
// PSX_TO_EMU = PSX_OFFSET - EMU_OFFSET + EMU_BASE_ADDRESS

// #define PSX_TO_EPSXE_1925 0x7F574960
#define PSX_TO_EPSXE_1900 0x7F9A8660
#define PSX_TO_EPSXE_1925 0x7F974960

// #define PSX_TO_EPSXE_2050 0x7EC4DFE0
#define PSX_TO_EPSXE_2050 0x7F57DFE0

#define PSX_TO_BIZHAWK_2300 0x7FEE2750
#define PSX_TO_BIZHAWK_2320 0x7FEE2780
#endif
Loading

0 comments on commit b34a2d4

Please sign in to comment.