Quick lo-res sprite parser in basic

1 post / 0 new
Offline
Last seen: 6 years 10 months ago
Joined: Jun 3 2016 - 00:25
Posts: 2
Quick lo-res sprite parser in basic

Hey guys,

Recently I've been messing around with graphics on the apple, and while trying to wrap my head around hi-res mode I decided it might be fun to make something quick in lo-res.

Doing this in Applesoft with the PLOT command is easy but quite slow, especially when you try and add things such as collision or sound effects.

So I tried making a simple routine that moves a sprite around the screen by poking values directly into memory.

This has a few benefits, it works so fast that any collision programming shouldn't slow it down too much, and since the value for the sprite is poked directly into ram, it can be any combination of colors in lo-res, 0 through 255. I chose 239 because it looks like a tiny person.

What I have so far just barely works. It uses the joystick and often crashes or gives me errors (good thing the computer boots in seconds (also thank god for DOS, if I had to reload the program from cassette every time I'd go crazy)) but I've taken it as far as I can with my knowledge so I figure I'll share it here in case anyone wants to play around or improve it.

It might be important that I haven't tried this on an emulator yet so I don't know how it will handle the joystick input.

100 GR
110 X = 0: Y = 0: CA = 1024: C = 239
120 POKE CA,C
150 XP% = PDL (0): FOR PX = 1 TO 10: NEXT: YP% = PDL (1): FOR PY = 1 TO 10: NEXT
160 HOME : PRINT CA: PRINT X;: PRINT " ";: PRINT Y
170 IF XP% > 130 THEN 300
180 IF XP% < 120 THEN 400
190 IF YP% > 130 THEN 500
200 IF YP% < 120 THEN 600
210 GOTO 150
300 POKE CA,0: X = X + 1: CA = CA + 1: POKE CA,C: GOTO 150
400 POKE CA,0: X = X - 1: CA = CA - 1: POKE CA,C: GOTO 150
500 POKE CA,0: Y = Y + 1
510 IF Y = 8 THEN CA = CA - 856
520 IF Y = 16 THEN CA = CA - 856
530 CA = CA + 128: POKE CA,C: GOTO 150
600 POKE CA,0: Y = Y - 1
610 IF Y = 16 THEN CA = CA + 856
620 IF Y = 8 THEN CA = CA + 856
630 CA = CA - 128: POKE CA,C: GOTO 150
999 END

In line 110, the value for CA, 1024 is the starting address in decimal for lo-res graphics (and text).
the value for C can be changed to make the little character look different, set it to 255 if you just want a solid white block

Lines 510, 520, 610, and 620 try to account for the Apple's quirk with storing data to display on screen. The 8th row of pixels are stored starting at address 1920 ($780) in ram while the line directly below it starts at address 1064 ($428)

That's all I've got for now

-Del