|
On a related note, I've been working on a script in Lua to "sort of" mimic a 6502 processor. The idea is, rather than code in 6502 assembly (for homebrew for NES, C64, etc.) you could code in Lua and possibly make some optimizations.
The assembly code in its entirety is an object. This object has a method for each instruction, as well as a key-value table to mimic memory (read: previously accessed memory locations), and processor registers. (The processor status register is a table with 7 numbers: N, V, B, D, I, Z, and C. :)
So, in Lua, you could read the values that would be in those locations at that point in the program's execution and choose one assembly instruction or one whole chunk over others if it's more suitable.
You could also break the entire program down into much smaller chunks and fit them all together. Just write a function that takes an assembly object and calls all these instructions methods on it. (There are also methods to add comments, labels, and cheap labels, as well as whole new lines.)
At the end, all the lines get printed to standard output. That can be redirected, assembled, and run in an emulator. :)
Also, the output is for ca65, but much of it is in variables that can be changed for other assemblers.
Currently working through the C64PRG and the Synertec MOS 6500 Programming Manual to translate each instruction individually. However, it is usable and each instruction is currently usable as a method. :)
This was rolling around in my head for a while. Source is in ca65.lua at https://github.com/Heathcode/rabbitfarm