Monday, November 30, 2015

READY (Atari BASIC Redux)

READYI recently found an active online community of Atari 8-bit computer retro enthusiasts. Having grown up playing games on and programming an Atari 400 (1982-1985) and an 800XL (1985-1989), it’s been fun getting back into it. A couple years ago I loaded the Atari800XL emulator on my Raspberry PI to show the kids the games I used to play. They were unimpressed. Too bad, because I could beat them at Asteroids. More recently, I’ve been working on a BASIC program using the Altirra emulator on my Windows 7/10 desktop. I learned about a 10-line BASIC game programming competition on the ANTIC podcast, which gave me a goal for my retro ruminations. I’m hoping they’ll rerun the competition in 2016 so I can enter.



To prepare, I decided to brush up on my BASIC. I only ever used Atari’s BASIC (cart. on the 400 and built-in on the 800XL), but have since learned there are many more BASICs from which to choose. For this program, I’m using Turbo BASIC XL because it’s faster and supports block memory copies. When I tried to write games in junior high, I didn't know about Atari's player-missile graphics (hardware based sprites) although I did learn a little of the C64 sprites in 8th grade computer programming. This time around, I set out to learn a couple of the things I missed growing up: page flipping and hardware sprites. To use these techniques in Atari BASIC requires lots of PEEKs and POKEs and some understanding of the memory map, which probably explains why I didn't get it back then.

I asked the boy what kind of game I should write and he thought "20-ball Pong" would be hilarious. I prototyped it in Python to get the game logic down so I wouldn't have to design the game while relearning BASIC. The concept is pretty easy and Python on a modern machine is speedy. Coding up the ball motion in an emulator, I quickly re-discovered how slow Atari BASIC was and abandoned trying to use hires graphics. The game(I call this version LMNOPing!) is now in text mode with 5 inverse ATASCII characters (L-P) standing in for software sprites and a player-missile paddle. The ball motion is not smooth moving 1 space per frame, but the paddle is speedy. The game play is still really slow, but has served the purpose of learning some new (to me) programming.

Page Flipping

To create motion, an object on the screen needs to be redrawn every frame at a new location while erasing the old location. This algorithm can easily create a flickering effect. The way around it is to draw the new frame while displaying the current frame and then flipping the page to show the updated screen. My Python prototype uses this technique. Because the Atari uses memory mapped graphics in RAM, it's pretty straightforward to implement in BASIC - a number of old magazine articles cover the topic (links are below). Point the graphics chip to display buffer A while filling in buffer B. Then flip the screen by pointing to B while filling in A.

I learned an interesting feature of the clear screen (CLS) command that is probably documented somewhere, but wasn't obvious to me. In GRAPHICS 0 (text mode), and maybe in others although I didn't test it, the CLS command will put 0's into the memory starting at the graphics map pointer filling in all the way to another pointer called RAMTOP (top of memory). I thought it would just clear out 4 pages (1 KByte) of RAM. The consequences are if one points to buffer A and doesn't update RAMTOP to point to the end of buffer A, CLS will clear both A & B. (Thanks to Wade Ripkowski for pointing out this was indeed documented.)

Player Missile Graphics (Hardware Sprites)

My 8th grade computer programming teacher taught us about C64 sprites near the end of the semester. I used them in my final project, which was a Simon game. For some reason, I never learned them on the Atari. I guess I never really understood why one would want to use some blocky single color thing when there are some great graphics modes to use. Obviously, I never tried to write a program with a software sprite back then; otherwise, I would have seen them for the genius they were.

For this game, I’m going pretty simple with a basic bar that is moved vertically on the screen using the paddle controller. To move the graphic, the bytes have to be copied from one location to another and erased from their old location. Instead of tracking the move, it’s easier just to rewrite the whole column by copying a buffer with the appropriate offset. This is OK since I have plenty of RAM. I suppose in a tight 8K cartridge game this would be wasteful since I use 256 bytes just for the buffer and another 256 bytes for the sprites.

What’s Next

I squeezed this program into 8 lines for practice and might add some sound. Not sure if it’ll be an entry to the 10-liner competition, but it’s been a fun challenge.

Resources



Saturday, November 7, 2015

Destiny Ghost - 3D Print for Halloween Costume

The boy really really likes to play Destiny. So for Halloween, it was an obvious costume choice. The only real important thing to him was the Ghost - an electronic companion that floats by your side in the game. Thinking I might draw one up in SketchUp to print, I started looking at images. But, then I found a really nice design at Thingiverse and ended up printing it instead.

Searching images for Destiny cosplay yields several characters with Ghosts. Most of them are holding the little light in their hand, but some had it hanging above their shoulder. To hang our Ghost, I designed a hanger insert and glued it between the Ghost halves during assembly. Wife made a cross-body harness to hold the boom for suspending the piece above the boy’s shoulder. It worked pretty well.





Clogged Printer Nozzle

Halfway through printing the second half, the printhead clogged. I learned to change out the nozzle. At first, I thought I could just melt it out at 250-C, but that didn’t clear the plug. I tried a couple other techniques I found online to no avail. I broke down and ordered a new nozzle. After clearing the stuck filament, replacing the nozzle, and hacking the G-Code, I was able to finish the print in progress. It was already 5 hours in and I didn’t want to have to start over. The piece has a little dislocation because I didn’t get the restart layer exactly right, but it’s acceptable. 

I had to recalibrate the printer before printing anything else. It took a while to figure out how to make the prints stick with the new head - I think because it’s an aftermarket part and is a different shape from the original. I suspect it transfers heat away from the filament because the tip has a large cross section. To get the first layer to stick to the blue tape, I have to really get a good squish. For more testing, I printed my go-to calibration cube and saw that bridges were sagging. Lowering the temperature 5 degrees helped (maybe the different nozzle shape blocks the cooling fan airflow), but then the prints had trouble sticking on the first layer. I discovered in Slic3r, there’s an option to print the first layer at a different temperature - bumping it up 5 degrees solved my problem. Now I’m back in business.