From 74ee7a44a91352cc49f112c87a27f031a877f766 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 5 Apr 2012 19:55:04 +0000 Subject: [PATCH] One more intermediate state - not compilable. git-svn-id: svn://svn.cc65.org/cc65/trunk@5644 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/sim65/chip.c | 11 +++--- src/sim65/chip.h | 8 ++-- src/sim65/config.c | 6 +-- src/sim65/cpu-6502.c | 6 +-- src/sim65/cpu-6502.h | 16 ++++---- src/sim65/cpucore.c | 13 +------ src/sim65/cpucore.h | 12 +++--- src/sim65/cpudata.h | 88 ++++++++++++++++++++++++++++++++++++++++++++ src/sim65/main.c | 4 +- src/sim65/system.c | 13 +++---- src/sim65/system.h | 33 ++++++++++------- 11 files changed, 147 insertions(+), 63 deletions(-) create mode 100644 src/sim65/cpudata.h diff --git a/src/sim65/chip.c b/src/sim65/chip.c index 7d1504bf9..4a3cc39a1 100644 --- a/src/sim65/chip.c +++ b/src/sim65/chip.c @@ -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 */ @@ -44,10 +44,10 @@ /* sim65 */ #include "cfgdata.h" +#include "chip.h" #include "chipdata.h" #include "cpucore.h" #include "error.h" -#include "chip.h" @@ -301,6 +301,7 @@ ChipInstance* MirrorChipInstance (const ChipInstance* Orig, unsigned Addr) /* Initialize the fields */ CI->C = Orig->C; + CI->AS = 0; CI->Addr = Addr; CI->Size = Orig->Size; CI->Data = Orig->Data; diff --git a/src/sim65/chip.h b/src/sim65/chip.h index f614c0ced..ddfad2475 100644 --- a/src/sim65/chip.h +++ b/src/sim65/chip.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ diff --git a/src/sim65/config.c b/src/sim65/config.c index 7c828026c..36187224c 100644 --- a/src/sim65/config.c +++ b/src/sim65/config.c @@ -143,8 +143,8 @@ static void ParseCPU (void) AttrCheck (Attr, atType, "TYPE"); AttrCheck (Attr, atAddrSpace, "ADDRSPACE"); - /* Create the CPU */ - CPUInstance = NewCPU ("6502", Size); + /* Create the system using the specified CPU */ + System = NewSystem (NewCPU ("6502", Size)); /* Skip the semicolon */ CfgConsumeSemi (); @@ -158,7 +158,7 @@ static void ParseAddrSpace (void) unsigned I; /* CPU must be defined before the address space */ - if (CPUInstance == 0) { + if (System == 0) { CfgError ("CPU must be defined before address space definitions"); } diff --git a/src/sim65/cpu-6502.c b/src/sim65/cpu-6502.c index 39929634d..06ef2cf3f 100644 --- a/src/sim65/cpu-6502.c +++ b/src/sim65/cpu-6502.c @@ -1,6 +1,6 @@ /*****************************************************************************/ /* */ -/* cpucore.c */ +/* cpu-6502.c */ /* */ /* CPU core for the 6502 simulator */ /* */ @@ -44,17 +44,17 @@ #include "strbuf.h" /* sim65 */ +#include "cpu-6502.h" #include "cpuregs.h" #include "cputype.h" #include "error.h" #include "global.h" #include "memory.h" -#include "cpucore.h" /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ diff --git a/src/sim65/cpu-6502.h b/src/sim65/cpu-6502.h index b88617143..469cf60c8 100644 --- a/src/sim65/cpu-6502.h +++ b/src/sim65/cpu-6502.h @@ -1,15 +1,15 @@ /*****************************************************************************/ /* */ -/* cpucore.h */ +/* cpu-6502.h */ /* */ /* CPU core for the 6502 simulator */ /* */ /* */ /* */ -/* (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 */ @@ -33,8 +33,8 @@ -#ifndef CPUCORE_H -#define CPUCORE_H +#ifndef CPU_6502_H +#define CPU_6502_H @@ -80,7 +80,7 @@ void CPURun (void); -/* End of cpucore.h */ +/* End of cpu-6502.h */ #endif diff --git a/src/sim65/cpucore.c b/src/sim65/cpucore.c index e4e189f6d..ad0c70897 100644 --- a/src/sim65/cpucore.c +++ b/src/sim65/cpucore.c @@ -44,17 +44,6 @@ -/*****************************************************************************/ -/* Data */ -/*****************************************************************************/ - - - -/* The actual CPU instance */ -CPUCore* CPU = 0; - - - /*****************************************************************************/ /* Code */ /*****************************************************************************/ @@ -76,7 +65,7 @@ CPUCore* NewCPUCore (const char* Name, unsigned AddrSpaceSize) /* Initialize the data */ C->Handle = 0; /* ### */ - C->AS = NewAddressSpace (AddrSpaceSize); + C->AddressSize = AddrSpaceSize; /* Return the new CPU core */ return C; diff --git a/src/sim65/cpucore.h b/src/sim65/cpucore.h index 28b9351ff..fba8fb835 100644 --- a/src/sim65/cpucore.h +++ b/src/sim65/cpucore.h @@ -52,12 +52,14 @@ /* CPU core structure */ typedef struct CPUCore CPUCore; struct CPUCore { - void* Handle; /* Pointer to shared lib handle */ - AddressSpace* AS; /* Address space */ -}; + void* Handle; /* Pointer to shared lib handle */ + unsigned AddressSize; /* Size of the address space */ + + /* Callback functions */ + -/* The actual CPU instance */ -extern CPUCore* CPU; + +}; diff --git a/src/sim65/cpudata.h b/src/sim65/cpudata.h new file mode 100644 index 000000000..b0bde1aea --- /dev/null +++ b/src/sim65/cpudata.h @@ -0,0 +1,88 @@ +/*****************************************************************************/ +/* */ +/* cpudata.h */ +/* */ +/* CPU data passed from the CPU plugins */ +/* */ +/* */ +/* */ +/* (C) 2012, Ullrich von Bassewitz */ +/* Roemerstrasse 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 CPUDATA_H +#define CPUDATA_H + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Forwards */ +struct SimData; + +/* CPUData structure */ +typedef struct CPUData CPUData; +struct CPUData { + const char* CPUName; /* Name of the chip */ + unsigned MajorVersion; /* Version information */ + unsigned MinorVersion; + + /* -- Exported functions -- */ + + void Init (const struct SimData* Data); + /* Initialize the CPU module */ + + void* (*CreateInstance) (void* CfgInfo); + /* Create an instance of the CPU. Return the instance data pointer */ + + void (*DestroyInstance) (void* Data); + /* Destroy an instance of the CPU */ + + void Reset (void* Data); + /* Generate a CPU RESET */ + + void IRQRequest (void* Data); + /* Generate an IRQ */ + + void NMIRequest (void* Data); + /* Generate an NMI */ + + void Run (void* Data); + /* Run one CPU instruction */ +}; + + + +/* End of cpudata.h */ + +#endif + + + diff --git a/src/sim65/main.c b/src/sim65/main.c index c0c6c44fd..f3bb8a112 100644 --- a/src/sim65/main.c +++ b/src/sim65/main.c @@ -111,7 +111,7 @@ static void OptChipDir (const char* Opt attribute ((unused)), const char* Arg) char* Name; struct stat S; - /* ### Ignore anything buy *.so files */ + /* ### Ignore anything but *.so files */ unsigned NameLen = strlen (E->d_name); if (NameLen <= 3) { continue; @@ -168,7 +168,7 @@ static void OptConfig (const char* Opt attribute ((unused)), const char* Arg) { if (CfgAvail ()) { Error ("Cannot use -C twice"); - } + } CfgSetName (Arg); } diff --git a/src/sim65/system.c b/src/sim65/system.c index 99bdbee78..d8860a799 100644 --- a/src/sim65/system.c +++ b/src/sim65/system.c @@ -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 */ @@ -37,7 +37,6 @@ #include "xmalloc.h" /* sim65 */ -#include "addrspace.h" #include "system.h" @@ -48,7 +47,7 @@ -System* NewSystem (struct CPUData* CPU) +System* NewSystem (CPUCore* CPU) /* Create and initialize a new System struct. The function will read the size * of the address space from the CPU, and also create a new AddressSpace * object. No chips are assigned, however. @@ -59,7 +58,7 @@ System* NewSystem (struct CPUData* CPU) /* Initialize the fields */ Sys->CPU = CPU; - Sys->AS = 0; /* ### */ + Sys->AS = NewAddressSpace (CPU->AddressSize); Sys->ChipInstances = AUTO_COLLECTION_INITIALIZER; /* Return the new system */ diff --git a/src/sim65/system.h b/src/sim65/system.h index bd2f5eb5c..873a3f7b3 100644 --- a/src/sim65/system.h +++ b/src/sim65/system.h @@ -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 */ @@ -41,6 +41,10 @@ /* common.h */ #include "coll.h" +/* sim65 */ +#include "addrspace.h" +#include "cpucore.h" + /*****************************************************************************/ @@ -50,29 +54,30 @@ /* Forwards */ -struct CPUData; +struct CPUCore; /* */ typedef struct System System; struct System { - - struct CPUData* CPU; /* The CPU in the system */ - struct AddressSpace* AS; /* The CPU address space */ - Collection ChipInstances;/* Instances of all the chips */ - + CPUCore* CPU; /* The CPU in the system */ + AddressSpace* AS; /* The CPU address space */ + Collection ChipInstances; /* Instances of all the chips */ }; +/* Global pointer to simulated system */ +extern System* System; + /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ -System* NewSystem (struct CPUData* CPU); -/* Create and initialize a new System struct. The function will read the size - * of the address space from the CPU, and also create a new AddressSpace +System* NewSystem (CPUCore* CPU); +/* Create and initialize a new System struct. The function will read the size + * of the address space from the CPU, and also create a new AddressSpace * object. No chips are assigned, however. */ -- 2.39.5