I'm converting a 6502 emulator I wrote in C a couple years ago to work on my Arduino Uno. It's pretty small, I think this will work. It's pretty straightforward C code, nothing fancy. However, I'm having some errors. Here's what I get when trying to compile the sketch... it looks like something is getting broken by pre-processing.
_6502_c:89: error: expected unqualified-id before '&&' token
_6502_c:94: error: expected unqualified-id before numeric constant
_6502_c:94: error: expected `)' before numeric constant
_6502_c:103: error: expected unqualified-id before 'asm'
_6502_c:134: error: expected unqualified-id before 'asm'
_6502_c:253: error: expected unqualified-id before '&&' token
The code is a little large to post on here, I think... 875 lines. Here it is on pastebin:
I haven't fooled around with the Arduino that much, so I'm probably just doing something obviously wrong. If anybody can help, it would be much appreciated. Thanks!
UKHeliBob:
The Auto Format tool in the IDE reports that there are too many right curly braces in your code. Until that is fixed it will not compile.
It didn't like my multi-line macro defines for the flag calculation stuff. However, I still get the same errors. I think the auto-format problems aren't affecting the compile. The formatter doesn't like them, but the compiler itself doesn't care. (Possible auto-formatter bug?)
This same code compiles file in Visual C++ or GCC.
Yes, I saw this a while after I wrote the emulator. Really interesting low-level stuff!! I originally wrote this as part of a NES emulator. Of course, the Arduino could never pull that off. Something like the Apple ][ may be do-able.
Thanks for the help, but I'm still getting the same problems.
Most of the warnings are expected due to most of the 6502 opcode emulation functions not being directly called in the code. There are function pointer arrays to the proper addressing mode functions and instruction emu functions for each opcode value. The execution loop can be tiny due to this, but it has the side-effect of the compiler thinking most functions aren't called thus the warnings. Instead of a huge switch block like you see in some CPU emulators, the main loop is reduced to this:
_6502_c:84: error: expected unqualified-id before '&&' token
And there is no && in my code. BASE_STACK is simply a define of 0x100. So, something is happening in the preprocessor that is breaking things. I wonder what of my code it doesn't like.
Can you describe exactly your compiling process? As I said, I compiled under the IDE using the method I described that error was not present.
And there is no && in my code. BASE_STACK is simply a define of 0x100. So, something is happening in the preprocessor that is breaking things. I wonder what of my code it doesn't like.
The line number being reported is clearly wrong. Using my method it reported the function I mentioned.
Thanks for spending some more time on this. I'm not doing anything special. Just clicking verify. I fixed the "and" thing, and now I'm getting this error first:
_6502_c:84: error: expected unqualified-id before 'asm'
Line 84 is completely blank. I'm attaching the current file.
I've changed the following things in "arduino-6502.c":
added "#define NULL 0" to the top
renamed the "and" function to something else ("Xand")
made the tentative definitions of "addrtable" and "optable" in lines 113/114 "extern" instead of "static", and removed "static" from their initializations in lines 746/766
added a typecast to line 866: "loopexternal = (void (*)()) funcptr;"
What remains are a few warnings, but the code compiles then. Whether it works, I can't tell.