About

Ghostbusters account generator

One of my favorite games for MSX was (and still is) Ghostbusters. If you finished the game with more money than you started with, you would get a bank account number. I was always curious how this worked. And when the MSX emulators came available with built in debuggers I spend some time figuring it out. In the form below you can enter your name and the amount of money you want.

Please contact me if you have any questions: rainier@meusesoft.com

Account generator

Javascript code

function CalculateAccount(Name, Money) {

	//Assertions
	if (Money < 10000) return "Amount at least 10.000";
	if (Money > 999900) return "999.900 is the maximum amount";
	if (Name.length > 19) return "The name must not exceed 19 characters";

	//Divide the amount over two variables. Only the digits $ xxyy00 are used
	mon = "00" + Money;
	monl = mon.length;
	mon = mon.substring(monl-6, monl-2);

	mon1 = mon.substring(0, 2);
	mon2 = mon.substring(2, 4);

	//Calculate the sum of all characters of the name
	totalCharsName = 0
	for (i = 0; i < Name.length; i++) {

		totalCharsName += Name.charCodeAt(i);
		}
	totalCharsName = totalCharsName & 255;

	//Calculate base checksum
	checksum = parseInt("0x" + mon1) + parseInt("0x" + mon2);
	checksum = checksum & 255;
	if (checksum == 0) checksum += 1;

	//Encode checksum
	code = checksum
	for (i = 0; i < totalCharsName; i++) {

		checksum = EncodeChecksum(code);
		}

	//Convert codes to account number
	accountBinary = ("00000000" + parseInt("0x" + mon1).toString(2)).slice(-8);
	accountBinary = accountBinary + (("00000000" + parseInt(code).toString(2)).slice(-8));
	accountBinary = accountBinary + (("00000000" + parseInt("0x" + mon2).toString(2)).slice(-8));

	//From binary value to account 6-digits
	accountDigits = "";
	for (i = 0; i < 24; i = i + 6) {

		accountDigits = parseInt(accountBinary.substr(i, 3), 2).toString() + parseInt(accountBinary.substr(i + 3, 3), 2).toString() + accountDigits;
		}

	return accountDigits;
	}

	function EncodeChecksum(value) {

		checksum = value;
		checksum = SLA(checksum);
		checksum = XOR(checksum, value);
		checksum = RL(checksum);
		checksum = XOR(checksum, value);
		checksum = RL(checksum);
		checksum = SLA(checksum);
		checksum = XOR(checksum, value);
		checksum = RL(checksum);
		code = RL(value);

		return checksum;
		}

	carryBit = 0;

	function SLA(value) {

		value = value * 2;
		carryBit = 0;
		if ((value & 256) != 0) carryBit = 1;
		value = value & 255;

		return value;
		}

	function XOR(value1, value2) {

		carryBit = 0;
		return value1 ^ value2;
		}

	function RL(value) {

		value = value * 2;
		value += carryBit;
		carryBit = 0;
		if ((value & 256) != 0) carryBit = 1;
		value = value & 255;

		return value;
		}