I am embarrassed that after writing 72,650 words about MLX 2.0 for last week, I left something out. Specifically, I didn’t include code for your own simulation of the checksum routine on a more modern platform. Here’s a function that carries out the calculations of the Commodore 64/128 or Apple II versions of MLX 2.0. It’s written in Octave, the open-source Matlab-like numerical computation routine. If you can read this, though, you can translate it to whatever language you find convenient.
function [retval] = mlxII (oneline) z2 = 2; z4 = 254; z5 = 255; z6 = 256; z7 = 127; address = oneline(1); entries = oneline(2:9); checksum = oneline(10); ck = 0; ck = floor(address/z6); ck = address-z4*ck + z5*(ck>z7)*(-1); ck = ck + z5*(ck>z5)*(-1); # # This looks like but is not the sum mod 255. # The 8-bit computers did not have a mod function and # used this subtraction instead. # for i=1:length(entries), ck = ck*z2 + z5*(ck>z7)*(-1) + entries(i); ck = ck + z5*(ck>z5)*(-1); endfor # # The checksum *can* be 255 (0xFF), but not 0 (0x00)! # Using the mod function could make zeroes appear # where 255's should. # retval = (ck == checksum); endfunction
This reproduces the code as it was actually coded. Here’s a version that relies on Octave or Matlab’s ability to use modulo operations:
function [retval] = mlxIIslick (oneline) factors = 2.^(7:-1:0); address = oneline(1); entries = oneline(2:9); checksum = oneline(10); ck = 0; ck = mod(address - 254*floor(address/256), 255); ck = ck + sum(entries.*factors); ck = mod(ck, 255); ck = ck + 255*(ck == 0); retval = (ck == checksum); endfunction
Enjoy! Please don’t ask when I’ll have the Automatic Proofreader solved.