AppleIIbot 280 char Applesoft Demos -- Part 3

Animated Lo-res X xor Y mod 9


This was an attempt to plot the (X^Y)%9 function (X exclusive-or Y modulus 9) which makes some cool-looking art. Trying to research simple things to plot other than Sierpinski. The issue is that doing modulus (remainder) math on Apple II is really complex, BASIC doesn't support it, and on 6502 you have to multiply/divide by 9, neither of which is that fast. One way to get around this is just make a 256 byte lookup table of the values 0 to 8 repeated, and use that to do the calculation.

If you're interested in functions like this, there was a fascinating twitter thread here

Link to source: mod9.s

Xor Zoom


This one was surprisingly popular. It was an attempt to do the Sierpinski Zoom trick (X AND Y) with xor instead. It gives sort of a zooming squares effect.

Link to source: xor_zoom.s

Hires Mod9


This is the Mod9 effect listed previously, but in hi-res rather than lo-res. Looks cooler to see the full screen, but also slower. It's ANDing with various values to try to get better colors out of things (artifact color helps a bit here).

I've mentioned before, but Apple II hires is a pain. War learning how to make it compact, there are actually MOVE.RIGHT and MOVE.DOWN routines in ROM that help a bit with making things compact. Also note it only draws up to column 255, as otherwise it takes a bit more code to handle the rest of the screen that won't fit in a single byte (up to 280).

Link to source: mod9.s

Hires Sierpinski Zoom


Was trying to put together a demo with a fast hires sierpinski zoom. Tricky. Also fast, but not fast enough. I do like the rainbow-like color of the artifacts.

Link to source: sier_hgr.s

LIST and Blocks (BASIC)


This one is pure BASIC, no need for much optimization. Playing with the Applesoft text window, where you can peek left/right/top/bottom ranges for the screen, then text like LISTing your code will be limited to that subset of the screen. Then flipping on graphics mode which turns the text into striped rectangles.

The BBC Micro people noticed this, and it was amusing to see them try to approximate this effect on their system which doesn't have text windows or text/graphics duality.
10 T=INT(RND(1)*24)
11 B=T+INT(RND(1)*15)+1: IF B>23 THEN B=23
12 L=INT(RND(1)*35)
13 W=INT(RND(1)*30)+1:IF W+L>39 THEN W=38-L
15 POKE 32,L:POKE 33,W:POKE 34,T:POKE 35,B
17 Q=INT(RND(1)*2):X=PEEK(49232+Q) 
30 GOTO 10

Scrolling Tokens


I was trying to do something neat where random BASIC tokens would scroll by. Getting text in small programs is always hard, as text takes up a huge amount of space. But all the BASIC tokens are there, in plain text in ROM, so I could just randomly grab them, right? It turns out this is a pain. The Applesoft ROM routines return back to the BASIC parser by jumping, not via RTS (return) so you can't just re-use routines. Also the strings are stored in memory not NUL terminated, but with a high bit set to indicate the end (which is compact, but makes it harder to parse them). BASIC actually finds the tokens by doing a linear search, rather than having a lookup table, which makes things slow and akward to get them. Needless to say this wasn't one of my more popular experiments.

Link to source: move_bot.s

Text Boxes (BASIC)


Exploring the text-window support on the Apple II, but using it purely to draw overlapping colored rectangles this time. Again abusing the text/lores equivelance of the hardware.
5 GR:POKE 49234,0
10 T=INT(RND(1)*20)
11 B=T+INT(RND(1)*15)+1: IF B>23 THEN B=23
12 L=INT(RND(1)*35)
13 W=INT(RND(1)*30)+1:IF W+L>38 THEN W=39-L
15 POKE 32,L:POKE 33,W:POKE 34,T:POKE 35,B
17 C=INT(RND(1)*96)+32
20 FOR I=1 TO ((B-T+1)*W)-1:?CHR$(C);:NEXT
30 GOTO 10

Xor Xtravaganza


This one is actually a 128-byte demo, Xor Xtravaganza, that got 2nd place at Outline Online 2021 demoparty. You can see more info on it at the link. It's doing a lot with Applesoft shapetables and using ROM locations as shape information.

Link to source: xdraw128.s

Alligator Disk


I made this one for 5.25" floppy day (May 25th). At first it was just a floppy, but I had a few rectangles left so I naturally thought I could try to fit an alligator too, despite it being explicitly warned against in the old Beagle Bros floppy disk warnings.

Giant Cursor


Someone else's entry reminded me of the delete char on the Apple II, and I thought maybe I could make a giant command prompt. I wanted to do it in text mode, as the color-killer would be off allowing for sharp graphics. I also wanted to draw two pages, one with the cursor and one with it off, so it would blink. My original plan was to do this in plain BASIC ,and this should have been relatively simple, but was a huge pain because I had forgotten that BASIC programs by default load to Text PAGE2, so if you want to page flip you really have to do assembly language.

There were further complications, once I finally got it running twitter inserted an http:// into the middle of the text because there was a .kr followed by a slash so it decided it was some sort of Korean URL. I had to optimize the code to remove an instruction which altered the encoding enough to not trigger this.

Link to source: cursor.s

Ray Casting (BASIC)


I somehow got started looking at ray-tracing, and ray-casting (such as is used in Wolf3D). There is a 256-byte Commodore 64 raycaster (1bit by Crescent/Wisdom) which I used as an example. It is possible to get a version of this on Apple II in 256 bytes, and while I tried mightily I could get it to fit in 140 bytes for the Apple II bot.

It is, however, possible to translate the algorithm into BASIC. The problem is that it's really really slow. Also the map is a bit limited. It's actually more of a ray-marcher than a ray-tracer, which means it has fish-eye and not as smooth edges as it could be. But hey, it's 280 bytes of BASIC. If you want the full 2.5D experience on Apple II, I reccommend checking out the "Escape from the Homebrew Computer Club" game.

Animated Stargate (ASM)


This one is yet another buggy effect that came up when trying to make another effect. I think I was trying to make a tunnel and went out of bounds a bit.

Link to source: stargate.s

Tunnel (BASIC)


I've wanted to have a good Apple II "tunnel" effect for a while. It's hard to make them, but it's a staple in the demoscene.

On March 7th @hisham_hm posted a nice BASIC tunnel type thing, so I started from there to see if I could build on it at all.

Here's something in BASIC that looks nice, though it's a bit slow.
0 DIM A(9,9):FOR I=0 TO 8:FOR J=0 TO 8:A(I,J)=40/(2+I+J/7):NEXTJ,I
1 GR:N=23
2 FOR Q=6 TO 0 STEP -1:P=0
3 FOR I=0 TO 19:IF 20-I>A(P,Q) THEN 7
4 P=P+1:Z=39-I:J=I+1:W=Z-1
7 NEXTI,Q:N=N+1:IF N=32 THEN N=16
8 GOTO 2

Tunnel (ASM)


Here is the previous tunnel effect, this time in assembly language. In order to fit it's using a compressed lookup table for where the color transitions happen.

Link to source: t.s

Animated Starfield (Lo-res)


This is another one I've wanted for a while. I've made lo-res starfields but all of 1k or so in size.

Sound warning, if you run this on real hardware the frame delay is using the BELL (beep) command for the delay. This doesn't matter on the bot as it doesn't support sound.

3d stuff like this is tricky as it needs a divide routine, something 6502 is not good at. It turns out though for 8-bit divides using an iterative subtract isn't too bad and is fairly compact. Although for this we needed a signed divide and that's even more of a pain.

Getting multi colors of stars was not easy either. Originally I wanted to base it on distance but that didn't really work on lo-res.

In the end I couldn't get this in under 142 bytes so just cheated and made the math slightly innaccurate (removed a call to SEC [set carry] before a subtract)

Link to source: starbot.s

Animated Starburst (Hi-res)


Decided I'd try for a hi-res starfield. As always some interesting bugs happened along the way, and I decided I liked this starburst where I wasn't erasing the old stars properly.


Link to source: staroops.s
On to Part 4
Back to Part 2
Back to main Apple II bot page