libc8
CHIP-8 utility library
decode.c File Reference
#include "decode.h"
#include "defs.h"
#include <stdio.h>
#include <stdlib.h>

Macros

#define DEFINE_LABELS   (args & C8_DECODE_DEFINE_LABELS)
 
#define PRINT_ADDRESSES   (args & C8_DECODE_PRINT_ADDRESSES)
 

Functions

void c8_decode (FILE *input, FILE *output, int args)
 Convert bytecode from input to assembly and writes it to output. More...
 
char * c8_decode_instruction (uint16_t in, uint8_t *label_map)
 Decode in and return its assembly value. More...
 
uint16_t jump (uint16_t in)
 Returns the value to jump to if n is a jump instruction, or 0. More...
 

Variables

char result [32]
 

Detailed Description

Stuff for disassembling bytecode.

Macro Definition Documentation

◆ DEFINE_LABELS

#define DEFINE_LABELS   (args & C8_DECODE_DEFINE_LABELS)

◆ PRINT_ADDRESSES

#define PRINT_ADDRESSES   (args & C8_DECODE_PRINT_ADDRESSES)

Function Documentation

◆ c8_decode()

void c8_decode ( FILE *  input,
FILE *  output,
int  args 
)

Convert bytecode from input to assembly and writes it to output.

ARG_PRINT_ADDRESSES should be AND'd to args to print addresses before each assembly instruction.

ARG_DEFINE_LABELS should be AND'd to args to define labels.

Parameters
inputthe CHIP-8 ROM file to disassemble
outputthe file to write the assembly to
args0 with ARG_PRINT_ADDRESSES and/or ARG_DEFINE_LABELS optionally OR'd

◆ c8_decode_instruction()

char * c8_decode_instruction ( uint16_t  in,
uint8_t *  label_map 
)

Decode in and return its assembly value.

Gets the assembly value of instruction in, stores it in the global variable result, and returns result.

If label_map is not NULL, it should point to an aray of size MEMSIZE, with all "labeled" elements set to a unique, non-zero integer. All other elements should be zero.

If label_map is not NULL, label_map[nnn] is greater than 0, and the instruction contains a nnn argument, a label name will be generated and used in the resulting string.

Parameters
inThe instruction to decode
label_mapThe label map (can be NULL for no labels)
Returns
result containing the associated assembly instruction

◆ jump()

uint16_t jump ( uint16_t  in)

Returns the value to jump to if n is a jump instruction, or 0.

Parameters
inThe instruction to check
Returns
in's nnn value if it exists, 0 otherwise.

Variable Documentation

◆ result

char result[32]