shrooms-vb-core/core/vb.h

155 lines
5.4 KiB
C
Raw Normal View History

2024-10-14 20:07:00 +00:00
#ifndef VB_H_
#define VB_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef VBAPI
#define VBAPI extern
#endif
/* Header includes */
#include <stddef.h>
#include <stdint.h>
/**************************** Compilation Control ****************************/
/*
VB_DIRECT_EXCEPTION
VB_DIRECT_EXECUTE
VB_DIRECT_FETCH
2024-10-16 21:15:39 +00:00
VB_DIRECT_FRAME
2024-10-14 20:07:00 +00:00
VB_DIRECT_READ
2024-10-20 23:52:19 +00:00
VB_DIRECT_SAMPLES
2024-10-14 20:07:00 +00:00
VB_DIRECT_WRITE
2024-10-15 19:11:29 +00:00
Implements callbacks as direct function calls with names given by the above
symbols in their respective situations. If left undefined, the function
pointer in the simulation state is used. Whether or not to call the callback
is still determined by whether the function pointer is NULL.
2024-10-14 20:07:00 +00:00
*/
/*
VB_DIV_GENERIC
Provides a generic implementation for the DIV instruction that guarantees the
correct results for quotient and remainder. If left undefined, an accelerated
implementation is used that depends on the compiler's behavior.
*/
/*
VB_LITTLE_ENDIAN
Accelerates simulated memory reads and writes on hosts with little-endian
byte ordering. If left undefined, a generic implementation is used instead.
*/
/*
VB_SIGNED_PROPAGATE
Accelerates sign extension by assuming the >> operator propagates the sign
bit for signed types and does not for unsigned types. If left undefined, a
generic implementation is used instead.
*/
/********************************* Constants *********************************/
/* System registers */
#define VB_ADTRE 25
#define VB_CHCW 24
#define VB_ECR 4
#define VB_EIPC 0
#define VB_EIPSW 1
#define VB_FEPC 2
#define VB_FEPSW 3
#define VB_PIR 6
#define VB_PSW 5
#define VB_TKCW 7
/* Memory access data types */
#define VB_S8 0
#define VB_U8 1
#define VB_S16 2
#define VB_U16 3
#define VB_S32 4
2024-10-23 21:29:11 +00:00
/* Option keys */
#define VB_PSEUDO_HALT 0
2024-10-14 20:07:00 +00:00
/*********************************** Types ***********************************/
/* Simulation state */
typedef struct VB VB;
/* Callbacks */
2024-10-20 23:52:19 +00:00
typedef int (*vbOnException)(VB *sim, uint16_t *cause);
typedef int (*vbOnExecute )(VB *sim, uint32_t address, const uint16_t *code, int length);
typedef int (*vbOnFetch )(VB *sim, int fetch, uint32_t address, int32_t *value, uint32_t *cycles);
typedef int (*vbOnFrame )(VB *sim);
typedef int (*vbOnRead )(VB *sim, uint32_t address, int type, int32_t *value, uint32_t *cycles);
typedef void (*vbOnSamples )(VB *sim, int16_t *buffer, uint32_t capacity);
typedef int (*vbOnWrite )(VB *sim, uint32_t address, int type, int32_t *value, uint32_t *cycles, int *cancel);
2024-10-14 20:07:00 +00:00
/******************************* API Commands ********************************/
VBAPI int vbEmulate (VB *sim, uint32_t *clocks);
VBAPI int vbEmulateEx (VB **sims, int count, uint32_t *clocks);
VBAPI void* vbGetCallback (VB *sim, int id);
VBAPI void* vbGetCartRAM (VB *sim, uint32_t *size);
VBAPI void* vbGetCartROM (VB *sim, uint32_t *size);
VBAPI vbOnException vbGetExceptionCallback(VB *sim);
VBAPI vbOnExecute vbGetExecuteCallback (VB *sim);
VBAPI vbOnFetch vbGetFetchCallback (VB *sim);
2024-10-16 21:15:39 +00:00
VBAPI vbOnFrame vbGetFrameCallback (VB *sim);
2024-10-20 01:35:56 +00:00
VBAPI uint16_t vbGetKeys (VB *sim);
2024-10-23 21:29:11 +00:00
VBAPI int vbGetOption (VB *sim, int key);
2024-10-16 21:53:33 +00:00
VBAPI void vbGetPixels (VB *sim, void *left, int leftStrideX, int leftStrideY, void *right, int rightStrideX, int rightStrideY);
2024-10-14 20:07:00 +00:00
VBAPI uint32_t vbGetProgramCounter (VB *sim);
VBAPI int32_t vbGetProgramRegister (VB *sim, int index);
VBAPI vbOnRead vbGetReadCallback (VB *sim);
2024-10-20 23:52:19 +00:00
VBAPI void* vbGetSamples (VB *sim, uint32_t *capacity, uint32_t *position);
VBAPI vbOnSamples vbGetSamplesCallback (VB *sim);
2024-10-14 20:07:00 +00:00
VBAPI uint32_t vbGetSystemRegister (VB *sim, int index);
VBAPI void* vbGetUserData (VB *sim);
VBAPI vbOnWrite vbGetWriteCallback (VB *sim);
VBAPI VB* vbInit (VB *sim);
VBAPI int32_t vbRead (VB *sim, uint32_t address, int type);
VBAPI VB* vbReset (VB *sim);
VBAPI int vbSetCartRAM (VB *sim, void *sram, uint32_t size);
VBAPI int vbSetCartROM (VB *sim, void *rom, uint32_t size);
VBAPI vbOnException vbSetExceptionCallback(VB *sim, vbOnException callback);
VBAPI vbOnExecute vbSetExecuteCallback (VB *sim, vbOnExecute callback);
VBAPI vbOnFetch vbSetFetchCallback (VB *sim, vbOnFetch callback);
2024-10-16 21:15:39 +00:00
VBAPI vbOnFrame vbSetFrameCallback (VB *sim, vbOnFrame callback);
2024-10-20 01:35:56 +00:00
VBAPI uint16_t vbSetKeys (VB *sim, uint16_t keys);
2024-10-23 21:29:11 +00:00
VBAPI int vbSetOption (VB *sim, int key, int value);
2024-10-14 20:07:00 +00:00
VBAPI uint32_t vbSetProgramCounter (VB *sim, uint32_t value);
VBAPI int32_t vbSetProgramRegister (VB *sim, int index, int32_t value);
VBAPI vbOnRead vbSetReadCallback (VB *sim, vbOnRead callback);
2024-10-20 23:52:19 +00:00
VBAPI int vbSetSamples (VB *sim, void *samples, uint32_t capacity);
VBAPI vbOnSamples vbSetSamplesCallback (VB *sim, vbOnSamples callback);
2024-10-14 20:07:00 +00:00
VBAPI uint32_t vbSetSystemRegister (VB *sim, int index, uint32_t value);
VBAPI void* vbSetUserData (VB *sim, void *tag);
VBAPI vbOnWrite vbSetWriteCallback (VB *sim, vbOnWrite callback);
VBAPI size_t vbSizeOf ();
VBAPI int32_t vbWrite (VB *sim, uint32_t address, int type, int32_t value);
#ifdef __cplusplus
}
#endif
#endif /* VB_H_ */