Work in progress Mandelbrot fractal viewer for Atari 8-bit home computers. Mostly an exercise in implementing signed 16-bit multiplication on the 6502.
Find a file
Brion Vibber 0afed893a6 whoops
now produces correct fractal but iterations outside are
sometimes wrong
probably range errrs in intermediate calc
2023-01-22 12:57:52 -08:00
.gitignore stuff 2022-12-28 21:08:16 -08:00
fixed.js whee 2023-01-07 22:57:18 -08:00
Makefile stuff 2022-12-28 21:08:16 -08:00
mandel.s whoops 2023-01-22 12:57:52 -08:00
readme.md update readme 2023-01-06 17:28:35 -08:00
sim.html mwahahah 2023-01-07 22:02:26 -08:00
sim.js whee 2023-01-07 22:57:18 -08:00

Mandel-6502

Work-in-progress Mandelbrot fractal viewer for Atari 8-bit home computers. Mostly an excuse to write an integer multiplication routine for the 6502 for practice.

Goals:

  • have fun learning 6502 assembly
  • make an old machine do something inefficient as efficiently as possible.
  • post cool screenshots of low-res fractals

Non-goals:

  • maintain anything long-term (but feel free to copy/fork if you want to make major changes!)

Enjoy! I'll probably work on this off and on for the next few weeks until I've got it producing fractals.

-- brion, january 2023

Current state

The 16-bit signed integer multiplication seems to be working, though I need to double-check it some more. It takes two 16-bit inputs and emits one 32-bit output in the zero page, using the Atari OS ROM's floating point registers as workspaces. Inputs are clobbered.

The main loop is a basic add-and-shift, using 16-bit adds which requires flipping the sign of negative inputs (otherwise you'd have to add all those sign-extension bits). Runs in 470-780 cycles depending on input.

The loop is unrolled which saves 148 cycles, but at the cost of making the routine quite large. This is an acceptable tradeoff for the Mandelbrot, where imul16 is the dominant performance cost and the rest of the program will be small.

The mandelbrot loop is now written out, but untested and probably buggy. With three multiplications, several additions/subtractions, and three sets of annoying bit shifts and rounds, it weighs in at 1939 - 3007 cycles per iteration.

Next steps

After a quick once-over to make sure it looks right, it's probably time to slap a display list together and draw some pixels to the screen and see what happens.

Reaching max iterations (256 runs through the loop) will take a half second or so per pixel -- this can be optimized by keeping a buffer of a few past zx/zy values and checking for duplicates which would signal a loop that will never escape. (Another technique I learned from Fractint!)

160x192 is luckily only 30,720 pixels, so there's a hard rendering time limit of about 4.5 hours. :D

Deps and build instructions

I'm using ca65 as a macro assembler, and have a Unix-style Makefile for building. Should work fairly easily on Linux and Mac. Might work on "raw" Windows but I use WSL for that.

Currently produces a .xex executable, which can be booted up in common Atari emulators and some i/o devices.