Working on the plugins

git-svn-id: svn://svn.cc65.org/cc65/trunk@1223 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2002-04-07 20:39:35 +00:00
parent 58b5779f35
commit 77308fe20f
6 changed files with 196 additions and 68 deletions

View File

@@ -33,29 +33,198 @@
#include <stdlib.h>
#include <string.h>
/* sim65 */
#include "chipif.h"
/*****************************************************************************/
/* Forwards */
/*****************************************************************************/
int InitChip (const struct SimData* Data);
/* Initialize the chip, return an error code */
static void* InitInstance (unsigned Addr, unsigned Range);
/* Initialize a new chip instance */
static void WriteCtrl (void* Data, unsigned Addr, unsigned char Val);
/* Write control data */
static void Write (void* Data, unsigned Addr, unsigned char Val);
/* Write user data */
static unsigned char ReadCtrl (void* Data, unsigned Addr);
/* Read control data */
static unsigned char Read (void* Data, unsigned Addr);
/* Read user data */
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Control data passed to the main program */
static const struct ChipData RAMData[1] = {
{
"RAM", /* Name of the chip */
CHIPDATA_VER_MAJOR, /* Version information */
CHIPDATA_VER_MINOR,
/* -- Exported functions -- */
InitChip,
InitInstance,
WriteCtrl,
Write,
ReadCtrl,
Read
}
};
/* The SimData pointer we get when InitChip is called */
static const SimData* Sim;
/* Possible RAM attributes */
#define ATTR_INITIALIZED 0x01 /* RAM cell is intialized */
#define ATTR_WPROT 0x02 /* RAM cell is write protected */
/* Data for one RAM instance */
typedef struct InstanceData InstanceData;
struct InstanceData {
unsigned BaseAddr; /* Base address */
unsigned Range; /* Memory range */
unsigned char* MemAttr; /* Memory attributes */
unsigned char* Mem; /* The memory itself */
};
/*****************************************************************************/
/* Code */
/* Exported function */
/*****************************************************************************/
int GetChipData (const ChipData** Data, unsigned* Count)
{
*Data = 0;
*Count = 0;
return 1;
/* Pass the control structure to the caller */
*Data = RAMData;
*Count = sizeof (Data) / sizeof (Data[0]);
/* Call was successful */
return 0;
}
/*****************************************************************************/
/* Code */
/*****************************************************************************/
int InitChip (const struct SimData* Data)
/* Initialize the chip, return an error code */
{
/* Remember the pointer */
Sim = Data;
/* Always successful */
return 0;
}
static void* InitInstance (unsigned Addr, unsigned Range)
/* Initialize a new chip instance */
{
/* Allocate a new instance structure */
InstanceData* D = Sim->Malloc (sizeof (InstanceData));
/* Initialize the structure, allocate RAM and attribute memory */
D->BaseAddr = Addr;
D->Range = Range;
D->MemAttr = Sim->Malloc (Range * sizeof (D->MemAttr[0]));
D->Mem = Sim->Malloc (Range * sizeof (D->Mem[0]));
/* Clear the RAM and attribute memory */
memset (D->MemAttr, 0, Range * sizeof (D->MemAttr[0]));
memset (D->Mem, 0, Range * sizeof (D->Mem[0]));
/* Done, return the instance data */
return D;
}
static void WriteCtrl (void* Data, unsigned Addr, unsigned char Val)
/* Write control data */
{
/* Cast the data pointer */
InstanceData* D = (InstanceData*) Data;
/* Do the write and remember the cell as initialized */
D->Mem[Addr] = Val;
D->MemAttr[Addr] |= ATTR_INITIALIZED;
}
static void Write (void* Data, unsigned Addr, unsigned char Val)
/* Write user data */
{
/* Cast the data pointer */
InstanceData* D = (InstanceData*) Data;
/* Check for a write to a write protected cell */
if (D->MemAttr[Addr] & ATTR_WPROT) {
Sim->Warning ("Writing to write protected memory at $%04X", Addr);
}
/* Do the write and remember the cell as initialized */
D->Mem[Addr] = Val;
D->MemAttr[Addr] |= ATTR_INITIALIZED;
}
static unsigned char ReadCtrl (void* Data, unsigned Addr)
/* Read control data */
{
/* Cast the data pointer */
InstanceData* D = (InstanceData*) Data;
/* Read the cell and return the value */
return D->Mem[Addr];
}
static unsigned char Read (void* Data, unsigned Addr)
/* Read user data */
{
/* Cast the data pointer */
InstanceData* D = (InstanceData*) Data;
/* Check for a read from an uninitialized cell */
if ((D->MemAttr[Addr] & ATTR_INITIALIZED) == 0) {
/* We're reading a memory cell that was never written to */
Sim->Warning ("Reading from uninitialized memory at $%04X", Addr);
}
/* Read the cell and return the value */
return D->Mem[Addr];
}