Jump to content



0

Programming Template


9 replies to this topic

#1 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 331 posts
  • Location:Polysorbate 60

Posted Wed Sep 16, 2009 2:47 PM

Hey everyone! Nice to see such a site dedicated to these classic consoles and keeping them alive. I've always wanted to make a game for a console and decided to start at the roots. I've got some programming experience and just finished Andrew Davie tutorials which are great! I thought it was really well done and provided a good starting point for the 2600.

I thought it might benefit some other new programmers to have a nice template to start off with instead of writing everything from scratch. I'm not sure if I left anything out and got all the info 100% correct, but it can always be updated if need be :D

Here you go:
;****************************************************************************
;*  Atari 2600 Template (NTSC)
;*  STARTED   (Project start date here)
;*  COMPLETED (date completed here)
;*  PROGRAMMED BY (insert name here)
;****************************************************************************
    processor 6502
    include "vcs.h"
    include "macro.h"
    SEG
    ORG $F000

RESET:
    CLEAN_START ;macro.h

; ----------------------------------------------------------------------------------------------------
;[VARIABLES]
; ----------------------------------------------------------------------------------------------------
;Add variables here

; ----------------------------------------------------------------------------------------------------
;[INITIALIZATION]
; ----------------------------------------------------------------------------------------------------
;Add any needed initialization here

; ----------------------------------------------------------------------------------------------------
;[KERNAL]/[VSYNC] ;3 scanlines of VSYNC
; ----------------------------------------------------------------------------------------------------
KERNAL:     lda #%1110              ;Taken from macro.h
VS_LOOP:    sta WSYNC               ;3 scanlines VSYNC
            sta VSYNC               ;Each '1' bits generates
            lsr                     ;a VSYNC ON line (bits 1..3)
            bne VS_LOOP             ;1st '0' bit resets Vsync,

; ----------------------------------------------------------------------------------------------------
;[VBLANK]   ;2812 Cycles for use
            ;76 per scanline
            ;37 scanlines VBLANK
; ----------------------------------------------------------------------------------------------------
            lda #45                 ;Set timer to 37 scanlines
            sta TIM64T              ;worth of time ((37*76)/64)
VB_LOOP:    lda INTIM               ;Read timer
            ;*****************
            ;Insert Logic here
            ;*****************
            bne VB_LOOP             ;Loop if not 0
            sta WSYNC               ;Rollover to scanline 38
            sta VBLANK              ;Enable beam/stop VBLANK

; ----------------------------------------------------------------------------------------------------
;[PLAYFIELD];Starts drawing on 38th scanline
            ;14,592 Cycles for use
            ;76 per scanline
            ;22.6 in Hblank
            ;53.3 in Visible area
; ----------------------------------------------------------------------------------------------------
            ldy #191                ;192 Visible scanlines
PF_LOOP:    ;*****************
            ;Insert Logic here
            sty COLUBK              ;example color gradient
            ;*****************
            dey
            sta WSYNC
            bne PF_LOOP

; ----------------------------------------------------------------------------------------------------
;[OVERSCAN] ;2280 Cycles for use
            ;76 per scanline
            ;30 scanlines
; ----------------------------------------------------------------------------------------------------
            lda #$42                ;Disable beam/Start VBLANK
            sta VBLANK
OVERSCAN:   lda #35                 ;Set timer to 30 scanlines
            sta TIM64T              ;worth of time ((30*76)/64)
OS_LOOP:    lda INTIM               ;Read timer
            ;*****************
            ;Insert Logic here
            ;*****************
            bne OS_LOOP
            sta WSYNC               ;Rollover to scanline 1
            jmp KERNAL              ;End of Kernal/loop back up

; ----------------------------------------------------------------------------------------------------
;[LOGIC SECTION]
; ----------------------------------------------------------------------------------------------------
;Fill in game logic routines here


; ----------------------------------------------------------------------------------------------------
;[INTERRUPTS]
; ----------------------------------------------------------------------------------------------------
    ORG $FFFA
INTERRUPTS:
            .word RESET ;NMI
            .word RESET ;RESET
            .word RESET ;IRQ
    END

Everything look right so far?

I plan to do a port or complete remake of Temple of Apshai. I always liked that game and thought it would be a fun first project to do.

I'm getting the hang of the TIA and how much I can hammer it per scanline :D what a wonderfully simplistic yet complex console, I get so excited just thinking about what I can do with it.

I'm very happy to have found this great site!
Cya all around

*edit* corrected code formatting (replaced tabs with spaces)

Edited by ScumSoft, Wed Sep 16, 2009 3:16 PM.


#2 Wickeycolumbus OFFLINE  

Wickeycolumbus

    River Patroller

  • 4,064 posts
  • Location:Michigan

Posted Wed Sep 16, 2009 3:43 PM

Since the 2600 does not have an NMI vector, there is no need to make it point to 'RESET' ;) Instead you can do this:


    org $FFFC
    .word RESET
    .word RESET



#3 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 331 posts
  • Location:Polysorbate 60

Posted Wed Sep 16, 2009 4:07 PM

I thought it was there in case you run the game on a system that uses the NMI vector for a safer than sorry scenario.
Is this incorrect? If so I'll remove the line. Thanks for the reply.

*edit* Odd, can I not edit my first post once it's been replied to?

Edited by ScumSoft, Wed Sep 16, 2009 4:12 PM.


#4 SeaGtGruff ONLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Wed Sep 16, 2009 9:17 PM

View PostScumSoft, on Wed Sep 16, 2009 4:07 PM, said:

*edit* Odd, can I not edit my first post once it's been replied to?
I thought you could always edit posts in the programming forums. But that was before the upgrade. Anyway, I'm not sure whether including the NMI vector is safer for games being played on the 7800-- which uses a 6502, so it does have NMI interrupts. I mean, just because the 7800 is capable of detecting and processing NMI interrupts, does it *need* to? Is there anything on a 7800 that *produces* an NMI interrupt?

Michael

#5 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 331 posts
  • Location:Polysorbate 60

Posted Thu Sep 17, 2009 12:01 AM

Well it eats up an extra byte, so if anyone is going to need this byte and is using this template then they can remove it, since I cannot edit the post to commit the change.

But everything looking good in it so far?

#6 GroovyBee OFFLINE  

GroovyBee

    7800 Developer

  • 5,781 posts
  • Busy bee!
  • Location:North, England

Posted Thu Sep 17, 2009 3:52 AM

View PostSeaGtGruff, on Wed Sep 16, 2009 9:17 PM, said:

I'm not sure whether including the NMI vector is safer for games being played on the 7800-- which uses a 6502, so it does have NMI interrupts. I mean, just because the 7800 is capable of detecting and processing NMI interrupts, does it *need* to? Is there anything on a 7800 that *produces* an NMI interrupt?

On the 7800, MARIA generates an NMI for the Display List Interrupt (DLI) when its enabled in the Display List List (DLL). This is often used in games for things like colour changes/splits and changing the character set.

EDIT: Fixed the quote tags

Edited by GroovyBee, Thu Sep 17, 2009 3:55 AM.


#7 Nukey Shay OFFLINE  

Nukey Shay

    Sheik Yerbouti

  • 20,458 posts
  • Location:The land of Gorch

Posted Thu Sep 17, 2009 4:07 AM

Since the above isn't applicable to a 7800 running 2600-compatability mode anyway, it doesn't really matter. Bytes $xFFA-$xFFB are just user romspace. BTW if BRK interrupts are not used, bytes $xFFE-$xFFF could also be used for anything. 2600-compatable hardware only requires that the reset vector points to the startup code.

#8 Animan OFFLINE  

Animan

    River Patroller

  • 2,123 posts
  • I'm a guy... I just happen to like Sailor Moon.

Posted Sun Dec 20, 2009 4:46 PM

This looks like it could help. I've only recently began my journey through 2600 assembly, and this will probably help me out. Thanks.

#9 RevEng OFFLINE  

RevEng

    River Patroller

  • 2,010 posts
  • bit shoveler
  • Location:Canada

Posted Tue Jan 5, 2010 7:10 AM

The "Insert Logic Here" comments for VBLANK and Overscan should be placed before their looping labels, instead of after. Otherwise the inserted code will loop N number of times per frame instead of once per frame. (where N depends on the cycle timing of the inserted code.)

I modified my version of the template to use the timer approach for the playfield as well, so I can build up the different sections of the screen (score, radar, whatever) as I go along and still have a 292 cycle count the whole time, but that's just a matter of preference.

Thanks for the nice template! :thumbsup:

#10 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 331 posts
  • Location:Polysorbate 60

Posted Wed Jan 27, 2010 11:54 PM

View PostRevEng, on Tue Jan 5, 2010 7:10 AM, said:

The "Insert Logic Here" comments for VBLANK and Overscan should be placed before their looping labels, instead of after. Otherwise the inserted code will loop N number of times per frame instead of once per frame. (where N depends on the cycle timing of the inserted code.)

I modified my version of the template to use the timer approach for the playfield as well, so I can build up the different sections of the screen (score, radar, whatever) as I go along and still have a 292 cycle count the whole time, but that's just a matter of preference.

Thanks for the nice template! :thumbsup:

Yes this was fixed on my end a little while after I posted, but due to not being able to edit the post after it was replied to I just left it to the user to fix without mention.
Glad its at least helped some :)

[edit]test test

Edited by ScumSoft, Wed Jan 27, 2010 11:56 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users