[stella] Template - Final version

Subject: [stella] Template - Final version
From: Rodrigo Silva <stella@xxxxxxxxxxxxx>
Date: Wed, 24 Sep 2003 07:03:10 -0300
After correcting both code and comment bugs (thanks Andrew and all who answered my questions), here goes the final version of my template.

I believe its a good framework for beginners like me... its heavily commented, indented, and every detail was carefully thought to be as easy to learn as possible. For example I used binary notation when writing to addresses like VBLANK, to make clear that in theory im not writing 2, but rather setting D1 bit.

I also precisely calculated (and tested) the # of cycles left for sections like vblank and overscan. I know this may sound useless (pretty much like the whole template), but when there is no need add any unpredicted "sta WSYNC" it gave me a warm felling of a robust, steady beggining...

So, I thought it would be worth sharing... and, as always, any comments, suggestions, compliments, flames, advices, etc would be greatly welcome

Cya,
Rodrigo
; Framework for simple Atari demos - Full version (heavily commented)
;
; Copyleft 2003 By Rodrigo E.S. Silva - atari@xxxxxxxxxxxxx
; Under GPL - GNU Public Licence - http://www.fsf.org/copyleft/gpl.html
; You may copy, distribuite, use, edit, sell, whatever, as long as such freedom
; is propagated in evey version and my credit for original work is kept
; "GPL = Free software that should remain Free"

                   processor 6502      ; Atari 2600 CPU
                   include "vcs.h"     ; Stella (TIA & PIA & RIOT) Definitions
                   include "macro.h"   ; Useful Functions

;///////////////////////////////////////////////////////////////////////////////

                   SEG.U Variables
                   ORG $80

;/////////////////// Global Variables
GlobalDummy        ds 0

;------------------------------------------------------------------------------
; OVERLAYS!
; These variables are overlays, and should be managed with care
; That is, variables are ALREADY DEFINED, and we're reusing RAM for other
; purposes
; EACH OF THESE ARE VARIABLES (TEMPORARY) USED BY ONE ROUTINE (AND IT'S
; SUBROUTINES) THAT IS, LOCAL VARIABLES.  USE 'EM FREELY, THEY COST NOTHING
; TOTAL SPACE USED BY ANY OVERLAY GROUP SHOULD BE <= SIZE OF 'Overlay'
;------------------------------------------------------------------------------
Overlay            ds 0  ; overlay (share) variables (make sure this is as big
                         ; as the biggest overlay subsection)
;/////////////////// 1st set of Overlay Variables - repeat block as necessary
                   ORG Overlay
ov1_Dummy          ds 0


 ECHO [*-$80]d,"out of 128 RAM bytes used",[$100-*]d,"bytes left"
;///////////////////////////////////////////////////////////////////////////////
                   SEG
                   ORG $F000

Reset
                   CLEAN_START         ; Clear RAM and all TIA registers
                                       ; Now A = X = Y = 0

         ;----------------------------------------------------------------------
         ; Once-only initialization... take your time



         ; End of once-only initialization
         ;----------------------------------------------------------------------

StartOfFrame       lda #%00000010      ; Get ready to turn VSYNC on
                   sta VSYNC           ; Starts VSYNC
                   sta WSYNC           ; End of VSYNC Line 1
                   sta WSYNC           ; End of VSYNC Line 2
                   lda #%00000000      ; Get ready to turn VSYNC off
                   sta WSYNC           ; End of VSYNC Line 3
                   sta VSYNC           ; Turn off VSYNC

         	   lda #43	       ; Get timer ready:43*64/76=36.2 scanlin
	           sta TIM64T          ; Start the timer for VBlank

         ;----------------------------------------------------------------------
         ; 37 scanlines of vertical blank... have fun with 2792 cycles
         ;                         (37 scanlines * 76 cycles - 20 cycles already
         ;                          used from one sta WSYNC to another)



         ; End of fun
         ;----------------------------------------------------------------------

WaitEndOfVBlank    lda INTIM           ; check timer...
	           bpl WaitEndOfVBlank ;
                   lda #%00000000      ; Get ready to turn off VBLANK
                   sta WSYNC           ;

         ;----------------------------------------------------------------------
         ; Do 192 scanlines

                   sta VBLANK          ; Turns VBLANK off
                   ldx #192            ; scanline counter
Kernel
                   ;--Go kernel, go! 68 cycles max

                   ;----------------
                   sta WSYNC           ;
                   dex                 ;
                   bne Kernel          ;

         ;----------------------------------------------------------------------
         ; 30 scanlines of overscan...

                   lda #%01000010      ; Get ready for Blanking
                   sta VBLANK          ; End of screen - enter blanking
                   lda #35             ; 35*64/76=29.4 scanlines
                   sta TIM64T          ; Start Timer for Overscan

         ;----------------------------------------------------------------------
         ; Have more fun with 2256 cycles left for overscan



         ; Sorry pal, time's up - get ready for next frame
         ;----------------------------------------------------------------------

WaitEndOfOverscan  lda INTIM             ; check timer...
                   bpl WaitEndOfOverscan ;
                   sta WSYNC             ;

                   jmp StartOfFrame      ;

;///////////////////////////////////////////////////////////////////////////////
 ECHO [*-$F000+6]d,"out of 4096 ROM bytes used",[$FFFA-*]d,"bytes left"

                   ORG $FFFA
InterruptVectors
                   .word Reset         ; NMI
                   .word Reset         ; RESET
                   .word Reset         ; IRQ

                   END
;EOF
; Framework for simple Atari demos - Short version (less comments, no overlay)
;
; Copyleft 2003 By Rodrigo E.S. Silva - atari@xxxxxxxxxxxxx
; Under GPL - GNU Public Licence - http://www.fsf.org/copyleft/gpl.html
; You may copy, distribuite, use, edit, sell, whatever, as long as such freedom
; is propagated in evey version and my credit for original work is kept
; "GPL = Free software that should remain Free"

                   processor 6502      ; Atari 2600 CPU
                   include "vcs.h"     ; Stella (TIA & PIA & RIOT) Definitions
                   include "macro.h"   ; Useful Functions

;///////////////////////////////////////////////////////////////////////////////

                   SEG.U Variables
                   ORG $80

GlobalDummy        ds 0


 ECHO [*-$80]d,"out of 128 RAM bytes used",[$100-*]d,"bytes left"
;///////////////////////////////////////////////////////////////////////////////
                   SEG
                   ORG $F000

Reset
                   CLEAN_START

         ;----------------------------------------------------------------------
         ; Once-only initialization



         ;----------------------------------------------------------------------

StartOfFrame       lda #%00000010
                   sta VSYNC
                   sta WSYNC
                   sta WSYNC
                   lda #%00000000
                   sta WSYNC
                   sta VSYNC

         	   lda #43
	           sta TIM64T

         ;----------------------------------------------------------------------
         ; Vertical blank - 2792 cycles avaliable



         ;----------------------------------------------------------------------

WaitEndOfVBlank    lda INTIM
	           bpl WaitEndOfVBlank
                   lda #%00000000
                   sta WSYNC

         ;----------------------------------------------------------------------
         ; Do 192 scanlines

                   sta VBLANK
                   ldx #192
Kernel
                   ;--68 cycles max

                   ;----------------
                   sta WSYNC
                   dex
                   bne Kernel

         ;----------------------------------------------------------------------
         ; 30 scanlines of overscan

                   lda #%01000010
                   sta VBLANK
                   lda #35
                   sta TIM64T

         ;----------------------------------------------------------------------
         ; Overscan - 2256 cycles avaliable



         ; End of Overscan
         ;----------------------------------------------------------------------

WaitEndOfOverscan  lda INTIM
                   bpl WaitEndOfOverscan
                   sta WSYNC

                   jmp StartOfFrame

;///////////////////////////////////////////////////////////////////////////////
 ECHO [*-$F000+6]d,"out of 4096 ROM bytes used",[$FFFA-*]d,"bytes left"

                   ORG $FFFA
InterruptVectors
                   .word Reset         ; NMI
                   .word Reset         ; RESET
                   .word Reset         ; IRQ

                   END
;EOF
Current Thread