Emulating a CPU in C++ #18 (6502) - Conditional Branches

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

Dave Poo

Dave Poo

Күн бұрын

In this episode i get the rest of the conditional branches working in the 6502 emulator.
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 Intro
1:10 BNE Test
3:16 Refactoring branch logic
5:50 BNE Implemented
6:20 BCS (Branch on Carry Set)
7:57 BCC (Branch on Carry Clear)
8:48 BMI & BPL (Branch Negative Set/Clear)
10:20 BVS & BVC (Branch Overflow Set/Clear)
12:22 Branching completed
12:50 Tidy up
14:00 Closing comments

Пікірлер: 4
@CZghost
@CZghost 3 жыл бұрын
6502 seems to have best branching instruction set, because it has branching based on all of the flags (maybe except the interrupt flag, possibly also overflow flag). But it has single addressing mode, which only seems to count with relative branching using a single byte, as it kind of limits the program to jump only 127 addresses forward and 128 addresses backwards (since it does take a sign into consideration). I would expect it to work like conditional jump, only with the flags check. So programmer has to keep track on if the code he's writing is actually compilable, because in a large scope, it could easily happen that the conditional jump would be more than a signed byte allows and it results in uncompilable code.
@CZghost
@CZghost 3 жыл бұрын
Okay, so overflow does have its own branch. The interrupt doesn't.
@andrsam3682
@andrsam3682 3 жыл бұрын
Are you sure that in case if branch instruction leads to other page it consumes 5 cycles, but not 4? In my opinion the doc says "2 cycles +1 if branch succeds OR +2 if to a new page", so 2 or 3 or 4.
@DavePoo
@DavePoo 3 жыл бұрын
Yes, I think you could be right about that. Page at masswerk.at seems to confirm what you are saying. "add 1 to cycles if branch occurs on same page, add 2 to cycles if branch occurs to different page". This might also make sense if when it does the page cross, all it has to do is an extra fixup on a single byte in the PC to change the high byte of the page. I'm at the testing & debugging phase of this emulator right now so i'll address that (no pun intented), in a future part in the series.
Emulating a CPU in C++ #19 (6502) - Status Flag Changes & NOP
11:18
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,5 МЛН
NO NO NO YES! (40 MLN SUBSCRIBERS CHALLENGE!) #shorts
00:27
PANDA BOI
Рет қаралды 109 МЛН
skibidi toilet 73 (part 2)
04:15
DaFuq!?Boom!
Рет қаралды 24 МЛН
КАРМАНЧИК 2 СЕЗОН 4 СЕРИЯ
24:05
Inter Production
Рет қаралды 587 М.
Making a Chip-8 Emulator
9:18
VoxelRifts
Рет қаралды 10 М.
NES Emulator Part #2: The CPU (6502 Implementation)
1:07:12
javidx9
Рет қаралды 408 М.
Live refactoring a subscriber's React code
32:32
Web Dev Cody
Рет қаралды 113 М.
Emulating a CPU in C++ #17 (6502) - BEQ Conditional Branch
32:41
Emulating a CPU in C++ #32 (6502) -  Test Program Debugging
52:25
I Asked GPT-4 To Refactor My Legacy Codebase
12:39
Nick Chapsas
Рет қаралды 347 М.
Stable Diffusion in Code (AI Image Generation) - Computerphile
16:56
Computerphile
Рет қаралды 279 М.
NO NO NO YES! (40 MLN SUBSCRIBERS CHALLENGE!) #shorts
00:27
PANDA BOI
Рет қаралды 109 МЛН