/*

File: cpu.c
Author: Neil Cafferkey
Copyright (C) 1999-2001 Neil Cafferkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.

*/

#include "cpu_protos.h"
#include "instruction_set_protos.h"
#include "string_protos.h"
#include "memory_protos.h"
#include "config_protos.h"


#if 0
GetDisassembly(Address address);

GetCPUNextContinue()
Address GetCPUNextBranch(CPU cpu,Address address)
{
return GetNearAddress(address,GetInstructionLength(cpu,address));
}

GetCPUNextBranch(CPU cpu,Address address)
{

}


IsCPUContinue(CPU cpu,Address address)


BOOL IsCPUBranch(CPU cpu,Address address)
{
   return IsInSet(cpu->branch_instructions,*GetAddressContents(address));
}
#endif


/* Function: CreateCPU
 * ===================
 */

CPU CreateCPU(TEXT *name,InstructionSet instructions,
   ULONG interrupt_vector)
{
   CPU cpu=Malloc(sizeof(CPU_imp));

   cpu->name=name;
   cpu->instructions=instructions;
   cpu->interrupt_vector=interrupt_vector;

   return cpu;
}


/* Function: ReadCPU
 * =================
 */
#if 0
CPU ReadCPU(TEXT *file_name)
{
   return CreateCPU(file_name,ReadInstructionSet("MOS6507.txt"));
}
#endif

/* Function: ReadCPU
 * =================
 */

CPU ReadCPU(TEXT *file_name)
{
   Config config=ReadConfig(file_name);
   TEXT *name=GetStringConfigOption(config,"Name:");
   InstructionSet instructions=
      ReadInstructionSet(GetStringSetConfigOption(config,"Instructions:"));
   ULONG interrupt_vector=
      GetNumericConfigOption(config,"Interrupt Vector:");

   KillConfig(config);

   return CreateCPU(name,instructions,interrupt_vector);
}


/* Function: GetCPUInstruction
 * ===========================
 */

Instruction GetCPUInstruction(CPU cpu,Address address,
   SourceProgram src_prog)
{
   Instruction instruction=GetMatchingInstruction(cpu->instructions,address,
      src_prog);

   return instruction;
}


/* Function: GetCPUInterruptVector
 * ===============================
 */

ULONG GetCPUInterruptVector(CPU cpu)
{
   return cpu->interrupt_vector;
}


/* Function: KillCPU
 * =================
 */

VOID KillCPU(CPU cpu)
{
   KillString(cpu->name);
   KillSet(cpu->instructions);
   Free(cpu,sizeof(CPU_imp));

   return;
}


