From cd76e114c0ba020f86d17aeb4eb761625d926e01 Mon Sep 17 00:00:00 2001 From: dwsJason Date: Sat, 4 Aug 2018 20:11:49 -0400 Subject: [PATCH] Allocate Video Buffers from the System, and check for errors while doing so --- include/system.h | 2 +- src/system.c | 10 ++++++++ src/sysvid.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ src/xrick.c | 44 +++---------------------------- 4 files changed, 81 insertions(+), 42 deletions(-) diff --git a/include/system.h b/include/system.h index f6b8398..3ae1f5d 100644 --- a/include/system.h +++ b/include/system.h @@ -99,7 +99,7 @@ extern void sysvid_zoom(S8); extern void sysvid_toggleFullscreen(void); extern void sysvid_setGamePalette(void); extern void sysvid_setPalette(img_color_t *, U16); - +extern void sysvid_wait_vblank(); /* * events section */ diff --git a/src/system.c b/src/system.c index 3caed3e..bba5bc5 100644 --- a/src/system.c +++ b/src/system.c @@ -100,6 +100,14 @@ sys_gettime(void) void sys_sleep(int s) { +#ifdef IIGS + // on GS we're going to work in ms, also we don't sleep, we just wait + while (s > 0) + { + sysvid_wait_vblank(); + s -= 16; // Abouy 1/60th of a second + } +#endif #ifndef IIGS SDL_Delay(s); #endif @@ -121,8 +129,10 @@ sys_init(int argc, char **argv) syssnd_init(); #endif atexit(sys_shutdown); +#ifndef IIGS signal(SIGINT, exit); signal(SIGTERM, exit); +#endif } /* diff --git a/src/sysvid.c b/src/sysvid.c index e561bcc..19f663f 100644 --- a/src/sysvid.c +++ b/src/sysvid.c @@ -26,6 +26,13 @@ #include "img.h" #include "debug.h" +#ifdef IIGS +#include +#include +#include +#include +#endif + #ifdef __MSVC__ #include /* memset */ #endif @@ -190,6 +197,48 @@ sysvid_chkvm(void) void sysvid_init(void) { +#ifdef IIGS + handle hndl; // "generic memory handle" + +// PushLong #0 ;/* Ask Shadowing Screen ($8000 bytes from $01/2000)*/ +// PushLong #$8000 +// PushWord myID +// PushWord #%11000000_00000011 +// PushLong #$012000 +// _NewHandle +// PLA +// PLA + + // Allocate Bank 01 memory + 4K before and after (25 lines pre flow) + // $012000-$019BFF pixel data + // $019D00-$019DC7 SCB data + // $019E00-$019FFF Clut data + // $900 bytes afer, (14 lines buffer on the bottom, which will wreck SCB+CLUT + // + printf("Allocate Bank $01 memory\n"); + hndl = NewHandle(0x9600, userid(), 0xC003, (pointer) 0x011000); + if (toolerror()) + { + printf("Unable to allocate backpage at 0x012000\n"); + printf("Game can't run\n"); + sys_sleep(5000); // Wait 5 seconds + exit(1); + + } + printf("SUCCESS\n"); + + // Allocate Bank E1 memory - Actual Video memory + printf("Allocate Bank $E1 memory\n"); + hndl = NewHandle(0x8000, userid(), 0xC003, (pointer) 0xE12000); + if (toolerror()) + { + printf("Unable to allocate display buffer at 0xE12000\n"); + printf("Game can't run\n"); + sys_sleep(5000); // Wait 5 seconds + exit(1); + } + printf("SUCCESS\n"); +#endif #ifndef IIGS SDL_Surface *s; U8 *mask, tpix; @@ -405,6 +454,24 @@ sysvid_toggleFullscreen(void) #endif } +void sysvid_wait_vblank() +{ +#ifdef IIGS + volatile const S8* VSTATUS = (S8*) 0xC019; + + // While already in vblank wait + while ((*VSTATUS & 0x80) == 0) + { + // Wait for VBLANK to END + } + while ((*VSTATUS & 0x80) != 0) + { + // Wait for VBLANK to BEGIN + } +#endif +} + + /* eof */ diff --git a/src/xrick.c b/src/xrick.c index 821f8dd..1edf053 100644 --- a/src/xrick.c +++ b/src/xrick.c @@ -18,13 +18,9 @@ #include #endif -//extern void waitkey(); -//extern void fbuffer(); extern char splash_lz4; - -char *VIDEO = (char*)0xE1C029; - +volatile char *VIDEO = (char*)0xC029; extern int LZ4_Unpack(char* pDest, char* pPackedSource); /* @@ -33,48 +29,14 @@ extern int LZ4_Unpack(char* pDest, char* pPackedSource); int main(int argc, char *argv[]) { - //char *pChar = &testtext; - printf("Hello from xrick IIgs\n"); - printf("Unpacking Splash!"); + printf("Unpacking Splash!\n"); LZ4_Unpack((char*)(0xE12000), &splash_lz4); - //while (pChar[0]) - //{ - // pChar[0]|=0x80; - // pChar++; - //} - -// printf("%s\n", &testtext); - // SHR ON - *VIDEO|=0xC0; - - -// waitkey(); -// fbuffer(); - - #if 0 -handle hndl; /* "generic" handle */ -/* Create new member array of minimum size. */ -hndl = NewHandle(1024L, myID, 0xC010, NULL); -if (toolerror()) { - HandleError(toolerror(), memryErr); - return FALSE; - } - -// PushLong #0 ;/* Ask Shadowing Screen ($8000 bytes from $01/2000)*/ -// PushLong #$8000 -// PushWord myID -// PushWord #%11000000_00000011 -// PushLong #$012000 -// _NewHandle -// PLA -// PLA - #endif - +// *VIDEO|=0xC0; sys_init(argc, argv); if (sysarg_args_data)