Skip to content

Commit

Permalink
riscos: Improve error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 committed Jun 18, 2019
1 parent 32c57bf commit fea588b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
4 changes: 3 additions & 1 deletion src/joystick/riscos/SDL_sysjoystick.c
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/video/riscos/SDL_riscosFullScreenVideo.c
Expand Up @@ -88,16 +88,14 @@ 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);
}

/* printf("Setting mode %dx%d\n", width, height); */

/* 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);
}

Expand Down Expand Up @@ -154,14 +152,16 @@ SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current,
** This is turned on by setting the enviromental variable
** SDL$<name>$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 */
Expand Down
8 changes: 4 additions & 4 deletions src/video/riscos/SDL_riscosmouse.c
Expand Up @@ -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);
}

Expand All @@ -85,7 +85,7 @@ WMcursor *RISCOS_CreateWMCursor(_THIS,
if (cursor_data == NULL)
{
SDL_free(cursor);
SDL_SetError("Out of memory");
SDL_OutOfMemory();
return(NULL);
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/video/riscos/SDL_riscossprite.c
Expand Up @@ -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;
Expand All @@ -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 */

Expand All @@ -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, &regs, &regs) == NULL)
error = _kernel_swi(OS_SpriteOp, &regs, &regs);
if (error == NULL)
{
if (format->log2bpp == 3)
{
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 7 additions & 6 deletions src/video/riscos/SDL_riscostask.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -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, &regs, &regs) == 0)
error = _kernel_swi(Wimp_Initialise, &regs, &regs);
if (error == 0)
{
wimp_version = regs.r[0];
task_handle = regs.r[1];
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/*****************************************************************
Expand Down
1 change: 0 additions & 1 deletion src/video/riscos/SDL_riscosvideo.c
Expand Up @@ -201,7 +201,6 @@ int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat)

if (RISCOS_InitTask() == 0)
{
SDL_SetError("Unable to start task");
return 0;
}

Expand Down
13 changes: 7 additions & 6 deletions src/video/riscos/SDL_wimpvideo.c
Expand Up @@ -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;
}
}
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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, &regs, &regs) == NULL)
error = _kernel_swi(Wimp_CreateWindow, &regs, &regs);
if (error == NULL)
{
this->hidden->window_handle = window_data[0] = regs.r[0];

Expand All @@ -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;
}

Expand Down

0 comments on commit fea588b

Please sign in to comment.