From 3ce93636d868ee99425284a22faa340b2fec0f5d Mon Sep 17 00:00:00 2001 From: michaelangel007 Date: Mon, 29 Dec 2014 09:05:49 -0800 Subject: [PATCH] Fix segfault --- src/StdAfx.h | 5 +++++ src/main.cpp | 41 +++++++++++++++++++++++++++++------------ src/wsvideo.cpp | 3 ++- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/StdAfx.h b/src/StdAfx.h index aaa289f..a43cb87 100644 --- a/src/StdAfx.h +++ b/src/StdAfx.h @@ -1,3 +1,8 @@ +#ifdef _MSC_VER + // Shut compiler up about strcpy() fopen() not being safe + #define _CRT_SECURE_NO_WARNINGS 1 +#endif // _MSC_VER + #include #include #include // uint8_t diff --git a/src/main.cpp b/src/main.cpp index dd3013c..2025d9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,11 @@ /* Copyleft {C} 2014 Michael Pohoreski License: GPL2 + +MSVC2010 Debug: + Configuration Properties, Debugging + Command Arguments: hgr/archon.hgr2 + Working Directory: $(ProjectDir) */ // Includes _______________________________________________________________ @@ -33,6 +38,9 @@ TARGA_HEADER_SIZE = 0x12 }; +#ifdef _MSC_VER + #pragma pack(push,1) +#endif // _MSC_VER struct TargaHeader_t { // Addr Bytes uint8_t nIdBytes ; // 00 01 size of ID field that follows 18 byte header (0 usually) @@ -53,6 +61,9 @@ // pixel data... uint8_t aPixelData[1] ; // 12 ?? variable length RGB data }; +#ifdef _MSC_VER + #pragma pack(pop) +#endif // _MSC_VER enum VideoFlag_e { @@ -98,15 +109,20 @@ printf( "Dst: '%s'\n", pDstFileName ); FILE *pSrcFile = fopen( pSrcFileName, "rb" ); FILE *pDstFile = fopen( pDstFileName, "w+b" ); - size_t nPageHGR = 0x2000; - fread( gaMemMain + nPageHGR, _8K, 1, pSrcFile ); + if( pSrcFile ) + { + size_t nPageHGR = 0x2000; + fread( gaMemMain + nPageHGR, _8K, 1, pSrcFile ); - TargaHeader_t tga; - hgr2rgb(); - rgb2tga( &tga ); + TargaHeader_t tga; + hgr2rgb(); + rgb2tga( &tga ); - fwrite( (void*)&tga , TARGA_HEADER_SIZE , 1, pDstFile ); - fwrite( (void*)&gaFrameBuffer, sizeof( gaFrameBuffer ), 1, pDstFile ); + fwrite( (void*)&tga , TARGA_HEADER_SIZE , 1, pDstFile ); + fwrite( (void*)&gaFrameBuffer, sizeof( gaFrameBuffer ), 1, pDstFile ); + } + else + printf( "ERROR: Couldn't open source file: '%s'\n", pSrcFileName ); fclose( pDstFile ); fclose( pSrcFile ); @@ -190,6 +206,12 @@ printf( "Dst: '%s'\n", pDstFileName ); int main( const int nArg, const char *aArg[] ) { init_mem(); + + // From: Video.cpp wsVideoCreateDIBSection() + uint8_t *g_pFramebufferbits = (uint8_t*) &gaFrameBuffer[0][0]; + for (int y = 0; y < 384; y++) + wsLines[y] = g_pFramebufferbits + 4 * FRAMEBUFFER_W * ((FRAMEBUFFER_H - 1) - y - 18) + 80; + wsVideoInitModel( 1 ); // Apple //e wsVideoInit(); wsVideoStyle( 1, 1 ); @@ -197,11 +219,6 @@ printf( "Dst: '%s'\n", pDstFileName ); g_bVideoMode = VF_HIRES; init_videomode(); - // From: Video.cpp wsVideoCreateDIBSection() - uint8_t *g_pFramebufferbits = (uint8_t*) &gaFrameBuffer[0][0]; - for (int y = 0; y < 384; y++) - wsLines[y] = g_pFramebufferbits + 4 * FRAMEBUFFER_W * ((FRAMEBUFFER_H - 1) - y - 18) + 80; - if( nArg > 1 ) { convert( aArg[1] ); diff --git a/src/wsvideo.cpp b/src/wsvideo.cpp index e931233..02c2bf0 100644 --- a/src/wsvideo.cpp +++ b/src/wsvideo.cpp @@ -77,7 +77,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static unsigned g_nVideoClockVert = 0; // 9-bit: VC VB VA V5 V4 V3 V2 V1 V0 = 0 .. 262 static unsigned g_nVideoClockHorz = 0; // 6-bit: H5 H4 H3 H2 H1 H0 = 0 .. 64, 25 >= visible - unsigned g_aHorzClockMemAddress[VIDEO_SCANNER_MAX_HORZ]; + uint16_t g_aHorzClockMemAddress[VIDEO_SCANNER_MAX_HORZ]; // MSVC2010 unsigned char * wsLines[384]; unsigned wsFlashidx = 0; @@ -705,6 +705,7 @@ int wsVideoIsVbl () unsigned char wsVideoByte (unsigned long cycle) { + (void)cycle; // MSVC2010 unsigned char * mem; mem = MemGetMainPtr(g_aHorzClockMemAddress[ g_nVideoClockHorz ]); return mem[0];