# Here’s some Matlab/Octave code for your MLX simulator

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;

entries = oneline(2:9);
checksum = oneline(10);

ck = 0;
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
#
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);

entries = oneline(2:9);
checksum = oneline(10);

ck = 0;
ck = ck + sum(entries.*factors);
ck = mod(ck, 255);
ck = ck + 255*(ck == 0);

retval = (ck == checksum);
endfunction
``` 