2 * Simulator of microcontrollers (mos65c02.cc)
4 * Copyright (C) 2020 Drotos Daniel
6 * To contact author send email to dr.dkdb@gmail.com
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
33 #include "mos65c02cl.h"
36 cl_mos65c02::cl_mos65c02(class cl_sim
*asim
):
43 cl_mos65c02::init(void)
47 // Map all 0x_3 into NOP 1,1
48 for (i
=0x13; i
<=0xf3; i
+= 0x10)
49 itab
[i
]= instruction_wrapper_03
;
50 // Map all 0x_b into NOP 1,1
51 for (i
=0x0b; i
<=0xfb; i
+= 0x10)
52 itab
[i
]= instruction_wrapper_03
;
57 cl_mos65c02::reset(void)
64 cl_mos65c02::get_dis_entry(t_addr addr
)
66 struct dis_entry
*de
= cl_mos6502::get_dis_entry(addr
);
70 t_mem code
= rom
->get(addr
);
71 for (de
= disass_mos65c02
; de
&& de
->mnemonic
; de
++)
73 if ((code
& de
->mask
) == de
->code
)
80 cl_mos65c02::inst_length(t_addr addr
)
82 struct dis_entry
*de
= get_dis_entry(addr
);
85 return (de
->mnemonic
)?(de
->length
):1;
90 cl_mos65c02::accept_it(class it_level
*il
)
92 class cl_it_src
*is
= il
->source
;
96 rom
->write(0x0100 + rSP
, rF
|0x20);
99 // All interrupts (incl BRK) clear D flag
105 t_addr a
= read_addr(rom
, is
->addr
);
119 cl_mos65c02::nopft(int nuof_fetches
, int nuof_ticks
)
121 while (nuof_fetches
--)
123 if (nuof_ticks
) tick(nuof_ticks
);
128 cl_mos65c02::BIT8(t_mem code
)
131 u8_t f
= rF
& ~(flagZ
);
132 if (!(rA
& v
)) f
|= flagZ
;
138 cl_mos65c02::DEA(t_mem code
)
143 if (rA
& 0x80) rF
|= flagS
;
150 cl_mos65c02::INA(t_mem code
)
155 if (rA
& 0x80) rF
|= flagS
;
162 cl_mos65c02::JMP7c(t_mem code
)
166 u16_t a
= read_addr(rom
, a2
);
173 cl_mos65c02::tsb(class cl_cell8
&op
)
176 u8_t r1
= o
& rA
, r2
= o
| rA
;
186 cl_mos65c02::trb(class cl_cell8
&op
)
189 u8_t r1
= o
& rA
, r2
= o
& ~rA
;
199 cl_mos65c02::stz(class cl_cell8
&op
)
206 cl_mos65c02::PHY(t_mem code
)
208 rom
->write(0x0100 + rSP
, rY
);
212 class cl_stack_push
*op
= new cl_stack_push(instPC
, rY
, spbef
, rSP
);
220 cl_mos65c02::PLY(t_mem code
)
224 cY
.W(rom
->read(0x0100 + rSP
));
225 class cl_stack_pop
*op
= new cl_stack_pop(instPC
, rY
, spbef
, rSP
);
228 u8_t f
= rF
& ~(flagN
|flagZ
);
230 if (rY
&0x80) f
|= flagN
;
238 cl_mos65c02::PHX(t_mem code
)
240 rom
->write(0x0100 + rSP
, rX
);
244 class cl_stack_push
*op
= new cl_stack_push(instPC
, rX
, spbef
, rSP
);
252 cl_mos65c02::PLX(t_mem code
)
256 cX
.W(rom
->read(0x0100 + rSP
));
257 class cl_stack_pop
*op
= new cl_stack_pop(instPC
, rX
, spbef
, rSP
);
260 u8_t f
= rF
& ~(flagN
|flagZ
);
262 if (rX
&0x80) f
|= flagN
;
270 /* End of mos6502.src/mos65c02.cc */