Quantcast
Channel: VBForums - Game Demos
Viewing all articles
Browse latest Browse all 56

Atari 2600 Programming Tutorial 4 - Asymmetric Graphics! (Demo Included)

$
0
0
Welcome to another addition of my ultimate Atari 2600 programming tutorial! Now I'm going to teach you how to have full control of the Playfield registers PF0, PF1, and PF2 to produce exciting graphics!

Believe it or not, after the first write to the registers, you can write it again to affect the mirrored / non-mirrored side. For example, you can do this:

Code:

    lda #%00010000        ; PF0 is mirrored <--- direction, low 4 bits ignored
    sta PF0
    lda #0
    sta PF1
    sta PF2
 
    lda #%00000000        ; The 2nd write affects the right side
    sta PF0

    ;PF1 and PF2 still remain 0

Which was the answer to the exercise from my previous tutorial! To produce real graphics though, you don't have to manually code everything. But you can have a byte data table instead which consists of 8 bit values, times 192 times per playfield section, which consist of 6 sections. Or if you are cleaver, you can produce a small graphic using data tables and move it's x and y positions which is easier said than done due to the fact the playfield sections are limited in size. But what if I told you theres a better way? There's a program that helps called fsb.exe, aka Fullscreen Bitmap Tool. You create either a 40x192 size bitmap or png file, drag it in the exe, and it spits an the data table in an asm file which you can include in yours by typing include "your_image_name.asm". But DO NOT include it on top where the other includes are or it wont work. Instead put the include part just before you are changing the ORG to $FFFA with the include indented of course.

Code:

;------------------------------------------------------------------------------
        include "galaga.asm"
       
        ORG $FFFA
       
InterruptVectors
        .word Reset          ; NMI
        .word Reset          ; RESET
        .word Reset          ; IRQ

END


The image can't just be any image. Just something over a black background to produce a shape. Such as a tree, or a ship, or a smiley face, even words. On top of that, the image will have to be upside down in order to appear right side up on the Atari 2600. Don't ask why, it's how FSB works.

I also don't like the labels fsb.exe put. They made File path labels. I'm pretty sure theres a batch command to remove them but instead, remove the paths manually, including the entire path on the top of the file, and just leave the strips. So instead of this:

Code:

C:\Jacob's Stuff\Source Code\DASM\bin\DOS\galaga

C:\Jacob's Stuff\Source Code\DASM\bin\DOS\galaga_STRIP_0
 .byte 0
 .byte 0
 .byte 0
...

You would do this:

Code:

galaga_STRIP_0
 .byte 0
 .byte 0
 .byte 0
 ...

You see the difference between the 2 tables now? Now that you have that set, use this code with your image name replacing galaga of course lol. They don't always have to be the same playfield color. You can actually change the color anywhere you wish while it enters the next scanline! You just have to know where you want to. So heres the code to do really cool asymmetrical playfields:

asymmetrical.asm
Code:

        processor 6502

        include "vcs.h"
        include "macro.h"
       
BLUE        = $9A
       
;------------------------------------------------------------------------------
        SEG
        ORG $F000
       
Reset
; Clear RAM and all TIA registers
        ldx #0
        lda #0
Clear         
        sta 0,x
        inx
        bne Clear
;------------------------------------------------
; Once-only initialization. . .
        lda #BLUE
        sta COLUBK            ; set the background color
       
        lda #$45
        sta COLUPF
       
        ;lda #%00000001
        ;sta CTRLPF
       
;------------------------------------------------

StartOfFrame
; Start of new frame
; Start of vertical blank processing
        lda #0
        sta VBLANK
        lda #2
        sta VSYNC
        sta WSYNC
        sta WSYNC
        sta WSYNC              ; 3 scanlines of VSYNC signal
        lda #0
        sta VSYNC
;------------------------------------------------
; 37 scanlines of vertical blank. . .
        ldx #0
VerticalBlank 
        sta WSYNC
        inx
        cpx #37
        bne VerticalBlank
;------------------------------------------------
; Do 192 scanlines of color-changing (our picture)
    ldx #0  ; this counts our scanline number
;--------------------------------------------------------------------------

ALine
    lda galaga_STRIP_0,x
        sta PF0
        lda galaga_STRIP_1,x
        sta PF1
        lda galaga_STRIP_2,x
        sta PF2
        lda galaga_STRIP_3,x
        sta PF0
        lda galaga_STRIP_4,x
        sta PF1
        lda galaga_STRIP_5,x
        sta PF2
       
    sta WSYNC
    inx
        cpx #192
    bne ALine
;--------------------------------------------------------------------------
; CLEAR THE PLAYFIELD REGISTERS
        lda #0
        sta PF0
        sta PF1
        sta PF2
;------------------------------------------------
    lda #%01000010
    sta VBLANK          ; end of screen - enter blanking     
;------------------------------------------------
; 30 scanlines of overscan. . .
        ldx #0
Overscan       
        sta WSYNC
        inx
        cpx #30
        bne Overscan
        jmp StartOfFrame
;------------------------------------------------------------------------------
        include "galaga.asm"
       
        ORG $FFFA
       
InterruptVectors
        .word Reset          ; NMI
        .word Reset          ; RESET
        .word Reset          ; IRQ

END

galaga.asm (produced by fsb.exe from this image )
See next post below

When you are finished, change the code in the Compile.bat to this and save it:

Code:

@echo off
dasm asymmetric.asm -lkernel.txt -f3 -v5 -oasymmetric.bin

Be sure its all in the same folder as DASM.exe. Compile the code to asymmetric.bin, and run it in through the Stella Atari 2600 emulator. You should now see this:



Much better than just a red border isn't it :bigyello:
Ignor the red line on the bottom left, was messing around with the last value earlier which is not in this tutorial.

Exercise: Play around with other things you can have on the play field. Or mess around with the values in the data table to see what happens.

In the next tutorial, I'm going to teach you how to put in real music!!! Happy coding :)
Attached Files

Viewing all articles
Browse latest Browse all 56

Latest Images

Trending Articles



Latest Images