Jump to content
IGNORED

Programming Template


ScumSoft

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

*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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 months later...
  • 3 weeks later...

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:

Link to comment
Share on other sites

  • 4 weeks later...

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...