mirror of
https://github.com/cc65/cc65.git
synced 2024-12-22 12:30:41 +00:00
Working
git-svn-id: svn://svn.cc65.org/cc65/trunk@2143 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
9330f3dc6a
commit
e9f6a0a3ab
@ -102,10 +102,12 @@ static const SimData Sim65Data = {
|
||||
Warning,
|
||||
Error,
|
||||
Internal,
|
||||
Break,
|
||||
GetCfgId,
|
||||
GetCfgStr,
|
||||
GetCfgNum
|
||||
GetCfgNum,
|
||||
Break,
|
||||
IRQRequest,
|
||||
NMIRequest,
|
||||
};
|
||||
|
||||
|
||||
|
@ -63,6 +63,92 @@
|
||||
|
||||
|
||||
|
||||
static void FlagAttr (unsigned* Flags, unsigned Mask, const char* Name)
|
||||
/* Check if the item is already defined. Print an error if so. If not, set
|
||||
* the marker that we have a definition now.
|
||||
*/
|
||||
{
|
||||
if (*Flags & Mask) {
|
||||
CfgError ("%s is already defined", Name);
|
||||
}
|
||||
*Flags |= Mask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void AttrCheck (unsigned Attr, unsigned Mask, const char* Name)
|
||||
/* Check that a mandatory attribute was given */
|
||||
{
|
||||
if ((Attr & Mask) == 0) {
|
||||
CfgError ("%s attribute is missing", Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void ParseCPU (void)
|
||||
/* Parse a CPU section */
|
||||
{
|
||||
static const IdentTok Attributes [] = {
|
||||
{ "TYPE", CFGTOK_TYPE },
|
||||
{ "ADDRSPACE", CFGTOK_ADDRSPACE },
|
||||
};
|
||||
|
||||
enum {
|
||||
atNone = 0x0000,
|
||||
atType = 0x0001,
|
||||
atAddrSpace = 0x0002
|
||||
};
|
||||
unsigned Attr = 0;
|
||||
unsigned long Size = 0;
|
||||
|
||||
|
||||
while (CfgTok == CFGTOK_IDENT) {
|
||||
|
||||
cfgtok_t AttrTok;
|
||||
CfgSpecialToken (Attributes, ENTRY_COUNT (Attributes), "Attribute");
|
||||
AttrTok = CfgTok;
|
||||
|
||||
/* An optional assignment follows */
|
||||
CfgNextTok ();
|
||||
CfgOptionalAssign ();
|
||||
|
||||
/* Check which attribute was given */
|
||||
switch (AttrTok) {
|
||||
|
||||
case CFGTOK_TYPE:
|
||||
FlagAttr (&Attr, atType, "TYPE");
|
||||
CfgAssureIdent ();
|
||||
/* ### */
|
||||
break;
|
||||
|
||||
case CFGTOK_ADDRSPACE:
|
||||
FlagAttr (&Attr, atAddrSpace, "ADDRSPACE");
|
||||
CfgAssureInt ();
|
||||
CfgRangeCheck (0x1000, 0x1000000);
|
||||
Size = CfgIVal;
|
||||
break;
|
||||
|
||||
default:
|
||||
FAIL ("Unexpected attribute token");
|
||||
|
||||
}
|
||||
|
||||
/* Skip the attribute value and an optional comma */
|
||||
CfgNextTok ();
|
||||
CfgOptionalComma ();
|
||||
}
|
||||
|
||||
/* Must have some attributes */
|
||||
AttrCheck (Attr, atType, "TYPE");
|
||||
AttrCheck (Attr, atAddrSpace, "ADDRSPACE");
|
||||
|
||||
/* Skip the semicolon */
|
||||
CfgConsumeSemi ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void ParseMemory (void)
|
||||
/* Parse a MEMORY section */
|
||||
{
|
||||
@ -241,6 +327,7 @@ static void ParseConfig (void)
|
||||
/* Parse the config file */
|
||||
{
|
||||
static const IdentTok BlockNames [] = {
|
||||
{ "CPU", CFGTOK_CPU },
|
||||
{ "MEMORY", CFGTOK_MEMORY },
|
||||
};
|
||||
cfgtok_t BlockTok;
|
||||
@ -258,6 +345,10 @@ static void ParseConfig (void)
|
||||
/* Read the block */
|
||||
switch (BlockTok) {
|
||||
|
||||
case CFGTOK_CPU:
|
||||
ParseCPU ();
|
||||
break;
|
||||
|
||||
case CFGTOK_MEMORY:
|
||||
ParseMemory ();
|
||||
break;
|
||||
@ -268,7 +359,7 @@ static void ParseConfig (void)
|
||||
}
|
||||
|
||||
/* Skip closing brace */
|
||||
CfgConsume (CFGTOK_RCURLY, "`}' expected");
|
||||
CfgConsumeRCurly ();
|
||||
|
||||
} while (CfgTok != CFGTOK_EOF);
|
||||
}
|
||||
|
1164
src/sim65/cpucore.c
1164
src/sim65/cpucore.c
File diff suppressed because it is too large
Load Diff
@ -38,33 +38,24 @@
|
||||
|
||||
|
||||
|
||||
/* sim65 */
|
||||
#include "cpuregs.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* Registers */
|
||||
extern unsigned char AC; /* Accumulator */
|
||||
extern unsigned char XR; /* X register */
|
||||
extern unsigned char YR; /* Y register */
|
||||
extern unsigned char SR; /* Status register */
|
||||
extern unsigned char SP; /* Stackpointer */
|
||||
extern unsigned PC; /* Program counter */
|
||||
|
||||
/* Status register bits */
|
||||
#define CF 0x01 /* Carry flag */
|
||||
#define ZF 0x02 /* Zero flag */
|
||||
#define IF 0x04 /* Interrupt flag */
|
||||
#define DF 0x08 /* Decimal flag */
|
||||
#define BF 0x10 /* Break flag */
|
||||
#define OF 0x40 /* Overflow flag */
|
||||
#define SF 0x80 /* Sign flag */
|
||||
extern CPURegs Regs;
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@ -72,20 +63,20 @@ extern unsigned PC; /* Program counter */
|
||||
void CPUInit (void);
|
||||
/* Initialize the CPU */
|
||||
|
||||
void Reset (void);
|
||||
/* Reset the CPU */
|
||||
void RESET (void);
|
||||
/* Generate a CPU RESET */
|
||||
|
||||
void IRQ (void);
|
||||
void IRQRequest (void);
|
||||
/* Generate an IRQ */
|
||||
|
||||
void NMI (void);
|
||||
void NMIRequest (void);
|
||||
/* Generate an NMI */
|
||||
|
||||
void Break (const char* Format, ...);
|
||||
/* Stop running and display the given message */
|
||||
|
||||
void CPURun (void);
|
||||
/* Run the CPU */
|
||||
/* Run one CPU instruction */
|
||||
|
||||
|
||||
|
||||
|
81
src/sim65/cpuregs.h
Normal file
81
src/sim65/cpuregs.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* cpuregs.h */
|
||||
/* */
|
||||
/* CPU registers */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 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 CPUREGS_H
|
||||
#define CPUREGS_H
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
typedef struct CPURegs CPURegs;
|
||||
struct CPURegs {
|
||||
unsigned AC; /* Accumulator */
|
||||
unsigned XR; /* X register */
|
||||
unsigned YR; /* Y register */
|
||||
unsigned ZR; /* Z register */
|
||||
unsigned SR; /* Status register */
|
||||
unsigned SP; /* Stackpointer */
|
||||
unsigned PC; /* Program counter */
|
||||
};
|
||||
|
||||
/* Status register bits */
|
||||
#define CF 0x01 /* Carry flag */
|
||||
#define ZF 0x02 /* Zero flag */
|
||||
#define IF 0x04 /* Interrupt flag */
|
||||
#define DF 0x08 /* Decimal flag */
|
||||
#define BF 0x10 /* Break flag */
|
||||
#define OF 0x40 /* Overflow flag */
|
||||
#define SF 0x80 /* Sign flag */
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* End of cpuregs.h */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -308,9 +308,10 @@ int main (int argc, char* argv[])
|
||||
CfgRead ();
|
||||
|
||||
CPUInit ();
|
||||
#if 1
|
||||
CPURun ();
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
CPURun ();
|
||||
}
|
||||
|
||||
/* Return an apropriate exit code */
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -237,7 +237,7 @@ Again:
|
||||
break;
|
||||
|
||||
case '.':
|
||||
NextChar ();
|
||||
NextChar ();
|
||||
if (C == '.') {
|
||||
NextChar ();
|
||||
CfgTok = CFGTOK_DOTDOT;
|
||||
@ -328,6 +328,14 @@ void CfgConsumeColon (void)
|
||||
|
||||
|
||||
|
||||
void CfgConsumeRCurly (void)
|
||||
/* Consume a right curly brace */
|
||||
{
|
||||
CfgConsume (CFGTOK_RCURLY, "`}' expected");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CfgOptionalComma (void)
|
||||
/* Consume a comma if there is one */
|
||||
{
|
||||
|
@ -37,7 +37,7 @@
|
||||
#define SCANNER_H
|
||||
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
|
||||
@ -66,8 +66,13 @@ typedef enum {
|
||||
CFGTOK_EOF,
|
||||
|
||||
/* Primary blocks */
|
||||
CFGTOK_CPU,
|
||||
CFGTOK_MEMORY,
|
||||
|
||||
/* CPU block */
|
||||
CFGTOK_TYPE,
|
||||
CFGTOK_ADDRSPACE,
|
||||
|
||||
/* Special identifiers */
|
||||
CFGTOK_TRUE,
|
||||
CFGTOK_FALSE
|
||||
@ -122,6 +127,9 @@ void CfgConsumeSemi (void);
|
||||
void CfgConsumeColon (void);
|
||||
/* Consume a colon */
|
||||
|
||||
void CfgConsumeRCurly (void);
|
||||
/* Consume a right curly brace */
|
||||
|
||||
void CfgOptionalComma (void);
|
||||
/* Consume a comma if there is one */
|
||||
|
||||
|
@ -67,9 +67,6 @@ struct SimData {
|
||||
void (*Internal) (const char* Format, ...);
|
||||
/* Print an internal program error and terminate */
|
||||
|
||||
void (*Break) (const char* Format, ...);
|
||||
/* Stop the CPU and display the given message */
|
||||
|
||||
int (*GetCfgId) (void* CfgInfo, const char* Name, char** Id);
|
||||
/* Search CfgInfo for an attribute with the given name and type "id". If
|
||||
* found, remove it from the configuration, pass a pointer to a dynamically
|
||||
@ -91,6 +88,18 @@ struct SimData {
|
||||
* If found, remove it from the configuration, copy it into Val and return
|
||||
* true. If not found, return false.
|
||||
*/
|
||||
|
||||
void (*Break) (const char* Format, ...);
|
||||
/* Stop the CPU and display the given message */
|
||||
|
||||
void (*IRQ) (void);
|
||||
/* Issue an irq request */
|
||||
|
||||
void (*NMI) (void);
|
||||
/* Issue an nmi request */
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user