From fbaf46548f0a4716495b2c8a9e1fad4828ea05c1 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 19 Feb 2019 00:50:16 +0000 Subject: [PATCH] Made Back.cpp about as ASM-accurate as I can make it ...without removing the widescreen stuff, at least. --- src/Back.cpp | 61 +++++++++++++++++++++++++++------------------------- src/Back.h | 4 +++- src/Draw.cpp | 32 +++++++++++++-------------- src/Draw.h | 12 +++++------ 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/Back.cpp b/src/Back.cpp index b60586cd..c6df1c6b 100644 --- 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,14 +27,14 @@ bool InitBack(char *fName, int type) 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 if (fgetc(fp) != 'B' || fgetc(fp) != 'M') { fclose(fp); - return false; + return FALSE; } fseek(fp, 18, SEEK_SET); @@ -53,7 +53,7 @@ bool InitBack(char *fName, int type) // 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,22 +65,25 @@ bool InitBack(char *fName, int type) //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; - } - else if (gBack.type >= 5 && gBack.type <= 7) - { - ++gBack.fx; - gBack.fx %= 640; + case 5: + gBack.fx += 0xC00; + break; + + case 6: + case 7: + ++gBack.fx; + gBack.fx %= 640; + break; } } @@ -195,35 +198,35 @@ void PutBack(int fx, int fy) 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 diff --git a/src/Back.h b/src/Back.h index 62fd9102..469c1c36 100644 --- 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 @@ struct BACK 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); diff --git a/src/Draw.cpp b/src/Draw.cpp index 283ce3d7..5df2c57a 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -78,7 +78,7 @@ BOOL Flip_SystemTask() 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 @@ bool StartDirectDraw(int lMagnification, int lColourDepth) } - return true; + return TRUE; } void EndDirectDraw() @@ -144,9 +144,9 @@ void ReleaseSurface(int s) } } -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 @@ bool MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no) else { surf[surf_no].in_use = true; - success = true; + success = TRUE; } } } @@ -303,7 +303,7 @@ static bool LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, bool create_surface) 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 @@ static bool LoadBitmap_File(const char *name, Surface_Ids surf_no, bool create_s { 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 @@ static bool LoadBitmap_File(const char *name, Surface_Ids surf_no, bool create_s { 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 @@ static bool LoadBitmap_Resource(const char *res, Surface_Ids surf_no, bool creat { 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); } diff --git a/src/Draw.h b/src/Draw.h index 666e1df1..d5ce2bd8 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -51,14 +51,14 @@ struct SURFACE; 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);