[stella] Crackers' Easy Playfield Graphics Code

Subject: [stella] Crackers' Easy Playfield Graphics Code
From: crackers@xxxxxxxxxxxxxxxxxxxxxx
Date: Sat, 8 Mar 1997 15:33:43 -0500 (EST)
Okie Dokie... (no pun intended Bob).

I figured out why my first attempt at compiling my code didn't work. It was
just a I had figured... 5:00 in the morning is no time to still be up writing
code. I had made typos and some errors which where just out an out whacky.
Chalk it up to programming while sleepy and not having written anything
in machine language since the early 80's. (Brian Mulruney was Prime Minister,
Ronald Regan was President). Having slept in until 2:00pm and taking another
look at my code the errors jumped out and slapped me in the face.

Anyways... do you remember that playfield graphics editor idea I proposed
not long ago (i.e. babbled on about). Well here's a routine that would
be able to take the data from that hypothetical editor and display it on
a 2600 as playfield graphics.

This routine is very simple, the other programmers will probably laugh and
call it names. They'd never let my source code, be in any video games.
But then one foggy christmans night....

Like I was saying. All this does is draw a playfield, simple and straight
forward. I don't know what modifications would need to be done to make
it work in a game environment. I don't want to think about that right now.
With this code I've now officially lost my 2600 cherry ("Rescue Bira Bira"
was just 'heavy petting'). And just like the real thing, it was a little
painful at first, and was over before I knew it. And it left me wondering
what all the fuss was about.

Special thanks to Nick Bensema's "How To Draw A Playfield" tutorial code.
I will always think of you as my slutty friend who's done it many times
and sat me down in the school cafeteria to tell me what to expect during
my first time and how to handel it. In otherwords you're like Pheobe Cates
in "Fast Times At Richmond High". ;)

And with no further delay, here is my simple (probably laughable simple)
source code to draw a playfield (using data generated from a hypothetical
playfield graphics editor that doesn't exist). ;)

-----------------------------------------------------------------------------

	processor 6502

VSYNC 	=  $00       ;this tells assembler what
VBLANK 	=  $01       ;the locations of all those funky
WSYNC	=  $02       ;2600 codes are
COLUPF	=  $08       ;
COLUBK	=  $09       ;you can see that this demo doesn't really do
CTRLPF	=  $0A       ;much.
PF0	=  $0D       ;
PF1	=  $0E       ;I had also made some stupid 5:00 in the morning
PF2	=  $0F       ;errors here that wouldn't let my first attempt
CXCLR	=  $2C       ;compile. Make sure you are well rested before you
INTIM	=  $284      ;attempt to programme the Atari 2600 or you risk
TIM64T	=  $296      ;losing your sanity.

	org  $F000

start	SEI            ;setting up the 6507
	CLD
	LDX  #$FF
	TXS
	LDA  #$00

zero	STA  $00,X     ;zeroing out all the locations
	DEX
	BNE  zero

main	JSR  vertb      ;this is the main loop of the programme
	JSR  scrnvar    ;starts with vertical blank then loads the screen
	JSR  draw       ;variables then draws the screen, then does the
	JSR  oscan      ;overscan, then does it all over and over again
	JMP  main       ;until you terminate the programme.

scrnvar	LDA  #$00        ;make the playfield graphics black
	STA  COLUPF      
	LDA  #$4F        ;make the background pink 
	STA  COLUBK
	LDA  #$01        ;reflect the left half of the playfield on the
	STA  CTRLPF      ;right
	RTS

vertb	LDX  #$00         ;thank you Nick Bensema for teaching us all
	LDA  #$02         ;how to do a vertical blank.  
	STA  WSYNC        ;who knows if I could have figured out this one 
	STA  WSYNC        ;on my own. I want to have your baby!
	STA  WSYNC
	STA  VSYNC        ;<- here was one of my 5:00 in the morning errors.
	STA  WSYNC        ;I had typed WSYNC instead of VSYNC. Bleary eyes 
	STA  WSYNC        ;and programming make a deadly combination!
	LDA  #$2C
	STA  TIM64T       ;much like cheese burgers an loneliness. 
	LDA  #$00
	STA  CXCLR        ;<- don't know why I left this in... but what the 
	STA  WSYNC        ;heck it looks cute.
	STA  WSYNC
	RTS

draw	LDA  INTIM         ;getting ready to draw the screen
	BNE  draw
	STA  WSYNC
	STA  VBLANK
        LDY  #$08          ;how many scanlines is each block?
	LDX  #$17          ;number of blocks of data. LDY * LDX = 192! 

load	LDA  playf0,X      ;load in the data for playfield 1
	STA  PF0
	LDA  playf1,X      ;load in the data for playfield 2
	STA  PF1
	LDA  playf2,X      ;load in the data for playfield 3
	STA  PF2

grfx	STA  WSYNC         ;draw the scanline
	DEY                ;decrease the block number 
	BEQ  block         ;if it's zero it's time for a new block
	JMP  grfx          ;if not then repeat the previous scanline

block	TXA                ;another 5 A.M. error had "LDA X" what was I on?
	BEQ  clear         ;checks to see if you've reached the last block.
	DEX                ;if not then got ot the next block number.
	LDY  #$08          ;set up for a new block.
	JMP  load          ;go load your new block of data in. 

clear   LDA  #$02          ;all done the screen. Now let's clear everything
 	STA  WSYNC         ;and get ready for the next exciting screen.
	STA  VBLANK        ;which in this case, just happens to be the same
	LDX  PF0           ;as the first.
	LDX  PF1           ;isn't this fun? 
	LDX  PF2
	RTS

oscan   LDX  #$1E          ;now we're getting ready to do the 30 lines of
                           ;overscan 
waste	STA  WSYNC         ;and in this demo we're just going blow them all
	DEX                ;off. But in a real game you wouldn't waste all
	BNE  waste         ;these valuable cycles. Not unles you want a   
	RTS                ;really dull game.
 
	org  $FF00
               
playf0	.byte $00   ;and here are the graphics for each block. My programme
        .byte $00   ;draws 24 blocks each is 8 scan lines high. 24*8=192 
        .byte $00   ;so by changing the values for LDY and LDX up in the
        .byte $00   ;draw routine you can alter your vertical resolution for
        .byte $00   ;your playfield graphics. Just make sure that both values
	.byte $00   ;multiply together to make 192. This will let you draw
	.byte $00   ;1*192=192 
	.byte $00   ;2*96 =192
	.byte $00   ;4*48 =192
	.byte $00   ;6*32 =192 
	.byte $00   ;8*24 =192 (also makes nice square blocks!) 
	.byte $20   ;16*12=192
	.byte $20   ;32*6 =192 (okay, we're getting rediculous)
	.byte $70   ;64*3 =192
	.byte $f0   ;96*2 =192
	.byte $f0   ;192*1=192
	.byte $f0   ;
	.byte $e0   ;Anyways... also note that the graphics data here
	.byte $e0   ;is stored upsidedown. Trust me, it's much easier
	.byte $c0   ;to load it this way.
	.byte $80   ;
	.byte $00   ;Using this kind of drawing routine would make it easy
	.byte $00   ;to create a playfield graphics editor that will auto
	.byte $00   ;generate the playfield data in a text file. Then you
playf1	.byte $00   ;can just cut and paste the data into your source code.
	.byte $00   ;But I honestly don't know how well my playfield drawing
	.byte $00   ;routine can be adapted to work in a game. Maybe our
	.byte $00   ;resident "2600 Gods" Nick Bensema or Bob Colbert can
	.byte $00   ;offer some criticism.
	.byte $00   ;
	.byte $00   ;Well that's about all I've got to say on the subject.
	.byte $00   ;It was actually a lot of fun figuring this stuff out
	.byte $00   ;and now that I've actually written my own code to draw
	.byte $00   ;a screen, the 2600 is a lot less scary now.
	.byte $10   ;But don't expect a game from me anytime soon. What i've
	.byte $10   ;just done now is the equivalent of a 
	.byte $11   ;10 PRINT "HELLO"
	.byte $3b   ;20 GOTO 10
	.byte $7b   ;basic programme. It's simple and probably silly, and no
	.byte $ff   ;doubt the real programmers will look at it and laugh at
	.byte $ff   ;me and say something like. "Feh! I could have done that
	.byte $ff   ;whole thing with three lines of code!"
	.byte $ff   ;But hey, we've all got to start somewhere.
	.byte $ff   ;Anyways, feel free to muck about with this and draw your
	.byte $ff   ;own playfield pictures by editing the data. Maybe we
	.byte $ff   ;could have an informal "2600 playfield graphics art
	.byte $7c   ;contest."
	.byte $30   ;
playf2	.byte $00   ;incidently... if you don't know what this is supposed
	.byte $00   ;to be a picture of, try singing "Nanana nanana Nanana
	.byte $80   ;nanana" over and over while looking at the picture.
	.byte $80   ; 
	.byte $c0   ;
	.byte $c0   ;                       CRACKERS
        .byte $c0   ;           (Baby's first code from hell!!!!!!)
	.byte $e2   ;
	.byte $e2   ;
	.byte $f2   ;
	.byte $fa   ;
	.byte $ff   ;
	.byte $1f   ;
	.byte $5f   ;
	.byte $5f   ;
	.byte $9f   ;
	.byte $df   ;
	.byte $cf   ;
	.byte $af   ;
	.byte $93   ;
	.byte $71   ;
	.byte $38   ;
	.byte $0c   ;This code is PUBLIC DOMAIN.
	.byte $04   ;By Chris "Crackers" Cracknell, March 8, 1997

	org $FFFC
	.word start
	.word start



-----------------------------------------------------------------------------

Please please please give me lots of comments, and tips. 

                               CRACKERS
                    (Toweling off from hell!!!!!!!!)


-- 

Accordionist - Wethifl Musician - Atari 2600 Collector | /\/\
http://www.freenet.hamilton.on.ca/~ad329/Profile.html  | \^^/
Bira Bira Devotee - FES Member - Samurai Pizza Cats Fan| =\/=


--
To unsubscribe, send the word UNSUBSCRIBE in the body of a message to
stella-request@xxxxxxxxxxx

Current Thread