dos33fsprogs/two-liners
2020-10-10 17:49:21 -04:00
..
convert4_4 appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
convert6 appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
convert6_2 appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
convert_xor appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
asteroid.bas 2liner: various 2020-10-05 18:55:32 -04:00
asteroid.shape 2liner: various 2020-10-05 18:55:32 -04:00
autumn.bas appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
circles.bas appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
concert.bas 2-liners: update with nyan 2020-10-07 01:34:28 -04:00
convert_back.c appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
convert_qkumba.c two-liners: add some more examples 2020-10-10 17:49:21 -04:00
convert_to.c appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
entropy_small.bas appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
entropy.bas
ENTROPY.BAS
entropy.dsk
entropy.s
flame2.bas appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
flame.bas appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
load.s appleiibot: wasted a lot of time getting assembly fitting in a tweet 2020-10-04 01:31:39 -04:00
lots.bas dhgr: some double-hires code 2020-10-07 17:01:18 -04:00
Makefile two-liners: add some more examples 2020-10-10 17:49:21 -04:00
nyan.bas 2-liners: update with nyan 2020-10-07 01:34:28 -04:00
person1.shape 2liner: various 2020-10-05 18:55:32 -04:00
person2.bas 2liner: various 2020-10-05 18:55:32 -04:00
person.bas 2liner: various 2020-10-05 18:55:32 -04:00
person.shape 2-liners: update with nyan 2020-10-07 01:34:28 -04:00
qkumba_autumn.bas twoliners: got autumn fitting 2020-10-04 23:50:13 -04:00
qkumba_seasons.bas twoliners: got autumn fitting 2020-10-04 23:50:13 -04:00
raster2.bas two-liners: add some more examples 2020-10-10 17:49:21 -04:00
raster3.bas two-liners: add some more examples 2020-10-10 17:49:21 -04:00
raster4.bas two-liners: add some more examples 2020-10-10 17:49:21 -04:00
raster5.bas two-liners: add some more examples 2020-10-10 17:49:21 -04:00
raster.bas dhgr: some double-hires code 2020-10-07 17:01:18 -04:00
README.entropy
ship.bas 2-liners: update with nyan 2020-10-07 01:34:28 -04:00
ship.shape 2-liners: update with nyan 2020-10-07 01:34:28 -04:00

                         Apple II Entropy Demo (128B)
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                       BASIC version -- Dave McKellar
                6502 Assembly Version -- Deater (Vince Weaver)

Webpage
=======
http://www.deater.net/weave/vmwprod/entropy_demo/

Background
==========

Back in the day people would challenge themselves to write one or two line
BASIC programs that did impressive things.

One of my favorite is "Entropy" by Dave McKellar from Toronto.

This two-line BASIC program can be found on the Beagle Brother's
Apple Mechanic Disk.

I thought it would be interesting to see if I could convert it to 6502
assembly language.


The original code looks like this:

1 ROT=0:FOR I=1 TO 15: READ A,B: POKE A,B: NEXT: DATA
	232,252,233,29,7676,1,7678,4,7679,0,7680,18,7681,63,
	7682,36,7683,36,7684,45,7685,45,7686,54,7687,54,7688,63,
	7689,0
2 FOR I=1 TO 99: HGR2: FOR E=.08 TO .15 STEP .01:
	FOR Y=4 to 189 STEP 6: FOR X=4 to 278 STEP 6:
	SCALE=(RND(1)<E)*RND(1)*E*20+1: XDRAW 1 AT X,Y:
	NEXT: NEXT: NEXT: NEXT

Line 1 sets up an Applesoft BASIC shape table. The Apple II lacks any sort
of sprite or graphics acceleration, but BASIC provides a software vector
drawing engine. The data statements setup vector art for a simple box shape.

Line 2 loops across the screen, drawing a box scaled to size 1, but randomly
scaling it up to size 2 leading to some interesting patterns. It is drawn
with XDRAW which draws the XOR (inverse) of what's already there. When it
hits the end of the screen, it starts again, this time erasing things.
But again randomly boxes of different sizes are drawn leading to interesting
patterns. After iteration 3, boxes of size 3 are also drawn. And after
iteration 8 it clears the screen and starts again.

This sound simple, but it leads to some neat patterns.


128B 6502 Assembly Demo
=======================

I thought it would be neat to see how small I could make this in assembly
language. Currently I have it down to 118 bytes (the executable is 122
bytes because DOS33 includes size/address filesystem metadata in the file
itself).

It started as a direct port of the BASIC version, it probably can be made
smaller. The assembly code calls directly into the BASIC firmware in various
places.

There were some challenges. One is that Applesoft BASIC has no integers:
all numbers are stored in 5-byte floating point. This made it hard to do
compact math, though the main issue was dealing with the random numbers.

As an aside, the Applesoft random number generator is pretty awful and you
can actually find multiple academic articles written at the time complaining
about it.