Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
cpu65.h
Go to the documentation of this file.
1 /* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
2  Copyright (C)2016-2021 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3 
4 | For more information about "cpu65" please also read comments in file cpu65.c |
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19 
20 #ifndef XEMU_COMMON_CPU65_H_INCLUDED
21 #define XEMU_COMMON_CPU65_H_INCLUDED
22 
23 #define CPU65_PF_N 0x80
24 #define CPU65_PF_V 0x40
25 #define CPU65_PF_E 0x20
26 #define CPU65_PF_B 0x10
27 #define CPU65_PF_D 0x08
28 #define CPU65_PF_I 0x04
29 #define CPU65_PF_Z 0x02
30 #define CPU65_PF_C 0x01
31 
32 /* Notes:
33  * cpu flags (pf_*) are INT in type, and "logic" types not actual bit mask.
34  this is because using flags are frequent and faster (maybe ... ?) this way,
35  and actual getting of the full flags register is much rare event when we
36  need to "construct" it from individual flag info data.
37  Type is "int" since in some cases they're implemented with > 8 bit data
38  length steps during opcode emulation.
39  * if CPU65_DISCRETE_PF_NZ is *NOT* defined:
40  pf_nz is an exception to the scheme above: 65xx CPU family is famous for
41  altering N and Z flags always if a general purpose register is filled,
42  even with eg TXA. So this is the way more frequent opcode flag operation
43  in general. Thus, I included two bits at the right bit position for N and
44  Z but not for the other flags though (see my previous comment).
45  * OK, maybe my theory is not the best, and it's not even optimal this way,
46  I have to admit ...
47  * 'B' bit (break flag) is not a real processor status flag. it depends on
48  the type of operation what the result is, eg BRK pushes it into the stack as
49  '1', while hardware interrupts as '0'
50 */
51 struct cpu65_st {
52  Uint8 a, x, y;
55 #ifdef MEGA65
56  int nmos_mode;
57  int prefix;
58 #endif
59 #ifdef CPU_65CE02
60  Uint8 z;
61  Uint16 bphi, sphi; // NOTE: it must store the value shifted to the high byte!
62  int cpu_inhibit_interrupts;
63  int pf_e;
64 #endif
65 #ifdef CPU65_DISCRETE_PF_NZ
66  int pf_n, pf_z;
67 #else
69 #endif
70  int pf_c, pf_v, pf_d, pf_i;
72  int multi_step_stop_trigger; // not used, only with multi-op mode but still here because some devices (like DMA) would use it
74  int op_cycles;
75 };
76 
77 #ifndef CPU65
78 #error "CPU65 must be defined."
79 #endif
80 
81 extern struct cpu65_st CPU65;
82 
83 #ifdef MEGA65
84 extern int cpu_mega65_opcodes;
85 extern void cpu65_init_mega_specific ( void );
86 #endif
87 
88 #ifdef CPU65_65CE02_6502NMOS_TIMING_EMULATION
89 extern void cpu65_set_timing ( unsigned int mode );
90 #endif
91 //extern int cpu_multi_step_stop_trigger;
92 
93 #ifndef CPU_CUSTOM_MEMORY_FUNCTIONS_H
94 extern void cpu65_write_callback ( Uint16 addr, Uint8 data );
95 #ifndef CPU65_NO_RMW_EMULATION
96 extern void cpu65_write_rmw_callback ( Uint16 addr, Uint8 old_data, Uint8 new_data );
97 #endif
99 #ifdef MEGA65
102 #endif
103 #if defined(CPU_6502_NMOS_ONLY) || defined(MEGA65)
104 extern void cpu65_illegal_opcode_callback ( void );
105 #endif
106 #else
107 #include CPU_CUSTOM_MEMORY_FUNCTIONS_H
108 #endif
109 
110 extern void cpu65_reset ( void );
111 extern int cpu65_step (
112 #ifdef CPU_STEP_MULTI_OPS
113  const int run_for_cycles
114 #else
115  void
116 #endif
117 );
118 
119 #ifdef CPU65_TRAP_OPCODE
120 extern int cpu65_trap_callback ( const Uint8 opcode );
121 #endif
122 #ifdef CPU_65CE02
123 extern void cpu65_do_aug_callback ( void );
124 extern void cpu65_do_nop_callback ( void );
125 #endif
126 
127 extern void cpu65_set_pf ( const Uint8 st );
128 extern Uint8 cpu65_get_pf ( void );
129 
130 #ifdef XEMU_SNAPSHOT_SUPPORT
131 #include "xemu/emutools_snapshot.h"
132 extern int cpu65_snapshot_load_state ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block );
133 extern int cpu65_snapshot_save_state ( const struct xemu_snapshot_definition_st *def );
134 #endif
135 
136 #endif
cpu65_st::multi_step_stop_trigger
int multi_step_stop_trigger
Definition: cpu65.h:72
cpu65_st::x
Uint8 x
Definition: cpu65.h:52
cpu65_st::pf_nz
Uint8 pf_nz
Definition: cpu65.h:68
cpu65_read_linear_opcode_callback
Uint8 cpu65_read_linear_opcode_callback(void)
Definition: memory_mapper.c:869
cpu_mega65_opcodes
int cpu_mega65_opcodes
Definition: io_mapper.c:41
cpu65_reset
void cpu65_reset(void)
Definition: cpu65.c:353
cpu65_st::irqLevel
int irqLevel
Definition: cpu65.h:73
cpu65_step
int cpu65_step(void)
Definition: cpu65.c:796
cpu65_st::s
Uint8 s
Definition: cpu65.h:53
addr
int addr
Definition: dma65.c:81
cpu65_st::y
Uint8 y
Definition: cpu65.h:52
m65-memcontent-generator.data
data
Definition: m65-memcontent-generator.py:119
Uint8
uint8_t Uint8
Definition: fat32.c:51
cpu65_write_linear_opcode_callback
void cpu65_write_linear_opcode_callback(Uint8 data)
Definition: memory_mapper.c:876
cpu65_st::pf_i
int pf_i
Definition: cpu65.h:70
cpu65_st::pf_c
int pf_c
Definition: cpu65.h:70
block
Uint32 block
Definition: fat32.c:156
cpu65_write_rmw_callback
void cpu65_write_rmw_callback(Uint16 addr, Uint8 old_data, Uint8 new_data)
Definition: commodore_65.c:741
cpu65_do_nop_callback
void cpu65_do_nop_callback(void)
Definition: commodore_65.c:434
cpu65_trap_callback
int cpu65_trap_callback(const Uint8 opcode)
Definition: commodore_geos.c:677
cpu65_st::nmiEdge
int nmiEdge
Definition: cpu65.h:73
cpu65_st::op_cycles
int op_cycles
Definition: cpu65.h:74
cpu65_st::pf_d
int pf_d
Definition: cpu65.h:70
cpu65_get_pf
Uint8 cpu65_get_pf(void)
Definition: cpu65.c:331
CPU_STEP_MULTI_OPS
#define CPU_STEP_MULTI_OPS
Definition: xemu-target.h:6
cpu65_st::old_pc
Uint16 old_pc
Definition: cpu65.h:71
cpu65_set_pf
void cpu65_set_pf(const Uint8 st)
Definition: cpu65.c:313
cpu65_read_callback
Uint8 cpu65_read_callback(Uint16 addr)
Definition: commodore_65.c:711
cpu65_st::a
Uint8 a
Definition: cpu65.h:52
cpu65_write_callback
void cpu65_write_callback(Uint16 addr, Uint8 data)
Definition: commodore_65.c:723
emutools_snapshot.h
cpu65_st::pc
Uint16 pc
Definition: cpu65.h:71
Uint16
uint16_t Uint16
Definition: fat32.c:50
cpu65_do_aug_callback
void cpu65_do_aug_callback(void)
Definition: commodore_65.c:418
cpu65_st
Definition: cpu65.h:51
cpu65_st::op
Uint8 op
Definition: cpu65.h:54
cpu65_st::pf_v
int pf_v
Definition: cpu65.h:70
CPU65
struct cpu65_st CPU65
Definition: cpu65.c:60
st
struct stat st
Definition: cpmfs.c:43
cpu65_illegal_opcode_callback
void cpu65_illegal_opcode_callback(void)
Definition: commodore_geos.c:709