From fea588be88446a8d0d739efc4c6a4be2ad9916f8 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Tue, 18 Jun 2019 23:55:01 +0100 Subject: [PATCH] riscos: Improve error reporting --- src/joystick/riscos/SDL_sysjoystick.c | 4 +++- src/video/riscos/SDL_riscosFullScreenVideo.c | 14 +++++++------- src/video/riscos/SDL_riscosmouse.c | 8 ++++---- src/video/riscos/SDL_riscossprite.c | 10 ++++++++-- src/video/riscos/SDL_riscostask.c | 13 +++++++------ src/video/riscos/SDL_riscosvideo.c | 1 - src/video/riscos/SDL_wimpvideo.c | 13 +++++++------ 7 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/joystick/riscos/SDL_sysjoystick.c b/src/joystick/riscos/SDL_sysjoystick.c index db39ce49d..b4430ed88 100644 --- a/src/joystick/riscos/SDL_sysjoystick.c +++ b/src/joystick/riscos/SDL_sysjoystick.c @@ -89,8 +89,10 @@ const char *SDL_SYS_JoystickName(int index) */ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) { - if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) + if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) { + SDL_OutOfMemory(); return -1; + } /* Don't know how to get exact count of buttons so assume max of 4 for now */ joystick->nbuttons=4; diff --git a/src/video/riscos/SDL_riscosFullScreenVideo.c b/src/video/riscos/SDL_riscosFullScreenVideo.c index b497ec4bb..6d09214bf 100644 --- a/src/video/riscos/SDL_riscosFullScreenVideo.c +++ b/src/video/riscos/SDL_riscosFullScreenVideo.c @@ -88,7 +88,6 @@ SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, const RISCOS_SDL_PixelFormat *fmt = FULLSCREEN_SetMode(width, height, bpp); if (fmt == NULL) { - SDL_SetError("Couldn't set requested mode"); return (NULL); } @@ -96,8 +95,7 @@ SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, fmt->sdl_bpp, fmt->rmask, fmt->gmask, fmt->bmask, 0) ) { - RISCOS_RestoreWimpMode(); - SDL_SetError("Couldn't allocate new pixel format for requested mode"); + RISCOS_RestoreWimpMode(); return(NULL); } @@ -154,14 +152,16 @@ SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, ** This is turned on by setting the enviromental variable ** SDL$$BackBuffer >= 1 */ - if (riscos_backbuffer == 3) + if (riscos_backbuffer == 3) { this->hidden->bank[0] = WIMP_CreateBuffer(width, height, &fmt->ro); - else + } else { this->hidden->bank[0] = SDL_malloc(height * current->pitch); + if (this->hidden->bank[0] == 0) + SDL_OutOfMemory(); + } if (this->hidden->bank[0] == 0) { - RISCOS_RestoreWimpMode(); - SDL_SetError("Couldnt allocate memory for back buffer"); + RISCOS_RestoreWimpMode(); return (NULL); } /* Surface updated in programs is now a software surface */ diff --git a/src/video/riscos/SDL_riscosmouse.c b/src/video/riscos/SDL_riscosmouse.c index 8b3b74a88..1bdfb1161 100644 --- a/src/video/riscos/SDL_riscosmouse.c +++ b/src/video/riscos/SDL_riscosmouse.c @@ -69,14 +69,14 @@ WMcursor *RISCOS_CreateWMCursor(_THIS, /* Check to make sure the cursor size is okay */ if ( (w > 32) || (h > 32) ) { - SDL_SetError("Only with width and height <= 32 pixels are allowed"); + SDL_SetError("Only cursors with width and height <= 32 pixels are allowed"); return(NULL); } /* Allocate the cursor */ cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); if ( cursor == NULL ) { - SDL_SetError("Out of memory"); + SDL_OutOfMemory(); return(NULL); } @@ -85,7 +85,7 @@ WMcursor *RISCOS_CreateWMCursor(_THIS, if (cursor_data == NULL) { SDL_free(cursor); - SDL_SetError("Out of memory"); + SDL_OutOfMemory(); return(NULL); } @@ -160,7 +160,7 @@ int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor) if (_kernel_osword(21, (int *)cursor_def) != 0) { - SDL_SetError("RISCOS couldn't create the cursor to show"); + SDL_SetError("RISC OS couldn't create the cursor to show"); return(0); } defined_cursor = cursor; diff --git a/src/video/riscos/SDL_riscossprite.c b/src/video/riscos/SDL_riscossprite.c index 5930e81fd..2fe88b3c3 100644 --- a/src/video/riscos/SDL_riscossprite.c +++ b/src/video/riscos/SDL_riscossprite.c @@ -96,6 +96,7 @@ unsigned char *WIMP_CreateBuffer(int width, int height, const RISCOS_PixelFormat char sprite_name[12] = "display"; unsigned char *buffer; _kernel_swi_regs regs; + _kernel_oserror *error; int bytesPerPixel = 1 << (format->log2bpp-3); int bytesPerRow; int offsetToSpriteData = 60; @@ -114,7 +115,10 @@ unsigned char *WIMP_CreateBuffer(int width, int height, const RISCOS_PixelFormat size = bytesPerRow * height; buffer = SDL_malloc( (size_t) size + offsetToSpriteData ); - if (!buffer) return NULL; + if (!buffer) { + SDL_OutOfMemory(); + return NULL; + } /* Initialise a sprite area */ @@ -132,7 +136,8 @@ unsigned char *WIMP_CreateBuffer(int width, int height, const RISCOS_PixelFormat regs.r[4] = width; regs.r[5] = height; regs.r[6] = format->sprite_mode_word; - if (_kernel_swi(OS_SpriteOp, ®s, ®s) == NULL) + error = _kernel_swi(OS_SpriteOp, ®s, ®s); + if (error == NULL) { if (format->log2bpp == 3) { @@ -162,6 +167,7 @@ unsigned char *WIMP_CreateBuffer(int width, int height, const RISCOS_PixelFormat } } else { + SDL_SetError("Unable to create sprite: %s (%i)", error->errmess, error->errnum); SDL_free(buffer); buffer = NULL; } diff --git a/src/video/riscos/SDL_riscostask.c b/src/video/riscos/SDL_riscostask.c index 04f58fc5a..7f1ba24c4 100644 --- a/src/video/riscos/SDL_riscostask.c +++ b/src/video/riscos/SDL_riscostask.c @@ -58,7 +58,7 @@ static int stored_mode = -1; /* -1 when in desktop, mode number or pointer when /* Local function */ -static int RISCOS_GetTaskName(char *task_name, size_t maxlen); +static void RISCOS_GetTaskName(char *task_name, size_t maxlen); /* Uncomment next line to copy mode changes/restores to stderr */ /* #define DUMP_MODE */ @@ -94,9 +94,10 @@ int RISCOS_InitTask() { char task_name[32]; _kernel_swi_regs regs; + _kernel_oserror *error; int messages[4]; - if (RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)) == 0) return 0; + RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)); messages[0] = 9; /* Palette changed */ messages[1] = 0x400c1; /* Mode changed */ @@ -108,7 +109,8 @@ int RISCOS_InitTask() regs.r[2] = (unsigned int)task_name; regs.r[3] = (unsigned int)messages; - if (_kernel_swi(Wimp_Initialise, ®s, ®s) == 0) + error = _kernel_swi(Wimp_Initialise, ®s, ®s); + if (error == 0) { wimp_version = regs.r[0]; task_handle = regs.r[1]; @@ -119,6 +121,7 @@ int RISCOS_InitTask() main_thread = pthread_self(); #endif + SDL_SetError("Unable to start task: %s (%i)", error->errmess, error->errnum); return 0; } @@ -182,7 +185,7 @@ void RISCOS_ExitTask() ***************************************************************************/ -int RISCOS_GetTaskName(char *task_name, size_t maxlen) +void RISCOS_GetTaskName(char *task_name, size_t maxlen) { _kernel_swi_regs regs; @@ -262,8 +265,6 @@ int RISCOS_GetTaskName(char *task_name, size_t maxlen) } if (task_name[0] == 0) SDL_strlcpy(task_name, "SDL Task", maxlen); - - return 1; } /***************************************************************** diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c index 14a45799d..bb6b8723a 100644 --- a/src/video/riscos/SDL_riscosvideo.c +++ b/src/video/riscos/SDL_riscosvideo.c @@ -201,7 +201,6 @@ int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat) if (RISCOS_InitTask() == 0) { - SDL_SetError("Unable to start task"); return 0; } diff --git a/src/video/riscos/SDL_wimpvideo.c b/src/video/riscos/SDL_wimpvideo.c index dba7ea3d4..246d736b4 100644 --- a/src/video/riscos/SDL_wimpvideo.c +++ b/src/video/riscos/SDL_wimpvideo.c @@ -72,7 +72,7 @@ SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, fmt = WIMP_FindSupportedSpriteFormat(bpp); if (fmt == NULL) { - SDL_SetError("Pixel depth not supported"); + SDL_SetError("Pixel depth %d not supported", bpp); return NULL; } } @@ -88,7 +88,6 @@ SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, fmt->sdl_bpp, fmt->rmask, fmt->gmask, fmt->bmask, 0) ) { - SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } @@ -100,7 +99,6 @@ SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, buffer = WIMP_CreateBuffer(width, height, &fmt->ro); if (buffer == NULL) { - SDL_SetError("Couldn't create sprite for video memory"); return (NULL); } @@ -133,7 +131,6 @@ SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, if (WIMP_SetupWindow(this, current) == 0) { - SDL_SetError("Unable to create window to display surface"); return NULL; } @@ -213,6 +210,7 @@ void WIMP_SetDeviceMode(_THIS) unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface) { _kernel_swi_regs regs; + _kernel_oserror *error; int window_data[23]; int *window_block = window_data+1; int x = ((this->hidden->screen_width << this->hidden->xeig) - (surface->w << 1)) / 2; @@ -255,7 +253,8 @@ unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface) regs.r[1] = (unsigned int)(window_block); /* Create the window */ - if (_kernel_swi(Wimp_CreateWindow, ®s, ®s) == NULL) + error = _kernel_swi(Wimp_CreateWindow, ®s, ®s); + if (error == NULL) { this->hidden->window_handle = window_data[0] = regs.r[0]; @@ -268,8 +267,10 @@ unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface) { WIMP_DeleteWindow(this); } + } else { + SDL_SetError("Unable to create window: %s (%i)", error->errmess, error->errnum); } - + return this->hidden->window_handle; }