libc8
CHIP-8 utility library
debug.c File Reference
#include "debug.h"
#include "../chip8.h"
#include "..//font.h"
#include "..//decode.h"
#include "exception.h"
#include "util.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Data Structures

union  ArgValue
 Stores an argument's value (string or int) More...
 
struct  arg_t
 Represents an argument for a command with a type and value. More...
 
struct  cmd_t
 Represents a command with an ID, argument ID, and associated argument. More...
 

Enumerations

enum  Command {
  CMD_NONE = -1 , CMD_ADD_BREAKPOINT = 0 , CMD_RM_BREAKPOINT , CMD_CONTINUE ,
  CMD_NEXT , CMD_SET , CMD_LOAD , CMD_SAVE ,
  CMD_PRINT , CMD_HELP , CMD_QUIT , CMD_LOADFLAGS ,
  CMD_SAVEFLAGS
}
 Represents command types. More...
 
enum  Argument {
  ARG_NONE = -1 , ARG_SP = 0 , ARG_DT , ARG_ST ,
  ARG_PC , ARG_I , ARG_VK , ARG_STACK ,
  ARG_BG , ARG_FG , ARG_SFONT , ARG_BFONT ,
  ARG_QUIRKS , ARG_V , ARG_R , ARG_ADDR ,
  ARG_FILE
}
 Represents argument types. More...
 

Functions

int debug_repl (c8_t *c8)
 Debug command line loop. More...
 
int has_breakpoint (c8_t *c8, uint16_t pc)
 Check if breakpoint exists at address pc. More...
 

Variables

const char * args []
 
const char * cmds []
 

Detailed Description

Note
NOT EXPORTED

Stuff related to debug mode.

Enumeration Type Documentation

◆ Argument

enum Argument

Represents argument types.

This enumeration defines all possible debug mode arguments.

Enumerator
ARG_NONE 
ARG_SP 
ARG_DT 
ARG_ST 
ARG_PC 
ARG_I 
ARG_VK 
ARG_STACK 
ARG_BG 
ARG_FG 
ARG_SFONT 
ARG_BFONT 
ARG_QUIRKS 
ARG_V 
ARG_R 
ARG_ADDR 
ARG_FILE 

◆ Command

enum Command

Represents command types.

This enumeration defines all possible debug mode commands

Enumerator
CMD_NONE 
CMD_ADD_BREAKPOINT 
CMD_RM_BREAKPOINT 
CMD_CONTINUE 
CMD_NEXT 
CMD_SET 
CMD_LOAD 
CMD_SAVE 
CMD_PRINT 
CMD_HELP 
CMD_QUIT 
CMD_LOADFLAGS 
CMD_SAVEFLAGS 

Function Documentation

◆ debug_repl()

int debug_repl ( c8_t c8)

Debug command line loop.

This function parses user commands from stdin and prints the result until one of the following conditions is met:

  • continue command is evaluated (return DEBUG_CONTINUE)
  • quit command is evaluated (return DEBUG_QUIT)
  • next command is evaluated (return DEBUG_STEP)
Parameters
c8the current CHIP-8 state
Returns
DEBUG_CONTINUE, DEBUG_STEP, or DEBUG_QUIT

◆ has_breakpoint()

int has_breakpoint ( c8_t c8,
uint16_t  pc 
)

Check if breakpoint exists at address pc.

Parameters
c8c8_t to check breakpoints of
pcaddress to check for breakpoint at
Returns
1 if yes, 0 if no

Variable Documentation

◆ args

const char* args[]
Initial value:
= {
"SP",
"DT",
"ST",
"PC",
"I",
"VK",
"stack",
"bg",
"fg",
"sfont",
"bfont",
"quirks",
}

These are string values of all possible argument, ordered to match the Argument enumerator.

◆ cmds

const char* cmds[]
Initial value:
= {
"break",
"rmbreak",
"continue",
"next",
"set",
"load",
"save",
"print",
"help",
"quit",
"loadflags",
"saveflags",
}

These are string values of all possible commands, ordered to match the Command enumerator.