2020-07-30 18:04:41 +00:00
|
|
|
#define VUEAPI
|
|
|
|
#include <vue.h>
|
2020-08-04 01:34:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Constants *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* Memory access type sizes */
|
|
|
|
static const int TYPE_SIZES[] = { 1, 1, 2, 2, 4 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Component Includes *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "bus.c"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Library Functions *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* Prepare an emulation state context for use */
|
|
|
|
void vueInitialize(VUE *vue) {
|
|
|
|
vue->rom = NULL;
|
|
|
|
vue->sram = NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-05 02:17:56 +00:00
|
|
|
/* Read bytes from the CPU bus */
|
|
|
|
vbool vueRead(VUE *vue, uint32_t address, uint8_t *dest, uint32_t length) {
|
2020-08-04 01:34:02 +00:00
|
|
|
uint32_t count; /* Bytes to read in one iteration */
|
|
|
|
|
|
|
|
/* Error checking */
|
2020-08-05 02:17:56 +00:00
|
|
|
if (vue == NULL || dest == NULL)
|
|
|
|
return VUE_FALSE;
|
2020-08-04 01:34:02 +00:00
|
|
|
|
|
|
|
/* Perform the operation */
|
2020-08-05 02:17:56 +00:00
|
|
|
for (; length > 0; address += count, length -= count, dest += count) {
|
2020-08-04 01:34:02 +00:00
|
|
|
|
|
|
|
/* Determine the maximum number of bytes to process at once */
|
|
|
|
count = 0x01000000 - (address & 0x00FFFFFF);
|
|
|
|
if (count > length)
|
|
|
|
count = length;
|
|
|
|
|
|
|
|
/* Process by component */
|
|
|
|
switch (address >> 24 & 7) {
|
2020-08-05 02:17:56 +00:00
|
|
|
case 1: /* Fallthrough */ /* VSU (write-only) */
|
|
|
|
case 3: /* Fallthrough */ /* Unmapped */
|
|
|
|
case 4: /* Cartridge expansion (not supported) */
|
|
|
|
busReadBytes(NULL , dest, address, 0 , count);
|
|
|
|
break;
|
|
|
|
case 5: /* System WRAM */
|
|
|
|
busReadBytes(vue->wram, dest, address, 0x10000 , count);
|
|
|
|
break;
|
|
|
|
case 6: /* Cartridge RAM */
|
|
|
|
busReadBytes(vue->sram, dest, address, vue->sram_size, count);
|
|
|
|
break;
|
|
|
|
case 7: /* Cartridge ROM */
|
|
|
|
busReadBytes(vue->rom , dest, address, vue->rom_size , count);
|
|
|
|
break;
|
2020-08-04 01:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
return VUE_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Specify a new ROM buffer */
|
|
|
|
vbool vueSetROM(VUE *vue, uint8_t *rom, uint32_t size) {
|
|
|
|
|
|
|
|
/* Error checking */
|
|
|
|
if (
|
|
|
|
vue == NULL ||
|
|
|
|
rom == NULL ||
|
|
|
|
size < 1024 || size > 0x01000000 ||
|
|
|
|
(size & (size - 1)) != 0
|
|
|
|
) return VUE_FALSE;
|
|
|
|
|
|
|
|
/* Accept the new ROM buffer */
|
|
|
|
vue->rom = rom;
|
|
|
|
vue->rom_size = size;
|
|
|
|
return VUE_TRUE;
|
|
|
|
}
|
2020-08-05 02:17:56 +00:00
|
|
|
|
|
|
|
/* Write bytes to the CPU bus */
|
|
|
|
vbool vueWrite(VUE *vue, uint32_t address, uint8_t *src, uint32_t length) {
|
|
|
|
uint32_t count; /* Bytes to write in one iteration */
|
|
|
|
|
|
|
|
/* Error checking */
|
|
|
|
if (vue == NULL || src == NULL)
|
|
|
|
return VUE_FALSE;
|
|
|
|
|
|
|
|
/* Perform the operation */
|
|
|
|
for (; length > 0; address += count, length -= count, src += count) {
|
|
|
|
|
|
|
|
/* Determine the maximum number of bytes to process at once */
|
|
|
|
count = 0x01000000 - (address & 0x00FFFFFF);
|
|
|
|
if (count > length)
|
|
|
|
count = length;
|
|
|
|
|
|
|
|
/* Process by component */
|
|
|
|
switch (address >> 24 & 7) {
|
|
|
|
case 5: /* System WRAM */
|
|
|
|
busWriteBytes(vue->wram, src, address, 0x10000 , count);
|
|
|
|
break;
|
|
|
|
case 6: /* Cartridge RAM */
|
|
|
|
busWriteBytes(vue->sram, src, address, vue->sram_size, count);
|
|
|
|
break;
|
|
|
|
case 7: /* Cartridge ROM */
|
|
|
|
busWriteBytes(vue->rom , src, address, vue->rom_size , count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
return VUE_TRUE;
|
|
|
|
}
|