r/C_Programming • u/WaterBowly • Aug 06 '26
I wrote a 6502 emulator in god's programming language
https://github.com/yasu-q/c-6502emuHello C programmers
I wrote a simple (mostly) instruction-accurate 6502 emulator in C. It has some basic functionality like
- Allowing you to step through programs instruction by instruction
- Visualizing CPU state and memory
I don't have much experience with the language, so if you have some time to look over my code I'd really appreciate it!
Repo: https://github.com/yasu-q/c-6502emu
Thank you for reading
85
Upvotes
β’
u/github-guard Aug 06 '26
π GitHub Guard: Trust Report
β οΈ This project scored 0/6 β below this subreddit's threshold of 3.
Audit Breakdown:
2
u/AutoModerator Aug 06 '26
Hi /u/WaterBowly,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
122
u/jonalaniz2 Aug 06 '26
This isn't Holy-C
48
u/Ikkepop Aug 06 '26
I was hoping you wrote it in HolyC
23
u/skeeto Aug 07 '26 edited Aug 07 '26
Neat project! I enjoyed poking around it. Here are some issues I noticed.
You can skip the
fseek/ftelldance. That is, instead of:Just read and offer all of memory:
(Caveat: The
memsetis because the C standard is insane, andfreadis allowed to write beyond the returned size. At least one implementation is insane enough to do it.) You should also check the results offgetsin the UI because right now EOF (e.g.ctrl+d) puts it in an infinite loop.The IRQ condition is flipped, though it's not yet in use:
SBCisA + ~M + C, so the addition overflow formula applies to the inverted operand (temp), not the raw fetched value:BRK is a 2-byte instruction: the byte after the opcode is padding, and the pushed return address skips over it:
Push the interrupt status byte before setting interrupt disable:
B is not a stored processor flag on real hardware. Bit 4 only exists in status bytes materialized by PHP/BRK (as 1) and IRQ/NMI (as 0). PLP and RTI ignore bits 4 and 5 when restoring, so stop copying the stacked B bit into CPU state:
Finally, a bug in the ROR carry flag (carry takes the bit shifted out):
5
u/ericek111 Aug 07 '26
Lisp? God wrote in Lisp.
4
u/FLMKane Aug 07 '26
God only had seven days. He didn't have time to chase segfaults. He used Lisp
3
u/slimscsi Aug 06 '26
Assembly?
3
u/0_00000073_ Aug 06 '26
Cool project! If you're an individual programmer, I suggest avoiding usage of "we" in comments as AI tends to over-use it. That might help with false detection from others!
If you don't mind me asking, why not call nmi() from irq() instead of copying it? It'd just reduce repeated code
1
u/Beautiful_Stage5720 Aug 06 '26
I tried this once and didnt get very far. I got stuck on interrupts for some reason, its been years so I dont really remember. How did you handle the interrupt controller?
1
u/mivanchev Aug 07 '26
-MMD -MPinstead of listing them all.[static 1]for non-nullable arguments instead of pointers.