Kill the Bit (Personified)
Jesse Downing	08 Oct 2019 (Rev 11 Oct 2019)

Explanation
The code here represents the code for the popular game "Kill the Bit" written
for the Altair 8800 on May 15, 1975 by Dean McDaniel. This code would be flipped
in in binary using switches on the front of the machine, and then once the
program is run, would cause the 8 LEDs representing the accumulator (CPU
register A) to have a "bit" rotate across them. The user would then try to "kill
the bit" by flipping the switch underneath the LED at the correct time. If the
wrong switch is flipped, bits would be added. The game is over when the final
bit is killed. This was one of many such popular demos on the Altair 8800
microcomputer - the first widely available personal computer, and arguably one
of the most important personal computers in all of computing history (as it was
the machine on which Microsoft got its start).

The narrator of this play (if it can be called that) is the personified version
of an Intel 8080 CPU. The format is as follows:

Code (in Octal)		Assembly Code		English Explanation
	NARRATION

This might make zero sense to anyone who's not obsessed with computers or
programming (and might quite frankly make zero sense to many of them), but it's
something I was interested in exploring, as I'm planning on trying to build my
own Altair 8800 from (mostly) new parts once I return to the US.

Program
			org	0

	PROGRAM INITIALIZED AT LOCATION ZERO

041 000 000	lxi	h,0		initialize counter

	COUNTER IS SET TO ZERO

026 200		mvi	d,080h	set up initial display bit

	REGISTER D IS SET TO HEXADECIMAL 80, OCTAL 200, DECIMAL 128,
	BINARY 10 00 00 00

001 016 000	lxi	b,0eh		higher value = faster

	REGISTER B IS SET TO HEXADECIMAL 0E, OCTAL 037, DECIMAL 15,
	BINARY 00 01 11 11 

032		beg:	ldax	d		display bit pattern on
032			ldax	d		upper 8 address lights
032			ldax	d
032			ldax	d

	LOAD THE ACCUMULATOR FROM THE ADDRESS IN D
	LOAD THE ACCUMULATOR FROM THE ADDRESS IN D
	LOAD THE ACCUMULATOR FROM THE ADDRESS IN D
	LOAD THE ACCUMULATOR FROM THE ADDRESS IN D

	(THE BITS HAVE BEEN DISPLAYED)

011			dad	b		increment display counter

	WHAT'S IN REGISTER B?
	WHAT'S IN REGISTER C?

	ADD B TO H AND C TO L AND MARK THE BIT IF IT BREAKS 16

322 010 000	jnc	beg

	IF IT DOESN'T CARRY, JUMP TO LOCATION 08.
	IF IT CARRIES, CONTINUE.

333 377		in	0ffh		input data from sense switches

	GET THE INPUT OF DEVICE FF.
	LOAD IT INTO REGISTER A.
	(WHAT DO THE SWITCHES SAY?)

252			xra	d		exclusive or with A

	XOR OF REGISTERS D AND A.
	IF A BIT IN ONE IS ONE THEY BOTH ARE ONE,
	BUT IF THE BITS IN TWO ARE ONE THEY'RE NONE.
	THIS IS XOR. LOAD REGISTER A


017			rrc			rotate display right one bit

	AND NOW SHIFT THE ACCUMULATOR ONCE.
	MOVES THE ZEROS, MOVE THE ONES.

127			mov	d,a		move data to display reg

	MOVE EVERYTHING FROM A TO D

303 010 000	jmp	beg		repeat sequence

	JUMP TO LOCATION 08

			end

	THIS IS THE END, BUT IT NEVER ENDS.