1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 02:29:52 +00:00

Intermediate state - doesn't run as is.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5643 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2012-04-05 13:30:21 +00:00
parent 032c16dda4
commit 10d58204b5
19 changed files with 2943 additions and 2648 deletions

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2003-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2002-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -57,17 +57,14 @@ CfgData* NewCfgData (void)
* uses the current output of the config scanner.
*/
{
/* Get the length of the identifier */
unsigned AttrLen = strlen (CfgSVal);
/* Allocate memory */
CfgData* D = xmalloc (sizeof (CfgData) + AttrLen);
CfgData* D = xmalloc (sizeof (CfgData) + SB_GetLen (&CfgSVal));
/* Initialize the fields */
D->Type = CfgDataInvalid;
D->Line = CfgErrorLine;
D->Col = CfgErrorCol;
memcpy (D->Attr, CfgSVal, AttrLen+1);
memcpy (D->Attr, SB_GetConstBuf (&CfgSVal), SB_GetLen (&CfgSVal) + 1);
/* Return the new struct */
return D;
@ -78,7 +75,7 @@ CfgData* NewCfgData (void)
void FreeCfgData (CfgData* D)
/* Free a config data structure */
{
if (D->Type == CfgDataString) {
if (D->Type == CfgDataId || D->Type == CfgDataString) {
/* Free the string value */
xfree (D->V.SVal);
}

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2002-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -58,7 +58,7 @@ struct CfgData {
CfgDataString
} Type; /* Type of the value */
union {
char* SVal; /* String or id value */
char* SVal; /* String or id value */
long IVal; /* Integer value */
} V;
unsigned Line; /* Line where the attribute was defined */

View File

@ -105,6 +105,8 @@ static const SimData Sim65Data = {
GetCfgId,
GetCfgStr,
GetCfgNum,
0,
0,
Break,
IRQRequest,
NMIRequest,
@ -156,7 +158,7 @@ static int GetCfgNum (void* CfgInfo, const char* Name, long* Val)
static int CmpChips (void* Data attribute ((unused)),
const void* lhs, const void* rhs)
const void* lhs, const void* rhs)
/* Compare function for CollSort */
{
/* Cast the object pointers */
@ -404,7 +406,7 @@ void LoadChipLibrary (const char* LibName)
/* Output chip name and version to keep the user happy */
Print (stdout, 1,
" Found %s `%s', version %u.%u in library `%s'\n",
(D->Type == CHIPDATA_TYPE_CHIP)? "chip" : "cpu",
(D->Type == CHIPDATA_TYPE_CHIP)? "chip" : "cpu",
D->ChipName,
D->MajorVersion,
D->MinorVersion,

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2003-2009, Ullrich von Bassewitz */
/* (C) 2003-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */

View File

@ -6,7 +6,7 @@
COMMON = ../../common
SIM65 = ..
CFLAGS = -g -O2 -Wall -W -std=c89
CFLAGS = -g -Wall -W -std=c89
override CFLAGS += -I$(COMMON) -I$(SIM65) -fpic
CC = gcc
EBIND = emxbind

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2002-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -60,9 +60,15 @@ static void* CreateInstance (unsigned Addr, unsigned Range, void* CfgInfo);
static void DestroyInstance (void* Data);
/* Destroy a chip instance */
static void WriteCtrl (void* Data, unsigned Offs, unsigned char Val);
/* Write control data */
static void Write (void* Data, unsigned Offs, unsigned char Val);
/* Write user data */
static unsigned char ReadCtrl (void* Data, unsigned Offs);
/* Read control data */
static unsigned char Read (void* Data, unsigned Offs);
/* Read user data */
@ -74,6 +80,9 @@ static unsigned char Read (void* Data, unsigned Offs);
/* The SimData pointer we get when InitChip is called */
static const SimData* Sim;
/* Control data passed to the main program */
static const struct ChipData CData[1] = {
{
@ -86,15 +95,33 @@ static const struct ChipData CData[1] = {
InitChip,
CreateInstance,
DestroyInstance,
WriteCtrl,
Write,
Write,
Read,
ReadCtrl,
Read
}
};
/* The SimData pointer we get when InitChip is called */
static const SimData* Sim;
/* Screen instance data */
typedef struct InstanceData InstanceData;
struct InstanceData {
/* The memory area used for data */
unsigned char* Mem[32];
};
/* Function opcodes */
enum {
F_open,
F_close,
F_write,
F_read,
F_lseek,
F_unlink,
F_chdir,
F_getcwd,
F_mkdir,
F_rmdir,
};
@ -137,8 +164,14 @@ static int InitChip (const struct SimData* Data)
static void* CreateInstance (unsigned Addr, unsigned Range, void* CfgInfo)
/* Initialize a new chip instance */
{
/* We don't need any instance data */
return 0;
/* Allocate the instance data */
InstanceData* D = Sim->Malloc (sizeof (InstanceData));
/* Initialize the instance data */
memset (D->Mem, 0x00, sizeof (D->Mem));
/* Return the instance data */
return D;
}
@ -146,28 +179,111 @@ static void* CreateInstance (unsigned Addr, unsigned Range, void* CfgInfo)
static void DestroyInstance (void* Data)
/* Destroy a chip instance */
{
/* Cast the instance data pointer */
InstanceData* D = Data;
/* Free the instance data */
Sim->Free (D);
}
static void Write (void* Data attribute ((unused)),
unsigned Offs attribute ((unused)),
unsigned char Val)
static void WriteCtrl (void* Data attribute, unsigned Offs, unsigned char Val)
/* Write user data */
{
putchar (Val);
/* Cast the instance data pointer */
InstanceData* D = Data;
/* Write to the memory */
D->Mem[Offs] = Val;
}
static unsigned char Read (void* Data attribute ((unused)),
unsigned Offs attribute ((unused)))
static void Write (void* Data, unsigned Offs, unsigned char Val)
/* Write user data */
{
/* Cast the instance data pointer */
InstanceData* D = Data;
/* Write to the memory */
D->Mem[Offs] = Val;
/* Now check the offset. Zero is special because it will trigger the
* action
*/
if (Offs == 0) {
/* The action is determined by the value that is written */
switch (Val) {
case F_open:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_close:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_write:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_read:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_lseek:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_unlink:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_chdir:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_getcwd:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_mkdir:
Sim->Break ("Unsupported function $%02X", Val);
break;
case F_rmdir:
Sim->Break ("Unsupported function $%02X", Val);
break;
}
}
}
static unsigned char ReadCtrl (void* Data, unsigned Offs)
/* Read user data */
{
/* Read a character and return the value */
return getchar ();
/* Cast the instance data pointer */
InstanceData* D = Data;
/* Read the cell and return the value */
return D->Mem[Offs];
}
static unsigned char Read (void* Data, unsigned Offs)
/* Read user data */
{
/* Cast the instance data pointer */
InstanceData* D = Data;
/* Read the cell and return the value */
return D->Mem[Offs];
}

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -46,11 +46,11 @@
#include "xmalloc.h"
/* sim65 */
#include "addrspace.h"
#include "cfgdata.h"
#include "chip.h"
#include "error.h"
#include "global.h"
#include "memory.h"
#include "location.h"
#include "scanner.h"
#include "config.h"
@ -143,18 +143,26 @@ static void ParseCPU (void)
AttrCheck (Attr, atType, "TYPE");
AttrCheck (Attr, atAddrSpace, "ADDRSPACE");
/* Create the CPU */
CPUInstance = NewCPU ("6502", Size);
/* Skip the semicolon */
CfgConsumeSemi ();
}
static void ParseMemory (void)
/* Parse a MEMORY section */
static void ParseAddrSpace (void)
/* Parse a ADDRSPACE section */
{
unsigned I;
/* CPU must be defined before the address space */
if (CPUInstance == 0) {
CfgError ("CPU must be defined before address space definitions");
}
/* Parse addresses */
while (CfgTok == CFGTOK_INTCON) {
Location* L;
@ -263,8 +271,8 @@ static void ParseMemory (void)
/* Delete the "name" attribute */
FreeCfgData (D);
/* Assign the chip instance to memory */
MemAssignChip (CI, L->Start, Range);
/* Assign the chip instance to address space */
ASAssignChip (CPUInstance->AS, CI, L->Start, Range);
}
/* Create the mirrors */
@ -295,7 +303,7 @@ static void ParseMemory (void)
/* For simplicity, get the chip instance we're mirroring from the
* memory, instead of searching for the range in the list.
*/
CI = MemGetChip (MirrorAddr);
CI = ASGetChip (MirrorAddr);
if (CI == 0) {
/* We are mirroring an unassigned address */
Error ("%s(%u): Mirroring an unassigned address",
@ -316,8 +324,8 @@ static void ParseMemory (void)
/* Clone the chip instance for the new location */
MCI = MirrorChipInstance (CI, L->Start - Offs);
/* Assign the chip instance to memory */
MemAssignChip (MCI, L->Start, Range);
/* Assign the chip instance to address space */
ASAssignChip (CPUInstance->AS, MCI, L->Start, Range);
}
}
@ -327,8 +335,8 @@ static void ParseConfig (void)
/* Parse the config file */
{
static const IdentTok BlockNames [] = {
{ "CPU", CFGTOK_CPU },
{ "MEMORY", CFGTOK_MEMORY },
{ "ADDRSPACE", CFGTOK_ADDRSPACE },
{ "CPU", CFGTOK_CPU },
};
cfgtok_t BlockTok;
@ -345,12 +353,12 @@ static void ParseConfig (void)
/* Read the block */
switch (BlockTok) {
case CFGTOK_CPU:
ParseCPU ();
case CFGTOK_ADDRSPACE:
ParseAddrSpace ();
break;
case CFGTOK_MEMORY:
ParseMemory ();
case CFGTOK_CPU:
ParseCPU ();
break;
default:

2592
src/sim65/cpu-6502.c Normal file

File diff suppressed because it is too large Load Diff

88
src/sim65/cpu-6502.h Normal file
View File

@ -0,0 +1,88 @@
/*****************************************************************************/
/* */
/* cpucore.h */
/* */
/* CPU core for the 6502 simulator */
/* */
/* */
/* */
/* (C) 2002-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#ifndef CPUCORE_H
#define CPUCORE_H
/* sim65 */
#include "cpuregs.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Registers */
extern CPURegs Regs;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void CPUInit (void);
/* Initialize the CPU */
void RESET (void);
/* Generate a CPU RESET */
void IRQRequest (void);
/* Generate an IRQ */
void NMIRequest (void);
/* Generate an NMI */
void Break (const char* Format, ...);
/* Stop running and display the given message */
void CPURun (void);
/* Run one CPU instruction */
/* End of cpucore.h */
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
/*****************************************************************************/
/* */
/* cpucore.h */
/* cpucore.h */
/* */
/* CPU core for the 6502 simulator */
/* CPU definition for the simulator */
/* */
/* */
/* */
/* (C) 2002-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2003-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -39,44 +39,36 @@
/* sim65 */
#include "cpuregs.h"
#include "addrspace.h"
/*****************************************************************************/
/* Data */
/* Data */
/*****************************************************************************/
/* Registers */
extern CPURegs Regs;
/* CPU core structure */
typedef struct CPUCore CPUCore;
struct CPUCore {
void* Handle; /* Pointer to shared lib handle */
AddressSpace* AS; /* Address space */
};
/* The actual CPU instance */
extern CPUCore* CPU;
/*****************************************************************************/
/* Code */
/* Code */
/*****************************************************************************/
void CPUInit (void);
/* Initialize the CPU */
void RESET (void);
/* Generate a CPU RESET */
void IRQRequest (void);
/* Generate an IRQ */
void NMIRequest (void);
/* Generate an NMI */
void Break (const char* Format, ...);
/* Stop running and display the given message */
void CPURun (void);
/* Run one CPU instruction */
CPUCore* NewCPUCore (const char* Name, unsigned AddrSpaceSize);
/* Create and return a new CPU including it's address space */
@ -86,3 +78,4 @@ void CPURun (void);

View File

@ -12,7 +12,7 @@ COMMON = ../common
#
CC = gcc
CFLAGS = -g -O2 -Wall -W -std=c89
CFLAGS = -g -Wall -W -std=c89
override CFLAGS += -I$(COMMON)
EBIND = emxbind
LDFLAGS = -ldl
@ -27,13 +27,13 @@ OBJS = addrspace.o \
chip.o \
chippath.o \
config.o \
cpu-6502.o \
cpucore.o \
cputype.o \
error.o \
global.o \
location.o \
main.o \
memory.o \
scanner.o \
system.o

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2002-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2002-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -57,7 +57,7 @@
/* Current token and attributes */
cfgtok_t CfgTok;
char CfgSVal [CFG_MAX_IDENT_LEN+1];
StrBuf CfgSVal = STATIC_STRBUF_INITIALIZER;
unsigned long CfgIVal;
/* Error location */
@ -266,7 +266,7 @@ Again:
I = 0;
while (C != '\"') {
if (C == EOF || C == '\n') {
Error ("%s(%u): Unterminated string", CfgName, InputLine);
Error ("%s(%u): Unterminated string", CfgName, InputLine);
}
if (I < CFG_MAX_IDENT_LEN) {
CfgSVal [I++] = C;

View File

@ -1,15 +1,15 @@
/*****************************************************************************/
/* */
/* scanner.h */
/* scanner.h */
/* */
/* Configuration file scanner for the sim65 6502 simulator */
/* */
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -40,6 +40,7 @@
/* common */
#include "attrib.h"
#include "strbuf.h"
@ -67,12 +68,11 @@ typedef enum {
/* Primary blocks */
CFGTOK_CPU,
CFGTOK_MEMORY,
/* CPU block */
CFGTOK_TYPE,
CFGTOK_ADDRSPACE,
/* Secondary stuff */
CFGTOK_TYPE,
/* Special identifiers */
CFGTOK_TRUE,
CFGTOK_FALSE
@ -92,9 +92,8 @@ struct IdentTok {
/* Current token and attributes */
#define CFG_MAX_IDENT_LEN 255
extern cfgtok_t CfgTok;
extern char CfgSVal [CFG_MAX_IDENT_LEN+1];
extern StrBuf CfgSVal;
extern unsigned long CfgIVal;
/* Error location */

View File

@ -89,6 +89,12 @@ struct SimData {
* true. If not found, return false.
*/
unsigned char (*ReadCtrl) (unsigned Addr);
/* Read from the given address without triggering any additional action */
void (*WriteCtrl) (unsigned Addr, unsigned char Val);
/* Write to the given address without triggering additional action */
void (*Break) (const char* Format, ...);
/* Stop the CPU and display the given message */
@ -98,7 +104,7 @@ struct SimData {
void (*NMI) (void);
/* Issue an nmi request */
};