Emulating a CPU in C++ #26 (6502) - Subtract With Carry

  Рет қаралды 3,536

Dave Poo

Dave Poo

Күн бұрын

In this video i get SBC "Subtract With Carry" instruction working in the 6502 emulator. A lot of the content here is based on having a working ADC "Add With Carry", so if you haven't seen the ADC videos or don't know how ADC works then you should watch that first.
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 SBC definition
2:00 Whiteboard theory
11:10 test 0 + 0 = 0
16:16 Implementing SBC Absolute
20:18 0 - 1= -1 test
24:36 0 - 1 - C = -2 test
27:47 -ve signed overflow test
29:52 +ve signed overflow test
32:50 0 - 0 - C = -1 test
34:20 Subtract 2 +ve numbers test
36:00 Tidy up and closing comments

Пікірлер: 7
@twobob
@twobob 3 жыл бұрын
Solid. Agreed, hardware must be like that
@CZghost
@CZghost 3 жыл бұрын
A - M - (1 - c) This is actually very poorly written, but it is explained quite correctly. It should be written like this: A + (~M) + (~C), where "~" means logical negation of the register and the flag (it could also be written as !C) Then your code is incorrect, because in real hardware, the carry flag isn't taken as is, it is actually negated, as well as the input to the ALU (negation is controlled by a microinstruction that tells the CPU to flip the bits - the actual control logic of the CPU that decodes the opcodes). So in reality you should actually copy the code over and change the addition of the operand and the carry into addition of their negation (so Operand becomes ~Operand, bitwise NOT so all of the bits are flipped, and Flags.C becomes !Flags.C, because it is only one bit you can use boolean NOT). Or interpret it into the existing ADC function so you actually set an operation to it and it decides based on the operation (and possibly rename the function). That would have much closer function to the real hardware. This mistake might actually lead to bugs and errors in otherwise fully working program code.
@thomasfriedrich2001
@thomasfriedrich2001 3 жыл бұрын
operator ~ is the bitwise complement, not the negative / two's complement.
@DavePoo
@DavePoo 3 жыл бұрын
Yeah, i think i called it "bitwise negation"
@CostasB-jv1ko
@CostasB-jv1ko 3 жыл бұрын
So we make the subtraction using the addition "circuit" based on the formula (Acc + Memory(1's complement) + Carry) ? Super confusing ..... Let's say Acc holds 0x01 and i want to subtract 0x01 from it, the Carry flag should be set to TRUE to get the result of 0x00. LDA #$0x01 SEC SBC #$0x01;Now Acc is cleared Am i missing something?
@DavePoo
@DavePoo 3 жыл бұрын
The result will be zero but the carry flag will be TRUE after the operation.
@TheJamieRamone
@TheJamieRamone 3 жыл бұрын
A - M - (1 - c) = A - M - 1 + c
Emulating a CPU in C++ #27 (6502) -  Arithmetic Shift Left
18:57
NES Emulator Part #2: The CPU (6502 Implementation)
1:07:12
javidx9
Рет қаралды 408 М.
Суд над Бишимбаевым. 2 мая | ОНЛАЙН
7:14:30
AKIpress news
Рет қаралды 669 М.
КИРПИЧ ОБ ГОЛОВУ #shorts
00:24
Паша Осадчий
Рет қаралды 6 МЛН
КАРМАНЧИК 2 СЕЗОН 4 СЕРИЯ
24:05
Inter Production
Рет қаралды 590 М.
Optimising Code - Computerphile
19:43
Computerphile
Рет қаралды 136 М.
Can you solve this Oxford admissions question?
8:18
MindYourDecisions
Рет қаралды 55 М.
You don't need libraries to write a game engine in C++ | OpenGL | Devlog
2:50
Advanced C #1: function pointers
11:22
Charles Cabergs
Рет қаралды 10 М.
A Introduction to Handles (in C++)
42:23
Dave Poo
Рет қаралды 10 М.
#1 How to Build a Virtual Machine from Scratch
31:09
Philip Bohun
Рет қаралды 57 М.
Суд над Бишимбаевым. 2 мая | ОНЛАЙН
7:14:30
AKIpress news
Рет қаралды 669 М.