Emulating a CPU in C++ #14 (6502) - First Ever Program

  Рет қаралды 8,222

Dave Poo

Dave Poo

Күн бұрын

In this episode I compile an actual 6502 program using some of the instructions that we know are currently working in this implemention and see if it can be executed.
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 Recap
0:38 Fixing BIT Instruction
5:50 Writing a test program
11:23 Loading the test program
27:40 Executing the test program
35:28 Closing comments

Пікірлер: 27
@Handskemager
@Handskemager 2 жыл бұрын
Now I know who you’re accent sounds like, The way you say Zero sounds exactly like Richard Hammond! :)
@DavePoo
@DavePoo 2 жыл бұрын
When I read that, at first i thought you meant John Hammond from Jurassic Park - "spared no expense!"
@JulianOnions
@JulianOnions 3 жыл бұрын
Pretty sure it is the | being undefined behaviour with the ++. Side effects that the optimiser can remove. Mem[A++] | (Mem[A++]
@DavePoo
@DavePoo 3 жыл бұрын
I think you are right! If i had looked at the dissasembly at the time it probably would have shown me that.
@M4RC90
@M4RC90 3 жыл бұрын
It definitely can not be both increments first, since it is the post-increment operator. Everything else is undefined though.
@AndersJackson
@AndersJackson 3 жыл бұрын
@@M4RC90 the compiler is allowed to execute the expression and thus the A++ in any order, as long as the result is valid, so either the first term or the second term can be done first. So yes, you have no clue which order this compiler calculate this expression in this instance, and that matter... You should NEVER do auto increment/decrement on the same variable in the same expression. (Yes, I didn't remember that when I watch the video, so I could have done the same error)
@M4RC90
@M4RC90 3 жыл бұрын
@@AndersJackson That's exactly what I was saying.
@AndersJackson
@AndersJackson 3 жыл бұрын
Would have been nice to use the reset vector too, to start the progam. Anyway, really nice series of videos, about developing programs.
@DavePoo
@DavePoo 3 жыл бұрын
Yeah, i never really used the reset vector correctly when i did this. That would be for the next stage if i started getting roms loaded.
@arkanjo7509
@arkanjo7509 2 жыл бұрын
thanks
@perfectionbox
@perfectionbox 3 жыл бұрын
If a capable programmer can make this many errors despite having a complete specification, it's easy to understand why making new software is so error prone and needs tons of QA.
@DavePoo
@DavePoo 3 жыл бұрын
Yeah, and also why automated testing is such a valuable tool, as once you do get it working, you've got to make sure that future changes and additions to the program don't break existing behavior.
@theinvisibleman5751
@theinvisibleman5751 3 жыл бұрын
Another thing to mention - just for the fun of it try writing, thinking along the path of C++, formulate meaningful english sentences and talk at the same time and see what happens :-)
@paulneal9908
@paulneal9908 8 ай бұрын
Good programming is more to do with how you fix code than how you write it
@DerykRobosson
@DerykRobosson 3 жыл бұрын
18:05 On current line, or block highlighted text, Comment CTRL-K, CTRL-C; Uncomment CTRL-K,CTRL-U. Knowing and using shortcuts such as these feed the DRY methodology. 36:21 There's nothing wrong with relying on external files to be used for unit tests.
@robcfg
@robcfg 3 жыл бұрын
Wouldn't it be better to use memcmp for testing that the program has been loaded correctly into memory? You should expect it to return 0 if the contents of the program are the same to that on the destination address.
@CostasB-jv1ko
@CostasB-jv1ko 3 жыл бұрын
Hello, i got a question. The A register gets values of 255 and 51 every loop, the Processor status shouldn't be affected as well? we have a negative value 255 (0xFF) and a positive value 51 (0x33) so the flag N should toggle each loop, right? Well done so far!
@DavePoo
@DavePoo 3 жыл бұрын
Thanks. The processor status would be affected. In fact for some reason in the video i was "saying it wasn't being affected", but you can see from the output that the PS: 128 when the value was 255, so the negative value was set. And PS: 0 when the value was 51, so the negative value was not set.
@twobob
@twobob 3 жыл бұрын
The Joys of promotion.
@januzi2
@januzi2 3 жыл бұрын
Illegal opcodes? I think that the internet police should take care of that issue.
@DavePoo
@DavePoo 3 жыл бұрын
i'll let them know
@januzi2
@januzi2 3 жыл бұрын
@@DavePoo Good. Only the real c64 will allow you to see what are those opcodes actually doing. I remember that there were at least 4 or 5 things that could have been done with those opcodes. There are still some people doing compos, so ... maybe you could ask them? I'm pretty sure that they'll be more than happy to help.
@januzi2
@januzi2 3 жыл бұрын
@@DavePoo Oh, and one more thing. Maybe you'd know. Why is it so hard to recreate a sid chip? Is it the same reason as in 6502 - undocumented instructions?
@DavePoo
@DavePoo 3 жыл бұрын
@@januzi2 No (but there are some undocumented features that allowed people to do things like sample playback). But firstly i'd like to say that the SID emulation out there is actually really good. The reason why it's hard to recreate is the SID actual has 3 analogue synthesizers built inside it (that are controlled digitally). Those synthesizers are not perfect and produce artifacts and distortion in the sound, people usually refer to that distortion as "warmth" or "character". So when you emulate the chip, you need to emulate the distortion produced in the analogue stage. Even Commodore themselves couldn't do that, there are different revisions of the chips that sounds slightly different. The later versions of the SID in the C64C were actually much better chips and ran on lower voltage, and for this reason they actually have a much cleaner output. People say they don't sound as good because they don't have the warmth/distortion of the earlier chips.
@M4RC90
@M4RC90 3 жыл бұрын
Not sure why load program is part of the cpu. You don't load the program into the cpu, you load it into memory, right?
@DavePoo
@DavePoo 3 жыл бұрын
Yeah, honestly could have put that function just free or anywhere really. In a real system, a real program would have to be loaded by the CPU into memory, so there it is.
@M4RC90
@M4RC90 3 жыл бұрын
@@DavePoo The operating system does that. But what loads the operating system into memory? ;) the CPU needs to start running code from somewhere, before that code can copy something into memory.
Emulating a CPU in C++ #15 (6502) - Register Transfers
14:49
Dave Poo
Рет қаралды 4,4 М.
The World's Fastest Cleaners
00:35
MrBeast
Рет қаралды 105 МЛН
ФОКУС С ЧИПСАМИ (секрет)
00:44
Masomka
Рет қаралды 4,2 МЛН
白天使和小丑帮助黑天使。#天使 #超人不会飞 #超人夫妇
00:42
unique_ptr: C++'s simplest smart pointer
11:54
mCoding
Рет қаралды 38 М.
My 2 Year Journey of Learning C, in 9 minutes
8:42
VoxelRifts
Рет қаралды 522 М.
The ONLY REASON To Unit Test
8:26
Theo - t3․gg
Рет қаралды 67 М.
27c3: Reverse Engineering the MOS 6502 CPU (en)
51:57
Christiaan008
Рет қаралды 428 М.
NES Emulator Part #2: The CPU (6502 Implementation)
1:07:12
javidx9
Рет қаралды 408 М.
“Hello, world” from scratch on a 6502 - Part 1
27:25
Ben Eater
Рет қаралды 4,6 МЛН
"Clean" Code, Horrible Performance
22:41
Molly Rocket
Рет қаралды 827 М.
Orange Pi Zero 2W - Is It Really That Good? You'll Be Surprised!
29:23
Platima Tinkers
Рет қаралды 21 М.
The World's Fastest Cleaners
00:35
MrBeast
Рет қаралды 105 МЛН