== YOUR FIRST REAL WORKING PROGRAM!! ==

Get the COMPLETE source code HERE.

Now it is time to get your hands dirty. You will be making your first snes asm
program today. It's about time, huh. So let's get on with it!

What this program will do:

If you've read any of Qwertie's SNES documentation, you may have come by the
term CG or CGRAM. CG is the color palette data. A palette is all the colors
that our tiles will be able to use, but sprites and tiles don't say "I need
color Red from the palette," they ask for a certain entry, or number, in the
palette. So if color 1 in the palette is yellow, any tiles that used color 1
are using yellow. What if you changed that palette entry later on? Then that
tile's color would change right in front of you! Cool, huh. Alright, I think
you get it now..

The CGRAM is where we store the palette data. Now, there's 2 registers that we
need to deal with in order to modify the palette. They are $2121, and $2122.
Let's see what Yoshi has to say about these.

| w   |$2121   |Color # (or palette) selection register [CGDATA]
|     |        |xxxxxxxx             x: address (color #).
|     |        |
|     |        |
| wd  |$2122   |Color data register [CGDATA]
|     |        |xxxxxxxx             x: Value of color. 
|     |        |
|     |        |Snes color is 15 bit; 5 bits for red, green, and blue. The
|     |        |order isn't RGB though: it's BGR (RGB reversed!).

Ok so now we know what we need to do to modify the palette. We need to write
the number of the color we wish to modify to $2121, and then write the new
color data to $2122. And Look, it says you need to write to $2122 twice
(wd - d = double-write required). But what's the format of these 2 bytes we need
to write? Let's look in Snes2.txt

The format (in binary) is the following:

    b: blue                               ?bbbbbgg gggrrrrr
    g: green
    r: red
    ?: "The infamous bit-of-confusion." (just leave it 0 ;)

Yoshi even provides you with some sample colors. Well let's use one of his
sample colors, Red ;). We'll fill the screen with red.

Since InitSNES turns off the screen, we need to turn it back on. Look up
register $2100 in Yoshi's doc to see what I did to turn on the screen.

Note that the screen is turned off in order to force a vertical blank.(VBLANK).
When the screen is being drawn, you cannot edit data in VRAM (or at least not
accurately). You need to either wait for the tracer to be in the stage where
it's not drawing, or just shut off the entire screen and "force VBLANK."
Just thought you should know that if you didn't already.

;-------------------------- Begin SCREENFILL.ASM ----------------------------

;== Include memorymap, header info, and SNES initialization routines
.INCLUDE "header.inc"
.INCLUDE "SnesINIT.asm"

;========================
; Start
;========================

.BANK 0 SLOT 0
.ORG 0
.SECTION "MainCode"

Start:
        InitSNES            ; Init Snes :)

        stz $2121           ; Edit color 0 - snes' screen color
                            ; you can write it in binary or hex
        lda #%00011111      ; binary is more visual, but if you
        sta $2122           ; wanna be cool, use hex ;) 
        stz $2122           ; second byte has no data, so we write a 0

        lda #$0F            ; = 00001111
        sta $2100           ; Turn on screen, full brightness
        

forever:
        jmp forever

.ENDS

;------------------------------------ END ------------------------------------

Ok, hows does it fill the whole screen?

That's that!

Get the COMPLETE source code HERE.

back