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

Macros

#define VERBOSE(c)   (c->flags & C8_FLAG_VERBOSE)
 
#define SCHIP_EXCLUSIVE(c)
 
#define XOCHIP_EXCLUSIVE(c)
 
#define QUIRK_BITWISE(c)
 
#define QUIRK_DRAW(c)
 
#define QUIRK_LOADSTORE(c)
 
#define QUIRK_SHIFT(c)
 
#define BORROWS(x, y)   ((((int) x) - y) < 0)
 
#define CARRIES(x, y)   ((((int) x) + y) > UINT8_MAX)
 

Functions

int c8_parse_instruction (C8 *c8)
 Execute the instruction at c8->pc
 

Detailed Description

Note
NOT EXPORTED

This file contains the implementation of the instruction parsing and execution for the CHIP-8 interpreter.

Macro Definition Documentation

◆ BORROWS

#define BORROWS (   x,
 
)    ((((int) x) - y) < 0)

◆ CARRIES

#define CARRIES (   x,
 
)    ((((int) x) + y) > UINT8_MAX)

◆ QUIRK_BITWISE

#define QUIRK_BITWISE (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_BITWISE) { \
c->V[0xF] = 0; \
}
#define C8_FLAG_QUIRK_BITWISE
Enable the 'b' quirk (see main page/README).
Definition: chip8.h:53

◆ QUIRK_DRAW

#define QUIRK_DRAW (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_DRAW) { \
if () \
}
#define C8_FLAG_QUIRK_DRAW
Enable the 'd' quirk (see main page/README).
Definition: chip8.h:58

◆ QUIRK_LOADSTORE

#define QUIRK_LOADSTORE (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_LOADSTORE) { \
c->I += x + 1; \
}
#define C8_FLAG_QUIRK_LOADSTORE
Enable the 'l' quirk (see main page/README).
Definition: chip8.h:63

◆ QUIRK_SHIFT

#define QUIRK_SHIFT (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_SHIFT) { \
y = x; \
}
#define C8_FLAG_QUIRK_SHIFT
Enable the 's' quirk (see main page/README).
Definition: chip8.h:68

◆ SCHIP_EXCLUSIVE

#define SCHIP_EXCLUSIVE (   c)
Value:
if (c->mode == C8_MODE_CHIP8) { \
"SCHIP instruction detected in CHIP-8 mode.\n"); \
}
#define C8_MODE_CHIP8
CHIP-8 execution mode. SCHIP and XO-CHIP instructions will throw an error.
Definition: chip8.h:28
@ C8_INVALID_INSTRUCTION_EXCEPTION
Definition: exception.h:31

◆ VERBOSE

#define VERBOSE (   c)    (c->flags & C8_FLAG_VERBOSE)

◆ XOCHIP_EXCLUSIVE

#define XOCHIP_EXCLUSIVE (   c)
Value:
if (c->mode != C8_MODE_XOCHIP) { \
const char* modeStr = (c->mode == C8_MODE_CHIP8) ? "CHIP-8" : "SCHIP"; \
"XOCHIP instruction detected in %s mode.\n", \
modeStr); \
}
#define C8_MODE_XOCHIP
XO-CHIP execution mode.
Definition: chip8.h:38

Function Documentation

◆ c8_parse_instruction()

int c8_parse_instruction ( C8 c8)

Execute the instruction at c8->pc

This function parses and executes the instruction at the current program counter.

If verbose flag is set, this will print the instruction to stdout as well.

Parameters
c8the C8 to execute the instruction from
Returns
amount to increase the program counter, or an exception code if an error occurs.