shithub: cstory

Download patch

ref: fbaf46548f0a4716495b2c8a9e1fad4828ea05c1
parent: e1e49a4dcc80a165cc9ed6fa0a787aa5121b70b1
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Feb 18 19:50:16 EST 2019

Made Back.cpp about as ASM-accurate as I can make it

...without removing the widescreen stuff, at least.

--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -15,7 +15,7 @@
 BACK gBack;
 int gWaterY;
 
-bool InitBack(char *fName, int type)
+BOOL InitBack(const char *fName, int type)
 {
 	//Get width and height
 	char path[PATH_LENGTH];
@@ -27,7 +27,7 @@
 		sprintf(path, "%s/%s.bmp", gDataPath, fName);
 		fp = fopen(path, "rb");
 		if (fp == NULL)
-			return false;
+			return FALSE;
 	}
 
 #ifdef FIX_BUGS	// TODO: Maybe we need a 'BETTER_PORTABILITY' flag
@@ -34,7 +34,7 @@
 	if (fgetc(fp) != 'B' || fgetc(fp) != 'M')
 	{
 		fclose(fp);
-		return false;
+		return FALSE;
 	}
 
 	fseek(fp, 18, SEEK_SET);
@@ -53,7 +53,7 @@
 
 	// Check if this is a valid bitmap file
 	if (bmp_header_buffer[0] != 0x4D42)	// 'MB' (we use hex to prevent a compiler warning)
-		return false;	// The original game forgets to close fp
+		return FALSE;	// The original game forgets to close fp
 
 	fread(bmp_header_buffer2, 40, 1, fp);
 	fclose(fp);
@@ -65,23 +65,26 @@
 	//Set background stuff and load texture
 	gBack.flag = 1;
 	if (!ReloadBitmap_File(fName, SURFACE_ID_LEVEL_BACKGROUND))
-		return false;
+		return FALSE;
 	gBack.type = type;
 	gWaterY = 0x1E0000;
-	return true;
+	return TRUE;
 }
 
 void ActBack()
 {
-	if (gBack.type == 5)
+	switch (gBack.type)
 	{
-		gBack.fx += 0xC00;
+		case 5:
+			gBack.fx += 0xC00;
+			break;
+
+		case 6:
+		case 7:
+			++gBack.fx;
+			gBack.fx %= 640;
+			break;
 	}
-	else if (gBack.type >= 5 && gBack.type <= 7)
-	{
-		++gBack.fx;
-		gBack.fx %= 640;
-	}
 }
 
 void PutBack(int fx, int fy)
@@ -195,35 +198,35 @@
 
 void PutFront(int fx, int fy)
 {
-	RECT rcWater[2];
-	rcWater[0] = {0, 0, 32, 16};
-	rcWater[1] = {0, 16, 32, 48};
+	RECT rcWater[2] = {{0, 0, 32, 16}, {0, 16, 32, 48}};
 
-	if (gBack.type == 3)
+	switch (gBack.type)
 	{
-		int x_1 = fx / 0x4000;
-		int x_2 = x_1 + (((WINDOW_WIDTH + 31) >> 5) + 1);
-		int y_1 = 0;
-		int y_2 = y_1 + 32;
-		
-		for (int y = y_1; y < y_2; y++)
-		{
-			int ypos = (y << 14) / 0x200 - fy / 0x200 + gWaterY / 0x200;
+		case 3:
+			int x_1 = fx / 0x4000;
+			int x_2 = x_1 + (((WINDOW_WIDTH + 31) >> 5) + 1);
+			int y_1 = 0;
+			int y_2 = y_1 + 32;
 			
-			if (ypos >= -32)
+			for (int y = y_1; y < y_2; y++)
 			{
+				int ypos = (y * 0x20 * 0x200) / 0x200 - fy / 0x200 + gWaterY / 0x200;
+				
+				if (ypos < -32)
+					break;
+
 				if (ypos > WINDOW_HEIGHT)
 					break;
-				
+					
 				for (int x = x_1; x < x_2; x++)
 				{
-					int xpos = (x << 14) / 0x200 - fx / 0x200;
+					int xpos = (x * 0x20 * 0x200) / 0x200 - fx / 0x200;
 					PutBitmap3(&grcGame, xpos, ypos, &rcWater[1], SURFACE_ID_LEVEL_BACKGROUND);
 					if (!y)
 						PutBitmap3(&grcGame, xpos, ypos, rcWater, SURFACE_ID_LEVEL_BACKGROUND);
 				}
 			}
-		}
+
 	}
 	
 	//Draw black bars
--- a/src/Back.h
+++ b/src/Back.h
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "WindowsWrapper.h"
+
 struct BACK
 {
 	int flag;
@@ -14,7 +16,7 @@
 extern BACK gBack;
 extern int gWaterY;
 
-bool InitBack(char *fName, int type);
+BOOL InitBack(const char *fName, int type);
 void ActBack();
 void PutBack(int fx, int fy);
 void PutFront(int fx, int fy);
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -78,7 +78,7 @@
 	return TRUE;
 }
 
-bool StartDirectDraw(int lMagnification, int lColourDepth)
+BOOL StartDirectDraw(int lMagnification, int lColourDepth)
 {
 	//Initialize rendering
 	SDL_InitSubSystem(SDL_INIT_VIDEO);
@@ -107,7 +107,7 @@
 		
 	}
 	
-	return true;
+	return TRUE;
 }
 
 void EndDirectDraw()
@@ -144,9 +144,9 @@
 	}
 }
 
-bool MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no)
+BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no)
 {
-	bool success = false;
+	BOOL success = FALSE;
 
 #ifdef FIX_BUGS
 	if (surf_no >= SURFACE_ID_MAX)
@@ -184,7 +184,7 @@
 				else
 				{
 					surf[surf_no].in_use = true;
-					success = true;
+					success = TRUE;
 				}
 			}
 		}
@@ -303,7 +303,7 @@
 	return success;
 }
 
-static bool LoadBitmap_File(const char *name, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap_File(const char *name, Surface_Ids surf_no, bool create_surface)
 {
 	char path[PATH_LENGTH];
 	SDL_RWops *fp;
@@ -322,7 +322,7 @@
 		{
 			printf("Loading surface (as .pbm) from %s for surface id %d\n", path, surf_no);
 			if (LoadBitmap(fp, surf_no, create_surface))
-				return true;
+				return TRUE;
 		}
 	}
 	
@@ -333,14 +333,14 @@
 	{
 		printf("Loading surface (as .bmp) from %s for surface id %d\n", path, surf_no);
 		if (LoadBitmap(fp, surf_no, create_surface))
-			return true;
+			return TRUE;
 	}
 	
 	printf("Failed to open file %s\n", name);
-	return false;
+	return FALSE;
 }
 
-static bool LoadBitmap_Resource(const char *res, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap_Resource(const char *res, Surface_Ids surf_no, bool create_surface)
 {
 	SDL_RWops *fp = FindResource(res);
 	
@@ -348,29 +348,29 @@
 	{
 		printf("Loading surface from resource %s for surface id %d\n", res, surf_no);
 		if (LoadBitmap(fp, surf_no, create_surface))
-			return true;
+			return TRUE;
 	}
 	
 	printf("Failed to open resource %s\n", res);
-	return false;
+	return FALSE;
 }
 
-bool MakeSurface_File(const char *name, Surface_Ids surf_no)
+BOOL MakeSurface_File(const char *name, Surface_Ids surf_no)
 {
 	return LoadBitmap_File(name, surf_no, true);
 }
 
-bool MakeSurface_Resource(const char *res, Surface_Ids surf_no)
+BOOL MakeSurface_Resource(const char *res, Surface_Ids surf_no)
 {
 	return LoadBitmap_Resource(res, surf_no, true);
 }
 
-bool ReloadBitmap_File(const char *name, Surface_Ids surf_no)
+BOOL ReloadBitmap_File(const char *name, Surface_Ids surf_no)
 {
 	return LoadBitmap_File(name, surf_no, false);
 }
 
-bool ReloadBitmap_Resource(const char *res, Surface_Ids surf_no)
+BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no)
 {
 	return LoadBitmap_Resource(res, surf_no, false);
 }
--- a/src/Draw.h
+++ b/src/Draw.h
@@ -51,14 +51,14 @@
 extern SURFACE surf[SURFACE_ID_MAX];
 
 BOOL Flip_SystemTask();
-bool StartDirectDraw(int lMagnification, int lColourDepth);
+BOOL StartDirectDraw(int lMagnification, int lColourDepth);
 void EndDirectDraw();
 void ReleaseSurface(int s);
-bool MakeSurface_File(const char *name, Surface_Ids surf_no);
-bool MakeSurface_Resource(const char *res, Surface_Ids surf_no);
-bool ReloadBitmap_File(const char *name, Surface_Ids surf_no);
-bool ReloadBitmap_Resource(const char *res, Surface_Ids surf_no);
-bool MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no);
+BOOL MakeSurface_File(const char *name, Surface_Ids surf_no);
+BOOL MakeSurface_Resource(const char *res, Surface_Ids surf_no);
+BOOL ReloadBitmap_File(const char *name, Surface_Ids surf_no);
+BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no);
+BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no);
 void BackupSurface(Surface_Ids surf_no, RECT *rect);
 void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no);
 void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no);