Add vbuCodeSize()

This commit is contained in:
Guy Perfect 2024-11-21 18:50:31 -06:00
parent f45636a491
commit 18b2c589e6
4 changed files with 16 additions and 13 deletions

View File

@ -1085,11 +1085,13 @@ static void vipDrawAffine(VB *sim, World *world) {
pixel = cell->pixels[(py & 7) << 3 | (px & 7)];
if (pixel != 0)
*col = cell->palette[pixel];
}
}
} /* x */
} /* y */
} /* i */
}
}
/* Draw an object group into shadow memory */

View File

@ -1,4 +1,4 @@
/* This file is included into vb.c and cannot be compiled on its own. */
/* This file is included into vbu.c and cannot be compiled on its own. */
#ifdef VBUAPI
@ -449,12 +449,6 @@ static VBU_DasmLine* dasmGrow(
return *lines == NULL ? NULL : &(*lines)[index];
}
/* Determine the size of an instruction */
static uint32_t dasmInstSize(VB *sim, uint32_t address) {
unsigned opcode = vbRead(sim, address, VB_U16) >> 10 & 63;
return opcode < 0x20 || opcode == 0x32 || opcode == 0x36 ? 2 : 4;
}
/* Format an operand */
static void dasmOperand(char *dest, VBU_DasmConfig *config,
VBU_DasmLine *line, uint8_t type) {
@ -515,7 +509,7 @@ static int dasmLine(VB *sim, uint32_t *address, uint32_t pc,
/* Process non-text members */
line = &(*lines)[index];
line->address = *address;
line->codeLength = dasmInstSize(sim, *address);
line->codeLength = vbuCodeSize(sim, *address);
line->isPC = *address == pc;
for (x = 0; x < line->codeLength; x++)
line->code[x] = vbRead(sim, *address + x, VB_U8);
@ -660,7 +654,7 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address,
}
/* Check if the instruction contains the reference address */
size = dasmInstSize(sim, addr);
size = vbuCodeSize(sim, addr);
if (address - addr < size)
break;
addr += addr != pc && pc - addr < size ? pc - addr : size;
@ -674,7 +668,7 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address,
/* Keep decoding until the first line of output */
else for (; line < 0; line++)
addr += dasmInstSize(sim, addr);
addr += vbuCodeSize(sim, addr);
/* Working variables */
size = length * sizeof (VBU_DasmLine);

View File

@ -38,6 +38,12 @@ static int32_t SignExtend(int32_t value, int32_t bits) {
/******************************* 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* vbuDasmInit(VBU_DasmConfig *config) {
config->bcondNotation = VBU_JOINED;

View File

@ -85,6 +85,7 @@ typedef struct {
/******************************* API Commands ********************************/
VBUAPI int vbuCodeSize (VB *sim, uint32_t address);
VBUAPI VBU_DasmConfig* vbuDasmInit (VBU_DasmConfig *config);
VBUAPI VBU_DasmLine* vbuDisassemble(VB *sim, uint32_t address, VBU_DasmConfig *config, unsigned length, int line);