libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
instruction.c File Reference
#include "c8/private/instruction.h"
#include "c8/decode.h"
#include "c8/defs.h"
#include "c8/font.h"
#include "c8/private/exception.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.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 parse_instruction (c8_t *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
Definition: chip8.h:24

◆ QUIRK_DRAW

#define QUIRK_DRAW (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_DRAW) { \
if () \
}
#define C8_FLAG_QUIRK_DRAW
Definition: chip8.h:25

◆ QUIRK_LOADSTORE

#define QUIRK_LOADSTORE (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_LOADSTORE) { \
c->I += x + 1; \
}
#define C8_FLAG_QUIRK_LOADSTORE
Definition: chip8.h:26

◆ QUIRK_SHIFT

#define QUIRK_SHIFT (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_SHIFT) { \
y = x; \
}
#define C8_FLAG_QUIRK_SHIFT
Definition: chip8.h:27

◆ SCHIP_EXCLUSIVE

#define SCHIP_EXCLUSIVE (   c)
Value:
if (c->mode == C8_MODE_CHIP8) { \
C8_EXCEPTION(INVALID_INSTRUCTION_EXCEPTION, "SCHIP instruction detected in CHIP-8 mode.\n"); \
}
#define C8_MODE_CHIP8
Definition: chip8.h:18
@ INVALID_INSTRUCTION_EXCEPTION
Definition: exception.h:21

◆ 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"; \
C8_EXCEPTION(INVALID_INSTRUCTION_EXCEPTION, "XOCHIP instruction detected in %s mode.\n", modeStr); \
}
#define C8_MODE_XOCHIP
Definition: chip8.h:20

Function Documentation

◆ parse_instruction()

int parse_instruction ( c8_t 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_t to execute the instruction from
Returns
amount to increase the program counter, or an exception code if an error occurs.