Compare commits

..
3 Commits
Author SHA1 Message Date
GuyPerfect 6e9b727b31 Fix botched disassembler backport 2026-10-19 19:01:25 -05:00
GuyPerfect 7ab5bd28bf Fix affine world width assignment logic 2026-10-19 18:20:00 -05:00
GuyPerfect 41cd7bc089 Backport Shrooms2 disassembler 2026-10-17 22:01:08 -05:00
5 changed files with 802 additions and 642 deletions
+5 -4
View File
@@ -320,6 +320,7 @@ static void vipWriteWorld(VB *sim, uint32_t offset, int type, int32_t value) {
uint32_t base; /* Base BG map index */ uint32_t base; /* Base BG map index */
uint8_t *bg; /* Background template */ uint8_t *bg; /* Background template */
uint32_t count; /* Number of BG maps in background */ uint32_t count; /* Number of BG maps in background */
int32_t width; /* Computed affine width */
World *world; /* World state */ World *world; /* World state */
uint32_t z; /* Iterator */ uint32_t z; /* Iterator */
@@ -381,10 +382,10 @@ static void vipWriteWorld(VB *sim, uint32_t offset, int type, int32_t value) {
case 5: world->mp = SignExtend(value, 15); break; case 5: world->mp = SignExtend(value, 15); break;
case 6: world->my = SignExtend(value, 13); break; case 6: world->my = SignExtend(value, 13); break;
case 7: /* W */ case 7: /* W */
value = SignExtend(value, 13) + 1; width = SignExtend(value, 13) + 1;
world->wNaffine = value < 0 ? 0 : value; world->wNaffine = width < 0 ? 0 : width;
value = SignExtend(value, 10) + 1; width = SignExtend(value, 10) + 1;
world->wAffine = value < 0 ? 0 : value; world->wAffine = width < 0 ? 0 : width;
world->width = world->bgm != 2 ? world->wNaffine : world->wAffine; world->width = world->bgm != 2 ? world->wNaffine : world->wAffine;
break; break;
case 8: /* H */ case 8: /* H */
+726 -588
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -257,7 +257,7 @@ static void* isxFrom(uint8_t *bytes, size_t length, size_t *romLength) {
src < lowMax + 0x1000001 - highMin; src < lowMax + 0x1000001 - highMin;
src <<= 1 src <<= 1
); );
rom = VBU_REALLOC(NULL, src); rom = VBU_MEMMGR(NULL, src);
if (rom == NULL) if (rom == NULL)
return NULL; return NULL;
*romLength = src; *romLength = src;
+36 -18
View File
@@ -5,29 +5,29 @@
#include <string.h> #include <string.h>
#include <vbu.h> #include <vbu.h>
/* Memory management */
#ifndef VBU_REALLOC
#include <stdlib.h>
#define VBU_REALLOC realloc
#else
extern void* VBU_REALLOC(void *, size_t);
#endif
/***************************** Library Functions *****************************/ /***************************** Library Functions *****************************/
/* Sign-extend an integer of variable width */ /* Memory manager */
static int32_t SignExtend(int32_t value, int32_t bits) { #ifdef VBU_MEMMGR
#ifndef VB_SIGNED_PROPAGATE extern void* VBU_MEMMGR(void *ptr, size_t size);
value &= ~((uint32_t) 0xFFFFFFFF << bits);
bits = (int32_t) 1 << (bits - (int32_t) 1);
return (value ^ bits) - bits;
#else #else
return value << (32 - bits) >> (32 - bits); #include <stdlib.h>
#endif 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 ********************************/ /******************************** Sub-Modules ********************************/
@@ -46,14 +46,21 @@ VBUAPI int vbuCodeSize(VB *sim, uint32_t address) {
} }
/* Initialize disassembler options with default settings */ /* Initialize disassembler options with default settings */
VBUAPI VBU_DasmConfig* vbuDasmInit(VBU_DasmConfig *config) { VBUAPI VBU_DasmConfig* vbuDasmDefaults(VBU_DasmConfig *config) {
/* Error checking */
if (config == NULL)
return NULL;
/* Supply default configuration */
config->bcondNotation = VBU_JOINED; config->bcondNotation = VBU_JOINED;
config->branchNotation = VBU_ABSOLUTE;
config->conditionCase = VBU_LOWER; config->conditionCase = VBU_LOWER;
config->conditionCL = VBU_L; config->conditionCL = VBU_L;
config->conditionEZ = VBU_Z; config->conditionEZ = VBU_Z;
config->conditionNotation = VBU_NAMES; config->conditionNotation = VBU_NAMES;
config->hexCase = VBU_UPPER; config->hexCase = VBU_UPPER;
config->hexNotation = VBU_0X; config->hexNotation = VBU_PREFIX_0X;
config->immediateNotation = VBU_NONE; config->immediateNotation = VBU_NONE;
config->memoryNotation = VBU_OUTSIDE; config->memoryNotation = VBU_OUTSIDE;
config->mnemonicCase = VBU_UPPER; config->mnemonicCase = VBU_UPPER;
@@ -69,6 +76,17 @@ VBUAPI VBU_DasmConfig* vbuDasmInit(VBU_DasmConfig *config) {
/* Disassemble from a simulation */ /* Disassemble from a simulation */
VBUAPI VBU_DasmLine* vbuDisassemble(VB *sim, uint32_t address, VBUAPI VBU_DasmLine* vbuDisassemble(VB *sim, uint32_t address,
VBU_DasmConfig *config, unsigned length, int line) { 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); return dasmDisassemble(sim, address, config, length, line);
} }
+11 -8
View File
@@ -17,23 +17,25 @@ extern "C" {
/********************************* Constants *********************************/ /********************************* Constants *********************************/
/* Disassembler options */ /* Disassembler options */
#define VBU_0X 0 #define VBU_ABSOLUTE 0
#define VBU_C 1 #define VBU_C 1
#define VBU_DEST_FIRST 1 #define VBU_DEST_FIRST 1
#define VBU_DEST_LAST 0 #define VBU_DEST_LAST 0
#define VBU_DOLLAR 1
#define VBU_E 0 #define VBU_E 0
#define VBU_H 2
#define VBU_INSIDE 1 #define VBU_INSIDE 1
#define VBU_JOINED 0 #define VBU_JOINED 0
#define VBU_L 0 #define VBU_L 0
#define VBU_LOWER 1 #define VBU_LOWER 1
#define VBU_NAMES 1 #define VBU_NAMES 1
#define VBU_NONE 0 #define VBU_NONE 0
#define VBU_NUMBER 1
#define VBU_NUMBERS 0 #define VBU_NUMBERS 0
#define VBU_OUTSIDE 0 #define VBU_OUTSIDE 0
#define VBU_PREFIX_0X 0
#define VBU_PREFIX_DOLLAR 1
#define VBU_PREFIX_NUMBER 1
#define VBU_RELATIVE 1
#define VBU_SPLIT 1 #define VBU_SPLIT 1
#define VBU_SUFFIX_H 2
#define VBU_UPPER 0 #define VBU_UPPER 0
#define VBU_Z 1 #define VBU_Z 1
@@ -44,13 +46,14 @@ extern "C" {
/* Disassembler text options */ /* Disassembler text options */
typedef struct { /* Defaults listed first */ typedef struct { /* Defaults listed first */
uint8_t bcondNotation; /* JOINED, SPLIT */ uint8_t bcondNotation; /* JOINED, SPLIT */
uint8_t branchNotation; /* ABSOLUTE, RELATIVE */
uint8_t conditionCase; /* LOWER, UPPER */ uint8_t conditionCase; /* LOWER, UPPER */
uint8_t conditionCL; /* L, C */ uint8_t conditionCL; /* L, C */
uint8_t conditionEZ; /* Z, E */ uint8_t conditionEZ; /* Z, E */
uint8_t conditionNotation; /* NAMES, NUMBERS */ uint8_t conditionNotation; /* NAMES, NUMBERS */
uint8_t hexCase; /* UPPER, LOWER */ uint8_t hexCase; /* UPPER, LOWER */
uint8_t hexNotation; /* 0X, H, DOLLAR */ uint8_t hexNotation; /* PREFIX_0X, SUFFIX_H, PREFIX_DOLLAR */
uint8_t immediateNotation; /* NONE, NUMBER */ uint8_t immediateNotation; /* NONE, SUFFIX_NUMBER */
uint8_t memoryNotation; /* OUTSIDE, INSIDE */ uint8_t memoryNotation; /* OUTSIDE, INSIDE */
uint8_t mnemonicCase; /* UPPER, LOWER */ uint8_t mnemonicCase; /* UPPER, LOWER */
uint8_t operandOrder; /* DEST_LAST, DEST_FIRST */ uint8_t operandOrder; /* DEST_LAST, DEST_FIRST */
@@ -66,7 +69,7 @@ typedef struct {
/* Parsed */ /* Parsed */
uint32_t address; /* Memory address */ uint32_t address; /* Memory address */
uint16_t code[4]; /* Instruction bytes */ uint8_t code[4]; /* Instruction bytes */
uint8_t codeLength; /* Number of items in code */ uint8_t codeLength; /* Number of items in code */
uint8_t isPC; /* Set if PC is on this line */ uint8_t isPC; /* Set if PC is on this line */
@@ -86,7 +89,7 @@ typedef struct {
/******************************* API Commands ********************************/ /******************************* API Commands ********************************/
VBUAPI int vbuCodeSize (VB *sim, uint32_t address); VBUAPI int vbuCodeSize (VB *sim, uint32_t address);
VBUAPI VBU_DasmConfig* vbuDasmInit (VBU_DasmConfig *config); VBUAPI VBU_DasmConfig* vbuDasmDefaults(VBU_DasmConfig *config);
VBUAPI VBU_DasmLine* vbuDisassemble (VB *sim, uint32_t address, VBU_DasmConfig *config, unsigned length, int line); VBUAPI VBU_DasmLine* vbuDisassemble (VB *sim, uint32_t address, VBU_DasmConfig *config, unsigned length, int line);
VBUAPI void* vbuFromISX (void *bytes, size_t length, size_t *romLength); VBUAPI void* vbuFromISX (void *bytes, size_t length, size_t *romLength);