Juliacon 2024

Retro6502 for 8-bit dev: smashing a mosquito with a pile driver
2024-07-11 , While Loop (4.2)

Developing for the 6502 8-bit microprocessor is hard with your code confined to the platform. Retro6502 has a fast, pure Julia emulator that lets your code call Julia where development is orders of magnitude faster – you can code in assembly after your Julia version works and passes your tests. You get
- macros / code gen in Julia
- Assembly in the Julia REPL
- Pure Julia 6502 emulation
- Live coding
- Automated testing
- Julia prototyping you can test against your 6502 code
- Read-only memory


Youtube: https://www.youtube.com/live/PzgFzorRtoo?si=W9TENH5mxrax2bgf&t=8919

Background music: https://www.youtube.com/watch?v=5ZoLphdE7l8 -- I had intended to play PRESS PLAY ON TAPE's cover of Martin Galway's classic Comic Bakery. This cover song is famous for certain values of "nerd".

Also, thanks to Roy Riggs, author of Hired Sword II for inspiration and guidance (and being my roommate in college).

This talk will demonstrate and discuss Retro6502, an open source Julia package licensed under the MIT license and available on GitHub at https://github.com/zot/Retro6502.jl

Developing for the 6502 8-bit microprocessor typically means compiling/assembling code, loading it into an emulator or a physical machine, and running and testing it there. There are advanced debugging environments like C64Debugger and the beta RetroDebugger that let you visualize memory and even use omniscient debugging, stepping backwards in time and finding the code and point in time that drew a particular pixel.

Despite these advantages, there is plenty of room for improvement. Coding and testing for the 6502 is tedious. Failure is always part of programming but the slow, error prone aspects of assembly language programming make it cost even more. If your 6502 code could somehow call Julia code outside the emulator, you could prototype and test in Julia and then, after the prototype code worked properly, you could write the 6502 code, radically reducing development time and relieving a lot of pain.

Retro6502 allows you to do just that. It does not implement Julia for the 6502 instruction set but it does allow you to use Julia code during development that interoperates reentrantly with 6502 code inside the emulator. Also, you don’t have to write (or wait for) a C++ plugin to support extra features you want or need because you can just write them in Julia.

Retro6502 initially focuses on the VIC-20 and Commodore-64 6502 architectures but provides hooks for extending into other architectures like Atari, Apple II, NES, etc.

Retro6502 also supports
- A Julia REPL extension:
* Designated pure Julia 6502 emulator instance,
* files watching for live coding.
- Custom assembler where Julia is the scripting language,

Exciting future directions like:
- Rewindable execution (after a test, etc.)
- Scrubbing back and forth in time and starting execution in the past to make alternate timelines.
- Showing divergent future screens based on input variations.
- Debugging with breakpoints and watchpoints that invoke custom Julia code.

See also: Slides (517.5 KB)