AppleIIbot 280 char Applesoft Demos -- Part 3


Animated Lo-res X xor Y mod 9


link

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
1FORI=0TO130:POKE885+I,4*PEEK(2125+I)-192+(PEEK(2256+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",=n9D`V/QmYnHlX1OnQ8YlB25AnR8J#N9261nV6EmAn8e,k1Z0CT/Z18IlR83nR,gidWnXOn,`X#XT,k0j_E_B1DQ0inCH/QbNo8@B>mJ>mJ>mJ8@BFm2026BnBk=IoHCJ0S+4'HN?-/@WC#4$6$?%+%CLMCW6#'`%BYMPPPMP-@6%0

Link to source: mod9.s

Xor Zoom


link

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.
1FORI=0TO123:POKE892+I,4*PEEK(2125+I)-192+(PEEK(2249+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",cl9E`P.QaNnUnKe/QbVn?j0FlRB28=mY8J0N9:61nX0QnQnIFnJnYaHl+PnUmKf/QlR>emAo8If63nb`:dgjh<][[e/J#Pl$Q0_j0LT0k0j_9`>0ST0CM0P0CO0S+E[4BWTP%6*0+#$W@X:4?+4&C###?BYVU`'#421#&

Link to source: xor_zoom.s

Hires Mod9


link

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).
1FORI=0TO122:POKE1013+I,4*PEEK(2126+I)-192+(PEEK(2249+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&"7G1,clNnX0QoP.X/Yo74mP.QiQAiY_(2Yjc2b0l#W0C91.lZTB2UkmQ7:Q08Om8Fm8JkYojdaioYo`Ta^bmYmb1`0Z%Nna2d0Z0NnCl0X.X0QV04bl1jh*jlblH'S0#C''E<;C6$Y#P+L$/%%E$-#SA*3W('00+)#&D+

Link to source: mod9.s

Hires Sierpinski Zoom


link

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.
1FORI=0TO133:POKE1013+I,4*PEEK(2126+I)-192+(PEEK(2260+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",clLnQfX@J8Z'O9P.QhPnQn6TmIjPnUmInQnS/4;nW04j`iYfH0PoT&goh91OlS>0_+3S8/X$U10QJZNo_049Ig6o6k0>FmjRdjRlbJIS(>kG1hbQe40mPG1W96E/S?/in4^;PS8I@HE=%884)4@#3H(M1M67FS;X$70'1#@;C%S30,8E%'

Link to source: sier_hgr.s

LIST and Blocks (BASIC)


link

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) 
19 HOME
20 LIST
30 GOTO 10

Scrolling Tokens


link

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.
1FORI=0TO133:POKE882+I,4*PEEK(2125+I)-192+(PEEK(2259+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&"SkQQYdK<Z/QWN=8akQjPQ+;nT/_/8d27i#73F1W/88b/:2W047i/2PW09_08+]n[/8M8_(7Qd\QoC=cYoHVnc/8jh4b_CK/bOc1JJC]0QoY9L8i6Xo?WCc/2l1T+A7OCH00CI0@:<*0A:W5'5Z4'@*3*$$W44CN#.]5#+A4#0$D3GG#9,#1

Link to source: move_bot.s

Text Boxes (BASIC)


link

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
18 HOME
20 FOR I=1 TO ((B-T+1)*W)-1:?CHR$(C);:NEXT
30 GOTO 10

Xor Xtravaganza


link

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.
1FORI=0TO127:POKE1013+I,4*PEEK(2126+I)-192+(PEEK(2254+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",clMnQmZ:Fgin8H'VLX18J1ddhQi8H/X1dmYm2dR6J%akV7QgR8A/X0Xl6J1]lZ?QoZP8bjX7Ud6J1]l[:0BOS>+j?,Z?0bHLeiiYCR?1YbXRZHX084mHXn8=kagF>f0S4(P$K#%E&+9(CS4.C$+?'$OT+?3';7'C8(O'#$(LC&

Link to source: xdraw128.s

Alligator Disk


link

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.
1GR:POKE49234,0:DEFFNP(X)=PEEK(2162+I*5+X)-35:FORI=0TO26:FORX=0TO(I=18)*9:COLOR=FNP(0):FORY=FNP(3)TOFNP(4):HLINFNP(1),FNP(2)ATY:NEXTY,X,I:GETA
2"*#J#R#,A%P(66DN(485?(399;(574@*677>*578=(::==2-@&1*AA34)=>//%,,0<>++/>(()#JOR'CJ@N'/JDK'02BC#DEAB#HIAB212LN267LN

Giant Cursor


link

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.
1FORI=0TO139:POKE876+I,4*PEEK(2125+I)-192+(PEEK(2265+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&"8FoV7Q;Z2M:Z$U076nV1Q.W3U082mZ.P;X0X28:eX3X0X18:lX0_01W02^am^U0_V0OV0b4deY1P;X.X;80nbb`0SmM[0=/SS.i5h;T:b/ch;E`Q/Zb8Zmbdj:ERU0Zb8RmbdnCc0CH0#4'4V'4W/49,#G,&+$$SYUT$9(7##4\8Q<86#A#+3[$C#//

Link to source: cursor.s

Ray Casting (BASIC)


link

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.
0GR
1Z=H:FORI=0TO39:Z=Z+.04:X=SIN(Z)/2:Y=COS(Z)/2:D=0:R=P:S=Q
2D=D+1:R=R+X:S=S+Y:C=0:A=ABS(R):B=ABS(S):IFA>6ORB>6THENC=5
5IFA>3ANDA<5ANDB>3ANDB<5THENC=1
6IFC=0THEN2
7U=40/D:IFU>19THENU=19
8V=19-U:U=19+U:COLOR=7:VLIN0,VATI:COLOR=C:VLINV,UATI:COLOR=8:VLINU,39ATI:NEXT:H=H+.2:GOTO1

Animated Stargate (ASM)


link

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.
1FORI=0TO123:POKE892+I,4*PEEK(2125+I)-192+(PEEK(2249+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",=n9D`S0QnZ0Oo6F3QeWoV/Q6QBk=J8QoM:Q9a;X9R1I0NnYlR86nYmYo76nVo8InYaVn76nRmY776`foWB8RmR1I1VhoR]>Rnj$NocnYnb1[Waod1V2Qc@S0CO0S+@*,4L4;6*4,I70.$*'0#Z'?3[0C75+@W=)G&4V&&

Link to source: stargate.s

Tunnel (BASIC)


link

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
6 COLOR=N+P:HLIN J,W AT I:HLIN J,W AT Z:VLIN J,W AT I:VLIN J,W AT Z
7 NEXTI,Q:N=N+1:IF N=32 THEN N=16
8 GOTO 2

Tunnel (ASM)


link

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.
1FORI=0TO140:POKE875+I,4*PEEK(2125+I)-192+(PEEK(2266+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",=nQYh$i4571RHB<AU\jRZlkI0d\foT0QmZ0HlZPl2,11fXR?o>F4fP0\6hnC3QoZRQ;Q-NnbmYaFo8InNlR76nRmYk76lRZVn8:nYbVn8:n^e4Z[aj3[7XXQSRKML@FFDCA0:;8904G0SIVWC=#K/[<)HH=E04#=@##\AX#O'?3+0#W#SK5788M&a0_

Link to source: t.s

Animated Starfield (Lo-res)


link

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)
1FORI=0TO138:POKE877+I,4*PEEK(2125+I)-192+(PEEK(2264+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",=nU38U.b*lX2ZD8ZoV/Q<]L]P8,m]L5f(::b:\0Oo]T8c0Z<7`:\6eHl3a<PJ\$5GnULSnUP80ba0)]0Z2_;]Yn^0kUTZ/lQW^,k::10MFioH2/0Bk5J$Uo^=m@2nV:4#?o5J5DBK0S1RK*#4#$3SF$I$2##%+-V#<#S_E'*'445:D&76T3C#Y'3&

Link to source: starbot.s

Animated Starburst (Hi-res)


link

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.

1FORI=0TO131:POKE884+I,4*PEEK(2125+I)-192+(PEEK(2257+I/3)-35)/4^(I-INT(I/3)*3):NEXT
2&",clU68V.b*lX.V7,fnV/Qh]\+d0FGb`\:b0T0OoQK]P7g/JPZUDe0l2aiQnVQWoX08=kYnC`,7a.b4X:^Rn^,kUS^0kU\\0l3N2/U0foH.31?o6I0Xob>m04nV:./Bo6H7J0S1PKFS4'W4#$G43*#%-%I#F#6.F?3'(,@(130(&$%;&S

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