libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
exception.c File Reference
#include "exception.h"
#include "../defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Data Structures

struct  exception_t
 

Macros

#define INVALID_INSTRUCTION_EXCEPTION_MESSAGE   "An invalid instruction exists in the input file."
 
#define TOO_MANY_LABELS_EXCEPTION_MESSAGE   "Too many labels are defined in the input file."
 
#define STACK_OVERFLOW_EXCEPTION_MESSAGE   "A stack overflow occurred during execution."
 
#define INVALID_ARGUMENT_EXCEPTION_MESSAGE   "An invalid instruction argument was given."
 
#define DUPLICATE_LABEL_EXCEPTION_MESSAGE   "A label was defined multiple times."
 
#define INVALID_SYMBOL_EXCEPTION_MESSAGE   "An invalid symbol exists in the input file."
 
#define MEMORY_ALLOCATION_EXCEPTION_MESSAGE   "Failed to allocate memory."
 
#define UNKNOWN_EXCEPTION_MESSAGE   "An unknown error has occurred."
 
#define TOO_MANY_SYMBOLS_EXCEPTION_MESSAGE   "Too many symbols exist in the input file."
 
#define LOAD_FILE_FAILURE_EXCEPTION_MESSAGE   "Failed to load file."
 
#define FILE_TOO_BIG_EXCEPTION_MESSAGE   "The given file is too big."
 
#define INVALID_COLOR_PALETTE_EXCEPTION_MESSAGE   "Invalid color palette."
 
#define INVALID_QUIRK_EXCEPTION_MESSAGE   "Invalid quirk."
 
#define FAILED_GRAPHICS_INITIALIZATION_EXCEPTION_MESSAGE   "Failed to initialize graphics."
 
#define INVALID_FONT_EXCEPTION_MESSAGE   "Invalid font."
 
#define INVALID_CLOCK_SPEED_EXCEPTION_MESSAGE   "Clock speed cannot be less than 1."
 
#define STACK_UNDERFLOW_EXCEPTION_MESSAGE   "Stack underflow occurred during execution."
 

Functions

void handle_exception (int code)
 

Variables

exception_t exceptions []
 
char c8_exception [BUFSIZ]
 

Detailed Description

Note
NOT EXPORTED

Stuff for handling exceptions.

Macro Definition Documentation

◆ DUPLICATE_LABEL_EXCEPTION_MESSAGE

#define DUPLICATE_LABEL_EXCEPTION_MESSAGE   "A label was defined multiple times."

◆ FAILED_GRAPHICS_INITIALIZATION_EXCEPTION_MESSAGE

#define FAILED_GRAPHICS_INITIALIZATION_EXCEPTION_MESSAGE   "Failed to initialize graphics."

◆ FILE_TOO_BIG_EXCEPTION_MESSAGE

#define FILE_TOO_BIG_EXCEPTION_MESSAGE   "The given file is too big."

◆ INVALID_ARGUMENT_EXCEPTION_MESSAGE

#define INVALID_ARGUMENT_EXCEPTION_MESSAGE   "An invalid instruction argument was given."

◆ INVALID_CLOCK_SPEED_EXCEPTION_MESSAGE

#define INVALID_CLOCK_SPEED_EXCEPTION_MESSAGE   "Clock speed cannot be less than 1."

◆ INVALID_COLOR_PALETTE_EXCEPTION_MESSAGE

#define INVALID_COLOR_PALETTE_EXCEPTION_MESSAGE   "Invalid color palette."

◆ INVALID_FONT_EXCEPTION_MESSAGE

#define INVALID_FONT_EXCEPTION_MESSAGE   "Invalid font."

◆ INVALID_INSTRUCTION_EXCEPTION_MESSAGE

#define INVALID_INSTRUCTION_EXCEPTION_MESSAGE   "An invalid instruction exists in the input file."

◆ INVALID_QUIRK_EXCEPTION_MESSAGE

#define INVALID_QUIRK_EXCEPTION_MESSAGE   "Invalid quirk."

◆ INVALID_SYMBOL_EXCEPTION_MESSAGE

#define INVALID_SYMBOL_EXCEPTION_MESSAGE   "An invalid symbol exists in the input file."

◆ LOAD_FILE_FAILURE_EXCEPTION_MESSAGE

#define LOAD_FILE_FAILURE_EXCEPTION_MESSAGE   "Failed to load file."

◆ MEMORY_ALLOCATION_EXCEPTION_MESSAGE

#define MEMORY_ALLOCATION_EXCEPTION_MESSAGE   "Failed to allocate memory."

◆ STACK_OVERFLOW_EXCEPTION_MESSAGE

#define STACK_OVERFLOW_EXCEPTION_MESSAGE   "A stack overflow occurred during execution."

◆ STACK_UNDERFLOW_EXCEPTION_MESSAGE

#define STACK_UNDERFLOW_EXCEPTION_MESSAGE   "Stack underflow occurred during execution."

◆ TOO_MANY_LABELS_EXCEPTION_MESSAGE

#define TOO_MANY_LABELS_EXCEPTION_MESSAGE   "Too many labels are defined in the input file."

◆ TOO_MANY_SYMBOLS_EXCEPTION_MESSAGE

#define TOO_MANY_SYMBOLS_EXCEPTION_MESSAGE   "Too many symbols exist in the input file."

◆ UNKNOWN_EXCEPTION_MESSAGE

#define UNKNOWN_EXCEPTION_MESSAGE   "An unknown error has occurred."

Function Documentation

◆ handle_exception()

void handle_exception ( int  code)

Variable Documentation

◆ c8_exception

char c8_exception[BUFSIZ]

Message to print when calling handle_exception with a non-zero code

◆ exceptions

exception_t exceptions[]
Initial value:
= {
{ INVALID_INSTRUCTION_EXCEPTION, "An invalid instruction exists in the input file." },
{ TOO_MANY_LABELS_EXCEPTION, "Too many labels are defined in the input file." },
{ STACK_OVERFLOW_EXCEPTION, "A stack overflow occurred during execution." },
{ INVALID_ARGUMENT_EXCEPTION, "An invalid instruction argument was given." },
{ DUPLICATE_LABEL_EXCEPTION, "A label was defined multiple times." },
{ INVALID_SYMBOL_EXCEPTION, "An invalid symbol exists in the input file." },
{ MEMORY_ALLOCATION_EXCEPTION, "Failed to allocate memory." },
{ UNKNOWN_EXCEPTION, "An unknown error has occurred." },
{ TOO_MANY_SYMBOLS_EXCEPTION, "Too many symbols exist in the input file." },
{ LOAD_FILE_FAILURE_EXCEPTION, "Failed to load file." },
{ FILE_TOO_BIG_EXCEPTION, "The given file is too big." },
{ INVALID_COLOR_PALETTE_EXCEPTION, "Invalid color palette." },
{ INVALID_QUIRK_EXCEPTION, "Invalid quirk." },
{ FAILED_GRAPHICS_INITIALIZATION_EXCEPTION, "Failed to initialize graphics." },
{ INVALID_FONT_EXCEPTION, "Invalid font." },
{ INVALID_CLOCK_SPEED_EXCEPTION, "Clock speed cannot be less than 1." },
{ STACK_UNDERFLOW_EXCEPTION, "Stack underflow occurred during execution." },
}
@ TOO_MANY_SYMBOLS_EXCEPTION
Definition: exception.h:29
@ MEMORY_ALLOCATION_EXCEPTION
Definition: exception.h:27
@ UNKNOWN_EXCEPTION
Definition: exception.h:28
@ INVALID_SYMBOL_EXCEPTION
Definition: exception.h:26
@ FILE_TOO_BIG_EXCEPTION
Definition: exception.h:31
@ TOO_MANY_LABELS_EXCEPTION
Definition: exception.h:22
@ INVALID_QUIRK_EXCEPTION
Definition: exception.h:33
@ INVALID_INSTRUCTION_EXCEPTION
Definition: exception.h:21
@ INVALID_FONT_EXCEPTION
Definition: exception.h:35
@ INVALID_CLOCK_SPEED_EXCEPTION
Definition: exception.h:36
@ STACK_UNDERFLOW_EXCEPTION
Definition: exception.h:37
@ INVALID_ARGUMENT_EXCEPTION
Definition: exception.h:24
@ STACK_OVERFLOW_EXCEPTION
Definition: exception.h:23
@ FAILED_GRAPHICS_INITIALIZATION_EXCEPTION
Definition: exception.h:34
@ INVALID_COLOR_PALETTE_EXCEPTION
Definition: exception.h:32
@ DUPLICATE_LABEL_EXCEPTION
Definition: exception.h:25
@ LOAD_FILE_FAILURE_EXCEPTION
Definition: exception.h:30