97 lines
2.6 KiB
C
97 lines
2.6 KiB
C
#ifndef VBUAPI
|
|
#define VBUAPI
|
|
#endif
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <vbu.h>
|
|
|
|
|
|
|
|
/***************************** Library Functions *****************************/
|
|
|
|
/* Memory manager */
|
|
#ifdef VBU_MEMMGR
|
|
extern void* VBU_MEMMGR(void *ptr, size_t size);
|
|
#else
|
|
#include <stdlib.h>
|
|
static void* VBU_MEMMGR(void *ptr, size_t size) {
|
|
|
|
/* Free a buffer */
|
|
if (size == 0) {
|
|
if (ptr != NULL)
|
|
free(ptr);
|
|
return NULL;
|
|
}
|
|
|
|
/* Create or resize a buffer */
|
|
return realloc(ptr, size);
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
/******************************** Sub-Modules ********************************/
|
|
|
|
#include "disassembler.c"
|
|
#include "isx.c"
|
|
|
|
|
|
|
|
/******************************* API Commands ********************************/
|
|
|
|
/* Determine the size in bytes of an instruction */
|
|
VBUAPI int vbuCodeSize(VB *sim, uint32_t address) {
|
|
int opcode = vbRead(sim, address, VB_U16) >> 10 & 63;
|
|
return opcode < 0x20 || opcode == 0x32 || opcode == 0x36 ? 2 : 4;
|
|
}
|
|
|
|
/* Initialize disassembler options with default settings */
|
|
VBUAPI VBU_DasmConfig* vbuDasmDefaults(VBU_DasmConfig *config) {
|
|
|
|
/* Error checking */
|
|
if (config == NULL)
|
|
return NULL;
|
|
|
|
/* Supply default configuration */
|
|
config->bcondNotation = VBU_JOINED;
|
|
config->branchNotation = VBU_ABSOLUTE;
|
|
config->conditionCase = VBU_LOWER;
|
|
config->conditionCL = VBU_L;
|
|
config->conditionEZ = VBU_Z;
|
|
config->conditionNotation = VBU_NAMES;
|
|
config->hexCase = VBU_UPPER;
|
|
config->hexNotation = VBU_PREFIX_0X;
|
|
config->immediateNotation = VBU_NONE;
|
|
config->memoryNotation = VBU_OUTSIDE;
|
|
config->mnemonicCase = VBU_UPPER;
|
|
config->operandOrder = VBU_DEST_LAST;
|
|
config->programCase = VBU_LOWER;
|
|
config->programNotation = VBU_NAMES;
|
|
config->setfNotation = VBU_SPLIT;
|
|
config->systemCase = VBU_LOWER;
|
|
config->systemNotation = VBU_NAMES;
|
|
return config;
|
|
}
|
|
|
|
/* Disassemble from a simulation */
|
|
VBUAPI VBU_DasmLine* vbuDisassemble(VB *sim, uint32_t address,
|
|
VBU_DasmConfig *config, unsigned length, int line) {
|
|
VBU_DasmConfig defs; /* Default settings */
|
|
|
|
/* Error checking */
|
|
if (sim == NULL || length == 0)
|
|
return NULL;
|
|
|
|
/* Supply default configuration */
|
|
if (config == NULL)
|
|
config = vbuDasmDefaults(&defs);
|
|
|
|
/* Disassemble instructions */
|
|
return dasmDisassemble(sim, address, config, length, line);
|
|
}
|
|
|
|
/* Decode an ISX debugger file to a Virtual Boy ROM */
|
|
VBUAPI void* vbuFromISX(void *bytes, size_t length, size_t *romLength) {
|
|
return isxFrom(bytes, length, romLength);
|
|
}
|