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

Macros

#define C8_VERBOSE(c)   (c->flags & C8_FLAG_VERBOSE)
 
#define C8_SCHIP_EXCLUSIVE(c)
 
#define C8_XOCHIP_EXCLUSIVE(c)
 
#define C8_QUIRK_VF_RESET(c)
 
#define C8_QUIRK_MEMORY(c)
 
#define C8_QUIRK_SHIFTING(c)
 

Functions

int c8_parse_instruction (C8 *c8)
 Execute the instruction at c8->pc
 
void print_binary (unsigned int n)
 

Detailed Description

Note
NOT EXPORTED

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

Macro Definition Documentation

◆ C8_QUIRK_MEMORY

#define C8_QUIRK_MEMORY (   c)
Value:
if (c->flags & C8_FLAG_QUIRK_MEMORY) { \
c8->I = (c8->I + x + 1) & 0xFFF; \
}
#define C8_FLAG_QUIRK_MEMORY
Enable the 'm' quirk (see main page/README).
Definition: chip8.h:58

◆ C8_QUIRK_SHIFTING

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

◆ C8_QUIRK_VF_RESET

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

◆ C8_SCHIP_EXCLUSIVE

#define C8_SCHIP_EXCLUSIVE (   c)
Value:
if (c->mode == C8_MODE_CHIP8) { \
fprintf(stderr, "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_STATE_EXCEPTION
Definition: exception.h:35

◆ C8_VERBOSE

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

◆ C8_XOCHIP_EXCLUSIVE

#define C8_XOCHIP_EXCLUSIVE (   c)
Value:
if (c->mode != C8_MODE_XOCHIP) { \
const char* modeStr = (c->mode == C8_MODE_CHIP8) ? "CHIP-8" : "SCHIP"; \
fprintf(stderr, "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.

◆ print_binary()

void print_binary ( unsigned int  n)