6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 7:34 pm

All times are UTC




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
PostPosted: Wed Aug 28, 2002 5:42 am 
Hey, I'm working on writing a simple 6502 emulator as a sort of project to test my skills, and I'm still a little confused on how some 6502 instructions work(still waiting for the library to get my books in).

The first thing is, using instructions like ADC, SBC, INC, DEC, and
others like them, if you do an operation that ends up setting the
target byte to 0, but also set's the carry flag(like doing ADC with
255 + 1), do you set the zero flag or not? I'm assuming you do,
since the basic guideline seems to be to set the zero flag if the result is 0 no matter what, since I figure the same thing could happen with, say, ASL, and it seems to make sense to set the zero flag then.

The second thing is, with undefined opcodes (one of the 104 non-standard opcodes), do you think it's best to try and emulate the strange reaction the CPU has to them, or to stop the CPU with an error? This is sort of an opinion thing.

Third, does anyone know where I can find out how instructions respond to decimal(BCD) mode? I've found some examples for ADC and SBC but I'm wondering if there are any other's that are affected, such as INC or DEC.

Thanks in advance for your help.


Report this post
Top
  
Reply with quote  
PostPosted: Thu Aug 29, 2002 2:23 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
> I'm working on writing a simple 6502 emulator

It sounds like you mean a simulator. An emulator is something you can actually plug into your board to act like the normal processor, but it has ribbon cables to interface to the PC to let you see what's going on inside the processor.

> using instructions like ADC, SBC, INC, DEC, and others like them,
> if you do an operation that ends up setting the target byte to 0,
> but also sets the carry flag (like doing ADC with 255 + 1), do you
> set the zero flag or not?

Yes. There's effectively an implied compare-to-zero included at no charge, which means the N flag is also set if bit 7 is set, and cleared otherwise.

> with undefined opcodes (one of the 104 non-standard opcodes), do
> you think it's best to try and emulate the strange reaction the CPU
> has to them, or to stop the CPU with an error?

A few people have been taking advantage of the odd behavior of the unofficial op codes. Personally, I find them interesting but hardly useful; and if you use them, you can't plug in a CMOS 6502 (which has more op codes) and expect it to work right. The CMOS 6502 treats its 46 unused op codes as no-ops.

> does anyone know where I can find out how instructions respond to
> decimal (BCD) mode? I've found some examples for ADC and SBC

CMP is also affected by the decimal flag. The decimal adjust is done automatically on the fly, so a second "decimal adjust" instruction is not needed, unlike on other processors. The flags are not always valid after these operations on the NMOS 6502 in decimal mode. This bug was fixed in the CMOS versions. Note also that on the NMOS 6502, the D flag state will be unknown following a reset, and will not be cleared upon interrupt.

> I'm wondering if there are any others that are affected, such as
> INC or DEC.

INC, DEC, INX, DEX, INY, and DEY are always in hex, not decimal.

Since the CMOS 6502 (65c02) will not be discontinued anytime in the forseeable future and has so many advantages over the NMOS 6502, I would encourage you to make your simulator able to handle it.

Garth

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 29, 2002 1:58 pm 
Thanks for your advice, especially about the unused opcodes. I haven't had much previous experience with the 6502 and don't know all the variations of the family. I'm attempting to write this simulator(thanks for the correction) to practice gaining familiarity with an otherwise unknown piece of hardware. It's a skill I think will pay off in the future if I manage to get into a good college to study electronics, and the 6502 seemed like a simple project compared to emulating something like an Intel CPU.

Thank you once again, I'll probably be back with more questions soon.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 50 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: