Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
Macros | Functions | Variables
cpu65.c File Reference
#include "xemu/emutools_basicdefs.h"
#include "xemu/cpu65.h"
Include dependency graph for cpu65.c:

Go to the source code of this file.

Macros

#define SP_HI   0x100
 
#define ZP_HI   0
 
#define CPU_TYPE   "65C02"
 
#define ZERO_REG   0
 
#define A_OP(op, dat)   CPU65.a = CPU65.a op dat
 
#define TIMINGS_65CE02_   {7,5,2,2,4,3,4,4,3,2,1,1,5,4,5,4,2,5,5,3,4,3,4,4,1,4,1,1,5,4,5,4,5,5,7,7,3,3,4,4,3,2,1,1,4,4,5,4,2,5,5,3,3,3,4,4,1,4,1,1,4,4,5,4,5,5,2,2,4,3,4,4,3,2,1,1,3,4,5,4,2,5,5,3,4,3,4,4,2,4,3,1,4,4,5,4,4,5,7,5,3,3,4,4,3,2,1,1,5,4,5,4,2,5,5,3,3,3,4,4,2,4,3,1,5,4,5,4,2,5,6,3,3,3,3,4,1,2,1,4,4,4,4,4,2,5,5,3,3,3,3,4,1,4,1,4,4,4,4,4,2,5,2,2,3,3,3,4,1,2,1,4,4,4,4,4,2,5,5,3,3,3,3,4,1,4,1,4,4,4,4,4,2,5,2,6,3,3,4,4,1,2,1,7,4,4,5,4,2,5,5,3,3,3,4,4,1,4,3,3,4,4,5,4,2,5,6,6,3,3,4,4,1,2,1,7,4,4,5,4,2,5,5,3,5,3,4,4,1,4,3,3,7,4,5,4}
 
#define TIMINGS_65CE02   {7,5,2,2,4,3,4,4,3,2,1,1,5,4,5,4,2,5,5,3,4,3,4,4,1,4,1,1,5,4,5,4,2,5,7,7,4,3,4,4,3,2,1,1,5,4,4,4,2,5,5,3,4,3,4,4,1,4,1,1,5,4,5,4,5,5,2,2,4,3,4,4,3,2,1,1,3,4,5,4,2,5,5,3,4,3,4,4,1,4,3,3,4,4,5,4,4,5,7,5,3,3,4,4,3,2,1,1,5,4,5,4,2,5,5,3,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U65_PF_N; else CPU65.pf_nz &= ~CPU65_PF_N; } while(0)
 
#define writeFlatAddressedByte(d)   cpu65_write_linear_opcode_callback(d)
 
#define readFlatAddressedByte()   cpu65_read_linear_opcode_callback()
 
#define writeFlatAddressedQuadWithZ(d)   cpu65_write_linear_long_opcode_callback(CPU65.z, d)
 
#define readFlatAddressedQuadWithZ()   cpu65_read_linear_long_opcode_callback(CPU65.z)
 
#define writeFlatAddressedQuadWithoutZ(d)   cpu65_write_linear_long_opcode_callback(0, d)
 
#define readFlatAddressedQuadWithoutZ()   cpu65_read_linear_long_opcode_callback(0)
 
#define writeByteTwice(a, od, nd)   cpu65_write_rmw_callback(a,od,nd)
 
#define writeByte(a, d)   cpu65_write_callback(a,d)
 
#define readByte(a)   cpu65_read_callback(a)
 
#define IS_CPU_NMOS   0
 
#define NMOS_JAM_OPCODE()
 
#define HAS_NMOS_BUG_JMP_INDIRECT   0
 
#define HAS_NMOS_BUG_NO_PFD_RES_ON_INT   0
 
#define HAS_NMOS_BUG_BCD   0
 
#define push(data)   writeByte(((Uint8)(CPU65.s--)) | SP_HI, data)
 
#define pop()   readByte(((Uint8)(++CPU65.s)) | SP_HI)
 
#define _imm()   (CPU65.pc++)
 
#define _absx()   ((Uint16)(_abs() + CPU65.x))
 
#define _absy()   ((Uint16)(_abs() + CPU65.y))
 
#define _absi()   readWord(_abs())
 
#define _absxi()   readWord(_absx())
 
#define _zp()   (readByte(CPU65.pc++) | ZP_HI)
 
#define _zpx()   (((readByte(CPU65.pc++) + CPU65.x) & 0xFF) | ZP_HI)
 
#define _zpy()   (((readByte(CPU65.pc++) + CPU65.y) & 0xFF) | ZP_HI)
 

Functions

void cpu65_set_pf (const Uint8 st)
 
Uint8 cpu65_get_pf (void)
 
void cpu65_reset (void)
 
int cpu65_step (void)
 

Variables

struct cpu65_st CPU65
 

Macro Definition Documentation

◆ _absi

#define _absi ( )    readWord(_abs())

Definition at line 421 of file cpu65.c.

◆ _absx

#define _absx ( )    ((Uint16)(_abs() + CPU65.x))

Definition at line 419 of file cpu65.c.

◆ _absxi

#define _absxi ( )    readWord(_absx())

Definition at line 422 of file cpu65.c.

◆ _absy

#define _absy ( )    ((Uint16)(_abs() + CPU65.y))

Definition at line 420 of file cpu65.c.

◆ _imm

#define _imm ( )    (CPU65.pc++)

Definition at line 414 of file cpu65.c.

◆ _zp

#define _zp ( )    (readByte(CPU65.pc++) | ZP_HI)

Definition at line 423 of file cpu65.c.

◆ _zpx

#define _zpx ( )    (((readByte(CPU65.pc++) + CPU65.x) & 0xFF) | ZP_HI)

Definition at line 447 of file cpu65.c.

◆ _zpy

#define _zpy ( )    (((readByte(CPU65.pc++) + CPU65.y) & 0xFF) | ZP_HI)

Definition at line 448 of file cpu65.c.

◆ A_OP

#define A_OP (   op,
  dat 
)    CPU65.a = CPU65.a op dat

Definition at line 79 of file cpu65.c.

◆ ASSIGN_PF_N_BY_COND

#define ASSIGN_PF_N_BY_COND (   a)    do { if (a) CPU65.pf_nz |= CPU65_PF_N; else CPU65.pf_nz &= ~CPU65_PF_N; } while(0)

Definition at line 189 of file cpu65.c.

◆ ASSIGN_PF_Z_BY_COND

#define ASSIGN_PF_Z_BY_COND (   a)    do { if (a) CPU65.pf_nz |= CPU65_PF_Z; else CPU65.pf_nz &= ~CPU65_PF_Z; } while(0)

Definition at line 188 of file cpu65.c.

◆ CPU_TYPE

#define CPU_TYPE   "65C02"

Definition at line 74 of file cpu65.c.

◆ HAS_NMOS_BUG_BCD

#define HAS_NMOS_BUG_BCD   0

Definition at line 240 of file cpu65.c.

◆ HAS_NMOS_BUG_JMP_INDIRECT

#define HAS_NMOS_BUG_JMP_INDIRECT   0

Definition at line 238 of file cpu65.c.

◆ HAS_NMOS_BUG_NO_PFD_RES_ON_INT

#define HAS_NMOS_BUG_NO_PFD_RES_ON_INT   0

Definition at line 239 of file cpu65.c.

◆ IS_CPU_NMOS

#define IS_CPU_NMOS   0

Definition at line 236 of file cpu65.c.

◆ NMOS_JAM_OPCODE

#define NMOS_JAM_OPCODE ( )

Definition at line 237 of file cpu65.c.

◆ pop

#define pop ( )    readByte(((Uint8)(++CPU65.s)) | SP_HI)

Definition at line 298 of file cpu65.c.

◆ push

#define push (   data)    writeByte(((Uint8)(CPU65.s--)) | SP_HI, data)

Definition at line 297 of file cpu65.c.

◆ readByte

#define readByte (   a)    cpu65_read_callback(a)

Definition at line 206 of file cpu65.c.

◆ readFlatAddressedByte

#define readFlatAddressedByte ( )    cpu65_read_linear_opcode_callback()

Definition at line 194 of file cpu65.c.

◆ readFlatAddressedQuadWithoutZ

#define readFlatAddressedQuadWithoutZ ( )    cpu65_read_linear_long_opcode_callback(0)

Definition at line 199 of file cpu65.c.

◆ readFlatAddressedQuadWithZ

#define readFlatAddressedQuadWithZ ( )    cpu65_read_linear_long_opcode_callback(CPU65.z)

Definition at line 197 of file cpu65.c.

◆ SP_HI

#define SP_HI   0x100

Definition at line 69 of file cpu65.c.

◆ TIMINGS_6502C65

#define TIMINGS_6502C65   {7,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6,2,5,5,8,4,4,6,6,2,4,2,7,4,4,7,7,6,6,7,8,3,3,5,5,4,2,2,2,4,4,6,6,2,5,5,8,4,4,6,6,2,4,2,7,4,4,7,7,6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6,2,5,5,8,4,4,6,6,2,4,2,7,4,4,7,7,6,6,7,8,3,3,5,5,4,2,2,2,5,4,6,6,2,5,5,8,4,4,6,6,2,4,2,7,4,4,7,7,2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,2,6,5,6,4,4,4,4,2,5,2,5,5,5,5,5,2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,2,5,5,5,4,4,4,4,2,4,2,4,4,4,4,4,2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,2,5,5,8,4,4,6,6,2,4,2,7,4,4,7,7,2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,2,5,5,8,4,4,6,6,2,4,2,7,4,4,7,7}

Defin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,4,2,5,2,2,3,3,3,4,1,2,1,4,4,4,4,4,2,5,5,3,3,3,3,4,1,4,1,4,4,4,4,4,2,5,2,6,3,3,4,4,1,2,1,7,4,4,5,4,2,5,5,3,3,3,4,4,1,4,3,3,4,4,5,4,2,5,6,6,3,3,4,4,1,2,1,7,4,4,5,4,2,5,5,3,5,3,4,4,1,4,3,3,7,4,5,4}

Definition at line 116 of file cpu65.c.

◆ VALUE_TO_PF_ZERO

#define VALUE_TO_PF_ZERO (   a)    ((a) ? 0 : CPU65_PF_Z)

Definition at line 181 of file cpu65.c.

◆ writeByte

#define writeByte (   a,
 
)    cpu65_write_callback(a,d)

Definition at line 205 of file cpu65.c.

◆ writeByteTwice

#define writeByteTwice (   a,
  od,
  nd 
)    cpu65_write_rmw_callback(a,od,nd)

Definition at line 203 of file cpu65.c.

◆ writeFlatAddressedByte

#define writeFlatAddressedByte (   d)    cpu65_write_linear_opcode_callback(d)

Definition at line 193 of file cpu65.c.

◆ writeFlatAddressedQuadWithoutZ

#define writeFlatAddressedQuadWithoutZ (   d)    cpu65_write_linear_long_opcode_callback(0, d)

Definition at line 198 of file cpu65.c.

◆ writeFlatAddressedQuadWithZ

#define writeFlatAddressedQuadWithZ (   d)    cpu65_write_linear_long_opcode_callback(CPU65.z, d)

Definition at line 196 of file cpu65.c.

◆ ZERO_REG

#define ZERO_REG   0

Definition at line 76 of file cpu65.c.

◆ ZP_HI

#define ZP_HI   0

Definition at line 70 of file cpu65.c.

Function Documentation

◆ cpu65_get_pf()

Uint8 cpu65_get_pf ( void  )

Definition at line 331 of file cpu65.c.

◆ cpu65_reset()

void cpu65_reset ( void  )

Definition at line 353 of file cpu65.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpu65_set_pf()

void cpu65_set_pf ( const Uint8  st)

Definition at line 313 of file cpu65.c.

Here is the caller graph for this function:

◆ cpu65_step()

int cpu65_step ( void  )

Definition at line 796 of file cpu65.c.

Variable Documentation

◆ CPU65

struct cpu65_st CPU65

Definition at line 60 of file cpu65.c.