Emulating a CPU in C++ #20 (6502) - Add With Carry Whiteboard

  Рет қаралды 4,272

Dave Poo

Dave Poo

Күн бұрын

In this video i just explain how i think ADC (Add with Carry) works in the 6502 and what is going to be required to set the correct processor state after an ADC instruction.
Also, i'm not dealing with decimal mode here, just binary addition.
Links:
Source for this project: github.com/davepoo/6502Emulator
Google Test: github.com/google/googletest
6502 Information: www.obelisk.me.uk/6502/
Timestamps:
0:00 What is ADC
2:28 Binary 1 + 1
4:57 Large binary addition
7:54 Binary add with carry
10:12 Signed numbers
12:05 Adding signed number
13:45 Signed overflow
21:49 Another signed overflow example
25:30 Closing comments

Пікірлер: 11
@MichalGerwatowski
@MichalGerwatowski 3 жыл бұрын
i just want to say that, i recently started watching you bcs of your 6502 emulating serie and i love your vids! Pls make more, you deserve more views and subscribers
@DavePoo
@DavePoo 3 жыл бұрын
Thanks very much, there are more videos on the way
@tomwhitcombe7621
@tomwhitcombe7621 3 жыл бұрын
The name for how these negative binary numbers are represented is called "twos compliment"; the TLDR is that storing numbers like this means you don't have zero and negative zero as you would if you just used 7 bit unsigned and the final bit as a sign bit. ie 1000000 and 00000000 would be minus zero and zero with that niave approach.
@twobob
@twobob 3 жыл бұрын
A reasonable and thorough explanation of the logic
@CZghost
@CZghost 3 жыл бұрын
Remember that the numbers in binary are actually treated as signed numbers. You could easily overflow a positive number into negative just when you add 0x01 to 0x7F (or any other combination that would let you exceed the 0x7F value). This is where I believe the overflow flag is actually set, because the signs do not actually match when you add 1 to 127, which would become 128, but because it is signed, it becomes -128 instead. If you add 0x01 to 0xFF, this is actually completely valid operation. Yes, you'll set carry flag, but since you add a positive 1 to a negative 1, the result is as expected, which is 0. Because -1 + 1 = 0. It also works with opposite. If you subtract a number from another, the carry flag is always set. So the only thing that should make it to set an overflow bit is when the signs mismatch because of an illegal overflow, which is when you add a positive number to a positive number, yet you still end up with a negative number in the result, or if you add a negative number (which is subtracting that number) to a negative number and you get in positive number instead.
@CZghost
@CZghost 3 жыл бұрын
What was happening? Did I actually trigger an antispam measure? My comment was deleted for no obvious reason 🤔
@DavePoo
@DavePoo 3 жыл бұрын
Yes, i covered the overflow in the video 13:46
@andrewmackenzie2638
@andrewmackenzie2638 3 жыл бұрын
Electrical engineer here - I started watching (and loving) this series about a week ago, and I have 2 questions 1) will there be more parts to the series? (I really hope so!) 2) will this architecture work if you start adding peripherals e.g. video, IO, sound, etc.? I'm wondering if you need to create a bit of a pipeline (I think that's the correct processor terminology) of single cycle instruction steps so that you can interface peripherals without timing issues
@DavePoo
@DavePoo 3 жыл бұрын
Hi. I've been getting in computer repairs recently. I manged to restore an Amiga 600 from eBay that had a faulty RAM chip. 1) You mean more parts that the 35! Possibly, I was pondering with moving it into an Unreal engine plugin and continuing work from there. I did actually do a little test where i got it into a an Unreal plugin and got the Unit tests working (as google test is actually included with Unreal Engine). 2) Yes, it might need some changes and fixes but most of what i've done here should be a good starting point to emulate a full system. I to continue the next thing to add would be the ROM support, as they have be mapped into memory at specific addresses, and the system would read from them instead of RAM (and might write to the underlying ram if it tried to write over them). And yes, the CPU will probably have to run lock stepped with the other emulated hardware. So i believe in the C64, the VIC and C64 would access the bus on each cycle, so the 2 have to co-operate and be run together in the emulator.
@andrewmackenzie2638
@andrewmackenzie2638 3 жыл бұрын
@@DavePoo I was hoping for a disassembler and debugger and maybe some peripherals, but I also know they are likely to be more work than the emulator itself, so can't blame you if you've got other things you want to focus on :).
@TheJamieRamone
@TheJamieRamone 3 жыл бұрын
Oh, u assume it happens after the instruction executes? Good thing it matches the statement on that page just above the table of affected flags, or that would've been embarrassing.
Emulating a CPU in C++ #21 (6502) - ADC Absolute
46:18
Dave Poo
Рет қаралды 4,3 М.
27c3: Reverse Engineering the MOS 6502 CPU (en)
51:57
Christiaan008
Рет қаралды 428 М.
[실시간] 전철에서 찍힌 기생생물 감염 장면 | 기생수: 더 그레이
00:15
Netflix Korea 넷플릭스 코리아
Рет қаралды 38 МЛН
狼来了的故事你听过吗?#海贼王  #路飞  #斗罗大陆
00:45
路飞与唐舞桐
Рет қаралды 7 МЛН
Write Your Own Emulator for Your Own CPU - Using a Raspberry Pi Pico
32:17
Why flat earthers scare me
8:05
Sabine Hossenfelder
Рет қаралды 246 М.
“Hello, world” from scratch on a 6502 - Part 1
27:25
Ben Eater
Рет қаралды 4,6 МЛН
NES Emulator Part #2: The CPU (6502 Implementation)
1:07:12
javidx9
Рет қаралды 408 М.
A Introduction to Handles (in C++)
42:23
Dave Poo
Рет қаралды 10 М.
What is a stack and how does it work? - 6502 part 5
24:25
Ben Eater
Рет қаралды 727 М.
Microsoft BASIC from 1977 on my 6502 computer!
17:08
Anders Nielsen
Рет қаралды 10 М.
Bjarne Stroustrup: C++ | Lex Fridman Podcast #48
1:47:13
Lex Fridman
Рет қаралды 1 МЛН
[실시간] 전철에서 찍힌 기생생물 감염 장면 | 기생수: 더 그레이
00:15
Netflix Korea 넷플릭스 코리아
Рет қаралды 38 МЛН